@proveanything/smartlinks 1.15.15 → 1.15.17

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.
@@ -1,4 +1,4 @@
1
- import { Asset, AssetResponse, UploadAssetOptions, UploadFromUrlOptions, ListAssetsOptions, GetAssetOptions, RemoveAssetOptions, AdminListAssetsOptions, AdminListAssetsResponse, UpdateAssetOptions, ReplaceAssetFileOptions, DeleteAssetOptions, BulkDeleteAssetsOptions, RequestUploadTokenOptions, UploadTokenResponse, PublicTokenUploadOptions } from "../types/asset";
1
+ import { Asset, AssetResponse, UploadAssetOptions, UploadFromUrlOptions, ListAssetsOptions, GetAssetOptions, RemoveAssetOptions, AdminListAssetsOptions, AdminListAssetsResponse, UpdateAssetOptions, ReplaceAssetFileOptions, DeleteAssetOptions, BulkDeleteAssetsOptions, RequestUploadTokenOptions, UploadTokenResponse, PublicTokenUploadOptions, CreateResumableUploadOptions, ResumableUploadHandle } from "../types/asset";
2
2
  export declare namespace asset {
3
3
  /**
4
4
  * Error type for asset uploads
@@ -136,4 +136,27 @@ export declare namespace asset {
136
136
  * has `reviewRequired: true`.
137
137
  */
138
138
  function publicUploadWithToken(options: PublicTokenUploadOptions): Promise<Asset>;
139
+ /** Thrown by a resumable `start()`/`resume()` when the caller pauses mid-transfer. */
140
+ class UploadPausedError extends Error {
141
+ constructor();
142
+ }
143
+ /**
144
+ * Open a resumable upload for a large file (e.g. video). The bytes are chunked
145
+ * directly to storage and can be paused/resumed — including after a page reload
146
+ * or app restart, by persisting `handle.id` and calling {@link resumeUpload}.
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * const handle = await asset.createResumableUpload({ file, scope, appId })
151
+ * localStorage.setItem('pendingUpload', handle.id) // survives reload
152
+ * const uploaded = await handle.start({ onProgress: p => setPct(p) })
153
+ * ```
154
+ */
155
+ function createResumableUpload(options: CreateResumableUploadOptions): Promise<ResumableUploadHandle>;
156
+ /**
157
+ * Resume a previously-created resumable upload after a reload/app restart.
158
+ * Pass the persisted `handle.id` and the same `File`; the transfer continues
159
+ * from the offset storage already holds rather than restarting.
160
+ */
161
+ function resumeUpload(handleId: string, file: File): Promise<ResumableUploadHandle>;
139
162
  }
package/dist/api/asset.js CHANGED
@@ -104,6 +104,14 @@ export var asset;
104
104
  }
105
105
  };
106
106
  xhr.onerror = () => reject(new AssetUploadError("Network error during asset upload", 'NETWORK_ERROR'));
107
+ if (options.signal) {
108
+ if (options.signal.aborted) {
109
+ xhr.abort();
110
+ return reject(new AssetUploadError("Upload aborted", 'NETWORK_ERROR'));
111
+ }
112
+ options.signal.addEventListener('abort', () => xhr.abort(), { once: true });
113
+ xhr.onabort = () => reject(new AssetUploadError("Upload aborted", 'NETWORK_ERROR'));
114
+ }
107
115
  xhr.send(formData);
108
116
  });
109
117
  }
@@ -529,4 +537,174 @@ export var asset;
529
537
  return response.json();
530
538
  }
531
539
  asset.publicUploadWithToken = publicUploadWithToken;
