{"size": 1493, "ext": "js", "max_stars_repo_path": "serverlessConfig.js", "max_stars_repo_name": "tesseract-collective/user-authentication-service", "max_stars_repo_stars_event_min_datetime": "2020-11-20T21:19:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-20T21:19:53.000Z", "max_issues_repo_path": "serverlessConfig.js", "max_issues_repo_name": "tesseract-collective/user-authentication-service", "max_issues_repo_issues_event_min_datetime": "2020-10-08T02:10:14.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-08T02:20:20.000Z", "max_forks_repo_path": "serverlessConfig.js", "max_forks_repo_name": "tesseract-collective/user-authentication-service", "max_forks_repo_forks_event_min_datetime": "2020-11-20T08:11:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-28T03:57:14.000Z"}
{"max_stars_count": 1, "max_issues_count": 2, "max_forks_count": 2, "avg_line_length": 48.1612903226, "max_line_length": 106, "alphanum_fraction": 0.7796383121}
const { DynamoDbWrapper, SesEmail, SnsSms } = require('@tesseractcollective/serverless-toolbox');

module.exports.config = function (serverless) {
  const configFile = serverless.pluginManager.serverlessConfigFile;
  const cliOptions = serverless.pluginManager.cliOptions;
  const stage = cliOptions.stage || 'dev';
  serverless.cli.consoleLog(`${configFile.service} stage: ${stage}`);

  const generalConfig = {
    region: 'us-east-1',
    passwordTable: `${configFile.service}-${stage}-password`,
    userTable: `${configFile.service}-${stage}-user`,
    cacheTable: `${configFile.service}-${stage}-cache`,
  };
  const iamRoleStatements = {
    passwordTableIamRoleStatements: DynamoDbWrapper.iamRoleStatementForTable(generalConfig.passwordTable),
    cacheTableIamRoleStatements: DynamoDbWrapper.iamRoleStatementForTable(generalConfig.cacheTable),
    userTableIamRoleStatements: DynamoDbWrapper.iamRoleStatementForTable(generalConfig.userTable),
    sesIamRoleStatements: SesEmail.iamRoleStatements(),
    smsIamRoleStatements: SnsSms.iamRoleStatements(),
  };
  const resources = {
    passwordTableResource: DynamoDbWrapper.cloudFormationForTableWithId(generalConfig.passwordTable),
    userTableResource: DynamoDbWrapper.cloudFormationForTableWithId(generalConfig.userTable),
    cacheTableResource: DynamoDbWrapper.cloudFormationForTableWithId(generalConfig.cacheTable, 'expires'),
  };

  const config = { ...generalConfig, ...iamRoleStatements, ...resources };
  return config;
};
