@app-swiss-knife/react-native-sdk 0.2.0 → 0.2.3

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 (27) hide show
  1. package/SwissKnifePurchases.podspec +16 -1
  2. package/android/src/main/java/com/swissknife/crashreporting/SKCrashReportingModule.kt +9 -3
  3. package/android/vendor/java/com/appswissknife/context/DeviceContext.kt +1 -1
  4. package/android/vendor/java/com/appswissknife/net/IngestClient.kt +1 -1
  5. package/android/vendor/java/com/appswissknife/purchases/BillingClientGateway.kt +106 -16
  6. package/ios/SwissKnifeCrashReporting.swift +19 -3
  7. package/ios/vendor/SwissKnifeiOS/Context/DeviceContext.swift +1 -1
  8. package/ios/vendor/SwissKnifeiOS/CrashReporting/SKCrashReporting.swift +153 -6
  9. package/lib/commonjs/modules/crash-reporting.js +108 -8
  10. package/lib/commonjs/modules/crash-reporting.js.map +1 -1
  11. package/lib/commonjs/purchases.js +60 -6
  12. package/lib/commonjs/purchases.js.map +1 -1
  13. package/lib/module/modules/crash-reporting.js +108 -8
  14. package/lib/module/modules/crash-reporting.js.map +1 -1
  15. package/lib/module/purchases.js +60 -7
  16. package/lib/module/purchases.js.map +1 -1
  17. package/lib/typescript/commonjs/modules/crash-reporting.d.ts +89 -0
  18. package/lib/typescript/commonjs/modules/crash-reporting.d.ts.map +1 -1
  19. package/lib/typescript/commonjs/purchases.d.ts +32 -1
  20. package/lib/typescript/commonjs/purchases.d.ts.map +1 -1
  21. package/lib/typescript/module/modules/crash-reporting.d.ts +89 -0
  22. package/lib/typescript/module/modules/crash-reporting.d.ts.map +1 -1
  23. package/lib/typescript/module/purchases.d.ts +32 -1
  24. package/lib/typescript/module/purchases.d.ts.map +1 -1
  25. package/package.json +1 -1
  26. package/src/modules/crash-reporting.ts +201 -18
  27. package/src/purchases.ts +65 -7
@@ -1,4 +1,36 @@
1
1
  import React from "react";
