@palbase/web 1.0.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 (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +292 -0
  3. package/dist/analytics-facade-DkOwkEpi.d.ts +454 -0
  4. package/dist/analytics-facade-t6UrFdn7.d.cts +454 -0
  5. package/dist/chunk-JVT65V4E.js +3384 -0
  6. package/dist/chunk-JVT65V4E.js.map +1 -0
  7. package/dist/chunk-VJXFABBW.js +94 -0
  8. package/dist/chunk-VJXFABBW.js.map +1 -0
  9. package/dist/errors-fDoNdTrJ.d.cts +35 -0
  10. package/dist/errors-fDoNdTrJ.d.ts +35 -0
  11. package/dist/index.cjs +2394 -0
  12. package/dist/index.cjs.map +1 -0
  13. package/dist/index.d.cts +11 -0
  14. package/dist/index.d.ts +11 -0
  15. package/dist/index.js +27 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/internal.cjs +3403 -0
  18. package/dist/internal.cjs.map +1 -0
  19. package/dist/internal.d.cts +49 -0
  20. package/dist/internal.d.ts +49 -0
  21. package/dist/internal.js +19 -0
  22. package/dist/internal.js.map +1 -0
  23. package/dist/next/client.cjs +3131 -0
  24. package/dist/next/client.cjs.map +1 -0
  25. package/dist/next/client.d.cts +19 -0
  26. package/dist/next/client.d.ts +19 -0
  27. package/dist/next/client.js +75 -0
  28. package/dist/next/client.js.map +1 -0
  29. package/dist/next/index.cjs +3680 -0
  30. package/dist/next/index.cjs.map +1 -0
  31. package/dist/next/index.d.cts +238 -0
  32. package/dist/next/index.d.ts +238 -0
  33. package/dist/next/index.js +301 -0
  34. package/dist/next/index.js.map +1 -0
  35. package/dist/pb-BmgkAe97.d.ts +54 -0
  36. package/dist/pb-Cudze7Kb.d.cts +54 -0
  37. package/dist/react/index.cjs +649 -0
  38. package/dist/react/index.cjs.map +1 -0
  39. package/dist/react/index.d.cts +86 -0
  40. package/dist/react/index.d.ts +86 -0
  41. package/dist/react/index.js +156 -0
  42. package/dist/react/index.js.map +1 -0
  43. package/dist/storage-BPaeSG8K.d.cts +21 -0
  44. package/dist/storage-BPaeSG8K.d.ts +21 -0
  45. package/package.json +123 -0
@@ -0,0 +1,19 @@
1
+ import { S as SessionStorageAdapter } from '../storage-BPaeSG8K.cjs';
2
+
3
+ /**
4
+ * document.cookie-backed SessionStorageAdapter. `load` returns the EXTENDED
5
+ * PersistedSession (access token + expiry ride along) so hydration adopts
6
+ * the full session without a refresh round-trip.
7
+ */
8
+ declare function cookieSessionStorage(endpointRef: string): SessionStorageAdapter;
9
+ /**
10
+ * One-liner for a client component/provider: re-configure the already-loaded
11
+ * gen config (palbe.gen.ts must be imported first — throws the guided
12
+ * notConfigured error otherwise) with cookie-backed session storage so the
13
+ * browser and the server share the session. Calling it again simply
14
+ * re-configures (safe, e.g. under fast refresh). When Next evaluates the
15
+ * client component module server-side there is no document — no-op.
16
+ */
17
+ declare function setupPalbeNext(): void;
18
+
19
+ export { cookieSessionStorage, setupPalbeNext };
@@ -0,0 +1,19 @@
1
+ import { S as SessionStorageAdapter } from '../storage-BPaeSG8K.js';
2
+
3
+ /**
4
+ * document.cookie-backed SessionStorageAdapter. `load` returns the EXTENDED
5
+ * PersistedSession (access token + expiry ride along) so hydration adopts
6
+ * the full session without a refresh round-trip.
7
+ */
8
+ declare function cookieSessionStorage(endpointRef: string): SessionStorageAdapter;
9
+ /**
10
+ * One-liner for a client component/provider: re-configure the already-loaded
11
+ * gen config (palbe.gen.ts must be imported first — throws the guided
12
+ * notConfigured error otherwise) with cookie-backed session storage so the
13
+ * browser and the server share the session. Calling it again simply
14
+ * re-configures (safe, e.g. under fast refresh). When Next evaluates the
15
+ * client component module server-side there is no document — no-op.
16
+ */
17
+ declare function setupPalbeNext(): void;
18
+
19
+ export { cookieSessionStorage, setupPalbeNext };
@@ -0,0 +1,75 @@
1
+ import {
2
+ clearedSessionCookieNames,
3
+ decodeSessionCookies,
4
+ encodeSessionCookies
5
+ } from "../chunk-VJXFABBW.js";
6
+ import {
7
+ __configure,
8
+ endpointRefFromApiKey,
9
+ getRuntime
10
+ } from "../chunk-JVT65V4E.js";
11
+
12
+ // src/next/client.ts
13
+ var SESSION_MAX_AGE_S = 2592e3;
14
+ var WRITE_ATTRS = "Path=/; SameSite=Lax; Secure";
15
+ function cookieJar() {
16
+ const jar = /* @__PURE__ */ new Map();
17
+ for (const part of document.cookie.split(";")) {
18
+ const eq = part.indexOf("=");
19
+ if (eq === -1) continue;
20
+ const name = part.slice(0, eq).trim();
21
+ if (name) jar.set(name, part.slice(eq + 1).trim());
22
+ }
23
+ return jar;
24
+ }
25
+ function deleteCookie(name) {
26
+ document.cookie = `${name}=; ${WRITE_ATTRS}; Max-Age=0`;
27
+ }
28
+ function cookieSessionStorage(endpointRef) {
29
+ return {
30
+ load() {
31
+ if (typeof document === "undefined") return null;
32
+ const jar = cookieJar();
33
+ const stored = decodeSessionCookies((name) => jar.get(name), endpointRef);
34
+ if (!stored) return null;
35
+ return stored.accessToken && stored.expiresAt > 0 ? {
36
+ refreshToken: stored.refreshToken,
37
+ accessToken: stored.accessToken,
38
+ expiresAt: stored.expiresAt
39
+ } : { refreshToken: stored.refreshToken };
40
+ },
41
+ save(session) {
42
+ if (typeof document === "undefined") return;
43
+ const jar = cookieJar();
44
+ for (const name of clearedSessionCookieNames(endpointRef, (n) => jar.has(n))) {
45
+ deleteCookie(name);
46
+ }
47
+ const { set, clear } = encodeSessionCookies(endpointRef, {
48
+ accessToken: session.accessToken ?? "",
49
+ refreshToken: session.refreshToken,
50
+ expiresAt: session.expiresAt ?? 0
51
+ });
52
+ for (const { name, value } of set) {
53
+ document.cookie = `${name}=${value}; ${WRITE_ATTRS}; Max-Age=${SESSION_MAX_AGE_S}`;
54
+ }
55
+ for (const name of clear) deleteCookie(name);
56
+ },
57
+ clear() {
58
+ if (typeof document === "undefined") return;
59
+ const jar = cookieJar();
60
+ for (const name of clearedSessionCookieNames(endpointRef, (n) => jar.has(n))) {
61
+ deleteCookie(name);
62
+ }
63
+ }
64
+ };
65
+ }
66
+ function setupPalbeNext() {
67
+ if (typeof document === "undefined") return;
68
+ const config = getRuntime().config;
69
+ __configure({ ...config, storage: cookieSessionStorage(endpointRefFromApiKey(config.apiKey)) });
70
+ }
71
+ export {
72
+ cookieSessionStorage,
73
+ setupPalbeNext
74
+ };
75
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/next/client.ts"],"sourcesContent":["/**\n * '@palbase/web/next/client' — the browser half of the Next.js adapter. This entry\n * must NEVER import 'next' (it runs in plain client bundles); the cookie jar\n * is document.cookie itself, written with the shared codec so the server\n * side (pbServer / middleware / callback) reads the same bytes.\n */\nimport { __configure, getRuntime } from '../internal.js';\nimport type { PersistedSession, SessionStorageAdapter } from '../storage.js';\nimport {\n clearedSessionCookieNames,\n decodeSessionCookies,\n encodeSessionCookies,\n endpointRefFromApiKey,\n} from './cookie-codec.js';\n\n/** 30 days — the refresh-token TTL (P3 design contract). */\nconst SESSION_MAX_AGE_S = 2_592_000;\n\n// Secure is unconditional, INCLUDING http://localhost: browsers treat\n// localhost as a potentially-trustworthy origin, so document.cookie accepts\n// Secure cookies there — no dev-mode special case needed. KNOWN LIMITATION:\n// plain-http origins OTHER than localhost — e.g. LAN-IP device testing on\n// http://192.168.x.x — are NOT trustworthy, so the browser silently DROPS\n// these Secure cookie writes and the session won't persist; use https (or a\n// localhost tunnel/port-forward) for on-device testing. NOT HttpOnly by\n// design: the browser SDK must read/write the session (Supabase-paradigm\n// tradeoff, documented in the P3 plan).\nconst WRITE_ATTRS = 'Path=/; SameSite=Lax; Secure';\n\n/** Parse document.cookie (\"a=1; b=2\") into a name → raw-value map. */\nfunction cookieJar(): Map<string, string> {\n const jar = new Map<string, string>();\n for (const part of document.cookie.split(';')) {\n const eq = part.indexOf('=');\n if (eq === -1) continue;\n const name = part.slice(0, eq).trim();\n if (name) jar.set(name, part.slice(eq + 1).trim());\n }\n return jar;\n}\n\nfunction deleteCookie(name: string): void {\n // biome-ignore lint/suspicious/noDocumentCookie: SessionStorageAdapter is a SYNC contract; the async Cookie Store API can't back it (and isn't universal).\n document.cookie = `${name}=; ${WRITE_ATTRS}; Max-Age=0`;\n}\n\n/**\n * document.cookie-backed SessionStorageAdapter. `load` returns the EXTENDED\n * PersistedSession (access token + expiry ride along) so hydration adopts\n * the full session without a refresh round-trip.\n */\nexport function cookieSessionStorage(endpointRef: string): SessionStorageAdapter {\n return {\n load(): PersistedSession | null {\n if (typeof document === 'undefined') return null;\n const jar = cookieJar();\n const stored = decodeSessionCookies((name) => jar.get(name), endpointRef);\n if (!stored) return null;\n // A refresh-only save round-trips as a:'' / e:0 — normalize back to\n // the legacy shape so hydration takes the expired-trick path cleanly.\n return stored.accessToken && stored.expiresAt > 0\n ? {\n refreshToken: stored.refreshToken,\n accessToken: stored.accessToken,\n expiresAt: stored.expiresAt,\n }\n : { refreshToken: stored.refreshToken };\n },\n save(session: PersistedSession): void {\n if (typeof document === 'undefined') return;\n const jar = cookieJar();\n // Delete every currently-present session cookie first (stale chunks of\n // a previously-larger session, or a stale base when the new write\n // chunks), then set the new cookie(s).\n for (const name of clearedSessionCookieNames(endpointRef, (n) => jar.has(n))) {\n deleteCookie(name);\n }\n const { set, clear } = encodeSessionCookies(endpointRef, {\n accessToken: session.accessToken ?? '',\n refreshToken: session.refreshToken,\n expiresAt: session.expiresAt ?? 0,\n });\n for (const { name, value } of set) {\n // biome-ignore lint/suspicious/noDocumentCookie: SessionStorageAdapter is a SYNC contract; the async Cookie Store API can't back it (and isn't universal).\n document.cookie = `${name}=${value}; ${WRITE_ATTRS}; Max-Age=${SESSION_MAX_AGE_S}`;\n }\n // Overflow guard (codec contract): delete one-past-the-end so a stale\n // orphan chunk behind a gap can never join a future chunk run.\n for (const name of clear) deleteCookie(name);\n },\n clear(): void {\n if (typeof document === 'undefined') return;\n const jar = cookieJar();\n for (const name of clearedSessionCookieNames(endpointRef, (n) => jar.has(n))) {\n deleteCookie(name);\n }\n },\n };\n}\n\n/**\n * One-liner for a client component/provider: re-configure the already-loaded\n * gen config (palbe.gen.ts must be imported first — throws the guided\n * notConfigured error otherwise) with cookie-backed session storage so the\n * browser and the server share the session. Calling it again simply\n * re-configures (safe, e.g. under fast refresh). When Next evaluates the\n * client component module server-side there is no document — no-op.\n */\nexport function setupPalbeNext(): void {\n if (typeof document === 'undefined') return;\n const config = getRuntime().config;\n __configure({ ...config, storage: cookieSessionStorage(endpointRefFromApiKey(config.apiKey)) });\n}\n"],"mappings":";;;;;;;;;;;;AAgBA,IAAM,oBAAoB;AAW1B,IAAM,cAAc;AAGpB,SAAS,YAAiC;AACxC,QAAM,MAAM,oBAAI,IAAoB;AACpC,aAAW,QAAQ,SAAS,OAAO,MAAM,GAAG,GAAG;AAC7C,UAAM,KAAK,KAAK,QAAQ,GAAG;AAC3B,QAAI,OAAO,GAAI;AACf,UAAM,OAAO,KAAK,MAAM,GAAG,EAAE,EAAE,KAAK;AACpC,QAAI,KAAM,KAAI,IAAI,MAAM,KAAK,MAAM,KAAK,CAAC,EAAE,KAAK,CAAC;AAAA,EACnD;AACA,SAAO;AACT;AAEA,SAAS,aAAa,MAAoB;AAExC,WAAS,SAAS,GAAG,IAAI,MAAM,WAAW;AAC5C;AAOO,SAAS,qBAAqB,aAA4C;AAC/E,SAAO;AAAA,IACL,OAAgC;AAC9B,UAAI,OAAO,aAAa,YAAa,QAAO;AAC5C,YAAM,MAAM,UAAU;AACtB,YAAM,SAAS,qBAAqB,CAAC,SAAS,IAAI,IAAI,IAAI,GAAG,WAAW;AACxE,UAAI,CAAC,OAAQ,QAAO;AAGpB,aAAO,OAAO,eAAe,OAAO,YAAY,IAC5C;AAAA,QACE,cAAc,OAAO;AAAA,QACrB,aAAa,OAAO;AAAA,QACpB,WAAW,OAAO;AAAA,MACpB,IACA,EAAE,cAAc,OAAO,aAAa;AAAA,IAC1C;AAAA,IACA,KAAK,SAAiC;AACpC,UAAI,OAAO,aAAa,YAAa;A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