@wireai/activation 0.9.1 → 0.9.2

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/dist/index.mjs CHANGED
@@ -3345,6 +3345,7 @@ var clearPersistedSession = (storage, key) => {
3345
3345
  } catch {
3346
3346
  }
3347
3347
  };
3348
+ var shouldClearOnComplete = (retainSessionOnComplete) => !retainSessionOnComplete;
3348
3349
 
3349
3350
  // src/identity/userIdentity.ts
3350
3351
  var USER_ID_MAX_LENGTH = 128;
@@ -3394,6 +3395,7 @@ var WireOnboarding = ({
3394
3395
  storage,
3395
3396
  sessionTtlMs = DEFAULT_SESSION_TTL_MS,
3396
3397
  persistKey,
3398
+ retainSessionOnComplete,
3397
3399
  userContext,
3398
3400
  userId
3399
3401
  }) => {
@@ -3428,10 +3430,10 @@ var WireOnboarding = ({
3428
3430
  }, [storage, storageKey, sessionTtlMs, session]);
3429
3431
  const handleComplete = useCallback(
3430
3432
  (result) => {
3431
- if (storage) clearPersistedSession(storage, storageKey);
3433
+ if (storage && shouldClearOnComplete(retainSessionOnComplete)) clearPersistedSession(storage, storageKey);
3432
3434
  onComplete(result);
3433
3435
  },
3434
- [storage, storageKey, onComplete]
3436
+ [storage, storageKey, retainSessionOnComplete, onComplete]
3435
3437
  );
3436
3438
  const sessionId = (_a2 = session == null ? void 0 : session.id) != null ? _a2 : "";
3437
3439
  const startupUserIdRef = useRef(boundUserId);
@@ -4427,8 +4429,9 @@ var createEventQueue = (options) => {
4427
4429
  } catch {
4428
4430
  }
4429
4431
  })();
4432
+ const DROP_STATUSES = /* @__PURE__ */ new Set([400, 404, 413, 422]);
4430
4433
  const postBatch = async (events) => {
4431
- if (!(target == null ? void 0 : target.serverUrl) || events.length === 0) return false;
4434
+ if (!(target == null ? void 0 : target.serverUrl) || events.length === 0) return "retry";
4432
4435
  const controller = typeof AbortController !== "undefined" ? new AbortController() : void 0;
4433
4436
  const timer = setTimeout(() => controller == null ? void 0 : controller.abort(), 15e3);
4434
4437
  try {
@@ -4441,9 +4444,12 @@ var createEventQueue = (options) => {
4441
4444
  body: JSON.stringify({ events }),
4442
4445
  signal: controller == null ? void 0 : controller.signal
4443
4446
  });
4444
- return !!(res && res.ok);
4447
+ if (res && res.ok) return "ok";
4448
+ const status = res == null ? void 0 : res.status;
4449
+ if (typeof status === "number" && DROP_STATUSES.has(status)) return "drop";
4450
+ return "retry";
4445
4451
  } catch {
4446
- return false;
4452
+ return "retry";
4447
4453
  } finally {
4448
4454
  clearTimeout(timer);
4449
4455
  }
@@ -4475,8 +4481,8 @@ var createEventQueue = (options) => {
4475
4481
  try {
4476
4482
  while (pending.length > 0) {
4477
4483
  const batch = pending.slice(0, batchSize);
4478
- const ok = await postBatch(batch.map((item) => item.event));
4479
- if (!ok) {
4484
+ const result = await postBatch(batch.map((item) => item.event));
4485
+ if (result === "retry") {
4480
4486
  scheduleRetry();
4481
4487
  return;
4482
4488
  }