@app-swiss-knife/react-native-sdk 0.4.0 → 0.5.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 (177) hide show
  1. package/CHANGELOG.md +385 -2
  2. package/LICENSE +21 -0
  3. package/README.md +229 -42
  4. package/SwissKnifePurchases.podspec +1 -1
  5. package/android/build.gradle +24 -2
  6. package/android/consumer-rules.pro +12 -0
  7. package/android/src/main/AndroidManifest.xml +15 -1
  8. package/android/src/main/java/com/swissknife/crashreporting/SKCrashReportingModule.kt +5 -4
  9. package/android/src/main/java/com/swissknife/purchases/SwissKnifeJson.kt +7 -2
  10. package/android/src/main/java/com/swissknife/purchases/SwissKnifePurchasesModule.kt +168 -6
  11. package/android/src/play/java/com/swissknife/purchases/StoreIntentHandler.kt +7 -0
  12. package/android/src/rustore/java/com/swissknife/purchases/StoreIntentHandler.kt +9 -0
  13. package/android/vendor/java/com/appswissknife/SwissKnife.kt +107 -38
  14. package/android/vendor/java/com/appswissknife/analytics/SKAnalytics.kt +180 -115
  15. package/android/vendor/java/com/appswissknife/attributes/AttributesClient.kt +16 -18
  16. package/android/vendor/java/com/appswissknife/attributes/SetAttributesWorker.kt +13 -13
  17. package/android/vendor/java/com/appswissknife/attribution/Attribution.kt +56 -25
  18. package/android/vendor/java/com/appswissknife/context/DeviceContext.kt +1 -1
  19. package/android/vendor/java/com/appswissknife/crashreporting/SKCrashReporting.kt +365 -206
  20. package/android/vendor/java/com/appswissknife/entitlements/EntitlementsRepository.kt +195 -26
  21. package/android/vendor/java/com/appswissknife/identity/Identity.kt +31 -6
  22. package/android/vendor/java/com/appswissknife/models/PurchasesError.kt +5 -0
  23. package/android/vendor/java/com/appswissknife/net/BackendHttpClient.kt +56 -31
  24. package/android/vendor/java/com/appswissknife/net/IngestClient.kt +673 -87
  25. package/android/vendor/java/com/appswissknife/net/OfflineQueueStore.kt +214 -30
  26. package/android/vendor/java/com/appswissknife/notifications/NotificationRenderer.kt +195 -0
  27. package/android/vendor/java/com/appswissknife/notifications/PermissionRequestActivity.kt +60 -0
  28. package/android/vendor/java/com/appswissknife/notifications/PermissionStatus.kt +41 -0
  29. package/android/vendor/java/com/appswissknife/notifications/PushEventQueue.kt +143 -0
  30. package/android/vendor/java/com/appswissknife/notifications/PushPayload.kt +72 -0
  31. package/android/vendor/java/com/appswissknife/notifications/PushRegistration.kt +89 -0
  32. package/android/vendor/java/com/appswissknife/notifications/SwissKnifeMessagingService.kt +57 -0
  33. package/android/vendor/java/com/appswissknife/notifications/SwissKnifeNotifications.kt +438 -0
  34. package/android/vendor/java/com/appswissknife/offerings/OfferingsRepository.kt +266 -64
  35. package/android/vendor/java/com/appswissknife/performance/SKPerformance.kt +1 -0
  36. package/android/vendor/java/com/appswissknife/purchases/BillingClientGateway.kt +545 -88
  37. package/android/vendor/java/com/appswissknife/purchases/PlayPriceEnrichmentProvider.kt +55 -24
  38. package/android/vendor/java/com/appswissknife/purchases/ProductKindHint.kt +21 -0
  39. package/android/vendor/java/com/appswissknife/purchases/PurchasesGateway.kt +14 -0
  40. package/android/vendor-rustore/AndroidManifest.xml +59 -0
  41. package/android/vendor-rustore/java/com/appswissknife/rustore/RuStoreGateway.kt +428 -0
  42. package/android/vendor-rustore/java/com/appswissknife/rustore/RuStoreInitProvider.kt +43 -0
  43. package/android/vendor-rustore/java/com/appswissknife/rustore/RuStorePriceEnrichmentProvider.kt +85 -0
  44. package/app.plugin.js +287 -0
  45. package/ios/SwissKnifePurchases.m +20 -0
  46. package/ios/SwissKnifePurchases.swift +97 -3
  47. package/ios/SwissKnifePushBootstrap.m +34 -0
  48. package/ios/vendor/SwissKnifeiOS/Analytics/SKAnalytics.swift +138 -89
  49. package/ios/vendor/SwissKnifeiOS/Context/DeviceContext.swift +1 -1
  50. package/ios/vendor/SwissKnifeiOS/CrashReporting/SKCrashReporting.swift +345 -44
  51. package/ios/vendor/SwissKnifeiOS/Net/BackendBackoffGate.swift +43 -2
  52. package/ios/vendor/SwissKnifeiOS/Net/IngestClient.swift +495 -16
  53. package/ios/vendor/SwissKnifeiOS/Net/OfflineQueueStore.swift +231 -23
  54. package/ios/vendor/SwissKnifeiOS/Notifications/PushPayload.swift +87 -0
  55. package/ios/vendor/SwissKnifeiOS/Notifications/PushRegistrar.swift +322 -0
  56. package/ios/vendor/SwissKnifeiOS/Notifications/SwissKnife+Notifications.swift +403 -0
  57. package/ios/vendor/SwissKnifeiOS/Performance/SKPerformance.swift +1 -0
  58. package/ios/vendor/SwissKnifeiOS/Services/EntitlementsService.swift +11 -7
  59. package/ios/vendor/SwissKnifeiOS/Services/PurchaseService.swift +38 -7
  60. package/ios/vendor/SwissKnifeiOS/SwissKnife.swift +34 -6
  61. package/lib/commonjs/attribution.js +4 -3
  62. package/lib/commonjs/attribution.js.map +1 -1
  63. package/lib/commonjs/identity.js +12 -11
  64. package/lib/commonjs/identity.js.map +1 -1
  65. package/lib/commonjs/index.js +16 -5
  66. package/lib/commonjs/index.js.map +1 -1
  67. package/lib/commonjs/internal/config.js +105 -8
  68. package/lib/commonjs/internal/config.js.map +1 -1
  69. package/lib/commonjs/internal/telemetry-context.js +70 -0
  70. package/lib/commonjs/internal/telemetry-context.js.map +1 -0
  71. package/lib/commonjs/modules/analytics.js +18 -25
  72. package/lib/commonjs/modules/analytics.js.map +1 -1
  73. package/lib/commonjs/modules/crash-reporting.js +27 -6
  74. package/lib/commonjs/modules/crash-reporting.js.map +1 -1
  75. package/lib/commonjs/modules/log.js +1 -1
  76. package/lib/commonjs/modules/notifications.js +500 -0
  77. package/lib/commonjs/modules/notifications.js.map +1 -0
  78. package/lib/commonjs/modules/performance.js +57 -8
  79. package/lib/commonjs/modules/performance.js.map +1 -1
  80. package/lib/commonjs/native/module.js +6 -0
  81. package/lib/commonjs/native/module.js.map +1 -1
  82. package/lib/commonjs/native/spec.js +12 -5
  83. package/lib/commonjs/native/spec.js.map +1 -1
  84. package/lib/commonjs/purchases.js +4 -4
  85. package/lib/commonjs/types.js +12 -15
  86. package/lib/commonjs/types.js.map +1 -1
  87. package/lib/module/attribution.js +4 -3
  88. package/lib/module/attribution.js.map +1 -1
  89. package/lib/module/identity.js +12 -11
  90. package/lib/module/identity.js.map +1 -1
  91. package/lib/module/index.js +8 -4
  92. package/lib/module/index.js.map +1 -1
  93. package/lib/module/internal/config.js +103 -8
  94. package/lib/module/internal/config.js.map +1 -1
  95. package/lib/module/internal/telemetry-context.js +63 -0
  96. package/lib/module/internal/telemetry-context.js.map +1 -0
  97. package/lib/module/modules/analytics.js +18 -25
  98. package/lib/module/modules/analytics.js.map +1 -1
  99. package/lib/module/modules/crash-reporting.js +27 -6
  100. package/lib/module/modules/crash-reporting.js.map +1 -1
  101. package/lib/module/modules/log.js +1 -1
  102. package/lib/module/modules/notifications.js +491 -0
  103. package/lib/module/modules/notifications.js.map +1 -0
  104. package/lib/module/modules/performance.js +57 -8
  105. package/lib/module/modules/performance.js.map +1 -1
  106. package/lib/module/native/module.js +6 -1
  107. package/lib/module/native/module.js.map +1 -1
  108. package/lib/module/native/spec.js +11 -4
  109. package/lib/module/native/spec.js.map +1 -1
  110. package/lib/module/purchases.js +4 -4
  111. package/lib/module/types.js +12 -15
  112. package/lib/module/types.js.map +1 -1
  113. package/lib/typescript/commonjs/attribution.d.ts +3 -2
  114. package/lib/typescript/commonjs/attribution.d.ts.map +1 -1
  115. package/lib/typescript/commonjs/identity.d.ts.map +1 -1
  116. package/lib/typescript/commonjs/index.d.ts +2 -0
  117. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  118. package/lib/typescript/commonjs/internal/config.d.ts +16 -2
  119. package/lib/typescript/commonjs/internal/config.d.ts.map +1 -1
  120. package/lib/typescript/commonjs/internal/telemetry-context.d.ts +22 -0
  121. package/lib/typescript/commonjs/internal/telemetry-context.d.ts.map +1 -0
  122. package/lib/typescript/commonjs/modules/analytics.d.ts +8 -11
  123. package/lib/typescript/commonjs/modules/analytics.d.ts.map +1 -1
  124. package/lib/typescript/commonjs/modules/crash-reporting.d.ts +18 -5
  125. package/lib/typescript/commonjs/modules/crash-reporting.d.ts.map +1 -1
  126. package/lib/typescript/commonjs/modules/notifications.d.ts +110 -0
  127. package/lib/typescript/commonjs/modules/notifications.d.ts.map +1 -0
  128. package/lib/typescript/commonjs/modules/performance.d.ts +13 -0
  129. package/lib/typescript/commonjs/modules/performance.d.ts.map +1 -1
  130. package/lib/typescript/commonjs/native/module.d.ts +2 -0
  131. package/lib/typescript/commonjs/native/module.d.ts.map +1 -1
  132. package/lib/typescript/commonjs/native/spec.d.ts +33 -4
  133. package/lib/typescript/commonjs/native/spec.d.ts.map +1 -1
  134. package/lib/typescript/commonjs/purchases.d.ts +4 -4
  135. package/lib/typescript/commonjs/types.d.ts +4 -5
  136. package/lib/typescript/commonjs/types.d.ts.map +1 -1
  137. package/lib/typescript/module/attribution.d.ts +3 -2
  138. package/lib/typescript/module/attribution.d.ts.map +1 -1
  139. package/lib/typescript/module/identity.d.ts.map +1 -1
  140. package/lib/typescript/module/index.d.ts +2 -0
  141. package/lib/typescript/module/index.d.ts.map +1 -1
  142. package/lib/typescript/module/internal/config.d.ts +16 -2
  143. package/lib/typescript/module/internal/config.d.ts.map +1 -1
  144. package/lib/typescript/module/internal/telemetry-context.d.ts +22 -0
  145. package/lib/typescript/module/internal/telemetry-context.d.ts.map +1 -0
  146. package/lib/typescript/module/modules/analytics.d.ts +8 -11
  147. package/lib/typescript/module/modules/analytics.d.ts.map +1 -1
  148. package/lib/typescript/module/modules/crash-reporting.d.ts +18 -5
  149. package/lib/typescript/module/modules/crash-reporting.d.ts.map +1 -1
  150. package/lib/typescript/module/modules/notifications.d.ts +110 -0
  151. package/lib/typescript/module/modules/notifications.d.ts.map +1 -0
  152. package/lib/typescript/module/modules/performance.d.ts +13 -0
  153. package/lib/typescript/module/modules/performance.d.ts.map +1 -1
  154. package/lib/typescript/module/native/module.d.ts +2 -0
  155. package/lib/typescript/module/native/module.d.ts.map +1 -1
  156. package/lib/typescript/module/native/spec.d.ts +33 -4
  157. package/lib/typescript/module/native/spec.d.ts.map +1 -1
  158. package/lib/typescript/module/purchases.d.ts +4 -4
  159. package/lib/typescript/module/types.d.ts +4 -5
  160. package/lib/typescript/module/types.d.ts.map +1 -1
  161. package/package.json +12 -4
  162. package/src/attribution.ts +4 -3
  163. package/src/identity.ts +12 -11
  164. package/src/index.ts +16 -4
  165. package/src/internal/config.ts +113 -8
  166. package/src/internal/telemetry-context.ts +76 -0
  167. package/src/modules/analytics.ts +24 -33
  168. package/src/modules/crash-reporting.ts +50 -9
  169. package/src/modules/log.ts +1 -1
  170. package/src/modules/notifications.ts +557 -0
  171. package/src/modules/performance.ts +94 -14
  172. package/src/native/module.ts +6 -0
  173. package/src/native/spec.ts +45 -10
  174. package/src/purchases.ts +4 -4
  175. package/src/types.ts +12 -15
  176. package/android/vendor/java/com/appswissknife/analytics/EventQueueStore.kt +0 -326
  177. package/android/vendor/java/com/appswissknife/analytics/FlushEventsWorker.kt +0 -296
