@twin.org/node-core 0.9.1-next.1 → 0.9.1-next.10
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/dist/es/builders/engineEnvBuilder.js +24 -3
- package/dist/es/builders/engineEnvBuilder.js.map +1 -1
- package/dist/es/cli.js +41 -12
- package/dist/es/cli.js.map +1 -1
- package/dist/es/commands/bootstrapLegacy.js +1 -1
- package/dist/es/commands/bootstrapLegacy.js.map +1 -1
- package/dist/es/commands/help.js +10 -1
- package/dist/es/commands/help.js.map +1 -1
- package/dist/es/commands/identityCreate.js +3 -3
- package/dist/es/commands/identityCreate.js.map +1 -1
- package/dist/es/commands/identityList.js +65 -0
- package/dist/es/commands/identityList.js.map +1 -0
- package/dist/es/commands/identityResolve.js +83 -0
- package/dist/es/commands/identityResolve.js.map +1 -0
- package/dist/es/commands/nodeIdentityGet.js +68 -0
- package/dist/es/commands/nodeIdentityGet.js.map +1 -0
- package/dist/es/commands/{nodeSetIdentity.js → nodeIdentitySet.js} +16 -15
- package/dist/es/commands/nodeIdentitySet.js.map +1 -0
- package/dist/es/commands/nodeOrgIdGet.js +55 -0
- package/dist/es/commands/nodeOrgIdGet.js.map +1 -0
- package/dist/es/commands/{setNodeOrgId.js → nodeOrgIdSet.js} +15 -13
- package/dist/es/commands/nodeOrgIdSet.js.map +1 -0
- package/dist/es/commands/orgUsersList.js +94 -0
- package/dist/es/commands/orgUsersList.js.map +1 -0
- package/dist/es/commands/tenantGet.js +68 -0
- package/dist/es/commands/tenantGet.js.map +1 -0
- package/dist/es/commands/tenantList.js +69 -0
- package/dist/es/commands/tenantList.js.map +1 -0
- package/dist/es/commands/tenantListByOrg.js +80 -0
- package/dist/es/commands/tenantListByOrg.js.map +1 -0
- package/dist/es/commands/{setTenantOrgId.js → tenantOrgIdSet.js} +16 -15
- package/dist/es/commands/tenantOrgIdSet.js.map +1 -0
- package/dist/es/commands/userGet.js +77 -0
- package/dist/es/commands/userGet.js.map +1 -0
- package/dist/es/models/ICliCommandDefinition.js.map +1 -1
- package/dist/es/models/IEngineEnvironmentVariables.js.map +1 -1
- package/dist/es/models/engineEnvironmentVariableKeys.js +8 -0
- package/dist/es/models/engineEnvironmentVariableKeys.js.map +1 -1
- package/dist/es/node.js +4 -35
- package/dist/es/node.js.map +1 -1
- package/dist/types/commands/identityList.d.ts +17 -0
- package/dist/types/commands/identityResolve.d.ts +24 -0
- package/dist/types/commands/nodeIdentityGet.d.ts +20 -0
- package/dist/types/commands/{nodeSetIdentity.d.ts → nodeIdentitySet.d.ts} +2 -2
- package/dist/types/commands/nodeOrgIdGet.d.ts +19 -0
- package/dist/types/commands/{setNodeOrgId.d.ts → nodeOrgIdSet.d.ts} +2 -2
- package/dist/types/commands/orgUsersList.d.ts +27 -0
- package/dist/types/commands/tenantGet.d.ts +22 -0
- package/dist/types/commands/tenantList.d.ts +22 -0
- package/dist/types/commands/tenantListByOrg.d.ts +22 -0
- package/dist/types/commands/{setTenantOrgId.d.ts → tenantOrgIdSet.d.ts} +2 -2
- package/dist/types/commands/userGet.d.ts +24 -0
- package/dist/types/models/ICliCommandDefinition.d.ts +8 -0
- package/dist/types/models/IEngineEnvironmentVariables.d.ts +45 -5
- package/docs/changelog.md +65 -0
- package/docs/reference/interfaces/ICliCommandDefinition.md +16 -0
- package/docs/reference/interfaces/IEngineEnvironmentVariables.md +77 -5
- package/locales/en.json +229 -14
- package/package.json +2 -3
- package/dist/es/commands/nodeSetIdentity.js.map +0 -1
- package/dist/es/commands/setNodeOrgId.js.map +0 -1
- package/dist/es/commands/setTenantOrgId.js.map +0 -1
|
@@ -3,40 +3,42 @@
|
|
|
3
3
|
import { CLIDisplay } from "@twin.org/cli-core";
|
|
4
4
|
import { Coerce, GeneralError, I18n } from "@twin.org/core";
|
|
5
5
|
import { Did } from "@twin.org/identity-models";
|
|
6
|
-
const COMMAND_NAME = "
|
|
6
|
+
const COMMAND_NAME = "node-org-id-set";
|
|
7
7
|
/**
|
|
8
8
|
* Get the command definition parameters.
|
|
9
9
|
* @param commandDefinitions The registered command definitions.
|
|
10
10
|
*/
|
|
11
|
-
export function
|
|
11
|
+
export function getCommandDefinitionNodeOrgIdSet(commandDefinitions) {
|
|
12
12
|
commandDefinitions[COMMAND_NAME] = {
|
|
13
13
|
command: COMMAND_NAME,
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
aliases: ["set-node-org-id"],
|
|
15
|
+
description: I18n.formatMessage("node.cli.commands.node-org-id-set.description"),
|
|
16
|
+
example: I18n.formatMessage("node.cli.commands.node-org-id-set.example"),
|
|
16
17
|
requiresNodeIdentity: false,
|
|
17
18
|
requiresOrgIdentity: false,
|
|
19
|
+
singleTenantOnly: true,
|
|
18
20
|
params: [
|
|
19
21
|
{
|
|
20
22
|
key: "env-prefix",
|
|
21
23
|
type: "string",
|
|
22
|
-
description: I18n.formatMessage("node.cli.commands.
|
|
24
|
+
description: I18n.formatMessage("node.cli.commands.node-org-id-set.params.env-prefix.description"),
|
|
23
25
|
required: false
|
|
24
26
|
},
|
|
25
27
|
{
|
|
26
28
|
key: "organization-id",
|
|
27
29
|
type: "string",
|
|
28
30
|
extendedType: "did",
|
|
29
|
-
description: I18n.formatMessage("node.cli.commands.
|
|
31
|
+
description: I18n.formatMessage("node.cli.commands.node-org-id-set.params.organization-id.description"),
|
|
30
32
|
required: true
|
|
31
33
|
},
|
|
32
34
|
{
|
|
33
35
|
key: "load-env",
|
|
34
36
|
type: "string",
|
|
35
|
-
description: I18n.formatMessage("node.cli.commands.
|
|
37
|
+
description: I18n.formatMessage("node.cli.commands.node-org-id-set.params.load-env.description"),
|
|
36
38
|
required: false
|
|
37
39
|
}
|
|
38
40
|
],
|
|
39
|
-
action: async (engineCore, envVars, params) =>
|
|
41
|
+
action: async (engineCore, envVars, params) => nodeOrgIdSet(engineCore, envVars, params)
|
|
40
42
|
};
|
|
41
43
|
}
|
|
42
44
|
/**
|
|
@@ -48,15 +50,15 @@ export function getCommandDefinitionSetNodeOrgId(commandDefinitions) {
|
|
|
48
50
|
* @returns A promise that resolves when the node organization ID has been persisted.
|
|
49
51
|
* @throws GeneralError if called while multi-tenant mode is enabled.
|
|
50
52
|
*/
|
|
51
|
-
export async function
|
|
53
|
+
export async function nodeOrgIdSet(engineCore, envVars, params) {
|
|
52
54
|
if (Coerce.boolean(envVars.tenantEnabled) ?? false) {
|
|
53
|
-
throw new GeneralError("
|
|
55
|
+
throw new GeneralError("nodeOrgIdSet", "notAvailableInMultiTenantMode");
|
|
54
56
|
}
|
|
55
|
-
Did.guard("
|
|
57
|
+
Did.guard("nodeOrgIdSet", "organizationId", params.organizationId);
|
|
56
58
|
const state = engineCore.getState();
|
|
57
59
|
state.nodeOrganizationId = params.organizationId;
|
|
58
60
|
engineCore.setStateDirty();
|
|
59
|
-
CLIDisplay.task(I18n.formatMessage("node.cli.commands.
|
|
61
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.node-org-id-set.labels.stored"));
|
|
60
62
|
CLIDisplay.done();
|
|
61
63
|
}
|
|
62
|
-
//# sourceMappingURL=
|
|
64
|
+
//# sourceMappingURL=nodeOrgIdSet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodeOrgIdSet.js","sourceRoot":"","sources":["../../../src/commands/nodeOrgIdSet.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAE5D,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAMhD,MAAM,YAAY,GAAG,iBAAiB,CAAC;AAEvC;;;GAGG;AACH,MAAM,UAAU,gCAAgC,CAAC,kBAEhD;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,OAAO,EAAE,CAAC,iBAAiB,CAAC;QAC5B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BAAkB,GAAG,MAAM,CAAC,cAAc,CAAC;IACjD,UAAU,CAAC,aAAa,EAAE,CAAC;IAE3B,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,iDAAiD,CAAC,CAAC,CAAC;IAEvF,UAAU,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { Coerce, GeneralError, I18n } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { Did } from \"@twin.org/identity-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { IEnvironmentVariables } from \"../models/IEnvironmentVariables.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\n\nconst COMMAND_NAME = \"node-org-id-set\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionNodeOrgIdSet(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\taliases: [\"set-node-org-id\"],\n\t\tdescription: I18n.formatMessage(\"node.cli.commands.node-org-id-set.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.node-org-id-set.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresOrgIdentity: false,\n\t\tsingleTenantOnly: true,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.node-org-id-set.params.env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"organization-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"did\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.node-org-id-set.params.organization-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.node-org-id-set.params.load-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars, params) => nodeOrgIdSet(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for setting the node organization ID.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.organizationId The organization ID to set.\n * @returns A promise that resolves when the node organization ID has been persisted.\n * @throws GeneralError if called while multi-tenant mode is enabled.\n */\nexport async function nodeOrgIdSet(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: IEnvironmentVariables,\n\tparams: {\n\t\torganizationId?: string;\n\t}\n): Promise<void> {\n\tif (Coerce.boolean(envVars.tenantEnabled) ?? false) {\n\t\tthrow new GeneralError(\"nodeOrgIdSet\", \"notAvailableInMultiTenantMode\");\n\t}\n\n\tDid.guard(\"nodeOrgIdSet\", \"organizationId\", params.organizationId);\n\n\tconst state = engineCore.getState();\n\tstate.nodeOrganizationId = params.organizationId;\n\tengineCore.setStateDirty();\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.node-org-id-set.labels.stored\"));\n\n\tCLIDisplay.done();\n}\n"]}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { CLIDisplay } from "@twin.org/cli-core";
|
|
2
|
+
import { Coerce, ComponentFactory, GeneralError, I18n, Is } from "@twin.org/core";
|
|
3
|
+
import { ComparisonOperator } from "@twin.org/entity";
|
|
4
|
+
import { EntityStorageConnectorFactory } from "@twin.org/entity-storage-models";
|
|
5
|
+
import { Did } from "@twin.org/identity-models";
|
|
6
|
+
const COMMAND_NAME = "org-users-list";
|
|
7
|
+
/**
|
|
8
|
+
* Get the command definition parameters.
|
|
9
|
+
* @param commandDefinitions The registered command definitions.
|
|
10
|
+
*/
|
|
11
|
+
export function getCommandDefinitionOrgUsersList(commandDefinitions) {
|
|
12
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
13
|
+
command: COMMAND_NAME,
|
|
14
|
+
description: I18n.formatMessage("node.cli.commands.org-users-list.description"),
|
|
15
|
+
example: I18n.formatMessage("node.cli.commands.org-users-list.example"),
|
|
16
|
+
requiresNodeIdentity: false,
|
|
17
|
+
requiresOrgIdentity: false,
|
|
18
|
+
params: [
|
|
19
|
+
{
|
|
20
|
+
key: "env-prefix",
|
|
21
|
+
type: "string",
|
|
22
|
+
description: I18n.formatMessage("node.cli.commands.org-users-list.params.env-prefix.description"),
|
|
23
|
+
required: false
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
key: "org-did",
|
|
27
|
+
type: "string",
|
|
28
|
+
extendedType: "did",
|
|
29
|
+
description: I18n.formatMessage("node.cli.commands.org-users-list.params.org-did.description"),
|
|
30
|
+
required: false
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
key: "load-env",
|
|
34
|
+
type: "string",
|
|
35
|
+
description: I18n.formatMessage("node.cli.commands.org-users-list.params.load-env.description"),
|
|
36
|
+
required: false
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
action: async (engineCore, envVars, params) => orgUsersList(engineCore, envVars, params)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Command for listing all users belonging to a given organization DID.
|
|
44
|
+
* @param engineCore The engine core.
|
|
45
|
+
* @param envVars The environment variables for the node.
|
|
46
|
+
* @param params The parameters for the command.
|
|
47
|
+
* @param params.orgDid The organization DID to filter by. Defaults to the node organization ID in single-tenant mode.
|
|
48
|
+
* @returns The list of users for the organization.
|
|
49
|
+
*/
|
|
50
|
+
export async function orgUsersList(engineCore, envVars, params) {
|
|
51
|
+
const isMultiTenant = Coerce.boolean(envVars.tenantEnabled) ?? false;
|
|
52
|
+
let effectiveOrgDid = params.orgDid;
|
|
53
|
+
if (!Is.stringValue(effectiveOrgDid) && !isMultiTenant) {
|
|
54
|
+
effectiveOrgDid = engineCore.getState().nodeOrganizationId;
|
|
55
|
+
}
|
|
56
|
+
if (!Is.stringValue(effectiveOrgDid)) {
|
|
57
|
+
throw new GeneralError("orgUsersList", "orgDidRequired");
|
|
58
|
+
}
|
|
59
|
+
Did.guard("orgUsersList", "org-did", effectiveOrgDid);
|
|
60
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.org-users-list.labels.listing"));
|
|
61
|
+
const authUserStorage = EntityStorageConnectorFactory.get("authentication-user");
|
|
62
|
+
const result = [];
|
|
63
|
+
const platformComponentType = engineCore.getRegisteredInstanceType("platformComponent");
|
|
64
|
+
const platformComponent = ComponentFactory.get(platformComponentType);
|
|
65
|
+
await platformComponent.execute(async () => {
|
|
66
|
+
let cursor;
|
|
67
|
+
do {
|
|
68
|
+
const page = await authUserStorage.query({
|
|
69
|
+
property: "organization",
|
|
70
|
+
value: effectiveOrgDid,
|
|
71
|
+
comparison: ComparisonOperator.Equals
|
|
72
|
+
}, undefined, ["email", "identity", "organization", "scope"], cursor);
|
|
73
|
+
for (const user of page.entities) {
|
|
74
|
+
if (Is.stringValue(user.email)) {
|
|
75
|
+
result.push({
|
|
76
|
+
email: user.email,
|
|
77
|
+
identity: user.identity ?? "",
|
|
78
|
+
scope: user.scope ?? ""
|
|
79
|
+
});
|
|
80
|
+
CLIDisplay.break();
|
|
81
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.org-users-list.labels.email"), user.email);
|
|
82
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.org-users-list.labels.identity"), user.identity ?? "", 1);
|
|
83
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.org-users-list.labels.scope"), user.scope ?? "", 1);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
cursor = page.cursor;
|
|
87
|
+
} while (Is.stringValue(cursor));
|
|
88
|
+
});
|
|
89
|
+
CLIDisplay.break();
|
|
90
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.org-users-list.labels.count"), result.length.toString());
|
|
91
|
+
CLIDisplay.done();
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=orgUsersList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orgUsersList.js","sourceRoot":"","sources":["../../../src/commands/orgUsersList.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAElF,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EACN,6BAA6B,EAE7B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAOhD,MAAM,YAAY,GAAG,gBAAgB,CAAC;AAEtC;;;GAGG;AACH,MAAM,UAAU,gCAAgC,CAAC,kBAEhD;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,8CAA8C,CAAC;QAC/E,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,0CAA0C,CAAC;QACvE,oBAAoB,EAAE,KAAK;QAC3B,mBAAmB,EAAE,KAAK;QAC1B,MAAM,EAAE;YACP;gBACC,GAAG,EAAE,YAAY;gBACjB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,gEAAgE,CAChE;gBACD,QAAQ,EAAE,KAAK;aACf;YACD;gBACC,GAAG,EAAE,SAAS;gBACd,IAAI,EA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AC,MAAM,CAAC;QACtB,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE;IAClC,CAAC,CAAC,CAAC;IAEH,UAAU,CAAC,KAAK,EAAE,CAAC;IACnB,UAAU,CAAC,KAAK,CACf,IAAI,CAAC,aAAa,CAAC,+CAA+C,CAAC,EACnE,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,CACxB,CAAC;IAEF,UAAU,CAAC,IAAI,EAAE,CAAC;IAElB,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { AuthenticationUser } from \"@twin.org/api-auth-entity-storage-service\";\nimport type { IPlatformComponent } from \"@twin.org/api-models\";\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { Coerce, ComponentFactory, GeneralError, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { ComparisonOperator } from \"@twin.org/entity\";\nimport {\n\tEntityStorageConnectorFactory,\n\ttype IEntityStorageConnector\n} from \"@twin.org/entity-storage-models\";\nimport { Did } from \"@twin.org/identity-models\";\nimport { nameofKebabCase } from \"@twin.org/nameof\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { IEnvironmentVariables } from \"../models/IEnvironmentVariables.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\n\nconst COMMAND_NAME = \"org-users-list\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionOrgUsersList(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\"node.cli.commands.org-users-list.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.org-users-list.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresOrgIdentity: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.org-users-list.params.env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"org-did\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"did\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.org-users-list.params.org-did.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.org-users-list.params.load-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars, params) => orgUsersList(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for listing all users belonging to a given organization DID.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.orgDid The organization DID to filter by. Defaults to the node organization ID in single-tenant mode.\n * @returns The list of users for the organization.\n */\nexport async function orgUsersList(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: IEnvironmentVariables,\n\tparams: {\n\t\torgDid?: string;\n\t}\n): Promise<{ email: string; identity: string; scope: string }[]> {\n\tconst isMultiTenant = Coerce.boolean(envVars.tenantEnabled) ?? false;\n\tlet effectiveOrgDid: string | undefined = params.orgDid;\n\tif (!Is.stringValue(effectiveOrgDid) && !isMultiTenant) {\n\t\teffectiveOrgDid = engineCore.getState().nodeOrganizationId;\n\t}\n\n\tif (!Is.stringValue(effectiveOrgDid)) {\n\t\tthrow new GeneralError(\"orgUsersList\", \"orgDidRequired\");\n\t}\n\n\tDid.guard(\"orgUsersList\", \"org-did\", effectiveOrgDid);\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.org-users-list.labels.listing\"));\n\n\tconst authUserStorage =\n\t\tEntityStorageConnectorFactory.get<IEntityStorageConnector<AuthenticationUser>>(\n\t\t\tnameofKebabCase<AuthenticationUser>()\n\t\t);\n\n\tconst result: { email: string; identity: string; scope: string }[] = [];\n\n\tconst platformComponentType = engineCore.getRegisteredInstanceType(\"platformComponent\");\n\tconst platformComponent = ComponentFactory.get<IPlatformComponent>(platformComponentType);\n\n\tawait platformComponent.execute(async () => {\n\t\tlet cursor: string | undefined;\n\t\tdo {\n\t\t\tconst page = await authUserStorage.query(\n\t\t\t\t{\n\t\t\t\t\tproperty: \"organization\",\n\t\t\t\t\tvalue: effectiveOrgDid,\n\t\t\t\t\tcomparison: ComparisonOperator.Equals\n\t\t\t\t},\n\t\t\t\tundefined,\n\t\t\t\t[\"email\", \"identity\", \"organization\", \"scope\"],\n\t\t\t\tcursor\n\t\t\t);\n\t\t\tfor (const user of page.entities) {\n\t\t\t\tif (Is.stringValue(user.email)) {\n\t\t\t\t\tresult.push({\n\t\t\t\t\t\temail: user.email,\n\t\t\t\t\t\tidentity: user.identity ?? \"\",\n\t\t\t\t\t\tscope: user.scope ?? \"\"\n\t\t\t\t\t});\n\t\t\t\t\tCLIDisplay.break();\n\t\t\t\t\tCLIDisplay.value(\n\t\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.org-users-list.labels.email\"),\n\t\t\t\t\t\tuser.email\n\t\t\t\t\t);\n\t\t\t\t\tCLIDisplay.value(\n\t\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.org-users-list.labels.identity\"),\n\t\t\t\t\t\tuser.identity ?? \"\",\n\t\t\t\t\t\t1\n\t\t\t\t\t);\n\t\t\t\t\tCLIDisplay.value(\n\t\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.org-users-list.labels.scope\"),\n\t\t\t\t\t\tuser.scope ?? \"\",\n\t\t\t\t\t\t1\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tcursor = page.cursor;\n\t\t} while (Is.stringValue(cursor));\n\t});\n\n\tCLIDisplay.break();\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"node.cli.commands.org-users-list.labels.count\"),\n\t\tresult.length.toString()\n\t);\n\n\tCLIDisplay.done();\n\n\treturn result;\n}\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { CLIDisplay } from "@twin.org/cli-core";
|
|
2
|
+
import { ComponentFactory, GeneralError, Guards, I18n, Is } from "@twin.org/core";
|
|
3
|
+
const COMMAND_NAME = "tenant-get";
|
|
4
|
+
/**
|
|
5
|
+
* Get the command definition parameters.
|
|
6
|
+
* @param commandDefinitions The registered command definitions.
|
|
7
|
+
*/
|
|
8
|
+
export function getCommandDefinitionTenantGet(commandDefinitions) {
|
|
9
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
10
|
+
command: COMMAND_NAME,
|
|
11
|
+
description: I18n.formatMessage("node.cli.commands.tenant-get.description"),
|
|
12
|
+
example: I18n.formatMessage("node.cli.commands.tenant-get.example"),
|
|
13
|
+
requiresNodeIdentity: false,
|
|
14
|
+
requiresOrgIdentity: false,
|
|
15
|
+
params: [
|
|
16
|
+
{
|
|
17
|
+
key: "env-prefix",
|
|
18
|
+
type: "string",
|
|
19
|
+
description: I18n.formatMessage("node.cli.commands.tenant-get.params.env-prefix.description"),
|
|
20
|
+
required: false
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
key: "tenant-id",
|
|
24
|
+
type: "string",
|
|
25
|
+
extendedType: "hex(32)",
|
|
26
|
+
description: I18n.formatMessage("node.cli.commands.tenant-get.params.tenant-id.description"),
|
|
27
|
+
required: true
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
key: "load-env",
|
|
31
|
+
type: "string",
|
|
32
|
+
description: I18n.formatMessage("node.cli.commands.tenant-get.params.load-env.description"),
|
|
33
|
+
required: false
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
action: async (engineCore, envVars, params) => tenantGet(engineCore, envVars, params)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Command for retrieving a single tenant by ID.
|
|
41
|
+
* @param engineCore The engine core.
|
|
42
|
+
* @param envVars The environment variables for the node.
|
|
43
|
+
* @param params The parameters for the command.
|
|
44
|
+
* @param params.tenantId The ID of the tenant to retrieve.
|
|
45
|
+
* @returns The tenant record.
|
|
46
|
+
*/
|
|
47
|
+
export async function tenantGet(engineCore, envVars, params) {
|
|
48
|
+
Guards.stringHexLength("tenantGet", "tenant-id", params.tenantId, 32);
|
|
49
|
+
const type = engineCore.getRegisteredInstanceTypeOptional("tenantAdminComponent");
|
|
50
|
+
if (!Is.stringValue(type)) {
|
|
51
|
+
throw new GeneralError("tenantGet", "tenantAdminComponentNotRegistered");
|
|
52
|
+
}
|
|
53
|
+
const tenantAdminComponent = ComponentFactory.get(type);
|
|
54
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-get.labels.retrieving"));
|
|
55
|
+
const tenant = await tenantAdminComponent.get(params.tenantId);
|
|
56
|
+
CLIDisplay.break();
|
|
57
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-get.labels.tenantId"), tenant.id);
|
|
58
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-get.labels.apiKey"), tenant.apiKey, 1);
|
|
59
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-get.labels.organizationId"), tenant.organizationId ?? "", 1);
|
|
60
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-get.labels.label"), tenant.label ?? "", 1);
|
|
61
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-get.labels.publicOrigin"), tenant.publicOrigin ?? "", 1);
|
|
62
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-get.labels.dateCreated"), tenant.dateCreated, 1);
|
|
63
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-get.labels.dateModified"), tenant.dateModified, 1);
|
|
64
|
+
CLIDisplay.break();
|
|
65
|
+
CLIDisplay.done();
|
|
66
|
+
return tenant;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=tenantGet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenantGet.js","sourceRoot":"","sources":["../../../src/commands/tenantGet.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAKlF,MAAM,YAAY,GAAG,YAAY,CAAC;AAElC;;;GAGG;AACH,MAAM,UAAU,6BAA6B,CAAC,kBAE7C;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,0CAA0C,CAAC;QAC3E,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,sCAAsC,CAAC;QACnE,oBAAoB,EAAE,KAAK;QAC3B,mBAAmB,EAAE,KAAK;QAC1B,MAAM,EAAE;YACP;gBACC,GAAG,EAAE,YAAY;gBACjB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,4DAA4D,CAC5D;gBACD,QAAQ,EAAE,KAAK;aACf;YACD;gBACC,GAAG,EAAE,WAAW;gBAChB,IAAI,EAAE,QAAQ;gBACd,YAAY,EAAE,SAAS;gBACvB,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,2DAA2D,CAC3D;gBACD,QAAQ,EAAE,IAAI;aACd;YACD;gBACC,GAAG,EAAE,UAAU;gBACf,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,0DAA0D,CAAC;gBAC3F,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,IAAI,CAAC,aAAa,CAAC,2CAA2C,CAAC,EAC/D,MAAM,CAAC,KAAK,IAAI,EAAE,EAClB,CAAC,CACD,CAAC;IACF,UAAU,CAAC,KAAK,CACf,IAAI,CAAC,aAAa,CAAC,kDAAkD,CAAC,EACtE,MAAM,CAAC,YAAY,IAAI,EAAE,EACzB,CAAC,CACD,CAAC;IACF,UAAU,CAAC,KAAK,CACf,IAAI,CAAC,aAAa,CAAC,iDAAiD,CAAC,EACrE,MAAM,CAAC,WAAW,EAClB,CAAC,CACD,CAAC;IACF,UAAU,CAAC,KAAK,CACf,IAAI,CAAC,aAAa,CAAC,kDAAkD,CAAC,EACtE,MAAM,CAAC,YAAY,EACnB,CAAC,CACD,CAAC;IACF,UAAU,CAAC,KAAK,EAAE,CAAC;IAEnB,UAAU,CAAC,IAAI,EAAE,CAAC;IAElB,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ITenantAdminComponent, ITenant } from \"@twin.org/api-models\";\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { ComponentFactory, GeneralError, Guards, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { IEnvironmentVariables } from \"../models/IEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"tenant-get\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionTenantGet(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\"node.cli.commands.tenant-get.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.tenant-get.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresOrgIdentity: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-get.params.env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"tenant-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"hex(32)\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-get.params.tenant-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\"node.cli.commands.tenant-get.params.load-env.description\"),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars, params) => tenantGet(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for retrieving a single tenant by ID.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.tenantId The ID of the tenant to retrieve.\n * @returns The tenant record.\n */\nexport async function tenantGet(\n\tengineCore: IEngineCore,\n\tenvVars: IEnvironmentVariables,\n\tparams: {\n\t\ttenantId?: string;\n\t}\n): Promise<ITenant> {\n\tGuards.stringHexLength(\"tenantGet\", \"tenant-id\", params.tenantId, 32);\n\n\tconst type = engineCore.getRegisteredInstanceTypeOptional(\"tenantAdminComponent\");\n\n\tif (!Is.stringValue(type)) {\n\t\tthrow new GeneralError(\"tenantGet\", \"tenantAdminComponentNotRegistered\");\n\t}\n\n\tconst tenantAdminComponent = ComponentFactory.get<ITenantAdminComponent>(type);\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.tenant-get.labels.retrieving\"));\n\n\tconst tenant = await tenantAdminComponent.get(params.tenantId);\n\n\tCLIDisplay.break();\n\tCLIDisplay.value(I18n.formatMessage(\"node.cli.commands.tenant-get.labels.tenantId\"), tenant.id);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"node.cli.commands.tenant-get.labels.apiKey\"),\n\t\ttenant.apiKey,\n\t\t1\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"node.cli.commands.tenant-get.labels.organizationId\"),\n\t\ttenant.organizationId ?? \"\",\n\t\t1\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"node.cli.commands.tenant-get.labels.label\"),\n\t\ttenant.label ?? \"\",\n\t\t1\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"node.cli.commands.tenant-get.labels.publicOrigin\"),\n\t\ttenant.publicOrigin ?? \"\",\n\t\t1\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"node.cli.commands.tenant-get.labels.dateCreated\"),\n\t\ttenant.dateCreated,\n\t\t1\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"node.cli.commands.tenant-get.labels.dateModified\"),\n\t\ttenant.dateModified,\n\t\t1\n\t);\n\tCLIDisplay.break();\n\n\tCLIDisplay.done();\n\n\treturn tenant;\n}\n"]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { CLIDisplay } from "@twin.org/cli-core";
|
|
2
|
+
import { ComponentFactory, GeneralError, I18n, Is } from "@twin.org/core";
|
|
3
|
+
const COMMAND_NAME = "tenant-list";
|
|
4
|
+
/**
|
|
5
|
+
* Get the command definition parameters.
|
|
6
|
+
* @param commandDefinitions The registered command definitions.
|
|
7
|
+
*/
|
|
8
|
+
export function getCommandDefinitionTenantList(commandDefinitions) {
|
|
9
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
10
|
+
command: COMMAND_NAME,
|
|
11
|
+
description: I18n.formatMessage("node.cli.commands.tenant-list.description"),
|
|
12
|
+
example: I18n.formatMessage("node.cli.commands.tenant-list.example"),
|
|
13
|
+
requiresNodeIdentity: false,
|
|
14
|
+
requiresOrgIdentity: false,
|
|
15
|
+
params: [
|
|
16
|
+
{
|
|
17
|
+
key: "env-prefix",
|
|
18
|
+
type: "string",
|
|
19
|
+
description: I18n.formatMessage("node.cli.commands.tenant-list.params.env-prefix.description"),
|
|
20
|
+
required: false
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
key: "load-env",
|
|
24
|
+
type: "string",
|
|
25
|
+
description: I18n.formatMessage("node.cli.commands.tenant-list.params.load-env.description"),
|
|
26
|
+
required: false
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
action: async (engineCore, envVars) => tenantList(engineCore, envVars)
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Command for listing all tenants.
|
|
34
|
+
* @param engineCore The engine core.
|
|
35
|
+
* @param envVars The environment variables for the node.
|
|
36
|
+
* @returns The list of tenants.
|
|
37
|
+
*/
|
|
38
|
+
export async function tenantList(engineCore, envVars) {
|
|
39
|
+
const type = engineCore.getRegisteredInstanceTypeOptional("tenantAdminComponent");
|
|
40
|
+
if (!Is.stringValue(type)) {
|
|
41
|
+
throw new GeneralError("tenantList", "tenantAdminComponentNotRegistered");
|
|
42
|
+
}
|
|
43
|
+
const tenantAdminComponent = ComponentFactory.get(type);
|
|
44
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-list.labels.listing"));
|
|
45
|
+
const result = [];
|
|
46
|
+
let cursor;
|
|
47
|
+
do {
|
|
48
|
+
const page = await tenantAdminComponent.query(undefined, undefined, cursor);
|
|
49
|
+
for (const tenant of page.tenants) {
|
|
50
|
+
result.push({
|
|
51
|
+
id: tenant.id,
|
|
52
|
+
apiKey: tenant.apiKey,
|
|
53
|
+
organizationId: tenant.organizationId ?? "",
|
|
54
|
+
label: tenant.label ?? ""
|
|
55
|
+
});
|
|
56
|
+
CLIDisplay.break();
|
|
57
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-list.labels.tenantId"), tenant.id);
|
|
58
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-list.labels.apiKey"), tenant.apiKey, 1);
|
|
59
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-list.labels.organizationId"), tenant.organizationId ?? "", 1);
|
|
60
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-list.labels.label"), tenant.label ?? "", 1);
|
|
61
|
+
}
|
|
62
|
+
cursor = page.cursor;
|
|
63
|
+
} while (Is.stringValue(cursor));
|
|
64
|
+
CLIDisplay.break();
|
|
65
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-list.labels.count"), result.length.toString());
|
|
66
|
+
CLIDisplay.done();
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=tenantList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenantList.js","sourceRoot":"","sources":["../../../src/commands/tenantList.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAK1E,MAAM,YAAY,GAAG,aAAa,CAAC;AAEnC;;;GAGG;AACH,MAAM,UAAU,8BAA8B,CAAC,kBAE9C;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,2CAA2C,CAAC;QAC5E,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,uCAAuC,CAAC;QACpE,oBAAoB,EAAE,KAAK;QAC3B,mBAAmB,EAAE,KAAK;QAC1B,MAAM,EAAE;YACP;gBACC,GAAG,EAAE,YAAY;gBACjB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,6DAA6D,CAC7D;gBACD,QAAQ,EAAE,KAAK;aACf;YACD;gBACC,GAAG,EAAE,UAAU;gBACf,IAAI,EAAE,QAAQ;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nE,MAAM,CAAC,EAAE,CACT,CAAC;YACF,UAAU,CAAC,KAAK,CACf,IAAI,CAAC,aAAa,CAAC,6CAA6C,CAAC,EACjE,MAAM,CAAC,MAAM,EACb,CAAC,CACD,CAAC;YACF,UAAU,CAAC,KAAK,CACf,IAAI,CAAC,aAAa,CAAC,qDAAqD,CAAC,EACzE,MAAM,CAAC,cAAc,IAAI,EAAE,EAC3B,CAAC,CACD,CAAC;YACF,UAAU,CAAC,KAAK,CACf,IAAI,CAAC,aAAa,CAAC,4CAA4C,CAAC,EAChE,MAAM,CAAC,KAAK,IAAI,EAAE,EAClB,CAAC,CACD,CAAC;QACH,CAAC;QACD,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IACtB,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE;IAEjC,UAAU,CAAC,KAAK,EAAE,CAAC;IACnB,UAAU,CAAC,KAAK,CACf,IAAI,CAAC,aAAa,CAAC,4CAA4C,CAAC,EAChE,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,CACxB,CAAC;IAEF,UAAU,CAAC,IAAI,EAAE,CAAC;IAElB,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ITenantAdminComponent } from \"@twin.org/api-models\";\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { ComponentFactory, GeneralError, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { IEnvironmentVariables } from \"../models/IEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"tenant-list\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionTenantList(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\"node.cli.commands.tenant-list.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.tenant-list.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresOrgIdentity: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-list.params.env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-list.params.load-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars) => tenantList(engineCore, envVars)\n\t};\n}\n\n/**\n * Command for listing all tenants.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @returns The list of tenants.\n */\nexport async function tenantList(\n\tengineCore: IEngineCore,\n\tenvVars: IEnvironmentVariables\n): Promise<{ id: string; apiKey: string; organizationId: string; label: string }[]> {\n\tconst type = engineCore.getRegisteredInstanceTypeOptional(\"tenantAdminComponent\");\n\n\tif (!Is.stringValue(type)) {\n\t\tthrow new GeneralError(\"tenantList\", \"tenantAdminComponentNotRegistered\");\n\t}\n\n\tconst tenantAdminComponent = ComponentFactory.get<ITenantAdminComponent>(type);\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.tenant-list.labels.listing\"));\n\n\tconst result: { id: string; apiKey: string; organizationId: string; label: string }[] = [];\n\tlet cursor: string | undefined;\n\n\tdo {\n\t\tconst page = await tenantAdminComponent.query(undefined, undefined, cursor);\n\t\tfor (const tenant of page.tenants) {\n\t\t\tresult.push({\n\t\t\t\tid: tenant.id,\n\t\t\t\tapiKey: tenant.apiKey,\n\t\t\t\torganizationId: tenant.organizationId ?? \"\",\n\t\t\t\tlabel: tenant.label ?? \"\"\n\t\t\t});\n\t\t\tCLIDisplay.break();\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.tenant-list.labels.tenantId\"),\n\t\t\t\ttenant.id\n\t\t\t);\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.tenant-list.labels.apiKey\"),\n\t\t\t\ttenant.apiKey,\n\t\t\t\t1\n\t\t\t);\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.tenant-list.labels.organizationId\"),\n\t\t\t\ttenant.organizationId ?? \"\",\n\t\t\t\t1\n\t\t\t);\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.tenant-list.labels.label\"),\n\t\t\t\ttenant.label ?? \"\",\n\t\t\t\t1\n\t\t\t);\n\t\t}\n\t\tcursor = page.cursor;\n\t} while (Is.stringValue(cursor));\n\n\tCLIDisplay.break();\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"node.cli.commands.tenant-list.labels.count\"),\n\t\tresult.length.toString()\n\t);\n\n\tCLIDisplay.done();\n\n\treturn result;\n}\n"]}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { CLIDisplay } from "@twin.org/cli-core";
|
|
2
|
+
import { ComponentFactory, GeneralError, I18n, Is } from "@twin.org/core";
|
|
3
|
+
import { ComparisonOperator } from "@twin.org/entity";
|
|
4
|
+
import { Did } from "@twin.org/identity-models";
|
|
5
|
+
const COMMAND_NAME = "tenant-list-by-org";
|
|
6
|
+
/**
|
|
7
|
+
* Get the command definition parameters.
|
|
8
|
+
* @param commandDefinitions The registered command definitions.
|
|
9
|
+
*/
|
|
10
|
+
export function getCommandDefinitionTenantListByOrg(commandDefinitions) {
|
|
11
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
12
|
+
command: COMMAND_NAME,
|
|
13
|
+
description: I18n.formatMessage("node.cli.commands.tenant-list-by-org.description"),
|
|
14
|
+
example: I18n.formatMessage("node.cli.commands.tenant-list-by-org.example"),
|
|
15
|
+
requiresNodeIdentity: false,
|
|
16
|
+
requiresOrgIdentity: false,
|
|
17
|
+
params: [
|
|
18
|
+
{
|
|
19
|
+
key: "env-prefix",
|
|
20
|
+
type: "string",
|
|
21
|
+
description: I18n.formatMessage("node.cli.commands.tenant-list-by-org.params.env-prefix.description"),
|
|
22
|
+
required: false
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
key: "org-id",
|
|
26
|
+
type: "string",
|
|
27
|
+
extendedType: "did",
|
|
28
|
+
description: I18n.formatMessage("node.cli.commands.tenant-list-by-org.params.org-id.description"),
|
|
29
|
+
required: true
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
key: "load-env",
|
|
33
|
+
type: "string",
|
|
34
|
+
description: I18n.formatMessage("node.cli.commands.tenant-list-by-org.params.load-env.description"),
|
|
35
|
+
required: false
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
action: async (engineCore, envVars, params) => tenantListByOrg(engineCore, envVars, params)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Command for listing all tenants associated with an organization DID.
|
|
43
|
+
* @param engineCore The engine core.
|
|
44
|
+
* @param envVars The environment variables for the node.
|
|
45
|
+
* @param params The parameters for the command.
|
|
46
|
+
* @param params.orgId The organization DID to filter by.
|
|
47
|
+
* @returns The matching tenants.
|
|
48
|
+
*/
|
|
49
|
+
export async function tenantListByOrg(engineCore, envVars, params) {
|
|
50
|
+
Did.guard("tenantListByOrg", "org-id", params.orgId);
|
|
51
|
+
const type = engineCore.getRegisteredInstanceTypeOptional("tenantAdminComponent");
|
|
52
|
+
if (!Is.stringValue(type)) {
|
|
53
|
+
throw new GeneralError("tenantListByOrg", "tenantAdminComponentNotRegistered");
|
|
54
|
+
}
|
|
55
|
+
const tenantAdminComponent = ComponentFactory.get(type);
|
|
56
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-list-by-org.labels.listing"));
|
|
57
|
+
const result = [];
|
|
58
|
+
let cursor;
|
|
59
|
+
do {
|
|
60
|
+
const page = await tenantAdminComponent.query({
|
|
61
|
+
property: "organizationId",
|
|
62
|
+
value: params.orgId,
|
|
63
|
+
comparison: ComparisonOperator.Equals
|
|
64
|
+
}, undefined, cursor);
|
|
65
|
+
for (const tenant of page.tenants) {
|
|
66
|
+
result.push(tenant);
|
|
67
|
+
CLIDisplay.break();
|
|
68
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-list-by-org.labels.tenantId"), tenant.id);
|
|
69
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-list-by-org.labels.apiKey"), tenant.apiKey, 1);
|
|
70
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-list-by-org.labels.organizationId"), tenant.organizationId ?? "", 1);
|
|
71
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-list-by-org.labels.label"), tenant.label ?? "", 1);
|
|
72
|
+
}
|
|
73
|
+
cursor = page.cursor;
|
|
74
|
+
} while (Is.stringValue(cursor));
|
|
75
|
+
CLIDisplay.break();
|
|
76
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-list-by-org.labels.count"), result.length.toString());
|
|
77
|
+
CLIDisplay.done();
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=tenantListByOrg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenantListByOrg.js","sourceRoot":"","sources":["../../../src/commands/tenantListByOrg.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAE1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EA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,MAAM,CAAC;IACtB,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE;IAEjC,UAAU,CAAC,KAAK,EAAE,CAAC;IACnB,UAAU,CAAC,KAAK,CACf,IAAI,CAAC,aAAa,CAAC,mDAAmD,CAAC,EACvE,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,CACxB,CAAC;IAEF,UAAU,CAAC,IAAI,EAAE,CAAC;IAElB,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ITenantAdminComponent, ITenant } from \"@twin.org/api-models\";\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { ComponentFactory, GeneralError, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { ComparisonOperator } from \"@twin.org/entity\";\nimport { Did } from \"@twin.org/identity-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { IEnvironmentVariables } from \"../models/IEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"tenant-list-by-org\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionTenantListByOrg(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\"node.cli.commands.tenant-list-by-org.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.tenant-list-by-org.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresOrgIdentity: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-list-by-org.params.env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"org-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"did\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-list-by-org.params.org-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-list-by-org.params.load-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars, params) => tenantListByOrg(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for listing all tenants associated with an organization DID.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.orgId The organization DID to filter by.\n * @returns The matching tenants.\n */\nexport async function tenantListByOrg(\n\tengineCore: IEngineCore,\n\tenvVars: IEnvironmentVariables,\n\tparams: {\n\t\torgId?: string;\n\t}\n): Promise<ITenant[]> {\n\tDid.guard(\"tenantListByOrg\", \"org-id\", params.orgId);\n\n\tconst type = engineCore.getRegisteredInstanceTypeOptional(\"tenantAdminComponent\");\n\n\tif (!Is.stringValue(type)) {\n\t\tthrow new GeneralError(\"tenantListByOrg\", \"tenantAdminComponentNotRegistered\");\n\t}\n\n\tconst tenantAdminComponent = ComponentFactory.get<ITenantAdminComponent>(type);\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.tenant-list-by-org.labels.listing\"));\n\n\tconst result: ITenant[] = [];\n\tlet cursor: string | undefined;\n\n\tdo {\n\t\tconst page = await tenantAdminComponent.query(\n\t\t\t{\n\t\t\t\tproperty: \"organizationId\",\n\t\t\t\tvalue: params.orgId,\n\t\t\t\tcomparison: ComparisonOperator.Equals\n\t\t\t},\n\t\t\tundefined,\n\t\t\tcursor\n\t\t);\n\t\tfor (const tenant of page.tenants) {\n\t\t\tresult.push(tenant);\n\t\t\tCLIDisplay.break();\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.tenant-list-by-org.labels.tenantId\"),\n\t\t\t\ttenant.id\n\t\t\t);\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.tenant-list-by-org.labels.apiKey\"),\n\t\t\t\ttenant.apiKey,\n\t\t\t\t1\n\t\t\t);\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.tenant-list-by-org.labels.organizationId\"),\n\t\t\t\ttenant.organizationId ?? \"\",\n\t\t\t\t1\n\t\t\t);\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.tenant-list-by-org.labels.label\"),\n\t\t\t\ttenant.label ?? \"\",\n\t\t\t\t1\n\t\t\t);\n\t\t}\n\t\tcursor = page.cursor;\n\t} while (Is.stringValue(cursor));\n\n\tCLIDisplay.break();\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"node.cli.commands.tenant-list-by-org.labels.count\"),\n\t\tresult.length.toString()\n\t);\n\n\tCLIDisplay.done();\n\n\treturn result;\n}\n"]}
|
|
@@ -1,47 +1,48 @@
|
|
|
1
1
|
import { CLIDisplay } from "@twin.org/cli-core";
|
|
2
2
|
import { ComponentFactory, GeneralError, Guards, I18n, Is } from "@twin.org/core";
|
|
3
3
|
import { Did } from "@twin.org/identity-models";
|
|
4
|
-
const COMMAND_NAME = "
|
|
4
|
+
const COMMAND_NAME = "tenant-org-id-set";
|
|
5
5
|
/**
|
|
6
6
|
* Get the command definition parameters.
|
|
7
7
|
* @param commandDefinitions The registered command definitions.
|
|
8
8
|
*/
|
|
9
|
-
export function
|
|
9
|
+
export function getCommandDefinitionTenantOrgIdSet(commandDefinitions) {
|
|
10
10
|
commandDefinitions[COMMAND_NAME] = {
|
|
11
11
|
command: COMMAND_NAME,
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
aliases: ["set-tenant-org-id"],
|
|
13
|
+
description: I18n.formatMessage("node.cli.commands.tenant-org-id-set.description"),
|
|
14
|
+
example: I18n.formatMessage("node.cli.commands.tenant-org-id-set.example"),
|
|
14
15
|
requiresNodeIdentity: false,
|
|
15
16
|
requiresOrgIdentity: false,
|
|
16
17
|
params: [
|
|
17
18
|
{
|
|
18
19
|
key: "env-prefix",
|
|
19
20
|
type: "string",
|
|
20
|
-
description: I18n.formatMessage("node.cli.commands.
|
|
21
|
+
description: I18n.formatMessage("node.cli.commands.tenant-org-id-set.params.env-prefix.description"),
|
|
21
22
|
required: false
|
|
22
23
|
},
|
|
23
24
|
{
|
|
24
25
|
key: "tenant-id",
|
|
25
26
|
type: "string",
|
|
26
27
|
extendedType: "hex(32)",
|
|
27
|
-
description: I18n.formatMessage("node.cli.commands.
|
|
28
|
+
description: I18n.formatMessage("node.cli.commands.tenant-org-id-set.params.tenant-id.description"),
|
|
28
29
|
required: true
|
|
29
30
|
},
|
|
30
31
|
{
|
|
31
32
|
key: "organization-id",
|
|
32
33
|
type: "string",
|
|
33
34
|
extendedType: "did",
|
|
34
|
-
description: I18n.formatMessage("node.cli.commands.
|
|
35
|
+
description: I18n.formatMessage("node.cli.commands.tenant-org-id-set.params.organization-id.description"),
|
|
35
36
|
required: true
|
|
36
37
|
},
|
|
37
38
|
{
|
|
38
39
|
key: "load-env",
|
|
39
40
|
type: "string",
|
|
40
|
-
description: I18n.formatMessage("node.cli.commands.
|
|
41
|
+
description: I18n.formatMessage("node.cli.commands.tenant-org-id-set.params.load-env.description"),
|
|
41
42
|
required: false
|
|
42
43
|
}
|
|
43
44
|
],
|
|
44
|
-
action: async (engineCore, envVars, params) =>
|
|
45
|
+
action: async (engineCore, envVars, params) => tenantOrgIdSet(engineCore, envVars, params)
|
|
45
46
|
};
|
|
46
47
|
}
|
|
47
48
|
/**
|
|
@@ -53,14 +54,14 @@ export function getCommandDefinitionSetTenantOrgId(commandDefinitions) {
|
|
|
53
54
|
* @param params.organizationId The organization ID to set.
|
|
54
55
|
* @returns A promise that resolves when the tenant organization ID has been stored.
|
|
55
56
|
*/
|
|
56
|
-
export async function
|
|
57
|
-
Guards.stringHexLength("
|
|
58
|
-
Did.guard("
|
|
59
|
-
CLIDisplay.task(I18n.formatMessage("node.cli.commands.
|
|
57
|
+
export async function tenantOrgIdSet(engineCore, envVars, params) {
|
|
58
|
+
Guards.stringHexLength("tenantOrgIdSet", "tenant-id", params.tenantId, 32);
|
|
59
|
+
Did.guard("tenantOrgIdSet", "organizationId", params.organizationId);
|
|
60
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-org-id-set.labels.updating"));
|
|
60
61
|
CLIDisplay.spinnerStart();
|
|
61
62
|
await applyOrganizationIdToTenant(engineCore, params.tenantId, params.organizationId);
|
|
62
63
|
CLIDisplay.spinnerStop();
|
|
63
|
-
CLIDisplay.task(I18n.formatMessage("node.cli.commands.
|
|
64
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-org-id-set.labels.stored"));
|
|
64
65
|
CLIDisplay.done();
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
@@ -96,4 +97,4 @@ export async function applyOrganizationIdToTenant(engineCore, tenantId, newOrgan
|
|
|
96
97
|
CLIDisplay.done();
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
|
-
//# sourceMappingURL=
|
|
100
|
+
//# sourceMappingURL=tenantOrgIdSet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenantOrgIdSet.js","sourceRoot":"","sources":["../../../src/commands/tenantOrgIdSet.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAElF,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAIhD,MAAM,YAAY,GAAG,mBAAm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AM,MAAM,GAAG,MAAM,oBAAoB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACxD,MAAM,oBAAoB,CAAC,MAAM,CAAC;QACjC,GAAG,MAAM;QACT,cAAc,EAAE,iBAAiB;KACjC,CAAC,CAAC;IAEH,IAAI,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,YAAY,CAAC,EAAE,CAAC;QAC3C,UAAU,CAAC,IAAI,EAAE,CAAC;IACnB,CAAC;AACF,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ITenantAdminComponent } from \"@twin.org/api-models\";\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { ComponentFactory, GeneralError, Guards, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { Did } from \"@twin.org/identity-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { IEnvironmentVariables } from \"../models/IEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"tenant-org-id-set\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionTenantOrgIdSet(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\taliases: [\"set-tenant-org-id\"],\n\t\tdescription: I18n.formatMessage(\"node.cli.commands.tenant-org-id-set.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.tenant-org-id-set.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresOrgIdentity: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-org-id-set.params.env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"tenant-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"hex(32)\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-org-id-set.params.tenant-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"organization-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"did\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-org-id-set.params.organization-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-org-id-set.params.load-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars, params) => tenantOrgIdSet(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for setting the organization ID on a tenant.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.tenantId The tenant ID to update.\n * @param params.organizationId The organization ID to set.\n * @returns A promise that resolves when the tenant organization ID has been stored.\n */\nexport async function tenantOrgIdSet(\n\tengineCore: IEngineCore,\n\tenvVars: IEnvironmentVariables,\n\tparams: {\n\t\ttenantId?: string;\n\t\torganizationId?: string;\n\t}\n): Promise<void> {\n\tGuards.stringHexLength(\"tenantOrgIdSet\", \"tenant-id\", params.tenantId, 32);\n\n\tDid.guard(\"tenantOrgIdSet\", \"organizationId\", params.organizationId);\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.tenant-org-id-set.labels.updating\"));\n\tCLIDisplay.spinnerStart();\n\n\tawait applyOrganizationIdToTenant(engineCore, params.tenantId, params.organizationId);\n\n\tCLIDisplay.spinnerStop();\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.tenant-org-id-set.labels.stored\"));\n\n\tCLIDisplay.done();\n}\n\n/**\n * Apply a new organization ID to a tenant.\n * @param engineCore The engine core used to look up the tenantAdminComponent.\n * @param tenantId The ID of the tenant to update.\n * @param newOrganizationId The new organization DID to set.\n * @param options Optional display and behaviour overrides.\n * @param options.sectionLabel When set, emits a CLI section header before and done marker after.\n * @param options.required When false, returns silently when the component is not registered (default true).\n * @returns A promise that resolves when the tenant record has been updated.\n * @throws GeneralError if the component is required but not registered.\n */\nexport async function applyOrganizationIdToTenant(\n\tengineCore: IEngineCore,\n\ttenantId: string,\n\tnewOrganizationId: string,\n\toptions?: { sectionLabel?: string; required?: boolean }\n): Promise<void> {\n\tconst type = engineCore.getRegisteredInstanceTypeOptional(\"tenantAdminComponent\");\n\n\tif (!Is.stringValue(type)) {\n\t\tif (options?.required ?? true) {\n\t\t\tthrow new GeneralError(\"applyOrganizationIdToTenant\", \"tenantAdminComponentNotRegistered\");\n\t\t}\n\t\treturn;\n\t}\n\n\tif (Is.stringValue(options?.sectionLabel)) {\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.section(options.sectionLabel);\n\t}\n\n\tconst tenantAdminComponent = ComponentFactory.get<ITenantAdminComponent>(type);\n\n\tconst tenant = await tenantAdminComponent.get(tenantId);\n\tawait tenantAdminComponent.update({\n\t\t...tenant,\n\t\torganizationId: newOrganizationId\n\t});\n\n\tif (Is.stringValue(options?.sectionLabel)) {\n\t\tCLIDisplay.done();\n\t}\n}\n"]}
|