@relai-team/access-sdk 0.11.1 → 0.12.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/README.md CHANGED
@@ -84,6 +84,45 @@ await relai.auth.verifyOtp("dana.the.courier.abc12345@test.relai.us", "455606");
84
84
  Test end-users receive no email, never appear among your real customers, and are
85
85
  refused by production keys.
86
86
 
87
+ ## Finding Exchange Zones
88
+
89
+ ```ts
90
+ // Nearest first. Returns an ARRAY.
91
+ const zones = await relai.exchangeZones.near({ lat: 40.7128, lng: -74.006, radiusM: 5000 });
92
+
93
+ // Everything your key can reach.
94
+ const all = await relai.exchangeZones.list({ minNodes: 2 });
95
+
96
+ // Full detail: towers, compartments, and your app's end-user prices.
97
+ const ez = await relai.exchangeZones.get(zones[0].id);
98
+ ```
99
+
100
+ `near` and `list` return the first page (25 by default, `limit` up to 100) as a
101
+ plain array. When you need to walk past it, `page` gives you the envelope and
102
+ the cursor:
103
+
104
+ ```ts
105
+ let cursor: string | undefined;
106
+ do {
107
+ const page = await relai.exchangeZones.page({ limit: 100, cursor });
108
+ for (const z of page.data) render(z);
109
+ cursor = page.next_cursor ?? undefined;
110
+ } while (cursor);
111
+ ```
112
+
113
+ What your key can see follows the environment: a **sandbox** key sees your app's
114
+ simulated Exchange Zones, a **production** key sees live ones.
115
+
116
+ ## Who is signed in
117
+
118
+ ```ts
119
+ const me = await relai.me();
120
+ // { user_id, email, name, app: { id, environment } }
121
+ ```
122
+
123
+ Requires a session, so call it after `auth.verifyOtp`. A guest (no bearer token)
124
+ gets `401 unauthorized`: a shared guest identity is not a person to report.
125
+
87
126
  ## How an open works
88
127
 
89
128
  `relai.unlock(...)` runs the full server-owns-trust sequence:
package/dist/index.cjs CHANGED
@@ -326,20 +326,38 @@ var ExchangeZonesModule = class {
326
326
  constructor(http) {
327
327
  this.http = http;
328
328
  }
329
- /** Nearby Exchange Zones, closest first. */
330
- near(input) {
331
- const query = { lat: input.lat, lng: input.lng };
332
- if (input.radiusM !== void 0) query["radius_m"] = input.radiusM;
333
- if (input.minNodes !== void 0) query["min_nodes"] = input.minNodes;
334
- if (input.maxNodes !== void 0) query["max_nodes"] = input.maxNodes;
335
- return this.http.request({ path: "/exchange-zones", query });
336
- }
337
- list(input) {
329
+ /**
330
+ * ONE page of Exchange Zones, plus the cursor to continue. `list` and `near`
331
+ * wrap this and hand back just the array, which is what most callers want.
332
+ */
333
+ async page(input) {
338
334
  const query = {};
335
+ if (input?.near) query["near"] = `${input.near.lat},${input.near.lng}`;
336
+ if (input?.radiusM !== void 0) query["radius"] = input.radiusM;
339
337
  if (input?.minNodes !== void 0) query["min_nodes"] = input.minNodes;
340
338
  if (input?.maxNodes !== void 0) query["max_nodes"] = input.maxNodes;
339
+ if (input?.limit !== void 0) query["limit"] = input.limit;
340
+ if (input?.cursor !== void 0) query["cursor"] = input.cursor;
341
341
  return this.http.request({ path: "/exchange-zones", query });
342
342
  }
343
+ /**
344
+ * Nearby Exchange Zones, closest first.
345
+ *
346
+ * Returns the ARRAY, not the `{ data, next_cursor }` envelope the endpoint
347
+ * sends: this used to return the envelope while its type promised an array,
348
+ * so `zones.length` was undefined and `.map` threw. Use `page()` when you need
349
+ * to read past the first page.
350
+ */
351
+ async near(input) {
352
+ const { lat, lng, ...rest } = input;
353
+ const page = await this.page({ ...rest, near: { lat, lng } });
354
+ return page.data;
355
+ }
356
+ /** Every Exchange Zone your key can reach. Returns the array; see `page()` to paginate. */
357
+ async list(input) {
358
+ const page = await this.page(input);
359
+ return page.data;
360
+ }
343
361
  /** Full detail: towers → nodes (includes each tower's parent_ble_id). */
344
362
  get(exchangeZoneId) {
345
363
  return this.http.request({ path: `/exchange-zones/${exchangeZoneId}` });
@@ -659,6 +677,20 @@ var RelaiClient = class {
659
677
  flushTelemetry() {
660
678
  return this.telemetryUploader.flush();
661
679
  }
680
+ /**
681
+ * The signed-in end user, plus which app and environment they are in.
682
+ *
683
+ * Requires a session: call after `auth.verifyOtp`. A guest (no bearer token)
684
+ * gets `401 unauthorized`, because a shared guest identity is not a person to
685
+ * report. This is the client-side counterpart to `endUsers.list()`, which is
686
+ * server-only precisely because it returns OTHER people's details.
687
+ *
688
+ * Documented in the README and the build guide since 0.5, implemented in
689
+ * 0.12.0: it was named in both and never actually existed.
690
+ */
691
+ me() {
692
+ return this.http.request({ path: "/me" });
693
+ }
662
694
  /**
663
695
  * Open a node: request the grant, then drive the physical unlock over the
664
696
  * given transport (challenge → mint → write → ack). Throws
package/dist/index.d.cts CHANGED
@@ -227,6 +227,28 @@ interface ExchangeZone {
227
227
  timezone: string;
228
228
  is_simulated: boolean;
229
229
  }
230
+ /**
231
+ * One page of Exchange Zones, and the cursor to continue.
232
+ *
233
+ * `exchangeZones.list()` and `.near()` hand back the array on this and drop the
234
+ * cursor, because most callers want the nearest few and nothing more. Reach for
235
+ * `.page()` when you actually need to walk past the first page.
236
+ */
237
+ interface ExchangeZonePage {
238
+ data: ExchangeZone[];
239
+ /** Pass as `cursor` for the next page. `null` means this was the last one. */
240
+ next_cursor: string | null;
241
+ }
242
+ /** The signed-in end user, and which app and environment they are signed into. */
243
+ interface Me {
244
+ user_id: string;
245
+ email: string | null;
246
+ name: string | null;
247
+ app: {
248
+ id: string;
249
+ environment: "sandbox" | "production";
250
+ };
251
+ }
230
252
  interface TowerNode {
231
253
  id: string;
232
254
  tower_id: string;
@@ -354,7 +376,35 @@ declare class AuthModule {
354
376
  declare class ExchangeZonesModule {
355
377
  private readonly http;
356
378
  constructor(http: HttpClient);
357
- /** Nearby Exchange Zones, closest first. */
379
+ /**
380
+ * ONE page of Exchange Zones, plus the cursor to continue. `list` and `near`
381
+ * wrap this and hand back just the array, which is what most callers want.
382
+ */
383
+ page(input?: {
384
+ /** Filter to zones near a point, closest first. */
385
+ near?: {
386
+ lat: number;
387
+ lng: number;
388
+ };
389
+ /** Metres around `near`. Server clamps to 1..50000, default 2000. Ignored without `near`. */
390
+ radiusM?: number;
391
+ /** Only zones with at least this many compartments. */
392
+ minNodes?: number;
393
+ /** Only zones with at most this many compartments. */
394
+ maxNodes?: number;
395
+ /** 1 to 100. Defaults to 25. */
396
+ limit?: number;
397
+ /** `next_cursor` from a previous page. */
398
+ cursor?: string;
399
+ }): Promise<ExchangeZonePage>;
400
+ /**
401
+ * Nearby Exchange Zones, closest first.
402
+ *
403
+ * Returns the ARRAY, not the `{ data, next_cursor }` envelope the endpoint
404
+ * sends: this used to return the envelope while its type promised an array,
405
+ * so `zones.length` was undefined and `.map` threw. Use `page()` when you need
406
+ * to read past the first page.
407
+ */
358
408
  near(input: {
359
409
  lat: number;
360
410
  lng: number;
@@ -363,10 +413,15 @@ declare class ExchangeZonesModule {
363
413
  minNodes?: number;
364
414
  /** Only zones with at most this many compartments. */
365
415
  maxNodes?: number;
416
+ /** 1 to 100. Defaults to 25. */
417
+ limit?: number;
366
418
  }): Promise<ExchangeZone[]>;
419
+ /** Every Exchange Zone your key can reach. Returns the array; see `page()` to paginate. */
367
420
  list(input?: {
368
421
  minNodes?: number;
369
422
  maxNodes?: number;
423
+ /** 1 to 100. Defaults to 25. */
424
+ limit?: number;
370
425
  }): Promise<ExchangeZone[]>;
371
426
  /** Full detail: towers → nodes (includes each tower's parent_ble_id). */
372
427
  get(exchangeZoneId: string): Promise<ExchangeZoneDetail>;
@@ -812,6 +867,18 @@ declare class RelaiClient {
812
867
  sent: number;
813
868
  remaining: number;
814
869
  }>;
870
+ /**
871
+ * The signed-in end user, plus which app and environment they are in.
872
+ *
873
+ * Requires a session: call after `auth.verifyOtp`. A guest (no bearer token)
874
+ * gets `401 unauthorized`, because a shared guest identity is not a person to
875
+ * report. This is the client-side counterpart to `endUsers.list()`, which is
876
+ * server-only precisely because it returns OTHER people's details.
877
+ *
878
+ * Documented in the README and the build guide since 0.5, implemented in
879
+ * 0.12.0: it was named in both and never actually existed.
880
+ */
881
+ me(): Promise<Me>;
815
882
  /**
816
883
  * Open a node: request the grant, then drive the physical unlock over the
817
884
  * given transport (challenge → mint → write → ack). Throws
package/dist/index.d.ts CHANGED
@@ -227,6 +227,28 @@ interface ExchangeZone {
227
227
  timezone: string;
228
228
  is_simulated: boolean;
229
229
  }
230
+ /**
231
+ * One page of Exchange Zones, and the cursor to continue.
232
+ *
233
+ * `exchangeZones.list()` and `.near()` hand back the array on this and drop the
234
+ * cursor, because most callers want the nearest few and nothing more. Reach for
235
+ * `.page()` when you actually need to walk past the first page.
236
+ */
237
+ interface ExchangeZonePage {
238
+ data: ExchangeZone[];
239
+ /** Pass as `cursor` for the next page. `null` means this was the last one. */
240
+ next_cursor: string | null;
241
+ }
242
+ /** The signed-in end user, and which app and environment they are signed into. */
243
+ interface Me {
244
+ user_id: string;
245
+ email: string | null;
246
+ name: string | null;
247
+ app: {
248
+ id: string;
249
+ environment: "sandbox" | "production";
250
+ };
251
+ }
230
252
  interface TowerNode {
231
253
  id: string;
232
254
  tower_id: string;
@@ -354,7 +376,35 @@ declare class AuthModule {
354
376
  declare class ExchangeZonesModule {
355
377
  private readonly http;
356
378
  constructor(http: HttpClient);
357
- /** Nearby Exchange Zones, closest first. */
379
+ /**
380
+ * ONE page of Exchange Zones, plus the cursor to continue. `list` and `near`
381
+ * wrap this and hand back just the array, which is what most callers want.
382
+ */
383
+ page(input?: {
384
+ /** Filter to zones near a point, closest first. */
385
+ near?: {
386
+ lat: number;
387
+ lng: number;
388
+ };
389
+ /** Metres around `near`. Server clamps to 1..50000, default 2000. Ignored without `near`. */
390
+ radiusM?: number;
391
+ /** Only zones with at least this many compartments. */
392
+ minNodes?: number;
393
+ /** Only zones with at most this many compartments. */
394
+ maxNodes?: number;
395
+ /** 1 to 100. Defaults to 25. */
396
+ limit?: number;
397
+ /** `next_cursor` from a previous page. */
398
+ cursor?: string;
399
+ }): Promise<ExchangeZonePage>;
400
+ /**
401
+ * Nearby Exchange Zones, closest first.
402
+ *
403
+ * Returns the ARRAY, not the `{ data, next_cursor }` envelope the endpoint
404
+ * sends: this used to return the envelope while its type promised an array,
405
+ * so `zones.length` was undefined and `.map` threw. Use `page()` when you need
406
+ * to read past the first page.
407
+ */
358
408
  near(input: {
359
409
  lat: number;
360
410
  lng: number;
@@ -363,10 +413,15 @@ declare class ExchangeZonesModule {
363
413
  minNodes?: number;
364
414
  /** Only zones with at most this many compartments. */
365
415
  maxNodes?: number;
416
+ /** 1 to 100. Defaults to 25. */
417
+ limit?: number;
366
418
  }): Promise<ExchangeZone[]>;
419
+ /** Every Exchange Zone your key can reach. Returns the array; see `page()` to paginate. */
367
420
  list(input?: {
368
421
  minNodes?: number;
369
422
  maxNodes?: number;
423
+ /** 1 to 100. Defaults to 25. */
424
+ limit?: number;
370
425
  }): Promise<ExchangeZone[]>;
371
426
  /** Full detail: towers → nodes (includes each tower's parent_ble_id). */
372
427
  get(exchangeZoneId: string): Promise<ExchangeZoneDetail>;
@@ -812,6 +867,18 @@ declare class RelaiClient {
812
867
  sent: number;
813
868
  remaining: number;
814
869
  }>;
870
+ /**
871
+ * The signed-in end user, plus which app and environment they are in.
872
+ *
873
+ * Requires a session: call after `auth.verifyOtp`. A guest (no bearer token)
874
+ * gets `401 unauthorized`, because a shared guest identity is not a person to
875
+ * report. This is the client-side counterpart to `endUsers.list()`, which is
876
+ * server-only precisely because it returns OTHER people's details.
877
+ *
878
+ * Documented in the README and the build guide since 0.5, implemented in
879
+ * 0.12.0: it was named in both and never actually existed.
880
+ */
881
+ me(): Promise<Me>;
815
882
  /**
816
883
  * Open a node: request the grant, then drive the physical unlock over the
817
884
  * given transport (challenge → mint → write → ack). Throws
package/dist/index.js CHANGED
@@ -209,20 +209,38 @@ var ExchangeZonesModule = class {
209
209
  constructor(http) {
210
210
  this.http = http;
211
211
  }
212
- /** Nearby Exchange Zones, closest first. */
213
- near(input) {
214
- const query = { lat: input.lat, lng: input.lng };
215
- if (input.radiusM !== void 0) query["radius_m"] = input.radiusM;
216
- if (input.minNodes !== void 0) query["min_nodes"] = input.minNodes;
217
- if (input.maxNodes !== void 0) query["max_nodes"] = input.maxNodes;
218
- return this.http.request({ path: "/exchange-zones", query });
219
- }
220
- list(input) {
212
+ /**
213
+ * ONE page of Exchange Zones, plus the cursor to continue. `list` and `near`
214
+ * wrap this and hand back just the array, which is what most callers want.
215
+ */
216
+ async page(input) {
221
217
  const query = {};
218
+ if (input?.near) query["near"] = `${input.near.lat},${input.near.lng}`;
219
+ if (input?.radiusM !== void 0) query["radius"] = input.radiusM;
222
220
  if (input?.minNodes !== void 0) query["min_nodes"] = input.minNodes;
223
221
  if (input?.maxNodes !== void 0) query["max_nodes"] = input.maxNodes;
222
+ if (input?.limit !== void 0) query["limit"] = input.limit;
223
+ if (input?.cursor !== void 0) query["cursor"] = input.cursor;
224
224
  return this.http.request({ path: "/exchange-zones", query });
225
225
  }
226
+ /**
227
+ * Nearby Exchange Zones, closest first.
228
+ *
229
+ * Returns the ARRAY, not the `{ data, next_cursor }` envelope the endpoint
230
+ * sends: this used to return the envelope while its type promised an array,
231
+ * so `zones.length` was undefined and `.map` threw. Use `page()` when you need
232
+ * to read past the first page.
233
+ */
234
+ async near(input) {
235
+ const { lat, lng, ...rest } = input;
236
+ const page = await this.page({ ...rest, near: { lat, lng } });
237
+ return page.data;
238
+ }
239
+ /** Every Exchange Zone your key can reach. Returns the array; see `page()` to paginate. */
240
+ async list(input) {
241
+ const page = await this.page(input);
242
+ return page.data;
243
+ }
226
244
  /** Full detail: towers → nodes (includes each tower's parent_ble_id). */
227
245
  get(exchangeZoneId) {
228
246
  return this.http.request({ path: `/exchange-zones/${exchangeZoneId}` });
@@ -535,6 +553,20 @@ var RelaiClient = class {
535
553
  flushTelemetry() {
536
554
  return this.telemetryUploader.flush();
537
555
  }
556
+ /**
557
+ * The signed-in end user, plus which app and environment they are in.
558
+ *
559
+ * Requires a session: call after `auth.verifyOtp`. A guest (no bearer token)
560
+ * gets `401 unauthorized`, because a shared guest identity is not a person to
561
+ * report. This is the client-side counterpart to `endUsers.list()`, which is
562
+ * server-only precisely because it returns OTHER people's details.
563
+ *
564
+ * Documented in the README and the build guide since 0.5, implemented in
565
+ * 0.12.0: it was named in both and never actually existed.
566
+ */
567
+ me() {
568
+ return this.http.request({ path: "/me" });
569
+ }
538
570
  /**
539
571
  * Open a node: request the grant, then drive the physical unlock over the
540
572
  * given transport (challenge → mint → write → ack). Throws
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@relai-team/access-sdk",
3
- "version": "0.11.1",
3
+ "version": "0.12.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",