@testerpaykit/expo 2.0.1 → 2.1.1

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 CHANGED
@@ -2,6 +2,32 @@
2
2
 
3
3
  All notable changes to `@testerpaykit/expo` are documented here.
4
4
 
5
+ ## 2.1.1 — 2026-11-09
6
+
7
+ ### Changed
8
+ - With `syncSessions: false` a launch sends nothing at all until the first
9
+ report: no sign-in and no profile check. Signing in marked the tester as
10
+ active on every start, so "no tracking" was not quite true. A person approved
11
+ on an earlier launch still signs in at launch and sees the widget; confirming
12
+ a number signs in when it starts.
13
+
14
+ ## 2.1.0 — 2026-11-09
15
+
16
+ ### Added
17
+ - `syncSessions` (default `true`). With `false` no usage data goes to the
18
+ server: no session, no foreground time, no breadcrumb or event flushes and
19
+ no task auto-completion. Reports keep working and carry a local session id.
20
+ For hosts that promise "no tracking"; leave it on for paid test orders.
21
+ - Crash reports carry `automatic: true`. A project that switched on
22
+ `acceptUnverifiedAutoReports` on the server takes them from its anonymous
23
+ installs without a confirmed number. Reports a person writes stay behind
24
+ the gate.
25
+
26
+ ### Fixed
27
+ - A report or upload queued while the offline queue was being flushed was
28
+ overwritten when the flush finished and never sent. Parallel `enqueue` calls
29
+ could lose entries the same way.
30
+
5
31
  ## 2.0.1 — 2026-11-08
6
32
 
7
33
  ### Fixed
package/dist/index.d.mts CHANGED
@@ -270,6 +270,7 @@ interface AttachmentQueueFlushOptions {
270
270
  }
