123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.ProjectConfig = void 0;
- const validator = require("../utils/validator");
- const error_1 = require("../utils/error");
- const auth_config_1 = require("./auth-config");
- const deep_copy_1 = require("../utils/deep-copy");
- class ProjectConfig {
-
- get multiFactorConfig() {
- return this.multiFactorConfig_;
- }
-
- static validate(request) {
- if (!validator.isNonNullObject(request)) {
- throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, '"UpdateProjectConfigRequest" must be a valid non-null object.');
- }
- const validKeys = {
- smsRegionConfig: true,
- multiFactorConfig: true,
- recaptchaConfig: true,
- passwordPolicyConfig: true,
- emailPrivacyConfig: true,
- };
-
- for (const key in request) {
- if (!(key in validKeys)) {
- throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, `"${key}" is not a valid UpdateProjectConfigRequest parameter.`);
- }
- }
-
- if (typeof request.smsRegionConfig !== 'undefined') {
- auth_config_1.SmsRegionsAuthConfig.validate(request.smsRegionConfig);
- }
-
- if (typeof request.multiFactorConfig !== 'undefined') {
- auth_config_1.MultiFactorAuthConfig.validate(request.multiFactorConfig);
- }
-
- if (typeof request.recaptchaConfig !== 'undefined') {
- auth_config_1.RecaptchaAuthConfig.validate(request.recaptchaConfig);
- }
-
- if (typeof request.passwordPolicyConfig !== 'undefined') {
- auth_config_1.PasswordPolicyAuthConfig.validate(request.passwordPolicyConfig);
- }
-
- if (typeof request.emailPrivacyConfig !== 'undefined') {
- auth_config_1.EmailPrivacyAuthConfig.validate(request.emailPrivacyConfig);
- }
- }
-
- static buildServerRequest(configOptions) {
- ProjectConfig.validate(configOptions);
- const request = {};
- if (typeof configOptions.smsRegionConfig !== 'undefined') {
- request.smsRegionConfig = configOptions.smsRegionConfig;
- }
- if (typeof configOptions.multiFactorConfig !== 'undefined') {
- request.mfa = auth_config_1.MultiFactorAuthConfig.buildServerRequest(configOptions.multiFactorConfig);
- }
- if (typeof configOptions.recaptchaConfig !== 'undefined') {
- request.recaptchaConfig = configOptions.recaptchaConfig;
- }
- if (typeof configOptions.passwordPolicyConfig !== 'undefined') {
- request.passwordPolicyConfig = auth_config_1.PasswordPolicyAuthConfig.buildServerRequest(configOptions.passwordPolicyConfig);
- }
- if (typeof configOptions.emailPrivacyConfig !== 'undefined') {
- request.emailPrivacyConfig = configOptions.emailPrivacyConfig;
- }
- return request;
- }
-
- get recaptchaConfig() {
- return this.recaptchaConfig_;
- }
-
- constructor(response) {
- if (typeof response.smsRegionConfig !== 'undefined') {
- this.smsRegionConfig = response.smsRegionConfig;
- }
-
-
- if (typeof response.mfa !== 'undefined') {
- this.multiFactorConfig_ = new auth_config_1.MultiFactorAuthConfig(response.mfa);
- }
- if (typeof response.recaptchaConfig !== 'undefined') {
- this.recaptchaConfig_ = new auth_config_1.RecaptchaAuthConfig(response.recaptchaConfig);
- }
- if (typeof response.passwordPolicyConfig !== 'undefined') {
- this.passwordPolicyConfig = new auth_config_1.PasswordPolicyAuthConfig(response.passwordPolicyConfig);
- }
- if (typeof response.emailPrivacyConfig !== 'undefined') {
- this.emailPrivacyConfig = response.emailPrivacyConfig;
- }
- }
-
- toJSON() {
-
- const json = {
- smsRegionConfig: (0, deep_copy_1.deepCopy)(this.smsRegionConfig),
- multiFactorConfig: (0, deep_copy_1.deepCopy)(this.multiFactorConfig),
- recaptchaConfig: this.recaptchaConfig_?.toJSON(),
- passwordPolicyConfig: (0, deep_copy_1.deepCopy)(this.passwordPolicyConfig),
- emailPrivacyConfig: (0, deep_copy_1.deepCopy)(this.emailPrivacyConfig),
- };
- if (typeof json.smsRegionConfig === 'undefined') {
- delete json.smsRegionConfig;
- }
- if (typeof json.multiFactorConfig === 'undefined') {
- delete json.multiFactorConfig;
- }
- if (typeof json.recaptchaConfig === 'undefined') {
- delete json.recaptchaConfig;
- }
- if (typeof json.passwordPolicyConfig === 'undefined') {
- delete json.passwordPolicyConfig;
- }
- if (typeof json.emailPrivacyConfig === 'undefined') {
- delete json.emailPrivacyConfig;
- }
- return json;
- }
- }
- exports.ProjectConfig = ProjectConfig;
|