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
|
@@ -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
|
+
}
|