From d2d05a1a8c0e8633a09a3cd93ffd3de33ab2c967 Mon Sep 17 00:00:00 2001 From: kevinwang Date: Sat, 25 Oct 2025 11:35:37 -0400 Subject: [PATCH] feat: Add ability to request codify credentials --- package-lock.json | 13 +++++++------ package.json | 2 +- src/messages/sender.ts | 13 +++++++++++++ src/resource/resource-controller.ts | 22 +++++++++++----------- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/package-lock.json b/package-lock.json index c26c8a2..14b4d05 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "codify-plugin-lib", - "version": "1.0.174", + "version": "1.0.177", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "codify-plugin-lib", - "version": "1.0.174", + "version": "1.0.177", "license": "ISC", "dependencies": { "@homebridge/node-pty-prebuilt-multiarch": "^0.12.0-beta.5", @@ -14,7 +14,7 @@ "ajv": "^8.12.0", "ajv-formats": "^2.1.1", "clean-deep": "^3.4.0", - "codify-schemas": "1.0.76", + "codify-schemas": "1.0.77", "lodash.isequal": "^4.5.0", "nanoid": "^5.0.9", "strip-ansi": "^7.1.0", @@ -2297,9 +2297,10 @@ } }, "node_modules/codify-schemas": { - "version": "1.0.76", - "resolved": "https://registry.npmjs.org/codify-schemas/-/codify-schemas-1.0.76.tgz", - "integrity": "sha512-ZytwEUc2xf6vJ98tZ3K16E4zcmI+80Y25eH1Zl+9nh5V1CoOKTv5xx/FREsfI2mTV0h4LCZL6USzqlOylfXxIg==", + "version": "1.0.77", + "resolved": "https://registry.npmjs.org/codify-schemas/-/codify-schemas-1.0.77.tgz", + "integrity": "sha512-Xv4M/2k9e6pIbrI6NGDeUYsRjBHET45x0ygBxhpgLcIgGGeNnWVi5/Mh1mTn+TOwGmrAw3bTRsQCpDLmtfJeGA==", + "license": "ISC", "dependencies": { "ajv": "^8.12.0" } diff --git a/package.json b/package.json index 43d689f..912667a 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "dependencies": { "ajv": "^8.12.0", "ajv-formats": "^2.1.1", - "codify-schemas": "1.0.76", + "codify-schemas": "1.0.77", "@npmcli/promise-spawn": "^7.0.1", "@homebridge/node-pty-prebuilt-multiarch": "^0.12.0-beta.5", "uuid": "^10.0.0", diff --git a/src/messages/sender.ts b/src/messages/sender.ts index 9923b10..1d0629c 100644 --- a/src/messages/sender.ts +++ b/src/messages/sender.ts @@ -21,6 +21,19 @@ class CodifyCliSenderImpl { }) } + async getCodifyCliCredentials(): Promise { + const data = await this.sendAndWaitForResponse({ + cmd: MessageCmd.CODIFY_CREDENTIALS_REQUEST, + data: {}, + }) + + if (typeof data.data !== 'string') { + throw new Error('Expected string back from credentials request'); + } + + return data.data; + } + private async sendAndWaitForResponse(message: IpcMessageV2): Promise { return new Promise((resolve) => { const requestId = nanoid(8); diff --git a/src/resource/resource-controller.ts b/src/resource/resource-controller.ts index 949eed5..e8c3ed9 100644 --- a/src/resource/resource-controller.ts +++ b/src/resource/resource-controller.ts @@ -59,7 +59,7 @@ export class ResourceController { parameters: Partial, ): Promise { const originalParameters = structuredClone(parameters); - await this.applyTransformParameters(parameters); + await this.applyTransformations(parameters, undefined, true); this.addDefaultValues(parameters); if (this.schemaValidator) { @@ -143,10 +143,10 @@ export class ResourceController { const paramsToMatch = structuredClone(resourceToMatch.parameters) as Partial; this.addDefaultValues(originalParams); - await this.applyTransformParameters(originalParams); + await this.applyTransformations(originalParams); this.addDefaultValues(paramsToMatch); - await this.applyTransformParameters(paramsToMatch); + await this.applyTransformations(paramsToMatch); const match = parameterMatcher(originalParams, paramsToMatch); if (match) { @@ -170,10 +170,10 @@ export class ResourceController { }; this.addDefaultValues(desired); - await this.applyTransformParameters(desired); + await this.applyTransformations(desired); this.addDefaultValues(state); - await this.applyTransformParameters(state); + await this.applyTransformations(state); // Parse data from the user supplied config const parsedConfig = new ConfigParser(desired, state, this.parsedSettings.statefulParameters) @@ -221,7 +221,7 @@ export class ResourceController { parameters: Partial ): Promise> { this.addDefaultValues(parameters); - await this.applyTransformParameters(parameters); + await this.applyTransformations(parameters); // Use refresh parameters if specified, otherwise try to refresh as many parameters as possible here const parametersToRefresh = this.settings.importAndDestroy?.refreshKeys @@ -298,7 +298,7 @@ export class ResourceController { } this.addDefaultValues(parameters); - await this.applyTransformParameters(parameters); + await this.applyTransformations(parameters); // Use refresh parameters if specified, otherwise try to refresh as many parameters as possible here const parametersToRefresh = this.getParametersToRefreshForImport(parameters, context); @@ -325,7 +325,7 @@ export class ResourceController { ?.map((r, idx) => ({ ...r, ...statefulCurrentParameters[idx] })) for (const result of resultParametersArray) { - await this.applyTransformParameters(result, { original: context.originalDesiredConfig }); + await this.applyTransformations(result, { original: context.originalDesiredConfig }); this.removeDefaultValues(result, parameters); } @@ -408,9 +408,9 @@ ${JSON.stringify(refresh, null, 2)} } } - private async applyTransformParameters(config: Partial | null, reverse?: { + private async applyTransformations(config: Partial | null, reverse?: { original: Partial | null - }): Promise { + }, skipConfigTransformation = false): Promise { if (!config) { return; } @@ -425,7 +425,7 @@ ${JSON.stringify(refresh, null, 2)} : await inputTransformation.to(config[key]); } - if (this.settings.transformation) { + if (this.settings.transformation && !skipConfigTransformation) { const transformed = reverse ? await this.settings.transformation.from({ ...config }, reverse.original) : await this.settings.transformation.to({ ...config })