1 |
|
2 | "use strict";
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | exports.ProjectConfig = void 0;
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | const validator = require("../utils/validator");
|
21 | const error_1 = require("../utils/error");
|
22 | const auth_config_1 = require("./auth-config");
|
23 | const deep_copy_1 = require("../utils/deep-copy");
|
24 |
|
25 |
|
26 |
|
27 | class ProjectConfig {
|
28 | |
29 |
|
30 |
|
31 | get multiFactorConfig() {
|
32 | return this.multiFactorConfig_;
|
33 | }
|
34 | |
35 |
|
36 |
|
37 |
|
38 |
|
39 | static validate(request) {
|
40 | if (!validator.isNonNullObject(request)) {
|
41 | throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, '"UpdateProjectConfigRequest" must be a valid non-null object.');
|
42 | }
|
43 | const validKeys = {
|
44 | smsRegionConfig: true,
|
45 | multiFactorConfig: true,
|
46 | recaptchaConfig: true,
|
47 | passwordPolicyConfig: true,
|
48 | emailPrivacyConfig: true,
|
49 | };
|
50 |
|
51 | for (const key in request) {
|
52 | if (!(key in validKeys)) {
|
53 | throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, `"${key}" is not a valid UpdateProjectConfigRequest parameter.`);
|
54 | }
|
55 | }
|
56 |
|
57 | if (typeof request.smsRegionConfig !== 'undefined') {
|
58 | auth_config_1.SmsRegionsAuthConfig.validate(request.smsRegionConfig);
|
59 | }
|
60 |
|
61 | if (typeof request.multiFactorConfig !== 'undefined') {
|
62 | auth_config_1.MultiFactorAuthConfig.validate(request.multiFactorConfig);
|
63 | }
|
64 |
|
65 | if (typeof request.recaptchaConfig !== 'undefined') {
|
66 | auth_config_1.RecaptchaAuthConfig.validate(request.recaptchaConfig);
|
67 | }
|
68 |
|
69 | if (typeof request.passwordPolicyConfig !== 'undefined') {
|
70 | auth_config_1.PasswordPolicyAuthConfig.validate(request.passwordPolicyConfig);
|
71 | }
|
72 |
|
73 | if (typeof request.emailPrivacyConfig !== 'undefined') {
|
74 | auth_config_1.EmailPrivacyAuthConfig.validate(request.emailPrivacyConfig);
|
75 | }
|
76 | }
|
77 | |
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | static buildServerRequest(configOptions) {
|
85 | ProjectConfig.validate(configOptions);
|
86 | const request = {};
|
87 | if (typeof configOptions.smsRegionConfig !== 'undefined') {
|
88 | request.smsRegionConfig = configOptions.smsRegionConfig;
|
89 | }
|
90 | if (typeof configOptions.multiFactorConfig !== 'undefined') {
|
91 | request.mfa = auth_config_1.MultiFactorAuthConfig.buildServerRequest(configOptions.multiFactorConfig);
|
92 | }
|
93 | if (typeof configOptions.recaptchaConfig !== 'undefined') {
|
94 | request.recaptchaConfig = configOptions.recaptchaConfig;
|
95 | }
|
96 | if (typeof configOptions.passwordPolicyConfig !== 'undefined') {
|
97 | request.passwordPolicyConfig = auth_config_1.PasswordPolicyAuthConfig.buildServerRequest(configOptions.passwordPolicyConfig);
|
98 | }
|
99 | if (typeof configOptions.emailPrivacyConfig !== 'undefined') {
|
100 | request.emailPrivacyConfig = configOptions.emailPrivacyConfig;
|
101 | }
|
102 | return request;
|
103 | }
|
104 | |
105 |
|
106 |
|
107 | get recaptchaConfig() {
|
108 | return this.recaptchaConfig_;
|
109 | }
|
110 | |
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 | constructor(response) {
|
118 | if (typeof response.smsRegionConfig !== 'undefined') {
|
119 | this.smsRegionConfig = response.smsRegionConfig;
|
120 | }
|
121 |
|
122 |
|
123 | if (typeof response.mfa !== 'undefined') {
|
124 | this.multiFactorConfig_ = new auth_config_1.MultiFactorAuthConfig(response.mfa);
|
125 | }
|
126 | if (typeof response.recaptchaConfig !== 'undefined') {
|
127 | this.recaptchaConfig_ = new auth_config_1.RecaptchaAuthConfig(response.recaptchaConfig);
|
128 | }
|
129 | if (typeof response.passwordPolicyConfig !== 'undefined') {
|
130 | this.passwordPolicyConfig = new auth_config_1.PasswordPolicyAuthConfig(response.passwordPolicyConfig);
|
131 | }
|
132 | if (typeof response.emailPrivacyConfig !== 'undefined') {
|
133 | this.emailPrivacyConfig = response.emailPrivacyConfig;
|
134 | }
|
135 | }
|
136 | |
137 |
|
138 |
|
139 |
|
140 |
|
141 | toJSON() {
|
142 |
|
143 | const json = {
|
144 | smsRegionConfig: (0, deep_copy_1.deepCopy)(this.smsRegionConfig),
|
145 | multiFactorConfig: (0, deep_copy_1.deepCopy)(this.multiFactorConfig),
|
146 | recaptchaConfig: this.recaptchaConfig_?.toJSON(),
|
147 | passwordPolicyConfig: (0, deep_copy_1.deepCopy)(this.passwordPolicyConfig),
|
148 | emailPrivacyConfig: (0, deep_copy_1.deepCopy)(this.emailPrivacyConfig),
|
149 | };
|
150 | if (typeof json.smsRegionConfig === 'undefined') {
|
151 | delete json.smsRegionConfig;
|
152 | }
|
153 | if (typeof json.multiFactorConfig === 'undefined') {
|
154 | delete json.multiFactorConfig;
|
155 | }
|
156 | if (typeof json.recaptchaConfig === 'undefined') {
|
157 | delete json.recaptchaConfig;
|
158 | }
|
159 | if (typeof json.passwordPolicyConfig === 'undefined') {
|
160 | delete json.passwordPolicyConfig;
|
161 | }
|
162 | if (typeof json.emailPrivacyConfig === 'undefined') {
|
163 | delete json.emailPrivacyConfig;
|
164 | }
|
165 | return json;
|
166 | }
|
167 | }
|
168 | exports.ProjectConfig = ProjectConfig;
|