@knapsack/app 4.79.2 → 4.79.3--canary.6036.f7fab19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.lintstagedrc.mjs +1 -1
- package/CHANGELOG.md +0 -44
- package/dist/cli/commands.d.ts +9 -14
- package/dist/cli/commands.d.ts.map +1 -1
- package/dist/cli/commands.js +24 -81
- package/dist/cli/commands.js.map +1 -1
- package/dist/cli/knapsack-cli.js +18 -24
- package/dist/cli/knapsack-cli.js.map +1 -1
- package/dist/cli/log.d.ts +1 -1
- package/dist/cli/log.d.ts.map +1 -1
- package/dist/cli/log.js +2 -6
- package/dist/cli/log.js.map +1 -1
- package/dist/domains/patterns/patterns.d.ts +3 -5
- package/dist/domains/patterns/patterns.d.ts.map +1 -1
- package/dist/domains/patterns/patterns.js +50 -38
- package/dist/domains/patterns/patterns.js.map +1 -1
- package/dist/domains/patterns/renderers/renderer-base.d.ts +29 -37
- package/dist/domains/patterns/renderers/renderer-base.d.ts.map +1 -1
- package/dist/domains/patterns/renderers/renderer-base.js +63 -172
- package/dist/domains/patterns/renderers/renderer-base.js.map +1 -1
- package/dist/domains/patterns/renderers/renderer-utils.d.ts +1 -2
- package/dist/domains/patterns/renderers/renderer-utils.d.ts.map +1 -1
- package/dist/domains/patterns/renderers/renderer-utils.js +0 -13
- package/dist/domains/patterns/renderers/renderer-utils.js.map +1 -1
- package/dist/index.d.ts +2 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -16
- package/dist/index.js.map +1 -1
- package/dist/lib/api-client.d.ts.map +1 -1
- package/dist/lib/api-client.js +4 -7
- package/dist/lib/api-client.js.map +1 -1
- package/dist/lib/bootstrap.d.ts.map +1 -1
- package/dist/lib/bootstrap.js +3 -1
- package/dist/lib/bootstrap.js.map +1 -1
- package/dist/lib/util/cache-dir.d.ts +1 -15
- package/dist/lib/util/cache-dir.d.ts.map +1 -1
- package/dist/lib/util/cache-dir.js +8 -15
- package/dist/lib/util/cache-dir.js.map +1 -1
- package/dist/lib/utils.d.ts +2 -1
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js.map +1 -1
- package/dist/node-api.d.ts +3 -0
- package/dist/node-api.d.ts.map +1 -0
- package/dist/node-api.js +11 -0
- package/dist/node-api.js.map +1 -0
- package/dist/server/rest-api.d.ts +3 -3
- package/dist/server/rest-api.d.ts.map +1 -1
- package/dist/server/rest-api.js +18 -83
- package/dist/server/rest-api.js.map +1 -1
- package/dist/server/server.d.ts +5 -5
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js +44 -70
- package/dist/server/server.js.map +1 -1
- package/dist/types/brain.d.ts +1 -2
- package/dist/types/brain.d.ts.map +1 -1
- package/dist/types/cli-lifecycle.d.ts +4 -9
- package/dist/types/cli-lifecycle.d.ts.map +1 -1
- package/dist/types/endpoints.d.ts +5 -58
- package/dist/types/endpoints.d.ts.map +1 -1
- package/dist/types/knapsack-config.d.ts +1 -1
- package/dist/types/knapsack-config.d.ts.map +1 -1
- package/package.json +19 -20
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PathAbsolute } from '@knapsack/file-utils';
|
|
2
|
-
import { KsAppClientDataNoMeta
|
|
2
|
+
import { KsAppClientDataNoMeta } from '@knapsack/types';
|
|
3
3
|
/**
|
|
4
4
|
* Cache directory. Likely will be `node_modules/.cache/@knapsack/app/` but falls back to the `/tmp` directory if it has problems.
|
|
5
5
|
*/
|
|
@@ -13,19 +13,5 @@ export declare const appClientDataFileHelper: {
|
|
|
13
13
|
write: (data: KsAppClientDataNoMeta) => Promise<void>;
|
|
14
14
|
exists: () => boolean;
|
|
15
15
|
};
|
|
16
|
-
export declare const discoveryFileHelper: {
|
|
17
|
-
path: PathAbsolute;
|
|
18
|
-
read: () => Promise<GeneralDiscovery>;
|
|
19
|
-
readSync: () => GeneralDiscovery;
|
|
20
|
-
write: (data: GeneralDiscovery) => Promise<void>;
|
|
21
|
-
exists: () => boolean;
|
|
22
|
-
};
|
|
23
|
-
export declare const getRendererDiscoveryFileHelper: <TheRendererId extends RendererId>(rendererId: TheRendererId) => {
|
|
24
|
-
path: PathAbsolute;
|
|
25
|
-
read: () => Promise<RendererDiscovery<TheRendererId>>;
|
|
26
|
-
readSync: () => RendererDiscovery<TheRendererId>;
|
|
27
|
-
write: (data: RendererDiscovery<TheRendererId>) => Promise<void>;
|
|
28
|
-
exists: () => boolean;
|
|
29
|
-
};
|
|
30
16
|
export declare function writePortFile(port: number): Promise<void>;
|
|
31
17
|
//# sourceMappingURL=cache-dir.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache-dir.d.ts","sourceRoot":"","sources":["../../../src/lib/util/cache-dir.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"cache-dir.d.ts","sourceRoot":"","sources":["../../../src/lib/util/cache-dir.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,YAAY,EAEb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAIxD;;GAEG;AACH,eAAO,MAAM,UAAU,EAGD,YAAY,CAAC;AAEnC,qEAAqE;AACrE,eAAO,MAAM,eAAe,qBAA6B,CAAC;AAG1D,eAAO,MAAM,uBAAuB;;gBAExB,OAAO,CAAC,qBAAqB,CAAC;oBAC1B,qBAAqB;kBACrB,qBAAqB;;CAGpC,CAAC;AAKF,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,iBAK/C"}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.appClientDataFileHelper = exports.emptyKsCacheDir = exports.ksCacheDir = void 0;
|
|
7
7
|
exports.writePortFile = writePortFile;
|
|
8
8
|
const file_utils_1 = require("@knapsack/file-utils");
|
|
9
9
|
const find_cache_dir_1 = __importDefault(require("find-cache-dir"));
|
|
@@ -18,21 +18,14 @@ exports.ksCacheDir = ((0, find_cache_dir_1.default)({
|
|
|
18
18
|
/** Deletes contents of cache directory – directory itself remains */
|
|
19
19
|
const emptyKsCacheDir = () => (0, file_utils_1.emptyDir)(exports.ksCacheDir);
|
|
20
20
|
exports.emptyKsCacheDir = emptyKsCacheDir;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
});
|
|
29
|
-
const getRendererDiscoveryFileHelper = (rendererId) => {
|
|
30
|
-
return (0, file_utils_1.createJsonFileHelper)({
|
|
31
|
-
dir: exports.ksCacheDir,
|
|
32
|
-
fileName: `renderer-discovery-${rendererId}.json`,
|
|
33
|
-
});
|
|
21
|
+
const appClientDataFilePath = (0, file_utils_1.join)(exports.ksCacheDir, 'app-client-data.json');
|
|
22
|
+
exports.appClientDataFileHelper = {
|
|
23
|
+
path: appClientDataFilePath,
|
|
24
|
+
read: () => (0, file_utils_1.readJSON)(appClientDataFilePath),
|
|
25
|
+
readSync: () => (0, file_utils_1.readJSONSync)(appClientDataFilePath),
|
|
26
|
+
write: (data) => (0, file_utils_1.writeJSON)({ path: appClientDataFilePath, contents: data }),
|
|
27
|
+
exists: () => (0, file_utils_1.existsSync)(appClientDataFilePath),
|
|
34
28
|
};
|
|
35
|
-
exports.getRendererDiscoveryFileHelper = getRendererDiscoveryFileHelper;
|
|
36
29
|
const portFilePath = (0, file_utils_1.join)(exports.ksCacheDir, 'port.txt');
|
|
37
30
|
(0, file_utils_1.removeSync)(portFilePath);
|
|
38
31
|
async function writePortFile(port) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache-dir.js","sourceRoot":"","sources":["../../../src/lib/util/cache-dir.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":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GED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
type CliCommand = 'unknown' | 'serve' | 'start';
|
|
2
2
|
export declare function setCliCommand(cmd: CliCommand): void;
|
|
3
3
|
export declare function getCliCommand(): CliCommand;
|
|
4
4
|
/**
|
|
5
5
|
* Determine if the current process is running in our internal monorepo or a user's workspace
|
|
6
6
|
*/
|
|
7
7
|
export declare const isInMonorepo: boolean;
|
|
8
|
+
export {};
|
|
8
9
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/lib/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"AAAA,KAAK,UAAU,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAGhD,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,QAE5C;AAED,wBAAgB,aAAa,IAAI,UAAU,CAE1C;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,SAAsC,CAAC"}
|
package/dist/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":";;;AAGA,sCAEC;AAED,sCAEC;AARD,IAAI,UAAU,GAAe,SAAS,CAAC;AAEvC,SAAgB,aAAa,CAAC,GAAe;IAC3C,UAAU,GAAG,GAAG,CAAC;AACnB,CAAC;AAED,SAAgB,aAAa;IAC3B,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;GAEG;AACU,QAAA,YAAY,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-api.d.ts","sourceRoot":"","sources":["../src/node-api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,wBAAsB,gBAAgB,CACpC,cAAc,SAAyB,GACtC,OAAO,CAAC,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAAC,CAIrD"}
|
package/dist/node-api.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bootstrapAndInit = bootstrapAndInit;
|
|
4
|
+
const commands_1 = require("./cli/commands");
|
|
5
|
+
const bootstrap_1 = require("./lib/bootstrap");
|
|
6
|
+
async function bootstrapAndInit(configFilePath = './knapsack.config.js') {
|
|
7
|
+
const brain = (0, bootstrap_1.bootstrapFromConfigFile)(configFilePath);
|
|
8
|
+
await (0, commands_1.initAll)({ ksBrain: brain });
|
|
9
|
+
return brain;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=node-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-api.js","sourceRoot":"","sources":["../src/node-api.ts"],"names":[],"mappings":";;AAGA,4CAMC;AATD,6CAAyC;AACzC,+CAA0D;AAEnD,KAAK,UAAU,gBAAgB,CACpC,cAAc,GAAG,sBAAsB;IAEvC,MAAM,KAAK,GAAG,IAAA,mCAAuB,EAAC,cAAc,CAAC,CAAC;IACtD,MAAM,IAAA,kBAAO,EAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;IAClC,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { KnapsackMeta } from '@knapsack/types';
|
|
2
2
|
import { KnapsackBrain } from '../types/brain';
|
|
3
3
|
import { Endpoint } from '../types/endpoints';
|
|
4
|
-
export declare function getApiRoutes({
|
|
5
|
-
|
|
4
|
+
export declare function getApiRoutes({ meta, ksBrain: { patterns: patternManifest, config }, isLocalDev, collectionsParentKey, }: {
|
|
5
|
+
meta: KnapsackMeta;
|
|
6
6
|
ksBrain: KnapsackBrain;
|
|
7
7
|
isLocalDev: boolean;
|
|
8
8
|
collectionsParentKey: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest-api.d.ts","sourceRoot":"","sources":["../../src/server/rest-api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rest-api.d.ts","sourceRoot":"","sources":["../../src/server/rest-api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAsB,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAUxE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAI9C,wBAAgB,YAAY,CAAC,EAC3B,IAAI,EACJ,OAAO,EAAE,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,EAAE,EAC9C,UAAU,EACV,oBAAoB,GACrB,EAAE;IACD,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,EAAE,aAAa,CAAC;IACvB,UAAU,EAAE,OAAO,CAAC;IACpB,oBAAoB,EAAE,MAAM,CAAC;CAC9B,GAAG,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAoW/B"}
|
package/dist/server/rest-api.js
CHANGED
|
@@ -1,38 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.getApiRoutes = getApiRoutes;
|
|
4
|
+
const path_1 = require("path");
|
|
7
5
|
const utils_1 = require("@knapsack/utils");
|
|
8
6
|
const file_utils_1 = require("@knapsack/file-utils");
|
|
9
|
-
const types_1 = require("@knapsack/types");
|
|
10
|
-
const json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
|
|
11
|
-
const path_1 = require("path");
|
|
12
7
|
const log_1 = require("../cli/log");
|
|
13
8
|
const utils_2 = require("../lib/utils");
|
|
14
9
|
const api_client_1 = require("../lib/api-client");
|
|
15
|
-
|
|
16
|
-
/** May be empty string when deployed in situations w/o git, like a Docker container */
|
|
17
|
-
const gitRoot = (0, file_utils_1.findGitRoot)();
|
|
18
|
-
function getApiRoutes({ ksBrain, isLocalDev, collectionsParentKey, discovery: { metaState: { meta }, }, }) {
|
|
10
|
+
function getApiRoutes({ meta, ksBrain: { patterns: patternManifest, config }, isLocalDev, collectionsParentKey, }) {
|
|
19
11
|
var _a;
|
|
20
|
-
const { patterns: patternManifest, config } = ksBrain;
|
|
21
12
|
/** We will do Ava unit testing on some endpoints but only on `ks-sandbox` and in our monorepo */
|
|
22
13
|
const isOkToRunLocallyForTesting = ((_a = config.cloud) === null || _a === void 0 ? void 0 : _a.siteId) === 'ks-sandbox' && utils_2.isInMonorepo;
|
|
23
14
|
const shouldCache = (0, utils_2.getCliCommand)() === 'serve';
|
|
24
15
|
const siteId = meta.knapsackCloudSiteId;
|
|
25
16
|
const appClientVersion = meta.ksVersions.app;
|
|
26
|
-
const rootDir = gitRoot || ksBrain.config.data;
|
|
27
|
-
const createCachedFn = (fn) => {
|
|
28
|
-
return shouldCache
|
|
29
|
-
? (0, utils_1.memoize)(fn, {
|
|
30
|
-
max: 100,
|
|
31
|
-
promise: true,
|
|
32
|
-
normalizer: (args) => (0, json_stable_stringify_1.default)(args) || JSON.stringify(args),
|
|
33
|
-
})
|
|
34
|
-
: fn;
|
|
35
|
-
};
|
|
36
17
|
async function renderUncached({ websocketsPort, stateId, dataId, patternId, templateId, assetSetId, isInIframe, }) {
|
|
37
18
|
if (!stateId) {
|
|
38
19
|
throw new Error(`Missing required "stateId" param`);
|
|
@@ -68,24 +49,26 @@ function getApiRoutes({ ksBrain, isLocalDev, collectionsParentKey, discovery: {
|
|
|
68
49
|
// give up
|
|
69
50
|
const pattern = state === null || state === void 0 ? void 0 : state.patterns[patternId];
|
|
70
51
|
const template = pattern === null || pattern === void 0 ? void 0 : pattern.templates.find((t) => t.id === templateId);
|
|
71
|
-
const templateInfo =
|
|
72
|
-
|
|
73
|
-
.join(' ');
|
|
74
|
-
log_1.log.error(results.message, {
|
|
75
|
-
templateInfo,
|
|
76
|
-
patternId,
|
|
77
|
-
templateId,
|
|
78
|
-
hasPattern: !!pattern,
|
|
79
|
-
hasTemplate: !!template,
|
|
80
|
-
}, 'render');
|
|
52
|
+
const templateInfo = `${template === null || template === void 0 ? void 0 : template.alias} ${template === null || template === void 0 ? void 0 : template.path}`;
|
|
53
|
+
log_1.log.error(`${results.message} - ${templateInfo}`, 'pattern render');
|
|
81
54
|
return results;
|
|
82
55
|
}
|
|
83
56
|
attempt += 1;
|
|
84
57
|
await new Promise((r) => setTimeout(r, waitTime));
|
|
85
58
|
}
|
|
86
59
|
}
|
|
87
|
-
const render =
|
|
88
|
-
|
|
60
|
+
const render = shouldCache
|
|
61
|
+
? (0, utils_1.memoize)(renderUncached, {
|
|
62
|
+
max: 100,
|
|
63
|
+
promise: true,
|
|
64
|
+
normalizer(args) {
|
|
65
|
+
// args is arguments object as accessible in memoized function
|
|
66
|
+
// If additionally we want to ensure that our logic works well with different order of properties, we need to imply an additional sorting, e.g.
|
|
67
|
+
const [arg] = args;
|
|
68
|
+
return JSON.stringify(Object.entries(arg).sort());
|
|
69
|
+
},
|
|
70
|
+
})
|
|
71
|
+
: renderUncached;
|
|
89
72
|
const baseEndpoint = {
|
|
90
73
|
path: '/api/v1',
|
|
91
74
|
method: 'GET',
|
|
@@ -186,7 +169,7 @@ function getApiRoutes({ ksBrain, isLocalDev, collectionsParentKey, discovery: {
|
|
|
186
169
|
if (!demo) {
|
|
187
170
|
throw new Error(`Cannot find demo "${demoId}"`);
|
|
188
171
|
}
|
|
189
|
-
if (
|
|
172
|
+
if (demo.type === 'data') {
|
|
190
173
|
demo = inlineDemoData({
|
|
191
174
|
demosById: patternManifest.demosById,
|
|
192
175
|
demo,
|
|
@@ -234,58 +217,13 @@ function getApiRoutes({ ksBrain, isLocalDev, collectionsParentKey, discovery: {
|
|
|
234
217
|
type: 'verify',
|
|
235
218
|
payload: {
|
|
236
219
|
exists,
|
|
237
|
-
relativePath: exists
|
|
238
|
-
? (0, file_utils_1.relative)(dataDir, absolutePath)
|
|
239
|
-
: '',
|
|
220
|
+
relativePath: exists ? (0, path_1.relative)(dataDir, absolutePath) : '',
|
|
240
221
|
absolutePath,
|
|
241
222
|
type,
|
|
242
223
|
},
|
|
243
224
|
};
|
|
244
225
|
},
|
|
245
226
|
};
|
|
246
|
-
const inspectEndpoint = {
|
|
247
|
-
path: '/api/v2/inspect',
|
|
248
|
-
method: 'GET',
|
|
249
|
-
authLevel: 'VIEWER',
|
|
250
|
-
handle: async (req) => inspect(req.query),
|
|
251
|
-
};
|
|
252
|
-
const rendererDiscoveryEndpoint = {
|
|
253
|
-
path: '/api/v2/renderer-discovery',
|
|
254
|
-
method: 'GET',
|
|
255
|
-
authLevel: 'VIEWER',
|
|
256
|
-
handle: async (req) => {
|
|
257
|
-
const { rendererId } = req.query;
|
|
258
|
-
if (!rendererId) {
|
|
259
|
-
throw new Error(`Missing required "rendererId" param`);
|
|
260
|
-
}
|
|
261
|
-
if (shouldCache) {
|
|
262
|
-
try {
|
|
263
|
-
return (0, cache_dir_1.getRendererDiscoveryFileHelper)(rendererId).read();
|
|
264
|
-
}
|
|
265
|
-
catch (e) {
|
|
266
|
-
throw new Error(`Renderer discovery file not found for ${rendererId}`, { cause: e });
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
const renderer = patternManifest.getRenderer(rendererId);
|
|
270
|
-
return renderer.getDiscovery();
|
|
271
|
-
},
|
|
272
|
-
};
|
|
273
|
-
const pkgInfoEndpoint = {
|
|
274
|
-
path: '/api/v2/pkg-info',
|
|
275
|
-
method: 'GET',
|
|
276
|
-
authLevel: 'VIEWER',
|
|
277
|
-
handle: async (req) => {
|
|
278
|
-
const { pkgName } = req.query;
|
|
279
|
-
const { pkgDir, getPkgJson } = await (0, file_utils_1.resolvePkg)(pkgName);
|
|
280
|
-
const pkgJson = await getPkgJson();
|
|
281
|
-
return {
|
|
282
|
-
pkgName,
|
|
283
|
-
pkgJson,
|
|
284
|
-
isFromNodeModules: pkgDir.split(path_1.sep).includes('node_modules'),
|
|
285
|
-
relativePath: (0, file_utils_1.relative)(rootDir, pkgDir),
|
|
286
|
-
};
|
|
287
|
-
},
|
|
288
|
-
};
|
|
289
227
|
const getTemplateSuggestionsEndpoint = {
|
|
290
228
|
path: '/api/v1/template-suggestions',
|
|
291
229
|
method: 'GET',
|
|
@@ -343,10 +281,7 @@ function getApiRoutes({ ksBrain, isLocalDev, collectionsParentKey, discovery: {
|
|
|
343
281
|
renderEndpointPost,
|
|
344
282
|
renderDemoIdEndpoint,
|
|
345
283
|
filesEndpoint,
|
|
346
|
-
inspectEndpoint,
|
|
347
|
-
rendererDiscoveryEndpoint,
|
|
348
284
|
getTemplateSuggestionsEndpoint,
|
|
349
|
-
pkgInfoEndpoint,
|
|
350
285
|
];
|
|
351
286
|
}
|
|
352
287
|
//# sourceMappingURL=rest-api.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest-api.js","sourceRoot":"","sources":["../../src/server/rest-api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rest-api.js","sourceRoot":"","sources":["../../src/server/rest-api.ts"],"names":[],"mappings":";;AAkBA,oCA8WC;AAhYD,+BAAgC;AAChC,2CAAsD;AACtD,qDAAmD;AAUnD,oCAAiC;AAGjC,wCAA2D;AAC3D,kDAAyE;AAEzE,SAAgB,YAAY,CAAC,EAC3B,IAAI,EACJ,OAAO,EAAE,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,EAAE,EAC9C,UAAU,EACV,oBAAoB,G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O;iBACvB,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC;IAEF,OAAO;QACL,YAAY;QACZ,eAAe;QACf,iBAAiB;QACjB,kBAAkB;QAClB,oBAAoB;QACpB,aAAa;QACb,8BAA8B;KAC/B,CAAC;AACJ,CAAC"}
|
package/dist/server/server.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { type Express } from 'express';
|
|
2
|
-
import { KsAppClientDataNoMeta,
|
|
2
|
+
import { KsAppClientDataNoMeta, KnapsackMeta } from '@knapsack/types';
|
|
3
3
|
import 'isomorphic-fetch';
|
|
4
4
|
import { KnapsackBrain } from '../types/brain';
|
|
5
5
|
import { Endpoint } from '../types/endpoints';
|
|
6
|
-
export declare function getEndpoints({ getDataStore, ksBrain,
|
|
6
|
+
export declare function getEndpoints({ getDataStore, ksBrain, meta, command, }: {
|
|
7
7
|
getDataStore: () => Promise<KsAppClientDataNoMeta>;
|
|
8
8
|
ksBrain: KnapsackBrain;
|
|
9
|
+
meta: KnapsackMeta;
|
|
9
10
|
command: 'serve' | 'start';
|
|
10
|
-
discovery: GeneralDiscovery;
|
|
11
11
|
}): Promise<Endpoint<unknown, unknown>[]>;
|
|
12
|
-
export declare function getServer({ ksBrain, getDataStore, command,
|
|
12
|
+
export declare function getServer({ meta, ksBrain, getDataStore, command, }: {
|
|
13
|
+
meta: KnapsackMeta;
|
|
13
14
|
ksBrain: KnapsackBrain;
|
|
14
15
|
getDataStore: () => Promise<KsAppClientDataNoMeta>;
|
|
15
16
|
command: 'serve' | 'start';
|
|
16
|
-
discovery: GeneralDiscovery;
|
|
17
17
|
}): Promise<{
|
|
18
18
|
serve: () => void;
|
|
19
19
|
app: Express;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAgB,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,KAAK,OAAO,EAA4B,MAAM,SAAS,CAAC;AAQ1E,OAAO,EAEL,qBAAqB,EAMrB,YAAY,EACb,MAAM,iBAAiB,CAAC;AAIzB,OAAO,kBAAkB,CAAC;AAc1B,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAsD9C,wBAAsB,YAAY,CAAC,EACjC,YAAY,EACZ,OAAO,EACP,IAAI,EACJ,OAAO,GACR,EAAE;IACD,YAAY,EAAE,MAAM,OAAO,CAAC,qBAAqB,CAAC,CAAC;IACnD,OAAO,EAAE,aAAa,CAAC;IACvB,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC;CAC5B,GAAG,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,CAsJxC;AAED,wBAAsB,SAAS,CAAC,EAC9B,IAAI,EACJ,OAAO,EACP,YAAY,EACZ,OAAO,GACR,EAAE;IACD,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,EAAE,aAAa,CAAC;IACvB,YAAY,EAAE,MAAM,OAAO,CAAC,qBAAqB,CAAC,CAAC;IACnD,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC;CAC5B,GAAG,OAAO,CAAC;IACV,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,GAAG,EAAE,OAAO,CAAC;CACd,CAAC,CAyVD"}
|
package/dist/server/server.js
CHANGED
|
@@ -63,7 +63,6 @@ const static_paths_1 = require("../lib/static-paths");
|
|
|
63
63
|
const cache_dir_1 = require("../lib/util/cache-dir");
|
|
64
64
|
const utils_2 = require("../lib/utils");
|
|
65
65
|
const ks_urls_1 = require("../lib/ks-urls");
|
|
66
|
-
const api_client_1 = require("../lib/api-client");
|
|
67
66
|
const { NODE_ENV, KS_TEST_RUN, KNAPSACK_PORT, PORT } = process.env;
|
|
68
67
|
const isProd = NODE_ENV === 'production';
|
|
69
68
|
const isKsTestRun = KS_TEST_RUN === 'yes';
|
|
@@ -73,16 +72,41 @@ async function primeRenderCache({ appClientData, patterns, }) {
|
|
|
73
72
|
// patterns,
|
|
74
73
|
// });
|
|
75
74
|
}
|
|
76
|
-
|
|
75
|
+
function convertPluginConfigToPluginMeta(pluginConfig = []) {
|
|
76
|
+
return pluginConfig.map((p) => {
|
|
77
|
+
let clientPluginPath;
|
|
78
|
+
let cssPath;
|
|
79
|
+
if (p.clientPluginPath) {
|
|
80
|
+
if (p.clientPluginPath.startsWith('http') ||
|
|
81
|
+
p.clientPluginPath.startsWith('//')) {
|
|
82
|
+
clientPluginPath = p.clientPluginPath;
|
|
83
|
+
if (p.cssPath) {
|
|
84
|
+
cssPath = p.cssPath;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
clientPluginPath = (0, path_1.join)(`/plugins/${p.id}`, p.clientPluginPath);
|
|
89
|
+
if (p.cssPath) {
|
|
90
|
+
cssPath = (0, path_1.join)(`/plugins/${p.id}`, p.cssPath);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
id: p.id,
|
|
96
|
+
hasContent: !!p.loadContent,
|
|
97
|
+
clientPluginPath,
|
|
98
|
+
cssPath,
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
async function getEndpoints({ getDataStore, ksBrain, meta, command, }) {
|
|
77
103
|
var _a, _b, _c;
|
|
78
104
|
const isLocalDev = command === 'start';
|
|
79
105
|
const { patterns, config } = ksBrain;
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
authLevel: 'VIEWER',
|
|
85
|
-
handle: async () => discovery,
|
|
106
|
+
const metaState = {
|
|
107
|
+
meta,
|
|
108
|
+
isLocalDev,
|
|
109
|
+
plugins: convertPluginConfigToPluginMeta(config.plugins),
|
|
86
110
|
};
|
|
87
111
|
const regularEndpoints = (0, routes_1.setupRoutes)({
|
|
88
112
|
patterns,
|
|
@@ -91,8 +115,8 @@ async function getEndpoints({ getDataStore, ksBrain, command, discovery, }) {
|
|
|
91
115
|
const { tokensSrc } = await getDataStore();
|
|
92
116
|
const restApiEndpoints = (0, rest_api_1.getApiRoutes)({
|
|
93
117
|
ksBrain,
|
|
118
|
+
meta,
|
|
94
119
|
isLocalDev,
|
|
95
|
-
discovery,
|
|
96
120
|
collectionsParentKey: (_c = (_b = (_a = tokensSrc === null || tokensSrc === void 0 ? void 0 : tokensSrc.$extensions) === null || _a === void 0 ? void 0 : _a['cloud.knapsack']) === null || _b === void 0 ? void 0 : _b.global) === null || _c === void 0 ? void 0 : _c.collectionsParentKey,
|
|
97
121
|
});
|
|
98
122
|
const metaStateEndpoint = {
|
|
@@ -200,11 +224,9 @@ async function getEndpoints({ getDataStore, ksBrain, command, discovery, }) {
|
|
|
200
224
|
dataStoreEndpoint,
|
|
201
225
|
dataStorePrepEndpoint,
|
|
202
226
|
dataStoreSaveEndpoint,
|
|
203
|
-
discoveryEndpoint,
|
|
204
227
|
];
|
|
205
228
|
}
|
|
206
|
-
async function getServer({ ksBrain, getDataStore, command,
|
|
207
|
-
var _a;
|
|
229
|
+
async function getServer({ meta, ksBrain, getDataStore, command, }) {
|
|
208
230
|
(0, utils_2.setCliCommand)(command);
|
|
209
231
|
if (!getDataStore) {
|
|
210
232
|
throw new Error(`Tried starting the server with no "getDataStore"`);
|
|
@@ -213,10 +235,7 @@ async function getServer({ ksBrain, getDataStore, command, discovery, }) {
|
|
|
213
235
|
throw new Error('Tried starting the server with no "ksBrain"');
|
|
214
236
|
}
|
|
215
237
|
const { config } = ksBrain;
|
|
216
|
-
const port = parseInt(KNAPSACK_PORT, 10) ||
|
|
217
|
-
parseInt(PORT, 10) ||
|
|
218
|
-
discovery.metaState.meta.serverPort;
|
|
219
|
-
const siteId = (_a = ksBrain.config.cloud) === null || _a === void 0 ? void 0 : _a.siteId;
|
|
238
|
+
const port = parseInt(KNAPSACK_PORT, 10) || parseInt(PORT, 10) || meta.serverPort;
|
|
220
239
|
const app = (0, express_1.default)();
|
|
221
240
|
app.use(express_1.default.json({
|
|
222
241
|
limit: '5000kb',
|
|
@@ -245,66 +264,17 @@ async function getServer({ ksBrain, getDataStore, command, discovery, }) {
|
|
|
245
264
|
// Access-Control-Allow-Credentials CORS header. Set to true to pass the header, otherwise it is omitted.
|
|
246
265
|
credentials: true,
|
|
247
266
|
}));
|
|
248
|
-
function createAuthMiddleware(endpoint) {
|
|
249
|
-
return async (req, res, next) => {
|
|
250
|
-
if (!endpoint.authLevel) {
|
|
251
|
-
next();
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
if (command !== 'serve') {
|
|
255
|
-
next();
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
try {
|
|
259
|
-
if (!siteId) {
|
|
260
|
-
// Missing siteId: return 401 rather than forwarding "undefined"
|
|
261
|
-
res
|
|
262
|
-
.status(constants_1.HTTP_STATUS.BAD.UNAUTHORIZED)
|
|
263
|
-
.send('Unauthorized, missing siteId in "config.cloud.siteId"');
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
const authHeader = req.header('authorization');
|
|
267
|
-
const { isSitePrivate, role } = await (0, api_client_1.authCheck)({
|
|
268
|
-
authHeader,
|
|
269
|
-
siteId,
|
|
270
|
-
});
|
|
271
|
-
switch (endpoint.authLevel) {
|
|
272
|
-
case 'VIEWER': {
|
|
273
|
-
// @todo switch to `canRoleView` when this is done: KSP-6412
|
|
274
|
-
const isAnonymous = role === 'ANONYMOUS';
|
|
275
|
-
const willAllow = isSitePrivate ? !isAnonymous : true;
|
|
276
|
-
if (!willAllow) {
|
|
277
|
-
// not calling `next` here b/c we're done and returning a response
|
|
278
|
-
res.status(constants_1.HTTP_STATUS.BAD.UNAUTHORIZED).send('Unauthorized');
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
break;
|
|
282
|
-
}
|
|
283
|
-
default: {
|
|
284
|
-
const _check = endpoint.authLevel;
|
|
285
|
-
next(new Error(`Unsupported authLevel: ${_check}`));
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
catch (e) {
|
|
291
|
-
next(e);
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
next();
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
267
|
const endpoints = await getEndpoints({
|
|
298
268
|
ksBrain,
|
|
299
269
|
getDataStore,
|
|
270
|
+
meta,
|
|
300
271
|
command,
|
|
301
|
-
discovery,
|
|
302
272
|
});
|
|
303
273
|
log_1.log.verbose(`API Endpoints`, endpoints.map(({ path, method }) => ({ path, method })));
|
|
304
274
|
endpoints.forEach((endpoint) => {
|
|
305
275
|
switch (endpoint.method) {
|
|
306
276
|
case 'GET':
|
|
307
|
-
app.get(endpoint.path,
|
|
277
|
+
app.get(endpoint.path, async (req, res, next) => {
|
|
308
278
|
var _a;
|
|
309
279
|
try {
|
|
310
280
|
(_a = endpoint.validateQuery) === null || _a === void 0 ? void 0 : _a.call(endpoint, req.query);
|
|
@@ -331,7 +301,7 @@ async function getServer({ ksBrain, getDataStore, command, discovery, }) {
|
|
|
331
301
|
});
|
|
332
302
|
break;
|
|
333
303
|
case 'POST':
|
|
334
|
-
app.post(endpoint.path,
|
|
304
|
+
app.post(endpoint.path, async (req, res, next) => {
|
|
335
305
|
var _a;
|
|
336
306
|
try {
|
|
337
307
|
(_a = endpoint.validateBody) === null || _a === void 0 ? void 0 : _a.call(endpoint, req.body);
|
|
@@ -420,7 +390,6 @@ async function getServer({ ksBrain, getDataStore, command, discovery, }) {
|
|
|
420
390
|
async function serve() {
|
|
421
391
|
const { note } = await import('@clack/prompts');
|
|
422
392
|
let server;
|
|
423
|
-
const { meta } = discovery.metaState;
|
|
424
393
|
if (meta.https && meta.ssl) {
|
|
425
394
|
server = https.createServer(meta.ssl, app);
|
|
426
395
|
}
|
|
@@ -463,9 +432,14 @@ async function getServer({ ksBrain, getDataStore, command, discovery, }) {
|
|
|
463
432
|
// Let the api know the deployment is live
|
|
464
433
|
try {
|
|
465
434
|
const siteDeployedEndpoint = new URL(core_1.siteDeployedWebhookEndpoint, ks_urls_1.ksUrls.apiOrigin);
|
|
435
|
+
const siteId = meta.knapsackCloudSiteId;
|
|
466
436
|
// this is fire & forget so we are not using `await`
|
|
467
437
|
getDataStore().then((dataStore) => {
|
|
468
|
-
const
|
|
438
|
+
const metaState = {
|
|
439
|
+
meta,
|
|
440
|
+
isLocalDev: false,
|
|
441
|
+
plugins: convertPluginConfigToPluginMeta(config.plugins),
|
|
442
|
+
};
|
|
469
443
|
const body = {
|
|
470
444
|
siteId,
|
|
471
445
|
appClientData: { ...dataStore, metaState },
|