text: "use strict";
  var __importDefault = (this && this.__importDefault) || function (mod) {
      return (mod && mod.__esModule) ? mod : { "default": mod };
  };
  Object.defineProperty(exports, "__esModule", { value: true });
  exports.SSMClientWrapper = void 0;
  const ora_1 = __importDefault(require("ora"));
  class SSMClientWrapper {
      constructor(ssmClient) {
          this.ssmClient = ssmClient;
          this.getSecrets = async (secretNames) => {
              if (!secretNames || secretNames.length === 0) {
                  return [];
              }
              const result = await this.ssmClient
                  .getParameters({
                  Names: secretNames,
                  WithDecryption: true,
              })
                  .promise();
              return result.Parameters.map(({ Name, Value }) => ({ secretName: Name, secretValue: Value }));
          };
          this.getSecretNamesByPath = async (secretPath) => {
              let NextToken;
              const accumulator = [];
              do {
                  const result = await this.ssmClient
                      .getParametersByPath({
                      Path: secretPath,
                      MaxResults: 10,
                      ParameterFilters: [
                          {
                              Key: 'Type',
                              Option: 'Equals',
                              Values: ['SecureString'],
                          },
                      ],
                      NextToken,
                  })
                      .promise();
                  accumulator.push(...result.Parameters.map(param => param.Name));
                  NextToken = result.NextToken;
              } while (NextToken);
              return accumulator;
          };
          this.setSecret = async (secretName, secretValue) => {
              await this.ssmClient
                  .putParameter({
                  Name: secretName,
                  Value: secretValue,
                  Type: 'SecureString',
                  Overwrite: true,
              })
                  .promise();
          };
          this.deleteSecret = async (secretName) => {
              await this.ssmClient
                  .deleteParameter({
                  Name: secretName,
              })
                  .promise()
                  .catch(err => {
                  if (err.code !== 'ParameterNotFound') {
                      throw err;
                  }
              });
          };
          this.deleteSecrets = async (secretNames) => {
              await this.ssmClient.deleteParameters({ Names: secretNames }).promise();
          };
      }
  }
  exports.SSMClientWrapper = SSMClientWrapper;
  SSMClientWrapper.getInstance = async (context) => {
      if (!SSMClientWrapper.instance) {
          SSMClientWrapper.instance = new SSMClientWrapper(await getSSMClient(context));
      }
      return SSMClientWrapper.instance;
  };
  const getSSMClient = async (context) => {
      const spinner = ora_1.default('Initializing SSM Client');
      try {
          spinner.start();
          const { client } = await context.amplify.invokePluginMethod(context, 'awscloudformation', undefined, 'getConfiguredSSMClient', [
              context,
          ]);
          return client;
      }
      finally {
          spinner.stop();
      }
  };
  //# sourceMappingURL=ssmClientWrapper.js.map