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