@xbg.solutions/backend-core 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.
Files changed (185) hide show
  1. package/lib/core/src/app.d.ts +28 -0
  2. package/lib/core/src/app.d.ts.map +1 -0
  3. package/lib/core/src/app.js +188 -0
  4. package/lib/core/src/app.js.map +1 -0
  5. package/lib/core/src/base/BaseController.d.ts +108 -0
  6. package/lib/core/src/base/BaseController.d.ts.map +1 -0
  7. package/lib/core/src/base/BaseController.js +307 -0
  8. package/lib/core/src/base/BaseController.js.map +1 -0
  9. package/lib/core/src/base/BaseEntity.d.ts +92 -0
  10. package/lib/core/src/base/BaseEntity.d.ts.map +1 -0
  11. package/lib/core/src/base/BaseEntity.js +143 -0
  12. package/lib/core/src/base/BaseEntity.js.map +1 -0
  13. package/lib/core/src/base/BaseRepository.d.ts +124 -0
  14. package/lib/core/src/base/BaseRepository.d.ts.map +1 -0
  15. package/lib/core/src/base/BaseRepository.js +414 -0
  16. package/lib/core/src/base/BaseRepository.js.map +1 -0
  17. package/lib/core/src/base/BaseService.d.ts +89 -0
  18. package/lib/core/src/base/BaseService.d.ts.map +1 -0
  19. package/lib/core/src/base/BaseService.js +342 -0
  20. package/lib/core/src/base/BaseService.js.map +1 -0
  21. package/lib/core/src/base/index.d.ts +8 -0
  22. package/lib/core/src/base/index.d.ts.map +1 -0
  23. package/lib/core/src/base/index.js +24 -0
  24. package/lib/core/src/base/index.js.map +1 -0
  25. package/lib/core/src/config/app.config.d.ts +70 -0
  26. package/lib/core/src/config/app.config.d.ts.map +1 -0
  27. package/lib/core/src/config/app.config.js +106 -0
  28. package/lib/core/src/config/app.config.js.map +1 -0
  29. package/lib/core/src/config/auth.config.d.ts +54 -0
  30. package/lib/core/src/config/auth.config.d.ts.map +1 -0
  31. package/lib/core/src/config/auth.config.js +88 -0
  32. package/lib/core/src/config/auth.config.js.map +1 -0
  33. package/lib/core/src/config/cache.config.d.ts +47 -0
  34. package/lib/core/src/config/cache.config.d.ts.map +1 -0
  35. package/lib/core/src/config/cache.config.js +225 -0
  36. package/lib/core/src/config/cache.config.js.map +1 -0
  37. package/lib/core/src/config/communications.config.d.ts +175 -0
  38. package/lib/core/src/config/communications.config.d.ts.map +1 -0
  39. package/lib/core/src/config/communications.config.js +219 -0
  40. package/lib/core/src/config/communications.config.js.map +1 -0
  41. package/lib/core/src/config/database.config.d.ts +68 -0
  42. package/lib/core/src/config/database.config.d.ts.map +1 -0
  43. package/lib/core/src/config/database.config.js +95 -0
  44. package/lib/core/src/config/database.config.js.map +1 -0
  45. package/lib/core/src/config/firebase-event-mapping.config.d.ts +41 -0
  46. package/lib/core/src/config/firebase-event-mapping.config.d.ts.map +1 -0
  47. package/lib/core/src/config/firebase-event-mapping.config.js +180 -0
  48. package/lib/core/src/config/firebase-event-mapping.config.js.map +1 -0
  49. package/lib/core/src/config/firestore.config.d.ts +61 -0
  50. package/lib/core/src/config/firestore.config.d.ts.map +1 -0
  51. package/lib/core/src/config/firestore.config.js +74 -0
  52. package/lib/core/src/config/firestore.config.js.map +1 -0
  53. package/lib/core/src/config/index.d.ts +15 -0
  54. package/lib/core/src/config/index.d.ts.map +1 -0
  55. package/lib/core/src/config/index.js +41 -0
  56. package/lib/core/src/config/index.js.map +1 -0
  57. package/lib/core/src/config/maps.config.d.ts +31 -0
  58. package/lib/core/src/config/maps.config.d.ts.map +1 -0
  59. package/lib/core/src/config/maps.config.js +50 -0
  60. package/lib/core/src/config/maps.config.js.map +1 -0
  61. package/lib/core/src/config/middleware.config.d.ts +57 -0
  62. package/lib/core/src/config/middleware.config.d.ts.map +1 -0
  63. package/lib/core/src/config/middleware.config.js +68 -0
  64. package/lib/core/src/config/middleware.config.js.map +1 -0
  65. package/lib/core/src/config/tokens.config.d.ts +53 -0
  66. package/lib/core/src/config/tokens.config.d.ts.map +1 -0
  67. package/lib/core/src/config/tokens.config.js +129 -0
  68. package/lib/core/src/config/tokens.config.js.map +1 -0
  69. package/lib/core/src/generator/generator.d.ts +38 -0
  70. package/lib/core/src/generator/generator.d.ts.map +1 -0
  71. package/lib/core/src/generator/generator.js +159 -0
  72. package/lib/core/src/generator/generator.js.map +1 -0
  73. package/lib/core/src/generator/index.d.ts +7 -0
  74. package/lib/core/src/generator/index.d.ts.map +1 -0
  75. package/lib/core/src/generator/index.js +23 -0
  76. package/lib/core/src/generator/index.js.map +1 -0
  77. package/lib/core/src/generator/parser.d.ts +10 -0
  78. package/lib/core/src/generator/parser.d.ts.map +1 -0
  79. package/lib/core/src/generator/parser.js +197 -0
  80. package/lib/core/src/generator/parser.js.map +1 -0
  81. package/lib/core/src/generator/types.d.ts +112 -0
  82. package/lib/core/src/generator/types.d.ts.map +1 -0
  83. package/lib/core/src/generator/types.js +7 -0
  84. package/lib/core/src/generator/types.js.map +1 -0
  85. package/lib/core/src/index.d.ts +19 -0
  86. package/lib/core/src/index.d.ts.map +1 -0
  87. package/lib/core/src/index.js +46 -0
  88. package/lib/core/src/index.js.map +1 -0
  89. package/lib/core/src/middleware/auth.middleware.d.ts +57 -0
  90. package/lib/core/src/middleware/auth.middleware.d.ts.map +1 -0
  91. package/lib/core/src/middleware/auth.middleware.js +256 -0
  92. package/lib/core/src/middleware/auth.middleware.js.map +1 -0
  93. package/lib/core/src/middleware/cors.middleware.d.ts +13 -0
  94. package/lib/core/src/middleware/cors.middleware.d.ts.map +1 -0
  95. package/lib/core/src/middleware/cors.middleware.js +50 -0
  96. package/lib/core/src/middleware/cors.middleware.js.map +1 -0
  97. package/lib/core/src/middleware/error.middleware.d.ts +46 -0
  98. package/lib/core/src/middleware/error.middleware.d.ts.map +1 -0
  99. package/lib/core/src/middleware/error.middleware.js +174 -0
  100. package/lib/core/src/middleware/error.middleware.js.map +1 -0
  101. package/lib/core/src/middleware/index.d.ts +11 -0
  102. package/lib/core/src/middleware/index.d.ts.map +1 -0
  103. package/lib/core/src/middleware/index.js +27 -0
  104. package/lib/core/src/middleware/index.js.map +1 -0
  105. package/lib/core/src/middleware/logging.middleware.d.ts +10 -0
  106. package/lib/core/src/middleware/logging.middleware.d.ts.map +1 -0
  107. package/lib/core/src/middleware/logging.middleware.js +87 -0
  108. package/lib/core/src/middleware/logging.middleware.js.map +1 -0
  109. package/lib/core/src/middleware/rateLimit.middleware.d.ts +26 -0
  110. package/lib/core/src/middleware/rateLimit.middleware.d.ts.map +1 -0
  111. package/lib/core/src/middleware/rateLimit.middleware.js +105 -0
  112. package/lib/core/src/middleware/rateLimit.middleware.js.map +1 -0
  113. package/lib/core/src/middleware/requestId.middleware.d.ts +11 -0
  114. package/lib/core/src/middleware/requestId.middleware.d.ts.map +1 -0
  115. package/lib/core/src/middleware/requestId.middleware.js +26 -0
  116. package/lib/core/src/middleware/requestId.middleware.js.map +1 -0
  117. package/lib/core/src/middleware/validation.middleware.d.ts +25 -0
  118. package/lib/core/src/middleware/validation.middleware.d.ts.map +1 -0
  119. package/lib/core/src/middleware/validation.middleware.js +133 -0
  120. package/lib/core/src/middleware/validation.middleware.js.map +1 -0
  121. package/lib/core/src/types/errors.d.ts +119 -0
  122. package/lib/core/src/types/errors.d.ts.map +1 -0
  123. package/lib/core/src/types/errors.js +210 -0
  124. package/lib/core/src/types/errors.js.map +1 -0
  125. package/lib/utils-cache-connector/src/cache-connector.d.ts +139 -0
  126. package/lib/utils-cache-connector/src/cache-connector.d.ts.map +1 -0
  127. package/lib/utils-cache-connector/src/cache-connector.js +277 -0
  128. package/lib/utils-cache-connector/src/cache-connector.js.map +1 -0
  129. package/lib/utils-cache-connector/src/index.d.ts +52 -0
  130. package/lib/utils-cache-connector/src/index.d.ts.map +1 -0
  131. package/lib/utils-cache-connector/src/index.js +103 -0
  132. package/lib/utils-cache-connector/src/index.js.map +1 -0
  133. package/lib/utils-cache-connector/src/providers/base-cache-provider.d.ts +95 -0
  134. package/lib/utils-cache-connector/src/providers/base-cache-provider.d.ts.map +1 -0
  135. package/lib/utils-cache-connector/src/providers/base-cache-provider.js +120 -0
  136. package/lib/utils-cache-connector/src/providers/base-cache-provider.js.map +1 -0
  137. package/lib/utils-cache-connector/src/providers/firestore-cache-provider.d.ts +58 -0
  138. package/lib/utils-cache-connector/src/providers/firestore-cache-provider.d.ts.map +1 -0
  139. package/lib/utils-cache-connector/src/providers/firestore-cache-provider.js +418 -0
  140. package/lib/utils-cache-connector/src/providers/firestore-cache-provider.js.map +1 -0
  141. package/lib/utils-cache-connector/src/providers/memory-cache-provider.d.ts +57 -0
  142. package/lib/utils-cache-connector/src/providers/memory-cache-provider.d.ts.map +1 -0
  143. package/lib/utils-cache-connector/src/providers/memory-cache-provider.js +217 -0
  144. package/lib/utils-cache-connector/src/providers/memory-cache-provider.js.map +1 -0
  145. package/lib/utils-cache-connector/src/providers/noop-cache-provider.d.ts +21 -0
  146. package/lib/utils-cache-connector/src/providers/noop-cache-provider.d.ts.map +1 -0
  147. package/lib/utils-cache-connector/src/providers/noop-cache-provider.js +42 -0
  148. package/lib/utils-cache-connector/src/providers/noop-cache-provider.js.map +1 -0
  149. package/lib/utils-cache-connector/src/providers/redis-cache-provider.d.ts +64 -0
  150. package/lib/utils-cache-connector/src/providers/redis-cache-provider.d.ts.map +1 -0
  151. package/lib/utils-cache-connector/src/providers/redis-cache-provider.js +414 -0
  152. package/lib/utils-cache-connector/src/providers/redis-cache-provider.js.map +1 -0
  153. package/lib/utils-cache-connector/src/types.d.ts +342 -0
  154. package/lib/utils-cache-connector/src/types.d.ts.map +1 -0
  155. package/lib/utils-cache-connector/src/types.js +8 -0
  156. package/lib/utils-cache-connector/src/types.js.map +1 -0
  157. package/lib/utils-events/src/event-bus.d.ts +42 -0
  158. package/lib/utils-events/src/event-bus.d.ts.map +1 -0
  159. package/lib/utils-events/src/event-bus.js +93 -0
  160. package/lib/utils-events/src/event-bus.js.map +1 -0
  161. package/lib/utils-events/src/event-types.d.ts +146 -0
  162. package/lib/utils-events/src/event-types.d.ts.map +1 -0
  163. package/lib/utils-events/src/event-types.js +49 -0
  164. package/lib/utils-events/src/event-types.js.map +1 -0
  165. package/lib/utils-events/src/index.d.ts +7 -0
  166. package/lib/utils-events/src/index.d.ts.map +1 -0
  167. package/lib/utils-events/src/index.js +11 -0
  168. package/lib/utils-events/src/index.js.map +1 -0
  169. package/lib/utils-logger/src/index.d.ts +12 -0
  170. package/lib/utils-logger/src/index.d.ts.map +1 -0
  171. package/lib/utils-logger/src/index.js +29 -0
  172. package/lib/utils-logger/src/index.js.map +1 -0
  173. package/lib/utils-logger/src/logger-types.d.ts +32 -0
  174. package/lib/utils-logger/src/logger-types.d.ts.map +1 -0
  175. package/lib/utils-logger/src/logger-types.js +17 -0
  176. package/lib/utils-logger/src/logger-types.js.map +1 -0
  177. package/lib/utils-logger/src/logger.d.ts +42 -0
  178. package/lib/utils-logger/src/logger.d.ts.map +1 -0
  179. package/lib/utils-logger/src/logger.js +123 -0
  180. package/lib/utils-logger/src/logger.js.map +1 -0
  181. package/package.json +49 -0
  182. package/src/templates/controller.hbs +48 -0
  183. package/src/templates/entity.hbs +80 -0
  184. package/src/templates/repository.hbs +56 -0
  185. package/src/templates/service.hbs +108 -0
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ /**
3
+ * Event Type Definitions
4
+ *
5
+ * Base event types for the internal event bus. These cover the standard
6
+ * lifecycle events that most applications need out of the box.
7
+ *
8
+ * ─── Extending with project-specific events ───────────────────────────
9
+ *
10
+ * The code generator adds entity-specific CRUD events automatically
11
+ * (e.g. ORDER_CREATED, PRODUCT_UPDATED) via BaseService.publishEvent().
12
+ * Those events are cast to EventType at runtime, so they work with the
13
+ * event bus without being listed here.
14
+ *
15
+ * To add custom domain events (e.g. ORDER_SHIPPED, PAYMENT_FAILED):
16
+ *
17
+ * 1. Add the new member to this enum.
18
+ * 2. Optionally define a typed payload interface below.
19
+ * 3. Add the mapping to EventPayloadMap for full type safety.
20
+ * 4. Subscribe in your service or in subscribers/.
21
+ *
22
+ * The enum is deliberately kept small so that new projects start clean
23
+ * and only grow the event catalogue as needed.
24
+ */
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.EventType = void 0;
27
+ var EventType;
28
+ (function (EventType) {
29
+ // ── User lifecycle ────────────────────────────────────────
30
+ EventType["USER_CREATED"] = "user.created";
31
+ EventType["USER_UPDATED"] = "user.updated";
32
+ EventType["USER_DELETED"] = "user.deleted";
33
+ // ── Authentication ────────────────────────────────────────
34
+ EventType["AUTH_LOGIN"] = "auth.login";
35
+ EventType["AUTH_LOGOUT"] = "auth.logout";
36
+ EventType["AUTH_TOKEN_REFRESHED"] = "auth.token_refreshed";
37
+ EventType["AUTH_TOKEN_BLACKLISTED"] = "auth.token_blacklisted";
38
+ EventType["AUTH_PASSWORD_CHANGED"] = "auth.password_changed";
39
+ // ── File / Storage ────────────────────────────────────────
40
+ EventType["FILE_UPLOADED"] = "file.uploaded";
41
+ EventType["FILE_DELETED"] = "file.deleted";
42
+ // ── Notifications ─────────────────────────────────────────
43
+ EventType["NOTIFICATION_SENT"] = "notification.sent";
44
+ EventType["NOTIFICATION_FAILED"] = "notification.failed";
45
+ // ── System ────────────────────────────────────────────────
46
+ /** Catch-all for external data changes (Firebase triggers, webhooks, etc.) */
47
+ EventType["EXTERNAL_DATA_CHANGE"] = "external.data.change";
48
+ })(EventType || (exports.EventType = EventType = {}));
49
+ //# sourceMappingURL=event-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-types.js","sourceRoot":"","sources":["../../../../utils-events/src/event-types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAEH,IAAY,SAwBX;AAxBD,WAAY,SAAS;IACnB,6DAA6D;IAC7D,0CAA6B,CAAA;IAC7B,0CAA6B,CAAA;IAC7B,0CAA6B,CAAA;IAE7B,6DAA6D;IAC7D,sCAAyB,CAAA;IACzB,wCAA2B,CAAA;IAC3B,0DAA6C,CAAA;IAC7C,8DAAiD,CAAA;IACjD,4DAA+C,CAAA;IAE/C,6DAA6D;IAC7D,4CAA+B,CAAA;IAC/B,0CAA6B,CAAA;IAE7B,6DAA6D;IAC7D,oDAAuC,CAAA;IACvC,wDAA2C,CAAA;IAE3C,6DAA6D;IAC7D,8EAA8E;IAC9E,0DAA6C,CAAA;AAC/C,CAAC,EAxBW,SAAS,yBAAT,SAAS,QAwBpB"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Event utilities barrel export
3
+ */
4
+ export { eventBus } from './event-bus';
5
+ export { EventType } from './event-types';
6
+ export type { BaseEventPayload, EntityCreatedPayload, EntityUpdatedPayload, EntityDeletedPayload, UserCreatedPayload, UserUpdatedPayload, UserDeletedPayload, AuthLoginPayload, AuthLogoutPayload, AuthTokenBlacklistedPayload, FileUploadedPayload, FileDeletedPayload, NotificationSentPayload, NotificationFailedPayload, ExternalDataChangePayload, EventPayloadMap, } from './event-types';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../utils-events/src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,YAAY,EACV,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,2BAA2B,EAC3B,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,EACvB,yBAAyB,EACzB,yBAAyB,EACzB,eAAe,GAChB,MAAM,eAAe,CAAC"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ /**
3
+ * Event utilities barrel export
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.EventType = exports.eventBus = void 0;
7
+ var event_bus_1 = require("./event-bus");
8
+ Object.defineProperty(exports, "eventBus", { enumerable: true, get: function () { return event_bus_1.eventBus; } });
9
+ var event_types_1 = require("./event-types");
10
+ Object.defineProperty(exports, "EventType", { enumerable: true, get: function () { return event_types_1.EventType; } });
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../utils-events/src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,yCAAuC;AAA9B,qGAAA,QAAQ,OAAA;AACjB,6CAA0C;AAAjC,wGAAA,SAAS,OAAA"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Logger utility barrel export
3
+ */
4
+ export * from './logger';
5
+ export * from './logger-types';
6
+ import { Logger } from './logger';
7
+ /**
8
+ * Default logger instance for use outside request context
9
+ * For request-scoped logging, use the logger from req.logger
10
+ */
11
+ export declare const logger: Logger;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../utils-logger/src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAE/B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;GAGG;AACH,eAAO,MAAM,MAAM,QAAoD,CAAC"}
@@ -0,0 +1,29 @@
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
+ exports.logger = void 0;
18
+ /**
19
+ * Logger utility barrel export
20
+ */
21
+ __exportStar(require("./logger"), exports);
22
+ __exportStar(require("./logger-types"), exports);
23
+ const logger_1 = require("./logger");
24
+ /**
25
+ * Default logger instance for use outside request context
26
+ * For request-scoped logging, use the logger from req.logger
27
+ */
28
+ exports.logger = new logger_1.Logger('system', { service: 'wishlist-api' });
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../utils-logger/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,2CAAyB;AACzB,iDAA+B;AAE/B,qCAAkC;AAElC;;;GAGG;AACU,QAAA,MAAM,GAAG,IAAI,eAAM,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Logger type definitions
3
+ */
4
+ /**
5
+ * Base log context interface
6
+ * Represents metadata that can be attached to log messages
7
+ */
8
+ export interface LogContext {
9
+ [key: string]: unknown;
10
+ }
11
+ /**
12
+ * Common context fields used across the application
13
+ */
14
+ export interface BaseLogContext extends LogContext {
15
+ operation?: string;
16
+ userId?: string;
17
+ accountUID?: string;
18
+ listUID?: string;
19
+ itemUID?: string;
20
+ contactUID?: string;
21
+ metadata?: Record<string, unknown>;
22
+ }
23
+ /**
24
+ * Log level enum (re-export for convenience)
25
+ */
26
+ export declare enum LogLevel {
27
+ DEBUG = "debug",
28
+ INFO = "info",
29
+ WARN = "warn",
30
+ ERROR = "error"
31
+ }
32
+ //# sourceMappingURL=logger-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger-types.d.ts","sourceRoot":"","sources":["../../../../utils-logger/src/logger-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,UAAU;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,oBAAY,QAAQ;IAClB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,IAAI,SAAS;IACb,KAAK,UAAU;CAChB"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /**
3
+ * Logger type definitions
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.LogLevel = void 0;
7
+ /**
8
+ * Log level enum (re-export for convenience)
9
+ */
10
+ var LogLevel;
11
+ (function (LogLevel) {
12
+ LogLevel["DEBUG"] = "debug";
13
+ LogLevel["INFO"] = "info";
14
+ LogLevel["WARN"] = "warn";
15
+ LogLevel["ERROR"] = "error";
16
+ })(LogLevel || (exports.LogLevel = LogLevel = {}));
17
+ //# sourceMappingURL=logger-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger-types.js","sourceRoot":"","sources":["../../../../utils-logger/src/logger-types.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAuBH;;GAEG;AACH,IAAY,QAKX;AALD,WAAY,QAAQ;IAClB,2BAAe,CAAA;IACf,yBAAa,CAAA;IACb,yBAAa,CAAA;IACb,2BAAe,CAAA;AACjB,CAAC,EALW,QAAQ,wBAAR,QAAQ,QAKnB"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Structured Logger with Correlation IDs
3
+ *
4
+ * Integrates with Firebase Functions logging (GCP Cloud Logging)
5
+ * Never logs PII in plaintext - sanitizes metadata
6
+ */
7
+ import { LogContext } from './logger-types';
8
+ export { LogLevel } from './logger-types';
9
+ export declare class Logger {
10
+ private readonly correlationId;
11
+ private readonly context;
12
+ constructor(correlationId: string, context?: LogContext);
13
+ /**
14
+ * Sanitize metadata to remove sensitive fields
15
+ */
16
+ private sanitizeMetadata;
17
+ /**
18
+ * Build log data structure
19
+ */
20
+ private buildLogData;
21
+ /**
22
+ * Log debug message (development only)
23
+ */
24
+ debug(message: string, meta?: LogContext): void;
25
+ /**
26
+ * Log info message
27
+ */
28
+ info(message: string, meta?: LogContext): void;
29
+ /**
30
+ * Log warning message
31
+ */
32
+ warn(message: string, meta?: LogContext): void;
33
+ /**
34
+ * Log error message with error object
35
+ */
36
+ error(message: string, error: Error, meta?: LogContext): void;
37
+ /**
38
+ * Create child logger with additional context
39
+ */
40
+ child(additionalContext: LogContext): Logger;
41
+ }
42
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../../utils-logger/src/logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAY,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAmC1C,qBAAa,MAAM;IAEf,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,OAAO;gBADP,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,UAAe;IAG3C;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAuBxB;;OAEG;IACH,OAAO,CAAC,YAAY;IAiBpB;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,UAAe,GAAG,IAAI;IAOnD;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,UAAe,GAAG,IAAI;IAKlD;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,UAAe,GAAG,IAAI;IAKlD;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,GAAE,UAAe,GAAG,IAAI;IAYjE;;OAEG;IACH,KAAK,CAAC,iBAAiB,EAAE,UAAU,GAAG,MAAM;CAM7C"}
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ /**
3
+ * Structured Logger with Correlation IDs
4
+ *
5
+ * Integrates with Firebase Functions logging (GCP Cloud Logging)
6
+ * Never logs PII in plaintext - sanitizes metadata
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.Logger = exports.LogLevel = void 0;
10
+ const firebase_functions_1 = require("firebase-functions");
11
+ const logger_types_1 = require("./logger-types");
12
+ var logger_types_2 = require("./logger-types");
13
+ Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return logger_types_2.LogLevel; } });
14
+ /**
15
+ * Sensitive field names that should never be logged
16
+ */
17
+ const SENSITIVE_FIELDS = [
18
+ 'password',
19
+ 'token',
20
+ 'secret',
21
+ 'key',
22
+ 'apiKey',
23
+ 'api_key',
24
+ 'accessToken',
25
+ 'access_token',
26
+ 'refreshToken',
27
+ 'refresh_token',
28
+ 'email',
29
+ 'phoneNumber',
30
+ 'phone',
31
+ 'address',
32
+ 'addressLine1',
33
+ 'addressLine2',
34
+ 'city',
35
+ 'state',
36
+ 'postalCode',
37
+ 'postal_code',
38
+ 'ssn',
39
+ 'creditCard',
40
+ 'credit_card',
41
+ 'cardNumber',
42
+ 'card_number',
43
+ 'cvv',
44
+ 'authorization',
45
+ ];
46
+ class Logger {
47
+ constructor(correlationId, context = {}) {
48
+ this.correlationId = correlationId;
49
+ this.context = context;
50
+ }
51
+ /**
52
+ * Sanitize metadata to remove sensitive fields
53
+ */
54
+ sanitizeMetadata(meta) {
55
+ const sanitized = {};
56
+ for (const [key, value] of Object.entries(meta)) {
57
+ // Check if field name is sensitive
58
+ const lowerKey = key.toLowerCase();
59
+ const isSensitive = SENSITIVE_FIELDS.some((field) => lowerKey.includes(field.toLowerCase()));
60
+ if (isSensitive) {
61
+ sanitized[key] = '[REDACTED]';
62
+ }
63
+ else if (value && typeof value === 'object' && !Array.isArray(value)) {
64
+ // Recursively sanitize nested objects
65
+ sanitized[key] = this.sanitizeMetadata(value);
66
+ }
67
+ else {
68
+ sanitized[key] = value;
69
+ }
70
+ }
71
+ return sanitized;
72
+ }
73
+ /**
74
+ * Build log data structure
75
+ */
76
+ buildLogData(level, message, meta = {}) {
77
+ const sanitizedMeta = this.sanitizeMetadata(meta);
78
+ return Object.assign({ correlationId: this.correlationId, timestamp: new Date().toISOString(), level,
79
+ message, context: this.context }, sanitizedMeta);
80
+ }
81
+ /**
82
+ * Log debug message (development only)
83
+ */
84
+ debug(message, meta = {}) {
85
+ if (process.env.LOG_LEVEL === 'debug' || process.env.NODE_ENV === 'development') {
86
+ const logData = this.buildLogData(logger_types_1.LogLevel.DEBUG, message, meta);
87
+ firebase_functions_1.logger.debug(logData);
88
+ }
89
+ }
90
+ /**
91
+ * Log info message
92
+ */
93
+ info(message, meta = {}) {
94
+ const logData = this.buildLogData(logger_types_1.LogLevel.INFO, message, meta);
95
+ firebase_functions_1.logger.info(logData);
96
+ }
97
+ /**
98
+ * Log warning message
99
+ */
100
+ warn(message, meta = {}) {
101
+ const logData = this.buildLogData(logger_types_1.LogLevel.WARN, message, meta);
102
+ firebase_functions_1.logger.warn(logData);
103
+ }
104
+ /**
105
+ * Log error message with error object
106
+ */
107
+ error(message, error, meta = {}) {
108
+ const logData = this.buildLogData(logger_types_1.LogLevel.ERROR, message, Object.assign({ error: {
109
+ name: error.name,
110
+ message: error.message,
111
+ stack: error.stack,
112
+ } }, meta));
113
+ firebase_functions_1.logger.error(logData);
114
+ }
115
+ /**
116
+ * Create child logger with additional context
117
+ */
118
+ child(additionalContext) {
119
+ return new Logger(this.correlationId, Object.assign(Object.assign({}, this.context), additionalContext));
120
+ }
121
+ }
122
+ exports.Logger = Logger;
123
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../../utils-logger/src/logger.ts"],"names":[],"mappings":"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"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@xbg.solutions/backend-core",
3
+ "version": "1.0.0",
4
+ "description": "XBG Backend Core - Base classes, middleware, config, and code generator",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "files": [
8
+ "lib",
9
+ "src/templates"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "build:watch": "tsc --watch",
14
+ "clean": "rm -rf lib",
15
+ "prepublishOnly": "npm run build"
16
+ },
17
+ "dependencies": {
18
+ "@xbg/utils-logger": "^1.0.0",
19
+ "@xbg/utils-events": "^1.0.0",
20
+ "@xbg/utils-cache-connector": "^1.0.0",
21
+ "@xbg/utils-firebase-event-bridge": "^1.0.0",
22
+ "@xbg/utils-firestore-connector": "^1.0.0",
23
+ "@xbg/utils-token-handler": "^1.0.0",
24
+ "cors": "^2.8.5",
25
+ "dotenv": "^16.3.1",
26
+ "express": "^4.18.2",
27
+ "express-rate-limit": "^7.1.5",
28
+ "express-validator": "^7.0.1",
29
+ "firebase-admin": "^12.0.0",
30
+ "firebase-functions": "^4.6.0",
31
+ "handlebars": "^4.7.8",
32
+ "helmet": "^7.1.0",
33
+ "joi": "^17.11.0",
34
+ "uuid": "^9.0.1"
35
+ },
36
+ "devDependencies": {
37
+ "@types/cors": "^2.8.17",
38
+ "@types/express": "^4.17.21",
39
+ "@types/node": "^20.11.0",
40
+ "@types/uuid": "^9.0.7",
41
+ "typescript": "^5.3.3"
42
+ },
43
+ "engines": {
44
+ "node": "22"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ }
49
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * {{entityName}} Controller
3
+ * Generated from data model specification
4
+ */
5
+
6
+ import { Router } from 'express';
7
+ import { BaseController } from '@xbg/backend-core';
8
+ import { {{entityName}} } from '../entities/{{entityName}}';
9
+ import { {{entityName}}Service } from '../services/{{entityName}}Service';
10
+
11
+ export class {{entityName}}Controller extends BaseController<{{entityName}}> {
12
+ constructor(service: {{entityName}}Service, basePath = '/{{entityNameLower}}s') {
13
+ super(service, basePath);
14
+ }
15
+
16
+ /**
17
+ * Register custom routes
18
+ */
19
+ protected registerRoutes(): void {
20
+ // Register standard CRUD routes
21
+ super.registerRoutes();
22
+
23
+ // Add custom routes here
24
+ {{#each fields}}
25
+ {{#if unique}}
26
+ // this.router.get('/by-{{name}}/:{{name}}', this.handleFindBy{{capitalize name}}.bind(this));
27
+ {{/if}}
28
+ {{/each}}
29
+ }
30
+
31
+ {{#each fields}}
32
+ {{#if unique}}
33
+ /**
34
+ * Find {{../../entityName}} by {{name}}
35
+ */
36
+ // protected async handleFindBy{{capitalize name}}(req: Request, res: Response, next: NextFunction): Promise<void> {
37
+ // try {
38
+ // const context = this.createContext(req);
39
+ // const { {{name}} } = req.params;
40
+ //
41
+ // // Implementation here
42
+ // } catch (error) {
43
+ // next(error);
44
+ // }
45
+ // }
46
+ {{/if}}
47
+ {{/each}}
48
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * {{entityName}} Entity
3
+ * Generated from data model specification
4
+ */
5
+
6
+ {{#each imports}}
7
+ {{{this}}}
8
+ {{/each}}
9
+
10
+ export interface {{entityName}}Data extends BaseEntityData {
11
+ {{#each fields}}
12
+ {{name}}{{#unless required}}?{{/unless}}: {{{tsType}}};
13
+ {{/each}}
14
+ }
15
+
16
+ export class {{entityName}} extends BaseEntity {
17
+ {{#each fields}}
18
+ {{name}}{{#unless required}}?{{/unless}}: {{{tsType}}};
19
+ {{/each}}
20
+
21
+ constructor(data: {{entityName}}Data) {
22
+ super(data);
23
+ {{#each fields}}
24
+ this.{{name}} = data.{{name}}{{#if hasDefault}} || {{{defaultValue}}}{{/if}};
25
+ {{/each}}
26
+ }
27
+
28
+ /**
29
+ * Get entity-specific data for Firestore
30
+ */
31
+ protected getEntityData(): Record<string, any> {
32
+ return {
33
+ {{#each fields}}
34
+ {{name}}: this.{{name}},
35
+ {{/each}}
36
+ };
37
+ }
38
+
39
+ /**
40
+ * Validate entity
41
+ */
42
+ validate(): ValidationResult {
43
+ const errors = ValidationHelper.collectErrors(
44
+ {{#each fields}}
45
+ {{#each validation}}
46
+ {{{this}}},
47
+ {{/each}}
48
+ {{/each}}
49
+ );
50
+
51
+ return ValidationHelper.isValidResult(errors);
52
+ }
53
+
54
+ /**
55
+ * Create entity from Firestore document
56
+ */
57
+ static fromFirestore(id: string, data: Record<string, any>): {{entityName}} {
58
+ return new {{entityName}}({
59
+ id,
60
+ ...data,
61
+ });
62
+ }
63
+
64
+ /**
65
+ * Convert to plain object for API responses
66
+ */
67
+ toJSON(): Record<string, any> {
68
+ return {
69
+ id: this.id,
70
+ {{#each fields}}
71
+ {{name}}: this.{{name}},
72
+ {{/each}}
73
+ createdAt: this.createdAt,
74
+ updatedAt: this.updatedAt,
75
+ {{#if hasSoftDelete}}
76
+ deletedAt: this.deletedAt,
77
+ {{/if}}
78
+ };
79
+ }
80
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * {{entityName}} Repository
3
+ * Generated from data model specification
4
+ */
5
+
6
+ import { Firestore, DocumentData } from 'firebase-admin/firestore';
7
+ import { BaseRepository } from '@xbg/backend-core';
8
+ import { {{entityName}} } from '../entities/{{entityName}}';
9
+
10
+ export class {{entityName}}Repository extends BaseRepository<{{entityName}}> {
11
+ protected collectionName = '{{collectionName}}';
12
+
13
+ constructor(db: Firestore) {
14
+ super(db);
15
+ }
16
+
17
+ /**
18
+ * Convert Firestore document to entity
19
+ */
20
+ protected fromFirestore(id: string, data: DocumentData): {{entityName}} {
21
+ return {{entityName}}.fromFirestore(id, data);
22
+ }
23
+
24
+ {{#each fields}}
25
+ {{#if unique}}
26
+ /**
27
+ * Find {{../../entityName}} by {{name}}
28
+ */
29
+ async findBy{{capitalize name}}({{name}}: {{{tsType}}}): Promise<{{../../entityName}} | null> {
30
+ const snapshot = await this.getCollection()
31
+ .where('{{name}}', '==', {{name}})
32
+ .where('deletedAt', '==', null)
33
+ .limit(1)
34
+ .get();
35
+
36
+ if (snapshot.empty) {
37
+ return null;
38
+ }
39
+
40
+ const doc = snapshot.docs[0];
41
+ return this.fromFirestore(doc.id, doc.data());
42
+ }
43
+ {{/if}}
44
+ {{/each}}
45
+
46
+ {{#each relationships}}
47
+ /**
48
+ * Get {{name}} for {{../../entityName}}
49
+ */
50
+ async get{{capitalize name}}({{../../entityNameLower}}Id: string): Promise<{{entity}}[]> {
51
+ // Implementation depends on relationship type
52
+ // TODO: Implement relationship query
53
+ return [];
54
+ }
55
+ {{/each}}
56
+ }