@draftlab/auth 0.15.0 → 0.16.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/esm/allow.js +26 -0
- package/dist/esm/client.js +254 -0
- package/dist/esm/core.js +597 -0
- package/dist/esm/css.d.js +0 -0
- package/dist/esm/error.js +88 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/keys.js +126 -0
- package/dist/esm/mutex.js +53 -0
- package/dist/esm/pkce.js +87 -0
- package/dist/esm/provider/apple.js +15 -0
- package/dist/esm/provider/code.js +62 -0
- package/dist/esm/provider/discord.js +15 -0
- package/dist/esm/provider/facebook.js +15 -0
- package/dist/esm/provider/github.js +15 -0
- package/dist/esm/provider/gitlab.js +15 -0
- package/dist/esm/provider/google.js +16 -0
- package/dist/esm/provider/linkedin.js +15 -0
- package/dist/esm/provider/magiclink.js +83 -0
- package/dist/esm/provider/microsoft.js +15 -0
- package/dist/esm/provider/oauth2.js +130 -0
- package/dist/esm/provider/password.js +331 -0
- package/dist/esm/provider/provider.js +18 -0
- package/dist/esm/provider/reddit.js +15 -0
- package/dist/esm/provider/slack.js +15 -0
- package/dist/esm/provider/spotify.js +15 -0
- package/dist/esm/provider/twitch.js +15 -0
- package/dist/esm/provider/vercel.js +17 -0
- package/dist/esm/random.js +40 -0
- package/dist/esm/revocation.js +27 -0
- package/dist/esm/storage/memory.js +110 -0
- package/dist/esm/storage/storage.js +56 -0
- package/dist/esm/storage/turso.js +93 -0
- package/dist/esm/storage/unstorage.js +78 -0
- package/dist/esm/subject.js +7 -0
- package/dist/esm/themes/theme.js +115 -0
- package/dist/esm/toolkit/client.js +119 -0
- package/dist/esm/toolkit/index.js +25 -0
- package/dist/esm/toolkit/providers/facebook.js +11 -0
- package/dist/esm/toolkit/providers/github.js +11 -0
- package/dist/esm/toolkit/providers/google.js +11 -0
- package/dist/esm/toolkit/providers/strategy.js +0 -0
- package/dist/esm/toolkit/storage.js +81 -0
- package/dist/esm/toolkit/utils.js +18 -0
- package/dist/esm/types.js +0 -0
- package/dist/esm/ui/base.js +478 -0
- package/dist/esm/ui/code.js +186 -0
- package/dist/esm/ui/form.js +46 -0
- package/dist/esm/ui/icon.js +242 -0
- package/dist/esm/ui/magiclink.js +158 -0
- package/dist/esm/ui/password.js +435 -0
- package/dist/esm/ui/select.js +102 -0
- package/dist/esm/util.js +59 -0
- package/dist/{allow.d.mts → types/allow.d.ts} +9 -11
- package/dist/types/allow.d.ts.map +1 -0
- package/dist/types/client.d.ts +462 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/core.d.ts +113 -0
- package/dist/types/core.d.ts.map +1 -0
- package/dist/{error.d.mts → types/error.d.ts} +95 -97
- package/dist/types/error.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/{keys.d.mts → types/keys.d.ts} +20 -24
- package/dist/types/keys.d.ts.map +1 -0
- package/dist/types/mutex.d.ts +42 -0
- package/dist/types/mutex.d.ts.map +1 -0
- package/dist/{pkce.d.mts → types/pkce.d.ts} +10 -11
- package/dist/types/pkce.d.ts.map +1 -0
- package/dist/types/provider/apple.d.ts +197 -0
- package/dist/types/provider/apple.d.ts.map +1 -0
- package/dist/types/provider/code.d.ts +288 -0
- package/dist/types/provider/code.d.ts.map +1 -0
- package/dist/types/provider/discord.d.ts +206 -0
- package/dist/types/provider/discord.d.ts.map +1 -0
- package/dist/types/provider/facebook.d.ts +200 -0
- package/dist/types/provider/facebook.d.ts.map +1 -0
- package/dist/types/provider/github.d.ts +220 -0
- package/dist/types/provider/github.d.ts.map +1 -0
- package/dist/types/provider/gitlab.d.ts +180 -0
- package/dist/types/provider/gitlab.d.ts.map +1 -0
- package/dist/types/provider/google.d.ts +158 -0
- package/dist/types/provider/google.d.ts.map +1 -0
- package/dist/types/provider/linkedin.d.ts +190 -0
- package/dist/types/provider/linkedin.d.ts.map +1 -0
- package/dist/types/provider/magiclink.d.ts +141 -0
- package/dist/types/provider/magiclink.d.ts.map +1 -0
- package/dist/types/provider/microsoft.d.ts +247 -0
- package/dist/types/provider/microsoft.d.ts.map +1 -0
- package/dist/types/provider/oauth2.d.ts +229 -0
- package/dist/types/provider/oauth2.d.ts.map +1 -0
- package/dist/types/provider/password.d.ts +408 -0
- package/dist/types/provider/password.d.ts.map +1 -0
- package/dist/types/provider/provider.d.ts +226 -0
- package/dist/types/provider/provider.d.ts.map +1 -0
- package/dist/types/provider/reddit.d.ts +159 -0
- package/dist/types/provider/reddit.d.ts.map +1 -0
- package/dist/types/provider/slack.d.ts +171 -0
- package/dist/types/provider/slack.d.ts.map +1 -0
- package/dist/types/provider/spotify.d.ts +168 -0
- package/dist/types/provider/spotify.d.ts.map +1 -0
- package/dist/types/provider/twitch.d.ts +163 -0
- package/dist/types/provider/twitch.d.ts.map +1 -0
- package/dist/types/provider/vercel.d.ts +294 -0
- package/dist/types/provider/vercel.d.ts.map +1 -0
- package/dist/{random.d.mts → types/random.d.ts} +4 -6
- package/dist/types/random.d.ts.map +1 -0
- package/dist/types/revocation.d.ts +76 -0
- package/dist/types/revocation.d.ts.map +1 -0
- package/dist/{storage/memory.d.mts → types/storage/memory.d.ts} +17 -21
- package/dist/types/storage/memory.d.ts.map +1 -0
- package/dist/types/storage/storage.d.ts +177 -0
- package/dist/types/storage/storage.d.ts.map +1 -0
- package/dist/{storage/turso.d.mts → types/storage/turso.d.ts} +4 -8
- package/dist/types/storage/turso.d.ts.map +1 -0
- package/dist/{storage/unstorage.d.mts → types/storage/unstorage.d.ts} +12 -11
- package/dist/types/storage/unstorage.d.ts.map +1 -0
- package/dist/types/subject.d.ts +115 -0
- package/dist/types/subject.d.ts.map +1 -0
- package/dist/types/themes/theme.d.ts +207 -0
- package/dist/types/themes/theme.d.ts.map +1 -0
- package/dist/types/toolkit/client.d.ts +235 -0
- package/dist/types/toolkit/client.d.ts.map +1 -0
- package/dist/types/toolkit/index.d.ts +45 -0
- package/dist/types/toolkit/index.d.ts.map +1 -0
- package/dist/types/toolkit/providers/facebook.d.ts +8 -0
- package/dist/types/toolkit/providers/facebook.d.ts.map +1 -0
- package/dist/types/toolkit/providers/github.d.ts +8 -0
- package/dist/types/toolkit/providers/github.d.ts.map +1 -0
- package/dist/types/toolkit/providers/google.d.ts +8 -0
- package/dist/types/toolkit/providers/google.d.ts.map +1 -0
- package/dist/types/toolkit/providers/strategy.d.ts +38 -0
- package/dist/types/toolkit/providers/strategy.d.ts.map +1 -0
- package/dist/{toolkit/storage.d.mts → types/toolkit/storage.d.ts} +37 -39
- package/dist/types/toolkit/storage.d.ts.map +1 -0
- package/dist/{toolkit/utils.d.mts → types/toolkit/utils.d.ts} +2 -4
- package/dist/types/toolkit/utils.d.ts.map +1 -0
- package/dist/types/types.d.ts +92 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/ui/base.d.ts +18 -0
- package/dist/types/ui/base.d.ts.map +1 -0
- package/dist/types/ui/code.d.ts +43 -0
- package/dist/types/ui/code.d.ts.map +1 -0
- package/dist/types/ui/form.d.ts +24 -0
- package/dist/types/ui/form.d.ts.map +1 -0
- package/dist/types/ui/icon.d.ts +60 -0
- package/dist/types/ui/icon.d.ts.map +1 -0
- package/dist/types/ui/magiclink.d.ts +41 -0
- package/dist/types/ui/magiclink.d.ts.map +1 -0
- package/dist/types/ui/password.d.ts +43 -0
- package/dist/types/ui/password.d.ts.map +1 -0
- package/dist/types/ui/select.d.ts +33 -0
- package/dist/types/ui/select.d.ts.map +1 -0
- package/dist/{util.d.mts → types/util.d.ts} +11 -13
- package/dist/types/util.d.ts.map +1 -0
- package/package.json +10 -16
- package/dist/adapters/node.d.mts +0 -18
- package/dist/adapters/node.mjs +0 -69
- package/dist/allow.mjs +0 -63
- package/dist/client.d.mts +0 -456
- package/dist/client.mjs +0 -283
- package/dist/core.d.mts +0 -110
- package/dist/core.mjs +0 -595
- package/dist/error.mjs +0 -237
- package/dist/index.d.mts +0 -2
- package/dist/index.mjs +0 -3
- package/dist/keys.mjs +0 -146
- package/dist/mutex.d.mts +0 -44
- package/dist/mutex.mjs +0 -110
- package/dist/pkce.mjs +0 -157
- package/dist/provider/apple.d.mts +0 -111
- package/dist/provider/apple.mjs +0 -164
- package/dist/provider/code.d.mts +0 -228
- package/dist/provider/code.mjs +0 -246
- package/dist/provider/discord.d.mts +0 -146
- package/dist/provider/discord.mjs +0 -156
- package/dist/provider/facebook.d.mts +0 -142
- package/dist/provider/facebook.mjs +0 -150
- package/dist/provider/github.d.mts +0 -140
- package/dist/provider/github.mjs +0 -169
- package/dist/provider/gitlab.d.mts +0 -106
- package/dist/provider/gitlab.mjs +0 -147
- package/dist/provider/google.d.mts +0 -112
- package/dist/provider/google.mjs +0 -109
- package/dist/provider/linkedin.d.mts +0 -132
- package/dist/provider/linkedin.mjs +0 -142
- package/dist/provider/magiclink.d.mts +0 -89
- package/dist/provider/magiclink.mjs +0 -143
- package/dist/provider/microsoft.d.mts +0 -178
- package/dist/provider/microsoft.mjs +0 -177
- package/dist/provider/oauth2.d.mts +0 -176
- package/dist/provider/oauth2.mjs +0 -222
- package/dist/provider/passkey.d.mts +0 -104
- package/dist/provider/passkey.mjs +0 -320
- package/dist/provider/password.d.mts +0 -412
- package/dist/provider/password.mjs +0 -363
- package/dist/provider/provider.d.mts +0 -227
- package/dist/provider/provider.mjs +0 -44
- package/dist/provider/reddit.d.mts +0 -107
- package/dist/provider/reddit.mjs +0 -127
- package/dist/provider/slack.d.mts +0 -114
- package/dist/provider/slack.mjs +0 -138
- package/dist/provider/spotify.d.mts +0 -113
- package/dist/provider/spotify.mjs +0 -135
- package/dist/provider/totp.d.mts +0 -112
- package/dist/provider/totp.mjs +0 -191
- package/dist/provider/twitch.d.mts +0 -108
- package/dist/provider/twitch.mjs +0 -131
- package/dist/provider/vercel.d.mts +0 -177
- package/dist/provider/vercel.mjs +0 -230
- package/dist/random.mjs +0 -86
- package/dist/revocation.d.mts +0 -55
- package/dist/revocation.mjs +0 -63
- package/dist/router/context.d.mts +0 -21
- package/dist/router/context.mjs +0 -193
- package/dist/router/cookies.d.mts +0 -8
- package/dist/router/cookies.mjs +0 -13
- package/dist/router/index.d.mts +0 -21
- package/dist/router/index.mjs +0 -107
- package/dist/router/matcher.d.mts +0 -15
- package/dist/router/matcher.mjs +0 -76
- package/dist/router/middleware/cors.d.mts +0 -15
- package/dist/router/middleware/cors.mjs +0 -114
- package/dist/router/safe-request.d.mts +0 -52
- package/dist/router/safe-request.mjs +0 -160
- package/dist/router/types.d.mts +0 -67
- package/dist/router/types.mjs +0 -1
- package/dist/router/variables.d.mts +0 -12
- package/dist/router/variables.mjs +0 -20
- package/dist/storage/memory.mjs +0 -125
- package/dist/storage/storage.d.mts +0 -179
- package/dist/storage/storage.mjs +0 -104
- package/dist/storage/turso.mjs +0 -117
- package/dist/storage/unstorage.mjs +0 -103
- package/dist/subject.d.mts +0 -62
- package/dist/subject.mjs +0 -36
- package/dist/themes/theme.d.mts +0 -209
- package/dist/themes/theme.mjs +0 -120
- package/dist/toolkit/client.d.mts +0 -169
- package/dist/toolkit/client.mjs +0 -209
- package/dist/toolkit/index.d.mts +0 -9
- package/dist/toolkit/index.mjs +0 -9
- package/dist/toolkit/providers/facebook.d.mts +0 -12
- package/dist/toolkit/providers/facebook.mjs +0 -16
- package/dist/toolkit/providers/github.d.mts +0 -12
- package/dist/toolkit/providers/github.mjs +0 -16
- package/dist/toolkit/providers/google.d.mts +0 -12
- package/dist/toolkit/providers/google.mjs +0 -20
- package/dist/toolkit/providers/strategy.d.mts +0 -40
- package/dist/toolkit/providers/strategy.mjs +0 -1
- package/dist/toolkit/storage.mjs +0 -157
- package/dist/toolkit/utils.mjs +0 -30
- package/dist/types.d.mts +0 -94
- package/dist/types.mjs +0 -1
- package/dist/ui/base.d.mts +0 -30
- package/dist/ui/base.mjs +0 -407
- package/dist/ui/code.d.mts +0 -43
- package/dist/ui/code.mjs +0 -173
- package/dist/ui/form.d.mts +0 -32
- package/dist/ui/form.mjs +0 -49
- package/dist/ui/icon.d.mts +0 -58
- package/dist/ui/icon.mjs +0 -247
- package/dist/ui/magiclink.d.mts +0 -41
- package/dist/ui/magiclink.mjs +0 -152
- package/dist/ui/passkey.d.mts +0 -27
- package/dist/ui/passkey.mjs +0 -323
- package/dist/ui/password.d.mts +0 -42
- package/dist/ui/password.mjs +0 -402
- package/dist/ui/select.d.mts +0 -34
- package/dist/ui/select.mjs +0 -98
- package/dist/ui/totp.d.mts +0 -34
- package/dist/ui/totp.mjs +0 -270
- package/dist/util.mjs +0 -128
package/dist/storage/turso.mjs
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { joinKey, splitKey } from "./storage.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/storage/turso.ts
|
|
4
|
-
/**
|
|
5
|
-
* Creates a Turso storage adapter using the provided LibSQL client.
|
|
6
|
-
* Automatically initializes the required database table and implements
|
|
7
|
-
* the StorageAdapter interface with efficient SQL operations.
|
|
8
|
-
*
|
|
9
|
-
* @param client - Configured LibSQL client for database operations
|
|
10
|
-
* @returns Storage adapter implementing the StorageAdapter interface
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* import { createClient } from "@libsql/client"
|
|
15
|
-
*
|
|
16
|
-
* const client = createClient({
|
|
17
|
-
* url: process.env.TURSO_DATABASE_URL,
|
|
18
|
-
* authToken: process.env.TURSO_AUTH_TOKEN
|
|
19
|
-
* })
|
|
20
|
-
*
|
|
21
|
-
* const storage = TursoStorage(client)
|
|
22
|
-
*
|
|
23
|
-
* // Now ready to use with Draft Auth
|
|
24
|
-
* const app = issuer({ storage, ... })
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
const TursoStorage = (client) => {
|
|
28
|
-
const TABLE_NAME = "__draftauth__kv_storage";
|
|
29
|
-
client.execute(`
|
|
30
|
-
CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (
|
|
31
|
-
key TEXT PRIMARY KEY,
|
|
32
|
-
value TEXT NOT NULL,
|
|
33
|
-
expiry INTEGER
|
|
34
|
-
)
|
|
35
|
-
`);
|
|
36
|
-
client.execute(`
|
|
37
|
-
CREATE INDEX IF NOT EXISTS idx_${TABLE_NAME}_key_prefix
|
|
38
|
-
ON ${TABLE_NAME} (key)
|
|
39
|
-
`);
|
|
40
|
-
client.execute(`
|
|
41
|
-
CREATE INDEX IF NOT EXISTS idx_${TABLE_NAME}_expiry
|
|
42
|
-
ON ${TABLE_NAME} (expiry)
|
|
43
|
-
WHERE expiry IS NOT NULL
|
|
44
|
-
`);
|
|
45
|
-
return {
|
|
46
|
-
async get(key) {
|
|
47
|
-
const joinedKey = joinKey(key);
|
|
48
|
-
const { rows } = await client.execute({
|
|
49
|
-
sql: `SELECT value, expiry FROM ${TABLE_NAME} WHERE key = ?`,
|
|
50
|
-
args: [joinedKey]
|
|
51
|
-
});
|
|
52
|
-
const row = rows[0];
|
|
53
|
-
if (!row) return;
|
|
54
|
-
if (row.expiry && row.expiry < Date.now()) {
|
|
55
|
-
await client.execute({
|
|
56
|
-
sql: `DELETE FROM ${TABLE_NAME} WHERE key = ?`,
|
|
57
|
-
args: [joinedKey]
|
|
58
|
-
});
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
try {
|
|
62
|
-
return JSON.parse(row.value);
|
|
63
|
-
} catch {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
async set(key, value, expiry) {
|
|
68
|
-
const joinedKey = joinKey(key);
|
|
69
|
-
const expiryTimestamp = expiry?.getTime() ?? null;
|
|
70
|
-
try {
|
|
71
|
-
const serializedValue = JSON.stringify(value);
|
|
72
|
-
await client.execute({
|
|
73
|
-
sql: `INSERT OR REPLACE INTO ${TABLE_NAME} (key, value, expiry) VALUES (?, ?, ?)`,
|
|
74
|
-
args: [
|
|
75
|
-
joinedKey,
|
|
76
|
-
serializedValue,
|
|
77
|
-
expiryTimestamp
|
|
78
|
-
]
|
|
79
|
-
});
|
|
80
|
-
} catch {
|
|
81
|
-
throw new Error("Storage operation failed");
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
async remove(key) {
|
|
85
|
-
const joinedKey = joinKey(key);
|
|
86
|
-
await client.execute({
|
|
87
|
-
sql: `DELETE FROM ${TABLE_NAME} WHERE key = ?`,
|
|
88
|
-
args: [joinedKey]
|
|
89
|
-
});
|
|
90
|
-
},
|
|
91
|
-
async *scan(prefix) {
|
|
92
|
-
const joinedPrefix = joinKey(prefix);
|
|
93
|
-
const now = Date.now();
|
|
94
|
-
const { rows } = await client.execute({
|
|
95
|
-
sql: `
|
|
96
|
-
SELECT key, value, expiry
|
|
97
|
-
FROM ${TABLE_NAME}
|
|
98
|
-
WHERE key LIKE ?
|
|
99
|
-
AND (expiry IS NULL OR expiry >= ?)
|
|
100
|
-
ORDER BY key
|
|
101
|
-
`,
|
|
102
|
-
args: [`${joinedPrefix}%`, now]
|
|
103
|
-
});
|
|
104
|
-
for (const row of rows) try {
|
|
105
|
-
const parsedValue = JSON.parse(row.value);
|
|
106
|
-
yield [splitKey(row.key), parsedValue];
|
|
107
|
-
} catch {}
|
|
108
|
-
client.execute({
|
|
109
|
-
sql: `DELETE FROM ${TABLE_NAME} WHERE expiry IS NOT NULL AND expiry < ?`,
|
|
110
|
-
args: [now]
|
|
111
|
-
}).catch(() => {});
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
//#endregion
|
|
117
|
-
export { TursoStorage };
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { joinKey, splitKey } from "./storage.mjs";
|
|
2
|
-
import { createStorage } from "unstorage";
|
|
3
|
-
|
|
4
|
-
//#region src/storage/unstorage.ts
|
|
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
|
-
/**
|
|
13
|
-
* Creates a Draft Auth storage adapter using Unstorage drivers.
|
|
14
|
-
* Supports automatic expiration, error handling, and any Unstorage driver.
|
|
15
|
-
*
|
|
16
|
-
* @param options - Configuration options
|
|
17
|
-
* @param options.driver - Optional Unstorage driver (defaults to memory)
|
|
18
|
-
* @returns Storage adapter compatible with Draft Auth
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```ts
|
|
22
|
-
* import { UnStorage } from "@draftlab/auth/storage/unstorage"
|
|
23
|
-
* import redisDriver from "unstorage/drivers/redis"
|
|
24
|
-
*
|
|
25
|
-
* // Using Redis driver
|
|
26
|
-
* const storage = UnStorage({
|
|
27
|
-
* driver: redisDriver({
|
|
28
|
-
* host: process.env.REDIS_HOST,
|
|
29
|
-
* port: parseInt(process.env.REDIS_PORT || "6379"),
|
|
30
|
-
* password: process.env.REDIS_PASSWORD
|
|
31
|
-
* })
|
|
32
|
-
* })
|
|
33
|
-
*
|
|
34
|
-
* // Using default memory driver (development only)
|
|
35
|
-
* const memoryStorage = UnStorage()
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
const UnStorage = ({ driver } = {}) => {
|
|
39
|
-
const store = createStorage({ driver });
|
|
40
|
-
return {
|
|
41
|
-
async get(key) {
|
|
42
|
-
try {
|
|
43
|
-
const keyPath = joinKey(key);
|
|
44
|
-
const entry = await store.getItem(keyPath);
|
|
45
|
-
if (!entry) return;
|
|
46
|
-
if (entry.expiry && Date.now() >= entry.expiry) {
|
|
47
|
-
store.removeItem(keyPath).catch(() => {});
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
return entry.value;
|
|
51
|
-
} catch (error) {
|
|
52
|
-
console.error("UnStorage get error:", error);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
async set(key, value, expiry) {
|
|
57
|
-
try {
|
|
58
|
-
const keyPath = joinKey(key);
|
|
59
|
-
const entry = {
|
|
60
|
-
value,
|
|
61
|
-
expiry: expiry ? expiry.getTime() : void 0
|
|
62
|
-
};
|
|
63
|
-
await store.setItem(keyPath, entry);
|
|
64
|
-
} catch (error) {
|
|
65
|
-
console.error("UnStorage set error:", error);
|
|
66
|
-
throw error;
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
async remove(key) {
|
|
70
|
-
try {
|
|
71
|
-
const keyPath = joinKey(key);
|
|
72
|
-
await store.removeItem(keyPath);
|
|
73
|
-
} catch (error) {
|
|
74
|
-
console.error("UnStorage remove error:", error);
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
async *scan(prefix) {
|
|
78
|
-
try {
|
|
79
|
-
const now = Date.now();
|
|
80
|
-
const prefixPath = joinKey(prefix);
|
|
81
|
-
let keys = await store.getKeys(prefixPath);
|
|
82
|
-
if (keys.length === 0) {
|
|
83
|
-
const allKeys = await store.getKeys();
|
|
84
|
-
if (allKeys.length > 0) keys = allKeys.filter((key) => key.startsWith(prefixPath));
|
|
85
|
-
}
|
|
86
|
-
for (const keyPath of keys) try {
|
|
87
|
-
const entry = await store.getItem(keyPath);
|
|
88
|
-
if (!entry || !entry.value) continue;
|
|
89
|
-
if (entry.expiry && now >= entry.expiry) {
|
|
90
|
-
store.removeItem(keyPath).catch(() => {});
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
yield [splitKey(keyPath), entry.value];
|
|
94
|
-
} catch {}
|
|
95
|
-
} catch (error) {
|
|
96
|
-
console.error("UnStorage scan error:", error);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
//#endregion
|
|
103
|
-
export { UnStorage };
|
package/dist/subject.d.mts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { Prettify } from "./util.mjs";
|
|
2
|
-
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
-
|
|
4
|
-
//#region src/subject.d.ts
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Schema definition for subjects, mapping subject type names to their validation schemas.
|
|
8
|
-
* Each key represents a subject type, and each value is a schema that validates
|
|
9
|
-
* the properties for that subject type.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* const schema: SubjectSchema = {
|
|
14
|
-
* user: object({ userID: string() }),
|
|
15
|
-
* admin: object({ userID: string(), workspaceID: string() })
|
|
16
|
-
* }
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
type SubjectSchema = Record<string, StandardSchemaV1>;
|
|
20
|
-
/**
|
|
21
|
-
* Internal type that transforms a SubjectSchema into a union of subject payload objects.
|
|
22
|
-
* Each payload contains the subject type and its validated properties.
|
|
23
|
-
*
|
|
24
|
-
* @template T - The subject schema to transform
|
|
25
|
-
* @internal
|
|
26
|
-
*/
|
|
27
|
-
type SubjectPayload<T extends SubjectSchema> = Prettify<{ [K in keyof T & string]: {
|
|
28
|
-
type: K;
|
|
29
|
-
properties: StandardSchemaV1.InferOutput<T[K]>;
|
|
30
|
-
} }[keyof T & string]>;
|
|
31
|
-
/**
|
|
32
|
-
* Creates a strongly-typed subject schema that can be used throughout your application.
|
|
33
|
-
* The returned schema maintains type information for excellent IDE support and runtime validation.
|
|
34
|
-
*
|
|
35
|
-
* @template Schema - The subject schema type being created
|
|
36
|
-
* @param types - Object mapping subject type names to their validation schemas
|
|
37
|
-
* @returns The same schema object with preserved type information
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```ts
|
|
41
|
-
* import { object, string, number } from "valibot"
|
|
42
|
-
*
|
|
43
|
-
* const subjects = createSubjects({
|
|
44
|
-
* user: object({
|
|
45
|
-
* userID: string(),
|
|
46
|
-
* createdAt: number()
|
|
47
|
-
* }),
|
|
48
|
-
* admin: object({
|
|
49
|
-
* userID: string(),
|
|
50
|
-
* workspaceID: string(),
|
|
51
|
-
* permissions: array(string())
|
|
52
|
-
* }),
|
|
53
|
-
* service: object({
|
|
54
|
-
* serviceID: string(),
|
|
55
|
-
* apiVersion: string()
|
|
56
|
-
* })
|
|
57
|
-
* })
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
declare const createSubjects: <Schema extends SubjectSchema>(types: Schema) => Schema;
|
|
61
|
-
//#endregion
|
|
62
|
-
export { SubjectPayload, SubjectSchema, createSubjects };
|
package/dist/subject.mjs
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
//#region src/subject.ts
|
|
2
|
-
/**
|
|
3
|
-
* Creates a strongly-typed subject schema that can be used throughout your application.
|
|
4
|
-
* The returned schema maintains type information for excellent IDE support and runtime validation.
|
|
5
|
-
*
|
|
6
|
-
* @template Schema - The subject schema type being created
|
|
7
|
-
* @param types - Object mapping subject type names to their validation schemas
|
|
8
|
-
* @returns The same schema object with preserved type information
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* import { object, string, number } from "valibot"
|
|
13
|
-
*
|
|
14
|
-
* const subjects = createSubjects({
|
|
15
|
-
* user: object({
|
|
16
|
-
* userID: string(),
|
|
17
|
-
* createdAt: number()
|
|
18
|
-
* }),
|
|
19
|
-
* admin: object({
|
|
20
|
-
* userID: string(),
|
|
21
|
-
* workspaceID: string(),
|
|
22
|
-
* permissions: array(string())
|
|
23
|
-
* }),
|
|
24
|
-
* service: object({
|
|
25
|
-
* serviceID: string(),
|
|
26
|
-
* apiVersion: string()
|
|
27
|
-
* })
|
|
28
|
-
* })
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
const createSubjects = (types) => {
|
|
32
|
-
return { ...types };
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
//#endregion
|
|
36
|
-
export { createSubjects };
|
package/dist/themes/theme.d.mts
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
//#region src/themes/theme.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Use one of the built-in themes.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
*
|
|
7
|
-
* ```ts
|
|
8
|
-
* import { THEME_SST } from "@draftlab/auth/themes/theme"
|
|
9
|
-
*
|
|
10
|
-
* export default issuer({
|
|
11
|
-
* theme: THEME_SST,
|
|
12
|
-
* // ...
|
|
13
|
-
* })
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* Or define your own.
|
|
17
|
-
*
|
|
18
|
-
* ```ts
|
|
19
|
-
* import type { Theme } from "@draftlab/auth/themes/theme"
|
|
20
|
-
*
|
|
21
|
-
* const MY_THEME: Theme = {
|
|
22
|
-
* title: "Acne",
|
|
23
|
-
* radius: "none",
|
|
24
|
-
* favicon: "https://www.example.com/favicon.svg",
|
|
25
|
-
* // ...
|
|
26
|
-
* }
|
|
27
|
-
*
|
|
28
|
-
* export default issuer({
|
|
29
|
-
* theme: MY_THEME,
|
|
30
|
-
* // ...
|
|
31
|
-
* })
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* @packageDocumentation
|
|
35
|
-
*/
|
|
36
|
-
/**
|
|
37
|
-
* A type to define values for light and dark mode.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```ts
|
|
41
|
-
* {
|
|
42
|
-
* light: "#FFF",
|
|
43
|
-
* dark: "#000"
|
|
44
|
-
* }
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
interface ColorScheme {
|
|
48
|
-
/**
|
|
49
|
-
* The value for dark mode.
|
|
50
|
-
*/
|
|
51
|
-
dark: string;
|
|
52
|
-
/**
|
|
53
|
-
* The value for light mode.
|
|
54
|
-
*/
|
|
55
|
-
light: string;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* A type to define your custom theme.
|
|
59
|
-
*/
|
|
60
|
-
interface Theme {
|
|
61
|
-
/**
|
|
62
|
-
* The name of your app. Also used as the title of the page.
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```ts
|
|
66
|
-
* {
|
|
67
|
-
* title: "Acne"
|
|
68
|
-
* }
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
title?: string;
|
|
72
|
-
/**
|
|
73
|
-
* A URL to the favicon of your app.
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```ts
|
|
77
|
-
* {
|
|
78
|
-
* favicon: "https://www.example.com/favicon.svg"
|
|
79
|
-
* }
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
favicon?: string;
|
|
83
|
-
/**
|
|
84
|
-
* The border radius of the UI elements.
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```ts
|
|
88
|
-
* {
|
|
89
|
-
* radius: "none"
|
|
90
|
-
* }
|
|
91
|
-
* ```
|
|
92
|
-
*/
|
|
93
|
-
radius?: "none" | "sm" | "md" | "lg" | "full";
|
|
94
|
-
/**
|
|
95
|
-
* The primary color of the theme.
|
|
96
|
-
*
|
|
97
|
-
* Takes a color or both light and dark colors.
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* ```ts
|
|
101
|
-
* {
|
|
102
|
-
* primary: "#FF5E00"
|
|
103
|
-
* }
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
|
-
primary: string | ColorScheme;
|
|
107
|
-
/**
|
|
108
|
-
* The background color of the theme.
|
|
109
|
-
*
|
|
110
|
-
* Takes a color or both light and dark colors.
|
|
111
|
-
*
|
|
112
|
-
* @example
|
|
113
|
-
* ```ts
|
|
114
|
-
* {
|
|
115
|
-
* background: "#FFF"
|
|
116
|
-
* }
|
|
117
|
-
* ```
|
|
118
|
-
*/
|
|
119
|
-
background?: string | ColorScheme;
|
|
120
|
-
/**
|
|
121
|
-
* A URL to the logo of your app.
|
|
122
|
-
*
|
|
123
|
-
* Takes a single image or both light and dark mode versions.
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* ```ts
|
|
127
|
-
* {
|
|
128
|
-
* logo: "https://www.example.com/logo.svg"
|
|
129
|
-
* }
|
|
130
|
-
* ```
|
|
131
|
-
*/
|
|
132
|
-
logo?: string | ColorScheme;
|
|
133
|
-
/**
|
|
134
|
-
* The font family and scale of the theme.
|
|
135
|
-
*/
|
|
136
|
-
font?: {
|
|
137
|
-
/**
|
|
138
|
-
* The font family of the theme.
|
|
139
|
-
*
|
|
140
|
-
* @example
|
|
141
|
-
* ```ts
|
|
142
|
-
* {
|
|
143
|
-
* font: {
|
|
144
|
-
* family: "Geist Mono, monospace"
|
|
145
|
-
* }
|
|
146
|
-
* }
|
|
147
|
-
* ```
|
|
148
|
-
*/
|
|
149
|
-
family?: string;
|
|
150
|
-
/**
|
|
151
|
-
* The font scale of the theme. Can be used to increase or decrease the font sizes across
|
|
152
|
-
* the UI.
|
|
153
|
-
*
|
|
154
|
-
* @default "1"
|
|
155
|
-
* @example
|
|
156
|
-
* ```ts
|
|
157
|
-
* {
|
|
158
|
-
* font: {
|
|
159
|
-
* scale: "1.25"
|
|
160
|
-
* }
|
|
161
|
-
* }
|
|
162
|
-
* ```
|
|
163
|
-
*/
|
|
164
|
-
scale?: string;
|
|
165
|
-
};
|
|
166
|
-
/**
|
|
167
|
-
* Custom CSS that's added to the page in a `<style>` tag.
|
|
168
|
-
*
|
|
169
|
-
* This can be used to import custom fonts.
|
|
170
|
-
*
|
|
171
|
-
* @example
|
|
172
|
-
* ```ts
|
|
173
|
-
* {
|
|
174
|
-
* css: `@import url('https://fonts.googleapis.com/css2?family=Rubik:wght@100;200;300;400;500;600;700;800;900&display=swap');`
|
|
175
|
-
* }
|
|
176
|
-
* ```
|
|
177
|
-
*/
|
|
178
|
-
css?: string;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Built-in default Draft Auth theme.
|
|
182
|
-
*/
|
|
183
|
-
declare const THEME_DRAFTAUTH: Theme;
|
|
184
|
-
/**
|
|
185
|
-
* Built-in theme based on [Terminal](https://terminal.shop).
|
|
186
|
-
*/
|
|
187
|
-
declare const THEME_TERMINAL: Theme;
|
|
188
|
-
/**
|
|
189
|
-
* Built-in theme based on [SST](https://sst.dev).
|
|
190
|
-
*/
|
|
191
|
-
declare const THEME_SST: Theme;
|
|
192
|
-
/**
|
|
193
|
-
* Built-in theme based on [Supabase](https://supabase.com).
|
|
194
|
-
*/
|
|
195
|
-
declare const THEME_SUPABASE: Theme;
|
|
196
|
-
/**
|
|
197
|
-
* Built-in theme based on [Vercel](https://vercel.com).
|
|
198
|
-
*/
|
|
199
|
-
declare const THEME_VERCEL: Theme;
|
|
200
|
-
/**
|
|
201
|
-
* @internal
|
|
202
|
-
*/
|
|
203
|
-
declare const setTheme: (value: Theme) => void;
|
|
204
|
-
/**
|
|
205
|
-
* @internal
|
|
206
|
-
*/
|
|
207
|
-
declare const getTheme: () => any;
|
|
208
|
-
//#endregion
|
|
209
|
-
export { ColorScheme, THEME_DRAFTAUTH, THEME_SST, THEME_SUPABASE, THEME_TERMINAL, THEME_VERCEL, Theme, getTheme, setTheme };
|
package/dist/themes/theme.mjs
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
//#region src/themes/theme.ts
|
|
2
|
-
/**
|
|
3
|
-
* Built-in default Draft Auth theme.
|
|
4
|
-
*/
|
|
5
|
-
const THEME_DRAFTAUTH = {
|
|
6
|
-
title: "Draft Auth",
|
|
7
|
-
radius: "none",
|
|
8
|
-
background: {
|
|
9
|
-
dark: "black",
|
|
10
|
-
light: "white"
|
|
11
|
-
},
|
|
12
|
-
primary: {
|
|
13
|
-
dark: "white",
|
|
14
|
-
light: "black"
|
|
15
|
-
},
|
|
16
|
-
font: { family: "IBM Plex Sans, sans-serif" },
|
|
17
|
-
css: `
|
|
18
|
-
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@100;200;300;400;500;600;700&display=swap');
|
|
19
|
-
`
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Built-in theme based on [Terminal](https://terminal.shop).
|
|
23
|
-
*/
|
|
24
|
-
const THEME_TERMINAL = {
|
|
25
|
-
title: "terminal",
|
|
26
|
-
radius: "none",
|
|
27
|
-
favicon: "https://www.terminal.shop/favicon.svg",
|
|
28
|
-
logo: {
|
|
29
|
-
dark: "https://www.terminal.shop/images/logo-white.svg",
|
|
30
|
-
light: "https://www.terminal.shop/images/logo-black.svg"
|
|
31
|
-
},
|
|
32
|
-
primary: "#ff5e00",
|
|
33
|
-
background: {
|
|
34
|
-
dark: "rgb(0, 0, 0)",
|
|
35
|
-
light: "rgb(255, 255, 255)"
|
|
36
|
-
},
|
|
37
|
-
font: { family: "Geist Mono, monospace" },
|
|
38
|
-
css: `
|
|
39
|
-
@import url('https://fonts.googleapis.com/css2?family=Geist+Mono:wght@100;200;300;400;500;600;700;800;900&display=swap');
|
|
40
|
-
`
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Built-in theme based on [SST](https://sst.dev).
|
|
44
|
-
*/
|
|
45
|
-
const THEME_SST = {
|
|
46
|
-
title: "SST",
|
|
47
|
-
favicon: "https://sst.dev/favicon.svg",
|
|
48
|
-
logo: {
|
|
49
|
-
dark: "https://sst.dev/favicon.svg",
|
|
50
|
-
light: "https://sst.dev/favicon.svg"
|
|
51
|
-
},
|
|
52
|
-
background: {
|
|
53
|
-
dark: "#1a1a2d",
|
|
54
|
-
light: "rgb(255, 255, 255)"
|
|
55
|
-
},
|
|
56
|
-
primary: "#f3663f",
|
|
57
|
-
font: { family: "Rubik, sans-serif" },
|
|
58
|
-
css: `
|
|
59
|
-
@import url('https://fonts.googleapis.com/css2?family=Rubik:wght@100;200;300;400;500;600;700;800;900&display=swap');
|
|
60
|
-
`
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Built-in theme based on [Supabase](https://supabase.com).
|
|
64
|
-
*/
|
|
65
|
-
const THEME_SUPABASE = {
|
|
66
|
-
title: "Supabase",
|
|
67
|
-
logo: {
|
|
68
|
-
dark: "https://supabase.com/dashboard/_next/image?url=%2Fdashboard%2Fimg%2Fsupabase-dark.svg&w=128&q=75",
|
|
69
|
-
light: "https://supabase.com/dashboard/_next/image?url=%2Fdashboard%2Fimg%2Fsupabase-light.svg&w=128&q=75"
|
|
70
|
-
},
|
|
71
|
-
background: {
|
|
72
|
-
dark: "#171717",
|
|
73
|
-
light: "#f8f8f8"
|
|
74
|
-
},
|
|
75
|
-
primary: {
|
|
76
|
-
dark: "#006239",
|
|
77
|
-
light: "#72e3ad"
|
|
78
|
-
},
|
|
79
|
-
font: { family: "Varela Round, sans-serif" },
|
|
80
|
-
css: `
|
|
81
|
-
@import url('https://fonts.googleapis.com/css2?family=Varela+Round:wght@100;200;300;400;500;600;700;800;900&display=swap');
|
|
82
|
-
`
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* Built-in theme based on [Vercel](https://vercel.com).
|
|
86
|
-
*/
|
|
87
|
-
const THEME_VERCEL = {
|
|
88
|
-
title: "Vercel",
|
|
89
|
-
logo: {
|
|
90
|
-
dark: "https://vercel.com/mktng/_next/static/media/vercel-logotype-dark.e8c0a742.svg",
|
|
91
|
-
light: "https://vercel.com/mktng/_next/static/media/vercel-logotype-light.700a8d26.svg"
|
|
92
|
-
},
|
|
93
|
-
background: {
|
|
94
|
-
dark: "black",
|
|
95
|
-
light: "white"
|
|
96
|
-
},
|
|
97
|
-
primary: {
|
|
98
|
-
dark: "white",
|
|
99
|
-
light: "black"
|
|
100
|
-
},
|
|
101
|
-
font: { family: "Geist, sans-serif" },
|
|
102
|
-
css: `
|
|
103
|
-
@import url('https://fonts.googleapis.com/css2?family=Geist:wght@100;200;300;400;500;600;700;800;900&display=swap');
|
|
104
|
-
`
|
|
105
|
-
};
|
|
106
|
-
/**
|
|
107
|
-
* @internal
|
|
108
|
-
*/
|
|
109
|
-
const setTheme = (value) => {
|
|
110
|
-
globalThis.DRAFTAUTH_THEME = value;
|
|
111
|
-
};
|
|
112
|
-
/**
|
|
113
|
-
* @internal
|
|
114
|
-
*/
|
|
115
|
-
const getTheme = () => {
|
|
116
|
-
return globalThis.DRAFTAUTH_THEME || THEME_DRAFTAUTH;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
//#endregion
|
|
120
|
-
export { THEME_DRAFTAUTH, THEME_SST, THEME_SUPABASE, THEME_TERMINAL, THEME_VERCEL, getTheme, setTheme };
|