faire-auth 1.0.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/LICENSE +661 -0
- package/README.md +34 -0
- package/dist/access-B5bBI4uT.mjs +39 -0
- package/dist/access-Crt-IJ2P.cjs +51 -0
- package/dist/adapter-factory-BXei1QRX.mjs +881 -0
- package/dist/adapter-factory-DT-_2aHJ.cjs +893 -0
- package/dist/adapters/drizzle-adapter/index.cjs +208 -0
- package/dist/adapters/drizzle-adapter/index.d.cts +48 -0
- package/dist/adapters/drizzle-adapter/index.d.mts +48 -0
- package/dist/adapters/drizzle-adapter/index.mjs +207 -0
- package/dist/adapters/index.cjs +23 -0
- package/dist/adapters/index.d.cts +157 -0
- package/dist/adapters/index.d.mts +157 -0
- package/dist/adapters/index.mjs +17 -0
- package/dist/adapters/kysely-adapter/index.cjs +11 -0
- package/dist/adapters/kysely-adapter/index.d.cts +52 -0
- package/dist/adapters/kysely-adapter/index.d.mts +52 -0
- package/dist/adapters/kysely-adapter/index.mjs +9 -0
- package/dist/adapters/memory-adapter/index.cjs +9 -0
- package/dist/adapters/memory-adapter/index.d.cts +15 -0
- package/dist/adapters/memory-adapter/index.d.mts +15 -0
- package/dist/adapters/memory-adapter/index.mjs +9 -0
- package/dist/adapters/mongodb-adapter/index.cjs +9 -0
- package/dist/adapters/mongodb-adapter/index.d.cts +4 -0
- package/dist/adapters/mongodb-adapter/index.d.mts +4 -0
- package/dist/adapters/mongodb-adapter/index.mjs +9 -0
- package/dist/adapters/prisma-adapter/index.cjs +156 -0
- package/dist/adapters/prisma-adapter/index.d.cts +35 -0
- package/dist/adapters/prisma-adapter/index.d.mts +35 -0
- package/dist/adapters/prisma-adapter/index.mjs +155 -0
- package/dist/adapters/test.cjs +797 -0
- package/dist/adapters/test.d.cts +82 -0
- package/dist/adapters/test.d.mts +82 -0
- package/dist/adapters/test.mjs +793 -0
- package/dist/api/index.cjs +20 -0
- package/dist/api/index.d.cts +3 -0
- package/dist/api/index.d.mts +3 -0
- package/dist/api/index.mjs +20 -0
- package/dist/api/middleware/index.cjs +16 -0
- package/dist/api/middleware/index.d.cts +16 -0
- package/dist/api/middleware/index.d.mts +16 -0
- package/dist/api/middleware/index.mjs +11 -0
- package/dist/api-Bm89BLgN.cjs +1899 -0
- package/dist/api-_B7qO28y.mjs +1892 -0
- package/dist/auth-Bo9PDt5j.cjs +739 -0
- package/dist/auth-Ds4AG4h4.mjs +709 -0
- package/dist/bearer-0SeEmaS4.mjs +54 -0
- package/dist/bearer-CHeREcGT.cjs +60 -0
- package/dist/bun-sqlite-dialect-CfkBo2v5.mjs +155 -0
- package/dist/bun-sqlite-dialect-wuaC2-gh.cjs +156 -0
- package/dist/chunk-Ceigfy4P.mjs +39 -0
- package/dist/chunk-oakRccI5.cjs +60 -0
- package/dist/client/index.cjs +22 -0
- package/dist/client/index.d.cts +8 -0
- package/dist/client/index.d.mts +8 -0
- package/dist/client/index.mjs +19 -0
- package/dist/client/lynx/index.cjs +79 -0
- package/dist/client/lynx/index.d.cts +156 -0
- package/dist/client/lynx/index.d.mts +156 -0
- package/dist/client/lynx/index.mjs +76 -0
- package/dist/client/plugins/index.cjs +11 -0
- package/dist/client/plugins/index.d.cts +17 -0
- package/dist/client/plugins/index.d.mts +17 -0
- package/dist/client/plugins/index.mjs +10 -0
- package/dist/client/react/index.cjs +79 -0
- package/dist/client/react/index.d.cts +156 -0
- package/dist/client/react/index.d.mts +156 -0
- package/dist/client/react/index.mjs +76 -0
- package/dist/client/solid/index.cjs +51 -0
- package/dist/client/solid/index.d.cts +90 -0
- package/dist/client/solid/index.d.mts +90 -0
- package/dist/client/solid/index.mjs +50 -0
- package/dist/client/svelte/index.cjs +28 -0
- package/dist/client/svelte/index.d.cts +110 -0
- package/dist/client/svelte/index.d.mts +110 -0
- package/dist/client/svelte/index.mjs +28 -0
- package/dist/client/vue/index.cjs +68 -0
- package/dist/client/vue/index.d.cts +123 -0
- package/dist/client/vue/index.d.mts +123 -0
- package/dist/client/vue/index.mjs +67 -0
- package/dist/cookies-B5xeA6i8.cjs +456 -0
- package/dist/cookies-Ch1JfQIz.mjs +367 -0
- package/dist/crypto/index.cjs +11 -0
- package/dist/crypto/index.d.cts +22 -0
- package/dist/crypto/index.d.mts +22 -0
- package/dist/crypto/index.mjs +5 -0
- package/dist/crypto-CcTxYH82.cjs +57 -0
- package/dist/crypto-CyQRFtkq.mjs +41 -0
- package/dist/db/index.cjs +40 -0
- package/dist/db/index.d.cts +4 -0
- package/dist/db/index.d.mts +4 -0
- package/dist/db/index.mjs +16 -0
- package/dist/db-BTKyYu-_.cjs +1180 -0
- package/dist/db-xiJtoDgz.mjs +1119 -0
- package/dist/defu-B0Svx_x4.cjs +34 -0
- package/dist/defu-SZkpHhbR.mjs +28 -0
- package/dist/email-verification-C-AsfJsb.cjs +247 -0
- package/dist/email-verification-CWhj2qfb.mjs +228 -0
- package/dist/hono-BEq1NYVX.cjs +526 -0
- package/dist/hono-Cdukwu5K.cjs +13 -0
- package/dist/hono-CoKYWnXA.mjs +7 -0
- package/dist/hono-Covz10jU.mjs +508 -0
- package/dist/hono-DOM31WQz.d.cts +18 -0
- package/dist/hono-DuE14mmj.d.mts +18 -0
- package/dist/index-B-WeOMzg.d.cts +13350 -0
- package/dist/index-B09P9p5_.d.cts +33 -0
- package/dist/index-B5_0QTLg.d.mts +3 -0
- package/dist/index-B7SKyR_a.d.cts +3 -0
- package/dist/index-BVHscLQl.d.cts +992 -0
- package/dist/index-C2-2QDyS.d.cts +35 -0
- package/dist/index-CTwrVluH.d.mts +41 -0
- package/dist/index-CWAqWfoZ.d.cts +27 -0
- package/dist/index-CYSShrFx.d.mts +27 -0
- package/dist/index-Qu-iJGNr.d.mts +992 -0
- package/dist/index-cs4Sh0En.d.cts +41 -0
- package/dist/index-jlessPI0.d.mts +13350 -0
- package/dist/index-ppgcFe12.d.mts +33 -0
- package/dist/index-to0RO38U.d.mts +35 -0
- package/dist/index.cjs +85 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +27 -0
- package/dist/integrations/next-js.cjs +50 -0
- package/dist/integrations/next-js.d.cts +23 -0
- package/dist/integrations/next-js.d.mts +23 -0
- package/dist/integrations/next-js.mjs +49 -0
- package/dist/integrations/node.cjs +139 -0
- package/dist/integrations/node.d.cts +22 -0
- package/dist/integrations/node.d.mts +22 -0
- package/dist/integrations/node.mjs +134 -0
- package/dist/integrations/react-start.cjs +37 -0
- package/dist/integrations/react-start.d.cts +17 -0
- package/dist/integrations/react-start.d.mts +17 -0
- package/dist/integrations/react-start.mjs +37 -0
- package/dist/integrations/solid-start.cjs +14 -0
- package/dist/integrations/solid-start.d.cts +13 -0
- package/dist/integrations/solid-start.d.mts +13 -0
- package/dist/integrations/solid-start.mjs +13 -0
- package/dist/integrations/svelte-kit.cjs +52 -0
- package/dist/integrations/svelte-kit.d.cts +42 -0
- package/dist/integrations/svelte-kit.d.mts +42 -0
- package/dist/integrations/svelte-kit.mjs +49 -0
- package/dist/ip-B5SwXaMB.cjs +54 -0
- package/dist/ip-BjNYspCH.mjs +36 -0
- package/dist/json-B1v2qRTQ.mjs +24 -0
- package/dist/json-CcJ2HjGo.cjs +30 -0
- package/dist/kysely-adapter-Bxi7sPdG.cjs +288 -0
- package/dist/kysely-adapter-DRuoT_X8.mjs +270 -0
- package/dist/logged-CyGfp8_H.mjs +187 -0
- package/dist/logged-DQK3C64b.cjs +193 -0
- package/dist/memory-adapter-BlnDIAAX.cjs +154 -0
- package/dist/memory-adapter-Db3tsJTn.mjs +148 -0
- package/dist/middleware-CE6OhDkq.mjs +29 -0
- package/dist/middleware-CWvRH4EW.cjs +47 -0
- package/dist/mongodb-adapter-C_qGQED5.mjs +291 -0
- package/dist/mongodb-adapter-C_qfK87x.cjs +297 -0
- package/dist/node-sqlite-dialect-BfBzyOAg.mjs +155 -0
- package/dist/node-sqlite-dialect-mJWC8LWQ.cjs +156 -0
- package/dist/oauth2/index.cjs +25 -0
- package/dist/oauth2/index.d.cts +42 -0
- package/dist/oauth2/index.d.mts +42 -0
- package/dist/oauth2/index.mjs +16 -0
- package/dist/oauth2-B8M0lW9l.mjs +159 -0
- package/dist/oauth2-BLeOEi7Y.cjs +177 -0
- package/dist/origin-check-8Gajklvh.mjs +228 -0
- package/dist/origin-check-id9lTnqZ.cjs +246 -0
- package/dist/parser-CdncAl9i.cjs +83 -0
- package/dist/parser-CeAer-RM.mjs +71 -0
- package/dist/passkey-B6N20LSS.cjs +512 -0
- package/dist/passkey-DJsR_GX3.mjs +505 -0
- package/dist/plugins/access/index.cjs +4 -0
- package/dist/plugins/access/index.d.cts +2 -0
- package/dist/plugins/access/index.d.mts +2 -0
- package/dist/plugins/access/index.mjs +3 -0
- package/dist/plugins/bearer/index.cjs +7 -0
- package/dist/plugins/bearer/index.d.cts +4 -0
- package/dist/plugins/bearer/index.d.mts +4 -0
- package/dist/plugins/bearer/index.mjs +7 -0
- package/dist/plugins/index.cjs +49 -0
- package/dist/plugins/index.d.cts +9326 -0
- package/dist/plugins/index.d.mts +9326 -0
- package/dist/plugins/index.mjs +26 -0
- package/dist/plugins/passkey/index.cjs +15 -0
- package/dist/plugins/passkey/index.d.cts +4 -0
- package/dist/plugins/passkey/index.d.mts +4 -0
- package/dist/plugins/passkey/index.mjs +15 -0
- package/dist/plugins-C1lm2Wj3.cjs +5254 -0
- package/dist/plugins-Dai1QkRU.mjs +5199 -0
- package/dist/request-1NL_1lyJ.mjs +58 -0
- package/dist/request-CPNlp-DK.cjs +100 -0
- package/dist/schema-D-qjygfE.cjs +179 -0
- package/dist/schema-DTIwLLmf.mjs +125 -0
- package/dist/session-De9POJTW.cjs +641 -0
- package/dist/session-rH8ougDl.mjs +538 -0
- package/dist/social-providers/index.cjs +10 -0
- package/dist/social-providers/index.d.cts +2 -0
- package/dist/social-providers/index.d.mts +2 -0
- package/dist/social-providers/index.mjs +5 -0
- package/dist/social-providers-DcFNUT0S.cjs +13 -0
- package/dist/social-providers-DoYJhBe3.mjs +9 -0
- package/dist/state--f7fwIGh.cjs +99 -0
- package/dist/state-CqJfCIl9.mjs +86 -0
- package/dist/test-utils/index.cjs +27492 -0
- package/dist/test-utils/index.d.cts +4584 -0
- package/dist/test-utils/index.d.mts +4584 -0
- package/dist/test-utils/index.mjs +27490 -0
- package/dist/types/index.cjs +0 -0
- package/dist/types/index.d.cts +3 -0
- package/dist/types/index.d.mts +3 -0
- package/dist/types/index.mjs +1 -0
- package/dist/url-BoUuoIwZ.mjs +88 -0
- package/dist/url-D2yvKaM7.cjs +118 -0
- package/dist/utils/cookies.cjs +51 -0
- package/dist/utils/cookies.d.cts +179 -0
- package/dist/utils/cookies.d.mts +179 -0
- package/dist/utils/cookies.mjs +7 -0
- package/dist/utils-44aDDP8f.cjs +2 -0
- package/dist/utils-D4vZd1-9.mjs +4 -0
- package/dist/vanilla-Bu2PmFzE.cjs +30 -0
- package/dist/vanilla-TfHqeiC7.mjs +25 -0
- package/package.json +470 -0
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-oakRccI5.cjs');
|
|
2
|
+
const require_url = require('./url-D2yvKaM7.cjs');
|
|
3
|
+
const require_request = require('./request-CPNlp-DK.cjs');
|
|
4
|
+
const require_defu = require('./defu-B0Svx_x4.cjs');
|
|
5
|
+
const require_parser = require('./parser-CdncAl9i.cjs');
|
|
6
|
+
let hono_utils_cookie = require("hono/utils/cookie");
|
|
7
|
+
let __better_fetch_fetch = require("@better-fetch/fetch");
|
|
8
|
+
let nanostores = require("nanostores");
|
|
9
|
+
|
|
10
|
+
//#region src/client/fetch-plugins.ts
|
|
11
|
+
const redirectPlugin = {
|
|
12
|
+
id: "redirect",
|
|
13
|
+
name: "Redirect",
|
|
14
|
+
hooks: { onSuccess(context) {
|
|
15
|
+
if (context.data?.url && context.data?.redirect) {
|
|
16
|
+
if (typeof window !== "undefined" && window.location) {
|
|
17
|
+
if (window.location) try {
|
|
18
|
+
window.location.href = context.data.url;
|
|
19
|
+
} catch {}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
} }
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/client/plugins/lifecycle.ts
|
|
27
|
+
const lifecycle = (options) => ({
|
|
28
|
+
id: "lifecycle-hooks",
|
|
29
|
+
name: "lifecycle-hooks",
|
|
30
|
+
hooks: {
|
|
31
|
+
...options?.fetchOptions?.onSuccess && { onSuccess: options?.fetchOptions?.onSuccess },
|
|
32
|
+
...options?.fetchOptions?.onError && { onError: options.fetchOptions.onError },
|
|
33
|
+
...options?.fetchOptions?.onRequest && { onRequest: options.fetchOptions.onRequest },
|
|
34
|
+
...options?.fetchOptions?.onResponse && { onResponse: options.fetchOptions.onResponse }
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/client/query.ts
|
|
40
|
+
const isServer = typeof window === "undefined";
|
|
41
|
+
const useAuthQuery = (initializedAtom, path, $fetch, options) => {
|
|
42
|
+
const value = (0, nanostores.atom)({
|
|
43
|
+
data: null,
|
|
44
|
+
error: null,
|
|
45
|
+
isPending: true,
|
|
46
|
+
isRefetching: false,
|
|
47
|
+
refetch: async () => fn()
|
|
48
|
+
});
|
|
49
|
+
const fn = async () => {
|
|
50
|
+
const opts = typeof options === "function" ? options({
|
|
51
|
+
data: value.get().data,
|
|
52
|
+
error: value.get().error,
|
|
53
|
+
isPending: value.get().isPending
|
|
54
|
+
}) : options;
|
|
55
|
+
return $fetch(path, {
|
|
56
|
+
...opts,
|
|
57
|
+
onSuccess: async (context) => {
|
|
58
|
+
value.set({
|
|
59
|
+
data: context.data,
|
|
60
|
+
error: null,
|
|
61
|
+
isPending: false,
|
|
62
|
+
isRefetching: false,
|
|
63
|
+
refetch: value.value.refetch
|
|
64
|
+
});
|
|
65
|
+
await opts?.onSuccess?.(context);
|
|
66
|
+
},
|
|
67
|
+
onError: async (context) => {
|
|
68
|
+
const { request } = context;
|
|
69
|
+
const retryAttempts = typeof request.retry === "number" ? request.retry : request.retry?.attempts;
|
|
70
|
+
const retryAttempt = request.retryAttempt ?? 0;
|
|
71
|
+
if (retryAttempts != null && retryAttempt < retryAttempts) return;
|
|
72
|
+
value.set({
|
|
73
|
+
error: context.error,
|
|
74
|
+
data: null,
|
|
75
|
+
isPending: false,
|
|
76
|
+
isRefetching: false,
|
|
77
|
+
refetch: value.value.refetch
|
|
78
|
+
});
|
|
79
|
+
await opts?.onError?.(context);
|
|
80
|
+
},
|
|
81
|
+
onRequest: async (context) => {
|
|
82
|
+
const currentValue = value.get();
|
|
83
|
+
value.set({
|
|
84
|
+
isPending: currentValue.data === null,
|
|
85
|
+
data: currentValue.data,
|
|
86
|
+
error: null,
|
|
87
|
+
isRefetching: true,
|
|
88
|
+
refetch: value.value.refetch
|
|
89
|
+
});
|
|
90
|
+
await opts?.onRequest?.(context);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
initializedAtom = Array.isArray(initializedAtom) ? initializedAtom : [initializedAtom];
|
|
95
|
+
let isMounted = false;
|
|
96
|
+
for (const initAtom of initializedAtom) initAtom.subscribe(() => {
|
|
97
|
+
if (isServer) return;
|
|
98
|
+
if (isMounted) fn();
|
|
99
|
+
else (0, nanostores.onMount)(value, () => {
|
|
100
|
+
setTimeout(() => {
|
|
101
|
+
fn();
|
|
102
|
+
}, 0);
|
|
103
|
+
isMounted = true;
|
|
104
|
+
return () => {
|
|
105
|
+
value.off();
|
|
106
|
+
initAtom.off();
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
return value;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/client/broadcast-channel.ts
|
|
115
|
+
const now$1 = () => Math.floor(Date.now() / 1e3);
|
|
116
|
+
function createBroadcastChannel(name = "faire-auth.message") {
|
|
117
|
+
return {
|
|
118
|
+
receive(onReceive) {
|
|
119
|
+
const handler = (event) => {
|
|
120
|
+
if (event.key !== name) return;
|
|
121
|
+
const message = JSON.parse(event.newValue ?? "{}");
|
|
122
|
+
if (message?.event !== "session" || !message?.data) return;
|
|
123
|
+
onReceive(message);
|
|
124
|
+
};
|
|
125
|
+
window.addEventListener("storage", handler);
|
|
126
|
+
return () => window.removeEventListener("storage", handler);
|
|
127
|
+
},
|
|
128
|
+
post(message) {
|
|
129
|
+
if (typeof window === "undefined") return;
|
|
130
|
+
try {
|
|
131
|
+
localStorage.setItem(name, JSON.stringify({
|
|
132
|
+
...message,
|
|
133
|
+
timestamp: now$1()
|
|
134
|
+
}));
|
|
135
|
+
} catch {}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/client/session-refresh.ts
|
|
142
|
+
const now = () => Math.floor(Date.now() / 1e3);
|
|
143
|
+
function createSessionRefreshManager(opts) {
|
|
144
|
+
const { sessionAtom, sessionSignal, options = {} } = opts;
|
|
145
|
+
const { refetchInterval = 0, refetchOnWindowFocus = true, refetchWhenOffline = false } = options?.sessionOptions || {};
|
|
146
|
+
const state = {
|
|
147
|
+
lastSync: 0,
|
|
148
|
+
cachedSession: void 0
|
|
149
|
+
};
|
|
150
|
+
let isOnline = typeof navigator !== "undefined" ? navigator.onLine : true;
|
|
151
|
+
const broadcast = createBroadcastChannel();
|
|
152
|
+
const shouldRefetch = () => {
|
|
153
|
+
if (typeof window === "undefined") return false;
|
|
154
|
+
return refetchWhenOffline || isOnline;
|
|
155
|
+
};
|
|
156
|
+
const triggerRefetch = (event) => {
|
|
157
|
+
if (!shouldRefetch()) return;
|
|
158
|
+
if (event?.event === "storage") {
|
|
159
|
+
state.lastSync = now();
|
|
160
|
+
sessionSignal.set(!sessionSignal.get());
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const currentSession = sessionAtom.get();
|
|
164
|
+
if (currentSession?.data === null || currentSession?.data === void 0 || event?.event === "poll" || event?.event === "visibilitychange") {
|
|
165
|
+
state.lastSync = now();
|
|
166
|
+
sessionSignal.set(!sessionSignal.get());
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
const broadcastSessionUpdate = (trigger) => {
|
|
170
|
+
broadcast.post({
|
|
171
|
+
event: "session",
|
|
172
|
+
data: { trigger },
|
|
173
|
+
clientId: Math.random().toString(36).substring(7)
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
const setupPolling = () => {
|
|
177
|
+
if (refetchInterval && refetchInterval > 0) state.pollInterval = setInterval(() => {
|
|
178
|
+
if (sessionAtom.get()?.data) triggerRefetch({ event: "poll" });
|
|
179
|
+
}, refetchInterval * 1e3);
|
|
180
|
+
};
|
|
181
|
+
const setupBroadcast = () => {
|
|
182
|
+
state.unsubscribeBroadcast = broadcast.receive(() => {
|
|
183
|
+
triggerRefetch({ event: "storage" });
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
const setupVisibilityChange = () => {
|
|
187
|
+
if (!refetchOnWindowFocus) return;
|
|
188
|
+
if (typeof document === "undefined") return;
|
|
189
|
+
const visibilityHandler = () => {
|
|
190
|
+
if (document.visibilityState === "visible") triggerRefetch({ event: "visibilitychange" });
|
|
191
|
+
};
|
|
192
|
+
document.addEventListener("visibilitychange", visibilityHandler, false);
|
|
193
|
+
state.unsubscribeVisibility = () => {
|
|
194
|
+
document.removeEventListener("visibilitychange", visibilityHandler, false);
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
const setupOnlineDetection = () => {
|
|
198
|
+
if (typeof window === "undefined") return;
|
|
199
|
+
const setOnline = () => {
|
|
200
|
+
isOnline = true;
|
|
201
|
+
triggerRefetch({ event: "visibilitychange" });
|
|
202
|
+
};
|
|
203
|
+
const setOffline = () => {
|
|
204
|
+
isOnline = false;
|
|
205
|
+
};
|
|
206
|
+
window.addEventListener("online", setOnline);
|
|
207
|
+
window.addEventListener("offline", setOffline);
|
|
208
|
+
state.unsubscribeOnline = () => window.removeEventListener("online", setOnline);
|
|
209
|
+
state.unsubscribeOffline = () => window.removeEventListener("offline", setOffline);
|
|
210
|
+
};
|
|
211
|
+
const init = () => {
|
|
212
|
+
if (typeof window === "undefined") return;
|
|
213
|
+
setupPolling();
|
|
214
|
+
setupBroadcast();
|
|
215
|
+
setupVisibilityChange();
|
|
216
|
+
setupOnlineDetection();
|
|
217
|
+
};
|
|
218
|
+
const cleanup = () => {
|
|
219
|
+
if (state.pollInterval) {
|
|
220
|
+
clearInterval(state.pollInterval);
|
|
221
|
+
state.pollInterval = void 0;
|
|
222
|
+
}
|
|
223
|
+
if (state.unsubscribeBroadcast) {
|
|
224
|
+
state.unsubscribeBroadcast();
|
|
225
|
+
state.unsubscribeBroadcast = void 0;
|
|
226
|
+
}
|
|
227
|
+
if (state.unsubscribeVisibility) {
|
|
228
|
+
state.unsubscribeVisibility();
|
|
229
|
+
state.unsubscribeVisibility = void 0;
|
|
230
|
+
}
|
|
231
|
+
if (state.unsubscribeOnline) {
|
|
232
|
+
state.unsubscribeOnline();
|
|
233
|
+
state.unsubscribeOnline = void 0;
|
|
234
|
+
}
|
|
235
|
+
if (state.unsubscribeOffline) {
|
|
236
|
+
state.unsubscribeOffline();
|
|
237
|
+
state.unsubscribeOffline = void 0;
|
|
238
|
+
}
|
|
239
|
+
state.lastSync = 0;
|
|
240
|
+
state.cachedSession = void 0;
|
|
241
|
+
};
|
|
242
|
+
return {
|
|
243
|
+
init,
|
|
244
|
+
cleanup,
|
|
245
|
+
triggerRefetch,
|
|
246
|
+
broadcastSessionUpdate
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region src/client/session-atom.ts
|
|
252
|
+
const getSessionAtom = ($fetch, options) => {
|
|
253
|
+
const $signal = (0, nanostores.atom)(false);
|
|
254
|
+
const session = useAuthQuery($signal, "/get-session", $fetch, { method: "GET" });
|
|
255
|
+
if (typeof window !== "undefined") (0, nanostores.onMount)(session, () => {
|
|
256
|
+
const refreshManager = createSessionRefreshManager({
|
|
257
|
+
sessionAtom: session,
|
|
258
|
+
sessionSignal: $signal,
|
|
259
|
+
$fetch,
|
|
260
|
+
options
|
|
261
|
+
});
|
|
262
|
+
refreshManager.init();
|
|
263
|
+
return () => {
|
|
264
|
+
refreshManager.cleanup();
|
|
265
|
+
};
|
|
266
|
+
});
|
|
267
|
+
return {
|
|
268
|
+
session,
|
|
269
|
+
$sessionSignal: $signal
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
//#endregion
|
|
274
|
+
//#region src/client/config.ts
|
|
275
|
+
const getClientConfig = (options) => {
|
|
276
|
+
const baseURL = () => require_url.getBaseURL(options?.baseURL, options?.basePath) ?? "/api/auth";
|
|
277
|
+
const plugins = options?.plugins ?? [];
|
|
278
|
+
const pluginsFetchPlugins = plugins.flatMap((plugin) => plugin.fetchPlugins).filter((pl) => pl !== void 0);
|
|
279
|
+
const { onSuccess: _, onError: __, onRequest: ___, onResponse: ____,...restOfFetchOptions } = options?.fetchOptions ?? {};
|
|
280
|
+
const $fetch = (0, __better_fetch_fetch.createFetch)({
|
|
281
|
+
get baseURL() {
|
|
282
|
+
return baseURL();
|
|
283
|
+
},
|
|
284
|
+
..."credentials" in Request.prototype && { credentials: "include" },
|
|
285
|
+
method: "GET",
|
|
286
|
+
jsonParser(text) {
|
|
287
|
+
if (!text) return null;
|
|
288
|
+
return require_parser.parseJSON(text, { strict: false });
|
|
289
|
+
},
|
|
290
|
+
customFetchImpl: fetch,
|
|
291
|
+
...restOfFetchOptions,
|
|
292
|
+
plugins: [
|
|
293
|
+
lifecycle(options),
|
|
294
|
+
...restOfFetchOptions.plugins ?? [],
|
|
295
|
+
...options?.disableDefaultFetchPlugins ? [] : [redirectPlugin],
|
|
296
|
+
...pluginsFetchPlugins
|
|
297
|
+
]
|
|
298
|
+
});
|
|
299
|
+
const sessionAtom = getSessionAtom($fetch);
|
|
300
|
+
const pluginsActions = {};
|
|
301
|
+
const pluginsAtoms = sessionAtom;
|
|
302
|
+
const pluginPathMethods = {
|
|
303
|
+
"/sign-out": "POST",
|
|
304
|
+
"/revoke-sessions": "POST",
|
|
305
|
+
"/revoke-other-sessions": "POST",
|
|
306
|
+
"/delete-user": "POST"
|
|
307
|
+
};
|
|
308
|
+
const atomListeners = [{
|
|
309
|
+
signal: "$sessionSignal",
|
|
310
|
+
matcher(path) {
|
|
311
|
+
return path === "/sign-out" || path === "/update-user" || path.startsWith("/sign-in") || path.startsWith("/sign-up") || path === "/delete-user" || path === "/verify-email";
|
|
312
|
+
}
|
|
313
|
+
}];
|
|
314
|
+
for (const plugin of plugins) {
|
|
315
|
+
if (plugin.getAtoms) Object.assign(pluginsAtoms, plugin.getAtoms?.($fetch));
|
|
316
|
+
if (plugin.pathMethods) Object.assign(pluginPathMethods, plugin.pathMethods);
|
|
317
|
+
if (plugin.atomListeners) atomListeners.push(...plugin.atomListeners);
|
|
318
|
+
}
|
|
319
|
+
const $store = {
|
|
320
|
+
notify: (signal) => {
|
|
321
|
+
if (signal) pluginsAtoms[signal].set(!pluginsAtoms[signal].get());
|
|
322
|
+
},
|
|
323
|
+
listen: (signal, listener) => {
|
|
324
|
+
pluginsAtoms[signal].subscribe(listener);
|
|
325
|
+
},
|
|
326
|
+
atoms: pluginsAtoms
|
|
327
|
+
};
|
|
328
|
+
for (const plugin of plugins) if (plugin.getActions) Object.assign(pluginsActions, plugin.getActions?.($fetch, $store, options));
|
|
329
|
+
return {
|
|
330
|
+
get baseURL() {
|
|
331
|
+
return baseURL();
|
|
332
|
+
},
|
|
333
|
+
pluginsActions,
|
|
334
|
+
pluginsAtoms,
|
|
335
|
+
pluginPathMethods,
|
|
336
|
+
atomListeners,
|
|
337
|
+
$fetch,
|
|
338
|
+
$store
|
|
339
|
+
};
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
//#endregion
|
|
343
|
+
//#region src/client/hono.ts
|
|
344
|
+
const isPromise = (value) => value != null && typeof value.then === "function";
|
|
345
|
+
const isHonoRequestLike = (value) => value != null && typeof value === "object" && "raw" in value && value.raw instanceof Request && "header" in value && typeof value.header === "function" && "query" in value && typeof value.query === "function" && "param" in value && typeof value.param === "function" && "json" in value && typeof value.json === "function" && "path" in value && typeof value.path === "string";
|
|
346
|
+
const isInputOpts = (value) => value == null || typeof value === "object" && Object.keys(value).every((k) => k !== "fetchOptions" && k !== "fetch" && k !== "websocket" && k !== "init" && k !== "headers");
|
|
347
|
+
const returnFromRoutesIfFn = (fullPath, routes) => {
|
|
348
|
+
let current = routes;
|
|
349
|
+
for (const segment of fullPath) if (current && typeof current === "object" && segment in current) current = current[segment];
|
|
350
|
+
else {
|
|
351
|
+
current = void 0;
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
if (typeof current === "function" || fullPath[0] === "$fetch" || fullPath[0] === "$store") return current;
|
|
355
|
+
};
|
|
356
|
+
const createProxy = (callback, path, routes) => {
|
|
357
|
+
return new Proxy(() => {}, {
|
|
358
|
+
get(_obj, key) {
|
|
359
|
+
if (typeof key !== "string" || key === "then" || key === "catch" || key === "finally") return void 0;
|
|
360
|
+
const fullPath = [...path, key];
|
|
361
|
+
const maybeFn = returnFromRoutesIfFn(fullPath, routes);
|
|
362
|
+
if (maybeFn) return maybeFn;
|
|
363
|
+
return createProxy(callback, fullPath, routes);
|
|
364
|
+
},
|
|
365
|
+
apply(_1, _2, args) {
|
|
366
|
+
return callback({
|
|
367
|
+
path,
|
|
368
|
+
args
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
};
|
|
373
|
+
var ClientRequestImpl = class {
|
|
374
|
+
url;
|
|
375
|
+
path;
|
|
376
|
+
method;
|
|
377
|
+
queryParams = void 0;
|
|
378
|
+
pathParams = {};
|
|
379
|
+
rBody;
|
|
380
|
+
cType = void 0;
|
|
381
|
+
$fetch;
|
|
382
|
+
atoms;
|
|
383
|
+
atomListeners;
|
|
384
|
+
constructor(url, path, method, $fetch, atoms, atomListeners) {
|
|
385
|
+
this.url = url;
|
|
386
|
+
this.path = path;
|
|
387
|
+
this.method = method;
|
|
388
|
+
this.$fetch = $fetch;
|
|
389
|
+
if (atoms) this.atoms = atoms;
|
|
390
|
+
if (atomListeners) this.atomListeners = atomListeners;
|
|
391
|
+
}
|
|
392
|
+
fetch = async (args, opt) => {
|
|
393
|
+
if (isHonoRequestLike(opt.fetch)) return this.$fetch(opt.fetch.url, opt.fetch.raw);
|
|
394
|
+
if (args) {
|
|
395
|
+
if (args.query) this.queryParams = require_request.buildSearchParams(args.query);
|
|
396
|
+
if (args.form) {
|
|
397
|
+
const form = new FormData();
|
|
398
|
+
for (const [k, v] of Object.entries(args.form)) if (Array.isArray(v)) for (const v2 of v) form.append(k, v2);
|
|
399
|
+
else form.append(k, v);
|
|
400
|
+
this.rBody = form;
|
|
401
|
+
}
|
|
402
|
+
if (args.json) {
|
|
403
|
+
this.rBody = JSON.stringify(args.json);
|
|
404
|
+
this.cType = "application/json";
|
|
405
|
+
}
|
|
406
|
+
if (args.param) this.pathParams = args.param;
|
|
407
|
+
}
|
|
408
|
+
let methodUpperCase = this.method.toUpperCase();
|
|
409
|
+
let headers = require_request.normaliseHeaders(opt.headers);
|
|
410
|
+
if (isPromise(headers)) headers = await headers;
|
|
411
|
+
if (args?.header) Object.entries(args.header).forEach(([k, v]) => headers.set(k, v));
|
|
412
|
+
if (args?.cookie) {
|
|
413
|
+
const cookies = [];
|
|
414
|
+
for (const [key, value] of Object.entries(args.cookie)) cookies.push((0, hono_utils_cookie.serialize)(key, value, { path: "/" }));
|
|
415
|
+
headers.set("Cookie", cookies.join(","));
|
|
416
|
+
}
|
|
417
|
+
if (this.cType) headers.set("Content-Type", this.cType);
|
|
418
|
+
let url = this.url;
|
|
419
|
+
url = require_request.removeIndexString(url);
|
|
420
|
+
url = require_request.replaceUrlParam(url, this.pathParams);
|
|
421
|
+
if (this.queryParams && this.queryParams.size > 0) url = url + "?" + this.queryParams.toString();
|
|
422
|
+
methodUpperCase = this.method.toUpperCase();
|
|
423
|
+
const setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
|
|
424
|
+
return this.$fetch(url, {
|
|
425
|
+
customFetchImpl: opt.fetch,
|
|
426
|
+
...opt.fetchOptions,
|
|
427
|
+
...setBody === true && { body: this.rBody },
|
|
428
|
+
method: methodUpperCase,
|
|
429
|
+
headers,
|
|
430
|
+
...opt.init,
|
|
431
|
+
onSuccess: async (context) => {
|
|
432
|
+
if (opt.fetchOptions?.onSuccess) await opt.fetchOptions.onSuccess(context);
|
|
433
|
+
/**
|
|
434
|
+
* We trigger listeners
|
|
435
|
+
*/
|
|
436
|
+
const matches = this.atomListeners?.filter((s) => s.matcher(this.path));
|
|
437
|
+
if (!matches?.length) return;
|
|
438
|
+
for (const match of matches) {
|
|
439
|
+
const signal = this.atoms?.[match.signal];
|
|
440
|
+
if (!signal) return;
|
|
441
|
+
/**
|
|
442
|
+
* To avoid race conditions we set the signal in a setTimeout
|
|
443
|
+
*/
|
|
444
|
+
const val = signal.get();
|
|
445
|
+
setTimeout(() => signal.set(!val), 10);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
};
|
|
450
|
+
};
|
|
451
|
+
const createHonoClient = (options, routes, $fetch, atoms, atomListeners) => createProxy(function proxyCallback(opts) {
|
|
452
|
+
const parts = opts.path.map((segment) => segment.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`));
|
|
453
|
+
const lastParts = parts.slice(-3).reverse();
|
|
454
|
+
if (lastParts[0] === "toString") {
|
|
455
|
+
if (lastParts[1] === "name") return lastParts[2] ?? "";
|
|
456
|
+
return proxyCallback.toString();
|
|
457
|
+
}
|
|
458
|
+
if (lastParts[0] === "valueOf") {
|
|
459
|
+
if (lastParts[1] === "name") return lastParts[2] ?? "";
|
|
460
|
+
return proxyCallback;
|
|
461
|
+
}
|
|
462
|
+
let method = "";
|
|
463
|
+
if (/^\$/.test(lastParts[0])) {
|
|
464
|
+
const last = parts.pop();
|
|
465
|
+
if (last) method = last.replace(/^\$/, "");
|
|
466
|
+
}
|
|
467
|
+
const { input, clientOpts } = isInputOpts(opts.args[0]) ? {
|
|
468
|
+
input: opts.args[0] ?? {},
|
|
469
|
+
clientOpts: opts.args[1] ?? {}
|
|
470
|
+
} : {
|
|
471
|
+
input: {},
|
|
472
|
+
clientOpts: opts.args[0] ?? {}
|
|
473
|
+
};
|
|
474
|
+
const path = `/${parts.join("/")}`;
|
|
475
|
+
const url = require_request.mergePath(options.baseURL, path);
|
|
476
|
+
clientOpts.headers = require_request.mergeHeaders(options?.createFetchOptions?.headers, clientOpts.fetchOptions?.headers, clientOpts.headers);
|
|
477
|
+
if (method === "url" || method === "path") {
|
|
478
|
+
let result = url;
|
|
479
|
+
if (input.param) result = require_request.replaceUrlParam(url, input.param);
|
|
480
|
+
if (input.query) {
|
|
481
|
+
const sp = require_request.buildSearchParams(input.query);
|
|
482
|
+
if (sp.size > 0) result += "?" + sp.toString();
|
|
483
|
+
}
|
|
484
|
+
result = require_request.removeIndexString(result);
|
|
485
|
+
if (method === "url") return new URL(result);
|
|
486
|
+
const base = (options.baseURL ?? "").replace(/\/+$/, "");
|
|
487
|
+
return result.slice(base.length).replace(/^\/?/, "/");
|
|
488
|
+
}
|
|
489
|
+
if (method === "ws") {
|
|
490
|
+
const webSocketUrl = require_request.replaceUrlProtocol(input.param ? require_request.replaceUrlParam(url, input.param) : url, "ws");
|
|
491
|
+
const targetUrl = new URL(webSocketUrl);
|
|
492
|
+
const queryParams = input.query;
|
|
493
|
+
if (queryParams) Object.entries(queryParams).forEach(([key, value]) => {
|
|
494
|
+
if (Array.isArray(value)) value.forEach((item) => targetUrl.searchParams.append(key, item));
|
|
495
|
+
else targetUrl.searchParams.set(key, value);
|
|
496
|
+
});
|
|
497
|
+
const establishWebSocket = (...args) => {
|
|
498
|
+
if (options?.webSocket !== void 0 && typeof options.webSocket === "function") return options.webSocket(...args);
|
|
499
|
+
return new WebSocket(...args);
|
|
500
|
+
};
|
|
501
|
+
return establishWebSocket(targetUrl.toString());
|
|
502
|
+
}
|
|
503
|
+
const req = new ClientRequestImpl(url, path, method, $fetch, atoms, atomListeners);
|
|
504
|
+
clientOpts.fetchOptions = require_defu.defu(clientOpts.fetchOptions, options.createFetchOptions);
|
|
505
|
+
return req.fetch(input, clientOpts);
|
|
506
|
+
}, [], routes);
|
|
507
|
+
|
|
508
|
+
//#endregion
|
|
509
|
+
Object.defineProperty(exports, 'createHonoClient', {
|
|
510
|
+
enumerable: true,
|
|
511
|
+
get: function () {
|
|
512
|
+
return createHonoClient;
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
Object.defineProperty(exports, 'getClientConfig', {
|
|
516
|
+
enumerable: true,
|
|
517
|
+
get: function () {
|
|
518
|
+
return getClientConfig;
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
Object.defineProperty(exports, 'useAuthQuery', {
|
|
522
|
+
enumerable: true,
|
|
523
|
+
get: function () {
|
|
524
|
+
return useAuthQuery;
|
|
525
|
+
}
|
|
526
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-oakRccI5.cjs');
|
|
2
|
+
let hono_context_storage = require("hono/context-storage");
|
|
3
|
+
|
|
4
|
+
//#region src/context/hono.ts
|
|
5
|
+
const getContext = () => (0, hono_context_storage.getContext)();
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
Object.defineProperty(exports, 'getContext', {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () {
|
|
11
|
+
return getContext;
|
|
12
|
+
}
|
|
13
|
+
});
|