@reclaimprotocol/js-sdk 4.7.1 → 4.8.1

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
@@ -314,7 +314,13 @@ The Reclaim SDK offers several advanced options to customize your integration:
314
314
  reclaimProofRequest.setRedirectUrl("https://example.com/redirect");
315
315
  ```
316
316
 
317
- 4. **Custom Callback URL**:
317
+ 4. **Custom Error Redirect URL**:
318
+ Set a custom URL to redirect users on an error which aborts the verification process:
319
+ ```javascript
320
+ reclaimProofRequest.setErrorRedirectUrl("https://example.com/error-redirect");
321
+ ```
322
+
323
+ 5. **Custom Callback URL**:
318
324
  Set a custom callback URL for your app which allows you to receive proofs and status updates on your callback URL:
319
325
  Pass in `jsonProofResponse: true` to receive the proof in JSON format: By default, the proof is returned as a url encoded string.
320
326
 
@@ -322,7 +328,14 @@ The Reclaim SDK offers several advanced options to customize your integration:
322
328
  reclaimProofRequest.setAppCallbackUrl("https://example.com/callback", true);
323
329
  ```
324
330
 
325
- 5. **Modal Customization for Desktop Users**:
331
+ 6. **Custom Error Callback URL**:
332
+ Set a custom error callback URL for your app which allows you to receive errors and status updates on your error callback URL:
333
+
334
+ ```javascript
335
+ reclaimProofRequest.setErrorCallbackUrl("https://example.com/error-callback");
336
+ ```
337
+
338
+ 7. **Modal Customization for Desktop Users**:
326
339
  Customize the appearance and behavior of the QR code modal shown to desktop users:
327
340
 
328
341
  ```javascript
@@ -334,7 +347,7 @@ The Reclaim SDK offers several advanced options to customize your integration:
334
347
  });
335
348
  ```
336
349
 
337
- 6. **Browser Extension Configuration**:
350
+ 8. **Browser Extension Configuration**:
338
351
  Configure browser extension behavior and detection:
339
352
 
340
353
  ```javascript
@@ -353,7 +366,7 @@ The Reclaim SDK offers several advanced options to customize your integration:
353
366
  });
354
367
  ```
355
368
 
356
- 7. **Custom Share Page and App Clip URLs**:
369
+ 9. **Custom Share Page and App Clip URLs**:
357
370
  You can customize the share page and app clip URLs for your app:
358
371
 
359
372
  ```javascript
@@ -364,7 +377,7 @@ const proofRequest = await ReclaimProofRequest.init(APP_ID, APP_SECRET, PROVIDER
364
377
  });
365
378
  ```
366
379
 
367
- 8. **Platform-Specific Flow Control**:
380
+ 10. **Platform-Specific Flow Control**:
368
381
  The `triggerReclaimFlow()` method provides intelligent platform detection, but you can still use traditional methods for custom flows:
369
382
 
370
383
  ```javascript
@@ -377,7 +390,7 @@ const proofRequest = await ReclaimProofRequest.init(APP_ID, APP_SECRET, PROVIDER
377
390
  // Automatically handles platform detection and optimal user experience
378
391
  ```
379
392
 
380
- 9. **Exporting and Importing SDK Configuration**:
393
+ 11. **Exporting and Importing SDK Configuration**:
381
394
  You can export the entire Reclaim SDK configuration as a JSON string and use it to initialize the SDK with the same configuration on a different service or backend:
382
395
 
383
396
  ```javascript
@@ -394,7 +407,7 @@ const proofRequest = await ReclaimProofRequest.init(APP_ID, APP_SECRET, PROVIDER
394
407
 
395
408
  This allows you to generate request URLs and other details from your backend or a different service while maintaining the same configuration.
396
409
 
397
- 10. **Utility Methods**:
410
+ 12. **Utility Methods**:
398
411
  Additional utility methods for managing your proof requests:
399
412
 
400
413
  ```javascript
@@ -403,7 +416,7 @@ const sessionId = reclaimProofRequest.getSessionId();
403
416
  console.log("Current session ID:", sessionId);
