@palbase/web 4.0.0 → 4.0.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.
Files changed (48) hide show
  1. package/dist/_mls-wasm.cjs +32 -0
  2. package/dist/_mls-wasm.cjs.map +1 -0
  3. package/dist/_mls-wasm.js +11 -0
  4. package/dist/_mls-wasm.js.map +1 -0
  5. package/dist/{analytics-facade-DwOtlXPP.d.cts → analytics-facade-CaluA4bW.d.cts} +26 -1
  6. package/dist/{analytics-facade-Nk6J9Ncm.d.ts → analytics-facade-Cp3d4QI-.d.ts} +26 -1
  7. package/dist/{chunk-S7NAY3MW.js → chunk-CFDU23TB.js} +3 -10
  8. package/dist/chunk-CFDU23TB.js.map +1 -0
  9. package/dist/chunk-PZ5AY32C.js +10 -0
  10. package/dist/chunk-PZ5AY32C.js.map +1 -0
  11. package/dist/{chunk-NP4NIY7A.js → chunk-TW6YN354.js} +84 -27
  12. package/dist/chunk-TW6YN354.js.map +1 -0
  13. package/dist/gen/cli.cjs +5 -5
  14. package/dist/gen/cli.cjs.map +1 -1
  15. package/dist/gen/cli.js +6 -5
  16. package/dist/gen/cli.js.map +1 -1
  17. package/dist/index.cjs +91 -27
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +3 -3
  20. package/dist/index.d.ts +3 -3
  21. package/dist/index.js +3 -2
  22. package/dist/internal.cjs +90 -26
  23. package/dist/internal.cjs.map +1 -1
  24. package/dist/internal.d.cts +3 -3
  25. package/dist/internal.d.ts +3 -3
  26. package/dist/internal.js +3 -2
  27. package/dist/next/client.cjs +90 -26
  28. package/dist/next/client.cjs.map +1 -1
  29. package/dist/next/client.js +3 -2
  30. package/dist/next/client.js.map +1 -1
  31. package/dist/next/index.cjs +81 -27
  32. package/dist/next/index.cjs.map +1 -1
  33. package/dist/next/index.d.cts +2 -2
  34. package/dist/next/index.d.ts +2 -2
  35. package/dist/next/index.js +3 -2
  36. package/dist/next/index.js.map +1 -1
  37. package/dist/{pb-FG_nV7NR.d.ts → pb-DUK5qy81.d.ts} +1 -1
  38. package/dist/{pb-C9v5dEO6.d.cts → pb-DvV6ftmf.d.cts} +1 -1
  39. package/dist/react/index.cjs +10 -2
  40. package/dist/react/index.cjs.map +1 -1
  41. package/dist/react/index.d.cts +1 -1
  42. package/dist/react/index.d.ts +1 -1
  43. package/dist/react/index.js +3 -2
  44. package/dist/react/index.js.map +1 -1
  45. package/package.json +10 -3
  46. package/dist/chunk-NP4NIY7A.js.map +0 -1
  47. package/dist/chunk-S7NAY3MW.js.map +0 -1
  48. package/dist/pkg/palbe_mls_bg.wasm +0 -0
@@ -1,7 +1,7 @@
1
- import { P as PalbeConfig } from './analytics-facade-DwOtlXPP.cjs';
2
- export { d as PalbeRuntime, e as buildRuntime } from './analytics-facade-DwOtlXPP.cjs';
1
+ import { P as PalbeConfig } from './analytics-facade-CaluA4bW.cjs';
2
+ export { d as PalbeRuntime, e as buildRuntime } from './analytics-facade-CaluA4bW.cjs';
3
3
  import { B as BackendError } from './errors-fDoNdTrJ.cjs';
4
- export { P as PB, c as createBoundClient } from './pb-C9v5dEO6.cjs';
4
+ export { P as PB, c as createBoundClient } from './pb-DvV6ftmf.cjs';
5
5
  import './storage-BPaeSG8K.cjs';
6
6
  import './pooled-flags-4GtDtsiu.js';
