@mochabug/adapt-web 1.0.0-rc40 → 1.0.0-rc41

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.
@@ -5800,6 +5800,21 @@ var MbAdapt = (() => {
5800
5800
  }
5801
5801
  return true;
5802
5802
  };
5803
+ const retryCall = async (fn, maxRetries = 3) => {
5804
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
5805
+ try {
5806
+ return await fn();
5807
+ } catch (error) {
5808
+ if (attempt === maxRetries)
5809
+ throw error;
5810
+ if (!isRetriableError(error))
5811
+ throw error;
5812
+ const backoff = Math.min(500 * (1 << attempt), 5e3);
5813
+ await new Promise((r) => setTimeout(r, Math.random() * backoff));
5814
+ }
5815
+ }
5816
+ throw new Error("unreachable");
5817
+ };
5803
5818
  const clearSeenMessages = () => {
5804
5819
  seenMessages.clear();
5805
5820
  seenMessagesOrder.length = 0;
@@ -5964,6 +5979,10 @@ var MbAdapt = (() => {
5964
5979
  abortController = controller;
5965
5980
  currentHandlers = options2 ?? {};
5966
5981
  reconnectAttempts = 0;
5982
+ const runHeaders = {
5983
+ ...options2?.authToken ? authHeader(options2.authToken) : {},
5984
+ "x-idempotency-key": crypto.randomUUID()
5985
+ };
5967
5986
  let resolve;
5968
5987
  let reject;
5969
5988
  const sessionPromise = new Promise((res, rej) => {
@@ -5973,7 +5992,7 @@ var MbAdapt = (() => {
5973
5992
  const attemptRunSession = async () => {
5974
5993
  const stream = raw.runSession(request, {
5975
5994
  signal: controller.signal,
5976
- headers: options2?.authToken ? authHeader(options2.authToken) : {}
5995
+ headers: runHeaders
5977
5996
  });
5978
5997
  let token;
5979
5998
  let resetTimer = null;
@@ -6161,8 +6180,11 @@ var MbAdapt = (() => {
6161
6180
  signals: buildSignals(options2?.signals),
6162
6181
  challengeToken: options2?.challengeToken
6163
6182
  });
6164
- const headers = options2?.authToken ? authHeader(options2.authToken) : {};
6165
- const response = await raw.startSession(request, { headers });
6183
+ const headers = {
6184
+ ...options2?.authToken ? authHeader(options2.authToken) : {},
6185
+ "x-idempotency-key": crypto.randomUUID()
6186
+ };
6187
+ const response = await retryCall(() => raw.startSession(request, { headers }));
6166
6188
  log("info", "start success", { token: response.token });
6167
6189
  return {
6168
6190
  sessionToken: response.token,
@@ -6171,7 +6193,7 @@ var MbAdapt = (() => {
6171
6193
  },
6172
6194
  async inherit(parentToken) {
6173
6195
  log("info", "inherit");
6174
- const response = await raw.inheritSession({ id }, { headers: authHeader(parentToken) });
6196
+ const response = await retryCall(() => raw.inheritSession({ id }, { headers: authHeader(parentToken) }));
6175
6197
  log("info", "inherit success", { token: response.token });
6176
6198
  return {
6177
6199
  sessionToken: response.token,
@@ -6190,7 +6212,7 @@ var MbAdapt = (() => {
6190
6212
  },
6191
6213
  async stop(token) {
6192
6214
  log("info", "stop");
6193
- await raw.stopSession({ id }, { headers: authHeader(token) });
6215
+ await retryCall(() => raw.stopSession({ id }, { headers: authHeader(token) }));
6194
6216
  log("info", "stop success");
6195
6217
  },
6196
6218
  async unsubscribe() {
@@ -6204,7 +6226,7 @@ var MbAdapt = (() => {
6204
6226
  },
6205
6227
  async getSession(token) {
6206
6228
  log("info", "getSession");
6207
- const response = await raw.getSession({ id }, { headers: authHeader(token) });
6229
+ const response = await retryCall(() => raw.getSession({ id }, { headers: authHeader(token) }));
6208
6230
  const result = {
6209
6231
  status: enumToJson(StatusSchema, response.session.status),
6210
6232
  fork: response.session.fork
@@ -6214,12 +6236,12 @@ var MbAdapt = (() => {
6214
6236
  },
6215
6237
  async readOutput(token, opts) {
6216
6238
  log("info", "readOutput", opts);
6217
- const response = await raw.readOutput({
6239
+ const response = await retryCall(() => raw.readOutput({
6218
6240
  id,
6219
6241
  pageSize: opts?.pageSize,
6220
6242
  vertex: opts?.vertex,
6221
6243
  newerThan: opts?.newerThan?.toISOString()
6222
- }, { headers: authHeader(token) });
6244
+ }, { headers: authHeader(token) }));
6223
6245
  const result = {
6224
6246
  session: {
6225
6247
  status: enumToJson(StatusSchema, response.session.status),
@@ -6250,12 +6272,12 @@ var MbAdapt = (() => {
6250
6272
  },
6251
6273
  async readOutputBinary(token, opts) {
6252
6274
  log("info", "readOutputBinary", opts);
6253
- const response = await raw.readOutput({
6275
+ const response = await retryCall(() => raw.readOutput({
6254
6276
  id,
6255
6277
  pageSize: opts?.pageSize,
6256
6278
  vertex: opts?.vertex,
6257
6279
  newerThan: opts?.newerThan?.toISOString()
6258
- }, { headers: authHeader(token) });
6280
+ }, { headers: authHeader(token) }));
6259
6281
  const result = {
6260
6282
  session: {
6261
6283
  status: enumToJson(StatusSchema, response.session.status),
@@ -6276,11 +6298,11 @@ var MbAdapt = (() => {
6276
6298
  },
6277
6299
  async readUrls(token, opts) {
6278
6300
  log("info", "readUrls", opts);
6279
- const response = await raw.readUrls({
6301
+ const response = await retryCall(() => raw.readUrls({
6280
6302
  id,
6281
6303
  pageSize: opts?.pageSize,
6282
6304
  newerThan: opts?.newerThan
6283
- }, { headers: authHeader(token) });
6305
+ }, { headers: authHeader(token) }));
6284
6306
  const result = {
6285
6307
  session: {
6286
6308
  status: enumToJson(StatusSchema, response.session.status),
@@ -7181,7 +7203,7 @@ var MbAdapt = (() => {
7181
7203
  // src/index.ts
7182
7204
  if (typeof window !== "undefined" && true && !window.CAP_CUSTOM_WASM_URL) {
7183
7205
  window.CAP_CUSTOM_WASM_URL = new URL(
7184
- "https://cdn.mochabug.com/adapt/web/1.0.0-rc40/cap_wasm.js",
7206
+ "https://cdn.mochabug.com/adapt/web/1.0.0-rc41/cap_wasm.js",
7185
7207
  window.location.href
7186
7208
  ).href;
7187
7209
  }