@uniformdev/next-app-router 20.49.2 → 20.49.3-alpha.47

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.
@@ -7,6 +7,7 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __typeError = (msg) => {
8
8
  throw TypeError(msg);
9
9
  };
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
11
  var __commonJS = (cb, mod) => function __require() {
11
12
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12
13
  };
@@ -26,16 +27,25 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
27
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
28
  mod
28
29
  ));
30
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
29
31
  var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
30
32
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
31
33
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
32
34
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
35
+ var __privateWrapper = (obj, member, setter, getter) => ({
36
+ set _(value) {
37
+ __privateSet(obj, member, value, setter);
38
+ },
39
+ get _() {
40
+ return __privateGet(obj, member, getter);
41
+ }
42
+ });
33
43
 
34
44
  // ../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js
35
45
  var require_yocto_queue = __commonJS({
36
46
  "../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js"(exports, module) {
37
47
  "use strict";
38
- var Node = class {
48
+ var Node2 = class {
39
49
  /// value;
40
50
  /// next;
41
51
  constructor(value) {
@@ -43,7 +53,7 @@ var require_yocto_queue = __commonJS({
43
53
  this.next = void 0;
44
54
  }
45
55
  };
46
- var Queue = class {
56
+ var Queue2 = class {
47
57
  // TODO: Use private class fields when targeting Node.js 12.
48
58
  // #_head;
49
59
  // #_tail;
@@ -52,7 +62,7 @@ var require_yocto_queue = __commonJS({
52
62
  this.clear();
53
63
  }
54
64
  enqueue(value) {
55
- const node = new Node(value);
65
+ const node = new Node2(value);
56
66
  if (this._head) {
57
67
  this._tail.next = node;
58
68
  this._tail = node;
@@ -87,7 +97,7 @@ var require_yocto_queue = __commonJS({
87
97
  }
88
98
  }
89
99
  };
90
- module.exports = Queue;
100
+ module.exports = Queue2;
91
101
  }
92
102
  });
93
103
 
@@ -95,12 +105,12 @@ var require_yocto_queue = __commonJS({
95
105
  var require_p_limit = __commonJS({
96
106
  "../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js"(exports, module) {
97
107
  "use strict";
98
- var Queue = require_yocto_queue();
99
- var pLimit2 = (concurrency) => {
108
+ var Queue2 = require_yocto_queue();
109
+ var pLimit3 = (concurrency) => {
100
110
  if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
101
111
  throw new TypeError("Expected `concurrency` to be a number from 1 and up");
102
112
  }
103
- const queue = new Queue();
113
+ const queue = new Queue2();
104
114
  let activeCount = 0;
105
115
  const next = () => {
106
116
  activeCount--;
@@ -145,7 +155,238 @@ var require_p_limit = __commonJS({
145
155
  });
146
156
  return generator;
147
157
  };
148
- module.exports = pLimit2;
158
+ module.exports = pLimit3;
159
+ }
160
+ });
161
+
162
+ // ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js
163
+ var require_retry_operation = __commonJS({
164
+ "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js"(exports, module) {
165
+ "use strict";
166
+ function RetryOperation(timeouts, options) {
167
+ if (typeof options === "boolean") {
168
+ options = { forever: options };
169
+ }
170
+ this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
171
+ this._timeouts = timeouts;
172
+ this._options = options || {};
173
+ this._maxRetryTime = options && options.maxRetryTime || Infinity;
174
+ this._fn = null;
175
+ this._errors = [];
176
+ this._attempts = 1;
177
+ this._operationTimeout = null;
178
+ this._operationTimeoutCb = null;
179
+ this._timeout = null;
180
+ this._operationStart = null;
181
+ this._timer = null;
182
+ if (this._options.forever) {
183
+ this._cachedTimeouts = this._timeouts.slice(0);
184
+ }
185
+ }
186
+ module.exports = RetryOperation;
187
+ RetryOperation.prototype.reset = function() {
188
+ this._attempts = 1;
189
+ this._timeouts = this._originalTimeouts.slice(0);
190
+ };
191
+ RetryOperation.prototype.stop = function() {
192
+ if (this._timeout) {
193
+ clearTimeout(this._timeout);
194
+ }
195
+ if (this._timer) {
196
+ clearTimeout(this._timer);
197
+ }
198
+ this._timeouts = [];
199
+ this._cachedTimeouts = null;
200
+ };
201
+ RetryOperation.prototype.retry = function(err) {
202
+ if (this._timeout) {
203
+ clearTimeout(this._timeout);
204
+ }
205
+ if (!err) {
206
+ return false;
207
+ }
208
+ var currentTime = (/* @__PURE__ */ new Date()).getTime();
209
+ if (err && currentTime - this._operationStart >= this._maxRetryTime) {
210
+ this._errors.push(err);
211
+ this._errors.unshift(new Error("RetryOperation timeout occurred"));
212
+ return false;
213
+ }
214
+ this._errors.push(err);
215
+ var timeout = this._timeouts.shift();
216
+ if (timeout === void 0) {
217
+ if (this._cachedTimeouts) {
218
+ this._errors.splice(0, this._errors.length - 1);
219
+ timeout = this._cachedTimeouts.slice(-1);
220
+ } else {
221
+ return false;
222
+ }
223
+ }
224
+ var self = this;
225
+ this._timer = setTimeout(function() {
226
+ self._attempts++;
227
+ if (self._operationTimeoutCb) {
228
+ self._timeout = setTimeout(function() {
229
+ self._operationTimeoutCb(self._attempts);
230
+ }, self._operationTimeout);
231
+ if (self._options.unref) {
232
+ self._timeout.unref();
233
+ }
234
+ }
235
+ self._fn(self._attempts);
236
+ }, timeout);
237
+ if (this._options.unref) {
238
+ this._timer.unref();
239
+ }
240
+ return true;
241
+ };
242
+ RetryOperation.prototype.attempt = function(fn, timeoutOps) {
243
+ this._fn = fn;
244
+ if (timeoutOps) {
245
+ if (timeoutOps.timeout) {
246
+ this._operationTimeout = timeoutOps.timeout;
247
+ }
248
+ if (timeoutOps.cb) {
249
+ this._operationTimeoutCb = timeoutOps.cb;
250
+ }
251
+ }
252
+ var self = this;
253
+ if (this._operationTimeoutCb) {
254
+ this._timeout = setTimeout(function() {
255
+ self._operationTimeoutCb();
256
+ }, self._operationTimeout);
257
+ }
258
+ this._operationStart = (/* @__PURE__ */ new Date()).getTime();
259
+ this._fn(this._attempts);
260
+ };
261
+ RetryOperation.prototype.try = function(fn) {
262
+ console.log("Using RetryOperation.try() is deprecated");
263
+ this.attempt(fn);
264
+ };
265
+ RetryOperation.prototype.start = function(fn) {
266
+ console.log("Using RetryOperation.start() is deprecated");
267
+ this.attempt(fn);
268
+ };
269
+ RetryOperation.prototype.start = RetryOperation.prototype.try;
270
+ RetryOperation.prototype.errors = function() {
271
+ return this._errors;
272
+ };
273
+ RetryOperation.prototype.attempts = function() {
274
+ return this._attempts;
275
+ };
276
+ RetryOperation.prototype.mainError = function() {
277
+ if (this._errors.length === 0) {
278
+ return null;
279
+ }
280
+ var counts = {};
281
+ var mainError = null;
282
+ var mainErrorCount = 0;
283
+ for (var i = 0; i < this._errors.length; i++) {
284
+ var error = this._errors[i];
285
+ var message = error.message;
286
+ var count = (counts[message] || 0) + 1;
287
+ counts[message] = count;
288
+ if (count >= mainErrorCount) {
289
+ mainError = error;
290
+ mainErrorCount = count;
291
+ }
292
+ }
293
+ return mainError;
294
+ };
295
+ }
296
+ });
297
+
298
+ // ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js
299
+ var require_retry = __commonJS({
300
+ "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js"(exports) {
301
+ "use strict";
302
+ var RetryOperation = require_retry_operation();
303
+ exports.operation = function(options) {
304
+ var timeouts = exports.timeouts(options);
305
+ return new RetryOperation(timeouts, {
306
+ forever: options && (options.forever || options.retries === Infinity),
307
+ unref: options && options.unref,
308
+ maxRetryTime: options && options.maxRetryTime
309
+ });
310
+ };
311
+ exports.timeouts = function(options) {
312
+ if (options instanceof Array) {
313
+ return [].concat(options);
314
+ }
315
+ var opts = {
316
+ retries: 10,
317
+ factor: 2,
318
+ minTimeout: 1 * 1e3,
319
+ maxTimeout: Infinity,
320
+ randomize: false
321
+ };
322
+ for (var key in options) {
323
+ opts[key] = options[key];
324
+ }
325
+ if (opts.minTimeout > opts.maxTimeout) {
326
+ throw new Error("minTimeout is greater than maxTimeout");
327
+ }
328
+ var timeouts = [];
329
+ for (var i = 0; i < opts.retries; i++) {
330
+ timeouts.push(this.createTimeout(i, opts));
331
+ }
332
+ if (options && options.forever && !timeouts.length) {
333
+ timeouts.push(this.createTimeout(i, opts));
334
+ }
335
+ timeouts.sort(function(a, b) {
336
+ return a - b;
337
+ });
338
+ return timeouts;
339
+ };
340
+ exports.createTimeout = function(attempt, opts) {
341
+ var random = opts.randomize ? Math.random() + 1 : 1;
342
+ var timeout = Math.round(random * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt));
343
+ timeout = Math.min(timeout, opts.maxTimeout);
344
+ return timeout;
345
+ };
346
+ exports.wrap = function(obj, options, methods) {
347
+ if (options instanceof Array) {
348
+ methods = options;
349
+ options = null;
350
+ }
351
+ if (!methods) {
352
+ methods = [];
353
+ for (var key in obj) {
354
+ if (typeof obj[key] === "function") {
355
+ methods.push(key);
356
+ }
357
+ }
358
+ }
359
+ for (var i = 0; i < methods.length; i++) {
360
+ var method = methods[i];
361
+ var original = obj[method];
362
+ obj[method] = function retryWrapper(original2) {
363
+ var op = exports.operation(options);
364
+ var args = Array.prototype.slice.call(arguments, 1);
365
+ var callback = args.pop();
366
+ args.push(function(err) {
367
+ if (op.retry(err)) {
368
+ return;
369
+ }
370
+ if (err) {
371
+ arguments[0] = op.mainError();
372
+ }
373
+ callback.apply(this, arguments);
374
+ });
375
+ op.attempt(function() {
376
+ original2.apply(obj, args);
377
+ });
378
+ }.bind(obj, original);
379
+ obj[method].options = options;
380
+ }
381
+ };
382
+ }
383
+ });
384
+
385
+ // ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js
386
+ var require_retry2 = __commonJS({
387
+ "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js"(exports, module) {
388
+ "use strict";
389
+ module.exports = require_retry();
149
390
  }
150
391
  });
151
392
 
@@ -344,30 +585,37 @@ var __defProp2 = Object.defineProperty;
344
585
  var __typeError2 = (msg) => {
345
586
  throw TypeError(msg);
346
587
  };
347
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
348
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
588
+ var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
589
+ var __publicField2 = (obj, key, value) => __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
349
590
  var __accessCheck2 = (obj, member, msg) => member.has(obj) || __typeError2("Cannot " + msg);
350
591
  var __privateGet2 = (obj, member, getter) => (__accessCheck2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
351
592
  var __privateAdd2 = (obj, member, value) => member.has(obj) ? __typeError2("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
352
593
  var defaultLimitPolicy = (0, import_p_limit.default)(6);
594
+ var UNIFORM_BEARER_TOKEN_NOT_VALID_OR_EXPIRED_MESSAGE = "Bearer token not valid or expired";
353
595
  var ApiClientError = class _ApiClientError extends Error {
354
596
  constructor(errorMessage, fetchMethod, fetchUri, statusCode, statusText, requestId) {
355
597
  super(
356
598
  `${errorMessage}
357
599
  ${statusCode}${statusText ? " " + statusText : ""} (${fetchMethod} ${fetchUri}${requestId ? ` Request ID: ${requestId}` : ""})`
358
600
  );
359
- this.errorMessage = errorMessage;
360
- this.fetchMethod = fetchMethod;
361
- this.fetchUri = fetchUri;
362
- this.statusCode = statusCode;
363
- this.statusText = statusText;
364
- this.requestId = requestId;
601
+ __publicField2(this, "errorMessage", errorMessage);
602
+ __publicField2(this, "fetchMethod", fetchMethod);
603
+ __publicField2(this, "fetchUri", fetchUri);
604
+ __publicField2(this, "statusCode", statusCode);
605
+ __publicField2(this, "statusText", statusText);
606
+ __publicField2(this, "requestId", requestId);
365
607
  Object.setPrototypeOf(this, _ApiClientError.prototype);
366
608
  }
367
609
  };
610
+ var BearerTokenNotValidOrExpiredError = class _BearerTokenNotValidOrExpiredError extends ApiClientError {
611
+ constructor(errorMessage, fetchMethod, fetchUri, statusCode, statusText, requestId) {
612
+ super(errorMessage, fetchMethod, fetchUri, statusCode, statusText, requestId);
613
+ Object.setPrototypeOf(this, _BearerTokenNotValidOrExpiredError.prototype);
614
+ }
615
+ };
368
616
  var ApiClient = class _ApiClient {
369
617
  constructor(options) {
370
- __publicField(this, "options");
618
+ __publicField2(this, "options");
371
619
  var _a, _b, _c, _d, _e;
372
620
  if (!options.apiKey && !options.bearerToken) {
373
621
  throw new Error("You must provide an API key or a bearer token");
@@ -398,7 +646,7 @@ var ApiClient = class _ApiClient {
398
646
  }
399
647
  async apiClientWithResponse(fetchUri, options) {
400
648
  return this.options.limitPolicy(async () => {
401
- var _a;
649
+ var _a, _b;
402
650
  const coreHeaders = this.options.apiKey ? {
403
651
  "x-api-key": this.options.apiKey
404
652
  } : {
@@ -434,9 +682,19 @@ var ApiClient = class _ApiClient {
434
682
  } catch (e) {
435
683
  message = `General error`;
436
684
  }
685
+ if (apiResponse.status === 401 && message === UNIFORM_BEARER_TOKEN_NOT_VALID_OR_EXPIRED_MESSAGE) {
686
+ throw new BearerTokenNotValidOrExpiredError(
687
+ message,
688
+ (_a = options == null ? void 0 : options.method) != null ? _a : "GET",
689
+ fetchUri.toString(),
690
+ apiResponse.status,
691
+ apiResponse.statusText,
692
+ _ApiClient.getRequestId(apiResponse)
693
+ );
694
+ }
437
695
  throw new ApiClientError(
438
696
  message,
439
- (_a = options == null ? void 0 : options.method) != null ? _a : "GET",
697
+ (_b = options == null ? void 0 : options.method) != null ? _b : "GET",
440
698
  fetchUri.toString(),
441
699
  apiResponse.status,
442
700
  apiResponse.statusText,
@@ -510,11 +768,25 @@ async function handleRateLimits(callApi) {
510
768
  }
511
769
  const base = Math.pow(2, backoffRetries - backoffRetriesLeft) * 333;
512
770
  const backoffWait = base + Math.round(Math.random() * (base / 2)) * (Math.random() > 0.5 ? 1 : -1);
513
- await new Promise((resolve) => setTimeout(resolve, resetWait + backoffWait));
771
+ await new Promise((resolve) => setTimeout(resolve, Math.max(0, resetWait + backoffWait)));
514
772
  backoffRetriesLeft -= 1;
515
773
  }
516
774
  return response;
517
775
  }
776
+ var isPlainObject = (obj) => typeof obj === "object" && obj !== null && !Array.isArray(obj);
777
+ function rewriteFiltersForApi(filters) {
778
+ return Object.entries(filters != null ? filters : {}).reduce(
779
+ (acc, [key, value]) => {
780
+ const lhs = `filters.${key}` + (isPlainObject(value) ? `[${Object.keys(value)[0]}]` : "");
781
+ const rhs = isPlainObject(value) ? Object.values(value)[0] : value;
782
+ return {
783
+ ...acc,
784
+ [lhs]: Array.isArray(rhs) ? rhs.map((v) => `${v}`.trim()).join(",") : `${rhs}`.trim()
785
+ };
786
+ },
787
+ {}
788
+ );
789
+ }
518
790
  var _url;
519
791
  var _AggregateClient = class _AggregateClient2 extends ApiClient {
520
792
  constructor(options) {
@@ -728,398 +1000,199 @@ var _TestClient = class _TestClient2 extends ApiClient {
728
1000
  await this.apiClient(fetchUri, {
729
1001
  method: "DELETE",
730
1002
  body: JSON.stringify({ ...body, projectId: this.options.projectId }),
731
- expectNoContent: true
732
- });
733
- }
734
- };
735
- _url7 = /* @__PURE__ */ new WeakMap();
736
- __privateAdd2(_TestClient, _url7, "/api/v2/test");
737
-
738
- // ../canvas/dist/index.mjs
739
- var __create2 = Object.create;
740
- var __defProp3 = Object.defineProperty;
741
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
742
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
743
- var __getProtoOf2 = Object.getPrototypeOf;
744
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
745
- var __typeError3 = (msg) => {
746
- throw TypeError(msg);
747
- };
748
- var __commonJS2 = (cb, mod) => function __require() {
749
- return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
750
- };
751
- var __copyProps2 = (to, from, except, desc) => {
752
- if (from && typeof from === "object" || typeof from === "function") {
753
- for (let key of __getOwnPropNames2(from))
754
- if (!__hasOwnProp2.call(to, key) && key !== except)
755
- __defProp3(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
756
- }
757
- return to;
758
- };
759
- var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
760
- // If the importer is in node compatibility mode or this is not an ESM
761
- // file that has been converted to a CommonJS file using a Babel-
762
- // compatible transform (i.e. "__esModule" has not been set), then set
763
- // "default" to the CommonJS "module.exports" for node compatibility.
764
- isNodeMode || !mod || !mod.__esModule ? __defProp3(target, "default", { value: mod, enumerable: true }) : target,
765
- mod
766
- ));
767
- var __accessCheck3 = (obj, member, msg) => member.has(obj) || __typeError3("Cannot " + msg);
768
- var __privateGet3 = (obj, member, getter) => (__accessCheck3(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
769
- var __privateAdd3 = (obj, member, value) => member.has(obj) ? __typeError3("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
770
- var require_yocto_queue2 = __commonJS2({
771
- "../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js"(exports, module) {
772
- "use strict";
773
- var Node = class {
774
- /// value;
775
- /// next;
776
- constructor(value) {
777
- this.value = value;
778
- this.next = void 0;
779
- }
780
- };
781
- var Queue = class {
782
- // TODO: Use private class fields when targeting Node.js 12.
783
- // #_head;
784
- // #_tail;
785
- // #_size;
786
- constructor() {
787
- this.clear();
788
- }
789
- enqueue(value) {
790
- const node = new Node(value);
791
- if (this._head) {
792
- this._tail.next = node;
793
- this._tail = node;
794
- } else {
795
- this._head = node;
796
- this._tail = node;
797
- }
798
- this._size++;
799
- }
800
- dequeue() {
801
- const current = this._head;
802
- if (!current) {
803
- return;
804
- }
805
- this._head = this._head.next;
806
- this._size--;
807
- return current.value;
808
- }
809
- clear() {
810
- this._head = void 0;
811
- this._tail = void 0;
812
- this._size = 0;
813
- }
814
- get size() {
815
- return this._size;
816
- }
817
- *[Symbol.iterator]() {
818
- let current = this._head;
819
- while (current) {
820
- yield current.value;
821
- current = current.next;
822
- }
823
- }
824
- };
825
- module.exports = Queue;
826
- }
827
- });
828
- var require_p_limit2 = __commonJS2({
829
- "../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js"(exports, module) {
830
- "use strict";
831
- var Queue = require_yocto_queue2();
832
- var pLimit2 = (concurrency) => {
833
- if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
834
- throw new TypeError("Expected `concurrency` to be a number from 1 and up");
835
- }
836
- const queue = new Queue();
837
- let activeCount = 0;
838
- const next = () => {
839
- activeCount--;
840
- if (queue.size > 0) {
841
- queue.dequeue()();
842
- }
843
- };
844
- const run = async (fn, resolve, ...args) => {
845
- activeCount++;
846
- const result = (async () => fn(...args))();
847
- resolve(result);
848
- try {
849
- await result;
850
- } catch (e) {
851
- }
852
- next();
853
- };
854
- const enqueue = (fn, resolve, ...args) => {
855
- queue.enqueue(run.bind(null, fn, resolve, ...args));
856
- (async () => {
857
- await Promise.resolve();
858
- if (activeCount < concurrency && queue.size > 0) {
859
- queue.dequeue()();
860
- }
861
- })();
862
- };
863
- const generator = (fn, ...args) => new Promise((resolve) => {
864
- enqueue(fn, resolve, ...args);
865
- });
866
- Object.defineProperties(generator, {
867
- activeCount: {
868
- get: () => activeCount
869
- },
870
- pendingCount: {
871
- get: () => queue.size
872
- },
873
- clearQueue: {
874
- value: () => {
875
- queue.clear();
876
- }
877
- }
878
- });
879
- return generator;
880
- };
881
- module.exports = pLimit2;
882
- }
883
- });
884
- var require_retry_operation = __commonJS2({
885
- "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js"(exports, module) {
886
- "use strict";
887
- function RetryOperation(timeouts, options) {
888
- if (typeof options === "boolean") {
889
- options = { forever: options };
890
- }
891
- this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
892
- this._timeouts = timeouts;
893
- this._options = options || {};
894
- this._maxRetryTime = options && options.maxRetryTime || Infinity;
895
- this._fn = null;
896
- this._errors = [];
897
- this._attempts = 1;
898
- this._operationTimeout = null;
899
- this._operationTimeoutCb = null;
900
- this._timeout = null;
901
- this._operationStart = null;
902
- this._timer = null;
903
- if (this._options.forever) {
904
- this._cachedTimeouts = this._timeouts.slice(0);
905
- }
906
- }
907
- module.exports = RetryOperation;
908
- RetryOperation.prototype.reset = function() {
909
- this._attempts = 1;
910
- this._timeouts = this._originalTimeouts.slice(0);
911
- };
912
- RetryOperation.prototype.stop = function() {
913
- if (this._timeout) {
914
- clearTimeout(this._timeout);
915
- }
916
- if (this._timer) {
917
- clearTimeout(this._timer);
918
- }
919
- this._timeouts = [];
920
- this._cachedTimeouts = null;
921
- };
922
- RetryOperation.prototype.retry = function(err) {
923
- if (this._timeout) {
924
- clearTimeout(this._timeout);
925
- }
926
- if (!err) {
927
- return false;
928
- }
929
- var currentTime = (/* @__PURE__ */ new Date()).getTime();
930
- if (err && currentTime - this._operationStart >= this._maxRetryTime) {
931
- this._errors.push(err);
932
- this._errors.unshift(new Error("RetryOperation timeout occurred"));
933
- return false;
934
- }
935
- this._errors.push(err);
936
- var timeout = this._timeouts.shift();
937
- if (timeout === void 0) {
938
- if (this._cachedTimeouts) {
939
- this._errors.splice(0, this._errors.length - 1);
940
- timeout = this._cachedTimeouts.slice(-1);
941
- } else {
942
- return false;
943
- }
944
- }
945
- var self = this;
946
- this._timer = setTimeout(function() {
947
- self._attempts++;
948
- if (self._operationTimeoutCb) {
949
- self._timeout = setTimeout(function() {
950
- self._operationTimeoutCb(self._attempts);
951
- }, self._operationTimeout);
952
- if (self._options.unref) {
953
- self._timeout.unref();
954
- }
955
- }
956
- self._fn(self._attempts);
957
- }, timeout);
958
- if (this._options.unref) {
959
- this._timer.unref();
960
- }
961
- return true;
962
- };
963
- RetryOperation.prototype.attempt = function(fn, timeoutOps) {
964
- this._fn = fn;
965
- if (timeoutOps) {
966
- if (timeoutOps.timeout) {
967
- this._operationTimeout = timeoutOps.timeout;
968
- }
969
- if (timeoutOps.cb) {
970
- this._operationTimeoutCb = timeoutOps.cb;
971
- }
972
- }
973
- var self = this;
974
- if (this._operationTimeoutCb) {
975
- this._timeout = setTimeout(function() {
976
- self._operationTimeoutCb();
977
- }, self._operationTimeout);
978
- }
979
- this._operationStart = (/* @__PURE__ */ new Date()).getTime();
980
- this._fn(this._attempts);
981
- };
982
- RetryOperation.prototype.try = function(fn) {
983
- console.log("Using RetryOperation.try() is deprecated");
984
- this.attempt(fn);
985
- };
986
- RetryOperation.prototype.start = function(fn) {
987
- console.log("Using RetryOperation.start() is deprecated");
988
- this.attempt(fn);
989
- };
990
- RetryOperation.prototype.start = RetryOperation.prototype.try;
991
- RetryOperation.prototype.errors = function() {
992
- return this._errors;
993
- };
994
- RetryOperation.prototype.attempts = function() {
995
- return this._attempts;
996
- };
997
- RetryOperation.prototype.mainError = function() {
998
- if (this._errors.length === 0) {
999
- return null;
1000
- }
1001
- var counts = {};
1002
- var mainError = null;
1003
- var mainErrorCount = 0;
1004
- for (var i = 0; i < this._errors.length; i++) {
1005
- var error = this._errors[i];
1006
- var message = error.message;
1007
- var count = (counts[message] || 0) + 1;
1008
- counts[message] = count;
1009
- if (count >= mainErrorCount) {
1010
- mainError = error;
1011
- mainErrorCount = count;
1012
- }
1013
- }
1014
- return mainError;
1015
- };
1016
- }
1017
- });
1018
- var require_retry = __commonJS2({
1019
- "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js"(exports) {
1020
- "use strict";
1021
- var RetryOperation = require_retry_operation();
1022
- exports.operation = function(options) {
1023
- var timeouts = exports.timeouts(options);
1024
- return new RetryOperation(timeouts, {
1025
- forever: options && (options.forever || options.retries === Infinity),
1026
- unref: options && options.unref,
1027
- maxRetryTime: options && options.maxRetryTime
1028
- });
1029
- };
1030
- exports.timeouts = function(options) {
1031
- if (options instanceof Array) {
1032
- return [].concat(options);
1033
- }
1034
- var opts = {
1035
- retries: 10,
1036
- factor: 2,
1037
- minTimeout: 1 * 1e3,
1038
- maxTimeout: Infinity,
1039
- randomize: false
1040
- };
1041
- for (var key in options) {
1042
- opts[key] = options[key];
1043
- }
1044
- if (opts.minTimeout > opts.maxTimeout) {
1045
- throw new Error("minTimeout is greater than maxTimeout");
1046
- }
1047
- var timeouts = [];
1048
- for (var i = 0; i < opts.retries; i++) {
1049
- timeouts.push(this.createTimeout(i, opts));
1050
- }
1051
- if (options && options.forever && !timeouts.length) {
1052
- timeouts.push(this.createTimeout(i, opts));
1003
+ expectNoContent: true
1004
+ });
1005
+ }
1006
+ };
1007
+ _url7 = /* @__PURE__ */ new WeakMap();
1008
+ __privateAdd2(_TestClient, _url7, "/api/v2/test");
1009
+
1010
+ // ../../node_modules/.pnpm/yocto-queue@1.2.2/node_modules/yocto-queue/index.js
1011
+ var Node = class {
1012
+ constructor(value) {
1013
+ __publicField(this, "value");
1014
+ __publicField(this, "next");
1015
+ this.value = value;
1016
+ }
1017
+ };
1018
+ var _head, _tail, _size;
1019
+ var Queue = class {
1020
+ constructor() {
1021
+ __privateAdd(this, _head);
1022
+ __privateAdd(this, _tail);
1023
+ __privateAdd(this, _size);
1024
+ this.clear();
1025
+ }
1026
+ enqueue(value) {
1027
+ const node = new Node(value);
1028
+ if (__privateGet(this, _head)) {
1029
+ __privateGet(this, _tail).next = node;
1030
+ __privateSet(this, _tail, node);
1031
+ } else {
1032
+ __privateSet(this, _head, node);
1033
+ __privateSet(this, _tail, node);
1034
+ }
1035
+ __privateWrapper(this, _size)._++;
1036
+ }
1037
+ dequeue() {
1038
+ const current = __privateGet(this, _head);
1039
+ if (!current) {
1040
+ return;
1041
+ }
1042
+ __privateSet(this, _head, __privateGet(this, _head).next);
1043
+ __privateWrapper(this, _size)._--;
1044
+ if (!__privateGet(this, _head)) {
1045
+ __privateSet(this, _tail, void 0);
1046
+ }
1047
+ return current.value;
1048
+ }
1049
+ peek() {
1050
+ if (!__privateGet(this, _head)) {
1051
+ return;
1052
+ }
1053
+ return __privateGet(this, _head).value;
1054
+ }
1055
+ clear() {
1056
+ __privateSet(this, _head, void 0);
1057
+ __privateSet(this, _tail, void 0);
1058
+ __privateSet(this, _size, 0);
1059
+ }
1060
+ get size() {
1061
+ return __privateGet(this, _size);
1062
+ }
1063
+ *[Symbol.iterator]() {
1064
+ let current = __privateGet(this, _head);
1065
+ while (current) {
1066
+ yield current.value;
1067
+ current = current.next;
1068
+ }
1069
+ }
1070
+ *drain() {
1071
+ while (__privateGet(this, _head)) {
1072
+ yield this.dequeue();
1073
+ }
1074
+ }
1075
+ };
1076
+ _head = new WeakMap();
1077
+ _tail = new WeakMap();
1078
+ _size = new WeakMap();
1079
+
1080
+ // ../../node_modules/.pnpm/p-limit@6.2.0/node_modules/p-limit/index.js
1081
+ function pLimit2(concurrency) {
1082
+ validateConcurrency(concurrency);
1083
+ const queue = new Queue();
1084
+ let activeCount = 0;
1085
+ const resumeNext = () => {
1086
+ if (activeCount < concurrency && queue.size > 0) {
1087
+ queue.dequeue()();
1088
+ activeCount++;
1089
+ }
1090
+ };
1091
+ const next = () => {
1092
+ activeCount--;
1093
+ resumeNext();
1094
+ };
1095
+ const run = async (function_, resolve, arguments_) => {
1096
+ const result = (async () => function_(...arguments_))();
1097
+ resolve(result);
1098
+ try {
1099
+ await result;
1100
+ } catch (e) {
1101
+ }
1102
+ next();
1103
+ };
1104
+ const enqueue = (function_, resolve, arguments_) => {
1105
+ new Promise((internalResolve) => {
1106
+ queue.enqueue(internalResolve);
1107
+ }).then(
1108
+ run.bind(void 0, function_, resolve, arguments_)
1109
+ );
1110
+ (async () => {
1111
+ await Promise.resolve();
1112
+ if (activeCount < concurrency) {
1113
+ resumeNext();
1053
1114
  }
1054
- timeouts.sort(function(a, b) {
1055
- return a - b;
1056
- });
1057
- return timeouts;
1058
- };
1059
- exports.createTimeout = function(attempt, opts) {
1060
- var random = opts.randomize ? Math.random() + 1 : 1;
1061
- var timeout = Math.round(random * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt));
1062
- timeout = Math.min(timeout, opts.maxTimeout);
1063
- return timeout;
1064
- };
1065
- exports.wrap = function(obj, options, methods) {
1066
- if (options instanceof Array) {
1067
- methods = options;
1068
- options = null;
1115
+ })();
1116
+ };
1117
+ const generator = (function_, ...arguments_) => new Promise((resolve) => {
1118
+ enqueue(function_, resolve, arguments_);
1119
+ });
1120
+ Object.defineProperties(generator, {
1121
+ activeCount: {
1122
+ get: () => activeCount
1123
+ },
1124
+ pendingCount: {
1125
+ get: () => queue.size
1126
+ },
1127
+ clearQueue: {
1128
+ value() {
1129
+ queue.clear();
1069
1130
  }
1070
- if (!methods) {
1071
- methods = [];
1072
- for (var key in obj) {
1073
- if (typeof obj[key] === "function") {
1074
- methods.push(key);
1131
+ },
1132
+ concurrency: {
1133
+ get: () => concurrency,
1134
+ set(newConcurrency) {
1135
+ validateConcurrency(newConcurrency);
1136
+ concurrency = newConcurrency;
1137
+ queueMicrotask(() => {
1138
+ while (activeCount < concurrency && queue.size > 0) {
1139
+ resumeNext();
1075
1140
  }
1076
- }
1077
- }
1078
- for (var i = 0; i < methods.length; i++) {
1079
- var method = methods[i];
1080
- var original = obj[method];
1081
- obj[method] = function retryWrapper(original2) {
1082
- var op = exports.operation(options);
1083
- var args = Array.prototype.slice.call(arguments, 1);
1084
- var callback = args.pop();
1085
- args.push(function(err) {
1086
- if (op.retry(err)) {
1087
- return;
1088
- }
1089
- if (err) {
1090
- arguments[0] = op.mainError();
1091
- }
1092
- callback.apply(this, arguments);
1093
- });
1094
- op.attempt(function() {
1095
- original2.apply(obj, args);
1096
- });
1097
- }.bind(obj, original);
1098
- obj[method].options = options;
1141
+ });
1099
1142
  }
1100
- };
1101
- }
1102
- });
1103
- var require_retry2 = __commonJS2({
1104
- "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js"(exports, module) {
1105
- "use strict";
1106
- module.exports = require_retry();
1143
+ }
1144
+ });
1145
+ return generator;
1146
+ }
1147
+ function validateConcurrency(concurrency) {
1148
+ if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
1149
+ throw new TypeError("Expected `concurrency` to be a number from 1 and up");
1107
1150
  }
1108
- });
1109
- var import_p_limit2 = __toESM2(require_p_limit2());
1110
- var import_retry = __toESM2(require_retry2(), 1);
1111
- var networkErrorMsgs = /* @__PURE__ */ new Set([
1112
- "Failed to fetch",
1151
+ }
1152
+
1153
+ // ../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
1154
+ var import_retry = __toESM(require_retry2(), 1);
1155
+
1156
+ // ../../node_modules/.pnpm/is-network-error@1.3.2/node_modules/is-network-error/index.js
1157
+ var objectToString = Object.prototype.toString;
1158
+ var isError = (value) => objectToString.call(value) === "[object Error]";
1159
+ var errorMessages = /* @__PURE__ */ new Set([
1160
+ "network error",
1113
1161
  // Chrome
1114
1162
  "NetworkError when attempting to fetch resource.",
1115
1163
  // Firefox
1116
1164
  "The Internet connection appears to be offline.",
1117
- // Safari
1165
+ // Safari 16
1118
1166
  "Network request failed",
1119
1167
  // `cross-fetch`
1120
- "fetch failed"
1168
+ "fetch failed",
1121
1169
  // Undici (Node.js)
1170
+ "terminated",
1171
+ // Undici (Node.js)
1172
+ " A network error occurred.",
1173
+ // Bun (WebKit)
1174
+ "Network connection lost"
1175
+ // Cloudflare Workers (fetch)
1122
1176
  ]);
1177
+ function isNetworkError(error) {
1178
+ const isValid = error && isError(error) && error.name === "TypeError" && typeof error.message === "string";
1179
+ if (!isValid) {
1180
+ return false;
1181
+ }
1182
+ const { message, stack } = error;
1183
+ if (message === "Load failed" || message.startsWith("Load failed (") && message.endsWith(")")) {
1184
+ return stack === void 0 || "__sentry_captured__" in error;
1185
+ }
1186
+ if (message.startsWith("error sending request for url")) {
1187
+ return true;
1188
+ }
1189
+ if (message === "Failed to fetch" || message.startsWith("Failed to fetch (") && message.endsWith(")")) {
1190
+ return true;
1191
+ }
1192
+ return errorMessages.has(message);
1193
+ }
1194
+
1195
+ // ../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
1123
1196
  var AbortError = class extends Error {
1124
1197
  constructor(message) {
1125
1198
  super();
@@ -1140,63 +1213,71 @@ var decorateErrorWithCounts = (error, attemptNumber, options) => {
1140
1213
  error.retriesLeft = retriesLeft;
1141
1214
  return error;
1142
1215
  };
1143
- var isNetworkError = (errorMessage) => networkErrorMsgs.has(errorMessage);
1144
- var getDOMException = (errorMessage) => globalThis.DOMException === void 0 ? new Error(errorMessage) : new DOMException(errorMessage);
1145
1216
  async function pRetry(input, options) {
1146
1217
  return new Promise((resolve, reject) => {
1147
- options = {
1148
- onFailedAttempt() {
1149
- },
1150
- retries: 10,
1151
- ...options
1218
+ var _a, _b, _c;
1219
+ options = { ...options };
1220
+ (_a = options.onFailedAttempt) != null ? _a : options.onFailedAttempt = () => {
1152
1221
  };
1222
+ (_b = options.shouldRetry) != null ? _b : options.shouldRetry = () => true;
1223
+ (_c = options.retries) != null ? _c : options.retries = 10;
1153
1224
  const operation = import_retry.default.operation(options);
1225
+ const abortHandler = () => {
1226
+ var _a2;
1227
+ operation.stop();
1228
+ reject((_a2 = options.signal) == null ? void 0 : _a2.reason);
1229
+ };
1230
+ if (options.signal && !options.signal.aborted) {
1231
+ options.signal.addEventListener("abort", abortHandler, { once: true });
1232
+ }
1233
+ const cleanUp = () => {
1234
+ var _a2;
1235
+ (_a2 = options.signal) == null ? void 0 : _a2.removeEventListener("abort", abortHandler);
1236
+ operation.stop();
1237
+ };
1154
1238
  operation.attempt(async (attemptNumber) => {
1155
1239
  try {
1156
- resolve(await input(attemptNumber));
1240
+ const result = await input(attemptNumber);
1241
+ cleanUp();
1242
+ resolve(result);
1157
1243
  } catch (error) {
1158
- if (!(error instanceof Error)) {
1159
- reject(new TypeError(`Non-error was thrown: "${error}". You should only throw errors.`));
1160
- return;
1161
- }
1162
- if (error instanceof AbortError) {
1163
- operation.stop();
1164
- reject(error.originalError);
1165
- } else if (error instanceof TypeError && !isNetworkError(error.message)) {
1166
- operation.stop();
1167
- reject(error);
1168
- } else {
1244
+ try {
1245
+ if (!(error instanceof Error)) {
1246
+ throw new TypeError(`Non-error was thrown: "${error}". You should only throw errors.`);
1247
+ }
1248
+ if (error instanceof AbortError) {
1249
+ throw error.originalError;
1250
+ }
1251
+ if (error instanceof TypeError && !isNetworkError(error)) {
1252
+ throw error;
1253
+ }
1169
1254
  decorateErrorWithCounts(error, attemptNumber, options);
1170
- try {
1171
- await options.onFailedAttempt(error);
1172
- } catch (error2) {
1173
- reject(error2);
1174
- return;
1255
+ if (!await options.shouldRetry(error)) {
1256
+ operation.stop();
1257
+ reject(error);
1175
1258
  }
1259
+ await options.onFailedAttempt(error);
1176
1260
  if (!operation.retry(error)) {
1177
- reject(operation.mainError());
1261
+ throw operation.mainError();
1178
1262
  }
1263
+ } catch (finalError) {
1264
+ decorateErrorWithCounts(finalError, attemptNumber, options);
1265
+ cleanUp();
1266
+ reject(finalError);
1179
1267
  }
1180
1268
  }
1181
1269
  });
1182
- if (options.signal && !options.signal.aborted) {
1183
- options.signal.addEventListener("abort", () => {
1184
- operation.stop();
1185
- const reason = options.signal.reason === void 0 ? getDOMException("The operation was aborted.") : options.signal.reason;
1186
- reject(reason instanceof Error ? reason : getDOMException(reason));
1187
- }, {
1188
- once: true
1189
- });
1190
- }
1191
1270
  });
1192
1271
  }
1272
+
1273
+ // ../../node_modules/.pnpm/p-throttle@6.2.0/node_modules/p-throttle/index.js
1193
1274
  var AbortError2 = class extends Error {
1194
1275
  constructor() {
1195
1276
  super("Throttled function aborted");
1196
1277
  this.name = "AbortError";
1197
1278
  }
1198
1279
  };
1199
- function pThrottle({ limit, interval, strict }) {
1280
+ function pThrottle({ limit, interval, strict, onDelay }) {
1200
1281
  if (!Number.isFinite(limit)) {
1201
1282
  throw new TypeError("Expected `limit` to be a finite number");
1202
1283
  }
@@ -1224,32 +1305,38 @@ function pThrottle({ limit, interval, strict }) {
1224
1305
  const strictTicks = [];
1225
1306
  function strictDelay() {
1226
1307
  const now = Date.now();
1227
- if (strictTicks.length < limit) {
1228
- strictTicks.push(now);
1229
- return 0;
1308
+ if (strictTicks.length > 0 && now - strictTicks.at(-1) > interval) {
1309
+ strictTicks.length = 0;
1230
1310
  }
1231
- const earliestTime = strictTicks.shift() + interval;
1232
- if (now >= earliestTime) {
1311
+ if (strictTicks.length < limit) {
1233
1312
  strictTicks.push(now);
1234
1313
  return 0;
1235
1314
  }
1236
- strictTicks.push(earliestTime);
1237
- return earliestTime - now;
1315
+ const nextExecutionTime = strictTicks[0] + interval;
1316
+ strictTicks.shift();
1317
+ strictTicks.push(nextExecutionTime);
1318
+ return Math.max(0, nextExecutionTime - now);
1238
1319
  }
1239
1320
  const getDelay = strict ? strictDelay : windowedDelay;
1240
1321
  return (function_) => {
1241
- const throttled = function(...args) {
1322
+ const throttled = function(...arguments_) {
1242
1323
  if (!throttled.isEnabled) {
1243
- return (async () => function_.apply(this, args))();
1324
+ return (async () => function_.apply(this, arguments_))();
1244
1325
  }
1245
- let timeout;
1326
+ let timeoutId;
1246
1327
  return new Promise((resolve, reject) => {
1247
1328
  const execute = () => {
1248
- resolve(function_.apply(this, args));
1249
- queue.delete(timeout);
1329
+ resolve(function_.apply(this, arguments_));
1330
+ queue.delete(timeoutId);
1250
1331
  };
1251
- timeout = setTimeout(execute, getDelay());
1252
- queue.set(timeout, reject);
1332
+ const delay = getDelay();
1333
+ if (delay > 0) {
1334
+ timeoutId = setTimeout(execute, delay);
1335
+ queue.set(timeoutId, reject);
1336
+ onDelay == null ? void 0 : onDelay(...arguments_);
1337
+ } else {
1338
+ execute();
1339
+ }
1253
1340
  });
1254
1341
  };
1255
1342
  throttled.abort = () => {
@@ -1261,16 +1348,29 @@ function pThrottle({ limit, interval, strict }) {
1261
1348
  strictTicks.splice(0, strictTicks.length);
1262
1349
  };
1263
1350
  throttled.isEnabled = true;
1351
+ Object.defineProperty(throttled, "queueSize", {
1352
+ get() {
1353
+ return queue.size;
1354
+ }
1355
+ });
1264
1356
  return throttled;
1265
1357
  };
1266
1358
  }
1359
+
1360
+ // ../canvas/dist/index.mjs
1361
+ var __typeError3 = (msg) => {
1362
+ throw TypeError(msg);
1363
+ };
1364
+ var __accessCheck3 = (obj, member, msg) => member.has(obj) || __typeError3("Cannot " + msg);
1365
+ var __privateGet3 = (obj, member, getter) => (__accessCheck3(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
1366
+ var __privateAdd3 = (obj, member, value) => member.has(obj) ? __typeError3("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1267
1367
  function createLimitPolicy({
1268
1368
  throttle = { interval: 1e3, limit: 10 },
1269
- retry: retry2 = { retries: 1, factor: 1.66 },
1369
+ retry: retry3 = { retries: 1, factor: 1.66 },
1270
1370
  limit = 10
1271
1371
  }) {
1272
1372
  const throttler = throttle ? pThrottle(throttle) : null;
1273
- const limiter = limit ? (0, import_p_limit2.default)(limit) : null;
1373
+ const limiter = limit ? pLimit2(limit) : null;
1274
1374
  return function limitPolicy(func) {
1275
1375
  let currentFunc = async () => await func();
1276
1376
  if (throttler) {
@@ -1281,13 +1381,13 @@ function createLimitPolicy({
1281
1381
  const limitFunc = currentFunc;
1282
1382
  currentFunc = () => limiter(limitFunc);
1283
1383
  }
1284
- if (retry2) {
1384
+ if (retry3) {
1285
1385
  const retryFunc = currentFunc;
1286
1386
  currentFunc = () => pRetry(retryFunc, {
1287
- ...retry2,
1387
+ ...retry3,
1288
1388
  onFailedAttempt: async (error) => {
1289
- if (retry2.onFailedAttempt) {
1290
- await retry2.onFailedAttempt(error);
1389
+ if (retry3.onFailedAttempt) {
1390
+ await retry3.onFailedAttempt(error);
1291
1391
  }
1292
1392
  if (error instanceof ApiClientError && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
1293
1393
  throw error;
@@ -1298,19 +1398,49 @@ function createLimitPolicy({
1298
1398
  return currentFunc();
1299
1399
  };
1300
1400
  }
1301
- var isPlainObject = (obj) => typeof obj === "object" && obj !== null && !Array.isArray(obj);
1302
- function rewriteFilters(filters) {
1303
- return Object.entries(filters != null ? filters : {}).reduce(
1304
- (acc, [key, value]) => {
1305
- const lhs = `filters.${key}` + (isPlainObject(value) ? `[${Object.keys(value)[0]}]` : "");
1306
- const rhs = isPlainObject(value) ? Object.values(value)[0] : value;
1307
- return {
1308
- ...acc,
1309
- [lhs]: Array.isArray(rhs) ? rhs.map((v) => `${v}`.trim()).join(",") : `${rhs}`.trim()
1310
- };
1311
- },
1312
- {}
1313
- );
1401
+ var SELECT_QUERY_PREFIX = "select.";
1402
+ function appendCsv(out, key, values) {
1403
+ if (values === void 0) {
1404
+ return;
1405
+ }
1406
+ out[key] = values.join(",");
1407
+ }
1408
+ function projectionToQuery(spec) {
1409
+ const out = {};
1410
+ if (!spec) {
1411
+ return out;
1412
+ }
1413
+ const { fields, fieldTypes, slots } = spec;
1414
+ const p = SELECT_QUERY_PREFIX;
1415
+ if (fields) {
1416
+ appendCsv(out, `${p}fields[only]`, fields.only);
1417
+ appendCsv(out, `${p}fields[except]`, fields.except);
1418
+ appendCsv(out, `${p}fields[locales]`, fields.locales);
1419
+ if (fields.blockDepth === "preserveAll" || typeof fields.blockDepth === "number") {
1420
+ out[`${p}fields[blockDepth]`] = String(fields.blockDepth);
1421
+ }
1422
+ }
1423
+ if (fieldTypes) {
1424
+ appendCsv(out, `${p}fieldTypes[only]`, fieldTypes.only);
1425
+ appendCsv(out, `${p}fieldTypes[except]`, fieldTypes.except);
1426
+ }
1427
+ if (slots) {
1428
+ appendCsv(out, `${p}slots[only]`, slots.only);
1429
+ appendCsv(out, `${p}slots[except]`, slots.except);
1430
+ if (typeof slots.depth === "number") {
1431
+ out[`${p}slots[depth]`] = String(slots.depth);
1432
+ }
1433
+ if (slots.named) {
1434
+ const slotNames = Object.keys(slots.named).sort();
1435
+ for (const slotName of slotNames) {
1436
+ const named = slots.named[slotName];
1437
+ if (named && typeof named.depth === "number") {
1438
+ out[`${p}slots.${slotName}[depth]`] = String(named.depth);
1439
+ }
1440
+ }
1441
+ }
1442
+ }
1443
+ return out;
1314
1444
  }
1315
1445
  var CANVAS_URL = "/api/v1/canvas";
1316
1446
  var CanvasClient = class extends ApiClient {
@@ -1326,17 +1456,24 @@ var CanvasClient = class extends ApiClient {
1326
1456
  /** Fetches lists of Canvas compositions, optionally by type */
1327
1457
  async getCompositionList(params = {}) {
1328
1458
  const { projectId } = this.options;
1329
- const { resolveData, filters, ...originParams } = params;
1330
- const rewrittenFilters = rewriteFilters(filters);
1459
+ const { resolveData, filters, select, ...originParams } = params;
1460
+ const rewrittenFilters = rewriteFiltersForApi(filters);
1461
+ const rewrittenSelect = projectionToQuery(select);
1331
1462
  if (!resolveData) {
1332
- const fetchUri = this.createUrl(CANVAS_URL, { ...originParams, projectId, ...rewrittenFilters });
1463
+ const fetchUri = this.createUrl(CANVAS_URL, {
1464
+ ...originParams,
1465
+ projectId,
1466
+ ...rewrittenFilters,
1467
+ ...rewrittenSelect
1468
+ });
1333
1469
  return this.apiClient(fetchUri);
1334
1470
  }
1335
1471
  const edgeParams = {
1336
1472
  ...originParams,
1337
1473
  projectId,
1338
1474
  diagnostics: typeof params.diagnostics === "boolean" ? params.diagnostics : params.diagnostics === "no-data" ? "no-data" : void 0,
1339
- ...rewrittenFilters
1475
+ ...rewrittenFilters,
1476
+ ...rewrittenSelect
1340
1477
  };
1341
1478
  const edgeUrl = this.createUrl("/api/v1/compositions", edgeParams, this.edgeApiHost);
1342
1479
  return this.apiClient(edgeUrl, this.edgeApiRequestInit);
@@ -1446,15 +1583,21 @@ var _ContentClient = class _ContentClient2 extends ApiClient {
1446
1583
  }
1447
1584
  getEntries(options) {
1448
1585
  const { projectId } = this.options;
1449
- const { skipDataResolution, filters, ...params } = options;
1450
- const rewrittenFilters = rewriteFilters(filters);
1586
+ const { skipDataResolution, filters, select, ...params } = options;
1587
+ const rewrittenFilters = rewriteFiltersForApi(filters);
1588
+ const rewrittenSelect = projectionToQuery(select);
1451
1589
  if (skipDataResolution) {
1452
- const url = this.createUrl(__privateGet3(_ContentClient2, _entriesUrl), { ...params, ...rewrittenFilters, projectId });
1590
+ const url = this.createUrl(__privateGet3(_ContentClient2, _entriesUrl), {
1591
+ ...params,
1592
+ ...rewrittenFilters,
1593
+ ...rewrittenSelect,
1594
+ projectId
1595
+ });
1453
1596
  return this.apiClient(url);
1454
1597
  }
1455
1598
  const edgeUrl = this.createUrl(
1456
1599
  __privateGet3(_ContentClient2, _entriesUrl),
1457
- { ...this.getEdgeOptions(params), ...rewrittenFilters },
1600
+ { ...this.getEdgeOptions(params), ...rewrittenFilters, ...rewrittenSelect },
1458
1601
  this.edgeApiHost
1459
1602
  );
1460
1603
  return this.apiClient(
@@ -1618,9 +1761,9 @@ function parseVariableExpression(serialized, onToken) {
1618
1761
  let bufferStartIndex = 0;
1619
1762
  let bufferEndIndex = 0;
1620
1763
  let tokenCount = 0;
1621
- const handleToken = (token, type) => {
1764
+ const handleToken = (token, type, offset) => {
1622
1765
  tokenCount++;
1623
- return onToken == null ? void 0 : onToken(token, type);
1766
+ return onToken == null ? void 0 : onToken(token, type, offset);
1624
1767
  };
1625
1768
  let state = "text";
1626
1769
  for (let index = 0; index < serialized.length; index++) {
@@ -1631,7 +1774,7 @@ function parseVariableExpression(serialized, onToken) {
1631
1774
  if (char === variablePrefix[0] && serialized[index + 1] === variablePrefix[1]) {
1632
1775
  if (serialized[index - 1] === escapeCharacter) {
1633
1776
  bufferEndIndex -= escapeCharacter.length;
1634
- if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text") === false) {
1777
+ if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text", bufferStartIndex) === false) {
1635
1778
  return tokenCount;
1636
1779
  }
1637
1780
  bufferStartIndex = index;
@@ -1640,12 +1783,12 @@ function parseVariableExpression(serialized, onToken) {
1640
1783
  }
1641
1784
  if (state === "variable") {
1642
1785
  const textStart = bufferStartIndex - variablePrefix.length;
1643
- if (handleToken(serialized.substring(textStart, bufferEndIndex), "text") === false) {
1786
+ if (handleToken(serialized.substring(textStart, bufferEndIndex), "text", textStart) === false) {
1644
1787
  return tokenCount;
1645
1788
  }
1646
1789
  bufferStartIndex = bufferEndIndex;
1647
1790
  } else if (bufferEndIndex > bufferStartIndex) {
1648
- if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text") === false) {
1791
+ if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text", bufferStartIndex) === false) {
1649
1792
  return tokenCount;
1650
1793
  }
1651
1794
  bufferStartIndex = bufferEndIndex;
@@ -1663,7 +1806,7 @@ function parseVariableExpression(serialized, onToken) {
1663
1806
  state = "text";
1664
1807
  if (bufferEndIndex > bufferStartIndex) {
1665
1808
  const unescapedVariableName = serialized.substring(bufferStartIndex, bufferEndIndex).replace(/\\([${}])/g, "$1");
1666
- if (handleToken(unescapedVariableName, "variable") === false) {
1809
+ if (handleToken(unescapedVariableName, "variable", bufferStartIndex) === false) {
1667
1810
  return tokenCount;
1668
1811
  }
1669
1812
  bufferStartIndex = bufferEndIndex + variableSuffix.length;
@@ -1677,7 +1820,7 @@ function parseVariableExpression(serialized, onToken) {
1677
1820
  bufferStartIndex -= variablePrefix.length;
1678
1821
  }
1679
1822
  if (bufferStartIndex < serialized.length) {
1680
- handleToken(serialized.substring(bufferStartIndex), state);
1823
+ handleToken(serialized.substring(bufferStartIndex), state, bufferStartIndex);
1681
1824
  }
1682
1825
  return tokenCount;
1683
1826
  }
@@ -1694,7 +1837,7 @@ function hasReferencedVariables(value) {
1694
1837
  return variableTokenCount;
1695
1838
  }
1696
1839
  function walkNodeTree(node, visitor, options) {
1697
- var _a, _b;
1840
+ var _a, _b, _c;
1698
1841
  const componentQueue = [
1699
1842
  {
1700
1843
  ancestorsAndSelf: Array.isArray(node) ? node : [{ node, type: "root" }],
@@ -1702,12 +1845,14 @@ function walkNodeTree(node, visitor, options) {
1702
1845
  }
1703
1846
  ];
1704
1847
  const childContexts = /* @__PURE__ */ new Map();
1848
+ const order = (_a = options == null ? void 0 : options.order) != null ? _a : "dfs";
1849
+ const takeNext = () => order === "bfs" ? componentQueue.shift() : componentQueue.pop();
1705
1850
  do {
1706
- const currentQueueEntry = componentQueue.pop();
1851
+ const currentQueueEntry = takeNext();
1707
1852
  if (!currentQueueEntry) continue;
1708
1853
  const currentComponent = currentQueueEntry.ancestorsAndSelf[0];
1709
1854
  let visitDescendants = true;
1710
- let descendantContext = (_a = childContexts.get(currentComponent.node)) != null ? _a : currentQueueEntry.context;
1855
+ let descendantContext = (_b = childContexts.get(currentComponent.node)) != null ? _b : currentQueueEntry.context;
1711
1856
  let visitorInfo;
1712
1857
  if (currentComponent.type === "root" && isRootEntryReference(currentComponent) || currentComponent.type === "block") {
1713
1858
  visitorInfo = {
@@ -1894,39 +2039,11 @@ function walkNodeTree(node, visitor, options) {
1894
2039
  continue;
1895
2040
  }
1896
2041
  const slots = "slots" in currentComponent.node && currentComponent.node.slots;
1897
- if (slots) {
1898
- const slotKeys = Object.keys(slots);
1899
- for (let slotIndex = slotKeys.length - 1; slotIndex >= 0; slotIndex--) {
1900
- const slotKey = slotKeys[slotIndex];
1901
- const components = slots[slotKey];
1902
- for (let componentIndex = components.length - 1; componentIndex >= 0; componentIndex--) {
1903
- const enqueueingComponent = components[componentIndex];
1904
- const parentSlotIndexFn = () => {
1905
- const result = currentComponent.node.slots[slotKey].findIndex(
1906
- (x) => x === enqueueingComponent
1907
- );
1908
- return result;
1909
- };
1910
- componentQueue.push({
1911
- ancestorsAndSelf: [
1912
- {
1913
- type: "slot",
1914
- node: enqueueingComponent,
1915
- parentSlot: slotKey,
1916
- parentSlotIndexFn
1917
- },
1918
- ...currentQueueEntry.ancestorsAndSelf
1919
- ],
1920
- context: descendantContext
1921
- });
1922
- }
1923
- }
1924
- }
2042
+ const childEntries = [];
1925
2043
  const properties = getPropertiesValue(currentComponent.node);
1926
2044
  if (properties) {
1927
2045
  const propertyEntries = Object.entries(properties);
1928
- for (let propIndex = propertyEntries.length - 1; propIndex >= 0; propIndex--) {
1929
- const [propKey, propObject] = propertyEntries[propIndex];
2046
+ for (const [propKey, propObject] of propertyEntries) {
1930
2047
  if (!isNestedNodeType(propObject.type)) {
1931
2048
  continue;
1932
2049
  }
@@ -1946,13 +2063,12 @@ function walkNodeTree(node, visitor, options) {
1946
2063
  continue;
1947
2064
  }
1948
2065
  }
1949
- const blocks = (_b = propObject.value) != null ? _b : [];
1950
- for (let blockIndex = blocks.length - 1; blockIndex >= 0; blockIndex--) {
1951
- const enqueueingBlock = blocks[blockIndex];
2066
+ const blocks = (_c = propObject.value) != null ? _c : [];
2067
+ for (const enqueueingBlock of blocks) {
1952
2068
  const blockIndexFn = () => {
1953
2069
  return getBlockValue(currentComponent.node, propKey).findIndex((x) => x === enqueueingBlock);
1954
2070
  };
1955
- componentQueue.push({
2071
+ childEntries.push({
1956
2072
  ancestorsAndSelf: [
1957
2073
  {
1958
2074
  type: "block",
@@ -1967,6 +2083,36 @@ function walkNodeTree(node, visitor, options) {
1967
2083
  }
1968
2084
  }
1969
2085
  }
2086
+ if (slots) {
2087
+ const slotKeys = Object.keys(slots);
2088
+ for (const slotKey of slotKeys) {
2089
+ const components = slots[slotKey];
2090
+ for (const enqueueingComponent of components) {
2091
+ const parentSlotIndexFn = () => {
2092
+ const result = currentComponent.node.slots[slotKey].findIndex(
2093
+ (x) => x === enqueueingComponent
2094
+ );
2095
+ return result;
2096
+ };
2097
+ childEntries.push({
2098
+ ancestorsAndSelf: [
2099
+ {
2100
+ type: "slot",
2101
+ node: enqueueingComponent,
2102
+ parentSlot: slotKey,
2103
+ parentSlotIndexFn
2104
+ },
2105
+ ...currentQueueEntry.ancestorsAndSelf
2106
+ ],
2107
+ context: descendantContext
2108
+ });
2109
+ }
2110
+ }
2111
+ }
2112
+ if (order === "dfs") {
2113
+ childEntries.reverse();
2114
+ }
2115
+ componentQueue.push(...childEntries);
1970
2116
  } while (componentQueue.length > 0);
1971
2117
  }
1972
2118
  function isNestedNodeType(type) {
@@ -2078,11 +2224,34 @@ var stringOperatorEvaluators = {
2078
2224
  endswith: endsWithEvaluator,
2079
2225
  empty: emptyEvaluator
2080
2226
  };
2227
+ var numericOperatorEvaluators = {
2228
+ gt: (left, right) => left > right,
2229
+ lt: (left, right) => left < right
2230
+ };
2231
+ function evaluateNumericOperator(criteria, matchValue) {
2232
+ const { op, value } = criteria;
2233
+ const evaluator = numericOperatorEvaluators[op];
2234
+ if (!evaluator) {
2235
+ return null;
2236
+ }
2237
+ if (typeof matchValue === "string" && matchValue.trim() === "" || typeof value === "string" && value.trim() === "") {
2238
+ return false;
2239
+ }
2240
+ const leftNum = Number(matchValue);
2241
+ const rightNum = Number(value);
2242
+ if (isNaN(leftNum) || isNaN(rightNum)) {
2243
+ return false;
2244
+ }
2245
+ return evaluator(leftNum, rightNum);
2246
+ }
2081
2247
  function evaluateStringMatch(criteria, matchValue, allow) {
2082
2248
  const { op, value } = criteria;
2083
2249
  if (allow && !allow.has(op)) {
2084
2250
  return null;
2085
2251
  }
2252
+ if (op in numericOperatorEvaluators) {
2253
+ return evaluateNumericOperator(criteria, matchValue);
2254
+ }
2086
2255
  let opMatch = op;
2087
2256
  const negation = op.startsWith("!");
2088
2257
  if (negation) {
@@ -2159,6 +2328,7 @@ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2
2159
2328
  _baseUrl = /* @__PURE__ */ new WeakMap();
2160
2329
  __privateAdd3(_IntegrationPropertyEditorsClient, _baseUrl, "/api/v1/integration-property-editors");
2161
2330
  var _url22;
2331
+ var _projectsUrl;
2162
2332
  var _ProjectClient = class _ProjectClient2 extends ApiClient {
2163
2333
  constructor(options) {
2164
2334
  super({ ...options, bypassCache: true });
@@ -2168,6 +2338,15 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
2168
2338
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22), { ...options });
2169
2339
  return await this.apiClient(fetchUri);
2170
2340
  }
2341
+ /**
2342
+ * Fetches projects grouped by team.
2343
+ * When teamId is provided, returns a single team with its projects.
2344
+ * When omitted, returns all accessible teams and their projects.
2345
+ */
2346
+ async getProjects(options) {
2347
+ const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
2348
+ return await this.apiClient(fetchUri);
2349
+ }
2171
2350
  /** Updates or creates (based on id) a Project */
2172
2351
  async upsert(body) {
2173
2352
  const fetchUri = this.createUrl(__privateGet3(_ProjectClient2, _url22));
@@ -2187,7 +2366,9 @@ var _ProjectClient = class _ProjectClient2 extends ApiClient {
2187
2366
  }
2188
2367
  };
2189
2368
  _url22 = /* @__PURE__ */ new WeakMap();
2369
+ _projectsUrl = /* @__PURE__ */ new WeakMap();
2190
2370
  __privateAdd3(_ProjectClient, _url22, "/api/v1/project");
2371
+ __privateAdd3(_ProjectClient, _projectsUrl, "/api/v1/projects");
2191
2372
  var ROUTE_URL = "/api/v1/route";
2192
2373
  var RouteClient = class extends ApiClient {
2193
2374
  constructor(options) {
@@ -2201,7 +2382,9 @@ var RouteClient = class extends ApiClient {
2201
2382
  /** Fetches lists of Canvas compositions, optionally by type */
2202
2383
  async getRoute(options) {
2203
2384
  const { projectId } = this.options;
2204
- const fetchUri = this.createUrl(ROUTE_URL, { ...options, projectId }, this.edgeApiHost);
2385
+ const { select, ...rest } = options != null ? options : {};
2386
+ const rewrittenSelect = projectionToQuery(select);
2387
+ const fetchUri = this.createUrl(ROUTE_URL, { ...rest, projectId, ...rewrittenSelect }, this.edgeApiHost);
2205
2388
  return await this.apiClient(
2206
2389
  fetchUri,
2207
2390
  this.options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0
@@ -2303,8 +2486,15 @@ var isIncontextEditingEnabled = ({
2303
2486
  var isDevelopmentEnvironment = () => {
2304
2487
  return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
2305
2488
  };
2489
+ var shouldIgnoreRedirects = ({ state }) => {
2490
+ const isNotPublished = state !== CANVAS_PUBLISHED_STATE;
2491
+ return isNotPublished ? true : void 0;
2492
+ };
2306
2493
 
2307
2494
  // src/clients/cache.ts
2495
+ var isSpecificCacheMode = (options) => {
2496
+ return "cache" in options;
2497
+ };
2308
2498
  var isStateCacheMode = (options) => {
2309
2499
  return "state" in options;
2310
2500
  };
@@ -2326,7 +2516,9 @@ var resolveCache = ({
2326
2516
  }) => {
2327
2517
  let cache = void 0;
2328
2518
  if (options) {
2329
- if (isStateCacheMode(options)) {
2519
+ if (isSpecificCacheMode(options)) {
2520
+ cache = options.cache;
2521
+ } else if (isStateCacheMode(options)) {
2330
2522
  if (options.state === CANVAS_DRAFT_STATE || options.state === CANVAS_EDITOR_STATE) {
2331
2523
  cache = {
2332
2524
  type: "no-cache",
@@ -2445,7 +2637,7 @@ function createLimiter(concurrency) {
2445
2637
  });
2446
2638
  };
2447
2639
  }
2448
- async function retry(fn, options) {
2640
+ async function retry2(fn, options) {
2449
2641
  let lastError;
2450
2642
  let delay = 1e3;
2451
2643
  for (let attempt = 1; attempt <= options.retries + 1; attempt++) {
@@ -2485,7 +2677,7 @@ function createLimitPolicy2({
2485
2677
  }
2486
2678
  if (retryOptions) {
2487
2679
  const retryFunc = currentFunc;
2488
- currentFunc = () => retry(retryFunc, {
2680
+ currentFunc = () => retry2(retryFunc, {
2489
2681
  ...retryOptions,
2490
2682
  onFailedAttempt: async (error) => {
2491
2683
  if (retryOptions.onFailedAttempt) {
@@ -2573,6 +2765,9 @@ var getQuirkSerialization = () => {
2573
2765
  return true;
2574
2766
  };
2575
2767
  var getMiddlewareRuntimeCache = () => {
2768
+ if (process.env.NODE_ENV === "development" && !process.env.RUNTIME_CACHE_ENDPOINT) {
2769
+ return false;
2770
+ }
2576
2771
  if (typeof config.middlewareRuntimeCache === "boolean") {
2577
2772
  return config.middlewareRuntimeCache;
2578
2773
  }
@@ -2718,7 +2913,10 @@ var DefaultDataClient = class {
2718
2913
  }
2719
2914
  }
2720
2915
  const manifest = await getManifest({
2721
- cache: {
2916
+ cache: isDevelopmentEnvironment() ? {
2917
+ type: "no-cache",
2918
+ bypassCache: true
2919
+ } : {
2722
2920
  type: "force-cache"
2723
2921
  }
2724
2922
  });
@@ -2821,20 +3019,23 @@ var DefaultDataClient = class {
2821
3019
  };
2822
3020
  }
2823
3021
  async getRoutePageState(options) {
3022
+ const shouldBypassCache = options.pageState.compositionState !== CANVAS_PUBLISHED_STATE || isDevelopmentEnvironment();
2824
3023
  const routeClient = getRouteClient({
2825
- cache: options.pageState.compositionState === CANVAS_PUBLISHED_STATE ? {
2826
- type: "force-cache"
2827
- } : {
3024
+ cache: shouldBypassCache ? {
2828
3025
  type: "no-cache",
2829
3026
  bypassCache: true
3027
+ } : {
3028
+ type: "force-cache"
2830
3029
  }
2831
3030
  });
2832
3031
  const originalRoute = {
2833
3032
  path: options.pageState.routePath,
2834
3033
  state: options.pageState.compositionState,
3034
+ dataSourceVariant: getDataSourceVariantFromRouteGetParams({}, options.pageState.compositionState),
2835
3035
  withComponentIDs: true,
2836
3036
  releaseId: options.pageState.releaseId,
2837
- locale: options.pageState.locale
3037
+ locale: options.pageState.locale,
3038
+ ignoreRedirects: shouldIgnoreRedirects({ state: options.pageState.compositionState })
2838
3039
  };
2839
3040
  const resolvedRoute = await this.getRouteFromApi({
2840
3041
  source: "pageState",
@@ -3013,7 +3214,8 @@ import {
3013
3214
  var evaluateRunnables = async ({
3014
3215
  runnables,
3015
3216
  context,
3016
- compositionContext
3217
+ compositionContext,
3218
+ isPrefetch
3017
3219
  }) => {
3018
3220
  var _a;
3019
3221
  const result = {
@@ -3023,6 +3225,9 @@ var evaluateRunnables = async ({
3023
3225
  const runnablesToProcess = runnables.filter((item2) => item2.variantId === void 0);
3024
3226
  let item;
3025
3227
  while (item = runnablesToProcess.shift()) {
3228
+ if (item.type === "test" && isPrefetch) {
3229
+ continue;
3230
+ }
3026
3231
  if (item.type === "test") {
3027
3232
  const testResult = evaluateTest({
3028
3233
  context,
@@ -3096,11 +3301,12 @@ function dequal(foo, bar) {
3096
3301
  return foo !== foo && bar !== bar;
3097
3302
  }
3098
3303
 
3099
- // ../../node_modules/.pnpm/js-cookie@3.0.5/node_modules/js-cookie/dist/js.cookie.mjs
3304
+ // ../../node_modules/.pnpm/js-cookie@3.0.8/node_modules/js-cookie/dist/js.cookie.mjs
3100
3305
  function assign(target) {
3101
3306
  for (var i = 1; i < arguments.length; i++) {
3102
3307
  var source = arguments[i];
3103
3308
  for (var key in source) {
3309
+ if (key === "__proto__") continue;
3104
3310
  target[key] = source[key];
3105
3311
  }
3106
3312
  }
@@ -3157,11 +3363,11 @@ function init(converter, defaultAttributes) {
3157
3363
  var value = parts.slice(1).join("=");
3158
3364
  try {
3159
3365
  var found = decodeURIComponent(parts[0]);
3160
- jar[found] = converter.read(value, found);
3366
+ if (!(found in jar)) jar[found] = converter.read(value, found);
3161
3367
  if (name === found) {
3162
3368
  break;
3163
3369
  }
3164
- } catch (e) {
3370
+ } catch (_e) {
3165
3371
  }
3166
3372
  }
3167
3373
  return name ? jar[name] : jar;
@@ -3216,12 +3422,12 @@ function mitt_default(n) {
3216
3422
  var import_rfdc = __toESM(require_rfdc(), 1);
3217
3423
  var import_rfdc2 = __toESM(require_rfdc(), 1);
3218
3424
  var import_rfdc3 = __toESM(require_rfdc(), 1);
3219
- var __defProp4 = Object.defineProperty;
3425
+ var __defProp3 = Object.defineProperty;
3220
3426
  var __typeError4 = (msg) => {
3221
3427
  throw TypeError(msg);
3222
3428
  };
3223
- var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3224
- var __publicField2 = (obj, key, value) => __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
3429
+ var __defNormalProp3 = (obj, key, value) => key in obj ? __defProp3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3430
+ var __publicField3 = (obj, key, value) => __defNormalProp3(obj, typeof key !== "symbol" ? key + "" : key, value);
3225
3431
  var __accessCheck4 = (obj, member, msg) => member.has(obj) || __typeError4("Cannot " + msg);
3226
3432
  var __privateGet4 = (obj, member, getter) => (__accessCheck4(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
3227
3433
  var __privateAdd4 = (obj, member, value) => member.has(obj) ? __typeError4("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
@@ -3298,7 +3504,7 @@ var SignalInstance = class {
3298
3504
  constructor(data, evaluator, onLogMessage) {
3299
3505
  __privateAdd4(this, _evaluator);
3300
3506
  __privateAdd4(this, _onLogMessage);
3301
- __publicField2(this, "signal");
3507
+ __publicField3(this, "signal");
3302
3508
  this.signal = data;
3303
3509
  __privateSet2(this, _evaluator, evaluator);
3304
3510
  __privateSet2(this, _onLogMessage, onLogMessage);
@@ -3353,11 +3559,10 @@ var ManifestInstance = class {
3353
3559
  constructor({
3354
3560
  manifest,
3355
3561
  evaluator = new GroupCriteriaEvaluator({}),
3356
- // eslint-disable-next-line @typescript-eslint/no-empty-function
3357
3562
  onLogMessage = () => {
3358
3563
  }
3359
3564
  }) {
3360
- __publicField2(this, "data");
3565
+ __publicField3(this, "data");
3361
3566
  __privateAdd4(this, _mf);
3362
3567
  __privateAdd4(this, _signalInstances);
3363
3568
  __privateAdd4(this, _goalEvaluators, []);
@@ -4144,7 +4349,7 @@ var TransitionDataStore = class {
4144
4349
  __privateAdd4(this, _data);
4145
4350
  __privateAdd4(this, _initialData);
4146
4351
  __privateAdd4(this, _mitt, mitt_default());
4147
- __publicField2(this, "events", {
4352
+ __publicField3(this, "events", {
4148
4353
  on: __privateGet4(this, _mitt).on,
4149
4354
  off: __privateGet4(this, _mitt).off
4150
4355
  });
@@ -4507,10 +4712,10 @@ var _LocalStorage_instances;
4507
4712
  var key_fn;
4508
4713
  var LocalStorage = class {
4509
4714
  constructor(partitionKey) {
4510
- this.partitionKey = partitionKey;
4715
+ __publicField3(this, "partitionKey", partitionKey);
4511
4716
  __privateAdd4(this, _LocalStorage_instances);
4512
- __publicField2(this, "inMemoryFallback", {});
4513
- __publicField2(this, "hasLocalStorageObject", typeof document !== "undefined" && typeof localStorage !== "undefined");
4717
+ __publicField3(this, "inMemoryFallback", {});
4718
+ __publicField3(this, "hasLocalStorageObject", typeof document !== "undefined" && typeof localStorage !== "undefined");
4514
4719
  }
4515
4720
  get(key) {
4516
4721
  const keyValue = __privateMethod(this, _LocalStorage_instances, key_fn).call(this, key);
@@ -4571,7 +4776,7 @@ var VisitorDataStore = class {
4571
4776
  __privateAdd4(this, _persist);
4572
4777
  __privateAdd4(this, _visitTimeout);
4573
4778
  __privateAdd4(this, _options);
4574
- __publicField2(this, "events", {
4779
+ __publicField3(this, "events", {
4575
4780
  on: __privateGet4(this, _mitt2).on,
4576
4781
  off: __privateGet4(this, _mitt2).off
4577
4782
  });
@@ -4772,7 +4977,7 @@ var calculateScores_fn;
4772
4977
  var Context = class {
4773
4978
  constructor(options) {
4774
4979
  __privateAdd4(this, _Context_instances);
4775
- __publicField2(this, "manifest");
4980
+ __publicField3(this, "manifest");
4776
4981
  __privateAdd4(this, _personalizationSelectionAlgorithms);
4777
4982
  __privateAdd4(this, _serverTransitionState);
4778
4983
  __privateAdd4(this, _scores, {});
@@ -4782,11 +4987,11 @@ var Context = class {
4782
4987
  __privateAdd4(this, _commands);
4783
4988
  __privateAdd4(this, _requireConsentForPersonalization);
4784
4989
  __privateAdd4(this, _mitt3, mitt_default());
4785
- __publicField2(this, "events", {
4990
+ __publicField3(this, "events", {
4786
4991
  on: __privateGet4(this, _mitt3).on,
4787
4992
  off: __privateGet4(this, _mitt3).off
4788
4993
  });
4789
- __publicField2(this, "storage");
4994
+ __publicField3(this, "storage");
4790
4995
  var _a, _b, _c;
4791
4996
  const { manifest, ...storageOptions } = options;
4792
4997
  __privateSet2(this, _state, {});
@@ -5384,7 +5589,8 @@ var retrieveRouteByPath = async ({
5384
5589
  withComponentIDs: true,
5385
5590
  withContentSourceMap: (_a = getServerConfig().experimental) == null ? void 0 : _a.vercelVisualEditing,
5386
5591
  releaseId,
5387
- locale
5592
+ locale,
5593
+ ignoreRedirects: shouldIgnoreRedirects({ state })
5388
5594
  }
5389
5595
  });
5390
5596
  };
@@ -5511,7 +5717,7 @@ var handlePlaygroundRequest = async ({
5511
5717
  })
5512
5718
  });
5513
5719
  const context = await onDemandContext.getContext();
5514
- const { components, rules } = await extractAndEvaluateRunnables({
5720
+ const { components, rules, allComponentIds } = await extractAndEvaluateRunnables({
5515
5721
  composition: composition.composition,
5516
5722
  routePath: id,
5517
5723
  state: composition.state,
@@ -5528,7 +5734,8 @@ var handlePlaygroundRequest = async ({
5528
5734
  searchParams: request.nextUrl.searchParams,
5529
5735
  isDraftModeEnabled: true
5530
5736
  // this is checked above
5531
- })
5737
+ }),
5738
+ isPrefetch: false
5532
5739
  });
5533
5740
  const pageState = {
5534
5741
  routePath: id,
@@ -5546,10 +5753,12 @@ var handlePlaygroundRequest = async ({
5546
5753
  // this is checked above
5547
5754
  }),
5548
5755
  rules,
5549
- locale: options.locale
5756
+ locale: options.locale,
5757
+ isPrefetch: void 0
5550
5758
  };
5551
5759
  const code = serializeEvaluationResult({
5552
- payload: pageState
5760
+ payload: pageState,
5761
+ allComponentIds
5553
5762
  });
5554
5763
  let pathToRewriteTo = await (options.rewriteDestinationPath ? options.rewriteDestinationPath({ code, pageState, source: "playground" }) : void 0);
5555
5764
  if (!pathToRewriteTo) {
@@ -5563,15 +5772,16 @@ var handleRouteRequest = async ({
5563
5772
  dataClient,
5564
5773
  options
5565
5774
  }) => {
5566
- var _a, _b, _c, _d, _e, _f, _g, _h;
5775
+ var _a, _b, _c, _d, _e, _f, _g;
5776
+ const releaseId = (_b = (_a = options.release) == null ? void 0 : _a.id) != null ? _b : draftModeEnabled ? request.nextUrl.searchParams.get("releaseId") || void 0 : void 0;
5567
5777
  const states = await determineState({
5568
5778
  searchParams: request.nextUrl.searchParams,
5569
5779
  draftModeEnabled
5570
5780
  });
5571
- const requestPath = (_b = await ((_a = options.rewriteRequestPath) == null ? void 0 : _a.call(options, {
5781
+ const requestPath = (_d = await ((_c = options.rewriteRequestPath) == null ? void 0 : _c.call(options, {
5572
5782
  request,
5573
5783
  url: new URL(request.url)
5574
- }))) != null ? _b : {
5784
+ }))) != null ? _d : {
5575
5785
  path: `${request.nextUrl.pathname}${request.nextUrl.search}`
5576
5786
  };
5577
5787
  const serverConfig = getServerConfig();
@@ -5582,7 +5792,7 @@ var handleRouteRequest = async ({
5582
5792
  searchParams: request.nextUrl.searchParams,
5583
5793
  draftModeEnabled,
5584
5794
  dataClient,
5585
- releaseId: (_c = options.release) == null ? void 0 : _c.id,
5795
+ releaseId,
5586
5796
  locale: options.locale
5587
5797
  }),
5588
5798
  createOnDemandContext({
@@ -5594,10 +5804,10 @@ var handleRouteRequest = async ({
5594
5804
  })
5595
5805
  })
5596
5806
  ]);
5597
- if (!(routeResult == null ? void 0 : routeResult.route) || ((_d = routeResult == null ? void 0 : routeResult.route) == null ? void 0 : _d.type) === "notFound") {
5598
- return NextResponse.next();
5807
+ if (!(routeResult == null ? void 0 : routeResult.route) || ((_e = routeResult == null ? void 0 : routeResult.route) == null ? void 0 : _e.type) === "notFound") {
5808
+ return NextResponse.rewrite(new URL("/404", request.url));
5599
5809
  }
5600
- if (((_e = routeResult == null ? void 0 : routeResult.route) == null ? void 0 : _e.type) === "redirect") {
5810
+ if (((_f = routeResult == null ? void 0 : routeResult.route) == null ? void 0 : _f.type) === "redirect") {
5601
5811
  return handleRedirect({ request, route: routeResult.route });
5602
5812
  }
5603
5813
  const { route } = routeResult;
@@ -5630,14 +5840,15 @@ var handleRouteRequest = async ({
5630
5840
  searchParams: request.nextUrl.searchParams,
5631
5841
  isDraftModeEnabled: draftModeEnabled
5632
5842
  });
5633
- const { components, rules } = await extractAndEvaluateRunnables({
5843
+ const isPrefetch = isPrefetchRequest(request);
5844
+ const { components, rules, allComponentIds } = await extractAndEvaluateRunnables({
5634
5845
  composition: route.compositionApiResponse.composition,
5635
5846
  routePath,
5636
5847
  state,
5637
5848
  context,
5638
5849
  matchedRoute: route.matchedRoute,
5639
- dynamicInputs: (_f = route.dynamicInputs) != null ? _f : {},
5640
- releaseId: (_g = options.release) == null ? void 0 : _g.id,
5850
+ dynamicInputs: (_g = route.dynamicInputs) != null ? _g : {},
5851
+ releaseId,
5641
5852
  defaultConsent: determineDefaultConsent({
5642
5853
  serverConfig,
5643
5854
  defaultConsent: options.defaultConsent
@@ -5647,24 +5858,27 @@ var handleRouteRequest = async ({
5647
5858
  searchParams: request.nextUrl.searchParams,
5648
5859
  isDraftModeEnabled: true
5649
5860
  // this is checked above
5650
- })
5861
+ }),
5862
+ isPrefetch
5651
5863
  });
5652
5864
  const pageState = {
5653
5865
  routePath,
5654
5866
  compositionState: state,
5655
5867
  components,
5656
5868
  keys: requestPath.keys,
5657
- releaseId: (_h = options.release) == null ? void 0 : _h.id,
5869
+ releaseId,
5658
5870
  defaultConsent: determineDefaultConsent({
5659
5871
  serverConfig,
5660
5872
  defaultConsent: options.defaultConsent
5661
5873
  }),
5662
5874
  previewMode,
5663
5875
  rules,
5664
- locale: options.locale
5876
+ locale: options.locale,
5877
+ isPrefetch: isPrefetch || void 0
5665
5878
  };
5666
5879
  const code = serializeEvaluationResult({
5667
- payload: pageState
5880
+ payload: pageState,
5881
+ allComponentIds
5668
5882
  });
5669
5883
  let pathToRewriteTo = await (options.rewriteDestinationPath ? options.rewriteDestinationPath({ code, pageState, source: "route" }) : void 0);
5670
5884
  if (!pathToRewriteTo) {
@@ -5681,6 +5895,9 @@ var handleRouteRequest = async ({
5681
5895
  headers
5682
5896
  });
5683
5897
  };
5898
+ var isPrefetchRequest = (request) => {
5899
+ return request.headers.has("next-url");
5900
+ };
5684
5901
  var extractAndEvaluateRunnables = async ({
5685
5902
  composition,
5686
5903
  routePath,
@@ -5691,12 +5908,14 @@ var extractAndEvaluateRunnables = async ({
5691
5908
  releaseId,
5692
5909
  defaultConsent,
5693
5910
  keys,
5694
- previewMode
5911
+ previewMode,
5912
+ isPrefetch
5695
5913
  }) => {
5696
5914
  const extracted = extractRunnables(composition);
5697
5915
  const result = await evaluateRunnables({
5698
5916
  runnables: extracted,
5699
5917
  context,
5918
+ isPrefetch,
5700
5919
  compositionContext: {
5701
5920
  _id: composition._id,
5702
5921
  type: composition.type,
@@ -5714,11 +5933,13 @@ var extractAndEvaluateRunnables = async ({
5714
5933
  defaultConsent,
5715
5934
  previewMode,
5716
5935
  rules: void 0,
5717
- locale: void 0
5936
+ locale: void 0,
5937
+ isPrefetch: isPrefetch || void 0
5718
5938
  }
5719
5939
  }
5720
5940
  });
5721
- return result;
5941
+ const allComponentIds = extracted.filter((r) => r.type === "test" || r.type === "personalization").map((r) => r._id);
5942
+ return { ...result, allComponentIds };
5722
5943
  };
5723
5944
  var handleRedirect = ({ request, route }) => {
5724
5945
  const href = resolveRedirectHref({
@@ -5816,5 +6037,5 @@ export {
5816
6037
  /*! Bundled license information:
5817
6038
 
5818
6039
  js-cookie/dist/js.cookie.mjs:
5819
- (*! js-cookie v3.0.5 | MIT *)
6040
+ (*! js-cookie v3.0.8 | MIT *)
5820
6041
  */