@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.
- package/CHANGELOG.md +385 -2
- package/LICENSE +21 -0
- package/README.md +229 -42
- package/SwissKnifePurchases.podspec +1 -1
- package/android/build.gradle +24 -2
- package/android/consumer-rules.pro +12 -0
- package/android/src/main/AndroidManifest.xml +15 -1
- package/android/src/main/java/com/swissknife/crashreporting/SKCrashReportingModule.kt +5 -4
- package/android/src/main/java/com/swissknife/purchases/SwissKnifeJson.kt +7 -2
- package/android/src/main/java/com/swissknife/purchases/SwissKnifePurchasesModule.kt +168 -6
- package/android/src/play/java/com/swissknife/purchases/StoreIntentHandler.kt +7 -0
- package/android/src/rustore/java/com/swissknife/purchases/StoreIntentHandler.kt +9 -0
- package/android/vendor/java/com/appswissknife/SwissKnife.kt +107 -38
- package/android/vendor/java/com/appswissknife/analytics/SKAnalytics.kt +180 -115
- package/android/vendor/java/com/appswissknife/attributes/AttributesClient.kt +16 -18
- package/android/vendor/java/com/appswissknife/attributes/SetAttributesWorker.kt +13 -13
- package/android/vendor/java/com/appswissknife/attribution/Attribution.kt +56 -25
- package/android/vendor/java/com/appswissknife/context/DeviceContext.kt +1 -1
- package/android/vendor/java/com/appswissknife/crashreporting/SKCrashReporting.kt +365 -206
- package/android/vendor/java/com/appswissknife/entitlements/EntitlementsRepository.kt +195 -26
- package/android/vendor/java/com/appswissknife/identity/Identity.kt +31 -6
- package/android/vendor/java/com/appswissknife/models/PurchasesError.kt +5 -0
- package/android/vendor/java/com/appswissknife/net/BackendHttpClient.kt +56 -31
- package/android/vendor/java/com/appswissknife/net/IngestClient.kt +673 -87
- package/android/vendor/java/com/appswissknife/net/OfflineQueueStore.kt +214 -30
- package/android/vendor/java/com/appswissknife/notifications/NotificationRenderer.kt +195 -0
- package/android/vendor/java/com/appswissknife/notifications/PermissionRequestActivity.kt +60 -0
- package/android/vendor/java/com/appswissknife/notifications/PermissionStatus.kt +41 -0
- package/android/vendor/java/com/appswissknife/notifications/PushEventQueue.kt +143 -0
- package/android/vendor/java/com/appswissknife/notifications/PushPayload.kt +72 -0
- package/android/vendor/java/com/appswissknife/notifications/PushRegistration.kt +89 -0
- package/android/vendor/java/com/appswissknife/notifications/SwissKnifeMessagingService.kt +57 -0
- package/android/vendor/java/com/appswissknife/notifications/SwissKnifeNotifications.kt +438 -0
- package/android/vendor/java/com/appswissknife/offerings/OfferingsRepository.kt +266 -64
- package/android/vendor/java/com/appswissknife/performance/SKPerformance.kt +1 -0
- package/android/vendor/java/com/appswissknife/purchases/BillingClientGateway.kt +545 -88
- package/android/vendor/java/com/appswissknife/purchases/PlayPriceEnrichmentProvider.kt +55 -24
- package/android/vendor/java/com/appswissknife/purchases/ProductKindHint.kt +21 -0
- package/android/vendor/java/com/appswissknife/purchases/PurchasesGateway.kt +14 -0
- package/android/vendor-rustore/AndroidManifest.xml +59 -0
- package/android/vendor-rustore/java/com/appswissknife/rustore/RuStoreGateway.kt +428 -0
- package/android/vendor-rustore/java/com/appswissknife/rustore/RuStoreInitProvider.kt +43 -0
- package/android/vendor-rustore/java/com/appswissknife/rustore/RuStorePriceEnrichmentProvider.kt +85 -0
- package/app.plugin.js +287 -0
- package/ios/SwissKnifePurchases.m +20 -0
- package/ios/SwissKnifePurchases.swift +97 -3
- package/ios/SwissKnifePushBootstrap.m +34 -0
- package/ios/vendor/SwissKnifeiOS/Analytics/SKAnalytics.swift +138 -89
- package/ios/vendor/SwissKnifeiOS/Context/DeviceContext.swift +1 -1
- package/ios/vendor/SwissKnifeiOS/CrashReporting/SKCrashReporting.swift +345 -44
- package/ios/vendor/SwissKnifeiOS/Net/BackendBackoffGate.swift +43 -2
- package/ios/vendor/SwissKnifeiOS/Net/IngestClient.swift +495 -16
- package/ios/vendor/SwissKnifeiOS/Net/OfflineQueueStore.swift +231 -23
- package/ios/vendor/SwissKnifeiOS/Notifications/PushPayload.swift +87 -0
- package/ios/vendor/SwissKnifeiOS/Notifications/PushRegistrar.swift +322 -0
- package/ios/vendor/SwissKnifeiOS/Notifications/SwissKnife+Notifications.swift +403 -0
- package/ios/vendor/SwissKnifeiOS/Performance/SKPerformance.swift +1 -0
- package/ios/vendor/SwissKnifeiOS/Services/EntitlementsService.swift +11 -7
- package/ios/vendor/SwissKnifeiOS/Services/PurchaseService.swift +38 -7
- package/ios/vendor/SwissKnifeiOS/SwissKnife.swift +34 -6
- package/lib/commonjs/attribution.js +4 -3
- package/lib/commonjs/attribution.js.map +1 -1
- package/lib/commonjs/identity.js +12 -11
- package/lib/commonjs/identity.js.map +1 -1
- package/lib/commonjs/index.js +16 -5
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/internal/config.js +105 -8
- package/lib/commonjs/internal/config.js.map +1 -1
- package/lib/commonjs/internal/telemetry-context.js +70 -0
- package/lib/commonjs/internal/telemetry-context.js.map +1 -0
- package/lib/commonjs/modules/analytics.js +18 -25
- package/lib/commonjs/modules/analytics.js.map +1 -1
- package/lib/commonjs/modules/crash-reporting.js +27 -6
- package/lib/commonjs/modules/crash-reporting.js.map +1 -1
- package/lib/commonjs/modules/log.js +1 -1
- package/lib/commonjs/modules/notifications.js +500 -0
- package/lib/commonjs/modules/notifications.js.map +1 -0
- package/lib/commonjs/modules/performance.js +57 -8
- package/lib/commonjs/modules/performance.js.map +1 -1
- package/lib/commonjs/native/module.js +6 -0
- package/lib/commonjs/native/module.js.map +1 -1
- package/lib/commonjs/native/spec.js +12 -5
- package/lib/commonjs/native/spec.js.map +1 -1
- package/lib/commonjs/purchases.js +4 -4
- package/lib/commonjs/types.js +12 -15
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/attribution.js +4 -3
- package/lib/module/attribution.js.map +1 -1
- package/lib/module/identity.js +12 -11
- package/lib/module/identity.js.map +1 -1
- package/lib/module/index.js +8 -4
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal/config.js +103 -8
- package/lib/module/internal/config.js.map +1 -1
- package/lib/module/internal/telemetry-context.js +63 -0
- package/lib/module/internal/telemetry-context.js.map +1 -0
- package/lib/module/modules/analytics.js +18 -25
- package/lib/module/modules/analytics.js.map +1 -1
- package/lib/module/modules/crash-reporting.js +27 -6
- package/lib/module/modules/crash-reporting.js.map +1 -1
- package/lib/module/modules/log.js +1 -1
- package/lib/module/modules/notifications.js +491 -0
- package/lib/module/modules/notifications.js.map +1 -0
- package/lib/module/modules/performance.js +57 -8
- package/lib/module/modules/performance.js.map +1 -1
- package/lib/module/native/module.js +6 -1
- package/lib/module/native/module.js.map +1 -1
- package/lib/module/native/spec.js +11 -4
- package/lib/module/native/spec.js.map +1 -1
- package/lib/module/purchases.js +4 -4
- package/lib/module/types.js +12 -15
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/commonjs/attribution.d.ts +3 -2
- package/lib/typescript/commonjs/attribution.d.ts.map +1 -1
- package/lib/typescript/commonjs/identity.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +2 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/internal/config.d.ts +16 -2
- package/lib/typescript/commonjs/internal/config.d.ts.map +1 -1
- package/lib/typescript/commonjs/internal/telemetry-context.d.ts +22 -0
- package/lib/typescript/commonjs/internal/telemetry-context.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/analytics.d.ts +8 -11
- package/lib/typescript/commonjs/modules/analytics.d.ts.map +1 -1
- package/lib/typescript/commonjs/modules/crash-reporting.d.ts +18 -5
- package/lib/typescript/commonjs/modules/crash-reporting.d.ts.map +1 -1
- package/lib/typescript/commonjs/modules/notifications.d.ts +110 -0
- package/lib/typescript/commonjs/modules/notifications.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/performance.d.ts +13 -0
- package/lib/typescript/commonjs/modules/performance.d.ts.map +1 -1
- package/lib/typescript/commonjs/native/module.d.ts +2 -0
- package/lib/typescript/commonjs/native/module.d.ts.map +1 -1
- package/lib/typescript/commonjs/native/spec.d.ts +33 -4
- package/lib/typescript/commonjs/native/spec.d.ts.map +1 -1
- package/lib/typescript/commonjs/purchases.d.ts +4 -4
- package/lib/typescript/commonjs/types.d.ts +4 -5
- package/lib/typescript/commonjs/types.d.ts.map +1 -1
- package/lib/typescript/module/attribution.d.ts +3 -2
- package/lib/typescript/module/attribution.d.ts.map +1 -1
- package/lib/typescript/module/identity.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +2 -0
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/internal/config.d.ts +16 -2
- package/lib/typescript/module/internal/config.d.ts.map +1 -1
- package/lib/typescript/module/internal/telemetry-context.d.ts +22 -0
- package/lib/typescript/module/internal/telemetry-context.d.ts.map +1 -0
- package/lib/typescript/module/modules/analytics.d.ts +8 -11
- package/lib/typescript/module/modules/analytics.d.ts.map +1 -1
- package/lib/typescript/module/modules/crash-reporting.d.ts +18 -5
- package/lib/typescript/module/modules/crash-reporting.d.ts.map +1 -1
- package/lib/typescript/module/modules/notifications.d.ts +110 -0
- package/lib/typescript/module/modules/notifications.d.ts.map +1 -0
- package/lib/typescript/module/modules/performance.d.ts +13 -0
- package/lib/typescript/module/modules/performance.d.ts.map +1 -1
- package/lib/typescript/module/native/module.d.ts +2 -0
- package/lib/typescript/module/native/module.d.ts.map +1 -1
- package/lib/typescript/module/native/spec.d.ts +33 -4
- package/lib/typescript/module/native/spec.d.ts.map +1 -1
- package/lib/typescript/module/purchases.d.ts +4 -4
- package/lib/typescript/module/types.d.ts +4 -5
- package/lib/typescript/module/types.d.ts.map +1 -1
- package/package.json +12 -4
- package/src/attribution.ts +4 -3
- package/src/identity.ts +12 -11
- package/src/index.ts +16 -4
- package/src/internal/config.ts +113 -8
- package/src/internal/telemetry-context.ts +76 -0
- package/src/modules/analytics.ts +24 -33
- package/src/modules/crash-reporting.ts +50 -9
- package/src/modules/log.ts +1 -1
- package/src/modules/notifications.ts +557 -0
- package/src/modules/performance.ts +94 -14
- package/src/native/module.ts +6 -0
- package/src/native/spec.ts +45 -10
- package/src/purchases.ts +4 -4
- package/src/types.ts +12 -15
- package/android/vendor/java/com/appswissknife/analytics/EventQueueStore.kt +0 -326
- 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(
|
|
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:
|
|
286
|
-
|
|
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: "",
|
|
313
|
-
|
|
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: "",
|
|
317
|
-
|
|
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":
|
|
423
|
+
"X-API-Key": config.apiKey,
|
|
385
424
|
},
|
|
386
|
-
body: JSON.stringify(
|
|
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 {
|
|
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) {
|
package/src/native/module.ts
CHANGED
|
@@ -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());
|
package/src/native/spec.ts
CHANGED
|
@@ -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.
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
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
|
-
//
|
|
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
|
|
106
|
-
*
|
|
107
|
-
*
|
|
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
|
-
//
|
|
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
|
-
*
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
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
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
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.
|
|
65
|
-
*
|
|
66
|
-
*
|
|
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
|
|
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
|
|
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
|
|
403
|
+
// MARK: - Attribution
|
|
407
404
|
|
|
408
405
|
/**
|
|
409
406
|
* Resolved attribution for the install. Mirrors
|