@draftlab/auth 0.4.1 → 0.6.0

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 (104) hide show
  1. package/dist/adapters/{node.js → node.mjs} +2 -4
  2. package/dist/{allow.js → allow.mjs} +1 -1
  3. package/dist/{client.d.ts → client.d.mts} +47 -4
  4. package/dist/{client.js → client.mjs} +81 -10
  5. package/dist/{core.d.ts → core.d.mts} +10 -10
  6. package/dist/{core.js → core.mjs} +104 -56
  7. package/dist/index.d.mts +2 -0
  8. package/dist/index.mjs +3 -0
  9. package/dist/{keys.d.ts → keys.d.mts} +1 -1
  10. package/dist/{keys.js → keys.mjs} +6 -8
  11. package/dist/{pkce.js → pkce.mjs} +5 -10
  12. package/dist/plugin/{builder.d.ts → builder.d.mts} +1 -1
  13. package/dist/plugin/{manager.d.ts → manager.d.mts} +2 -2
  14. package/dist/plugin/{manager.js → manager.mjs} +1 -1
  15. package/dist/plugin/{plugin.d.ts → plugin.d.mts} +1 -1
  16. package/dist/plugin/{types.d.ts → types.d.mts} +1 -1
  17. package/dist/provider/apple.d.mts +105 -0
  18. package/dist/provider/apple.mjs +151 -0
  19. package/dist/provider/{code.d.ts → code.d.mts} +1 -1
  20. package/dist/provider/{code.js → code.mjs} +2 -3
  21. package/dist/provider/{discord.d.ts → discord.d.mts} +2 -2
  22. package/dist/provider/{discord.js → discord.mjs} +59 -1
  23. package/dist/provider/{facebook.d.ts → facebook.d.mts} +2 -2
  24. package/dist/provider/{facebook.js → facebook.mjs} +57 -1
  25. package/dist/provider/{github.d.ts → github.d.mts} +2 -2
  26. package/dist/provider/{github.js → github.mjs} +79 -1
  27. package/dist/provider/gitlab.d.mts +100 -0
  28. package/dist/provider/gitlab.mjs +128 -0
  29. package/dist/provider/{google.d.ts → google.d.mts} +2 -2
  30. package/dist/provider/{google.js → google.mjs} +45 -1
  31. package/dist/provider/{linkedin.d.ts → linkedin.d.mts} +2 -2
  32. package/dist/provider/{linkedin.js → linkedin.mjs} +57 -1
  33. package/dist/provider/{magiclink.d.ts → magiclink.d.mts} +1 -1
  34. package/dist/provider/{magiclink.js → magiclink.mjs} +4 -6
  35. package/dist/provider/{microsoft.d.ts → microsoft.d.mts} +2 -2
  36. package/dist/provider/{microsoft.js → microsoft.mjs} +68 -1
  37. package/dist/provider/{oauth2.d.ts → oauth2.d.mts} +1 -1
  38. package/dist/provider/{oauth2.js → oauth2.mjs} +4 -4
  39. package/dist/provider/{passkey.d.ts → passkey.d.mts} +1 -1
  40. package/dist/provider/{passkey.js → passkey.mjs} +8 -13
  41. package/dist/provider/{password.d.ts → password.d.mts} +1 -1
  42. package/dist/provider/{password.js → password.mjs} +31 -44
  43. package/dist/provider/{provider.d.ts → provider.d.mts} +1 -1
  44. package/dist/provider/reddit.d.mts +101 -0
  45. package/dist/provider/reddit.mjs +114 -0
  46. package/dist/provider/slack.d.mts +108 -0
  47. package/dist/provider/slack.mjs +125 -0
  48. package/dist/provider/spotify.d.mts +107 -0
  49. package/dist/provider/spotify.mjs +122 -0
  50. package/dist/provider/{totp.d.ts → totp.d.mts} +1 -1
  51. package/dist/provider/{totp.js → totp.mjs} +51 -14
  52. package/dist/provider/twitch.d.mts +102 -0
  53. package/dist/provider/twitch.mjs +118 -0
  54. package/dist/{random.js → random.mjs} +1 -2
  55. package/dist/revocation.d.mts +55 -0
  56. package/dist/revocation.mjs +63 -0
  57. package/dist/storage/{memory.d.ts → memory.d.mts} +1 -1
  58. package/dist/storage/{memory.js → memory.mjs} +3 -5
  59. package/dist/storage/{storage.d.ts → storage.d.mts} +27 -10
  60. package/dist/storage/storage.mjs +104 -0
  61. package/dist/storage/{turso.d.ts → turso.d.mts} +1 -1
  62. package/dist/storage/{turso.js → turso.mjs} +1 -1
  63. package/dist/storage/{unstorage.d.ts → unstorage.d.mts} +1 -1
  64. package/dist/storage/{unstorage.js → unstorage.mjs} +11 -4
  65. package/dist/{subject.d.ts → subject.d.mts} +1 -1
  66. package/dist/ui/{base.d.ts → base.d.mts} +1 -1
  67. package/dist/ui/{base.js → base.mjs} +1 -1
  68. package/dist/ui/{code.d.ts → code.d.mts} +1 -1
  69. package/dist/ui/{code.js → code.mjs} +3 -4
  70. package/dist/ui/{magiclink.d.ts → magiclink.d.mts} +1 -1
  71. package/dist/ui/{magiclink.js → magiclink.mjs} +3 -4
  72. package/dist/ui/{passkey.d.ts → passkey.d.mts} +1 -1
  73. package/dist/ui/{passkey.js → passkey.mjs} +2 -2
  74. package/dist/ui/{password.d.ts → password.d.mts} +1 -1
  75. package/dist/ui/{password.js → password.mjs} +3 -4
  76. package/dist/ui/{select.d.ts → select.d.mts} +1 -1
  77. package/dist/ui/{select.js → select.mjs} +2 -2
  78. package/dist/ui/{totp.d.ts → totp.d.mts} +1 -1
  79. package/dist/ui/{totp.js → totp.mjs} +2 -2
  80. package/dist/{util.js → util.mjs} +2 -5
  81. package/package.json +17 -16
  82. package/dist/index.d.ts +0 -2
  83. package/dist/index.js +0 -3
  84. package/dist/storage/storage.js +0 -62
  85. /package/dist/adapters/{node.d.ts → node.d.mts} +0 -0
  86. /package/dist/{allow.d.ts → allow.d.mts} +0 -0
  87. /package/dist/{error.d.ts → error.d.mts} +0 -0
  88. /package/dist/{error.js → error.mjs} +0 -0
  89. /package/dist/{pkce.d.ts → pkce.d.mts} +0 -0
  90. /package/dist/plugin/{builder.js → builder.mjs} +0 -0
  91. /package/dist/plugin/{plugin.js → plugin.mjs} +0 -0
  92. /package/dist/plugin/{types.js → types.mjs} +0 -0
  93. /package/dist/provider/{provider.js → provider.mjs} +0 -0
  94. /package/dist/{random.d.ts → random.d.mts} +0 -0
  95. /package/dist/{subject.js → subject.mjs} +0 -0
  96. /package/dist/themes/{theme.d.ts → theme.d.mts} +0 -0
  97. /package/dist/themes/{theme.js → theme.mjs} +0 -0
  98. /package/dist/{types.d.ts → types.d.mts} +0 -0
  99. /package/dist/{types.js → types.mjs} +0 -0
  100. /package/dist/ui/{form.d.ts → form.d.mts} +0 -0
  101. /package/dist/ui/{form.js → form.mjs} +0 -0
  102. /package/dist/ui/{icon.d.ts → icon.d.mts} +0 -0
  103. /package/dist/ui/{icon.js → icon.mjs} +0 -0
  104. /package/dist/{util.d.ts → util.d.mts} +0 -0
