@uniformdev/next-app-router 20.80.2 → 20.81.1-alpha.10.sha-def425616f
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/dist/{UniformComposition-DBO-oo7J.d.ts → UniformComposition-ChDH4dMd.d.ts} +12 -31
- package/dist/{UniformComposition-le6UEB_r.d.mts → UniformComposition-Doa1kKRm.d.mts} +12 -31
- package/dist/cache.d.mts +24 -6
- package/dist/cache.d.ts +24 -6
- package/dist/cache.js +396 -832
- package/dist/cache.mjs +391 -830
- package/dist/compat.d.mts +2 -4
- package/dist/compat.d.ts +2 -4
- package/dist/component.d.mts +10 -1
- package/dist/component.d.ts +10 -1
- package/dist/component.js +113 -617
- package/dist/component.mjs +112 -640
- package/dist/composition-CGU7iH-k.d.mts +37 -0
- package/dist/composition-CGU7iH-k.d.ts +37 -0
- package/dist/config/default.js +0 -1
- package/dist/config/default.mjs +0 -1
- package/dist/createCachedManifestProvider-2-2u3PYd.d.mts +84 -0
- package/dist/createCachedManifestProvider-BoorKD15.d.ts +84 -0
- package/dist/edge.d.mts +80 -0
- package/dist/edge.d.ts +80 -0
- package/dist/edge.js +1225 -0
- package/dist/edge.mjs +1191 -0
- package/dist/handler.d.mts +15 -2
- package/dist/handler.d.ts +15 -2
- package/dist/handler.js +134 -628
- package/dist/handler.mjs +132 -626
- package/dist/index.d.mts +81 -41
- package/dist/index.d.ts +81 -41
- package/dist/index.esm.js +2051 -5614
- package/dist/index.js +2092 -5651
- package/dist/index.mjs +2051 -5614
- package/dist/middleware.d.mts +60 -13
- package/dist/middleware.d.ts +60 -13
- package/dist/middleware.js +415 -5746
- package/dist/middleware.mjs +422 -5776
- package/dist/models-C8OdCO44.d.mts +72 -0
- package/dist/models-C8OdCO44.d.ts +72 -0
- package/dist/resolveRouteFromPath-CnfnaxY2.d.ts +80 -0
- package/dist/resolveRouteFromPath-_rauUskz.d.mts +80 -0
- package/dist/vercel.d.mts +37 -0
- package/dist/vercel.d.ts +37 -0
- package/dist/vercel.js +788 -0
- package/dist/vercel.mjs +759 -0
- package/package.json +37 -9
- package/dist/client-BElN_CWD.d.mts +0 -786
- package/dist/client-BElN_CWD.d.ts +0 -786
- package/dist/resolveRouteFromCode-BOvjIvM2.d.ts +0 -18
- package/dist/resolveRouteFromCode-CuJ4JHeb.d.mts +0 -18
package/dist/edge.js
ADDED
|
@@ -0,0 +1,1225 @@
|
|
|
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 __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/edge.ts
|
|
31
|
+
var edge_exports = {};
|
|
32
|
+
__export(edge_exports, {
|
|
33
|
+
UNIFORM_EDGE_ORIGIN_HEADER: () => UNIFORM_EDGE_ORIGIN_HEADER,
|
|
34
|
+
createCachedManifestProvider: () => createCachedManifestProvider,
|
|
35
|
+
createLearnedEdgeRouteFilter: () => createLearnedEdgeRouteFilter,
|
|
36
|
+
createStaticEdgeRouteFilter: () => createStaticEdgeRouteFilter,
|
|
37
|
+
handleUniformEdgeRoute: () => handleUniformEdgeRoute,
|
|
38
|
+
uniformEdgeMiddleware: () => uniformEdgeMiddleware
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(edge_exports);
|
|
41
|
+
|
|
42
|
+
// src/edge/uniformEdgeMiddleware.ts
|
|
43
|
+
var import_context_edge = require("@uniformdev/context-edge");
|
|
44
|
+
var import_server2 = require("next/server");
|
|
45
|
+
|
|
46
|
+
// ../canvas/dist/index.mjs
|
|
47
|
+
var import_api = require("@uniformdev/context/api");
|
|
48
|
+
var import_api2 = require("@uniformdev/context/api");
|
|
49
|
+
var import_api3 = require("@uniformdev/context/api");
|
|
50
|
+
var import_api4 = require("@uniformdev/context/api");
|
|
51
|
+
var import_api5 = require("@uniformdev/context/api");
|
|
52
|
+
var import_api6 = require("@uniformdev/context/api");
|
|
53
|
+
var import_api7 = require("@uniformdev/context/api");
|
|
54
|
+
var import_api8 = require("@uniformdev/context/api");
|
|
55
|
+
var import_api9 = require("@uniformdev/context/api");
|
|
56
|
+
var import_api10 = require("@uniformdev/context/api");
|
|
57
|
+
var import_api11 = require("@uniformdev/context/api");
|
|
58
|
+
var import_api12 = require("@uniformdev/context/api");
|
|
59
|
+
var import_api13 = require("@uniformdev/context/api");
|
|
60
|
+
var import_api14 = require("@uniformdev/context/api");
|
|
61
|
+
var import_api15 = require("@uniformdev/context/api");
|
|
62
|
+
var import_api16 = require("@uniformdev/context/api");
|
|
63
|
+
var import_api17 = require("@uniformdev/context/api");
|
|
64
|
+
var import_api18 = require("@uniformdev/context/api");
|
|
65
|
+
var import_api19 = require("@uniformdev/context/api");
|
|
66
|
+
var import_api20 = require("@uniformdev/context/api");
|
|
67
|
+
var import_api21 = require("@uniformdev/context/api");
|
|
68
|
+
var import_api22 = require("@uniformdev/context/api");
|
|
69
|
+
var import_api23 = require("@uniformdev/context/api");
|
|
70
|
+
var import_api24 = require("@uniformdev/context/api");
|
|
71
|
+
var import_api25 = require("@uniformdev/context/api");
|
|
72
|
+
var import_api26 = require("@uniformdev/context/api");
|
|
73
|
+
var import_api27 = require("@uniformdev/context/api");
|
|
74
|
+
var __typeError = (msg) => {
|
|
75
|
+
throw TypeError(msg);
|
|
76
|
+
};
|
|
77
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
78
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
79
|
+
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);
|
|
80
|
+
var SELECT_QUERY_PREFIX = "select.";
|
|
81
|
+
function appendCsv(out, key, values) {
|
|
82
|
+
if (values === void 0) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
out[key] = values.join(",");
|
|
86
|
+
}
|
|
87
|
+
function projectionToQuery(spec) {
|
|
88
|
+
const out = {};
|
|
89
|
+
if (!spec) {
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
const { fields, fieldTypes, slots } = spec;
|
|
93
|
+
const p = SELECT_QUERY_PREFIX;
|
|
94
|
+
if (fields) {
|
|
95
|
+
appendCsv(out, `${p}fields[only]`, fields.only);
|
|
96
|
+
appendCsv(out, `${p}fields[except]`, fields.except);
|
|
97
|
+
appendCsv(out, `${p}fields[locales]`, fields.locales);
|
|
98
|
+
if (fields.blockDepth === "preserveAll" || typeof fields.blockDepth === "number") {
|
|
99
|
+
out[`${p}fields[blockDepth]`] = String(fields.blockDepth);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (fieldTypes) {
|
|
103
|
+
appendCsv(out, `${p}fieldTypes[only]`, fieldTypes.only);
|
|
104
|
+
appendCsv(out, `${p}fieldTypes[except]`, fieldTypes.except);
|
|
105
|
+
}
|
|
106
|
+
if (slots) {
|
|
107
|
+
appendCsv(out, `${p}slots[only]`, slots.only);
|
|
108
|
+
appendCsv(out, `${p}slots[except]`, slots.except);
|
|
109
|
+
if (typeof slots.depth === "number") {
|
|
110
|
+
out[`${p}slots[depth]`] = String(slots.depth);
|
|
111
|
+
}
|
|
112
|
+
if (slots.named) {
|
|
113
|
+
const slotNames = Object.keys(slots.named).sort();
|
|
114
|
+
for (const slotName of slotNames) {
|
|
115
|
+
const named = slots.named[slotName];
|
|
116
|
+
if (named && typeof named.depth === "number") {
|
|
117
|
+
out[`${p}slots.${slotName}[depth]`] = String(named.depth);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
var CANVAS_DRAFT_STATE = 0;
|
|
125
|
+
var CANVAS_PUBLISHED_STATE = 64;
|
|
126
|
+
var CANVAS_EDITOR_STATE = 63;
|
|
127
|
+
var CANVAS_INTERNAL_PARAM_PREFIX = "$internal_";
|
|
128
|
+
var CANVAS_COMPONENT_DISPLAY_NAME_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}displayName`;
|
|
129
|
+
var CANVAS_HYPOTHESIS_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}hypothesis`;
|
|
130
|
+
var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
|
|
131
|
+
var IN_CONTEXT_EDITOR_FORCED_SETTINGS_QUERY_STRING_PARAM = "is_incontext_editing_forced_settings";
|
|
132
|
+
var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
|
|
133
|
+
var _contentTypesUrl;
|
|
134
|
+
var _entriesUrl;
|
|
135
|
+
var _ContentClient = class _ContentClient2 extends import_api12.ApiClient {
|
|
136
|
+
constructor(options) {
|
|
137
|
+
var _a;
|
|
138
|
+
super(options);
|
|
139
|
+
this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
|
|
140
|
+
}
|
|
141
|
+
getContentTypes(options) {
|
|
142
|
+
const { projectId } = this.options;
|
|
143
|
+
const fetchUri = this.createUrl(__privateGet(_ContentClient2, _contentTypesUrl), { ...options, projectId });
|
|
144
|
+
return this.apiClient(fetchUri);
|
|
145
|
+
}
|
|
146
|
+
getEntries(options) {
|
|
147
|
+
const { projectId } = this.options;
|
|
148
|
+
const { skipDataResolution, filters, select, ...params } = options;
|
|
149
|
+
const rewrittenFilters = (0, import_api12.rewriteFiltersForApi)(filters);
|
|
150
|
+
const rewrittenSelect = projectionToQuery(select);
|
|
151
|
+
if (skipDataResolution) {
|
|
152
|
+
const url = this.createUrl(__privateGet(_ContentClient2, _entriesUrl), {
|
|
153
|
+
...params,
|
|
154
|
+
...rewrittenFilters,
|
|
155
|
+
...rewrittenSelect,
|
|
156
|
+
projectId
|
|
157
|
+
});
|
|
158
|
+
return this.apiClient(url);
|
|
159
|
+
}
|
|
160
|
+
const edgeUrl = this.createUrl(
|
|
161
|
+
__privateGet(_ContentClient2, _entriesUrl),
|
|
162
|
+
{ ...this.getEdgeOptions(params), ...rewrittenFilters, ...rewrittenSelect },
|
|
163
|
+
this.edgeApiHost
|
|
164
|
+
);
|
|
165
|
+
return this.apiClient(
|
|
166
|
+
edgeUrl,
|
|
167
|
+
this.options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
/** Fetches historical versions of an entry */
|
|
171
|
+
async getEntryHistory(options) {
|
|
172
|
+
const historyUrl = this.createUrl("/api/v1/entries-history", {
|
|
173
|
+
...options,
|
|
174
|
+
projectId: this.options.projectId
|
|
175
|
+
});
|
|
176
|
+
return this.apiClient(historyUrl);
|
|
177
|
+
}
|
|
178
|
+
async upsertContentType(body, opts = {}) {
|
|
179
|
+
const fetchUri = this.createUrl(__privateGet(_ContentClient2, _contentTypesUrl));
|
|
180
|
+
if (typeof body.contentType.slugSettings === "object" && body.contentType.slugSettings !== null && Object.keys(body.contentType.slugSettings).length === 0) {
|
|
181
|
+
delete body.contentType.slugSettings;
|
|
182
|
+
}
|
|
183
|
+
await this.apiClient(fetchUri, {
|
|
184
|
+
method: "PUT",
|
|
185
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
186
|
+
expectNoContent: true,
|
|
187
|
+
headers: opts.autogenerateDataTypes ? { "x-uniform-autogenerate-data-types": "true" } : {}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
async upsertEntry(body, options) {
|
|
191
|
+
const fetchUri = this.createUrl(__privateGet(_ContentClient2, _entriesUrl));
|
|
192
|
+
const headers = {};
|
|
193
|
+
if (options == null ? void 0 : options.ifUnmodifiedSince) {
|
|
194
|
+
headers["x-if-unmodified-since"] = options.ifUnmodifiedSince;
|
|
195
|
+
}
|
|
196
|
+
const { response } = await this.apiClientWithResponse(fetchUri, {
|
|
197
|
+
method: "PUT",
|
|
198
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
199
|
+
expectNoContent: true,
|
|
200
|
+
headers
|
|
201
|
+
});
|
|
202
|
+
return { modified: response.headers.get("x-modified-at") };
|
|
203
|
+
}
|
|
204
|
+
async deleteContentType(body) {
|
|
205
|
+
const fetchUri = this.createUrl(__privateGet(_ContentClient2, _contentTypesUrl));
|
|
206
|
+
await this.apiClient(fetchUri, {
|
|
207
|
+
method: "DELETE",
|
|
208
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
209
|
+
expectNoContent: true
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
async deleteEntry(body) {
|
|
213
|
+
const fetchUri = this.createUrl(__privateGet(_ContentClient2, _entriesUrl));
|
|
214
|
+
await this.apiClient(fetchUri, {
|
|
215
|
+
method: "DELETE",
|
|
216
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
217
|
+
expectNoContent: true
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
getEdgeOptions(options) {
|
|
221
|
+
const { projectId } = this.options;
|
|
222
|
+
const { skipDataResolution, ...params } = options;
|
|
223
|
+
return {
|
|
224
|
+
projectId,
|
|
225
|
+
...params,
|
|
226
|
+
diagnostics: typeof options.diagnostics === "boolean" ? options.diagnostics : options.diagnostics === "no-data" ? "no-data" : void 0
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
_contentTypesUrl = /* @__PURE__ */ new WeakMap();
|
|
231
|
+
_entriesUrl = /* @__PURE__ */ new WeakMap();
|
|
232
|
+
__privateAdd(_ContentClient, _contentTypesUrl, "/api/v1/content-types");
|
|
233
|
+
__privateAdd(_ContentClient, _entriesUrl, "/api/v1/entries");
|
|
234
|
+
var _url;
|
|
235
|
+
var _DataTypeClient = class _DataTypeClient2 extends import_api14.ApiClient {
|
|
236
|
+
constructor(options) {
|
|
237
|
+
super(options);
|
|
238
|
+
}
|
|
239
|
+
/** Fetches a list of DataTypes for a project */
|
|
240
|
+
async list(options) {
|
|
241
|
+
const { projectId } = this.options;
|
|
242
|
+
const fetchUri = this.createUrl(__privateGet(_DataTypeClient2, _url), { ...options, projectId });
|
|
243
|
+
return await this.apiClient(fetchUri);
|
|
244
|
+
}
|
|
245
|
+
/** @deprecated Use {@link list} instead. */
|
|
246
|
+
async get(options) {
|
|
247
|
+
return this.list(options);
|
|
248
|
+
}
|
|
249
|
+
/** Updates or creates (based on id) a DataType */
|
|
250
|
+
async save(body) {
|
|
251
|
+
const fetchUri = this.createUrl(__privateGet(_DataTypeClient2, _url));
|
|
252
|
+
await this.apiClient(fetchUri, {
|
|
253
|
+
method: "PUT",
|
|
254
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
255
|
+
expectNoContent: true
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
/** @deprecated Use {@link save} instead. */
|
|
259
|
+
async upsert(body) {
|
|
260
|
+
return this.save(body);
|
|
261
|
+
}
|
|
262
|
+
/** Deletes a DataType */
|
|
263
|
+
async remove(body) {
|
|
264
|
+
const fetchUri = this.createUrl(__privateGet(_DataTypeClient2, _url));
|
|
265
|
+
await this.apiClient(fetchUri, {
|
|
266
|
+
method: "DELETE",
|
|
267
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
268
|
+
expectNoContent: true
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
_url = /* @__PURE__ */ new WeakMap();
|
|
273
|
+
__privateAdd(_DataTypeClient, _url, "/api/v1/data-types");
|
|
274
|
+
var _baseUrl;
|
|
275
|
+
var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2 extends import_api16.ApiClient {
|
|
276
|
+
constructor(options) {
|
|
277
|
+
super(options);
|
|
278
|
+
this.teamId = options.teamId;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Gets a list of property type and hook names for the current team, including public integrations' hooks.
|
|
282
|
+
*/
|
|
283
|
+
get(options) {
|
|
284
|
+
const fetchUri = this.createUrl(__privateGet(_IntegrationPropertyEditorsClient2, _baseUrl), {
|
|
285
|
+
...options,
|
|
286
|
+
teamId: this.teamId
|
|
287
|
+
});
|
|
288
|
+
return this.apiClient(fetchUri);
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Creates or updates a custom AI property editor on a Mesh app.
|
|
292
|
+
*/
|
|
293
|
+
async deploy(body) {
|
|
294
|
+
const fetchUri = this.createUrl(__privateGet(_IntegrationPropertyEditorsClient2, _baseUrl));
|
|
295
|
+
await this.apiClient(fetchUri, {
|
|
296
|
+
method: "PUT",
|
|
297
|
+
body: JSON.stringify({ ...body, teamId: this.teamId }),
|
|
298
|
+
expectNoContent: true
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Removes a custom AI property editor from a Mesh app.
|
|
303
|
+
*/
|
|
304
|
+
async delete(body) {
|
|
305
|
+
const fetchUri = this.createUrl(__privateGet(_IntegrationPropertyEditorsClient2, _baseUrl));
|
|
306
|
+
await this.apiClient(fetchUri, {
|
|
307
|
+
method: "DELETE",
|
|
308
|
+
body: JSON.stringify({ ...body, teamId: this.teamId }),
|
|
309
|
+
expectNoContent: true
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
_baseUrl = /* @__PURE__ */ new WeakMap();
|
|
314
|
+
__privateAdd(_IntegrationPropertyEditorsClient, _baseUrl, "/api/v1/integration-property-editors");
|
|
315
|
+
var _url2;
|
|
316
|
+
var _projectsUrl;
|
|
317
|
+
var _ProjectClient = class _ProjectClient2 extends import_api20.ApiClient {
|
|
318
|
+
constructor(options) {
|
|
319
|
+
super({ ...options, bypassCache: true });
|
|
320
|
+
}
|
|
321
|
+
/** Fetches single Project */
|
|
322
|
+
async get(options) {
|
|
323
|
+
const fetchUri = this.createUrl(__privateGet(_ProjectClient2, _url2), { ...options });
|
|
324
|
+
return await this.apiClient(fetchUri);
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Fetches projects grouped by team.
|
|
328
|
+
* When teamId is provided, returns a single team with its projects.
|
|
329
|
+
* When omitted, returns all accessible teams and their projects.
|
|
330
|
+
*/
|
|
331
|
+
async list(options) {
|
|
332
|
+
const fetchUri = this.createUrl(__privateGet(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
|
|
333
|
+
return await this.apiClient(fetchUri);
|
|
334
|
+
}
|
|
335
|
+
/** @deprecated Use {@link list} instead. */
|
|
336
|
+
async getProjects(options) {
|
|
337
|
+
return this.list(options);
|
|
338
|
+
}
|
|
339
|
+
/** Updates or creates (based on id) a Project */
|
|
340
|
+
async save(body) {
|
|
341
|
+
const fetchUri = this.createUrl(__privateGet(_ProjectClient2, _url2));
|
|
342
|
+
return await this.apiClient(fetchUri, {
|
|
343
|
+
method: "PUT",
|
|
344
|
+
body: JSON.stringify({ ...body })
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
/** @deprecated Use {@link save} instead. */
|
|
348
|
+
async upsert(body) {
|
|
349
|
+
return this.save(body);
|
|
350
|
+
}
|
|
351
|
+
/** Deletes a Project */
|
|
352
|
+
async remove(body) {
|
|
353
|
+
const fetchUri = this.createUrl(__privateGet(_ProjectClient2, _url2));
|
|
354
|
+
await this.apiClient(fetchUri, {
|
|
355
|
+
method: "DELETE",
|
|
356
|
+
body: JSON.stringify({ ...body }),
|
|
357
|
+
expectNoContent: true
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
/** @deprecated Use {@link remove} instead. */
|
|
361
|
+
async delete(body) {
|
|
362
|
+
return this.remove(body);
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
_url2 = /* @__PURE__ */ new WeakMap();
|
|
366
|
+
_projectsUrl = /* @__PURE__ */ new WeakMap();
|
|
367
|
+
__privateAdd(_ProjectClient, _url2, "/api/v1/project");
|
|
368
|
+
__privateAdd(_ProjectClient, _projectsUrl, "/api/v1/projects");
|
|
369
|
+
|
|
370
|
+
// src/middleware.ts
|
|
371
|
+
var import_context = require("@uniformdev/context");
|
|
372
|
+
var import_next_app_router_shared = require("@uniformdev/next-app-router-shared");
|
|
373
|
+
var import_headers = require("next/headers");
|
|
374
|
+
var import_server = require("next/server");
|
|
375
|
+
|
|
376
|
+
// src/config/helpers.ts
|
|
377
|
+
var import_resolved = __toESM(require("@uniformdev/next-app-router/config/resolved"));
|
|
378
|
+
var getServerConfig = () => {
|
|
379
|
+
return import_resolved.default;
|
|
380
|
+
};
|
|
381
|
+
var getDefaultConsent = () => {
|
|
382
|
+
if (typeof import_resolved.default.defaultConsent === "boolean") {
|
|
383
|
+
return import_resolved.default.defaultConsent;
|
|
384
|
+
}
|
|
385
|
+
return false;
|
|
386
|
+
};
|
|
387
|
+
var getQuirkSerialization = () => {
|
|
388
|
+
if (typeof import_resolved.default.quirkSerialization === "boolean") {
|
|
389
|
+
return import_resolved.default.quirkSerialization;
|
|
390
|
+
}
|
|
391
|
+
return true;
|
|
392
|
+
};
|
|
393
|
+
var getPlaygroundPath = () => {
|
|
394
|
+
if (typeof import_resolved.default.playgroundPath === "string") {
|
|
395
|
+
return import_resolved.default.playgroundPath;
|
|
396
|
+
}
|
|
397
|
+
return "/uniform/playground";
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
// src/data/routes.ts
|
|
401
|
+
var findRouteMatch = (routes, path) => {
|
|
402
|
+
const pieces = path.split("/").filter(Boolean);
|
|
403
|
+
for (const route of routes) {
|
|
404
|
+
const patternPieces = route.pattern.split("/").filter(Boolean);
|
|
405
|
+
if (patternPieces.length !== pieces.length) {
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
let match = true;
|
|
409
|
+
const params = {};
|
|
410
|
+
for (let i = 0; i < patternPieces.length; i++) {
|
|
411
|
+
const patternPiece = patternPieces[i];
|
|
412
|
+
const piece = pieces[i];
|
|
413
|
+
if (patternPiece.startsWith(":")) {
|
|
414
|
+
const paramName = patternPiece.slice(1);
|
|
415
|
+
params[paramName] = piece;
|
|
416
|
+
} else if (patternPiece !== piece) {
|
|
417
|
+
match = false;
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
if (match) {
|
|
422
|
+
return {
|
|
423
|
+
route,
|
|
424
|
+
params
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return void 0;
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
// src/utils/draft.ts
|
|
432
|
+
var isDraftModeEnabled = ({
|
|
433
|
+
draftModeEnabled
|
|
434
|
+
}) => {
|
|
435
|
+
return draftModeEnabled;
|
|
436
|
+
};
|
|
437
|
+
var isIncontextEditingEnabled = ({
|
|
438
|
+
isDraftModeEnabled: isDraftModeEnabled2,
|
|
439
|
+
searchParams
|
|
440
|
+
}) => {
|
|
441
|
+
if (!isDraftModeEnabled2) {
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
const containsKey = searchParams.has(IN_CONTEXT_EDITOR_QUERY_STRING_PARAM);
|
|
445
|
+
return containsKey;
|
|
446
|
+
};
|
|
447
|
+
var isDevelopmentEnvironment = () => {
|
|
448
|
+
return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
// src/utils/quirks.ts
|
|
452
|
+
var buildQuirksFromHeaders = (headers) => {
|
|
453
|
+
const headerToQuirkKey = {
|
|
454
|
+
"x-vercel-ip-country": "vc-country",
|
|
455
|
+
"x-vercel-ip-country-region": "vc-region",
|
|
456
|
+
"x-vercel-ip-city": "vc-city"
|
|
457
|
+
};
|
|
458
|
+
return Object.entries(headerToQuirkKey).reduce((acc, [headerName, quirkKey]) => {
|
|
459
|
+
const value = headers.get(headerName);
|
|
460
|
+
if (value) {
|
|
461
|
+
acc[quirkKey] = value;
|
|
462
|
+
}
|
|
463
|
+
return acc;
|
|
464
|
+
}, {});
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
// src/middleware.ts
|
|
468
|
+
var resolveUniformRequest = async ({
|
|
469
|
+
request,
|
|
470
|
+
edgeMode,
|
|
471
|
+
...options
|
|
472
|
+
}) => {
|
|
473
|
+
const draftModeEnabled = (await (0, import_headers.draftMode)()).isEnabled;
|
|
474
|
+
if (draftModeEnabled && isPlaygroundPath(request.nextUrl.pathname)) {
|
|
475
|
+
return handlePlaygroundRequest({ request, options });
|
|
476
|
+
}
|
|
477
|
+
return resolveRouteRequest({ request, draftModeEnabled, edgeMode, options });
|
|
478
|
+
};
|
|
479
|
+
var isPlaygroundPath = (path) => {
|
|
480
|
+
const { playgroundPath } = getServerConfig();
|
|
481
|
+
if (!playgroundPath) {
|
|
482
|
+
return false;
|
|
483
|
+
}
|
|
484
|
+
const PLAYGROUND_ID = "playground";
|
|
485
|
+
const match = findRouteMatch(
|
|
486
|
+
[
|
|
487
|
+
{
|
|
488
|
+
id: PLAYGROUND_ID,
|
|
489
|
+
pattern: playgroundPath
|
|
490
|
+
}
|
|
491
|
+
],
|
|
492
|
+
path
|
|
493
|
+
);
|
|
494
|
+
return (match == null ? void 0 : match.route.id) === PLAYGROUND_ID;
|
|
495
|
+
};
|
|
496
|
+
var handlePlaygroundRequest = async ({
|
|
497
|
+
request,
|
|
498
|
+
options
|
|
499
|
+
}) => {
|
|
500
|
+
var _a, _b;
|
|
501
|
+
const id = request.nextUrl.searchParams.get("id");
|
|
502
|
+
if (!id) {
|
|
503
|
+
return {
|
|
504
|
+
type: "response",
|
|
505
|
+
response: import_server.NextResponse.json({ error: "No id provided" }, { status: 400 })
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
const playgroundPath = getPlaygroundPath();
|
|
509
|
+
const pageState = {
|
|
510
|
+
routePath: id,
|
|
511
|
+
compositionState: CANVAS_EDITOR_STATE,
|
|
512
|
+
keys: void 0,
|
|
513
|
+
releaseId: (_a = options.release) == null ? void 0 : _a.id,
|
|
514
|
+
defaultConsent: determineDefaultConsent({
|
|
515
|
+
serverConfig: getServerConfig(),
|
|
516
|
+
defaultConsent: options.defaultConsent
|
|
517
|
+
}),
|
|
518
|
+
previewMode: determinePreviewMode({
|
|
519
|
+
searchParams: request.nextUrl.searchParams,
|
|
520
|
+
isDraftModeEnabled: true
|
|
521
|
+
}),
|
|
522
|
+
locale: options.locale
|
|
523
|
+
};
|
|
524
|
+
const code = (0, import_next_app_router_shared.serializeEvaluationResult)({ payload: pageState });
|
|
525
|
+
const destination = await ((_b = options.rewriteDestinationPath) == null ? void 0 : _b.call(options, { code, pageState, source: "playground" })) || `${playgroundPath}${playgroundPath.endsWith("/") ? "" : "/"}${code}`;
|
|
526
|
+
return {
|
|
527
|
+
type: "response",
|
|
528
|
+
response: import_server.NextResponse.rewrite(new URL(destination, request.nextUrl.origin))
|
|
529
|
+
};
|
|
530
|
+
};
|
|
531
|
+
var resolveRouteRequest = async ({
|
|
532
|
+
request,
|
|
533
|
+
draftModeEnabled,
|
|
534
|
+
edgeMode,
|
|
535
|
+
options
|
|
536
|
+
}) => {
|
|
537
|
+
var _a, _b, _c, _d, _e;
|
|
538
|
+
const releaseId = (_b = (_a = options.release) == null ? void 0 : _a.id) != null ? _b : draftModeEnabled ? request.nextUrl.searchParams.get("releaseId") || void 0 : void 0;
|
|
539
|
+
const requestPath = (_d = await ((_c = options.rewriteRequestPath) == null ? void 0 : _c.call(options, {
|
|
540
|
+
request,
|
|
541
|
+
url: new URL(request.url)
|
|
542
|
+
}))) != null ? _d : {
|
|
543
|
+
path: `${request.nextUrl.pathname}${request.nextUrl.search}`
|
|
544
|
+
};
|
|
545
|
+
const defaultConsent = determineDefaultConsent({
|
|
546
|
+
serverConfig: getServerConfig(),
|
|
547
|
+
defaultConsent: options.defaultConsent
|
|
548
|
+
});
|
|
549
|
+
const pageState = {
|
|
550
|
+
routePath: buildRoutePath({ path: requestPath.path, queryStrings: options.queryStrings }),
|
|
551
|
+
compositionState: determineCompositionState({
|
|
552
|
+
searchParams: request.nextUrl.searchParams,
|
|
553
|
+
draftModeEnabled
|
|
554
|
+
}),
|
|
555
|
+
keys: requestPath.keys,
|
|
556
|
+
releaseId,
|
|
557
|
+
defaultConsent,
|
|
558
|
+
previewMode: determinePreviewMode({
|
|
559
|
+
searchParams: request.nextUrl.searchParams,
|
|
560
|
+
isDraftModeEnabled: draftModeEnabled
|
|
561
|
+
}),
|
|
562
|
+
locale: options.locale
|
|
563
|
+
};
|
|
564
|
+
if (edgeMode && pageState.compositionState === CANVAS_PUBLISHED_STATE && await edgeMode({ pageState })) {
|
|
565
|
+
pageState.edgeMode = true;
|
|
566
|
+
}
|
|
567
|
+
const code = (0, import_next_app_router_shared.serializeEvaluationResult)({ payload: pageState });
|
|
568
|
+
const destination = await ((_e = options.rewriteDestinationPath) == null ? void 0 : _e.call(options, { code, pageState, source: "route" })) || `/uniform/${code}`;
|
|
569
|
+
const quirks = {
|
|
570
|
+
...buildQuirksFromHeaders(request.headers),
|
|
571
|
+
...options.quirks
|
|
572
|
+
};
|
|
573
|
+
const headers = new Headers();
|
|
574
|
+
if (Object.keys(quirks).length > 0) {
|
|
575
|
+
headers.append(
|
|
576
|
+
"Set-Cookie",
|
|
577
|
+
`${import_next_app_router_shared.UNIFORM_MIDDLEWARE_QUIRK_COOKIE_NAME}=${JSON.stringify(quirks)}; Path=/; SameSite=Lax; Max-Age=10`
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
const createContext = async ({ manifest }) => {
|
|
581
|
+
var _a2, _b2, _c2, _d2;
|
|
582
|
+
const context = new import_context.Context({
|
|
583
|
+
manifest,
|
|
584
|
+
defaultConsent: defaultConsent != null ? defaultConsent : getDefaultConsent(),
|
|
585
|
+
transitionStore: new import_context.CookieTransitionDataStore({
|
|
586
|
+
serverCookieValue: (_b2 = (_a2 = request.cookies.get(import_context.UNIFORM_DEFAULT_COOKIE_NAME)) == null ? void 0 : _a2.value) != null ? _b2 : "",
|
|
587
|
+
experimental_quirksEnabled: getQuirkSerialization(),
|
|
588
|
+
quirkCookieValue: (_d2 = (_c2 = request.cookies.get(import_context.UNIFORM_DEFAULT_QUIRK_COOKIE_NAME)) == null ? void 0 : _c2.value) != null ? _d2 : ""
|
|
589
|
+
})
|
|
590
|
+
});
|
|
591
|
+
await context.update({
|
|
592
|
+
url: new URL(request.nextUrl.href),
|
|
593
|
+
cookies: Object.fromEntries(request.cookies.getAll().map((cookie) => [cookie.name, cookie.value])),
|
|
594
|
+
quirks
|
|
595
|
+
});
|
|
596
|
+
return context;
|
|
597
|
+
};
|
|
598
|
+
return {
|
|
599
|
+
type: "rewrite",
|
|
600
|
+
destination,
|
|
601
|
+
pageState,
|
|
602
|
+
code,
|
|
603
|
+
headers,
|
|
604
|
+
draftModeEnabled,
|
|
605
|
+
createContext
|
|
606
|
+
};
|
|
607
|
+
};
|
|
608
|
+
var buildRoutePath = ({
|
|
609
|
+
path,
|
|
610
|
+
queryStrings
|
|
611
|
+
}) => {
|
|
612
|
+
const [pathname = "", search] = path.split("?");
|
|
613
|
+
if (!search || !queryStrings) {
|
|
614
|
+
return pathname;
|
|
615
|
+
}
|
|
616
|
+
const patterns = Object.keys(queryStrings);
|
|
617
|
+
const match = findRouteMatch(
|
|
618
|
+
patterns.map((pattern) => ({ id: pattern, pattern })),
|
|
619
|
+
pathname
|
|
620
|
+
);
|
|
621
|
+
const allowed = match ? queryStrings[match.route.id] : void 0;
|
|
622
|
+
if (!(allowed == null ? void 0 : allowed.length)) {
|
|
623
|
+
return pathname;
|
|
624
|
+
}
|
|
625
|
+
const requestSearchParams = new URLSearchParams(search);
|
|
626
|
+
const searchParams = new URLSearchParams();
|
|
627
|
+
[...allowed].sort().forEach((name) => {
|
|
628
|
+
const value = requestSearchParams.get(name);
|
|
629
|
+
if (value !== null) {
|
|
630
|
+
searchParams.set(name, value);
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
return searchParams.size ? `${pathname}?${searchParams.toString()}` : pathname;
|
|
634
|
+
};
|
|
635
|
+
var determineCompositionState = ({
|
|
636
|
+
searchParams,
|
|
637
|
+
draftModeEnabled
|
|
638
|
+
}) => {
|
|
639
|
+
if (!draftModeEnabled) {
|
|
640
|
+
return CANVAS_PUBLISHED_STATE;
|
|
641
|
+
}
|
|
642
|
+
return isIncontextEditingEnabled({ isDraftModeEnabled: draftModeEnabled, searchParams }) ? CANVAS_EDITOR_STATE : CANVAS_DRAFT_STATE;
|
|
643
|
+
};
|
|
644
|
+
var determineDefaultConsent = ({
|
|
645
|
+
serverConfig,
|
|
646
|
+
defaultConsent
|
|
647
|
+
}) => {
|
|
648
|
+
return defaultConsent !== serverConfig.defaultConsent ? defaultConsent : void 0;
|
|
649
|
+
};
|
|
650
|
+
var determinePreviewMode = ({
|
|
651
|
+
searchParams,
|
|
652
|
+
isDraftModeEnabled: isDraftModeEnabled2
|
|
653
|
+
}) => {
|
|
654
|
+
if (!isDraftModeEnabled2) {
|
|
655
|
+
return void 0;
|
|
656
|
+
}
|
|
657
|
+
const queryStringSettings = searchParams.get(IN_CONTEXT_EDITOR_FORCED_SETTINGS_QUERY_STRING_PARAM);
|
|
658
|
+
let previewSettings = void 0;
|
|
659
|
+
if (queryStringSettings) {
|
|
660
|
+
try {
|
|
661
|
+
previewSettings = JSON.parse(queryStringSettings);
|
|
662
|
+
} catch (e) {
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
if (previewSettings == null ? void 0 : previewSettings.isVisualEditingDisabled) {
|
|
666
|
+
return "preview";
|
|
667
|
+
}
|
|
668
|
+
const isInContextEditingEnabled = isIncontextEditingEnabled({ isDraftModeEnabled: isDraftModeEnabled2, searchParams });
|
|
669
|
+
if (isInContextEditingEnabled) {
|
|
670
|
+
return "editor";
|
|
671
|
+
}
|
|
672
|
+
return void 0;
|
|
673
|
+
};
|
|
674
|
+
|
|
675
|
+
// src/edge/uniformEdgeMiddleware.ts
|
|
676
|
+
var UNIFORM_EDGE_ORIGIN_HEADER = "x-uniform-edge-origin";
|
|
677
|
+
var uniformEdgeMiddleware = (options) => {
|
|
678
|
+
return async (request, event) => {
|
|
679
|
+
return handleUniformEdgeRoute({
|
|
680
|
+
request,
|
|
681
|
+
waitUntil: event ? (promise) => event.waitUntil(promise) : void 0,
|
|
682
|
+
...options
|
|
683
|
+
});
|
|
684
|
+
};
|
|
685
|
+
};
|
|
686
|
+
var handleUniformEdgeRoute = async ({
|
|
687
|
+
request,
|
|
688
|
+
manifest,
|
|
689
|
+
onError,
|
|
690
|
+
filter,
|
|
691
|
+
waitUntil = ignorePromise,
|
|
692
|
+
...options
|
|
693
|
+
}) => {
|
|
694
|
+
var _a;
|
|
695
|
+
if (request.headers.has(UNIFORM_EDGE_ORIGIN_HEADER)) {
|
|
696
|
+
return import_server2.NextResponse.next();
|
|
697
|
+
}
|
|
698
|
+
const result = await resolveUniformRequest({
|
|
699
|
+
request,
|
|
700
|
+
...options,
|
|
701
|
+
edgeMode: ({ pageState }) => filter ? filter.shouldProcess({ pageState, waitUntil }) : true
|
|
702
|
+
});
|
|
703
|
+
if (result.type === "response") {
|
|
704
|
+
return result.response;
|
|
705
|
+
}
|
|
706
|
+
const destination = new URL(result.destination, request.nextUrl.origin);
|
|
707
|
+
if (!result.pageState.edgeMode || !isDocumentRequest(request)) {
|
|
708
|
+
return import_server2.NextResponse.rewrite(destination, { headers: result.headers });
|
|
709
|
+
}
|
|
710
|
+
const [originResponse, context] = await Promise.all([
|
|
711
|
+
fetch(destination, {
|
|
712
|
+
// A page that calls `redirect()` answers with a redirect, which belongs to the visitor.
|
|
713
|
+
redirect: "manual",
|
|
714
|
+
headers: {
|
|
715
|
+
cookie: (_a = request.headers.get("cookie")) != null ? _a : "",
|
|
716
|
+
accept: "text/html",
|
|
717
|
+
// Node's fetch decompresses the body but keeps the header, so ask for plain HTML.
|
|
718
|
+
"accept-encoding": "identity",
|
|
719
|
+
[UNIFORM_EDGE_ORIGIN_HEADER]: "1"
|
|
720
|
+
}
|
|
721
|
+
}),
|
|
722
|
+
resolveManifest({ manifest, waitUntil, onError }).then(
|
|
723
|
+
(resolved) => result.createContext({ manifest: resolved })
|
|
724
|
+
)
|
|
725
|
+
]);
|
|
726
|
+
const headers = new Headers(originResponse.headers);
|
|
727
|
+
result.headers.forEach((value, key) => {
|
|
728
|
+
headers.append(key, value);
|
|
729
|
+
});
|
|
730
|
+
if (originResponse.status >= 300 && originResponse.status < 400) {
|
|
731
|
+
return new Response(originResponse.body, {
|
|
732
|
+
status: originResponse.status,
|
|
733
|
+
statusText: originResponse.statusText,
|
|
734
|
+
headers
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
headers.delete("content-length");
|
|
738
|
+
headers.delete("content-encoding");
|
|
739
|
+
headers.set("cache-control", "private, no-store");
|
|
740
|
+
const observe = filter == null ? void 0 : filter.observe;
|
|
741
|
+
const onComplete = observe && originResponse.status === 200 ? (hasPlacements) => observe({ pageState: result.pageState, hasPlacements, waitUntil }) : void 0;
|
|
742
|
+
return new Response(transformBody({ body: originResponse.body, context, onError, onComplete }), {
|
|
743
|
+
status: originResponse.status,
|
|
744
|
+
statusText: originResponse.statusText,
|
|
745
|
+
headers
|
|
746
|
+
});
|
|
747
|
+
};
|
|
748
|
+
var ignorePromise = (promise) => {
|
|
749
|
+
promise.catch(() => {
|
|
750
|
+
});
|
|
751
|
+
};
|
|
752
|
+
var EMPTY_MANIFEST = { project: {} };
|
|
753
|
+
var resolveManifest = async ({
|
|
754
|
+
manifest,
|
|
755
|
+
waitUntil,
|
|
756
|
+
onError
|
|
757
|
+
}) => {
|
|
758
|
+
if (typeof manifest !== "function") {
|
|
759
|
+
return manifest;
|
|
760
|
+
}
|
|
761
|
+
try {
|
|
762
|
+
return await manifest({ waitUntil });
|
|
763
|
+
} catch (error) {
|
|
764
|
+
onError == null ? void 0 : onError({ error });
|
|
765
|
+
return EMPTY_MANIFEST;
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
var isDocumentRequest = (request) => {
|
|
769
|
+
const accept = request.headers.get("accept");
|
|
770
|
+
return request.method === "GET" && !request.headers.has("rsc") && !request.headers.has("next-router-prefetch") && (!accept || accept.includes("text/html") || accept.includes("*/*"));
|
|
771
|
+
};
|
|
772
|
+
var transformBody = ({
|
|
773
|
+
body,
|
|
774
|
+
context,
|
|
775
|
+
onError,
|
|
776
|
+
onComplete
|
|
777
|
+
}) => {
|
|
778
|
+
if (!body) {
|
|
779
|
+
return null;
|
|
780
|
+
}
|
|
781
|
+
const reader = body.getReader();
|
|
782
|
+
const { readable, writable } = new TransformStream();
|
|
783
|
+
const writer = writable.getWriter();
|
|
784
|
+
let hasPlacements = false;
|
|
785
|
+
let complete = true;
|
|
786
|
+
writer.closed.catch(() => {
|
|
787
|
+
complete = false;
|
|
788
|
+
return reader.cancel();
|
|
789
|
+
}).catch(() => {
|
|
790
|
+
});
|
|
791
|
+
void (0, import_context_edge.transformEdgeStream)({
|
|
792
|
+
context,
|
|
793
|
+
decoder: new TextDecoder(),
|
|
794
|
+
encoder: new TextEncoder(),
|
|
795
|
+
reader: {
|
|
796
|
+
read: async () => {
|
|
797
|
+
await writer.ready.catch(() => {
|
|
798
|
+
});
|
|
799
|
+
const { done, value } = await reader.read();
|
|
800
|
+
return { done, value };
|
|
801
|
+
}
|
|
802
|
+
},
|
|
803
|
+
writer: {
|
|
804
|
+
// Write and close fail only after the visitor disconnects, which `writer.closed` handles.
|
|
805
|
+
write: (value) => {
|
|
806
|
+
writer.write(value).catch(() => {
|
|
807
|
+
});
|
|
808
|
+
},
|
|
809
|
+
close: () => {
|
|
810
|
+
return writer.close().catch(() => {
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
},
|
|
814
|
+
onError: (details) => {
|
|
815
|
+
complete = false;
|
|
816
|
+
if (onError) {
|
|
817
|
+
onError(details);
|
|
818
|
+
} else {
|
|
819
|
+
console.error("[transformEdgeStream]", details.error);
|
|
820
|
+
}
|
|
821
|
+
},
|
|
822
|
+
onPlacement: () => {
|
|
823
|
+
hasPlacements = true;
|
|
824
|
+
}
|
|
825
|
+
}).then(() => {
|
|
826
|
+
if (complete) {
|
|
827
|
+
onComplete == null ? void 0 : onComplete(hasPlacements);
|
|
828
|
+
}
|
|
829
|
+
});
|
|
830
|
+
return readable;
|
|
831
|
+
};
|
|
832
|
+
|
|
833
|
+
// src/utils/env.ts
|
|
834
|
+
var env = {
|
|
835
|
+
getProjectId: () => {
|
|
836
|
+
return process.env.UNIFORM_PROJECT_ID;
|
|
837
|
+
},
|
|
838
|
+
getApiKey: () => {
|
|
839
|
+
return process.env.UNIFORM_API_KEY;
|
|
840
|
+
},
|
|
841
|
+
getApiHost: () => {
|
|
842
|
+
return process.env.UNIFORM_API_HOST || process.env.UNIFORM_CLI_BASE_URL;
|
|
843
|
+
},
|
|
844
|
+
getEdgeApiHost: () => {
|
|
845
|
+
return process.env.UNIFORM_EDGE_API_HOST || process.env.UNIFORM_CLI_BASE_EDGE_URL;
|
|
846
|
+
}
|
|
847
|
+
};
|
|
848
|
+
|
|
849
|
+
// src/utils/tag.ts
|
|
850
|
+
var encodePathForTag = (path) => path.split("/").map((segment) => /[^\x00-\x7F]/.test(segment) ? encodeURIComponent(segment) : segment).join("/");
|
|
851
|
+
var buildPathTag = (path) => {
|
|
852
|
+
const actualPath = path.startsWith("/") ? path : `/${path}`;
|
|
853
|
+
return `path:${encodePathForTag(actualPath)}`.toLowerCase();
|
|
854
|
+
};
|
|
855
|
+
|
|
856
|
+
// src/edgeRouteFilter/createLearnedEdgeRouteFilter.ts
|
|
857
|
+
var createLearnedEdgeRouteFilter = ({
|
|
858
|
+
cache,
|
|
859
|
+
ttl = 3600,
|
|
860
|
+
maxAge = 10,
|
|
861
|
+
maxEntries = 1e3
|
|
862
|
+
} = {}) => {
|
|
863
|
+
const memory = /* @__PURE__ */ new Map();
|
|
864
|
+
const pending = /* @__PURE__ */ new Map();
|
|
865
|
+
const remember = (key, hasPlacements) => {
|
|
866
|
+
memory.delete(key);
|
|
867
|
+
memory.set(key, { hasPlacements, checkedAt: Date.now() });
|
|
868
|
+
if (memory.size > maxEntries) {
|
|
869
|
+
const oldest = memory.keys().next().value;
|
|
870
|
+
if (oldest !== void 0) {
|
|
871
|
+
memory.delete(oldest);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
};
|
|
875
|
+
const read = async (key) => {
|
|
876
|
+
const stored = await (cache == null ? void 0 : cache.get(key).catch(() => void 0));
|
|
877
|
+
const hasPlacements = isRecord(stored) ? stored.hasPlacements : void 0;
|
|
878
|
+
remember(key, hasPlacements);
|
|
879
|
+
return hasPlacements;
|
|
880
|
+
};
|
|
881
|
+
return {
|
|
882
|
+
shouldProcess: async ({ pageState }) => {
|
|
883
|
+
var _a, _b;
|
|
884
|
+
const key = buildKey(pageState);
|
|
885
|
+
const known = memory.get(key);
|
|
886
|
+
if (known && Date.now() - known.checkedAt < maxAge * 1e3) {
|
|
887
|
+
return (_a = known.hasPlacements) != null ? _a : true;
|
|
888
|
+
}
|
|
889
|
+
let lookup = pending.get(key);
|
|
890
|
+
if (!lookup) {
|
|
891
|
+
lookup = read(key).finally(() => {
|
|
892
|
+
pending.delete(key);
|
|
893
|
+
});
|
|
894
|
+
pending.set(key, lookup);
|
|
895
|
+
}
|
|
896
|
+
return (_b = await lookup) != null ? _b : true;
|
|
897
|
+
},
|
|
898
|
+
observe: ({ pageState, hasPlacements, waitUntil }) => {
|
|
899
|
+
var _a, _b;
|
|
900
|
+
const key = buildKey(pageState);
|
|
901
|
+
if (((_a = memory.get(key)) == null ? void 0 : _a.hasPlacements) === hasPlacements) {
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
remember(key, hasPlacements);
|
|
905
|
+
if (cache) {
|
|
906
|
+
const tags = [buildPathTag((_b = pageState.routePath.split("?")[0]) != null ? _b : "")];
|
|
907
|
+
waitUntil(cache.set(key, { hasPlacements }, { ttl, tags }).catch(() => {
|
|
908
|
+
}));
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
};
|
|
913
|
+
var buildKey = (pageState) => {
|
|
914
|
+
var _a, _b;
|
|
915
|
+
return `uniform-edge-route-${(_a = env.getProjectId()) != null ? _a : ""}-${(_b = pageState.locale) != null ? _b : ""}-${pageState.routePath}`;
|
|
916
|
+
};
|
|
917
|
+
var isRecord = (value) => typeof value === "object" && value !== null && "hasPlacements" in value && typeof value.hasPlacements === "boolean";
|
|
918
|
+
|
|
919
|
+
// src/edgeRouteFilter/createStaticEdgeRouteFilter.ts
|
|
920
|
+
var createStaticEdgeRouteFilter = ({
|
|
921
|
+
paths
|
|
922
|
+
}) => {
|
|
923
|
+
const routes = paths.map((pattern) => ({ id: pattern, pattern }));
|
|
924
|
+
return {
|
|
925
|
+
shouldProcess: ({ pageState }) => Boolean(findRouteMatch(routes, stripQuery(pageState.routePath)))
|
|
926
|
+
};
|
|
927
|
+
};
|
|
928
|
+
var stripQuery = (routePath) => {
|
|
929
|
+
var _a;
|
|
930
|
+
return (_a = routePath.split("?")[0]) != null ? _a : "";
|
|
931
|
+
};
|
|
932
|
+
|
|
933
|
+
// src/clients/manifest.ts
|
|
934
|
+
var import_server_only = require("server-only");
|
|
935
|
+
var import_api29 = require("@uniformdev/context/api");
|
|
936
|
+
|
|
937
|
+
// src/clients/cache.ts
|
|
938
|
+
var isSpecificCacheMode = (options) => {
|
|
939
|
+
return "cache" in options;
|
|
940
|
+
};
|
|
941
|
+
var isStateCacheMode = (options) => {
|
|
942
|
+
return "state" in options;
|
|
943
|
+
};
|
|
944
|
+
var isDetectCacheMode = (options) => {
|
|
945
|
+
return "searchParams" in options && "draftModeEnabled" in options;
|
|
946
|
+
};
|
|
947
|
+
var resolveManifestCache = (options) => {
|
|
948
|
+
return resolveCache({
|
|
949
|
+
options
|
|
950
|
+
});
|
|
951
|
+
};
|
|
952
|
+
var resolveCache = ({
|
|
953
|
+
options
|
|
954
|
+
}) => {
|
|
955
|
+
let cache = void 0;
|
|
956
|
+
if (options) {
|
|
957
|
+
if (isSpecificCacheMode(options)) {
|
|
958
|
+
cache = options.cache;
|
|
959
|
+
} else if (isStateCacheMode(options)) {
|
|
960
|
+
if (options.state === CANVAS_DRAFT_STATE || options.state === CANVAS_EDITOR_STATE) {
|
|
961
|
+
cache = {
|
|
962
|
+
type: "no-cache",
|
|
963
|
+
bypassCache: true
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
} else if (isDetectCacheMode(options)) {
|
|
967
|
+
const { disabled } = shouldCacheBeDisabled(options);
|
|
968
|
+
if (disabled) {
|
|
969
|
+
cache = {
|
|
970
|
+
type: "no-cache",
|
|
971
|
+
bypassCache: true
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
return cache || {
|
|
977
|
+
type: "force-cache"
|
|
978
|
+
};
|
|
979
|
+
};
|
|
980
|
+
var shouldCacheBeDisabled = (options) => {
|
|
981
|
+
if (isDraftModeEnabled(options)) {
|
|
982
|
+
return { disabled: true, reason: "DRAFT" };
|
|
983
|
+
}
|
|
984
|
+
if (isIncontextEditingEnabled({
|
|
985
|
+
isDraftModeEnabled: options.draftModeEnabled,
|
|
986
|
+
searchParams: options.searchParams
|
|
987
|
+
})) {
|
|
988
|
+
return { disabled: true, reason: "INCONTEXT" };
|
|
989
|
+
}
|
|
990
|
+
if (isDevelopmentEnvironment()) {
|
|
991
|
+
return { disabled: true, reason: "DEV" };
|
|
992
|
+
}
|
|
993
|
+
return {
|
|
994
|
+
disabled: false,
|
|
995
|
+
reason: void 0
|
|
996
|
+
};
|
|
997
|
+
};
|
|
998
|
+
var determineFetchCacheOptions = (mode) => {
|
|
999
|
+
let cache = void 0;
|
|
1000
|
+
let revalidate = void 0;
|
|
1001
|
+
if (mode.type === "revalidate") {
|
|
1002
|
+
cache = void 0;
|
|
1003
|
+
revalidate = mode.interval;
|
|
1004
|
+
} else {
|
|
1005
|
+
cache = mode.type;
|
|
1006
|
+
}
|
|
1007
|
+
return {
|
|
1008
|
+
cache,
|
|
1009
|
+
revalidate
|
|
1010
|
+
};
|
|
1011
|
+
};
|
|
1012
|
+
|
|
1013
|
+
// src/clients/retry.ts
|
|
1014
|
+
var import_api28 = require("@uniformdev/context/api");
|
|
1015
|
+
function createThrottler(limit, interval) {
|
|
1016
|
+
let available = limit;
|
|
1017
|
+
let refillScheduled = false;
|
|
1018
|
+
const waiting = [];
|
|
1019
|
+
function scheduleRefill() {
|
|
1020
|
+
if (refillScheduled) return;
|
|
1021
|
+
refillScheduled = true;
|
|
1022
|
+
setTimeout(() => {
|
|
1023
|
+
refillScheduled = false;
|
|
1024
|
+
available = limit;
|
|
1025
|
+
while (available > 0 && waiting.length > 0) {
|
|
1026
|
+
available--;
|
|
1027
|
+
const next = waiting.shift();
|
|
1028
|
+
next();
|
|
1029
|
+
}
|
|
1030
|
+
if (waiting.length > 0) {
|
|
1031
|
+
scheduleRefill();
|
|
1032
|
+
}
|
|
1033
|
+
}, interval);
|
|
1034
|
+
}
|
|
1035
|
+
return async function throttle(fn) {
|
|
1036
|
+
if (available > 0) {
|
|
1037
|
+
available--;
|
|
1038
|
+
if (!refillScheduled) {
|
|
1039
|
+
scheduleRefill();
|
|
1040
|
+
}
|
|
1041
|
+
return fn();
|
|
1042
|
+
}
|
|
1043
|
+
return new Promise((resolve, reject) => {
|
|
1044
|
+
waiting.push(() => {
|
|
1045
|
+
fn().then(resolve, reject);
|
|
1046
|
+
});
|
|
1047
|
+
scheduleRefill();
|
|
1048
|
+
});
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
function createLimiter(concurrency) {
|
|
1052
|
+
let active = 0;
|
|
1053
|
+
const queue = [];
|
|
1054
|
+
return async function limit(fn) {
|
|
1055
|
+
return new Promise((resolve, reject) => {
|
|
1056
|
+
const run = async () => {
|
|
1057
|
+
active++;
|
|
1058
|
+
try {
|
|
1059
|
+
const result = await fn();
|
|
1060
|
+
resolve(result);
|
|
1061
|
+
} catch (error) {
|
|
1062
|
+
reject(error);
|
|
1063
|
+
} finally {
|
|
1064
|
+
active--;
|
|
1065
|
+
if (queue.length > 0) {
|
|
1066
|
+
const next = queue.shift();
|
|
1067
|
+
next();
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
};
|
|
1071
|
+
if (active < concurrency) {
|
|
1072
|
+
run();
|
|
1073
|
+
} else {
|
|
1074
|
+
queue.push(run);
|
|
1075
|
+
}
|
|
1076
|
+
});
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
async function retry(fn, options) {
|
|
1080
|
+
let lastError;
|
|
1081
|
+
let delay = 1e3;
|
|
1082
|
+
for (let attempt = 1; attempt <= options.retries + 1; attempt++) {
|
|
1083
|
+
try {
|
|
1084
|
+
return await fn();
|
|
1085
|
+
} catch (error) {
|
|
1086
|
+
lastError = error;
|
|
1087
|
+
const attemptError = Object.assign(error, { attemptNumber: attempt });
|
|
1088
|
+
if (options.onFailedAttempt) {
|
|
1089
|
+
await options.onFailedAttempt(attemptError);
|
|
1090
|
+
}
|
|
1091
|
+
if (attempt > options.retries) {
|
|
1092
|
+
throw error;
|
|
1093
|
+
}
|
|
1094
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1095
|
+
delay *= options.factor;
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
throw lastError;
|
|
1099
|
+
}
|
|
1100
|
+
function createLimitPolicy({
|
|
1101
|
+
throttle = { interval: 1e3, limit: 10 },
|
|
1102
|
+
retry: retryOptions = { retries: 1, factor: 1.66 },
|
|
1103
|
+
limit = 10
|
|
1104
|
+
}) {
|
|
1105
|
+
const throttler = throttle ? createThrottler(throttle.limit, throttle.interval) : null;
|
|
1106
|
+
const limiter = limit ? createLimiter(limit) : null;
|
|
1107
|
+
return function limitPolicy(func) {
|
|
1108
|
+
let currentFunc = async () => await func();
|
|
1109
|
+
if (throttler) {
|
|
1110
|
+
const throttleFunc = currentFunc;
|
|
1111
|
+
currentFunc = () => throttler(throttleFunc);
|
|
1112
|
+
}
|
|
1113
|
+
if (limiter) {
|
|
1114
|
+
const limitFunc = currentFunc;
|
|
1115
|
+
currentFunc = () => limiter(limitFunc);
|
|
1116
|
+
}
|
|
1117
|
+
if (retryOptions) {
|
|
1118
|
+
const retryFunc = currentFunc;
|
|
1119
|
+
currentFunc = () => retry(retryFunc, {
|
|
1120
|
+
...retryOptions,
|
|
1121
|
+
onFailedAttempt: async (error) => {
|
|
1122
|
+
if (retryOptions.onFailedAttempt) {
|
|
1123
|
+
await retryOptions.onFailedAttempt(error);
|
|
1124
|
+
}
|
|
1125
|
+
if (error instanceof import_api28.ApiClientError && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
|
|
1126
|
+
throw error;
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
});
|
|
1130
|
+
}
|
|
1131
|
+
return currentFunc();
|
|
1132
|
+
};
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
// src/clients/tags.ts
|
|
1136
|
+
var generateManifestCacheTags = () => {
|
|
1137
|
+
return ["manifest"];
|
|
1138
|
+
};
|
|
1139
|
+
|
|
1140
|
+
// src/clients/manifest.ts
|
|
1141
|
+
var getManifestClient = (options) => {
|
|
1142
|
+
const cache = resolveManifestCache(options);
|
|
1143
|
+
const manifestClient = new import_api29.ManifestClient({
|
|
1144
|
+
apiHost: env.getApiHost(),
|
|
1145
|
+
apiKey: env.getApiKey(),
|
|
1146
|
+
projectId: env.getProjectId(),
|
|
1147
|
+
limitPolicy: createLimitPolicy({
|
|
1148
|
+
limit: 6
|
|
1149
|
+
}),
|
|
1150
|
+
fetch: (req, init) => {
|
|
1151
|
+
const { cache: fetchCache, revalidate } = determineFetchCacheOptions(cache);
|
|
1152
|
+
return fetch(req, {
|
|
1153
|
+
...init,
|
|
1154
|
+
headers: {
|
|
1155
|
+
...init == null ? void 0 : init.headers,
|
|
1156
|
+
"x-bypass-cache": typeof cache.bypassCache !== "undefined" ? cache.bypassCache.toString() : "false"
|
|
1157
|
+
},
|
|
1158
|
+
cache: fetchCache,
|
|
1159
|
+
next: {
|
|
1160
|
+
revalidate,
|
|
1161
|
+
tags: generateManifestCacheTags()
|
|
1162
|
+
}
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
});
|
|
1166
|
+
return manifestClient;
|
|
1167
|
+
};
|
|
1168
|
+
|
|
1169
|
+
// src/manifest/createCachedManifestProvider.ts
|
|
1170
|
+
var createCachedManifestProvider = ({
|
|
1171
|
+
cache,
|
|
1172
|
+
fallback,
|
|
1173
|
+
ttl = 3600,
|
|
1174
|
+
maxAge = 10,
|
|
1175
|
+
fetchManifest = fetchPublishedManifest
|
|
1176
|
+
} = {}) => {
|
|
1177
|
+
let current;
|
|
1178
|
+
let pending;
|
|
1179
|
+
const load = async ({ waitUntil }) => {
|
|
1180
|
+
var _a;
|
|
1181
|
+
const key = `uniform-manifest-${(_a = env.getProjectId()) != null ? _a : ""}`;
|
|
1182
|
+
const cached = await (cache == null ? void 0 : cache.get(key).catch(() => void 0));
|
|
1183
|
+
if (isManifest(cached)) {
|
|
1184
|
+
return cached;
|
|
1185
|
+
}
|
|
1186
|
+
const manifest = await fetchManifest();
|
|
1187
|
+
if (cache) {
|
|
1188
|
+
waitUntil(cache.set(key, manifest, { ttl, tags: generateManifestCacheTags() }).catch(() => {
|
|
1189
|
+
}));
|
|
1190
|
+
}
|
|
1191
|
+
return manifest;
|
|
1192
|
+
};
|
|
1193
|
+
return async (options) => {
|
|
1194
|
+
var _a;
|
|
1195
|
+
if (current && Date.now() - current.loadedAt < maxAge * 1e3) {
|
|
1196
|
+
return current.manifest;
|
|
1197
|
+
}
|
|
1198
|
+
pending != null ? pending : pending = load(options).then((manifest) => {
|
|
1199
|
+
current = { manifest, loadedAt: Date.now() };
|
|
1200
|
+
return manifest;
|
|
1201
|
+
}).finally(() => {
|
|
1202
|
+
pending = void 0;
|
|
1203
|
+
});
|
|
1204
|
+
try {
|
|
1205
|
+
return await pending;
|
|
1206
|
+
} catch (error) {
|
|
1207
|
+
const known = (_a = current == null ? void 0 : current.manifest) != null ? _a : fallback;
|
|
1208
|
+
if (known) {
|
|
1209
|
+
return known;
|
|
1210
|
+
}
|
|
1211
|
+
throw error;
|
|
1212
|
+
}
|
|
1213
|
+
};
|
|
1214
|
+
};
|
|
1215
|
+
var fetchPublishedManifest = () => getManifestClient({ cache: { type: "no-store" } }).get({ preview: false });
|
|
1216
|
+
var isManifest = (value) => typeof value === "object" && value !== null && "project" in value;
|
|
1217
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1218
|
+
0 && (module.exports = {
|
|
1219
|
+
UNIFORM_EDGE_ORIGIN_HEADER,
|
|
1220
|
+
createCachedManifestProvider,
|
|
1221
|
+
createLearnedEdgeRouteFilter,
|
|
1222
|
+
createStaticEdgeRouteFilter,
|
|
1223
|
+
handleUniformEdgeRoute,
|
|
1224
|
+
uniformEdgeMiddleware
|
|
1225
|
+
});
|