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
@@ -2,17 +2,37 @@ package expo.modules.docusign
2
2
 
3
3
  import expo.modules.kotlin.exception.CodedException
4
4
 
5
- class NotInitializedException :
6
- CodedException("DocuSign SDK has not been initialized. Call initialize() first.")
5
+ // Caller mistakes only. Runtime failures travel as DocuSignFailure so their details survive the
6
+ // bridge. Codes are given explicitly rather than inferred: CodedException derives a code from the
7
+ // class name when none is provided, which would surface NotInitializedException to JS as
8
+ // ERR_NOT_INITIALIZED, not the not_initialized documented in the README error table.
7
9
 
8
- class NotLoggedInException :
9
- CodedException("DocuSign SDK is not logged in. Call loginWithAccessToken() first.")
10
+ class NotInitializedException : CodedException(
11
+ "not_initialized",
12
+ "DocuSign SDK has not been initialized. Call initialize() first.",
13
+ null
14
+ )
10
15
 
11
- class LoginFailedException(message: String) :
12
- CodedException("DocuSign login failed: $message")
16
+ class NotLoggedInException : CodedException(
17
+ "not_logged_in",
18
+ "DocuSign SDK is not logged in. Call loginWithAccessToken() first.",
19
+ null
20
+ )
13
21
 
14
- class SigningFailedException(message: String) :
15
- CodedException("DocuSign signing failed: $message")
22
+ class SigningInProgressException : CodedException(
23
+ "signing_in_progress",
24
+ "A signing session is already in progress. Wait for it to finish or call endSigningSession() first.",
25
+ null
26
+ )
16
27
 