540
+ // ---------------------------------------------------------------------------
541
+ // Resumable uploads (large files, e.g. video) — GCS-backed, chunked, resumable
542
+ // ---------------------------------------------------------------------------
543
+ const RESUMABLE_CHUNK_SIZE = 8 * 1024 * 1024; // 8 MiB — must be a multiple of 256 KiB (GCS rule)
544
+ const RESUMABLE_MAX_RETRIES = 5;
545
+ /** Thrown by a resumable `start()`/`resume()` when the caller pauses mid-transfer. */
546
+ class UploadPausedError extends Error {
547
+ constructor() { super('Upload paused'); this.name = 'UploadPausedError'; }
548
+ }
549
+ asset.UploadPausedError = UploadPausedError;
550
+ function backoff(attempt) {
551
+ const ms = Math.min(30000, 1000 * Math.pow(2, attempt - 1));
552
+ return new Promise(r => setTimeout(r, ms));
553
+ }
554
+ class ResumableUpload {
555
+ constructor(uploadId, // signed JWT — capability for finalize
556
+ sessionUrl, // GCS resumable session URI
557
+ file, finalizePath, finalizeBody) {
558
+ this.uploadId = uploadId;
559
+ this.sessionUrl = sessionUrl;
560
+ this.file = file;
561
+ this.finalizePath = finalizePath;
562
+ this.finalizeBody = finalizeBody;
563
+ this._paused = false;
564
+ this._offset = 0;
565
+ }
566
+ get id() {
567
+ const st = { u: this.uploadId, s: this.sessionUrl, n: this.file.name, z: this.file.size, f: this.finalizePath };
568
+ return JSON.stringify(st);
569
+ }
570
+ get size() { return this.file.size; }
571
+ pause() { this._paused = true; }
572
+ resume(options) {
573
+ this._paused = false;
574
+ return this.start(options);
575
+ }
576
+ async start(options) {
577
+ this._paused = false;
578
+ const onProgress = options === null || options === void 0 ? void 0 : options.onProgress;
579
+ const signal = options === null || options === void 0 ? void 0 : options.signal;
580
+ // Probe the storage offset first — this is what makes resume work after a reload.
581
+ this._offset = await this.probeOffset(signal);
582
+ while (this._offset < this.file.size) {
583
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted)
584
+ throw new AssetUploadError('Upload aborted', 'NETWORK_ERROR');
585
+ if (this._paused)
586
+ throw new UploadPausedError();
587
+ const end = Math.min(this._offset + RESUMABLE_CHUNK_SIZE, this.file.size);
588
+ const complete = await this.putChunk(this._offset, end, signal);
589
+ this._offset = end;
590
+ if (onProgress)
591
+ onProgress(Math.round((this._offset / this.file.size) * 100));
592
+ if (complete)
593
+ break;
594
+ }
595
+ return post(this.finalizePath, this.finalizeBody);
596
+ }
597
+ // PUT with `bytes * /total` returns the current stored offset (or completion).
598
+ async probeOffset(signal) {
599
+ const res = await this.putWithRetry({ 'Content-Range': `bytes */${this.file.size}` }, undefined, signal);
600
+ if (res.status === 200 || res.status === 201)
601
+ return this.file.size;
602
+ if (res.status === 308) {
603
+ const range = res.headers.get('Range');
604
+ const m = range && /bytes=0-(\d+)/.exec(range);
605
+ return m ? parseInt(m[1], 10) + 1 : 0;
606
+ }
607
+ if (res.status === 404 || res.status === 410)
608
+ throw new AssetUploadError('Upload session expired', 'UNKNOWN');
609
+ throw new AssetUploadError(`Unexpected resume-probe status ${res.status}`, 'UNKNOWN');
610
+ }
611
+ // Returns true when the final chunk completed the upload (2xx from GCS).
612
+ async putChunk(start, end, signal) {
613
+ const blob = this.file.slice(start, end);
614
+ const res = await this.putWithRetry({ 'Content-Range': `bytes ${start}-${end - 1}/${this.file.size}` }, blob, signal);
615
+ if (res.status === 200 || res.status === 201)
616
+ return true;
617
+ if (res.status === 308)
618
+ return false;
619
+ throw new AssetUploadError(`Chunk upload failed (${res.status})`, res.status === 413 ? 'FILE_TOO_LARGE' : 'UNKNOWN');
620
+ }
621
+ async putWithRetry(headers, body, signal) {
622
+ let attempt = 0;
623
+ while (true) {
624
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted)
625
+ throw new AssetUploadError('Upload aborted', 'NETWORK_ERROR');
626
+ try {
627
+ const res = await fetch(this.sessionUrl, { method: 'PUT', headers, body, signal });
628
+ if (res.status >= 500 && attempt < RESUMABLE_MAX_RETRIES) {
629
+ attempt++;
630
+ await backoff(attempt);
631
+ continue;
632
+ }
633
+ return res;
634
+ }
635
+ catch (err) {
636
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted)
637
+ throw new AssetUploadError('Upload aborted', 'NETWORK_ERROR');
638
+ if (attempt < RESUMABLE_MAX_RETRIES) {
639
+ attempt++;
640
+ await backoff(attempt);
641
+ continue;
642
+ }
643
+ throw new AssetUploadError('Network error during resumable upload', 'NETWORK_ERROR');
644
+ }
645
+ }
646
+ }
647
+ }
648
+ function resumableBasePath(opts) {
649
+ const prefix = (opts.admin && !opts.token) ? '/admin' : '/public';
650
+ return `${prefix}/collection/${encodeURIComponent(opts.collectionId)}/asset/resumable`;
651
+ }
652
+ /**
653
+ * Open a resumable upload for a large file (e.g. video). The bytes are chunked
654
+ * directly to storage and can be paused/resumed — including after a page reload
655
+ * or app restart, by persisting `handle.id` and calling {@link resumeUpload}.
656
+ *
657
+ * @example
658
+ * ```ts
659
+ * const handle = await asset.createResumableUpload({ file, scope, appId })
660
+ * localStorage.setItem('pendingUpload', handle.id) // survives reload
661
+ * const uploaded = await handle.start({ onProgress: p => setPct(p) })
662
+ * ```
663
+ */
664
+ async function createResumableUpload(options) {
665
+ const { file, scope, name, appId, token, admin } = options;
666
+ const base = resumableBasePath({ admin, token, collectionId: scope.collectionId });
667
+ const startBody = {
668
+ filename: name || file.name,
669
+ mime: file.type || 'application/octet-stream',
670
+ appId,
671
+ };
672
+ if (scope.type !== 'collection')
673
+ startBody.productId = scope.productId;
674
+ if (scope.type === 'proof')
675
+ startBody.proofId = scope.proofId;
676
+ const started = await post(base, startBody, token ? { 'X-Upload-Token': token } : undefined);
677
+ const finalizePath = `${base}/${encodeURIComponent(started.uploadId)}/complete`;
678
+ const finalizeBody = {};
679
+ if (name)
680
+ finalizeBody.name = name;
681
+ if (options.metadata)
682
+ finalizeBody.metadata = options.metadata;
683
+ return new ResumableUpload(started.uploadId, started.sessionUrl, file, finalizePath, finalizeBody);
684
+ }
685
+ asset.createResumableUpload = createResumableUpload;
686
+ /**
687
+ * Resume a previously-created resumable upload after a reload/app restart.
688
+ * Pass the persisted `handle.id` and the same `File`; the transfer continues
689
+ * from the offset storage already holds rather than restarting.
690
+ */
691
+ async function resumeUpload(handleId, file) {
692
+ let st;
693
+ try {
694
+ st = JSON.parse(handleId);
695
+ }
696
+ catch (_b) {
697
+ throw new AssetUploadError('Invalid resumable upload handle', 'UNKNOWN');
698
+ }
699
+ if (!st.u || !st.s || !st.f)
700
+ throw new AssetUploadError('Invalid resumable upload handle', 'UNKNOWN');
701
+ if (typeof st.z === 'number' && file.size !== st.z) {
702
+ throw new AssetUploadError('Resumed file does not match the original upload', 'UNKNOWN');
703
+ }
704
+ const finalizeBody = {};
705
+ if (st.n)
706
+ finalizeBody.name = st.n;
707
+ return new ResumableUpload(st.u, st.s, file, st.f, finalizeBody);
708
+ }
709
+ asset.resumeUpload = resumeUpload;
532
710
  })(asset || (asset = {}));
