@makeswift/runtime 0.28.7 → 0.28.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.
- package/dist/cjs/api/api-resources-client.js +47 -0
- package/dist/cjs/api/api-resources-client.js.map +1 -1
- package/dist/cjs/api/graphql-api-client.js +1 -1
- package/dist/cjs/api/host-api-resources-client.js +38 -32
- package/dist/cjs/api/host-api-resources-client.js.map +1 -1
- package/dist/cjs/api/makeswift-api-resources-client.js +84 -0
- package/dist/cjs/api/makeswift-api-resources-client.js.map +1 -0
- package/dist/cjs/api/rest-api-client.js +1 -1
- package/dist/cjs/api/rest-api-client.js.map +1 -1
- package/dist/cjs/api/types.js.map +1 -1
- package/dist/cjs/api-handler/handlers/manifest.js +1 -1
- package/dist/cjs/client/index.js +1 -1
- package/dist/cjs/runtimes/react/components/ElementData.js +2 -2
- package/dist/cjs/runtimes/react/components/ElementData.js.map +1 -1
- package/dist/cjs/runtimes/react/components/resolve-props.js +43 -0
- package/dist/cjs/runtimes/react/components/resolve-props.js.map +1 -0
- package/dist/cjs/runtimes/react/hooks/use-control-defs.js +40 -0
- package/dist/cjs/runtimes/react/hooks/use-control-defs.js.map +1 -0
- package/dist/cjs/runtimes/react/runtime-core.js +13 -0
- package/dist/cjs/runtimes/react/runtime-core.js.map +1 -1
- package/dist/cjs/state/api-client/fetch-api-resource.js +5 -47
- package/dist/cjs/state/api-client/fetch-api-resource.js.map +1 -1
- package/dist/esm/api/api-resources-client.js +47 -0
- package/dist/esm/api/api-resources-client.js.map +1 -1
- package/dist/esm/api/graphql-api-client.js +1 -1
- package/dist/esm/api/host-api-resources-client.js +38 -33
- package/dist/esm/api/host-api-resources-client.js.map +1 -1
- package/dist/esm/api/makeswift-api-resources-client.js +50 -0
- package/dist/esm/api/makeswift-api-resources-client.js.map +1 -0
- package/dist/esm/api/rest-api-client.js +1 -1
- package/dist/esm/api/rest-api-client.js.map +1 -1
- package/dist/esm/api/types.js.map +1 -1
- package/dist/esm/api-handler/handlers/manifest.js +1 -1
- package/dist/esm/client/index.js +1 -1
- package/dist/esm/runtimes/react/components/ElementData.js +1 -1
- package/dist/esm/runtimes/react/components/ElementData.js.map +1 -1
- package/dist/esm/runtimes/react/components/resolve-props.js +19 -0
- package/dist/esm/runtimes/react/components/resolve-props.js.map +1 -0
- package/dist/esm/runtimes/react/hooks/use-control-defs.js +16 -0
- package/dist/esm/runtimes/react/hooks/use-control-defs.js.map +1 -0
- package/dist/esm/runtimes/react/runtime-core.js +13 -0
- package/dist/esm/runtimes/react/runtime-core.js.map +1 -1
- package/dist/esm/state/api-client/fetch-api-resource.js +5 -47
- package/dist/esm/state/api-client/fetch-api-resource.js.map +1 -1
- package/dist/types/api/api-resources-client.d.ts +18 -10
- package/dist/types/api/api-resources-client.d.ts.map +1 -1
- package/dist/types/api/host-api-resources-client.d.ts +9 -14
- package/dist/types/api/host-api-resources-client.d.ts.map +1 -1
- package/dist/types/api/makeswift-api-resources-client.d.ts +30 -0
- package/dist/types/api/makeswift-api-resources-client.d.ts.map +1 -0
- package/dist/types/api/rest-api-client.d.ts +1 -1
- package/dist/types/api/rest-api-client.d.ts.map +1 -1
- package/dist/types/api/types.d.ts +3 -0
- package/dist/types/api/types.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/resolve-props.d.ts +7 -0
- package/dist/types/runtimes/react/components/resolve-props.d.ts.map +1 -0
- package/dist/types/runtimes/react/hooks/use-control-defs.d.ts +6 -0
- package/dist/types/runtimes/react/hooks/use-control-defs.d.ts.map +1 -0
- package/dist/types/runtimes/react/runtime-core.d.ts +4 -2
- package/dist/types/runtimes/react/runtime-core.d.ts.map +1 -1
- package/dist/types/state/api-client/fetch-api-resource.d.ts +3 -4
- package/dist/types/state/api-client/fetch-api-resource.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/runtimes/react/controls.js +0 -59
- package/dist/cjs/runtimes/react/controls.js.map +0 -1
- package/dist/esm/runtimes/react/controls.js +0 -25
- package/dist/esm/runtimes/react/controls.js.map +0 -1
- package/dist/types/runtimes/react/controls.d.ts +0 -9
- package/dist/types/runtimes/react/controls.d.ts.map +0 -1
|
@@ -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,mBAY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AAK,MAAM,SAAS,GAAG,6BAAgB,OAAO,OAAO;AAAA,EAC5F;AAAA,EAEA,SAAS,QAA6B;AACpC,WAAO,eAAe,eAAe,KAAK,MAAM,SAAS,GAAG,6BAAgB,MAAM,MAAM;AAAA,EAC1F;AAAA,EAEA,SAAS,QAA6B;AACpC,WAAO,eAAe,eAAe,KAAK,MAAM,SAAS,GAAG,6BAAgB,MAAM,MAAM;AAAA,EAC1F;AAAA,EAEA,YAAY,WAAmC;AAC7C,WAAO,eAAe,eAAe,KAAK,MAAM,SAAS,GAAG,6BAAgB,SAAS,SAAS;AAAA,EAChG;AACF;","names":[]}
|
|
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'\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,QA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iB,6BAAgB,OAAO,SAAS,KAAK,CAAC;AAAA,EAC1F;AAAA,EAEA,UAAU,SAA+B;AACvC,WAAO,eAAe,eAAe,KAAK,MAAM,SAAS,GAAG,6BAAgB,OAAO,OAAO;AAAA,EAC5F;AAAA,EAEA,SAAS,QAA6B;AACpC,WAAO,eAAe,eAAe,KAAK,MAAM,SAAS,GAAG,6BAAgB,MAAM,MAAM;AAAA,EAC1F;AAAA,EAEA,SAAS,QAA6B;AACpC,WAAO,eAAe,eAAe,KAAK,MAAM,SAAS,GAAG,6BAAgB,MAAM,MAAM;AAAA,EAC1F;AAAA,EAEA,YAAY,WAAmC;AAC7C,WAAO,eAAe,eAAe,KAAK,MAAM,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.
|
|
30
|
+
"makeswift-runtime-version": "0.28.8-canary.1"
|
|
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
|
|
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
|
|
42
|
-
return await this.
|
|
38
|
+
async fetchSwatchImpl(id, version) {
|
|
39
|
+
return await this.fetchVersioned(`/api/makeswift/swatches/${id}`, version);
|
|
43
40
|
}
|
|
44
|
-
async
|
|
45
|
-
return await this.
|
|
41
|
+
async fetchFileImpl(id, version) {
|
|
42
|
+
return await this.fetchVersioned(`/api/makeswift/files/${id}`, version);
|
|
46
43
|
}
|
|
47
|
-
async
|
|
48
|
-
return await this.
|
|
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
|
|
53
|
-
return await this.
|
|
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
|
|
58
|
-
|
|
59
|
-
|
|
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
|
|
66
|
-
|
|
67
|
-
locale
|
|
68
|
-
|
|
69
|
-
return await this.
|
|
70
|
-
|
|
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
|
|
74
|
-
|
|
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'\
|
|
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,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,GAAI,WAAW,OACX,EAAE,CAAC,sCAAkB,WAAW,OAAG,0CAAqB,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,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var makeswift_api_resources_client_exports = {};
|
|
30
|
+
__export(makeswift_api_resources_client_exports, {
|
|
31
|
+
MakeswiftApiResourcesClient: () => MakeswiftApiResourcesClient
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(makeswift_api_resources_client_exports);
|
|
34
|
+
var import_client_store = require("../state/api-client/client-store");
|
|
35
|
+
var import_api_resources_client = require("./api-resources-client");
|
|
36
|
+
class MakeswiftApiResourcesClient extends import_api_resources_client.ApiResourcesClient {
|
|
37
|
+
restApiClient;
|
|
38
|
+
graphQlClient;
|
|
39
|
+
constructor({
|
|
40
|
+
fetch,
|
|
41
|
+
apiKey,
|
|
42
|
+
apiOrigin,
|
|
43
|
+
graphqlApiEndpoint,
|
|
44
|
+
preloadedState
|
|
45
|
+
}) {
|
|
46
|
+
super({
|
|
47
|
+
store: (0, import_client_store.configureClientStore)({ preloadedState })
|
|
48
|
+
});
|
|
49
|
+
this.restApiClient = (async () => {
|
|
50
|
+
const { MakeswiftRestAPIClient } = await Promise.resolve().then(() => __toESM(require("./rest-api-client")));
|
|
51
|
+
return new MakeswiftRestAPIClient({ fetch, apiKey, apiOrigin });
|
|
52
|
+
})();
|
|
53
|
+
this.graphQlClient = (async () => {
|
|
54
|
+
const { MakeswiftGraphQLApiClient } = await Promise.resolve().then(() => __toESM(require("./graphql-api-client")));
|
|
55
|
+
return new MakeswiftGraphQLApiClient({ endpoint: graphqlApiEndpoint });
|
|
56
|
+
})();
|
|
57
|
+
}
|
|
58
|
+
async fetchSwatchImpl(id, version) {
|
|
59
|
+
return (await this.restApiClient).getSwatch(id, version);
|
|
60
|
+
}
|
|
61
|
+
async fetchFileImpl(id, _version) {
|
|
62
|
+
return (await this.graphQlClient).getFile(id);
|
|
63
|
+
}
|
|
64
|
+
async fetchTypographyImpl(id, version) {
|
|
65
|
+
return (await this.restApiClient).getTypography(id, version);
|
|
66
|
+
}
|
|
67
|
+
async fetchGlobalElementImpl(id, version) {
|
|
68
|
+
return (await this.restApiClient).getGlobalElement(id, version);
|
|
69
|
+
}
|
|
70
|
+
async fetchLocalizedGlobalElementImpl(id, version, locale) {
|
|
71
|
+
return (await this.restApiClient).getLocalizedGlobalElement(id, locale, version);
|
|
72
|
+
}
|
|
73
|
+
async fetchPagePathnameSliceImpl(id, version, locale) {
|
|
74
|
+
return (await this.restApiClient).getPagePathnameSlice(id, version, { locale });
|
|
75
|
+
}
|
|
76
|
+
async fetchTableImpl(id, _version) {
|
|
77
|
+
return (await this.graphQlClient).getTable(id);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
MakeswiftApiResourcesClient
|
|
83
|
+
});
|
|
84
|
+
//# 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 { type SiteVersion } from './site-version'\n\n// see the comment in `MakeswiftApiResourcesClient` constructor below\nimport { type MakeswiftGraphQLApiClient } from './graphql-api-client'\nimport { type MakeswiftRestAPIClient } from './rest-api-client'\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: Promise<MakeswiftRestAPIClient>\n private graphQlClient: Promise<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 // `MakeswiftApiResourcesClient` is used by the runtime and therefore will be imported\n // on the client; lazy import server-side REST/GraphQL clients to avoid unnecessarily\n // pulling their code into a client bundle.\n //\n // (we can't easily lazy-load `MakeswiftApiResourcesClient` itself, at it will make its\n // construction async, but because it shares most of its implementation with\n // `HostApiResourcesClient`, the overhead of this module on its own is negligible)\n this.restApiClient = (async () => {\n const { MakeswiftRestAPIClient } = await import('./rest-api-client')\n return new MakeswiftRestAPIClient({ fetch, apiKey, apiOrigin })\n })()\n\n this.graphQlClient = (async () => {\n const { MakeswiftGraphQLApiClient } = await import('./graphql-api-client')\n return new MakeswiftGraphQLApiClient({ endpoint: graphqlApiEndpoint })\n })()\n }\n\n protected async fetchSwatchImpl(id: string, version: SiteVersion | null): Promise<Swatch | null> {\n return (await 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 (await this.graphQlClient).getFile(id)\n }\n\n protected async fetchTypographyImpl(\n id: string,\n version: SiteVersion | null,\n ): Promise<Typography | null> {\n return (await this.restApiClient).getTypography(id, version)\n }\n\n protected async fetchGlobalElementImpl(\n id: string,\n version: SiteVersion | null,\n ): Promise<GlobalElement | null> {\n return (await 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 (await 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 (await 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 (await this.graphQlClient).getTable(id)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0BAAqC;AAarC,kCAAmC;AAc5B,MAAM,oCAAoC,+CAAmB;AAAA,EAC1D;AAAA,EACA;AAAA,EAER,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAMG;AACD,UAAM;AAAA,MACJ,WAAO,0CAAqB,EAAE,eAAe,CAAC;AAAA,IAChD,CAAC;AASD,SAAK,iBAAiB,YAAY;AAChC,YAAM,EAAE,uBAAuB,IAAI,MAAM,6CAAO,mBAAmB;AACnE,aAAO,IAAI,uBAAuB,EAAE,OAAO,QAAQ,UAAU,CAAC;AAAA,IAChE,GAAG;AAEH,SAAK,iBAAiB,YAAY;AAChC,YAAM,EAAE,0BAA0B,IAAI,MAAM,6CAAO,sBAAsB;AACzE,aAAO,IAAI,0BAA0B,EAAE,UAAU,mBAAmB,CAAC;AAAA,IACvE,GAAG;AAAA,EACL;AAAA,EAEA,MAAgB,gBAAgB,IAAY,SAAqD;AAC/F,YAAQ,MAAM,KAAK,eAAe,UAAU,IAAI,OAAO;AAAA,EACzD;AAAA,EAEA,MAAgB,cAAc,IAAY,UAAoD;AAE5F,YAAQ,MAAM,KAAK,eAAe,QAAQ,EAAE;AAAA,EAC9C;AAAA,EAEA,MAAgB,oBACd,IACA,SAC4B;AAC5B,YAAQ,MAAM,KAAK,eAAe,cAAc,IAAI,OAAO;AAAA,EAC7D;AAAA,EAEA,MAAgB,uBACd,IACA,SAC+B;AAC/B,YAAQ,MAAM,KAAK,eAAe,iBAAiB,IAAI,OAAO;AAAA,EAChE;AAAA,EAEA,MAAgB,gCACd,IACA,SACA,QACwC;AACxC,YAAQ,MAAM,KAAK,eAAe,0BAA0B,IAAI,QAAQ,OAAO;AAAA,EACjF;AAAA,EAEA,MAAgB,2BACd,IACA,SACA,QACmC;AACnC,YAAQ,MAAM,KAAK,eAAe,qBAAqB,IAAI,SAAS,EAAE,OAAO,CAAC;AAAA,EAChF;AAAA,EAEA,MAAgB,eAAe,IAAY,UAAqD;AAE9F,YAAQ,MAAM,KAAK,eAAe,SAAS,EAAE;AAAA,EAC/C;AACF;","names":[]}
|
|
@@ -147,7 +147,7 @@ class MakeswiftRestAPIClient {
|
|
|
147
147
|
const requestHeaders = new Headers({
|
|
148
148
|
"x-api-key": this.apiKey,
|
|
149
149
|
"makeswift-site-api-key": this.apiKey,
|
|
150
|
-
"makeswift-runtime-version": "0.28.
|
|
150
|
+
"makeswift-runtime-version": "0.28.8-canary.1"
|
|
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,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,IACT;AAEA,UAAM,SAAS,MAAM,SAAS,KAAK;AAEnC,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,cACJ,cACA,aAC4B;AAC5B,UAAM,WAAW,MAAM,KAAK,MAAM,mBAAmB,YAAY,IAAI,WAAW;AAEhF,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,aAAa,MAAM,mBAAmB,QAAQ;AACpD,UAAI,SAAS,WAAW,KAAK;AAC3B,gBAAQ,MAAM,6BAA6B,YAAY,KAAK;AAAA,UAC1D,UAAU;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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":";;;;;;;;;;;;;;;;;;;;;;;;;;;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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.
|
|
31
|
+
version: "0.28.8-canary.1",
|
|
32
32
|
interactionMode: true,
|
|
33
33
|
clientSideNavigation: false,
|
|
34
34
|
elementFromPoint: false,
|
package/dist/cjs/client/index.js
CHANGED
|
@@ -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.
|
|
692
|
+
"makeswift-runtime-version": "0.28.8-canary.1",
|
|
693
693
|
"content-type": "application/json"
|
|
694
694
|
},
|
|
695
695
|
body: JSON.stringify({ token }),
|
|
@@ -28,7 +28,7 @@ var import_use_builtin_suspense = require("../hooks/use-builtin-suspense");
|
|
|
28
28
|
var import_use_component = require("../hooks/use-component");
|
|
29
29
|
var import_can_accept_ref = require("../utils/can-accept-ref");
|
|
30
30
|
var import_FallbackComponent = require("../../../components/shared/FallbackComponent");
|
|
31
|
-
var
|
|
31
|
+
var import_resolve_props = require("./resolve-props");
|
|
32
32
|
var import_activity_with_fallback = require("./activity-with-fallback");
|
|
33
33
|
const ElementData = (0, import_react2.memo)(
|
|
34
34
|
(0, import_react2.forwardRef)(function ElementData2({ elementData }, ref) {
|
|
@@ -39,7 +39,7 @@ const ElementData = (0, import_react2.memo)(
|
|
|
39
39
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_FallbackComponent.FallbackComponent, { ref, text: "Component not found" });
|
|
40
40
|
}
|
|
41
41
|
const forwardRef2 = (0, import_can_accept_ref.canAcceptRef)(Component);
|
|
42
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_activity_with_fallback.ActivityOrFallback, { suspenseFallback: builtinSuspense, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
42
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_activity_with_fallback.ActivityOrFallback, { suspenseFallback: builtinSuspense, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_resolve_props.ResolveProps, { element: elementData, children: (props) => forwardRef2 ? /* @__PURE__ */ (0, import_react.createElement)(Component, { ...props, key: elementData.key, ref }) : /* @__PURE__ */ (0, import_react.createElement)(Component, { ...props, key: elementData.key }) }) });
|
|
43
43
|
})
|
|
44
44
|
);
|
|
45
45
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/components/ElementData.tsx"],"sourcesContent":["import { Ref, forwardRef, memo, ReactNode } from 'react'\n\nimport { ElementData as ReactPageElementData } from '../../../state/read-only-state'\nimport { useBuiltinSuspense } from '../hooks/use-builtin-suspense'\nimport { useComponent } from '../hooks/use-component'\nimport { canAcceptRef } from '../utils/can-accept-ref'\nimport { FallbackComponent } from '../../../components/shared/FallbackComponent'\nimport { ResolveProps } from '
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/components/ElementData.tsx"],"sourcesContent":["import { Ref, forwardRef, memo, ReactNode } from 'react'\n\nimport { ElementData as ReactPageElementData } from '../../../state/read-only-state'\nimport { useBuiltinSuspense } from '../hooks/use-builtin-suspense'\nimport { useComponent } from '../hooks/use-component'\nimport { canAcceptRef } from '../utils/can-accept-ref'\nimport { FallbackComponent } from '../../../components/shared/FallbackComponent'\nimport { ResolveProps } from './resolve-props'\nimport { ActivityOrFallback } from './activity-with-fallback'\n\ntype ElementDataProps = {\n elementData: ReactPageElementData\n}\n\nexport const ElementData = memo(\n forwardRef(function ElementData({ elementData }: ElementDataProps, ref: Ref<unknown>): ReactNode {\n const Component = useComponent(elementData.type)\n const builtinSuspense = useBuiltinSuspense(elementData.type)\n\n if (Component == null) {\n console.warn(`Unknown component '${elementData.type}'`, { elementData })\n return <FallbackComponent ref={ref as Ref<HTMLDivElement>} text=\"Component not found\" />\n }\n\n const forwardRef = canAcceptRef(Component)\n\n return (\n <ActivityOrFallback suspenseFallback={builtinSuspense}>\n <ResolveProps element={elementData}>\n {props =>\n forwardRef ? (\n <Component {...props} key={elementData.key} ref={ref} />\n ) : (\n <Component {...props} key={elementData.key} />\n )\n }\n </ResolveProps>\n </ActivityOrFallback>\n )\n }),\n)\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBa;AAUC;AA/Bd,IAAAA,gBAAiD;AAGjD,kCAAmC;AACnC,2BAA6B;AAC7B,4BAA6B;AAC7B,+BAAkC;AAClC,2BAA6B;AAC7B,oCAAmC;AAM5B,MAAM,kBAAc;AAAA,MACzB,0BAAW,SAASC,aAAY,EAAE,YAAY,GAAqB,KAA8B;AAC/F,UAAM,gBAAY,mCAAa,YAAY,IAAI;AAC/C,UAAM,sBAAkB,gDAAmB,YAAY,IAAI;AAE3D,QAAI,aAAa,MAAM;AACrB,cAAQ,KAAK,sBAAsB,YAAY,IAAI,KAAK,EAAE,YAAY,CAAC;AACvE,aAAO,4CAAC,8CAAkB,KAAiC,MAAK,uBAAsB;AAAA,IACxF;AAEA,UAAMC,kBAAa,oCAAa,SAAS;AAEzC,WACE,4CAAC,oDAAmB,kBAAkB,iBACpC,sDAAC,qCAAa,SAAS,aACpB,qBACCA,cACE,gDAAC,aAAW,GAAG,OAAO,KAAK,YAAY,KAAK,KAAU,IAEtD,gDAAC,aAAW,GAAG,OAAO,KAAK,YAAY,KAAK,GAGlD,GACF;AAAA,EAEJ,CAAC;AACH;","names":["import_react","ElementData","forwardRef"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
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 resolve_props_exports = {};
|
|
20
|
+
__export(resolve_props_exports, {
|
|
21
|
+
ResolveProps: () => ResolveProps
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(resolve_props_exports);
|
|
24
|
+
var import_use_control_defs = require("../hooks/use-control-defs");
|
|
25
|
+
var import_use_resolved_props = require("../hooks/use-resolved-props");
|
|
26
|
+
var import_legacy_controls = require("../legacy-controls");
|
|
27
|
+
function ResolveProps({
|
|
28
|
+
element,
|
|
29
|
+
children: renderComponent
|
|
30
|
+
}) {
|
|
31
|
+
const [legacyDescriptors, definitions] = (0, import_use_control_defs.useControlDefs)({ elementType: element.type });
|
|
32
|
+
const resolvedProps = (0, import_use_resolved_props.useResolvedProps)(definitions, element.props, element.key);
|
|
33
|
+
const renderFn = Object.entries(legacyDescriptors).reduceRight(
|
|
34
|
+
(renderFn2, [propName, descriptor]) => (props) => (0, import_legacy_controls.resolveLegacyDescriptorProp)(descriptor, propName, element.props[propName], props, renderFn2),
|
|
35
|
+
renderComponent
|
|
36
|
+
);
|
|
37
|
+
return renderFn(resolvedProps);
|
|
38
|
+
}
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
ResolveProps
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=resolve-props.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/components/resolve-props.tsx"],"sourcesContent":["import { type ReactNode } from 'react'\n\nimport { type ElementData } from '../../../state/read-only-state'\n\nimport { useControlDefs } from '../hooks/use-control-defs'\nimport { useResolvedProps } from '../hooks/use-resolved-props'\n\nimport { resolveLegacyDescriptorProp } from '../legacy-controls'\n\nexport function ResolveProps({\n element,\n children: renderComponent,\n}: {\n element: ElementData\n children: (props: Record<string, unknown>) => ReactNode\n}): ReactNode {\n const [legacyDescriptors, definitions] = useControlDefs({ elementType: element.type })\n\n const resolvedProps = useResolvedProps(definitions, element.props, element.key)\n\n const renderFn = Object.entries(legacyDescriptors).reduceRight(\n (renderFn, [propName, descriptor]) =>\n props =>\n resolveLegacyDescriptorProp(descriptor, propName, element.props[propName], props, renderFn),\n renderComponent,\n )\n\n return renderFn(resolvedProps)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,8BAA+B;AAC/B,gCAAiC;AAEjC,6BAA4C;AAErC,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA,UAAU;AACZ,GAGc;AACZ,QAAM,CAAC,mBAAmB,WAAW,QAAI,wCAAe,EAAE,aAAa,QAAQ,KAAK,CAAC;AAErF,QAAM,oBAAgB,4CAAiB,aAAa,QAAQ,OAAO,QAAQ,GAAG;AAE9E,QAAM,WAAW,OAAO,QAAQ,iBAAiB,EAAE;AAAA,IACjD,CAACA,WAAU,CAAC,UAAU,UAAU,MAC9B,eACE,oDAA4B,YAAY,UAAU,QAAQ,MAAM,QAAQ,GAAG,OAAOA,SAAQ;AAAA,IAC9F;AAAA,EACF;AAEA,SAAO,SAAS,aAAa;AAC/B;","names":["renderFn"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 use_control_defs_exports = {};
|
|
20
|
+
__export(use_control_defs_exports, {
|
|
21
|
+
useControlDefs: () => useControlDefs
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(use_control_defs_exports);
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
var import_partition = require("../../../utils/partition");
|
|
26
|
+
var import_read_only_state = require("../../../state/read-only-state");
|
|
27
|
+
var import_descriptors = require("../../../prop-controllers/descriptors");
|
|
28
|
+
var import_use_store = require("./use-store");
|
|
29
|
+
function useControlDefs({
|
|
30
|
+
elementType
|
|
31
|
+
}) {
|
|
32
|
+
const store = (0, import_use_store.useStore)();
|
|
33
|
+
const all = (0, import_read_only_state.getComponentPropControllerDescriptors)(store.getState(), elementType) ?? {};
|
|
34
|
+
return (0, import_react.useRef)((0, import_partition.partitionRecord)(all, import_descriptors.isLegacyDescriptor)).current;
|
|
35
|
+
}
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
useControlDefs
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=use-control-defs.js.map
|