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