7
7
 
@@ -1,7 +1,7 @@
1
- import { P as PalbeConfig } from './analytics-facade-Nk6J9Ncm.js';
2
- export { d as PalbeRuntime, e as buildRuntime } from './analytics-facade-Nk6J9Ncm.js';
1
+ import { P as PalbeConfig } from './analytics-facade-Cp3d4QI-.js';
2
+ export { d as PalbeRuntime, e as buildRuntime } from './analytics-facade-Cp3d4QI-.js';
3
3
  import { B as BackendError } from './errors-fDoNdTrJ.js';
4
- export { P as PB, c as createBoundClient } from './pb-FG_nV7NR.js';
4
+ export { P as PB, c as createBoundClient } from './pb-DUK5qy81.js';
5
5
  import './storage-BPaeSG8K.js';
6
6
  import './pooled-flags-4GtDtsiu.js';
7
7
 
package/dist/internal.js CHANGED
@@ -6,8 +6,9 @@ import {
6
6
  createBoundClient,
7
7
  getRuntime,
8
8
  onConfigured
9
- } from "./chunk-NP4NIY7A.js";
10
- import "./chunk-S7NAY3MW.js";
9
+ } from "./chunk-TW6YN354.js";
10
+ import "./chunk-CFDU23TB.js";
11
+ import "./chunk-PZ5AY32C.js";
11
12
  export {
12
13
  __configure,
13
14
  __registerNamespaces,
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/next/client.ts
@@ -40,7 +50,7 @@ var PalbaseError = class extends Error {
40
50
  }
41
51
  };
42
52
  var PALBASE_DEFAULT_HOST = "api.palbase.studio";
43
- var API_KEY_RE = /^pb_([a-z0-9]+)_c[A-Za-z0-9]{20}$/;
53
+ var API_KEY_RE = /^pb_([a-z0-9]{4,24})_c[A-Za-z0-9]{20}$/;
44
54
  function parseEnvironmentRef(apiKey) {
45
55
  return API_KEY_RE.exec(apiKey)?.[1] ?? null;
46
56
  }
@@ -417,6 +427,11 @@ var PERF_EXCLUDED_PREFIX = "/v1/analytics/";
417
427
  function isSelfTraced(path) {
418
428
  return path.startsWith(PERF_EXCLUDED_PREFIX);
419
429
  }
430
+ function isSessionKilled(status, code) {
431
+ if (status === 401) return code === "session_revoked";
432
+ if (status === 403) return code === "subject_fenced" || code === "subject_erased";
433
+ return false;
434
+ }
420
435
  function nowMs() {
421
436
  return typeof performance !== "undefined" && typeof performance.now === "function" ? performance.now() : Date.now();
422
437
  }