@@ -1,3 +1,7 @@
1
+ import {
2
+ captureTelemetryContext,
3
+ setTelemetryTraceReader,
4
+ } from "../internal/telemetry-context";
1
5
  // packages/react-native-sdk/src/modules/performance.ts
2
6
  //
3
7
  // Sentry-compatible performance monitoring SDK for swiss-knife (React Native).
@@ -21,6 +25,7 @@ export interface PerformanceConfig {
21
25
  serverURL?: string;
22
26
  environment?: string;
23
27
  release?: string;
28
+ buildNumber?: string;
24
29
  enableAutoHTTP?: boolean;
25
30
  /** Transaction sample rate (0.0 to 1.0, default 1.0). */
26
31
  tracesSampleRate?: number;
@@ -31,6 +36,12 @@ export interface PerformanceConfig {
31
36
  * `tracesSampleRate`.
32
37
  */
33
38
  tracesSampler?: (context: { name: string; op?: string }) => number;
39
+ /**
40
+ * Record the cold start as an `app.start` transaction, from the moment this
41
+ * module loaded to your call of `Performance.finishAppStart()` (call it when
42
+ * the first screen is interactive). Off by default; sampling applies.
43
+ */
44
+ trackAppStart?: boolean;
34
45
  }
35
46
 
36
47
  /** Stall aggregation attached to the transaction payload as `measurements`. */
@@ -140,7 +151,11 @@ class SpanImpl implements SKSpan {
140
151
  private _data: Record<string, unknown> = {};
141
152
  private children: SpanImpl[] = [];
142
153
 
143
- constructor(op: string, description: string | undefined, parentSpanId: string) {
154
+ constructor(
155
+ op: string,
156
+ description: string | undefined,
157
+ parentSpanId: string
158
+ ) {
144
159
  this.spanId = generateSpanId();
145
160
  this.parentSpanId = parentSpanId;
146
161
  this.op = op;
@@ -201,6 +216,11 @@ class TransactionImpl implements SKTransaction {
201
216
  readonly name: string;
202
217
  readonly op: string;
203
218
 
219
+ readonly correlation = captureTelemetryContext();
220
+ readonly delivery = _config ? { ..._config } : null;
221
+ private readonly capturedBuild = _config?.buildNumber;
222
+ private readonly capturedRelease = _config?.release;
223
+ private readonly capturedEnvironment = _config?.environment ?? "production";
204
224
  private startTime: Date;
205
225
  private endTime: Date | null = null;
206
226
  private status = "ok";
@@ -213,12 +233,12 @@ class TransactionImpl implements SKTransaction {
213
233
  stallLongestMs: 0,
214
234
  };
215
235
 
216
- constructor(name: string, op: string) {
236
+ constructor(name: string, op: string, startedAt?: Date) {
217
237
  this.traceId = generateTraceId();
218
238
  this.spanId = generateSpanId();
219
239
  this.name = name;
220
240
  this.op = op;
221
- this.startTime = new Date();
241
+ this.startTime = startedAt ?? new Date();
222
242
  // Stall tracking runs for every real (non-sampled-out) transaction,
223
243
  // including the navigation-tracker ones constructed directly.
224
244
  registerOpenTransaction(this);
@@ -276,14 +296,16 @@ class TransactionImpl implements SKTransaction {
276
296
 
277
297
  const payload: Record<string, unknown> = {
278
298
  traceId: this.traceId,
299
+ spanId: this.spanId,
279
300
  name: this.name,
280
301
  op: this.op,
281
302
  startTimestamp: this.startTime.toISOString(),
282
303
  endTimestamp: end.toISOString(),
283
304
  status: this.status,
284
305
  spans: childPayloads,
285
- release: _config?.release,
286
- environment: _config?.environment ?? "production",
306
+ release: this.capturedRelease,
307
+ buildNumber: this.capturedBuild,
308
+ environment: this.capturedEnvironment,
287
309
  measurements: { ...this.stalls },
288
310
  contexts: {
289
311
  os: { name: "React Native" },
@@ -309,17 +331,33 @@ class TransactionImpl implements SKTransaction {
309
331
 
310
332
  // No-op transaction (returned when sampling drops a transaction)
311
333
  const noopSpan: SKSpan = {
312
- spanId: "", parentSpanId: "", op: "",
313
- startChild() { return noopSpan; }, finish() {}, setTag() {}, setData() {},
334
+ spanId: "",
335
+ parentSpanId: "",
336
+ op: "",
337
+ startChild() {
338
+ return noopSpan;
339
+ },
340
+ finish() {},
341
+ setTag() {},
342
+ setData() {},
314
343
  };
315
344
  const noopTransaction: SKTransaction = {
316
- traceId: "", spanId: "", name: "", op: "",
317
- startChild() { return noopSpan; }, finish() {}, setTag() {}, setData() {},
345
+ traceId: "",
346
+ spanId: "",
347
+ name: "",
348
+ op: "",
349
+ startChild() {
350
+ return noopSpan;
351
+ },
352
+ finish() {},
353
+ setTag() {},
354
+ setData() {},
318
355
  };
319
356
 
320
357
  let _config: PerformanceConfig | null = null;
321
358
  let _originalFetch: typeof fetch | null = null;
322
359
  let _activeTransaction: TransactionImpl | null = null;
360
+ setTelemetryTraceReader(() => _activeTransaction?.traceId);
323
361
  let _txQueue: TransactionImpl[] = [];
324
362
  let _txFlushTimer: ReturnType<typeof setTimeout> | null = null;
325
363
 
@@ -370,20 +408,24 @@ async function flushTransactions(): Promise<void> {
370
408
  const batch = _txQueue;
371
409
  _txQueue = [];
372
410
 
373
- const baseURL = _config.serverURL || "https://api.swiss-knife.dev";
374
- const url = `${baseURL}/api/sdk/errors/transaction`;
375
411
  // Use original fetch if we've patched it
376
412
  const fetchFn = _originalFetch ?? fetch;
377
413
 
378
414
  for (const transaction of batch) {
415
+ const config = transaction.delivery;
416
+ if (!config) continue;
417
+ const url = `${config.serverURL || "https://api.swiss-knife.dev"}/api/sdk/errors/transaction`;
379
418
  try {
380
419
  const res = await fetchFn(url, {
381
420
  method: "POST",
382
421
  headers: {
383
422
  "Content-Type": "application/json",
384
- "X-API-Key": _config.apiKey,
423
+ "X-API-Key": config.apiKey,
385
424
  },
386
- body: JSON.stringify(transaction._toPayload()),
425
+ body: JSON.stringify({
426
+ ...transaction._toPayload(),
427
+ ...(await transaction.correlation),
428
+ }),
387
429
  });
388
430
 
389
431
  if (!res.ok) {
@@ -470,7 +512,10 @@ function createNavigationTracker(): (state: unknown) => void {
470
512
 
471
513
  function getActiveRouteName(state: unknown): string | null {
472
514
  if (!state || typeof state !== "object") return null;
473
- const s = state as { index?: number; routes?: Array<{ name: string; state?: unknown }> };
515
+ const s = state as {
516
+ index?: number;
517
+ routes?: Array<{ name: string; state?: unknown }>;
518
+ };
474
519
  if (!s.routes || s.index === undefined) return null;
475
520
  const route = s.routes[s.index];
476
521
  if (!route) return null;
@@ -504,6 +549,23 @@ function createNavigationTracker(): (state: unknown) => void {
504
549
  };
505
550
  }
506
551
 
552
+ // MARK: - App Start
553
+
554
+ /** When this module was evaluated: the best JS-side stand-in for process start. */
555
+ const MODULE_LOADED_AT = new Date();
556
+ let _appStart: SKTransaction | null = null;
557
+ let _appStartDone = false;
558
+
559
+ function beginAppStart(): void {
560
+ if (_appStartDone || _appStart) return;
561
+ const rate = resolveSampleRate("app.start", "app.start");
562
+ if (rate <= 0 || (rate < 1.0 && Math.random() > rate)) {
563
+ _appStartDone = true;
564
+ return;
565
+ }
566
+ _appStart = new TransactionImpl("app.start", "app.start", MODULE_LOADED_AT);
567
+ }
568
+
507
569
  // MARK: - Main Export
508
570
 
509
571
  export const Performance = {
@@ -517,6 +579,22 @@ export const Performance = {
517
579
  if (_config.enableAutoHTTP) {
518
580
  installFetchInstrumentation();
519
581
  }
582
+ if (_config.trackAppStart) {
583
+ beginAppStart();
584
+ }
585
+ },
586
+
587
+ /**
588
+ * Ends the `app.start` transaction begun by `trackAppStart: true`. Call it
589
+ * when the first screen is interactive. Once per launch; a no-op when
590
+ * app-start tracking is off, sampled out, or already finished.
591
+ */
592
+ finishAppStart(status = "ok"): void {
593
+ if (!_appStart) return;
594
+ const tx = _appStart;
595
+ _appStart = null;
596
+ _appStartDone = true;
597
+ tx.finish(status);
520
598
  },
521
599
 
522
600
  startTransaction(name: string, op: string): SKTransaction {
@@ -557,6 +635,8 @@ export const Performance = {
557
635
 
558
636
  _reset(): void {
559
637
  _config = null;
638
+ _appStart = null;
639
+ _appStartDone = false;
560
640
  _activeTransaction = null;
561
641
  _txQueue = [];
562
642
  if (_txFlushTimer !== null) {
@@ -3,6 +3,7 @@ import {
3
3
  NativeModules,
4
4
  NativeEventEmitter,
5
5
  TurboModuleRegistry,
6
+ Platform,
6
7
  } from "react-native";
7
8
  import type { SwissKnifePurchasesNativeModule } from "./spec";
8
9
 
@@ -34,6 +35,11 @@ export function getNativeModule(): SwissKnifePurchasesNativeModule {
34
35
  return mod;
35
36
  }
36
37
 
38
+ /** "ios" or "android" (anything else is treated as android, the only other native target). */
39
+ export function getPlatformOS(): "ios" | "android" {
40
+ return Platform.OS === "ios" ? "ios" : "android";
41
+ }
42
+
37
43
  export function getEventEmitter(): NativeEventEmitter {
38
44
  if (cachedEmitter) return cachedEmitter;
39
45
  cachedEmitter = new NativeEventEmitter(getNativeModule());
@@ -1,9 +1,9 @@
1
1
  // src/native/spec.ts
2
2
  // The contract the native module must implement. All params/returns are
3
- // JSON-serializable plain objects — the RN bridge marshals them. Phase 7 of
4
- // the SDK rip-and-replace cut the implementation over from PHC to our own
5
- // SwissKnifeiOS (StoreKit 2) and swiss-knife-android (Play Billing v8) AARs;
6
- // this TS spec is what both sides of the bridge now agree on.
3
+ // JSON-serializable plain objects — the RN bridge marshals them. Both sides
4
+ // are this package's own native SDKs, SwissKnifeiOS (StoreKit 2) and
5
+ // swiss-knife-android (Play Billing v8); this TS spec is what the two bridges
6
+ // agree on.
7
7
  import type { TurboModule } from "react-native";
8
8
  import type {
9
9
  CustomerInfo,
@@ -38,6 +38,29 @@ export interface NativeConfigureOptions {
38
38
  // The event name RC emits on CustomerInfo changes; SP-2b must emit the same name.
39
39
  export const CUSTOMER_INFO_UPDATED_EVENT = "Purchases-CustomerInfoUpdated";
40
40
 
41
+ /** Emitted by native when a Swiss Knife push notification (or one of its action buttons) is tapped. */
42
+ export const PUSH_OPENED_EVENT = "SwissKnife-PushOpened";
43
+
44
+ /** Wire shape of a tapped notification, both platforms. */
45
+ export interface NativePushOpen {
46
+ messageId?: string;
47
+ deliveryId?: string;
48
+ link?: string;
49
+ actionId?: string;
50
+ /** Raw notification data (iOS: full userInfo; Android: the string data map). */
51
+ data?: Record<string, unknown>;
52
+ }
53
+
54
+ /** Facts only native knows, for the JS-only token registration path. */
55
+ export interface NativePushDeviceInfo {
56
+ bundleId: string;
57
+ appVersion?: string;
58
+ osVersion?: string;
59
+ sdkVersion?: string;
60
+ /** iOS only: "production" | "sandbox" derived from the provisioning profile. */
61
+ environment?: string;
62
+ }
63
+
41
64
  // Resolved via `TurboModuleRegistry.get<T>` on the New Architecture, so it must
42
65
  // be a `TurboModule` (RN constrains `get<T extends TurboModule>`). `TurboModule`
43
66
  // only adds an optional `getConstants?(): {}`, which the native side doesn't use.
@@ -91,7 +114,7 @@ export interface SwissKnifePurchasesNativeModule extends TurboModule {
91
114
  getAppUserID(): Promise<string>;
92
115
  isAnonymous(): Promise<boolean>;
93
116
 
94
- // Wave 1 — unified Identity surface. Mirrors `SwissKnife.Identity` on
117
+ // Identity. Mirrors `SwissKnife.Identity` on
95
118
  // iOS and `com.appswissknife.identity.Identity` on Android. JS code
96
119
  // should prefer these over the per-leg `logIn` / `logOut` /
97
120
  // `getAppUserID` / `isAnonymous` above. The legacy methods stay on
@@ -102,9 +125,9 @@ export interface SwissKnifePurchasesNativeModule extends TurboModule {
102
125
 
103
126
  /**
104
127
  * Identify this device as a known user. Native posts the
105
- * (anonymous_id, user_id) pair to /api/sdk/users/identify (the
106
- * bug-fixed behaviour on Android — pre-Wave-1 Android did NOT POST)
107
- * and rebinds entitlements + analytics user_id from the same callsite.
128
+ * (anonymous_id, user_id) pair to /api/sdk/users/identify on both
129
+ * platforms and rebinds entitlements + analytics user_id from the same
130
+ * callsite.
108
131
  */
109
132
  identityLogIn(userId: string): Promise<LogInResult>;
110
133
 
@@ -130,7 +153,7 @@ export interface SwissKnifePurchasesNativeModule extends TurboModule {
130
153
  */
131
154
  sessionCurrent(): Promise<{ id: string; sessionNumber: number; startedAt: number }>;
132
155
 
133
- // Wave 2 — Attribution. Native owns the disk-backed cache + the
156
+ // Attribution. Native owns the disk-backed cache + the
134
157
  // ATT prompt orchestration (iOS) and the AdvertisingId/InstallReferrer
135
158
  // collectors (Android). JS is a thin passthrough; see
136
159
  // `packages/react-native-sdk/src/attribution.ts`.
@@ -159,6 +182,18 @@ export interface SwissKnifePurchasesNativeModule extends TurboModule {
159
182
  setPhoneNumber(phoneNumber: string | null): Promise<void>;
160
183
  setPushToken(pushToken: string | null): Promise<void>;
161
184
 
185
+ // ---- Push notifications (swiss-push) — see src/modules/notifications.ts ----
186
+
187
+ /** Prompt for notification permission. `provisional` is iOS-only (ignored on Android). Resolves the wire status string. */
188
+ pushRequestPermission(provisional: boolean): Promise<string>;
189
+ pushPermissionStatus(): Promise<string>;
190
+ /** iOS: registerForRemoteNotifications + delegate proxy. Android: fetch the FCM token via the native SDK. */
191
+ pushRegister(): Promise<void>;
192
+ pushUnregister(): Promise<void>;
193
+ /** The notification that launched the app, once; null when none. */
194
+ pushGetInitialNotification(): Promise<NativePushOpen | null>;
195
+ pushDeviceInfo(): Promise<NativePushDeviceInfo>;
196
+
162
197
  setLogLevel(level: string): Promise<void>;
163
198
 
164
199
  /**
@@ -189,7 +224,7 @@ export interface SwissKnifePurchasesNativeModule extends TurboModule {
189
224
  /**
190
225
  * Persist a pre-built analytics event onto the native disk-backed queue.
191
226
  *
192
- * Phase 2.3 of the RC rip-and-replace: JS owns the payload shape (event_id,
227
+ * JS owns the payload shape (event_id,
193
228
  * device_id, super properties, timed-event duration, identify merges) and
194
229
  * native owns the queue (disk persistence on iOS Caches / Android cacheDir,
195
230
  * exponential back-off, dead-letter on permanent failure). Once this
package/src/purchases.ts CHANGED
@@ -320,7 +320,7 @@ export class Purchases {
320
320
  * Works after `SwissKnife.configure`, `SwissKnife.configureCore`, or
321
321
  * `Analytics.init` — the store does not have to be ours.
322
322
  *
323
- * @deprecated Wave 1 — prefer `Identity.logIn(userId)`. This alias exists so
323
+ * @deprecated Prefer `Identity.logIn(userId)`. This alias exists so
324
324
  * RevenueCat migrations compile unchanged; it is a pure delegation, so there
325
325
  * is nothing to gain by keeping it and one less name to learn by dropping it.
326
326
  */
@@ -341,7 +341,7 @@ export class Purchases {
341
341
  * the same record, built in JS, on both platforms. Do not read that as a
342
342
  * store error; if you want real entitlements, call `getCustomerInfo()`.
343
343
  *
344
- * @deprecated Wave 1 — prefer `Identity.logOut()`, which does not pretend to
344
+ * @deprecated Prefer `Identity.logOut()`, which does not pretend to
345
345
  * return store state.
346
346
  */
347
347
  static async logOut(): Promise<CustomerInfo> {
@@ -359,7 +359,7 @@ export class Purchases {
359
359
  * gateway's own anonymous id is a different, per-process value, and this
360
360
  * alias deliberately does not report it.
361
361
  *
362
- * @deprecated Wave 1 — prefer `Identity.current()`, which hands back the
362
+ * @deprecated Prefer `Identity.current()`, which hands back the
363
363
  * anonymous id, the user id and `isAnonymous` in one read instead of forcing
364
364
  * two calls that can interleave.
365
365
  */
@@ -375,7 +375,7 @@ export class Purchases {
375
375
  * Exactly `(await Identity.current()).isAnonymous`, so it tracks
376
376
  * `Identity.reset()` and `Identity.wipe()` on both platforms.
377
377
  *
378
- * @deprecated Wave 1 — prefer `Identity.current()`; see
378
+ * @deprecated Prefer `Identity.current()`; see
379
379
  * {@link getAppUserID}.
380
380
  */
381
381
  static async isAnonymous(): Promise<boolean> {
package/src/types.ts CHANGED
@@ -1,10 +1,8 @@
1
1
  // packages/react-native-sdk/src/types.ts
2
2
  //
3
- // Phase 7 of the RC rip-and-replace: own TypeScript type definitions that
4
- // REPLACE the previous star-export of `@revenuecat/purchases-typescript-internal`.
5
- // Shape mirrors RC's public API (same field names, same semantics) per the
6
- // user-locked decision in the Phase 7 plan, so consumers of this SDK keep
7
- // working without any source change.
3
+ // This package's own TypeScript type definitions. Their shape mirrors
4
+ // RevenueCat's public API (same names, same field names, same semantics), so
5
+ // code written against `react-native-purchases` types compiles against these.
8
6
  //
9
7
  // Why mirror RC names?
10
8
  // - The public JS surface (`Purchases.configure`, `Purchases.getCustomerInfo`,
@@ -14,9 +12,9 @@
14
12
  // types (defined in `packages/swiss-knife-{ios,android}`) into payloads
15
13
  // that match these TS shapes. One contract on both sides of the bridge.
16
14
  //
17
- // What's gone:
18
- // - The dep on `@revenuecat/purchases-typescript-internal` — removed from
19
- // package.json. No more PHC-licensed code ships in the SDK.
15
+ // No RevenueCat package is a dependency: these are not re-exported from
16
+ // `@revenuecat/purchases-typescript-internal`, and no RevenueCat code ships in
17
+ // the SDK.
20
18
  //
21
19
  // What's preserved:
22
20
  // - Re-exported names (`PurchasesEntitlementInfo`, `PurchasesOfferings`,
@@ -61,9 +59,9 @@ export const PACKAGE_TYPE = {
61
59
  export type PACKAGE_TYPE = (typeof PACKAGE_TYPE)[keyof typeof PACKAGE_TYPE];
62
60
 
63
61
  /**
64
- * StoreKit version selection on iOS. We only support StoreKit 2 in Phase 5+,
65
- * but the enum stays for source compatibility — `configure({ storeKitVersion:
66
- * STOREKIT_VERSION.STOREKIT_2 })` is a no-op now.
62
+ * StoreKit version selection on iOS. The SDK always uses StoreKit 2; the enum
63
+ * stays for source compatibility, and `configure({ storeKitVersion: ... })` is
64
+ * a no-op.
67
65
  */
68
66
  export const STOREKIT_VERSION = {
69
67
  DEFAULT: "DEFAULT",
@@ -381,15 +379,14 @@ export interface LogInResult {
381
379
  created: boolean;
382
380
  }
383
381
 
384
- // MARK: - Identity (Wave 1)
382
+ // MARK: - Identity
385
383
 
386
384
  /**
387
385
  * Immutable snapshot of the current identity. Mirrors
388
386
  * `SwissKnife.Identity.Snapshot` (iOS) and
389
387
  * `com.appswissknife.identity.Identity.Snapshot` (Android).
390
388
  *
391
- * The `anonymousId` carries the unified `$SKAnonymousID:` prefix as of
392
- * Wave 1 (was `$RCAnonymousID:` on Android pre-Wave-1).
389
+ * The `anonymousId` carries the `$SKAnonymousID:` prefix on both platforms.
393
390
  */
394
391
  export interface IdentitySnapshot {
395
392
  anonymousId: string;
@@ -403,7 +400,7 @@ export interface IdentityChange {
403
400
  current: IdentitySnapshot;
404
401
  }
405
402
 
406
- // MARK: - Attribution (Wave 2)
403
+ // MARK: - Attribution
407
404
 
408
405
  /**
409
406
  * Resolved attribution for the install. Mirrors