@relai-team/access-sdk 0.12.4 → 0.14.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.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { RelaiApiError, RelaiTransportError, RelaiUnlockRejected, RelaiMissingKeyError, RelaiError } from './chunk-MNXTMLX2.js';
2
- export { RelaiApiError, RelaiError, RelaiLateFeeDue, RelaiMissingKeyError, RelaiTransportError, RelaiUnlockRejected } from './chunk-MNXTMLX2.js';
3
- export { asPaymentRequired, presentRelaiPaymentSheet } from './chunk-3WZBCXG3.js';
1
+ import { RelaiApiError, RelaiTransportError, RelaiUnlockRejected, RelaiMissingKeyError, RelaiError, RelaiNetworkError } from './chunk-B2T3KFBF.js';
2
+ export { RelaiApiError, RelaiConfigError, RelaiError, RelaiLateFeeDue, RelaiMissingKeyError, RelaiNetworkError, RelaiTransportError, RelaiUnlockRejected } from './chunk-B2T3KFBF.js';
3
+ export { asPaymentRequired, isStripePublishableKey, presentRelaiPaymentSheet } from './chunk-BIHTDL4L.js';
4
4
 
5
5
  // src/http.ts
6
6
  var RETRYABLE_STATUS = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
@@ -48,14 +48,18 @@ var HttpClient = class {
48
48
  await sleep(backoffMs(i));
49
49
  continue;
50
50
  }
51
- throw new RelaiError(`Network request failed: ${netErr.message}`);
51
+ throw new RelaiNetworkError(
52
+ `Network request failed: ${netErr.message}`,
53
+ { method: opts.method ?? "GET", path: opts.path },
54
+ netErr
55
+ );
52
56
  }
53
57
  if (res.ok) return await this.parseJson(res);
54
58
  if (RETRYABLE_STATUS.has(res.status) && i < this.cfg.maxRetries) {
55
59
  await sleep(retryDelayMs(res, i));
56
60
  continue;
57
61
  }
58
- const apiErr = await this.toApiError(res);
62
+ const apiErr = await this.toApiError(res, opts);
59
63
  if (apiErr.code === "idempotency_in_progress" && i < this.cfg.maxRetries) {
60
64
  await sleep(retryDelayMs(res, i));
61
65
  continue;
@@ -93,7 +97,7 @@ var HttpClient = class {
93
97
  throw new RelaiError(`Expected JSON from ${res.url} but got: ${text.slice(0, 120)}`);
94
98
  }
95
99
  }
