@knapsack/app-client-api 4.70.0--canary.4821.e250df4.0 → 4.70.0--canary.4821.82d27e9.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +15 -195
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -166
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
@@ -1,199 +1,19 @@
|
|
1
|
-
|
2
|
-
var __defProp = Object.defineProperty;
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
7
|
-
var __export = (target, all) => {
|
8
|
-
for (var name in all)
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
10
|
-
};
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
13
|
-
for (let key of __getOwnPropNames(from))
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
16
|
-
}
|
17
|
-
return to;
|
18
|
-
};
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
1
|
+
'use strict';
|
20
2
|
|
21
|
-
|
22
|
-
var
|
23
|
-
__export(src_exports, {
|
24
|
-
ENDPOINTS: () => ENDPOINTS,
|
25
|
-
checkAppClientUrl: () => checkAppClientUrl,
|
26
|
-
getAppClientData: () => getAppClientData,
|
27
|
-
getDataStore: () => getDataStore,
|
28
|
-
getPluginContent: () => getPluginContent,
|
29
|
-
getTemplateSuggestions: () => get_template_suggestions_exports,
|
30
|
-
prepAppClientData: () => prepAppClientData,
|
31
|
-
prepareDataForFileSave: () => prepareDataForFileSave,
|
32
|
-
renderTemplate: () => renderTemplate,
|
33
|
-
submitDataForFileSave: () => submitDataForFileSave
|
34
|
-
});
|
35
|
-
module.exports = __toCommonJS(src_exports);
|
3
|
+
var utils = require('@knapsack/utils');
|
4
|
+
var types = require('@knapsack/types');
|
36
5
|
|
37
|
-
|
38
|
-
var get_template_suggestions_exports = {};
|
39
|
-
__export(get_template_suggestions_exports, {
|
40
|
-
getTemplateSuggestions: () => getTemplateSuggestions,
|
41
|
-
method: () => method,
|
42
|
-
path: () => path
|
43
|
-
});
|
44
|
-
var import_utils = require("@knapsack/utils");
|
45
|
-
var path = "/api/v1/template-suggestions";
|
46
|
-
var method = "GET";
|
47
|
-
async function getTemplateSuggestions({
|
48
|
-
appClientUrl,
|
49
|
-
query
|
50
|
-
}) {
|
51
|
-
return (0, import_utils.fetcher)({
|
52
|
-
url: new URL(path, appClientUrl).toString(),
|
53
|
-
query
|
54
|
-
});
|
55
|
-
}
|
56
|
-
__name(getTemplateSuggestions, "getTemplateSuggestions");
|
6
|
+
var g=Object.defineProperty;var r=(e,t)=>g(e,"name",{value:t,configurable:!0});var c=(e,t)=>{for(var a in t)g(e,a,{get:t[a],enumerable:!0});};var i={};c(i,{getTemplateSuggestions:()=>S,method:()=>m,path:()=>o});var o="/api/v1/template-suggestions",m="GET";async function S({appClientUrl:e,query:t}){return utils.fetcher({url:new URL(o,e).toString(),query:t})}r(S,"getTemplateSuggestions");var s={health:"/api/v1/",dataStore:"/api/v1/data-store",dataStorePrep:"/api/v1/data-store-prep",files:"/api/v1/files",data:"/api/v1/data",render:"/api/v1/render",upload:"/api/v1/upload",plugins:"/api/v1/plugins",getTemplateSuggestions:o};async function h(e){try{let t=new URL(s.health,e);return await utils.fetcher({url:t.toString()})}catch(t){return {ok:!1,message:t instanceof Error?t.message:"Unknown error"}}}r(h,"checkAppClientUrl");async function f({appClientUrl:e}){try{return {ok:!0,data:await utils.fetcher({url:new URL(s.dataStore,e).toString()})}}catch(t){return {ok:!1,message:t instanceof Error?t.message:"Unknown error"}}}r(f,"getDataStore");async function K({appClientUrl:e}){let t=await f({appClientUrl:e});if(!t.ok||!t.data){let a=`Could not load data from custom url "${e}" ${t.message}`;throw new Error(a)}return t.data}r(K,"getAppClientData");function d(e){let{metaState:t,...a}=e;return a}r(d,"prepAppClientData");async function k({urlBase:e,state:t}){try{let a={state:d(t)};return await utils.fetcher({url:new URL(s.dataStorePrep,e).toString(),body:a})}catch(a){return {ok:!1,message:a instanceof Error?a.message:"Unknown error"}}}r(k,"prepareDataForFileSave");async function I({urlBase:e,state:t}){let p={state:d(t)},l=await utils.fetcher({url:new URL(s.dataStore,e).toString(),body:p});if(!l.ok)throw new Error(`Could not save data to localhost files: ${l.message}`)}r(I,"submitDataForFileSave");async function U({pluginId:e,appClientUrl:t}){let a={pluginId:e,type:types.PluginsApi.ACTIONS.getContent};return await utils.fetcher({url:new URL(s.plugins,t).toString(),body:a})}r(U,"getPluginContent");async function G({options:e,appClientUrl:t}){return await utils.fetcher({url:new URL(s.render,t).toString(),body:e})}r(G,"renderTemplate");
|
57
7
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
plugins: "/api/v1/plugins",
|
70
|
-
getTemplateSuggestions: path
|
71
|
-
};
|
72
|
-
async function checkAppClientUrl(url) {
|
73
|
-
try {
|
74
|
-
const theUrl = new URL(ENDPOINTS.health, url);
|
75
|
-
const res = await (0, import_utils2.fetcher)({
|
76
|
-
url: theUrl.toString()
|
77
|
-
});
|
78
|
-
return res;
|
79
|
-
} catch (err) {
|
80
|
-
return {
|
81
|
-
ok: false,
|
82
|
-
message: err instanceof Error ? err.message : "Unknown error"
|
83
|
-
};
|
84
|
-
}
|
85
|
-
}
|
86
|
-
__name(checkAppClientUrl, "checkAppClientUrl");
|
87
|
-
async function getDataStore({
|
88
|
-
appClientUrl
|
89
|
-
}) {
|
90
|
-
try {
|
91
|
-
const data = await (0, import_utils2.fetcher)({
|
92
|
-
url: new URL(ENDPOINTS.dataStore, appClientUrl).toString()
|
93
|
-
});
|
94
|
-
return {
|
95
|
-
ok: true,
|
96
|
-
data
|
97
|
-
};
|
98
|
-
} catch (err) {
|
99
|
-
return {
|
100
|
-
ok: false,
|
101
|
-
message: err instanceof Error ? err.message : "Unknown error"
|
102
|
-
};
|
103
|
-
}
|
104
|
-
}
|
105
|
-
__name(getDataStore, "getDataStore");
|
106
|
-
async function getAppClientData({
|
107
|
-
appClientUrl
|
108
|
-
}) {
|
109
|
-
const serverDataRes = await getDataStore({ appClientUrl });
|
110
|
-
if (!serverDataRes.ok || !serverDataRes.data) {
|
111
|
-
const message = `Could not load data from custom url "${appClientUrl}" ${serverDataRes.message}`;
|
112
|
-
throw new Error(message);
|
113
|
-
}
|
114
|
-
return serverDataRes.data;
|
115
|
-
}
|
116
|
-
__name(getAppClientData, "getAppClientData");
|
117
|
-
function prepAppClientData(state) {
|
118
|
-
const { metaState, ...appClientDataNoMeta } = state;
|
119
|
-
return appClientDataNoMeta;
|
120
|
-
}
|
121
|
-
__name(prepAppClientData, "prepAppClientData");
|
122
|
-
async function prepareDataForFileSave({
|
123
|
-
urlBase,
|
124
|
-
state
|
125
|
-
}) {
|
126
|
-
try {
|
127
|
-
const body = {
|
128
|
-
state: prepAppClientData(state)
|
129
|
-
};
|
130
|
-
const data = await (0, import_utils2.fetcher)({
|
131
|
-
url: new URL(ENDPOINTS.dataStorePrep, urlBase).toString(),
|
132
|
-
body
|
133
|
-
});
|
134
|
-
return data;
|
135
|
-
} catch (err) {
|
136
|
-
return {
|
137
|
-
ok: false,
|
138
|
-
message: err instanceof Error ? err.message : "Unknown error"
|
139
|
-
};
|
140
|
-
}
|
141
|
-
}
|
142
|
-
__name(prepareDataForFileSave, "prepareDataForFileSave");
|
143
|
-
async function submitDataForFileSave({
|
144
|
-
urlBase,
|
145
|
-
state
|
146
|
-
}) {
|
147
|
-
const appClientData = prepAppClientData(state);
|
148
|
-
const body = {
|
149
|
-
state: appClientData
|
150
|
-
};
|
151
|
-
const data = await (0, import_utils2.fetcher)({
|
152
|
-
url: new URL(ENDPOINTS.dataStore, urlBase).toString(),
|
153
|
-
body
|
154
|
-
});
|
155
|
-
if (!data.ok) {
|
156
|
-
throw new Error(`Could not save data to localhost files: ${data.message}`);
|
157
|
-
}
|
158
|
-
}
|
159
|
-
__name(submitDataForFileSave, "submitDataForFileSave");
|
160
|
-
async function getPluginContent({
|
161
|
-
pluginId,
|
162
|
-
appClientUrl
|
163
|
-
}) {
|
164
|
-
const body = {
|
165
|
-
pluginId,
|
166
|
-
type: import_types.PluginsApi.ACTIONS.getContent
|
167
|
-
};
|
168
|
-
const data = await (0, import_utils2.fetcher)({
|
169
|
-
url: new URL(ENDPOINTS.plugins, appClientUrl).toString(),
|
170
|
-
body
|
171
|
-
});
|
172
|
-
return data;
|
173
|
-
}
|
174
|
-
__name(getPluginContent, "getPluginContent");
|
175
|
-
async function renderTemplate({
|
176
|
-
options,
|
177
|
-
appClientUrl
|
178
|
-
}) {
|
179
|
-
const data = await (0, import_utils2.fetcher)({
|
180
|
-
url: new URL(ENDPOINTS.render, appClientUrl).toString(),
|
181
|
-
body: options
|
182
|
-
});
|
183
|
-
return data;
|
184
|
-
}
|
185
|
-
__name(renderTemplate, "renderTemplate");
|
186
|
-
// Annotate the CommonJS export names for ESM import in node:
|
187
|
-
0 && (module.exports = {
|
188
|
-
ENDPOINTS,
|
189
|
-
checkAppClientUrl,
|
190
|
-
getAppClientData,
|
191
|
-
getDataStore,
|
192
|
-
getPluginContent,
|
193
|
-
getTemplateSuggestions,
|
194
|
-
prepAppClientData,
|
195
|
-
prepareDataForFileSave,
|
196
|
-
renderTemplate,
|
197
|
-
submitDataForFileSave
|
198
|
-
});
|
8
|
+
exports.ENDPOINTS = s;
|
9
|
+
exports.checkAppClientUrl = h;
|
10
|
+
exports.getAppClientData = K;
|
11
|
+
exports.getDataStore = f;
|
12
|
+
exports.getPluginContent = U;
|
13
|
+
exports.getTemplateSuggestions = i;
|
14
|
+
exports.prepAppClientData = d;
|
15
|
+
exports.prepareDataForFileSave = k;
|
16
|
+
exports.renderTemplate = G;
|
17
|
+
exports.submitDataForFileSave = I;
|
18
|
+
//# sourceMappingURL=index.js.map
|
199
19
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/
|
1
|
+
{"version":3,"sources":["../src/get-template-suggestions.ts","../src/app-client-api.ts"],"names":["get_template_suggestions_exports","__export","getTemplateSuggestions","method","path","appClientUrl","query","fetcher","__name","ENDPOINTS","checkAppClientUrl","url","theUrl","err","getDataStore","getAppClientData","serverDataRes","message","prepAppClientData","state","metaState","appClientDataNoMeta","prepareDataForFileSave","urlBase","body","submitDataForFileSave","data","getPluginContent","pluginId","PluginsApi","renderTemplate","options"],"mappings":";;;;;8IAAAA,IAAAA,CAAAA,CAAA,GAAAC,CAAAD,CAAAA,CAAAA,CAAA,4BAAAE,CAAA,CAAA,MAAA,CAAA,IAAAC,EAAA,IAAAC,CAAAA,IAAAA,CAAAA,CAAAA,CAAAA,CAGO,IAAMA,CAAAA,CAAO,+BACPD,CAAS,CAAA,KAAA,CA4BtB,eAAsBD,CAAAA,CAAuB,CAC3C,YAAA,CAAAG,EACA,KAAAC,CAAAA,CACF,EAGqB,CACnB,OAAOC,cAAiB,CACtB,GAAA,CAAK,IAAI,GAAA,CAAIH,CAAMC,CAAAA,CAAY,EAAE,QAAS,EAAA,CAC1C,MAAAC,CACF,CAAC,CACH,CAXsBE,CAAAA,CAAAN,CAAA,CAAA,wBAAA,CAAA,KCOTO,CAAY,CAAA,CACvB,OAAQ,UACR,CAAA,SAAA,CAAW,qBACX,aAAe,CAAA,yBAAA,CACf,MAAO,eACP,CAAA,IAAA,CAAM,eACN,MAAQ,CAAA,gBAAA,CACR,MAAQ,CAAA,gBAAA,CACR,OAAS,CAAA,iBAAA,CACT,uBAA+CL,CACjD,EAEA,eAAsBM,CAAkBC,CAA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AMmB,CAAqC,CAAA,CACzC,SAAAI,CACA,CAAA,IAAA,CAAMC,gBAAW,CAAA,OAAA,CAAQ,UAC3B,CAAA,CAKA,OAJa,MAAMtB,aAAAA,CAAuC,CACxD,GAAK,CAAA,IAAI,IAAIE,CAAU,CAAA,OAAA,CAASJ,CAAY,CAAE,CAAA,QAAA,GAC9C,IAAAmB,CAAAA,CACF,CAAC,CAEH,CAhBsBhB,EAAAmB,CAAA,CAAA,kBAAA,CAAA,CAkBtB,eAAsBG,CAAAA,CAAe,CACnC,OAAA,CAAAC,EACA,YAAA1B,CAAAA,CACF,EAG6B,CAK3B,OAJa,MAAME,aAAyB,CAAA,CAC1C,GAAK,CAAA,IAAI,GAAIE,CAAAA,CAAAA,CAAU,OAAQJ,CAAY,CAAA,CAAE,UAC7C,CAAA,IAAA,CAAM0B,CACR,CAAC,CAEH,CAZsBvB,CAAAA,CAAAsB,CAAA,CAAA,gBAAA,CAAA","file":"index.js","sourcesContent":["import type { TemplateSuggestionsGetFn } from '@knapsack/types';\nimport { fetcher, Except } from '@knapsack/utils';\n\nexport const path = '/api/v1/template-suggestions';\nexport const method = 'GET';\nexport type ReqParams = Except<\n Parameters<TemplateSuggestionsGetFn>[0],\n 'state'\n> & {\n /**\n * ID from saving {@link ContentStateForRendering} to `api.knapsack.cloud/render-data\n */\n stateId: string;\n};\nexport type ResBody =\n | {\n type: 'success';\n data: Awaited<ReturnType<TemplateSuggestionsGetFn>>;\n }\n | {\n type: 'error.invalidParams';\n message: string;\n }\n | {\n type: 'error.pathNotFound';\n message: string;\n }\n | {\n type: 'error.couldNotParse';\n message: string;\n };\n\nexport async function getTemplateSuggestions({\n appClientUrl,\n query,\n}: {\n appClientUrl: string;\n query: ReqParams;\n}): Promise<ResBody> {\n return fetcher<ResBody>({\n url: new URL(path, appClientUrl).toString(),\n query,\n });\n}\n","import { KsAppClientData, PluginsApi, KsRenderResults } from '@knapsack/types';\nimport type {\n GenericResponse,\n KsAppClientDataAndMeta,\n KsAppClientDataNoMeta,\n KsFileSaverParams,\n} from '@knapsack/types';\nimport { fetcher } from '@knapsack/utils';\nimport * as getTemplateSuggestions from './get-template-suggestions';\n\nexport interface KnapsackDataStoreSaveBody {\n state: KsAppClientData;\n}\n\nexport type PatternRenderDataWithDemoId = {\n patternId: string;\n templateId: string;\n assetSetId: string;\n demoId: string;\n};\n\nexport type PatternRenderData = {\n patternId: string;\n templateId: string;\n assetSetId?: string;\n wrapHtml?: boolean;\n isInIframe?: boolean;\n cacheBuster?: string;\n /**\n * Data id for Demo from `saveData()`\n * @see {@link Demo}\n */\n dataId: string;\n /**\n * ID for @see {ContentStateForRendering}\n */\n stateId: string;\n};\n\nexport const ENDPOINTS = {\n health: '/api/v1/',\n dataStore: '/api/v1/data-store',\n dataStorePrep: '/api/v1/data-store-prep',\n files: '/api/v1/files',\n data: '/api/v1/data',\n render: '/api/v1/render',\n upload: '/api/v1/upload',\n plugins: '/api/v1/plugins',\n getTemplateSuggestions: getTemplateSuggestions.path,\n};\n\nexport async function checkAppClientUrl(url: string): Promise<GenericResponse> {\n try {\n const theUrl = new URL(ENDPOINTS.health, url); // will throw if url not formatted correctly\n const res = await fetcher<GenericResponse>({\n url: theUrl.toString(),\n });\n return res;\n } catch (err) {\n return {\n ok: false,\n message: err instanceof Error ? err.message : 'Unknown error',\n };\n }\n}\n\nexport async function getDataStore({\n appClientUrl,\n}: {\n appClientUrl: string;\n}): Promise<GenericResponse<KsAppClientDataAndMeta>> {\n try {\n const data = await fetcher<KsAppClientDataAndMeta>({\n url: new URL(ENDPOINTS.dataStore, appClientUrl).toString(),\n });\n\n return {\n ok: true,\n data,\n };\n } catch (err) {\n return {\n ok: false,\n message: err instanceof Error ? err.message : 'Unknown error',\n };\n }\n}\n\n// just need a function that can throw an error\nexport async function getAppClientData({\n appClientUrl,\n}: {\n appClientUrl: string;\n}): Promise<KsAppClientDataAndMeta> {\n const serverDataRes = await getDataStore({ appClientUrl });\n if (!serverDataRes.ok || !serverDataRes.data) {\n const message = `Could not load data from custom url \"${appClientUrl}\" ${serverDataRes.message}`;\n throw new Error(message);\n }\n return serverDataRes.data;\n}\n\n/** Sole job is to strip `metaState` if it's there */\nexport function prepAppClientData(\n state: KsAppClientData,\n): KsAppClientDataNoMeta {\n const { metaState, ...appClientDataNoMeta } = state;\n return appClientDataNoMeta;\n}\n\nexport async function prepareDataForFileSave({\n urlBase,\n state,\n}: {\n urlBase: string;\n state: KsAppClientDataNoMeta;\n}): Promise<GenericResponse<KsFileSaverParams>> {\n try {\n const body: KnapsackDataStoreSaveBody = {\n state: prepAppClientData(state),\n };\n const data = await fetcher<GenericResponse<KsFileSaverParams>>({\n url: new URL(ENDPOINTS.dataStorePrep, urlBase).toString(),\n body,\n });\n\n return data;\n } catch (err) {\n return {\n ok: false,\n message: err instanceof Error ? err.message : 'Unknown error',\n };\n }\n}\n\nexport async function submitDataForFileSave({\n urlBase,\n state,\n}: {\n urlBase: string;\n state: KsAppClientDataNoMeta;\n}): Promise<void> {\n const appClientData = prepAppClientData(state);\n const body: KnapsackDataStoreSaveBody = {\n state: appClientData,\n };\n const data = await fetcher<GenericResponse>({\n url: new URL(ENDPOINTS.dataStore, urlBase).toString(),\n body,\n });\n\n if (!data.ok) {\n throw new Error(`Could not save data to localhost files: ${data.message}`);\n }\n}\n\nexport async function getPluginContent({\n pluginId,\n appClientUrl,\n}: {\n pluginId: string;\n appClientUrl: string;\n}): Promise<PluginsApi.GetContentResponse> {\n const body: PluginsApi.GetContentRequest = {\n pluginId,\n type: PluginsApi.ACTIONS.getContent,\n };\n const data = await fetcher<PluginsApi.GetContentResponse>({\n url: new URL(ENDPOINTS.plugins, appClientUrl).toString(),\n body,\n });\n return data;\n}\n\nexport async function renderTemplate({\n options,\n appClientUrl,\n}: {\n options: PatternRenderData;\n appClientUrl: string;\n}): Promise<KsRenderResults> {\n const data = await fetcher<KsRenderResults>({\n url: new URL(ENDPOINTS.render, appClientUrl).toString(),\n body: options,\n });\n return data;\n}\n"]}
|
package/dist/index.mjs
CHANGED
@@ -1,169 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
var __export = (target, all) => {
|
4
|
-
for (var name in all)
|
5
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
6
|
-
};
|
1
|
+
import { fetcher } from '@knapsack/utils';
|
2
|
+
import { PluginsApi } from '@knapsack/types';
|
7
3
|
|
8
|
-
|
9
|
-
var get_template_suggestions_exports = {};
|
10
|
-
__export(get_template_suggestions_exports, {
|
11
|
-
getTemplateSuggestions: () => getTemplateSuggestions,
|
12
|
-
method: () => method,
|
13
|
-
path: () => path
|
14
|
-
});
|
15
|
-
import { fetcher } from "@knapsack/utils";
|
16
|
-
var path = "/api/v1/template-suggestions";
|
17
|
-
var method = "GET";
|
18
|
-
async function getTemplateSuggestions({
|
19
|
-
appClientUrl,
|
20
|
-
query
|
21
|
-
}) {
|
22
|
-
return fetcher({
|
23
|
-
url: new URL(path, appClientUrl).toString(),
|
24
|
-
query
|
25
|
-
});
|
26
|
-
}
|
27
|
-
__name(getTemplateSuggestions, "getTemplateSuggestions");
|
4
|
+
var g=Object.defineProperty;var r=(e,t)=>g(e,"name",{value:t,configurable:!0});var c=(e,t)=>{for(var a in t)g(e,a,{get:t[a],enumerable:!0});};var i={};c(i,{getTemplateSuggestions:()=>S,method:()=>m,path:()=>o});var o="/api/v1/template-suggestions",m="GET";async function S({appClientUrl:e,query:t}){return fetcher({url:new URL(o,e).toString(),query:t})}r(S,"getTemplateSuggestions");var s={health:"/api/v1/",dataStore:"/api/v1/data-store",dataStorePrep:"/api/v1/data-store-prep",files:"/api/v1/files",data:"/api/v1/data",render:"/api/v1/render",upload:"/api/v1/upload",plugins:"/api/v1/plugins",getTemplateSuggestions:o};async function h(e){try{let t=new URL(s.health,e);return await fetcher({url:t.toString()})}catch(t){return {ok:!1,message:t instanceof Error?t.message:"Unknown error"}}}r(h,"checkAppClientUrl");async function f({appClientUrl:e}){try{return {ok:!0,data:await fetcher({url:new URL(s.dataStore,e).toString()})}}catch(t){return {ok:!1,message:t instanceof Error?t.message:"Unknown error"}}}r(f,"getDataStore");async function K({appClientUrl:e}){let t=await f({appClientUrl:e});if(!t.ok||!t.data){let a=`Could not load data from custom url "${e}" ${t.message}`;throw new Error(a)}return t.data}r(K,"getAppClientData");function d(e){let{metaState:t,...a}=e;return a}r(d,"prepAppClientData");async function k({urlBase:e,state:t}){try{let a={state:d(t)};return await fetcher({url:new URL(s.dataStorePrep,e).toString(),body:a})}catch(a){return {ok:!1,message:a instanceof Error?a.message:"Unknown error"}}}r(k,"prepareDataForFileSave");async function I({urlBase:e,state:t}){let p={state:d(t)},l=await fetcher({url:new URL(s.dataStore,e).toString(),body:p});if(!l.ok)throw new Error(`Could not save data to localhost files: ${l.message}`)}r(I,"submitDataForFileSave");async function U({pluginId:e,appClientUrl:t}){let a={pluginId:e,type:PluginsApi.ACTIONS.getContent};return await fetcher({url:new URL(s.plugins,t).toString(),body:a})}r(U,"getPluginContent");async function G({options:e,appClientUrl:t}){return await fetcher({url:new URL(s.render,t).toString(),body:e})}r(G,"renderTemplate");
|
28
5
|
|
29
|
-
|
30
|
-
|
31
|
-
import { fetcher as fetcher2 } from "@knapsack/utils";
|
32
|
-
var ENDPOINTS = {
|
33
|
-
health: "/api/v1/",
|
34
|
-
dataStore: "/api/v1/data-store",
|
35
|
-
dataStorePrep: "/api/v1/data-store-prep",
|
36
|
-
files: "/api/v1/files",
|
37
|
-
data: "/api/v1/data",
|
38
|
-
render: "/api/v1/render",
|
39
|
-
upload: "/api/v1/upload",
|
40
|
-
plugins: "/api/v1/plugins",
|
41
|
-
getTemplateSuggestions: path
|
42
|
-
};
|
43
|
-
async function checkAppClientUrl(url) {
|
44
|
-
try {
|
45
|
-
const theUrl = new URL(ENDPOINTS.health, url);
|
46
|
-
const res = await fetcher2({
|
47
|
-
url: theUrl.toString()
|
48
|
-
});
|
49
|
-
return res;
|
50
|
-
} catch (err) {
|
51
|
-
return {
|
52
|
-
ok: false,
|
53
|
-
message: err instanceof Error ? err.message : "Unknown error"
|
54
|
-
};
|
55
|
-
}
|
56
|
-
}
|
57
|
-
__name(checkAppClientUrl, "checkAppClientUrl");
|
58
|
-
async function getDataStore({
|
59
|
-
appClientUrl
|
60
|
-
}) {
|
61
|
-
try {
|
62
|
-
const data = await fetcher2({
|
63
|
-
url: new URL(ENDPOINTS.dataStore, appClientUrl).toString()
|
64
|
-
});
|
65
|
-
return {
|
66
|
-
ok: true,
|
67
|
-
data
|
68
|
-
};
|
69
|
-
} catch (err) {
|
70
|
-
return {
|
71
|
-
ok: false,
|
72
|
-
message: err instanceof Error ? err.message : "Unknown error"
|
73
|
-
};
|
74
|
-
}
|
75
|
-
}
|
76
|
-
__name(getDataStore, "getDataStore");
|
77
|
-
async function getAppClientData({
|
78
|
-
appClientUrl
|
79
|
-
}) {
|
80
|
-
const serverDataRes = await getDataStore({ appClientUrl });
|
81
|
-
if (!serverDataRes.ok || !serverDataRes.data) {
|
82
|
-
const message = `Could not load data from custom url "${appClientUrl}" ${serverDataRes.message}`;
|
83
|
-
throw new Error(message);
|
84
|
-
}
|
85
|
-
return serverDataRes.data;
|
86
|
-
}
|
87
|
-
__name(getAppClientData, "getAppClientData");
|
88
|
-
function prepAppClientData(state) {
|
89
|
-
const { metaState, ...appClientDataNoMeta } = state;
|
90
|
-
return appClientDataNoMeta;
|
91
|
-
}
|
92
|
-
__name(prepAppClientData, "prepAppClientData");
|
93
|
-
async function prepareDataForFileSave({
|
94
|
-
urlBase,
|
95
|
-
state
|
96
|
-
}) {
|
97
|
-
try {
|
98
|
-
const body = {
|
99
|
-
state: prepAppClientData(state)
|
100
|
-
};
|
101
|
-
const data = await fetcher2({
|
102
|
-
url: new URL(ENDPOINTS.dataStorePrep, urlBase).toString(),
|
103
|
-
body
|
104
|
-
});
|
105
|
-
return data;
|
106
|
-
} catch (err) {
|
107
|
-
return {
|
108
|
-
ok: false,
|
109
|
-
message: err instanceof Error ? err.message : "Unknown error"
|
110
|
-
};
|
111
|
-
}
|
112
|
-
}
|
113
|
-
__name(prepareDataForFileSave, "prepareDataForFileSave");
|
114
|
-
async function submitDataForFileSave({
|
115
|
-
urlBase,
|
116
|
-
state
|
117
|
-
}) {
|
118
|
-
const appClientData = prepAppClientData(state);
|
119
|
-
const body = {
|
120
|
-
state: appClientData
|
121
|
-
};
|
122
|
-
const data = await fetcher2({
|
123
|
-
url: new URL(ENDPOINTS.dataStore, urlBase).toString(),
|
124
|
-
body
|
125
|
-
});
|
126
|
-
if (!data.ok) {
|
127
|
-
throw new Error(`Could not save data to localhost files: ${data.message}`);
|
128
|
-
}
|
129
|
-
}
|
130
|
-
__name(submitDataForFileSave, "submitDataForFileSave");
|
131
|
-
async function getPluginContent({
|
132
|
-
pluginId,
|
133
|
-
appClientUrl
|
134
|
-
}) {
|
135
|
-
const body = {
|
136
|
-
pluginId,
|
137
|
-
type: PluginsApi.ACTIONS.getContent
|
138
|
-
};
|
139
|
-
const data = await fetcher2({
|
140
|
-
url: new URL(ENDPOINTS.plugins, appClientUrl).toString(),
|
141
|
-
body
|
142
|
-
});
|
143
|
-
return data;
|
144
|
-
}
|
145
|
-
__name(getPluginContent, "getPluginContent");
|
146
|
-
async function renderTemplate({
|
147
|
-
options,
|
148
|
-
appClientUrl
|
149
|
-
}) {
|
150
|
-
const data = await fetcher2({
|
151
|
-
url: new URL(ENDPOINTS.render, appClientUrl).toString(),
|
152
|
-
body: options
|
153
|
-
});
|
154
|
-
return data;
|
155
|
-
}
|
156
|
-
__name(renderTemplate, "renderTemplate");
|
157
|
-
export {
|
158
|
-
ENDPOINTS,
|
159
|
-
checkAppClientUrl,
|
160
|
-
getAppClientData,
|
161
|
-
getDataStore,
|
162
|
-
getPluginContent,
|
163
|
-
get_template_suggestions_exports as getTemplateSuggestions,
|
164
|
-
prepAppClientData,
|
165
|
-
prepareDataForFileSave,
|
166
|
-
renderTemplate,
|
167
|
-
submitDataForFileSave
|
168
|
-
};
|
6
|
+
export { s as ENDPOINTS, h as checkAppClientUrl, K as getAppClientData, f as getDataStore, U as getPluginContent, i as getTemplateSuggestions, d as prepAppClientData, k as prepareDataForFileSave, G as renderTemplate, I as submitDataForFileSave };
|
7
|
+
//# sourceMappingURL=index.mjs.map
|
169
8
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/get-template-suggestions.ts","../src/app-client-api.ts"],"sourcesContent":["import type { TemplateSuggestionsGetFn } from '@knapsack/types';\nimport { fetcher, Except } from '@knapsack/utils';\n\nexport const path = '/api/v1/template-suggestions';\nexport const method = 'GET';\nexport type ReqParams = Except<\n Parameters<TemplateSuggestionsGetFn>[0],\n 'state'\n> & {\n /**\n * ID from saving {@link ContentStateForRendering} to `api.knapsack.cloud/render-data\n */\n stateId: string;\n};\nexport type ResBody =\n | {\n type: 'success';\n data: Awaited<ReturnType<TemplateSuggestionsGetFn>>;\n }\n | {\n type: 'error.invalidParams';\n message: string;\n }\n | {\n type: 'error.pathNotFound';\n message: string;\n }\n | {\n type: 'error.couldNotParse';\n message: string;\n };\n\nexport async function getTemplateSuggestions({\n appClientUrl,\n query,\n}: {\n appClientUrl: string;\n query: ReqParams;\n}): Promise<ResBody> {\n return fetcher<ResBody>({\n url: new URL(path, appClientUrl).toString(),\n query,\n });\n}\n","import { KsAppClientData, PluginsApi, KsRenderResults } from '@knapsack/types';\nimport type {\n GenericResponse,\n KsAppClientDataAndMeta,\n KsAppClientDataNoMeta,\n KsFileSaverParams,\n} from '@knapsack/types';\nimport { fetcher } from '@knapsack/utils';\nimport * as getTemplateSuggestions from './get-template-suggestions';\n\nexport interface KnapsackDataStoreSaveBody {\n state: KsAppClientData;\n}\n\nexport type PatternRenderDataWithDemoId = {\n patternId: string;\n templateId: string;\n assetSetId: string;\n demoId: string;\n};\n\nexport type PatternRenderData = {\n patternId: string;\n templateId: string;\n assetSetId?: string;\n wrapHtml?: boolean;\n isInIframe?: boolean;\n cacheBuster?: string;\n /**\n * Data id for Demo from `saveData()`\n * @see {@link Demo}\n */\n dataId: string;\n /**\n * ID for @see {ContentStateForRendering}\n */\n stateId: string;\n};\n\nexport const ENDPOINTS = {\n health: '/api/v1/',\n dataStore: '/api/v1/data-store',\n dataStorePrep: '/api/v1/data-store-prep',\n files: '/api/v1/files',\n data: '/api/v1/data',\n render: '/api/v1/render',\n upload: '/api/v1/upload',\n plugins: '/api/v1/plugins',\n getTemplateSuggestions: getTemplateSuggestions.path,\n};\n\nexport async function checkAppClientUrl(url: string): Promise<GenericResponse> {\n try {\n const theUrl = new URL(ENDPOINTS.health, url); // will throw if url not formatted correctly\n const res = await fetcher<GenericResponse>({\n url: theUrl.toString(),\n });\n return res;\n } catch (err) {\n return {\n ok: false,\n message: err instanceof Error ? err.message : 'Unknown error',\n };\n }\n}\n\nexport async function getDataStore({\n appClientUrl,\n}: {\n appClientUrl: string;\n}): Promise<GenericResponse<KsAppClientDataAndMeta>> {\n try {\n const data = await fetcher<KsAppClientDataAndMeta>({\n url: new URL(ENDPOINTS.dataStore, appClientUrl).toString(),\n });\n\n return {\n ok: true,\n data,\n };\n } catch (err) {\n return {\n ok: false,\n message: err instanceof Error ? err.message : 'Unknown error',\n };\n }\n}\n\n// just need a function that can throw an error\nexport async function getAppClientData({\n appClientUrl,\n}: {\n appClientUrl: string;\n}): Promise<KsAppClientDataAndMeta> {\n const serverDataRes = await getDataStore({ appClientUrl });\n if (!serverDataRes.ok || !serverDataRes.data) {\n const message = `Could not load data from custom url \"${appClientUrl}\" ${serverDataRes.message}`;\n throw new Error(message);\n }\n return serverDataRes.data;\n}\n\n/** Sole job is to strip `metaState` if it's there */\nexport function prepAppClientData(\n state: KsAppClientData,\n): KsAppClientDataNoMeta {\n const { metaState, ...appClientDataNoMeta } = state;\n return appClientDataNoMeta;\n}\n\nexport async function prepareDataForFileSave({\n urlBase,\n state,\n}: {\n urlBase: string;\n state: KsAppClientDataNoMeta;\n}): Promise<GenericResponse<KsFileSaverParams>> {\n try {\n const body: KnapsackDataStoreSaveBody = {\n state: prepAppClientData(state),\n };\n const data = await fetcher<GenericResponse<KsFileSaverParams>>({\n url: new URL(ENDPOINTS.dataStorePrep, urlBase).toString(),\n body,\n });\n\n return data;\n } catch (err) {\n return {\n ok: false,\n message: err instanceof Error ? err.message : 'Unknown error',\n };\n }\n}\n\nexport async function submitDataForFileSave({\n urlBase,\n state,\n}: {\n urlBase: string;\n state: KsAppClientDataNoMeta;\n}): Promise<void> {\n const appClientData = prepAppClientData(state);\n const body: KnapsackDataStoreSaveBody = {\n state: appClientData,\n };\n const data = await fetcher<GenericResponse>({\n url: new URL(ENDPOINTS.dataStore, urlBase).toString(),\n body,\n });\n\n if (!data.ok) {\n throw new Error(`Could not save data to localhost files: ${data.message}`);\n }\n}\n\nexport async function getPluginContent({\n pluginId,\n appClientUrl,\n}: {\n pluginId: string;\n appClientUrl: string;\n}): Promise<PluginsApi.GetContentResponse> {\n const body: PluginsApi.GetContentRequest = {\n pluginId,\n type: PluginsApi.ACTIONS.getContent,\n };\n const data = await fetcher<PluginsApi.GetContentResponse>({\n url: new URL(ENDPOINTS.plugins, appClientUrl).toString(),\n body,\n });\n return data;\n}\n\nexport async function renderTemplate({\n options,\n appClientUrl,\n}: {\n options: PatternRenderData;\n appClientUrl: string;\n}): Promise<KsRenderResults> {\n const data = await fetcher<KsRenderResults>({\n url: new URL(ENDPOINTS.render, appClientUrl).toString(),\n body: options,\n });\n return data;\n}\n"]
|
1
|
+
{"version":3,"sources":["../src/get-template-suggestions.ts","../src/app-client-api.ts"],"names":["get_template_suggestions_exports","__export","getTemplateSuggestions","method","path","appClientUrl","query","fetcher","__name","ENDPOINTS","checkAppClientUrl","url","theUrl","err","getDataStore","getAppClientData","serverDataRes","message","prepAppClientData","state","metaState","appClientDataNoMeta","prepareDataForFileSave","urlBase","body","submitDataForFileSave","data","getPluginContent","pluginId","PluginsApi","renderTemplate","options"],"mappings":";;;8IAAAA,IAAAA,CAAAA,CAAA,GAAAC,CAAA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A,CAAA","file":"index.mjs","sourcesContent":["import type { TemplateSuggestionsGetFn } from '@knapsack/types';\nimport { fetcher, Except } from '@knapsack/utils';\n\nexport const path = '/api/v1/template-suggestions';\nexport const method = 'GET';\nexport type ReqParams = Except<\n Parameters<TemplateSuggestionsGetFn>[0],\n 'state'\n> & {\n /**\n * ID from saving {@link ContentStateForRendering} to `api.knapsack.cloud/render-data\n */\n stateId: string;\n};\nexport type ResBody =\n | {\n type: 'success';\n data: Awaited<ReturnType<TemplateSuggestionsGetFn>>;\n }\n | {\n type: 'error.invalidParams';\n message: string;\n }\n | {\n type: 'error.pathNotFound';\n message: string;\n }\n | {\n type: 'error.couldNotParse';\n message: string;\n };\n\nexport async function getTemplateSuggestions({\n appClientUrl,\n query,\n}: {\n appClientUrl: string;\n query: ReqParams;\n}): Promise<ResBody> {\n return fetcher<ResBody>({\n url: new URL(path, appClientUrl).toString(),\n query,\n });\n}\n","import { KsAppClientData, PluginsApi, KsRenderResults } from '@knapsack/types';\nimport type {\n GenericResponse,\n KsAppClientDataAndMeta,\n KsAppClientDataNoMeta,\n KsFileSaverParams,\n} from '@knapsack/types';\nimport { fetcher } from '@knapsack/utils';\nimport * as getTemplateSuggestions from './get-template-suggestions';\n\nexport interface KnapsackDataStoreSaveBody {\n state: KsAppClientData;\n}\n\nexport type PatternRenderDataWithDemoId = {\n patternId: string;\n templateId: string;\n assetSetId: string;\n demoId: string;\n};\n\nexport type PatternRenderData = {\n patternId: string;\n templateId: string;\n assetSetId?: string;\n wrapHtml?: boolean;\n isInIframe?: boolean;\n cacheBuster?: string;\n /**\n * Data id for Demo from `saveData()`\n * @see {@link Demo}\n */\n dataId: string;\n /**\n * ID for @see {ContentStateForRendering}\n */\n stateId: string;\n};\n\nexport const ENDPOINTS = {\n health: '/api/v1/',\n dataStore: '/api/v1/data-store',\n dataStorePrep: '/api/v1/data-store-prep',\n files: '/api/v1/files',\n data: '/api/v1/data',\n render: '/api/v1/render',\n upload: '/api/v1/upload',\n plugins: '/api/v1/plugins',\n getTemplateSuggestions: getTemplateSuggestions.path,\n};\n\nexport async function checkAppClientUrl(url: string): Promise<GenericResponse> {\n try {\n const theUrl = new URL(ENDPOINTS.health, url); // will throw if url not formatted correctly\n const res = await fetcher<GenericResponse>({\n url: theUrl.toString(),\n });\n return res;\n } catch (err) {\n return {\n ok: false,\n message: err instanceof Error ? err.message : 'Unknown error',\n };\n }\n}\n\nexport async function getDataStore({\n appClientUrl,\n}: {\n appClientUrl: string;\n}): Promise<GenericResponse<KsAppClientDataAndMeta>> {\n try {\n const data = await fetcher<KsAppClientDataAndMeta>({\n url: new URL(ENDPOINTS.dataStore, appClientUrl).toString(),\n });\n\n return {\n ok: true,\n data,\n };\n } catch (err) {\n return {\n ok: false,\n message: err instanceof Error ? err.message : 'Unknown error',\n };\n }\n}\n\n// just need a function that can throw an error\nexport async function getAppClientData({\n appClientUrl,\n}: {\n appClientUrl: string;\n}): Promise<KsAppClientDataAndMeta> {\n const serverDataRes = await getDataStore({ appClientUrl });\n if (!serverDataRes.ok || !serverDataRes.data) {\n const message = `Could not load data from custom url \"${appClientUrl}\" ${serverDataRes.message}`;\n throw new Error(message);\n }\n return serverDataRes.data;\n}\n\n/** Sole job is to strip `metaState` if it's there */\nexport function prepAppClientData(\n state: KsAppClientData,\n): KsAppClientDataNoMeta {\n const { metaState, ...appClientDataNoMeta } = state;\n return appClientDataNoMeta;\n}\n\nexport async function prepareDataForFileSave({\n urlBase,\n state,\n}: {\n urlBase: string;\n state: KsAppClientDataNoMeta;\n}): Promise<GenericResponse<KsFileSaverParams>> {\n try {\n const body: KnapsackDataStoreSaveBody = {\n state: prepAppClientData(state),\n };\n const data = await fetcher<GenericResponse<KsFileSaverParams>>({\n url: new URL(ENDPOINTS.dataStorePrep, urlBase).toString(),\n body,\n });\n\n return data;\n } catch (err) {\n return {\n ok: false,\n message: err instanceof Error ? err.message : 'Unknown error',\n };\n }\n}\n\nexport async function submitDataForFileSave({\n urlBase,\n state,\n}: {\n urlBase: string;\n state: KsAppClientDataNoMeta;\n}): Promise<void> {\n const appClientData = prepAppClientData(state);\n const body: KnapsackDataStoreSaveBody = {\n state: appClientData,\n };\n const data = await fetcher<GenericResponse>({\n url: new URL(ENDPOINTS.dataStore, urlBase).toString(),\n body,\n });\n\n if (!data.ok) {\n throw new Error(`Could not save data to localhost files: ${data.message}`);\n }\n}\n\nexport async function getPluginContent({\n pluginId,\n appClientUrl,\n}: {\n pluginId: string;\n appClientUrl: string;\n}): Promise<PluginsApi.GetContentResponse> {\n const body: PluginsApi.GetContentRequest = {\n pluginId,\n type: PluginsApi.ACTIONS.getContent,\n };\n const data = await fetcher<PluginsApi.GetContentResponse>({\n url: new URL(ENDPOINTS.plugins, appClientUrl).toString(),\n body,\n });\n return data;\n}\n\nexport async function renderTemplate({\n options,\n appClientUrl,\n}: {\n options: PatternRenderData;\n appClientUrl: string;\n}): Promise<KsRenderResults> {\n const data = await fetcher<KsRenderResults>({\n url: new URL(ENDPOINTS.render, appClientUrl).toString(),\n body: options,\n });\n return data;\n}\n"]}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@knapsack/app-client-api",
|
3
3
|
"description": "",
|
4
|
-
"version": "4.70.0--canary.4821.
|
4
|
+
"version": "4.70.0--canary.4821.82d27e9.0",
|
5
5
|
"exports": {
|
6
6
|
".": {
|
7
7
|
"types": "./dist/index.d.ts",
|
@@ -21,14 +21,14 @@
|
|
21
21
|
"lint": "eslint ./"
|
22
22
|
},
|
23
23
|
"dependencies": {
|
24
|
-
"@knapsack/types": "4.70.0--canary.4821.
|
25
|
-
"@knapsack/utils": "4.70.0--canary.4821.
|
24
|
+
"@knapsack/types": "4.70.0--canary.4821.82d27e9.0",
|
25
|
+
"@knapsack/utils": "4.70.0--canary.4821.82d27e9.0",
|
26
26
|
"cross-fetch": "^4.0.0"
|
27
27
|
},
|
28
28
|
"devDependencies": {
|
29
|
-
"@knapsack/eslint-config-starter": "4.70.0--canary.4821.
|
30
|
-
"@knapsack/prettier-config": "4.70.0--canary.4821.
|
31
|
-
"@knapsack/typescript-config-starter": "4.70.0--canary.4821.
|
29
|
+
"@knapsack/eslint-config-starter": "4.70.0--canary.4821.82d27e9.0",
|
30
|
+
"@knapsack/prettier-config": "4.70.0--canary.4821.82d27e9.0",
|
31
|
+
"@knapsack/typescript-config-starter": "4.70.0--canary.4821.82d27e9.0",
|
32
32
|
"@types/node": "^20.16.6",
|
33
33
|
"eslint": "^8.57.0",
|
34
34
|
"tsup": "^8.2.4",
|
@@ -43,5 +43,5 @@
|
|
43
43
|
"directory": "libs/app-client-api",
|
44
44
|
"type": "git"
|
45
45
|
},
|
46
|
-
"gitHead": "
|
46
|
+
"gitHead": "82d27e98c26dd8ff00329a2a23ca7f3fc090e144"
|
47
47
|
}
|