@logto/cli 1.13.1 → 1.14.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.
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { DatabasePool } from 'slonik';
|
|
2
2
|
import type { CommandModule } from 'yargs';
|
|
3
|
-
export declare const seedByPool: (pool: DatabasePool, cloud?: boolean, test?: boolean) => Promise<void>;
|
|
3
|
+
export declare const seedByPool: (pool: DatabasePool, cloud?: boolean, test?: boolean, encryptBaseRole?: boolean) => Promise<void>;
|
|
4
4
|
declare const seed: CommandModule<Record<string, unknown>, {
|
|
5
5
|
swe?: boolean;
|
|
6
6
|
cloud?: boolean;
|
|
7
7
|
test?: boolean;
|
|
8
8
|
'legacy-test-data'?: boolean;
|
|
9
|
+
'encrypt-base-role'?: boolean;
|
|
9
10
|
}>;
|
|
10
11
|
export default seed;
|
|
@@ -4,7 +4,7 @@ import { consoleLog, oraPromise } from '../../../utils.js';
|
|
|
4
4
|
import { getLatestAlterationTimestamp } from '../alteration/index.js';
|
|
5
5
|
import { getAlterationDirectory } from '../alteration/utils.js';
|
|
6
6
|
import { createTables, seedCloud, seedTables, seedTest } from './tables.js';
|
|
7
|
-
export const seedByPool = async (pool, cloud = false, test = false) => {
|
|
7
|
+
export const seedByPool = async (pool, cloud = false, test = false, encryptBaseRole = false) => {
|
|
8
8
|
await pool.transaction(async (connection) => {
|
|
9
9
|
// Check alteration scripts available in order to insert correct timestamp
|
|
10
10
|
const latestTimestamp = await getLatestAlterationTimestamp();
|
|
@@ -12,9 +12,12 @@ export const seedByPool = async (pool, cloud = false, test = false) => {
|
|
|
12
12
|
throw new Error(`No alteration script found when seeding the database.\n` +
|
|
13
13
|
`Please check \`${getAlterationDirectory()}\` to see if there are alteration scripts available.\n`);
|
|
14
14
|
}
|
|
15
|
-
await oraPromise(createTables(connection), {
|
|
15
|
+
const tableInfo = await oraPromise(createTables(connection, encryptBaseRole), {
|
|
16
16
|
text: 'Create tables',
|
|
17
17
|
});
|
|
18
|
+
if (tableInfo.password.length > 0) {
|
|
19
|
+
consoleLog.info('base role password:', tableInfo.password);
|
|
20
|
+
}
|
|
18
21
|
await seedTables(connection, latestTimestamp, cloud);
|
|
19
22
|
if (cloud) {
|
|
20
23
|
await seedCloud(connection);
|
|
@@ -49,8 +52,12 @@ const seed = {
|
|
|
49
52
|
.option('legacy-test-data', {
|
|
50
53
|
describe: 'Seed test data only for legacy Logto versions (<=1.12.0), this option conflicts with others',
|
|
51
54
|
type: 'boolean',
|
|
55
|
+
})
|
|
56
|
+
.option('encrypt-base-role', {
|
|
57
|
+
describe: 'Seed base role with password',
|
|
58
|
+
type: 'boolean',
|
|
52
59
|
}),
|
|
53
|
-
handler: async ({ swe, cloud, test, legacyTestData }) => {
|
|
60
|
+
handler: async ({ swe, cloud, test, legacyTestData, encryptBaseRole }) => {
|
|
54
61
|
const pool = await createPoolAndDatabaseIfNeeded();
|
|
55
62
|
if (legacyTestData) {
|
|
56
63
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
@@ -67,7 +74,7 @@ const seed = {
|
|
|
67
74
|
return;
|
|
68
75
|
}
|
|
69
76
|
try {
|
|
70
|
-
await seedByPool(pool, cloud, test);
|
|
77
|
+
await seedByPool(pool, cloud, test, encryptBaseRole);
|
|
71
78
|
}
|
|
72
79
|
catch (error) {
|
|
73
80
|
consoleLog.error(error);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { DatabaseTransactionConnection } from 'slonik';
|
|
2
|
-
export declare const createTables: (connection: DatabaseTransactionConnection) => Promise<
|
|
2
|
+
export declare const createTables: (connection: DatabaseTransactionConnection, encryptBaseRole: boolean) => Promise<{
|
|
3
|
+
password: string;
|
|
4
|
+
}>;
|
|
3
5
|
export declare const seedTables: (connection: DatabaseTransactionConnection, latestTimestamp: number, isCloud: boolean) => Promise<void>;
|
|
4
6
|
export declare const seedCloud: (connection: DatabaseTransactionConnection) => Promise<void>;
|
|
5
7
|
/**
|
|
@@ -37,7 +37,7 @@ const lifecycleNames = Object.freeze([
|
|
|
37
37
|
'after_all',
|
|
38
38
|
'after_each',
|
|
39
39
|
]);
|
|
40
|
-
export const createTables = async (connection) => {
|
|
40
|
+
export const createTables = async (connection, encryptBaseRole) => {
|
|
41
41
|
const tableDirectory = getPathInModule('@logto/schemas', 'tables');
|
|
42
42
|
const directoryFiles = await readdir(tableDirectory);
|
|
43
43
|
const tableFiles = directoryFiles.filter((file) => file.endsWith('.sql'));
|
|
@@ -53,6 +53,7 @@ export const createTables = async (connection) => {
|
|
|
53
53
|
query
|
|
54
54
|
.replaceAll('${name}', parameters.name ?? '')
|
|
55
55
|
.replaceAll('${database}', parameters.database ?? '')
|
|
56
|
+
.replaceAll('${password}', parameters.password ?? '')
|
|
56
57
|
/* eslint-enable no-template-curly-in-string */
|
|
57
58
|
)}`);
|
|
58
59
|
}
|
|
@@ -63,7 +64,8 @@ export const createTables = async (connection) => {
|
|
|
63
64
|
];
|
|
64
65
|
const sorted = allQueries.slice().sort(compareQuery);
|
|
65
66
|
const database = await getDatabaseName(connection, true);
|
|
66
|
-
|
|
67
|
+
const password = encryptBaseRole ? generateStandardId(32) : '';
|
|
68
|
+
await runLifecycleQuery('before_all', { database, password });
|
|
67
69
|
/* eslint-disable no-await-in-loop */
|
|
68
70
|
for (const [file, query] of sorted) {
|
|
69
71
|
await connection.query(sql `${raw(query)}`);
|
|
@@ -73,6 +75,7 @@ export const createTables = async (connection) => {
|
|
|
73
75
|
}
|
|
74
76
|
/* eslint-enable no-await-in-loop */
|
|
75
77
|
await runLifecycleQuery('after_all', { database });
|
|
78
|
+
return { password };
|
|
76
79
|
};
|
|
77
80
|
export const seedTables = async (connection, latestTimestamp, isCloud) => {
|
|
78
81
|
await createTenant(connection, defaultTenantId);
|
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.14.0",
|
|
4
4
|
"description": "Logto CLI.",
|
|
5
5
|
"author": "Silverhand Inc. <contact@silverhand.io>",
|
|
6
6
|
"homepage": "https://github.com/logto-io/logto#readme",
|
|
@@ -48,7 +48,7 @@ export const packageJson = {
|
|
|
48
48
|
"@logto/language-kit": "workspace:^1.1.0",
|
|
49
49
|
"@logto/phrases": "workspace:^1.9.0",
|
|
50
50
|
"@logto/phrases-experience": "workspace:^1.6.0",
|
|
51
|
-
"@logto/schemas": "workspace:1.
|
|
51
|
+
"@logto/schemas": "workspace:1.14.0",
|
|
52
52
|
"@logto/shared": "workspace:^3.1.0",
|
|
53
53
|
"@silverhand/essentials": "^2.9.0",
|
|
54
54
|
"chalk": "^5.0.0",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "Logto CLI.",
|
|
5
5
|
"author": "Silverhand Inc. <contact@silverhand.io>",
|
|
6
6
|
"homepage": "https://github.com/logto-io/logto#readme",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@logto/language-kit": "^1.1.0",
|
|
34
34
|
"@logto/phrases": "^1.9.0",
|
|
35
35
|
"@logto/phrases-experience": "^1.6.0",
|
|
36
|
-
"@logto/schemas": "1.
|
|
36
|
+
"@logto/schemas": "1.14.0",
|
|
37
37
|
"@logto/shared": "^3.1.0",
|
|
38
38
|
"@silverhand/essentials": "^2.9.0",
|
|
39
39
|
"chalk": "^5.0.0",
|