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
@@ -3,6 +3,7 @@ package expo.modules.docusign
3
3
  import android.app.Activity
4
4
  import android.content.Context
5
5
  import expo.modules.kotlin.Promise
6
+ import expo.modules.kotlin.exception.CodedException
6
7
  import expo.modules.kotlin.exception.Exceptions
7
8
  import expo.modules.kotlin.modules.Module
8
9
  import expo.modules.kotlin.modules.ModuleDefinition
@@ -52,6 +53,9 @@ internal class CaptiveSigningRecord : Record {
52
53
 
53
54
  @Field
54
55
  var recipientClientUserId: String = ""
56
+
57
+ @Field
58
+ var launchStrategy: String = "fetch"
55
59
  }
56
60
 
57
61
  internal class CaptiveSigningUrlRecord : Record {
@@ -83,7 +87,17 @@ class DocuSignModule : Module() {
83
87
  DocuSignManager.initialize(context, config.integratorKey, environment)
84
88
  promise.resolve(null)
85
89
  } catch (e: Exception) {
86
- promise.reject("initialize_failed", e.message ?: "Unknown error", e)
90
+ // A runtime failure of the SDK itself, so it carries the exception's details rather than
91
+ // rejecting with a message alone.
92
+ settleFailure(
93
+ DocuSignFailure(
94
+ code = "initialize_failed",
95
+ message = "DocuSign SDK could not be initialized: ${e.message ?: e.javaClass.simpleName}",
96
+ details = FailureDetails.from(e)
97
+ ),
98
+ null,
99
+ promise
100
+ )
87
101
  }
88
102
  }
89
103
 
@@ -101,57 +115,55 @@ class DocuSignModule : Module() {
101
115
  onSuccess = { info ->
102
116
  promise.resolve(
103
117
  mapOf(
104
- "accountId" to info.accountId,
105
- "userId" to info.userId,
106
- "userName" to info.userName,
107
- "email" to info.email
118
+ "status" to "success",
119
+ "account" to mapOf(
120
+ "accountId" to info.accountId,
121
+ "userId" to info.userId,
122
+ "userName" to info.userName,
123
+ "email" to info.email
124
+ )
108
125
  )
109
126
  )
110
127
  },
111
- onFailure = { error ->
112
- emitSigningError(null, "login_failed", error.message ?: "Unknown error")
113
- promise.reject("login_failed", error.message ?: "Unknown error", error as? Exception)
114
- }
128
+ onFailure = { error -> settleFailure(error, null, promise) }
115
129
  )
116
130
  }
117
131
  }
118
132
 
119
133
  AsyncFunction("presentCaptiveSigning") { params: CaptiveSigningRecord, promise: Promise ->
120
134
  val activity: Activity = appContext.activityProvider?.currentActivity
121
- ?: throw Exceptions.MissingActivity()
135
+ ?: throw PresentationException("no foreground Activity to present from")
122
136
 
123
137
  DocuSignManager.presentCaptiveSigning(
124
138
  activity = activity,
125
139
  envelopeId = params.envelopeId,
126
140
  recipientUserName = params.recipientUserName,
127
141
  recipientEmail = params.recipientEmail,
128
- recipientClientUserId = params.recipientClientUserId
142
+ recipientClientUserId = params.recipientClientUserId,
143
+ launchStrategy = CaptiveSigningLaunchStrategy.fromString(params.launchStrategy)
129
144
  ) { result ->
130
145
  result.fold(
131
- onSuccess = { outcome ->
132
- promise.resolve(
133
- mapOf(
134
- "status" to outcome.status,
135
- "envelopeId" to outcome.envelopeId,
136
- "errorCode" to outcome.errorCode,
137
- "errorMessage" to outcome.errorMessage
138
- )
139
- )
140
- },
141
- onFailure = { error ->
142
- emitSigningError(params.envelopeId, "signing_failed", error.message ?: "Unknown error")
143
- promise.reject("signing_failed", error.message ?: "Unknown error", error as? Exception)
144
- }
146
+ onSuccess = { outcome -> promise.resolve(outcome.toPayload()) },
147
+ onFailure = { error -> settleFailure(error, params.envelopeId, promise) }
145
148
  )
146
149
  }
147
150
  }
148
151
 