@@ -122,7 +122,7 @@ export var navigation;
122
122
  type: 'smartlinks-navigate',
123
123
  appId: link.appId,
124
124
  path: link.kind === 'deep' ? deepPath(link.deepLinkId) : '/',
125
- params: link.kind === 'deep' ? ((_b = link.params) !== null && _b !== void 0 ? _b : {}) : {},
125
+ params: (link.kind === 'deep' || link.kind === 'app') ? ((_b = link.params) !== null && _b !== void 0 ? _b : {}) : {},
126
126
  target: (_c = link.target) !== null && _c !== void 0 ? _c : '_self',
127
127
  }, '*');
128
128
  return;
@@ -134,7 +134,8 @@ export var navigation;
134
134
  const hash = link.kind === 'deep'
135
135
  ? `#${deepPath(link.deepLinkId)}${qs(link.params)}`
136
136
  : `#/`;
137
- const url = `${win.location.pathname}?appId=${encodeURIComponent(link.appId)}${hash}`;
137
+ const appParams = link.kind === 'app' && link.params ? qs(link.params).replace(/^\?/, '&') : '';
138
+ const url = `${win.location.pathname}?appId=${encodeURIComponent(link.appId)}${appParams}${hash}`;
138
139
  if (link.target === '_blank') {
139
140
  win.open(url, '_blank', windowFeatures());
140
141
  }
@@ -1,4 +1,4 @@
1
- import { ProofResponse, ProofCreateRequest, ProofUpdateRequest, ProofClaimRequest } from "../types/proof";
1
+ import { ProofResponse, ProofCreateRequest, ProofUpdateRequest, ProofClaimRequest, ProofGrant, CreateGrantOptions, RedeemGrantOptions, RedeemGrantResult } from "../types/proof";
2
2
  export declare namespace proof {
3
3
  /**
4
4
  * Retrieves a single Proof by Collection ID, Product ID, and Proof ID.
@@ -104,4 +104,22 @@ export declare namespace proof {
104
104
  data: {
105
105
  targetProductId: string;
106
106
  }): Promise<ProofResponse>;
107
+ /**
108
+ * Create a share grant on a proof (owner / collection admin only). The returned
109
+ * grant includes `token` — the opaque bearer secret, available ONLY on this
110
+ * response. Embed it in a share link and hand recipients {@link redeemGrant} /
111
+ * {@link setGrantToken}.
112
+ */
113
+ function createGrant(collectionId: string, productId: string, proofId: string, options: CreateGrantOptions): Promise<ProofGrant>;
114
+ /** List the active + past grants on a proof (owner / collection admin only). Tokens are never returned here. */
115
+ function listGrants(collectionId: string, productId: string, proofId: string): Promise<ProofGrant[]>;
116
+ /** Revoke a grant by id (owner / collection admin only). Takes effect immediately. */
117
+ function revokeGrant(collectionId: string, productId: string, proofId: string, grantId: string): Promise<void>;
118
+ /**
119
+ * Redeem a grant token (anonymous or signed-in). Records the redemption and
120
+ * returns the granted scope, or — for a `verify_owner` grant — an ownership
121
+ * assertion (never the account). After redeeming, call
122
+ * {@link setGrantToken} so subsequent data requests carry the token.
123
+ */
124
+ function redeemGrant(collectionId: string, productId: string, proofId: string, token: string, options?: RedeemGrantOptions): Promise<RedeemGrantResult>;
107
125
  }
