@twin.org/node-core 0.0.3-next.27 → 0.0.3-next.28

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 CHANGED
@@ -1,6 +1,8 @@
1
1
  # TWIN Node Core
2
2
 
3
- Core components for running TWIN nodes with dynamic extension loading and protocol-based module resolution.
3
+ This package provides the shared runtime foundation for hosting service workloads in a Node.js environment. It brings together reusable server capabilities, command tooling support, and integration patterns that help teams run API driven workloads with consistent behaviour.
4
+
5
+ By centralising this functionality, the package reduces duplication across applications and creates a stable base for extension as platform needs evolve. It is designed to support reliable day to day operation while keeping implementation concerns clear and maintainable.
4
6
 
5
7
  ## Installation
6
8
 
@@ -177,7 +177,8 @@ export async function bootstrapLegacy(engineCore, envVars, params) {
177
177
  password: envVars.adminUserPassword,
178
178
  scope: "tenant-admin",
179
179
  givenName: "Node",
180
- familyName: "Admin"
180
+ familyName: "Admin",
181
+ overwriteMode: "skip"
181
182
  });
182
183
  });
183
184
  }
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrapLegacy.js","sourceRoot":"","sources":["../../../src/commands/bootstrapLegacy.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAE3E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,gCAAgC,EAAE,MAAM,uCAAuC,CAAC;AACzF,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACj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,CACD,CAAC;gBACF,MAAM,gCAAgC,CAAC,UAAU,EAAE,OAAO,EAAE;oBAC3D,QAAQ,EAAE,YAAY,CAAC,GAAG;oBAC1B,sBAAsB,EAAE,iBAAiB;oBACzC,oBAAoB,EAAE,OAAO,CAAC,kCAAkC;oBAChE,aAAa,EAAE,MAAM;iBACrB,CAAC,CAAC;YACJ,CAAC;YAED,UAAU,CAAC,KAAK,EAAE,CAAC;YACnB,UAAU,CAAC,OAAO,CACjB,IAAI,CAAC,aAAa,CAAC,+DAA+D,CAAC,CACnF,CAAC;YACF,MAAM,iBAAiB,GAAG,MAAM,cAAc,CAAC,UAAU,EAAE,OAAO,EAAE;gBACnE,QAAQ,EAAE,OAAO,CAAC,iBAAiB;gBACnC,QAAQ,EAAE,OAAO,CAAC,iBAAiB;gBACnC,UAAU,EAAE,YAAY,CAAC,GAAG;aAC5B,CAAC,CAAC;YAEH,UAAU,CAAC,KAAK,EAAE,CAAC;YACnB,UAAU,CAAC,OAAO,CACjB,IAAI,CAAC,aAAa,CAAC,2DAA2D,CAAC,CAC/E,CAAC;YACF,MAAM,UAAU,CAAC,UAAU,EAAE,OAAO,EAAE;gBACrC,YAAY,EAAE,iBAAiB,CAAC,GAAG;gBACnC,oBAAoB,EAAE,YAAY,CAAC,GAAG;gBACtC,KAAK,EAAE,OAAO,CAAC,aAAa,IAAI,YAAY;gBAC5C,QAAQ,EAAE,OAAO,CAAC,iBAAiB;gBACnC,KAAK,EAAE,cAAc;gBACrB,SAAS,EAAE,MAAM;gBACjB,UAAU,EAAE,OAAO;aACnB,CAAC,CAAC;QACJ,CAAC,CACD,CAAC;IACH,CAAC;AACF,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport { Coerce, Converter, GeneralError, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { identityCreate } from \"./identityCreate.js\";\nimport { identityVerificationMethodCreate } from \"./identityVerificationMethodCreate.js\";\nimport { nodeSetIdentity } from \"./nodeSetIdentity.js\";\nimport { nodeSetTenant } from \"./nodeSetTenant.js\";\nimport { tenantCreate } from \"./tenantCreate.js\";\nimport { userCreate } from \"./userCreate.js\";\nimport { vaultKeyCreate } from \"./vaultKeyCreate.js\";\nimport { vaultKeyImport } from \"./vaultKeyImport.js\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"bootstrap-legacy\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionBootstrapLegacy(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.bootstrap-legacy.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.bootstrap-legacy.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresTenantId: 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.bootstrap-legacy.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.bootstrap-legacy.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) => bootstrapLegacy(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for legacy bootstrap.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n */\nexport async function bootstrapLegacy(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables & {\n\t\t/**\n\t\t * The features that are enabled on the node.\n\t\t * @default []\n\t\t */\n\t\tfeatures?: string;\n\n\t\t/**\n\t\t * The identity of the node which, if empty and node-identity feature is enabled it will be generated.\n\t\t */\n\t\tnodeIdentity?: string;\n\n\t\t/**\n\t\t * The mnemonic for the identity, if empty and node-identity feature is enabled it will be randomly generated.\n\t\t */\n\t\tnodeMnemonic?: string;\n\n\t\t/**\n\t\t * A tenant id to use as a default for the node.\n\t\t */\n\t\ttenantId?: string;\n\n\t\t/**\n\t\t * A tenant api key to use as a default for the node.\n\t\t */\n\t\ttenantApiKey?: string;\n\n\t\t/**\n\t\t * If the node-admin-user feature is enabled, this will be the organization of the user, if one is not provided it will be generated\n\t\t */\n\t\torganizationIdentity?: string;\n\n\t\t/**\n\t\t * The mnemonic for the organization, if empty and node-admin-user feature is enabled it will be randomly generated.\n\t\t */\n\t\torganizationMnemonic?: string;\n\n\t\t/**\n\t\t * If the node-admin-user feature is enabled, this will be the identity of the user, if one is not provided it will be generated\n\t\t */\n\t\tadminUserIdentity?: string;\n\n\t\t/**\n\t\t * The mnemonic for the admin user, if empty and node-admin-user feature is enabled it will be randomly generated.\n\t\t */\n\t\tadminUserMnemonic?: string;\n\n\t\t/**\n\t\t * If the node-admin-user feature is enabled, this will be the name of the user.\n\t\t * @default admin@node\n\t\t */\n\t\tadminUserName?: string;\n\n\t\t/**\n\t\t * If the node-admin-user feature is enabled, this will be the password of the user, if empty it will be randomly generated.\n\t\t */\n\t\tadminUserPassword?: string;\n\t},\n\tparams: {}\n): Promise<void> {\n\tconst features = (envVars.features ?? \"\")\n\t\t.split(\",\")\n\t\t.map(f => f.trim())\n\t\t.filter(f => f.length > 0);\n\n\tconst state = engineCore.getState();\n\tconst requireWallet = features.includes(\"node-wallet\");\n\tlet tenantId = state.nodeTenantId;\n\tlet nodeId = state.nodeId;\n\n\tif (features.length === 0) {\n\t\tthrow new GeneralError(\"bootstrapLegacy\", \"noFeaturesEnabled\");\n\t}\n\n\tif (features.includes(\"node-identity\") && Is.empty(nodeId)) {\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.section(\n\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.nodeIdentityCreate\")\n\t\t);\n\n\t\tconst nodeIdentity = await identityCreate(engineCore, envVars, {\n\t\t\tidentity: envVars.nodeIdentity,\n\t\t\tmnemonic: envVars.nodeMnemonic,\n\t\t\tfundWallet: requireWallet\n\t\t});\n\n\t\tnodeId = nodeIdentity.did;\n\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.section(\n\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.nodeAuthKeyCreate\")\n\t\t);\n\t\tawait vaultKeyCreate(engineCore, envVars, {\n\t\t\tidentity: nodeIdentity.did,\n\t\t\tkeyType: \"Ed25519\",\n\t\t\tkeyId: envVars.authSigningKeyId,\n\t\t\toverwriteMode: \"skip\"\n\t\t});\n\n\t\tif (Coerce.boolean(envVars.trustEnabled) ?? false) {\n\t\t\tCLIDisplay.break();\n\t\t\tCLIDisplay.section(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.bootstrap-legacy.labels.trustVerificationMethodCreate\"\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tawait identityVerificationMethodCreate(engineCore, envVars, {\n\t\t\t\tidentity: nodeIdentity.did,\n\t\t\t\tverificationMethodType: \"assertionMethod\",\n\t\t\t\tverificationMethodId: envVars.trustVerificationMethodId,\n\t\t\t\toverwriteMode: \"skip\"\n\t\t\t});\n\t\t}\n\n\t\tif (\n\t\t\t(Coerce.boolean(envVars.synchronisedStorageEnabled) ?? false) &&\n\t\t\tIs.stringBase64(envVars.synchronisedStorageBlobStorageKey)\n\t\t) {\n\t\t\tCLIDisplay.break();\n\t\t\tCLIDisplay.section(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.synchronisedStorageKeyAdd\")\n\t\t\t);\n\t\t\tawait vaultKeyImport(engineCore, envVars, {\n\t\t\t\tidentity: nodeIdentity.did,\n\t\t\t\tkeyType: \"ChaCha20Poly1305\",\n\t\t\t\tkeyId: envVars.synchronisedStorageBlobStorageEncryptionKeyId,\n\t\t\t\tprivateKeyHex: Converter.bytesToHex(\n\t\t\t\t\tConverter.base64ToBytes(envVars.synchronisedStorageBlobStorageKey)\n\t\t\t\t)\n\t\t\t});\n\t\t}\n\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.section(\n\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.nodeIdentitySet\")\n\t\t);\n\t\tawait nodeSetIdentity(engineCore, envVars, {\n\t\t\tidentity: nodeId\n\t\t});\n\n\t\tconst tenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;\n\t\tif (tenantEnabled && Is.empty(tenantId)) {\n\t\t\tawait ContextIdStore.run({ [ContextIdKeys.Node]: nodeId }, async () => {\n\t\t\t\tCLIDisplay.break();\n\t\t\t\tCLIDisplay.section(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.nodeTenantCreate\")\n\t\t\t\t);\n\t\t\t\tconst tenantDetails = await tenantCreate(engineCore, envVars, {\n\t\t\t\t\ttenantId: envVars.tenantId,\n\t\t\t\t\tapiKey: envVars.tenantApiKey,\n\t\t\t\t\tlabel: \"Node\"\n\t\t\t\t});\n\n\t\t\t\tCLIDisplay.break();\n\t\t\t\tCLIDisplay.section(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.nodeTenantSet\")\n\t\t\t\t);\n\t\t\t\tawait nodeSetTenant(engineCore, envVars, {\n\t\t\t\t\ttenantId: tenantDetails.tenantId\n\t\t\t\t});\n\n\t\t\t\ttenantId = tenantDetails.tenantId;\n\t\t\t});\n\t\t}\n\t}\n\n\tif (features.includes(\"node-admin-user\")) {\n\t\tawait ContextIdStore.run(\n\t\t\t{ [ContextIdKeys.Node]: nodeId, [ContextIdKeys.Tenant]: tenantId },\n\t\t\tasync () => {\n\t\t\t\tCLIDisplay.break();\n\t\t\t\tCLIDisplay.section(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.organisationCreate\")\n\t\t\t\t);\n\t\t\t\tconst organisation = await identityCreate(engineCore, envVars, {\n\t\t\t\t\tidentity: envVars.organizationIdentity,\n\t\t\t\t\tmnemonic: envVars.organizationMnemonic,\n\t\t\t\t\tfundWallet: requireWallet\n\t\t\t\t});\n\n\t\t\t\tif (Coerce.boolean(envVars.blobStorageEnableEncryption) ?? false) {\n\t\t\t\t\tCLIDisplay.break();\n\t\t\t\t\tCLIDisplay.section(\n\t\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.blobStorageKeyCreate\")\n\t\t\t\t\t);\n\t\t\t\t\tawait vaultKeyCreate(engineCore, envVars, {\n\t\t\t\t\t\tidentity: organisation.did,\n\t\t\t\t\t\tkeyType: \"ChaCha20Poly1305\",\n\t\t\t\t\t\tkeyId: envVars.blobStorageEncryptionKeyId,\n\t\t\t\t\t\toverwriteMode: \"skip\"\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst defaultAttestationConnectorType =\n\t\t\t\t\tengineCore.getRegisteredInstanceTypeOptional(\"attestationConnector\");\n\t\t\t\tif (!Is.empty(defaultAttestationConnectorType)) {\n\t\t\t\t\tCLIDisplay.break();\n\t\t\t\t\tCLIDisplay.section(\n\t\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.attestationMethodCreate\")\n\t\t\t\t\t);\n\t\t\t\t\tawait identityVerificationMethodCreate(engineCore, envVars, {\n\t\t\t\t\t\tidentity: organisation.did,\n\t\t\t\t\t\tverificationMethodType: \"assertionMethod\",\n\t\t\t\t\t\tverificationMethodId: envVars.attestationVerificationMethodId,\n\t\t\t\t\t\toverwriteMode: \"skip\"\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst defaultImmutableProofComponentType =\n\t\t\t\t\tengineCore.getRegisteredInstanceTypeOptional(\"immutableProofComponent\");\n\n\t\t\t\tif (!Is.empty(defaultImmutableProofComponentType)) {\n\t\t\t\t\tCLIDisplay.break();\n\t\t\t\t\tCLIDisplay.section(\n\t\t\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\t\t\"node.cli.commands.bootstrap-legacy.labels.immutableProofMethodCreate\"\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t\tawait identityVerificationMethodCreate(engineCore, envVars, {\n\t\t\t\t\t\tidentity: organisation.did,\n\t\t\t\t\t\tverificationMethodType: \"assertionMethod\",\n\t\t\t\t\t\tverificationMethodId: envVars.immutableProofVerificationMethodId,\n\t\t\t\t\t\toverwriteMode: \"skip\"\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tCLIDisplay.break();\n\t\t\t\tCLIDisplay.section(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.adminIdentityCreate\")\n\t\t\t\t);\n\t\t\t\tconst adminUserIdentity = await identityCreate(engineCore, envVars, {\n\t\t\t\t\tidentity: envVars.adminUserIdentity,\n\t\t\t\t\tmnemonic: envVars.adminUserMnemonic,\n\t\t\t\t\tcontroller: organisation.did\n\t\t\t\t});\n\n\t\t\t\tCLIDisplay.break();\n\t\t\t\tCLIDisplay.section(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.adminUserCreate\")\n\t\t\t\t);\n\t\t\t\tawait userCreate(engineCore, envVars, {\n\t\t\t\t\tuserIdentity: adminUserIdentity.did,\n\t\t\t\t\torganizationIdentity: organisation.did,\n\t\t\t\t\temail: envVars.adminUserName ?? \"admin@node\",\n\t\t\t\t\tpassword: envVars.adminUserPassword,\n\t\t\t\t\tscope: \"tenant-admin\",\n\t\t\t\t\tgivenName: \"Node\",\n\t\t\t\t\tfamilyName: \"Admin\"\n\t\t\t\t});\n\t\t\t}\n\t\t);\n\t}\n}\n"]}
1
+ {"version":3,"file":"bootstrapLegacy.js","sourceRoot":"","sources":["../../../src/commands/bootstrapLegacy.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAE3E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,gCAAgC,EAAE,MAAM,uCAAuC,CAAC;AACzF,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAMrD,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAExC;;;GAGG;AACH,MAAM,UAAU,mCAAmC,CAAC,kBAEnD;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,gDAAgD,CAAC;QACjF,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,4CAA4C,CAAC;QACzE,oBAAoB,EAAE,KAAK;QAC3B,gBAAgB,EAA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QAAQ,EAAE,OAAO,CAAC,iBAAiB;gBACnC,UAAU,EAAE,YAAY,CAAC,GAAG;aAC5B,CAAC,CAAC;YAEH,UAAU,CAAC,KAAK,EAAE,CAAC;YACnB,UAAU,CAAC,OAAO,CACjB,IAAI,CAAC,aAAa,CAAC,2DAA2D,CAAC,CAC/E,CAAC;YACF,MAAM,UAAU,CAAC,UAAU,EAAE,OAAO,EAAE;gBACrC,YAAY,EAAE,iBAAiB,CAAC,GAAG;gBACnC,oBAAoB,EAAE,YAAY,CAAC,GAAG;gBACtC,KAAK,EAAE,OAAO,CAAC,aAAa,IAAI,YAAY;gBAC5C,QAAQ,EAAE,OAAO,CAAC,iBAAiB;gBACnC,KAAK,EAAE,cAAc;gBACrB,SAAS,EAAE,MAAM;gBACjB,UAAU,EAAE,OAAO;gBACnB,aAAa,EAAE,MAAM;aACrB,CAAC,CAAC;QACJ,CAAC,CACD,CAAC;IACH,CAAC;AACF,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport { Coerce, Converter, GeneralError, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { identityCreate } from \"./identityCreate.js\";\nimport { identityVerificationMethodCreate } from \"./identityVerificationMethodCreate.js\";\nimport { nodeSetIdentity } from \"./nodeSetIdentity.js\";\nimport { nodeSetTenant } from \"./nodeSetTenant.js\";\nimport { tenantCreate } from \"./tenantCreate.js\";\nimport { userCreate } from \"./userCreate.js\";\nimport { vaultKeyCreate } from \"./vaultKeyCreate.js\";\nimport { vaultKeyImport } from \"./vaultKeyImport.js\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"bootstrap-legacy\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionBootstrapLegacy(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.bootstrap-legacy.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.bootstrap-legacy.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresTenantId: 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.bootstrap-legacy.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.bootstrap-legacy.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) => bootstrapLegacy(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for legacy bootstrap.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n */\nexport async function bootstrapLegacy(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables & {\n\t\t/**\n\t\t * The features that are enabled on the node.\n\t\t * @default []\n\t\t */\n\t\tfeatures?: string;\n\n\t\t/**\n\t\t * The identity of the node which, if empty and node-identity feature is enabled it will be generated.\n\t\t */\n\t\tnodeIdentity?: string;\n\n\t\t/**\n\t\t * The mnemonic for the identity, if empty and node-identity feature is enabled it will be randomly generated.\n\t\t */\n\t\tnodeMnemonic?: string;\n\n\t\t/**\n\t\t * A tenant id to use as a default for the node.\n\t\t */\n\t\ttenantId?: string;\n\n\t\t/**\n\t\t * A tenant api key to use as a default for the node.\n\t\t */\n\t\ttenantApiKey?: string;\n\n\t\t/**\n\t\t * If the node-admin-user feature is enabled, this will be the organization of the user, if one is not provided it will be generated\n\t\t */\n\t\torganizationIdentity?: string;\n\n\t\t/**\n\t\t * The mnemonic for the organization, if empty and node-admin-user feature is enabled it will be randomly generated.\n\t\t */\n\t\torganizationMnemonic?: string;\n\n\t\t/**\n\t\t * If the node-admin-user feature is enabled, this will be the identity of the user, if one is not provided it will be generated\n\t\t */\n\t\tadminUserIdentity?: string;\n\n\t\t/**\n\t\t * The mnemonic for the admin user, if empty and node-admin-user feature is enabled it will be randomly generated.\n\t\t */\n\t\tadminUserMnemonic?: string;\n\n\t\t/**\n\t\t * If the node-admin-user feature is enabled, this will be the name of the user.\n\t\t * @default admin@node\n\t\t */\n\t\tadminUserName?: string;\n\n\t\t/**\n\t\t * If the node-admin-user feature is enabled, this will be the password of the user, if empty it will be randomly generated.\n\t\t */\n\t\tadminUserPassword?: string;\n\t},\n\tparams: {}\n): Promise<void> {\n\tconst features = (envVars.features ?? \"\")\n\t\t.split(\",\")\n\t\t.map(f => f.trim())\n\t\t.filter(f => f.length > 0);\n\n\tconst state = engineCore.getState();\n\tconst requireWallet = features.includes(\"node-wallet\");\n\tlet tenantId = state.nodeTenantId;\n\tlet nodeId = state.nodeId;\n\n\tif (features.length === 0) {\n\t\tthrow new GeneralError(\"bootstrapLegacy\", \"noFeaturesEnabled\");\n\t}\n\n\tif (features.includes(\"node-identity\") && Is.empty(nodeId)) {\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.section(\n\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.nodeIdentityCreate\")\n\t\t);\n\n\t\tconst nodeIdentity = await identityCreate(engineCore, envVars, {\n\t\t\tidentity: envVars.nodeIdentity,\n\t\t\tmnemonic: envVars.nodeMnemonic,\n\t\t\tfundWallet: requireWallet\n\t\t});\n\n\t\tnodeId = nodeIdentity.did;\n\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.section(\n\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.nodeAuthKeyCreate\")\n\t\t);\n\t\tawait vaultKeyCreate(engineCore, envVars, {\n\t\t\tidentity: nodeIdentity.did,\n\t\t\tkeyType: \"Ed25519\",\n\t\t\tkeyId: envVars.authSigningKeyId,\n\t\t\toverwriteMode: \"skip\"\n\t\t});\n\n\t\tif (Coerce.boolean(envVars.trustEnabled) ?? false) {\n\t\t\tCLIDisplay.break();\n\t\t\tCLIDisplay.section(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.bootstrap-legacy.labels.trustVerificationMethodCreate\"\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tawait identityVerificationMethodCreate(engineCore, envVars, {\n\t\t\t\tidentity: nodeIdentity.did,\n\t\t\t\tverificationMethodType: \"assertionMethod\",\n\t\t\t\tverificationMethodId: envVars.trustVerificationMethodId,\n\t\t\t\toverwriteMode: \"skip\"\n\t\t\t});\n\t\t}\n\n\t\tif (\n\t\t\t(Coerce.boolean(envVars.synchronisedStorageEnabled) ?? false) &&\n\t\t\tIs.stringBase64(envVars.synchronisedStorageBlobStorageKey)\n\t\t) {\n\t\t\tCLIDisplay.break();\n\t\t\tCLIDisplay.section(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.synchronisedStorageKeyAdd\")\n\t\t\t);\n\t\t\tawait vaultKeyImport(engineCore, envVars, {\n\t\t\t\tidentity: nodeIdentity.did,\n\t\t\t\tkeyType: \"ChaCha20Poly1305\",\n\t\t\t\tkeyId: envVars.synchronisedStorageBlobStorageEncryptionKeyId,\n\t\t\t\tprivateKeyHex: Converter.bytesToHex(\n\t\t\t\t\tConverter.base64ToBytes(envVars.synchronisedStorageBlobStorageKey)\n\t\t\t\t)\n\t\t\t});\n\t\t}\n\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.section(\n\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.nodeIdentitySet\")\n\t\t);\n\t\tawait nodeSetIdentity(engineCore, envVars, {\n\t\t\tidentity: nodeId\n\t\t});\n\n\t\tconst tenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;\n\t\tif (tenantEnabled && Is.empty(tenantId)) {\n\t\t\tawait ContextIdStore.run({ [ContextIdKeys.Node]: nodeId }, async () => {\n\t\t\t\tCLIDisplay.break();\n\t\t\t\tCLIDisplay.section(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.nodeTenantCreate\")\n\t\t\t\t);\n\t\t\t\tconst tenantDetails = await tenantCreate(engineCore, envVars, {\n\t\t\t\t\ttenantId: envVars.tenantId,\n\t\t\t\t\tapiKey: envVars.tenantApiKey,\n\t\t\t\t\tlabel: \"Node\"\n\t\t\t\t});\n\n\t\t\t\tCLIDisplay.break();\n\t\t\t\tCLIDisplay.section(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.nodeTenantSet\")\n\t\t\t\t);\n\t\t\t\tawait nodeSetTenant(engineCore, envVars, {\n\t\t\t\t\ttenantId: tenantDetails.tenantId\n\t\t\t\t});\n\n\t\t\t\ttenantId = tenantDetails.tenantId;\n\t\t\t});\n\t\t}\n\t}\n\n\tif (features.includes(\"node-admin-user\")) {\n\t\tawait ContextIdStore.run(\n\t\t\t{ [ContextIdKeys.Node]: nodeId, [ContextIdKeys.Tenant]: tenantId },\n\t\t\tasync () => {\n\t\t\t\tCLIDisplay.break();\n\t\t\t\tCLIDisplay.section(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.organisationCreate\")\n\t\t\t\t);\n\t\t\t\tconst organisation = await identityCreate(engineCore, envVars, {\n\t\t\t\t\tidentity: envVars.organizationIdentity,\n\t\t\t\t\tmnemonic: envVars.organizationMnemonic,\n\t\t\t\t\tfundWallet: requireWallet\n\t\t\t\t});\n\n\t\t\t\tif (Coerce.boolean(envVars.blobStorageEnableEncryption) ?? false) {\n\t\t\t\t\tCLIDisplay.break();\n\t\t\t\t\tCLIDisplay.section(\n\t\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.blobStorageKeyCreate\")\n\t\t\t\t\t);\n\t\t\t\t\tawait vaultKeyCreate(engineCore, envVars, {\n\t\t\t\t\t\tidentity: organisation.did,\n\t\t\t\t\t\tkeyType: \"ChaCha20Poly1305\",\n\t\t\t\t\t\tkeyId: envVars.blobStorageEncryptionKeyId,\n\t\t\t\t\t\toverwriteMode: \"skip\"\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst defaultAttestationConnectorType =\n\t\t\t\t\tengineCore.getRegisteredInstanceTypeOptional(\"attestationConnector\");\n\t\t\t\tif (!Is.empty(defaultAttestationConnectorType)) {\n\t\t\t\t\tCLIDisplay.break();\n\t\t\t\t\tCLIDisplay.section(\n\t\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.attestationMethodCreate\")\n\t\t\t\t\t);\n\t\t\t\t\tawait identityVerificationMethodCreate(engineCore, envVars, {\n\t\t\t\t\t\tidentity: organisation.did,\n\t\t\t\t\t\tverificationMethodType: \"assertionMethod\",\n\t\t\t\t\t\tverificationMethodId: envVars.attestationVerificationMethodId,\n\t\t\t\t\t\toverwriteMode: \"skip\"\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst defaultImmutableProofComponentType =\n\t\t\t\t\tengineCore.getRegisteredInstanceTypeOptional(\"immutableProofComponent\");\n\n\t\t\t\tif (!Is.empty(defaultImmutableProofComponentType)) {\n\t\t\t\t\tCLIDisplay.break();\n\t\t\t\t\tCLIDisplay.section(\n\t\t\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\t\t\"node.cli.commands.bootstrap-legacy.labels.immutableProofMethodCreate\"\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t\tawait identityVerificationMethodCreate(engineCore, envVars, {\n\t\t\t\t\t\tidentity: organisation.did,\n\t\t\t\t\t\tverificationMethodType: \"assertionMethod\",\n\t\t\t\t\t\tverificationMethodId: envVars.immutableProofVerificationMethodId,\n\t\t\t\t\t\toverwriteMode: \"skip\"\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tCLIDisplay.break();\n\t\t\t\tCLIDisplay.section(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.adminIdentityCreate\")\n\t\t\t\t);\n\t\t\t\tconst adminUserIdentity = await identityCreate(engineCore, envVars, {\n\t\t\t\t\tidentity: envVars.adminUserIdentity,\n\t\t\t\t\tmnemonic: envVars.adminUserMnemonic,\n\t\t\t\t\tcontroller: organisation.did\n\t\t\t\t});\n\n\t\t\t\tCLIDisplay.break();\n\t\t\t\tCLIDisplay.section(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.adminUserCreate\")\n\t\t\t\t);\n\t\t\t\tawait userCreate(engineCore, envVars, {\n\t\t\t\t\tuserIdentity: adminUserIdentity.did,\n\t\t\t\t\torganizationIdentity: organisation.did,\n\t\t\t\t\temail: envVars.adminUserName ?? \"admin@node\",\n\t\t\t\t\tpassword: envVars.adminUserPassword,\n\t\t\t\t\tscope: \"tenant-admin\",\n\t\t\t\t\tgivenName: \"Node\",\n\t\t\t\t\tfamilyName: \"Admin\",\n\t\t\t\t\toverwriteMode: \"skip\"\n\t\t\t\t});\n\t\t\t}\n\t\t);\n\t}\n}\n"]}
@@ -126,7 +126,7 @@ export async function identityVerificationMethodCreate(engineCore, envVars, para
126
126
  CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-verification-method-create.labels.resolvingIdentity"));
127
127
  const identityDoc = await identityResolverComponent.identityResolve(params.identity);
128
128
  try {
129
- verificationMethod = DocumentHelper.getVerificationMethod(identityDoc, DocumentHelper.joinId(params.identity, params.verificationMethodId));
129
+ verificationMethod = DocumentHelper.getVerificationMethod(identityDoc, DocumentHelper.joinId(params.identity, params.verificationMethodId), params.verificationMethodType);
130
130
  }
131
131
  catch { }
132
132
  if (!Is.empty(verificationMethod)) {
@@ -1 +1 @@
1
- {"version":3,"file":"identityVerificationMethodCreate.js","sourceRoot":"","sources":["../../../src/commands/identityVerificationMethodCreate.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAE7F,OAAO,EACN,GAAG,EACH,cAAc,EACd,wBAAwB,EAExB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAa,GAAG,EAAE,MAAM,eAAe,CAAC;AAM/C,MAAM,YAAY,GAAG,qCAAqC,CAAC;AAE3D;;;GAGG;AACH,MAAM,UAAU,oDAAoD,CAAC,kBAEpE;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,mEAAmE,CACnE;QACD,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,+DAA+D,CAAC;QAC5F,oBAAoB,EAAE,KAAK;QAC3B,gBAAgB,EAAE,KAAK;QACvB,MAAM,EAAE;YACP;gBACC,GAAG,EAAE,YAAY;gBACjB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,qFAAqF,CACrF;gBACD,QAAQ,EAAE,KAAK;aACf;YACD;gBACC,GAAG,EAAE,UAAU;gBACf,IAAI,EAAE,Q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AC,YAAY,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QAC9D,CAAC;IACF,CAAC;IAED,UAAU,CAAC,IAAI,EAAE,CAAC;IAElB,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay, CLIUtils } from \"@twin.org/cli-core\";\nimport { ComponentFactory, Converter, GeneralError, Guards, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport {\n\tDid,\n\tDocumentHelper,\n\tIdentityConnectorFactory,\n\ttype IIdentityResolverComponent\n} from \"@twin.org/identity-models\";\nimport { DidVerificationMethodType } from \"@twin.org/standards-w3c-did\";\nimport { VaultConnectorFactory } from \"@twin.org/vault-models\";\nimport { type IJwk, Jwk } from \"@twin.org/web\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"identity-verification-method-create\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionIdentityVerificationMethodCreate(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\n\t\t\t\"node.cli.commands.identity-verification-method-create.description\"\n\t\t),\n\t\texample: I18n.formatMessage(\"node.cli.commands.identity-verification-method-create.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresTenantId: 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.identity-verification-method-create.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: \"identity\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.identity.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"did\"\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"controller\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.controller.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"did\",\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"verification-method-type\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.verification-method-type.description\"\n\t\t\t\t),\n\t\t\t\toptions: Object.values(DidVerificationMethodType),\n\t\t\t\trequired: false,\n\t\t\t\tdefaultValue: \"assertionMethod\"\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"verification-method-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.verification-method-id.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: \"overwrite-mode\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.overwrite-mode.description\"\n\t\t\t\t),\n\t\t\t\toptions: [\"skip\", \"overwrite\", \"error\"],\n\t\t\t\tdefaultValue: \"skip\",\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.identity-verification-method-create.params.load-env.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: \"output-json\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.output-json.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: \"output-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.output-env.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: \"output-env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.output-env-prefix.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) =>\n\t\t\tidentityVerificationMethodCreate(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for creating an identity verification method.\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.identity The DID of the identity to create.\n * @param params.verificationMethodType The type of verification method to create.\n * @param params.verificationMethodId The ID of the verification method to create.\n * @param params.controller The controller DID for the identity.\n * @param params.overwriteMode The mode to use when a verification method with the same ID already exists.\n * @param params.outputJson The output .json file to store the command output.\n * @param params.outputEnv The output .env file to store the command output.\n * @param params.outputEnvPrefix The prefix to use for variables in the output .env file.\n * @returns The created verification method details or undefined if skipped.\n */\nexport async function identityVerificationMethodCreate(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tidentity?: string;\n\t\tverificationMethodType?: DidVerificationMethodType;\n\t\tverificationMethodId?: string;\n\t\tcontroller?: string;\n\t\toverwriteMode?: \"skip\" | \"overwrite\" | \"error\";\n\t\toutputJson?: string;\n\t\toutputEnv?: string;\n\t\toutputEnvPrefix?: string;\n\t}\n): Promise<\n\t| {\n\t\t\tverificationMethodId: string;\n\t\t\tverificationMethodType: string;\n\t\t\tprivateKeyJwk: IJwk;\n\t\t\tprivateKeyHex: string;\n\t\t\tpublicKeyHex: string;\n\t\t\tprivateKeyBase64: string;\n\t\t\tpublicKeyBase64: string;\n\t }\n\t| undefined\n> {\n\tDid.guard(\"identityVerificationMethodCreate\", \"identity\", params.identity);\n\tGuards.arrayOneOf(\n\t\t\"identityVerificationMethodCreate\",\n\t\t\"verificationMethodType\",\n\t\tparams.verificationMethodType,\n\t\tObject.values(DidVerificationMethodType)\n\t);\n\tGuards.arrayOneOf(\"identityVerificationMethodCreate\", \"overwrite-mode\", params.overwriteMode, [\n\t\t\"skip\",\n\t\t\"overwrite\",\n\t\t\"error\"\n\t]);\n\n\tconst defaultIdentityConnectorType = engineCore.getRegisteredInstanceType(\"identityConnector\");\n\tconst identityConnector = IdentityConnectorFactory.get(defaultIdentityConnectorType);\n\n\tconst defaultIdentityResolverComponentType = engineCore.getRegisteredInstanceType(\n\t\t\"identityResolverComponent\"\n\t);\n\tconst identityResolverComponent = ComponentFactory.get<IIdentityResolverComponent>(\n\t\tdefaultIdentityResolverComponentType\n\t);\n\n\tconst defaultVaultConnectorType = engineCore.getRegisteredInstanceType(\"vaultConnector\");\n\tconst vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);\n\n\tlet createMethod = true;\n\tlet verificationMethod;\n\n\t// We only need to perform the overwrite check if a verification method ID was provided\n\t// otherwise a new ID will be generated\n\tif (Is.stringValue(params.verificationMethodId)) {\n\t\tif (params.overwriteMode === \"skip\" || params.overwriteMode === \"error\") {\n\t\t\tCLIDisplay.task(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.resolvingIdentity\"\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tconst identityDoc = await identityResolverComponent.identityResolve(params.identity);\n\t\t\ttry {\n\t\t\t\tverificationMethod = DocumentHelper.getVerificationMethod(\n\t\t\t\t\tidentityDoc,\n\t\t\t\t\tDocumentHelper.joinId(params.identity, params.verificationMethodId)\n\t\t\t\t);\n\t\t\t} catch {}\n\n\t\t\tif (!Is.empty(verificationMethod)) {\n\t\t\t\tif (params.overwriteMode === \"error\") {\n\t\t\t\t\tthrow new GeneralError(\n\t\t\t\t\t\t\"identityVerificationMethodCreate\",\n\t\t\t\t\t\t\"verificationMethodAlreadyExists\"\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcreateMethod = false;\n\t\t\t\tCLIDisplay.task(\n\t\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.skipping\"\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (createMethod) {\n\t\tCLIDisplay.task(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.creatingVerificationMethod\"\n\t\t\t)\n\t\t);\n\t\tCLIDisplay.spinnerStart();\n\n\t\tverificationMethod = await identityConnector.addVerificationMethod(\n\t\t\tparams.controller ?? params.identity,\n\t\t\tparams.identity,\n\t\t\tparams.verificationMethodType as DidVerificationMethodType,\n\t\t\tparams.verificationMethodId\n\t\t);\n\n\t\tCLIDisplay.spinnerStop();\n\t\tCLIDisplay.task(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.createdVerificationMethod\"\n\t\t\t)\n\t\t);\n\t}\n\n\tlet json;\n\n\tif (!Is.empty(verificationMethod)) {\n\t\tconst keyParts = DocumentHelper.parseId(verificationMethod.id);\n\n\t\tconst keyPair = await vaultConnector.getKey(`${params.identity}/${keyParts.fragment}`);\n\t\tconst privateKeyBase64Url = Converter.bytesToBase64Url(keyPair.privateKey);\n\t\tconst publicKeyBase64Url = Is.uint8Array(keyPair.publicKey)\n\t\t\t? Converter.bytesToBase64Url(keyPair.publicKey)\n\t\t\t: \"\";\n\t\tconst privateKeyBase64 = Converter.bytesToBase64(keyPair.privateKey);\n\t\tconst publicKeyBase64 = Is.uint8Array(keyPair.publicKey)\n\t\t\t? Converter.bytesToBase64(keyPair.publicKey)\n\t\t\t: \"\";\n\n\t\tconst privateKeyHex = Converter.bytesToHex(keyPair.privateKey, true);\n\t\tconst publicKeyHex = Is.uint8Array(keyPair.publicKey)\n\t\t\t? Converter.bytesToHex(keyPair.publicKey, true)\n\t\t\t: \"\";\n\n\t\tconst jwk = await Jwk.fromEd25519Private(keyPair.privateKey);\n\t\tconst kid = await Jwk.generateKid(jwk);\n\n\t\tCLIDisplay.break();\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.verificationMethodId\"\n\t\t\t),\n\t\t\tverificationMethod.id\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.verificationMethodType\"\n\t\t\t),\n\t\t\tverificationMethod.type\n\t\t);\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.identity-verification-method-create.labels.kid\"),\n\t\t\tkid\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.privateKeyBase64Url\"\n\t\t\t),\n\t\t\tprivateKeyBase64Url\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.publicKeyBase64Url\"\n\t\t\t),\n\t\t\tpublicKeyBase64Url\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.privateKeyBase64\"\n\t\t\t),\n\t\t\tprivateKeyBase64\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.publicKeyBase64\"\n\t\t\t),\n\t\t\tpublicKeyBase64\n\t\t);\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.privateKeyHex\"\n\t\t\t),\n\t\t\tprivateKeyHex\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.publicKeyHex\"\n\t\t\t),\n\t\t\tpublicKeyHex\n\t\t);\n\n\t\tCLIDisplay.break();\n\n\t\tjson = {\n\t\t\tverificationMethodId: verificationMethod.id,\n\t\t\tverificationMethodType: verificationMethod.type,\n\t\t\tprivateKeyJwk: {\n\t\t\t\tkid,\n\t\t\t\t...jwk\n\t\t\t},\n\t\t\tprivateKeyHex,\n\t\t\tpublicKeyHex,\n\t\t\tprivateKeyBase64,\n\t\t\tpublicKeyBase64\n\t\t};\n\n\t\tif (Is.stringValue(params.outputJson)) {\n\t\t\tawait CLIUtils.writeJsonFile(params.outputJson, json, false);\n\t\t}\n\n\t\tif (Is.stringValue(params.outputEnv)) {\n\t\t\tconst output = [\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_ID=\"${verificationMethod.id}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_TYPE=\"${verificationMethod.type}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_KID=\"${kid}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_KTY=\"${jwk.kty}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_USE=\"${jwk.use}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_ALG=\"${jwk.alg}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_CRV=\"${jwk.crv}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_X=\"${jwk.x}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_D=\"${jwk.d}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PRIVATE_KEY_HEX=\"${privateKeyHex}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PUBLIC_KEY_HEX=\"${publicKeyHex}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PRIVATE_KEY_BASE64=\"${privateKeyBase64}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PUBLIC_KEY_BASE64=\"${publicKeyBase64}\"`\n\t\t\t];\n\t\t\tawait CLIUtils.writeEnvFile(params.outputEnv, output, false);\n\t\t}\n\t}\n\n\tCLIDisplay.done();\n\n\treturn json;\n}\n"]}
1
+ {"version":3,"file":"identityVerificationMethodCreate.js","sourceRoot":"","sources":["../../../src/commands/identityVerificationMethodCreate.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAE7F,OAAO,EACN,GAAG,EACH,cAAc,EACd,wBAAwB,EAExB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAa,GAAG,EAAE,MAAM,eAAe,CAAC;AAM/C,MAAM,YAAY,GAAG,qCAAqC,CAAC;A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AAG,CAAC,GAAG,GAAG;gBACvE,GAAG,MAAM,CAAC,eAAe,oCAAoC,GAAG,CAAC,GAAG,GAAG;gBACvE,GAAG,MAAM,CAAC,eAAe,oCAAoC,GAAG,CAAC,GAAG,GAAG;gBACvE,GAAG,MAAM,CAAC,eAAe,kCAAkC,GAAG,CAAC,CAAC,GAAG;gBACnE,GAAG,MAAM,CAAC,eAAe,kCAAkC,GAAG,CAAC,CAAC,GAAG;gBACnE,GAAG,MAAM,CAAC,eAAe,4CAA4C,aAAa,GAAG;gBACrF,GAAG,MAAM,CAAC,eAAe,2CAA2C,YAAY,GAAG;gBACnF,GAAG,MAAM,CAAC,eAAe,+CAA+C,gBAAgB,GAAG;gBAC3F,GAAG,MAAM,CAAC,eAAe,8CAA8C,eAAe,GAAG;aACzF,CAAC;YACF,MAAM,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QAC9D,CAAC;IACF,CAAC;IAED,UAAU,CAAC,IAAI,EAAE,CAAC;IAElB,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay, CLIUtils } from \"@twin.org/cli-core\";\nimport { ComponentFactory, Converter, GeneralError, Guards, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport {\n\tDid,\n\tDocumentHelper,\n\tIdentityConnectorFactory,\n\ttype IIdentityResolverComponent\n} from \"@twin.org/identity-models\";\nimport { DidVerificationMethodType } from \"@twin.org/standards-w3c-did\";\nimport { VaultConnectorFactory } from \"@twin.org/vault-models\";\nimport { type IJwk, Jwk } from \"@twin.org/web\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"identity-verification-method-create\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionIdentityVerificationMethodCreate(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\n\t\t\t\"node.cli.commands.identity-verification-method-create.description\"\n\t\t),\n\t\texample: I18n.formatMessage(\"node.cli.commands.identity-verification-method-create.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresTenantId: 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.identity-verification-method-create.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: \"identity\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.identity.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"did\"\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"controller\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.controller.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"did\",\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"verification-method-type\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.verification-method-type.description\"\n\t\t\t\t),\n\t\t\t\toptions: Object.values(DidVerificationMethodType),\n\t\t\t\trequired: false,\n\t\t\t\tdefaultValue: \"assertionMethod\"\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"verification-method-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.verification-method-id.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: \"overwrite-mode\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.overwrite-mode.description\"\n\t\t\t\t),\n\t\t\t\toptions: [\"skip\", \"overwrite\", \"error\"],\n\t\t\t\tdefaultValue: \"skip\",\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.identity-verification-method-create.params.load-env.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: \"output-json\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.output-json.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: \"output-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.output-env.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: \"output-env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.output-env-prefix.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) =>\n\t\t\tidentityVerificationMethodCreate(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for creating an identity verification method.\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.identity The DID of the identity to create.\n * @param params.verificationMethodType The type of verification method to create.\n * @param params.verificationMethodId The ID of the verification method to create.\n * @param params.controller The controller DID for the identity.\n * @param params.overwriteMode The mode to use when a verification method with the same ID already exists.\n * @param params.outputJson The output .json file to store the command output.\n * @param params.outputEnv The output .env file to store the command output.\n * @param params.outputEnvPrefix The prefix to use for variables in the output .env file.\n * @returns The created verification method details or undefined if skipped.\n */\nexport async function identityVerificationMethodCreate(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tidentity?: string;\n\t\tverificationMethodType?: DidVerificationMethodType;\n\t\tverificationMethodId?: string;\n\t\tcontroller?: string;\n\t\toverwriteMode?: \"skip\" | \"overwrite\" | \"error\";\n\t\toutputJson?: string;\n\t\toutputEnv?: string;\n\t\toutputEnvPrefix?: string;\n\t}\n): Promise<\n\t| {\n\t\t\tverificationMethodId: string;\n\t\t\tverificationMethodType: string;\n\t\t\tprivateKeyJwk: IJwk;\n\t\t\tprivateKeyHex: string;\n\t\t\tpublicKeyHex: string;\n\t\t\tprivateKeyBase64: string;\n\t\t\tpublicKeyBase64: string;\n\t }\n\t| undefined\n> {\n\tDid.guard(\"identityVerificationMethodCreate\", \"identity\", params.identity);\n\tGuards.arrayOneOf(\n\t\t\"identityVerificationMethodCreate\",\n\t\t\"verificationMethodType\",\n\t\tparams.verificationMethodType,\n\t\tObject.values(DidVerificationMethodType)\n\t);\n\tGuards.arrayOneOf(\"identityVerificationMethodCreate\", \"overwrite-mode\", params.overwriteMode, [\n\t\t\"skip\",\n\t\t\"overwrite\",\n\t\t\"error\"\n\t]);\n\n\tconst defaultIdentityConnectorType = engineCore.getRegisteredInstanceType(\"identityConnector\");\n\tconst identityConnector = IdentityConnectorFactory.get(defaultIdentityConnectorType);\n\n\tconst defaultIdentityResolverComponentType = engineCore.getRegisteredInstanceType(\n\t\t\"identityResolverComponent\"\n\t);\n\tconst identityResolverComponent = ComponentFactory.get<IIdentityResolverComponent>(\n\t\tdefaultIdentityResolverComponentType\n\t);\n\n\tconst defaultVaultConnectorType = engineCore.getRegisteredInstanceType(\"vaultConnector\");\n\tconst vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);\n\n\tlet createMethod = true;\n\tlet verificationMethod;\n\n\t// We only need to perform the overwrite check if a verification method ID was provided\n\t// otherwise a new ID will be generated\n\tif (Is.stringValue(params.verificationMethodId)) {\n\t\tif (params.overwriteMode === \"skip\" || params.overwriteMode === \"error\") {\n\t\t\tCLIDisplay.task(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.resolvingIdentity\"\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tconst identityDoc = await identityResolverComponent.identityResolve(params.identity);\n\t\t\ttry {\n\t\t\t\tverificationMethod = DocumentHelper.getVerificationMethod(\n\t\t\t\t\tidentityDoc,\n\t\t\t\t\tDocumentHelper.joinId(params.identity, params.verificationMethodId),\n\t\t\t\t\tparams.verificationMethodType\n\t\t\t\t);\n\t\t\t} catch {}\n\n\t\t\tif (!Is.empty(verificationMethod)) {\n\t\t\t\tif (params.overwriteMode === \"error\") {\n\t\t\t\t\tthrow new GeneralError(\n\t\t\t\t\t\t\"identityVerificationMethodCreate\",\n\t\t\t\t\t\t\"verificationMethodAlreadyExists\"\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcreateMethod = false;\n\t\t\t\tCLIDisplay.task(\n\t\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.skipping\"\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (createMethod) {\n\t\tCLIDisplay.task(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.creatingVerificationMethod\"\n\t\t\t)\n\t\t);\n\t\tCLIDisplay.spinnerStart();\n\n\t\tverificationMethod = await identityConnector.addVerificationMethod(\n\t\t\tparams.controller ?? params.identity,\n\t\t\tparams.identity,\n\t\t\tparams.verificationMethodType as DidVerificationMethodType,\n\t\t\tparams.verificationMethodId\n\t\t);\n\n\t\tCLIDisplay.spinnerStop();\n\t\tCLIDisplay.task(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.createdVerificationMethod\"\n\t\t\t)\n\t\t);\n\t}\n\n\tlet json;\n\n\tif (!Is.empty(verificationMethod)) {\n\t\tconst keyParts = DocumentHelper.parseId(verificationMethod.id);\n\n\t\tconst keyPair = await vaultConnector.getKey(`${params.identity}/${keyParts.fragment}`);\n\t\tconst privateKeyBase64Url = Converter.bytesToBase64Url(keyPair.privateKey);\n\t\tconst publicKeyBase64Url = Is.uint8Array(keyPair.publicKey)\n\t\t\t? Converter.bytesToBase64Url(keyPair.publicKey)\n\t\t\t: \"\";\n\t\tconst privateKeyBase64 = Converter.bytesToBase64(keyPair.privateKey);\n\t\tconst publicKeyBase64 = Is.uint8Array(keyPair.publicKey)\n\t\t\t? Converter.bytesToBase64(keyPair.publicKey)\n\t\t\t: \"\";\n\n\t\tconst privateKeyHex = Converter.bytesToHex(keyPair.privateKey, true);\n\t\tconst publicKeyHex = Is.uint8Array(keyPair.publicKey)\n\t\t\t? Converter.bytesToHex(keyPair.publicKey, true)\n\t\t\t: \"\";\n\n\t\tconst jwk = await Jwk.fromEd25519Private(keyPair.privateKey);\n\t\tconst kid = await Jwk.generateKid(jwk);\n\n\t\tCLIDisplay.break();\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.verificationMethodId\"\n\t\t\t),\n\t\t\tverificationMethod.id\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.verificationMethodType\"\n\t\t\t),\n\t\t\tverificationMethod.type\n\t\t);\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.identity-verification-method-create.labels.kid\"),\n\t\t\tkid\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.privateKeyBase64Url\"\n\t\t\t),\n\t\t\tprivateKeyBase64Url\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.publicKeyBase64Url\"\n\t\t\t),\n\t\t\tpublicKeyBase64Url\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.privateKeyBase64\"\n\t\t\t),\n\t\t\tprivateKeyBase64\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.publicKeyBase64\"\n\t\t\t),\n\t\t\tpublicKeyBase64\n\t\t);\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.privateKeyHex\"\n\t\t\t),\n\t\t\tprivateKeyHex\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.publicKeyHex\"\n\t\t\t),\n\t\t\tpublicKeyHex\n\t\t);\n\n\t\tCLIDisplay.break();\n\n\t\tjson = {\n\t\t\tverificationMethodId: verificationMethod.id,\n\t\t\tverificationMethodType: verificationMethod.type,\n\t\t\tprivateKeyJwk: {\n\t\t\t\tkid,\n\t\t\t\t...jwk\n\t\t\t},\n\t\t\tprivateKeyHex,\n\t\t\tpublicKeyHex,\n\t\t\tprivateKeyBase64,\n\t\t\tpublicKeyBase64\n\t\t};\n\n\t\tif (Is.stringValue(params.outputJson)) {\n\t\t\tawait CLIUtils.writeJsonFile(params.outputJson, json, false);\n\t\t}\n\n\t\tif (Is.stringValue(params.outputEnv)) {\n\t\t\tconst output = [\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_ID=\"${verificationMethod.id}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_TYPE=\"${verificationMethod.type}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_KID=\"${kid}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_KTY=\"${jwk.kty}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_USE=\"${jwk.use}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_ALG=\"${jwk.alg}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_CRV=\"${jwk.crv}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_X=\"${jwk.x}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_D=\"${jwk.d}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PRIVATE_KEY_HEX=\"${privateKeyHex}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PUBLIC_KEY_HEX=\"${publicKeyHex}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PRIVATE_KEY_BASE64=\"${privateKeyBase64}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PUBLIC_KEY_BASE64=\"${publicKeyBase64}\"`\n\t\t\t];\n\t\t\tawait CLIUtils.writeEnvFile(params.outputEnv, output, false);\n\t\t}\n\t}\n\n\tCLIDisplay.done();\n\n\treturn json;\n}\n"]}
package/dist/es/node.js CHANGED
@@ -28,7 +28,7 @@ export async function run(nodeOptions, args) {
28
28
  nodeOptions ??= {};
29
29
  const serverInfo = {
30
30
  name: nodeOptions?.serverName ?? "TWIN Node",
31
- version: nodeOptions?.serverVersion ?? "0.0.3-next.27" // x-release-please-version
31
+ version: nodeOptions?.serverVersion ?? "0.0.3-next.28" // x-release-please-version
32
32
  };
33
33
  CLIDisplay.header(serverInfo.name, serverInfo.version, "🌩️ ");
34
34
  if (!Is.stringValue(nodeOptions?.executionDirectory)) {
@@ -1 +1 @@
1
- {"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/node.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAI9F,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AACtF,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACvF,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAK/C,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EACN,qBAAqB,EACrB,UAAU,EACV,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,m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AAY,GAAG,IAAI,CAAC,OAAO,CAChC,qBAAqB,CAAC,kBAAkB,EAAE,cAAc,CAAC,GAAG,EAAE,cAAc,CAAC,EAC7E,cAAc,CACd,CAAC;oBAEF,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;oBAC3D,MAAM,QAAQ,GAAG,MAAM,wBAAwB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;oBACzE,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;oBACvD,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,UAAU,CAAC,CAAC;oBAC5C,IAAI,MAAM,EAAE,CAAC;wBACZ,YAAY,GAAG,UAAU,CAAC;oBAC3B,CAAC;gBACF,CAAC;gBAAC,MAAM,CAAC;oBACR,4CAA4C;gBAC7C,CAAC;gBACD,MAAM;YACP,CAAC;QACF,CAAC;QAED,0CAA0C;QAC1C,IAAI,YAAY,EAAE,CAAC;YAClB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC,CAAC;YACjE,WAAW,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC;YACjC,OAAO;gBACN,MAAM;gBACN,UAAU,EAAE,KAAK;aACjB,CAAC;QACH,CAAC;QAED,OAAO;YACN,MAAM,EAAE,SAAS;YACjB,UAAU,EAAE,IAAI;SAChB,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,cAAc;IACtB,YAAY,KAAK,QAAQ,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC5E,OAAO,YAAY,CAAC;AACrB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { execSync } from \"node:child_process\";\nimport path from \"node:path\";\nimport type { IServerInfo } from \"@twin.org/api-models\";\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { BaseError, Coerce, EnvHelper, GeneralError, Is, ObjectHelper } from \"@twin.org/core\";\nimport type { Engine } from \"@twin.org/engine\";\nimport type { EngineServer } from \"@twin.org/engine-server\";\nimport type { IEngineServerConfig } from \"@twin.org/engine-server-types\";\nimport { ModuleHelper } from \"@twin.org/modules\";\nimport * as dotenv from \"dotenv\";\nimport { buildEngineConfiguration } from \"./builders/engineEnvBuilder.js\";\nimport { buildEngineServerConfiguration } from \"./builders/engineServerEnvBuilder.js\";\nimport { extensionsConfiguration } from \"./builders/extensionsBuilder.js\";\nimport { constructCliCommand, parseCommandLineArgs, registerCommands } from \"./cli.js\";\nimport { getEnvDefaults } from \"./defaults.js\";\nimport type { INodeEngineConfig } from \"./models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"./models/INodeEngineState.js\";\nimport type { INodeEnvironmentVariables } from \"./models/INodeEnvironmentVariables.js\";\nimport type { INodeOptions } from \"./models/INodeOptions.js\";\nimport { ModuleProtocol } from \"./models/moduleProtocol.js\";\nimport { start } from \"./start.js\";\nimport {\n\tcreateModuleImportUrl,\n\tfileExists,\n\tgetExecutionDirectory,\n\tgetExtensionsCacheDir,\n\tgetScriptDirectory,\n\thandleHttpsProtocol,\n\thandleNpmProtocol,\n\tinitialiseLocales,\n\tloadJsonFile,\n\tloadTextFile,\n\tparseModuleProtocol,\n\tresolvePackageEntryPoint\n} from \"./utils.js\";\n\nconst moduleCache: { [id: string]: unknown } = {};\nlet npmRootCache: string | undefined;\n\n/**\n * Run the TWIN Node.\n * @param nodeOptions Optional configuration options for running the server.\n * @param args Optional command line arguments.\n * @returns A promise that resolves when the server is started containing a shutdown method.\n */\nexport async function run(\n\tnodeOptions?: INodeOptions,\n\targs?: string[]\n): Promise<\n\t| {\n\t\t\tengine: Engine<IEngineServerConfig, INodeEngineState>;\n\t\t\tserver: EngineServer;\n\t\t\tshutdown: () => Promise<void>;\n\t }\n\t| undefined\n> {\n\tlet showErrorDetails = true;\n\ttry {\n\t\tnodeOptions ??= {};\n\n\t\tconst serverInfo: IServerInfo = {\n\t\t\tname: nodeOptions?.serverName ?? \"TWIN Node\",\n\t\t\tversion: nodeOptions?.serverVersion ?? \"0.0.3-next.27\" // x-release-please-version\n\t\t};\n\n\t\tCLIDisplay.header(serverInfo.name, serverInfo.version, \"🌩️ \");\n\n\t\tif (!Is.stringValue(nodeOptions?.executionDirectory)) {\n\t\t\tnodeOptions.executionDirectory = getExecutionDirectory();\n\t\t}\n\t\tCLIDisplay.value(\"Execution Directory\", nodeOptions.executionDirectory);\n\n\t\tif (!Is.stringValue(nodeOptions?.scriptDirectory)) {\n\t\t\tnodeOptions.scriptDirectory = getScriptDirectory(args);\n\t\t}\n\t\tCLIDisplay.value(\"Script Directory\", nodeOptions.scriptDirectory);\n\n\t\tnodeOptions.localesDirectory =\n\t\t\tnodeOptions?.localesDirectory ??\n\t\t\tpath.resolve(path.join(nodeOptions.scriptDirectory, \"dist\", \"locales\"));\n\n\t\tCLIDisplay.value(\"Locales Directory\", nodeOptions.localesDirectory);\n\t\tawait initialiseLocales(nodeOptions.localesDirectory);\n\n\t\tnodeOptions.envPrefix ??= \"TWIN_\";\n\n\t\toverrideModuleImport(nodeOptions.executionDirectory ?? \"\");\n\n\t\tconst commandLineArgs = parseCommandLineArgs(args);\n\n\t\tconst hasEnvPrefix = commandLineArgs.options?.find(option => option.key === \"env-prefix\");\n\t\tif (hasEnvPrefix) {\n\t\t\tnodeOptions.envPrefix = Coerce.string(hasEnvPrefix.value) ?? nodeOptions.envPrefix;\n\t\t}\n\n\t\tCLIDisplay.value(\"Environment Variable Prefix\", nodeOptions.envPrefix);\n\n\t\t// This is the only location in the code base that should access process.env directly\n\t\t// So we can safely disable the linting rule here.\n\t\tlet finalEnvVars =\n\t\t\t// eslint-disable-next-line no-restricted-syntax\n\t\t\tprocess.env as {\n\t\t\t\t[id: string]: string;\n\t\t\t};\n\n\t\tif (Is.objectValue(nodeOptions?.envVars)) {\n\t\t\tfinalEnvVars = {\n\t\t\t\t...finalEnvVars,\n\t\t\t\t...nodeOptions.envVars\n\t\t\t};\n\t\t}\n\n\t\tfinalEnvVars = {\n\t\t\t...getEnvDefaults(nodeOptions.envPrefix),\n\t\t\t...finalEnvVars\n\t\t};\n\n\t\tlet cliCommand;\n\t\tif (Is.arrayValue(commandLineArgs.options)) {\n\t\t\tregisterCommands();\n\t\t\tcliCommand = constructCliCommand(finalEnvVars, commandLineArgs);\n\t\t}\n\n\t\tif (Is.object(cliCommand)) {\n\t\t\tfinalEnvVars[`${nodeOptions.envPrefix}SILENT`] ??= \"true\";\n\t\t} else {\n\t\t\tif (Is.empty(nodeOptions?.openApiSpecFile)) {\n\t\t\t\tconst specFile = path.resolve(\n\t\t\t\t\tpath.join(nodeOptions.scriptDirectory ?? \"\", \"docs\", \"open-api\", \"spec.json\")\n\t\t\t\t);\n\t\t\t\tif (await fileExists(specFile)) {\n\t\t\t\t\tnodeOptions ??= {};\n\t\t\t\t\tnodeOptions.openApiSpecFile = specFile;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (Is.stringValue(nodeOptions.openApiSpecFile)) {\n\t\t\t\tCLIDisplay.value(\"OpenAPI Spec File\", nodeOptions.openApiSpecFile);\n\t\t\t}\n\n\t\t\tif (Is.empty(nodeOptions?.favIconFile)) {\n\t\t\t\tconst favIconFile = path.resolve(\n\t\t\t\t\tpath.join(nodeOptions.scriptDirectory ?? \"\", \"static\", \"favicon.png\")\n\t\t\t\t);\n\t\t\t\tif (await fileExists(favIconFile)) {\n\t\t\t\t\tnodeOptions ??= {};\n\t\t\t\t\tnodeOptions.favIconFile = favIconFile;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (Is.stringValue(nodeOptions.favIconFile)) {\n\t\t\t\tCLIDisplay.value(\"Favicon File\", nodeOptions.favIconFile);\n\t\t\t}\n\t\t}\n\n\t\tconst { nodeEngineConfig, nodeEnvVars, availableContextIdKeys } = await buildConfiguration(\n\t\t\tfinalEnvVars,\n\t\t\tnodeOptions,\n\t\t\tserverInfo\n\t\t);\n\n\t\tCLIDisplay.break();\n\n\t\tconst startResult = await start(\n\t\t\tnodeOptions,\n\t\t\tnodeEngineConfig,\n\t\t\tnodeEnvVars,\n\t\t\tcliCommand,\n\t\t\tavailableContextIdKeys\n\t\t);\n\n\t\tif (!Is.empty(startResult)) {\n\t\t\tshowErrorDetails = false;\n\n\t\t\tlet isShuttingDown = false;\n\t\t\tfor (const signal of [\"SIGHUP\", \"SIGINT\", \"SIGTERM\"]) {\n\t\t\t\tprocess.on(signal, async () => {\n\t\t\t\t\tif (!isShuttingDown) {\n\t\t\t\t\t\tisShuttingDown = true;\n\t\t\t\t\t\tCLIDisplay.value(\"Terminate Signal\", signal);\n\t\t\t\t\t\tawait startResult.shutdown();\n\t\t\t\t\t\tprocess.exit(0);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn startResult;\n\t} catch (err) {\n\t\tif (nodeOptions?.disableProcessExitOnFailure ?? false) {\n\t\t\tthrow err;\n\t\t}\n\n\t\tif (showErrorDetails) {\n\t\t\tconst baseError = BaseError.fromError(err);\n\t\t\tif (baseError.source === \"node\") {\n\t\t\t\tObjectHelper.propertyDelete(err, \"stack\");\n\t\t\t}\n\t\t\tCLIDisplay.error(err);\n\t\t}\n\n\t\t// eslint-disable-next-line unicorn/no-process-exit\n\t\tprocess.exit(1);\n\t}\n}\n\n/**\n * Build the configuration for the TWIN Node.\n * @param processEnv The environment variables from the process.\n * @param options The options for running the server.\n * @param serverInfo The server information.\n * @returns A promise that resolves to the engine server configuration, environment prefix, environment variables,\n * and options.\n */\nexport async function buildConfiguration(\n\tprocessEnv: {\n\t\t[id: string]: string;\n\t},\n\toptions: INodeOptions,\n\tserverInfo: IServerInfo\n): Promise<{\n\tnodeEnvVars: INodeEnvironmentVariables & { [id: string]: string | unknown };\n\tnodeEngineConfig: INodeEngineConfig;\n\tavailableContextIdKeys: { key: string; requiredHandlerFeatures: string[] }[];\n}> {\n\tconst availableContextIdKeys: { key: string; requiredHandlerFeatures: string[] }[] = [];\n\n\tlet defaultEnvOnly = false;\n\tif (Is.empty(options?.envFilenames)) {\n\t\tconst envFile = path.resolve(path.join(options.executionDirectory ?? \"\", \".env\"));\n\t\tCLIDisplay.value(\"Default Environment File\", envFile);\n\t\toptions ??= {};\n\t\toptions.envFilenames = [envFile];\n\t\tdefaultEnvOnly = true;\n\t}\n\n\tif (Is.arrayValue(options?.envFilenames)) {\n\t\tconst output = dotenv.config({\n\t\t\tpath: options?.envFilenames,\n\t\t\tquiet: true\n\t\t});\n\n\t\t// We don't want to throw an error if the default environment file is not found.\n\t\t// Only if we have custom environment files.\n\t\tif (!defaultEnvOnly && output.error) {\n\t\t\tthrow output.error;\n\t\t}\n\n\t\tif (Is.objectValue(output.parsed)) {\n\t\t\tObject.assign(processEnv, output.parsed);\n\t\t}\n\t}\n\n\tconst envVars = EnvHelper.envToJson<{ [id: string]: string | unknown }>(\n\t\tprocessEnv,\n\t\toptions.envPrefix ?? \"\"\n\t);\n\n\t// Expand any environment variables that use the @file: syntax\n\tconst keys = Object.keys(envVars);\n\tfor (const key of keys) {\n\t\tif (\n\t\t\tIs.stringValue(envVars[key]) &&\n\t\t\t(envVars[key].startsWith(\"@text:\") || envVars[key].startsWith(\"@json:\"))\n\t\t) {\n\t\t\tconst filePath = envVars[key].slice(6).trim();\n\t\t\tconst embeddedFile = path.resolve(path.join(options.executionDirectory ?? \"\", filePath));\n\n\t\t\tif (envVars[key].startsWith(\"@text:\")) {\n\t\t\t\tCLIDisplay.value(`Expanding Environment Variable: ${key} from text file`, embeddedFile);\n\t\t\t\tenvVars[key] = await loadTextFile(embeddedFile);\n\t\t\t} else if (envVars[key].startsWith(\"@json:\")) {\n\t\t\t\tCLIDisplay.value(`Expanding Environment Variable: ${key} from JSON file`, embeddedFile);\n\t\t\t\tenvVars[key] = await loadJsonFile(embeddedFile);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Extend the environment variables with any additional custom configuration.\n\tif (Is.function(options?.extendEnvVars)) {\n\t\tCLIDisplay.task(\"Extending Environment Variables\");\n\t\tawait options.extendEnvVars(envVars);\n\t}\n\n\t// Build the engine configuration from the environment variables.\n\tconst coreConfig = await buildEngineConfiguration(envVars, availableContextIdKeys);\n\tconst engineServerConfig = await buildEngineServerConfiguration(\n\t\tenvVars,\n\t\tavailableContextIdKeys,\n\t\tcoreConfig,\n\t\tserverInfo,\n\t\toptions?.openApiSpecFile,\n\t\toptions?.favIconFile\n\t);\n\n\t// Merge any custom configuration provided in the options.\n\tif (Is.arrayValue(options?.configFilenames)) {\n\t\tfor (const configFile of options.configFilenames) {\n\t\t\tCLIDisplay.value(\"Loading Configuration File\", configFile);\n\t\t\tconst configFilePath = path.resolve(path.join(options.executionDirectory ?? \"\", configFile));\n\t\t\tconst config = await loadJsonFile(configFilePath);\n\t\t\tObject.assign(engineServerConfig, config);\n\t\t}\n\t}\n\n\tif (Is.objectValue(options?.config)) {\n\t\tCLIDisplay.task(\"Merging Custom Configuration\");\n\t\tObject.assign(engineServerConfig, options.config);\n\t}\n\n\t// Merge any custom configuration provided in the options.\n\tif (Is.function(options?.extendConfig)) {\n\t\tCLIDisplay.task(\"Extending Configuration\");\n\t\tawait options.extendConfig(envVars, engineServerConfig);\n\t}\n\n\tconst nodeEngineConfig = await extensionsConfiguration(envVars, engineServerConfig);\n\n\treturn { nodeEngineConfig, nodeEnvVars: envVars, availableContextIdKeys };\n}\n\n/**\n * Override module imports to support protocol-based loading (npm:, https:) and local files.\n * @param executionDirectory The execution directory for resolving local module paths.\n * @param envVars The environment variables containing extension configuration (optional, uses defaults if not provided).\n */\nexport function overrideModuleImport(\n\texecutionDirectory: string,\n\tenvVars?: INodeEnvironmentVariables\n): void {\n\tconst maxSizeMb = Coerce.number(envVars?.extensionsMaxSizeMb) ?? 10;\n\tconst cacheDirectory = envVars?.extensionsCacheDirectory;\n\n\tModuleHelper.overrideImport(async moduleName => {\n\t\tif (moduleCache[moduleName]) {\n\t\t\treturn {\n\t\t\t\tmodule: moduleCache[moduleName],\n\t\t\t\tuseDefault: false\n\t\t\t};\n\t\t}\n\n\t\tconst parsed = parseModuleProtocol(moduleName);\n\t\tlet resolvedPath: string | undefined;\n\n\t\tswitch (parsed.protocol) {\n\t\t\tcase ModuleProtocol.Npm: {\n\t\t\t\tconst result = await handleNpmProtocol(\n\t\t\t\t\tparsed.identifier,\n\t\t\t\t\texecutionDirectory,\n\t\t\t\t\tcacheDirectory\n\t\t\t\t);\n\t\t\t\tresolvedPath = result.resolvedPath;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Https: {\n\t\t\t\tconst result = await handleHttpsProtocol(\n\t\t\t\t\tparsed.identifier,\n\t\t\t\t\texecutionDirectory,\n\t\t\t\t\tmaxSizeMb,\n\t\t\t\t\tcacheDirectory,\n\t\t\t\t\tenvVars?.extensionsCacheTtlHours,\n\t\t\t\t\tenvVars?.extensionsForceRefresh\n\t\t\t\t);\n\t\t\t\tresolvedPath = result.resolvedPath;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Http: {\n\t\t\t\tthrow new GeneralError(\"node\", \"insecureProtocol\", { protocol: ModuleProtocol.Http });\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Local: {\n\t\t\t\tlet localFilename = path.resolve(moduleName);\n\n\t\t\t\tlet exists = await fileExists(localFilename);\n\t\t\t\tif (!exists) {\n\t\t\t\t\tlocalFilename = path.resolve(executionDirectory, moduleName);\n\t\t\t\t\texists = await fileExists(localFilename);\n\t\t\t\t}\n\n\t\t\t\tif (exists) {\n\t\t\t\t\tresolvedPath = localFilename;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Default: {\n\t\t\t\ttry {\n\t\t\t\t\tconst packagePath = path.resolve(getNpmRootPath(), moduleName);\n\t\t\t\t\tconst mainFile = await resolvePackageEntryPoint(packagePath, moduleName);\n\t\t\t\t\tconst modulePath = path.resolve(packagePath, mainFile);\n\t\t\t\t\tconst exists = await fileExists(modulePath);\n\t\t\t\t\tif (exists) {\n\t\t\t\t\t\tresolvedPath = modulePath;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// Continue to fallback resolution\n\t\t\t\t}\n\n\t\t\t\t// Fallback: resolve from npm protocol cache directory (installed via handleNpmProtocol)\n\t\t\t\ttry {\n\t\t\t\t\tconst cacheNpmRoot = path.resolve(\n\t\t\t\t\t\tgetExtensionsCacheDir(executionDirectory, ModuleProtocol.Npm, cacheDirectory),\n\t\t\t\t\t\t\"node_modules\"\n\t\t\t\t\t);\n\n\t\t\t\t\tconst packagePath = path.resolve(cacheNpmRoot, moduleName);\n\t\t\t\t\tconst mainFile = await resolvePackageEntryPoint(packagePath, moduleName);\n\t\t\t\t\tconst modulePath = path.resolve(packagePath, mainFile);\n\t\t\t\t\tconst exists = await fileExists(modulePath);\n\t\t\t\t\tif (exists) {\n\t\t\t\t\t\tresolvedPath = modulePath;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// No cached resolution either; fall through\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\t// Common module loading and caching logic\n\t\tif (resolvedPath) {\n\t\t\tconst module = await import(createModuleImportUrl(resolvedPath));\n\t\t\tmoduleCache[moduleName] = module;\n\t\t\treturn {\n\t\t\t\tmodule,\n\t\t\t\tuseDefault: false\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tmodule: undefined,\n\t\t\tuseDefault: true\n\t\t};\n\t});\n}\n\n/**\n * Get the root path for npm modules by executing \"npm root\" command and cache it.\n * @returns The root path for npm modules.\n */\nfunction getNpmRootPath(): string {\n\tnpmRootCache ??= execSync(\"npm root\").toString().trim().replace(/\\\\/g, \"/\");\n\treturn npmRootC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G,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;oBACvD,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,UAAU,CAAC,CAAC;oBAC5C,IAAI,MAAM,EAAE,CAAC;wBACZ,YAAY,GAAG,UAAU,CAAC;oBAC3B,CAAC;gBACF,CAAC;gBAAC,MAAM,CAAC;oBACR,4CAA4C;gBAC7C,CAAC;gBACD,MAAM;YACP,CAAC;QACF,CAAC;QAED,0CAA0C;QAC1C,IAAI,YAAY,EAAE,CAAC;YAClB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC,CAAC;YACjE,WAAW,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC;YACjC,OAAO;gBACN,MAAM;gBACN,UAAU,EAAE,KAAK;aACjB,CAAC;QACH,CAAC;QAED,OAAO;YACN,MAAM,EAAE,SAAS;YACjB,UAAU,EAAE,IAAI;SAChB,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,cAAc;IACtB,YAAY,KAAK,QAAQ,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC5E,OAAO,YAAY,CAAC;AACrB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { execSync } from \"node:child_process\";\nimport path from \"node:path\";\nimport type { IServerInfo } from \"@twin.org/api-models\";\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { BaseError, Coerce, EnvHelper, GeneralError, Is, ObjectHelper } from \"@twin.org/core\";\nimport type { Engine } from \"@twin.org/engine\";\nimport type { EngineServer } from \"@twin.org/engine-server\";\nimport type { IEngineServerConfig } from \"@twin.org/engine-server-types\";\nimport { ModuleHelper } from \"@twin.org/modules\";\nimport * as dotenv from \"dotenv\";\nimport { buildEngineConfiguration } from \"./builders/engineEnvBuilder.js\";\nimport { buildEngineServerConfiguration } from \"./builders/engineServerEnvBuilder.js\";\nimport { extensionsConfiguration } from \"./builders/extensionsBuilder.js\";\nimport { constructCliCommand, parseCommandLineArgs, registerCommands } from \"./cli.js\";\nimport { getEnvDefaults } from \"./defaults.js\";\nimport type { INodeEngineConfig } from \"./models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"./models/INodeEngineState.js\";\nimport type { INodeEnvironmentVariables } from \"./models/INodeEnvironmentVariables.js\";\nimport type { INodeOptions } from \"./models/INodeOptions.js\";\nimport { ModuleProtocol } from \"./models/moduleProtocol.js\";\nimport { start } from \"./start.js\";\nimport {\n\tcreateModuleImportUrl,\n\tfileExists,\n\tgetExecutionDirectory,\n\tgetExtensionsCacheDir,\n\tgetScriptDirectory,\n\thandleHttpsProtocol,\n\thandleNpmProtocol,\n\tinitialiseLocales,\n\tloadJsonFile,\n\tloadTextFile,\n\tparseModuleProtocol,\n\tresolvePackageEntryPoint\n} from \"./utils.js\";\n\nconst moduleCache: { [id: string]: unknown } = {};\nlet npmRootCache: string | undefined;\n\n/**\n * Run the TWIN Node.\n * @param nodeOptions Optional configuration options for running the server.\n * @param args Optional command line arguments.\n * @returns A promise that resolves when the server is started containing a shutdown method.\n */\nexport async function run(\n\tnodeOptions?: INodeOptions,\n\targs?: string[]\n): Promise<\n\t| {\n\t\t\tengine: Engine<IEngineServerConfig, INodeEngineState>;\n\t\t\tserver: EngineServer;\n\t\t\tshutdown: () => Promise<void>;\n\t }\n\t| undefined\n> {\n\tlet showErrorDetails = true;\n\ttry {\n\t\tnodeOptions ??= {};\n\n\t\tconst serverInfo: IServerInfo = {\n\t\t\tname: nodeOptions?.serverName ?? \"TWIN Node\",\n\t\t\tversion: nodeOptions?.serverVersion ?? \"0.0.3-next.28\" // x-release-please-version\n\t\t};\n\n\t\tCLIDisplay.header(serverInfo.name, serverInfo.version, \"🌩️ \");\n\n\t\tif (!Is.stringValue(nodeOptions?.executionDirectory)) {\n\t\t\tnodeOptions.executionDirectory = getExecutionDirectory();\n\t\t}\n\t\tCLIDisplay.value(\"Execution Directory\", nodeOptions.executionDirectory);\n\n\t\tif (!Is.stringValue(nodeOptions?.scriptDirectory)) {\n\t\t\tnodeOptions.scriptDirectory = getScriptDirectory(args);\n\t\t}\n\t\tCLIDisplay.value(\"Script Directory\", nodeOptions.scriptDirectory);\n\n\t\tnodeOptions.localesDirectory =\n\t\t\tnodeOptions?.localesDirectory ??\n\t\t\tpath.resolve(path.join(nodeOptions.scriptDirectory, \"dist\", \"locales\"));\n\n\t\tCLIDisplay.value(\"Locales Directory\", nodeOptions.localesDirectory);\n\t\tawait initialiseLocales(nodeOptions.localesDirectory);\n\n\t\tnodeOptions.envPrefix ??= \"TWIN_\";\n\n\t\toverrideModuleImport(nodeOptions.executionDirectory ?? \"\");\n\n\t\tconst commandLineArgs = parseCommandLineArgs(args);\n\n\t\tconst hasEnvPrefix = commandLineArgs.options?.find(option => option.key === \"env-prefix\");\n\t\tif (hasEnvPrefix) {\n\t\t\tnodeOptions.envPrefix = Coerce.string(hasEnvPrefix.value) ?? nodeOptions.envPrefix;\n\t\t}\n\n\t\tCLIDisplay.value(\"Environment Variable Prefix\", nodeOptions.envPrefix);\n\n\t\t// This is the only location in the code base that should access process.env directly\n\t\t// So we can safely disable the linting rule here.\n\t\tlet finalEnvVars =\n\t\t\t// eslint-disable-next-line no-restricted-syntax\n\t\t\tprocess.env as {\n\t\t\t\t[id: string]: string;\n\t\t\t};\n\n\t\tif (Is.objectValue(nodeOptions?.envVars)) {\n\t\t\tfinalEnvVars = {\n\t\t\t\t...finalEnvVars,\n\t\t\t\t...nodeOptions.envVars\n\t\t\t};\n\t\t}\n\n\t\tfinalEnvVars = {\n\t\t\t...getEnvDefaults(nodeOptions.envPrefix),\n\t\t\t...finalEnvVars\n\t\t};\n\n\t\tlet cliCommand;\n\t\tif (Is.arrayValue(commandLineArgs.options)) {\n\t\t\tregisterCommands();\n\t\t\tcliCommand = constructCliCommand(finalEnvVars, commandLineArgs);\n\t\t}\n\n\t\tif (Is.object(cliCommand)) {\n\t\t\tfinalEnvVars[`${nodeOptions.envPrefix}SILENT`] ??= \"true\";\n\t\t} else {\n\t\t\tif (Is.empty(nodeOptions?.openApiSpecFile)) {\n\t\t\t\tconst specFile = path.resolve(\n\t\t\t\t\tpath.join(nodeOptions.scriptDirectory ?? \"\", \"docs\", \"open-api\", \"spec.json\")\n\t\t\t\t);\n\t\t\t\tif (await fileExists(specFile)) {\n\t\t\t\t\tnodeOptions ??= {};\n\t\t\t\t\tnodeOptions.openApiSpecFile = specFile;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (Is.stringValue(nodeOptions.openApiSpecFile)) {\n\t\t\t\tCLIDisplay.value(\"OpenAPI Spec File\", nodeOptions.openApiSpecFile);\n\t\t\t}\n\n\t\t\tif (Is.empty(nodeOptions?.favIconFile)) {\n\t\t\t\tconst favIconFile = path.resolve(\n\t\t\t\t\tpath.join(nodeOptions.scriptDirectory ?? \"\", \"static\", \"favicon.png\")\n\t\t\t\t);\n\t\t\t\tif (await fileExists(favIconFile)) {\n\t\t\t\t\tnodeOptions ??= {};\n\t\t\t\t\tnodeOptions.favIconFile = favIconFile;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (Is.stringValue(nodeOptions.favIconFile)) {\n\t\t\t\tCLIDisplay.value(\"Favicon File\", nodeOptions.favIconFile);\n\t\t\t}\n\t\t}\n\n\t\tconst { nodeEngineConfig, nodeEnvVars, availableContextIdKeys } = await buildConfiguration(\n\t\t\tfinalEnvVars,\n\t\t\tnodeOptions,\n\t\t\tserverInfo\n\t\t);\n\n\t\tCLIDisplay.break();\n\n\t\tconst startResult = await start(\n\t\t\tnodeOptions,\n\t\t\tnodeEngineConfig,\n\t\t\tnodeEnvVars,\n\t\t\tcliCommand,\n\t\t\tavailableContextIdKeys\n\t\t);\n\n\t\tif (!Is.empty(startResult)) {\n\t\t\tshowErrorDetails = false;\n\n\t\t\tlet isShuttingDown = false;\n\t\t\tfor (const signal of [\"SIGHUP\", \"SIGINT\", \"SIGTERM\"]) {\n\t\t\t\tprocess.on(signal, async () => {\n\t\t\t\t\tif (!isShuttingDown) {\n\t\t\t\t\t\tisShuttingDown = true;\n\t\t\t\t\t\tCLIDisplay.value(\"Terminate Signal\", signal);\n\t\t\t\t\t\tawait startResult.shutdown();\n\t\t\t\t\t\tprocess.exit(0);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn startResult;\n\t} catch (err) {\n\t\tif (nodeOptions?.disableProcessExitOnFailure ?? false) {\n\t\t\tthrow err;\n\t\t}\n\n\t\tif (showErrorDetails) {\n\t\t\tconst baseError = BaseError.fromError(err);\n\t\t\tif (baseError.source === \"node\") {\n\t\t\t\tObjectHelper.propertyDelete(err, \"stack\");\n\t\t\t}\n\t\t\tCLIDisplay.error(err);\n\t\t}\n\n\t\t// eslint-disable-next-line unicorn/no-process-exit\n\t\tprocess.exit(1);\n\t}\n}\n\n/**\n * Build the configuration for the TWIN Node.\n * @param processEnv The environment variables from the process.\n * @param options The options for running the server.\n * @param serverInfo The server information.\n * @returns A promise that resolves to the engine server configuration, environment prefix, environment variables,\n * and options.\n */\nexport async function buildConfiguration(\n\tprocessEnv: {\n\t\t[id: string]: string;\n\t},\n\toptions: INodeOptions,\n\tserverInfo: IServerInfo\n): Promise<{\n\tnodeEnvVars: INodeEnvironmentVariables & { [id: string]: string | unknown };\n\tnodeEngineConfig: INodeEngineConfig;\n\tavailableContextIdKeys: { key: string; requiredHandlerFeatures: string[] }[];\n}> {\n\tconst availableContextIdKeys: { key: string; requiredHandlerFeatures: string[] }[] = [];\n\n\tlet defaultEnvOnly = false;\n\tif (Is.empty(options?.envFilenames)) {\n\t\tconst envFile = path.resolve(path.join(options.executionDirectory ?? \"\", \".env\"));\n\t\tCLIDisplay.value(\"Default Environment File\", envFile);\n\t\toptions ??= {};\n\t\toptions.envFilenames = [envFile];\n\t\tdefaultEnvOnly = true;\n\t}\n\n\tif (Is.arrayValue(options?.envFilenames)) {\n\t\tconst output = dotenv.config({\n\t\t\tpath: options?.envFilenames,\n\t\t\tquiet: true\n\t\t});\n\n\t\t// We don't want to throw an error if the default environment file is not found.\n\t\t// Only if we have custom environment files.\n\t\tif (!defaultEnvOnly && output.error) {\n\t\t\tthrow output.error;\n\t\t}\n\n\t\tif (Is.objectValue(output.parsed)) {\n\t\t\tObject.assign(processEnv, output.parsed);\n\t\t}\n\t}\n\n\tconst envVars = EnvHelper.envToJson<{ [id: string]: string | unknown }>(\n\t\tprocessEnv,\n\t\toptions.envPrefix ?? \"\"\n\t);\n\n\t// Expand any environment variables that use the @file: syntax\n\tconst keys = Object.keys(envVars);\n\tfor (const key of keys) {\n\t\tif (\n\t\t\tIs.stringValue(envVars[key]) &&\n\t\t\t(envVars[key].startsWith(\"@text:\") || envVars[key].startsWith(\"@json:\"))\n\t\t) {\n\t\t\tconst filePath = envVars[key].slice(6).trim();\n\t\t\tconst embeddedFile = path.resolve(path.join(options.executionDirectory ?? \"\", filePath));\n\n\t\t\tif (envVars[key].startsWith(\"@text:\")) {\n\t\t\t\tCLIDisplay.value(`Expanding Environment Variable: ${key} from text file`, embeddedFile);\n\t\t\t\tenvVars[key] = await loadTextFile(embeddedFile);\n\t\t\t} else if (envVars[key].startsWith(\"@json:\")) {\n\t\t\t\tCLIDisplay.value(`Expanding Environment Variable: ${key} from JSON file`, embeddedFile);\n\t\t\t\tenvVars[key] = await loadJsonFile(embeddedFile);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Extend the environment variables with any additional custom configuration.\n\tif (Is.function(options?.extendEnvVars)) {\n\t\tCLIDisplay.task(\"Extending Environment Variables\");\n\t\tawait options.extendEnvVars(envVars);\n\t}\n\n\t// Build the engine configuration from the environment variables.\n\tconst coreConfig = await buildEngineConfiguration(envVars, availableContextIdKeys);\n\tconst engineServerConfig = await buildEngineServerConfiguration(\n\t\tenvVars,\n\t\tavailableContextIdKeys,\n\t\tcoreConfig,\n\t\tserverInfo,\n\t\toptions?.openApiSpecFile,\n\t\toptions?.favIconFile\n\t);\n\n\t// Merge any custom configuration provided in the options.\n\tif (Is.arrayValue(options?.configFilenames)) {\n\t\tfor (const configFile of options.configFilenames) {\n\t\t\tCLIDisplay.value(\"Loading Configuration File\", configFile);\n\t\t\tconst configFilePath = path.resolve(path.join(options.executionDirectory ?? \"\", configFile));\n\t\t\tconst config = await loadJsonFile(configFilePath);\n\t\t\tObject.assign(engineServerConfig, config);\n\t\t}\n\t}\n\n\tif (Is.objectValue(options?.config)) {\n\t\tCLIDisplay.task(\"Merging Custom Configuration\");\n\t\tObject.assign(engineServerConfig, options.config);\n\t}\n\n\t// Merge any custom configuration provided in the options.\n\tif (Is.function(options?.extendConfig)) {\n\t\tCLIDisplay.task(\"Extending Configuration\");\n\t\tawait options.extendConfig(envVars, engineServerConfig);\n\t}\n\n\tconst nodeEngineConfig = await extensionsConfiguration(envVars, engineServerConfig);\n\n\treturn { nodeEngineConfig, nodeEnvVars: envVars, availableContextIdKeys };\n}\n\n/**\n * Override module imports to support protocol-based loading (npm:, https:) and local files.\n * @param executionDirectory The execution directory for resolving local module paths.\n * @param envVars The environment variables containing extension configuration (optional, uses defaults if not provided).\n */\nexport function overrideModuleImport(\n\texecutionDirectory: string,\n\tenvVars?: INodeEnvironmentVariables\n): void {\n\tconst maxSizeMb = Coerce.number(envVars?.extensionsMaxSizeMb) ?? 10;\n\tconst cacheDirectory = envVars?.extensionsCacheDirectory;\n\n\tModuleHelper.overrideImport(async moduleName => {\n\t\tif (moduleCache[moduleName]) {\n\t\t\treturn {\n\t\t\t\tmodule: moduleCache[moduleName],\n\t\t\t\tuseDefault: false\n\t\t\t};\n\t\t}\n\n\t\tconst parsed = parseModuleProtocol(moduleName);\n\t\tlet resolvedPath: string | undefined;\n\n\t\tswitch (parsed.protocol) {\n\t\t\tcase ModuleProtocol.Npm: {\n\t\t\t\tconst result = await handleNpmProtocol(\n\t\t\t\t\tparsed.identifier,\n\t\t\t\t\texecutionDirectory,\n\t\t\t\t\tcacheDirectory\n\t\t\t\t);\n\t\t\t\tresolvedPath = result.resolvedPath;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Https: {\n\t\t\t\tconst result = await handleHttpsProtocol(\n\t\t\t\t\tparsed.identifier,\n\t\t\t\t\texecutionDirectory,\n\t\t\t\t\tmaxSizeMb,\n\t\t\t\t\tcacheDirectory,\n\t\t\t\t\tenvVars?.extensionsCacheTtlHours,\n\t\t\t\t\tenvVars?.extensionsForceRefresh\n\t\t\t\t);\n\t\t\t\tresolvedPath = result.resolvedPath;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Http: {\n\t\t\t\tthrow new GeneralError(\"node\", \"insecureProtocol\", { protocol: ModuleProtocol.Http });\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Local: {\n\t\t\t\tlet localFilename = path.resolve(moduleName);\n\n\t\t\t\tlet exists = await fileExists(localFilename);\n\t\t\t\tif (!exists) {\n\t\t\t\t\tlocalFilename = path.resolve(executionDirectory, moduleName);\n\t\t\t\t\texists = await fileExists(localFilename);\n\t\t\t\t}\n\n\t\t\t\tif (exists) {\n\t\t\t\t\tresolvedPath = localFilename;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Default: {\n\t\t\t\ttry {\n\t\t\t\t\tconst packagePath = path.resolve(getNpmRootPath(), moduleName);\n\t\t\t\t\tconst mainFile = await resolvePackageEntryPoint(packagePath, moduleName);\n\t\t\t\t\tconst modulePath = path.resolve(packagePath, mainFile);\n\t\t\t\t\tconst exists = await fileExists(modulePath);\n\t\t\t\t\tif (exists) {\n\t\t\t\t\t\tresolvedPath = modulePath;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// Continue to fallback resolution\n\t\t\t\t}\n\n\t\t\t\t// Fallback: resolve from npm protocol cache directory (installed via handleNpmProtocol)\n\t\t\t\ttry {\n\t\t\t\t\tconst cacheNpmRoot = path.resolve(\n\t\t\t\t\t\tgetExtensionsCacheDir(executionDirectory, ModuleProtocol.Npm, cacheDirectory),\n\t\t\t\t\t\t\"node_modules\"\n\t\t\t\t\t);\n\n\t\t\t\t\tconst packagePath = path.resolve(cacheNpmRoot, moduleName);\n\t\t\t\t\tconst mainFile = await resolvePackageEntryPoint(packagePath, moduleName);\n\t\t\t\t\tconst modulePath = path.resolve(packagePath, mainFile);\n\t\t\t\t\tconst exists = await fileExists(modulePath);\n\t\t\t\t\tif (exists) {\n\t\t\t\t\t\tresolvedPath = modulePath;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// No cached resolution either; fall through\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\t// Common module loading and caching logic\n\t\tif (resolvedPath) {\n\t\t\tconst module = await import(createModuleImportUrl(resolvedPath));\n\t\t\tmoduleCache[moduleName] = module;\n\t\t\treturn {\n\t\t\t\tmodule,\n\t\t\t\tuseDefault: false\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tmodule: undefined,\n\t\t\tuseDefault: true\n\t\t};\n\t});\n}\n\n/**\n * Get the root path for npm modules by executing \"npm root\" command and cache it.\n * @returns The root path for npm modules.\n */\nfunction getNpmRootPath(): string {\n\tnpmRootCache ??= execSync(\"npm root\").toString().trim().replace(/\\\\/g, \"/\");\n\treturn npmRootCache;\n}\n"]}
package/docs/changelog.md CHANGED
@@ -1,4 +1,11 @@
1
- # @twin.org/node-core - Changelog
1
+ # Changelog
2
+
3
+ ## [0.0.3-next.28](https://github.com/twinfoundation/node/compare/node-core-v0.0.3-next.27...node-core-v0.0.3-next.28) (2026-03-12)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * bootstrap legacy fails on second run ([c0a4e6d](https://github.com/twinfoundation/node/commit/c0a4e6d6f8d1bf385412a22fed2a0974e219abaa))
2
9
 
3
10
  ## [0.0.3-next.27](https://github.com/twinfoundation/node/compare/node-core-v0.0.3-next.26...node-core-v0.0.3-next.27) (2026-03-09)
4
11
 
package/docs/examples.md CHANGED
@@ -1 +1,99 @@
1
- # @twin.org/node-core - Examples
1
+ # Node Core Examples
2
+
3
+ These snippets show practical runtime setup patterns, state inspection, and controlled shutdown so you can move from local development to automation with predictable behaviour.
4
+
5
+ ## Engine
6
+
7
+ ```typescript
8
+ import { run } from '@twin.org/node-core';
9
+
10
+ const runtime = await run(
11
+ {
12
+ disableProcessExitOnFailure: true,
13
+ envVars: {
14
+ TWIN_HOST: '127.0.0.1',
15
+ TWIN_PORT: '8080',
16
+ TWIN_STORAGE_FILE_ROOT: './storage',
17
+ TWIN_STATE_FILENAME: 'engine-state.json'
18
+ }
19
+ },
20
+ ['node', 'index.js']
21
+ );
22
+
23
+ if (runtime) {
24
+ const state = runtime.engine.getState();
25
+ console.log(typeof state); // object
26
+ console.log(state.nodeId ?? 'not-configured'); // not-configured
27
+ await runtime.shutdown();
28
+ }
29
+ ```
30
+
31
+ ```typescript
32
+ import { run } from '@twin.org/node-core';
33
+
34
+ const runtime = await run(
35
+ {
36
+ disableProcessExitOnFailure: true,
37
+ envVars: {
38
+ TWIN_HOST: '127.0.0.1',
39
+ TWIN_PORT: '8081',
40
+ TWIN_STORAGE_FILE_ROOT: './storage',
41
+ TWIN_STATE_FILENAME: 'engine-state.json'
42
+ }
43
+ },
44
+ ['node', 'index.js']
45
+ );
46
+
47
+ if (runtime) {
48
+ await runtime.engine.logInfo('Startup validation completed');
49
+ const state = runtime.engine.getState();
50
+ console.log(Object.keys(state).length >= 0); // true
51
+ await runtime.shutdown();
52
+ }
53
+ ```
54
+
55
+ ## EngineServer
56
+
57
+ ```typescript
58
+ import type { IServerInfo } from '@twin.org/api-models';
59
+ import type { INodeOptions } from '@twin.org/node-core';
60
+ import { buildConfiguration, start } from '@twin.org/node-core';
61
+
62
+ const processEnv: Record<string, string> = {
63
+ TWIN_HOST: '127.0.0.1',
64
+ TWIN_PORT: '8082',
65
+ TWIN_STORAGE_FILE_ROOT: './storage',
66
+ TWIN_STATE_FILENAME: 'engine-state.json'
67
+ };
68
+
69
+ const options: INodeOptions = {
70
+ disableProcessExitOnFailure: true,
71
+ envPrefix: 'TWIN_',
72
+ executionDirectory: process.cwd(),
73
+ scriptDirectory: process.cwd()
74
+ };
75
+
76
+ const serverInfo: IServerInfo = {
77
+ name: 'Local Runtime',
78
+ version: '0.0.0-dev'
79
+ };
80
+
81
+ const { nodeEngineConfig, nodeEnvVars, availableContextIdKeys } = await buildConfiguration(
82
+ processEnv,
83
+ options,
84
+ serverInfo
85
+ );
86
+
87
+ const runtime = await start(
88
+ options,
89
+ nodeEngineConfig,
90
+ nodeEnvVars,
91
+ undefined,
92
+ availableContextIdKeys
93
+ );
94
+
95
+ if (runtime) {
96
+ console.log(typeof runtime.server.stop); // function
97
+ await runtime.server.stop();
98
+ }
99
+ ```
@@ -66,12 +66,6 @@ The method to execute for the command.
66
66
 
67
67
  Indicates whether the engine needs to be started before executing the command.
68
68
 
69
- #### Default
70
-
71
- ```ts
72
- true
73
- ```
74
-
75
69
  ***
76
70
 
77
71
  ### requiresNodeIdentity?
@@ -80,12 +74,6 @@ true
80
74
 
81
75
  Indicates whether the engine needs the node identity to be set if configured to use.
82
76
 
83
- #### Default
84
-
85
- ```ts
86
- true
87
- ```
88
-
89
77
  ***
90
78
 
91
79
  ### requiresTenantId?
@@ -93,9 +81,3 @@ true
93
81
  > `optional` **requiresTenantId**: `boolean`
94
82
 
95
83
  Indicates whether the engine needs the tenant id to be set if configured to use.
96
-
97
- #### Default
98
-
99
- ```ts
100
- true
101
- ```
@@ -42,12 +42,6 @@ The extended type e.g. hex etc.
42
42
 
43
43
  Whether the param is required.
44
44
 
45
- #### Default
46
-
47
- ```ts
48
- true
49
- ```
50
-
51
45
  ***
52
46
 
53
47
  ### defaultValue?
@@ -924,12 +924,6 @@ Only required for trusted nodes, as regular nodes will not write encrypted data.
924
924
 
925
925
  How often to check for entity updates in minutes.
926
926
 
927
- #### Default
928
-
929
- ```ts
930
- 5
931
- ```
932
-
933
927
  ***
934
928
 
935
929
  ### synchronisedStorageConsolidationIntervalMinutes?
@@ -938,12 +932,6 @@ How often to check for entity updates in minutes.
938
932
 
939
933
  Interval to perform consolidation of changesets, only used if this is a trusted node.
940
934
 
941
- #### Default
942
-
943
- ```ts
944
- 60
945
- ```
946
-
947
935
  ***
948
936
 
949
937
  ### synchronisedStorageConsolidationBatchSize?
@@ -952,12 +940,6 @@ Interval to perform consolidation of changesets, only used if this is a trusted
952
940
 
953
941
  The number of entities to process in a single consolidation batch, only used if this is a trusted node.
954
942
 
955
- #### Default
956
-
957
- ```ts
958
- 1000
959
- ```
960
-
961
943
  ***
962
944
 
963
945
  ### synchronisedStorageMaxConsolidations?
@@ -966,12 +948,6 @@ The number of entities to process in a single consolidation batch, only used if
966
948
 
967
949
  The maximum number of consolidations to keep in storage, only used if this is a trusted node.
968
950
 
969
- #### Default
970
-
971
- ```ts
972
- 5
973
- ```
974
-
975
951
  ***
976
952
 
977
953
  ### federatedCatalogueEnabled?
@@ -1134,12 +1110,6 @@ Is the dataspace enabled, defaults to false.
1134
1110
 
1135
1111
  The length of time to retain the activity logs for in minutes, set to -1 to keep forever.
1136
1112
 
1137
- #### Default
1138
-
1139
- ```ts
1140
- 10
1141
- ```
1142
-
1143
1113
  ***
1144
1114
 
1145
1115
  ### dataspaceActivityLogsCleanUpInterval?
@@ -1148,12 +1118,6 @@ The length of time to retain the activity logs for in minutes, set to -1 to keep
1148
1118
 
1149
1119
  The interval for cleaning up the activity logs.
1150
1120
 
1151
- #### Default
1152
-
1153
- ```ts
1154
- 60
1155
- ```
1156
-
1157
1121
  ***
1158
1122
 
1159
1123
  ### dataspaceDataPlanePath?
@@ -1380,12 +1380,6 @@ Only required for trusted nodes, as regular nodes will not write encrypted data.
1380
1380
 
1381
1381
  How often to check for entity updates in minutes.
1382
1382
 
1383
- #### Default
1384
-
1385
- ```ts
1386
- 5
1387
- ```
1388
-
1389
1383
  #### Inherited from
1390
1384
 
1391
1385
  [`IEngineEnvironmentVariables`](IEngineEnvironmentVariables.md).[`synchronisedStorageEntityUpdateIntervalMinutes`](IEngineEnvironmentVariables.md#synchronisedstorageentityupdateintervalminutes)
@@ -1398,12 +1392,6 @@ How often to check for entity updates in minutes.
1398
1392
 
1399
1393
  Interval to perform consolidation of changesets, only used if this is a trusted node.
1400
1394
 
1401
- #### Default
1402
-
1403
- ```ts
1404
- 60
1405
- ```
1406
-
1407
1395
  #### Inherited from
1408
1396
 
1409
1397
  [`IEngineEnvironmentVariables`](IEngineEnvironmentVariables.md).[`synchronisedStorageConsolidationIntervalMinutes`](IEngineEnvironmentVariables.md#synchronisedstorageconsolidationintervalminutes)
@@ -1416,12 +1404,6 @@ Interval to perform consolidation of changesets, only used if this is a trusted
1416
1404
 
1417
1405
  The number of entities to process in a single consolidation batch, only used if this is a trusted node.
1418
1406
 
1419
- #### Default
1420
-
1421
- ```ts
1422
- 1000
1423
- ```
1424
-
1425
1407
  #### Inherited from
1426
1408
 
1427
1409
  [`IEngineEnvironmentVariables`](IEngineEnvironmentVariables.md).[`synchronisedStorageConsolidationBatchSize`](IEngineEnvironmentVariables.md#synchronisedstorageconsolidationbatchsize)
@@ -1434,12 +1416,6 @@ The number of entities to process in a single consolidation batch, only used if
1434
1416
 
1435
1417
  The maximum number of consolidations to keep in storage, only used if this is a trusted node.
1436
1418
 
1437
- #### Default
1438
-
1439
- ```ts
1440
- 5
1441
- ```
1442
-
1443
1419
  #### Inherited from
1444
1420
 
1445
1421
  [`IEngineEnvironmentVariables`](IEngineEnvironmentVariables.md).[`synchronisedStorageMaxConsolidations`](IEngineEnvironmentVariables.md#synchronisedstoragemaxconsolidations)
@@ -1682,12 +1658,6 @@ Is the dataspace enabled, defaults to false.
1682
1658
 
1683
1659
  The length of time to retain the activity logs for in minutes, set to -1 to keep forever.
1684
1660
 
1685
- #### Default
1686
-
1687
- ```ts
1688
- 10
1689
- ```
1690
-
1691
1661
  #### Inherited from
1692
1662
 
1693
1663
  [`IEngineEnvironmentVariables`](IEngineEnvironmentVariables.md).[`dataspaceRetainActivityLogsFor`](IEngineEnvironmentVariables.md#dataspaceretainactivitylogsfor)
@@ -1700,12 +1670,6 @@ The length of time to retain the activity logs for in minutes, set to -1 to keep
1700
1670
 
1701
1671
  The interval for cleaning up the activity logs.
1702
1672
 
1703
- #### Default
1704
-
1705
- ```ts
1706
- 60
1707
- ```
1708
-
1709
1673
  #### Inherited from
1710
1674
 
1711
1675
  [`IEngineEnvironmentVariables`](IEngineEnvironmentVariables.md).[`dataspaceActivityLogsCleanUpInterval`](IEngineEnvironmentVariables.md#dataspaceactivitylogscleanupinterval)
@@ -1376,12 +1376,6 @@ Only required for trusted nodes, as regular nodes will not write encrypted data.
1376
1376
 
1377
1377
  How often to check for entity updates in minutes.
1378
1378
 
1379
- #### Default
1380
-
1381
- ```ts
1382
- 5
1383
- ```
1384
-
1385
1379
  #### Inherited from
1386
1380
 
1387
1381
  [`IEngineServerEnvironmentVariables`](IEngineServerEnvironmentVariables.md).[`synchronisedStorageEntityUpdateIntervalMinutes`](IEngineServerEnvironmentVariables.md#synchronisedstorageentityupdateintervalminutes)
@@ -1394,12 +1388,6 @@ How often to check for entity updates in minutes.
1394
1388
 
1395
1389
  Interval to perform consolidation of changesets, only used if this is a trusted node.
1396
1390
 
1397
- #### Default
1398
-
1399
- ```ts
1400
- 60
1401
- ```
1402
-
1403
1391
  #### Inherited from
1404
1392
 
1405
1393
  [`IEngineServerEnvironmentVariables`](IEngineServerEnvironmentVariables.md).[`synchronisedStorageConsolidationIntervalMinutes`](IEngineServerEnvironmentVariables.md#synchronisedstorageconsolidationintervalminutes)
@@ -1412,12 +1400,6 @@ Interval to perform consolidation of changesets, only used if this is a trusted
1412
1400
 
1413
1401
  The number of entities to process in a single consolidation batch, only used if this is a trusted node.
1414
1402
 
1415
- #### Default
1416
-
1417
- ```ts
1418
- 1000
1419
- ```
1420
-
1421
1403
  #### Inherited from
1422
1404
 
1423
1405
  [`IEngineServerEnvironmentVariables`](IEngineServerEnvironmentVariables.md).[`synchronisedStorageConsolidationBatchSize`](IEngineServerEnvironmentVariables.md#synchronisedstorageconsolidationbatchsize)
@@ -1430,12 +1412,6 @@ The number of entities to process in a single consolidation batch, only used if
1430
1412
 
1431
1413
  The maximum number of consolidations to keep in storage, only used if this is a trusted node.
1432
1414
 
1433
- #### Default
1434
-
1435
- ```ts
1436
- 5
1437
- ```
1438
-
1439
1415
  #### Inherited from
1440
1416
 
1441
1417
  [`IEngineServerEnvironmentVariables`](IEngineServerEnvironmentVariables.md).[`synchronisedStorageMaxConsolidations`](IEngineServerEnvironmentVariables.md#synchronisedstoragemaxconsolidations)
@@ -1678,12 +1654,6 @@ Is the dataspace enabled, defaults to false.
1678
1654
 
1679
1655
  The length of time to retain the activity logs for in minutes, set to -1 to keep forever.
1680
1656
 
1681
- #### Default
1682
-
1683
- ```ts
1684
- 10
1685
- ```
1686
-
1687
1657
  #### Inherited from
1688
1658
 
1689
1659
  [`IEngineServerEnvironmentVariables`](IEngineServerEnvironmentVariables.md).[`dataspaceRetainActivityLogsFor`](IEngineServerEnvironmentVariables.md#dataspaceretainactivitylogsfor)
@@ -1696,12 +1666,6 @@ The length of time to retain the activity logs for in minutes, set to -1 to keep
1696
1666
 
1697
1667
  The interval for cleaning up the activity logs.
1698
1668
 
1699
- #### Default
1700
-
1701
- ```ts
1702
- 60
1703
- ```
1704
-
1705
1669
  #### Inherited from
1706
1670
 
1707
1671
  [`IEngineServerEnvironmentVariables`](IEngineServerEnvironmentVariables.md).[`dataspaceActivityLogsCleanUpInterval`](IEngineServerEnvironmentVariables.md#dataspaceactivitylogscleanupinterval)
@@ -1909,12 +1873,6 @@ List of properties to obfuscate in the REST logging output, comma separated.
1909
1873
 
1910
1874
  Maximum size in MB for HTTPS extensions downloads.
1911
1875
 
1912
- #### Default
1913
-
1914
- ```ts
1915
- 10
1916
- ```
1917
-
1918
1876
  ***
1919
1877
 
1920
1878
  ### extensionsClearCache?
@@ -1923,12 +1881,6 @@ Maximum size in MB for HTTPS extensions downloads.
1923
1881
 
1924
1882
  Whether to clear the extensions cache on startup.
1925
1883
 
1926
- #### Default
1927
-
1928
- ```ts
1929
- false
1930
- ```
1931
-
1932
1884
  ***
1933
1885
 
1934
1886
  ### extensionsCacheDirectory?
@@ -1937,12 +1889,6 @@ false
1937
1889
 
1938
1890
  Custom directory for extensions cache storage.
1939
1891
 
1940
- #### Default
1941
-
1942
- ```ts
1943
- ".tmp"
1944
- ```
1945
-
1946
1892
  ***
1947
1893
 
1948
1894
  ### extensionsCacheTtlHours?
@@ -1951,12 +1897,6 @@ Custom directory for extensions cache storage.
1951
1897
 
1952
1898
  TTL in hours for HTTPS extensions cache.
1953
1899
 
1954
- #### Default
1955
-
1956
- ```ts
1957
- 24
1958
- ```
1959
-
1960
1900
  ***
1961
1901
 
1962
1902
  ### extensionsForceRefresh?
@@ -1964,9 +1904,3 @@ TTL in hours for HTTPS extensions cache.
1964
1904
  > `optional` **extensionsForceRefresh**: `boolean`
1965
1905
 
1966
1906
  Force refresh of all cached extensions.
1967
-
1968
- #### Default
1969
-
1970
- ```ts
1971
- false
1972
- ```
@@ -10,12 +10,6 @@ The options when running the node.
10
10
 
11
11
  The name of the server, defaults to "TWIN Node".
12
12
 
13
- #### Default
14
-
15
- ```ts
16
- "TWIN Node"
17
- ```
18
-
19
13
  ***
20
14
 
21
15
  ### serverVersion?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/node-core",
3
- "version": "0.0.3-next.27",
3
+ "version": "0.0.3-next.28",
4
4
  "description": "TWIN Node Core for serving APIs using the specified configuration",
5
5
  "repository": {
6
6
  "type": "git",