@@ -452,7 +467,7 @@ async function palbeRequest(rt, method, path, spec = {}) {
452
467
  let res;
453
468
  try {
454
469
  res = await attempt();
455
- if (res.error?.status === 401 && rt.tokenManager.getRefreshToken() && rt.tokenManager.refreshFunction) {
470
+ if (res.error?.status === 401 && res.error.code !== "session_revoked" && rt.tokenManager.getRefreshToken() && rt.tokenManager.refreshFunction) {
456
471
  try {
457
472
  await rt.tokenManager.refreshSession();
458
473
  } catch (refreshErr) {
@@ -472,6 +487,9 @@ async function palbeRequest(rt, method, path, spec = {}) {
472
487
  if (!isAbort(e)) record(asPalbaseError(e)?.status ?? 0);
473
488
  throw e;
474
489
  }
490
+ if (res.error && isSessionKilled(res.error.status, res.error.code)) {
491
+ rt.auth.reactiveTeardown();
492
+ }
475
493
  record(res.error?.status ?? 200);
476
494
  return unwrap(res);
477
495
  }
@@ -1211,7 +1229,7 @@ var PalbeAnalytics = class {
1211
1229
  };
1212
1230
 
1213
1231
  // src/api-key.ts
1214
- var PUBLISHABLE_API_KEY_RE = /^pb_([a-z0-9]+)_c[A-Za-z0-9]{20}$/;
1232
+ var PUBLISHABLE_API_KEY_RE = /^pb_([a-z0-9]{4,24})_c[A-Za-z0-9]{20}$/;
1215
1233
  function environmentRefFromPublishableApiKey(apiKey) {
1216
1234
  const match = PUBLISHABLE_API_KEY_RE.exec(apiKey);
1217
1235
  return match ? match[1] ?? "" : "";
@@ -1258,7 +1276,8 @@ var PalbeAuth = class {
1258
1276
  if (!this.signedInState) return;
1259
1277
  this.signedInState = false;
1260
1278
  this.cachedUser = null;
1261
- const reason = this.signingOut ? "userInitiated" : "sessionExpired";
1279
+ const reason = this.nextSignOutReason ?? (this.signingOut ? "userInitiated" : "sessionExpired");
1280
+ this.nextSignOutReason = null;
1262
1281
  this.emitState({ status: "signedOut" });
1263
1282
  this.emitEvent({ type: "signedOut", reason });
1264
1283
  } else if (event === "TOKEN_REFRESHED") {
@@ -1271,6 +1290,10 @@ var PalbeAuth = class {
1271
1290
  rt;
1272
1291
  cachedUser = null;
1273
1292
  signingOut = false;
1293
+ // Explicit signedOut reason pinned for the NEXT session clear (deleteAccount /
1294
+ // reactiveTeardown set it before clearSession; the SIGNED_OUT handler consumes
1295
+ // it exactly once, then resets to null → normal signOut/expiry split resumes).
1296
+ nextSignOutReason = null;
1274
1297
  signingIn = false;
1275
1298
  // suppresses AuthClient's TOKEN_REFRESHED during re-signIn
1276
1299
  signedInState = false;
@@ -1318,6 +1341,45 @@ var PalbeAuth = class {
1318
1341
  this.cachedUser = null;
1319
1342
  }
1320
1343
  }
1344
+ /**
1345
+ * Self-service account erasure ("right to be forgotten"). Calls palauth
1346
+ * `DELETE /auth/user` (session-authed + fresh re-auth): password users pass
1347
+ * `{ password }`; passwordless/OAuth users rely on a freshly stepped-up
1348
+ * session. On 202 the erasure workflow is durably queued AND every session is
1349
+ * already revoked server-side — so we tear down local state (mirroring
1350
+ * `signOut()`'s clear, minus the pointless `/logout`) and emit
1351
+ * `signedOut{reason:'accountDeleted'}`.
1352
+ *
1353
+ * On 401 `reauth_required` / 503 `not_configured` (or `erasure_unavailable`)
1354
+ * the request throws BEFORE the teardown line, so the local session is left
1355
+ * fully intact — the deletion did not happen and the user is still signed in.
1356
+ */
1357
+ async deleteAccount(params = {}) {
1358
+ const res = await palbeRequest(this.rt, "DELETE", "/auth/user", {
1359
+ body: params.password ? { password: params.password } : {}
1360
+ });
1361
+ this.nextSignOutReason = "accountDeleted";
1362
+ this.rt.tokenManager.clearSession();
1363
+ this.rt.storage.clear();
1364
+ this.cachedUser = null;
1365
+ return { erasureId: res.erasure_id };
1366
+ }
1367
+ /**
1368
+ * @internal — invoked by the transport choke point (`request.ts`), not app code.
1369
+ * Reactive teardown when the server reports the session is gone: a 403
1370
+ * `subject_fenced`/`subject_erased` (subject being erased) or a 401
1371
+ * `session_revoked`. Clears local state and emits
1372
+ * `signedOut{reason:'sessionInvalid'}` exactly once (deduped by
1373
+ * `signedInState`). An ordinary 403 authz denial does NOT reach here —
1374
+ * `request.ts` matches only the exact session-kill codes.
1375
+ */
1376
+ reactiveTeardown() {
1377
+ if (!this.signedInState) return;
1378
+ this.nextSignOutReason = "sessionInvalid";
1379
+ this.rt.tokenManager.clearSession();
1380
+ this.rt.storage.clear();
1381
+ this.cachedUser = null;
1382
+ }
1321
1383
  async getUser() {
1322
1384
  const raw = await palbeRequest(this.rt, "GET", "/auth/user");
1323
1385
  return mapWireUser(raw);
@@ -6257,31 +6319,29 @@ function date_now() {
6257
6319
  }
6258
6320
 
6259
6321
  // src/messaging/wasm/loader.ts
6260
- var import_meta = {};
6261
6322
  var GLUE_MODULE = "./palbe_mls_bg.js";
6262
6323
  var SNIPPET_MODULE = "./snippets/mls-rs-core-f99cdecbb456b09c/inline0.js";
6263
6324
  var inflight = null;
6264
6325
  var ready = null;
6265
- async function loadWasmModule() {
6266
- const wasmUrl = new URL("./pkg/palbe_mls_bg.wasm", import_meta.url);
6267
- if (wasmUrl.protocol === "file:") {
6268
- const fsSpecifier = ["node", "fs/promises"].join(":");
6269
- const { readFile } = await import(
6270
- /* webpackIgnore: true */
6271
- fsSpecifier
6272
- );
6273
- const bytes = await readFile(wasmUrl);
6274
- return WebAssembly.compile(bytes);
6326
+ function decodeBase64(encoded) {
6327
+ if (typeof encoded !== "string" || encoded.length === 0 || typeof globalThis.atob !== "function") {
6328
+ throw new Error("palbe-mls WASM asset is invalid");
6275
6329
  }
6276
- const response = await fetch(wasmUrl);
6277
- if (typeof WebAssembly.compileStreaming === "function") {
6278
- try {
6279
- return await WebAssembly.compileStreaming(Promise.resolve(response));
6280
- } catch {
6281
- }
6330
+ let binary;
6331
+ try {
6332
+ binary = globalThis.atob(encoded);
6333
+ } catch {
6334
+ throw new Error("palbe-mls WASM asset is invalid");
6335
+ }
6336
+ const bytes = new Uint8Array(binary.length);
6337
+ for (let index = 0; index < binary.length; index += 1) {
6338
+ bytes[index] = binary.charCodeAt(index);
6282
6339
  }
6283
- const buffer = await response.arrayBuffer();
6284
- return WebAssembly.compile(buffer);
6340
+ return bytes.buffer;
6341
+ }
6342
+ async function loadWasmModule() {
6343
+ const asset = await import("#palbase-mls-wasm");
6344
+ return WebAssembly.compile(decodeBase64(asset.default));
6285
6345
  }
6286
6346
  function buildImports() {
6287
6347
  return {
@@ -6292,7 +6352,7 @@ function buildImports() {
6292
6352
  function initMls() {
6293
6353
  if (ready) return Promise.resolve(ready);
6294
6354
  if (inflight) return inflight;
6295
- inflight = (async () => {
6355
+ const attempt = (async () => {
6296
6356
  const module2 = await loadWasmModule();
6297
6357
  const instance = await WebAssembly.instantiate(module2, buildImports());
6298
6358
  const setWasm = __wbg_set_wasm;
@@ -6311,7 +6371,11 @@ function initMls() {
6311
6371
  ready = g;
6312
6372
  return g;
6313
6373
  })();
6314
- return inflight;
6374
+ inflight = attempt;
6375
+ void attempt.catch(() => {
6376
+ if (inflight === attempt) inflight = null;
6377
+ });
6378
+ return attempt;
6315
6379
  }
6316
6380
  function requireMls() {
6317
6381
  if (!ready) {
@@ -8764,7 +8828,7 @@ function defaultSessionStorage(key) {
8764
8828
  }
8765
8829
 
8766
8830
  // src/version.ts
8767
- var VERSION = "4.0.0";
8831
+ var VERSION = "4.0.2";
8768
8832
 
8769
8833
  // src/runtime.ts
8770
8834
  function buildRuntime(config) {