@almadar/server 1.2.1 → 1.3.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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { E as EventBus, a as EventLogEntry, c as closeWebSocketServer, d as db, e as emitEntityEvent, b as env, g as getAuth, f as getConnectedClientCount, h as getFirestore, i as getWebSocketServer, l as logger, s as serverEventBus, j as setupEventBroadcast } from './index-BGC2yptv.js';
1
+ export { E as EventBus, a as EventLogEntry, c as closeWebSocketServer, d as db, e as emitEntityEvent, b as env, g as getAuth, f as getConnectedClientCount, h as getFirestore, i as getWebSocketServer, j as initializeFirebase, l as logger, s as serverEventBus, k as setupEventBroadcast } from './index-B64ll_cY.js';
2
2
  import { Router } from 'express';
3
3
  export { AppError, ConflictError, ForbiddenError, NotFoundError, UnauthorizedError, ValidationError, asyncHandler, authenticateFirebase, errorHandler, notFoundHandler, validateBody, validateParams, validateQuery } from './middleware/index.js';
4
4
  export { D as DataService, E as EntitySchema, a as EntitySeedConfig, F as FieldSchema, M as MockDataService, P as PaginatedResult, b as PaginationOptions, d as dataService, m as mockDataService, s as seedMockData } from './index-D8fohXsO.js';
package/dist/index.js CHANGED
@@ -197,66 +197,70 @@ function debugEventsRouter() {
197
197
  });
198
198
  return router2;
199
199
  }
200
- var firebaseApp = null;
201
200
  function initializeFirebase() {
202
- if (firebaseApp) {
203
- return firebaseApp;
204
- }
205
201
  if (admin.apps.length > 0) {
206
- firebaseApp = admin.apps[0];
207
- return firebaseApp;
202
+ return admin.app();
208
203
  }
209
- if (env.FIRESTORE_EMULATOR_HOST) {
210
- firebaseApp = admin.initializeApp({
211
- projectId: env.FIREBASE_PROJECT_ID || "demo-project"
204
+ const projectId = process.env.FIREBASE_PROJECT_ID;
205
+ const emulatorHost = process.env.FIRESTORE_EMULATOR_HOST;
206
+ if (emulatorHost) {
207
+ const app = admin.initializeApp({
208
+ projectId: projectId || "demo-project"
212
209
  });
213
- console.log(`\u{1F527} Firebase Admin initialized for emulator: ${env.FIRESTORE_EMULATOR_HOST}`);
214
- return firebaseApp;
210
+ console.log(`Firebase Admin initialized for emulator: ${emulatorHost}`);
211
+ return app;
215
212
  }
216
- const serviceAccountPath = env.FIREBASE_SERVICE_ACCOUNT_PATH;
213
+ const serviceAccountPath = process.env.FIREBASE_SERVICE_ACCOUNT_PATH;
217
214
  if (serviceAccountPath) {
218
215
  const serviceAccount = __require(serviceAccountPath);
219
- firebaseApp = admin.initializeApp({
216
+ return admin.initializeApp({
220
217
  credential: admin.credential.cert(serviceAccount),
221
- projectId: env.FIREBASE_PROJECT_ID
218
+ projectId
222
219
  });
223
- } else if (env.FIREBASE_PROJECT_ID && env.FIREBASE_CLIENT_EMAIL && env.FIREBASE_PRIVATE_KEY) {
224
- firebaseApp = admin.initializeApp({
220
+ }
221
+ const clientEmail = process.env.FIREBASE_CLIENT_EMAIL;
222
+ const privateKey = process.env.FIREBASE_PRIVATE_KEY;
223
+ if (projectId && clientEmail && privateKey) {
224
+ return admin.initializeApp({
225
225
  credential: admin.credential.cert({
226
- projectId: env.FIREBASE_PROJECT_ID,
227
- clientEmail: env.FIREBASE_CLIENT_EMAIL,
228
- privateKey: env.FIREBASE_PRIVATE_KEY.replace(/\\n/g, "\n")
226
+ projectId,
227
+ clientEmail,
228
+ privateKey: privateKey.replace(/\\n/g, "\n")
229
229
  }),
230
- projectId: env.FIREBASE_PROJECT_ID
230
+ projectId
231
231
  });
232
- } else if (env.FIREBASE_PROJECT_ID) {
233
- firebaseApp = admin.initializeApp({
232
+ }
233
+ if (projectId) {
234
+ return admin.initializeApp({
234
235
  credential: admin.credential.applicationDefault(),
235
- projectId: env.FIREBASE_PROJECT_ID
236
- });
237
- } else {
238
- firebaseApp = admin.initializeApp({
239
- projectId: "demo-project"
236
+ projectId
240
237
  });
241
238
  }
242
- return firebaseApp;
239
+ throw new Error(
240
+ "@almadar/server: Cannot initialize Firebase \u2014 no credentials found. Set FIREBASE_PROJECT_ID + FIREBASE_CLIENT_EMAIL + FIREBASE_PRIVATE_KEY, or FIREBASE_SERVICE_ACCOUNT_PATH, or FIRESTORE_EMULATOR_HOST."
241
+ );
243
242
  }
244
- function getFirestore() {
245
- const app = initializeFirebase();
246
- const db2 = app.firestore();
247
- if (env.FIRESTORE_EMULATOR_HOST) {
248
- db2.settings({
249
- host: env.FIRESTORE_EMULATOR_HOST,
250
- ssl: false
251
- });
243
+ function getApp() {
244
+ if (admin.apps.length === 0) {
245
+ throw new Error(
246
+ "@almadar/server: Firebase Admin SDK is not initialized. Call initializeFirebase() or admin.initializeApp() before using @almadar/server."
247
+ );
252
248
  }
253
- return db2;
249
+ return admin.app();
250
+ }
251
+ function getFirestore() {
252
+ return getApp().firestore();
254
253
  }
255
254
  function getAuth() {
256
- const app = initializeFirebase();
257
- return app.auth();
255
+ return getApp().auth();
258
256
  }
259
- var db = getFirestore();
257
+ var db = new Proxy({}, {
258
+ get(_target, prop, receiver) {
259
+ const firestore = getFirestore();
260
+ const value = Reflect.get(firestore, prop, receiver);
261
+ return typeof value === "function" ? value.bind(firestore) : value;
262
+ }
263
+ });
260
264
  var wss = null;
261
265
  function setupEventBroadcast(server, path = "/ws/events") {
262
266
  if (wss) {
@@ -1819,6 +1823,6 @@ router.get("/active-sessions", async (req, res) => {
1819
1823
  });
1820
1824
  var observability_default = router;
1821
1825
 
1822
- export { AppError, ChangeSetStore, ConflictError, EventBus, ForbiddenError, MockDataService, NotFoundError, SchemaProtectionService, SchemaStore, SnapshotStore, UnauthorizedError, ValidationError, ValidationStore, applyFiltersToQuery, asyncHandler, authenticateFirebase, closeWebSocketServer, createServerSkillAgent, dataService, db, debugEventsRouter, emitEntityEvent, env, errorHandler, extractPaginationParams, fromFirestoreFormat, getMemoryManager as getAgentMemoryManager, getSessionManager as getAgentSessionManager, getAuth, getConnectedClientCount, getFirestore, getMemoryManager, getSessionManager, getWebSocketServer, logger, mockDataService, multiUserMiddleware, notFoundHandler, observability_default as observabilityRouter, parseQueryFilters, resetMemoryManager, resetSessionManager, seedMockData, serverEventBus, setupEventBroadcast, setupStateSyncWebSocket, toFirestoreFormat, validateBody, validateParams, validateQuery, verifyFirebaseAuth };
1826
+ export { AppError, ChangeSetStore, ConflictError, EventBus, ForbiddenError, MockDataService, NotFoundError, SchemaProtectionService, SchemaStore, SnapshotStore, UnauthorizedError, ValidationError, ValidationStore, applyFiltersToQuery, asyncHandler, authenticateFirebase, closeWebSocketServer, createServerSkillAgent, dataService, db, debugEventsRouter, emitEntityEvent, env, errorHandler, extractPaginationParams, fromFirestoreFormat, getMemoryManager as getAgentMemoryManager, getSessionManager as getAgentSessionManager, getAuth, getConnectedClientCount, getFirestore, getMemoryManager, getSessionManager, getWebSocketServer, initializeFirebase, logger, mockDataService, multiUserMiddleware, notFoundHandler, observability_default as observabilityRouter, parseQueryFilters, resetMemoryManager, resetSessionManager, seedMockData, serverEventBus, setupEventBroadcast, setupStateSyncWebSocket, toFirestoreFormat, validateBody, validateParams, validateQuery, verifyFirebaseAuth };
1823
1827
  //# sourceMappingURL=index.js.map
1824
1828
  //# sourceMappingURL=index.js.map