@lunora/auth 0.0.0 → 1.0.0-alpha.1
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/LICENSE.md +105 -0
- package/README.md +125 -9
- package/__assets__/package-og.svg +14 -0
- package/dist/adapter.d.mts +43 -0
- package/dist/adapter.d.ts +43 -0
- package/dist/adapter.mjs +47 -0
- package/dist/index.d.mts +386 -0
- package/dist/index.d.ts +386 -0
- package/dist/index.mjs +12 -0
- package/dist/middleware.d.mts +189 -0
- package/dist/middleware.d.ts +189 -0
- package/dist/middleware.mjs +53 -0
- package/dist/packem_shared/DEFAULT_AUTH_BASE_PATH-DjcUWEQl.mjs +11 -0
- package/dist/packem_shared/create-auth.d-M36jwG_Y.d.mts +58 -0
- package/dist/packem_shared/create-auth.d-M36jwG_Y.d.ts +58 -0
- package/dist/packem_shared/createAuth-B-tvsvQU.mjs +56 -0
- package/dist/packem_shared/createAuthAdmin-BxrfEeA_.mjs +249 -0
- package/dist/packem_shared/ensureMigrated-wZH3oXDu.mjs +28 -0
- package/dist/packem_shared/sessionPresets-B95rXrd8.mjs +35 -0
- package/dist/plugins-client.d.mts +2 -0
- package/dist/plugins-client.d.ts +2 -0
- package/dist/plugins-client.mjs +2 -0
- package/dist/plugins.d.mts +22 -0
- package/dist/plugins.d.ts +22 -0
- package/dist/plugins.mjs +22 -0
- package/dist/schema.d.mts +44 -0
- package/dist/schema.d.ts +44 -0
- package/dist/schema.mjs +62 -0
- package/dist/sql-store.d.mts +51 -0
- package/dist/sql-store.d.ts +51 -0
- package/dist/sql-store.mjs +162 -0
- package/dist/store.d.mts +66 -0
- package/dist/store.d.ts +66 -0
- package/dist/store.mjs +170 -0
- package/dist/turnstile-middleware.d.mts +80 -0
- package/dist/turnstile-middleware.d.ts +80 -0
- package/dist/turnstile-middleware.mjs +45 -0
- package/dist/turnstile.d.mts +98 -0
- package/dist/turnstile.d.ts +98 -0
- package/dist/turnstile.mjs +61 -0
- package/package.json +80 -18
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const TURNSTILE_VERIFY_ENDPOINT = "https://challenges.cloudflare.com/turnstile/v0/siteverify";
|
|
2
|
+
const asString = (value) => typeof value === "string" ? value : void 0;
|
|
3
|
+
const asStringArray = (value) => Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
|
|
4
|
+
const verifyTurnstile = async ({
|
|
5
|
+
expectedAction,
|
|
6
|
+
expectedHostname,
|
|
7
|
+
fetch = globalThis.fetch,
|
|
8
|
+
remoteip,
|
|
9
|
+
secret,
|
|
10
|
+
token
|
|
11
|
+
}) => {
|
|
12
|
+
const body = new URLSearchParams({ response: token, secret });
|
|
13
|
+
if (remoteip !== void 0 && remoteip !== "") {
|
|
14
|
+
body.set("remoteip", remoteip);
|
|
15
|
+
}
|
|
16
|
+
let response;
|
|
17
|
+
try {
|
|
18
|
+
response = await fetch(TURNSTILE_VERIFY_ENDPOINT, {
|
|
19
|
+
body: body.toString(),
|
|
20
|
+
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
21
|
+
method: "POST"
|
|
22
|
+
});
|
|
23
|
+
} catch (error) {
|
|
24
|
+
throw Object.assign(new Error("turnstile siteverify request failed"), {
|
|
25
|
+
cause: error,
|
|
26
|
+
code: "SERVICE_UNAVAILABLE",
|
|
27
|
+
name: "LunoraError",
|
|
28
|
+
status: 503
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if (!response.ok) {
|
|
32
|
+
throw Object.assign(new Error(`turnstile siteverify returned ${String(response.status)}`), {
|
|
33
|
+
code: "SERVICE_UNAVAILABLE",
|
|
34
|
+
name: "LunoraError",
|
|
35
|
+
status: 503
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const raw = await response.json();
|
|
39
|
+
const action = asString(raw.action);
|
|
40
|
+
const hostname = asString(raw.hostname);
|
|
41
|
+
const errorCodes = asStringArray(raw["error-codes"]);
|
|
42
|
+
let success = raw.success === true;
|
|
43
|
+
if (success && expectedHostname !== void 0 && hostname !== expectedHostname) {
|
|
44
|
+
success = false;
|
|
45
|
+
errorCodes.push("hostname-mismatch");
|
|
46
|
+
}
|
|
47
|
+
if (success && expectedAction !== void 0 && action !== expectedAction) {
|
|
48
|
+
success = false;
|
|
49
|
+
errorCodes.push("action-mismatch");
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
action,
|
|
53
|
+
cdata: asString(raw.cdata),
|
|
54
|
+
challengeTs: asString(raw.challenge_ts),
|
|
55
|
+
errorCodes,
|
|
56
|
+
hostname,
|
|
57
|
+
success
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export { TURNSTILE_VERIFY_ENDPOINT, verifyTurnstile };
|
package/package.json
CHANGED
|
@@ -1,31 +1,93 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/auth",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0-alpha.1",
|
|
4
|
+
"description": "Auth for Lunora — a thin better-auth wrapper: email/password, OAuth, plugins, D1-backed",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"auth",
|
|
7
|
+
"better-auth",
|
|
8
|
+
"cloudflare",
|
|
9
|
+
"durable-objects",
|
|
10
|
+
"lunora",
|
|
11
|
+
"oauth",
|
|
12
|
+
"session",
|
|
13
|
+
"workers"
|
|
14
|
+
],
|
|
6
15
|
"homepage": "https://lunora.sh",
|
|
16
|
+
"bugs": "https://github.com/anolilab/lunora/issues",
|
|
17
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
18
|
+
"author": {
|
|
19
|
+
"name": "Daniel Bannert",
|
|
20
|
+
"email": "d.bannert@anolilab.de"
|
|
21
|
+
},
|
|
7
22
|
"repository": {
|
|
8
23
|
"type": "git",
|
|
9
24
|
"url": "git+https://github.com/anolilab/lunora.git",
|
|
10
25
|
"directory": "packages/auth"
|
|
11
26
|
},
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"cloudflare",
|
|
18
|
-
"workers",
|
|
19
|
-
"durable-objects",
|
|
20
|
-
"auth",
|
|
21
|
-
"better-auth",
|
|
22
|
-
"oauth",
|
|
23
|
-
"session"
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"__assets__",
|
|
30
|
+
"README.md",
|
|
31
|
+
"LICENSE.md"
|
|
24
32
|
],
|
|
33
|
+
"type": "module",
|
|
34
|
+
"sideEffects": false,
|
|
35
|
+
"main": "./dist/index.mjs",
|
|
36
|
+
"module": "./dist/index.mjs",
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"types": "./dist/index.d.ts",
|
|
41
|
+
"import": "./dist/index.mjs"
|
|
42
|
+
},
|
|
43
|
+
"./plugins": {
|
|
44
|
+
"types": "./dist/plugins.d.ts",
|
|
45
|
+
"import": "./dist/plugins.mjs"
|
|
46
|
+
},
|
|
47
|
+
"./plugins/client": {
|
|
48
|
+
"types": "./dist/plugins-client.d.ts",
|
|
49
|
+
"import": "./dist/plugins-client.mjs"
|
|
50
|
+
},
|
|
51
|
+
"./middleware": {
|
|
52
|
+
"types": "./dist/middleware.d.ts",
|
|
53
|
+
"import": "./dist/middleware.mjs"
|
|
54
|
+
},
|
|
55
|
+
"./turnstile": {
|
|
56
|
+
"types": "./dist/turnstile.d.ts",
|
|
57
|
+
"import": "./dist/turnstile.mjs"
|
|
58
|
+
},
|
|
59
|
+
"./turnstile-middleware": {
|
|
60
|
+
"types": "./dist/turnstile-middleware.d.ts",
|
|
61
|
+
"import": "./dist/turnstile-middleware.mjs"
|
|
62
|
+
},
|
|
63
|
+
"./schema": {
|
|
64
|
+
"types": "./dist/schema.d.ts",
|
|
65
|
+
"import": "./dist/schema.mjs"
|
|
66
|
+
},
|
|
67
|
+
"./adapter": {
|
|
68
|
+
"types": "./dist/adapter.d.ts",
|
|
69
|
+
"import": "./dist/adapter.mjs"
|
|
70
|
+
},
|
|
71
|
+
"./store": {
|
|
72
|
+
"types": "./dist/store.d.ts",
|
|
73
|
+
"import": "./dist/store.mjs"
|
|
74
|
+
},
|
|
75
|
+
"./sql-store": {
|
|
76
|
+
"types": "./dist/sql-store.d.ts",
|
|
77
|
+
"import": "./dist/sql-store.mjs"
|
|
78
|
+
},
|
|
79
|
+
"./package.json": "./package.json"
|
|
80
|
+
},
|
|
25
81
|
"publishConfig": {
|
|
26
82
|
"access": "public"
|
|
27
83
|
},
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
84
|
+
"dependencies": {
|
|
85
|
+
"@better-auth/passkey": "^1.6.19",
|
|
86
|
+
"@lunora/server": "1.0.0-alpha.1",
|
|
87
|
+
"@lunora/values": "1.0.0-alpha.1",
|
|
88
|
+
"better-auth": "^1.6.19"
|
|
89
|
+
},
|
|
90
|
+
"engines": {
|
|
91
|
+
"node": "^22.15.0 || >=24.11.0"
|
|
92
|
+
}
|
|
31
93
|
}
|