@lupinum/better-convex-nuxt 0.8.0-beta.40
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/LICENSE +21 -0
- package/LICENSES/Apache-2.0.txt +201 -0
- package/README.md +151 -0
- package/THIRD_PARTY_NOTICES.md +38 -0
- package/dist/module.d.mts +55 -0
- package/dist/module.json +12 -0
- package/dist/module.mjs +309 -0
- package/dist/runtime/auth/auth-identity.d.ts +31 -0
- package/dist/runtime/auth/auth-identity.js +21 -0
- package/dist/runtime/auth/better-auth-browser-adapter.d.ts +33 -0
- package/dist/runtime/auth/better-auth-browser-adapter.js +215 -0
- package/dist/runtime/auth/client-engine-types.d.ts +4 -0
- package/dist/runtime/auth/client-engine-types.js +0 -0
- package/dist/runtime/auth/integrated-client.d.ts +25 -0
- package/dist/runtime/auth/integrated-client.js +132 -0
- package/dist/runtime/auth/operation-tracker.d.ts +7 -0
- package/dist/runtime/auth/operation-tracker.js +14 -0
- package/dist/runtime/auth/session-synchronization.d.ts +23 -0
- package/dist/runtime/auth/session-synchronization.js +156 -0
- package/dist/runtime/auth/token-fetcher.d.ts +66 -0
- package/dist/runtime/auth/token-fetcher.js +131 -0
- package/dist/runtime/auth/validate-auth-client-definition.d.ts +12 -0
- package/dist/runtime/auth/validate-auth-client-definition.js +47 -0
- package/dist/runtime/auth-client/convex-client-plugin.d.ts +31 -0
- package/dist/runtime/auth-client/convex-client-plugin.js +14 -0
- package/dist/runtime/auth-client/definition-types.d.ts +6 -0
- package/dist/runtime/auth-client/definition-types.js +0 -0
- package/dist/runtime/auth-client/empty-definition.d.ts +2 -0
- package/dist/runtime/auth-client/empty-definition.js +2 -0
- package/dist/runtime/auth-client/index.d.ts +71 -0
- package/dist/runtime/auth-client/index.js +3 -0
- package/dist/runtime/cli/auth-schema.d.ts +2 -0
- package/dist/runtime/cli/auth-schema.js +169 -0
- package/dist/runtime/cli/convex.d.ts +11 -0
- package/dist/runtime/cli/convex.js +274 -0
- package/dist/runtime/composables/useConvex.d.ts +4 -0
- package/dist/runtime/composables/useConvex.js +9 -0
- package/dist/runtime/composables/useConvexAction.d.ts +4 -0
- package/dist/runtime/composables/useConvexAction.js +18 -0
- package/dist/runtime/composables/useConvexAttachment.d.ts +9 -0
- package/dist/runtime/composables/useConvexAttachment.js +14 -0
- package/dist/runtime/composables/useConvexAuth.d.ts +10 -0
- package/dist/runtime/composables/useConvexAuth.js +37 -0
- package/dist/runtime/composables/useConvexConfig.d.ts +12 -0
- package/dist/runtime/composables/useConvexConfig.js +7 -0
- package/dist/runtime/composables/useConvexConnectionState.d.ts +33 -0
- package/dist/runtime/composables/useConvexConnectionState.js +24 -0
- package/dist/runtime/composables/useConvexFileUpload.d.ts +169 -0
- package/dist/runtime/composables/useConvexFileUpload.js +198 -0
- package/dist/runtime/composables/useConvexMutation.d.ts +13 -0
- package/dist/runtime/composables/useConvexMutation.js +24 -0
- package/dist/runtime/composables/useConvexPaginatedQuery.d.ts +13 -0
- package/dist/runtime/composables/useConvexPaginatedQuery.js +256 -0
- package/dist/runtime/composables/useConvexQuery.d.ts +19 -0
- package/dist/runtime/composables/useConvexQuery.js +308 -0
- package/dist/runtime/convex-auth/adapter/create-adapter.d.ts +33 -0
- package/dist/runtime/convex-auth/adapter/create-adapter.js +308 -0
- package/dist/runtime/convex-auth/adapter/define-functions.d.ts +160 -0
- package/dist/runtime/convex-auth/adapter/define-functions.js +497 -0
- package/dist/runtime/convex-auth/adapter/generate-schema.d.ts +16 -0
- package/dist/runtime/convex-auth/adapter/generate-schema.js +332 -0
- package/dist/runtime/convex-auth/adapter/metadata.d.ts +44 -0
- package/dist/runtime/convex-auth/adapter/metadata.js +91 -0
- package/dist/runtime/convex-auth/adapter/query.d.ts +32 -0
- package/dist/runtime/convex-auth/adapter/query.js +275 -0
- package/dist/runtime/convex-auth/adapter/relationships.d.ts +20 -0
- package/dist/runtime/convex-auth/adapter/relationships.js +128 -0
- package/dist/runtime/convex-auth/component/_generated/api.js +5 -0
- package/dist/runtime/convex-auth/component/_generated/component.d.ts +116 -0
- package/dist/runtime/convex-auth/component/_generated/component.js +0 -0
- package/dist/runtime/convex-auth/component/_generated/dataModel.js +0 -0
- package/dist/runtime/convex-auth/component/_generated/server.js +16 -0
- package/dist/runtime/convex-auth/component/adapter.d.ts +142 -0
- package/dist/runtime/convex-auth/component/adapter.js +16 -0
- package/dist/runtime/convex-auth/component/convex.config.d.ts +2 -0
- package/dist/runtime/convex-auth/component/convex.config.js +3 -0
- package/dist/runtime/convex-auth/component/schema.d.ts +799 -0
- package/dist/runtime/convex-auth/component/schema.js +180 -0
- package/dist/runtime/convex-auth/component/schemaMetadata.d.ts +2094 -0
- package/dist/runtime/convex-auth/component/schemaMetadata.js +2161 -0
- package/dist/runtime/convex-auth/context.d.ts +5 -0
- package/dist/runtime/convex-auth/context.js +8 -0
- package/dist/runtime/convex-auth/create-auth-component.d.ts +41 -0
- package/dist/runtime/convex-auth/create-auth-component.js +157 -0
- package/dist/runtime/convex-auth/index.d.ts +11 -0
- package/dist/runtime/convex-auth/index.js +7 -0
- package/dist/runtime/convex-auth/internal-session.d.ts +2 -0
- package/dist/runtime/convex-auth/internal-session.js +1 -0
- package/dist/runtime/convex-auth/jwks-rotation.d.ts +58 -0
- package/dist/runtime/convex-auth/jwks-rotation.js +163 -0
- package/dist/runtime/convex-auth/oauth-live-access.d.ts +17 -0
- package/dist/runtime/convex-auth/oauth-live-access.js +78 -0
- package/dist/runtime/convex-auth/oauth-provider-compat.d.ts +10 -0
- package/dist/runtime/convex-auth/oauth-provider-compat.js +170 -0
- package/dist/runtime/convex-auth/oauth-resource.d.ts +39 -0
- package/dist/runtime/convex-auth/oauth-resource.js +118 -0
- package/dist/runtime/convex-auth/oauth-security.d.ts +82 -0
- package/dist/runtime/convex-auth/oauth-security.js +454 -0
- package/dist/runtime/convex-auth/origin.d.ts +4 -0
- package/dist/runtime/convex-auth/origin.js +9 -0
- package/dist/runtime/convex-auth/plugin.d.ts +18 -0
- package/dist/runtime/convex-auth/plugin.js +605 -0
- package/dist/runtime/convex-auth/provider.d.ts +2 -0
- package/dist/runtime/convex-auth/provider.js +11 -0
- package/dist/runtime/convex-auth/test.d.ts +410 -0
- package/dist/runtime/convex-auth/test.js +9 -0
- package/dist/runtime/convex-auth/types.d.ts +18 -0
- package/dist/runtime/convex-auth/types.js +0 -0
- package/dist/runtime/convex-auth/user-projection.d.ts +106 -0
- package/dist/runtime/convex-auth/user-projection.js +128 -0
- package/dist/runtime/devtools/auth-proxy-registry.d.ts +4 -0
- package/dist/runtime/devtools/auth-proxy-registry.js +47 -0
- package/dist/runtime/devtools/bridge-setup.d.ts +21 -0
- package/dist/runtime/devtools/bridge-setup.js +165 -0
- package/dist/runtime/devtools/path-utils.d.ts +2 -0
- package/dist/runtime/devtools/path-utils.js +12 -0
- package/dist/runtime/devtools/server.d.ts +2 -0
- package/dist/runtime/devtools/server.js +108 -0
- package/dist/runtime/devtools/setup-client.d.ts +16 -0
- package/dist/runtime/devtools/setup-client.js +43 -0
- package/dist/runtime/devtools/sink.d.ts +18 -0
- package/dist/runtime/devtools/sink.js +110 -0
- package/dist/runtime/devtools/transport.d.ts +16 -0
- package/dist/runtime/devtools/transport.js +149 -0
- package/dist/runtime/devtools/types.d.ts +167 -0
- package/dist/runtime/devtools/types.js +1 -0
- package/dist/runtime/devtools/ui/dist/200.html +1 -0
- package/dist/runtime/devtools/ui/dist/404.html +1 -0
- package/dist/runtime/devtools/ui/dist/_nuxt/C4MASuCh.js +1 -0
- package/dist/runtime/devtools/ui/dist/_nuxt/DJHkqtZq.js +3 -0
- package/dist/runtime/devtools/ui/dist/_nuxt/DWwrCltl.js +2 -0
- package/dist/runtime/devtools/ui/dist/_nuxt/DZ_UiYoH.js +1 -0
- package/dist/runtime/devtools/ui/dist/_nuxt/_m9ujb-i.js +1 -0
- package/dist/runtime/devtools/ui/dist/_nuxt/builds/latest.json +1 -0
- package/dist/runtime/devtools/ui/dist/_nuxt/builds/meta/better-convex-nuxt-devtools.json +1 -0
- package/dist/runtime/devtools/ui/dist/_nuxt/entry.DpFDKYZ5.css +1 -0
- package/dist/runtime/devtools/ui/dist/_nuxt/error-404.DYUJo5xt.css +1 -0
- package/dist/runtime/devtools/ui/dist/_nuxt/error-500.DQdoJJXg.css +1 -0
- package/dist/runtime/devtools/ui/dist/convex-logo.svg +5 -0
- package/dist/runtime/devtools/ui/dist/index.html +1 -0
- package/dist/runtime/errors/index.d.ts +7 -0
- package/dist/runtime/errors/index.js +5 -0
- package/dist/runtime/middleware/convex-auth.global.d.ts +2 -0
- package/dist/runtime/middleware/convex-auth.global.js +31 -0
- package/dist/runtime/plugin.auth.client.d.ts +3 -0
- package/dist/runtime/plugin.auth.client.js +217 -0
- package/dist/runtime/plugin.client.d.ts +3 -0
- package/dist/runtime/plugin.client.js +43 -0
- package/dist/runtime/plugin.server.d.ts +12 -0
- package/dist/runtime/plugin.server.js +98 -0
- package/dist/runtime/plugins/convex-call-error-payload.d.ts +14 -0
- package/dist/runtime/plugins/convex-call-error-payload.js +12 -0
- package/dist/runtime/runtime-context.d.ts +26 -0
- package/dist/runtime/runtime-context.js +48 -0
- package/dist/runtime/server/api/auth/[...].d.ts +10 -0
- package/dist/runtime/server/api/auth/[...].js +509 -0
- package/dist/runtime/server/api/auth/authorization-server-metadata.d.ts +2 -0
- package/dist/runtime/server/api/auth/authorization-server-metadata.js +6 -0
- package/dist/runtime/server/api/auth/body-size.d.ts +15 -0
- package/dist/runtime/server/api/auth/body-size.js +179 -0
- package/dist/runtime/server/api/auth/headers.d.ts +6 -0
- package/dist/runtime/server/api/auth/headers.js +98 -0
- package/dist/runtime/server/api/auth/jwks.d.ts +2 -0
- package/dist/runtime/server/api/auth/jwks.js +6 -0
- package/dist/runtime/server/api/auth/security.d.ts +14 -0
- package/dist/runtime/server/api/auth/security.js +85 -0
- package/dist/runtime/server/api/release-fingerprint.d.ts +2 -0
- package/dist/runtime/server/api/release-fingerprint.js +36 -0
- package/dist/runtime/server/index.d.ts +1 -0
- package/dist/runtime/server/index.js +3 -0
- package/dist/runtime/server/plugins/runtime-config.d.ts +7 -0
- package/dist/runtime/server/plugins/runtime-config.js +7 -0
- package/dist/runtime/server/utils/auth-snapshot.d.ts +26 -0
- package/dist/runtime/server/utils/auth-snapshot.js +165 -0
- package/dist/runtime/server/utils/http.d.ts +16 -0
- package/dist/runtime/server/utils/http.js +133 -0
- package/dist/runtime/server/utils/server-convex-caller.d.ts +31 -0
- package/dist/runtime/server/utils/server-convex-caller.js +151 -0
- package/dist/runtime/server/utils/server-convex-options.d.ts +83 -0
- package/dist/runtime/server/utils/server-convex-options.js +69 -0
- package/dist/runtime/server/utils/signed-client-ip.d.ts +6 -0
- package/dist/runtime/server/utils/signed-client-ip.js +29 -0
- package/dist/runtime/server/utils/ssr-auth-headers.d.ts +26 -0
- package/dist/runtime/server/utils/ssr-auth-headers.js +49 -0
- package/dist/runtime/server/utils/token-exchange.d.ts +27 -0
- package/dist/runtime/server/utils/token-exchange.js +96 -0
- package/dist/runtime/shared/auth-cookie.d.ts +4 -0
- package/dist/runtime/shared/auth-cookie.js +25 -0
- package/dist/runtime/shared/auth-origin.d.ts +15 -0
- package/dist/runtime/shared/auth-origin.js +42 -0
- package/dist/runtime/shared/bounded-stream.d.ts +2 -0
- package/dist/runtime/shared/bounded-stream.js +50 -0
- package/dist/runtime/shared/client-ip.d.ts +21 -0
- package/dist/runtime/shared/client-ip.js +123 -0
- package/dist/runtime/shared/release-fingerprint.d.ts +5 -0
- package/dist/runtime/shared/release-fingerprint.js +17 -0
- package/dist/runtime/types.d.ts +19 -0
- package/dist/runtime/utils/auth-config.d.ts +24 -0
- package/dist/runtime/utils/auth-config.js +45 -0
- package/dist/runtime/utils/auth-contract.d.ts +22 -0
- package/dist/runtime/utils/auth-contract.js +0 -0
- package/dist/runtime/utils/auth-errors.d.ts +5 -0
- package/dist/runtime/utils/auth-errors.js +22 -0
- package/dist/runtime/utils/auth-identity-state.d.ts +4 -0
- package/dist/runtime/utils/auth-identity-state.js +8 -0
- package/dist/runtime/utils/auth-pending-state.d.ts +13 -0
- package/dist/runtime/utils/auth-pending-state.js +4 -0
- package/dist/runtime/utils/auth-pending.d.ts +10 -0
- package/dist/runtime/utils/auth-pending.js +30 -0
- package/dist/runtime/utils/auth-route-protection.d.ts +16 -0
- package/dist/runtime/utils/auth-route-protection.js +58 -0
- package/dist/runtime/utils/auth-status.d.ts +47 -0
- package/dist/runtime/utils/auth-status.js +8 -0
- package/dist/runtime/utils/bounded-convex-fetch.d.ts +18 -0
- package/dist/runtime/utils/bounded-convex-fetch.js +152 -0
- package/dist/runtime/utils/callable-devtools.d.ts +17 -0
- package/dist/runtime/utils/callable-devtools.js +49 -0
- package/dist/runtime/utils/callable-observer.d.ts +2 -0
- package/dist/runtime/utils/callable-observer.js +1 -0
- package/dist/runtime/utils/composable-scope.d.ts +2 -0
- package/dist/runtime/utils/composable-scope.js +8 -0
- package/dist/runtime/utils/config-defaults.d.ts +8 -0
- package/dist/runtime/utils/config-defaults.js +8 -0
- package/dist/runtime/utils/convex-cache.d.ts +68 -0
- package/dist/runtime/utils/convex-cache.js +47 -0
- package/dist/runtime/utils/convex-config.d.ts +16 -0
- package/dist/runtime/utils/convex-config.js +50 -0
- package/dist/runtime/utils/convex-shared.d.ts +67 -0
- package/dist/runtime/utils/convex-shared.js +134 -0
- package/dist/runtime/utils/identity-changed-error.d.ts +4 -0
- package/dist/runtime/utils/identity-changed-error.js +12 -0
- package/dist/runtime/utils/identity-key.d.ts +19 -0
- package/dist/runtime/utils/identity-key.js +10 -0
- package/dist/runtime/utils/integrated-auth-client.d.ts +5 -0
- package/dist/runtime/utils/integrated-auth-client.js +0 -0
- package/dist/runtime/utils/logger.d.ts +42 -0
- package/dist/runtime/utils/logger.js +190 -0
- package/dist/runtime/utils/mime-type.d.ts +33 -0
- package/dist/runtime/utils/mime-type.js +10 -0
- package/dist/runtime/utils/query-execution-gate.d.ts +47 -0
- package/dist/runtime/utils/query-execution-gate.js +63 -0
- package/dist/runtime/utils/query-execution.d.ts +8 -0
- package/dist/runtime/utils/query-execution.js +19 -0
- package/dist/runtime/utils/query-foundation.d.ts +20 -0
- package/dist/runtime/utils/query-foundation.js +39 -0
- package/dist/runtime/utils/query-state.d.ts +12 -0
- package/dist/runtime/utils/query-state.js +12 -0
- package/dist/runtime/utils/reactive-args.d.ts +5 -0
- package/dist/runtime/utils/reactive-args.js +42 -0
- package/dist/runtime/utils/runtime-config-normalize.d.ts +22 -0
- package/dist/runtime/utils/runtime-config-normalize.js +28 -0
- package/dist/runtime/utils/runtime-config.d.ts +4 -0
- package/dist/runtime/utils/runtime-config.js +8 -0
- package/dist/runtime/utils/sanitize-diagnostic.d.ts +6 -0
- package/dist/runtime/utils/sanitize-diagnostic.js +81 -0
- package/dist/runtime/utils/shared-helpers.d.ts +46 -0
- package/dist/runtime/utils/shared-helpers.js +139 -0
- package/dist/runtime/utils/site-url.d.ts +4 -0
- package/dist/runtime/utils/site-url.js +15 -0
- package/dist/runtime/utils/ssr-pagination-state.d.ts +3 -0
- package/dist/runtime/utils/ssr-pagination-state.js +3 -0
- package/dist/runtime/utils/types.d.ts +29 -0
- package/dist/runtime/utils/types.js +0 -0
- package/dist/runtime/utils/upload-core.d.ts +16 -0
- package/dist/runtime/utils/upload-core.js +116 -0
- package/dist/types.d.mts +21 -0
- package/package.json +253 -0
- package/security/upstream-convex-better-auth.json +477 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
const HIDDEN_ROOT_KEYS = /* @__PURE__ */ new Set([
|
|
2
|
+
"$fetch",
|
|
3
|
+
"$store",
|
|
4
|
+
"hydrateSession",
|
|
5
|
+
// Installed only for the module-owned token exchange. It is intentionally
|
|
6
|
+
// absent from the inferred consumer type and must also be absent at runtime.
|
|
7
|
+
"convex"
|
|
8
|
+
]);
|
|
9
|
+
const NON_THENABLE_ROOT_KEYS = /* @__PURE__ */ new Set(["then", "catch", "finally"]);
|
|
10
|
+
function isObjectLike(value) {
|
|
11
|
+
return typeof value === "object" && value !== null || typeof value === "function";
|
|
12
|
+
}
|
|
13
|
+
function isPromiseLike(value) {
|
|
14
|
+
if (!isObjectLike(value)) return false;
|
|
15
|
+
return typeof Reflect.get(value, "then") === "function";
|
|
16
|
+
}
|
|
17
|
+
export function createIntegratedAuthClient(client, reconciler, track = (operation) => operation) {
|
|
18
|
+
const wrappedByRaw = /* @__PURE__ */ new WeakMap();
|
|
19
|
+
const rawByWrapped = /* @__PURE__ */ new WeakMap();
|
|
20
|
+
const propertyCache = /* @__PURE__ */ new WeakMap();
|
|
21
|
+
const unwrap = (value) => isObjectLike(value) ? rawByWrapped.get(value) ?? value : value;
|
|
22
|
+
const wrap = (raw, depth) => {
|
|
23
|
+
const existing = wrappedByRaw.get(raw);
|
|
24
|
+
if (existing) return existing;
|
|
25
|
+
const exposeResult = (value) => {
|
|
26
|
+
if (!isObjectLike(value)) return value;
|
|
27
|
+
const known = wrappedByRaw.get(value);
|
|
28
|
+
if (known) return known;
|
|
29
|
+
if (rawByWrapped.has(value)) return value;
|
|
30
|
+
return typeof value === "function" ? wrap(value, depth + 1) : value;
|
|
31
|
+
};
|
|
32
|
+
const target = typeof raw === "function" ? (..._arguments) => void 0 : /* @__PURE__ */ Object.create(null);
|
|
33
|
+
const readExposedProperty = (property) => {
|
|
34
|
+
let cached = propertyCache.get(raw);
|
|
35
|
+
if (!cached) {
|
|
36
|
+
cached = /* @__PURE__ */ new Map();
|
|
37
|
+
propertyCache.set(raw, cached);
|
|
38
|
+
}
|
|
39
|
+
if (cached.has(property)) return cached.get(property);
|
|
40
|
+
const value = Reflect.get(raw, property, raw);
|
|
41
|
+
const exposed = isObjectLike(value) ? wrap(value, depth + 1) : value;
|
|
42
|
+
cached.set(property, exposed);
|
|
43
|
+
return exposed;
|
|
44
|
+
};
|
|
45
|
+
const isHidden = (property) => depth === 0 && (HIDDEN_ROOT_KEYS.has(property) || NON_THENABLE_ROOT_KEYS.has(property));
|
|
46
|
+
const proxy = new Proxy(target, {
|
|
47
|
+
get(_target, property) {
|
|
48
|
+
if (isHidden(property)) return void 0;
|
|
49
|
+
return readExposedProperty(property);
|
|
50
|
+
},
|
|
51
|
+
has(_target, property) {
|
|
52
|
+
if (isHidden(property)) return false;
|
|
53
|
+
return Reflect.has(raw, property);
|
|
54
|
+
},
|
|
55
|
+
ownKeys(shadow) {
|
|
56
|
+
const keys = new Set(Reflect.ownKeys(shadow));
|
|
57
|
+
for (const property of Reflect.ownKeys(raw)) {
|
|
58
|
+
if (!isHidden(property)) keys.add(property);
|
|
59
|
+
}
|
|
60
|
+
return [...keys];
|
|
61
|
+
},
|
|
62
|
+
getOwnPropertyDescriptor(shadow, property) {
|
|
63
|
+
const shadowDescriptor = Reflect.getOwnPropertyDescriptor(shadow, property);
|
|
64
|
+
if (shadowDescriptor && shadowDescriptor.configurable === false) return shadowDescriptor;
|
|
65
|
+
if (isHidden(property)) return void 0;
|
|
66
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(raw, property);
|
|
67
|
+
if (!descriptor) return shadowDescriptor;
|
|
68
|
+
return {
|
|
69
|
+
configurable: true,
|
|
70
|
+
enumerable: descriptor.enumerable,
|
|
71
|
+
...descriptor.get || descriptor.set ? {
|
|
72
|
+
get: descriptor.get ? () => readExposedProperty(property) : void 0,
|
|
73
|
+
set: void 0
|
|
74
|
+
} : {
|
|
75
|
+
value: readExposedProperty(property),
|
|
76
|
+
writable: false
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
set() {
|
|
81
|
+
return false;
|
|
82
|
+
},
|
|
83
|
+
defineProperty() {
|
|
84
|
+
return false;
|
|
85
|
+
},
|
|
86
|
+
deleteProperty() {
|
|
87
|
+
return false;
|
|
88
|
+
},
|
|
89
|
+
setPrototypeOf() {
|
|
90
|
+
return false;
|
|
91
|
+
},
|
|
92
|
+
preventExtensions() {
|
|
93
|
+
return false;
|
|
94
|
+
},
|
|
95
|
+
apply(_target, thisArgument, argumentsList) {
|
|
96
|
+
const checkpoint = reconciler.checkpoint();
|
|
97
|
+
let result;
|
|
98
|
+
let promiseLike;
|
|
99
|
+
try {
|
|
100
|
+
result = Reflect.apply(
|
|
101
|
+
raw,
|
|
102
|
+
unwrap(thisArgument),
|
|
103
|
+
argumentsList
|
|
104
|
+
);
|
|
105
|
+
promiseLike = isPromiseLike(result);
|
|
106
|
+
} catch (error) {
|
|
107
|
+
reconciler.cancel(checkpoint);
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
if (!promiseLike) {
|
|
111
|
+
reconciler.cancel(checkpoint);
|
|
112
|
+
return exposeResult(result);
|
|
113
|
+
}
|
|
114
|
+
const reconciled = Promise.resolve(result).then(
|
|
115
|
+
async (value) => {
|
|
116
|
+
await reconciler.reconcile(checkpoint);
|
|
117
|
+
return exposeResult(value);
|
|
118
|
+
},
|
|
119
|
+
async (error) => {
|
|
120
|
+
await reconciler.reconcile(checkpoint);
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
);
|
|
124
|
+
return track(reconciled);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
wrappedByRaw.set(raw, proxy);
|
|
128
|
+
rawByWrapped.set(proxy, raw);
|
|
129
|
+
return proxy;
|
|
130
|
+
};
|
|
131
|
+
return wrap(client, 0);
|
|
132
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ComputedRef } from 'vue';
|
|
2
|
+
/** Tracks actual asynchronous Better Auth work without serializing callers. */
|
|
3
|
+
export interface AuthOperationTracker {
|
|
4
|
+
readonly isPending: ComputedRef<boolean>;
|
|
5
|
+
track<Value>(operation: Promise<Value>): Promise<Value>;
|
|
6
|
+
}
|
|
7
|
+
export declare function createAuthOperationTracker(): AuthOperationTracker;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { computed, ref } from "vue";
|
|
2
|
+
export function createAuthOperationTracker() {
|
|
3
|
+
const pendingCount = ref(0);
|
|
4
|
+
const isPending = computed(() => pendingCount.value > 0);
|
|
5
|
+
return {
|
|
6
|
+
isPending,
|
|
7
|
+
track(operation) {
|
|
8
|
+
pendingCount.value += 1;
|
|
9
|
+
return operation.finally(() => {
|
|
10
|
+
pendingCount.value -= 1;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ConvexCallError } from '../errors/index.js';
|
|
2
|
+
import type { CanonicalSessionReconciler } from './integrated-client.js';
|
|
3
|
+
export interface ProviderSessionRevision {
|
|
4
|
+
readonly sessionToken: string | null;
|
|
5
|
+
readonly revision: number;
|
|
6
|
+
readonly failed: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface SessionSynchronization extends CanonicalSessionReconciler {
|
|
9
|
+
/** Published synchronously by the one Better Auth session observer. */
|
|
10
|
+
observeProvider(session: ProviderSessionRevision): void;
|
|
11
|
+
/** Published only after the one Convex runtime has settled this generation. */
|
|
12
|
+
observeAccepted(session: ProviderSessionRevision, failed: boolean): void;
|
|
13
|
+
dispose(): void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Correlates the canonical Better Auth session revision with Convex runtime
|
|
17
|
+
* acceptance. Provider tokens remain private to this browser-only boundary.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createSessionSynchronization(input: {
|
|
20
|
+
timeoutMs: number;
|
|
21
|
+
refetchCanonicalSession: () => Promise<void>;
|
|
22
|
+
failClosed: (failure: ConvexCallError) => void;
|
|
23
|
+
}): SessionSynchronization;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { ConvexCallError } from "../errors/index.js";
|
|
2
|
+
const DISPOSED_CODE = "AUTH_CLIENT_DISPOSED";
|
|
3
|
+
const REFRESH_FAILED_CODE = "SESSION_RECONCILIATION_REFRESH_FAILED";
|
|
4
|
+
const RUNTIME_FAILED_CODE = "SESSION_RECONCILIATION_RUNTIME_FAILED";
|
|
5
|
+
const SYNC_CHANGE_CODE = "SYNCHRONOUS_SESSION_CHANGE";
|
|
6
|
+
const TIMEOUT_CODE = "SESSION_RECONCILIATION_TIMEOUT";
|
|
7
|
+
function failure(code, message) {
|
|
8
|
+
return new ConvexCallError({ kind: "authentication", code, message });
|
|
9
|
+
}
|
|
10
|
+
function sameSession(left, right) {
|
|
11
|
+
return left.revision === right.revision && left.sessionToken === right.sessionToken;
|
|
12
|
+
}
|
|
13
|
+
export function createSessionSynchronization(input) {
|
|
14
|
+
let disposed = false;
|
|
15
|
+
let provider;
|
|
16
|
+
let accepted;
|
|
17
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
18
|
+
const notify = () => {
|
|
19
|
+
for (const listener of [...listeners]) listener();
|
|
20
|
+
};
|
|
21
|
+
const failClosed = (authFailure) => {
|
|
22
|
+
try {
|
|
23
|
+
input.failClosed(authFailure);
|
|
24
|
+
} catch {
|
|
25
|
+
}
|
|
26
|
+
throw authFailure;
|
|
27
|
+
};
|
|
28
|
+
const assertActive = () => {
|
|
29
|
+
if (disposed) {
|
|
30
|
+
throw failure(DISPOSED_CODE, "The integrated authentication client was disposed");
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const waitForNotification = (deadline) => {
|
|
34
|
+
assertActive();
|
|
35
|
+
const remaining = deadline - Date.now();
|
|
36
|
+
if (remaining <= 0) {
|
|
37
|
+
return Promise.reject(failure(TIMEOUT_CODE, "Better Auth session reconciliation timed out"));
|
|
38
|
+
}
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
let active = true;
|
|
41
|
+
const finish = (reason) => {
|
|
42
|
+
if (!active) return;
|
|
43
|
+
active = false;
|
|
44
|
+
clearTimeout(timer);
|
|
45
|
+
listeners.delete(wake);
|
|
46
|
+
if (reason) reject(reason);
|
|
47
|
+
else resolve();
|
|
48
|
+
};
|
|
49
|
+
const wake = () => finish();
|
|
50
|
+
const timer = setTimeout(
|
|
51
|
+
() => finish(failure(TIMEOUT_CODE, "Better Auth session reconciliation timed out")),
|
|
52
|
+
remaining
|
|
53
|
+
);
|
|
54
|
+
listeners.add(wake);
|
|
55
|
+
if (disposed) {
|
|
56
|
+
finish(failure(DISPOSED_CODE, "The integrated authentication client was disposed"));
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
const withinDeadline = async (operation, deadline) => {
|
|
61
|
+
const remaining = deadline - Date.now();
|
|
62
|
+
if (remaining <= 0) {
|
|
63
|
+
throw failure(TIMEOUT_CODE, "Better Auth session reconciliation timed out");
|
|
64
|
+
}
|
|
65
|
+
let timer;
|
|
66
|
+
try {
|
|
67
|
+
return await Promise.race([
|
|
68
|
+
operation,
|
|
69
|
+
new Promise((_resolve, reject) => {
|
|
70
|
+
timer = setTimeout(
|
|
71
|
+
() => reject(failure(TIMEOUT_CODE, "Better Auth session reconciliation timed out")),
|
|
72
|
+
remaining
|
|
73
|
+
);
|
|
74
|
+
})
|
|
75
|
+
]);
|
|
76
|
+
} finally {
|
|
77
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const waitForProvider = async (deadline) => {
|
|
81
|
+
for (; ; ) {
|
|
82
|
+
assertActive();
|
|
83
|
+
if (provider) return provider;
|
|
84
|
+
await waitForNotification(deadline);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const waitForAcceptanceOrChurn = async (expected, deadline) => {
|
|
88
|
+
for (; ; ) {
|
|
89
|
+
assertActive();
|
|
90
|
+
if (provider && !sameSession(provider, expected)) return "changed";
|
|
91
|
+
if (accepted && sameSession(accepted.session, expected)) {
|
|
92
|
+
if (accepted.failed) {
|
|
93
|
+
throw failure(RUNTIME_FAILED_CODE, "Convex rejected the refreshed Better Auth session");
|
|
94
|
+
}
|
|
95
|
+
return "accepted";
|
|
96
|
+
}
|
|
97
|
+
await waitForNotification(deadline);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
return {
|
|
101
|
+
observeProvider(session) {
|
|
102
|
+
if (disposed) return;
|
|
103
|
+
provider = session;
|
|
104
|
+
notify();
|
|
105
|
+
},
|
|
106
|
+
observeAccepted(session, runtimeFailed) {
|
|
107
|
+
if (disposed) return;
|
|
108
|
+
accepted = { session, failed: runtimeFailed };
|
|
109
|
+
notify();
|
|
110
|
+
},
|
|
111
|
+
checkpoint() {
|
|
112
|
+
assertActive();
|
|
113
|
+
return { revision: provider?.revision ?? -1 };
|
|
114
|
+
},
|
|
115
|
+
cancel(checkpoint) {
|
|
116
|
+
assertActive();
|
|
117
|
+
if (provider && provider.revision !== checkpoint.revision) {
|
|
118
|
+
failClosed(
|
|
119
|
+
failure(
|
|
120
|
+
SYNC_CHANGE_CODE,
|
|
121
|
+
"A synchronous Better Auth operation changed the provider session"
|
|
122
|
+
)
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
async reconcile(_checkpoint) {
|
|
127
|
+
assertActive();
|
|
128
|
+
const deadline = Date.now() + input.timeoutMs;
|
|
129
|
+
try {
|
|
130
|
+
for (; ; ) {
|
|
131
|
+
await withinDeadline(input.refetchCanonicalSession(), deadline);
|
|
132
|
+
const expected = await waitForProvider(deadline);
|
|
133
|
+
if (expected.failed) {
|
|
134
|
+
throw failure(REFRESH_FAILED_CODE, "The canonical Better Auth session refresh failed");
|
|
135
|
+
}
|
|
136
|
+
const outcome = await waitForAcceptanceOrChurn(expected, deadline);
|
|
137
|
+
if (outcome === "accepted") return;
|
|
138
|
+
}
|
|
139
|
+
} catch (error) {
|
|
140
|
+
if (error instanceof ConvexCallError) {
|
|
141
|
+
if (error.code === DISPOSED_CODE) throw error;
|
|
142
|
+
failClosed(error);
|
|
143
|
+
}
|
|
144
|
+
failClosed(failure(REFRESH_FAILED_CODE, "The canonical Better Auth session refresh failed"));
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
dispose() {
|
|
148
|
+
if (disposed) return;
|
|
149
|
+
disposed = true;
|
|
150
|
+
notify();
|
|
151
|
+
listeners.clear();
|
|
152
|
+
provider = void 0;
|
|
153
|
+
accepted = void 0;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { TOKEN_EXPIRY_SAFETY_BUFFER_MS } from '../utils/convex-shared.js';
|
|
2
|
+
import type { ConvexUser } from '../utils/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Better Auth Convex-plugin surface used to exchange the session for a JWT.
|
|
5
|
+
* `convex.token()` returns `{ data: { token } | null, error }` and, with
|
|
6
|
+
* `fetchOptions.throw = false`, resolves rather than throwing on HTTP failure.
|
|
7
|
+
*/
|
|
8
|
+
export interface ConvexTokenSource {
|
|
9
|
+
convex: {
|
|
10
|
+
token: (options?: unknown) => Promise<{
|
|
11
|
+
data?: {
|
|
12
|
+
token: string | null;
|
|
13
|
+
} | null;
|
|
14
|
+
error?: unknown;
|
|
15
|
+
}>;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** A confirmed candidate identity produced by a successful token exchange. */
|
|
19
|
+
export interface FetchedIdentity {
|
|
20
|
+
token: string;
|
|
21
|
+
user: ConvexUser;
|
|
22
|
+
}
|
|
23
|
+
export { TOKEN_EXPIRY_SAFETY_BUFFER_MS };
|
|
24
|
+
/** Immediate transient-retry attempts bounded by one fixed exchange deadline. */
|
|
25
|
+
export declare const MAX_FETCH_ATTEMPTS = 4;
|
|
26
|
+
/**
|
|
27
|
+
* A token is retainable only while it carries a valid required `exp` still in
|
|
28
|
+
* the future beyond the safety buffer. A token without a valid `exp`, or at/after
|
|
29
|
+
* expiry, is never retained (architecture invariant).
|
|
30
|
+
*/
|
|
31
|
+
export declare function isTokenUsable(token: string | null, nowMs?: number): token is string;
|
|
32
|
+
/**
|
|
33
|
+
* A settled token WITHOUT a non-empty Better Auth `user.id` is an authentication
|
|
34
|
+
* error : decode returns null and the token is discarded, never
|
|
35
|
+
* installed. Returns `null` for a token that decodes to no usable user.
|
|
36
|
+
*/
|
|
37
|
+
export declare function decodeFetchedIdentity(token: string): FetchedIdentity | null;
|
|
38
|
+
/**
|
|
39
|
+
* The outcome of one total token fetch. `identity: null` with `authError: null`
|
|
40
|
+
* is a clean anonymous result when the exchange succeeds with no token. A
|
|
41
|
+
* definitive 401/403 means presented credentials were rejected and is reported
|
|
42
|
+
* as an authentication error. `authError` is also set when a token decodes
|
|
43
|
+
* without a stable user id, or a transient transport failure exhausts the retry
|
|
44
|
+
* loop. `definitive`
|
|
45
|
+
* distinguishes such a transient (non-definitive) failure — over which a usable
|
|
46
|
+
* identity is retained — from the definitive verdicts above. Never rejects.
|
|
47
|
+
*/
|
|
48
|
+
export interface FetchOutcome {
|
|
49
|
+
identity: FetchedIdentity | null;
|
|
50
|
+
authError: string | null;
|
|
51
|
+
definitive: boolean;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Total Convex-token fetch; never throws.
|
|
55
|
+
*
|
|
56
|
+
* Runs a bounded transient-retry loop over the Better Auth exchange within one
|
|
57
|
+
* fixed browser deadline, validating each returned token's `exp`. Returns a
|
|
58
|
+
* decoded identity on success, a clean anonymous outcome when the exchange
|
|
59
|
+
* reports no session, or a definitive error outcome when every attempt fails. A
|
|
60
|
+
* rejecting or never-settling exchange is totalized for the Convex caller.
|
|
61
|
+
*/
|
|
62
|
+
export declare function fetchConvexToken(source: ConvexTokenSource, options?: {
|
|
63
|
+
maxAttempts?: number;
|
|
64
|
+
nowMs?: () => number;
|
|
65
|
+
signal?: AbortSignal;
|
|
66
|
+
}): Promise<FetchOutcome>;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decodeUserFromJwt,
|
|
3
|
+
isJwtUsable,
|
|
4
|
+
TOKEN_EXPIRY_SAFETY_BUFFER_MS
|
|
5
|
+
} from "../utils/convex-shared.js";
|
|
6
|
+
export { TOKEN_EXPIRY_SAFETY_BUFFER_MS };
|
|
7
|
+
export const MAX_FETCH_ATTEMPTS = 4;
|
|
8
|
+
const TOKEN_EXCHANGE_TIMEOUT_MS = 5e3;
|
|
9
|
+
const TOKEN_EXCHANGE_TIMED_OUT = Symbol("TOKEN_EXCHANGE_TIMED_OUT");
|
|
10
|
+
const TOKEN_EXCHANGE_CANCELLED = Symbol("TOKEN_EXCHANGE_CANCELLED");
|
|
11
|
+
const TOKEN_EXCHANGE_TIMEOUT_MESSAGE = "Convex authentication token exchange timed out";
|
|
12
|
+
const TOKEN_EXCHANGE_CANCELLED_MESSAGE = "Convex authentication token exchange was cancelled";
|
|
13
|
+
const TOKEN_EXCHANGE_FAILURE_MESSAGE = "Authentication is temporarily unavailable";
|
|
14
|
+
export function isTokenUsable(token, nowMs = Date.now()) {
|
|
15
|
+
return isJwtUsable(token, nowMs);
|
|
16
|
+
}
|
|
17
|
+
export function decodeFetchedIdentity(token) {
|
|
18
|
+
const user = decodeUserFromJwt(token);
|
|
19
|
+
if (!user || typeof user.id !== "string" || user.id.length === 0) return null;
|
|
20
|
+
return { token, user };
|
|
21
|
+
}
|
|
22
|
+
export async function fetchConvexToken(source, options = {}) {
|
|
23
|
+
if (options.signal?.aborted) {
|
|
24
|
+
return {
|
|
25
|
+
identity: null,
|
|
26
|
+
authError: TOKEN_EXCHANGE_CANCELLED_MESSAGE,
|
|
27
|
+
definitive: false
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const maxAttempts = options.maxAttempts ?? MAX_FETCH_ATTEMPTS;
|
|
31
|
+
const now = options.nowMs ?? Date.now;
|
|
32
|
+
let lastError = null;
|
|
33
|
+
const controller = new AbortController();
|
|
34
|
+
let timedOut = false;
|
|
35
|
+
let externallyCancelled = false;
|
|
36
|
+
let timeout = null;
|
|
37
|
+
const deadline = new Promise((resolve) => {
|
|
38
|
+
timeout = setTimeout(() => {
|
|
39
|
+
timedOut = true;
|
|
40
|
+
controller.abort();
|
|
41
|
+
resolve(TOKEN_EXCHANGE_TIMED_OUT);
|
|
42
|
+
}, TOKEN_EXCHANGE_TIMEOUT_MS);
|
|
43
|
+
});
|
|
44
|
+
let removeExternalAbort = () => {
|
|
45
|
+
};
|
|
46
|
+
const cancellation = new Promise((resolve) => {
|
|
47
|
+
const externalSignal = options.signal;
|
|
48
|
+
if (!externalSignal) return;
|
|
49
|
+
const cancel = () => {
|
|
50
|
+
externallyCancelled = true;
|
|
51
|
+
resolve(TOKEN_EXCHANGE_CANCELLED);
|
|
52
|
+
controller.abort();
|
|
53
|
+
};
|
|
54
|
+
externalSignal.addEventListener("abort", cancel, { once: true });
|
|
55
|
+
removeExternalAbort = () => externalSignal.removeEventListener("abort", cancel);
|
|
56
|
+
if (externalSignal.aborted) cancel();
|
|
57
|
+
});
|
|
58
|
+
try {
|
|
59
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
|
|
60
|
+
if (externallyCancelled) {
|
|
61
|
+
lastError = TOKEN_EXCHANGE_CANCELLED_MESSAGE;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const exchange = source.convex.token({
|
|
66
|
+
fetchOptions: { throw: false, signal: controller.signal }
|
|
67
|
+
});
|
|
68
|
+
const response = await Promise.race([exchange, deadline, cancellation]);
|
|
69
|
+
if (response === TOKEN_EXCHANGE_CANCELLED) {
|
|
70
|
+
lastError = TOKEN_EXCHANGE_CANCELLED_MESSAGE;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
if (response === TOKEN_EXCHANGE_TIMED_OUT) {
|
|
74
|
+
lastError = TOKEN_EXCHANGE_TIMEOUT_MESSAGE;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
if (response.error) {
|
|
78
|
+
if (isDefinitiveAuthStatus(response.error)) {
|
|
79
|
+
return {
|
|
80
|
+
identity: null,
|
|
81
|
+
authError: "Authentication credentials are invalid or expired",
|
|
82
|
+
definitive: true
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
lastError = TOKEN_EXCHANGE_FAILURE_MESSAGE;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const token = response.data?.token;
|
|
89
|
+
if (!token) {
|
|
90
|
+
return { identity: null, authError: null, definitive: true };
|
|
91
|
+
}
|
|
92
|
+
if (!isTokenUsable(token, now())) {
|
|
93
|
+
lastError = "Convex authentication token is expired or missing a valid expiry";
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const identity = decodeFetchedIdentity(token);
|
|
97
|
+
if (!identity) {
|
|
98
|
+
return {
|
|
99
|
+
identity: null,
|
|
100
|
+
authError: "Convex authentication token is missing a stable user id",
|
|
101
|
+
definitive: true
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return { identity, authError: null, definitive: false };
|
|
105
|
+
} catch {
|
|
106
|
+
if (externallyCancelled) {
|
|
107
|
+
lastError = TOKEN_EXCHANGE_CANCELLED_MESSAGE;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
if (timedOut) {
|
|
111
|
+
lastError = TOKEN_EXCHANGE_TIMEOUT_MESSAGE;
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
lastError = TOKEN_EXCHANGE_FAILURE_MESSAGE;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
} finally {
|
|
118
|
+
removeExternalAbort();
|
|
119
|
+
if (timeout !== null) clearTimeout(timeout);
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
identity: null,
|
|
123
|
+
authError: lastError ?? TOKEN_EXCHANGE_FAILURE_MESSAGE,
|
|
124
|
+
definitive: false
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function isDefinitiveAuthStatus(error) {
|
|
128
|
+
if (!error || typeof error !== "object") return false;
|
|
129
|
+
const status = error.status;
|
|
130
|
+
return status === 401 || status === 403;
|
|
131
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ConvexAuthClientDefinition } from '../auth-client/index.js';
|
|
2
|
+
import type { AuthClientPlugins, ConvexAuthClientDefinitionOptions } from '../auth-client/definition-types.js';
|
|
3
|
+
export declare class ConvexAuthClientDefinitionError extends TypeError {
|
|
4
|
+
constructor(message: string);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Validate a resolved definition object and return its `options`. Throws a
|
|
8
|
+
* `ConvexAuthClientDefinitionError` on any forbidden key, non-array/malformed
|
|
9
|
+
* `plugins`, or a consumer plugin whose stable `id` collides with the reserved
|
|
10
|
+
* Convex plugin id.
|
|
11
|
+
*/
|
|
12
|
+
export declare function validateConvexAuthClientDefinition<Plugins extends AuthClientPlugins>(definition: ConvexAuthClientDefinition<Plugins> | unknown): ConvexAuthClientDefinitionOptions<Plugins>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const FORBIDDEN_OWN_KEYS = ["baseURL", "basePath", "fetchOptions"];
|
|
2
|
+
const CONVEX_PLUGIN_ID = "convex";
|
|
3
|
+
export class ConvexAuthClientDefinitionError extends TypeError {
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(`[better-convex-nuxt] invalid auth-client definition: ${message}`);
|
|
6
|
+
this.name = "ConvexAuthClientDefinitionError";
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function isRecord(value) {
|
|
10
|
+
return typeof value === "object" && value !== null;
|
|
11
|
+
}
|
|
12
|
+
export function validateConvexAuthClientDefinition(definition) {
|
|
13
|
+
if (!isRecord(definition) || !isRecord(definition.options)) {
|
|
14
|
+
throw new ConvexAuthClientDefinitionError(
|
|
15
|
+
"expected a `defineConvexAuthClient({ ... })` result with an `options` object."
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
const options = definition.options;
|
|
19
|
+
for (const key of FORBIDDEN_OWN_KEYS) {
|
|
20
|
+
if (Object.prototype.hasOwnProperty.call(options, key)) {
|
|
21
|
+
throw new ConvexAuthClientDefinitionError(
|
|
22
|
+
`\`${key}\` is owned by the module and cannot be set on the definition.`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const { plugins } = options;
|
|
27
|
+
if (plugins !== void 0) {
|
|
28
|
+
if (!Array.isArray(plugins)) {
|
|
29
|
+
throw new ConvexAuthClientDefinitionError(
|
|
30
|
+
"`plugins` must be an array of Better Auth client plugins."
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
for (const [index, plugin] of plugins.entries()) {
|
|
34
|
+
if (!isRecord(plugin) || typeof plugin.id !== "string") {
|
|
35
|
+
throw new ConvexAuthClientDefinitionError(
|
|
36
|
+
`plugins[${index}] is not a valid Better Auth client plugin (missing string \`id\`).`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
if (plugin.id === CONVEX_PLUGIN_ID) {
|
|
40
|
+
throw new ConvexAuthClientDefinitionError(
|
|
41
|
+
`plugins[${index}] uses the reserved id \`${CONVEX_PLUGIN_ID}\`; the module prepends the Convex client plugin itself.`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return options;
|
|
47
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
interface ConvexTokenActionOptions {
|
|
2
|
+
fetchOptions?: Record<string, unknown>;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Internal Better Auth client action for the fixed Convex session-token route.
|
|
6
|
+
* Consumers cannot supply or replace this plugin.
|
|
7
|
+
*/
|
|
8
|
+
export declare function convexClientPlugin(): {
|
|
9
|
+
id: "convex";
|
|
10
|
+
pathMethods: {
|
|
11
|
+
'/convex/token': "GET";
|
|
12
|
+
};
|
|
13
|
+
getActions: ($fetch: import("better-auth/vue").BetterFetch) => {
|
|
14
|
+
convex: {
|
|
15
|
+
token: (options?: ConvexTokenActionOptions) => Promise<{
|
|
16
|
+
data: {
|
|
17
|
+
token: string | null;
|
|
18
|
+
};
|
|
19
|
+
error: null;
|
|
20
|
+
} | {
|
|
21
|
+
data: null;
|
|
22
|
+
error: {
|
|
23
|
+
message?: string | undefined;
|
|
24
|
+
status: number;
|
|
25
|
+
statusText: string;
|
|
26
|
+
};
|
|
27
|
+
}>;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function convexClientPlugin() {
|
|
2
|
+
return {
|
|
3
|
+
id: "convex",
|
|
4
|
+
pathMethods: { "/convex/token": "GET" },
|
|
5
|
+
getActions: ($fetch) => ({
|
|
6
|
+
convex: {
|
|
7
|
+
token: async (options) => await $fetch("/convex/token", {
|
|
8
|
+
...options?.fetchOptions ?? {},
|
|
9
|
+
method: "GET"
|
|
10
|
+
})
|
|
11
|
+
}
|
|
12
|
+
})
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BetterAuthClientOptions, BetterAuthClientPlugin } from 'better-auth/client';
|
|
2
|
+
/** Internal generic inputs shared by the public definition and its runtime validator. */
|
|
3
|
+
export type AuthClientPlugins = readonly BetterAuthClientPlugin[];
|
|
4
|
+
export type ConvexAuthClientDefinitionOptions<Plugins extends AuthClientPlugins> = Omit<BetterAuthClientOptions, 'baseURL' | 'basePath' | 'plugins' | 'fetchOptions'> & {
|
|
5
|
+
plugins?: Plugins;
|
|
6
|
+
};
|
|
File without changes
|