UNPKG

@am92/kms

Version:
31 lines (30 loc) 1.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateKmsInstance = generateKmsInstance; const NodeKms_1 = require("./lib/NodeKms"); const AwsKms_1 = require("./lib/AwsKms"); const CONFIG_1 = require("./CONFIG"); const KmsError_1 = require("./KmsError"); const ERRORS_1 = require("./ERRORS"); /** * Function that returns an instance of {@link NodeKms} or {@link AwsKms} based on the provided `config.TYPE` * * @param config - The configuration object * @returns */ function generateKmsInstance(config) { const { TYPE } = config; switch (TYPE) { case 'AWS': { const kmsConfig = { ...CONFIG_1.KMS_CONFIG, ...config }; return new AwsKms_1.AwsKms(kmsConfig); } case 'NODE': { const kmsConfig = { ...CONFIG_1.KMS_CONFIG, ...config }; return new NodeKms_1.NodeKms(kmsConfig); } default: { throw new KmsError_1.KmsError(config, ERRORS_1.INVALID_CONFIG_ERROR); } } }