@cimplify/sdk 0.54.0 → 0.56.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.
Files changed (43) hide show
  1. package/dist/advanced.d.mts +1 -1
  2. package/dist/advanced.d.ts +1 -1
  3. package/dist/advanced.js +20 -20
  4. package/dist/advanced.mjs +1 -1
  5. package/dist/{chunk-EJUKGJTZ.js → chunk-6W3AH4QW.js} +2 -2
  6. package/dist/{chunk-NEK7CVE2.mjs → chunk-F4WS3OIF.mjs} +1 -1
  7. package/dist/{chunk-B3Y4C4A7.mjs → chunk-I4IXPQIX.mjs} +7 -4
  8. package/dist/{chunk-YJLOOC3L.js → chunk-JGBDWEPJ.js} +7 -4
  9. package/dist/chunk-JYPLT56O.js +272 -0
  10. package/dist/{chunk-IJ32BXKZ.js → chunk-MW7ICTVK.js} +35 -35
  11. package/dist/{chunk-6QZQQRBB.mjs → chunk-SQ7U3BWY.mjs} +1 -1
  12. package/dist/chunk-XYI4NXWG.mjs +259 -0
  13. package/dist/{client-D1Gknspz.d.mts → client-Bhvlelij.d.mts} +1 -1
  14. package/dist/{client-Bj2apl_y.d.mts → client-DKg-5OWu.d.mts} +16 -1
  15. package/dist/{client-306peWZ0.d.ts → client-Dfg_hmkP.d.ts} +16 -1
  16. package/dist/{client-C2bKMy5g.d.ts → client-DlGJqSDd.d.ts} +1 -1
  17. package/dist/index.d.mts +18 -3
  18. package/dist/index.d.ts +18 -3
  19. package/dist/index.js +160 -72
  20. package/dist/index.mjs +91 -3
  21. package/dist/react.d.mts +52 -5
  22. package/dist/react.d.ts +52 -5
  23. package/dist/react.js +592 -512
  24. package/dist/react.mjs +136 -58
  25. package/dist/server.d.mts +54 -3
  26. package/dist/server.d.ts +54 -3
  27. package/dist/server.js +222 -3
  28. package/dist/server.mjs +212 -3
  29. package/dist/{ads-C2c2Aald.d.mts → sign-in-TL01-awQ.d.mts} +17 -1
  30. package/dist/{ads-C2c2Aald.d.ts → sign-in-TL01-awQ.d.ts} +17 -1
  31. package/dist/styles.css +1 -1
  32. package/dist/testing/suite.d.mts +2 -2
  33. package/dist/testing/suite.d.ts +2 -2
  34. package/dist/testing/suite.js +22 -22
  35. package/dist/testing/suite.mjs +3 -3
  36. package/dist/testing.d.mts +17 -17
  37. package/dist/testing.d.ts +17 -17
  38. package/dist/testing.js +78 -78
  39. package/dist/testing.mjs +4 -4
  40. package/package.json +2 -1
  41. package/registry/account.json +1 -1
  42. package/dist/chunk-MN4PNKJA.js +0 -129
  43. package/dist/chunk-NRDRVZ62.mjs +0 -119
package/dist/server.js CHANGED
@@ -1,11 +1,12 @@
1
1
  'use strict';
2
2
 
3
- var chunkIJ32BXKZ_js = require('./chunk-IJ32BXKZ.js');
4
- require('./chunk-YJLOOC3L.js');
3
+ var chunkMW7ICTVK_js = require('./chunk-MW7ICTVK.js');
4
+ require('./chunk-JGBDWEPJ.js');
5
5
  require('./chunk-7Y2O3E4D.js');
6
6
  var chunkXA3ZNR75_js = require('./chunk-XA3ZNR75.js');
7
7
  require('./chunk-OWW5GUSB.js');
8
8
  var react = require('react');
9
+ var jose = require('jose');
9
10
 
10
11
  var DEFAULT_PROD_URL = "https://storefronts.cimplify.io";
11
12
  var DEFAULT_DEV_URL = "http://127.0.0.1:8787";
