@knapsack/app-client-api 4.70.0--canary.3797.b249674.0 → 4.70.0--canary.4821.56b0218.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,22 +3,28 @@ import type { GenericResponse, KsAppClientDataAndMeta, KsAppClientDataNoMeta, Ks
3
3
  export interface KnapsackDataStoreSaveBody {
4
4
  state: KsAppClientData;
5
5
  }
6
+ export type PatternRenderDataWithDemoId = {
7
+ patternId: string;
8
+ templateId: string;
9
+ assetSetId: string;
10
+ demoId: string;
11
+ };
6
12
  export type PatternRenderData = {
7
13
  patternId: string;
8
14
  templateId: string;
9
- /**
10
- * Data id from `saveData()`
11
- * Cannot use with `demoId`
12
- */
13
- dataId?: string;
14
- /**
15
- * Cannot use with `dataId`
16
- */
17
- demoId?: string;
18
15
  assetSetId?: string;
19
16
  wrapHtml?: boolean;
20
17
  isInIframe?: boolean;
21
18
  cacheBuster?: string;
19
+ /**
20
+ * Data id for Demo from `saveData()`
21
+ * @see {@link Demo}
22
+ */
23
+ dataId: string;
24
+ /**
25
+ * ID for @see {ContentStateForRendering}
26
+ */
27
+ stateId: string;
22
28
  };
23
29
  export declare const ENDPOINTS: {
24
30
  health: string;
@@ -1 +1 @@
1
- {"version":3,"file":"app-client-api.d.ts","sourceRoot":"","sources":["../src/app-client-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,KAAK,EACV,eAAe,EACf,sBAAsB,EACtB,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AAIzB,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,eAAe,CAAC;CACxB;AACD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;I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,YAAY,GACb,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAOlC;AAED,qDAAqD;AACrD,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,eAAe,GACrB,qBAAqB,CAGvB;AAED,wBAAsB,sBAAsB,CAAC,EAC3C,OAAO,EACP,KAAK,GACN,EAAE;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,qBAAqB,CAAC;CAC9B,GAAG,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC,CAiB9C;AAED,wBAAsB,qBAAqB,CAAC,EAC1C,OAAO,EACP,KAAK,GACN,EAAE;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,qBAAqB,CAAC;CAC9B,GAAG,OAAO,CAAC,IAAI,CAAC,CAahB;AAED,wBAAsB,gBAAgB,CAAC,EACrC,QAAQ,EACR,YAAY,GACb,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAUzC;AAED,wBAAsB,cAAc,CAAC,EACnC,OAAO,EACP,YAAY,GACb,EAAE;IACD,OAAO,EAAE,iBAAiB,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,CAAC,eAAe,CAAC,CAM3B"}
@@ -1,7 +1,13 @@
1
1
  import type { TemplateSuggestionsGetFn } from '@knapsack/types';
2
+ import { Except } from '@knapsack/utils';
2
3
  export declare const path = "/api/v1/template-suggestions";
3
4
  export declare const method = "GET";
4
- export type ReqParams = Parameters<TemplateSuggestionsGetFn>[0];
5
+ export type ReqParams = Except<Parameters<TemplateSuggestionsGetFn>[0], 'state'> & {
6
+ /**
7
+ * ID from saving {@link ContentStateForRendering} to `api.knapsack.cloud/render-data
8
+ */
9
+ stateId: string;
10
+ };
5
11
  export type ResBody = {
6
12
  type: 'success';
7
13
  data: Awaited<ReturnType<TemplateSuggestionsGetFn>>;
@@ -1 +1 @@
1
- {"version":3,"file":"get-template-suggestions.d.ts","sourceRoot":"","sources":["../src/get-template-suggestions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAGhE,eAAO,MAAM,IAAI,iCAAiC,CAAC;AACnD,eAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC;AAChE,MAAM,MAAM,OAAO,GACf;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,wBAAwB,CAAC,CAAC,CAAC;CACrD,GACD;IACE,IAAI,EAAE,qBAAqB,CAAC;IAC5B,OAAO,EAAE,MAAM,CAAC;CACjB,GACD;IACE,IAAI,EAAE,oBAAoB,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;CACjB,GACD;IACE,IAAI,EAAE,qBAAqB,CAAC;IAC5B,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEN,wBAAsB,sBAAsB,CAAC,EAC3C,YAAY,EACZ,KAAK,GACN,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,SAAS,CAAC;CAClB,GAAG,OAAO,CAAC,OAAO,CAAC,CAKnB"}
1
+ {"version":3,"file":"get-template-suggestions.d.ts","sourceRoot":"","sources":["../src/get-template-suggestions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAW,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAElD,eAAO,MAAM,IAAI,iCAAiC,CAAC;AACnD,eAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,MAAM,MAAM,SAAS,GAAG,MAAM,CAC5B,UAAU,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,EACvC,OAAO,CACR,GAAG;IACF;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AACF,MAAM,MAAM,OAAO,GACf;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,wBAAwB,CAAC,CAAC,CAAC;CACrD,GACD;IACE,IAAI,EAAE,qBAAqB,CAAC;IAC5B,OAAO,EAAE,MAAM,CAAC;CACjB,GACD;IACE,IAAI,EAAE,oBAAoB,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;CACjB,GACD;IACE,IAAI,EAAE,qBAAqB,CAAC;IAC5B,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEN,wBAAsB,sBAAsB,CAAC,EAC3C,YAAY,EACZ,KAAK,GACN,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,SAAS,CAAC;CAClB,GAAG,OAAO,CAAC,OAAO,CAAC,CAKnB"}
package/dist/index.js CHANGED
@@ -1,19 +1,199 @@
1
- 'use strict';
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 __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);
2
20
 
3
- var utils = require('@knapsack/utils');
4
- var types = require('@knapsack/types');
21
+ // src/index.ts
22
+ var src_exports = {};
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);
5
36
 
6
- var g=Object.defineProperty;var r=(t,e)=>g(t,"name",{value:e,configurable:!0});var d=(t,e)=>{for(var a in e)g(t,a,{get:e[a],enumerable:!0});};var i={};d(i,{getTemplateSuggestions:()=>S,method:()=>m,path:()=>o});var o="/api/v1/template-suggestions",m="GET";async function S({appClientUrl:t,query:e}){return utils.fetcher({url:new URL(o,t).toString(),query:e})}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 K(t){try{let e=new URL(s.health,t);return await utils.fetcher({url:e.toString()})}catch(e){return {ok:!1,message:e instanceof Error?e.message:"Unknown error"}}}r(K,"checkAppClientUrl");async function f({appClientUrl:t}){try{return {ok:!0,data:await utils.fetcher({url:new URL(s.dataStore,t).toString()})}}catch(e){return {ok:!1,message:e instanceof Error?e.message:"Unknown error"}}}r(f,"getDataStore");async function h({appClientUrl:t}){let e=await f({appClientUrl:t});if(!e.ok||!e.data){let a=`Could not load data from custom url "${t}" ${e.message}`;throw new Error(a)}return e.data}r(h,"getAppClientData");function c(t){let{metaState:e,...a}=t;return a}r(c,"prepAppClientData");async function x({urlBase:t,state:e}){try{let a={state:c(e)};return await utils.fetcher({url:new URL(s.dataStorePrep,t).toString(),body:a})}catch(a){return {ok:!1,message:a instanceof Error?a.message:"Unknown error"}}}r(x,"prepareDataForFileSave");async function k({urlBase:t,state:e}){let p={state:c(e)},l=await utils.fetcher({url:new URL(s.dataStore,t).toString(),body:p});if(!l.ok)throw new Error(`Could not save data to localhost files: ${l.message}`)}r(k,"submitDataForFileSave");async function U({pluginId:t,appClientUrl:e}){let a={pluginId:t,type:types.PluginsApi.ACTIONS.getContent};return await utils.fetcher({url:new URL(s.plugins,e).toString(),body:a})}r(U,"getPluginContent");async function G({options:t,appClientUrl:e}){return await utils.fetcher({url:new URL(s.render,e).toString(),body:t})}r(G,"renderTemplate");
37
+ // src/get-template-suggestions.ts
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");
7
57
 
8
- exports.ENDPOINTS = s;
9
- exports.checkAppClientUrl = K;
10
- exports.getAppClientData = h;
11
- exports.getDataStore = f;
12
- exports.getPluginContent = U;
13
- exports.getTemplateSuggestions = i;
14
- exports.prepAppClientData = c;
15
- exports.prepareDataForFileSave = x;
16
- exports.renderTemplate = G;
17
- exports.submitDataForFileSave = k;
18
- //# sourceMappingURL=index.js.map
58
+ // src/app-client-api.ts
59
+ var import_types = require("@knapsack/types");
60
+ var import_utils2 = require("@knapsack/utils");
61
+ var ENDPOINTS = {
62
+ health: "/api/v1/",
63
+ dataStore: "/api/v1/data-store",
64
+ dataStorePrep: "/api/v1/data-store-prep",
65
+ files: "/api/v1/files",
66
+ data: "/api/v1/data",
67
+ render: "/api/v1/render",
68
+ upload: "/api/v1/upload",
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
+ });
19
199
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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,CAoBtB,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,CAAAA,CAAAA,CAAuC,CAC7E,GAAI,CACF,IAAMC,CAAAA,CAAS,IAAI,GAAA,CAAIH,EAAU,MAAQE,CAAAA,CAAG,EAI5C,OAHY,MAAMJ,cAAyB,CACzC,GAAA,CAAKK,CAAO,CAAA,QAAA,EACd,CAAC,CAEH,CAASC,MAAAA,CAAAA,CAAK,CACZ,OAAO,CACL,GAAI,CACJ,CAAA,CAAA,OAAA,CAASA,aAAe,KAAQA,CAAAA,CAAAA,CAAI,QAAU,eAChD,CACF,CACF,CAbsBL,CAAAA,CAAAE,EAAA,mBAetB,CAAA,CAAA,eAAsBI,CAAa,CAAA,CACjC,YAAAT,CAAAA,CACF,EAEqD,C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,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 } from '@knapsack/utils';\n\nexport const path = '/api/v1/template-suggestions';\nexport const method = 'GET';\nexport type ReqParams = Parameters<TemplateSuggestionsGetFn>[0];\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}\nexport type PatternRenderData = {\n patternId: string;\n templateId: string;\n /**\n * Data id from `saveData()`\n * Cannot use with `demoId`\n */\n dataId?: string;\n /**\n * Cannot use with `dataId`\n */\n demoId?: string;\n assetSetId?: string;\n wrapHtml?: boolean;\n isInIframe?: boolean;\n cacheBuster?: 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/index.ts","../src/get-template-suggestions.ts","../src/app-client-api.ts"],"sourcesContent":["import * as getTemplateSuggestions from './get-template-suggestions';\n\nexport { getTemplateSuggestions };\nexport * from './app-client-api';\n","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"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAgC;AAEzB,IAAM,OAAO;AACb,IAAM,SAAS;AA4BtB,eAAsB,uBAAuB;AAAA,EAC3C;AAAA,EACA;AACF,GAGqB;AACnB,aAAO,sBAAiB;AAAA,IACtB,KAAK,IAAI,IAAI,MAAM,YAAY,EAAE,SAAS;AAAA,IAC1C;AAAA,EACF,CAAC;AACH;AAXsB;;;AChCtB,mBAA6D;AAO7D,IAAAA,gBAAwB;AAgCjB,IAAM,YAAY;AAAA,EACvB,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,eAAe;AAAA,EACf,OAAO;AAAA,EACP,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,wBAA+C;AACjD;AAEA,eAAsB,kBAAkB,KAAuC;AAC7E,MAAI;AACF,UAAM,SAAS,IAAI,IAAI,UAAU,QAAQ,GAAG;AAC5C,UAAM,MAAM,UAAM,uBAAyB;AAAA,MACzC,KAAK,OAAO,SAAS;AAAA,IACvB,CAAC;AACD,WAAO;AAAA,EACT,SAAS,KAAK;AACZ,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,SAAS,eAAe,QAAQ,IAAI,UAAU;AAAA,IAChD;AAAA,EACF;AACF;AAbsB;AAetB,eAAsB,aAAa;AAAA,EACjC;AACF,GAEqD;AACnD,MAAI;AACF,UAAM,OAAO,UAAM,uBAAgC;AAAA,MACjD,KAAK,IAAI,IAAI,UAAU,WAAW,YAAY,EAAE,SAAS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ED,MAAI,CAAC,KAAK,IAAI;AACZ,UAAM,IAAI,MAAM,2CAA2C,KAAK,OAAO,EAAE;AAAA,EAC3E;AACF;AAnBsB;AAqBtB,eAAsB,iBAAiB;AAAA,EACrC;AAAA,EACA;AACF,GAG2C;AACzC,QAAM,OAAqC;AAAA,IACzC;AAAA,IACA,MAAM,wBAAW,QAAQ;AAAA,EAC3B;AACA,QAAM,OAAO,UAAM,uBAAuC;AAAA,IACxD,KAAK,IAAI,IAAI,UAAU,SAAS,YAAY,EAAE,SAAS;AAAA,IACvD;AAAA,EACF,CAAC;AACD,SAAO;AACT;AAhBsB;AAkBtB,eAAsB,eAAe;AAAA,EACnC;AAAA,EACA;AACF,GAG6B;AAC3B,QAAM,OAAO,UAAM,uBAAyB;AAAA,IAC1C,KAAK,IAAI,IAAI,UAAU,QAAQ,YAAY,EAAE,SAAS;AAAA,IACtD,MAAM;AAAA,EACR,CAAC;AACD,SAAO;AACT;AAZsB;","names":["import_utils"]}
package/dist/index.mjs CHANGED
@@ -1,8 +1,169 @@
1
- import { fetcher } from '@knapsack/utils';
2
- import { PluginsApi } from '@knapsack/types';
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, { get: all[name], enumerable: true });
6
+ };
3
7
 
