@app-swiss-knife/react-native-sdk 0.1.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.
Files changed (218) hide show
  1. package/README.md +182 -0
  2. package/SwissKnifePurchases.podspec +40 -0
  3. package/android/build.gradle +89 -0
  4. package/android/gradle.properties +3 -0
  5. package/android/src/main/AndroidManifest.xml +26 -0
  6. package/android/src/main/java/com/swissknife/crashreporting/SKCrashReportingModule.kt +216 -0
  7. package/android/src/main/java/com/swissknife/crashreporting/SKCrashReportingPackage.kt +17 -0
  8. package/android/src/main/java/com/swissknife/purchases/Conversions.kt +15 -0
  9. package/android/src/main/java/com/swissknife/purchases/SwissKnifeJson.kt +371 -0
  10. package/android/src/main/java/com/swissknife/purchases/SwissKnifePurchasesModule.kt +497 -0
  11. package/android/src/main/java/com/swissknife/purchases/SwissKnifePurchasesPackage.kt +25 -0
  12. package/android/vendor/GENERATED.md +10 -0
  13. package/android/vendor/java/com/appswissknife/SwissKnife.kt +533 -0
  14. package/android/vendor/java/com/appswissknife/analytics/EventQueueStore.kt +326 -0
  15. package/android/vendor/java/com/appswissknife/analytics/FlushEventsWorker.kt +296 -0
  16. package/android/vendor/java/com/appswissknife/analytics/SKAnalytics.kt +503 -0
  17. package/android/vendor/java/com/appswissknife/attributes/AttributesClient.kt +188 -0
  18. package/android/vendor/java/com/appswissknife/attributes/SetAttributesWorker.kt +204 -0
  19. package/android/vendor/java/com/appswissknife/attribution/Attribution.kt +447 -0
  20. package/android/vendor/java/com/appswissknife/context/AppLifecycle.kt +120 -0
  21. package/android/vendor/java/com/appswissknife/context/Clock.kt +70 -0
  22. package/android/vendor/java/com/appswissknife/context/DeviceContext.kt +138 -0
  23. package/android/vendor/java/com/appswissknife/context/IDs.kt +55 -0
  24. package/android/vendor/java/com/appswissknife/context/Reachability.kt +145 -0
  25. package/android/vendor/java/com/appswissknife/context/Session.kt +192 -0
  26. package/android/vendor/java/com/appswissknife/crashreporting/SKCrashReporting.kt +945 -0
  27. package/android/vendor/java/com/appswissknife/crashreporting/SKScreenshot.kt +201 -0
  28. package/android/vendor/java/com/appswissknife/device/DeviceID.kt +172 -0
  29. package/android/vendor/java/com/appswissknife/diagnostics/SKLog.kt +97 -0
  30. package/android/vendor/java/com/appswissknife/entitlements/EntitlementsRepository.kt +495 -0
  31. package/android/vendor/java/com/appswissknife/identity/Identity.kt +522 -0
  32. package/android/vendor/java/com/appswissknife/models/CustomerInfo.kt +67 -0
  33. package/android/vendor/java/com/appswissknife/models/Enums.kt +35 -0
  34. package/android/vendor/java/com/appswissknife/models/Offerings.kt +80 -0
  35. package/android/vendor/java/com/appswissknife/models/PurchasesError.kt +89 -0
  36. package/android/vendor/java/com/appswissknife/models/StoreTransaction.kt +17 -0
  37. package/android/vendor/java/com/appswissknife/net/BackendHttpClient.kt +507 -0
  38. package/android/vendor/java/com/appswissknife/net/ExponentialBackoff.kt +69 -0
  39. package/android/vendor/java/com/appswissknife/net/IngestClient.kt +582 -0
  40. package/android/vendor/java/com/appswissknife/net/OfflineQueueStore.kt +320 -0
  41. package/android/vendor/java/com/appswissknife/offerings/OfferingsRepository.kt +219 -0
  42. package/android/vendor/java/com/appswissknife/performance/SKFrameTracker.kt +94 -0
  43. package/android/vendor/java/com/appswissknife/performance/SKPerformance.kt +428 -0
  44. package/android/vendor/java/com/appswissknife/purchases/BillingClientGateway.kt +560 -0
  45. package/android/vendor/java/com/appswissknife/purchases/PlayPriceEnrichmentProvider.kt +100 -0
  46. package/android/vendor/java/com/appswissknife/purchases/PriceEnrichmentProvider.kt +36 -0
  47. package/android/vendor/java/com/appswissknife/purchases/PurchasesGateway.kt +120 -0
  48. package/android/vendor/res/xml/swissknife_data_extraction_rules.xml +20 -0
  49. package/ios/SwissKnifeCrashReporting.m +32 -0
  50. package/ios/SwissKnifeCrashReporting.swift +186 -0
  51. package/ios/SwissKnifeJSON.swift +347 -0
  52. package/ios/SwissKnifePurchases.m +124 -0
  53. package/ios/SwissKnifePurchases.swift +523 -0
  54. package/ios/vendor/GENERATED.md +10 -0
  55. package/ios/vendor/SwissKnifeiOS/Analytics/SKAnalytics.swift +488 -0
  56. package/ios/vendor/SwissKnifeiOS/AttributesClient.swift +460 -0
  57. package/ios/vendor/SwissKnifeiOS/Attribution/Attribution.swift +307 -0
  58. package/ios/vendor/SwissKnifeiOS/Attribution/AttributionNetwork.swift +92 -0
  59. package/ios/vendor/SwissKnifeiOS/Attribution/AttributionState.swift +141 -0
  60. package/ios/vendor/SwissKnifeiOS/Context/AppLifecycle.swift +130 -0
  61. package/ios/vendor/SwissKnifeiOS/Context/Clock.swift +100 -0
  62. package/ios/vendor/SwissKnifeiOS/Context/DeviceContext.swift +190 -0
  63. package/ios/vendor/SwissKnifeiOS/Context/IDs.swift +64 -0
  64. package/ios/vendor/SwissKnifeiOS/Context/Reachability.swift +121 -0
  65. package/ios/vendor/SwissKnifeiOS/Context/Session.swift +223 -0
  66. package/ios/vendor/SwissKnifeiOS/CrashReporting/SKCrashReporting.swift +1287 -0
  67. package/ios/vendor/SwissKnifeiOS/CrashReporting/SKScreenshot.swift +175 -0
  68. package/ios/vendor/SwissKnifeiOS/DeviceID.swift +161 -0
  69. package/ios/vendor/SwissKnifeiOS/Diagnostics/SKLog.swift +128 -0
  70. package/ios/vendor/SwissKnifeiOS/Identity/Identity.swift +323 -0
  71. package/ios/vendor/SwissKnifeiOS/Identity/IdentityNetwork.swift +70 -0
  72. package/ios/vendor/SwissKnifeiOS/Net/BackendHttpClient.swift +329 -0
  73. package/ios/vendor/SwissKnifeiOS/Net/ExponentialBackoff.swift +87 -0
  74. package/ios/vendor/SwissKnifeiOS/Net/IngestClient.swift +681 -0
  75. package/ios/vendor/SwissKnifeiOS/Net/OfflineQueueStore.swift +409 -0
  76. package/ios/vendor/SwissKnifeiOS/Performance/SKFrameTracker.swift +89 -0
  77. package/ios/vendor/SwissKnifeiOS/Performance/SKPerformance.swift +440 -0
  78. package/ios/vendor/SwissKnifeiOS/Performance/SKURLSessionDelegate.swift +87 -0
  79. package/ios/vendor/SwissKnifeiOS/Services/EntitlementsService.swift +646 -0
  80. package/ios/vendor/SwissKnifeiOS/Services/OfferingsService.swift +458 -0
  81. package/ios/vendor/SwissKnifeiOS/Services/PurchaseService.swift +374 -0
  82. package/ios/vendor/SwissKnifeiOS/SwissKnife+Analytics.swift +46 -0
  83. package/ios/vendor/SwissKnifeiOS/SwissKnife+DeviceID.swift +30 -0
  84. package/ios/vendor/SwissKnifeiOS/SwissKnife+Session.swift +47 -0
  85. package/ios/vendor/SwissKnifeiOS/SwissKnife.swift +417 -0
  86. package/ios/vendor/SwissKnifeiOS/Types.swift +496 -0
  87. package/lib/commonjs/attribution.js +55 -0
  88. package/lib/commonjs/attribution.js.map +1 -0
  89. package/lib/commonjs/identity.js +126 -0
  90. package/lib/commonjs/identity.js.map +1 -0
  91. package/lib/commonjs/index.js +118 -0
  92. package/lib/commonjs/index.js.map +1 -0
  93. package/lib/commonjs/modules/analytics.js +646 -0
  94. package/lib/commonjs/modules/analytics.js.map +1 -0
  95. package/lib/commonjs/modules/attachments.js +169 -0
  96. package/lib/commonjs/modules/attachments.js.map +1 -0
  97. package/lib/commonjs/modules/crash-reporting.js +1327 -0
  98. package/lib/commonjs/modules/crash-reporting.js.map +1 -0
  99. package/lib/commonjs/modules/ids.js +50 -0
  100. package/lib/commonjs/modules/ids.js.map +1 -0
  101. package/lib/commonjs/modules/log.js +59 -0
  102. package/lib/commonjs/modules/log.js.map +1 -0
  103. package/lib/commonjs/modules/offline-store.js +44 -0
  104. package/lib/commonjs/modules/offline-store.js.map +1 -0
  105. package/lib/commonjs/modules/performance.js +494 -0
  106. package/lib/commonjs/modules/performance.js.map +1 -0
  107. package/lib/commonjs/native/module.js +41 -0
  108. package/lib/commonjs/native/module.js.map +1 -0
  109. package/lib/commonjs/native/spec.js +26 -0
  110. package/lib/commonjs/native/spec.js.map +1 -0
  111. package/lib/commonjs/package.json +1 -0
  112. package/lib/commonjs/purchases.js +194 -0
  113. package/lib/commonjs/purchases.js.map +1 -0
  114. package/lib/commonjs/types.js +236 -0
  115. package/lib/commonjs/types.js.map +1 -0
  116. package/lib/module/attribution.js +51 -0
  117. package/lib/module/attribution.js.map +1 -0
  118. package/lib/module/identity.js +122 -0
  119. package/lib/module/identity.js.map +1 -0
  120. package/lib/module/index.js +36 -0
  121. package/lib/module/index.js.map +1 -0
  122. package/lib/module/modules/analytics.js +642 -0
  123. package/lib/module/modules/analytics.js.map +1 -0
  124. package/lib/module/modules/attachments.js +162 -0
  125. package/lib/module/modules/attachments.js.map +1 -0
  126. package/lib/module/modules/crash-reporting.js +1320 -0
  127. package/lib/module/modules/crash-reporting.js.map +1 -0
  128. package/lib/module/modules/ids.js +44 -0
  129. package/lib/module/modules/ids.js.map +1 -0
  130. package/lib/module/modules/log.js +54 -0
  131. package/lib/module/modules/log.js.map +1 -0
  132. package/lib/module/modules/offline-store.js +39 -0
  133. package/lib/module/modules/offline-store.js.map +1 -0
  134. package/lib/module/modules/performance.js +491 -0
  135. package/lib/module/modules/performance.js.map +1 -0
  136. package/lib/module/native/module.js +34 -0
  137. package/lib/module/native/module.js.map +1 -0
  138. package/lib/module/native/spec.js +22 -0
  139. package/lib/module/native/spec.js.map +1 -0
  140. package/lib/module/package.json +1 -0
  141. package/lib/module/purchases.js +187 -0
  142. package/lib/module/purchases.js.map +1 -0
  143. package/lib/module/types.js +230 -0
  144. package/lib/module/types.js.map +1 -0
  145. package/lib/typescript/commonjs/attribution.d.ts +24 -0
  146. package/lib/typescript/commonjs/attribution.d.ts.map +1 -0
  147. package/lib/typescript/commonjs/identity.d.ts +37 -0
  148. package/lib/typescript/commonjs/identity.d.ts.map +1 -0
  149. package/lib/typescript/commonjs/index.d.ts +15 -0
  150. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  151. package/lib/typescript/commonjs/modules/analytics.d.ts +127 -0
  152. package/lib/typescript/commonjs/modules/analytics.d.ts.map +1 -0
  153. package/lib/typescript/commonjs/modules/attachments.d.ts +50 -0
  154. package/lib/typescript/commonjs/modules/attachments.d.ts.map +1 -0
  155. package/lib/typescript/commonjs/modules/crash-reporting.d.ts +175 -0
  156. package/lib/typescript/commonjs/modules/crash-reporting.d.ts.map +1 -0
  157. package/lib/typescript/commonjs/modules/ids.d.ts +17 -0
  158. package/lib/typescript/commonjs/modules/ids.d.ts.map +1 -0
  159. package/lib/typescript/commonjs/modules/log.d.ts +12 -0
  160. package/lib/typescript/commonjs/modules/log.d.ts.map +1 -0
  161. package/lib/typescript/commonjs/modules/offline-store.d.ts +9 -0
  162. package/lib/typescript/commonjs/modules/offline-store.d.ts.map +1 -0
  163. package/lib/typescript/commonjs/modules/performance.d.ts +75 -0
  164. package/lib/typescript/commonjs/modules/performance.d.ts.map +1 -0
  165. package/lib/typescript/commonjs/native/module.d.ts +6 -0
  166. package/lib/typescript/commonjs/native/module.d.ts.map +1 -0
  167. package/lib/typescript/commonjs/native/spec.d.ts +119 -0
  168. package/lib/typescript/commonjs/native/spec.d.ts.map +1 -0
  169. package/lib/typescript/commonjs/package.json +1 -0
  170. package/lib/typescript/commonjs/purchases.d.ts +68 -0
  171. package/lib/typescript/commonjs/purchases.d.ts.map +1 -0
  172. package/lib/typescript/commonjs/types.d.ts +384 -0
  173. package/lib/typescript/commonjs/types.d.ts.map +1 -0
  174. package/lib/typescript/module/attribution.d.ts +24 -0
  175. package/lib/typescript/module/attribution.d.ts.map +1 -0
  176. package/lib/typescript/module/identity.d.ts +37 -0
  177. package/lib/typescript/module/identity.d.ts.map +1 -0
  178. package/lib/typescript/module/index.d.ts +15 -0
  179. package/lib/typescript/module/index.d.ts.map +1 -0
  180. package/lib/typescript/module/modules/analytics.d.ts +127 -0
  181. package/lib/typescript/module/modules/analytics.d.ts.map +1 -0
  182. package/lib/typescript/module/modules/attachments.d.ts +50 -0
  183. package/lib/typescript/module/modules/attachments.d.ts.map +1 -0
  184. package/lib/typescript/module/modules/crash-reporting.d.ts +175 -0
  185. package/lib/typescript/module/modules/crash-reporting.d.ts.map +1 -0
  186. package/lib/typescript/module/modules/ids.d.ts +17 -0
  187. package/lib/typescript/module/modules/ids.d.ts.map +1 -0
  188. package/lib/typescript/module/modules/log.d.ts +12 -0
  189. package/lib/typescript/module/modules/log.d.ts.map +1 -0
  190. package/lib/typescript/module/modules/offline-store.d.ts +9 -0
  191. package/lib/typescript/module/modules/offline-store.d.ts.map +1 -0
  192. package/lib/typescript/module/modules/performance.d.ts +75 -0
  193. package/lib/typescript/module/modules/performance.d.ts.map +1 -0
  194. package/lib/typescript/module/native/module.d.ts +6 -0
  195. package/lib/typescript/module/native/module.d.ts.map +1 -0
  196. package/lib/typescript/module/native/spec.d.ts +119 -0
  197. package/lib/typescript/module/native/spec.d.ts.map +1 -0
  198. package/lib/typescript/module/package.json +1 -0
  199. package/lib/typescript/module/purchases.d.ts +68 -0
  200. package/lib/typescript/module/purchases.d.ts.map +1 -0
  201. package/lib/typescript/module/types.d.ts +384 -0
  202. package/lib/typescript/module/types.d.ts.map +1 -0
  203. package/package.json +115 -0
  204. package/react-native.config.js +23 -0
  205. package/src/attribution.ts +56 -0
  206. package/src/identity.ts +133 -0
  207. package/src/index.ts +54 -0
  208. package/src/modules/analytics.ts +689 -0
  209. package/src/modules/attachments.ts +222 -0
  210. package/src/modules/crash-reporting.ts +1577 -0
  211. package/src/modules/ids.ts +41 -0
  212. package/src/modules/log.ts +56 -0
  213. package/src/modules/offline-store.ts +51 -0
  214. package/src/modules/performance.ts +589 -0
  215. package/src/native/module.ts +47 -0
  216. package/src/native/spec.ts +183 -0
  217. package/src/purchases.ts +214 -0
  218. package/src/types.ts +470 -0
