@logto/cli 1.3.0 → 1.6.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/utils.d.ts +8 -0
- package/lib/commands/connector/utils.js +6 -3
- package/lib/commands/database/seed/tenant.js +12 -9
- package/lib/commands/install/utils.js +1 -1
- package/lib/commands/translate/openai.js +6 -11
- package/lib/commands/translate/prompts.d.ts +4 -1
- package/lib/commands/translate/prompts.js +14 -8
- package/lib/commands/translate/sync.js +1 -1
- package/lib/package-json.js +5 -5
- package/package.json +5 -5
|
@@ -18,5 +18,13 @@ export declare const getConnectorDirectory: (instancePath: string) => string;
|
|
|
18
18
|
export declare const isOfficialConnector: (packageName: string) => boolean;
|
|
19
19
|
export declare const getConnectorPackagesFrom: (instancePath?: string) => Promise<import("../../utils.js").ConnectorPackage[]>;
|
|
20
20
|
export declare const getLocalConnectorPackages: (instancePath: string) => Promise<(readonly [string, string])[]>;
|
|
21
|
+
export declare const addConnectorsToPath: (cwd: string, packageNames: string[]) => Promise<void>;
|
|
21
22
|
export declare const addConnectors: (instancePath: string, packageNames: string[]) => Promise<void>;
|
|
23
|
+
type PackageMeta = {
|
|
24
|
+
name: string;
|
|
25
|
+
scope: string;
|
|
26
|
+
version: string;
|
|
27
|
+
};
|
|
28
|
+
export declare const fetchOfficialConnectorList: (includingCloudConnectors?: boolean) => Promise<PackageMeta[]>;
|
|
22
29
|
export declare const addOfficialConnectors: (instancePath: string, includingCloudConnectors?: boolean) => Promise<void>;
|
|
30
|
+
export {};
|
|
@@ -93,8 +93,7 @@ export const getLocalConnectorPackages = async (instancePath) => {
|
|
|
93
93
|
}
|
|
94
94
|
return packages.map(({ name }) => [name, path.join(directory, name)]);
|
|
95
95
|
};
|
|
96
|
-
export const
|
|
97
|
-
const cwd = getConnectorDirectory(instancePath);
|
|
96
|
+
export const addConnectorsToPath = async (cwd, packageNames) => {
|
|
98
97
|
if (!existsSync(cwd)) {
|
|
99
98
|
await fs.mkdir(cwd, { recursive: true });
|
|
100
99
|
}
|
|
@@ -138,8 +137,12 @@ export const addConnectors = async (instancePath, packageNames) => {
|
|
|
138
137
|
consoleLog.warn('Failed to add ' + errorPackages.map((name) => chalk.green(name)).join(', '));
|
|
139
138
|
}
|
|
140
139
|
};
|
|
140
|
+
export const addConnectors = async (instancePath, packageNames) => {
|
|
141
|
+
const cwd = getConnectorDirectory(instancePath);
|
|
142
|
+
await addConnectorsToPath(cwd, packageNames);
|
|
143
|
+
};
|
|
141
144
|
const officialConnectorPrefix = '@logto/connector-';
|
|
142
|
-
const fetchOfficialConnectorList = async (includingCloudConnectors = false) => {
|
|
145
|
+
export const fetchOfficialConnectorList = async (includingCloudConnectors = false) => {
|
|
143
146
|
const fetchList = async (from = 0, size = 20) => {
|
|
144
147
|
const parameters = new URLSearchParams({
|
|
145
148
|
text: officialConnectorPrefix,
|
|
@@ -8,8 +8,12 @@ import { getDatabaseName } from '../../../queries/database.js';
|
|
|
8
8
|
export const createTenant = async (pool, tenantId) => {
|
|
9
9
|
const database = await getDatabaseName(pool, true);
|
|
10
10
|
const { parentRole, role, password } = createTenantMetadata(database, tenantId);
|
|
11
|
-
const
|
|
12
|
-
|
|
11
|
+
const createTenant = {
|
|
12
|
+
id: tenantId,
|
|
13
|
+
dbUser: role,
|
|
14
|
+
dbUserPassword: password,
|
|
15
|
+
};
|
|
16
|
+
await pool.query(insertInto(createTenant, 'tenants'));
|
|
13
17
|
await pool.query(sql `
|
|
14
18
|
create role ${sql.identifier([role])} with inherit login
|
|
15
19
|
password '${raw(password)}'
|
|
@@ -17,8 +21,8 @@ export const createTenant = async (pool, tenantId) => {
|
|
|
17
21
|
`);
|
|
18
22
|
};
|
|
19
23
|
export const seedAdminData = async (pool, data, ...additionalScopes) => {
|
|
20
|
-
const { resource,
|
|
21
|
-
assert(resource.tenantId === scope.tenantId && scope.tenantId === role.tenantId, new Error('All data should have the same tenant ID'));
|
|
24
|
+
const { resource, scopes, role } = data;
|
|
25
|
+
assert(scopes.every((scope) => resource.tenantId === scope.tenantId && scope.tenantId === role.tenantId), new Error('All data should have the same tenant ID'));
|
|
22
26
|
const processRole = async () => {
|
|
23
27
|
if ('id' in role) {
|
|
24
28
|
await pool.query(insertInto(role, 'roles'));
|
|
@@ -33,15 +37,14 @@ export const seedAdminData = async (pool, data, ...additionalScopes) => {
|
|
|
33
37
|
return id;
|
|
34
38
|
};
|
|
35
39
|
await pool.query(insertInto(resource, 'resources'));
|
|
36
|
-
await pool.query(insertInto(scope, 'scopes'));
|
|
37
|
-
await Promise.all(additionalScopes.map(async (scope) => pool.query(insertInto(scope, 'scopes'))));
|
|
40
|
+
await Promise.all([...scopes, ...additionalScopes].map(async (scope) => pool.query(insertInto(scope, 'scopes'))));
|
|
38
41
|
const roleId = await processRole();
|
|
39
|
-
await pool.query(insertInto({
|
|
42
|
+
await Promise.all(scopes.map(async ({ id }) => pool.query(insertInto({
|
|
40
43
|
id: generateStandardId(),
|
|
41
44
|
roleId,
|
|
42
|
-
scopeId:
|
|
45
|
+
scopeId: id,
|
|
43
46
|
tenantId: resource.tenantId,
|
|
44
|
-
}, 'roles_scopes'));
|
|
47
|
+
}, 'roles_scopes'))));
|
|
45
48
|
};
|
|
46
49
|
export const assignScopesToRole = async (pool, tenantId, roleId, ...scopeIds) => {
|
|
47
50
|
await Promise.all(scopeIds.map(async (scopeId) => pool.query(insertInto({
|
|
@@ -112,7 +112,7 @@ export const decompress = async (toPath, tarPath) => {
|
|
|
112
112
|
export const seedDatabase = async (instancePath, cloud) => {
|
|
113
113
|
try {
|
|
114
114
|
const pool = await createPoolAndDatabaseIfNeeded();
|
|
115
|
-
await seedByPool(pool);
|
|
115
|
+
await seedByPool(pool, cloud);
|
|
116
116
|
await pool.end();
|
|
117
117
|
}
|
|
118
118
|
catch (error) {
|
|
@@ -4,7 +4,7 @@ import { got, HTTPError } from 'got';
|
|
|
4
4
|
import { HttpsProxyAgent } from 'hpagent';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { consoleLog, getProxy } from '../../utils.js';
|
|
7
|
-
import {
|
|
7
|
+
import { getTranslationPromptMessages } from './prompts.js';
|
|
8
8
|
export const createOpenaiApi = () => {
|
|
9
9
|
const proxy = getProxy();
|
|
10
10
|
return got.extend({
|
|
@@ -30,16 +30,11 @@ export const translate = async ({ api, targetLanguage, sourceFilePath, extraProm
|
|
|
30
30
|
.post('chat/completions', {
|
|
31
31
|
json: {
|
|
32
32
|
model: 'gpt-3.5-turbo',
|
|
33
|
-
messages:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
targetLanguage,
|
|
39
|
-
extraPrompt,
|
|
40
|
-
}),
|
|
41
|
-
},
|
|
42
|
-
],
|
|
33
|
+
messages: getTranslationPromptMessages({
|
|
34
|
+
sourceFileContent,
|
|
35
|
+
targetLanguage,
|
|
36
|
+
extraPrompt,
|
|
37
|
+
}),
|
|
43
38
|
},
|
|
44
39
|
})
|
|
45
40
|
.json(), (error) => {
|
|
@@ -10,5 +10,8 @@ type GetTranslationPromptProperties = {
|
|
|
10
10
|
* Remember to check the token limit before adding more prompt.
|
|
11
11
|
* Tokens can be counted in https://platform.openai.com/tokenizer
|
|
12
12
|
*/
|
|
13
|
-
export declare const
|
|
13
|
+
export declare const getTranslationPromptMessages: ({ sourceFileContent, targetLanguage, extraPrompt, }: GetTranslationPromptProperties) => {
|
|
14
|
+
role: string;
|
|
15
|
+
content: string;
|
|
16
|
+
}[];
|
|
14
17
|
export {};
|
|
@@ -6,13 +6,12 @@ import { conditionalString } from '@silverhand/essentials';
|
|
|
6
6
|
* Remember to check the token limit before adding more prompt.
|
|
7
7
|
* Tokens can be counted in https://platform.openai.com/tokenizer
|
|
8
8
|
*/
|
|
9
|
-
export const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
only translate object values to ${languages[targetLanguage]}, keep all object keys original, output ts code only, the code format should be strictly consistent, and should not contains the given code snippet.
|
|
9
|
+
export const getTranslationPromptMessages = ({ sourceFileContent, targetLanguage, extraPrompt, }) => [
|
|
10
|
+
{
|
|
11
|
+
role: 'assistant',
|
|
12
|
+
content: `You are a translate assistant of a Typescript engineer, when you receive a code snippet that contains an object, translate and ONLY translate those values that are marked with comment "// UNTRANSLATED" into the language ${languages[targetLanguage]}, remove the "// UNTRANSLATED" mark, keep all object keys original, output ts code only, the code format should be strictly consistent, and should not contain the given code snippet. ${conditionalString(extraPrompt)}
|
|
14
13
|
|
|
15
|
-
Take
|
|
14
|
+
Take Chinese as an example, if the input is:
|
|
16
15
|
\`\`\`ts
|
|
17
16
|
import others from './others.js';
|
|
18
17
|
|
|
@@ -35,5 +34,12 @@ const translation = {
|
|
|
35
34
|
};
|
|
36
35
|
|
|
37
36
|
export default translation;
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
\`\`\``,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
role: 'user',
|
|
41
|
+
content: `\`\`\`ts
|
|
42
|
+
${sourceFileContent}
|
|
43
|
+
\`\`\``,
|
|
44
|
+
},
|
|
45
|
+
];
|
|
@@ -8,7 +8,7 @@ const sync = {
|
|
|
8
8
|
command: ['sync'],
|
|
9
9
|
describe: 'Translate all untranslated phrases using ChatGPT. Note the environment variable `OPENAI_API_KEY` is required to work.',
|
|
10
10
|
handler: async ({ path: inputPath }) => {
|
|
11
|
-
const queue = new PQueue({ concurrency:
|
|
11
|
+
const queue = new PQueue({ concurrency: 1 });
|
|
12
12
|
const instancePath = await inquireInstancePath(inputPath);
|
|
13
13
|
for (const languageTag of Object.keys(languages)) {
|
|
14
14
|
if (languageTag === baseLanguage) {
|
package/lib/package-json.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export const packageJson = {
|
|
2
2
|
"name": "@logto/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Logto CLI.",
|
|
5
5
|
"author": "Silverhand Inc. <contact@silverhand.io>",
|
|
6
6
|
"homepage": "https://github.com/logto-io/logto#readme",
|
|
@@ -44,17 +44,17 @@ export const packageJson = {
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@logto/connector-kit": "workspace:^1.1.1",
|
|
47
|
-
"@logto/core-kit": "workspace:^2.0.
|
|
47
|
+
"@logto/core-kit": "workspace:^2.0.1",
|
|
48
48
|
"@logto/language-kit": "workspace:^1.0.0",
|
|
49
|
-
"@logto/phrases": "workspace:^1.
|
|
49
|
+
"@logto/phrases": "workspace:^1.4.1",
|
|
50
50
|
"@logto/phrases-ui": "workspace:^1.2.0",
|
|
51
|
-
"@logto/schemas": "workspace:1.
|
|
51
|
+
"@logto/schemas": "workspace:1.6.0",
|
|
52
52
|
"@logto/shared": "workspace:^2.0.0",
|
|
53
53
|
"@silverhand/essentials": "^2.5.0",
|
|
54
54
|
"chalk": "^5.0.0",
|
|
55
55
|
"decamelize": "^6.0.0",
|
|
56
56
|
"dotenv": "^16.0.0",
|
|
57
|
-
"got": "^
|
|
57
|
+
"got": "^13.0.0",
|
|
58
58
|
"hpagent": "^1.2.0",
|
|
59
59
|
"inquirer": "^9.0.0",
|
|
60
60
|
"nanoid": "^4.0.0",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Logto CLI.",
|
|
5
5
|
"author": "Silverhand Inc. <contact@silverhand.io>",
|
|
6
6
|
"homepage": "https://github.com/logto-io/logto#readme",
|
|
@@ -29,17 +29,17 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@logto/connector-kit": "^1.1.1",
|
|
32
|
-
"@logto/core-kit": "^2.0.
|
|
32
|
+
"@logto/core-kit": "^2.0.1",
|
|
33
33
|
"@logto/language-kit": "^1.0.0",
|
|
34
|
-
"@logto/phrases": "^1.
|
|
34
|
+
"@logto/phrases": "^1.4.1",
|
|
35
35
|
"@logto/phrases-ui": "^1.2.0",
|
|
36
|
-
"@logto/schemas": "1.
|
|
36
|
+
"@logto/schemas": "1.6.0",
|
|
37
37
|
"@logto/shared": "^2.0.0",
|
|
38
38
|
"@silverhand/essentials": "^2.5.0",
|
|
39
39
|
"chalk": "^5.0.0",
|
|
40
40
|
"decamelize": "^6.0.0",
|
|
41
41
|
"dotenv": "^16.0.0",
|
|
42
|
-
"got": "^
|
|
42
|
+
"got": "^13.0.0",
|
|
43
43
|
"hpagent": "^1.2.0",
|
|
44
44
|
"inquirer": "^9.0.0",
|
|
45
45
|
"nanoid": "^4.0.0",
|