@logto/cli 1.0.3 → 1.2.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/lib/commands/connector/add.js +4 -4
- package/lib/commands/connector/index.js +2 -0
- package/lib/commands/connector/link.d.ts +9 -0
- package/lib/commands/connector/link.js +46 -0
- package/lib/commands/connector/list.js +4 -3
- package/lib/commands/connector/remove.js +7 -7
- package/lib/commands/connector/utils.d.ts +2 -0
- package/lib/commands/connector/utils.js +29 -17
- package/lib/commands/database/alteration/index.js +8 -8
- package/lib/commands/database/alteration/utils.js +3 -3
- package/lib/commands/database/alteration/version.js +4 -4
- package/lib/commands/database/config.js +11 -11
- package/lib/commands/database/seed/cloud.js +2 -2
- package/lib/commands/database/seed/index.js +4 -5
- package/lib/commands/database/seed/oidc-config.js +6 -6
- package/lib/commands/database/seed/tables.js +4 -4
- package/lib/commands/database/seed/tenant.js +2 -2
- package/lib/commands/database/system.js +5 -5
- package/lib/commands/database/utils.js +3 -3
- package/lib/commands/install/index.js +3 -3
- package/lib/commands/install/utils.js +17 -17
- package/lib/commands/translate/create.d.ts +8 -0
- package/lib/commands/translate/create.js +38 -0
- package/lib/commands/translate/index.d.ts +3 -0
- package/lib/commands/translate/index.js +20 -0
- package/lib/commands/translate/list-tags.d.ts +3 -0
- package/lib/commands/translate/list-tags.js +19 -0
- package/lib/commands/translate/openai.d.ts +11 -0
- package/lib/commands/translate/openai.js +77 -0
- package/lib/commands/translate/prompts.d.ts +14 -0
- package/lib/commands/translate/prompts.js +39 -0
- package/lib/commands/translate/sync.d.ts +7 -0
- package/lib/commands/translate/sync.js +40 -0
- package/lib/commands/translate/utils.d.ts +14 -0
- package/lib/commands/translate/utils.js +131 -0
- package/lib/connector/factories.js +2 -1
- package/lib/connector/loader.js +5 -4
- package/lib/connector/utils.js +3 -3
- package/lib/database.js +3 -3
- package/lib/index.js +4 -2
- package/lib/package-json.d.ts +7 -0
- package/lib/package-json.js +14 -7
- package/lib/utils.d.ts +3 -8
- package/lib/utils.js +23 -24
- package/package.json +15 -8
package/lib/connector/loader.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import path from 'path';
|
|
1
|
+
import path from 'node:path';
|
|
2
2
|
import connectorKitMeta from '@logto/connector-kit/package.json' assert { type: 'json' };
|
|
3
3
|
import { satisfies } from 'semver';
|
|
4
|
+
import { consoleLog } from '../utils.js';
|
|
4
5
|
import { isKeyInObject } from './utils.js';
|
|
5
6
|
const connectorKit = '@logto/connector-kit';
|
|
6
7
|
const { version: currentVersion } = connectorKitMeta;
|
|
@@ -8,12 +9,12 @@ const checkConnectorKitVersion = (dependencies, ignoreVersionMismatch) => {
|
|
|
8
9
|
if (isKeyInObject(dependencies, connectorKit)) {
|
|
9
10
|
const value = dependencies[connectorKit];
|
|
10
11
|
if (typeof value === 'string') {
|
|
11
|
-
if (satisfies(currentVersion, value)) {
|
|
12
|
+
if (value.startsWith('workspace:') || satisfies(currentVersion, value)) {
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
14
15
|
const message = `Connector requires ${connectorKit} to be ${value}, but the version here is ${currentVersion}.`;
|
|
15
16
|
if (ignoreVersionMismatch) {
|
|
16
|
-
|
|
17
|
+
consoleLog.warn(`${message}\n\nThis is highly discouraged in production.`);
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
19
20
|
throw new Error(message);
|
|
@@ -33,7 +34,7 @@ export const loadConnector = async (connectorPath, ignoreVersionMismatch) => {
|
|
|
33
34
|
// CJS pattern
|
|
34
35
|
if (isKeyInObject(loaded.default, 'default')) {
|
|
35
36
|
if (typeof loaded.default.default === 'function') {
|
|
36
|
-
|
|
37
|
+
consoleLog.warn(`Load connector ${connectorPath} in CJS mode`);
|
|
37
38
|
// eslint-disable-next-line no-restricted-syntax
|
|
38
39
|
return loaded.default.default;
|
|
39
40
|
}
|
package/lib/connector/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { existsSync } from 'fs';
|
|
2
|
-
import { readFile } from 'fs/promises';
|
|
3
|
-
import path from 'path';
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
4
|
import { ConnectorError, ConnectorErrorCodes, ConnectorType } from '@logto/connector-kit';
|
|
5
5
|
import { notImplemented } from './consts.js';
|
|
6
6
|
export function validateConnectorModule(connector) {
|
package/lib/database.js
CHANGED
|
@@ -4,7 +4,7 @@ import decamelize from 'decamelize';
|
|
|
4
4
|
import { DatabaseError } from 'pg-protocol';
|
|
5
5
|
import { createPool, parseDsn, sql, stringifyDsn } from 'slonik';
|
|
6
6
|
import { createInterceptors } from 'slonik-interceptor-preset';
|
|
7
|
-
import { ConfigKey,
|
|
7
|
+
import { ConfigKey, consoleLog, getCliConfigWithPrompt } from './utils.js';
|
|
8
8
|
export const defaultDatabaseUrl = 'postgresql://localhost:5432/logto';
|
|
9
9
|
export const getDatabaseUrlFromConfig = async () => (await getCliConfigWithPrompt({
|
|
10
10
|
key: ConfigKey.DatabaseUrl,
|
|
@@ -32,7 +32,7 @@ export const createPoolAndDatabaseIfNeeded = async () => {
|
|
|
32
32
|
// Database does not exist, try to create one
|
|
33
33
|
// https://www.postgresql.org/docs/14/errcodes-appendix.html
|
|
34
34
|
if (!(error instanceof DatabaseError && error.code === '3D000')) {
|
|
35
|
-
|
|
35
|
+
consoleLog.fatal(error);
|
|
36
36
|
}
|
|
37
37
|
const databaseUrl = await getDatabaseUrlFromConfig();
|
|
38
38
|
const dsn = parseDsn(databaseUrl);
|
|
@@ -50,7 +50,7 @@ export const createPoolAndDatabaseIfNeeded = async () => {
|
|
|
50
50
|
connection_limit = -1;
|
|
51
51
|
`);
|
|
52
52
|
await maintenancePool.end();
|
|
53
|
-
|
|
53
|
+
consoleLog.succeed(`Created database ${databaseName}`);
|
|
54
54
|
return createPoolFromConfig();
|
|
55
55
|
}
|
|
56
56
|
};
|
package/lib/index.js
CHANGED
|
@@ -5,8 +5,9 @@ import { hideBin } from 'yargs/helpers';
|
|
|
5
5
|
import connector from './commands/connector/index.js';
|
|
6
6
|
import database from './commands/database/index.js';
|
|
7
7
|
import install from './commands/install/index.js';
|
|
8
|
+
import translate from './commands/translate/index.js';
|
|
8
9
|
import { packageJson } from './package-json.js';
|
|
9
|
-
import { cliConfig, ConfigKey } from './utils.js';
|
|
10
|
+
import { cliConfig, ConfigKey, consoleLog } from './utils.js';
|
|
10
11
|
void yargs(hideBin(process.argv))
|
|
11
12
|
.version(false)
|
|
12
13
|
.option('env', {
|
|
@@ -27,7 +28,7 @@ void yargs(hideBin(process.argv))
|
|
|
27
28
|
})
|
|
28
29
|
.middleware(({ version }) => {
|
|
29
30
|
if (version) {
|
|
30
|
-
|
|
31
|
+
consoleLog.plain(packageJson.name + ' v' + packageJson.version);
|
|
31
32
|
// eslint-disable-next-line unicorn/no-process-exit
|
|
32
33
|
process.exit(0);
|
|
33
34
|
}
|
|
@@ -42,6 +43,7 @@ void yargs(hideBin(process.argv))
|
|
|
42
43
|
.command(install)
|
|
43
44
|
.command(database)
|
|
44
45
|
.command(connector)
|
|
46
|
+
.command(translate)
|
|
45
47
|
.demandCommand(1)
|
|
46
48
|
.showHelpOnFail(false, `Specify ${chalk.green('--help')} for available options`)
|
|
47
49
|
.strict()
|
package/lib/package-json.d.ts
CHANGED
|
@@ -42,6 +42,9 @@ export declare const packageJson: {
|
|
|
42
42
|
dependencies: {
|
|
43
43
|
"@logto/connector-kit": string;
|
|
44
44
|
"@logto/core-kit": string;
|
|
45
|
+
"@logto/language-kit": string;
|
|
46
|
+
"@logto/phrases": string;
|
|
47
|
+
"@logto/phrases-ui": string;
|
|
45
48
|
"@logto/schemas": string;
|
|
46
49
|
"@logto/shared": string;
|
|
47
50
|
"@silverhand/essentials": string;
|
|
@@ -54,6 +57,7 @@ export declare const packageJson: {
|
|
|
54
57
|
nanoid: string;
|
|
55
58
|
ora: string;
|
|
56
59
|
"p-limit": string;
|
|
60
|
+
"p-queue": string;
|
|
57
61
|
"p-retry": string;
|
|
58
62
|
"pg-protocol": string;
|
|
59
63
|
roarr: string;
|
|
@@ -84,6 +88,9 @@ export declare const packageJson: {
|
|
|
84
88
|
};
|
|
85
89
|
eslintConfig: {
|
|
86
90
|
extends: string;
|
|
91
|
+
rules: {
|
|
92
|
+
"no-console": string;
|
|
93
|
+
};
|
|
87
94
|
ignorePatterns: string[];
|
|
88
95
|
};
|
|
89
96
|
prettier: string;
|
package/lib/package-json.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export const packageJson = {
|
|
2
2
|
"name": "@logto/cli",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Logto CLI.",
|
|
5
5
|
"author": "Silverhand Inc. <contact@silverhand.io>",
|
|
6
6
|
"homepage": "https://github.com/logto-io/logto#readme",
|
|
@@ -43,10 +43,13 @@ export const packageJson = {
|
|
|
43
43
|
"url": "https://github.com/logto-io/logto/issues"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@logto/connector-kit": "workspace:^",
|
|
47
|
-
"@logto/core-kit": "workspace:^",
|
|
48
|
-
"@logto/
|
|
49
|
-
"@logto/
|
|
46
|
+
"@logto/connector-kit": "workspace:^1.1.1",
|
|
47
|
+
"@logto/core-kit": "workspace:^2.0.0",
|
|
48
|
+
"@logto/language-kit": "workspace:^1.0.0",
|
|
49
|
+
"@logto/phrases": "workspace:^1.2.0",
|
|
50
|
+
"@logto/phrases-ui": "workspace:^1.2.0",
|
|
51
|
+
"@logto/schemas": "workspace:^1.2.0",
|
|
52
|
+
"@logto/shared": "workspace:^2.0.0",
|
|
50
53
|
"@silverhand/essentials": "^2.5.0",
|
|
51
54
|
"chalk": "^5.0.0",
|
|
52
55
|
"decamelize": "^6.0.0",
|
|
@@ -57,6 +60,7 @@ export const packageJson = {
|
|
|
57
60
|
"nanoid": "^4.0.0",
|
|
58
61
|
"ora": "^6.1.2",
|
|
59
62
|
"p-limit": "^4.0.0",
|
|
63
|
+
"p-queue": "^7.3.4",
|
|
60
64
|
"p-retry": "^5.1.2",
|
|
61
65
|
"pg-protocol": "^1.6.0",
|
|
62
66
|
"roarr": "^7.11.0",
|
|
@@ -69,8 +73,8 @@ export const packageJson = {
|
|
|
69
73
|
"zod": "^3.20.2"
|
|
70
74
|
},
|
|
71
75
|
"devDependencies": {
|
|
72
|
-
"@silverhand/eslint-config": "
|
|
73
|
-
"@silverhand/ts-config": "
|
|
76
|
+
"@silverhand/eslint-config": "3.0.1",
|
|
77
|
+
"@silverhand/ts-config": "3.0.0",
|
|
74
78
|
"@types/inquirer": "^9.0.0",
|
|
75
79
|
"@types/jest": "^29.4.0",
|
|
76
80
|
"@types/node": "^18.11.18",
|
|
@@ -87,6 +91,9 @@ export const packageJson = {
|
|
|
87
91
|
},
|
|
88
92
|
"eslintConfig": {
|
|
89
93
|
"extends": "@silverhand",
|
|
94
|
+
"rules": {
|
|
95
|
+
"no-console": "error"
|
|
96
|
+
},
|
|
90
97
|
"ignorePatterns": [
|
|
91
98
|
"src/package-json.ts"
|
|
92
99
|
]
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
+
import { ConsoleLog } from '@logto/shared';
|
|
1
2
|
import type { Optional } from '@silverhand/essentials';
|
|
2
3
|
import type { Options } from 'ora';
|
|
3
4
|
export declare const safeExecSync: (command: string) => string | undefined;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
succeed: typeof console.log;
|
|
7
|
-
warn: typeof console.log;
|
|
8
|
-
error: (...args: Parameters<typeof console.log>) => never;
|
|
9
|
-
}>;
|
|
10
|
-
export declare const log: Log;
|
|
5
|
+
export declare const consoleLog: ConsoleLog;
|
|
6
|
+
export declare const getProxy: () => string | undefined;
|
|
11
7
|
export declare const downloadFile: (url: string, destination: string) => Promise<unknown>;
|
|
12
8
|
export declare const getPathInModule: (moduleName: string, relativePath?: string) => string;
|
|
13
9
|
export declare const oraPromise: <T>(promise: PromiseLike<T>, options?: Options, exitOnError?: boolean) => Promise<T>;
|
|
@@ -37,4 +33,3 @@ export type ConnectorPackage = {
|
|
|
37
33
|
path: string;
|
|
38
34
|
};
|
|
39
35
|
export declare const getConnectorPackagesFromDirectory: (directory: string) => Promise<ConnectorPackage[]>;
|
|
40
|
-
export {};
|
package/lib/utils.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
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';
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
import { createWriteStream, existsSync } from 'node:fs';
|
|
3
|
+
import { readdir, readFile } from 'node:fs/promises';
|
|
4
|
+
import { createRequire } from 'node:module';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { ConsoleLog } from '@logto/shared';
|
|
6
7
|
import { conditionalString } from '@silverhand/essentials';
|
|
7
8
|
import chalk from 'chalk';
|
|
8
9
|
import { got } from 'got';
|
|
@@ -16,26 +17,24 @@ export const safeExecSync = (command) => {
|
|
|
16
17
|
}
|
|
17
18
|
catch { }
|
|
18
19
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// eslint-disable-next-line unicorn/no-process-exit
|
|
32
|
-
process.exit(1);
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
export const downloadFile = async (url, destination) => {
|
|
20
|
+
// The explicit type annotation is required to make `.fatal()`
|
|
21
|
+
// works correctly without `return`:
|
|
22
|
+
//
|
|
23
|
+
// ```ts
|
|
24
|
+
// const foo: number | undefined;
|
|
25
|
+
// consoleLog.fatal();
|
|
26
|
+
// typeof foo // Still `number | undefined` without explicit type annotation
|
|
27
|
+
// ```
|
|
28
|
+
//
|
|
29
|
+
// For now I have no idea why.
|
|
30
|
+
export const consoleLog = new ConsoleLog();
|
|
31
|
+
export const getProxy = () => {
|
|
36
32
|
const { HTTPS_PROXY, HTTP_PROXY, https_proxy, http_proxy } = process.env;
|
|
33
|
+
return HTTPS_PROXY ?? https_proxy ?? HTTP_PROXY ?? http_proxy;
|
|
34
|
+
};
|
|
35
|
+
export const downloadFile = async (url, destination) => {
|
|
37
36
|
const file = createWriteStream(destination);
|
|
38
|
-
const proxy =
|
|
37
|
+
const proxy = getProxy();
|
|
39
38
|
const stream = got.stream(url, {
|
|
40
39
|
...(proxy && { agent: { https: new HttpsProxyAgent({ proxy }) } }),
|
|
41
40
|
});
|
|
@@ -76,7 +75,7 @@ export const oraPromise = async (promise, options, exitOnError = false) => {
|
|
|
76
75
|
catch (error) {
|
|
77
76
|
spinner.fail();
|
|
78
77
|
if (exitOnError) {
|
|
79
|
-
|
|
78
|
+
consoleLog.fatal(error);
|
|
80
79
|
}
|
|
81
80
|
throw error;
|
|
82
81
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/cli",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Logto CLI.",
|
|
5
5
|
"author": "Silverhand Inc. <contact@silverhand.io>",
|
|
6
6
|
"homepage": "https://github.com/logto-io/logto#readme",
|
|
@@ -28,6 +28,13 @@
|
|
|
28
28
|
"url": "https://github.com/logto-io/logto/issues"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
+
"@logto/connector-kit": "^1.1.1",
|
|
32
|
+
"@logto/core-kit": "^2.0.0",
|
|
33
|
+
"@logto/language-kit": "^1.0.0",
|
|
34
|
+
"@logto/phrases": "^1.2.0",
|
|
35
|
+
"@logto/phrases-ui": "^1.2.0",
|
|
36
|
+
"@logto/schemas": "^1.2.0",
|
|
37
|
+
"@logto/shared": "^2.0.0",
|
|
31
38
|
"@silverhand/essentials": "^2.5.0",
|
|
32
39
|
"chalk": "^5.0.0",
|
|
33
40
|
"decamelize": "^6.0.0",
|
|
@@ -38,6 +45,7 @@
|
|
|
38
45
|
"nanoid": "^4.0.0",
|
|
39
46
|
"ora": "^6.1.2",
|
|
40
47
|
"p-limit": "^4.0.0",
|
|
48
|
+
"p-queue": "^7.3.4",
|
|
41
49
|
"p-retry": "^5.1.2",
|
|
42
50
|
"pg-protocol": "^1.6.0",
|
|
43
51
|
"roarr": "^7.11.0",
|
|
@@ -47,15 +55,11 @@
|
|
|
47
55
|
"slonik-sql-tag-raw": "^1.1.4",
|
|
48
56
|
"tar": "^6.1.11",
|
|
49
57
|
"yargs": "^17.6.0",
|
|
50
|
-
"zod": "^3.20.2"
|
|
51
|
-
"@logto/core-kit": "^1.1.0",
|
|
52
|
-
"@logto/schemas": "^1.0.7",
|
|
53
|
-
"@logto/shared": "^1.0.2",
|
|
54
|
-
"@logto/connector-kit": "^1.1.0"
|
|
58
|
+
"zod": "^3.20.2"
|
|
55
59
|
},
|
|
56
60
|
"devDependencies": {
|
|
57
|
-
"@silverhand/eslint-config": "
|
|
58
|
-
"@silverhand/ts-config": "
|
|
61
|
+
"@silverhand/eslint-config": "3.0.1",
|
|
62
|
+
"@silverhand/ts-config": "3.0.0",
|
|
59
63
|
"@types/inquirer": "^9.0.0",
|
|
60
64
|
"@types/jest": "^29.4.0",
|
|
61
65
|
"@types/node": "^18.11.18",
|
|
@@ -72,6 +76,9 @@
|
|
|
72
76
|
},
|
|
73
77
|
"eslintConfig": {
|
|
74
78
|
"extends": "@silverhand",
|
|
79
|
+
"rules": {
|
|
80
|
+
"no-console": "error"
|
|
81
|
+
},
|
|
75
82
|
"ignorePatterns": [
|
|
76
83
|
"src/package-json.ts"
|
|
77
84
|
]
|