@app-swiss-knife/react-native-sdk 0.2.4 → 0.2.5

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.
@@ -210,6 +210,37 @@ export declare const CrashReporting: {
210
210
  comments: string;
211
211
  }): void;
212
212
  addBreadcrumb(breadcrumb: SKCrashBreadcrumb): void;
213
+ /**
214
+ * Explicitly override the crash subject.
215
+ *
216
+ * **You do not need this to get a subject onto crash reports.** The `id` is
217
+ * pulled from `Identity.current()` at report time, so a plain
218
+ * `Identity.logIn("u_42")` is enough — see the "Identity-derived Subject"
219
+ * section in this file. `setUser` exists for the two things Identity cannot
220
+ * express: extra fields, and a subject that deliberately differs from the
221
+ * identity in effect.
222
+ *
223
+ * ## Precedence — field-by-field, explicit wins
224
+ *
225
+ * | field | source |
226
+ * | ---------- | --------------------------------------------------- |
227
+ * | `id` | this call's `id` if set, else `Identity.current().userId` |
228
+ * | `email` | this call only — Identity has no email |
229
+ * | `username` | this call only — Identity has no username |
230
+ *
231
+ * So `setUser({ email })` after `Identity.logIn("u_42")` yields
232
+ * `{ id: "u_42", email }`, and `setUser({ id: "other" })` yields
233
+ * `{ id: "other" }` — the identity is not allowed to overwrite an id the
234
+ * host stated on purpose.
235
+ *
236
+ * `setUser(null)` clears **only this override**. It does not suppress the
237
+ * Identity-derived id; call `Identity.logOut()` for that. (With no identity
238
+ * and no override, `user` is omitted from the payload entirely, exactly as
239
+ * before this pull existed.)
240
+ *
241
+ * Resolution happens at report time, never at login time, so the order of
242
+ * `init` / `logIn` / `setUser` does not matter.
243
+ */
213
244
  setUser(user: SKCrashUser | null): void;
214
245
  setTag(key: string, value: string): void;
215
246
  setExtra(key: string, value: unknown): void;
