@uniformdev/next-app-router 20.81.1-alpha.4.sha-de16ebeee7 → 20.81.1

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/edge.js DELETED
@@ -1,751 +0,0 @@
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
- handleUniformEdgeRoute: () => handleUniformEdgeRoute,
35
- uniformEdgeMiddleware: () => uniformEdgeMiddleware
36
- });
37
- module.exports = __toCommonJS(edge_exports);
38
-
39
- // src/edge/uniformEdgeMiddleware.ts
40
- var import_context_edge = require("@uniformdev/context-edge");
41
- var import_server2 = require("next/server");
42
-
43
- // ../canvas/dist/index.mjs
44
- var import_api = require("@uniformdev/context/api");
45
- var import_api2 = require("@uniformdev/context/api");
46
- var import_api3 = require("@uniformdev/context/api");
47
- var import_api4 = require("@uniformdev/context/api");
48
- var import_api5 = require("@uniformdev/context/api");
49
- var import_api6 = require("@uniformdev/context/api");
50
- var import_api7 = require("@uniformdev/context/api");
51
- var import_api8 = require("@uniformdev/context/api");
52
- var import_api9 = require("@uniformdev/context/api");
53
- var import_api10 = require("@uniformdev/context/api");
54
- var import_api11 = require("@uniformdev/context/api");
55
- var import_api12 = require("@uniformdev/context/api");
56
- var import_api13 = require("@uniformdev/context/api");
57
- var import_api14 = require("@uniformdev/context/api");
58
- var import_api15 = require("@uniformdev/context/api");
59
- var import_api16 = require("@uniformdev/context/api");
60
- var import_api17 = require("@uniformdev/context/api");
61
- var import_api18 = require("@uniformdev/context/api");
62
- var import_api19 = require("@uniformdev/context/api");
63
- var import_api20 = require("@uniformdev/context/api");
64
- var import_api21 = require("@uniformdev/context/api");
65
- var import_api22 = require("@uniformdev/context/api");
66
- var import_api23 = require("@uniformdev/context/api");
67
- var import_api24 = require("@uniformdev/context/api");
68
- var import_api25 = require("@uniformdev/context/api");
69
- var import_api26 = require("@uniformdev/context/api");
70
- var import_api27 = require("@uniformdev/context/api");
71
- var __typeError = (msg) => {
72
- throw TypeError(msg);
73
- };
74
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
75
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
76
- 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);
77
- var SELECT_QUERY_PREFIX = "select.";
78
- function appendCsv(out, key, values) {
79
- if (values === void 0) {
80
- return;
81
- }
82
- out[key] = values.join(",");
83
- }
84
- function projectionToQuery(spec) {
85
- const out = {};
86
- if (!spec) {
87
- return out;
88
- }
89
- const { fields, fieldTypes, slots } = spec;
90
- const p = SELECT_QUERY_PREFIX;
91
- if (fields) {
92
- appendCsv(out, `${p}fields[only]`, fields.only);
93
- appendCsv(out, `${p}fields[except]`, fields.except);
94
- appendCsv(out, `${p}fields[locales]`, fields.locales);
95
- if (fields.blockDepth === "preserveAll" || typeof fields.blockDepth === "number") {
96
- out[`${p}fields[blockDepth]`] = String(fields.blockDepth);
97
- }
98
- }
99
- if (fieldTypes) {
100
- appendCsv(out, `${p}fieldTypes[only]`, fieldTypes.only);
101
- appendCsv(out, `${p}fieldTypes[except]`, fieldTypes.except);
102
- }
103
- if (slots) {
104
- appendCsv(out, `${p}slots[only]`, slots.only);
105
- appendCsv(out, `${p}slots[except]`, slots.except);
106
- if (typeof slots.depth === "number") {
107
- out[`${p}slots[depth]`] = String(slots.depth);
108
- }
109
- if (slots.named) {
110
- const slotNames = Object.keys(slots.named).sort();
111
- for (const slotName of slotNames) {
112
- const named = slots.named[slotName];
113
- if (named && typeof named.depth === "number") {
114
- out[`${p}slots.${slotName}[depth]`] = String(named.depth);
115
- }
116
- }
117
- }
118
- }
119
- return out;
120
- }
121
- var CANVAS_DRAFT_STATE = 0;
122
- var CANVAS_PUBLISHED_STATE = 64;
123
- var CANVAS_EDITOR_STATE = 63;
124
- var CANVAS_INTERNAL_PARAM_PREFIX = "$internal_";
125
- var CANVAS_COMPONENT_DISPLAY_NAME_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}displayName`;
126
- var CANVAS_HYPOTHESIS_PARAM = `${CANVAS_INTERNAL_PARAM_PREFIX}hypothesis`;
127
- var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
128
- var IN_CONTEXT_EDITOR_FORCED_SETTINGS_QUERY_STRING_PARAM = "is_incontext_editing_forced_settings";
129
- var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
130
- var _contentTypesUrl;
131
- var _entriesUrl;
132
- var _ContentClient = class _ContentClient2 extends import_api12.ApiClient {
133
- constructor(options) {
134
- var _a;
135
- super(options);
136
- this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
137
- }
138
- getContentTypes(options) {
139
- const { projectId } = this.options;
140
- const fetchUri = this.createUrl(__privateGet(_ContentClient2, _contentTypesUrl), { ...options, projectId });
141
- return this.apiClient(fetchUri);
142
- }
143
- getEntries(options) {
144
- const { projectId } = this.options;
145
- const { skipDataResolution, filters, select, ...params } = options;
146
- const rewrittenFilters = (0, import_api12.rewriteFiltersForApi)(filters);
147
- const rewrittenSelect = projectionToQuery(select);
148
- if (skipDataResolution) {
149
- const url = this.createUrl(__privateGet(_ContentClient2, _entriesUrl), {
150
- ...params,
151
- ...rewrittenFilters,
152
- ...rewrittenSelect,
153
- projectId
154
- });
155
- return this.apiClient(url);
156
- }
157
- const edgeUrl = this.createUrl(
158
- __privateGet(_ContentClient2, _entriesUrl),
159
- { ...this.getEdgeOptions(params), ...rewrittenFilters, ...rewrittenSelect },
160
- this.edgeApiHost
161
- );
162
- return this.apiClient(
163
- edgeUrl,
164
- this.options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0
165
- );
166
- }
167
- /** Fetches historical versions of an entry */
168
- async getEntryHistory(options) {
169
- const historyUrl = this.createUrl("/api/v1/entries-history", {
170
- ...options,
171
- projectId: this.options.projectId
172
- });
173
- return this.apiClient(historyUrl);
174
- }
175
- async upsertContentType(body, opts = {}) {
176
- const fetchUri = this.createUrl(__privateGet(_ContentClient2, _contentTypesUrl));
177
- if (typeof body.contentType.slugSettings === "object" && body.contentType.slugSettings !== null && Object.keys(body.contentType.slugSettings).length === 0) {
178
- delete body.contentType.slugSettings;
179
- }
180
- await this.apiClient(fetchUri, {
181
- method: "PUT",
182
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
183
- expectNoContent: true,
184
- headers: opts.autogenerateDataTypes ? { "x-uniform-autogenerate-data-types": "true" } : {}
185
- });
186
- }
187
- async upsertEntry(body, options) {
188
- const fetchUri = this.createUrl(__privateGet(_ContentClient2, _entriesUrl));
189
- const headers = {};
190
- if (options == null ? void 0 : options.ifUnmodifiedSince) {
191
- headers["x-if-unmodified-since"] = options.ifUnmodifiedSince;
192
- }
193
- const { response } = await this.apiClientWithResponse(fetchUri, {
194
- method: "PUT",
195
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
196
- expectNoContent: true,
197
- headers
198
- });
199
- return { modified: response.headers.get("x-modified-at") };
200
- }
201
- async deleteContentType(body) {
202
- const fetchUri = this.createUrl(__privateGet(_ContentClient2, _contentTypesUrl));
203
- await this.apiClient(fetchUri, {
204
- method: "DELETE",
205
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
206
- expectNoContent: true
207
- });
208
- }
209
- async deleteEntry(body) {
210
- const fetchUri = this.createUrl(__privateGet(_ContentClient2, _entriesUrl));
211
- await this.apiClient(fetchUri, {
212
- method: "DELETE",
213
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
214
- expectNoContent: true
215
- });
216
- }
217
- getEdgeOptions(options) {
218
- const { projectId } = this.options;
219
- const { skipDataResolution, ...params } = options;
220
- return {
221
- projectId,
222
- ...params,
223
- diagnostics: typeof options.diagnostics === "boolean" ? options.diagnostics : options.diagnostics === "no-data" ? "no-data" : void 0
224
- };
225
- }
226
- };
227
- _contentTypesUrl = /* @__PURE__ */ new WeakMap();
228
- _entriesUrl = /* @__PURE__ */ new WeakMap();
229
- __privateAdd(_ContentClient, _contentTypesUrl, "/api/v1/content-types");
230
- __privateAdd(_ContentClient, _entriesUrl, "/api/v1/entries");
231
- var _url;
232
- var _DataTypeClient = class _DataTypeClient2 extends import_api14.ApiClient {
233
- constructor(options) {
234
- super(options);
235
- }
236
- /** Fetches a list of DataTypes for a project */
237
- async list(options) {
238
- const { projectId } = this.options;
239
- const fetchUri = this.createUrl(__privateGet(_DataTypeClient2, _url), { ...options, projectId });
240
- return await this.apiClient(fetchUri);
241
- }
242
- /** @deprecated Use {@link list} instead. */
243
- async get(options) {
244
- return this.list(options);
245
- }
246
- /** Updates or creates (based on id) a DataType */
247
- async save(body) {
248
- const fetchUri = this.createUrl(__privateGet(_DataTypeClient2, _url));
249
- await this.apiClient(fetchUri, {
250
- method: "PUT",
251
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
252
- expectNoContent: true
253
- });
254
- }
255
- /** @deprecated Use {@link save} instead. */
256
- async upsert(body) {
257
- return this.save(body);
258
- }
259
- /** Deletes a DataType */
260
- async remove(body) {
261
- const fetchUri = this.createUrl(__privateGet(_DataTypeClient2, _url));
262
- await this.apiClient(fetchUri, {
263
- method: "DELETE",
264
- body: JSON.stringify({ ...body, projectId: this.options.projectId }),
265
- expectNoContent: true
266
- });
267
- }
268
- };
269
- _url = /* @__PURE__ */ new WeakMap();
270
- __privateAdd(_DataTypeClient, _url, "/api/v1/data-types");
271
- var _baseUrl;
272
- var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2 extends import_api16.ApiClient {
273
- constructor(options) {
274
- super(options);
275
- this.teamId = options.teamId;
276
- }
277
- /**
278
- * Gets a list of property type and hook names for the current team, including public integrations' hooks.
279
- */
280
- get(options) {
281
- const fetchUri = this.createUrl(__privateGet(_IntegrationPropertyEditorsClient2, _baseUrl), {
282
- ...options,
283
- teamId: this.teamId
284
- });
285
- return this.apiClient(fetchUri);
286
- }
287
- /**
288
- * Creates or updates a custom AI property editor on a Mesh app.
289
- */
290
- async deploy(body) {
291
- const fetchUri = this.createUrl(__privateGet(_IntegrationPropertyEditorsClient2, _baseUrl));
292
- await this.apiClient(fetchUri, {
293
- method: "PUT",
294
- body: JSON.stringify({ ...body, teamId: this.teamId }),
295
- expectNoContent: true
296
- });
297
- }
298
- /**
299
- * Removes a custom AI property editor from a Mesh app.
300
- */
301
- async delete(body) {
302
- const fetchUri = this.createUrl(__privateGet(_IntegrationPropertyEditorsClient2, _baseUrl));
303
- await this.apiClient(fetchUri, {
304
- method: "DELETE",
305
- body: JSON.stringify({ ...body, teamId: this.teamId }),
306
- expectNoContent: true
307
- });
308
- }
309
- };
310
- _baseUrl = /* @__PURE__ */ new WeakMap();
311
- __privateAdd(_IntegrationPropertyEditorsClient, _baseUrl, "/api/v1/integration-property-editors");
312
- var _url2;
313
- var _projectsUrl;
314
- var _ProjectClient = class _ProjectClient2 extends import_api20.ApiClient {
315
- constructor(options) {
316
- super({ ...options, bypassCache: true });
317
- }
318
- /** Fetches single Project */
319
- async get(options) {
320
- const fetchUri = this.createUrl(__privateGet(_ProjectClient2, _url2), { ...options });
321
- return await this.apiClient(fetchUri);
322
- }
323
- /**
324
- * Fetches projects grouped by team.
325
- * When teamId is provided, returns a single team with its projects.
326
- * When omitted, returns all accessible teams and their projects.
327
- */
328
- async list(options) {
329
- const fetchUri = this.createUrl(__privateGet(_ProjectClient2, _projectsUrl), options ? { ...options } : {});
330
- return await this.apiClient(fetchUri);
331
- }
332
- /** @deprecated Use {@link list} instead. */
333
- async getProjects(options) {
334
- return this.list(options);
335
- }
336
- /** Updates or creates (based on id) a Project */
337
- async save(body) {
338
- const fetchUri = this.createUrl(__privateGet(_ProjectClient2, _url2));
339
- return await this.apiClient(fetchUri, {
340
- method: "PUT",
341
- body: JSON.stringify({ ...body })
342
- });
343
- }
344
- /** @deprecated Use {@link save} instead. */
345
- async upsert(body) {
346
- return this.save(body);
347
- }
348
- /** Deletes a Project */
349
- async remove(body) {
350
- const fetchUri = this.createUrl(__privateGet(_ProjectClient2, _url2));
351
- await this.apiClient(fetchUri, {
352
- method: "DELETE",
353
- body: JSON.stringify({ ...body }),
354
- expectNoContent: true
355
- });
356
- }
357
- /** @deprecated Use {@link remove} instead. */
358
- async delete(body) {
359
- return this.remove(body);
360
- }
361
- };
362
- _url2 = /* @__PURE__ */ new WeakMap();
363
- _projectsUrl = /* @__PURE__ */ new WeakMap();
364
- __privateAdd(_ProjectClient, _url2, "/api/v1/project");
365
- __privateAdd(_ProjectClient, _projectsUrl, "/api/v1/projects");
366
-
367
- // src/middleware.ts
368
- var import_context = require("@uniformdev/context");
369
- var import_next_app_router_shared = require("@uniformdev/next-app-router-shared");
370
- var import_headers = require("next/headers");
371
- var import_server = require("next/server");
372
-
373
- // src/config/helpers.ts
374
- var import_resolved = __toESM(require("@uniformdev/next-app-router/config/resolved"));
375
- var getServerConfig = () => {
376
- return import_resolved.default;
377
- };
378
- var getDefaultConsent = () => {
379
- if (typeof import_resolved.default.defaultConsent === "boolean") {
380
- return import_resolved.default.defaultConsent;
381
- }
382
- return false;
383
- };
384
- var getQuirkSerialization = () => {
385
- if (typeof import_resolved.default.quirkSerialization === "boolean") {
386
- return import_resolved.default.quirkSerialization;
387
- }
388
- return true;
389
- };
390
- var getPlaygroundPath = () => {
391
- if (typeof import_resolved.default.playgroundPath === "string") {
392
- return import_resolved.default.playgroundPath;
393
- }
394
- return "/uniform/playground";
395
- };
396
-
397
- // src/data/routes.ts
398
- var findRouteMatch = (routes, path) => {
399
- const pieces = path.split("/").filter(Boolean);
400
- for (const route of routes) {
401
- const patternPieces = route.pattern.split("/").filter(Boolean);
402
- if (patternPieces.length !== pieces.length) {
403
- continue;
404
- }
405
- let match = true;
406
- const params = {};
407
- for (let i = 0; i < patternPieces.length; i++) {
408
- const patternPiece = patternPieces[i];
409
- const piece = pieces[i];
410
- if (patternPiece.startsWith(":")) {
411
- const paramName = patternPiece.slice(1);
412
- params[paramName] = piece;
413
- } else if (patternPiece !== piece) {
414
- match = false;
415
- break;
416
- }
417
- }
418
- if (match) {
419
- return {
420
- route,
421
- params
422
- };
423
- }
424
- }
425
- return void 0;
426
- };
427
-
428
- // src/utils/draft.ts
429
- var isIncontextEditingEnabled = ({
430
- isDraftModeEnabled,
431
- searchParams
432
- }) => {
433
- if (!isDraftModeEnabled) {
434
- return false;
435
- }
436
- const containsKey = searchParams.has(IN_CONTEXT_EDITOR_QUERY_STRING_PARAM);
437
- return containsKey;
438
- };
439
-
440
- // src/utils/quirks.ts
441
- var buildQuirksFromHeaders = (headers) => {
442
- const headerToQuirkKey = {
443
- "x-vercel-ip-country": "vc-country",
444
- "x-vercel-ip-country-region": "vc-region",
445
- "x-vercel-ip-city": "vc-city"
446
- };
447
- return Object.entries(headerToQuirkKey).reduce((acc, [headerName, quirkKey]) => {
448
- const value = headers.get(headerName);
449
- if (value) {
450
- acc[quirkKey] = value;
451
- }
452
- return acc;
453
- }, {});
454
- };
455
-
456
- // src/middleware.ts
457
- var resolveUniformRequest = async ({
458
- request,
459
- ...options
460
- }) => {
461
- const draftModeEnabled = (await (0, import_headers.draftMode)()).isEnabled;
462
- if (draftModeEnabled && isPlaygroundPath(request.nextUrl.pathname)) {
463
- return handlePlaygroundRequest({ request, options });
464
- }
465
- return resolveRouteRequest({ request, draftModeEnabled, options });
466
- };
467
- var isPlaygroundPath = (path) => {
468
- const { playgroundPath } = getServerConfig();
469
- if (!playgroundPath) {
470
- return false;
471
- }
472
- const PLAYGROUND_ID = "playground";
473
- const match = findRouteMatch(
474
- [
475
- {
476
- id: PLAYGROUND_ID,
477
- pattern: playgroundPath
478
- }
479
- ],
480
- path
481
- );
482
- return (match == null ? void 0 : match.route.id) === PLAYGROUND_ID;
483
- };
484
- var handlePlaygroundRequest = async ({
485
- request,
486
- options
487
- }) => {
488
- var _a, _b;
489
- const id = request.nextUrl.searchParams.get("id");
490
- if (!id) {
491
- return {
492
- type: "response",
493
- response: import_server.NextResponse.json({ error: "No id provided" }, { status: 400 })
494
- };
495
- }
496
- const playgroundPath = getPlaygroundPath();
497
- const pageState = {
498
- routePath: id,
499
- compositionState: CANVAS_EDITOR_STATE,
500
- keys: void 0,
501
- releaseId: (_a = options.release) == null ? void 0 : _a.id,
502
- defaultConsent: determineDefaultConsent({
503
- serverConfig: getServerConfig(),
504
- defaultConsent: options.defaultConsent
505
- }),
506
- previewMode: determinePreviewMode({
507
- searchParams: request.nextUrl.searchParams,
508
- isDraftModeEnabled: true
509
- }),
510
- locale: options.locale
511
- };
512
- const code = (0, import_next_app_router_shared.serializeEvaluationResult)({ payload: pageState });
513
- const destination = await ((_b = options.rewriteDestinationPath) == null ? void 0 : _b.call(options, { code, pageState, source: "playground" })) || `${playgroundPath}${playgroundPath.endsWith("/") ? "" : "/"}${code}`;
514
- return {
515
- type: "response",
516
- response: import_server.NextResponse.rewrite(new URL(destination, request.nextUrl.origin))
517
- };
518
- };
519
- var resolveRouteRequest = async ({
520
- request,
521
- draftModeEnabled,
522
- options
523
- }) => {
524
- var _a, _b, _c, _d, _e;
525
- const releaseId = (_b = (_a = options.release) == null ? void 0 : _a.id) != null ? _b : draftModeEnabled ? request.nextUrl.searchParams.get("releaseId") || void 0 : void 0;
526
- const requestPath = (_d = await ((_c = options.rewriteRequestPath) == null ? void 0 : _c.call(options, {
527
- request,
528
- url: new URL(request.url)
529
- }))) != null ? _d : {
530
- path: `${request.nextUrl.pathname}${request.nextUrl.search}`
531
- };
532
- const defaultConsent = determineDefaultConsent({
533
- serverConfig: getServerConfig(),
534
- defaultConsent: options.defaultConsent
535
- });
536
- const pageState = {
537
- routePath: buildRoutePath({ path: requestPath.path, queryStrings: options.queryStrings }),
538
- compositionState: determineCompositionState({
539
- searchParams: request.nextUrl.searchParams,
540
- draftModeEnabled
541
- }),
542
- keys: requestPath.keys,
543
- releaseId,
544
- defaultConsent,
545
- previewMode: determinePreviewMode({
546
- searchParams: request.nextUrl.searchParams,
547
- isDraftModeEnabled: draftModeEnabled
548
- }),
549
- locale: options.locale
550
- };
551
- const code = (0, import_next_app_router_shared.serializeEvaluationResult)({ payload: pageState });
552
- const destination = await ((_e = options.rewriteDestinationPath) == null ? void 0 : _e.call(options, { code, pageState, source: "route" })) || `/uniform/${code}`;
553
- const quirks = {
554
- ...buildQuirksFromHeaders(request.headers),
555
- ...options.quirks
556
- };
557
- const headers = new Headers();
558
- if (Object.keys(quirks).length > 0) {
559
- headers.append(
560
- "Set-Cookie",
561
- `${import_next_app_router_shared.UNIFORM_MIDDLEWARE_QUIRK_COOKIE_NAME}=${JSON.stringify(quirks)}; Path=/; SameSite=Lax; Max-Age=10`
562
- );
563
- }
564
- const createContext = async ({ manifest }) => {
565
- var _a2, _b2, _c2, _d2;
566
- const context = new import_context.Context({
567
- manifest,
568
- defaultConsent: defaultConsent != null ? defaultConsent : getDefaultConsent(),
569
- transitionStore: new import_context.CookieTransitionDataStore({
570
- serverCookieValue: (_b2 = (_a2 = request.cookies.get(import_context.UNIFORM_DEFAULT_COOKIE_NAME)) == null ? void 0 : _a2.value) != null ? _b2 : "",
571
- experimental_quirksEnabled: getQuirkSerialization(),
572
- quirkCookieValue: (_d2 = (_c2 = request.cookies.get(import_context.UNIFORM_DEFAULT_QUIRK_COOKIE_NAME)) == null ? void 0 : _c2.value) != null ? _d2 : ""
573
- })
574
- });
575
- await context.update({
576
- url: new URL(request.nextUrl.href),
577
- cookies: Object.fromEntries(request.cookies.getAll().map((cookie) => [cookie.name, cookie.value])),
578
- quirks
579
- });
580
- return context;
581
- };
582
- return {
583
- type: "rewrite",
584
- destination,
585
- pageState,
586
- code,
587
- headers,
588
- draftModeEnabled,
589
- createContext
590
- };
591
- };
592
- var buildRoutePath = ({
593
- path,
594
- queryStrings
595
- }) => {
596
- const [pathname = "", search] = path.split("?");
597
- if (!search || !queryStrings) {
598
- return pathname;
599
- }
600
- const patterns = Object.keys(queryStrings);
601
- const match = findRouteMatch(
602
- patterns.map((pattern) => ({ id: pattern, pattern })),
603
- pathname
604
- );
605
- const allowed = match ? queryStrings[match.route.id] : void 0;
606
- if (!(allowed == null ? void 0 : allowed.length)) {
607
- return pathname;
608
- }
609
- const requestSearchParams = new URLSearchParams(search);
610
- const searchParams = new URLSearchParams();
611
- [...allowed].sort().forEach((name) => {
612
- const value = requestSearchParams.get(name);
613
- if (value !== null) {
614
- searchParams.set(name, value);
615
- }
616
- });
617
- return searchParams.size ? `${pathname}?${searchParams.toString()}` : pathname;
618
- };
619
- var determineCompositionState = ({
620
- searchParams,
621
- draftModeEnabled
622
- }) => {
623
- if (!draftModeEnabled) {
624
- return CANVAS_PUBLISHED_STATE;
625
- }
626
- return isIncontextEditingEnabled({ isDraftModeEnabled: draftModeEnabled, searchParams }) ? CANVAS_EDITOR_STATE : CANVAS_DRAFT_STATE;
627
- };
628
- var determineDefaultConsent = ({
629
- serverConfig,
630
- defaultConsent
631
- }) => {
632
- return defaultConsent !== serverConfig.defaultConsent ? defaultConsent : void 0;
633
- };
634
- var determinePreviewMode = ({
635
- searchParams,
636
- isDraftModeEnabled
637
- }) => {
638
- if (!isDraftModeEnabled) {
639
- return void 0;
640
- }
641
- const queryStringSettings = searchParams.get(IN_CONTEXT_EDITOR_FORCED_SETTINGS_QUERY_STRING_PARAM);
642
- let previewSettings = void 0;
643
- if (queryStringSettings) {
644
- try {
645
- previewSettings = JSON.parse(queryStringSettings);
646
- } catch (e) {
647
- }
648
- }
649
- if (previewSettings == null ? void 0 : previewSettings.isVisualEditingDisabled) {
650
- return "preview";
651
- }
652
- const isInContextEditingEnabled = isIncontextEditingEnabled({ isDraftModeEnabled, searchParams });
653
- if (isInContextEditingEnabled) {
654
- return "editor";
655
- }
656
- return void 0;
657
- };
658
-
659
- // src/edge/uniformEdgeMiddleware.ts
660
- var UNIFORM_EDGE_ORIGIN_HEADER = "x-uniform-edge-origin";
661
- var uniformEdgeMiddleware = (options) => {
662
- return async (request) => {
663
- return handleUniformEdgeRoute({ request, ...options });
664
- };
665
- };
666
- var handleUniformEdgeRoute = async ({
667
- request,
668
- manifest,
669
- onError,
670
- ...options
671
- }) => {
672
- var _a;
673
- if (request.headers.has(UNIFORM_EDGE_ORIGIN_HEADER)) {
674
- return import_server2.NextResponse.next();
675
- }
676
- const result = await resolveUniformRequest({ request, ...options });
677
- if (result.type === "response") {
678
- return result.response;
679
- }
680
- const destination = new URL(result.destination, request.nextUrl.origin);
681
- if (result.draftModeEnabled || !isDocumentRequest(request)) {
682
- return import_server2.NextResponse.rewrite(destination, { headers: result.headers });
683
- }
684
- const [originResponse, context] = await Promise.all([
685
- fetch(destination, {
686
- headers: {
687
- cookie: (_a = request.headers.get("cookie")) != null ? _a : "",
688
- accept: "text/html",
689
- // Node's fetch decompresses the body but keeps the header, so ask for plain HTML.
690
- "accept-encoding": "identity",
691
- [UNIFORM_EDGE_ORIGIN_HEADER]: "1"
692
- }
693
- }),
694
- result.createContext({ manifest })
695
- ]);
696
- const headers = new Headers(originResponse.headers);
697
- headers.delete("content-length");
698
- headers.delete("content-encoding");
699
- headers.set("cache-control", "private, no-store");
700
- result.headers.forEach((value, key) => {
701
- headers.append(key, value);
702
- });
703
- return new Response(transformBody({ body: originResponse.body, context, onError }), {
704
- status: originResponse.status,
705
- statusText: originResponse.statusText,
706
- headers
707
- });
708
- };
709
- var isDocumentRequest = (request) => {
710
- var _a;
711
- return request.method === "GET" && !request.headers.has("rsc") && !request.headers.has("next-router-prefetch") && ((_a = request.headers.get("accept")) != null ? _a : "").includes("text/html");
712
- };
713
- var transformBody = ({
714
- body,
715
- context,
716
- onError
717
- }) => {
718
- if (!body) {
719
- return null;
720
- }
721
- const reader = body.getReader();
722
- const { readable, writable } = new TransformStream();
723
- const writer = writable.getWriter();
724
- void (0, import_context_edge.transformEdgeStream)({
725
- context,
726
- decoder: new TextDecoder(),
727
- encoder: new TextEncoder(),
728
- reader: {
729
- read: async () => {
730
- const { done, value } = await reader.read();
731
- return { done, value };
732
- }
733
- },
734
- writer: {
735
- write: (value) => {
736
- void writer.write(value);
737
- },
738
- close: () => {
739
- return writer.close();
740
- }
741
- },
742
- onError
743
- });
744
- return readable;
745
- };
746
- // Annotate the CommonJS export names for ESM import in node:
747
- 0 && (module.exports = {
748
- UNIFORM_EDGE_ORIGIN_HEADER,
749
- handleUniformEdgeRoute,
750
- uniformEdgeMiddleware
751
- });