@oddington/sdk 0.1.51 → 0.1.53

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/README.md CHANGED
@@ -265,17 +265,28 @@ uses the CLI-backed app connection and presents the signed-in viewer:
265
265
 
266
266
  ```ts
267
267
  const { status, account } = browserAuth.getState();
268
- if (status === "signed_in") {
268
+ if ((status === "signed_in" || status === "reconnecting") && account) {
269
269
  // account.email and account.displayName identify this app's current viewer.
270
+ // Keep viewer presentation while reconnecting; protected access awaits renewal.
270
271
  }
271
272
  ```
272
273
 
273
274
  Use this account for viewer-aware presentation such as a Mine filter. Subscribe
274
275
  to keep that presentation current; it is not an authorization decision. There
275
276
  is no Inbox identity call, extra hosted lookup, browser provider session or CLI
276
- token. The handle and `os.init` share one exact-origin connection. Expiry clears
277
- account presentation, and same-session renewal restores it. Local sign-out ends
278
- the host session for its browsers; a failed confirmation reports unavailable.
277
+ token. The handle and `os.init` share one exact-origin connection. When an
278
+ established viewer's short access proof expires, the handle reports `reconnecting`
279
+ and retains the confirmed account for presentation while the SDK begins or joins
280
+ one shared, bounded recovery of the same session. No protected operation is
281
+ admitted before renewal succeeds. Confirmed connection and account recovery
282
+ restore `signed_in`; failed or unconfirmed recovery settles to `unavailable`.
283
+ A later lifecycle event or protected operation may recover the still-eligible
284
+ same session from `unavailable`; the SDK does not start an automatic retry loop
285
+ after an exhausted attempt. Local handles never report `signed_out` or `expired`.
286
+ Local sign-out immediately reports `unavailable` without an account, closes document
287
+ access and requests host-wide sign-out. Confirmed sign-out resolves while remaining
288
+ `unavailable`; failed confirmation rejects while remaining `unavailable`. Reopen
289
+ the app through OS after local sign-out.
279
290
  Disposal preserves the connection's stored proofs for document refresh. Local
280
291
  passcode and consent actions are unavailable: sign in with `os login` first.
281
292
 
@@ -297,7 +308,7 @@ provider internally through exact-origin `GET /api/auth`, owned by OS. The SDK
297
308
  uses same-origin credentials, refuses redirects and bypasses caching. Missing or
298
309
  invalid setup makes authentication unavailable without a legacy endpoint or
299
310
  app-configured provider fallback; ordinary app modules do not consume this
300
- internal bootstrap. State is `initializing`, `signed_out`, `signed_in`, `expired`
311
+ internal bootstrap. Hosted state is `initializing`, `signed_out`, `signed_in`, `expired`
301
312
  or `unavailable`; actions complete without returning a session. Invitation-only
302
313
  code delivery never creates accounts or reveals account existence. Keep form
303
314
  selection, entered values, copy and navigation in the app. The handle exposes no
package/dist/browser.js CHANGED
@@ -319,7 +319,6 @@ function validateRoutineSchemaValue(schema2, value, rejected) {
319
319
  check(schema2, value, "$");
320
320
  }
321
321
 
322
- var RECORD_READ_INPUT_LIMIT = 1024 * 1024, RECORD_CAPTURE_OUTPUT_LIMIT = 25 * 1024 * 1024;
323
322
  function validRecordRef(value) {
324
323
  return typeof value == "string" && value.length <= 512 && /^[_a-zA-Z0-9][a-zA-Z0-9_-]*(\/[_a-zA-Z0-9][a-zA-Z0-9_-]*)+$/.test(value);
325
324
  }
@@ -1608,6 +1607,18 @@ function mapping(value) {
1608
1607
  return invalidChange();
1609
1608
  }
1610
1609
  }
