@lunora/auth 0.0.0 → 1.0.0-alpha.2

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.
Files changed (41) hide show
  1. package/LICENSE.md +105 -0
  2. package/README.md +125 -9
  3. package/__assets__/package-og.svg +14 -0
  4. package/dist/adapter.d.mts +43 -0
  5. package/dist/adapter.d.ts +43 -0
  6. package/dist/adapter.mjs +47 -0
  7. package/dist/index.d.mts +386 -0
  8. package/dist/index.d.ts +386 -0
  9. package/dist/index.mjs +12 -0
  10. package/dist/middleware.d.mts +189 -0
  11. package/dist/middleware.d.ts +189 -0
  12. package/dist/middleware.mjs +53 -0
  13. package/dist/packem_shared/DEFAULT_AUTH_BASE_PATH-DjcUWEQl.mjs +11 -0
  14. package/dist/packem_shared/LunoraAuthAdminError-BxrfEeA_.mjs +249 -0
  15. package/dist/packem_shared/compileMigrationsSql-wZH3oXDu.mjs +28 -0
  16. package/dist/packem_shared/create-auth.d-M36jwG_Y.d.mts +58 -0
  17. package/dist/packem_shared/create-auth.d-M36jwG_Y.d.ts +58 -0
  18. package/dist/packem_shared/createAuth-B-tvsvQU.mjs +56 -0
  19. package/dist/packem_shared/sessionPresets-B95rXrd8.mjs +35 -0
  20. package/dist/plugins-client.d.mts +2 -0
  21. package/dist/plugins-client.d.ts +2 -0
  22. package/dist/plugins-client.mjs +2 -0
  23. package/dist/plugins.d.mts +22 -0
  24. package/dist/plugins.d.ts +22 -0
  25. package/dist/plugins.mjs +22 -0
  26. package/dist/schema.d.mts +44 -0
  27. package/dist/schema.d.ts +44 -0
  28. package/dist/schema.mjs +62 -0
  29. package/dist/sql-store.d.mts +51 -0
  30. package/dist/sql-store.d.ts +51 -0
  31. package/dist/sql-store.mjs +162 -0
  32. package/dist/store.d.mts +66 -0
  33. package/dist/store.d.ts +66 -0
  34. package/dist/store.mjs +170 -0
  35. package/dist/turnstile-middleware.d.mts +80 -0
  36. package/dist/turnstile-middleware.d.ts +80 -0
  37. package/dist/turnstile-middleware.mjs +45 -0
  38. package/dist/turnstile.d.mts +98 -0
  39. package/dist/turnstile.d.ts +98 -0
  40. package/dist/turnstile.mjs +61 -0
  41. 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.0",
4
- "description": "Cookie-session auth for Lunora: PBKDF2 email/password plus OAuth (PKCE), D1-backed, sessions in SessionDO",
5
- "license": "FSL-1.1-Apache-2.0",
3
+ "version": "1.0.0-alpha.2",
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
- "bugs": {
13
- "url": "https://github.com/anolilab/lunora/issues"
14
- },
15
- "keywords": [
16
- "lunora",
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
- "files": [
29
- "README.md"
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
  }