@uniformdev/next-app-router 20.81.0 → 20.81.1-alpha.7.sha-91a5b13e0c

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.
Files changed (46) hide show
  1. package/dist/{UniformComposition-DBO-oo7J.d.ts → UniformComposition-C00_YDOg.d.ts} +11 -31
  2. package/dist/{UniformComposition-le6UEB_r.d.mts → UniformComposition-DiArCpVQ.d.mts} +11 -31
  3. package/dist/cache.d.mts +24 -6
  4. package/dist/cache.d.ts +24 -6
  5. package/dist/cache.js +410 -831
  6. package/dist/cache.mjs +405 -829
  7. package/dist/compat.d.mts +2 -4
  8. package/dist/compat.d.ts +2 -4
  9. package/dist/component.d.mts +10 -1
  10. package/dist/component.d.ts +10 -1
  11. package/dist/component.js +113 -617
  12. package/dist/component.mjs +112 -640
  13. package/dist/composition-BvOM-LIW.d.mts +28 -0
  14. package/dist/composition-BvOM-LIW.d.ts +28 -0
  15. package/dist/config/default.js +0 -1
  16. package/dist/config/default.mjs +0 -1
  17. package/dist/createCachedManifestProvider-C7faGJJ8.d.mts +69 -0
  18. package/dist/createCachedManifestProvider-C7faGJJ8.d.ts +69 -0
  19. package/dist/edge.d.mts +57 -0
  20. package/dist/edge.d.ts +57 -0
  21. package/dist/edge.js +1105 -0
  22. package/dist/edge.mjs +1073 -0
  23. package/dist/handler.d.mts +15 -2
  24. package/dist/handler.d.ts +15 -2
  25. package/dist/handler.js +134 -628
  26. package/dist/handler.mjs +132 -626
  27. package/dist/index.d.mts +73 -42
  28. package/dist/index.d.ts +73 -42
  29. package/dist/index.esm.js +2032 -5629
  30. package/dist/index.js +2068 -5661
  31. package/dist/index.mjs +2032 -5629
  32. package/dist/middleware.d.mts +52 -13
  33. package/dist/middleware.d.ts +52 -13
  34. package/dist/middleware.js +410 -5746
  35. package/dist/middleware.mjs +417 -5776
  36. package/dist/resolveRouteFromPath-BHJGOpBN.d.ts +82 -0
  37. package/dist/resolveRouteFromPath-BsZUVkRX.d.mts +82 -0
  38. package/dist/vercel.d.mts +24 -0
  39. package/dist/vercel.d.ts +24 -0
  40. package/dist/vercel.js +703 -0
  41. package/dist/vercel.mjs +675 -0
  42. package/package.json +37 -9
  43. package/dist/client-BElN_CWD.d.mts +0 -786
  44. package/dist/client-BElN_CWD.d.ts +0 -786
  45. package/dist/resolveRouteFromCode-BOvjIvM2.d.ts +0 -18
  46. package/dist/resolveRouteFromCode-CuJ4JHeb.d.mts +0 -18