1610
+ function captureDataChangeOptions(value) {
1611
+ if (value === void 0) return {};
1612
+ let options = mapping(value);
1613
+ if (Object.keys(options).some((key) => !["summary", "source"].includes(key))) return invalidChange();
1614
+ let line = (value2) => !dataText(value2) || !value2.trim().length || [...value2].length > 120 || /[\u0000-\u001f\u007f-\u009f\u2028\u2029]/u.test(value2) ? invalidChange() : value2, captured = {};
1615
+ if (Object.hasOwn(options, "summary") && (captured.summary = line(options.summary)), Object.hasOwn(options, "source")) {
1616
+ let source2 = mapping(options.source);
1617
+ if (Object.keys(source2).sort().join(",") !== "id,kind" || source2.kind !== "app" && source2.kind !== "routine") return invalidChange();
1618
+ captured.source = { kind: source2.kind, id: line(source2.id) };
1619
+ }
1620
+ return captured;
1621
+ }
1611
1622
  function captureValue(value, ancestors = /* @__PURE__ */ new Set(), depth = 0) {
1612
1623
  if (value === null || typeof value == "string" || typeof value == "boolean" || typeof value == "number" && Number.isFinite(value)) return value;
1613
1624
  if (!value || typeof value != "object" || ancestors.has(value) || depth > 32) return invalidChange();
@@ -1884,11 +1895,11 @@ var genericData = {
1884
1895
  all: async (query, options) => send3({ operation: "records.all", ...captureRecordsAll(query, options) }),
1885
1896
  search: async (query, options) => send3({ operation: "records.search", ...captureRecordsSearchInput(query, options) })
1886
1897
  },
1887
- changes() {
1888
- let updates = [], creates = [], deletes = [], applyId, method, pending, confirmed, assertMutable = () => {
1898
+ changes(options) {
1899
+ let metadata = captureDataChangeOptions(options), updates = [], creates = [], deletes = [], applyId, method, pending, confirmed, assertMutable = () => {
1889
1900
  if (applyId) throw new DataOperationError("invalid_change", !1, "unapplied");
1890
1901
  }, snapshot = (nextUpdates = updates, nextCreates = creates, nextDeletes = deletes) => {
1891
- let { updates: updates2, creates: creates2, deletes: deletes2 } = captureDataChanges(nextUpdates, nextCreates, nextDeletes), input = { updates: updates2, ...creates2.length ? { creates: creates2 } : {}, ...deletes2.length ? { deletes: deletes2 } : {} };
1902
+ let { updates: updates2, creates: creates2, deletes: deletes2 } = captureDataChanges(nextUpdates, nextCreates, nextDeletes), input = { ...metadata, updates: updates2, ...creates2.length ? { creates: creates2 } : {}, ...deletes2.length ? { deletes: deletes2 } : {} };
1892
1903
  return checkDataRequestSize({
1893
1904
  repository,
1894
1905
  operation: "changes.apply",
@@ -2922,7 +2933,7 @@ function parseInboxRecords(value) {
2922
2933
 
2923
2934
  var InboxOperationError = class extends Error {
2924
2935
  constructor(status, reason) {
2925
- super(reason === "handler_unavailable" ? "Deploy the routine that owns this question\u2019s response handler." : reason === "conflict" ? "This question already has an accepted answer" : reason === "unavailable" ? "Inbox request unavailable. Retry the same action." : reason === "invalid_input" ? "Invalid Inbox request" : "Inbox access unavailable");
2936
+ super(reason === "action_processing" ? "The previous answer is still processing. Wait for it to finish." : reason === "action_failed" ? "The previous answer could not be completed. Further answers are on hold." : reason === "handler_unavailable" ? "Deploy the routine that owns this question\u2019s response handler." : reason === "conflict" ? "This question already has an accepted answer" : reason === "unavailable" ? "Inbox request unavailable. Retry the same action." : reason === "invalid_input" ? "Invalid Inbox request" : "Inbox access unavailable");
2926
2937
  this.status = status;
2927
2938
  this.reason = reason;
2928
2939
  }
@@ -2940,8 +2951,16 @@ function questionAvailability(value, available = !1) {
2940
2951
  }
2941
2952
  function parseInboxUnavailableFailure(value, status) {
2942
2953
  try {
2943
- if (status !== 503) return;
2944
2954
  let envelope = object4(value);
2955
+ if (status === 409) {
2956
+ keys3(envelope, ["error"]);
2957
+ for (let reason of ["action_processing", "action_failed"]) {
2958
+ let error = new InboxOperationError(409, reason);
2959
+ if (envelope.error === error.message) return error;
2960
+ }
2961
+ return;
2962
+ }
2963
+ if (status !== 503) return;
2945
2964
  keys3(envelope, ["error", "unavailableReason"], ["error", "unavailableReason"]), assert(text4(envelope.error));
2946
2965
  let state = questionAvailability(envelope);
2947
2966
  return new InboxOperationError(503, state.unavailableReason);
@@ -3446,7 +3465,9 @@ function appContext(origin, active2, changed) {
3446
3465
  async function renew(initialConnection = !1) {
3447
3466
  if (renewal) return renewal;
3448
3467
  if (!binding || !pair || !alive()) throw new Error();
3449
- renewal = (async () => {
3468
+ renewal = Promise.resolve().then(async () => {
3469
+ if (!alive()) throw new Error();
3470
+ clearTimeout(renewalTimer), binding.expiresAt <= Date.now() && notify("recovering");
3450
3471
  let requestController = new AbortController(), abort = () => requestController.abort();
3451
3472
  controller.signal.addEventListener("abort", abort, { once: !0 });
3452
3473
  let timeout = setTimeout(abort, 2e4), previous = serialized;
@@ -3486,17 +3507,17 @@ function appContext(origin, active2, changed) {
3486
3507
  }
3487
3508
  } catch {
3488
3509
  }
3489
- throw (error instanceof AppRenewalUnavailable || error instanceof AppResponseReadError || requestController.signal.aborted) && alive() ? current2() && (renewalTimer = setTimeout(
3510
+ throw (error instanceof AppRenewalUnavailable || error instanceof AppResponseReadError || requestController.signal.aborted) && alive() ? current2() ? renewalTimer = setTimeout(
3490
3511
  () => {
3491
3512
  renew().catch(() => {
3492
3513
  });
3493
3514
  },
3494
3515
  Math.min(5e3, (binding.expiresAt - Date.now()) / 5)
3495
- )) : invalidate(), new AppRenewalUnavailable();
3516
+ ) : notify("unavailable") : invalidate(), new AppRenewalUnavailable();
3496
3517
  } finally {
3497
3518
  clearTimeout(timeout), controller.signal.removeEventListener("abort", abort);
3498
3519
  }
3499
- })();
3520
+ });
3500
3521
  try {
3501
3522
  await renewal;
3502
3523
  } finally {
@@ -3685,7 +3706,8 @@ function appContext(origin, active2, changed) {
3685
3706
  return Object.freeze({ email: value.account.email, displayName: value.account.displayName });
3686
3707
  },
3687
3708
  signOut: async () => {
3688
- if (current2() || await resolve(), !current2()) throw new Error("Local app context unavailable.");
3709
+ if (!alive() || !credential)
3710
+ throw invalidate(), new Error("Local app context unavailable.");
3689
3711
  let signal = AbortSignal.timeout(2e4), pending = send3("sign-out", credential, signal, { method: "POST" });
3690
3712
  invalidate("signed_out");
3691
3713
  let response2 = await pending, value = await appResponse(response2, 4096, signal);
@@ -4018,7 +4040,7 @@ function refresh(c) {
4018
4040
  let promise = (async () => {
4019
4041
  try {
4020
4042
  let account = await c.context.account();
4021
- c.active && !c.closed && c.revision === revision && publish(c, { status: "signed_in", account });
4043
+ c.active && !c.closed && c.revision === revision && (c.account = account, publish(c, { status: "signed_in", account }));
4022
4044
  } catch {
4023
4045
  c.active && !c.closed && c.revision === revision && publish(c, { status: "unavailable", error: "unavailable" });
4024
4046
  }
@@ -4041,7 +4063,22 @@ function createLocalBrowserAuth(origin, failure) {
4041
4063
  ready: Promise.resolve()
4042
4064
  };
4043
4065
  coordinator2.context = appContext(origin, () => coordinator2.active, (state) => {
4044
- !coordinator2.active || coordinator2.closed || (state === "connected" ? coordinator2.state.status !== "initializing" && (coordinator2.revision++, refresh(coordinator2)) : (coordinator2.revision++, publish(coordinator2, { status: state === "expired" ? "expired" : state === "signed_out" ? "signed_out" : "unavailable" })));
4066
+ if (!(!coordinator2.active || coordinator2.closed))
4067
+ if (state === "connected")
4068
+ coordinator2.state.status !== "initializing" && (coordinator2.revision++, refresh(coordinator2));
4069
+ else if (state === "expired" || state === "recovering") {
4070
+ if (!coordinator2.account) return;
4071
+ let revision = ++coordinator2.revision;
4072
+ publish(coordinator2, { status: "reconnecting", account: coordinator2.account }), state === "expired" && Promise.resolve().then(async () => {
4073
+ if (!(!coordinator2.active || coordinator2.closed || coordinator2.revision !== revision))
4074
+ try {
4075
+ await coordinator2.context.resolve();
4076
+ } catch {
4077
+ coordinator2.active && !coordinator2.closed && coordinator2.revision === revision && publish(coordinator2, { status: "unavailable", error: "unavailable" });
4078
+ }
4079
+ });
4080
+ } else
4081
+ coordinator2.revision++, state === "signed_out" && (coordinator2.account = void 0), publish(coordinator2, { status: "unavailable" });
4045
4082
  }), c = coordinator2, coordinators.set(origin, c), c.ready = Promise.resolve().then(() => refresh(coordinator2));
4046
4083
  }
4047
4084
  let coordinator = c;
@@ -4058,7 +4095,7 @@ function createLocalBrowserAuth(origin, failure) {
4058
4095
  let assertActive = () => {
4059
4096
  if (!active2) throw failure("disposed");
4060
4097
  }, unavailable5 = async () => Object.freeze({
4061
- status: active2 ? coordinator.state.status === "signed_out" ? "signed_out" : "unavailable" : "disposed"
4098
+ status: active2 ? "unavailable" : "disposed"
4062
4099
  }), handle2 = Object.freeze({
4063
4100
  authorization: Object.freeze({ get: unavailable5, approve: unavailable5, deny: unavailable5 }),
4064
4101
  getState() {
@@ -4078,13 +4115,13 @@ function createLocalBrowserAuth(origin, failure) {
4078
4115
  async signOut() {
4079
4116
  if (assertActive(), coordinator.state.pending === "sign_out") throw failure("busy");
4080
4117
  if (coordinator.closed) throw failure("unavailable");
4081
- coordinator.closed = !0, coordinator.revision++, publish(coordinator, { status: coordinator.state.status, pending: "sign_out" });
4118
+ coordinator.closed = !0, coordinator.revision++, coordinator.account = void 0, publish(coordinator, { status: "unavailable", pending: "sign_out" });
4082
4119
  try {
4083
4120
  await coordinator.context.signOut();
4084
4121
  } catch {
4085
4122
  throw coordinator.context.invalidate(), coordinator.active && publish(coordinator, { status: "unavailable", error: "unavailable" }), failure(active2 ? "unavailable" : "disposed");
4086
4123
  }
4087
- coordinator.active && publish(coordinator, { status: "signed_out" }), assertActive();
4124
+ coordinator.active && publish(coordinator, { status: "unavailable" }), assertActive();
4088
4125
  },
4089
4126
  dispose() {
4090
4127
  if (active2) {