Skip to content

Commit 9d75f00

Browse files
refactor(import): simplify app config decrypt guard in updateAppsConfig
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent c671cf2 commit 9d75f00

1 file changed

Lines changed: 22 additions & 32 deletions

File tree

‎packages/contentstack-import/src/import/modules/marketplace-apps.ts‎

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -697,26 +697,14 @@ export default class ImportMarketplaceApps extends BaseClass {
697697

698698
if (!isEmpty(configuration)) {
699699
log.debug(`Updating app configuration for: ${appName}`, this.importConfig.context);
700-
// NOTE: decrypt synchronously in a guard. A bad-decrypt (e.g. ERR_OSSL_BAD_DECRYPT when the
701-
// export was encrypted with a different key) would otherwise throw here — outside the promise
702-
// chain's .catch — abort the whole marketplace-apps module, and skip writing the
703-
// marketplace_apps uid-mapping, which starves the downstream GF/CT/entry extension remap.
704-
// Instead: warn and skip only this app's configuration; the app stays installed and its
705-
// extension mappings are still recorded.
706-
let decryptedConfiguration: any;
700+
// NOTE: decrypt inside the try. A bad-decrypt (e.g. ERR_OSSL_BAD_DECRYPT when the export was
701+
// encrypted with a different key) would otherwise throw — outside the promise chain's .catch —
702+
// and abort the whole marketplace-apps module before the marketplace_apps uid-mapping is
703+
// written, which starves the downstream GF/CT/entry extension remap. We warn and skip only
704+
// this app's configuration; the app stays installed and its extension mappings are preserved.
705+
// (Skip, not return — the server_configuration block below is independent and must still run.)
707706
try {
708-
decryptedConfiguration = this.nodeCrypto.decrypt(configuration);
709-
} catch (error: any) {
710-
log.warn(
711-
`Failed to decrypt configuration for '${appName}'; skipping its configuration update. The app is installed and its extension mappings are preserved. (${
712-
error?.message || error
713-
})`,
714-
this.importConfig.context,
715-
);
716-
decryptedConfiguration = undefined;
717-
}
718-
719-
if (decryptedConfiguration !== undefined) {
707+
const decryptedConfiguration = this.nodeCrypto.decrypt(configuration);
720708
await this.appSdk
721709
.marketplace(this.importConfig.org_uid)
722710
.installation(installation_uid)
@@ -735,27 +723,22 @@ export default class ImportMarketplaceApps extends BaseClass {
735723
log.error(formatError(error), this.importConfig.context);
736724
log.debug(`Configuration update failed for: ${appName}`, this.importConfig.context);
737725
});
738-
}
739-
}
740-
741-
if (!isEmpty(server_configuration)) {
742-
log.debug(`Updating server configuration for: ${appName}`, this.importConfig.context);
743-
// NOTE: guard the decrypt for the same reason as `configuration` above — a bad-decrypt must
744-
// not abort the module or skip the uid-mapping write.
745-
let decryptedServerConfiguration: any;
746-
try {
747-
decryptedServerConfiguration = this.nodeCrypto.decrypt(server_configuration);
748726
} catch (error: any) {
749727
log.warn(
750-
`Failed to decrypt server configuration for '${appName}'; skipping its server configuration update. The app is installed and its extension mappings are preserved. (${
728+
`Failed to decrypt configuration for '${appName}'; skipping its configuration update. The app is installed and its extension mappings are preserved. (${
751729
error?.message || error
752730
})`,
753731
this.importConfig.context,
754732
);
755-
decryptedServerConfiguration = undefined;
756733
}
734+
}
757735

758-
if (decryptedServerConfiguration !== undefined) {
736+
if (!isEmpty(server_configuration)) {
737+
log.debug(`Updating server configuration for: ${appName}`, this.importConfig.context);
738+
// Same rationale as `configuration` above — a bad-decrypt must not abort the module or skip
739+
// the uid-mapping write.
740+
try {
741+
const decryptedServerConfiguration = this.nodeCrypto.decrypt(server_configuration);
759742
await this.appSdk
760743
.marketplace(this.importConfig.org_uid)
761744
.installation(installation_uid)
@@ -774,6 +757,13 @@ export default class ImportMarketplaceApps extends BaseClass {
774757
log.error(formatError(error), this.importConfig.context);
775758
log.debug(`Server configuration update failed for: ${appName}`, this.importConfig.context);
776759
});
760+
} catch (error: any) {
761+
log.warn(
762+
`Failed to decrypt server configuration for '${appName}'; skipping its server configuration update. The app is installed and its extension mappings are preserved. (${
763+
error?.message || error
764+
})`,
765+
this.importConfig.context,
766+
);
777767
}
778768
}
779769
}

0 commit comments

Comments
 (0)