@plyaz/core 1.10.1 → 1.11.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.
Files changed (36) hide show
  1. package/dist/base/observability/DatadogAdapter.d.ts.map +1 -1
  2. package/dist/domain/example/FrontendExampleDomainService.d.ts.map +1 -1
  3. package/dist/domain/featureFlags/module.d.ts.map +1 -1
  4. package/dist/domain/files/BackendFilesDomainService.d.ts +10 -13
  5. package/dist/domain/files/BackendFilesDomainService.d.ts.map +1 -1
  6. package/dist/entry-backend.js +382 -200
  7. package/dist/entry-backend.js.map +1 -1
  8. package/dist/entry-backend.mjs +280 -98
  9. package/dist/entry-backend.mjs.map +1 -1
  10. package/dist/entry-frontend-browser.js +122 -35
  11. package/dist/entry-frontend-browser.js.map +1 -1
  12. package/dist/entry-frontend-browser.mjs +123 -33
  13. package/dist/entry-frontend-browser.mjs.map +1 -1
  14. package/dist/entry-frontend.js +122 -35
  15. package/dist/entry-frontend.js.map +1 -1
  16. package/dist/entry-frontend.mjs +123 -33
  17. package/dist/entry-frontend.mjs.map +1 -1
  18. package/dist/frontend/providers/PlyazProvider.d.ts +1 -3
  19. package/dist/frontend/providers/PlyazProvider.d.ts.map +1 -1
  20. package/dist/index.js +1339 -1134
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +1290 -1085
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/init/CoreInitializer.d.ts +31 -1
  25. package/dist/init/CoreInitializer.d.ts.map +1 -1
  26. package/dist/init/nestjs/index.js +126 -14
  27. package/dist/init/nestjs/index.js.map +1 -1
  28. package/dist/init/nestjs/index.mjs +127 -15
  29. package/dist/init/nestjs/index.mjs.map +1 -1
  30. package/dist/services/DbService.d.ts +12 -0
  31. package/dist/services/DbService.d.ts.map +1 -1
  32. package/dist/services/NotificationService.d.ts +8 -0
  33. package/dist/services/NotificationService.d.ts.map +1 -1
  34. package/dist/services/StorageService.d.ts +8 -0
  35. package/dist/services/StorageService.d.ts.map +1 -1
  36. package/package.json +3 -3
@@ -56,7 +56,7 @@ import type { ObservabilityAdapter } from '@plyaz/types/observability';
56
56
  import type { FeatureFlagStoreSlice } from '@plyaz/types/features';
57
57
  import type { ErrorStoreActions } from '@plyaz/types/errors';
58
58
  import { type StoreKey } from '@plyaz/store';
59
- import type { RootStoreSlice } from '@plyaz/types/store';
59
+ import type { RootStoreSlice, RootStoreHook } from '@plyaz/types/store';
60
60
  import type { StoreApi } from 'zustand/vanilla';
61
61
  /**
62
62
  * Core initialization options with specific types for this package
@@ -187,6 +187,20 @@ export declare class Core {
187
187
  * All store access should go through Core.rootStore - no separate stores needed
188
188
  */
189
189
  private static _rootStore;
190
+ /**
191
+ * Injected store hook for frontend (set via setRootStoreHook before initialize).
192
+ * This is used instead of directly importing from @plyaz/store to prevent
193
+ * duplicate store instances when bundlers create multiple module copies.
194
+ */
195
+ private static _injectedStoreHook;
196
+ /**
197
+ * Set the root store hook for frontend use.
198
+ * Must be called before Core.initialize() when running in browser.
199
+ * PlyazProvider calls this automatically with the store prop.
200
+ *
201
+ * @param store - The useRootStore hook from @plyaz/store
202
+ */
203
+ static setRootStoreHook(store: RootStoreHook): void;
190
204
  /**
191
205
  * Setup environment and context
192
206
  */
