Skip to content

Commit

Permalink
Project update. [p][robotic]
Browse files Browse the repository at this point in the history
  • Loading branch information
jaswrks committed Jan 8, 2024
1 parent 92b48cc commit 81f0e3c
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .browserslistrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Generated data.
# <generated:start>

# Last generated Jan 8, 2024 2:21 AM UTC.
# Last generated Jan 8, 2024 2:57 AM UTC.

[production]
node >= 20.9.0
Expand Down
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Generated data.
# <generated:start>

# Last generated Jan 8, 2024 2:21 AM UTC.
# Last generated Jan 8, 2024 2:57 AM UTC.

# Locals

Expand Down
8 changes: 4 additions & 4 deletions .env.vault
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ DOTENV_VAULT_MAIN="3rfi+ClkONvfHPiU9FTBcC1+Um/L8QeM9dRw1jFzEqzZXw=="
DOTENV_VAULT_MAIN_VERSION=1

# dev
DOTENV_VAULT_DEV="y+f2F71mgD9qMUGboxpsN9L8PVUWv3dn8d5CqJtpnqZzywQGwUrm2V8YdhzIeDziY1F65m29RI+g1KqmCtJpRwEdB1SQyKiG5/FnrXMLhKWtU6y8tXEod8pMqyqdboe1z5mbkuQovANu23LeRtY1OuiXDDXkd8MnZzbrQG8TSDnrCaZGhnZJDL3crpqVWCpnSiV7QG1xCtfephzx4mP44095vXI7ytrNoFVGXp+i8wFzqb9NI8vf7V3vsvVP/Yj/BIbEy1UgrX5hcNF6BgrA9hwOBG4g6V3/ZaAc7YwGcwH/wBX78tkBQELxcADuEXVHLUAGUvJOx/jCvMm6SqLFaaw2fI8JMQZlsnF3+h8mkt38wC9FBHpNn1Kdq1i2jbU5gwweVoxOWUsBIfsLeZrAasnZLLJWCToHbQHcIS4X83XwdHPeg9hSO1VjNySuOp1how1ZB7HjtuVS468958bSb15+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msxx8ITppgNxMUJeFZcKa/FW8LYvfeYYUr+XkNQaLRz9lPhdnizUAblXikDp0in9ghe4EC71L73rLn2wzpHs4fK476gstjP1crEk8WwQnFcnWPSsLw8GNaEsPMEHjLXFq2sZyn7HK6RTDvwJQIHtz5DEuLN8Ud3Q/T8cDgaxKP9c3U9fuFZbIh5zg3GPCSq2aLLKnI5QyF5IoZ7yCfBe+cNeQ/IkQYd6pG2gCIebQ0qvEMkYVF8Ppw5ZE6J+IWQatqBvDYb7fScSPBQcUIEC3qvwl8TWn+zcgwwMvHmwazU616Ai/w5Vt3k9HUd+KsPEadIsmPYC8x0iAKfkt21k1FTx0dZBpoNUzT4+EckP4WkbPP6CfjGAkaaBsCaat6lxvna/BqxfxeZOOb0jyhWI4XKAIDPYktabHBWb678xCqRe3LkI50DItFkm5Dn7eg/1db4EeCUsneQMvPB06tzqGO0AhIshG6VHeLvRewCYkntKiorq2OHeOnt2aWy3DEUeks+0oqD1S+tBEcBL5jC91JRgJ9Rjve/myr+e4HEnaAL6Wd3w6w=="
DOTENV_VAULT_CI_VERSION=21

# stage
DOTENV_VAULT_STAGE="bfqZYD8oVLWMZ0JR5LICV+sB/btaXavszxZLxTfwSH8U5fg="
Expand Down
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Generated data.
# <generated:start>

# Last generated Jan 8, 2024 2:21 AM UTC.
# Last generated Jan 8, 2024 2:57 AM UTC.

# Default

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Generated data.
# <generated:start>

# Last generated Jan 8, 2024 2:21 AM UTC.
# Last generated Jan 8, 2024 2:57 AM UTC.

# Locals

Expand Down
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# Generated data.
# <generated:start>

# Last generated Jan 8, 2024 2:21 AM UTC.
# Last generated Jan 8, 2024 2:57 AM UTC.

# Locals

Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Generated data.
# <generated:start>

# Last generated Jan 8, 2024 2:21 AM UTC.
# Last generated Jan 8, 2024 2:57 AM UTC.

# Packages

Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @note This entire file will be updated automatically.
* @note Instead of editing here, please review `./settings.mjs`.
*
* Last generated using `./settings.mjs` Jan 8, 2024 2:21 AM UTC.
* Last generated using `./settings.mjs` Jan 8, 2024 2:57 AM UTC.
*/
{
"editor.formatOnType": false,
Expand Down
2 changes: 1 addition & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Generated data.
# <generated:start>

# Last generated Jan 8, 2024 2:21 AM UTC.
# Last generated Jan 8, 2024 2:57 AM UTC.

# Locals

Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publishConfig": {
"access": "public"
},
"version": "1.0.162",
"version": "1.0.163",
"license": "GPL-3.0-or-later",
"name": "@clevercanyon/utilities.cfw",
"description": "Utilities for JavaScript apps running in a Cloudflare Worker environment.",
Expand Down
50 changes: 36 additions & 14 deletions src/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import '#@initialize.ts';

