jitsu-cli 0.9.0 → 1.2.0-canary.231.20230920065613

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.
Files changed (78) hide show
  1. package/.turbo/turbo-build.log +112 -0
  2. package/LICENSE +1 -1
  3. package/babel.config.cjs +4 -0
  4. package/bin/jitsu-cli +1 -1
  5. package/compiled/package.json +66 -0
  6. package/compiled/src/commands/build.js +55 -0
  7. package/compiled/src/commands/deploy.js +124 -0
  8. package/compiled/src/commands/init.js +38 -0
  9. package/compiled/src/commands/login.js +94 -0
  10. package/compiled/src/commands/run.js +87 -0
  11. package/compiled/src/commands/shared.js +26 -0
  12. package/{lib/cli/extension → compiled/src/commands}/template.js +43 -41
  13. package/compiled/src/commands/test.js +15 -0
  14. package/compiled/src/index.js +49 -0
  15. package/{lib → compiled/src}/lib/log.js +7 -6
  16. package/{lib → compiled/src}/lib/template.js +1 -1
  17. package/{lib → compiled/src}/lib/version.js +1 -2
  18. package/compiled/src/templates/functions.js +67 -0
  19. package/dist/10546bf325e211cf9719.js +886 -0
  20. package/dist/1463a26331df3b0b4d694b076097b2dd.node +0 -0
  21. package/dist/230.js +4890 -0
  22. package/dist/230.js.map +1 -0
  23. package/dist/535.js +112 -0
  24. package/dist/535.js.map +1 -0
  25. package/dist/718.js +452 -0
  26. package/dist/718.js.map +1 -0
  27. package/dist/main.js +350126 -0
  28. package/dist/main.js.map +1 -0
  29. package/package.json +53 -60
  30. package/src/commands/build.ts +63 -0
  31. package/src/commands/deploy.ts +126 -0
  32. package/src/commands/init.ts +45 -0
  33. package/src/commands/login.ts +91 -0
  34. package/src/commands/run.ts +85 -0
  35. package/src/commands/shared.ts +26 -0
  36. package/src/commands/test.ts +16 -0
  37. package/src/index.ts +69 -0
  38. package/src/lib/chalk-code-highlight.ts +46 -0
  39. package/src/lib/indent.ts +42 -0
  40. package/src/lib/template.ts +37 -0
  41. package/src/lib/version.ts +35 -0
  42. package/src/templates/functions.ts +73 -0
  43. package/tsconfig.json +28 -0
  44. package/webpack.config.js +43 -0
  45. package/README.md +0 -11
  46. package/lib/cli/extension/build.d.ts +0 -2
  47. package/lib/cli/extension/build.js +0 -137
  48. package/lib/cli/extension/create.d.ts +0 -2
  49. package/lib/cli/extension/create.js +0 -92
  50. package/lib/cli/extension/exec.d.ts +0 -3
  51. package/lib/cli/extension/exec.js +0 -296
  52. package/lib/cli/extension/index.d.ts +0 -9
  53. package/lib/cli/extension/index.js +0 -147
  54. package/lib/cli/extension/template.d.ts +0 -30
  55. package/lib/cli/extension/test.d.ts +0 -2
  56. package/lib/cli/extension/test.js +0 -34
  57. package/lib/cli/extension/validate-config.d.ts +0 -2
  58. package/lib/cli/extension/validate-config.js +0 -62
  59. package/lib/index.d.ts +0 -1
  60. package/lib/index.js +0 -7
  61. package/lib/lib/chalk-code-highlight.d.ts +0 -14
  62. package/lib/lib/command/index.d.ts +0 -3
  63. package/lib/lib/command/index.js +0 -118
  64. package/lib/lib/errors.d.ts +0 -1
  65. package/lib/lib/indent.d.ts +0 -9
  66. package/lib/lib/log.d.ts +0 -8
  67. package/lib/lib/template.d.ts +0 -5
  68. package/lib/lib/validation.d.ts +0 -2
  69. package/lib/lib/validation.js +0 -23
  70. package/lib/lib/version.d.ts +0 -5
  71. package/lib/package.json +0 -73
  72. package/lib/run.d.ts +0 -1
  73. package/lib/run.js +0 -37
  74. package/lib/tests.d.ts +0 -2
  75. package/lib/tests.js +0 -10
  76. /package/{lib → compiled/src}/lib/chalk-code-highlight.js +0 -0
  77. /package/{lib → compiled/src}/lib/errors.js +0 -0
  78. /package/{lib → compiled/src}/lib/indent.js +0 -0
@@ -1,29 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extensionProjectTemplate = exports.packageJsonTemplate = void 0;
4
- const version_1 = require("../../lib/version");
5
- const packageJsonTemplate = ({ packageName, type, jitsuVersion = undefined }) => ({
6
- name: `${packageName}`,
7
- version: "0.0.1",
8
- description: `Jitsu ${type} - ${packageName}`,
9
- main: `dist/${packageName}.js`,
10
- scripts: {
11
- clean: "rm -rf ./dist",
12
- build: "jitsu-cli extension build",
13
- test: "jitsu-cli extension test",
14
- "validate-config": "jitsu-cli extension validate-config",
15
- execute: `jitsu-cli extension ${type == "destination" ? "exec" : "exec-src"}`,
16
- },
17
- devDependencies: {
18
- "@jitsu/types": `${jitsuVersion || "^" + version_1.jitsuCliVersion}`,
19
- "@jitsu/jlib": `${jitsuVersion || "^" + version_1.jitsuCliVersion}`,
20
- "ts-jest": "^27.0.7",
21
- "jitsu-cli": `${jitsuVersion || "^" + version_1.jitsuCliVersion}`,
22
- tslib: "^2.3.1",
23
- typescript: "^4.5.2",
24
- },
25
- dependencies: {},
26
- });
4
+ const version_1 = require("../lib/version");
5
+ const index_1 = require("../index");
6
+ const packageJsonTemplate = ({ packageName, type, jitsuVersion = undefined }) => {
7
+ const res = {
8
+ name: `${packageName}`,
9
+ version: "0.0.1",
10
+ description: `Jitsu ${type} - ${packageName}`,
11
+ keywords: ["jitsu", "extension", `jitsu-${type}-extension`],
12
+ main: `dist/${packageName}.js`,
13
+ scripts: {
14
+ clean: "rm -rf ./dist",
15
+ build: `${index_1.binName} extension build`,
16
+ test: `${index_1.binName} extension test`,
17
+ execute: `${index_1.binName} extension exec`,
18
+ },
19
+ devDependencies: {
20
+ "@jitsu/types": `${jitsuVersion || "^" + version_1.jitsuCliVersion}`,
21
+ "@jitsu/jlib": `${jitsuVersion || "^" + version_1.jitsuCliVersion}`,
22
+ "ts-jest": "^27.0.7",
23
+ [index_1.binName]: `${jitsuVersion || "^" + version_1.jitsuCliVersion}`,
24
+ tslib: "^2.3.1",
25
+ typescript: "^4.5.2",
26
+ },
27
+ dependencies: {},
28
+ };
29
+ if (type === "destination" || type === "source") {
30
+ res.scripts["validate-config"] = `${index_1.binName} extension validate-config`;
31
+ }
32
+ return res;
33
+ };
27
34
  exports.packageJsonTemplate = packageJsonTemplate;
