@wireai/activation 0.9.2 → 0.10.0

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.
@@ -497,22 +497,38 @@ var useScreenTracking = (navigationRef, options = {}) => {
497
497
 
498
498
  // src/analytics/reportClientEvent.ts
499
499
  var makeSessionId = () => `wire_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
500
- var reportClientEvents = (target, events) => {
501
- if (!(target == null ? void 0 : target.serverUrl) || events.length === 0) return;
500
+ var buildEventsRequest = (target, events) => {
501
+ if (!(target == null ? void 0 : target.serverUrl) || events.length === 0) return null;
502
502
  try {
503
503
  const url = `${target.serverUrl.replace(/\/$/, "")}/v1/events`;
504
504
  const headers = { "Content-Type": "application/json" };
505
505
  if (target.apiKey) headers.Authorization = `Bearer ${target.apiKey}`;
506
- void fetch(url, {
507
- method: "POST",
508
- headers,
509
- body: JSON.stringify({ events })
510
- }).catch(() => {
506
+ return { url, init: { method: "POST", headers, body: JSON.stringify({ events }) } };
507
+ } catch {
508
+ return null;
509
+ }
510
+ };
511
+ var reportClientEvents = (target, events) => {
512
+ try {
513
+ const req = buildEventsRequest(target, events);
514
+ if (!req) return;
515
+ void fetch(req.url, req.init).catch(() => {
511
516
  });
512
517
  } catch {
513
518
  }
514
519
  };
515
520
  var reportClientEvent = (target, event) => reportClientEvents(target, [event]);
521
+ var reportClientEventsAwait = async (target, events) => {
522
+ try {
523
+ const req = buildEventsRequest(target, events);
524
+ if (!req) return false;
525
+ const res = await fetch(req.url, req.init);
526
+ return Boolean(res && res.ok);
527
+ } catch {
528
+ return false;
529
+ }
530
+ };
531
+ var reportClientEventAwait = (target, event) => reportClientEventsAwait(target, [event]);
516
532
 
517
533
  // src/analytics/analyticsEvent.ts
518
534
  var WIRE_ONBOARDING_EVENTS = {
@@ -858,9 +874,8 @@ var createEventQueue = (options) => {
858
874
  } catch {
859
875
  }
860
876
  })();
861
- const DROP_STATUSES = /* @__PURE__ */ new Set([400, 404, 413, 422]);
862
877
  const postBatch = async (events) => {
863
- if (!(target == null ? void 0 : target.serverUrl) || events.length === 0) return "retry";
878
+ if (!(target == null ? void 0 : target.serverUrl) || events.length === 0) return false;
864
879
  const controller = typeof AbortController !== "undefined" ? new AbortController() : void 0;
865
880
  const timer = setTimeout(() => controller == null ? void 0 : controller.abort(), 15e3);
866
881
  try {
@@ -873,12 +888,9 @@ var createEventQueue = (options) => {
873
888
  body: JSON.stringify({ events }),
874
889
  signal: controller == null ? void 0 : controller.signal
875
890
  });
876
- if (res && res.ok) return "ok";
877
- const status = res == null ? void 0 : res.status;
878
- if (typeof status === "number" && DROP_STATUSES.has(status)) return "drop";
879
- return "retry";
891
+ return !!(res && res.ok);
880
892
  } catch {
881
- return "retry";
893
+ return false;
882
894
  } finally {
883
895
  clearTimeout(timer);
884
896
  }
@@ -910,8 +922,8 @@ var createEventQueue = (options) => {
910
922
  try {
911
923
  while (pending.length > 0) {
912
924
  const batch = pending.slice(0, batchSize);
913
- const result = await postBatch(batch.map((item) => item.event));
914
- if (result === "retry") {
925
+ const ok = await postBatch(batch.map((item) => item.event));
926
+ if (!ok) {
915
927
  scheduleRetry();
916
928
  return;
917
929
  }
@@ -955,13 +967,18 @@ var createEventQueue = (options) => {
955
967
  };
956
968
 
957
969
  // src/analytics/currentSession.ts
958
- var _currentSessionId;
970
+ var CURRENT_SESSION_ID_SLOT = /* @__PURE__ */ Symbol.for(
971
+ "@wireai/activation:currentSessionId"
972
+ );
973
+ var globalSlot = globalThis;
959
974
  var setCurrentSessionId = (id) => {
960
- if (typeof id === "string" && id.length > 0) _currentSessionId = id;
975
+ if (typeof id === "string" && id.length > 0) {
976
+ globalSlot[CURRENT_SESSION_ID_SLOT] = id;
977
+ }
961
978
  };
962
- var getCurrentSessionId = () => _currentSessionId;
979
+ var getCurrentSessionId = () => globalSlot[CURRENT_SESSION_ID_SLOT];
963
980
  var resetCurrentSessionId = () => {
964
- _currentSessionId = void 0;
981
+ globalSlot[CURRENT_SESSION_ID_SLOT] = void 0;
965
982
  };
966
983
 
967
984
  // src/identity/userIdentity.ts
@@ -1179,6 +1196,6 @@ var useAnalytics = (config, options = {}) => {
1179
1196
  return ref.current;
1180
1197
  };
1181
1198
 
1182
- export { WIRE_ONBOARDING_EVENTS, buildContextEnvelope, createAnalytics, createEventQueue, createScreenTracker, getActiveRouteName, getCurrentSessionId, makeSessionId, reportAppEvent, reportClientEvent, reportClientEvents, resetCurrentSessionId, screenTrackingHandler, setCurrentSessionId, toAnalyticsEvent, useAnalytics, useScreenTracking };
1199
+ export { WIRE_ONBOARDING_EVENTS, buildContextEnvelope, createAnalytics, createEventQueue, createScreenTracker, getActiveRouteName, getCurrentSessionId, makeSessionId, reportAppEvent, reportClientEvent, reportClientEventAwait, reportClientEvents, reportClientEventsAwait, resetCurrentSessionId, screenTrackingHandler, setCurrentSessionId, toAnalyticsEvent, useAnalytics, useScreenTracking };
1183
1200
  //# sourceMappingURL=index.mjs.map
1184
1201
  //# sourceMappingURL=index.mjs.map