function recursivelyFetchConfig()

in typescript/src/utils/ssmConfig.ts [7:36]


function recursivelyFetchConfig(
  nextToken?: string,
  currentConfig?: Config,
): Promise<Config> {
  const path = `/${App}/${Stage}/${Stack}/`;
  return ssm
    .getParametersByPath({
      Path: path,
      WithDecryption: true,
      NextToken: nextToken,
    })
    .promise()
    .then((result) => {
      const fetchedConfig: Config = {};
      if (result.Parameters) {
        result.Parameters.forEach((param) => {
          if (param.Name) {
            const name = param.Name.replace(path, '');
            fetchedConfig[name] = param.Value;
          }
        });
      }
      const config = Object.assign({}, currentConfig, fetchedConfig);
      if (result.NextToken) {
        return recursivelyFetchConfig(result.NextToken, config);
      } else {
        return Promise.resolve(config);
      }
    });
}