@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,494 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Performance = void 0;
7
+ var _ids = require("./ids.js");
8
+ var _crashReporting = require("./crash-reporting.js");
9
+ // packages/react-native-sdk/src/modules/performance.ts
10
+ //
11
+ // Sentry-compatible performance monitoring SDK for swiss-knife (React Native).
12
+ // Provides Transaction/Span tracking with automatic navigation and HTTP
13
+ // fetch instrumentation.
14
+ //
15
+ // ## Round-D audit note: deliberate JS-side fetch
16
+ //
17
+ // Same rationale as `crash-reporting.ts` — transactions captured purely
18
+ // in JS (via `fetch` patches + auto-instrumented spans) ship directly
19
+ // to `/api/sdk/errors/transaction` without a typed bridge round-trip.
20
+ // Native-side performance hooks (cold-start, app-resume, ANR-adjacent
21
+ // stalls) already go through the unified transport on iOS + Android.
22
+ // Migrating the JS path through a `performanceCaptureTransaction` spec
23
+ // method is a follow-up wave; Round-D's scope ended at iOS/Android.
24
+
25
+ // MARK: - Types
26
+
27
+ /** Stall aggregation attached to the transaction payload as `measurements`. */
28
+
29
+ // MARK: - Internals
30
+ // Post-#136 audit: id helpers used to live inline here and in
31
+ // `analytics.ts`. They have been centralized in `./ids.ts` so future
32
+ // callers can import rather than copy-paste.
33
+
34
+ // MARK: - Stall Tracking (wave-2 C6)
35
+ //
36
+ // While at least one transaction is open, a 50ms interval timer measures
37
+ // event-loop drift: if a tick arrives more than 100ms later than scheduled,
38
+ // the JS thread stalled. Each stall is aggregated into EVERY currently-open
39
+ // transaction (a blocked event loop stalls them all). The timer runs ONLY
40
+ // while transactions are open — zero overhead otherwise.
41
+
42
+ const STALL_TICK_INTERVAL_MS = 50;
43
+ const STALL_DRIFT_THRESHOLD_MS = 100;
44
+ let _stallTimer = null;
45
+ let _stallLastTick = 0;
46
+ const _openTransactions = new Set();
47
+ function registerOpenTransaction(tx) {
48
+ _openTransactions.add(tx);
49
+ if (_stallTimer === null) {
50
+ _stallLastTick = Date.now();
51
+ _stallTimer = setInterval(() => {
52
+ recordStallTick(Date.now());
53
+ }, STALL_TICK_INTERVAL_MS);
54
+ }
55
+ }
56
+ function unregisterOpenTransaction(tx) {
57
+ _openTransactions.delete(tx);
58
+ if (_openTransactions.size === 0 && _stallTimer !== null) {
59
+ clearInterval(_stallTimer);
60
+ _stallTimer = null;
61
+ }
62
+ }
63
+
64
+ /** Tick handler, split out so tests can drive it with explicit clocks. */
65
+ function recordStallTick(now) {
66
+ const drift = now - _stallLastTick - STALL_TICK_INTERVAL_MS;
67
+ _stallLastTick = now;
68
+ if (drift <= STALL_DRIFT_THRESHOLD_MS) return;
69
+ for (const tx of _openTransactions) {
70
+ tx._recordStall(drift);
71
+ }
72
+ }
73
+
74
+ // MARK: - Span Implementation
75
+
76
+ class SpanImpl {
77
+ endTime = null;
78
+ status = "ok";
79
+ tags = {};
80
+ _data = {};
81
+ children = [];
82
+ constructor(op, description, parentSpanId) {
83
+ this.spanId = (0, _ids.generateSpanId)();
84
+ this.parentSpanId = parentSpanId;
85
+ this.op = op;
86
+ this.description = description;
87
+ this.startTime = new Date();
88
+ }
89
+ startChild(op, description) {
90
+ const child = new SpanImpl(op, description, this.spanId);
91
+ this.children.push(child);
92
+ return child;
93
+ }
94
+ finish(status = "ok") {
95
+ if (this.endTime) return; // already finished
96
+ this.endTime = new Date();
97
+ this.status = status;
98
+ }
99
+ setTag(key, value) {
100
+ this.tags[key] = value;
101
+ }
102
+ setData(key, value) {
103
+ this._data[key] = value;
104
+ }
105
+ _toPayload() {
106
+ const end = this.endTime ?? new Date();
107
+ const payload = {
108
+ spanId: this.spanId,
109
+ parentSpanId: this.parentSpanId,
110
+ op: this.op,
111
+ startTimestamp: this.startTime.toISOString(),
112
+ endTimestamp: end.toISOString(),
113
+ status: this.status
114
+ };
115
+ if (this.description) payload.description = this.description;
116
+ if (Object.keys(this.tags).length > 0) payload.tags = this.tags;
117
+ if (Object.keys(this._data).length > 0) payload.data = this._data;
118
+ return payload;
119
+ }
120
+ _allSpans() {
121
+ const result = [this];
122
+ for (const child of this.children) {
123
+ result.push(...child._allSpans());
124
+ }
125
+ return result;
126
+ }
127
+ }
128
+
129
+ // MARK: - Transaction Implementation
130
+
131
+ class TransactionImpl {
132
+ endTime = null;
133
+ status = "ok";
134
+ tags = {};
135
+ _data = {};
136
+ spans = [];
137
+ stalls = {
138
+ stallCount: 0,
139
+ stallTotalMs: 0,
140
+ stallLongestMs: 0
141
+ };
142
+ constructor(name, op) {
143
+ this.traceId = (0, _ids.generateTraceId)();
144
+ this.spanId = (0, _ids.generateSpanId)();
145
+ this.name = name;
146
+ this.op = op;
147
+ this.startTime = new Date();
148
+ // Stall tracking runs for every real (non-sampled-out) transaction,
149
+ // including the navigation-tracker ones constructed directly.
150
+ registerOpenTransaction(this);
151
+ }
152
+
153
+ /** Called by the stall timer while this transaction is open. */
154
+ _recordStall(driftMs) {
155
+ const drift = Math.round(driftMs);
156
+ this.stalls.stallCount += 1;
157
+ this.stalls.stallTotalMs += drift;
158
+ if (drift > this.stalls.stallLongestMs) {
159
+ this.stalls.stallLongestMs = drift;
160
+ }
161
+ }
162
+ startChild(op, description) {
163
+ const span = new SpanImpl(op, description, this.spanId);
164
+ this.spans.push(span);
165
+ return span;
166
+ }
167
+ finish(status = "ok") {
168
+ if (this.endTime) return; // already finished
169
+ this.endTime = new Date();
170
+ this.status = status;
171
+
172
+ // Stall timer stops when the last open transaction finishes.
173
+ unregisterOpenTransaction(this);
174
+
175
+ // Clear active transaction reference
176
+ if (_activeTransaction === this) {
177
+ _activeTransaction = null;
178
+ }
179
+
180
+ // Auto-finish any unfinished child spans
181
+ for (const span of this._allChildSpans()) {
182
+ span.finish("ok");
183
+ }
184
+
185
+ // Queue for the debounced send
186
+ enqueueTransaction(this);
187
+ }
188
+ setTag(key, value) {
189
+ this.tags[key] = value;
190
+ }
191
+ setData(key, value) {
192
+ this._data[key] = value;
193
+ }
194
+ _toPayload() {
195
+ const end = this.endTime ?? new Date();
196
+ const childPayloads = this._allChildSpans().map(s => s._toPayload());
197
+ const payload = {
198
+ traceId: this.traceId,
199
+ name: this.name,
200
+ op: this.op,
201
+ startTimestamp: this.startTime.toISOString(),
202
+ endTimestamp: end.toISOString(),
203
+ status: this.status,
204
+ spans: childPayloads,
205
+ release: _config?.release,
206
+ environment: _config?.environment ?? "production",
207
+ measurements: {
208
+ ...this.stalls
209
+ },
210
+ contexts: {
211
+ os: {
212
+ name: "React Native"
213
+ },
214
+ device: {}
215
+ }
216
+ };
217
+ if (Object.keys(this.tags).length > 0) payload.tags = this.tags;
218
+ return payload;
219
+ }
220
+ _allChildSpans() {
221
+ const result = [];
222
+ for (const span of this.spans) {
223
+ result.push(...span._allSpans());
224
+ }
225
+ return result;
226
+ }
227
+ }
228
+
229
+ // MARK: - Module State
230
+
231
+ // No-op transaction (returned when sampling drops a transaction)
232
+ const noopSpan = {
233
+ spanId: "",
234
+ parentSpanId: "",
235
+ op: "",
236
+ startChild() {
237
+ return noopSpan;
238
+ },
239
+ finish() {},
240
+ setTag() {},
241
+ setData() {}
242
+ };
243
+ const noopTransaction = {
244
+ traceId: "",
245
+ spanId: "",
246
+ name: "",
247
+ op: "",
248
+ startChild() {
249
+ return noopSpan;
250
+ },
251
+ finish() {},
252
+ setTag() {},
253
+ setData() {}
254
+ };
255
+ let _config = null;
256
+ let _originalFetch = null;
257
+ let _activeTransaction = null;
258
+ let _txQueue = [];
259
+ let _txFlushTimer = null;
260
+
261
+ // MARK: - Sampling
262
+
263
+ /**
264
+ * Effective sample rate for one transaction: `tracesSampler` (clamped 0..1)
265
+ * when configured and well-behaved, else `tracesSampleRate` (default 1.0).
266
+ */
267
+ function resolveSampleRate(name, op) {
268
+ const fallback = _config?.tracesSampleRate ?? 1.0;
269
+ const sampler = _config?.tracesSampler;
270
+ if (!sampler) return fallback;
271
+ try {
272
+ const rate = sampler({
273
+ name,
274
+ op
275
+ });
276
+ if (typeof rate !== "number" || !Number.isFinite(rate)) return fallback;
277
+ return Math.min(1, Math.max(0, rate));
278
+ } catch (e) {
279
+ console.warn("[SwissKnife Performance] tracesSampler threw — falling back to tracesSampleRate:", e);
280
+ return fallback;
281
+ }
282
+ }
283
+
284
+ // MARK: - Send
285
+
286
+ const TX_FLUSH_DEBOUNCE_MS = 500;
287
+
288
+ /** Debounce finished transactions like error events — one wakeup per burst. */
289
+ function enqueueTransaction(transaction) {
290
+ if (!_config) return;
291
+ _txQueue.push(transaction);
292
+ if (_txFlushTimer !== null) return;
293
+ _txFlushTimer = setTimeout(() => {
294
+ _txFlushTimer = null;
295
+ void flushTransactions();
296
+ }, TX_FLUSH_DEBOUNCE_MS);
297
+ }
298
+
299
+ // No batch endpoint exists for transactions server-side, so the debounced
300
+ // queue drains serially over the single-transaction endpoint (one request
301
+ // in flight at a time instead of a POST per finish()).
302
+ async function flushTransactions() {
303
+ if (!_config || _txQueue.length === 0) return;
304
+ const batch = _txQueue;
305
+ _txQueue = [];
306
+ const baseURL = _config.serverURL || "https://api.swiss-knife.dev";
307
+ const url = `${baseURL}/api/sdk/errors/transaction`;
308
+ // Use original fetch if we've patched it
309
+ const fetchFn = _originalFetch ?? fetch;
310
+ for (const transaction of batch) {
311
+ try {
312
+ const res = await fetchFn(url, {
313
+ method: "POST",
314
+ headers: {
315
+ "Content-Type": "application/json",
316
+ "X-API-Key": _config.apiKey
317
+ },
318
+ body: JSON.stringify(transaction._toPayload())
319
+ });
320
+ if (!res.ok) {
321
+ console.warn(`[SwissKnife Performance] send failed: HTTP ${res.status}`);
322
+ }
323
+ } catch (e) {
324
+ console.warn("[SwissKnife Performance] send error:", e);
325
+ }
326
+ }
327
+ }
328
+
329
+ // MARK: - Auto HTTP Instrumentation
330
+
331
+ function installFetchInstrumentation() {
332
+ if (typeof globalThis.fetch !== "function") return;
333
+ _originalFetch = globalThis.fetch;
334
+ globalThis.fetch = async function patchedFetch(input, init) {
335
+ const method = init?.method?.toUpperCase() ?? (input instanceof Request ? input.method : "GET");
336
+ const urlStr = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
337
+ const tx = Performance.startTransaction(`${method} ${new URL(urlStr, "http://localhost").pathname}`, "http.client");
338
+ tx.setData("url", urlStr);
339
+ tx.setData("method", method);
340
+
341
+ // Inject trace propagation headers if there's an active transaction
342
+ const traceHeaders = Performance.traceHeaders();
343
+ if (Object.keys(traceHeaders).length > 0) {
344
+ const existingHeaders = init?.headers ?? {};
345
+ const mergedHeaders = {
346
+ ...(existingHeaders instanceof Headers ? Object.fromEntries(existingHeaders.entries()) : Array.isArray(existingHeaders) ? Object.fromEntries(existingHeaders) : existingHeaders),
347
+ ...traceHeaders
348
+ };
349
+ init = {
350
+ ...init,
351
+ headers: mergedHeaders
352
+ };
353
+ }
354
+ try {
355
+ const response = await _originalFetch(input, init);
356
+ tx.setData("status_code", response.status);
357
+ tx.finish(response.ok ? "ok" : "internal_error");
358
+ return response;
359
+ } catch (error) {
360
+ tx.finish("internal_error");
361
+ throw error;
362
+ }
363
+ };
364
+ }
365
+
366
+ // MARK: - React Navigation Integration
367
+
368
+ /**
369
+ * Creates an onStateChange handler for React Navigation that automatically
370
+ * tracks screen transitions as transactions.
371
+ *
372
+ * Usage:
373
+ * ```
374
+ * const onStateChange = Performance.createNavigationTracker();
375
+ * <NavigationContainer onStateChange={onStateChange}>
376
+ * ```
377
+ */
378
+ function createNavigationTracker() {
379
+ let currentRoute = null;
380
+ let currentTransaction = null;
381
+ function getActiveRouteName(state) {
382
+ if (!state || typeof state !== "object") return null;
383
+ const s = state;
384
+ if (!s.routes || s.index === undefined) return null;
385
+ const route = s.routes[s.index];
386
+ if (!route) return null;
387
+ // If the route has a nested state, recurse
388
+ if (route.state) {
389
+ return getActiveRouteName(route.state) ?? route.name;
390
+ }
391
+ return route.name;
392
+ }
393
+ return state => {
394
+ const routeName = getActiveRouteName(state);
395
+ if (!routeName || routeName === currentRoute) return;
396
+
397
+ // Finish previous screen transaction
398
+ if (currentTransaction) {
399
+ currentTransaction.finish("ok");
400
+ }
401
+
402
+ // Route changes are also crash-reporting breadcrumbs (Sentry parity) —
403
+ // the ring buffer is a safe no-op when CrashReporting isn't initialized.
404
+ _crashReporting.CrashReporting.addBreadcrumb({
405
+ category: "navigation",
406
+ message: routeName,
407
+ data: {
408
+ ...(currentRoute ? {
409
+ from: currentRoute
410
+ } : {}),
411
+ to: routeName
412
+ },
413
+ level: "info"
414
+ });
415
+ currentRoute = routeName;
416
+ currentTransaction = new TransactionImpl(routeName, "navigation");
417
+ };
418
+ }
419
+
420
+ // MARK: - Main Export
421
+
422
+ const Performance = exports.Performance = {
423
+ init(config) {
424
+ _config = {
425
+ environment: "production",
426
+ enableAutoHTTP: false,
427
+ ...config
428
+ };
429
+ if (_config.enableAutoHTTP) {
430
+ installFetchInstrumentation();
431
+ }
432
+ },
433
+ startTransaction(name, op) {
434
+ const rate = resolveSampleRate(name, op);
435
+ if (rate <= 0) return noopTransaction;
436
+ if (rate < 1.0 && Math.random() > rate) return noopTransaction;
437
+ const tx = new TransactionImpl(name, op);
438
+ _activeTransaction = tx;
439
+ return tx;
440
+ },
441
+ /**
442
+ * Returns the current trace propagation headers for the active transaction.
443
+ * Add these to outbound HTTP requests to correlate spans across services.
444
+ */
445
+ traceHeaders() {
446
+ if (!_activeTransaction) return {};
447
+ const sampled = (_config?.tracesSampleRate ?? 1.0) > 0 ? "1" : "0";
448
+ return {
449
+ "sk-trace-id": _activeTransaction.traceId,
450
+ "sk-parent-span-id": _activeTransaction.spanId,
451
+ "sk-sampled": sampled
452
+ };
453
+ },
454
+ createNavigationTracker,
455
+ /** Drain the queued transactions immediately (skips the debounce). */
456
+ async flush() {
457
+ if (_txFlushTimer !== null) {
458
+ clearTimeout(_txFlushTimer);
459
+ _txFlushTimer = null;
460
+ }
461
+ await flushTransactions();
462
+ },
463
+ // MARK: - Test Hooks
464
+
465
+ _reset() {
466
+ _config = null;
467
+ _activeTransaction = null;
468
+ _txQueue = [];
469
+ if (_txFlushTimer !== null) {
470
+ clearTimeout(_txFlushTimer);
471
+ _txFlushTimer = null;
472
+ }
473
+ _openTransactions.clear();
474
+ if (_stallTimer !== null) {
475
+ clearInterval(_stallTimer);
476
+ _stallTimer = null;
477
+ }
478
+ if (_originalFetch) {
479
+ globalThis.fetch = _originalFetch;
480
+ _originalFetch = null;
481
+ }
482
+ },
483
+ /** Drive the stall-tick handler with an explicit clock (tests only). */
484
+ _recordStallTickForTests(nowMs) {
485
+ recordStallTick(nowMs);
486
+ },
487
+ _stallTimerRunningForTests() {
488
+ return _stallTimer !== null;
489
+ },
490
+ _openTransactionCountForTests() {
491
+ return _openTransactions.size;
492
+ }
493
+ };
494
+ //# sourceMappingURL=performance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_ids","require","_crashReporting","STALL_TICK_INTERVAL_MS","STALL_DRIFT_THRESHOLD_MS","_stallTimer","_stallLastTick","_openTransactions","Set","registerOpenTransaction","tx","add","Date","now","setInterval","recordStallTick","unregisterOpenTransaction","delete","size","clearInterval","drift","_recordStall","SpanImpl","endTime","status","tags","_data","children","constructor","op","description","parentSpanId","spanId","generateSpanId","startTime","startChild","child","push","finish","setTag","key","value","setData","_toPayload","end","payload","startTimestamp","toISOString","endTimestamp","Object","keys","length","data","_allSpans","result","TransactionImpl","spans","stalls","stallCount","stallTotalMs","stallLongestMs","name","traceId","generateTraceId","driftMs","Math","round","span","_activeTransaction","_allChildSpans","enqueueTransaction","childPayloads","map","s","release","_config","environment","measurements","contexts","os","device","noopSpan","noopTransaction","_originalFetch","_txQueue","_txFlushTimer","resolveSampleRate","fallback","tracesSampleRate","sampler","tracesSampler","rate","Number","isFinite","min","max","e","console","warn","TX_FLUSH_DEBOUNCE_MS","transaction","setTimeout","flushTransactions","batch","baseURL","serverURL","url","fetchFn","fetch","res","method","headers","apiKey","body","JSON","stringify","ok","installFetchInstrumentation","globalThis","patchedFetch","input","init","toUpperCase","Request","urlStr","URL","toString","Performance","startTransaction","pathname","traceHeaders","existingHeaders","mergedHeaders","Headers","fromEntries","entries","Array","isArray","response","error","createNavigationTracker","currentRoute","currentTransaction","getActiveRouteName","state","routes","index","undefined","route","routeName","CrashReporting","addBreadcrumb","category","message","from","to","level","exports","config","enableAutoHTTP","random","sampled","flush","clearTimeout","_reset","clear","_recordStallTickForTests","nowMs","_stallTimerRunningForTests","_openTransactionCountForTests"],"sourceRoot":"../../../src","sources":["modules/performance.ts"],"mappings":";;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D,MAAMA,CAAA,EAAS;IACbzF,OAAO,GAAG,IAAI;IACdP,kBAAkB,GAAG,IAAI;IACzBgB,QAAQ,GAAG,EAAE;IACb,IAAIC,aAAa,KAAK,IAAI,EAAE;MAC1B8E,YAAY,CAAC9E,aAAa,CAAC;MAC3BA,aAAa,GAAG,IAAI;IACtB;IACA9E,iBAAiB,CAAC8J,KAAK,CAAC,CAAC;IACzB,IAAIhK,WAAW,KAAK,IAAI,EAAE;MACxBc,aAAa,CAACd,WAAW,CAAC;MAC1BA,WAAW,GAAG,IAAI;IACpB;IACA,IAAI8E,cAAc,EAAE;MAClBmC,UAAU,CAACV,KAAK,GAAGzB,cAAc;MACjCA,cAAc,GAAG,IAAI;IACvB;EACF,CAAC;EAED;EACAmF,wBAAwBA,CAACC,KAAa,EAAQ;IAC5CxJ,eAAe,CAACwJ,KAAK,CAAC;EACxB,CAAC;EAEDC,0BAA0BA,CAAA,EAAY;IACpC,OAAOnK,WAAW,KAAK,IAAI;EAC7B,CAAC;EAEDoK,6BAA6BA,CAAA,EAAW;IACtC,OAAOlK,iBAAiB,CAACW,IAAI;EAC/B;AACF,CAAC","ignoreList":[]}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.__resetNativeModuleForTests = __resetNativeModuleForTests;
7
+ exports.getEventEmitter = getEventEmitter;
8
+ exports.getNativeModule = getNativeModule;
9
+ var _reactNative = require("react-native");
10
+ // src/native/module.ts
11
+
12
+ const MODULE_NAME = "SwissKnifePurchases";
13
+ const NOT_LINKED_MESSAGE = `The "${MODULE_NAME}" native module is not linked. This SDK requires a native ` + `build — it cannot run in a bare JS/web context or Expo Go. Did you rebuild the ` + `app after installing (pod install / Gradle sync) and use a development build?`;
14
+ let cached = null;
15
+ let cachedEmitter = null;
16
+ function resolve() {
17
+ // New Architecture: TurboModuleRegistry. Falls back to the legacy bridge.
18
+ const turbo = _reactNative.TurboModuleRegistry?.get?.(MODULE_NAME) ?? null;
19
+ if (turbo) return turbo;
20
+ const legacy = _reactNative.NativeModules[MODULE_NAME];
21
+ return legacy ?? null;
22
+ }
23
+ function getNativeModule() {
24
+ if (cached) return cached;
25
+ const mod = resolve();
26
+ if (!mod) throw new Error(NOT_LINKED_MESSAGE);
27
+ cached = mod;
28
+ return mod;
29
+ }
30
+ function getEventEmitter() {
31
+ if (cachedEmitter) return cachedEmitter;
32
+ cachedEmitter = new _reactNative.NativeEventEmitter(getNativeModule());
33
+ return cachedEmitter;
34
+ }
35
+
36
+ // Test seam: reset memoized references so each test starts clean.
37
+ function __resetNativeModuleForTests() {
38
+ cached = null;
39
+ cachedEmitter = null;
40
+ }
41
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","MODULE_NAME","NOT_LINKED_MESSAGE","cached","cachedEmitter","resolve","turbo","TurboModuleRegistry","get","legacy","NativeModules","getNativeModule","mod","Error","getEventEmitter","NativeEventEmitter","__resetNativeModuleForTests"],"sourceRoot":"../../../src","sources":["native/module.ts"],"mappings":";;;;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AADA;;AAQA,MAAMC,WAAW,GAAG,qBAAqB;AAEzC,MAAMC,kBAAkB,GACtB,QAAQD,WAAW,4DAA4D,GAC/E,iFAAiF,GACjF,+EAA+E;AAEjF,IAAIE,MAA8C,GAAG,IAAI;AACzD,IAAIC,aAAwC,GAAG,IAAI;AAEnD,SAASC,OAAOA,CAAA,EAA2C;EACzD;EACA,MAAMC,KAAK,GACTC,gCAAmB,EAAEC,GAAG,GAAoCP,WAAW,CAAC,IACxE,IAAI;EACN,IAAIK,KAAK,EAAE,OAAOA,KAAK;EACvB,MAAMG,MAAM,GAAIC,0BAAa,CAA6BT,WAAW,CAAC;EACtE,OAAQQ,MAAM,IAAoD,IAAI;AACxE;AAEO,SAASE,eAAeA,CAAA,EAAoC;EACjE,IAAIR,MAAM,EAAE,OAAOA,MAAM;EACzB,MAAMS,GAAG,GAAGP,OAAO,CAAC,CAAC;EACrB,IAAI,CAACO,GAAG,EAAE,MAAM,IAAIC,KAAK,CAACX,kBAAkB,CAAC;EAC7CC,MAAM,GAAGS,GAAG;EACZ,OAAOA,GAAG;AACZ;AAEO,SAASE,eAAeA,CAAA,EAAuB;EACpD,IAAIV,aAAa,EAAE,OAAOA,aAAa;EACvCA,aAAa,GAAG,IAAIW,+BAAkB,CAACJ,eAAe,CAAC,CAAC,CAAC;EACzD,OAAOP,aAAa;AACtB;;AAEA;AACO,SAASY,2BAA2BA,CAAA,EAAS;EAClDb,MAAM,GAAG,IAAI;EACbC,aAAa,GAAG,IAAI;AACtB","ignoreList":[]}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CUSTOMER_INFO_UPDATED_EVENT = void 0;
7
+ // src/native/spec.ts
8
+ // The contract the native module must implement. All params/returns are
9
+ // JSON-serializable plain objects — the RN bridge marshals them. Phase 7 of
10
+ // the SDK rip-and-replace cut the implementation over from PHC to our own
11
+ // SwissKnifeiOS (StoreKit 2) and swiss-knife-android (Play Billing v8) AARs;
12
+ // this TS spec is what both sides of the bridge now agree on.
13
+
14
+ // Mirrors RC's PurchasesConfiguration but only the fields the native layer accepts
15
+ // over the bridge. apiKey is required; the rest are optional.
16
+
17
+ // The event name RC emits on CustomerInfo changes; SP-2b must emit the same name.
18
+ const CUSTOMER_INFO_UPDATED_EVENT = exports.CUSTOMER_INFO_UPDATED_EVENT = "Purchases-CustomerInfoUpdated";
19
+
20
+ // Resolved via `TurboModuleRegistry.get<T>` on the New Architecture, so it must
21
+ // be a `TurboModule` (RN constrains `get<T extends TurboModule>`). `TurboModule`
22
+ // only adds an optional `getConstants?(): {}`, which the native side doesn't use.
23
+
24
+ // Re-export the unbound package/product shapes callers pass into purchase methods,
25
+ // so callers don't need to reach into ../types for these specific ones.
26
+ //# sourceMappingURL=spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["CUSTOMER_INFO_UPDATED_EVENT","exports"],"sourceRoot":"../../../src","sources":["native/spec.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;;AAaA;AACA;;AAkBA;AACO,MAAMA,2BAA2B,GAAAC,OAAA,CAAAD,2BAAA,GAAG,+BAA+B;;AAE1E;AACA;AACA;;AA0IA;AACA","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}