fiber-firebase-functions 1.0.0 → 1.0.1

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.
@@ -89,6 +89,9 @@ exports.isUserDisabled = (0, https_1.onCall)(async (request) => {
89
89
  : UserDisabledStatus.ENABLED;
90
90
  }
91
91
  catch (error) {
92
+ if (error.code === "auth/user-not-found") {
93
+ return UserDisabledStatus.NOT_FOUND;
94
+ }
92
95
  return UserDisabledStatus.INTERNAL_ERROR;
93
96
  }
94
97
  });
@@ -1 +1 @@
1
- {"version":3,"file":"is_user_disabled.js","sourceRoot":"","sources":["../../src/auth/is_user_disabled.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,sDAAwC;AACxC,uDAAqD;AAErD,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;IAC1B,KAAK,CAAC,aAAa,EAAE,CAAC;AAC1B,CAAC;AAED,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC1B,mDAA6B,CAAA;IAC7B,yCAAmB,CAAA;IACnB,2CAAqB,CAAA;IACrB,6CAAuB,CAAA;IACvB,uDAAiC,CAAA;AACrC,CAAC,EANW,kBAAkB,kCAAlB,kBAAkB,QAM7B;AAEY,QAAA,cAAc,GAAG,IAAA,cAAM,EAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACnD,MAAM,GAAG,GAAuB,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;IAElD,IAAI,CAAC,GAAG;QAAE,OAAO,kBAAkB,CAAC,YAAY,CAAC;IAEjD,IAAI,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC7C,MAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC;QAErC,OAAO,cAAc;YACjB,CAAC,CAAC,kBAAkB,CAAC,QAAQ;YAC7B,CAAC,CAAC,kBAAkB,CAAC,OAAO,CAAC;IACrC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,kBAAkB,CAAC,cAAc,CAAC;IAC7C,CAAC;AACL,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"is_user_disabled.js","sourceRoot":"","sources":["../../src/auth/is_user_disabled.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,sDAAwC;AACxC,uDAAqD;AAErD,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;IAC1B,KAAK,CAAC,aAAa,EAAE,CAAC;AAC1B,CAAC;AAED,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC1B,mDAA6B,CAAA;IAC7B,yCAAmB,CAAA;IACnB,2CAAqB,CAAA;IACrB,6CAAuB,CAAA;IACvB,uDAAiC,CAAA;AACrC,CAAC,EANW,kBAAkB,kCAAlB,kBAAkB,QAM7B;AAEY,QAAA,cAAc,GAAG,IAAA,cAAM,EAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACnD,MAAM,GAAG,GAAuB,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;IAElD,IAAI,CAAC,GAAG;QAAE,OAAO,kBAAkB,CAAC,YAAY,CAAC;IAEjD,IAAI,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC7C,MAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC;QAErC,OAAO,cAAc;YACjB,CAAC,CAAC,kBAAkB,CAAC,QAAQ;YAC7B,CAAC,CAAC,kBAAkB,CAAC,OAAO,CAAC;IACrC,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QAClB,IAAI,KAAK,CAAC,IAAI,KAAK,qBAAqB,EAAE,CAAC;YACvC,OAAO,kBAAkB,CAAC,SAAS,CAAC;QACxC,CAAC;QACD,OAAO,kBAAkB,CAAC,cAAc,CAAC;IAC7C,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (C) 2025 Fiber
4
+ *
5
+ * All rights reserved. This script, including its code and logic, is the
6
+ * exclusive property of Fiber. Redistribution, reproduction,
7
+ * or modification of any part of this script is strictly prohibited
8
+ * without prior written permission from Fiber.
9
+ *
10
+ * Conditions of use:
11
+ * - The code may not be copied, duplicated, or used, in whole or in part,
12
+ * for any purpose without explicit authorization.
13
+ * - Redistribution of this code, with or without modification, is not
14
+ * permitted unless expressly agreed upon by Fiber.
15
+ * - The name "Fiber" and any associated branding, logos, or
16
+ * trademarks may not be used to endorse or promote derived products
17
+ * or services without prior written approval.
18
+ *
19
+ * Disclaimer:
20
+ * THIS SCRIPT AND ITS CODE ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
21
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
22
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL
23
+ * FIBER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO LOSS OF USE,
25
+ * DATA, PROFITS, OR BUSINESS INTERRUPTION) ARISING OUT OF OR RELATED TO THE USE
26
+ * OR INABILITY TO USE THIS SCRIPT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ *
28
+ * Unauthorized copying or reproduction of this script, in whole or in part,
29
+ * is a violation of applicable intellectual property laws and will result
30
+ * in legal action.
31
+ */
32
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
33
+ if (k2 === undefined) k2 = k;
34
+ var desc = Object.getOwnPropertyDescriptor(m, k);
35
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
36
+ desc = { enumerable: true, get: function() { return m[k]; } };
37
+ }
38
+ Object.defineProperty(o, k2, desc);
39
+ }) : (function(o, m, k, k2) {
40
+ if (k2 === undefined) k2 = k;
41
+ o[k2] = m[k];
42
+ }));
43
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
44
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
45
+ }) : function(o, v) {
46
+ o["default"] = v;
47
+ });
48
+ var __importStar = (this && this.__importStar) || (function () {
49
+ var ownKeys = function(o) {
50
+ ownKeys = Object.getOwnPropertyNames || function (o) {
51
+ var ar = [];
52
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
53
+ return ar;
54
+ };
55
+ return ownKeys(o);
56
+ };
57
+ return function (mod) {
58
+ if (mod && mod.__esModule) return mod;
59
+ var result = {};
60
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
61
+ __setModuleDefault(result, mod);
62
+ return result;
63
+ };
64
+ })();
65
+ Object.defineProperty(exports, "__esModule", { value: true });
66
+ exports.isUserExists = exports.UserExistsStatus = void 0;
67
+ const admin = __importStar(require("firebase-admin"));
68
+ const https_1 = require("firebase-functions/v2/https");
69
+ if (admin.apps.length === 0) {
70
+ admin.initializeApp();
71
+ }
72
+ var UserExistsStatus;
73
+ (function (UserExistsStatus) {
74
+ UserExistsStatus["MISSING_UUID"] = "MISSING_UUID";
75
+ UserExistsStatus["EXISTS"] = "EXISTS";
76
+ UserExistsStatus["NOT_FOUND"] = "NOT_FOUND";
77
+ UserExistsStatus["INTERNAL_ERROR"] = "INTERNAL_ERROR";
78
+ })(UserExistsStatus || (exports.UserExistsStatus = UserExistsStatus = {}));
79
+ exports.isUserExists = (0, https_1.onCall)(async (request) => {
80
+ const uid = request.data?.uid;
81
+ if (!uid)
82
+ return UserExistsStatus.MISSING_UUID;
83
+ try {
84
+ await admin.auth().getUser(uid);
85
+ return UserExistsStatus.EXISTS;
86
+ }
87
+ catch (error) {
88
+ if (error.code === "auth/user-not-found") {
89
+ return UserExistsStatus.NOT_FOUND;
90
+ }
91
+ return UserExistsStatus.INTERNAL_ERROR;
92
+ }
93
+ });
94
+ //# sourceMappingURL=is_user_exists.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is_user_exists.js","sourceRoot":"","sources":["../../src/auth/is_user_exists.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,sDAAwC;AACxC,uDAAqD;AAErD,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;IAC1B,KAAK,CAAC,aAAa,EAAE,CAAC;AAC1B,CAAC;AAED,IAAY,gBAKX;AALD,WAAY,gBAAgB;IACxB,iDAA6B,CAAA;IAC7B,qCAAiB,CAAA;IACjB,2CAAuB,CAAA;IACvB,qDAAiC,CAAA;AACrC,CAAC,EALW,gBAAgB,gCAAhB,gBAAgB,QAK3B;AAEY,QAAA,YAAY,GAAG,IAAA,cAAM,EAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACjD,MAAM,GAAG,GAAuB,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;IAElD,IAAI,CAAC,GAAG;QAAE,OAAO,gBAAgB,CAAC,YAAY,CAAC;IAE/C,IAAI,CAAC;QACD,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAEhC,OAAO,gBAAgB,CAAC,MAAM,CAAC;IACnC,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QAClB,IAAI,KAAK,CAAC,IAAI,KAAK,qBAAqB,EAAE,CAAC;YACvC,OAAO,gBAAgB,CAAC,SAAS,CAAC;QACtC,CAAC;QACD,OAAO,gBAAgB,CAAC,cAAc,CAAC;IAC3C,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (C) 2025 Fiber
4
+ *
5
+ * All rights reserved. This script, including its code and logic, is the
6
+ * exclusive property of Fiber. Redistribution, reproduction,
7
+ * or modification of any part of this script is strictly prohibited
8
+ * without prior written permission from Fiber.
9
+ *
10
+ * Conditions of use:
11
+ * - The code may not be copied, duplicated, or used, in whole or in part,
12
+ * for any purpose without explicit authorization.
13
+ * - Redistribution of this code, with or without modification, is not
14
+ * permitted unless expressly agreed upon by Fiber.
15
+ * - The name "Fiber" and any associated branding, logos, or
16
+ * trademarks may not be used to endorse or promote derived products
17
+ * or services without prior written approval.
18
+ *
19
+ * Disclaimer:
20
+ * THIS SCRIPT AND ITS CODE ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
21
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
22
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL
23
+ * FIBER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO LOSS OF USE,
25
+ * DATA, PROFITS, OR BUSINESS INTERRUPTION) ARISING OUT OF OR RELATED TO THE USE
26
+ * OR INABILITY TO USE THIS SCRIPT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ *
28
+ * Unauthorized copying or reproduction of this script, in whole or in part,
29
+ * is a violation of applicable intellectual property laws and will result
30
+ * in legal action.
31
+ */
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ exports.realtimeDatabase = realtimeDatabase;
34
+ const app_1 = require("firebase-admin/app");
35
+ const database_1 = require("firebase-admin/database");
36
+ function realtimeDatabase(config) {
37
+ return function getRealtimeDatabase(name) {
38
+ const entry = config[name];
39
+ if (!entry) {
40
+ throw new Error(`Realtime DB config "${name}" not found`);
41
+ }
42
+ const { appName, url } = entry;
43
+ let app;
44
+ try {
45
+ app = (0, app_1.getApps)().find((a) => a.name === appName) || (0, app_1.initializeApp)({ databaseURL: url }, appName);
46
+ }
47
+ catch (e) {
48
+ console.error("[Error:getRealtimeDatabase]", {
49
+ appName,
50
+ url,
51
+ loadedApps: (0, app_1.getApps)().map((a) => a.name),
52
+ error: e.message,
53
+ stack: e.stack,
54
+ });
55
+ throw e;
56
+ }
57
+ return (0, database_1.getDatabase)(app);
58
+ };
59
+ }
60
+ //# sourceMappingURL=realtime_database.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"realtime_database.js","sourceRoot":"","sources":["../../src/common/realtime_database.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;;AAUH,4CA2BC;AAnCD,4CAAiE;AACjE,sDAAgE;AAOhE,SAAgB,gBAAgB,CAAC,MAAwC;IACrE,OAAO,SAAS,mBAAmB,CAAC,IAAY;QAC5C,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,CAAC,KAAK,EAAE,CAAC;YACT,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,aAAa,CAAC,CAAC;QAC9D,CAAC;QAED,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC;QAE/B,IAAI,GAAQ,CAAC;QAEb,IAAI,CAAC;YACD,GAAG,GAAG,IAAA,aAAO,GAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,IAAA,mBAAa,EAAC,EAAE,WAAW,EAAE,GAAG,EAAE,EAAE,OAAO,CAAC,CAAC;QACpG,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE;gBACzC,OAAO;gBACP,GAAG;gBACH,UAAU,EAAE,IAAA,aAAO,GAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;gBACxC,KAAK,EAAG,CAAW,CAAC,OAAO;gBAC3B,KAAK,EAAG,CAAW,CAAC,KAAK;aAC5B,CAAC,CAAC;YAEH,MAAM,CAAC,CAAC;QACZ,CAAC;QAED,OAAO,IAAA,sBAAW,EAAC,GAAG,CAAC,CAAC;IAC5B,CAAC,CAAC;AACN,CAAC"}
package/lib/index.js CHANGED
@@ -45,4 +45,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
45
45
  };