package/dist/api/proof.js CHANGED
@@ -156,4 +156,48 @@ export var proof;
156
156
  return post(path, data);
157
157
  }
158
158
  proof.migrate = migrate;
159
+ // ---------------------------------------------------------------------------
160
+ // Share grants — delegated, scoped, revocable bearer access to this proof
161
+ // ---------------------------------------------------------------------------
162
+ function grantBase(collectionId, productId, proofId) {
163
+ return `/public/collection/${encodeURIComponent(collectionId)}/product/${encodeURIComponent(productId)}/proof/${encodeURIComponent(proofId)}/grant`;
164
+ }
165
+ /**
166
+ * Create a share grant on a proof (owner / collection admin only). The returned
167
+ * grant includes `token` — the opaque bearer secret, available ONLY on this
168
+ * response. Embed it in a share link and hand recipients {@link redeemGrant} /
169
+ * {@link setGrantToken}.
170
+ */
171
+ async function createGrant(collectionId, productId, proofId, options) {
172
+ const body = { scope: options.scope };
173
+ if (options.audience)
174
+ body.audience = options.audience;
175
+ if (options.expiresAt)
176
+ body.expiresAt = options.expiresAt instanceof Date ? options.expiresAt.toISOString() : options.expiresAt;
177
+ return post(grantBase(collectionId, productId, proofId), body);
178
+ }
179
+ proof.createGrant = createGrant;
180
+ /** List the active + past grants on a proof (owner / collection admin only). Tokens are never returned here. */
181
+ async function listGrants(collectionId, productId, proofId) {
182
+ return request(grantBase(collectionId, productId, proofId));
183
+ }
184
+ proof.listGrants = listGrants;
185
+ /** Revoke a grant by id (owner / collection admin only). Takes effect immediately. */
186
+ async function revokeGrant(collectionId, productId, proofId, grantId) {
187
+ return del(`${grantBase(collectionId, productId, proofId)}/${encodeURIComponent(grantId)}`);
188
+ }
189
+ proof.revokeGrant = revokeGrant;
190
+ /**
191
+ * Redeem a grant token (anonymous or signed-in). Records the redemption and
192
+ * returns the granted scope, or — for a `verify_owner` grant — an ownership
193
+ * assertion (never the account). After redeeming, call
194
+ * {@link setGrantToken} so subsequent data requests carry the token.
195
+ */
196
+ async function redeemGrant(collectionId, productId, proofId, token, options) {
197
+ const body = { token };
198
+ if (options === null || options === void 0 ? void 0 : options.guestName)
199
+ body.guestName = options.guestName;
200
+ return post(`${grantBase(collectionId, productId, proofId)}/redeem`, body);
201
+ }
202
+ proof.redeemGrant = redeemGrant;
159
203
  })(proof || (proof = {}));
@@ -1,6 +1,6 @@
1
1
  # Smartlinks API Summary
2
2
 
3
- Version: 1.15.15 | Generated: 2026-07-29T17:46:34.198Z
3
+ Version: 1.15.17 | Generated: 2026-08-18T08:10:50.608Z
4
4
 
5
5
  This is a concise summary of all available API functions and types.
6
6
 
@@ -170,6 +170,12 @@ Replace or augment globally applied custom headers.
170
170
  **setBearerToken**(token: string | undefined) → `void`
171
171
  Allows setting the bearerToken at runtime (e.g. after login/logout). Clears the HTTP cache whenever the token actually changes so that stale user-scoped responses (e.g. /account/profile) are not served after a login or logout event.
172
172
 
173
+ **setGrantToken**(token: string | undefined) → `void`
174
+ Set (or clear) the per-proof share-grant token. When set, it is attached as the `X-Grant-Token` header on every request, so a recipient who has opened a shared link can read/comment on the granted proof's data. Pass `undefined` to clear it. The server re-checks the grant against the database on every request, so calling `revokeGrant` invalidates an in-flight token immediately. Clears the GET cache on change so grant-tier responses are not served after the token changes. ```ts // On opening ?proofId=…&shareToken=abc setGrantToken(shareToken) const { attestations } = await proof.get(...) // now sees owner-tier memories ```
175
+
176
+ **getGrantToken**() → `string | undefined`
177
+ Returns the currently-set share-grant token, or `undefined`.
178
+
173
179
  **getBearerToken**() → `string | undefined`
174
180
  Returns the bearer token currently held by the SDK, or `undefined` if none is set. In proxy mode, credentials are held by the parent frame, not the local SDK, so this returns `undefined` even when the caller is authenticated.
175
181
 
@@ -2459,6 +2465,7 @@ interface UploadAssetOptions {
2459
2465
  onProgress?: (percent: number) => void
2460
2466
  appId?: string
2461
2467
  admin?: boolean
2468
+ signal?: AbortSignal
2462
2469
  }
2463
2470
  ```
2464
2471
 
@@ -2639,6 +2646,43 @@ interface PublicTokenUploadOptions {
2639
2646
  }
2640
2647
  ```
