@fefade/common 1.0.5 → 1.0.6
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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +19 -20
- package/dist/index.mjs +19 -20
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -38,7 +38,7 @@ type RateLimiterLike = {
|
|
|
38
38
|
};
|
|
39
39
|
declare function export_default$1<E extends HasRequest>(handler: Handler<E>, limiter: RateLimiterLike): Handler<E>;
|
|
40
40
|
|
|
41
|
-
declare function export_default<E extends HasRequest>(handler: Handler<E>, secretKey
|
|
41
|
+
declare function export_default<E extends HasRequest>(handler: Handler<E>, secretKey?: string): Handler<E>;
|
|
42
42
|
|
|
43
43
|
declare const ORG_NAME = "Fefade";
|
|
44
44
|
declare const ACRONYM = "ff";
|
package/dist/index.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ type RateLimiterLike = {
|
|
|
38
38
|
};
|
|
39
39
|
declare function export_default$1<E extends HasRequest>(handler: Handler<E>, limiter: RateLimiterLike): Handler<E>;
|
|
40
40
|
|
|
41
|
-
declare function export_default<E extends HasRequest>(handler: Handler<E>, secretKey
|
|
41
|
+
declare function export_default<E extends HasRequest>(handler: Handler<E>, secretKey?: string): Handler<E>;
|
|
42
42
|
|
|
43
43
|
declare const ORG_NAME = "Fefade";
|
|
44
44
|
declare const ACRONYM = "ff";
|
package/dist/index.js
CHANGED
|
@@ -14010,9 +14010,9 @@ function handleError_default(err) {
|
|
|
14010
14010
|
if (err instanceof external_exports.ZodError) {
|
|
14011
14011
|
return new Errors(err.issues[0].message, "VALIDATION_ERROR", 400);
|
|
14012
14012
|
}
|
|
14013
|
-
const
|
|
14014
|
-
if (
|
|
14015
|
-
return
|
|
14013
|
+
const fbError = firebaseError(err);
|
|
14014
|
+
if (fbError instanceof Errors) {
|
|
14015
|
+
return fbError;
|
|
14016
14016
|
}
|
|
14017
14017
|
return new Errors("Internal server error", "INTERNAL_SERVER_ERROR", 500);
|
|
14018
14018
|
}
|
|
@@ -14051,23 +14051,17 @@ function withRateLimit_default(handler, limiter) {
|
|
|
14051
14051
|
await limiter.consume(ip);
|
|
14052
14052
|
} catch (err) {
|
|
14053
14053
|
if (isRateLimiterRes(err)) {
|
|
14054
|
-
Response.
|
|
14055
|
-
|
|
14056
|
-
{
|
|
14057
|
-
|
|
14058
|
-
|
|
14059
|
-
"Retry-After": "1800",
|
|
14060
|
-
"Content-Type": "application/json"
|
|
14061
|
-
}
|
|
14054
|
+
new Response(JSON.stringify({ error: "Too many requests" }), {
|
|
14055
|
+
status: 429,
|
|
14056
|
+
headers: {
|
|
14057
|
+
"Retry-After": "1800",
|
|
14058
|
+
"Content-Type": "application/json"
|
|
14062
14059
|
}
|
|
14063
|
-
);
|
|
14060
|
+
});
|
|
14064
14061
|
}
|
|
14065
|
-
return Response.
|
|
14066
|
-
|
|
14067
|
-
|
|
14068
|
-
status: 500
|
|
14069
|
-
}
|
|
14070
|
-
);
|
|
14062
|
+
return new Response(JSON.stringify({ error: "Internal server error" }), {
|
|
14063
|
+
status: 500
|
|
14064
|
+
});
|
|
14071
14065
|
}
|
|
14072
14066
|
return handler({ ...event, ip });
|
|
14073
14067
|
};
|
|
@@ -14076,11 +14070,14 @@ function withRateLimit_default(handler, limiter) {
|
|
|
14076
14070
|
// src/validateTurnstile.ts
|
|
14077
14071
|
function validateTurnstile_default(handler, secretKey) {
|
|
14078
14072
|
return async (event) => {
|
|
14073
|
+
if (!secretKey) {
|
|
14074
|
+
return new Response(JSON.stringify({ error: "Invalid secret key" }));
|
|
14075
|
+
}
|
|
14079
14076
|
const body = await event.request.json();
|
|
14080
14077
|
const token = body["cf-turnstile-response"];
|
|
14081
14078
|
const ip = getIp_default(event.request);
|
|
14082
14079
|
if (!token) {
|
|
14083
|
-
return Response.
|
|
14080
|
+
return new Response(JSON.stringify({ error: "Captcha not sent" }));
|
|
14084
14081
|
}
|
|
14085
14082
|
const response = await fetch(
|
|
14086
14083
|
"https://challenges.cloudflare.com/turnstile/v0/siteverify",
|
|
@@ -14097,7 +14094,9 @@ function validateTurnstile_default(handler, secretKey) {
|
|
|
14097
14094
|
}
|
|
14098
14095
|
);
|
|
14099
14096
|
if (!response.ok) {
|
|
14100
|
-
return Response.
|
|
14097
|
+
return new Response(JSON.stringify({ error: "Invalid verification" }), {
|
|
14098
|
+
status: 400
|
|
14099
|
+
});
|
|
14101
14100
|
}
|
|
14102
14101
|
return handler({ ...event, ip });
|
|
14103
14102
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -13982,9 +13982,9 @@ function handleError_default(err) {
|
|
|
13982
13982
|
if (err instanceof external_exports.ZodError) {
|
|
13983
13983
|
return new Errors(err.issues[0].message, "VALIDATION_ERROR", 400);
|
|
13984
13984
|
}
|
|
13985
|
-
const
|
|
13986
|
-
if (
|
|
13987
|
-
return
|
|
13985
|
+
const fbError = firebaseError(err);
|
|
13986
|
+
if (fbError instanceof Errors) {
|
|
13987
|
+
return fbError;
|
|
13988
13988
|
}
|
|
13989
13989
|
return new Errors("Internal server error", "INTERNAL_SERVER_ERROR", 500);
|
|
13990
13990
|
}
|
|
@@ -14023,23 +14023,17 @@ function withRateLimit_default(handler, limiter) {
|
|
|
14023
14023
|
await limiter.consume(ip);
|
|
14024
14024
|
} catch (err) {
|
|
14025
14025
|
if (isRateLimiterRes(err)) {
|
|
14026
|
-
Response.
|
|
14027
|
-
|
|
14028
|
-
{
|
|
14029
|
-
|
|
14030
|
-
|
|
14031
|
-
"Retry-After": "1800",
|
|
14032
|
-
"Content-Type": "application/json"
|
|
14033
|
-
}
|
|
14026
|
+
new Response(JSON.stringify({ error: "Too many requests" }), {
|
|
14027
|
+
status: 429,
|
|
14028
|
+
headers: {
|
|
14029
|
+
"Retry-After": "1800",
|
|
14030
|
+
"Content-Type": "application/json"
|
|
14034
14031
|
}
|
|
14035
|
-
);
|
|
14032
|
+
});
|
|
14036
14033
|
}
|
|
14037
|
-
return Response.
|
|
14038
|
-
|
|
14039
|
-
|
|
14040
|
-
status: 500
|
|
14041
|
-
}
|
|
14042
|
-
);
|
|
14034
|
+
return new Response(JSON.stringify({ error: "Internal server error" }), {
|
|
14035
|
+
status: 500
|
|
14036
|
+
});
|
|
14043
14037
|
}
|
|
14044
14038
|
return handler({ ...event, ip });
|
|
14045
14039
|
};
|
|
@@ -14048,11 +14042,14 @@ function withRateLimit_default(handler, limiter) {
|
|
|
14048
14042
|
// src/validateTurnstile.ts
|
|
14049
14043
|
function validateTurnstile_default(handler, secretKey) {
|
|
14050
14044
|
return async (event) => {
|
|
14045
|
+
if (!secretKey) {
|
|
14046
|
+
return new Response(JSON.stringify({ error: "Invalid secret key" }));
|
|
14047
|
+
}
|
|
14051
14048
|
const body = await event.request.json();
|
|
14052
14049
|
const token = body["cf-turnstile-response"];
|
|
14053
14050
|
const ip = getIp_default(event.request);
|
|
14054
14051
|
if (!token) {
|
|
14055
|
-
return Response.
|
|
14052
|
+
return new Response(JSON.stringify({ error: "Captcha not sent" }));
|
|
14056
14053
|
}
|
|
14057
14054
|
const response = await fetch(
|
|
14058
14055
|
"https://challenges.cloudflare.com/turnstile/v0/siteverify",
|
|
@@ -14069,7 +14066,9 @@ function validateTurnstile_default(handler, secretKey) {
|
|
|
14069
14066
|
}
|
|
14070
14067
|
);
|
|
14071
14068
|
if (!response.ok) {
|
|
14072
|
-
return Response.
|
|
14069
|
+
return new Response(JSON.stringify({ error: "Invalid verification" }), {
|
|
14070
|
+
status: 400
|
|
14071
|
+
});
|
|
14073
14072
|
}
|
|
14074
14073
|
return handler({ ...event, ip });
|
|
14075
14074
|
};
|
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.6",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|