@@ -587,6 +601,22 @@ export declare class Core {
587
601
  /** Build global error handler config */
588
602
  private static buildErrorHandlerConfig;
589
603
  private static initializeErrorHandler;
604
+ /**
605
+ * Log serialized errors with full details.
606
+ */
607
+ private static logErrors;
608
+ /**
609
+ * Setup SYSTEM.ERROR event subscription for error store updates.
610
+ * Backend: Also logs errors with full details.
611
+ * Frontend: Only updates store (logging handled by store subscription).
612
+ */
613
+ private static setupErrorEventSubscription;
614
+ /**
615
+ * Setup error store subscription for frontend logging.
616
+ * Logs new errors when they're added to the store.
617
+ * Only active for non-backend runtimes (browser, nextjs, nuxt, edge).
618
+ */
619
+ private static setupErrorStoreSubscription;
590
620
  /**
591
621
  * Create HTTP error handler based on detected runtime.
592
622
  * Stores the handler in Core._httpErrorHandler for access via Core.httpErrorHandler
@@ -1 +1 @@
1
- {"version":3,"file":"CoreInitializer.d.ts","sourceRoot":"","sources":["../../src/init/CoreInitializer.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,OAAO,KAAK,EACV,sBAAsB,EACtB,kBAAkB,EAClB,WAAW,EAEX,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,IAAI,mBAAmB,EACtC,sBAAsB,EACtB,gBAAgB,EAChB,yBAAyB,EAEzB,yBAAyB,EACzB,0BAA0B,EAC1B,eAAe,EACf,uBAAuB,EACvB,mBAAmB,EACnB,iBAAiB,EACjB,sBAAsB,EAEtB,qBAAqB,EACrB,wBAAwB,EACxB,0BAA0B,EAC1B,+BAA+B,EAChC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAGvE,OAAO,KAAK,EAAoB,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAUrF,OAAO,KAAK,EACV,iBAAiB,EAIlB,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EAIL,KAAK,QAAQ,EACd,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAMhD;;GAEG;AACH,MAAM,WAAW,eACf,SAAQ,IAAI,CACV,mBAAmB,CACjB,OAAO,CAAC,mBAAmB,CAAC,EAC5B,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,sBAAsB,CACvB,EACD,eAAe,GAAG,mBAAmB,CACtC;IACD,kCAAkC;IAClC,aAAa,CAAC,E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CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIvC;;OAEG;WAEU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAkFnC;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAiClC;;;OAGG;mBACkB,YAAY;IAmBjC;;;OAGG;mBACkB,aAAa;IAmBlC;;;OAGG;mBACkB,eAAe;IAapC;;;OAGG;mBACkB,uBAAuB;IA2D5C;;OAEG;IACH,iFAAiF;mBAC5D,mBAAmB;IAuDxC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAoBpC,8CAA8C;IAC9C,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAUnC,wCAAwC;IAExC,OAAO,CAAC,MAAM,CAAC,uBAAuB;mBAyBjB,sBAAsB;IA4D3C;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,SAAS;IAgBxB;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,2BAA2B;IAwB1C;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,2BAA2B;IAoB1C;;;OAGG;mBAEkB,sBAAsB;IAkF3C;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,MAAM,CAAC,sBAAsB;IAiDrC,sDAAsD;IACtD,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAoBpC,kCAAkC;IAClC,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAmCjC;;OAEG;mBAGkB,sBAAsB;CAoC5C;AAID,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
@@ -971,7 +971,7 @@ var LoggerAdapter = class extends BaseAdapter {
971
971
  let status = "unset";
972
972
  let statusMessage;
973
973
  const logSpans = this.logSpans;
974
- const logger2 = this.observabilityLogger;
974
+ const logger3 = this.observabilityLogger;
975
975
  return {
976
976
  context,
977
977
  setAttribute: /* @__PURE__ */ __name((key, value) => {
@@ -983,7 +983,7 @@ var LoggerAdapter = class extends BaseAdapter {
983
983
  addEvent: /* @__PURE__ */ __name((event) => {
984
984
  events.push(event);
985
985
  if (logSpans) {
986
- logger2.debug(`[SPAN EVENT] ${options.name}: ${event.name}`, {
986
+ logger3.debug(`[SPAN EVENT] ${options.name}: ${event.name}`, {
987
987
  traceId: context.traceId,
988
988
  spanId: context.spanId,
989
989
  eventAttributes: event.attributes
@@ -998,7 +998,7 @@ var LoggerAdapter = class extends BaseAdapter {
998
998
  const duration = (endTime ?? Date.now()) - startTime;
999
999
  if (logSpans) {
1000
1000
  const logMethod = status === "error" ? "warn" : "debug";
1001
- logger2[logMethod](`[SPAN END] ${options.name}`, {
1001
+ logger3[logMethod](`[SPAN END] ${options.name}`, {
1002
1002
  traceId: context.traceId,
1003
1003
  spanId: context.spanId,
1004
1004
  durationMs: duration,
@@ -1011,7 +1011,7 @@ var LoggerAdapter = class extends BaseAdapter {
1011
1011
  }, "end"),
1012
1012
  recordException: /* @__PURE__ */ __name((error) => {
1013
1013
  if (logSpans) {
1014
- logger2.error(`[SPAN ERROR] ${options.name}`, {
1014
+ logger3.error(`[SPAN ERROR] ${options.name}`, {
1015
1015
  traceId: context.traceId,
1016
1016
  spanId: context.spanId,
1017
1017
  error: error.message,
@@ -2502,6 +2502,24 @@ var Core = class _Core {
2502
2502
  */
2503
2503
  this._rootStore = null;
2504
2504
  }
2505
+ static {
2506
+ /**
2507
+ * Injected store hook for frontend (set via setRootStoreHook before initialize).
2508
+ * This is used instead of directly importing from @plyaz/store to prevent
2509
+ * duplicate store instances when bundlers create multiple module copies.
2510
+ */
2511
+ this._injectedStoreHook = null;
2512
+ }
2513
+ /**
2514
+ * Set the root store hook for frontend use.
2515
+ * Must be called before Core.initialize() when running in browser.
2516
+ * PlyazProvider calls this automatically with the store prop.
2517
+ *
2518
+ * @param store - The useRootStore hook from @plyaz/store
2519
+ */
2520
+ static setRootStoreHook(store) {
2521
+ _Core._injectedStoreHook = store;
2522
+ }
2505
2523
  /**
2506
2524
  * Setup environment and context
2507
2525
  */
@@ -3412,8 +3430,14 @@ var Core = class _Core {
3412
3430
  static async initializeRootStore(config, verbose) {
3413
3431
  const isFrontend = typeof window !== "undefined";
3414
3432
  if (isFrontend) {
3415
- _Core.log("Using frontend root store (Zustand)", verbose);
3416
- _Core._rootStore = store.useRootStore;
3433
+ if (!_Core._injectedStoreHook) {
3434
+ throw new errors.CorePackageError(
3435
+ "Root store hook not set. Call Core.setRootStoreHook(useRootStore) before Core.initialize(), or use PlyazProvider with the store prop: <PlyazProvider store={useRootStore} ...>",
3436
+ types.ERROR_CODES.CLIENT_INITIALIZATION_FAILED
3437
+ );
3438
+ }
3439
+ _Core.log("Using frontend root store (Zustand) - injected via setRootStoreHook", verbose);
3440
+ _Core._rootStore = _Core._injectedStoreHook;
3417
3441
  } else {
3418
3442
  _Core.log("Creating backend composite store (in-memory)", verbose);
3419
3443
  const ServerErrorMiddleware = getCoreDependency("ServerErrorMiddleware");
@@ -3522,26 +3546,76 @@ var Core = class _Core {
3522
3546
  errorStore,
3523
3547
  _Core.buildErrorHandlerConfig(_Core._errorConfig)
3524
3548
  );
3549
+ _Core.setupErrorEventSubscription(verbose);
3550
+ _Core.setupErrorStoreSubscription(verbose);
3551
+ _Core.log("Global error handler initialized with CoreEventManager integration", verbose);
3552
+ if (_Core._errorConfig.httpHandler !== false) {
3553
+ await _Core.createHttpErrorHandler(_Core._errorConfig, verbose);
3554
+ }
3555
+ }
3556
+ /**
3557
+ * Log serialized errors with full details.
3558
+ */
3559
+ static logErrors(errors, prefix = "ErrorStore") {
3560
+ for (const err of errors) {
3561
+ _Core.logger.error(`[${prefix}] ${err.code}: ${err.message}`, {
3562
+ id: err.id,
3563
+ code: err.code,
3564
+ message: err.message,
3565
+ category: err.category,
3566
+ source: err.source,
3567
+ status: err.status,
3568
+ isRetryable: err.isRetryable,
3569
+ context: err.context,
3570
+ timestamp: err.timestamp
3571
+ });
3572
+ }
3573
+ }
3574
+ /**
3575
+ * Setup SYSTEM.ERROR event subscription for error store updates.
3576
+ * Backend: Also logs errors with full details.
3577
+ * Frontend: Only updates store (logging handled by store subscription).
3578
+ */
3579
+ static setupErrorEventSubscription(verbose) {
3580
+ const isBackend = types.BACKEND_RUNTIMES.includes(_Core._coreServices.runtime);
3525
3581
  const errorEventCleanup = CoreEventManager.on(
3526
3582
  core.CORE_EVENTS.SYSTEM.ERROR,
3527
3583
  (event) => {
3528
3584
  if (!_Core._rootStore) return;
3529
3585
  try {
3530
3586
  const { errors } = event.data;
3531
- if (errors && errors.length > 0) {
3532
- _Core._rootStore.getState().errors.addErrors(errors);
3533
- _Core.log(`Added ${errors.length} error(s) to store`, verbose);
3534
- }
3587
+ if (!errors || errors.length === 0) return;
3588
+ _Core._rootStore.getState().errors.addErrors(errors);
3589
+ if (isBackend) _Core.logErrors(errors);
3590
+ _Core.log(`Added ${errors.length} error(s) to store`, verbose);
3535
3591
  } catch (e) {
3536
3592
  _Core.logger.error("Failed to handle error event", { error: e });
3537
3593
  }
3538
3594
  }
3539
3595
  );
3540
3596
  _Core._eventCleanupFns.push(errorEventCleanup);
3541
- _Core.log("Global error handler initialized with CoreEventManager integration", verbose);
3542
- if (_Core._errorConfig.httpHandler !== false) {
3543
- await _Core.createHttpErrorHandler(_Core._errorConfig, verbose);
3544
- }
3597
+ }
3598
+ /**
3599
+ * Setup error store subscription for frontend logging.
3600
+ * Logs new errors when they're added to the store.
3601
+ * Only active for non-backend runtimes (browser, nextjs, nuxt, edge).
3602
+ */
3603
+ static setupErrorStoreSubscription(verbose) {
3604
+ const isFrontend = !types.BACKEND_RUNTIMES.includes(_Core._coreServices.runtime);
3605
+ if (!isFrontend || !_Core._rootStore) return;
3606
+ let prevErrorCount = 0;
3607
+ const storeUnsubscribe = _Core._rootStore.subscribe((state) => {
3608
+ const currentCount = state.errors.errorCount;
3609
+ if (currentCount <= prevErrorCount) {
3610
+ prevErrorCount = currentCount;
3611
+ return;
3612
+ }
3613
+ const newErrors = state.errors.errors.slice(0, currentCount - prevErrorCount);
3614
+ _Core.logErrors(newErrors, "ErrorStore:FE");
3615
+ prevErrorCount = currentCount;
3616
+ });
3617
+ _Core._eventCleanupFns.push(storeUnsubscribe);
3618
+ _Core.log("Error store subscription initialized for frontend", verbose);
3545
3619
  }
3546
3620
  /**
3547
3621
  * Create HTTP error handler based on detected runtime.
@@ -3729,6 +3803,7 @@ var Core = class _Core {
3729
3803
  _Core.log("Feature flags initialized", verbose);
3730
3804
  }
3731
3805
  };
3806
+ var logger2 = new logger$1.PackageLogger({ packageName: "core", service: "DbService" });
3732
3807
  var DEFAULT_ENCRYPTION_FIELDS = {
3733
3808
  // User PII
3734
3809
  users: ["password_hash", "phone_number", "date_of_birth"],
@@ -3822,6 +3897,41 @@ var DbService = class _DbService {
3822
3897
  };
3823
3898
  CoreEventManager.emit(core.CORE_EVENTS.DATABASE.ERROR, payload);
3824
3899
  }
3900
+ /**
3901
+ * Creates merged event handlers that wrap user-provided handlers.
3902
+ * Adds Core-level logging and forwards to user handlers.
3903
+ *
3904
+ * Note: Unlike StorageService/NotificationService, DB events don't emit
3905
+ * to CoreEventManager by default (too verbose). User handlers can emit
3906
+ * if needed.
3907
+ *
3908
+ * @param userHandlers - User-provided event handlers from config
3909
+ * @returns Merged handlers with Core logging + user handlers
3910
+ */
3911
+ static createMergedEventHandlers(userHandlers) {
3912
+ return {
3913
+ ...userHandlers,
3914
+ onAfterWrite: /* @__PURE__ */ __name(async (event) => {
3915
+ logger2.debug("Database write completed", {
3916
+ operation: event.operation,
3917
+ table: event.table,
3918
+ duration: event.duration
3919
+ });
3920
+ if (userHandlers?.onAfterWrite) {
3921
+ await userHandlers.onAfterWrite(event);
3922
+ }
3923
+ }, "onAfterWrite"),
3924
+ onAfterRead: /* @__PURE__ */ __name(async (event) => {
3925
+ logger2.debug("Database read completed", {
3926
+ table: event.table,
3927
+ duration: event.duration
3928
+ });
3929
+ if (userHandlers?.onAfterRead) {
3930
+ await userHandlers.onAfterRead(event);
3931
+ }
3932
+ }, "onAfterRead")
3933
+ };
3934
+ }
3825
3935
  /**
3826
3936
  * Gets the singleton instance of DbService
3827
3937
  *
@@ -4026,6 +4136,8 @@ var DbService = class _DbService {
4026
4136
  if (cache) dbConfig.cache = cache;
4027
4137
  if (audit) dbConfig.audit = audit;
4028
4138
  if (encryption) dbConfig.encryption = encryption;
4139
+ const events = _DbService.createMergedEventHandlers(config.events);
4140
+ if (events) dbConfig.events = events;
4029
4141
  return dbConfig;
4030
4142
  }
4031
4143
  /**