@makeswift/runtime 0.28.7-canary.9 → 0.28.8-canary.0

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 (41) hide show
  1. package/dist/cjs/api/api-resources-client.js +47 -0
  2. package/dist/cjs/api/api-resources-client.js.map +1 -1
  3. package/dist/cjs/api/graphql-api-client.js +1 -1
  4. package/dist/cjs/api/host-api-resources-client.js +38 -32
  5. package/dist/cjs/api/host-api-resources-client.js.map +1 -1
  6. package/dist/cjs/api/makeswift-api-resources-client.js +70 -0
  7. package/dist/cjs/api/makeswift-api-resources-client.js.map +1 -0
  8. package/dist/cjs/api/rest-api-client.js +1 -1
  9. package/dist/cjs/api/rest-api-client.js.map +1 -1
  10. package/dist/cjs/api/types.js.map +1 -1
  11. package/dist/cjs/api-handler/handlers/manifest.js +1 -1
  12. package/dist/cjs/client/index.js +1 -1
  13. package/dist/cjs/state/api-client/fetch-api-resource.js +5 -47
  14. package/dist/cjs/state/api-client/fetch-api-resource.js.map +1 -1
  15. package/dist/esm/api/api-resources-client.js +47 -0
  16. package/dist/esm/api/api-resources-client.js.map +1 -1
  17. package/dist/esm/api/graphql-api-client.js +1 -1
  18. package/dist/esm/api/host-api-resources-client.js +38 -33
  19. package/dist/esm/api/host-api-resources-client.js.map +1 -1
  20. package/dist/esm/api/makeswift-api-resources-client.js +46 -0
  21. package/dist/esm/api/makeswift-api-resources-client.js.map +1 -0
  22. package/dist/esm/api/rest-api-client.js +1 -1
  23. package/dist/esm/api/rest-api-client.js.map +1 -1
  24. package/dist/esm/api/types.js.map +1 -1
  25. package/dist/esm/api-handler/handlers/manifest.js +1 -1
  26. package/dist/esm/client/index.js +1 -1
  27. package/dist/esm/state/api-client/fetch-api-resource.js +5 -47
  28. package/dist/esm/state/api-client/fetch-api-resource.js.map +1 -1
  29. package/dist/types/api/api-resources-client.d.ts +18 -10
  30. package/dist/types/api/api-resources-client.d.ts.map +1 -1
  31. package/dist/types/api/host-api-resources-client.d.ts +9 -14
  32. package/dist/types/api/host-api-resources-client.d.ts.map +1 -1
  33. package/dist/types/api/makeswift-api-resources-client.d.ts +30 -0
  34. package/dist/types/api/makeswift-api-resources-client.d.ts.map +1 -0
  35. package/dist/types/api/rest-api-client.d.ts +1 -1
  36. package/dist/types/api/rest-api-client.d.ts.map +1 -1
  37. package/dist/types/api/types.d.ts +3 -0
  38. package/dist/types/api/types.d.ts.map +1 -1
  39. package/dist/types/state/api-client/fetch-api-resource.d.ts +3 -4
  40. package/dist/types/state/api-client/fetch-api-resource.d.ts.map +1 -1
  41. package/package.json +4 -4
@@ -33,6 +33,7 @@ __export(api_resources_client_exports, {
33
33
  });
34
34
  module.exports = __toCommonJS(api_resources_client_exports);
35
35
  var ApiClientState = __toESM(require("../state/api-client/state"));
36
+ var import_fetch_api_resource = require("../state/api-client/fetch-api-resource");
36
37
  var import_types = require("./types");
37
38
  const CacheData = {
38
39
  empty() {
@@ -49,6 +50,10 @@ class ApiResourcesClient {
49
50
  this.store = store;
50
51
  this.subscribe = this.store.subscribe;
51
52
  }
53
+ async fetchSwatch(swatchId) {
54
+ const fetch = (id, version) => this.fetchSwatchImpl(id, version);
55
+ return await this.store.dispatch((0, import_fetch_api_resource.fetchAPIResource)(import_types.APIResourceType.Swatch, swatchId, fetch));
56
+ }
52
57
  readSwatch(swatchId) {
53
58
  return ApiClientState.getAPIResource(this.store.getState(), import_types.APIResourceType.Swatch, swatchId);
54
59
  }
@@ -59,6 +64,10 @@ class ApiResourcesClient {
59
64
  fetch: (id) => this.fetchSwatch(id)
60
65
  });
61
66
  }
67
+ async fetchFile(fileId) {
68
+ const fetch = (id, version) => this.fetchFileImpl(id, version);
69
+ return await this.store.dispatch((0, import_fetch_api_resource.fetchAPIResource)(import_types.APIResourceType.File, fileId, fetch));
70
+ }
62
71
  readFile(fileId) {
63
72
  return ApiClientState.getAPIResource(this.store.getState(), import_types.APIResourceType.File, fileId);
64
73
  }
@@ -69,6 +78,12 @@ class ApiResourcesClient {
69
78
  fetch: (id) => this.fetchFile(id)
70
79
  });
71
80
  }
81
+ async fetchTypography(typographyId) {
82
+ const fetch = (id, version) => this.fetchTypographyImpl(id, version);
83
+ return await this.store.dispatch(
84
+ (0, import_fetch_api_resource.fetchAPIResource)(import_types.APIResourceType.Typography, typographyId, fetch)
85
+ );
86
+ }
72
87
  readTypography(typographyId) {
73
88
  return ApiClientState.getAPIResource(
74
89
  this.store.getState(),
@@ -83,6 +98,12 @@ class ApiResourcesClient {
83
98
  fetch: (id) => this.fetchTypography(id)
84
99
  });
85
100
  }
101
+ async fetchGlobalElement(globalElementId) {
102
+ const fetch = (id, version) => this.fetchGlobalElementImpl(id, version);
103
+ return await this.store.dispatch(
104
+ (0, import_fetch_api_resource.fetchAPIResource)(import_types.APIResourceType.GlobalElement, globalElementId, fetch)
105
+ );
106
+ }
86
107
  readGlobalElement(globalElementId) {
87
108
  return ApiClientState.getAPIResource(
88
109
  this.store.getState(),
@@ -90,6 +111,19 @@ class ApiResourcesClient {
90
111
  globalElementId
91
112
  );
92
113
  }
114
+ async fetchLocalizedGlobalElement({
115
+ globalElementId,
116
+ locale
117
+ }) {
118
+ const fetch = (id, version, locale2) => {
119
+ if (locale2 == null)
120
+ throw new Error("Locale is required to fetch LocalizedGlobalElement");
121
+ return this.fetchLocalizedGlobalElementImpl(id, version, locale2);
122
+ };
123
+ return await this.store.dispatch(
124
+ (0, import_fetch_api_resource.fetchAPIResource)(import_types.APIResourceType.LocalizedGlobalElement, globalElementId, fetch, locale)
125
+ );
126
+ }
93
127
  readLocalizedGlobalElement({
94
128
  globalElementId,
95
129
  locale
@@ -101,6 +135,15 @@ class ApiResourcesClient {
101
135
  locale
102
136
  );
103
137
  }
138
+ async fetchPagePathnameSlice({
139
+ pageId,
140
+ locale
141
+ }) {
142
+ const fetch = (id, version, locale2) => this.fetchPagePathnameSliceImpl(id, version, locale2);
143
+ return await this.store.dispatch(
144
+ (0, import_fetch_api_resource.fetchAPIResource)(import_types.APIResourceType.PagePathnameSlice, pageId, fetch, locale)
145
+ );
146
+ }
104
147
  readPagePathnameSlice({
105
148
  pageId,
106
149
  locale
@@ -139,6 +182,10 @@ class ApiResourcesClient {
139
182
  fetch: async () => id != null ? fetch(id) : null
140
183
  };
141
184
  }
185
+ async fetchTable(tableId) {
186
+ const fetch = (id, version) => this.fetchTableImpl(id, version);
187
+ return await this.store.dispatch((0, import_fetch_api_resource.fetchAPIResource)(import_types.APIResourceType.Table, tableId, fetch));
188
+ }
142
189
  readTable(tableId) {
143
190
  return ApiClientState.getAPIResource(this.store.getState(), import_types.APIResourceType.Table, tableId);
144
191
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/api/api-resources-client.ts"],"sourcesContent":["import { type FetchableValue } from '@makeswift/controls'\n\nimport { type Store as ApiClientStore } from '../state/api-client/store'\nimport * as ApiClientState from '../state/api-client/state'\n\nimport {\n type File,\n type GlobalElement,\n type LocalizedGlobalElement,\n type Page,\n type PagePathnameSlice,\n type Site,\n type Snippet,\n type Swatch,\n type Table,\n type Typography,\n APIResourceType,\n} from './types'\n\nexport type CacheData = ApiClientState.SerializedState\n\nexport const CacheData = {\n empty(): CacheData {\n return {\n apiResources: {},\n localizedResourcesMap: {},\n }\n },\n}\n\nexport abstract class ApiResourcesClient {\n readonly store: ApiClientStore\n readonly subscribe: ApiClientStore['subscribe']\n\n constructor({ store }: { store: ApiClientStore }) {\n this.store = store\n this.subscribe = this.store.subscribe\n }\n\n abstract fetchSwatch(swatchId: string): Promise<Swatch | null>\n\n readSwatch(swatchId: string): Swatch | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Swatch, swatchId)\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 abstract fetchFile(fileId: string): Promise<File | null>\n\n readFile(fileId: string): File | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.File, fileId)\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 abstract fetchTypography(typographyId: string): Promise<Typography | null>\n\n readTypography(typographyId: string): Typography | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.Typography,\n 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 abstract fetchGlobalElement(globalElementId: string): Promise<GlobalElement | null>\n\n readGlobalElement(globalElementId: string): GlobalElement | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.GlobalElement,\n globalElementId,\n )\n }\n\n abstract fetchLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): Promise<LocalizedGlobalElement | null>\n\n readLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): LocalizedGlobalElement | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n locale,\n )\n }\n\n readPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): PagePathnameSlice | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.PagePathnameSlice,\n pageId,\n locale,\n )\n }\n\n abstract fetchPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): Promise<PagePathnameSlice | null>\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 abstract fetchTable(tableId: string): Promise<Table | null>\n\n readTable(tableId: string): Table | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Table, tableId)\n }\n\n readSite(siteId: string): Site | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Site, siteId)\n }\n\n readPage(pageId: string): Page | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Page, pageId)\n }\n\n readSnippet(snippetId: string): Snippet | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Snippet, snippetId)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAgC;AAEhC,mBAYO;AAIA,MAAM,YAAY;AAAA,EACvB,QAAmB;AACjB,WAAO;AAAA,MACL,cAAc,CAAC;AAAA,MACf,uBAAuB,CAAC;AAAA,IAC1B;AAAA,EACF;AACF;AAEO,MAAe,mBAAmB;AAAA,EAC9B;AAAA,EACA;AAAA,EAET,YAAY,EAAE,MAAM,GAA8B;AAChD,SAAK,QAAQ;AACb,SAAK,YAAY,KAAK,MAAM;AAAA,EAC9B;AAAA,EAIA,WAAW,UAAiC;AAC1C,WAAO,eAAe,eAAe,KAAK,MAAM,SAAS,GAAG,6BAAgB,QAAQ,QAAQ;AAAA,EAC9F;AAAA,EAEA,cAAc,UAA6D;AACzE,WAAO,KAAK,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.ts"],"sourcesContent":["import { type FetchableValue } from '@makeswift/controls'\n\nimport { type Store as ApiClientStore } from '../state/api-client/store'\nimport * as ApiClientState from '../state/api-client/state'\nimport { fetchAPIResource } from '../state/api-client/fetch-api-resource'\n\nimport {\n type File,\n type GlobalElement,\n type LocalizedGlobalElement,\n type Page,\n type PagePathnameSlice,\n type Site,\n type Snippet,\n type Swatch,\n type Table,\n type Typography,\n APIResourceType,\n} from './types'\n\nimport { type SiteVersion } from './site-version'\n\nexport type CacheData = ApiClientState.SerializedState\n\nexport const CacheData = {\n empty(): CacheData {\n return {\n apiResources: {},\n localizedResourcesMap: {},\n }\n },\n}\n\nexport abstract class ApiResourcesClient {\n readonly store: ApiClientStore\n readonly subscribe: ApiClientStore['subscribe']\n\n constructor({ store }: { store: ApiClientStore }) {\n this.store = store\n this.subscribe = this.store.subscribe\n }\n\n async fetchSwatch(swatchId: string): Promise<Swatch | null> {\n const fetch = (id: string, version: SiteVersion | null) => this.fetchSwatchImpl(id, version)\n\n return await this.store.dispatch(fetchAPIResource(APIResourceType.Swatch, swatchId, fetch))\n }\n\n readSwatch(swatchId: string): Swatch | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Swatch, swatchId)\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 async fetchFile(fileId: string): Promise<File | null> {\n const fetch = (id: string, version: SiteVersion | null) => this.fetchFileImpl(id, version)\n\n return await this.store.dispatch(fetchAPIResource(APIResourceType.File, fileId, fetch))\n }\n\n readFile(fileId: string): File | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.File, fileId)\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 async fetchTypography(typographyId: string): Promise<Typography | null> {\n const fetch = (id: string, version: SiteVersion | null) => this.fetchTypographyImpl(id, version)\n\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.Typography, typographyId, fetch),\n )\n }\n\n readTypography(typographyId: string): Typography | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.Typography,\n 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 async fetchGlobalElement(globalElementId: string): Promise<GlobalElement | null> {\n const fetch = (id: string, version: SiteVersion | null) =>\n this.fetchGlobalElementImpl(id, version)\n\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.GlobalElement, globalElementId, fetch),\n )\n }\n\n readGlobalElement(globalElementId: string): GlobalElement | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.GlobalElement,\n globalElementId,\n )\n }\n\n async fetchLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): Promise<LocalizedGlobalElement | null> {\n const fetch = (id: string, version: SiteVersion | null, locale: string | null | undefined) => {\n if (locale == null) throw new Error('Locale is required to fetch LocalizedGlobalElement')\n return this.fetchLocalizedGlobalElementImpl(id, version, locale)\n }\n\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.LocalizedGlobalElement, globalElementId, fetch, locale),\n )\n }\n\n readLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): LocalizedGlobalElement | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\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 const fetch = (id: string, version: SiteVersion | null, locale: string | null | undefined) =>\n this.fetchPagePathnameSliceImpl(id, version, locale)\n\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.PagePathnameSlice, pageId, fetch, locale),\n )\n }\n\n readPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): PagePathnameSlice | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.PagePathnameSlice,\n pageId,\n 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 async fetchTable(tableId: string): Promise<Table | null> {\n const fetch = (id: string, version: SiteVersion | null) => this.fetchTableImpl(id, version)\n\n return await this.store.dispatch(fetchAPIResource(APIResourceType.Table, tableId, fetch))\n }\n\n readTable(tableId: string): Table | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Table, tableId)\n }\n\n readSite(siteId: string): Site | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Site, siteId)\n }\n\n readPage(pageId: string): Page | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Page, pageId)\n }\n\n readSnippet(snippetId: string): Snippet | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Snippet, snippetId)\n }\n\n protected abstract fetchSwatchImpl(\n id: string,\n version: SiteVersion | null,\n ): Promise<Swatch | null>\n\n protected abstract fetchFileImpl(id: string, version: SiteVersion | null): Promise<File | null>\n protected abstract fetchTypographyImpl(\n id: string,\n version: SiteVersion | null,\n ): Promise<Typography | null>\n\n protected abstract fetchGlobalElementImpl(\n id: string,\n version: SiteVersion | null,\n ): Promise<GlobalElement | null>\n\n protected abstract fetchLocalizedGlobalElementImpl(\n id: string,\n version: SiteVersion | null,\n locale: string,\n ): Promise<LocalizedGlobalElement | null>\n\n protected abstract fetchPagePathnameSliceImpl(\n id: string,\n version: SiteVersion | null,\n locale: string | null | undefined,\n ): Promise<PagePathnameSlice | null>\n\n protected abstract fetchTableImpl(id: string, version: SiteVersion | null): Promise<Table | null>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAgC;AAChC,gCAAiC;AAEjC,mBAYO;AAMA,MAAM,YAAY;AAAA,EACvB,QAAmB;AACjB,WAAO;AAAA,MACL,cAAc,CAAC;AAAA,MACf,uBAAuB,CAAC;AAAA,IAC1B;AAAA,EACF;AACF;AAEO,MAAe,mBAAmB;AAAA,EAC9B;AAAA,EACA;AAAA,EAET,YAAY,EAAE,MAAM,GAA8B;AAChD,SAAK,QAAQ;AACb,SAAK,YAAY,KAAK,MAAM;AAAA,EAC9B;AAAA,EAEA,MAAM,YAAY,UAA0C;AAC1D,UAAM,QAAQ,CAAC,IAAY,YAAgC,KAAK,gBAAgB,IAAI,OAAO;AAE3F,WAAO,MAAM,KAAK,MAAM,aAAS,4CAAiB,6BAAgB,QAAQ,UAAU,KAAK,CAAC;AAAA,EAC5F;AAAA,EAEA,WAAW,UAAiC;AAC1C,WAAO,eAAe,eAAe,KAAK,MAAM,SAAS,GAAG,6BAAgB,QAAQ,QAAQ;AAAA,EAC9F;AAAA,EAEA,cAAc,UAA6D;AACzE,WAAO,KAAK,gBAAgB,6BAAgB,QAAQ;AAAA,MAClD,IAAI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,SAAS,GAAG,6BAAgB,SAAS,SAAS;AAAA,EAChG;AA+BF;","names":["locale"]}
@@ -27,7 +27,7 @@ class MakeswiftGraphQLApiClient {
27
27
  graphqlClient;
28
28
  constructor({ endpoint }) {
29
29
  this.graphqlClient = new import_client.GraphQLClient(endpoint, {
30
- "makeswift-runtime-version": "0.28.7-canary.9"
30
+ "makeswift-runtime-version": "0.28.8-canary.0"
31
31
  });
32
32
  }
33
33
  async createTableRecord(tableId, columns) {
@@ -18,15 +18,12 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var host_api_resources_client_exports = {};
20
20
  __export(host_api_resources_client_exports, {
21
- CacheData: () => import_api_resources_client2.CacheData,
22
21
  HostApiResourcesClient: () => HostApiResourcesClient
23
22
  });
24
23
  module.exports = __toCommonJS(host_api_resources_client_exports);
25
- var import_fetch_api_resource = require("../state/api-client/fetch-api-resource");
26
24
  var import_client_store = require("../state/api-client/client-store");
27
- var import_types = require("./types");
25
+ var import_site_version = require("./site-version");
28
26
  var import_api_resources_client = require("./api-resources-client");
29
- var import_api_resources_client2 = require("./api-resources-client");
30
27
  class HostApiResourcesClient extends import_api_resources_client.ApiResourcesClient {
31
28
  fetch;
32
29
  constructor({
@@ -38,45 +35,54 @@ class HostApiResourcesClient extends import_api_resources_client.ApiResourcesCli
38
35
  });
39
36
  this.fetch = fetch;
40
37
  }
41
- async fetchSwatch(swatchId) {
42
- return await this.store.dispatch((0, import_fetch_api_resource.fetchAPIResource)(import_types.APIResourceType.Swatch, swatchId, this.fetch));
38
+ async fetchSwatchImpl(id, version) {
39
+ return await this.fetchVersioned(`/api/makeswift/swatches/${id}`, version);
43
40
  }
44
- async fetchFile(fileId) {
45
- return await this.store.dispatch((0, import_fetch_api_resource.fetchAPIResource)(import_types.APIResourceType.File, fileId, this.fetch));
41
+ async fetchFileImpl(id, version) {
42
+ return await this.fetchVersioned(`/api/makeswift/files/${id}`, version);
46
43
  }
47
- async fetchTypography(typographyId) {
48
- return await this.store.dispatch(
49
- (0, import_fetch_api_resource.fetchAPIResource)(import_types.APIResourceType.Typography, typographyId, this.fetch)
50
- );
44
+ async fetchTypographyImpl(id, version) {
45
+ return await this.fetchVersioned(`/api/makeswift/typographies/${id}`, version);
51
46
  }
52
- async fetchGlobalElement(globalElementId) {
53
- return await this.store.dispatch(
54
- (0, import_fetch_api_resource.fetchAPIResource)(import_types.APIResourceType.GlobalElement, globalElementId, this.fetch)
55
- );
47
+ async fetchGlobalElementImpl(id, version) {
48
+ return await this.fetchVersioned(`/api/makeswift/global-elements/${id}`, version);
56
49
  }
57
- async fetchLocalizedGlobalElement({
58
- globalElementId,
59
- locale
60
- }) {
61
- return await this.store.dispatch(
62
- (0, import_fetch_api_resource.fetchAPIResource)(import_types.APIResourceType.LocalizedGlobalElement, globalElementId, this.fetch, locale)
50
+ async fetchLocalizedGlobalElementImpl(id, version, locale) {
51
+ return await this.fetchVersioned(
52
+ `/api/makeswift/localized-global-elements/${id}/${locale}`,
53
+ version
63
54
  );
64
55
  }
65
- async fetchPagePathnameSlice({
66
- pageId,
67
- locale
68
- }) {
69
- return await this.store.dispatch(
70
- (0, import_fetch_api_resource.fetchAPIResource)(import_types.APIResourceType.PagePathnameSlice, pageId, this.fetch, locale)
71
- );
56
+ async fetchPagePathnameSliceImpl(id, version, locale) {
57
+ const url = new URL(`/api/makeswift/page-pathname-slices/${id}`, "http://n");
58
+ if (locale != null)
59
+ url.searchParams.set("locale", locale);
60
+ return await this.fetchVersioned(url.pathname + url.search, version);
61
+ }
62
+ async fetchTableImpl(id, version) {
63
+ return await this.fetchVersioned(`/api/makeswift/tables/${id}`, version);
72
64
  }
73
- async fetchTable(tableId) {
74
- return await this.store.dispatch((0, import_fetch_api_resource.fetchAPIResource)(import_types.APIResourceType.Table, tableId, this.fetch));
65
+ async fetchVersioned(url, version) {
66
+ const response = await this.fetch(url, {
67
+ headers: {
68
+ "Content-Type": "application/json",
69
+ ...version != null ? { [import_site_version.ApiHandlerHeaders.SiteVersion]: (0, import_site_version.serializeSiteVersion)(version) } : {}
70
+ }
71
+ });
72
+ if (response.status === 404)
73
+ return null;
74
+ if (!response.ok)
75
+ throw new Error(response.statusText);
76
+ if (response.headers.get("content-type")?.includes("application/json") !== true) {
77
+ throw new Error(
78
+ `Expected JSON response from "${url}" but got "${response.headers.get("content-type")}"`
79
+ );
80
+ }
81
+ return response.json();
75
82
  }
76
83
  }
77
84
  // Annotate the CommonJS export names for ESM import in node:
78
85
  0 && (module.exports = {
79
- CacheData,
80
86
  HostApiResourcesClient
81
87
  });
82
88
  //# sourceMappingURL=host-api-resources-client.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/api/host-api-resources-client.ts"],"sourcesContent":["import { type State as ApiClientState } from '../state/api-client/state'\nimport { fetchAPIResource } from '../state/api-client/fetch-api-resource'\nimport { configureClientStore } from '../state/api-client/client-store'\n\nimport {\n type File,\n type GlobalElement,\n type LocalizedGlobalElement,\n type PagePathnameSlice,\n type Swatch,\n type Table,\n type Typography,\n type HttpFetch,\n APIResourceType,\n} from './types'\n\nimport { ApiResourcesClient } from './api-resources-client'\n\nexport { CacheData } from './api-resources-client'\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 HostApiResourcesClient extends ApiResourcesClient {\n readonly fetch: HttpFetch\n\n constructor({\n fetch,\n preloadedState,\n }: {\n fetch: HttpFetch\n preloadedState: Partial<ApiClientState>\n }) {\n super({\n store: configureClientStore({ preloadedState }),\n })\n\n this.fetch = fetch\n }\n\n async fetchSwatch(swatchId: string): Promise<Swatch | null> {\n return await this.store.dispatch(fetchAPIResource(APIResourceType.Swatch, swatchId, this.fetch))\n }\n\n async fetchFile(fileId: string): Promise<File | null> {\n return await this.store.dispatch(fetchAPIResource(APIResourceType.File, fileId, this.fetch))\n }\n\n async fetchTypography(typographyId: string): Promise<Typography | null> {\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.Typography, typographyId, this.fetch),\n )\n }\n\n async fetchGlobalElement(globalElementId: string): Promise<GlobalElement | null> {\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.GlobalElement, globalElementId, this.fetch),\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.store.dispatch(\n fetchAPIResource(APIResourceType.LocalizedGlobalElement, globalElementId, this.fetch, 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.store.dispatch(\n fetchAPIResource(APIResourceType.PagePathnameSlice, pageId, this.fetch, locale),\n )\n }\n\n async fetchTable(tableId: string): Promise<Table | null> {\n return await this.store.dispatch(fetchAPIResource(APIResourceType.Table, tableId, this.fetch))\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,gCAAiC;AACjC,0BAAqC;AAErC,mBAUO;AAEP,kCAAmC;AAEnC,IAAAA,+BAA0B;AAqBnB,MAAM,+BAA+B,+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ources_client"]}
1
+ {"version":3,"sources":["../../../src/api/host-api-resources-client.ts"],"sourcesContent":["import { type State as ApiClientState } from '../state/api-client/state'\n\nimport { configureClientStore } from '../state/api-client/client-store'\n\nimport {\n type File,\n type GlobalElement,\n type LocalizedGlobalElement,\n type PagePathnameSlice,\n type Swatch,\n type Table,\n type Typography,\n type HttpFetch,\n} from './types'\n\nimport { type SiteVersion, ApiHandlerHeaders, serializeSiteVersion } from './site-version'\nimport { ApiResourcesClient } from './api-resources-client'\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 HostApiResourcesClient extends ApiResourcesClient {\n readonly fetch: HttpFetch\n\n constructor({\n fetch,\n preloadedState,\n }: {\n fetch: HttpFetch\n preloadedState: Partial<ApiClientState>\n }) {\n super({\n store: configureClientStore({ preloadedState }),\n })\n\n this.fetch = fetch\n }\n\n protected async fetchSwatchImpl(id: string, version: SiteVersion | null): Promise<Swatch | null> {\n return await this.fetchVersioned<Swatch>(`/api/makeswift/swatches/${id}`, version)\n }\n\n protected async fetchFileImpl(id: string, version: SiteVersion | null): Promise<File | null> {\n return await this.fetchVersioned<File>(`/api/makeswift/files/${id}`, version)\n }\n\n protected async fetchTypographyImpl(\n id: string,\n version: SiteVersion | null,\n ): Promise<Typography | null> {\n return await this.fetchVersioned<Typography>(`/api/makeswift/typographies/${id}`, version)\n }\n\n protected async fetchGlobalElementImpl(\n id: string,\n version: SiteVersion | null,\n ): Promise<GlobalElement | null> {\n return await this.fetchVersioned<GlobalElement>(`/api/makeswift/global-elements/${id}`, version)\n }\n\n protected async fetchLocalizedGlobalElementImpl(\n id: string,\n version: SiteVersion | null,\n locale: string,\n ): Promise<LocalizedGlobalElement | null> {\n return await this.fetchVersioned<LocalizedGlobalElement>(\n `/api/makeswift/localized-global-elements/${id}/${locale}`,\n version,\n )\n }\n\n protected async fetchPagePathnameSliceImpl(\n id: string,\n version: SiteVersion | null,\n locale: string | null | undefined,\n ): Promise<PagePathnameSlice | null> {\n const url = new URL(`/api/makeswift/page-pathname-slices/${id}`, 'http://n')\n\n if (locale != null) url.searchParams.set('locale', locale)\n\n return await this.fetchVersioned<PagePathnameSlice>(url.pathname + url.search, version)\n }\n\n protected async fetchTableImpl(id: string, version: SiteVersion | null): Promise<Table | null> {\n return await this.fetchVersioned<Table>(`/api/makeswift/tables/${id}`, version)\n }\n\n private async fetchVersioned<T>(url: string, version: SiteVersion | null): Promise<T | null> {\n const response = await this.fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n ...(version != null\n ? { [ApiHandlerHeaders.SiteVersion]: serializeSiteVersion(version) }\n : {}),\n },\n })\n\n if (response.status === 404) return null\n if (!response.ok) throw new Error(response.statusText)\n\n if (response.headers.get('content-type')?.includes('application/json') !== true) {\n throw new Error(\n `Expected JSON response from \"${url}\" but got \"${response.headers.get('content-type')}\"`,\n )\n }\n\n return response.json()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAAqC;AAarC,0BAA0E;AAC1E,kCAAmC;AAqB5B,MAAM,+BAA+B,+CAAmB;AAAA,EACpD;AAAA,EAET,YAAY;AAAA,IACV;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B,OAAO,EAAE,IACjE,CAAC;AAAA,MACP;AAAA,IACF,CAAC;AAED,QAAI,SAAS,WAAW;AAAK,aAAO;AACpC,QAAI,CAAC,SAAS;AAAI,YAAM,IAAI,MAAM,SAAS,UAAU;AAErD,QAAI,SAAS,QAAQ,IAAI,cAAc,GAAG,SAAS,kBAAkB,MAAM,MAAM;AAC/E,YAAM,IAAI;AAAA,QACR,gCAAgC,GAAG,cAAc,SAAS,QAAQ,IAAI,cAAc,CAAC;AAAA,MACvF;AAAA,IACF;AAEA,WAAO,SAAS,KAAK;AAAA,EACvB;AACF;","names":[]}
@@ -0,0 +1,70 @@
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 makeswift_api_resources_client_exports = {};
20
+ __export(makeswift_api_resources_client_exports, {
21
+ MakeswiftApiResourcesClient: () => MakeswiftApiResourcesClient
22
+ });
23
+ module.exports = __toCommonJS(makeswift_api_resources_client_exports);
24
+ var import_client_store = require("../state/api-client/client-store");
25
+ var import_api_resources_client = require("./api-resources-client");
26
+ var import_graphql_api_client = require("./graphql-api-client");
27
+ var import_rest_api_client = require("./rest-api-client");
28
+ class MakeswiftApiResourcesClient extends import_api_resources_client.ApiResourcesClient {
29
+ restApiClient;
30
+ graphQlClient;
31
+ constructor({
32
+ fetch,
33
+ apiKey,
34
+ apiOrigin,
35
+ graphqlApiEndpoint,
36
+ preloadedState
37
+ }) {
38
+ super({
39
+ store: (0, import_client_store.configureClientStore)({ preloadedState })
40
+ });
41
+ this.restApiClient = new import_rest_api_client.MakeswiftRestAPIClient({ fetch, apiKey, apiOrigin });
42
+ this.graphQlClient = new import_graphql_api_client.MakeswiftGraphQLApiClient({ endpoint: graphqlApiEndpoint });
43
+ }
44
+ async fetchSwatchImpl(id, version) {
45
+ return this.restApiClient.getSwatch(id, version);
46
+ }
47
+ async fetchFileImpl(id, _version) {
48
+ return this.graphQlClient.getFile(id);
49
+ }
50
+ async fetchTypographyImpl(id, version) {
51
+ return this.restApiClient.getTypography(id, version);
52
+ }
53
+ async fetchGlobalElementImpl(id, version) {
54
+ return this.restApiClient.getGlobalElement(id, version);
55
+ }
56
+ async fetchLocalizedGlobalElementImpl(id, version, locale) {
57
+ return this.restApiClient.getLocalizedGlobalElement(id, locale, version);
58
+ }
59
+ async fetchPagePathnameSliceImpl(id, version, locale) {
60
+ return this.restApiClient.getPagePathnameSlice(id, version, { locale });
61
+ }
62
+ async fetchTableImpl(id, _version) {
63
+ return this.graphQlClient.getTable(id);
64
+ }
65
+ }
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ MakeswiftApiResourcesClient
69
+ });
70
+ //# sourceMappingURL=makeswift-api-resources-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/api/makeswift-api-resources-client.ts"],"sourcesContent":["import { type State as ApiClientState } from '../state/api-client/state'\nimport { configureClientStore } from '../state/api-client/client-store'\n\nimport {\n type File,\n type GlobalElement,\n type LocalizedGlobalElement,\n type PagePathnameSlice,\n type Swatch,\n type Table,\n type Typography,\n type HttpFetch,\n} from './types'\n\nimport { ApiResourcesClient } from './api-resources-client'\nimport { MakeswiftGraphQLApiClient } from './graphql-api-client'\nimport { MakeswiftRestAPIClient } from './rest-api-client'\nimport { type SiteVersion } from './site-version'\n\n/**\n * Server-side implementation that makes direct authenticated requests to the Makeswift API.\n * Requires an API key.\n *\n * For client-side usage, see `HostApiResourcesClient`, which goes through the host via\n * `/api/makeswift/...` endpoints.\n */\nexport class MakeswiftApiResourcesClient extends ApiResourcesClient {\n private restApiClient: MakeswiftRestAPIClient\n private graphQlClient: MakeswiftGraphQLApiClient\n\n constructor({\n fetch,\n apiKey,\n apiOrigin,\n graphqlApiEndpoint,\n preloadedState,\n }: {\n fetch: HttpFetch\n apiKey: string\n apiOrigin: string\n graphqlApiEndpoint: string\n preloadedState: Partial<ApiClientState>\n }) {\n super({\n store: configureClientStore({ preloadedState }),\n })\n\n this.restApiClient = new MakeswiftRestAPIClient({ fetch, apiKey, apiOrigin })\n this.graphQlClient = new MakeswiftGraphQLApiClient({ endpoint: graphqlApiEndpoint })\n }\n\n protected async fetchSwatchImpl(id: string, version: SiteVersion | null): Promise<Swatch | null> {\n return this.restApiClient.getSwatch(id, version)\n }\n\n protected async fetchFileImpl(id: string, _version: SiteVersion | null): Promise<File | null> {\n // files are unversioned\n return this.graphQlClient.getFile(id)\n }\n\n protected async fetchTypographyImpl(\n id: string,\n version: SiteVersion | null,\n ): Promise<Typography | null> {\n return this.restApiClient.getTypography(id, version)\n }\n\n protected async fetchGlobalElementImpl(\n id: string,\n version: SiteVersion | null,\n ): Promise<GlobalElement | null> {\n return this.restApiClient.getGlobalElement(id, version)\n }\n\n protected async fetchLocalizedGlobalElementImpl(\n id: string,\n version: SiteVersion | null,\n locale: string,\n ): Promise<LocalizedGlobalElement | null> {\n return this.restApiClient.getLocalizedGlobalElement(id, locale, version)\n }\n\n protected async fetchPagePathnameSliceImpl(\n id: string,\n version: SiteVersion | null,\n locale: string | null | undefined,\n ): Promise<PagePathnameSlice | null> {\n return this.restApiClient.getPagePathnameSlice(id, version, { locale })\n }\n\n protected async fetchTableImpl(id: string, _version: SiteVersion | null): Promise<Table | null> {\n // tables are unversioned\n return this.graphQlClient.get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eaders = new Headers({
148
148
  "x-api-key": this.apiKey,
149
149
  "makeswift-site-api-key": this.apiKey,
150
- "makeswift-runtime-version": "0.28.7-canary.9"
150
+ "makeswift-runtime-version": "0.28.8-canary.0"
151
151
  });
152
152
  if (siteVersion?.token) {
153
153
  requestUrl.searchParams.set("version", siteVersion.version);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/api/rest-api-client.ts"],"sourcesContent":["import {\n type GlobalElement,\n type LocalizedGlobalElement,\n type PagePathnameSlice,\n type Swatch,\n type Typography,\n type HttpFetch,\n} from './types'\n\nimport { type SiteVersion } from './site-version'\nimport * as Schema from './schema'\n\nexport class MakeswiftRestAPIClient {\n private _fetch: HttpFetch\n\n readonly apiKey: string\n readonly apiOrigin: string\n\n constructor({\n fetch,\n apiKey,\n apiOrigin,\n }: {\n fetch: HttpFetch\n apiKey: string\n apiOrigin: string\n }) {\n this._fetch = fetch\n this.apiKey = apiKey\n this.apiOrigin = apiOrigin\n }\n\n async getSwatch(swatchId: string, siteVersion: SiteVersion | null): Promise<Swatch | null> {\n const response = await this.fetch(`v3/swatches/${swatchId}`, siteVersion)\n\n if (!response.ok) {\n const failedBody = await failedResponseBody(response)\n if (response.status !== 404) {\n console.error(`Failed to get swatch '${swatchId}'`, {\n response: failedBody,\n siteVersion,\n })\n }\n\n return null\n }\n\n const swatch = await response.json()\n\n return swatch\n }\n\n async getTypography(\n typographyId: string,\n siteVersion: SiteVersion | null,\n ): Promise<Typography | null> {\n const response = await this.fetch(`v3/typographies/${typographyId}`, siteVersion)\n\n if (!response.ok) {\n const failedBody = await failedResponseBody(response)\n if (response.status !== 404) {\n console.error(`Failed to get typography '${typographyId}'`, {\n response: failedBody,\n siteVersion,\n })\n }\n\n return null\n }\n\n const typography = await response.json()\n\n return typography\n }\n\n async getGlobalElement(\n globalElementId: string,\n siteVersion: SiteVersion | null,\n ): Promise<GlobalElement | null> {\n const response = await this.fetch(`v3/global-elements/${globalElementId}`, siteVersion)\n\n if (!response.ok) {\n const failedBody = await failedResponseBody(response)\n if (response.status !== 404) {\n console.error(`Failed to get global element '${globalElementId}'`, {\n response: failedBody,\n siteVersion,\n })\n }\n\n return null\n }\n\n const globalElement = await response.json()\n\n return globalElement\n }\n\n async getLocalizedGlobalElement(\n globalElementId: string,\n locale: string,\n siteVersion: SiteVersion | null,\n ): Promise<LocalizedGlobalElement | null> {\n const response = await this.fetch(\n `v3/localized-global-elements/${globalElementId}?locale=${locale}`,\n siteVersion,\n )\n\n if (!response.ok) {\n const failedBody = await failedResponseBody(response)\n if (response.status !== 404) {\n console.error(`Failed to get localized global element '${globalElementId}'`, {\n response: failedBody,\n siteVersion,\n locale,\n })\n }\n\n return null\n }\n\n const localizedGlobalElement = await response.json()\n\n return localizedGlobalElement\n }\n\n async getPagePathnameSlices(\n pageIds: string[],\n siteVersion: SiteVersion | null,\n { locale }: { locale?: string | null },\n ): Promise<(PagePathnameSlice | null)[]> {\n if (pageIds.length === 0) return []\n\n const url = new URL(`v3/page-pathname-slices/bulk`, this.apiOrigin)\n\n pageIds.forEach(id => url.searchParams.append('ids', id))\n if (locale != null) url.searchParams.set('locale', locale)\n\n const response = await this.fetch(url.pathname + url.search, siteVersion)\n\n if (!response.ok) {\n console.error(`Failed to get page pathname slice(s) for ${pageIds.join(', ')}`, {\n response: await failedResponseBody(response),\n siteVersion,\n locale,\n })\n\n return []\n }\n\n const json = await response.json()\n\n const pagePathnameSlices = Schema.pagePathnameSlices.parse(json)\n\n // We're mapping the basePageId to be the id, because we're still using the GraphQL\n // fragment as our APIResource. The id on the APIResource needs to match the pageId\n // so that we can find the corresponding page pathname slice when we call getPagePathnameSlice(pageId).\n // TODO: Update this once we move away from the GraphQL fragments.\n return pagePathnameSlices.map(pagePathnameSlice => {\n if (pagePathnameSlice == null) return null\n\n return {\n ...pagePathnameSlice,\n id: pagePathnameSlice.basePageId,\n localizedPathname: pagePathnameSlice.localizedPathname ?? null,\n }\n })\n }\n\n async getPagePathnameSlice(\n pageId: string,\n siteVersion: SiteVersion | null,\n { locale }: { locale?: string } = {},\n ): Promise<PagePathnameSlice | null> {\n const pagePathnameSlices = await this.getPagePathnameSlices([pageId], siteVersion, { locale })\n\n return pagePathnameSlices.at(0) ?? null\n }\n\n protected async fetch(\n path: string,\n siteVersion: SiteVersion | null,\n init?: RequestInit,\n ): Promise<Response> {\n const requestUrl = new URL(path, this.apiOrigin)\n\n const requestHeaders = new Headers({\n 'x-api-key': this.apiKey,\n 'makeswift-site-api-key': this.apiKey,\n 'makeswift-runtime-version': PACKAGE_VERSION,\n })\n\n if (siteVersion?.token) {\n requestUrl.searchParams.set('version', siteVersion.version)\n requestHeaders.set('makeswift-preview-token', siteVersion.token)\n }\n\n if (init?.headers) {\n new Headers(init.headers).forEach((value, key) => {\n requestHeaders.set(key, value)\n })\n }\n\n const response = await this._fetch(requestUrl.toString(), {\n ...init,\n headers: requestHeaders,\n ...(siteVersion != null ? { cache: 'no-store' } : {}),\n })\n\n return response\n }\n}\n\n// This function attempts to consume the response body of a failed response, and\n// returns either the parsed JSON or raw text. This is useful for logging more\n// detailed error information when an API request fails.\n//\n// Cloudflare Worker Note: The Cloudflare Worker runtime has automatic deadlock\n// prevention (in the form of auto-cancelling responses) that triggers when too\n// many response bodies are unconsumed. This applies for error responses as\n// well. As such, in this client we use this function to consume the response\n// body whenever the request fails, even if we don't end up logging the body\n// itself, to avoid hitting the deadlock prevention.\nexport async function failedResponseBody(response: Response): Promise<unknown> {\n try {\n const text = await response.text()\n try {\n return JSON.parse(text)\n } catch {\n return text\n }\n } catch (e) {\n return `Failed to extract response body: ${e}`\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,aAAwB;AAEjB,MAAM,uBAAuB;AAAA,EAC1B;AAAA,EAEC;AAAA,EACA;AAAA,EAET,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAIG;AACD,SAAK,SAAS;AACd,SA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,QACA,aACA,EAAE,OAAO,IAAyB,CAAC,GACA;AACnC,UAAM,qBAAqB,MAAM,KAAK,sBAAsB,CAAC,MAAM,GAAG,aAAa,EAAE,OAAO,CAAC;AAE7F,WAAO,mBAAmB,GAAG,CAAC,KAAK;AAAA,EACrC;AAAA,EAEA,MAAgB,MACd,MACA,aACA,MACmB;AACnB,UAAM,aAAa,IAAI,IAAI,MAAM,KAAK,SAAS;AAE/C,UAAM,iBAAiB,IAAI,QAAQ;AAAA,MACjC,aAAa,KAAK;AAAA,MAClB,0BAA0B,KAAK;AAAA,MAC/B,6BAA6B;AAAA,IAC/B,CAAC;AAED,QAAI,aAAa,OAAO;AACtB,iBAAW,aAAa,IAAI,WAAW,YAAY,OAAO;AAC1D,qBAAe,IAAI,2BAA2B,YAAY,KAAK;AAAA,IACjE;AAEA,QAAI,MAAM,SAAS;AACjB,UAAI,QAAQ,KAAK,OAAO,EAAE,QAAQ,CAAC,OAAO,QAAQ;AAChD,uBAAe,IAAI,KAAK,KAAK;AAAA,MAC/B,CAAC;AAAA,IACH;AAEA,UAAM,WAAW,MAAM,KAAK,OAAO,WAAW,SAAS,GAAG;AAAA,MACxD,GAAG;AAAA,MACH,SAAS;AAAA,MACT,GAAI,eAAe,OAAO,EAAE,OAAO,WAAW,IAAI,CAAC;AAAA,IACrD,CAAC;AAED,WAAO;AAAA,EACT;AACF;AAYA,eAAsB,mBAAmB,UAAsC;AAC7E,MAAI;AACF,UAAM,OAAO,MAAM,SAAS,KAAK;AACjC,QAAI;AACF,aAAO,KAAK,MAAM,IAAI;AAAA,IACxB,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAG;AACV,WAAO,oCAAoC,CAAC;AAAA,EAC9C;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/api/rest-api-client.ts"],"sourcesContent":["import {\n type GlobalElement,\n type LocalizedGlobalElement,\n type PagePathnameSlice,\n type Swatch,\n type Typography,\n type HttpFetch,\n} from './types'\n\nimport { type SiteVersion } from './site-version'\nimport * as Schema from './schema'\n\nexport class MakeswiftRestAPIClient {\n private _fetch: HttpFetch\n\n readonly apiKey: string\n readonly apiOrigin: string\n\n constructor({\n fetch,\n apiKey,\n apiOrigin,\n }: {\n fetch: HttpFetch\n apiKey: string\n apiOrigin: string\n }) {\n this._fetch = fetch\n this.apiKey = apiKey\n this.apiOrigin = apiOrigin\n }\n\n async getSwatch(swatchId: string, siteVersion: SiteVersion | null): Promise<Swatch | null> {\n const response = await this.fetch(`v3/swatches/${swatchId}`, siteVersion)\n\n if (!response.ok) {\n const failedBody = await failedResponseBody(response)\n if (response.status !== 404) {\n console.error(`Failed to get swatch '${swatchId}'`, {\n response: failedBody,\n siteVersion,\n })\n }\n\n return null\n }\n\n const swatch = await response.json()\n\n return swatch\n }\n\n async getTypography(\n typographyId: string,\n siteVersion: SiteVersion | null,\n ): Promise<Typography | null> {\n const response = await this.fetch(`v3/typographies/${typographyId}`, siteVersion)\n\n if (!response.ok) {\n const failedBody = await failedResponseBody(response)\n if (response.status !== 404) {\n console.error(`Failed to get typography '${typographyId}'`, {\n response: failedBody,\n siteVersion,\n })\n }\n\n return null\n }\n\n const typography = await response.json()\n\n return typography\n }\n\n async getGlobalElement(\n globalElementId: string,\n siteVersion: SiteVersion | null,\n ): Promise<GlobalElement | null> {\n const response = await this.fetch(`v3/global-elements/${globalElementId}`, siteVersion)\n\n if (!response.ok) {\n const failedBody = await failedResponseBody(response)\n if (response.status !== 404) {\n console.error(`Failed to get global element '${globalElementId}'`, {\n response: failedBody,\n siteVersion,\n })\n }\n\n return null\n }\n\n const globalElement = await response.json()\n\n return globalElement\n }\n\n async getLocalizedGlobalElement(\n globalElementId: string,\n locale: string,\n siteVersion: SiteVersion | null,\n ): Promise<LocalizedGlobalElement | null> {\n const response = await this.fetch(\n `v3/localized-global-elements/${globalElementId}?locale=${locale}`,\n siteVersion,\n )\n\n if (!response.ok) {\n const failedBody = await failedResponseBody(response)\n if (response.status !== 404) {\n console.error(`Failed to get localized global element '${globalElementId}'`, {\n response: failedBody,\n siteVersion,\n locale,\n })\n }\n\n return null\n }\n\n const localizedGlobalElement = await response.json()\n\n return localizedGlobalElement\n }\n\n async getPagePathnameSlices(\n pageIds: string[],\n siteVersion: SiteVersion | null,\n { locale }: { locale?: string | null },\n ): Promise<(PagePathnameSlice | null)[]> {\n if (pageIds.length === 0) return []\n\n const url = new URL(`v3/page-pathname-slices/bulk`, this.apiOrigin)\n\n pageIds.forEach(id => url.searchParams.append('ids', id))\n if (locale != null) url.searchParams.set('locale', locale)\n\n const response = await this.fetch(url.pathname + url.search, siteVersion)\n\n if (!response.ok) {\n console.error(`Failed to get page pathname slice(s) for ${pageIds.join(', ')}`, {\n response: await failedResponseBody(response),\n siteVersion,\n locale,\n })\n\n return []\n }\n\n const json = await response.json()\n\n const pagePathnameSlices = Schema.pagePathnameSlices.parse(json)\n\n // We're mapping the basePageId to be the id, because we're still using the GraphQL\n // fragment as our APIResource. The id on the APIResource needs to match the pageId\n // so that we can find the corresponding page pathname slice when we call getPagePathnameSlice(pageId).\n // TODO: Update this once we move away from the GraphQL fragments.\n return pagePathnameSlices.map(pagePathnameSlice => {\n if (pagePathnameSlice == null) return null\n\n return {\n ...pagePathnameSlice,\n id: pagePathnameSlice.basePageId,\n localizedPathname: pagePathnameSlice.localizedPathname ?? null,\n }\n })\n }\n\n async getPagePathnameSlice(\n pageId: string,\n siteVersion: SiteVersion | null,\n { locale }: { locale?: string | null } = {},\n ): Promise<PagePathnameSlice | null> {\n const pagePathnameSlices = await this.getPagePathnameSlices([pageId], siteVersion, { locale })\n\n return pagePathnameSlices.at(0) ?? null\n }\n\n protected async fetch(\n path: string,\n siteVersion: SiteVersion | null,\n init?: RequestInit,\n ): Promise<Response> {\n const requestUrl = new URL(path, this.apiOrigin)\n\n const requestHeaders = new Headers({\n 'x-api-key': this.apiKey,\n 'makeswift-site-api-key': this.apiKey,\n 'makeswift-runtime-version': PACKAGE_VERSION,\n })\n\n if (siteVersion?.token) {\n requestUrl.searchParams.set('version', siteVersion.version)\n requestHeaders.set('makeswift-preview-token', siteVersion.token)\n }\n\n if (init?.headers) {\n new Headers(init.headers).forEach((value, key) => {\n requestHeaders.set(key, value)\n })\n }\n\n const response = await this._fetch(requestUrl.toString(), {\n ...init,\n headers: requestHeaders,\n ...(siteVersion != null ? { cache: 'no-store' } : {}),\n })\n\n return response\n }\n}\n\n// This function attempts to consume the response body of a failed response, and\n// returns either the parsed JSON or raw text. This is useful for logging more\n// detailed error information when an API request fails.\n//\n// Cloudflare Worker Note: The Cloudflare Worker runtime has automatic deadlock\n// prevention (in the form of auto-cancelling responses) that triggers when too\n// many response bodies are unconsumed. This applies for error responses as\n// well. As such, in this client we use this function to consume the response\n// body whenever the request fails, even if we don't end up logging the body\n// itself, to avoid hitting the deadlock prevention.\nexport async function failedResponseBody(response: Response): Promise<unknown> {\n try {\n const text = await response.text()\n try {\n return JSON.parse(text)\n } catch {\n return text\n }\n } catch (e) {\n return `Failed to extract response body: ${e}`\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,aAAwB;AAEjB,MAAM,uBAAuB;AAAA,EAC1B;AAAA,EAEC;AAAA,EACA;AAAA,EAET,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAIG;AACD,SAAK,SAAS;AACd,SAAK,SAAS;AACd,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,MAAM,UAAU,UAAkB,aAAyD;AACzF,UAAM,WAAW,MAAM,KAAK,MAAM,eAAe,QAAQ,IAAI,WAAW;AAExE,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,aAAa,MAAM,mBAAmB,QAAQ;AACpD,UAAI,SAAS,WAAW,KAAK;AAC3B,gBAAQ,MAAM,yBAAyB,QAAQ,KAAK;AAAA,UAClD,UAAU;AAAA,UACV;AAAA,QACF,CAAC;AAAA,MACH;AAEA,aAAO;AAAA,I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AC/B,6BAA6B;AAAA,IAC/B,CAAC;AAED,QAAI,aAAa,OAAO;AACtB,iBAAW,aAAa,IAAI,WAAW,YAAY,OAAO;AAC1D,qBAAe,IAAI,2BAA2B,YAAY,KAAK;AAAA,IACjE;AAEA,QAAI,MAAM,SAAS;AACjB,UAAI,QAAQ,KAAK,OAAO,EAAE,QAAQ,CAAC,OAAO,QAAQ;AAChD,uBAAe,IAAI,KAAK,KAAK;AAAA,MAC/B,CAAC;AAAA,IACH;AAEA,UAAM,WAAW,MAAM,KAAK,OAAO,WAAW,SAAS,GAAG;AAAA,MACxD,GAAG;AAAA,MACH,SAAS;AAAA,MACT,GAAI,eAAe,OAAO,EAAE,OAAO,WAAW,IAAI,CAAC;AAAA,IACrD,CAAC;AAED,WAAO;AAAA,EACT;AACF;AAYA,eAAsB,mBAAmB,UAAsC;AAC7E,MAAI;AACF,UAAM,OAAO,MAAM,SAAS,KAAK;AACjC,QAAI;AACF,aAAO,KAAK,MAAM,IAAI;AAAA,IACxB,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAG;AACV,WAAO,oCAAoC,CAAC;AAAA,EAC9C;AACF;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/api/types.ts"],"sourcesContent":["import {\n SwatchFragment as Swatch,\n FileFragment as File,\n TypographyFragment as Typography,\n PagePathnameSliceFragment,\n GlobalElementFragment as GlobalElement,\n LocalizedGlobalElementFragment as LocalizedGlobalElement,\n TableFragment as Table,\n SnippetFragment as Snippet,\n PageFragment as Page,\n SiteFragment as Site,\n} from './graphql/generated/types'\n\ntype PagePathnameSlice = PagePathnameSliceFragment & {\n basePageId?: string\n localizedPathname?: string | null\n}\n\nexport type {\n Swatch,\n File,\n Typography,\n PagePathnameSlice,\n GlobalElement,\n LocalizedGlobalElement,\n Table,\n Snippet,\n Page,\n Site,\n}\n\nexport type LocalizableAPIResource = PagePathnameSlice | LocalizedGlobalElement\n\nexport const LocalizableAPIResourceType: {\n [R in LocalizableAPIResource as R['__typename']]: R['__typename']\n} = {\n PagePathnameSlice: 'PagePathnameSlice',\n LocalizedGlobalElement: 'LocalizedGlobalElement',\n}\n\nexport type LocalizableAPIResourceType =\n (typeof LocalizableAPIResourceType)[keyof typeof LocalizableAPIResourceType]\n\nexport type APIResource =\n | LocalizableAPIResource\n | Swatch\n | File\n | Typography\n | GlobalElement\n | Table\n | Snippet\n | Page\n | Site\n\nexport const APIResourceType: { [R in APIResource as R['__typename']]: R['__typename'] } = {\n ...LocalizableAPIResourceType,\n Swatch: 'Swatch',\n File: 'File',\n Typography: 'Typography',\n GlobalElement: 'GlobalElement',\n Table: 'Table',\n Snippet: 'Snippet',\n Page: 'Page',\n Site: 'Site',\n}\n\nexport type APIResourceType = (typeof APIResourceType)[keyof typeof APIResourceType]\n\nexport type APIResourceLocale<R extends APIResource | APIResourceType> = R extends\n | LocalizableAPIResource\n | LocalizableAPIResourceType\n ? string | null\n : never\n\nexport type HttpFetch = (url: string | URL, init?: RequestInit) => Promise<Response>\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiCO,MAAM,6BAET;AAAA,EACF,mBAAmB;AAAA,EACnB,wBAAwB;AAC1B;AAgBO,MAAM,kBAA8E;AAAA,EACzF,GAAG;AAAA,EACH,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AACR;","names":[]}
1
+ {"version":3,"sources":["../../../src/api/types.ts"],"sourcesContent":["import {\n SwatchFragment as Swatch,\n FileFragment as File,\n TypographyFragment as Typography,\n PagePathnameSliceFragment,\n GlobalElementFragment as GlobalElement,\n LocalizedGlobalElementFragment as LocalizedGlobalElement,\n TableFragment as Table,\n SnippetFragment as Snippet,\n PageFragment as Page,\n SiteFragment as Site,\n} from './graphql/generated/types'\n\ntype PagePathnameSlice = PagePathnameSliceFragment & {\n basePageId?: string\n localizedPathname?: string | null\n}\n\nexport type {\n Swatch,\n File,\n Typography,\n PagePathnameSlice,\n GlobalElement,\n LocalizedGlobalElement,\n Table,\n Snippet,\n Page,\n Site,\n}\n\nexport type LocalizableAPIResource = PagePathnameSlice | LocalizedGlobalElement\n\nexport const LocalizableAPIResourceType: {\n [R in LocalizableAPIResource as R['__typename']]: R['__typename']\n} = {\n PagePathnameSlice: 'PagePathnameSlice',\n LocalizedGlobalElement: 'LocalizedGlobalElement',\n}\n\nexport type LocalizableAPIResourceType =\n (typeof LocalizableAPIResourceType)[keyof typeof LocalizableAPIResourceType]\n\nexport type APIResource =\n | LocalizableAPIResource\n | Swatch\n | File\n | Typography\n | GlobalElement\n | Table\n | Snippet\n | Page\n | Site\n\nexport const APIResourceType: { [R in APIResource as R['__typename']]: R['__typename'] } = {\n ...LocalizableAPIResourceType,\n Swatch: 'Swatch',\n File: 'File',\n Typography: 'Typography',\n GlobalElement: 'GlobalElement',\n Table: 'Table',\n Snippet: 'Snippet',\n Page: 'Page',\n Site: 'Site',\n}\n\nexport type APIResourceType = (typeof APIResourceType)[keyof typeof APIResourceType]\n\nexport type APIResourceByType<T extends APIResourceType> = Extract<APIResource, { __typename: T }>\n\nexport type APIResourceLocale<R extends APIResource | APIResourceType> = R extends\n | LocalizableAPIResource\n | LocalizableAPIResourceType\n ? string | null\n : never\n\nexport type HttpFetch = (url: string | URL, init?: RequestInit) => Promise<Response>\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiCO,MAAM,6BAET;AAAA,EACF,mBAAmB;AAAA,EACnB,wBAAwB;AAC1B;AAgBO,MAAM,kBAA8E;AAAA,EACzF,GAAG;AAAA,EACH,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AACR;","names":[]}
@@ -28,7 +28,7 @@ async function manifestHandler(req, { apiKey, manifest }) {
28
28
  return import_request_response.ApiResponse.json({ message: "Unauthorized" }, { status: 401 });
29
29
  }
30
30
  return import_request_response.ApiResponse.json({
31
- version: "0.28.7-canary.9",
31
+ version: "0.28.8-canary.0",
32
32
  interactionMode: true,
33
33
  clientSideNavigation: false,
34
34
  elementFromPoint: false,
@@ -689,7 +689,7 @@ Received "${apiKey}" instead.`
689
689
  headers: {
690
690
  "x-api-key": this.apiKey,
691
691
  "makeswift-site-api-key": this.apiKey,
692
- "makeswift-runtime-version": "0.28.7-canary.9",
692
+ "makeswift-runtime-version": "0.28.8-canary.0",
693
693
  "content-type": "application/json"
694
694
  },
695
695
  body: JSON.stringify({ token }),
@@ -31,31 +31,12 @@ __export(fetch_api_resource_exports, {
31
31
  fetchAPIResource: () => fetchAPIResource
32
32
  });
33
33
  module.exports = __toCommonJS(fetch_api_resource_exports);
34
- var import_site_version = require("../../api/site-version");
35
34
  var SiteVersionState = __toESM(require("../modules/site-version"));
36
35
  var import_read_only_actions = require("../actions/internal/read-only-actions");
37
36
  var import_host_api = require("../host-api");
38
37
  var import_types = require("../../api/types");
39
38
  var import_state = require("./state");
40
- function fetchAPIResource(resourceType, resourceId, fetch, locale) {
41
- const fetchVersioned = async (url, version) => {
42
- const response = await fetch(url, {
43
- headers: {
44
- "Content-Type": "application/json",
45
- ...version != null ? { [import_site_version.ApiHandlerHeaders.SiteVersion]: (0, import_site_version.serializeSiteVersion)(version) } : {}
46
- }
47
- });
48
- if (response.status === 404)
49
- return null;
50
- if (!response.ok)
51
- throw new Error(response.statusText);
52
- if (response.headers.get("content-type")?.includes("application/json") !== true) {
53
- throw new Error(
54
- `Expected JSON response from "${url}" but got "${response.headers.get("content-type")}"`
55
- );
56
- }
57
- return response.json();
58
- };
39
+ function fetchAPIResource(resourceType, resourceId, fetchResource, locale) {
59
40
  return async (dispatch, getState) => {
60
41
  const state = getState();
61
42
  const version = SiteVersionState.getSiteVersion(state.siteVersion);
@@ -65,22 +46,12 @@ function fetchAPIResource(resourceType, resourceId, fetch, locale) {
65
46
  let resource;
66
47
  switch (resourceType) {
67
48
  case import_types.APIResourceType.Swatch:
68
- resource = await fetchVersioned(`/api/makeswift/swatches/${resourceId}`, version);
69
- break;
70
49
  case import_types.APIResourceType.File:
71
- resource = await fetchVersioned(`/api/makeswift/files/${resourceId}`, version);
72
- break;
73
50
  case import_types.APIResourceType.Typography:
74
- resource = await fetchVersioned(
75
- `/api/makeswift/typographies/${resourceId}`,
76
- version
77
- );
78
- break;
79
51
  case import_types.APIResourceType.GlobalElement:
80
- resource = await fetchVersioned(
81
- `/api/makeswift/global-elements/${resourceId}`,
82
- version
83
- );
52
+ case import_types.APIResourceType.PagePathnameSlice:
53
+ case import_types.APIResourceType.Table:
54
+ resource = await fetchResource(resourceId, version, locale);
84
55
  break;
85
56
  case import_types.APIResourceType.LocalizedGlobalElement: {
86
57
  if (locale == null)
@@ -88,10 +59,7 @@ function fetchAPIResource(resourceType, resourceId, fetch, locale) {
88
59
  if ((0, import_state.getLocalizedResourceId)(state, locale, resourceId) === null) {
89
60
  return null;
90
61
  }
91
- resource = await fetchVersioned(
92
- `/api/makeswift/localized-global-elements/${resourceId}/${locale}`,
93
- version
94
- );
62
+ resource = await fetchResource(resourceId, version, locale);
95
63
  dispatch(
96
64
  (0, import_host_api.setLocalizedResourceId)({
97
65
  locale,
@@ -101,16 +69,6 @@ function fetchAPIResource(resourceType, resourceId, fetch, locale) {
101
69
  );
102
70
  break;
103
71
  }
104
- case import_types.APIResourceType.PagePathnameSlice: {
105
- const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, "http://n");
106
- if (locale != null)
107
- url.searchParams.set("locale", locale);
108
- resource = await fetchVersioned(url.pathname + url.search, version);
109
- break;
110
- }
111
- case import_types.APIResourceType.Table:
112
- resource = await fetchVersioned(`/api/makeswift/tables/${resourceId}`, version);
113
- break;
114
72
  default:
115
73
  resource = null;
116
74
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/state/api-client/fetch-api-resource.ts"],"sourcesContent":["import { type ThunkAction } from '@reduxjs/toolkit'\n\nimport { type SiteVersion, ApiHandlerHeaders, serializeSiteVersion } from '../../api/site-version'\n\nimport * as SiteVersionState from '../modules/site-version'\n\nimport { type Action } from '../actions'\nimport { apiResourceFulfilled } from '../actions/internal/read-only-actions'\nimport { setLocalizedResourceId } from '../host-api'\n\nimport {\n APIResourceType,\n type APIResource,\n type Swatch,\n type File,\n type Typography,\n type GlobalElement,\n type PagePathnameSlice,\n type Table,\n type LocalizedGlobalElement,\n type APIResourceLocale,\n type HttpFetch,\n} from '../../api/types'\n\nimport { type State, getHasAPIResource, getAPIResource, getLocalizedResourceId } from './state'\n\ntype Thunk<ReturnType> = ThunkAction<ReturnType, State, unknown, Action>\n\nexport function fetchAPIResource<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n fetch: HttpFetch,\n locale?: APIResourceLocale<T>,\n): Thunk<Promise<Extract<APIResource, { __typename: T }> | null>> {\n const fetchVersioned = async <T>(url: string, version: SiteVersion | null): Promise<T | null> => {\n const response = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n ...(version != null\n ? { [ApiHandlerHeaders.SiteVersion]: serializeSiteVersion(version) }\n : {}),\n },\n })\n\n if (response.status === 404) return null\n if (!response.ok) throw new Error(response.statusText)\n\n if (response.headers.get('content-type')?.includes('application/json') !== true) {\n throw new Error(\n `Expected JSON response from \"${url}\" but got \"${response.headers.get('content-type')}\"`,\n )\n }\n\n return response.json()\n }\n\n return async (dispatch, getState) => {\n const state = getState()\n const version = SiteVersionState.getSiteVersion(state.siteVersion)\n\n if (getHasAPIResource(state, resourceType, resourceId, locale)) {\n return getAPIResource(state, resourceType, resourceId, locale)\n }\n\n let resource: APIResource | null\n\n switch (resourceType) {\n case APIResourceType.Swatch:\n resource = await fetchVersioned<Swatch>(`/api/makeswift/swatches/${resourceId}`, version)\n break\n\n case APIResourceType.File:\n resource = await fetchVersioned<File>(`/api/makeswift/files/${resourceId}`, version)\n break\n\n case APIResourceType.Typography:\n resource = await fetchVersioned<Typography>(\n `/api/makeswift/typographies/${resourceId}`,\n version,\n )\n break\n\n case APIResourceType.GlobalElement:\n resource = await fetchVersioned<GlobalElement>(\n `/api/makeswift/global-elements/${resourceId}`,\n version,\n )\n break\n\n case APIResourceType.LocalizedGlobalElement: {\n if (locale == null) throw new Error('Locale is required to fetch LocalizedGlobalElement')\n\n // If `getLocalizedResourceId` returns null, it means we have tried to fetch the resource,\n // but the resource is not available. If we haven't fetched it yet, it'll return undefined.\n if (getLocalizedResourceId(state, locale, resourceId) === null) {\n return null\n }\n\n resource = await fetchVersioned<LocalizedGlobalElement>(\n `/api/makeswift/localized-global-elements/${resourceId}/${locale}`,\n version,\n )\n\n dispatch(\n setLocalizedResourceId({\n locale,\n resourceId,\n localizedResourceId: resource?.id ?? null,\n }),\n )\n\n break\n }\n\n case APIResourceType.PagePathnameSlice: {\n const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, 'http://n')\n\n if (locale != null) url.searchParams.set('locale', locale)\n\n resource = await fetchVersioned<PagePathnameSlice>(url.pathname + url.search, version)\n break\n }\n\n case APIResourceType.Table:\n resource = await fetchVersioned<Table>(`/api/makeswift/tables/${resourceId}`, version)\n break\n\n default:\n resource = null\n }\n\n dispatch(apiResourceFulfilled(resourceType, resourceId, resource, locale))\n\n return resource as Extract<APIResource, { __typename: T }> | null\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAA0E;AAE1E,uBAAkC;AAGlC,+BAAqC;AACrC,sBAAuC;AAEvC,mBAYO;AAEP,mBAAsF;AAI/E,SAAS,iBACd,cACA,YACA,OACA,QACgE;AAChE,QAAM,iBAAiB,OAAU,KAAa,YAAmD;AAC/F,UAAM,WAAW,MAAM,MAAM,KAAK;AAAA,MAChC,SAAS;AAAA,QACP,gBAAgB;AAAA,QAChB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C,UAAU,IAAI,MAAM;AAAA,UAChE;AAAA,QACF;AAEA;AAAA,cACE,wCAAuB;AAAA,YACrB;AAAA,YACA;AAAA,YACA,qBAAqB,UAAU,MAAM;AAAA,UACvC,CAAC;AAAA,QACH;AAEA;AAAA,MACF;AAAA,MAEA,KAAK,6BAAgB,mBAAmB;AACtC,cAAM,MAAM,IAAI,IAAI,uCAAuC,UAAU,IAAI,UAAU;AAEnF,YAAI,UAAU;AAAM,cAAI,aAAa,IAAI,UAAU,MAAM;AAEzD,mBAAW,MAAM,eAAkC,IAAI,WAAW,IAAI,QAAQ,OAAO;AACrF;AAAA,MACF;AAAA,MAEA,KAAK,6BAAgB;AACnB,mBAAW,MAAM,eAAsB,yBAAyB,UAAU,IAAI,OAAO;AACrF;AAAA,MAEF;AACE,mBAAW;AAAA,IACf;AAEA,iBAAS,+CAAqB,cAAc,YAAY,UAAU,MAAM,CAAC;AAEzE,WAAO;AAAA,EACT;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/state/api-client/fetch-api-resource.ts"],"sourcesContent":["import { type ThunkAction } from '@reduxjs/toolkit'\n\nimport { type SiteVersion } from '../../api/site-version'\n\nimport * as SiteVersionState from '../modules/site-version'\n\nimport { type Action } from '../actions'\nimport { apiResourceFulfilled } from '../actions/internal/read-only-actions'\nimport { setLocalizedResourceId } from '../host-api'\n\nimport {\n APIResourceType,\n type APIResource,\n type APIResourceByType,\n type APIResourceLocale,\n} from '../../api/types'\n\nimport { type State, getHasAPIResource, getAPIResource, getLocalizedResourceId } from './state'\n\ntype Thunk<ReturnType> = ThunkAction<ReturnType, State, unknown, Action>\n\nexport function fetchAPIResource<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n fetchResource: (\n resourceId: string,\n version: SiteVersion | null,\n locale?: APIResourceLocale<T>,\n ) => Promise<APIResourceByType<T> | null>,\n locale?: APIResourceLocale<T>,\n): Thunk<Promise<APIResourceByType<T> | null>> {\n return async (dispatch, getState) => {\n const state = getState()\n const version = SiteVersionState.getSiteVersion(state.siteVersion)\n\n if (getHasAPIResource(state, resourceType, resourceId, locale)) {\n return getAPIResource(state, resourceType, resourceId, locale)\n }\n\n let resource: APIResource | null\n\n switch (resourceType) {\n case APIResourceType.Swatch:\n case APIResourceType.File:\n case APIResourceType.Typography:\n case APIResourceType.GlobalElement:\n case APIResourceType.PagePathnameSlice:\n case APIResourceType.Table:\n resource = await fetchResource(resourceId, version, locale)\n break\n\n case APIResourceType.LocalizedGlobalElement: {\n if (locale == null) throw new Error('Locale is required to fetch LocalizedGlobalElement')\n\n // If `getLocalizedResourceId` returns null, it means we have tried to fetch the resource,\n // but the resource is not available. If we haven't fetched it yet, it'll return undefined.\n if (getLocalizedResourceId(state, locale, resourceId) === null) {\n return null\n }\n\n resource = await fetchResource(resourceId, version, locale)\n\n dispatch(\n setLocalizedResourceId({\n locale,\n resourceId,\n localizedResourceId: resource?.id ?? null,\n }),\n )\n\n break\n }\n\n default:\n resource = null\n }\n\n dispatch(apiResourceFulfilled(resourceType, resourceId, resource, locale))\n\n return resource as APIResourceByType<T> | null\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,uBAAkC;AAGlC,+BAAqC;AACrC,sBAAuC;AAEvC,mBAKO;AAEP,mBAAsF;AAI/E,SAAS,iBACd,cACA,YACA,eAKA,QAC6C;AAC7C,SAAO,OAAO,UAAU,aAAa;AACnC,UAAM,QAAQ,SAAS;AACvB,UAAM,UAAU,iBAAiB,eAAe,MAAM,WAAW;AAEjE,YAAI,gCAAkB,OAAO,cAAc,YAAY,MAAM,GAAG;AAC9D,iBAAO,6BAAe,OAAO,cAAc,YAAY,MAAM;AAAA,IAC/D;AAEA,QAAI;AAEJ,YAAQ,cAAc;AAAA,MACpB,KAAK,6BAAgB;AAAA,MACrB,KAAK,6BAAgB;AAAA,MACrB,KAAK,6BAAgB;AAAA,MACrB,KAAK,6BAAgB;AAAA,MACrB,KAAK,6BAAgB;AAAA,MACrB,KAAK,6BAAgB;AACnB,mBAAW,MAAM,cAAc,YAAY,SAAS,MAAM;AAC1D;AAAA,MAEF,KAAK,6BAAgB,wBAAwB;AAC3C,YAAI,UAAU;AAAM,gBAAM,IAAI,MAAM,oDAAoD;AAIxF,gBAAI,qCAAuB,OAAO,QAAQ,UAAU,MAAM,MAAM;AAC9D,iBAAO;AAAA,QACT;AAEA,mBAAW,MAAM,cAAc,YAAY,SAAS,MAAM;AAE1D;AAAA,cACE,wCAAuB;AAAA,YACrB;AAAA,YACA;AAAA,YACA,qBAAqB,UAAU,MAAM;AAAA,UACvC,CAAC;AAAA,QACH;AAEA;AAAA,MACF;AAAA,MAEA;AACE,mBAAW;AAAA,IACf;AAEA,iBAAS,+CAAqB,cAAc,YAAY,UAAU,MAAM,CAAC;AAEzE,WAAO;AAAA,EACT;AACF;","names":[]}