@fefade/common 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +28 -15
- package/dist/index.mjs +28 -15
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -34,7 +34,9 @@ type MaybePromise<T> = T | Promise<T>;
|
|
|
34
34
|
type Handler<E extends HasRequest> = (event: E) => MaybePromise<Response>;
|
|
35
35
|
|
|
36
36
|
type RateLimiterLike = {
|
|
37
|
-
consume
|
|
37
|
+
consume(key: string | number, pointsToConsume?: number, options?: {
|
|
38
|
+
[key: string]: any;
|
|
39
|
+
}): Promise<unknown>;
|
|
38
40
|
};
|
|
39
41
|
declare function export_default$1<E extends HasRequest>(handler: Handler<E>, limiter: RateLimiterLike): Handler<E>;
|
|
40
42
|
|
package/dist/index.d.ts
CHANGED
|
@@ -34,7 +34,9 @@ type MaybePromise<T> = T | Promise<T>;
|
|
|
34
34
|
type Handler<E extends HasRequest> = (event: E) => MaybePromise<Response>;
|
|
35
35
|
|
|
36
36
|
type RateLimiterLike = {
|
|
37
|
-
consume
|
|
37
|
+
consume(key: string | number, pointsToConsume?: number, options?: {
|
|
38
|
+
[key: string]: any;
|
|
39
|
+
}): Promise<unknown>;
|
|
38
40
|
};
|
|
39
41
|
declare function export_default$1<E extends HasRequest>(handler: Handler<E>, limiter: RateLimiterLike): Handler<E>;
|
|
40
42
|
|
package/dist/index.js
CHANGED
|
@@ -14042,16 +14042,17 @@ function getIp_default(request) {
|
|
|
14042
14042
|
|
|
14043
14043
|
// src/withRateLimit.ts
|
|
14044
14044
|
function isRateLimiterRes(err) {
|
|
14045
|
-
return
|
|
14045
|
+
return typeof err === "object" && err !== null && "msBeforeNext" in err && "remainingPoints" in err;
|
|
14046
14046
|
}
|
|
14047
14047
|
function withRateLimit_default(handler, limiter) {
|
|
14048
14048
|
return async (event) => {
|
|
14049
|
-
const
|
|
14049
|
+
const requestCloned = event.request.clone();
|
|
14050
|
+
const ipAddress = getIp_default(requestCloned);
|
|
14050
14051
|
try {
|
|
14051
|
-
await limiter.consume(
|
|
14052
|
+
await limiter.consume(ipAddress);
|
|
14052
14053
|
} catch (err) {
|
|
14053
14054
|
if (isRateLimiterRes(err)) {
|
|
14054
|
-
new Response(JSON.stringify({ error: "Too many requests" }), {
|
|
14055
|
+
return new Response(JSON.stringify({ error: "Too many requests" }), {
|
|
14055
14056
|
status: 429,
|
|
14056
14057
|
headers: {
|
|
14057
14058
|
"Retry-After": "1800",
|
|
@@ -14059,11 +14060,9 @@ function withRateLimit_default(handler, limiter) {
|
|
|
14059
14060
|
}
|
|
14060
14061
|
});
|
|
14061
14062
|
}
|
|
14062
|
-
|
|
14063
|
-
status: 500
|
|
14064
|
-
});
|
|
14063
|
+
throw err;
|
|
14065
14064
|
}
|
|
14066
|
-
return handler(
|
|
14065
|
+
return handler(event);
|
|
14067
14066
|
};
|
|
14068
14067
|
}
|
|
14069
14068
|
|
|
@@ -14071,13 +14070,24 @@ function withRateLimit_default(handler, limiter) {
|
|
|
14071
14070
|
function validateTurnstile_default(handler, secretKey) {
|
|
14072
14071
|
return async (event) => {
|
|
14073
14072
|
if (!secretKey) {
|
|
14074
|
-
return new Response(JSON.stringify({ error: "Invalid secret key" })
|
|
14073
|
+
return new Response(JSON.stringify({ error: "Invalid secret key" }), {
|
|
14074
|
+
status: 500,
|
|
14075
|
+
headers: {
|
|
14076
|
+
"Content-Type": "application/json"
|
|
14077
|
+
}
|
|
14078
|
+
});
|
|
14075
14079
|
}
|
|
14076
|
-
const
|
|
14080
|
+
const requestCloned = event.request.clone();
|
|
14081
|
+
const body = await requestCloned.json();
|
|
14077
14082
|
const token = body["cf-turnstile-response"];
|
|
14078
|
-
const
|
|
14083
|
+
const ipAddress = getIp_default(event.request);
|
|
14079
14084
|
if (!token) {
|
|
14080
|
-
return new Response(JSON.stringify({ error: "Captcha not sent" })
|
|
14085
|
+
return new Response(JSON.stringify({ error: "Captcha not sent" }), {
|
|
14086
|
+
status: 400,
|
|
14087
|
+
headers: {
|
|
14088
|
+
"Content-Type": "application/json"
|
|
14089
|
+
}
|
|
14090
|
+
});
|
|
14081
14091
|
}
|
|
14082
14092
|
const response = await fetch(
|
|
14083
14093
|
"https://challenges.cloudflare.com/turnstile/v0/siteverify",
|
|
@@ -14089,16 +14099,19 @@ function validateTurnstile_default(handler, secretKey) {
|
|
|
14089
14099
|
body: JSON.stringify({
|
|
14090
14100
|
secret: secretKey,
|
|
14091
14101
|
response: token.toString(),
|
|
14092
|
-
remoteip:
|
|
14102
|
+
remoteip: ipAddress
|
|
14093
14103
|
})
|
|
14094
14104
|
}
|
|
14095
14105
|
);
|
|
14096
14106
|
if (!response.ok) {
|
|
14097
14107
|
return new Response(JSON.stringify({ error: "Invalid verification" }), {
|
|
14098
|
-
status: 400
|
|
14108
|
+
status: 400,
|
|
14109
|
+
headers: {
|
|
14110
|
+
"Content-Type": "application/json"
|
|
14111
|
+
}
|
|
14099
14112
|
});
|
|
14100
14113
|
}
|
|
14101
|
-
return handler(
|
|
14114
|
+
return handler(event);
|
|
14102
14115
|
};
|
|
14103
14116
|
}
|
|
14104
14117
|
|
package/dist/index.mjs
CHANGED
|
@@ -14014,16 +14014,17 @@ function getIp_default(request) {
|
|
|
14014
14014
|
|
|
14015
14015
|
// src/withRateLimit.ts
|
|
14016
14016
|
function isRateLimiterRes(err) {
|
|
14017
|
-
return
|
|
14017
|
+
return typeof err === "object" && err !== null && "msBeforeNext" in err && "remainingPoints" in err;
|
|
14018
14018
|
}
|
|
14019
14019
|
function withRateLimit_default(handler, limiter) {
|
|
14020
14020
|
return async (event) => {
|
|
14021
|
-
const
|
|
14021
|
+
const requestCloned = event.request.clone();
|
|
14022
|
+
const ipAddress = getIp_default(requestCloned);
|
|
14022
14023
|
try {
|
|
14023
|
-
await limiter.consume(
|
|
14024
|
+
await limiter.consume(ipAddress);
|
|
14024
14025
|
} catch (err) {
|
|
14025
14026
|
if (isRateLimiterRes(err)) {
|
|
14026
|
-
new Response(JSON.stringify({ error: "Too many requests" }), {
|
|
14027
|
+
return new Response(JSON.stringify({ error: "Too many requests" }), {
|
|
14027
14028
|
status: 429,
|
|
14028
14029
|
headers: {
|
|
14029
14030
|
"Retry-After": "1800",
|
|
@@ -14031,11 +14032,9 @@ function withRateLimit_default(handler, limiter) {
|
|
|
14031
14032
|
}
|
|
14032
14033
|
});
|
|
14033
14034
|
}
|
|
14034
|
-
|
|
14035
|
-
status: 500
|
|
14036
|
-
});
|
|
14035
|
+
throw err;
|
|
14037
14036
|
}
|
|
14038
|
-
return handler(
|
|
14037
|
+
return handler(event);
|
|
14039
14038
|
};
|
|
14040
14039
|
}
|
|
14041
14040
|
|
|
@@ -14043,13 +14042,24 @@ function withRateLimit_default(handler, limiter) {
|
|
|
14043
14042
|
function validateTurnstile_default(handler, secretKey) {
|
|
14044
14043
|
return async (event) => {
|
|
14045
14044
|
if (!secretKey) {
|
|
14046
|
-
return new Response(JSON.stringify({ error: "Invalid secret key" })
|
|
14045
|
+
return new Response(JSON.stringify({ error: "Invalid secret key" }), {
|
|
14046
|
+
status: 500,
|
|
14047
|
+
headers: {
|
|
14048
|
+
"Content-Type": "application/json"
|
|
14049
|
+
}
|
|
14050
|
+
});
|
|
14047
14051
|
}
|
|
14048
|
-
const
|
|
14052
|
+
const requestCloned = event.request.clone();
|
|
14053
|
+
const body = await requestCloned.json();
|
|
14049
14054
|
const token = body["cf-turnstile-response"];
|
|
14050
|
-
const
|
|
14055
|
+
const ipAddress = getIp_default(event.request);
|
|
14051
14056
|
if (!token) {
|
|
14052
|
-
return new Response(JSON.stringify({ error: "Captcha not sent" })
|
|
14057
|
+
return new Response(JSON.stringify({ error: "Captcha not sent" }), {
|
|
14058
|
+
status: 400,
|
|
14059
|
+
headers: {
|
|
14060
|
+
"Content-Type": "application/json"
|
|
14061
|
+
}
|
|
14062
|
+
});
|
|
14053
14063
|
}
|
|
14054
14064
|
const response = await fetch(
|
|
14055
14065
|
"https://challenges.cloudflare.com/turnstile/v0/siteverify",
|
|
@@ -14061,16 +14071,19 @@ function validateTurnstile_default(handler, secretKey) {
|
|
|
14061
14071
|
body: JSON.stringify({
|
|
14062
14072
|
secret: secretKey,
|
|
14063
14073
|
response: token.toString(),
|
|
14064
|
-
remoteip:
|
|
14074
|
+
remoteip: ipAddress
|
|
14065
14075
|
})
|
|
14066
14076
|
}
|
|
14067
14077
|
);
|
|
14068
14078
|
if (!response.ok) {
|
|
14069
14079
|
return new Response(JSON.stringify({ error: "Invalid verification" }), {
|
|
14070
|
-
status: 400
|
|
14080
|
+
status: 400,
|
|
14081
|
+
headers: {
|
|
14082
|
+
"Content-Type": "application/json"
|
|
14083
|
+
}
|
|
14071
14084
|
});
|
|
14072
14085
|
}
|
|
14073
|
-
return handler(
|
|
14086
|
+
return handler(event);
|
|
14074
14087
|
};
|
|
14075
14088
|
}
|
|
14076
14089
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fefade/common",
|
|
3
3
|
"description": "Containing common resources, constants, images, and utility functions that are used across various projects. This package aims to promote reusability and maintain consistency across different applications by centralizing commonly used assets and code.",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.8",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|