@knapsack/app-client-api 4.72.0--canary.4920.be98a9b.0 → 4.72.0--canary.5313.51b7b5f.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,143 @@
1
+ # v4.71.16 (Thu Dec 05 2024)
2
+
3
+ #### 🐛 Bug Fix
4
+
5
+ - refactor React Renderer to use `tsc` for build [#5224](https://github.com/knapsack-labs/app-monorepo/pull/5224) ([@EvanLovely](https://github.com/EvanLovely) [@mabry1985](https://github.com/mabry1985))
6
+
7
+ #### Authors: 2
8
+
9
+ - Evan Lovely ([@EvanLovely](https://github.com/EvanLovely))
10
+ - Josh Mabry ([@mabry1985](https://github.com/mabry1985))
11
+
12
+ ---
13
+
14
+ # v4.71.13 (Wed Dec 04 2024)
15
+
16
+ #### 🐛 Bug Fix
17
+
18
+ - Merge branch 'feature/ksp-5777-gsk-sso-issues' into feature/sso-config-via-db ([@EvanLovely](https://github.com/EvanLovely))
19
+ - Merge branch 'latest' into feature/ksp-5777-gsk-sso-issues ([@illepic](https://github.com/illepic))
20
+ - Bump version to: v4.71.12 \[skip ci\] ([@KnapsackBot](https://github.com/KnapsackBot))
21
+ - Update CHANGELOG.md \[skip ci\] ([@KnapsackBot](https://github.com/KnapsackBot))
22
+ - Bump version to: v4.71.11 \[skip ci\] ([@KnapsackBot](https://github.com/KnapsackBot))
23
+
24
+ #### 🏠 Internal
25
+
26
+ - refactor Cypress user login [#5225](https://github.com/knapsack-labs/app-monorepo/pull/5225) ([@EvanLovely](https://github.com/EvanLovely))
27
+ - Update Node.js to v20.18.1 [#5197](https://github.com/knapsack-labs/app-monorepo/pull/5197) ([@renovate[bot]](https://github.com/renovate[bot]))
28
+ - adds evt handlers for design src logs [#5194](https://github.com/knapsack-labs/app-monorepo/pull/5194) ([@mabry1985](https://github.com/mabry1985))
29
+ - setup login w popup [#5209](https://github.com/knapsack-labs/app-monorepo/pull/5209) ([@GormanDesign](https://github.com/GormanDesign) [@mabry1985](https://github.com/mabry1985) [@EvanLovely](https://github.com/EvanLovely) [@KnapsackBot](https://github.com/KnapsackBot) [@illepic](https://github.com/illepic))
30
+ - migrate to new Figma oAuth endpoints and configuration [#5206](https://github.com/knapsack-labs/app-monorepo/pull/5206) ([@mabry1985](https://github.com/mabry1985))
31
+
32
+ #### Authors: 6
33
+
34
+ - [@renovate[bot]](https://github.com/renovate[bot])
35
+ - Christopher Bloom ([@illepic](https://github.com/illepic))
36
+ - Evan Lovely ([@EvanLovely](https://github.com/EvanLovely))
37
+ - Josh Mabry ([@mabry1985](https://github.com/mabry1985))
38
+ - KnapsackBot ([@KnapsackBot](https://github.com/KnapsackBot))
39
+ - Matt Gorman ([@GormanDesign](https://github.com/GormanDesign))
40
+
41
+ ---
42
+
43
+ # v4.71.12 (Thu Nov 21 2024)
44
+
45
+ #### 🐛 Bug Fix
46
+
47
+ - Fix component alignment in pattern stage and embeds [#5138](https://github.com/knapsack-labs/app-monorepo/pull/5138) ([@GormanDesign](https://github.com/GormanDesign))
48
+ - Merge branch 'latest' into feature/ksp-5732-fix-component-alignment-in-pattern-stage-and-embeds ([@GormanDesign](https://github.com/GormanDesign))
49
+
50
+ #### Authors: 1
51
+
52
+ - Matt Gorman ([@GormanDesign](https://github.com/GormanDesign))
53
+
54
+ ---
55
+
56
+ # v4.71.10 (Thu Nov 21 2024)
57
+
58
+ #### 🐛 Bug Fix
59
+
60
+ - fix prop reordering doesnt stick [#5196](https://github.com/knapsack-labs/app-monorepo/pull/5196) ([@mabry1985](https://github.com/mabry1985))
61
+
62
+ #### Authors: 1
63
+
64
+ - Josh Mabry ([@mabry1985](https://github.com/mabry1985))
65
+
66
+ ---
67
+
68
+ # v4.71.8 (Fri Nov 15 2024)
69
+
70
+ #### 🐛 Bug Fix
71
+
72
+ - Merge branch 'latest' into feature/KSP-5764-add-button-modes ([@brittanysmart](https://github.com/brittanysmart))
73
+ - Merge branch 'latest' into GormanDesign-patch-2 ([@GormanDesign](https://github.com/GormanDesign))
74
+
75
+ #### 🏠 Internal
76
+
77
+ - update gsk-digital-channels sso page content [#5178](https://github.com/knapsack-labs/app-monorepo/pull/5178) ([@GormanDesign](https://github.com/GormanDesign))
78
+ - fix figma tiles show processing message indefinitely [#5179](https://github.com/knapsack-labs/app-monorepo/pull/5179) ([@mabry1985](https://github.com/mabry1985))
79
+
80
+ #### Authors: 3
81
+
82
+ - Brittany Smart ([@brittanysmart](https://github.com/brittanysmart))
83
+ - Josh Mabry ([@mabry1985](https://github.com/mabry1985))
84
+ - Matt Gorman ([@GormanDesign](https://github.com/GormanDesign))
85
+
86
+ ---
87
+
88
+ # v4.71.6 (Thu Nov 14 2024)
89
+
90
+ #### 🐛 Bug Fix
91
+
92
+ - Merge branch 'latest' into feature/ksp-5437-update-auth0-node-sdk ([@freneticpixel](https://github.com/freneticpixel))
93
+ - Merge branch 'latest' into feature/ksp-5710-collections-block-filters ([@GormanDesign](https://github.com/GormanDesign))
94
+ - Merge remote-tracking branch 'origin/latest' into feature/ksp-5437-update-auth0-node-sdk ([@freneticpixel](https://github.com/freneticpixel))
95
+
96
+ #### 🏠 Internal
97
+
98
+ - Update dependency @types/node to ^20.17.6 [#5127](https://github.com/knapsack-labs/app-monorepo/pull/5127) ([@renovate[bot]](https://github.com/renovate[bot]))
99
+
100
+ #### Authors: 3
101
+
102
+ - [@renovate[bot]](https://github.com/renovate[bot])
103
+ - Jim Frenette ([@freneticpixel](https://github.com/freneticpixel))
104
+ - Matt Gorman ([@GormanDesign](https://github.com/GormanDesign))
105
+
106
+ ---
107
+
108
+ # v4.71.5 (Tue Nov 05 2024)
109
+
110
+ #### 🐛 Bug Fix
111
+
112
+ - Merge branch 'latest' into feature/ksp-5668-handle-figma-blocks-when-updating-design-source-file ([@GormanDesign](https://github.com/GormanDesign))
113
+
114
+ #### 🏠 Internal
115
+
116
+ - Update Typescript [#5051](https://github.com/knapsack-labs/app-monorepo/pull/5051) ([@renovate[bot]](https://github.com/renovate[bot]))
117
+ - Update dependency @types/node to ^20.17.5 [#5086](https://github.com/knapsack-labs/app-monorepo/pull/5086) ([@renovate[bot]](https://github.com/renovate[bot]))
118
+ - Update dependency @react-aria/visually-hidden to ^3.8.17 [#5078](https://github.com/knapsack-labs/app-monorepo/pull/5078) ([@renovate[bot]](https://github.com/renovate[bot]))
119
+ - Update dependency @types/node to ^20.17.4 [#5080](https://github.com/knapsack-labs/app-monorepo/pull/5080) ([@renovate[bot]](https://github.com/renovate[bot]))
120
+ - Update dependency @types/node to ^20.17.3 [#5046](https://github.com/knapsack-labs/app-monorepo/pull/5046) ([@renovate[bot]](https://github.com/renovate[bot]))
121
+
122
+ #### Authors: 2
123
+
124
+ - [@renovate[bot]](https://github.com/renovate[bot])
125
+ - Matt Gorman ([@GormanDesign](https://github.com/GormanDesign))
126
+
127
+ ---
128
+
129
+ # v4.71.4 (Tue Oct 29 2024)
130
+
131
+ #### 🏠 Internal
132
+
133
+ - Update dependency @types/node to ^20.17.2 [#5020](https://github.com/knapsack-labs/app-monorepo/pull/5020) ([@renovate[bot]](https://github.com/renovate[bot]))
134
+
135
+ #### Authors: 1
136
+
137
+ - [@renovate[bot]](https://github.com/renovate[bot])
138
+
139
+ ---
140
+
1
141
  # v4.71.2 (Wed Oct 23 2024)
2
142
 
3
143
  #### 🐛 Bug Fix
package/dist/index.js CHANGED
@@ -1,18 +1,2 @@
1
- 'use strict';
2
-
3
- var utils = require('@knapsack/utils');
4
-
5
- var p=Object.defineProperty;var n=(e,t)=>p(e,"name",{value:t,configurable:!0});async function g({appClientUrl:e,query:t}){return utils.fetcher({url:new URL("/api/v1/template-suggestions",e).toString(),query:t})}n(g,"getTemplateSuggestions");async function y(e){try{let t=new URL("/api/v1",e);return await utils.fetcher({url:t.toString()})}catch(t){return {ok:!1,message:t instanceof Error?t.message:"Unknown error"}}}n(y,"checkAppClientUrl");async function d({appClientUrl:e}){try{return {ok:!0,data:await utils.fetcher({url:new URL("/api/v1/data-store",e).toString()})}}catch(t){return {ok:!1,message:t instanceof Error?t.message:"Unknown error"}}}n(d,"getDataStore");async function R({appClientUrl:e}){let t=await d({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}n(R,"getAppClientData");function i(e){let{metaState:t,...a}=e;return a}n(i,"prepAppClientData");async function P({urlBase:e,state:t}){try{let a={state:i(t)};return await utils.fetcher({url:new URL("/api/v1/data-store-prep",e).toString(),body:a})}catch(a){return {ok:!1,message:a instanceof Error?a.message:"Unknown error"}}}n(P,"prepareDataForFileSave");async function D({urlBase:e,state:t}){let r={state:i(t)},o=await utils.fetcher({url:new URL("/api/v1/data-store",e).toString(),body:r});if(!o.ok)throw new Error(`Could not save data to localhost files: ${o.message}`)}n(D,"submitDataForFileSave");async function S({pluginId:e,appClientUrl:t}){return utils.fetcher({url:new URL("/api/v1/plugins",t).toString(),body:{pluginId:e,type:"getContent"}})}n(S,"getPluginContent");async function C({options:e,appClientUrl:t}){return await utils.fetcher({url:new URL("/api/v1/render",t).toString(),body:e})}n(C,"renderTemplate");async function x({appClientUrl:e,payload:t}){return (await utils.fetcher({url:new URL("/api/v1/files",e).toString(),body:{type:"verify",payload:t}})).payload}n(x,"verifyFile");
6
-
7
- exports.checkAppClientUrl = y;
8
- exports.getAppClientData = R;
9
- exports.getDataStore = d;
10
- exports.getPluginContent = S;
11
- exports.getTemplateSuggestions = g;
12
- exports.prepAppClientData = i;
13
- exports.prepareDataForFileSave = P;
14
- exports.renderTemplate = C;
15
- exports.submitDataForFileSave = D;
16
- exports.verifyFile = x;
17
- //# sourceMappingURL=index.js.map
1
+ 'use strict';var utils=require('@knapsack/utils');var p=Object.defineProperty;var n=(e,t)=>p(e,"name",{value:t,configurable:!0});async function g({appClientUrl:e,query:t}){return utils.fetcher({url:new URL("/api/v1/template-suggestions",e).toString(),query:t})}n(g,"getTemplateSuggestions");async function y(e){try{let t=new URL("/api/v1",e);return await utils.fetcher({url:t.toString()})}catch(t){return {ok:!1,message:t instanceof Error?t.message:"Unknown error"}}}n(y,"checkAppClientUrl");async function d({appClientUrl:e}){try{return {ok:!0,data:await utils.fetcher({url:new URL("/api/v1/data-store",e).toString()})}}catch(t){return {ok:!1,message:t instanceof Error?t.message:"Unknown error"}}}n(d,"getDataStore");async function R({appClientUrl:e}){let t=await d({appClientUrl:e});if(!t.ok||!t.data){let a=`We're having trouble accessing your server at ${e}.`;throw new Error(a)}return t.data}n(R,"getAppClientData");function o(e){let{metaState:t,...a}=e;return a}n(o,"prepAppClientData");async function P({urlBase:e,state:t}){try{let a={state:o(t)};return await utils.fetcher({url:new URL("/api/v1/data-store-prep",e).toString(),body:a})}catch(a){return {ok:!1,message:a instanceof Error?a.message:"Unknown error"}}}n(P,"prepareDataForFileSave");async function D({urlBase:e,state:t}){let r={state:o(t)},i=await utils.fetcher({url:new URL("/api/v1/data-store",e).toString(),body:r});if(!i.ok)throw new Error(`Could not save data to localhost files: ${i.message}`)}n(D,"submitDataForFileSave");async function S({pluginId:e,appClientUrl:t}){return utils.fetcher({url:new URL("/api/v1/plugins",t).toString(),body:{pluginId:e,type:"getContent"}})}n(S,"getPluginContent");async function C({options:e,appClientUrl:t}){return await utils.fetcher({url:new URL("/api/v1/render",t).toString(),body:e})}n(C,"renderTemplate");async function v({appClientUrl:e,payload:t}){return (await utils.fetcher({url:new URL("/api/v1/files",e).toString(),body:{type:"verify",payload:t}})).payload}n(v,"verifyFile");exports.checkAppClientUrl=y;exports.getAppClientData=R;exports.getDataStore=d;exports.getPluginContent=S;exports.getTemplateSuggestions=g;exports.prepAppClientData=o;exports.prepareDataForFileSave=P;exports.renderTemplate=C;exports.submitDataForFileSave=D;exports.verifyFile=v;//# sourceMappingURL=index.js.map
18
2
  //# 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":["getTemplateSuggestions","appClientUrl","query","fetcher","__name","checkAppClientUrl","url","theUrl","err","getDataStore","getAppClientData","serverDataRes","message","prepAppClientData","state","metaState","appClientDataNoMeta","prepareDataForFileSave","urlBase","body","submitDataForFileSave","data","getPluginContent","pluginId","renderTemplate","options","verifyFile","payload"],"mappings":";;;;+EAOA,eAAsBA,EAAuB,CAC3C,YAAA,CAAAC,EACA,KAAAC,CAAAA,CACF,EAGwC,CACtC,OAAOC,cAAoC,CACzC,GAAA,CAAK,IAAI,GACP,CAAA,8BAAA,CACAF,CACF,CAAE,CAAA,QAAA,GACF,KAAAC,CAAAA,CACF,CAAC,CACH,CAdsBE,EAAAJ,CAAA,CAAA,wBAAA,CAAA,CCctB,eAAsBK,CAAAA,CAAkBC,EAAuC,CAC7E,GAAI,CACF,IAAMC,CAAAA,CAAS,IAAI,GAAI,CAAA,SAAA,CAAmCD,CAAG,CAI7D,CAAA,OAHY,MAAMH,aAAyB,CAAA,CACzC,IAAKI,CAAO,CAAA,QAAA,EACd,CAAC,CAEH,OAASC,CAAK,CAAA,CACZ,OAAO,CACL,EAAA,CAAI,GACJ,OAASA,CAAAA,CAAAA,YAAe,MAAQA,CAAI,CAAA,OAAA,CAAU,eAChD,CACF,CACF,CAbsBJ,CAAAC,CAAAA,CAAAA,CAAA,qBAetB,eAAsBI,CAAAA,CAAa,CACjC,YAAAR,CAAAA,CACF,EAEqD,CACnD,GAAI,CAQF,OAAO,CACL,GAAI,CACJ,CAAA,CAAA,IAAA,CATW,MAAME,aAAAA,CAAgC,CACjD,GAAA,CAAK,IAAI,GACP,CAAA,oBAAA,CACAF,CACF,CAAE,CAAA,QAAA,EACJ,CAAC,CAKD,CACF,CAASO,MAAAA,CAAAA,CAAK,CACZ,OAAO,CACL,GAAI,CACJ,CAAA,CAAA,OAAA,CAASA,aAAe,KAAQA,CAAAA,CAAAA,CAAI,QAAU,eAChD,CACF,CACF,CAvBsBJ,CAAAA,CAAAK,EAAA,cA0BtB,CAAA,CAAA,eAAsBC,EAAiB,CACrC,YAAA,CAAAT,CACF,CAEoC,CAAA,CAClC,IAAMU,CAAgB,CAAA,MAAMF,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,EAAK,EACR,CAAA,MAAM,IAAI,KAAM,CAAA,CAAA,wCAAA,EAA2CA,EAAK,OAAO,CAAA,CAAE,CAE7E,CAtBsBjB,CAAAgB,CAAAA,CAAAA,CAAA,yBAwBtB,eAAsBE,CAAAA,CAAiB,CACrC,QAAAC,CAAAA,CAAAA,CACA,aAAAtB,CACF,CAAA,CAIE,CACA,OAAOE,aAAAA,CAAQ,CACb,GAAK,CAAA,IAAI,IACP,iBACAF,CAAAA,CACF,EAAE,QAAS,EAAA,CACX,KAAM,CACJ,QAAA,CAAAsB,EACA,IAAM,CAAA,YACR,CACF,CAAC,CACH,CAlBsBnB,CAAAkB,CAAAA,CAAAA,CAAA,oBAoBtB,eAAsBE,CAAAA,CAAe,CACnC,OAAAC,CAAAA,CAAAA,CACA,aAAAxB,CACF,CAAA,CAG6B,CAQ3B,OAPa,MAAME,aAAyB,CAAA,CAC1C,GAAK,CAAA,IAAI,IACP,gBACAF,CAAAA,CACF,EAAE,QAAS,EAAA,CACX,KAAMwB,CACR,CAAC,CAEH,CAfsBrB,CAAAA,CAAAoB,EAAA,gBAiBtB,CAAA,CAAA,eAAsBE,EAAW,CAC/B,YAAA,CAAAzB,EACA,OAAA0B,CAAAA,CACF,EAGG,CAWD,OAAA,CAVa,MAAMxB,aAA+C,CAAA,CAChE,IAAK,IAAI,GAAA,CACP,gBACAF,CACF,CAAA,CAAE,UACF,CAAA,IAAA,CAAM,CACJ,IAAM,CAAA,QAAA,CACN,QAAA0B,CACF,CACF,CAAC,CACW,EAAA,OACd,CAlBsBvB,CAAAA,CAAAsB,CAAA,CAAA,YAAA,CAAA","file":"index.js","sourcesContent":["import type {\n EndpointPaths,\n TemplateSuggestionsReqParams,\n TemplateSuggestionsResBody,\n} from '@knapsack/app/api-info';\nimport { fetcher } from '@knapsack/utils';\n\nexport async function getTemplateSuggestions({\n appClientUrl,\n query,\n}: {\n appClientUrl: string;\n query: TemplateSuggestionsReqParams;\n}): Promise<TemplateSuggestionsResBody> {\n return fetcher<TemplateSuggestionsResBody>({\n url: new URL(\n '/api/v1/template-suggestions' satisfies EndpointPaths,\n appClientUrl,\n ).toString(),\n query,\n });\n}\n","import { KsAppClientData, KsRenderResults } from '@knapsack/types';\nimport type {\n Except,\n GenericResponse,\n KsAppClientDataAndMeta,\n KsAppClientDataNoMeta,\n KsFileSaverParams,\n} from '@knapsack/types';\nimport { fetcher } from '@knapsack/utils';\nimport type {\n PatternRenderData,\n KnapsackDataStoreSaveBody,\n EndpointPaths,\n EndpointFiles,\n ExtractEndpointData,\n ExtractEndpointResBody,\n EndpointPlugins,\n} from '@knapsack/app/api-info';\n\nexport type { PatternRenderData, EndpointPaths };\n\nexport async function checkAppClientUrl(url: string): Promise<GenericResponse> {\n try {\n const theUrl = new URL('/api/v1' satisfies EndpointPaths, 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(\n '/api/v1/data-store' satisfies EndpointPaths,\n appClientUrl,\n ).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(\n '/api/v1/data-store-prep' satisfies EndpointPaths,\n urlBase,\n ).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(\n '/api/v1/data-store' satisfies EndpointPaths,\n urlBase,\n ).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 appClientUrl: string;\n} & Except<ExtractEndpointData<EndpointPlugins>, 'type'>): Promise<\n ExtractEndpointResBody<EndpointPlugins>\n> {\n return fetcher({\n url: new URL(\n '/api/v1/plugins' satisfies EndpointPlugins['path'],\n appClientUrl,\n ).toString(),\n body: {\n pluginId,\n type: 'getContent',\n } satisfies ExtractEndpointData<EndpointPlugins>,\n });\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(\n '/api/v1/render' satisfies EndpointPaths,\n appClientUrl,\n ).toString(),\n body: options,\n });\n return data;\n}\n\nexport async function verifyFile({\n appClientUrl,\n payload,\n}: {\n appClientUrl: string;\n payload: ExtractEndpointData<EndpointFiles>['payload'];\n}) {\n const data = await fetcher<ExtractEndpointResBody<EndpointFiles>>({\n url: new URL(\n '/api/v1/files' satisfies EndpointFiles['path'],\n appClientUrl,\n ).toString(),\n body: {\n type: 'verify',\n payload,\n } satisfies ExtractEndpointData<EndpointFiles>,\n });\n return data.payload;\n}\n"]}
1
+ {"version":3,"sources":["../src/get-template-suggestions.ts","../src/app-client-api.ts"],"names":["getTemplateSuggestions","appClientUrl","query","fetcher","__name","checkAppClientUrl","url","theUrl","err","getDataStore","getAppClientData","serverDataRes","message","prepAppClientData","state","metaState","appClientDataNoMeta","prepareDataForFileSave","urlBase","body","submitDataForFileSave","data","getPluginContent","pluginId","renderTemplate","options","verifyFile","payload"],"mappings":"iIAOA,eAAsBA,EAAuB,CAC3C,YAAA,CAAAC,EACA,KAAAC,CAAAA,CACF,EAGwC,CACtC,OAAOC,cAAoC,CACzC,GAAA,CAAK,IAAI,GACP,CAAA,8BAAA,CACAF,CACF,CAAE,CAAA,QAAA,GACF,KAAAC,CAAAA,CACF,CAAC,CACH,CAdsBE,EAAAJ,CAAA,CAAA,wBAAA,CAAA,CCctB,eAAsBK,CAAAA,CAAkBC,EAAuC,CAC7E,GAAI,CACF,IAAMC,CAAAA,CAAS,IAAI,GAAI,CAAA,SAAA,CAAmCD,CAAG,CAI7D,CAAA,OAHY,MAAMH,aAAyB,CAAA,CACzC,IAAKI,CAAO,CAAA,QAAA,EACd,CAAC,CAEH,OAASC,CAAK,CAAA,CACZ,OAAO,CACL,EAAA,CAAI,GACJ,OAASA,CAAAA,CAAAA,YAAe,MAAQA,CAAI,CAAA,OAAA,CAAU,eAChD,CACF,CACF,CAbsBJ,CAAAC,CAAAA,CAAAA,CAAA,qBAetB,eAAsBI,CAAAA,CAAa,CACjC,YAAAR,CAAAA,CACF,EAEqD,CACnD,GAAI,CAQF,OAAO,CACL,GAAI,CACJ,CAAA,CAAA,IAAA,CATW,MAAME,aAAgC,CAAA,CACjD,IAAK,IAAI,GAAA,CACP,qBACAF,CACF,CAAA,CAAE,UACJ,C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,OACd,CAlBsBvB,CAAAA,CAAAsB,CAAA,CAAA,YAAA,CAAA","file":"index.js","sourcesContent":["import type {\n EndpointPaths,\n TemplateSuggestionsReqParams,\n TemplateSuggestionsResBody,\n} from '@knapsack/app/api-info';\nimport { fetcher } from '@knapsack/utils';\n\nexport async function getTemplateSuggestions({\n appClientUrl,\n query,\n}: {\n appClientUrl: string;\n query: TemplateSuggestionsReqParams;\n}): Promise<TemplateSuggestionsResBody> {\n return fetcher<TemplateSuggestionsResBody>({\n url: new URL(\n '/api/v1/template-suggestions' satisfies EndpointPaths,\n appClientUrl,\n ).toString(),\n query,\n });\n}\n","import { KsAppClientData, KsRenderResults } from '@knapsack/types';\nimport type {\n Except,\n GenericResponse,\n KsAppClientDataAndMeta,\n KsAppClientDataNoMeta,\n KsFileSaverParams,\n} from '@knapsack/types';\nimport { fetcher } from '@knapsack/utils';\nimport type {\n PatternRenderData,\n KnapsackDataStoreSaveBody,\n EndpointPaths,\n EndpointFiles,\n ExtractEndpointData,\n ExtractEndpointResBody,\n EndpointPlugins,\n} from '@knapsack/app/api-info';\n\nexport type { PatternRenderData, EndpointPaths };\n\nexport async function checkAppClientUrl(url: string): Promise<GenericResponse> {\n try {\n const theUrl = new URL('/api/v1' satisfies EndpointPaths, 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(\n '/api/v1/data-store' satisfies EndpointPaths,\n appClientUrl,\n ).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 = `We're having trouble accessing your server at ${appClientUrl}.`;\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(\n '/api/v1/data-store-prep' satisfies EndpointPaths,\n urlBase,\n ).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(\n '/api/v1/data-store' satisfies EndpointPaths,\n urlBase,\n ).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 appClientUrl: string;\n} & Except<ExtractEndpointData<EndpointPlugins>, 'type'>): Promise<\n ExtractEndpointResBody<EndpointPlugins>\n> {\n return fetcher({\n url: new URL(\n '/api/v1/plugins' satisfies EndpointPlugins['path'],\n appClientUrl,\n ).toString(),\n body: {\n pluginId,\n type: 'getContent',\n } satisfies ExtractEndpointData<EndpointPlugins>,\n });\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(\n '/api/v1/render' satisfies EndpointPaths,\n appClientUrl,\n ).toString(),\n body: options,\n });\n return data;\n}\n\nexport async function verifyFile({\n appClientUrl,\n payload,\n}: {\n appClientUrl: string;\n payload: ExtractEndpointData<EndpointFiles>['payload'];\n}) {\n const data = await fetcher<ExtractEndpointResBody<EndpointFiles>>({\n url: new URL(\n '/api/v1/files' satisfies EndpointFiles['path'],\n appClientUrl,\n ).toString(),\n body: {\n type: 'verify',\n payload,\n } satisfies ExtractEndpointData<EndpointFiles>,\n });\n return data.payload;\n}\n"]}
package/dist/index.mjs CHANGED
@@ -1,7 +1,2 @@
1
- import { fetcher } from '@knapsack/utils';
2
-
3
- var p=Object.defineProperty;var n=(e,t)=>p(e,"name",{value:t,configurable:!0});async function g({appClientUrl:e,query:t}){return fetcher({url:new URL("/api/v1/template-suggestions",e).toString(),query:t})}n(g,"getTemplateSuggestions");async function y(e){try{let t=new URL("/api/v1",e);return await fetcher({url:t.toString()})}catch(t){return {ok:!1,message:t instanceof Error?t.message:"Unknown error"}}}n(y,"checkAppClientUrl");async function d({appClientUrl:e}){try{return {ok:!0,data:await fetcher({url:new URL("/api/v1/data-store",e).toString()})}}catch(t){return {ok:!1,message:t instanceof Error?t.message:"Unknown error"}}}n(d,"getDataStore");async function R({appClientUrl:e}){let t=await d({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}n(R,"getAppClientData");function i(e){let{metaState:t,...a}=e;return a}n(i,"prepAppClientData");async function P({urlBase:e,state:t}){try{let a={state:i(t)};return await fetcher({url:new URL("/api/v1/data-store-prep",e).toString(),body:a})}catch(a){return {ok:!1,message:a instanceof Error?a.message:"Unknown error"}}}n(P,"prepareDataForFileSave");async function D({urlBase:e,state:t}){let r={state:i(t)},o=await fetcher({url:new URL("/api/v1/data-store",e).toString(),body:r});if(!o.ok)throw new Error(`Could not save data to localhost files: ${o.message}`)}n(D,"submitDataForFileSave");async function S({pluginId:e,appClientUrl:t}){return fetcher({url:new URL("/api/v1/plugins",t).toString(),body:{pluginId:e,type:"getContent"}})}n(S,"getPluginContent");async function C({options:e,appClientUrl:t}){return await fetcher({url:new URL("/api/v1/render",t).toString(),body:e})}n(C,"renderTemplate");async function x({appClientUrl:e,payload:t}){return (await fetcher({url:new URL("/api/v1/files",e).toString(),body:{type:"verify",payload:t}})).payload}n(x,"verifyFile");
4
-
5
- export { y as checkAppClientUrl, R as getAppClientData, d as getDataStore, S as getPluginContent, g as getTemplateSuggestions, i as prepAppClientData, P as prepareDataForFileSave, C as renderTemplate, D as submitDataForFileSave, x as verifyFile };
6
- //# sourceMappingURL=index.mjs.map
1
+ import {fetcher}from'@knapsack/utils';var p=Object.defineProperty;var n=(e,t)=>p(e,"name",{value:t,configurable:!0});async function g({appClientUrl:e,query:t}){return fetcher({url:new URL("/api/v1/template-suggestions",e).toString(),query:t})}n(g,"getTemplateSuggestions");async function y(e){try{let t=new URL("/api/v1",e);return await fetcher({url:t.toString()})}catch(t){return {ok:!1,message:t instanceof Error?t.message:"Unknown error"}}}n(y,"checkAppClientUrl");async function d({appClientUrl:e}){try{return {ok:!0,data:await fetcher({url:new URL("/api/v1/data-store",e).toString()})}}catch(t){return {ok:!1,message:t instanceof Error?t.message:"Unknown error"}}}n(d,"getDataStore");async function R({appClientUrl:e}){let t=await d({appClientUrl:e});if(!t.ok||!t.data){let a=`We're having trouble accessing your server at ${e}.`;throw new Error(a)}return t.data}n(R,"getAppClientData");function o(e){let{metaState:t,...a}=e;return a}n(o,"prepAppClientData");async function P({urlBase:e,state:t}){try{let a={state:o(t)};return await fetcher({url:new URL("/api/v1/data-store-prep",e).toString(),body:a})}catch(a){return {ok:!1,message:a instanceof Error?a.message:"Unknown error"}}}n(P,"prepareDataForFileSave");async function D({urlBase:e,state:t}){let r={state:o(t)},i=await fetcher({url:new URL("/api/v1/data-store",e).toString(),body:r});if(!i.ok)throw new Error(`Could not save data to localhost files: ${i.message}`)}n(D,"submitDataForFileSave");async function S({pluginId:e,appClientUrl:t}){return fetcher({url:new URL("/api/v1/plugins",t).toString(),body:{pluginId:e,type:"getContent"}})}n(S,"getPluginContent");async function C({options:e,appClientUrl:t}){return await fetcher({url:new URL("/api/v1/render",t).toString(),body:e})}n(C,"renderTemplate");async function v({appClientUrl:e,payload:t}){return (await fetcher({url:new URL("/api/v1/files",e).toString(),body:{type:"verify",payload:t}})).payload}n(v,"verifyFile");export{y as checkAppClientUrl,R as getAppClientData,d as getDataStore,S as getPluginContent,g as getTemplateSuggestions,o as prepAppClientData,P as prepareDataForFileSave,C as renderTemplate,D as submitDataForFileSave,v as verifyFile};//# sourceMappingURL=index.mjs.map
7
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/get-template-suggestions.ts","../src/app-client-api.ts"],"names":["getTemplateSuggestions","appClientUrl","query","fetcher","__name","checkAppClientUrl","url","theUrl","err","getDataStore","getAppClientData","serverDataRes","message","prepAppClientData","state","metaState","appClientDataNoMeta","prepareDataForFileSave","urlBase","body","submitDataForFileSave","data","getPluginContent","pluginId","renderTemplate","options","verifyFile","payload"],"mappings":";;+EAOA,eAAsBA,EAAuB,CAC3C,YAAA,CAAAC,EACA,KAAAC,CAAAA,CACF,EAGwC,CACtC,OAAOC,QAAoC,CACzC,GAAA,CAAK,IAAI,GACP,CAAA,8BAAA,CACAF,CACF,CAAE,CAAA,QAAA,GACF,KAAAC,CAAAA,CACF,CAAC,CACH,CAdsBE,EAAAJ,CAAA,CAAA,wBAAA,CAAA,CCctB,eAAsBK,CAAAA,CAAkBC,EAAuC,CAC7E,GAAI,CACF,IAAMC,CAAAA,CAAS,IAAI,GAAI,CAAA,SAAA,CAAmCD,CAAG,CAI7D,CAAA,OAHY,MAAMH,OAAyB,CAAA,CACzC,IAAKI,CAAO,CAAA,QA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OAAyB,CAAA,CAC1C,GAAK,CAAA,IAAI,IACP,gBACAF,CAAAA,CACF,EAAE,QAAS,EAAA,CACX,KAAMwB,CACR,CAAC,CAEH,CAfsBrB,CAAAA,CAAAoB,EAAA,gBAiBtB,CAAA,CAAA,eAAsBE,EAAW,CAC/B,YAAA,CAAAzB,EACA,OAAA0B,CAAAA,CACF,EAGG,CAWD,OAAA,CAVa,MAAMxB,OAA+C,CAAA,CAChE,IAAK,IAAI,GAAA,CACP,gBACAF,CACF,CAAA,CAAE,UACF,CAAA,IAAA,CAAM,CACJ,IAAM,CAAA,QAAA,CACN,QAAA0B,CACF,CACF,CAAC,CACW,EAAA,OACd,CAlBsBvB,CAAAA,CAAAsB,CAAA,CAAA,YAAA,CAAA","file":"index.mjs","sourcesContent":["import type {\n EndpointPaths,\n TemplateSuggestionsReqParams,\n TemplateSuggestionsResBody,\n} from '@knapsack/app/api-info';\nimport { fetcher } from '@knapsack/utils';\n\nexport async function getTemplateSuggestions({\n appClientUrl,\n query,\n}: {\n appClientUrl: string;\n query: TemplateSuggestionsReqParams;\n}): Promise<TemplateSuggestionsResBody> {\n return fetcher<TemplateSuggestionsResBody>({\n url: new URL(\n '/api/v1/template-suggestions' satisfies EndpointPaths,\n appClientUrl,\n ).toString(),\n query,\n });\n}\n","import { KsAppClientData, KsRenderResults } from '@knapsack/types';\nimport type {\n Except,\n GenericResponse,\n KsAppClientDataAndMeta,\n KsAppClientDataNoMeta,\n KsFileSaverParams,\n} from '@knapsack/types';\nimport { fetcher } from '@knapsack/utils';\nimport type {\n PatternRenderData,\n KnapsackDataStoreSaveBody,\n EndpointPaths,\n EndpointFiles,\n ExtractEndpointData,\n ExtractEndpointResBody,\n EndpointPlugins,\n} from '@knapsack/app/api-info';\n\nexport type { PatternRenderData, EndpointPaths };\n\nexport async function checkAppClientUrl(url: string): Promise<GenericResponse> {\n try {\n const theUrl = new URL('/api/v1' satisfies EndpointPaths, 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(\n '/api/v1/data-store' satisfies EndpointPaths,\n appClientUrl,\n ).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(\n '/api/v1/data-store-prep' satisfies EndpointPaths,\n urlBase,\n ).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(\n '/api/v1/data-store' satisfies EndpointPaths,\n urlBase,\n ).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 appClientUrl: string;\n} & Except<ExtractEndpointData<EndpointPlugins>, 'type'>): Promise<\n ExtractEndpointResBody<EndpointPlugins>\n> {\n return fetcher({\n url: new URL(\n '/api/v1/plugins' satisfies EndpointPlugins['path'],\n appClientUrl,\n ).toString(),\n body: {\n pluginId,\n type: 'getContent',\n } satisfies ExtractEndpointData<EndpointPlugins>,\n });\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(\n '/api/v1/render' satisfies EndpointPaths,\n appClientUrl,\n ).toString(),\n body: options,\n });\n return data;\n}\n\nexport async function verifyFile({\n appClientUrl,\n payload,\n}: {\n appClientUrl: string;\n payload: ExtractEndpointData<EndpointFiles>['payload'];\n}) {\n const data = await fetcher<ExtractEndpointResBody<EndpointFiles>>({\n url: new URL(\n '/api/v1/files' satisfies EndpointFiles['path'],\n appClientUrl,\n ).toString(),\n body: {\n type: 'verify',\n payload,\n } satisfies ExtractEndpointData<EndpointFiles>,\n });\n return data.payload;\n}\n"]}
1
+ {"version":3,"sources":["../src/get-template-suggestions.ts","../src/app-client-api.ts"],"names":["getTemplateSuggestions","appClientUrl","query","fetcher","__name","checkAppClientUrl","url","theUrl","err","getDataStore","getAppClientData","serverDataRes","message","prepAppClientData","state","metaState","appClientDataNoMeta","prepareDataForFileSave","urlBase","body","submitDataForFileSave","data","getPluginContent","pluginId","renderTemplate","options","verifyFile","payload"],"mappings":"qHAOA,eAAsBA,EAAuB,CAC3C,YAAA,CAAAC,EACA,KAAAC,CAAAA,CACF,EAGwC,CACtC,OAAOC,QAAoC,CACzC,GAAA,CAAK,I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AA,CACb,IAAK,IAAI,GAAA,CACP,kBACAF,CACF,CAAA,CAAE,UACF,CAAA,IAAA,CAAM,CACJ,QAAAsB,CAAAA,CAAAA,CACA,KAAM,YACR,CACF,CAAC,CACH,CAlBsBnB,EAAAkB,CAAA,CAAA,kBAAA,CAAA,CAoBtB,eAAsBE,CAAe,CAAA,CACnC,QAAAC,CACA,CAAA,YAAA,CAAAxB,CACF,CAG6B,CAAA,CAQ3B,OAPa,MAAME,OAAAA,CAAyB,CAC1C,GAAK,CAAA,IAAI,IACP,gBACAF,CAAAA,CACF,EAAE,QAAS,EAAA,CACX,KAAMwB,CACR,CAAC,CAEH,CAfsBrB,CAAAA,CAAAoB,EAAA,gBAiBtB,CAAA,CAAA,eAAsBE,EAAW,CAC/B,YAAA,CAAAzB,EACA,OAAA0B,CAAAA,CACF,EAGG,CAWD,OAAA,CAVa,MAAMxB,OAA+C,CAAA,CAChE,IAAK,IAAI,GAAA,CACP,gBACAF,CACF,CAAA,CAAE,UACF,CAAA,IAAA,CAAM,CACJ,IAAM,CAAA,QAAA,CACN,QAAA0B,CACF,CACF,CAAC,CACW,EAAA,OACd,CAlBsBvB,CAAAA,CAAAsB,CAAA,CAAA,YAAA,CAAA","file":"index.mjs","sourcesContent":["import type {\n EndpointPaths,\n TemplateSuggestionsReqParams,\n TemplateSuggestionsResBody,\n} from '@knapsack/app/api-info';\nimport { fetcher } from '@knapsack/utils';\n\nexport async function getTemplateSuggestions({\n appClientUrl,\n query,\n}: {\n appClientUrl: string;\n query: TemplateSuggestionsReqParams;\n}): Promise<TemplateSuggestionsResBody> {\n return fetcher<TemplateSuggestionsResBody>({\n url: new URL(\n '/api/v1/template-suggestions' satisfies EndpointPaths,\n appClientUrl,\n ).toString(),\n query,\n });\n}\n","import { KsAppClientData, KsRenderResults } from '@knapsack/types';\nimport type {\n Except,\n GenericResponse,\n KsAppClientDataAndMeta,\n KsAppClientDataNoMeta,\n KsFileSaverParams,\n} from '@knapsack/types';\nimport { fetcher } from '@knapsack/utils';\nimport type {\n PatternRenderData,\n KnapsackDataStoreSaveBody,\n EndpointPaths,\n EndpointFiles,\n ExtractEndpointData,\n ExtractEndpointResBody,\n EndpointPlugins,\n} from '@knapsack/app/api-info';\n\nexport type { PatternRenderData, EndpointPaths };\n\nexport async function checkAppClientUrl(url: string): Promise<GenericResponse> {\n try {\n const theUrl = new URL('/api/v1' satisfies EndpointPaths, 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(\n '/api/v1/data-store' satisfies EndpointPaths,\n appClientUrl,\n ).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 = `We're having trouble accessing your server at ${appClientUrl}.`;\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(\n '/api/v1/data-store-prep' satisfies EndpointPaths,\n urlBase,\n ).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(\n '/api/v1/data-store' satisfies EndpointPaths,\n urlBase,\n ).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 appClientUrl: string;\n} & Except<ExtractEndpointData<EndpointPlugins>, 'type'>): Promise<\n ExtractEndpointResBody<EndpointPlugins>\n> {\n return fetcher({\n url: new URL(\n '/api/v1/plugins' satisfies EndpointPlugins['path'],\n appClientUrl,\n ).toString(),\n body: {\n pluginId,\n type: 'getContent',\n } satisfies ExtractEndpointData<EndpointPlugins>,\n });\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(\n '/api/v1/render' satisfies EndpointPaths,\n appClientUrl,\n ).toString(),\n body: options,\n });\n return data;\n}\n\nexport async function verifyFile({\n appClientUrl,\n payload,\n}: {\n appClientUrl: string;\n payload: ExtractEndpointData<EndpointFiles>['payload'];\n}) {\n const data = await fetcher<ExtractEndpointResBody<EndpointFiles>>({\n url: new URL(\n '/api/v1/files' satisfies EndpointFiles['path'],\n appClientUrl,\n ).toString(),\n body: {\n type: 'verify',\n payload,\n } satisfies ExtractEndpointData<EndpointFiles>,\n });\n return data.payload;\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.72.0--canary.4920.be98a9b.0",
4
+ "version": "4.72.0--canary.5313.51b7b5f.0",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",
@@ -21,18 +21,18 @@
21
21
  "lint": "eslint ./"
22
22
  },
23
23
  "dependencies": {
24
- "@knapsack/app": "4.72.0--canary.4920.be98a9b.0",
25
- "@knapsack/types": "4.72.0--canary.4920.be98a9b.0",
26
- "@knapsack/utils": "4.72.0--canary.4920.be98a9b.0",
24
+ "@knapsack/app": "4.72.0--canary.5313.51b7b5f.0",
25
+ "@knapsack/types": "4.72.0--canary.5313.51b7b5f.0",
26
+ "@knapsack/utils": "4.72.0--canary.5313.51b7b5f.0",
27
27
  "cross-fetch": "^4.0.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@knapsack/eslint-config-starter": "4.72.0--canary.4920.be98a9b.0",
31
- "@knapsack/prettier-config": "4.72.0--canary.4920.be98a9b.0",
32
- "@knapsack/typescript-config-starter": "4.72.0--canary.4920.be98a9b.0",
33
- "@types/node": "^20.17.2",
30
+ "@knapsack/eslint-config-starter": "4.72.0--canary.5313.51b7b5f.0",
31
+ "@knapsack/prettier-config": "4.72.0--canary.5313.51b7b5f.0",
32
+ "@knapsack/typescript-config-starter": "4.72.0--canary.5313.51b7b5f.0",
33
+ "@types/node": "^20.17.8",
34
34
  "eslint": "^8.57.0",
35
- "tsup": "^8.3.0",
35
+ "tsup": "^8.3.5",
36
36
  "typescript": "^5.6.3"
37
37
  },
38
38
  "license": "GPL-2.0-or-later",
@@ -44,5 +44,5 @@
44
44
  "directory": "libs/app-client-api",
45
45
  "type": "git"
46
46
  },
47
- "gitHead": "be98a9b39ed70c97fd88e8359e5420250a582b6f"
47
+ "gitHead": "51b7b5f2b8e4a42f078030647178769053559d32"
48
48
  }