better-auth 0.0.8-beta.2 → 0.0.8-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/access.d.ts +3 -4
- package/dist/access.js +3 -13
- package/dist/access.js.map +1 -1
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +36 -44
- package/dist/cli.js.map +1 -1
- package/dist/client/plugins.d.ts +97 -2407
- package/dist/client/plugins.js +143 -203
- package/dist/client/plugins.js.map +1 -1
- package/dist/client.d.ts +159 -1213
- package/dist/client.js +125 -527
- package/dist/client.js.map +1 -1
- package/dist/{helper-B5_2Vzba.d.ts → helper-D8dhRz72.d.ts} +1 -4
- package/dist/{index-Dg4eEXZW.d.ts → index-B9jOjqnF.d.ts} +1 -1
- package/dist/{schema-BOszzrbQ.d.ts → index-CcxejJTH.d.ts} +172 -142
- package/dist/{client-CaF9eUcv.d.ts → index-Dwhjsk4l.d.ts} +2014 -1971
- package/dist/index.d.ts +1124 -6
- package/dist/index.js +737 -707
- package/dist/index.js.map +1 -1
- package/dist/internal-adapter-CVKQ4XR9.d.ts +637 -0
- package/dist/next-js.d.ts +17 -7
- package/dist/next-js.js +20 -3
- package/dist/next-js.js.map +1 -1
- package/dist/plugins.d.ts +12 -883
- package/dist/plugins.js +743 -679
- package/dist/plugins.js.map +1 -1
- package/dist/react.d.ts +312 -12
- package/dist/react.js +138 -148
- package/dist/react.js.map +1 -1
- package/dist/social.d.ts +2 -2
- package/dist/social.js +179 -151
- package/dist/social.js.map +1 -1
- package/dist/solid-start.d.ts +7 -6
- package/dist/solid-start.js +3 -3
- package/dist/solid-start.js.map +1 -1
- package/dist/solid.d.ts +91 -2713
- package/dist/solid.js +130 -139
- package/dist/solid.js.map +1 -1
- package/dist/{statement-COylZd3J.d.ts → statement-D6SPoYOh.d.ts} +7 -7
- package/dist/svelte-kit.d.ts +6 -5
- package/dist/svelte-kit.js +10 -9
- package/dist/svelte-kit.js.map +1 -1
- package/dist/svelte.d.ts +89 -2713
- package/dist/svelte.js +124 -138
- package/dist/svelte.js.map +1 -1
- package/dist/types-D4WrjKeJ.d.ts +81 -0
- package/dist/types.d.ts +31 -5
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -1
- package/dist/vue.d.ts +313 -12
- package/dist/vue.js +131 -145
- package/dist/vue.js.map +1 -1
- package/package.json +8 -3
- package/dist/index-CGeV0d2g.d.ts +0 -1498
- package/dist/preact.d.ts +0 -8
- package/dist/preact.js +0 -291
- package/dist/preact.js.map +0 -1
- package/dist/type-tYx_kmry.d.ts +0 -5724
package/dist/client.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
import { createFetch, betterFetch } from '@better-fetch/fetch';
|
|
2
|
+
import { atom, computed, task } from 'nanostores';
|
|
3
3
|
|
|
4
|
-
// src/
|
|
5
|
-
var BetterAuthError = class extends Error {
|
|
6
|
-
constructor(message) {
|
|
7
|
-
super(message);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
4
|
+
// src/client/config.ts
|
|
10
5
|
|
|
11
6
|
// src/utils/base-url.ts
|
|
12
7
|
function checkHasPath(url) {
|
|
@@ -21,47 +16,43 @@ function checkHasPath(url) {
|
|
|
21
16
|
function withPath(url, path = "/api/auth") {
|
|
22
17
|
const hasPath = checkHasPath(url);
|
|
23
18
|
if (hasPath) {
|
|
24
|
-
return
|
|
25
|
-
baseURL: new URL(url).origin,
|
|
26
|
-
withPath: url
|
|
27
|
-
};
|
|
19
|
+
return url;
|
|
28
20
|
}
|
|
29
21
|
path = path.startsWith("/") ? path : `/${path}`;
|
|
30
|
-
return {
|
|
31
|
-
baseURL: url,
|
|
32
|
-
withPath: `${url}${path}`
|
|
33
|
-
};
|
|
22
|
+
return `${url}${path}`;
|
|
34
23
|
}
|
|
35
24
|
function getBaseURL(url, path) {
|
|
36
25
|
if (url) {
|
|
37
26
|
return withPath(url, path);
|
|
38
27
|
}
|
|
39
28
|
const env = typeof process !== "undefined" ? process.env : {};
|
|
40
|
-
const fromEnv = env.BETTER_AUTH_URL || env.
|
|
29
|
+
const fromEnv = env.BETTER_AUTH_URL || env.NEXT_PUBLIC_BETTER_AUTH_URL || env.PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_AUTH_URL;
|
|
41
30
|
if (fromEnv) {
|
|
42
31
|
return withPath(fromEnv, path);
|
|
43
32
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
baseURL: "http://localhost:3000",
|
|
48
|
-
withPath: "http://localhost:3000/api/auth"
|
|
49
|
-
};
|
|
33
|
+
if (typeof window !== "undefined") {
|
|
34
|
+
return withPath(window.location.origin, path);
|
|
50
35
|
}
|
|
51
|
-
|
|
52
|
-
"Could not infer baseURL from environment variables"
|
|
53
|
-
);
|
|
36
|
+
return void 0;
|
|
54
37
|
}
|
|
55
38
|
|
|
39
|
+
// src/error/better-auth-error.ts
|
|
40
|
+
var BetterAuthError = class extends Error {
|
|
41
|
+
constructor(message) {
|
|
42
|
+
super(message);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
56
46
|
// src/client/fetch-plugins.ts
|
|
57
|
-
import { betterFetch } from "@better-fetch/fetch";
|
|
58
47
|
var redirectPlugin = {
|
|
59
48
|
id: "redirect",
|
|
60
49
|
name: "Redirect",
|
|
61
50
|
hooks: {
|
|
62
51
|
onSuccess(context) {
|
|
63
52
|
if (context.data?.url && context.data?.redirect) {
|
|
64
|
-
window
|
|
53
|
+
if (typeof window !== "undefined") {
|
|
54
|
+
window.location.href = context.data.url;
|
|
55
|
+
}
|
|
65
56
|
}
|
|
66
57
|
}
|
|
67
58
|
}
|
|
@@ -84,6 +75,17 @@ var csrfPlugin = {
|
|
|
84
75
|
id: "csrf",
|
|
85
76
|
name: "CSRF Check",
|
|
86
77
|
async init(url, options) {
|
|
78
|
+
if (typeof window !== "undefined") {
|
|
79
|
+
const isTheSameOrigin = new URL(options?.baseURL || url).origin === window.location.origin;
|
|
80
|
+
if (isTheSameOrigin) {
|
|
81
|
+
return { url, options };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (!options?.baseURL) {
|
|
85
|
+
throw new BetterAuthError(
|
|
86
|
+
"API Base URL on the auth client isn't configured. Please pass it directly to the client `baseURL`"
|
|
87
|
+
);
|
|
88
|
+
}
|
|
87
89
|
if (options?.method !== "GET") {
|
|
88
90
|
options = options || {};
|
|
89
91
|
const { data, error } = await betterFetch("/csrf", {
|
|
@@ -91,7 +93,8 @@ var csrfPlugin = {
|
|
|
91
93
|
baseURL: options.baseURL,
|
|
92
94
|
plugins: [],
|
|
93
95
|
method: "GET",
|
|
94
|
-
credentials: "include"
|
|
96
|
+
credentials: "include",
|
|
97
|
+
customFetchImpl: options.customFetchImpl
|
|
95
98
|
});
|
|
96
99
|
if (error?.status === 404) {
|
|
97
100
|
throw new BetterAuthError(
|
|
@@ -111,6 +114,61 @@ var csrfPlugin = {
|
|
|
111
114
|
}
|
|
112
115
|
};
|
|
113
116
|
|
|
117
|
+
// src/client/config.ts
|
|
118
|
+
var getClientConfig = (options) => {
|
|
119
|
+
const $fetch = createFetch({
|
|
120
|
+
baseURL: getBaseURL(options?.fetchOptions?.baseURL || options?.baseURL),
|
|
121
|
+
...options?.fetchOptions,
|
|
122
|
+
plugins: [
|
|
123
|
+
csrfPlugin,
|
|
124
|
+
redirectPlugin,
|
|
125
|
+
addCurrentURL,
|
|
126
|
+
...options?.fetchOptions?.plugins || [],
|
|
127
|
+
...options?.plugins?.flatMap((plugin) => plugin.fetchPlugins).filter((pl) => pl !== void 0) || []
|
|
128
|
+
]
|
|
129
|
+
});
|
|
130
|
+
const plugins = options?.plugins || [];
|
|
131
|
+
let pluginsActions = {};
|
|
132
|
+
let pluginsAtoms = {};
|
|
133
|
+
let pluginPathMethods = {
|
|
134
|
+
"/sign-out": "POST"
|
|
135
|
+
};
|
|
136
|
+
const atomListeners = [
|
|
137
|
+
{
|
|
138
|
+
signal: "_sessionSignal",
|
|
139
|
+
matcher(path) {
|
|
140
|
+
return path === "/sign-out" || path === "sign-up/email";
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
];
|
|
144
|
+
for (const plugin of plugins) {
|
|
145
|
+
if (plugin.getActions) {
|
|
146
|
+
Object.assign(pluginsActions, plugin.getActions?.($fetch));
|
|
147
|
+
}
|
|
148
|
+
if (plugin.getAtoms) {
|
|
149
|
+
Object.assign(pluginsAtoms, plugin.getAtoms?.($fetch));
|
|
150
|
+
}
|
|
151
|
+
if (plugin.pathMethods) {
|
|
152
|
+
Object.assign(pluginPathMethods, plugin.pathMethods);
|
|
153
|
+
}
|
|
154
|
+
if (plugin.atomListeners) {
|
|
155
|
+
atomListeners.push(...plugin.atomListeners);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
pluginsActions,
|
|
160
|
+
pluginsAtoms,
|
|
161
|
+
pluginPathMethods,
|
|
162
|
+
atomListeners,
|
|
163
|
+
$fetch
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// src/utils/misc.ts
|
|
168
|
+
function capitalizeFirstLetter(str) {
|
|
169
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
170
|
+
}
|
|
171
|
+
|
|
114
172
|
// src/client/proxy.ts
|
|
115
173
|
function getMethod(path, knownPathMethods, args) {
|
|
116
174
|
const method = knownPathMethods[path];
|
|
@@ -126,7 +184,7 @@ function getMethod(path, knownPathMethods, args) {
|
|
|
126
184
|
}
|
|
127
185
|
return "GET";
|
|
128
186
|
}
|
|
129
|
-
function createDynamicPathProxy(routes, client, knownPathMethods,
|
|
187
|
+
function createDynamicPathProxy(routes, client, knownPathMethods, atoms, atomListeners) {
|
|
130
188
|
function createProxy(path = []) {
|
|
131
189
|
return new Proxy(function() {
|
|
132
190
|
}, {
|
|
@@ -155,16 +213,21 @@ function createDynamicPathProxy(routes, client, knownPathMethods, $signal, $sign
|
|
|
155
213
|
const { query, options, ...body } = arg;
|
|
156
214
|
return await client(routePath, {
|
|
157
215
|
...options,
|
|
158
|
-
body: method === "GET" ? void 0 :
|
|
216
|
+
body: method === "GET" ? void 0 : {
|
|
217
|
+
...body,
|
|
218
|
+
...options?.body || {}
|
|
219
|
+
},
|
|
159
220
|
query,
|
|
160
221
|
method,
|
|
161
222
|
async onSuccess(context) {
|
|
162
|
-
const signal = $signal?.find((s) => s.matcher(routePath));
|
|
163
|
-
if (!signal) return;
|
|
164
|
-
const signalAtom = $signals?.[signal.atom];
|
|
165
|
-
if (!signalAtom) return;
|
|
166
|
-
signalAtom.set(!signalAtom.get());
|
|
167
223
|
await options?.onSuccess?.(context);
|
|
224
|
+
const matches = atomListeners?.find((s) => s.matcher(routePath));
|
|
225
|
+
if (!matches) return;
|
|
226
|
+
const signal = atoms[matches.signal];
|
|
227
|
+
if (!signal) return;
|
|
228
|
+
setTimeout(() => {
|
|
229
|
+
signal.set(!signal.get());
|
|
230
|
+
}, 0);
|
|
168
231
|
}
|
|
169
232
|
});
|
|
170
233
|
}
|
|
@@ -172,9 +235,6 @@ function createDynamicPathProxy(routes, client, knownPathMethods, $signal, $sign
|
|
|
172
235
|
}
|
|
173
236
|
return createProxy();
|
|
174
237
|
}
|
|
175
|
-
|
|
176
|
-
// src/client/session-atom.ts
|
|
177
|
-
import { atom, computed, task } from "nanostores";
|
|
178
238
|
function getSessionAtom(client) {
|
|
179
239
|
const $signal = atom(false);
|
|
180
240
|
const $session = computed(
|
|
@@ -187,504 +247,42 @@ function getSessionAtom(client) {
|
|
|
187
247
|
return session.data;
|
|
188
248
|
})
|
|
189
249
|
);
|
|
190
|
-
return { $session,
|
|
250
|
+
return { $session, _sessionSignal: $signal };
|
|
191
251
|
}
|
|
192
252
|
|
|
193
|
-
// src/client/
|
|
194
|
-
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
baseURL: getBaseURL(options?.baseURL).withPath,
|
|
200
|
-
plugins: [
|
|
201
|
-
...options?.plugins || [],
|
|
202
|
-
...options?.authPlugins?.flatMap((plugin) => plugin($baseFetch).fetchPlugins).filter((plugin) => plugin !== void 0) || [],
|
|
203
|
-
...options?.csrfPlugin !== false ? [csrfPlugin] : [],
|
|
204
|
-
redirectPlugin,
|
|
205
|
-
addCurrentURL
|
|
206
|
-
]
|
|
207
|
-
});
|
|
208
|
-
};
|
|
209
|
-
var createAuthClient = (options, additionalActions = {}) => {
|
|
210
|
-
const $fetch = createAuthFetch(options);
|
|
211
|
-
const { $session, $sessionSignal } = getSessionAtom($fetch);
|
|
212
|
-
let pluginsActions = {};
|
|
213
|
-
const pluginProxySignals = [];
|
|
214
|
-
let pluginSignals = {};
|
|
215
|
-
let pluginPathMethods = {};
|
|
216
|
-
for (const plugin of options?.authPlugins || []) {
|
|
217
|
-
const pl = plugin($fetch);
|
|
218
|
-
if (pl.authProxySignal) {
|
|
219
|
-
pluginProxySignals.push(...pl.authProxySignal);
|
|
220
|
-
}
|
|
221
|
-
if (pl.actions) {
|
|
222
|
-
pluginsActions = {
|
|
223
|
-
...pluginsActions,
|
|
224
|
-
...pl.actions
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
if (pl.signals) {
|
|
228
|
-
pluginSignals = {
|
|
229
|
-
...pluginSignals,
|
|
230
|
-
...pl.signals
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
if (pl.pathMethods) {
|
|
234
|
-
pluginPathMethods = {
|
|
235
|
-
...pluginPathMethods,
|
|
236
|
-
...pl.pathMethods
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
const actions = {
|
|
241
|
-
$atoms: {
|
|
242
|
-
$session
|
|
243
|
-
},
|
|
253
|
+
// src/client/vanilla.ts
|
|
254
|
+
function createAuthClient(options) {
|
|
255
|
+
const {
|
|
256
|
+
pluginPathMethods,
|
|
257
|
+
pluginsActions,
|
|
258
|
+
pluginsAtoms,
|
|
244
259
|
$fetch,
|
|
260
|
+
atomListeners
|
|
261
|
+
} = getClientConfig(options);
|
|
262
|
+
let resolvedHooks = {};
|
|
263
|
+
for (const [key, value] of Object.entries(pluginsAtoms)) {
|
|
264
|
+
resolvedHooks[`use${capitalizeFirstLetter(key)}`] = value;
|
|
265
|
+
}
|
|
266
|
+
const { $session, _sessionSignal } = getSessionAtom($fetch);
|
|
267
|
+
const routes = {
|
|
245
268
|
...pluginsActions,
|
|
246
|
-
...
|
|
269
|
+
...resolvedHooks,
|
|
270
|
+
$fetch,
|
|
271
|
+
useSession: $session
|
|
247
272
|
};
|
|
248
273
|
const proxy = createDynamicPathProxy(
|
|
249
|
-
|
|
274
|
+
routes,
|
|
250
275
|
$fetch,
|
|
276
|
+
pluginPathMethods,
|
|
251
277
|
{
|
|
252
|
-
...
|
|
253
|
-
|
|
278
|
+
...pluginsAtoms,
|
|
279
|
+
_sessionSignal
|
|
254
280
|
},
|
|
255
|
-
|
|
256
|
-
{
|
|
257
|
-
matcher: (path) => path === "/organization/create",
|
|
258
|
-
atom: "$listOrg"
|
|
259
|
-
},
|
|
260
|
-
{
|
|
261
|
-
matcher: (path) => path.startsWith("/organization"),
|
|
262
|
-
atom: "$activeOrgSignal"
|
|
263
|
-
},
|
|
264
|
-
{
|
|
265
|
-
matcher: (path) => path === "/sign-out" || path.startsWith("/sign-up") || path.startsWith("/sign-in"),
|
|
266
|
-
atom: "$sessionSignal"
|
|
267
|
-
},
|
|
268
|
-
...pluginProxySignals
|
|
269
|
-
],
|
|
270
|
-
{
|
|
271
|
-
$sessionSignal,
|
|
272
|
-
...pluginSignals
|
|
273
|
-
}
|
|
281
|
+
atomListeners
|
|
274
282
|
);
|
|
275
283
|
return proxy;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// src/client/create-client-plugin.ts
|
|
279
|
-
var createClientPlugin = () => {
|
|
280
|
-
return ($fn) => {
|
|
281
|
-
return ($fetch) => {
|
|
282
|
-
const data = $fn($fetch);
|
|
283
|
-
return {
|
|
284
|
-
...data,
|
|
285
|
-
integrations: data.integrations,
|
|
286
|
-
plugin: {}
|
|
287
|
-
};
|
|
288
|
-
};
|
|
289
|
-
};
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
// src/plugins/two-factor/client.ts
|
|
293
|
-
var twoFactorClient = (options = {
|
|
294
|
-
redirect: true,
|
|
295
|
-
twoFactorPage: "/"
|
|
296
|
-
}) => {
|
|
297
|
-
return createClientPlugin()(($fetch) => {
|
|
298
|
-
return {
|
|
299
|
-
id: "two-factor",
|
|
300
|
-
authProxySignal: [
|
|
301
|
-
{
|
|
302
|
-
matcher: (path) => path === "/two-factor/enable" || path === "/two-factor/send-otp",
|
|
303
|
-
atom: "$sessionSignal"
|
|
304
|
-
}
|
|
305
|
-
],
|
|
306
|
-
pathMethods: {
|
|
307
|
-
"enable/totp": "POST",
|
|
308
|
-
"/two-factor/disable": "POST",
|
|
309
|
-
"/two-factor/enable": "POST",
|
|
310
|
-
"/two-factor/send-otp": "POST"
|
|
311
|
-
},
|
|
312
|
-
fetchPlugins: [
|
|
313
|
-
{
|
|
314
|
-
id: "two-factor",
|
|
315
|
-
name: "two-factor",
|
|
316
|
-
hooks: {
|
|
317
|
-
async onSuccess(context) {
|
|
318
|
-
if (context.data?.twoFactorRedirect) {
|
|
319
|
-
if (options.redirect) {
|
|
320
|
-
window.location.href = options.twoFactorPage;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
]
|
|
327
|
-
};
|
|
328
|
-
});
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
// src/plugins/organization/client.ts
|
|
332
|
-
import { atom as atom2, computed as computed2, task as task2 } from "nanostores";
|
|
333
|
-
|
|
334
|
-
// src/plugins/organization/access/src/access.ts
|
|
335
|
-
var ParsingError = class extends Error {
|
|
336
|
-
path;
|
|
337
|
-
constructor(message, path) {
|
|
338
|
-
super(message);
|
|
339
|
-
this.path = path;
|
|
340
|
-
}
|
|
341
|
-
};
|
|
342
|
-
var AccessControl = class {
|
|
343
|
-
constructor(s) {
|
|
344
|
-
this.s = s;
|
|
345
|
-
this.statements = s;
|
|
346
|
-
}
|
|
347
|
-
statements;
|
|
348
|
-
newRole(statements) {
|
|
349
|
-
return new Role(statements);
|
|
350
|
-
}
|
|
351
|
-
};
|
|
352
|
-
var Role = class _Role {
|
|
353
|
-
statements;
|
|
354
|
-
constructor(statements) {
|
|
355
|
-
this.statements = statements;
|
|
356
|
-
}
|
|
357
|
-
authorize(request, connector) {
|
|
358
|
-
for (const [requestedResource, requestedActions] of Object.entries(
|
|
359
|
-
request
|
|
360
|
-
)) {
|
|
361
|
-
const allowedActions = this.statements[requestedResource];
|
|
362
|
-
if (!allowedActions) {
|
|
363
|
-
return {
|
|
364
|
-
success: false,
|
|
365
|
-
error: `You are not allowed to access resource: ${requestedResource}`
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
const success = connector === "OR" ? requestedActions.some(
|
|
369
|
-
(requestedAction) => allowedActions.includes(requestedAction)
|
|
370
|
-
) : requestedActions.every(
|
|
371
|
-
(requestedAction) => allowedActions.includes(requestedAction)
|
|
372
|
-
);
|
|
373
|
-
if (success) {
|
|
374
|
-
return { success };
|
|
375
|
-
}
|
|
376
|
-
return {
|
|
377
|
-
success: false,
|
|
378
|
-
error: `unauthorized to access resource "${requestedResource}"`
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
return {
|
|
382
|
-
success: false,
|
|
383
|
-
error: "Not authorized"
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
static fromString(s) {
|
|
387
|
-
const statements = JSON.parse(s);
|
|
388
|
-
if (typeof statements !== "object") {
|
|
389
|
-
throw new ParsingError("statements is not an object", ".");
|
|
390
|
-
}
|
|
391
|
-
for (const [resource, actions] of Object.entries(statements)) {
|
|
392
|
-
if (typeof resource !== "string") {
|
|
393
|
-
throw new ParsingError("invalid resource identifier", resource);
|
|
394
|
-
}
|
|
395
|
-
if (!Array.isArray(actions)) {
|
|
396
|
-
throw new ParsingError("actions is not an array", resource);
|
|
397
|
-
}
|
|
398
|
-
for (let i = 0; i < actions.length; i++) {
|
|
399
|
-
if (typeof actions[i] !== "string") {
|
|
400
|
-
throw new ParsingError("action is not a string", `${resource}[${i}]`);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
return new _Role(statements);
|
|
405
|
-
}
|
|
406
|
-
toString() {
|
|
407
|
-
return JSON.stringify(this.statements);
|
|
408
|
-
}
|
|
409
|
-
};
|
|
410
|
-
|
|
411
|
-
// src/plugins/organization/access/statement.ts
|
|
412
|
-
var createAccessControl = (statements) => {
|
|
413
|
-
return new AccessControl(statements);
|
|
414
|
-
};
|
|
415
|
-
var defaultStatements = {
|
|
416
|
-
organization: ["update", "delete"],
|
|
417
|
-
member: ["create", "update", "delete"],
|
|
418
|
-
invitation: ["create", "cancel"]
|
|
419
|
-
};
|
|
420
|
-
var defaultAc = createAccessControl(defaultStatements);
|
|
421
|
-
var adminAc = defaultAc.newRole({
|
|
422
|
-
organization: ["update"],
|
|
423
|
-
invitation: ["create", "cancel"],
|
|
424
|
-
member: ["create", "update", "delete"]
|
|
425
|
-
});
|
|
426
|
-
var ownerAc = defaultAc.newRole({
|
|
427
|
-
organization: ["update", "delete"],
|
|
428
|
-
member: ["create", "update", "delete"],
|
|
429
|
-
invitation: ["create", "cancel"]
|
|
430
|
-
});
|
|
431
|
-
var memberAc = defaultAc.newRole({
|
|
432
|
-
organization: [],
|
|
433
|
-
member: [],
|
|
434
|
-
invitation: []
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
// src/plugins/organization/client.ts
|
|
438
|
-
var organizationClient = (options) => createClientPlugin()(($fetch) => {
|
|
439
|
-
const activeOrgId = atom2(null);
|
|
440
|
-
const $listOrg = atom2(false);
|
|
441
|
-
const $activeOrgSignal = atom2(false);
|
|
442
|
-
const $activeOrganization = computed2(
|
|
443
|
-
[activeOrgId, $activeOrgSignal],
|
|
444
|
-
() => task2(async () => {
|
|
445
|
-
if (!activeOrgId.get()) {
|
|
446
|
-
return null;
|
|
447
|
-
}
|
|
448
|
-
const organization = await $fetch("/organization/set-active", {
|
|
449
|
-
method: "POST",
|
|
450
|
-
credentials: "include",
|
|
451
|
-
body: {
|
|
452
|
-
orgId: activeOrgId.get()
|
|
453
|
-
}
|
|
454
|
-
});
|
|
455
|
-
return organization.data;
|
|
456
|
-
})
|
|
457
|
-
);
|
|
458
|
-
const $listOrganizations = computed2(
|
|
459
|
-
$listOrg,
|
|
460
|
-
() => task2(async () => {
|
|
461
|
-
const organizations = await $fetch(
|
|
462
|
-
"/organization/list",
|
|
463
|
-
{
|
|
464
|
-
method: "GET"
|
|
465
|
-
}
|
|
466
|
-
);
|
|
467
|
-
return organizations.data;
|
|
468
|
-
})
|
|
469
|
-
);
|
|
470
|
-
const $activeInvitationId = atom2(null);
|
|
471
|
-
const $invitation = computed2(
|
|
472
|
-
$activeInvitationId,
|
|
473
|
-
() => task2(async () => {
|
|
474
|
-
if (!$activeInvitationId.get()) {
|
|
475
|
-
return {
|
|
476
|
-
error: {
|
|
477
|
-
message: "No invitation found",
|
|
478
|
-
status: 400,
|
|
479
|
-
data: null
|
|
480
|
-
},
|
|
481
|
-
data: null
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
|
-
const res = await $fetch("/organization/get-active-invitation", {
|
|
485
|
-
method: "GET",
|
|
486
|
-
query: {
|
|
487
|
-
id: $activeInvitationId.get()
|
|
488
|
-
},
|
|
489
|
-
credentials: "include"
|
|
490
|
-
});
|
|
491
|
-
return res;
|
|
492
|
-
})
|
|
493
|
-
);
|
|
494
|
-
return {
|
|
495
|
-
id: "organization",
|
|
496
|
-
actions: {
|
|
497
|
-
organization: {
|
|
498
|
-
setActive(orgId) {
|
|
499
|
-
activeOrgId.set(orgId);
|
|
500
|
-
},
|
|
501
|
-
setInvitationId: (id) => {
|
|
502
|
-
$activeInvitationId.set(id);
|
|
503
|
-
},
|
|
504
|
-
hasPermission: async (permission) => {
|
|
505
|
-
await $fetch("/organization/has-permission", {
|
|
506
|
-
method: "POST",
|
|
507
|
-
body: {
|
|
508
|
-
permission
|
|
509
|
-
}
|
|
510
|
-
});
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
},
|
|
514
|
-
integrations: {
|
|
515
|
-
react(useStore) {
|
|
516
|
-
return {
|
|
517
|
-
organization: {
|
|
518
|
-
useActiveOrganization() {
|
|
519
|
-
return useStore($activeOrganization);
|
|
520
|
-
},
|
|
521
|
-
useListOrganization() {
|
|
522
|
-
return useStore($listOrganizations);
|
|
523
|
-
},
|
|
524
|
-
useInvitation() {
|
|
525
|
-
return useStore($invitation);
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
};
|
|
529
|
-
},
|
|
530
|
-
vue(useStore) {
|
|
531
|
-
return {
|
|
532
|
-
useActiveOrganization() {
|
|
533
|
-
return useStore($activeOrganization);
|
|
534
|
-
},
|
|
535
|
-
useListOrganization() {
|
|
536
|
-
return useStore($listOrganizations);
|
|
537
|
-
},
|
|
538
|
-
useInvitation() {
|
|
539
|
-
return useStore($invitation);
|
|
540
|
-
}
|
|
541
|
-
};
|
|
542
|
-
},
|
|
543
|
-
preact(useStore) {
|
|
544
|
-
return {
|
|
545
|
-
useActiveOrganization() {
|
|
546
|
-
return useStore($activeOrganization);
|
|
547
|
-
},
|
|
548
|
-
useListOrganization() {
|
|
549
|
-
return useStore($listOrganizations);
|
|
550
|
-
},
|
|
551
|
-
useInvitation() {
|
|
552
|
-
return useStore($invitation);
|
|
553
|
-
}
|
|
554
|
-
};
|
|
555
|
-
},
|
|
556
|
-
svelte() {
|
|
557
|
-
return {
|
|
558
|
-
$activeOrganization,
|
|
559
|
-
$listOrganizations,
|
|
560
|
-
$invitation
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
},
|
|
564
|
-
signals: {
|
|
565
|
-
$listOrg,
|
|
566
|
-
$activeOrgSignal
|
|
567
|
-
},
|
|
568
|
-
authProxySignal: [
|
|
569
|
-
{
|
|
570
|
-
matcher(path) {
|
|
571
|
-
return path.startsWith("/organization");
|
|
572
|
-
},
|
|
573
|
-
atom: "$listOrg"
|
|
574
|
-
},
|
|
575
|
-
{
|
|
576
|
-
matcher(path) {
|
|
577
|
-
return path.startsWith("/organization");
|
|
578
|
-
},
|
|
579
|
-
atom: "$activeOrgSignal"
|
|
580
|
-
}
|
|
581
|
-
]
|
|
582
|
-
};
|
|
583
|
-
});
|
|
584
|
-
|
|
585
|
-
// src/plugins/passkey/client.ts
|
|
586
|
-
import {
|
|
587
|
-
WebAuthnError,
|
|
588
|
-
startAuthentication,
|
|
589
|
-
startRegistration
|
|
590
|
-
} from "@simplewebauthn/browser";
|
|
591
|
-
var getPasskeyActions = ($fetch) => {
|
|
592
|
-
const signInPasskey = async (opts) => {
|
|
593
|
-
const response = await $fetch(
|
|
594
|
-
"/passkey/generate-authenticate-options",
|
|
595
|
-
{
|
|
596
|
-
method: "POST",
|
|
597
|
-
body: {
|
|
598
|
-
email: opts?.email
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
);
|
|
602
|
-
if (!response.data) {
|
|
603
|
-
return response;
|
|
604
|
-
}
|
|
605
|
-
try {
|
|
606
|
-
const res = await startAuthentication(
|
|
607
|
-
response.data,
|
|
608
|
-
opts?.autoFill || false
|
|
609
|
-
);
|
|
610
|
-
const verified = await $fetch("/passkey/verify-authentication", {
|
|
611
|
-
body: {
|
|
612
|
-
response: res,
|
|
613
|
-
type: "authenticate"
|
|
614
|
-
}
|
|
615
|
-
});
|
|
616
|
-
if (!verified.data) {
|
|
617
|
-
return verified;
|
|
618
|
-
}
|
|
619
|
-
} catch (e) {
|
|
620
|
-
console.log(e);
|
|
621
|
-
}
|
|
622
|
-
};
|
|
623
|
-
const registerPasskey = async () => {
|
|
624
|
-
const options = await $fetch(
|
|
625
|
-
"/passkey/generate-register-options",
|
|
626
|
-
{
|
|
627
|
-
method: "GET"
|
|
628
|
-
}
|
|
629
|
-
);
|
|
630
|
-
if (!options.data) {
|
|
631
|
-
return options;
|
|
632
|
-
}
|
|
633
|
-
try {
|
|
634
|
-
const res = await startRegistration(options.data);
|
|
635
|
-
const verified = await $fetch("/passkey/verify-registration", {
|
|
636
|
-
body: {
|
|
637
|
-
response: res,
|
|
638
|
-
type: "register"
|
|
639
|
-
}
|
|
640
|
-
});
|
|
641
|
-
if (!verified.data) {
|
|
642
|
-
return verified;
|
|
643
|
-
}
|
|
644
|
-
} catch (e) {
|
|
645
|
-
if (e instanceof WebAuthnError) {
|
|
646
|
-
if (e.code === "ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED") {
|
|
647
|
-
return {
|
|
648
|
-
data: null,
|
|
649
|
-
error: {
|
|
650
|
-
message: "previously registered",
|
|
651
|
-
status: 400,
|
|
652
|
-
statusText: "BAD_REQUEST"
|
|
653
|
-
}
|
|
654
|
-
};
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
};
|
|
659
|
-
return {
|
|
660
|
-
signInPasskey,
|
|
661
|
-
registerPasskey
|
|
662
|
-
};
|
|
663
|
-
};
|
|
664
|
-
var passkeyClient = createClientPlugin()(
|
|
665
|
-
($fetch) => {
|
|
666
|
-
return {
|
|
667
|
-
id: "passkey",
|
|
668
|
-
actions: getPasskeyActions($fetch)
|
|
669
|
-
};
|
|
670
|
-
}
|
|
671
|
-
);
|
|
284
|
+
}
|
|
672
285
|
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
($fetch) => {
|
|
676
|
-
return {
|
|
677
|
-
id: "username"
|
|
678
|
-
};
|
|
679
|
-
}
|
|
680
|
-
);
|
|
681
|
-
export {
|
|
682
|
-
createAuthClient,
|
|
683
|
-
createAuthFetch,
|
|
684
|
-
getPasskeyActions,
|
|
685
|
-
organizationClient,
|
|
686
|
-
passkeyClient,
|
|
687
|
-
twoFactorClient,
|
|
688
|
-
usernameClient
|
|
689
|
-
};
|
|
286
|
+
export { createAuthClient };
|
|
287
|
+
//# sourceMappingURL=client.js.map
|
|
690
288
|
//# sourceMappingURL=client.js.map
|