fiber-firebase-functions 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,317 +0,0 @@
1
- /*
2
- * Copyright (C) 2025 Fiber
3
- *
4
- * All rights reserved. This script, including its code and logic, is the
5
- * exclusive property of Fiber. Redistribution, reproduction,
6
- * or modification of any part of this script is strictly prohibited
7
- * without prior written permission from Fiber.
8
- *
9
- * Conditions of use:
10
- * - The code may not be copied, duplicated, or used, in whole or in part,
11
- * for any purpose without explicit authorization.
12
- * - Redistribution of this code, with or without modification, is not
13
- * permitted unless expressly agreed upon by Fiber.
14
- * - The name "Fiber" and any associated branding, logos, or
15
- * trademarks may not be used to endorse or promote derived products
16
- * or services without prior written approval.
17
- *
18
- * Disclaimer:
19
- * THIS SCRIPT AND ITS CODE ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
20
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
21
- * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL
22
- * FIBER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO LOSS OF USE,
24
- * DATA, PROFITS, OR BUSINESS INTERRUPTION) ARISING OUT OF OR RELATED TO THE USE
25
- * OR INABILITY TO USE THIS SCRIPT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
- *
27
- * Unauthorized copying or reproduction of this script, in whole or in part,
28
- * is a violation of applicable intellectual property laws and will result
29
- * in legal action.
30
- */
31
-
32
- import * as admin from "firebase-admin";
33
- import validator from "validator";
34
- import { appInitialize } from "../common/config";
35
- import { isRateLimited, RateLimitCheckStatus, RateLimitIdentifier, RateLimitRule, recordRateLimitHit } from "../middleware/rate_limiter";
36
- import { IsUserDisabled, UserDisabledByIdStatus } from "./is_user_disabled";
37
- import { IsUserExists, UserExistsByIdStatus } from "./is_user_exists";
38
- import { Otp } from "./otp";
39
- import { User, UserByEmailStatus } from "./user";
40
-
41
- if (admin.apps.length === 0) {
42
- admin.initializeApp();
43
- }
44
-
45
- export enum ResetPasswordByEmailStatus {
46
- MISSING_DATABASE_CONFIG = "MISSING_DATABASE_CONFIG",
47
- MISSING_USER_EMAIL = "MISSING_USER_EMAIL",
48
- MISSING_NEW_PASSWORD = "MISSING_NEW_PASSWORD",
49
- MISSING_CONFIRM_NEW_PASSWORD = "MISSING_CONFIRM_NEW_PASSWORD",
50
- MISSING_PASSWORD_POLICY = "MISSING_PASSWORD_POLICY",
51
- NOT_IDENTICAL_CONFIRM_PASSWORD = "NOT_IDENTICAL_CONFIRM_PASSWORD",
52
- USER_NOT_FOUND = "USER_NOT_FOUND",
53
- USER_DISABLED = "USER_DISABLED",
54
- WEAK_NEW_PASSWORD = "WEAK_NEW_PASSWORD",
55
- MISSING_PASSWORD_UPPERCASE = "MISSING_PASSWORD_UPPERCASE",
56
- MISSING_PASSWORD_LOWERCASE = "MISSING_PASSWORD_LOWERCASE",
57
- MISSING_PASSWORD_DIGIT = "MISSING_PASSWORD_DIGIT",
58
- MISSING_PASSWORD_SPECIAL_CHAR = "MISSING_PASSWORD_SPECIAL_CHAR",
59
- TOO_MANY_REQUEST = "TOO_MANY_REQUEST",
60
- INVALID_EMAIL_FORMAT = "INVALID_EMAIL_FORMAT",
61
- SUCCESS = "SUCCESS",
62
- INTERNAL_ERROR = "INTERNAL_ERROR",
63
- }
64
-
65
- export enum ResetPasswordByIdStatus {
66
- MISSING_DATABASE_CONFIG = "MISSING_DATABASE_CONFIG",
67
- MISSING_USER_ID = "MISSING_USER_ID",
68
- MISSING_NEW_PASSWORD = "MISSING_NEW_PASSWORD",
69
- MISSING_CONFIRM_NEW_PASSWORD = "MISSING_CONFIRM_NEW_PASSWORD",
70
- MISSING_PASSWORD_POLICY = "MISSING_PASSWORD_POLICY",
71
- NOT_IDENTICAL_CONFIRM_PASSWORD = "NOT_IDENTICAL_CONFIRM_PASSWORD",
72
- USER_NOT_FOUND = "USER_NOT_FOUND",
73
- USER_DISABLED = "USER_DISABLED",
74
- WEAK_NEW_PASSWORD = "WEAK_NEW_PASSWORD",
75
- MISSING_PASSWORD_UPPERCASE = "MISSING_PASSWORD_UPPERCASE",
76
- MISSING_PASSWORD_LOWERCASE = "MISSING_PASSWORD_LOWERCASE",
77
- MISSING_PASSWORD_DIGIT = "MISSING_PASSWORD_DIGIT",
78
- MISSING_PASSWORD_SPECIAL_CHAR = "MISSING_PASSWORD_SPECIAL_CHAR",
79
- TOO_MANY_REQUEST = "TOO_MANY_REQUEST",
80
- SUCCESS = "SUCCESS",
81
- INTERNAL_ERROR = "INTERNAL_ERROR",
82
- }
83
-
84
- export enum RequestResetPasswordByIdStatus {
85
- MISSING_OTP_CONFIG = "MISSING_OTP_CONFIG",
86
- MISSING_DATABASE_CONFIG = "MISSING_DATABASE_CONFIG",
87
- MISSING_USER_ID = "MISSING_USER_ID",
88
- TOO_MANY_REQUEST = "TOO_MANY_REQUEST",
89
- USER_NOT_FOUND = "USER_NOT_FOUND",
90
- USER_DISABLED = "USER_DISABLED",
91
- SUCCESS = "SUCCESS",
92
- INTERNAL_ERROR = "INTERNAL_ERROR",
93
- }
94
-
95
- export enum RequestResetPasswordByEmailStatus {
96
- MISSING_OTP_CONFIG = "MISSING_OTP_CONFIG",
97
- MISSING_DATABASE_CONFIG = "MISSING_DATABASE_CONFIG",
98
- MISSING_USER_EMAIL = "MISSING_USER_EMAIL",
99
- TOO_MANY_REQUEST = "TOO_MANY_REQUEST",
100
- USER_NOT_FOUND = "USER_NOT_FOUND",
101
- USER_DISABLED = "USER_DISABLED",
102
- INVALID_EMAIL_FORMAT = "INVALID_EMAIL_FORMAT",
103
- SUCCESS = "SUCCESS",
104
- INTERNAL_ERROR = "INTERNAL_ERROR",
105
- }
106
-
107
- export interface PasswordPolicy {
108
- minLength: number;
109
- requireUppercase: boolean;
110
- requireLowercase: boolean;
111
- requireDigit: boolean;
112
- requireSpecial: boolean;
113
- }
114
-
115
- export interface ResetPassword {
116
- newPassword: string;
117
- confirmNewPassword: string;
118
- passwordPolicy: PasswordPolicy;
119
- }
120
-
121
- export class RequestResetPassword {
122
- static async withId(userId: string): Promise<RequestResetPasswordByIdStatus> {
123
- const config = appInitialize();
124
- const otp = config.otp;
125
- const rateLimiter = config.rateLimiter;
126
-
127
- if (otp.collection === undefined) return RequestResetPasswordByIdStatus.MISSING_OTP_CONFIG;
128
- if (rateLimiter.appName === undefined || rateLimiter.url === undefined) {
129
- return RequestResetPasswordByIdStatus.MISSING_DATABASE_CONFIG;
130
- }
131
-
132
- userId = userId.trim();
133
- if (!userId || userId === "") return RequestResetPasswordByIdStatus.MISSING_USER_ID;
134
-
135
- const identifier: RateLimitIdentifier = {
136
- id: userId,
137
- target: "request_reset_password"
138
- };
139
-
140
- const rule: RateLimitRule = {
141
- ttl: 2 * 60 * 1000,
142
- windowMs: 3 * 60 * 1000,
143
- maxHits: 5,
144
- };
145
-
146
- const userExists = await IsUserExists.withId(userId);
147
- if (userExists === UserExistsByIdStatus.MISSING_USER_ID) return RequestResetPasswordByIdStatus.MISSING_USER_ID;
148
- if (userExists === UserExistsByIdStatus.INTERNAL_ERROR) return RequestResetPasswordByIdStatus.INTERNAL_ERROR;
149
- if (userExists === UserExistsByIdStatus.USER_NOT_FOUND) return RequestResetPasswordByIdStatus.USER_NOT_FOUND;
150
-
151
- const userDisabled = await IsUserDisabled.withId(userId);
152
- if (userDisabled === UserDisabledByIdStatus.MISSING_USER_ID) {
153
- return RequestResetPasswordByIdStatus.MISSING_USER_ID;
154
- }
155
- if (userDisabled === UserDisabledByIdStatus.INTERNAL_ERROR) {
156
- return RequestResetPasswordByIdStatus.INTERNAL_ERROR;
157
- }
158
- if (userDisabled === UserDisabledByIdStatus.USER_NOT_FOUND) {
159
- return RequestResetPasswordByIdStatus.USER_NOT_FOUND;
160
- }
161
-
162
- if (await isRateLimited(identifier, rule) !== RateLimitCheckStatus.LIMIT_NOT_FOUND) {
163
- return RequestResetPasswordByIdStatus.TOO_MANY_REQUEST;
164
- }
165
- await recordRateLimitHit(identifier, rule);
166
-
167
- if (await IsUserExists.withId(userId)) return RequestResetPasswordByIdStatus.USER_NOT_FOUND;
168
- if (await IsUserDisabled.withId(userId)) return RequestResetPasswordByIdStatus.USER_DISABLED;
169
-
170
- await Otp.generate(userId, "request_reset_password");
171
-
172
- return RequestResetPasswordByIdStatus.SUCCESS;
173
- }
174
-
175
- static async withEmail(email: string): Promise<RequestResetPasswordByEmailStatus> {
176
- email = email.trim();
177
- if (!email || email === "") return RequestResetPasswordByEmailStatus.MISSING_USER_EMAIL;
178
-
179
- if (!validator.isEmail(email)) return RequestResetPasswordByEmailStatus.INVALID_EMAIL_FORMAT;
180
-
181
- const user = await User.withEmail(email);
182
- if (user.status === UserByEmailStatus.INTERNAL_ERROR) return RequestResetPasswordByEmailStatus.INTERNAL_ERROR;
183
- if (user.status === UserByEmailStatus.MISSING_EMAIL) {
184
- return RequestResetPasswordByEmailStatus.MISSING_USER_EMAIL;
185
- }
186
- if (user.status === UserByEmailStatus.USER_NOT_FOUND) return RequestResetPasswordByEmailStatus.USER_NOT_FOUND;
187
-
188
- const userId = user.user?.uid;
189
- if (!userId || userId === undefined) return RequestResetPasswordByEmailStatus.INTERNAL_ERROR;
190
-
191
- const result = await this.withId(userId);
192
-
193
- const map = {
194
- [RequestResetPasswordByIdStatus.MISSING_OTP_CONFIG]: RequestResetPasswordByEmailStatus.MISSING_OTP_CONFIG,
195
- [RequestResetPasswordByIdStatus.MISSING_DATABASE_CONFIG]: RequestResetPasswordByEmailStatus.MISSING_DATABASE_CONFIG,
196
- [RequestResetPasswordByIdStatus.MISSING_USER_ID]: RequestResetPasswordByEmailStatus.MISSING_USER_EMAIL,
197
- [RequestResetPasswordByIdStatus.TOO_MANY_REQUEST]: RequestResetPasswordByEmailStatus.TOO_MANY_REQUEST,
198
- [RequestResetPasswordByIdStatus.USER_NOT_FOUND]: RequestResetPasswordByEmailStatus.USER_NOT_FOUND,
199
- [RequestResetPasswordByIdStatus.USER_DISABLED]: RequestResetPasswordByEmailStatus.USER_DISABLED,
200
- [RequestResetPasswordByIdStatus.SUCCESS]: RequestResetPasswordByEmailStatus.SUCCESS,
201
- [RequestResetPasswordByIdStatus.INTERNAL_ERROR]: RequestResetPasswordByEmailStatus.INTERNAL_ERROR,
202
- };
203
-
204
- return map[result];
205
- }
206
- }
207
-
208
- export class VerifyRequestResetPasswordOTP {
209
-
210
- }
211
-
212
- export class ResetPassword {
213
- static async withId(userId: string, password: ResetPassword): Promise<ResetPasswordByIdStatus> {
214
- const config = appInitialize();
215
- const rateLimiter = config.rateLimiter;
216
-
217
- if (rateLimiter.appName === undefined || rateLimiter.url === undefined) {
218
- return ResetPasswordByIdStatus.MISSING_DATABASE_CONFIG;
219
- }
220
-
221
- userId = userId.trim();
222
-
223
- if (!userId || userId === "") return ResetPasswordByIdStatus.MISSING_USER_ID;
224
-
225
- const newPassword = password.newPassword.trim();
226
- const confirmNewPassword = password.confirmNewPassword.trim();
227
-
228
- if (!newPassword || newPassword === "") return ResetPasswordByIdStatus.MISSING_NEW_PASSWORD;
229
- if (!confirmNewPassword || confirmNewPassword === "") return ResetPasswordByIdStatus.MISSING_CONFIRM_NEW_PASSWORD;
230
-
231
- const passwordPolicy = password.passwordPolicy;
232
-
233
- if (!passwordPolicy) return ResetPasswordByIdStatus.MISSING_PASSWORD_POLICY;
234
-
235
- const identifier: RateLimitIdentifier = {
236
- id: userId,
237
- target: "reset_password"
238
- };
239
-
240
- const rule: RateLimitRule = {
241
- ttl: 2 * 60 * 1000,
242
- windowMs: 3 * 60 * 1000,
243
- maxHits: 5,
244
- };
245
-
246
- if (await isRateLimited(identifier, rule) !== RateLimitCheckStatus.LIMIT_NOT_FOUND) {
247
- return ResetPasswordByIdStatus.TOO_MANY_REQUEST;
248
- }
249
- await recordRateLimitHit(identifier, rule);
250
-
251
- if (await IsUserExists.withId(userId)) return ResetPasswordByIdStatus.USER_NOT_FOUND;
252
- if (await IsUserDisabled.withId(userId)) return ResetPasswordByIdStatus.USER_DISABLED;
253
-
254
- if (newPassword !== confirmNewPassword) return ResetPasswordByIdStatus.NOT_IDENTICAL_CONFIRM_PASSWORD;
255
-
256
- const requiredMin = Math.max(6, passwordPolicy.minLength);
257
- if (newPassword.length < requiredMin) return ResetPasswordByIdStatus.WEAK_NEW_PASSWORD;
258
-
259
- const rules = [
260
- { enabled: passwordPolicy.requireUppercase, regex: /[A-Z]/, error: ResetPasswordByIdStatus.MISSING_PASSWORD_UPPERCASE },
261
- { enabled: passwordPolicy.requireLowercase, regex: /[a-z]/, error: ResetPasswordByIdStatus.MISSING_PASSWORD_LOWERCASE },
262
- { enabled: passwordPolicy.requireDigit, regex: /[0-9]/, error: ResetPasswordByIdStatus.MISSING_PASSWORD_DIGIT },
263
- { enabled: passwordPolicy.requireSpecial, regex: /[^A-Za-z0-9]/, error: ResetPasswordByIdStatus.MISSING_PASSWORD_SPECIAL_CHAR },
264
- ];
265
-
266
- for (const rule of rules) {
267
- if (rule.enabled && !rule.regex.test(newPassword)) return rule.error;
268
- }
269
-
270
- try {
271
- await admin.auth().updateUser(userId, { password: newPassword });
272
- return ResetPasswordByIdStatus.SUCCESS;
273
- } catch (error: any) {
274
- return ResetPasswordByIdStatus.INTERNAL_ERROR;
275
- }
276
- }
277
-
278
- static async withEmail(email: string, password: ResetPassword): Promise<ResetPasswordByEmailStatus> {
279
- email = email.trim();
280
- if (!email || email === "") return ResetPasswordByEmailStatus.MISSING_USER_EMAIL;
281
-
282
- if (!validator.isEmail(email)) return ResetPasswordByEmailStatus.INVALID_EMAIL_FORMAT;
283
-
284
- const user = await User.withEmail(email);
285
- if (user.status === UserByEmailStatus.INTERNAL_ERROR) return ResetPasswordByEmailStatus.INTERNAL_ERROR;
286
- if (user.status === UserByEmailStatus.MISSING_EMAIL) {
287
- return ResetPasswordByEmailStatus.MISSING_USER_EMAIL;
288
- }
289
- if (user.status === UserByEmailStatus.USER_NOT_FOUND) return ResetPasswordByEmailStatus.USER_NOT_FOUND;
290
-
291
- const userId = user.user?.uid;
292
- if (!userId || userId === undefined) return ResetPasswordByEmailStatus.INTERNAL_ERROR;
293
-
294
- const result = await this.withId(userId, password);
295
-
296
- const map = {
297
- [ResetPasswordByIdStatus.MISSING_DATABASE_CONFIG]: ResetPasswordByEmailStatus.MISSING_DATABASE_CONFIG,
298
- [ResetPasswordByIdStatus.MISSING_USER_ID]: ResetPasswordByEmailStatus.MISSING_USER_EMAIL,
299
- [ResetPasswordByIdStatus.MISSING_NEW_PASSWORD]: ResetPasswordByEmailStatus.MISSING_NEW_PASSWORD,
300
- [ResetPasswordByIdStatus.MISSING_CONFIRM_NEW_PASSWORD]: ResetPasswordByEmailStatus.MISSING_CONFIRM_NEW_PASSWORD,
301
- [ResetPasswordByIdStatus.MISSING_PASSWORD_POLICY]: ResetPasswordByEmailStatus.MISSING_PASSWORD_POLICY,
302
- [ResetPasswordByIdStatus.NOT_IDENTICAL_CONFIRM_PASSWORD]: ResetPasswordByEmailStatus.NOT_IDENTICAL_CONFIRM_PASSWORD,
303
- [ResetPasswordByIdStatus.USER_NOT_FOUND]: ResetPasswordByEmailStatus.USER_NOT_FOUND,
304
- [ResetPasswordByIdStatus.USER_DISABLED]: ResetPasswordByEmailStatus.USER_DISABLED,
305
- [ResetPasswordByIdStatus.WEAK_NEW_PASSWORD]: ResetPasswordByEmailStatus.WEAK_NEW_PASSWORD,
306
- [ResetPasswordByIdStatus.MISSING_PASSWORD_UPPERCASE]: ResetPasswordByEmailStatus.MISSING_PASSWORD_UPPERCASE,
307
- [ResetPasswordByIdStatus.MISSING_PASSWORD_LOWERCASE]: ResetPasswordByEmailStatus.MISSING_PASSWORD_LOWERCASE,
308
- [ResetPasswordByIdStatus.MISSING_PASSWORD_DIGIT]: ResetPasswordByEmailStatus.MISSING_PASSWORD_DIGIT,
309
- [ResetPasswordByIdStatus.MISSING_PASSWORD_SPECIAL_CHAR]: ResetPasswordByEmailStatus.MISSING_PASSWORD_SPECIAL_CHAR,
310
- [ResetPasswordByIdStatus.TOO_MANY_REQUEST]: ResetPasswordByEmailStatus.TOO_MANY_REQUEST,
311
- [ResetPasswordByIdStatus.SUCCESS]: ResetPasswordByEmailStatus.SUCCESS,
312
- [ResetPasswordByIdStatus.INTERNAL_ERROR]: ResetPasswordByEmailStatus.INTERNAL_ERROR,
313
- };
314
-
315
- return map[result];
316
- }
317
- }
package/src/auth/user.ts DELETED
@@ -1,93 +0,0 @@
1
- /*
2
- * Copyright (C) 2025 Fiber
3
- *
4
- * All rights reserved. This script, including its code and logic, is the
5
- * exclusive property of Fiber. Redistribution, reproduction,
6
- * or modification of any part of this script is strictly prohibited
7
- * without prior written permission from Fiber.
8
- *
9
- * Conditions of use:
10
- * - The code may not be copied, duplicated, or used, in whole or in part,
11
- * for any purpose without explicit authorization.
12
- * - Redistribution of this code, with or without modification, is not
13
- * permitted unless expressly agreed upon by Fiber.
14
- * - The name "Fiber" and any associated branding, logos, or
15
- * trademarks may not be used to endorse or promote derived products
16
- * or services without prior written approval.
17
- *
18
- * Disclaimer:
19
- * THIS SCRIPT AND ITS CODE ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
20
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
21
- * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL
22
- * FIBER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO LOSS OF USE,
24
- * DATA, PROFITS, OR BUSINESS INTERRUPTION) ARISING OUT OF OR RELATED TO THE USE
25
- * OR INABILITY TO USE THIS SCRIPT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
- *
27
- * Unauthorized copying or reproduction of this script, in whole or in part,
28
- * is a violation of applicable intellectual property laws and will result
29
- * in legal action.
30
- */
31
-
32
- import * as admin from "firebase-admin";
33
- import { IsUserExists, UserExistsByEmailStatus, UserExistsByIdStatus } from "./is_user_exists";
34
-
35
- if (admin.apps.length === 0) {
36
- admin.initializeApp();
37
- }
38
-
39
- export enum UserByIdStatus {
40
- MISSING_USER_ID = "MISSING_USER_ID",
41
- USER_NOT_FOUND = "USER_NOT_FOUND",
42
- USER_FOUND = "USER_FOUND",
43
- INTERNAL_ERROR = "INTERNAL_ERROR",
44
- }
45
-
46
- export enum UserByEmailStatus {
47
- MISSING_EMAIL = "MISSING_EMAIL",
48
- USER_NOT_FOUND = "USER_NOT_FOUND",
49
- USER_FOUND = "USER_FOUND",
50
- INTERNAL_ERROR = "INTERNAL_ERROR",
51
- }
52
-
53
- export class User {
54
- static async withId(userId: string): Promise<{ status: UserByIdStatus; user?: admin.auth.UserRecord; }> {
55
- userId = userId.trim();
56
-
57
- if (!userId || userId === "") return { status: UserByIdStatus.MISSING_USER_ID };
58
-
59
- const userExists = await IsUserExists.withId(userId);
60
- if (userExists === UserExistsByIdStatus.MISSING_USER_ID) return { status: UserByIdStatus.MISSING_USER_ID };
61
- if (userExists === UserExistsByIdStatus.INTERNAL_ERROR) return { status: UserByIdStatus.INTERNAL_ERROR };
62
- if (userExists === UserExistsByIdStatus.USER_NOT_FOUND) return { status: UserByIdStatus.USER_NOT_FOUND };
63
-
64
- try {
65
- const user = await admin.auth().getUser(userId);
66
-
67
- return { status: UserByIdStatus.USER_FOUND, user: user };
68
- } catch (error: any) {
69
- return { status: UserByIdStatus.INTERNAL_ERROR };
70
- }
71
- }
72
-
73
- static async withEmail(email: string): Promise<{ status: UserByEmailStatus; user?: admin.auth.UserRecord; }> {
74
- email = email.trim();
75
-
76
- if (!email || email === "") return { status: UserByEmailStatus.MISSING_EMAIL };
77
-
78
- const userExists = await IsUserExists.withEmail(email);
79
- if (userExists === UserExistsByEmailStatus.MISSING_USER_EMAIL) {
80
- return { status: UserByEmailStatus.MISSING_EMAIL };
81
- }
82
- if (userExists === UserExistsByEmailStatus.INTERNAL_ERROR) return { status: UserByEmailStatus.INTERNAL_ERROR };
83
- if (userExists === UserExistsByEmailStatus.USER_NOT_FOUND) return { status: UserByEmailStatus.USER_NOT_FOUND };
84
-
85
- try {
86
- const user = await admin.auth().getUserByEmail(email);
87
-
88
- return { status: UserByEmailStatus.USER_FOUND, user: user };
89
- } catch (error: any) {
90
- return { status: UserByEmailStatus.INTERNAL_ERROR };
91
- }
92
- }
93
- }
@@ -1,84 +0,0 @@
1
- /*
2
- * Copyright (C) 2025 Fiber
3
- *
4
- * All rights reserved. This script, including its code and logic, is the
5
- * exclusive property of Fiber. Redistribution, reproduction,
6
- * or modification of any part of this script is strictly prohibited
7
- * without prior written permission from Fiber.
8
- *
9
- * Conditions of use:
10
- * - The code may not be copied, duplicated, or used, in whole or in part,
11
- * for any purpose without explicit authorization.
12
- * - Redistribution of this code, with or without modification, is not
13
- * permitted unless expressly agreed upon by Fiber.
14
- * - The name "Fiber" and any associated branding, logos, or
15
- * trademarks may not be used to endorse or promote derived products
16
- * or services without prior written approval.
17
- *
18
- * Disclaimer:
19
- * THIS SCRIPT AND ITS CODE ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
20
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
21
- * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL
22
- * FIBER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO LOSS OF USE,
24
- * DATA, PROFITS, OR BUSINESS INTERRUPTION) ARISING OUT OF OR RELATED TO THE USE
25
- * OR INABILITY TO USE THIS SCRIPT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
- *
27
- * Unauthorized copying or reproduction of this script, in whole or in part,
28
- * is a violation of applicable intellectual property laws and will result
29
- * in legal action.
30
- */
31
-
32
- import fs from "fs";
33
- import path from "path";
34
-
35
- export interface AppConfig {
36
- rateLimiter: DatabaseConfig;
37
- otp: OtpConfig;
38
- email: EmailConfig;
39
- }
40
-
41
- export interface DatabaseConfig {
42
- appName: string;
43
- url: string;
44
- }
45
-
46
- export interface OtpConfig {
47
- collection: string;
48
- }
49
-
50
- export interface EmailConfig {
51
- applicationName: string;
52
- collection: string;
53
- }
54
-
55
- let cachedConfig: AppConfig | null = null;
56
-
57
- export function appInitialize(): AppConfig {
58
- if (cachedConfig) return cachedConfig;
59
-
60
- const configPath = path.resolve(process.cwd(), "config", "app.json");
61
-
62
- if (!fs.existsSync(configPath)) {
63
- throw new Error(`Missing configuration file at: ${configPath}`);
64
- }
65
-
66
- const raw = fs.readFileSync(configPath, "utf-8");
67
- const parsed = JSON.parse(raw);
68
-
69
- cachedConfig = {
70
- rateLimiter: {
71
- appName: parsed.rate_limiter.app_name ?? undefined,
72
- url: parsed.rate_limiter.url ?? undefined,
73
- },
74
- otp: {
75
- collection: parsed.otp.collection ?? undefined
76
- },
77
- email: {
78
- applicationName: parsed.email.application_name ?? undefined,
79
- collection: parsed.email.collection ?? undefined,
80
- }
81
- };
82
-
83
- return cachedConfig;
84
- }
@@ -1,121 +0,0 @@
1
- /*
2
- * Copyright (C) 2025 Fiber
3
- *
4
- * All rights reserved. This script, including its code and logic, is the
5
- * exclusive property of Fiber. Redistribution, reproduction,
6
- * or modification of any part of this script is strictly prohibited
7
- * without prior written permission from Fiber.
8
- *
9
- * Conditions of use:
10
- * - The code may not be copied, duplicated, or used, in whole or in part,
11
- * for any purpose without explicit authorization.
12
- * - Redistribution of this code, with or without modification, is not
13
- * permitted unless expressly agreed upon by Fiber.
14
- * - The name "Fiber" and any associated branding, logos, or
15
- * trademarks may not be used to endorse or promote derived products
16
- * or services without prior written approval.
17
- *
18
- * Disclaimer:
19
- * THIS SCRIPT AND ITS CODE ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
20
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
21
- * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL
22
- * FIBER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO LOSS OF USE,
24
- * DATA, PROFITS, OR BUSINESS INTERRUPTION) ARISING OUT OF OR RELATED TO THE USE
25
- * OR INABILITY TO USE THIS SCRIPT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
- *
27
- * Unauthorized copying or reproduction of this script, in whole or in part,
28
- * is a violation of applicable intellectual property laws and will result
29
- * in legal action.
30
- */
31
-
32
- export interface LanguageCode {
33
- short: string;
34
- full: string;
35
- }
36
-
37
- export enum Language {
38
- ARABIC = "arabic",
39
- BULGARIAN = "bulgarian",
40
- CATALAN = "catalan",
41
- CHINESE = "chinese",
42
- CROATIAN = "croatian",
43
- CZECH = "czech",
44
- DANISH = "danish",
45
- DUTCH = "dutch",
46
- ENGLISH = "english",
47
- FINNISH = "finnish",
48
- FRENCH = "french",
49
- GERMAN = "german",
50
- GREEK = "greek",
51
- HEBREW = "hebrew",
52
- HINDI = "hindi",
53
- HUNGARIAN = "hungarian",
54
- INDONESIAN = "indonesian",
55
- ITALIAN = "italian",
56
- JAPANESE = "japanese",
57
- KOREAN = "korean",
58
- LITHUANIAN = "lithuanian",
59
- MALAY = "malay",
60
- NORWEGIAN = "norwegian",
61
- POLISH = "polish",
62
- PORTUGUESE = "portuguese",
63
- ROMANIAN = "romanian",
64
- RUSSIAN = "russian",
65
- SLOVAK = "slovak",
66
- SLOVENIAN = "slovenian",
67
- SPANISH = "spanish",
68
- SWEDISH = "swedish",
69
- THAI = "thai",
70
- TURKISH = "turkish",
71
- UKRAINIAN = "ukrainian",
72
- VIETNAMESE = "vietnamese"
73
- }
74
-
75
- export const countryCode: Record<Language, LanguageCode> = {
76
- [Language.ARABIC]: { short: 'ar', full: 'ar-SA' },
77
- [Language.BULGARIAN]: { short: 'bg', full: 'bg-BG' },
78
- [Language.CATALAN]: { short: 'ca', full: 'ca-ES' },
79
- [Language.CHINESE]: { short: 'zh', full: 'zh-CN' },
80
- [Language.CROATIAN]: { short: 'hr', full: 'hr-HR' },
81
- [Language.CZECH]: { short: 'cs', full: 'cs-CZ' },
82
- [Language.DANISH]: { short: 'da', full: 'da-DK' },
83
- [Language.DUTCH]: { short: 'nl', full: 'nl-NL' },
84
- [Language.ENGLISH]: { short: 'en', full: 'en-US' },
85
- [Language.FINNISH]: { short: 'fi', full: 'fi-FI' },
86
- [Language.FRENCH]: { short: 'fr', full: 'fr-FR' },
87
- [Language.GERMAN]: { short: 'de', full: 'de-DE' },
88
- [Language.GREEK]: { short: 'el', full: 'el-GR' },
89
- [Language.HEBREW]: { short: 'he', full: 'he-IL' },
90
- [Language.HINDI]: { short: 'hi', full: 'hi-IN' },
91
- [Language.HUNGARIAN]: { short: 'hu', full: 'hu-HU' },
92
- [Language.INDONESIAN]: { short: 'id', full: 'id-ID' },
93
- [Language.ITALIAN]: { short: 'it', full: 'it-IT' },
94
- [Language.JAPANESE]: { short: 'ja', full: 'ja-JP' },
95
- [Language.KOREAN]: { short: 'ko', full: 'ko-KR' },
96
- [Language.LITHUANIAN]: { short: 'lt', full: 'lt-LT' },
97
- [Language.MALAY]: { short: 'ms', full: 'ms-MY' },
98
- [Language.NORWEGIAN]: { short: 'no', full: 'no-NO' },
99
- [Language.POLISH]: { short: 'pl', full: 'pl-PL' },
100
- [Language.PORTUGUESE]: { short: 'pt', full: 'pt-PT' },
101
- [Language.ROMANIAN]: { short: 'ro', full: 'ro-RO' },
102
- [Language.RUSSIAN]: { short: 'ru', full: 'ru-RU' },
103
- [Language.SLOVAK]: { short: 'sk', full: 'sk-SK' },
104
- [Language.SLOVENIAN]: { short: 'sl', full: 'sl-SI' },
105
- [Language.SPANISH]: { short: 'es', full: 'es-ES' },
106
- [Language.SWEDISH]: { short: 'sv', full: 'sv-SE' },
107
- [Language.THAI]: { short: 'th', full: 'th-TH' },
108
- [Language.TURKISH]: { short: 'tr', full: 'tr-TR' },
109
- [Language.UKRAINIAN]: { short: 'uk', full: 'uk-UA' },
110
- [Language.VIETNAMESE]: { short: 'vi', full: 'vi-VN' },
111
- };
112
-
113
- export namespace Language {
114
- export function fullCountryCode(lang: Language): string {
115
- return countryCode[lang].full;
116
- }
117
-
118
- export function shortCountryCode(lang: Language): string {
119
- return countryCode[lang].short;
120
- }
121
- }
@@ -1,60 +0,0 @@
1
- /*
2
- * Copyright (C) 2025 Fiber
3
- *
4
- * All rights reserved. This script, including its code and logic, is the
5
- * exclusive property of Fiber. Redistribution, reproduction,
6
- * or modification of any part of this script is strictly prohibited
7
- * without prior written permission from Fiber.
8
- *
9
- * Conditions of use:
10
- * - The code may not be copied, duplicated, or used, in whole or in part,
11
- * for any purpose without explicit authorization.
12
- * - Redistribution of this code, with or without modification, is not
13
- * permitted unless expressly agreed upon by Fiber.
14
- * - The name "Fiber" and any associated branding, logos, or
15
- * trademarks may not be used to endorse or promote derived products
16
- * or services without prior written approval.
17
- *
18
- * Disclaimer:
19
- * THIS SCRIPT AND ITS CODE ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
20
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
21
- * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL
22
- * FIBER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO LOSS OF USE,
24
- * DATA, PROFITS, OR BUSINESS INTERRUPTION) ARISING OUT OF OR RELATED TO THE USE
25
- * OR INABILITY TO USE THIS SCRIPT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
- *
27
- * Unauthorized copying or reproduction of this script, in whole or in part,
28
- * is a violation of applicable intellectual property laws and will result
29
- * in legal action.
30
- */
31
-
32
- import { App, getApps, initializeApp } from "firebase-admin/app";
33
- import { Database, getDatabase } from "firebase-admin/database";
34
-
35
- export interface RealtimeDatabase {
36
- appName: string;
37
- url: string;
38
- }
39
-
40
- export function realtimeDatabase(config: RealtimeDatabase): Database {
41
- const { appName, url } = config;
42
-
43
- let app: App;
44
-
45
- try {
46
- app = getApps().find((a) => a.name === appName) || initializeApp({ databaseURL: url }, appName);
47
- } catch (e) {
48
- console.error("[Error:getRealtimeDatabase]", {
49
- appName,
50
- url,
51
- loadedApps: getApps().map((a) => a.name),
52
- error: (e as Error).message,
53
- stack: (e as Error).stack,
54
- });
55
-
56
- throw e;
57
- }
58
-
59
- return getDatabase(app);
60
- };