@uniformdev/next-app-router 20.7.1-alpha.118
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +2 -0
- package/dist/UniformComposition-Bekn8k24.d.mts +74 -0
- package/dist/UniformComposition-CdXfLiaB.d.ts +74 -0
- package/dist/UniformText-ChMwHBw4.d.mts +10 -0
- package/dist/UniformText-ChMwHBw4.d.ts +10 -0
- package/dist/cache.d.mts +9 -0
- package/dist/cache.d.ts +9 -0
- package/dist/cache.js +1915 -0
- package/dist/cache.mjs +1903 -0
- package/dist/client-BCGVjYM-.d.mts +779 -0
- package/dist/client-BCGVjYM-.d.ts +779 -0
- package/dist/compat.d.mts +36 -0
- package/dist/compat.d.ts +36 -0
- package/dist/compat.js +120 -0
- package/dist/compat.mjs +89 -0
- package/dist/component.d.mts +61 -0
- package/dist/component.d.ts +61 -0
- package/dist/component.js +1397 -0
- package/dist/component.mjs +1384 -0
- package/dist/config.d.mts +13 -0
- package/dist/config.d.ts +13 -0
- package/dist/config.js +80 -0
- package/dist/config.mjs +55 -0
- package/dist/handler.d.mts +29 -0
- package/dist/handler.d.ts +29 -0
- package/dist/handler.js +2664 -0
- package/dist/handler.mjs +2648 -0
- package/dist/index.d.mts +264 -0
- package/dist/index.d.ts +264 -0
- package/dist/index.esm.js +3935 -0
- package/dist/index.js +3953 -0
- package/dist/index.mjs +3935 -0
- package/dist/middleware.d.mts +70 -0
- package/dist/middleware.d.ts +70 -0
- package/dist/middleware.js +5873 -0
- package/dist/middleware.mjs +5867 -0
- package/dist/resolveRouteFromCode-B2rqnHgJ.d.ts +26 -0
- package/dist/resolveRouteFromCode-CA63-EPp.d.mts +26 -0
- package/package.json +112 -0
package/dist/cache.mjs
ADDED
|
@@ -0,0 +1,1903 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// ../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js
|
|
28
|
+
var require_yocto_queue = __commonJS({
|
|
29
|
+
"../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js"(exports, module) {
|
|
30
|
+
"use strict";
|
|
31
|
+
var Node = class {
|
|
32
|
+
/// value;
|
|
33
|
+
/// next;
|
|
34
|
+
constructor(value) {
|
|
35
|
+
this.value = value;
|
|
36
|
+
this.next = void 0;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var Queue = class {
|
|
40
|
+
// TODO: Use private class fields when targeting Node.js 12.
|
|
41
|
+
// #_head;
|
|
42
|
+
// #_tail;
|
|
43
|
+
// #_size;
|
|
44
|
+
constructor() {
|
|
45
|
+
this.clear();
|
|
46
|
+
}
|
|
47
|
+
enqueue(value) {
|
|
48
|
+
const node = new Node(value);
|
|
49
|
+
if (this._head) {
|
|
50
|
+
this._tail.next = node;
|
|
51
|
+
this._tail = node;
|
|
52
|
+
} else {
|
|
53
|
+
this._head = node;
|
|
54
|
+
this._tail = node;
|
|
55
|
+
}
|
|
56
|
+
this._size++;
|
|
57
|
+
}
|
|
58
|
+
dequeue() {
|
|
59
|
+
const current = this._head;
|
|
60
|
+
if (!current) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
this._head = this._head.next;
|
|
64
|
+
this._size--;
|
|
65
|
+
return current.value;
|
|
66
|
+
}
|
|
67
|
+
clear() {
|
|
68
|
+
this._head = void 0;
|
|
69
|
+
this._tail = void 0;
|
|
70
|
+
this._size = 0;
|
|
71
|
+
}
|
|
72
|
+
get size() {
|
|
73
|
+
return this._size;
|
|
74
|
+
}
|
|
75
|
+
*[Symbol.iterator]() {
|
|
76
|
+
let current = this._head;
|
|
77
|
+
while (current) {
|
|
78
|
+
yield current.value;
|
|
79
|
+
current = current.next;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
module.exports = Queue;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// ../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js
|
|
88
|
+
var require_p_limit = __commonJS({
|
|
89
|
+
"../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js"(exports, module) {
|
|
90
|
+
"use strict";
|
|
91
|
+
var Queue = require_yocto_queue();
|
|
92
|
+
var pLimit2 = (concurrency) => {
|
|
93
|
+
if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
|
|
94
|
+
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
95
|
+
}
|
|
96
|
+
const queue = new Queue();
|
|
97
|
+
let activeCount = 0;
|
|
98
|
+
const next = () => {
|
|
99
|
+
activeCount--;
|
|
100
|
+
if (queue.size > 0) {
|
|
101
|
+
queue.dequeue()();
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const run = async (fn, resolve, ...args) => {
|
|
105
|
+
activeCount++;
|
|
106
|
+
const result = (async () => fn(...args))();
|
|
107
|
+
resolve(result);
|
|
108
|
+
try {
|
|
109
|
+
await result;
|
|
110
|
+
} catch (e) {
|
|
111
|
+
}
|
|
112
|
+
next();
|
|
113
|
+
};
|
|
114
|
+
const enqueue = (fn, resolve, ...args) => {
|
|
115
|
+
queue.enqueue(run.bind(null, fn, resolve, ...args));
|
|
116
|
+
(async () => {
|
|
117
|
+
await Promise.resolve();
|
|
118
|
+
if (activeCount < concurrency && queue.size > 0) {
|
|
119
|
+
queue.dequeue()();
|
|
120
|
+
}
|
|
121
|
+
})();
|
|
122
|
+
};
|
|
123
|
+
const generator = (fn, ...args) => new Promise((resolve) => {
|
|
124
|
+
enqueue(fn, resolve, ...args);
|
|
125
|
+
});
|
|
126
|
+
Object.defineProperties(generator, {
|
|
127
|
+
activeCount: {
|
|
128
|
+
get: () => activeCount
|
|
129
|
+
},
|
|
130
|
+
pendingCount: {
|
|
131
|
+
get: () => queue.size
|
|
132
|
+
},
|
|
133
|
+
clearQueue: {
|
|
134
|
+
value: () => {
|
|
135
|
+
queue.clear();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
return generator;
|
|
140
|
+
};
|
|
141
|
+
module.exports = pLimit2;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// src/cache.ts
|
|
146
|
+
import { cacheLife } from "next/cache";
|
|
147
|
+
|
|
148
|
+
// src/data/resolveRouteFromCode.ts
|
|
149
|
+
import { deserializeEvaluationResult } from "@uniformdev/next-app-router-shared";
|
|
150
|
+
|
|
151
|
+
// ../context/dist/api/api.mjs
|
|
152
|
+
var import_p_limit = __toESM(require_p_limit(), 1);
|
|
153
|
+
var __defProp2 = Object.defineProperty;
|
|
154
|
+
var __typeError = (msg) => {
|
|
155
|
+
throw TypeError(msg);
|
|
156
|
+
};
|
|
157
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
158
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
159
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
160
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
161
|
+
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);
|
|
162
|
+
var defaultLimitPolicy = (0, import_p_limit.default)(6);
|
|
163
|
+
var ApiClientError = class _ApiClientError extends Error {
|
|
164
|
+
constructor(errorMessage, fetchMethod, fetchUri, statusCode, statusText, requestId) {
|
|
165
|
+
super(
|
|
166
|
+
`${errorMessage}
|
|
167
|
+
${statusCode}${statusText ? " " + statusText : ""} (${fetchMethod} ${fetchUri}${requestId ? ` Request ID: ${requestId}` : ""})`
|
|
168
|
+
);
|
|
169
|
+
this.errorMessage = errorMessage;
|
|
170
|
+
this.fetchMethod = fetchMethod;
|
|
171
|
+
this.fetchUri = fetchUri;
|
|
172
|
+
this.statusCode = statusCode;
|
|
173
|
+
this.statusText = statusText;
|
|
174
|
+
this.requestId = requestId;
|
|
175
|
+
Object.setPrototypeOf(this, _ApiClientError.prototype);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
var ApiClient = class _ApiClient {
|
|
179
|
+
constructor(options) {
|
|
180
|
+
__publicField(this, "options");
|
|
181
|
+
var _a, _b, _c, _d, _e;
|
|
182
|
+
if (!options.apiKey && !options.bearerToken) {
|
|
183
|
+
throw new Error("You must provide an API key or a bearer token");
|
|
184
|
+
}
|
|
185
|
+
let leFetch = options.fetch;
|
|
186
|
+
if (!leFetch) {
|
|
187
|
+
if (typeof window !== "undefined") {
|
|
188
|
+
leFetch = window.fetch.bind(window);
|
|
189
|
+
} else if (typeof fetch !== "undefined") {
|
|
190
|
+
leFetch = fetch;
|
|
191
|
+
} else {
|
|
192
|
+
throw new Error("You must provide or polyfill a fetch implementation when not in a browser");
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
this.options = {
|
|
196
|
+
...options,
|
|
197
|
+
fetch: leFetch,
|
|
198
|
+
apiHost: this.ensureApiHost(options.apiHost),
|
|
199
|
+
apiKey: (_a = options.apiKey) != null ? _a : null,
|
|
200
|
+
projectId: (_b = options.projectId) != null ? _b : null,
|
|
201
|
+
bearerToken: (_c = options.bearerToken) != null ? _c : null,
|
|
202
|
+
limitPolicy: (_d = options.limitPolicy) != null ? _d : defaultLimitPolicy,
|
|
203
|
+
bypassCache: (_e = options.bypassCache) != null ? _e : false
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
async apiClient(fetchUri, options) {
|
|
207
|
+
return (await this.apiClientWithResponse(fetchUri, options)).body;
|
|
208
|
+
}
|
|
209
|
+
async apiClientWithResponse(fetchUri, options) {
|
|
210
|
+
return this.options.limitPolicy(async () => {
|
|
211
|
+
var _a;
|
|
212
|
+
const coreHeaders = this.options.apiKey ? {
|
|
213
|
+
"x-api-key": this.options.apiKey
|
|
214
|
+
} : {
|
|
215
|
+
Authorization: `Bearer ${this.options.bearerToken}`
|
|
216
|
+
};
|
|
217
|
+
if (this.options.bypassCache) {
|
|
218
|
+
coreHeaders["x-bypass-cache"] = "true";
|
|
219
|
+
}
|
|
220
|
+
const { fetch: fetch2, signal } = this.options;
|
|
221
|
+
const callApi = () => fetch2(fetchUri.toString(), {
|
|
222
|
+
...options,
|
|
223
|
+
signal,
|
|
224
|
+
headers: {
|
|
225
|
+
...options == null ? void 0 : options.headers,
|
|
226
|
+
...coreHeaders
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
const apiResponse = await handleRateLimits(callApi);
|
|
230
|
+
if (!apiResponse.ok) {
|
|
231
|
+
let message = "";
|
|
232
|
+
try {
|
|
233
|
+
const responseText = await apiResponse.text();
|
|
234
|
+
try {
|
|
235
|
+
const parsed = JSON.parse(responseText);
|
|
236
|
+
if (parsed.errorMessage) {
|
|
237
|
+
message = Array.isArray(parsed.errorMessage) ? parsed.errorMessage.join(", ") : parsed.errorMessage;
|
|
238
|
+
} else {
|
|
239
|
+
message = responseText;
|
|
240
|
+
}
|
|
241
|
+
} catch (e) {
|
|
242
|
+
message = responseText;
|
|
243
|
+
}
|
|
244
|
+
} catch (e) {
|
|
245
|
+
message = `General error`;
|
|
246
|
+
}
|
|
247
|
+
throw new ApiClientError(
|
|
248
|
+
message,
|
|
249
|
+
(_a = options == null ? void 0 : options.method) != null ? _a : "GET",
|
|
250
|
+
fetchUri.toString(),
|
|
251
|
+
apiResponse.status,
|
|
252
|
+
apiResponse.statusText,
|
|
253
|
+
_ApiClient.getRequestId(apiResponse)
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
if (options == null ? void 0 : options.expectNoContent) {
|
|
257
|
+
return { response: apiResponse, body: null };
|
|
258
|
+
}
|
|
259
|
+
return {
|
|
260
|
+
response: apiResponse,
|
|
261
|
+
body: await apiResponse.json()
|
|
262
|
+
};
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
createUrl(path, queryParams, hostOverride) {
|
|
266
|
+
const url = new URL(`${hostOverride != null ? hostOverride : this.options.apiHost}${path}`);
|
|
267
|
+
Object.entries(queryParams != null ? queryParams : {}).forEach(([key, value]) => {
|
|
268
|
+
var _a;
|
|
269
|
+
if (typeof value !== "undefined" && value !== null) {
|
|
270
|
+
url.searchParams.append(key, Array.isArray(value) ? value.join(",") : (_a = value == null ? void 0 : value.toString()) != null ? _a : "");
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
return url;
|
|
274
|
+
}
|
|
275
|
+
ensureApiHost(apiHost) {
|
|
276
|
+
if (!apiHost) return "https://uniform.app";
|
|
277
|
+
if (!(apiHost == null ? void 0 : apiHost.startsWith("http"))) {
|
|
278
|
+
throw new Error('Your apiHost must start with "http"');
|
|
279
|
+
}
|
|
280
|
+
if (apiHost.indexOf("/", 8) > -1) {
|
|
281
|
+
throw new Error("Your apiHost must not contain a path element after the domain");
|
|
282
|
+
}
|
|
283
|
+
if (apiHost.indexOf("?") > -1) {
|
|
284
|
+
throw new Error("Your apiHost must not contain a query string");
|
|
285
|
+
}
|
|
286
|
+
if (apiHost == null ? void 0 : apiHost.endsWith("/")) {
|
|
287
|
+
apiHost = apiHost.substring(0, apiHost.length - 1);
|
|
288
|
+
}
|
|
289
|
+
return apiHost;
|
|
290
|
+
}
|
|
291
|
+
static getRequestId(response) {
|
|
292
|
+
const apigRequestId = response.headers.get("apigw-requestid");
|
|
293
|
+
if (apigRequestId) {
|
|
294
|
+
return apigRequestId;
|
|
295
|
+
}
|
|
296
|
+
return void 0;
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
async function handleRateLimits(callApi) {
|
|
300
|
+
var _a;
|
|
301
|
+
const backoffRetries = 5;
|
|
302
|
+
let backoffRetriesLeft = backoffRetries;
|
|
303
|
+
let response;
|
|
304
|
+
while (backoffRetriesLeft > 0) {
|
|
305
|
+
response = await callApi();
|
|
306
|
+
if (response.status !== 429) {
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
let resetWait = 0;
|
|
310
|
+
try {
|
|
311
|
+
const responseClone = response.clone();
|
|
312
|
+
const dateHeader = responseClone.headers.get("date");
|
|
313
|
+
const serverTime = dateHeader ? new Date(dateHeader).getTime() : void 0;
|
|
314
|
+
const body = await responseClone.json();
|
|
315
|
+
const resetTime = (_a = body == null ? void 0 : body.info) == null ? void 0 : _a.reset;
|
|
316
|
+
if (typeof serverTime === "number" && typeof resetTime === "number") {
|
|
317
|
+
resetWait = Math.max(0, Math.min(Math.round(1.1 * (resetTime - serverTime)), 1e4));
|
|
318
|
+
}
|
|
319
|
+
} catch (e) {
|
|
320
|
+
}
|
|
321
|
+
const base = Math.pow(2, backoffRetries - backoffRetriesLeft) * 333;
|
|
322
|
+
const backoffWait = base + Math.round(Math.random() * (base / 2)) * (Math.random() > 0.5 ? 1 : -1);
|
|
323
|
+
await new Promise((resolve) => setTimeout(resolve, resetWait + backoffWait));
|
|
324
|
+
backoffRetriesLeft -= 1;
|
|
325
|
+
}
|
|
326
|
+
return response;
|
|
327
|
+
}
|
|
328
|
+
var _url;
|
|
329
|
+
var _AggregateClient = class _AggregateClient2 extends ApiClient {
|
|
330
|
+
constructor(options) {
|
|
331
|
+
super(options);
|
|
332
|
+
}
|
|
333
|
+
/** Fetches all aggregates for a project */
|
|
334
|
+
async get(options) {
|
|
335
|
+
const { projectId } = this.options;
|
|
336
|
+
const fetchUri = this.createUrl(__privateGet(_AggregateClient2, _url), { ...options, projectId });
|
|
337
|
+
return await this.apiClient(fetchUri);
|
|
338
|
+
}
|
|
339
|
+
/** Updates or creates (based on id) an Aggregate */
|
|
340
|
+
async upsert(body) {
|
|
341
|
+
const fetchUri = this.createUrl(__privateGet(_AggregateClient2, _url));
|
|
342
|
+
await this.apiClient(fetchUri, {
|
|
343
|
+
method: "PUT",
|
|
344
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
345
|
+
expectNoContent: true
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
/** Deletes an Aggregate */
|
|
349
|
+
async remove(body) {
|
|
350
|
+
const fetchUri = this.createUrl(__privateGet(_AggregateClient2, _url));
|
|
351
|
+
await this.apiClient(fetchUri, {
|
|
352
|
+
method: "DELETE",
|
|
353
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
354
|
+
expectNoContent: true
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
_url = /* @__PURE__ */ new WeakMap();
|
|
359
|
+
__privateAdd(_AggregateClient, _url, "/api/v2/aggregate");
|
|
360
|
+
var _url2;
|
|
361
|
+
var _DimensionClient = class _DimensionClient2 extends ApiClient {
|
|
362
|
+
constructor(options) {
|
|
363
|
+
super(options);
|
|
364
|
+
}
|
|
365
|
+
/** Fetches the known score dimensions for a project */
|
|
366
|
+
async get(options) {
|
|
367
|
+
const { projectId } = this.options;
|
|
368
|
+
const fetchUri = this.createUrl(__privateGet(_DimensionClient2, _url2), { ...options, projectId });
|
|
369
|
+
return await this.apiClient(fetchUri);
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
_url2 = /* @__PURE__ */ new WeakMap();
|
|
373
|
+
__privateAdd(_DimensionClient, _url2, "/api/v2/dimension");
|
|
374
|
+
var _url3;
|
|
375
|
+
var _valueUrl;
|
|
376
|
+
var _EnrichmentClient = class _EnrichmentClient2 extends ApiClient {
|
|
377
|
+
constructor(options) {
|
|
378
|
+
super(options);
|
|
379
|
+
}
|
|
380
|
+
/** Fetches all enrichments and values for a project, grouped by category */
|
|
381
|
+
async get(options) {
|
|
382
|
+
const { projectId } = this.options;
|
|
383
|
+
const fetchUri = this.createUrl(__privateGet(_EnrichmentClient2, _url3), { ...options, projectId });
|
|
384
|
+
return await this.apiClient(fetchUri);
|
|
385
|
+
}
|
|
386
|
+
/** Updates or creates (based on id) an enrichment category */
|
|
387
|
+
async upsertCategory(body) {
|
|
388
|
+
const fetchUri = this.createUrl(__privateGet(_EnrichmentClient2, _url3));
|
|
389
|
+
await this.apiClient(fetchUri, {
|
|
390
|
+
method: "PUT",
|
|
391
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
392
|
+
expectNoContent: true
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
/** Deletes an enrichment category */
|
|
396
|
+
async removeCategory(body) {
|
|
397
|
+
const fetchUri = this.createUrl(__privateGet(_EnrichmentClient2, _url3));
|
|
398
|
+
await this.apiClient(fetchUri, {
|
|
399
|
+
method: "DELETE",
|
|
400
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
401
|
+
expectNoContent: true
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
/** Updates or creates (based on id) an enrichment value within an enrichment category */
|
|
405
|
+
async upsertValue(body) {
|
|
406
|
+
const fetchUri = this.createUrl(__privateGet(_EnrichmentClient2, _valueUrl));
|
|
407
|
+
await this.apiClient(fetchUri, {
|
|
408
|
+
method: "PUT",
|
|
409
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
410
|
+
expectNoContent: true
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
/** Deletes an enrichment value within an enrichment category. The category is left alone. */
|
|
414
|
+
async removeValue(body) {
|
|
415
|
+
const fetchUri = this.createUrl(__privateGet(_EnrichmentClient2, _valueUrl));
|
|
416
|
+
await this.apiClient(fetchUri, {
|
|
417
|
+
method: "DELETE",
|
|
418
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
419
|
+
expectNoContent: true
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
_url3 = /* @__PURE__ */ new WeakMap();
|
|
424
|
+
_valueUrl = /* @__PURE__ */ new WeakMap();
|
|
425
|
+
__privateAdd(_EnrichmentClient, _url3, "/api/v1/enrichments");
|
|
426
|
+
__privateAdd(_EnrichmentClient, _valueUrl, "/api/v1/enrichment-values");
|
|
427
|
+
var _url4;
|
|
428
|
+
var _ManifestClient = class _ManifestClient2 extends ApiClient {
|
|
429
|
+
constructor(options) {
|
|
430
|
+
super(options);
|
|
431
|
+
}
|
|
432
|
+
/** Fetches the Context manifest for a project */
|
|
433
|
+
async get(options) {
|
|
434
|
+
const { projectId } = this.options;
|
|
435
|
+
const fetchUri = this.createUrl(__privateGet(_ManifestClient2, _url4), { ...options, projectId });
|
|
436
|
+
return await this.apiClient(fetchUri);
|
|
437
|
+
}
|
|
438
|
+
/** Publishes the Context manifest for a project */
|
|
439
|
+
async publish() {
|
|
440
|
+
const { projectId } = this.options;
|
|
441
|
+
const fetchUri = this.createUrl("/api/v1/publish", { siteId: projectId });
|
|
442
|
+
await this.apiClient(fetchUri, {
|
|
443
|
+
method: "POST",
|
|
444
|
+
expectNoContent: true
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
_url4 = /* @__PURE__ */ new WeakMap();
|
|
449
|
+
__privateAdd(_ManifestClient, _url4, "/api/v2/manifest");
|
|
450
|
+
var ManifestClient = _ManifestClient;
|
|
451
|
+
var _url5;
|
|
452
|
+
var _QuirkClient = class _QuirkClient2 extends ApiClient {
|
|
453
|
+
constructor(options) {
|
|
454
|
+
super(options);
|
|
455
|
+
}
|
|
456
|
+
/** Fetches all Quirks for a project */
|
|
457
|
+
async get(options) {
|
|
458
|
+
const { projectId } = this.options;
|
|
459
|
+
const fetchUri = this.createUrl(__privateGet(_QuirkClient2, _url5), { ...options, projectId });
|
|
460
|
+
return await this.apiClient(fetchUri);
|
|
461
|
+
}
|
|
462
|
+
/** Updates or creates (based on id) a Quirk */
|
|
463
|
+
async upsert(body) {
|
|
464
|
+
const fetchUri = this.createUrl(__privateGet(_QuirkClient2, _url5));
|
|
465
|
+
await this.apiClient(fetchUri, {
|
|
466
|
+
method: "PUT",
|
|
467
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
468
|
+
expectNoContent: true
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
/** Deletes a Quirk */
|
|
472
|
+
async remove(body) {
|
|
473
|
+
const fetchUri = this.createUrl(__privateGet(_QuirkClient2, _url5));
|
|
474
|
+
await this.apiClient(fetchUri, {
|
|
475
|
+
method: "DELETE",
|
|
476
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
477
|
+
expectNoContent: true
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
_url5 = /* @__PURE__ */ new WeakMap();
|
|
482
|
+
__privateAdd(_QuirkClient, _url5, "/api/v2/quirk");
|
|
483
|
+
var _url6;
|
|
484
|
+
var _SignalClient = class _SignalClient2 extends ApiClient {
|
|
485
|
+
constructor(options) {
|
|
486
|
+
super(options);
|
|
487
|
+
}
|
|
488
|
+
/** Fetches all Signals for a project */
|
|
489
|
+
async get(options) {
|
|
490
|
+
const { projectId } = this.options;
|
|
491
|
+
const fetchUri = this.createUrl(__privateGet(_SignalClient2, _url6), { ...options, projectId });
|
|
492
|
+
return await this.apiClient(fetchUri);
|
|
493
|
+
}
|
|
494
|
+
/** Updates or creates (based on id) a Signal */
|
|
495
|
+
async upsert(body) {
|
|
496
|
+
const fetchUri = this.createUrl(__privateGet(_SignalClient2, _url6));
|
|
497
|
+
await this.apiClient(fetchUri, {
|
|
498
|
+
method: "PUT",
|
|
499
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
500
|
+
expectNoContent: true
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
/** Deletes a Signal */
|
|
504
|
+
async remove(body) {
|
|
505
|
+
const fetchUri = this.createUrl(__privateGet(_SignalClient2, _url6));
|
|
506
|
+
await this.apiClient(fetchUri, {
|
|
507
|
+
method: "DELETE",
|
|
508
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
509
|
+
expectNoContent: true
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
_url6 = /* @__PURE__ */ new WeakMap();
|
|
514
|
+
__privateAdd(_SignalClient, _url6, "/api/v2/signal");
|
|
515
|
+
var _url7;
|
|
516
|
+
var _TestClient = class _TestClient2 extends ApiClient {
|
|
517
|
+
constructor(options) {
|
|
518
|
+
super(options);
|
|
519
|
+
}
|
|
520
|
+
/** Fetches all Tests for a project */
|
|
521
|
+
async get(options) {
|
|
522
|
+
const { projectId } = this.options;
|
|
523
|
+
const fetchUri = this.createUrl(__privateGet(_TestClient2, _url7), { ...options, projectId });
|
|
524
|
+
return await this.apiClient(fetchUri);
|
|
525
|
+
}
|
|
526
|
+
/** Updates or creates (based on id) a Test */
|
|
527
|
+
async upsert(body) {
|
|
528
|
+
const fetchUri = this.createUrl(__privateGet(_TestClient2, _url7));
|
|
529
|
+
await this.apiClient(fetchUri, {
|
|
530
|
+
method: "PUT",
|
|
531
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
532
|
+
expectNoContent: true
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
/** Deletes a Test */
|
|
536
|
+
async remove(body) {
|
|
537
|
+
const fetchUri = this.createUrl(__privateGet(_TestClient2, _url7));
|
|
538
|
+
await this.apiClient(fetchUri, {
|
|
539
|
+
method: "DELETE",
|
|
540
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
541
|
+
expectNoContent: true
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
_url7 = /* @__PURE__ */ new WeakMap();
|
|
546
|
+
__privateAdd(_TestClient, _url7, "/api/v2/test");
|
|
547
|
+
|
|
548
|
+
// ../canvas/dist/index.mjs
|
|
549
|
+
var __create2 = Object.create;
|
|
550
|
+
var __defProp3 = Object.defineProperty;
|
|
551
|
+
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
552
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
553
|
+
var __getProtoOf2 = Object.getPrototypeOf;
|
|
554
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
555
|
+
var __typeError2 = (msg) => {
|
|
556
|
+
throw TypeError(msg);
|
|
557
|
+
};
|
|
558
|
+
var __commonJS2 = (cb, mod) => function __require() {
|
|
559
|
+
return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
560
|
+
};
|
|
561
|
+
var __copyProps2 = (to, from, except, desc) => {
|
|
562
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
563
|
+
for (let key of __getOwnPropNames2(from))
|
|
564
|
+
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
565
|
+
__defProp3(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
|
566
|
+
}
|
|
567
|
+
return to;
|
|
568
|
+
};
|
|
569
|
+
var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
|
|
570
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
571
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
572
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
573
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
574
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp3(target, "default", { value: mod, enumerable: true }) : target,
|
|
575
|
+
mod
|
|
576
|
+
));
|
|
577
|
+
var __accessCheck2 = (obj, member, msg) => member.has(obj) || __typeError2("Cannot " + msg);
|
|
578
|
+
var __privateGet2 = (obj, member, getter) => (__accessCheck2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
579
|
+
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);
|
|
580
|
+
var require_yocto_queue2 = __commonJS2({
|
|
581
|
+
"../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js"(exports, module) {
|
|
582
|
+
"use strict";
|
|
583
|
+
var Node = class {
|
|
584
|
+
/// value;
|
|
585
|
+
/// next;
|
|
586
|
+
constructor(value) {
|
|
587
|
+
this.value = value;
|
|
588
|
+
this.next = void 0;
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
var Queue = class {
|
|
592
|
+
// TODO: Use private class fields when targeting Node.js 12.
|
|
593
|
+
// #_head;
|
|
594
|
+
// #_tail;
|
|
595
|
+
// #_size;
|
|
596
|
+
constructor() {
|
|
597
|
+
this.clear();
|
|
598
|
+
}
|
|
599
|
+
enqueue(value) {
|
|
600
|
+
const node = new Node(value);
|
|
601
|
+
if (this._head) {
|
|
602
|
+
this._tail.next = node;
|
|
603
|
+
this._tail = node;
|
|
604
|
+
} else {
|
|
605
|
+
this._head = node;
|
|
606
|
+
this._tail = node;
|
|
607
|
+
}
|
|
608
|
+
this._size++;
|
|
609
|
+
}
|
|
610
|
+
dequeue() {
|
|
611
|
+
const current = this._head;
|
|
612
|
+
if (!current) {
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
this._head = this._head.next;
|
|
616
|
+
this._size--;
|
|
617
|
+
return current.value;
|
|
618
|
+
}
|
|
619
|
+
clear() {
|
|
620
|
+
this._head = void 0;
|
|
621
|
+
this._tail = void 0;
|
|
622
|
+
this._size = 0;
|
|
623
|
+
}
|
|
624
|
+
get size() {
|
|
625
|
+
return this._size;
|
|
626
|
+
}
|
|
627
|
+
*[Symbol.iterator]() {
|
|
628
|
+
let current = this._head;
|
|
629
|
+
while (current) {
|
|
630
|
+
yield current.value;
|
|
631
|
+
current = current.next;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
module.exports = Queue;
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
var require_p_limit2 = __commonJS2({
|
|
639
|
+
"../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js"(exports, module) {
|
|
640
|
+
"use strict";
|
|
641
|
+
var Queue = require_yocto_queue2();
|
|
642
|
+
var pLimit2 = (concurrency) => {
|
|
643
|
+
if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
|
|
644
|
+
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
645
|
+
}
|
|
646
|
+
const queue = new Queue();
|
|
647
|
+
let activeCount = 0;
|
|
648
|
+
const next = () => {
|
|
649
|
+
activeCount--;
|
|
650
|
+
if (queue.size > 0) {
|
|
651
|
+
queue.dequeue()();
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
const run = async (fn, resolve, ...args) => {
|
|
655
|
+
activeCount++;
|
|
656
|
+
const result = (async () => fn(...args))();
|
|
657
|
+
resolve(result);
|
|
658
|
+
try {
|
|
659
|
+
await result;
|
|
660
|
+
} catch (e) {
|
|
661
|
+
}
|
|
662
|
+
next();
|
|
663
|
+
};
|
|
664
|
+
const enqueue = (fn, resolve, ...args) => {
|
|
665
|
+
queue.enqueue(run.bind(null, fn, resolve, ...args));
|
|
666
|
+
(async () => {
|
|
667
|
+
await Promise.resolve();
|
|
668
|
+
if (activeCount < concurrency && queue.size > 0) {
|
|
669
|
+
queue.dequeue()();
|
|
670
|
+
}
|
|
671
|
+
})();
|
|
672
|
+
};
|
|
673
|
+
const generator = (fn, ...args) => new Promise((resolve) => {
|
|
674
|
+
enqueue(fn, resolve, ...args);
|
|
675
|
+
});
|
|
676
|
+
Object.defineProperties(generator, {
|
|
677
|
+
activeCount: {
|
|
678
|
+
get: () => activeCount
|
|
679
|
+
},
|
|
680
|
+
pendingCount: {
|
|
681
|
+
get: () => queue.size
|
|
682
|
+
},
|
|
683
|
+
clearQueue: {
|
|
684
|
+
value: () => {
|
|
685
|
+
queue.clear();
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
});
|
|
689
|
+
return generator;
|
|
690
|
+
};
|
|
691
|
+
module.exports = pLimit2;
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
var require_retry_operation = __commonJS2({
|
|
695
|
+
"../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js"(exports, module) {
|
|
696
|
+
"use strict";
|
|
697
|
+
function RetryOperation(timeouts, options) {
|
|
698
|
+
if (typeof options === "boolean") {
|
|
699
|
+
options = { forever: options };
|
|
700
|
+
}
|
|
701
|
+
this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
|
|
702
|
+
this._timeouts = timeouts;
|
|
703
|
+
this._options = options || {};
|
|
704
|
+
this._maxRetryTime = options && options.maxRetryTime || Infinity;
|
|
705
|
+
this._fn = null;
|
|
706
|
+
this._errors = [];
|
|
707
|
+
this._attempts = 1;
|
|
708
|
+
this._operationTimeout = null;
|
|
709
|
+
this._operationTimeoutCb = null;
|
|
710
|
+
this._timeout = null;
|
|
711
|
+
this._operationStart = null;
|
|
712
|
+
this._timer = null;
|
|
713
|
+
if (this._options.forever) {
|
|
714
|
+
this._cachedTimeouts = this._timeouts.slice(0);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
module.exports = RetryOperation;
|
|
718
|
+
RetryOperation.prototype.reset = function() {
|
|
719
|
+
this._attempts = 1;
|
|
720
|
+
this._timeouts = this._originalTimeouts.slice(0);
|
|
721
|
+
};
|
|
722
|
+
RetryOperation.prototype.stop = function() {
|
|
723
|
+
if (this._timeout) {
|
|
724
|
+
clearTimeout(this._timeout);
|
|
725
|
+
}
|
|
726
|
+
if (this._timer) {
|
|
727
|
+
clearTimeout(this._timer);
|
|
728
|
+
}
|
|
729
|
+
this._timeouts = [];
|
|
730
|
+
this._cachedTimeouts = null;
|
|
731
|
+
};
|
|
732
|
+
RetryOperation.prototype.retry = function(err) {
|
|
733
|
+
if (this._timeout) {
|
|
734
|
+
clearTimeout(this._timeout);
|
|
735
|
+
}
|
|
736
|
+
if (!err) {
|
|
737
|
+
return false;
|
|
738
|
+
}
|
|
739
|
+
var currentTime = (/* @__PURE__ */ new Date()).getTime();
|
|
740
|
+
if (err && currentTime - this._operationStart >= this._maxRetryTime) {
|
|
741
|
+
this._errors.push(err);
|
|
742
|
+
this._errors.unshift(new Error("RetryOperation timeout occurred"));
|
|
743
|
+
return false;
|
|
744
|
+
}
|
|
745
|
+
this._errors.push(err);
|
|
746
|
+
var timeout = this._timeouts.shift();
|
|
747
|
+
if (timeout === void 0) {
|
|
748
|
+
if (this._cachedTimeouts) {
|
|
749
|
+
this._errors.splice(0, this._errors.length - 1);
|
|
750
|
+
timeout = this._cachedTimeouts.slice(-1);
|
|
751
|
+
} else {
|
|
752
|
+
return false;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
var self = this;
|
|
756
|
+
this._timer = setTimeout(function() {
|
|
757
|
+
self._attempts++;
|
|
758
|
+
if (self._operationTimeoutCb) {
|
|
759
|
+
self._timeout = setTimeout(function() {
|
|
760
|
+
self._operationTimeoutCb(self._attempts);
|
|
761
|
+
}, self._operationTimeout);
|
|
762
|
+
if (self._options.unref) {
|
|
763
|
+
self._timeout.unref();
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
self._fn(self._attempts);
|
|
767
|
+
}, timeout);
|
|
768
|
+
if (this._options.unref) {
|
|
769
|
+
this._timer.unref();
|
|
770
|
+
}
|
|
771
|
+
return true;
|
|
772
|
+
};
|
|
773
|
+
RetryOperation.prototype.attempt = function(fn, timeoutOps) {
|
|
774
|
+
this._fn = fn;
|
|
775
|
+
if (timeoutOps) {
|
|
776
|
+
if (timeoutOps.timeout) {
|
|
777
|
+
this._operationTimeout = timeoutOps.timeout;
|
|
778
|
+
}
|
|
779
|
+
if (timeoutOps.cb) {
|
|
780
|
+
this._operationTimeoutCb = timeoutOps.cb;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
var self = this;
|
|
784
|
+
if (this._operationTimeoutCb) {
|
|
785
|
+
this._timeout = setTimeout(function() {
|
|
786
|
+
self._operationTimeoutCb();
|
|
787
|
+
}, self._operationTimeout);
|
|
788
|
+
}
|
|
789
|
+
this._operationStart = (/* @__PURE__ */ new Date()).getTime();
|
|
790
|
+
this._fn(this._attempts);
|
|
791
|
+
};
|
|
792
|
+
RetryOperation.prototype.try = function(fn) {
|
|
793
|
+
console.log("Using RetryOperation.try() is deprecated");
|
|
794
|
+
this.attempt(fn);
|
|
795
|
+
};
|
|
796
|
+
RetryOperation.prototype.start = function(fn) {
|
|
797
|
+
console.log("Using RetryOperation.start() is deprecated");
|
|
798
|
+
this.attempt(fn);
|
|
799
|
+
};
|
|
800
|
+
RetryOperation.prototype.start = RetryOperation.prototype.try;
|
|
801
|
+
RetryOperation.prototype.errors = function() {
|
|
802
|
+
return this._errors;
|
|
803
|
+
};
|
|
804
|
+
RetryOperation.prototype.attempts = function() {
|
|
805
|
+
return this._attempts;
|
|
806
|
+
};
|
|
807
|
+
RetryOperation.prototype.mainError = function() {
|
|
808
|
+
if (this._errors.length === 0) {
|
|
809
|
+
return null;
|
|
810
|
+
}
|
|
811
|
+
var counts = {};
|
|
812
|
+
var mainError = null;
|
|
813
|
+
var mainErrorCount = 0;
|
|
814
|
+
for (var i = 0; i < this._errors.length; i++) {
|
|
815
|
+
var error = this._errors[i];
|
|
816
|
+
var message = error.message;
|
|
817
|
+
var count = (counts[message] || 0) + 1;
|
|
818
|
+
counts[message] = count;
|
|
819
|
+
if (count >= mainErrorCount) {
|
|
820
|
+
mainError = error;
|
|
821
|
+
mainErrorCount = count;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
return mainError;
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
var require_retry = __commonJS2({
|
|
829
|
+
"../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js"(exports) {
|
|
830
|
+
"use strict";
|
|
831
|
+
var RetryOperation = require_retry_operation();
|
|
832
|
+
exports.operation = function(options) {
|
|
833
|
+
var timeouts = exports.timeouts(options);
|
|
834
|
+
return new RetryOperation(timeouts, {
|
|
835
|
+
forever: options && (options.forever || options.retries === Infinity),
|
|
836
|
+
unref: options && options.unref,
|
|
837
|
+
maxRetryTime: options && options.maxRetryTime
|
|
838
|
+
});
|
|
839
|
+
};
|
|
840
|
+
exports.timeouts = function(options) {
|
|
841
|
+
if (options instanceof Array) {
|
|
842
|
+
return [].concat(options);
|
|
843
|
+
}
|
|
844
|
+
var opts = {
|
|
845
|
+
retries: 10,
|
|
846
|
+
factor: 2,
|
|
847
|
+
minTimeout: 1 * 1e3,
|
|
848
|
+
maxTimeout: Infinity,
|
|
849
|
+
randomize: false
|
|
850
|
+
};
|
|
851
|
+
for (var key in options) {
|
|
852
|
+
opts[key] = options[key];
|
|
853
|
+
}
|
|
854
|
+
if (opts.minTimeout > opts.maxTimeout) {
|
|
855
|
+
throw new Error("minTimeout is greater than maxTimeout");
|
|
856
|
+
}
|
|
857
|
+
var timeouts = [];
|
|
858
|
+
for (var i = 0; i < opts.retries; i++) {
|
|
859
|
+
timeouts.push(this.createTimeout(i, opts));
|
|
860
|
+
}
|
|
861
|
+
if (options && options.forever && !timeouts.length) {
|
|
862
|
+
timeouts.push(this.createTimeout(i, opts));
|
|
863
|
+
}
|
|
864
|
+
timeouts.sort(function(a, b) {
|
|
865
|
+
return a - b;
|
|
866
|
+
});
|
|
867
|
+
return timeouts;
|
|
868
|
+
};
|
|
869
|
+
exports.createTimeout = function(attempt, opts) {
|
|
870
|
+
var random = opts.randomize ? Math.random() + 1 : 1;
|
|
871
|
+
var timeout = Math.round(random * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt));
|
|
872
|
+
timeout = Math.min(timeout, opts.maxTimeout);
|
|
873
|
+
return timeout;
|
|
874
|
+
};
|
|
875
|
+
exports.wrap = function(obj, options, methods) {
|
|
876
|
+
if (options instanceof Array) {
|
|
877
|
+
methods = options;
|
|
878
|
+
options = null;
|
|
879
|
+
}
|
|
880
|
+
if (!methods) {
|
|
881
|
+
methods = [];
|
|
882
|
+
for (var key in obj) {
|
|
883
|
+
if (typeof obj[key] === "function") {
|
|
884
|
+
methods.push(key);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
for (var i = 0; i < methods.length; i++) {
|
|
889
|
+
var method = methods[i];
|
|
890
|
+
var original = obj[method];
|
|
891
|
+
obj[method] = function retryWrapper(original2) {
|
|
892
|
+
var op = exports.operation(options);
|
|
893
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
|
894
|
+
var callback = args.pop();
|
|
895
|
+
args.push(function(err) {
|
|
896
|
+
if (op.retry(err)) {
|
|
897
|
+
return;
|
|
898
|
+
}
|
|
899
|
+
if (err) {
|
|
900
|
+
arguments[0] = op.mainError();
|
|
901
|
+
}
|
|
902
|
+
callback.apply(this, arguments);
|
|
903
|
+
});
|
|
904
|
+
op.attempt(function() {
|
|
905
|
+
original2.apply(obj, args);
|
|
906
|
+
});
|
|
907
|
+
}.bind(obj, original);
|
|
908
|
+
obj[method].options = options;
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
});
|
|
913
|
+
var require_retry2 = __commonJS2({
|
|
914
|
+
"../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js"(exports, module) {
|
|
915
|
+
"use strict";
|
|
916
|
+
module.exports = require_retry();
|
|
917
|
+
}
|
|
918
|
+
});
|
|
919
|
+
var import_p_limit2 = __toESM2(require_p_limit2());
|
|
920
|
+
var import_retry = __toESM2(require_retry2(), 1);
|
|
921
|
+
var networkErrorMsgs = /* @__PURE__ */ new Set([
|
|
922
|
+
"Failed to fetch",
|
|
923
|
+
// Chrome
|
|
924
|
+
"NetworkError when attempting to fetch resource.",
|
|
925
|
+
// Firefox
|
|
926
|
+
"The Internet connection appears to be offline.",
|
|
927
|
+
// Safari
|
|
928
|
+
"Network request failed",
|
|
929
|
+
// `cross-fetch`
|
|
930
|
+
"fetch failed"
|
|
931
|
+
// Undici (Node.js)
|
|
932
|
+
]);
|
|
933
|
+
var AbortError = class extends Error {
|
|
934
|
+
constructor(message) {
|
|
935
|
+
super();
|
|
936
|
+
if (message instanceof Error) {
|
|
937
|
+
this.originalError = message;
|
|
938
|
+
({ message } = message);
|
|
939
|
+
} else {
|
|
940
|
+
this.originalError = new Error(message);
|
|
941
|
+
this.originalError.stack = this.stack;
|
|
942
|
+
}
|
|
943
|
+
this.name = "AbortError";
|
|
944
|
+
this.message = message;
|
|
945
|
+
}
|
|
946
|
+
};
|
|
947
|
+
var decorateErrorWithCounts = (error, attemptNumber, options) => {
|
|
948
|
+
const retriesLeft = options.retries - (attemptNumber - 1);
|
|
949
|
+
error.attemptNumber = attemptNumber;
|
|
950
|
+
error.retriesLeft = retriesLeft;
|
|
951
|
+
return error;
|
|
952
|
+
};
|
|
953
|
+
var isNetworkError = (errorMessage) => networkErrorMsgs.has(errorMessage);
|
|
954
|
+
var getDOMException = (errorMessage) => globalThis.DOMException === void 0 ? new Error(errorMessage) : new DOMException(errorMessage);
|
|
955
|
+
async function pRetry(input, options) {
|
|
956
|
+
return new Promise((resolve, reject) => {
|
|
957
|
+
options = {
|
|
958
|
+
onFailedAttempt() {
|
|
959
|
+
},
|
|
960
|
+
retries: 10,
|
|
961
|
+
...options
|
|
962
|
+
};
|
|
963
|
+
const operation = import_retry.default.operation(options);
|
|
964
|
+
operation.attempt(async (attemptNumber) => {
|
|
965
|
+
try {
|
|
966
|
+
resolve(await input(attemptNumber));
|
|
967
|
+
} catch (error) {
|
|
968
|
+
if (!(error instanceof Error)) {
|
|
969
|
+
reject(new TypeError(`Non-error was thrown: "${error}". You should only throw errors.`));
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
if (error instanceof AbortError) {
|
|
973
|
+
operation.stop();
|
|
974
|
+
reject(error.originalError);
|
|
975
|
+
} else if (error instanceof TypeError && !isNetworkError(error.message)) {
|
|
976
|
+
operation.stop();
|
|
977
|
+
reject(error);
|
|
978
|
+
} else {
|
|
979
|
+
decorateErrorWithCounts(error, attemptNumber, options);
|
|
980
|
+
try {
|
|
981
|
+
await options.onFailedAttempt(error);
|
|
982
|
+
} catch (error2) {
|
|
983
|
+
reject(error2);
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
if (!operation.retry(error)) {
|
|
987
|
+
reject(operation.mainError());
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
});
|
|
992
|
+
if (options.signal && !options.signal.aborted) {
|
|
993
|
+
options.signal.addEventListener("abort", () => {
|
|
994
|
+
operation.stop();
|
|
995
|
+
const reason = options.signal.reason === void 0 ? getDOMException("The operation was aborted.") : options.signal.reason;
|
|
996
|
+
reject(reason instanceof Error ? reason : getDOMException(reason));
|
|
997
|
+
}, {
|
|
998
|
+
once: true
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
1003
|
+
var AbortError2 = class extends Error {
|
|
1004
|
+
constructor() {
|
|
1005
|
+
super("Throttled function aborted");
|
|
1006
|
+
this.name = "AbortError";
|
|
1007
|
+
}
|
|
1008
|
+
};
|
|
1009
|
+
function pThrottle({ limit, interval, strict }) {
|
|
1010
|
+
if (!Number.isFinite(limit)) {
|
|
1011
|
+
throw new TypeError("Expected `limit` to be a finite number");
|
|
1012
|
+
}
|
|
1013
|
+
if (!Number.isFinite(interval)) {
|
|
1014
|
+
throw new TypeError("Expected `interval` to be a finite number");
|
|
1015
|
+
}
|
|
1016
|
+
const queue = /* @__PURE__ */ new Map();
|
|
1017
|
+
let currentTick = 0;
|
|
1018
|
+
let activeCount = 0;
|
|
1019
|
+
function windowedDelay() {
|
|
1020
|
+
const now = Date.now();
|
|
1021
|
+
if (now - currentTick > interval) {
|
|
1022
|
+
activeCount = 1;
|
|
1023
|
+
currentTick = now;
|
|
1024
|
+
return 0;
|
|
1025
|
+
}
|
|
1026
|
+
if (activeCount < limit) {
|
|
1027
|
+
activeCount++;
|
|
1028
|
+
} else {
|
|
1029
|
+
currentTick += interval;
|
|
1030
|
+
activeCount = 1;
|
|
1031
|
+
}
|
|
1032
|
+
return currentTick - now;
|
|
1033
|
+
}
|
|
1034
|
+
const strictTicks = [];
|
|
1035
|
+
function strictDelay() {
|
|
1036
|
+
const now = Date.now();
|
|
1037
|
+
if (strictTicks.length < limit) {
|
|
1038
|
+
strictTicks.push(now);
|
|
1039
|
+
return 0;
|
|
1040
|
+
}
|
|
1041
|
+
const earliestTime = strictTicks.shift() + interval;
|
|
1042
|
+
if (now >= earliestTime) {
|
|
1043
|
+
strictTicks.push(now);
|
|
1044
|
+
return 0;
|
|
1045
|
+
}
|
|
1046
|
+
strictTicks.push(earliestTime);
|
|
1047
|
+
return earliestTime - now;
|
|
1048
|
+
}
|
|
1049
|
+
const getDelay = strict ? strictDelay : windowedDelay;
|
|
1050
|
+
return (function_) => {
|
|
1051
|
+
const throttled = function(...args) {
|
|
1052
|
+
if (!throttled.isEnabled) {
|
|
1053
|
+
return (async () => function_.apply(this, args))();
|
|
1054
|
+
}
|
|
1055
|
+
let timeout;
|
|
1056
|
+
return new Promise((resolve, reject) => {
|
|
1057
|
+
const execute = () => {
|
|
1058
|
+
resolve(function_.apply(this, args));
|
|
1059
|
+
queue.delete(timeout);
|
|
1060
|
+
};
|
|
1061
|
+
timeout = setTimeout(execute, getDelay());
|
|
1062
|
+
queue.set(timeout, reject);
|
|
1063
|
+
});
|
|
1064
|
+
};
|
|
1065
|
+
throttled.abort = () => {
|
|
1066
|
+
for (const timeout of queue.keys()) {
|
|
1067
|
+
clearTimeout(timeout);
|
|
1068
|
+
queue.get(timeout)(new AbortError2());
|
|
1069
|
+
}
|
|
1070
|
+
queue.clear();
|
|
1071
|
+
strictTicks.splice(0, strictTicks.length);
|
|
1072
|
+
};
|
|
1073
|
+
throttled.isEnabled = true;
|
|
1074
|
+
return throttled;
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
function createLimitPolicy({
|
|
1078
|
+
throttle = { interval: 1e3, limit: 10 },
|
|
1079
|
+
retry: retry2 = { retries: 1, factor: 1.66 },
|
|
1080
|
+
limit = 10
|
|
1081
|
+
}) {
|
|
1082
|
+
const throttler = throttle ? pThrottle(throttle) : null;
|
|
1083
|
+
const limiter = limit ? (0, import_p_limit2.default)(limit) : null;
|
|
1084
|
+
return function limitPolicy(func) {
|
|
1085
|
+
let currentFunc = async () => await func();
|
|
1086
|
+
if (throttler) {
|
|
1087
|
+
const throttleFunc = currentFunc;
|
|
1088
|
+
currentFunc = throttler(throttleFunc);
|
|
1089
|
+
}
|
|
1090
|
+
if (limiter) {
|
|
1091
|
+
const limitFunc = currentFunc;
|
|
1092
|
+
currentFunc = () => limiter(limitFunc);
|
|
1093
|
+
}
|
|
1094
|
+
if (retry2) {
|
|
1095
|
+
const retryFunc = currentFunc;
|
|
1096
|
+
currentFunc = () => pRetry(retryFunc, {
|
|
1097
|
+
...retry2,
|
|
1098
|
+
onFailedAttempt: async (error) => {
|
|
1099
|
+
if (retry2.onFailedAttempt) {
|
|
1100
|
+
await retry2.onFailedAttempt(error);
|
|
1101
|
+
}
|
|
1102
|
+
if (error instanceof ApiClientError && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
|
|
1103
|
+
throw error;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
return currentFunc();
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
1111
|
+
var isPlainObject = (obj) => typeof obj === "object" && obj !== null && !Array.isArray(obj);
|
|
1112
|
+
function rewriteFilters(filters) {
|
|
1113
|
+
return Object.entries(filters != null ? filters : {}).reduce(
|
|
1114
|
+
(acc, [key, value]) => {
|
|
1115
|
+
const lhs = `filters.${key}` + (isPlainObject(value) ? `[${Object.keys(value)[0]}]` : "");
|
|
1116
|
+
const rhs = isPlainObject(value) ? Object.values(value)[0] : value;
|
|
1117
|
+
return {
|
|
1118
|
+
...acc,
|
|
1119
|
+
[lhs]: Array.isArray(rhs) ? rhs.map((v) => `${v}`.trim()).join(",") : `${rhs}`.trim()
|
|
1120
|
+
};
|
|
1121
|
+
},
|
|
1122
|
+
{}
|
|
1123
|
+
);
|
|
1124
|
+
}
|
|
1125
|
+
var _contentTypesUrl;
|
|
1126
|
+
var _entriesUrl;
|
|
1127
|
+
var _ContentClient = class _ContentClient2 extends ApiClient {
|
|
1128
|
+
constructor(options) {
|
|
1129
|
+
var _a;
|
|
1130
|
+
super(options);
|
|
1131
|
+
this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
|
|
1132
|
+
}
|
|
1133
|
+
getContentTypes(options) {
|
|
1134
|
+
const { projectId } = this.options;
|
|
1135
|
+
const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _contentTypesUrl), { ...options, projectId });
|
|
1136
|
+
return this.apiClient(fetchUri);
|
|
1137
|
+
}
|
|
1138
|
+
getEntries(options) {
|
|
1139
|
+
const { projectId } = this.options;
|
|
1140
|
+
const { skipDataResolution, filters, ...params } = options;
|
|
1141
|
+
const rewrittenFilters = rewriteFilters(filters);
|
|
1142
|
+
if (skipDataResolution) {
|
|
1143
|
+
const url = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl), { ...params, ...rewrittenFilters, projectId });
|
|
1144
|
+
return this.apiClient(url);
|
|
1145
|
+
}
|
|
1146
|
+
const edgeUrl = this.createUrl(
|
|
1147
|
+
__privateGet2(_ContentClient2, _entriesUrl),
|
|
1148
|
+
{ ...this.getEdgeOptions(params), ...rewrittenFilters },
|
|
1149
|
+
this.edgeApiHost
|
|
1150
|
+
);
|
|
1151
|
+
return this.apiClient(
|
|
1152
|
+
edgeUrl,
|
|
1153
|
+
this.options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0
|
|
1154
|
+
);
|
|
1155
|
+
}
|
|
1156
|
+
/** Fetches historical versions of an entry */
|
|
1157
|
+
async getEntryHistory(options) {
|
|
1158
|
+
const historyUrl = this.createUrl("/api/v1/entries-history", {
|
|
1159
|
+
...options,
|
|
1160
|
+
projectId: this.options.projectId
|
|
1161
|
+
});
|
|
1162
|
+
return this.apiClient(historyUrl);
|
|
1163
|
+
}
|
|
1164
|
+
async upsertContentType(body, opts = {}) {
|
|
1165
|
+
const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _contentTypesUrl));
|
|
1166
|
+
if (typeof body.contentType.slugSettings === "object" && body.contentType.slugSettings !== null && Object.keys(body.contentType.slugSettings).length === 0) {
|
|
1167
|
+
delete body.contentType.slugSettings;
|
|
1168
|
+
}
|
|
1169
|
+
await this.apiClient(fetchUri, {
|
|
1170
|
+
method: "PUT",
|
|
1171
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1172
|
+
expectNoContent: true,
|
|
1173
|
+
headers: opts.autogenerateDataTypes ? { "x-uniform-autogenerate-data-types": "true" } : {}
|
|
1174
|
+
});
|
|
1175
|
+
}
|
|
1176
|
+
async upsertEntry(body, options) {
|
|
1177
|
+
const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl));
|
|
1178
|
+
const headers = {};
|
|
1179
|
+
if (options == null ? void 0 : options.ifUnmodifiedSince) {
|
|
1180
|
+
headers["x-if-unmodified-since"] = options.ifUnmodifiedSince;
|
|
1181
|
+
}
|
|
1182
|
+
const { response } = await this.apiClientWithResponse(fetchUri, {
|
|
1183
|
+
method: "PUT",
|
|
1184
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1185
|
+
expectNoContent: true,
|
|
1186
|
+
headers
|
|
1187
|
+
});
|
|
1188
|
+
return { modified: response.headers.get("x-modified-at") };
|
|
1189
|
+
}
|
|
1190
|
+
async deleteContentType(body) {
|
|
1191
|
+
const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _contentTypesUrl));
|
|
1192
|
+
await this.apiClient(fetchUri, {
|
|
1193
|
+
method: "DELETE",
|
|
1194
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1195
|
+
expectNoContent: true
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
async deleteEntry(body) {
|
|
1199
|
+
const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl));
|
|
1200
|
+
await this.apiClient(fetchUri, {
|
|
1201
|
+
method: "DELETE",
|
|
1202
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1203
|
+
expectNoContent: true
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
getEdgeOptions(options) {
|
|
1207
|
+
const { projectId } = this.options;
|
|
1208
|
+
const { skipDataResolution, ...params } = options;
|
|
1209
|
+
return {
|
|
1210
|
+
projectId,
|
|
1211
|
+
...params,
|
|
1212
|
+
diagnostics: typeof options.diagnostics === "boolean" ? options.diagnostics : options.diagnostics === "no-data" ? "no-data" : void 0
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
};
|
|
1216
|
+
_contentTypesUrl = /* @__PURE__ */ new WeakMap();
|
|
1217
|
+
_entriesUrl = /* @__PURE__ */ new WeakMap();
|
|
1218
|
+
__privateAdd2(_ContentClient, _contentTypesUrl, "/api/v1/content-types");
|
|
1219
|
+
__privateAdd2(_ContentClient, _entriesUrl, "/api/v1/entries");
|
|
1220
|
+
var _url8;
|
|
1221
|
+
var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
|
|
1222
|
+
constructor(options) {
|
|
1223
|
+
super(options);
|
|
1224
|
+
}
|
|
1225
|
+
/** Fetches all DataTypes for a project */
|
|
1226
|
+
async get(options) {
|
|
1227
|
+
const { projectId } = this.options;
|
|
1228
|
+
const fetchUri = this.createUrl(__privateGet2(_DataTypeClient2, _url8), { ...options, projectId });
|
|
1229
|
+
return await this.apiClient(fetchUri);
|
|
1230
|
+
}
|
|
1231
|
+
/** Updates or creates (based on id) a DataType */
|
|
1232
|
+
async upsert(body) {
|
|
1233
|
+
const fetchUri = this.createUrl(__privateGet2(_DataTypeClient2, _url8));
|
|
1234
|
+
await this.apiClient(fetchUri, {
|
|
1235
|
+
method: "PUT",
|
|
1236
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1237
|
+
expectNoContent: true
|
|
1238
|
+
});
|
|
1239
|
+
}
|
|
1240
|
+
/** Deletes a DataType */
|
|
1241
|
+
async remove(body) {
|
|
1242
|
+
const fetchUri = this.createUrl(__privateGet2(_DataTypeClient2, _url8));
|
|
1243
|
+
await this.apiClient(fetchUri, {
|
|
1244
|
+
method: "DELETE",
|
|
1245
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1246
|
+
expectNoContent: true
|
|
1247
|
+
});
|
|
1248
|
+
}
|
|
1249
|
+
};
|
|
1250
|
+
_url8 = /* @__PURE__ */ new WeakMap();
|
|
1251
|
+
__privateAdd2(_DataTypeClient, _url8, "/api/v1/data-types");
|
|
1252
|
+
var CANVAS_DRAFT_STATE = 0;
|
|
1253
|
+
var CANVAS_PUBLISHED_STATE = 64;
|
|
1254
|
+
var CANVAS_EDITOR_STATE = 63;
|
|
1255
|
+
var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
|
|
1256
|
+
var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
|
|
1257
|
+
var _baseUrl;
|
|
1258
|
+
var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2 extends ApiClient {
|
|
1259
|
+
constructor(options) {
|
|
1260
|
+
super(options);
|
|
1261
|
+
this.teamId = options.teamId;
|
|
1262
|
+
}
|
|
1263
|
+
/**
|
|
1264
|
+
* Gets a list of property type and hook names for the current team, including public integrations' hooks.
|
|
1265
|
+
*/
|
|
1266
|
+
get(options) {
|
|
1267
|
+
const fetchUri = this.createUrl(__privateGet2(_IntegrationPropertyEditorsClient2, _baseUrl), {
|
|
1268
|
+
...options,
|
|
1269
|
+
teamId: this.teamId
|
|
1270
|
+
});
|
|
1271
|
+
return this.apiClient(fetchUri);
|
|
1272
|
+
}
|
|
1273
|
+
/**
|
|
1274
|
+
* Creates or updates a custom AI property editor on a Mesh app.
|
|
1275
|
+
*/
|
|
1276
|
+
async deploy(body) {
|
|
1277
|
+
const fetchUri = this.createUrl(__privateGet2(_IntegrationPropertyEditorsClient2, _baseUrl));
|
|
1278
|
+
await this.apiClient(fetchUri, {
|
|
1279
|
+
method: "PUT",
|
|
1280
|
+
body: JSON.stringify({ ...body, teamId: this.teamId }),
|
|
1281
|
+
expectNoContent: true
|
|
1282
|
+
});
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* Removes a custom AI property editor from a Mesh app.
|
|
1286
|
+
*/
|
|
1287
|
+
async delete(body) {
|
|
1288
|
+
const fetchUri = this.createUrl(__privateGet2(_IntegrationPropertyEditorsClient2, _baseUrl));
|
|
1289
|
+
await this.apiClient(fetchUri, {
|
|
1290
|
+
method: "DELETE",
|
|
1291
|
+
body: JSON.stringify({ ...body, teamId: this.teamId }),
|
|
1292
|
+
expectNoContent: true
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
};
|
|
1296
|
+
_baseUrl = /* @__PURE__ */ new WeakMap();
|
|
1297
|
+
__privateAdd2(_IntegrationPropertyEditorsClient, _baseUrl, "/api/v1/integration-property-editors");
|
|
1298
|
+
var _url22;
|
|
1299
|
+
var _ProjectClient = class _ProjectClient2 extends ApiClient {
|
|
1300
|
+
constructor(options) {
|
|
1301
|
+
super({ ...options, bypassCache: true });
|
|
1302
|
+
}
|
|
1303
|
+
/** Fetches single Project */
|
|
1304
|
+
async get(options) {
|
|
1305
|
+
const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _url22), { ...options });
|
|
1306
|
+
return await this.apiClient(fetchUri);
|
|
1307
|
+
}
|
|
1308
|
+
/** Updates or creates (based on id) a Project */
|
|
1309
|
+
async upsert(body) {
|
|
1310
|
+
const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _url22));
|
|
1311
|
+
return await this.apiClient(fetchUri, {
|
|
1312
|
+
method: "PUT",
|
|
1313
|
+
body: JSON.stringify({ ...body })
|
|
1314
|
+
});
|
|
1315
|
+
}
|
|
1316
|
+
/** Deletes a Project */
|
|
1317
|
+
async delete(body) {
|
|
1318
|
+
const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _url22));
|
|
1319
|
+
await this.apiClient(fetchUri, {
|
|
1320
|
+
method: "DELETE",
|
|
1321
|
+
body: JSON.stringify({ ...body }),
|
|
1322
|
+
expectNoContent: true
|
|
1323
|
+
});
|
|
1324
|
+
}
|
|
1325
|
+
};
|
|
1326
|
+
_url22 = /* @__PURE__ */ new WeakMap();
|
|
1327
|
+
__privateAdd2(_ProjectClient, _url22, "/api/v1/project");
|
|
1328
|
+
var ROUTE_URL = "/api/v1/route";
|
|
1329
|
+
var RouteClient = class extends ApiClient {
|
|
1330
|
+
constructor(options) {
|
|
1331
|
+
var _a;
|
|
1332
|
+
if (!options.limitPolicy) {
|
|
1333
|
+
options.limitPolicy = createLimitPolicy({});
|
|
1334
|
+
}
|
|
1335
|
+
super(options);
|
|
1336
|
+
this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
|
|
1337
|
+
}
|
|
1338
|
+
/** Fetches lists of Canvas compositions, optionally by type */
|
|
1339
|
+
async getRoute(options) {
|
|
1340
|
+
const { projectId } = this.options;
|
|
1341
|
+
const fetchUri = this.createUrl(ROUTE_URL, { ...options, projectId }, this.edgeApiHost);
|
|
1342
|
+
return await this.apiClient(
|
|
1343
|
+
fetchUri,
|
|
1344
|
+
this.options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0
|
|
1345
|
+
);
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
|
|
1349
|
+
// src/data/client.ts
|
|
1350
|
+
import { getCache, waitUntil } from "@vercel/functions";
|
|
1351
|
+
|
|
1352
|
+
// src/clients/route.ts
|
|
1353
|
+
import "server-only";
|
|
1354
|
+
|
|
1355
|
+
// src/utils/env.ts
|
|
1356
|
+
var env = {
|
|
1357
|
+
getProjectId: () => {
|
|
1358
|
+
return process.env.UNIFORM_PROJECT_ID;
|
|
1359
|
+
},
|
|
1360
|
+
getApiKey: () => {
|
|
1361
|
+
return process.env.UNIFORM_API_KEY;
|
|
1362
|
+
},
|
|
1363
|
+
getApiHost: () => {
|
|
1364
|
+
return process.env.UNIFORM_API_HOST || process.env.UNIFORM_CLI_BASE_URL;
|
|
1365
|
+
},
|
|
1366
|
+
getEdgeApiHost: () => {
|
|
1367
|
+
return process.env.UNIFORM_EDGE_API_HOST || process.env.UNIFORM_CLI_BASE_EDGE_URL;
|
|
1368
|
+
}
|
|
1369
|
+
};
|
|
1370
|
+
|
|
1371
|
+
// src/config/helpers.ts
|
|
1372
|
+
import serverConfig from "uniform.server.config";
|
|
1373
|
+
var getServerConfig = () => {
|
|
1374
|
+
return serverConfig;
|
|
1375
|
+
};
|
|
1376
|
+
|
|
1377
|
+
// src/utils/draft.ts
|
|
1378
|
+
var isDraftModeEnabled = ({
|
|
1379
|
+
draftModeEnabled
|
|
1380
|
+
}) => {
|
|
1381
|
+
return draftModeEnabled;
|
|
1382
|
+
};
|
|
1383
|
+
var isIncontextEditingEnabled = ({ searchParams }) => {
|
|
1384
|
+
const containsKey = searchParams.has(IN_CONTEXT_EDITOR_QUERY_STRING_PARAM);
|
|
1385
|
+
return containsKey;
|
|
1386
|
+
};
|
|
1387
|
+
var isDevelopmentEnvironment = () => {
|
|
1388
|
+
return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
|
|
1389
|
+
};
|
|
1390
|
+
|
|
1391
|
+
// src/clients/cache.ts
|
|
1392
|
+
var isSpecificCacheMode = (options) => {
|
|
1393
|
+
return "cache" in options;
|
|
1394
|
+
};
|
|
1395
|
+
var isStateCacheMode = (options) => {
|
|
1396
|
+
return "state" in options;
|
|
1397
|
+
};
|
|
1398
|
+
var isDetectCacheMode = (options) => {
|
|
1399
|
+
return "searchParams" in options && "draftModeEnabled" in options;
|
|
1400
|
+
};
|
|
1401
|
+
var resolveManifestCache = (options) => {
|
|
1402
|
+
return resolveCache({
|
|
1403
|
+
options,
|
|
1404
|
+
defaultCache: getServerConfig().manifestCache
|
|
1405
|
+
});
|
|
1406
|
+
};
|
|
1407
|
+
var resolveCanvasCache = (options) => {
|
|
1408
|
+
return resolveCache({
|
|
1409
|
+
options,
|
|
1410
|
+
defaultCache: getServerConfig().canvasCache
|
|
1411
|
+
});
|
|
1412
|
+
};
|
|
1413
|
+
var resolveCache = ({
|
|
1414
|
+
options,
|
|
1415
|
+
defaultCache
|
|
1416
|
+
}) => {
|
|
1417
|
+
let cache = defaultCache;
|
|
1418
|
+
if (options) {
|
|
1419
|
+
if (isSpecificCacheMode(options)) {
|
|
1420
|
+
cache = options.cache;
|
|
1421
|
+
} else if (isStateCacheMode(options)) {
|
|
1422
|
+
if (options.state === CANVAS_DRAFT_STATE || options.state === CANVAS_EDITOR_STATE) {
|
|
1423
|
+
cache = {
|
|
1424
|
+
type: "no-cache",
|
|
1425
|
+
bypassCache: true
|
|
1426
|
+
};
|
|
1427
|
+
}
|
|
1428
|
+
} else if (isDetectCacheMode(options)) {
|
|
1429
|
+
const { disabled } = shouldCacheBeDisabled(options);
|
|
1430
|
+
if (disabled) {
|
|
1431
|
+
cache = {
|
|
1432
|
+
type: "no-cache",
|
|
1433
|
+
bypassCache: true
|
|
1434
|
+
};
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
return cache || {
|
|
1439
|
+
type: "force-cache"
|
|
1440
|
+
};
|
|
1441
|
+
};
|
|
1442
|
+
var shouldCacheBeDisabled = (options) => {
|
|
1443
|
+
if (isDraftModeEnabled(options)) {
|
|
1444
|
+
return { disabled: true, reason: "DRAFT" };
|
|
1445
|
+
}
|
|
1446
|
+
if (isIncontextEditingEnabled(options)) {
|
|
1447
|
+
return { disabled: true, reason: "INCONTEXT" };
|
|
1448
|
+
}
|
|
1449
|
+
if (isDevelopmentEnvironment()) {
|
|
1450
|
+
return { disabled: true, reason: "DEV" };
|
|
1451
|
+
}
|
|
1452
|
+
return {
|
|
1453
|
+
disabled: false,
|
|
1454
|
+
reason: void 0
|
|
1455
|
+
};
|
|
1456
|
+
};
|
|
1457
|
+
var determineFetchCacheOptions = (mode) => {
|
|
1458
|
+
let cache = void 0;
|
|
1459
|
+
let revalidate = void 0;
|
|
1460
|
+
if (mode.type === "revalidate") {
|
|
1461
|
+
cache = void 0;
|
|
1462
|
+
revalidate = mode.interval;
|
|
1463
|
+
} else {
|
|
1464
|
+
cache = mode.type;
|
|
1465
|
+
}
|
|
1466
|
+
return {
|
|
1467
|
+
cache,
|
|
1468
|
+
revalidate
|
|
1469
|
+
};
|
|
1470
|
+
};
|
|
1471
|
+
|
|
1472
|
+
// src/clients/retry.ts
|
|
1473
|
+
function createThrottler(limit, interval) {
|
|
1474
|
+
let available = limit;
|
|
1475
|
+
let refillScheduled = false;
|
|
1476
|
+
const waiting = [];
|
|
1477
|
+
function scheduleRefill() {
|
|
1478
|
+
if (refillScheduled) return;
|
|
1479
|
+
refillScheduled = true;
|
|
1480
|
+
setTimeout(() => {
|
|
1481
|
+
refillScheduled = false;
|
|
1482
|
+
available = limit;
|
|
1483
|
+
while (available > 0 && waiting.length > 0) {
|
|
1484
|
+
available--;
|
|
1485
|
+
const next = waiting.shift();
|
|
1486
|
+
next();
|
|
1487
|
+
}
|
|
1488
|
+
if (waiting.length > 0) {
|
|
1489
|
+
scheduleRefill();
|
|
1490
|
+
}
|
|
1491
|
+
}, interval);
|
|
1492
|
+
}
|
|
1493
|
+
return async function throttle(fn) {
|
|
1494
|
+
if (available > 0) {
|
|
1495
|
+
available--;
|
|
1496
|
+
if (!refillScheduled) {
|
|
1497
|
+
scheduleRefill();
|
|
1498
|
+
}
|
|
1499
|
+
return fn();
|
|
1500
|
+
}
|
|
1501
|
+
return new Promise((resolve, reject) => {
|
|
1502
|
+
waiting.push(() => {
|
|
1503
|
+
fn().then(resolve, reject);
|
|
1504
|
+
});
|
|
1505
|
+
scheduleRefill();
|
|
1506
|
+
});
|
|
1507
|
+
};
|
|
1508
|
+
}
|
|
1509
|
+
function createLimiter(concurrency) {
|
|
1510
|
+
let active = 0;
|
|
1511
|
+
const queue = [];
|
|
1512
|
+
return async function limit(fn) {
|
|
1513
|
+
return new Promise((resolve, reject) => {
|
|
1514
|
+
const run = async () => {
|
|
1515
|
+
active++;
|
|
1516
|
+
try {
|
|
1517
|
+
const result = await fn();
|
|
1518
|
+
resolve(result);
|
|
1519
|
+
} catch (error) {
|
|
1520
|
+
reject(error);
|
|
1521
|
+
} finally {
|
|
1522
|
+
active--;
|
|
1523
|
+
if (queue.length > 0) {
|
|
1524
|
+
const next = queue.shift();
|
|
1525
|
+
next();
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
};
|
|
1529
|
+
if (active < concurrency) {
|
|
1530
|
+
run();
|
|
1531
|
+
} else {
|
|
1532
|
+
queue.push(run);
|
|
1533
|
+
}
|
|
1534
|
+
});
|
|
1535
|
+
};
|
|
1536
|
+
}
|
|
1537
|
+
async function retry(fn, options) {
|
|
1538
|
+
let lastError;
|
|
1539
|
+
let delay = 1e3;
|
|
1540
|
+
for (let attempt = 1; attempt <= options.retries + 1; attempt++) {
|
|
1541
|
+
try {
|
|
1542
|
+
return await fn();
|
|
1543
|
+
} catch (error) {
|
|
1544
|
+
lastError = error;
|
|
1545
|
+
const attemptError = Object.assign(error, { attemptNumber: attempt });
|
|
1546
|
+
if (options.onFailedAttempt) {
|
|
1547
|
+
await options.onFailedAttempt(attemptError);
|
|
1548
|
+
}
|
|
1549
|
+
if (attempt > options.retries) {
|
|
1550
|
+
throw error;
|
|
1551
|
+
}
|
|
1552
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1553
|
+
delay *= options.factor;
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
throw lastError;
|
|
1557
|
+
}
|
|
1558
|
+
function createLimitPolicy2({
|
|
1559
|
+
throttle = { interval: 1e3, limit: 10 },
|
|
1560
|
+
retry: retryOptions = { retries: 1, factor: 1.66 },
|
|
1561
|
+
limit = 10
|
|
1562
|
+
}) {
|
|
1563
|
+
const throttler = throttle ? createThrottler(throttle.limit, throttle.interval) : null;
|
|
1564
|
+
const limiter = limit ? createLimiter(limit) : null;
|
|
1565
|
+
return function limitPolicy(func) {
|
|
1566
|
+
let currentFunc = async () => await func();
|
|
1567
|
+
if (throttler) {
|
|
1568
|
+
const throttleFunc = currentFunc;
|
|
1569
|
+
currentFunc = () => throttler(throttleFunc);
|
|
1570
|
+
}
|
|
1571
|
+
if (limiter) {
|
|
1572
|
+
const limitFunc = currentFunc;
|
|
1573
|
+
currentFunc = () => limiter(limitFunc);
|
|
1574
|
+
}
|
|
1575
|
+
if (retryOptions) {
|
|
1576
|
+
const retryFunc = currentFunc;
|
|
1577
|
+
currentFunc = () => retry(retryFunc, {
|
|
1578
|
+
...retryOptions,
|
|
1579
|
+
onFailedAttempt: async (error) => {
|
|
1580
|
+
if (retryOptions.onFailedAttempt) {
|
|
1581
|
+
await retryOptions.onFailedAttempt(error);
|
|
1582
|
+
}
|
|
1583
|
+
if (error instanceof ApiClientError && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
|
|
1584
|
+
throw error;
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
});
|
|
1588
|
+
}
|
|
1589
|
+
return currentFunc();
|
|
1590
|
+
};
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
// src/utils/tag.ts
|
|
1594
|
+
var buildPathTag = (path) => {
|
|
1595
|
+
const actualPath = path.startsWith("/") ? path : `/${path}`;
|
|
1596
|
+
return `path:${actualPath}`.toLowerCase();
|
|
1597
|
+
};
|
|
1598
|
+
|
|
1599
|
+
// src/clients/tags.ts
|
|
1600
|
+
var generateRouteCacheTags = ({ path, old }) => {
|
|
1601
|
+
const tags = old ? ["route-old"] : ["route"];
|
|
1602
|
+
if (path) {
|
|
1603
|
+
const pathWithoutQuery = path.split("?")[0];
|
|
1604
|
+
const pieces = pathWithoutQuery.split("/");
|
|
1605
|
+
for (let i = 0; i < pieces.length; i++) {
|
|
1606
|
+
const segmentPieces = pieces.slice(0, i + 1);
|
|
1607
|
+
const segment = segmentPieces.join("/");
|
|
1608
|
+
tags.push(buildPathTag(segment));
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
return tags;
|
|
1612
|
+
};
|
|
1613
|
+
var generateManifestCacheTags = () => {
|
|
1614
|
+
return ["manifest"];
|
|
1615
|
+
};
|
|
1616
|
+
|
|
1617
|
+
// src/clients/route.ts
|
|
1618
|
+
var getRouteCacheTags = (requestedUrl) => {
|
|
1619
|
+
const tags = ["route"];
|
|
1620
|
+
if (requestedUrl) {
|
|
1621
|
+
const pathKey = "path";
|
|
1622
|
+
const path = requestedUrl.searchParams.get(pathKey);
|
|
1623
|
+
if (path) {
|
|
1624
|
+
return generateRouteCacheTags({ path });
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
return tags;
|
|
1628
|
+
};
|
|
1629
|
+
var getRouteClient = (options) => {
|
|
1630
|
+
const cache = resolveCanvasCache(options);
|
|
1631
|
+
const client = new RouteClient({
|
|
1632
|
+
projectId: env.getProjectId(),
|
|
1633
|
+
apiKey: env.getApiKey(),
|
|
1634
|
+
edgeApiHost: env.getEdgeApiHost(),
|
|
1635
|
+
disableSWR: typeof cache.disableSWR !== "undefined" ? cache.disableSWR : true,
|
|
1636
|
+
limitPolicy: createLimitPolicy2({
|
|
1637
|
+
limit: 6
|
|
1638
|
+
}),
|
|
1639
|
+
fetch: (req, init) => {
|
|
1640
|
+
let requestedUrl;
|
|
1641
|
+
if (typeof req === "string") {
|
|
1642
|
+
requestedUrl = new URL(req);
|
|
1643
|
+
} else if (req instanceof URL) {
|
|
1644
|
+
requestedUrl = req;
|
|
1645
|
+
} else {
|
|
1646
|
+
requestedUrl = new URL(req.url);
|
|
1647
|
+
}
|
|
1648
|
+
const tags = getRouteCacheTags(requestedUrl);
|
|
1649
|
+
const { cache: fetchCache, revalidate } = determineFetchCacheOptions(cache);
|
|
1650
|
+
return fetch(req, {
|
|
1651
|
+
...init,
|
|
1652
|
+
headers: {
|
|
1653
|
+
...init == null ? void 0 : init.headers,
|
|
1654
|
+
"x-bypass-cache": typeof cache.bypassCache !== "undefined" ? cache.bypassCache.toString() : "false"
|
|
1655
|
+
},
|
|
1656
|
+
cache: fetchCache,
|
|
1657
|
+
next: {
|
|
1658
|
+
revalidate,
|
|
1659
|
+
tags: tags.length ? tags : void 0
|
|
1660
|
+
}
|
|
1661
|
+
});
|
|
1662
|
+
}
|
|
1663
|
+
});
|
|
1664
|
+
return client;
|
|
1665
|
+
};
|
|
1666
|
+
|
|
1667
|
+
// src/clients/manifest.ts
|
|
1668
|
+
import "server-only";
|
|
1669
|
+
var getManifestClient = (options) => {
|
|
1670
|
+
const cache = resolveManifestCache(options);
|
|
1671
|
+
const manifestClient = new ManifestClient({
|
|
1672
|
+
apiHost: env.getApiHost(),
|
|
1673
|
+
apiKey: env.getApiKey(),
|
|
1674
|
+
projectId: env.getProjectId(),
|
|
1675
|
+
limitPolicy: createLimitPolicy2({
|
|
1676
|
+
limit: 6
|
|
1677
|
+
}),
|
|
1678
|
+
fetch: (req, init) => {
|
|
1679
|
+
const { cache: fetchCache, revalidate } = determineFetchCacheOptions(cache);
|
|
1680
|
+
return fetch(req, {
|
|
1681
|
+
...init,
|
|
1682
|
+
headers: {
|
|
1683
|
+
...init == null ? void 0 : init.headers,
|
|
1684
|
+
"x-bypass-cache": typeof cache.bypassCache !== "undefined" ? cache.bypassCache.toString() : "false"
|
|
1685
|
+
},
|
|
1686
|
+
cache: fetchCache,
|
|
1687
|
+
next: {
|
|
1688
|
+
revalidate,
|
|
1689
|
+
tags: generateManifestCacheTags()
|
|
1690
|
+
}
|
|
1691
|
+
});
|
|
1692
|
+
}
|
|
1693
|
+
});
|
|
1694
|
+
return manifestClient;
|
|
1695
|
+
};
|
|
1696
|
+
var getManifest = async (options) => {
|
|
1697
|
+
let preview = false;
|
|
1698
|
+
if (options && isStateCacheMode(options)) {
|
|
1699
|
+
preview = options.state === CANVAS_DRAFT_STATE || options.state === CANVAS_EDITOR_STATE;
|
|
1700
|
+
}
|
|
1701
|
+
const manifestClient = getManifestClient(options);
|
|
1702
|
+
return manifestClient.get({
|
|
1703
|
+
preview
|
|
1704
|
+
});
|
|
1705
|
+
};
|
|
1706
|
+
|
|
1707
|
+
// src/data/client.ts
|
|
1708
|
+
var MANIFEST_CACHE_KEY = "uniform-manifest";
|
|
1709
|
+
var DefaultDataClient = class {
|
|
1710
|
+
async getManifest(options) {
|
|
1711
|
+
var _a, _b;
|
|
1712
|
+
const cache = options.source === "middleware" && ((_b = (_a = getServerConfig().experimental) == null ? void 0 : _a.middlewareRuntimeCache) != null ? _b : false) ? getCache() : null;
|
|
1713
|
+
if (cache) {
|
|
1714
|
+
const cachedManifest = await cache.get(MANIFEST_CACHE_KEY);
|
|
1715
|
+
if (cachedManifest) {
|
|
1716
|
+
return cachedManifest;
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
const manifest = await getManifest({
|
|
1720
|
+
cache: {
|
|
1721
|
+
type: "force-cache"
|
|
1722
|
+
}
|
|
1723
|
+
});
|
|
1724
|
+
if (cache) {
|
|
1725
|
+
waitUntil(
|
|
1726
|
+
(async () => {
|
|
1727
|
+
await cache.set(MANIFEST_CACHE_KEY, manifest, {
|
|
1728
|
+
tags: generateManifestCacheTags()
|
|
1729
|
+
});
|
|
1730
|
+
})()
|
|
1731
|
+
);
|
|
1732
|
+
}
|
|
1733
|
+
return manifest;
|
|
1734
|
+
}
|
|
1735
|
+
async getRouteFromApi({
|
|
1736
|
+
route,
|
|
1737
|
+
routeClient,
|
|
1738
|
+
enableRuntimeCache,
|
|
1739
|
+
disableSwrCache
|
|
1740
|
+
}) {
|
|
1741
|
+
const newCacheKey = `uniform-route-${route.state}-${route.releaseId}-${route.path}`;
|
|
1742
|
+
const oldCacheKey = `uniform-route-old-${route.state}-${route.releaseId}-${route.path}`;
|
|
1743
|
+
const cache = enableRuntimeCache ? getCache() : null;
|
|
1744
|
+
const cacheNewRoute = async (result2) => {
|
|
1745
|
+
if (cache && result2.type === "composition") {
|
|
1746
|
+
const tags = generateRouteCacheTags({ path: route.path });
|
|
1747
|
+
await cache.set(newCacheKey, result2, {
|
|
1748
|
+
tags
|
|
1749
|
+
});
|
|
1750
|
+
}
|
|
1751
|
+
};
|
|
1752
|
+
const cacheOldRoute = async (result2) => {
|
|
1753
|
+
if (cache && result2.type === "composition" && !disableSwrCache) {
|
|
1754
|
+
const tags = generateRouteCacheTags({ path: route.path, old: true });
|
|
1755
|
+
await cache.set(oldCacheKey, result2, {
|
|
1756
|
+
tags
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
};
|
|
1760
|
+
if (cache) {
|
|
1761
|
+
const [cachedRoute, oldCachedRoute] = await Promise.all([
|
|
1762
|
+
cache.get(newCacheKey),
|
|
1763
|
+
disableSwrCache ? null : cache.get(oldCacheKey)
|
|
1764
|
+
]);
|
|
1765
|
+
if (cachedRoute) {
|
|
1766
|
+
return cachedRoute;
|
|
1767
|
+
}
|
|
1768
|
+
if (oldCachedRoute) {
|
|
1769
|
+
waitUntil(
|
|
1770
|
+
(async () => {
|
|
1771
|
+
const result2 = await routeClient.getRoute(route);
|
|
1772
|
+
await cacheNewRoute(result2);
|
|
1773
|
+
})()
|
|
1774
|
+
);
|
|
1775
|
+
return oldCachedRoute;
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
const result = await routeClient.getRoute(route);
|
|
1779
|
+
waitUntil(
|
|
1780
|
+
(async () => {
|
|
1781
|
+
await Promise.all([
|
|
1782
|
+
cacheNewRoute(result),
|
|
1783
|
+
disableSwrCache ? Promise.resolve() : cacheOldRoute(result)
|
|
1784
|
+
]);
|
|
1785
|
+
})()
|
|
1786
|
+
);
|
|
1787
|
+
return result;
|
|
1788
|
+
}
|
|
1789
|
+
async getRoute(options) {
|
|
1790
|
+
if (options.source === "middleware") {
|
|
1791
|
+
return this.getRouteMiddleware(options);
|
|
1792
|
+
}
|
|
1793
|
+
return this.getRoutePageState(options);
|
|
1794
|
+
}
|
|
1795
|
+
async enhanceRoute(_options) {
|
|
1796
|
+
}
|
|
1797
|
+
async getRouteMiddleware(options) {
|
|
1798
|
+
var _a, _b, _c, _d;
|
|
1799
|
+
const routeClient = getRouteClient({
|
|
1800
|
+
searchParams: options.searchParams,
|
|
1801
|
+
draftModeEnabled: options.draftModeEnabled
|
|
1802
|
+
});
|
|
1803
|
+
const config = getServerConfig();
|
|
1804
|
+
const resolvedRoute = await this.getRouteFromApi({
|
|
1805
|
+
source: "middleware",
|
|
1806
|
+
route: options.route,
|
|
1807
|
+
routeClient,
|
|
1808
|
+
enableRuntimeCache: options.route.state === CANVAS_PUBLISHED_STATE && ((_b = (_a = config.experimental) == null ? void 0 : _a.middlewareRuntimeCache) != null ? _b : false),
|
|
1809
|
+
disableSwrCache: (_d = (_c = config.experimental) == null ? void 0 : _c.disableSwrMiddlewareCache) != null ? _d : false
|
|
1810
|
+
});
|
|
1811
|
+
if (resolvedRoute.type === "composition") {
|
|
1812
|
+
await this.enhanceRoute({
|
|
1813
|
+
source: "middleware",
|
|
1814
|
+
parameters: options.route,
|
|
1815
|
+
route: resolvedRoute,
|
|
1816
|
+
routeClient,
|
|
1817
|
+
keys: void 0
|
|
1818
|
+
});
|
|
1819
|
+
}
|
|
1820
|
+
return {
|
|
1821
|
+
route: resolvedRoute
|
|
1822
|
+
};
|
|
1823
|
+
}
|
|
1824
|
+
async getRoutePageState(options) {
|
|
1825
|
+
var _a;
|
|
1826
|
+
const routeClient = getRouteClient({
|
|
1827
|
+
cache: options.pageState.compositionState === CANVAS_PUBLISHED_STATE ? (_a = getServerConfig().canvasCache) != null ? _a : {
|
|
1828
|
+
type: "force-cache"
|
|
1829
|
+
} : {
|
|
1830
|
+
type: "no-cache"
|
|
1831
|
+
}
|
|
1832
|
+
});
|
|
1833
|
+
const originalRoute = {
|
|
1834
|
+
path: options.pageState.routePath,
|
|
1835
|
+
state: options.pageState.compositionState,
|
|
1836
|
+
withComponentIDs: true,
|
|
1837
|
+
releaseId: options.pageState.releaseId
|
|
1838
|
+
};
|
|
1839
|
+
const resolvedRoute = await this.getRouteFromApi({
|
|
1840
|
+
source: "pageState",
|
|
1841
|
+
route: originalRoute,
|
|
1842
|
+
routeClient,
|
|
1843
|
+
enableRuntimeCache: false,
|
|
1844
|
+
disableSwrCache: false
|
|
1845
|
+
});
|
|
1846
|
+
if (resolvedRoute.type === "composition") {
|
|
1847
|
+
await this.enhanceRoute({
|
|
1848
|
+
source: "pageState",
|
|
1849
|
+
parameters: originalRoute,
|
|
1850
|
+
route: resolvedRoute,
|
|
1851
|
+
routeClient,
|
|
1852
|
+
keys: options.pageState.keys
|
|
1853
|
+
});
|
|
1854
|
+
}
|
|
1855
|
+
return {
|
|
1856
|
+
route: resolvedRoute
|
|
1857
|
+
};
|
|
1858
|
+
}
|
|
1859
|
+
};
|
|
1860
|
+
|
|
1861
|
+
// src/data/resolveRouteFromCode.ts
|
|
1862
|
+
var resolveRouteFromCode = async ({
|
|
1863
|
+
params,
|
|
1864
|
+
dataClient: providedDataClient
|
|
1865
|
+
}) => {
|
|
1866
|
+
const { code } = await params;
|
|
1867
|
+
const pageState = deserializeEvaluationResult({ input: code });
|
|
1868
|
+
const dataClient = providedDataClient != null ? providedDataClient : new DefaultDataClient();
|
|
1869
|
+
const { route } = await dataClient.getRoute({
|
|
1870
|
+
source: "pageState",
|
|
1871
|
+
pageState
|
|
1872
|
+
});
|
|
1873
|
+
return {
|
|
1874
|
+
pageState,
|
|
1875
|
+
// suppress the route if it's not a composition
|
|
1876
|
+
route: (route == null ? void 0 : route.type) === "composition" ? route : void 0,
|
|
1877
|
+
// the code that was used to resolve the route
|
|
1878
|
+
code
|
|
1879
|
+
};
|
|
1880
|
+
};
|
|
1881
|
+
|
|
1882
|
+
// src/cache.ts
|
|
1883
|
+
var resolveRouteFromCode2 = async ({
|
|
1884
|
+
params,
|
|
1885
|
+
dataClient: providedDataClient
|
|
1886
|
+
}) => {
|
|
1887
|
+
"use cache";
|
|
1888
|
+
const result = await resolveRouteFromCode({
|
|
1889
|
+
params,
|
|
1890
|
+
dataClient: providedDataClient
|
|
1891
|
+
});
|
|
1892
|
+
if (process.env.NODE_ENV === "development") {
|
|
1893
|
+
cacheLife({
|
|
1894
|
+
expire: 0,
|
|
1895
|
+
revalidate: 0,
|
|
1896
|
+
stale: 0
|
|
1897
|
+
});
|
|
1898
|
+
}
|
|
1899
|
+
return result;
|
|
1900
|
+
};
|
|
1901
|
+
export {
|
|
1902
|
+
resolveRouteFromCode2 as resolveRouteFromCode
|
|
1903
|
+
};
|