@lunora/auth 1.0.0-alpha.25 → 1.0.0-alpha.26
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/turnstile-middleware.mjs +5 -16
- package/dist/turnstile.d.mts +0 -10
- package/dist/turnstile.d.ts +0 -10
- package/dist/turnstile.mjs +4 -11
- package/package.json +2 -2
|
@@ -1,13 +1,10 @@
|
|
|
1
|
+
import { LunoraError } from '@lunora/errors';
|
|
1
2
|
import { verifyTurnstile } from './turnstile.mjs';
|
|
2
3
|
|
|
3
4
|
const verifyTurnstileMiddleware = (options) => async ({ ctx, next }) => {
|
|
4
5
|
const token = options.token(ctx);
|
|
5
6
|
if (token === void 0 || token === "") {
|
|
6
|
-
throw
|
|
7
|
-
code: "FORBIDDEN",
|
|
8
|
-
name: "LunoraError",
|
|
9
|
-
status: 403
|
|
10
|
-
});
|
|
7
|
+
throw new LunoraError("FORBIDDEN", options.message ?? "turnstile token missing");
|
|
11
8
|
}
|
|
12
9
|
let result;
|
|
13
10
|
try {
|
|
@@ -24,19 +21,11 @@ const verifyTurnstileMiddleware = (options) => async ({ ctx, next }) => {
|
|
|
24
21
|
if (options.failOpen) {
|
|
25
22
|
return next();
|
|
26
23
|
}
|
|
27
|
-
throw
|
|
28
|
-
cause: error,
|
|
29
|
-
code: "FORBIDDEN",
|
|
30
|
-
name: "LunoraError",
|
|
31
|
-
status: 403
|
|
32
|
-
});
|
|
24
|
+
throw new LunoraError("FORBIDDEN", options.message ?? "turnstile verification unavailable", { cause: error });
|
|
33
25
|
}
|
|
34
26
|
if (!result.success || options.validate !== void 0 && !options.validate(result)) {
|
|
35
|
-
throw
|
|
36
|
-
|
|
37
|
-
errorCodes: result.errorCodes,
|
|
38
|
-
name: "LunoraError",
|
|
39
|
-
status: 403
|
|
27
|
+
throw new LunoraError("FORBIDDEN", options.message ?? "turnstile verification failed", {
|
|
28
|
+
data: result.errorCodes.length > 0 ? { errorCodes: result.errorCodes } : void 0
|
|
40
29
|
});
|
|
41
30
|
}
|
|
42
31
|
return next();
|
package/dist/turnstile.d.mts
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cloudflare Turnstile server-side verification.
|
|
3
|
-
*
|
|
4
|
-
* Turnstile has **no Cloudflare binding** — verification is a single HTTPS POST
|
|
5
|
-
* to the public `siteverify` endpoint with your secret key. The secret lives in
|
|
6
|
-
* a plain env var / `.dev.vars` (conventionally `TURNSTILE_SECRET_KEY`), not in
|
|
7
|
-
* `wrangler.jsonc`. This module is therefore pure, transport-agnostic, and
|
|
8
|
-
* usable from any mutation/action — not just the auth flow.
|
|
9
|
-
* @see https://developers.cloudflare.com/turnstile/get-started/server-side-validation/
|
|
10
|
-
*/
|
|
11
1
|
/** Cloudflare's public Turnstile `siteverify` endpoint. */
|
|
12
2
|
declare const TURNSTILE_VERIFY_ENDPOINT = "https://challenges.cloudflare.com/turnstile/v0/siteverify";
|
|
13
3
|
/** Minimal `fetch` shape we depend on, so callers can inject a stub in tests. */
|
package/dist/turnstile.d.ts
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cloudflare Turnstile server-side verification.
|
|
3
|
-
*
|
|
4
|
-
* Turnstile has **no Cloudflare binding** — verification is a single HTTPS POST
|
|
5
|
-
* to the public `siteverify` endpoint with your secret key. The secret lives in
|
|
6
|
-
* a plain env var / `.dev.vars` (conventionally `TURNSTILE_SECRET_KEY`), not in
|
|
7
|
-
* `wrangler.jsonc`. This module is therefore pure, transport-agnostic, and
|
|
8
|
-
* usable from any mutation/action — not just the auth flow.
|
|
9
|
-
* @see https://developers.cloudflare.com/turnstile/get-started/server-side-validation/
|
|
10
|
-
*/
|
|
11
1
|
/** Cloudflare's public Turnstile `siteverify` endpoint. */
|
|
12
2
|
declare const TURNSTILE_VERIFY_ENDPOINT = "https://challenges.cloudflare.com/turnstile/v0/siteverify";
|
|
13
3
|
/** Minimal `fetch` shape we depend on, so callers can inject a stub in tests. */
|
package/dist/turnstile.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { LunoraError } from '@lunora/errors';
|
|
2
|
+
|
|
1
3
|
const TURNSTILE_VERIFY_ENDPOINT = "https://challenges.cloudflare.com/turnstile/v0/siteverify";
|
|
2
4
|
const asString = (value) => typeof value === "string" ? value : void 0;
|
|
3
5
|
const asStringArray = (value) => Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
|
|
@@ -21,19 +23,10 @@ const verifyTurnstile = async ({
|
|
|
21
23
|
method: "POST"
|
|
22
24
|
});
|
|
23
25
|
} catch (error) {
|
|
24
|
-
throw
|
|
25
|
-
cause: error,
|
|
26
|
-
code: "SERVICE_UNAVAILABLE",
|
|
27
|
-
name: "LunoraError",
|
|
28
|
-
status: 503
|
|
29
|
-
});
|
|
26
|
+
throw new LunoraError("SERVICE_UNAVAILABLE", "turnstile siteverify request failed", { cause: error, status: 503 });
|
|
30
27
|
}
|
|
31
28
|
if (!response.ok) {
|
|
32
|
-
throw
|
|
33
|
-
code: "SERVICE_UNAVAILABLE",
|
|
34
|
-
name: "LunoraError",
|
|
35
|
-
status: 503
|
|
36
|
-
});
|
|
29
|
+
throw new LunoraError("SERVICE_UNAVAILABLE", `turnstile siteverify returned ${String(response.status)}`, { status: 503 });
|
|
37
30
|
}
|
|
38
31
|
const raw = await response.json();
|
|
39
32
|
const action = asString(raw.action);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/auth",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.26",
|
|
4
4
|
"description": "Auth for Lunora — a thin better-auth wrapper: email/password, OAuth, plugins, D1-backed",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"auth",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"dependencies": {
|
|
85
85
|
"@better-auth/passkey": "^1.6.23",
|
|
86
86
|
"@lunora/errors": "1.0.0-alpha.2",
|
|
87
|
-
"@lunora/server": "1.0.0-alpha.
|
|
87
|
+
"@lunora/server": "1.0.0-alpha.20",
|
|
88
88
|
"@lunora/values": "1.0.0-alpha.5",
|
|
89
89
|
"better-auth": "^1.6.23"
|
|
90
90
|
},
|