@zssz-soft/firebase-functions-shared 1.5.6 → 1.6.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/index.d.ts CHANGED
@@ -16,4 +16,5 @@ export * from './modules/events';
16
16
  export * from './modules/error-reporting';
17
17
  export * from './modules/health';
18
18
  export * from './modules/audit';
19
+ export * from './modules/app-config';
19
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC"}
package/lib/index.js CHANGED
@@ -32,4 +32,5 @@ __exportStar(require("./modules/events"), exports);
32
32
  __exportStar(require("./modules/error-reporting"), exports);
33
33
  __exportStar(require("./modules/health"), exports);
34
34
  __exportStar(require("./modules/audit"), exports);
35
+ __exportStar(require("./modules/app-config"), exports);
35
36
  //# 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;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,2CAAyB;AACzB,sDAAoC;AACpC,kDAAgC;AAChC,oDAAkC;AAClC,iDAA+B;AAC/B,qDAAmC;AACnC,gDAA8B;AAC9B,oDAAkC;AAClC,mDAAiC;AACjC,4DAA0C;AAC1C,mDAAiC;AACjC,kDAAgC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,2CAAyB;AACzB,sDAAoC;AACpC,kDAAgC;AAChC,oDAAkC;AAClC,iDAA+B;AAC/B,qDAAmC;AACnC,gDAA8B;AAC9B,oDAAkC;AAClC,mDAAiC;AACjC,4DAA0C;AAC1C,mDAAiC;AACjC,kDAAgC;AAChC,uDAAqC"}
