@makeswift/runtime 0.23.7 → 0.23.8-canary.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.
Files changed (95) hide show
  1. package/dist/cjs/api/react.js +28 -7
  2. package/dist/cjs/api/react.js.map +1 -1
  3. package/dist/cjs/api/site-version.js +36 -0
  4. package/dist/cjs/api/site-version.js.map +1 -0
  5. package/dist/cjs/next/api-handler/handlers/draft-mode.js +78 -0
  6. package/dist/cjs/next/api-handler/handlers/draft-mode.js.map +1 -0
  7. package/dist/cjs/next/api-handler/handlers/manifest.js +1 -1
  8. package/dist/cjs/next/api-handler/handlers/preview-mode.js +71 -0
  9. package/dist/cjs/next/api-handler/handlers/preview-mode.js.map +1 -0
  10. package/dist/cjs/next/api-handler/handlers/proxy-draft-mode.js +2 -2
  11. package/dist/cjs/next/api-handler/handlers/proxy-draft-mode.js.map +1 -1
  12. package/dist/cjs/next/api-handler/handlers/proxy-preview-mode.js +2 -2
  13. package/dist/cjs/next/api-handler/handlers/proxy-preview-mode.js.map +1 -1
  14. package/dist/cjs/next/api-handler/index.js +20 -2
  15. package/dist/cjs/next/api-handler/index.js.map +1 -1
  16. package/dist/cjs/next/client.js +7 -6
  17. package/dist/cjs/next/client.js.map +1 -1
  18. package/dist/cjs/next/draft-mode/index.js +3 -3
  19. package/dist/cjs/next/draft-mode/index.js.map +1 -1
  20. package/dist/cjs/next/middleware/exceptions.js +59 -0
  21. package/dist/cjs/next/middleware/exceptions.js.map +1 -0
  22. package/dist/cjs/next/middleware/index.js +37 -0
  23. package/dist/cjs/next/middleware/index.js.map +1 -0
  24. package/dist/cjs/next/middleware/request-utils.js +167 -0
  25. package/dist/cjs/next/middleware/request-utils.js.map +1 -0
  26. package/dist/cjs/next/preview-mode.js +4 -9
  27. package/dist/cjs/next/preview-mode.js.map +1 -1
  28. package/dist/cjs/runtimes/react/components/RuntimeProvider.js +4 -2
  29. package/dist/cjs/runtimes/react/components/RuntimeProvider.js.map +1 -1
  30. package/dist/cjs/runtimes/react/host-api-client.js +5 -1
  31. package/dist/cjs/runtimes/react/host-api-client.js.map +1 -1
  32. package/dist/cjs/state/makeswift-api-client.js +21 -10
  33. package/dist/cjs/state/makeswift-api-client.js.map +1 -1
  34. package/dist/esm/api/react.js +28 -7
  35. package/dist/esm/api/react.js.map +1 -1
  36. package/dist/esm/api/site-version.js +10 -0
  37. package/dist/esm/api/site-version.js.map +1 -0
  38. package/dist/esm/next/api-handler/handlers/draft-mode.js +58 -0
  39. package/dist/esm/next/api-handler/handlers/draft-mode.js.map +1 -0
  40. package/dist/esm/next/api-handler/handlers/manifest.js +1 -1
  41. package/dist/esm/next/api-handler/handlers/preview-mode.js +51 -0
  42. package/dist/esm/next/api-handler/handlers/preview-mode.js.map +1 -0
  43. package/dist/esm/next/api-handler/handlers/proxy-draft-mode.js +1 -1
  44. package/dist/esm/next/api-handler/handlers/proxy-draft-mode.js.map +1 -1
  45. package/dist/esm/next/api-handler/handlers/proxy-preview-mode.js +1 -1
  46. package/dist/esm/next/api-handler/handlers/proxy-preview-mode.js.map +1 -1
  47. package/dist/esm/next/api-handler/index.js +24 -2
  48. package/dist/esm/next/api-handler/index.js.map +1 -1
  49. package/dist/esm/next/client.js +2 -1
  50. package/dist/esm/next/client.js.map +1 -1
  51. package/dist/esm/next/draft-mode/index.js +1 -1
  52. package/dist/esm/next/draft-mode/index.js.map +1 -1
  53. package/dist/esm/next/middleware/exceptions.js +29 -0
  54. package/dist/esm/next/middleware/exceptions.js.map +1 -0
  55. package/dist/esm/next/middleware/index.js +15 -0
  56. package/dist/esm/next/middleware/index.js.map +1 -0
  57. package/dist/esm/next/middleware/request-utils.js +146 -0
  58. package/dist/esm/next/middleware/request-utils.js.map +1 -0
  59. package/dist/esm/next/preview-mode.js +2 -5
  60. package/dist/esm/next/preview-mode.js.map +1 -1
  61. package/dist/esm/runtimes/react/components/RuntimeProvider.js +4 -2
  62. package/dist/esm/runtimes/react/components/RuntimeProvider.js.map +1 -1
  63. package/dist/esm/runtimes/react/host-api-client.js +5 -1
  64. package/dist/esm/runtimes/react/host-api-client.js.map +1 -1
  65. package/dist/esm/state/makeswift-api-client.js +21 -10
  66. package/dist/esm/state/makeswift-api-client.js.map +1 -1
  67. package/dist/types/api/react.d.ts +4 -1
  68. package/dist/types/api/react.d.ts.map +1 -1
  69. package/dist/types/api/site-version.d.ts +6 -0
  70. package/dist/types/api/site-version.d.ts.map +1 -0
  71. package/dist/types/next/api-handler/handlers/draft-mode.d.ts +20 -0
  72. package/dist/types/next/api-handler/handlers/draft-mode.d.ts.map +1 -0
  73. package/dist/types/next/api-handler/handlers/preview-mode.d.ts +20 -0
  74. package/dist/types/next/api-handler/handlers/preview-mode.d.ts.map +1 -0
  75. package/dist/types/next/api-handler/handlers/proxy-preview-mode.d.ts.map +1 -1
  76. package/dist/types/next/api-handler/index.d.ts +3 -1
  77. package/dist/types/next/api-handler/index.d.ts.map +1 -1
  78. package/dist/types/next/client.d.ts +1 -1
  79. package/dist/types/next/client.d.ts.map +1 -1
  80. package/dist/types/next/draft-mode/index.d.ts +2 -2
  81. package/dist/types/next/middleware/exceptions.d.ts +16 -0
  82. package/dist/types/next/middleware/exceptions.d.ts.map +1 -0
  83. package/dist/types/next/middleware/index.d.ts +2 -0
  84. package/dist/types/next/middleware/index.d.ts.map +1 -0
  85. package/dist/types/next/middleware/request-utils.d.ts +16 -0
  86. package/dist/types/next/middleware/request-utils.d.ts.map +1 -0
  87. package/dist/types/next/middleware/request-utils.test.d.ts +2 -0
  88. package/dist/types/next/middleware/request-utils.test.d.ts.map +1 -0
  89. package/dist/types/next/preview-mode.d.ts +3 -5
  90. package/dist/types/next/preview-mode.d.ts.map +1 -1
  91. package/dist/types/runtimes/react/components/RuntimeProvider.d.ts.map +1 -1
  92. package/dist/types/runtimes/react/host-api-client.d.ts.map +1 -1
  93. package/dist/types/state/makeswift-api-client.d.ts +2 -1
  94. package/dist/types/state/makeswift-api-client.d.ts.map +1 -1
  95. package/package.json +10 -1
@@ -45,15 +45,22 @@ const CacheData = {
45
45
  }
46
46
  };
