@knapsack/app-client-api 4.69.13--canary.4821.022ca72.0 → 4.69.13
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +19 -0
- package/dist/app-client-api.d.ts +9 -15
- package/dist/app-client-api.d.ts.map +1 -1
- package/dist/get-template-suggestions.d.ts +1 -7
- package/dist/get-template-suggestions.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
# v4.69.13 (Thu Sep 26 2024)
|
2
|
+
|
3
|
+
#### 🐛 Bug Fix
|
4
|
+
|
5
|
+
- update design src user flow to be async [#4739](https://github.com/knapsack-labs/app-monorepo/pull/4739) ([@mabry1985](https://github.com/mabry1985))
|
6
|
+
- Merge branch 'latest' into feature/ksp-5512-create-add-design-src-file-async-mutation ([@mabry1985](https://github.com/mabry1985))
|
7
|
+
|
8
|
+
#### 🏠 Internal
|
9
|
+
|
10
|
+
- extract rendering utils out [#4789](https://github.com/knapsack-labs/app-monorepo/pull/4789) ([@EvanLovely](https://github.com/EvanLovely))
|
11
|
+
- refactors user flow for updating design src files [#4769](https://github.com/knapsack-labs/app-monorepo/pull/4769) ([@mabry1985](https://github.com/mabry1985))
|
12
|
+
|
13
|
+
#### Authors: 2
|
14
|
+
|
15
|
+
- Evan Lovely ([@EvanLovely](https://github.com/EvanLovely))
|
16
|
+
- Josh Mabry ([@mabry1985](https://github.com/mabry1985))
|
17
|
+
|
18
|
+
---
|
19
|
+
|
1
20
|
# v4.69.12 (Thu Sep 26 2024)
|
2
21
|
|
3
22
|
#### 🐛 Bug Fix
|
package/dist/app-client-api.d.ts
CHANGED
@@ -3,28 +3,22 @@ import type { GenericResponse, KsAppClientDataAndMeta, KsAppClientDataNoMeta, Ks
|
|
3
3
|
export interface KnapsackDataStoreSaveBody {
|
4
4
|
state: KsAppClientData;
|
5
5
|
}
|
6
|
-
export type PatternRenderDataWithDemoId = {
|
7
|
-
patternId: string;
|
8
|
-
templateId: string;
|
9
|
-
assetSetId: string;
|
10
|
-
demoId: string;
|
11
|
-
};
|
12
6
|
export type PatternRenderData = {
|
13
7
|
patternId: string;
|
14
8
|
templateId: string;
|
15
|
-
assetSetId?: string;
|
16
|
-
wrapHtml?: boolean;
|
17
|
-
isInIframe?: boolean;
|
18
|
-
cacheBuster?: string;
|
19
9
|
/**
|
20
|
-
* Data id
|
21
|
-
*
|
10
|
+
* Data id from `saveData()`
|
11
|
+
* Cannot use with `demoId`
|
22
12
|
*/
|
23
|
-
dataId
|
13
|
+
dataId?: string;
|
24
14
|
/**
|
25
|
-
*
|
15
|
+
* Cannot use with `dataId`
|
26
16
|
*/
|
27
|
-
|
17
|
+
demoId?: string;
|
18
|
+
assetSetId?: string;
|
19
|
+
wrapHtml?: boolean;
|
20
|
+
isInIframe?: boolean;
|
21
|
+
cacheBuster?: string;
|
28
22
|
};
|
29
23
|
export declare const ENDPOINTS: {
|
30
24
|
health: string;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"app-client-api.d.ts","sourceRoot":"","sources":["../src/app-client-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,KAAK,EACV,eAAe,EACf,sBAAsB,EACtB,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AAIzB,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,eAAe,CAAC;CACxB;
|
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;IACx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B,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,13 +1,7 @@
|
|
1
1
|
import type { TemplateSuggestionsGetFn } from '@knapsack/types';
|
2
|
-
import { Except } from '@knapsack/utils';
|
3
2
|
export declare const path = "/api/v1/template-suggestions";
|
4
3
|
export declare const method = "GET";
|
5
|
-
export type ReqParams =
|
6
|
-
/**
|
7
|
-
* ID from saving {@link ContentStateForRendering} to `api.knapsack.cloud/render-data
|
8
|
-
*/
|
9
|
-
stateId: string;
|
10
|
-
};
|
4
|
+
export type ReqParams = Parameters<TemplateSuggestionsGetFn>[0];
|
11
5
|
export type ResBody = {
|
12
6
|
type: 'success';
|
13
7
|
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;
|
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"}
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
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
|
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,IACtB,KAAK,IAAI,IAAI,MAAM,YAAY,EAAE,SAAS;AAAA,IAC1C;AAAA,EACF,CAAC;AACH;AAXsB;;;ACxBtB,mBAA6D;AAO7D,IAAAA,gBAAwB;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,UAAM,uBAAyB;AAAA,MACzC,KAAK,OAAO,SAAS;AAAA,IACvB,CAAC;AACD,WAAO;AAAA,EACT,SAAS,KAAK;AACZ,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,SAAS,eAAe,QAAQ,IAAI,UAAU;AAAA,IAChD;AAAA,EACF;AACF;AAbsB;AAetB,eAAsB,aAAa;AAAA,EACjC;AACF,GAEqD;AACnD,MAAI;AACF,UAAM,OAAO,UAAM,uBAAgC;AAAA,MACjD,KAAK,IAAI,IAAI,UAAU,WAAW,YAAY,EAAE,SAAS;AAAA,IAC3D,CAAC;AAED,WAAO;AAAA,MACL,I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,MAAM,2CAA2C,KAAK,OAAO,EAAE;AAAA,EAC3E;AACF;AAnBsB;AAqBtB,eAAsB,iBAAiB;AAAA,EACrC;AAAA,EACA;AACF,GAG2C;AACzC,QAAM,OAAqC;AAAA,IACzC;AAAA,IACA,MAAM,wBAAW,QAAQ;AAAA,EAC3B;AACA,QAAM,OAAO,UAAM,uBAAuC;AAAA,IACxD,KAAK,IAAI,IAAI,UAAU,SAAS,YAAY,EAAE,SAAS;AAAA,IACvD;AAAA,EACF,CAAC;AACD,SAAO;AACT;AAhBsB;AAkBtB,eAAsB,eAAe;AAAA,EACnC;AAAA,EACA;AACF,GAG6B;AAC3B,QAAM,OAAO,UAAM,uBAAyB;AAAA,IAC1C,KAAK,IAAI,IAAI,UAAU,QAAQ,YAAY,EAAE,SAAS;AAAA,IACtD,MAAM;AAAA,EACR,CAAC;AACD,SAAO;AACT;AAZsB;","names":["import_utils"]}
|
package/dist/index.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/get-template-suggestions.ts","../src/app-client-api.ts"],"sourcesContent":["import type { TemplateSuggestionsGetFn } from '@knapsack/types';\nimport { 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;\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,OAAO,MAAMA,SAAuC;AAAA,IACxD,KAAK,IAAI,IAAI,UAAU,SAAS,YAAY,EAAE,SAAS;AAAA,IACvD;AAAA,EACF,CAAC;AACD,SAAO;AACT;AAhBsB;AAkBtB,eAAsB,eAAe;AAAA,EACnC;AAAA,EACA;AACF,GAG6B;AAC3B,QAAM,OAAO,MAAMA,SAAyB;AAAA,IAC1C,KAAK,IAAI,IAAI,UAAU,QAAQ,YAAY,EAAE,SAAS;AAAA,IACtD,MAAM;AAAA,EACR,CAAC;AACD,SAAO;AACT;AAZsB;","names":["fetcher","fetcher"]}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@knapsack/app-client-api",
|
3
3
|
"description": "",
|
4
|
-
"version": "4.69.13
|
4
|
+
"version": "4.69.13",
|
5
5
|
"exports": {
|
6
6
|
".": {
|
7
7
|
"types": "./dist/index.d.ts",
|
@@ -21,14 +21,14 @@
|
|
21
21
|
"lint": "eslint ./"
|
22
22
|
},
|
23
23
|
"dependencies": {
|
24
|
-
"@knapsack/types": "4.69.13
|
25
|
-
"@knapsack/utils": "4.69.13
|
24
|
+
"@knapsack/types": "4.69.13",
|
25
|
+
"@knapsack/utils": "4.69.13",
|
26
26
|
"cross-fetch": "^4.0.0"
|
27
27
|
},
|
28
28
|
"devDependencies": {
|
29
|
-
"@knapsack/eslint-config-starter": "4.69.13
|
30
|
-
"@knapsack/prettier-config": "4.69.13
|
31
|
-
"@knapsack/typescript-config-starter": "4.69.13
|
29
|
+
"@knapsack/eslint-config-starter": "4.69.13",
|
30
|
+
"@knapsack/prettier-config": "4.69.13",
|
31
|
+
"@knapsack/typescript-config-starter": "4.69.13",
|
32
32
|
"@types/node": "^20.16.6",
|
33
33
|
"eslint": "^8.57.0",
|
34
34
|
"tsup": "^8.2.4",
|
@@ -43,5 +43,5 @@
|
|
43
43
|
"directory": "libs/app-client-api",
|
44
44
|
"type": "git"
|
45
45
|
},
|
46
|
-
"gitHead": "
|
46
|
+
"gitHead": "d92e69870e1d094abc7d97fb1170ae68c0411b17"
|
47
47
|
}
|