react-native-docusign 1.0.5 → 2.0.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +181 -70
  3. package/android/build.gradle +5 -5
  4. package/android/src/main/java/expo/modules/docusign/DocuSignError.kt +30 -10
  5. package/android/src/main/java/expo/modules/docusign/DocuSignFailure.kt +145 -0
  6. package/android/src/main/java/expo/modules/docusign/DocuSignManager.kt +407 -58
  7. package/android/src/main/java/expo/modules/docusign/DocuSignModule.kt +61 -42
  8. package/build/DocuSign.types.d.ts +39 -0
  9. package/build/DocuSign.types.d.ts.map +1 -1
  10. package/build/DocuSignError.d.ts +86 -0
  11. package/build/DocuSignError.d.ts.map +1 -0
  12. package/build/DocuSignError.js +210 -0
  13. package/build/DocuSignError.js.map +1 -0
  14. package/build/DocuSignModule.d.ts +24 -5
  15. package/build/DocuSignModule.d.ts.map +1 -1
  16. package/build/DocuSignModule.js.map +1 -1
  17. package/build/api.d.ts +24 -6
  18. package/build/api.d.ts.map +1 -1
  19. package/build/api.js +84 -17
  20. package/build/api.js.map +1 -1
  21. package/build/index.d.ts +2 -0
  22. package/build/index.d.ts.map +1 -1
  23. package/build/index.js +1 -0
  24. package/build/index.js.map +1 -1
  25. package/build/useDocuSignSigning.d.ts +2 -1
  26. package/build/useDocuSignSigning.d.ts.map +1 -1
  27. package/build/useDocuSignSigning.js +20 -6
  28. package/build/useDocuSignSigning.js.map +1 -1
  29. package/ios/DocuSignError.swift +45 -10
  30. package/ios/DocuSignFailure.swift +104 -0
  31. package/ios/DocuSignManager.swift +162 -106
  32. package/ios/DocuSignModule.swift +37 -37
  33. package/ios/ReactNativeDocuSign.podspec +1 -1
  34. package/package.json +12 -3
  35. package/plugin/build/index.js +21 -41
  36. package/plugin/build/index.js.map +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,49 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.0