2
+ /**
3
+ * Optional native module for crash reporting. If the host app has linked
4
+ * the SwissKnife iOS/Android native crash SDKs, this module delegates
5
+ * init/setUser/addBreadcrumb to the native layer — catching Mach exceptions,
6
+ * signal crashes (iOS), and NDK native crashes (Android) that JS can't see.
7
+ */
8
+ interface SKCrashReportingNative {
9
+ start(config: {
10
+ apiKey: string;
11
+ serverURL: string;
12
+ ingestURL?: string;
13
+ environment: string;
14
+ release: string;
15
+ }): void;
16
+ setUser(user: {
17
+ id?: string;
18
+ email?: string;
19
+ username?: string;
20
+ } | null): void;
21
+ addBreadcrumb(breadcrumb: {
22
+ category?: string;
23
+ message?: string;
24
+ level?: string;
25
+ }): void;
26
+ setTag(key: string, value: string): void;
27
+ /**
28
+ * Wave-2 C1: capture a masked screenshot of the current window. Returns
29
+ * base64 JPEG (no `data:` prefix) or null. Optional — older native SDKs
30
+ * don't implement it, so every call site must feature-detect.
31
+ */
32
+ captureScreenshot?(): Promise<string | null>;
33
+ }
2
34
  export interface CrashReportingConfig {
3
35
  apiKey: string;
4
36
  serverURL?: string;
@@ -9,6 +41,54 @@ export interface CrashReportingConfig {
9
41
  dist?: string;
10
42
  maxBreadcrumbs?: number;
11
43
  enableAutoBreadcrumbs?: boolean;
44
+ /**
45
+ * Take over `ErrorUtils`' global JS error handler. Default **true**.
46
+ *
47
+ * We chain — the handler that was installed before us is still invoked —
48
+ * so leaving this on is safe alongside another reporter. Set false if the
49
+ * host wants Swiss Knife's manual APIs (`captureException`, breadcrumbs,
50
+ * sessions) without us touching the global slot at all.
51
+ */
52
+ enableGlobalErrorHandler?: boolean;
53
+ /**
54
+ * Track unhandled promise rejections. Default **true**.
55
+ *
56
+ * ⚠️ Unlike every other handler in this SDK, this one CANNOT be chained
57
+ * reliably. Both engines expose a single-slot switch with no getter:
58
+ * Hermes' `HermesInternal.enablePromiseRejectionTracker(options)` and JSC's
59
+ * `promise/setimmediate/rejection-tracking`.`enable(options)` each replace
60
+ * whatever was registered, and neither offers a way to read the incumbent
61
+ * back out. Sentry React Native calls exactly the same APIs.
62
+ *
63
+ * What we do about it:
64
+ * - We install a composing wrapper over the engine's `enable` entry point,
65
+ * so a reporter that initialises AFTER us is merged with us instead of
66
+ * replacing us. Both handlers then run.
67
+ * - The reverse order is unfixable. If another reporter installed BEFORE
68
+ * Swiss Knife and did not itself chain, its handler is unreachable and
69
+ * ours replaces it. Either initialise Swiss Knife first, or set this to
70
+ * false — the rest of the SDK (manual captures, breadcrumbs, sessions,
71
+ * the global error handler, native crashes) is unaffected either way.
72
+ */
73
+ enablePromiseRejectionTracking?: boolean;
74
+ /**
75
+ * Subscribe to `AppState` to open/close crash-reporting sessions on
76
+ * foreground/background. Default **true**. Purely additive (RN's AppState
77
+ * is a multi-listener emitter — no slot to fight over); the opt-out exists
78
+ * for hosts that drive session boundaries themselves.
79
+ */
80
+ enableAppStateTracking?: boolean;
81
+ /**
82
+ * Start the NATIVE crash handler (iOS Mach/signal + NSException, Android
83
+ * NDK + system ANR) via the native module. Default **true**.
84
+ *
85
+ * Our native handlers chain (they capture and re-invoke the previous
86
+ * `NSSetUncaughtExceptionHandler` / `signal()` / Java
87
+ * `UncaughtExceptionHandler`), so coexisting with Sentry or Crashlytics is
88
+ * supported. Set false if the host's incumbent owns native crash reporting
89
+ * outright and you only want Swiss Knife's JS-level features.
90
+ */
91
+ enableNativeCrashHandler?: boolean;
12
92
  /** Called before sending each event. Return null to drop the event. */
13
93
  beforeSend?: (event: SKCrashEvent) => SKCrashEvent | null;
14
94
  /**
@@ -155,6 +235,15 @@ export declare const CrashReporting: {
155
235
  }>;
156
236
  _pendingScreenshotCountForTests(): number;
157
237
  _simulateAppState(nextState: string): void;
238
+ /** Test seam: stand in for `NativeModules.SKCrashReporting`.
239
+ * `null` = native absent; `undefined` = resolve from react-native. */
240
+ _setNativeCrashModuleForTests(mod: SKCrashReportingNative | null | undefined): void;
241
+ /** Test seam: stand in for react-native's `AppState`. */
242
+ _setAppStateForTests(appState: {
243
+ addEventListener: (e: string, h: (s: string) => void) => {
244
+ remove: () => void;
245
+ };
246
+ } | null | undefined): void;
158
247
  };
159
248
  export interface SKErrorBoundaryProps {
160
249
  children: React.ReactNode;
@@ -1 +1 @@
1
- {"version":3,"file":"crash-reporting.d.ts","sourceRoot":"","sources":["../../../../src/modules/crash-reporting.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,MAAM,OAAO,CAAC;AAyD1B,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;sDACkD;IAClD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,uEAAuE;IACvE,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,YAAY,GAAG,IAAI,CAAC;IAC1D;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,CACjB,UAAU,EAAE,iBAAiB,KAC1B,iBAAiB,GAAG,IAAI,CAAC;IAC9B,yDAAyD;IACzD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qEAAqE;IACrE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;gCAC4B;IAC5B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,CA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;IAC3B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,SAAS,KAAK,IAAI,CAAC;CACzD;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAED,qBAAa,eAAgB,SAAQ,KAAK,CAAC,SAAS,CAAC,oBAAoB,EAAE,oBAAoB,CAAC;gBAClF,KAAK,EAAE,oBAAoB;IAKvC,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,KAAK,GAAG,oBAAoB;IAInE,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,SAAS,GAAG,IAAI;IAa5D,MAAM,IAAI,KAAK,CAAC,SAAS;CAM1B"}
@@ -1,5 +1,36 @@
1
1
  import type { PurchasesConfiguration, LOG_LEVEL, CustomerInfo, PurchasesOfferings, PurchasesPackage, PurchasesStoreProduct, MakePurchaseResult, LogInResult, CustomerInfoUpdateListener } from "./types.js";
2
+ /**
3
+ * Guard for surfaces that genuinely need the PURCHASE engine — the store APIs
4
+ * and the RC-parity identity aliases that route through the store gateway on
5
+ * Android. Checks the JS "configure was called" flag.
6
+ */
2
7
  declare function throwIfNotConfigured(): void;
8
+ /**
9
+ * Guard for surfaces that only need CORE — the subscriber-attribute setters.
10
+ *
11
+ * Attributes describe the *person*, not the purchase: natively they land in
12
+ * `AttributesClient` → `POST /api/sdk/users/attributes` → `app_users.properties`,
13
+ * which is what the dashboard person card reads. Neither platform's attributes
14
+ * path touches StoreKit or Play Billing — iOS gates on `SwissKnife.isCoreConfigured`
15
+ * (`SwissKnife.currentAnonymousIdForAttributes`), and Android's `configureCore`
16
+ * wires `AttributesClient` with an `Identity`-snapshot id fallback precisely so a
17
+ * store-less app still resolves ids. Gating these on the purchase flag left an app
18
+ * that uses `configureCore` (because another library owns the store) with **no way
19
+ * at all** to populate the person card.
20
+ *
21
+ * Two-step check, and the second step is load-bearing:
22
+ *
23
+ * 1. The JS flag, set by `configure` / `configureCore`. Free, no bridge hop.
24
+ * 2. Native truth. `Analytics.init(...)` wires core natively via
25
+ * `configureObservability` and touches no JS flag, so an analytics-only app
26
+ * has core configured while every JS flag reads `false` — exactly the case
27
+ * {@link isCoreConfigured} documents. Skipping this step would keep the most
28
+ * common core-only integration broken.
29
+ *
30
+ * Never consults the purchase flag. Strictly more permissive than
31
+ * {@link throwIfNotConfigured}, so no existing caller can break.
32
+ */
33
+ declare function throwIfCoreNotConfigured(): Promise<void>;
3
34
  /**
4
35
  * RC-compatible subscriptions SDK entry point. Process-wide singleton; call
5
36
  * `Purchases.configure(...)` once at app start, then use the static methods.
@@ -108,6 +139,6 @@ export declare class Purchases {
108
139
  /** @internal Test seam: reset singleton state between tests. */
109
140
  static __resetForTests(): void;
110
141
  }
111
- export { throwIfNotConfigured as __throwIfNotConfigured };
142
+ export { throwIfNotConfigured as __throwIfNotConfigured, throwIfCoreNotConfigured as __throwIfCoreNotConfigured, };
112
143
  export default Purchases;
113
144
  //# sourceMappingURL=purchases.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"purchases.d.ts","sourceRoot":"","sources":["../../../src/purchases.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,sBAAsB,EACtB,SAAS,EACT,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,qBAAqB,EACrB,kBAAkB,EAClB,WAAW,EACX,0BAA0B,EAC3B,MAAM,YAAS,CAAC;AA2CjB,iBAAS,oBAAoB,IAAI,IAAI,CAIpC;AAED;;;GAGG;AACH,qBAAa,SAAS;IACpB;;;;OAIG;IACH,MAAM,CAAC,SAAS,CACd,OAAO,EAAE,sBAAsB,GAAG;QAAE,QAAQ,CAAC,EAAE,SAAS,CAAA;KAAE,GACzD,IAAI;IA2BP;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,aAAa,CAClB,OAAO,EAAE,sBAAsB,GAAG;QA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lE,gEAAgE;WACnD,WAAW,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzD,8EAA8E;IAC9E,MAAM,CAAC,6BAA6B,CAClC,QAAQ,EAAE,0BAA0B,GACnC,IAAI;IAQP,mEAAmE;IACnE,MAAM,CAAC,gCAAgC,CACrC,QAAQ,EAAE,0BAA0B,GACnC,IAAI;IAQP,gEAAgE;IAChE,MAAM,CAAC,eAAe,IAAI,IAAI;CAM/B;AAGD,OAAO,EACL,oBAAoB,IAAI,sBAAsB,EAC9C,wBAAwB,IAAI,0BAA0B,GACvD,CAAC;AAEF,eAAe,SAAS,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-swiss-knife/react-native-sdk",
3
- "version": "0.2.0",
3
+ "version": "0.2.3",
4
4
  "description": "Subscriptions-only React Native SDK for App Swiss Knife — a drop-in replacement for RevenueCat's react-native-purchases public API.",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./lib/commonjs/index.js",
@@ -71,7 +71,18 @@ interface SKCrashReportingNative {
71
71
  captureScreenshot?(): Promise<string | null>;
72
72
  }
73
73
 
74
+ /** Test seam (same shape as `_screenshotCaptureOverride`): `undefined` =
75
+ * resolve from NativeModules, `null` = pretend the native module is absent.
76
+ * Needed because `require("react-native")` under vitest reaches the real
77
+ * Flow-syntax entry point and throws, so the native branch is otherwise
78
+ * unreachable — and "we did not start the native handler" would pass
79
+ * vacuously. */
80
+ let _nativeCrashModuleOverride: SKCrashReportingNative | null | undefined;
81
+
74
82
  function getNativeCrashModule(): SKCrashReportingNative | null {
83
+ if (_nativeCrashModuleOverride !== undefined) {
84
+ return _nativeCrashModuleOverride;
85
+ }
75
86
  try {
76
87
  // Dynamic require to avoid vitest/bundler trying to parse react-native Flow code
77
88
  // eslint-disable-next-line @typescript-eslint/no-require-imports
@@ -98,6 +109,54 @@ export interface CrashReportingConfig {
98
109
  dist?: string;
99
110
  maxBreadcrumbs?: number;
100
111
  enableAutoBreadcrumbs?: boolean;
112
+ /**
113
+ * Take over `ErrorUtils`' global JS error handler. Default **true**.
114
+ *
115
+ * We chain — the handler that was installed before us is still invoked —
116
+ * so leaving this on is safe alongside another reporter. Set false if the
117
+ * host wants Swiss Knife's manual APIs (`captureException`, breadcrumbs,
118
+ * sessions) without us touching the global slot at all.
119
+ */
120
+ enableGlobalErrorHandler?: boolean;
121
+ /**
122
+ * Track unhandled promise rejections. Default **true**.
123
+ *
124
+ * ⚠️ Unlike every other handler in this SDK, this one CANNOT be chained
125
+ * reliably. Both engines expose a single-slot switch with no getter:
126
+ * Hermes' `HermesInternal.enablePromiseRejectionTracker(options)` and JSC's
127
+ * `promise/setimmediate/rejection-tracking`.`enable(options)` each replace
128
+ * whatever was registered, and neither offers a way to read the incumbent
129
+ * back out. Sentry React Native calls exactly the same APIs.
130
+ *
131
+ * What we do about it:
132
+ * - We install a composing wrapper over the engine's `enable` entry point,
133
+ * so a reporter that initialises AFTER us is merged with us instead of
134
+ * replacing us. Both handlers then run.
135
+ * - The reverse order is unfixable. If another reporter installed BEFORE
136
+ * Swiss Knife and did not itself chain, its handler is unreachable and
137
+ * ours replaces it. Either initialise Swiss Knife first, or set this to
138
+ * false — the rest of the SDK (manual captures, breadcrumbs, sessions,
139
+ * the global error handler, native crashes) is unaffected either way.
140
+ */
141
+ enablePromiseRejectionTracking?: boolean;
142
+ /**
143
+ * Subscribe to `AppState` to open/close crash-reporting sessions on
144
+ * foreground/background. Default **true**. Purely additive (RN's AppState
145
+ * is a multi-listener emitter — no slot to fight over); the opt-out exists
146
+ * for hosts that drive session boundaries themselves.
147
+ */
148
+ enableAppStateTracking?: boolean;
149
+ /**
150
+ * Start the NATIVE crash handler (iOS Mach/signal + NSException, Android
151
+ * NDK + system ANR) via the native module. Default **true**.
152
+ *
153
+ * Our native handlers chain (they capture and re-invoke the previous
154
+ * `NSSetUncaughtExceptionHandler` / `signal()` / Java
155
+ * `UncaughtExceptionHandler`), so coexisting with Sentry or Crashlytics is
156
+ * supported. Set false if the host's incumbent owns native crash reporting
157
+ * outright and you only want Swiss Knife's JS-level features.
158
+ */
159
+ enableNativeCrashHandler?: boolean;
101
160
  /** Called before sending each event. Return null to drop the event. */
102
161
  beforeSend?: (event: SKCrashEvent) => SKCrashEvent | null;
103
162
  /**
@@ -603,8 +662,20 @@ function handleAppStateChange(nextState: string): void {
603
662
  }
604
663
  }
605
664
 
665
+ /** Test seam — see `_nativeCrashModuleOverride` for why. `undefined` =
666
+ * resolve from react-native. */
667
+ let _appStateOverride:
668
+ | { addEventListener: (e: string, h: (s: string) => void) => { remove: () => void } }
669
+ | null
670
+ | undefined;
671
+
606
672
  function installAppStateListener(): void {
607
673
  if (_appStateSubscription) return; // double-init guard
674
+ if (_appStateOverride !== undefined) {
675
+ _appStateSubscription =
676
+ _appStateOverride?.addEventListener("change", handleAppStateChange) ?? null;
677
+ return;
678
+ }
608
679
  // AppState is a React Native API. Guard so tests/Node imports don't blow up.
609
680
  try {
610
681
  // eslint-disable-next-line @typescript-eslint/no-require-imports
@@ -1021,10 +1092,70 @@ function onUnhandledRejection(_id: number, rejection: unknown): void {
1021
1092
  }
1022
1093
  }
1023
1094
 
1095
+ interface RejectionTrackingOptions {
1096
+ allRejections: boolean;
1097
+ onUnhandled: (id: number, rejection: unknown) => void;
1098
+ onHandled?: (id: number) => void;
1099
+ }
1100
+
1101
+ type RejectionEnableFn = (opts: RejectionTrackingOptions) => void;
1102
+
1103
+ /**
1104
+ * Wrap a single-slot `enable(options)` entry point so a LATER caller composes
1105
+ * with us instead of evicting us.
1106
+ *
1107
+ * Promise-rejection tracking is the one global in this SDK that offers no way
1108
+ * to read the incumbent handler back out — see
1109
+ * `CrashReportingConfig.enablePromiseRejectionTracking`. Since we cannot
1110
+ * capture what came before, we defend the other direction: after we install,
1111
+ * anyone else calling `enable` (Sentry RN, RN core's LogBox re-arm, the host
1112
+ * itself) is routed through this wrapper, which re-registers a merged
1113
+ * handler. Ours runs first and is isolated behind try/catch so a throw on our
1114
+ * side cannot swallow theirs.
1115
+ *
1116
+ * `allRejections: false` is treated as a disable request and passed straight
1117
+ * through unwrapped — that is how both engines spell "stop tracking", and
1118
+ * silently forcing it back to true would make the API a lie (our own
1119
+ * `_disableRejectionTracking` uses it).
1120
+ *
1121
+ * Returns the un-wrapped original so the caller can restore it on teardown.
1122
+ */
1123
+ function composeRejectionEnable(
1124
+ install: (fn: RejectionEnableFn) => void,
1125
+ original: RejectionEnableFn,
1126
+ ours: RejectionTrackingOptions
1127
+ ): void {
1128
+ install((theirs: RejectionTrackingOptions) => {
1129
+ if (!theirs || theirs.allRejections === false) {
1130
+ original(theirs);
1131
+ return;
1132
+ }
1133
+ original({
1134
+ allRejections: true,
1135
+ onUnhandled: (id: number, rejection: unknown) => {
1136
+ try {
1137
+ ours.onUnhandled(id, rejection);
1138
+ } catch {
1139
+ // never let our reporting break the other tracker
1140
+ }
1141
+ theirs.onUnhandled?.(id, rejection);
1142
+ },
1143
+ onHandled: (id: number) => {
1144
+ try {
1145
+ ours.onHandled?.(id);
1146
+ } catch {
1147
+ /* ignore */
1148
+ }
1149
+ theirs.onHandled?.(id);
1150
+ },
1151
+ });
1152
+ });
1153
+ }
1154
+
1024
1155
  function installPromiseRejectionTracking(): void {
1025
1156
  if (_rejectionTrackingInstalled) return; // double-init guard
1026
1157
 
1027
- const options = {
1158
+ const options: RejectionTrackingOptions = {
1028
1159
  allRejections: true,
1029
1160
  onUnhandled: onUnhandledRejection,
1030
1161
  onHandled: () => {},
@@ -1034,22 +1165,27 @@ function installPromiseRejectionTracking(): void {
1034
1165
  const hermes = (
1035
1166
  globalThis as {
1036
1167
  HermesInternal?: {
1037
- enablePromiseRejectionTracker?: (opts: {
1038
- allRejections: boolean;
1039
- onUnhandled: (id: number, rejection: unknown) => void;
1040
- onHandled?: (id: number) => void;
1041
- }) => void;
1168
+ enablePromiseRejectionTracker?: RejectionEnableFn;
1042
1169
  };
1043
1170
  }
1044
1171
  ).HermesInternal;
1045
1172
  if (hermes?.enablePromiseRejectionTracker) {
1046
- hermes.enablePromiseRejectionTracker(options);
1173
+ // Keep the un-bound reference for restoration — teardown must put the
1174
+ // host's own function object back, not a bound copy of it.
1175
+ const engineEnable = hermes.enablePromiseRejectionTracker;
1176
+ const original = engineEnable.bind(hermes);
1177
+ original(options);
1178
+ composeRejectionEnable(
1179
+ (fn) => {
1180
+ hermes.enablePromiseRejectionTracker = fn;
1181
+ },
1182
+ original,
1183
+ options
1184
+ );
1047
1185
  _rejectionTrackingInstalled = true;
1048
1186
  _disableRejectionTracking = () => {
1049
- hermes.enablePromiseRejectionTracker?.({
1050
- allRejections: false,
1051
- onUnhandled: () => {},
1052
- });
1187
+ hermes.enablePromiseRejectionTracker = engineEnable;
1188
+ original({ allRejections: false, onUnhandled: () => {} });
1053
1189
  };
1054
1190
  return;
1055
1191
  }
@@ -1059,12 +1195,24 @@ function installPromiseRejectionTracking(): void {
1059
1195
  try {
1060
1196
  // eslint-disable-next-line @typescript-eslint/no-require-imports
1061
1197
  const tracking = require("promise/setimmediate/rejection-tracking") as {
1062
- enable: (opts: typeof options) => void;
1198
+ enable: RejectionEnableFn;
1063
1199
  disable: () => void;
1064
1200
  };
1065
- tracking.enable(options);
1201
+ const moduleEnable = tracking.enable;
1202
+ const original = moduleEnable.bind(tracking);
1203
+ original(options);
1204
+ composeRejectionEnable(
1205
+ (fn) => {
1206
+ tracking.enable = fn;
1207
+ },
1208
+ original,
1209
+ options
1210
+ );
1066
1211
  _rejectionTrackingInstalled = true;
1067
- _disableRejectionTracking = () => tracking.disable();
1212
+ _disableRejectionTracking = () => {
1213
+ tracking.enable = moduleEnable;
1214
+ tracking.disable();
1215
+ };
1068
1216
  } catch {
1069
1217
  // promise polyfill unavailable (plain Node/tests) — no rejection capture
1070
1218
  }
@@ -1151,23 +1299,33 @@ function installConsoleBreadcrumbs(): void {
1151
1299
 
1152
1300
  export const CrashReporting = {
1153
1301
  init(config: CrashReportingConfig): void {
1302
+ // Defaults keep today's behaviour byte-for-byte: every handler is on
1303
+ // unless the host explicitly opts out. The opt-outs exist for apps whose
1304
+ // incumbent reporter owns a given global — see each field's doc comment
1305
+ // on CrashReportingConfig for which ones we chain and which we can't.
1154
1306
  _config = {
1155
1307
  maxBreadcrumbs: 100,
1156
1308
  environment: "production",
1157
1309
  enableAutoBreadcrumbs: true,
1310
+ enableGlobalErrorHandler: true,
1311
+ enablePromiseRejectionTracking: true,
1312
+ enableAppStateTracking: true,
1313
+ enableNativeCrashHandler: true,
1158
1314
  ...config,
1159
1315
  };
1160
1316
  _breadcrumbs = new RingBuffer(_config.maxBreadcrumbs!);
1161
- installGlobalHandler();
1162
- installPromiseRejectionTracking();
1317
+ if (_config.enableGlobalErrorHandler) installGlobalHandler();
1318
+ if (_config.enablePromiseRejectionTracking) installPromiseRejectionTracking();
1163
1319
  restorePersistedState();
1164
1320
  startSession();
1165
- installAppStateListener();
1321
+ if (_config.enableAppStateTracking) installAppStateListener();
1166
1322
 
1167
1323
  // Initialize native crash handler if the native module is linked.
1168
1324
  // This catches Mach exceptions + signal crashes (iOS) and NDK native
1169
1325
  // crashes + system ANRs (Android) that pure JS cannot observe.
1170
- const nativeMod = getNativeCrashModule();
1326
+ const nativeMod = _config.enableNativeCrashHandler
1327
+ ? getNativeCrashModule()
1328
+ : null;
1171
1329
  if (nativeMod) {
1172
1330
  try {
1173
1331
  nativeMod.start({
@@ -1472,6 +1630,8 @@ export const CrashReporting = {
1472
1630
  _screenshotPromises = new Map();
1473
1631
  _offlineScreenshots = [];
1474
1632
  _screenshotCaptureOverride = undefined;
1633
+ _nativeCrashModuleOverride = undefined;
1634
+ _appStateOverride = undefined;
1475
1635
  if (_appStateSubscription) {
1476
1636
  _appStateSubscription.remove();
1477
1637
  _appStateSubscription = null;
@@ -1530,6 +1690,29 @@ export const CrashReporting = {
1530
1690
  _simulateAppState(nextState: string): void {
1531
1691
  handleAppStateChange(nextState);
1532
1692
  },
1693
+
1694
+ /** Test seam: stand in for `NativeModules.SKCrashReporting`.
1695
+ * `null` = native absent; `undefined` = resolve from react-native. */
1696
+ _setNativeCrashModuleForTests(
1697
+ mod: SKCrashReportingNative | null | undefined
1698
+ ): void {
1699
+ _nativeCrashModuleOverride = mod;
1700
+ },
1701
+
1702
+ /** Test seam: stand in for react-native's `AppState`. */
1703
+ _setAppStateForTests(
1704
+ appState:
1705
+ | {
1706
+ addEventListener: (
1707
+ e: string,
1708
+ h: (s: string) => void
1709
+ ) => { remove: () => void };
1710
+ }
1711
+ | null
1712
+ | undefined
1713
+ ): void {
1714
+ _appStateOverride = appState;
1715
+ },
1533
1716
  };
1534
1717
 
1535
1718
  // MARK: - React Error Boundary
package/src/purchases.ts CHANGED
@@ -56,12 +56,51 @@ const customerInfoSubscriptions = new Map<
56
56
  EmitterSubscription
57
57
  >();
58
58
 
59
+ /**
60
+ * Guard for surfaces that genuinely need the PURCHASE engine — the store APIs
61
+ * and the RC-parity identity aliases that route through the store gateway on
62
+ * Android. Checks the JS "configure was called" flag.
63
+ */
59
64
  function throwIfNotConfigured(): void {
60
65
  if (!configured) {
61
66
  throw new UninitializedPurchasesError();
62
67
  }
63
68
  }
64
69
 
70
+ /**
71
+ * Guard for surfaces that only need CORE — the subscriber-attribute setters.
72
+ *
73
+ * Attributes describe the *person*, not the purchase: natively they land in
74
+ * `AttributesClient` → `POST /api/sdk/users/attributes` → `app_users.properties`,
75
+ * which is what the dashboard person card reads. Neither platform's attributes
76
+ * path touches StoreKit or Play Billing — iOS gates on `SwissKnife.isCoreConfigured`
77
+ * (`SwissKnife.currentAnonymousIdForAttributes`), and Android's `configureCore`
78
+ * wires `AttributesClient` with an `Identity`-snapshot id fallback precisely so a
79
+ * store-less app still resolves ids. Gating these on the purchase flag left an app
80
+ * that uses `configureCore` (because another library owns the store) with **no way
81
+ * at all** to populate the person card.
82
+ *
83
+ * Two-step check, and the second step is load-bearing:
84
+ *
85
+ * 1. The JS flag, set by `configure` / `configureCore`. Free, no bridge hop.
86
+ * 2. Native truth. `Analytics.init(...)` wires core natively via
87
+ * `configureObservability` and touches no JS flag, so an analytics-only app
88
+ * has core configured while every JS flag reads `false` — exactly the case
89
+ * {@link isCoreConfigured} documents. Skipping this step would keep the most
90
+ * common core-only integration broken.
91
+ *
92
+ * Never consults the purchase flag. Strictly more permissive than
93
+ * {@link throwIfNotConfigured}, so no existing caller can break.
94
+ */
95
+ async function throwIfCoreNotConfigured(): Promise<void> {
96
+ if (coreConfigured) return;
97
+ if (await nativeBoolean((native) => native.isCoreConfigured())) return;
98
+ throw new UninitializedPurchasesError(
99
+ "Purchases core is not configured. Call Purchases.configure(), " +
100
+ "Purchases.configureCore(), or Analytics.init() first."
101
+ );
102
+ }
103
+
65
104
  /**
66
105
  * RC-compatible subscriptions SDK entry point. Process-wide singleton; call
67
106
  * `Purchases.configure(...)` once at app start, then use the static methods.
@@ -206,6 +245,18 @@ export class Purchases {
206
245
  return getNativeModule().restorePurchases();
207
246
  }
208
247
 
248
+ // The four RC-parity identity aliases below stay on the PURCHASE guard on
249
+ // purpose, even though identity is a core concern natively. The two platforms
250
+ // disagree about what this specific surface does: the iOS bridge's `logIn`
251
+ // reaches `SwissKnife.logIn` → `Identity.logIn`, which is core-gated and POSTs
252
+ // `/api/sdk/users/identify`; the Android bridge's `logIn` reaches
253
+ // `SwissKnife.logIn` → the purchases `gateway`, which only rebinds the local
254
+ // user id and refreshes entitlements. Loosening the guard here would let a
255
+ // core-only app call a method that means different things per platform and
256
+ // silently skips the identify POST on Android. `Identity.logIn` / `logOut` /
257
+ // `current` are the core-safe surface — they route to the unified native
258
+ // Identity on both platforms and carry no configure guard in JS at all.
259
+
209
260
  /**
210
261
  * Identify the user. Aliases/merges anonymous purchases server-side.
211
262
  *
@@ -241,33 +292,37 @@ export class Purchases {
241
292
  return getNativeModule().isAnonymous();
242
293
  }
243
294
 
295
+ // Subscriber attributes. CORE, not store — see {@link throwIfCoreNotConfigured}.
296
+ // These work in an app that only called `configureCore` (another library owns
297
+ // the store) or only `Analytics.init`.
298
+
244
299
  /** Set arbitrary subscriber attributes. null clears an attribute. */
245
300
  static async setAttributes(attributes: Record<string, string | null>): Promise<void> {
246
- throwIfNotConfigured();
301
+ await throwIfCoreNotConfigured();
247
302
  return getNativeModule().setAttributes(attributes);
248
303
  }
249
304
 
250
305
  /** Reserved attribute: email. */
251
306
  static async setEmail(email: string | null): Promise<void> {
252
- throwIfNotConfigured();
307
+ await throwIfCoreNotConfigured();
253
308
  return getNativeModule().setEmail(email);
254
309
  }
255
310
 
256
311
  /** Reserved attribute: display name. */
257
312
  static async setDisplayName(displayName: string | null): Promise<void> {
258
- throwIfNotConfigured();
313
+ await throwIfCoreNotConfigured();
259
314
  return getNativeModule().setDisplayName(displayName);
260
315
  }
261
316
 
262
317
  /** Reserved attribute: phone number. */
263
318
  static async setPhoneNumber(phoneNumber: string | null): Promise<void> {
264
- throwIfNotConfigured();
319
+ await throwIfCoreNotConfigured();
265
320
  return getNativeModule().setPhoneNumber(phoneNumber);
266
321
  }
267
322
 
268
323
  /** Reserved attribute: push token. */
269
324
  static async setPushToken(pushToken: string | null): Promise<void> {
270
- throwIfNotConfigured();
325
+ await throwIfCoreNotConfigured();
271
326
  return getNativeModule().setPushToken(pushToken);
272
327
  }
273
328
 
@@ -307,7 +362,10 @@ export class Purchases {
307
362
  }
308
363
  }
309
364
 
310
- // Internal helper shared with the rest of the class (defined across SP-2a tasks).
311
- export { throwIfNotConfigured as __throwIfNotConfigured };
365
+ // Internal helpers shared with the rest of the class (defined across SP-2a tasks).
366
+ export {
367
+ throwIfNotConfigured as __throwIfNotConfigured,
368
+ throwIfCoreNotConfigured as __throwIfCoreNotConfigured,
369
+ };
312
370
 
313
371
  export default Purchases;