import { type StdFetchEventData } from '#cfw.ts';
import { $class, $env, $fn, $http, $is, $mime, $obj } from '@clevercanyon/utilities';
import { $class, $env, $fn, $http, $is, $json, $mime, $obj, $url } from '@clevercanyon/utilities';
import { Ratelimit as RateLimiterCore } from '@upstash/ratelimit';
import { Redis } from '@upstash/redis/cloudflare';

Expand Down Expand Up @@ -119,7 +119,7 @@ export const instance = $fn.memo(
* @returns {@see RateLimiter} Instance.
*/
export const rateLimiter = (feData: StdFetchEventData, options?: RateLimiterOptions): RateLimiter => {
const { auditLogger, request, ctx } = feData,
const { ctx, url, request, auditLogger } = feData,
limiter = rateLimiterCore(options);

return {
Expand All @@ -132,16 +132,27 @@ export const rateLimiter = (feData: StdFetchEventData, options?: RateLimiterOpti
ctx.waitUntil(limiterResponse.pending); // e.g., Analytics, multiregion sync.
}
if (!limiterResponse.success) {
void auditLogger.info('429: ' + $http.responseStatusText('429'), {
void auditLogger.info('429: ' + $http.responseStatusText(429), {
rateLimiter: limiter,
rateLimiterMethod: 'limit',
rateLimiterResponse: limiterResponse,
});
throw $http.prepareResponse(request, {
status: 429, // Too many requests in this scenario.
headers: { 'content-type': $mime.contentType('.txt') },
body: $http.responseStatusText('429'), // Too many requests.
});
if (
/\b(?:application\/json)\b/iu.test(request.headers.get('accept') || '') || //
/^\/(?:api)(?:$|\/)/iu.test($url.removeAppBasePath(url).pathname)
) {
throw $http.prepareResponse(request, {
status: 429, // Too many requests.
headers: { 'content-type': $json.contentType() },
body: $json.stringify({ ok: false, error: { message: $http.responseStatusText(429) } }, { pretty: true }),
});
} else {
throw $http.prepareResponse(request, {
status: 429, // Too many requests.
headers: { 'content-type': $mime.contentType('.txt') },
body: $http.responseStatusText(429),
});
}
}
return limiterResponse;
},
Expand All @@ -152,16 +163,27 @@ export const rateLimiter = (feData: StdFetchEventData, options?: RateLimiterOpti
ctx.waitUntil(limiterResponse.pending); // e.g., Analytics, multiregion sync.
}
if (!limiterResponse.success) {
void auditLogger.info('429: ' + $http.responseStatusText('429'), {
void auditLogger.info('429: ' + $http.responseStatusText(429), {
rateLimiter: limiter,
rateLimiterMethod: 'blockUntilReady',
rateLimiterResponse: limiterResponse,
});
throw $http.prepareResponse(request, {
status: 429, // Too many requests in this scenario.
headers: { 'content-type': $mime.contentType('.txt') },
body: $http.responseStatusText('429'), // Too many requests.
});
if (
/\b(?:application\/json)\b/iu.test(request.headers.get('accept') || '') || //
/^\/(?:api)(?:$|\/)/iu.test($url.removeAppBasePath(url).pathname)
) {
throw $http.prepareResponse(request, {
status: 429, // Too many requests.
headers: { 'content-type': $json.contentType() },
body: $json.stringify({ ok: false, error: { message: $http.responseStatusText(429) } }, { pretty: true }),
});
} else {
throw $http.prepareResponse(request, {
status: 429, // Too many requests.
headers: { 'content-type': $mime.contentType('.txt') },
body: $http.responseStatusText(429),
});
}
}
return limiterResponse;
},
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @note This entire file will be updated automatically.
* @note Instead of editing here, please review `./tsconfig.mjs`.
*
* Last generated using `./tsconfig.mjs` Jan 8, 2024 2:21 AM UTC.
* Last generated using `./tsconfig.mjs` Jan 8, 2024 2:57 AM UTC.
*/
{
"include": ["./src/**/*", "./dev-types.d.ts"],
Expand Down
2 changes: 1 addition & 1 deletion wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# @note This entire file will be updated automatically.
# @note Instead of editing here, please review `./wrangler.mjs`.
#
# Last generated using `./wrangler.mjs` Jan 8, 2024 2:21 AM UTC.
# Last generated using `./wrangler.mjs` Jan 8, 2024 2:57 AM UTC.
##

send_metrics = false
Expand Down

0 comments on commit 81f0e3c

Please sign in to comment.