47
47
  class MakeswiftHostApiClient {
48
+ siteVersion;
48
49
  graphqlClient;
49
50
  makeswiftApiClient;
50
51
  subscribe;
51
- constructor({ uri, cacheData, locale }) {
52
+ constructor({
53
+ uri,
54
+ siteVersion,
55
+ cacheData,
56
+ locale
57
+ }) {
52
58
  this.graphqlClient = new import_client.GraphQLClient(uri);
53
59
  this.makeswiftApiClient = MakeswiftApiClient.configureStore({
54
60
  serializedState: cacheData,
55
61
  defaultLocale: locale
56
62
  });
63
+ this.siteVersion = siteVersion;
57
64
  this.subscribe = this.makeswiftApiClient.subscribe;
58
65
  }
59
66
  readSwatch(swatchId) {
@@ -65,7 +72,7 @@ class MakeswiftHostApiClient {
65
72
  }
66
73
  async fetchSwatch(swatchId) {
67
74
  return await this.makeswiftApiClient.dispatch(
68
- MakeswiftApiClient.fetchAPIResource(import_types.APIResourceType.Swatch, swatchId)
75
+ MakeswiftApiClient.fetchAPIResource(import_types.APIResourceType.Swatch, swatchId, this.siteVersion)
69
76
  );
70
77
  }
71
78
  resolveSwatch(swatchId) {
@@ -84,7 +91,7 @@ class MakeswiftHostApiClient {
84
91
  }
85
92
  async fetchFile(fileId) {
86
93
  return await this.makeswiftApiClient.dispatch(
87
- MakeswiftApiClient.fetchAPIResource(import_types.APIResourceType.File, fileId)
94
+ MakeswiftApiClient.fetchAPIResource(import_types.APIResourceType.File, fileId, this.siteVersion)
88
95
  );
89
96
  }
90
97
  resolveFile(fileId) {
@@ -103,7 +110,11 @@ class MakeswiftHostApiClient {
103
110
  }
104
111
  async fetchTypography(typographyId) {
105
112
  return await this.makeswiftApiClient.dispatch(
106
- MakeswiftApiClient.fetchAPIResource(import_types.APIResourceType.Typography, typographyId)
113
+ MakeswiftApiClient.fetchAPIResource(
114
+ import_types.APIResourceType.Typography,
115
+ typographyId,
116
+ this.siteVersion
117
+ )
107
118
  );
108
119
  }
109
120
  resolveTypography(typographyId) {
@@ -122,7 +133,11 @@ class MakeswiftHostApiClient {
122
133
  }
123
134
  async fetchGlobalElement(globalElementId) {
124
135
  return await this.makeswiftApiClient.dispatch(
125
- MakeswiftApiClient.fetchAPIResource(import_types.APIResourceType.GlobalElement, globalElementId)
136
+ MakeswiftApiClient.fetchAPIResource(
137
+ import_types.APIResourceType.GlobalElement,
138
+ globalElementId,
139
+ this.siteVersion
140
+ )
126
141
  );
127
142
  }
128
143
  readLocalizedGlobalElement({
@@ -144,6 +159,7 @@ class MakeswiftHostApiClient {
144
159
  MakeswiftApiClient.fetchAPIResource(
145
160
  import_types.APIResourceType.LocalizedGlobalElement,
146
161
  globalElementId,
162
+ this.siteVersion,
147
163
  locale
148
164
  )
149
165
  );
@@ -164,7 +180,12 @@ class MakeswiftHostApiClient {
164
180
  locale
165
181
  }) {
166
182
  return await this.makeswiftApiClient.dispatch(
167
- MakeswiftApiClient.fetchAPIResource(import_types.APIResourceType.PagePathnameSlice, pageId, locale)
183
+ MakeswiftApiClient.fetchAPIResource(
184
+ import_types.APIResourceType.PagePathnameSlice,
185
+ pageId,
186
+ this.siteVersion,
187
+ locale
188
+ )
168
189
  );
169
190
  }
170
191
  resolvePagePathnameSlice({
@@ -203,7 +224,7 @@ class MakeswiftHostApiClient {
203
224
  }
204
225
  async fetchTable(tableId) {
205
226
  return await this.makeswiftApiClient.dispatch(
206
- MakeswiftApiClient.fetchAPIResource(import_types.APIResourceType.Table, tableId)
227
+ MakeswiftApiClient.fetchAPIResource(import_types.APIResourceType.Table, tableId, this.siteVersion)
207
228
  );
208
229
  }
209
230
  async createTableRecord(tableId, columns) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/api/react.ts"],"sourcesContent":["import { type FetchableValue } from '@makeswift/controls'\nimport * as MakeswiftApiClient from '../state/makeswift-api-client'\nimport {\n APIResourceType,\n File,\n GlobalElement,\n LocalizedGlobalElement,\n Page,\n PagePathnameSlice,\n Site,\n Snippet,\n Swatch,\n Table,\n Typography,\n} from './types'\nimport { GraphQLClient } from './graphql/client'\nimport { CreateTableRecordMutation } from './graphql/documents'\nimport {\n CreateTableRecordMutationResult,\n CreateTableRecordMutationVariables,\n} from './graphql/generated/types'\n\nexport type CacheData = MakeswiftApiClient.SerializedState\n\nexport const CacheData = {\n empty(): CacheData {\n return {\n apiResources: {},\n localizedResourcesMap: {},\n }\n },\n}\n\n/**\n * NOTE(miguel): This \"client\" is used to fetch Makeswift API resources needed for the host. For\n * example, swatches, files, typographies, etc. Ideally it's internal to the runtime and is only\n * used by controls to transform API references to API resources.\n *\n * Moreover, its use should be reserved for the builder only, since for live pages all Makeswift\n * API resources should be embedded in the \"page snapshot\". In the builder, this client serves the\n * purpose of sending requests for API resources and keeping a cache so that changes that happen in\n * the builder, like modifying a swatch, can be sent via `postMessage` to the host and the cache can\n * immediately update the value and re-render.\n *\n * Furthermore, the API resources requested shouldn't be requested directly from the Makeswift API\n * as that would require those resources to not be authenticated since the requests come from the\n * browser when running the host. Instead, the requests should go to the host directly, at the\n * Makeswift API endpoint (i.g., `/api/makeswift/[...makeswift]` dynamic route) where the host's\n * API key can be used, securely, in the server. For this reason, this client should really be a\n * client of the host's API, not Makeswift's, intended to build and continuously maintain a realtime\n * snapshot for use in the builder, not the lives pages.\n */\nexport class MakeswiftHostApiClient {\n graphqlClient: GraphQLClient\n makeswiftApiClient: MakeswiftApiClient.Store\n subscribe: MakeswiftApiClient.Store['subscribe']\n\n constructor({ uri, cacheData, locale }: { uri: string; cacheData?: CacheData; locale?: string }) {\n this.graphqlClient = new GraphQLClient(uri)\n this.makeswiftApiClient = MakeswiftApiClient.configureStore({\n serializedState: cacheData,\n defaultLocale: locale,\n })\n\n this.subscribe = this.makeswiftApiClient.subscribe\n }\n\n readSwatch(swatchId: string): Swatch | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Swatch,\n swatchId,\n )\n }\n\n async fetchSwatch(swatchId: string): Promise<Swatch | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Swatch, swatchId),\n )\n }\n\n resolveSwatch(swatchId: string | undefined): FetchableValue<Swatch | null> {\n return this.resolveResource(APIResourceType.Swatch, {\n id: swatchId,\n read: id => this.readSwatch(id),\n fetch: id => this.fetchSwatch(id),\n })\n }\n\n readFile(fileId: string): File | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.File,\n fileId,\n )\n }\n\n async fetchFile(fileId: string): Promise<File | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.File, fileId),\n )\n }\n\n resolveFile(fileId: string | undefined): FetchableValue<File | null> {\n return this.resolveResource(APIResourceType.File, {\n id: fileId,\n read: id => this.readFile(id),\n fetch: id => this.fetchFile(id),\n })\n }\n\n readTypography(typographyId: string): Typography | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Typography,\n typographyId,\n )\n }\n\n async fetchTypography(typographyId: string): Promise<Typography | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Typography, typographyId),\n )\n }\n\n resolveTypography(typographyId: string | undefined): FetchableValue<Typography | null> {\n return this.resolveResource(APIResourceType.Typography, {\n id: typographyId,\n read: id => this.readTypography(id),\n fetch: id => this.fetchTypography(id),\n })\n }\n\n readGlobalElement(globalElementId: string): GlobalElement | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.GlobalElement,\n globalElementId,\n )\n }\n\n async fetchGlobalElement(globalElementId: string): Promise<GlobalElement | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.GlobalElement, globalElementId),\n )\n }\n\n readLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): LocalizedGlobalElement | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n locale,\n )\n }\n\n async fetchLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): Promise<LocalizedGlobalElement | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n locale,\n ),\n )\n }\n\n readPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): PagePathnameSlice | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.PagePathnameSlice,\n pageId,\n locale,\n )\n }\n\n async fetchPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): Promise<PagePathnameSlice | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.PagePathnameSlice, pageId, locale),\n )\n }\n\n resolvePagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string | undefined\n locale: string | null\n }): FetchableValue<PagePathnameSlice | null> {\n return this.resolveResource(APIResourceType.PagePathnameSlice, {\n id: pageId,\n read: id => this.readPagePathnameSlice({ pageId: id, locale }),\n fetch: id => this.fetchPagePathnameSlice({ pageId: id, locale }),\n })\n }\n\n resolveResource<R>(\n type: APIResourceType,\n {\n id,\n read,\n fetch,\n }: {\n id: string | undefined\n read: (id: string) => R | null\n fetch: (id: string) => Promise<R | null>\n },\n ): FetchableValue<R | null> {\n const _read = () => (id != null ? read(id) : null)\n let lastValue: R | null = null\n return {\n name: `${type}:${id}`,\n readStable: () => (lastValue = _read()),\n subscribe: (onUpdate: () => void) =>\n this.subscribe(() => {\n if (_read() !== lastValue) onUpdate()\n }),\n fetch: async () => (id != null ? fetch(id) : null),\n }\n }\n\n readTable(tableId: string): Table | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Table,\n tableId,\n )\n }\n\n async fetchTable(tableId: string): Promise<Table | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Table, tableId),\n )\n }\n\n async createTableRecord(tableId: string, columns: any): Promise<void> {\n await this.graphqlClient.request<\n CreateTableRecordMutationResult,\n CreateTableRecordMutationVariables\n >(CreateTableRecordMutation, { input: { data: { tableId, columns } } })\n }\n\n readSite(siteId: string): Site | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Site,\n siteId,\n )\n }\n\n readPage(pageId: string): Page | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Page,\n pageId,\n )\n }\n\n readSnippet(snippetId: string): Snippet | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Snippet,\n snippetId,\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,yBAAoC;AACpC,mBAYO;AACP,oBAA8B;AAC9B,uBAA0C;AAQnC,MAAM,YAAY;AAAA,EACvB,QAAmB;AACjB,WAAO;AAAA,MACL,cAAc,CAAC;AAAA,MACf,uBAAuB,CAAC;AAAA,IAC1B;AAAA,EACF;AACF;AAqBO,MAAM,uBAAuB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YAAY,EAAE,KAAK,WAAW,OAAO,GAA4D;AAC/F,SAAK,gBAAgB,IAAI,4BAAc,GAAG;AAC1C,SAAK,qBAAqB,mBAAmB,eAAe;AAAA,MAC1D,iBAAiB;AAAA,MACjB,eAAe;AAAA,IACjB,CAAC;AAED,SAAK,YAAY,KAAK,mBAAmB;AAAA,EAC3C;AAAA,EAEA,WAAW,UAAiC;AAC1C,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,6BAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AA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AAAA,EAEA,YAAY,WAAmC;AAC7C,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,6BAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/api/react.ts"],"sourcesContent":["import { type FetchableValue } from '@makeswift/controls'\nimport * as MakeswiftApiClient from '../state/makeswift-api-client'\nimport {\n APIResourceType,\n File,\n GlobalElement,\n LocalizedGlobalElement,\n Page,\n PagePathnameSlice,\n Site,\n Snippet,\n Swatch,\n Table,\n Typography,\n} from './types'\nimport { GraphQLClient } from './graphql/client'\nimport { CreateTableRecordMutation } from './graphql/documents'\nimport {\n CreateTableRecordMutationResult,\n CreateTableRecordMutationVariables,\n} from './graphql/generated/types'\nimport { MakeswiftSiteVersion } from './site-version'\n\nexport type CacheData = MakeswiftApiClient.SerializedState\n\nexport const CacheData = {\n empty(): CacheData {\n return {\n apiResources: {},\n localizedResourcesMap: {},\n }\n },\n}\n\n/**\n * NOTE(miguel): This \"client\" is used to fetch Makeswift API resources needed for the host. For\n * example, swatches, files, typographies, etc. Ideally it's internal to the runtime and is only\n * used by controls to transform API references to API resources.\n *\n * Moreover, its use should be reserved for the builder only, since for live pages all Makeswift\n * API resources should be embedded in the \"page snapshot\". In the builder, this client serves the\n * purpose of sending requests for API resources and keeping a cache so that changes that happen in\n * the builder, like modifying a swatch, can be sent via `postMessage` to the host and the cache can\n * immediately update the value and re-render.\n *\n * Furthermore, the API resources requested shouldn't be requested directly from the Makeswift API\n * as that would require those resources to not be authenticated since the requests come from the\n * browser when running the host. Instead, the requests should go to the host directly, at the\n * Makeswift API endpoint (i.g., `/api/makeswift/[...makeswift]` dynamic route) where the host's\n * API key can be used, securely, in the server. For this reason, this client should really be a\n * client of the host's API, not Makeswift's, intended to build and continuously maintain a realtime\n * snapshot for use in the builder, not the lives pages.\n */\nexport class MakeswiftHostApiClient {\n siteVersion: MakeswiftSiteVersion\n graphqlClient: GraphQLClient\n makeswiftApiClient: MakeswiftApiClient.Store\n subscribe: MakeswiftApiClient.Store['subscribe']\n\n constructor({\n uri,\n siteVersion,\n cacheData,\n locale,\n }: {\n uri: string\n siteVersion: MakeswiftSiteVersion\n cacheData?: CacheData\n locale?: string\n }) {\n this.graphqlClient = new GraphQLClient(uri)\n this.makeswiftApiClient = MakeswiftApiClient.configureStore({\n serializedState: cacheData,\n defaultLocale: locale,\n })\n this.siteVersion = siteVersion\n this.subscribe = this.makeswiftApiClient.subscribe\n }\n\n readSwatch(swatchId: string): Swatch | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Swatch,\n swatchId,\n )\n }\n\n async fetchSwatch(swatchId: string): Promise<Swatch | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Swatch, swatchId, this.siteVersion),\n )\n }\n\n resolveSwatch(swatchId: string | undefined): FetchableValue<Swatch | null> {\n return this.resolveResource(APIResourceType.Swatch, {\n id: swatchId,\n read: id => this.readSwatch(id),\n fetch: id => this.fetchSwatch(id),\n })\n }\n\n readFile(fileId: string): File | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.File,\n fileId,\n )\n }\n\n async fetchFile(fileId: string): Promise<File | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.File, fileId, this.siteVersion),\n )\n }\n\n resolveFile(fileId: string | undefined): FetchableValue<File | null> {\n return this.resolveResource(APIResourceType.File, {\n id: fileId,\n read: id => this.readFile(id),\n fetch: id => this.fetchFile(id),\n })\n }\n\n readTypography(typographyId: string): Typography | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Typography,\n typographyId,\n )\n }\n\n async fetchTypography(typographyId: string): Promise<Typography | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.Typography,\n typographyId,\n this.siteVersion,\n ),\n )\n }\n\n resolveTypography(typographyId: string | undefined): FetchableValue<Typography | null> {\n return this.resolveResource(APIResourceType.Typography, {\n id: typographyId,\n read: id => this.readTypography(id),\n fetch: id => this.fetchTypography(id),\n })\n }\n\n readGlobalElement(globalElementId: string): GlobalElement | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.GlobalElement,\n globalElementId,\n )\n }\n\n async fetchGlobalElement(globalElementId: string): Promise<GlobalElement | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.GlobalElement,\n globalElementId,\n this.siteVersion,\n ),\n )\n }\n\n readLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): LocalizedGlobalElement | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n locale,\n )\n }\n\n async fetchLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): Promise<LocalizedGlobalElement | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n this.siteVersion,\n locale,\n ),\n )\n }\n\n readPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): PagePathnameSlice | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.PagePathnameSlice,\n pageId,\n locale,\n )\n }\n\n async fetchPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): Promise<PagePathnameSlice | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.PagePathnameSlice,\n pageId,\n this.siteVersion,\n locale,\n ),\n )\n }\n\n resolvePagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string | undefined\n locale: string | null\n }): FetchableValue<PagePathnameSlice | null> {\n return this.resolveResource(APIResourceType.PagePathnameSlice, {\n id: pageId,\n read: id => this.readPagePathnameSlice({ pageId: id, locale }),\n fetch: id => this.fetchPagePathnameSlice({ pageId: id, locale }),\n })\n }\n\n resolveResource<R>(\n type: APIResourceType,\n {\n id,\n read,\n fetch,\n }: {\n id: string | undefined\n read: (id: string) => R | null\n fetch: (id: string) => Promise<R | null>\n },\n ): FetchableValue<R | null> {\n const _read = () => (id != null ? read(id) : null)\n let lastValue: R | null = null\n return {\n name: `${type}:${id}`,\n readStable: () => (lastValue = _read()),\n subscribe: (onUpdate: () => void) =>\n this.subscribe(() => {\n if (_read() !== lastValue) onUpdate()\n }),\n fetch: async () => (id != null ? fetch(id) : null),\n }\n }\n\n readTable(tableId: string): Table | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Table,\n tableId,\n )\n }\n\n async fetchTable(tableId: string): Promise<Table | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Table, tableId, this.siteVersion),\n )\n }\n\n async createTableRecord(tableId: string, columns: any): Promise<void> {\n await this.graphqlClient.request<\n CreateTableRecordMutationResult,\n CreateTableRecordMutationVariables\n >(CreateTableRecordMutation, { input: { data: { tableId, columns } } })\n }\n\n readSite(siteId: string): Site | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Site,\n siteId,\n )\n }\n\n readPage(pageId: string): Page | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Page,\n pageId,\n )\n }\n\n readSnippet(snippetId: string): Snippet | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Snippet,\n snippetId,\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,yBAAoC;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ACtC,CAAC;AAAA,MACH,OAAO,YAAa,MAAM,OAAO,MAAM,EAAE,IAAI;AAAA,IAC/C;AAAA,EACF;AAAA,EAEA,UAAU,SAA+B;AACvC,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,6BAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,WAAW,SAAwC;AACvD,WAAO,MAAM,KAAK,mBAAmB;AAAA,MACnC,mBAAmB,iBAAiB,6BAAgB,OAAO,SAAS,KAAK,WAAW;AAAA,IACtF;AAAA,EACF;AAAA,EAEA,MAAM,kBAAkB,SAAiB,SAA6B;AACpE,UAAM,KAAK,cAAc,QAGvB,4CAA2B,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,QAAQ,EAAE,EAAE,CAAC;AAAA,EACxE;AAAA,EAEA,SAAS,QAA6B;AACpC,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,6BAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,SAAS,QAA6B;AACpC,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,6BAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,YAAY,WAAmC;AAC7C,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,6BAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var site_version_exports = {};
20
+ __export(site_version_exports, {
21
+ API_HANDLER_SITE_VERSION_HEADER: () => API_HANDLER_SITE_VERSION_HEADER,
22
+ MakeswiftSiteVersion: () => MakeswiftSiteVersion,
23
+ makeswiftSiteVersionSchema: () => makeswiftSiteVersionSchema
24
+ });
25
+ module.exports = __toCommonJS(site_version_exports);
26
+ var import_zod = require("zod");
27
+ const makeswiftSiteVersionSchema = import_zod.z.enum(["Live", "Working"]);
28
+ const MakeswiftSiteVersion = makeswiftSiteVersionSchema.Enum;
29
+ const API_HANDLER_SITE_VERSION_HEADER = "X-Makeswift-Site-Version";
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ API_HANDLER_SITE_VERSION_HEADER,
33
+ MakeswiftSiteVersion,
34
+ makeswiftSiteVersionSchema
35
+ });
36
+ //# sourceMappingURL=site-version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/api/site-version.ts"],"sourcesContent":["import { z } from 'zod'\n\nexport const makeswiftSiteVersionSchema = z.enum(['Live', 'Working'])\nexport const MakeswiftSiteVersion = makeswiftSiteVersionSchema.Enum\nexport type MakeswiftSiteVersion = z.infer<typeof makeswiftSiteVersionSchema>\n\nexport const API_HANDLER_SITE_VERSION_HEADER = 'X-Makeswift-Site-Version'\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAkB;AAEX,MAAM,6BAA6B,aAAE,KAAK,CAAC,QAAQ,SAAS,CAAC;AAC7D,MAAM,uBAAuB,2BAA2B;AAGxD,MAAM,kCAAkC;","names":[]}
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var draft_mode_exports = {};
20
+ __export(draft_mode_exports, {
21
+ default: () => draftModeHandler
22
+ });
23
+ module.exports = __toCommonJS(draft_mode_exports);
24
+ var import_server = require("next/server");
25
+ var import_ts_pattern = require("ts-pattern");
26
+ var import_headers = require("next/headers");
27
+ var import_site_version = require("../../../api/site-version");
28
+ const PRERENDER_BYPASS_COOKIE = "__prerender_bypass";
29
+ const DRAFT_DATA_COOKIE = "x-makeswift-draft-data";
30
+ const routeHandlerPattern = [import_ts_pattern.P.instanceOf(Request), import_ts_pattern.P.any, import_ts_pattern.P.any];
31
+ const apiRoutePattern = [import_ts_pattern.P.any, import_ts_pattern.P.any, import_ts_pattern.P.any];
32
+ async function draftModeHandler(...args) {
33
+ return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, (args2) => draftModeRouteHandler(...args2)).with(apiRoutePattern, (args2) => draftModeApiRouteHandler(...args2)).exhaustive();
34
+ }
35
+ async function draftModeRouteHandler(request, _context, { apiKey }) {
36
+ const secret = request.nextUrl.searchParams.get("secret");
37
+ if (secret == null) {
38
+ return new import_server.NextResponse("Unauthorized to enable draft mode: no secret provided", {
39
+ status: 401
40
+ });
41
+ }
42
+ if (secret !== apiKey) {
43
+ return new import_server.NextResponse("Unauthorized to enable draft mode: incorrect secret", { status: 401 });
44
+ }
45
+ const draft = await (0, import_headers.draftMode)();
46
+ const cookieStore = await (0, import_headers.cookies)();
47
+ draft.enable();
48
+ const bypassCookie = cookieStore.get(PRERENDER_BYPASS_COOKIE);
49
+ if (bypassCookie?.value == null) {
50
+ return new import_server.NextResponse("Could not retrieve draft mode bypass cookie", { status: 500 });
51
+ }
52
+ cookieStore.set({
53
+ name: bypassCookie.name,
54
+ value: bypassCookie.value,
55
+ sameSite: "none",
56
+ secure: true,
57
+ partitioned: true
58
+ });
59
+ cookieStore.set({
60
+ name: DRAFT_DATA_COOKIE,
61
+ // Eventually, we can make the value dynamic using the request
62
+ value: JSON.stringify({ makeswift: true, siteVersion: import_site_version.MakeswiftSiteVersion.Working }),
63
+ sameSite: "none",
64
+ secure: true,
65
+ partitioned: true
66
+ });
67
+ const siteVersionCookie = cookieStore.get(DRAFT_DATA_COOKIE);
68
+ if (siteVersionCookie?.value == null) {
69
+ return new import_server.NextResponse("Could not retrieve draft mode site version cookie", { status: 500 });
70
+ }
71
+ return import_server.NextResponse.json({ __brand: "DraftModeResponse" });
72
+ }
73
+ async function draftModeApiRouteHandler(_req, res, {}) {
74
+ const message = "Cannot request draft endpoint from an API handler registered in `pages`. Move your Makeswift API handler to the `app` directory";
75
+ console.error(message);
76
+ return res.status(500).send(message);
77
+ }
78
+ //# sourceMappingURL=draft-mode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/next/api-handler/handlers/draft-mode.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport { NextRequest, NextResponse } from 'next/server'\nimport { P, match } from 'ts-pattern'\nimport { cookies, draftMode } from 'next/headers'\nimport { MakeswiftSiteVersion } from '../../../api/site-version'\n\nconst PRERENDER_BYPASS_COOKIE = '__prerender_bypass'\nconst DRAFT_DATA_COOKIE = 'x-makeswift-draft-data'\n\ntype Context = { params: { [key: string]: string | string[] } }\n\ntype DraftModeError = string\n\ntype Response = { __brand: 'DraftModeResponse' }\n\nexport type DraftModeResponse = DraftModeError | Response\n\ntype DraftModeHandlerArgs =\n | [request: NextRequest, context: Context, params: { apiKey: string }]\n | [req: NextApiRequest, res: NextApiResponse<DraftModeResponse>, params: { apiKey: string }]\n\nconst routeHandlerPattern = [P.instanceOf(Request), P.any, P.any] as const\nconst apiRoutePattern = [P.any, P.any, P.any] as const\n\nexport default async function draftModeHandler(\n request: NextRequest,\n context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<DraftModeResponse>>\nexport default async function draftModeHandler(\n req: NextApiRequest,\n res: NextApiResponse<DraftModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void>\nexport default async function draftModeHandler(\n ...args: DraftModeHandlerArgs\n): Promise<NextResponse<DraftModeResponse> | void> {\n return match(args)\n .with(routeHandlerPattern, args => draftModeRouteHandler(...args))\n .with(apiRoutePattern, args => draftModeApiRouteHandler(...args))\n .exhaustive()\n}\n\nasync function draftModeRouteHandler(\n request: NextRequest,\n _context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<DraftModeResponse>> {\n const secret = request.nextUrl.searchParams.get('secret')\n\n if (secret == null) {\n return new NextResponse('Unauthorized to enable draft mode: no secret provided', {\n status: 401,\n })\n }\n if (secret !== apiKey) {\n return new NextResponse('Unauthorized to enable draft mode: incorrect secret', { status: 401 })\n }\n\n const draft = await draftMode()\n const cookieStore = await cookies()\n\n draft.enable()\n\n const bypassCookie = cookieStore.get(PRERENDER_BYPASS_COOKIE)\n\n if (bypassCookie?.value == null) {\n return new NextResponse('Could not retrieve draft mode bypass cookie', { status: 500 })\n }\n\n cookieStore.set({\n name: bypassCookie.name,\n value: bypassCookie.value,\n sameSite: 'none',\n secure: true,\n partitioned: true,\n })\n\n cookieStore.set({\n name: DRAFT_DATA_COOKIE,\n // Eventually, we can make the value dynamic using the request\n value: JSON.stringify({ makeswift: true, siteVersion: MakeswiftSiteVersion.Working }),\n sameSite: 'none',\n secure: true,\n partitioned: true,\n })\n\n const siteVersionCookie = cookieStore.get(DRAFT_DATA_COOKIE)\n\n if (siteVersionCookie?.value == null) {\n return new NextResponse('Could not retrieve draft mode site version cookie', { status: 500 })\n }\n\n return NextResponse.json({ __brand: 'DraftModeResponse' })\n}\n\nasync function draftModeApiRouteHandler(\n _req: NextApiRequest,\n res: NextApiResponse<DraftModeResponse>,\n {}: { apiKey: string },\n): Promise<void> {\n const message =\n 'Cannot request draft endpoint from an API handler registered in `pages`. Move your Makeswift API handler to the `app` directory'\n console.error(message)\n return res.status(500).send(message)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA0C;AAC1C,wBAAyB;AACzB,qBAAmC;AACnC,0BAAqC;AAErC,MAAM,0BAA0B;AAChC,MAAM,oBAAoB;AAc1B,MAAM,sBAAsB,CAAC,oBAAE,WAAW,OAAO,GAAG,oBAAE,KAAK,oBAAE,GAAG;AAChE,MAAM,kBAAkB,CAAC,oBAAE,KAAK,oBAAE,KAAK,oBAAE,GAAG;AAY5C,eAAO,oBACF,MAC8C;AACjD,aAAO,yBAAM,IAAI,EACd,KAAK,qBAAqB,CAAAA,UAAQ,sBAAsB,GAAGA,KAAI,CAAC,EAChE,KAAK,iBAAiB,CAAAA,UAAQ,yBAAyB,GAAGA,KAAI,CAAC,EAC/D,WAAW;AAChB;AAEA,eAAe,sBACb,SACA,UACA,EAAE,OAAO,GACiC;AAC1C,QAAM,SAAS,QAAQ,QAAQ,aAAa,IAAI,QAAQ;AAExD,MAAI,UAAU,MAAM;AAClB,WAAO,IAAI,2BAAa,yDAAyD;AAAA,MAC/E,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AACA,MAAI,WAAW,QAAQ;AACrB,WAAO,IAAI,2BAAa,uDAAuD,EAAE,QAAQ,IAAI,CAAC;AAAA,EAChG;AAEA,QAAM,QAAQ,UAAM,0BAAU;AAC9B,QAAM,cAAc,UAAM,wBAAQ;AAElC,QAAM,OAAO;AAEb,QAAM,eAAe,YAAY,IAAI,uBAAuB;AAE5D,MAAI,cAAc,SAAS,MAAM;AAC/B,WAAO,IAAI,2BAAa,+CAA+C,EAAE,QAAQ,IAAI,CAAC;AAAA,EACxF;AAEA,cAAY,IAAI;AAAA,IACd,MAAM,aAAa;AAAA,IACnB,OAAO,aAAa;AAAA,IACpB,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,aAAa;AAAA,EACf,CAAC;AAED,cAAY,IAAI;AAAA,IACd,MAAM;AAAA;AAAA,IAEN,OAAO,KAAK,UAAU,EAAE,WAAW,MAAM,aAAa,yCAAqB,QAAQ,CAAC;AAAA,IACpF,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,aAAa;AAAA,EACf,CAAC;AAED,QAAM,oBAAoB,YAAY,IAAI,iBAAiB;AAE3D,MAAI,mBAAmB,SAAS,MAAM;AACpC,WAAO,IAAI,2BAAa,qDAAqD,EAAE,QAAQ,IAAI,CAAC;AAAA,EAC9F;AAEA,SAAO,2BAAa,KAAK,EAAE,SAAS,oBAAoB,CAAC;AAC3D;AAEA,eAAe,yBACb,MACA,KACA,CAAC,GACc;AACf,QAAM,UACJ;AACF,UAAQ,MAAM,OAAO;AACrB,SAAO,IAAI,OAAO,GAAG,EAAE,KAAK,OAAO;AACrC;","names":["args"]}
@@ -37,7 +37,7 @@ async function handler(...args) {
37
37
  const supportsDraftMode = (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => true).with(apiRoutePattern, () => false).exhaustive();
38
38
  const supportsWebhook = (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => true).with(apiRoutePattern, () => false).exhaustive();
39
39
  const body = {
40
- version: "0.23.7",
40
+ version: "0.23.8-canary.1",
41
41
  previewMode: supportsPreviewMode,
42
42
  draftMode: supportsDraftMode,
43
43
  interactionMode: true,
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var preview_mode_exports = {};
20
+ __export(preview_mode_exports, {
21
+ default: () => previewModeHandler
22
+ });
23
+ module.exports = __toCommonJS(preview_mode_exports);
24
+ var import_server = require("next/server");
25
+ var import_ts_pattern = require("ts-pattern");
26
+ var import_set_cookie_parser = require("set-cookie-parser");
27
+ var import_cookie = require("cookie");
28
+ var import_site_version = require("../../../api/site-version");
29
+ const SET_COOKIE_HEADER = "set-cookie";
30
+ const PRERENDER_BYPASS_COOKIE = "__prerender_bypass";
31
+ const PREVIEW_DATA_COOKIE = "__next_preview_data";
32
+ const routeHandlerPattern = [import_ts_pattern.P.instanceOf(Request), import_ts_pattern.P.any, import_ts_pattern.P.any];
33
+ const apiRoutePattern = [import_ts_pattern.P.any, import_ts_pattern.P.any, import_ts_pattern.P.any];
34
+ async function previewModeHandler(...args) {
35
+ return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, (args2) => previewModeRouteHandler(...args2)).with(apiRoutePattern, (args2) => previewModeApiRouteHandler(...args2)).exhaustive();
36
+ }
37
+ async function previewModeRouteHandler(_request, _context, {}) {
38
+ const message = "Cannot request preview endpoint from an API handler registered in `app`. Move your Makeswift API handler to the `pages/api` directory";
39
+ console.error(message);
40
+ return import_server.NextResponse.json(message, { status: 500 });
41
+ }
42
+ async function previewModeApiRouteHandler(req, res, { apiKey }) {
43
+ const secret = req.query.secret;
44
+ if (secret == null) {
45
+ return res.status(401).send("Unauthorized to enable preview mode: no secret provided");
46
+ }
47
+ if (secret !== apiKey) {
48
+ return res.status(401).send("Unauthorized to enable preview mode: secret is incorrect");
49
+ }
50
+ const setCookie = res.setPreviewData({ makeswift: true, siteVersion: import_site_version.MakeswiftSiteVersion.Working }).getHeader(SET_COOKIE_HEADER);
51
+ res.removeHeader(SET_COOKIE_HEADER);
52
+ const parsedCookies = (0, import_set_cookie_parser.parse)(Array.isArray(setCookie) ? setCookie : "");
53
+ const prerenderBypassCookie = parsedCookies.find((c) => c.name === PRERENDER_BYPASS_COOKIE);
54
+ const previewDataCookie = parsedCookies.find((c) => c.name === PREVIEW_DATA_COOKIE);
55
+ if (prerenderBypassCookie?.value == null || previewDataCookie?.value == null) {
56
+ return res.status(500).send("Could not retrieve preview mode cookies");
57
+ }
58
+ const patchedCookies = [prerenderBypassCookie, previewDataCookie].map(
59
+ ({ name, value, ...options }) => {
60
+ return (0, import_cookie.serialize)(name, value, {
61
+ ...options,
62
+ sameSite: "none",
63
+ secure: true,
64
+ partitioned: true
65
+ });
66
+ }
67
+ );
68
+ res.setHeader(SET_COOKIE_HEADER, patchedCookies);
69
+ return res.json({ __brand: "PreviewModeResponse" });
70
+ }
71
+ //# sourceMappingURL=preview-mode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/next/api-handler/handlers/preview-mode.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport { NextRequest, NextResponse } from 'next/server'\nimport { P, match } from 'ts-pattern'\nimport { parse as parseSetCookie } from 'set-cookie-parser'\nimport { serialize as serializeCookie } from 'cookie'\nimport { MakeswiftSiteVersion } from '../../../api/site-version'\n\nconst SET_COOKIE_HEADER = 'set-cookie'\nconst PRERENDER_BYPASS_COOKIE = '__prerender_bypass'\nconst PREVIEW_DATA_COOKIE = '__next_preview_data'\n\ntype Context = { params: { [key: string]: string | string[] } }\n\ntype PreviewModeError = string\n\ntype Response = { __brand: 'PreviewModeResponse' }\n\nexport type PreviewModeResponse = PreviewModeError | Response\n\ntype PreviewModeHandlerArgs =\n | [request: NextRequest, context: Context, params: { apiKey: string }]\n | [req: NextApiRequest, res: NextApiResponse<PreviewModeResponse>, params: { apiKey: string }]\n\nconst routeHandlerPattern = [P.instanceOf(Request), P.any, P.any] as const\nconst apiRoutePattern = [P.any, P.any, P.any] as const\n\nexport default async function previewModeHandler(\n request: NextRequest,\n context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<PreviewModeResponse>>\nexport default async function previewModeHandler(\n req: NextApiRequest,\n res: NextApiResponse<PreviewModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void>\nexport default async function previewModeHandler(\n ...args: PreviewModeHandlerArgs\n): Promise<NextResponse<PreviewModeResponse> | void> {\n return match(args)\n .with(routeHandlerPattern, args => previewModeRouteHandler(...args))\n .with(apiRoutePattern, args => previewModeApiRouteHandler(...args))\n .exhaustive()\n}\n\nasync function previewModeRouteHandler(\n _request: NextRequest,\n _context: Context,\n {}: { apiKey: string },\n): Promise<NextResponse<PreviewModeResponse>> {\n const message =\n 'Cannot request preview endpoint from an API handler registered in `app`. Move your Makeswift API handler to the `pages/api` directory'\n console.error(message)\n return NextResponse.json(message, { status: 500 })\n}\n\nasync function previewModeApiRouteHandler(\n req: NextApiRequest,\n res: NextApiResponse<PreviewModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void> {\n const secret = req.query.secret\n\n if (secret == null) {\n return res.status(401).send('Unauthorized to enable preview mode: no secret provided')\n }\n if (secret !== apiKey) {\n return res.status(401).send('Unauthorized to enable preview mode: secret is incorrect')\n }\n\n // Eventually, we can make the preview data value dynamic using the request\n const setCookie = res\n .setPreviewData({ makeswift: true, siteVersion: MakeswiftSiteVersion.Working })\n .getHeader(SET_COOKIE_HEADER)\n\n res.removeHeader(SET_COOKIE_HEADER)\n\n const parsedCookies = parseSetCookie(Array.isArray(setCookie) ? setCookie : '')\n\n const prerenderBypassCookie = parsedCookies.find(c => c.name === PRERENDER_BYPASS_COOKIE)\n const previewDataCookie = parsedCookies.find(c => c.name === PREVIEW_DATA_COOKIE)\n\n if (prerenderBypassCookie?.value == null || previewDataCookie?.value == null) {\n return res.status(500).send('Could not retrieve preview mode cookies')\n }\n\n const patchedCookies = [prerenderBypassCookie, previewDataCookie].map(\n ({ name, value, ...options }) => {\n return serializeCookie(name, value, {\n ...options,\n sameSite: 'none',\n secure: true,\n partitioned: true,\n })\n },\n )\n\n res.setHeader(SET_COOKIE_HEADER, patchedCookies)\n\n return res.json({ __brand: 'PreviewModeResponse' })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA0C;AAC1C,wBAAyB;AACzB,+BAAwC;AACxC,oBAA6C;AAC7C,0BAAqC;AAErC,MAAM,oBAAoB;AAC1B,MAAM,0BAA0B;AAChC,MAAM,sBAAsB;AAc5B,MAAM,sBAAsB,CAAC,oBAAE,WAAW,OAAO,GAAG,oBAAE,KAAK,oBAAE,GAAG;AAChE,MAAM,kBAAkB,CAAC,oBAAE,KAAK,oBAAE,KAAK,oBAAE,GAAG;AAY5C,eAAO,sBACF,MACgD;AACnD,aAAO,yBAAM,IAAI,EACd,KAAK,qBAAqB,CAAAA,UAAQ,wBAAwB,GAAGA,KAAI,CAAC,EAClE,KAAK,iBAAiB,CAAAA,UAAQ,2BAA2B,GAAGA,KAAI,CAAC,EACjE,WAAW;AAChB;AAEA,eAAe,wBACb,UACA,UACA,CAAC,GAC2C;AAC5C,QAAM,UACJ;AACF,UAAQ,MAAM,OAAO;AACrB,SAAO,2BAAa,KAAK,SAAS,EAAE,QAAQ,IAAI,CAAC;AACnD;AAEA,eAAe,2BACb,KACA,KACA,EAAE,OAAO,GACM;AACf,QAAM,SAAS,IAAI,MAAM;AAEzB,MAAI,UAAU,MAAM;AAClB,WAAO,IAAI,OAAO,GAAG,EAAE,KAAK,yDAAyD;AAAA,EACvF;AACA,MAAI,WAAW,QAAQ;AACrB,WAAO,IAAI,OAAO,GAAG,EAAE,KAAK,0DAA0D;AAAA,EACxF;AAGA,QAAM,YAAY,IACf,eAAe,EAAE,WAAW,MAAM,aAAa,yCAAqB,QAAQ,CAAC,EAC7E,UAAU,iBAAiB;AAE9B,MAAI,aAAa,iBAAiB;AAElC,QAAM,oBAAgB,yBAAAC,OAAe,MAAM,QAAQ,SAAS,IAAI,YAAY,EAAE;AAE9E,QAAM,wBAAwB,cAAc,KAAK,OAAK,EAAE,SAAS,uBAAuB;AACxF,QAAM,oBAAoB,cAAc,KAAK,OAAK,EAAE,SAAS,mBAAmB;AAEhF,MAAI,uBAAuB,SAAS,QAAQ,mBAAmB,SAAS,MAAM;AAC5E,WAAO,IAAI,OAAO,GAAG,EAAE,KAAK,yCAAyC;AAAA,EACvE;AAEA,QAAM,iBAAiB,CAAC,uBAAuB,iBAAiB,EAAE;AAAA,IAChE,CAAC,EAAE,MAAM,OAAO,GAAG,QAAQ,MAAM;AAC/B,iBAAO,cAAAC,WAAgB,MAAM,OAAO;AAAA,QAClC,GAAG;AAAA,QACH,UAAU;AAAA,QACV,QAAQ;AAAA,QACR,aAAa;AAAA,MACf,CAAC;AAAA,IACH;AAAA,EACF;AAEA,MAAI,UAAU,mBAAmB,cAAc;AAE/C,SAAO,IAAI,KAAK,EAAE,SAAS,sBAAsB,CAAC;AACpD;","names":["args","parseSetCookie","serializeCookie"]}
@@ -25,7 +25,7 @@ var import_server = require("next/server");
25
25
  var import_ts_pattern = require("ts-pattern");
26
26
  var import_headers = require("next/headers");
27
27
  var import_draft_mode = require("../../draft-mode");
28
- var import_preview_mode = require("../../preview-mode");
28
+ var import_site_version = require("../../../api/site-version");
29
29
  const routeHandlerPattern = [import_ts_pattern.P.instanceOf(Request), import_ts_pattern.P.any, import_ts_pattern.P.any];
30
30
  const apiRoutePattern = [import_ts_pattern.P.any, import_ts_pattern.P.any, import_ts_pattern.P.any];
31
31
  async function proxyDraftMode(...args) {
@@ -37,7 +37,7 @@ async function proxyDraftModeRouteHandler(request, _context, { apiKey }) {
37
37
  return new import_server.NextResponse("Unauthorized", { status: 401 });
38
38
  const draftModeData = {
39
39
  makeswift: true,
40
- siteVersion: import_preview_mode.MakeswiftSiteVersion.Working
40
+ siteVersion: import_site_version.MakeswiftSiteVersion.Working
41
41
  };
42
42
  const draft = await (0, import_headers.draftMode)();
43
43
  draft.enable();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/next/api-handler/handlers/proxy-draft-mode.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport { NextRequest, NextResponse } from 'next/server'\nimport { P, match } from 'ts-pattern'\nimport { cookies, draftMode } from 'next/headers'\n\nimport { MAKESWIFT_DRAFT_MODE_DATA_COOKIE, MakeswiftDraftData } from '../../draft-mode'\nimport { MakeswiftSiteVersion } from '../../preview-mode'\n\ntype Context = { params: { [key: string]: string | string[] } }\n\ntype ProxyDraftModeError = string\n\ntype ProxyResponse = { __brand: 'ProxyResponse' }\n\nexport type ProxyDraftModeResponse = ProxyDraftModeError | ProxyResponse\n\ntype ProxyDraftModeHandlerArgs =\n | [request: NextRequest, context: Context, params: { apiKey: string }]\n | [req: NextApiRequest, res: NextApiResponse<ProxyDraftModeResponse>, params: { apiKey: string }]\n\nconst routeHandlerPattern = [P.instanceOf(Request), P.any, P.any] as const\nconst apiRoutePattern = [P.any, P.any, P.any] as const\n\nexport default async function proxyDraftMode(\n request: NextRequest,\n context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<ProxyDraftModeResponse>>\nexport default async function proxyDraftMode(\n req: NextApiRequest,\n res: NextApiResponse<ProxyDraftModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void>\nexport default async function proxyDraftMode(\n ...args: ProxyDraftModeHandlerArgs\n): Promise<NextResponse<ProxyDraftModeResponse> | void> {\n return match(args)\n .with(routeHandlerPattern, args => proxyDraftModeRouteHandler(...args))\n .with(apiRoutePattern, args => proxyDraftModeApiRouteHandler(...args))\n .exhaustive()\n}\n\nasync function proxyDraftModeRouteHandler(\n request: NextRequest,\n _context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<ProxyDraftModeResponse>> {\n const secret =\n request.nextUrl.searchParams.get('x-makeswift-draft-mode') ??\n request.headers.get('X-Makeswift-Draft-Mode')\n\n if (secret !== apiKey) return new NextResponse('Unauthorized', { status: 401 })\n\n const draftModeData: MakeswiftDraftData = {\n makeswift: true,\n siteVersion: MakeswiftSiteVersion.Working,\n }\n\n const draft = await draftMode()\n draft.enable()\n\n const proxyUrl = request.nextUrl.clone()\n\n if (process.env.MAKESWIFT_DRAFT_MODE_PROXY_FORCE_HTTP == null) {\n proxyUrl.protocol = request.headers.get('x-forwarded-proto') ?? request.nextUrl.protocol\n } else {\n proxyUrl.protocol = 'http'\n }\n\n const forwardingHost = request.headers.get('x-forwarded-host') ?? request.headers.get('host')\n if (forwardingHost) {\n proxyUrl.host = forwardingHost\n }\n\n proxyUrl.searchParams.delete('x-makeswift-draft-mode')\n\n const proxyHeaders = new Headers(request.headers)\n proxyHeaders.delete('X-Makeswift-Draft-Mode')\n\n const proxyRequest = new NextRequest(proxyUrl, { headers: proxyHeaders })\n const draftModeCookie = (await cookies()).get('__prerender_bypass')\n if (draftModeCookie) {\n proxyRequest.cookies.set(draftModeCookie)\n proxyRequest.cookies.set(MAKESWIFT_DRAFT_MODE_DATA_COOKIE, JSON.stringify(draftModeData))\n }\n\n draft.disable()\n\n const proxyResponse = await fetch(proxyRequest)\n\n const response = new NextResponse<ProxyResponse>(proxyResponse.body, {\n headers: proxyResponse.headers,\n status: proxyResponse.status,\n })\n\n // `fetch` automatically decompresses the response, but the response headers will keep the\n // `content-encoding` and `content-length` headers. This will cause decoding issues if the client\n // attempts to decompress the response again. To prevent this, we remove these headers.\n //\n // See https://github.com/nodejs/undici/issues/2514.\n if (response.headers.has('content-encoding')) {\n response.headers.delete('content-encoding')\n response.headers.delete('content-length')\n }\n\n return response\n}\n\nasync function proxyDraftModeApiRouteHandler(\n _req: NextApiRequest,\n res: NextApiResponse<ProxyDraftModeResponse>,\n {}: { apiKey: string },\n): Promise<void> {\n const message =\n 'Cannot request draft endpoint from an API handler registered in `pages`. Move your Makeswift API handler to the `app` directory'\n console.error(message)\n return res.status(500).send(message)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA0C;AAC1C,wBAAyB;AACzB,qBAAmC;AAEnC,wBAAqE;AACrE,0BAAqC;AAcrC,MAAM,sBAAsB,CAAC,oBAAE,WAAW,OAAO,GAAG,oBAAE,KAAK,oBAAE,GAAG;AAChE,MAAM,kBAAkB,CAAC,oBAAE,KAAK,oBAAE,KAAK,oBAAE,GAAG;AAY5C,eAAO,kBACF,MACmD;AACtD,aAAO,yBAAM,IAAI,EACd,KAAK,qBAAqB,CAAAA,UAAQ,2BAA2B,GAAGA,KAAI,CAAC,EACrE,KAAK,iBAAiB,CAAAA,UAAQ,8BAA8B,GAAGA,KAAI,CAAC,EACpE,WAAW;AAChB;AAEA,eAAe,2BACb,SACA,UACA,EAAE,OAAO,GACsC;AAC/C,QAAM,SACJ,QAAQ,QAAQ,aAAa,IAAI,wBAAwB,KACzD,QAAQ,QAAQ,IAAI,wBAAwB;AAE9C,MAAI,WAAW;AAAQ,WAAO,IAAI,2BAAa,gBAAgB,EAAE,QAAQ,IAAI,CAAC;AAE9E,QAAM,gBAAoC;AAAA,IACxC,WAAW;AAAA,IACX,aAAa,yCAAqB;AAAA,EACpC;AAEA,QAAM,QAAQ,UAAM,0BAAU;AAC9B,QAAM,OAAO;AAEb,QAAM,WAAW,QAAQ,QAAQ,MAAM;AAEvC,MAAI,QAAQ,IAAI,yCAAyC,MAAM;AAC7D,aAAS,WAAW,QAAQ,QAAQ,IAAI,mBAAmB,KAAK,QAAQ,QAAQ;AAAA,EAClF,OAAO;AACL,aAAS,WAAW;AAAA,EACtB;AAEA,QAAM,iBAAiB,QAAQ,QAAQ,IAAI,kBAAkB,KAAK,QAAQ,QAAQ,IAAI,MAAM;AAC5F,MAAI,gBAAgB;AAClB,aAAS,OAAO;AAAA,EAClB;AAEA,WAAS,aAAa,OAAO,wBAAwB;AAErD,QAAM,eAAe,IAAI,QAAQ,QAAQ,OAAO;AAChD,eAAa,OAAO,wBAAwB;AAE5C,QAAM,eAAe,IAAI,0BAAY,UAAU,EAAE,SAAS,aAAa,CAAC;AACxE,QAAM,mBAAmB,UAAM,wBAAQ,GAAG,IAAI,oBAAoB;AAClE,MAAI,iBAAiB;AACnB,iBAAa,QAAQ,IAAI,eAAe;AACxC,iBAAa,QAAQ,IAAI,oDAAkC,KAAK,UAAU,aAAa,CAAC;AAAA,EAC1F;AAEA,QAAM,QAAQ;AAEd,QAAM,gBAAgB,MAAM,MAAM,YAAY;AAE9C,QAAM,WAAW,IAAI,2BAA4B,cAAc,MAAM;AAAA,IACnE,SAAS,cAAc;AAAA,IACvB,QAAQ,cAAc;AAAA,EACxB,CAAC;AAOD,MAAI,SAAS,QAAQ,IAAI,kBAAkB,GAAG;AAC5C,aAAS,QAAQ,OAAO,kBAAkB;AAC1C,aAAS,QAAQ,OAAO,gBAAgB;AAAA,EAC1C;AAEA,SAAO;AACT;AAEA,eAAe,8BACb,MACA,KACA,CAAC,GACc;AACf,QAAM,UACJ;AACF,UAAQ,MAAM,OAAO;AACrB,SAAO,IAAI,OAAO,GAAG,EAAE,KAAK,OAAO;AACrC;","names":["args"]}
1
+ {"version":3,"sources":["../../../../../src/next/api-handler/handlers/proxy-draft-mode.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport { NextRequest, NextResponse } from 'next/server'\nimport { P, match } from 'ts-pattern'\nimport { cookies, draftMode } from 'next/headers'\n\nimport { MAKESWIFT_DRAFT_MODE_DATA_COOKIE, MakeswiftDraftData } from '../../draft-mode'\nimport { MakeswiftSiteVersion } from '../../../api/site-version'\n\ntype Context = { params: { [key: string]: string | string[] } }\n\ntype ProxyDraftModeError = string\n\ntype ProxyResponse = { __brand: 'ProxyResponse' }\n\nexport type ProxyDraftModeResponse = ProxyDraftModeError | ProxyResponse\n\ntype ProxyDraftModeHandlerArgs =\n | [request: NextRequest, context: Context, params: { apiKey: string }]\n | [req: NextApiRequest, res: NextApiResponse<ProxyDraftModeResponse>, params: { apiKey: string }]\n\nconst routeHandlerPattern = [P.instanceOf(Request), P.any, P.any] as const\nconst apiRoutePattern = [P.any, P.any, P.any] as const\n\nexport default async function proxyDraftMode(\n request: NextRequest,\n context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<ProxyDraftModeResponse>>\nexport default async function proxyDraftMode(\n req: NextApiRequest,\n res: NextApiResponse<ProxyDraftModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void>\nexport default async function proxyDraftMode(\n ...args: ProxyDraftModeHandlerArgs\n): Promise<NextResponse<ProxyDraftModeResponse> | void> {\n return match(args)\n .with(routeHandlerPattern, args => proxyDraftModeRouteHandler(...args))\n .with(apiRoutePattern, args => proxyDraftModeApiRouteHandler(...args))\n .exhaustive()\n}\n\nasync function proxyDraftModeRouteHandler(\n request: NextRequest,\n _context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<ProxyDraftModeResponse>> {\n const secret =\n request.nextUrl.searchParams.get('x-makeswift-draft-mode') ??\n request.headers.get('X-Makeswift-Draft-Mode')\n\n if (secret !== apiKey) return new NextResponse('Unauthorized', { status: 401 })\n\n const draftModeData: MakeswiftDraftData = {\n makeswift: true,\n siteVersion: MakeswiftSiteVersion.Working,\n }\n\n const draft = await draftMode()\n draft.enable()\n\n const proxyUrl = request.nextUrl.clone()\n\n if (process.env.MAKESWIFT_DRAFT_MODE_PROXY_FORCE_HTTP == null) {\n proxyUrl.protocol = request.headers.get('x-forwarded-proto') ?? request.nextUrl.protocol\n } else {\n proxyUrl.protocol = 'http'\n }\n\n const forwardingHost = request.headers.get('x-forwarded-host') ?? request.headers.get('host')\n if (forwardingHost) {\n proxyUrl.host = forwardingHost\n }\n\n proxyUrl.searchParams.delete('x-makeswift-draft-mode')\n\n const proxyHeaders = new Headers(request.headers)\n proxyHeaders.delete('X-Makeswift-Draft-Mode')\n\n const proxyRequest = new NextRequest(proxyUrl, { headers: proxyHeaders })\n const draftModeCookie = (await cookies()).get('__prerender_bypass')\n if (draftModeCookie) {\n proxyRequest.cookies.set(draftModeCookie)\n proxyRequest.cookies.set(MAKESWIFT_DRAFT_MODE_DATA_COOKIE, JSON.stringify(draftModeData))\n }\n\n draft.disable()\n\n const proxyResponse = await fetch(proxyRequest)\n\n const response = new NextResponse<ProxyResponse>(proxyResponse.body, {\n headers: proxyResponse.headers,\n status: proxyResponse.status,\n })\n\n // `fetch` automatically decompresses the response, but the response headers will keep the\n // `content-encoding` and `content-length` headers. This will cause decoding issues if the client\n // attempts to decompress the response again. To prevent this, we remove these headers.\n //\n // See https://github.com/nodejs/undici/issues/2514.\n if (response.headers.has('content-encoding')) {\n response.headers.delete('content-encoding')\n response.headers.delete('content-length')\n }\n\n return response\n}\n\nasync function proxyDraftModeApiRouteHandler(\n _req: NextApiRequest,\n res: NextApiResponse<ProxyDraftModeResponse>,\n {}: { apiKey: string },\n): Promise<void> {\n const message =\n 'Cannot request draft endpoint from an API handler registered in `pages`. Move your Makeswift API handler to the `app` directory'\n console.error(message)\n return res.status(500).send(message)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA0C;AAC1C,wBAAyB;AACzB,qBAAmC;AAEnC,wBAAqE;AACrE,0BAAqC;AAcrC,MAAM,sBAAsB,CAAC,oBAAE,WAAW,OAAO,GAAG,oBAAE,KAAK,oBAAE,GAAG;AAChE,MAAM,kBAAkB,CAAC,oBAAE,KAAK,oBAAE,KAAK,oBAAE,GAAG;AAY5C,eAAO,kBACF,MACmD;AACtD,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AAY;AAE9C,QAAM,WAAW,IAAI,2BAA4B,cAAc,MAAM;AAAA,IACnE,SAAS,cAAc;AAAA,IACvB,QAAQ,cAAc;AAAA,EACxB,CAAC;AAOD,MAAI,SAAS,QAAQ,IAAI,kBAAkB,GAAG;AAC5C,aAAS,QAAQ,OAAO,kBAAkB;AAC1C,aAAS,QAAQ,OAAO,gBAAgB;AAAA,EAC1C;AAEA,SAAO;AACT;AAEA,eAAe,8BACb,MACA,KACA,CAAC,GACc;AACf,QAAM,UACJ;AACF,UAAQ,MAAM,OAAO;AACrB,SAAO,IAAI,OAAO,GAAG,EAAE,KAAK,OAAO;AACrC;","names":["args"]}
@@ -21,9 +21,9 @@ __export(proxy_preview_mode_exports, {
21
21
  default: () => proxyPreviewMode
22
22
  });
23
23
  module.exports = __toCommonJS(proxy_preview_mode_exports);
24
- var import_preview_mode = require("../../preview-mode");
25
24
  var import_server = require("next/server");
26
25
  var import_ts_pattern = require("ts-pattern");
26
+ var import_site_version = require("../../../api/site-version");
27
27
  const routeHandlerPattern = [import_ts_pattern.P.instanceOf(Request), import_ts_pattern.P.any, import_ts_pattern.P.any];
28
28
  const apiRoutePattern = [import_ts_pattern.P.any, import_ts_pattern.P.any, import_ts_pattern.P.any];
29
29
  function mapRequestHeadersToHeaders(requestHeaders) {
@@ -74,7 +74,7 @@ async function proxyPreviewModeApiRouteHandler(req, res, { apiKey }) {
74
74
  const previewData = {
75
75
  makeswift: true,
76
76
  // This will eventually be dynamic
77
- siteVersion: import_preview_mode.MakeswiftSiteVersion.Working
77
+ siteVersion: import_site_version.MakeswiftSiteVersion.Working
78
78
  };
79
79
  const setCookie = res.setPreviewData(previewData).getHeader("set-cookie");
80
80
  res.removeHeader("set-cookie");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/next/api-handler/handlers/proxy-preview-mode.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport { MakeswiftPreviewData, MakeswiftSiteVersion } from '../../preview-mode'\nimport { NextRequest, NextResponse } from 'next/server'\nimport { P, match } from 'ts-pattern'\n\ntype Context = { params: { [key: string]: string | string[] } }\n\ntype ProxyPreviewModeError = string\n\ntype ProxyResponse = { __brand: 'ProxyResponse' }\n\nexport type ProxyPreviewModeResponse = ProxyPreviewModeError | ProxyResponse\n\ntype ProxyPreviewModeHandlerArgs =\n | [request: NextRequest, context: Context, params: { apiKey: string }]\n | [\n req: NextApiRequest,\n res: NextApiResponse<ProxyPreviewModeResponse>,\n params: { apiKey: string },\n ]\n\nconst routeHandlerPattern = [P.instanceOf(Request), P.any, P.any] as const\nconst apiRoutePattern = [P.any, P.any, P.any] as const\n\nfunction mapRequestHeadersToHeaders(requestHeaders: NextApiRequest['headers']): Headers {\n const headers = new Headers()\n\n Object.entries(requestHeaders).forEach(([key, value]) => {\n match(value)\n .with(P.array(P.string), value => value.map(val => headers.append(key, val)))\n .with(P.string, value => headers.set(key, value))\n })\n\n return headers\n}\n\nfunction mapRequestToProxyUrl(req: NextApiRequest): URL {\n const isForwardedProtoHttps = match(req.headers['x-forwarded-proto'])\n .with(P.string, x => x.split(','))\n .with(P.array(P.string), x => x)\n .otherwise(() => [])\n .includes('https')\n\n const isForwardedSSL = match(req.headers['x-forwarded-ssl'])\n .with('on', () => true)\n .otherwise(() => false)\n\n const proto = isForwardedProtoHttps || isForwardedSSL ? 'https' : 'http'\n\n return new URL(`${proto}://${req.headers.host}${req.url}`)\n}\n\nexport default async function proxyPreviewMode(\n request: NextRequest,\n context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<ProxyPreviewModeResponse>>\nexport default async function proxyPreviewMode(\n req: NextApiRequest,\n res: NextApiResponse<ProxyPreviewModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void>\nexport default async function proxyPreviewMode(\n ...args: ProxyPreviewModeHandlerArgs\n): Promise<NextResponse<ProxyPreviewModeResponse> | void> {\n return match(args)\n .with(routeHandlerPattern, args => proxyPreviewModeRouteHandler(...args))\n .with(apiRoutePattern, args => proxyPreviewModeApiRouteHandler(...args))\n .exhaustive()\n}\n\nasync function proxyPreviewModeRouteHandler(\n _request: NextRequest,\n _context: Context,\n {}: { apiKey: string },\n): Promise<NextResponse<ProxyPreviewModeResponse>> {\n const message =\n 'Cannot request preview endpoint from an API handler registered in `app`. Move your Makeswift API handler to the `pages/api` directory'\n console.error(message)\n return NextResponse.json(message, { status: 500 })\n}\n\nasync function proxyPreviewModeApiRouteHandler(\n req: NextApiRequest,\n res: NextApiResponse<ProxyPreviewModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void> {\n if (req.query.secret !== apiKey) return res.status(401).send('Unauthorized')\n if (req.headers.host == null) return res.status(400).send('Bad Request')\n\n // TODO: This is a hack to get the locale from the request.\n // Next.js strips the locale from the req.url, and there's no official way to get the locale\n // from an API route: https://github.com/vercel/next.js/discussions/21798.\n // The current workaround is to get the locale from an internal object: RequestMeta,\n // https://github.com/vercel/next.js/blob/a0d1d728b9003f12c9df6c5e9a33bc4c33cef0ab/packages/next/src/server/request-meta.ts\n // One possible way to properly fix this is by updating how we do preview mode. For example,\n // by using partitioned cookies instead of a proxy.\n const NextRequestMetaSymbol = Reflect.ownKeys(req).find(\n key =>\n key.toString() === 'Symbol(NextRequestMeta)' ||\n key.toString() === 'Symbol(NextInternalRequestMeta)',\n ) as keyof NextApiRequest | undefined\n\n if (NextRequestMetaSymbol) {\n const nextRequestMeta = req[NextRequestMetaSymbol]\n const initUrl = nextRequestMeta?.__NEXT_INIT_URL ?? nextRequestMeta?.initURL\n const isLocaleStripped =\n nextRequestMeta?.__nextStrippedLocale ?? nextRequestMeta?.didStripLocale\n\n try {\n if (isLocaleStripped && initUrl) req.url = new URL(initUrl).pathname\n } catch {}\n }\n\n const proxyHeaders = mapRequestHeadersToHeaders(req.headers)\n const proxyUrl = mapRequestToProxyUrl(req)\n\n proxyUrl.searchParams.delete('x-makeswift-preview-mode')\n proxyHeaders.delete('x-makeswift-preview-mode')\n // The following headers are Next.js-specific and are removed to prevent Next.js from\n // short-circuiting requests, breaking routing.\n proxyHeaders.delete('x-invoke-path')\n proxyHeaders.delete('x-invoke-query')\n\n const previewData: MakeswiftPreviewData = {\n makeswift: true,\n // This will eventually be dynamic\n siteVersion: MakeswiftSiteVersion.Working,\n }\n\n const setCookie = res.setPreviewData(previewData).getHeader('set-cookie')\n res.removeHeader('set-cookie')\n\n if (!Array.isArray(setCookie)) return res.status(500).send('Internal Server Error')\n\n setCookie.forEach(cookie => proxyHeaders.append('cookie', cookie))\n\n const response = await fetch(proxyUrl, {\n headers: proxyHeaders,\n })\n\n response.headers.forEach((value, name) => {\n res.setHeader(name, value)\n })\n\n res.statusCode = response.status\n res.statusMessage = response.statusText\n\n // `fetch` automatically decompresses the response, but the response headers will keep the\n // `content-encoding` and `content-length` headers. This will cause decoding issues if the client\n // attempts to decompress the response again. To prevent this, we remove these headers.\n //\n // See https://github.com/nodejs/undici/issues/2514.\n if (res.hasHeader('content-encoding')) {\n res.removeHeader('content-encoding')\n res.removeHeader('content-length')\n }\n\n const arrayBuffer = await response.arrayBuffer()\n\n res.write(new Uint8Array(arrayBuffer))\n res.end()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0BAA2D;AAC3D,oBAA0C;AAC1C,wBAAyB;AAkBzB,MAAM,sBAAsB,CAAC,oBAAE,WAAW,OAAO,GAAG,oBAAE,KAAK,oBAAE,GAAG;AAChE,MAAM,kBAAkB,CAAC,oBAAE,KAAK,oBAAE,KAAK,oBAAE,GAAG;AAE5C,SAAS,2BAA2B,gBAAoD;AACtF,QAAM,UAAU,IAAI,QAAQ;AAE5B,SAAO,QAAQ,cAAc,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AACvD,iCAAM,KAAK,EACR,KAAK,oBAAE,MAAM,oBAAE,MAAM,GAAG,CAAAA,WAASA,OAAM,IAAI,SAAO,QAAQ,OAAO,KAAK,GAAG,CAAC,CAAC,EAC3E,KAAK,oB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lers/proxy-preview-mode.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport { MakeswiftPreviewData } from '../../preview-mode'\nimport { NextRequest, NextResponse } from 'next/server'\nimport { P, match } from 'ts-pattern'\nimport { MakeswiftSiteVersion } from '../../../api/site-version'\n\ntype Context = { params: { [key: string]: string | string[] } }\n\ntype ProxyPreviewModeError = string\n\ntype ProxyResponse = { __brand: 'ProxyResponse' }\n\nexport type ProxyPreviewModeResponse = ProxyPreviewModeError | ProxyResponse\n\ntype ProxyPreviewModeHandlerArgs =\n | [request: NextRequest, context: Context, params: { apiKey: string }]\n | [\n req: NextApiRequest,\n res: NextApiResponse<ProxyPreviewModeResponse>,\n params: { apiKey: string },\n ]\n\nconst routeHandlerPattern = [P.instanceOf(Request), P.any, P.any] as const\nconst apiRoutePattern = [P.any, P.any, P.any] as const\n\nfunction mapRequestHeadersToHeaders(requestHeaders: NextApiRequest['headers']): Headers {\n const headers = new Headers()\n\n Object.entries(requestHeaders).forEach(([key, value]) => {\n match(value)\n .with(P.array(P.string), value => value.map(val => headers.append(key, val)))\n .with(P.string, value => headers.set(key, value))\n })\n\n return headers\n}\n\nfunction mapRequestToProxyUrl(req: NextApiRequest): URL {\n const isForwardedProtoHttps = match(req.headers['x-forwarded-proto'])\n .with(P.string, x => x.split(','))\n .with(P.array(P.string), x => x)\n .otherwise(() => [])\n .includes('https')\n\n const isForwardedSSL = match(req.headers['x-forwarded-ssl'])\n .with('on', () => true)\n .otherwise(() => false)\n\n const proto = isForwardedProtoHttps || isForwardedSSL ? 'https' : 'http'\n\n return new URL(`${proto}://${req.headers.host}${req.url}`)\n}\n\nexport default async function proxyPreviewMode(\n request: NextRequest,\n context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<ProxyPreviewModeResponse>>\nexport default async function proxyPreviewMode(\n req: NextApiRequest,\n res: NextApiResponse<ProxyPreviewModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void>\nexport default async function proxyPreviewMode(\n ...args: ProxyPreviewModeHandlerArgs\n): Promise<NextResponse<ProxyPreviewModeResponse> | void> {\n return match(args)\n .with(routeHandlerPattern, args => proxyPreviewModeRouteHandler(...args))\n .with(apiRoutePattern, args => proxyPreviewModeApiRouteHandler(...args))\n .exhaustive()\n}\n\nasync function proxyPreviewModeRouteHandler(\n _request: NextRequest,\n _context: Context,\n {}: { apiKey: string },\n): Promise<NextResponse<ProxyPreviewModeResponse>> {\n const message =\n 'Cannot request preview endpoint from an API handler registered in `app`. Move your Makeswift API handler to the `pages/api` directory'\n console.error(message)\n return NextResponse.json(message, { status: 500 })\n}\n\nasync function proxyPreviewModeApiRouteHandler(\n req: NextApiRequest,\n res: NextApiResponse<ProxyPreviewModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void> {\n if (req.query.secret !== apiKey) return res.status(401).send('Unauthorized')\n if (req.headers.host == null) return res.status(400).send('Bad Request')\n\n // TODO: This is a hack to get the locale from the request.\n // Next.js strips the locale from the req.url, and there's no official way to get the locale\n // from an API route: https://github.com/vercel/next.js/discussions/21798.\n // The current workaround is to get the locale from an internal object: RequestMeta,\n // https://github.com/vercel/next.js/blob/a0d1d728b9003f12c9df6c5e9a33bc4c33cef0ab/packages/next/src/server/request-meta.ts\n // One possible way to properly fix this is by updating how we do preview mode. For example,\n // by using partitioned cookies instead of a proxy.\n const NextRequestMetaSymbol = Reflect.ownKeys(req).find(\n key =>\n key.toString() === 'Symbol(NextRequestMeta)' ||\n key.toString() === 'Symbol(NextInternalRequestMeta)',\n ) as keyof NextApiRequest | undefined\n\n if (NextRequestMetaSymbol) {\n const nextRequestMeta = req[NextRequestMetaSymbol]\n const initUrl = nextRequestMeta?.__NEXT_INIT_URL ?? nextRequestMeta?.initURL\n const isLocaleStripped =\n nextRequestMeta?.__nextStrippedLocale ?? nextRequestMeta?.didStripLocale\n\n try {\n if (isLocaleStripped && initUrl) req.url = new URL(initUrl).pathname\n } catch {}\n }\n\n const proxyHeaders = mapRequestHeadersToHeaders(req.headers)\n const proxyUrl = mapRequestToProxyUrl(req)\n\n proxyUrl.searchParams.delete('x-makeswift-preview-mode')\n proxyHeaders.delete('x-makeswift-preview-mode')\n // The following headers are Next.js-specific and are removed to prevent Next.js from\n // short-circuiting requests, breaking routing.\n proxyHeaders.delete('x-invoke-path')\n proxyHeaders.delete('x-invoke-query')\n\n const previewData: MakeswiftPreviewData = {\n makeswift: true,\n // This will eventually be dynamic\n siteVersion: MakeswiftSiteVersion.Working,\n }\n\n const setCookie = res.setPreviewData(previewData).getHeader('set-cookie')\n res.removeHeader('set-cookie')\n\n if (!Array.isArray(setCookie)) return res.status(500).send('Internal Server Error')\n\n setCookie.forEach(cookie => proxyHeaders.append('cookie', cookie))\n\n const response = await fetch(proxyUrl, {\n headers: proxyHeaders,\n })\n\n response.headers.forEach((value, name) => {\n res.setHeader(name, value)\n })\n\n res.statusCode = response.status\n res.statusMessage = response.statusText\n\n // `fetch` automatically decompresses the response, but the response headers will keep the\n // `content-encoding` and `content-length` headers. This will cause decoding issues if the client\n // attempts to decompress the response again. To prevent this, we remove these headers.\n //\n // See https://github.com/nodejs/undici/issues/2514.\n if (res.hasHeader('content-encoding')) {\n res.removeHeader('content-encoding')\n res.removeHeader('content-length')\n }\n\n const arrayBuffer = await response.arrayBuffer()\n\n res.write(new Uint8Array(arrayBuffer))\n res.end()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAA0C;AAC1C,wBAAyB;AACzB,0BAAqC;AAkBrC,MAAM,sBAAsB,CAAC,oBAAE,WAAW,OAAO,GAAG,oBAAE,KAAK,oBAAE,GAAG;AAChE,MAAM,kBAAkB,CAAC,oBAAE,KAAK,oBAAE,KAAK,oBAAE,GAAG;AAE5C,SAAS,2BAA2B,gBAAoD;AACtF,QAAM,UAAU,IAAI,QAAQ;AAE5B,SAAO,QAAQ,cAAc,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AACvD,iCAAM,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MAAM,SAAS,YAAY;AAE/C,MAAI,MAAM,IAAI,WAAW,WAAW,CAAC;AACrC,MAAI,IAAI;AACV;","names":["value","args"]}
@@ -40,12 +40,14 @@ var import_fonts = __toESM(require("./handlers/fonts"));
40
40
  var import_manifest = __toESM(require("./handlers/manifest"));
41
41
  var import_proxy_preview_mode = __toESM(require("./handlers/proxy-preview-mode"));
42
42
  var import_proxy_draft_mode = __toESM(require("./handlers/proxy-draft-mode"));
43
+ var import_draft_mode = __toESM(require("./handlers/draft-mode"));
44
+ var import_preview_mode = __toESM(require("./handlers/preview-mode"));
43
45
  var import_revalidate = require("./handlers/revalidate");
44
46
  var import_translatable_data = __toESM(require("./handlers/translatable-data"));
45
47
  var import_merge_translated_data = __toESM(require("./handlers/merge-translated-data"));
46
48
  var import_webhook = __toESM(require("./handlers/webhook"));
47
49
  var import_ts_pattern = require("ts-pattern");
48
- var import_draft_mode = require("../draft-mode");
50
+ var import_site_version = require("../../api/site-version");
49
51
  function apiRequestParams(request) {
50
52
  return Promise.resolve(request.query);
51
53
  }
@@ -84,6 +86,16 @@ Received "${apiKey}" instead.`
84
86
  return await makeswiftApiHandler(...args2);
85
87
  }).exhaustive();
86
88
  };
89
+ function getSiteVersionFromRequest(args) {
90
+ const header = (0, import_ts_pattern.match)(args).with(
91
+ routeHandlerPattern,
92
+ ([request]) => request.headers.get(import_site_version.API_HANDLER_SITE_VERSION_HEADER)
93
+ ).with(apiRoutePattern, ([req]) => req.headers[import_site_version.API_HANDLER_SITE_VERSION_HEADER.toLowerCase()]).exhaustive();
94
+ const parsed = import_site_version.makeswiftSiteVersionSchema.safeParse(header);
95
+ if (!parsed.success)
96
+ return import_site_version.MakeswiftSiteVersion.Live;
97
+ return parsed.data;
98
+ }
87
99
  async function makeswiftApiHandler(...args) {
88
100
  const params = (0, import_ts_pattern.match)(args).with(routeHandlerPattern, ([, context]) => context.params).with(apiRoutePattern, ([req]) => apiRequestParams(req)).exhaustive();
89
101
  const { makeswift } = await params;
@@ -95,7 +107,7 @@ Read more about dynamic catch-all routes here: https://nextjs.org/docs/routing/d
95
107
  );
96
108
  }
97
109
  const client = new import_client.Makeswift(apiKey, { apiOrigin, runtime });
98
- const siteVersion = await (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => (0, import_draft_mode.getSiteVersion)()).with(apiRoutePattern, ([req]) => import_client.Makeswift.getSiteVersion(req.previewData)).exhaustive();
110
+ const siteVersion = getSiteVersionFromRequest(args);
99
111
  const action = "/" + makeswift.join("/");
100
112
  const matches = (pattern) => (0, import_path_to_regexp.match)(pattern, { decode: decodeURIComponent })(action);
101
113
  let m;
@@ -111,6 +123,12 @@ Read more about dynamic catch-all routes here: https://nextjs.org/docs/routing/d
111
123
  if (matches("/proxy-draft-mode")) {
112
124
  return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, (args2) => (0, import_proxy_draft_mode.default)(...args2, { apiKey })).with(apiRoutePattern, (args2) => (0, import_proxy_draft_mode.default)(...args2, { apiKey })).exhaustive();
113
125
  }
126
+ if (matches("/draft-mode")) {
127
+ return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, (args2) => (0, import_draft_mode.default)(...args2, { apiKey })).with(apiRoutePattern, (args2) => (0, import_draft_mode.default)(...args2, { apiKey })).exhaustive();
128
+ }
129
+ if (matches("/preview-mode")) {
130
+ return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, (args2) => (0, import_preview_mode.default)(...args2, { apiKey })).with(apiRoutePattern, (args2) => (0, import_preview_mode.default)(...args2, { apiKey })).exhaustive();
131
+ }
114
132
  if (matches("/fonts")) {
115
133
  return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, (args2) => (0, import_fonts.default)(...args2, { getFonts })).with(apiRoutePattern, (args2) => (0, import_fonts.default)(...args2, { getFonts })).exhaustive();
116
134
  }