46
46
  Object.defineProperty(exports, "__esModule", { value: true });
47
47
  __exportStar(require("./auth/is_user_disabled"), exports);
48
+ __exportStar(require("./auth/is_user_exists"), exports);
49
+ __exportStar(require("./common/realtime_database"), exports);
48
50
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;;;;;;;;;;;;;;;;AAEH,0DAAwC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;;;;;;;;;;;;;;;;AAEH,0DAAwC;AACxC,wDAAsC;AACtC,6DAA2C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fiber-firebase-functions",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A collection of ready-to-use Firebase Cloud Functions utilities and wrappers designed for any application built by Fiber. Provides reusable helpers, common patterns, and production-grade modules to streamline backend development across all Fiber projects.",
5
5
  "author": "Fiber",
6
6
  "license": "FIBER-PROPRIETARY",
@@ -56,7 +56,10 @@ export const isUserDisabled = onCall(async (request) => {
56
56
  return isUserDisabled
57
57
  ? UserDisabledStatus.DISABLED
58
58
  : UserDisabledStatus.ENABLED;
59
- } catch (error) {
59
+ } catch (error: any) {
60
+ if (error.code === "auth/user-not-found") {
61
+ return UserDisabledStatus.NOT_FOUND;
62
+ }
60
63
  return UserDisabledStatus.INTERNAL_ERROR;
61
64
  }
62
65
  });