4
- var g=Object.defineProperty;var r=(t,e)=>g(t,"name",{value:e,configurable:!0});var d=(t,e)=>{for(var a in e)g(t,a,{get:e[a],enumerable:!0});};var i={};d(i,{getTemplateSuggestions:()=>S,method:()=>m,path:()=>o});var o="/api/v1/template-suggestions",m="GET";async function S({appClientUrl:t,query:e}){return fetcher({url:new URL(o,t).toString(),query:e})}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 K(t){try{let e=new URL(s.health,t);return await fetcher({url:e.toString()})}catch(e){return {ok:!1,message:e instanceof Error?e.message:"Unknown error"}}}r(K,"checkAppClientUrl");async function f({appClientUrl:t}){try{return {ok:!0,data:await fetcher({url:new URL(s.dataStore,t).toString()})}}catch(e){return {ok:!1,message:e instanceof Error?e.message:"Unknown error"}}}r(f,"getDataStore");async function h({appClientUrl:t}){let e=await f({appClientUrl:t});if(!e.ok||!e.data){let a=`Could not load data from custom url "${t}" ${e.message}`;throw new Error(a)}return e.data}r(h,"getAppClientData");function c(t){let{metaState:e,...a}=t;return a}r(c,"prepAppClientData");async function x({urlBase:t,state:e}){try{let a={state:c(e)};return await fetcher({url:new URL(s.dataStorePrep,t).toString(),body:a})}catch(a){return {ok:!1,message:a instanceof Error?a.message:"Unknown error"}}}r(x,"prepareDataForFileSave");async function k({urlBase:t,state:e}){let p={state:c(e)},l=await fetcher({url:new URL(s.dataStore,t).toString(),body:p});if(!l.ok)throw new Error(`Could not save data to localhost files: ${l.message}`)}r(k,"submitDataForFileSave");async function U({pluginId:t,appClientUrl:e}){let a={pluginId:t,type:PluginsApi.ACTIONS.getContent};return await fetcher({url:new URL(s.plugins,e).toString(),body:a})}r(U,"getPluginContent");async function G({options:t,appClientUrl:e}){return await fetcher({url:new URL(s.render,e).toString(),body:t})}r(G,"renderTemplate");
8
+ // src/get-template-suggestions.ts
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");
5
28
 