17
- class PresentationException(message: String) :
18
- CodedException("Failed to present DocuSign signing UI: $message")
28
+ class InvalidSigningUrlException : CodedException(
29
+ "invalid_signing_url",
30
+ "signingUrl must be a non-empty https URL.",
31
+ null
32
+ )
33
+
34
+ class PresentationException(message: String) : CodedException(
35
+ "presentation_failed",
36
+ "Failed to present DocuSign signing UI: $message",
37
+ null
38
+ )
@@ -0,0 +1,145 @@
1
+ package expo.modules.docusign
2
+
3
+ import com.docusign.androidsdk.exceptions.DSException
4
+ import com.docusign.androidsdk.exceptions.DSRestException
5
+ import java.io.IOException
6
+ import org.json.JSONObject
7
+
8
+ /**
9
+ * Facts about a runtime failure, sent to JS as flat keys.
10
+ *
11
+ * JS derives the failure's `reason` from these, so native code reports what it observed and never
12
+ * guesses. Every field is optional because each failure knows a different subset.
13
+ */
14
+ internal data class FailureDetails(
15
+ val nativeDomain: String? = null,
16
+ val nativeCode: String? = null,
17
+ val nativeMessage: String? = null,
18
+ val underlyingDomain: String? = null,
19
+ val underlyingCode: String? = null,
20
+ val underlyingMessage: String? = null,
21
+ val httpStatus: Int? = null,
22
+ val docusignErrorCode: String? = null,
23
+ val docusignMessage: String? = null
24
+ ) {
25
+ /** Records a lower-level error without overwriting one the SDK already reported. */
26
+ fun withUnderlyingIfAbsent(error: Throwable): FailureDetails {
27
+ if (underlyingDomain != null) return this
28
+ val root = rootCause(error) ?: error
29
+ return copy(
30
+ underlyingDomain = root.javaClass.name,
31
+ underlyingCode = sdkErrorCode(root),
32
+ underlyingMessage = root.message
33
+ )
34
+ }
35
+
36
+ fun withHttp(error: DocuSignHttpException): FailureDetails =
37
+ copy(
38
+ httpStatus = error.status,
39
+ docusignErrorCode = error.docusignErrorCode,
40
+ docusignMessage = error.docusignMessage
41
+ )
42
+
43
+ fun toMap(): Map<String, Any> =
44
+ listOfNotNull<Pair<String, Any>>(
45
+ nativeDomain?.let { "nativeDomain" to it },
46
+ nativeCode?.let { "nativeCode" to it },
47
+ nativeMessage?.let { "nativeMessage" to it },
48
+ underlyingDomain?.let { "underlyingDomain" to it },
49
+ underlyingCode?.let { "underlyingCode" to it },
50
+ underlyingMessage?.let { "underlyingMessage" to it },
51
+ httpStatus?.let { "httpStatus" to it },
52
+ docusignErrorCode?.let { "docusignErrorCode" to it },
53
+ docusignMessage?.let { "docusignMessage" to it }
54
+ ).toMap()
55
+
56
+ companion object {
57
+ /**
58
+ * Reads the SDK's own error code and message where it provides them. The exception message
59
+ * alone was all this module forwarded before, and it rarely says what failed.
60
+ */
61
+ fun from(error: Throwable): FailureDetails {
62
+ val cause = rootCause(error)
63
+ return FailureDetails(
64
+ nativeDomain = error.javaClass.name,
65
+ nativeCode = sdkErrorCode(error),
66
+ nativeMessage = (error as? DSException)?.errorMsg?.takeIf { it.isNotBlank() } ?: error.message,
67
+ underlyingDomain = cause?.javaClass?.name,
68
+ underlyingCode = cause?.let { sdkErrorCode(it) },
69
+ underlyingMessage = cause?.message,
70
+ httpStatus = (error as? DSRestException)?.responseCode?.takeIf { it > 0 }
71
+ )
72
+ }
73
+
74
+ private fun sdkErrorCode(error: Throwable): String? =
75
+ (error as? DSException)?.errorCode?.takeIf { it.isNotBlank() }
76
+
77
+ private const val MAX_CAUSE_DEPTH = 8
78
+
79
+ /**
80
+ * The deepest cause, bounded and safe against cycles. Java wraps transport failures, so the
81
+ * SocketTimeoutException or UnknownHostException that explains a failure sits at the root of
82
+ * the chain, often more than one level below the exception the SDK hands over. iOS keeps the
83
+ * immediate underlying error instead, because the deepest error under an NSURLErrorDomain
84
+ * failure is a CFNetwork error that the reason rules do not classify as a network failure.
85
+ */
86
+ private fun rootCause(error: Throwable): Throwable? {
87
+ val seen = mutableSetOf(error)
88
+ var current = error.cause ?: return null
89
+ repeat(MAX_CAUSE_DEPTH) {
90
+ seen.add(current)
91
+ val next = current.cause
92
+ if (next == null || next in seen) return current
93
+ current = next
94
+ }
95
+ return current
96
+ }
97
+ }
98
+ }
99
+
100
+ /**
101
+ * A non-2xx response to a request this package makes itself. DocuSign's error body names the real
102
+ * problem, such as `UNKNOWN_ENVELOPE_RECIPIENT` for a recipient that does not match the envelope,
103
+ * so it is kept rather than reduced to the status line.
104
+ */
105
+ internal class DocuSignHttpException(
106
+ val status: Int,
107
+ val docusignErrorCode: String?,
108
+ val docusignMessage: String?
109
+ ) : IOException("DocuSign request failed with HTTP $status") {
110
+ companion object {
111
+ fun from(status: Int, body: String): DocuSignHttpException {
112
+ val json = runCatching { JSONObject(body) }.getOrNull()
113
+ return DocuSignHttpException(
114
+ status = status,
115
+ docusignErrorCode = json?.nonEmpty("errorCode") ?: json?.nonEmpty("error"),
116
+ docusignMessage = json?.nonEmpty("message") ?: json?.nonEmpty("error_description")
117
+ )
118
+ }
119
+
120
+ private fun JSONObject.nonEmpty(key: String): String? =
121
+ if (isNull(key)) null else optString(key).takeIf { it.isNotBlank() }
122
+ }
123
+ }
124
+
125
+ /**
126
+ * A runtime failure, as opposed to a caller mistake.
127
+ *
128
+ * Caller mistakes are coded exceptions and reject. A rejection crosses the Expo bridge with only a
129
+ * code and a message, so runtime failures resolve with this payload instead and JS turns it into a
130
+ * thrown `DocuSignError` with every detail intact.
131
+ */
132
+ internal class DocuSignFailure(
133
+ val code: String,
134
+ override val message: String,
135
+ val details: FailureDetails,
136
+ val envelopeId: String? = null
137
+ ) : Exception(message) {
138
+ fun toPayload(fallbackEnvelopeId: String?): Map<String, Any> {
139
+ val payload = details.toMap().toMutableMap()
140
+ payload["errorCode"] = code
141
+ payload["errorMessage"] = message
142
+ (envelopeId ?: fallbackEnvelopeId)?.takeIf { it.isNotEmpty() }?.let { payload["envelopeId"] = it }
143
+ return payload
144
+ }
145
+ }