@@ -0,0 +1,675 @@
1
+ // src/vercel/expireVercelRuntimeCacheTags.ts
2
+ import { getCache } from "@vercel/functions";
3
+
4
+ // src/vercel/isRuntimeCacheAvailable.ts
5
+ var isRuntimeCacheAvailable = () => process.env.NODE_ENV !== "development" || Boolean(process.env.RUNTIME_CACHE_ENDPOINT);
6
+
7
+ // src/vercel/expireVercelRuntimeCacheTags.ts
8
+ var expireVercelRuntimeCacheTags = async (tags) => {
9
+ if (!tags.length || !isRuntimeCacheAvailable()) {
10
+ return;
11
+ }
12
+ await getCache().expireTag(tags);
13
+ };
14
+
15
+ // src/vercel/vercelManifestProvider.ts
16
+ import { getCache as getCache2 } from "@vercel/functions";
17
+
18
+ // src/clients/manifest.ts
19
+ import "server-only";
20
+
21
+ // ../canvas/dist/index.mjs
22
+ import { ApiClient } from "@uniformdev/context/api";
23
+ import { ApiClientError } from "@uniformdev/context/api";
24
+ import { ApiClientError as ApiClientError2 } from "@uniformdev/context/api";
25
+ import { ApiClient as ApiClient2 } from "@uniformdev/context/api";
26
+ import { rewriteFiltersForApi } from "@uniformdev/context/api";
27
+ import { rewriteFiltersForApi as rewriteFiltersForApi2 } from "@uniformdev/context/api";
28
+ import { ApiClientError as ApiClientError3 } from "@uniformdev/context/api";
29
+ import { rewriteFiltersForApi as rewriteFiltersForApi3 } from "@uniformdev/context/api";
30
+ import { ApiClientError as ApiClientError4 } from "@uniformdev/context/api";
31
+ import { rewriteFiltersForApi as rewriteFiltersForApi4 } from "@uniformdev/context/api";
32
+ import { ApiClient as ApiClient3, rewriteFiltersForApi as rewriteFiltersForApi5 } from "@uniformdev/context/api";
33
+ import { ApiClient as ApiClient4, rewriteFiltersForApi as rewriteFiltersForApi6 } from "@uniformdev/context/api";
34
+ import { ApiClient as ApiClient5 } from "@uniformdev/context/api";
35
+ import { ApiClient as ApiClient6 } from "@uniformdev/context/api";
36
+ import { ApiClient as ApiClient7 } from "@uniformdev/context/api";
37
+ import { ApiClient as ApiClient8 } from "@uniformdev/context/api";
38
+ import { ApiClient as ApiClient9 } from "@uniformdev/context/api";
39
+ import { ApiClient as ApiClient10 } from "@uniformdev/context/api";
40
+ import { ApiClient as ApiClient11 } from "@uniformdev/context/api";
41
+ import { ApiClient as ApiClient12 } from "@uniformdev/context/api";
42
+ import { ApiClient as ApiClient13 } from "@uniformdev/context/api";
43
+ import { ApiClient as ApiClient14 } from "@uniformdev/context/api";
44
+ import { ApiClient as ApiClient15 } from "@uniformdev/context/api";
45
+ import { ApiClient as ApiClient16 } from "@uniformdev/context/api";
46
+ import { ApiClient as ApiClient17 } from "@uniformdev/context/api";
47
+ import { ApiClientError as ApiClientError5 } from "@uniformdev/context/api";
48
+ import { ApiClient as ApiClient18 } from "@uniformdev/context/api";
49
+ var __typeError = (msg) => {
50
+ throw TypeError(msg);
51
+ };
52
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
53
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
54
+ 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);
55
+ var SELECT_QUERY_PREFIX = "select.";
56
+ function appendCsv(out, key, values) {
57
+ if (values === void 0) {
58
+ return;
59
+ }
60
+ out[key] = values.join(",");
61
+ }
62
+ function projectionToQuery(spec) {
63
+ const out = {};
64
+ if (!spec) {
65
+ return out;
66
+ }
67
+ const { fields, fieldTypes, slots } = spec;
68
+ const p = SELECT_QUERY_PREFIX;
69
+ if (fields) {
70
+ appendCsv(out, `${p}fields[only]`, fields.only);
71
+ appendCsv(out, `${p}fields[except]`, fields.except);
72
+ appendCsv(out, `${p}fields[locales]`, fields.locales);
73
+ if (fields.blockDepth === "preserveAll" || typeof fields.blockDepth === "number") {
74
+ out[`${p}fields[blockDepth]`] = String(fields.blockDepth);
75
+ }
76
+ }
77
+ if (fieldTypes) {
78
+ appendCsv(out, `${p}fieldTypes[only]`, fieldTypes.only);
79
+ appendCsv(out, `${p}fieldTypes[except]`, fieldTypes.except);
80
+ }
81
+ if (slots) {
82
+ appendCsv(out, `${p}slots[only]`, slots.only);
83
+ appendCsv(out, `${p}slots[except]`, slots.except);
84
+ if (typeof slots.depth === "number") {
85
+ out[`${p}slots[depth]`] = String(slots.depth);
86
+ }
87
+ if (slots.named) {
88
+ const slotNames = Object.keys(slots.named).sort();
89
+ for (const slotName of slotNames) {
90
+ const named = slots.named[slotName];
91
+ if (named && typeof named.depth === "number") {
92
+ out[`${p}slots.${slotName}[depth]`] = String(named.depth);
93
+ }
94
+ }
95
+ }
96
+ }
97
+ return out;
98
+ }
99
+ var CANVAS_DRAFT_STATE = 0;
100
+ var CANVAS_EDITOR_STATE = 63;
101
+ var CANVAS_INTERNAL_PARAM_PREFIX = "$internal_";
102
+ var CANVAS_COMPONENT_DISPLAY_NAME_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}displayName`;
103
+ var CANVAS_HYPOTHESIS_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}hypothesis`;
104
+ var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
105
+ var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
106
+ var _contentTypesUrl;
107
+ var _entriesUrl;
108
+ var _ContentClient = class _ContentClient2 extends ApiClient4 {
109
+ constructor(options) {
110
+ var _a;
111
+ super(options);
112
+ this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
113
+ }
114
+ getContentTypes(options) {
115
+ const { projectId } = this.options;
116
+ const fetchUri = this.createUrl(__privateGet(_ContentClient2, _contentTypesUrl), { ...options, projectId });
117
+ return this.apiClient(fetchUri);
118
+ }
119
+ getEntries(options) {
120
+ const { projectId } = this.options;
121
+ const { skipDataResolution, filters, select, ...params } = options;
122
+ const rewrittenFilters = rewriteFiltersForApi6(filters);
123
+ const rewrittenSelect = projectionToQuery(select);
124
+ if (skipDataResolution) {
125
+ const url = this.createUrl(__privateGet(_ContentClient2, _entriesUrl), {
126
+ ...params,
127
+ ...rewrittenFilters,
128
+ ...rewrittenSelect,
129
+ projectId
130
+ });
131
+ return this.apiClient(url);
132
+ }
133
+ const edgeUrl = this.createUrl(
134
+ __privateGet(_ContentClient2, _entriesUrl),
135
+ { ...this.getEdgeOptions(params), ...rewrittenFilters, ...rewrittenSelect },
136
+ this.edgeApiHost
137
+ );
138
+ return this.apiClient(
139
+ edgeUrl,
140
+ this.options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0
141
+ );
142
+ }
143
+ /** Fetches historical versions of an entry */
144
+ async getEntryHistory(options) {
145
+ const historyUrl = this.createUrl("/api/v1/entries-history", {
146
+ ...options,
147
+ projectId: this.options.projectId
148
+ });
149
+ return this.apiClient(historyUrl);
150
+ }
151
+ async upsertContentType(body, opts = {}) {
152
+ const fetchUri = this.createUrl(__privateGet(_ContentClient2, _contentTypesUrl));
153
+ if (typeof body.contentType.slugSettings === "object" && body.contentType.slugSettings !== null && Object.keys(body.contentType.slugSettings).length === 0) {
154
+ delete body.contentType.slugSettings;
155
+ }
156
+ await this.apiClient(fetchUri, {
157
+ method: "PUT",
158
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
159
+ expectNoContent: true,
160
+ headers: opts.autogenerateDataTypes ? { "x-uniform-autogenerate-data-types": "true" } : {}
161
+ });
162
+ }
163
+ async upsertEntry(body, options) {
164
+ const fetchUri = this.createUrl(__privateGet(_ContentClient2, _entriesUrl));
165
+ const headers = {};
166
+ if (options == null ? void 0 : options.ifUnmodifiedSince) {
167
+ headers["x-if-unmodified-since"] = options.ifUnmodifiedSince;
168
+ }
169
+ const { response } = await this.apiClientWithResponse(fetchUri, {
170
+ method: "PUT",
171
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
172
+ expectNoContent: true,
173
+ headers
174
+ });
175
+ return { modified: response.headers.get("x-modified-at") };
176
+ }
177
+ async deleteContentType(body) {
178
+ const fetchUri = this.createUrl(__privateGet(_ContentClient2, _contentTypesUrl));
179
+ await this.apiClient(fetchUri, {
180
+ method: "DELETE",
181
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
182
+ expectNoContent: true
183
+ });
184
+ }
185
+ async deleteEntry(body) {
186
+ const fetchUri = this.createUrl(__privateGet(_ContentClient2, _entriesUrl));
187
+ await this.apiClient(fetchUri, {
188
+ method: "DELETE",
189
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
190
+ expectNoContent: true
191
+ });
192
+ }
193
+ getEdgeOptions(options) {
194
+ const { projectId } = this.options;
195
+ const { skipDataResolution, ...params } = options;
196
+ return {
197
+ projectId,
198
+ ...params,
199
+ diagnostics: typeof options.diagnostics === "boolean" ? options.diagnostics : options.diagnostics === "no-data" ? "no-data" : void 0
200
+ };
201
+ }
202
+ };
203
+ _contentTypesUrl = /* @__PURE__ */ new WeakMap();
204
+ _entriesUrl = /* @__PURE__ */ new WeakMap();
205
+ __privateAdd(_ContentClient, _contentTypesUrl, "/api/v1/content-types");
206
+ __privateAdd(_ContentClient, _entriesUrl, "/api/v1/entries");
207
+ var _url;
208
+ var _DataTypeClient = class _DataTypeClient2 extends ApiClient6 {
209
+ constructor(options) {
210
+ super(options);
211
+ }
212
+ /** Fetches a list of DataTypes for a project */
213
+ async list(options) {
214
+ const { projectId } = this.options;
215
+ const fetchUri = this.createUrl(__privateGet(_DataTypeClient2, _url), { ...options, projectId });
216
+ return await this.apiClient(fetchUri);
217
+ }
218
+ /** @deprecated Use {@link list} instead. */
219
+ async get(options) {
220
+ return this.list(options);
221
+ }
222
+ /** Updates or creates (based on id) a DataType */
223
+ async save(body) {
224
+ const fetchUri = this.createUrl(__privateGet(_DataTypeClient2, _url));
225
+ await this.apiClient(fetchUri, {
226
+ method: "PUT",
227
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
228
+ expectNoContent: true
229
+ });
230
+ }
231
+ /** @deprecated Use {@link save} instead. */
232
+ async upsert(body) {
233
+ return this.save(body);
234
+ }
235
+ /** Deletes a DataType */
236
+ async remove(body) {
237
+ const fetchUri = this.createUrl(__privateGet(_DataTypeClient2, _url));
238
+ await this.apiClient(fetchUri, {
239
+ method: "DELETE",
240
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
241
+ expectNoContent: true
242
+ });
243
+ }
244
+ };
245
+ _url = /* @__PURE__ */ new WeakMap();
246
+ __privateAdd(_DataTypeClient, _url, "/api/v1/data-types");
247
+ var _baseUrl;
248
+ var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2 extends ApiClient8 {
249
+ constructor(options) {
250
+ super(options);
251
+ this.teamId = options.teamId;
252
+ }
253
+ /**
254
+ * Gets a list of property type and hook names for the current team, including public integrations' hooks.
255
+ */
256
+ get(options) {
257
+ const fetchUri = this.createUrl(__privateGet(_IntegrationPropertyEditorsClient2, _baseUrl), {
258
+ ...options,
259
+ teamId: this.teamId
260
+ });
261
+ return this.apiClient(fetchUri);
262
+ }
263
+ /**
264
+ * Creates or updates a custom AI property editor on a Mesh app.
265
+ */
266
+ async deploy(body) {
267
+ const fetchUri = this.createUrl(__privateGet(_IntegrationPropertyEditorsClient2, _baseUrl));
268
+ await this.apiClient(fetchUri, {
269
+ method: "PUT",
270
+ body: JSON.stringify({ ...body, teamId: this.teamId }),
271
+ expectNoContent: true
272
+ });
273
+ }
274
+ /**
275
+ * Removes a custom AI property editor from a Mesh app.
276
+ */
277
+ async delete(body) {
278
+ const fetchUri = this.createUrl(__privateGet(_IntegrationPropertyEditorsClient2, _baseUrl));
279
+ await this.apiClient(fetchUri, {
280
+ method: "DELETE",
281
+ body: JSON.stringify({ ...body, teamId: this.teamId }),
282
+ expectNoContent: true
283
+ });
284
+ }
285
+ };
286
+ _baseUrl = /* @__PURE__ */ new WeakMap();
287
+ __privateAdd(_IntegrationPropertyEditorsClient, _baseUrl, "/api/v1/integration-property-editors");
288
+ var _url2;
289
+ var _projectsUrl;
290
+ var _ProjectClient = class _ProjectClient2 extends ApiClient12 {
291
+ constructor(options) {
292
+ super({ ...options, bypassCache: true });
293
+ }
294
+ /** Fetches single Project */
295
+ async get(options) {
296
+ const fetchUri = this.createUrl(__privateGet(_ProjectClient2, _url2), { ...options });
297
+ return await this.apiClient(fetchUri);
298
+ }
299
+ /**
300
+ * Fetches projects grouped by team.
301
+ * When teamId is provided, returns a single team with its projects.
302
+ * When omitted, returns all accessible teams and their projects.
303
+ */
304
+ async list(options) {
305
+ const fetchUri = this.createUrl(__privateGet(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
306
+ return await this.apiClient(fetchUri);
307
+ }
308
+ /** @deprecated Use {@link list} instead. */
309
+ async getProjects(options) {
310
+ return this.list(options);
311
+ }
312
+ /** Updates or creates (based on id) a Project */
313
+ async save(body) {
314
+ const fetchUri = this.createUrl(__privateGet(_ProjectClient2, _url2));
315
+ return await this.apiClient(fetchUri, {
316
+ method: "PUT",
317
+ body: JSON.stringify({ ...body })
318
+ });
319
+ }
320
+ /** @deprecated Use {@link save} instead. */
321
+ async upsert(body) {
322
+ return this.save(body);
323
+ }
324
+ /** Deletes a Project */
325
+ async remove(body) {
326
+ const fetchUri = this.createUrl(__privateGet(_ProjectClient2, _url2));
327
+ await this.apiClient(fetchUri, {
328
+ method: "DELETE",
329
+ body: JSON.stringify({ ...body }),
330
+ expectNoContent: true
331
+ });
332
+ }
333
+ /** @deprecated Use {@link remove} instead. */
334
+ async delete(body) {
335
+ return this.remove(body);
336
+ }
337
+ };
338
+ _url2 = /* @__PURE__ */ new WeakMap();
339
+ _projectsUrl = /* @__PURE__ */ new WeakMap();
340
+ __privateAdd(_ProjectClient, _url2, "/api/v1/project");
341
+ __privateAdd(_ProjectClient, _projectsUrl, "/api/v1/projects");
342
+
343
+ // src/clients/manifest.ts
344
+ import { ManifestClient } from "@uniformdev/context/api";
345
+
346
+ // src/utils/env.ts
347
+ var env = {
348
+ getProjectId: () => {
349
+ return process.env.UNIFORM_PROJECT_ID;
350
+ },
351
+ getApiKey: () => {
352
+ return process.env.UNIFORM_API_KEY;
353
+ },
354
+ getApiHost: () => {
355
+ return process.env.UNIFORM_API_HOST || process.env.UNIFORM_CLI_BASE_URL;
356
+ },
357
+ getEdgeApiHost: () => {
358
+ return process.env.UNIFORM_EDGE_API_HOST || process.env.UNIFORM_CLI_BASE_EDGE_URL;
359
+ }
360
+ };
361
+
362
+ // src/utils/draft.ts
363
+ var isDraftModeEnabled = ({
364
+ draftModeEnabled
365
+ }) => {
366
+ return draftModeEnabled;
367
+ };
368
+ var isIncontextEditingEnabled = ({
369
+ isDraftModeEnabled: isDraftModeEnabled2,
370
+ searchParams
371
+ }) => {
372
+ if (!isDraftModeEnabled2) {
373
+ return false;
374
+ }
375
+ const containsKey = searchParams.has(IN_CONTEXT_EDITOR_QUERY_STRING_PARAM);
376
+ return containsKey;
377
+ };
378
+ var isDevelopmentEnvironment = () => {
379
+ return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
380
+ };
381
+
382
+ // src/clients/cache.ts
383
+ var isSpecificCacheMode = (options) => {
384
+ return "cache" in options;
385
+ };
386
+ var isStateCacheMode = (options) => {
387
+ return "state" in options;
388
+ };
389
+ var isDetectCacheMode = (options) => {
390
+ return "searchParams" in options && "draftModeEnabled" in options;
391
+ };
392
+ var resolveManifestCache = (options) => {
393
+ return resolveCache({
394
+ options
395
+ });
396
+ };
397
+ var resolveCache = ({
398
+ options
399
+ }) => {
400
+ let cache = void 0;
401
+ if (options) {
402
+ if (isSpecificCacheMode(options)) {
403
+ cache = options.cache;
404
+ } else if (isStateCacheMode(options)) {
405
+ if (options.state === CANVAS_DRAFT_STATE || options.state === CANVAS_EDITOR_STATE) {
406
+ cache = {
407
+ type: "no-cache",
408
+ bypassCache: true
409
+ };
410
+ }
411
+ } else if (isDetectCacheMode(options)) {
412
+ const { disabled } = shouldCacheBeDisabled(options);
413
+ if (disabled) {
414
+ cache = {
415
+ type: "no-cache",
416
+ bypassCache: true
417
+ };
418
+ }
419
+ }
420
+ }
421
+ return cache || {
422
+ type: "force-cache"
423
+ };
424
+ };
425
+ var shouldCacheBeDisabled = (options) => {
426
+ if (isDraftModeEnabled(options)) {
427
+ return { disabled: true, reason: "DRAFT" };
428
+ }
429
+ if (isIncontextEditingEnabled({
430
+ isDraftModeEnabled: options.draftModeEnabled,
431
+ searchParams: options.searchParams
432
+ })) {
433
+ return { disabled: true, reason: "INCONTEXT" };
434
+ }
435
+ if (isDevelopmentEnvironment()) {
436
+ return { disabled: true, reason: "DEV" };
437
+ }
438
+ return {
439
+ disabled: false,
440
+ reason: void 0
441
+ };
442
+ };
443
+ var determineFetchCacheOptions = (mode) => {
444
+ let cache = void 0;
445
+ let revalidate = void 0;
446
+ if (mode.type === "revalidate") {
447
+ cache = void 0;
448
+ revalidate = mode.interval;
449
+ } else {
450
+ cache = mode.type;
451
+ }
452
+ return {
453
+ cache,
454
+ revalidate
455
+ };
456
+ };
457
+
458
+ // src/clients/retry.ts
459
+ import { ApiClientError as ApiClientError6 } from "@uniformdev/context/api";
460
+ function createThrottler(limit, interval) {
461
+ let available = limit;
462
+ let refillScheduled = false;
463
+ const waiting = [];
464
+ function scheduleRefill() {
465
+ if (refillScheduled) return;
466
+ refillScheduled = true;
467
+ setTimeout(() => {
468
+ refillScheduled = false;
469
+ available = limit;
470
+ while (available > 0 && waiting.length > 0) {
471
+ available--;
472
+ const next = waiting.shift();
473
+ next();
474
+ }
475
+ if (waiting.length > 0) {
476
+ scheduleRefill();
477
+ }
478
+ }, interval);
479
+ }
480
+ return async function throttle(fn) {
481
+ if (available > 0) {
482
+ available--;
483
+ if (!refillScheduled) {
484
+ scheduleRefill();
485
+ }
486
+ return fn();
487
+ }
488
+ return new Promise((resolve, reject) => {
489
+ waiting.push(() => {
490
+ fn().then(resolve, reject);
491
+ });
492
+ scheduleRefill();
493
+ });
494
+ };
495
+ }
496
+ function createLimiter(concurrency) {
497
+ let active = 0;
498
+ const queue = [];
499
+ return async function limit(fn) {
500
+ return new Promise((resolve, reject) => {
501
+ const run = async () => {
502
+ active++;
503
+ try {
504
+ const result = await fn();
505
+ resolve(result);
506
+ } catch (error) {
507
+ reject(error);
508
+ } finally {
509
+ active--;
510
+ if (queue.length > 0) {
511
+ const next = queue.shift();
512
+ next();
513
+ }
514
+ }
515
+ };
516
+ if (active < concurrency) {
517
+ run();
518
+ } else {
519
+ queue.push(run);
520
+ }
521
+ });
522
+ };
523
+ }
524
+ async function retry(fn, options) {
525
+ let lastError;
526
+ let delay = 1e3;
527
+ for (let attempt = 1; attempt <= options.retries + 1; attempt++) {
528
+ try {
529
+ return await fn();
530
+ } catch (error) {
531
+ lastError = error;
532
+ const attemptError = Object.assign(error, { attemptNumber: attempt });
533
+ if (options.onFailedAttempt) {
534
+ await options.onFailedAttempt(attemptError);
535
+ }
536
+ if (attempt > options.retries) {
537
+ throw error;
538
+ }
539
+ await new Promise((resolve) => setTimeout(resolve, delay));
540
+ delay *= options.factor;
541
+ }
542
+ }
543
+ throw lastError;
544
+ }
545
+ function createLimitPolicy({
546
+ throttle = { interval: 1e3, limit: 10 },
547
+ retry: retryOptions = { retries: 1, factor: 1.66 },
548
+ limit = 10
549
+ }) {
550
+ const throttler = throttle ? createThrottler(throttle.limit, throttle.interval) : null;
551
+ const limiter = limit ? createLimiter(limit) : null;
552
+ return function limitPolicy(func) {
553
+ let currentFunc = async () => await func();
554
+ if (throttler) {
555
+ const throttleFunc = currentFunc;
556
+ currentFunc = () => throttler(throttleFunc);
557
+ }
558
+ if (limiter) {
559
+ const limitFunc = currentFunc;
560
+ currentFunc = () => limiter(limitFunc);
561
+ }
562
+ if (retryOptions) {
563
+ const retryFunc = currentFunc;
564
+ currentFunc = () => retry(retryFunc, {
565
+ ...retryOptions,
566
+ onFailedAttempt: async (error) => {
567
+ if (retryOptions.onFailedAttempt) {
568
+ await retryOptions.onFailedAttempt(error);
569
+ }
570
+ if (error instanceof ApiClientError6 && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
571
+ throw error;
572
+ }
573
+ }
574
+ });
575
+ }
576
+ return currentFunc();
577
+ };
578
+ }
579
+
580
+ // src/clients/tags.ts
581
+ var generateManifestCacheTags = () => {
582
+ return ["manifest"];
583
+ };
584
+
585
+ // src/clients/manifest.ts
586
+ var getManifestClient = (options) => {
587
+ const cache = resolveManifestCache(options);
588
+ const manifestClient = new ManifestClient({
589
+ apiHost: env.getApiHost(),
590
+ apiKey: env.getApiKey(),
591
+ projectId: env.getProjectId(),
592
+ limitPolicy: createLimitPolicy({
593
+ limit: 6
594
+ }),
595
+ fetch: (req, init) => {
596
+ const { cache: fetchCache, revalidate } = determineFetchCacheOptions(cache);
597
+ return fetch(req, {
598
+ ...init,
599
+ headers: {
600
+ ...init == null ? void 0 : init.headers,
601
+ "x-bypass-cache": typeof cache.bypassCache !== "undefined" ? cache.bypassCache.toString() : "false"
602
+ },
603
+ cache: fetchCache,
604
+ next: {
605
+ revalidate,
606
+ tags: generateManifestCacheTags()
607
+ }
608
+ });
609
+ }
610
+ });
611
+ return manifestClient;
612
+ };
613
+
614
+ // src/manifest/createCachedManifestProvider.ts
615
+ var createCachedManifestProvider = ({
616
+ cache,
617
+ fallback,
618
+ ttl = 3600,
619
+ maxAge = 10,
620
+ fetchManifest = fetchPublishedManifest
621
+ } = {}) => {
622
+ let current;
623
+ let pending;
624
+ const load = async ({ waitUntil }) => {
625
+ var _a;
626
+ const key = `uniform-manifest-${(_a = env.getProjectId()) != null ? _a : ""}`;
627
+ const cached = await (cache == null ? void 0 : cache.get(key).catch(() => void 0));
628
+ if (isManifest(cached)) {
629
+ return cached;
630
+ }
631
+ const manifest = await fetchManifest();
632
+ if (cache) {
633
+ waitUntil(cache.set(key, manifest, { ttl, tags: generateManifestCacheTags() }).catch(() => {
634
+ }));
635
+ }
636
+ return manifest;
637
+ };
638
+ return async (options) => {
639
+ var _a;
640
+ if (current && Date.now() - current.loadedAt < maxAge * 1e3) {
641
+ return current.manifest;
642
+ }
643
+ pending != null ? pending : pending = load(options).then((manifest) => {
644
+ current = { manifest, loadedAt: Date.now() };
645
+ return manifest;
646
+ }).finally(() => {
647
+ pending = void 0;
648
+ });
649
+ try {
650
+ return await pending;
651
+ } catch (error) {
652
+ const known = (_a = current == null ? void 0 : current.manifest) != null ? _a : fallback;
653
+ if (known) {
654
+ return known;
655
+ }
656
+ throw error;
657
+ }
658
+ };
659
+ };
660
+ var fetchPublishedManifest = () => getManifestClient({ cache: { type: "no-store" } }).get({ preview: false });
661
+ var isManifest = (value) => typeof value === "object" && value !== null && "project" in value;
662
+
663
+ // src/vercel/vercelManifestProvider.ts
664
+ var runtimeCache = {
665
+ get: (key) => getCache2().get(key),
666
+ set: (key, value, options) => getCache2().set(key, value, options)
667
+ };
668
+ var vercelManifestProvider = (options = {}) => createCachedManifestProvider({
669
+ ...options,
670
+ cache: isRuntimeCacheAvailable() ? runtimeCache : void 0
671
+ });
672
+ export {
673
+ expireVercelRuntimeCacheTags,
674
+ vercelManifestProvider
675
+ };