@relai-team/access-sdk 0.19.0 → 0.20.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.cjs CHANGED
@@ -925,6 +925,7 @@ var RelaiClient = class {
925
925
  constructor(options) {
926
926
  if (!options.publishableKey && !options.secretKey) throw new exports.RelaiMissingKeyError();
927
927
  this.stripe = options.stripe;
928
+ this.handleStorage = options.handleStorage;
928
929
  const storage = options.tokenStorage ?? new MemoryTokenStorage();
929
930
  let auth;
930
931
  const httpConfig = {
@@ -1006,7 +1007,12 @@ var RelaiClient = class {
1006
1007
  transport: input.transport,
1007
1008
  ...input.parentBleId !== void 0 ? { parentBleId: input.parentBleId } : {},
1008
1009
  ...input.exchangeZoneId !== void 0 ? { exchangeZoneId: input.exchangeZoneId } : {},
1009
- ...input.keepConnected !== void 0 ? { keepConnected: input.keepConnected } : {}
1010
+ ...input.keepConnected !== void 0 ? { keepConnected: input.keepConnected } : {},
1011
+ // Per-call first, then the client's. Spread rather than assigned:
1012
+ // exactOptionalPropertyTypes makes an explicit `undefined` a value, and
1013
+ // `new ParentHandleCache(undefined)` is a cache that silently does
1014
+ // nothing, which is precisely the bug being fixed.
1015
+ ...input.handleStorage ?? this.handleStorage ? { handleStorage: input.handleStorage ?? this.handleStorage } : {}
1010
1016
  }
1011
1017
  );
1012
1018
  }
@@ -1099,6 +1105,21 @@ function base64ToUtf8(b64) {
1099
1105
  if (g.atob) return decodeURIComponent(escape(g.atob(b64)));
1100
1106
  throw new Error("No base64 decoder available in this runtime.");
1101
1107
  }
1108
+ function base64ToBytes(b64) {
1109
+ const g = globalThis;
1110
+ try {
1111
+ if (g.Buffer) return new Uint8Array(g.Buffer.from(b64, "base64"));
1112
+ if (g.atob) {
1113
+ const binary = g.atob(b64);
1114
+ const out = new Uint8Array(binary.length);
1115
+ for (let i = 0; i < binary.length; i++) out[i] = binary.charCodeAt(i);
1116
+ return out;
1117
+ }
1118
+ return null;
1119
+ } catch {
1120
+ return null;
1121
+ }
1122
+ }
1102
1123
 
1103
1124
  // src/transport/simulated.ts
1104
1125
  function randomNonceB64Url() {
@@ -1224,23 +1245,10 @@ init_errors();
1224
1245
  var COMPANY_ID = 65535;
1225
1246
  var FORMAT_VERSION = 1;
1226
1247
  var HEADER_BYTES = 3;
1227
- var SERIAL_MAX = 12;
1228
- function decodeBase64(value) {
1229
- try {
1230
- const binary = typeof atob === "function" ? atob(value) : (
1231
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1232
- globalThis.Buffer.from(value, "base64").toString("binary")
1233
- );
1234
- const out = new Uint8Array(binary.length);
1235
- for (let i = 0; i < binary.length; i++) out[i] = binary.charCodeAt(i);
1236
- return out;
1237
- } catch {
1238
- return null;
1239
- }
1240
- }
1248
+ var SERIAL_MAX = 29 - HEADER_BYTES;
1241
1249
  function parseAdvertisedSerial(value) {
1242
1250
  if (!value) return null;
1243
- const bytes = decodeBase64(value);
1251
+ const bytes = base64ToBytes(value);
1244
1252
  if (!bytes || bytes.length <= HEADER_BYTES) return null;
1245
1253
  const company = bytes[0] | bytes[1] << 8;
1246
1254
  if (company !== COMPANY_ID) return null;
package/dist/index.d.cts CHANGED
@@ -930,6 +930,60 @@ declare class TelemetryUploader {
930
930
  }>;
931
931
  }
932
932
 
933
+ /**
934
+ * Persistent telemetry queue (owner, 2026-07-24). `MemoryTelemetryQueue` loses
935
+ * anything queued when the app is killed; a React Native app that opens nodes
936
+ * offline needs its unreported opens to survive a restart. This backs the same
937
+ * `TelemetryQueue` interface with a key-value store.
938
+ *
939
+ * The store is AsyncStorage-shaped on purpose, so RN apps pass the library in
940
+ * directly (it is an OPTIONAL dependency: the SDK core never imports it):
941
+ *
942
+ * import AsyncStorage from "@react-native-async-storage/async-storage";
943
+ * const client = new RelaiClient({
944
+ * publishableKey,
945
+ * telemetryQueue: new StorageTelemetryQueue(AsyncStorage),
946
+ * });
947
+ *
948
+ * The whole queue is one JSON blob under a single key: telemetry volume is one
949
+ * item per open, so this stays small; writes are serialized through an internal
950
+ * lock so concurrent submit/flush calls can't clobber each other.
951
+ */
952
+
953
+ /** The subset of AsyncStorage (and localStorage-async wrappers) we need. */
954
+ interface KeyValueStorage {
955
+ getItem(key: string): Promise<string | null>;
956
+ setItem(key: string, value: string): Promise<void>;
957
+ removeItem(key: string): Promise<void>;
958
+ }
959
+ interface StorageTelemetryQueueOptions {
960
+ /** Storage key for the serialized queue. Default `@relai/telemetry-queue`. */
961
+ storageKey?: string;
962
+ /**
963
+ * Hard cap on queued items; when exceeded the OLDEST are dropped so a long
964
+ * outage can't grow storage without bound. Default 500.
965
+ */
966
+ maxItems?: number;
967
+ }
968
+ declare class StorageTelemetryQueue implements TelemetryQueue {
969
+ private readonly storage;
970
+ private readonly key;
971
+ private readonly maxItems;
972
+ /** Serializes read-modify-write so concurrent calls don't lose updates. */
973
+ private chain;
974
+ private seq;
975
+ constructor(storage: KeyValueStorage, opts?: StorageTelemetryQueueOptions);
976
+ enqueue(payload: TelemetryPayload): Promise<void>;
977
+ list(): Promise<QueuedTelemetry[]>;
978
+ remove(id: string): Promise<void>;
979
+ markAttempt(id: string): Promise<void>;
980
+ private nextId;
981
+ /** Serialize an operation after any in-flight ones (a simple promise lock). */
982
+ private run;
983
+ private mutate;
984
+ private read;
985
+ }
986
+
933
987
  /**
934
988
  * The outcome of writing one authenticated command to a Parent, distilled from
935
989
  * the notify surface. `accepted` is the ONLY control-flow signal; `verbHint` is
@@ -1004,60 +1058,6 @@ interface ParentTransport {
1004
1058
  disconnect(session: Session): Promise<void>;
1005
1059
  }
1006
1060
 
1007
- /**
1008
- * Persistent telemetry queue (owner, 2026-07-24). `MemoryTelemetryQueue` loses
1009
- * anything queued when the app is killed; a React Native app that opens nodes
1010
- * offline needs its unreported opens to survive a restart. This backs the same
1011
- * `TelemetryQueue` interface with a key-value store.
1012
- *
1013
- * The store is AsyncStorage-shaped on purpose, so RN apps pass the library in
1014
- * directly (it is an OPTIONAL dependency: the SDK core never imports it):
1015
- *
1016
- * import AsyncStorage from "@react-native-async-storage/async-storage";
1017
- * const client = new RelaiClient({
1018
- * publishableKey,
1019
- * telemetryQueue: new StorageTelemetryQueue(AsyncStorage),
1020
- * });
1021
- *
1022
- * The whole queue is one JSON blob under a single key: telemetry volume is one
1023
- * item per open, so this stays small; writes are serialized through an internal
1024
- * lock so concurrent submit/flush calls can't clobber each other.
1025
- */
1026
-
1027
- /** The subset of AsyncStorage (and localStorage-async wrappers) we need. */
1028
- interface KeyValueStorage {
1029
- getItem(key: string): Promise<string | null>;
1030
- setItem(key: string, value: string): Promise<void>;
1031
- removeItem(key: string): Promise<void>;
1032
- }
1033
- interface StorageTelemetryQueueOptions {
1034
- /** Storage key for the serialized queue. Default `@relai/telemetry-queue`. */
1035
- storageKey?: string;
1036
- /**
1037
- * Hard cap on queued items; when exceeded the OLDEST are dropped so a long
1038
- * outage can't grow storage without bound. Default 500.
1039
- */
1040
- maxItems?: number;
1041
- }
1042
- declare class StorageTelemetryQueue implements TelemetryQueue {
1043
- private readonly storage;
1044
- private readonly key;
1045
- private readonly maxItems;
1046
- /** Serializes read-modify-write so concurrent calls don't lose updates. */
1047
- private chain;
1048
- private seq;
1049
- constructor(storage: KeyValueStorage, opts?: StorageTelemetryQueueOptions);
1050
- enqueue(payload: TelemetryPayload): Promise<void>;
1051
- list(): Promise<QueuedTelemetry[]>;
1052
- remove(id: string): Promise<void>;
1053
- markAttempt(id: string): Promise<void>;
1054
- private nextId;
1055
- /** Serialize an operation after any in-flight ones (a simple promise lock). */
1056
- private run;
1057
- private mutate;
1058
- private read;
1059
- }
1060
-
1061
1061
  interface UnlockDeps {
1062
1062
  grants: GrantsModule;
1063
1063
  telemetry: TelemetryUploader;
@@ -1201,6 +1201,22 @@ interface RelaiClientOptions {
1201
1201
  maxRetries?: number;
1202
1202
  /** Persistent telemetry queue (default: in-memory). RN apps can back it with storage. */
1203
1203
  telemetryQueue?: TelemetryQueue;
1204
+ /**
1205
+ * Where to remember which local handle turned out to be which Parent.
1206
+ *
1207
+ * Pass the same `KeyValueStorage` the telemetry queue uses, typically
1208
+ * AsyncStorage, and an open that resolved a Parent connects straight to it
1209
+ * next time instead of scanning. Omit it and every open rescans, which costs
1210
+ * a few seconds and nothing else.
1211
+ *
1212
+ * HERE rather than only on each `unlock()` call, because the mapping is
1213
+ * per-install device state like `tokenStorage` and `telemetryQueue`: an app
1214
+ * wires its store once. `UnlockInput.handleStorage` overrides it per call.
1215
+ *
1216
+ * The mapping is per device, because the identifier is: the handle this phone
1217
+ * connects by is not the handle another phone gets for the same Parent.
1218
+ */
1219
+ handleStorage?: KeyValueStorage;
1204
1220
  /**
1205
1221
  * The `@stripe/stripe-react-native` module, for Relai checkout. Pass it and
1206
1222
  * payment-gated opens present the standard Payment Sheet and retry
@@ -1251,6 +1267,15 @@ interface UnlockInput {
1251
1267
  /** Admin/partner override link code: bypasses handoff + paywall gates. */
1252
1268
  overrideCode?: string;
1253
1269
  keepConnected?: boolean;
1270
+ /**
1271
+ * Override the client's `handleStorage` for this open.
1272
+ *
1273
+ * Normally omitted: set it once on the client. This exists because
1274
+ * `deliverOpen` has always accepted it and `unlock()` dropped it silently, so
1275
+ * a Relai-checkout app could not reach the cache at all without
1276
+ * reimplementing the payment handling (partner report, 2026-10-05).
1277
+ */
1278
+ handleStorage?: KeyValueStorage;
1254
1279
  }
1255
1280
  declare class RelaiClient {
1256
1281
  readonly auth: AuthModule;
@@ -1275,6 +1300,8 @@ declare class RelaiClient {
1275
1300
  private readonly http;
1276
1301
  /** The app-supplied Stripe module, if any. See `RelaiClientOptions.stripe`. */
1277
1302
  private readonly stripe;
1303
+ /** Where resolved Parent handles are remembered. See `RelaiClientOptions.handleStorage`. */
1304
+ private readonly handleStorage;
1278
1305
  constructor(options: RelaiClientOptions);
1279
1306
  /** Drain any telemetry queued after a failed send (e.g. on app foreground). */
1280
1307
  flushTelemetry(): Promise<{
package/dist/index.d.ts CHANGED
@@ -930,6 +930,60 @@ declare class TelemetryUploader {
930
930
  }>;
931
931
  }
932
932
 
933
+ /**
934
+ * Persistent telemetry queue (owner, 2026-07-24). `MemoryTelemetryQueue` loses
935
+ * anything queued when the app is killed; a React Native app that opens nodes
936
+ * offline needs its unreported opens to survive a restart. This backs the same
937
+ * `TelemetryQueue` interface with a key-value store.
938
+ *
939
+ * The store is AsyncStorage-shaped on purpose, so RN apps pass the library in
940
+ * directly (it is an OPTIONAL dependency: the SDK core never imports it):
941
+ *
942
+ * import AsyncStorage from "@react-native-async-storage/async-storage";
943
+ * const client = new RelaiClient({
944
+ * publishableKey,
945
+ * telemetryQueue: new StorageTelemetryQueue(AsyncStorage),
946
+ * });
947
+ *
948
+ * The whole queue is one JSON blob under a single key: telemetry volume is one
949
+ * item per open, so this stays small; writes are serialized through an internal
950
+ * lock so concurrent submit/flush calls can't clobber each other.
951
+ */
952
+
953
+ /** The subset of AsyncStorage (and localStorage-async wrappers) we need. */
954
+ interface KeyValueStorage {
955
+ getItem(key: string): Promise<string | null>;
956
+ setItem(key: string, value: string): Promise<void>;
957
+ removeItem(key: string): Promise<void>;
958
+ }
959
+ interface StorageTelemetryQueueOptions {
960
+ /** Storage key for the serialized queue. Default `@relai/telemetry-queue`. */
961
+ storageKey?: string;
962
+ /**
963
+ * Hard cap on queued items; when exceeded the OLDEST are dropped so a long
964
+ * outage can't grow storage without bound. Default 500.
965
+ */
966
+ maxItems?: number;
967
+ }
968
+ declare class StorageTelemetryQueue implements TelemetryQueue {
969
+ private readonly storage;
970
+ private readonly key;
971
+ private readonly maxItems;
972
+ /** Serializes read-modify-write so concurrent calls don't lose updates. */
973
+ private chain;
974
+ private seq;
975
+ constructor(storage: KeyValueStorage, opts?: StorageTelemetryQueueOptions);
976
+ enqueue(payload: TelemetryPayload): Promise<void>;
977
+ list(): Promise<QueuedTelemetry[]>;
978
+ remove(id: string): Promise<void>;
979
+ markAttempt(id: string): Promise<void>;
980
+ private nextId;
981
+ /** Serialize an operation after any in-flight ones (a simple promise lock). */
982
+ private run;
983
+ private mutate;
984
+ private read;
985
+ }
986
+
933
987
  /**
934
988
  * The outcome of writing one authenticated command to a Parent, distilled from
935
989
  * the notify surface. `accepted` is the ONLY control-flow signal; `verbHint` is
@@ -1004,60 +1058,6 @@ interface ParentTransport {
1004
1058
  disconnect(session: Session): Promise<void>;
1005
1059
  }
1006
1060
 
1007
- /**
1008
- * Persistent telemetry queue (owner, 2026-07-24). `MemoryTelemetryQueue` loses
1009
- * anything queued when the app is killed; a React Native app that opens nodes
1010
- * offline needs its unreported opens to survive a restart. This backs the same
1011
- * `TelemetryQueue` interface with a key-value store.
1012
- *
1013
- * The store is AsyncStorage-shaped on purpose, so RN apps pass the library in
1014
- * directly (it is an OPTIONAL dependency: the SDK core never imports it):
1015
- *
1016
- * import AsyncStorage from "@react-native-async-storage/async-storage";
1017
- * const client = new RelaiClient({
1018
- * publishableKey,
1019
- * telemetryQueue: new StorageTelemetryQueue(AsyncStorage),
1020
- * });
1021
- *
1022
- * The whole queue is one JSON blob under a single key: telemetry volume is one
1023
- * item per open, so this stays small; writes are serialized through an internal
1024
- * lock so concurrent submit/flush calls can't clobber each other.
1025
- */
1026
-
1027
- /** The subset of AsyncStorage (and localStorage-async wrappers) we need. */
1028
- interface KeyValueStorage {
1029
- getItem(key: string): Promise<string | null>;
1030
- setItem(key: string, value: string): Promise<void>;
1031
- removeItem(key: string): Promise<void>;
1032
- }
1033
- interface StorageTelemetryQueueOptions {
1034
- /** Storage key for the serialized queue. Default `@relai/telemetry-queue`. */
1035
- storageKey?: string;
1036
- /**
1037
- * Hard cap on queued items; when exceeded the OLDEST are dropped so a long
1038
- * outage can't grow storage without bound. Default 500.
1039
- */
1040
- maxItems?: number;
1041
- }
1042
- declare class StorageTelemetryQueue implements TelemetryQueue {
1043
- private readonly storage;
1044
- private readonly key;
1045
- private readonly maxItems;
1046
- /** Serializes read-modify-write so concurrent calls don't lose updates. */
1047
- private chain;
1048
- private seq;
1049
- constructor(storage: KeyValueStorage, opts?: StorageTelemetryQueueOptions);
1050
- enqueue(payload: TelemetryPayload): Promise<void>;
1051
- list(): Promise<QueuedTelemetry[]>;
1052
- remove(id: string): Promise<void>;
1053
- markAttempt(id: string): Promise<void>;
1054
- private nextId;
1055
- /** Serialize an operation after any in-flight ones (a simple promise lock). */
1056
- private run;
1057
- private mutate;
1058
- private read;
1059
- }
1060
-
1061
1061
  interface UnlockDeps {
1062
1062
  grants: GrantsModule;
1063
1063
  telemetry: TelemetryUploader;
@@ -1201,6 +1201,22 @@ interface RelaiClientOptions {
1201
1201
  maxRetries?: number;
1202
1202
  /** Persistent telemetry queue (default: in-memory). RN apps can back it with storage. */
1203
1203
  telemetryQueue?: TelemetryQueue;
1204
+ /**
1205
+ * Where to remember which local handle turned out to be which Parent.
1206
+ *
1207
+ * Pass the same `KeyValueStorage` the telemetry queue uses, typically
1208
+ * AsyncStorage, and an open that resolved a Parent connects straight to it
1209
+ * next time instead of scanning. Omit it and every open rescans, which costs
1210
+ * a few seconds and nothing else.
1211
+ *
1212
+ * HERE rather than only on each `unlock()` call, because the mapping is
1213
+ * per-install device state like `tokenStorage` and `telemetryQueue`: an app
1214
+ * wires its store once. `UnlockInput.handleStorage` overrides it per call.
1215
+ *
1216
+ * The mapping is per device, because the identifier is: the handle this phone
1217
+ * connects by is not the handle another phone gets for the same Parent.
1218
+ */
1219
+ handleStorage?: KeyValueStorage;
1204
1220
  /**
1205
1221
  * The `@stripe/stripe-react-native` module, for Relai checkout. Pass it and
1206
1222
  * payment-gated opens present the standard Payment Sheet and retry
@@ -1251,6 +1267,15 @@ interface UnlockInput {
1251
1267
  /** Admin/partner override link code: bypasses handoff + paywall gates. */
1252
1268
  overrideCode?: string;
1253
1269
  keepConnected?: boolean;
1270
+ /**
1271
+ * Override the client's `handleStorage` for this open.
1272
+ *
1273
+ * Normally omitted: set it once on the client. This exists because
1274
+ * `deliverOpen` has always accepted it and `unlock()` dropped it silently, so
1275
+ * a Relai-checkout app could not reach the cache at all without
1276
+ * reimplementing the payment handling (partner report, 2026-10-05).
1277
+ */
1278
+ handleStorage?: KeyValueStorage;
1254
1279
  }
1255
1280
  declare class RelaiClient {
1256
1281
  readonly auth: AuthModule;
@@ -1275,6 +1300,8 @@ declare class RelaiClient {
1275
1300
  private readonly http;
1276
1301
  /** The app-supplied Stripe module, if any. See `RelaiClientOptions.stripe`. */
1277
1302
  private readonly stripe;
1303
+ /** Where resolved Parent handles are remembered. See `RelaiClientOptions.handleStorage`. */
1304
+ private readonly handleStorage;
1278
1305
  constructor(options: RelaiClientOptions);
1279
1306
  /** Drain any telemetry queued after a failed send (e.g. on app foreground). */
1280
1307
  flushTelemetry(): Promise<{
package/dist/index.js CHANGED
@@ -762,6 +762,7 @@ var RelaiClient = class {
762
762
  constructor(options) {
763
763
  if (!options.publishableKey && !options.secretKey) throw new RelaiMissingKeyError();
764
764
  this.stripe = options.stripe;
765
+ this.handleStorage = options.handleStorage;
765
766
  const storage = options.tokenStorage ?? new MemoryTokenStorage();
766
767
  let auth;
767
768
  const httpConfig = {
@@ -843,7 +844,12 @@ var RelaiClient = class {
843
844
  transport: input.transport,
844
845
  ...input.parentBleId !== void 0 ? { parentBleId: input.parentBleId } : {},
845
846
  ...input.exchangeZoneId !== void 0 ? { exchangeZoneId: input.exchangeZoneId } : {},
846
- ...input.keepConnected !== void 0 ? { keepConnected: input.keepConnected } : {}
847
+ ...input.keepConnected !== void 0 ? { keepConnected: input.keepConnected } : {},
848
+ // Per-call first, then the client's. Spread rather than assigned:
849
+ // exactOptionalPropertyTypes makes an explicit `undefined` a value, and
850
+ // `new ParentHandleCache(undefined)` is a cache that silently does
851
+ // nothing, which is precisely the bug being fixed.
852
+ ...input.handleStorage ?? this.handleStorage ? { handleStorage: input.handleStorage ?? this.handleStorage } : {}
847
853
  }
848
854
  );
849
855
  }
@@ -933,6 +939,21 @@ function base64ToUtf8(b64) {
933
939
  if (g.atob) return decodeURIComponent(escape(g.atob(b64)));
934
940
  throw new Error("No base64 decoder available in this runtime.");
935
941
  }
942
+ function base64ToBytes(b64) {
943
+ const g = globalThis;
944
+ try {
945
+ if (g.Buffer) return new Uint8Array(g.Buffer.from(b64, "base64"));
946
+ if (g.atob) {
947
+ const binary = g.atob(b64);
948
+ const out = new Uint8Array(binary.length);
949
+ for (let i = 0; i < binary.length; i++) out[i] = binary.charCodeAt(i);
950
+ return out;
951
+ }
952
+ return null;
953
+ } catch {
954
+ return null;
955
+ }
956
+ }
936
957
 
937
958
  // src/transport/simulated.ts
938
959
  function randomNonceB64Url() {
@@ -1054,23 +1075,10 @@ var SimAuthenticatedTransport = class {
1054
1075
  var COMPANY_ID = 65535;
1055
1076
  var FORMAT_VERSION = 1;
1056
1077
  var HEADER_BYTES = 3;
1057
- var SERIAL_MAX = 12;
1058
- function decodeBase64(value) {
1059
- try {
1060
- const binary = typeof atob === "function" ? atob(value) : (
1061
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1062
- globalThis.Buffer.from(value, "base64").toString("binary")
1063
- );
1064
- const out = new Uint8Array(binary.length);
1065
- for (let i = 0; i < binary.length; i++) out[i] = binary.charCodeAt(i);
1066
- return out;
1067
- } catch {
1068
- return null;
1069
- }
1070
- }
1078
+ var SERIAL_MAX = 29 - HEADER_BYTES;
1071
1079
  function parseAdvertisedSerial(value) {
1072
1080
  if (!value) return null;
1073
- const bytes = decodeBase64(value);
1081
+ const bytes = base64ToBytes(value);
1074
1082
  if (!bytes || bytes.length <= HEADER_BYTES) return null;
1075
1083
  const company = bytes[0] | bytes[1] << 8;
1076
1084
  if (company !== COMPANY_ID) return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@relai-team/access-sdk",
3
- "version": "0.19.0",
3
+ "version": "0.20.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",