271
271
  declare class SubmitQueue {
272
272
  private readonly storage;
273
+ private readonly writes;
273
274
  constructor(storage: TpkStorage);
274
275
  enqueue(payload: BugReportPayload, options?: {
275
276
  idempotencyKey?: string;
@@ -285,6 +286,7 @@ declare class SubmitQueue {
285
286
  }
286
287
  declare class AttachmentQueue {
287
288
  private readonly storage;
289
+ private readonly writes;
288
290
  constructor(storage: TpkStorage);
289
291
  enqueue(bugReportId: string, attachment: BugReportAttachmentInput): Promise<QueuedAttachmentEntry>;
290
292
  size(): Promise<number>;
@@ -595,6 +597,14 @@ interface TpkExpoConfig {
595
597
  * are submitted as `type: 'crash'` bug reports automatically.
596
598
  */
597
599
  captureCrashes?: boolean;
600
+ /**
601
+ * Whether usage data goes to the server. Defaults to true. False is for
602
+ * hosts that promise "no tracking" and only want reports: no server
603
+ * session, no foreground time, no breadcrumb or event flushes and no task
604
+ * auto-completion. Reports keep working and carry a local session id.
605
+ * Leave it on for paid test orders.
606
+ */
607
+ syncSessions?: boolean;
598
608
  /**
599
609
  * How many breadcrumbs to keep in the ring buffer (default 50).
600
610
  * Older breadcrumbs are dropped as new ones come in.
@@ -749,12 +759,16 @@ declare class TpkExpo {
749
759
  private compensationClient;
750
760
  get compensation(): CompensationClient;
751
761
  private readonly sessionEvents;
762
+ private get syncSessions();
752
763
  private uninstallDurableSync;
753
764
  private uninstallTaskBinding;
754
765
  private readonly capturedCrashes;
755
766
  private readonly submittedCrashes;
756
767
  private crashFlush;
757
768
  private accessValue;
769
+ /** `syncSessions: false`: nothing reaches the server until a report does. */
770
+ private quietUntilReport;
771
+ private signingIn;
758
772
  private handleValue;
759
773
  /** Bumped by a tester-gate 403: a check that started before it must
760
774
  * not bring a stale "ready" back. */
@@ -834,6 +848,12 @@ declare class TpkExpo {
834
848
  revalidate?: boolean;
835
849
  }): Promise<'verified' | 'required' | 'awaitingApproval' | 'unknown'>;
836
850
  private loginRecovery;
851
+ /**
852
+ * Signs in for the first report when `syncSessions: false` left that open,
853
+ * or just ends the quiet with a stored login. Concurrent callers share one
854
+ * sign-in; a failure is retried by the next one.
855
+ */
856
+ private signInForReport;
837
857
  /**
838
858
  * Drop a login the server no longer accepts, with its session and phone
839
859
  * state, and log in anonymously again, like a first start. Concurrent
package/dist/index.d.ts CHANGED
@@ -270,6 +270,7 @@ interface AttachmentQueueFlushOptions {
270
270
  }
271
271
  declare class SubmitQueue {
272
272
  private readonly storage;
273
+ private readonly writes;
273
274
  constructor(storage: TpkStorage);
274
275
  enqueue(payload: BugReportPayload, options?: {
275
276
  idempotencyKey?: string;
@@ -285,6 +286,7 @@ declare class SubmitQueue {
285
286
  }
286
287
  declare class AttachmentQueue {
287
288
  private readonly storage;
289
+ private readonly writes;
288
290
  constructor(storage: TpkStorage);
289
291
  enqueue(bugReportId: string, attachment: BugReportAttachmentInput): Promise<QueuedAttachmentEntry>;
290
292
  size(): Promise<number>;
@@ -595,6 +597,14 @@ interface TpkExpoConfig {
595
597
  * are submitted as `type: 'crash'` bug reports automatically.
596
598
  */
597
599
  captureCrashes?: boolean;
600
+ /**
601
+ * Whether usage data goes to the server. Defaults to true. False is for
602
+ * hosts that promise "no tracking" and only want reports: no server
603
+ * session, no foreground time, no breadcrumb or event flushes and no task
604
+ * auto-completion. Reports keep working and carry a local session id.
605
+ * Leave it on for paid test orders.
606
+ */
607
+ syncSessions?: boolean;
598
608
  /**
599
609
  * How many breadcrumbs to keep in the ring buffer (default 50).
600
610
  * Older breadcrumbs are dropped as new ones come in.
@@ -749,12 +759,16 @@ declare class TpkExpo {
749
759
  private compensationClient;
750
760
  get compensation(): CompensationClient;
751
761
  private readonly sessionEvents;
762
+ private get syncSessions();
752
763
  private uninstallDurableSync;
753
764
  private uninstallTaskBinding;
754
765
  private readonly capturedCrashes;
755
766
  private readonly submittedCrashes;
756
767
  private crashFlush;
757
768
  private accessValue;
769
+ /** `syncSessions: false`: nothing reaches the server until a report does. */
770
+ private quietUntilReport;
771
+ private signingIn;
758
772
  private handleValue;
759
773
  /** Bumped by a tester-gate 403: a check that started before it must
760
774
  * not bring a stale "ready" back. */
@@ -834,6 +848,12 @@ declare class TpkExpo {
834
848
  revalidate?: boolean;
835
849
  }): Promise<'verified' | 'required' | 'awaitingApproval' | 'unknown'>;
836
850
  private loginRecovery;
851
+ /**
852
+ * Signs in for the first report when `syncSessions: false` left that open,
853
+ * or just ends the quiet with a stored login. Concurrent callers share one
854
+ * sign-in; a failure is retried by the next one.
855
+ */
856
+ private signInForReport;
837
857
  /**
838
858
  * Drop a login the server no longer accepts, with its session and phone
839
859
  * state, and log in anonymously again, like a first start. Concurrent
package/dist/index.js CHANGED
@@ -802,12 +802,23 @@ var CrashQueue = class {
802
802
  // src/queue.ts
803
803
  var QUEUE_KEY = "queue/bug-reports";
804
804
  var ATTACHMENT_QUEUE_KEY = "queue/attachments";
805
+ var SerialWrites = class {
806
+ constructor() {
807
+ this.last = Promise.resolve();
808
+ }
809
+ run(step) {
810
+ const result = this.last.then(step, step);
811
+ this.last = result.catch(() => {
812
+ });
813
+ return result;
814
+ }
815
+ };
805
816
  var SubmitQueue = class {
806
817
  constructor(storage) {
807
818
  this.storage = storage;
819
+ this.writes = new SerialWrites();
808
820
  }
809
821
  async enqueue(payload, options) {
810
- const queue = await this.read() ?? [];
811
822
  const entry = {
812
823
  id: cryptoRandomId(),
813
824
  // Reuse the caller's key when supplied — that's how the first
@@ -818,8 +829,11 @@ var SubmitQueue = class {
818
829
  queuedAt: (/* @__PURE__ */ new Date()).toISOString(),
819
830
  payload
820
831
  };
821
- queue.push(entry);
822
- await this.storage.set(QUEUE_KEY, queue);
832
+ await this.writes.run(async () => {
833
+ const queue = await this.read() ?? [];
834
+ queue.push(entry);
835
+ await this.storage.set(QUEUE_KEY, queue);
836
+ });
823
837
  return entry;
824
838
  }
825
839
  async size() {
@@ -861,11 +875,16 @@ var SubmitQueue = class {
861
875
  }
862
876
  }
863
877
  }
864
- if (remaining.length === 0) {
865
- await this.storage.remove(QUEUE_KEY);
866
- } else {
867
- await this.storage.set(QUEUE_KEY, remaining);
868
- }
878
+ await this.writes.run(async () => {
879
+ const handled = new Set(queue.map((entry) => entry.id));
880
+ const added = (await this.read() ?? []).filter((entry) => !handled.has(entry.id));
881
+ const next = [...remaining, ...added];
882
+ if (next.length === 0) {
883
+ await this.storage.remove(QUEUE_KEY);
884
+ } else {
885
+ await this.storage.set(QUEUE_KEY, next);
886
+ }
887
+ });
869
888
  return result;
870
889
  }
