jitsu-cli 1.10.4 → 1.11.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/bin/jitsu +3 -0
- package/build.mts +39 -0
- package/compiled/package.json +27 -29
- package/compiled/src/commands/build.js +43 -55
- package/compiled/src/commands/config/handlers.js +292 -0
- package/compiled/src/commands/config/index.js +148 -0
- package/compiled/src/commands/config/resources.js +88 -0
- package/compiled/src/commands/default-workspace.js +39 -0
- package/compiled/src/commands/deploy.js +127 -78
- package/compiled/src/commands/init.js +17 -21
- package/compiled/src/commands/login.js +24 -27
- package/compiled/src/commands/shared.js +12 -17
- package/compiled/src/commands/spec.js +31 -0
- package/compiled/src/commands/test.js +7 -10
- package/compiled/src/commands/whoami.js +8 -12
- package/compiled/src/index.js +40 -24
- package/compiled/src/lib/api-client.js +52 -0
- package/compiled/src/lib/auth-file.js +67 -0
- package/compiled/src/lib/body-builder.js +53 -0
- package/compiled/src/lib/body-fields.js +47 -0
- package/compiled/src/lib/chalk-code-highlight.js +15 -20
- package/compiled/src/lib/compiled-function.js +27 -29
- package/compiled/src/lib/dotted.js +34 -0
- package/compiled/src/lib/indent.js +3 -8
- package/compiled/src/lib/project-config.js +20 -0
- package/compiled/src/lib/renderer.js +33 -0
- package/compiled/src/lib/spec.js +11 -0
- package/compiled/src/lib/template.js +7 -11
- package/compiled/src/lib/version.js +13 -20
- package/compiled/src/templates/functions.js +13 -18
- package/dist/main.js +45496 -86270
- package/dist/main.js.map +7 -1
- package/package.json +27 -29
- package/src/commands/build.ts +22 -27
- package/src/commands/config/handlers.ts +339 -0
- package/src/commands/config/index.ts +171 -0
- package/src/commands/config/resources.ts +110 -0
- package/src/commands/default-workspace.ts +44 -0
- package/src/commands/deploy.ts +145 -44
- package/src/commands/login.ts +3 -1
- package/src/commands/spec.ts +32 -0
- package/src/index.ts +36 -19
- package/src/lib/api-client.ts +64 -0
- package/src/lib/auth-file.ts +83 -0
- package/src/lib/body-builder.ts +68 -0
- package/src/lib/body-fields.ts +61 -0
- package/src/lib/compiled-function.ts +30 -23
- package/src/lib/dotted.ts +43 -0
- package/src/lib/project-config.ts +32 -0
- package/src/lib/renderer.ts +44 -0
- package/src/lib/spec.ts +32 -0
- package/tsconfig.json +2 -19
- package/.turbo/turbo-build.log +0 -28
- package/.turbo/turbo-clean.log +0 -5
- package/babel.config.cjs +0 -4
- package/dist/140.js +0 -452
- package/dist/140.js.map +0 -1
- package/dist/233.js +0 -4890
- package/dist/233.js.map +0 -1
- package/dist/445e7f36f8a19c2bf682.js +0 -900
- package/webpack.config.js +0 -49
|
@@ -1,37 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
6
|
-
const rollup_1 = require("rollup");
|
|
7
|
-
const juava_1 = require("juava");
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import * as esbuild from "esbuild";
|
|
3
|
+
import { assertDefined, assertTrue } from "juava";
|
|
8
4
|
function getSlug(filePath) {
|
|
9
|
-
return filePath.split("/").pop()?.replace(".ts", "");
|
|
5
|
+
return filePath.split("/").pop()?.replace(".ts", "").replace(".js", "");
|
|
10
6
|
}
|
|
11
|
-
async function getFunctionFromFilePath(filePath, kind, profileBuilders = []) {
|
|
12
|
-
if (!
|
|
7
|
+
export async function getFunctionFromFilePath(projectDir, filePath, kind, profileBuilders = []) {
|
|
8
|
+
if (!fs.existsSync(filePath)) {
|
|
13
9
|
throw new Error(`Cannot load function from file ${filePath}: file doesn't exist`);
|
|
14
10
|
}
|
|
15
|
-
else if (!
|
|
11
|
+
else if (!fs.statSync(filePath).isFile()) {
|
|
16
12
|
throw new Error(`Cannot load function from file ${filePath}: path is not a file`);
|
|
17
13
|
}
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
const result = await esbuild.transform(fs.readFileSync(filePath, "utf-8"), {
|
|
15
|
+
loader: filePath.endsWith(".ts") ? "ts" : "js",
|
|
16
|
+
format: "cjs",
|
|
17
|
+
platform: "node",
|
|
22
18
|
});
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
19
|
+
const code = result.code;
|
|
20
|
+
const module = { exports: {} };
|
|
21
|
+
const exports = module.exports;
|
|
22
|
+
const require = (id) => {
|
|
23
|
+
return {};
|
|
24
|
+
};
|
|
25
|
+
eval(code);
|
|
26
|
+
const moduleExports = module.exports;
|
|
27
|
+
assertDefined(moduleExports.default, `Function from ${filePath} doesn't have default export. Exported symbols: ${Object.keys(moduleExports)}`);
|
|
28
|
+
assertTrue(typeof moduleExports.default === "function", `Default export from ${filePath} is not a function`);
|
|
29
|
+
let name = moduleExports.config?.name || moduleExports.config?.slug || getSlug(filePath);
|
|
30
|
+
let id = moduleExports.config?.id;
|
|
33
31
|
if (kind === "profile") {
|
|
34
|
-
const profileBuilderId =
|
|
32
|
+
const profileBuilderId = moduleExports.config?.profileBuilderId;
|
|
35
33
|
const profileBuilder = profileBuilders.find(pb => pb.id === profileBuilderId);
|
|
36
34
|
if (!profileBuilder) {
|
|
37
35
|
throw new Error(`Cannot find profile builder with id ${profileBuilderId} for profile function ${filePath}. Please setup Profile Builder in UI first.`);
|
|
@@ -43,12 +41,12 @@ async function getFunctionFromFilePath(filePath, kind, profileBuilders = []) {
|
|
|
43
41
|
}
|
|
44
42
|
}
|
|
45
43
|
return {
|
|
46
|
-
func:
|
|
44
|
+
func: moduleExports.default,
|
|
47
45
|
meta: {
|
|
48
|
-
slug:
|
|
46
|
+
slug: moduleExports.config?.slug || getSlug(filePath),
|
|
49
47
|
id: id,
|
|
50
48
|
name: name,
|
|
51
|
-
description:
|
|
49
|
+
description: moduleExports.config?.description,
|
|
52
50
|
},
|
|
53
51
|
};
|
|
54
52
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function parseScalar(raw) {
|
|
2
|
+
if (raw === "")
|
|
3
|
+
return "";
|
|
4
|
+
const trimmed = raw.trim();
|
|
5
|
+
const first = trimmed[0];
|
|
6
|
+
const looksLikeJson = first === "{" ||
|
|
7
|
+
first === "[" ||
|
|
8
|
+
first === '"' ||
|
|
9
|
+
trimmed === "true" ||
|
|
10
|
+
trimmed === "false" ||
|
|
11
|
+
trimmed === "null" ||
|
|
12
|
+
/^-?\d/.test(trimmed);
|
|
13
|
+
if (looksLikeJson) {
|
|
14
|
+
try {
|
|
15
|
+
return JSON.parse(trimmed);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return raw;
|
|
21
|
+
}
|
|
22
|
+
export function setDottedPath(target, path, value) {
|
|
23
|
+
const parts = path.split(".");
|
|
24
|
+
let node = target;
|
|
25
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
26
|
+
const key = parts[i];
|
|
27
|
+
if (node[key] == null || typeof node[key] !== "object" || Array.isArray(node[key])) {
|
|
28
|
+
node[key] = {};
|
|
29
|
+
}
|
|
30
|
+
node = node[key];
|
|
31
|
+
}
|
|
32
|
+
node[parts[parts.length - 1]] = value;
|
|
33
|
+
return target;
|
|
34
|
+
}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.removeIndentation = removeIndentation;
|
|
4
|
-
exports.align = align;
|
|
5
|
-
exports.jsonify = jsonify;
|
|
6
1
|
function getIndentSize(line) {
|
|
7
2
|
let idx = 0;
|
|
8
3
|
for (; line.charAt(idx) === " " && idx < line.length; idx++) { }
|
|
9
4
|
return idx;
|
|
10
5
|
}
|
|
11
|
-
function removeIndentation(text, { trimLines = true } = {}) {
|
|
6
|
+
export function removeIndentation(text, { trimLines = true } = {}) {
|
|
12
7
|
let lines = text.split("\n");
|
|
13
8
|
if (trimLines) {
|
|
14
9
|
let start = 0, end = lines.length - 1;
|
|
@@ -19,7 +14,7 @@ function removeIndentation(text, { trimLines = true } = {}) {
|
|
|
19
14
|
let commonIndent = Math.min(...lines.filter(ln => ln.trim().length > 0).map(getIndentSize));
|
|
20
15
|
return lines.map(ln => ln.substring(commonIndent)).join("\n");
|
|
21
16
|
}
|
|
22
|
-
function align(text, { indent = 0, lnBefore = 0, lnAfter = 0 } = {}) {
|
|
17
|
+
export function align(text, { indent = 0, lnBefore = 0, lnAfter = 0 } = {}) {
|
|
23
18
|
const cleanText = removeIndentation(text, { trimLines: true });
|
|
24
19
|
return [
|
|
25
20
|
...new Array(lnBefore).fill(""),
|
|
@@ -27,7 +22,7 @@ function align(text, { indent = 0, lnBefore = 0, lnAfter = 0 } = {}) {
|
|
|
27
22
|
...new Array(lnAfter).fill(""),
|
|
28
23
|
].join("\n");
|
|
29
24
|
}
|
|
30
|
-
function jsonify(obj) {
|
|
25
|
+
export function jsonify(obj) {
|
|
31
26
|
if (typeof obj === "string") {
|
|
32
27
|
try {
|
|
33
28
|
return JSON.parse(obj);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { existsSync, readFileSync } from "fs";
|
|
3
|
+
import { b } from "./chalk-code-highlight";
|
|
4
|
+
export function loadProjectConfig(projectDir, packageJson) {
|
|
5
|
+
const jitsuJsonPath = path.resolve(projectDir, "jitsu.json");
|
|
6
|
+
if (existsSync(jitsuJsonPath)) {
|
|
7
|
+
let parsed;
|
|
8
|
+
try {
|
|
9
|
+
parsed = JSON.parse(readFileSync(jitsuJsonPath, "utf-8"));
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
throw new Error(`Failed to parse ${b(jitsuJsonPath)}: ${e instanceof Error ? e.message : String(e)}`);
|
|
13
|
+
}
|
|
14
|
+
return parsed ?? {};
|
|
15
|
+
}
|
|
16
|
+
if (packageJson?.jitsu && typeof packageJson.jitsu === "object") {
|
|
17
|
+
return packageJson.jitsu;
|
|
18
|
+
}
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import yaml from "js-yaml";
|
|
2
|
+
const renderers = {
|
|
3
|
+
yaml: {
|
|
4
|
+
format: "yaml",
|
|
5
|
+
render(value) {
|
|
6
|
+
if (value === undefined)
|
|
7
|
+
return "";
|
|
8
|
+
return yaml.dump(value, { skipInvalid: true, noRefs: true, sortKeys: false, lineWidth: 120 });
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
json: {
|
|
12
|
+
format: "json",
|
|
13
|
+
render(value) {
|
|
14
|
+
return JSON.stringify(value, null, 2) + "\n";
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
export const SUPPORTED_OUTPUTS = Object.keys(renderers);
|
|
19
|
+
export const DEFAULT_OUTPUT = "yaml";
|
|
20
|
+
export function getRenderer(format) {
|
|
21
|
+
const key = (format ?? DEFAULT_OUTPUT).toLowerCase();
|
|
22
|
+
const r = renderers[key];
|
|
23
|
+
if (!r) {
|
|
24
|
+
throw new Error(`Unsupported output format '${format}'. Supported: ${SUPPORTED_OUTPUTS.join(", ")}`);
|
|
25
|
+
}
|
|
26
|
+
return r;
|
|
27
|
+
}
|
|
28
|
+
export function registerRenderer(r) {
|
|
29
|
+
renderers[r.format.toLowerCase()] = r;
|
|
30
|
+
}
|
|
31
|
+
export function print(value, format) {
|
|
32
|
+
process.stdout.write(getRenderer(format).render(value));
|
|
33
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ApiClient } from "./api-client";
|
|
2
|
+
export async function fetchSpec(auth) {
|
|
3
|
+
const client = new ApiClient(auth);
|
|
4
|
+
return client.request({ method: "GET", path: "/api/spec" });
|
|
5
|
+
}
|
|
6
|
+
export function findOperation(spec, path, method) {
|
|
7
|
+
const item = spec.paths?.[path];
|
|
8
|
+
if (!item)
|
|
9
|
+
return undefined;
|
|
10
|
+
return item[method.toLowerCase()];
|
|
11
|
+
}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
6
|
-
const fs = tslib_1.__importStar(require("fs"));
|
|
7
|
-
const indent_1 = require("./indent");
|
|
1
|
+
import path from "path";
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import { removeIndentation } from "./indent";
|
|
8
4
|
function toTemplateFunction(template) {
|
|
9
5
|
if (template === null || template === undefined) {
|
|
10
6
|
return () => undefined;
|
|
@@ -16,10 +12,10 @@ function toTemplateFunction(template) {
|
|
|
16
12
|
return () => template;
|
|
17
13
|
}
|
|
18
14
|
}
|
|
19
|
-
function write(dir, template, vars) {
|
|
15
|
+
export function write(dir, template, vars) {
|
|
20
16
|
Object.entries(template(vars)).forEach(([fileName, template]) => {
|
|
21
|
-
let filePath =
|
|
22
|
-
let fileDir =
|
|
17
|
+
let filePath = path.resolve(dir, fileName);
|
|
18
|
+
let fileDir = path.dirname(filePath);
|
|
23
19
|
if (!fs.existsSync(fileDir)) {
|
|
24
20
|
fs.mkdirSync(fileDir, { recursive: true });
|
|
25
21
|
}
|
|
@@ -28,7 +24,7 @@ function write(dir, template, vars) {
|
|
|
28
24
|
content = JSON.stringify(content, null, 2);
|
|
29
25
|
}
|
|
30
26
|
if (content) {
|
|
31
|
-
let data =
|
|
27
|
+
let data = removeIndentation(content);
|
|
32
28
|
fs.writeFileSync(filePath, data);
|
|
33
29
|
}
|
|
34
30
|
});
|
|
@@ -1,35 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
exports.box = box;
|
|
6
|
-
exports.hasNewerVersion = hasNewerVersion;
|
|
7
|
-
const tslib_1 = require("tslib");
|
|
8
|
-
const package_json_1 = tslib_1.__importDefault(require("../../package.json"));
|
|
9
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
10
|
-
const preload_1 = tslib_1.__importDefault(require("semver/preload"));
|
|
11
|
-
const chalk_code_highlight_1 = require("./chalk-code-highlight");
|
|
1
|
+
import pkg from "../../package.json";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import semver from "semver/preload";
|
|
4
|
+
import { b } from "./chalk-code-highlight";
|
|
12
5
|
const fetch = require("cross-fetch");
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
export const jitsuCliVersion = pkg.version;
|
|
7
|
+
export const jitsuCliPackageName = pkg.name;
|
|
15
8
|
let newVersion = undefined;
|
|
16
|
-
function getUpgradeMessage(newVersion, oldVersion) {
|
|
17
|
-
return box(`🚀 New version of Jitsu CLI is available: ${oldVersion} → ${
|
|
9
|
+
export function getUpgradeMessage(newVersion, oldVersion) {
|
|
10
|
+
return box(`🚀 New version of Jitsu CLI is available: ${oldVersion} → ${chalk.green(newVersion)} \n Run ${b("npm install -g " + jitsuCliPackageName)} or ${b("yarn global install " + jitsuCliPackageName)}`);
|
|
18
11
|
}
|
|
19
12
|
function padRight(str, minLen, symbol = " ") {
|
|
20
13
|
return str.length >= minLen ? str : str + symbol.repeat(minLen - str.length);
|
|
21
14
|
}
|
|
22
|
-
function box(msg) {
|
|
15
|
+
export function box(msg) {
|
|
23
16
|
let lines = msg.split("\n");
|
|
24
17
|
return ["──".repeat(80), ...lines.map(ln => ` ${ln}`), "──".repeat(80)].join("\n");
|
|
25
18
|
}
|
|
26
|
-
async function hasNewerVersion() {
|
|
19
|
+
export async function hasNewerVersion() {
|
|
27
20
|
try {
|
|
28
|
-
let json = (await (await fetch(`https://registry.npmjs.org/-/package/${
|
|
21
|
+
let json = (await (await fetch(`https://registry.npmjs.org/-/package/${jitsuCliPackageName}/dist-tags`)).json());
|
|
29
22
|
let latestVersion = json.latest;
|
|
30
|
-
return
|
|
23
|
+
return semver.gt(latestVersion, jitsuCliVersion) ? latestVersion : undefined;
|
|
31
24
|
}
|
|
32
25
|
catch (e) {
|
|
33
|
-
console.debug(`Failed to fetch latest version of ${
|
|
26
|
+
console.debug(`Failed to fetch latest version of ${jitsuCliPackageName}: ${e?.message}`);
|
|
34
27
|
}
|
|
35
28
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const version_1 = require("../lib/version");
|
|
5
|
-
const juava_1 = require("juava");
|
|
6
|
-
const packageJsonTemplate = ({ packageName, license = "MIT", jitsuVersion = undefined }) => ({
|
|
1
|
+
import { jitsuCliVersion, jitsuCliPackageName } from "../lib/version";
|
|
2
|
+
import { sanitize } from "juava";
|
|
3
|
+
export const packageJsonTemplate = ({ packageName, license = "MIT", jitsuVersion = undefined }) => ({
|
|
7
4
|
name: `${packageName}`,
|
|
8
5
|
version: "0.0.1",
|
|
9
6
|
description: `Jitsu extension - ${packageName}`,
|
|
@@ -11,23 +8,22 @@ const packageJsonTemplate = ({ packageName, license = "MIT", jitsuVersion = unde
|
|
|
11
8
|
keywords: ["jitsu", "jitsu-cli", "function", `jitsu-extension`],
|
|
12
9
|
scripts: {
|
|
13
10
|
clean: "rm -rf ./dist",
|
|
14
|
-
build: `${
|
|
15
|
-
test: `${
|
|
16
|
-
deploy: `${
|
|
11
|
+
build: `${jitsuCliPackageName} build`,
|
|
12
|
+
test: `${jitsuCliPackageName} test`,
|
|
13
|
+
deploy: `${jitsuCliPackageName} deploy`,
|
|
17
14
|
},
|
|
18
15
|
devDependencies: {
|
|
19
|
-
"jitsu-cli": `${jitsuVersion || "^" +
|
|
20
|
-
"@jitsu/protocols": `${jitsuVersion || "^" +
|
|
21
|
-
"@jitsu/functions-lib": `${jitsuVersion || "^" +
|
|
16
|
+
"jitsu-cli": `${jitsuVersion || "^" + jitsuCliVersion}`,
|
|
17
|
+
"@jitsu/protocols": `${jitsuVersion || "^" + jitsuCliVersion}`,
|
|
18
|
+
"@jitsu/functions-lib": `${jitsuVersion || "^" + jitsuCliVersion}`,
|
|
22
19
|
"@types/jest": "^29.5.5",
|
|
23
20
|
"ts-jest": "^29.1.1",
|
|
24
21
|
},
|
|
25
22
|
dependencies: {},
|
|
26
23
|
});
|
|
27
|
-
exports.packageJsonTemplate = packageJsonTemplate;
|
|
28
24
|
let functionTest = ({ packageName }) => {
|
|
29
25
|
return `
|
|
30
|
-
test("${
|
|
26
|
+
test("${sanitize(packageName)} test", () => {
|
|
31
27
|
//TODO: implement test
|
|
32
28
|
});
|
|
33
29
|
`;
|
|
@@ -55,7 +51,7 @@ export default helloWorldFunction;
|
|
|
55
51
|
};
|
|
56
52
|
let profileTest = ({ packageName }) => {
|
|
57
53
|
return `
|
|
58
|
-
test("${
|
|
54
|
+
test("${sanitize(packageName)} test", () => {
|
|
59
55
|
//TODO: implement test
|
|
60
56
|
});
|
|
61
57
|
`;
|
|
@@ -85,12 +81,12 @@ const profileExample: ProfileFunction = async (events, user, context) => {
|
|
|
85
81
|
export default profileExample;
|
|
86
82
|
`;
|
|
87
83
|
};
|
|
88
|
-
const functionProjectTemplate = ({ packageName }) => ({
|
|
84
|
+
export const functionProjectTemplate = ({ packageName }) => ({
|
|
89
85
|
[`__tests__/profiles/profile-example.test.ts`]: profileTest,
|
|
90
86
|
[`__tests__/functions/hello.test.ts`]: functionTest,
|
|
91
87
|
[`src/profiles/profile-example.ts`]: profileCode,
|
|
92
88
|
[`src/functions/hello.ts`]: functionCode,
|
|
93
|
-
"package.json":
|
|
89
|
+
"package.json": packageJsonTemplate,
|
|
94
90
|
"tsconfig.json": {
|
|
95
91
|
compilerOptions: {
|
|
96
92
|
rootDir: "./src",
|
|
@@ -108,4 +104,3 @@ const functionProjectTemplate = ({ packageName }) => ({
|
|
|
108
104
|
exclude: ["__tests__", "node_modules", "dist"],
|
|
109
105
|
},
|
|
110
106
|
});
|
|
111
|
-
exports.functionProjectTemplate = functionProjectTemplate;
|