4
+
5
+ Upgrading from 1.x: every failure now rejects with a `DocuSignError`. Check any code that branches on `error.code`, matches message text, handles `status: 'error'` from `presentCaptiveSigning*`, or reads `errorCode` in an `addSigningErrorListener` callback. Codes are the lowercase codes the README documents, on both platforms, where iOS previously emitted `ERR_`-prefixed variants and Android rejected most failures as `signing_failed`. The new Android `launchStrategy` is opt-in. Both native SDKs also move forward, see [Native SDKs](#native-sdks) for what that changes in your app.
6
+
7
+ ### Native SDKs
8
+
9
+ - **Android**: DocuSign Android SDK 2.1.4 to 2.1.7, the version DocuSign's install guide documents. Its own dependencies moved to Glide 5.0.4, OkHttp 4.12.0, RxJava 3, Room 2.7.2 and kotlin-stdlib 2.2.10, and it no longer pulls in RxJava 2, slf4j or commons-codec. Gradle resolves these across the whole app, so an app on an older OkHttp or Room gets the newer one. Compiling the module against it needs Kotlin 2.1 or newer, which Expo SDK 55 already ships. The config plugin still strips the Glide class from `sdk-pdf`, now pinned to the 2.1.7 hash, so run `npx expo prebuild` after upgrading to fetch the new AAR.
10
+ - **iOS**: DocuSign iOS SDK 4.1.1 to 4.3.0. DocuSign 4.3.0 fixes a double JavaScript invocation that caused signing backend errors. The captive signing screen gains Print, Download and Download Separate PDFs menu options (added in DocuSign 4.2.0), and the SDK has no setup key to hide them. DocuSign also inserted a new error code in the middle of its `DSMErrorCode` enum, so for DocuSign's own errors from 1022 up, `native.code` is one higher than on 4.1.1. A project with a committed `Podfile.lock` needs `pod update DocuSign`, because `pod install` alone keeps the locked 4.1.1 and fails to resolve.
11
+
12
+ ### Breaking changes
13
+
14
+ - Every failure from `initialize`, `loginWithAccessToken`, `presentCaptiveSigning` and `presentCaptiveSigningWithUrl` rejects with a `DocuSignError` on both platforms. It carries `code` (what failed), `reason` (why, set only from verifiable facts), `native` and `http` (the raw SDK error and any DocuSign response), and `toAttributes()`. Branch on `code` and `reason`, never on message text, which was rewritten to say what failed and what to check. See [docs/ERROR_HANDLING.md](docs/ERROR_HANDLING.md).
15
+ - `presentCaptiveSigning` and `presentCaptiveSigningWithUrl` never resolve with `status: 'error'`. iOS used it for SDK errors reported after the signing UI was on screen, while Android rejected the same failures. Both platforms now reject, so a resolve always means completed or cancelled. `'error'` stays in `SigningStatus` so existing `switch` statements compile.
16
+ - Rejection codes are the documented lowercase codes on both platforms. iOS emitted `ERR_`-prefixed codes that Expo derived from exception class names, and Android rejected most failures as `signing_failed`. Two caller mistakes that hid inside `signing_failed` now have their own codes: `signing_in_progress` and `invalid_signing_url`. A missing presenter on iOS, or a missing foreground Activity on Android, rejects with `presentation_failed`, and an iOS initialization failure rejects with `initialize_failed`.
17
+ - `addSigningErrorListener` receives a `DocuSignError` instead of `{ errorCode, errorMessage }`, and now receives every failure from those four functions exactly once, caller mistakes included. It no longer wraps the native `onSigningError` event, which stays available on `DocuSignModule`.
18
+ - `useDocuSignSigning` types `error` as `DocuSignError | null`.
19
+ - **Android**: one native `onSigningError` event per failure instead of two.
20
+
21
+ ### New features
22
+
23
+ - `DocuSignError.reason` classifies a failure as `usage`, `network`, `auth`, `configuration`, `recipient` or `unknown`, so an app can show a message that fits and skip retries that cannot succeed. A login failure is checked against `/oauth/userinfo` with the same token, which separates an expired token (`auth`) from a valid token DocuSign still refuses (`configuration`).
24
+ - `DocuSignError.toAttributes()` returns flat, primitive attributes ready for Amplitude, New Relic, Sentry or any other tool.
25
+ - Messages and details are redacted before they reach app code: JWTs, `Bearer` credentials, URL query strings and token-like URL path segments are removed. The redaction is pattern-based, so `toAttributes()`, which carries no message text, is the safest thing to forward to third-party tools.
26
+ - **Android**: `initialize` failures carry the SDK exception's details instead of a message alone, and the underlying error is the root of the exception's cause chain, where the transport failure that explains a timeout actually sits.
27
+ - In development, a caller mistake also prints one console warning naming the fix, so a catch that shows a generic toast cannot hide it.
28
+ - **Android**: the SDK's own error code, the HTTP status of an SDK REST failure, and DocuSign's error body from the recipient-view request are kept. The module previously forwarded only the exception message, and the `signingUrl` strategy discarded the error body entirely when it fell back to `fetch`.
29
+ - New [error handling guide](docs/ERROR_HANDLING.md) covering translated copy, retries, reporting to Amplitude, New Relic and Sentry, and reading the results in production. Its examples live in `examples/error-handling` and are type-checked in CI.
30
+ - **Android**: Add `presentCaptiveSigningWithUrl` support. The URL flow now has iOS/Android parity and does not require `loginWithAccessToken`.
31
+ - **Android**: Add an opt-in `launchStrategy` on `presentCaptiveSigning`. `signingUrl` mints a recipient view and launches the SDK's URL overload, skipping the envelope download that runs on a size-derived read timeout floored at 15s and can leave the ceremony unopened on large envelopes. Falls back to `fetch` if the mint fails. Defaults to `fetch`, so upgrading changes nothing unless you opt in.
32
+
33
+ ### Fixes
34
+
35
+ - Bump `adm-zip`, the Config Plugin's only runtime dependency, to 0.6.1. This clears GHSA-xcpc-8h2w-3j85 (high) and GHSA-vwc7-r8mq-g2x9 (moderate) from consumers' `npm audit`. Neither was reachable: the plugin never extracts to disk, and it only parses the AAR it downloaded after checking its SHA-256, or its own cached copy under `node_modules`.
36
+ - **Android**: the Config Plugin matches the maven repository URL exactly when deciding whether `android/build.gradle` already declares it, and ignores declarations inside `//` and `/* */` comments. The substring check it replaces skipped adding the repository when the URL appeared only in a comment or as the prefix of a longer URL. It was also the CodeQL `js/incomplete-url-substring-sanitization` alert.
37
+ - **Android**: the Config Plugin no longer adds a `flatDir` block to `android/build.gradle`, and no longer warns Kotlin Script projects to add one by hand. The module has referenced the stripped `sdk-pdf` AAR by file path since 1.0.4, so the block did nothing. On current Expo templates it was never added anyway, because its pattern could not match the nested `maven { ... }` entry inside `allprojects.repositories`.
38
+ - **iOS**: the module compiles without warnings under the Swift 6 compiler. Its exception classes restate the `@unchecked Sendable` conformance they inherit from Expo's `Exception`, and a `??` fallback on `DSMManager.defaultConfigurations()`, which never returns nil, is gone.
39
+ - **iOS**: the view controller to present from is looked up on the main thread. The lookup read `UIApplication.shared` on the background queue the JS call arrived on.
40
+ - **iOS**: a missing view controller settles the promise once. It previously completed the pending signing slot with a failure and also threw, rejecting the same call twice.
41
+ - **iOS**: `endSigningSession` no longer calls `DSMManager` off the main thread. Expo dispatches a synchronous `AsyncFunction` body on a serial background queue, so `clearAllWebCookies()` and `logout()` were reached off-main on every call, including the one `useDocuSignSigning`'s `reset()` makes between flows. The guard now lives in `clearWebCookiesAsync`, the only method touching `DSMManager` and `WKWebsiteDataStore` directly, so it covers every caller. Thanks to @virajpsimformsolutions for finding and fixing this.
42
+ - **iOS**: `reset()` no longer re-enters itself to reach the main thread. The hop sat below the block that cancels an in-flight signing promise, so the re-entrant pass ran that block twice and could cancel a session that claimed the slot in between.
43
+ - **iOS**: reject a blank or non-`https` `signingUrl` before presenting. `DSMEnvelopesManager.presentCaptiveSigning` validates nothing and presents unconditionally, so a malformed URL rendered an empty signing controller whose completion never fired and left the promise unsettled. `signingUrl` defaults to `""` when JS omits it, so this was reachable without a malformed URL at all. Brings iOS to parity with the Android guard below.
44
+ - **Android**: reject a blank or non-`https` `signingUrl` before launching. The SDK's URL overload validates nothing and calls `startActivity` unconditionally, so a malformed URL opened an empty signing activity and left the promise unsettled.
45
+ - **Android**: `presentCaptiveSigning` now clears `currentEnvelopeId` when the launch itself throws, matching the URL path.
46
+
3
47
  ## 1.0.5
4
48
 
5
49
  ### New features
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/IronTony/react-native-docusign/main/docs/img/banner-dark.svg" alt="react-native-docusign" />
3
+ </p>
4
+
1
5
  # react-native-docusign
2
6
 
3
7
  [![npm version](https://img.shields.io/npm/v/react-native-docusign.svg?style=flat-square)](https://www.npmjs.com/package/react-native-docusign)
@@ -18,9 +22,7 @@ Built on the Expo Modules API. Works with Expo SDK 55+ (managed or bare with `ex
18
22
  | Flow | iOS | Android |
19
23
  |-------------------------------------------------------------------------|:---:|:-------:|
20
24
  | Session flow: `initialize` → `loginWithAccessToken` → `presentCaptiveSigning` | ✅ | ✅ |
21
- | URL flow: `presentCaptiveSigningWithUrl` | ✅ | ❌ |
22
-
23
- The DocuSign Android SDK (2.1.4) does not expose a public URL-based signing entry point; calling `presentCaptiveSigningWithUrl` on Android rejects with `not_implemented`. **Default to the session flow for cross-platform apps.**
25
+ | URL flow: `initialize` → `presentCaptiveSigningWithUrl` | ✅ | ✅ |
24
26
 
25
27
  ## One backend response, both platforms
26
28
 
@@ -92,12 +94,12 @@ The React Native layer never renders any of the signing UI. It only triggers the
92
94
 
93
95
  | Platform | Minimum OS | SDK version | Language |
94
96
  | -------- | -------------------- | -------------------------- | ----------- |
95
- | iOS | 15.1 | DocuSign iOS SDK 4.1.1 | Swift 5.9 |
96
- | Android | API 24 (Android 7.0) | DocuSign Android SDK 2.1.4 | Kotlin 1.8+ |
97
+ | iOS | 15.1 | DocuSign iOS SDK 4.3.0 | Swift 5.9 |
98
+ | Android | API 24 (Android 7.0) | DocuSign Android SDK 2.1.7 | Kotlin 2.1+ |
97
99
 
98
100
  **Runtime requirements:**
99
101
 
100
- - Expo SDK 55 or newer, OR bare React Native 0.74+
102
+ - Expo SDK 55 or newer, OR bare React Native 0.74+ (Android needs Kotlin 2.1 or newer)
101
103
  - React Native New Architecture (Fabric + Hermes): supported, no additional configuration
102
104
  - Expo Go: NOT supported (custom native modules require a development build)
103
105
 
@@ -105,12 +107,12 @@ The React Native layer never renders any of the signing UI. It only triggers the
105
107
 
106
108
  The DocuSign native SDKs are **NOT bundled** inside this npm package. They are declared as external dependencies and resolved at consumer build time:
107
109
 
108
- - **iOS**: `pod 'DocuSign-iOS-SDK', '~> 4.1.1'` from the public CocoaPods trunk
109
- - **Android**: `com.docusign:androidsdk:2.1.4` from DocuSign's Maven repository (the config plugin adds the repo automatically)
110
+ - **iOS**: the `DocuSign` pod (`~> 4.3.0`) from the public CocoaPods trunk, declared by this package's podspec
111
+ - **Android**: `com.docusign:androidsdk:2.1.7` from DocuSign's Maven repository (the config plugin adds the repo automatically)
110
112
 
111
113
  ### Android Glide collision workaround
112
114
 
113
- DocuSign's `com.docusign:sdk-pdf:2.1.4` AAR ships a pre-generated `com.bumptech.glide.GeneratedAppGlideModuleImpl.class` that collides at dex time with any other Glide-based library in the host app (notably `expo-image`, `react-native-fast-image`, and similar). To avoid this without redistributing DocuSign's binary, the Expo Config Plugin downloads `sdk-pdf-2.1.4.aar` directly from DocuSign's public Maven during `expo prebuild`, verifies its SHA-256 against a pinned hash, removes the offending class from the AAR's `classes.jar` in-memory, and writes the stripped artifact to `node_modules/react-native-docusign/android/libs/`. The existing flatDir injection picks it up at consumer build time. The download is cached after the first run; corrupted or partial caches are detected and regenerated. SHA mismatch or fetch failure aborts `expo prebuild` with an actionable error rather than silently letting the Android build fail later at the dex step.
115
+ DocuSign's `com.docusign:sdk-pdf:2.1.7` AAR ships a pre-generated `com.bumptech.glide.GeneratedAppGlideModuleImpl.class` that collides at dex time with any other Glide-based library in the host app (notably `expo-image`, `react-native-fast-image`, and similar). To avoid this without redistributing DocuSign's binary, the Expo Config Plugin downloads `sdk-pdf-2.1.7.aar` directly from DocuSign's public Maven during `expo prebuild`, verifies its SHA-256 against a pinned hash, removes the offending class from the AAR's `classes.jar` in-memory, and writes the stripped artifact to `node_modules/react-native-docusign/android/libs/`. The module's `android/build.gradle` references it by file path at consumer build time. The download is cached after the first run; corrupted or partial caches are detected and regenerated. SHA mismatch or fetch failure aborts `expo prebuild` with an actionable error rather than silently letting the Android build fail later at the dex step.
114
116
 
115
117
  ### What ships inside this package
116
118
 
@@ -180,7 +182,7 @@ npx expo run:android
180
182
 
181
183
  If you are not using Expo prebuild, you must manually:
182
184
 
183
- - **iOS**: add `pod 'DocuSign-iOS-SDK', '~> 4.1.1'` to your Podfile and run `pod install`
185
+ - **iOS**: run `pod install`. This package's podspec already depends on the `DocuSign` pod, so your Podfile needs no entry for it
184
186
  - **Android**: add the Maven repo and the DocuSign dependency to your `android/build.gradle` + `android/app/build.gradle`
185
187
  - **iOS**: add the `NSCameraUsageDescription` and `NSPhotoLibraryUsageDescription` keys to your `Info.plist`
186
188
  - **Android**: add the required permissions to your `AndroidManifest.xml`
@@ -207,7 +209,7 @@ type DocuSignPluginProps = {
207
209
 
208
210
  /**
209
211
  * URL of the Android Maven repository that serves the DocuSign Android SDK.
210
- * Defaults to 'https://maven.docusign.com/'.
212
+ * Defaults to 'https://docucdn-a.akamaihd.net/prod/docusignandroidsdk'.
211
213
  * Override only if DocuSign moves their repo.
212
214
  */
213
215
  androidMavenRepo?: string;
@@ -250,27 +252,30 @@ async function signAgreement() {
250
252
  });
251
253
 
252
254
  // Step 4: present the native signing UI
253
- const result = await DocuSign.presentCaptiveSigning({
254
- envelopeId: session.envelopeId,
255
- recipientUserName: session.userName,
256
- recipientEmail: session.email,
257
- recipientClientUserId: session.recipientClientUserId,
258
- });
255
+ try {
256
+ const result = await DocuSign.presentCaptiveSigning({
257
+ envelopeId: session.envelopeId,
258
+ recipientUserName: session.userName,
259
+ recipientEmail: session.email,
260
+ recipientClientUserId: session.recipientClientUserId,
261
+ });
259
262
 
260
- switch (result.status) {
261
- case 'completed':
263
+ if (result.status === 'completed') {
262
264
  console.log('Signed:', result.envelopeId);
263
- break;
264
- case 'cancelled':
265
+ } else {
265
266
  console.log('User cancelled signing');
266
- break;
267
- case 'error':
268
- console.error('Signing error:', result.errorMessage);
269
- break;
267
+ }
268
+ } catch (error) {
269
+ if (error instanceof DocuSign.DocuSignError) {
270
+ // error.reason picks the message to show, error.toAttributes() goes to your logs.
271
+ console.error(error.code, error.reason, error.message);
272
+ }
270
273
  }
271
274
  }
272
275
  ```
273
276
 
277
+ Every failure rejects with a `DocuSignError`. See [Error handling](#error-handling).
278
+
274
279
  ## API reference
275
280
 
276
281
  ### `initialize(config: DocuSignConfig): Promise<void>`
@@ -289,7 +294,7 @@ type DocuSignConfig = {
289
294
  - `integratorKey`: your DocuSign Integrator Key (Client ID). Can be fetched from your backend at runtime to avoid shipping it in the app bundle.
290
295
  - `environment`: `'demo'` targets `demo.docusign.net` (DocuSign developer sandbox). `'production'` targets `docusign.net`.
291
296
 
292
- **Throws:** rejects if the SDK cannot be initialized.
297
+ **Throws:** a `DocuSignError` with `initialize_failed` if the SDK cannot be configured.
293
298
 
294
299
  ### `loginWithAccessToken(params: DocuSignAuthParams): Promise<void>`
295
300
 
@@ -315,7 +320,10 @@ type DocuSignAuthParams = {
315
320
  - `email`: email address for the signer
316
321
  - `host`: DocuSign API host URL (e.g. `'https://demo.docusign.net/restapi'`)
317
322
 
318
- **Throws:** rejects with `login_failed` if the token is invalid, expired, or rejected by DocuSign.
323
+ **Throws:**
324
+
325
+ - `not_initialized` if `initialize` has not been called
326
+ - `login_failed` if DocuSign rejects the login. `reason` separates an expired or wrongly scoped token (`auth`) from a valid token DocuSign still refuses (`configuration`) and a lost connection (`network`). The package tells them apart by checking the same token against `/oauth/userinfo`.
319
327
 
320
328
  **Notes:** access tokens from DocuSign are typically valid for 1 hour. Do not cache them client-side. Fetch a fresh token for each signing session.
321
329
 
@@ -329,13 +337,14 @@ type CaptiveSigningParams = {
329
337
  recipientUserName: string;
330
338
  recipientEmail: string;
331
339
  recipientClientUserId: string;
340
+ launchStrategy?: 'fetch' | 'signingUrl'; // Android only, default 'fetch'
332
341
  };
333
342
 
334
343
  type SigningResult = {
335
- status: 'completed' | 'cancelled' | 'error';
344
+ status: 'completed' | 'cancelled' | 'error'; // 'error' is never returned since 2.0.0
336
345
  envelopeId: string;
337
346
  errorCode?: string;
338
- errorMessage?: string;
347
+ errorMessage?: string; // for 'cancelled', the SDK's exit reason when it gives one
339
348
  };
340
349
  ```
341
350
 
@@ -344,14 +353,43 @@ type SigningResult = {
344
353
  - `envelopeId`: the DocuSign envelope ID created by your backend
345
354
  - `recipientUserName`, `recipientEmail`: must match the recipient registered on the envelope
346
355
  - `recipientClientUserId`: the `clientUserId` of the embedded recipient, used by DocuSign to identify captive signers
356
+ - `launchStrategy`: how the Android SDK opens the ceremony, see [Android launch strategies](#android-launch-strategies). Ignored on iOS.
347
357
 
348
- **Throws:** rejects with `signing_failed` if the SDK fails to present the signing UI (e.g. not initialized, not logged in, invalid envelope).
358
+ **Throws:** a `DocuSignError`.
359
+
360
+ - `not_initialized` if `initialize` has not been called
361
+ - `not_logged_in` if `loginWithAccessToken` has not been called
362
+ - `signing_in_progress` if a ceremony is already open
363
+ - `presentation_failed` if there is no screen to present from
364
+ - `signing_failed` if the ceremony cannot open or ends with an error. `reason` tells a lost connection (`network`), an expired token (`auth`) or a recipient that does not match the envelope (`recipient`) apart from an SDK error the package cannot classify (`unknown`).
349
365
 
350
366
  **Returns:** resolves with a `SigningResult` once the user completes or cancels. `status === 'completed'` means the user finished the signing ceremony. `status === 'cancelled'` means the user explicitly cancelled or closed the signing UI.
351
367
 
368
+ #### Android launch strategies
369
+
370
+ The Android SDK can open a captive signing ceremony two ways, and `launchStrategy` picks between them. It has no effect on iOS.
371
+
372
+ `'fetch'` is the default and matches every release before this option existed. The SDK downloads the envelope with `include=documents` and then opens the ceremony. That download runs on a read timeout derived from the envelope size, which floors at 15 seconds when nothing is cached, so a large envelope on a slow connection can exhaust it and the ceremony never opens.
373
+
374
+ `'signingUrl'` skips the download. The module mints a recipient view with the session access token (`POST /accounts/{accountId}/envelopes/{envelopeId}/views/recipient`) and points the SDK straight at the returned URL, so the call that times out never runs.
375
+
376
+ ```ts
377
+ await presentCaptiveSigning({
378
+ envelopeId,
379
+ recipientUserName,
380
+ recipientEmail,
381
+ recipientClientUserId,
382
+ launchStrategy: 'signingUrl',
383
+ });
384
+ ```
385
+
386
+ Before opting in, check that the access token you pass to `loginWithAccessToken` is scoped to create recipient views on the envelope. If the mint fails the module falls back to `'fetch'`, so the worst case is a wasted round trip per ceremony rather than a failure, but there is no point paying for it if the token cannot mint.
387
+
388
+ If your backend already mints recipient view URLs, prefer `presentCaptiveSigningWithUrl` instead. It keeps the DocuSign access token off the device entirely, which is the better shape. `'signingUrl'` exists for teams who cannot change their backend.
389
+
352
390
  ### `presentCaptiveSigningWithUrl(params: CaptiveSigningUrlParams): Promise<SigningResult>`
353
391
 
354
- **iOS only.** Presents the DocuSign signing UI using a pre-minted recipient view URL (obtained server-side from `POST /envelopes/{id}/views/recipient`). Bypasses SDK authentication; no `initialize` / `loginWithAccessToken` required first.
392
+ Presents the DocuSign signing UI using a pre-minted recipient view URL (obtained server-side from `POST /envelopes/{id}/views/recipient`). Bypasses SDK authentication; `initialize` is required, but `loginWithAccessToken` is not.
355
393
 
356
394
  ```ts
357
395
  type CaptiveSigningUrlParams = {
@@ -367,14 +405,17 @@ type CaptiveSigningUrlParams = {
367
405
  - `envelopeId`: the DocuSign envelope ID
368
406
  - `recipientId` (optional): identifier used for event correlation
369
407
 
370
- **Throws:**
408
+ **Throws:** a `DocuSignError`.
371
409
 
372
- - `not_implemented` on Android (see [Limitations](#limitations))
373
- - `signing_failed` if the URL is expired, malformed, or rejected by DocuSign
410
+ - `not_initialized` if `initialize` has not been called
411
+ - `invalid_signing_url` if the URL is blank or not `https`
412
+ - `signing_in_progress` if a ceremony is already open
413
+ - `presentation_failed` if there is no screen to present from
414
+ - `signing_failed` if the URL is expired or rejected by DocuSign, with `reason` as for `presentCaptiveSigning`
374
415
 
375
416
  **Returns:** same `SigningResult` shape as `presentCaptiveSigning`.
376
417
 
377
- **Why this flow:** keeps the DocuSign access token out of the mobile app entirely; your backend mints the signing URL and hands that single-use credential to the client. Recommended for production iOS flows.
418
+ **Why this flow:** keeps the DocuSign access token out of the mobile app entirely; your backend mints the signing URL and hands that single-use credential to the client. Recommended for production iOS and Android flows.
378
419
 
379
420
  ### `logout(): Promise<void>`
380
421
 
@@ -420,8 +461,9 @@ const cancelSub = DocuSign.addSigningCancelledListener((event) => {
420
461
  console.log('Cancelled:', event.envelopeId, event.reason);
421
462
  });
422
463
 
423
- const errorSub = DocuSign.addSigningErrorListener((event) => {
424
- console.error('Error:', event.errorCode, event.errorMessage);
464
+ const errorSub = DocuSign.addSigningErrorListener((error) => {
465
+ // Every DocuSignError, caller mistakes included, once each and before the call rejects.
466
+ analytics.track('docusign_failed', error.toAttributes());
425
467
  });
426
468
 
427
469
  // Later, clean up:
@@ -430,6 +472,8 @@ cancelSub.remove();
430
472
  errorSub.remove();
431
473
  ```
432
474
 
475
+ `addSigningErrorListener` covers `initialize`, `loginWithAccessToken`, `presentCaptiveSigning` and `presentCaptiveSigningWithUrl`. Register it once at startup to send every failure to your analytics or error reporting tool, as shown in the [error handling guide](docs/ERROR_HANDLING.md#sending-errors-to-your-tools).
476
+
433
477
  In React hooks:
434
478
 
435
479
  ```ts
@@ -482,7 +526,7 @@ function SigningScreen() {
482
526
  {state === 'signing' && <Text>Opening signing UI...</Text>}
483
527
  {state === 'completed' && <Text>Signed envelope {result?.envelopeId}</Text>}
484
528
  {state === 'cancelled' && <Text>Signing cancelled</Text>}
485
- {state === 'error' && <Text>Error: {error?.message}</Text>}
529
+ {state === 'error' && error && <Text>{t(DOCUSIGN_ERROR_COPY_KEY[error.reason])}</Text>}
486
530
  </View>
487
531
  );
488
532
  }
@@ -493,12 +537,12 @@ function SigningScreen() {
493
537
  - Calls `initialize()` automatically on mount (toggle with `autoInitialize: false` if you want to defer)
494
538
  - Accepts both signing flows via a discriminated union on `startSigning(session)`:
495
539
  - `{ type: 'session', ... }`: runs `loginWithAccessToken` + `presentCaptiveSigning` (iOS + Android)
496
- - `{ type: 'url', ... }`: runs `presentCaptiveSigningWithUrl` (iOS only; throws on Android)
540
+ - `{ type: 'url', ... }`: runs `presentCaptiveSigningWithUrl` (iOS + Android, no SDK login)
497
541
  - Tracks SDK state in a finite state machine
498
- - Subscribes to error events and surfaces them in the `error` field
542
+ - Stores the latest `DocuSignError` in the `error` field. `DOCUSIGN_ERROR_COPY_KEY` in the usage example comes from the [error handling guide](docs/ERROR_HANDLING.md#copyts)
499
543
  - Cleans up event listeners on unmount
500
544
 
501
- ### URL-flow example (iOS)
545
+ ### URL-flow example (iOS + Android)
502
546
 
503
547
  ```tsx
504
548
  const result = await startSigning({
@@ -567,7 +611,7 @@ type UseDocuSignSigningOptions = {
567
611
 
568
612
  type UseDocuSignSigningReturn = {
569
613
  state: DocuSignSigningState;
570
- error: Error | null;
614
+ error: DocuSignError | null;
571
615
  result: SigningResult | null;
572
616
  initialize: () => Promise<void>; // manual init if autoInitialize=false
573
617
  startSigning: (session: SigningSession) => Promise<SigningResult>;
@@ -605,6 +649,7 @@ export type CaptiveSigningParams = {
605
649
  recipientClientUserId: string;
606
650
  };
607
651
 
652
+ // 'error' is never returned since 2.0.0. It stays so existing switch statements compile.
608
653
  export type SigningStatus = 'completed' | 'cancelled' | 'error';
609
654
 
610
655
  export type SigningResult = {
@@ -623,13 +668,37 @@ export type SigningCancelledEvent = {
623
668
  reason?: string;
624
669
  };
625
670
 
626
- export type SigningErrorEvent = {
671
+ export class DocuSignError extends Error {
672
+ code: DocuSignErrorCode;
673
+ reason: DocuSignErrorReason;
627
674
  envelopeId?: string;
628
- errorCode: string;
629
- errorMessage: string;
630
- };
675
+ native?: DocuSignNativeErrorDetails;
676
+ http?: DocuSignHttpErrorDetails;
677
+ toAttributes(): DocuSignErrorAttributes;
678
+ }
679
+
680
+ export type DocuSignErrorCode =
681
+ | 'not_initialized'
682
+ | 'not_logged_in'
683
+ | 'signing_in_progress'
684
+ | 'invalid_signing_url'
685
+ | 'presentation_failed'
686
+ | 'initialize_failed'
687
+ | 'login_failed'
688
+ | 'signing_failed'
689
+ | 'unexpected';
690
+
691
+ export type DocuSignErrorReason =
692
+ | 'usage'
693
+ | 'network'
694
+ | 'auth'
695
+ | 'configuration'
696
+ | 'recipient'
697
+ | 'unknown';
631
698
  ```
632
699
 
700
+ The full error model, including `native`, `http` and the attributes, is in the [error handling guide](docs/ERROR_HANDLING.md#the-error-model).
701
+
633
702
  ## Authentication flow
634
703
 
635
704
  This package does NOT implement DocuSign JWT Grant authentication. JWT Grant must happen on your backend because it requires access to an RSA private key that should never ship on mobile devices.
@@ -703,7 +772,9 @@ const envelope = await docusign.envelopes.create({
703
772
 
704
773
  ## Multi-document / multi-envelope chaining
705
774
 
706
- Because the DocuSign SDK returns control to your app after each signing ceremony, you can easily chain multiple signings in sequence:
775
+ Because the DocuSign SDK returns control to your app after each signing ceremony, you can chain multiple signings in sequence.
776
+
777
+ ### Minimal example
707
778
 
708
779
  ```ts
709
780
  async function signMultipleDocuments(documents: Document[]) {
@@ -727,36 +798,74 @@ async function signMultipleDocuments(documents: Document[]) {
727
798
  }
728
799
  ```
729
800
 
801
+ ### Production-grade example with `endSigningSession`
802
+
803
+ Between signing ceremonies on the same app session, call [`endSigningSession`](#endsigningsession-promisevoid) so the next `loginWithAccessToken` + `presentCaptiveSigning` pair starts from a clean SDK state. This avoids the iOS WebKit race that caused captive signing to hang on the second consecutive open in versions ≤ 1.0.1. Always run it in a `finally` block so it executes on cancel and error paths too.
804
+
805
+ ```ts
806
+ async function signMultipleDocumentsSafe(documents: Document[]) {
807
+ const results: SigningResult[] = [];
808
+
809
+ for (const document of documents) {
810
+ const session = await fetchSigningSession(document.id);
811
+
812
+ try {
813
+ await DocuSign.loginWithAccessToken(session);
814
+ const result = await DocuSign.presentCaptiveSigning({
815
+ envelopeId: session.envelopeId,
816
+ recipientUserName: session.userName,
817
+ recipientEmail: session.email,
818
+ recipientClientUserId: session.recipientClientUserId,
819
+ });
820
+ results.push(result);
821
+
822
+ if (result.status !== 'completed') break;
823
+ } finally {
824
+ await DocuSign.endSigningSession();
825
+ }
826
+ }
827
+
828
+ return results;
829
+ }
830
+ ```
831
+
730
832
  Between signings, you can also show a confirmation prompt ("sign another document?") and only continue if the user agrees.
731
833
 
732
834
  ## Error handling
733
835
 
734
- The module rejects promises with coded exceptions you can inspect at the call site:
836
+ Every failure rejects with a `DocuSignError`, on both platforms, with the same fields:
735
837
 
736
- | Error code | When | Mitigation |
737
- | ------------------- | --------------------------------------------- | -------------------------------------------------------------- |
738
- | `initialize_failed` | SDK failed to configure | Check integrator key and network connectivity |
739
- | `login_failed` | Access token rejected, or Keychain misconfigured (iOS) | Fetch a fresh token from your backend; on iOS also verify `AppIdentifierPrefix` is set in `Info.plist` (see [Permissions](#permissions)) |
740
- | `signing_failed` | SDK failed to present or complete signing | Check envelope ID, recipient info, SDK login state |
741
- | `not_initialized` | `initialize()` was not called first | Call `initialize()` before any other method |
742
- | `not_logged_in` | `loginWithAccessToken()` was not called first | Call `loginWithAccessToken()` before `presentCaptiveSigning()` |
838
+ - `code` says what failed, such as `login_failed` or `signing_in_progress`. It is stable and safe to branch on.
839
+ - `reason` says why: `usage`, `network`, `auth`, `configuration`, `recipient` or `unknown`. The package sets it only from facts it can verify, so it never guesses.
840
+ - `message` is English text for developers. Never show it to users.
841
+ - `native` and `http` carry the raw SDK error and any DocuSign response behind the failure.
842
+ - `toAttributes()` flattens all of it into primitive values for Amplitude, New Relic, Sentry or any other tool.
743
843
 
744
- Example:
844
+ The package shows no UI, ships no user-facing strings and logs nothing in production. Your app picks the copy from `reason` and decides where errors are recorded:
745
845
 
746
846
  ```ts
747
847
  try {
748
848
  await DocuSign.presentCaptiveSigning(params);
749
849
  } catch (error) {
750
- if (error.code === 'not_logged_in') {
751
- const session = await refreshSession();
752
- await DocuSign.loginWithAccessToken(session);
753
- // retry
754
- } else {
755
- reportError(error);
850
+ if (!(error instanceof DocuSign.DocuSignError)) throw error;
851
+ showToast({ title: t(DOCUSIGN_ERROR_COPY_KEY[error.reason]) });
852
+ if (error.reason === 'auth') {
853
+ await startOverWithFreshSession();
756
854
  }
757
855
  }
758
856
  ```
759
857
 
858
+ | `reason` | Who fixes it | Suggested copy | Retry |
859
+ | --- | --- | --- | --- |
860
+ | `usage` | the app developer | generic | no, it is a bug |
861
+ | `network` | nobody, the connection was lost | "Check your connection and try again." | yes |
862
+ | `auth` | backend token minting | "Your signing session expired." | after a fresh session |
863
+ | `configuration` | DocuSign admin, or `AppIdentifierPrefix` on iOS | "Signing isn't available right now." | no |
864
+ | `recipient` | backend envelope creation | "Please contact the sender." | no |
865
+ | `unknown` | investigate with `native` | generic | yes |
866
+
867
+ The [error handling guide](docs/ERROR_HANDLING.md) covers the full error model, translated copy with i18next, a retry policy, sending errors to Amplitude, New Relic and Sentry, the dashboards and queries to read them in production, and worked examples for every reason. Its code samples are type-checked in CI.
868
+
760
869
  ## Security considerations
761
870
 
762
871
  1. **Never log access tokens.** If you use LogRocket, Sentry, Datadog, or any other session recording tool, add the signing session endpoint and any DocuSign token fields to your network scrub list.
@@ -790,35 +899,37 @@ The config plugin writes these keys automatically, or you can configure them man
790
899
 
791
900
  ### iOS build fails with "No such module 'DocuSignSDK'"
792
901
 
793
- Ensure `pod install` completed successfully inside `ios/`. The podspec declares a dependency on `DocuSign-iOS-SDK`; if CocoaPods trunk is unreachable, the pod cannot be installed. Check your network, proxy, and CocoaPods version (`pod --version` should be 1.14+).
902
+ Ensure `pod install` completed successfully inside `ios/`. The podspec declares a dependency on the `DocuSign` pod; if CocoaPods trunk is unreachable, the pod cannot be installed. Check your network, proxy, and CocoaPods version (`pod --version` should be 1.14+).
794
903
 
795
904
  ### iOS build fails with "Undefined symbols" for DSMManager
796
905
 
797
906
  The DocuSign SDK must be set to `use_frameworks!` mode. Most Expo projects use frameworks by default. If you recently switched to static libraries, add `use_frameworks! :linkage => :static` to your Podfile and rebuild.
798
907
 
799
- ### Android build fails with "Could not find com.docusign:androidsdk:2.1.4"
908
+ ### Android build fails with "Could not find com.docusign:androidsdk:2.1.7"
800
909
 
801
910
  The DocuSign Android SDK is not on Maven Central; it is hosted on DocuSign's own Maven repository. Ensure the config plugin has added the repo to your project-level `build.gradle`. If running a bare project, manually add:
802
911
 
803
912
  ```groovy
804
913
  allprojects {
805
914
  repositories {
806
- maven { url "https://maven.docusign.com/" }
915
+ maven { url "https://docucdn-a.akamaihd.net/prod/docusignandroidsdk" }
807
916
  }
808
917
  }
809
918
  ```
810
919
 
920
+ This is the URL DocuSign's own [Android SDK install guide](https://github.com/docusign/mobile-android-sdk) uses. It is a static file host with no index page, so opening it in a browser returns 404 even though Gradle resolves artifacts under it, such as `com/docusign/androidsdk/2.1.7/androidsdk-2.1.7.pom`. It also serves no `maven-metadata.xml`, so declare exact versions: a dynamic version such as `2.+` does not resolve.
921
+
811
922
  ### "not_logged_in" error when calling `presentCaptiveSigning`
812
923
 
813
924
  The SDK login state is in-memory and does not survive app restarts. Always call `loginWithAccessToken()` before `presentCaptiveSigning()` within the same app session.
814
925
 
815
926
  ### Access token expired mid-signing
816
927
 
817
- DocuSign access tokens are valid for about 1 hour. If a token expires while the signing UI is open, the SDK emits an error event and the promise rejects. Catch the error, fetch a fresh session from your backend, and retry.
928
+ DocuSign access tokens are valid for about 1 hour. If a token expires while the signing UI is open, the promise rejects with a `DocuSignError`. Catch it, fetch a fresh session from your backend, and start over rather than retrying the same session.
818
929
 
819
930
  ### `login_failed` on iOS even with a valid token
820
931
 
821
- If `loginWithAccessToken` rejects with `login_failed` (or the SDK logs "unauthorized") but the same token works on Android, the most likely cause is a missing `AppIdentifierPrefix` entry in your `Info.plist`.
932
+ If `loginWithAccessToken` rejects with `login_failed` and `reason: 'configuration'`, DocuSign accepted the token at `/oauth/userinfo` but the SDK still refused it. When the same token works on Android, the most likely cause is a missing `AppIdentifierPrefix` entry in your `Info.plist`.
822
933
 
823
934
  The DocuSign iOS SDK uses the Apple Keychain to store auth state. Without `AppIdentifierPrefix`, it cannot access the Keychain group and rejects the login at the SDK level, regardless of token validity.
824
935
 
@@ -844,10 +955,10 @@ The module uses `appContext.activityProvider.currentActivity` to get the current
844
955
  | This package version | Expo SDK | React Native | iOS SDK | Android SDK |
845
956
  | -------------------- | -------- | ------------ | ------------------ | ---------------------- |
846
957
  | 1.0.x | 55.x | 0.82.x | DocuSign iOS 4.1.1 | DocuSign Android 2.1.4 |
958
+ | 2.0.x | 55.x+ | 0.85.x+ | DocuSign iOS 4.3.0 | DocuSign Android 2.1.7 |
847
959
 
848
960
  ## Limitations
849
961
 
850
- - **URL-based captive signing is iOS-only.** `presentCaptiveSigningWithUrl` is supported on iOS via DocuSign's iOS SDK 4.1.1. The DocuSign Android SDK 2.1.4 does not expose a public API that accepts a pre-minted recipient view URL, so the method throws `not_implemented` on Android. On Android, use `loginWithAccessToken` + `presentCaptiveSigning` (the session path). Your backend can branch response shape per platform.
851
962
  - **Offline signing not exposed.** DocuSign's Android SDK supports offline signing via `com.docusign:sdk-offline-signing`. This package does not currently expose offline APIs. If you need offline signing, open an issue or send a pull request.
852
963
  - **Template management not exposed.** The SDK's template caching and download APIs are not wrapped. Template creation should happen server-side via the DocuSign REST API.
853
964
  - **Custom UI not supported.** The signing UI is provided by the DocuSign SDK and cannot be customized from this package. DocuSign owns the look and feel of the signing ceremony (this is intentional for legal compliance consistency).
@@ -880,9 +991,9 @@ Create a free DocuSign developer account at https://developers.docusign.com. It
880
991
 
881
992
  Configure a DocuSign Connect webhook that points to your backend. DocuSign will push envelope status updates (sent, delivered, completed, declined, voided) as they happen. Use the webhook as your source of truth and treat the mobile-side `SigningResult` as a UX signal only.
882
993
 
883
- ### Why is the DocuSign SDK so large?
994
+ ### How much does the DocuSign SDK add to my app bundle?
884
995
 
885
- The DocuSign native SDKs include a full PDF viewer, signature pad, form renderer, and offline sync engine. Combined, they add roughly 30 to 50 MB per platform to your app bundle. DocuSign reduced the iOS SDK size by about 75% in v4.0.0; the current size is considered the minimum viable footprint.
996
+ This npm package itself is under 1 MB (TypeScript + native bridge sources only, see [SDK bundling policy](#sdk-bundling-policy)). The size impact comes from the upstream DocuSign native SDKs that consumers pull from CocoaPods (iOS) and DocuSign's Maven repo (Android) at consumer build time. They add tens of MB per platform: full PDF viewer, signature pad, form renderer, and offline sync engine. Measure your own delta by running `du -sh` on your release IPA / APK before and after adding the dependency.
886
997
 
887
998
  ### Can I ship this alongside `react-native-pdf` or another PDF viewer?
888
999
 
@@ -70,14 +70,14 @@ dependencies {
70
70
  // collides with expo-image (and any other Glide-based library) at dex time.
71
71
  // We exclude the upstream sdk-pdf and link a locally-stripped copy from
72
72
  // libs/ that has the generated Glide classes removed.
73
- implementation('com.docusign:androidsdk:2.1.4') {
73
+ implementation('com.docusign:androidsdk:2.1.7') {
74
74
  exclude group: 'com.docusign', module: 'sdk-pdf'
75
75
  }
76
- implementation 'com.docusign:sdk-common:2.1.4'
76
+ implementation 'com.docusign:sdk-common:2.1.7'
77
77
  // Direct file reference instead of flatDir (name:..., ext:...). Gradle 9.0 no
78
78
  // longer honors subproject-scoped flatDir when resolving across project
79
- // boundaries, so the stripped AAR (placed at libs/sdk-pdf-2.1.4-stripped.aar
79
+ // boundaries, so the stripped AAR (placed at libs/sdk-pdf-2.1.7-stripped.aar
80
80
  // by the config plugin) wasn't found and the build failed with
81
- // "Could not find :sdk-pdf-2.1.4-stripped:".
82
- implementation files("$projectDir/libs/sdk-pdf-2.1.4-stripped.aar")
81
+ // "Could not find :sdk-pdf-2.1.7-stripped:".
82
+ implementation files("$projectDir/libs/sdk-pdf-2.1.7-stripped.aar")
83
83
  }
@@ -2,17 +2,37 @@ package expo.modules.docusign
2
2
 
3
3
  import expo.modules.kotlin.exception.CodedException
4
4
 
5
- class NotInitializedException :
6
- CodedException("DocuSign SDK has not been initialized. Call initialize() first.")
5
+ // Caller mistakes only. Runtime failures travel as DocuSignFailure so their details survive the
6
+ // bridge. Codes are given explicitly rather than inferred: CodedException derives a code from the
7
+ // class name when none is provided, which would surface NotInitializedException to JS as
8
+ // ERR_NOT_INITIALIZED, not the not_initialized documented in the README error table.
7
9
 
8
- class NotLoggedInException :
9
- CodedException("DocuSign SDK is not logged in. Call loginWithAccessToken() first.")
10
+ class NotInitializedException : CodedException(
11
+ "not_initialized",
12
+ "DocuSign SDK has not been initialized. Call initialize() first.",
13
+ null
14
+ )
10
15
 
11
- class LoginFailedException(message: String) :
12
- CodedException("DocuSign login failed: $message")
16
+ class NotLoggedInException : CodedException(
17
+ "not_logged_in",
18
+ "DocuSign SDK is not logged in. Call loginWithAccessToken() first.",
19
+ null
20
+ )
13
21
 
14
- class SigningFailedException(message: String) :
15
- CodedException("DocuSign signing failed: $message")
22
+ class SigningInProgressException : CodedException(
23
+ "signing_in_progress",
24
+ "A signing session is already in progress. Wait for it to finish or call endSigningSession() first.",
25
+ null
26
+ )
16
27
 
17
- class PresentationException(message: String) :
18
- CodedException("Failed to present DocuSign signing UI: $message")
28
+ class InvalidSigningUrlException : CodedException(
29
+ "invalid_signing_url",
30
+ "signingUrl must be a non-empty https URL.",
31
+ null
32
+ )
33
+
34
+ class PresentationException(message: String) : CodedException(
35
+ "presentation_failed",
36
+ "Failed to present DocuSign signing UI: $message",
37
+ null
38
+ )