@@ -0,0 +1,25 @@
1
+ import { Firestore } from 'firebase-admin/firestore';
2
+ import { AppConfig } from '../../config';
3
+ import { CreateAppConfigRequest, CreateAppConfigResult } from './app-config.models';
4
+ export declare const APP_CONFIG_COLLECTION = "app-config";
5
+ /**
6
+ * Validate create app config request data
7
+ */
8
+ export declare function validateCreateAppConfigData(data: CreateAppConfigRequest): void;
9
+ /**
10
+ * Check if app config already exists
11
+ */
12
+ export declare function appConfigExists(firestore: Firestore, appId: string): Promise<boolean>;
13
+ /**
14
+ * Create app config document in Firestore
15
+ */
16
+ export declare function createAppConfigDocument(firestore: Firestore, appId: string, config: Record<string, unknown>): Promise<void>;
17
+ /**
18
+ * Core create app config logic - exported for testing
19
+ */
20
+ export declare function executeCreateAppConfig(data: CreateAppConfigRequest, config: AppConfig): Promise<CreateAppConfigResult>;
21
+ /**
22
+ * Cloud Function factory - creates createAppConfig function
23
+ */
24
+ export declare function createCreateAppConfigFunction(): import("firebase-functions/https").CallableFunction<CreateAppConfigRequest, Promise<CreateAppConfigResult>, unknown>;
25
+ //# sourceMappingURL=app-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-config.d.ts","sourceRoot":"","sources":["../../../src/modules/app-config/app-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAInE,OAAO,EAAE,SAAS,EAAa,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAEpF,eAAO,MAAM,qBAAqB,eAAe,CAAC;AASlD;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,sBAAsB,GAAG,IAAI,CAO9E;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAI3F;AAED;;GAEG;AACH,wBAAsB,uBAAuB,CAC3C,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,OAAO,CAAC,IAAI,CAAC,CAcf;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,sBAAsB,EAC5B,MAAM,EAAE,SAAS,GAChB,OAAO,CAAC,qBAAqB,CAAC,CA+BhC;AAED;;GAEG;AACH,wBAAgB,6BAA6B,yHAsB5C"}
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.APP_CONFIG_COLLECTION = void 0;
4
+ exports.validateCreateAppConfigData = validateCreateAppConfigData;
5
+ exports.appConfigExists = appConfigExists;
6
+ exports.createAppConfigDocument = createAppConfigDocument;
7
+ exports.executeCreateAppConfig = executeCreateAppConfig;
8
+ exports.createCreateAppConfigFunction = createCreateAppConfigFunction;
9
+ const firestore_1 = require("firebase-admin/firestore");
10
+ const firebase_functions_1 = require("firebase-functions");
11
+ const https_1 = require("firebase-functions/https");
12
+ const config_1 = require("../../config");
13
+ exports.APP_CONFIG_COLLECTION = 'app-config';
14
+ /**
15
+ * Get Firestore instance based on config
16
+ */
17
+ function getFirestoreInstance(config) {
18
+ return config.firestoreDatabaseId ? (0, firestore_1.getFirestore)(config.firestoreDatabaseId) : (0, firestore_1.getFirestore)();
19
+ }
20
+ /**
21
+ * Validate create app config request data
22
+ */
23
+ function validateCreateAppConfigData(data) {
24
+ if (!data.appId) {
25
+ throw new https_1.HttpsError('invalid-argument', 'appId is required');
26
+ }
27
+ if (!data.config) {
28
+ throw new https_1.HttpsError('invalid-argument', 'config is required');
29
+ }
30
+ }
31
+ /**
32
+ * Check if app config already exists
33
+ */
34
+ async function appConfigExists(firestore, appId) {
35
+ const docRef = firestore.collection(exports.APP_CONFIG_COLLECTION).doc(appId);
36
+ const doc = await docRef.get();
37
+ return doc.exists;
38
+ }
39
+ /**
40
+ * Create app config document in Firestore
41
+ */
42
+ async function createAppConfigDocument(firestore, appId, config) {
43
+ const now = new Date().toISOString();
44
+ const docRef = firestore.collection(exports.APP_CONFIG_COLLECTION).doc(appId);
45
+ await docRef.set(Object.assign(Object.assign({}, config), { uid: appId, meta: {
46
+ createdAt: now,
47
+ updatedAt: now,
48
+ createdBy: 'system-initializer',
49
+ updatedBy: 'system-initializer',
50
+ } }));
51
+ }
52
+ /**
53
+ * Core create app config logic - exported for testing
54
+ */
55
+ async function executeCreateAppConfig(data, config) {
56
+ validateCreateAppConfigData(data);
57
+ const { appId, config: appConfigData } = data;
58
+ const firestore = getFirestoreInstance(config);
59
+ // Check if already exists
60
+ if (await appConfigExists(firestore, appId)) {
61
+ firebase_functions_1.logger.info(`[CreateAppConfig] App config already exists for '${appId}'`);
62
+ return {
63
+ success: true,
64
+ message: `App config already exists for '${appId}'`,
65
+ data: {
66
+ appId,
67
+ created: false,
68
+ },
69
+ };
70
+ }
71
+ // Create the document
72
+ await createAppConfigDocument(firestore, appId, appConfigData);
73
+ firebase_functions_1.logger.info(`[CreateAppConfig] Created app config for '${appId}'`);
74
+ return {
75
+ success: true,
76
+ message: `App config created for '${appId}'`,
77
+ data: {
78
+ appId,
79
+ created: true,
80
+ },
81
+ };
82
+ }
83
+ /**
84
+ * Cloud Function factory - creates createAppConfig function
85
+ */
86
+ function createCreateAppConfigFunction() {
87
+ const config = (0, config_1.getConfig)();
88
+ return (0, https_1.onCall)({
89
+ region: config.region,
90
+ enforceAppCheck: config.enforceAppCheck,
91
+ }, async (request) => {
92
+ try {
93
+ return await executeCreateAppConfig(request.data, config);
94
+ }
95
+ catch (error) {
96
+ firebase_functions_1.logger.error('Create app config error:', error);
97
+ if (error instanceof https_1.HttpsError) {
98
+ throw error;
99
+ }
100
+ throw new https_1.HttpsError('internal', 'Create app config failed: ' + (error instanceof Error ? error.message : String(error)));
101
+ }
102
+ });
103
+ }
104
+ //# sourceMappingURL=app-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-config.js","sourceRoot":"","sources":["../../../src/modules/app-config/app-config.ts"],"names":[],"mappings":";;;AAmBA,kEAOC;AAKD,0CAIC;AAKD,0DAkBC;AAKD,wDAkCC;AAKD,sEAsBC;AA5HD,wDAAmE;AACnE,2DAA4C;AAC5C,oDAA+E;AAE/E,yCAAoD;AAGvC,QAAA,qBAAqB,GAAG,YAAY,CAAC;AAElD;;GAEG;AACH,SAAS,oBAAoB,CAAC,MAAiB;IAC7C,OAAO,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC,IAAA,wBAAY,EAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,IAAA,wBAAY,GAAE,CAAC;AAChG,CAAC;AAED;;GAEG;AACH,SAAgB,2BAA2B,CAAC,IAA4B;IACtE,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAChB,MA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H,CAAC,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,13 @@
1
+ export interface CreateAppConfigRequest {
2
+ appId: string;
3
+ config: Record<string, unknown>;
4
+ }
5
+ export interface CreateAppConfigResult {
6
+ success: boolean;
7
+ message?: string;
8
+ data?: {
9
+ appId: string;
10
+ created: boolean;
11
+ };
12
+ }
13
+ //# sourceMappingURL=app-config.models.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-config.models.d.ts","sourceRoot":"","sources":["../../../src/modules/app-config/app-config.models.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE;QACL,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;CACH"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=app-config.models.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-config.models.js","sourceRoot":"","sources":["../../../src/modules/app-config/app-config.models.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export * from './app-config';
2
+ export * from './app-config.models';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/app-config/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,19 @@
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("./app-config"), exports);
18
+ __exportStar(require("./app-config.models"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/app-config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,sDAAoC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zssz-soft/firebase-functions-shared",
3
- "version": "1.5.6",
4
- "description": "Shared Firebase Cloud Functions modules for LodgeFlow applications",
3
+ "version": "1.6.0",
4
+ "description": "Shared Firebase Cloud Functions modules",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
7
7
  "files": [
@@ -22,7 +22,6 @@
22
22
  "keywords": [
23
23
  "firebase",
24
24
  "cloud-functions",
25
- "lodgeflow",
26
25
  "shared",
27
26
  "typescript",
28
27
  "email",
@@ -38,12 +37,12 @@
38
37
  "license": "UNLICENSED",
39
38
  "repository": {
40
39
  "type": "git",
41
- "url": "git+https://github.com/your-org/lodgeflow.git",
42
- "directory": "firebase/shared/functions"
40
+ "url": "git+https://github.com/zssz-soft/libraries.git",
41
+ "directory": "firebase/shared-functions"
43
42
  },
44
- "homepage": "https://github.com/your-org/lodgeflow#readme",
43
+ "homepage": "https://github.com/zssz-soft/libraries#readme",
45
44
  "bugs": {
46
- "url": "https://github.com/your-org/lodgeflow/issues"
45
+ "url": "https://github.com/zssz-soft/libraries/issues"
47
46
  },
48
47
  "engines": {
49
48
  "node": ">=18.0.0"