@traqio/web 0.1.1 → 0.1.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/build/index.cjs CHANGED
@@ -338,7 +338,7 @@ var require_build = __commonJS({
338
338
  var skan_1 = require_skan();
339
339
  var adservices_1 = require_adservices();
340
340
  var deeplink_1 = require_deeplink();
341
- exports.SDK_VERSION = "0.1.1";
341
+ exports.SDK_VERSION = "0.1.2";
342
342
  var skan_2 = require_skan();
343
343
  Object.defineProperty(exports, "Skan", { enumerable: true, get: function() {
344
344
  return skan_2.Skan;
@@ -362,6 +362,7 @@ var require_build = __commonJS({
362
362
  var DEFERRED_KEY = "traq_deferred_link";
363
363
  var CONSENT_KEY = "traq_consent";
364
364
  var MAX_BATCH = 20;
365
+ var NON_RETRYABLE_STATUS = /* @__PURE__ */ new Set([400, 413, 422]);
365
366
  var MAX_QUEUE = 500;
366
367
  var MAX_AD_BATCH = 100;
367
368
  var MAX_AD_QUEUE = 1e3;
@@ -1036,13 +1037,16 @@ var require_build = __commonJS({
1036
1037
  try {
1037
1038
  while (this.queue.length) {
1038
1039
  const batch = this.queue.slice(0, MAX_BATCH);
1039
- const ok = await this.post({
1040
+ const outcome = await this.send({
1040
1041
  events: batch,
1041
1042
  appUserId: this.opts.userId,
1042
1043
  deviceId: this.context.deviceId
1043
1044
  });
1044
- if (!ok)
1045
+ if (outcome === "retry")
1045
1046
  return this.backOff();
1047
+ if (outcome === "refused") {
1048
+ console.warn(`[traqio] the server refused ${batch.length} event(s) as malformed \u2014 dropped, not retried`);
1049
+ }
1046
1050
  this.queue.splice(0, batch.length);
1047
1051
  await this.persistQueue();
1048
1052
  this.retryMs = BASE_RETRY_MS;
@@ -1119,6 +1123,15 @@ var require_build = __commonJS({
1119
1123
  return this.isWeb ? { keepalive: true } : {};
1120
1124
  }
1121
1125
  async post(body, path = "/ingest") {
1126
+ return await this.send(body, path) === "ok";
1127
+ }
1128
+ /**
1129
+ * `post`, with the failure split in two: `refused` is a status the same body will
1130
+ * get again on every retry (400 malformed, 413 too large, 422 unprocessable);
1131
+ * `retry` is everything else — network down, 5xx, 429, and 401/403 too, since a
1132
+ * key fixed in the console makes the same queued batch succeed.
1133
+ */
1134
+ async send(body, path = "/ingest") {
1122
1135
  const consent = this.consent && (path === "/ingest" || path === "/ingest/session") ? { consent: this.consent } : {};
1123
1136
  try {
1124
1137
  const res = await fetch(`${this.opts.endpoint}${path}`, {
@@ -1127,9 +1140,11 @@ var require_build = __commonJS({
1127
1140
  body: JSON.stringify({ sdkKey: this.opts.sdkKey, ...body, ...consent }),
1128
1141
  ...this.keepalive()
1129
1142
  });
1130
- return res.ok;
1143
+ if (res.ok)
1144
+ return "ok";
1145
+ return NON_RETRYABLE_STATUS.has(res.status) ? "refused" : "retry";
1131
1146
  } catch {
1132
- return false;
1147
+ return "retry";
1133
1148
  }
1134
1149
  }
1135
1150
  };