@c1m-public/platform-auth 0.8.3 → 0.8.4

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/next.d.ts CHANGED
@@ -128,6 +128,11 @@ interface SessionStoreConfig {
128
128
  /** Called when a cookie read/write fails outside a request (prerender); default swallows. */
129
129
  onError?: (error: unknown, operation: string) => void;
130
130
  }
131
+ /** Per-call overrides: a multi-host surface picks the cookie domain per request. */
132
+ interface SessionWriteOptions {
133
+ /** Ignored for `__Host-` names, which forbid Domain. */
134
+ cookieDomain?: string;
135
+ }
131
136
  /**
132
137
  * Session cookies for a first-party Next.js platform surface, written once.
133
138
  *
@@ -148,24 +153,24 @@ interface SessionStoreConfig {
148
153
  declare function createSessionStore(config: SessionStoreConfig): {
149
154
  audience: string;
150
155
  cookieNames: SessionCookieNames;
151
- cookieOptions: (rememberMe: boolean, token?: string) => CookieOptions & {
156
+ cookieOptions: (rememberMe: boolean, token?: string, options?: SessionWriteOptions) => CookieOptions & {
152
157
  httpOnly: true;
153
158
  sameSite: "lax";
154
159
  path: "/";
155
160
  };
156
- createSession: (accessToken: string, refreshToken?: string, rememberMe?: boolean) => Promise<void>;
161
+ createSession: (accessToken: string, refreshToken?: string, rememberMe?: boolean, options?: SessionWriteOptions) => Promise<void>;
157
162
  writeSessionCookies: (response: Response, accessToken: string, refreshToken?: string, rememberMe?: boolean) => Response;
158
163
  getAccessToken: () => Promise<string | null>;
159
164
  getRefreshToken: () => Promise<string | null>;
160
165
  getSession: () => Promise<SessionData | null>;
161
166
  getSessionWithRefresh: () => Promise<SessionData | null>;
162
167
  isRememberMe: () => Promise<boolean>;
163
- updateAccessToken: (accessToken: string, refreshToken?: string) => Promise<void>;
164
- destroySession: () => Promise<void>;
168
+ updateAccessToken: (accessToken: string, refreshToken?: string, options?: SessionWriteOptions) => Promise<void>;
169
+ destroySession: (options?: SessionWriteOptions) => Promise<void>;
165
170
  clearSessionCookies: (response: Response) => Response;
166
171
  requireSession: () => Promise<SessionData>;
167
172
  isAuthenticated(): Promise<boolean>;
168
173
  };
169
174
  type SessionStore = ReturnType<typeof createSessionStore>;
170
175
 
171
- export { CookieOptions, type PlatformFetch, type PlatformFetchConfig, type PlatformFetchTimeouts, PlatformServerFetchError, RecentAuthenticationRequiredError, SSOReauthenticationRequiredError, type SessionCookieNames, SessionData, SessionExpiredError, type SessionStore, type SessionStoreConfig, type SessionStoreRefreshConfig, authenticationErrorFor, buildForwardedRequestHeaders, controlRequest, createPlatformFetch, createSessionStore, isPlatformServerFetchError, isRecentAuthenticationRequiredError, isSSOReauthenticationRequiredError, isSessionExpiredError, mapControlError };
176
+ export { CookieOptions, type PlatformFetch, type PlatformFetchConfig, type PlatformFetchTimeouts, PlatformServerFetchError, RecentAuthenticationRequiredError, SSOReauthenticationRequiredError, type SessionCookieNames, SessionData, SessionExpiredError, type SessionStore, type SessionStoreConfig, type SessionStoreRefreshConfig, type SessionWriteOptions, authenticationErrorFor, buildForwardedRequestHeaders, controlRequest, createPlatformFetch, createSessionStore, isPlatformServerFetchError, isRecentAuthenticationRequiredError, isSSOReauthenticationRequiredError, isSessionExpiredError, mapControlError };
package/dist/next.js CHANGED
@@ -176,15 +176,16 @@ function createSessionStore(config) {
176
176
  timeoutMs: config.refresh.timeoutMs,
177
177
  fetch: config.refresh.fetch
178
178
  }) : void 0;
179
- function cookieOptions(rememberMe, token) {
179
+ function cookieOptions(rememberMe, token, options) {
180
180
  const maxAge = token ? tokenMaxAgeSeconds(token, maxAgeCap) : maxAgeCap;
181
+ const effectiveDomain = hostPrefixed ? void 0 : options?.cookieDomain ?? domain;
181
182
  return {
182
183
  httpOnly: true,
183
184
  secure,
184
185
  sameSite: "lax",
185
186
  path: "/",
186
187
  ...rememberMe ? { maxAge } : {},
187
- ...domain ? { domain } : {}
188
+ ...effectiveDomain ? { domain: effectiveDomain } : {}
188
189
  };
189
190
  }
190
191
  function assertAudience(token) {
@@ -207,13 +208,13 @@ function createSessionStore(config) {
207
208
  function rememberedIn(store) {
208
209
  return store?.get(names.rememberMe)?.value === "true";
209
210
  }
210
- async function createSession(accessToken, refreshToken, rememberMe = config.defaultRememberMe ?? true) {
211
+ async function createSession(accessToken, refreshToken, rememberMe = config.defaultRememberMe ?? true, options) {
211
212
  assertAudience(accessToken);
212
213
  const store = await jar("createSession");
213
214
  if (!store) throw new Error("Cannot create a session outside a request");
214
- store.set(names.session, accessToken, cookieOptions(rememberMe, accessToken));
215
- if (refreshToken) store.set(names.refreshToken, refreshToken, cookieOptions(rememberMe, refreshToken));
216
- store.set(names.rememberMe, rememberMe ? "true" : "false", cookieOptions(rememberMe));
215
+ store.set(names.session, accessToken, cookieOptions(rememberMe, accessToken, options));
216
+ if (refreshToken) store.set(names.refreshToken, refreshToken, cookieOptions(rememberMe, refreshToken, options));
217
+ store.set(names.rememberMe, rememberMe ? "true" : "false", cookieOptions(rememberMe, void 0, options));
217
218
  }
218
219
  function writeSessionCookies(response, accessToken, refreshToken, rememberMe = config.defaultRememberMe ?? true) {
219
220
  assertAudience(accessToken);
@@ -238,13 +239,13 @@ function createSessionStore(config) {
238
239
  async function isRememberMe() {
239
240
  return rememberedIn(await jar("isRememberMe"));
240
241
  }
241
- async function updateAccessToken(accessToken, refreshToken) {
242
+ async function updateAccessToken(accessToken, refreshToken, options) {
242
243
  assertAudience(accessToken);
243
244
  const store = await jar("updateAccessToken");
244
245
  if (!store) throw new Error("Cannot update a session outside a request");
245
246
  const rememberMe = rememberedIn(store);
246
- store.set(names.session, accessToken, cookieOptions(rememberMe, accessToken));
247
- if (refreshToken) store.set(names.refreshToken, refreshToken, cookieOptions(rememberMe, refreshToken));
247
+ store.set(names.session, accessToken, cookieOptions(rememberMe, accessToken, options));
248
+ if (refreshToken) store.set(names.refreshToken, refreshToken, cookieOptions(rememberMe, refreshToken, options));
248
249
  }
249
250
  async function getSessionWithRefresh() {
250
251
  const store = await jar("getSessionWithRefresh");
@@ -264,12 +265,12 @@ function createSessionStore(config) {
264
265
  function clearOptions() {
265
266
  return { path: "/", secure };
266
267
  }
267
- async function destroySession() {
268
+ async function destroySession(options) {
268
269
  const store = await jar("destroySession");
269
270
  if (!store) return;
270
271
  try {
271
- const options = cookieOptions(false);
272
- for (const name of [names.session, names.refreshToken, names.rememberMe]) store.delete({ name, ...options });
272
+ const attributes = cookieOptions(false, void 0, options);
273
+ for (const name of [names.session, names.refreshToken, names.rememberMe]) store.delete({ name, ...attributes });
273
274
  } catch (error) {
274
275
  onError(error, "destroySession");
275
276
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c1m-public/platform-auth",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Session and authorization helpers for C1M platform surfaces. The root is runtime-neutral (Web Request/Response): token/session reads, the first-party handoff (PKCE target + source), proxy session gate and coalesced refresh; ./next adds the server-only guard; ./access carries the resolved access snapshot, typed permission keys, predicates, a Next loader and React bindings",