149
- AsyncFunction("presentCaptiveSigningWithUrl") { _: CaptiveSigningUrlRecord, promise: Promise ->
150
- promise.reject(
151
- "not_implemented",
152
- "presentCaptiveSigningWithUrl is iOS-only. On Android, use presentCaptiveSigning after login.",
153
- UnsupportedOperationException("presentCaptiveSigningWithUrl is iOS-only")
154
- )
152
+ AsyncFunction("presentCaptiveSigningWithUrl") { params: CaptiveSigningUrlRecord, promise: Promise ->
153
+ val activity: Activity = appContext.activityProvider?.currentActivity
154
+ ?: throw PresentationException("no foreground Activity to present from")
155
+
156
+ DocuSignManager.presentCaptiveSigningWithUrl(
157
+ activity = activity,
158
+ signingUrl = params.signingUrl,
159
+ envelopeId = params.envelopeId,
160
+ recipientId = params.recipientId.takeIf { it.isNotEmpty() }
161
+ ) { result ->
162
+ result.fold(
163
+ onSuccess = { outcome -> promise.resolve(outcome.toPayload()) },
164
+ onFailure = { error -> settleFailure(error, params.envelopeId, promise) }
165
+ )
166
+ }
155
167
  }
156
168
 
157
169
  AsyncFunction("logout") { promise: Promise ->
@@ -174,6 +186,24 @@ class DocuSignModule : Module() {
174
186
  }
175
187
  }
176
188
 
189
+ /**
190
+ * The one place a failure is settled.
191
+ *
192
+ * A runtime failure resolves with its details, because a rejection reaches JS with only a code
193
+ * and a message and would drop them. A caller mistake rejects with its own code.
194
+ */
195
+ private fun settleFailure(error: Throwable, envelopeId: String?, promise: Promise) {
196
+ when (error) {
197
+ is DocuSignFailure -> {
198
+ val payload = error.toPayload(envelopeId)
199
+ sendEvent("onSigningError", payload)
200
+ promise.resolve(payload + ("status" to "error"))
201
+ }
202
+ is CodedException -> promise.reject(error.code, error.message ?: "Unknown error", error)
203
+ else -> promise.reject("unexpected", error.message ?: "Unknown error", error)
204
+ }
205
+ }
206
+
177
207
  internal fun emitSigningComplete(envelopeId: String) {
178
208
  sendEvent("onSigningComplete", mapOf("envelopeId" to envelopeId))
179
209
  }
@@ -181,15 +211,4 @@ class DocuSignModule : Module() {
181
211
  internal fun emitSigningCancelled(envelopeId: String, reason: String?) {
182
212
  sendEvent("onSigningCancelled", mapOf("envelopeId" to envelopeId, "reason" to reason))
183
213
  }
184
-
185
- internal fun emitSigningError(envelopeId: String?, errorCode: String, errorMessage: String) {
186
- sendEvent(
187
- "onSigningError",
188
- mapOf(
189
- "envelopeId" to envelopeId,
190
- "errorCode" to errorCode,
191
- "errorMessage" to errorMessage
192
- )
193
- )
194
- }
195
214
  }
@@ -30,22 +30,46 @@ export type DocuSignAccountInfo = {
30
30
  userName: string;
31
31
  email: string;
32
32
  };
33
+ /**
34
+ * How the Android SDK opens the signing ceremony.
35
+ *
36
+ * `fetch` downloads the envelope first. That download runs on a size-derived
37
+ * read timeout which floors at 15s when nothing is cached, so it can time out
38
+ * on large envelopes.
39
+ *
40
+ * `signingUrl` mints a recipient view with the session access token and points
41
+ * the SDK straight at it, skipping the download. Requires the token to be
42
+ * scoped to create recipient views on the envelope; if the mint fails it falls
43
+ * back to `fetch`.
44
+ */
45
+ export type CaptiveSigningLaunchStrategy = 'fetch' | 'signingUrl';
33
46
  export type CaptiveSigningParams = {
34
47
  envelopeId: string;
35
48
  recipientUserName: string;
36
49
  recipientEmail: string;
37
50
  recipientClientUserId: string;
51
+ /**
52
+ * Android only, ignored on iOS. Defaults to `fetch`, which is the behaviour
53
+ * of every release before this option existed.
54
+ */
55
+ launchStrategy?: CaptiveSigningLaunchStrategy;
38
56
  };
39
57
  export type CaptiveSigningUrlParams = {
40
58
  signingUrl: string;
41
59
  envelopeId: string;
42
60
  recipientId?: string;
43
61
  };
62
+ /**
63
+ * `'error'` is never returned since 2.0.0: every failure rejects with a
64
+ * `DocuSignError` instead. It stays in the union so existing `switch`
65
+ * statements keep compiling.
66
+ */
44
67
  export type SigningStatus = 'completed' | 'cancelled' | 'error';
45
68
  export type SigningResult = {
46
69
  status: SigningStatus;
47
70
  envelopeId: string;
48
71
  errorCode?: string;
72
+ /** For `cancelled`, the SDK's exit reason when it provides one. */
49
73
  errorMessage?: string;
50
74
  };
51
75
  export type SigningCompleteEvent = {
@@ -55,10 +79,25 @@ export type SigningCancelledEvent = {
55
79
  envelopeId: string;
56
80
  reason?: string;
57
81
  };
82
+ /**
83
+ * The raw failure payload native code sends, both as the resolved value of a
84
+ * failed call and as the `onSigningError` event on `DocuSignModule`. Apps should
85
+ * not need it: the functions exported by this package turn it into a
86
+ * `DocuSignError`, which is what `addSigningErrorListener` delivers.
87
+ */
58
88
  export type SigningErrorEvent = {
59
89
  envelopeId?: string;
60
90
  errorCode: string;
61
91
  errorMessage: string;
92
+ nativeDomain?: string;
93
+ nativeCode?: string;
94
+ nativeMessage?: string;
95
+ underlyingDomain?: string;
96
+ underlyingCode?: string;
97
+ underlyingMessage?: string;
98
+ httpStatus?: number;
99
+ docusignErrorCode?: string;
100
+ docusignMessage?: string;
62
101
  };
63
102
  export type LoginAttemptEvent = {
64
103
  integratorKey: string;
@@ -1 +1 @@
1
- {"version":3,"file":"DocuSign.types.d.ts","sourceRoot":"","sources":["../src/DocuSign.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,YAAY,CAAC;AAExD,MAAM,MAAM,cAAc,GAAG;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,mBAAmB,CAAC;IACjC,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACrC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,qBAAqB,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,M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AC;IAC3D,cAAc,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;IACnD,cAAc,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;CACpD,CAAC"}
@@ -0,0 +1,86 @@
1
+ import type { SigningErrorEvent } from './DocuSign.types';
2
+ /**
3
+ * What failed. Stable across releases, so it is safe to branch on.
4
+ *
5
+ * `usage` codes mean the app called the package wrongly. The rest describe a
6
+ * failure at runtime.
7
+ */
8
+ export type DocuSignErrorCode = 'initialize_failed' | 'not_initialized' | 'not_logged_in' | 'login_failed' | 'signing_in_progress' | 'invalid_signing_url' | 'presentation_failed' | 'signing_failed' | 'unexpected';
9
+ /**
10
+ * Why it failed, set only from facts the package can verify. Anything else is
11
+ * `unknown`. A later minor release may turn an `unknown` into a more specific
12
+ * reason, so always handle `unknown`.
13
+ */
14
+ export type DocuSignErrorReason = 'usage' | 'network' | 'auth' | 'configuration' | 'recipient' | 'unknown';
15
+ export type DocuSignUnderlyingError = {
16
+ domain?: string;
17
+ code?: string;
18
+ message?: string;
19
+ };
20
+ /**
21
+ * Raw details from the platform. On iOS `domain` and `code` come from the
22
+ * `NSError`, on Android `domain` is the exception class and `code` is the
23
+ * DocuSign SDK error code when it provides one.
24
+ */
25
+ export type DocuSignNativeErrorDetails = DocuSignUnderlyingError & {
26
+ /**
27
+ * The lower-level error behind the failure when known: `NSUnderlyingErrorKey`
28
+ * on iOS, the root of the exception's cause chain on Android, or the transport
29
+ * error of a request the package made itself.
30
+ */
31
+ underlying?: DocuSignUnderlyingError;
32
+ };
33
+ /** Present when an HTTP response is part of the failure. */
34
+ export type DocuSignHttpErrorDetails = {
35
+ status: number;
36
+ /** DocuSign's own error code from the response body, such as `UNKNOWN_ENVELOPE_RECIPIENT`. */
37
+ docusignErrorCode?: string;
38
+ docusignMessage?: string;
39
+ };
40
+ /**
41
+ * Flat, primitive-only attributes for analytics and error reporting tools.
42
+ * Low cardinality on purpose: no messages, so dashboards can group on every key.
43
+ */
44
+ export type DocuSignErrorAttributes = {
45
+ docusign_code: DocuSignErrorCode;
46
+ docusign_reason: DocuSignErrorReason;
47
+ docusign_envelope_id?: string;
48
+ docusign_native_domain?: string;
49
+ docusign_native_code?: string;
50
+ docusign_underlying_domain?: string;
51
+ docusign_underlying_code?: string;
52
+ docusign_http_status?: number;
53
+ docusign_api_error_code?: string;
54
+ };
55
+ export type DocuSignErrorInit = {
56
+ code: DocuSignErrorCode;
57
+ message: string;
58
+ envelopeId?: string;
59
+ native?: DocuSignNativeErrorDetails;
60
+ http?: DocuSignHttpErrorDetails;
61
+ };
62
+ export declare function redactSecrets(text: string): string;
63
+ /**
64
+ * Order matters. A caller mistake outranks everything, and a transport failure
65
+ * outranks an HTTP status seen earlier in the same flow, because the transport
66
+ * failure is what actually stopped the call.
67
+ */
68
+ export declare function deriveReason({ code, native, http, }: Pick<DocuSignErrorInit, 'code' | 'native' | 'http'>): DocuSignErrorReason;
69
+ export declare class DocuSignError extends Error {
70
+ readonly code: DocuSignErrorCode;
71
+ readonly reason: DocuSignErrorReason;
72
+ readonly envelopeId?: string;
73
+ readonly native?: DocuSignNativeErrorDetails;
74
+ readonly http?: DocuSignHttpErrorDetails;
75
+ constructor(init: DocuSignErrorInit);
76
+ toAttributes(): DocuSignErrorAttributes;
77
+ }
78
+ /** Builds the error from the failure payload native code resolves with. */
79
+ export declare function fromFailurePayload(payload: SigningErrorEvent): DocuSignError;
80
+ /**
81
+ * Normalises anything thrown into a `DocuSignError`. Native rejections arrive
82
+ * as an Error carrying only `code` and `message`, because the Expo bridge drops
83
+ * everything else.
84
+ */
85
+ export declare function toDocuSignError(value: unknown): DocuSignError;
86
+ //# sourceMappingURL=DocuSignError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DocuSignError.d.ts","sourceRoot":"","sources":["../src/DocuSignError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1D;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AAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,0BAA0B,CAAC;IACpC,IAAI,CAAC,EAAE,wBAAwB,CAAC;CACjC,CAAC;AAgEF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKlD;AAUD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,EAC3B,IAAI,EACJ,MAAM,EACN,IAAI,GACL,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC,GAAG,mBAAmB,CAwB3E;AAED,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC;IACrC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,CAAC,EAAE,0BAA0B,CAAC;IAC7C,QAAQ,CAAC,IAAI,CAAC,EAAE,wBAAwB,CAAC;gBAE7B,IAAI,EAAE,iBAAiB;IA2BnC,YAAY,IAAI,uBAAuB;CAqBxC;AAYD,2EAA2E;AAC3E,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,iBAAiB,GAAG,aAAa,CAuC5E;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,CAe7D"}
@@ -0,0 +1,210 @@
1
+ const USAGE_CODES = new Set([
2
+ 'not_initialized',
3
+ 'not_logged_in',
4
+ 'signing_in_progress',
5
+ 'invalid_signing_url',
6
+ 'presentation_failed',
7
+ ]);
8
+ const KNOWN_CODES = new Set([
9
+ 'initialize_failed',
10
+ 'not_initialized',
11
+ 'not_logged_in',
12
+ 'login_failed',
13
+ 'signing_in_progress',
14
+ 'invalid_signing_url',
15
+ 'presentation_failed',
16
+ 'signing_failed',
17
+ 'unexpected',
18
+ ]);
19
+ const NETWORK_DOMAINS = new Set([
20
+ 'NSURLErrorDomain',
21
+ 'java.net.UnknownHostException',
22
+ 'java.net.SocketTimeoutException',
23
+ 'java.net.ConnectException',
24
+ ]);
25
+ const RECIPIENT_API_ERROR_CODES = new Set([
26
+ 'UNKNOWN_ENVELOPE_RECIPIENT',
27
+ ]);
28
+ const JWT_PATTERN = /\beyJ[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]*/g;
29
+ const BEARER_PATTERN = /\bBearer\s+\S+/gi;
30
+ const URL_PATTERN = /\bhttps?:\/\/[^\s"'<>]+/gi;
31
+ const TOKEN_LIKE_SEGMENT = /^[A-Za-z0-9_-]{20,}$/;
32
+ const TRAILING_PUNCTUATION = /[.,;:!?)\]}]+$/;
33
+ /**
34
+ * Signing URLs carry a token in their path and query, and SDK messages can
35
+ * echo a URL or a bearer token back. Keep the origin and short path segments so
36
+ * a message still says which host failed, and drop everything token shaped.
37
+ *
38
+ * The URL match also takes punctuation that ends the sentence around it. That
39
+ * is peeled off first, or a token segment followed by a period would fail the
40
+ * token test and be left in place.
41
+ */
42
+ function redactUrl(matched) {
43
+ const trailing = TRAILING_PUNCTUATION.exec(matched)?.[0] ?? '';
44
+ const url = matched.slice(0, matched.length - trailing.length);
45
+ const withoutQuery = url.split(/[?#]/)[0];
46
+ const match = /^(https?:\/\/[^/]+)(\/.*)?$/i.exec(withoutQuery);
47
+ if (!match)
48
+ return `[redacted-url]${trailing}`;
49
+ const [, origin, path = ''] = match;
50
+ const segments = path
51
+ .split('/')
52
+ .map((segment) => TOKEN_LIKE_SEGMENT.test(segment) ? '[redacted]' : segment);
53
+ return origin + segments.join('/') + trailing;
54
+ }
55
+ export function redactSecrets(text) {
56
+ return text
57
+ .replace(JWT_PATTERN, '[redacted-token]')
58
+ .replace(BEARER_PATTERN, 'Bearer [redacted]')
59
+ .replace(URL_PATTERN, redactUrl);
60
+ }
61
+ function redactOptional(text) {
62
+ return text === undefined ? undefined : redactSecrets(text);
63
+ }
64
+ function isNetworkDomain(domain) {
65
+ return domain !== undefined && NETWORK_DOMAINS.has(domain);
66
+ }
67
+ /**
68
+ * Order matters. A caller mistake outranks everything, and a transport failure
69
+ * outranks an HTTP status seen earlier in the same flow, because the transport
70
+ * failure is what actually stopped the call.
71
+ */
72
+ export function deriveReason({ code, native, http, }) {
73
+ if (USAGE_CODES.has(code))
74
+ return 'usage';
75
+ if (isNetworkDomain(native?.domain) ||
76
+ isNetworkDomain(native?.underlying?.domain)) {
77
+ return 'network';
78
+ }
79
+ if (http?.status === 401 || http?.status === 403)
80
+ return 'auth';
81
+ if (code === 'login_failed' &&
82
+ http &&
83
+ http.status >= 200 &&
84
+ http.status < 300) {
85
+ return 'configuration';
86
+ }
87
+ if (http?.docusignErrorCode &&
88
+ RECIPIENT_API_ERROR_CODES.has(http.docusignErrorCode)) {
89
+ return 'recipient';
90
+ }
91
+ return 'unknown';
92
+ }
93
+ export class DocuSignError extends Error {
94
+ constructor(init) {
95
+ super(redactSecrets(init.message));
96
+ // Babel's class transform breaks `instanceof` for Error subclasses unless
97
+ // the prototype is restored explicitly.
98
+ Object.setPrototypeOf(this, new.target.prototype);
99
+ this.name = 'DocuSignError';
100
+ this.code = init.code;
101
+ this.envelopeId = init.envelopeId;
102
+ this.native = init.native && {
103
+ ...init.native,
104
+ message: redactOptional(init.native.message),
105
+ underlying: init.native.underlying && {
106
+ ...init.native.underlying,
107
+ message: redactOptional(init.native.underlying.message),
108
+ },
109
+ };
110
+ this.http = init.http && {
111
+ ...init.http,
112
+ docusignMessage: redactOptional(init.http.docusignMessage),
113
+ };
114
+ this.reason = deriveReason({
115
+ code: init.code,
116
+ native: this.native,
117
+ http: this.http,
118
+ });
119
+ }
120
+ toAttributes() {
121
+ const attributes = {
122
+ docusign_code: this.code,
123
+ docusign_reason: this.reason,
124
+ };
125
+ if (this.envelopeId)
126
+ attributes.docusign_envelope_id = this.envelopeId;
127
+ if (this.native?.domain)
128
+ attributes.docusign_native_domain = this.native.domain;
129
+ if (this.native?.code)
130
+ attributes.docusign_native_code = this.native.code;
131
+ if (this.native?.underlying?.domain) {
132
+ attributes.docusign_underlying_domain = this.native.underlying.domain;
133
+ }
134
+ if (this.native?.underlying?.code) {
135
+ attributes.docusign_underlying_code = this.native.underlying.code;
136
+ }
137
+ if (this.http)
138
+ attributes.docusign_http_status = this.http.status;
139
+ if (this.http?.docusignErrorCode) {
140
+ attributes.docusign_api_error_code = this.http.docusignErrorCode;
141
+ }
142
+ return attributes;
143
+ }
144
+ }
145
+ function nonEmpty(value) {
146
+ return typeof value === 'string' && value.length > 0 ? value : undefined;
147
+ }
148
+ function toKnownCode(value) {
149
+ return typeof value === 'string' && KNOWN_CODES.has(value)
150
+ ? value
151
+ : 'unexpected';
152
+ }
153
+ /** Builds the error from the failure payload native code resolves with. */
154
+ export function fromFailurePayload(payload) {
155
+ const underlying = payload.underlyingDomain ||
156
+ payload.underlyingCode ||
157
+ payload.underlyingMessage
158
+ ? {
159
+ domain: nonEmpty(payload.underlyingDomain),
160
+ code: nonEmpty(payload.underlyingCode),
161
+ message: nonEmpty(payload.underlyingMessage),
162
+ }
163
+ : undefined;
164
+ const hasNative = payload.nativeDomain ||
165
+ payload.nativeCode ||
166
+ payload.nativeMessage ||
167
+ underlying;
168
+ return new DocuSignError({
169
+ code: toKnownCode(payload.errorCode),
170
+ message: nonEmpty(payload.errorMessage) ?? 'DocuSign operation failed',
171
+ envelopeId: nonEmpty(payload.envelopeId),
172
+ native: hasNative
173
+ ? {
174
+ domain: nonEmpty(payload.nativeDomain),
175
+ code: nonEmpty(payload.nativeCode),
176
+ message: nonEmpty(payload.nativeMessage),
177
+ underlying,
178
+ }
179
+ : undefined,
180
+ http: typeof payload.httpStatus === 'number'
181
+ ? {
182
+ status: payload.httpStatus,
183
+ docusignErrorCode: nonEmpty(payload.docusignErrorCode),
184
+ docusignMessage: nonEmpty(payload.docusignMessage),
185
+ }
186
+ : undefined,
187
+ });
188
+ }
189
+ /**
190
+ * Normalises anything thrown into a `DocuSignError`. Native rejections arrive
191
+ * as an Error carrying only `code` and `message`, because the Expo bridge drops
192
+ * everything else.
193
+ */
194
+ export function toDocuSignError(value) {
195
+ if (value instanceof DocuSignError)
196
+ return value;
197
+ if (value instanceof Error) {
198
+ const code = value.code;
199
+ const knownCode = toKnownCode(code);
200
+ return new DocuSignError({
201
+ code: knownCode,
202
+ message: value.message,
203
+ native: knownCode === 'unexpected' && typeof code === 'string'
204
+ ? { code, message: value.message }
205
+ : undefined,
206
+ });
207
+ }
208
+ return new DocuSignError({ code: 'unexpected', message: String(value) });
209
+ }
210
+ //# sourceMappingURL=DocuSignError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DocuSignError.js","sourceRoot":"","sources":["../src/DocuSignError.ts"],"names":[],"mappings":"AA+EA,MAAM,WAAW,GAAmC,IAAI,GAAG,CAAC;IAC1D,iBAAiB;IACjB,eAAe;IACf,qBAAqB;IACrB,qBAAqB;IACrB,qBAAqB;CACtB,CAAC,CAAC;AAEH,MAAM,WAAW,GAAwB,IAAI,GAAG,CAAoB;IAClE,mBAAmB;IACnB,iBAAiB;IACjB,eAAe;IACf,cAAc;IACd,qBAAqB;IACrB,qBAAqB;IACrB,qBAAqB;IACrB,gBAAgB;IAChB,YAAY;CACb,CAAC,CAAC;AAEH,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC;IACnD,kBAAkB;IAClB,+BAA+B;IAC/B,iCAAiC;IACjC,2BAA2B;CAC5B,CAAC,CAAC;AAEH,MAAM,yBAAyB,GAAwB,IAAI,GAAG,CAAC;IAC7D,4BAA4B;CAC7B,CAAC,CAAC;AAEH,MAAM,WAAW,GACf,4DAA4D,CAAC;AAC/D,MAAM,cAAc,GAAG,kBAAkB,CAAC;AAC1C,MAAM,WAAW,GAAG,2BAA2B,CAAC;AAChD,MAAM,kBAAkB,GAAG,sBAAsB,CAAC;AAClD,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AAE9C;;;;;;;;GAQG;AACH,SAAS,SAAS,CA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AO,EAAE,KAAK,CAAC,OAAO,EAAE;gBAClC,CAAC,CAAC,SAAS;SAChB,CAAC,CAAC;IACL,CAAC;IACD,OAAO,IAAI,aAAa,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAC3E,CAAC"}
@@ -1,10 +1,29 @@
1
1
  import { NativeModule } from 'expo';
2
- import { CaptiveSigningParams, CaptiveSigningUrlParams, DocuSignAccountInfo, DocuSignAuthParams, DocuSignConfig, DocuSignModuleEvents, SigningResult } from './DocuSign.types';
2
+ import { CaptiveSigningParams, CaptiveSigningUrlParams, DocuSignAccountInfo, DocuSignAuthParams, DocuSignConfig, DocuSignModuleEvents, SigningErrorEvent } from './DocuSign.types';
3
+ /**
4
+ * Native code rejects only for caller mistakes, because a rejection crosses the
5
+ * Expo bridge with nothing but `code` and `message`. Runtime failures resolve
6
+ * with this payload instead, so their details survive, and the exported API
7
+ * turns them into a thrown `DocuSignError`.
8
+ */
9
+ export type NativeFailureOutcome = SigningErrorEvent & {
10
+ status: 'error';
11
+ };
12
+ export type NativeSigningOutcome = {
13
+ status: 'completed' | 'cancelled';
14
+ envelopeId: string;
15
+ errorCode?: string | null;
16
+ errorMessage?: string | null;
17
+ } | NativeFailureOutcome;
18
+ export type NativeLoginOutcome = {
19
+ status: 'success';
20
+ account: DocuSignAccountInfo;
21
+ } | NativeFailureOutcome;
3
22
  declare class DocuSignModule extends NativeModule<DocuSignModuleEvents> {
4
- initialize(config: DocuSignConfig): Promise<void>;
5
- loginWithAccessToken(params: DocuSignAuthParams): Promise<DocuSignAccountInfo>;
6
- presentCaptiveSigning(params: CaptiveSigningParams): Promise<SigningResult>;
7
- presentCaptiveSigningWithUrl(params: CaptiveSigningUrlParams): Promise<SigningResult>;
23
+ initialize(config: DocuSignConfig): Promise<NativeFailureOutcome | null>;
24
+ loginWithAccessToken(params: DocuSignAuthParams): Promise<NativeLoginOutcome>;
25
+ presentCaptiveSigning(params: CaptiveSigningParams): Promise<NativeSigningOutcome>;
26
+ presentCaptiveSigningWithUrl(params: CaptiveSigningUrlParams): Promise<NativeSigningOutcome>;
8
27
  logout(): Promise<void>;
9
28
  isLoggedIn(): Promise<boolean>;
10
29
  endSigningSession(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"DocuSignModule.d.ts","sourceRoot":"","sources":["../src/DocuSignModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAuB,MAAM,MAAM,CAAC;AAEzD,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACpB,aAAa,EACd,MAAM,kBAAkB,CAAC;AAE1B,OAAO,OAAO,cAAe,SAAQ,YAAY,CAAC,oBAAoB,CAAC;IACrE,UAAU,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IACjD,oBAAoB,CAClB,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,mBAAmB,CAAC;IAC/B,qBAAqB,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,aAAa,CAAC;IAC3E,4BAA4B,CAC1B,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,aAAa,CAAC;IACzB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IACvB,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;IAC9B,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAClC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CACvB;;AAED,wBAA+D"}
1
+ {"version":3,"file":"DocuSignModule.d.ts","sourceRoot":"","sources":["../src/DocuSignModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAuB,MAAM,MAAM,CAAC;AAEzD,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACpB,iBAA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CAAC"}
1
+ {"version":3,"file":"DocuSignModule.js","sourceRoot":"","sources":["../src/DocuSignModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,mBAAmB,EAAE,MAAM,MAAM,CAAC;AA+CzD,eAAe,mBAAmB,CAAiB,UAAU,CAAC,CAAC"}
package/build/api.d.ts CHANGED
@@ -1,9 +1,23 @@
1
- import { CaptiveSigningParams, CaptiveSigningUrlParams, DocuSignAccountInfo, DocuSignAuthParams, DocuSignConfig, LoginAttemptEvent, SigningCancelledEvent, SigningCompleteEvent, SigningErrorEvent, SigningResult } from './DocuSign.types';
1
+ import { CaptiveSigningParams, CaptiveSigningUrlParams, DocuSignAccountInfo, DocuSignAuthParams, DocuSignConfig, LoginAttemptEvent, SigningCancelledEvent, SigningCompleteEvent, SigningResult } from './DocuSign.types';
2
+ import { DocuSignError } from './DocuSignError';
2
3
  export type DocuSignSubscription = {
3
4
  remove(): void;
4
5
  };
6
+ export type DocuSignErrorListener = (error: DocuSignError) => void;
7
+ /**
8
+ * Configures the underlying DocuSign SDK. Rejects with a `DocuSignError`.
9
+ */
5
10
  export declare function initialize(config: DocuSignConfig): Promise<void>;
11
+ /**
12
+ * Logs the SDK in with an access token. Rejects with a `DocuSignError` whose
13
+ * `reason` tells an expired token (`auth`) from a DocuSign account that is not
14
+ * set up for the mobile SDK (`configuration`).
15
+ */
6
16
  export declare function loginWithAccessToken(params: DocuSignAuthParams): Promise<DocuSignAccountInfo>;
17
+ /**
18
+ * Presents captive signing. Resolves with `completed` or `cancelled`, and
19
+ * rejects with a `DocuSignError` for every failure.
20
+ */
7
21
  export declare function presentCaptiveSigning(params: CaptiveSigningParams): Promise<SigningResult>;
8
22
  /**
9
23
  * Present captive signing from a pre-minted DocuSign recipient-view URL.
@@ -12,10 +26,8 @@ export declare function presentCaptiveSigning(params: CaptiveSigningParams): Pro
12
26
  * encodes recipient identity via a short-lived token. {@link initialize} is
13
27
  * still required.
14
28
  *
15
- * @platform iOS only. The Android DocuSign SDK (2.1.4) does not expose a
16
- * public URL-based signing entry point; calling this on Android rejects with
17
- * a clear JS error. For cross-platform parity, prefer {@link presentCaptiveSigning}
18
- * with the session flow (accessToken + envelopeId + recipient).
29
+ * Supported on iOS and Android. Resolves with `completed` or `cancelled`, and
30
+ * rejects with a `DocuSignError` for every failure.
19
31
  */
20
32
  export declare function presentCaptiveSigningWithUrl(params: CaptiveSigningUrlParams): Promise<SigningResult>;
21
33
  export declare function logout(): Promise<void>;
@@ -49,6 +61,12 @@ export declare function endSigningSession(): Promise<void>;
49
61
  export declare function reset(): Promise<void>;
50
62
  export declare function addSigningCompleteListener(listener: (event: SigningCompleteEvent) => void): DocuSignSubscription;
51
63
  export declare function addSigningCancelledListener(listener: (event: SigningCancelledEvent) => void): DocuSignSubscription;
52
- export declare function addSigningErrorListener(listener: (event: SigningErrorEvent) => void): DocuSignSubscription;
64
+ /**
65
+ * Receives every `DocuSignError` raised by `initialize`, `loginWithAccessToken`,
66
+ * `presentCaptiveSigning` and `presentCaptiveSigningWithUrl`, caller mistakes
67
+ * included, once each and before the call rejects. Register it once at startup
68
+ * to send failures to your analytics or error reporting tool.
69
+ */
70
+ export declare function addSigningErrorListener(listener: DocuSignErrorListener): DocuSignSubscription;
53
71
  export declare function addLoginAttemptListener(listener: (event: LoginAttemptEvent) => void): DocuSignSubscription;
54
72
  //# sourceMappingURL=api.d.ts.map