react-native-docusign 1.0.4 → 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 +50 -0
  2. package/README.md +198 -71
  3. package/android/build.gradle +7 -7
  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 +435 -58
  7. package/android/src/main/java/expo/modules/docusign/DocuSignModule.kt +66 -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 +25 -5
  15. package/build/DocuSignModule.d.ts.map +1 -1
  16. package/build/DocuSignModule.js.map +1 -1
  17. package/build/api.d.ts +39 -6
  18. package/build/api.d.ts.map +1 -1
  19. package/build/api.js +102 -18
  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 +219 -98
  32. package/ios/DocuSignModule.swift +43 -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
@@ -80,7 +80,7 @@ internal final class DocuSignManager: NSObject {
80
80
  }
81
81
 
82
82
  guard let url = URL(string: host) else {
83
- throw NotInitializedException()
83
+ throw InitializeFailedException("invalid DocuSign host URL \(host)")
84
84
  }
85
85
 
86
86
  self.integratorKey = integratorKey
@@ -88,7 +88,7 @@ internal final class DocuSignManager: NSObject {
88
88
  self.environment = environment
89
89
 
90
90
  let dispatchSetup: () -> Void = {
91
- var configurations = DSMManager.defaultConfigurations() ?? [:]
91
+ var configurations = DSMManager.defaultConfigurations()
92
92
  if options.disablePoweredByBranding {
93
93
  configurations[DSM_SETUP_POWERED_BY_DOCUSIGN_ENABLED] = DSM_SETUP_FALSE_VALUE
94
94
  }
@@ -318,7 +318,25 @@ internal final class DocuSignManager: NSObject {
318
318
  /// `loginWithAccessToken` runs. If you need to isolate DocuSign's WebKit
319
319
  /// state from the rest of your app, use a non-default data store for those
320
320
  /// other WebViews.
321
+ /// Hops to the main thread before touching any DSMManager or WebKit API.
322
+ ///
323
+ /// Expo dispatches a synchronous `AsyncFunction` body on a serial background queue, so every
324
+ /// caller that originates in a JS call arrives here off-main. This is the only method reaching
325
+ /// `DSMManager.clearAllWebCookies()` and `WKWebsiteDataStore` directly, so one guard here covers
326
+ /// `performLogin`, `endSigningSession` and `reset` rather than each hopping for itself. The
327
+ /// completion is dispatched on main below, so callers may touch DSMManager from it.
321
328
  private func clearWebCookiesAsync(completion: @escaping () -> Void) {
329
+ guard Thread.isMainThread else {
330
+ DispatchQueue.main.async { [weak self] in
331
+ guard let self = self else {
332
+ completion()
333
+ return
334
+ }
335
+ self.clearWebCookiesAsync(completion: completion)
336
+ }
337
+ return
338
+ }
339
+
322
340
  DSMManager.clearAllWebCookies()
323
341
  let dataStore = WKWebsiteDataStore.default()
324
342
  let types = WKWebsiteDataStore.allWebsiteDataTypes()
@@ -328,6 +346,9 @@ internal final class DocuSignManager: NSObject {
328
346
  }
329
347
  }
330
348
 
349
+ /// The SDK's login error rarely says why. A second call to `/oauth/userinfo` with the same token
350
+ /// separates an expired or wrongly scoped token (401 or 403) from a valid token the SDK still
351
+ /// refuses, which points at DocuSign admin configuration rather than the backend.
331
352
  private func classifyLoginFailure(
332
353
  accessToken: String,
333
354
  sdkError: Error,
@@ -335,37 +356,42 @@ internal final class DocuSignManager: NSObject {
335
356
  integratorKey: String,
336
357
  completion: @escaping (Result<DocuSignAccountInfo, Error>) -> Void
337
358
  ) {
338
- let sdkMsg = (sdkError as NSError).localizedDescription
339
- let sdkCode = (sdkError as NSError).code
340
-
341
359
  probeUserInfoStatus(accessToken: accessToken) { probe in
342
- let enrichedMsg: String
360
+ var details = FailureDetails(error: sdkError)
361
+ let summary: String
343
362
  switch probe {
344
- case .ok:
345
- enrichedMsg = "SDK rejected a valid token. Likely causes: Mobile SDK not enabled for integration key \(integratorKey), or iOS bundle ID not whitelisted in DocuSign admin. Contact DocuSign support. (SDK: \(sdkMsg)) | \(diagnostic)"
346
- case .unauthorized:
347
- enrichedMsg = "Access token rejected by DocuSign /oauth/userinfo. Re-mint via JWT Bearer Grant with scope=signature impersonation. (SDK: \(sdkMsg)) | \(diagnostic)"
348
- case .network(let netMsg):
349
- enrichedMsg = "\(sdkMsg) (userinfo probe network error: \(netMsg)) | \(diagnostic)"
363
+ case .response(let status, let body):
364
+ details.setResponse(status: status, body: body)
365
+ if (200..<300).contains(status) {
366
+ summary = "DocuSign rejected a valid access token. Check that AppIdentifierPrefix is set in Info.plist, that the Mobile SDK is enabled for integration key \(integratorKey), and that the iOS bundle ID is allowed in DocuSign admin."
367
+ } else if status == 401 || status == 403 {
368
+ summary = "DocuSign rejected the access token. Mint a new token with the signature and impersonation scopes."
369
+ } else {
370
+ summary = "DocuSign login failed, and the userinfo check returned HTTP \(status)."
371
+ }
372
+ case .transportFailed(let error):
373
+ details.setUnderlyingIfAbsent(error)
374
+ summary = "DocuSign login failed, and the userinfo check could not reach DocuSign."
375
+ case .unavailable(let reason):
376
+ summary = "DocuSign login failed, and the userinfo check could not run: \(reason)."
350
377
  }
351
- let enriched = NSError(
352
- domain: "DocuSign",
353
- code: sdkCode,
354
- userInfo: [NSLocalizedDescriptionKey: enrichedMsg]
355
- )
356
- completion(.failure(enriched))
378
+ completion(.failure(DocuSignFailure(
379
+ code: "login_failed",
380
+ message: "\(summary) (\(diagnostic))",
381
+ details: details
382
+ )))
357
383
  }
358
384
  }
359
385
 
360
386
  private enum UserInfoProbe {
361
- case ok
362
- case unauthorized
363
- case network(String)
387
+ case response(status: Int, body: Data?)
388
+ case transportFailed(Error)
389
+ case unavailable(String)
364
390
  }
365
391
 
366
392
  private func probeUserInfoStatus(accessToken: String, completion: @escaping (UserInfoProbe) -> Void) {
367
393
  guard let base = oauthBaseURL() else {
368
- completion(.network("no oauth base URL"))
394
+ completion(.unavailable("no OAuth base URL"))
369
395
  return
370
396
  }
371
397
  let url = base.appendingPathComponent("oauth/userinfo")
@@ -375,22 +401,16 @@ internal final class DocuSignManager: NSObject {
375
401
  request.setValue("application/json", forHTTPHeaderField: "Accept")
376
402
  request.timeoutInterval = 10
377
403
 
378
- URLSession.shared.dataTask(with: request) { _, response, error in
404
+ URLSession.shared.dataTask(with: request) { data, response, error in
379
405
  if let error = error {
380
- completion(.network(error.localizedDescription))
406
+ completion(.transportFailed(error))
381
407
  return
382
408
  }
383
409
  guard let http = response as? HTTPURLResponse else {
384
- completion(.network("no HTTP response"))
410
+ completion(.unavailable("no HTTP response"))
385
411
  return
386
412
  }
387
- if (200..<300).contains(http.statusCode) {
388
- completion(.ok)
389
- } else if http.statusCode == 401 || http.statusCode == 403 {
390
- completion(.unauthorized)
391
- } else {
392
- completion(.network("userinfo HTTP \(http.statusCode)"))
393
- }
413
+ completion(.response(status: http.statusCode, body: data))
394
414
  }.resume()
395
415
  }
396
416
 
@@ -431,7 +451,7 @@ internal final class DocuSignManager: NSObject {
431
451
  completion: @escaping (Result<ResolvedUserInfo, Error>) -> Void
432
452
  ) {
433
453
  guard let base = oauthBaseURL() else {
434
- completion(.failure(LoginFailedException("Could not derive OAuth base URL")))
454
+ completion(.failure(Self.userInfoFailure("Could not derive the DocuSign OAuth base URL.", FailureDetails())))
435
455
  return
436
456
  }
437
457
  let url = base.appendingPathComponent("oauth/userinfo")
@@ -443,22 +463,29 @@ internal final class DocuSignManager: NSObject {
443
463
 
444
464
  URLSession.shared.dataTask(with: request) { data, response, error in
445
465
  if let error = error {
446
- completion(.failure(LoginFailedException("userinfo request failed: \(error.localizedDescription)")))
466
+ completion(.failure(Self.userInfoFailure(
467
+ "The DocuSign userinfo request failed: \(error.localizedDescription)",
468
+ FailureDetails(error: error)
469
+ )))
447
470
  return
448
471
  }
449
472
  guard let http = response as? HTTPURLResponse else {
450
- completion(.failure(LoginFailedException("userinfo: no HTTP response")))
473
+ completion(.failure(Self.userInfoFailure("The DocuSign userinfo request returned no HTTP response.", FailureDetails())))
451
474
  return
452
475
  }
453
476
  guard (200..<300).contains(http.statusCode), let data = data else {
454
- let snippet = data.flatMap { String(data: $0, encoding: .utf8) } ?? ""
455
- completion(.failure(LoginFailedException("userinfo HTTP \(http.statusCode): \(snippet.prefix(200))")))
477
+ var details = FailureDetails()
478
+ details.setResponse(status: http.statusCode, body: data)
479
+ completion(.failure(Self.userInfoFailure(
480
+ "The DocuSign userinfo request returned HTTP \(http.statusCode).",
481
+ details
482
+ )))
456
483
  return
457
484
  }
458
485
  do {
459
486
  let decoded = try JSONDecoder().decode(UserInfoPayload.self, from: data)
460
487
  guard let account = Self.pickAccount(from: decoded.accounts, preferredId: preferredAccountId) else {
461
- completion(.failure(LoginFailedException("userinfo: no accounts in response")))
488
+ completion(.failure(Self.userInfoFailure("The DocuSign userinfo response lists no accounts.", FailureDetails())))
462
489
  return
463
490
  }
464
491
  let host = account.base_uri.hasSuffix("/restapi") ? account.base_uri : account.base_uri + "/restapi"
@@ -471,11 +498,18 @@ internal final class DocuSignManager: NSObject {
471
498
  )
472
499
  completion(.success(resolved))
473
500
  } catch {
474
- completion(.failure(LoginFailedException("userinfo decode error: \(error.localizedDescription)")))
501
+ completion(.failure(Self.userInfoFailure(
502
+ "The DocuSign userinfo response could not be read.",
503
+ FailureDetails(error: error)
504
+ )))
475
505
  }
476
506
  }.resume()
477
507
  }
478
508
 
509
+ private static func userInfoFailure(_ message: String, _ details: FailureDetails) -> DocuSignFailure {
510
+ DocuSignFailure(code: "login_failed", message: message, details: details)
511
+ }
512
+
479
513
  private static func pickAccount(from accounts: [UserInfoAccount], preferredId: String) -> UserInfoAccount? {
480
514
  if !preferredId.isEmpty, let match = accounts.first(where: { $0.account_id == preferredId }) {
481
515
  return match
@@ -526,7 +560,6 @@ internal final class DocuSignManager: NSObject {
526
560
  /// free.
527
561
  func endSigningSession(completion: @escaping () -> Void) {
528
562
  // Resolve any in-flight signing promise so the JS side does not hang.
529
- var pendingResolved = false
530
563
  stateQueue.sync {
531
564
  if let pending = pendingCompletion {
532
565
  let outcome = SigningOutcome(
@@ -538,10 +571,8 @@ internal final class DocuSignManager: NSObject {
538
571
  pendingCompletion = nil
539
572
  currentEnvelopeId = nil
540
573
  DispatchQueue.main.async { pending(.success(outcome)) }
541
- pendingResolved = true
542
574
  }
543
575
  }
544
- _ = pendingResolved // silence unused-warning; kept for future telemetry
545
576
 
546
577
  clearWebCookiesAsync { [weak self] in
547
578
  guard let self = self else {
@@ -554,6 +585,66 @@ internal final class DocuSignManager: NSObject {
554
585
  }
555
586
  }
556
587
 
588
+ /// Full SDK teardown: a heavier counterpart to `endSigningSession`. Resolves
589
+ /// any in-flight signing promise as `cancelled`, wipes WebKit data (cookies,
590
+ /// service workers, fetch cache, etc.), calls `DSMManager.logout()`, removes
591
+ /// notification observers, and resets every internal state flag including
592
+ /// `_isInitialized` and `_observersRegistered`. The next `initialize()` call
593
+ /// will run `DSMManager.setup(withConfiguration:)` again, giving the SDK a
594
+ /// completely fresh slate.
595
+ ///
596
+ /// Use this when you want a hard reset between flows (e.g. error recovery,
597
+ /// switching DocuSign accounts, or after an app-level logout). For routine
598
+ /// teardown between consecutive captive signing flows on the same auth,
599
+ /// prefer `endSigningSession`, which keeps the SDK initialized and skips
600
+ /// the observer churn.
601
+ ///
602
+ /// Safe to call when the SDK was never initialized: returns immediately
603
+ /// without touching DSMManager.
604
+ func reset(completion: @escaping () -> Void) {
605
+ stateQueue.sync {
606
+ if let pending = pendingCompletion {
607
+ let outcome = SigningOutcome(
608
+ status: "cancelled",
609
+ envelopeId: currentEnvelopeId ?? "",
610
+ errorCode: nil,
611
+ errorMessage: "reset"
612
+ )
613
+ pendingCompletion = nil
614
+ currentEnvelopeId = nil
615
+ DispatchQueue.main.async { pending(.success(outcome)) }
616
+ }
617
+ }
618
+
619
+ let needsTeardown = stateQueue.sync { _isInitialized || _hasLoggedIn }
620
+ guard needsTeardown else {
621
+ completion()
622
+ return
623
+ }
624
+
625
+ // No main-thread hop here. clearWebCookiesAsync guards itself, and re-entering reset() from
626
+ // main would run the pending-cancellation block above a second time, cancelling any session
627
+ // that claimed the slot in between.
628
+ clearWebCookiesAsync { [weak self] in
629
+ guard let self = self else { completion(); return }
630
+ _ = DSMManager.logout()
631
+ NotificationCenter.default.removeObserver(self)
632
+ // Use stateQueue.async (not sync) for the state reset. We are on main
633
+ // here (clearWebCookiesAsync's completion is dispatched on main), and a
634
+ // nested stateQueue.sync from main while another thread holds the queue
635
+ // is the classic deadlock recipe. async serializes the writes safely
636
+ // without blocking, then hops back to main to fire the completion.
637
+ self.stateQueue.async {
638
+ self._isInitialized = false
639
+ self._hasLoggedIn = false
640
+ self._integratorKey = nil
641
+ self._hostURL = nil
642
+ self._observersRegistered = false
643
+ DispatchQueue.main.async { completion() }
644
+ }
645
+ }
646
+ }
647
+
557
648
  func presentCaptiveSigning(
558
649
  envelopeId: String,
559
650
  recipientUserName: String,
@@ -569,6 +660,33 @@ internal final class DocuSignManager: NSObject {
569
660
  throw NotLoggedInException()
570
661
  }
571
662
 
663
+ try claimPendingSlot(envelopeId: envelopeId, completion: completion)
664
+
665
+ DispatchQueue.main.async { [weak self] in
666
+ guard let self = self else { return }
667
+ guard let presentingViewController = self.presentingViewControllerOrSettle() else { return }
668
+ let envelopesManager = DSMEnvelopesManager()
669
+ envelopesManager.presentCaptiveSigning(
670
+ withPresenting: presentingViewController,
671
+ envelopeId: envelopeId,
672
+ recipientUserName: recipientUserName,
673
+ recipientEmail: recipientEmail,
674
+ recipientClientUserId: recipientClientUserId,
675
+ animated: true,
676
+ completion: { [weak self] (_: UIViewController?, error: Error?) in
677
+ guard let self = self, let error = error else { return }
678
+ self.resolvePending(.failure(Self.openFailure(error, envelopeId: envelopeId)))
679
+ // Success/cancel path is driven by DSMSigningCompletedNotification / DSMSigningCancelledNotification
680
+ }
681
+ )
682
+ }
683
+ }
684
+
685
+ /// Claims the single pending-signing slot, or throws when a ceremony is already open.
686
+ private func claimPendingSlot(
687
+ envelopeId: String,
688
+ completion: @escaping (Result<SigningOutcome, Error>) -> Void
689
+ ) throws {
572
690
  var alreadyInFlight = false
573
691
  stateQueue.sync {
574
692
  if pendingCompletion != nil {
@@ -579,32 +697,41 @@ internal final class DocuSignManager: NSObject {
579
697
  }
580
698
  }
581
699
  if alreadyInFlight {
582
- throw SigningFailedException("A signing session is already in progress")
700
+ throw SigningInProgressException()
583
701
  }
702
+ }
584
703
 
585
- guard let presentingViewController = Self.topmostViewController() else {
586
- resolvePending(.failure(PresentationException("Could not find a view controller to present from")))
587
- throw PresentationException("Could not find a view controller to present from")
704
+ /// Looks the presenter up on the main thread, where UIKit requires it. Doing this on the queue
705
+ /// the JS call arrived on read `UIApplication.shared` off-main. Without a presenter the slot is
706
+ /// settled as a caller mistake, so the promise never hangs.
707
+ private func presentingViewControllerOrSettle() -> UIViewController? {
708
+ if let presentingViewController = Self.topmostViewController() {
709
+ return presentingViewController
588
710
  }
711
+ resolvePending(.failure(PresentationException("Could not find a view controller to present from")))
712
+ return nil
713
+ }
589
714
 
590
- DispatchQueue.main.async {
591
- let envelopesManager = DSMEnvelopesManager()
592
- envelopesManager.presentCaptiveSigning(
593
- withPresenting: presentingViewController,
594
- envelopeId: envelopeId,
595
- recipientUserName: recipientUserName,
596
- recipientEmail: recipientEmail,
597
- recipientClientUserId: recipientClientUserId,
598
- animated: true,
599
- completion: { [weak self] (_: UIViewController?, error: Error?) in
600
- guard let self = self else { return }
601
- if let error = error {
602
- self.resolvePending(.failure(error))
603
- }
604
- // Success/cancel path is driven by DSMSigningCompletedNotification / DSMSigningCancelledNotification
605
- }
606
- )
715
+ private static func openFailure(_ error: Error, envelopeId: String) -> DocuSignFailure {
716
+ DocuSignFailure(
717
+ code: "signing_failed",
718
+ message: "DocuSign could not open the signing ceremony: \((error as NSError).localizedDescription)",
719
+ details: FailureDetails(error: error),
720
+ envelopeId: envelopeId
721
+ )
722
+ }
723
+
724
+ /// Guards the URL handed to the SDK's URL overload.
725
+ ///
726
+ /// `DSMEnvelopesManager.presentCaptiveSigning(withPresenting:signingUrl:...)` validates nothing
727
+ /// and presents unconditionally, so a blank or non-https URL renders an empty signing controller
728
+ /// whose completion never fires and leaves the promise unsettled. `CaptiveSigningUrlRecord`
729
+ /// defaults `signingUrl` to "", so an omitted field reaches here as a blank string.
730
+ private static func isHttpsUrl(_ url: String) -> Bool {
731
+ guard let components = URLComponents(string: url) else {
732
+ return false
607
733
  }
734
+ return components.scheme?.lowercased() == "https" && !(components.host ?? "").isEmpty
608
735
  }
609
736
 
610
737
  /// Presents captive signing from a pre-minted DocuSign recipient-view URL.
@@ -622,25 +749,17 @@ internal final class DocuSignManager: NSObject {
622
749
  throw NotInitializedException()
623
750
  }
624
751
 
625
- var alreadyInFlight = false
626
- stateQueue.sync {
627
- if pendingCompletion != nil {
628
- alreadyInFlight = true
629
- } else {
630
- currentEnvelopeId = envelopeId
631
- pendingCompletion = completion
632
- }
633
- }
634
- if alreadyInFlight {
635
- throw SigningFailedException("A signing session is already in progress")
752
+ // Ahead of the pendingCompletion claim on purpose: a rejected URL must not occupy the slot, or
753
+ // a later valid call would be refused as "already in progress".
754
+ guard Self.isHttpsUrl(signingUrl) else {
755
+ throw InvalidSigningUrlException()
636
756
  }
637
757
 
638
- guard let presentingViewController = Self.topmostViewController() else {
639
- resolvePending(.failure(PresentationException("Could not find a view controller to present from")))
640
- throw PresentationException("Could not find a view controller to present from")
641
- }
758
+ try claimPendingSlot(envelopeId: envelopeId, completion: completion)
642
759
 
643
- DispatchQueue.main.async {
760
+ DispatchQueue.main.async { [weak self] in
761
+ guard let self = self else { return }
762
+ guard let presentingViewController = self.presentingViewControllerOrSettle() else { return }
644
763
  let envelopesManager = DSMEnvelopesManager()
645
764
  envelopesManager.presentCaptiveSigning(
646
765
  withPresenting: presentingViewController,
@@ -649,10 +768,8 @@ internal final class DocuSignManager: NSObject {
649
768
  recipientId: recipientId,
650
769
  animated: true,
651
770
  completion: { [weak self] (_: UIViewController?, error: Error?) in
652
- guard let self = self else { return }
653
- if let error = error {
654
- self.resolvePending(.failure(error))
655
- }
771
+ guard let self = self, let error = error else { return }
772
+ self.resolvePending(.failure(Self.openFailure(error, envelopeId: envelopeId)))
656
773
  }
657
774
  )
658
775
  }
@@ -663,6 +780,16 @@ internal final class DocuSignManager: NSObject {
663
780
  let envelopeId: String
664
781
  let errorCode: String?
665
782
  let errorMessage: String?
783
+
784
+ var payload: [String: Any] {
785
+ let values: [String: Any?] = [
786
+ "status": status,
787
+ "envelopeId": envelopeId,
788
+ "errorCode": errorCode,
789
+ "errorMessage": errorMessage
790
+ ]
791
+ return values.compactMapValues { $0 }
792
+ }
666
793
  }
667
794
 
668
795
  private func resolvePending(_ result: Result<SigningOutcome, Error>) {
@@ -724,22 +851,16 @@ internal final class DocuSignManager: NSObject {
724
851
  let envelopeId = envelopeId(from: notification)
725
852
  let userInfo = notification.userInfo
726
853
 
854
+ // The SDK reports some failures through its cancel notification. Settling them as a failure
855
+ // keeps one rule for every consumer: resolved means completed or cancelled, and each failure
856
+ // rejects with its details. The module emits onSigningError when it settles the failure.
727
857
  if let sdkError = userInfo?[DSMErrorKey] as? Error {
728
- let nsErr = sdkError as NSError
729
- let errorMessage = nsErr.localizedDescription
730
- let errorCode = String(nsErr.code)
731
- let outcome = SigningOutcome(
732
- status: "error",
733
- envelopeId: envelopeId,
734
- errorCode: errorCode,
735
- errorMessage: errorMessage
736
- )
737
- module?.sendEvent("onSigningError", [
738
- "envelopeId": envelopeId,
739
- "errorCode": errorCode,
740
- "errorMessage": errorMessage
741
- ])
742
- resolvePending(.success(outcome))
858
+ resolvePending(.failure(DocuSignFailure(
859
+ code: "signing_failed",
860
+ message: "DocuSign ended the signing ceremony with an error: \((sdkError as NSError).localizedDescription)",
861
+ details: FailureDetails(error: sdkError),
862
+ envelopeId: envelopeId
863
+ )))
743
864
  return
744
865
  }
745
866
 
@@ -56,7 +56,7 @@ public class DocuSignModule: Module {
56
56
  )
57
57
  promise.resolve(nil)
58
58
  } catch {
59
- promise.reject(error)
59
+ self.settleFailure(error, envelopeId: nil, promise: promise)
60
60
  }
61
61
  }
62
62
 
@@ -74,21 +74,20 @@ public class DocuSignModule: Module {
74
74
  switch result {
75
75
  case .success(let info):
76
76
  promise.resolve([
77
- "accountId": info.accountId,
78
- "userId": info.userId,
79
- "userName": info.userName,
80
- "email": info.email
77
+ "status": "success",
78
+ "account": [
79
+ "accountId": info.accountId,
80
+ "userId": info.userId,
81
+ "userName": info.userName,
82
+ "email": info.email
83
+ ]
81
84
  ])
82
85
  case .failure(let error):
83
- self.sendEvent("onSigningError", [
84
- "errorCode": "login_failed",
85
- "errorMessage": error.localizedDescription
86
- ])
87
- promise.reject(LoginFailedException(error.localizedDescription))
86
+ self.settleFailure(error, envelopeId: nil, promise: promise)
88
87
  }
89
88
  }
90
89
  } catch {
91
- promise.reject(error)
90
+ self.settleFailure(error, envelopeId: nil, promise: promise)
92
91
  }
93
92
  }
94
93
 
@@ -102,23 +101,13 @@ public class DocuSignModule: Module {
102
101
  ) { result in
103
102
  switch result {
104
103
  case .success(let outcome):
105
- promise.resolve([
106
- "status": outcome.status,
107
- "envelopeId": outcome.envelopeId,
108
- "errorCode": outcome.errorCode as Any,
109
- "errorMessage": outcome.errorMessage as Any
110
- ])
104
+ promise.resolve(outcome.payload)
111
105
  case .failure(let error):
112
- self.sendEvent("onSigningError", [
113
- "envelopeId": params.envelopeId,
114
- "errorCode": "signing_failed",
115
- "errorMessage": error.localizedDescription
116
- ])
117
- promise.reject(SigningFailedException(error.localizedDescription))
106
+ self.settleFailure(error, envelopeId: params.envelopeId, promise: promise)
118
107
  }
119
108
  }
120
109
  } catch {
121
- promise.reject(error)
110
+ self.settleFailure(error, envelopeId: params.envelopeId, promise: promise)
122
111
  }
123
112
  }
124
113
 
@@ -131,23 +120,13 @@ public class DocuSignModule: Module {
131
120
  ) { result in
132
121
  switch result {
133
122
  case .success(let outcome):
134
- promise.resolve([
135
- "status": outcome.status,
136
- "envelopeId": outcome.envelopeId,
137
- "errorCode": outcome.errorCode as Any,
138
- "errorMessage": outcome.errorMessage as Any
139
- ])
123
+ promise.resolve(outcome.payload)
140
124
  case .failure(let error):
141
- self.sendEvent("onSigningError", [
142
- "envelopeId": params.envelopeId,
143
- "errorCode": "signing_failed",
144
- "errorMessage": error.localizedDescription
145
- ])
146
- promise.reject(SigningFailedException(error.localizedDescription))
125
+ self.settleFailure(error, envelopeId: params.envelopeId, promise: promise)
147
126
  }
148
127
  }
149
128
  } catch {
150
- promise.reject(error)
129
+ self.settleFailure(error, envelopeId: params.envelopeId, promise: promise)
151
130
  }
152
131
  }
153
132
 
@@ -165,5 +144,32 @@ public class DocuSignModule: Module {
165
144
  promise.resolve(nil)
166
145
  }
167
146
  }
147
+
148
+ AsyncFunction("reset") { (promise: Promise) in
149
+ DocuSignManager.shared.reset {
150
+ promise.resolve(nil)
151
+ }
152
+ }
153
+ }
154
+
155
+ /// The one place a failure is settled.
156
+ ///
157
+ /// A runtime failure resolves with its details, because a rejection reaches JS with only a code
158
+ /// and a message and would drop them. A caller mistake rejects. The message comes from
159
+ /// `CodedError.description`, since Expo's `Exception` is not a `LocalizedError` and its
160
+ /// `localizedDescription` is Foundation's generic text.
161
+ private func settleFailure(_ error: Error, envelopeId: String?, promise: Promise) {
162
+ if let failure = error as? DocuSignFailure {
163
+ var payload = failure.payload(fallbackEnvelopeId: envelopeId)
164
+ sendEvent("onSigningError", payload)
165
+ payload["status"] = "error"
166
+ promise.resolve(payload)
167
+ return
168
+ }
169
+ let codedError = error as? CodedError
170
+ promise.reject(
171
+ codedError?.code ?? "unexpected",
172
+ codedError?.description ?? error.localizedDescription
173
+ )
168
174
  }
169
175
  }
@@ -18,7 +18,7 @@ Pod::Spec.new do |s|
18
18
  s.static_framework = true
19
19
 
20
20
  s.dependency 'ExpoModulesCore'
21
- s.dependency 'DocuSign', '~> 4.1.1'
21
+ s.dependency 'DocuSign', '~> 4.3.0'
22
22
 
23
23
  s.pod_target_xcconfig = {
24
24
  'DEFINES_MODULE' => 'YES',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-docusign",
3
- "version": "1.0.4",
3
+ "version": "2.0.0",
4
4
  "description": "React Native / Expo native module wrapping DocuSign iOS and Android SDKs for in-app captive signing",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -17,6 +17,8 @@
17
17
  ],
18
18
  "scripts": {
19
19
  "build": "tsc -p tsconfig.build.json && tsc -p plugin/tsconfig.build.json",
20
+ "lint": "eslint . --max-warnings 0",
21
+ "typecheck:examples": "tsc -p tsconfig.examples.json && node scripts/check-doc-examples.js",
20
22
  "test": "jest",
21
23
  "test:coverage": "jest --coverage",
22
24
  "prepublishOnly": "npm run build && npm test"
@@ -40,13 +42,20 @@
40
42
  "license": "MIT",
41
43
  "homepage": "https://github.com/IronTony/react-native-docusign",
42
44
  "devDependencies": {
45
+ "@amplitude/analytics-react-native": "^1.8.0",
43
46
  "@react-native/jest-preset": "^0.85.2",
47
+ "@sentry/react-native": "^8.26.0",
44
48
  "@testing-library/react-native": "^13.3.3",
45
- "@types/adm-zip": "^0.5.8",
46
49
  "@types/jest": "^29.5.14",
47
50
  "@types/node": "^20.19.39",
51
+ "eslint": "^9.39.5",
52
+ "eslint-config-universe": "^16.0.0",
53
+ "i18next": "^26.4.2",
48
54
  "jest": "^29.7.0",
49
55
  "jest-expo": "^55.0.17",
56
+ "newrelic-react-native-agent": "^1.9.0",
57
+ "prettier": "^3.9.6",
58
+ "react-i18next": "^17.0.13",
50
59
  "react-test-renderer": "^19.2.5"
51
60
  },
52
61
  "peerDependencies": {
@@ -55,6 +64,6 @@
55
64
  "react-native": "*"
56
65
  },
57
66
  "dependencies": {
58
- "adm-zip": "^0.5.17"
67
+ "adm-zip": "^0.6.1"
59
68
  }
60
69
  }