@knapsack/app-client-api 4.71.1 → 4.71.2

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # v4.71.2 (Wed Oct 23 2024)
2
+
3
+ #### 🐛 Bug Fix
4
+
5
+ - refactor App Client API types approach KSP-5612 [#4921](https://github.com/knapsack-labs/app-monorepo/pull/4921) ([@EvanLovely](https://github.com/EvanLovely))
6
+
7
+ #### Authors: 1
8
+
9
+ - Evan Lovely ([@EvanLovely](https://github.com/EvanLovely))
10
+
11
+ ---
12
+
1
13
  # v4.71.1 (Wed Oct 23 2024)
2
14
 
3
15
  #### 🐛 Bug Fix
@@ -1,42 +1,7 @@
1
- import { KsAppClientData, PluginsApi, KsRenderResults } from '@knapsack/types';
2
- import type { GenericResponse, KsAppClientDataAndMeta, KsAppClientDataNoMeta, KsFileSaverParams } from '@knapsack/types';
3
- export interface KnapsackDataStoreSaveBody {
4
- state: KsAppClientData;
5
- }
6
- export type PatternRenderDataWithDemoId = {
7
- patternId: string;
8
- templateId: string;
9
- assetSetId: string;
10
- demoId: string;
11
- };
12
- export type PatternRenderData = {
13
- patternId: string;
14
- templateId: string;
15
- assetSetId?: string;
16
- wrapHtml?: boolean;
17
- isInIframe?: boolean;
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;
28
- };
29
- export declare const ENDPOINTS: {
30
- health: string;
31
- dataStore: string;
32
- dataStorePrep: string;
33
- files: string;
34
- data: string;
35
- render: string;
36
- upload: string;
37
- plugins: string;
38
- getTemplateSuggestions: string;
39
- };
1
+ import { KsAppClientData, KsRenderResults } from '@knapsack/types';
2
+ import type { Except, GenericResponse, KsAppClientDataAndMeta, KsAppClientDataNoMeta, KsFileSaverParams } from '@knapsack/types';
3
+ import type { PatternRenderData, EndpointPaths, EndpointFiles, ExtractEndpointData, ExtractEndpointResBody, EndpointPlugins } from '@knapsack/app/api-info';
4
+ export type { PatternRenderData, EndpointPaths };
40
5
  export declare function checkAppClientUrl(url: string): Promise<GenericResponse>;
41
6
  export declare function getDataStore({ appClientUrl, }: {
42
7
  appClientUrl: string;
@@ -55,11 +20,19 @@ export declare function submitDataForFileSave({ urlBase, state, }: {
55
20
  state: KsAppClientDataNoMeta;
56
21
  }): Promise<void>;
57
22
  export declare function getPluginContent({ pluginId, appClientUrl, }: {
58
- pluginId: string;
59
23
  appClientUrl: string;
60
- }): Promise<PluginsApi.GetContentResponse>;
24
+ } & Except<ExtractEndpointData<EndpointPlugins>, 'type'>): Promise<ExtractEndpointResBody<EndpointPlugins>>;
61
25
  export declare function renderTemplate({ options, appClientUrl, }: {
62
26
  options: PatternRenderData;
63
27
  appClientUrl: string;
64
28
  }): Promise<KsRenderResults>;
29
+ export declare function verifyFile({ appClientUrl, payload, }: {
30
+ appClientUrl: string;
31
+ payload: ExtractEndpointData<EndpointFiles>['payload'];
32
+ }): Promise<{
33
+ exists: boolean;
34
+ relativePath: string;
35
+ absolutePath: string;
36
+ type: "absolute" | "relative" | "package" | "unknown";
37
+ }>;
65
38
  //# sourceMappingURL=app-client-api.d.ts.map
@@ -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;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB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AE,MAAM,CAAC;IAChB,KAAK,EAAE,qBAAqB,CAAC;CAC9B,GAAG,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC,CAoB9C;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,CAgBhB;AAED,wBAAsB,gBAAgB,CAAC,EACrC,QAAQ,EACR,YAAY,GACb,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,MAAM,CAAC,mBAAmB,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC,GAAG,OAAO,CAChE,sBAAsB,CAAC,eAAe,CAAC,CACxC,CAWA;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,CAS3B;AAED,wBAAsB,UAAU,CAAC,EAC/B,YAAY,EACZ,OAAO,GACR,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,mBAAmB,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC,CAAC;CACxD;;;;;GAYA"}
@@ -1,28 +1,6 @@
1
- import type { TemplateSuggestionsGetFn } from '@knapsack/types';
2
- import { Except } from '@knapsack/utils';
3
- export declare const path = "/api/v1/template-suggestions";
4
- export declare const method = "GET";
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
- };
11
- export type ResBody = {
12
- type: 'success';
13
- data: Awaited<ReturnType<TemplateSuggestionsGetFn>>;
14
- } | {
15
- type: 'error.invalidParams';
16
- message: string;
17
- } | {
18
- type: 'error.pathNotFound';
19
- message: string;
20
- } | {
21
- type: 'error.couldNotParse';
22
- message: string;
23
- };
1
+ import type { TemplateSuggestionsReqParams, TemplateSuggestionsResBody } from '@knapsack/app/api-info';
24
2
  export declare function getTemplateSuggestions({ appClientUrl, query, }: {
25
3
  appClientUrl: string;
26
- query: ReqParams;
27
- }): Promise<ResBody>;
4
+ query: TemplateSuggestionsReqParams;
5
+ }): Promise<TemplateSuggestionsResBody>;
28
6
  //# sourceMappingURL=get-template-suggestions.d.ts.map