@@ -0,0 +1,222 @@
1
+ // packages/react-native-sdk/src/modules/attachments.ts
2
+ //
3
+ // Attachment upload for the crash-reporting module (wave-2 C2): POSTs
4
+ // screenshot blobs to /api/sdk/errors/attachments as multipart/form-data.
5
+ //
6
+ // ## Why a hand-built multipart body (not FormData)
7
+ //
8
+ // React Native has no filesystem the SDK can rely on, so the screenshot
9
+ // exists only as a base64 string in memory. The usual RN trick — FormData
10
+ // with a `{ uri: "data:..." }` part — depends on platform-specific native
11
+ // data-URI handlers, and RN's JS `FormData` cannot carry raw bytes (its
12
+ // parts must be strings or `{uri}` descriptors; web `Blob` parts are not
13
+ // supported by RN's `getParts()`). What IS reliably supported end-to-end:
14
+ // RN's fetch (whatwg-fetch over RCTNetworking) accepts a typed-array body —
15
+ // `convertRequestBody` handles `ArrayBuffer.isView(body)` by base64-encoding
16
+ // it across the bridge, so binary survives intact. We therefore decode the
17
+ // base64 to a Uint8Array and serialize the multipart envelope ourselves,
18
+ // byte-exact, with a manual boundary. This is also fully unit-testable: the
19
+ // tests inspect the exact bytes handed to fetch.
20
+
21
+ import { generateUUID } from "./ids";
22
+
23
+ // MARK: - Base64 → bytes
24
+
25
+ const B64_ALPHABET =
26
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
27
+ const B64_LOOKUP: Record<string, number> = {};
28
+ for (let i = 0; i < B64_ALPHABET.length; i++) {
29
+ B64_LOOKUP[B64_ALPHABET[i]] = i;
30
+ }
31
+
32
+ /**
33
+ * Decode a base64 string into a Uint8Array without relying on `atob` or
34
+ * `Buffer` (neither is guaranteed across RN JS engines). Whitespace and
35
+ * padding are tolerated; any other non-alphabet character is skipped.
36
+ */
37
+ export function base64ToUint8Array(base64: string): Uint8Array {
38
+ const clean = base64.replace(/[^A-Za-z0-9+/]/g, "");
39
+ const out = new Uint8Array(Math.floor((clean.length * 3) / 4));
40
+ let outIndex = 0;
41
+ let buffer = 0;
42
+ let bits = 0;
43
+ for (let i = 0; i < clean.length; i++) {
44
+ buffer = (buffer << 6) | B64_LOOKUP[clean[i]];
45
+ bits += 6;
46
+ if (bits >= 8) {
47
+ bits -= 8;
48
+ out[outIndex++] = (buffer >> bits) & 0xff;
49
+ }
50
+ }
51
+ return outIndex === out.length ? out : out.slice(0, outIndex);
52
+ }
53
+
54
+ // MARK: - UTF-8 encoding
55
+
56
+ /**
57
+ * Minimal UTF-8 encoder — `TextEncoder` is not available on every RN
58
+ * JS engine version, and the multipart headers must be byte-exact.
59
+ */
60
+ export function encodeUtf8(text: string): Uint8Array {
61
+ const bytes: number[] = [];
62
+ for (let i = 0; i < text.length; i++) {
63
+ const code = text.codePointAt(i)!;
64
+ if (code > 0xffff) i++; // surrogate pair consumed two UTF-16 units
65
+ if (code < 0x80) {
66
+ bytes.push(code);
67
+ } else if (code < 0x800) {
68
+ bytes.push(0xc0 | (code >> 6), 0x80 | (code & 0x3f));
69
+ } else if (code < 0x10000) {
70
+ bytes.push(
71
+ 0xe0 | (code >> 12),
72
+ 0x80 | ((code >> 6) & 0x3f),
73
+ 0x80 | (code & 0x3f)
74
+ );
75
+ } else {
76
+ bytes.push(
77
+ 0xf0 | (code >> 18),
78
+ 0x80 | ((code >> 12) & 0x3f),
79
+ 0x80 | ((code >> 6) & 0x3f),
80
+ 0x80 | (code & 0x3f)
81
+ );
82
+ }
83
+ }
84
+ return Uint8Array.from(bytes);
85
+ }
86
+
87
+ // MARK: - Multipart body
88
+
89
+ export interface MultipartTextField {
90
+ name: string;
91
+ value: string;
92
+ }
93
+
94
+ export interface MultipartFilePart {
95
+ name: string;
96
+ filename: string;
97
+ contentType: string;
98
+ data: Uint8Array;
99
+ }
100
+
101
+ function concatBytes(chunks: Uint8Array[]): Uint8Array {
102
+ let total = 0;
103
+ for (const chunk of chunks) total += chunk.length;
104
+ const out = new Uint8Array(total);
105
+ let offset = 0;
106
+ for (const chunk of chunks) {
107
+ out.set(chunk, offset);
108
+ offset += chunk.length;
109
+ }
110
+ return out;
111
+ }
112
+
113
+ const CRLF = "\r\n";
114
+
115
+ /**
116
+ * Serialize a multipart/form-data body: text fields first, then the file
117
+ * part with raw binary content, closed with the terminal boundary.
118
+ */
119
+ export function buildMultipartBody(
120
+ boundary: string,
121
+ fields: MultipartTextField[],
122
+ file: MultipartFilePart
123
+ ): Uint8Array {
124
+ const chunks: Uint8Array[] = [];
125
+ for (const field of fields) {
126
+ chunks.push(
127
+ encodeUtf8(
128
+ `--${boundary}${CRLF}` +
129
+ `Content-Disposition: form-data; name="${field.name}"${CRLF}${CRLF}` +
130
+ `${field.value}${CRLF}`
131
+ )
132
+ );
133
+ }
134
+ chunks.push(
135
+ encodeUtf8(
136
+ `--${boundary}${CRLF}` +
137
+ `Content-Disposition: form-data; name="${file.name}"; filename="${file.filename}"${CRLF}` +
138
+ `Content-Type: ${file.contentType}${CRLF}${CRLF}`
139
+ )
140
+ );
141
+ chunks.push(file.data);
142
+ chunks.push(encodeUtf8(`${CRLF}--${boundary}--${CRLF}`));
143
+ return concatBytes(chunks);
144
+ }
145
+
146
+ // MARK: - Upload
147
+
148
+ export interface AttachmentUploadOptions {
149
+ serverURL: string;
150
+ apiKey: string;
151
+ /** Error event this attachment belongs to. */
152
+ eventId: string;
153
+ kind: "screenshot" | "view_hierarchy" | "log";
154
+ contentType: string;
155
+ data: Uint8Array;
156
+ /** Bypass fetch patches (breadcrumb/perf instrumentation). */
157
+ fetchFn?: typeof fetch;
158
+ }
159
+
160
+ /**
161
+ * - "ok" → 2xx, attachment stored
162
+ * - "transient" → network error / 429 / 5xx — worth one retry
163
+ * - "permanent" → other 4xx (validation, over-limit) — do not retry
164
+ */
165
+ export type AttachmentUploadResult = "ok" | "transient" | "permanent";
166
+
167
+ export async function uploadAttachment(
168
+ options: AttachmentUploadOptions
169
+ ): Promise<AttachmentUploadResult> {
170
+ const boundary = `----SwissKnifeBoundary${generateUUID().replace(/-/g, "")}`;
171
+ const body = buildMultipartBody(
172
+ boundary,
173
+ [
174
+ { name: "eventId", value: options.eventId },
175
+ { name: "kind", value: options.kind },
176
+ ],
177
+ {
178
+ name: "file",
179
+ // Server never trusts filenames (stores under a uuid) — this is
180
+ // only a hint for the multipart parser.
181
+ filename: `${options.eventId}.jpg`,
182
+ contentType: options.contentType,
183
+ data: options.data,
184
+ }
185
+ );
186
+
187
+ const fetchFn = options.fetchFn ?? fetch;
188
+ try {
189
+ const res = await fetchFn(
190
+ `${options.serverURL}/api/sdk/errors/attachments`,
191
+ {
192
+ method: "POST",
193
+ headers: {
194
+ "Content-Type": `multipart/form-data; boundary=${boundary}`,
195
+ "X-API-Key": options.apiKey,
196
+ },
197
+ // RN's fetch/XHR bridge supports typed-array bodies
198
+ // (convertRequestBody → base64 over the bridge). See module header.
199
+ body: body as unknown as NonNullable<
200
+ Parameters<typeof fetch>[1]
201
+ >["body"],
202
+ }
203
+ );
204
+ if (res.ok) return "ok";
205
+ if (res.status === 429 || res.status >= 500) return "transient";
206
+ return "permanent";
207
+ } catch {
208
+ return "transient";
209
+ }
210
+ }
211
+
212
+ /**
213
+ * Fire the upload with AT MOST one retry (transient failures only).
214
+ * Never throws — attachment delivery must never block event delivery.
215
+ */
216
+ export async function uploadAttachmentWithRetry(
217
+ options: AttachmentUploadOptions
218
+ ): Promise<AttachmentUploadResult> {
219
+ const first = await uploadAttachment(options);
220
+ if (first !== "transient") return first;
221
+ return uploadAttachment(options);
222
+ }