react-native-docusign 1.0.5 → 2.0.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.
Files changed (37) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +186 -71
  3. package/android/build.gradle +6 -5
  4. package/android/consumer-rules.pro +8 -0
  5. package/android/src/main/java/expo/modules/docusign/DocuSignError.kt +30 -10
  6. package/android/src/main/java/expo/modules/docusign/DocuSignFailure.kt +145 -0
  7. package/android/src/main/java/expo/modules/docusign/DocuSignManager.kt +407 -58
  8. package/android/src/main/java/expo/modules/docusign/DocuSignModule.kt +61 -42
  9. package/build/DocuSign.types.d.ts +39 -0
  10. package/build/DocuSign.types.d.ts.map +1 -1
  11. package/build/DocuSignError.d.ts +86 -0
  12. package/build/DocuSignError.d.ts.map +1 -0
  13. package/build/DocuSignError.js +210 -0
  14. package/build/DocuSignError.js.map +1 -0
  15. package/build/DocuSignModule.d.ts +24 -5
  16. package/build/DocuSignModule.d.ts.map +1 -1
  17. package/build/DocuSignModule.js.map +1 -1
  18. package/build/api.d.ts +24 -6
  19. package/build/api.d.ts.map +1 -1
  20. package/build/api.js +84 -17
  21. package/build/api.js.map +1 -1
  22. package/build/index.d.ts +2 -0
  23. package/build/index.d.ts.map +1 -1
  24. package/build/index.js +1 -0
  25. package/build/index.js.map +1 -1
  26. package/build/useDocuSignSigning.d.ts +2 -1
  27. package/build/useDocuSignSigning.d.ts.map +1 -1
  28. package/build/useDocuSignSigning.js +20 -6
  29. package/build/useDocuSignSigning.js.map +1 -1
  30. package/ios/DocuSignError.swift +45 -10
  31. package/ios/DocuSignFailure.swift +104 -0
  32. package/ios/DocuSignManager.swift +162 -106
  33. package/ios/DocuSignModule.swift +37 -37
  34. package/ios/ReactNativeDocuSign.podspec +1 -1
  35. package/package.json +12 -3
  36. package/plugin/build/index.js +21 -41
  37. package/plugin/build/index.js.map +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,55 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.1