@@ -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;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"}
1
+ {"version":3,"file":"get-template-suggestions.d.ts","sourceRoot":"","sources":["../src/get-template-suggestions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,4BAA4B,EAC5B,0BAA0B,EAC3B,MAAM,wBAAwB,CAAC;AAGhC,wBAAsB,sBAAsB,CAAC,EAC3C,YAAY,EACZ,KAAK,GACN,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,4BAA4B,CAAC;CACrC,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAQtC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import * as getTemplateSuggestions from './get-template-suggestions';
2
- export { getTemplateSuggestions };
1
+ export * from './get-template-suggestions';
3
2
  export * from './app-client-api';
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,sBAAsB,MAAM,4BAA4B,CAAC;AAErE,OAAO,EAAE,sBAAsB,EAAE,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -1,19 +1,18 @@
1
1
  'use strict';
2
2
 
3
3
  var utils = require('@knapsack/utils');
4
- var types = require('@knapsack/types');
5
4
 
6
- var g=Object.defineProperty;var r=(e,t)=>g(e,"name",{value:t,configurable:!0});var c=(e,t)=>{for(var a in t)g(e,a,{get:t[a],enumerable:!0});};var i={};c(i,{getTemplateSuggestions:()=>S,method:()=>m,path:()=>o});var o="/api/v1/template-suggestions",m="GET";async function S({appClientUrl:e,query:t}){return utils.fetcher({url:new URL(o,e).toString(),query:t})}r(S,"getTemplateSuggestions");var s={health:"/api/v1/",dataStore:"/api/v1/data-store",dataStorePrep:"/api/v1/data-store-prep",files:"/api/v1/files",data:"/api/v1/data",render:"/api/v1/render",upload:"/api/v1/upload",plugins:"/api/v1/plugins",getTemplateSuggestions:o};async function h(e){try{let t=new URL(s.health,e);return await utils.fetcher({url:t.toString()})}catch(t){return {ok:!1,message:t instanceof Error?t.message:"Unknown error"}}}r(h,"checkAppClientUrl");async function f({appClientUrl:e}){try{return {ok:!0,data:await utils.fetcher({url:new URL(s.dataStore,e).toString()})}}catch(t){return {ok:!1,message:t instanceof Error?t.message:"Unknown error"}}}r(f,"getDataStore");async function K({appClientUrl:e}){let t=await f({appClientUrl:e});if(!t.ok||!t.data){let a=`Could not load data from custom url "${e}" ${t.message}`;throw new Error(a)}return t.data}r(K,"getAppClientData");function d(e){let{metaState:t,...a}=e;return a}r(d,"prepAppClientData");async function k({urlBase:e,state:t}){try{let a={state:d(t)};return await utils.fetcher({url:new URL(s.dataStorePrep,e).toString(),body:a})}catch(a){return {ok:!1,message:a instanceof Error?a.message:"Unknown error"}}}r(k,"prepareDataForFileSave");async function I({urlBase:e,state:t}){let p={state:d(t)},l=await utils.fetcher({url:new URL(s.dataStore,e).toString(),body:p});if(!l.ok)throw new Error(`Could not save data to localhost files: ${l.message}`)}r(I,"submitDataForFileSave");async function U({pluginId:e,appClientUrl:t}){let a={pluginId:e,type:types.PluginsApi.ACTIONS.getContent};return await utils.fetcher({url:new URL(s.plugins,t).toString(),body:a})}r(U,"getPluginContent");async function G({options:e,appClientUrl:t}){return await utils.fetcher({url:new URL(s.render,t).toString(),body:e})}r(G,"renderTemplate");
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");
7
6
 
8
- exports.ENDPOINTS = s;
9
- exports.checkAppClientUrl = h;
10
- exports.getAppClientData = K;
11
- exports.getDataStore = f;
12
- exports.getPluginContent = U;
13
- exports.getTemplateSuggestions = i;
14
- exports.prepAppClientData = d;
15
- exports.prepareDataForFileSave = k;
16
- exports.renderTemplate = G;
17
- exports.submitDataForFileSave = I;
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;
18
17
  //# sourceMappingURL=index.js.map
19
18
  //# 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,CA4BtB,eAAsBD,CAAAA,CAAuB,CAC3C,YAAA,CAAAG,EACA,KAAAC,CAAAA,CACF,EAGqB,CACnB,OAAOC,cAAiB,CACtB,GAAA,CAAK,IAAI,GAAA,CAAIH,CAAMC,CAAAA,CAAY,EAAE,QAAS,EAAA,CAC1C,MAAAC,CACF,CAAC,CACH,CAXsBE,CAAAA,CAAAN,CAAA,CAAA,wBAAA,CAAA,KCOTO,CAAY,CAAA,CACvB,OAAQ,UACR,CAAA,SAAA,CAAW,qBACX,aAAe,CAAA,yBAAA,CACf,MAAO,eACP,CAAA,IAAA,CAAM,eACN,MAAQ,CAAA,gBAAA,CACR,MAAQ,CAAA,gBAAA,CACR,OAAS,CAAA,iBAAA,CACT,uBAA+CL,CACjD,EAEA,eAAsBM,CAAkBC,CAAAA,CAAAA,CAAuC,CAC7E,GAAI,CACF,IAAMC,CAAAA,CAAS,IAAI,GAAA,CAAIH,EAAU,MAAQE,CAAAA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,CAKA,OAJa,MAAMtB,aAAAA,CAAuC,CACxD,GAAK,CAAA,IAAI,IAAIE,CAAU,CAAA,OAAA,CAASJ,CAAY,CAAE,CAAA,QAAA,GAC9C,IAAAmB,CAAAA,CACF,CAAC,CAEH,CAhBsBhB,EAAAmB,CAAA,CAAA,kBAAA,CAAA,CAkBtB,eAAsBG,CAAAA,CAAe,CACnC,OAAA,CAAAC,EACA,YAAA1B,CAAAA,CACF,EAG6B,CAK3B,OAJa,MAAME,aAAyB,CAAA,CAC1C,GAAK,CAAA,IAAI,GAAIE,CAAAA,CAAAA,CAAU,OAAQJ,CAAY,CAAA,CAAE,UAC7C,CAAA,IAAA,CAAM0B,CACR,CAAC,CAEH,CAZsBvB,CAAAA,CAAAsB,CAAA,CAAA,gBAAA,CAAA","file":"index.js","sourcesContent":["import type { TemplateSuggestionsGetFn } from '@knapsack/types';\nimport { fetcher, Except } from '@knapsack/utils';\n\nexport const path = '/api/v1/template-suggestions';\nexport const method = 'GET';\nexport type ReqParams = Except<\n Parameters<TemplateSuggestionsGetFn>[0],\n 'state'\n> & {\n /**\n * ID from saving {@link ContentStateForRendering} to `api.knapsack.cloud/render-data\n */\n stateId: string;\n};\nexport type ResBody =\n | {\n type: 'success';\n data: Awaited<ReturnType<TemplateSuggestionsGetFn>>;\n }\n | {\n type: 'error.invalidParams';\n message: string;\n }\n | {\n type: 'error.pathNotFound';\n message: string;\n }\n | {\n type: 'error.couldNotParse';\n message: string;\n };\n\nexport async function getTemplateSuggestions({\n appClientUrl,\n query,\n}: {\n appClientUrl: string;\n query: ReqParams;\n}): Promise<ResBody> {\n return fetcher<ResBody>({\n url: new URL(path, appClientUrl).toString(),\n query,\n });\n}\n","import { KsAppClientData, PluginsApi, KsRenderResults } from '@knapsack/types';\nimport type {\n GenericResponse,\n KsAppClientDataAndMeta,\n KsAppClientDataNoMeta,\n KsFileSaverParams,\n} from '@knapsack/types';\nimport { fetcher } from '@knapsack/utils';\nimport * as getTemplateSuggestions from './get-template-suggestions';\n\nexport interface KnapsackDataStoreSaveBody {\n state: KsAppClientData;\n}\n\nexport type PatternRenderDataWithDemoId = {\n patternId: string;\n templateId: string;\n assetSetId: string;\n demoId: string;\n};\n\nexport type PatternRenderData = {\n patternId: string;\n templateId: string;\n assetSetId?: string;\n wrapHtml?: boolean;\n isInIframe?: boolean;\n cacheBuster?: string;\n /**\n * Data id for Demo from `saveData()`\n * @see {@link Demo}\n */\n dataId: string;\n /**\n * ID for @see {ContentStateForRendering}\n */\n stateId: string;\n};\n\nexport const ENDPOINTS = {\n health: '/api/v1/',\n dataStore: '/api/v1/data-store',\n dataStorePrep: '/api/v1/data-store-prep',\n files: '/api/v1/files',\n data: '/api/v1/data',\n render: '/api/v1/render',\n upload: '/api/v1/upload',\n plugins: '/api/v1/plugins',\n getTemplateSuggestions: getTemplateSuggestions.path,\n};\n\nexport async function checkAppClientUrl(url: string): Promise<GenericResponse> {\n try {\n const theUrl = new URL(ENDPOINTS.health, url); // will throw if url not formatted correctly\n const res = await fetcher<GenericResponse>({\n url: theUrl.toString(),\n });\n return res;\n } catch (err) {\n return {\n ok: false,\n message: err instanceof Error ? err.message : 'Unknown error',\n };\n }\n}\n\nexport async function getDataStore({\n appClientUrl,\n}: {\n appClientUrl: string;\n}): Promise<GenericResponse<KsAppClientDataAndMeta>> {\n try {\n const data = await fetcher<KsAppClientDataAndMeta>({\n url: new URL(ENDPOINTS.dataStore, appClientUrl).toString(),\n });\n\n return {\n ok: true,\n data,\n };\n } catch (err) {\n return {\n ok: false,\n message: err instanceof Error ? err.message : 'Unknown error',\n };\n }\n}\n\n// just need a function that can throw an error\nexport async function getAppClientData({\n appClientUrl,\n}: {\n appClientUrl: string;\n}): Promise<KsAppClientDataAndMeta> {\n const serverDataRes = await getDataStore({ appClientUrl });\n if (!serverDataRes.ok || !serverDataRes.data) {\n const message = `Could not load data from custom url \"${appClientUrl}\" ${serverDataRes.message}`;\n throw new Error(message);\n }\n return serverDataRes.data;\n}\n\n/** Sole job is to strip `metaState` if it's there */\nexport function prepAppClientData(\n state: KsAppClientData,\n): KsAppClientDataNoMeta {\n const { metaState, ...appClientDataNoMeta } = state;\n return appClientDataNoMeta;\n}\n\nexport async function prepareDataForFileSave({\n urlBase,\n state,\n}: {\n urlBase: string;\n state: KsAppClientDataNoMeta;\n}): Promise<GenericResponse<KsFileSaverParams>> {\n try {\n const body: KnapsackDataStoreSaveBody = {\n state: prepAppClientData(state),\n };\n const data = await fetcher<GenericResponse<KsFileSaverParams>>({\n url: new URL(ENDPOINTS.dataStorePrep, urlBase).toString(),\n body,\n });\n\n return data;\n } catch (err) {\n return {\n ok: false,\n message: err instanceof Error ? err.message : 'Unknown error',\n };\n }\n}\n\nexport async function submitDataForFileSave({\n urlBase,\n state,\n}: {\n urlBase: string;\n state: KsAppClientDataNoMeta;\n}): Promise<void> {\n const appClientData = prepAppClientData(state);\n const body: KnapsackDataStoreSaveBody = {\n state: appClientData,\n };\n const data = await fetcher<GenericResponse>({\n url: new URL(ENDPOINTS.dataStore, urlBase).toString(),\n body,\n });\n\n if (!data.ok) {\n throw new Error(`Could not save data to localhost files: ${data.message}`);\n }\n}\n\nexport async function getPluginContent({\n pluginId,\n appClientUrl,\n}: {\n pluginId: string;\n appClientUrl: string;\n}): Promise<PluginsApi.GetContentResponse> {\n const body: PluginsApi.GetContentRequest = {\n pluginId,\n type: PluginsApi.ACTIONS.getContent,\n };\n const data = await fetcher<PluginsApi.GetContentResponse>({\n url: new URL(ENDPOINTS.plugins, appClientUrl).toString(),\n body,\n });\n return data;\n}\n\nexport async function renderTemplate({\n options,\n appClientUrl,\n}: {\n options: PatternRenderData;\n appClientUrl: string;\n}): Promise<KsRenderResults> {\n const data = await fetcher<KsRenderResults>({\n url: new URL(ENDPOINTS.render, appClientUrl).toString(),\n body: options,\n });\n return data;\n}\n"]}
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,CAE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AAA,CACX,KAAAC,CACF,CAAC,EAED,GAAI,CAACE,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"]}
package/dist/index.mjs CHANGED
@@ -1,8 +1,7 @@
1
1
  import { fetcher } from '@knapsack/utils';
2
- import { PluginsApi } from '@knapsack/types';
3
2
 
4
- var g=Object.defineProperty;var r=(e,t)=>g(e,"name",{value:t,configurable:!0});var c=(e,t)=>{for(var a in t)g(e,a,{get:t[a],enumerable:!0});};var i={};c(i,{getTemplateSuggestions:()=>S,method:()=>m,path:()=>o});var o="/api/v1/template-suggestions",m="GET";async function S({appClientUrl:e,query:t}){return fetcher({url:new URL(o,e).toString(),query:t})}r(S,"getTemplateSuggestions");var s={health:"/api/v1/",dataStore:"/api/v1/data-store",dataStorePrep:"/api/v1/data-store-prep",files:"/api/v1/files",data:"/api/v1/data",render:"/api/v1/render",upload:"/api/v1/upload",plugins:"/api/v1/plugins",getTemplateSuggestions:o};async function h(e){try{let t=new URL(s.health,e);return await fetcher({url:t.toString()})}catch(t){return {ok:!1,message:t instanceof Error?t.message:"Unknown error"}}}r(h,"checkAppClientUrl");async function f({appClientUrl:e}){try{return {ok:!0,data:await fetcher({url:new URL(s.dataStore,e).toString()})}}catch(t){return {ok:!1,message:t instanceof Error?t.message:"Unknown error"}}}r(f,"getDataStore");async function K({appClientUrl:e}){let t=await f({appClientUrl:e});if(!t.ok||!t.data){let a=`Could not load data from custom url "${e}" ${t.message}`;throw new Error(a)}return t.data}r(K,"getAppClientData");function d(e){let{metaState:t,...a}=e;return a}r(d,"prepAppClientData");async function k({urlBase:e,state:t}){try{let a={state:d(t)};return await fetcher({url:new URL(s.dataStorePrep,e).toString(),body:a})}catch(a){return {ok:!1,message:a instanceof Error?a.message:"Unknown error"}}}r(k,"prepareDataForFileSave");async function I({urlBase:e,state:t}){let p={state:d(t)},l=await fetcher({url:new URL(s.dataStore,e).toString(),body:p});if(!l.ok)throw new Error(`Could not save data to localhost files: ${l.message}`)}r(I,"submitDataForFileSave");async function U({pluginId:e,appClientUrl:t}){let a={pluginId:e,type:PluginsApi.ACTIONS.getContent};return await fetcher({url:new URL(s.plugins,t).toString(),body:a})}r(U,"getPluginContent");async function G({options:e,appClientUrl:t}){return await fetcher({url:new URL(s.render,t).toString(),body:e})}r(G,"renderTemplate");
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");
5
4
 
6
- export { s as ENDPOINTS, h as checkAppClientUrl, K as getAppClientData, f as getDataStore, U as getPluginContent, i as getTemplateSuggestions, d as prepAppClientData, k as prepareDataForFileSave, G as renderTemplate, I as submitDataForFileSave };
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 };
7
6
  //# sourceMappingURL=index.mjs.map
8
7
  //# 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,CA4BtB,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,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,EACR,CAAA,MAAM,IAAI,KAAA,CAAM,CAA2CA,wCAAAA,EAAAA,CAAAA,CAAK,OAAO,CAAE,CAAA,CAE7E,CAnBsBlB,CAAAiB,CAAAA,CAAAA,CAAA,yBAqBtB,eAAsBE,CAAAA,CAAiB,CACrC,QAAA,CAAAC,CACA,CAAA,YAAA,CAAAvB,CACF,CAG2C,CAAA,CACzC,IAAMmB,CAAqC,CAAA,CACzC,SAAAI,CACA,CAAA,IAAA,CAAMC,UAAW,CAAA,OAAA,CAAQ,UAC3B,CAAA,CAKA,OAJa,MAAMtB,OAAAA,CAAuC,CACxD,GAAK,CAAA,IAAI,IAAIE,CAAU,CAAA,OAAA,CAASJ,CAAY,CAAE,CAAA,QAAA,GAC9C,IAAAmB,CAAAA,CACF,CAAC,CAEH,CAhBsBhB,EAAAmB,CAAA,CAAA,kBAAA,CAAA,CAkBtB,eAAsBG,CAAAA,CAAe,CACnC,OAAA,CAAAC,EACA,YAAA1B,CAAAA,CACF,EAG6B,CAK3B,OAJa,MAAME,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, Except } from '@knapsack/utils';\n\nexport const path = '/api/v1/template-suggestions';\nexport const method = 'GET';\nexport type ReqParams = Except<\n Parameters<TemplateSuggestionsGetFn>[0],\n 'state'\n> & {\n /**\n * ID from saving {@link ContentStateForRendering} to `api.knapsack.cloud/render-data\n */\n stateId: string;\n};\nexport type ResBody =\n | {\n type: 'success';\n data: Awaited<ReturnType<TemplateSuggestionsGetFn>>;\n }\n | {\n type: 'error.invalidParams';\n message: string;\n }\n | {\n type: 'error.pathNotFound';\n message: string;\n }\n | {\n type: 'error.couldNotParse';\n message: string;\n };\n\nexport async function getTemplateSuggestions({\n appClientUrl,\n query,\n}: {\n appClientUrl: string;\n query: ReqParams;\n}): Promise<ResBody> {\n return fetcher<ResBody>({\n url: new URL(path, appClientUrl).toString(),\n query,\n });\n}\n","import { KsAppClientData, PluginsApi, KsRenderResults } from '@knapsack/types';\nimport type {\n GenericResponse,\n KsAppClientDataAndMeta,\n KsAppClientDataNoMeta,\n KsFileSaverParams,\n} from '@knapsack/types';\nimport { fetcher } from '@knapsack/utils';\nimport * as getTemplateSuggestions from './get-template-suggestions';\n\nexport interface KnapsackDataStoreSaveBody {\n state: KsAppClientData;\n}\n\nexport type PatternRenderDataWithDemoId = {\n patternId: string;\n templateId: string;\n assetSetId: string;\n demoId: string;\n};\n\nexport type PatternRenderData = {\n patternId: string;\n templateId: string;\n assetSetId?: string;\n wrapHtml?: boolean;\n isInIframe?: boolean;\n cacheBuster?: string;\n /**\n * Data id for Demo from `saveData()`\n * @see {@link Demo}\n */\n dataId: string;\n /**\n * ID for @see {ContentStateForRendering}\n */\n stateId: string;\n};\n\nexport const ENDPOINTS = {\n health: '/api/v1/',\n dataStore: '/api/v1/data-store',\n dataStorePrep: '/api/v1/data-store-prep',\n files: '/api/v1/files',\n data: '/api/v1/data',\n render: '/api/v1/render',\n upload: '/api/v1/upload',\n plugins: '/api/v1/plugins',\n getTemplateSuggestions: getTemplateSuggestions.path,\n};\n\nexport async function checkAppClientUrl(url: string): Promise<GenericResponse> {\n try {\n const theUrl = new URL(ENDPOINTS.health, url); // will throw if url not formatted correctly\n const res = await fetcher<GenericResponse>({\n url: theUrl.toString(),\n });\n return res;\n } catch (err) {\n return {\n ok: false,\n message: err instanceof Error ? err.message : 'Unknown error',\n };\n }\n}\n\nexport async function getDataStore({\n appClientUrl,\n}: {\n appClientUrl: string;\n}): Promise<GenericResponse<KsAppClientDataAndMeta>> {\n try {\n const data = await fetcher<KsAppClientDataAndMeta>({\n url: new URL(ENDPOINTS.dataStore, appClientUrl).toString(),\n });\n\n return {\n ok: true,\n data,\n };\n } catch (err) {\n return {\n ok: false,\n message: err instanceof Error ? err.message : 'Unknown error',\n };\n }\n}\n\n// just need a function that can throw an error\nexport async function getAppClientData({\n appClientUrl,\n}: {\n appClientUrl: string;\n}): Promise<KsAppClientDataAndMeta> {\n const serverDataRes = await getDataStore({ appClientUrl });\n if (!serverDataRes.ok || !serverDataRes.data) {\n const message = `Could not load data from custom url \"${appClientUrl}\" ${serverDataRes.message}`;\n throw new Error(message);\n }\n return serverDataRes.data;\n}\n\n/** Sole job is to strip `metaState` if it's there */\nexport function prepAppClientData(\n state: KsAppClientData,\n): KsAppClientDataNoMeta {\n const { metaState, ...appClientDataNoMeta } = state;\n return appClientDataNoMeta;\n}\n\nexport async function prepareDataForFileSave({\n urlBase,\n state,\n}: {\n urlBase: string;\n state: KsAppClientDataNoMeta;\n}): Promise<GenericResponse<KsFileSaverParams>> {\n try {\n const body: KnapsackDataStoreSaveBody = {\n state: prepAppClientData(state),\n };\n const data = await fetcher<GenericResponse<KsFileSaverParams>>({\n url: new URL(ENDPOINTS.dataStorePrep, urlBase).toString(),\n body,\n });\n\n return data;\n } catch (err) {\n return {\n ok: false,\n message: err instanceof Error ? err.message : 'Unknown error',\n };\n }\n}\n\nexport async function submitDataForFileSave({\n urlBase,\n state,\n}: {\n urlBase: string;\n state: KsAppClientDataNoMeta;\n}): Promise<void> {\n const appClientData = prepAppClientData(state);\n const body: KnapsackDataStoreSaveBody = {\n state: appClientData,\n };\n const data = await fetcher<GenericResponse>({\n url: new URL(ENDPOINTS.dataStore, urlBase).toString(),\n body,\n });\n\n if (!data.ok) {\n throw new Error(`Could not save data to localhost files: ${data.message}`);\n }\n}\n\nexport async function getPluginContent({\n pluginId,\n appClientUrl,\n}: {\n pluginId: string;\n appClientUrl: string;\n}): Promise<PluginsApi.GetContentResponse> {\n const body: PluginsApi.GetContentRequest = {\n pluginId,\n type: PluginsApi.ACTIONS.getContent,\n };\n const data = await fetcher<PluginsApi.GetContentResponse>({\n url: new URL(ENDPOINTS.plugins, appClientUrl).toString(),\n body,\n });\n return data;\n}\n\nexport async function renderTemplate({\n options,\n appClientUrl,\n}: {\n options: PatternRenderData;\n appClientUrl: string;\n}): Promise<KsRenderResults> {\n const data = await fetcher<KsRenderResults>({\n url: new URL(ENDPOINTS.render, appClientUrl).toString(),\n body: options,\n });\n return data;\n}\n"]}
1
+ {"version":3,"sources":["../src/get-template-suggestions.ts","../src/app-client-api.ts"],"names":["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,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,OA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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"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@knapsack/app-client-api",
3
3
  "description": "",
4
- "version": "4.71.1",
4
+ "version": "4.71.2",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",
@@ -21,14 +21,15 @@
21
21
  "lint": "eslint ./"
22
22
  },
23
23
  "dependencies": {
24
- "@knapsack/types": "4.71.1",
25
- "@knapsack/utils": "4.71.1",
24
+ "@knapsack/app": "4.71.2",
25
+ "@knapsack/types": "4.71.2",
26
+ "@knapsack/utils": "4.71.2",
26
27
  "cross-fetch": "^4.0.0"
27
28
  },
28
29
  "devDependencies": {
29
- "@knapsack/eslint-config-starter": "4.71.1",
30
- "@knapsack/prettier-config": "4.71.1",
31
- "@knapsack/typescript-config-starter": "4.71.1",
30
+ "@knapsack/eslint-config-starter": "4.71.2",
31
+ "@knapsack/prettier-config": "4.71.2",
32
+ "@knapsack/typescript-config-starter": "4.71.2",
32
33
  "@types/node": "^20.16.11",
33
34
  "eslint": "^8.57.0",
34
35
  "tsup": "^8.3.0",
@@ -43,5 +44,5 @@
43
44
  "directory": "libs/app-client-api",
44
45
  "type": "git"
45
46
  },
46
- "gitHead": "72c592e4197c9d639f566022822a3a3cf8a8f0a1"
47
+ "gitHead": "53393364de6df01286130c0f44c948d70457215d"
47
48
  }