@naturalcycles/internal-web-lib 1.4.0 → 1.5.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.
@@ -117,7 +117,7 @@ var f = d(({ level: e, msg: t, err: n, ...r }) => {
117
117
  }(), m = p.runInBackground.bind(p), te = (...e) => void 0, h = Object.entries;
118
118
  //#endregion
119
119
  //#region ../../node_modules/.pnpm/@naturalcycles+js-lib@15.93.0_undici@8.11.2/node_modules/@naturalcycles/js-lib/dist/object/object.util.js
120
- function ne(e, t, n = {}) {
120
+ function g(e, t, n = {}) {
121
121
  if (n.mutate) {
122
122
  for (let n of Object.keys(e)) t.includes(n) || delete e[n];
123
123
  return e;
@@ -126,7 +126,7 @@ function ne(e, t, n = {}) {
126
126
  for (let n of t) n in e && (r[n] = e[n]);
127
127
  return r;
128
128
  }
129
- function g(e, t, n = {}) {
129
+ function _(e, t, n = {}) {
130
130
  if (n.mutate) {
131
131
  for (let n of t) delete e[n];
132
132
  return e;
@@ -135,16 +135,16 @@ function g(e, t, n = {}) {
135
135
  for (let n of Object.keys(e)) t.includes(n) || (r[n] = e[n]);
136
136
  return r;
137
137
  }
138
- function re(e, t = {}) {
139
- return y(e, (e, t) => !!t, t);
140
- }
141
- function _(e, t = {}) {
142
- return y(e, (e, t) => t != null, t);
138
+ function ne(e, t = {}) {
139
+ return b(e, (e, t) => !!t, t);
143
140
  }
144
141
  function v(e, t = {}) {
145
- return y(e, (e, t) => t !== void 0, t);
142
+ return b(e, (e, t) => t != null, t);
143
+ }
144
+ function y(e, t = {}) {
145
+ return b(e, (e, t) => t !== void 0, t);
146
146
  }
147
- function y(e, t, n = {}) {
147
+ function b(e, t, n = {}) {
148
148
  if (n.mutate) {
149
149
  for (let [n, r] of h(e)) t(n, r, e) || delete e[n];
150
150
  return e;
@@ -153,24 +153,24 @@ function y(e, t, n = {}) {
153
153
  for (let [n, i] of h(e)) t(n, i, e) && (r[n] = i);
154
154
  return r;
155
155
  }
156
- function b(e, t) {
156
+ function x(e, t) {
157
157
  let n = {};
158
158
  for (let [r, i] of Object.entries(e)) n[t(r, i, e)] = i;
159
159
  return n;
160
160
  }
161
- function ie(e, t = {}) {
162
- return y(e, (e, t) => !i(t), t);
161
+ function re(e, t = {}) {
162
+ return b(e, (e, t) => !i(t), t);
163
163
  }
164
- function x(e, ...t) {
165
- for (let n of t) if (r(n)) for (let t of Object.keys(n)) t !== "__proto__" && t !== "constructor" && t !== "prototype" && (r(n[t]) ? (e[t] ||= {}, x(e[t], n[t])) : e[t] = n[t]);
164
+ function S(e, ...t) {
165
+ for (let n of t) if (r(n)) for (let t of Object.keys(n)) t !== "__proto__" && t !== "constructor" && t !== "prototype" && (r(n[t]) ? (e[t] ||= {}, S(e[t], n[t])) : e[t] = n[t]);
166
166
  return e;
167
167
  }
168
168
  //#endregion
169
169
  //#region ../../node_modules/.pnpm/@naturalcycles+js-lib@15.93.0_undici@8.11.2/node_modules/@naturalcycles/js-lib/dist/env.js
170
- function S() {
171
- return !C();
172
- }
173
170
  function C() {
171
+ return !ie();
172
+ }
173
+ function ie() {
174
174
  return typeof window < "u" && !!window?.document;
175
175
  }
176
176
  //#endregion
@@ -182,32 +182,36 @@ function w(e, t) {
182
182
  } catch {}
183
183
  return e;
184
184
  }
185
- function T(e, t) {
185
+ function oe(e, t) {
186
186
  try {
187
187
  return JSON.parse(e, t);
188
188
  } catch {
189
- throw new L({ text: e });
189
+ throw new le({ text: e });
190
190
  }
191
191
  }
192
192
  //#endregion
193
193
  //#region ../../node_modules/.pnpm/@naturalcycles+js-lib@15.93.0_undici@8.11.2/node_modules/@naturalcycles/js-lib/dist/string/string.util.js
194
- function E(e, t, n = "...") {
194
+ function T(e, t, n = "...") {
195
195
  if (!e || e.length <= t) return e;
196
196
  if (t <= n.length) return n;
197
197
  let r = Math.round((t - n.length) / 2), i = e.length - Math.floor((t - n.length) / 2);
198
198
  return e.slice(0, r) + n + e.slice(i);
199
199
  }
200
+ function E(e, t) {
201
+ let n = e.indexOf(t);
202
+ return e.slice(0, n === -1 ? void 0 : n);
203
+ }
200
204
  //#endregion
201
205
  //#region ../../node_modules/.pnpm/@naturalcycles+js-lib@15.93.0_undici@8.11.2/node_modules/@naturalcycles/js-lib/dist/error/error.util.js
202
206
  function D(e, t = Error, n) {
203
207
  let r;
204
- return r = e instanceof t ? e : oe(O(e), t), n && (r.data ||= {}, Object.assign(r.data, n)), r;
208
+ return r = e instanceof t ? e : se(O(e), t), n && (r.data ||= {}, Object.assign(r.data, n)), r;
205
209
  }
206
210
  function O(e, t) {
207
211
  let n;
208
212
  return M(e) ? n = k(e) : (e = w(e), n = A(e) ? e.error : j(e) ? e : M(e) ? k(e) : {
209
213
  name: "Error",
210
- message: W(e),
214
+ message: H(e),
211
215
  data: {}
212
216
  }), Object.assign(n.data, t), n;
213
217
  }
@@ -220,7 +224,7 @@ function k(e) {
220
224
  };
221
225
  return e.stack && (t.stack = e.stack), e.cause && (t.cause = O(e.cause)), t;
222
226
  }
223
- function oe(e, t = Error) {
227
+ function se(e, t = Error) {
224
228
  if (e instanceof t) return e;
225
229
  let { name: n, cause: r } = e, i = new t(e.message, e.data, {
226
230
  name: n,
@@ -285,7 +289,7 @@ var P = class e extends Error {
285
289
  }
286
290
  constructor(e, t = {}, n = {}) {
287
291
  super(e);
288
- let { name: r = S() ? this.constructor.name : "AppError", cause: i } = n;
292
+ let { name: r = C() ? this.constructor.name : "AppError", cause: i } = n;
289
293
  Object.defineProperties(this, {
290
294
  name: {
291
295
  value: r,
@@ -316,37 +320,37 @@ var P = class e extends Error {
316
320
  name: "HttpRequestError"
317
321
  });
318
322
  }
319
- }, I = class extends P {
323
+ }, ce = class extends P {
320
324
  constructor(e, t) {
321
325
  super(e, t, { name: "AssertionError" });
322
326
  }
323
- }, L = class extends P {
327
+ }, le = class extends P {
324
328
  constructor(e) {
325
- let t = ["Failed to parse", e.text && E(e.text, 200)].filter(Boolean).join(": ");
329
+ let t = ["Failed to parse", e.text && T(e.text, 200)].filter(Boolean).join(": ");
326
330
  super(t, e, { name: "JsonParseError" });
327
331
  }
328
- }, R = class extends P {
332
+ }, I = class extends P {
329
333
  constructor(e, t, n) {
330
334
  super(e, t, {
331
335
  ...n,
332
336
  name: "TimeoutError"
333
337
  });
334
338
  }
335
- }, z = class extends P {
339
+ }, L = class extends P {
336
340
  constructor(e) {
337
341
  super(e || "expected error was not thrown", {}, { name: "UnexpectedPassError" });
338
342
  }
339
343
  };
340
344
  //#endregion
341
345
  //#region ../../node_modules/.pnpm/@naturalcycles+js-lib@15.93.0_undici@8.11.2/node_modules/@naturalcycles/js-lib/dist/string/safeJsonStringify.js
342
- function B(e, t, n, r) {
346
+ function R(e, t, n, r) {
343
347
  try {
344
348
  return JSON.stringify(e, t, n);
345
349
  } catch {
346
- return JSON.stringify(e, V(t, r), n);
350
+ return JSON.stringify(e, z(t, r), n);
347
351
  }
348
352
  }
349
- function V(e, t) {
353
+ function z(e, t) {
350
354
  let n = [], r = [];
351
355
  return t ??= (e, t) => n[0] === t ? "[Circular ~]" : "[Circular ~." + r.slice(0, n.indexOf(t)).join(".") + "]", function(i, a) {
352
356
  if (n.length > 0) {
@@ -358,21 +362,21 @@ function V(e, t) {
358
362
  }
359
363
  //#endregion
360
364
  //#region ../../node_modules/.pnpm/@naturalcycles+js-lib@15.93.0_undici@8.11.2/node_modules/@naturalcycles/js-lib/dist/string/stringify.js
361
- var H = typeof globalThis.AggregateError == "function", U = B;
362
- function W(e, t = {}) {
365
+ var B = typeof globalThis.AggregateError == "function", V = R;
366
+ function H(e, t = {}) {
363
367
  if (e === void 0) return "undefined";
364
368
  if (e === null) return "null";
365
369
  if (typeof e == "function") return "function";
366
370
  if (typeof e == "symbol") return e.toString();
367
371
  let n;
368
- if (e = w(e), A(e)) return W(e.error, t);
369
- if (e instanceof Error || M(e)) n = G(e, t);
372
+ if (e = w(e), A(e)) return H(e.error, t);
373
+ if (e instanceof Error || M(e)) n = U(e, t);
370
374
  else if (typeof e == "string") n = e.trim() || "empty_string";
371
375
  else if (typeof e == "number") n = String(e);
372
376
  else {
373
377
  e instanceof Map ? e = Object.fromEntries(e) : e instanceof Set && (e = Array.from(e));
374
378
  try {
375
- let { stringifyFn: r = U } = t;
379
+ let { stringifyFn: r = V } = t;
376
380
  n = r(e, void 0, 2);
377
381
  } catch {
378
382
  n = String(e);
@@ -380,31 +384,31 @@ function W(e, t = {}) {
380
384
  }
381
385
  if (n === void 0) return "undefined";
382
386
  let { maxLen: r = 1e4 } = t;
383
- return r && n.length > r ? E(n, r, `\n... ${Math.ceil(n.length / 1024)} Kb message truncated ...\n`) : n;
387
+ return r && n.length > r ? T(n, r, `\n... ${Math.ceil(n.length / 1024)} Kb message truncated ...\n`) : n;
384
388
  }
385
- function G(e, t) {
389
+ function U(e, t) {
386
390
  let { includeErrorCause: n = !0 } = t, r = [e.name, e.message].filter(Boolean).join(": ");
387
- if (typeof e.code == "string" && (r += `\ncode: ${e.code}`), t.includeErrorData && j(e) && Object.keys(e.data).length && (r += "\n" + W(e.data, t)), t.includeErrorStack && e.stack) {
391
+ if (typeof e.code == "string" && (r += `\ncode: ${e.code}`), t.includeErrorData && j(e) && Object.keys(e.data).length && (r += "\n" + H(e.data, t)), t.includeErrorStack && e.stack) {
388
392
  let t = r.split("\n").length;
389
393
  r = [r, ...e.stack.split("\n").slice(t)].join("\n");
390
394
  }
391
- return H && e instanceof AggregateError && e.errors.length && (r = [
395
+ return B && e instanceof AggregateError && e.errors.length && (r = [
392
396
  r,
393
397
  `${e.errors.length} error(s):`,
394
- ...e.errors.map((e, n) => `${n + 1}. ${W(e, t)}`)
395
- ].join("\n")), e.cause && n && (r = r + "\nCaused by: " + W(e.cause, t)), r;
398
+ ...e.errors.map((e, n) => `${n + 1}. ${H(e, t)}`)
399
+ ].join("\n")), e.cause && n && (r = r + "\nCaused by: " + H(e.cause, t)), r;
396
400
  }
397
401
  //#endregion
398
402
  //#region ../../node_modules/.pnpm/@naturalcycles+js-lib@15.93.0_undici@8.11.2/node_modules/@naturalcycles/js-lib/dist/error/assert.js
399
- function K(e, t = Error) {
400
- if (!(e instanceof t)) throw new I(`Expected to be instanceof ${t.name}, actual typeof: ${typeof e}`);
403
+ function W(e, t = Error) {
404
+ if (!(e instanceof t)) throw new ce(`Expected to be instanceof ${t.name}, actual typeof: ${typeof e}`);
401
405
  }
402
- function q(e, t) {
406
+ function ue(e, t) {
403
407
  if (!(e instanceof t)) throw e;
404
408
  }
405
409
  //#endregion
406
410
  //#region ../../node_modules/.pnpm/@naturalcycles+js-lib@15.93.0_undici@8.11.2/node_modules/@naturalcycles/js-lib/dist/promise/pDelay.js
407
- async function se(e, t) {
411
+ async function de(e, t) {
408
412
  t?.aborted || await new Promise((n) => {
409
413
  let r = setTimeout(i, e);
410
414
  function i() {
@@ -415,10 +419,10 @@ async function se(e, t) {
415
419
  }
416
420
  //#endregion
417
421
  //#region ../../node_modules/.pnpm/@naturalcycles+js-lib@15.93.0_undici@8.11.2/node_modules/@naturalcycles/js-lib/dist/datetime/time.util.js
418
- function J(e, t = Date.now()) {
419
- return Y(t - e);
422
+ function G(e, t = Date.now()) {
423
+ return K(t - e);
420
424
  }
421
- function Y(e) {
425
+ function K(e) {
422
426
  if (e < 1e3) return `${Math.round(e)} ms`;
423
427
  if (e < 1e4) return `${(e / 1e3).toFixed(2)} sec`;
424
428
  let t = Math.floor(e / 1e3) % 60, n = Math.floor(e / 6e4) % 60, r = Math.floor(e / 36e5);
@@ -426,18 +430,18 @@ function Y(e) {
426
430
  }
427
431
  //#endregion
428
432
  //#region ../../node_modules/.pnpm/@naturalcycles+js-lib@15.93.0_undici@8.11.2/node_modules/@naturalcycles/js-lib/dist/number/number.util.js
429
- function ce(e, t, n) {
433
+ function fe(e, t, n) {
430
434
  return e <= t ? t : e >= n ? n : e;
431
435
  }
432
436
  //#endregion
433
437
  //#region ../../node_modules/.pnpm/@naturalcycles+js-lib@15.93.0_undici@8.11.2/node_modules/@naturalcycles/js-lib/dist/promise/pTimeout.js
434
- async function le(e, t) {
438
+ async function pe(e, t) {
435
439
  let n = new AbortController(), { signal: r } = n;
436
440
  if (!t.timeout) return await e(r);
437
441
  let { timeout: i, name: a = e.name || "pTimeout function", onTimeout: o } = t, s = t.fakeError || /* @__PURE__ */ Error("TimeoutError");
438
442
  return await new Promise(async (c, l) => {
439
443
  let u = setTimeout(() => {
440
- let e = new R(`"${a}" timed out after ${i} ms`, t.errorData);
444
+ let e = new I(`"${a}" timed out after ${i} ms`, t.errorData);
441
445
  if (e.stack = s.stack.replace("Error: TimeoutError", "TimeoutError: " + e.message), o) {
442
446
  try {
443
447
  c(o(e));
@@ -458,7 +462,7 @@ async function le(e, t) {
458
462
  }
459
463
  //#endregion
460
464
  //#region ../../node_modules/.pnpm/@naturalcycles+js-lib@15.93.0_undici@8.11.2/node_modules/@naturalcycles/js-lib/dist/string/url.util.js
461
- function ue(e, t) {
465
+ function me(e, t) {
462
466
  if (typeof e != "string") return null;
463
467
  try {
464
468
  return new URL(e, t || void 0);
@@ -468,20 +472,20 @@ function ue(e, t) {
468
472
  }
469
473
  //#endregion
470
474
  //#region ../../node_modules/.pnpm/@naturalcycles+js-lib@15.93.0_undici@8.11.2/node_modules/@naturalcycles/js-lib/dist/http/http.model.js
471
- var de = [
475
+ var he = [
472
476
  "GET",
473
477
  "POST",
474
478
  "PUT",
475
479
  "PATCH",
476
480
  "DELETE",
477
481
  "HEAD"
478
- ], fe = class e {
482
+ ], ge = class e {
479
483
  static VERSION = 5;
480
- static userAgent = S() ? `fetcher/${this.VERSION}` : void 0;
484
+ static userAgent = C() ? `fetcher/${this.VERSION}` : void 0;
481
485
  constructor(e = {}) {
482
486
  if (typeof globalThis.fetch != "function") throw TypeError("globalThis.fetch is not available");
483
487
  this.cfg = this.normalizeCfg(e);
484
- for (let e of de) {
488
+ for (let e of he) {
485
489
  let t = e.toLowerCase();
486
490
  this[`${t}Void`] = async (t, n) => await this.fetch({
487
491
  url: t,
@@ -543,7 +547,7 @@ var de = [
543
547
  headVoid;
544
548
  async queryGraphQL(e) {
545
549
  e = { ...e }, e.method ||= this.cfg.init.method;
546
- let t = re({
550
+ let t = ne({
547
551
  query: e.query,
548
552
  variables: e.variables
549
553
  });
@@ -598,12 +602,12 @@ var de = [
598
602
  }
599
603
  async expectError(e) {
600
604
  let t = await this.doFetch(e);
601
- if (!t.err) throw new z("Fetch was expected to error");
602
- return K(t.err, F), t.err;
605
+ if (!t.err) throw new L("Fetch was expected to error");
606
+ return W(t.err, F), t.err;
603
607
  }
604
608
  async tryFetch(e) {
605
609
  let t = await this.doFetch(e);
606
- return t.err ? (q(t.err, F), [t.err, null]) : [null, t.body];
610
+ return t.err ? (ue(t.err, F), [t.err, null]) : [null, t.body];
607
611
  }
608
612
  async doFetch(t) {
609
613
  let n = 0;
@@ -641,7 +645,7 @@ var de = [
641
645
  d.err = D(e), d.ok = !1, d.fetchResponse = void 0;
642
646
  }
643
647
  if (d.statusFamily = this.getStatusFamily(d), d.statusCode = d.fetchResponse?.status, d.fetchResponse?.ok) try {
644
- await le(async () => await this.onOkResponse(d), {
648
+ await pe(async () => await this.onOkResponse(d), {
645
649
  timeout: s ?? 0,
646
650
  name: "Fetcher.downloadBody"
647
651
  });
@@ -657,12 +661,12 @@ var de = [
657
661
  for (let e of this.cfg.hooks.afterResponse || []) await e(d);
658
662
  return d.err && await this.detectStaleInit(t, d, n) ? await this.doFetch({
659
663
  ...t,
660
- [X]: !0
664
+ [q]: !0
661
665
  }) : d;
662
666
  }
663
667
  async detectStaleInit(e, t, n) {
664
668
  let { shouldReinit: r, init: i } = this.cfg.hooks;
665
- return !r || !i || e[X] || !await r(t) ? !1 : (n === this.initGeneration && this.resetInit(), !0);
669
+ return !r || !i || e[q] || !await r(t) ? !1 : (n === this.initGeneration && this.resetInit(), !0);
666
670
  }
667
671
  async runInitHooks() {
668
672
  for (let e of this.cfg.hooks.init || []) await e(this.cfg);
@@ -672,7 +676,7 @@ var de = [
672
676
  if (n === "json") {
673
677
  if (e.fetchResponse.body) {
674
678
  let n = await e.fetchResponse.text();
675
- n ? (e.body = n, e.body = T(n, t.jsonReviver)) : e.body = {};
679
+ n ? (e.body = n, e.body = oe(n, t.jsonReviver)) : e.body = {};
676
680
  } else e.body = {};
677
681
  } else if (n === "text") e.body = e.fetchResponse.body ? await e.fetchResponse.text() : "";
678
682
  else if (n === "arrayBuffer") e.body = e.fetchResponse.body ? await e.fetchResponse.arrayBuffer() : /* @__PURE__ */ new ArrayBuffer(0);
@@ -687,7 +691,7 @@ var de = [
687
691
  e.fetchResponse.status,
688
692
  e.signature,
689
693
  n && `try#${n + 1}/${t.retry.count + 1}`,
690
- J(e.req.started)
694
+ G(e.req.started)
691
695
  ].filter(Boolean).join(" ")), t.logResponseBody && e.body !== void 0 && r.log({ body: e.body });
692
696
  }
693
697
  }
@@ -705,7 +709,7 @@ var de = [
705
709
  data: {}
706
710
  };
707
711
  let n = e.fetchResponse?.status || 0;
708
- e.statusFamily === 2 && (e.statusFamily = void 0, e.statusCode = void 0, n = 0), e.err = new F([e.statusCode, e.signature].filter(Boolean).join(" "), _({
712
+ e.statusFamily === 2 && (e.statusFamily = void 0, e.statusCode = void 0, n = 0), e.err = new F([e.statusCode, e.signature].filter(Boolean).join(" "), v({
709
713
  response: e.fetchResponse,
710
714
  responseStatusCode: n,
711
715
  requestUrl: e.req.fullUrl,
@@ -728,13 +732,13 @@ var de = [
728
732
  e.fetchResponse?.status || 0,
729
733
  e.signature,
730
734
  n && (t.retryAttempt || !t.retryStopped) && `try#${t.retryAttempt + 1}/${n + 1}`,
731
- J(e.req.started)
735
+ G(e.req.started)
732
736
  ].filter(Boolean).join(" "),
733
737
  err: e.err.cause || e.err
734
738
  }), t.retryStopped) return;
735
739
  t.retryAttempt++;
736
740
  let a = this.getRetryTimeout(e);
737
- a === null ? (this.cfg.logger.warn(`${e.signature} server-indicated delay exceeds maxRetryAfter, will not retry`), t.retryStopped = !0) : (t.retryTimeout = ce(t.retryTimeout * r, 0, i), e.req.debug && this.cfg.logger.log(` .. ${e.signature} waiting ${Y(a)}`), await se(a, e.req.signal), e.req.signal?.aborted && (t.retryStopped = !0));
741
+ a === null ? (this.cfg.logger.warn(`${e.signature} server-indicated delay exceeds maxRetryAfter, will not retry`), t.retryStopped = !0) : (t.retryTimeout = fe(t.retryTimeout * r, 0, i), e.req.debug && this.cfg.logger.log(` .. ${e.signature} waiting ${K(a)}`), await de(a, e.req.signal), e.req.signal?.aborted && (t.retryStopped = !0));
738
742
  }
739
743
  getRetryTimeout(e) {
740
744
  let t = 0;
@@ -780,7 +784,7 @@ var de = [
780
784
  normalizeCfg(t) {
781
785
  let { debug: n = !1, logger: r = f } = t;
782
786
  t.baseUrl?.endsWith("/") && (r.warn(`Fetcher: baseUrl should not end with slash: ${t.baseUrl}`), t.baseUrl = t.baseUrl.slice(0, t.baseUrl.length - 1));
783
- let i = x({
787
+ let i = S({
784
788
  baseUrl: "",
785
789
  name: this.getFetcherName(t),
786
790
  inputUrl: "",
@@ -797,12 +801,12 @@ var de = [
797
801
  logRequestBody: n,
798
802
  logResponse: n,
799
803
  logResponseBody: n,
800
- logWithBaseUrl: S(),
804
+ logWithBaseUrl: C(),
801
805
  logWithSearchParams: !0,
802
- retry: { ...he },
806
+ retry: { ...ye },
803
807
  init: {
804
808
  method: t.method || "GET",
805
- headers: _({
809
+ headers: v({
806
810
  "user-agent": e.userAgent,
807
811
  ...t.headers
808
812
  }),
@@ -814,7 +818,7 @@ var de = [
814
818
  hooks: {},
815
819
  throwHttpErrors: !0,
816
820
  errorData: {}
817
- }, g(t, [
821
+ }, _(t, [
818
822
  "method",
819
823
  "credentials",
820
824
  "headers",
@@ -823,19 +827,19 @@ var de = [
823
827
  "name",
824
828
  "keepalive"
825
829
  ]));
826
- return i.init.headers = b(i.init.headers, (e) => e.toLowerCase()), i;
830
+ return i.init.headers = x(i.init.headers, (e) => e.toLowerCase()), i;
827
831
  }
828
832
  getFetcherName(e) {
829
833
  let { name: t } = e;
830
834
  if (!t && e.baseUrl) {
831
- let n = ue(e.baseUrl);
835
+ let n = me(e.baseUrl);
832
836
  n && (t = n.hostname);
833
837
  }
834
838
  return t;
835
839
  }
836
840
  normalizeOptions(t) {
837
841
  let n = {
838
- ...ne(this.cfg, [
842
+ ...g(this.cfg, [
839
843
  "timeoutSeconds",
840
844
  "retryPost",
841
845
  "retry3xx",
@@ -854,7 +858,7 @@ var de = [
854
858
  "overrideFetchFn"
855
859
  ]),
856
860
  started: Date.now(),
857
- ...g(t, [
861
+ ..._(t, [
858
862
  "method",
859
863
  "headers",
860
864
  "credentials"
@@ -863,9 +867,9 @@ var de = [
863
867
  fullUrl: t.url || "",
864
868
  retry: {
865
869
  ...this.cfg.retry,
866
- ...v(t.retry || {})
870
+ ...y(t.retry || {})
867
871
  },
868
- init: x({
872
+ init: S({
869
873
  ...this.cfg.init,
870
874
  headers: {
871
875
  ...this.cfg.init.headers,
@@ -875,15 +879,15 @@ var de = [
875
879
  credentials: t.credentials || this.cfg.init.credentials,
876
880
  redirect: t.redirect || this.cfg.init.redirect || "follow",
877
881
  keepalive: t.keepalive ?? this.cfg.init.keepalive
878
- }, { headers: b(t.headers || {}, (e) => e.toLowerCase()) })
882
+ }, { headers: x(t.headers || {}, (e) => e.toLowerCase()) })
879
883
  };
880
- _(n.init.headers, { mutate: !0 });
884
+ v(n.init.headers, { mutate: !0 });
881
885
  let r = t.baseUrl || this.cfg.baseUrl;
882
886
  if (r) {
883
887
  let { inputUrl: e } = n;
884
888
  e.startsWith("/") && (this.cfg.logger.warn("Fetcher: url should not start with / when baseUrl is specified"), e = e.slice(1)), n.fullUrl = `${r}/${e}`;
885
889
  }
886
- let i = v({
890
+ let i = y({
887
891
  ...this.cfg.searchParams,
888
892
  ...t.searchParams
889
893
  });
@@ -891,13 +895,13 @@ var de = [
891
895
  let e = new URLSearchParams(i).toString();
892
896
  n.fullUrl += (n.fullUrl.includes("?") ? "&" : "?") + e;
893
897
  }
894
- return t.json === void 0 ? t.text === void 0 ? t.form ? t.form instanceof URLSearchParams || t.form instanceof FormData ? n.init.body = t.form : (n.init.body = new URLSearchParams(t.form), n.init.headers["content-type"] ||= "application/x-www-form-urlencoded") : t.body !== void 0 && (n.init.body = t.body) : (n.init.body = t.text, n.init.headers["content-type"] ||= "text/plain") : (n.init.body = JSON.stringify(t.json), n.init.headers["content-type"] ||= "application/json"), n.init.headers.accept ||= me[n.responseType], n;
898
+ return t.json === void 0 ? t.text === void 0 ? t.form ? t.form instanceof URLSearchParams || t.form instanceof FormData ? n.init.body = t.form : (n.init.body = new URLSearchParams(t.form), n.init.headers["content-type"] ||= "application/x-www-form-urlencoded") : t.body !== void 0 && (n.init.body = t.body) : (n.init.body = t.text, n.init.headers["content-type"] ||= "text/plain") : (n.init.body = JSON.stringify(t.json), n.init.headers["content-type"] ||= "application/json"), n.init.headers.accept ||= ve[n.responseType], n;
895
899
  }
896
900
  };
897
- function pe(e = {}) {
898
- return fe.create(e);
901
+ function _e(e = {}) {
902
+ return ge.create(e);
899
903
  }
900
- var X = Symbol("reinitAttempted"), me = {
904
+ var q = Symbol("reinitAttempted"), ve = {
901
905
  text: "text/plain",
902
906
  json: "application/json",
903
907
  void: "*/*",
@@ -905,56 +909,87 @@ var X = Symbol("reinitAttempted"), me = {
905
909
  arrayBuffer: "application/octet-stream",
906
910
  bytes: "application/octet-stream",
907
911
  blob: "application/octet-stream"
908
- }, he = {
912
+ }, ye = {
909
913
  count: 2,
910
914
  timeout: 1e3,
911
915
  timeoutMax: 3e4,
912
916
  timeoutMultiplier: 2,
913
917
  maxRetryAfter: 6e5
914
- }, ge = {
918
+ }, be = {
915
919
  "https://www.naturalcycles.com/": [
916
- "shop",
917
- "research-library",
918
- "plan-pregnancy",
919
- "postpartum",
920
- "cyclematters/period-calculator",
921
- "cyclematters/search",
922
- "cyclematters/perimenopause-quiz"
920
+ {
921
+ pathIncludes: "shop",
922
+ conversionScrubber: (e) => J(e, "/shop")
923
+ },
924
+ {
925
+ pathIncludes: "research-library",
926
+ conversionScrubber: (e) => J(e, "/research-library")
927
+ },
928
+ { pathIncludes: "plan-pregnancy" },
929
+ { pathIncludes: "postpartum" },
930
+ {
931
+ pathIncludes: "cyclematters/period-calculator",
932
+ conversionScrubber: (e) => E(e, "/period-calculator")
933
+ },
934
+ {
935
+ pathIncludes: "cyclematters/search",
936
+ conversionScrubber: (e) => J(e, "/cyclematters/search")
937
+ },
938
+ {
939
+ pathIncludes: "cyclematters/perimenopause-quiz",
940
+ conversionScrubber: (e) => E(e, "/perimenopause-quiz")
941
+ }
923
942
  ],
924
943
  "https://www.naturalcycles.me/": [],
925
- "https://signup.naturalcycles.com/": ["account", "onboarding"],
944
+ "https://signup.naturalcycles.com/": [{ pathIncludes: "account" }, {
945
+ pathIncludes: "onboarding",
946
+ conversionScrubber: (e) => J(e, "/onboarding")
947
+ }],
926
948
  "https://se.naturalcycles.com/": [],
927
949
  "https://br.naturalcycles.com/": [],
928
950
  "https://uk.naturalcycles.com/": []
929
- }, _e = {
951
+ };
952
+ function J(e, t) {
953
+ let n = e.indexOf(t);
954
+ return n === -1 ? null : e.slice(0, n + t.length);
955
+ }
956
+ var xe = {
930
957
  "http://localhost:8000": "https://www.naturalcycles.com/",
931
958
  "http://localhost:8001": "https://www.naturalcycles.me/",
932
959
  "http://localhost:4200": "https://signup.naturalcycles.com/"
933
- }, ve = [
960
+ }, Se = [
934
961
  "https://www.naturalcycles.com/",
935
962
  "https://www.naturalcycles.me/",
936
963
  "https://signup.naturalcycles.com/",
937
964
  "https://se.naturalcycles.com/",
938
965
  "https://br.naturalcycles.com/",
939
966
  "https://uk.naturalcycles.com/"
940
- ], Z;
967
+ ], Y;
941
968
  (function(e) {
942
969
  e.flow = "flow", e.code = "code", e.refId = "refId", e.referral = "referral", e.ignoreConfirmation = "ignoreConfirmation", e.ic = "ic", e.measuringDevice = "measuringDevice", e.irclickid = "irclickid", e.fg = "fg", e.sfg = "sfg", e.sq = "sq", e.cbo = "cbo", e.ip = "ip", e.ipv = "ipv", e.appleAuth = "appleAuth", e.googleAuth = "googleAuth", e.od = "od", e.pl = "pl", e.ScCid = "ScCid", e.fbclid = "fbclid", e.ttclid = "ttclid", e.rdt_cid = "rdt_cid", e.epik = "epik", e.adid = "adid", e.wcf = "wcf", e.we = "we", e.werr = "werr", e.wdpm = "wdpm", e.wsc = "wsc", e.ral = "ral";
943
- })(Z ||= {});
944
- var ye = [
945
- Z.ScCid,
946
- Z.irclickid,
947
- Z.fbclid,
948
- Z.ttclid,
949
- Z.rdt_cid,
950
- Z.epik
970
+ })(Y ||= {});
971
+ var Ce = [
972
+ Y.ScCid,
973
+ Y.irclickid,
974
+ Y.fbclid,
975
+ Y.ttclid,
976
+ Y.rdt_cid,
977
+ Y.epik
951
978
  ];
952
- Z.flow, Z.code, Z.ignoreConfirmation, Z.ic, Z.fg, Z.sfg, Z.sq, Z.cbo, Z.ip, Z.ipv, Z.od, Z.pl, Z.wcf, Z.we, Z.wdpm, Z.wsc, Z.ral;
953
- var be;
979
+ Y.flow, Y.code, Y.ignoreConfirmation, Y.ic, Y.fg, Y.sfg, Y.sq, Y.cbo, Y.ip, Y.ipv, Y.od, Y.pl, Y.wcf, Y.we, Y.wdpm, Y.wsc, Y.ral;
980
+ var X;
954
981
  (function(e) {
955
982
  e[e.OURA = 1] = "OURA", e[e.APPLE_WATCH = 2] = "APPLE_WATCH", e[e.META_LANDING_PAGE = 3] = "META_LANDING_PAGE", e[e.PAYMENT_REDIRECT_FROM_APP = 4] = "PAYMENT_REDIRECT_FROM_APP", e[e.B1 = 5] = "B1", e[e.EMAIL_VERIFICATION_REDIRECT = 6] = "EMAIL_VERIFICATION_REDIRECT", e[e.WHOOP = 7] = "WHOOP";
956
- })(be ||= {});
957
- var Q = new class {
983
+ })(X ||= {});
984
+ var Z = new class {
985
+ scrubPathname(e, t) {
986
+ let n = Se.find((t) => t === `${e}/`) || xe[e];
987
+ if (!n) return null;
988
+ let r = t;
989
+ for (let e of be[n]) if (r.includes(e.pathIncludes) && (r = e.conversionScrubber?.(r) ?? null, r === null)) return null;
990
+ return r;
991
+ }
992
+ }(), Q = new class {
958
993
  getAllCookies() {
959
994
  let e = {}, t = document.cookie.split("; ");
960
995
  for (let n of t) {
@@ -992,7 +1027,7 @@ var Q = new class {
992
1027
  function $(e) {
993
1028
  if (e) return e.startsWith("fb.") ? e : `fb.1.${Date.now()}.${e}`;
994
1029
  }
995
- function xe(e) {
1030
+ function we(e) {
996
1031
  if (!e) return;
997
1032
  e = e.split("?")[0], e.includes("__DOT__") && (e = e.replaceAll("__DOT__", ".")), e = e.split("%")[0], e = e.split("&")[0];
998
1033
  let t = e.split("."), n = t.lastIndexOf("fb");
@@ -1000,13 +1035,13 @@ function xe(e) {
1000
1035
  }
1001
1036
  //#endregion
1002
1037
  //#region src/conversion/conversionClient.ts
1003
- var Se = 30, Ce = 200, we = 20, Te = class {
1038
+ var Te = 30, Ee = 200, De = 20, Oe = class {
1004
1039
  constructor(e) {
1005
1040
  this.cfg = {
1006
1041
  ...e,
1007
1042
  enabled: e.enabled ?? !0,
1008
1043
  onError: e.onError ?? te
1009
- }, this.fetcher = pe({ baseUrl: e.url });
1044
+ }, this.fetcher = _e({ baseUrl: e.url });
1010
1045
  }
1011
1046
  cfg;
1012
1047
  fetcher;
@@ -1017,7 +1052,7 @@ var Se = 30, Ce = 200, we = 20, Te = class {
1017
1052
  }
1018
1053
  pageView(e, t = {}) {
1019
1054
  if (!this.cfg.enabled || !this.hasMarketingConsent(e)) return;
1020
- let n = this.getAllowedPathname(e.pathname);
1055
+ let n = Z.scrubPathname(globalThis.location.origin, e.pathname);
1021
1056
  n !== null && m(this.send("p", {
1022
1057
  ...e,
1023
1058
  pathname: n
@@ -1025,7 +1060,7 @@ var Se = 30, Ce = 200, we = 20, Te = class {
1025
1060
  }
1026
1061
  purchase(e, t = {}) {
1027
1062
  if (!this.cfg.enabled || !this.hasMarketingConsent(e)) return;
1028
- let n = this.getAllowedPathname(e.pathname);
1063
+ let n = Z.scrubPathname(globalThis.location.origin, e.pathname);
1029
1064
  n !== null && m(this.send("purchase", {
1030
1065
  ...e,
1031
1066
  pathname: n
@@ -1034,10 +1069,6 @@ var Se = 30, Ce = 200, we = 20, Te = class {
1034
1069
  hasMarketingConsent(e) {
1035
1070
  return (e.marketingConsent ?? e.marketingCookie) === !0;
1036
1071
  }
1037
- getAllowedPathname(e) {
1038
- let { href: t, origin: n } = globalThis.location, r = ve.find((e) => t.startsWith(e)) || _e[n];
1039
- return r ? ge[r].some((t) => e.includes(t)) ? null : e : null;
1040
- }
1041
1072
  async send(e, t, n) {
1042
1073
  try {
1043
1074
  let r = await this.fetcher.doFetch({
@@ -1058,20 +1089,20 @@ var Se = 30, Ce = 200, we = 20, Te = class {
1058
1089
  }
1059
1090
  getHeaders(e) {
1060
1091
  let t = String(this.cfg.clientId);
1061
- return e.marketingConsent ? this.tryOrReport(() => (this.cfg.enabled && this.storeClickIds(), ie({
1092
+ return e.marketingConsent ? this.tryOrReport(() => (this.cfg.enabled && this.storeClickIds(), re({
1062
1093
  clientId: t,
1063
- fbc: Q.getCookie("_fbc") || $(Q.getCookie(Z.fbclid)),
1094
+ fbc: Q.getCookie("_fbc") || $(Q.getCookie(Y.fbclid)),
1064
1095
  fbp: Q.getCookie("_fbp"),
1065
- scCid: Q.getCookie(Z.ScCid),
1066
- ttclid: Q.getCookie(Z.ttclid),
1067
- rdtCid: Q.getCookie(Z.rdt_cid),
1068
- epik: Q.getCookie("_epik") || Q.getCookie(Z.epik),
1096
+ scCid: Q.getCookie(Y.ScCid),
1097
+ ttclid: Q.getCookie(Y.ttclid),
1098
+ rdtCid: Q.getCookie(Y.rdt_cid),
1099
+ epik: Q.getCookie("_epik") || Q.getCookie(Y.epik),
1069
1100
  uuid_c1: Q.getCookie("_scid") || Q.getCookie("uuid_c1")
1070
1101
  })), { clientId: t }) : { clientId: t };
1071
1102
  }
1072
1103
  storeClickIds() {
1073
1104
  this.captureClickIds();
1074
- for (let [e, t] of Object.entries(this.pendingClickIds)) Q.setCookie(e, t, Se, this.cfg.cookieDomain);
1105
+ for (let [e, t] of Object.entries(this.pendingClickIds)) Q.setCookie(e, t, Te, this.cfg.cookieDomain);
1075
1106
  this.pendingClickIds = {};
1076
1107
  }
1077
1108
  tryOrReport(e, t) {
@@ -1086,19 +1117,19 @@ var Se = 30, Ce = 200, we = 20, Te = class {
1086
1117
  if (e === this.lastCapturedHref) return;
1087
1118
  this.lastCapturedHref = e;
1088
1119
  let n = new URLSearchParams(t);
1089
- for (let e of ye) {
1120
+ for (let e of Ce) {
1090
1121
  let t = n.get(e) || n.get(e.toLowerCase());
1091
1122
  if (!t) continue;
1092
- let r = e === Z.fbclid ? this.toFbc(t) : t.slice(0, Ce);
1123
+ let r = e === Y.fbclid ? this.toFbc(t) : t.slice(0, Ee);
1093
1124
  r && (this.pendingClickIds[e] = r);
1094
1125
  }
1095
1126
  }
1096
1127
  toFbc(e) {
1097
- let t = xe(e);
1098
- if (!(!t || t.length < we) && !(this.pendingClickIds[Z.fbclid] || Q.getCookie(Z.fbclid))?.endsWith(`.${t}`)) return $(t);
1128
+ let t = we(e);
1129
+ if (!(!t || t.length < De) && !(this.pendingClickIds[Y.fbclid] || Q.getCookie(Y.fbclid))?.endsWith(`.${t}`)) return $(t);
1099
1130
  }
1100
1131
  };
1101
1132
  //#endregion
1102
- export { Te as ConversionClient, t as generateConversionEventId };
1133
+ export { Oe as ConversionClient, t as generateConversionEventId };
1103
1134
 
1104
1135
  //# sourceMappingURL=conversionClient.js.map