@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/index.js
ADDED
|
@@ -0,0 +1,3953 @@
|
|
|
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/index.ts
|
|
152
|
+
var src_exports = {};
|
|
153
|
+
__export(src_exports, {
|
|
154
|
+
DefaultDataClient: () => DefaultDataClient,
|
|
155
|
+
UniformComposition: () => UniformComposition,
|
|
156
|
+
UniformPlayground: () => UniformPlayground,
|
|
157
|
+
createCompositionCache: () => createCompositionCache,
|
|
158
|
+
createUniformPlaygroundStaticParams: () => createUniformPlaygroundStaticParams,
|
|
159
|
+
createUniformStaticParams: () => createUniformStaticParams,
|
|
160
|
+
expireMiddlewareCacheTag: () => expireMiddlewareCacheTag,
|
|
161
|
+
findRouteMatch: () => findRouteMatch,
|
|
162
|
+
getCanvasClient: () => getCanvasClient,
|
|
163
|
+
getManifest: () => getManifest,
|
|
164
|
+
getManifestClient: () => getManifestClient,
|
|
165
|
+
getProjectMapClient: () => getProjectMapClient,
|
|
166
|
+
getRouteClient: () => getRouteClient,
|
|
167
|
+
precomputeComposition: () => precomputeComposition,
|
|
168
|
+
resolvePlaygroundRoute: () => resolvePlaygroundRoute,
|
|
169
|
+
resolveRouteFromCode: () => resolveRouteFromCode,
|
|
170
|
+
serverContext: () => serverContext
|
|
171
|
+
});
|
|
172
|
+
module.exports = __toCommonJS(src_exports);
|
|
173
|
+
var import_server_only5 = require("server-only");
|
|
174
|
+
|
|
175
|
+
// src/clients/canvas.ts
|
|
176
|
+
var import_server_only = require("server-only");
|
|
177
|
+
|
|
178
|
+
// ../context/dist/api/api.mjs
|
|
179
|
+
var import_p_limit = __toESM(require_p_limit(), 1);
|
|
180
|
+
var __defProp2 = Object.defineProperty;
|
|
181
|
+
var __typeError = (msg) => {
|
|
182
|
+
throw TypeError(msg);
|
|
183
|
+
};
|
|
184
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
185
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
186
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
187
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
188
|
+
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);
|
|
189
|
+
var defaultLimitPolicy = (0, import_p_limit.default)(6);
|
|
190
|
+
var ApiClientError = class _ApiClientError extends Error {
|
|
191
|
+
constructor(errorMessage, fetchMethod, fetchUri, statusCode, statusText, requestId) {
|
|
192
|
+
super(
|
|
193
|
+
`${errorMessage}
|
|
194
|
+
${statusCode}${statusText ? " " + statusText : ""} (${fetchMethod} ${fetchUri}${requestId ? ` Request ID: ${requestId}` : ""})`
|
|
195
|
+
);
|
|
196
|
+
this.errorMessage = errorMessage;
|
|
197
|
+
this.fetchMethod = fetchMethod;
|
|
198
|
+
this.fetchUri = fetchUri;
|
|
199
|
+
this.statusCode = statusCode;
|
|
200
|
+
this.statusText = statusText;
|
|
201
|
+
this.requestId = requestId;
|
|
202
|
+
Object.setPrototypeOf(this, _ApiClientError.prototype);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
var ApiClient = class _ApiClient {
|
|
206
|
+
constructor(options) {
|
|
207
|
+
__publicField(this, "options");
|
|
208
|
+
var _a, _b, _c, _d, _e;
|
|
209
|
+
if (!options.apiKey && !options.bearerToken) {
|
|
210
|
+
throw new Error("You must provide an API key or a bearer token");
|
|
211
|
+
}
|
|
212
|
+
let leFetch = options.fetch;
|
|
213
|
+
if (!leFetch) {
|
|
214
|
+
if (typeof window !== "undefined") {
|
|
215
|
+
leFetch = window.fetch.bind(window);
|
|
216
|
+
} else if (typeof fetch !== "undefined") {
|
|
217
|
+
leFetch = fetch;
|
|
218
|
+
} else {
|
|
219
|
+
throw new Error("You must provide or polyfill a fetch implementation when not in a browser");
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
this.options = {
|
|
223
|
+
...options,
|
|
224
|
+
fetch: leFetch,
|
|
225
|
+
apiHost: this.ensureApiHost(options.apiHost),
|
|
226
|
+
apiKey: (_a = options.apiKey) != null ? _a : null,
|
|
227
|
+
projectId: (_b = options.projectId) != null ? _b : null,
|
|
228
|
+
bearerToken: (_c = options.bearerToken) != null ? _c : null,
|
|
229
|
+
limitPolicy: (_d = options.limitPolicy) != null ? _d : defaultLimitPolicy,
|
|
230
|
+
bypassCache: (_e = options.bypassCache) != null ? _e : false
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
async apiClient(fetchUri, options) {
|
|
234
|
+
return (await this.apiClientWithResponse(fetchUri, options)).body;
|
|
235
|
+
}
|
|
236
|
+
async apiClientWithResponse(fetchUri, options) {
|
|
237
|
+
return this.options.limitPolicy(async () => {
|
|
238
|
+
var _a;
|
|
239
|
+
const coreHeaders = this.options.apiKey ? {
|
|
240
|
+
"x-api-key": this.options.apiKey
|
|
241
|
+
} : {
|
|
242
|
+
Authorization: `Bearer ${this.options.bearerToken}`
|
|
243
|
+
};
|
|
244
|
+
if (this.options.bypassCache) {
|
|
245
|
+
coreHeaders["x-bypass-cache"] = "true";
|
|
246
|
+
}
|
|
247
|
+
const { fetch: fetch2, signal } = this.options;
|
|
248
|
+
const callApi = () => fetch2(fetchUri.toString(), {
|
|
249
|
+
...options,
|
|
250
|
+
signal,
|
|
251
|
+
headers: {
|
|
252
|
+
...options == null ? void 0 : options.headers,
|
|
253
|
+
...coreHeaders
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
const apiResponse = await handleRateLimits(callApi);
|
|
257
|
+
if (!apiResponse.ok) {
|
|
258
|
+
let message = "";
|
|
259
|
+
try {
|
|
260
|
+
const responseText = await apiResponse.text();
|
|
261
|
+
try {
|
|
262
|
+
const parsed = JSON.parse(responseText);
|
|
263
|
+
if (parsed.errorMessage) {
|
|
264
|
+
message = Array.isArray(parsed.errorMessage) ? parsed.errorMessage.join(", ") : parsed.errorMessage;
|
|
265
|
+
} else {
|
|
266
|
+
message = responseText;
|
|
267
|
+
}
|
|
268
|
+
} catch (e) {
|
|
269
|
+
message = responseText;
|
|
270
|
+
}
|
|
271
|
+
} catch (e) {
|
|
272
|
+
message = `General error`;
|
|
273
|
+
}
|
|
274
|
+
throw new ApiClientError(
|
|
275
|
+
message,
|
|
276
|
+
(_a = options == null ? void 0 : options.method) != null ? _a : "GET",
|
|
277
|
+
fetchUri.toString(),
|
|
278
|
+
apiResponse.status,
|
|
279
|
+
apiResponse.statusText,
|
|
280
|
+
_ApiClient.getRequestId(apiResponse)
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
if (options == null ? void 0 : options.expectNoContent) {
|
|
284
|
+
return { response: apiResponse, body: null };
|
|
285
|
+
}
|
|
286
|
+
return {
|
|
287
|
+
response: apiResponse,
|
|
288
|
+
body: await apiResponse.json()
|
|
289
|
+
};
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
createUrl(path, queryParams, hostOverride) {
|
|
293
|
+
const url = new URL(`${hostOverride != null ? hostOverride : this.options.apiHost}${path}`);
|
|
294
|
+
Object.entries(queryParams != null ? queryParams : {}).forEach(([key, value]) => {
|
|
295
|
+
var _a;
|
|
296
|
+
if (typeof value !== "undefined" && value !== null) {
|
|
297
|
+
url.searchParams.append(key, Array.isArray(value) ? value.join(",") : (_a = value == null ? void 0 : value.toString()) != null ? _a : "");
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
return url;
|
|
301
|
+
}
|
|
302
|
+
ensureApiHost(apiHost) {
|
|
303
|
+
if (!apiHost) return "https://uniform.app";
|
|
304
|
+
if (!(apiHost == null ? void 0 : apiHost.startsWith("http"))) {
|
|
305
|
+
throw new Error('Your apiHost must start with "http"');
|
|
306
|
+
}
|
|
307
|
+
if (apiHost.indexOf("/", 8) > -1) {
|
|
308
|
+
throw new Error("Your apiHost must not contain a path element after the domain");
|
|
309
|
+
}
|
|
310
|
+
if (apiHost.indexOf("?") > -1) {
|
|
311
|
+
throw new Error("Your apiHost must not contain a query string");
|
|
312
|
+
}
|
|
313
|
+
if (apiHost == null ? void 0 : apiHost.endsWith("/")) {
|
|
314
|
+
apiHost = apiHost.substring(0, apiHost.length - 1);
|
|
315
|
+
}
|
|
316
|
+
return apiHost;
|
|
317
|
+
}
|
|
318
|
+
static getRequestId(response) {
|
|
319
|
+
const apigRequestId = response.headers.get("apigw-requestid");
|
|
320
|
+
if (apigRequestId) {
|
|
321
|
+
return apigRequestId;
|
|
322
|
+
}
|
|
323
|
+
return void 0;
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
async function handleRateLimits(callApi) {
|
|
327
|
+
var _a;
|
|
328
|
+
const backoffRetries = 5;
|
|
329
|
+
let backoffRetriesLeft = backoffRetries;
|
|
330
|
+
let response;
|
|
331
|
+
while (backoffRetriesLeft > 0) {
|
|
332
|
+
response = await callApi();
|
|
333
|
+
if (response.status !== 429) {
|
|
334
|
+
break;
|
|
335
|
+
}
|
|
336
|
+
let resetWait = 0;
|
|
337
|
+
try {
|
|
338
|
+
const responseClone = response.clone();
|
|
339
|
+
const dateHeader = responseClone.headers.get("date");
|
|
340
|
+
const serverTime = dateHeader ? new Date(dateHeader).getTime() : void 0;
|
|
341
|
+
const body = await responseClone.json();
|
|
342
|
+
const resetTime = (_a = body == null ? void 0 : body.info) == null ? void 0 : _a.reset;
|
|
343
|
+
if (typeof serverTime === "number" && typeof resetTime === "number") {
|
|
344
|
+
resetWait = Math.max(0, Math.min(Math.round(1.1 * (resetTime - serverTime)), 1e4));
|
|
345
|
+
}
|
|
346
|
+
} catch (e) {
|
|
347
|
+
}
|
|
348
|
+
const base = Math.pow(2, backoffRetries - backoffRetriesLeft) * 333;
|
|
349
|
+
const backoffWait = base + Math.round(Math.random() * (base / 2)) * (Math.random() > 0.5 ? 1 : -1);
|
|
350
|
+
await new Promise((resolve) => setTimeout(resolve, resetWait + backoffWait));
|
|
351
|
+
backoffRetriesLeft -= 1;
|
|
352
|
+
}
|
|
353
|
+
return response;
|
|
354
|
+
}
|
|
355
|
+
var _url;
|
|
356
|
+
var _AggregateClient = class _AggregateClient2 extends ApiClient {
|
|
357
|
+
constructor(options) {
|
|
358
|
+
super(options);
|
|
359
|
+
}
|
|
360
|
+
/** Fetches all aggregates for a project */
|
|
361
|
+
async get(options) {
|
|
362
|
+
const { projectId } = this.options;
|
|
363
|
+
const fetchUri = this.createUrl(__privateGet(_AggregateClient2, _url), { ...options, projectId });
|
|
364
|
+
return await this.apiClient(fetchUri);
|
|
365
|
+
}
|
|
366
|
+
/** Updates or creates (based on id) an Aggregate */
|
|
367
|
+
async upsert(body) {
|
|
368
|
+
const fetchUri = this.createUrl(__privateGet(_AggregateClient2, _url));
|
|
369
|
+
await this.apiClient(fetchUri, {
|
|
370
|
+
method: "PUT",
|
|
371
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
372
|
+
expectNoContent: true
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
/** Deletes an Aggregate */
|
|
376
|
+
async remove(body) {
|
|
377
|
+
const fetchUri = this.createUrl(__privateGet(_AggregateClient2, _url));
|
|
378
|
+
await this.apiClient(fetchUri, {
|
|
379
|
+
method: "DELETE",
|
|
380
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
381
|
+
expectNoContent: true
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
_url = /* @__PURE__ */ new WeakMap();
|
|
386
|
+
__privateAdd(_AggregateClient, _url, "/api/v2/aggregate");
|
|
387
|
+
var _url2;
|
|
388
|
+
var _DimensionClient = class _DimensionClient2 extends ApiClient {
|
|
389
|
+
constructor(options) {
|
|
390
|
+
super(options);
|
|
391
|
+
}
|
|
392
|
+
/** Fetches the known score dimensions for a project */
|
|
393
|
+
async get(options) {
|
|
394
|
+
const { projectId } = this.options;
|
|
395
|
+
const fetchUri = this.createUrl(__privateGet(_DimensionClient2, _url2), { ...options, projectId });
|
|
396
|
+
return await this.apiClient(fetchUri);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
_url2 = /* @__PURE__ */ new WeakMap();
|
|
400
|
+
__privateAdd(_DimensionClient, _url2, "/api/v2/dimension");
|
|
401
|
+
var _url3;
|
|
402
|
+
var _valueUrl;
|
|
403
|
+
var _EnrichmentClient = class _EnrichmentClient2 extends ApiClient {
|
|
404
|
+
constructor(options) {
|
|
405
|
+
super(options);
|
|
406
|
+
}
|
|
407
|
+
/** Fetches all enrichments and values for a project, grouped by category */
|
|
408
|
+
async get(options) {
|
|
409
|
+
const { projectId } = this.options;
|
|
410
|
+
const fetchUri = this.createUrl(__privateGet(_EnrichmentClient2, _url3), { ...options, projectId });
|
|
411
|
+
return await this.apiClient(fetchUri);
|
|
412
|
+
}
|
|
413
|
+
/** Updates or creates (based on id) an enrichment category */
|
|
414
|
+
async upsertCategory(body) {
|
|
415
|
+
const fetchUri = this.createUrl(__privateGet(_EnrichmentClient2, _url3));
|
|
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 category */
|
|
423
|
+
async removeCategory(body) {
|
|
424
|
+
const fetchUri = this.createUrl(__privateGet(_EnrichmentClient2, _url3));
|
|
425
|
+
await this.apiClient(fetchUri, {
|
|
426
|
+
method: "DELETE",
|
|
427
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
428
|
+
expectNoContent: true
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
/** Updates or creates (based on id) an enrichment value within an enrichment category */
|
|
432
|
+
async upsertValue(body) {
|
|
433
|
+
const fetchUri = this.createUrl(__privateGet(_EnrichmentClient2, _valueUrl));
|
|
434
|
+
await this.apiClient(fetchUri, {
|
|
435
|
+
method: "PUT",
|
|
436
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
437
|
+
expectNoContent: true
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
/** Deletes an enrichment value within an enrichment category. The category is left alone. */
|
|
441
|
+
async removeValue(body) {
|
|
442
|
+
const fetchUri = this.createUrl(__privateGet(_EnrichmentClient2, _valueUrl));
|
|
443
|
+
await this.apiClient(fetchUri, {
|
|
444
|
+
method: "DELETE",
|
|
445
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
446
|
+
expectNoContent: true
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
_url3 = /* @__PURE__ */ new WeakMap();
|
|
451
|
+
_valueUrl = /* @__PURE__ */ new WeakMap();
|
|
452
|
+
__privateAdd(_EnrichmentClient, _url3, "/api/v1/enrichments");
|
|
453
|
+
__privateAdd(_EnrichmentClient, _valueUrl, "/api/v1/enrichment-values");
|
|
454
|
+
var _url4;
|
|
455
|
+
var _ManifestClient = class _ManifestClient2 extends ApiClient {
|
|
456
|
+
constructor(options) {
|
|
457
|
+
super(options);
|
|
458
|
+
}
|
|
459
|
+
/** Fetches the Context manifest for a project */
|
|
460
|
+
async get(options) {
|
|
461
|
+
const { projectId } = this.options;
|
|
462
|
+
const fetchUri = this.createUrl(__privateGet(_ManifestClient2, _url4), { ...options, projectId });
|
|
463
|
+
return await this.apiClient(fetchUri);
|
|
464
|
+
}
|
|
465
|
+
/** Publishes the Context manifest for a project */
|
|
466
|
+
async publish() {
|
|
467
|
+
const { projectId } = this.options;
|
|
468
|
+
const fetchUri = this.createUrl("/api/v1/publish", { siteId: projectId });
|
|
469
|
+
await this.apiClient(fetchUri, {
|
|
470
|
+
method: "POST",
|
|
471
|
+
expectNoContent: true
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
_url4 = /* @__PURE__ */ new WeakMap();
|
|
476
|
+
__privateAdd(_ManifestClient, _url4, "/api/v2/manifest");
|
|
477
|
+
var ManifestClient = _ManifestClient;
|
|
478
|
+
var _url5;
|
|
479
|
+
var _QuirkClient = class _QuirkClient2 extends ApiClient {
|
|
480
|
+
constructor(options) {
|
|
481
|
+
super(options);
|
|
482
|
+
}
|
|
483
|
+
/** Fetches all Quirks for a project */
|
|
484
|
+
async get(options) {
|
|
485
|
+
const { projectId } = this.options;
|
|
486
|
+
const fetchUri = this.createUrl(__privateGet(_QuirkClient2, _url5), { ...options, projectId });
|
|
487
|
+
return await this.apiClient(fetchUri);
|
|
488
|
+
}
|
|
489
|
+
/** Updates or creates (based on id) a Quirk */
|
|
490
|
+
async upsert(body) {
|
|
491
|
+
const fetchUri = this.createUrl(__privateGet(_QuirkClient2, _url5));
|
|
492
|
+
await this.apiClient(fetchUri, {
|
|
493
|
+
method: "PUT",
|
|
494
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
495
|
+
expectNoContent: true
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
/** Deletes a Quirk */
|
|
499
|
+
async remove(body) {
|
|
500
|
+
const fetchUri = this.createUrl(__privateGet(_QuirkClient2, _url5));
|
|
501
|
+
await this.apiClient(fetchUri, {
|
|
502
|
+
method: "DELETE",
|
|
503
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
504
|
+
expectNoContent: true
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
_url5 = /* @__PURE__ */ new WeakMap();
|
|
509
|
+
__privateAdd(_QuirkClient, _url5, "/api/v2/quirk");
|
|
510
|
+
var _url6;
|
|
511
|
+
var _SignalClient = class _SignalClient2 extends ApiClient {
|
|
512
|
+
constructor(options) {
|
|
513
|
+
super(options);
|
|
514
|
+
}
|
|
515
|
+
/** Fetches all Signals for a project */
|
|
516
|
+
async get(options) {
|
|
517
|
+
const { projectId } = this.options;
|
|
518
|
+
const fetchUri = this.createUrl(__privateGet(_SignalClient2, _url6), { ...options, projectId });
|
|
519
|
+
return await this.apiClient(fetchUri);
|
|
520
|
+
}
|
|
521
|
+
/** Updates or creates (based on id) a Signal */
|
|
522
|
+
async upsert(body) {
|
|
523
|
+
const fetchUri = this.createUrl(__privateGet(_SignalClient2, _url6));
|
|
524
|
+
await this.apiClient(fetchUri, {
|
|
525
|
+
method: "PUT",
|
|
526
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
527
|
+
expectNoContent: true
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
/** Deletes a Signal */
|
|
531
|
+
async remove(body) {
|
|
532
|
+
const fetchUri = this.createUrl(__privateGet(_SignalClient2, _url6));
|
|
533
|
+
await this.apiClient(fetchUri, {
|
|
534
|
+
method: "DELETE",
|
|
535
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
536
|
+
expectNoContent: true
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
_url6 = /* @__PURE__ */ new WeakMap();
|
|
541
|
+
__privateAdd(_SignalClient, _url6, "/api/v2/signal");
|
|
542
|
+
var _url7;
|
|
543
|
+
var _TestClient = class _TestClient2 extends ApiClient {
|
|
544
|
+
constructor(options) {
|
|
545
|
+
super(options);
|
|
546
|
+
}
|
|
547
|
+
/** Fetches all Tests for a project */
|
|
548
|
+
async get(options) {
|
|
549
|
+
const { projectId } = this.options;
|
|
550
|
+
const fetchUri = this.createUrl(__privateGet(_TestClient2, _url7), { ...options, projectId });
|
|
551
|
+
return await this.apiClient(fetchUri);
|
|
552
|
+
}
|
|
553
|
+
/** Updates or creates (based on id) a Test */
|
|
554
|
+
async upsert(body) {
|
|
555
|
+
const fetchUri = this.createUrl(__privateGet(_TestClient2, _url7));
|
|
556
|
+
await this.apiClient(fetchUri, {
|
|
557
|
+
method: "PUT",
|
|
558
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
559
|
+
expectNoContent: true
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
/** Deletes a Test */
|
|
563
|
+
async remove(body) {
|
|
564
|
+
const fetchUri = this.createUrl(__privateGet(_TestClient2, _url7));
|
|
565
|
+
await this.apiClient(fetchUri, {
|
|
566
|
+
method: "DELETE",
|
|
567
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
568
|
+
expectNoContent: true
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
_url7 = /* @__PURE__ */ new WeakMap();
|
|
573
|
+
__privateAdd(_TestClient, _url7, "/api/v2/test");
|
|
574
|
+
|
|
575
|
+
// ../canvas/dist/index.mjs
|
|
576
|
+
var __create2 = Object.create;
|
|
577
|
+
var __defProp3 = Object.defineProperty;
|
|
578
|
+
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
579
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
580
|
+
var __getProtoOf2 = Object.getPrototypeOf;
|
|
581
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
582
|
+
var __typeError2 = (msg) => {
|
|
583
|
+
throw TypeError(msg);
|
|
584
|
+
};
|
|
585
|
+
var __commonJS2 = (cb, mod) => function __require() {
|
|
586
|
+
return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
587
|
+
};
|
|
588
|
+
var __copyProps2 = (to, from, except, desc) => {
|
|
589
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
590
|
+
for (let key of __getOwnPropNames2(from))
|
|
591
|
+
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
592
|
+
__defProp3(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
|
593
|
+
}
|
|
594
|
+
return to;
|
|
595
|
+
};
|
|
596
|
+
var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
|
|
597
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
598
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
599
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
600
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
601
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp3(target, "default", { value: mod, enumerable: true }) : target,
|
|
602
|
+
mod
|
|
603
|
+
));
|
|
604
|
+
var __accessCheck2 = (obj, member, msg) => member.has(obj) || __typeError2("Cannot " + msg);
|
|
605
|
+
var __privateGet2 = (obj, member, getter) => (__accessCheck2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
606
|
+
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);
|
|
607
|
+
var require_yocto_queue2 = __commonJS2({
|
|
608
|
+
"../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js"(exports2, module2) {
|
|
609
|
+
"use strict";
|
|
610
|
+
var Node = class {
|
|
611
|
+
/// value;
|
|
612
|
+
/// next;
|
|
613
|
+
constructor(value) {
|
|
614
|
+
this.value = value;
|
|
615
|
+
this.next = void 0;
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
var Queue = class {
|
|
619
|
+
// TODO: Use private class fields when targeting Node.js 12.
|
|
620
|
+
// #_head;
|
|
621
|
+
// #_tail;
|
|
622
|
+
// #_size;
|
|
623
|
+
constructor() {
|
|
624
|
+
this.clear();
|
|
625
|
+
}
|
|
626
|
+
enqueue(value) {
|
|
627
|
+
const node = new Node(value);
|
|
628
|
+
if (this._head) {
|
|
629
|
+
this._tail.next = node;
|
|
630
|
+
this._tail = node;
|
|
631
|
+
} else {
|
|
632
|
+
this._head = node;
|
|
633
|
+
this._tail = node;
|
|
634
|
+
}
|
|
635
|
+
this._size++;
|
|
636
|
+
}
|
|
637
|
+
dequeue() {
|
|
638
|
+
const current = this._head;
|
|
639
|
+
if (!current) {
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
this._head = this._head.next;
|
|
643
|
+
this._size--;
|
|
644
|
+
return current.value;
|
|
645
|
+
}
|
|
646
|
+
clear() {
|
|
647
|
+
this._head = void 0;
|
|
648
|
+
this._tail = void 0;
|
|
649
|
+
this._size = 0;
|
|
650
|
+
}
|
|
651
|
+
get size() {
|
|
652
|
+
return this._size;
|
|
653
|
+
}
|
|
654
|
+
*[Symbol.iterator]() {
|
|
655
|
+
let current = this._head;
|
|
656
|
+
while (current) {
|
|
657
|
+
yield current.value;
|
|
658
|
+
current = current.next;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
module2.exports = Queue;
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
var require_p_limit2 = __commonJS2({
|
|
666
|
+
"../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js"(exports2, module2) {
|
|
667
|
+
"use strict";
|
|
668
|
+
var Queue = require_yocto_queue2();
|
|
669
|
+
var pLimit2 = (concurrency) => {
|
|
670
|
+
if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
|
|
671
|
+
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
672
|
+
}
|
|
673
|
+
const queue = new Queue();
|
|
674
|
+
let activeCount = 0;
|
|
675
|
+
const next = () => {
|
|
676
|
+
activeCount--;
|
|
677
|
+
if (queue.size > 0) {
|
|
678
|
+
queue.dequeue()();
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
const run = async (fn, resolve, ...args) => {
|
|
682
|
+
activeCount++;
|
|
683
|
+
const result = (async () => fn(...args))();
|
|
684
|
+
resolve(result);
|
|
685
|
+
try {
|
|
686
|
+
await result;
|
|
687
|
+
} catch (e) {
|
|
688
|
+
}
|
|
689
|
+
next();
|
|
690
|
+
};
|
|
691
|
+
const enqueue = (fn, resolve, ...args) => {
|
|
692
|
+
queue.enqueue(run.bind(null, fn, resolve, ...args));
|
|
693
|
+
(async () => {
|
|
694
|
+
await Promise.resolve();
|
|
695
|
+
if (activeCount < concurrency && queue.size > 0) {
|
|
696
|
+
queue.dequeue()();
|
|
697
|
+
}
|
|
698
|
+
})();
|
|
699
|
+
};
|
|
700
|
+
const generator = (fn, ...args) => new Promise((resolve) => {
|
|
701
|
+
enqueue(fn, resolve, ...args);
|
|
702
|
+
});
|
|
703
|
+
Object.defineProperties(generator, {
|
|
704
|
+
activeCount: {
|
|
705
|
+
get: () => activeCount
|
|
706
|
+
},
|
|
707
|
+
pendingCount: {
|
|
708
|
+
get: () => queue.size
|
|
709
|
+
},
|
|
710
|
+
clearQueue: {
|
|
711
|
+
value: () => {
|
|
712
|
+
queue.clear();
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
});
|
|
716
|
+
return generator;
|
|
717
|
+
};
|
|
718
|
+
module2.exports = pLimit2;
|
|
719
|
+
}
|
|
720
|
+
});
|
|
721
|
+
var require_retry_operation = __commonJS2({
|
|
722
|
+
"../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js"(exports2, module2) {
|
|
723
|
+
"use strict";
|
|
724
|
+
function RetryOperation(timeouts, options) {
|
|
725
|
+
if (typeof options === "boolean") {
|
|
726
|
+
options = { forever: options };
|
|
727
|
+
}
|
|
728
|
+
this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
|
|
729
|
+
this._timeouts = timeouts;
|
|
730
|
+
this._options = options || {};
|
|
731
|
+
this._maxRetryTime = options && options.maxRetryTime || Infinity;
|
|
732
|
+
this._fn = null;
|
|
733
|
+
this._errors = [];
|
|
734
|
+
this._attempts = 1;
|
|
735
|
+
this._operationTimeout = null;
|
|
736
|
+
this._operationTimeoutCb = null;
|
|
737
|
+
this._timeout = null;
|
|
738
|
+
this._operationStart = null;
|
|
739
|
+
this._timer = null;
|
|
740
|
+
if (this._options.forever) {
|
|
741
|
+
this._cachedTimeouts = this._timeouts.slice(0);
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
module2.exports = RetryOperation;
|
|
745
|
+
RetryOperation.prototype.reset = function() {
|
|
746
|
+
this._attempts = 1;
|
|
747
|
+
this._timeouts = this._originalTimeouts.slice(0);
|
|
748
|
+
};
|
|
749
|
+
RetryOperation.prototype.stop = function() {
|
|
750
|
+
if (this._timeout) {
|
|
751
|
+
clearTimeout(this._timeout);
|
|
752
|
+
}
|
|
753
|
+
if (this._timer) {
|
|
754
|
+
clearTimeout(this._timer);
|
|
755
|
+
}
|
|
756
|
+
this._timeouts = [];
|
|
757
|
+
this._cachedTimeouts = null;
|
|
758
|
+
};
|
|
759
|
+
RetryOperation.prototype.retry = function(err) {
|
|
760
|
+
if (this._timeout) {
|
|
761
|
+
clearTimeout(this._timeout);
|
|
762
|
+
}
|
|
763
|
+
if (!err) {
|
|
764
|
+
return false;
|
|
765
|
+
}
|
|
766
|
+
var currentTime = (/* @__PURE__ */ new Date()).getTime();
|
|
767
|
+
if (err && currentTime - this._operationStart >= this._maxRetryTime) {
|
|
768
|
+
this._errors.push(err);
|
|
769
|
+
this._errors.unshift(new Error("RetryOperation timeout occurred"));
|
|
770
|
+
return false;
|
|
771
|
+
}
|
|
772
|
+
this._errors.push(err);
|
|
773
|
+
var timeout = this._timeouts.shift();
|
|
774
|
+
if (timeout === void 0) {
|
|
775
|
+
if (this._cachedTimeouts) {
|
|
776
|
+
this._errors.splice(0, this._errors.length - 1);
|
|
777
|
+
timeout = this._cachedTimeouts.slice(-1);
|
|
778
|
+
} else {
|
|
779
|
+
return false;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
var self = this;
|
|
783
|
+
this._timer = setTimeout(function() {
|
|
784
|
+
self._attempts++;
|
|
785
|
+
if (self._operationTimeoutCb) {
|
|
786
|
+
self._timeout = setTimeout(function() {
|
|
787
|
+
self._operationTimeoutCb(self._attempts);
|
|
788
|
+
}, self._operationTimeout);
|
|
789
|
+
if (self._options.unref) {
|
|
790
|
+
self._timeout.unref();
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
self._fn(self._attempts);
|
|
794
|
+
}, timeout);
|
|
795
|
+
if (this._options.unref) {
|
|
796
|
+
this._timer.unref();
|
|
797
|
+
}
|
|
798
|
+
return true;
|
|
799
|
+
};
|
|
800
|
+
RetryOperation.prototype.attempt = function(fn, timeoutOps) {
|
|
801
|
+
this._fn = fn;
|
|
802
|
+
if (timeoutOps) {
|
|
803
|
+
if (timeoutOps.timeout) {
|
|
804
|
+
this._operationTimeout = timeoutOps.timeout;
|
|
805
|
+
}
|
|
806
|
+
if (timeoutOps.cb) {
|
|
807
|
+
this._operationTimeoutCb = timeoutOps.cb;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
var self = this;
|
|
811
|
+
if (this._operationTimeoutCb) {
|
|
812
|
+
this._timeout = setTimeout(function() {
|
|
813
|
+
self._operationTimeoutCb();
|
|
814
|
+
}, self._operationTimeout);
|
|
815
|
+
}
|
|
816
|
+
this._operationStart = (/* @__PURE__ */ new Date()).getTime();
|
|
817
|
+
this._fn(this._attempts);
|
|
818
|
+
};
|
|
819
|
+
RetryOperation.prototype.try = function(fn) {
|
|
820
|
+
console.log("Using RetryOperation.try() is deprecated");
|
|
821
|
+
this.attempt(fn);
|
|
822
|
+
};
|
|
823
|
+
RetryOperation.prototype.start = function(fn) {
|
|
824
|
+
console.log("Using RetryOperation.start() is deprecated");
|
|
825
|
+
this.attempt(fn);
|
|
826
|
+
};
|
|
827
|
+
RetryOperation.prototype.start = RetryOperation.prototype.try;
|
|
828
|
+
RetryOperation.prototype.errors = function() {
|
|
829
|
+
return this._errors;
|
|
830
|
+
};
|
|
831
|
+
RetryOperation.prototype.attempts = function() {
|
|
832
|
+
return this._attempts;
|
|
833
|
+
};
|
|
834
|
+
RetryOperation.prototype.mainError = function() {
|
|
835
|
+
if (this._errors.length === 0) {
|
|
836
|
+
return null;
|
|
837
|
+
}
|
|
838
|
+
var counts = {};
|
|
839
|
+
var mainError = null;
|
|
840
|
+
var mainErrorCount = 0;
|
|
841
|
+
for (var i = 0; i < this._errors.length; i++) {
|
|
842
|
+
var error = this._errors[i];
|
|
843
|
+
var message = error.message;
|
|
844
|
+
var count = (counts[message] || 0) + 1;
|
|
845
|
+
counts[message] = count;
|
|
846
|
+
if (count >= mainErrorCount) {
|
|
847
|
+
mainError = error;
|
|
848
|
+
mainErrorCount = count;
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
return mainError;
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
});
|
|
855
|
+
var require_retry = __commonJS2({
|
|
856
|
+
"../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js"(exports2) {
|
|
857
|
+
"use strict";
|
|
858
|
+
var RetryOperation = require_retry_operation();
|
|
859
|
+
exports2.operation = function(options) {
|
|
860
|
+
var timeouts = exports2.timeouts(options);
|
|
861
|
+
return new RetryOperation(timeouts, {
|
|
862
|
+
forever: options && (options.forever || options.retries === Infinity),
|
|
863
|
+
unref: options && options.unref,
|
|
864
|
+
maxRetryTime: options && options.maxRetryTime
|
|
865
|
+
});
|
|
866
|
+
};
|
|
867
|
+
exports2.timeouts = function(options) {
|
|
868
|
+
if (options instanceof Array) {
|
|
869
|
+
return [].concat(options);
|
|
870
|
+
}
|
|
871
|
+
var opts = {
|
|
872
|
+
retries: 10,
|
|
873
|
+
factor: 2,
|
|
874
|
+
minTimeout: 1 * 1e3,
|
|
875
|
+
maxTimeout: Infinity,
|
|
876
|
+
randomize: false
|
|
877
|
+
};
|
|
878
|
+
for (var key in options) {
|
|
879
|
+
opts[key] = options[key];
|
|
880
|
+
}
|
|
881
|
+
if (opts.minTimeout > opts.maxTimeout) {
|
|
882
|
+
throw new Error("minTimeout is greater than maxTimeout");
|
|
883
|
+
}
|
|
884
|
+
var timeouts = [];
|
|
885
|
+
for (var i = 0; i < opts.retries; i++) {
|
|
886
|
+
timeouts.push(this.createTimeout(i, opts));
|
|
887
|
+
}
|
|
888
|
+
if (options && options.forever && !timeouts.length) {
|
|
889
|
+
timeouts.push(this.createTimeout(i, opts));
|
|
890
|
+
}
|
|
891
|
+
timeouts.sort(function(a, b) {
|
|
892
|
+
return a - b;
|
|
893
|
+
});
|
|
894
|
+
return timeouts;
|
|
895
|
+
};
|
|
896
|
+
exports2.createTimeout = function(attempt, opts) {
|
|
897
|
+
var random = opts.randomize ? Math.random() + 1 : 1;
|
|
898
|
+
var timeout = Math.round(random * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt));
|
|
899
|
+
timeout = Math.min(timeout, opts.maxTimeout);
|
|
900
|
+
return timeout;
|
|
901
|
+
};
|
|
902
|
+
exports2.wrap = function(obj, options, methods) {
|
|
903
|
+
if (options instanceof Array) {
|
|
904
|
+
methods = options;
|
|
905
|
+
options = null;
|
|
906
|
+
}
|
|
907
|
+
if (!methods) {
|
|
908
|
+
methods = [];
|
|
909
|
+
for (var key in obj) {
|
|
910
|
+
if (typeof obj[key] === "function") {
|
|
911
|
+
methods.push(key);
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
for (var i = 0; i < methods.length; i++) {
|
|
916
|
+
var method = methods[i];
|
|
917
|
+
var original = obj[method];
|
|
918
|
+
obj[method] = function retryWrapper(original2) {
|
|
919
|
+
var op = exports2.operation(options);
|
|
920
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
|
921
|
+
var callback = args.pop();
|
|
922
|
+
args.push(function(err) {
|
|
923
|
+
if (op.retry(err)) {
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
if (err) {
|
|
927
|
+
arguments[0] = op.mainError();
|
|
928
|
+
}
|
|
929
|
+
callback.apply(this, arguments);
|
|
930
|
+
});
|
|
931
|
+
op.attempt(function() {
|
|
932
|
+
original2.apply(obj, args);
|
|
933
|
+
});
|
|
934
|
+
}.bind(obj, original);
|
|
935
|
+
obj[method].options = options;
|
|
936
|
+
}
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
});
|
|
940
|
+
var require_retry2 = __commonJS2({
|
|
941
|
+
"../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js"(exports2, module2) {
|
|
942
|
+
"use strict";
|
|
943
|
+
module2.exports = require_retry();
|
|
944
|
+
}
|
|
945
|
+
});
|
|
946
|
+
var import_p_limit2 = __toESM2(require_p_limit2());
|
|
947
|
+
var import_retry = __toESM2(require_retry2(), 1);
|
|
948
|
+
var networkErrorMsgs = /* @__PURE__ */ new Set([
|
|
949
|
+
"Failed to fetch",
|
|
950
|
+
// Chrome
|
|
951
|
+
"NetworkError when attempting to fetch resource.",
|
|
952
|
+
// Firefox
|
|
953
|
+
"The Internet connection appears to be offline.",
|
|
954
|
+
// Safari
|
|
955
|
+
"Network request failed",
|
|
956
|
+
// `cross-fetch`
|
|
957
|
+
"fetch failed"
|
|
958
|
+
// Undici (Node.js)
|
|
959
|
+
]);
|
|
960
|
+
var AbortError = class extends Error {
|
|
961
|
+
constructor(message) {
|
|
962
|
+
super();
|
|
963
|
+
if (message instanceof Error) {
|
|
964
|
+
this.originalError = message;
|
|
965
|
+
({ message } = message);
|
|
966
|
+
} else {
|
|
967
|
+
this.originalError = new Error(message);
|
|
968
|
+
this.originalError.stack = this.stack;
|
|
969
|
+
}
|
|
970
|
+
this.name = "AbortError";
|
|
971
|
+
this.message = message;
|
|
972
|
+
}
|
|
973
|
+
};
|
|
974
|
+
var decorateErrorWithCounts = (error, attemptNumber, options) => {
|
|
975
|
+
const retriesLeft = options.retries - (attemptNumber - 1);
|
|
976
|
+
error.attemptNumber = attemptNumber;
|
|
977
|
+
error.retriesLeft = retriesLeft;
|
|
978
|
+
return error;
|
|
979
|
+
};
|
|
980
|
+
var isNetworkError = (errorMessage) => networkErrorMsgs.has(errorMessage);
|
|
981
|
+
var getDOMException = (errorMessage) => globalThis.DOMException === void 0 ? new Error(errorMessage) : new DOMException(errorMessage);
|
|
982
|
+
async function pRetry(input, options) {
|
|
983
|
+
return new Promise((resolve, reject) => {
|
|
984
|
+
options = {
|
|
985
|
+
onFailedAttempt() {
|
|
986
|
+
},
|
|
987
|
+
retries: 10,
|
|
988
|
+
...options
|
|
989
|
+
};
|
|
990
|
+
const operation = import_retry.default.operation(options);
|
|
991
|
+
operation.attempt(async (attemptNumber) => {
|
|
992
|
+
try {
|
|
993
|
+
resolve(await input(attemptNumber));
|
|
994
|
+
} catch (error) {
|
|
995
|
+
if (!(error instanceof Error)) {
|
|
996
|
+
reject(new TypeError(`Non-error was thrown: "${error}". You should only throw errors.`));
|
|
997
|
+
return;
|
|
998
|
+
}
|
|
999
|
+
if (error instanceof AbortError) {
|
|
1000
|
+
operation.stop();
|
|
1001
|
+
reject(error.originalError);
|
|
1002
|
+
} else if (error instanceof TypeError && !isNetworkError(error.message)) {
|
|
1003
|
+
operation.stop();
|
|
1004
|
+
reject(error);
|
|
1005
|
+
} else {
|
|
1006
|
+
decorateErrorWithCounts(error, attemptNumber, options);
|
|
1007
|
+
try {
|
|
1008
|
+
await options.onFailedAttempt(error);
|
|
1009
|
+
} catch (error2) {
|
|
1010
|
+
reject(error2);
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
if (!operation.retry(error)) {
|
|
1014
|
+
reject(operation.mainError());
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
});
|
|
1019
|
+
if (options.signal && !options.signal.aborted) {
|
|
1020
|
+
options.signal.addEventListener("abort", () => {
|
|
1021
|
+
operation.stop();
|
|
1022
|
+
const reason = options.signal.reason === void 0 ? getDOMException("The operation was aborted.") : options.signal.reason;
|
|
1023
|
+
reject(reason instanceof Error ? reason : getDOMException(reason));
|
|
1024
|
+
}, {
|
|
1025
|
+
once: true
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
var AbortError2 = class extends Error {
|
|
1031
|
+
constructor() {
|
|
1032
|
+
super("Throttled function aborted");
|
|
1033
|
+
this.name = "AbortError";
|
|
1034
|
+
}
|
|
1035
|
+
};
|
|
1036
|
+
function pThrottle({ limit, interval, strict }) {
|
|
1037
|
+
if (!Number.isFinite(limit)) {
|
|
1038
|
+
throw new TypeError("Expected `limit` to be a finite number");
|
|
1039
|
+
}
|
|
1040
|
+
if (!Number.isFinite(interval)) {
|
|
1041
|
+
throw new TypeError("Expected `interval` to be a finite number");
|
|
1042
|
+
}
|
|
1043
|
+
const queue = /* @__PURE__ */ new Map();
|
|
1044
|
+
let currentTick = 0;
|
|
1045
|
+
let activeCount = 0;
|
|
1046
|
+
function windowedDelay() {
|
|
1047
|
+
const now = Date.now();
|
|
1048
|
+
if (now - currentTick > interval) {
|
|
1049
|
+
activeCount = 1;
|
|
1050
|
+
currentTick = now;
|
|
1051
|
+
return 0;
|
|
1052
|
+
}
|
|
1053
|
+
if (activeCount < limit) {
|
|
1054
|
+
activeCount++;
|
|
1055
|
+
} else {
|
|
1056
|
+
currentTick += interval;
|
|
1057
|
+
activeCount = 1;
|
|
1058
|
+
}
|
|
1059
|
+
return currentTick - now;
|
|
1060
|
+
}
|
|
1061
|
+
const strictTicks = [];
|
|
1062
|
+
function strictDelay() {
|
|
1063
|
+
const now = Date.now();
|
|
1064
|
+
if (strictTicks.length < limit) {
|
|
1065
|
+
strictTicks.push(now);
|
|
1066
|
+
return 0;
|
|
1067
|
+
}
|
|
1068
|
+
const earliestTime = strictTicks.shift() + interval;
|
|
1069
|
+
if (now >= earliestTime) {
|
|
1070
|
+
strictTicks.push(now);
|
|
1071
|
+
return 0;
|
|
1072
|
+
}
|
|
1073
|
+
strictTicks.push(earliestTime);
|
|
1074
|
+
return earliestTime - now;
|
|
1075
|
+
}
|
|
1076
|
+
const getDelay = strict ? strictDelay : windowedDelay;
|
|
1077
|
+
return (function_) => {
|
|
1078
|
+
const throttled = function(...args) {
|
|
1079
|
+
if (!throttled.isEnabled) {
|
|
1080
|
+
return (async () => function_.apply(this, args))();
|
|
1081
|
+
}
|
|
1082
|
+
let timeout;
|
|
1083
|
+
return new Promise((resolve, reject) => {
|
|
1084
|
+
const execute = () => {
|
|
1085
|
+
resolve(function_.apply(this, args));
|
|
1086
|
+
queue.delete(timeout);
|
|
1087
|
+
};
|
|
1088
|
+
timeout = setTimeout(execute, getDelay());
|
|
1089
|
+
queue.set(timeout, reject);
|
|
1090
|
+
});
|
|
1091
|
+
};
|
|
1092
|
+
throttled.abort = () => {
|
|
1093
|
+
for (const timeout of queue.keys()) {
|
|
1094
|
+
clearTimeout(timeout);
|
|
1095
|
+
queue.get(timeout)(new AbortError2());
|
|
1096
|
+
}
|
|
1097
|
+
queue.clear();
|
|
1098
|
+
strictTicks.splice(0, strictTicks.length);
|
|
1099
|
+
};
|
|
1100
|
+
throttled.isEnabled = true;
|
|
1101
|
+
return throttled;
|
|
1102
|
+
};
|
|
1103
|
+
}
|
|
1104
|
+
function createLimitPolicy({
|
|
1105
|
+
throttle = { interval: 1e3, limit: 10 },
|
|
1106
|
+
retry: retry2 = { retries: 1, factor: 1.66 },
|
|
1107
|
+
limit = 10
|
|
1108
|
+
}) {
|
|
1109
|
+
const throttler = throttle ? pThrottle(throttle) : null;
|
|
1110
|
+
const limiter = limit ? (0, import_p_limit2.default)(limit) : null;
|
|
1111
|
+
return function limitPolicy(func) {
|
|
1112
|
+
let currentFunc = async () => await func();
|
|
1113
|
+
if (throttler) {
|
|
1114
|
+
const throttleFunc = currentFunc;
|
|
1115
|
+
currentFunc = throttler(throttleFunc);
|
|
1116
|
+
}
|
|
1117
|
+
if (limiter) {
|
|
1118
|
+
const limitFunc = currentFunc;
|
|
1119
|
+
currentFunc = () => limiter(limitFunc);
|
|
1120
|
+
}
|
|
1121
|
+
if (retry2) {
|
|
1122
|
+
const retryFunc = currentFunc;
|
|
1123
|
+
currentFunc = () => pRetry(retryFunc, {
|
|
1124
|
+
...retry2,
|
|
1125
|
+
onFailedAttempt: async (error) => {
|
|
1126
|
+
if (retry2.onFailedAttempt) {
|
|
1127
|
+
await retry2.onFailedAttempt(error);
|
|
1128
|
+
}
|
|
1129
|
+
if (error instanceof ApiClientError && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
|
|
1130
|
+
throw error;
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
});
|
|
1134
|
+
}
|
|
1135
|
+
return currentFunc();
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1138
|
+
var isPlainObject = (obj) => typeof obj === "object" && obj !== null && !Array.isArray(obj);
|
|
1139
|
+
function rewriteFilters(filters) {
|
|
1140
|
+
return Object.entries(filters != null ? filters : {}).reduce(
|
|
1141
|
+
(acc, [key, value]) => {
|
|
1142
|
+
const lhs = `filters.${key}` + (isPlainObject(value) ? `[${Object.keys(value)[0]}]` : "");
|
|
1143
|
+
const rhs = isPlainObject(value) ? Object.values(value)[0] : value;
|
|
1144
|
+
return {
|
|
1145
|
+
...acc,
|
|
1146
|
+
[lhs]: Array.isArray(rhs) ? rhs.map((v) => `${v}`.trim()).join(",") : `${rhs}`.trim()
|
|
1147
|
+
};
|
|
1148
|
+
},
|
|
1149
|
+
{}
|
|
1150
|
+
);
|
|
1151
|
+
}
|
|
1152
|
+
var CANVAS_URL = "/api/v1/canvas";
|
|
1153
|
+
var CanvasClient = class extends ApiClient {
|
|
1154
|
+
constructor(options) {
|
|
1155
|
+
var _a;
|
|
1156
|
+
if (!options.limitPolicy) {
|
|
1157
|
+
options.limitPolicy = createLimitPolicy({});
|
|
1158
|
+
}
|
|
1159
|
+
super(options);
|
|
1160
|
+
this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
|
|
1161
|
+
this.edgeApiRequestInit = options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0;
|
|
1162
|
+
}
|
|
1163
|
+
/** Fetches lists of Canvas compositions, optionally by type */
|
|
1164
|
+
async getCompositionList(params = {}) {
|
|
1165
|
+
const { projectId } = this.options;
|
|
1166
|
+
const { resolveData, filters, ...originParams } = params;
|
|
1167
|
+
const rewrittenFilters = rewriteFilters(filters);
|
|
1168
|
+
if (!resolveData) {
|
|
1169
|
+
const fetchUri = this.createUrl(CANVAS_URL, { ...originParams, projectId, ...rewrittenFilters });
|
|
1170
|
+
return this.apiClient(fetchUri);
|
|
1171
|
+
}
|
|
1172
|
+
const edgeParams = {
|
|
1173
|
+
...originParams,
|
|
1174
|
+
projectId,
|
|
1175
|
+
diagnostics: typeof params.diagnostics === "boolean" ? params.diagnostics : params.diagnostics === "no-data" ? "no-data" : void 0,
|
|
1176
|
+
...rewrittenFilters
|
|
1177
|
+
};
|
|
1178
|
+
const edgeUrl = this.createUrl("/api/v1/compositions", edgeParams, this.edgeApiHost);
|
|
1179
|
+
return this.apiClient(edgeUrl, this.edgeApiRequestInit);
|
|
1180
|
+
}
|
|
1181
|
+
getCompositionByNodePath(options) {
|
|
1182
|
+
return this.getOneComposition(options);
|
|
1183
|
+
}
|
|
1184
|
+
getCompositionByNodeId(options) {
|
|
1185
|
+
return this.getOneComposition(options);
|
|
1186
|
+
}
|
|
1187
|
+
getCompositionBySlug(options) {
|
|
1188
|
+
return this.getOneComposition(options);
|
|
1189
|
+
}
|
|
1190
|
+
getCompositionById(options) {
|
|
1191
|
+
return this.getOneComposition(options);
|
|
1192
|
+
}
|
|
1193
|
+
getCompositionDefaults(options) {
|
|
1194
|
+
return this.getOneComposition(options);
|
|
1195
|
+
}
|
|
1196
|
+
/** Fetches historical versions of a composition or pattern */
|
|
1197
|
+
async getCompositionHistory(options) {
|
|
1198
|
+
const historyUrl = this.createUrl("/api/v1/canvas-history", {
|
|
1199
|
+
...options,
|
|
1200
|
+
projectId: this.options.projectId
|
|
1201
|
+
});
|
|
1202
|
+
return this.apiClient(historyUrl);
|
|
1203
|
+
}
|
|
1204
|
+
getOneComposition({
|
|
1205
|
+
skipDataResolution,
|
|
1206
|
+
diagnostics,
|
|
1207
|
+
...params
|
|
1208
|
+
}) {
|
|
1209
|
+
const { projectId } = this.options;
|
|
1210
|
+
if (skipDataResolution) {
|
|
1211
|
+
return this.apiClient(this.createUrl(CANVAS_URL, { ...params, projectId }));
|
|
1212
|
+
}
|
|
1213
|
+
const edgeParams = {
|
|
1214
|
+
...params,
|
|
1215
|
+
projectId,
|
|
1216
|
+
diagnostics: typeof diagnostics === "boolean" ? diagnostics : diagnostics === "no-data" ? "no-data" : void 0
|
|
1217
|
+
};
|
|
1218
|
+
const edgeUrl = this.createUrl("/api/v1/composition", edgeParams, this.edgeApiHost);
|
|
1219
|
+
return this.apiClient(edgeUrl, this.edgeApiRequestInit);
|
|
1220
|
+
}
|
|
1221
|
+
/** Updates or creates a Canvas component definition */
|
|
1222
|
+
async updateComposition(body, options) {
|
|
1223
|
+
const fetchUri = this.createUrl(CANVAS_URL);
|
|
1224
|
+
const headers = {};
|
|
1225
|
+
if (options == null ? void 0 : options.ifUnmodifiedSince) {
|
|
1226
|
+
headers["x-if-unmodified-since"] = options.ifUnmodifiedSince;
|
|
1227
|
+
}
|
|
1228
|
+
const { response } = await this.apiClientWithResponse(fetchUri, {
|
|
1229
|
+
method: "PUT",
|
|
1230
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1231
|
+
expectNoContent: true,
|
|
1232
|
+
headers
|
|
1233
|
+
});
|
|
1234
|
+
return { modified: response.headers.get("x-modified-at") };
|
|
1235
|
+
}
|
|
1236
|
+
/** Deletes a Canvas component definition */
|
|
1237
|
+
async removeComposition(body) {
|
|
1238
|
+
const fetchUri = this.createUrl(CANVAS_URL);
|
|
1239
|
+
const { projectId } = this.options;
|
|
1240
|
+
await this.apiClient(fetchUri, {
|
|
1241
|
+
method: "DELETE",
|
|
1242
|
+
body: JSON.stringify({ ...body, projectId }),
|
|
1243
|
+
expectNoContent: true
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1246
|
+
/** Fetches all Canvas component definitions */
|
|
1247
|
+
async getComponentDefinitions(options) {
|
|
1248
|
+
const { projectId } = this.options;
|
|
1249
|
+
const fetchUri = this.createUrl("/api/v1/canvas-definitions", { ...options, projectId });
|
|
1250
|
+
return this.apiClient(fetchUri);
|
|
1251
|
+
}
|
|
1252
|
+
/** Updates or creates a Canvas component definition */
|
|
1253
|
+
async updateComponentDefinition(body) {
|
|
1254
|
+
const fetchUri = this.createUrl("/api/v1/canvas-definitions");
|
|
1255
|
+
await this.apiClient(fetchUri, {
|
|
1256
|
+
method: "PUT",
|
|
1257
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1258
|
+
expectNoContent: true
|
|
1259
|
+
});
|
|
1260
|
+
}
|
|
1261
|
+
/** Deletes a Canvas component definition */
|
|
1262
|
+
async removeComponentDefinition(body) {
|
|
1263
|
+
const fetchUri = this.createUrl("/api/v1/canvas-definitions");
|
|
1264
|
+
await this.apiClient(fetchUri, {
|
|
1265
|
+
method: "DELETE",
|
|
1266
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1267
|
+
expectNoContent: true
|
|
1268
|
+
});
|
|
1269
|
+
}
|
|
1270
|
+
};
|
|
1271
|
+
var _contentTypesUrl;
|
|
1272
|
+
var _entriesUrl;
|
|
1273
|
+
var _ContentClient = class _ContentClient2 extends ApiClient {
|
|
1274
|
+
constructor(options) {
|
|
1275
|
+
var _a;
|
|
1276
|
+
super(options);
|
|
1277
|
+
this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
|
|
1278
|
+
}
|
|
1279
|
+
getContentTypes(options) {
|
|
1280
|
+
const { projectId } = this.options;
|
|
1281
|
+
const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _contentTypesUrl), { ...options, projectId });
|
|
1282
|
+
return this.apiClient(fetchUri);
|
|
1283
|
+
}
|
|
1284
|
+
getEntries(options) {
|
|
1285
|
+
const { projectId } = this.options;
|
|
1286
|
+
const { skipDataResolution, filters, ...params } = options;
|
|
1287
|
+
const rewrittenFilters = rewriteFilters(filters);
|
|
1288
|
+
if (skipDataResolution) {
|
|
1289
|
+
const url = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl), { ...params, ...rewrittenFilters, projectId });
|
|
1290
|
+
return this.apiClient(url);
|
|
1291
|
+
}
|
|
1292
|
+
const edgeUrl = this.createUrl(
|
|
1293
|
+
__privateGet2(_ContentClient2, _entriesUrl),
|
|
1294
|
+
{ ...this.getEdgeOptions(params), ...rewrittenFilters },
|
|
1295
|
+
this.edgeApiHost
|
|
1296
|
+
);
|
|
1297
|
+
return this.apiClient(
|
|
1298
|
+
edgeUrl,
|
|
1299
|
+
this.options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0
|
|
1300
|
+
);
|
|
1301
|
+
}
|
|
1302
|
+
/** Fetches historical versions of an entry */
|
|
1303
|
+
async getEntryHistory(options) {
|
|
1304
|
+
const historyUrl = this.createUrl("/api/v1/entries-history", {
|
|
1305
|
+
...options,
|
|
1306
|
+
projectId: this.options.projectId
|
|
1307
|
+
});
|
|
1308
|
+
return this.apiClient(historyUrl);
|
|
1309
|
+
}
|
|
1310
|
+
async upsertContentType(body, opts = {}) {
|
|
1311
|
+
const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _contentTypesUrl));
|
|
1312
|
+
if (typeof body.contentType.slugSettings === "object" && body.contentType.slugSettings !== null && Object.keys(body.contentType.slugSettings).length === 0) {
|
|
1313
|
+
delete body.contentType.slugSettings;
|
|
1314
|
+
}
|
|
1315
|
+
await this.apiClient(fetchUri, {
|
|
1316
|
+
method: "PUT",
|
|
1317
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1318
|
+
expectNoContent: true,
|
|
1319
|
+
headers: opts.autogenerateDataTypes ? { "x-uniform-autogenerate-data-types": "true" } : {}
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
async upsertEntry(body, options) {
|
|
1323
|
+
const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl));
|
|
1324
|
+
const headers = {};
|
|
1325
|
+
if (options == null ? void 0 : options.ifUnmodifiedSince) {
|
|
1326
|
+
headers["x-if-unmodified-since"] = options.ifUnmodifiedSince;
|
|
1327
|
+
}
|
|
1328
|
+
const { response } = await this.apiClientWithResponse(fetchUri, {
|
|
1329
|
+
method: "PUT",
|
|
1330
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1331
|
+
expectNoContent: true,
|
|
1332
|
+
headers
|
|
1333
|
+
});
|
|
1334
|
+
return { modified: response.headers.get("x-modified-at") };
|
|
1335
|
+
}
|
|
1336
|
+
async deleteContentType(body) {
|
|
1337
|
+
const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _contentTypesUrl));
|
|
1338
|
+
await this.apiClient(fetchUri, {
|
|
1339
|
+
method: "DELETE",
|
|
1340
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1341
|
+
expectNoContent: true
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1344
|
+
async deleteEntry(body) {
|
|
1345
|
+
const fetchUri = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl));
|
|
1346
|
+
await this.apiClient(fetchUri, {
|
|
1347
|
+
method: "DELETE",
|
|
1348
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1349
|
+
expectNoContent: true
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
getEdgeOptions(options) {
|
|
1353
|
+
const { projectId } = this.options;
|
|
1354
|
+
const { skipDataResolution, ...params } = options;
|
|
1355
|
+
return {
|
|
1356
|
+
projectId,
|
|
1357
|
+
...params,
|
|
1358
|
+
diagnostics: typeof options.diagnostics === "boolean" ? options.diagnostics : options.diagnostics === "no-data" ? "no-data" : void 0
|
|
1359
|
+
};
|
|
1360
|
+
}
|
|
1361
|
+
};
|
|
1362
|
+
_contentTypesUrl = /* @__PURE__ */ new WeakMap();
|
|
1363
|
+
_entriesUrl = /* @__PURE__ */ new WeakMap();
|
|
1364
|
+
__privateAdd2(_ContentClient, _contentTypesUrl, "/api/v1/content-types");
|
|
1365
|
+
__privateAdd2(_ContentClient, _entriesUrl, "/api/v1/entries");
|
|
1366
|
+
var _url8;
|
|
1367
|
+
var _DataTypeClient = class _DataTypeClient2 extends ApiClient {
|
|
1368
|
+
constructor(options) {
|
|
1369
|
+
super(options);
|
|
1370
|
+
}
|
|
1371
|
+
/** Fetches all DataTypes for a project */
|
|
1372
|
+
async get(options) {
|
|
1373
|
+
const { projectId } = this.options;
|
|
1374
|
+
const fetchUri = this.createUrl(__privateGet2(_DataTypeClient2, _url8), { ...options, projectId });
|
|
1375
|
+
return await this.apiClient(fetchUri);
|
|
1376
|
+
}
|
|
1377
|
+
/** Updates or creates (based on id) a DataType */
|
|
1378
|
+
async upsert(body) {
|
|
1379
|
+
const fetchUri = this.createUrl(__privateGet2(_DataTypeClient2, _url8));
|
|
1380
|
+
await this.apiClient(fetchUri, {
|
|
1381
|
+
method: "PUT",
|
|
1382
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1383
|
+
expectNoContent: true
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
/** Deletes a DataType */
|
|
1387
|
+
async remove(body) {
|
|
1388
|
+
const fetchUri = this.createUrl(__privateGet2(_DataTypeClient2, _url8));
|
|
1389
|
+
await this.apiClient(fetchUri, {
|
|
1390
|
+
method: "DELETE",
|
|
1391
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1392
|
+
expectNoContent: true
|
|
1393
|
+
});
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
_url8 = /* @__PURE__ */ new WeakMap();
|
|
1397
|
+
__privateAdd2(_DataTypeClient, _url8, "/api/v1/data-types");
|
|
1398
|
+
function getComponentPath(ancestorsAndSelf) {
|
|
1399
|
+
const path = [];
|
|
1400
|
+
for (let i = ancestorsAndSelf.length - 1; i >= 0; i--) {
|
|
1401
|
+
const currentLocation = ancestorsAndSelf[i];
|
|
1402
|
+
const parentLocation = ancestorsAndSelf[i + 1];
|
|
1403
|
+
if ("type" in currentLocation && currentLocation.type !== "slot") {
|
|
1404
|
+
if (currentLocation.type === "block") {
|
|
1405
|
+
const { fieldName, blockIndexFn } = currentLocation;
|
|
1406
|
+
const blockIndex = blockIndexFn();
|
|
1407
|
+
if (fieldName && blockIndex !== void 0) {
|
|
1408
|
+
const noun = parentLocation && "type" in parentLocation && parentLocation.type === "block" ? "fields" : "parameters";
|
|
1409
|
+
path.push(`${noun}.${fieldName}.value[${blockIndex}]`);
|
|
1410
|
+
}
|
|
1411
|
+
} else {
|
|
1412
|
+
}
|
|
1413
|
+
continue;
|
|
1414
|
+
}
|
|
1415
|
+
const parentSlotIndex = currentLocation.parentSlotIndexFn();
|
|
1416
|
+
const { parentSlot } = currentLocation;
|
|
1417
|
+
if (parentSlot && parentSlotIndex !== void 0) {
|
|
1418
|
+
path.push(`${parentSlot}[${parentSlotIndex}]`);
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
return `.${path.join(".")}`;
|
|
1422
|
+
}
|
|
1423
|
+
var CANVAS_PERSONALIZE_TYPE = "$personalization";
|
|
1424
|
+
var CANVAS_TEST_TYPE = "$test";
|
|
1425
|
+
var CANVAS_BLOCK_PARAM_TYPE = "$block";
|
|
1426
|
+
var CANVAS_PERSONALIZE_SLOT = "pz";
|
|
1427
|
+
var CANVAS_TEST_SLOT = "test";
|
|
1428
|
+
var CANVAS_DRAFT_STATE = 0;
|
|
1429
|
+
var CANVAS_PUBLISHED_STATE = 64;
|
|
1430
|
+
var CANVAS_EDITOR_STATE = 63;
|
|
1431
|
+
var CANVAS_PERSONALIZATION_PARAM = "$pzCrit";
|
|
1432
|
+
var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
|
|
1433
|
+
var CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
|
|
1434
|
+
var CANVAS_CONTEXTUAL_EDITING_PARAM = "$contextualEditing";
|
|
1435
|
+
var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
|
|
1436
|
+
var PLACEHOLDER_ID = "placeholder";
|
|
1437
|
+
var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
|
|
1438
|
+
function isRootEntryReference(root) {
|
|
1439
|
+
return root.type === "root" && isEntryData(root.node);
|
|
1440
|
+
}
|
|
1441
|
+
function isEntryData(entryData) {
|
|
1442
|
+
return Boolean(entryData && typeof entryData === "object" && "fields" in entryData);
|
|
1443
|
+
}
|
|
1444
|
+
function getPropertiesValue(entity) {
|
|
1445
|
+
return "parameters" in entity && entity.parameters ? entity.parameters : "fields" in entity && entity.fields ? entity.fields : void 0;
|
|
1446
|
+
}
|
|
1447
|
+
var escapeCharacter = "\\";
|
|
1448
|
+
var variablePrefix = "${";
|
|
1449
|
+
var variableSuffix = "}";
|
|
1450
|
+
function parseVariableExpression(serialized, onToken) {
|
|
1451
|
+
if (typeof serialized !== "string") {
|
|
1452
|
+
throw new TypeError("Variable expression must be a string");
|
|
1453
|
+
}
|
|
1454
|
+
let bufferStartIndex = 0;
|
|
1455
|
+
let bufferEndIndex = 0;
|
|
1456
|
+
let tokenCount = 0;
|
|
1457
|
+
const handleToken = (token, type) => {
|
|
1458
|
+
tokenCount++;
|
|
1459
|
+
return onToken == null ? void 0 : onToken(token, type);
|
|
1460
|
+
};
|
|
1461
|
+
let state = "text";
|
|
1462
|
+
for (let index = 0; index < serialized.length; index++) {
|
|
1463
|
+
const char = serialized[index];
|
|
1464
|
+
if (bufferStartIndex > bufferEndIndex) {
|
|
1465
|
+
bufferEndIndex = bufferStartIndex;
|
|
1466
|
+
}
|
|
1467
|
+
if (char === variablePrefix[0] && serialized[index + 1] === variablePrefix[1]) {
|
|
1468
|
+
if (serialized[index - 1] === escapeCharacter) {
|
|
1469
|
+
bufferEndIndex -= escapeCharacter.length;
|
|
1470
|
+
if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text") === false) {
|
|
1471
|
+
return tokenCount;
|
|
1472
|
+
}
|
|
1473
|
+
bufferStartIndex = index;
|
|
1474
|
+
bufferEndIndex = index + 1;
|
|
1475
|
+
continue;
|
|
1476
|
+
}
|
|
1477
|
+
state = "variable";
|
|
1478
|
+
if (bufferEndIndex > bufferStartIndex) {
|
|
1479
|
+
if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text") === false) {
|
|
1480
|
+
return tokenCount;
|
|
1481
|
+
}
|
|
1482
|
+
bufferStartIndex = bufferEndIndex;
|
|
1483
|
+
}
|
|
1484
|
+
index += variablePrefix.length - 1;
|
|
1485
|
+
bufferStartIndex += variablePrefix.length;
|
|
1486
|
+
continue;
|
|
1487
|
+
}
|
|
1488
|
+
if (char === variableSuffix && state === "variable") {
|
|
1489
|
+
if (serialized[index - 1] === escapeCharacter) {
|
|
1490
|
+
bufferEndIndex++;
|
|
1491
|
+
continue;
|
|
1492
|
+
}
|
|
1493
|
+
state = "text";
|
|
1494
|
+
if (bufferEndIndex > bufferStartIndex) {
|
|
1495
|
+
const unescapedVariableName = serialized.substring(bufferStartIndex, bufferEndIndex).replace(/\\([${}])/g, "$1");
|
|
1496
|
+
if (handleToken(unescapedVariableName, "variable") === false) {
|
|
1497
|
+
return tokenCount;
|
|
1498
|
+
}
|
|
1499
|
+
bufferStartIndex = bufferEndIndex + variableSuffix.length;
|
|
1500
|
+
}
|
|
1501
|
+
continue;
|
|
1502
|
+
}
|
|
1503
|
+
bufferEndIndex++;
|
|
1504
|
+
}
|
|
1505
|
+
if (bufferEndIndex > bufferStartIndex) {
|
|
1506
|
+
if (state === "variable") {
|
|
1507
|
+
state = "text";
|
|
1508
|
+
bufferStartIndex -= variablePrefix.length;
|
|
1509
|
+
}
|
|
1510
|
+
handleToken(serialized.substring(bufferStartIndex), state);
|
|
1511
|
+
}
|
|
1512
|
+
return tokenCount;
|
|
1513
|
+
}
|
|
1514
|
+
function hasReferencedVariables(value) {
|
|
1515
|
+
if (value === void 0) {
|
|
1516
|
+
return 0;
|
|
1517
|
+
}
|
|
1518
|
+
let variableTokenCount = 0;
|
|
1519
|
+
parseVariableExpression(value, (_, tokenType) => {
|
|
1520
|
+
if (tokenType === "variable") {
|
|
1521
|
+
variableTokenCount++;
|
|
1522
|
+
}
|
|
1523
|
+
});
|
|
1524
|
+
return variableTokenCount;
|
|
1525
|
+
}
|
|
1526
|
+
function walkNodeTree(node, visitor, options) {
|
|
1527
|
+
var _a, _b;
|
|
1528
|
+
const componentQueue = [
|
|
1529
|
+
{
|
|
1530
|
+
ancestorsAndSelf: Array.isArray(node) ? node : [{ node, type: "root" }],
|
|
1531
|
+
context: options == null ? void 0 : options.initialContext
|
|
1532
|
+
}
|
|
1533
|
+
];
|
|
1534
|
+
const childContexts = /* @__PURE__ */ new Map();
|
|
1535
|
+
do {
|
|
1536
|
+
const currentQueueEntry = componentQueue.pop();
|
|
1537
|
+
if (!currentQueueEntry) continue;
|
|
1538
|
+
const currentComponent = currentQueueEntry.ancestorsAndSelf[0];
|
|
1539
|
+
let visitDescendants = true;
|
|
1540
|
+
let descendantContext = (_a = childContexts.get(currentComponent.node)) != null ? _a : currentQueueEntry.context;
|
|
1541
|
+
let visitorInfo;
|
|
1542
|
+
if (currentComponent.type === "root" && isRootEntryReference(currentComponent) || currentComponent.type === "block") {
|
|
1543
|
+
visitorInfo = {
|
|
1544
|
+
type: "entry",
|
|
1545
|
+
node: currentComponent.node,
|
|
1546
|
+
ancestorsAndSelf: currentQueueEntry.ancestorsAndSelf,
|
|
1547
|
+
actions: {
|
|
1548
|
+
replace: (replacementNode) => {
|
|
1549
|
+
Object.assign(currentComponent.node, replacementNode);
|
|
1550
|
+
const propertiesToCheck = ["fields", "_dataResources", "_author"];
|
|
1551
|
+
propertiesToCheck.forEach((property) => {
|
|
1552
|
+
if (!replacementNode[property]) {
|
|
1553
|
+
delete currentComponent.node[property];
|
|
1554
|
+
}
|
|
1555
|
+
});
|
|
1556
|
+
},
|
|
1557
|
+
remove: () => {
|
|
1558
|
+
const currentComponentLocation = currentQueueEntry.ancestorsAndSelf[0];
|
|
1559
|
+
const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
|
|
1560
|
+
if (currentComponentLocation.type === "block") {
|
|
1561
|
+
const { fieldName, blockIndexFn } = currentComponentLocation;
|
|
1562
|
+
const blockIndex = blockIndexFn();
|
|
1563
|
+
const blockValue = getBlockValue(parentComponent.node, fieldName);
|
|
1564
|
+
blockValue.splice(blockIndex, 1);
|
|
1565
|
+
if (blockValue.length === 0) {
|
|
1566
|
+
const properties2 = getPropertiesValue(parentComponent.node);
|
|
1567
|
+
delete properties2[fieldName];
|
|
1568
|
+
}
|
|
1569
|
+
} else {
|
|
1570
|
+
throw new Error("Unknown node type");
|
|
1571
|
+
}
|
|
1572
|
+
visitDescendants = false;
|
|
1573
|
+
},
|
|
1574
|
+
insertAfter: (nodes) => {
|
|
1575
|
+
const currentNodeInfo = currentQueueEntry.ancestorsAndSelf[0];
|
|
1576
|
+
if (currentNodeInfo.type !== "block") {
|
|
1577
|
+
throw new Error("Unknown type");
|
|
1578
|
+
}
|
|
1579
|
+
const { fieldName, blockIndexFn } = currentNodeInfo;
|
|
1580
|
+
const blockIndex = blockIndexFn();
|
|
1581
|
+
const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
|
|
1582
|
+
const nodesToInsert = Array.isArray(nodes) ? nodes : [nodes];
|
|
1583
|
+
if (fieldName && typeof blockIndex !== "undefined") {
|
|
1584
|
+
getPropertiesValue(parentComponent.node)[fieldName].value.splice(
|
|
1585
|
+
blockIndex + 1,
|
|
1586
|
+
0,
|
|
1587
|
+
...nodesToInsert
|
|
1588
|
+
);
|
|
1589
|
+
componentQueue.unshift(
|
|
1590
|
+
...nodesToInsert.map((enqueueingComponent) => {
|
|
1591
|
+
const blockIndexFn2 = () => {
|
|
1592
|
+
const parentArray = getPropertiesValue(parentComponent.node)[fieldName].value;
|
|
1593
|
+
return parentArray.findIndex((x) => x === enqueueingComponent);
|
|
1594
|
+
};
|
|
1595
|
+
return {
|
|
1596
|
+
ancestorsAndSelf: [
|
|
1597
|
+
{
|
|
1598
|
+
type: "block",
|
|
1599
|
+
node: enqueueingComponent,
|
|
1600
|
+
fieldName,
|
|
1601
|
+
blockIndexFn: blockIndexFn2
|
|
1602
|
+
},
|
|
1603
|
+
// slice removes 'self' since we are inserting a peer of self
|
|
1604
|
+
...currentQueueEntry.ancestorsAndSelf.slice(1)
|
|
1605
|
+
],
|
|
1606
|
+
context: descendantContext
|
|
1607
|
+
};
|
|
1608
|
+
})
|
|
1609
|
+
);
|
|
1610
|
+
}
|
|
1611
|
+
},
|
|
1612
|
+
stopProcessingDescendants() {
|
|
1613
|
+
visitDescendants = false;
|
|
1614
|
+
},
|
|
1615
|
+
setDescendantsContext(context) {
|
|
1616
|
+
descendantContext = context;
|
|
1617
|
+
},
|
|
1618
|
+
setChildContext(child, context) {
|
|
1619
|
+
childContexts.set(child, context);
|
|
1620
|
+
}
|
|
1621
|
+
},
|
|
1622
|
+
context: descendantContext
|
|
1623
|
+
};
|
|
1624
|
+
} else {
|
|
1625
|
+
visitorInfo = {
|
|
1626
|
+
type: "component",
|
|
1627
|
+
node: currentComponent.node,
|
|
1628
|
+
ancestorsAndSelf: currentQueueEntry.ancestorsAndSelf,
|
|
1629
|
+
actions: {
|
|
1630
|
+
replace: (replacementComponent) => {
|
|
1631
|
+
Object.assign(currentComponent.node, replacementComponent);
|
|
1632
|
+
const propertiesToCheck = [
|
|
1633
|
+
"parameters",
|
|
1634
|
+
"variant",
|
|
1635
|
+
"slots",
|
|
1636
|
+
"data",
|
|
1637
|
+
"_pattern",
|
|
1638
|
+
"_patternError",
|
|
1639
|
+
"_dataResources",
|
|
1640
|
+
"_overridability",
|
|
1641
|
+
"_overrides",
|
|
1642
|
+
"_patternDataResources"
|
|
1643
|
+
];
|
|
1644
|
+
propertiesToCheck.forEach((property) => {
|
|
1645
|
+
if (!replacementComponent[property]) {
|
|
1646
|
+
delete currentComponent.node[property];
|
|
1647
|
+
}
|
|
1648
|
+
});
|
|
1649
|
+
},
|
|
1650
|
+
remove: () => {
|
|
1651
|
+
const currentComponentLocation = currentQueueEntry.ancestorsAndSelf[0];
|
|
1652
|
+
const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
|
|
1653
|
+
if (currentComponentLocation.type === "root") {
|
|
1654
|
+
throw new Error("Unable to delete root node.");
|
|
1655
|
+
}
|
|
1656
|
+
if (currentComponentLocation.type === "slot") {
|
|
1657
|
+
const { parentSlot, parentSlotIndexFn } = currentComponentLocation;
|
|
1658
|
+
const parentSlotIndex = parentSlotIndexFn();
|
|
1659
|
+
parentComponent.node.slots[parentSlot].splice(parentSlotIndex, 1);
|
|
1660
|
+
} else {
|
|
1661
|
+
throw new Error("Unknown node type");
|
|
1662
|
+
}
|
|
1663
|
+
visitDescendants = false;
|
|
1664
|
+
},
|
|
1665
|
+
insertAfter: (nodes) => {
|
|
1666
|
+
const nodesToInsert = Array.isArray(nodes) ? nodes : [nodes];
|
|
1667
|
+
const currentNodeInfo = currentQueueEntry.ancestorsAndSelf[0];
|
|
1668
|
+
if (currentNodeInfo.type === "root") {
|
|
1669
|
+
throw new Error("Unable to insert after root node.");
|
|
1670
|
+
}
|
|
1671
|
+
if (currentNodeInfo.type === "slot") {
|
|
1672
|
+
const { parentSlot, parentSlotIndexFn } = currentNodeInfo;
|
|
1673
|
+
const parentSlotIndex = parentSlotIndexFn();
|
|
1674
|
+
const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
|
|
1675
|
+
if (parentSlot && typeof parentSlotIndex !== "undefined") {
|
|
1676
|
+
parentComponent.node.slots[parentSlot].splice(
|
|
1677
|
+
parentSlotIndex + 1,
|
|
1678
|
+
0,
|
|
1679
|
+
...nodesToInsert
|
|
1680
|
+
);
|
|
1681
|
+
componentQueue.unshift(
|
|
1682
|
+
...nodesToInsert.map((enqueueingComponent) => {
|
|
1683
|
+
const parentSlotIndexFn2 = () => {
|
|
1684
|
+
return parentComponent.node.slots[parentSlot].findIndex(
|
|
1685
|
+
(x) => x === enqueueingComponent
|
|
1686
|
+
);
|
|
1687
|
+
};
|
|
1688
|
+
return {
|
|
1689
|
+
type: "slot",
|
|
1690
|
+
ancestorsAndSelf: [
|
|
1691
|
+
{
|
|
1692
|
+
type: "slot",
|
|
1693
|
+
node: enqueueingComponent,
|
|
1694
|
+
parentSlot,
|
|
1695
|
+
parentSlotIndexFn: parentSlotIndexFn2
|
|
1696
|
+
},
|
|
1697
|
+
// slice removes 'self' since we are inserting a peer of self
|
|
1698
|
+
...currentQueueEntry.ancestorsAndSelf.slice(1)
|
|
1699
|
+
],
|
|
1700
|
+
context: descendantContext
|
|
1701
|
+
};
|
|
1702
|
+
})
|
|
1703
|
+
);
|
|
1704
|
+
}
|
|
1705
|
+
} else {
|
|
1706
|
+
throw new Error("Unknown type");
|
|
1707
|
+
}
|
|
1708
|
+
},
|
|
1709
|
+
stopProcessingDescendants() {
|
|
1710
|
+
visitDescendants = false;
|
|
1711
|
+
},
|
|
1712
|
+
setDescendantsContext(context) {
|
|
1713
|
+
descendantContext = context;
|
|
1714
|
+
},
|
|
1715
|
+
setChildContext(child, context) {
|
|
1716
|
+
childContexts.set(child, context);
|
|
1717
|
+
}
|
|
1718
|
+
},
|
|
1719
|
+
context: descendantContext
|
|
1720
|
+
};
|
|
1721
|
+
}
|
|
1722
|
+
visitor(visitorInfo);
|
|
1723
|
+
if (!visitDescendants) {
|
|
1724
|
+
continue;
|
|
1725
|
+
}
|
|
1726
|
+
const slots = "slots" in currentComponent.node && currentComponent.node.slots;
|
|
1727
|
+
if (slots) {
|
|
1728
|
+
const slotKeys = Object.keys(slots);
|
|
1729
|
+
for (let slotIndex = slotKeys.length - 1; slotIndex >= 0; slotIndex--) {
|
|
1730
|
+
const slotKey = slotKeys[slotIndex];
|
|
1731
|
+
const components = slots[slotKey];
|
|
1732
|
+
for (let componentIndex = components.length - 1; componentIndex >= 0; componentIndex--) {
|
|
1733
|
+
const enqueueingComponent = components[componentIndex];
|
|
1734
|
+
const parentSlotIndexFn = () => {
|
|
1735
|
+
const result = currentComponent.node.slots[slotKey].findIndex(
|
|
1736
|
+
(x) => x === enqueueingComponent
|
|
1737
|
+
);
|
|
1738
|
+
return result;
|
|
1739
|
+
};
|
|
1740
|
+
componentQueue.push({
|
|
1741
|
+
ancestorsAndSelf: [
|
|
1742
|
+
{
|
|
1743
|
+
type: "slot",
|
|
1744
|
+
node: enqueueingComponent,
|
|
1745
|
+
parentSlot: slotKey,
|
|
1746
|
+
parentSlotIndexFn
|
|
1747
|
+
},
|
|
1748
|
+
...currentQueueEntry.ancestorsAndSelf
|
|
1749
|
+
],
|
|
1750
|
+
context: descendantContext
|
|
1751
|
+
});
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
const properties = getPropertiesValue(currentComponent.node);
|
|
1756
|
+
if (properties) {
|
|
1757
|
+
const propertyEntries = Object.entries(properties);
|
|
1758
|
+
for (let propIndex = propertyEntries.length - 1; propIndex >= 0; propIndex--) {
|
|
1759
|
+
const [propKey, propObject] = propertyEntries[propIndex];
|
|
1760
|
+
if (!isNestedNodeType(propObject.type)) {
|
|
1761
|
+
continue;
|
|
1762
|
+
}
|
|
1763
|
+
if (typeof propObject.value === "string" && hasReferencedVariables(propObject.value) > 0) {
|
|
1764
|
+
continue;
|
|
1765
|
+
}
|
|
1766
|
+
if (!Array.isArray(propObject.value)) {
|
|
1767
|
+
const error = new BlockFormatError(
|
|
1768
|
+
`${getComponentPath(currentQueueEntry.ancestorsAndSelf)}`,
|
|
1769
|
+
propKey,
|
|
1770
|
+
propObject.value
|
|
1771
|
+
);
|
|
1772
|
+
if (options == null ? void 0 : options.throwForInvalidBlockValues) {
|
|
1773
|
+
throw error;
|
|
1774
|
+
} else {
|
|
1775
|
+
console.warn(`Skipped invalid block value: ${error.message}}`);
|
|
1776
|
+
continue;
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
const blocks = (_b = propObject.value) != null ? _b : [];
|
|
1780
|
+
for (let blockIndex = blocks.length - 1; blockIndex >= 0; blockIndex--) {
|
|
1781
|
+
const enqueueingBlock = blocks[blockIndex];
|
|
1782
|
+
const blockIndexFn = () => {
|
|
1783
|
+
return getBlockValue(currentComponent.node, propKey).findIndex((x) => x === enqueueingBlock);
|
|
1784
|
+
};
|
|
1785
|
+
componentQueue.push({
|
|
1786
|
+
ancestorsAndSelf: [
|
|
1787
|
+
{
|
|
1788
|
+
type: "block",
|
|
1789
|
+
node: enqueueingBlock,
|
|
1790
|
+
fieldName: propKey,
|
|
1791
|
+
blockIndexFn
|
|
1792
|
+
},
|
|
1793
|
+
...currentQueueEntry.ancestorsAndSelf
|
|
1794
|
+
],
|
|
1795
|
+
context: descendantContext
|
|
1796
|
+
});
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
} while (componentQueue.length > 0);
|
|
1801
|
+
}
|
|
1802
|
+
function isNestedNodeType(type) {
|
|
1803
|
+
return type === CANVAS_BLOCK_PARAM_TYPE;
|
|
1804
|
+
}
|
|
1805
|
+
function getBlockValue(component, parameterName) {
|
|
1806
|
+
var _a;
|
|
1807
|
+
const parameter = (_a = getPropertiesValue(component)) == null ? void 0 : _a[parameterName];
|
|
1808
|
+
if ((parameter == null ? void 0 : parameter.value) && parameter.type === CANVAS_BLOCK_PARAM_TYPE && Array.isArray(parameter.value)) {
|
|
1809
|
+
return parameter.value;
|
|
1810
|
+
}
|
|
1811
|
+
return [];
|
|
1812
|
+
}
|
|
1813
|
+
var BlockFormatError = class _BlockFormatError extends Error {
|
|
1814
|
+
constructor(componentPath, propertyId, blockValue) {
|
|
1815
|
+
super(
|
|
1816
|
+
`${componentPath} has an invalid block property value on ${propertyId}. Block values must be arrays of blocks (BlockValue type), but received ${blockValue === null ? "null" : typeof blockValue}`
|
|
1817
|
+
);
|
|
1818
|
+
this.componentPath = componentPath;
|
|
1819
|
+
this.propertyId = propertyId;
|
|
1820
|
+
this.blockValue = blockValue;
|
|
1821
|
+
Object.setPrototypeOf(this, _BlockFormatError.prototype);
|
|
1822
|
+
}
|
|
1823
|
+
};
|
|
1824
|
+
function createVariableReference(variableName) {
|
|
1825
|
+
return `\${${variableName.replace(/([${}])/g, "\\$1")}}`;
|
|
1826
|
+
}
|
|
1827
|
+
var CANVAS_VIZ_CONTROL_PARAM = "$viz";
|
|
1828
|
+
var _baseUrl;
|
|
1829
|
+
var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2 extends ApiClient {
|
|
1830
|
+
constructor(options) {
|
|
1831
|
+
super(options);
|
|
1832
|
+
this.teamId = options.teamId;
|
|
1833
|
+
}
|
|
1834
|
+
/**
|
|
1835
|
+
* Gets a list of property type and hook names for the current team, including public integrations' hooks.
|
|
1836
|
+
*/
|
|
1837
|
+
get(options) {
|
|
1838
|
+
const fetchUri = this.createUrl(__privateGet2(_IntegrationPropertyEditorsClient2, _baseUrl), {
|
|
1839
|
+
...options,
|
|
1840
|
+
teamId: this.teamId
|
|
1841
|
+
});
|
|
1842
|
+
return this.apiClient(fetchUri);
|
|
1843
|
+
}
|
|
1844
|
+
/**
|
|
1845
|
+
* Creates or updates a custom AI property editor on a Mesh app.
|
|
1846
|
+
*/
|
|
1847
|
+
async deploy(body) {
|
|
1848
|
+
const fetchUri = this.createUrl(__privateGet2(_IntegrationPropertyEditorsClient2, _baseUrl));
|
|
1849
|
+
await this.apiClient(fetchUri, {
|
|
1850
|
+
method: "PUT",
|
|
1851
|
+
body: JSON.stringify({ ...body, teamId: this.teamId }),
|
|
1852
|
+
expectNoContent: true
|
|
1853
|
+
});
|
|
1854
|
+
}
|
|
1855
|
+
/**
|
|
1856
|
+
* Removes a custom AI property editor from a Mesh app.
|
|
1857
|
+
*/
|
|
1858
|
+
async delete(body) {
|
|
1859
|
+
const fetchUri = this.createUrl(__privateGet2(_IntegrationPropertyEditorsClient2, _baseUrl));
|
|
1860
|
+
await this.apiClient(fetchUri, {
|
|
1861
|
+
method: "DELETE",
|
|
1862
|
+
body: JSON.stringify({ ...body, teamId: this.teamId }),
|
|
1863
|
+
expectNoContent: true
|
|
1864
|
+
});
|
|
1865
|
+
}
|
|
1866
|
+
};
|
|
1867
|
+
_baseUrl = /* @__PURE__ */ new WeakMap();
|
|
1868
|
+
__privateAdd2(_IntegrationPropertyEditorsClient, _baseUrl, "/api/v1/integration-property-editors");
|
|
1869
|
+
var _url22;
|
|
1870
|
+
var _ProjectClient = class _ProjectClient2 extends ApiClient {
|
|
1871
|
+
constructor(options) {
|
|
1872
|
+
super({ ...options, bypassCache: true });
|
|
1873
|
+
}
|
|
1874
|
+
/** Fetches single Project */
|
|
1875
|
+
async get(options) {
|
|
1876
|
+
const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _url22), { ...options });
|
|
1877
|
+
return await this.apiClient(fetchUri);
|
|
1878
|
+
}
|
|
1879
|
+
/** Updates or creates (based on id) a Project */
|
|
1880
|
+
async upsert(body) {
|
|
1881
|
+
const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _url22));
|
|
1882
|
+
return await this.apiClient(fetchUri, {
|
|
1883
|
+
method: "PUT",
|
|
1884
|
+
body: JSON.stringify({ ...body })
|
|
1885
|
+
});
|
|
1886
|
+
}
|
|
1887
|
+
/** Deletes a Project */
|
|
1888
|
+
async delete(body) {
|
|
1889
|
+
const fetchUri = this.createUrl(__privateGet2(_ProjectClient2, _url22));
|
|
1890
|
+
await this.apiClient(fetchUri, {
|
|
1891
|
+
method: "DELETE",
|
|
1892
|
+
body: JSON.stringify({ ...body }),
|
|
1893
|
+
expectNoContent: true
|
|
1894
|
+
});
|
|
1895
|
+
}
|
|
1896
|
+
};
|
|
1897
|
+
_url22 = /* @__PURE__ */ new WeakMap();
|
|
1898
|
+
__privateAdd2(_ProjectClient, _url22, "/api/v1/project");
|
|
1899
|
+
var ROUTE_URL = "/api/v1/route";
|
|
1900
|
+
var RouteClient = class extends ApiClient {
|
|
1901
|
+
constructor(options) {
|
|
1902
|
+
var _a;
|
|
1903
|
+
if (!options.limitPolicy) {
|
|
1904
|
+
options.limitPolicy = createLimitPolicy({});
|
|
1905
|
+
}
|
|
1906
|
+
super(options);
|
|
1907
|
+
this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
|
|
1908
|
+
}
|
|
1909
|
+
/** Fetches lists of Canvas compositions, optionally by type */
|
|
1910
|
+
async getRoute(options) {
|
|
1911
|
+
const { projectId } = this.options;
|
|
1912
|
+
const fetchUri = this.createUrl(ROUTE_URL, { ...options, projectId }, this.edgeApiHost);
|
|
1913
|
+
return await this.apiClient(
|
|
1914
|
+
fetchUri,
|
|
1915
|
+
this.options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0
|
|
1916
|
+
);
|
|
1917
|
+
}
|
|
1918
|
+
};
|
|
1919
|
+
function mapSlotToPersonalizedVariations(slot) {
|
|
1920
|
+
if (!slot) return [];
|
|
1921
|
+
return slot.map((v, i) => {
|
|
1922
|
+
var _a, _b;
|
|
1923
|
+
const contextTag = (_b = (_a = v.parameters) == null ? void 0 : _a[CANVAS_PERSONALIZATION_PARAM]) == null ? void 0 : _b.value;
|
|
1924
|
+
const id = (contextTag == null ? void 0 : contextTag.name) || `pz-${i}-${v.type}`;
|
|
1925
|
+
return {
|
|
1926
|
+
...v,
|
|
1927
|
+
id,
|
|
1928
|
+
pz: contextTag
|
|
1929
|
+
};
|
|
1930
|
+
});
|
|
1931
|
+
}
|
|
1932
|
+
function mapSlotToTestVariations(slot) {
|
|
1933
|
+
if (!slot) return [];
|
|
1934
|
+
return slot.map((v, i) => {
|
|
1935
|
+
var _a, _b, _c;
|
|
1936
|
+
const contextTag = (_b = (_a = v.parameters) == null ? void 0 : _a[CANVAS_TEST_VARIANT_PARAM]) == null ? void 0 : _b.value;
|
|
1937
|
+
const id = (_c = contextTag == null ? void 0 : contextTag.id) != null ? _c : "testId" in v ? v.testId : `ab-${i}-${v.type}`;
|
|
1938
|
+
return {
|
|
1939
|
+
...v,
|
|
1940
|
+
id,
|
|
1941
|
+
testDistribution: contextTag == null ? void 0 : contextTag.testDistribution,
|
|
1942
|
+
control: contextTag == null ? void 0 : contextTag.control
|
|
1943
|
+
};
|
|
1944
|
+
});
|
|
1945
|
+
}
|
|
1946
|
+
var isComponentPlaceholderId = (id) => {
|
|
1947
|
+
if (id === PLACEHOLDER_ID) {
|
|
1948
|
+
return true;
|
|
1949
|
+
}
|
|
1950
|
+
if (typeof id !== "string") {
|
|
1951
|
+
return false;
|
|
1952
|
+
}
|
|
1953
|
+
return id == null ? void 0 : id.startsWith(PLACEHOLDER_ID);
|
|
1954
|
+
};
|
|
1955
|
+
|
|
1956
|
+
// src/utils/env.ts
|
|
1957
|
+
var env = {
|
|
1958
|
+
getProjectId: () => {
|
|
1959
|
+
return process.env.UNIFORM_PROJECT_ID;
|
|
1960
|
+
},
|
|
1961
|
+
getApiKey: () => {
|
|
1962
|
+
return process.env.UNIFORM_API_KEY;
|
|
1963
|
+
},
|
|
1964
|
+
getApiHost: () => {
|
|
1965
|
+
return process.env.UNIFORM_API_HOST || process.env.UNIFORM_CLI_BASE_URL;
|
|
1966
|
+
},
|
|
1967
|
+
getEdgeApiHost: () => {
|
|
1968
|
+
return process.env.UNIFORM_EDGE_API_HOST || process.env.UNIFORM_CLI_BASE_EDGE_URL;
|
|
1969
|
+
}
|
|
1970
|
+
};
|
|
1971
|
+
|
|
1972
|
+
// src/utils/tag.ts
|
|
1973
|
+
var buildPathTag = (path) => {
|
|
1974
|
+
const actualPath = path.startsWith("/") ? path : `/${path}`;
|
|
1975
|
+
return `path:${actualPath}`.toLowerCase();
|
|
1976
|
+
};
|
|
1977
|
+
var buildCompositionTag = (compositionId) => {
|
|
1978
|
+
return `composition:${compositionId}`.toLowerCase();
|
|
1979
|
+
};
|
|
1980
|
+
|
|
1981
|
+
// src/config/helpers.ts
|
|
1982
|
+
var import_uniform_server = __toESM(require("uniform.server.config"));
|
|
1983
|
+
var getServerConfig = () => {
|
|
1984
|
+
return import_uniform_server.default;
|
|
1985
|
+
};
|
|
1986
|
+
|
|
1987
|
+
// src/utils/draft.ts
|
|
1988
|
+
var isDraftModeEnabled = ({
|
|
1989
|
+
draftModeEnabled
|
|
1990
|
+
}) => {
|
|
1991
|
+
return draftModeEnabled;
|
|
1992
|
+
};
|
|
1993
|
+
var isIncontextEditingEnabled = ({ searchParams }) => {
|
|
1994
|
+
const containsKey = searchParams.has(IN_CONTEXT_EDITOR_QUERY_STRING_PARAM);
|
|
1995
|
+
return containsKey;
|
|
1996
|
+
};
|
|
1997
|
+
var isDevelopmentEnvironment = () => {
|
|
1998
|
+
return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
|
|
1999
|
+
};
|
|
2000
|
+
|
|
2001
|
+
// src/clients/cache.ts
|
|
2002
|
+
var isSpecificCacheMode = (options) => {
|
|
2003
|
+
return "cache" in options;
|
|
2004
|
+
};
|
|
2005
|
+
var isStateCacheMode = (options) => {
|
|
2006
|
+
return "state" in options;
|
|
2007
|
+
};
|
|
2008
|
+
var isDetectCacheMode = (options) => {
|
|
2009
|
+
return "searchParams" in options && "draftModeEnabled" in options;
|
|
2010
|
+
};
|
|
2011
|
+
var resolveManifestCache = (options) => {
|
|
2012
|
+
return resolveCache({
|
|
2013
|
+
options,
|
|
2014
|
+
defaultCache: getServerConfig().manifestCache
|
|
2015
|
+
});
|
|
2016
|
+
};
|
|
2017
|
+
var resolveCanvasCache = (options) => {
|
|
2018
|
+
return resolveCache({
|
|
2019
|
+
options,
|
|
2020
|
+
defaultCache: getServerConfig().canvasCache
|
|
2021
|
+
});
|
|
2022
|
+
};
|
|
2023
|
+
var resolveProjectMapCache = (options) => {
|
|
2024
|
+
return resolveCache({
|
|
2025
|
+
options,
|
|
2026
|
+
defaultCache: getServerConfig().projectMapCache
|
|
2027
|
+
});
|
|
2028
|
+
};
|
|
2029
|
+
var resolveCache = ({
|
|
2030
|
+
options,
|
|
2031
|
+
defaultCache
|
|
2032
|
+
}) => {
|
|
2033
|
+
let cache2 = defaultCache;
|
|
2034
|
+
if (options) {
|
|
2035
|
+
if (isSpecificCacheMode(options)) {
|
|
2036
|
+
cache2 = options.cache;
|
|
2037
|
+
} else if (isStateCacheMode(options)) {
|
|
2038
|
+
if (options.state === CANVAS_DRAFT_STATE || options.state === CANVAS_EDITOR_STATE) {
|
|
2039
|
+
cache2 = {
|
|
2040
|
+
type: "no-cache",
|
|
2041
|
+
bypassCache: true
|
|
2042
|
+
};
|
|
2043
|
+
}
|
|
2044
|
+
} else if (isDetectCacheMode(options)) {
|
|
2045
|
+
const { disabled } = shouldCacheBeDisabled(options);
|
|
2046
|
+
if (disabled) {
|
|
2047
|
+
cache2 = {
|
|
2048
|
+
type: "no-cache",
|
|
2049
|
+
bypassCache: true
|
|
2050
|
+
};
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
return cache2 || {
|
|
2055
|
+
type: "force-cache"
|
|
2056
|
+
};
|
|
2057
|
+
};
|
|
2058
|
+
var shouldCacheBeDisabled = (options) => {
|
|
2059
|
+
if (isDraftModeEnabled(options)) {
|
|
2060
|
+
return { disabled: true, reason: "DRAFT" };
|
|
2061
|
+
}
|
|
2062
|
+
if (isIncontextEditingEnabled(options)) {
|
|
2063
|
+
return { disabled: true, reason: "INCONTEXT" };
|
|
2064
|
+
}
|
|
2065
|
+
if (isDevelopmentEnvironment()) {
|
|
2066
|
+
return { disabled: true, reason: "DEV" };
|
|
2067
|
+
}
|
|
2068
|
+
return {
|
|
2069
|
+
disabled: false,
|
|
2070
|
+
reason: void 0
|
|
2071
|
+
};
|
|
2072
|
+
};
|
|
2073
|
+
var determineFetchCacheOptions = (mode) => {
|
|
2074
|
+
let cache2 = void 0;
|
|
2075
|
+
let revalidate = void 0;
|
|
2076
|
+
if (mode.type === "revalidate") {
|
|
2077
|
+
cache2 = void 0;
|
|
2078
|
+
revalidate = mode.interval;
|
|
2079
|
+
} else {
|
|
2080
|
+
cache2 = mode.type;
|
|
2081
|
+
}
|
|
2082
|
+
return {
|
|
2083
|
+
cache: cache2,
|
|
2084
|
+
revalidate
|
|
2085
|
+
};
|
|
2086
|
+
};
|
|
2087
|
+
|
|
2088
|
+
// src/clients/retry.ts
|
|
2089
|
+
function createThrottler(limit, interval) {
|
|
2090
|
+
let available = limit;
|
|
2091
|
+
let refillScheduled = false;
|
|
2092
|
+
const waiting = [];
|
|
2093
|
+
function scheduleRefill() {
|
|
2094
|
+
if (refillScheduled) return;
|
|
2095
|
+
refillScheduled = true;
|
|
2096
|
+
setTimeout(() => {
|
|
2097
|
+
refillScheduled = false;
|
|
2098
|
+
available = limit;
|
|
2099
|
+
while (available > 0 && waiting.length > 0) {
|
|
2100
|
+
available--;
|
|
2101
|
+
const next = waiting.shift();
|
|
2102
|
+
next();
|
|
2103
|
+
}
|
|
2104
|
+
if (waiting.length > 0) {
|
|
2105
|
+
scheduleRefill();
|
|
2106
|
+
}
|
|
2107
|
+
}, interval);
|
|
2108
|
+
}
|
|
2109
|
+
return async function throttle(fn) {
|
|
2110
|
+
if (available > 0) {
|
|
2111
|
+
available--;
|
|
2112
|
+
if (!refillScheduled) {
|
|
2113
|
+
scheduleRefill();
|
|
2114
|
+
}
|
|
2115
|
+
return fn();
|
|
2116
|
+
}
|
|
2117
|
+
return new Promise((resolve, reject) => {
|
|
2118
|
+
waiting.push(() => {
|
|
2119
|
+
fn().then(resolve, reject);
|
|
2120
|
+
});
|
|
2121
|
+
scheduleRefill();
|
|
2122
|
+
});
|
|
2123
|
+
};
|
|
2124
|
+
}
|
|
2125
|
+
function createLimiter(concurrency) {
|
|
2126
|
+
let active = 0;
|
|
2127
|
+
const queue = [];
|
|
2128
|
+
return async function limit(fn) {
|
|
2129
|
+
return new Promise((resolve, reject) => {
|
|
2130
|
+
const run = async () => {
|
|
2131
|
+
active++;
|
|
2132
|
+
try {
|
|
2133
|
+
const result = await fn();
|
|
2134
|
+
resolve(result);
|
|
2135
|
+
} catch (error) {
|
|
2136
|
+
reject(error);
|
|
2137
|
+
} finally {
|
|
2138
|
+
active--;
|
|
2139
|
+
if (queue.length > 0) {
|
|
2140
|
+
const next = queue.shift();
|
|
2141
|
+
next();
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
};
|
|
2145
|
+
if (active < concurrency) {
|
|
2146
|
+
run();
|
|
2147
|
+
} else {
|
|
2148
|
+
queue.push(run);
|
|
2149
|
+
}
|
|
2150
|
+
});
|
|
2151
|
+
};
|
|
2152
|
+
}
|
|
2153
|
+
async function retry(fn, options) {
|
|
2154
|
+
let lastError;
|
|
2155
|
+
let delay = 1e3;
|
|
2156
|
+
for (let attempt = 1; attempt <= options.retries + 1; attempt++) {
|
|
2157
|
+
try {
|
|
2158
|
+
return await fn();
|
|
2159
|
+
} catch (error) {
|
|
2160
|
+
lastError = error;
|
|
2161
|
+
const attemptError = Object.assign(error, { attemptNumber: attempt });
|
|
2162
|
+
if (options.onFailedAttempt) {
|
|
2163
|
+
await options.onFailedAttempt(attemptError);
|
|
2164
|
+
}
|
|
2165
|
+
if (attempt > options.retries) {
|
|
2166
|
+
throw error;
|
|
2167
|
+
}
|
|
2168
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
2169
|
+
delay *= options.factor;
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
2172
|
+
throw lastError;
|
|
2173
|
+
}
|
|
2174
|
+
function createLimitPolicy2({
|
|
2175
|
+
throttle = { interval: 1e3, limit: 10 },
|
|
2176
|
+
retry: retryOptions = { retries: 1, factor: 1.66 },
|
|
2177
|
+
limit = 10
|
|
2178
|
+
}) {
|
|
2179
|
+
const throttler = throttle ? createThrottler(throttle.limit, throttle.interval) : null;
|
|
2180
|
+
const limiter = limit ? createLimiter(limit) : null;
|
|
2181
|
+
return function limitPolicy(func) {
|
|
2182
|
+
let currentFunc = async () => await func();
|
|
2183
|
+
if (throttler) {
|
|
2184
|
+
const throttleFunc = currentFunc;
|
|
2185
|
+
currentFunc = () => throttler(throttleFunc);
|
|
2186
|
+
}
|
|
2187
|
+
if (limiter) {
|
|
2188
|
+
const limitFunc = currentFunc;
|
|
2189
|
+
currentFunc = () => limiter(limitFunc);
|
|
2190
|
+
}
|
|
2191
|
+
if (retryOptions) {
|
|
2192
|
+
const retryFunc = currentFunc;
|
|
2193
|
+
currentFunc = () => retry(retryFunc, {
|
|
2194
|
+
...retryOptions,
|
|
2195
|
+
onFailedAttempt: async (error) => {
|
|
2196
|
+
if (retryOptions.onFailedAttempt) {
|
|
2197
|
+
await retryOptions.onFailedAttempt(error);
|
|
2198
|
+
}
|
|
2199
|
+
if (error instanceof ApiClientError && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
|
|
2200
|
+
throw error;
|
|
2201
|
+
}
|
|
2202
|
+
}
|
|
2203
|
+
});
|
|
2204
|
+
}
|
|
2205
|
+
return currentFunc();
|
|
2206
|
+
};
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
// src/clients/canvas.ts
|
|
2210
|
+
var getCanvasClient = (options) => {
|
|
2211
|
+
const cache2 = resolveCanvasCache(options);
|
|
2212
|
+
return new CanvasClient({
|
|
2213
|
+
projectId: env.getProjectId(),
|
|
2214
|
+
apiHost: env.getApiHost(),
|
|
2215
|
+
apiKey: env.getApiKey(),
|
|
2216
|
+
edgeApiHost: env.getEdgeApiHost(),
|
|
2217
|
+
disableSWR: typeof cache2.disableSWR !== "undefined" ? cache2.disableSWR : true,
|
|
2218
|
+
limitPolicy: createLimitPolicy2({
|
|
2219
|
+
limit: 6
|
|
2220
|
+
}),
|
|
2221
|
+
fetch: (req, init) => {
|
|
2222
|
+
let requestedUrl;
|
|
2223
|
+
if (typeof req === "string") {
|
|
2224
|
+
requestedUrl = new URL(req);
|
|
2225
|
+
} else if (req instanceof URL) {
|
|
2226
|
+
requestedUrl = req;
|
|
2227
|
+
} else {
|
|
2228
|
+
requestedUrl = new URL(req.url);
|
|
2229
|
+
}
|
|
2230
|
+
const tags = [];
|
|
2231
|
+
if (requestedUrl) {
|
|
2232
|
+
const compositionIdKey = "compositionId";
|
|
2233
|
+
const compositionIdsKey = "compositionIDs";
|
|
2234
|
+
const compositionId = requestedUrl.searchParams.get(compositionIdKey);
|
|
2235
|
+
const compositionIds = requestedUrl.searchParams.get(compositionIdsKey);
|
|
2236
|
+
if (compositionId) {
|
|
2237
|
+
tags.push(buildCompositionTag(compositionId));
|
|
2238
|
+
}
|
|
2239
|
+
if (compositionIds) {
|
|
2240
|
+
const ids = compositionIds.split(",");
|
|
2241
|
+
for (let i = 0; i < ids.length; i++) {
|
|
2242
|
+
tags.push(buildCompositionTag(ids[i]));
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
const { cache: fetchCache, revalidate } = determineFetchCacheOptions(cache2);
|
|
2247
|
+
return fetch(req, {
|
|
2248
|
+
...init,
|
|
2249
|
+
cache: fetchCache,
|
|
2250
|
+
headers: {
|
|
2251
|
+
...init == null ? void 0 : init.headers,
|
|
2252
|
+
"x-bypass-cache": typeof cache2.bypassCache !== "undefined" ? cache2.bypassCache.toString() : "false"
|
|
2253
|
+
},
|
|
2254
|
+
next: {
|
|
2255
|
+
revalidate,
|
|
2256
|
+
tags: tags.length ? tags : void 0
|
|
2257
|
+
}
|
|
2258
|
+
});
|
|
2259
|
+
}
|
|
2260
|
+
});
|
|
2261
|
+
};
|
|
2262
|
+
|
|
2263
|
+
// src/clients/manifest.ts
|
|
2264
|
+
var import_server_only2 = require("server-only");
|
|
2265
|
+
|
|
2266
|
+
// src/clients/tags.ts
|
|
2267
|
+
var generateRouteCacheTags = ({ path, old }) => {
|
|
2268
|
+
const tags = old ? ["route-old"] : ["route"];
|
|
2269
|
+
if (path) {
|
|
2270
|
+
const pathWithoutQuery = path.split("?")[0];
|
|
2271
|
+
const pieces = pathWithoutQuery.split("/");
|
|
2272
|
+
for (let i = 0; i < pieces.length; i++) {
|
|
2273
|
+
const segmentPieces = pieces.slice(0, i + 1);
|
|
2274
|
+
const segment = segmentPieces.join("/");
|
|
2275
|
+
tags.push(buildPathTag(segment));
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2278
|
+
return tags;
|
|
2279
|
+
};
|
|
2280
|
+
var generateManifestCacheTags = () => {
|
|
2281
|
+
return ["manifest"];
|
|
2282
|
+
};
|
|
2283
|
+
|
|
2284
|
+
// src/clients/manifest.ts
|
|
2285
|
+
var getManifestClient = (options) => {
|
|
2286
|
+
const cache2 = resolveManifestCache(options);
|
|
2287
|
+
const manifestClient = new ManifestClient({
|
|
2288
|
+
apiHost: env.getApiHost(),
|
|
2289
|
+
apiKey: env.getApiKey(),
|
|
2290
|
+
projectId: env.getProjectId(),
|
|
2291
|
+
limitPolicy: createLimitPolicy2({
|
|
2292
|
+
limit: 6
|
|
2293
|
+
}),
|
|
2294
|
+
fetch: (req, init) => {
|
|
2295
|
+
const { cache: fetchCache, revalidate } = determineFetchCacheOptions(cache2);
|
|
2296
|
+
return fetch(req, {
|
|
2297
|
+
...init,
|
|
2298
|
+
headers: {
|
|
2299
|
+
...init == null ? void 0 : init.headers,
|
|
2300
|
+
"x-bypass-cache": typeof cache2.bypassCache !== "undefined" ? cache2.bypassCache.toString() : "false"
|
|
2301
|
+
},
|
|
2302
|
+
cache: fetchCache,
|
|
2303
|
+
next: {
|
|
2304
|
+
revalidate,
|
|
2305
|
+
tags: generateManifestCacheTags()
|
|
2306
|
+
}
|
|
2307
|
+
});
|
|
2308
|
+
}
|
|
2309
|
+
});
|
|
2310
|
+
return manifestClient;
|
|
2311
|
+
};
|
|
2312
|
+
var getManifest = async (options) => {
|
|
2313
|
+
let preview = false;
|
|
2314
|
+
if (options && isStateCacheMode(options)) {
|
|
2315
|
+
preview = options.state === CANVAS_DRAFT_STATE || options.state === CANVAS_EDITOR_STATE;
|
|
2316
|
+
}
|
|
2317
|
+
const manifestClient = getManifestClient(options);
|
|
2318
|
+
return manifestClient.get({
|
|
2319
|
+
preview
|
|
2320
|
+
});
|
|
2321
|
+
};
|
|
2322
|
+
|
|
2323
|
+
// src/clients/projectMap.ts
|
|
2324
|
+
var import_server_only3 = require("server-only");
|
|
2325
|
+
|
|
2326
|
+
// ../project-map/dist/index.mjs
|
|
2327
|
+
var __typeError3 = (msg) => {
|
|
2328
|
+
throw TypeError(msg);
|
|
2329
|
+
};
|
|
2330
|
+
var __accessCheck3 = (obj, member, msg) => member.has(obj) || __typeError3("Cannot " + msg);
|
|
2331
|
+
var __privateGet3 = (obj, member, getter) => (__accessCheck3(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
2332
|
+
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);
|
|
2333
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck3(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
2334
|
+
var __privateMethod = (obj, member, method) => (__accessCheck3(obj, member, "access private method"), method);
|
|
2335
|
+
var ProjectMapClient = class extends ApiClient {
|
|
2336
|
+
constructor(options) {
|
|
2337
|
+
super(options);
|
|
2338
|
+
this.getProjectMapDefinitions = async () => {
|
|
2339
|
+
const { projectId } = this.options;
|
|
2340
|
+
const fetchUri = this.createUrl("/api/v1/project-map", { projectId });
|
|
2341
|
+
return await this.apiClient(fetchUri);
|
|
2342
|
+
};
|
|
2343
|
+
this.getProjectMapDefinition = async (options2) => {
|
|
2344
|
+
const { projectId } = this.options;
|
|
2345
|
+
const fetchUri = this.createUrl("/api/v1/project-map", {
|
|
2346
|
+
...options2,
|
|
2347
|
+
projectId
|
|
2348
|
+
});
|
|
2349
|
+
return await this.apiClient(fetchUri);
|
|
2350
|
+
};
|
|
2351
|
+
this.upsertProjectMap = async (options2) => {
|
|
2352
|
+
const { projectId } = this.options;
|
|
2353
|
+
const fetchUri = this.createUrl("/api/v1/project-map");
|
|
2354
|
+
const result = await this.apiClient(fetchUri, {
|
|
2355
|
+
method: "PUT",
|
|
2356
|
+
body: JSON.stringify({ ...options2, projectId })
|
|
2357
|
+
});
|
|
2358
|
+
return result.projectMapId;
|
|
2359
|
+
};
|
|
2360
|
+
this.deleteProjectMap = async (options2) => {
|
|
2361
|
+
const { projectId } = this.options;
|
|
2362
|
+
const fetchUri = this.createUrl("/api/v1/project-map");
|
|
2363
|
+
await this.apiClient(fetchUri, {
|
|
2364
|
+
method: "DELETE",
|
|
2365
|
+
body: JSON.stringify({ ...options2, projectId }),
|
|
2366
|
+
expectNoContent: true
|
|
2367
|
+
});
|
|
2368
|
+
};
|
|
2369
|
+
this.upsertProjectMapNodes = async (options2) => {
|
|
2370
|
+
const { projectId } = this.options;
|
|
2371
|
+
const fetchUri = this.createUrl("/api/v1/project-map-nodes");
|
|
2372
|
+
await this.apiClient(fetchUri, {
|
|
2373
|
+
method: "PUT",
|
|
2374
|
+
body: JSON.stringify({
|
|
2375
|
+
...options2,
|
|
2376
|
+
projectId,
|
|
2377
|
+
nodes: options2.nodes.map((n) => {
|
|
2378
|
+
return {
|
|
2379
|
+
...n,
|
|
2380
|
+
node: { ...this.cleanProjectMapNode(n.node) }
|
|
2381
|
+
};
|
|
2382
|
+
})
|
|
2383
|
+
}),
|
|
2384
|
+
expectNoContent: true
|
|
2385
|
+
});
|
|
2386
|
+
};
|
|
2387
|
+
this.deleteProjectMapNode = async (options2) => {
|
|
2388
|
+
const { projectId } = this.options;
|
|
2389
|
+
const fetchUri = this.createUrl("/api/v1/project-map-nodes");
|
|
2390
|
+
await this.apiClient(fetchUri, {
|
|
2391
|
+
method: "DELETE",
|
|
2392
|
+
body: JSON.stringify({
|
|
2393
|
+
...options2,
|
|
2394
|
+
projectId
|
|
2395
|
+
}),
|
|
2396
|
+
expectNoContent: true
|
|
2397
|
+
});
|
|
2398
|
+
};
|
|
2399
|
+
this.getSubtree = async (options2) => {
|
|
2400
|
+
var _a;
|
|
2401
|
+
const fetchOptions = this.setFetchOptions(options2);
|
|
2402
|
+
fetchOptions["tree"] = "true";
|
|
2403
|
+
const fetchUri = this.createUrl("/api/v1/project-map-nodes", fetchOptions);
|
|
2404
|
+
const result = await this.apiClient(fetchUri);
|
|
2405
|
+
const root = {
|
|
2406
|
+
...result.tree
|
|
2407
|
+
};
|
|
2408
|
+
const nodes = [root];
|
|
2409
|
+
while (nodes && nodes.length > 0) {
|
|
2410
|
+
const currentNode = nodes.pop();
|
|
2411
|
+
let lastChild = void 0;
|
|
2412
|
+
(_a = currentNode == null ? void 0 : currentNode.children) == null ? void 0 : _a.forEach((child) => {
|
|
2413
|
+
child.parent = cutReferences(currentNode);
|
|
2414
|
+
child.previousSibling = cutReferences(lastChild);
|
|
2415
|
+
if (lastChild) {
|
|
2416
|
+
lastChild.nextSibling = cutReferences(child);
|
|
2417
|
+
}
|
|
2418
|
+
lastChild = child;
|
|
2419
|
+
nodes.push(child);
|
|
2420
|
+
});
|
|
2421
|
+
}
|
|
2422
|
+
return root;
|
|
2423
|
+
};
|
|
2424
|
+
this.getNodes = async (options2) => {
|
|
2425
|
+
const fetchOptions = this.setFetchOptions(options2);
|
|
2426
|
+
const fetchUri = this.createUrl("/api/v1/project-map-nodes", fetchOptions);
|
|
2427
|
+
return await this.apiClient(fetchUri);
|
|
2428
|
+
};
|
|
2429
|
+
}
|
|
2430
|
+
setFetchOptions(options) {
|
|
2431
|
+
const { projectId } = this.options;
|
|
2432
|
+
const fetchOptions = {
|
|
2433
|
+
projectId
|
|
2434
|
+
};
|
|
2435
|
+
Object.entries(options).forEach(([key, value]) => {
|
|
2436
|
+
if (value === void 0) {
|
|
2437
|
+
return;
|
|
2438
|
+
}
|
|
2439
|
+
if (typeof value === "boolean") {
|
|
2440
|
+
if (!value) {
|
|
2441
|
+
return;
|
|
2442
|
+
}
|
|
2443
|
+
fetchOptions[key] = "true";
|
|
2444
|
+
return;
|
|
2445
|
+
}
|
|
2446
|
+
if (typeof value === "number") {
|
|
2447
|
+
fetchOptions[key] = value.toString(10);
|
|
2448
|
+
return;
|
|
2449
|
+
}
|
|
2450
|
+
fetchOptions[key] = value;
|
|
2451
|
+
});
|
|
2452
|
+
return fetchOptions;
|
|
2453
|
+
}
|
|
2454
|
+
cleanProjectMapNode(node) {
|
|
2455
|
+
var _a, _b, _c;
|
|
2456
|
+
return {
|
|
2457
|
+
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,
|
|
2458
|
+
path: node.path,
|
|
2459
|
+
name: node.name,
|
|
2460
|
+
type: node.type,
|
|
2461
|
+
order: node.order,
|
|
2462
|
+
data: node.data,
|
|
2463
|
+
compositionId: node.compositionId,
|
|
2464
|
+
description: node.description,
|
|
2465
|
+
locales: node.locales
|
|
2466
|
+
};
|
|
2467
|
+
}
|
|
2468
|
+
};
|
|
2469
|
+
var cutReferences = (node) => node ? {
|
|
2470
|
+
...node,
|
|
2471
|
+
parent: void 0,
|
|
2472
|
+
children: void 0
|
|
2473
|
+
} : void 0;
|
|
2474
|
+
var _routeInfo;
|
|
2475
|
+
var _Route_static;
|
|
2476
|
+
var parseRouteOrPath_fn;
|
|
2477
|
+
var isDynamicRouteSegment_fn;
|
|
2478
|
+
var _Route = class _Route2 {
|
|
2479
|
+
constructor(route) {
|
|
2480
|
+
this.route = route;
|
|
2481
|
+
__privateAdd3(this, _routeInfo);
|
|
2482
|
+
var _a;
|
|
2483
|
+
__privateSet(this, _routeInfo, __privateMethod(_a = _Route2, _Route_static, parseRouteOrPath_fn).call(_a, this.route));
|
|
2484
|
+
}
|
|
2485
|
+
get dynamicSegmentCount() {
|
|
2486
|
+
return __privateGet3(this, _routeInfo).segments.reduce(
|
|
2487
|
+
(count, segment) => {
|
|
2488
|
+
var _a;
|
|
2489
|
+
return __privateMethod(_a = _Route2, _Route_static, isDynamicRouteSegment_fn).call(_a, segment) ? count + 1 : count;
|
|
2490
|
+
},
|
|
2491
|
+
0
|
|
2492
|
+
);
|
|
2493
|
+
}
|
|
2494
|
+
/** Tests if an incoming path matches this route */
|
|
2495
|
+
matches(path) {
|
|
2496
|
+
var _a, _b;
|
|
2497
|
+
const { segments: pathSegments, queryParams: pathQuery } = __privateMethod(_a = _Route2, _Route_static, parseRouteOrPath_fn).call(_a, path);
|
|
2498
|
+
const { segments: routeSegments } = __privateGet3(this, _routeInfo);
|
|
2499
|
+
if (pathSegments.length !== routeSegments.length) {
|
|
2500
|
+
return { match: false };
|
|
2501
|
+
}
|
|
2502
|
+
const possibleMatch = {
|
|
2503
|
+
match: true,
|
|
2504
|
+
dynamicSegmentCount: 0,
|
|
2505
|
+
pathParams: {},
|
|
2506
|
+
queryParams: {}
|
|
2507
|
+
};
|
|
2508
|
+
for (let i = 0; i < routeSegments.length; i++) {
|
|
2509
|
+
const routeSegment = routeSegments[i];
|
|
2510
|
+
const pathSegment = pathSegments[i];
|
|
2511
|
+
if (__privateMethod(_b = _Route2, _Route_static, isDynamicRouteSegment_fn).call(_b, routeSegment)) {
|
|
2512
|
+
const key = routeSegment.slice(1);
|
|
2513
|
+
possibleMatch.pathParams[key] = pathSegment;
|
|
2514
|
+
possibleMatch.dynamicSegmentCount++;
|
|
2515
|
+
} else if (routeSegment !== pathSegment) {
|
|
2516
|
+
return { match: false };
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
for (const [key, value] of __privateGet3(this, _routeInfo).queryParams) {
|
|
2520
|
+
possibleMatch.queryParams[key] = pathQuery.has(key) ? pathQuery.get(key) : value;
|
|
2521
|
+
}
|
|
2522
|
+
return possibleMatch;
|
|
2523
|
+
}
|
|
2524
|
+
/**
|
|
2525
|
+
* Creates an expanded path value for this route given dynamic input values and allowed query string values
|
|
2526
|
+
*/
|
|
2527
|
+
expand(options) {
|
|
2528
|
+
const { dynamicInputValues = {}, allowedQueryParams = [], doNotEscapeVariables = false } = options != null ? options : {};
|
|
2529
|
+
const path = __privateGet3(this, _routeInfo).segments.map((segment) => {
|
|
2530
|
+
const dynamicSegmentName = _Route2.getDynamicRouteSegmentName(segment);
|
|
2531
|
+
if (!dynamicSegmentName) {
|
|
2532
|
+
return segment;
|
|
2533
|
+
}
|
|
2534
|
+
const dynamicSegmentValue = dynamicInputValues[dynamicSegmentName];
|
|
2535
|
+
if (!dynamicSegmentValue) {
|
|
2536
|
+
return segment;
|
|
2537
|
+
}
|
|
2538
|
+
return encodeRouteComponent(dynamicSegmentValue, doNotEscapeVariables);
|
|
2539
|
+
}).join("/");
|
|
2540
|
+
const queries = allowedQueryParams.filter((qs) => {
|
|
2541
|
+
const type = typeof dynamicInputValues[qs];
|
|
2542
|
+
return type === "string" || type === "number" || type === "boolean";
|
|
2543
|
+
}).map(
|
|
2544
|
+
(qs) => `${encodeRouteComponent(qs, doNotEscapeVariables)}=${encodeRouteComponent(
|
|
2545
|
+
dynamicInputValues[qs],
|
|
2546
|
+
doNotEscapeVariables
|
|
2547
|
+
)}`
|
|
2548
|
+
);
|
|
2549
|
+
const query = queries.length ? `?${queries.join("&")}` : "";
|
|
2550
|
+
return `/${path}${query}`;
|
|
2551
|
+
}
|
|
2552
|
+
static getDynamicRouteSegmentName(segment) {
|
|
2553
|
+
var _a;
|
|
2554
|
+
if (!__privateMethod(_a = _Route2, _Route_static, isDynamicRouteSegment_fn).call(_a, segment)) {
|
|
2555
|
+
return void 0;
|
|
2556
|
+
}
|
|
2557
|
+
return segment.slice(_Route2.dynamicSegmentPrefix.length);
|
|
2558
|
+
}
|
|
2559
|
+
};
|
|
2560
|
+
_routeInfo = /* @__PURE__ */ new WeakMap();
|
|
2561
|
+
_Route_static = /* @__PURE__ */ new WeakSet();
|
|
2562
|
+
parseRouteOrPath_fn = function(path) {
|
|
2563
|
+
if (!path.startsWith("/") || path === "") {
|
|
2564
|
+
throw new Error(`Path must start with a slash: ${path}`);
|
|
2565
|
+
}
|
|
2566
|
+
const [pathname, queryString] = path.split("?");
|
|
2567
|
+
const pathSegments = pathname.substring(1).split("/");
|
|
2568
|
+
if (pathSegments[pathSegments.length - 1] === "") {
|
|
2569
|
+
pathSegments.pop();
|
|
2570
|
+
}
|
|
2571
|
+
const queryParams = new URLSearchParams(queryString);
|
|
2572
|
+
return { segments: pathSegments, queryParams };
|
|
2573
|
+
};
|
|
2574
|
+
isDynamicRouteSegment_fn = function(segment) {
|
|
2575
|
+
if (!segment) {
|
|
2576
|
+
return false;
|
|
2577
|
+
}
|
|
2578
|
+
return segment.startsWith(_Route.dynamicSegmentPrefix);
|
|
2579
|
+
};
|
|
2580
|
+
__privateAdd3(_Route, _Route_static);
|
|
2581
|
+
_Route.dynamicSegmentPrefix = ":";
|
|
2582
|
+
function encodeRouteComponent(value, doNotEscapeVariables) {
|
|
2583
|
+
if (!doNotEscapeVariables) {
|
|
2584
|
+
return encodeURIComponent(value);
|
|
2585
|
+
}
|
|
2586
|
+
const result = [];
|
|
2587
|
+
parseVariableExpression(value.toString(10), (token, type) => {
|
|
2588
|
+
if (type === "variable") {
|
|
2589
|
+
result.push(createVariableReference(token));
|
|
2590
|
+
} else {
|
|
2591
|
+
result.push(encodeURIComponent(token));
|
|
2592
|
+
}
|
|
2593
|
+
});
|
|
2594
|
+
return result.join("");
|
|
2595
|
+
}
|
|
2596
|
+
|
|
2597
|
+
// src/clients/projectMap.ts
|
|
2598
|
+
var getProjectMapClient = (options) => {
|
|
2599
|
+
const cache2 = resolveProjectMapCache(options);
|
|
2600
|
+
const manifestClient = new ProjectMapClient({
|
|
2601
|
+
apiHost: env.getApiHost(),
|
|
2602
|
+
apiKey: env.getApiKey(),
|
|
2603
|
+
projectId: env.getProjectId(),
|
|
2604
|
+
limitPolicy: createLimitPolicy2({
|
|
2605
|
+
limit: 6
|
|
2606
|
+
}),
|
|
2607
|
+
fetch: (req, init) => {
|
|
2608
|
+
const { cache: fetchCache, revalidate } = determineFetchCacheOptions(cache2);
|
|
2609
|
+
return fetch(req, {
|
|
2610
|
+
...init,
|
|
2611
|
+
headers: {
|
|
2612
|
+
...init == null ? void 0 : init.headers,
|
|
2613
|
+
"x-bypass-cache": typeof cache2.bypassCache !== "undefined" ? cache2.bypassCache.toString() : "false"
|
|
2614
|
+
},
|
|
2615
|
+
cache: fetchCache,
|
|
2616
|
+
next: {
|
|
2617
|
+
revalidate
|
|
2618
|
+
}
|
|
2619
|
+
});
|
|
2620
|
+
}
|
|
2621
|
+
});
|
|
2622
|
+
return manifestClient;
|
|
2623
|
+
};
|
|
2624
|
+
|
|
2625
|
+
// src/clients/route.ts
|
|
2626
|
+
var import_server_only4 = require("server-only");
|
|
2627
|
+
var getRouteCacheTags = (requestedUrl) => {
|
|
2628
|
+
const tags = ["route"];
|
|
2629
|
+
if (requestedUrl) {
|
|
2630
|
+
const pathKey = "path";
|
|
2631
|
+
const path = requestedUrl.searchParams.get(pathKey);
|
|
2632
|
+
if (path) {
|
|
2633
|
+
return generateRouteCacheTags({ path });
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
return tags;
|
|
2637
|
+
};
|
|
2638
|
+
var getRouteClient = (options) => {
|
|
2639
|
+
const cache2 = resolveCanvasCache(options);
|
|
2640
|
+
const client = new RouteClient({
|
|
2641
|
+
projectId: env.getProjectId(),
|
|
2642
|
+
apiKey: env.getApiKey(),
|
|
2643
|
+
edgeApiHost: env.getEdgeApiHost(),
|
|
2644
|
+
disableSWR: typeof cache2.disableSWR !== "undefined" ? cache2.disableSWR : true,
|
|
2645
|
+
limitPolicy: createLimitPolicy2({
|
|
2646
|
+
limit: 6
|
|
2647
|
+
}),
|
|
2648
|
+
fetch: (req, init) => {
|
|
2649
|
+
let requestedUrl;
|
|
2650
|
+
if (typeof req === "string") {
|
|
2651
|
+
requestedUrl = new URL(req);
|
|
2652
|
+
} else if (req instanceof URL) {
|
|
2653
|
+
requestedUrl = req;
|
|
2654
|
+
} else {
|
|
2655
|
+
requestedUrl = new URL(req.url);
|
|
2656
|
+
}
|
|
2657
|
+
const tags = getRouteCacheTags(requestedUrl);
|
|
2658
|
+
const { cache: fetchCache, revalidate } = determineFetchCacheOptions(cache2);
|
|
2659
|
+
return fetch(req, {
|
|
2660
|
+
...init,
|
|
2661
|
+
headers: {
|
|
2662
|
+
...init == null ? void 0 : init.headers,
|
|
2663
|
+
"x-bypass-cache": typeof cache2.bypassCache !== "undefined" ? cache2.bypassCache.toString() : "false"
|
|
2664
|
+
},
|
|
2665
|
+
cache: fetchCache,
|
|
2666
|
+
next: {
|
|
2667
|
+
revalidate,
|
|
2668
|
+
tags: tags.length ? tags : void 0
|
|
2669
|
+
}
|
|
2670
|
+
});
|
|
2671
|
+
}
|
|
2672
|
+
});
|
|
2673
|
+
return client;
|
|
2674
|
+
};
|
|
2675
|
+
|
|
2676
|
+
// src/components/UniformComposition.tsx
|
|
2677
|
+
var import_core = require("@uniformdev/canvas-react/core");
|
|
2678
|
+
var import_next_app_router_client4 = require("@uniformdev/next-app-router-client");
|
|
2679
|
+
var import_next_app_router_shared4 = require("@uniformdev/next-app-router-shared");
|
|
2680
|
+
var import_navigation = require("next/navigation");
|
|
2681
|
+
var import_react6 = __toESM(require("react"));
|
|
2682
|
+
|
|
2683
|
+
// src/data/extract/extractTest.ts
|
|
2684
|
+
var import_next_app_router_shared = require("@uniformdev/next-app-router-shared");
|
|
2685
|
+
var extractTest = ({ component }) => {
|
|
2686
|
+
var _a;
|
|
2687
|
+
const testName = (0, import_next_app_router_shared.extractTestName)({ component });
|
|
2688
|
+
const slot = ((_a = component.slots) == null ? void 0 : _a[CANVAS_TEST_SLOT]) || [];
|
|
2689
|
+
const componentVariations = mapSlotToTestVariations(slot).map((variation, index) => {
|
|
2690
|
+
const slotComponent = slot[index];
|
|
2691
|
+
if (!slotComponent) {
|
|
2692
|
+
throw new Error(`Slot component not found for index ${index}`);
|
|
2693
|
+
}
|
|
2694
|
+
return {
|
|
2695
|
+
...variation,
|
|
2696
|
+
index,
|
|
2697
|
+
componentId: slotComponent._id
|
|
2698
|
+
};
|
|
2699
|
+
});
|
|
2700
|
+
return {
|
|
2701
|
+
name: testName,
|
|
2702
|
+
variations: componentVariations
|
|
2703
|
+
};
|
|
2704
|
+
};
|
|
2705
|
+
|
|
2706
|
+
// src/components/ComponentProps.ts
|
|
2707
|
+
var import_next_app_router_shared2 = require("@uniformdev/next-app-router-shared");
|
|
2708
|
+
var createComponentProps = ({
|
|
2709
|
+
component,
|
|
2710
|
+
parent,
|
|
2711
|
+
isRoot,
|
|
2712
|
+
slotName,
|
|
2713
|
+
slotIndex,
|
|
2714
|
+
slots,
|
|
2715
|
+
pageState,
|
|
2716
|
+
composition,
|
|
2717
|
+
compositionContext
|
|
2718
|
+
}) => {
|
|
2719
|
+
var _a, _b;
|
|
2720
|
+
const parameters = (_a = component.parameters) != null ? _a : {};
|
|
2721
|
+
const componentProps = {
|
|
2722
|
+
parameters: Object.keys(parameters).reduce((acc, cur) => {
|
|
2723
|
+
acc[cur] = {
|
|
2724
|
+
parameterId: cur,
|
|
2725
|
+
...parameters[cur]
|
|
2726
|
+
};
|
|
2727
|
+
return acc;
|
|
2728
|
+
}, {}),
|
|
2729
|
+
component: {
|
|
2730
|
+
_id: component._id,
|
|
2731
|
+
_parentId: (_b = parent == null ? void 0 : parent._id) != null ? _b : null,
|
|
2732
|
+
slotName,
|
|
2733
|
+
slotIndex: isRoot ? void 0 : slotIndex
|
|
2734
|
+
},
|
|
2735
|
+
type: component.type,
|
|
2736
|
+
variant: component.variant,
|
|
2737
|
+
slots,
|
|
2738
|
+
context: {
|
|
2739
|
+
isContextualEditing: pageState.compositionState === CANVAS_EDITOR_STATE,
|
|
2740
|
+
_id: composition._id,
|
|
2741
|
+
state: pageState.compositionState,
|
|
2742
|
+
type: composition.type,
|
|
2743
|
+
pageState,
|
|
2744
|
+
matchedRoute: compositionContext.matchedRoute,
|
|
2745
|
+
dynamicInputs: compositionContext.dynamicInputs
|
|
2746
|
+
}
|
|
2747
|
+
};
|
|
2748
|
+
return componentProps;
|
|
2749
|
+
};
|
|
2750
|
+
var createPersonalizeComponentProps = ({
|
|
2751
|
+
common,
|
|
2752
|
+
componentId,
|
|
2753
|
+
pageState
|
|
2754
|
+
}) => {
|
|
2755
|
+
var _a;
|
|
2756
|
+
const component = (0, import_next_app_router_shared2.resolveComponentFromPageState)({
|
|
2757
|
+
pageState,
|
|
2758
|
+
componentId
|
|
2759
|
+
});
|
|
2760
|
+
return {
|
|
2761
|
+
...common,
|
|
2762
|
+
indexes: (_a = component == null ? void 0 : component.indexes) != null ? _a : []
|
|
2763
|
+
};
|
|
2764
|
+
};
|
|
2765
|
+
var createTestComponentProps = ({
|
|
2766
|
+
common,
|
|
2767
|
+
componentId,
|
|
2768
|
+
pageState,
|
|
2769
|
+
test
|
|
2770
|
+
}) => {
|
|
2771
|
+
var _a;
|
|
2772
|
+
const component = (0, import_next_app_router_shared2.resolveComponentFromPageState)({
|
|
2773
|
+
pageState,
|
|
2774
|
+
componentId
|
|
2775
|
+
});
|
|
2776
|
+
const [testIndex] = (_a = component == null ? void 0 : component.indexes) != null ? _a : [];
|
|
2777
|
+
return {
|
|
2778
|
+
...common,
|
|
2779
|
+
index: testIndex != null ? testIndex : 0,
|
|
2780
|
+
test
|
|
2781
|
+
};
|
|
2782
|
+
};
|
|
2783
|
+
|
|
2784
|
+
// src/components/helpers/applyEditableParameters.ts
|
|
2785
|
+
var applyEditableParameters = ({
|
|
2786
|
+
composition,
|
|
2787
|
+
state
|
|
2788
|
+
}) => {
|
|
2789
|
+
if (state === CANVAS_EDITOR_STATE) {
|
|
2790
|
+
walkNodeTree(composition, (node) => {
|
|
2791
|
+
var _a, _b;
|
|
2792
|
+
if (node.type === "component" && node.node.parameters) {
|
|
2793
|
+
const contextualEditing = node.node.parameters[CANVAS_CONTEXTUAL_EDITING_PARAM];
|
|
2794
|
+
const editableFields = (_b = (_a = contextualEditing == null ? void 0 : contextualEditing.value) == null ? void 0 : _a.editableParameters) != null ? _b : [];
|
|
2795
|
+
Object.keys(node.node.parameters).forEach((key) => {
|
|
2796
|
+
const parameter = node.node.parameters[key];
|
|
2797
|
+
if (parameter.type === "text") {
|
|
2798
|
+
const contextualParameter = parameter;
|
|
2799
|
+
contextualParameter._contextualEditing = {
|
|
2800
|
+
isEditable: editableFields.includes(key)
|
|
2801
|
+
};
|
|
2802
|
+
}
|
|
2803
|
+
});
|
|
2804
|
+
}
|
|
2805
|
+
});
|
|
2806
|
+
}
|
|
2807
|
+
};
|
|
2808
|
+
|
|
2809
|
+
// src/components/Test.tsx
|
|
2810
|
+
var import_react2 = require("react");
|
|
2811
|
+
|
|
2812
|
+
// src/components/ContextTestTransfer.tsx
|
|
2813
|
+
var import_next_app_router_client = require("@uniformdev/next-app-router-client");
|
|
2814
|
+
var import_react = __toESM(require("react"));
|
|
2815
|
+
var ContextTestTransfer = ({ event }) => {
|
|
2816
|
+
return /* @__PURE__ */ import_react.default.createElement(import_next_app_router_client.ClientContextTestTransfer, { event });
|
|
2817
|
+
};
|
|
2818
|
+
|
|
2819
|
+
// src/components/Test.tsx
|
|
2820
|
+
var Test = ({ index, slots, test, component, context: compositionContext }) => {
|
|
2821
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2822
|
+
const indexToShow = typeof index === "number" ? (_b = (_a = slots == null ? void 0 : slots[CANVAS_TEST_SLOT]) == null ? void 0 : _a.items[index]) != null ? _b : null : null;
|
|
2823
|
+
const event = {
|
|
2824
|
+
name: test.name,
|
|
2825
|
+
// todo: add Control Group support
|
|
2826
|
+
control: (_d = (_c = test.variations[index]) == null ? void 0 : _c.control) != null ? _d : false,
|
|
2827
|
+
variantAssigned: true,
|
|
2828
|
+
variantId: (_f = (_e = test.variations[index]) == null ? void 0 : _e.id) != null ? _f : "NO_VARIANTS",
|
|
2829
|
+
compositionMetadata: {
|
|
2830
|
+
compositionId: compositionContext._id,
|
|
2831
|
+
matchedRoute: compositionContext.matchedRoute,
|
|
2832
|
+
dynamicInputs: compositionContext.dynamicInputs
|
|
2833
|
+
}
|
|
2834
|
+
};
|
|
2835
|
+
const eventElement = (0, import_react2.createElement)(ContextTestTransfer, {
|
|
2836
|
+
event,
|
|
2837
|
+
key: `${component.slotName}-${component.slotIndex}-server-transfer`
|
|
2838
|
+
});
|
|
2839
|
+
return (0, import_react2.createElement)(import_react2.Fragment, void 0, [indexToShow == null ? void 0 : indexToShow.component, eventElement]);
|
|
2840
|
+
};
|
|
2841
|
+
|
|
2842
|
+
// src/components/UniformCompositionWrapper.tsx
|
|
2843
|
+
var import_next_app_router_shared3 = require("@uniformdev/next-app-router-shared");
|
|
2844
|
+
var import_react3 = __toESM(require("react"));
|
|
2845
|
+
var UniformCompositionWrapper = ({
|
|
2846
|
+
code,
|
|
2847
|
+
children
|
|
2848
|
+
}) => {
|
|
2849
|
+
const data = (0, import_next_app_router_shared3.deserializeEvaluationResult)({ input: code });
|
|
2850
|
+
const WrapperComponent = data.compositionState === CANVAS_EDITOR_STATE || data.compositionState === CANVAS_DRAFT_STATE ? import_react3.Suspense : import_react3.Fragment;
|
|
2851
|
+
return /* @__PURE__ */ import_react3.default.createElement(WrapperComponent, null, children);
|
|
2852
|
+
};
|
|
2853
|
+
|
|
2854
|
+
// src/components/UniformContext.tsx
|
|
2855
|
+
var import_next_app_router_client2 = require("@uniformdev/next-app-router-client");
|
|
2856
|
+
var import_react4 = __toESM(require("react"));
|
|
2857
|
+
var UniformContext = async ({ clientContextComponent, result }) => {
|
|
2858
|
+
var _a, _b, _c, _d;
|
|
2859
|
+
const manifest = await getManifest({
|
|
2860
|
+
state: CANVAS_PUBLISHED_STATE
|
|
2861
|
+
});
|
|
2862
|
+
const { route } = result != null ? result : {};
|
|
2863
|
+
const compositionMetadata = route ? {
|
|
2864
|
+
compositionId: route.compositionApiResponse.composition._id,
|
|
2865
|
+
dynamicInputs: route.dynamicInputs,
|
|
2866
|
+
matchedRoute: route.matchedRoute
|
|
2867
|
+
} : void 0;
|
|
2868
|
+
const ContextComponent = clientContextComponent || import_next_app_router_client2.DefaultUniformClientContext;
|
|
2869
|
+
const serverConfig2 = getServerConfig();
|
|
2870
|
+
const disableDevTools = ((_a = serverConfig2.context) == null ? void 0 : _a.disableDevTools) || false;
|
|
2871
|
+
const defaultConsent = (_c = (_b = result == null ? void 0 : result.pageState.defaultConsent) != null ? _b : serverConfig2.defaultConsent) != null ? _c : false;
|
|
2872
|
+
const experimentalQuirkSerialization = ((_d = serverConfig2.experimental) == null ? void 0 : _d.quirkSerialization) || false;
|
|
2873
|
+
return /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, /* @__PURE__ */ import_react4.default.createElement(
|
|
2874
|
+
ContextComponent,
|
|
2875
|
+
{
|
|
2876
|
+
manifest,
|
|
2877
|
+
disableDevTools,
|
|
2878
|
+
defaultConsent,
|
|
2879
|
+
experimentalQuirkSerialization,
|
|
2880
|
+
compositionMetadata
|
|
2881
|
+
}
|
|
2882
|
+
));
|
|
2883
|
+
};
|
|
2884
|
+
|
|
2885
|
+
// src/components/VisibilityRulesWrapper.tsx
|
|
2886
|
+
var import_next_app_router_client3 = require("@uniformdev/next-app-router-client");
|
|
2887
|
+
var import_react5 = __toESM(require("react"));
|
|
2888
|
+
var VisibilityRulesWrapper = ({
|
|
2889
|
+
parameter,
|
|
2890
|
+
initialIsVisible,
|
|
2891
|
+
children
|
|
2892
|
+
}) => {
|
|
2893
|
+
return /* @__PURE__ */ import_react5.default.createElement(import_next_app_router_client3.VisibilityRulesWrapperClient, { parameter, initialIsVisible }, children);
|
|
2894
|
+
};
|
|
2895
|
+
|
|
2896
|
+
// src/components/UniformComposition.tsx
|
|
2897
|
+
function UniformComposition({ code, ...props }) {
|
|
2898
|
+
return /* @__PURE__ */ import_react6.default.createElement(UniformCompositionWrapper, { code }, /* @__PURE__ */ import_react6.default.createElement(UniformCompositionInner, { code, ...props }));
|
|
2899
|
+
}
|
|
2900
|
+
async function UniformCompositionInner({
|
|
2901
|
+
code,
|
|
2902
|
+
resolveRoute,
|
|
2903
|
+
resolveComponent,
|
|
2904
|
+
resolveEmptyPlaceholder,
|
|
2905
|
+
compositionCache,
|
|
2906
|
+
clientContextComponent
|
|
2907
|
+
}) {
|
|
2908
|
+
var _a, _b;
|
|
2909
|
+
const result = await resolveRoute({
|
|
2910
|
+
params: Promise.resolve({ code })
|
|
2911
|
+
});
|
|
2912
|
+
if (!(result == null ? void 0 : result.route) || ((_a = result == null ? void 0 : result.route) == null ? void 0 : _a.type) !== "composition") {
|
|
2913
|
+
(0, import_navigation.notFound)();
|
|
2914
|
+
}
|
|
2915
|
+
const { pageState, route } = result;
|
|
2916
|
+
const composition = result.route.compositionApiResponse.composition;
|
|
2917
|
+
applyEditableParameters({
|
|
2918
|
+
composition,
|
|
2919
|
+
state: route.compositionApiResponse.state
|
|
2920
|
+
});
|
|
2921
|
+
compositionCache == null ? void 0 : compositionCache.setUniformComposition(composition);
|
|
2922
|
+
const compositionContext = {
|
|
2923
|
+
_id: composition._id,
|
|
2924
|
+
type: composition.type,
|
|
2925
|
+
state: pageState.compositionState,
|
|
2926
|
+
isContextualEditing: pageState.compositionState === CANVAS_EDITOR_STATE,
|
|
2927
|
+
matchedRoute: route.matchedRoute,
|
|
2928
|
+
dynamicInputs: (_b = route.dynamicInputs) != null ? _b : {},
|
|
2929
|
+
pageState
|
|
2930
|
+
};
|
|
2931
|
+
const [resolved] = resolveComponents({
|
|
2932
|
+
target: {
|
|
2933
|
+
type: "root",
|
|
2934
|
+
composition
|
|
2935
|
+
},
|
|
2936
|
+
pageState,
|
|
2937
|
+
slotName: void 0,
|
|
2938
|
+
slotIndex: void 0,
|
|
2939
|
+
resolveComponent,
|
|
2940
|
+
resolveEmptyPlaceholder,
|
|
2941
|
+
composition,
|
|
2942
|
+
compositionContext
|
|
2943
|
+
});
|
|
2944
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react6.default.Fragment, null, resolved, /* @__PURE__ */ import_react6.default.createElement(import_react6.Suspense, null, /* @__PURE__ */ import_react6.default.createElement(
|
|
2945
|
+
UniformContext,
|
|
2946
|
+
{
|
|
2947
|
+
clientContextComponent,
|
|
2948
|
+
result: {
|
|
2949
|
+
code,
|
|
2950
|
+
pageState,
|
|
2951
|
+
route
|
|
2952
|
+
}
|
|
2953
|
+
}
|
|
2954
|
+
)), (pageState.compositionState === CANVAS_EDITOR_STATE || pageState.compositionState === CANVAS_DRAFT_STATE) && /* @__PURE__ */ import_react6.default.createElement(import_next_app_router_client4.UniformScript, null));
|
|
2955
|
+
}
|
|
2956
|
+
var resolveComponents = ({
|
|
2957
|
+
target,
|
|
2958
|
+
pageState,
|
|
2959
|
+
slotName,
|
|
2960
|
+
slotIndex,
|
|
2961
|
+
resolveComponent,
|
|
2962
|
+
resolveEmptyPlaceholder,
|
|
2963
|
+
composition,
|
|
2964
|
+
compositionContext
|
|
2965
|
+
}) => {
|
|
2966
|
+
const isRoot = !slotName && typeof slotIndex !== "number";
|
|
2967
|
+
let root;
|
|
2968
|
+
let parent = void 0;
|
|
2969
|
+
let components;
|
|
2970
|
+
if (target.type === "root") {
|
|
2971
|
+
root = target.composition;
|
|
2972
|
+
components = [target.composition];
|
|
2973
|
+
} else {
|
|
2974
|
+
root = target.root;
|
|
2975
|
+
components = target.components;
|
|
2976
|
+
parent = target.parent;
|
|
2977
|
+
}
|
|
2978
|
+
const resolved = components.map((component, componentIndex) => {
|
|
2979
|
+
var _a, _b, _c;
|
|
2980
|
+
const isPlaceholder = isComponentPlaceholderId(component == null ? void 0 : component._id);
|
|
2981
|
+
let resolveResult = null;
|
|
2982
|
+
if (isPlaceholder && resolveEmptyPlaceholder) {
|
|
2983
|
+
const resolvedPlaceholder = resolveEmptyPlaceholder({
|
|
2984
|
+
parentComponent: parent,
|
|
2985
|
+
component,
|
|
2986
|
+
slotName,
|
|
2987
|
+
slotIndex: componentIndex
|
|
2988
|
+
});
|
|
2989
|
+
if (resolvedPlaceholder) {
|
|
2990
|
+
resolveResult = {
|
|
2991
|
+
component: resolvedPlaceholder.component
|
|
2992
|
+
};
|
|
2993
|
+
}
|
|
2994
|
+
}
|
|
2995
|
+
if (!resolveResult) {
|
|
2996
|
+
resolveResult = resolveComponent({ component });
|
|
2997
|
+
}
|
|
2998
|
+
const { component: resolvedComponent, suspense: componentSuspense } = resolveResult || {
|
|
2999
|
+
component: null
|
|
3000
|
+
};
|
|
3001
|
+
const slots = resolveSlots({
|
|
3002
|
+
component,
|
|
3003
|
+
root,
|
|
3004
|
+
resolveComponent,
|
|
3005
|
+
resolveEmptyPlaceholder,
|
|
3006
|
+
pageState,
|
|
3007
|
+
composition,
|
|
3008
|
+
compositionContext
|
|
3009
|
+
});
|
|
3010
|
+
const wrapInSuspense = componentSuspense;
|
|
3011
|
+
const parameters = (_a = component.parameters) != null ? _a : {};
|
|
3012
|
+
const enrichmentTags = (_b = parameters[CANVAS_ENRICHMENT_TAG_PARAM]) == null ? void 0 : _b.value;
|
|
3013
|
+
const visibilityRules = (_c = parameters[CANVAS_VIZ_CONTROL_PARAM]) == null ? void 0 : _c.value;
|
|
3014
|
+
if (!component._id) {
|
|
3015
|
+
console.warn(`Component ${component.type} has no _id`);
|
|
3016
|
+
}
|
|
3017
|
+
const key = `${slotName}-${componentIndex}-component`;
|
|
3018
|
+
const componentProps = createComponentProps({
|
|
3019
|
+
component,
|
|
3020
|
+
parent: parent != null ? parent : null,
|
|
3021
|
+
isRoot,
|
|
3022
|
+
slotName,
|
|
3023
|
+
slotIndex: isRoot ? void 0 : componentIndex,
|
|
3024
|
+
slots,
|
|
3025
|
+
pageState,
|
|
3026
|
+
composition,
|
|
3027
|
+
compositionContext
|
|
3028
|
+
});
|
|
3029
|
+
let element = null;
|
|
3030
|
+
if (wrapInSuspense) {
|
|
3031
|
+
element = (0, import_react6.createElement)(
|
|
3032
|
+
import_react6.Suspense,
|
|
3033
|
+
{
|
|
3034
|
+
key,
|
|
3035
|
+
fallback: typeof wrapInSuspense === "boolean" || typeof (wrapInSuspense == null ? void 0 : wrapInSuspense.fallback) === "undefined" ? void 0 : (0, import_react6.createElement)(wrapInSuspense.fallback)
|
|
3036
|
+
},
|
|
3037
|
+
createResolvedComponent({ component, props: componentProps, resolvedComponent, pageState })
|
|
3038
|
+
);
|
|
3039
|
+
} else {
|
|
3040
|
+
element = createResolvedComponent({
|
|
3041
|
+
component,
|
|
3042
|
+
props: componentProps,
|
|
3043
|
+
resolvedComponent,
|
|
3044
|
+
pageState,
|
|
3045
|
+
key
|
|
3046
|
+
});
|
|
3047
|
+
}
|
|
3048
|
+
let tagElement = null;
|
|
3049
|
+
if (enrichmentTags == null ? void 0 : enrichmentTags.length) {
|
|
3050
|
+
tagElement = (0, import_react6.createElement)(import_next_app_router_client4.ContextUpdateTransfer, {
|
|
3051
|
+
key: `${slotName}-${componentIndex}-tags`,
|
|
3052
|
+
update: {
|
|
3053
|
+
enrichments: enrichmentTags
|
|
3054
|
+
}
|
|
3055
|
+
});
|
|
3056
|
+
}
|
|
3057
|
+
let childNode;
|
|
3058
|
+
if (pageState.compositionState === CANVAS_EDITOR_STATE) {
|
|
3059
|
+
const elements = [element];
|
|
3060
|
+
if (tagElement) {
|
|
3061
|
+
elements.push(tagElement);
|
|
3062
|
+
}
|
|
3063
|
+
const isPlaceholder2 = isComponentPlaceholderId(component == null ? void 0 : component._id);
|
|
3064
|
+
if (!isPlaceholder2 || pageState.compositionState === CANVAS_EDITOR_STATE) {
|
|
3065
|
+
childNode = (0, import_react6.createElement)(
|
|
3066
|
+
import_core.PureContextualEditingComponentWrapper,
|
|
3067
|
+
{
|
|
3068
|
+
key: `${slotName}-${componentIndex}-wrapper`,
|
|
3069
|
+
isPlaceholder: isPlaceholder2,
|
|
3070
|
+
parentComponent: parent,
|
|
3071
|
+
component,
|
|
3072
|
+
slotName,
|
|
3073
|
+
indexInSlot: componentIndex,
|
|
3074
|
+
slotChildrenCount: components.length,
|
|
3075
|
+
isReadOnly: "false"
|
|
3076
|
+
},
|
|
3077
|
+
elements
|
|
3078
|
+
);
|
|
3079
|
+
}
|
|
3080
|
+
} else {
|
|
3081
|
+
const elements = [element];
|
|
3082
|
+
if (tagElement) {
|
|
3083
|
+
elements.push(tagElement);
|
|
3084
|
+
}
|
|
3085
|
+
childNode = elements;
|
|
3086
|
+
}
|
|
3087
|
+
if (visibilityRules) {
|
|
3088
|
+
const isVisible = (0, import_next_app_router_shared4.resolveRuleFromPageState)({
|
|
3089
|
+
pageState,
|
|
3090
|
+
rule: visibilityRules
|
|
3091
|
+
});
|
|
3092
|
+
childNode = (0, import_react6.createElement)(
|
|
3093
|
+
VisibilityRulesWrapper,
|
|
3094
|
+
{
|
|
3095
|
+
key: `${slotName}-${componentIndex}-visibility`,
|
|
3096
|
+
parameter: visibilityRules,
|
|
3097
|
+
initialIsVisible: isVisible != null ? isVisible : null
|
|
3098
|
+
},
|
|
3099
|
+
childNode
|
|
3100
|
+
);
|
|
3101
|
+
}
|
|
3102
|
+
return (0, import_react6.createElement)(
|
|
3103
|
+
import_react6.Fragment,
|
|
3104
|
+
{
|
|
3105
|
+
key: !isRoot ? `${slotName}-${componentIndex}` : void 0
|
|
3106
|
+
},
|
|
3107
|
+
childNode
|
|
3108
|
+
);
|
|
3109
|
+
});
|
|
3110
|
+
return resolved;
|
|
3111
|
+
};
|
|
3112
|
+
var createResolvedComponent = ({
|
|
3113
|
+
component,
|
|
3114
|
+
props,
|
|
3115
|
+
resolvedComponent,
|
|
3116
|
+
pageState,
|
|
3117
|
+
key
|
|
3118
|
+
}) => {
|
|
3119
|
+
if (component.type === CANVAS_PERSONALIZE_TYPE) {
|
|
3120
|
+
const personalizeProps = createPersonalizeComponentProps({
|
|
3121
|
+
common: props,
|
|
3122
|
+
componentId: component._id,
|
|
3123
|
+
pageState
|
|
3124
|
+
});
|
|
3125
|
+
return (0, import_react6.createElement)(import_next_app_router_client4.Personalize, { ...personalizeProps, key });
|
|
3126
|
+
}
|
|
3127
|
+
if (component.type === CANVAS_TEST_TYPE) {
|
|
3128
|
+
const extractedTest = extractTest({
|
|
3129
|
+
component
|
|
3130
|
+
});
|
|
3131
|
+
const testProps = createTestComponentProps({
|
|
3132
|
+
common: props,
|
|
3133
|
+
componentId: component._id,
|
|
3134
|
+
pageState,
|
|
3135
|
+
test: extractedTest
|
|
3136
|
+
});
|
|
3137
|
+
return (0, import_react6.createElement)(Test, { ...testProps, key });
|
|
3138
|
+
}
|
|
3139
|
+
if (!resolvedComponent) {
|
|
3140
|
+
return null;
|
|
3141
|
+
}
|
|
3142
|
+
return (0, import_react6.createElement)(resolvedComponent, { ...props, key });
|
|
3143
|
+
};
|
|
3144
|
+
var resolveSlots = ({
|
|
3145
|
+
component,
|
|
3146
|
+
root,
|
|
3147
|
+
resolveComponent,
|
|
3148
|
+
resolveEmptyPlaceholder,
|
|
3149
|
+
pageState,
|
|
3150
|
+
composition,
|
|
3151
|
+
compositionContext
|
|
3152
|
+
}) => {
|
|
3153
|
+
const slots = {};
|
|
3154
|
+
if (component.slots) {
|
|
3155
|
+
Object.keys(component.slots).forEach((slotName, slotIndex) => {
|
|
3156
|
+
const components = component.slots[slotName];
|
|
3157
|
+
const resolved = resolveComponents({
|
|
3158
|
+
target: {
|
|
3159
|
+
type: "slot",
|
|
3160
|
+
components,
|
|
3161
|
+
root,
|
|
3162
|
+
parent: component
|
|
3163
|
+
},
|
|
3164
|
+
slotName,
|
|
3165
|
+
slotIndex,
|
|
3166
|
+
resolveComponent,
|
|
3167
|
+
resolveEmptyPlaceholder,
|
|
3168
|
+
pageState,
|
|
3169
|
+
composition,
|
|
3170
|
+
compositionContext
|
|
3171
|
+
});
|
|
3172
|
+
if (resolved) {
|
|
3173
|
+
let variantIds;
|
|
3174
|
+
if (component.type === CANVAS_PERSONALIZE_TYPE) {
|
|
3175
|
+
variantIds = mapSlotToPersonalizedVariations(components).map((v) => v.id);
|
|
3176
|
+
} else if (component.type === CANVAS_TEST_TYPE) {
|
|
3177
|
+
variantIds = mapSlotToTestVariations(components).map((v) => v.id);
|
|
3178
|
+
}
|
|
3179
|
+
slots[slotName] = {
|
|
3180
|
+
name: slotName,
|
|
3181
|
+
items: components.map((component2, index) => {
|
|
3182
|
+
var _a, _b;
|
|
3183
|
+
const item = resolved[index];
|
|
3184
|
+
if (!item) {
|
|
3185
|
+
return null;
|
|
3186
|
+
}
|
|
3187
|
+
const pzCriteria = (_b = (_a = component2.parameters) == null ? void 0 : _a[CANVAS_PERSONALIZATION_PARAM]) == null ? void 0 : _b.value;
|
|
3188
|
+
return {
|
|
3189
|
+
_id: component2._id,
|
|
3190
|
+
variantId: variantIds == null ? void 0 : variantIds[index],
|
|
3191
|
+
[CANVAS_PERSONALIZATION_PARAM]: pzCriteria,
|
|
3192
|
+
component: item
|
|
3193
|
+
};
|
|
3194
|
+
})
|
|
3195
|
+
};
|
|
3196
|
+
}
|
|
3197
|
+
});
|
|
3198
|
+
}
|
|
3199
|
+
return slots;
|
|
3200
|
+
};
|
|
3201
|
+
|
|
3202
|
+
// src/components/UniformPlayground.tsx
|
|
3203
|
+
var import_headers = require("next/headers");
|
|
3204
|
+
var import_react7 = __toESM(require("react"));
|
|
3205
|
+
|
|
3206
|
+
// src/data/resolvePlaygroundRoute.ts
|
|
3207
|
+
var import_next_app_router_shared5 = require("@uniformdev/next-app-router-shared");
|
|
3208
|
+
var resolvePlaygroundRoute = async ({
|
|
3209
|
+
params
|
|
3210
|
+
}) => {
|
|
3211
|
+
const { code } = await params;
|
|
3212
|
+
const pageState = (0, import_next_app_router_shared5.deserializeEvaluationResult)({ input: code });
|
|
3213
|
+
const canvasClient = getCanvasClient({
|
|
3214
|
+
cache: {
|
|
3215
|
+
type: "no-cache"
|
|
3216
|
+
}
|
|
3217
|
+
});
|
|
3218
|
+
let composition = void 0;
|
|
3219
|
+
try {
|
|
3220
|
+
composition = await canvasClient.getCompositionById({
|
|
3221
|
+
compositionId: pageState.routePath,
|
|
3222
|
+
state: pageState.compositionState,
|
|
3223
|
+
withComponentIDs: true
|
|
3224
|
+
});
|
|
3225
|
+
} catch (e) {
|
|
3226
|
+
console.warn(
|
|
3227
|
+
`Failed to get composition ${pageState.routePath} with state ${pageState.compositionState}`,
|
|
3228
|
+
e
|
|
3229
|
+
);
|
|
3230
|
+
}
|
|
3231
|
+
if (!composition) {
|
|
3232
|
+
return {
|
|
3233
|
+
code,
|
|
3234
|
+
pageState,
|
|
3235
|
+
route: void 0
|
|
3236
|
+
};
|
|
3237
|
+
}
|
|
3238
|
+
return {
|
|
3239
|
+
code,
|
|
3240
|
+
pageState,
|
|
3241
|
+
route: {
|
|
3242
|
+
type: "composition",
|
|
3243
|
+
compositionApiResponse: composition,
|
|
3244
|
+
matchedRoute: "composition"
|
|
3245
|
+
}
|
|
3246
|
+
};
|
|
3247
|
+
};
|
|
3248
|
+
|
|
3249
|
+
// src/components/UniformPlayground.tsx
|
|
3250
|
+
var UniformPlayground = async ({ resolveRoute, ...rest }) => {
|
|
3251
|
+
const isDraftMode = (await (0, import_headers.draftMode)()).isEnabled;
|
|
3252
|
+
if (!isDraftMode) {
|
|
3253
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", null, /* @__PURE__ */ import_react7.default.createElement("h1", null, "Playground is only available in draft mode"));
|
|
3254
|
+
}
|
|
3255
|
+
return /* @__PURE__ */ import_react7.default.createElement(UniformComposition, { ...rest, resolveRoute: resolvePlaygroundRoute });
|
|
3256
|
+
};
|
|
3257
|
+
|
|
3258
|
+
// src/components/generateStaticParams.ts
|
|
3259
|
+
var import_next_app_router_shared8 = require("@uniformdev/next-app-router-shared");
|
|
3260
|
+
|
|
3261
|
+
// src/data/extract/extractRunnables.ts
|
|
3262
|
+
var import_next_app_router_shared7 = require("@uniformdev/next-app-router-shared");
|
|
3263
|
+
|
|
3264
|
+
// src/data/extract/extractPersonalization.ts
|
|
3265
|
+
var import_next_app_router_shared6 = require("@uniformdev/next-app-router-shared");
|
|
3266
|
+
var extractPersonalization = ({
|
|
3267
|
+
component
|
|
3268
|
+
}) => {
|
|
3269
|
+
var _a, _b, _c;
|
|
3270
|
+
const trackingEventName = (0, import_next_app_router_shared6.extractPersonalizationName)({ component });
|
|
3271
|
+
const countParameter = (_a = component.parameters) == null ? void 0 : _a.count;
|
|
3272
|
+
const algorithmParameter = (_b = component.parameters) == null ? void 0 : _b.algorithm;
|
|
3273
|
+
const count = countParameter == null ? void 0 : countParameter.value;
|
|
3274
|
+
const algorithm = algorithmParameter == null ? void 0 : algorithmParameter.value;
|
|
3275
|
+
let parsedCount;
|
|
3276
|
+
if (typeof count === "string") {
|
|
3277
|
+
parsedCount = parseInt(count, 10);
|
|
3278
|
+
} else if (typeof count !== "number") {
|
|
3279
|
+
parsedCount = void 0;
|
|
3280
|
+
} else {
|
|
3281
|
+
parsedCount = count || 1;
|
|
3282
|
+
}
|
|
3283
|
+
const slot = ((_c = component.slots) == null ? void 0 : _c[CANVAS_PERSONALIZE_SLOT]) || [];
|
|
3284
|
+
const componentVariations = mapSlotToPersonalizedVariations(
|
|
3285
|
+
slot
|
|
3286
|
+
).map((variant, index) => {
|
|
3287
|
+
const slotComponent = slot[index];
|
|
3288
|
+
if (!slotComponent) {
|
|
3289
|
+
throw new Error(`Slot component not found for index ${index}`);
|
|
3290
|
+
}
|
|
3291
|
+
return {
|
|
3292
|
+
...variant,
|
|
3293
|
+
index,
|
|
3294
|
+
componentId: slotComponent._id
|
|
3295
|
+
};
|
|
3296
|
+
});
|
|
3297
|
+
return {
|
|
3298
|
+
name: trackingEventName,
|
|
3299
|
+
take: parsedCount,
|
|
3300
|
+
variations: componentVariations,
|
|
3301
|
+
algorithm
|
|
3302
|
+
};
|
|
3303
|
+
};
|
|
3304
|
+
|
|
3305
|
+
// src/data/extract/extractRunnables.ts
|
|
3306
|
+
var findAncestorVariant = (ancestorsAndSelf) => {
|
|
3307
|
+
let nodeIndex = -1;
|
|
3308
|
+
for (let i = 1; i < ancestorsAndSelf.length; i++) {
|
|
3309
|
+
const node = ancestorsAndSelf[i];
|
|
3310
|
+
if (node.type === "slot" && (node.parentSlot === CANVAS_PERSONALIZE_SLOT || node.parentSlot === CANVAS_TEST_SLOT)) {
|
|
3311
|
+
nodeIndex = i;
|
|
3312
|
+
break;
|
|
3313
|
+
}
|
|
3314
|
+
}
|
|
3315
|
+
if (nodeIndex !== -1) {
|
|
3316
|
+
const node = ancestorsAndSelf[nodeIndex];
|
|
3317
|
+
return node.node._id;
|
|
3318
|
+
}
|
|
3319
|
+
return void 0;
|
|
3320
|
+
};
|
|
3321
|
+
var extractRunnables = (composition) => {
|
|
3322
|
+
const runnable = [];
|
|
3323
|
+
walkNodeTree(composition, (node) => {
|
|
3324
|
+
var _a, _b;
|
|
3325
|
+
if (node.type === "component") {
|
|
3326
|
+
const component = node.node;
|
|
3327
|
+
const visibilityRules = (_b = (_a = component.parameters) == null ? void 0 : _a[CANVAS_VIZ_CONTROL_PARAM]) == null ? void 0 : _b.value;
|
|
3328
|
+
if (component.type === CANVAS_TEST_TYPE) {
|
|
3329
|
+
const test = extractTest({ component });
|
|
3330
|
+
runnable.push({
|
|
3331
|
+
_id: component._id,
|
|
3332
|
+
variantId: findAncestorVariant(node.ancestorsAndSelf),
|
|
3333
|
+
type: "test",
|
|
3334
|
+
result: test
|
|
3335
|
+
});
|
|
3336
|
+
} else if (component.type === CANVAS_PERSONALIZE_TYPE) {
|
|
3337
|
+
const personalize = extractPersonalization({ component });
|
|
3338
|
+
runnable.push({
|
|
3339
|
+
type: "personalization",
|
|
3340
|
+
variantId: findAncestorVariant(node.ancestorsAndSelf),
|
|
3341
|
+
_id: component._id,
|
|
3342
|
+
result: personalize
|
|
3343
|
+
});
|
|
3344
|
+
}
|
|
3345
|
+
if (visibilityRules) {
|
|
3346
|
+
runnable.push({
|
|
3347
|
+
type: "visibility",
|
|
3348
|
+
_id: (0, import_next_app_router_shared7.getRuleId)(visibilityRules),
|
|
3349
|
+
variantId: findAncestorVariant(node.ancestorsAndSelf),
|
|
3350
|
+
rules: visibilityRules
|
|
3351
|
+
});
|
|
3352
|
+
}
|
|
3353
|
+
}
|
|
3354
|
+
});
|
|
3355
|
+
return runnable;
|
|
3356
|
+
};
|
|
3357
|
+
|
|
3358
|
+
// src/components/generateStaticParams.ts
|
|
3359
|
+
var createUniformPlaygroundStaticParams = async (options) => {
|
|
3360
|
+
var _a;
|
|
3361
|
+
const { paths } = options;
|
|
3362
|
+
const [firstPath] = paths;
|
|
3363
|
+
if (!firstPath) {
|
|
3364
|
+
throw new Error("At least one path is required.");
|
|
3365
|
+
}
|
|
3366
|
+
const possibleStates = [CANVAS_EDITOR_STATE, CANVAS_DRAFT_STATE];
|
|
3367
|
+
let route = void 0;
|
|
3368
|
+
for (const state of possibleStates) {
|
|
3369
|
+
const routeClient = getRouteClient({
|
|
3370
|
+
state
|
|
3371
|
+
});
|
|
3372
|
+
route = await routeClient.getRoute({
|
|
3373
|
+
path: firstPath,
|
|
3374
|
+
withComponentIDs: true,
|
|
3375
|
+
state: CANVAS_DRAFT_STATE
|
|
3376
|
+
});
|
|
3377
|
+
if (route.type === "composition") {
|
|
3378
|
+
break;
|
|
3379
|
+
}
|
|
3380
|
+
}
|
|
3381
|
+
if ((route == null ? void 0 : route.type) !== "composition") {
|
|
3382
|
+
throw new Error("No route found for the given path.");
|
|
3383
|
+
}
|
|
3384
|
+
const runnables = extractRunnables(route.compositionApiResponse.composition);
|
|
3385
|
+
const choices = generatePossiblePageStates({
|
|
3386
|
+
runnables,
|
|
3387
|
+
path: route.compositionApiResponse.composition._id,
|
|
3388
|
+
keys: void 0,
|
|
3389
|
+
state: route.compositionApiResponse.state
|
|
3390
|
+
});
|
|
3391
|
+
return (_a = choices == null ? void 0 : choices.map((code) => {
|
|
3392
|
+
return {
|
|
3393
|
+
code
|
|
3394
|
+
};
|
|
3395
|
+
})) != null ? _a : [];
|
|
3396
|
+
};
|
|
3397
|
+
var createUniformStaticParams = async (options) => {
|
|
3398
|
+
var _a;
|
|
3399
|
+
const { paths, rewrite } = options;
|
|
3400
|
+
const codes = [];
|
|
3401
|
+
for (const path of paths) {
|
|
3402
|
+
const pageStates = await processRoutePath({ path, rewrite });
|
|
3403
|
+
if (pageStates) {
|
|
3404
|
+
codes.push(...pageStates);
|
|
3405
|
+
}
|
|
3406
|
+
}
|
|
3407
|
+
return (_a = codes == null ? void 0 : codes.map((code) => {
|
|
3408
|
+
return {
|
|
3409
|
+
code
|
|
3410
|
+
};
|
|
3411
|
+
})) != null ? _a : [];
|
|
3412
|
+
};
|
|
3413
|
+
async function processRoutePath({
|
|
3414
|
+
path,
|
|
3415
|
+
rewrite
|
|
3416
|
+
}) {
|
|
3417
|
+
var _a;
|
|
3418
|
+
const routeClient = getRouteClient({
|
|
3419
|
+
state: CANVAS_PUBLISHED_STATE
|
|
3420
|
+
});
|
|
3421
|
+
const rewrittenPath = await (rewrite == null ? void 0 : rewrite({ path }));
|
|
3422
|
+
const resolvedPath = (_a = rewrittenPath == null ? void 0 : rewrittenPath.path) != null ? _a : path;
|
|
3423
|
+
const route = await routeClient.getRoute({
|
|
3424
|
+
path: resolvedPath,
|
|
3425
|
+
withComponentIDs: true,
|
|
3426
|
+
state: CANVAS_PUBLISHED_STATE
|
|
3427
|
+
});
|
|
3428
|
+
if (route.type !== "composition") {
|
|
3429
|
+
return void 0;
|
|
3430
|
+
}
|
|
3431
|
+
const runnables = extractRunnables(route.compositionApiResponse.composition);
|
|
3432
|
+
const choices = generatePossiblePageStates({
|
|
3433
|
+
runnables,
|
|
3434
|
+
path: resolvedPath,
|
|
3435
|
+
keys: rewrittenPath == null ? void 0 : rewrittenPath.keys,
|
|
3436
|
+
state: CANVAS_PUBLISHED_STATE
|
|
3437
|
+
});
|
|
3438
|
+
return choices;
|
|
3439
|
+
}
|
|
3440
|
+
var buildDependencyMap = (runnables) => {
|
|
3441
|
+
var _a;
|
|
3442
|
+
const map = /* @__PURE__ */ new Map();
|
|
3443
|
+
for (const runnable of runnables) {
|
|
3444
|
+
const deps = (_a = map.get(runnable.variantId)) != null ? _a : [];
|
|
3445
|
+
deps.push(runnable);
|
|
3446
|
+
map.set(runnable.variantId, deps);
|
|
3447
|
+
}
|
|
3448
|
+
return map;
|
|
3449
|
+
};
|
|
3450
|
+
var runnablesToGroups = (runnables) => {
|
|
3451
|
+
var _a;
|
|
3452
|
+
const groups = [];
|
|
3453
|
+
for (const runnable of runnables) {
|
|
3454
|
+
if (runnable.type === "visibility") {
|
|
3455
|
+
groups.push({
|
|
3456
|
+
_id: runnable._id,
|
|
3457
|
+
optionType: "visibility",
|
|
3458
|
+
select: 1,
|
|
3459
|
+
options: [true, false]
|
|
3460
|
+
});
|
|
3461
|
+
} else if (runnable.type === "test") {
|
|
3462
|
+
groups.push({
|
|
3463
|
+
_id: runnable._id,
|
|
3464
|
+
optionType: "indexes",
|
|
3465
|
+
select: 1,
|
|
3466
|
+
options: runnable.result.variations.map((variation, index) => ({
|
|
3467
|
+
variantId: variation.componentId,
|
|
3468
|
+
index
|
|
3469
|
+
}))
|
|
3470
|
+
});
|
|
3471
|
+
} else if (runnable.type === "personalization") {
|
|
3472
|
+
const options = [];
|
|
3473
|
+
let index = 0;
|
|
3474
|
+
for (const variation of runnable.result.variations) {
|
|
3475
|
+
options.push({
|
|
3476
|
+
variantId: variation.componentId,
|
|
3477
|
+
index
|
|
3478
|
+
});
|
|
3479
|
+
index++;
|
|
3480
|
+
}
|
|
3481
|
+
groups.push({
|
|
3482
|
+
_id: runnable._id,
|
|
3483
|
+
optionType: "indexes",
|
|
3484
|
+
select: (_a = runnable.result.take) != null ? _a : 1,
|
|
3485
|
+
options
|
|
3486
|
+
});
|
|
3487
|
+
}
|
|
3488
|
+
}
|
|
3489
|
+
return groups;
|
|
3490
|
+
};
|
|
3491
|
+
var extractSelectedVariantIds = (groups, permutation) => {
|
|
3492
|
+
const variantIds = [];
|
|
3493
|
+
for (let i = 0; i < groups.length; i++) {
|
|
3494
|
+
const group = groups[i];
|
|
3495
|
+
const choices = permutation[i];
|
|
3496
|
+
if (group.optionType === "indexes") {
|
|
3497
|
+
for (const choice of choices) {
|
|
3498
|
+
variantIds.push(choice.variantId);
|
|
3499
|
+
}
|
|
3500
|
+
}
|
|
3501
|
+
}
|
|
3502
|
+
return variantIds;
|
|
3503
|
+
};
|
|
3504
|
+
var applyChoicesToPageState = (state, groups, permutation) => {
|
|
3505
|
+
var _a;
|
|
3506
|
+
const newState = {
|
|
3507
|
+
...state,
|
|
3508
|
+
components: { ...state.components },
|
|
3509
|
+
rules: state.rules ? { ...state.rules } : void 0
|
|
3510
|
+
};
|
|
3511
|
+
for (let i = 0; i < permutation.length; i++) {
|
|
3512
|
+
const group = groups[i];
|
|
3513
|
+
const choices = permutation[i];
|
|
3514
|
+
if (group.optionType === "indexes") {
|
|
3515
|
+
newState.components[group._id] = {
|
|
3516
|
+
indexes: choices.map((v) => v.index)
|
|
3517
|
+
};
|
|
3518
|
+
} else if (group.optionType === "visibility" && typeof choices[0] === "boolean") {
|
|
3519
|
+
newState.rules = (_a = newState.rules) != null ? _a : {};
|
|
3520
|
+
newState.rules[group._id] = choices[0];
|
|
3521
|
+
}
|
|
3522
|
+
}
|
|
3523
|
+
return newState;
|
|
3524
|
+
};
|
|
3525
|
+
var generateStatesRecursively = (dependencyMap, parentVariantId, currentState) => {
|
|
3526
|
+
var _a;
|
|
3527
|
+
const runnables = (_a = dependencyMap.get(parentVariantId)) != null ? _a : [];
|
|
3528
|
+
if (runnables.length === 0) {
|
|
3529
|
+
return [currentState];
|
|
3530
|
+
}
|
|
3531
|
+
const groups = runnablesToGroups(runnables);
|
|
3532
|
+
const permutations = generateAllGroupPermutations(groups);
|
|
3533
|
+
const results = [];
|
|
3534
|
+
for (const permutation of permutations) {
|
|
3535
|
+
const mergedState = applyChoicesToPageState(currentState, groups, permutation);
|
|
3536
|
+
const selectedVariantIds = extractSelectedVariantIds(groups, permutation);
|
|
3537
|
+
let subResults = [mergedState];
|
|
3538
|
+
for (const variantId of selectedVariantIds) {
|
|
3539
|
+
if (dependencyMap.has(variantId)) {
|
|
3540
|
+
subResults = subResults.flatMap(
|
|
3541
|
+
(state) => generateStatesRecursively(dependencyMap, variantId, state)
|
|
3542
|
+
);
|
|
3543
|
+
}
|
|
3544
|
+
}
|
|
3545
|
+
results.push(...subResults);
|
|
3546
|
+
}
|
|
3547
|
+
return results;
|
|
3548
|
+
};
|
|
3549
|
+
var generatePossiblePageStates = ({
|
|
3550
|
+
runnables,
|
|
3551
|
+
path,
|
|
3552
|
+
keys,
|
|
3553
|
+
state
|
|
3554
|
+
}) => {
|
|
3555
|
+
const dependencyMap = buildDependencyMap(runnables);
|
|
3556
|
+
const initialState = {
|
|
3557
|
+
compositionState: state,
|
|
3558
|
+
keys,
|
|
3559
|
+
releaseId: void 0,
|
|
3560
|
+
routePath: path,
|
|
3561
|
+
components: {},
|
|
3562
|
+
defaultConsent: void 0,
|
|
3563
|
+
previewMode: void 0,
|
|
3564
|
+
rules: void 0
|
|
3565
|
+
};
|
|
3566
|
+
const allStates = generateStatesRecursively(dependencyMap, void 0, initialState);
|
|
3567
|
+
return allStates.map((payload) => (0, import_next_app_router_shared8.serializeEvaluationResult)({ payload }));
|
|
3568
|
+
};
|
|
3569
|
+
function permutationsWithoutRepetition(options, k) {
|
|
3570
|
+
if (k === 0) return [[]];
|
|
3571
|
+
if (k > options.length) return [];
|
|
3572
|
+
const results = [];
|
|
3573
|
+
const used = new Array(options.length).fill(false);
|
|
3574
|
+
const current = [];
|
|
3575
|
+
function backtrack() {
|
|
3576
|
+
if (current.length === k) {
|
|
3577
|
+
results.push(current.slice());
|
|
3578
|
+
return;
|
|
3579
|
+
}
|
|
3580
|
+
for (let i = 0; i < options.length; i++) {
|
|
3581
|
+
if (used[i]) continue;
|
|
3582
|
+
used[i] = true;
|
|
3583
|
+
current.push(options[i]);
|
|
3584
|
+
backtrack();
|
|
3585
|
+
current.pop();
|
|
3586
|
+
used[i] = false;
|
|
3587
|
+
}
|
|
3588
|
+
}
|
|
3589
|
+
backtrack();
|
|
3590
|
+
return results;
|
|
3591
|
+
}
|
|
3592
|
+
function combineAcrossGroups(perGroupSelections) {
|
|
3593
|
+
return perGroupSelections.reduce(
|
|
3594
|
+
(acc, group) => acc.flatMap((config) => group.map((selection) => [...config, selection])),
|
|
3595
|
+
[[]]
|
|
3596
|
+
);
|
|
3597
|
+
}
|
|
3598
|
+
function generateAllGroupPermutations(groups) {
|
|
3599
|
+
const perGroupSelections = groups.map((g) => permutationsWithoutRepetition(g.options, g.select));
|
|
3600
|
+
return combineAcrossGroups(perGroupSelections);
|
|
3601
|
+
}
|
|
3602
|
+
|
|
3603
|
+
// src/data/client.ts
|
|
3604
|
+
var import_functions = require("@vercel/functions");
|
|
3605
|
+
var MANIFEST_CACHE_KEY = "uniform-manifest";
|
|
3606
|
+
var DefaultDataClient = class {
|
|
3607
|
+
async getManifest(options) {
|
|
3608
|
+
var _a, _b;
|
|
3609
|
+
const cache2 = options.source === "middleware" && ((_b = (_a = getServerConfig().experimental) == null ? void 0 : _a.middlewareRuntimeCache) != null ? _b : false) ? (0, import_functions.getCache)() : null;
|
|
3610
|
+
if (cache2) {
|
|
3611
|
+
const cachedManifest = await cache2.get(MANIFEST_CACHE_KEY);
|
|
3612
|
+
if (cachedManifest) {
|
|
3613
|
+
return cachedManifest;
|
|
3614
|
+
}
|
|
3615
|
+
}
|
|
3616
|
+
const manifest = await getManifest({
|
|
3617
|
+
cache: {
|
|
3618
|
+
type: "force-cache"
|
|
3619
|
+
}
|
|
3620
|
+
});
|
|
3621
|
+
if (cache2) {
|
|
3622
|
+
(0, import_functions.waitUntil)(
|
|
3623
|
+
(async () => {
|
|
3624
|
+
await cache2.set(MANIFEST_CACHE_KEY, manifest, {
|
|
3625
|
+
tags: generateManifestCacheTags()
|
|
3626
|
+
});
|
|
3627
|
+
})()
|
|
3628
|
+
);
|
|
3629
|
+
}
|
|
3630
|
+
return manifest;
|
|
3631
|
+
}
|
|
3632
|
+
async getRouteFromApi({
|
|
3633
|
+
route,
|
|
3634
|
+
routeClient,
|
|
3635
|
+
enableRuntimeCache,
|
|
3636
|
+
disableSwrCache
|
|
3637
|
+
}) {
|
|
3638
|
+
const newCacheKey = `uniform-route-${route.state}-${route.releaseId}-${route.path}`;
|
|
3639
|
+
const oldCacheKey = `uniform-route-old-${route.state}-${route.releaseId}-${route.path}`;
|
|
3640
|
+
const cache2 = enableRuntimeCache ? (0, import_functions.getCache)() : null;
|
|
3641
|
+
const cacheNewRoute = async (result2) => {
|
|
3642
|
+
if (cache2 && result2.type === "composition") {
|
|
3643
|
+
const tags = generateRouteCacheTags({ path: route.path });
|
|
3644
|
+
await cache2.set(newCacheKey, result2, {
|
|
3645
|
+
tags
|
|
3646
|
+
});
|
|
3647
|
+
}
|
|
3648
|
+
};
|
|
3649
|
+
const cacheOldRoute = async (result2) => {
|
|
3650
|
+
if (cache2 && result2.type === "composition" && !disableSwrCache) {
|
|
3651
|
+
const tags = generateRouteCacheTags({ path: route.path, old: true });
|
|
3652
|
+
await cache2.set(oldCacheKey, result2, {
|
|
3653
|
+
tags
|
|
3654
|
+
});
|
|
3655
|
+
}
|
|
3656
|
+
};
|
|
3657
|
+
if (cache2) {
|
|
3658
|
+
const [cachedRoute, oldCachedRoute] = await Promise.all([
|
|
3659
|
+
cache2.get(newCacheKey),
|
|
3660
|
+
disableSwrCache ? null : cache2.get(oldCacheKey)
|
|
3661
|
+
]);
|
|
3662
|
+
if (cachedRoute) {
|
|
3663
|
+
return cachedRoute;
|
|
3664
|
+
}
|
|
3665
|
+
if (oldCachedRoute) {
|
|
3666
|
+
(0, import_functions.waitUntil)(
|
|
3667
|
+
(async () => {
|
|
3668
|
+
const result2 = await routeClient.getRoute(route);
|
|
3669
|
+
await cacheNewRoute(result2);
|
|
3670
|
+
})()
|
|
3671
|
+
);
|
|
3672
|
+
return oldCachedRoute;
|
|
3673
|
+
}
|
|
3674
|
+
}
|
|
3675
|
+
const result = await routeClient.getRoute(route);
|
|
3676
|
+
(0, import_functions.waitUntil)(
|
|
3677
|
+
(async () => {
|
|
3678
|
+
await Promise.all([
|
|
3679
|
+
cacheNewRoute(result),
|
|
3680
|
+
disableSwrCache ? Promise.resolve() : cacheOldRoute(result)
|
|
3681
|
+
]);
|
|
3682
|
+
})()
|
|
3683
|
+
);
|
|
3684
|
+
return result;
|
|
3685
|
+
}
|
|
3686
|
+
async getRoute(options) {
|
|
3687
|
+
if (options.source === "middleware") {
|
|
3688
|
+
return this.getRouteMiddleware(options);
|
|
3689
|
+
}
|
|
3690
|
+
return this.getRoutePageState(options);
|
|
3691
|
+
}
|
|
3692
|
+
async enhanceRoute(_options) {
|
|
3693
|
+
}
|
|
3694
|
+
async getRouteMiddleware(options) {
|
|
3695
|
+
var _a, _b, _c, _d;
|
|
3696
|
+
const routeClient = getRouteClient({
|
|
3697
|
+
searchParams: options.searchParams,
|
|
3698
|
+
draftModeEnabled: options.draftModeEnabled
|
|
3699
|
+
});
|
|
3700
|
+
const config = getServerConfig();
|
|
3701
|
+
const resolvedRoute = await this.getRouteFromApi({
|
|
3702
|
+
source: "middleware",
|
|
3703
|
+
route: options.route,
|
|
3704
|
+
routeClient,
|
|
3705
|
+
enableRuntimeCache: options.route.state === CANVAS_PUBLISHED_STATE && ((_b = (_a = config.experimental) == null ? void 0 : _a.middlewareRuntimeCache) != null ? _b : false),
|
|
3706
|
+
disableSwrCache: (_d = (_c = config.experimental) == null ? void 0 : _c.disableSwrMiddlewareCache) != null ? _d : false
|
|
3707
|
+
});
|
|
3708
|
+
if (resolvedRoute.type === "composition") {
|
|
3709
|
+
await this.enhanceRoute({
|
|
3710
|
+
source: "middleware",
|
|
3711
|
+
parameters: options.route,
|
|
3712
|
+
route: resolvedRoute,
|
|
3713
|
+
routeClient,
|
|
3714
|
+
keys: void 0
|
|
3715
|
+
});
|
|
3716
|
+
}
|
|
3717
|
+
return {
|
|
3718
|
+
route: resolvedRoute
|
|
3719
|
+
};
|
|
3720
|
+
}
|
|
3721
|
+
async getRoutePageState(options) {
|
|
3722
|
+
var _a;
|
|
3723
|
+
const routeClient = getRouteClient({
|
|
3724
|
+
cache: options.pageState.compositionState === CANVAS_PUBLISHED_STATE ? (_a = getServerConfig().canvasCache) != null ? _a : {
|
|
3725
|
+
type: "force-cache"
|
|
3726
|
+
} : {
|
|
3727
|
+
type: "no-cache"
|
|
3728
|
+
}
|
|
3729
|
+
});
|
|
3730
|
+
const originalRoute = {
|
|
3731
|
+
path: options.pageState.routePath,
|
|
3732
|
+
state: options.pageState.compositionState,
|
|
3733
|
+
withComponentIDs: true,
|
|
3734
|
+
releaseId: options.pageState.releaseId
|
|
3735
|
+
};
|
|
3736
|
+
const resolvedRoute = await this.getRouteFromApi({
|
|
3737
|
+
source: "pageState",
|
|
3738
|
+
route: originalRoute,
|
|
3739
|
+
routeClient,
|
|
3740
|
+
enableRuntimeCache: false,
|
|
3741
|
+
disableSwrCache: false
|
|
3742
|
+
});
|
|
3743
|
+
if (resolvedRoute.type === "composition") {
|
|
3744
|
+
await this.enhanceRoute({
|
|
3745
|
+
source: "pageState",
|
|
3746
|
+
parameters: originalRoute,
|
|
3747
|
+
route: resolvedRoute,
|
|
3748
|
+
routeClient,
|
|
3749
|
+
keys: options.pageState.keys
|
|
3750
|
+
});
|
|
3751
|
+
}
|
|
3752
|
+
return {
|
|
3753
|
+
route: resolvedRoute
|
|
3754
|
+
};
|
|
3755
|
+
}
|
|
3756
|
+
};
|
|
3757
|
+
var expireMiddlewareCacheTag = async (tag) => {
|
|
3758
|
+
var _a;
|
|
3759
|
+
const cache2 = ((_a = getServerConfig().experimental) == null ? void 0 : _a.middlewareRuntimeCache) ? (0, import_functions.getCache)() : null;
|
|
3760
|
+
if (cache2) {
|
|
3761
|
+
await cache2.expireTag(tag);
|
|
3762
|
+
} else {
|
|
3763
|
+
console.warn("Middleware cache is not enabled, cannot clear cache tag", tag);
|
|
3764
|
+
}
|
|
3765
|
+
};
|
|
3766
|
+
|
|
3767
|
+
// src/data/precomputeComposition.ts
|
|
3768
|
+
var import_next_app_router_shared9 = require("@uniformdev/next-app-router-shared");
|
|
3769
|
+
var shouldEvaluateTest = (test, evaluateTests) => {
|
|
3770
|
+
return typeof evaluateTests === "function" ? evaluateTests({
|
|
3771
|
+
name: (0, import_next_app_router_shared9.extractTestName)({ component: test }),
|
|
3772
|
+
component: test
|
|
3773
|
+
}) : evaluateTests;
|
|
3774
|
+
};
|
|
3775
|
+
var shouldEvaluatePersonalization = (personalization, evaluatePersonalizations) => {
|
|
3776
|
+
const result = typeof evaluatePersonalizations === "function" ? evaluatePersonalizations({
|
|
3777
|
+
name: (0, import_next_app_router_shared9.extractPersonalizationName)({ component: personalization }),
|
|
3778
|
+
component: personalization
|
|
3779
|
+
}) : evaluatePersonalizations;
|
|
3780
|
+
return result;
|
|
3781
|
+
};
|
|
3782
|
+
var precomputeComposition = ({
|
|
3783
|
+
pageState,
|
|
3784
|
+
route,
|
|
3785
|
+
evaluatePersonalizations = true,
|
|
3786
|
+
evaluateTests = true
|
|
3787
|
+
}) => {
|
|
3788
|
+
if (!route) {
|
|
3789
|
+
return Promise.resolve();
|
|
3790
|
+
}
|
|
3791
|
+
walkNodeTree(route.compositionApiResponse.composition, (node) => {
|
|
3792
|
+
var _a, _b;
|
|
3793
|
+
if (node.type === "component") {
|
|
3794
|
+
const component = node.node;
|
|
3795
|
+
const pageStateComponent = (0, import_next_app_router_shared9.resolveComponentFromPageState)({
|
|
3796
|
+
pageState,
|
|
3797
|
+
componentId: component._id
|
|
3798
|
+
});
|
|
3799
|
+
if (component.type === CANVAS_TEST_TYPE && shouldEvaluateTest(component, evaluateTests)) {
|
|
3800
|
+
const [testIndex] = (pageStateComponent == null ? void 0 : pageStateComponent.indexes) || [];
|
|
3801
|
+
if (typeof testIndex === "undefined") {
|
|
3802
|
+
node.actions.remove();
|
|
3803
|
+
return;
|
|
3804
|
+
}
|
|
3805
|
+
const slotComponents = ((_a = component.slots) == null ? void 0 : _a[CANVAS_TEST_SLOT]) || [];
|
|
3806
|
+
const visibileComponent = slotComponents[testIndex];
|
|
3807
|
+
if (typeof visibileComponent !== "undefined") {
|
|
3808
|
+
node.actions.replace(visibileComponent);
|
|
3809
|
+
} else {
|
|
3810
|
+
node.actions.remove();
|
|
3811
|
+
}
|
|
3812
|
+
} else if (component.type === CANVAS_PERSONALIZE_TYPE && shouldEvaluatePersonalization(component, evaluatePersonalizations)) {
|
|
3813
|
+
const personalizeIndexes = (pageStateComponent == null ? void 0 : pageStateComponent.indexes) || [];
|
|
3814
|
+
if (!(personalizeIndexes == null ? void 0 : personalizeIndexes.length)) {
|
|
3815
|
+
node.actions.remove();
|
|
3816
|
+
return;
|
|
3817
|
+
}
|
|
3818
|
+
const slotComponents = ((_b = component.slots) == null ? void 0 : _b[CANVAS_PERSONALIZE_SLOT]) || [];
|
|
3819
|
+
const visibileComponents = personalizeIndexes.map((index) => slotComponents[index]).filter(Boolean);
|
|
3820
|
+
if (visibileComponents.length) {
|
|
3821
|
+
const [first, ...rest] = visibileComponents;
|
|
3822
|
+
node.actions.replace(first);
|
|
3823
|
+
for (const component2 of rest) {
|
|
3824
|
+
node.actions.insertAfter(component2);
|
|
3825
|
+
}
|
|
3826
|
+
} else {
|
|
3827
|
+
node.actions.remove();
|
|
3828
|
+
}
|
|
3829
|
+
}
|
|
3830
|
+
}
|
|
3831
|
+
});
|
|
3832
|
+
return Promise.resolve();
|
|
3833
|
+
};
|
|
3834
|
+
|
|
3835
|
+
// src/data/resolveRouteFromCode.ts
|
|
3836
|
+
var import_next_app_router_shared10 = require("@uniformdev/next-app-router-shared");
|
|
3837
|
+
var resolveRouteFromCode = async ({
|
|
3838
|
+
params,
|
|
3839
|
+
dataClient: providedDataClient
|
|
3840
|
+
}) => {
|
|
3841
|
+
const { code } = await params;
|
|
3842
|
+
const pageState = (0, import_next_app_router_shared10.deserializeEvaluationResult)({ input: code });
|
|
3843
|
+
const dataClient = providedDataClient != null ? providedDataClient : new DefaultDataClient();
|
|
3844
|
+
const { route } = await dataClient.getRoute({
|
|
3845
|
+
source: "pageState",
|
|
3846
|
+
pageState
|
|
3847
|
+
});
|
|
3848
|
+
return {
|
|
3849
|
+
pageState,
|
|
3850
|
+
// suppress the route if it's not a composition
|
|
3851
|
+
route: (route == null ? void 0 : route.type) === "composition" ? route : void 0,
|
|
3852
|
+
// the code that was used to resolve the route
|
|
3853
|
+
code
|
|
3854
|
+
};
|
|
3855
|
+
};
|
|
3856
|
+
|
|
3857
|
+
// src/data/routes.ts
|
|
3858
|
+
var findRouteMatch = (routes, path) => {
|
|
3859
|
+
const pieces = path.split("/").filter(Boolean);
|
|
3860
|
+
for (const route of routes) {
|
|
3861
|
+
const patternPieces = route.pattern.split("/").filter(Boolean);
|
|
3862
|
+
if (patternPieces.length !== pieces.length) {
|
|
3863
|
+
continue;
|
|
3864
|
+
}
|
|
3865
|
+
let match = true;
|
|
3866
|
+
const params = {};
|
|
3867
|
+
for (let i = 0; i < patternPieces.length; i++) {
|
|
3868
|
+
const patternPiece = patternPieces[i];
|
|
3869
|
+
const piece = pieces[i];
|
|
3870
|
+
if (patternPiece.startsWith(":")) {
|
|
3871
|
+
const paramName = patternPiece.slice(1);
|
|
3872
|
+
params[paramName] = piece;
|
|
3873
|
+
} else if (patternPiece !== piece) {
|
|
3874
|
+
match = false;
|
|
3875
|
+
break;
|
|
3876
|
+
}
|
|
3877
|
+
}
|
|
3878
|
+
if (match) {
|
|
3879
|
+
return {
|
|
3880
|
+
route,
|
|
3881
|
+
params
|
|
3882
|
+
};
|
|
3883
|
+
}
|
|
3884
|
+
}
|
|
3885
|
+
return void 0;
|
|
3886
|
+
};
|
|
3887
|
+
|
|
3888
|
+
// src/cache/helpers.ts
|
|
3889
|
+
var import_react8 = require("react");
|
|
3890
|
+
var serverContext = (defaultValue) => {
|
|
3891
|
+
const getRef = (0, import_react8.cache)(() => ({ current: defaultValue }));
|
|
3892
|
+
const getValue = () => getRef().current;
|
|
3893
|
+
const setValue = (value) => {
|
|
3894
|
+
getRef().current = value;
|
|
3895
|
+
};
|
|
3896
|
+
return [getValue, setValue];
|
|
3897
|
+
};
|
|
3898
|
+
|
|
3899
|
+
// src/cache/composition.ts
|
|
3900
|
+
var createCompositionCache = () => {
|
|
3901
|
+
const [getCompositionInternal, setCompositionInternal] = serverContext({});
|
|
3902
|
+
const getUniformComposition = ({ id }) => {
|
|
3903
|
+
const compositions = getCompositionInternal();
|
|
3904
|
+
if (!compositions) {
|
|
3905
|
+
return null;
|
|
3906
|
+
}
|
|
3907
|
+
return compositions[id];
|
|
3908
|
+
};
|
|
3909
|
+
const setUniformComposition = (composition) => {
|
|
3910
|
+
const compositions = getCompositionInternal();
|
|
3911
|
+
compositions[composition._id] = composition;
|
|
3912
|
+
setCompositionInternal(compositions);
|
|
3913
|
+
};
|
|
3914
|
+
const getUniformComponent = ({ compositionId, componentId }) => {
|
|
3915
|
+
const composition = getUniformComposition({ id: compositionId });
|
|
3916
|
+
if (!composition) {
|
|
3917
|
+
return null;
|
|
3918
|
+
}
|
|
3919
|
+
let component;
|
|
3920
|
+
walkNodeTree(composition, ({ node, actions }) => {
|
|
3921
|
+
if (node._id === componentId) {
|
|
3922
|
+
component = node;
|
|
3923
|
+
actions.stopProcessingDescendants();
|
|
3924
|
+
}
|
|
3925
|
+
});
|
|
3926
|
+
return component != null ? component : null;
|
|
3927
|
+
};
|
|
3928
|
+
return {
|
|
3929
|
+
getUniformComposition,
|
|
3930
|
+
setUniformComposition,
|
|
3931
|
+
getUniformComponent
|
|
3932
|
+
};
|
|
3933
|
+
};
|
|
3934
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
3935
|
+
0 && (module.exports = {
|
|
3936
|
+
DefaultDataClient,
|
|
3937
|
+
UniformComposition,
|
|
3938
|
+
UniformPlayground,
|
|
3939
|
+
createCompositionCache,
|
|
3940
|
+
createUniformPlaygroundStaticParams,
|
|
3941
|
+
createUniformStaticParams,
|
|
3942
|
+
expireMiddlewareCacheTag,
|
|
3943
|
+
findRouteMatch,
|
|
3944
|
+
getCanvasClient,
|
|
3945
|
+
getManifest,
|
|
3946
|
+
getManifestClient,
|
|
3947
|
+
getProjectMapClient,
|
|
3948
|
+
getRouteClient,
|
|
3949
|
+
precomputeComposition,
|
|
3950
|
+
resolvePlaygroundRoute,
|
|
3951
|
+
resolveRouteFromCode,
|
|
3952
|
+
serverContext
|
|
3953
|
+
});
|