@korajs/auth 0.5.0 → 1.0.0-beta.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 +21 -0
- package/dist/chunk-MPMXJ62R.js +203 -0
- package/dist/chunk-MPMXJ62R.js.map +1 -0
- package/dist/{org-client-q2u55qod.d.cts → create-org-session-RsDj9cl4.d.cts} +58 -1
- package/dist/{org-client-q2u55qod.d.ts → create-org-session-RsDj9cl4.d.ts} +58 -1
- package/dist/index.cjs +168 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -19
- package/dist/index.d.ts +9 -19
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +294 -258
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +15 -215
- package/dist/react.d.ts +15 -215
- package/dist/react.js +135 -288
- package/dist/react.js.map +1 -1
- package/dist/server.cjs +42 -5
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +24 -0
- package/dist/server.d.ts +24 -0
- package/dist/server.js +42 -5
- package/dist/server.js.map +1 -1
- package/dist/svelte.cjs +512 -0
- package/dist/svelte.cjs.map +1 -0
- package/dist/svelte.d.cts +100 -0
- package/dist/svelte.d.ts +100 -0
- package/dist/svelte.js +278 -0
- package/dist/svelte.js.map +1 -0
- package/dist/vue.cjs +565 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.cts +136 -0
- package/dist/vue.d.ts +136 -0
- package/dist/vue.js +338 -0
- package/dist/vue.js.map +1 -0
- package/package.json +40 -6
- package/src/svelte/AuthProvider.svelte +37 -0
- package/src/svelte/OrgProvider.svelte +22 -0
package/dist/svelte.cjs
ADDED
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/svelte.ts
|
|
21
|
+
var svelte_exports = {};
|
|
22
|
+
__export(svelte_exports, {
|
|
23
|
+
checkOrgPermission: () => checkOrgPermission,
|
|
24
|
+
createAuthStatusStore: () => createAuthStatusStore,
|
|
25
|
+
createAuthStore: () => createAuthStore,
|
|
26
|
+
createCurrentUserStore: () => createCurrentUserStore,
|
|
27
|
+
createPermissionStore: () => createPermissionStore,
|
|
28
|
+
destroyAuthProvider: () => destroyAuthProvider,
|
|
29
|
+
destroyOrgProvider: () => destroyOrgProvider,
|
|
30
|
+
getAuthContext: () => getAuthContext,
|
|
31
|
+
getOrgContext: () => getOrgContext,
|
|
32
|
+
initAuthProvider: () => initAuthProvider,
|
|
33
|
+
initOrgProvider: () => initOrgProvider,
|
|
34
|
+
useAuth: () => useAuth,
|
|
35
|
+
useAuthStatus: () => useAuthStatus,
|
|
36
|
+
useCurrentUser: () => useCurrentUser,
|
|
37
|
+
useOrg: () => useOrg,
|
|
38
|
+
useOrgMembers: () => useOrgMembers,
|
|
39
|
+
usePermission: () => usePermission
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(svelte_exports);
|
|
42
|
+
|
|
43
|
+
// src/svelte/auth-context.ts
|
|
44
|
+
var import_svelte = require("svelte");
|
|
45
|
+
|
|
46
|
+
// src/bindings/create-auth-session.ts
|
|
47
|
+
function createAuthSession(client) {
|
|
48
|
+
let state = client.state;
|
|
49
|
+
let isLoading = true;
|
|
50
|
+
let initError = null;
|
|
51
|
+
let lastError = null;
|
|
52
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
53
|
+
let snapshot = buildSnapshot2();
|
|
54
|
+
const refreshSnapshot = () => {
|
|
55
|
+
snapshot = buildSnapshot2();
|
|
56
|
+
};
|
|
57
|
+
const notify = () => {
|
|
58
|
+
refreshSnapshot();
|
|
59
|
+
for (const listener of listeners) {
|
|
60
|
+
listener();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
function buildSnapshot2() {
|
|
64
|
+
return {
|
|
65
|
+
state,
|
|
66
|
+
user: client.currentUser,
|
|
67
|
+
isAuthenticated: state === "authenticated",
|
|
68
|
+
isLoading,
|
|
69
|
+
initError,
|
|
70
|
+
error: lastError
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const captureError = (error) => {
|
|
74
|
+
lastError = error instanceof Error ? error.message : String(error);
|
|
75
|
+
notify();
|
|
76
|
+
};
|
|
77
|
+
const run = async (action) => {
|
|
78
|
+
lastError = null;
|
|
79
|
+
try {
|
|
80
|
+
await action();
|
|
81
|
+
} catch (error) {
|
|
82
|
+
captureError(error);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const runWithResult = async (action) => {
|
|
86
|
+
lastError = null;
|
|
87
|
+
try {
|
|
88
|
+
return await action();
|
|
89
|
+
} catch (error) {
|
|
90
|
+
captureError(error);
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const unsubscribeAuth = client.onAuthChange((nextState) => {
|
|
95
|
+
state = nextState;
|
|
96
|
+
notify();
|
|
97
|
+
});
|
|
98
|
+
void client.initialize().then(() => {
|
|
99
|
+
state = client.state;
|
|
100
|
+
isLoading = false;
|
|
101
|
+
notify();
|
|
102
|
+
}).catch((error) => {
|
|
103
|
+
initError = error instanceof Error ? error : new Error(String(error));
|
|
104
|
+
isLoading = false;
|
|
105
|
+
notify();
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
client,
|
|
109
|
+
getSnapshot: () => snapshot,
|
|
110
|
+
subscribe(listener) {
|
|
111
|
+
listeners.add(listener);
|
|
112
|
+
return () => {
|
|
113
|
+
listeners.delete(listener);
|
|
114
|
+
};
|
|
115
|
+
},
|
|
116
|
+
signUp: (params) => run(async () => {
|
|
117
|
+
await client.signUp(params);
|
|
118
|
+
}),
|
|
119
|
+
signIn: (params) => run(async () => {
|
|
120
|
+
await client.signIn(params);
|
|
121
|
+
}),
|
|
122
|
+
signInWithOAuth: async (provider, options) => {
|
|
123
|
+
lastError = null;
|
|
124
|
+
try {
|
|
125
|
+
return await client.signInWithOAuth(provider, options);
|
|
126
|
+
} catch (error) {
|
|
127
|
+
captureError(error);
|
|
128
|
+
throw error instanceof Error ? error : new Error(String(error));
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
completeOAuthSignIn: (provider, params) => run(async () => {
|
|
132
|
+
await client.completeOAuthSignIn(provider, params);
|
|
133
|
+
}),
|
|
134
|
+
getOAuthAuthorizationUrl: async (provider, options) => {
|
|
135
|
+
lastError = null;
|
|
136
|
+
try {
|
|
137
|
+
return await client.getOAuthAuthorizationUrl(provider, options);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
captureError(error);
|
|
140
|
+
throw error instanceof Error ? error : new Error(String(error));
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
linkOAuth: (provider, params) => runWithResult(async () => client.linkOAuth(provider, params)),
|
|
144
|
+
listLinkedAccounts: () => runWithResult(async () => client.listLinkedAccounts()).then((value) => value ?? []),
|
|
145
|
+
unlinkOAuth: (provider) => run(async () => {
|
|
146
|
+
await client.unlinkOAuth(provider);
|
|
147
|
+
}),
|
|
148
|
+
signOut: () => run(async () => {
|
|
149
|
+
await client.signOut();
|
|
150
|
+
}),
|
|
151
|
+
destroy() {
|
|
152
|
+
unsubscribeAuth();
|
|
153
|
+
listeners.clear();
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/svelte/auth-context.ts
|
|
159
|
+
var authContextKey = /* @__PURE__ */ Symbol("korajs-auth-context");
|
|
160
|
+
function initAuthProvider(client) {
|
|
161
|
+
const session = createAuthSession(client);
|
|
162
|
+
const value = {
|
|
163
|
+
client,
|
|
164
|
+
session,
|
|
165
|
+
get state() {
|
|
166
|
+
return session.getSnapshot().state;
|
|
167
|
+
},
|
|
168
|
+
get isLoading() {
|
|
169
|
+
return session.getSnapshot().isLoading;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
(0, import_svelte.setContext)(authContextKey, value);
|
|
173
|
+
return value;
|
|
174
|
+
}
|
|
175
|
+
function getAuthContext() {
|
|
176
|
+
const context = (0, import_svelte.getContext)(authContextKey);
|
|
177
|
+
if (!context) {
|
|
178
|
+
throw new Error(
|
|
179
|
+
"Auth context missing. Call initAuthProvider(client) in your root layout component."
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
return context;
|
|
183
|
+
}
|
|
184
|
+
function destroyAuthProvider(context) {
|
|
185
|
+
context.session.destroy();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// src/svelte/use-auth.ts
|
|
189
|
+
var import_store = require("svelte/store");
|
|
190
|
+
function createAuthStore() {
|
|
191
|
+
const { session } = getAuthContext();
|
|
192
|
+
return (0, import_store.readable)(buildResult(session), (set) => {
|
|
193
|
+
const sync = () => {
|
|
194
|
+
set(buildResult(session));
|
|
195
|
+
};
|
|
196
|
+
sync();
|
|
197
|
+
return session.subscribe(sync);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
var useAuth = createAuthStore;
|
|
201
|
+
function buildResult(session) {
|
|
202
|
+
const snapshot = session.getSnapshot();
|
|
203
|
+
return {
|
|
204
|
+
...snapshot,
|
|
205
|
+
signUp: (params) => session.signUp(params),
|
|
206
|
+
signIn: (params) => session.signIn(params),
|
|
207
|
+
signInWithOAuth: (provider, options) => session.signInWithOAuth(provider, options),
|
|
208
|
+
completeOAuthSignIn: (provider, params) => session.completeOAuthSignIn(provider, params),
|
|
209
|
+
getOAuthAuthorizationUrl: (provider, options) => session.getOAuthAuthorizationUrl(provider, options),
|
|
210
|
+
linkOAuth: (provider, params) => session.linkOAuth(provider, params),
|
|
211
|
+
listLinkedAccounts: () => session.listLinkedAccounts(),
|
|
212
|
+
unlinkOAuth: (provider) => session.unlinkOAuth(provider),
|
|
213
|
+
signOut: () => session.signOut()
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function createCurrentUserStore() {
|
|
217
|
+
const { session } = getAuthContext();
|
|
218
|
+
return (0, import_store.readable)(session.getSnapshot().user, (set) => {
|
|
219
|
+
const sync = () => {
|
|
220
|
+
set(session.getSnapshot().user);
|
|
221
|
+
};
|
|
222
|
+
sync();
|
|
223
|
+
return session.subscribe(sync);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
var useCurrentUser = createCurrentUserStore;
|
|
227
|
+
function createAuthStatusStore() {
|
|
228
|
+
const { session } = getAuthContext();
|
|
229
|
+
return (0, import_store.readable)(
|
|
230
|
+
{
|
|
231
|
+
state: session.getSnapshot().state,
|
|
232
|
+
isAuthenticated: session.getSnapshot().isAuthenticated,
|
|
233
|
+
isLoading: session.getSnapshot().isLoading
|
|
234
|
+
},
|
|
235
|
+
(set) => {
|
|
236
|
+
const sync = () => {
|
|
237
|
+
const snapshot = session.getSnapshot();
|
|
238
|
+
set({
|
|
239
|
+
state: snapshot.state,
|
|
240
|
+
isAuthenticated: snapshot.isAuthenticated,
|
|
241
|
+
isLoading: snapshot.isLoading
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
sync();
|
|
245
|
+
return session.subscribe(sync);
|
|
246
|
+
}
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
var useAuthStatus = createAuthStatusStore;
|
|
250
|
+
|
|
251
|
+
// src/svelte/org-context.ts
|
|
252
|
+
var import_svelte2 = require("svelte");
|
|
253
|
+
|
|
254
|
+
// src/bindings/create-org-session.ts
|
|
255
|
+
var ROLE_LEVELS = {
|
|
256
|
+
viewer: 10,
|
|
257
|
+
billing: 15,
|
|
258
|
+
member: 20,
|
|
259
|
+
admin: 30,
|
|
260
|
+
owner: 40
|
|
261
|
+
};
|
|
262
|
+
function checkOrgPermission(currentRole, requiredRole) {
|
|
263
|
+
if (!currentRole) return false;
|
|
264
|
+
const currentLevel = ROLE_LEVELS[currentRole] ?? 0;
|
|
265
|
+
const requiredLevel = ROLE_LEVELS[requiredRole] ?? 0;
|
|
266
|
+
return currentLevel >= requiredLevel;
|
|
267
|
+
}
|
|
268
|
+
function createOrgSession(client) {
|
|
269
|
+
let snapshot = buildSnapshot(client);
|
|
270
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
271
|
+
const notify = () => {
|
|
272
|
+
snapshot = buildSnapshot(client);
|
|
273
|
+
for (const listener of listeners) {
|
|
274
|
+
listener();
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
const unsubscribeOrgChange = client.onOrgChange(notify);
|
|
278
|
+
return {
|
|
279
|
+
client,
|
|
280
|
+
getSnapshot: () => snapshot,
|
|
281
|
+
subscribe(listener) {
|
|
282
|
+
listeners.add(listener);
|
|
283
|
+
return () => {
|
|
284
|
+
listeners.delete(listener);
|
|
285
|
+
};
|
|
286
|
+
},
|
|
287
|
+
checkPermission(requiredRole) {
|
|
288
|
+
return checkOrgPermission(snapshot.role, requiredRole);
|
|
289
|
+
},
|
|
290
|
+
destroy() {
|
|
291
|
+
unsubscribeOrgChange();
|
|
292
|
+
listeners.clear();
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
function buildSnapshot(client) {
|
|
297
|
+
return {
|
|
298
|
+
orgId: client.activeOrgId,
|
|
299
|
+
org: client.activeOrg,
|
|
300
|
+
role: client.activeRole
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
function createOrgMembersActions(client, orgId, onError) {
|
|
304
|
+
return {
|
|
305
|
+
async refresh() {
|
|
306
|
+
await client.listMembers(orgId);
|
|
307
|
+
},
|
|
308
|
+
async invite(email, role) {
|
|
309
|
+
try {
|
|
310
|
+
return await client.inviteMember(orgId, { email, role });
|
|
311
|
+
} catch (error) {
|
|
312
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
313
|
+
onError(message);
|
|
314
|
+
throw error;
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
async removeMember(userId) {
|
|
318
|
+
try {
|
|
319
|
+
await client.removeMember(orgId, userId);
|
|
320
|
+
} catch (error) {
|
|
321
|
+
onError(error instanceof Error ? error.message : String(error));
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
async updateRole(userId, role) {
|
|
325
|
+
try {
|
|
326
|
+
await client.updateMemberRole(orgId, userId, role);
|
|
327
|
+
} catch (error) {
|
|
328
|
+
onError(error instanceof Error ? error.message : String(error));
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
async function loadOrgMembers(client, orgId) {
|
|
334
|
+
return client.listMembers(orgId);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// src/svelte/org-context.ts
|
|
338
|
+
var orgContextKey = /* @__PURE__ */ Symbol("korajs-org-context");
|
|
339
|
+
function initOrgProvider(client) {
|
|
340
|
+
const session = createOrgSession(client);
|
|
341
|
+
const value = { client, session };
|
|
342
|
+
(0, import_svelte2.setContext)(orgContextKey, value);
|
|
343
|
+
return value;
|
|
344
|
+
}
|
|
345
|
+
function getOrgContext() {
|
|
346
|
+
const context = (0, import_svelte2.getContext)(orgContextKey);
|
|
347
|
+
if (!context) {
|
|
348
|
+
throw new Error(
|
|
349
|
+
"Org context missing. Wrap your app with <OrgProvider client={orgClient}> from @korajs/auth/svelte."
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
return context;
|
|
353
|
+
}
|
|
354
|
+
function destroyOrgProvider(context) {
|
|
355
|
+
context.session.destroy();
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// src/svelte/org-hooks.ts
|
|
359
|
+
var import_store2 = require("svelte/store");
|
|
360
|
+
function createOrgSnapshotStore() {
|
|
361
|
+
const { session } = getOrgContext();
|
|
362
|
+
return (0, import_store2.readable)(session.getSnapshot(), (set) => {
|
|
363
|
+
set(session.getSnapshot());
|
|
364
|
+
return session.subscribe(() => {
|
|
365
|
+
set(session.getSnapshot());
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
function useOrg() {
|
|
370
|
+
const { client, session } = getOrgContext();
|
|
371
|
+
const snapshotStore = createOrgSnapshotStore();
|
|
372
|
+
const error = (0, import_store2.writable)(null);
|
|
373
|
+
const store = (0, import_store2.derived)([snapshotStore, error], ([snapshot, errorValue]) => ({
|
|
374
|
+
...snapshot,
|
|
375
|
+
error: errorValue
|
|
376
|
+
}));
|
|
377
|
+
const switchOrg = async (orgId) => {
|
|
378
|
+
error.set(null);
|
|
379
|
+
try {
|
|
380
|
+
await client.switchOrg(orgId);
|
|
381
|
+
} catch (err) {
|
|
382
|
+
error.set(err instanceof Error ? err.message : String(err));
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
const createOrg = async (params) => {
|
|
386
|
+
error.set(null);
|
|
387
|
+
try {
|
|
388
|
+
return await client.createOrg(params);
|
|
389
|
+
} catch (err) {
|
|
390
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
391
|
+
error.set(message);
|
|
392
|
+
throw err;
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
const leaveOrg = async () => {
|
|
396
|
+
const orgId = (0, import_store2.get)(snapshotStore).orgId;
|
|
397
|
+
if (!orgId) return;
|
|
398
|
+
error.set(null);
|
|
399
|
+
try {
|
|
400
|
+
await client.leaveOrg(orgId);
|
|
401
|
+
} catch (err) {
|
|
402
|
+
error.set(err instanceof Error ? err.message : String(err));
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
const clearOrg = () => {
|
|
406
|
+
client.clearActiveOrg();
|
|
407
|
+
};
|
|
408
|
+
const listOrgs = async () => {
|
|
409
|
+
try {
|
|
410
|
+
return await client.listOrgs();
|
|
411
|
+
} catch (err) {
|
|
412
|
+
error.set(err instanceof Error ? err.message : String(err));
|
|
413
|
+
return [];
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
return {
|
|
417
|
+
subscribe: store.subscribe,
|
|
418
|
+
get org() {
|
|
419
|
+
return (0, import_store2.get)(snapshotStore).org;
|
|
420
|
+
},
|
|
421
|
+
get role() {
|
|
422
|
+
return (0, import_store2.get)(snapshotStore).role;
|
|
423
|
+
},
|
|
424
|
+
get orgId() {
|
|
425
|
+
return (0, import_store2.get)(snapshotStore).orgId;
|
|
426
|
+
},
|
|
427
|
+
switchOrg,
|
|
428
|
+
createOrg,
|
|
429
|
+
leaveOrg,
|
|
430
|
+
clearOrg,
|
|
431
|
+
listOrgs
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
function useOrgMembers(orgId) {
|
|
435
|
+
const { client } = getOrgContext();
|
|
436
|
+
const members = (0, import_store2.writable)([]);
|
|
437
|
+
const isLoading = (0, import_store2.writable)(true);
|
|
438
|
+
const error = (0, import_store2.writable)(null);
|
|
439
|
+
const refresh = async (targetOrgId) => {
|
|
440
|
+
isLoading.set(true);
|
|
441
|
+
error.set(null);
|
|
442
|
+
try {
|
|
443
|
+
members.set(await loadOrgMembers(client, targetOrgId));
|
|
444
|
+
} catch (err) {
|
|
445
|
+
error.set(err instanceof Error ? err.message : String(err));
|
|
446
|
+
} finally {
|
|
447
|
+
isLoading.set(false);
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
$effect(() => {
|
|
451
|
+
void refresh(orgId);
|
|
452
|
+
});
|
|
453
|
+
const actions = createOrgMembersActions(client, orgId, (message) => {
|
|
454
|
+
error.set(message);
|
|
455
|
+
});
|
|
456
|
+
const invite = async (email, role) => {
|
|
457
|
+
const result = await actions.invite(email, role);
|
|
458
|
+
await refresh(orgId);
|
|
459
|
+
return result;
|
|
460
|
+
};
|
|
461
|
+
const removeMember = async (userId) => {
|
|
462
|
+
await actions.removeMember(userId);
|
|
463
|
+
await refresh(orgId);
|
|
464
|
+
};
|
|
465
|
+
const updateRole = async (userId, role) => {
|
|
466
|
+
await actions.updateRole(userId, role);
|
|
467
|
+
await refresh(orgId);
|
|
468
|
+
};
|
|
469
|
+
const store = (0, import_store2.derived)([members, isLoading, error], ([memberList, loading, errorValue]) => ({
|
|
470
|
+
members: memberList,
|
|
471
|
+
isLoading: loading,
|
|
472
|
+
error: errorValue
|
|
473
|
+
}));
|
|
474
|
+
return {
|
|
475
|
+
subscribe: store.subscribe,
|
|
476
|
+
refresh: () => refresh(orgId),
|
|
477
|
+
invite,
|
|
478
|
+
removeMember,
|
|
479
|
+
updateRole
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
function createPermissionStore(requiredRole) {
|
|
483
|
+
const { session } = getOrgContext();
|
|
484
|
+
return (0, import_store2.readable)(session.checkPermission(requiredRole), (set) => {
|
|
485
|
+
set(session.checkPermission(requiredRole));
|
|
486
|
+
return session.subscribe(() => {
|
|
487
|
+
set(session.checkPermission(requiredRole));
|
|
488
|
+
});
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
var usePermission = createPermissionStore;
|
|
492
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
493
|
+
0 && (module.exports = {
|
|
494
|
+
checkOrgPermission,
|
|
495
|
+
createAuthStatusStore,
|
|
496
|
+
createAuthStore,
|
|
497
|
+
createCurrentUserStore,
|
|
498
|
+
createPermissionStore,
|
|
499
|
+
destroyAuthProvider,
|
|
500
|
+
destroyOrgProvider,
|
|
501
|
+
getAuthContext,
|
|
502
|
+
getOrgContext,
|
|
503
|
+
initAuthProvider,
|
|
504
|
+
initOrgProvider,
|
|
505
|
+
useAuth,
|
|
506
|
+
useAuthStatus,
|
|
507
|
+
useCurrentUser,
|
|
508
|
+
useOrg,
|
|
509
|
+
useOrgMembers,
|
|
510
|
+
usePermission
|
|
511
|
+
});
|
|
512
|
+
//# sourceMappingURL=svelte.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/svelte.ts","../src/svelte/auth-context.ts","../src/bindings/create-auth-session.ts","../src/svelte/use-auth.ts","../src/svelte/org-context.ts","../src/bindings/create-org-session.ts","../src/svelte/org-hooks.ts"],"sourcesContent":["export {\n\tdestroyAuthProvider,\n\tgetAuthContext,\n\tinitAuthProvider,\n} from './svelte/auth-context'\nexport type { AuthContextValue } from './svelte/auth-context'\nexport {\n\tcreateAuthStore,\n\tcreateAuthStatusStore,\n\tcreateCurrentUserStore,\n\tuseAuth,\n\tuseAuthStatus,\n\tuseCurrentUser,\n} from './svelte/use-auth'\nexport type { UseAuthResult } from './svelte/use-auth'\nexport { destroyOrgProvider, getOrgContext, initOrgProvider } from './svelte/org-context'\nexport type { OrgContextValue } from './svelte/org-context'\nexport {\n\tcreatePermissionStore,\n\tuseOrg,\n\tuseOrgMembers,\n\tusePermission,\n\tcheckOrgPermission,\n} from './svelte/org-hooks'\nexport type { UseOrgResult, UseOrgMembersResult } from './svelte/org-hooks'\n","import { getContext, setContext } from 'svelte'\nimport { type AuthSession, createAuthSession } from '../bindings/create-auth-session'\nimport type { AuthClient, AuthState } from '../client/auth-client'\n\nconst authContextKey = Symbol('korajs-auth-context')\n\nexport interface AuthContextValue {\n\tclient: AuthClient\n\tsession: AuthSession\n\tget state(): AuthState\n\tget isLoading(): boolean\n}\n\n/**\n * Initialize auth context inside a Svelte component (root layout).\n * Must be called during component initialization before children render.\n */\nexport function initAuthProvider(client: AuthClient): AuthContextValue {\n\tconst session = createAuthSession(client)\n\n\tconst value: AuthContextValue = {\n\t\tclient,\n\t\tsession,\n\t\tget state() {\n\t\t\treturn session.getSnapshot().state\n\t\t},\n\t\tget isLoading() {\n\t\t\treturn session.getSnapshot().isLoading\n\t\t},\n\t}\n\n\tsetContext(authContextKey, value)\n\treturn value\n}\n\nexport function getAuthContext(): AuthContextValue {\n\tconst context = getContext<AuthContextValue | undefined>(authContextKey)\n\tif (!context) {\n\t\tthrow new Error(\n\t\t\t'Auth context missing. Call initAuthProvider(client) in your root layout component.',\n\t\t)\n\t}\n\treturn context\n}\n\nexport function destroyAuthProvider(context: AuthContextValue): void {\n\tcontext.session.destroy()\n}\n","import type {\n\tAuthClient,\n\tAuthState,\n\tAuthUser,\n\tLinkedOAuthAccount,\n\tOAuthAuthorizationOptions,\n\tOAuthAuthorizationResult,\n\tOAuthCallbackParams,\n} from '../client/auth-client'\n\nexport interface AuthSessionSnapshot {\n\tstate: AuthState\n\tuser: AuthUser | null\n\tisAuthenticated: boolean\n\tisLoading: boolean\n\tinitError: Error | null\n\terror: string | null\n}\n\nexport interface AuthSession {\n\treadonly client: AuthClient\n\tgetSnapshot(): AuthSessionSnapshot\n\tsubscribe(listener: () => void): () => void\n\tsignUp(params: {\n\t\temail: string\n\t\tpassword: string\n\t\tname?: string\n\t\tdeviceId?: string\n\t\tdevicePublicKey?: string\n\t}): Promise<void>\n\tsignIn(params: {\n\t\temail: string\n\t\tpassword: string\n\t\tdeviceId?: string\n\t\tdevicePublicKey?: string\n\t}): Promise<void>\n\tsignInWithOAuth(\n\t\tprovider: string,\n\t\toptions?: OAuthAuthorizationOptions,\n\t): Promise<OAuthAuthorizationResult>\n\tcompleteOAuthSignIn(provider: string, params: OAuthCallbackParams): Promise<void>\n\tgetOAuthAuthorizationUrl(\n\t\tprovider: string,\n\t\toptions?: OAuthAuthorizationOptions,\n\t): Promise<OAuthAuthorizationResult>\n\tlinkOAuth(provider: string, params: OAuthCallbackParams): Promise<LinkedOAuthAccount | null>\n\tlistLinkedAccounts(): Promise<LinkedOAuthAccount[]>\n\tunlinkOAuth(provider: string): Promise<void>\n\tsignOut(): Promise<void>\n\tdestroy(): void\n}\n\n/**\n * Framework-agnostic auth session: initialization, reactive snapshot, and client methods.\n */\nexport function createAuthSession(client: AuthClient): AuthSession {\n\tlet state: AuthState = client.state\n\tlet isLoading = true\n\tlet initError: Error | null = null\n\tlet lastError: string | null = null\n\n\tconst listeners = new Set<() => void>()\n\tlet snapshot = buildSnapshot()\n\n\tconst refreshSnapshot = (): void => {\n\t\tsnapshot = buildSnapshot()\n\t}\n\n\tconst notify = (): void => {\n\t\trefreshSnapshot()\n\t\tfor (const listener of listeners) {\n\t\t\tlistener()\n\t\t}\n\t}\n\n\tfunction buildSnapshot(): AuthSessionSnapshot {\n\t\treturn {\n\t\t\tstate,\n\t\t\tuser: client.currentUser,\n\t\t\tisAuthenticated: state === 'authenticated',\n\t\t\tisLoading,\n\t\t\tinitError,\n\t\t\terror: lastError,\n\t\t}\n\t}\n\n\tconst captureError = (error: unknown): void => {\n\t\tlastError = error instanceof Error ? error.message : String(error)\n\t\tnotify()\n\t}\n\n\tconst run = async (action: () => Promise<void>): Promise<void> => {\n\t\tlastError = null\n\t\ttry {\n\t\t\tawait action()\n\t\t} catch (error) {\n\t\t\tcaptureError(error)\n\t\t}\n\t}\n\n\tconst runWithResult = async <T>(action: () => Promise<T>): Promise<T | null> => {\n\t\tlastError = null\n\t\ttry {\n\t\t\treturn await action()\n\t\t} catch (error) {\n\t\t\tcaptureError(error)\n\t\t\treturn null\n\t\t}\n\t}\n\n\tconst unsubscribeAuth = client.onAuthChange((nextState) => {\n\t\tstate = nextState\n\t\tnotify()\n\t})\n\n\tvoid client\n\t\t.initialize()\n\t\t.then(() => {\n\t\t\tstate = client.state\n\t\t\tisLoading = false\n\t\t\tnotify()\n\t\t})\n\t\t.catch((error: unknown) => {\n\t\t\tinitError = error instanceof Error ? error : new Error(String(error))\n\t\t\tisLoading = false\n\t\t\tnotify()\n\t\t})\n\n\treturn {\n\t\tclient,\n\t\tgetSnapshot: () => snapshot,\n\t\tsubscribe(listener) {\n\t\t\tlisteners.add(listener)\n\t\t\treturn () => {\n\t\t\t\tlisteners.delete(listener)\n\t\t\t}\n\t\t},\n\t\tsignUp: (params) =>\n\t\t\trun(async () => {\n\t\t\t\tawait client.signUp(params)\n\t\t\t}),\n\t\tsignIn: (params) =>\n\t\t\trun(async () => {\n\t\t\t\tawait client.signIn(params)\n\t\t\t}),\n\t\tsignInWithOAuth: async (provider, options) => {\n\t\t\tlastError = null\n\t\t\ttry {\n\t\t\t\treturn await client.signInWithOAuth(provider, options)\n\t\t\t} catch (error) {\n\t\t\t\tcaptureError(error)\n\t\t\t\tthrow error instanceof Error ? error : new Error(String(error))\n\t\t\t}\n\t\t},\n\t\tcompleteOAuthSignIn: (provider, params) =>\n\t\t\trun(async () => {\n\t\t\t\tawait client.completeOAuthSignIn(provider, params)\n\t\t\t}),\n\t\tgetOAuthAuthorizationUrl: async (provider, options) => {\n\t\t\tlastError = null\n\t\t\ttry {\n\t\t\t\treturn await client.getOAuthAuthorizationUrl(provider, options)\n\t\t\t} catch (error) {\n\t\t\t\tcaptureError(error)\n\t\t\t\tthrow error instanceof Error ? error : new Error(String(error))\n\t\t\t}\n\t\t},\n\t\tlinkOAuth: (provider, params) => runWithResult(async () => client.linkOAuth(provider, params)),\n\t\tlistLinkedAccounts: () =>\n\t\t\trunWithResult(async () => client.listLinkedAccounts()).then((value) => value ?? []),\n\t\tunlinkOAuth: (provider) =>\n\t\t\trun(async () => {\n\t\t\t\tawait client.unlinkOAuth(provider)\n\t\t\t}),\n\t\tsignOut: () =>\n\t\t\trun(async () => {\n\t\t\t\tawait client.signOut()\n\t\t\t}),\n\t\tdestroy() {\n\t\t\tunsubscribeAuth()\n\t\t\tlisteners.clear()\n\t\t},\n\t}\n}\n","import { type Readable, readable } from 'svelte/store'\nimport type { AuthSessionSnapshot } from '../bindings/create-auth-session'\nimport type {\n\tAuthUser,\n\tLinkedOAuthAccount,\n\tOAuthAuthorizationOptions,\n\tOAuthAuthorizationResult,\n\tOAuthCallbackParams,\n} from '../client/auth-client'\nimport { getAuthContext } from './auth-context'\n\nexport interface UseAuthResult extends AuthSessionSnapshot {\n\tsignUp: (params: {\n\t\temail: string\n\t\tpassword: string\n\t\tname?: string\n\t\tdeviceId?: string\n\t\tdevicePublicKey?: string\n\t}) => Promise<void>\n\tsignIn: (params: {\n\t\temail: string\n\t\tpassword: string\n\t\tdeviceId?: string\n\t\tdevicePublicKey?: string\n\t}) => Promise<void>\n\tsignInWithOAuth: (\n\t\tprovider: string,\n\t\toptions?: OAuthAuthorizationOptions,\n\t) => Promise<OAuthAuthorizationResult>\n\tcompleteOAuthSignIn: (provider: string, params: OAuthCallbackParams) => Promise<void>\n\tgetOAuthAuthorizationUrl: (\n\t\tprovider: string,\n\t\toptions?: OAuthAuthorizationOptions,\n\t) => Promise<OAuthAuthorizationResult>\n\tlinkOAuth: (provider: string, params: OAuthCallbackParams) => Promise<LinkedOAuthAccount | null>\n\tlistLinkedAccounts: () => Promise<LinkedOAuthAccount[]>\n\tunlinkOAuth: (provider: string) => Promise<void>\n\tsignOut: () => Promise<void>\n}\n\nexport function createAuthStore(): Readable<UseAuthResult> {\n\tconst { session } = getAuthContext()\n\n\treturn readable<UseAuthResult>(buildResult(session), (set) => {\n\t\tconst sync = (): void => {\n\t\t\tset(buildResult(session))\n\t\t}\n\t\tsync()\n\t\treturn session.subscribe(sync)\n\t})\n}\n\n/** @alias createAuthStore */\nexport const useAuth = createAuthStore\n\nfunction buildResult(session: ReturnType<typeof getAuthContext>['session']): UseAuthResult {\n\tconst snapshot = session.getSnapshot()\n\treturn {\n\t\t...snapshot,\n\t\tsignUp: (params) => session.signUp(params),\n\t\tsignIn: (params) => session.signIn(params),\n\t\tsignInWithOAuth: (provider, options) => session.signInWithOAuth(provider, options),\n\t\tcompleteOAuthSignIn: (provider, params) => session.completeOAuthSignIn(provider, params),\n\t\tgetOAuthAuthorizationUrl: (provider, options) =>\n\t\t\tsession.getOAuthAuthorizationUrl(provider, options),\n\t\tlinkOAuth: (provider, params) => session.linkOAuth(provider, params),\n\t\tlistLinkedAccounts: () => session.listLinkedAccounts(),\n\t\tunlinkOAuth: (provider) => session.unlinkOAuth(provider),\n\t\tsignOut: () => session.signOut(),\n\t}\n}\n\nexport function createCurrentUserStore(): Readable<AuthUser | null> {\n\tconst { session } = getAuthContext()\n\treturn readable<AuthUser | null>(session.getSnapshot().user, (set) => {\n\t\tconst sync = (): void => {\n\t\t\tset(session.getSnapshot().user)\n\t\t}\n\t\tsync()\n\t\treturn session.subscribe(sync)\n\t})\n}\n\n/** @alias createCurrentUserStore */\nexport const useCurrentUser = createCurrentUserStore\n\nexport function createAuthStatusStore(): Readable<{\n\tstate: AuthSessionSnapshot['state']\n\tisAuthenticated: boolean\n\tisLoading: boolean\n}> {\n\tconst { session } = getAuthContext()\n\treturn readable(\n\t\t{\n\t\t\tstate: session.getSnapshot().state,\n\t\t\tisAuthenticated: session.getSnapshot().isAuthenticated,\n\t\t\tisLoading: session.getSnapshot().isLoading,\n\t\t},\n\t\t(set) => {\n\t\t\tconst sync = (): void => {\n\t\t\t\tconst snapshot = session.getSnapshot()\n\t\t\t\tset({\n\t\t\t\t\tstate: snapshot.state,\n\t\t\t\t\tisAuthenticated: snapshot.isAuthenticated,\n\t\t\t\t\tisLoading: snapshot.isLoading,\n\t\t\t\t})\n\t\t\t}\n\t\t\tsync()\n\t\t\treturn session.subscribe(sync)\n\t\t},\n\t)\n}\n\n/** @alias createAuthStatusStore */\nexport const useAuthStatus = createAuthStatusStore\n","import { getContext, setContext } from 'svelte'\nimport { type OrgSession, createOrgSession } from '../bindings/create-org-session'\nimport type { OrgClient } from '../client/org-client'\n\nconst orgContextKey = Symbol('korajs-org-context')\n\nexport interface OrgContextValue {\n\tclient: OrgClient\n\tsession: OrgSession\n}\n\nexport function initOrgProvider(client: OrgClient): OrgContextValue {\n\tconst session = createOrgSession(client)\n\tconst value: OrgContextValue = { client, session }\n\tsetContext(orgContextKey, value)\n\treturn value\n}\n\nexport function getOrgContext(): OrgContextValue {\n\tconst context = getContext<OrgContextValue | undefined>(orgContextKey)\n\tif (!context) {\n\t\tthrow new Error(\n\t\t\t'Org context missing. Wrap your app with <OrgProvider client={orgClient}> from @korajs/auth/svelte.',\n\t\t)\n\t}\n\treturn context\n}\n\nexport function destroyOrgProvider(context: OrgContextValue): void {\n\tcontext.session.destroy()\n}\n","import type {\n\tClientInvitation,\n\tClientMembership,\n\tClientOrganization,\n\tOrgClient,\n} from '../client/org-client'\n\nexport interface OrgSnapshot {\n\torgId: string | null\n\torg: ClientOrganization | null\n\trole: string | null\n}\n\nexport interface OrgSession {\n\treadonly client: OrgClient\n\tgetSnapshot(): OrgSnapshot\n\tsubscribe(listener: () => void): () => void\n\tcheckPermission(requiredRole: string): boolean\n\tdestroy(): void\n}\n\nconst ROLE_LEVELS: Record<string, number> = {\n\tviewer: 10,\n\tbilling: 15,\n\tmember: 20,\n\tadmin: 30,\n\towner: 40,\n}\n\nexport function checkOrgPermission(currentRole: string | null, requiredRole: string): boolean {\n\tif (!currentRole) return false\n\tconst currentLevel = ROLE_LEVELS[currentRole] ?? 0\n\tconst requiredLevel = ROLE_LEVELS[requiredRole] ?? 0\n\treturn currentLevel >= requiredLevel\n}\n\n/**\n * Framework-agnostic org session with reactive snapshot subscription.\n */\nexport function createOrgSession(client: OrgClient): OrgSession {\n\tlet snapshot = buildSnapshot(client)\n\tconst listeners = new Set<() => void>()\n\n\tconst notify = (): void => {\n\t\tsnapshot = buildSnapshot(client)\n\t\tfor (const listener of listeners) {\n\t\t\tlistener()\n\t\t}\n\t}\n\n\tconst unsubscribeOrgChange = client.onOrgChange(notify)\n\n\treturn {\n\t\tclient,\n\t\tgetSnapshot: () => snapshot,\n\t\tsubscribe(listener: () => void): () => void {\n\t\t\tlisteners.add(listener)\n\t\t\treturn () => {\n\t\t\t\tlisteners.delete(listener)\n\t\t\t}\n\t\t},\n\t\tcheckPermission(requiredRole: string): boolean {\n\t\t\treturn checkOrgPermission(snapshot.role, requiredRole)\n\t\t},\n\t\tdestroy(): void {\n\t\t\tunsubscribeOrgChange()\n\t\t\tlisteners.clear()\n\t\t},\n\t}\n}\n\nfunction buildSnapshot(client: OrgClient): OrgSnapshot {\n\treturn {\n\t\torgId: client.activeOrgId,\n\t\torg: client.activeOrg,\n\t\trole: client.activeRole,\n\t}\n}\n\nexport interface UseOrgMembersActions {\n\trefresh: () => Promise<void>\n\tinvite: (email: string, role: string) => Promise<ClientInvitation>\n\tremoveMember: (userId: string) => Promise<void>\n\tupdateRole: (userId: string, role: string) => Promise<void>\n}\n\n/**\n * Shared org member management actions (loading state remains framework-specific).\n */\nexport function createOrgMembersActions(\n\tclient: OrgClient,\n\torgId: string,\n\tonError: (message: string) => void,\n): UseOrgMembersActions {\n\treturn {\n\t\tasync refresh(): Promise<void> {\n\t\t\tawait client.listMembers(orgId)\n\t\t},\n\t\tasync invite(email: string, role: string): Promise<ClientInvitation> {\n\t\t\ttry {\n\t\t\t\treturn await client.inviteMember(orgId, { email, role })\n\t\t\t} catch (error) {\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error)\n\t\t\t\tonError(message)\n\t\t\t\tthrow error\n\t\t\t}\n\t\t},\n\t\tasync removeMember(userId: string): Promise<void> {\n\t\t\ttry {\n\t\t\t\tawait client.removeMember(orgId, userId)\n\t\t\t} catch (error) {\n\t\t\t\tonError(error instanceof Error ? error.message : String(error))\n\t\t\t}\n\t\t},\n\t\tasync updateRole(userId: string, role: string): Promise<void> {\n\t\t\ttry {\n\t\t\t\tawait client.updateMemberRole(orgId, userId, role)\n\t\t\t} catch (error) {\n\t\t\t\tonError(error instanceof Error ? error.message : String(error))\n\t\t\t}\n\t\t},\n\t}\n}\n\nexport async function loadOrgMembers(\n\tclient: OrgClient,\n\torgId: string,\n): Promise<ClientMembership[]> {\n\treturn client.listMembers(orgId)\n}\n","import { type Readable, derived, get, readable, writable } from 'svelte/store'\nimport {\n\tcheckOrgPermission,\n\tcreateOrgMembersActions,\n\tloadOrgMembers,\n} from '../bindings/create-org-session'\nimport type { ClientInvitation, ClientMembership, ClientOrganization } from '../client/org-client'\nimport { getOrgContext } from './org-context'\n\nexport interface UseOrgResult {\n\tsubscribe: Readable<{\n\t\torg: ClientOrganization | null\n\t\trole: string | null\n\t\torgId: string | null\n\t\terror: string | null\n\t}>['subscribe']\n\tget org(): ClientOrganization | null\n\tget role(): string | null\n\tget orgId(): string | null\n\tswitchOrg: (orgId: string) => Promise<void>\n\tcreateOrg: (params: { name: string; slug?: string }) => Promise<ClientOrganization>\n\tleaveOrg: () => Promise<void>\n\tclearOrg: () => void\n\tlistOrgs: () => Promise<ClientOrganization[]>\n}\n\nexport interface UseOrgMembersResult {\n\tsubscribe: Readable<{\n\t\tmembers: ClientMembership[]\n\t\tisLoading: boolean\n\t\terror: string | null\n\t}>['subscribe']\n\trefresh: () => Promise<void>\n\tinvite: (email: string, role: string) => Promise<ClientInvitation>\n\tremoveMember: (userId: string) => Promise<void>\n\tupdateRole: (userId: string, role: string) => Promise<void>\n}\n\nfunction createOrgSnapshotStore(): Readable<{\n\torg: ClientOrganization | null\n\trole: string | null\n\torgId: string | null\n}> {\n\tconst { session } = getOrgContext()\n\n\treturn readable(session.getSnapshot(), (set) => {\n\t\tset(session.getSnapshot())\n\t\treturn session.subscribe(() => {\n\t\t\tset(session.getSnapshot())\n\t\t})\n\t})\n}\n\nexport function useOrg(): UseOrgResult {\n\tconst { client, session } = getOrgContext()\n\tconst snapshotStore = createOrgSnapshotStore()\n\tconst error = writable<string | null>(null)\n\n\tconst store = derived([snapshotStore, error], ([snapshot, errorValue]) => ({\n\t\t...snapshot,\n\t\terror: errorValue,\n\t}))\n\n\tconst switchOrg = async (orgId: string): Promise<void> => {\n\t\terror.set(null)\n\t\ttry {\n\t\t\tawait client.switchOrg(orgId)\n\t\t} catch (err) {\n\t\t\terror.set(err instanceof Error ? err.message : String(err))\n\t\t}\n\t}\n\n\tconst createOrg = async (params: {\n\t\tname: string\n\t\tslug?: string\n\t}): Promise<ClientOrganization> => {\n\t\terror.set(null)\n\t\ttry {\n\t\t\treturn await client.createOrg(params)\n\t\t} catch (err) {\n\t\t\tconst message = err instanceof Error ? err.message : String(err)\n\t\t\terror.set(message)\n\t\t\tthrow err\n\t\t}\n\t}\n\n\tconst leaveOrg = async (): Promise<void> => {\n\t\tconst orgId = get(snapshotStore).orgId\n\t\tif (!orgId) return\n\t\terror.set(null)\n\t\ttry {\n\t\t\tawait client.leaveOrg(orgId)\n\t\t} catch (err) {\n\t\t\terror.set(err instanceof Error ? err.message : String(err))\n\t\t}\n\t}\n\n\tconst clearOrg = (): void => {\n\t\tclient.clearActiveOrg()\n\t}\n\n\tconst listOrgs = async (): Promise<ClientOrganization[]> => {\n\t\ttry {\n\t\t\treturn await client.listOrgs()\n\t\t} catch (err) {\n\t\t\terror.set(err instanceof Error ? err.message : String(err))\n\t\t\treturn []\n\t\t}\n\t}\n\n\treturn {\n\t\tsubscribe: store.subscribe,\n\t\tget org() {\n\t\t\treturn get(snapshotStore).org\n\t\t},\n\t\tget role() {\n\t\t\treturn get(snapshotStore).role\n\t\t},\n\t\tget orgId() {\n\t\t\treturn get(snapshotStore).orgId\n\t\t},\n\t\tswitchOrg,\n\t\tcreateOrg,\n\t\tleaveOrg,\n\t\tclearOrg,\n\t\tlistOrgs,\n\t}\n}\n\nexport function useOrgMembers(orgId: string): UseOrgMembersResult {\n\tconst { client } = getOrgContext()\n\tconst members = writable<ClientMembership[]>([])\n\tconst isLoading = writable(true)\n\tconst error = writable<string | null>(null)\n\n\tconst refresh = async (targetOrgId: string): Promise<void> => {\n\t\tisLoading.set(true)\n\t\terror.set(null)\n\t\ttry {\n\t\t\tmembers.set(await loadOrgMembers(client, targetOrgId))\n\t\t} catch (err) {\n\t\t\terror.set(err instanceof Error ? err.message : String(err))\n\t\t} finally {\n\t\t\tisLoading.set(false)\n\t\t}\n\t}\n\n\t$effect(() => {\n\t\tvoid refresh(orgId)\n\t})\n\n\tconst actions = createOrgMembersActions(client, orgId, (message) => {\n\t\terror.set(message)\n\t})\n\n\tconst invite = async (email: string, role: string): Promise<ClientInvitation> => {\n\t\tconst result = await actions.invite(email, role)\n\t\tawait refresh(orgId)\n\t\treturn result\n\t}\n\n\tconst removeMember = async (userId: string): Promise<void> => {\n\t\tawait actions.removeMember(userId)\n\t\tawait refresh(orgId)\n\t}\n\n\tconst updateRole = async (userId: string, role: string): Promise<void> => {\n\t\tawait actions.updateRole(userId, role)\n\t\tawait refresh(orgId)\n\t}\n\n\tconst store = derived([members, isLoading, error], ([memberList, loading, errorValue]) => ({\n\t\tmembers: memberList,\n\t\tisLoading: loading,\n\t\terror: errorValue,\n\t}))\n\n\treturn {\n\t\tsubscribe: store.subscribe,\n\t\trefresh: () => refresh(orgId),\n\t\tinvite,\n\t\tremoveMember,\n\t\tupdateRole,\n\t}\n}\n\nexport function createPermissionStore(requiredRole: string): Readable<boolean> {\n\tconst { session } = getOrgContext()\n\n\treturn readable(session.checkPermission(requiredRole), (set) => {\n\t\tset(session.checkPermission(requiredRole))\n\t\treturn session.subscribe(() => {\n\t\t\tset(session.checkPermission(requiredRole))\n\t\t})\n\t})\n}\n\n/** Alias for {@link createPermissionStore}. */\nexport const usePermission = createPermissionStore\n\nexport { checkOrgPermission }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAuC;;;ACuDhC,SAAS,kBAAkB,QAAiC;AAClE,MAAI,QAAmB,OAAO;AAC9B,MAAI,YAAY;AAChB,MAAI,YAA0B;AAC9B,MAAI,YAA2B;AAE/B,QAAM,YAAY,oBAAI,IAAgB;AACtC,MAAI,WAAWA,eAAc;AAE7B,QAAM,kBAAkB,MAAY;AACnC,eAAWA,eAAc;AAAA,EAC1B;AAEA,QAAM,S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GAAG,CAAC,QAAQ;AAC/D,QAAI,QAAQ,gBAAgB,YAAY,CAAC;AACzC,WAAO,QAAQ,UAAU,MAAM;AAC9B,UAAI,QAAQ,gBAAgB,YAAY,CAAC;AAAA,IAC1C,CAAC;AAAA,EACF,CAAC;AACF;AAGO,IAAM,gBAAgB;","names":["buildSnapshot","import_svelte","import_store"]}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { d as AuthClient, i as AuthSession, e as AuthState, j as AuthSessionSnapshot, O as OAuthAuthorizationOptions, q as OAuthAuthorizationResult, r as OAuthCallbackParams, L as LinkedOAuthAccount, l as AuthUser, s as OrgClient, v as OrgSession, m as ClientMembership, C as ClientInvitation, n as ClientOrganization } from './create-org-session-RsDj9cl4.cjs';
|
|
2
|
+
export { x as checkOrgPermission } from './create-org-session-RsDj9cl4.cjs';
|
|
3
|
+
import { Readable } from 'svelte/store';
|
|
4
|
+
import '@korajs/core';
|
|
5
|
+
|
|
6
|
+
interface AuthContextValue {
|
|
7
|
+
client: AuthClient;
|
|
8
|
+
session: AuthSession;
|
|
9
|
+
get state(): AuthState;
|
|
10
|
+
get isLoading(): boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Initialize auth context inside a Svelte component (root layout).
|
|
14
|
+
* Must be called during component initialization before children render.
|
|
15
|
+
*/
|
|
16
|
+
declare function initAuthProvider(client: AuthClient): AuthContextValue;
|
|
17
|
+
declare function getAuthContext(): AuthContextValue;
|
|
18
|
+
declare function destroyAuthProvider(context: AuthContextValue): void;
|
|
19
|
+
|
|
20
|
+
interface UseAuthResult extends AuthSessionSnapshot {
|
|
21
|
+
signUp: (params: {
|
|
22
|
+
email: string;
|
|
23
|
+
password: string;
|
|
24
|
+
name?: string;
|
|
25
|
+
deviceId?: string;
|
|
26
|
+
devicePublicKey?: string;
|
|
27
|
+
}) => Promise<void>;
|
|
28
|
+
signIn: (params: {
|
|
29
|
+
email: string;
|
|
30
|
+
password: string;
|
|
31
|
+
deviceId?: string;
|
|
32
|
+
devicePublicKey?: string;
|
|
33
|
+
}) => Promise<void>;
|
|
34
|
+
signInWithOAuth: (provider: string, options?: OAuthAuthorizationOptions) => Promise<OAuthAuthorizationResult>;
|
|
35
|
+
completeOAuthSignIn: (provider: string, params: OAuthCallbackParams) => Promise<void>;
|
|
36
|
+
getOAuthAuthorizationUrl: (provider: string, options?: OAuthAuthorizationOptions) => Promise<OAuthAuthorizationResult>;
|
|
37
|
+
linkOAuth: (provider: string, params: OAuthCallbackParams) => Promise<LinkedOAuthAccount | null>;
|
|
38
|
+
listLinkedAccounts: () => Promise<LinkedOAuthAccount[]>;
|
|
39
|
+
unlinkOAuth: (provider: string) => Promise<void>;
|
|
40
|
+
signOut: () => Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
declare function createAuthStore(): Readable<UseAuthResult>;
|
|
43
|
+
/** @alias createAuthStore */
|
|
44
|
+
declare const useAuth: typeof createAuthStore;
|
|
45
|
+
declare function createCurrentUserStore(): Readable<AuthUser | null>;
|
|
46
|
+
/** @alias createCurrentUserStore */
|
|
47
|
+
declare const useCurrentUser: typeof createCurrentUserStore;
|
|
48
|
+
declare function createAuthStatusStore(): Readable<{
|
|
49
|
+
state: AuthSessionSnapshot['state'];
|
|
50
|
+
isAuthenticated: boolean;
|
|
51
|
+
isLoading: boolean;
|
|
52
|
+
}>;
|
|
53
|
+
/** @alias createAuthStatusStore */
|
|
54
|
+
declare const useAuthStatus: typeof createAuthStatusStore;
|
|
55
|
+
|
|
56
|
+
interface OrgContextValue {
|
|
57
|
+
client: OrgClient;
|
|
58
|
+
session: OrgSession;
|
|
59
|
+
}
|
|
60
|
+
declare function initOrgProvider(client: OrgClient): OrgContextValue;
|
|
61
|
+
declare function getOrgContext(): OrgContextValue;
|
|
62
|
+
declare function destroyOrgProvider(context: OrgContextValue): void;
|
|
63
|
+
|
|
64
|
+
interface UseOrgResult {
|
|
65
|
+
subscribe: Readable<{
|
|
66
|
+
org: ClientOrganization | null;
|
|
67
|
+
role: string | null;
|
|
68
|
+
orgId: string | null;
|
|
69
|
+
error: string | null;
|
|
70
|
+
}>['subscribe'];
|
|
71
|
+
get org(): ClientOrganization | null;
|
|
72
|
+
get role(): string | null;
|
|
73
|
+
get orgId(): string | null;
|
|
74
|
+
switchOrg: (orgId: string) => Promise<void>;
|
|
75
|
+
createOrg: (params: {
|
|
76
|
+
name: string;
|
|
77
|
+
slug?: string;
|
|
78
|
+
}) => Promise<ClientOrganization>;
|
|
79
|
+
leaveOrg: () => Promise<void>;
|
|
80
|
+
clearOrg: () => void;
|
|
81
|
+
listOrgs: () => Promise<ClientOrganization[]>;
|
|
82
|
+
}
|
|
83
|
+
interface UseOrgMembersResult {
|
|
84
|
+
subscribe: Readable<{
|
|
85
|
+
members: ClientMembership[];
|
|
86
|
+
isLoading: boolean;
|
|
87
|
+
error: string | null;
|
|
88
|
+
}>['subscribe'];
|
|
89
|
+
refresh: () => Promise<void>;
|
|
90
|
+
invite: (email: string, role: string) => Promise<ClientInvitation>;
|
|
91
|
+
removeMember: (userId: string) => Promise<void>;
|
|
92
|
+
updateRole: (userId: string, role: string) => Promise<void>;
|
|
93
|
+
}
|
|
94
|
+
declare function useOrg(): UseOrgResult;
|
|
95
|
+
declare function useOrgMembers(orgId: string): UseOrgMembersResult;
|
|
96
|
+
declare function createPermissionStore(requiredRole: string): Readable<boolean>;
|
|
97
|
+
/** Alias for {@link createPermissionStore}. */
|
|
98
|
+
declare const usePermission: typeof createPermissionStore;
|
|
99
|
+
|
|
100
|
+
export { type AuthContextValue, type OrgContextValue, type UseAuthResult, type UseOrgMembersResult, type UseOrgResult, createAuthStatusStore, createAuthStore, createCurrentUserStore, createPermissionStore, destroyAuthProvider, destroyOrgProvider, getAuthContext, getOrgContext, initAuthProvider, initOrgProvider, useAuth, useAuthStatus, useCurrentUser, useOrg, useOrgMembers, usePermission };
|