@knapsack/app-client-api 4.70.0--canary.4854.b1d79a8.0 → 4.70.0--canary.4561.78aed7a.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,51 @@
1
+ # v4.69.14 (Fri Sep 27 2024)
2
+
3
+ #### 🏠 Internal
4
+
5
+ - spec docs uses collapse instead of accordion [#4862](https://github.com/knapsack-labs/app-monorepo/pull/4862) ([@GormanDesign](https://github.com/GormanDesign))
6
+
7
+ #### Authors: 1
8
+
9
+ - Matt Gorman ([@GormanDesign](https://github.com/GormanDesign))
10
+
11
+ ---
12
+
13
+ # v4.69.13 (Thu Sep 26 2024)
14
+
15
+ #### 🐛 Bug Fix
16
+
17
+ - update design src user flow to be async [#4739](https://github.com/knapsack-labs/app-monorepo/pull/4739) ([@mabry1985](https://github.com/mabry1985))
18
+ - Merge branch 'latest' into feature/ksp-5512-create-add-design-src-file-async-mutation ([@mabry1985](https://github.com/mabry1985))
19
+
20
+ #### 🏠 Internal
21
+
22
+ - extract rendering utils out [#4789](https://github.com/knapsack-labs/app-monorepo/pull/4789) ([@EvanLovely](https://github.com/EvanLovely))
23
+ - refactors user flow for updating design src files [#4769](https://github.com/knapsack-labs/app-monorepo/pull/4769) ([@mabry1985](https://github.com/mabry1985))
24
+
25
+ #### Authors: 2
26
+
27
+ - Evan Lovely ([@EvanLovely](https://github.com/EvanLovely))
28
+ - Josh Mabry ([@mabry1985](https://github.com/mabry1985))
29
+
30
+ ---
31
+
32
+ # v4.69.12 (Thu Sep 26 2024)
33
+
34
+ #### 🐛 Bug Fix
35
+
36
+ - Merge branch 'latest' into feature/ksp-5560-replace-schema-forms-in-content-blocks ([@GormanDesign](https://github.com/GormanDesign))
37
+
38
+ #### 🏠 Internal
39
+
40
+ - chore(deps): update dependency @types/node to ^20.16.6 [#4846](https://github.com/knapsack-labs/app-monorepo/pull/4846) ([@renovate[bot]](https://github.com/renovate[bot]))
41
+
42
+ #### Authors: 2
43
+
44
+ - [@renovate[bot]](https://github.com/renovate[bot])
45
+ - Matt Gorman ([@GormanDesign](https://github.com/GormanDesign))
46
+
47
+ ---
48
+
1
49
  # v4.69.11 (Fri Sep 20 2024)
2
50
 
3
51
  #### 🏠 Internal
@@ -0,0 +1,59 @@
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 PatternRenderData = {
7
+ patternId: string;
8
+ templateId: string;
9
+ /**
10
+ * Data id from `saveData()`
11
+ * Cannot use with `demoId`
12
+ */
13
+ dataId?: string;
14
+ /**
15
+ * Cannot use with `dataId`
16
+ */
17
+ demoId?: string;
18
+ assetSetId?: string;
19
+ wrapHtml?: boolean;
20
+ isInIframe?: boolean;
21
+ cacheBuster?: string;
22
+ };
23
+ export declare const ENDPOINTS: {
24
+ health: string;
25
+ dataStore: string;
26
+ dataStorePrep: string;
27
+ files: string;
28
+ data: string;
29
+ render: string;
30
+ upload: string;
31
+ plugins: string;
32
+ getTemplateSuggestions: string;
33
+ };
34
+ export declare function checkAppClientUrl(url: string): Promise<GenericResponse>;
35
+ export declare function getDataStore({ appClientUrl, }: {
36
+ appClientUrl: string;
37
+ }): Promise<GenericResponse<KsAppClientDataAndMeta>>;
38
+ export declare function getAppClientData({ appClientUrl, }: {
39
+ appClientUrl: string;
40
+ }): Promise<KsAppClientDataAndMeta>;
41
+ /** Sole job is to strip `metaState` if it's there */
42
+ export declare function prepAppClientData(state: KsAppClientData): KsAppClientDataNoMeta;
43
+ export declare function prepareDataForFileSave({ urlBase, state, }: {
44
+ urlBase: string;
45
+ state: KsAppClientDataNoMeta;
46
+ }): Promise<GenericResponse<KsFileSaverParams>>;
47
+ export declare function submitDataForFileSave({ urlBase, state, }: {
48
+ urlBase: string;
49
+ state: KsAppClientDataNoMeta;
50
+ }): Promise<void>;
51
+ export declare function getPluginContent({ pluginId, appClientUrl, }: {
52
+ pluginId: string;
53
+ appClientUrl: string;
54
+ }): Promise<PluginsApi.GetContentResponse>;
55
+ export declare function renderTemplate({ options, appClientUrl, }: {
56
+ options: PatternRenderData;
57
+ appClientUrl: string;
58
+ }): Promise<KsRenderResults>;
59
+ //# 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;AACD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,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"}
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;AA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ACD,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
+ {"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":";;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uBAAuC;AAAA,IACxD,KAAK,IAAI,IAAI,UAAU,SAAS,YAAY,EAAE,SAAS;AAAA,IACvD;AAAA,EACF,CAAC;AACD,SAAO;AACT;AAhBsB;AAkBtB,eAAsB,eAAe;AAAA,EACnC;AAAA,EACA;AACF,GAG6B;AAC3B,QAAM,OAAO,UAAM,uBAAyB;AAAA,IAC1C,KAAK,IAAI,IAAI,UAAU,QAAQ,YAAY,EAAE,SAAS;AAAA,IACtD,MAAM;AAAA,EACR,CAAC;AACD,SAAO;AACT;AAZsB;","names":["import_utils"]}
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 } from '@knapsack/utils';\n\nexport const path = '/api/v1/template-suggestions';\nexport const method = 'GET';\nexport type ReqParams = Parameters<TemplateSuggestionsGetFn>[0];\nexport type ResBody =\n | {\n type: 'success';\n data: Awaited<ReturnType<TemplateSuggestionsGetFn>>;\n }\n | {\n type: 'error.invalidParams';\n message: string;\n }\n | {\n type: 'error.pathNotFound';\n message: string;\n }\n | {\n type: 'error.couldNotParse';\n message: string;\n };\n\nexport async function getTemplateSuggestions({\n appClientUrl,\n query,\n}: {\n appClientUrl: string;\n query: ReqParams;\n}): Promise<ResBody> {\n return fetcher<ResBody>({\n url: new URL(path, appClientUrl).toString(),\n query,\n });\n}\n","import { KsAppClientData, PluginsApi, KsRenderResults } from '@knapsack/types';\nimport type {\n GenericResponse,\n KsAppClientDataAndMeta,\n KsAppClientDataNoMeta,\n KsFileSaverParams,\n} from '@knapsack/types';\nimport { fetcher } from '@knapsack/utils';\nimport * as getTemplateSuggestions from './get-template-suggestions';\n\nexport interface KnapsackDataStoreSaveBody {\n state: KsAppClientData;\n}\nexport type PatternRenderData = {\n patternId: string;\n templateId: string;\n /**\n * Data id from `saveData()`\n * Cannot use with `demoId`\n */\n dataId?: string;\n /**\n * Cannot use with `dataId`\n */\n demoId?: string;\n assetSetId?: string;\n wrapHtml?: boolean;\n isInIframe?: boolean;\n cacheBuster?: string;\n};\n\nexport const ENDPOINTS = {\n health: '/api/v1/',\n dataStore: '/api/v1/data-store',\n dataStorePrep: '/api/v1/data-store-prep',\n files: '/api/v1/files',\n data: '/api/v1/data',\n render: '/api/v1/render',\n upload: '/api/v1/upload',\n plugins: '/api/v1/plugins',\n getTemplateSuggestions: getTemplateSuggestions.path,\n};\n\nexport async function checkAppClientUrl(url: string): Promise<GenericResponse> {\n try {\n const theUrl = new URL(ENDPOINTS.health, url); // will throw if url not formatted correctly\n const res = await fetcher<GenericResponse>({\n url: theUrl.toString(),\n });\n return res;\n } catch (err) {\n return {\n ok: false,\n message: err instanceof Error ? err.message : 'Unknown error',\n };\n }\n}\n\nexport async function getDataStore({\n appClientUrl,\n}: {\n appClientUrl: string;\n}): Promise<GenericResponse<KsAppClientDataAndMeta>> {\n try {\n const data = await fetcher<KsAppClientDataAndMeta>({\n url: new URL(ENDPOINTS.dataStore, appClientUrl).toString(),\n });\n\n return {\n ok: true,\n data,\n };\n } catch (err) {\n return {\n ok: false,\n message: err instanceof Error ? err.message : 'Unknown error',\n };\n }\n}\n\n// just need a function that can throw an error\nexport async function getAppClientData({\n appClientUrl,\n}: {\n appClientUrl: string;\n}): Promise<KsAppClientDataAndMeta> {\n const serverDataRes = await getDataStore({ appClientUrl });\n if (!serverDataRes.ok || !serverDataRes.data) {\n const message = `Could not load data from custom url \"${appClientUrl}\" ${serverDataRes.message}`;\n throw new Error(message);\n }\n return serverDataRes.data;\n}\n\n/** Sole job is to strip `metaState` if it's there */\nexport function prepAppClientData(\n state: KsAppClientData,\n): KsAppClientDataNoMeta {\n const { metaState, ...appClientDataNoMeta } = state;\n return appClientDataNoMeta;\n}\n\nexport async function prepareDataForFileSave({\n urlBase,\n state,\n}: {\n urlBase: string;\n state: KsAppClientDataNoMeta;\n}): Promise<GenericResponse<KsFileSaverParams>> {\n try {\n const body: KnapsackDataStoreSaveBody = {\n state: prepAppClientData(state),\n };\n const data = await fetcher<GenericResponse<KsFileSaverParams>>({\n url: new URL(ENDPOINTS.dataStorePrep, urlBase).toString(),\n body,\n });\n\n return data;\n } catch (err) {\n return {\n ok: false,\n message: err instanceof Error ? err.message : 'Unknown error',\n };\n }\n}\n\nexport async function submitDataForFileSave({\n urlBase,\n state,\n}: {\n urlBase: string;\n state: KsAppClientDataNoMeta;\n}): Promise<void> {\n const appClientData = prepAppClientData(state);\n const body: KnapsackDataStoreSaveBody = {\n state: appClientData,\n };\n const data = await fetcher<GenericResponse>({\n url: new URL(ENDPOINTS.dataStore, urlBase).toString(),\n body,\n });\n\n if (!data.ok) {\n throw new Error(`Could not save data to localhost files: ${data.message}`);\n }\n}\n\nexport async function getPluginContent({\n pluginId,\n appClientUrl,\n}: {\n pluginId: string;\n appClientUrl: string;\n}): Promise<PluginsApi.GetContentResponse> {\n const body: PluginsApi.GetContentRequest = {\n pluginId,\n type: PluginsApi.ACTIONS.getContent,\n };\n const data = await fetcher<PluginsApi.GetContentResponse>({\n url: new URL(ENDPOINTS.plugins, appClientUrl).toString(),\n body,\n });\n return data;\n}\n\nexport async function renderTemplate({\n options,\n appClientUrl,\n}: {\n options: PatternRenderData;\n appClientUrl: string;\n}): Promise<KsRenderResults> {\n const data = await fetcher<KsRenderResults>({\n url: new URL(ENDPOINTS.render, appClientUrl).toString(),\n body: options,\n });\n return data;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAwB;AAEjB,IAAM,OAAO;AACb,IAAM,SAAS;AAoBtB,eAAsB,uBAAuB;AAAA,EAC3C;AAAA,EACA;AACF,GAGqB;AACnB,aAAO,sBAAiB;AAAA,I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,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,EACT,wBAA+C;AACjD;AAEA,eAAsB,kBAAkB,KAAuC;AAC7E,MAAI;AACF,UAAM,SAAS,IAAI,IAAI,UAAU,Q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,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 } from '@knapsack/utils';\n\nexport const path = '/api/v1/template-suggestions';\nexport const method = 'GET';\nexport type ReqParams = Parameters<TemplateSuggestionsGetFn>[0];\nexport type ResBody =\n | {\n type: 'success';\n data: Awaited<ReturnType<TemplateSuggestionsGetFn>>;\n }\n | {\n type: 'error.invalidParams';\n message: string;\n }\n | {\n type: 'error.pathNotFound';\n message: string;\n }\n | {\n type: 'error.couldNotParse';\n message: string;\n };\n\nexport async function getTemplateSuggestions({\n appClientUrl,\n query,\n}: {\n appClientUrl: string;\n query: ReqParams;\n}): Promise<ResBody> {\n return fetcher<ResBody>({\n url: new URL(path, appClientUrl).toString(),\n query,\n });\n}\n","import { KsAppClientData, PluginsApi, KsRenderResults } from '@knapsack/types';\nimport type {\n GenericResponse,\n KsAppClientDataAndMeta,\n KsAppClientDataNoMeta,\n KsFileSaverParams,\n} from '@knapsack/types';\nimport { fetcher } from '@knapsack/utils';\nimport * as getTemplateSuggestions from './get-template-suggestions';\n\nexport interface KnapsackDataStoreSaveBody {\n state: KsAppClientData;\n}\nexport type PatternRenderData = {\n patternId: string;\n templateId: string;\n /**\n * Data id from `saveData()`\n * Cannot use with `demoId`\n */\n dataId?: string;\n /**\n * Cannot use with `dataId`\n */\n demoId?: string;\n assetSetId?: string;\n wrapHtml?: boolean;\n isInIframe?: boolean;\n cacheBuster?: string;\n};\n\nexport const ENDPOINTS = {\n health: '/api/v1/',\n dataStore: '/api/v1/data-store',\n dataStorePrep: '/api/v1/data-store-prep',\n files: '/api/v1/files',\n data: '/api/v1/data',\n render: '/api/v1/render',\n upload: '/api/v1/upload',\n plugins: '/api/v1/plugins',\n getTemplateSuggestions: getTemplateSuggestions.path,\n};\n\nexport async function checkAppClientUrl(url: string): Promise<GenericResponse> {\n try {\n const theUrl = new URL(ENDPOINTS.health, url); // will throw if url not formatted correctly\n const res = await fetcher<GenericResponse>({\n url: theUrl.toString(),\n });\n return res;\n } catch (err) {\n return {\n ok: false,\n message: err instanceof Error ? err.message : 'Unknown error',\n };\n }\n}\n\nexport async function getDataStore({\n appClientUrl,\n}: {\n appClientUrl: string;\n}): Promise<GenericResponse<KsAppClientDataAndMeta>> {\n try {\n const data = await fetcher<KsAppClientDataAndMeta>({\n url: new URL(ENDPOINTS.dataStore, appClientUrl).toString(),\n });\n\n return {\n ok: true,\n data,\n };\n } catch (err) {\n return {\n ok: false,\n message: err instanceof Error ? err.message : 'Unknown error',\n };\n }\n}\n\n// just need a function that can throw an error\nexport async function getAppClientData({\n appClientUrl,\n}: {\n appClientUrl: string;\n}): Promise<KsAppClientDataAndMeta> {\n const serverDataRes = await getDataStore({ appClientUrl });\n if (!serverDataRes.ok || !serverDataRes.data) {\n const message = `Could not load data from custom url \"${appClientUrl}\" ${serverDataRes.message}`;\n throw new Error(message);\n }\n return serverDataRes.data;\n}\n\n/** Sole job is to strip `metaState` if it's there */\nexport function prepAppClientData(\n state: KsAppClientData,\n): KsAppClientDataNoMeta {\n const { metaState, ...appClientDataNoMeta } = state;\n return appClientDataNoMeta;\n}\n\nexport async function prepareDataForFileSave({\n urlBase,\n state,\n}: {\n urlBase: string;\n state: KsAppClientDataNoMeta;\n}): Promise<GenericResponse<KsFileSaverParams>> {\n try {\n const body: KnapsackDataStoreSaveBody = {\n state: prepAppClientData(state),\n };\n const data = await fetcher<GenericResponse<KsFileSaverParams>>({\n url: new URL(ENDPOINTS.dataStorePrep, urlBase).toString(),\n body,\n });\n\n return data;\n } catch (err) {\n return {\n ok: false,\n message: err instanceof Error ? err.message : 'Unknown error',\n };\n }\n}\n\nexport async function submitDataForFileSave({\n urlBase,\n state,\n}: {\n urlBase: string;\n state: KsAppClientDataNoMeta;\n}): Promise<void> {\n const appClientData = prepAppClientData(state);\n const body: KnapsackDataStoreSaveBody = {\n state: appClientData,\n };\n const data = await fetcher<GenericResponse>({\n url: new URL(ENDPOINTS.dataStore, urlBase).toString(),\n body,\n });\n\n if (!data.ok) {\n throw new Error(`Could not save data to localhost files: ${data.message}`);\n }\n}\n\nexport async function getPluginContent({\n pluginId,\n appClientUrl,\n}: {\n pluginId: string;\n appClientUrl: string;\n}): Promise<PluginsApi.GetContentResponse> {\n const body: PluginsApi.GetContentRequest = {\n pluginId,\n type: PluginsApi.ACTIONS.getContent,\n };\n const data = await fetcher<PluginsApi.GetContentResponse>({\n url: new URL(ENDPOINTS.plugins, appClientUrl).toString(),\n body,\n });\n return data;\n}\n\nexport async function renderTemplate({\n options,\n appClientUrl,\n}: {\n options: PatternRenderData;\n appClientUrl: string;\n}): Promise<KsRenderResults> {\n const data = await fetcher<KsRenderResults>({\n url: new URL(ENDPOINTS.render, appClientUrl).toString(),\n body: options,\n });\n return data;\n}\n"],"mappings":";;;;;;;;AAAA;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;;;ACxBtB,SAA0B,kBAAmC;AAO7D,SAAS,WAAAA,gBAAe;AAwBjB,IAAM,YAAY;AAAA,EACvB,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,eAAe;AAAA,EACf,OAAO;AAAA,EACP,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,wBAA+C;AACjD;AAEA,eAAsB,kBAAkB,KAAuC;AAC7E,MAAI;AACF,UAAM,SAAS,IAAI,IAAI,UAAU,QAAQ,GAAG;AAC5C,UAAM,MAAM,MAAMC,SAAyB;AAAA,MACzC,KAAK,OAAO,SAAS;AAAA,IACvB,CAAC;AACD,WAAO;AAAA,EACT,SAAS,KAAK;AACZ,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,SAAS,eAAe,QAAQ,IAAI,UAAU;AAAA,IAChD;AAAA,EACF;AACF;AAbsB;AAetB,eAAsB,aAAa;AAAA,EACjC;AACF,GAEqD;AACnD,MAAI;AACF,UAAM,OAAO,MAAMA,SAAgC;AAAA,MACjD,KAAK,IAAI,IAAI,UAAU,WAAW,YAAY,EAAE,SAAS;AAAA,IAC3D,CAAC;AAED,WAAO;AAAA,MACL,IAAI;AAAA,MACJ;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AAK,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.70.0--canary.4854.b1d79a8.0",
5
- "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
- "types": "dist/index.d.ts",
4
+ "version": "4.70.0--canary.4561.78aed7a.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.70.0--canary.4854.b1d79a8.0",
27
- "@knapsack/utils": "4.70.0--canary.4854.b1d79a8.0",
24
+ "@knapsack/types": "4.70.0--canary.4561.78aed7a.0",
25
+ "@knapsack/utils": "4.70.0--canary.4561.78aed7a.0",
28
26
  "cross-fetch": "^4.0.0"
29
27
  },
30
28
  "devDependencies": {
31
- "@knapsack/eslint-config-starter": "4.70.0--canary.4854.b1d79a8.0",
32
- "@knapsack/prettier-config": "4.70.0--canary.4854.b1d79a8.0",
33
- "@knapsack/typescript-config-starter": "4.70.0--canary.4854.b1d79a8.0",
34
- "@types/node": "^20.16.5",
29
+ "@knapsack/eslint-config-starter": "4.70.0--canary.4561.78aed7a.0",
30
+ "@knapsack/prettier-config": "4.70.0--canary.4561.78aed7a.0",
31
+ "@knapsack/typescript-config-starter": "4.70.0--canary.4561.78aed7a.0",
32
+ "@types/node": "^20.16.6",
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": "b1d79a8caffe3537b921ff76bae2f2e8bcabbc43"
46
+ "gitHead": "78aed7a41e9fe84276609d2f85fbd944914473a0"
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"]