@knapsack/app-client-api 4.69.12--canary.a4ca68f.0 → 4.69.12--canary.4821.8709676.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,65 @@
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
+ };
40
+ export declare function checkAppClientUrl(url: string): Promise<GenericResponse>;
41
+ export declare function getDataStore({ appClientUrl, }: {
42
+ appClientUrl: string;
43
+ }): Promise<GenericResponse<KsAppClientDataAndMeta>>;
44
+ export declare function getAppClientData({ appClientUrl, }: {
45
+ appClientUrl: string;
46
+ }): Promise<KsAppClientDataAndMeta>;
47
+ /** Sole job is to strip `metaState` if it's there */
48
+ export declare function prepAppClientData(state: KsAppClientData): KsAppClientDataNoMeta;
49
+ export declare function prepareDataForFileSave({ urlBase, state, }: {
50
+ urlBase: string;
51
+ state: KsAppClientDataNoMeta;
52
+ }): Promise<GenericResponse<KsFileSaverParams>>;
53
+ export declare function submitDataForFileSave({ urlBase, state, }: {
54
+ urlBase: string;
55
+ state: KsAppClientDataNoMeta;
56
+ }): Promise<void>;
57
+ export declare function getPluginContent({ pluginId, appClientUrl, }: {
58
+ pluginId: string;
59
+ appClientUrl: string;
60
+ }): Promise<PluginsApi.GetContentResponse>;
61
+ export declare function renderTemplate({ options, appClientUrl, }: {
62
+ options: PatternRenderData;
63
+ appClientUrl: string;
64
+ }): Promise<KsRenderResults>;
65
+ //# sourceMappingURL=app-client-api.d.ts.map
@@ -0,0 +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,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,SAAS;;;;;;;;;;CAUrB,CAAC;AAEF,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAa7E;AAED,wBAAsB,YAAY,CAAC,EACjC,YAAY,GACb,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,CAAC,eAAe,CAAC,sBAAsB,CAAC,CAAC,CAgBnD;AAGD,wBAAsB,gBAAgB,CAAC,EACrC,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.d.ts CHANGED
@@ -1,61 +1,4 @@
1
- import { KsAppClientData, PluginsApi, KsRenderResults } from '@knapsack/types';
2
- import type { GenericResponse, KsAppClientDataAndMeta, KsAppClientDataNoMeta, KsFileSaverParams } from '@knapsack/types';
3
1
  import * as getTemplateSuggestions from './get-template-suggestions';
4
2
  export { getTemplateSuggestions };
5
- export interface KnapsackDataStoreSaveBody {
6
- state: KsAppClientData;
7
- }
8
- export type PatternRenderData = {
9
- patternId: string;
10
- templateId: string;
11
- /**
12
- * Data id from `saveData()`
13
- * Cannot use with `demoId`
14
- */
15
- dataId?: string;
16
- /**
17
- * Cannot use with `dataId`
18
- */
19
- demoId?: string;
20
- assetSetId?: string;
21
- wrapHtml?: boolean;
22
- isInIframe?: boolean;
23
- cacheBuster?: string;
24
- };
25
- export declare const ENDPOINTS: {
26
- health: string;
27
- dataStore: string;
28
- dataStorePrep: string;
29
- files: string;
30
- data: string;
31
- render: string;
32
- upload: string;
33
- plugins: string;
34
- getTemplateSuggestions: string;
35
- };
36
- export declare function checkAppClientUrl(url: string): Promise<GenericResponse>;
37
- export declare function getDataStore({ appClientUrl, }: {
38
- appClientUrl: string;
39
- }): Promise<GenericResponse<KsAppClientDataAndMeta>>;
40
- export declare function getAppClientData({ appClientUrl, }: {
41
- appClientUrl: string;
42
- }): Promise<KsAppClientDataAndMeta>;
43
- /** Sole job is to strip `metaState` if it's there */
44
- export declare function prepAppClientData(state: KsAppClientData): KsAppClientDataNoMeta;
45
- export declare function prepareDataForFileSave({ urlBase, state, }: {
46
- urlBase: string;
47
- state: KsAppClientDataNoMeta;
48
- }): Promise<GenericResponse<KsFileSaverParams>>;
49
- export declare function submitDataForFileSave({ urlBase, state, }: {
50
- urlBase: string;
51
- state: KsAppClientDataNoMeta;
52
- }): Promise<void>;
53
- export declare function getPluginContent({ pluginId, appClientUrl, }: {
54
- pluginId: string;
55
- appClientUrl: string;
56
- }): Promise<PluginsApi.GetContentResponse>;
57
- export declare function renderTemplate({ options, appClientUrl, }: {
58
- options: PatternRenderData;
59
- appClientUrl: string;
60
- }): Promise<KsRenderResults>;
3
+ export * from './app-client-api';
61
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.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;AAEzB,OAAO,KAAK,sBAAsB,MAAM,4BAA4B,CAAC;AAErE,OAAO,EAAE,sBAAsB,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,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
+ {"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"}
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -32,8 +33,6 @@ __export(src_exports, {
32
33
  submitDataForFileSave: () => submitDataForFileSave
33
34
  });
34
35
  module.exports = __toCommonJS(src_exports);
35
- var import_types = require("@knapsack/types");
36
- var import_utils2 = require("@knapsack/utils");
37
36
 
38
37
  // src/get-template-suggestions.ts
39
38
  var get_template_suggestions_exports = {};
@@ -56,7 +55,9 @@ async function getTemplateSuggestions({
56
55
  }
57
56
  __name(getTemplateSuggestions, "getTemplateSuggestions");
58
57
 
59
- // src/index.ts
58
+ // src/app-client-api.ts
59
+ var import_types = require("@knapsack/types");
60
+ var import_utils2 = require("@knapsack/utils");
60
61
  var ENDPOINTS = {
61
62
  health: "/api/v1/",
62
63
  dataStore: "/api/v1/data-store",
@@ -75,10 +76,10 @@ async function checkAppClientUrl(url) {
75
76
  url: theUrl.toString()
76
77
  });
77
78
  return res;
78
- } catch (e) {
79
+ } catch (err) {
79
80
  return {
80
81
  ok: false,
81
- message: e.message
82
+ message: err instanceof Error ? err.message : "Unknown error"
82
83
  };
83
84
  }
84
85
  }
@@ -97,7 +98,7 @@ async function getDataStore({
97
98
  } catch (err) {
98
99
  return {
99
100
  ok: false,
100
- message: err.message
101
+ message: err instanceof Error ? err.message : "Unknown error"
101
102
  };
102
103
  }
103
104
  }
@@ -106,7 +107,7 @@ async function getAppClientData({
106
107
  appClientUrl
107
108
  }) {
108
109
  const serverDataRes = await getDataStore({ appClientUrl });
109
- if (!serverDataRes.ok) {
110
+ if (!serverDataRes.ok || !serverDataRes.data) {
110
111
  const message = `Could not load data from custom url "${appClientUrl}" ${serverDataRes.message}`;
111
112
  throw new Error(message);
112
113
  }
@@ -134,7 +135,7 @@ async function prepareDataForFileSave({
134
135
  } catch (err) {
135
136
  return {
136
137
  ok: false,
137
- message: err.message
138
+ message: err instanceof Error ? err.message : "Unknown error"
138
139
  };
139
140
  }
140
141
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/get-template-suggestions.ts"],"sourcesContent":["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 { getTemplateSuggestions };\n\nexport interface KnapsackDataStoreSaveBody {\n state: KsAppClientData;\n}\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 (e) {\n return {\n ok: false,\n message: e.message,\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.message,\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 // console.log(`getDataStore() response`, serverDataRes);\n if (!serverDataRes.ok) {\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.message,\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","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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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A,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"]}
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,IA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D,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
@@ -5,10 +5,6 @@ var __export = (target, all) => {
5
5
  __defProp(target, name, { get: all[name], enumerable: true });
6
6
  };
7
7
 
8
- // src/index.ts
9
- import { PluginsApi } from "@knapsack/types";
10
- import { fetcher as fetcher2 } from "@knapsack/utils";
11
-
12
8
  // src/get-template-suggestions.ts
13
9
  var get_template_suggestions_exports = {};
14
10
  __export(get_template_suggestions_exports, {
@@ -30,7 +26,9 @@ async function getTemplateSuggestions({
30
26
  }
31
27
  __name(getTemplateSuggestions, "getTemplateSuggestions");
32
28
 
33
- // src/index.ts
29
+ // src/app-client-api.ts
30
+ import { PluginsApi } from "@knapsack/types";
31
+ import { fetcher as fetcher2 } from "@knapsack/utils";
34
32
  var ENDPOINTS = {
35
33
  health: "/api/v1/",
36
34
  dataStore: "/api/v1/data-store",
@@ -49,10 +47,10 @@ async function checkAppClientUrl(url) {
49
47
  url: theUrl.toString()
50
48
  });
51
49
  return res;
52
- } catch (e) {
50
+ } catch (err) {
53
51
  return {
54
52
  ok: false,
55
- message: e.message
53
+ message: err instanceof Error ? err.message : "Unknown error"
56
54
  };
57
55
  }
58
56
  }
@@ -71,7 +69,7 @@ async function getDataStore({
71
69
  } catch (err) {
72
70
  return {
73
71
  ok: false,
74
- message: err.message
72
+ message: err instanceof Error ? err.message : "Unknown error"
75
73
  };
76
74
  }
77
75
  }
@@ -80,7 +78,7 @@ async function getAppClientData({
80
78
  appClientUrl
81
79
  }) {
82
80
  const serverDataRes = await getDataStore({ appClientUrl });
83
- if (!serverDataRes.ok) {
81
+ if (!serverDataRes.ok || !serverDataRes.data) {
84
82
  const message = `Could not load data from custom url "${appClientUrl}" ${serverDataRes.message}`;
85
83
  throw new Error(message);
86
84
  }
@@ -108,7 +106,7 @@ async function prepareDataForFileSave({
108
106
  } catch (err) {
109
107
  return {
110
108
  ok: false,
111
- message: err.message
109
+ message: err instanceof Error ? err.message : "Unknown error"
112
110
  };
113
111
  }
114
112
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/get-template-suggestions.ts"],"sourcesContent":["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 { getTemplateSuggestions };\n\nexport interface KnapsackDataStoreSaveBody {\n state: KsAppClientData;\n}\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 (e) {\n return {\n ok: false,\n message: e.message,\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.message,\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 // console.log(`getDataStore() response`, serverDataRes);\n if (!serverDataRes.ok) {\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.message,\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","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"],"mappings":";;;;;;;;AAAA,SAA0B,kBAAmC;AAO7D,SAAS,WAAAA,gBAAe;;;ACPxB;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,SAAS,eAAe;AAEjB,IAAM,OAAO;AACb,IAAM,SAAS;AAoBtB,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;;;ADUf,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,E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AAC;AAED,WAAO;AAAA,EACT,SAAS,KAAK;AACZ,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,SAAS,IAAI;AAAA,IACf;AAAA,EACF;AACF;AAvBsB;AAyBtB,eAAsB,sBAAsB;AAAA,EAC1C;AAAA,EACA;AACF,GAGkB;AAChB,QAAM,gBAAgB,kBAAkB,KAAK;AAC7C,QAAM,OAAkC;AAAA,IACtC,OAAO;AAAA,EACT;AACA,QAAM,OAAO,MAAMA,SAAyB;AAAA,IAC1C,KAAK,IAAI,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"]}
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,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ChB,QAAM,gBAAgB,kBAAkB,KAAK;AAC7C,QAAM,OAAkC;AAAA,IACtC,OAAO;AAAA,EACT;AACA,QAAM,OAAO,MAAMA,SAAyB;AAAA,IAC1C,KAAK,IAAI,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,15 +1,13 @@
1
1
  {
2
2
  "name": "@knapsack/app-client-api",
3
3
  "description": "",
4
- "version": "4.69.12--canary.a4ca68f.0",
5
- "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
- "types": "dist/index.d.ts",
4
+ "version": "4.69.12--canary.4821.8709676.0",
8
5
  "exports": {
9
6
  ".": {
10
7
  "types": "./dist/index.d.ts",
11
8
  "import": "./dist/index.mjs",
12
- "require": "./dist/index.js"
9
+ "require": "./dist/index.js",
10
+ "default": "./dist/index.mjs"
13
11
  },
14
12
  "./package": "./package.json",
15
13
  "./package.json": "./package.json"
@@ -23,15 +21,15 @@
23
21
  "lint": "eslint ./"
24
22
  },
25
23
  "dependencies": {
26
- "@knapsack/types": "4.69.12--canary.a4ca68f.0",
27
- "@knapsack/utils": "4.69.12--canary.a4ca68f.0",
24
+ "@knapsack/types": "4.69.12--canary.4821.8709676.0",
25
+ "@knapsack/utils": "4.69.12--canary.4821.8709676.0",
28
26
  "cross-fetch": "^4.0.0"
29
27
  },
30
28
  "devDependencies": {
31
- "@knapsack/eslint-config-starter": "4.69.12--canary.a4ca68f.0",
32
- "@knapsack/prettier-config": "4.69.12--canary.a4ca68f.0",
33
- "@knapsack/typescript-config-starter": "4.69.12--canary.a4ca68f.0",
34
- "@types/node": "^20.16.6",
29
+ "@knapsack/eslint-config-starter": "4.69.12--canary.4821.8709676.0",
30
+ "@knapsack/prettier-config": "4.69.12--canary.4821.8709676.0",
31
+ "@knapsack/typescript-config-starter": "4.69.12--canary.4821.8709676.0",
32
+ "@types/node": "^20.16.5",
35
33
  "eslint": "^8.57.0",
36
34
  "tsup": "^8.2.4",
37
35
  "typescript": "^5.5.4"
@@ -45,5 +43,5 @@
45
43
  "directory": "libs/app-client-api",
46
44
  "type": "git"
47
45
  },
48
- "gitHead": "a4ca68fa56ea750ef33eced2d2f273c295e7d705"
46
+ "gitHead": "8709676f3545d2ea5c97f981cc964e92035585f0"
49
47
  }
package/tsconfig.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "extends": "@knapsack/typescript-config-starter/tsconfig.declarations-only.json",
3
3
  "compilerOptions": {
4
+ "strict": true,
4
5
  "outDir": "./dist"
5
6
  },
6
7
  "include": ["./src"]