2641
2648
 
2649
+ **CreateResumableUploadOptions** (interface)
2650
+ ```typescript
2651
+ interface CreateResumableUploadOptions {
2652
+ file: File
2653
+ scope:
2654
+ | { type: 'collection'; collectionId: string }
2655
+ | { type: 'product'; collectionId: string; productId: string }
2656
+ | { type: 'proof'; collectionId: string; productId: string; proofId: string }
2657
+ name?: string
2658
+ metadata?: Record<string, any>
2659
+ appId?: string
2660
+ admin?: boolean
2661
+ * Upload token id (from {@link requestUploadToken}) for public/unauthenticated
2662
+ * uploads. When provided, the public resumable route is used.
2663
+ token?: string
2664
+ }
2665
+ ```
2666
+
2667
+ **ResumableStartOptions** (interface)
2668
+ ```typescript
2669
+ interface ResumableStartOptions {
2670
+ onProgress?: (percent: number) => void
2671
+ signal?: AbortSignal
2672
+ }
2673
+ ```
2674
+
2675
+ **ResumableUploadHandle** (interface)
2676
+ ```typescript
2677
+ interface ResumableUploadHandle {
2678
+ readonly id: string
2679
+ readonly size: number
2680
+ start(options?: ResumableStartOptions): Promise<Asset>
2681
+ pause(): void
2682
+ resume(options?: ResumableStartOptions): Promise<Asset>
2683
+ }
2684
+ ```
2685
+
2642
2686
  **AssetResponse** = `Asset`
2643
2687
 
2644
2688
  ### attestation
@@ -7249,6 +7293,50 @@ interface ProofFieldsConfig {
7249
7293
  }
7250
7294
  ```
7251
7295
 
7296
+ **GrantAudience** (interface)
7297
+ ```typescript
7298
+ interface GrantAudience {
7299
+ kind: 'public_link' | 'named'
7300
+ email?: string
7301
+ userId?: string
7302
+ }
7303
+ ```
7304
+
7305
+ **ProofGrant** (interface)
7306
+ ```typescript
7307
+ interface ProofGrant {
7308
+ grantId: string
7309
+ proofId: string
7310
+ productId?: string | null
7311
+ scope: GrantScope[]
7312
+ audience: GrantAudience
7313
+ createdBy: string
7314
+ expiresAt?: string | null
7315
+ revokedAt?: string | null
7316
+ redeemedBy?: { userId?: string; guestName?: string; redeemedAt: string }
7317
+ redeemCount: number
7318
+ createdAt: string
7319
+ updatedAt: string
7320
+ token?: string
7321
+ }
7322
+ ```
7323
+
7324
+ **CreateGrantOptions** (interface)
7325
+ ```typescript
7326
+ interface CreateGrantOptions {
7327
+ scope: GrantScope[]
7328
+ audience?: GrantAudience
7329
+ expiresAt?: Date | string
7330
+ }
7331
+ ```
7332
+
7333
+ **RedeemGrantOptions** (interface)
7334
+ ```typescript
7335
+ interface RedeemGrantOptions {
7336
+ guestName?: string
7337
+ }
7338
+ ```
7339
+
7252
7340
  **ProofResponse** = `Proof`
7253
7341
 
7254
7342
  **ProofUpdateRequest** = `Partial<ProofCreateRequest>`
@@ -7259,6 +7347,10 @@ interface ProofFieldsConfig {
7259
7347
 
7260
7348
  **ProofFieldDef** = `ScopedFieldDef & { scope?: ProofFieldScope }`
7261
7349
 
7350
+ **GrantScope** = `'read' | 'comment' | 'admin' | 'verify_owner'`
7351
+
7352
+ **RedeemGrantResult** = ``
7353
+
7262
7354
  ### qr
7263
7355
 
7264
7356
  **QrShortCodeLookupResponse** (interface)
@@ -8479,6 +8571,12 @@ Request a single-use upload token for a public (unauthenticated) upload. The tok
8479
8571
  **publicUploadWithToken**(options: PublicTokenUploadOptions) → `Promise<Asset>`
8480
8572
  Upload a file using a single-use upload token (no admin auth required). Assets are created with `status: 'pending_review'` when the token policy has `reviewRequired: true`.
8481
8573
 
8574
+ **createResumableUpload**(options: CreateResumableUploadOptions) → `Promise<ResumableUploadHandle>`
8575
+ Open a resumable upload for a large file (e.g. video). The bytes are chunked directly to storage and can be paused/resumed — including after a page reload or app restart, by persisting `handle.id` and calling {@link resumeUpload}. ```ts const handle = await asset.createResumableUpload({ file, scope, appId }) localStorage.setItem('pendingUpload', handle.id) // survives reload const uploaded = await handle.start({ onProgress: p => setPct(p) }) ```
8576
+
8577
+ **resumeUpload**(handleId: string, file: File) → `Promise<ResumableUploadHandle>`
8578
+ Resume a previously-created resumable upload after a reload/app restart. Pass the persisted `handle.id` and the same `File`; the transfer continues from the offset storage already holds rather than restarting.
8579
+
8482
8580
  ### async