@@ -238,6 +269,14 @@ export declare const CrashReporting: {
238
269
  /** Test seam: stand in for `NativeModules.SKCrashReporting`.
239
270
  * `null` = native absent; `undefined` = resolve from react-native. */
240
271
  _setNativeCrashModuleForTests(mod: SKCrashReportingNative | null | undefined): void;
272
+ /** Test seam: stand in for the native `Identity.current()` bridge call.
273
+ * `null` = Identity bridge absent; `undefined` = resolve from react-native.
274
+ * Clears the cached subject so the next resolve goes through the seam. */
275
+ _setIdentityResolverForTests(resolver: (() => Promise<{
276
+ userId?: string | null;
277
+ }>) | null | undefined): void;
278
+ /** @internal Current Identity-derived subject id, for assertions. */
279
+ _identitySubjectForTests(): string | null;
241
280
  /** Test seam: stand in for react-native's `AppState`. */
242
281
  _setAppStateForTests(appState: {
243
282
  addEventListener: (e: string, h: (s: string) => void) => {
@@ -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;AAW1B;;;;;GAKG;AACH,UAAU,sBAAsB;IAC9B,KAAK,CAAC,MAAM,EAAE;QACZ,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;KACjB,GAAG,IAAI,CAAC;IACT,OAAO,CAAC,IAAI,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,GAAG,IAAI,CAAC;IAC/E,aAAa,CAAC,UAAU,EAAE;QACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,GAAG,IAAI,CAAC;IACT,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC;;;;OAIG;IACH,iBAAiB,CAAC,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAC9C;AA8BD,MA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G,SAAS,GAC7C,IAAI;IAIP;;8EAE0E;2CAGpE,CAAC,MAAM,OAAO,CAAC;QAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC,GAC3C,IAAI,GACJ,SAAS,GACZ,IAAI;IAOP,qEAAqE;gCACzC,MAAM,GAAG,IAAI;IAIzC,yDAAyD;mCAGnD;QACE,gBAAgB,EAAE,CAChB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,KACnB;YAAE,MAAM,EAAE,MAAM,IAAI,CAAA;SAAE,CAAC;KAC7B,GACD,IAAI,GACJ,SAAS,GACZ,IAAI;CAGR,CAAC;AAIF,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-swiss-knife/react-native-sdk",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
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",
@@ -108,6 +108,7 @@
108
108
  "scripts": {
109
109
  "typecheck": "tsc --noEmit",
110
110
  "test": "vitest run",
111
+ "check:hermes": "node scripts/hermes-boot-check.mjs",
111
112
  "clean": "node -e \"for (const d of ['lib','ios/vendor','android/vendor']) require('fs').rmSync(d,{recursive:true,force:true})\"",
112
113
  "vendor:native": "node scripts/vendor-native.mjs",
113
114
  "build": "node scripts/vendor-native.mjs && bob build"
@@ -372,6 +372,190 @@ let _screenshotCaptureOverride:
372
372
  | null
373
373
  | undefined;
374
374
 
375
+ // MARK: - Identity-derived Subject
376
+ //
377
+ // ## Why the subject is PULLED, never pushed
378
+ //
379
+ // Attaching a person to a crash used to require a `CrashReporting.setUser(...)`
380
+ // call that nothing enforced and nothing validated. Forget it and every crash
381
+ // arrives with `user.id === ""`; the dashboard then reports "Affected users:
382
+ // No identified users" and the integration looks like broken crash reporting
383
+ // when it is actually complete. `Identity.logIn(...)` — the canonical "this is
384
+ // who this is" statement — did not reach this module at all.
385
+ //
386
+ // `modules/analytics.ts` already fixed this exact bug class (see the comment
387
+ // above its `buildEvent`, and `identity.ts` lines 8-16): `user_id` is derived
388
+ // from the native `Identity.current()` snapshot at event-build time rather
389
+ // than being pushed in by whoever calls `logIn`. A pull is immune to
390
+ // initialisation order, and crash reporting is precisely the module that
391
+ // starts before the identity is known — you want the handler armed on the
392
+ // first frame, long before auth state has been read.
393
+ //
394
+ // So: the crash subject is resolved from Identity at report time (and
395
+ // re-resolved at send time, see `flush`), not at login time.
396
+ //
397
+ // ## Deliberately not the anonymous id
398
+ //
399
+ // `Identity.current()` also carries an `anonymousId`, and stamping it into
400
+ // `user.id` would make "affected users" non-zero for every app that never
401
+ // logs in. That both inflates the number and diverges from Analytics, whose
402
+ // `user_id` is the identified subject only. The anonymous id already travels
403
+ // separately on the ingest envelope. Only `userId` is used here.
404
+
405
+ /**
406
+ * Last resolved identified subject id from the native Identity bridge.
407
+ * `null` means "no identified subject" — either genuinely anonymous, or the
408
+ * bridge has not answered yet. Both cases are treated the same: nothing is
409
+ * stamped, which is exactly today's behaviour for apps that never log in.
410
+ */
411
+ let _identityUserId: string | null = null;
412
+ /** In-flight read, so N events in a burst share one bridge hop. */
413
+ let _identityRefresh: Promise<void> | null = null;
414
+ /** Monotonic read counter — a superseded read must not clobber a newer one. */
415
+ let _identityGeneration = 0;
416
+ /**
417
+ * Test seam (same shape as `_nativeCrashModuleOverride`): `undefined` =
418
+ * resolve from the native bridge, `null` = pretend the Identity bridge is
419
+ * absent. Needed because `require("react-native")` under vitest reaches the
420
+ * real Flow-syntax entry point and throws, so the bridge branch is otherwise
421
+ * unreachable and "we did read Identity" would pass vacuously.
422
+ */
423
+ let _identityResolverOverride:
424
+ | (() => Promise<{ userId?: string | null }>)
425
+ | null
426
+ | undefined;
427
+
428
+ /** Budget for the send-time identity re-resolve. Kept well under
429
+ * FATAL_SEND_TIMEOUT_MS so a slow bridge can never eat the fatal path's
430
+ * one chance to deliver before the process dies. */
431
+ const IDENTITY_RESOLVE_TIMEOUT_MS = 250;
432
+
433
+ function getIdentityResolver():
434
+ | (() => Promise<{ userId?: string | null }>)
435
+ | null {
436
+ if (_identityResolverOverride !== undefined) {
437
+ return _identityResolverOverride;
438
+ }
439
+ try {
440
+ // Lazy require for the same reason as `getNativeCrashModule()` — a static
441
+ // import would drag react-native's Flow entry point into plain-Node and
442
+ // vitest contexts where this module must stay importable.
443
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
444
+ const mod = require("../native/module") as {
445
+ getNativeModule: () => { identityCurrent?: () => Promise<unknown> };
446
+ };
447
+ const native = mod.getNativeModule();
448
+ if (typeof native?.identityCurrent !== "function") return null;
449
+ return () =>
450
+ native.identityCurrent!() as Promise<{ userId?: string | null }>;
451
+ } catch {
452
+ // Identity bridge not linked (bare Expo app, tests, plain Node).
453
+ return null;
454
+ }
455
+ }
456
+
457
+ /**
458
+ * Issue a FRESH read of `Identity.current()` into `_identityUserId`.
459
+ *
460
+ * Never throws and never rejects — a failed read leaves the previous value in
461
+ * place rather than blanking a subject we already knew about.
462
+ *
463
+ * A generation counter discards the answer of any read that a newer read has
464
+ * already superseded, so two overlapping reads can never let the older one's
465
+ * (pre-`logIn`) snapshot win on arrival order.
466
+ */
467
+ function startIdentityRead(): Promise<void> {
468
+ const resolver = getIdentityResolver();
469
+ if (!resolver) return Promise.resolve();
470
+ const generation = ++_identityGeneration;
471
+ // `p` is only read inside the `finally`, which cannot run before the
472
+ // assignment below completes — TS can't see that, hence the explicit
473
+ // `undefined` seed rather than a definite-assignment lie.
474
+ let p: Promise<void> | undefined;
475
+ p = (async () => {
476
+ try {
477
+ const snapshot = await resolver();
478
+ if (generation !== _identityGeneration) return; // superseded
479
+ const userId = snapshot?.userId;
480
+ _identityUserId =
481
+ typeof userId === "string" && userId.length > 0 ? userId : null;
482
+ } catch {
483
+ // Bridge hiccup — keep the last known subject.
484
+ } finally {
485
+ if (_identityRefresh === p) _identityRefresh = null;
486
+ }
487
+ })();
488
+ _identityRefresh = p;
489
+ return p;
490
+ }
491
+
492
+ /**
493
+ * Warm the cache. Joins a read that is already in flight — this is only ever
494
+ * used for the opportunistic warm-up at `init`, where an answer a few
495
+ * milliseconds old is fine.
496
+ */
497
+ function refreshIdentitySubject(): Promise<void> {
498
+ return _identityRefresh ?? startIdentityRead();
499
+ }
500
+
501
+ /**
502
+ * Send-time resolve, capped at `IDENTITY_RESOLVE_TIMEOUT_MS`.
503
+ *
504
+ * Deliberately does NOT join an in-flight read. `init` kicks a warm-up read
505
+ * immediately, and the host typically calls `Identity.logIn(...)` a moment
506
+ * later — a send that piggybacked on that warm-up would be answered with the
507
+ * pre-`logIn` snapshot and ship a subject-less crash, which is the exact bug
508
+ * this whole pull exists to kill. (Found by evaluating the built bundle in
509
+ * Node, not by the unit suite: a `settle()` in the test masked the race.)
510
+ * One fresh read per flush — not per event.
511
+ *
512
+ * Returns an already-resolved promise (and arms no timer) when there is no
513
+ * Identity bridge to ask — apps without the native module, and every test
514
+ * that has not installed the seam, must not pay a timer or a scheduling hop
515
+ * for a question that has no answer.
516
+ */
517
+ function resolveIdentitySubjectNow(): Promise<void> {
518
+ if (getIdentityResolver() === null) return Promise.resolve();
519
+ const read = startIdentityRead();
520
+ return new Promise<void>((resolve) => {
521
+ const timer = setTimeout(resolve, IDENTITY_RESOLVE_TIMEOUT_MS);
522
+ void read.then(() => {
523
+ clearTimeout(timer);
524
+ resolve();
525
+ });
526
+ });
527
+ }
528
+
529
+ /**
530
+ * Merge the explicit `setUser` override with the Identity-derived subject.
531
+ *
532
+ * Precedence is **field-by-field, explicit wins**:
533
+ * - `id` — `setUser`'s id if set, else `Identity.current().userId`
534
+ * - `email` — explicit only (Identity has no such field)
535
+ * - `username` — explicit only
536
+ *
537
+ * When nothing resolves, `null` is returned and the `user` key is omitted
538
+ * from the wire payload entirely — byte-identical to today for an app that
539
+ * neither logs in nor calls `setUser`.
540
+ */
541
+ function resolveSubject(): SKCrashUser | null {
542
+ return mergeIdentityInto(_user);
543
+ }
544
+
545
+ /**
546
+ * Fill in the Identity-derived `id` on a subject that does not already carry
547
+ * one. Idempotent: a subject that already has an `id` is returned untouched,
548
+ * so applying this at build time and again at send time cannot change it.
549
+ */
550
+ function mergeIdentityInto(
551
+ user: SKCrashUser | null | undefined
552
+ ): SKCrashUser | null {
553
+ if (user?.id) return user;
554
+ const id = _identityUserId;
555
+ if (!id) return user ?? null;
556
+ return { ...(user ?? {}), id };
557
+ }
558
+
375
559
  // MARK: - Pending Queue (memory + best-effort disk mirror)
376
560
 
377
561
  function enqueueEvent(event: SKCrashEvent): void {
@@ -552,6 +736,9 @@ function buildSessionPayload(status: SessionPayload["status"]): SessionPayload {
552
736
  const contexts = getStaticContexts();
553
737
  const os = contexts.os as { name?: string; version?: string } | undefined;
554
738
  const device = contexts.device as { model?: string } | undefined;
739
+ // Same pull as events: explicit `setUser` id wins, else the Identity
740
+ // subject. Synchronous, so it reads the cache `flush`/`init` keep warm.
741
+ const subject = resolveSubject();
555
742
  return {
556
743
  sessionId: _sessionId!,
557
744
  status,
@@ -559,7 +746,7 @@ function buildSessionPayload(status: SessionPayload["status"]): SessionPayload {
559
746
  errorsCount: _sessionErrorCount,
560
747
  releaseVersion: _config?.release,
561
748
  environment: _config?.environment,
562
- ...(_user?.id ? { userId: _user.id } : {}),
749
+ ...(subject?.id ? { userId: subject.id } : {}),
563
750
  ...(os?.name ? { osName: os.name, osVersion: os.version } : {}),
564
751
  ...(device?.model ? { deviceModel: device.model } : {}),
565
752
  };
@@ -600,6 +787,14 @@ async function postSessionPayload(
600
787
  }
601
788
  }
602
789
 
790
+ /**
791
+ * Deliberately has NO `await` before `postSessionPayload` — not even to
792
+ * re-resolve the identity. `endSession` nulls `_sessionId` and zeroes the
793
+ * error count the instant this function yields, and callers rely on the POST
794
+ * being issued in the same tick. Session payloads therefore take the subject
795
+ * from the warm cache only (see `buildSessionPayload`); the authoritative
796
+ * re-resolve happens on the event path in `flush`.
797
+ */
603
798
  async function sendSessionEvent(
604
799
  status: "started" | "ended" | "crashed"
605
800
  ): Promise<void> {
@@ -1004,7 +1199,7 @@ function buildEvent(
1004
1199
  ...(_config?.dist ? { dist: _config.dist } : {}),
1005
1200
  tags: { ..._tags },
1006
1201
  extra: { ..._extra },
1007
- user: _user,
1202
+ user: resolveSubject(),
1008
1203
  breadcrumbs: _breadcrumbs.snapshot(),
1009
1204
  ...partial,
1010
1205
  contexts,
@@ -1390,6 +1585,11 @@ export const CrashReporting = {
1390
1585
  ...config,
1391
1586
  };
1392
1587
  _breadcrumbs = new RingBuffer(_config.maxBreadcrumbs!);
1588
+ // Warm the Identity subject cache. Fire-and-forget: crash reporting must
1589
+ // arm on the first frame and cannot wait on a bridge hop, and every send
1590
+ // path re-resolves anyway — this only shortens the window in which an
1591
+ // early event has to fall back to the send-time pull.
1592
+ void refreshIdentitySubject();
1393
1593
  // Every global-slot install is best-effort. `initSwissKnife()` is normally
1394
1594
  // called in module scope, so anything that throws here takes the host's
1395
1595
  // root module down with it and the app never boots (v0.2.3 did exactly
@@ -1548,9 +1748,42 @@ export const CrashReporting = {
1548
1748
  }
1549
1749
  },
1550
1750
 
1751
+ /**
1752
+ * Explicitly override the crash subject.
1753
+ *
1754
+ * **You do not need this to get a subject onto crash reports.** The `id` is
1755
+ * pulled from `Identity.current()` at report time, so a plain
1756
+ * `Identity.logIn("u_42")` is enough — see the "Identity-derived Subject"
1757
+ * section in this file. `setUser` exists for the two things Identity cannot
1758
+ * express: extra fields, and a subject that deliberately differs from the
1759
+ * identity in effect.
1760
+ *
1761
+ * ## Precedence — field-by-field, explicit wins
1762
+ *
1763
+ * | field | source |
1764
+ * | ---------- | --------------------------------------------------- |
1765
+ * | `id` | this call's `id` if set, else `Identity.current().userId` |
1766
+ * | `email` | this call only — Identity has no email |
1767
+ * | `username` | this call only — Identity has no username |
1768
+ *
1769
+ * So `setUser({ email })` after `Identity.logIn("u_42")` yields
1770
+ * `{ id: "u_42", email }`, and `setUser({ id: "other" })` yields
1771
+ * `{ id: "other" }` — the identity is not allowed to overwrite an id the
1772
+ * host stated on purpose.
1773
+ *
1774
+ * `setUser(null)` clears **only this override**. It does not suppress the
1775
+ * Identity-derived id; call `Identity.logOut()` for that. (With no identity
1776
+ * and no override, `user` is omitted from the payload entirely, exactly as
1777
+ * before this pull existed.)
1778
+ *
1779
+ * Resolution happens at report time, never at login time, so the order of
1780
+ * `init` / `logIn` / `setUser` does not matter.
1781
+ */
1551
1782
  setUser(user: SKCrashUser | null): void {
1552
1783
  _user = user;
1553
- // Forward to native layer for crash-time user context
1784
+ // Forward the EXPLICIT override to native, unmerged. The native crash
1785
+ // SDKs run the same precedence against their own `Identity.current`, so
1786
+ // sending a merged subject here would pin the id and defeat their pull.
1554
1787
  const nativeMod = getNativeCrashModule();
1555
1788
  if (nativeMod) {
1556
1789
  try {
@@ -1599,12 +1832,23 @@ export const CrashReporting = {
1599
1832
  const baseURL = _config.serverURL || "https://api.swiss-knife.dev";
1600
1833
  const url = `${baseURL}/api/sdk/errors/event/batch`;
1601
1834
 
1835
+ // Re-resolve the subject at SEND time. `buildEvent` is synchronous and
1836
+ // can only read the cached snapshot, so an event captured before the
1837
+ // Identity bridge first answered would otherwise ship subject-less —
1838
+ // which is the whole failure mode this pull exists to kill. Doing it
1839
+ // here makes ordering irrelevant in both directions: `logIn` before
1840
+ // `init` and `init` before `logIn` both end up stamped. Bounded by
1841
+ // IDENTITY_RESOLVE_TIMEOUT_MS so the fatal path keeps its budget.
1842
+ await resolveIdentitySubjectNow();
1843
+
1602
1844
  // The /api/sdk/errors/event/batch endpoint:
1603
1845
  // - expects `timestamp` as an ISO string (SDK builds it as Date.now() number)
1604
1846
  // - rejects `user: null` (schema marks `user` optional, not nullable)
1605
1847
  // Coerce both on the wire so the internal SDK shape stays ergonomic.
1606
1848
  const serialized = batch.map((e) => {
1607
- const { user, ...rest } = e;
1849
+ const { user: builtUser, ...rest } = e;
1850
+ // Idempotent: leaves an id that build time already resolved alone.
1851
+ const user = mergeIdentityInto(builtUser);
1608
1852
  return {
1609
1853
  ...rest,
1610
1854
  ...(user ? { user } : {}),
@@ -1718,6 +1962,12 @@ export const CrashReporting = {
1718
1962
  _offlineScreenshots = [];
1719
1963
  _screenshotCaptureOverride = undefined;
1720
1964
  _nativeCrashModuleOverride = undefined;
1965
+ _identityUserId = null;
1966
+ _identityRefresh = null;
1967
+ // Bump the generation so a read still in flight cannot land after the
1968
+ // reset and repopulate the subject the reset just cleared.
1969
+ _identityGeneration++;
1970
+ _identityResolverOverride = undefined;
1721
1971
  _appStateOverride = undefined;
1722
1972
  if (_appStateSubscription) {
1723
1973
  _appStateSubscription.remove();
@@ -1788,6 +2038,26 @@ export const CrashReporting = {
1788
2038
  _nativeCrashModuleOverride = mod;
1789
2039
  },
1790
2040
 
2041
+ /** Test seam: stand in for the native `Identity.current()` bridge call.
2042
+ * `null` = Identity bridge absent; `undefined` = resolve from react-native.
2043
+ * Clears the cached subject so the next resolve goes through the seam. */
2044
+ _setIdentityResolverForTests(
2045
+ resolver:
2046
+ | (() => Promise<{ userId?: string | null }>)
2047
+ | null
2048
+ | undefined
2049
+ ): void {
2050
+ _identityResolverOverride = resolver;
2051
+ _identityUserId = null;
2052
+ _identityRefresh = null;
2053
+ _identityGeneration++;
2054
+ },
2055
+
2056
+ /** @internal Current Identity-derived subject id, for assertions. */
2057
+ _identitySubjectForTests(): string | null {
2058
+ return _identityUserId;
2059
+ },
2060
+
1791
2061
  /** Test seam: stand in for react-native's `AppState`. */
1792
2062
  _setAppStateForTests(
1793
2063
  appState: