@logto/cli 1.0.0-beta.15 → 1.0.0-beta.18

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 (43) hide show
  1. package/bin/logto.js +2 -0
  2. package/lib/commands/connector/add.js +8 -10
  3. package/lib/commands/connector/index.js +9 -14
  4. package/lib/commands/connector/list.js +10 -16
  5. package/lib/commands/connector/remove.js +13 -18
  6. package/lib/commands/connector/utils.d.ts +1 -1
  7. package/lib/commands/connector/utils.js +100 -86
  8. package/lib/commands/database/alteration/index.d.ts +1 -2
  9. package/lib/commands/database/alteration/index.js +36 -98
  10. package/lib/commands/database/alteration/index.test.js +36 -57
  11. package/lib/commands/database/alteration/meta-url.d.ts +1 -0
  12. package/lib/commands/database/alteration/meta-url.js +4 -0
  13. package/lib/commands/database/alteration/type.d.ts +1 -1
  14. package/lib/commands/database/alteration/type.js +1 -2
  15. package/lib/commands/database/alteration/utils.d.ts +4 -0
  16. package/lib/commands/database/alteration/utils.js +39 -0
  17. package/lib/commands/database/alteration/version.d.ts +1 -1
  18. package/lib/commands/database/alteration/version.js +18 -25
  19. package/lib/commands/database/config.js +44 -49
  20. package/lib/commands/database/index.js +7 -12
  21. package/lib/commands/database/seed/index.d.ts +1 -1
  22. package/lib/commands/database/seed/index.js +59 -55
  23. package/lib/commands/database/seed/oidc-config.js +15 -18
  24. package/lib/commands/database/utilities.js +6 -11
  25. package/lib/commands/install/index.d.ts +1 -1
  26. package/lib/commands/install/index.js +14 -28
  27. package/lib/commands/install/utils.d.ts +0 -1
  28. package/lib/commands/install/utils.js +59 -106
  29. package/lib/constants.js +1 -4
  30. package/lib/database.js +33 -43
  31. package/lib/index.js +18 -23
  32. package/lib/meta-url.d.ts +1 -0
  33. package/lib/meta-url.js +4 -0
  34. package/lib/package-json.d.ts +7 -3
  35. package/lib/package-json.js +28 -27
  36. package/lib/queries/logto-config.js +18 -26
  37. package/lib/queries/logto-config.test.js +29 -30
  38. package/lib/test-utilities.d.ts +2 -2
  39. package/lib/test-utilities.js +1 -5
  40. package/lib/utilities.d.ts +5 -5
  41. package/lib/utilities.js +49 -64
  42. package/package.json +27 -23
  43. package/bin/logto +0 -2
