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
@@ -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 {
@@ -591,14 +622,9 @@ internal final class DocuSignManager: NSObject {
591
622
  return
592
623
  }
593
624
 
594
- if !Thread.isMainThread {
595
- DispatchQueue.main.async { [weak self] in
596
- guard let self = self else { completion(); return }
597
- self.reset(completion: completion)
598
- }
599
- return
600
- }
601
-
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.
602
628
  clearWebCookiesAsync { [weak self] in
603
629
  guard let self = self else { completion(); return }
604
630
  _ = DSMManager.logout()
@@ -634,6 +660,33 @@ internal final class DocuSignManager: NSObject {
634
660
  throw NotLoggedInException()
635
661
  }
636
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 {
637
690
  var alreadyInFlight = false
638
691
  stateQueue.sync {
639
692
  if pendingCompletion != nil {
@@ -644,32 +697,41 @@ internal final class DocuSignManager: NSObject {
644
697
  }
645
698
  }
646
699
  if alreadyInFlight {
647
- throw SigningFailedException("A signing session is already in progress")
700
+ throw SigningInProgressException()
648
701
  }
702
+ }
649
703
 
650
- guard let presentingViewController = Self.topmostViewController() else {
651
- resolvePending(.failure(PresentationException("Could not find a view controller to present from")))
652
- 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
653
710
  }
711
+ resolvePending(.failure(PresentationException("Could not find a view controller to present from")))
712
+ return nil
713
+ }
654
714
 
655
- DispatchQueue.main.async {
656
- let envelopesManager = DSMEnvelopesManager()
657
- envelopesManager.presentCaptiveSigning(
658
- withPresenting: presentingViewController,
659
- envelopeId: envelopeId,
660
- recipientUserName: recipientUserName,
661
- recipientEmail: recipientEmail,
662
- recipientClientUserId: recipientClientUserId,
663
- animated: true,
664
- completion: { [weak self] (_: UIViewController?, error: Error?) in
665
- guard let self = self else { return }
666
- if let error = error {
667
- self.resolvePending(.failure(error))
668
- }
669
- // Success/cancel path is driven by DSMSigningCompletedNotification / DSMSigningCancelledNotification
670
- }
671
- )
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
672
733
  }
734
+ return components.scheme?.lowercased() == "https" && !(components.host ?? "").isEmpty
673
735
  }
674
736
 
675
737
  /// Presents captive signing from a pre-minted DocuSign recipient-view URL.
@@ -687,25 +749,17 @@ internal final class DocuSignManager: NSObject {
687
749
  throw NotInitializedException()
688
750
  }
689
751
 
690
- var alreadyInFlight = false
691
- stateQueue.sync {
692
- if pendingCompletion != nil {
693
- alreadyInFlight = true
694
- } else {
695
- currentEnvelopeId = envelopeId
696
- pendingCompletion = completion
697
- }
698
- }
699
- if alreadyInFlight {
700
- 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()
701
756
  }
702
757
 
703
- guard let presentingViewController = Self.topmostViewController() else {
704
- resolvePending(.failure(PresentationException("Could not find a view controller to present from")))
705
- throw PresentationException("Could not find a view controller to present from")
706
- }
758
+ try claimPendingSlot(envelopeId: envelopeId, completion: completion)
707
759
 
708
- 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 }
709
763
  let envelopesManager = DSMEnvelopesManager()
710
764
  envelopesManager.presentCaptiveSigning(
711
765
  withPresenting: presentingViewController,
@@ -714,10 +768,8 @@ internal final class DocuSignManager: NSObject {
714
768
  recipientId: recipientId,
715
769
  animated: true,
716
770
  completion: { [weak self] (_: UIViewController?, error: Error?) in
717
- guard let self = self else { return }
718
- if let error = error {
719
- self.resolvePending(.failure(error))
720
- }
771
+ guard let self = self, let error = error else { return }
772
+ self.resolvePending(.failure(Self.openFailure(error, envelopeId: envelopeId)))
721
773
  }
722
774
  )
723
775
  }
@@ -728,6 +780,16 @@ internal final class DocuSignManager: NSObject {
728
780
  let envelopeId: String
729
781
  let errorCode: String?
730
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
+ }
731
793
  }
732
794
 
733
795
  private func resolvePending(_ result: Result<SigningOutcome, Error>) {
@@ -789,22 +851,16 @@ internal final class DocuSignManager: NSObject {
789
851
  let envelopeId = envelopeId(from: notification)
790
852
  let userInfo = notification.userInfo
791
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.
792
857
  if let sdkError = userInfo?[DSMErrorKey] as? Error {
793
- let nsErr = sdkError as NSError
794
- let errorMessage = nsErr.localizedDescription
795
- let errorCode = String(nsErr.code)
796
- let outcome = SigningOutcome(
797
- status: "error",
798
- envelopeId: envelopeId,
799
- errorCode: errorCode,
800
- errorMessage: errorMessage
801
- )
802
- module?.sendEvent("onSigningError", [
803
- "envelopeId": envelopeId,
804
- "errorCode": errorCode,
805
- "errorMessage": errorMessage
806
- ])
807
- 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
+ )))
808
864
  return
809
865
  }
810
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
 
@@ -172,4 +151,25 @@ public class DocuSignModule: Module {
172
151
  }
173
152
  }
174
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
+ )
174
+ }
175
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.5",
3
+ "version": "2.0.1",
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
  }