@zhin.js/gateway 1.1.2 → 1.3.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/README.md +5 -5
- package/lib/config/configuration.d.ts +16 -0
- package/lib/config/configuration.js +32 -7
- package/lib/config/environment-files.d.ts +42 -0
- package/lib/config/environment-files.js +347 -7
- package/lib/config/validation-messages.d.ts +13 -0
- package/lib/config/validation-messages.js +59 -0
- package/lib/database/config.js +31 -0
- package/lib/database/console-role.d.ts +35 -0
- package/lib/database/console-role.js +108 -0
- package/lib/database/gateway-store.d.ts +43 -0
- package/lib/database/gateway-store.js +90 -0
- package/lib/database/index.d.ts +2 -0
- package/lib/database/index.js +2 -0
- package/lib/database/project-database.d.ts +45 -0
- package/lib/database/project-database.js +212 -6
- package/lib/http/console-rpc.d.ts +3 -1
- package/lib/http/console-rpc.js +31 -4
- package/lib/http/gateway-console.d.ts +15 -8
- package/lib/http/gateway-console.js +134 -50
- package/lib/http/gateway-http-server.js +39 -1
- package/lib/http/plugin-switch-rpc.js +11 -6
- package/lib/http/start-gateway.js +9 -0
- package/lib/iam/index.d.ts +4 -3
- package/lib/iam/index.js +4 -3
- package/lib/iam/install.d.ts +17 -11
- package/lib/iam/install.js +39 -18
- package/lib/iam/legacy-import.d.ts +151 -0
- package/lib/iam/legacy-import.js +600 -0
- package/lib/iam/local-admin.d.ts +2 -0
- package/lib/iam/local-admin.js +6 -1
- package/lib/iam/routes.js +10 -2
- package/lib/iam/rpc.js +1 -1
- package/lib/iam/service.d.ts +31 -0
- package/lib/iam/service.js +49 -4
- package/lib/iam/setup-service.d.ts +2 -0
- package/lib/iam/setup-service.js +11 -4
- package/lib/iam/tables.d.ts +6 -6
- package/lib/iam/tables.js +6 -8
- package/lib/local/protocol.d.ts +6 -0
- package/lib/local/protocol.js +6 -0
- package/lib/packages/errors.js +1 -0
- package/lib/packages/rpc.d.ts +6 -1
- package/lib/packages/rpc.js +28 -2
- package/lib/packages/service.d.ts +3 -1
- package/lib/packages/service.js +22 -4
- package/lib/plugin-management/use-cases.js +8 -8
- package/lib/plugin-management/workflow.d.ts +8 -2
- package/lib/plugin-management/workflow.js +28 -10
- package/lib/supervisor/instance-supervisor.d.ts +4 -1
- package/lib/supervisor/instance-supervisor.js +18 -1
- package/lib/terminal/modules.d.ts +12 -0
- package/lib/terminal/modules.js +38 -2
- package/lib/usage/aggregate.d.ts +64 -3
- package/lib/usage/aggregate.js +199 -26
- package/lib/usage/prompt-cache.d.ts +49 -0
- package/lib/usage/prompt-cache.js +113 -0
- package/lib/usage.d.ts +1 -0
- package/lib/usage.js +1 -0
- package/package.json +7 -7
package/lib/iam/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { installConsoleIam, projectEnvironment, type ConsoleIamInstallation, type InstallConsoleIamOptions } from './install.js';
|
|
2
|
-
export { accountInputProblem, ConsoleIamService, IamError, type BindingInput, type ConsoleAuditView, type ConsoleBindingView, type ConsoleCredentialRevocation, type ConsoleCredentialRevocationReason, type ConsoleIamServiceOptions, type ConsoleRoleView, type ConsoleTokenView, type ConsoleUserView, type IamDatabase, type IamErrorCode, } from './service.js';
|
|
3
|
-
export { ConsoleSetupService, SETUP_NO_MIGRATION_NOTICE, upsertDotenv, type ConsoleSetupServiceOptions, type SetupConfigPort, type SetupDatabaseField, type SetupDatabaseInput, type SetupDatabaseSummary, type SetupDriver, type SetupEnvFilePort, type SetupStatus, } from './setup-service.js';
|
|
4
|
-
export { defineConsoleIamTables,
|
|
2
|
+
export { accountInputProblem, IAM_UNAVAILABLE_PUBLIC_MESSAGE, ConsoleIamService, IamError, type BindingInput, type ConsoleAuditView, type ConsoleBindingView, type ConsoleCredentialRevocation, type ConsoleCredentialRevocationReason, type ConsoleIamServiceOptions, type ConsoleRoleView, type ConsoleTokenView, type ConsoleUserView, type IamDatabase, type IamErrorCode, } from './service.js';
|
|
3
|
+
export { ConsoleSetupService, SETUP_CONSOLE_ROLE_NOTICE, SETUP_NO_MIGRATION_NOTICE, upsertDotenv, type ConsoleSetupServiceOptions, type SetupConfigPort, type SetupDatabaseField, type SetupDatabaseInput, type SetupDatabaseSummary, type SetupDriver, type SetupEnvFilePort, type SetupStatus, } from './setup-service.js';
|
|
4
|
+
export { defineConsoleIamTables, IAM_TABLE_DEFINITIONS, IAM_TABLES, type IamTableHost } from './tables.js';
|
|
5
|
+
export { importLegacyIamTables, ensureGatewayStoreMarker, isTransientLegacyImportError, LEGACY_IMPORT_FAILURE_KEY, resetGatewayStore, type LegacyImportFailure, inspectLegacyIamImport, LEGACY_IMPORT_KEY, LegacyImportError, legacyImportSettled, readLegacyImportRecord, revertLegacyIamImport, tableChecksum, type LegacyIamSource, type LegacyImportErrorCode, type LegacyImportInspection, type LegacyImportOptions, type LegacyImportRecord, type LegacySourceSummary, type RevertLegacyImportResult, } from './legacy-import.js';
|
|
5
6
|
export { dispatchIamRpc, isIamRpc } from './rpc.js';
|
|
6
7
|
export { registerConsoleAuthRoutes } from './routes.js';
|
|
7
8
|
export { LoginRateLimiter } from './rate-limit.js';
|
package/lib/iam/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { installConsoleIam, projectEnvironment } from './install.js';
|
|
2
|
-
export { accountInputProblem, ConsoleIamService, IamError, } from './service.js';
|
|
3
|
-
export { ConsoleSetupService, SETUP_NO_MIGRATION_NOTICE, upsertDotenv, } from './setup-service.js';
|
|
4
|
-
export { defineConsoleIamTables,
|
|
2
|
+
export { accountInputProblem, IAM_UNAVAILABLE_PUBLIC_MESSAGE, ConsoleIamService, IamError, } from './service.js';
|
|
3
|
+
export { ConsoleSetupService, SETUP_CONSOLE_ROLE_NOTICE, SETUP_NO_MIGRATION_NOTICE, upsertDotenv, } from './setup-service.js';
|
|
4
|
+
export { defineConsoleIamTables, IAM_TABLE_DEFINITIONS, IAM_TABLES } from './tables.js';
|
|
5
|
+
export { importLegacyIamTables, ensureGatewayStoreMarker, isTransientLegacyImportError, LEGACY_IMPORT_FAILURE_KEY, resetGatewayStore, inspectLegacyIamImport, LEGACY_IMPORT_KEY, LegacyImportError, legacyImportSettled, readLegacyImportRecord, revertLegacyIamImport, tableChecksum, } from './legacy-import.js';
|
|
5
6
|
export { dispatchIamRpc, isIamRpc } from './rpc.js';
|
|
6
7
|
export { registerConsoleAuthRoutes } from './routes.js';
|
|
7
8
|
export { LoginRateLimiter } from './rate-limit.js';
|
package/lib/iam/install.d.ts
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
import type { HttpHost } from '@zhin.js/host-http';
|
|
2
|
-
import {
|
|
2
|
+
import type { ProjectDatabaseConfig } from '../database/config.js';
|
|
3
|
+
import { type GatewayStore } from '../database/gateway-store.js';
|
|
4
|
+
import { ConsoleIamService } from './service.js';
|
|
3
5
|
import { ConsoleSetupService, type SetupConfigPort } from './setup-service.js';
|
|
4
|
-
import { type IamTableHost } from './tables.js';
|
|
5
6
|
export interface InstallConsoleIamOptions {
|
|
6
|
-
/** Process database; tables are defined here, so call before it starts. */
|
|
7
|
-
readonly database: IamDatabase & IamTableHost;
|
|
8
7
|
/** Config file writer (ConsoleConfigurationStore). */
|
|
9
8
|
readonly configStore: SetupConfigPort;
|
|
10
9
|
readonly projectRoot: string;
|
|
10
|
+
/**
|
|
11
|
+
* The project database the old `console_*` tables are imported from (ADR 0059 §3), opened on a
|
|
12
|
+
* connection of its own — never the process DatabaseHost.
|
|
13
|
+
*/
|
|
14
|
+
readonly projectDatabase: () => Promise<ProjectDatabaseConfig>;
|
|
15
|
+
/** Opens the gateway store (default `.zhin/gateway.db` of the project; tests pass their own). */
|
|
16
|
+
readonly openStore?: () => Promise<GatewayStore>;
|
|
11
17
|
readonly apiBase?: string;
|
|
12
18
|
readonly logger?: Readonly<{
|
|
13
19
|
warn(message: string): void;
|
|
20
|
+
info?(message: string): void;
|
|
14
21
|
}>;
|
|
15
22
|
/** Process restart after the setup wizard changed the database. */
|
|
16
23
|
readonly requestRestart?: () => void;
|
|
@@ -20,16 +27,15 @@ export interface InstallConsoleIamOptions {
|
|
|
20
27
|
export interface ConsoleIamInstallation {
|
|
21
28
|
readonly service: ConsoleIamService;
|
|
22
29
|
readonly setup: ConsoleSetupService;
|
|
23
|
-
/**
|
|
24
|
-
readonly supported: boolean;
|
|
25
|
-
/** Call once the database has started (idempotent). */
|
|
30
|
+
/** Opens the gateway store, imports the old tables, starts the service (idempotent). */
|
|
26
31
|
activate(): Promise<void>;
|
|
27
|
-
dispose(): void
|
|
32
|
+
dispose(): Promise<void>;
|
|
28
33
|
}
|
|
29
34
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
35
|
+
* Console access control (ADR 0049) inside one process — a standalone instance (`zhin start
|
|
36
|
+
* --standalone`, development and tests) that has no gateway. It opens `.zhin/gateway.db` itself,
|
|
37
|
+
* so there is no process isolation from plugins there; under the gateway the instance never
|
|
38
|
+
* calls this. Wires the session resolver behind `http.tokenRegistry`, `/auth/*` and the setup flow.
|
|
33
39
|
*/
|
|
34
40
|
export declare function installConsoleIam(http: HttpHost, options: InstallConsoleIamOptions): ConsoleIamInstallation;
|
|
35
41
|
/** process env overlaid with the project `.env` (what `${…}` in config resolves against). */
|
package/lib/iam/install.js
CHANGED
|
@@ -1,23 +1,33 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
2
|
import { readEnvFile, writeEnvFile } from '../config/environment-files.js';
|
|
3
|
+
import { openGatewayStore } from '../database/gateway-store.js';
|
|
3
4
|
import { normalizeBase } from '../http-response.js';
|
|
5
|
+
import { importLegacyIamTables, LegacyImportError } from './legacy-import.js';
|
|
4
6
|
import { registerConsoleAuthRoutes } from './routes.js';
|
|
5
7
|
import { ConsoleIamService } from './service.js';
|
|
6
8
|
import { ConsoleSetupService } from './setup-service.js';
|
|
7
|
-
import { defineConsoleIamTables } from './tables.js';
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* Console access control (ADR 0049) inside one process — a standalone instance (`zhin start
|
|
11
|
+
* --standalone`, development and tests) that has no gateway. It opens `.zhin/gateway.db` itself,
|
|
12
|
+
* so there is no process isolation from plugins there; under the gateway the instance never
|
|
13
|
+
* calls this. Wires the session resolver behind `http.tokenRegistry`, `/auth/*` and the setup flow.
|
|
12
14
|
*/
|
|
13
15
|
export function installConsoleIam(http, options) {
|
|
14
|
-
|
|
16
|
+
let store;
|
|
17
|
+
let pending = 'Console 访问控制正在启动';
|
|
18
|
+
let pendingCode = 'starting';
|
|
19
|
+
const database = Object.freeze({
|
|
20
|
+
get started() { return store?.started ?? false; },
|
|
21
|
+
models: Object.freeze({ get: (name) => store?.models.get(name) }),
|
|
22
|
+
});
|
|
15
23
|
const service = new ConsoleIamService({
|
|
16
|
-
database
|
|
24
|
+
database,
|
|
17
25
|
projectRoot: options.projectRoot,
|
|
18
26
|
onError: error => options.logger?.warn(`console iam: ${error instanceof Error ? error.message : String(error)}`),
|
|
19
27
|
// Installed on the token registry by the runtime composition root; empty until then.
|
|
20
28
|
pluginPermissions: () => http.tokenRegistry.pluginPermissions(),
|
|
29
|
+
unavailable: () => pending,
|
|
30
|
+
unavailableCode: () => pendingCode,
|
|
21
31
|
});
|
|
22
32
|
const setup = new ConsoleSetupService({
|
|
23
33
|
projectRoot: options.projectRoot,
|
|
@@ -26,18 +36,14 @@ export function installConsoleIam(http, options) {
|
|
|
26
36
|
read: () => readEnvFile(options.projectRoot, '.env'),
|
|
27
37
|
write: content => writeEnvFile(options.projectRoot, '.env', content),
|
|
28
38
|
},
|
|
29
|
-
iam: () =>
|
|
39
|
+
iam: () => service,
|
|
30
40
|
environment: options.environment ?? (() => projectEnvironment(options.projectRoot)),
|
|
31
41
|
});
|
|
32
|
-
const disposers = [];
|
|
33
|
-
if (supported)
|
|
34
|
-
disposers.push(http.tokenRegistry.useAccessProvider(service));
|
|
35
|
-
else
|
|
36
|
-
options.logger?.warn('console iam: the configured database cannot store Console users; run the setup wizard to choose sqlite/mysql/pg/mongodb');
|
|
42
|
+
const disposers = [http.tokenRegistry.useAccessProvider(service)];
|
|
37
43
|
disposers.push(...registerConsoleAuthRoutes({
|
|
38
44
|
http,
|
|
39
45
|
base: normalizeBase(options.apiBase ?? '/api'),
|
|
40
|
-
iam: () =>
|
|
46
|
+
iam: () => service,
|
|
41
47
|
setup,
|
|
42
48
|
...(options.requestRestart ? { requestRestart: options.requestRestart } : {}),
|
|
43
49
|
}));
|
|
@@ -45,17 +51,32 @@ export function installConsoleIam(http, options) {
|
|
|
45
51
|
return Object.freeze({
|
|
46
52
|
service,
|
|
47
53
|
setup,
|
|
48
|
-
supported,
|
|
49
54
|
activate() {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
55
|
+
activation ??= (async () => {
|
|
56
|
+
try {
|
|
57
|
+
store = await (options.openStore ?? (() => openGatewayStore(options.projectRoot)))();
|
|
58
|
+
await importLegacyIamTables({
|
|
59
|
+
store,
|
|
60
|
+
projectRoot: options.projectRoot,
|
|
61
|
+
projectDatabase: options.projectDatabase,
|
|
62
|
+
logger: { info: message => options.logger?.info?.(message), warn: message => options.logger?.warn(message) },
|
|
63
|
+
});
|
|
64
|
+
await service.start();
|
|
65
|
+
pending = undefined;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
pending = `Console 访问控制不可用:${error instanceof Error ? error.message : String(error)}`;
|
|
69
|
+
pendingCode = error instanceof LegacyImportError && (error.code === 'store_lost' || error.code === 'store_mismatch') ? error.code : 'migration_failed';
|
|
70
|
+
options.logger?.warn(`console iam: ${pending}`);
|
|
71
|
+
}
|
|
72
|
+
})();
|
|
53
73
|
return activation;
|
|
54
74
|
},
|
|
55
|
-
dispose() {
|
|
75
|
+
async dispose() {
|
|
56
76
|
service.stop();
|
|
57
77
|
for (const dispose of disposers.reverse())
|
|
58
78
|
dispose();
|
|
79
|
+
await store?.close().catch(() => undefined);
|
|
59
80
|
},
|
|
60
81
|
});
|
|
61
82
|
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { ProjectDatabaseConfig } from '../database/config.js';
|
|
2
|
+
import type { GatewayStore } from '../database/gateway-store.js';
|
|
3
|
+
import { type ProjectDatabaseTransaction, type StoreMarker, type TableRows } from '../database/project-database.js';
|
|
4
|
+
export declare const LEGACY_IMPORT_KEY = "legacy_import";
|
|
5
|
+
/** Where the rows came from, without secrets. */
|
|
6
|
+
export interface LegacySourceSummary {
|
|
7
|
+
readonly dialect: string;
|
|
8
|
+
readonly location: string;
|
|
9
|
+
}
|
|
10
|
+
export type LegacyImportRecord = Readonly<{
|
|
11
|
+
status: 'fresh';
|
|
12
|
+
at: number;
|
|
13
|
+
source: LegacySourceSummary;
|
|
14
|
+
reason: 'no-tables' | 'no-database-file' | 'non-relational' | 'reset-store';
|
|
15
|
+
}> | Readonly<{
|
|
16
|
+
status: 'copied';
|
|
17
|
+
at: number;
|
|
18
|
+
source: LegacySourceSummary;
|
|
19
|
+
counts: Readonly<Record<string, number>>;
|
|
20
|
+
checksums: Readonly<Record<string, string>>;
|
|
21
|
+
/** Columns each checksum covers. */
|
|
22
|
+
columns: Readonly<Record<string, readonly string[]>>;
|
|
23
|
+
/** Project-relative directory of `console-tables.json`. */
|
|
24
|
+
backup: string;
|
|
25
|
+
}> | Readonly<{
|
|
26
|
+
status: 'done';
|
|
27
|
+
at: number;
|
|
28
|
+
copiedAt: number;
|
|
29
|
+
source: LegacySourceSummary;
|
|
30
|
+
counts: Readonly<Record<string, number>>;
|
|
31
|
+
checksums: Readonly<Record<string, string>>;
|
|
32
|
+
columns: Readonly<Record<string, readonly string[]>>;
|
|
33
|
+
backup: string;
|
|
34
|
+
/** The old tables changed between copy and drop; `changedExport` holds them as they were dropped. */
|
|
35
|
+
changed: boolean;
|
|
36
|
+
changedExport?: string;
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* `unavailable` (project database unreachable or busy, and every error a driver reports — a
|
|
40
|
+
* unique-key violation while copying included: retried with backoff); the rest need the
|
|
41
|
+
* operator and are not retried automatically: `conflict` (gateway.db holds data without a record,
|
|
42
|
+
* or the project database already holds rows on revert), `mismatch` (copy did not read back
|
|
43
|
+
* identically), `invalid` (the old rows cannot be copied: a table without an `id` column),
|
|
44
|
+
* `unsupported`, `store_lost` (the project database's marker says the accounts are in another
|
|
45
|
+
* gateway.db: the store was lost or replaced) and `store_mismatch` (marker of a different store).
|
|
46
|
+
*/
|
|
47
|
+
export type LegacyImportErrorCode = 'unavailable' | 'conflict' | 'mismatch' | 'invalid' | 'unsupported' | 'store_lost' | 'store_mismatch';
|
|
48
|
+
export declare class LegacyImportError extends Error {
|
|
49
|
+
readonly code: LegacyImportErrorCode;
|
|
50
|
+
constructor(code: LegacyImportErrorCode, message: string, options?: {
|
|
51
|
+
cause?: unknown;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/** Whether retrying later may help (the gateway backs off); otherwise the operator must act. */
|
|
55
|
+
export declare function isTransientLegacyImportError(error: unknown): boolean;
|
|
56
|
+
/** `gateway_meta` key of the last non-transient failure (for `zhin doctor`; cleared on success). */
|
|
57
|
+
export declare const LEGACY_IMPORT_FAILURE_KEY = "legacy_import_failure";
|
|
58
|
+
export interface LegacyImportFailure {
|
|
59
|
+
readonly code: LegacyImportErrorCode;
|
|
60
|
+
readonly message: string;
|
|
61
|
+
readonly at: number;
|
|
62
|
+
}
|
|
63
|
+
/** What the import reads and drops (ProjectDatabase satisfies it). */
|
|
64
|
+
export interface LegacyIamSource {
|
|
65
|
+
readonly dialect: string;
|
|
66
|
+
start(): Promise<void>;
|
|
67
|
+
stop(): Promise<void>;
|
|
68
|
+
tableExists(names: readonly string[]): Promise<string[]>;
|
|
69
|
+
readSnapshot(tables: readonly string[]): Promise<TableRows>;
|
|
70
|
+
dropTables(tables: readonly string[]): Promise<void>;
|
|
71
|
+
/** The marker (ADR 0059 §3 修订); a source without these methods has no marker. */
|
|
72
|
+
readStoreMarker?(): Promise<StoreMarker | undefined>;
|
|
73
|
+
writeStoreMarker?(marker: StoreMarker): Promise<void>;
|
|
74
|
+
deleteStoreMarker?(): Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
export interface LegacyImportOptions {
|
|
77
|
+
readonly store: GatewayStore;
|
|
78
|
+
readonly projectRoot: string;
|
|
79
|
+
/** The project database block (resolved only when the state is still undecided). */
|
|
80
|
+
readonly projectDatabase: () => Promise<ProjectDatabaseConfig>;
|
|
81
|
+
/** Opens the project database (default: a ProjectDatabase that defines no table). */
|
|
82
|
+
readonly openSource?: (config: ProjectDatabaseConfig) => LegacyIamSource;
|
|
83
|
+
readonly now?: () => number;
|
|
84
|
+
readonly logger?: Readonly<{
|
|
85
|
+
info?(message: string): void;
|
|
86
|
+
warn?(message: string): void;
|
|
87
|
+
}>;
|
|
88
|
+
}
|
|
89
|
+
export declare function readLegacyImportRecord(store: GatewayStore, trx?: ProjectDatabaseTransaction): Promise<LegacyImportRecord | undefined>;
|
|
90
|
+
/** True when the record lets Console access control open. */
|
|
91
|
+
export declare function legacyImportSettled(record: LegacyImportRecord | undefined): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* SHA-256 of the rows ordered by `id` (code-unit order), as canonical JSON of `[columns, rows]`
|
|
94
|
+
* with integers as decimal strings and null kept: the same rows read from any dialect hash equal.
|
|
95
|
+
*/
|
|
96
|
+
export declare function tableChecksum(table: string, rows: readonly Record<string, unknown>[], columns?: readonly string[]): string;
|
|
97
|
+
/**
|
|
98
|
+
* Brings `gateway_meta.legacy_import` to `fresh` or `done` (or throws). Runs under the gateway
|
|
99
|
+
* store's write lock (`BEGIN IMMEDIATE`), so the gateway and the CLI never import twice. Once
|
|
100
|
+
* settled, it writes the marker (`zhin_gateway_store`) into the project database: a later empty or
|
|
101
|
+
* foreign gateway.db is refused (`store_lost` / `store_mismatch`) instead of reopening setup.
|
|
102
|
+
* Non-transient failures are recorded in `gateway_meta.legacy_import_failure` for `zhin doctor`.
|
|
103
|
+
*/
|
|
104
|
+
export declare function importLegacyIamTables(options: LegacyImportOptions): Promise<LegacyImportRecord>;
|
|
105
|
+
/**
|
|
106
|
+
* Settled store: the marker in the project database must name this store. Missing → written (best
|
|
107
|
+
* effort; also for a SQLite file that did not exist at the first start). A different store id →
|
|
108
|
+
* `store_mismatch`. An unreachable project database is not an error here: this gateway.db is
|
|
109
|
+
* intact, and the marker is checked again on the next start.
|
|
110
|
+
*/
|
|
111
|
+
/**
|
|
112
|
+
* Writes the marker if it is missing for a settled store (the gateway calls it again after the
|
|
113
|
+
* first owner was created and after the supervised instance first reported ready). A store whose
|
|
114
|
+
* import has not settled is left alone; errors are logged, never thrown, except `store_mismatch`.
|
|
115
|
+
*/
|
|
116
|
+
export declare function ensureGatewayStoreMarker(options: LegacyImportOptions): Promise<void>;
|
|
117
|
+
/**
|
|
118
|
+
* `zhin console init --reset-store`: the operator accepts that the Console accounts of the
|
|
119
|
+
* previous gateway.db are gone (ADR 0059 §3 修订). Marks this store as settled (`fresh`, reason
|
|
120
|
+
* `reset-store`) when it has no record, rewrites the project database's marker to this store and
|
|
121
|
+
* records the reset in this store's audit log. Run only while no gateway runs.
|
|
122
|
+
*/
|
|
123
|
+
export declare function resetGatewayStore(options: LegacyImportOptions): Promise<{
|
|
124
|
+
readonly previousStoreId?: string;
|
|
125
|
+
readonly storeId: string;
|
|
126
|
+
}>;
|
|
127
|
+
export interface LegacyImportInspection {
|
|
128
|
+
readonly record: LegacyImportRecord | undefined;
|
|
129
|
+
/** The last failure that needs the operator (not retried automatically). */
|
|
130
|
+
readonly failure?: LegacyImportFailure;
|
|
131
|
+
/** Gateway tables present in the project database again (undefined: not checked or unreachable). */
|
|
132
|
+
readonly reappeared?: readonly string[];
|
|
133
|
+
/** Why the project database could not be checked. */
|
|
134
|
+
readonly problem?: string;
|
|
135
|
+
}
|
|
136
|
+
/** For `zhin doctor`: the record, and whether old tables showed up again in the project database. */
|
|
137
|
+
export declare function inspectLegacyIamImport(options: LegacyImportOptions): Promise<LegacyImportInspection>;
|
|
138
|
+
export interface RevertLegacyImportResult {
|
|
139
|
+
readonly counts: Readonly<Record<string, number>>;
|
|
140
|
+
/** What the operator still has to do (e.g. drop the restricted Console account). */
|
|
141
|
+
readonly warnings: readonly string[];
|
|
142
|
+
/** Project-relative directory with the gateway.db copy taken before the revert. */
|
|
143
|
+
readonly backup: string;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* `zhin console migrate --revert` (before installing a version older than ADR 0059): writes the
|
|
147
|
+
* gateway's tables back into the project database, verifies them, then empties them in
|
|
148
|
+
* gateway.db and clears the record. The project database must not hold rows in those tables.
|
|
149
|
+
* Run only while no gateway runs.
|
|
150
|
+
*/
|
|
151
|
+
export declare function revertLegacyIamImport(options: LegacyImportOptions): Promise<RevertLegacyImportResult>;
|