@progressive-development/pd-provider-firebase-functions 0.1.0 → 0.3.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/dist/auth.d.ts CHANGED
@@ -5,7 +5,8 @@ import { AuthContext } from './types';
5
5
  */
6
6
  export declare function requireAuth(request: CallableRequest): AuthContext;
7
7
  /**
8
- * Require specific role claims
8
+ * Require specific role claims.
9
+ * Supports Firebase standard format: { admin: true, developer: true }
9
10
  */
10
11
  export declare function requireClaims(request: CallableRequest, allowedRoles: string[]): AuthContext;
11
12
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,eAAe,GAAG,WAAW,CASjE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,eAAe,EACxB,YAAY,EAAE,MAAM,EAAE,GACrB,WAAW,CASb;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,GAAG,IAAI,CAMjF"}
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,eAAe,GAAG,WAAW,CASjE;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,eAAe,EACxB,YAAY,EAAE,MAAM,EAAE,GACrB,WAAW,CAUb;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,GAAG,IAAI,CAMjF"}
package/dist/auth.js CHANGED
@@ -13,15 +13,14 @@ function requireAuth(request) {
13
13
  }
14
14
  function requireClaims(request, allowedRoles) {
15
15
  const auth = requireAuth(request);
16
- const userRoles = auth.claims.roles ?? [];
17
- if (!allowedRoles.some((role) => userRoles.includes(role))) {
18
- logger.warn("Access denied", { uid: auth.uid, required: allowedRoles });
16
+ const hasRole = allowedRoles.some((role) => auth.claims[role] === true);
17
+ if (!hasRole) {
19
18
  throw new ForbiddenError();
20
19
  }
21
20
  return auth;
22
21
  }
23
22
  function requireOwnership(auth, resourceOwnerId) {
24
- const isAdmin = (auth.claims.roles ?? []).includes("admin");
23
+ const isAdmin = auth.claims.admin === true;
25
24
  if (!isAdmin && auth.uid !== resourceOwnerId) {
26
25
  logger.warn("Ownership violation", { uid: auth.uid, resourceOwnerId });
27
26
  throw new ForbiddenError("Cannot access other user's resources");
@@ -1,6 +1,8 @@
1
1
  import { Firestore } from 'firebase-admin/firestore';
2
2
  /**
3
3
  * Get Firestore instance (cached)
4
+ *
5
+ * Uses the default Firebase app - consumer must call initializeApp() first.
4
6
  * @param databaseId Optional named database
5
7
  */
6
8
  export declare function getDb(databaseId?: string): Firestore;
@@ -1 +1 @@
1
- {"version":3,"file":"firestore.d.ts","sourceRoot":"","sources":["../src/firestore.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAKnE;;;GAGG;AACH,wBAAgB,KAAK,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAepD"}
1
+ {"version":3,"file":"firestore.d.ts","sourceRoot":"","sources":["../src/firestore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAInE;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAWpD"}
package/dist/firestore.js CHANGED
@@ -1,15 +1,10 @@
1
- import { initializeApp } from 'firebase-admin/app';
2
1
  import { getFirestore } from 'firebase-admin/firestore';
3
2
 
4
- let app;
5
3
  const dbCache = /* @__PURE__ */ new Map();
6
4
  function getDb(databaseId) {
7
5
  const cacheKey = databaseId ?? "default";
8
6
  if (!dbCache.has(cacheKey)) {
9
- if (!app) {
10
- app = initializeApp();
11
- }
12
- const db = databaseId ? getFirestore(app, databaseId) : getFirestore(app);
7
+ const db = databaseId ? getFirestore(databaseId) : getFirestore();
13
8
  db.settings({ ignoreUndefinedProperties: true });
14
9
  dbCache.set(cacheKey, db);
15
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@progressive-development/pd-provider-firebase-functions",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Firebase Functions v2 utilities for pd-spa-helper backend",
5
5
  "author": "PD Progressive Development",
6
6
  "license": "SEE LICENSE IN LICENSE",