6
- export { s as ENDPOINTS, K as checkAppClientUrl, h as getAppClientData, f as getDataStore, U as getPluginContent, i as getTemplateSuggestions, c as prepAppClientData, x as prepareDataForFileSave, G as renderTemplate, k as submitDataForFileSave };
7
- //# sourceMappingURL=index.mjs.map
29
+ // src/app-client-api.ts
30
+ import { PluginsApi } from "@knapsack/types";
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
+ };
8
169
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
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,CAoBtB,eAAsBD,CAAAA,CAAuB,CAC3C,YAAA,CAAAG,EACA,KAAAC,CAAAA,CACF,EAGqB,CACnB,OAAOC,QAAiB,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,CAAAA,CAAAA,CAAuC,CAC7E,GAAI,CACF,IAAMC,CAAAA,CAAS,IAAI,GAAA,CAAIH,EAAU,MAAQE,CAAAA,CAAG,EAI5C,OAHY,MAAMJ,QAAyB,CACzC,GAAA,CAAKK,CAAO,CAAA,QAAA,EACd,CAAC,CAEH,C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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,OAAyB,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.mjs","sourcesContent":["import type { TemplateSuggestionsGetFn } from '@knapsack/types';\nimport { fetcher } from '@knapsack/utils';\n\nexport const path = '/api/v1/template-suggestions';\nexport const method = 'GET';\nexport type ReqParams = Parameters<TemplateSuggestionsGetFn>[0];\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}\nexport type PatternRenderData = {\n patternId: string;\n templateId: string;\n /**\n * Data id from `saveData()`\n * Cannot use with `demoId`\n */\n dataId?: string;\n /**\n * Cannot use with `dataId`\n */\n demoId?: string;\n assetSetId?: string;\n wrapHtml?: boolean;\n isInIframe?: boolean;\n cacheBuster?: 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"],"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"],"mappings":";;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,SAAS,eAAuB;AAEzB,IAAM,OAAO;AACb,IAAM,SAAS;AA4BtB,eAAsB,uBAAuB;AAAA,EAC3C;AAAA,EACA;AACF,GAGqB;AACnB,SAAO,QAAiB;AAAA,IACtB,KAAK,IAAI,IAAI,MAAM,YAAY,EAAE,SAAS;AAAA,IAC1C;AAAA,EACF,CAAC;AACH;AAXsB;;;AChCtB,SAA0B,kBAAmC;AAO7D,SAAS,WAAAA,gBAAe;AAgCjB,IAAM,YAAY;AAAA,EACvB,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,eAAe;AAAA,EACf,OAAO;AAAA,EACP,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,wBAA+C;AACjD;AAEA,eAAsB,kBAAkB,KAAuC;AAC7E,MAAI;AACF,UAAM,SAAS,IAAI,IAAI,UAAU,QAAQ,GAAG;AAC5C,UAAM,MAAM,MAAMC,SAAyB;AAAA,MACzC,KAAK,OAAO,SAAS;AAAA,IACvB,CAAC;AACD,WAAO;AAAA,EACT,SAAS,KAAK;AACZ,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,SAAS,eAAe,QAAQ,IAAI,UAAU;AAAA,IAChD;AAAA,EACF;AACF;AAbsB;AAetB,eAAsB,aAAa;AAAA,EACjC;AACF,GAEqD;AACnD,MAAI;AACF,UAAM,OAAO,MA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AI,IAAI,UAAU,WAAW,OAAO,EAAE,SAAS;AAAA,IACpD;AAAA,EACF,CAAC;AAED,MAAI,CAAC,KAAK,IAAI;AACZ,UAAM,IAAI,MAAM,2CAA2C,KAAK,OAAO,EAAE;AAAA,EAC3E;AACF;AAnBsB;AAqBtB,eAAsB,iBAAiB;AAAA,EACrC;AAAA,EACA;AACF,GAG2C;AACzC,QAAM,OAAqC;AAAA,IACzC;AAAA,IACA,MAAM,WAAW,QAAQ;AAAA,EAC3B;AACA,QAAM,OAAO,MAAMA,SAAuC;AAAA,IACxD,KAAK,IAAI,IAAI,UAAU,SAAS,YAAY,EAAE,SAAS;AAAA,IACvD;AAAA,EACF,CAAC;AACD,SAAO;AACT;AAhBsB;AAkBtB,eAAsB,eAAe;AAAA,EACnC;AAAA,EACA;AACF,GAG6B;AAC3B,QAAM,OAAO,MAAMA,SAAyB;AAAA,IAC1C,KAAK,IAAI,IAAI,UAAU,QAAQ,YAAY,EAAE,SAAS;AAAA,IACtD,MAAM;AAAA,EACR,CAAC;AACD,SAAO;AACT;AAZsB;","names":["fetcher","fetcher"]}
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.3797.b249674.0",
4
+ "version": "4.70.0--canary.4821.56b0218.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.3797.b249674.0",
25
- "@knapsack/utils": "4.70.0--canary.3797.b249674.0",
24
+ "@knapsack/types": "4.70.0--canary.4821.56b0218.0",
25
+ "@knapsack/utils": "4.70.0--canary.4821.56b0218.0",
26
26
  "cross-fetch": "^4.0.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@knapsack/eslint-config-starter": "4.70.0--canary.3797.b249674.0",
30
- "@knapsack/prettier-config": "4.70.0--canary.3797.b249674.0",
31
- "@knapsack/typescript-config-starter": "4.70.0--canary.3797.b249674.0",
29
+ "@knapsack/eslint-config-starter": "4.70.0--canary.4821.56b0218.0",
30
+ "@knapsack/prettier-config": "4.70.0--canary.4821.56b0218.0",
31
+ "@knapsack/typescript-config-starter": "4.70.0--canary.4821.56b0218.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": "b249674c50182c969f973424bdeae9bc2ba4f49b"
46
+ "gitHead": "56b02187ee87f98fefa3254d2a725a06fc1f13f8"
47
47
  }