@@ -25,7 +26,7 @@ function readEnv(...keys) {
25
26
  var getServerClient = react.cache((opts = {}) => {
26
27
  const baseUrl = opts.apiUrl ?? readEnv("CIMPLIFY_API_URL", "NEXT_PUBLIC_CIMPLIFY_API_URL") ?? defaultBaseUrl();
27
28
  const publicKey = opts.secretKey ?? readEnv("CIMPLIFY_SECRET_KEY", "NEXT_PUBLIC_CIMPLIFY_PUBLIC_KEY") ?? "mock-dev";
28
- const client = chunkIJ32BXKZ_js.createCimplifyClient({
29
+ const client = chunkMW7ICTVK_js.createCimplifyClient({
29
30
  baseUrl,
30
31
  publicKey,
31
32
  suppressPublicKeyWarning: true
@@ -33,6 +34,9 @@ var getServerClient = react.cache((opts = {}) => {
33
34
  if (opts.locationId) {
34
35
  client.setLocationId(opts.locationId);
35
36
  }
37
+ if (opts.accessToken) {
38
+ client.setAccessToken(opts.accessToken);
39
+ }
36
40
  return client;
37
41
  });
38
42
 
@@ -233,6 +237,211 @@ async function refreshPage() {
233
237
  const fn = await getRefresh();
234
238
  fn();
235
239
  }
240
+ var DEFAULT_AUTH_URL = "https://auth.cimplify.io";
241
+ var SESSION_COOKIE = "cimplify_session";
242
+ var ACCESS_TOKEN_COOKIE = "cimplify_access";
243
+ var discoveryCache = /* @__PURE__ */ new Map();
244
+ var jwksCache = /* @__PURE__ */ new Map();
245
+ function authUrl(cfg) {
246
+ return (cfg.authUrl ?? DEFAULT_AUTH_URL).replace(/\/$/, "");
247
+ }
248
+ function cookieName(cfg) {
249
+ return cfg.cookieName ?? SESSION_COOKIE;
250
+ }
251
+ function accessTokenCookieName(cfg) {
252
+ return cfg.accessTokenCookieName ?? ACCESS_TOKEN_COOKIE;
253
+ }
254
+ async function discovery(cfg) {
255
+ const base = authUrl(cfg);
256
+ let p = discoveryCache.get(base);
257
+ if (!p) {
258
+ p = fetch(`${base}/.well-known/openid-configuration`, {
259
+ next: { revalidate: 3600 }
260
+ }).then((r) => {
261
+ if (!r.ok) throw new Error(`oidc discovery failed: ${r.status}`);
262
+ return r.json();
263
+ });
264
+ discoveryCache.set(base, p);
265
+ }
266
+ return p;
267
+ }
268
+ async function jwks(cfg) {
269
+ const doc = await discovery(cfg);
270
+ let set = jwksCache.get(doc.jwks_uri);
271
+ if (!set) {
272
+ set = jose.createRemoteJWKSet(new URL(doc.jwks_uri));
273
+ jwksCache.set(doc.jwks_uri, set);
274
+ }
275
+ return { set, issuer: doc.issuer };
276
+ }
277
+ async function exchangeCode(opts) {
278
+ const doc = await discovery(opts);
279
+ const body = new URLSearchParams({
280
+ grant_type: "authorization_code",
281
+ code: opts.code,
282
+ code_verifier: opts.codeVerifier,
283
+ redirect_uri: opts.redirectUri,
284
+ client_id: opts.clientId
285
+ });
286
+ const res = await fetch(doc.token_endpoint, {
287
+ method: "POST",
288
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
289
+ body: body.toString()
290
+ });
291
+ if (!res.ok) {
292
+ const text = await res.text().catch(() => "");
293
+ throw new Error(`token exchange failed (${res.status}): ${text}`);
294
+ }
295
+ const payload = await res.json();
296
+ return {
297
+ accessToken: payload.access_token,
298
+ idToken: payload.id_token,
299
+ refreshToken: payload.refresh_token,
300
+ expiresIn: payload.expires_in,
301
+ scope: payload.scope
302
+ };
303
+ }
304
+ async function verifyIdToken(cfg, idToken) {
305
+ const { set, issuer } = await jwks(cfg);
306
+ return jose.jwtVerify(idToken, set, {
307
+ issuer,
308
+ audience: cfg.clientId
309
+ });
310
+ }
311
+ function payloadToSession(payload) {
312
+ return {
313
+ sub: String(payload.sub ?? ""),
314
+ name: payload.name,
315
+ email: payload.email,
316
+ emailVerified: payload.email_verified,
317
+ phoneNumber: payload.phone_number,
318
+ phoneNumberVerified: payload.phone_number_verified,
319
+ exp: Number(payload.exp ?? 0),
320
+ iat: Number(payload.iat ?? 0)
321
+ };
322
+ }
323
+ function buildSessionCookie(cfg, idToken, maxAgeSeconds) {
324
+ const name = cookieName(cfg);
325
+ const parts = [
326
+ `${name}=${idToken}`,
327
+ "Path=/",
328
+ "HttpOnly",
329
+ "Secure",
330
+ "SameSite=Lax",
331
+ `Max-Age=${maxAgeSeconds}`
332
+ ];
333
+ if (cfg.cookieDomain) parts.push(`Domain=${cfg.cookieDomain}`);
334
+ return parts.join("; ");
335
+ }
336
+ function buildSignoutCookie(cfg) {
337
+ const name = cookieName(cfg);
338
+ const parts = [`${name}=`, "Path=/", "HttpOnly", "Secure", "SameSite=Lax", "Max-Age=0"];
339
+ if (cfg.cookieDomain) parts.push(`Domain=${cfg.cookieDomain}`);
340
+ return parts.join("; ");
341
+ }
342
+ function buildAccessTokenCookie(cfg, accessToken, maxAgeSeconds) {
343
+ const parts = [
344
+ `${accessTokenCookieName(cfg)}=${accessToken}`,
345
+ "Path=/",
346
+ "HttpOnly",
347
+ "Secure",
348
+ "SameSite=Lax",
349
+ `Max-Age=${maxAgeSeconds}`
350
+ ];
351
+ if (cfg.cookieDomain) parts.push(`Domain=${cfg.cookieDomain}`);
352
+ return parts.join("; ");
353
+ }
354
+ function buildSignoutCookies(cfg) {
355
+ const idTokenParts = [
356
+ `${cookieName(cfg)}=`,
357
+ "Path=/",
358
+ "HttpOnly",
359
+ "Secure",
360
+ "SameSite=Lax",
361
+ "Max-Age=0"
362
+ ];
363
+ const accessParts = [
364
+ `${accessTokenCookieName(cfg)}=`,
365
+ "Path=/",
366
+ "HttpOnly",
367
+ "Secure",
368
+ "SameSite=Lax",
369
+ "Max-Age=0"
370
+ ];
371
+ if (cfg.cookieDomain) {
372
+ idTokenParts.push(`Domain=${cfg.cookieDomain}`);
373
+ accessParts.push(`Domain=${cfg.cookieDomain}`);
374
+ }
375
+ return [idTokenParts.join("; "), accessParts.join("; ")];
376
+ }
377
+ function getAccessTokenFromCookieHeader(cfg, cookieHeader) {
378
+ if (!cookieHeader) return null;
379
+ const name = accessTokenCookieName(cfg);
380
+ const match = cookieHeader.split(/;\s*/).find((p) => p.startsWith(`${name}=`));
381
+ if (!match) return null;
382
+ const token = match.slice(name.length + 1);
383
+ return token || null;
384
+ }
385
+ async function handleOidcCallback(req, opts) {
386
+ let body;
387
+ try {
388
+ body = await req.json();
389
+ } catch {
390
+ return Response.json({ error: "invalid_json" }, { status: 400 });
391
+ }
392
+ if (!body.code || !body.codeVerifier) {
393
+ return Response.json({ error: "missing_code_or_verifier" }, { status: 400 });
394
+ }
395
+ let tokens;
396
+ try {
397
+ tokens = await exchangeCode({
398
+ ...opts,
399
+ code: body.code,
400
+ codeVerifier: body.codeVerifier
401
+ });
402
+ } catch (e) {
403
+ return Response.json({ error: "exchange_failed", detail: String(e) }, { status: 400 });
404
+ }
405
+ if (!tokens.idToken) {
406
+ return Response.json({ error: "missing_id_token" }, { status: 400 });
407
+ }
408
+ try {
409
+ await verifyIdToken(opts, tokens.idToken);
410
+ } catch (e) {
411
+ return Response.json({ error: "id_token_invalid", detail: String(e) }, { status: 401 });
412
+ }
413
+ const headers = new Headers({ "Content-Type": "application/json" });
414
+ headers.append("Set-Cookie", buildSessionCookie(opts, tokens.idToken, tokens.expiresIn));
415
+ headers.append("Set-Cookie", buildAccessTokenCookie(opts, tokens.accessToken, tokens.expiresIn));
416
+ return new Response(JSON.stringify({ ok: true }), { status: 200, headers });
417
+ }
418
+ async function handleSessionRequest(req, cfg) {
419
+ const session = await getSessionFromCookieHeader(cfg, req.headers.get("cookie"));
420
+ if (!session) {
421
+ return new Response(JSON.stringify({ sub: null }), {
422
+ status: 200,
423
+ headers: { "Content-Type": "application/json", "Cache-Control": "no-store" }
424
+ });
425
+ }
426
+ return new Response(JSON.stringify(session), {
427
+ status: 200,
428
+ headers: { "Content-Type": "application/json", "Cache-Control": "no-store" }
429
+ });
430
+ }
431
+ async function getSessionFromCookieHeader(cfg, cookieHeader) {
432
+ if (!cookieHeader) return null;
433
+ const name = cookieName(cfg);
434
+ const match = cookieHeader.split(/;\s*/).find((p) => p.startsWith(`${name}=`));
435
+ if (!match) return null;
436
+ const token = match.slice(name.length + 1);
437
+ if (!token) return null;
438
+ try {
439
+ const { payload } = await verifyIdToken(cfg, token);
440
+ return payloadToSession(payload);
441
+ } catch {
442
+ return null;
443
+ }
444
+ }
236
445
 
237
446
  Object.defineProperty(exports, "CimplifyError", {
238
447
  enumerable: true,
@@ -240,7 +449,16 @@ Object.defineProperty(exports, "CimplifyError", {
240
449
  });
241
450
  exports.CACHE_LIFE_DEFAULT = CACHE_LIFE_DEFAULT;
242
451
  exports.CACHE_LIFE_PROBE = CACHE_LIFE_PROBE;
452
+ exports.buildAccessTokenCookie = buildAccessTokenCookie;
453
+ exports.buildSessionCookie = buildSessionCookie;
454
+ exports.buildSignoutCookie = buildSignoutCookie;
455
+ exports.buildSignoutCookies = buildSignoutCookies;
456
+ exports.exchangeCode = exchangeCode;
457
+ exports.getAccessTokenFromCookieHeader = getAccessTokenFromCookieHeader;
243
458
  exports.getServerClient = getServerClient;
459
+ exports.getSessionFromCookieHeader = getSessionFromCookieHeader;
460
+ exports.handleOidcCallback = handleOidcCallback;
461
+ exports.handleSessionRequest = handleSessionRequest;
244
462
  exports.refreshPage = refreshPage;
245
463
  exports.revalidateAddOn = revalidateAddOn;
246
464
  exports.revalidateAddOns = revalidateAddOns;
@@ -277,3 +495,4 @@ exports.updateProducts = updateProducts;
277
495
  exports.updateStock = updateStock;
278
496
  exports.updateSubscription = updateSubscription;
279
497
  exports.updateSubscriptions = updateSubscriptions;
498
+ exports.verifyIdToken = verifyIdToken;
package/dist/server.mjs CHANGED
@@ -1,9 +1,10 @@
1
- import { createCimplifyClient } from './chunk-6QZQQRBB.mjs';
2
- import './chunk-B3Y4C4A7.mjs';
1
+ import { createCimplifyClient } from './chunk-SQ7U3BWY.mjs';
2
+ import './chunk-I4IXPQIX.mjs';
3
3
  import './chunk-TD3AY34U.mjs';
4
4
  export { CimplifyError } from './chunk-AMZXALF6.mjs';
5
5
  import './chunk-3G6RQLXK.mjs';
6
6
  import { cache } from 'react';
7
+ import { jwtVerify, createRemoteJWKSet } from 'jose';
7
8
 
8
9
  var DEFAULT_PROD_URL = "https://storefronts.cimplify.io";
9
10
  var DEFAULT_DEV_URL = "http://127.0.0.1:8787";
@@ -31,6 +32,9 @@ var getServerClient = cache((opts = {}) => {
31
32
  if (opts.locationId) {
32
33
  client.setLocationId(opts.locationId);
33
34
  }
35
+ if (opts.accessToken) {
36
+ client.setAccessToken(opts.accessToken);
37
+ }
34
38
  return client;
35
39
  });
36
40
 
@@ -231,5 +235,210 @@ async function refreshPage() {
231
235
  const fn = await getRefresh();
232
236
  fn();
233
237
  }
238
+ var DEFAULT_AUTH_URL = "https://auth.cimplify.io";
239
+ var SESSION_COOKIE = "cimplify_session";
240
+ var ACCESS_TOKEN_COOKIE = "cimplify_access";
241
+ var discoveryCache = /* @__PURE__ */ new Map();
242
+ var jwksCache = /* @__PURE__ */ new Map();
243
+ function authUrl(cfg) {
244
+ return (cfg.authUrl ?? DEFAULT_AUTH_URL).replace(/\/$/, "");
245
+ }
246
+ function cookieName(cfg) {
247
+ return cfg.cookieName ?? SESSION_COOKIE;
248
+ }
249
+ function accessTokenCookieName(cfg) {
250
+ return cfg.accessTokenCookieName ?? ACCESS_TOKEN_COOKIE;
251
+ }
252
+ async function discovery(cfg) {
253
+ const base = authUrl(cfg);
254
+ let p = discoveryCache.get(base);
255
+ if (!p) {
256
+ p = fetch(`${base}/.well-known/openid-configuration`, {
257
+ next: { revalidate: 3600 }
258
+ }).then((r) => {
259
+ if (!r.ok) throw new Error(`oidc discovery failed: ${r.status}`);
260
+ return r.json();
261
+ });
262
+ discoveryCache.set(base, p);
263
+ }
264
+ return p;
265
+ }
266
+ async function jwks(cfg) {
267
+ const doc = await discovery(cfg);
268
+ let set = jwksCache.get(doc.jwks_uri);
269
+ if (!set) {
270
+ set = createRemoteJWKSet(new URL(doc.jwks_uri));
271
+ jwksCache.set(doc.jwks_uri, set);
272
+ }
273
+ return { set, issuer: doc.issuer };
274
+ }
275
+ async function exchangeCode(opts) {
276
+ const doc = await discovery(opts);
277
+ const body = new URLSearchParams({
278
+ grant_type: "authorization_code",
279
+ code: opts.code,
280
+ code_verifier: opts.codeVerifier,
281
+ redirect_uri: opts.redirectUri,
282
+ client_id: opts.clientId
283
+ });
284
+ const res = await fetch(doc.token_endpoint, {
285
+ method: "POST",
286
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
287
+ body: body.toString()
288
+ });
289
+ if (!res.ok) {
290
+ const text = await res.text().catch(() => "");
291
+ throw new Error(`token exchange failed (${res.status}): ${text}`);
292
+ }
293
+ const payload = await res.json();
294
+ return {
295
+ accessToken: payload.access_token,
296
+ idToken: payload.id_token,
297
+ refreshToken: payload.refresh_token,
298
+ expiresIn: payload.expires_in,
299
+ scope: payload.scope
300
+ };
301
+ }
302
+ async function verifyIdToken(cfg, idToken) {
303
+ const { set, issuer } = await jwks(cfg);
304
+ return jwtVerify(idToken, set, {
305
+ issuer,
306
+ audience: cfg.clientId
307
+ });
308
+ }
309
+ function payloadToSession(payload) {
310
+ return {
311
+ sub: String(payload.sub ?? ""),
312
+ name: payload.name,
313
+ email: payload.email,
314
+ emailVerified: payload.email_verified,
315
+ phoneNumber: payload.phone_number,
316
+ phoneNumberVerified: payload.phone_number_verified,
317
+ exp: Number(payload.exp ?? 0),
318
+ iat: Number(payload.iat ?? 0)
319
+ };
320
+ }
321
+ function buildSessionCookie(cfg, idToken, maxAgeSeconds) {
322
+ const name = cookieName(cfg);
323
+ const parts = [
324
+ `${name}=${idToken}`,
325
+ "Path=/",
326
+ "HttpOnly",
327
+ "Secure",
328
+ "SameSite=Lax",
329
+ `Max-Age=${maxAgeSeconds}`
330
+ ];
331
+ if (cfg.cookieDomain) parts.push(`Domain=${cfg.cookieDomain}`);
332
+ return parts.join("; ");
333
+ }
334
+ function buildSignoutCookie(cfg) {
335
+ const name = cookieName(cfg);
336
+ const parts = [`${name}=`, "Path=/", "HttpOnly", "Secure", "SameSite=Lax", "Max-Age=0"];
337
+ if (cfg.cookieDomain) parts.push(`Domain=${cfg.cookieDomain}`);
338
+ return parts.join("; ");
339
+ }
340
+ function buildAccessTokenCookie(cfg, accessToken, maxAgeSeconds) {
341
+ const parts = [
342
+ `${accessTokenCookieName(cfg)}=${accessToken}`,
343
+ "Path=/",
344
+ "HttpOnly",
345
+ "Secure",
346
+ "SameSite=Lax",
347
+ `Max-Age=${maxAgeSeconds}`
348
+ ];
349
+ if (cfg.cookieDomain) parts.push(`Domain=${cfg.cookieDomain}`);
350
+ return parts.join("; ");
351
+ }
352
+ function buildSignoutCookies(cfg) {
353
+ const idTokenParts = [
354
+ `${cookieName(cfg)}=`,
355
+ "Path=/",
356
+ "HttpOnly",
357
+ "Secure",
358
+ "SameSite=Lax",
359
+ "Max-Age=0"
360
+ ];
361
+ const accessParts = [
362
+ `${accessTokenCookieName(cfg)}=`,
363
+ "Path=/",
364
+ "HttpOnly",
365
+ "Secure",
366
+ "SameSite=Lax",
367
+ "Max-Age=0"
368
+ ];
369
+ if (cfg.cookieDomain) {
370
+ idTokenParts.push(`Domain=${cfg.cookieDomain}`);
371
+ accessParts.push(`Domain=${cfg.cookieDomain}`);
372
+ }
373
+ return [idTokenParts.join("; "), accessParts.join("; ")];
374
+ }
375
+ function getAccessTokenFromCookieHeader(cfg, cookieHeader) {
376
+ if (!cookieHeader) return null;
377
+ const name = accessTokenCookieName(cfg);
378
+ const match = cookieHeader.split(/;\s*/).find((p) => p.startsWith(`${name}=`));
379
+ if (!match) return null;
380
+ const token = match.slice(name.length + 1);
381
+ return token || null;
382
+ }
383
+ async function handleOidcCallback(req, opts) {
384
+ let body;
385
+ try {
386
+ body = await req.json();
387
+ } catch {
388
+ return Response.json({ error: "invalid_json" }, { status: 400 });
389
+ }
390
+ if (!body.code || !body.codeVerifier) {
391
+ return Response.json({ error: "missing_code_or_verifier" }, { status: 400 });
392
+ }
393
+ let tokens;
394
+ try {
395
+ tokens = await exchangeCode({
396
+ ...opts,
397
+ code: body.code,
398
+ codeVerifier: body.codeVerifier
399
+ });
400
+ } catch (e) {
401
+ return Response.json({ error: "exchange_failed", detail: String(e) }, { status: 400 });
402
+ }
403
+ if (!tokens.idToken) {
404
+ return Response.json({ error: "missing_id_token" }, { status: 400 });
405
+ }
406
+ try {
407
+ await verifyIdToken(opts, tokens.idToken);
408
+ } catch (e) {
409
+ return Response.json({ error: "id_token_invalid", detail: String(e) }, { status: 401 });
410
+ }
411
+ const headers = new Headers({ "Content-Type": "application/json" });
412
+ headers.append("Set-Cookie", buildSessionCookie(opts, tokens.idToken, tokens.expiresIn));
413
+ headers.append("Set-Cookie", buildAccessTokenCookie(opts, tokens.accessToken, tokens.expiresIn));
414
+ return new Response(JSON.stringify({ ok: true }), { status: 200, headers });
415
+ }
416
+ async function handleSessionRequest(req, cfg) {
417
+ const session = await getSessionFromCookieHeader(cfg, req.headers.get("cookie"));
418
+ if (!session) {
419
+ return new Response(JSON.stringify({ sub: null }), {
420
+ status: 200,
421
+ headers: { "Content-Type": "application/json", "Cache-Control": "no-store" }
422
+ });
423
+ }
424
+ return new Response(JSON.stringify(session), {
425
+ status: 200,
426
+ headers: { "Content-Type": "application/json", "Cache-Control": "no-store" }
427
+ });
428
+ }
429
+ async function getSessionFromCookieHeader(cfg, cookieHeader) {
430
+ if (!cookieHeader) return null;
431
+ const name = cookieName(cfg);
432
+ const match = cookieHeader.split(/;\s*/).find((p) => p.startsWith(`${name}=`));
433
+ if (!match) return null;
434
+ const token = match.slice(name.length + 1);
435
+ if (!token) return null;
436
+ try {
437
+ const { payload } = await verifyIdToken(cfg, token);
438
+ return payloadToSession(payload);
439
+ } catch {
440
+ return null;
441
+ }
442
+ }
234
443
 
235
- export { CACHE_LIFE_DEFAULT, CACHE_LIFE_PROBE, getServerClient, refreshPage, revalidateAddOn, revalidateAddOns, revalidateBrand, revalidateBusiness, revalidateByTag, revalidateCategories, revalidateCategory, revalidateCollection, revalidateCollections, revalidateLocation, revalidateLocations, revalidatePricing, revalidateProduct, revalidateProducts, revalidateStock, revalidateSubscription, revalidateSubscriptions, tags, updateAddOn, updateAddOns, updateBrand, updateBusiness, updateByTag, updateCategories, updateCategory, updateCollection, updateCollections, updateLocation, updateLocations, updatePricing, updateProduct, updateProducts, updateStock, updateSubscription, updateSubscriptions };
444
+ export { CACHE_LIFE_DEFAULT, CACHE_LIFE_PROBE, buildAccessTokenCookie, buildSessionCookie, buildSignoutCookie, buildSignoutCookies, exchangeCode, getAccessTokenFromCookieHeader, getServerClient, getSessionFromCookieHeader, handleOidcCallback, handleSessionRequest, refreshPage, revalidateAddOn, revalidateAddOns, revalidateBrand, revalidateBusiness, revalidateByTag, revalidateCategories, revalidateCategory, revalidateCollection, revalidateCollections, revalidateLocation, revalidateLocations, revalidatePricing, revalidateProduct, revalidateProducts, revalidateStock, revalidateSubscription, revalidateSubscriptions, tags, updateAddOn, updateAddOns, updateBrand, updateBusiness, updateByTag, updateCategories, updateCategory, updateCollection, updateCollections, updateLocation, updateLocations, updatePricing, updateProduct, updateProducts, updateStock, updateSubscription, updateSubscriptions, verifyIdToken };
@@ -25,4 +25,20 @@ interface AdContextValue {
25
25
  isLoading: boolean;
26
26
  }
27
27
 
28
- export { type AdConfig as A, type AdContextValue as a, type AdCreative as b, type AdPosition as c, type AdSlot as d, type AdTheme as e, getVariantDisplayName as g };
28
+ interface SignInOptions {
29
+ clientId: string;
30
+ redirectUri: string;
31
+ callbackUri?: string;
32
+ scope?: string;
33
+ authUrl?: string;
34
+ loginHint?: string;
35
+ prompt?: "none" | "login" | "consent";
36
+ onError?: (err: {
37
+ error: string;
38
+ description?: string;
39
+ }) => void;
40
+ onSuccess?: () => void;
41
+ }
42
+ declare function startSignIn(opts: SignInOptions): Promise<void>;
43
+
44
+ export { type AdConfig as A, type SignInOptions as S, type AdContextValue as a, type AdCreative as b, type AdPosition as c, type AdSlot as d, type AdTheme as e, getVariantDisplayName as g, startSignIn as s };
@@ -25,4 +25,20 @@ interface AdContextValue {
25
25
  isLoading: boolean;
26
26
  }
27
27
 
28
- export { type AdConfig as A, type AdContextValue as a, type AdCreative as b, type AdPosition as c, type AdSlot as d, type AdTheme as e, getVariantDisplayName as g };
28
+ interface SignInOptions {
29
+ clientId: string;
30
+ redirectUri: string;
31
+ callbackUri?: string;
32
+ scope?: string;
33
+ authUrl?: string;
34
+ loginHint?: string;
35
+ prompt?: "none" | "login" | "consent";
36
+ onError?: (err: {
37
+ error: string;
38
+ description?: string;
39
+ }) => void;
40
+ onSuccess?: () => void;
41
+ }
42
+ declare function startSignIn(opts: SignInOptions): Promise<void>;
43
+
44
+ export { type AdConfig as A, type SignInOptions as S, type AdContextValue as a, type AdCreative as b, type AdPosition as c, type AdSlot as d, type AdTheme as e, getVariantDisplayName as g, startSignIn as s };