@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/handler.js
ADDED
|
@@ -0,0 +1,2664 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
+
|
|
33
|
+
// ../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js
|
|
34
|
+
var require_yocto_queue = __commonJS({
|
|
35
|
+
"../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js"(exports2, module2) {
|
|
36
|
+
"use strict";
|
|
37
|
+
var Node = class {
|
|
38
|
+
/// value;
|
|
39
|
+
/// next;
|
|
40
|
+
constructor(value) {
|
|
41
|
+
this.value = value;
|
|
42
|
+
this.next = void 0;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var Queue = class {
|
|
46
|
+
// TODO: Use private class fields when targeting Node.js 12.
|
|
47
|
+
// #_head;
|
|
48
|
+
// #_tail;
|
|
49
|
+
// #_size;
|
|
50
|
+
constructor() {
|
|
51
|
+
this.clear();
|
|
52
|
+
}
|
|
53
|
+
enqueue(value) {
|
|
54
|
+
const node = new Node(value);
|
|
55
|
+
if (this._head) {
|
|
56
|
+
this._tail.next = node;
|
|
57
|
+
this._tail = node;
|
|
58
|
+
} else {
|
|
59
|
+
this._head = node;
|
|
60
|
+
this._tail = node;
|
|
61
|
+
}
|
|
62
|
+
this._size++;
|
|
63
|
+
}
|
|
64
|
+
dequeue() {
|
|
65
|
+
const current = this._head;
|
|
66
|
+
if (!current) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
this._head = this._head.next;
|
|
70
|
+
this._size--;
|
|
71
|
+
return current.value;
|
|
72
|
+
}
|
|
73
|
+
clear() {
|
|
74
|
+
this._head = void 0;
|
|
75
|
+
this._tail = void 0;
|
|
76
|
+
this._size = 0;
|
|
77
|
+
}
|
|
78
|
+
get size() {
|
|
79
|
+
return this._size;
|
|
80
|
+
}
|
|
81
|
+
*[Symbol.iterator]() {
|
|
82
|
+
let current = this._head;
|
|
83
|
+
while (current) {
|
|
84
|
+
yield current.value;
|
|
85
|
+
current = current.next;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
module2.exports = Queue;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// ../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js
|
|
94
|
+
var require_p_limit = __commonJS({
|
|
95
|
+
"../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js"(exports2, module2) {
|
|
96
|
+
"use strict";
|
|
97
|
+
var Queue = require_yocto_queue();
|
|
98
|
+
var pLimit2 = (concurrency) => {
|
|
99
|
+
if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
|
|
100
|
+
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
101
|
+
}
|
|
102
|
+
const queue = new Queue();
|
|
103
|
+
let activeCount = 0;
|
|
104
|
+
const next = () => {
|
|
105
|
+
activeCount--;
|
|
106
|
+
if (queue.size > 0) {
|
|
107
|
+
queue.dequeue()();
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const run = async (fn, resolve, ...args) => {
|
|
111
|
+
activeCount++;
|
|
112
|
+
const result = (async () => fn(...args))();
|
|
113
|
+
resolve(result);
|
|
114
|
+
try {
|
|
115
|
+
await result;
|
|
116
|
+
} catch (e) {
|
|
117
|
+
}
|
|
118
|
+
next();
|
|
119
|
+
};
|
|
120
|
+
const enqueue = (fn, resolve, ...args) => {
|
|
121
|
+
queue.enqueue(run.bind(null, fn, resolve, ...args));
|
|
122
|
+
(async () => {
|
|
123
|
+
await Promise.resolve();
|
|
124
|
+
if (activeCount < concurrency && queue.size > 0) {
|
|
125
|
+
queue.dequeue()();
|
|
126
|
+
}
|
|
127
|
+
})();
|
|
128
|
+
};
|
|
129
|
+
const generator = (fn, ...args) => new Promise((resolve) => {
|
|
130
|
+
enqueue(fn, resolve, ...args);
|
|
131
|
+
});
|
|
132
|
+
Object.defineProperties(generator, {
|
|
133
|
+
activeCount: {
|
|
134
|
+
get: () => activeCount
|
|
135
|
+
},
|
|
136
|
+
pendingCount: {
|
|
137
|
+
get: () => queue.size
|
|
138
|
+
},
|
|
139
|
+
clearQueue: {
|
|
140
|
+
value: () => {
|
|
141
|
+
queue.clear();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
return generator;
|
|
146
|
+
};
|
|
147
|
+
module2.exports = pLimit2;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// src/handler.ts
|
|
152
|
+
var handler_exports = {};
|
|
153
|
+
__export(handler_exports, {
|
|
154
|
+
createPreviewGETRouteHandler: () => createPreviewGETRouteHandler,
|
|
155
|
+
createPreviewOPTIONSRouteHandler: () => createPreviewOPTIONSRouteHandler,
|
|
156
|
+
createPreviewPOSTRouteHandler: () => createPreviewPOSTRouteHandler
|
|
157
|
+
});
|
|
158
|
+
module.exports = __toCommonJS(handler_exports);
|
|
159
|
+
|
|
160
|
+
// ../context/dist/api/api.mjs
|
|
161
|
+
var import_p_limit = __toESM(require_p_limit(), 1);
|
|
162
|
+
var __defProp2 = Object.defineProperty;
|
|
163
|
+
var __typeError = (msg) => {
|
|
164
|
+
throw TypeError(msg);
|
|
165
|
+
};
|
|
166
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
167
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
168
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
169
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
170
|
+
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);
|
|
171
|
+
var defaultLimitPolicy = (0, import_p_limit.default)(6);
|
|
172
|
+
var ApiClientError = class _ApiClientError extends Error {
|
|
173
|
+
constructor(errorMessage, fetchMethod, fetchUri, statusCode, statusText, requestId) {
|
|
174
|
+
super(
|
|
175
|
+
`${errorMessage}
|
|
176
|
+
${statusCode}${statusText ? " " + statusText : ""} (${fetchMethod} ${fetchUri}${requestId ? ` Request ID: ${requestId}` : ""})`
|
|
177
|
+
);
|
|
178
|
+
this.errorMessage = errorMessage;
|
|
179
|
+
this.fetchMethod = fetchMethod;
|
|
180
|
+
this.fetchUri = fetchUri;
|
|
181
|
+
this.statusCode = statusCode;
|
|
182
|
+
this.statusText = statusText;
|
|
183
|
+
this.requestId = requestId;
|
|
184
|
+
Object.setPrototypeOf(this, _ApiClientError.prototype);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
var ApiClient = class _ApiClient {
|
|
188
|
+
constructor(options) {
|
|
189
|
+
__publicField(this, "options");
|
|
190
|
+
var _a, _b, _c, _d, _e;
|
|
191
|
+
if (!options.apiKey && !options.bearerToken) {
|
|
192
|
+
throw new Error("You must provide an API key or a bearer token");
|
|
193
|
+
}
|
|
194
|
+
let leFetch = options.fetch;
|
|
195
|
+
if (!leFetch) {
|
|
196
|
+
if (typeof window !== "undefined") {
|
|
197
|
+
leFetch = window.fetch.bind(window);
|
|
198
|
+
} else if (typeof fetch !== "undefined") {
|
|
199
|
+
leFetch = fetch;
|
|
200
|
+
} else {
|
|
201
|
+
throw new Error("You must provide or polyfill a fetch implementation when not in a browser");
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
this.options = {
|
|
205
|
+
...options,
|
|
206
|
+
fetch: leFetch,
|
|
207
|
+
apiHost: this.ensureApiHost(options.apiHost),
|
|
208
|
+
apiKey: (_a = options.apiKey) != null ? _a : null,
|
|
209
|
+
projectId: (_b = options.projectId) != null ? _b : null,
|
|
210
|
+
bearerToken: (_c = options.bearerToken) != null ? _c : null,
|
|
211
|
+
limitPolicy: (_d = options.limitPolicy) != null ? _d : defaultLimitPolicy,
|
|
212
|
+
bypassCache: (_e = options.bypassCache) != null ? _e : false
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
async apiClient(fetchUri, options) {
|
|
216
|
+
return (await this.apiClientWithResponse(fetchUri, options)).body;
|
|
217
|
+
}
|
|
218
|
+
async apiClientWithResponse(fetchUri, options) {
|
|
219
|
+
return this.options.limitPolicy(async () => {
|
|
220
|
+
var _a;
|
|
221
|
+
const coreHeaders = this.options.apiKey ? {
|
|
222
|
+
"x-api-key": this.options.apiKey
|
|
223
|
+
} : {
|
|
224
|
+
Authorization: `Bearer ${this.options.bearerToken}`
|
|
225
|
+
};
|
|
226
|
+
if (this.options.bypassCache) {
|
|
227
|
+
coreHeaders["x-bypass-cache"] = "true";
|
|
228
|
+
}
|
|
229
|
+
const { fetch: fetch2, signal } = this.options;
|
|
230
|
+
const callApi = () => fetch2(fetchUri.toString(), {
|
|
231
|
+
...options,
|
|
232
|
+
signal,
|
|
233
|
+
headers: {
|
|
234
|
+
...options == null ? void 0 : options.headers,
|
|
235
|
+
...coreHeaders
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
const apiResponse = await handleRateLimits(callApi);
|
|
239
|
+
if (!apiResponse.ok) {
|
|
240
|
+
let message = "";
|
|
241
|
+
try {
|
|
242
|
+
const responseText = await apiResponse.text();
|
|
243
|
+
try {
|
|
244
|
+
const parsed = JSON.parse(responseText);
|
|
245
|
+
if (parsed.errorMessage) {
|
|
246
|
+
message = Array.isArray(parsed.errorMessage) ? parsed.errorMessage.join(", ") : parsed.errorMessage;
|
|
247
|
+
} else {
|
|
248
|
+
message = responseText;
|
|
249
|
+
}
|
|
250
|
+
} catch (e) {
|
|
251
|
+
message = responseText;
|
|
252
|
+
}
|
|
253
|
+
} catch (e) {
|
|
254
|
+
message = `General error`;
|
|
255
|
+
}
|
|
256
|
+
throw new ApiClientError(
|
|
257
|
+
message,
|
|
258
|
+
(_a = options == null ? void 0 : options.method) != null ? _a : "GET",
|
|
259
|
+
fetchUri.toString(),
|
|
260
|
+
apiResponse.status,
|
|
261
|
+
apiResponse.statusText,
|
|
262
|
+
_ApiClient.getRequestId(apiResponse)
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
if (options == null ? void 0 : options.expectNoContent) {
|
|
266
|
+
return { response: apiResponse, body: null };
|
|
267
|
+
}
|
|
268
|
+
return {
|
|
269
|
+
response: apiResponse,
|
|
270
|
+
body: await apiResponse.json()
|
|
271
|
+
};
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
createUrl(path, queryParams, hostOverride) {
|
|
275
|
+
const url = new URL(`${hostOverride != null ? hostOverride : this.options.apiHost}${path}`);
|
|
276
|
+
Object.entries(queryParams != null ? queryParams : {}).forEach(([key, value]) => {
|
|
277
|
+
var _a;
|
|
278
|
+
if (typeof value !== "undefined" && value !== null) {
|
|
279
|
+
url.searchParams.append(key, Array.isArray(value) ? value.join(",") : (_a = value == null ? void 0 : value.toString()) != null ? _a : "");
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
return url;
|
|
283
|
+
}
|
|
284
|
+
ensureApiHost(apiHost) {
|
|
285
|
+
if (!apiHost) return "https://uniform.app";
|
|
286
|
+
if (!(apiHost == null ? void 0 : apiHost.startsWith("http"))) {
|
|
287
|
+
throw new Error('Your apiHost must start with "http"');
|
|
288
|
+
}
|
|
289
|
+
if (apiHost.indexOf("/", 8) > -1) {
|
|
290
|
+
throw new Error("Your apiHost must not contain a path element after the domain");
|
|
291
|
+
}
|
|
292
|
+
if (apiHost.indexOf("?") > -1) {
|
|
293
|
+
throw new Error("Your apiHost must not contain a query string");
|
|
294
|
+
}
|
|
295
|
+
if (apiHost == null ? void 0 : apiHost.endsWith("/")) {
|
|
296
|
+
apiHost = apiHost.substring(0, apiHost.length - 1);
|
|
297
|
+
}
|
|
298
|
+
return apiHost;
|
|
299
|
+
}
|
|
300
|
+
static getRequestId(response) {
|
|
301
|
+
const apigRequestId = response.headers.get("apigw-requestid");
|
|
302
|
+
if (apigRequestId) {
|
|
303
|
+
return apigRequestId;
|
|
304
|
+
}
|
|
305
|
+
return void 0;
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
async function handleRateLimits(callApi) {
|
|
309
|
+
var _a;
|
|
310
|
+
const backoffRetries = 5;
|
|
311
|
+
let backoffRetriesLeft = backoffRetries;
|
|
312
|
+
let response;
|
|
313
|
+
while (backoffRetriesLeft > 0) {
|
|
314
|
+
response = await callApi();
|
|
315
|
+
if (response.status !== 429) {
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
let resetWait = 0;
|
|
319
|
+
try {
|
|
320
|
+
const responseClone = response.clone();
|
|
321
|
+
const dateHeader = responseClone.headers.get("date");
|
|
322
|
+
const serverTime = dateHeader ? new Date(dateHeader).getTime() : void 0;
|
|
323
|
+
const body = await responseClone.json();
|
|
324
|
+
const resetTime = (_a = body == null ? void 0 : body.info) == null ? void 0 : _a.reset;
|
|
325
|
+
if (typeof serverTime === "number" && typeof resetTime === "number") {
|
|
326
|
+
resetWait = Math.max(0, Math.min(Math.round(1.1 * (resetTime - serverTime)), 1e4));
|
|
327
|
+
}
|
|
328
|
+
} catch (e) {
|
|
329
|
+
}
|
|
330
|
+
const base = Math.pow(2, backoffRetries - backoffRetriesLeft) * 333;
|
|
331
|
+
const backoffWait = base + Math.round(Math.random() * (base / 2)) * (Math.random() > 0.5 ? 1 : -1);
|
|
332
|
+
await new Promise((resolve) => setTimeout(resolve, resetWait + backoffWait));
|
|
333
|
+
backoffRetriesLeft -= 1;
|
|
334
|
+
}
|
|
335
|
+
return response;
|
|
336
|
+
}
|
|
337
|
+
var _url;
|
|
338
|
+
var _AggregateClient = class _AggregateClient2 extends ApiClient {
|
|
339
|
+
constructor(options) {
|
|
340
|
+
super(options);
|
|
341
|
+
}
|
|
342
|
+
/** Fetches all aggregates for a project */
|
|
343
|
+
async get(options) {
|
|
344
|
+
const { projectId } = this.options;
|
|
345
|
+
const fetchUri = this.createUrl(__privateGet(_AggregateClient2, _url), { ...options, projectId });
|
|
346
|
+
return await this.apiClient(fetchUri);
|
|
347
|
+
}
|
|
348
|
+
/** Updates or creates (based on id) an Aggregate */
|
|
349
|
+
async upsert(body) {
|
|
350
|
+
const fetchUri = this.createUrl(__privateGet(_AggregateClient2, _url));
|
|
351
|
+
await this.apiClient(fetchUri, {
|
|
352
|
+
method: "PUT",
|
|
353
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
354
|
+
expectNoContent: true
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
/** Deletes an Aggregate */
|
|
358
|
+
async remove(body) {
|
|
359
|
+
const fetchUri = this.createUrl(__privateGet(_AggregateClient2, _url));
|
|
360
|
+
await this.apiClient(fetchUri, {
|
|
361
|
+
method: "DELETE",
|
|
362
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
363
|
+
expectNoContent: true
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
_url = /* @__PURE__ */ new WeakMap();
|
|
368
|
+
__privateAdd(_AggregateClient, _url, "/api/v2/aggregate");
|
|
369
|
+
var _url2;
|
|
370
|
+
var _DimensionClient = class _DimensionClient2 extends ApiClient {
|
|
371
|
+
constructor(options) {
|
|
372
|
+
super(options);
|
|
373
|
+
}
|
|
374
|
+
/** Fetches the known score dimensions for a project */
|
|
375
|
+
async get(options) {
|
|
376
|
+
const { projectId } = this.options;
|
|
377
|
+
const fetchUri = this.createUrl(__privateGet(_DimensionClient2, _url2), { ...options, projectId });
|
|
378
|
+
return await this.apiClient(fetchUri);
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
_url2 = /* @__PURE__ */ new WeakMap();
|
|
382
|
+
__privateAdd(_DimensionClient, _url2, "/api/v2/dimension");
|
|
383
|
+
var _url3;
|
|
384
|
+
var _valueUrl;
|
|
385
|
+
var _EnrichmentClient = class _EnrichmentClient2 extends ApiClient {
|
|
386
|
+
constructor(options) {
|
|
387
|
+
super(options);
|
|
388
|
+
}
|
|
389
|
+
/** Fetches all enrichments and values for a project, grouped by category */
|
|
390
|
+
async get(options) {
|
|
391
|
+
const { projectId } = this.options;
|
|
392
|
+
const fetchUri = this.createUrl(__privateGet(_EnrichmentClient2, _url3), { ...options, projectId });
|
|
393
|
+
return await this.apiClient(fetchUri);
|
|
394
|
+
}
|
|
395
|
+
/** Updates or creates (based on id) an enrichment category */
|
|
396
|
+
async upsertCategory(body) {
|
|
397
|
+
const fetchUri = this.createUrl(__privateGet(_EnrichmentClient2, _url3));
|
|
398
|
+
await this.apiClient(fetchUri, {
|
|
399
|
+
method: "PUT",
|
|
400
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
401
|
+
expectNoContent: true
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
/** Deletes an enrichment category */
|
|
405
|
+
async removeCategory(body) {
|
|
406
|
+
const fetchUri = this.createUrl(__privateGet(_EnrichmentClient2, _url3));
|
|
407
|
+
await this.apiClient(fetchUri, {
|
|
408
|
+
method: "DELETE",
|
|
409
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
410
|
+
expectNoContent: true
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
/** Updates or creates (based on id) an enrichment value within an enrichment category */
|
|
414
|
+
async upsertValue(body) {
|
|
415
|
+
const fetchUri = this.createUrl(__privateGet(_EnrichmentClient2, _valueUrl));
|
|
416
|
+
await this.apiClient(fetchUri, {
|
|
417
|
+
method: "PUT",
|
|
418
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
419
|
+
expectNoContent: true
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
/** Deletes an enrichment value within an enrichment category. The category is left alone. */
|
|
423
|
+
async removeValue(body) {
|
|
424
|
+
const fetchUri = this.createUrl(__privateGet(_EnrichmentClient2, _valueUrl));
|
|
425
|
+
await this.apiClient(fetchUri, {
|
|
426
|
+
method: "DELETE",
|
|
427
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
428
|
+
expectNoContent: true
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
_url3 = /* @__PURE__ */ new WeakMap();
|
|
433
|
+
_valueUrl = /* @__PURE__ */ new WeakMap();
|
|
434
|
+
__privateAdd(_EnrichmentClient, _url3, "/api/v1/enrichments");
|
|
435
|
+
__privateAdd(_EnrichmentClient, _valueUrl, "/api/v1/enrichment-values");
|
|
436
|
+
var _url4;
|
|
437
|
+
var _ManifestClient = class _ManifestClient2 extends ApiClient {
|
|
438
|
+
constructor(options) {
|
|
439
|
+
super(options);
|
|
440
|
+
}
|
|
441
|
+
/** Fetches the Context manifest for a project */
|
|
442
|
+
async get(options) {
|
|
443
|
+
const { projectId } = this.options;
|
|
444
|
+
const fetchUri = this.createUrl(__privateGet(_ManifestClient2, _url4), { ...options, projectId });
|
|
445
|
+
return await this.apiClient(fetchUri);
|
|
446
|
+
}
|
|
447
|
+
/** Publishes the Context manifest for a project */
|
|
448
|
+
async publish() {
|
|
449
|
+
const { projectId } = this.options;
|
|
450
|
+
const fetchUri = this.createUrl("/api/v1/publish", { siteId: projectId });
|
|
451
|
+
await this.apiClient(fetchUri, {
|
|
452
|
+
method: "POST",
|
|
453
|
+
expectNoContent: true
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
_url4 = /* @__PURE__ */ new WeakMap();
|
|
458
|
+
__privateAdd(_ManifestClient, _url4, "/api/v2/manifest");
|
|
459
|
+
var _url5;
|
|
460
|
+
var _QuirkClient = class _QuirkClient2 extends ApiClient {
|
|
461
|
+
constructor(options) {
|
|
462
|
+
super(options);
|
|
463
|
+
}
|
|
464
|
+
/** Fetches all Quirks for a project */
|
|
465
|
+
async get(options) {
|
|
466
|
+
const { projectId } = this.options;
|
|
467
|
+
const fetchUri = this.createUrl(__privateGet(_QuirkClient2, _url5), { ...options, projectId });
|
|
468
|
+
return await this.apiClient(fetchUri);
|
|
469
|
+
}
|
|
470
|
+
/** Updates or creates (based on id) a Quirk */
|
|
471
|
+
async upsert(body) {
|
|
472
|
+
const fetchUri = this.createUrl(__privateGet(_QuirkClient2, _url5));
|
|
473
|
+
await this.apiClient(fetchUri, {
|
|
474
|
+
method: "PUT",
|
|
475
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
476
|
+
expectNoContent: true
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
/** Deletes a Quirk */
|
|
480
|
+
async remove(body) {
|
|
481
|
+
const fetchUri = this.createUrl(__privateGet(_QuirkClient2, _url5));
|
|
482
|
+
await this.apiClient(fetchUri, {
|
|
483
|
+
method: "DELETE",
|
|
484
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
485
|
+
expectNoContent: true
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
_url5 = /* @__PURE__ */ new WeakMap();
|
|
490
|
+
__privateAdd(_QuirkClient, _url5, "/api/v2/quirk");
|
|
491
|
+
var _url6;
|
|
492
|
+
var _SignalClient = class _SignalClient2 extends ApiClient {
|
|
493
|
+
constructor(options) {
|
|
494
|
+
super(options);
|
|
495
|
+
}
|
|
496
|
+
/** Fetches all Signals for a project */
|
|
497
|
+
async get(options) {
|
|
498
|
+
const { projectId } = this.options;
|
|
499
|
+
const fetchUri = this.createUrl(__privateGet(_SignalClient2, _url6), { ...options, projectId });
|
|
500
|
+
return await this.apiClient(fetchUri);
|
|
501
|
+
}
|
|
502
|
+
/** Updates or creates (based on id) a Signal */
|
|
503
|
+
async upsert(body) {
|
|
504
|
+
const fetchUri = this.createUrl(__privateGet(_SignalClient2, _url6));
|
|
505
|
+
await this.apiClient(fetchUri, {
|
|
506
|
+
method: "PUT",
|
|
507
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
508
|
+
expectNoContent: true
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
/** Deletes a Signal */
|
|
512
|
+
async remove(body) {
|
|
513
|
+
const fetchUri = this.createUrl(__privateGet(_SignalClient2, _url6));
|
|
514
|
+
await this.apiClient(fetchUri, {
|
|
515
|
+
method: "DELETE",
|
|
516
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
517
|
+
expectNoContent: true
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
_url6 = /* @__PURE__ */ new WeakMap();
|
|
522
|
+
__privateAdd(_SignalClient, _url6, "/api/v2/signal");
|
|
523
|
+
var _url7;
|
|
524
|
+
var _TestClient = class _TestClient2 extends ApiClient {
|
|
525
|
+
constructor(options) {
|
|
526
|
+
super(options);
|
|
527
|
+
}
|
|
528
|
+
/** Fetches all Tests for a project */
|
|
529
|
+
async get(options) {
|
|
530
|
+
const { projectId } = this.options;
|
|
531
|
+
const fetchUri = this.createUrl(__privateGet(_TestClient2, _url7), { ...options, projectId });
|
|
532
|
+
return await this.apiClient(fetchUri);
|
|
533
|
+
}
|
|
534
|
+
/** Updates or creates (based on id) a Test */
|
|
535
|
+
async upsert(body) {
|
|
536
|
+
const fetchUri = this.createUrl(__privateGet(_TestClient2, _url7));
|
|
537
|
+
await this.apiClient(fetchUri, {
|
|
538
|
+
method: "PUT",
|
|
539
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
540
|
+
expectNoContent: true
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
/** Deletes a Test */
|
|
544
|
+
async remove(body) {
|
|
545
|
+
const fetchUri = this.createUrl(__privateGet(_TestClient2, _url7));
|
|
546
|
+
await this.apiClient(fetchUri, {
|
|
547
|
+
method: "DELETE",
|
|
548
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
549
|
+
expectNoContent: true
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
_url7 = /* @__PURE__ */ new WeakMap();
|
|
554
|
+
__privateAdd(_TestClient, _url7, "/api/v2/test");
|
|
555
|
+
|
|
556
|
+
// ../canvas/dist/index.mjs
|
|
557
|
+
var __create2 = Object.create;
|
|
558
|
+
var __defProp3 = Object.defineProperty;
|
|
559
|
+
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
560
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
561
|
+
var __getProtoOf2 = Object.getPrototypeOf;
|
|
562
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
563
|
+
var __typeError2 = (msg) => {
|
|
564
|
+
throw TypeError(msg);
|
|
565
|
+
};
|
|
566
|
+
var __commonJS2 = (cb, mod) => function __require() {
|
|
567
|
+
return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
568
|
+
};
|
|
569
|
+
var __copyProps2 = (to, from, except, desc) => {
|
|
570
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
571
|
+
for (let key of __getOwnPropNames2(from))
|
|
572
|
+
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
573
|
+
__defProp3(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
|
574
|
+
}
|
|
575
|
+
return to;
|
|
576
|
+
};
|
|
577
|
+
var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
|
|
578
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
579
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
580
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
581
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
582
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp3(target, "default", { value: mod, enumerable: true }) : target,
|
|
583
|
+
mod
|
|
584
|
+
));
|
|
585
|
+
var __accessCheck2 = (obj, member, msg) => member.has(obj) || __typeError2("Cannot " + msg);
|
|
586
|
+
var __privateGet2 = (obj, member, getter) => (__accessCheck2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
587
|
+
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);
|
|
588
|
+
var require_yocto_queue2 = __commonJS2({
|
|
589
|
+
"../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js"(exports2, module2) {
|
|
590
|
+
"use strict";
|
|
591
|
+
var Node = class {
|
|
592
|
+
/// value;
|
|
593
|
+
/// next;
|
|
594
|
+
constructor(value) {
|
|
595
|
+
this.value = value;
|
|
596
|
+
this.next = void 0;
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
var Queue = class {
|
|
600
|
+
// TODO: Use private class fields when targeting Node.js 12.
|
|
601
|
+
// #_head;
|
|
602
|
+
// #_tail;
|
|
603
|
+
// #_size;
|
|
604
|
+
constructor() {
|
|
605
|
+
this.clear();
|
|
606
|
+
}
|
|
607
|
+
enqueue(value) {
|
|
608
|
+
const node = new Node(value);
|
|
609
|
+
if (this._head) {
|
|
610
|
+
this._tail.next = node;
|
|
611
|
+
this._tail = node;
|
|
612
|
+
} else {
|
|
613
|
+
this._head = node;
|
|
614
|
+
this._tail = node;
|
|
615
|
+
}
|
|
616
|
+
this._size++;
|
|
617
|
+
}
|
|
618
|
+
dequeue() {
|
|
619
|
+
const current = this._head;
|
|
620
|
+
if (!current) {
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
this._head = this._head.next;
|
|
624
|
+
this._size--;
|
|
625
|
+
return current.value;
|
|
626
|
+
}
|
|
627
|
+
clear() {
|
|
628
|
+
this._head = void 0;
|
|
629
|
+
this._tail = void 0;
|
|
630
|
+
this._size = 0;
|
|
631
|
+
}
|
|
632
|
+
get size() {
|
|
633
|
+
return this._size;
|
|
634
|
+
}
|
|
635
|
+
*[Symbol.iterator]() {
|
|
636
|
+
let current = this._head;
|
|
637
|
+
while (current) {
|
|
638
|
+
yield current.value;
|
|
639
|
+
current = current.next;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
module2.exports = Queue;
|
|
644
|
+
}
|
|
645
|
+
});
|
|
646
|
+
var require_p_limit2 = __commonJS2({
|
|
647
|
+
"../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js"(exports2, module2) {
|
|
648
|
+
"use strict";
|
|
649
|
+
var Queue = require_yocto_queue2();
|
|
650
|
+
var pLimit2 = (concurrency) => {
|
|
651
|
+
if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
|
|
652
|
+
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
653
|
+
}
|
|
654
|
+
const queue = new Queue();
|
|
655
|
+
let activeCount = 0;
|
|
656
|
+
const next = () => {
|
|
657
|
+
activeCount--;
|
|
658
|
+
if (queue.size > 0) {
|
|
659
|
+
queue.dequeue()();
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
const run = async (fn, resolve, ...args) => {
|
|
663
|
+
activeCount++;
|
|
664
|
+
const result = (async () => fn(...args))();
|
|
665
|
+
resolve(result);
|
|
666
|
+
try {
|
|
667
|
+
await result;
|
|
668
|
+
} catch (e) {
|
|
669
|
+
}
|
|
670
|
+
next();
|
|
671
|
+
};
|
|
672
|
+
const enqueue = (fn, resolve, ...args) => {
|
|
673
|
+
queue.enqueue(run.bind(null, fn, resolve, ...args));
|
|
674
|
+
(async () => {
|
|
675
|
+
await Promise.resolve();
|
|
676
|
+
if (activeCount < concurrency && queue.size > 0) {
|
|
677
|
+
queue.dequeue()();
|
|
678
|
+
}
|
|
679
|
+
})();
|
|
680
|
+
};
|
|
681
|
+
const generator = (fn, ...args) => new Promise((resolve) => {
|
|
682
|
+
enqueue(fn, resolve, ...args);
|
|
683
|
+
});
|
|
684
|
+
Object.defineProperties(generator, {
|
|
685
|
+
activeCount: {
|
|
686
|
+
get: () => activeCount
|
|
687
|
+
},
|
|
688
|
+
pendingCount: {
|
|
689
|
+
get: () => queue.size
|
|
690
|
+
},
|
|
691
|
+
clearQueue: {
|
|
692
|
+
value: () => {
|
|
693
|
+
queue.clear();
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
});
|
|
697
|
+
return generator;
|
|
698
|
+
};
|
|
699
|
+
module2.exports = pLimit2;
|
|
700
|
+
}
|
|
701
|
+
});
|
|
702
|
+
var require_retry_operation = __commonJS2({
|
|
703
|
+
"../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js"(exports2, module2) {
|
|
704
|
+
"use strict";
|
|
705
|
+
function RetryOperation(timeouts, options) {
|
|
706
|
+
if (typeof options === "boolean") {
|
|
707
|
+
options = { forever: options };
|
|
708
|
+
}
|
|
709
|
+
this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
|
|
710
|
+
this._timeouts = timeouts;
|
|
711
|
+
this._options = options || {};
|
|
712
|
+
this._maxRetryTime = options && options.maxRetryTime || Infinity;
|
|
713
|
+
this._fn = null;
|
|
714
|
+
this._errors = [];
|
|
715
|
+
this._attempts = 1;
|
|
716
|
+
this._operationTimeout = null;
|
|
717
|
+
this._operationTimeoutCb = null;
|
|
718
|
+
this._timeout = null;
|
|
719
|
+
this._operationStart = null;
|
|
720
|
+
this._timer = null;
|
|
721
|
+
if (this._options.forever) {
|
|
722
|
+
this._cachedTimeouts = this._timeouts.slice(0);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
module2.exports = RetryOperation;
|
|
726
|
+
RetryOperation.prototype.reset = function() {
|
|
727
|
+
this._attempts = 1;
|
|
728
|
+
this._timeouts = this._originalTimeouts.slice(0);
|
|
729
|
+
};
|
|
730
|
+
RetryOperation.prototype.stop = function() {
|
|
731
|
+
if (this._timeout) {
|
|
732
|
+
clearTimeout(this._timeout);
|
|
733
|
+
}
|
|
734
|
+
if (this._timer) {
|
|
735
|
+
clearTimeout(this._timer);
|
|
736
|
+
}
|
|
737
|
+
this._timeouts = [];
|
|
738
|
+
this._cachedTimeouts = null;
|
|
739
|
+
};
|
|
740
|
+
RetryOperation.prototype.retry = function(err) {
|
|
741
|
+
if (this._timeout) {
|
|
742
|
+
clearTimeout(this._timeout);
|
|
743
|
+
}
|
|
744
|
+
if (!err) {
|
|
745
|
+
return false;
|
|
746
|
+
}
|
|
747
|
+
var currentTime = (/* @__PURE__ */ new Date()).getTime();
|
|
748
|
+
if (err && currentTime - this._operationStart >= this._maxRetryTime) {
|
|
749
|
+
this._errors.push(err);
|
|
750
|
+
this._errors.unshift(new Error("RetryOperation timeout occurred"));
|
|
751
|
+
return false;
|
|
752
|
+
}
|
|
753
|
+
this._errors.push(err);
|
|
754
|
+
var timeout = this._timeouts.shift();
|
|
755
|
+
if (timeout === void 0) {
|
|
756
|
+
if (this._cachedTimeouts) {
|
|
757
|
+
this._errors.splice(0, this._errors.length - 1);
|
|
758
|
+
timeout = this._cachedTimeouts.slice(-1);
|
|
759
|
+
} else {
|
|
760
|
+
return false;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
var self = this;
|
|
764
|
+
this._timer = setTimeout(function() {
|
|
765
|
+
self._attempts++;
|
|
766
|
+
if (self._operationTimeoutCb) {
|
|
767
|
+
self._timeout = setTimeout(function() {
|
|
768
|
+
self._operationTimeoutCb(self._attempts);
|
|
769
|
+
}, self._operationTimeout);
|
|
770
|
+
if (self._options.unref) {
|
|
771
|
+
self._timeout.unref();
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
self._fn(self._attempts);
|
|
775
|
+
}, timeout);
|
|
776
|
+
if (this._options.unref) {
|
|
777
|
+
this._timer.unref();
|
|
778
|
+
}
|
|
779
|
+
return true;
|
|
780
|
+
};
|
|
781
|
+
RetryOperation.prototype.attempt = function(fn, timeoutOps) {
|
|
782
|
+
this._fn = fn;
|
|
783
|
+
if (timeoutOps) {
|
|
784
|
+
if (timeoutOps.timeout) {
|
|
785
|
+
this._operationTimeout = timeoutOps.timeout;
|
|
786
|
+
}
|
|
787
|
+
if (timeoutOps.cb) {
|
|
788
|
+
this._operationTimeoutCb = timeoutOps.cb;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
var self = this;
|
|
792
|
+
if (this._operationTimeoutCb) {
|
|
793
|
+
this._timeout = setTimeout(function() {
|
|
794
|
+
self._operationTimeoutCb();
|
|
795
|
+
}, self._operationTimeout);
|
|
796
|
+
}
|
|
797
|
+
this._operationStart = (/* @__PURE__ */ new Date()).getTime();
|
|
798
|
+
this._fn(this._attempts);
|
|
799
|
+
};
|
|
800
|
+
RetryOperation.prototype.try = function(fn) {
|
|
801
|
+
console.log("Using RetryOperation.try() is deprecated");
|
|
802
|
+
this.attempt(fn);
|
|
803
|
+
};
|
|
804
|
+
RetryOperation.prototype.start = function(fn) {
|
|
805
|
+
console.log("Using RetryOperation.start() is deprecated");
|
|
806
|
+
this.attempt(fn);
|
|
807
|
+
};
|
|
808
|
+
RetryOperation.prototype.start = RetryOperation.prototype.try;
|
|
809
|
+
RetryOperation.prototype.errors = function() {
|
|
810
|
+
return this._errors;
|
|
811
|
+
};
|
|
812
|
+
RetryOperation.prototype.attempts = function() {
|
|
813
|
+
return this._attempts;
|
|
814
|
+
};
|
|
815
|
+
RetryOperation.prototype.mainError = function() {
|
|
816
|
+
if (this._errors.length === 0) {
|
|
817
|
+
return null;
|
|
818
|
+
}
|
|
819
|
+
var counts = {};
|
|
820
|
+
var mainError = null;
|
|
821
|
+
var mainErrorCount = 0;
|
|
822
|
+
for (var i = 0; i < this._errors.length; i++) {
|
|
823
|
+
var error = this._errors[i];
|
|
824
|
+
var message = error.message;
|
|
825
|
+
var count = (counts[message] || 0) + 1;
|
|
826
|
+
counts[message] = count;
|
|
827
|
+
if (count >= mainErrorCount) {
|
|
828
|
+
mainError = error;
|
|
829
|
+
mainErrorCount = count;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
return mainError;
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
});
|
|
836
|
+
var require_retry = __commonJS2({
|
|
837
|
+
"../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js"(exports2) {
|
|
838
|
+
"use strict";
|
|
839
|
+
var RetryOperation = require_retry_operation();
|
|
840
|
+
exports2.operation = function(options) {
|
|
841
|
+
var timeouts = exports2.timeouts(options);
|
|
842
|
+
return new RetryOperation(timeouts, {
|
|
843
|
+
forever: options && (options.forever || options.retries === Infinity),
|
|
844
|
+
unref: options && options.unref,
|
|
845
|
+
maxRetryTime: options && options.maxRetryTime
|
|
846
|
+
});
|
|
847
|
+
};
|
|
848
|
+
exports2.timeouts = function(options) {
|
|
849
|
+
if (options instanceof Array) {
|
|
850
|
+
return [].concat(options);
|
|
851
|
+
}
|
|
852
|
+
var opts = {
|
|
853
|
+
retries: 10,
|
|
854
|
+
factor: 2,
|
|
855
|
+
minTimeout: 1 * 1e3,
|
|
856
|
+
maxTimeout: Infinity,
|
|
857
|
+
randomize: false
|
|
858
|
+
};
|
|
859
|
+
for (var key in options) {
|
|
860
|
+
opts[key] = options[key];
|
|
861
|
+
}
|
|
862
|
+
if (opts.minTimeout > opts.maxTimeout) {
|
|
863
|
+
throw new Error("minTimeout is greater than maxTimeout");
|
|
864
|
+
}
|
|
865
|
+
var timeouts = [];
|
|
866
|
+
for (var i = 0; i < opts.retries; i++) {
|
|
867
|
+
timeouts.push(this.createTimeout(i, opts));
|
|
868
|
+
}
|
|
869
|
+
if (options && options.forever && !timeouts.length) {
|
|
870
|
+
timeouts.push(this.createTimeout(i, opts));
|
|
871
|
+
}
|
|
872
|
+
timeouts.sort(function(a, b) {
|
|
873
|
+
return a - b;
|
|
874
|
+
});
|
|
875
|
+
return timeouts;
|
|
876
|
+
};
|
|
877
|
+
exports2.createTimeout = function(attempt, opts) {
|
|
878
|
+
var random = opts.randomize ? Math.random() + 1 : 1;
|
|
879
|
+
var timeout = Math.round(random * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt));
|
|
880
|
+
timeout = Math.min(timeout, opts.maxTimeout);
|
|
881
|
+
return timeout;
|
|
882
|
+
};
|
|
883
|
+
exports2.wrap = function(obj, options, methods) {
|
|
884
|
+
if (options instanceof Array) {
|
|
885
|
+
methods = options;
|
|
886
|
+
options = null;
|
|
887
|
+
}
|
|
888
|
+
if (!methods) {
|
|
889
|
+
methods = [];
|
|
890
|
+
for (var key in obj) {
|
|
891
|
+
if (typeof obj[key] === "function") {
|
|
892
|
+
methods.push(key);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
for (var i = 0; i < methods.length; i++) {
|
|
897
|
+
var method = methods[i];
|
|
898
|
+
var original = obj[method];
|
|
899
|
+
obj[method] = function retryWrapper(original2) {
|
|
900
|
+
var op = exports2.operation(options);
|
|
901
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
|
902
|
+
var callback = args.pop();
|
|
903
|
+
args.push(function(err) {
|
|
904
|
+
if (op.retry(err)) {
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
if (err) {
|
|
908
|
+
arguments[0] = op.mainError();
|
|
909
|
+
}
|
|
910
|
+
callback.apply(this, arguments);
|
|
911
|
+
});
|
|
912
|
+
op.attempt(function() {
|
|
913
|
+
original2.apply(obj, args);
|
|
914
|
+
});
|
|
915
|
+
}.bind(obj, original);
|
|
916
|
+
obj[method].options = options;
|
|
917
|
+
}
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
});
|
|
921
|
+
var require_retry2 = __commonJS2({
|
|
922
|
+
"../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js"(exports2, module2) {
|
|
923
|
+
"use strict";
|
|
924
|
+
module2.exports = require_retry();
|
|
925
|
+
}
|
|
926
|
+
});
|
|
927
|
+
var import_p_limit2 = __toESM2(require_p_limit2());
|
|
928
|
+
var import_retry = __toESM2(require_retry2(), 1);
|
|
929
|
+
var networkErrorMsgs = /* @__PURE__ */ new Set([
|
|
930
|
+
"Failed to fetch",
|
|
931
|
+
// Chrome
|
|
932
|
+
"NetworkError when attempting to fetch resource.",
|
|
933
|
+
// Firefox
|
|
934
|
+
"The Internet connection appears to be offline.",
|
|
935
|
+
// Safari
|
|
936
|
+
"Network request failed",
|
|
937
|
+
// `cross-fetch`
|
|
938
|
+
"fetch failed"
|
|
939
|
+
// Undici (Node.js)
|
|
940
|
+
]);
|
|
941
|
+
var AbortError = class extends Error {
|
|
942
|
+
constructor(message) {
|
|
943
|
+
super();
|
|
944
|
+
if (message instanceof Error) {
|
|
945
|
+
this.originalError = message;
|
|
946
|
+
({ message } = message);
|
|
947
|
+
} else {
|
|
948
|
+
this.originalError = new Error(message);
|
|
949
|
+
this.originalError.stack = this.stack;
|
|
950
|
+
}
|
|
951
|
+
this.name = "AbortError";
|
|
952
|
+
this.message = message;
|
|
953
|
+
}
|
|
954
|
+
};
|
|
955
|
+
var decorateErrorWithCounts = (error, attemptNumber, options) => {
|
|
956
|
+
const retriesLeft = options.retries - (attemptNumber - 1);
|
|
957
|
+
error.attemptNumber = attemptNumber;
|
|
958
|
+
error.retriesLeft = retriesLeft;
|
|
959
|
+
return error;
|
|
960
|
+
};
|
|
961
|
+
var isNetworkError = (errorMessage) => networkErrorMsgs.has(errorMessage);
|
|
962
|
+
var getDOMException = (errorMessage) => globalThis.DOMException === void 0 ? new Error(errorMessage) : new DOMException(errorMessage);
|
|
963
|
+
async function pRetry(input, options) {
|
|
964
|
+
return new Promise((resolve, reject) => {
|
|
965
|
+
options = {
|
|
966
|
+
onFailedAttempt() {
|
|
967
|
+
},
|
|
968
|
+
retries: 10,
|
|
969
|
+
...options
|
|
970
|
+
};
|
|
971
|
+
const operation = import_retry.default.operation(options);
|
|
972
|
+
operation.attempt(async (attemptNumber) => {
|
|
973
|
+
try {
|
|
974
|
+
resolve(await input(attemptNumber));
|
|
975
|
+
} catch (error) {
|
|
976
|
+
if (!(error instanceof Error)) {
|
|
977
|
+
reject(new TypeError(`Non-error was thrown: "${error}". You should only throw errors.`));
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
if (error instanceof AbortError) {
|
|
981
|
+
operation.stop();
|
|
982
|
+
reject(error.originalError);
|
|
983
|
+
} else if (error instanceof TypeError && !isNetworkError(error.message)) {
|
|
984
|
+
operation.stop();
|
|
985
|
+
reject(error);
|
|
986
|
+
} else {
|
|
987
|
+
decorateErrorWithCounts(error, attemptNumber, options);
|
|
988
|
+
try {
|
|
989
|
+
await options.onFailedAttempt(error);
|
|
990
|
+
} catch (error2) {
|
|
991
|
+
reject(error2);
|
|
992
|
+
return;
|
|
993
|
+
}
|
|
994
|
+
if (!operation.retry(error)) {
|
|
995
|
+
reject(operation.mainError());
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
});
|
|
1000
|
+
if (options.signal && !options.signal.aborted) {
|
|
1001
|
+
options.signal.addEventListener("abort", () => {
|
|
1002
|
+
operation.stop();
|
|
1003
|
+
const reason = options.signal.reason === void 0 ? getDOMException("The operation was aborted.") : options.signal.reason;
|
|
1004
|
+
reject(reason instanceof Error ? reason : getDOMException(reason));
|
|
1005
|
+
}, {
|
|
1006
|
+
once: true
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
var AbortError2 = class extends Error {
|
|
1012
|
+
constructor() {
|
|
1013
|
+
super("Throttled function aborted");
|
|
1014
|
+
this.name = "AbortError";
|
|
1015
|
+
}
|
|
1016
|
+
};
|
|
1017
|
+
function pThrottle({ limit, interval, strict }) {
|
|
1018
|
+
if (!Number.isFinite(limit)) {
|
|
1019
|
+
throw new TypeError("Expected `limit` to be a finite number");
|
|
1020
|
+
}
|
|
1021
|
+
if (!Number.isFinite(interval)) {
|
|
1022
|
+
throw new TypeError("Expected `interval` to be a finite number");
|
|
1023
|
+
}
|
|
1024
|
+
const queue = /* @__PURE__ */ new Map();
|
|
1025
|
+
let currentTick = 0;
|
|
1026
|
+
let activeCount = 0;
|
|
1027
|
+
function windowedDelay() {
|
|
1028
|
+
const now = Date.now();
|
|
1029
|
+
if (now - currentTick > interval) {
|
|
1030
|
+
activeCount = 1;
|
|
1031
|
+
currentTick = now;
|
|
1032
|
+
return 0;
|
|
1033
|
+
}
|
|
1034
|
+
if (activeCount < limit) {
|
|
1035
|
+
activeCount++;
|
|
1036
|
+
} else {
|
|
1037
|
+
currentTick += interval;
|
|
1038
|
+
activeCount = 1;
|
|
1039
|
+
}
|
|
1040
|
+
return currentTick - now;
|
|
1041
|
+
}
|
|
1042
|
+
const strictTicks = [];
|
|
1043
|
+
function strictDelay() {
|
|
1044
|
+
const now = Date.now();
|
|
1045
|
+
if (strictTicks.length < limit) {
|
|
1046
|
+
strictTicks.push(now);
|
|
1047
|
+
return 0;
|
|
1048
|
+
}
|
|
1049
|
+
const earliestTime = strictTicks.shift() + interval;
|
|
1050
|
+
if (now >= earliestTime) {
|
|
1051
|
+
strictTicks.push(now);
|
|
1052
|
+
return 0;
|
|
1053
|
+
}
|
|
1054
|
+
strictTicks.push(earliestTime);
|
|
1055
|
+
return earliestTime - now;
|
|
1056
|
+
}
|
|
1057
|
+
const getDelay = strict ? strictDelay : windowedDelay;
|
|
1058
|
+
return (function_) => {
|
|
1059
|
+
const throttled = function(...args) {
|
|
1060
|
+
if (!throttled.isEnabled) {
|
|
1061
|
+
return (async () => function_.apply(this, args))();
|
|
1062
|
+
}
|
|
1063
|
+
let timeout;
|
|
1064
|
+
return new Promise((resolve, reject) => {
|
|
1065
|
+
const execute = () => {
|
|
1066
|
+
resolve(function_.apply(this, args));
|
|
1067
|
+
queue.delete(timeout);
|
|
1068
|
+
};
|
|
1069
|
+
timeout = setTimeout(execute, getDelay());
|
|
1070
|
+
queue.set(timeout, reject);
|
|
1071
|
+
});
|
|
1072
|
+
};
|
|
1073
|
+
throttled.abort = () => {
|
|
1074
|
+
for (const timeout of queue.keys()) {
|
|
1075
|
+
clearTimeout(timeout);
|
|
1076
|
+
queue.get(timeout)(new AbortError2());
|
|
1077
|
+
}
|
|
1078
|
+
queue.clear();
|
|
1079
|
+
strictTicks.splice(0, strictTicks.length);
|
|
1080
|
+
};
|
|
1081
|
+
throttled.isEnabled = true;
|
|
1082
|
+
return throttled;
|
|
1083
|
+
};
|
|
1084
|
+
}
|
|
1085
|
+
function createLimitPolicy({
|
|
1086
|
+
throttle = { interval: 1e3, limit: 10 },
|
|
1087
|
+
retry: retry2 = { retries: 1, factor: 1.66 },
|
|
1088
|
+
limit = 10
|
|
1089
|
+
}) {
|
|
1090
|
+
const throttler = throttle ? pThrottle(throttle) : null;
|
|
1091
|
+
const limiter = limit ? (0, import_p_limit2.default)(limit) : null;
|
|
1092
|
+
return function limitPolicy(func) {
|
|
1093
|
+
let currentFunc = async () => await func();
|
|
1094
|
+
if (throttler) {
|
|
1095
|
+
const throttleFunc = currentFunc;
|
|
1096
|
+
currentFunc = throttler(throttleFunc);
|
|
1097
|
+
}
|
|
1098
|
+
if (limiter) {
|
|
1099
|
+
const limitFunc = currentFunc;
|
|
1100
|
+
currentFunc = () => limiter(limitFunc);
|
|
1101
|
+
}
|
|
1102
|
+
if (retry2) {
|
|
1103
|
+
const retryFunc = currentFunc;
|
|
1104
|
+
currentFunc = () => pRetry(retryFunc, {
|
|
1105
|
+
...retry2,
|
|
1106
|
+
onFailedAttempt: async (error) => {
|
|
1107
|
+
if (retry2.onFailedAttempt) {
|
|
1108
|
+
await retry2.onFailedAttempt(error);
|
|
1109
|
+
}
|
|
1110
|
+
if (error instanceof ApiClientError && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
|
|
1111
|
+
throw error;
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
return currentFunc();
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1119
|
+
var isPlainObject = (obj) => typeof obj === "object" && obj !== null && !Array.isArray(obj);
|
|
1120
|
+
function rewriteFilters(filters) {
|
|
1121
|
+
return Object.entries(filters != null ? filters : {}).reduce(
|
|
1122
|
+
(acc, [key, value]) => {
|
|
1123
|
+
const lhs = `filters.${key}` + (isPlainObject(value) ? `[${Object.keys(value)[0]}]` : "");
|
|
1124
|
+
const rhs = isPlainObject(value) ? Object.values(value)[0] : value;
|
|
1125
|
+
return {
|
|
1126
|
+
...acc,
|
|
1127
|
+
[lhs]: Array.isArray(rhs) ? rhs.map((v) => `${v}`.trim()).join(",") : `${rhs}`.trim()
|
|
1128
|
+
};
|
|
1129
|
+
},
|
|
1130
|
+
{}
|
|
1131
|
+
);
|
|
1132
|
+
}
|
|
1133
|
+
var CANVAS_URL = "/api/v1/canvas";
|
|
1134
|
+
var CanvasClient = class extends ApiClient {
|
|
1135
|
+
constructor(options) {
|
|
1136
|
+
var _a;
|
|
1137
|
+
if (!options.limitPolicy) {
|
|
1138
|
+
options.limitPolicy = createLimitPolicy({});
|
|
1139
|
+
}
|
|
1140
|
+
super(options);
|
|
1141
|
+
this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
|
|
1142
|
+
this.edgeApiRequestInit = options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0;
|
|
1143
|
+
}
|
|
1144
|
+
/** Fetches lists of Canvas compositions, optionally by type */
|
|
1145
|
+
async getCompositionList(params = {}) {
|
|
1146
|
+
const { projectId } = this.options;
|
|
1147
|
+
const { resolveData, filters, ...originParams } = params;
|
|
1148
|
+
const rewrittenFilters = rewriteFilters(filters);
|
|
1149
|
+
if (!resolveData) {
|
|
1150
|
+
const fetchUri = this.createUrl(CANVAS_URL, { ...originParams, projectId, ...rewrittenFilters });
|
|
1151
|
+
return this.apiClient(fetchUri);
|
|
1152
|
+
}
|
|
1153
|
+
const edgeParams = {
|
|
1154
|
+
...originParams,
|
|
1155
|
+
projectId,
|
|
1156
|
+
diagnostics: typeof params.diagnostics === "boolean" ? params.diagnostics : params.diagnostics === "no-data" ? "no-data" : void 0,
|
|
1157
|
+
...rewrittenFilters
|
|
1158
|
+
};
|
|
1159
|
+
const edgeUrl = this.createUrl("/api/v1/compositions", edgeParams, this.edgeApiHost);
|
|
1160
|
+
return this.apiClient(edgeUrl, this.edgeApiRequestInit);
|
|
1161
|
+
}
|
|
1162
|
+
getCompositionByNodePath(options) {
|
|
1163
|
+
return this.getOneComposition(options);
|
|
1164
|
+
}
|
|
1165
|
+
getCompositionByNodeId(options) {
|
|
1166
|
+
return this.getOneComposition(options);
|
|
1167
|
+
}
|
|
1168
|
+
getCompositionBySlug(options) {
|
|
1169
|
+
return this.getOneComposition(options);
|
|
1170
|
+
}
|
|
1171
|
+
getCompositionById(options) {
|
|
1172
|
+
return this.getOneComposition(options);
|
|
1173
|
+
}
|
|
1174
|
+
getCompositionDefaults(options) {
|
|
1175
|
+
return this.getOneComposition(options);
|
|
1176
|
+
}
|
|
1177
|
+
/** Fetches historical versions of a composition or pattern */
|
|
1178
|
+
async getCompositionHistory(options) {
|
|
1179
|
+
const historyUrl = this.createUrl("/api/v1/canvas-history", {
|
|
1180
|
+
...options,
|
|
1181
|
+
projectId: this.options.projectId
|
|
1182
|
+
});
|
|
1183
|
+
return this.apiClient(historyUrl);
|
|
1184
|
+
}
|
|
1185
|
+
getOneComposition({
|
|
1186
|
+
skipDataResolution,
|
|
1187
|
+
diagnostics,
|
|
1188
|
+
...params
|
|
1189
|
+
}) {
|
|
1190
|
+
const { projectId } = this.options;
|
|
1191
|
+
if (skipDataResolution) {
|
|
1192
|
+
return this.apiClient(this.createUrl(CANVAS_URL, { ...params, projectId }));
|
|
1193
|
+
}
|
|
1194
|
+
const edgeParams = {
|
|
1195
|
+
...params,
|
|
1196
|
+
projectId,
|
|
1197
|
+
diagnostics: typeof diagnostics === "boolean" ? diagnostics : diagnostics === "no-data" ? "no-data" : void 0
|
|
1198
|
+
};
|
|
1199
|
+
const edgeUrl = this.createUrl("/api/v1/composition", edgeParams, this.edgeApiHost);
|
|
1200
|
+
return this.apiClient(edgeUrl, this.edgeApiRequestInit);
|
|
1201
|
+
}
|
|
1202
|
+
/** Updates or creates a Canvas component definition */
|
|
1203
|
+
async updateComposition(body, options) {
|
|
1204
|
+
const fetchUri = this.createUrl(CANVAS_URL);
|
|
1205
|
+
const headers = {};
|
|
1206
|
+
if (options == null ? void 0 : options.ifUnmodifiedSince) {
|
|
1207
|
+
headers["x-if-unmodified-since"] = options.ifUnmodifiedSince;
|
|
1208
|
+
}
|
|
1209
|
+
const { response } = await this.apiClientWithResponse(fetchUri, {
|
|
1210
|
+
method: "PUT",
|
|
1211
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1212
|
+
expectNoContent: true,
|
|
1213
|
+
headers
|
|
1214
|
+
});
|
|
1215
|
+
return { modified: response.headers.get("x-modified-at") };
|
|
1216
|
+
}
|
|
1217
|
+
/** Deletes a Canvas component definition */
|
|
1218
|
+
async removeComposition(body) {
|
|
1219
|
+
const fetchUri = this.createUrl(CANVAS_URL);
|
|
1220
|
+
const { projectId } = this.options;
|
|
1221
|
+
await this.apiClient(fetchUri, {
|
|
1222
|
+
method: "DELETE",
|
|
1223
|
+
body: JSON.stringify({ ...body, projectId }),
|
|
1224
|
+
expectNoContent: true
|
|
1225
|
+
});
|
|
1226
|
+
}
|
|
1227
|
+
/** Fetches all Canvas component definitions */
|
|
1228
|
+
async getComponentDefinitions(options) {
|
|
1229
|
+
const { projectId } = this.options;
|
|
1230
|
+
const fetchUri = this.createUrl("/api/v1/canvas-definitions", { ...options, projectId });
|
|
1231
|
+
return this.apiClient(fetchUri);
|
|
1232
|
+
}
|
|
1233
|
+
/** Updates or creates a Canvas component definition */
|
|
1234
|
+
async updateComponentDefinition(body) {
|
|
1235
|
+
const fetchUri = this.createUrl("/api/v1/canvas-definitions");
|
|
1236
|
+
await this.apiClient(fetchUri, {
|
|
1237
|
+
method: "PUT",
|
|
1238
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1239
|
+
expectNoContent: true
|
|
1240
|
+
});
|
|
1241
|
+
}
|
|
1242
|
+
/** Deletes a Canvas component definition */
|
|
1243
|
+
async removeComponentDefinition(body) {
|
|
1244
|
+
const fetchUri = this.createUrl("/api/v1/canvas-definitions");
|
|
1245
|
+
await this.apiClient(fetchUri, {
|
|
1246
|
+
method: "DELETE",
|
|
1247
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1248
|
+
expectNoContent: true
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
};
|
|
1252
|
+
var _contentTypesUrl;
|
|
1253
|
+
var _entriesUrl;
|
|
1254
|
+
var _ContentClient = class _ContentClient2 extends ApiClient {
|
|
1255
|
+
constructor(options) {
|
|
1256
|
+
var _a;
|
|
1257
|
+
super(options);
|
|
1258
|
+
this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
|
|
1259
|
+
}
|
|
1260
|
+
getContentTypes(options) {
|
|
1261
|
+
const { projectId } = this.options;
|
|
1262
|
+
const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _contentTypesUrl), { ...options, projectId });
|
|
1263
|
+
return this.apiClient(fetchUri);
|
|
1264
|
+
}
|
|
1265
|
+
getEntries(options) {
|
|
1266
|
+
const { projectId } = this.options;
|
|
1267
|
+
const { skipDataResolution, filters, ...params } = options;
|
|
1268
|
+
const rewrittenFilters = rewriteFilters(filters);
|
|
1269
|
+
if (skipDataResolution) {
|
|
1270
|
+
const url = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl), { ...params, ...rewrittenFilters, projectId });
|
|
1271
|
+
return this.apiClient(url);
|
|
1272
|
+
}
|
|
1273
|
+
const edgeUrl = this.createUrl(
|
|
1274
|
+
__privateGet2(_ContentClient2, _entriesUrl),
|
|
1275
|
+
{ ...this.getEdgeOptions(params), ...rewrittenFilters },
|
|
1276
|
+
this.edgeApiHost
|
|
1277
|
+
);
|
|
1278
|
+
return this.apiClient(
|
|
1279
|
+
edgeUrl,
|
|
1280
|
+
this.options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0
|
|
1281
|
+
);
|
|
1282
|
+
}
|
|
1283
|
+
/** Fetches historical versions of an entry */
|
|
1284
|
+
async getEntryHistory(options) {
|
|
1285
|
+
const historyUrl = this.createUrl("/api/v1/entries-history", {
|
|
1286
|
+
...options,
|
|
1287
|
+
projectId: this.options.projectId
|
|
1288
|
+
});
|
|
1289
|
+
return this.apiClient(historyUrl);
|
|
1290
|
+
}
|
|
1291
|
+
async upsertContentType(body, opts = {}) {
|
|
1292
|
+
const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _contentTypesUrl));
|
|
1293
|
+
if (typeof body.contentType.slugSettings === "object" && body.contentType.slugSettings !== null && Object.keys(body.contentType.slugSettings).length === 0) {
|
|
1294
|
+
delete body.contentType.slugSettings;
|
|
1295
|
+
}
|
|
1296
|
+
await this.apiClient(fetchUri, {
|
|
1297
|
+
method: "PUT",
|
|
1298
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1299
|
+
expectNoContent: true,
|
|
1300
|
+
headers: opts.autogenerateDataTypes ? { "x-uniform-autogenerate-data-types": "true" } : {}
|
|
1301
|
+
});
|
|
1302
|
+
}
|
|
1303
|
+
async upsertEntry(body, options) {
|
|
1304
|
+
const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl));
|
|
1305
|
+
const headers = {};
|
|
1306
|
+
if (options == null ? void 0 : options.ifUnmodifiedSince) {
|
|
1307
|
+
headers["x-if-unmodified-since"] = options.ifUnmodifiedSince;
|
|
1308
|
+
}
|
|
1309
|
+
const { response } = await this.apiClientWithResponse(fetchUri, {
|
|
1310
|
+
method: "PUT",
|
|
1311
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1312
|
+
expectNoContent: true,
|
|
1313
|
+
headers
|
|
1314
|
+
});
|
|
1315
|
+
return { modified: response.headers.get("x-modified-at") };
|
|
1316
|
+
}
|
|
1317
|
+
async deleteContentType(body) {
|
|
1318
|
+
const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _contentTypesUrl));
|
|
1319
|
+
await this.apiClient(fetchUri, {
|
|
1320
|
+
method: "DELETE",
|
|
1321
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1322
|
+
expectNoContent: true
|
|
1323
|
+
});
|
|
1324
|
+
}
|
|
1325
|
+
async deleteEntry(body) {
|
|
1326
|
+
const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl));
|
|
1327
|
+
await this.apiClient(fetchUri, {
|
|
1328
|
+
method: "DELETE",
|
|
1329
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1330
|
+
expectNoContent: true
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1333
|
+
getEdgeOptions(options) {
|
|
1334
|
+
const { projectId } = this.options;
|
|
1335
|
+
const { skipDataResolution, ...params } = options;
|
|
1336
|
+
return {
|
|
1337
|
+
projectId,
|
|
1338
|
+
...params,
|
|
1339
|
+
diagnostics: typeof options.diagnostics === "boolean" ? options.diagnostics : options.diagnostics === "no-data" ? "no-data" : void 0
|
|
1340
|
+
};
|
|
1341
|
+
}
|
|
1342
|
+
};
|
|
1343
|
+
_contentTypesUrl = /* @__PURE__ */ new WeakMap();
|
|
1344
|
+
_entriesUrl = /* @__PURE__ */ new WeakMap();
|
|
1345
|
+
__privateAdd2(_ContentClient, _contentTypesUrl, "/api/v1/content-types");
|
|
1346
|
+
__privateAdd2(_ContentClient, _entriesUrl, "/api/v1/entries");
|
|
1347
|
+
var _url8;
|
|
1348
|
+
var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
|
|
1349
|
+
constructor(options) {
|
|
1350
|
+
super(options);
|
|
1351
|
+
}
|
|
1352
|
+
/** Fetches all DataTypes for a project */
|
|
1353
|
+
async get(options) {
|
|
1354
|
+
const { projectId } = this.options;
|
|
1355
|
+
const fetchUri = this.createUrl(__privateGet2(_DataTypeClient2, _url8), { ...options, projectId });
|
|
1356
|
+
return await this.apiClient(fetchUri);
|
|
1357
|
+
}
|
|
1358
|
+
/** Updates or creates (based on id) a DataType */
|
|
1359
|
+
async upsert(body) {
|
|
1360
|
+
const fetchUri = this.createUrl(__privateGet2(_DataTypeClient2, _url8));
|
|
1361
|
+
await this.apiClient(fetchUri, {
|
|
1362
|
+
method: "PUT",
|
|
1363
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1364
|
+
expectNoContent: true
|
|
1365
|
+
});
|
|
1366
|
+
}
|
|
1367
|
+
/** Deletes a DataType */
|
|
1368
|
+
async remove(body) {
|
|
1369
|
+
const fetchUri = this.createUrl(__privateGet2(_DataTypeClient2, _url8));
|
|
1370
|
+
await this.apiClient(fetchUri, {
|
|
1371
|
+
method: "DELETE",
|
|
1372
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1373
|
+
expectNoContent: true
|
|
1374
|
+
});
|
|
1375
|
+
}
|
|
1376
|
+
};
|
|
1377
|
+
_url8 = /* @__PURE__ */ new WeakMap();
|
|
1378
|
+
__privateAdd2(_DataTypeClient, _url8, "/api/v1/data-types");
|
|
1379
|
+
var CANVAS_DRAFT_STATE = 0;
|
|
1380
|
+
var CANVAS_EDITOR_STATE = 63;
|
|
1381
|
+
var SECRET_QUERY_STRING_PARAM = "secret";
|
|
1382
|
+
var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
|
|
1383
|
+
var IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM = "is_incontext_editing_playground";
|
|
1384
|
+
var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
|
|
1385
|
+
var escapeCharacter = "\\";
|
|
1386
|
+
var variablePrefix = "${";
|
|
1387
|
+
var variableSuffix = "}";
|
|
1388
|
+
function parseVariableExpression(serialized, onToken) {
|
|
1389
|
+
if (typeof serialized !== "string") {
|
|
1390
|
+
throw new TypeError("Variable expression must be a string");
|
|
1391
|
+
}
|
|
1392
|
+
let bufferStartIndex = 0;
|
|
1393
|
+
let bufferEndIndex = 0;
|
|
1394
|
+
let tokenCount = 0;
|
|
1395
|
+
const handleToken = (token, type) => {
|
|
1396
|
+
tokenCount++;
|
|
1397
|
+
return onToken == null ? void 0 : onToken(token, type);
|
|
1398
|
+
};
|
|
1399
|
+
let state = "text";
|
|
1400
|
+
for (let index = 0; index < serialized.length; index++) {
|
|
1401
|
+
const char = serialized[index];
|
|
1402
|
+
if (bufferStartIndex > bufferEndIndex) {
|
|
1403
|
+
bufferEndIndex = bufferStartIndex;
|
|
1404
|
+
}
|
|
1405
|
+
if (char === variablePrefix[0] && serialized[index + 1] === variablePrefix[1]) {
|
|
1406
|
+
if (serialized[index - 1] === escapeCharacter) {
|
|
1407
|
+
bufferEndIndex -= escapeCharacter.length;
|
|
1408
|
+
if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text") === false) {
|
|
1409
|
+
return tokenCount;
|
|
1410
|
+
}
|
|
1411
|
+
bufferStartIndex = index;
|
|
1412
|
+
bufferEndIndex = index + 1;
|
|
1413
|
+
continue;
|
|
1414
|
+
}
|
|
1415
|
+
state = "variable";
|
|
1416
|
+
if (bufferEndIndex > bufferStartIndex) {
|
|
1417
|
+
if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text") === false) {
|
|
1418
|
+
return tokenCount;
|
|
1419
|
+
}
|
|
1420
|
+
bufferStartIndex = bufferEndIndex;
|
|
1421
|
+
}
|
|
1422
|
+
index += variablePrefix.length - 1;
|
|
1423
|
+
bufferStartIndex += variablePrefix.length;
|
|
1424
|
+
continue;
|
|
1425
|
+
}
|
|
1426
|
+
if (char === variableSuffix && state === "variable") {
|
|
1427
|
+
if (serialized[index - 1] === escapeCharacter) {
|
|
1428
|
+
bufferEndIndex++;
|
|
1429
|
+
continue;
|
|
1430
|
+
}
|
|
1431
|
+
state = "text";
|
|
1432
|
+
if (bufferEndIndex > bufferStartIndex) {
|
|
1433
|
+
const unescapedVariableName = serialized.substring(bufferStartIndex, bufferEndIndex).replace(/\\([${}])/g, "$1");
|
|
1434
|
+
if (handleToken(unescapedVariableName, "variable") === false) {
|
|
1435
|
+
return tokenCount;
|
|
1436
|
+
}
|
|
1437
|
+
bufferStartIndex = bufferEndIndex + variableSuffix.length;
|
|
1438
|
+
}
|
|
1439
|
+
continue;
|
|
1440
|
+
}
|
|
1441
|
+
bufferEndIndex++;
|
|
1442
|
+
}
|
|
1443
|
+
if (bufferEndIndex > bufferStartIndex) {
|
|
1444
|
+
if (state === "variable") {
|
|
1445
|
+
state = "text";
|
|
1446
|
+
bufferStartIndex -= variablePrefix.length;
|
|
1447
|
+
}
|
|
1448
|
+
handleToken(serialized.substring(bufferStartIndex), state);
|
|
1449
|
+
}
|
|
1450
|
+
return tokenCount;
|
|
1451
|
+
}
|
|
1452
|
+
function createVariableReference(variableName) {
|
|
1453
|
+
return `\${${variableName.replace(/([${}])/g, "\\$1")}}`;
|
|
1454
|
+
}
|
|
1455
|
+
var _baseUrl;
|
|
1456
|
+
var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2 extends ApiClient {
|
|
1457
|
+
constructor(options) {
|
|
1458
|
+
super(options);
|
|
1459
|
+
this.teamId = options.teamId;
|
|
1460
|
+
}
|
|
1461
|
+
/**
|
|
1462
|
+
* Gets a list of property type and hook names for the current team, including public integrations' hooks.
|
|
1463
|
+
*/
|
|
1464
|
+
get(options) {
|
|
1465
|
+
const fetchUri = this.createUrl(__privateGet2(_IntegrationPropertyEditorsClient2, _baseUrl), {
|
|
1466
|
+
...options,
|
|
1467
|
+
teamId: this.teamId
|
|
1468
|
+
});
|
|
1469
|
+
return this.apiClient(fetchUri);
|
|
1470
|
+
}
|
|
1471
|
+
/**
|
|
1472
|
+
* Creates or updates a custom AI property editor on a Mesh app.
|
|
1473
|
+
*/
|
|
1474
|
+
async deploy(body) {
|
|
1475
|
+
const fetchUri = this.createUrl(__privateGet2(_IntegrationPropertyEditorsClient2, _baseUrl));
|
|
1476
|
+
await this.apiClient(fetchUri, {
|
|
1477
|
+
method: "PUT",
|
|
1478
|
+
body: JSON.stringify({ ...body, teamId: this.teamId }),
|
|
1479
|
+
expectNoContent: true
|
|
1480
|
+
});
|
|
1481
|
+
}
|
|
1482
|
+
/**
|
|
1483
|
+
* Removes a custom AI property editor from a Mesh app.
|
|
1484
|
+
*/
|
|
1485
|
+
async delete(body) {
|
|
1486
|
+
const fetchUri = this.createUrl(__privateGet2(_IntegrationPropertyEditorsClient2, _baseUrl));
|
|
1487
|
+
await this.apiClient(fetchUri, {
|
|
1488
|
+
method: "DELETE",
|
|
1489
|
+
body: JSON.stringify({ ...body, teamId: this.teamId }),
|
|
1490
|
+
expectNoContent: true
|
|
1491
|
+
});
|
|
1492
|
+
}
|
|
1493
|
+
};
|
|
1494
|
+
_baseUrl = /* @__PURE__ */ new WeakMap();
|
|
1495
|
+
__privateAdd2(_IntegrationPropertyEditorsClient, _baseUrl, "/api/v1/integration-property-editors");
|
|
1496
|
+
var _url22;
|
|
1497
|
+
var _ProjectClient = class _ProjectClient2 extends ApiClient {
|
|
1498
|
+
constructor(options) {
|
|
1499
|
+
super({ ...options, bypassCache: true });
|
|
1500
|
+
}
|
|
1501
|
+
/** Fetches single Project */
|
|
1502
|
+
async get(options) {
|
|
1503
|
+
const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _url22), { ...options });
|
|
1504
|
+
return await this.apiClient(fetchUri);
|
|
1505
|
+
}
|
|
1506
|
+
/** Updates or creates (based on id) a Project */
|
|
1507
|
+
async upsert(body) {
|
|
1508
|
+
const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _url22));
|
|
1509
|
+
return await this.apiClient(fetchUri, {
|
|
1510
|
+
method: "PUT",
|
|
1511
|
+
body: JSON.stringify({ ...body })
|
|
1512
|
+
});
|
|
1513
|
+
}
|
|
1514
|
+
/** Deletes a Project */
|
|
1515
|
+
async delete(body) {
|
|
1516
|
+
const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _url22));
|
|
1517
|
+
await this.apiClient(fetchUri, {
|
|
1518
|
+
method: "DELETE",
|
|
1519
|
+
body: JSON.stringify({ ...body }),
|
|
1520
|
+
expectNoContent: true
|
|
1521
|
+
});
|
|
1522
|
+
}
|
|
1523
|
+
};
|
|
1524
|
+
_url22 = /* @__PURE__ */ new WeakMap();
|
|
1525
|
+
__privateAdd2(_ProjectClient, _url22, "/api/v1/project");
|
|
1526
|
+
var isAllowedReferrer = (referrer) => {
|
|
1527
|
+
return Boolean(referrer == null ? void 0 : referrer.match(/(^https:\/\/|\.)(uniform.app|uniform.wtf|localhost:\d{4})\//));
|
|
1528
|
+
};
|
|
1529
|
+
|
|
1530
|
+
// src/handler/createPreviewGETRouteHandler.ts
|
|
1531
|
+
var import_headers = require("next/headers");
|
|
1532
|
+
var import_navigation = require("next/navigation");
|
|
1533
|
+
var import_server = require("next/server");
|
|
1534
|
+
|
|
1535
|
+
// src/config/helpers.ts
|
|
1536
|
+
var import_uniform_server = __toESM(require("uniform.server.config"));
|
|
1537
|
+
var getServerConfig = () => {
|
|
1538
|
+
return import_uniform_server.default;
|
|
1539
|
+
};
|
|
1540
|
+
|
|
1541
|
+
// src/handler/createPreviewGETRouteHandler.ts
|
|
1542
|
+
var BASE_URL_EXAMPLE = "https://example.com";
|
|
1543
|
+
var getQueryParam = (req, paramName) => {
|
|
1544
|
+
const value = req.nextUrl.searchParams.get(paramName);
|
|
1545
|
+
if (typeof value === "undefined") {
|
|
1546
|
+
return void 0;
|
|
1547
|
+
}
|
|
1548
|
+
return Array.isArray(value) ? value[0] : value;
|
|
1549
|
+
};
|
|
1550
|
+
var contextualEditingQueryParams = [
|
|
1551
|
+
IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
|
|
1552
|
+
IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM
|
|
1553
|
+
];
|
|
1554
|
+
var createPreviewGETRouteHandler = (options) => {
|
|
1555
|
+
return async (request) => {
|
|
1556
|
+
const isConfigCheck = getQueryParam(request, "is_config_check") === "true";
|
|
1557
|
+
const { playgroundPath } = getServerConfig();
|
|
1558
|
+
if (isConfigCheck) {
|
|
1559
|
+
return Response.json(
|
|
1560
|
+
{
|
|
1561
|
+
hasPlayground: Boolean(playgroundPath),
|
|
1562
|
+
isUsingCustomFullPathResolver: false
|
|
1563
|
+
},
|
|
1564
|
+
{
|
|
1565
|
+
headers: {
|
|
1566
|
+
"Access-Control-Allow-Origin": process.env.UNIFORM_CLI_BASE_URL || "https://uniform.app"
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
);
|
|
1570
|
+
}
|
|
1571
|
+
if (request.headers.get("sec-fetch-mode") === "no-cors") {
|
|
1572
|
+
return new Response(null, { status: 204 });
|
|
1573
|
+
}
|
|
1574
|
+
if (!process.env.UNIFORM_PREVIEW_SECRET) {
|
|
1575
|
+
return new Response("No preview secret is configured", { status: 401 });
|
|
1576
|
+
}
|
|
1577
|
+
const { searchParams } = new URL(request.url);
|
|
1578
|
+
const id = getQueryParam(request, compositionQueryParam.id);
|
|
1579
|
+
const path = getQueryParam(request, compositionQueryParam.path);
|
|
1580
|
+
const isPlayground = searchParams.get(IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM) === "true" || id && !path;
|
|
1581
|
+
const locale = getQueryParam(request, compositionQueryParam.locale);
|
|
1582
|
+
let pathToRedirectTo;
|
|
1583
|
+
if (isPlayground) {
|
|
1584
|
+
if (!playgroundPath) {
|
|
1585
|
+
return new Response("No playground path is configured", { status: 401 });
|
|
1586
|
+
}
|
|
1587
|
+
pathToRedirectTo = playgroundPath;
|
|
1588
|
+
if (options == null ? void 0 : options.processPlaygroundPath) {
|
|
1589
|
+
const processedPath = options.processPlaygroundPath({ playgroundPath, locale });
|
|
1590
|
+
if (processedPath) {
|
|
1591
|
+
pathToRedirectTo = processedPath;
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
const slug = getQueryParam(request, compositionQueryParam.slug);
|
|
1596
|
+
const disable = getQueryParam(request, "disable");
|
|
1597
|
+
const secret = getQueryParam(request, SECRET_QUERY_STRING_PARAM);
|
|
1598
|
+
const referer = request.headers.get("referer");
|
|
1599
|
+
const isUniformContextualEditing = getQueryParam(request, IN_CONTEXT_EDITOR_QUERY_STRING_PARAM) === "true" && isAllowedReferrer(referer || void 0);
|
|
1600
|
+
const releaseId = getQueryParam(request, "releaseId");
|
|
1601
|
+
if (typeof pathToRedirectTo === "undefined") {
|
|
1602
|
+
const resolveFullPath = (options == null ? void 0 : options.resolveFullPath) || resolveFullPathDefault;
|
|
1603
|
+
pathToRedirectTo = resolveFullPath({ id, slug, path, locale });
|
|
1604
|
+
}
|
|
1605
|
+
validateLocalRedirectUrl(pathToRedirectTo);
|
|
1606
|
+
if (!pathToRedirectTo) {
|
|
1607
|
+
return new Response("Could not resolve the full path of the preview page", { status: 400 });
|
|
1608
|
+
}
|
|
1609
|
+
if (disable) {
|
|
1610
|
+
(await (0, import_headers.draftMode)()).disable();
|
|
1611
|
+
(0, import_navigation.redirect)(pathToRedirectTo);
|
|
1612
|
+
return;
|
|
1613
|
+
}
|
|
1614
|
+
if (secret !== process.env.UNIFORM_PREVIEW_SECRET) {
|
|
1615
|
+
return new Response("Invalid preview secret", { status: 401 });
|
|
1616
|
+
}
|
|
1617
|
+
const draft = await (0, import_headers.draftMode)();
|
|
1618
|
+
draft.enable();
|
|
1619
|
+
const cookieStore = await (0, import_headers.cookies)();
|
|
1620
|
+
const draftCookie = cookieStore.get("__prerender_bypass");
|
|
1621
|
+
if (draftCookie == null ? void 0 : draftCookie.value) {
|
|
1622
|
+
cookieStore.set({
|
|
1623
|
+
name: "__prerender_bypass",
|
|
1624
|
+
value: draftCookie.value,
|
|
1625
|
+
httpOnly: true,
|
|
1626
|
+
path: "/",
|
|
1627
|
+
secure: true,
|
|
1628
|
+
sameSite: "none"
|
|
1629
|
+
// Allow cookie in cross-origin iframes
|
|
1630
|
+
});
|
|
1631
|
+
}
|
|
1632
|
+
const redirectionUrl = new URL(pathToRedirectTo, BASE_URL_EXAMPLE);
|
|
1633
|
+
assignRequestQueryToSearchParams(redirectionUrl.searchParams, searchParams);
|
|
1634
|
+
if (isPlayground) {
|
|
1635
|
+
redirectionUrl.searchParams.set("id", searchParams.get("id") || "");
|
|
1636
|
+
if (locale) {
|
|
1637
|
+
redirectionUrl.searchParams.set("locale", locale);
|
|
1638
|
+
}
|
|
1639
|
+
if (releaseId) {
|
|
1640
|
+
redirectionUrl.searchParams.set("releaseId", releaseId);
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
if (releaseId) {
|
|
1644
|
+
redirectionUrl.searchParams.set("releaseId", releaseId);
|
|
1645
|
+
}
|
|
1646
|
+
if (!isUniformContextualEditing) {
|
|
1647
|
+
contextualEditingQueryParams.forEach((param) => {
|
|
1648
|
+
redirectionUrl.searchParams.delete(param);
|
|
1649
|
+
});
|
|
1650
|
+
}
|
|
1651
|
+
const fullPathToRedirectTo = redirectionUrl.href.replace(BASE_URL_EXAMPLE, "");
|
|
1652
|
+
return import_server.NextResponse.redirect(new URL(fullPathToRedirectTo, request.url), {
|
|
1653
|
+
status: 307
|
|
1654
|
+
});
|
|
1655
|
+
};
|
|
1656
|
+
};
|
|
1657
|
+
function validateLocalRedirectUrl(pathToRedirectTo) {
|
|
1658
|
+
if (pathToRedirectTo == null ? void 0 : pathToRedirectTo.match(/^[a-z]+:\/\//g)) {
|
|
1659
|
+
throw new Error("Tried to redirect to absolute URL with protocol. Disallowing open redirect.");
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
var resolveFullPathDefault = ({ slug, path }) => {
|
|
1663
|
+
return path || slug;
|
|
1664
|
+
};
|
|
1665
|
+
var compositionQueryParam = {
|
|
1666
|
+
id: "id",
|
|
1667
|
+
slug: "slug",
|
|
1668
|
+
path: "path",
|
|
1669
|
+
locale: "locale"
|
|
1670
|
+
};
|
|
1671
|
+
var assignRequestQueryToSearchParams = (searchParams, query) => {
|
|
1672
|
+
const compositionQueryParamNames = Object.values(compositionQueryParam);
|
|
1673
|
+
for (const [name, value] of query.entries()) {
|
|
1674
|
+
if (name === SECRET_QUERY_STRING_PARAM) {
|
|
1675
|
+
continue;
|
|
1676
|
+
}
|
|
1677
|
+
if (compositionQueryParamNames.includes(name)) {
|
|
1678
|
+
continue;
|
|
1679
|
+
}
|
|
1680
|
+
if (typeof value === "undefined") {
|
|
1681
|
+
continue;
|
|
1682
|
+
}
|
|
1683
|
+
searchParams.append(name, value);
|
|
1684
|
+
}
|
|
1685
|
+
};
|
|
1686
|
+
|
|
1687
|
+
// src/handler/createPreviewOPTIONSRouteHandler.ts
|
|
1688
|
+
var createPreviewOPTIONSRouteHandler = () => {
|
|
1689
|
+
return async () => {
|
|
1690
|
+
return new Response(null, {
|
|
1691
|
+
headers: {
|
|
1692
|
+
"Access-Control-Allow-Origin": process.env.UNIFORM_CLI_BASE_URL || "https://uniform.app",
|
|
1693
|
+
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
|
|
1694
|
+
"Access-Control-Allow-Headers": "*"
|
|
1695
|
+
}
|
|
1696
|
+
});
|
|
1697
|
+
};
|
|
1698
|
+
};
|
|
1699
|
+
|
|
1700
|
+
// src/handler/createPreviewPOSTRouteHandler.ts
|
|
1701
|
+
var import_functions = require("@vercel/functions");
|
|
1702
|
+
var import_cache4 = require("next/cache");
|
|
1703
|
+
|
|
1704
|
+
// src/handler/helpers.ts
|
|
1705
|
+
var import_svix = require("svix");
|
|
1706
|
+
|
|
1707
|
+
// src/clients/canvas.ts
|
|
1708
|
+
var import_server_only = require("server-only");
|
|
1709
|
+
|
|
1710
|
+
// src/utils/env.ts
|
|
1711
|
+
var env = {
|
|
1712
|
+
getProjectId: () => {
|
|
1713
|
+
return process.env.UNIFORM_PROJECT_ID;
|
|
1714
|
+
},
|
|
1715
|
+
getApiKey: () => {
|
|
1716
|
+
return process.env.UNIFORM_API_KEY;
|
|
1717
|
+
},
|
|
1718
|
+
getApiHost: () => {
|
|
1719
|
+
return process.env.UNIFORM_API_HOST || process.env.UNIFORM_CLI_BASE_URL;
|
|
1720
|
+
},
|
|
1721
|
+
getEdgeApiHost: () => {
|
|
1722
|
+
return process.env.UNIFORM_EDGE_API_HOST || process.env.UNIFORM_CLI_BASE_EDGE_URL;
|
|
1723
|
+
}
|
|
1724
|
+
};
|
|
1725
|
+
|
|
1726
|
+
// src/utils/tag.ts
|
|
1727
|
+
var buildPathTag = (path) => {
|
|
1728
|
+
const actualPath = path.startsWith("/") ? path : `/${path}`;
|
|
1729
|
+
return `path:${actualPath}`.toLowerCase();
|
|
1730
|
+
};
|
|
1731
|
+
var buildCompositionTag = (compositionId) => {
|
|
1732
|
+
return `composition:${compositionId}`.toLowerCase();
|
|
1733
|
+
};
|
|
1734
|
+
|
|
1735
|
+
// src/utils/draft.ts
|
|
1736
|
+
var isDraftModeEnabled = ({
|
|
1737
|
+
draftModeEnabled
|
|
1738
|
+
}) => {
|
|
1739
|
+
return draftModeEnabled;
|
|
1740
|
+
};
|
|
1741
|
+
var isIncontextEditingEnabled = ({ searchParams }) => {
|
|
1742
|
+
const containsKey = searchParams.has(IN_CONTEXT_EDITOR_QUERY_STRING_PARAM);
|
|
1743
|
+
return containsKey;
|
|
1744
|
+
};
|
|
1745
|
+
var isDevelopmentEnvironment = () => {
|
|
1746
|
+
return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
|
|
1747
|
+
};
|
|
1748
|
+
|
|
1749
|
+
// src/clients/cache.ts
|
|
1750
|
+
var isSpecificCacheMode = (options) => {
|
|
1751
|
+
return "cache" in options;
|
|
1752
|
+
};
|
|
1753
|
+
var isStateCacheMode = (options) => {
|
|
1754
|
+
return "state" in options;
|
|
1755
|
+
};
|
|
1756
|
+
var isDetectCacheMode = (options) => {
|
|
1757
|
+
return "searchParams" in options && "draftModeEnabled" in options;
|
|
1758
|
+
};
|
|
1759
|
+
var resolveCanvasCache = (options) => {
|
|
1760
|
+
return resolveCache({
|
|
1761
|
+
options,
|
|
1762
|
+
defaultCache: getServerConfig().canvasCache
|
|
1763
|
+
});
|
|
1764
|
+
};
|
|
1765
|
+
var resolveProjectMapCache = (options) => {
|
|
1766
|
+
return resolveCache({
|
|
1767
|
+
options,
|
|
1768
|
+
defaultCache: getServerConfig().projectMapCache
|
|
1769
|
+
});
|
|
1770
|
+
};
|
|
1771
|
+
var resolveCache = ({
|
|
1772
|
+
options,
|
|
1773
|
+
defaultCache
|
|
1774
|
+
}) => {
|
|
1775
|
+
let cache = defaultCache;
|
|
1776
|
+
if (options) {
|
|
1777
|
+
if (isSpecificCacheMode(options)) {
|
|
1778
|
+
cache = options.cache;
|
|
1779
|
+
} else if (isStateCacheMode(options)) {
|
|
1780
|
+
if (options.state === CANVAS_DRAFT_STATE || options.state === CANVAS_EDITOR_STATE) {
|
|
1781
|
+
cache = {
|
|
1782
|
+
type: "no-cache",
|
|
1783
|
+
bypassCache: true
|
|
1784
|
+
};
|
|
1785
|
+
}
|
|
1786
|
+
} else if (isDetectCacheMode(options)) {
|
|
1787
|
+
const { disabled } = shouldCacheBeDisabled(options);
|
|
1788
|
+
if (disabled) {
|
|
1789
|
+
cache = {
|
|
1790
|
+
type: "no-cache",
|
|
1791
|
+
bypassCache: true
|
|
1792
|
+
};
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
return cache || {
|
|
1797
|
+
type: "force-cache"
|
|
1798
|
+
};
|
|
1799
|
+
};
|
|
1800
|
+
var shouldCacheBeDisabled = (options) => {
|
|
1801
|
+
if (isDraftModeEnabled(options)) {
|
|
1802
|
+
return { disabled: true, reason: "DRAFT" };
|
|
1803
|
+
}
|
|
1804
|
+
if (isIncontextEditingEnabled(options)) {
|
|
1805
|
+
return { disabled: true, reason: "INCONTEXT" };
|
|
1806
|
+
}
|
|
1807
|
+
if (isDevelopmentEnvironment()) {
|
|
1808
|
+
return { disabled: true, reason: "DEV" };
|
|
1809
|
+
}
|
|
1810
|
+
return {
|
|
1811
|
+
disabled: false,
|
|
1812
|
+
reason: void 0
|
|
1813
|
+
};
|
|
1814
|
+
};
|
|
1815
|
+
var determineFetchCacheOptions = (mode) => {
|
|
1816
|
+
let cache = void 0;
|
|
1817
|
+
let revalidate = void 0;
|
|
1818
|
+
if (mode.type === "revalidate") {
|
|
1819
|
+
cache = void 0;
|
|
1820
|
+
revalidate = mode.interval;
|
|
1821
|
+
} else {
|
|
1822
|
+
cache = mode.type;
|
|
1823
|
+
}
|
|
1824
|
+
return {
|
|
1825
|
+
cache,
|
|
1826
|
+
revalidate
|
|
1827
|
+
};
|
|
1828
|
+
};
|
|
1829
|
+
|
|
1830
|
+
// src/clients/retry.ts
|
|
1831
|
+
function createThrottler(limit, interval) {
|
|
1832
|
+
let available = limit;
|
|
1833
|
+
let refillScheduled = false;
|
|
1834
|
+
const waiting = [];
|
|
1835
|
+
function scheduleRefill() {
|
|
1836
|
+
if (refillScheduled) return;
|
|
1837
|
+
refillScheduled = true;
|
|
1838
|
+
setTimeout(() => {
|
|
1839
|
+
refillScheduled = false;
|
|
1840
|
+
available = limit;
|
|
1841
|
+
while (available > 0 && waiting.length > 0) {
|
|
1842
|
+
available--;
|
|
1843
|
+
const next = waiting.shift();
|
|
1844
|
+
next();
|
|
1845
|
+
}
|
|
1846
|
+
if (waiting.length > 0) {
|
|
1847
|
+
scheduleRefill();
|
|
1848
|
+
}
|
|
1849
|
+
}, interval);
|
|
1850
|
+
}
|
|
1851
|
+
return async function throttle(fn) {
|
|
1852
|
+
if (available > 0) {
|
|
1853
|
+
available--;
|
|
1854
|
+
if (!refillScheduled) {
|
|
1855
|
+
scheduleRefill();
|
|
1856
|
+
}
|
|
1857
|
+
return fn();
|
|
1858
|
+
}
|
|
1859
|
+
return new Promise((resolve, reject) => {
|
|
1860
|
+
waiting.push(() => {
|
|
1861
|
+
fn().then(resolve, reject);
|
|
1862
|
+
});
|
|
1863
|
+
scheduleRefill();
|
|
1864
|
+
});
|
|
1865
|
+
};
|
|
1866
|
+
}
|
|
1867
|
+
function createLimiter(concurrency) {
|
|
1868
|
+
let active = 0;
|
|
1869
|
+
const queue = [];
|
|
1870
|
+
return async function limit(fn) {
|
|
1871
|
+
return new Promise((resolve, reject) => {
|
|
1872
|
+
const run = async () => {
|
|
1873
|
+
active++;
|
|
1874
|
+
try {
|
|
1875
|
+
const result = await fn();
|
|
1876
|
+
resolve(result);
|
|
1877
|
+
} catch (error) {
|
|
1878
|
+
reject(error);
|
|
1879
|
+
} finally {
|
|
1880
|
+
active--;
|
|
1881
|
+
if (queue.length > 0) {
|
|
1882
|
+
const next = queue.shift();
|
|
1883
|
+
next();
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
};
|
|
1887
|
+
if (active < concurrency) {
|
|
1888
|
+
run();
|
|
1889
|
+
} else {
|
|
1890
|
+
queue.push(run);
|
|
1891
|
+
}
|
|
1892
|
+
});
|
|
1893
|
+
};
|
|
1894
|
+
}
|
|
1895
|
+
async function retry(fn, options) {
|
|
1896
|
+
let lastError;
|
|
1897
|
+
let delay = 1e3;
|
|
1898
|
+
for (let attempt = 1; attempt <= options.retries + 1; attempt++) {
|
|
1899
|
+
try {
|
|
1900
|
+
return await fn();
|
|
1901
|
+
} catch (error) {
|
|
1902
|
+
lastError = error;
|
|
1903
|
+
const attemptError = Object.assign(error, { attemptNumber: attempt });
|
|
1904
|
+
if (options.onFailedAttempt) {
|
|
1905
|
+
await options.onFailedAttempt(attemptError);
|
|
1906
|
+
}
|
|
1907
|
+
if (attempt > options.retries) {
|
|
1908
|
+
throw error;
|
|
1909
|
+
}
|
|
1910
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1911
|
+
delay *= options.factor;
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
throw lastError;
|
|
1915
|
+
}
|
|
1916
|
+
function createLimitPolicy2({
|
|
1917
|
+
throttle = { interval: 1e3, limit: 10 },
|
|
1918
|
+
retry: retryOptions = { retries: 1, factor: 1.66 },
|
|
1919
|
+
limit = 10
|
|
1920
|
+
}) {
|
|
1921
|
+
const throttler = throttle ? createThrottler(throttle.limit, throttle.interval) : null;
|
|
1922
|
+
const limiter = limit ? createLimiter(limit) : null;
|
|
1923
|
+
return function limitPolicy(func) {
|
|
1924
|
+
let currentFunc = async () => await func();
|
|
1925
|
+
if (throttler) {
|
|
1926
|
+
const throttleFunc = currentFunc;
|
|
1927
|
+
currentFunc = () => throttler(throttleFunc);
|
|
1928
|
+
}
|
|
1929
|
+
if (limiter) {
|
|
1930
|
+
const limitFunc = currentFunc;
|
|
1931
|
+
currentFunc = () => limiter(limitFunc);
|
|
1932
|
+
}
|
|
1933
|
+
if (retryOptions) {
|
|
1934
|
+
const retryFunc = currentFunc;
|
|
1935
|
+
currentFunc = () => retry(retryFunc, {
|
|
1936
|
+
...retryOptions,
|
|
1937
|
+
onFailedAttempt: async (error) => {
|
|
1938
|
+
if (retryOptions.onFailedAttempt) {
|
|
1939
|
+
await retryOptions.onFailedAttempt(error);
|
|
1940
|
+
}
|
|
1941
|
+
if (error instanceof ApiClientError && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
|
|
1942
|
+
throw error;
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
});
|
|
1946
|
+
}
|
|
1947
|
+
return currentFunc();
|
|
1948
|
+
};
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1951
|
+
// src/clients/canvas.ts
|
|
1952
|
+
var getCanvasClient = (options) => {
|
|
1953
|
+
const cache = resolveCanvasCache(options);
|
|
1954
|
+
return new CanvasClient({
|
|
1955
|
+
projectId: env.getProjectId(),
|
|
1956
|
+
apiHost: env.getApiHost(),
|
|
1957
|
+
apiKey: env.getApiKey(),
|
|
1958
|
+
edgeApiHost: env.getEdgeApiHost(),
|
|
1959
|
+
disableSWR: typeof cache.disableSWR !== "undefined" ? cache.disableSWR : true,
|
|
1960
|
+
limitPolicy: createLimitPolicy2({
|
|
1961
|
+
limit: 6
|
|
1962
|
+
}),
|
|
1963
|
+
fetch: (req, init) => {
|
|
1964
|
+
let requestedUrl;
|
|
1965
|
+
if (typeof req === "string") {
|
|
1966
|
+
requestedUrl = new URL(req);
|
|
1967
|
+
} else if (req instanceof URL) {
|
|
1968
|
+
requestedUrl = req;
|
|
1969
|
+
} else {
|
|
1970
|
+
requestedUrl = new URL(req.url);
|
|
1971
|
+
}
|
|
1972
|
+
const tags = [];
|
|
1973
|
+
if (requestedUrl) {
|
|
1974
|
+
const compositionIdKey = "compositionId";
|
|
1975
|
+
const compositionIdsKey = "compositionIDs";
|
|
1976
|
+
const compositionId = requestedUrl.searchParams.get(compositionIdKey);
|
|
1977
|
+
const compositionIds = requestedUrl.searchParams.get(compositionIdsKey);
|
|
1978
|
+
if (compositionId) {
|
|
1979
|
+
tags.push(buildCompositionTag(compositionId));
|
|
1980
|
+
}
|
|
1981
|
+
if (compositionIds) {
|
|
1982
|
+
const ids = compositionIds.split(",");
|
|
1983
|
+
for (let i = 0; i < ids.length; i++) {
|
|
1984
|
+
tags.push(buildCompositionTag(ids[i]));
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
const { cache: fetchCache, revalidate } = determineFetchCacheOptions(cache);
|
|
1989
|
+
return fetch(req, {
|
|
1990
|
+
...init,
|
|
1991
|
+
cache: fetchCache,
|
|
1992
|
+
headers: {
|
|
1993
|
+
...init == null ? void 0 : init.headers,
|
|
1994
|
+
"x-bypass-cache": typeof cache.bypassCache !== "undefined" ? cache.bypassCache.toString() : "false"
|
|
1995
|
+
},
|
|
1996
|
+
next: {
|
|
1997
|
+
revalidate,
|
|
1998
|
+
tags: tags.length ? tags : void 0
|
|
1999
|
+
}
|
|
2000
|
+
});
|
|
2001
|
+
}
|
|
2002
|
+
});
|
|
2003
|
+
};
|
|
2004
|
+
|
|
2005
|
+
// src/clients/projectMap.ts
|
|
2006
|
+
var import_server_only2 = require("server-only");
|
|
2007
|
+
|
|
2008
|
+
// ../project-map/dist/index.mjs
|
|
2009
|
+
var __typeError3 = (msg) => {
|
|
2010
|
+
throw TypeError(msg);
|
|
2011
|
+
};
|
|
2012
|
+
var __accessCheck3 = (obj, member, msg) => member.has(obj) || __typeError3("Cannot " + msg);
|
|
2013
|
+
var __privateGet3 = (obj, member, getter) => (__accessCheck3(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
2014
|
+
var __privateAdd3 = (obj, member, value) => member.has(obj) ? __typeError3("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
2015
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck3(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
2016
|
+
var __privateMethod = (obj, member, method) => (__accessCheck3(obj, member, "access private method"), method);
|
|
2017
|
+
var ProjectMapClient = class extends ApiClient {
|
|
2018
|
+
constructor(options) {
|
|
2019
|
+
super(options);
|
|
2020
|
+
this.getProjectMapDefinitions = async () => {
|
|
2021
|
+
const { projectId } = this.options;
|
|
2022
|
+
const fetchUri = this.createUrl("/api/v1/project-map", { projectId });
|
|
2023
|
+
return await this.apiClient(fetchUri);
|
|
2024
|
+
};
|
|
2025
|
+
this.getProjectMapDefinition = async (options2) => {
|
|
2026
|
+
const { projectId } = this.options;
|
|
2027
|
+
const fetchUri = this.createUrl("/api/v1/project-map", {
|
|
2028
|
+
...options2,
|
|
2029
|
+
projectId
|
|
2030
|
+
});
|
|
2031
|
+
return await this.apiClient(fetchUri);
|
|
2032
|
+
};
|
|
2033
|
+
this.upsertProjectMap = async (options2) => {
|
|
2034
|
+
const { projectId } = this.options;
|
|
2035
|
+
const fetchUri = this.createUrl("/api/v1/project-map");
|
|
2036
|
+
const result = await this.apiClient(fetchUri, {
|
|
2037
|
+
method: "PUT",
|
|
2038
|
+
body: JSON.stringify({ ...options2, projectId })
|
|
2039
|
+
});
|
|
2040
|
+
return result.projectMapId;
|
|
2041
|
+
};
|
|
2042
|
+
this.deleteProjectMap = async (options2) => {
|
|
2043
|
+
const { projectId } = this.options;
|
|
2044
|
+
const fetchUri = this.createUrl("/api/v1/project-map");
|
|
2045
|
+
await this.apiClient(fetchUri, {
|
|
2046
|
+
method: "DELETE",
|
|
2047
|
+
body: JSON.stringify({ ...options2, projectId }),
|
|
2048
|
+
expectNoContent: true
|
|
2049
|
+
});
|
|
2050
|
+
};
|
|
2051
|
+
this.upsertProjectMapNodes = async (options2) => {
|
|
2052
|
+
const { projectId } = this.options;
|
|
2053
|
+
const fetchUri = this.createUrl("/api/v1/project-map-nodes");
|
|
2054
|
+
await this.apiClient(fetchUri, {
|
|
2055
|
+
method: "PUT",
|
|
2056
|
+
body: JSON.stringify({
|
|
2057
|
+
...options2,
|
|
2058
|
+
projectId,
|
|
2059
|
+
nodes: options2.nodes.map((n) => {
|
|
2060
|
+
return {
|
|
2061
|
+
...n,
|
|
2062
|
+
node: { ...this.cleanProjectMapNode(n.node) }
|
|
2063
|
+
};
|
|
2064
|
+
})
|
|
2065
|
+
}),
|
|
2066
|
+
expectNoContent: true
|
|
2067
|
+
});
|
|
2068
|
+
};
|
|
2069
|
+
this.deleteProjectMapNode = async (options2) => {
|
|
2070
|
+
const { projectId } = this.options;
|
|
2071
|
+
const fetchUri = this.createUrl("/api/v1/project-map-nodes");
|
|
2072
|
+
await this.apiClient(fetchUri, {
|
|
2073
|
+
method: "DELETE",
|
|
2074
|
+
body: JSON.stringify({
|
|
2075
|
+
...options2,
|
|
2076
|
+
projectId
|
|
2077
|
+
}),
|
|
2078
|
+
expectNoContent: true
|
|
2079
|
+
});
|
|
2080
|
+
};
|
|
2081
|
+
this.getSubtree = async (options2) => {
|
|
2082
|
+
var _a;
|
|
2083
|
+
const fetchOptions = this.setFetchOptions(options2);
|
|
2084
|
+
fetchOptions["tree"] = "true";
|
|
2085
|
+
const fetchUri = this.createUrl("/api/v1/project-map-nodes", fetchOptions);
|
|
2086
|
+
const result = await this.apiClient(fetchUri);
|
|
2087
|
+
const root = {
|
|
2088
|
+
...result.tree
|
|
2089
|
+
};
|
|
2090
|
+
const nodes = [root];
|
|
2091
|
+
while (nodes && nodes.length > 0) {
|
|
2092
|
+
const currentNode = nodes.pop();
|
|
2093
|
+
let lastChild = void 0;
|
|
2094
|
+
(_a = currentNode == null ? void 0 : currentNode.children) == null ? void 0 : _a.forEach((child) => {
|
|
2095
|
+
child.parent = cutReferences(currentNode);
|
|
2096
|
+
child.previousSibling = cutReferences(lastChild);
|
|
2097
|
+
if (lastChild) {
|
|
2098
|
+
lastChild.nextSibling = cutReferences(child);
|
|
2099
|
+
}
|
|
2100
|
+
lastChild = child;
|
|
2101
|
+
nodes.push(child);
|
|
2102
|
+
});
|
|
2103
|
+
}
|
|
2104
|
+
return root;
|
|
2105
|
+
};
|
|
2106
|
+
this.getNodes = async (options2) => {
|
|
2107
|
+
const fetchOptions = this.setFetchOptions(options2);
|
|
2108
|
+
const fetchUri = this.createUrl("/api/v1/project-map-nodes", fetchOptions);
|
|
2109
|
+
return await this.apiClient(fetchUri);
|
|
2110
|
+
};
|
|
2111
|
+
}
|
|
2112
|
+
setFetchOptions(options) {
|
|
2113
|
+
const { projectId } = this.options;
|
|
2114
|
+
const fetchOptions = {
|
|
2115
|
+
projectId
|
|
2116
|
+
};
|
|
2117
|
+
Object.entries(options).forEach(([key, value]) => {
|
|
2118
|
+
if (value === void 0) {
|
|
2119
|
+
return;
|
|
2120
|
+
}
|
|
2121
|
+
if (typeof value === "boolean") {
|
|
2122
|
+
if (!value) {
|
|
2123
|
+
return;
|
|
2124
|
+
}
|
|
2125
|
+
fetchOptions[key] = "true";
|
|
2126
|
+
return;
|
|
2127
|
+
}
|
|
2128
|
+
if (typeof value === "number") {
|
|
2129
|
+
fetchOptions[key] = value.toString(10);
|
|
2130
|
+
return;
|
|
2131
|
+
}
|
|
2132
|
+
fetchOptions[key] = value;
|
|
2133
|
+
});
|
|
2134
|
+
return fetchOptions;
|
|
2135
|
+
}
|
|
2136
|
+
cleanProjectMapNode(node) {
|
|
2137
|
+
var _a, _b, _c;
|
|
2138
|
+
return {
|
|
2139
|
+
id: ((_c = (_b = (_a = node.id) == null ? void 0 : _a.match(/^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i)) == null ? void 0 : _b.length) != null ? _c : 0) == 1 ? node.id : void 0,
|
|
2140
|
+
path: node.path,
|
|
2141
|
+
name: node.name,
|
|
2142
|
+
type: node.type,
|
|
2143
|
+
order: node.order,
|
|
2144
|
+
data: node.data,
|
|
2145
|
+
compositionId: node.compositionId,
|
|
2146
|
+
description: node.description,
|
|
2147
|
+
locales: node.locales
|
|
2148
|
+
};
|
|
2149
|
+
}
|
|
2150
|
+
};
|
|
2151
|
+
var cutReferences = (node) => node ? {
|
|
2152
|
+
...node,
|
|
2153
|
+
parent: void 0,
|
|
2154
|
+
children: void 0
|
|
2155
|
+
} : void 0;
|
|
2156
|
+
var _routeInfo;
|
|
2157
|
+
var _Route_static;
|
|
2158
|
+
var parseRouteOrPath_fn;
|
|
2159
|
+
var isDynamicRouteSegment_fn;
|
|
2160
|
+
var _Route = class _Route2 {
|
|
2161
|
+
constructor(route) {
|
|
2162
|
+
this.route = route;
|
|
2163
|
+
__privateAdd3(this, _routeInfo);
|
|
2164
|
+
var _a;
|
|
2165
|
+
__privateSet(this, _routeInfo, __privateMethod(_a = _Route2, _Route_static, parseRouteOrPath_fn).call(_a, this.route));
|
|
2166
|
+
}
|
|
2167
|
+
get dynamicSegmentCount() {
|
|
2168
|
+
return __privateGet3(this, _routeInfo).segments.reduce(
|
|
2169
|
+
(count, segment) => {
|
|
2170
|
+
var _a;
|
|
2171
|
+
return __privateMethod(_a = _Route2, _Route_static, isDynamicRouteSegment_fn).call(_a, segment) ? count + 1 : count;
|
|
2172
|
+
},
|
|
2173
|
+
0
|
|
2174
|
+
);
|
|
2175
|
+
}
|
|
2176
|
+
/** Tests if an incoming path matches this route */
|
|
2177
|
+
matches(path) {
|
|
2178
|
+
var _a, _b;
|
|
2179
|
+
const { segments: pathSegments, queryParams: pathQuery } = __privateMethod(_a = _Route2, _Route_static, parseRouteOrPath_fn).call(_a, path);
|
|
2180
|
+
const { segments: routeSegments } = __privateGet3(this, _routeInfo);
|
|
2181
|
+
if (pathSegments.length !== routeSegments.length) {
|
|
2182
|
+
return { match: false };
|
|
2183
|
+
}
|
|
2184
|
+
const possibleMatch = {
|
|
2185
|
+
match: true,
|
|
2186
|
+
dynamicSegmentCount: 0,
|
|
2187
|
+
pathParams: {},
|
|
2188
|
+
queryParams: {}
|
|
2189
|
+
};
|
|
2190
|
+
for (let i = 0; i < routeSegments.length; i++) {
|
|
2191
|
+
const routeSegment = routeSegments[i];
|
|
2192
|
+
const pathSegment = pathSegments[i];
|
|
2193
|
+
if (__privateMethod(_b = _Route2, _Route_static, isDynamicRouteSegment_fn).call(_b, routeSegment)) {
|
|
2194
|
+
const key = routeSegment.slice(1);
|
|
2195
|
+
possibleMatch.pathParams[key] = pathSegment;
|
|
2196
|
+
possibleMatch.dynamicSegmentCount++;
|
|
2197
|
+
} else if (routeSegment !== pathSegment) {
|
|
2198
|
+
return { match: false };
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
for (const [key, value] of __privateGet3(this, _routeInfo).queryParams) {
|
|
2202
|
+
possibleMatch.queryParams[key] = pathQuery.has(key) ? pathQuery.get(key) : value;
|
|
2203
|
+
}
|
|
2204
|
+
return possibleMatch;
|
|
2205
|
+
}
|
|
2206
|
+
/**
|
|
2207
|
+
* Creates an expanded path value for this route given dynamic input values and allowed query string values
|
|
2208
|
+
*/
|
|
2209
|
+
expand(options) {
|
|
2210
|
+
const { dynamicInputValues = {}, allowedQueryParams = [], doNotEscapeVariables = false } = options != null ? options : {};
|
|
2211
|
+
const path = __privateGet3(this, _routeInfo).segments.map((segment) => {
|
|
2212
|
+
const dynamicSegmentName = _Route2.getDynamicRouteSegmentName(segment);
|
|
2213
|
+
if (!dynamicSegmentName) {
|
|
2214
|
+
return segment;
|
|
2215
|
+
}
|
|
2216
|
+
const dynamicSegmentValue = dynamicInputValues[dynamicSegmentName];
|
|
2217
|
+
if (!dynamicSegmentValue) {
|
|
2218
|
+
return segment;
|
|
2219
|
+
}
|
|
2220
|
+
return encodeRouteComponent(dynamicSegmentValue, doNotEscapeVariables);
|
|
2221
|
+
}).join("/");
|
|
2222
|
+
const queries = allowedQueryParams.filter((qs) => {
|
|
2223
|
+
const type = typeof dynamicInputValues[qs];
|
|
2224
|
+
return type === "string" || type === "number" || type === "boolean";
|
|
2225
|
+
}).map(
|
|
2226
|
+
(qs) => `${encodeRouteComponent(qs, doNotEscapeVariables)}=${encodeRouteComponent(
|
|
2227
|
+
dynamicInputValues[qs],
|
|
2228
|
+
doNotEscapeVariables
|
|
2229
|
+
)}`
|
|
2230
|
+
);
|
|
2231
|
+
const query = queries.length ? `?${queries.join("&")}` : "";
|
|
2232
|
+
return `/${path}${query}`;
|
|
2233
|
+
}
|
|
2234
|
+
static getDynamicRouteSegmentName(segment) {
|
|
2235
|
+
var _a;
|
|
2236
|
+
if (!__privateMethod(_a = _Route2, _Route_static, isDynamicRouteSegment_fn).call(_a, segment)) {
|
|
2237
|
+
return void 0;
|
|
2238
|
+
}
|
|
2239
|
+
return segment.slice(_Route2.dynamicSegmentPrefix.length);
|
|
2240
|
+
}
|
|
2241
|
+
};
|
|
2242
|
+
_routeInfo = /* @__PURE__ */ new WeakMap();
|
|
2243
|
+
_Route_static = /* @__PURE__ */ new WeakSet();
|
|
2244
|
+
parseRouteOrPath_fn = function(path) {
|
|
2245
|
+
if (!path.startsWith("/") || path === "") {
|
|
2246
|
+
throw new Error(`Path must start with a slash: ${path}`);
|
|
2247
|
+
}
|
|
2248
|
+
const [pathname, queryString] = path.split("?");
|
|
2249
|
+
const pathSegments = pathname.substring(1).split("/");
|
|
2250
|
+
if (pathSegments[pathSegments.length - 1] === "") {
|
|
2251
|
+
pathSegments.pop();
|
|
2252
|
+
}
|
|
2253
|
+
const queryParams = new URLSearchParams(queryString);
|
|
2254
|
+
return { segments: pathSegments, queryParams };
|
|
2255
|
+
};
|
|
2256
|
+
isDynamicRouteSegment_fn = function(segment) {
|
|
2257
|
+
if (!segment) {
|
|
2258
|
+
return false;
|
|
2259
|
+
}
|
|
2260
|
+
return segment.startsWith(_Route.dynamicSegmentPrefix);
|
|
2261
|
+
};
|
|
2262
|
+
__privateAdd3(_Route, _Route_static);
|
|
2263
|
+
_Route.dynamicSegmentPrefix = ":";
|
|
2264
|
+
function encodeRouteComponent(value, doNotEscapeVariables) {
|
|
2265
|
+
if (!doNotEscapeVariables) {
|
|
2266
|
+
return encodeURIComponent(value);
|
|
2267
|
+
}
|
|
2268
|
+
const result = [];
|
|
2269
|
+
parseVariableExpression(value.toString(10), (token, type) => {
|
|
2270
|
+
if (type === "variable") {
|
|
2271
|
+
result.push(createVariableReference(token));
|
|
2272
|
+
} else {
|
|
2273
|
+
result.push(encodeURIComponent(token));
|
|
2274
|
+
}
|
|
2275
|
+
});
|
|
2276
|
+
return result.join("");
|
|
2277
|
+
}
|
|
2278
|
+
|
|
2279
|
+
// src/clients/projectMap.ts
|
|
2280
|
+
var getProjectMapClient = (options) => {
|
|
2281
|
+
const cache = resolveProjectMapCache(options);
|
|
2282
|
+
const manifestClient = new ProjectMapClient({
|
|
2283
|
+
apiHost: env.getApiHost(),
|
|
2284
|
+
apiKey: env.getApiKey(),
|
|
2285
|
+
projectId: env.getProjectId(),
|
|
2286
|
+
limitPolicy: createLimitPolicy2({
|
|
2287
|
+
limit: 6
|
|
2288
|
+
}),
|
|
2289
|
+
fetch: (req, init) => {
|
|
2290
|
+
const { cache: fetchCache, revalidate } = determineFetchCacheOptions(cache);
|
|
2291
|
+
return fetch(req, {
|
|
2292
|
+
...init,
|
|
2293
|
+
headers: {
|
|
2294
|
+
...init == null ? void 0 : init.headers,
|
|
2295
|
+
"x-bypass-cache": typeof cache.bypassCache !== "undefined" ? cache.bypassCache.toString() : "false"
|
|
2296
|
+
},
|
|
2297
|
+
cache: fetchCache,
|
|
2298
|
+
next: {
|
|
2299
|
+
revalidate
|
|
2300
|
+
}
|
|
2301
|
+
});
|
|
2302
|
+
}
|
|
2303
|
+
});
|
|
2304
|
+
return manifestClient;
|
|
2305
|
+
};
|
|
2306
|
+
|
|
2307
|
+
// src/handler/helpers.ts
|
|
2308
|
+
var isSvixMessage = async (request) => {
|
|
2309
|
+
const requiredHeaders = ["svix-id", "svix-timestamp", "svix-signature"];
|
|
2310
|
+
const hasAllRequiredHeaders = requiredHeaders.every((header) => request.headers.has(header));
|
|
2311
|
+
if (!hasAllRequiredHeaders) {
|
|
2312
|
+
return {
|
|
2313
|
+
looksLikeMessage: false,
|
|
2314
|
+
validation: false
|
|
2315
|
+
};
|
|
2316
|
+
}
|
|
2317
|
+
if (typeof process.env.UNIFORM_WEBHOOK_SECRET !== "undefined") {
|
|
2318
|
+
const payload = await request.clone().text();
|
|
2319
|
+
const headers = Object.fromEntries(request.headers.entries());
|
|
2320
|
+
const wh = new import_svix.Webhook(process.env.UNIFORM_WEBHOOK_SECRET);
|
|
2321
|
+
try {
|
|
2322
|
+
wh.verify(payload, headers);
|
|
2323
|
+
} catch (e) {
|
|
2324
|
+
return {
|
|
2325
|
+
looksLikeMessage: true,
|
|
2326
|
+
validation: false
|
|
2327
|
+
};
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
return {
|
|
2331
|
+
looksLikeMessage: true,
|
|
2332
|
+
validation: true
|
|
2333
|
+
};
|
|
2334
|
+
};
|
|
2335
|
+
var processCompositionChange = async (compositionId) => {
|
|
2336
|
+
const projectMapClient = getProjectMapClient({
|
|
2337
|
+
cache: {
|
|
2338
|
+
type: "no-cache"
|
|
2339
|
+
}
|
|
2340
|
+
});
|
|
2341
|
+
const [{ nodes }, composition] = await Promise.all([
|
|
2342
|
+
projectMapClient.getNodes({
|
|
2343
|
+
compositionId
|
|
2344
|
+
}),
|
|
2345
|
+
getComposition({ compositionId })
|
|
2346
|
+
]);
|
|
2347
|
+
const tags = [];
|
|
2348
|
+
const paths = [];
|
|
2349
|
+
if (composition == null ? void 0 : composition.pattern) {
|
|
2350
|
+
tags.push("route");
|
|
2351
|
+
}
|
|
2352
|
+
if (nodes) {
|
|
2353
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
2354
|
+
const node = nodes[i];
|
|
2355
|
+
const result = buildProjectMapNodePaths(node.path);
|
|
2356
|
+
tags.push(...result.tags);
|
|
2357
|
+
if (result.paths) {
|
|
2358
|
+
paths.push(...result.paths);
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
tags.push(buildCompositionTag(compositionId));
|
|
2363
|
+
return {
|
|
2364
|
+
tags,
|
|
2365
|
+
paths
|
|
2366
|
+
};
|
|
2367
|
+
};
|
|
2368
|
+
var getComposition = async ({ compositionId }) => {
|
|
2369
|
+
const canvasClient = getCanvasClient({
|
|
2370
|
+
cache: {
|
|
2371
|
+
type: "no-cache"
|
|
2372
|
+
}
|
|
2373
|
+
});
|
|
2374
|
+
try {
|
|
2375
|
+
const composition = await canvasClient.getCompositionById({
|
|
2376
|
+
compositionId
|
|
2377
|
+
});
|
|
2378
|
+
return composition;
|
|
2379
|
+
} catch (err) {
|
|
2380
|
+
if (err instanceof ApiClientError && err.statusCode === 404) {
|
|
2381
|
+
return null;
|
|
2382
|
+
}
|
|
2383
|
+
throw err;
|
|
2384
|
+
}
|
|
2385
|
+
};
|
|
2386
|
+
var buildProjectMapNodePaths = (path) => {
|
|
2387
|
+
const tags = [];
|
|
2388
|
+
const paths = [];
|
|
2389
|
+
const isDynamic = path.includes(":");
|
|
2390
|
+
if (!isDynamic) {
|
|
2391
|
+
tags.push(buildPathTag(path));
|
|
2392
|
+
paths.push(path);
|
|
2393
|
+
} else {
|
|
2394
|
+
const pieces = path.split("/");
|
|
2395
|
+
const invalidatePieces = [];
|
|
2396
|
+
for (let j = 0; j < pieces.length; j++) {
|
|
2397
|
+
const piece = pieces[j];
|
|
2398
|
+
if (piece.startsWith(":")) {
|
|
2399
|
+
break;
|
|
2400
|
+
}
|
|
2401
|
+
invalidatePieces.push(piece);
|
|
2402
|
+
}
|
|
2403
|
+
const toInvalidate = invalidatePieces.join("/");
|
|
2404
|
+
tags.push(buildPathTag(toInvalidate));
|
|
2405
|
+
paths.push(toInvalidate);
|
|
2406
|
+
}
|
|
2407
|
+
return {
|
|
2408
|
+
tags,
|
|
2409
|
+
paths
|
|
2410
|
+
};
|
|
2411
|
+
};
|
|
2412
|
+
var getPathName = (url) => {
|
|
2413
|
+
try {
|
|
2414
|
+
const { pathname } = new URL(url);
|
|
2415
|
+
return pathname;
|
|
2416
|
+
} catch (e) {
|
|
2417
|
+
return url;
|
|
2418
|
+
}
|
|
2419
|
+
};
|
|
2420
|
+
var processRedirectChange = async (sourceUrl) => {
|
|
2421
|
+
const tags = [];
|
|
2422
|
+
const pathName = getPathName(sourceUrl);
|
|
2423
|
+
tags.push(buildPathTag(pathName));
|
|
2424
|
+
return {
|
|
2425
|
+
tags,
|
|
2426
|
+
paths: [pathName]
|
|
2427
|
+
};
|
|
2428
|
+
};
|
|
2429
|
+
|
|
2430
|
+
// src/handler/messages/handleCompositionChanged.ts
|
|
2431
|
+
var import_webhooks = require("@uniformdev/webhooks");
|
|
2432
|
+
var handleCompositionChanged = async (body) => {
|
|
2433
|
+
const parsed = import_webhooks.CompositionChangedDefinition.schema.safeParse(body);
|
|
2434
|
+
if (!parsed.success) {
|
|
2435
|
+
return void 0;
|
|
2436
|
+
}
|
|
2437
|
+
return processCompositionChange(parsed.data.id);
|
|
2438
|
+
};
|
|
2439
|
+
|
|
2440
|
+
// src/handler/messages/handleCompositionDeleted.ts
|
|
2441
|
+
var import_webhooks2 = require("@uniformdev/webhooks");
|
|
2442
|
+
var handleCompositionDeleted = async (body) => {
|
|
2443
|
+
const parsed = import_webhooks2.CompositionDeletedDefinition.schema.safeParse(body);
|
|
2444
|
+
if (!parsed.success) {
|
|
2445
|
+
return void 0;
|
|
2446
|
+
}
|
|
2447
|
+
return processCompositionChange(parsed.data.id);
|
|
2448
|
+
};
|
|
2449
|
+
|
|
2450
|
+
// src/handler/messages/handleCompositionPublished.ts
|
|
2451
|
+
var import_webhooks3 = require("@uniformdev/webhooks");
|
|
2452
|
+
var handleCompositionPublished = async (body) => {
|
|
2453
|
+
const parsed = import_webhooks3.CompositionPublishedDefinition.schema.safeParse(body);
|
|
2454
|
+
if (!parsed.success) {
|
|
2455
|
+
return void 0;
|
|
2456
|
+
}
|
|
2457
|
+
return processCompositionChange(parsed.data.id);
|
|
2458
|
+
};
|
|
2459
|
+
|
|
2460
|
+
// src/handler/messages/handleManifestPublished.ts
|
|
2461
|
+
var import_webhooks4 = require("@uniformdev/webhooks");
|
|
2462
|
+
var handleManifestPublished = async (body) => {
|
|
2463
|
+
const parsed = import_webhooks4.ManifestPublishedDefinition.schema.safeParse(body);
|
|
2464
|
+
if (!parsed.success) {
|
|
2465
|
+
return void 0;
|
|
2466
|
+
}
|
|
2467
|
+
return {
|
|
2468
|
+
tags: ["manifest"]
|
|
2469
|
+
};
|
|
2470
|
+
};
|
|
2471
|
+
|
|
2472
|
+
// src/handler/messages/handleProjectMapNodeDelete.ts
|
|
2473
|
+
var import_webhooks5 = require("@uniformdev/webhooks");
|
|
2474
|
+
var handleProjectMapNodeDelete = async (body) => {
|
|
2475
|
+
const parsed = import_webhooks5.ProjectMapNodeDeleteDefinition.schema.safeParse(body);
|
|
2476
|
+
if (!parsed.success) {
|
|
2477
|
+
return void 0;
|
|
2478
|
+
}
|
|
2479
|
+
const tags = [];
|
|
2480
|
+
const paths = [];
|
|
2481
|
+
const result = buildProjectMapNodePaths(parsed.data.path);
|
|
2482
|
+
tags.push(...result.tags);
|
|
2483
|
+
if (result.paths) {
|
|
2484
|
+
paths.push(...result.paths);
|
|
2485
|
+
}
|
|
2486
|
+
return {
|
|
2487
|
+
tags,
|
|
2488
|
+
paths
|
|
2489
|
+
};
|
|
2490
|
+
};
|
|
2491
|
+
|
|
2492
|
+
// src/handler/messages/handleProjectMapNodeInsert.ts
|
|
2493
|
+
var import_webhooks6 = require("@uniformdev/webhooks");
|
|
2494
|
+
var handleProjectMapNodeInsert = async (body) => {
|
|
2495
|
+
const parsed = import_webhooks6.ProjectMapNodeInsertDefinition.schema.safeParse(body);
|
|
2496
|
+
if (!parsed.success) {
|
|
2497
|
+
return void 0;
|
|
2498
|
+
}
|
|
2499
|
+
const tags = [];
|
|
2500
|
+
const paths = [];
|
|
2501
|
+
const result = buildProjectMapNodePaths(parsed.data.path);
|
|
2502
|
+
tags.push(...result.tags);
|
|
2503
|
+
if (result.paths) {
|
|
2504
|
+
paths.push(...result.paths);
|
|
2505
|
+
}
|
|
2506
|
+
return {
|
|
2507
|
+
tags,
|
|
2508
|
+
paths
|
|
2509
|
+
};
|
|
2510
|
+
};
|
|
2511
|
+
|
|
2512
|
+
// src/handler/messages/handleProjectMapNodeUpdate.ts
|
|
2513
|
+
var import_webhooks7 = require("@uniformdev/webhooks");
|
|
2514
|
+
var handleProjectMapNodeUpdate = async (body) => {
|
|
2515
|
+
const parsed = import_webhooks7.ProjectMapNodeUpdateDefinition.schema.safeParse(body);
|
|
2516
|
+
if (!parsed.success) {
|
|
2517
|
+
return void 0;
|
|
2518
|
+
}
|
|
2519
|
+
const tags = [];
|
|
2520
|
+
const paths = [];
|
|
2521
|
+
const currentResult = buildProjectMapNodePaths(parsed.data.path);
|
|
2522
|
+
tags.push(...currentResult.tags);
|
|
2523
|
+
if (currentResult.paths) {
|
|
2524
|
+
paths.push(...currentResult.paths);
|
|
2525
|
+
}
|
|
2526
|
+
const previousResult = buildProjectMapNodePaths(parsed.data.previous_path);
|
|
2527
|
+
tags.push(...previousResult.tags);
|
|
2528
|
+
if (previousResult.paths) {
|
|
2529
|
+
paths.push(...previousResult.paths);
|
|
2530
|
+
}
|
|
2531
|
+
return {
|
|
2532
|
+
tags,
|
|
2533
|
+
paths
|
|
2534
|
+
};
|
|
2535
|
+
};
|
|
2536
|
+
|
|
2537
|
+
// src/handler/messages/handleRedirectDelete.ts
|
|
2538
|
+
var import_webhooks8 = require("@uniformdev/webhooks");
|
|
2539
|
+
var handleRedirectDelete = async (body) => {
|
|
2540
|
+
const parsed = import_webhooks8.RedirectDeleteDefinition.schema.safeParse(body);
|
|
2541
|
+
if (!parsed.success) {
|
|
2542
|
+
return void 0;
|
|
2543
|
+
}
|
|
2544
|
+
return processRedirectChange(parsed.data.source_url);
|
|
2545
|
+
};
|
|
2546
|
+
|
|
2547
|
+
// src/handler/messages/handleRedirectInsert.ts
|
|
2548
|
+
var import_webhooks9 = require("@uniformdev/webhooks");
|
|
2549
|
+
var handleRedirectInsert = async (body) => {
|
|
2550
|
+
const parsed = import_webhooks9.RedirectInsertDefinition.schema.safeParse(body);
|
|
2551
|
+
if (!parsed.success) {
|
|
2552
|
+
return void 0;
|
|
2553
|
+
}
|
|
2554
|
+
return processRedirectChange(parsed.data.source_url);
|
|
2555
|
+
};
|
|
2556
|
+
|
|
2557
|
+
// src/handler/messages/handleRedirectUpdate.ts
|
|
2558
|
+
var import_webhooks10 = require("@uniformdev/webhooks");
|
|
2559
|
+
var handleRedirectUpdate = async (body) => {
|
|
2560
|
+
const parsed = import_webhooks10.RedirectUpdateDefinition.schema.safeParse(body);
|
|
2561
|
+
if (!parsed.success) {
|
|
2562
|
+
return void 0;
|
|
2563
|
+
}
|
|
2564
|
+
return processRedirectChange(parsed.data.source_url);
|
|
2565
|
+
};
|
|
2566
|
+
|
|
2567
|
+
// src/handler/createPreviewPOSTRouteHandler.ts
|
|
2568
|
+
var createPreviewPOSTRouteHandler = () => {
|
|
2569
|
+
return async (request) => {
|
|
2570
|
+
let previewSecretPassed = false;
|
|
2571
|
+
if (process.env.UNIFORM_PREVIEW_SECRET) {
|
|
2572
|
+
const secretValue = request.nextUrl.searchParams.get(SECRET_QUERY_STRING_PARAM);
|
|
2573
|
+
if (secretValue !== process.env.UNIFORM_PREVIEW_SECRET) {
|
|
2574
|
+
console.warn(
|
|
2575
|
+
"The preview secret passed in the query string does not match the UNIFORM_PREVIEW_SECRET env var."
|
|
2576
|
+
);
|
|
2577
|
+
} else {
|
|
2578
|
+
previewSecretPassed = true;
|
|
2579
|
+
}
|
|
2580
|
+
} else {
|
|
2581
|
+
if (!process.env.UNIFORM_WEBHOOK_SECRET) {
|
|
2582
|
+
console.warn("Both UNIFORM_PREVIEW_SECRET and UNIFORM_WEBHOOK_SECRET are not set.");
|
|
2583
|
+
}
|
|
2584
|
+
previewSecretPassed = true;
|
|
2585
|
+
}
|
|
2586
|
+
if (!previewSecretPassed) {
|
|
2587
|
+
return new Response("The request could not be validated.", {
|
|
2588
|
+
status: 401
|
|
2589
|
+
});
|
|
2590
|
+
}
|
|
2591
|
+
const { looksLikeMessage, validation } = await isSvixMessage(request);
|
|
2592
|
+
if (looksLikeMessage) {
|
|
2593
|
+
if (!validation) {
|
|
2594
|
+
return new Response("This looks like a webhook request but the validation failed.", { status: 401 });
|
|
2595
|
+
}
|
|
2596
|
+
return handleSvixMessage(request);
|
|
2597
|
+
}
|
|
2598
|
+
return new Response("This is not a webhook request.", { status: 401 });
|
|
2599
|
+
};
|
|
2600
|
+
};
|
|
2601
|
+
var handleSvixMessage = async (request) => {
|
|
2602
|
+
var _a;
|
|
2603
|
+
const handlers = [
|
|
2604
|
+
handleProjectMapNodeUpdate,
|
|
2605
|
+
handleProjectMapNodeInsert,
|
|
2606
|
+
handleProjectMapNodeDelete,
|
|
2607
|
+
handleCompositionDeleted,
|
|
2608
|
+
handleCompositionChanged,
|
|
2609
|
+
handleCompositionPublished,
|
|
2610
|
+
handleRedirectInsert,
|
|
2611
|
+
handleRedirectUpdate,
|
|
2612
|
+
handleRedirectDelete,
|
|
2613
|
+
handleManifestPublished
|
|
2614
|
+
];
|
|
2615
|
+
let tags = void 0;
|
|
2616
|
+
let paths = void 0;
|
|
2617
|
+
let jsonBody;
|
|
2618
|
+
try {
|
|
2619
|
+
jsonBody = await request.json();
|
|
2620
|
+
} catch (err) {
|
|
2621
|
+
console.error("Error parsing the request body as JSON.", err);
|
|
2622
|
+
return new Response("Error parsing the request body as JSON.", {
|
|
2623
|
+
status: 400
|
|
2624
|
+
});
|
|
2625
|
+
}
|
|
2626
|
+
for (let i = 0; i < handlers.length; i++) {
|
|
2627
|
+
const handler = handlers[i];
|
|
2628
|
+
const result = await handler(jsonBody);
|
|
2629
|
+
if (result) {
|
|
2630
|
+
tags = result.tags;
|
|
2631
|
+
paths = result.paths;
|
|
2632
|
+
break;
|
|
2633
|
+
}
|
|
2634
|
+
}
|
|
2635
|
+
if (tags == null ? void 0 : tags.length) {
|
|
2636
|
+
const cache = ((_a = getServerConfig().experimental) == null ? void 0 : _a.middlewareRuntimeCache) ? (0, import_functions.getCache)() : void 0;
|
|
2637
|
+
for (let i = 0; i < tags.length; i++) {
|
|
2638
|
+
const tag = tags[i];
|
|
2639
|
+
(0, import_cache4.revalidateTag)(tag, "max");
|
|
2640
|
+
if (cache) {
|
|
2641
|
+
await cache.expireTag(tag);
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2645
|
+
if (paths == null ? void 0 : paths.length) {
|
|
2646
|
+
for (let i = 0; i < paths.length; i++) {
|
|
2647
|
+
const path = paths[i];
|
|
2648
|
+
(0, import_cache4.revalidatePath)(path);
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2651
|
+
return new Response(
|
|
2652
|
+
JSON.stringify({
|
|
2653
|
+
handled: typeof tags !== "undefined" || typeof paths !== "undefined",
|
|
2654
|
+
tags,
|
|
2655
|
+
paths
|
|
2656
|
+
})
|
|
2657
|
+
);
|
|
2658
|
+
};
|
|
2659
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2660
|
+
0 && (module.exports = {
|
|
2661
|
+
createPreviewGETRouteHandler,
|
|
2662
|
+
createPreviewOPTIONSRouteHandler,
|
|
2663
|
+
createPreviewPOSTRouteHandler
|
|
2664
|
+
});
|