@@ -1,4 +1,4 @@
1
- import { joinKey, splitKey } from "./storage.js";
1
+ import { joinKey, splitKey } from "./storage.mjs";
2
2
 
3
3
  //#region src/storage/turso.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { StorageAdapter } from "./storage.js";
1
+ import { StorageAdapter } from "./storage.mjs";
2
2
  import { Driver } from "unstorage";
3
3
 
4
4
  //#region src/storage/unstorage.d.ts
@@ -1,8 +1,15 @@
1
- import { joinKey, splitKey } from "./storage.js";
1
+ import { joinKey, splitKey } from "./storage.mjs";
2
2
  import { createStorage } from "unstorage";
3
3
 
4
4
  //#region src/storage/unstorage.ts
5
5
  /**
6
+ * Universal storage adapter for Draft Auth using Unstorage drivers.
7
+ * Provides seamless integration with any Unstorage-compatible backend including
8
+ * Redis, Cloudflare KV, Vercel KV, and more.
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+ /**
6
13
  * Creates a Draft Auth storage adapter using Unstorage drivers.
7
14
  * Supports automatic expiration, error handling, and any Unstorage driver.
8
15
  *
@@ -35,15 +42,15 @@ const UnStorage = ({ driver } = {}) => {
35
42
  try {
36
43
  const keyPath = joinKey(key);
37
44
  const entry = await store.getItem(keyPath);
38
- if (!entry) return void 0;
45
+ if (!entry) return;
39
46
  if (entry.expiry && Date.now() >= entry.expiry) {
40
47
  store.removeItem(keyPath).catch(() => {});
41
- return void 0;
48
+ return;
42
49
  }
43
50
  return entry.value;
44
51
  } catch (error) {
45
52
  console.error("UnStorage get error:", error);
46
- return void 0;
53
+ return;
47
54
  }
48
55
  },
49
56
  async set(key, value, expiry) {
@@ -1,4 +1,4 @@
1
- import { Prettify } from "./util.js";
1
+ import { Prettify } from "./util.mjs";
2
2
  import { StandardSchemaV1 } from "@standard-schema/spec";
3
3
 
4
4
  //#region src/subject.d.ts
@@ -1,4 +1,4 @@
1
- import { Theme } from "../themes/theme.js";
1
+ import { Theme } from "../themes/theme.mjs";
2
2
  import * as preact0 from "preact";
3
3
  import { ComponentChildren } from "preact";
4
4
 
@@ -1,4 +1,4 @@
1
- import { getTheme } from "../themes/theme.js";
1
+ import { getTheme } from "../themes/theme.mjs";
2
2
  import { render } from "preact-render-to-string";
3
3
  import { jsx, jsxs } from "preact/jsx-runtime";
4
4
 
@@ -1,4 +1,4 @@
1
- import { CodeProviderOptions } from "../provider/code.js";
1
+ import { CodeProviderOptions } from "../provider/code.mjs";
2
2
 
3
3
  //#region src/ui/code.d.ts
4
4
 
@@ -1,5 +1,5 @@
1
- import { Layout, renderToHTML } from "./base.js";
2
- import { FormAlert } from "./form.js";
1
+ import { Layout, renderToHTML } from "./base.mjs";
2
+ import { FormAlert } from "./form.mjs";
3
3
  import { jsx, jsxs } from "preact/jsx-runtime";
4
4
 
5
5
  //#region src/ui/code.tsx
@@ -34,9 +34,8 @@ const getErrorMessage = (error, copy) => {
34
34
  const getSuccessMessage = (state, copy) => {
35
35
  if (state.type === "start" || !state.claims) return void 0;
36
36
  const contact = state.claims.email || state.claims.phone || "";
37
- const prefix = state.resend ? copy.code_resent : copy.code_sent;
38
37
  return {
39
- message: `${prefix}${contact}`,
38
+ message: `${state.resend ? copy.code_resent : copy.code_sent}${contact}`,
40
39
  contact
41
40
  };
42
41
  };
@@ -1,4 +1,4 @@
1
- import { MagicLinkConfig } from "../provider/magiclink.js";
1
+ import { MagicLinkConfig } from "../provider/magiclink.mjs";
2
2
 
3
3
  //#region src/ui/magiclink.d.ts
4
4
 
@@ -1,5 +1,5 @@
1
- import { Layout, renderToHTML } from "./base.js";
2
- import { FormAlert } from "./form.js";
1
+ import { Layout, renderToHTML } from "./base.mjs";
2
+ import { FormAlert } from "./form.mjs";
3
3
  import { jsx, jsxs } from "preact/jsx-runtime";
4
4
 
5
5
  //#region src/ui/magiclink.tsx
@@ -32,9 +32,8 @@ const getErrorMessage = (error, copy) => {
32
32
  const getSuccessMessage = (state, copy, mode) => {
33
33
  if (state.type === "start" || !state.claims) return void 0;
34
34
  const contact = state.claims[mode] || "";
35
- const prefix = state.resend ? copy.link_resent : copy.link_sent;
36
35
  return {
37
- message: `${prefix}${contact}`,
36
+ message: `${state.resend ? copy.link_resent : copy.link_sent}${contact}`,
38
37
  contact
39
38
  };
40
39
  };
@@ -1,4 +1,4 @@
1
- import { PasskeyProviderConfig } from "../provider/passkey.js";
1
+ import { PasskeyProviderConfig } from "../provider/passkey.mjs";
2
2
 
3
3
  //#region src/ui/passkey.d.ts
4
4
 
@@ -1,5 +1,5 @@
1
- import { Layout, renderToHTML } from "./base.js";
2
- import { FormAlert } from "./form.js";
1
+ import { Layout, renderToHTML } from "./base.mjs";
2
+ import { FormAlert } from "./form.mjs";
3
3
  import { jsx, jsxs } from "preact/jsx-runtime";
4
4
 
5
5
  //#region src/ui/passkey.tsx
@@ -1,4 +1,4 @@
1
- import { PasswordConfig } from "../provider/password.js";
1
+ import { PasswordConfig } from "../provider/password.mjs";
2
2
 
3
3
  //#region src/ui/password.d.ts
4
4
 
@@ -1,5 +1,5 @@
1
- import { Layout, renderToHTML } from "./base.js";
2
- import { FormAlert } from "./form.js";
1
+ import { Layout, renderToHTML } from "./base.mjs";
2
+ import { FormAlert } from "./form.mjs";
3
3
  import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
4
4
 
5
5
  //#region src/ui/password.tsx
@@ -45,8 +45,7 @@ const PasswordUI = (options) => {
45
45
  const getErrorMessage = (error) => {
46
46
  if (!error?.type) return void 0;
47
47
  if (error.type === "validation_error" && "message" in error && error.message) return error.message;
48
- const errorKey = `error_${error.type}`;
49
- return copy[errorKey];
48
+ return copy[`error_${error.type}`];
50
49
  };
51
50
  /**
52
51
  * Renders the login form with email and password inputs
@@ -1,4 +1,4 @@
1
- import { Theme } from "../themes/theme.js";
1
+ import { Theme } from "../themes/theme.mjs";
2
2
 
3
3
  //#region src/ui/select.d.ts
4
4
 
@@ -1,5 +1,5 @@
1
- import { Layout, renderToHTML } from "./base.js";
2
- import { ICON_GITHUB, ICON_GOOGLE } from "./icon.js";
1
+ import { Layout, renderToHTML } from "./base.mjs";
2
+ import { ICON_GITHUB, ICON_GOOGLE } from "./icon.mjs";
3
3
  import { jsx, jsxs } from "preact/jsx-runtime";
4
4
 
5
5
  //#region src/ui/select.tsx
@@ -1,4 +1,4 @@
1
- import { TOTPProviderConfig } from "../provider/totp.js";
1
+ import { TOTPProviderConfig } from "../provider/totp.mjs";
2
2
 
3
3
  //#region src/ui/totp.d.ts
4
4
 
@@ -1,5 +1,5 @@
1
- import { Layout, renderToHTML } from "./base.js";
2
- import { FormAlert } from "./form.js";
1
+ import { Layout, renderToHTML } from "./base.mjs";
2
+ import { FormAlert } from "./form.mjs";
3
3
  import { jsx, jsxs } from "preact/jsx-runtime";
4
4
  import QRCode from "qrcode";
5
5
 
@@ -66,12 +66,9 @@ const isDomainMatch = (a, b) => {
66
66
  if (a === b) return true;
67
67
  const partsA = a.split(".");
68
68
  const partsB = b.split(".");
69
- const hasTwoPartTld = twoPartTlds.some((tld) => a.endsWith(`.${tld}`) || b.endsWith(`.${tld}`));
70
- const numParts = hasTwoPartTld ? -3 : -2;
69
+ const numParts = twoPartTlds.some((tld) => a.endsWith(`.${tld}`) || b.endsWith(`.${tld}`)) ? -3 : -2;
71
70
  const min = Math.min(partsA.length, partsB.length, numParts);
72
- const tailA = partsA.slice(min).join(".");
73
- const tailB = partsB.slice(min).join(".");
74
- return tailA === tailB;
71
+ return partsA.slice(min).join(".") === partsB.slice(min).join(".");
75
72
  };
76
73
  /**
77
74
  * Creates a lazy-evaluated function that caches the result of the first execution.
package/package.json CHANGED
@@ -1,22 +1,22 @@
1
1
  {
2
2
  "name": "@draftlab/auth",
3
- "version": "0.4.1",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "description": "Core implementation for @draftlab/auth",
6
6
  "author": "Matheus Pergoli",
7
- "main": "dist/index.js",
8
- "typings": "dist/index.d.ts",
7
+ "main": "dist/index.mjs",
8
+ "typings": "dist/index.d.mts",
9
9
  "files": [
10
10
  "dist"
11
11
  ],
12
12
  "exports": {
13
13
  ".": {
14
- "import": "./dist/index.js",
15
- "types": "./dist/index.d.ts"
14
+ "import": "./dist/index.mjs",
15
+ "types": "./dist/index.d.mts"
16
16
  },
17
17
  "./*": {
18
- "import": "./dist/*.js",
19
- "types": "./dist/*.d.ts"
18
+ "import": "./dist/*.mjs",
19
+ "types": "./dist/*.d.mts"
20
20
  }
21
21
  },
22
22
  "sideEffects": false,
@@ -37,10 +37,10 @@
37
37
  ],
38
38
  "license": "MIT",
39
39
  "devDependencies": {
40
- "@types/node": "^24.3.0",
41
- "@types/qrcode": "^1.5.5",
42
- "tsdown": "^0.14.1",
43
- "typescript": "^5.9.2",
40
+ "@types/node": "^24.10.1",
41
+ "@types/qrcode": "^1.5.6",
42
+ "tsdown": "^0.16.6",
43
+ "typescript": "^5.9.3",
44
44
  "@draftlab/tsconfig": "0.1.0"
45
45
  },
46
46
  "peerDependencies": {
@@ -56,14 +56,14 @@
56
56
  }
57
57
  },
58
58
  "dependencies": {
59
- "@simplewebauthn/server": "^13.1.2",
59
+ "@simplewebauthn/server": "^13.2.2",
60
60
  "@standard-schema/spec": "^1.0.0",
61
- "jose": "^6.0.12",
61
+ "jose": "^6.1.2",
62
62
  "otpauth": "^9.4.1",
63
- "preact": "^10.27.1",
64
- "preact-render-to-string": "^6.5.13",
63
+ "preact": "^10.27.2",
64
+ "preact-render-to-string": "^6.6.3",
65
65
  "qrcode": "^1.5.4",
66
- "@draftlab/auth-router": "0.0.6"
66
+ "@draftlab/auth-router": "0.1.0"
67
67
  },
68
68
  "engines": {
69
69
  "node": ">=18"
@@ -73,6 +73,7 @@
73
73
  },
74
74
  "scripts": {
75
75
  "build": "tsdown",
76
+ "typecheck": "tsc --noEmit --emitDeclarationOnly false",
76
77
  "clean": "rm -rf dist .turbo node_modules"
77
78
  }
78
79
  }
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { issuer } from "./core.js";
2
- export { issuer };
package/dist/index.js DELETED
@@ -1,3 +0,0 @@
1
- import { issuer } from "./core.js";
2
-
3
- export { issuer };
@@ -1,62 +0,0 @@
1
- //#region src/storage/storage.ts
2
- /**
3
- * ASCII unit separator character used to join key segments.
4
- * Using a control character ensures it won't conflict with user data.
5
- */
6
- const SEPARATOR = String.fromCharCode(31);
7
- /**
8
- * Joins an array of key segments into a single string using the separator.
9
- *
10
- * @param key - Array of key segments to join
11
- * @returns Single string representing the full key path
12
- *
13
- * @example
14
- * ```ts
15
- * joinKey(['user', 'session', '123'])
16
- * // Returns: "user\x1fsession\x1f123"
17
- * ```
18
- */
19
- const joinKey = (key) => {
20
- return key.join(SEPARATOR);
21
- };
22
- /**
23
- * Splits a joined key string back into its component segments.
24
- *
25
- * @param key - Joined key string to split
26
- * @returns Array of individual key segments
27
- *
28
- * @example
29
- * ```ts
30
- * splitKey("user\x1fsession\x1f123")
31
- * // Returns: ['user', 'session', '123']
32
- * ```
33
- */
34
- const splitKey = (key) => {
35
- return key.split(SEPARATOR);
36
- };
37
- /**
38
- * High-level storage operations with key encoding and type safety.
39
- * Provides a convenient interface over storage adapters with additional features
40
- * like TTL conversion and key sanitization.
41
- */
42
- const Storage = {
43
- encode: (key) => {
44
- return key.map((segment) => segment.replaceAll(SEPARATOR, ""));
45
- },
46
- get: (adapter, key) => {
47
- return adapter.get(Storage.encode(key));
48
- },
49
- set: (adapter, key, value, ttlSeconds) => {
50
- const expiry = ttlSeconds ? new Date(Date.now() + ttlSeconds * 1e3) : void 0;
51
- return adapter.set(Storage.encode(key), value, expiry);
52
- },
53
- remove: (adapter, key) => {
54
- return adapter.remove(Storage.encode(key));
55
- },
56
- scan: (adapter, prefix) => {
57
- return adapter.scan(Storage.encode(prefix));
58
- }
59
- };
60
-
61
- //#endregion
62
- export { Storage, joinKey, splitKey };
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes