@xbg.solutions/utils-firestore-connector 1.0.0
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.
- package/lib/firebase-types.d.ts +141 -0
- package/lib/firebase-types.d.ts.map +1 -0
- package/lib/firebase-types.js +85 -0
- package/lib/firebase-types.js.map +1 -0
- package/lib/firebase.d.ts +35 -0
- package/lib/firebase.d.ts.map +1 -0
- package/lib/firebase.js +133 -0
- package/lib/firebase.js.map +1 -0
- package/lib/firestore-connector.d.ts +86 -0
- package/lib/firestore-connector.d.ts.map +1 -0
- package/lib/firestore-connector.js +381 -0
- package/lib/firestore-connector.js.map +1 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +27 -0
- package/lib/index.js.map +1 -0
- package/package.json +30 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Firebase/Firestore type definitions for portable use
|
|
3
|
+
* Clean implementation without legacy compatibility
|
|
4
|
+
*/
|
|
5
|
+
import { Firestore } from 'firebase-admin/firestore';
|
|
6
|
+
import { LogContext } from '@xbg/utils-logger';
|
|
7
|
+
/**
|
|
8
|
+
* Generic database configuration for any project
|
|
9
|
+
*/
|
|
10
|
+
export type DatabaseConfig<TDatabaseNames extends string = string> = {
|
|
11
|
+
[dbName in TDatabaseNames]: {
|
|
12
|
+
/** Firestore database name (for named databases in production) */
|
|
13
|
+
firestoreName?: string;
|
|
14
|
+
/** Collections that exist in this database */
|
|
15
|
+
collections: string[];
|
|
16
|
+
/** Whether this database should be available in emulator mode */
|
|
17
|
+
emulatorSupport?: boolean;
|
|
18
|
+
/** Custom initialization options for this database */
|
|
19
|
+
initOptions?: Record<string, any>;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Runtime database instances
|
|
24
|
+
*/
|
|
25
|
+
export type DatabaseInstances<TDatabaseNames extends string = string> = {
|
|
26
|
+
[K in TDatabaseNames]: Firestore;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Database connection test results
|
|
30
|
+
*/
|
|
31
|
+
export type DatabaseConnectionResult<TDatabaseNames extends string = string> = {
|
|
32
|
+
[K in TDatabaseNames]: boolean;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Firestore environment detection
|
|
36
|
+
*/
|
|
37
|
+
export interface FirestoreEnvironment {
|
|
38
|
+
isEmulator: boolean;
|
|
39
|
+
isProduction: boolean;
|
|
40
|
+
isFunctionsEnvironment: boolean;
|
|
41
|
+
projectId: string;
|
|
42
|
+
emulatorHost?: string;
|
|
43
|
+
emulatorPort?: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Firebase configuration interface
|
|
47
|
+
*/
|
|
48
|
+
export interface FirebaseConfig {
|
|
49
|
+
projectId: string;
|
|
50
|
+
databaseURL?: string;
|
|
51
|
+
storageBucket?: string;
|
|
52
|
+
serviceAccountPath?: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Extended LogContext for Firebase operations
|
|
56
|
+
*/
|
|
57
|
+
export interface FirebaseLogContext extends LogContext {
|
|
58
|
+
dbName?: string;
|
|
59
|
+
databases?: string[];
|
|
60
|
+
collection?: string;
|
|
61
|
+
document?: string;
|
|
62
|
+
docId?: string;
|
|
63
|
+
firebaseOperation?: FirebaseOperation;
|
|
64
|
+
connectionTest?: boolean;
|
|
65
|
+
healthCheck?: boolean;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Health check result interface
|
|
69
|
+
*/
|
|
70
|
+
export interface HealthCheckResult<TDatabaseNames extends string = string> {
|
|
71
|
+
firebase: boolean;
|
|
72
|
+
databases: DatabaseConnectionResult<TDatabaseNames>;
|
|
73
|
+
timestamp: Date;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Firebase error interface
|
|
77
|
+
*/
|
|
78
|
+
export interface FirebaseError extends Error {
|
|
79
|
+
code?: string;
|
|
80
|
+
details?: string;
|
|
81
|
+
httpStatus?: number;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Test document interface
|
|
85
|
+
*/
|
|
86
|
+
export interface TestDocument {
|
|
87
|
+
timestamp: any;
|
|
88
|
+
test: boolean;
|
|
89
|
+
database: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Firebase connection state
|
|
93
|
+
*/
|
|
94
|
+
export interface FirebaseConnectionState {
|
|
95
|
+
initialized: boolean;
|
|
96
|
+
connected: boolean;
|
|
97
|
+
databasesInitialized: boolean;
|
|
98
|
+
lastHealthCheck?: Date;
|
|
99
|
+
connectionErrors?: Error[];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Firebase initialization options
|
|
103
|
+
*/
|
|
104
|
+
export interface FirebaseInitOptions {
|
|
105
|
+
forceReinitialize?: boolean;
|
|
106
|
+
skipDatabaseInit?: boolean;
|
|
107
|
+
testMode?: boolean;
|
|
108
|
+
emulatorMode?: boolean;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Firebase operation types
|
|
112
|
+
*/
|
|
113
|
+
export declare enum FirebaseOperation {
|
|
114
|
+
INITIALIZE = "initialize",
|
|
115
|
+
CONNECT = "connect",
|
|
116
|
+
DISCONNECT = "disconnect",
|
|
117
|
+
READ = "read",
|
|
118
|
+
WRITE = "write",
|
|
119
|
+
DELETE = "delete",
|
|
120
|
+
QUERY = "query",
|
|
121
|
+
HEALTH_CHECK = "health_check",
|
|
122
|
+
CONNECTION_TEST = "connection_test"
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Type guard for standard errors
|
|
126
|
+
*/
|
|
127
|
+
export declare const isError: (error: any) => error is Error;
|
|
128
|
+
/**
|
|
129
|
+
* Convert unknown error to Error type
|
|
130
|
+
*/
|
|
131
|
+
export declare const toError: (error: unknown) => Error;
|
|
132
|
+
/**
|
|
133
|
+
* Detect Firestore environment
|
|
134
|
+
*/
|
|
135
|
+
export declare const detectEnvironment: () => FirestoreEnvironment;
|
|
136
|
+
/**
|
|
137
|
+
* Get Firebase configuration from environment
|
|
138
|
+
*/
|
|
139
|
+
export declare const getFirebaseConfigFromEnv: () => FirebaseConfig;
|
|
140
|
+
export { Firestore, CollectionReference, DocumentReference, DocumentSnapshot, QuerySnapshot } from 'firebase-admin/firestore';
|
|
141
|
+
//# sourceMappingURL=firebase-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebase-types.d.ts","sourceRoot":"","sources":["../src/firebase-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,cAAc,CAAC,cAAc,SAAS,MAAM,GAAG,MAAM,IAAI;KAClE,MAAM,IAAI,cAAc,GAAG;QAC1B,kEAAkE;QAClE,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,8CAA8C;QAC9C,WAAW,EAAE,MAAM,EAAE,CAAC;QACtB,iEAAiE;QACjE,eAAe,CAAC,EAAE,OAAO,CAAC;QAC1B,sDAAsD;QACtD,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KACnC;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,cAAc,SAAS,MAAM,GAAG,MAAM,IAAI;KACrE,CAAC,IAAI,cAAc,GAAG,SAAS;CACjC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,wBAAwB,CAAC,cAAc,SAAS,MAAM,GAAG,MAAM,IAAI;KAC5E,CAAC,IAAI,cAAc,GAAG,OAAO;CAC/B,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,OAAO,CAAC;IACtB,sBAAsB,EAAE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AE,OAAO,CAAC;IACnB,oBAAoB,EAAE,OAAO,CAAC;IAC9B,eAAe,CAAC,EAAE,IAAI,CAAC;IACvB,gBAAgB,CAAC,EAAE,KAAK,EAAE,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,oBAAY,iBAAiB;IAC3B,UAAU,eAAe;IACzB,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,IAAI,SAAS;IACb,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,YAAY,iBAAiB;IAC7B,eAAe,oBAAoB;CACpC;AAED;;GAEG;AACH,eAAO,MAAM,OAAO,GAAI,OAAO,GAAG,KAAG,KAAK,IAAI,KAE7C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,OAAO,GAAI,OAAO,OAAO,KAAG,KAcxC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,QAAO,oBAWpC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB,QAAO,cAmB3C,CAAC;AAGF,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QuerySnapshot = exports.DocumentSnapshot = exports.DocumentReference = exports.CollectionReference = exports.Firestore = exports.getFirebaseConfigFromEnv = exports.detectEnvironment = exports.toError = exports.isError = exports.FirebaseOperation = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Firebase operation types
|
|
6
|
+
*/
|
|
7
|
+
var FirebaseOperation;
|
|
8
|
+
(function (FirebaseOperation) {
|
|
9
|
+
FirebaseOperation["INITIALIZE"] = "initialize";
|
|
10
|
+
FirebaseOperation["CONNECT"] = "connect";
|
|
11
|
+
FirebaseOperation["DISCONNECT"] = "disconnect";
|
|
12
|
+
FirebaseOperation["READ"] = "read";
|
|
13
|
+
FirebaseOperation["WRITE"] = "write";
|
|
14
|
+
FirebaseOperation["DELETE"] = "delete";
|
|
15
|
+
FirebaseOperation["QUERY"] = "query";
|
|
16
|
+
FirebaseOperation["HEALTH_CHECK"] = "health_check";
|
|
17
|
+
FirebaseOperation["CONNECTION_TEST"] = "connection_test";
|
|
18
|
+
})(FirebaseOperation || (exports.FirebaseOperation = FirebaseOperation = {}));
|
|
19
|
+
/**
|
|
20
|
+
* Type guard for standard errors
|
|
21
|
+
*/
|
|
22
|
+
const isError = (error) => {
|
|
23
|
+
return error instanceof Error;
|
|
24
|
+
};
|
|
25
|
+
exports.isError = isError;
|
|
26
|
+
/**
|
|
27
|
+
* Convert unknown error to Error type
|
|
28
|
+
*/
|
|
29
|
+
const toError = (error) => {
|
|
30
|
+
if ((0, exports.isError)(error)) {
|
|
31
|
+
return error;
|
|
32
|
+
}
|
|
33
|
+
if (typeof error === 'string') {
|
|
34
|
+
return new Error(error);
|
|
35
|
+
}
|
|
36
|
+
if (error && typeof error === 'object' && 'message' in error) {
|
|
37
|
+
return new Error(String(error.message));
|
|
38
|
+
}
|
|
39
|
+
return new Error('Unknown error occurred');
|
|
40
|
+
};
|
|
41
|
+
exports.toError = toError;
|
|
42
|
+
/**
|
|
43
|
+
* Detect Firestore environment
|
|
44
|
+
*/
|
|
45
|
+
const detectEnvironment = () => {
|
|
46
|
+
const projectId = process.env.FIREBASE_PROJECT_ID || process.env.GCLOUD_PROJECT || '';
|
|
47
|
+
return {
|
|
48
|
+
isEmulator: !!(process.env.FUNCTIONS_EMULATOR || process.env.FIRESTORE_EMULATOR_HOST),
|
|
49
|
+
isProduction: !!(process.env.K_SERVICE || process.env.GCLOUD_PROJECT),
|
|
50
|
+
isFunctionsEnvironment: !!(process.env.FUNCTIONS_EMULATOR || process.env.K_SERVICE),
|
|
51
|
+
projectId,
|
|
52
|
+
emulatorHost: process.env.FIRESTORE_EMULATOR_HOST,
|
|
53
|
+
emulatorPort: process.env.FIRESTORE_EMULATOR_PORT ? parseInt(process.env.FIRESTORE_EMULATOR_PORT) : undefined
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
exports.detectEnvironment = detectEnvironment;
|
|
57
|
+
/**
|
|
58
|
+
* Get Firebase configuration from environment
|
|
59
|
+
*/
|
|
60
|
+
const getFirebaseConfigFromEnv = () => {
|
|
61
|
+
const projectId = process.env.FIREBASE_PROJECT_ID || process.env.GCLOUD_PROJECT;
|
|
62
|
+
const serviceAccountPath = process.env.GOOGLE_APPLICATION_CREDENTIALS;
|
|
63
|
+
if (!projectId) {
|
|
64
|
+
throw new Error('FIREBASE_PROJECT_ID or GCLOUD_PROJECT environment variable is required');
|
|
65
|
+
}
|
|
66
|
+
// In Firebase Functions environment, service account credentials are not required
|
|
67
|
+
if (!serviceAccountPath && !process.env.FUNCTIONS_EMULATOR && !process.env.K_SERVICE) {
|
|
68
|
+
throw new Error('GOOGLE_APPLICATION_CREDENTIALS environment variable is required');
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
projectId,
|
|
72
|
+
databaseURL: process.env.FIREBASE_DATABASE_URL || `https://${projectId}.firebaseio.com`,
|
|
73
|
+
storageBucket: process.env.FIREBASE_STORAGE_BUCKET || `${projectId}.appspot.com`,
|
|
74
|
+
serviceAccountPath: serviceAccountPath || ''
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
exports.getFirebaseConfigFromEnv = getFirebaseConfigFromEnv;
|
|
78
|
+
// Re-export Firestore types for convenience
|
|
79
|
+
var firestore_1 = require("firebase-admin/firestore");
|
|
80
|
+
Object.defineProperty(exports, "Firestore", { enumerable: true, get: function () { return firestore_1.Firestore; } });
|
|
81
|
+
Object.defineProperty(exports, "CollectionReference", { enumerable: true, get: function () { return firestore_1.CollectionReference; } });
|
|
82
|
+
Object.defineProperty(exports, "DocumentReference", { enumerable: true, get: function () { return firestore_1.DocumentReference; } });
|
|
83
|
+
Object.defineProperty(exports, "DocumentSnapshot", { enumerable: true, get: function () { return firestore_1.DocumentSnapshot; } });
|
|
84
|
+
Object.defineProperty(exports, "QuerySnapshot", { enumerable: true, get: function () { return firestore_1.QuerySnapshot; } });
|
|
85
|
+
//# sourceMappingURL=firebase-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebase-types.js","sourceRoot":"","sources":["../src/firebase-types.ts"],"names":[],"mappings":";;;AA8HA;;GAEG;AACH,IAAY,iBAUX;AAVD,WAAY,iBAAiB;IAC3B,8CAAyB,CAAA;IACzB,wCAAmB,CAAA;IACnB,8CAAyB,CAAA;IACzB,kCAAa,CAAA;IACb,oCAAe,CAAA;IACf,sCAAiB,CAAA;IACjB,oCAAe,CAAA;IACf,kDAA6B,CAAA;IAC7B,wDAAmC,CAAA;AACrC,CAAC,EAVW,iBAAiB,iCAAjB,iBAAiB,QAU5B;AAED;;GAEG;AACI,MAAM,OAAO,GAAG,CAAC,KAAU,EAAkB,EAAE;IACpD,OAAO,KAAK,YAAY,KAAK,CAAC;AAChC,CAAC,CAAC;AAFW,QAAA,OAAO,WAElB;AAEF;;GAEG;AACI,MAAM,OAAO,GAAG,CAAC,KAAc,EAAS,EAAE;IAC/C,IAAI,IAAA,eAAO,EAAC,KAAK,CAAC,EAAE,CAAC;QACnB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAED,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,SAAS,IAAI,KAAK,EAAE,CAAC;QAC7D,OAAO,IAAI,KAAK,CAAC,M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IAC5F,CAAC;IAED,kFAAkF;IAClF,IAAI,CAAC,kBAAkB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC;QACrF,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;IACrF,CAAC;IAED,OAAO;QACL,SAAS;QACT,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,WAAW,SAAS,iBAAiB;QACvF,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,uBAAuB,IAAI,GAAG,SAAS,cAAc;QAChF,kBAAkB,EAAE,kBAAkB,IAAI,EAAE;KAC7C,CAAC;AACJ,CAAC,CAAC;AAnBW,QAAA,wBAAwB,4BAmBnC;AAEF,4CAA4C;AAC5C,sDAA8H;AAArH,sGAAA,SAAS,OAAA;AAAE,gHAAA,mBAAmB,OAAA;AAAE,8GAAA,iBAAiB,OAAA;AAAE,6GAAA,gBAAgB,OAAA;AAAE,0GAAA,aAAa,OAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firebase Admin SDK Initialization
|
|
3
|
+
* Centralized Firebase initialization for the backend boilerplate
|
|
4
|
+
*/
|
|
5
|
+
import * as admin from 'firebase-admin';
|
|
6
|
+
import { Firestore } from 'firebase-admin/firestore';
|
|
7
|
+
/**
|
|
8
|
+
* Initialize Firebase Admin SDK
|
|
9
|
+
* Safe to call multiple times - only initializes once
|
|
10
|
+
*/
|
|
11
|
+
export declare function initializeFirebase(): admin.app.App;
|
|
12
|
+
/**
|
|
13
|
+
* Get Firestore instance
|
|
14
|
+
* Initializes Firebase if not already initialized
|
|
15
|
+
*
|
|
16
|
+
* @returns Firestore instance
|
|
17
|
+
*/
|
|
18
|
+
export declare function getFirestore(): Firestore;
|
|
19
|
+
/**
|
|
20
|
+
* Get Firebase Auth instance
|
|
21
|
+
*/
|
|
22
|
+
export declare function getAuth(): admin.auth.Auth;
|
|
23
|
+
/**
|
|
24
|
+
* Get Firebase Storage instance
|
|
25
|
+
*/
|
|
26
|
+
export declare function getStorage(): admin.storage.Storage;
|
|
27
|
+
/**
|
|
28
|
+
* Reset Firebase instances (useful for testing)
|
|
29
|
+
*/
|
|
30
|
+
export declare function resetFirebase(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Check if Firebase is initialized
|
|
33
|
+
*/
|
|
34
|
+
export declare function isFirebaseInitialized(): boolean;
|
|
35
|
+
//# sourceMappingURL=firebase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebase.d.ts","sourceRoot":"","sources":["../src/firebase.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAMrD;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,CAiClD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,IAAI,SAAS,CAmBxC;AAED;;GAEG;AACH,wBAAgB,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAGzC;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAGlD;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,IAAI,CAGpC;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,OAAO,CAE/C"}
|
package/lib/firebase.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Firebase Admin SDK Initialization
|
|
4
|
+
* Centralized Firebase initialization for the backend boilerplate
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.initializeFirebase = initializeFirebase;
|
|
41
|
+
exports.getFirestore = getFirestore;
|
|
42
|
+
exports.getAuth = getAuth;
|
|
43
|
+
exports.getStorage = getStorage;
|
|
44
|
+
exports.resetFirebase = resetFirebase;
|
|
45
|
+
exports.isFirebaseInitialized = isFirebaseInitialized;
|
|
46
|
+
const admin = __importStar(require("firebase-admin"));
|
|
47
|
+
const utils_logger_1 = require("@xbg/utils-logger");
|
|
48
|
+
let firestoreInstance = null;
|
|
49
|
+
let isInitialized = false;
|
|
50
|
+
/**
|
|
51
|
+
* Initialize Firebase Admin SDK
|
|
52
|
+
* Safe to call multiple times - only initializes once
|
|
53
|
+
*/
|
|
54
|
+
function initializeFirebase() {
|
|
55
|
+
if (!isInitialized) {
|
|
56
|
+
try {
|
|
57
|
+
// Check if already initialized (e.g., by Firebase Functions runtime)
|
|
58
|
+
if (admin.apps.length === 0) {
|
|
59
|
+
const projectId = process.env.FIREBASE_PROJECT_ID || process.env.GCLOUD_PROJECT;
|
|
60
|
+
if (!projectId) {
|
|
61
|
+
throw new Error('FIREBASE_PROJECT_ID or GCLOUD_PROJECT environment variable is required');
|
|
62
|
+
}
|
|
63
|
+
// Initialize with application default credentials in Cloud Functions
|
|
64
|
+
// or with service account in local development
|
|
65
|
+
admin.initializeApp({
|
|
66
|
+
projectId,
|
|
67
|
+
credential: admin.credential.applicationDefault(),
|
|
68
|
+
});
|
|
69
|
+
utils_logger_1.logger.info('Firebase Admin SDK initialized', {
|
|
70
|
+
projectId,
|
|
71
|
+
environment: process.env.NODE_ENV,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
isInitialized = true;
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
78
|
+
utils_logger_1.logger.error('Failed to initialize Firebase Admin SDK', err);
|
|
79
|
+
throw err;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return admin.app();
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get Firestore instance
|
|
86
|
+
* Initializes Firebase if not already initialized
|
|
87
|
+
*
|
|
88
|
+
* @returns Firestore instance
|
|
89
|
+
*/
|
|
90
|
+
function getFirestore() {
|
|
91
|
+
if (!firestoreInstance) {
|
|
92
|
+
// Ensure Firebase is initialized
|
|
93
|
+
initializeFirebase();
|
|
94
|
+
// Get Firestore instance
|
|
95
|
+
firestoreInstance = admin.firestore();
|
|
96
|
+
// Configure Firestore settings
|
|
97
|
+
firestoreInstance.settings({
|
|
98
|
+
ignoreUndefinedProperties: true,
|
|
99
|
+
});
|
|
100
|
+
utils_logger_1.logger.info('Firestore instance created', {
|
|
101
|
+
emulator: !!process.env.FIRESTORE_EMULATOR_HOST,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return firestoreInstance;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get Firebase Auth instance
|
|
108
|
+
*/
|
|
109
|
+
function getAuth() {
|
|
110
|
+
initializeFirebase();
|
|
111
|
+
return admin.auth();
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Get Firebase Storage instance
|
|
115
|
+
*/
|
|
116
|
+
function getStorage() {
|
|
117
|
+
initializeFirebase();
|
|
118
|
+
return admin.storage();
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Reset Firebase instances (useful for testing)
|
|
122
|
+
*/
|
|
123
|
+
function resetFirebase() {
|
|
124
|
+
firestoreInstance = null;
|
|
125
|
+
isInitialized = false;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Check if Firebase is initialized
|
|
129
|
+
*/
|
|
130
|
+
function isFirebaseInitialized() {
|
|
131
|
+
return isInitialized;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=firebase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebase.js","sourceRoot":"","sources":["../src/firebase.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaH,gDAiCC;AAQD,oCAmBC;AAKD,0BAGC;AAKD,gCAGC;AAKD,sCAGC;AAKD,sDAEC;AAtGD,sDAAwC;AAExC,oDAA2C;AAE3C,IAAI,iBAAiB,GAAqB,IAAI,CAAC;AAC/C,IAAI,aAAa,GAAG,KAAK,CAAC;AAE1B;;;GAGG;A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,CAAC,QAAQ,CAAC;YACzB,yBAAyB,EAAE,IAAI;SAChC,CAAC,CAAC;QAEH,qBAAM,CAAC,IAAI,CAAC,4BAA4B,EAAE;YACxC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB;SAChD,CAAC,CAAC;IACL,CAAC;IAED,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AAED;;GAEG;AACH,SAAgB,OAAO;IACrB,kBAAkB,EAAE,CAAC;IACrB,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC;AACtB,CAAC;AAED;;GAEG;AACH,SAAgB,UAAU;IACxB,kBAAkB,EAAE,CAAC;IACrB,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC;AACzB,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa;IAC3B,iBAAiB,GAAG,IAAI,CAAC;IACzB,aAAa,GAAG,KAAK,CAAC;AACxB,CAAC;AAED;;GAEG;AACH,SAAgB,qBAAqB;IACnC,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Firebase configuration and database access utility
|
|
3
|
+
* Clean implementation without legacy compatibility
|
|
4
|
+
*/
|
|
5
|
+
import * as admin from 'firebase-admin';
|
|
6
|
+
import { DatabaseConfig, DatabaseInstances, DatabaseConnectionResult, HealthCheckResult, FirebaseConnectionState, FirebaseInitOptions, Firestore } from './firebase-types';
|
|
7
|
+
/**
|
|
8
|
+
* Generic Firestore Connector Class
|
|
9
|
+
* Can be configured for any project's database schema
|
|
10
|
+
*/
|
|
11
|
+
export declare class FirestoreConnector<TDatabaseNames extends string = string> {
|
|
12
|
+
private config;
|
|
13
|
+
private options;
|
|
14
|
+
private dbInstances;
|
|
15
|
+
private connectionState;
|
|
16
|
+
constructor(config: DatabaseConfig<TDatabaseNames>, options?: FirebaseInitOptions);
|
|
17
|
+
/**
|
|
18
|
+
* Initialize Firebase Admin SDK with service account
|
|
19
|
+
*/
|
|
20
|
+
initializeFirebase(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Initialize database instances based on configuration
|
|
23
|
+
*/
|
|
24
|
+
private initializeDatabaseInstances;
|
|
25
|
+
/**
|
|
26
|
+
* Get all database instances, initializing if necessary
|
|
27
|
+
*/
|
|
28
|
+
getDb(): DatabaseInstances<TDatabaseNames>;
|
|
29
|
+
/**
|
|
30
|
+
* Get specific database instance by name
|
|
31
|
+
*/
|
|
32
|
+
getDbByName(dbName: TDatabaseNames): Firestore;
|
|
33
|
+
/**
|
|
34
|
+
* Get database instance with collection reference for convenience
|
|
35
|
+
*/
|
|
36
|
+
getCollection(dbName: TDatabaseNames, collectionName: string): admin.firestore.CollectionReference<admin.firestore.DocumentData, admin.firestore.DocumentData>;
|
|
37
|
+
/**
|
|
38
|
+
* Test database connectivity for a specific database
|
|
39
|
+
*/
|
|
40
|
+
testDatabaseConnection(dbName: TDatabaseNames): Promise<boolean>;
|
|
41
|
+
/**
|
|
42
|
+
* Test all database connections
|
|
43
|
+
*/
|
|
44
|
+
testAllDatabaseConnections(): Promise<DatabaseConnectionResult<TDatabaseNames>>;
|
|
45
|
+
/**
|
|
46
|
+
* Health check for Firebase connection
|
|
47
|
+
*/
|
|
48
|
+
healthCheck(): Promise<HealthCheckResult<TDatabaseNames>>;
|
|
49
|
+
/**
|
|
50
|
+
* Gracefully close Firebase connections
|
|
51
|
+
*/
|
|
52
|
+
closeConnections(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Get current Firebase connection state
|
|
55
|
+
*/
|
|
56
|
+
getConnectionState(): FirebaseConnectionState;
|
|
57
|
+
/**
|
|
58
|
+
* Reset connection state (useful for testing)
|
|
59
|
+
*/
|
|
60
|
+
resetConnectionState(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Check if Firebase is properly initialized
|
|
63
|
+
*/
|
|
64
|
+
isInitialized(): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Get available database names from configuration
|
|
67
|
+
*/
|
|
68
|
+
getDatabaseNames(): TDatabaseNames[];
|
|
69
|
+
/**
|
|
70
|
+
* Get collections for a specific database
|
|
71
|
+
*/
|
|
72
|
+
getCollectionsForDatabase(dbName: TDatabaseNames): string[];
|
|
73
|
+
/**
|
|
74
|
+
* Get all collections across all databases
|
|
75
|
+
*/
|
|
76
|
+
getAllCollections(): Record<TDatabaseNames, string[]>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Factory function to create a simple single-database connector
|
|
80
|
+
*/
|
|
81
|
+
export declare const createSingleDatabaseConnector: (_projectId: string, collections: string[], options?: FirebaseInitOptions) => FirestoreConnector<"main">;
|
|
82
|
+
/**
|
|
83
|
+
* Factory function to create a multi-database connector with custom names
|
|
84
|
+
*/
|
|
85
|
+
export declare const createMultiDatabaseConnector: <T extends string>(config: DatabaseConfig<T>, options?: FirebaseInitOptions) => FirestoreConnector<T>;
|
|
86
|
+
//# sourceMappingURL=firestore-connector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firestore-connector.d.ts","sourceRoot":"","sources":["../src/firestore-connector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AAGxC,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,EAEjB,uBAAuB,EAGvB,mBAAmB,EAInB,SAAS,EACV,MAAM,kBAAkB,CAAC;AAE1B;;;GAGG;AACH,qBAAa,kBAAkB,CAAC,cAAc,SAAS,MAAM,GAAG,MAAM;IAUlE,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,OAAO;IAVjB,OAAO,CAAC,WAAW,CAAkD;IACrE,OAAO,CAAC,eAAe,CAKrB;gBAGQ,MAAM,EAAE,cAAc,CAAC,cAAc,CAAC,EACtC,OAAO,GAAE,mBAAwB;IAG3C;;OAEG;IACI,kBAAkB,IAAI,IAAI;IA8CjC;;OAEG;IACH,OAAO,CAAC,2BAA2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
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.createMultiDatabaseConnector = exports.createSingleDatabaseConnector = exports.FirestoreConnector = void 0;
|
|
37
|
+
/**
|
|
38
|
+
* Generic Firebase configuration and database access utility
|
|
39
|
+
* Clean implementation without legacy compatibility
|
|
40
|
+
*/
|
|
41
|
+
const admin = __importStar(require("firebase-admin"));
|
|
42
|
+
const firestore_1 = require("firebase-admin/firestore");
|
|
43
|
+
const utils_logger_1 = require("@xbg/utils-logger");
|
|
44
|
+
const firebase_types_1 = require("./firebase-types");
|
|
45
|
+
/**
|
|
46
|
+
* Generic Firestore Connector Class
|
|
47
|
+
* Can be configured for any project's database schema
|
|
48
|
+
*/
|
|
49
|
+
class FirestoreConnector {
|
|
50
|
+
constructor(config, options = {}) {
|
|
51
|
+
this.config = config;
|
|
52
|
+
this.options = options;
|
|
53
|
+
this.dbInstances = null;
|
|
54
|
+
this.connectionState = {
|
|
55
|
+
initialized: false,
|
|
56
|
+
connected: false,
|
|
57
|
+
databasesInitialized: false,
|
|
58
|
+
connectionErrors: []
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Initialize Firebase Admin SDK with service account
|
|
63
|
+
*/
|
|
64
|
+
initializeFirebase() {
|
|
65
|
+
try {
|
|
66
|
+
// Check if already initialized (unless forcing reinitialize)
|
|
67
|
+
if (!this.options.forceReinitialize) {
|
|
68
|
+
try {
|
|
69
|
+
admin.app();
|
|
70
|
+
this.connectionState.initialized = true;
|
|
71
|
+
utils_logger_1.logger.debug('Firebase already initialized');
|
|
72
|
+
}
|
|
73
|
+
catch (_a) {
|
|
74
|
+
// Not initialized, continue with initialization
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (!this.connectionState.initialized || this.options.forceReinitialize) {
|
|
78
|
+
const environment = (0, firebase_types_1.detectEnvironment)();
|
|
79
|
+
if (environment.isFunctionsEnvironment) {
|
|
80
|
+
// Use default initialization for Firebase Functions
|
|
81
|
+
admin.initializeApp();
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const firebaseConfig = (0, firebase_types_1.getFirebaseConfigFromEnv)();
|
|
85
|
+
admin.initializeApp({
|
|
86
|
+
credential: admin.credential.applicationDefault(),
|
|
87
|
+
projectId: firebaseConfig.projectId,
|
|
88
|
+
databaseURL: firebaseConfig.databaseURL,
|
|
89
|
+
storageBucket: firebaseConfig.storageBucket,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
this.connectionState.initialized = true;
|
|
93
|
+
this.connectionState.connected = true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
const firebaseError = (0, firebase_types_1.toError)(error);
|
|
98
|
+
this.connectionState.connectionErrors = this.connectionState.connectionErrors || [];
|
|
99
|
+
this.connectionState.connectionErrors.push(firebaseError);
|
|
100
|
+
throw firebaseError;
|
|
101
|
+
}
|
|
102
|
+
// Initialize database instances if not skipped
|
|
103
|
+
if (!this.options.skipDatabaseInit) {
|
|
104
|
+
this.initializeDatabaseInstances();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Initialize database instances based on configuration
|
|
109
|
+
*/
|
|
110
|
+
initializeDatabaseInstances() {
|
|
111
|
+
try {
|
|
112
|
+
const environment = (0, firebase_types_1.detectEnvironment)();
|
|
113
|
+
const dbInstances = {};
|
|
114
|
+
if (environment.isEmulator) {
|
|
115
|
+
// Emulator doesn't support multiple databases - use same instance for all
|
|
116
|
+
const db = (0, firestore_1.getFirestore)();
|
|
117
|
+
for (const dbName of this.getDatabaseNames()) {
|
|
118
|
+
dbInstances[dbName] = db;
|
|
119
|
+
}
|
|
120
|
+
utils_logger_1.logger.warn('Running in emulator mode - all databases point to same Firestore instance', {
|
|
121
|
+
operation: 'initializeDatabaseInstances',
|
|
122
|
+
emulator: true,
|
|
123
|
+
databases: this.getDatabaseNames()
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
// Production: Use named databases
|
|
128
|
+
for (const [dbName, dbConfig] of Object.entries(this.config)) {
|
|
129
|
+
const firestoreName = dbConfig.firestoreName || dbName;
|
|
130
|
+
dbInstances[dbName] = (0, firestore_1.getFirestore)(admin.app(), firestoreName);
|
|
131
|
+
}
|
|
132
|
+
utils_logger_1.logger.info(`Initialized ${this.getDatabaseNames().length} named Firestore databases`, {
|
|
133
|
+
operation: 'initializeDatabaseInstances',
|
|
134
|
+
production: true,
|
|
135
|
+
databases: this.getDatabaseNames()
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
this.dbInstances = dbInstances;
|
|
139
|
+
this.connectionState.databasesInitialized = true;
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
const firebaseError = (0, firebase_types_1.toError)(error);
|
|
143
|
+
this.connectionState.connectionErrors = this.connectionState.connectionErrors || [];
|
|
144
|
+
this.connectionState.connectionErrors.push(firebaseError);
|
|
145
|
+
throw firebaseError;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Get all database instances, initializing if necessary
|
|
150
|
+
*/
|
|
151
|
+
getDb() {
|
|
152
|
+
if (!this.dbInstances) {
|
|
153
|
+
this.initializeFirebase();
|
|
154
|
+
}
|
|
155
|
+
if (!this.dbInstances) {
|
|
156
|
+
throw new Error('Failed to initialize Firebase database instances');
|
|
157
|
+
}
|
|
158
|
+
return this.dbInstances;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Get specific database instance by name
|
|
162
|
+
*/
|
|
163
|
+
getDbByName(dbName) {
|
|
164
|
+
const databases = this.getDb();
|
|
165
|
+
const db = databases[dbName];
|
|
166
|
+
if (!db) {
|
|
167
|
+
throw new Error(`Database instance '${String(dbName)}' not found`);
|
|
168
|
+
}
|
|
169
|
+
return db;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Get database instance with collection reference for convenience
|
|
173
|
+
*/
|
|
174
|
+
getCollection(dbName, collectionName) {
|
|
175
|
+
const db = this.getDbByName(dbName);
|
|
176
|
+
return db.collection(collectionName);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Test database connectivity for a specific database
|
|
180
|
+
*/
|
|
181
|
+
async testDatabaseConnection(dbName) {
|
|
182
|
+
const baseContext = {
|
|
183
|
+
operation: 'testDatabaseConnection',
|
|
184
|
+
dbName: String(dbName),
|
|
185
|
+
firebaseOperation: firebase_types_1.FirebaseOperation.CONNECTION_TEST,
|
|
186
|
+
connectionTest: true
|
|
187
|
+
};
|
|
188
|
+
try {
|
|
189
|
+
const db = this.getDbByName(dbName);
|
|
190
|
+
// Test by writing and reading a test document
|
|
191
|
+
const testCollection = 'connection-test';
|
|
192
|
+
const testDocId = `test-${Date.now()}`;
|
|
193
|
+
const testData = {
|
|
194
|
+
timestamp: admin.firestore.FieldValue.serverTimestamp(),
|
|
195
|
+
test: true,
|
|
196
|
+
database: String(dbName)
|
|
197
|
+
};
|
|
198
|
+
// Write test document
|
|
199
|
+
await db.collection(testCollection).doc(testDocId).set(testData);
|
|
200
|
+
utils_logger_1.logger.debug('Test document written', Object.assign(Object.assign({}, baseContext), { collection: testCollection, docId: testDocId, firebaseOperation: firebase_types_1.FirebaseOperation.WRITE }));
|
|
201
|
+
// Read test document
|
|
202
|
+
const doc = await db.collection(testCollection).doc(testDocId).get();
|
|
203
|
+
if (!doc.exists) {
|
|
204
|
+
throw new Error('Test document not found after write');
|
|
205
|
+
}
|
|
206
|
+
// Clean up test document
|
|
207
|
+
await db.collection(testCollection).doc(testDocId).delete();
|
|
208
|
+
utils_logger_1.logger.debug('Test document cleaned up', Object.assign(Object.assign({}, baseContext), { collection: testCollection, docId: testDocId, firebaseOperation: firebase_types_1.FirebaseOperation.DELETE }));
|
|
209
|
+
utils_logger_1.logger.info(`Database connection test passed for ${String(dbName)}`, baseContext);
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
const firebaseError = (0, firebase_types_1.toError)(error);
|
|
214
|
+
utils_logger_1.logger.error(`Database connection test failed for ${String(dbName)}`, firebaseError, baseContext);
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Test all database connections
|
|
220
|
+
*/
|
|
221
|
+
async testAllDatabaseConnections() {
|
|
222
|
+
const context = {
|
|
223
|
+
operation: 'testAllDatabaseConnections',
|
|
224
|
+
firebaseOperation: firebase_types_1.FirebaseOperation.CONNECTION_TEST
|
|
225
|
+
};
|
|
226
|
+
utils_logger_1.logger.info('Testing all database connections', context);
|
|
227
|
+
const databases = this.getDb();
|
|
228
|
+
const results = {};
|
|
229
|
+
for (const dbName of Object.keys(databases)) {
|
|
230
|
+
try {
|
|
231
|
+
results[dbName] = await this.testDatabaseConnection(dbName);
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
const firebaseError = (0, firebase_types_1.toError)(error);
|
|
235
|
+
utils_logger_1.logger.error(`Failed to test database connection for ${String(dbName)}`, firebaseError, Object.assign(Object.assign({}, context), { dbName: String(dbName) }));
|
|
236
|
+
results[dbName] = false;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const successCount = Object.values(results).filter(Boolean).length;
|
|
240
|
+
const totalCount = Object.keys(results).length;
|
|
241
|
+
if (successCount === totalCount) {
|
|
242
|
+
utils_logger_1.logger.info(`All ${totalCount} database connections tested successfully`, Object.assign(Object.assign({}, context), { metadata: { results, successCount, totalCount } }));
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
utils_logger_1.logger.warn(`Database connection tests: ${successCount}/${totalCount} passed`, Object.assign(Object.assign({}, context), { metadata: { results, successCount, totalCount } }));
|
|
246
|
+
}
|
|
247
|
+
return results;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Health check for Firebase connection
|
|
251
|
+
*/
|
|
252
|
+
async healthCheck() {
|
|
253
|
+
const context = {
|
|
254
|
+
operation: 'healthCheck',
|
|
255
|
+
firebaseOperation: firebase_types_1.FirebaseOperation.HEALTH_CHECK,
|
|
256
|
+
healthCheck: true
|
|
257
|
+
};
|
|
258
|
+
try {
|
|
259
|
+
// Test Firebase admin connectivity
|
|
260
|
+
const app = admin.app();
|
|
261
|
+
const firebaseHealthy = !!app;
|
|
262
|
+
// Test all database connections
|
|
263
|
+
const databaseResults = await this.testAllDatabaseConnections();
|
|
264
|
+
const result = {
|
|
265
|
+
firebase: firebaseHealthy,
|
|
266
|
+
databases: databaseResults,
|
|
267
|
+
timestamp: new Date()
|
|
268
|
+
};
|
|
269
|
+
this.connectionState.lastHealthCheck = result.timestamp;
|
|
270
|
+
utils_logger_1.logger.info('Firebase health check completed', Object.assign(Object.assign({}, context), { metadata: { result } }));
|
|
271
|
+
return result;
|
|
272
|
+
}
|
|
273
|
+
catch (error) {
|
|
274
|
+
const firebaseError = (0, firebase_types_1.toError)(error);
|
|
275
|
+
utils_logger_1.logger.error('Firebase health check failed', firebaseError, context);
|
|
276
|
+
throw firebaseError;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Gracefully close Firebase connections
|
|
281
|
+
*/
|
|
282
|
+
async closeConnections() {
|
|
283
|
+
const context = {
|
|
284
|
+
operation: 'closeConnections',
|
|
285
|
+
firebaseOperation: firebase_types_1.FirebaseOperation.DISCONNECT
|
|
286
|
+
};
|
|
287
|
+
try {
|
|
288
|
+
if (this.dbInstances) {
|
|
289
|
+
// Firebase Admin SDK doesn't require explicit connection closing
|
|
290
|
+
// but we can clean up our references
|
|
291
|
+
this.dbInstances = null;
|
|
292
|
+
this.connectionState.databasesInitialized = false;
|
|
293
|
+
utils_logger_1.logger.info('Firebase database instances cleared', context);
|
|
294
|
+
}
|
|
295
|
+
// Delete the default app to fully clean up
|
|
296
|
+
await admin.app().delete();
|
|
297
|
+
this.connectionState.initialized = false;
|
|
298
|
+
this.connectionState.connected = false;
|
|
299
|
+
utils_logger_1.logger.info('Firebase connections closed successfully', context);
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
const firebaseError = (0, firebase_types_1.toError)(error);
|
|
303
|
+
utils_logger_1.logger.error('Error closing Firebase connections', firebaseError, context);
|
|
304
|
+
throw firebaseError;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Get current Firebase connection state
|
|
309
|
+
*/
|
|
310
|
+
getConnectionState() {
|
|
311
|
+
return Object.assign({}, this.connectionState);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Reset connection state (useful for testing)
|
|
315
|
+
*/
|
|
316
|
+
resetConnectionState() {
|
|
317
|
+
this.connectionState = {
|
|
318
|
+
initialized: false,
|
|
319
|
+
connected: false,
|
|
320
|
+
databasesInitialized: false,
|
|
321
|
+
connectionErrors: []
|
|
322
|
+
};
|
|
323
|
+
this.dbInstances = null;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Check if Firebase is properly initialized
|
|
327
|
+
*/
|
|
328
|
+
isInitialized() {
|
|
329
|
+
return this.connectionState.initialized &&
|
|
330
|
+
this.connectionState.databasesInitialized &&
|
|
331
|
+
this.dbInstances !== null;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Get available database names from configuration
|
|
335
|
+
*/
|
|
336
|
+
getDatabaseNames() {
|
|
337
|
+
return Object.keys(this.config);
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Get collections for a specific database
|
|
341
|
+
*/
|
|
342
|
+
getCollectionsForDatabase(dbName) {
|
|
343
|
+
const dbConfig = this.config[dbName];
|
|
344
|
+
if (!dbConfig) {
|
|
345
|
+
throw new Error(`Database configuration for '${String(dbName)}' not found`);
|
|
346
|
+
}
|
|
347
|
+
return dbConfig.collections;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Get all collections across all databases
|
|
351
|
+
*/
|
|
352
|
+
getAllCollections() {
|
|
353
|
+
const result = {};
|
|
354
|
+
for (const [dbName, dbConfig] of Object.entries(this.config)) {
|
|
355
|
+
result[dbName] = dbConfig.collections;
|
|
356
|
+
}
|
|
357
|
+
return result;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
exports.FirestoreConnector = FirestoreConnector;
|
|
361
|
+
/**
|
|
362
|
+
* Factory function to create a simple single-database connector
|
|
363
|
+
*/
|
|
364
|
+
const createSingleDatabaseConnector = (_projectId, collections, options = {}) => {
|
|
365
|
+
const config = {
|
|
366
|
+
main: {
|
|
367
|
+
collections,
|
|
368
|
+
emulatorSupport: true
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
return new FirestoreConnector(config, options);
|
|
372
|
+
};
|
|
373
|
+
exports.createSingleDatabaseConnector = createSingleDatabaseConnector;
|
|
374
|
+
/**
|
|
375
|
+
* Factory function to create a multi-database connector with custom names
|
|
376
|
+
*/
|
|
377
|
+
const createMultiDatabaseConnector = (config, options = {}) => {
|
|
378
|
+
return new FirestoreConnector(config, options);
|
|
379
|
+
};
|
|
380
|
+
exports.createMultiDatabaseConnector = createMultiDatabaseConnector;
|
|
381
|
+
//# sourceMappingURL=firestore-connector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firestore-connector.js","sourceRoot":"","sources":["../src/firestore-connector.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;GAGG;AACH,sDAAwC;AACxC,wDAAwD;AACxD,oDAA2C;AAC3C,qDAc0B;AAE1B;;;GAGG;AACH,MAAa,kBAAkB;IAS7B,YACU,MAAsC,EACtC,UAA+B,EAAE;QADjC,WAAM,GAAN,MAAM,CAAgC;QACtC,YAAO,GAAP,OAAO,CAA0B;QAVnC,gBAAW,GAA6C,IAAI,CAAC;QAC7D,oBAAe,GAA4B;YACjD,WAAW,EAAE,KAAK;YAClB,SAAS,EAAE,KAAK;YAChB,oBAAoB,EAAE,KAAK;YAC3B,gBAAgB,EAAE,EAAE;SACrB,CAAC;IAKC,CAAC;IAEJ;;OAEG;IACI,kBAAkB;QACvB,IAAI,CAAC;YACH,6DAA6D;YAC7D,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC;gBACpC,IAAI,CAAC;oBACH,KAAK,CAAC,GAAG,EAAE,CAAC;oBACZ,IAAI,CA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WAAW;YACX,eAAe,EAAE,IAAI;SACtB;KACF,CAAC;IAEF,OAAO,IAAI,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACjD,CAAC,CAAC;AAbW,QAAA,6BAA6B,iCAaxC;AAEF;;GAEG;AACI,MAAM,4BAA4B,GAAG,CAC1C,MAAyB,EACzB,UAA+B,EAAE,EACV,EAAE;IACzB,OAAO,IAAI,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACjD,CAAC,CAAC;AALW,QAAA,4BAA4B,gCAKvC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,cAAc,kBAAkB,CAAC;AAGjC,cAAc,uBAAuB,CAAC;AAGtC,cAAc,YAAY,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Firebase utilities barrel export
|
|
4
|
+
* Clean API without legacy compatibility
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
18
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
// Core types and utilities
|
|
22
|
+
__exportStar(require("./firebase-types"), exports);
|
|
23
|
+
// Generic connector implementation
|
|
24
|
+
__exportStar(require("./firestore-connector"), exports);
|
|
25
|
+
// Firebase Admin SDK initialization
|
|
26
|
+
__exportStar(require("./firebase"), exports);
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;AAEH,2BAA2B;AAC3B,mDAAiC;AAEjC,mCAAmC;AACnC,wDAAsC;AAEtC,oCAAoC;AACpC,6CAA2B"}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xbg.solutions/utils-firestore-connector",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Multi-database Firestore access",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"build:watch": "tsc --watch",
|
|
13
|
+
"clean": "rm -rf lib",
|
|
14
|
+
"prepublishOnly": "npm run build"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@xbg/utils-logger": "^1.0.0",
|
|
18
|
+
"firebase-admin": "^12.0.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "^20.11.0",
|
|
22
|
+
"typescript": "^5.3.3"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": "22"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
}
|
|
30
|
+
}
|