@korajs/auth 0.5.0 → 0.6.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/dist/chunk-7OXBRSJL.js +203 -0
- package/dist/chunk-7OXBRSJL.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 +293 -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 +134 -288
- package/dist/react.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
|
@@ -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 { AuthClient, AuthState } from '../client/auth-client'\nimport { createAuthSession, type AuthSession } from '../bindings/create-auth-session'\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) =>\n\t\t\trunWithResult(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 { readable, type Readable } from 'svelte/store'\nimport type {\n\tAuthUser,\n\tLinkedOAuthAccount,\n\tOAuthAuthorizationOptions,\n\tOAuthAuthorizationResult,\n\tOAuthCallbackParams,\n} from '../client/auth-client'\nimport type { AuthSessionSnapshot } from '../bindings/create-auth-session'\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 { OrgClient } from '../client/org-client'\nimport { createOrgSession, type OrgSession } from '../bindings/create-org-session'\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 { derived, get, readable, writable, type Readable } from 'svelte/store'\nimport type {\n\tClientInvitation,\n\tClientMembership,\n\tClientOrganization,\n} from '../client/org-client'\nimport {\n\tcheckOrgPermission,\n\tcreateOrgMembersActions,\n\tloadOrgMembers,\n} from '../bindings/create-org-session'\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,SAAS,MAAY;AAC1B,oBAAgB;AAChB,eAAW,YAAY,WAAW;AACjC,eAAS;AAAA,IACV;AAAA,EACD;AAEA,WAASA,iBAAqC;AAC7C,WAAO;AAAA,MACN;AAAA,MACA,MAAM,OAAO;AAAA,MACb,iBAAiB,UAAU;AAAA,MAC3B;AAAA,MACA;AAAA,MACA,OAAO;AAAA,IACR;AAAA,EACD;AAEA,QAAM,eAAe,CAAC,UAAyB;AAC9C,gBAAY,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACjE,WAAO;AAAA,EACR;AAEA,QAAM,MAAM,OAAO,WAA+C;AACjE,gBAAY;AACZ,QAAI;AACH,YAAM,OAAO;AAAA,IACd,SAAS,OAAO;AACf,mBAAa,KAAK;AAAA,IACnB;AAAA,EACD;AAEA,QAAM,gBAAgB,OAAU,WAAgD;AAC/E,gBAAY;AACZ,QAAI;AACH,a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AAQ,OAAO,OAAO,IAAI;AAC/C,UAAM,QAAQ,KAAK;AACnB,WAAO;AAAA,EACR;AAEA,QAAM,eAAe,OAAO,WAAkC;AAC7D,UAAM,QAAQ,aAAa,MAAM;AACjC,UAAM,QAAQ,KAAK;AAAA,EACpB;AAEA,QAAM,aAAa,OAAO,QAAgB,SAAgC;AACzE,UAAM,QAAQ,WAAW,QAAQ,IAAI;AACrC,UAAM,QAAQ,KAAK;AAAA,EACpB;AAEA,QAAM,YAAQ,uBAAQ,CAAC,SAAS,WAAW,KAAK,GAAG,CAAC,CAAC,YAAY,SAAS,UAAU,OAAO;AAAA,IAC1F,SAAS;AAAA,IACT,WAAW;AAAA,IACX,OAAO;AAAA,EACR,EAAE;AAEF,SAAO;AAAA,IACN,WAAW,MAAM;AAAA,IACjB,SAAS,MAAM,QAAQ,KAAK;AAAA,IAC5B;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAEO,SAAS,sBAAsB,cAAyC;AAC9E,QAAM,EAAE,QAAQ,IAAI,cAAc;AAElC,aAAO,wBAAS,QAAQ,gBAAgB,YAAY,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 };
|
package/dist/svelte.d.ts
ADDED
|
@@ -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.js';
|
|
2
|
+
export { x as checkOrgPermission } from './create-org-session-RsDj9cl4.js';
|
|
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 };
|
package/dist/svelte.js
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import {
|
|
2
|
+
checkOrgPermission,
|
|
3
|
+
createAuthSession,
|
|
4
|
+
createOrgMembersActions,
|
|
5
|
+
createOrgSession,
|
|
6
|
+
loadOrgMembers
|
|
7
|
+
} from "./chunk-7OXBRSJL.js";
|
|
8
|
+
|
|
9
|
+
// src/svelte/auth-context.ts
|
|
10
|
+
import { getContext, setContext } from "svelte";
|
|
11
|
+
var authContextKey = /* @__PURE__ */ Symbol("korajs-auth-context");
|
|
12
|
+
function initAuthProvider(client) {
|
|
13
|
+
const session = createAuthSession(client);
|
|
14
|
+
const value = {
|
|
15
|
+
client,
|
|
16
|
+
session,
|
|
17
|
+
get state() {
|
|
18
|
+
return session.getSnapshot().state;
|
|
19
|
+
},
|
|
20
|
+
get isLoading() {
|
|
21
|
+
return session.getSnapshot().isLoading;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
setContext(authContextKey, value);
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
function getAuthContext() {
|
|
28
|
+
const context = getContext(authContextKey);
|
|
29
|
+
if (!context) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
"Auth context missing. Call initAuthProvider(client) in your root layout component."
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
return context;
|
|
35
|
+
}
|
|
36
|
+
function destroyAuthProvider(context) {
|
|
37
|
+
context.session.destroy();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/svelte/use-auth.ts
|
|
41
|
+
import { readable } from "svelte/store";
|
|
42
|
+
function createAuthStore() {
|
|
43
|
+
const { session } = getAuthContext();
|
|
44
|
+
return readable(buildResult(session), (set) => {
|
|
45
|
+
const sync = () => {
|
|
46
|
+
set(buildResult(session));
|
|
47
|
+
};
|
|
48
|
+
sync();
|
|
49
|
+
return session.subscribe(sync);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
var useAuth = createAuthStore;
|
|
53
|
+
function buildResult(session) {
|
|
54
|
+
const snapshot = session.getSnapshot();
|
|
55
|
+
return {
|
|
56
|
+
...snapshot,
|
|
57
|
+
signUp: (params) => session.signUp(params),
|
|
58
|
+
signIn: (params) => session.signIn(params),
|
|
59
|
+
signInWithOAuth: (provider, options) => session.signInWithOAuth(provider, options),
|
|
60
|
+
completeOAuthSignIn: (provider, params) => session.completeOAuthSignIn(provider, params),
|
|
61
|
+
getOAuthAuthorizationUrl: (provider, options) => session.getOAuthAuthorizationUrl(provider, options),
|
|
62
|
+
linkOAuth: (provider, params) => session.linkOAuth(provider, params),
|
|
63
|
+
listLinkedAccounts: () => session.listLinkedAccounts(),
|
|
64
|
+
unlinkOAuth: (provider) => session.unlinkOAuth(provider),
|
|
65
|
+
signOut: () => session.signOut()
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function createCurrentUserStore() {
|
|
69
|
+
const { session } = getAuthContext();
|
|
70
|
+
return readable(session.getSnapshot().user, (set) => {
|
|
71
|
+
const sync = () => {
|
|
72
|
+
set(session.getSnapshot().user);
|
|
73
|
+
};
|
|
74
|
+
sync();
|
|
75
|
+
return session.subscribe(sync);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
var useCurrentUser = createCurrentUserStore;
|
|
79
|
+
function createAuthStatusStore() {
|
|
80
|
+
const { session } = getAuthContext();
|
|
81
|
+
return readable(
|
|
82
|
+
{
|
|
83
|
+
state: session.getSnapshot().state,
|
|
84
|
+
isAuthenticated: session.getSnapshot().isAuthenticated,
|
|
85
|
+
isLoading: session.getSnapshot().isLoading
|
|
86
|
+
},
|
|
87
|
+
(set) => {
|
|
88
|
+
const sync = () => {
|
|
89
|
+
const snapshot = session.getSnapshot();
|
|
90
|
+
set({
|
|
91
|
+
state: snapshot.state,
|
|
92
|
+
isAuthenticated: snapshot.isAuthenticated,
|
|
93
|
+
isLoading: snapshot.isLoading
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
sync();
|
|
97
|
+
return session.subscribe(sync);
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
var useAuthStatus = createAuthStatusStore;
|
|
102
|
+
|
|
103
|
+
// src/svelte/org-context.ts
|
|
104
|
+
import { getContext as getContext2, setContext as setContext2 } from "svelte";
|
|
105
|
+
var orgContextKey = /* @__PURE__ */ Symbol("korajs-org-context");
|
|
106
|
+
function initOrgProvider(client) {
|
|
107
|
+
const session = createOrgSession(client);
|
|
108
|
+
const value = { client, session };
|
|
109
|
+
setContext2(orgContextKey, value);
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
112
|
+
function getOrgContext() {
|
|
113
|
+
const context = getContext2(orgContextKey);
|
|
114
|
+
if (!context) {
|
|
115
|
+
throw new Error(
|
|
116
|
+
"Org context missing. Wrap your app with <OrgProvider client={orgClient}> from @korajs/auth/svelte."
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
return context;
|
|
120
|
+
}
|
|
121
|
+
function destroyOrgProvider(context) {
|
|
122
|
+
context.session.destroy();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/svelte/org-hooks.ts
|
|
126
|
+
import { derived, get, readable as readable2, writable } from "svelte/store";
|
|
127
|
+
function createOrgSnapshotStore() {
|
|
128
|
+
const { session } = getOrgContext();
|
|
129
|
+
return readable2(session.getSnapshot(), (set) => {
|
|
130
|
+
set(session.getSnapshot());
|
|
131
|
+
return session.subscribe(() => {
|
|
132
|
+
set(session.getSnapshot());
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
function useOrg() {
|
|
137
|
+
const { client, session } = getOrgContext();
|
|
138
|
+
const snapshotStore = createOrgSnapshotStore();
|
|
139
|
+
const error = writable(null);
|
|
140
|
+
const store = derived([snapshotStore, error], ([snapshot, errorValue]) => ({
|
|
141
|
+
...snapshot,
|
|
142
|
+
error: errorValue
|
|
143
|
+
}));
|
|
144
|
+
const switchOrg = async (orgId) => {
|
|
145
|
+
error.set(null);
|
|
146
|
+
try {
|
|
147
|
+
await client.switchOrg(orgId);
|
|
148
|
+
} catch (err) {
|
|
149
|
+
error.set(err instanceof Error ? err.message : String(err));
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
const createOrg = async (params) => {
|
|
153
|
+
error.set(null);
|
|
154
|
+
try {
|
|
155
|
+
return await client.createOrg(params);
|
|
156
|
+
} catch (err) {
|
|
157
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
158
|
+
error.set(message);
|
|
159
|
+
throw err;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
const leaveOrg = async () => {
|
|
163
|
+
const orgId = get(snapshotStore).orgId;
|
|
164
|
+
if (!orgId) return;
|
|
165
|
+
error.set(null);
|
|
166
|
+
try {
|
|
167
|
+
await client.leaveOrg(orgId);
|
|
168
|
+
} catch (err) {
|
|
169
|
+
error.set(err instanceof Error ? err.message : String(err));
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
const clearOrg = () => {
|
|
173
|
+
client.clearActiveOrg();
|
|
174
|
+
};
|
|
175
|
+
const listOrgs = async () => {
|
|
176
|
+
try {
|
|
177
|
+
return await client.listOrgs();
|
|
178
|
+
} catch (err) {
|
|
179
|
+
error.set(err instanceof Error ? err.message : String(err));
|
|
180
|
+
return [];
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
return {
|
|
184
|
+
subscribe: store.subscribe,
|
|
185
|
+
get org() {
|
|
186
|
+
return get(snapshotStore).org;
|
|
187
|
+
},
|
|
188
|
+
get role() {
|
|
189
|
+
return get(snapshotStore).role;
|
|
190
|
+
},
|
|
191
|
+
get orgId() {
|
|
192
|
+
return get(snapshotStore).orgId;
|
|
193
|
+
},
|
|
194
|
+
switchOrg,
|
|
195
|
+
createOrg,
|
|
196
|
+
leaveOrg,
|
|
197
|
+
clearOrg,
|
|
198
|
+
listOrgs
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function useOrgMembers(orgId) {
|
|
202
|
+
const { client } = getOrgContext();
|
|
203
|
+
const members = writable([]);
|
|
204
|
+
const isLoading = writable(true);
|
|
205
|
+
const error = writable(null);
|
|
206
|
+
const refresh = async (targetOrgId) => {
|
|
207
|
+
isLoading.set(true);
|
|
208
|
+
error.set(null);
|
|
209
|
+
try {
|
|
210
|
+
members.set(await loadOrgMembers(client, targetOrgId));
|
|
211
|
+
} catch (err) {
|
|
212
|
+
error.set(err instanceof Error ? err.message : String(err));
|
|
213
|
+
} finally {
|
|
214
|
+
isLoading.set(false);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
$effect(() => {
|
|
218
|
+
void refresh(orgId);
|
|
219
|
+
});
|
|
220
|
+
const actions = createOrgMembersActions(client, orgId, (message) => {
|
|
221
|
+
error.set(message);
|
|
222
|
+
});
|
|
223
|
+
const invite = async (email, role) => {
|
|
224
|
+
const result = await actions.invite(email, role);
|
|
225
|
+
await refresh(orgId);
|
|
226
|
+
return result;
|
|
227
|
+
};
|
|
228
|
+
const removeMember = async (userId) => {
|
|
229
|
+
await actions.removeMember(userId);
|
|
230
|
+
await refresh(orgId);
|
|
231
|
+
};
|
|
232
|
+
const updateRole = async (userId, role) => {
|
|
233
|
+
await actions.updateRole(userId, role);
|
|
234
|
+
await refresh(orgId);
|
|
235
|
+
};
|
|
236
|
+
const store = derived([members, isLoading, error], ([memberList, loading, errorValue]) => ({
|
|
237
|
+
members: memberList,
|
|
238
|
+
isLoading: loading,
|
|
239
|
+
error: errorValue
|
|
240
|
+
}));
|
|
241
|
+
return {
|
|
242
|
+
subscribe: store.subscribe,
|
|
243
|
+
refresh: () => refresh(orgId),
|
|
244
|
+
invite,
|
|
245
|
+
removeMember,
|
|
246
|
+
updateRole
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
function createPermissionStore(requiredRole) {
|
|
250
|
+
const { session } = getOrgContext();
|
|
251
|
+
return readable2(session.checkPermission(requiredRole), (set) => {
|
|
252
|
+
set(session.checkPermission(requiredRole));
|
|
253
|
+
return session.subscribe(() => {
|
|
254
|
+
set(session.checkPermission(requiredRole));
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
var usePermission = createPermissionStore;
|
|
259
|
+
export {
|
|
260
|
+
checkOrgPermission,
|
|
261
|
+
createAuthStatusStore,
|
|
262
|
+
createAuthStore,
|
|
263
|
+
createCurrentUserStore,
|
|
264
|
+
createPermissionStore,
|
|
265
|
+
destroyAuthProvider,
|
|
266
|
+
destroyOrgProvider,
|
|
267
|
+
getAuthContext,
|
|
268
|
+
getOrgContext,
|
|
269
|
+
initAuthProvider,
|
|
270
|
+
initOrgProvider,
|
|
271
|
+
useAuth,
|
|
272
|
+
useAuthStatus,
|
|
273
|
+
useCurrentUser,
|
|
274
|
+
useOrg,
|
|
275
|
+
useOrgMembers,
|
|
276
|
+
usePermission
|
|
277
|
+
};
|
|
278
|
+
//# sourceMappingURL=svelte.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/svelte/auth-context.ts","../src/svelte/use-auth.ts","../src/svelte/org-context.ts","../src/svelte/org-hooks.ts"],"sourcesContent":["import { getContext, setContext } from 'svelte'\nimport type { AuthClient, AuthState } from '../client/auth-client'\nimport { createAuthSession, type AuthSession } from '../bindings/create-auth-session'\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 { readable, type Readable } from 'svelte/store'\nimport type {\n\tAuthUser,\n\tLinkedOAuthAccount,\n\tOAuthAuthorizationOptions,\n\tOAuthAuthorizationResult,\n\tOAuthCallbackParams,\n} from '../client/auth-client'\nimport type { AuthSessionSnapshot } from '../bindings/create-auth-session'\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 { OrgClient } from '../client/org-client'\nimport { createOrgSession, type OrgSession } from '../bindings/create-org-session'\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 { derived, get, readable, writable, type Readable } from 'svelte/store'\nimport type {\n\tClientInvitation,\n\tClientMembership,\n\tClientOrganization,\n} from '../client/org-client'\nimport {\n\tcheckOrgPermission,\n\tcreateOrgMembersActions,\n\tloadOrgMembers,\n} from '../bindings/create-org-session'\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,SAAS,YAAY,kBAAkB;AAIvC,IAAM,iBAAiB,uBAAO,qBAAqB;AAa5C,SAAS,iBAAiB,QAAsC;AACtE,QAAM,UAAU,kBAAkB,MAAM;AAExC,QAAM,QAA0B;AAAA,IAC/B;AAAA,IACA;AAAA,IACA,IAAI,QAAQ;AACX,aAAO,QAAQ,YAAY,EAAE;AAAA,IAC9B;AAAA,IACA,IAAI,YAAY;AACf,aAAO,QAAQ,YAAY,EAAE;AAAA,IAC9B;AAAA,EACD;AAEA,aAAW,gBAAgB,KAAK;AAChC,SAAO;AACR;AAEO,SAAS,iBAAmC;AAClD,QAAM,UAAU,WAAyC,cAAc;AACvE,MAAI,CAAC,SAAS;AACb,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;AAEO,SAAS,oBAAoB,SAAiC;AACpE,UAAQ,QAAQ,QAAQ;AACzB;;;AC/CA,SAAS,gBAA+B;AAwCjC,SAAS,kBAA2C;AAC1D,QAAM,EAAE,QAAQ,IAAI,eAAe;AAEnC,SAAO,SAAwB,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