@finueva/auth 0.4.0 → 0.5.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/README.md +6 -0
- package/dist/device.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +234 -124
- package/dist/server.d.ts +1 -1
- package/dist/{types-zEqO1_r2.d.ts → types-HSdjQWMZ.d.ts} +6 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -23,6 +23,10 @@ const stop = auth.onAuthStateChange((state) => {
|
|
|
23
23
|
|
|
24
24
|
const session = await auth.getSession();
|
|
25
25
|
await auth.signIn({ email, password });
|
|
26
|
+
await auth.sendVerificationEmail({
|
|
27
|
+
email,
|
|
28
|
+
callbackURL: `${window.location.origin}/account/email-verified`,
|
|
29
|
+
});
|
|
26
30
|
const organizations = await auth.listOrganizations();
|
|
27
31
|
const acceptance = await auth.acceptInvitation({ invitationId });
|
|
28
32
|
const credential = await auth.getDriveCredential({
|
|
@@ -37,6 +41,8 @@ stop();
|
|
|
37
41
|
|
|
38
42
|
The Auth session uses the Auth-owned HTTP-only cookie. `getSession()` and `onSessionChange()` report Better Auth authority results only. `onAuthStateChange()` separately emits `loading`, non-authoritative `cached`, authoritative `authenticated`/`unauthenticated`, or non-authoritative `unavailable`; it verifies every cache hint immediately.
|
|
39
43
|
|
|
44
|
+
`sendVerificationEmail({ email, callbackURL? })` sends one non-retried request. An explicit callback must be an exact absolute URL on `appOrigin`; it is never persisted by the SDK. Without one, the email lands on Auth's value-free verification result page after Better Auth completes verification.
|
|
45
|
+
|
|
40
46
|
DOM browsers use local storage by default. Set `persistence` to `"session"`, `"memory"`, or a structural driver with `getItem`, `setItem`, and `removeItem`; Workers and Node default to memory. The one 16 KiB versioned snapshot contains only a normalized session and its Auth authority identity. It expires with the session and never contains cookies, passwords, Drive credentials, tokens, headers, workspace selection, Better Auth payloads, or errors. Persistence failure cannot change an Auth request result.
|
|
41
47
|
|
|
42
48
|
A workspace is either `{ type: "personal" }` or `{ type: "organization", organizationId }`; organization IDs must match `[A-Za-z0-9_-]{1,128}`. Workspace selections are strict and reject additional properties locally with `invalid_workspace_selection` before making a request.
|
package/dist/device.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as AuthSession } from "./types-
|
|
1
|
+
import { o as AuthSession } from "./types-HSdjQWMZ.js";
|
|
2
2
|
//#region src/device.d.ts
|
|
3
3
|
type DeviceAuthorizationErrorCode = "device_access_denied" | "device_authorization_cancelled" | "device_code_expired" | "invalid_device_authorization" | "identity_authority_unavailable";
|
|
4
4
|
declare class DeviceAuthorizationError extends Error {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as AuthPersistenceDriver, c as AuthUser, d as FinuevaAuthClient, f as InvitationAcceptance, g as
|
|
1
|
+
import { _ as WorkspaceSelection, a as AuthPersistenceDriver, c as AuthUser, d as FinuevaAuthClient, f as InvitationAcceptance, g as SignInInput, h as SendVerificationEmailInput, i as AuthPersistence, l as DriveCredential, m as PersonalWorkspaceSelection, n as AuthClientOptions, o as AuthSession, p as OrganizationWorkspaceSelection, r as AuthOrganization, s as AuthState, t as AcceptInvitationInput, u as DriveCredentialInput } from "./types-HSdjQWMZ.js";
|
|
2
2
|
import { n as AuthErrorCode, r as AuthErrorStatus, t as AuthError } from "./errors-Crd93Rah.js";
|
|
3
3
|
//#region src/client.d.ts
|
|
4
4
|
declare function createAuthClient(options: AuthClientOptions): FinuevaAuthClient;
|
|
5
5
|
//#endregion
|
|
6
|
-
export { type AcceptInvitationInput, type AuthClientOptions, AuthError, type AuthErrorCode, type AuthErrorStatus, type AuthOrganization, type AuthPersistence, type AuthPersistenceDriver, type AuthSession, type AuthState, type AuthUser, type DriveCredential, type DriveCredentialInput, type FinuevaAuthClient, type InvitationAcceptance, type OrganizationWorkspaceSelection, type PersonalWorkspaceSelection, type SignInInput, type WorkspaceSelection, createAuthClient };
|
|
6
|
+
export { type AcceptInvitationInput, type AuthClientOptions, AuthError, type AuthErrorCode, type AuthErrorStatus, type AuthOrganization, type AuthPersistence, type AuthPersistenceDriver, type AuthSession, type AuthState, type AuthUser, type DriveCredential, type DriveCredentialInput, type FinuevaAuthClient, type InvitationAcceptance, type OrganizationWorkspaceSelection, type PersonalWorkspaceSelection, type SendVerificationEmailInput, type SignInInput, type WorkspaceSelection, createAuthClient };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
|
-
//#region
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp$1 = Object.defineProperty;
|
|
3
|
+
var __esmMin = (fn, res, err) => () => {
|
|
4
|
+
if (err) throw err[0];
|
|
5
|
+
try {
|
|
6
|
+
return fn && (res = fn(fn = 0)), res;
|
|
7
|
+
} catch (e) {
|
|
8
|
+
throw err = [e], e;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var __exportAll = (all, no_symbols) => {
|
|
12
|
+
let target = {};
|
|
13
|
+
for (var name in all) __defProp$1(target, name, {
|
|
14
|
+
get: all[name],
|
|
15
|
+
enumerable: true
|
|
16
|
+
});
|
|
17
|
+
if (!no_symbols) __defProp$1(target, Symbol.toStringTag, { value: "Module" });
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@_fc032d4b6d0d0a5be5267474da10b212/node_modules/better-auth/dist/client/broadcast-channel.mjs
|
|
2
22
|
const kBroadcastChannel = Symbol.for("better-auth:broadcast-channel");
|
|
3
23
|
const now$1 = () => Math.floor(Date.now() / 1e3);
|
|
4
24
|
var WindowBroadcastChannel = class {
|
|
@@ -205,7 +225,7 @@ let onMount = ($store, initialize) => {
|
|
|
205
225
|
});
|
|
206
226
|
};
|
|
207
227
|
//#endregion
|
|
208
|
-
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@
|
|
228
|
+
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@_fc032d4b6d0d0a5be5267474da10b212/node_modules/better-auth/dist/client/equality.mjs
|
|
209
229
|
function isPlainObject$1(value) {
|
|
210
230
|
if (typeof value !== "object" || value === null) return false;
|
|
211
231
|
const prototype = Object.getPrototypeOf(value);
|
|
@@ -233,7 +253,7 @@ function withEquality(store, isEqual) {
|
|
|
233
253
|
});
|
|
234
254
|
}
|
|
235
255
|
//#endregion
|
|
236
|
-
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@
|
|
256
|
+
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@_fc032d4b6d0d0a5be5267474da10b212/node_modules/better-auth/dist/client/focus-manager.mjs
|
|
237
257
|
const kFocusManager = Symbol.for("better-auth:focus-manager");
|
|
238
258
|
var WindowFocusManager = class {
|
|
239
259
|
listeners = new Set();
|
|
@@ -262,7 +282,7 @@ function getGlobalFocusManager() {
|
|
|
262
282
|
return globalThis[kFocusManager];
|
|
263
283
|
}
|
|
264
284
|
//#endregion
|
|
265
|
-
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@
|
|
285
|
+
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@_fc032d4b6d0d0a5be5267474da10b212/node_modules/better-auth/dist/client/online-manager.mjs
|
|
266
286
|
const kOnlineManager = Symbol.for("better-auth:online-manager");
|
|
267
287
|
var WindowOnlineManager = class {
|
|
268
288
|
listeners = new Set();
|
|
@@ -294,7 +314,7 @@ function getGlobalOnlineManager() {
|
|
|
294
314
|
return globalThis[kOnlineManager];
|
|
295
315
|
}
|
|
296
316
|
//#endregion
|
|
297
|
-
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@
|
|
317
|
+
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@_fc032d4b6d0d0a5be5267474da10b212/node_modules/better-auth/dist/client/parser.mjs
|
|
298
318
|
const PROTO_POLLUTION_PATTERNS = {
|
|
299
319
|
proto: /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,
|
|
300
320
|
constructor: /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,
|
|
@@ -363,7 +383,7 @@ function parseJSON(value, options = { strict: true }) {
|
|
|
363
383
|
return betterJSONParse(value, options);
|
|
364
384
|
}
|
|
365
385
|
//#endregion
|
|
366
|
-
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@
|
|
386
|
+
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@_fc032d4b6d0d0a5be5267474da10b212/node_modules/better-auth/dist/client/session-refresh.mjs
|
|
367
387
|
const now = () => Math.floor(Date.now() / 1e3);
|
|
368
388
|
const FOCUS_REFETCH_RATE_LIMIT_SECONDS = 5;
|
|
369
389
|
function createSessionRefreshManager(opts) {
|
|
@@ -660,7 +680,7 @@ var BetterAuthError = class extends Error {
|
|
|
660
680
|
}
|
|
661
681
|
};
|
|
662
682
|
//#endregion
|
|
663
|
-
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@
|
|
683
|
+
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@_fc032d4b6d0d0a5be5267474da10b212/node_modules/better-auth/dist/utils/url.mjs
|
|
664
684
|
const SLASH_CHAR_CODE = "/".charCodeAt(0);
|
|
665
685
|
function trimTrailingSlashes(value) {
|
|
666
686
|
let end = value.length;
|
|
@@ -754,7 +774,7 @@ function isSafeUrlScheme(value) {
|
|
|
754
774
|
return !DANGEROUS_URL_SCHEMES.includes(parsed.protocol);
|
|
755
775
|
}
|
|
756
776
|
//#endregion
|
|
757
|
-
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@
|
|
777
|
+
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@_fc032d4b6d0d0a5be5267474da10b212/node_modules/better-auth/dist/client/fetch-plugins.mjs
|
|
758
778
|
const redirectPlugin = {
|
|
759
779
|
id: "redirect",
|
|
760
780
|
name: "Redirect",
|
|
@@ -769,7 +789,7 @@ const redirectPlugin = {
|
|
|
769
789
|
} }
|
|
770
790
|
};
|
|
771
791
|
//#endregion
|
|
772
|
-
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@
|
|
792
|
+
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@_fc032d4b6d0d0a5be5267474da10b212/node_modules/better-auth/dist/client/session-atom.mjs
|
|
773
793
|
const isServer = () => typeof window === "undefined";
|
|
774
794
|
function normalizeSessionResponse(res) {
|
|
775
795
|
if (typeof res === "object" && res !== null && "data" in res && "error" in res) return res;
|
|
@@ -1417,7 +1437,7 @@ var betterFetch = async (url, options) => {
|
|
|
1417
1437
|
};
|
|
1418
1438
|
};
|
|
1419
1439
|
//#endregion
|
|
1420
|
-
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@
|
|
1440
|
+
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@_fc032d4b6d0d0a5be5267474da10b212/node_modules/better-auth/dist/client/config.mjs
|
|
1421
1441
|
const resolvePublicAuthUrl = (basePath) => {
|
|
1422
1442
|
if (typeof process === "undefined") return void 0;
|
|
1423
1443
|
const path = basePath ?? "/api/auth";
|
|
@@ -1515,7 +1535,7 @@ const getClientConfig = (options, loadEnv) => {
|
|
|
1515
1535
|
};
|
|
1516
1536
|
};
|
|
1517
1537
|
//#endregion
|
|
1518
|
-
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@
|
|
1538
|
+
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@_fc032d4b6d0d0a5be5267474da10b212/node_modules/better-auth/dist/utils/is-atom.mjs
|
|
1519
1539
|
function isAtom(value) {
|
|
1520
1540
|
return typeof value === "object" && value !== null && "get" in value && typeof value.get === "function" && "lc" in value && typeof value.lc === "number";
|
|
1521
1541
|
}
|
|
@@ -1533,7 +1553,7 @@ function toKebabCase(input) {
|
|
|
1533
1553
|
return splitWords(input).map((word) => word.toLowerCase()).join("-");
|
|
1534
1554
|
}
|
|
1535
1555
|
//#endregion
|
|
1536
|
-
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@
|
|
1556
|
+
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@_fc032d4b6d0d0a5be5267474da10b212/node_modules/better-auth/dist/client/proxy.mjs
|
|
1537
1557
|
function getMethod(path, knownPathMethods, args) {
|
|
1538
1558
|
const method = knownPathMethods[path];
|
|
1539
1559
|
const { fetchOptions, query: _query, ...body } = args || {};
|
|
@@ -1602,7 +1622,7 @@ function createDynamicPathProxy(routes, client, knownPathMethods, atoms, atomLis
|
|
|
1602
1622
|
return createProxy();
|
|
1603
1623
|
}
|
|
1604
1624
|
//#endregion
|
|
1605
|
-
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@
|
|
1625
|
+
//#region ../../node_modules/.pnpm/better-auth@1.6.22_drizzle-kit@0.31.10_drizzle-orm@0.45.2_@libsql+client@0.17.4_kysely@_fc032d4b6d0d0a5be5267474da10b212/node_modules/better-auth/dist/client/vanilla.mjs
|
|
1606
1626
|
function createAuthClient$1(options) {
|
|
1607
1627
|
const { pluginPathMethods, pluginsActions, pluginsAtoms, $fetch, atomListeners, $store } = getClientConfig(options);
|
|
1608
1628
|
const resolvedHooks = {};
|
|
@@ -2211,6 +2231,27 @@ function normalizeInvitationInput(value) {
|
|
|
2211
2231
|
if (!isObject(value) || Object.keys(value).length !== 1 || !isId(value.invitationId)) throw new AuthError("invalid_invitation", 422);
|
|
2212
2232
|
return { invitationId: value.invitationId };
|
|
2213
2233
|
}
|
|
2234
|
+
function normalizeVerificationEmailInput(value, appOrigin) {
|
|
2235
|
+
if (!isObject(value)) throw new TypeError("verification email input is invalid");
|
|
2236
|
+
const keys = Object.keys(value);
|
|
2237
|
+
if (keys.length !== 1 && keys.length !== 2 || !keys.includes("email") || keys.length === 2 && !keys.includes("callbackURL") || typeof value.email !== "string" || value.email.length > 320 || !email.test(value.email)) throw new TypeError("verification email input is invalid");
|
|
2238
|
+
if (value.callbackURL === void 0) return { email: value.email };
|
|
2239
|
+
if (typeof value.callbackURL !== "string" || value.callbackURL.length > 2048 || /[^\x20-\x7e]/.test(value.callbackURL)) throw new TypeError("callbackURL must belong to appOrigin");
|
|
2240
|
+
let callback;
|
|
2241
|
+
try {
|
|
2242
|
+
callback = new URL(value.callbackURL);
|
|
2243
|
+
} catch {
|
|
2244
|
+
throw new TypeError("callbackURL must belong to appOrigin");
|
|
2245
|
+
}
|
|
2246
|
+
if (callback.origin !== appOrigin || callback.username || callback.password || callback.toString() !== value.callbackURL) throw new TypeError("callbackURL must belong to appOrigin");
|
|
2247
|
+
return {
|
|
2248
|
+
email: value.email,
|
|
2249
|
+
callbackURL: value.callbackURL
|
|
2250
|
+
};
|
|
2251
|
+
}
|
|
2252
|
+
function normalizeVerificationEmailResponse(value) {
|
|
2253
|
+
if (!isObject(value) || value.status !== true) throw authorityUnavailable();
|
|
2254
|
+
}
|
|
2214
2255
|
function normalizeInvitationAcceptance(value, invitationId) {
|
|
2215
2256
|
if (!isObject(value) || !isObject(value.invitation) || !isObject(value.member) || value.invitation.id !== invitationId || value.invitation.status !== "accepted" || !isId(value.invitation.organizationId) || value.member.organizationId !== value.invitation.organizationId) throw authorityUnavailable();
|
|
2216
2257
|
return { organizationId: value.invitation.organizationId };
|
|
@@ -2780,120 +2821,148 @@ function createRequiredError(driver, name) {
|
|
|
2780
2821
|
if (Array.isArray(name)) return createError(driver, `Missing some of the required options ${name.map((n) => "`" + n + "`").join(", ")}`);
|
|
2781
2822
|
return createError(driver, `Missing required option \`${name}\`.`);
|
|
2782
2823
|
}
|
|
2783
|
-
|
|
2784
|
-
//#region ../../node_modules/.pnpm/unstorage@1.17.5/node_modules/unstorage/drivers/localstorage.mjs
|
|
2785
|
-
const DRIVER_NAME$2 = "localstorage";
|
|
2786
|
-
var localstorage_default = defineDriver((opts = {}) => {
|
|
2787
|
-
const storage = opts.storage || opts.localStorage || opts.sessionStorage || (opts.window || globalThis.window)?.[opts.windowKey || "localStorage"];
|
|
2788
|
-
if (!storage) throw createRequiredError(DRIVER_NAME$2, "localStorage");
|
|
2789
|
-
const base = opts.base ? normalizeKey(opts.base) : "";
|
|
2790
|
-
const r = (key) => (base ? `${base}:` : "") + key;
|
|
2791
|
-
let _storageListener;
|
|
2792
|
-
const _unwatch = () => {
|
|
2793
|
-
if (_storageListener) opts.window?.removeEventListener("storage", _storageListener);
|
|
2794
|
-
_storageListener = void 0;
|
|
2795
|
-
};
|
|
2796
|
-
return {
|
|
2797
|
-
name: DRIVER_NAME$2,
|
|
2798
|
-
options: opts,
|
|
2799
|
-
getInstance: () => storage,
|
|
2800
|
-
hasItem(key) {
|
|
2801
|
-
return Object.prototype.hasOwnProperty.call(storage, r(key));
|
|
2802
|
-
},
|
|
2803
|
-
getItem(key) {
|
|
2804
|
-
return storage.getItem(r(key));
|
|
2805
|
-
},
|
|
2806
|
-
setItem(key, value) {
|
|
2807
|
-
return storage.setItem(r(key), value);
|
|
2808
|
-
},
|
|
2809
|
-
removeItem(key) {
|
|
2810
|
-
return storage.removeItem(r(key));
|
|
2811
|
-
},
|
|
2812
|
-
getKeys() {
|
|
2813
|
-
const allKeys = Object.keys(storage);
|
|
2814
|
-
return base ? allKeys.filter((key) => key.startsWith(`${base}:`)).map((key) => key.slice(base.length + 1)) : allKeys;
|
|
2815
|
-
},
|
|
2816
|
-
clear(prefix) {
|
|
2817
|
-
const _base = [base, prefix].filter(Boolean).join(":");
|
|
2818
|
-
if (_base) {
|
|
2819
|
-
for (const key of Object.keys(storage)) if (key.startsWith(`${_base}:`)) storage?.removeItem(key);
|
|
2820
|
-
} else storage.clear();
|
|
2821
|
-
},
|
|
2822
|
-
dispose() {
|
|
2823
|
-
if (opts.window && _storageListener) opts.window.removeEventListener("storage", _storageListener);
|
|
2824
|
-
},
|
|
2825
|
-
watch(callback) {
|
|
2826
|
-
if (!opts.window) return _unwatch;
|
|
2827
|
-
_storageListener = (ev) => {
|
|
2828
|
-
if (ev.key) callback(ev.newValue ? "update" : "remove", ev.key);
|
|
2829
|
-
};
|
|
2830
|
-
opts.window.addEventListener("storage", _storageListener);
|
|
2831
|
-
return _unwatch;
|
|
2832
|
-
}
|
|
2833
|
-
};
|
|
2834
|
-
});
|
|
2824
|
+
var init_utils = __esmMin((() => {}));
|
|
2835
2825
|
//#endregion
|
|
2836
2826
|
//#region ../../node_modules/.pnpm/unstorage@1.17.5/node_modules/unstorage/drivers/memory.mjs
|
|
2837
|
-
|
|
2838
|
-
var memory_default
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2827
|
+
var memory_exports = __exportAll({ default: () => memory_default });
|
|
2828
|
+
var DRIVER_NAME$2, memory_default;
|
|
2829
|
+
var init_memory = __esmMin((() => {
|
|
2830
|
+
init_utils();
|
|
2831
|
+
DRIVER_NAME$2 = "memory";
|
|
2832
|
+
memory_default = defineDriver(() => {
|
|
2833
|
+
const data = new Map();
|
|
2834
|
+
return {
|
|
2835
|
+
name: DRIVER_NAME$2,
|
|
2836
|
+
getInstance: () => data,
|
|
2837
|
+
hasItem(key) {
|
|
2838
|
+
return data.has(key);
|
|
2839
|
+
},
|
|
2840
|
+
getItem(key) {
|
|
2841
|
+
return data.get(key) ?? null;
|
|
2842
|
+
},
|
|
2843
|
+
getItemRaw(key) {
|
|
2844
|
+
return data.get(key) ?? null;
|
|
2845
|
+
},
|
|
2846
|
+
setItem(key, value) {
|
|
2847
|
+
data.set(key, value);
|
|
2848
|
+
},
|
|
2849
|
+
setItemRaw(key, value) {
|
|
2850
|
+
data.set(key, value);
|
|
2851
|
+
},
|
|
2852
|
+
removeItem(key) {
|
|
2853
|
+
data.delete(key);
|
|
2854
|
+
},
|
|
2855
|
+
getKeys() {
|
|
2856
|
+
return [...data.keys()];
|
|
2857
|
+
},
|
|
2858
|
+
clear() {
|
|
2859
|
+
data.clear();
|
|
2860
|
+
},
|
|
2861
|
+
dispose() {
|
|
2862
|
+
data.clear();
|
|
2863
|
+
}
|
|
2864
|
+
};
|
|
2865
|
+
});
|
|
2866
|
+
}));
|
|
2867
|
+
//#endregion
|
|
2868
|
+
//#region ../../node_modules/.pnpm/unstorage@1.17.5/node_modules/unstorage/drivers/localstorage.mjs
|
|
2869
|
+
var localstorage_exports = __exportAll({ default: () => localstorage_default });
|
|
2870
|
+
var DRIVER_NAME$1, localstorage_default;
|
|
2871
|
+
var init_localstorage = __esmMin((() => {
|
|
2872
|
+
init_utils();
|
|
2873
|
+
DRIVER_NAME$1 = "localstorage";
|
|
2874
|
+
localstorage_default = defineDriver((opts = {}) => {
|
|
2875
|
+
const storage = opts.storage || opts.localStorage || opts.sessionStorage || (opts.window || globalThis.window)?.[opts.windowKey || "localStorage"];
|
|
2876
|
+
if (!storage) throw createRequiredError(DRIVER_NAME$1, "localStorage");
|
|
2877
|
+
const base = opts.base ? normalizeKey(opts.base) : "";
|
|
2878
|
+
const r = (key) => (base ? `${base}:` : "") + key;
|
|
2879
|
+
let _storageListener;
|
|
2880
|
+
const _unwatch = () => {
|
|
2881
|
+
if (_storageListener) opts.window?.removeEventListener("storage", _storageListener);
|
|
2882
|
+
_storageListener = void 0;
|
|
2883
|
+
};
|
|
2884
|
+
return {
|
|
2885
|
+
name: DRIVER_NAME$1,
|
|
2886
|
+
options: opts,
|
|
2887
|
+
getInstance: () => storage,
|
|
2888
|
+
hasItem(key) {
|
|
2889
|
+
return Object.prototype.hasOwnProperty.call(storage, r(key));
|
|
2890
|
+
},
|
|
2891
|
+
getItem(key) {
|
|
2892
|
+
return storage.getItem(r(key));
|
|
2893
|
+
},
|
|
2894
|
+
setItem(key, value) {
|
|
2895
|
+
return storage.setItem(r(key), value);
|
|
2896
|
+
},
|
|
2897
|
+
removeItem(key) {
|
|
2898
|
+
return storage.removeItem(r(key));
|
|
2899
|
+
},
|
|
2900
|
+
getKeys() {
|
|
2901
|
+
const allKeys = Object.keys(storage);
|
|
2902
|
+
return base ? allKeys.filter((key) => key.startsWith(`${base}:`)).map((key) => key.slice(base.length + 1)) : allKeys;
|
|
2903
|
+
},
|
|
2904
|
+
clear(prefix) {
|
|
2905
|
+
const _base = [base, prefix].filter(Boolean).join(":");
|
|
2906
|
+
if (_base) {
|
|
2907
|
+
for (const key of Object.keys(storage)) if (key.startsWith(`${_base}:`)) storage?.removeItem(key);
|
|
2908
|
+
} else storage.clear();
|
|
2909
|
+
},
|
|
2910
|
+
dispose() {
|
|
2911
|
+
if (opts.window && _storageListener) opts.window.removeEventListener("storage", _storageListener);
|
|
2912
|
+
},
|
|
2913
|
+
watch(callback) {
|
|
2914
|
+
if (!opts.window) return _unwatch;
|
|
2915
|
+
_storageListener = (ev) => {
|
|
2916
|
+
if (ev.key) callback(ev.newValue ? "update" : "remove", ev.key);
|
|
2917
|
+
};
|
|
2918
|
+
opts.window.addEventListener("storage", _storageListener);
|
|
2919
|
+
return _unwatch;
|
|
2920
|
+
}
|
|
2921
|
+
};
|
|
2922
|
+
});
|
|
2923
|
+
}));
|
|
2872
2924
|
//#endregion
|
|
2873
2925
|
//#region ../../node_modules/.pnpm/unstorage@1.17.5/node_modules/unstorage/drivers/session-storage.mjs
|
|
2874
|
-
|
|
2875
|
-
var session_storage_default
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2926
|
+
var session_storage_exports = __exportAll({ default: () => session_storage_default });
|
|
2927
|
+
var DRIVER_NAME, session_storage_default;
|
|
2928
|
+
var init_session_storage = __esmMin((() => {
|
|
2929
|
+
init_utils();
|
|
2930
|
+
init_localstorage();
|
|
2931
|
+
DRIVER_NAME = "session-storage";
|
|
2932
|
+
session_storage_default = defineDriver((opts = {}) => {
|
|
2933
|
+
return {
|
|
2934
|
+
...localstorage_default({
|
|
2935
|
+
windowKey: "sessionStorage",
|
|
2936
|
+
...opts
|
|
2937
|
+
}),
|
|
2938
|
+
name: DRIVER_NAME
|
|
2939
|
+
};
|
|
2940
|
+
});
|
|
2941
|
+
}));
|
|
2884
2942
|
//#endregion
|
|
2885
2943
|
//#region src/persistence.ts
|
|
2886
2944
|
const KEY = "finueva-auth:session:v1";
|
|
2887
2945
|
const MAX_SNAPSHOT_BYTES = 16 * 1024;
|
|
2888
2946
|
const MAX_FUTURE_SKEW_MS = 300 * 1e3;
|
|
2889
2947
|
function createSessionPersistence(persistence, authOrigin, now, timeoutMs) {
|
|
2890
|
-
|
|
2948
|
+
validatePersistence(persistence);
|
|
2949
|
+
const storageCache = {};
|
|
2950
|
+
const storage = async (persistence) => {
|
|
2951
|
+
if (typeof persistence === "string") {
|
|
2952
|
+
if (storageCache[persistence]) return storageCache[persistence];
|
|
2953
|
+
const storage = createStorage({ driver: guardRawValues(await selectDriver(persistence)) });
|
|
2954
|
+
storageCache[persistence] = storage;
|
|
2955
|
+
return storage;
|
|
2956
|
+
}
|
|
2957
|
+
if (typeof persistence === "object" && persistence !== null) return createStorage({ driver: guardRawValues(adaptDriver(persistence)) });
|
|
2958
|
+
return createStorage({ driver: guardRawValues(await selectDriver(persistence)) });
|
|
2959
|
+
};
|
|
2891
2960
|
let enabled = true;
|
|
2892
2961
|
let generation = 0;
|
|
2893
2962
|
let queue = Promise.resolve();
|
|
2894
2963
|
const operationTimeoutMs = Math.min(timeoutMs, 1e3);
|
|
2895
|
-
function cleanup() {
|
|
2896
|
-
|
|
2964
|
+
async function cleanup() {
|
|
2965
|
+
await (await storage(persistence)).removeItem(KEY);
|
|
2897
2966
|
}
|
|
2898
2967
|
async function finishesWithin(work) {
|
|
2899
2968
|
let timeout;
|
|
@@ -2926,12 +2995,13 @@ function createSessionPersistence(persistence, authOrigin, now, timeoutMs) {
|
|
|
2926
2995
|
return {
|
|
2927
2996
|
hydrate(accept) {
|
|
2928
2997
|
schedule(async (isCurrent) => {
|
|
2929
|
-
const
|
|
2998
|
+
const _storage = await storage(persistence);
|
|
2999
|
+
const value = await _storage.getItem(KEY);
|
|
2930
3000
|
if (!isCurrent()) return;
|
|
2931
3001
|
if (value === null) return;
|
|
2932
3002
|
const session = readSnapshot(value, authOrigin, now());
|
|
2933
3003
|
if (!session) {
|
|
2934
|
-
await
|
|
3004
|
+
await _storage.removeItem(KEY);
|
|
2935
3005
|
return;
|
|
2936
3006
|
}
|
|
2937
3007
|
if (isCurrent()) accept(session);
|
|
@@ -2952,8 +3022,9 @@ function createSessionPersistence(persistence, authOrigin, now, timeoutMs) {
|
|
|
2952
3022
|
};
|
|
2953
3023
|
schedule(async () => {
|
|
2954
3024
|
const cachedAt = now();
|
|
3025
|
+
const _storage = await storage(persistence);
|
|
2955
3026
|
if (expiresAt <= cachedAt) {
|
|
2956
|
-
await
|
|
3027
|
+
await _storage.removeItem(KEY);
|
|
2957
3028
|
return;
|
|
2958
3029
|
}
|
|
2959
3030
|
const snapshot = {
|
|
@@ -2963,28 +3034,57 @@ function createSessionPersistence(persistence, authOrigin, now, timeoutMs) {
|
|
|
2963
3034
|
session: normalizedSession
|
|
2964
3035
|
};
|
|
2965
3036
|
if (byteLength(JSON.stringify(snapshot)) > MAX_SNAPSHOT_BYTES) {
|
|
2966
|
-
await
|
|
3037
|
+
await _storage.removeItem(KEY);
|
|
2967
3038
|
return;
|
|
2968
3039
|
}
|
|
2969
|
-
await
|
|
2970
|
-
if (expiresAt <= now()) await
|
|
3040
|
+
await _storage.setItem(KEY, snapshot);
|
|
3041
|
+
if (expiresAt <= now()) await _storage.removeItem(KEY);
|
|
2971
3042
|
});
|
|
2972
3043
|
},
|
|
2973
3044
|
remove() {
|
|
2974
|
-
schedule(() =>
|
|
3045
|
+
schedule(async () => {
|
|
3046
|
+
(await storage(persistence)).removeItem(KEY);
|
|
3047
|
+
});
|
|
2975
3048
|
}
|
|
2976
3049
|
};
|
|
2977
3050
|
}
|
|
2978
|
-
function
|
|
3051
|
+
function validatePersistence(persistence) {
|
|
3052
|
+
if (persistence === void 0) return;
|
|
3053
|
+
if (persistence === "local" || persistence === "session" || persistence === "memory") return;
|
|
3054
|
+
if (typeof persistence === "object" && persistence !== null) {
|
|
3055
|
+
adaptDriver(persistence);
|
|
3056
|
+
return;
|
|
3057
|
+
}
|
|
3058
|
+
throw new TypeError("persistence must be local, session, memory, or a driver");
|
|
3059
|
+
}
|
|
3060
|
+
async function selectDriver(persistence) {
|
|
2979
3061
|
if (typeof persistence === "object" && persistence !== null) return adaptDriver(persistence);
|
|
2980
|
-
if (persistence === "memory")
|
|
3062
|
+
if (persistence === "memory") {
|
|
3063
|
+
const { default: memoryDriver } = await Promise.resolve().then(() => (init_memory(), memory_exports));
|
|
3064
|
+
return memoryDriver();
|
|
3065
|
+
}
|
|
2981
3066
|
if (persistence === "local" || persistence === "session") {
|
|
2982
3067
|
const storage = browserStorage(persistence);
|
|
2983
|
-
|
|
3068
|
+
if (persistence === "local") {
|
|
3069
|
+
const { default: localStorageDriver } = await Promise.resolve().then(() => (init_localstorage(), localstorage_exports));
|
|
3070
|
+
if (storage) return localStorageDriver({ storage });
|
|
3071
|
+
const { default: memoryDriver } = await Promise.resolve().then(() => (init_memory(), memory_exports));
|
|
3072
|
+
return memoryDriver();
|
|
3073
|
+
} else {
|
|
3074
|
+
const { default: sessionStorageDriver } = await Promise.resolve().then(() => (init_session_storage(), session_storage_exports));
|
|
3075
|
+
if (storage) return sessionStorageDriver({ storage });
|
|
3076
|
+
const { default: memoryDriver } = await Promise.resolve().then(() => (init_memory(), memory_exports));
|
|
3077
|
+
return memoryDriver();
|
|
3078
|
+
}
|
|
2984
3079
|
}
|
|
2985
3080
|
if (persistence !== void 0) throw new TypeError("persistence must be local, session, memory, or a driver");
|
|
2986
3081
|
const storage = browserStorage("local");
|
|
2987
|
-
|
|
3082
|
+
if (storage) {
|
|
3083
|
+
const { default: localStorageDriver } = await Promise.resolve().then(() => (init_localstorage(), localstorage_exports));
|
|
3084
|
+
return localStorageDriver({ storage });
|
|
3085
|
+
}
|
|
3086
|
+
const { default: memoryDriver } = await Promise.resolve().then(() => (init_memory(), memory_exports));
|
|
3087
|
+
return memoryDriver();
|
|
2988
3088
|
}
|
|
2989
3089
|
function browserStorage(mode) {
|
|
2990
3090
|
try {
|
|
@@ -3324,6 +3424,16 @@ function createAuthClient(options) {
|
|
|
3324
3424
|
if (activeSignInGeneration === generation) activeSignInGeneration = void 0;
|
|
3325
3425
|
}
|
|
3326
3426
|
},
|
|
3427
|
+
async sendVerificationEmail(input) {
|
|
3428
|
+
const body = normalizeVerificationEmailInput(input, appOrigin);
|
|
3429
|
+
normalizeVerificationEmailResponse(await requestJson(joinURL(authOrigin, "api/v1/auth/send-verification-email"), {
|
|
3430
|
+
fetch: fetchImpl,
|
|
3431
|
+
timeoutMs,
|
|
3432
|
+
method: "POST",
|
|
3433
|
+
headers: { "content-type": "application/json; charset=utf-8" },
|
|
3434
|
+
body
|
|
3435
|
+
}));
|
|
3436
|
+
},
|
|
3327
3437
|
signOut,
|
|
3328
3438
|
getDriveCredential(input) {
|
|
3329
3439
|
let workspace;
|
package/dist/server.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as WorkspaceSelection, c as AuthUser, f as InvitationAcceptance, l as DriveCredential, m as PersonalWorkspaceSelection, o as AuthSession, p as OrganizationWorkspaceSelection, r as AuthOrganization, t as AcceptInvitationInput, u as DriveCredentialInput } from "./types-HSdjQWMZ.js";
|
|
2
2
|
import { n as AuthErrorCode, r as AuthErrorStatus, t as AuthError } from "./errors-Crd93Rah.js";
|
|
3
3
|
//#region src/server.d.ts
|
|
4
4
|
interface ServerAuthOptions {
|
|
@@ -64,6 +64,10 @@ interface SignInInput {
|
|
|
64
64
|
email: string;
|
|
65
65
|
password: string;
|
|
66
66
|
}
|
|
67
|
+
interface SendVerificationEmailInput {
|
|
68
|
+
email: string;
|
|
69
|
+
callbackURL?: string;
|
|
70
|
+
}
|
|
67
71
|
interface DriveCredentialInput {
|
|
68
72
|
workspace: WorkspaceSelection;
|
|
69
73
|
forceRefresh?: boolean;
|
|
@@ -80,6 +84,7 @@ interface FinuevaAuthClient {
|
|
|
80
84
|
acceptInvitation(input: AcceptInvitationInput): Promise<InvitationAcceptance>;
|
|
81
85
|
getSession(): Promise<AuthSession | null>;
|
|
82
86
|
listOrganizations(): Promise<AuthOrganization[]>;
|
|
87
|
+
sendVerificationEmail(input: SendVerificationEmailInput): Promise<void>;
|
|
83
88
|
signIn(input: SignInInput): Promise<AuthSession>;
|
|
84
89
|
signOut(): Promise<void>;
|
|
85
90
|
getDriveCredential(input: DriveCredentialInput): Promise<DriveCredential>;
|
|
@@ -87,4 +92,4 @@ interface FinuevaAuthClient {
|
|
|
87
92
|
onSessionChange(listener: (session: AuthSession | null) => void): () => void;
|
|
88
93
|
}
|
|
89
94
|
//#endregion
|
|
90
|
-
export { AuthPersistenceDriver as a, AuthUser as c, FinuevaAuthClient as d, InvitationAcceptance as f,
|
|
95
|
+
export { WorkspaceSelection as _, AuthPersistenceDriver as a, AuthUser as c, FinuevaAuthClient as d, InvitationAcceptance as f, SignInInput as g, SendVerificationEmailInput as h, AuthPersistence as i, DriveCredential as l, PersonalWorkspaceSelection as m, AuthClientOptions as n, AuthSession as o, OrganizationWorkspaceSelection as p, AuthOrganization as r, AuthState as s, AcceptInvitationInput as t, DriveCredentialInput as u };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@finueva/auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Public browser and server SDK for Finueva Auth",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "rolldown -c",
|
|
42
42
|
"coverage": "vitest run --coverage",
|
|
43
|
-
"lint": "
|
|
43
|
+
"lint": "oxlint . --deny-warnings",
|
|
44
44
|
"test": "pnpm test:unit && pnpm build && pnpm test:package",
|
|
45
45
|
"test:composition": "node scripts/test-composition.mjs",
|
|
46
46
|
"test:package": "node scripts/test-package.mjs",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@chiballc/utils": "2.2.22",
|
|
52
52
|
"@types/node": "24.13.3",
|
|
53
|
+
"@typescript/native": "npm:typescript@7.0.2",
|
|
53
54
|
"@vitest/coverage-v8": "4.1.10",
|
|
54
55
|
"better-auth": "1.6.22",
|
|
55
56
|
"miniflare": "4.20260722.0",
|
|
@@ -57,7 +58,7 @@
|
|
|
57
58
|
"playwright": "1.62.0",
|
|
58
59
|
"rolldown": "1.2.0",
|
|
59
60
|
"rolldown-plugin-dts": "0.27.14",
|
|
60
|
-
"typescript": "
|
|
61
|
+
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
61
62
|
"ufo": "1.6.4",
|
|
62
63
|
"unstorage": "1.17.5",
|
|
63
64
|
"vitest": "4.1.10"
|