@zssz-soft/firebase-functions-shared 1.1.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/README.md +391 -0
- package/lib/config/app.config.d.ts +106 -0
- package/lib/config/app.config.d.ts.map +1 -0
- package/lib/config/app.config.js +55 -0
- package/lib/config/app.config.js.map +1 -0
- package/lib/config/index.d.ts +2 -0
- package/lib/config/index.d.ts.map +1 -0
- package/lib/config/index.js +18 -0
- package/lib/config/index.js.map +1 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +29 -0
- package/lib/index.js.map +1 -0
- package/lib/modules/bootstrap/bootstrap.d.ts +4 -0
- package/lib/modules/bootstrap/bootstrap.d.ts.map +1 -0
- package/lib/modules/bootstrap/bootstrap.js +162 -0
- package/lib/modules/bootstrap/bootstrap.js.map +1 -0
- package/lib/modules/bootstrap/bootstrap.models.d.ts +20 -0
- package/lib/modules/bootstrap/bootstrap.models.d.ts.map +1 -0
- package/lib/modules/bootstrap/bootstrap.models.js +3 -0
- package/lib/modules/bootstrap/bootstrap.models.js.map +1 -0
- package/lib/modules/bootstrap/index.d.ts +3 -0
- package/lib/modules/bootstrap/index.d.ts.map +1 -0
- package/lib/modules/bootstrap/index.js +19 -0
- package/lib/modules/bootstrap/index.js.map +1 -0
- package/lib/modules/email/email.d.ts +5 -0
- package/lib/modules/email/email.d.ts.map +1 -0
- package/lib/modules/email/email.js +105 -0
- package/lib/modules/email/email.js.map +1 -0
- package/lib/modules/email/email.models.d.ts +25 -0
- package/lib/modules/email/email.models.d.ts.map +1 -0
- package/lib/modules/email/email.models.js +3 -0
- package/lib/modules/email/email.models.js.map +1 -0
- package/lib/modules/email/email.service.d.ts +11 -0
- package/lib/modules/email/email.service.d.ts.map +1 -0
- package/lib/modules/email/email.service.js +227 -0
- package/lib/modules/email/email.service.js.map +1 -0
- package/lib/modules/email/email.validator.d.ts +2 -0
- package/lib/modules/email/email.validator.d.ts.map +1 -0
- package/lib/modules/email/email.validator.js +9 -0
- package/lib/modules/email/email.validator.js.map +1 -0
- package/lib/modules/email/index.d.ts +5 -0
- package/lib/modules/email/index.d.ts.map +1 -0
- package/lib/modules/email/index.js +21 -0
- package/lib/modules/email/index.js.map +1 -0
- package/lib/modules/security/effective-permissions.d.ts +28 -0
- package/lib/modules/security/effective-permissions.d.ts.map +1 -0
- package/lib/modules/security/effective-permissions.js +133 -0
- package/lib/modules/security/effective-permissions.js.map +1 -0
- package/lib/modules/security/effective-permissions.models.d.ts +96 -0
- package/lib/modules/security/effective-permissions.models.d.ts.map +1 -0
- package/lib/modules/security/effective-permissions.models.js +24 -0
- package/lib/modules/security/effective-permissions.models.js.map +1 -0
- package/lib/modules/security/effective-permissions.triggers.d.ts +83 -0
- package/lib/modules/security/effective-permissions.triggers.d.ts.map +1 -0
- package/lib/modules/security/effective-permissions.triggers.js +307 -0
- package/lib/modules/security/effective-permissions.triggers.js.map +1 -0
- package/lib/modules/security/index.d.ts +10 -0
- package/lib/modules/security/index.d.ts.map +1 -0
- package/lib/modules/security/index.js +28 -0
- package/lib/modules/security/index.js.map +1 -0
- package/lib/modules/storage/index.d.ts +2 -0
- package/lib/modules/storage/index.d.ts.map +1 -0
- package/lib/modules/storage/index.js +18 -0
- package/lib/modules/storage/index.js.map +1 -0
- package/lib/modules/storage/thumbnail-functions.d.ts +10 -0
- package/lib/modules/storage/thumbnail-functions.d.ts.map +1 -0
- package/lib/modules/storage/thumbnail-functions.js +482 -0
- package/lib/modules/storage/thumbnail-functions.js.map +1 -0
- package/lib/modules/user/index.d.ts +4 -0
- package/lib/modules/user/index.d.ts.map +1 -0
- package/lib/modules/user/index.js +20 -0
- package/lib/modules/user/index.js.map +1 -0
- package/lib/modules/user/user-management.d.ts +29 -0
- package/lib/modules/user/user-management.d.ts.map +1 -0
- package/lib/modules/user/user-management.js +134 -0
- package/lib/modules/user/user-management.js.map +1 -0
- package/lib/modules/user/user.d.ts +2 -0
- package/lib/modules/user/user.d.ts.map +1 -0
- package/lib/modules/user/user.js +15 -0
- package/lib/modules/user/user.js.map +1 -0
- package/lib/modules/user/user.models.d.ts +15 -0
- package/lib/modules/user/user.models.d.ts.map +1 -0
- package/lib/modules/user/user.models.js +6 -0
- package/lib/modules/user/user.models.js.map +1 -0
- package/package.json +72 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email.validator.d.ts","sourceRoot":"","sources":["../../../src/modules/email/email.validator.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,KAAG,OAE7C,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateEmail = void 0;
|
|
4
|
+
const emailRegex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
5
|
+
const validateEmail = (email) => {
|
|
6
|
+
return emailRegex.test(email);
|
|
7
|
+
};
|
|
8
|
+
exports.validateEmail = validateEmail;
|
|
9
|
+
//# sourceMappingURL=email.validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email.validator.js","sourceRoot":"","sources":["../../../src/modules/email/email.validator.ts"],"names":[],"mappings":";;;AAAA,MAAM,UAAU,GACd,sIAAsI,CAAC;AAElI,MAAM,aAAa,GAAG,CAAC,KAAa,EAAW,EAAE;IACtD,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC,CAAC;AAFW,QAAA,aAAa,iBAExB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/email/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./email"), exports);
|
|
18
|
+
__exportStar(require("./email.models"), exports);
|
|
19
|
+
__exportStar(require("./email.service"), exports);
|
|
20
|
+
__exportStar(require("./email.validator"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/email/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,iDAA+B;AAC/B,kDAAgC;AAChC,oDAAkC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Effective Permissions Core Logic
|
|
3
|
+
*
|
|
4
|
+
* Provides functions to calculate and cache effective permissions for users.
|
|
5
|
+
*/
|
|
6
|
+
import { EffectivePermissionsConfig } from './effective-permissions.models';
|
|
7
|
+
/**
|
|
8
|
+
* Calculate and cache effective permissions for a user
|
|
9
|
+
*
|
|
10
|
+
* @param userId - The user ID to calculate permissions for
|
|
11
|
+
* @param config - Configuration options (uses defaults if not provided)
|
|
12
|
+
*/
|
|
13
|
+
export declare function calculateEffectivePermissions(userId: string, config?: Partial<EffectivePermissionsConfig>): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Delete effective permissions cache for a user
|
|
16
|
+
*
|
|
17
|
+
* @param userId - The user ID to delete permissions for
|
|
18
|
+
* @param config - Configuration options (uses defaults if not provided)
|
|
19
|
+
*/
|
|
20
|
+
export declare function deleteEffectivePermissions(userId: string, config?: Partial<EffectivePermissionsConfig>): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Batch update effective permissions for multiple users
|
|
23
|
+
*
|
|
24
|
+
* @param userIds - Array of user IDs to update
|
|
25
|
+
* @param config - Configuration options (uses defaults if not provided)
|
|
26
|
+
*/
|
|
27
|
+
export declare function batchUpdateEffectivePermissions(userIds: string[], config?: Partial<EffectivePermissionsConfig>): Promise<void>;
|
|
28
|
+
//# sourceMappingURL=effective-permissions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effective-permissions.d.ts","sourceRoot":"","sources":["../../../src/modules/security/effective-permissions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,0BAA0B,EAG3B,MAAM,gCAAgC,CAAC;AAExC;;;;;GAKG;AACH,wBAAsB,6BAA6B,CACjD,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,OAAO,CAAC,0BAA0B,CAAM,GAC/C,OAAO,CAAC,IAAI,CAAC,CAyDf;AAED;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,OAAO,CAAC,0BAA0B,CAAM,GAC/C,OAAO,CAAC,IAAI,CAAC,CAYf;AAED;;;;;GAKG;AACH,wBAAsB,+BAA+B,CACnD,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,GAAE,OAAO,CAAC,0BAA0B,CAAM,GAC/C,OAAO,CAAC,IAAI,CAAC,CAiBf"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Effective Permissions Core Logic
|
|
4
|
+
*
|
|
5
|
+
* Provides functions to calculate and cache effective permissions for users.
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.calculateEffectivePermissions = calculateEffectivePermissions;
|
|
42
|
+
exports.deleteEffectivePermissions = deleteEffectivePermissions;
|
|
43
|
+
exports.batchUpdateEffectivePermissions = batchUpdateEffectivePermissions;
|
|
44
|
+
const admin = __importStar(require("firebase-admin"));
|
|
45
|
+
const effective_permissions_models_1 = require("./effective-permissions.models");
|
|
46
|
+
/**
|
|
47
|
+
* Calculate and cache effective permissions for a user
|
|
48
|
+
*
|
|
49
|
+
* @param userId - The user ID to calculate permissions for
|
|
50
|
+
* @param config - Configuration options (uses defaults if not provided)
|
|
51
|
+
*/
|
|
52
|
+
async function calculateEffectivePermissions(userId, config = {}) {
|
|
53
|
+
const cfg = Object.assign(Object.assign({}, effective_permissions_models_1.DEFAULT_EFFECTIVE_PERMISSIONS_CONFIG), config);
|
|
54
|
+
const db = admin.firestore();
|
|
55
|
+
// Fetch user document
|
|
56
|
+
const userDoc = await db.collection(cfg.userCollection).doc(userId).get();
|
|
57
|
+
if (!userDoc.exists) {
|
|
58
|
+
console.warn(`User ${userId} does not exist, skipping permission calculation`);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const userData = userDoc.data();
|
|
62
|
+
const roleIds = userData[cfg.userRoleIdsField] || [];
|
|
63
|
+
// Fetch all roles for this user
|
|
64
|
+
const rolePromises = roleIds.map((roleId) => db.collection(cfg.roleCollection).doc(roleId).get());
|
|
65
|
+
const roleDocs = await Promise.all(rolePromises);
|
|
66
|
+
// Aggregate permissions and role names
|
|
67
|
+
const allPermissions = new Set();
|
|
68
|
+
const roleNames = [];
|
|
69
|
+
for (const roleDoc of roleDocs) {
|
|
70
|
+
if (roleDoc.exists) {
|
|
71
|
+
const roleData = roleDoc.data();
|
|
72
|
+
const roleName = roleData[cfg.roleNameField];
|
|
73
|
+
const permissions = roleData[cfg.rolePermissionsField] || [];
|
|
74
|
+
if (roleName) {
|
|
75
|
+
roleNames.push(roleName);
|
|
76
|
+
}
|
|
77
|
+
if (Array.isArray(permissions)) {
|
|
78
|
+
permissions.forEach((p) => allPermissions.add(p));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Create effective permissions document
|
|
83
|
+
const effectivePermissions = {
|
|
84
|
+
permissions: Array.from(allPermissions).sort(),
|
|
85
|
+
roles: roleNames.sort(),
|
|
86
|
+
lastUpdated: admin.firestore.FieldValue.serverTimestamp(),
|
|
87
|
+
};
|
|
88
|
+
// Write to cache location: security/users/{userId}/effective_permissions
|
|
89
|
+
await db
|
|
90
|
+
.collection(cfg.securityCollection)
|
|
91
|
+
.doc('users')
|
|
92
|
+
.collection(userId)
|
|
93
|
+
.doc('effective_permissions')
|
|
94
|
+
.set(effectivePermissions, { merge: false });
|
|
95
|
+
console.log(`Updated effective permissions for user ${userId}: ${effectivePermissions.permissions.length} permissions, ${effectivePermissions.roles.length} roles`);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Delete effective permissions cache for a user
|
|
99
|
+
*
|
|
100
|
+
* @param userId - The user ID to delete permissions for
|
|
101
|
+
* @param config - Configuration options (uses defaults if not provided)
|
|
102
|
+
*/
|
|
103
|
+
async function deleteEffectivePermissions(userId, config = {}) {
|
|
104
|
+
const cfg = Object.assign(Object.assign({}, effective_permissions_models_1.DEFAULT_EFFECTIVE_PERMISSIONS_CONFIG), config);
|
|
105
|
+
const db = admin.firestore();
|
|
106
|
+
await db
|
|
107
|
+
.collection(cfg.securityCollection)
|
|
108
|
+
.doc('users')
|
|
109
|
+
.collection(userId)
|
|
110
|
+
.doc('effective_permissions')
|
|
111
|
+
.delete();
|
|
112
|
+
console.log(`Deleted effective permissions for user ${userId}`);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Batch update effective permissions for multiple users
|
|
116
|
+
*
|
|
117
|
+
* @param userIds - Array of user IDs to update
|
|
118
|
+
* @param config - Configuration options (uses defaults if not provided)
|
|
119
|
+
*/
|
|
120
|
+
async function batchUpdateEffectivePermissions(userIds, config = {}) {
|
|
121
|
+
const cfg = Object.assign(Object.assign({}, effective_permissions_models_1.DEFAULT_EFFECTIVE_PERMISSIONS_CONFIG), config);
|
|
122
|
+
const BATCH_SIZE = cfg.batchSize;
|
|
123
|
+
console.log(`Batch updating ${userIds.length} users (batch size: ${BATCH_SIZE})`);
|
|
124
|
+
for (let i = 0; i < userIds.length; i += BATCH_SIZE) {
|
|
125
|
+
const batch = userIds.slice(i, i + BATCH_SIZE);
|
|
126
|
+
const batchNumber = Math.floor(i / BATCH_SIZE) + 1;
|
|
127
|
+
const totalBatches = Math.ceil(userIds.length / BATCH_SIZE);
|
|
128
|
+
console.log(`Processing batch ${batchNumber}/${totalBatches} (${batch.length} users)`);
|
|
129
|
+
await Promise.all(batch.map((userId) => calculateEffectivePermissions(userId, config)));
|
|
130
|
+
}
|
|
131
|
+
console.log(`Completed batch update for ${userIds.length} users`);
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=effective-permissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effective-permissions.js","sourceRoot":"","sources":["../../../src/modules/security/effective-permissions.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeH,sEA4DC;AAQD,gEAeC;AAQD,0EAoBC;AA5HD,sDAAwC;AACxC,iFAIwC;AAExC;;;;;GAKG;AACI,KAAK,UAAU,6BAA6B,CACjD,MAAc,EACd,SAA8C,EAAE;IAEhD,MAAM,GAAG,mCAAQ,mEAAoC,GAAK,MAAM,CAAE,CAAC;IACnE,MAAM,EAAE,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;IAE7B,sBAAsB;IACtB,MAAM,OAAO,GAAG,MAAM,EAAE,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CACnD,OAAiB,EACjB,SAA8C,EAAE;IAEhD,MAAM,GAAG,mCAAQ,mEAAoC,GAAK,MAAM,CAAE,CAAC;IACnE,MAAM,UAAU,GAAG,GAAG,CAAC,SAAS,CAAC;IAEjC,OAAO,CAAC,GAAG,CAAC,kBAAkB,OAAO,CAAC,MAAM,uBAAuB,UAAU,GAAG,CAAC,CAAC;IAElF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,UAAU,EAAE,CAAC;QACpD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC;QAC/C,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;QACnD,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,UAAU,CAAC,CAAC;QAE5D,OAAO,CAAC,GAAG,CAAC,oBAAoB,WAAW,IAAI,YAAY,KAAK,KAAK,CAAC,MAAM,SAAS,CAAC,CAAC;QAEvF,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,6BAA6B,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAC1F,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,8BAA8B,OAAO,CAAC,MAAM,QAAQ,CAAC,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Effective Permissions Models and Configuration
|
|
3
|
+
*
|
|
4
|
+
* Provides configurable permission caching system for Firebase security rules.
|
|
5
|
+
* Maintains denormalized permission cache based on user roles.
|
|
6
|
+
*/
|
|
7
|
+
import { FieldValue } from 'firebase-admin/firestore';
|
|
8
|
+
import { Role } from '../user/user.models';
|
|
9
|
+
export { Role };
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for the effective permissions system
|
|
12
|
+
*/
|
|
13
|
+
export interface EffectivePermissionsConfig {
|
|
14
|
+
/**
|
|
15
|
+
* Collection name where users are stored
|
|
16
|
+
* @default 'user'
|
|
17
|
+
*/
|
|
18
|
+
userCollection: string;
|
|
19
|
+
/**
|
|
20
|
+
* Collection name where roles are stored
|
|
21
|
+
* @default 'role'
|
|
22
|
+
*/
|
|
23
|
+
roleCollection: string;
|
|
24
|
+
/**
|
|
25
|
+
* Collection name for security data
|
|
26
|
+
* @default 'security'
|
|
27
|
+
*/
|
|
28
|
+
securityCollection: string;
|
|
29
|
+
/**
|
|
30
|
+
* Field name in user documents that contains role IDs array
|
|
31
|
+
* @default 'roleIds'
|
|
32
|
+
*/
|
|
33
|
+
userRoleIdsField: string;
|
|
34
|
+
/**
|
|
35
|
+
* Field name in role documents that contains permissions array
|
|
36
|
+
* @default 'permissions'
|
|
37
|
+
*/
|
|
38
|
+
rolePermissionsField: string;
|
|
39
|
+
/**
|
|
40
|
+
* Field name in role documents that contains role name
|
|
41
|
+
* @default 'name'
|
|
42
|
+
*/
|
|
43
|
+
roleNameField: string;
|
|
44
|
+
/**
|
|
45
|
+
* Batch size for processing multiple users at once
|
|
46
|
+
* Used when a role's permissions change and many users need updates
|
|
47
|
+
* @default 50
|
|
48
|
+
*/
|
|
49
|
+
batchSize: number;
|
|
50
|
+
/**
|
|
51
|
+
* Region for deployed functions
|
|
52
|
+
* @default 'us-central1'
|
|
53
|
+
*/
|
|
54
|
+
region: string;
|
|
55
|
+
/**
|
|
56
|
+
* Max instances for each function
|
|
57
|
+
* @default 10
|
|
58
|
+
*/
|
|
59
|
+
maxInstances: number;
|
|
60
|
+
/**
|
|
61
|
+
* Firestore database ID (optional, uses default if not specified)
|
|
62
|
+
*/
|
|
63
|
+
databaseId?: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Default configuration values
|
|
67
|
+
*/
|
|
68
|
+
export declare const DEFAULT_EFFECTIVE_PERMISSIONS_CONFIG: EffectivePermissionsConfig;
|
|
69
|
+
/**
|
|
70
|
+
* Effective permissions cache document structure
|
|
71
|
+
* Stored at: {securityCollection}/users/{userId}/effective_permissions
|
|
72
|
+
*/
|
|
73
|
+
export interface EffectivePermissions {
|
|
74
|
+
/**
|
|
75
|
+
* Flattened array of all permissions from all user's roles
|
|
76
|
+
* Sorted alphabetically for consistency
|
|
77
|
+
*/
|
|
78
|
+
permissions: string[];
|
|
79
|
+
/**
|
|
80
|
+
* Array of role names (not IDs) for easier debugging
|
|
81
|
+
* Sorted alphabetically for consistency
|
|
82
|
+
*/
|
|
83
|
+
roles: string[];
|
|
84
|
+
/**
|
|
85
|
+
* Timestamp when this cache was last updated
|
|
86
|
+
*/
|
|
87
|
+
lastUpdated: FieldValue;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* User document structure (partial - only fields we care about)
|
|
91
|
+
* Note: Actual field names are configurable via EffectivePermissionsConfig
|
|
92
|
+
*/
|
|
93
|
+
export interface UserDocument {
|
|
94
|
+
[key: string]: any;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=effective-permissions.models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effective-permissions.models.d.ts","sourceRoot":"","sources":["../../../src/modules/security/effective-permissions.models.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAG3C,OAAO,EAAE,IAAI,EAAE,CAAC;AAEhB;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAE3B;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAE7B;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,eAAO,MAAM,oCAAoC,EAAE,0BAUlD,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,WAAW,EAAE,MAAM,EAAE,CAAC;IAEtB;;;OAGG;IACH,KAAK,EAAE,MAAM,EAAE,CAAC;IAEhB;;OAEG;IACH,WAAW,EAAE,UAAU,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Effective Permissions Models and Configuration
|
|
4
|
+
*
|
|
5
|
+
* Provides configurable permission caching system for Firebase security rules.
|
|
6
|
+
* Maintains denormalized permission cache based on user roles.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.DEFAULT_EFFECTIVE_PERMISSIONS_CONFIG = void 0;
|
|
10
|
+
/**
|
|
11
|
+
* Default configuration values
|
|
12
|
+
*/
|
|
13
|
+
exports.DEFAULT_EFFECTIVE_PERMISSIONS_CONFIG = {
|
|
14
|
+
userCollection: 'user',
|
|
15
|
+
roleCollection: 'role',
|
|
16
|
+
securityCollection: 'security',
|
|
17
|
+
userRoleIdsField: 'roleIds',
|
|
18
|
+
rolePermissionsField: 'permissions',
|
|
19
|
+
roleNameField: 'name',
|
|
20
|
+
batchSize: 50,
|
|
21
|
+
region: 'us-central1',
|
|
22
|
+
maxInstances: 10,
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=effective-permissions.models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effective-permissions.models.js","sourceRoot":"","sources":["../../../src/modules/security/effective-permissions.models.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAyEH;;GAEG;AACU,QAAA,oCAAoC,GAA+B;IAC9E,cAAc,EAAE,MAAM;IACtB,cAAc,EAAE,MAAM;IACtB,kBAAkB,EAAE,UAAU;IAC9B,gBAAgB,EAAE,SAAS;IAC3B,oBAAoB,EAAE,aAAa;IACnC,aAAa,EAAE,MAAM;IACrB,SAAS,EAAE,EAAE;IACb,MAAM,EAAE,aAAa;IACrB,YAAY,EAAE,EAAE;CACjB,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Effective Permissions Trigger Factories
|
|
3
|
+
*
|
|
4
|
+
* Factory functions that create Firebase Cloud Functions v2 triggers
|
|
5
|
+
* for automatically maintaining the effective permissions cache.
|
|
6
|
+
*/
|
|
7
|
+
import { EffectivePermissionsConfig } from './effective-permissions.models';
|
|
8
|
+
/**
|
|
9
|
+
* Create user lifecycle triggers
|
|
10
|
+
* Automatically maintains permission cache when users are created, updated, or deleted
|
|
11
|
+
*
|
|
12
|
+
* @param config - Configuration for the permission system
|
|
13
|
+
* @returns Object containing the three trigger functions
|
|
14
|
+
*/
|
|
15
|
+
export declare function createUserPermissionTriggers(config?: Partial<EffectivePermissionsConfig>): {
|
|
16
|
+
/**
|
|
17
|
+
* Trigger when a new user is created
|
|
18
|
+
* Calculates initial effective permissions
|
|
19
|
+
*/
|
|
20
|
+
onUserCreate: import("firebase-functions/core").CloudFunction<import("firebase-functions/v2/firestore").FirestoreEvent<import("firebase-functions/v2/firestore").QueryDocumentSnapshot | undefined, {
|
|
21
|
+
userId: string;
|
|
22
|
+
}>>;
|
|
23
|
+
/**
|
|
24
|
+
* Trigger when a user document is updated
|
|
25
|
+
* Recalculates effective permissions if roles changed
|
|
26
|
+
*/
|
|
27
|
+
onUserRoleChange: import("firebase-functions/core").CloudFunction<import("firebase-functions/v2/firestore").FirestoreEvent<import("firebase-functions/v2/firestore").Change<import("firebase-functions/v2/firestore").QueryDocumentSnapshot> | undefined, {
|
|
28
|
+
userId: string;
|
|
29
|
+
}>>;
|
|
30
|
+
/**
|
|
31
|
+
* Trigger when a user is deleted
|
|
32
|
+
* Cleans up the permission cache
|
|
33
|
+
*/
|
|
34
|
+
onUserDelete: import("firebase-functions/core").CloudFunction<import("firebase-functions/v2/firestore").FirestoreEvent<import("firebase-functions/v2/firestore").QueryDocumentSnapshot | undefined, {
|
|
35
|
+
userId: string;
|
|
36
|
+
}>>;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Create role permission change triggers
|
|
40
|
+
* Automatically updates all affected users when role permissions change
|
|
41
|
+
*
|
|
42
|
+
* @param config - Configuration for the permission system
|
|
43
|
+
* @returns Object containing the two trigger functions
|
|
44
|
+
*/
|
|
45
|
+
export declare function createRolePermissionTriggers(config?: Partial<EffectivePermissionsConfig>): {
|
|
46
|
+
/**
|
|
47
|
+
* Trigger when a role's permissions are updated
|
|
48
|
+
* Updates all users who have this role
|
|
49
|
+
*/
|
|
50
|
+
onRolePermissionsChange: import("firebase-functions/core").CloudFunction<import("firebase-functions/v2/firestore").FirestoreEvent<import("firebase-functions/v2/firestore").Change<import("firebase-functions/v2/firestore").QueryDocumentSnapshot> | undefined, {
|
|
51
|
+
roleId: string;
|
|
52
|
+
}>>;
|
|
53
|
+
/**
|
|
54
|
+
* Trigger when a role is deleted
|
|
55
|
+
* Updates all users who had this role
|
|
56
|
+
*/
|
|
57
|
+
onRoleDelete: import("firebase-functions/core").CloudFunction<import("firebase-functions/v2/firestore").FirestoreEvent<import("firebase-functions/v2/firestore").QueryDocumentSnapshot | undefined, {
|
|
58
|
+
roleId: string;
|
|
59
|
+
}>>;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Create admin HTTP endpoints for manual permission management
|
|
63
|
+
*
|
|
64
|
+
* @param config - Configuration for the permission system
|
|
65
|
+
* @param adminSecretKey - Key in functions config where admin secret is stored (e.g., 'admin.secret')
|
|
66
|
+
* @returns Object containing bootstrap and recalculate endpoints
|
|
67
|
+
*/
|
|
68
|
+
export declare function createAdminPermissionEndpoints(config?: Partial<EffectivePermissionsConfig>, adminSecretKey?: string): {
|
|
69
|
+
/**
|
|
70
|
+
* Bootstrap endpoint - initialize permissions for all existing users
|
|
71
|
+
* POST /bootstrapEffectivePermissions
|
|
72
|
+
* Requires Authorization: Bearer <admin-secret>
|
|
73
|
+
*/
|
|
74
|
+
bootstrapEffectivePermissions: import("firebase-functions/v2/https").HttpsFunction;
|
|
75
|
+
/**
|
|
76
|
+
* Recalculate endpoint - manually recalculate permissions for a single user
|
|
77
|
+
* POST /recalculateUserPermissions
|
|
78
|
+
* Body: { userId: string }
|
|
79
|
+
* Requires Authorization: Bearer <admin-secret>
|
|
80
|
+
*/
|
|
81
|
+
recalculateUserPermissions: import("firebase-functions/v2/https").HttpsFunction;
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=effective-permissions.triggers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effective-permissions.triggers.d.ts","sourceRoot":"","sources":["../../../src/modules/security/effective-permissions.triggers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAcH,OAAO,EACL,0BAA0B,EAE3B,MAAM,gCAAgC,CAAC;AAExC;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,GAAE,OAAO,CAAC,0BAA0B,CAAM;IAIzF;;;OAGG;;;;IAcH;;;OAGG;;;;IA8BH;;;OAGG;;;;EAcN;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,GAAE,OAAO,CAAC,0BAA0B,CAAM;IAIzF;;;OAGG;;;;IA6CH;;;OAGG;;;;EA2BN;AAED;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAC5C,MAAM,GAAE,OAAO,CAAC,0BAA0B,CAAM,EAChD,cAAc,GAAE,MAAuB;IAoBrC;;;;OAIG;;IA6DH;;;;;OAKG;;EAiDN"}
|