4
+
5
+ ### Fixes
6
+
7
+ - **Android**: the module ships R8 keep rules for the models in DocuSign's `sdk-esign-api`. DocuSign's own rules cover `com.docusign.androidsdk` only, so an app with minification on lost the fields Gson fills on those models, and login and captive signing failed at runtime without a crash at launch. The rules reach the app through `consumerProguardFiles`, so an app can delete any DocuSign keep rules it added itself.
8
+
9
+ ## 2.0.0
10
+
11
+ 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.
12
+
13
+ ### Native SDKs
14
+
15
+ - **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.
16
+ - **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.
17
+
18
+ ### Breaking changes
19
+
20
+ - 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).
21
+ - `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.
22
+ - 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`.
23
+ - `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`.
24
+ - `useDocuSignSigning` types `error` as `DocuSignError | null`.
25
+ - **Android**: one native `onSigningError` event per failure instead of two.
26
+
27
+ ### New features
28
+
29
+ - `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`).
30
+ - `DocuSignError.toAttributes()` returns flat, primitive attributes ready for Amplitude, New Relic, Sentry or any other tool.
31
+ - 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.
32
+ - **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.
33
+ - In development, a caller mistake also prints one console warning naming the fix, so a catch that shows a generic toast cannot hide it.
34
+ - **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`.
35
+ - 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.
36
+ - **Android**: Add `presentCaptiveSigningWithUrl` support. The URL flow now has iOS/Android parity and does not require `loginWithAccessToken`.
37
+ - **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.
38
+
39
+ ### Fixes
40
+
41
+ - 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`.
42
+ - **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.
43
+ - **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`.
44
+ - **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.
45
+ - **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.
46
+ - **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.
47
+ - **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.
48
+ - **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.
49
+ - **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.
50
+ - **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.
51
+ - **Android**: `presentCaptiveSigning` now clears `currentEnvelopeId` when the launch itself throws, matching the URL path.
52
+
3
53
  ## 1.0.5
4
54
 
5
55
  ### 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,18 +107,22 @@ 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.
116
+
117
+ ### Minified release builds (R8)
118
+
119
+ Apps with `minifyEnabled` (for Expo, `expo-build-properties` `android.enableMinifyInReleaseBuilds`) need no DocuSign keep rules of their own from 2.0.1. The module's `android/consumer-rules.pro` reaches the app's R8 configuration through `consumerProguardFiles` and keeps `com.docusign.esign.model.**`, the Gson models in DocuSign's `sdk-esign-api` JAR. DocuSign's own rules cover `com.docusign.androidsdk` only, so without it R8 strips the model fields and login and captive signing fail at runtime. The module's class names are also kept, so `DocuSignError.native.domain` stays readable in an obfuscated build.
114
120
 
115
121
  ### What ships inside this package
116
122
 
117
123
  - TypeScript source + type definitions
118
124
  - Swift + Kotlin bridge source files
119
- - Podspec and gradle config
125
+ - Podspec, gradle config and R8 consumer rules
120
126
  - Config plugin compiled output
121
127
  - README, CHANGELOG, LICENSE
122
128
 
@@ -180,7 +186,7 @@ npx expo run:android
180
186
 
181
187
  If you are not using Expo prebuild, you must manually:
182
188
 
183
- - **iOS**: add `pod 'DocuSign-iOS-SDK', '~> 4.1.1'` to your Podfile and run `pod install`
189
+ - **iOS**: run `pod install`. This package's podspec already depends on the `DocuSign` pod, so your Podfile needs no entry for it
184
190
  - **Android**: add the Maven repo and the DocuSign dependency to your `android/build.gradle` + `android/app/build.gradle`
185
191
  - **iOS**: add the `NSCameraUsageDescription` and `NSPhotoLibraryUsageDescription` keys to your `Info.plist`
186
192
  - **Android**: add the required permissions to your `AndroidManifest.xml`
@@ -207,7 +213,7 @@ type DocuSignPluginProps = {
207
213
 
208
214
  /**
209
215
  * URL of the Android Maven repository that serves the DocuSign Android SDK.
210
- * Defaults to 'https://maven.docusign.com/'.
216
+ * Defaults to 'https://docucdn-a.akamaihd.net/prod/docusignandroidsdk'.
211
217
  * Override only if DocuSign moves their repo.
212
218
  */
213
219
  androidMavenRepo?: string;
@@ -250,27 +256,30 @@ async function signAgreement() {
250
256
  });
251
257
 
252
258
  // 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
- });
259
+ try {
260
+ const result = await DocuSign.presentCaptiveSigning({
261
+ envelopeId: session.envelopeId,
262
+ recipientUserName: session.userName,
263
+ recipientEmail: session.email,
264
+ recipientClientUserId: session.recipientClientUserId,
265
+ });
259
266
 
260
- switch (result.status) {
261
- case 'completed':
267
+ if (result.status === 'completed') {
262
268
  console.log('Signed:', result.envelopeId);
263
- break;
264
- case 'cancelled':
269
+ } else {
265
270
  console.log('User cancelled signing');
266
- break;
267
- case 'error':
268
- console.error('Signing error:', result.errorMessage);
269
- break;
271
+ }
272
+ } catch (error) {
273
+ if (error instanceof DocuSign.DocuSignError) {
274
+ // error.reason picks the message to show, error.toAttributes() goes to your logs.
275
+ console.error(error.code, error.reason, error.message);
276
+ }
270
277
  }
271
278
  }
272
279
  ```
273
280
 
