@strivacity/sdk-svelte 4.0.0-beta.0 → 4.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +160 -104
- package/package.json +5 -4
- package/src/client/components.svelte.ts +6 -5
- package/src/client/hooks.svelte.ts +17 -147
- package/src/client/types.ts +16 -102
- package/src/server/sdk.ts +52 -28
- package/testing/tests/components.spec.ts +1 -1
- package/testing/tests/hooks.spec.ts +1 -1
- package/testing/tests/index.spec.ts +10 -0
- package/testing/tests/server/sdk.spec.ts +59 -15
- package/dist/assets/rolldown-runtime.cjs +0 -1
- package/dist/client/components.svelte.cjs +0 -2
- package/dist/client/components.svelte.cjs.map +0 -1
- package/dist/client/components.svelte.d.ts +0 -11
- package/dist/client/components.svelte.mjs +0 -2
- package/dist/client/components.svelte.mjs.map +0 -1
- package/dist/client/hooks.svelte.cjs +0 -2
- package/dist/client/hooks.svelte.cjs.map +0 -1
- package/dist/client/hooks.svelte.d.ts +0 -27
- package/dist/client/hooks.svelte.mjs +0 -2
- package/dist/client/hooks.svelte.mjs.map +0 -1
- package/dist/client/index.d.ts +0 -8
- package/dist/client/index.mjs +0 -1
- package/dist/client/storages.cjs +0 -1
- package/dist/client/storages.d.ts +0 -1
- package/dist/client/storages.mjs +0 -1
- package/dist/client/types.cjs +0 -1
- package/dist/client/types.d.ts +0 -238
- package/dist/client/types.mjs +0 -1
- package/dist/client/utils.cjs +0 -1
- package/dist/client/utils.d.ts +0 -1
- package/dist/client/utils.mjs +0 -1
- package/dist/errors.cjs +0 -1
- package/dist/errors.d.ts +0 -1
- package/dist/errors.mjs +0 -1
- package/dist/server/index.cjs +0 -1
- package/dist/server/index.d.ts +0 -6
- package/dist/server/index.mjs +0 -1
- package/dist/server/sdk.cjs +0 -2
- package/dist/server/sdk.cjs.map +0 -1
- package/dist/server/sdk.d.ts +0 -8
- package/dist/server/sdk.mjs +0 -2
- package/dist/server/sdk.mjs.map +0 -1
- package/dist/server/storages.cjs +0 -2
- package/dist/server/storages.cjs.map +0 -1
- package/dist/server/storages.d.ts +0 -10
- package/dist/server/storages.mjs +0 -2
- package/dist/server/storages.mjs.map +0 -1
- package/dist/server/types.cjs +0 -1
- package/dist/server/types.d.ts +0 -35
- package/dist/server/types.mjs +0 -1
- package/dist/server/utils.cjs +0 -1
- package/dist/server/utils.d.ts +0 -1
- package/dist/server/utils.mjs +0 -1
- package/dist/types.cjs +0 -1
- package/dist/types.d.ts +0 -2
- package/dist/types.mjs +0 -1
package/dist/server/sdk.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.mjs","names":[],"sources":["../../src/server/sdk.ts"],"sourcesContent":["import type { RequestEvent, Handle } from '@sveltejs/kit';\nimport type { SessionData } from '@strivacity/sdk-core/types';\nimport type { SvelteKitServerSDK, SvelteKitServerSDKInitConfig } from './types';\nimport { redirect } from '@sveltejs/kit';\nimport { isSessionExpired } from '@strivacity/sdk-core/utils';\nimport { createBaseServerSDK } from '@strivacity/sdk-core/server';\n\n/**\n * Creates the Strivacity server SDK for SvelteKit: session management, auth route handlers, and the `handle` hook used in `hooks.server.ts`.\n *\n * @param {SvelteKitServerSDKInitConfig} initConfig - The configuration options for initializing the server SDK.\n * @returns {SvelteKitServerSDK} The initialized server SDK instance.\n */\nexport function createServerSDK(initConfig: SvelteKitServerSDKInitConfig): SvelteKitServerSDK {\n\tconst base = createBaseServerSDK<RequestEvent>(\n\t\t{\n\t\t\ttoRequest: (event) => event.request,\n\t\t},\n\t\tinitConfig,\n\t);\n\n\tasync function requireSession(event: RequestEvent, guardOpts: { returnTo?: string } = {}): Promise<SessionData> {\n\t\tlet session = await base.getSession(event);\n\n\t\tif (session && isSessionExpired(session) && session.refresh_token) {\n\t\t\ttry {\n\t\t\t\tsession = await base.refreshSession(event);\n\t\t\t} catch {\n\t\t\t\tsession = null;\n\t\t\t}\n\t\t}\n\n\t\tif (!session) {\n\t\t\tconst loginUrl = ['embedded', 'native'].includes(base.options.mode) ? base.options.loginUri : `${base.options.authUrlPrefix}/login`;\n\t\t\tconst uri = new URL(loginUrl, event.url.origin);\n\t\t\tconst returnTo = guardOpts.returnTo ?? `${event.url.pathname}${event.url.search}`;\n\n\t\t\tif (returnTo) {\n\t\t\t\turi.searchParams.set('returnTo', returnTo);\n\t\t\t}\n\n\t\t\tredirect(302, uri);\n\t\t}\n\n\t\treturn session;\n\t}\n\n\tconst handle: Handle = async ({ event, resolve }) => {\n\t\tconst response = await base.handler(event);\n\n\t\treturn response ?? resolve(event);\n\t};\n\n\treturn {\n\t\tget options() {\n\t\t\treturn base.options;\n\t\t},\n\t\thandle,\n\t\trequireSession,\n\t\tgetSession: (event) => base.getSession(event),\n\t\tupdateSession: (session, event) => base.updateSession(session, event),\n\t\trefreshSession: (event) => base.refreshSession(event),\n\t\trevokeSession: (event) => base.revokeSession(event),\n\t\tgetEntrySession: (entryUrl) => base.getEntrySession(entryUrl),\n\t\tcompleteLogin: (params, event) => base.completeLogin(params, event),\n\t\tlogout: (postLogoutRedirectUri, event) => base.logout(postLogoutRedirectUri, event),\n\t\thandleLogin: (event) => base.handleLogin(event),\n\t\thandleRegister: (event) => base.handleRegister(event),\n\t\thandleCallback: (event) => base.handleCallback(event),\n\t\thandleRefresh: (event) => base.handleRefresh(event),\n\t\thandleRevoke: (event) => base.handleRevoke(event),\n\t\thandleEntry: (event) => base.handleEntry(event),\n\t\thandleLogout: (event) => base.handleLogout(event),\n\t\thandleBackChannelLogout: (event) => base.handleBackChannelLogout(event),\n\t\thandler: (event) => base.handler(event),\n\t};\n}\n"],"mappings":"yKAaA,SAAgB,EAAgB,EAA8D,CAC7F,IAAM,EAAO,EACZ,CACC,UAAY,GAAU,EAAM,OAC7B,EACA,CACD,EAEA,eAAe,EAAe,EAAqB,EAAmC,CAAC,EAAyB,CAC/G,IAAI,EAAU,MAAM,EAAK,WAAW,CAAK,EAEzC,GAAI,GAAW,EAAiB,CAAO,GAAK,EA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storages.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require("../assets/rolldown-runtime.cjs");let e=require("@strivacity/sdk-core/storages/server");function t(t,n){return(0,e.createSessionIdCookieStorage)({toRequest:e=>e.request},t,n)}exports.createSessionIdCookieStorage=t;var n=require("@strivacity/sdk-core/storages");Object.keys(n).forEach(function(e){e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return n[e]}})});
|
|
2
|
-
//# sourceMappingURL=storages.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"storages.cjs","names":[],"sources":["../../src/server/storages.ts"],"sourcesContent":["import type { RequestEvent } from '@sveltejs/kit';\nimport type { ServerStorage, SDKStorage, SessionIdCookieStorageOptions } from './types';\nimport { createSessionIdCookieStorage as createSessionIdCookieStorageBase } from '@strivacity/sdk-core/storages/server';\n\nexport * from '@strivacity/sdk-core/storages';\n\n/**\n * Creates a session storage that puts a random unique id value cookie on the client and keeping the actual session data in the given `storage`.\n *\n * @param {SDKStorage} storage - The storage used to persist session data, keyed by a randomly generated session id.\n * @param {SessionIdCookieStorageOptions} [options] - Options for configuring the session-id cookie storage.\n * @returns {ServerStorage} An object implementing the ServerStorage interface for managing sessions indexed by a session-id cookie.\n */\nexport function createSessionIdCookieStorage(storage: SDKStorage, options?: SessionIdCookieStorageOptions): ServerStorage {\n\treturn createSessionIdCookieStorageBase<RequestEvent>(\n\t\t{\n\t\t\ttoRequest: (event) => event.request,\n\t\t},\n\t\tstorage,\n\t\toptions,\n\t);\n}\n"],"mappings":"mKAaA,SAAgB,EAA6B,EAAqB,EAAwD,CACzH,OAAA,EAAO,EAAA,6BAAA,CACN,CACC,UAAY,GAAU,EAAM,OAC7B,EACA,EACA,CACD,CACD"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ServerStorage, SDKStorage, SessionIdCookieStorageOptions } from './types';
|
|
2
|
-
export * from '@strivacity/sdk-core/storages';
|
|
3
|
-
/**
|
|
4
|
-
* Creates a session storage that puts a random unique id value cookie on the client and keeping the actual session data in the given `storage`.
|
|
5
|
-
*
|
|
6
|
-
* @param {SDKStorage} storage - The storage used to persist session data, keyed by a randomly generated session id.
|
|
7
|
-
* @param {SessionIdCookieStorageOptions} [options] - Options for configuring the session-id cookie storage.
|
|
8
|
-
* @returns {ServerStorage} An object implementing the ServerStorage interface for managing sessions indexed by a session-id cookie.
|
|
9
|
-
*/
|
|
10
|
-
export declare function createSessionIdCookieStorage(storage: SDKStorage, options?: SessionIdCookieStorageOptions): ServerStorage;
|
package/dist/server/storages.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"storages.mjs","names":[],"sources":["../../src/server/storages.ts"],"sourcesContent":["import type { RequestEvent } from '@sveltejs/kit';\nimport type { ServerStorage, SDKStorage, SessionIdCookieStorageOptions } from './types';\nimport { createSessionIdCookieStorage as createSessionIdCookieStorageBase } from '@strivacity/sdk-core/storages/server';\n\nexport * from '@strivacity/sdk-core/storages';\n\n/**\n * Creates a session storage that puts a random unique id value cookie on the client and keeping the actual session data in the given `storage`.\n *\n * @param {SDKStorage} storage - The storage used to persist session data, keyed by a randomly generated session id.\n * @param {SessionIdCookieStorageOptions} [options] - Options for configuring the session-id cookie storage.\n * @returns {ServerStorage} An object implementing the ServerStorage interface for managing sessions indexed by a session-id cookie.\n */\nexport function createSessionIdCookieStorage(storage: SDKStorage, options?: SessionIdCookieStorageOptions): ServerStorage {\n\treturn createSessionIdCookieStorageBase<RequestEvent>(\n\t\t{\n\t\t\ttoRequest: (event) => event.request,\n\t\t},\n\t\tstorage,\n\t\toptions,\n\t);\n}\n"],"mappings":"+HAaA,SAAgB,EAA6B,EAAqB,EAAwD,CACzH,OAAO,EACN,CACC,UAAY,GAAU,EAAM,OAC7B,EACA,EACA,CACD,CACD"}
|
package/dist/server/types.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
require("../assets/rolldown-runtime.cjs");var e=require("@strivacity/sdk-core/types");Object.keys(e).forEach(function(t){t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})});
|
package/dist/server/types.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Handle, RequestEvent } from '@sveltejs/kit';
|
|
2
|
-
import { ServerSDKOptions, ServerSDKInitConfig, SDKStorage, SessionData, CookieOptions, LogoutTokenClaims, BaseServerSDK } from '@strivacity/sdk-core/types';
|
|
3
|
-
export * from '@strivacity/sdk-core/types';
|
|
4
|
-
export type SvelteKitServerStorage = SDKStorage<[
|
|
5
|
-
event?: RequestEvent
|
|
6
|
-
], [
|
|
7
|
-
event?: RequestEvent,
|
|
8
|
-
cookieOptions?: CookieOptions
|
|
9
|
-
], [
|
|
10
|
-
event?: RequestEvent,
|
|
11
|
-
cookieOptions?: CookieOptions
|
|
12
|
-
]> & {
|
|
13
|
-
deleteByLogoutToken?(token: LogoutTokenClaims): Promise<void>;
|
|
14
|
-
};
|
|
15
|
-
export type SvelteKitServerSDKOptions<Storage extends SvelteKitServerStorage = SvelteKitServerStorage, StateStorage extends SDKStorage = SDKStorage> = ServerSDKOptions<RequestEvent, Storage, StateStorage>;
|
|
16
|
-
export type SvelteKitServerSDKInitConfig<Storage extends SvelteKitServerStorage = SvelteKitServerStorage, StateStorage extends SDKStorage = SDKStorage> = ServerSDKInitConfig<RequestEvent> & Partial<SvelteKitServerSDKOptions<Storage, StateStorage>>;
|
|
17
|
-
export type SvelteKitServerSDK = BaseServerSDK<RequestEvent> & {
|
|
18
|
-
/**
|
|
19
|
-
* A SvelteKit `Handle` hook that intercepts and serves the `authUrlPrefix` auth routes.
|
|
20
|
-
* Mount it in `src/hooks.server.ts`, optionally combined with your own hooks via `sequence()`.
|
|
21
|
-
*/
|
|
22
|
-
handle: Handle;
|
|
23
|
-
/**
|
|
24
|
-
* Guard for `+page.server.ts`/`+layout.server.ts` `load()` functions: returns the current session, or throws a SvelteKit `redirect()` to the login page if unauthenticated.
|
|
25
|
-
*
|
|
26
|
-
* @param {RequestEvent} event - The SvelteKit request event.
|
|
27
|
-
* @param {Object} [options] - Optional options for the session requirement.
|
|
28
|
-
* @param {string} [options.returnTo] - Optional relative path to redirect to after login. Defaults to the current page.
|
|
29
|
-
* @returns {Promise<SessionData>} A promise that resolves to the current session data if authenticated.
|
|
30
|
-
* @throws {Redirect} Throws a SvelteKit `redirect()` to the login page if unauthenticated.
|
|
31
|
-
*/
|
|
32
|
-
requireSession(event: RequestEvent, options?: {
|
|
33
|
-
returnTo?: string;
|
|
34
|
-
}): Promise<SessionData>;
|
|
35
|
-
};
|
package/dist/server/types.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export*from"@strivacity/sdk-core/types";
|
package/dist/server/utils.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
require("../assets/rolldown-runtime.cjs");var e=require("@strivacity/sdk-core/utils");Object.keys(e).forEach(function(t){t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})});
|
package/dist/server/utils.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@strivacity/sdk-core/utils';
|
package/dist/server/utils.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export*from"@strivacity/sdk-core/utils";
|
package/dist/types.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
require("./assets/rolldown-runtime.cjs"),require("./client/types.cjs"),require("./server/types.cjs");var e=require("@strivacity/sdk-core/types");Object.keys(e).forEach(function(t){t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})});
|
package/dist/types.d.ts
DELETED
package/dist/types.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./client/types.mjs";import"./server/types.mjs";export*from"@strivacity/sdk-core/types";
|