@@ -0,0 +1,61 @@
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 { onCall } from "firebase-functions/v2/https";
34
+
35
+ if (admin.apps.length === 0) {
36
+ admin.initializeApp();
37
+ }
38
+
39
+ export enum UserExistsStatus {
40
+ MISSING_UUID = "MISSING_UUID",
41
+ EXISTS = "EXISTS",
42
+ NOT_FOUND = "NOT_FOUND",
43
+ INTERNAL_ERROR = "INTERNAL_ERROR",
44
+ }
45
+
46
+ export const isUserExists = onCall(async (request) => {
47
+ const uid: string | undefined = request.data?.uid;
48
+
49
+ if (!uid) return UserExistsStatus.MISSING_UUID;
50
+
51
+ try {
52
+ await admin.auth().getUser(uid);
53
+
54
+ return UserExistsStatus.EXISTS;
55
+ } catch (error: any) {
56
+ if (error.code === "auth/user-not-found") {
57
+ return UserExistsStatus.NOT_FOUND;
58
+ }
59
+ return UserExistsStatus.INTERNAL_ERROR;
60
+ }
61
+ });
@@ -0,0 +1,31 @@
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
+
@@ -0,0 +1,67 @@
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: Record<string, RealtimeDatabase>) {
41
+ return function getRealtimeDatabase(name: string): Database {
42
+ const entry = config[name];
43
+ if (!entry) {
44
+ throw new Error(`Realtime DB config "${name}" not found`);
45
+ }
46
+
47
+ const { appName, url } = entry;
48
+
49
+ let app: App;
50
+
51
+ try {
52
+ app = getApps().find((a) => a.name === appName) || initializeApp({ databaseURL: url }, appName);
53
+ } catch (e) {
54
+ console.error("[Error:getRealtimeDatabase]", {
55
+ appName,
56
+ url,
57
+ loadedApps: getApps().map((a) => a.name),
58
+ error: (e as Error).message,
59
+ stack: (e as Error).stack,
60
+ });
61
+
62
+ throw e;
63
+ }
64
+
65
+ return getDatabase(app);
66
+ };
67
+ }
package/src/index.ts CHANGED
@@ -30,3 +30,6 @@
30
30
  */
31
31
 
32
32
  export * from "./auth/is_user_disabled";
33
+ export * from "./auth/is_user_exists";
34
+ export * from "./common/realtime_database";
35
+