8483
8581
 
8484
8582
  **enqueueAsyncJob**(collectionId: string,
@@ -9893,6 +9991,30 @@ Get proofs for a batch (admin only). GET /admin/collection/:collectionId/product
9893
9991
  data: { targetProductId: string }) → `Promise<ProofResponse>`
9894
9992
  Migrate a proof to a different product within the same collection (admin only). Because the Firestore ledger document ID is `{productId}-{proofId}`, a proof cannot simply be re-assigned to another product by updating a field — the document must be re-keyed. This endpoint handles that atomically: 1. Reads the source ledger document (`{sourceProductId}-{proofId}`). 2. Writes a new document (`{targetProductId}-{proofId}`) with `productId` and `proofGroup` updated. The short `proofId` (nanoid) is unchanged. 3. Writes a migration history entry to the new document's `history` subcollection (snapshot of the original proof + migration metadata). 4. Copies all subcollections — `assets`, `attestations`, `history` — from the old document to the new one. 5. Deletes the old subcollections and then the old document. Repeated migrations are safe — each one appends a history record; no migration metadata is stored on the proof document itself. ```typescript const migrated = await proof.migrate('coll_123', 'prod_old', 'proof_abc', { targetProductId: 'prod_new', }) console.log(migrated.productId) // 'prod_new' ```
9895
9993
 
9994
+ **createGrant**(collectionId: string,
9995
+ productId: string,
9996
+ proofId: string,
9997
+ options: CreateGrantOptions) → `Promise<ProofGrant>`
9998
+ Create a share grant on a proof (owner / collection admin only). The returned grant includes `token` — the opaque bearer secret, available ONLY on this response. Embed it in a share link and hand recipients {@link redeemGrant} / {@link setGrantToken}.
9999
+
10000
+ **listGrants**(collectionId: string,
10001
+ productId: string,
10002
+ proofId: string) → `Promise<ProofGrant[]>`
10003
+ List the active + past grants on a proof (owner / collection admin only). Tokens are never returned here.
10004
+
10005
+ **revokeGrant**(collectionId: string,
10006
+ productId: string,
10007
+ proofId: string,
10008
+ grantId: string) → `Promise<void>`
10009
+ Revoke a grant by id (owner / collection admin only). Takes effect immediately.
10010
+
10011
+ **redeemGrant**(collectionId: string,
10012
+ productId: string,
10013
+ proofId: string,
10014
+ token: string,
10015
+ options?: RedeemGrantOptions) → `Promise<RedeemGrantResult>`
10016
+ Redeem a grant token (anonymous or signed-in). Records the redemption and returns the granted scope, or — for a `verify_owner` grant — an ownership assertion (never the account). After redeeming, call {@link setGrantToken} so subsequent data requests carry the token.
10017
+
9896
10018
  ### publicClient
9897
10019
 