281
+ Every failure rejects with a `DocuSignError`. See [Error handling](#error-handling).
282
+
274
283
  ## API reference
275
284
 
276
285
  ### `initialize(config: DocuSignConfig): Promise<void>`
@@ -289,7 +298,7 @@ type DocuSignConfig = {
289
298
  - `integratorKey`: your DocuSign Integrator Key (Client ID). Can be fetched from your backend at runtime to avoid shipping it in the app bundle.
290
299
  - `environment`: `'demo'` targets `demo.docusign.net` (DocuSign developer sandbox). `'production'` targets `docusign.net`.
291
300
 
292
- **Throws:** rejects if the SDK cannot be initialized.
301
+ **Throws:** a `DocuSignError` with `initialize_failed` if the SDK cannot be configured.
293
302
 
294
303
  ### `loginWithAccessToken(params: DocuSignAuthParams): Promise<void>`
295
304
 
@@ -315,7 +324,10 @@ type DocuSignAuthParams = {
315
324
  - `email`: email address for the signer
316
325
  - `host`: DocuSign API host URL (e.g. `'https://demo.docusign.net/restapi'`)
317
326
 
318
- **Throws:** rejects with `login_failed` if the token is invalid, expired, or rejected by DocuSign.
327
+ **Throws:**
328
+
329
+ - `not_initialized` if `initialize` has not been called
330
+ - `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
331
 
320
332
  **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
333
 
@@ -329,13 +341,14 @@ type CaptiveSigningParams = {
329
341
  recipientUserName: string;
330
342
  recipientEmail: string;
331
343
  recipientClientUserId: string;
344
+ launchStrategy?: 'fetch' | 'signingUrl'; // Android only, default 'fetch'
332
345
  };
333
346
 
334
347
  type SigningResult = {
335
- status: 'completed' | 'cancelled' | 'error';
348
+ status: 'completed' | 'cancelled' | 'error'; // 'error' is never returned since 2.0.0
336
349
  envelopeId: string;
337
350
  errorCode?: string;
338
- errorMessage?: string;
351
+ errorMessage?: string; // for 'cancelled', the SDK's exit reason when it gives one
339
352
  };
340
353
  ```
341
354
 
@@ -344,14 +357,43 @@ type SigningResult = {
344
357
  - `envelopeId`: the DocuSign envelope ID created by your backend
345
358
  - `recipientUserName`, `recipientEmail`: must match the recipient registered on the envelope
346
359
  - `recipientClientUserId`: the `clientUserId` of the embedded recipient, used by DocuSign to identify captive signers
360
+ - `launchStrategy`: how the Android SDK opens the ceremony, see [Android launch strategies](#android-launch-strategies). Ignored on iOS.
347
361
 
348
- **Throws:** rejects with `signing_failed` if the SDK fails to present the signing UI (e.g. not initialized, not logged in, invalid envelope).
362
+ **Throws:** a `DocuSignError`.
363
+
364
+ - `not_initialized` if `initialize` has not been called
365
+ - `not_logged_in` if `loginWithAccessToken` has not been called
366
+ - `signing_in_progress` if a ceremony is already open
367
+ - `presentation_failed` if there is no screen to present from
368
+ - `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
369
 
350
370
  **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
371
 
372
+ #### Android launch strategies
373
+
374
+ The Android SDK can open a captive signing ceremony two ways, and `launchStrategy` picks between them. It has no effect on iOS.
375
+
376
+ `'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.
377
+
378
+ `'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.
379
+
380
+ ```ts
381
+ await presentCaptiveSigning({
382
+ envelopeId,
383
+ recipientUserName,
384
+ recipientEmail,
385
+ recipientClientUserId,
386
+ launchStrategy: 'signingUrl',
387
+ });
388
+ ```
389
+
390
+ 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.
391
+
392
+ 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.
393
+
352
394
  ### `presentCaptiveSigningWithUrl(params: CaptiveSigningUrlParams): Promise<SigningResult>`
353
395
 
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.
396
+ 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
397
 
356
398
  ```ts
357
399
  type CaptiveSigningUrlParams = {
@@ -367,14 +409,17 @@ type CaptiveSigningUrlParams = {
367
409
  - `envelopeId`: the DocuSign envelope ID
368
410
  - `recipientId` (optional): identifier used for event correlation
369
411
 
370
- **Throws:**
412
+ **Throws:** a `DocuSignError`.
371
413
 
372
- - `not_implemented` on Android (see [Limitations](#limitations))
373
- - `signing_failed` if the URL is expired, malformed, or rejected by DocuSign
414
+ - `not_initialized` if `initialize` has not been called
415
+ - `invalid_signing_url` if the URL is blank or not `https`
416
+ - `signing_in_progress` if a ceremony is already open
417
+ - `presentation_failed` if there is no screen to present from
418
+ - `signing_failed` if the URL is expired or rejected by DocuSign, with `reason` as for `presentCaptiveSigning`
374
419
 
375
420
  **Returns:** same `SigningResult` shape as `presentCaptiveSigning`.
376
421
 
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.
422
+ **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
423
 
379
424
  ### `logout(): Promise<void>`
380
425
 
@@ -420,8 +465,9 @@ const cancelSub = DocuSign.addSigningCancelledListener((event) => {
420
465
  console.log('Cancelled:', event.envelopeId, event.reason);
421
466
  });
422
467
 
423
- const errorSub = DocuSign.addSigningErrorListener((event) => {
424
- console.error('Error:', event.errorCode, event.errorMessage);
468
+ const errorSub = DocuSign.addSigningErrorListener((error) => {
469
+ // Every DocuSignError, caller mistakes included, once each and before the call rejects.
470
+ analytics.track('docusign_failed', error.toAttributes());
425
471
  });
426
472
 
427
473
  // Later, clean up:
@@ -430,6 +476,8 @@ cancelSub.remove();
430
476
  errorSub.remove();
431
477
  ```
432
478
 
479
+ `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).
480
+
433
481
  In React hooks:
434
482
 
435
483
  ```ts
@@ -482,7 +530,7 @@ function SigningScreen() {
482
530
  {state === 'signing' && <Text>Opening signing UI...</Text>}
483
531
  {state === 'completed' && <Text>Signed envelope {result?.envelopeId}</Text>}
484
532
  {state === 'cancelled' && <Text>Signing cancelled</Text>}
485
- {state === 'error' && <Text>Error: {error?.message}</Text>}
533
+ {state === 'error' && error && <Text>{t(DOCUSIGN_ERROR_COPY_KEY[error.reason])}</Text>}
486
534
  </View>
487
535
  );
488
536
  }
@@ -493,12 +541,12 @@ function SigningScreen() {
493
541
  - Calls `initialize()` automatically on mount (toggle with `autoInitialize: false` if you want to defer)
494
542
  - Accepts both signing flows via a discriminated union on `startSigning(session)`:
495
543
  - `{ type: 'session', ... }`: runs `loginWithAccessToken` + `presentCaptiveSigning` (iOS + Android)
496
- - `{ type: 'url', ... }`: runs `presentCaptiveSigningWithUrl` (iOS only; throws on Android)
544
+ - `{ type: 'url', ... }`: runs `presentCaptiveSigningWithUrl` (iOS + Android, no SDK login)
497
545
  - Tracks SDK state in a finite state machine
498
- - Subscribes to error events and surfaces them in the `error` field
546
+ - 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
547
  - Cleans up event listeners on unmount
500
548
 
501
- ### URL-flow example (iOS)
549
+ ### URL-flow example (iOS + Android)
502
550
 
503
551
  ```tsx
504
552
  const result = await startSigning({
@@ -567,7 +615,7 @@ type UseDocuSignSigningOptions = {
567
615
 
568
616
  type UseDocuSignSigningReturn = {
569
617
  state: DocuSignSigningState;
570
- error: Error | null;
618
+ error: DocuSignError | null;
571
619
  result: SigningResult | null;
572
620
  initialize: () => Promise<void>; // manual init if autoInitialize=false
573
621
  startSigning: (session: SigningSession) => Promise<SigningResult>;
@@ -605,6 +653,7 @@ export type CaptiveSigningParams = {
605
653
  recipientClientUserId: string;
606
654
  };
607
655
 
656
+ // 'error' is never returned since 2.0.0. It stays so existing switch statements compile.
608
657
  export type SigningStatus = 'completed' | 'cancelled' | 'error';
609
658
 
610
659
  export type SigningResult = {
@@ -623,13 +672,37 @@ export type SigningCancelledEvent = {
623
672
  reason?: string;
624
673
  };
625
674
 
626
- export type SigningErrorEvent = {
675
+ export class DocuSignError extends Error {
676
+ code: DocuSignErrorCode;
677
+ reason: DocuSignErrorReason;
627
678
  envelopeId?: string;
628
- errorCode: string;
629
- errorMessage: string;
630
- };
679
+ native?: DocuSignNativeErrorDetails;
680
+ http?: DocuSignHttpErrorDetails;
681
+ toAttributes(): DocuSignErrorAttributes;
682
+ }
683
+
684
+ export type DocuSignErrorCode =
685
+ | 'not_initialized'
686
+ | 'not_logged_in'
687
+ | 'signing_in_progress'
688
+ | 'invalid_signing_url'
689
+ | 'presentation_failed'
690
+ | 'initialize_failed'
691
+ | 'login_failed'
692
+ | 'signing_failed'
693
+ | 'unexpected';
694
+
695
+ export type DocuSignErrorReason =
696
+ | 'usage'
697
+ | 'network'
698
+ | 'auth'
699
+ | 'configuration'
700
+ | 'recipient'
701
+ | 'unknown';
631
702
  ```
632
703
 
704
+ The full error model, including `native`, `http` and the attributes, is in the [error handling guide](docs/ERROR_HANDLING.md#the-error-model).
705
+
633
706
  ## Authentication flow
634
707
 
635
708
  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 +776,9 @@ const envelope = await docusign.envelopes.create({
703
776
 
704
777
  ## Multi-document / multi-envelope chaining
705
778
 
706
- Because the DocuSign SDK returns control to your app after each signing ceremony, you can easily chain multiple signings in sequence:
779
+ Because the DocuSign SDK returns control to your app after each signing ceremony, you can chain multiple signings in sequence.
780
+
781
+ ### Minimal example
707
782
 
708
783
  ```ts
709
784
  async function signMultipleDocuments(documents: Document[]) {
@@ -727,36 +802,74 @@ async function signMultipleDocuments(documents: Document[]) {
727
802
  }
728
803
  ```
729
804
 
805
+ ### Production-grade example with `endSigningSession`
806
+
807
+ 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.
808
+
809
+ ```ts
810
+ async function signMultipleDocumentsSafe(documents: Document[]) {
811
+ const results: SigningResult[] = [];
812
+
813
+ for (const document of documents) {
814
+ const session = await fetchSigningSession(document.id);
815
+
816
+ try {
817
+ await DocuSign.loginWithAccessToken(session);
818
+ const result = await DocuSign.presentCaptiveSigning({
819
+ envelopeId: session.envelopeId,
820
+ recipientUserName: session.userName,
821
+ recipientEmail: session.email,
822
+ recipientClientUserId: session.recipientClientUserId,
823
+ });
824
+ results.push(result);
825
+
826
+ if (result.status !== 'completed') break;
827
+ } finally {
828
+ await DocuSign.endSigningSession();
829
+ }
830
+ }
831
+
832
+ return results;
833
+ }
834
+ ```
835
+
730
836
  Between signings, you can also show a confirmation prompt ("sign another document?") and only continue if the user agrees.
731
837
 
732
838
  ## Error handling
733
839
 
734
- The module rejects promises with coded exceptions you can inspect at the call site:
840
+ Every failure rejects with a `DocuSignError`, on both platforms, with the same fields:
735
841
 
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()` |
842
+ - `code` says what failed, such as `login_failed` or `signing_in_progress`. It is stable and safe to branch on.
843
+ - `reason` says why: `usage`, `network`, `auth`, `configuration`, `recipient` or `unknown`. The package sets it only from facts it can verify, so it never guesses.
844
+ - `message` is English text for developers. Never show it to users.
845
+ - `native` and `http` carry the raw SDK error and any DocuSign response behind the failure.
846
+ - `toAttributes()` flattens all of it into primitive values for Amplitude, New Relic, Sentry or any other tool.
743
847
 
744
- Example:
848
+ 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
849
 
746
850
  ```ts
747
851
  try {
748
852
  await DocuSign.presentCaptiveSigning(params);
749
853
  } 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);
854
+ if (!(error instanceof DocuSign.DocuSignError)) throw error;
855
+ showToast({ title: t(DOCUSIGN_ERROR_COPY_KEY[error.reason]) });
856
+ if (error.reason === 'auth') {
857
+ await startOverWithFreshSession();
756
858
  }
757
859
  }
758
860
  ```
759
861
 
862
+ | `reason` | Who fixes it | Suggested copy | Retry |
863
+ | --- | --- | --- | --- |
864
+ | `usage` | the app developer | generic | no, it is a bug |
865
+ | `network` | nobody, the connection was lost | "Check your connection and try again." | yes |
866
+ | `auth` | backend token minting | "Your signing session expired." | after a fresh session |
867
+ | `configuration` | DocuSign admin, or `AppIdentifierPrefix` on iOS | "Signing isn't available right now." | no |
868
+ | `recipient` | backend envelope creation | "Please contact the sender." | no |
869
+ | `unknown` | investigate with `native` | generic | yes |
870
+
871
+ 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.
872
+
760
873
  ## Security considerations
761
874
 
762
875
  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 +903,37 @@ The config plugin writes these keys automatically, or you can configure them man
790
903
 
791
904
  ### iOS build fails with "No such module 'DocuSignSDK'"
792
905
 
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+).
906
+ 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
907
 
795
908
  ### iOS build fails with "Undefined symbols" for DSMManager
796
909
 
797
910
  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
911
 
799
- ### Android build fails with "Could not find com.docusign:androidsdk:2.1.4"
912
+ ### Android build fails with "Could not find com.docusign:androidsdk:2.1.7"
800
913
 
801
914
  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
915
 
803
916
  ```groovy
804
917
  allprojects {
805
918
  repositories {
806
- maven { url "https://maven.docusign.com/" }
919
+ maven { url "https://docucdn-a.akamaihd.net/prod/docusignandroidsdk" }
807
920
  }
808
921
  }
809
922
  ```
810
923
 
924
+ 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.
925
+
811
926
  ### "not_logged_in" error when calling `presentCaptiveSigning`
812
927
 
813
928
  The SDK login state is in-memory and does not survive app restarts. Always call `loginWithAccessToken()` before `presentCaptiveSigning()` within the same app session.
814
929
 
815
930
  ### Access token expired mid-signing
816
931
 
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.
932
+ 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
933
 
819
934
  ### `login_failed` on iOS even with a valid token
820
935
 
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`.
936
+ 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
937
 
823
938
  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
939
 
@@ -844,10 +959,10 @@ The module uses `appContext.activityProvider.currentActivity` to get the current
844
959
  | This package version | Expo SDK | React Native | iOS SDK | Android SDK |
845
960
  | -------------------- | -------- | ------------ | ------------------ | ---------------------- |
846
961
  | 1.0.x | 55.x | 0.82.x | DocuSign iOS 4.1.1 | DocuSign Android 2.1.4 |
962
+ | 2.0.x | 55.x+ | 0.85.x+ | DocuSign iOS 4.3.0 | DocuSign Android 2.1.7 |
847
963
 
848
964
  ## Limitations
849
965
 
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
966
  - **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
967
  - **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
968
  - **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 +995,9 @@ Create a free DocuSign developer account at https://developers.docusign.com. It
880
995
 
881
996
  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
997
 
883
- ### Why is the DocuSign SDK so large?
998
+ ### How much does the DocuSign SDK add to my app bundle?
884
999
 
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.
1000
+ 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
1001
 
887
1002
  ### Can I ship this alongside `react-native-pdf` or another PDF viewer?
888
1003
 
@@ -42,6 +42,7 @@ android {
42
42
  targetSdkVersion safeExtGet("targetSdkVersion", 35)
43
43
  versionCode 1
44
44
  versionName "1.0.5"
45
+ consumerProguardFiles 'consumer-rules.pro'
45
46
  }
46
47
 
47
48
  buildFeatures {
@@ -70,14 +71,14 @@ dependencies {
70
71
  // collides with expo-image (and any other Glide-based library) at dex time.
71
72
  // We exclude the upstream sdk-pdf and link a locally-stripped copy from
72
73
  // libs/ that has the generated Glide classes removed.
73
- implementation('com.docusign:androidsdk:2.1.4') {
74
+ implementation('com.docusign:androidsdk:2.1.7') {
74
75
  exclude group: 'com.docusign', module: 'sdk-pdf'
75
76
  }
76
- implementation 'com.docusign:sdk-common:2.1.4'
77
+ implementation 'com.docusign:sdk-common:2.1.7'
77
78
  // Direct file reference instead of flatDir (name:..., ext:...). Gradle 9.0 no
78
79
  // 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
80
+ // boundaries, so the stripped AAR (placed at libs/sdk-pdf-2.1.7-stripped.aar
80
81
  // 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")
82
+ // "Could not find :sdk-pdf-2.1.7-stripped:".
83
+ implementation files("$projectDir/libs/sdk-pdf-2.1.7-stripped.aar")
83
84
  }
@@ -0,0 +1,8 @@
1
+ # Gson fills com.docusign.esign.model fields by reflection, and DocuSign's
2
+ # sdk-esign-api JAR ships no keep rules. Keeping the whole esign package
3
+ # fails R8 on the missing org.apache.oltu classes, so only the models.
4
+ -keep class com.docusign.esign.model.** { *; }
5
+
6
+ # DocuSignError.native.domain carries the Android exception class name.
7
+ # Keeps this module's names readable when the app obfuscates.
8
+ -keepnames class expo.modules.docusign.**