@riducms/sveltekit 0.4.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/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  },
5
5
  "description": "SvelteKit integration for Ridu: direct browser requests, server rendering, and one session owner.",
6
6
  "devDependencies": {
7
- "@riducms/sdk": "0.4.0",
7
+ "@riducms/sdk": "0.6.0",
8
8
  "@sveltejs/kit": "^2.48.0"
9
9
  },
10
10
  "exports": {
@@ -27,7 +27,7 @@
27
27
  "license": "MIT",
28
28
  "name": "@riducms/sveltekit",
29
29
  "peerDependencies": {
30
- "@riducms/sdk": "0.4.0",
30
+ "@riducms/sdk": "0.6.0",
31
31
  "@sveltejs/kit": "^2.20.0",
32
32
  "svelte": "^5.29.0"
33
33
  },
@@ -45,5 +45,5 @@
45
45
  "test": "bun test"
46
46
  },
47
47
  "type": "module",
48
- "version": "0.4.0"
48
+ "version": "0.6.0"
49
49
  }
package/src/definition.ts CHANGED
@@ -28,7 +28,7 @@ export interface RiduDefinitionOptions<Factory extends ClientFactory, Slug exten
28
28
  authCollection: Slug;
29
29
  /** Frontend-domain cookie that stores the session token. Defaults to `ridu_token`. */
30
30
  cookieName?: string;
31
- /** Fetch used by server-side clients. Defaults to the platform fetch. */
31
+ /** Fetch used by server-side clients. Defaults to SvelteKit's `event.fetch`. */
32
32
  fetch?: ClientOptions["fetch"];
33
33
  }
34
34
 
@@ -44,7 +44,12 @@ export interface RiduDefinition<
44
44
  readonly cookieName: string;
45
45
  client(
46
46
  token: SessionTokenStore<SessionFor<Config, Slug>>,
47
- options?: { fetch?: ClientOptions["fetch"]; memoizeSession?: boolean }
47
+ options?: {
48
+ fetch?: ClientOptions["fetch"];
49
+ /** Used when neither the call nor the definition supplies a fetch. */
50
+ fallbackFetch?: ClientOptions["fetch"];
51
+ memoizeSession?: boolean;
52
+ }
48
53
  ): RiduClient<Config, Slug>;
49
54
  }
50
55
 
@@ -62,7 +67,7 @@ export function createDefinition<
62
67
  authCollection: options.authCollection,
63
68
  cookieName,
64
69
  client(token, clientOptions = {}) {
65
- const fetch = clientOptions.fetch ?? options.fetch;
70
+ const fetch = clientOptions.fetch ?? options.fetch ?? clientOptions.fallbackFetch;
66
71
  return options.createClient({
67
72
  baseURL,
68
73
  ...(fetch === undefined ? {} : { fetch }),
package/src/server.ts CHANGED
@@ -15,7 +15,11 @@ interface Binding<Config extends RiduConfigShape, Slug extends AuthCollectionSlu
15
15
  }
16
16
 
17
17
  export interface ServerClientOptions {
18
- /** Fetch for server requests to Ridu. Defaults to the definition's fetch or the platform fetch. */
18
+ /**
19
+ * Fetch for server requests to Ridu. Defaults to the definition's fetch, then to SvelteKit's
20
+ * `event.fetch`. The client sends its token in a header with `credentials: "omit"`, so
21
+ * `event.fetch` does not forward the web app's cookies to Ridu.
22
+ */
19
23
  fetch?: ClientOptions["fetch"];
20
24
  }
21
25
 
@@ -29,7 +33,7 @@ export function createServerClient<
29
33
  Slug extends AuthCollectionSlug<Config>,
30
34
  >(
31
35
  ridu: Binding<Config, Slug>,
32
- event: Pick<RequestEvent, "cookies" | "url">,
36
+ event: Pick<RequestEvent, "cookies" | "url"> & Partial<Pick<RequestEvent, "fetch">>,
33
37
  options: ServerClientOptions = {}
34
38
  ): RiduClient<Config, Slug> {
35
39
  const definition = ridu[definitionKey];
@@ -40,6 +44,7 @@ export function createServerClient<
40
44
  );
41
45
  return definition.client(store, {
42
46
  ...(options.fetch === undefined ? {} : { fetch: options.fetch }),
47
+ ...(event.fetch === undefined ? {} : { fallbackFetch: event.fetch }),
43
48
  memoizeSession: true,
44
49
  });
45
50
  }