9898
10020
  **chat**(collectionId: string,
package/dist/http.d.ts CHANGED
@@ -49,6 +49,25 @@ export declare function setExtraHeaders(headers: Record<string, string>): void;
49
49
  * login or logout event.
50
50
  */
51
51
  export declare function setBearerToken(token: string | undefined): void;
52
+ /**
53
+ * Set (or clear) the per-proof share-grant token. When set, it is attached as the
54
+ * `X-Grant-Token` header on every request, so a recipient who has opened a shared
55
+ * link can read/comment on the granted proof's data. Pass `undefined` to clear it.
56
+ *
57
+ * The server re-checks the grant against the database on every request, so calling
58
+ * `revokeGrant` invalidates an in-flight token immediately. Clears the GET cache on
59
+ * change so grant-tier responses are not served after the token changes.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * // On opening ?proofId=…&shareToken=abc
64
+ * setGrantToken(shareToken)
65
+ * const { attestations } = await proof.get(...) // now sees owner-tier memories
66
+ * ```
67
+ */
68
+ export declare function setGrantToken(token: string | undefined): void;
69
+ /** Returns the currently-set share-grant token, or `undefined`. */
70
+ export declare function getGrantToken(): string | undefined;
52
71
  /**
53
72
  * Returns the bearer token currently held by the SDK, or `undefined` if none is set.
54
73
  * In proxy mode, credentials are held by the parent frame, not the local SDK,
package/dist/http.js CHANGED
@@ -39,6 +39,12 @@ let extraHeadersGlobal = {};
39
39
  * issue refresh tokens and short-lived access tokens. Undefined → web behaviour.
40
40
  */
41
41
  let clientPlatform = undefined;
42
+ /**
43
+ * Per-proof share-grant bearer token. When set (via setGrantToken), it is attached
44
+ * as `X-Grant-Token` on every request so the server can evaluate the grant on any
45
+ * data call that touches the granted proof (attestations, threads, app data).
46
+ */
47
+ let grantToken = undefined;
42
48
  /** Whether initializeApi has been successfully called at least once. */
43
49
  let initialized = false;
44
50
  /** Safely returns the current browser hostname, or an empty string in non-browser / Node environments. */
@@ -466,6 +472,34 @@ export function setBearerToken(token) {
466
472
  if (cachePersistence !== 'none')
467
473
  idbClear().catch(() => { });
468
474
  }
475
+ /**
476
+ * Set (or clear) the per-proof share-grant token. When set, it is attached as the
477
+ * `X-Grant-Token` header on every request, so a recipient who has opened a shared
478
+ * link can read/comment on the granted proof's data. Pass `undefined` to clear it.
479
+ *
480
+ * The server re-checks the grant against the database on every request, so calling
481
+ * `revokeGrant` invalidates an in-flight token immediately. Clears the GET cache on
482
+ * change so grant-tier responses are not served after the token changes.
483
+ *
484
+ * @example
485
+ * ```ts
486
+ * // On opening ?proofId=…&shareToken=abc
487
+ * setGrantToken(shareToken)
488
+ * const { attestations } = await proof.get(...) // now sees owner-tier memories
489
+ * ```
490
+ */
491
+ export function setGrantToken(token) {
492
+ if (token === grantToken)
493
+ return;
494
+ grantToken = token;
495
+ httpCache.clear();
496
+ if (cachePersistence !== 'none')
497
+ idbClear().catch(() => { });
498
+ }
499
+ /** Returns the currently-set share-grant token, or `undefined`. */
500
+ export function getGrantToken() {
501
+ return grantToken;
502
+ }
469
503
  /**
470
504
  * Returns the bearer token currently held by the SDK, or `undefined` if none is set.
471
505
  * In proxy mode, credentials are held by the parent frame, not the local SDK,
@@ -1107,6 +1141,10 @@ export async function request(path) {
1107
1141
  headers["AUTHORIZATION"] = `Bearer ${bearerToken}`;
1108
1142
  if (clientPlatform)
1109
1143
  headers["X-Client-Platform"] = clientPlatform;
1144
+ if (grantToken)
1145
+ headers["X-Grant-Token"] = grantToken;
1146
+ if (grantToken)
1147
+ headers["X-Grant-Token"] = grantToken;
1110
1148
  if (ngrokSkipBrowserWarning)
1111
1149
  headers["ngrok-skip-browser-warning"] = "true";
1112
1150
  const _getDomain = getSourceDomain();
@@ -1182,6 +1220,8 @@ export async function post(path, body, extraHeaders) {
1182
1220
  headers["AUTHORIZATION"] = `Bearer ${bearerToken}`;
1183
1221
  if (clientPlatform)
1184
1222
  headers["X-Client-Platform"] = clientPlatform;
1223
+ if (grantToken)
1224
+ headers["X-Grant-Token"] = grantToken;
1185
1225
  if (ngrokSkipBrowserWarning)
1186
1226
  headers["ngrok-skip-browser-warning"] = "true";
1187
1227
  const _postDomain = getSourceDomain();
@@ -1241,6 +1281,8 @@ export async function put(path, body, extraHeaders) {
1241
1281
  headers["AUTHORIZATION"] = `Bearer ${bearerToken}`;
1242
1282
  if (clientPlatform)
1243
1283
  headers["X-Client-Platform"] = clientPlatform;
1284
+ if (grantToken)
1285
+ headers["X-Grant-Token"] = grantToken;
1244
1286
  if (ngrokSkipBrowserWarning)
1245
1287
  headers["ngrok-skip-browser-warning"] = "true";
1246
1288
  const _putDomain = getSourceDomain();
@@ -1300,6 +1342,8 @@ export async function patch(path, body, extraHeaders) {
1300
1342
  headers["AUTHORIZATION"] = `Bearer ${bearerToken}`;
1301
1343
  if (clientPlatform)
1302
1344
  headers["X-Client-Platform"] = clientPlatform;
1345
+ if (grantToken)
1346
+ headers["X-Grant-Token"] = grantToken;
1303
1347
  if (ngrokSkipBrowserWarning)
1304
1348
  headers["ngrok-skip-browser-warning"] = "true";
1305
1349
  const _patchDomain = getSourceDomain();
@@ -1404,7 +1448,7 @@ export async function requestWithOptions(path, options) {
1404
1448
  }
1405
1449
  }
1406
1450
  const _rwoDomain = getSourceDomain();
1407
- const headers = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ "Content-Type": "application/json" }, (apiKey ? { "X-API-Key": apiKey } : {})), (bearerToken ? { "AUTHORIZATION": `Bearer ${bearerToken}` } : {})), (clientPlatform ? { "X-Client-Platform": clientPlatform } : {})), (ngrokSkipBrowserWarning ? { "ngrok-skip-browser-warning": "true" } : {})), (_rwoDomain ? { "X-Source-Domain": _rwoDomain } : {})), extraHeaders);
1451
+ const headers = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ "Content-Type": "application/json" }, (apiKey ? { "X-API-Key": apiKey } : {})), (bearerToken ? { "AUTHORIZATION": `Bearer ${bearerToken}` } : {})), (clientPlatform ? { "X-Client-Platform": clientPlatform } : {})), (grantToken ? { "X-Grant-Token": grantToken } : {})), (ngrokSkipBrowserWarning ? { "ngrok-skip-browser-warning": "true" } : {})), (_rwoDomain ? { "X-Source-Domain": _rwoDomain } : {})), extraHeaders);
1408
1452
  // Merge global custom headers (do not override existing keys from options.headers)
1409
1453
  for (const [k, v] of Object.entries(extraHeadersGlobal))
1410
1454
  if (!(k in headers))
@@ -1510,6 +1554,8 @@ export async function del(path, extraHeaders) {
1510
1554
  headers["AUTHORIZATION"] = `Bearer ${bearerToken}`;
1511
1555
  if (clientPlatform)
1512
1556
  headers["X-Client-Platform"] = clientPlatform;
1557
+ if (grantToken)
1558
+ headers["X-Grant-Token"] = grantToken;
1513
1559
  if (ngrokSkipBrowserWarning)
1514
1560
  headers["ngrok-skip-browser-warning"] = "true";
1515
1561
  const _delDomain = getSourceDomain();
@@ -1552,6 +1598,8 @@ export function getApiHeaders() {
1552
1598
  headers["AUTHORIZATION"] = `Bearer ${bearerToken}`;
1553
1599
  if (clientPlatform)
1554
1600
  headers["X-Client-Platform"] = clientPlatform;
1601
+ if (grantToken)
1602
+ headers["X-Grant-Token"] = grantToken;
1555
1603
  if (ngrokSkipBrowserWarning)
1556
1604
  headers["ngrok-skip-browser-warning"] = "true";
1557
1605
  const sourceDomain = getSourceDomain();
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { initializeApi, isInitialized, hasAuthCredentials, configureSdkCache, invalidateCache, request, post, put, patch, del, sendCustomProxyMessage, getApiHeaders, isProxyEnabled, setBearerToken, getBearerToken } from "./http";
1
+ export { initializeApi, isInitialized, hasAuthCredentials, configureSdkCache, invalidateCache, request, post, put, patch, del, sendCustomProxyMessage, getApiHeaders, isProxyEnabled, setBearerToken, getBearerToken, setGrantToken, getGrantToken } from "./http";
2
2
  export * from "./api";
3
3
  export * from "./types";
4
4
  export { iframe } from "./iframe";
@@ -17,7 +17,7 @@ export type { AdditionalGtin, ISODateString, JsonPrimitive, JsonValue, ProductCr
17
17
  export type { TranslationLookupMode, TranslationContentType, TranslationQuality, TranslationItemStatus, TranslationContextValue, TranslationContext, TranslationLookupRequestBase, TranslationLookupSingleRequest, TranslationLookupBatchRequest, TranslationLookupRequest, TranslationLookupItem, TranslationLookupResponse, ResolvedTranslationItem, ResolvedTranslationResponse, TranslationHashOptions, TranslationResolveOptions, TranslationRecord, TranslationListParams, TranslationListResponse, TranslationUpdateRequest, } from "./types/translations";
18
18
  export type { FacetBucket, FacetDefinition, FacetDefinitionWriteInput, FacetGetParams, FacetListParams, FacetListResponse, FacetNamespaceListResponse, FacetQueryRequest, FacetQueryResponse, FacetValue, FacetValueDefinition, FacetValueGetParams, FacetValueListParams, FacetValueListResponse, FacetValueResponse, FacetValueWriteInput, PublicFacetListParams, } from "./types/facets";
19
19
  export type { Collection, CollectionResponse, CollectionCreateRequest, CollectionUpdateRequest, DomainTarget, HubAvailabilityResponse, } from "./types/collection";
20
- export type { Proof, ProofResponse, ProofCreateRequest, ProofUpdateRequest, ProofClaimRequest, } from "./types/proof";
20
+ export type { Proof, ProofResponse, ProofCreateRequest, ProofUpdateRequest, ProofClaimRequest, ProofGrant, GrantScope, GrantAudience, CreateGrantOptions, RedeemGrantOptions, RedeemGrantResult, } from "./types/proof";
21
21
  export type { QrShortCodeLookupResponse, } from "./types/qr";
22
22
  export type { ReverseTagLookupParams, ReverseTagLookupResponse, } from "./types/tags";
23
23
  export type { AdminMobileCapability, ActionableCapability, AdminMobileHostId, AdminMobileEvent, AdminMobileEventCallback, AdminMobileEventSubscriber, ScannerEventSubscriber, // @deprecated — use AdminMobileEventCallback
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/index.ts
2
2
  // Top-level entrypoint of the npm package. Re-export initializeApi + all namespaces.
3
- export { initializeApi, isInitialized, hasAuthCredentials, configureSdkCache, invalidateCache, request, post, put, patch, del, sendCustomProxyMessage, getApiHeaders, isProxyEnabled, setBearerToken, getBearerToken } from "./http";
3
+ export { initializeApi, isInitialized, hasAuthCredentials, configureSdkCache, invalidateCache, request, post, put, patch, del, sendCustomProxyMessage, getApiHeaders, isProxyEnabled, setBearerToken, getBearerToken, setGrantToken, getGrantToken } from "./http";
4
4
  export * from "./api";
5
5
  export * from "./types";
6
6
  // Iframe namespace