404
417
  ```
405
418
 
406
- 11. **Control auto-submission of proofs**:
419
+ 13. **Control auto-submission of proofs**:
407
420
 
408
421
  Whether the verification client should automatically submit necessary proofs once they are generated. If set to false, the user must manually click a button to submit.
409
422
  Defaults to true.
@@ -415,7 +428,7 @@ const proofRequest = await ReclaimProofRequest.init(APP_ID, APP_SECRET, PROVIDER
415
428
  });
416
429
  ```
417
430
 
418
- 12. **Add additional metadata for verification client**:
431
+ 14. **Add additional metadata for verification client**:
419
432
 
420
433
  Additional metadata to pass to the verification client. This can be used to customize the client experience, such as customizing themes or UI by passing context-specific information.
421
434
  The keys and values must be strings. For most clients, this is not required and goes unused.
@@ -431,11 +444,16 @@ const proofRequest = await ReclaimProofRequest.init(APP_ID, APP_SECRET, PROVIDER
431
444
 
432
445
  ## Handling Proofs on Your Backend
433
446
 
434
- For production applications, it's recommended to handle proofs on your backend:
447
+ For production applications, it's recommended to handle proofs, and errors on your backend:
435
448
 
436
449
  1. Set a callback URL:
437
450
  ```javascript
438
- reclaimProofRequest.setCallbackUrl("https://your-backend.com/receive-proofs");
451
+ reclaimProofRequest.setAppCallbackUrl("https://your-backend.com/receive-proofs");
452
+ ```
453
+
454
+ 2. Set a error callback URL:
455
+ ```javascript
456
+ reclaimProofRequest.setErrorCallbackUrl("https://your-backend.com/receive-errors");
439
457
  ```
440
458
 
441
459
  These options allow you to securely process proofs and status updates on your server.
@@ -517,6 +535,7 @@ try {
517
535
  - `ProviderFailedError`: Provider failed to generate proof
518
536
  - `SessionNotStartedError`: Session could not be started
519
537
  - `ProofSubmissionFailedError`: Proof submission to callback failed
538
+ - `ErrorDuringVerificationError`: An abort error during verification which was caused by the user aborting the verification process or provider's JS script raising a validation error
520
539
 
521
540
  ## Next Steps
522
541
 
package/dist/index.d.ts CHANGED
@@ -145,6 +145,8 @@ type ProofPropertiesJSON = {
145
145
  timeStamp?: string;
146
146
  timestamp?: string;
147
147
  appCallbackUrl?: string;
148
+ errorCallbackUrl?: TemplateData['errorCallbackUrl'];
149
+ errorRedirectUrl?: TemplateData['errorRedirectUrl'];
148
150
  claimCreationType?: ClaimCreationType;
149
151
  options?: ProofRequestOptions;
150
152
  sdkVersion: string;
@@ -152,6 +154,29 @@ type ProofPropertiesJSON = {
152
154
  resolvedProviderVersion: string;
153
155
  modalOptions?: SerializableModalOptions;
154
156
  };
157
+ type TemplateData = {
158
+ sessionId: string;
159
+ providerId: string;
160
+ applicationId: string;
161
+ signature: string;
162
+ timestamp: string;
163
+ callbackUrl: string;
164
+ context: string;
165
+ parameters: {
166
+ [key: string]: string;
167
+ };
168
+ redirectUrl: string;
169
+ errorCallbackUrl?: string | null;
170
+ errorRedirectUrl?: string | null;
171
+ acceptAiProviders: boolean;
172
+ sdkVersion: string;
173
+ jsonProofResponse?: boolean;
174
+ providerVersion?: string;
175
+ resolvedProviderVersion: string;
176
+ log?: boolean;
177
+ canAutoSubmit?: boolean;
178
+ metadata?: Record<string, string>;
179
+ };
155
180
 
156
181
  /**
157
182
  * Verifies one or more Reclaim proofs by validating signatures and witness information
@@ -198,6 +223,8 @@ declare class ReclaimProofRequest {
198
223
  private resolvedProviderVersion?;
199
224
  private parameters;
200
225
  private redirectUrl?;
226
+ private errorCallbackUrl?;
227
+ private errorRedirectUrl?;
201
228
  private intervals;
202
229
  private timeStamp;
203
230
  private sdkVersion;
@@ -284,6 +311,35 @@ declare class ReclaimProofRequest {
284
311
  * ```
285
312
  */
286
313
  setRedirectUrl(url: string): void;
314
+ /**
315
+ * Sets a custom callback URL where errors that abort the verification process will be submitted via HTTP POST
316
+ *
317
+ * Errors will be HTTP POSTed with `header 'Content-Type': 'application/json'`.
318
+ * When a custom error callback URL is set, Reclaim will no longer receive errors upon submission,
319
+ * and listeners on the startSession method will not be triggered. Your application must
320
+ * coordinate with your backend to receive errors.
321
+ *
322
+ * @param url - The URL where errors should be submitted via HTTP POST
323
+ * @throws {InvalidParamError} When URL is invalid
324
+ *
325
+ * @example
326
+ * ```typescript
327
+ * proofRequest.setErrorCallbackUrl('https://your-backend.com/error-callback');
328
+ * ```
329
+ */
330
+ setErrorCallbackUrl(url: string): void;
331
+ /**
332
+ * Sets an error redirect URL where users will be redirected after an error which aborts the verification process
333
+ *
334
+ * @param url - The URL where users should be redirected after an error which aborts the verification process
335
+ * @throws {InvalidParamError} When URL is invalid
336
+ *
337
+ * @example
338
+ * ```typescript
339
+ * proofRequest.setErrorRedirectUrl('https://your-app.com/error');
340
+ * ```
341
+ */
342
+ setErrorRedirectUrl(url: string): void;
287
343
  /**
288
344
  * Sets the claim creation type for the proof request
289
345
  *
@@ -387,6 +443,22 @@ declare class ReclaimProofRequest {
387
443
  * ```
388
444
  */
389
445
  getAppCallbackUrl(): string;
446
+ /**
447
+ * Returns the currently configured error callback URL
448
+ *
449
+ * If no custom error callback URL was set via setErrorCallbackUrl(), this returns the default
450
+ * Reclaim service error callback URL with the current session ID.
451
+ *
452
+ * @returns The error callback URL where proofs will be submitted
453
+ * @throws {GetAppCallbackUrlError} When unable to retrieve the error callback URL
454
+ *
455
+ * @example
456
+ * ```typescript
457
+ * const callbackUrl = proofRequest.getErrorCallbackUrl();
458
+ * console.log('Errors will be sent to:', callbackUrl);
459
+ * ```
460
+ */
461
+ getErrorCallbackUrl(): string;
390
462
  /**
391
463
  * Returns the status URL for monitoring the current session
392
464
  *
package/dist/index.js CHANGED
@@ -72,7 +72,7 @@ var require_package = __commonJS({
72
72
  "package.json"(exports2, module2) {
73
73
  module2.exports = {
74
74
  name: "@reclaimprotocol/js-sdk",
75
- version: "4.7.1",
75
+ version: "4.8.1",
76
76
  description: "Designed to request proofs from the Reclaim protocol and manage the flow of claims and witness interactions.",
77
77
  main: "dist/index.js",
78
78
  types: "dist/index.d.ts",
@@ -322,6 +322,7 @@ var GetAppCallbackUrlError = createErrorClass("GetAppCallbackUrlError");
322
322
  var StatusUrlError = createErrorClass("StatusUrlError");
323
323
  var InavlidParametersError = createErrorClass("InavlidParametersError");
324
324
  var ProofSubmissionFailedError = createErrorClass("ProofSubmissionFailedError");
325
+ var ErrorDuringVerificationError = createErrorClass("ErrorDuringVerificationError");
325
326
 
326
327
  // src/utils/logger.ts
327
328
  var SimpleLogger = class {
@@ -405,6 +406,10 @@ var constants = {
405
406
  get DEFAULT_RECLAIM_CALLBACK_URL() {
406
407
  return `${BACKEND_BASE_URL}/api/sdk/callback?callbackId=`;
407
408
  },
409
+ // Default error callback URL for Reclaim protocol
410
+ get DEFAULT_RECLAIM_ERROR_CALLBACK_URL() {
411
+ return `${BACKEND_BASE_URL}/api/sdk/error-callback?callbackId=`;
412
+ },
408
413
  // Default status URL for Reclaim sessions
409
414
  get DEFAULT_RECLAIM_STATUS_URL() {
410
415
  return `${BACKEND_BASE_URL}/api/sdk/session/`;
@@ -1861,6 +1866,8 @@ var emptyTemplateData = {
1861
1866
  context: "",
1862
1867
  parameters: {},
1863
1868
  redirectUrl: "",
1869
+ errorCallbackUrl: "",
1870
+ errorRedirectUrl: "",
1864
1871
  acceptAiProviders: false,
1865
1872
  sdkVersion: "",
1866
1873
  providerVersion: "",
@@ -1899,6 +1906,8 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1899
1906
  resolvedProviderVersion: (_c = this.resolvedProviderVersion) != null ? _c : "",
1900
1907
  parameters: this.parameters,
1901
1908
  redirectUrl: (_d = this.redirectUrl) != null ? _d : "",
1909
+ errorCallbackUrl: this.getErrorCallbackUrl(),
1910
+ errorRedirectUrl: this.errorRedirectUrl,
1902
1911
  acceptAiProviders: (_f = (_e = this.options) == null ? void 0 : _e.acceptAiProviders) != null ? _f : false,
1903
1912
  sdkVersion: this.sdkVersion,
1904
1913
  jsonProofResponse: this.jsonProofResponse,
@@ -2064,6 +2073,8 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2064
2073
  parameters,
2065
2074
  signature,
2066
2075
  redirectUrl,
2076
+ errorCallbackUrl,
2077
+ errorRedirectUrl,
2067
2078
  timeStamp,
2068
2079
  timestamp,
2069
2080
  appCallbackUrl,
@@ -2092,6 +2103,12 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2092
2103
  if (appCallbackUrl) {
2093
2104
  validateURL(appCallbackUrl, "fromJsonString");
2094
2105
  }
2106
+ if (errorRedirectUrl) {
2107
+ validateURL(errorRedirectUrl, "fromJsonString");
2108
+ }
2109
+ if (errorCallbackUrl) {
2110
+ validateURL(errorCallbackUrl, "fromJsonString");
2111
+ }
2095
2112
  if (context) {
2096
2113
  validateContext(context);
2097
2114
  }
@@ -2130,6 +2147,8 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2130
2147
  proofRequestInstance.resolvedProviderVersion = resolvedProviderVersion;
2131
2148
  proofRequestInstance.modalOptions = modalOptions;
2132
2149
  proofRequestInstance.jsonProofResponse = jsonProofResponse != null ? jsonProofResponse : false;
2150
+ proofRequestInstance.errorCallbackUrl = errorCallbackUrl;
2151
+ proofRequestInstance.errorRedirectUrl = errorRedirectUrl;
2133
2152
  return proofRequestInstance;
2134
2153
  } catch (error) {
2135
2154
  logger7.info("Failed to parse JSON string in fromJsonString:", error);
@@ -2178,6 +2197,41 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2178
2197
  validateURL(url, "setRedirectUrl");
2179
2198
  this.redirectUrl = url;
2180
2199
  }
2200
+ /**
2201
+ * Sets a custom callback URL where errors that abort the verification process will be submitted via HTTP POST
2202
+ *
2203
+ * Errors will be HTTP POSTed with `header 'Content-Type': 'application/json'`.
2204
+ * When a custom error callback URL is set, Reclaim will no longer receive errors upon submission,
2205
+ * and listeners on the startSession method will not be triggered. Your application must
2206
+ * coordinate with your backend to receive errors.
2207
+ *
2208
+ * @param url - The URL where errors should be submitted via HTTP POST
2209
+ * @throws {InvalidParamError} When URL is invalid
2210
+ *
2211
+ * @example
2212
+ * ```typescript
2213
+ * proofRequest.setErrorCallbackUrl('https://your-backend.com/error-callback');
2214
+ * ```
2215
+ */
2216
+ setErrorCallbackUrl(url) {
2217
+ validateURL(url, "setErrorCallbackUrl");
2218
+ this.errorCallbackUrl = url;
2219
+ }
2220
+ /**
2221
+ * Sets an error redirect URL where users will be redirected after an error which aborts the verification process
2222
+ *
2223
+ * @param url - The URL where users should be redirected after an error which aborts the verification process
2224
+ * @throws {InvalidParamError} When URL is invalid
2225
+ *
2226
+ * @example
2227
+ * ```typescript
2228
+ * proofRequest.setErrorRedirectUrl('https://your-app.com/error');
2229
+ * ```
2230
+ */
2231
+ setErrorRedirectUrl(url) {
2232
+ validateURL(url, "setErrorRedirectUrl");
2233
+ this.errorRedirectUrl = url;
2234
+ }
2181
2235
  /**
2182
2236
  * Sets the claim creation type for the proof request
2183
2237
  *
@@ -2329,6 +2383,30 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2329
2383
  throw new GetAppCallbackUrlError("Error getting app callback url", error);
2330
2384
  }
2331
2385
  }
2386
+ /**
2387
+ * Returns the currently configured error callback URL
2388
+ *
2389
+ * If no custom error callback URL was set via setErrorCallbackUrl(), this returns the default
2390
+ * Reclaim service error callback URL with the current session ID.
2391
+ *
2392
+ * @returns The error callback URL where proofs will be submitted
2393
+ * @throws {GetAppCallbackUrlError} When unable to retrieve the error callback URL
2394
+ *
2395
+ * @example
2396
+ * ```typescript
2397
+ * const callbackUrl = proofRequest.getErrorCallbackUrl();
2398
+ * console.log('Errors will be sent to:', callbackUrl);
2399
+ * ```
2400
+ */
2401
+ getErrorCallbackUrl() {
2402
+ try {
2403
+ validateFunctionParams([{ input: this.sessionId, paramName: "sessionId", isString: true }], "getErrorCallbackUrl");
2404
+ return this.errorCallbackUrl || `${constants.DEFAULT_RECLAIM_ERROR_CALLBACK_URL}${this.sessionId}`;
2405
+ } catch (error) {
2406
+ logger7.info("Error getting error callback url", error);
2407
+ throw new GetAppCallbackUrlError("Error getting error callback url", error);
2408
+ }
2409
+ }
2332
2410
  /**
2333
2411
  * Returns the status URL for monitoring the current session
2334
2412
  *
@@ -2441,6 +2519,8 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2441
2519
  parameters: this.parameters,
2442
2520
  signature: this.signature,
2443
2521
  redirectUrl: this.redirectUrl,
2522
+ errorCallbackUrl: this.errorCallbackUrl,
2523
+ errorRedirectUrl: this.errorRedirectUrl,
2444
2524
  timestamp: this.timeStamp,
2445
2525
  // New field with correct spelling
2446
2526
  timeStamp: this.timeStamp,
@@ -2784,6 +2864,9 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2784
2864
  }
2785
2865
  return;
2786
2866
  }
2867
+ if (statusUrlResponse.session.statusV2 === "ERROR_SUBMISSION_FAILED" /* ERROR_SUBMISSION_FAILED */ || statusUrlResponse.session.statusV2 === "ERROR_SUBMITTED" /* ERROR_SUBMITTED */) {
2868
+ throw new ErrorDuringVerificationError();
2869
+ }
2787
2870
  const isDefaultCallbackUrl = this.getAppCallbackUrl() === `${constants.DEFAULT_RECLAIM_CALLBACK_URL}${this.sessionId}`;
2788
2871
  if (isDefaultCallbackUrl) {
2789
2872
  if (statusUrlResponse.session.proofs && statusUrlResponse.session.proofs.length > 0) {