@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,646 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SKRevenue = exports.SKIdentify = exports.Analytics = void 0;
7
+ var _module = require("../native/module.js");
8
+ var _ids = require("./ids.js");
9
+ // packages/react-native-sdk/src/modules/analytics.ts
10
+ //
11
+ // Amplitude/Mixpanel-compatible analytics SDK for swiss-knife (React Native).
12
+ // Drop-in replacement interface.
13
+ //
14
+ // ## Architecture: thin pass-through to native
15
+ //
16
+ // Phase 2.3 of the RC rip-and-replace makes the RN Analytics layer a thin
17
+ // pass-through to the native event queue:
18
+ //
19
+ // - **JS owns the payload shape** — `event_id`, `device_id`, super
20
+ // properties, timed-event duration, identify merging, session id, user
21
+ // id, user properties, groups. These are constructed client-side because
22
+ // they depend on JS-only state (super properties + timed events + user
23
+ // properties live in this module).
24
+ //
25
+ // - **Native owns the queue** — disk persistence (iOS Caches /
26
+ // Android cacheDir), exponential back-off with jitter, dead-letter on
27
+ // permanent failure, 5-retry cap. JS can't provide any of that: a JS
28
+ // queue is lost on every JS reload and there is no reliable way to
29
+ // persist + retry from within an RN bridge thread.
30
+ //
31
+ // The bridge surface is just two methods: `trackEvent(event)` and
32
+ // `flushEvents()`. JS calls `trackEvent` once per event with the fully-built
33
+ // payload; native persists it and runs its own scheduler. Auto-flush
34
+ // scheduling lives in native too (iOS Timer / Android WorkManager). The JS
35
+ // `flushIntervalMs` timer is kept as a defensive nudge but the native side
36
+ // is the source of truth.
37
+ //
38
+ // ## device_id source-of-truth: native bridge
39
+ //
40
+ // `device_id` is sourced from the native SDK (iOS Keychain via
41
+ // `SwissKnife.getDeviceId()`, Android EncryptedSharedPreferences via
42
+ // `SwissKnife.getDeviceId(context)`) — NEVER generated in JS.
43
+ //
44
+ // Why: a JS-generated UUID lives in module scope and is reset on every cold
45
+ // start. That fragments every user's analytics timeline on every app restart
46
+ // (one anonymous user becomes N anonymous users). Native persistence (Keychain
47
+ // / EncryptedSharedPreferences) survives process restart AND app reinstall on
48
+ // iOS, and survives process restart but NOT auto-backup transfer on Android —
49
+ // see `packages/swiss-knife-{ios,android}` for the storage rationale.
50
+ //
51
+ // ## event_id generation policy
52
+ //
53
+ // `event_id` is generated **in JS at event-construction time** (the moment
54
+ // `track()` is called). Native receives it as-is and writes it to disk.
55
+ //
56
+ // Why JS-side: the idempotency key needs to be stable across bridge
57
+ // round-trips. If native generated it on receipt, a bridge crash mid-call
58
+ // could (in theory) result in JS retrying `trackEvent` and native assigning
59
+ // a fresh id to what is logically the same event — defeating dedupe at the
60
+ // backend `(app_project_id, event_id)` unique index. Generating it in JS,
61
+ // before the bridge call, eliminates that window.
62
+ //
63
+ // ## Startup-race handling
64
+ //
65
+ // The native `getDeviceId()` call is async. Code that calls `Analytics.track()`
66
+ // immediately after `Analytics.init()` may build events before the native
67
+ // promise resolves. We handle this by:
68
+ // 1. Stamping `device_id` synchronously when the value is already known.
69
+ // 2. Awaiting the native promise inside `track()` when it's still pending,
70
+ // then handing the now-stamped event to the native bridge.
71
+ //
72
+ // Bridge failure falls back to the sentinel string `"unknown-device"` so the
73
+ // backend `events.device_id` column stays populated. See the FALLBACK_DEVICE_ID
74
+ // constant.
75
+
76
+ // MARK: - Types
77
+
78
+ // MARK: - Identify (user properties — Amplitude-compatible)
79
+
80
+ class SKIdentify {
81
+ operations = [];
82
+ set(property, value) {
83
+ this.operations.push({
84
+ op: "$set",
85
+ key: property,
86
+ value
87
+ });
88
+ return this;
89
+ }
90
+ setOnce(property, value) {
91
+ this.operations.push({
92
+ op: "$setOnce",
93
+ key: property,
94
+ value
95
+ });
96
+ return this;
97
+ }
98
+ unset(property) {
99
+ this.operations.push({
100
+ op: "$unset",
101
+ key: property
102
+ });
103
+ return this;
104
+ }
105
+ add(property, value) {
106
+ this.operations.push({
107
+ op: "$add",
108
+ key: property,
109
+ value
110
+ });
111
+ return this;
112
+ }
113
+ append(property, value) {
114
+ this.operations.push({
115
+ op: "$append",
116
+ key: property,
117
+ value
118
+ });
119
+ return this;
120
+ }
121
+ prepend(property, value) {
122
+ this.operations.push({
123
+ op: "$prepend",
124
+ key: property,
125
+ value
126
+ });
127
+ return this;
128
+ }
129
+ remove(property, value) {
130
+ this.operations.push({
131
+ op: "$remove",
132
+ key: property,
133
+ value
134
+ });
135
+ return this;
136
+ }
137
+ union(property, values) {
138
+ this.operations.push({
139
+ op: "$union",
140
+ key: property,
141
+ value: values
142
+ });
143
+ return this;
144
+ }
145
+ clearAll() {
146
+ this.operations.push({
147
+ op: "$clearAll"
148
+ });
149
+ return this;
150
+ }
151
+
152
+ /** @internal */
153
+ _getOperations() {
154
+ return this.operations;
155
+ }
156
+ }
157
+
158
+ // MARK: - Revenue
159
+ exports.SKIdentify = SKIdentify;
160
+ class SKRevenue {
161
+ productId = "";
162
+ quantity = 1;
163
+ price = 0;
164
+ }
165
+
166
+ // MARK: - Main SDK
167
+
168
+ /** Sentinel device_id when the native bridge fails. Documented in module doc-comment. */
169
+ exports.SKRevenue = SKRevenue;
170
+ const FALLBACK_DEVICE_ID = "unknown-device";
171
+ let _config = null;
172
+ let _userId;
173
+ /**
174
+ * The resolved device id. `null` until the native bridge resolves (or until
175
+ * `setDeviceId` is called). When `null`, `track()` awaits the native promise
176
+ * before stamping the outgoing event so every event sent across the bridge
177
+ * carries a `device_id`.
178
+ */
179
+ let _deviceId = null;
180
+ /**
181
+ * In-flight (or settled) promise for the native `getDeviceId()` call. `track()`
182
+ * awaits this to guarantee every emitted event carries a `device_id`. Resolves
183
+ * to the sentinel on bridge failure (never rejects to callers).
184
+ */
185
+ let _deviceIdPromise = null;
186
+ // Cached session id from the native canonical `Session.shared` primitive.
187
+ // Resolved lazily on the first `track()` call and refreshed when native
188
+ // rotates the session (which itself is canonical at flush time too — JS
189
+ // merely reads the latest snapshot). `null` until the first successful
190
+ // native call; falls back to a one-shot millis sentinel only if the native
191
+ // bridge errors out.
192
+ let _sessionId = null;
193
+ let _sessionIdPromise = null;
194
+ let _userProperties = {};
195
+ let _groups = {};
196
+ let _superProperties = {};
197
+ let _timedEvents = {};
198
+ let _flushTimer = null;
199
+
200
+ // Post-#136 audit: `generateUUID` used to live inline here. It has been
201
+ // centralized in `./ids.ts` so future callers can import rather than
202
+ // copy-paste.
203
+
204
+ /**
205
+ * Detect whether we're in a React Native runtime (`navigator` is defined by RN's
206
+ * polyfill) vs plain Node. Wrapped in a function so the `navigator` global
207
+ * reference is hidden behind a runtime check the TS lib doesn't have to know
208
+ * about — we set `tsconfig.lib = ES2020` which omits `dom`/`webworker`, so a
209
+ * bare `typeof navigator` triggers `Cannot find name 'navigator'`.
210
+ */
211
+ function detectOsName() {
212
+ return typeof globalThis.navigator !== "undefined" ? "rn" : "node";
213
+ }
214
+
215
+ /**
216
+ * Kick off the native `getDeviceId()` call and resolve `_deviceIdPromise`.
217
+ * Always resolves (never rejects) — bridge failure produces the sentinel so
218
+ * `track()` can always make progress.
219
+ */
220
+ /**
221
+ * Read the canonical session id from the native `Session.shared` primitive.
222
+ * Cached after first resolve. Falls back to a string-encoded `Date.now()`
223
+ * sentinel ONLY if the native bridge fails — that preserves the
224
+ * fire-and-forget nature of analytics without ever surfacing the error to
225
+ * app code.
226
+ */
227
+ function loadSessionIdFromNative() {
228
+ const p = (async () => {
229
+ try {
230
+ const snap = await (0, _module.getNativeModule)().sessionCurrent();
231
+ if (snap && typeof snap.id === "string" && snap.id.length > 0) {
232
+ _sessionId = snap.id;
233
+ return snap.id;
234
+ }
235
+ const fallback = String(Date.now());
236
+ _sessionId = fallback;
237
+ return fallback;
238
+ } catch (e) {
239
+ console.warn(`[SwissKnife Analytics] native sessionCurrent() failed; falling back to Date.now()-derived id:`, e);
240
+ const fallback = String(Date.now());
241
+ _sessionId = fallback;
242
+ return fallback;
243
+ }
244
+ })();
245
+ _sessionIdPromise = p;
246
+ return p;
247
+ }
248
+ function loadDeviceIdFromNative() {
249
+ const p = (async () => {
250
+ try {
251
+ const id = await (0, _module.getNativeModule)().getDeviceId();
252
+ if (typeof id === "string" && id.length > 0) {
253
+ _deviceId = id;
254
+ return id;
255
+ }
256
+ console.warn(`[SwissKnife Analytics] native getDeviceId() returned an empty value; falling back to "${FALLBACK_DEVICE_ID}"`);
257
+ _deviceId = FALLBACK_DEVICE_ID;
258
+ return FALLBACK_DEVICE_ID;
259
+ } catch (e) {
260
+ console.warn(`[SwissKnife Analytics] native getDeviceId() failed; falling back to "${FALLBACK_DEVICE_ID}":`, e);
261
+ _deviceId = FALLBACK_DEVICE_ID;
262
+ return FALLBACK_DEVICE_ID;
263
+ }
264
+ })();
265
+ _deviceIdPromise = p;
266
+ return p;
267
+ }
268
+
269
+ /**
270
+ * Fire-and-forget send to the native bridge. We do NOT throw out of the public
271
+ * `track()`/`identify()`/etc. surface because analytics is fire-and-forget for
272
+ * app code — app authors don't want a typo-in-event-name or a bridge hiccup to
273
+ * propagate up the call stack. Failures are logged once.
274
+ */
275
+ function sendToNativeFireAndForget(event) {
276
+ void (async () => {
277
+ try {
278
+ await (0, _module.getNativeModule)().trackEvent(event);
279
+ } catch (e) {
280
+ console.warn(`[SwissKnife Analytics] native trackEvent() failed (event will be dropped):`, e);
281
+ }
282
+ })();
283
+ }
284
+
285
+ /**
286
+ * Build a fully-stamped event from `eventType` + props + current SDK state.
287
+ * Awaits the native device-id promise when the cached id is still null.
288
+ * The returned event is ready to hand to the native bridge.
289
+ *
290
+ * Wave 1: `user_id` is derived from the native `Identity.current()`
291
+ * snapshot at event-build time — NOT from the JS-local `_userId` cache
292
+ * that historically drifted from native. Pre-Wave-1: calling
293
+ * `Purchases.logIn("u_42")` and immediately `Analytics.track(...)`
294
+ * emitted with `user_id: ""` because the JS-side `setUserId(...)` was
295
+ * never called. Now native is the single source of truth.
296
+ */
297
+ async function buildEvent(eventType, eventProperties, overrides) {
298
+ // Merge super properties (event props override)
299
+ const mergedProps = {
300
+ ..._superProperties,
301
+ ...eventProperties
302
+ };
303
+
304
+ // Timed event duration
305
+ if (_timedEvents[eventType]) {
306
+ mergedProps.$duration = (Date.now() - _timedEvents[eventType]) / 1000;
307
+ delete _timedEvents[eventType];
308
+ }
309
+
310
+ // Resolve device_id. Synchronous when already cached; otherwise await the
311
+ // native bridge promise (kicked off in init()) so every event handed to
312
+ // native has a device_id stamped.
313
+ let deviceId = _deviceId;
314
+ if (deviceId == null) {
315
+ if (_deviceIdPromise == null) loadDeviceIdFromNative();
316
+ deviceId = (await _deviceIdPromise) ?? FALLBACK_DEVICE_ID;
317
+ }
318
+
319
+ // Resolve session_id from the canonical native primitive. Same lazy
320
+ // pattern as device_id — synchronous when cached, otherwise await the
321
+ // in-flight promise kicked off in init(). Pre-audit this was a JS-side
322
+ // `Date.now()` which diverged from envelope-level
323
+ // ContextSnapshot.session_id.
324
+ let sessionId = _sessionId;
325
+ if (sessionId == null) {
326
+ if (_sessionIdPromise == null) loadSessionIdFromNative();
327
+ sessionId = (await _sessionIdPromise) ?? String(Date.now());
328
+ }
329
+
330
+ // Wave 1: derive user_id from the native Identity snapshot. Fall back
331
+ // to the JS-local `_userId` only when the native call throws (e.g.
332
+ // test harness without the Identity bridge methods stubbed) — that
333
+ // preserves the legacy `Analytics.setUserId(...)` test seam.
334
+ let userId;
335
+ let anonymousId;
336
+ try {
337
+ const snapshot = await (0, _module.getNativeModule)().identityCurrent();
338
+ userId = snapshot.userId ?? "";
339
+ anonymousId = snapshot.anonymousId;
340
+ } catch {
341
+ userId = _userId ?? "";
342
+ anonymousId = undefined;
343
+ }
344
+ const event = {
345
+ event_id: (0, _ids.generateUUID)(),
346
+ event_type: eventType,
347
+ event_properties: mergedProps,
348
+ user_id: userId,
349
+ device_id: deviceId,
350
+ session_id: sessionId,
351
+ time: Date.now(),
352
+ platform: "React Native",
353
+ os_name: detectOsName(),
354
+ // User properties are canonical server-side state (app_users.properties)
355
+ // mutated via $identify operations — regular events carry them only when
356
+ // the local cache is non-empty (matches the iOS SDK, which omits empty
357
+ // maps). Same for groups. `overrides` (used by $identify/$groupidentify
358
+ // to send their operation payloads) still wins over both.
359
+ ...(Object.keys(_userProperties).length > 0 ? {
360
+ user_properties: {
361
+ ..._userProperties
362
+ }
363
+ } : {}),
364
+ ...(Object.keys(_groups).length > 0 ? {
365
+ groups: {
366
+ ..._groups
367
+ }
368
+ } : {}),
369
+ ...overrides
370
+ };
371
+ // Stamp anonymous_id when we resolved it from native — Wave 1's
372
+ // unified $SKAnonymousID: prefix flows through here.
373
+ if (anonymousId !== undefined) {
374
+ event.anonymous_id = anonymousId;
375
+ }
376
+ return event;
377
+ }
378
+ const Analytics = exports.Analytics = {
379
+ // MARK: Initialize
380
+
381
+ /**
382
+ * Configure the analytics SDK. Kicks off (but does not block on) the native
383
+ * `device_id` fetch — callers do not need to `await init()`. Events tracked
384
+ * before the native promise resolves are still sent with `device_id`
385
+ * stamped because `track()` internally awaits the native promise before
386
+ * crossing the bridge.
387
+ */
388
+ init(config) {
389
+ _config = {
390
+ flushQueueSize: 30,
391
+ flushIntervalMs: 30_000,
392
+ optOut: false,
393
+ trackingSessionEvents: true,
394
+ ...config
395
+ };
396
+ // Reset cached session id so the next track() refetches from the
397
+ // canonical native primitive. Pre-audit this was `Date.now()`.
398
+ _sessionId = null;
399
+ _sessionIdPromise = null;
400
+
401
+ // Wire the native observability backend (BackendHttpClient + IngestClient)
402
+ // independently of Purchases.configure, so builds that never configure the
403
+ // purchase engine (e.g. RuStore-only Android) still send analytics. Android
404
+ // implements `configureObservability`; on iOS it's absent (the backend is
405
+ // wired by Purchases.configure), so the optional-chained call no-ops.
406
+ // Fire-and-forget: events queue natively regardless and flush once wired.
407
+ if (config.serverURL) {
408
+ try {
409
+ void (0, _module.getNativeModule)().configureObservability?.(config.apiKey, config.serverURL)?.catch(() => {});
410
+ } catch {
411
+ // getNativeModule throws only when unlinked (web/Expo Go); harmless here.
412
+ }
413
+ }
414
+ if (_flushTimer) clearInterval(_flushTimer);
415
+ // Native owns the authoritative flush scheduling (iOS Timer / Android
416
+ // WorkManager). The JS-side interval is kept as a defensive nudge for
417
+ // cases where native scheduling is delayed (e.g. WorkManager under
418
+ // app standby) — it just delegates to the native flush.
419
+ _flushTimer = setInterval(() => {
420
+ void Analytics.flush();
421
+ }, _config.flushIntervalMs);
422
+
423
+ // Kick off the native device-id fetch unless an explicit `setDeviceId`
424
+ // already seeded a value during this process (test seam / consumer
425
+ // override). When already seeded, keep that promise resolved.
426
+ if (_deviceId == null && _deviceIdPromise == null) {
427
+ loadDeviceIdFromNative();
428
+ }
429
+ // Same lazy warmup for session_id — first track() will await this.
430
+ if (_sessionId == null && _sessionIdPromise == null) {
431
+ loadSessionIdFromNative();
432
+ }
433
+ if (_config.trackingSessionEvents) {
434
+ Analytics.track("[SwissKnife] Session Start");
435
+ }
436
+
437
+ // Return the device-id promise so tests / consumers that want to await
438
+ // initialization can. Resolves to void; the inner string is captured in
439
+ // `_deviceId`. We swallow the result because consumers should read it via
440
+ // `Analytics.getDeviceId()` once init resolves.
441
+ return (_deviceIdPromise ?? Promise.resolve("")).then(() => undefined);
442
+ },
443
+ // MARK: Track events (Amplitude-compatible)
444
+
445
+ track(eventType, eventProperties) {
446
+ if (_config?.optOut) return;
447
+ // Fire-and-forget: build the event (await native device-id if needed),
448
+ // then push it across the bridge. The caller does not need to `await`.
449
+ void (async () => {
450
+ const event = await buildEvent(eventType, eventProperties);
451
+ sendToNativeFireAndForget(event);
452
+ })();
453
+ },
454
+ // MARK: Screen tracking (Mixpanel-compatible)
455
+
456
+ trackScreen(name, properties) {
457
+ Analytics.track("[SwissKnife] Screen Viewed", {
458
+ ...properties,
459
+ "[SwissKnife] Screen Name": name
460
+ });
461
+ },
462
+ // MARK: User identity
463
+
464
+ setUserId(userId) {
465
+ _userId = userId;
466
+ },
467
+ getUserId() {
468
+ return _userId;
469
+ },
470
+ /**
471
+ * Override the device id. Useful for tests and for consumers who want to
472
+ * tie analytics to an external identity. Once called, the native bridge
473
+ * value is ignored for the lifetime of this Analytics module (until
474
+ * `reset()`).
475
+ */
476
+ setDeviceId(deviceId) {
477
+ _deviceId = deviceId;
478
+ _deviceIdPromise = Promise.resolve(deviceId);
479
+ },
480
+ /**
481
+ * Returns the resolved device id, or `null` if the native bridge has not yet
482
+ * resolved AND no explicit override has been set. Most callers should await
483
+ * `init()` first.
484
+ */
485
+ getDeviceId() {
486
+ return _deviceId;
487
+ },
488
+ /**
489
+ * Current session id from the native `Session.shared` primitive.
490
+ * Returns `null` until the first `track()` (or explicit await on
491
+ * `init()`'s session warm) has resolved the native call. Pre-audit
492
+ * this returned a `Date.now()` number; the new return type is `string |
493
+ * null` reflecting both the native UUID format and the lazy resolution.
494
+ */
495
+ getSessionId() {
496
+ return _sessionId;
497
+ },
498
+ identify(identify) {
499
+ if (_config?.optOut) return;
500
+ // Snapshot operations before async hop in case the caller mutates `identify`
501
+ // (defensive — SKIdentify is a builder and re-use is unusual but possible).
502
+ const operations = identify._getOperations();
503
+
504
+ // Apply locally before the async hop so any subsequent track() picks up
505
+ // the new user properties without waiting on the bridge round-trip.
506
+ for (const op of operations) {
507
+ if (op.op === "$set" && op.key) {
508
+ _userProperties[op.key] = op.value;
509
+ }
510
+ }
511
+ void (async () => {
512
+ const event = await buildEvent("$identify", undefined, {
513
+ event_type: "$identify",
514
+ user_properties: {
515
+ $set: operations
516
+ }
517
+ });
518
+ sendToNativeFireAndForget(event);
519
+ })();
520
+ },
521
+ // Super properties (Mixpanel-compatible)
522
+ registerSuperProperties(properties) {
523
+ Object.assign(_superProperties, properties);
524
+ },
525
+ registerSuperPropertiesOnce(properties) {
526
+ for (const [k, v] of Object.entries(properties)) {
527
+ if (!(k in _superProperties)) _superProperties[k] = v;
528
+ }
529
+ },
530
+ getSuperProperties() {
531
+ return {
532
+ ..._superProperties
533
+ };
534
+ },
535
+ unregisterSuperProperty(property) {
536
+ delete _superProperties[property];
537
+ },
538
+ clearSuperProperties() {
539
+ _superProperties = {};
540
+ },
541
+ // Time events (Mixpanel-compatible)
542
+ timeEvent(eventName) {
543
+ _timedEvents[eventName] = Date.now();
544
+ },
545
+ // Group helper (Mixpanel-compatible)
546
+ addGroup(groupType, groupName) {
547
+ const existing = _groups[groupType];
548
+ if (Array.isArray(existing)) {
549
+ if (!existing.includes(groupName)) existing.push(groupName);
550
+ } else {
551
+ _groups[groupType] = [groupName];
552
+ }
553
+ },
554
+ reset() {
555
+ _userId = undefined;
556
+ // Drop both the cached id and the in-flight promise; next init() (or the
557
+ // explicit kickoff below) will refetch from native. This matches the
558
+ // "fresh anonymous identity" semantics callers expect from reset().
559
+ _deviceId = null;
560
+ _deviceIdPromise = null;
561
+ _userProperties = {};
562
+ _groups = {};
563
+ _superProperties = {};
564
+ _timedEvents = {};
565
+ // Drop the cached session id so the next track() refetches from the
566
+ // native primitive (`Session.shared`). Pre-audit this was set to
567
+ // `Date.now()` here, which fragmented the analytics timeline at
568
+ // every reset because the JS-side number drifted from the native
569
+ // session UUID stamped on the envelope.
570
+ _sessionId = null;
571
+ _sessionIdPromise = null;
572
+ },
573
+ // MARK: Groups (Amplitude-compatible)
574
+
575
+ setGroup(groupType, groupName) {
576
+ _groups[groupType] = groupName;
577
+ },
578
+ groupIdentify(groupType, groupName, identify) {
579
+ if (_config?.optOut) return;
580
+ const operations = identify._getOperations();
581
+ void (async () => {
582
+ const event = await buildEvent("$groupidentify", undefined, {
583
+ event_type: "$groupidentify",
584
+ groups: {
585
+ [groupType]: groupName
586
+ },
587
+ user_properties: {
588
+ $set: operations
589
+ }
590
+ });
591
+ sendToNativeFireAndForget(event);
592
+ })();
593
+ },
594
+ // MARK: Revenue (Amplitude + Mixpanel compatible)
595
+
596
+ revenue(revenue) {
597
+ const props = {
598
+ ...revenue.eventProperties,
599
+ $productId: revenue.productId,
600
+ $quantity: revenue.quantity,
601
+ $price: revenue.price
602
+ };
603
+ if (revenue.revenueType) props.$revenueType = revenue.revenueType;
604
+ Analytics.track("revenue_amount", props);
605
+ },
606
+ // Mixpanel-compatible
607
+ trackCharge(amount, properties) {
608
+ Analytics.track("revenue_amount", {
609
+ ...properties,
610
+ $amount: amount
611
+ });
612
+ },
613
+ // MARK: Flush
614
+
615
+ /**
616
+ * Ask the native side to flush its disk-backed queue. Fire-and-forget — the
617
+ * actual HTTP work runs natively (iOS GCD with back-off; Android
618
+ * WorkManager). This promise resolves as soon as the flush job is scheduled.
619
+ *
620
+ * No-op when the bridge is not linked (we don't keep a JS-side queue any
621
+ * more — there's nothing to send). Errors are swallowed with a single warning
622
+ * so background flushers don't crash the host app.
623
+ */
624
+ async flush() {
625
+ try {
626
+ await (0, _module.getNativeModule)().flushEvents();
627
+ } catch (e) {
628
+ console.warn(`[SwissKnife Analytics] native flushEvents() failed:`, e);
629
+ }
630
+ },
631
+ // MARK: Opt out
632
+
633
+ setOptOut(optOut) {
634
+ if (_config) _config.optOut = optOut;
635
+ },
636
+ // MARK: Shutdown
637
+
638
+ shutdown() {
639
+ if (_flushTimer) {
640
+ clearInterval(_flushTimer);
641
+ _flushTimer = null;
642
+ }
643
+ void Analytics.flush();
644
+ }
645
+ };
646
+ //# sourceMappingURL=analytics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_module","require","_ids","SKIdentify","operations","set","property","value","push","op","key","setOnce","unset","add","append","prepend","remove","union","values","clearAll","_getOperations","exports","SKRevenue","productId","quantity","price","FALLBACK_DEVICE_ID","_config","_userId","_deviceId","_deviceIdPromise","_sessionId","_sessionIdPromise","_userProperties","_groups","_superProperties","_timedEvents","_flushTimer","detectOsName","globalThis","navigator","loadSessionIdFromNative","p","snap","getNativeModule","sessionCurrent","id","length","fallback","String","Date","now","e","console","warn","loadDeviceIdFromNative","getDeviceId","sendToNativeFireAndForget","event","trackEvent","buildEvent","eventType","eventProperties","overrides","mergedProps","$duration","deviceId","sessionId","userId","anonymousId","snapshot","identityCurrent","undefined","event_id","generateUUID","event_type","event_properties","user_id","device_id","session_id","time","platform","os_name","Object","keys","user_properties","groups","anonymous_id","Analytics","init","config","flushQueueSize","flushIntervalMs","optOut","trackingSessionEvents","serverURL","configureObservability","apiKey","catch","clearInterval","setInterval","flush","track","Promise","resolve","then","trackScreen","name","properties","setUserId","getUserId","setDeviceId","getSessionId","identify","$set","registerSuperProperties","assign","registerSuperPropertiesOnce","k","v","entries","getSuperProperties","unregisterSuperProperty","clearSuperProperties","timeEvent","eventName","addGroup","groupType","groupName","existing","Array","isArray","includes","reset","setGroup","groupIdentify","revenue","props","$productId","$quantity","$price","revenueType","$revenueType","trackCharge","amount","$amount","flushEvents","setOptOut","shutdown"],"sourceRoot":"../../../src","sources":["modules/analytics.ts"],"mappings":";;;;;;AAmEA,IAAAA,OAAA,GAAAC,OAAA;AAsJA,IAAAC,IAAA,GAAAD,OAAA;AAzNA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA;;AA4CA;;AAEO,MAAME,UAAU,CAAC;EACdC,UAAU,GAAyD,EAAE;EAE7EC,GAAGA,CAACC,QAAgB,EAAEC,KAAc,EAAQ;IAC1C,IAAI,CAACH,UAAU,CAACI,IAAI,CAAC;MAAEC,EAAE,EAAE,MAAM;MAAEC,GAAG,EAAEJ,QAAQ;MAAEC;IAAM,CAAC,CAAC;IAC1D,OAAO,IAAI;EACb;EAEAI,OAAOA,CAACL,QAAgB,EAAEC,KAAc,EAAQ;IAC9C,IAAI,CAACH,UAAU,CAACI,IAAI,CAAC;MAAEC,EAAE,EAAE,UAAU;MAAEC,GAAG,EAAEJ,QAAQ;MAAEC;IAAM,CAAC,CAAC;IAC9D,OAAO,IAAI;EACb;EAEAK,KAAKA,CAACN,QAAgB,EAAQ;IAC5B,IAAI,CAACF,UAAU,CAACI,IAAI,CAAC;MAAEC,EAAE,EAAE,QAAQ;MAAEC,GAAG,EAAEJ;IAAS,CAAC,CAAC;IACrD,OAAO,IAAI;EACb;EAEAO,GAAGA,CAACP,QAAgB,EAAEC,KAAa,EAAQ;IACzC,IAAI,CAACH,UAAU,CAACI,IAAI,CAAC;MAAEC,EAAE,EAAE,MAAM;MAAEC,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