"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.createAdminAppConfig = exports.configureAdminCognitoUserPoolDomain = void 0;
var _createReactAppConfig = require("./createReactAppConfig");
const createAdminAppConfig = modifier => {
  return (0, _createReactAppConfig.createReactAppConfig)(baseParams => {
    const {
      config,
      options
    } = baseParams;
    config.customEnv(env => ({
      ...env,
      PORT: process.env.PORT || 3001,
      WEBINY_ADMIN_ENV: options.env,
      WEBINY_ADMIN_TRASH_BIN_RETENTION_PERIOD_DAYS: process.env.WEBINY_TRASH_BIN_RETENTION_PERIOD_DAYS
    }));
    config.pulumiOutputToEnv("apps/api", ({
      output,
      env
    }) => {
      if (!output) {
        return env;
      }
      return {
        ...env,
        REACT_APP_USER_POOL_REGION: output.region,
        REACT_APP_GRAPHQL_API_URL: `${output.apiUrl}/graphql`,
        REACT_APP_API_URL: output.apiUrl,
        REACT_APP_USER_POOL_ID: output.cognitoUserPoolId,
        REACT_APP_USER_POOL_WEB_CLIENT_ID: output.cognitoAppClientId,
        REACT_APP_USER_POOL_PASSWORD_POLICY: JSON.stringify(output.cognitoUserPoolPasswordPolicy),
        REACT_APP_WEBSOCKET_URL: output.websocketApiUrl
      };
    });
    if (modifier) {
      modifier(baseParams);
    }
  });
};

/**
 * Inject REACT_APP_USER_POOL_DOMAIN from the `core` app output into the `admin` app bundle.
 * The Cognito user pool domain is taken from the `cognitoUserPoolDomain` Pulumi app output.
 */
exports.createAdminAppConfig = createAdminAppConfig;
const configureAdminCognitoUserPoolDomain = modifier => {
  modifier.config.pulumiOutputToEnv("apps/core", ({
    env,
    output
  }) => {
    return {
      ...env,
      REACT_APP_USER_POOL_DOMAIN: output["cognitoUserPoolDomain"]
    };
  });
};
exports.configureAdminCognitoUserPoolDomain = configureAdminCognitoUserPoolDomain;

//# sourceMappingURL=createAdminAppConfig.js.map