96
- async toApiError(res) {
100
+ async toApiError(res, opts) {
97
101
  let body;
98
102
  try {
99
103
  body = await this.parseJson(res);
@@ -101,11 +105,18 @@ var HttpClient = class {
101
105
  body = { error: { code: "http_error", message: `HTTP ${res.status}` } };
102
106
  }
103
107
  if (!body?.error?.code) body = { error: { code: "http_error", message: `HTTP ${res.status}` } };
108
+ const ra = Number(res.headers.get("retry-after"));
109
+ const ctx = {
110
+ requestId: res.headers.get("x-relai-request-id") ?? void 0,
111
+ retryAfterSeconds: Number.isFinite(ra) && res.headers.get("retry-after") !== null ? ra : void 0,
112
+ method: opts.method ?? "GET",
113
+ path: opts.path
114
+ };
104
115
  if (body.error.code === "late_fee_due") {
105
- const { RelaiLateFeeDue: RelaiLateFeeDue2 } = await import('./errors-L7B45UIZ.js');
106
- return new RelaiLateFeeDue2(res.status, body);
116
+ const { RelaiLateFeeDue: RelaiLateFeeDue2 } = await import('./errors-NKRGOFB3.js');
117
+ return new RelaiLateFeeDue2(res.status, body, ctx);
107
118
  }
108
- return new RelaiApiError(res.status, body);
119
+ return new RelaiApiError(res.status, body, ctx);
109
120
  }
110
121
  };
111
122
  function backoffMs(attempt) {
@@ -395,6 +406,61 @@ var TelemetryModule = class {
395
406
  return this.http.request({ method: "POST", path: "/telemetry", body });
396
407
  }
397
408
  };
409
+ var PushModule = class {
410
+ constructor(http) {
411
+ this.http = http;
412
+ }
413
+ /**
414
+ * Register this device for handoff and pick-up notifications. Requires a
415
+ * signed-in end user. Safe to call on every launch: re-registering the same
416
+ * token updates it rather than duplicating it.
417
+ */
418
+ register(token, platform = "expo") {
419
+ return this.http.request({
420
+ method: "POST",
421
+ path: "/push/tokens",
422
+ body: { token, platform }
423
+ });
424
+ }
425
+ /** Unregister on sign-out, or the next person to use the device gets their alerts. */
426
+ unregister(token) {
427
+ return this.http.request({
428
+ method: "DELETE",
429
+ path: "/push/tokens",
430
+ body: { token }
431
+ });
432
+ }
433
+ };
434
+ var SandboxModule = class {
435
+ constructor(http) {
436
+ this.http = http;
437
+ }
438
+ /**
439
+ * Force a fault so the app's unhappy paths can be exercised without hardware.
440
+ * `jammed_door` needs a `nodeId`; `dead_battery` applies to the whole
441
+ * Exchange Zone.
442
+ */
443
+ injectFault(input) {
444
+ const body = { ez_id: input.exchangeZoneId, fault: input.fault };
445
+ if (input.nodeId !== void 0) body["node_id"] = input.nodeId;
446
+ return this.http.request({ method: "POST", path: "/sandbox/faults", body });
447
+ }
448
+ /** Clear an injected fault and return the Exchange Zone to service. */
449
+ clearFault(input) {
450
+ const body = { ez_id: input.exchangeZoneId, fault: "clear" };
451
+ if (input.nodeId !== void 0) body["node_id"] = input.nodeId;
452
+ return this.http.request({ method: "POST", path: "/sandbox/faults", body });
453
+ }
454
+ };
455
+ var AppModule = class {
456
+ constructor(http) {
457
+ this.http = http;
458
+ }
459
+ /** Config for the app the current key belongs to. */
460
+ self() {
461
+ return this.http.request({ path: "/apps/self" });
462
+ }
463
+ };
398
464
 
399
465
  // src/telemetry-queue.ts
400
466
  var MemoryTelemetryQueue = class {
@@ -552,6 +618,9 @@ var RelaiClient = class {
552
618
  this.overrideLinks = new OverrideLinksModule(this.http);
553
619
  this.endUsers = new EndUsersModule(this.http);
554
620
  this.telemetry = new TelemetryModule(this.http);
621
+ this.push = new PushModule(this.http);
622
+ this.sandbox = new SandboxModule(this.http);
623
+ this.app = new AppModule(this.http);
555
624
  this.telemetryUploader = new TelemetryUploader(this.telemetry, options.telemetryQueue);
556
625
  }
557
626
  /** Drain any telemetry queued after a failed send (e.g. on app foreground). */
@@ -589,9 +658,9 @@ var RelaiClient = class {
589
658
  try {
590
659
  open = await requestOpen();
591
660
  } catch (err) {
592
- const { RelaiApiError: RelaiApiError2 } = await import('./errors-L7B45UIZ.js');
661
+ const { RelaiApiError: RelaiApiError2 } = await import('./errors-NKRGOFB3.js');
593
662
  if (input.presentPaymentSheet !== false && err instanceof RelaiApiError2 && err.code === "payment_required") {
594
- const { asPaymentRequired: asPaymentRequired2, presentRelaiPaymentSheet: presentRelaiPaymentSheet2 } = await import('./payment-sheet-XIZYASSI.js');
663
+ const { asPaymentRequired: asPaymentRequired2, presentRelaiPaymentSheet: presentRelaiPaymentSheet2 } = await import('./payment-sheet-B3X5QQMO.js');
595
664
  const details = asPaymentRequired2(err.details);
596
665
  if (!details || !await presentRelaiPaymentSheet2(details, this.stripe)) throw err;
597
666
  open = await requestOpen();
@@ -987,4 +1056,4 @@ var Intents = {
987
1056
  MakeAvailable: "make_available"
988
1057
  };
989
1058
 
990
- export { AccessLinksModule, AuthModule, BleTransport, EndUsersModule, ExchangeZonesModule, GrantsModule, Intents, MemoryTelemetryQueue, MemoryTokenStorage, OrdersModule, OverrideLinksModule, REJECT_REASONS, RELAI_RX_CHAR, RELAI_TX_CHAR, RELAI_UART_SERVICE, RecipientsModule, RelaiClient, SimAuthenticatedTransport, SimulatedTransport, StorageTelemetryQueue, TelemetryModule, TelemetryUploader, deliverOpen, parseNotifyLine, verifyWebhook };
1059
+ export { AccessLinksModule, AppModule, AuthModule, BleTransport, EndUsersModule, ExchangeZonesModule, GrantsModule, Intents, MemoryTelemetryQueue, MemoryTokenStorage, OrdersModule, OverrideLinksModule, PushModule, REJECT_REASONS, RELAI_RX_CHAR, RELAI_TX_CHAR, RELAI_UART_SERVICE, RecipientsModule, RelaiClient, SandboxModule, SimAuthenticatedTransport, SimulatedTransport, StorageTelemetryQueue, TelemetryModule, TelemetryUploader, deliverOpen, parseNotifyLine, verifyWebhook };
@@ -0,0 +1 @@
1
+ export { asPaymentRequired, isStripePublishableKey, presentRelaiPaymentSheet } from './chunk-BIHTDL4L.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@relai-team/access-sdk",
3
- "version": "0.12.4",
3
+ "version": "0.14.0",
4
4
  "description": "Official Relai Access SDK, open Relai Exchange Zone nodes over BLE, backed by the Relai Access platform (server-owns-trust).",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "module",
@@ -23,6 +23,7 @@
23
23
  "scripts": {
24
24
  "build": "tsup",
25
25
  "typecheck": "tsc --noEmit",
26
+ "pretest": "npm run build",
26
27
  "test": "vitest run",
27
28
  "test:watch": "vitest",
28
29
  "spec:types": "openapi-typescript openapi.json -o src/generated/api.ts",
@@ -1 +0,0 @@
1
- export { RelaiApiError, RelaiError, RelaiLateFeeDue, RelaiMissingKeyError, RelaiTransportError, RelaiUnlockRejected } from './chunk-MNXTMLX2.js';
@@ -1 +0,0 @@
1
- export { asPaymentRequired, presentRelaiPaymentSheet } from './chunk-3WZBCXG3.js';