@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.
- package/dist/adapters/{node.js → node.mjs} +2 -4
- package/dist/{allow.js → allow.mjs} +1 -1
- package/dist/{client.d.ts → client.d.mts} +47 -4
- package/dist/{client.js → client.mjs} +81 -10
- package/dist/{core.d.ts → core.d.mts} +10 -10
- package/dist/{core.js → core.mjs} +104 -56
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +3 -0
- package/dist/{keys.d.ts → keys.d.mts} +1 -1
- package/dist/{keys.js → keys.mjs} +6 -8
- package/dist/{pkce.js → pkce.mjs} +5 -10
- package/dist/plugin/{builder.d.ts → builder.d.mts} +1 -1
- package/dist/plugin/{manager.d.ts → manager.d.mts} +2 -2
- package/dist/plugin/{manager.js → manager.mjs} +1 -1
- package/dist/plugin/{plugin.d.ts → plugin.d.mts} +1 -1
- package/dist/plugin/{types.d.ts → types.d.mts} +1 -1
- package/dist/provider/apple.d.mts +105 -0
- package/dist/provider/apple.mjs +151 -0
- package/dist/provider/{code.d.ts → code.d.mts} +1 -1
- package/dist/provider/{code.js → code.mjs} +2 -3
- package/dist/provider/{discord.d.ts → discord.d.mts} +2 -2
- package/dist/provider/{discord.js → discord.mjs} +59 -1
- package/dist/provider/{facebook.d.ts → facebook.d.mts} +2 -2
- package/dist/provider/{facebook.js → facebook.mjs} +57 -1
- package/dist/provider/{github.d.ts → github.d.mts} +2 -2
- package/dist/provider/{github.js → github.mjs} +79 -1
- package/dist/provider/gitlab.d.mts +100 -0
- package/dist/provider/gitlab.mjs +128 -0
- package/dist/provider/{google.d.ts → google.d.mts} +2 -2
- package/dist/provider/{google.js → google.mjs} +45 -1
- package/dist/provider/{linkedin.d.ts → linkedin.d.mts} +2 -2
- package/dist/provider/{linkedin.js → linkedin.mjs} +57 -1
- package/dist/provider/{magiclink.d.ts → magiclink.d.mts} +1 -1
- package/dist/provider/{magiclink.js → magiclink.mjs} +4 -6
- package/dist/provider/{microsoft.d.ts → microsoft.d.mts} +2 -2
- package/dist/provider/{microsoft.js → microsoft.mjs} +68 -1
- package/dist/provider/{oauth2.d.ts → oauth2.d.mts} +1 -1
- package/dist/provider/{oauth2.js → oauth2.mjs} +4 -4
- package/dist/provider/{passkey.d.ts → passkey.d.mts} +1 -1
- package/dist/provider/{passkey.js → passkey.mjs} +8 -13
- package/dist/provider/{password.d.ts → password.d.mts} +1 -1
- package/dist/provider/{password.js → password.mjs} +31 -44
- package/dist/provider/{provider.d.ts → provider.d.mts} +1 -1
- package/dist/provider/reddit.d.mts +101 -0
- package/dist/provider/reddit.mjs +114 -0
- package/dist/provider/slack.d.mts +108 -0
- package/dist/provider/slack.mjs +125 -0
- package/dist/provider/spotify.d.mts +107 -0
- package/dist/provider/spotify.mjs +122 -0
- package/dist/provider/{totp.d.ts → totp.d.mts} +1 -1
- package/dist/provider/{totp.js → totp.mjs} +51 -14
- package/dist/provider/twitch.d.mts +102 -0
- package/dist/provider/twitch.mjs +118 -0
- package/dist/{random.js → random.mjs} +1 -2
- package/dist/revocation.d.mts +55 -0
- package/dist/revocation.mjs +63 -0
- package/dist/storage/{memory.d.ts → memory.d.mts} +1 -1
- package/dist/storage/{memory.js → memory.mjs} +3 -5
- package/dist/storage/{storage.d.ts → storage.d.mts} +27 -10
- package/dist/storage/storage.mjs +104 -0
- package/dist/storage/{turso.d.ts → turso.d.mts} +1 -1
- package/dist/storage/{turso.js → turso.mjs} +1 -1
- package/dist/storage/{unstorage.d.ts → unstorage.d.mts} +1 -1
- package/dist/storage/{unstorage.js → unstorage.mjs} +11 -4
- package/dist/{subject.d.ts → subject.d.mts} +1 -1
- package/dist/ui/{base.d.ts → base.d.mts} +1 -1
- package/dist/ui/{base.js → base.mjs} +1 -1
- package/dist/ui/{code.d.ts → code.d.mts} +1 -1
- package/dist/ui/{code.js → code.mjs} +3 -4
- package/dist/ui/{magiclink.d.ts → magiclink.d.mts} +1 -1
- package/dist/ui/{magiclink.js → magiclink.mjs} +3 -4
- package/dist/ui/{passkey.d.ts → passkey.d.mts} +1 -1
- package/dist/ui/{passkey.js → passkey.mjs} +2 -2
- package/dist/ui/{password.d.ts → password.d.mts} +1 -1
- package/dist/ui/{password.js → password.mjs} +3 -4
- package/dist/ui/{select.d.ts → select.d.mts} +1 -1
- package/dist/ui/{select.js → select.mjs} +2 -2
- package/dist/ui/{totp.d.ts → totp.d.mts} +1 -1
- package/dist/ui/{totp.js → totp.mjs} +2 -2
- package/dist/{util.js → util.mjs} +2 -5
- package/package.json +17 -16
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -3
- package/dist/storage/storage.js +0 -62
- /package/dist/adapters/{node.d.ts → node.d.mts} +0 -0
- /package/dist/{allow.d.ts → allow.d.mts} +0 -0
- /package/dist/{error.d.ts → error.d.mts} +0 -0
- /package/dist/{error.js → error.mjs} +0 -0
- /package/dist/{pkce.d.ts → pkce.d.mts} +0 -0
- /package/dist/plugin/{builder.js → builder.mjs} +0 -0
- /package/dist/plugin/{plugin.js → plugin.mjs} +0 -0
- /package/dist/plugin/{types.js → types.mjs} +0 -0
- /package/dist/provider/{provider.js → provider.mjs} +0 -0
- /package/dist/{random.d.ts → random.d.mts} +0 -0
- /package/dist/{subject.js → subject.mjs} +0 -0
- /package/dist/themes/{theme.d.ts → theme.d.mts} +0 -0
- /package/dist/themes/{theme.js → theme.mjs} +0 -0
- /package/dist/{types.d.ts → types.d.mts} +0 -0
- /package/dist/{types.js → types.mjs} +0 -0
- /package/dist/ui/{form.d.ts → form.d.mts} +0 -0
- /package/dist/ui/{form.js → form.mjs} +0 -0
- /package/dist/ui/{icon.d.ts → icon.d.mts} +0 -0
- /package/dist/ui/{icon.js → icon.mjs} +0 -0
- /package/dist/{util.d.ts → util.d.mts} +0 -0
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import { joinKey, splitKey } from "./storage.
|
|
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
|
|
45
|
+
if (!entry) return;
|
|
39
46
|
if (entry.expiry && Date.now() >= entry.expiry) {
|
|
40
47
|
store.removeItem(keyPath).catch(() => {});
|
|
41
|
-
return
|
|
48
|
+
return;
|
|
42
49
|
}
|
|
43
50
|
return entry.value;
|
|
44
51
|
} catch (error) {
|
|
45
52
|
console.error("UnStorage get error:", error);
|
|
46
|
-
return
|
|
53
|
+
return;
|
|
47
54
|
}
|
|
48
55
|
},
|
|
49
56
|
async set(key, value, expiry) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Layout, renderToHTML } from "./base.
|
|
2
|
-
import { FormAlert } from "./form.
|
|
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: `${
|
|
38
|
+
message: `${state.resend ? copy.code_resent : copy.code_sent}${contact}`,
|
|
40
39
|
contact
|
|
41
40
|
};
|
|
42
41
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Layout, renderToHTML } from "./base.
|
|
2
|
-
import { FormAlert } from "./form.
|
|
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: `${
|
|
36
|
+
message: `${state.resend ? copy.link_resent : copy.link_sent}${contact}`,
|
|
38
37
|
contact
|
|
39
38
|
};
|
|
40
39
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Layout, renderToHTML } from "./base.
|
|
2
|
-
import { FormAlert } from "./form.
|
|
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,5 +1,5 @@
|
|
|
1
|
-
import { Layout, renderToHTML } from "./base.
|
|
2
|
-
import { FormAlert } from "./form.
|
|
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
|
-
|
|
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,5 +1,5 @@
|
|
|
1
|
-
import { Layout, renderToHTML } from "./base.
|
|
2
|
-
import { ICON_GITHUB, ICON_GOOGLE } from "./icon.
|
|
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,5 +1,5 @@
|
|
|
1
|
-
import { Layout, renderToHTML } from "./base.
|
|
2
|
-
import { FormAlert } from "./form.
|
|
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
|
|
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
|
-
|
|
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.
|
|
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.
|
|
8
|
-
"typings": "dist/index.d.
|
|
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.
|
|
15
|
-
"types": "./dist/index.d.
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"types": "./dist/index.d.mts"
|
|
16
16
|
},
|
|
17
17
|
"./*": {
|
|
18
|
-
"import": "./dist/*.
|
|
19
|
-
"types": "./dist/*.d.
|
|
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.
|
|
41
|
-
"@types/qrcode": "^1.5.
|
|
42
|
-
"tsdown": "^0.
|
|
43
|
-
"typescript": "^5.9.
|
|
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.
|
|
59
|
+
"@simplewebauthn/server": "^13.2.2",
|
|
60
60
|
"@standard-schema/spec": "^1.0.0",
|
|
61
|
-
"jose": "^6.
|
|
61
|
+
"jose": "^6.1.2",
|
|
62
62
|
"otpauth": "^9.4.1",
|
|
63
|
-
"preact": "^10.27.
|
|
64
|
-
"preact-render-to-string": "^6.
|
|
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
|
|
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
package/dist/index.js
DELETED
package/dist/storage/storage.js
DELETED
|
@@ -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
|