28
35
  let destinationTest = ({ type = "destination" }) => {
29
36
  if (type !== "destination") {
@@ -31,7 +38,7 @@ let destinationTest = ({ type = "destination" }) => {
31
38
  }
32
39
  return `
33
40
  import { JitsuDestinationContext } from "@jitsu/types/extension"
34
- import { testDestination } from "jitsu-cli/lib/tests"
41
+ import { testDestination } from "${index_1.binName}/lib/tests"
35
42
  import { destination } from "../src"
36
43
 
37
44
  testDestination({
@@ -171,15 +178,15 @@ let sourceCode = () => {
171
178
  };
172
179
  let transformCode = () => {
173
180
  return `
174
- import {Destination, DestinationMessage, JitsuDestinationContext} from "@jitsu/types/destination";
181
+ import {TransformationFunction} from "@jitsu/types/extension";
175
182
  import {DefaultJitsuEvent} from "@jitsu/types/event";
176
-
183
+
177
184
  //duplicate events
178
185
  const transform: TransformationFunction = (event: DefaultJitsuEvent) => {
179
186
  return [event, {...event, eventn_ctx_event_id: event.eventn_ctx_event_id + "_2"}]
180
187
  }
181
-
182
- export default jitsuAdapter;
188
+
189
+ export default transform;
183
190
  `;
184
191
  };
185
192
  let descriptor = {};
@@ -191,7 +198,7 @@ descriptor["destination"] = (vars) => `
191
198
  id: "${vars.packageName}",
192
199
  displayName: "${vars.packageName}",
193
200
  icon: "",
194
- description: "Jitsu destination - ${vars.packageName} (generated by 'jitsu-cli extension create')",
201
+ description: "Jitsu destination - ${vars.packageName} (generated by \`${index_1.binName} extension create\`)",
195
202
  configurationParameters: [
196
203
  {id: "exampleParam", type: "string", required: true, displayName: "Example param", documentation: "Documentation"}
197
204
  ],
@@ -200,22 +207,17 @@ descriptor["destination"] = (vars) => `
200
207
  export { descriptor, destination, validator };
201
208
  `;
202
209
  descriptor["transform"] = (vars) => `
203
- import {DestinationAdapter, DestinationDescriptor} from "@jitsu/types/destination";
204
- import jitsuAdapter from "./adapter";
205
-
206
- const adapter: DestinationAdapter = jitsuAdapter
207
-
208
- const descriptor: DestinationDescriptor = {
209
- type: "${vars.packageName}",
210
+ import {ExtensionDescriptor} from "@jitsu/types/extension";
211
+ import transform from "./transform";
212
+
213
+ const descriptor: ExtensionDescriptor = {
214
+ id: "${vars.packageName}",
210
215
  displayName: "${vars.packageName}",
211
216
  icon: "",
212
- description: "Jitsu ${vars.type} - ${vars.packageName} (generated by 'jitsu-cli extension create)'",
213
- configurationParameters: [
214
- //put configuration here
215
- ]
217
+ description: "Jitsu ${vars.type} - ${vars.packageName} (generated by \`${index_1.binName} extension create)\`"
216
218
  }
217
219
 
218
- export {descriptor, adapter}
220
+ export {descriptor, transform}
219
221
  `;
220
222
  exports.extensionProjectTemplate = {
221
223
  "__test__/destination.test.ts": destinationTest,
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.test = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
+ const jest_cli_1 = require("jest-cli");
7
+ const shared_1 = require("./shared");
8
+ async function test({ dir }) {
9
+ const projectDir = dir || process.cwd();
10
+ console.log(`Running tests in ${chalk_1.default.bold(projectDir)}`);
11
+ const packageJson = (0, shared_1.loadPackageJson)(projectDir);
12
+ const jestArgs = ["--passWithNoTests", "--projects", projectDir, "--preset", "ts-jest"];
13
+ await (0, jest_cli_1.run)(jestArgs);
14
+ }
15
+ exports.test = test;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const figlet_1 = tslib_1.__importDefault(require("figlet"));
5
+ const commander_1 = require("commander");
6
+ const login_1 = require("./commands/login");
7
+ const deploy_1 = require("./commands/deploy");
8
+ const init_1 = require("./commands/init");
9
+ const build_1 = require("./commands/build");
10
+ const test_1 = require("./commands/test");
11
+ const run_1 = require("./commands/run");
12
+ const version_1 = require("./lib/version");
13
+ console.log(figlet_1.default.textSync("Jitsu CLI", { horizontalLayout: "full" }));
14
+ const p = new commander_1.Command();
15
+ p.name(version_1.jitsuPackageName).description("CLI command to create, test and deploy extensions for Jitsu Next");
16
+ p.command("init")
17
+ .description("Initialize a new Jitsu extension project")
18
+ .option("-n, --name <name>", "the name of the project. (Optional). By default, interactive prompt is shown to enter the name.")
19
+ .option("-p, --parent <dir>", "the parent directory of project. (Optional). By default, interactive prompt is shown to enter the parent directory.")
20
+ .action(init_1.init);
21
+ p.command("build")
22
+ .description("Build the extension")
23
+ .option("-d, --dir <dir>", "the directory of project. (Optional). By default, current directory is used")
24
+ .action(build_1.build);
25
+ p.command("test")
26
+ .description("Run test provided with the extension")
27
+ .option("-d, --dir <dir>", "the directory of project. (Optional). By default, current directory is used")
28
+ .action(test_1.test);
29
+ p.command("run")
30
+ .description("Check extensions on provided event, config and persistent storage state")
31
+ .option("-d, --dir <dir>", "the directory of project. (Optional). By default, current directory is used")
32
+ .option("-n, --name <name>", "name of function to check (optional). Required if multiple functions are defined in project")
33
+ .option("-t, --type <type>", "entity type to run", "function")
34
+ .requiredOption("-e, --event <file_or_json>", "path to file with event json or event json as a string")
35
+ .option("-p, --props <file_or_json>", "path to file with config json or config json as a string (optional)")
36
+ .option("-s, --store <file_or_json>", "path to file with state json or state json as a string (optional)")
37
+ .action(run_1.run);
38
+ p.command("login")
39
+ .description("Login to Jitsu and remember credentials in `~/.jitsu/jitsu-cli.json` file")
40
+ .option("--host <host>", "Jitsu host or base url", "https://use.jitsu.com")
41
+ .option("-k, --apikey <api-key>", "Jitsu user's Api Key (optional). Disables interactive login.")
42
+ .action(login_1.login);
43
+ p.command("deploy")
44
+ .description("Deploy functions to Jitsu project")
45
+ .option("-d, --dir <dir>", "the directory of project. (Optional). By default, current directory is used")
46
+ .option("-w, --workspace <workspace-id>", "Id of workspace where to deploy function (Optional). By default, interactive prompt is shown to select workspace")
47
+ .option("-t, --type <type>", "entity type to deploy", "function")
48
+ .action(deploy_1.deploy);
49
+ p.parse();
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
5
- function log(delegate, styling, msg, args) {
5
+ function log0(delegate, styling, msg, args) {
6
6
  if (!msg) {
7
7
  delegate("");
8
8
  return;
@@ -18,18 +18,19 @@ function log(delegate, styling, msg, args) {
18
18
  function getLog() {
19
19
  return {
20
20
  error(msg, ...args) {
21
- log(console.error, { prefix: "error", color: "red" }, msg, args);
21
+ log0(console.error, { prefix: "error", color: "red" }, msg, args);
22
22
  },
23
23
  warn(msg, ...args) {
24
- log(console.warn, { prefix: "warn ", color: "yellow" }, msg, args);
24
+ log0(console.warn, { prefix: "warn ", color: "yellow" }, msg, args);
25
25
  },
26
26
  spinInfo(args) { },
27
27
  info(msg, ...args) {
28
- log(console.info, { prefix: "info ", color: "cyan" }, msg, args);
28
+ log0(console.info, { prefix: "info ", color: "cyan" }, msg, args);
29
29
  },
30
30
  debug(msg, ...args) {
31
- log(console.debug, { prefix: "debug", color: "gray" }, msg, args);
31
+ log0(console.debug, { prefix: "debug", color: "gray" }, msg, args);
32
32
  },
33
33
  };
34
34
  }
35
- exports.default = getLog;
35
+ const log = getLog();
36
+ exports.default = log;
@@ -17,7 +17,7 @@ function toTemplateFunction(template) {
17
17
  }
18
18
  }
19
19
  function write(dir, template, vars) {
20
- Object.entries(template).forEach(([fileName, template]) => {
20
+ Object.entries(template(vars)).forEach(([fileName, template]) => {
21
21
  let filePath = path_1.default.resolve(dir, fileName);
22
22
  let fileDir = path_1.default.dirname(filePath);
23
23
  if (!fs.existsSync(fileDir)) {
@@ -4,7 +4,6 @@ exports.hasNewerVersion = exports.box = exports.getUpgradeMessage = exports.jits
4
4
  const tslib_1 = require("tslib");
5
5
  const package_json_1 = tslib_1.__importDefault(require("../../package.json"));
6
6
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
7
- const log_1 = tslib_1.__importDefault(require("./log"));
8
7
  const preload_1 = tslib_1.__importDefault(require("semver/preload"));
9
8
  const fetch = require("cross-fetch");
10
9
  exports.jitsuCliVersion = package_json_1.default.version;
@@ -29,7 +28,7 @@ async function hasNewerVersion() {
29
28
  return preload_1.default.gt(latestVersion, exports.jitsuCliVersion) ? latestVersion : undefined;
30
29
  }
31
30
  catch (e) {
32
- (0, log_1.default)().debug(`Failed to fetch latest version of ${exports.jitsuPackageName}: ${e?.message}`);
31
+ console.debug(`Failed to fetch latest version of ${exports.jitsuPackageName}: ${e?.message}`);
33
32
  }
34
33
  }
35
34
  exports.hasNewerVersion = hasNewerVersion;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.functionProjectTemplate = exports.packageJsonTemplate = void 0;
4
+ const version_1 = require("../lib/version");
5
+ const juava_1 = require("juava");
6
+ const packageJsonTemplate = ({ packageName, license = "MIT", jitsuVersion = undefined }) => ({
7
+ name: `${packageName}`,
8
+ version: "0.0.1",
9
+ description: `Jitsu extension - ${packageName}`,
10
+ license: license,
11
+ keywords: ["jitsu", "jitsu-cli", "function", `jitsu-extension`],
12
+ main: `dist/index.js`,
13
+ scripts: {
14
+ clean: "rm -rf ./dist",
15
+ build: `${version_1.jitsuPackageName} build`,
16
+ test: `${version_1.jitsuPackageName} test`,
17
+ deploy: `${version_1.jitsuPackageName} deploy`,
18
+ },
19
+ devDependencies: {
20
+ "jitsu-cli": `${version_1.jitsuCliVersion}`,
21
+ "@jitsu/protocols": `${jitsuVersion || "^" + version_1.jitsuCliVersion}`,
22
+ "@types/jest": "^29.5.5",
23
+ "ts-jest": "^29.1.1",
24
+ },
25
+ dependencies: {},
26
+ });
27
+ exports.packageJsonTemplate = packageJsonTemplate;
28
+ let functionTest = ({ packageName }) => {
29
+ return `
30
+ test("${(0, juava_1.sanitize)(packageName)} test", () => {
31
+ //TODO: implement test
32
+ });
33
+ `;
34
+ };
35
+ let functionCode = ({ packageName }) => {
36
+ return `
37
+ import { JitsuFunction } from "@jitsu/protocols/functions";
38
+ import { AnalyticsServerEvent } from "@jitsu/protocols/analytics";
39
+
40
+ const ${(0, juava_1.sanitize)(packageName)}: JitsuFunction<AnalyticsServerEvent, any> = async (event, ctx) => {
41
+ //TODO: implement function logic
42
+ };
43
+
44
+ export default ${(0, juava_1.sanitize)(packageName)};
45
+ `;
46
+ };
47
+ const functionProjectTemplate = ({ packageName }) => ({
48
+ [`__test__/${(0, juava_1.sanitize)(packageName)}.test.ts`]: functionTest,
49
+ [`src/index.ts`]: functionCode,
50
+ "package.json": exports.packageJsonTemplate,
51
+ "tsconfig.json": {
52
+ compilerOptions: {
53
+ rootDir: "./src",
54
+ outDir: "./dist",
55
+ declaration: true,
56
+ esModuleInterop: true,
57
+ importHelpers: false,
58
+ module: "esnext",
59
+ lib: ["esnext", "dom"],
60
+ noEmit: false,
61
+ target: "esnext",
62
+ },
63
+ target: "esnext",
64
+ exclude: ["__tests__", "node_modules", "dist"],
65
+ },
66
+ });
67
+ exports.functionProjectTemplate = functionProjectTemplate;