react-native-docusign 1.0.5 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -0
- package/README.md +181 -70
- package/android/build.gradle +5 -5
- package/android/src/main/java/expo/modules/docusign/DocuSignError.kt +30 -10
- package/android/src/main/java/expo/modules/docusign/DocuSignFailure.kt +145 -0
- package/android/src/main/java/expo/modules/docusign/DocuSignManager.kt +407 -58
- package/android/src/main/java/expo/modules/docusign/DocuSignModule.kt +61 -42
- package/build/DocuSign.types.d.ts +39 -0
- package/build/DocuSign.types.d.ts.map +1 -1
- package/build/DocuSignError.d.ts +86 -0
- package/build/DocuSignError.d.ts.map +1 -0
- package/build/DocuSignError.js +210 -0
- package/build/DocuSignError.js.map +1 -0
- package/build/DocuSignModule.d.ts +24 -5
- package/build/DocuSignModule.d.ts.map +1 -1
- package/build/DocuSignModule.js.map +1 -1
- package/build/api.d.ts +24 -6
- package/build/api.d.ts.map +1 -1
- package/build/api.js +84 -17
- package/build/api.js.map +1 -1
- package/build/index.d.ts +2 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/useDocuSignSigning.d.ts +2 -1
- package/build/useDocuSignSigning.d.ts.map +1 -1
- package/build/useDocuSignSigning.js +20 -6
- package/build/useDocuSignSigning.js.map +1 -1
- package/ios/DocuSignError.swift +45 -10
- package/ios/DocuSignFailure.swift +104 -0
- package/ios/DocuSignManager.swift +162 -106
- package/ios/DocuSignModule.swift +37 -37
- package/ios/ReactNativeDocuSign.podspec +1 -1
- package/package.json +12 -3
- package/plugin/build/index.js +21 -41
- 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
|
|
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
|
-
|
|
360
|
+
var details = FailureDetails(error: sdkError)
|
|
361
|
+
let summary: String
|
|
343
362
|
switch probe {
|
|
344
|
-
case .
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
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
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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
|
|
362
|
-
case
|
|
363
|
-
case
|
|
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(.
|
|
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) {
|
|
404
|
+
URLSession.shared.dataTask(with: request) { data, response, error in
|
|
379
405
|
if let error = error {
|
|
380
|
-
completion(.
|
|
406
|
+
completion(.transportFailed(error))
|
|
381
407
|
return
|
|
382
408
|
}
|
|
383
409
|
guard let http = response as? HTTPURLResponse else {
|
|
384
|
-
completion(.
|
|
410
|
+
completion(.unavailable("no HTTP response"))
|
|
385
411
|
return
|
|
386
412
|
}
|
|
387
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
455
|
-
|
|
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(
|
|
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(
|
|
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
|
-
|
|
595
|
-
|
|
596
|
-
|
|
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
|
|
700
|
+
throw SigningInProgressException()
|
|
648
701
|
}
|
|
702
|
+
}
|
|
649
703
|
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
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
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
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
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
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
|
|
package/ios/DocuSignModule.swift
CHANGED
|
@@ -56,7 +56,7 @@ public class DocuSignModule: Module {
|
|
|
56
56
|
)
|
|
57
57
|
promise.resolve(nil)
|
|
58
58
|
} catch {
|
|
59
|
-
|
|
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
|
-
"
|
|
78
|
-
"
|
|
79
|
-
|
|
80
|
-
|
|
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.
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-docusign",
|
|
3
|
-
"version": "
|
|
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.
|
|
67
|
+
"adm-zip": "^0.6.1"
|
|
59
68
|
}
|
|
60
69
|
}
|