871
890
  async read() {
@@ -875,17 +894,20 @@ var SubmitQueue = class {
875
894
  var AttachmentQueue = class {
876
895
  constructor(storage) {
877
896
  this.storage = storage;
897
+ this.writes = new SerialWrites();
878
898
  }
879
899
  async enqueue(bugReportId, attachment) {
880
- const queue = await this.read() ?? [];
881
900
  const entry = {
882
901
  id: cryptoRandomId(),
883
902
  bugReportId,
884
903
  queuedAt: (/* @__PURE__ */ new Date()).toISOString(),
885
904
  attachment
886
905
  };
887
- queue.push(entry);
888
- await this.storage.set(ATTACHMENT_QUEUE_KEY, queue);
906
+ await this.writes.run(async () => {
907
+ const queue = await this.read() ?? [];
908
+ queue.push(entry);
909
+ await this.storage.set(ATTACHMENT_QUEUE_KEY, queue);
910
+ });
889
911
  return entry;
890
912
  }
891
913
  async size() {
@@ -924,11 +946,16 @@ var AttachmentQueue = class {
924
946
  }
925
947
  }
926
948
  }
927
- if (remaining.length === 0) {
928
- await this.storage.remove(ATTACHMENT_QUEUE_KEY);
929
- } else {
930
- await this.storage.set(ATTACHMENT_QUEUE_KEY, remaining);
931
- }
949
+ await this.writes.run(async () => {
950
+ const handled = new Set(queue.map((entry) => entry.id));
951
+ const added = (await this.read() ?? []).filter((entry) => !handled.has(entry.id));
952
+ const next = [...remaining, ...added];
953
+ if (next.length === 0) {
954
+ await this.storage.remove(ATTACHMENT_QUEUE_KEY);
955
+ } else {
956
+ await this.storage.set(ATTACHMENT_QUEUE_KEY, next);
957
+ }
958
+ });
932
959
  return result;
933
960
  }
934
961
  async read() {
@@ -1308,7 +1335,7 @@ function findAssignmentForTask(tasks, key) {
1308
1335
  }
1309
1336
 
1310
1337
  // package.json
1311
- var version = "2.0.1";
1338
+ var version = "2.1.1";
1312
1339
 
1313
1340
  // src/version.ts
1314
1341
  var SDK_VERSION = `@testerpaykit/expo/${version}`;
@@ -1513,6 +1540,9 @@ var TpkExpo = class _TpkExpo {
1513
1540
  this.crashFlush = Promise.resolve();
1514
1541
  // ── Access (who sees the widget) ──
1515
1542
  this.accessValue = "hidden";
1543
+ /** `syncSessions: false`: nothing reaches the server until a report does. */
1544
+ this.quietUntilReport = false;
1545
+ this.signingIn = null;
1516
1546
  this.handleValue = null;
1517
1547
  /** Bumped by a tester-gate 403: a check that started before it must
1518
1548
  * not bring a stale "ready" back. */
@@ -1544,6 +1574,9 @@ var TpkExpo = class _TpkExpo {
1544
1574
  }
1545
1575
  return this.compensationClient.client;
1546
1576
  }
1577
+ get syncSessions() {
1578
+ return this.config.syncSessions !== false;
1579
+ }
1547
1580
  static async init(config) {
1548
1581
  runSetupCheck();
1549
1582
  const storage = config.storage ?? new ExpoStorage();
@@ -1563,6 +1596,7 @@ var TpkExpo = class _TpkExpo {
1563
1596
  let tester;
1564
1597
  let authReady;
1565
1598
  let hasCachedAuth = false;
1599
+ const signInLater = config.syncSessions === false && (await storage.get(STORAGE_KEY_PHONE))?.approved !== true;
1566
1600
  const acquireFreshAuth = async () => {
1567
1601
  try {
1568
1602
  const fresh = await api.loginAnonymous(config.projectId, config.testerCode);
@@ -1578,7 +1612,7 @@ var TpkExpo = class _TpkExpo {
1578
1612
  authReady = Promise.resolve();
1579
1613
  } else {
1580
1614
  tester = { id: "", projectId: config.projectId, code: config.testerCode };
1581
- authReady = acquireFreshAuth();
1615
+ authReady = signInLater ? Promise.resolve() : acquireFreshAuth();
1582
1616
  }
1583
1617
  let sessionId = "";
1584
1618
  let sessionReady;
@@ -1590,8 +1624,12 @@ var TpkExpo = class _TpkExpo {
1590
1624
  } catch {
1591
1625
  }
1592
1626
  });
1593
- const persisted = await loadPersistedSession(storage, config.projectId, config.testerCode);
1594
- if (persisted) {
1627
+ const syncSessions = config.syncSessions !== false;
1628
+ const persisted = syncSessions ? await loadPersistedSession(storage, config.projectId, config.testerCode) : null;
1629
+ if (!syncSessions) {
1630
+ sessionId = uuidv4();
1631
+ sessionReady = Promise.resolve();
1632
+ } else if (persisted) {
1595
1633
  sessionId = persisted;
1596
1634
  sessionReady = Promise.resolve();
1597
1635
  } else if (hasCachedAuth) {
@@ -1625,6 +1663,7 @@ var TpkExpo = class _TpkExpo {
1625
1663
  );
1626
1664
  instance.tester = tester;
1627
1665
  instance.sessionId = sessionId;
1666
+ instance.quietUntilReport = signInLater;
1628
1667
  sessionReady.then(() => {
1629
1668
  instance.sessionId = sessionId;
1630
1669
  });
@@ -1651,7 +1690,7 @@ var TpkExpo = class _TpkExpo {
1651
1690
  intervalMs: config.flushIntervalMs ?? 6e4,
1652
1691
  appState
1653
1692
  });
1654
- instance.uninstallTaskBinding = instance.bindTaskCompletion();
1693
+ if (syncSessions) instance.uninstallTaskBinding = instance.bindTaskCompletion();
1655
1694
  if (config.flushQueueOnInit !== false) {
1656
1695
  instance.flushQueue().catch(() => {
1657
1696
  });
@@ -1678,6 +1717,7 @@ var TpkExpo = class _TpkExpo {
1678
1717
  const payload = await this.buildPayload(input);
1679
1718
  const idempotencyKey = uuidv4();
1680
1719
  try {
1720
+ await this.signInForReport();
1681
1721
  const response = await this.api.submitBugReport(payload, {
1682
1722
  idempotencyKey
1683
1723
  });
@@ -1821,6 +1861,7 @@ var TpkExpo = class _TpkExpo {
1821
1861
  const cached2 = await this.storage.get(STORAGE_KEY_PHONE);
1822
1862
  const cachedOk = cached2?.approved === true;
1823
1863
  if (cachedOk && !options.revalidate) return "verified";
1864
+ await this.signInForReport();
1824
1865
  let status;
1825
1866
  try {
1826
1867
  let profile;
@@ -1848,6 +1889,29 @@ var TpkExpo = class _TpkExpo {
1848
1889
  }
1849
1890
  return status;
1850
1891
  }
1892
+ /**
1893
+ * Signs in for the first report when `syncSessions: false` left that open,
1894
+ * or just ends the quiet with a stored login. Concurrent callers share one
1895
+ * sign-in; a failure is retried by the next one.
1896
+ */
1897
+ signInForReport() {
1898
+ if (!this.quietUntilReport) return Promise.resolve();
1899
+ this.signingIn ?? (this.signingIn = (async () => {
1900
+ try {
1901
+ if (!this.tester.id) {
1902
+ const fresh = await this.api.loginAnonymous(this.config.projectId, this.config.testerCode);
1903
+ await this.storage.set(STORAGE_KEY_AUTH, fresh);
1904
+ this.tester = fresh.tester;
1905
+ }
1906
+ this.quietUntilReport = false;
1907
+ void this.refreshAccess().catch(() => void 0);
1908
+ } catch {
1909
+ } finally {
1910
+ this.signingIn = null;
1911
+ }
1912
+ })());
1913
+ return this.signingIn;
1914
+ }
1851
1915
  /**
1852
1916
  * Drop a login the server no longer accepts, with its session and phone
1853
1917
  * state, and log in anonymously again, like a first start. Concurrent
@@ -1861,6 +1925,7 @@ var TpkExpo = class _TpkExpo {
1861
1925
  const fresh = await this.api.loginAnonymous(this.config.projectId, this.config.testerCode);
1862
1926
  await this.storage.set(STORAGE_KEY_AUTH, fresh);
1863
1927
  this.tester = fresh.tester;
1928
+ if (!this.syncSessions) return true;
1864
1929
  try {
1865
1930
  this.sessionId = await startServerSession(this.api, fresh.tester.projectId);
1866
1931
  await persistSession(this.storage, this.sessionId, this.config.projectId, this.config.testerCode);
@@ -1898,6 +1963,7 @@ var TpkExpo = class _TpkExpo {
1898
1963
  * `revalidate: false` answers from the cache when there is one.
1899
1964
  */
1900
1965
  async refreshAccess(options = {}) {
1966
+ if (this.quietUntilReport) return this.accessValue;
1901
1967
  const generation = this.accessGeneration;
1902
1968
  let status;
1903
1969
  try {
@@ -1971,6 +2037,7 @@ var TpkExpo = class _TpkExpo {
1971
2037
  */
1972
2038
  async startPhone(phone) {
1973
2039
  try {
2040
+ await this.signInForReport();
1974
2041
  const r = await this.api.startPhoneVerification(phone);
1975
2042
  return { ok: true, verificationId: r.verificationId, devCode: r.devCode };
1976
2043
  } catch (e) {
@@ -2058,6 +2125,7 @@ var TpkExpo = class _TpkExpo {
2058
2125
  await this.storage.set(STORAGE_KEY_AUTH, fresh);
2059
2126
  this.api.setAccessToken(fresh.accessToken);
2060
2127
  this.tester = fresh.tester;
2128
+ if (!this.syncSessions) return;
2061
2129
  const sid = await startServerSession(this.api, fresh.tester.projectId);
2062
2130
  this.sessionId = sid;
2063
2131
  await persistSession(this.storage, sid, this.config.projectId, code);
@@ -2106,7 +2174,7 @@ var TpkExpo = class _TpkExpo {
2106
2174
  if (!this.sessionId) return Promise.reject(new Error("no session yet"));
2107
2175
  payload = { ...payload, sessionId: this.sessionId };
2108
2176
  }
2109
- return this.api.submitBugReport(payload, options);
2177
+ return this.signInForReport().then(() => this.api.submitBugReport(payload, options));
2110
2178
  }
2111
2179
  });
2112
2180
  }
@@ -2116,6 +2184,7 @@ var TpkExpo = class _TpkExpo {
2116
2184
  */
2117
2185
  async attachToBugReport(bugReportId, attachment) {
2118
2186
  try {
2187
+ await this.signInForReport();
2119
2188
  return await this.api.attachToBugReport(bugReportId, attachment);
2120
2189
  } catch (e) {
2121
2190
  const status = extractStatus2(e);
@@ -2137,7 +2206,7 @@ var TpkExpo = class _TpkExpo {
2137
2206
  /** Flush queued attachment uploads immediately. */
2138
2207
  async flushAttachmentQueue() {
2139
2208
  return this.attachmentQueue.flush({
2140
- attach: (bugReportId, attachment) => this.api.attachToBugReport(bugReportId, attachment)
2209
+ attach: (bugReportId, attachment) => this.signInForReport().then(() => this.api.attachToBugReport(bugReportId, attachment))
2141
2210
  });
2142
2211
  }
2143
2212
  /** Cached crashes available for post-crash review or retry. */
@@ -2182,6 +2251,10 @@ var TpkExpo = class _TpkExpo {
2182
2251
  }
2183
2252
  /** Flush pending session events + breadcrumbs to timeline endpoints. */
2184
2253
  async flushTelemetry() {
2254
+ if (!this.syncSessions) {
2255
+ this.sessionEvents.splice(0, this.sessionEvents.length - MAX_LOCAL_EVENTS);
2256
+ return { eventsInserted: 0, breadcrumbsInserted: 0 };
2257
+ }
2185
2258
  if (!this.sessionId) {
2186
2259
  return { eventsInserted: 0, breadcrumbsInserted: 0 };
2187
2260
  }
@@ -2216,6 +2289,7 @@ var TpkExpo = class _TpkExpo {
2216
2289
  await this.compensation.act(a, "pause", workSeconds(a, Date.now() + offset));
2217
2290
  }
2218
2291
  }
2292
+ if (!this.syncSessions) return;
2219
2293
  await this.flushTelemetry();
2220
2294
  await this.api.endTesterSession({
2221
2295
  sessionId: this.sessionId,
@@ -2228,14 +2302,18 @@ var TpkExpo = class _TpkExpo {
2228
2302
  }
2229
2303
  /** Rotate the server-side session id (call after a logical restart). */
2230
2304
  async rotateSession() {
2231
- await this.flushTelemetry();
2232
- this.sessionId = await startServerSession(this.api, this.tester.projectId);
2233
- await persistSession(
2234
- this.storage,
2235
- this.sessionId,
2236
- this.config.projectId,
2237
- this.config.testerCode
2238
- );
2305
+ if (this.syncSessions) {
2306
+ await this.flushTelemetry();
2307
+ this.sessionId = await startServerSession(this.api, this.tester.projectId);
2308
+ await persistSession(
2309
+ this.storage,
2310
+ this.sessionId,
2311
+ this.config.projectId,
2312
+ this.config.testerCode
2313
+ );
2314
+ } else {
2315
+ this.sessionId = uuidv4();
2316
+ }
2239
2317
  this.capturedCrashes.clear();
2240
2318
  this.submittedCrashes.clear();
2241
2319
  this.breadcrumbs.record({ action: "tpk", target: "session_rotated" });
@@ -2378,10 +2456,15 @@ var TpkExpo = class _TpkExpo {
2378
2456
  title: truncate(info.message, 200),
2379
2457
  description: composeCrashDescription(info)
2380
2458
  });
2381
- await this.api.submitBugReport(payload, { idempotencyKey: crashId });
2459
+ await this.signInForReport();
2460
+ await this.api.submitBugReport(
2461
+ { ...payload, automatic: true },
2462
+ { idempotencyKey: crashId }
2463
+ );
2382
2464
  this.breadcrumbs.record({ action: "tpk", target: "crash_submitted" });
2383
2465
  }
2384
2466
  };
2467
+ var MAX_LOCAL_EVENTS = 1e3;
2385
2468
  function lastScreen(buf) {
2386
2469
  const snapshot = buf.snapshot();
2387
2470
  for (let i = snapshot.length - 1; i >= 0; i--) {
package/dist/index.mjs CHANGED
@@ -536,12 +536,23 @@ var CrashQueue = class {
536
536
  // src/queue.ts
537
537
  var QUEUE_KEY = "queue/bug-reports";
538
538
  var ATTACHMENT_QUEUE_KEY = "queue/attachments";
539
+ var SerialWrites = class {
540
+ constructor() {
541
+ this.last = Promise.resolve();
542
+ }
543
+ run(step) {
544
+ const result = this.last.then(step, step);
545
+ this.last = result.catch(() => {
546
+ });
547
+ return result;
548
+ }
549
+ };
539
550
  var SubmitQueue = class {
540
551
  constructor(storage) {
541
552
  this.storage = storage;
553
+ this.writes = new SerialWrites();
542
554
  }
543
555
  async enqueue(payload, options) {
544
- const queue = await this.read() ?? [];
545
556
  const entry = {
546
557
  id: cryptoRandomId(),
547
558
  // Reuse the caller's key when supplied — that's how the first
@@ -552,8 +563,11 @@ var SubmitQueue = class {
552
563
  queuedAt: (/* @__PURE__ */ new Date()).toISOString(),
553
564
  payload
554
565
  };
555
- queue.push(entry);
556
- await this.storage.set(QUEUE_KEY, queue);
566
+ await this.writes.run(async () => {
567
+ const queue = await this.read() ?? [];
568
+ queue.push(entry);
569
+ await this.storage.set(QUEUE_KEY, queue);
570
+ });
557
571
  return entry;
558
572
  }
559
573
  async size() {
@@ -595,11 +609,16 @@ var SubmitQueue = class {
595
609
  }
596
610
  }
597
611
  }
598
- if (remaining.length === 0) {
599
- await this.storage.remove(QUEUE_KEY);
600
- } else {
601
- await this.storage.set(QUEUE_KEY, remaining);
602
- }
612
+ await this.writes.run(async () => {
613
+ const handled = new Set(queue.map((entry) => entry.id));
614
+ const added = (await this.read() ?? []).filter((entry) => !handled.has(entry.id));
615
+ const next = [...remaining, ...added];
616
+ if (next.length === 0) {
617
+ await this.storage.remove(QUEUE_KEY);
618
+ } else {
619
+ await this.storage.set(QUEUE_KEY, next);
620
+ }
621
+ });
603
622
  return result;
604
623
  }
605
624
  async read() {
@@ -609,17 +628,20 @@ var SubmitQueue = class {
609
628
  var AttachmentQueue = class {
610
629
  constructor(storage) {
611
630
  this.storage = storage;
631
+ this.writes = new SerialWrites();
612
632
  }
613
633
  async enqueue(bugReportId, attachment) {
614
- const queue = await this.read() ?? [];
615
634
  const entry = {
616
635
  id: cryptoRandomId(),
617
636
  bugReportId,
618
637
  queuedAt: (/* @__PURE__ */ new Date()).toISOString(),
619
638
  attachment
620
639
  };
621
- queue.push(entry);
622
- await this.storage.set(ATTACHMENT_QUEUE_KEY, queue);
640
+ await this.writes.run(async () => {
641
+ const queue = await this.read() ?? [];
642
+ queue.push(entry);
643
+ await this.storage.set(ATTACHMENT_QUEUE_KEY, queue);
644
+ });
623
645
  return entry;
624
646
  }
625
647
  async size() {
@@ -658,11 +680,16 @@ var AttachmentQueue = class {
658
680
  }
659
681
  }
660
682
  }
661
- if (remaining.length === 0) {
662
- await this.storage.remove(ATTACHMENT_QUEUE_KEY);
663
- } else {
664
- await this.storage.set(ATTACHMENT_QUEUE_KEY, remaining);
665
- }
683
+ await this.writes.run(async () => {
684
+ const handled = new Set(queue.map((entry) => entry.id));
685
+ const added = (await this.read() ?? []).filter((entry) => !handled.has(entry.id));
686
+ const next = [...remaining, ...added];
687
+ if (next.length === 0) {
688
+ await this.storage.remove(ATTACHMENT_QUEUE_KEY);
689
+ } else {
690
+ await this.storage.set(ATTACHMENT_QUEUE_KEY, next);
691
+ }
692
+ });
666
693
  return result;
667
694
  }
668
695
  async read() {
@@ -1042,7 +1069,7 @@ function findAssignmentForTask(tasks, key) {
1042
1069
  }
1043
1070
 
1044
1071
  // package.json
1045
- var version = "2.0.1";
1072
+ var version = "2.1.1";
1046
1073
 
1047
1074
  // src/version.ts
1048
1075
  var SDK_VERSION = `@testerpaykit/expo/${version}`;
@@ -1247,6 +1274,9 @@ var TpkExpo = class _TpkExpo {
1247
1274
  this.crashFlush = Promise.resolve();
1248
1275
  // ── Access (who sees the widget) ──
1249
1276
  this.accessValue = "hidden";
1277
+ /** `syncSessions: false`: nothing reaches the server until a report does. */
1278
+ this.quietUntilReport = false;
1279
+ this.signingIn = null;
1250
1280
  this.handleValue = null;
1251
1281
  /** Bumped by a tester-gate 403: a check that started before it must
1252
1282
  * not bring a stale "ready" back. */
@@ -1278,6 +1308,9 @@ var TpkExpo = class _TpkExpo {
1278
1308
  }
1279
1309
  return this.compensationClient.client;
1280
1310
  }
1311
+ get syncSessions() {
1312
+ return this.config.syncSessions !== false;
1313
+ }
1281
1314
  static async init(config) {
1282
1315
  runSetupCheck();
1283
1316
  const storage = config.storage ?? new ExpoStorage();
@@ -1297,6 +1330,7 @@ var TpkExpo = class _TpkExpo {
1297
1330
  let tester;
1298
1331
  let authReady;
1299
1332
  let hasCachedAuth = false;
1333
+ const signInLater = config.syncSessions === false && (await storage.get(STORAGE_KEY_PHONE))?.approved !== true;
1300
1334
  const acquireFreshAuth = async () => {
1301
1335
  try {
1302
1336
  const fresh = await api.loginAnonymous(config.projectId, config.testerCode);
@@ -1312,7 +1346,7 @@ var TpkExpo = class _TpkExpo {
1312
1346
  authReady = Promise.resolve();
1313
1347
  } else {
1314
1348
  tester = { id: "", projectId: config.projectId, code: config.testerCode };
1315
- authReady = acquireFreshAuth();
1349
+ authReady = signInLater ? Promise.resolve() : acquireFreshAuth();
1316
1350
  }
1317
1351
  let sessionId = "";
1318
1352
  let sessionReady;
@@ -1324,8 +1358,12 @@ var TpkExpo = class _TpkExpo {
1324
1358
  } catch {
1325
1359
  }
1326
1360
  });
1327
- const persisted = await loadPersistedSession(storage, config.projectId, config.testerCode);
1328
- if (persisted) {
1361
+ const syncSessions = config.syncSessions !== false;
1362
+ const persisted = syncSessions ? await loadPersistedSession(storage, config.projectId, config.testerCode) : null;
1363
+ if (!syncSessions) {
1364
+ sessionId = uuidv4();
1365
+ sessionReady = Promise.resolve();
1366
+ } else if (persisted) {
1329
1367
  sessionId = persisted;
1330
1368
  sessionReady = Promise.resolve();
1331
1369
  } else if (hasCachedAuth) {
@@ -1359,6 +1397,7 @@ var TpkExpo = class _TpkExpo {
1359
1397
  );
1360
1398
  instance.tester = tester;
1361
1399
  instance.sessionId = sessionId;
1400
+ instance.quietUntilReport = signInLater;
1362
1401
  sessionReady.then(() => {
1363
1402
  instance.sessionId = sessionId;
1364
1403
  });
@@ -1385,7 +1424,7 @@ var TpkExpo = class _TpkExpo {
1385
1424
  intervalMs: config.flushIntervalMs ?? 6e4,
1386
1425
  appState
1387
1426
  });
1388
- instance.uninstallTaskBinding = instance.bindTaskCompletion();
1427
+ if (syncSessions) instance.uninstallTaskBinding = instance.bindTaskCompletion();
1389
1428
  if (config.flushQueueOnInit !== false) {
1390
1429
  instance.flushQueue().catch(() => {
1391
1430
  });
@@ -1412,6 +1451,7 @@ var TpkExpo = class _TpkExpo {
1412
1451
  const payload = await this.buildPayload(input);
1413
1452
  const idempotencyKey = uuidv4();
1414
1453
  try {
1454
+ await this.signInForReport();
1415
1455
  const response = await this.api.submitBugReport(payload, {
1416
1456
  idempotencyKey
1417
1457
  });
@@ -1555,6 +1595,7 @@ var TpkExpo = class _TpkExpo {
1555
1595
  const cached2 = await this.storage.get(STORAGE_KEY_PHONE);
1556
1596
  const cachedOk = cached2?.approved === true;
1557
1597
  if (cachedOk && !options.revalidate) return "verified";
1598
+ await this.signInForReport();
1558
1599
  let status;
1559
1600
  try {
1560
1601
  let profile;
@@ -1582,6 +1623,29 @@ var TpkExpo = class _TpkExpo {
1582
1623
  }
1583
1624
  return status;
1584
1625
  }
1626
+ /**
1627
+ * Signs in for the first report when `syncSessions: false` left that open,
1628
+ * or just ends the quiet with a stored login. Concurrent callers share one
1629
+ * sign-in; a failure is retried by the next one.
1630
+ */
1631
+ signInForReport() {
1632
+ if (!this.quietUntilReport) return Promise.resolve();
1633
+ this.signingIn ?? (this.signingIn = (async () => {
1634
+ try {
1635
+ if (!this.tester.id) {
1636
+ const fresh = await this.api.loginAnonymous(this.config.projectId, this.config.testerCode);
1637
+ await this.storage.set(STORAGE_KEY_AUTH, fresh);
1638
+ this.tester = fresh.tester;
1639
+ }
1640
+ this.quietUntilReport = false;
1641
+ void this.refreshAccess().catch(() => void 0);
1642
+ } catch {
1643
+ } finally {
1644
+ this.signingIn = null;
1645
+ }
1646
+ })());
1647
+ return this.signingIn;
1648
+ }
1585
1649
  /**
1586
1650
  * Drop a login the server no longer accepts, with its session and phone
1587
1651
  * state, and log in anonymously again, like a first start. Concurrent
@@ -1595,6 +1659,7 @@ var TpkExpo = class _TpkExpo {
1595
1659
  const fresh = await this.api.loginAnonymous(this.config.projectId, this.config.testerCode);
1596
1660
  await this.storage.set(STORAGE_KEY_AUTH, fresh);
1597
1661
  this.tester = fresh.tester;
1662
+ if (!this.syncSessions) return true;
1598
1663
  try {
1599
1664
  this.sessionId = await startServerSession(this.api, fresh.tester.projectId);
1600
1665
  await persistSession(this.storage, this.sessionId, this.config.projectId, this.config.testerCode);
@@ -1632,6 +1697,7 @@ var TpkExpo = class _TpkExpo {
1632
1697
  * `revalidate: false` answers from the cache when there is one.
1633
1698
  */
1634
1699
  async refreshAccess(options = {}) {
1700
+ if (this.quietUntilReport) return this.accessValue;
1635
1701
  const generation = this.accessGeneration;
1636
1702
  let status;
1637
1703
  try {
@@ -1705,6 +1771,7 @@ var TpkExpo = class _TpkExpo {
1705
1771
  */
1706
1772
  async startPhone(phone) {
1707
1773
  try {
1774
+ await this.signInForReport();
1708
1775
  const r = await this.api.startPhoneVerification(phone);
1709
1776
  return { ok: true, verificationId: r.verificationId, devCode: r.devCode };
1710
1777
  } catch (e) {
@@ -1792,6 +1859,7 @@ var TpkExpo = class _TpkExpo {
1792
1859
  await this.storage.set(STORAGE_KEY_AUTH, fresh);
1793
1860
  this.api.setAccessToken(fresh.accessToken);
1794
1861
  this.tester = fresh.tester;
1862
+ if (!this.syncSessions) return;
1795
1863
  const sid = await startServerSession(this.api, fresh.tester.projectId);
1796
1864
  this.sessionId = sid;
1797
1865
  await persistSession(this.storage, sid, this.config.projectId, code);
@@ -1840,7 +1908,7 @@ var TpkExpo = class _TpkExpo {
1840
1908
  if (!this.sessionId) return Promise.reject(new Error("no session yet"));
1841
1909
  payload = { ...payload, sessionId: this.sessionId };
1842
1910
  }
1843
- return this.api.submitBugReport(payload, options);
1911
+ return this.signInForReport().then(() => this.api.submitBugReport(payload, options));
1844
1912
  }
1845
1913
  });
1846
1914
  }
@@ -1850,6 +1918,7 @@ var TpkExpo = class _TpkExpo {
1850
1918
  */
1851
1919
  async attachToBugReport(bugReportId, attachment) {
1852
1920
  try {
1921
+ await this.signInForReport();
1853
1922
  return await this.api.attachToBugReport(bugReportId, attachment);
1854
1923
  } catch (e) {
1855
1924
  const status = extractStatus2(e);
@@ -1871,7 +1940,7 @@ var TpkExpo = class _TpkExpo {
1871
1940
  /** Flush queued attachment uploads immediately. */
1872
1941
  async flushAttachmentQueue() {
1873
1942
  return this.attachmentQueue.flush({
1874
- attach: (bugReportId, attachment) => this.api.attachToBugReport(bugReportId, attachment)
1943
+ attach: (bugReportId, attachment) => this.signInForReport().then(() => this.api.attachToBugReport(bugReportId, attachment))
1875
1944
  });
1876
1945
  }
1877
1946
  /** Cached crashes available for post-crash review or retry. */
@@ -1916,6 +1985,10 @@ var TpkExpo = class _TpkExpo {
1916
1985
  }
1917
1986
  /** Flush pending session events + breadcrumbs to timeline endpoints. */
1918
1987
  async flushTelemetry() {
1988
+ if (!this.syncSessions) {
1989
+ this.sessionEvents.splice(0, this.sessionEvents.length - MAX_LOCAL_EVENTS);
1990
+ return { eventsInserted: 0, breadcrumbsInserted: 0 };
1991
+ }
1919
1992
  if (!this.sessionId) {
1920
1993
  return { eventsInserted: 0, breadcrumbsInserted: 0 };
1921
1994
  }
@@ -1950,6 +2023,7 @@ var TpkExpo = class _TpkExpo {
1950
2023
  await this.compensation.act(a, "pause", workSeconds(a, Date.now() + offset));
1951
2024
  }
1952
2025
  }
2026
+ if (!this.syncSessions) return;
1953
2027
  await this.flushTelemetry();
1954
2028
  await this.api.endTesterSession({
1955
2029
  sessionId: this.sessionId,
@@ -1962,14 +2036,18 @@ var TpkExpo = class _TpkExpo {
1962
2036
  }
1963
2037
  /** Rotate the server-side session id (call after a logical restart). */
1964
2038
  async rotateSession() {
1965
- await this.flushTelemetry();
1966
- this.sessionId = await startServerSession(this.api, this.tester.projectId);
1967
- await persistSession(
1968
- this.storage,
1969
- this.sessionId,
1970
- this.config.projectId,
1971
- this.config.testerCode
1972
- );
2039
+ if (this.syncSessions) {
2040
+ await this.flushTelemetry();
2041
+ this.sessionId = await startServerSession(this.api, this.tester.projectId);
2042
+ await persistSession(
2043
+ this.storage,
2044
+ this.sessionId,
2045
+ this.config.projectId,
2046
+ this.config.testerCode
2047
+ );
2048
+ } else {
2049
+ this.sessionId = uuidv4();
2050
+ }
1973
2051
  this.capturedCrashes.clear();
1974
2052
  this.submittedCrashes.clear();
1975
2053
  this.breadcrumbs.record({ action: "tpk", target: "session_rotated" });
@@ -2112,10 +2190,15 @@ var TpkExpo = class _TpkExpo {
2112
2190
  title: truncate(info.message, 200),
2113
2191
  description: composeCrashDescription(info)
2114
2192
  });
2115
- await this.api.submitBugReport(payload, { idempotencyKey: crashId });
2193
+ await this.signInForReport();
2194
+ await this.api.submitBugReport(
2195
+ { ...payload, automatic: true },
2196
+ { idempotencyKey: crashId }
2197
+ );
2116
2198
  this.breadcrumbs.record({ action: "tpk", target: "crash_submitted" });
2117
2199
  }
2118
2200
  };
2201
+ var MAX_LOCAL_EVENTS = 1e3;
2119
2202
  function lastScreen(buf) {
2120
2203
  const snapshot = buf.snapshot();
2121
2204
  for (let i = snapshot.length - 1; i >= 0; i--) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testerpaykit/expo",
3
- "version": "2.0.1",
3
+ "version": "2.1.1",
4
4
  "description": "TesterPayKit Expo / React-Native bindings — shake-to-report, device info, bug-report hook",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",