@robelest/convex-auth 0.0.4-preview.27 → 0.0.4-preview.28
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 +3 -5
- package/dist/bin.js +6488 -1571
- package/dist/browser/index.js +10 -7
- package/dist/browser/locks.js +3 -5
- package/dist/browser/navigation.js +7 -10
- package/dist/browser/runtime.js +35 -33
- package/dist/client/core/types.js +17 -0
- package/dist/client/factors/device.js +26 -19
- package/dist/client/index.js +151 -163
- package/dist/client/runtime/proxy.js +6 -6
- package/dist/client/services/adapters.js +3 -7
- package/dist/client/services/http.js +2 -5
- package/dist/client/services/resolve.js +5 -11
- package/dist/client/services/runtime.js +2 -5
- package/dist/component/_generated/component.d.ts +46 -0
- package/dist/component/index.d.ts +3 -3
- package/dist/component/model.d.ts +25 -25
- package/dist/component/public/identity/sessions.js +38 -1
- package/dist/component/public/identity/tokens.js +81 -3
- package/dist/component/public/identity/verifiers.js +9 -3
- package/dist/component/public.js +3 -3
- package/dist/component/schema.d.ts +320 -320
- package/dist/core/index.d.ts +380 -0
- package/dist/core/index.js +83 -0
- package/dist/otel.d.ts +13 -17
- package/dist/otel.js +39 -49
- package/dist/providers/email.d.ts +2 -2
- package/dist/providers/password.js +8 -16
- package/dist/providers/phone.js +2 -9
- package/dist/server/auth-context.d.ts +204 -0
- package/dist/server/auth-context.js +76 -0
- package/dist/server/auth.d.ts +25 -187
- package/dist/server/auth.js +5 -96
- package/dist/server/componentContext.d.ts +12 -0
- package/dist/server/componentContext.js +1 -0
- package/dist/server/config.js +1 -12
- package/dist/server/constants.js +6 -0
- package/dist/server/contract.d.ts +1 -1
- package/dist/server/core.js +5 -14
- package/dist/server/crypto.js +26 -18
- package/dist/server/db.js +6 -1
- package/dist/server/device.js +88 -78
- package/dist/server/http.d.ts +4 -3
- package/dist/server/http.js +74 -86
- package/dist/server/index.d.ts +2 -1
- package/dist/server/limits.js +22 -15
- package/dist/server/mounts.d.ts +103 -103
- package/dist/server/mutations/account.js +6 -4
- package/dist/server/mutations/invalidate.js +3 -6
- package/dist/server/mutations/oauth.js +86 -88
- package/dist/server/mutations/refresh.js +45 -87
- package/dist/server/mutations/register.js +19 -19
- package/dist/server/mutations/retrieve.js +17 -15
- package/dist/server/mutations/signature.js +9 -13
- package/dist/server/mutations/signin.js +7 -3
- package/dist/server/mutations/signout.js +10 -15
- package/dist/server/mutations/store.js +22 -12
- package/dist/server/mutations/verifier.js +11 -6
- package/dist/server/mutations/verify.js +55 -46
- package/dist/server/oauth/runtime.js +27 -25
- package/dist/server/passkey.js +299 -250
- package/dist/server/prefetch.js +283 -281
- package/dist/server/refresh.js +7 -60
- package/dist/server/runtime.d.ts +82 -206
- package/dist/server/runtime.js +63 -56
- package/dist/server/services/config.js +5 -3
- package/dist/server/services/logger.js +2 -4
- package/dist/server/services/providers.js +2 -4
- package/dist/server/services/refresh.js +2 -4
- package/dist/server/services/resolve.js +15 -14
- package/dist/server/services/signin.js +2 -4
- package/dist/server/sessions.js +32 -33
- package/dist/server/signin.js +177 -142
- package/dist/server/sso/domain.d.ts +20 -68
- package/dist/server/sso/domain.js +444 -413
- package/dist/server/sso/http.js +53 -59
- package/dist/server/sso/oidc.js +94 -80
- package/dist/server/tokens.js +13 -3
- package/dist/server/totp.js +153 -116
- package/dist/server/types.d.ts +2 -2
- package/dist/server/users.js +18 -23
- package/dist/server/utils/cache.js +51 -0
- package/dist/server/utils/dispatch.js +36 -0
- package/dist/server/utils/retry.js +24 -0
- package/dist/server/utils/span.js +32 -0
- package/dist/shared/errors.js +9 -3
- package/dist/shared/log.js +20 -22
- package/package.json +41 -33
package/dist/browser/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { ClientAdapterFactoriesLive, ClientAdaptersLive } from "../client/services/adapters.js";
|
|
2
2
|
import { ClientHttpLive } from "../client/services/http.js";
|
|
3
|
-
import { ClientRuntimeLive } from "../client/services/runtime.js";
|
|
4
3
|
import { resolveClientServices } from "../client/services/resolve.js";
|
|
4
|
+
import { ClientRuntimeLive } from "../client/services/runtime.js";
|
|
5
5
|
import { client as client$1 } from "../client/index.js";
|
|
6
6
|
import { createBrowserRuntime } from "./runtime.js";
|
|
7
7
|
import { createPasskeyClient } from "./passkey.js";
|
|
8
|
-
import { Layer } from "effect";
|
|
9
8
|
import { ConvexHttpClient } from "convex/browser";
|
|
10
9
|
|
|
11
10
|
//#region src/browser/index.ts
|
|
@@ -42,11 +41,15 @@ import { ConvexHttpClient } from "convex/browser";
|
|
|
42
41
|
*/
|
|
43
42
|
function client(options) {
|
|
44
43
|
const url = options.proxyPath === void 0 ? options.url ?? inferConvexUrl(options.convex) : void 0;
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
const services = resolveClientServices({
|
|
45
|
+
runtime: ClientRuntimeLive(mergeBrowserRuntime(options.runtime)),
|
|
46
|
+
adapters: ClientAdaptersLive(options.adapters ?? {}),
|
|
47
|
+
adapterFactories: ClientAdapterFactoriesLive({
|
|
48
|
+
...options.adapterFactories,
|
|
49
|
+
passkey: options.adapterFactories?.passkey ?? ((deps) => createPasskeyClient(deps))
|
|
50
|
+
}),
|
|
51
|
+
http: ClientHttpLive(options.proxyPath !== void 0 ? null : options.httpClient ?? (url ? new ConvexHttpClient(url) : null))
|
|
52
|
+
});
|
|
50
53
|
return client$1({
|
|
51
54
|
...options,
|
|
52
55
|
storage: options.storage === void 0 && options.proxyPath !== void 0 ? null : options.storage,
|
package/dist/browser/locks.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { localMutex } from "../client/runtime/mutex.js";
|
|
2
|
-
import { Effect, Layer, ServiceMap } from "effect";
|
|
3
2
|
|
|
4
3
|
//#region src/browser/locks.ts
|
|
5
|
-
|
|
6
|
-
const BrowserLocksLive = Layer.succeed(BrowserLocks)({ withKey: (key, callback) => Effect.promise(async () => {
|
|
4
|
+
const BrowserLocksLive = { withKey: async (key, callback) => {
|
|
7
5
|
const lockManager = typeof navigator === "undefined" ? void 0 : navigator.locks;
|
|
8
6
|
return lockManager !== void 0 ? await lockManager.request(key, callback) : await localMutex(key, callback);
|
|
9
|
-
}
|
|
7
|
+
} };
|
|
10
8
|
|
|
11
9
|
//#endregion
|
|
12
|
-
export {
|
|
10
|
+
export { BrowserLocksLive };
|
|
13
11
|
//# sourceMappingURL=locks.js.map
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import { Effect, Layer, ServiceMap } from "effect";
|
|
2
|
-
|
|
3
1
|
//#region src/browser/navigation.ts
|
|
4
|
-
|
|
5
|
-
const BrowserNavigationLive = Layer.succeed(BrowserNavigation)({
|
|
2
|
+
const BrowserNavigationLive = {
|
|
6
3
|
get: () => typeof window === "undefined" ? null : new URL(window.location.href),
|
|
7
|
-
replace: (url) =>
|
|
4
|
+
replace: (url) => {
|
|
8
5
|
if (typeof window !== "undefined") window.history.replaceState({}, "", url);
|
|
9
|
-
}
|
|
10
|
-
redirect: (url) =>
|
|
6
|
+
},
|
|
7
|
+
redirect: (url) => {
|
|
11
8
|
if (typeof window !== "undefined") window.location.href = url.toString();
|
|
12
|
-
}
|
|
13
|
-
}
|
|
9
|
+
}
|
|
10
|
+
};
|
|
14
11
|
|
|
15
12
|
//#endregion
|
|
16
|
-
export {
|
|
13
|
+
export { BrowserNavigationLive };
|
|
17
14
|
//# sourceMappingURL=navigation.js.map
|
package/dist/browser/runtime.js
CHANGED
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Effect, Fiber, Stream } from "effect";
|
|
4
|
-
import * as BrowserHttpClient from "@effect/platform-browser/BrowserHttpClient";
|
|
5
|
-
import * as BrowserKeyValueStore from "@effect/platform-browser/BrowserKeyValueStore";
|
|
6
|
-
import * as BrowserStream from "@effect/platform-browser/BrowserStream";
|
|
7
|
-
import * as KeyValueStore from "effect/unstable/persistence/KeyValueStore";
|
|
1
|
+
import { BrowserLocksLive } from "./locks.js";
|
|
2
|
+
import { BrowserNavigationLive } from "./navigation.js";
|
|
8
3
|
|
|
9
4
|
//#region src/browser/runtime.ts
|
|
10
5
|
const browserStorage = {
|
|
11
6
|
async getItem(key) {
|
|
12
|
-
|
|
13
|
-
return
|
|
14
|
-
}
|
|
7
|
+
try {
|
|
8
|
+
return localStorage.getItem(key);
|
|
9
|
+
} catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
15
12
|
},
|
|
16
13
|
async setItem(key, value) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
14
|
+
try {
|
|
15
|
+
localStorage.setItem(key, value);
|
|
16
|
+
} catch {}
|
|
20
17
|
},
|
|
21
18
|
async removeItem(key) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
19
|
+
try {
|
|
20
|
+
localStorage.removeItem(key);
|
|
21
|
+
} catch {}
|
|
25
22
|
}
|
|
26
23
|
};
|
|
27
24
|
/** @internal */
|
|
@@ -51,33 +48,38 @@ function createBrowserRuntime() {
|
|
|
51
48
|
environment: typeof window === "undefined" ? "server" : "client",
|
|
52
49
|
storage: typeof window === "undefined" ? null : browserStorage,
|
|
53
50
|
location: {
|
|
54
|
-
get: () =>
|
|
55
|
-
replace: (url) =>
|
|
56
|
-
|
|
51
|
+
get: () => BrowserNavigationLive.get(),
|
|
52
|
+
replace: (url) => {
|
|
53
|
+
BrowserNavigationLive.replace(url);
|
|
54
|
+
return Promise.resolve();
|
|
55
|
+
},
|
|
56
|
+
redirect: (url) => {
|
|
57
|
+
BrowserNavigationLive.redirect(url);
|
|
58
|
+
return Promise.resolve();
|
|
59
|
+
}
|
|
57
60
|
},
|
|
58
|
-
mutex: { withKey: (key, callback) =>
|
|
61
|
+
mutex: { withKey: (key, callback) => BrowserLocksLive.withKey(key, callback) },
|
|
59
62
|
proxy: { fetch: async (body, proxyPath) => {
|
|
60
|
-
return
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
body: JSON.stringify(body)
|
|
67
|
-
}));
|
|
68
|
-
}).pipe(Effect.provide(BrowserHttpClient.layerFetch)));
|
|
63
|
+
return fetch(new URL(proxyPath, window.location.origin), {
|
|
64
|
+
method: "POST",
|
|
65
|
+
headers: { "Content-Type": "application/json" },
|
|
66
|
+
credentials: "include",
|
|
67
|
+
body: JSON.stringify(body)
|
|
68
|
+
});
|
|
69
69
|
} },
|
|
70
70
|
sync: { subscribe: (key, callback) => {
|
|
71
71
|
if (typeof window === "undefined") return null;
|
|
72
72
|
const registry = getStorageListenerRegistry();
|
|
73
73
|
const existingSubscription = registry[key];
|
|
74
74
|
if (existingSubscription !== void 0) existingSubscription();
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
const controller = new AbortController();
|
|
76
|
+
window.addEventListener("storage", (event) => {
|
|
77
|
+
if (event.key !== key) return;
|
|
78
|
+
callback(event.newValue ?? null);
|
|
79
|
+
}, { signal: controller.signal });
|
|
78
80
|
const unsubscribe = () => {
|
|
79
81
|
if (registry[key] === unsubscribe) delete registry[key];
|
|
80
|
-
|
|
82
|
+
controller.abort();
|
|
81
83
|
};
|
|
82
84
|
registry[key] = unsubscribe;
|
|
83
85
|
return unsubscribe;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/client/core/types.ts
|
|
2
|
+
function createDeferred() {
|
|
3
|
+
let resolve;
|
|
4
|
+
let reject;
|
|
5
|
+
return {
|
|
6
|
+
promise: new Promise((res, rej) => {
|
|
7
|
+
resolve = res;
|
|
8
|
+
reject = rej;
|
|
9
|
+
}),
|
|
10
|
+
resolve,
|
|
11
|
+
reject
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { createDeferred };
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ConvexError } from "convex/values";
|
|
2
|
-
import { Effect } from "effect";
|
|
3
2
|
|
|
4
3
|
//#region src/client/factors/device.ts
|
|
5
4
|
function isSignedInResult(result) {
|
|
@@ -8,8 +7,8 @@ function isSignedInResult(result) {
|
|
|
8
7
|
/** @internal */
|
|
9
8
|
function createDeviceClient(deps) {
|
|
10
9
|
const { proxy, convex, requireApiRefs, proxyFetch, setTokenAndMaybeWait } = deps;
|
|
11
|
-
const requestDeviceSignIn = (params) =>
|
|
12
|
-
|
|
10
|
+
const requestDeviceSignIn = async (params) => {
|
|
11
|
+
return proxy ? await proxyFetch({
|
|
13
12
|
action: "auth:signIn",
|
|
14
13
|
args: {
|
|
15
14
|
provider: "device",
|
|
@@ -18,9 +17,8 @@ function createDeviceClient(deps) {
|
|
|
18
17
|
}) : await convex.action(requireApiRefs().signIn, {
|
|
19
18
|
provider: "device",
|
|
20
19
|
params
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
});
|
|
20
|
+
});
|
|
21
|
+
};
|
|
24
22
|
return {
|
|
25
23
|
poll: async (opts) => {
|
|
26
24
|
const { code } = opts;
|
|
@@ -32,15 +30,20 @@ function createDeviceClient(deps) {
|
|
|
32
30
|
flow: "poll",
|
|
33
31
|
deviceCode: code.deviceCode
|
|
34
32
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
33
|
+
let pollResult;
|
|
34
|
+
try {
|
|
35
|
+
pollResult = await requestDeviceSignIn(params);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
if (error instanceof ConvexError) {
|
|
38
|
+
const errorCode = error.data?.code;
|
|
39
|
+
if (errorCode === "DEVICE_AUTHORIZATION_PENDING") continue;
|
|
40
|
+
if (errorCode === "DEVICE_SLOW_DOWN") {
|
|
41
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
44
47
|
if (pollResult === null) continue;
|
|
45
48
|
if (isSignedInResult(pollResult) && pollResult.tokens) {
|
|
46
49
|
if (proxy) await setTokenAndMaybeWait({
|
|
@@ -74,10 +77,14 @@ function createDeviceClient(deps) {
|
|
|
74
77
|
flow: "verify",
|
|
75
78
|
userCode: opts.code
|
|
76
79
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
try {
|
|
81
|
+
await requestDeviceSignIn(params);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
throw new ConvexError({
|
|
84
|
+
code: "DEVICE_AUTHORIZATION_FAILED",
|
|
85
|
+
message: error instanceof Error ? error.message : "Invalid or expired code."
|
|
86
|
+
});
|
|
87
|
+
}
|
|
81
88
|
}
|
|
82
89
|
};
|
|
83
90
|
}
|