package/lib/utilities.js CHANGED
@@ -1,53 +1,48 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getConnectorPackagesFromDirectory = exports.findLastIndex = exports.getCliConfigWithPrompt = exports.cliConfig = exports.ConfigKey = exports.isTty = exports.oraPromise = exports.getPathInModule = exports.downloadFile = exports.log = exports.safeExecSync = void 0;
7
- const child_process_1 = require("child_process");
8
- const fs_1 = require("fs");
9
- const promises_1 = require("fs/promises");
10
- const path_1 = __importDefault(require("path"));
11
- const essentials_1 = require("@silverhand/essentials");
12
- const chalk_1 = __importDefault(require("chalk"));
13
- const got_1 = __importDefault(require("got"));
14
- const hpagent_1 = require("hpagent");
15
- const inquirer_1 = __importDefault(require("inquirer"));
16
- const ora_1 = __importDefault(require("ora"));
17
- const zod_1 = require("zod");
18
- const safeExecSync = (command) => {
1
+ import { execSync } from 'child_process';
2
+ import { createWriteStream, existsSync } from 'fs';
3
+ import { readdir, readFile } from 'fs/promises';
4
+ import { createRequire } from 'module';
5
+ import path from 'path';
6
+ import { conditionalString } from '@silverhand/essentials';
7
+ import chalk from 'chalk';
8
+ import { got } from 'got';
9
+ import { HttpsProxyAgent } from 'hpagent';
10
+ import inquirer from 'inquirer';
11
+ import ora from 'ora';
12
+ import { z } from 'zod';
13
+ import { metaUrl } from './meta-url.js';
14
+ export const safeExecSync = (command) => {
19
15
  try {
20
- return (0, child_process_1.execSync)(command, { encoding: 'utf8', stdio: 'pipe' });
16
+ return execSync(command, { encoding: 'utf8', stdio: 'pipe' });
21
17
  }
22
18
  catch { }
23
19
  };
24
- exports.safeExecSync = safeExecSync;
25
- exports.log = Object.freeze({
20
+ export const log = Object.freeze({
26
21
  info: (...args) => {
27
- console.log(chalk_1.default.blue('[info]'), ...args);
22
+ console.log(chalk.blue('[info]'), ...args);
28
23
  },
29
24
  succeed: (...args) => {
30
- exports.log.info(chalk_1.default.green('✔'), ...args);
25
+ log.info(chalk.green('✔'), ...args);
31
26
  },
32
27
  warn: (...args) => {
33
- console.warn(chalk_1.default.yellow('[warn]'), ...args);
28
+ console.warn(chalk.yellow('[warn]'), ...args);
34
29
  },
35
30
  error: (...args) => {
36
- console.error(chalk_1.default.red('[error]'), ...args);
31
+ console.error(chalk.red('[error]'), ...args);
37
32
  // eslint-disable-next-line unicorn/no-process-exit
38
33
  process.exit(1);
39
34
  },
40
35
  });
41
- const downloadFile = async (url, destination) => {
36
+ export const downloadFile = async (url, destination) => {
42
37
  const { HTTPS_PROXY, HTTP_PROXY, https_proxy, http_proxy } = process.env;
43
- const file = (0, fs_1.createWriteStream)(destination);
38
+ const file = createWriteStream(destination);
44
39
  const proxy = HTTPS_PROXY ?? https_proxy ?? HTTP_PROXY ?? http_proxy;
45
- const stream = got_1.default.stream(url, {
46
- ...(proxy && { agent: { https: new hpagent_1.HttpsProxyAgent({ proxy }) } }),
40
+ const stream = got.stream(url, {
41
+ ...(proxy && { agent: { https: new HttpsProxyAgent({ proxy }) } }),
47
42
  });
48
- const spinner = (0, ora_1.default)({
43
+ const spinner = ora({
49
44
  text: 'Connecting',
50
- prefixText: chalk_1.default.blue('[info]'),
45
+ prefixText: chalk.blue('[info]'),
51
46
  }).start();
52
47
  stream.pipe(file);
53
48
  return new Promise((resolve, reject) => {
@@ -69,16 +64,11 @@ const downloadFile = async (url, destination) => {
69
64
  });
70
65
  });
71
66
  };
72
- exports.downloadFile = downloadFile;
73
- const getPathInModule = (moduleName, relativePath = '/') =>
67
+ export const getPathInModule = (moduleName, relativePath = '/') =>
74
68
  // https://stackoverflow.com/a/49455609/12514940
75
- path_1.default.join(
76
- // Until we migrate to ESM
77
- // eslint-disable-next-line unicorn/prefer-module
78
- path_1.default.dirname(require.resolve(`${moduleName}/package.json`)), relativePath);
79
- exports.getPathInModule = getPathInModule;
80
- const oraPromise = async (promise, options, exitOnError = false) => {
81
- const spinner = (0, ora_1.default)(options).start();
69
+ path.join(path.dirname(createRequire(metaUrl).resolve(`${moduleName}/package.json`)), relativePath);
70
+ export const oraPromise = async (promise, options, exitOnError = false) => {
71
+ const spinner = ora(options).start();
82
72
  try {
83
73
  const result = await promise;
84
74
  spinner.succeed();
@@ -87,33 +77,30 @@ const oraPromise = async (promise, options, exitOnError = false) => {
87
77
  catch (error) {
88
78
  spinner.fail();
89
79
  if (exitOnError) {
90
- exports.log.error(error);
80
+ log.error(error);
91
81
  }
92
82
  throw error;
93
83
  }
94
84
  };
95
- exports.oraPromise = oraPromise;
96
- const isTty = () => process.stdin.isTTY;
97
- exports.isTty = isTty;
98
- var ConfigKey;
85
+ export const isTty = () => process.stdin.isTTY;
86
+ export var ConfigKey;
99
87
  (function (ConfigKey) {
100
88
  ConfigKey["DatabaseUrl"] = "DB_URL";
101
- })(ConfigKey = exports.ConfigKey || (exports.ConfigKey = {}));
102
- exports.cliConfig = new Map();
103
- const getCliConfigWithPrompt = async ({ key, readableKey, comments, defaultValue, }) => {
104
- if (exports.cliConfig.has(key) || !(0, exports.isTty)()) {
105
- return exports.cliConfig.get(key);
89
+ })(ConfigKey || (ConfigKey = {}));
90
+ export const cliConfig = new Map();
91
+ export const getCliConfigWithPrompt = async ({ key, readableKey, comments, defaultValue, }) => {
92
+ if (cliConfig.has(key) || !isTty()) {
93
+ return cliConfig.get(key);
106
94
  }
107
- const { input } = await inquirer_1.default.prompt({
95
+ const { input } = await inquirer.prompt({
108
96
  type: 'input',
109
97
  name: 'input',
110
- message: `Enter your ${readableKey}${(0, essentials_1.conditionalString)(comments && ' ' + comments)}`,
98
+ message: `Enter your ${readableKey}${conditionalString(comments && ' ' + comments)}`,
111
99
  default: defaultValue,
112
100
  });
113
- exports.cliConfig.set(key, input);
101
+ cliConfig.set(key, input);
114
102
  return input;
115
103
  };
116
- exports.getCliConfigWithPrompt = getCliConfigWithPrompt;
117
104
  // https://stackoverflow.com/a/53187807/12514940
118
105
  /**
119
106
  * Returns the index of the last element in the array where predicate is true, and -1
@@ -123,7 +110,7 @@ exports.getCliConfigWithPrompt = getCliConfigWithPrompt;
123
110
  * order, until it finds one where predicate returns true. If such an element is found,
124
111
  * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
125
112
  */
126
- function findLastIndex(array, predicate) {
113
+ export function findLastIndex(array, predicate) {
127
114
  // eslint-disable-next-line @silverhand/fp/no-let
128
115
  let { length } = array;
129
116
  // eslint-disable-next-line @silverhand/fp/no-mutation
@@ -135,24 +122,22 @@ function findLastIndex(array, predicate) {
135
122
  }
136
123
  return -1;
137
124
  }
138
- exports.findLastIndex = findLastIndex;
139
125
  const getConnectorPackageName = async (directory) => {
140
- const filePath = path_1.default.join(directory, 'package.json');
141
- if (!(0, fs_1.existsSync)(filePath)) {
126
+ const filePath = path.join(directory, 'package.json');
127
+ if (!existsSync(filePath)) {
142
128
  return;
143
129
  }
144
- const json = await (0, promises_1.readFile)(filePath, 'utf8');
145
- const { name } = zod_1.z.object({ name: zod_1.z.string() }).parse(JSON.parse(json));
130
+ const json = await readFile(filePath, 'utf8');
131
+ const { name } = z.object({ name: z.string() }).parse(JSON.parse(json));
146
132
  if (name.startsWith('connector-') || Boolean(name.split('/')[1]?.startsWith('connector-'))) {
147
133
  return name;
148
134
  }
149
135
  };
150
- const getConnectorPackagesFromDirectory = async (directory) => {
151
- const content = await (0, promises_1.readdir)(directory, 'utf8');
136
+ export const getConnectorPackagesFromDirectory = async (directory) => {
137
+ const content = await readdir(directory, 'utf8');
152
138
  const rawPackages = await Promise.all(content.map(async (value) => {
153
- const currentDirectory = path_1.default.join(directory, value);
139
+ const currentDirectory = path.join(directory, value);
154
140
  return { name: await getConnectorPackageName(currentDirectory), path: currentDirectory };
155
141
  }));
156
142
  return rawPackages.filter((packageInfo) => typeof packageInfo.name === 'string');
157
143
  };
158
- exports.getConnectorPackagesFromDirectory = getConnectorPackagesFromDirectory;
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "@logto/cli",
3
- "version": "1.0.0-beta.15",
3
+ "version": "1.0.0-beta.18",
4
4
  "description": "Logto CLI.",
5
5
  "author": "Silverhand Inc. <contact@silverhand.io>",
6
6
  "homepage": "https://github.com/logto-io/logto#readme",
7
7
  "license": "MPL-2.0",
8
+ "type": "module",
8
9
  "publishConfig": {
9
10
  "access": "public"
10
11
  },
11
12
  "main": "lib/index.js",
12
13
  "bin": {
13
- "logto": "bin/logto"
14
+ "logto": "bin/logto.js"
14
15
  },
15
16
  "files": [
16
17
  "bin",
@@ -27,46 +28,47 @@
27
28
  "url": "https://github.com/logto-io/logto/issues"
28
29
  },
29
30
  "dependencies": {
30
- "@silverhand/essentials": "^1.3.0",
31
- "chalk": "^4.1.2",
32
- "decamelize": "^5.0.0",
31
+ "@silverhand/essentials": "2.1.0",
32
+ "chalk": "^5.0.0",
33
+ "decamelize": "^6.0.0",
33
34
  "dotenv": "^16.0.0",
34
- "fs-extra": "^10.1.0",
35
- "got": "^11.8.5",
36
- "hpagent": "^1.0.0",
35
+ "got": "^12.5.3",
36
+ "hpagent": "^1.2.0",
37
37
  "inquirer": "^8.2.2",
38
- "nanoid": "^3.3.4",
39
- "ora": "^5.0.0",
40
- "p-retry": "^4.6.1",
38
+ "nanoid": "^4.0.0",
39
+ "ora": "^6.1.2",
40
+ "p-limit": "^4.0.0",
41
+ "p-retry": "^5.1.2",
41
42
  "roarr": "^7.11.0",
42
- "semver": "^7.3.7",
43
+ "semver": "^7.3.8",
43
44
  "slonik": "^30.0.0",
44
45
  "slonik-interceptor-preset": "^1.2.10",
45
46
  "slonik-sql-tag-raw": "^1.1.4",
46
47
  "tar": "^6.1.11",
47
48
  "yargs": "^17.6.0",
48
- "zod": "^3.19.1",
49
- "@logto/schemas": "^1.0.0-beta.15",
50
- "@logto/shared": "^1.0.0-beta.15"
49
+ "zod": "^3.20.2",
50
+ "@logto/core-kit": "1.0.0-beta.30",
51
+ "@logto/schemas": "1.0.0-beta.17",
52
+ "@logto/shared": "1.0.0-beta.17"
51
53
  },
52
54
  "devDependencies": {
53
55
  "@silverhand/eslint-config": "1.3.0",
54
- "@silverhand/jest-config": "1.2.2",
55
56
  "@silverhand/ts-config": "1.2.1",
56
57
  "@types/fs-extra": "^9.0.13",
57
58
  "@types/inquirer": "^8.2.1",
58
59
  "@types/jest": "^29.1.2",
59
60
  "@types/node": "^16.0.0",
60
61
  "@types/semver": "^7.3.12",
62
+ "@types/sinon": "^10.0.13",
61
63
  "@types/tar": "^6.1.2",
62
64
  "@types/yargs": "^17.0.13",
63
65
  "eslint": "^8.21.0",
64
- "jest": "^29.1.2",
66
+ "jest": "^29.3.1",
65
67
  "lint-staged": "^13.0.0",
66
- "prettier": "^2.7.1",
68
+ "prettier": "^2.8.1",
67
69
  "rimraf": "^3.0.2",
68
- "ts-node": "^10.9.1",
69
- "typescript": "^4.7.4"
70
+ "sinon": "^15.0.0",
71
+ "typescript": "^4.9.4"
70
72
  },
71
73
  "eslintConfig": {
72
74
  "extends": "@silverhand",
@@ -79,12 +81,14 @@
79
81
  "precommit": "lint-staged",
80
82
  "prepare:package-json": "node -p \"'export const packageJson = ' + JSON.stringify(require('./package.json'), undefined, 2) + ';'\" > src/package-json.ts",
81
83
  "build": "rimraf lib && pnpm prepare:package-json && tsc -p tsconfig.build.json",
84
+ "build:test": "rimraf lib/ && pnpm prepare:package-json && tsc -p tsconfig.test.json --sourcemap",
82
85
  "dev": "tsc -p tsconfig.build.json --watch --preserveWatchOutput --incremental",
83
86
  "start": "node .",
84
- "start:dev": "ts-node --files src/index.ts",
87
+ "start:dev": "pnpm build && node .",
85
88
  "lint": "eslint --ext .ts src",
86
89
  "lint:report": "pnpm lint --format json --output-file report.json",
87
- "test": "jest",
88
- "test:ci": "jest"
90
+ "test:only": "NODE_OPTIONS=--experimental-vm-modules jest",
91
+ "test": "pnpm build:test && pnpm test:only",
92
+ "test:ci": "pnpm test:only"
89
93
  }
90
94
  }
package/bin/logto DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- require('../lib/index.js');