@plyaz/core 1.10.0 → 1.11.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.
@@ -2980,6 +2980,11 @@ var Core = class _Core {
2980
2980
  environment: globalEnvironment,
2981
2981
  runtime,
2982
2982
  apiClient: apiConfig ? { baseURL: apiConfig.baseURL, ...apiConfig } : void 0,
2983
+ db: options.db,
2984
+ cache: options.cache,
2985
+ storage: options.storage,
2986
+ notifications: options.notifications,
2987
+ observability: options.observability,
2983
2988
  services: mergedServices,
2984
2989
  stores: {
2985
2990
  // Returns specific slice from namespaced root store (type-safe)
@@ -3789,26 +3794,76 @@ var Core = class _Core {
3789
3794
  errorStore,
3790
3795
  _Core.buildErrorHandlerConfig(_Core._errorConfig)
3791
3796
  );
3797
+ _Core.setupErrorEventSubscription(verbose);
3798
+ _Core.setupErrorStoreSubscription(verbose);
3799
+ _Core.log("Global error handler initialized with CoreEventManager integration", verbose);
3800
+ if (_Core._errorConfig.httpHandler !== false) {
3801
+ await _Core.createHttpErrorHandler(_Core._errorConfig, verbose);
3802
+ }
3803
+ }
3804
+ /**
3805
+ * Log serialized errors with full details.
3806
+ */
3807
+ static logErrors(errors, prefix = "ErrorStore") {
3808
+ for (const err of errors) {
3809
+ _Core.logger.error(`[${prefix}] ${err.code}: ${err.message}`, {
3810
+ id: err.id,
3811
+ code: err.code,
3812
+ message: err.message,
3813
+ category: err.category,
3814
+ source: err.source,
3815
+ status: err.status,
3816
+ isRetryable: err.isRetryable,
3817
+ context: err.context,
3818
+ timestamp: err.timestamp
3819
+ });
3820
+ }
3821
+ }
3822
+ /**
3823
+ * Setup SYSTEM.ERROR event subscription for error store updates.
3824
+ * Backend: Also logs errors with full details.
3825
+ * Frontend: Only updates store (logging handled by store subscription).
3826
+ */
3827
+ static setupErrorEventSubscription(verbose) {
3828
+ const isBackend = types.BACKEND_RUNTIMES.includes(_Core._coreServices.runtime);
3792
3829
  const errorEventCleanup = CoreEventManager.on(
3793
3830
  core.CORE_EVENTS.SYSTEM.ERROR,
3794
3831
  (event) => {
3795
3832
  if (!_Core._rootStore) return;
3796
3833
  try {
3797
3834
  const { errors } = event.data;
3798
- if (errors && errors.length > 0) {
3799
- _Core._rootStore.getState().errors.addErrors(errors);
3800
- _Core.log(`Added ${errors.length} error(s) to store`, verbose);
3801
- }
3835
+ if (!errors || errors.length === 0) return;
3836
+ _Core._rootStore.getState().errors.addErrors(errors);
3837
+ if (isBackend) _Core.logErrors(errors);
3838
+ _Core.log(`Added ${errors.length} error(s) to store`, verbose);
3802
3839
  } catch (e) {
3803
3840
  _Core.logger.error("Failed to handle error event", { error: e });
3804
3841
  }
3805
3842
  }
3806
3843
  );
3807
3844
  _Core._eventCleanupFns.push(errorEventCleanup);
3808
- _Core.log("Global error handler initialized with CoreEventManager integration", verbose);
3809
- if (_Core._errorConfig.httpHandler !== false) {
3810
- await _Core.createHttpErrorHandler(_Core._errorConfig, verbose);
3811
- }
3845
+ }
3846
+ /**
3847
+ * Setup error store subscription for frontend logging.
3848
+ * Logs new errors when they're added to the store.
3849
+ * Only active for non-backend runtimes (browser, nextjs, nuxt, edge).
3850
+ */
3851
+ static setupErrorStoreSubscription(verbose) {
3852
+ const isFrontend = !types.BACKEND_RUNTIMES.includes(_Core._coreServices.runtime);
3853
+ if (!isFrontend || !_Core._rootStore) return;
3854
+ let prevErrorCount = 0;
3855
+ const storeUnsubscribe = _Core._rootStore.subscribe((state) => {
3856
+ const currentCount = state.errors.errorCount;
3857
+ if (currentCount <= prevErrorCount) {
3858
+ prevErrorCount = currentCount;
3859
+ return;
3860
+ }
3861
+ const newErrors = state.errors.errors.slice(0, currentCount - prevErrorCount);
3862
+ _Core.logErrors(newErrors, "ErrorStore:FE");
3863
+ prevErrorCount = currentCount;
3864
+ });
3865
+ _Core._eventCleanupFns.push(storeUnsubscribe);
3866
+ _Core.log("Error store subscription initialized for frontend", verbose);
3812
3867
  }
3813
3868
  /**
3814
3869
  * Create HTTP error handler based on detected runtime.
@@ -6815,7 +6870,7 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
6815
6870
  // Constructor
6816
6871
  // ─────────────────────────────────────────────────────────────────────────
6817
6872
  constructor(config = {}, options) {
6818
- const apiBasePath = config.apiBasePath || "/api/examples";
6873
+ const apiBasePath = config.apiBasePath || "";
6819
6874
  super({
6820
6875
  serviceName: "ExampleFrontendService",
6821
6876
  supportedRuntimes: ["frontend"],
@@ -6840,20 +6895,20 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
6840
6895
  // Note: Use relative paths since apiClient.baseURL is already set to apiBasePath
6841
6896
  fetchers: {
6842
6897
  fetchAll: /* @__PURE__ */ __name(async (query) => {
6843
- return this.apiClient.get("", { params: query });
6898
+ return this.apiClient.get("/examples", { params: query });
6844
6899
  }, "fetchAll"),
6845
6900
  fetchById: /* @__PURE__ */ __name(async (id) => {
6846
- return this.apiClient.get(`/${id}`);
6901
+ return this.apiClient.get(`/examples/${id}`);
6847
6902
  }, "fetchById"),
6848
6903
  create: /* @__PURE__ */ __name(async (data) => {
6849
- return this.apiClient.post("", data);
6904
+ return this.apiClient.post("/examples", data);
6850
6905
  }, "create"),
6851
6906
  update: /* @__PURE__ */ __name(async (payload) => {
6852
6907
  const { id, data } = payload;
6853
- return this.apiClient.patch(`/${id}`, data);
6908
+ return this.apiClient.patch(`/examples/${id}`, data);
6854
6909
  }, "update"),
6855
6910
  delete: /* @__PURE__ */ __name(async (id) => {
6856
- return this.apiClient.delete(`/${id}`);
6911
+ return this.apiClient.delete(`/examples/${id}`);
6857
6912
  }, "delete")
6858
6913
  }
6859
6914
  // Store handlers - customize how data syncs to store
@@ -6921,7 +6976,7 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
6921
6976
  // The ?? operator only falls through on null/undefined, not empty strings.
6922
6977
  // An empty string is not a valid API path, so we treat it as "not provided" and fall through to default.
6923
6978
  // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
6924
- apiBasePath: config.apiBasePath || options?.apiClient?.options?.baseURL || "/api/examples"
6979
+ apiBasePath: config.apiBasePath || options?.apiClient?.options?.baseURL || ""
6925
6980
  };
6926
6981
  const service = new _FrontendExampleDomainService(mergedConfig, options);
6927
6982
  if (mergedConfig.autoFetch) {
@@ -8645,7 +8700,10 @@ async function initializeServices(config) {
8645
8700
  globalThis.console.log("[PlyazProvider] Initializing domain services...");
8646
8701
  }
8647
8702
  await ServiceRegistry.initialize({
8703
+ environment: config.environment,
8704
+ runtime: config.runtime ?? detectRuntime(),
8648
8705
  apiClient: { baseURL: config.api.baseURL },
8706
+ observability: config.observability,
8649
8707
  services: config.services,
8650
8708
  // Provide store registry for injecting stores into services
8651
8709
  stores: createStoreRegistry()
@@ -9058,7 +9116,7 @@ var FilesMapper = new FilesMapperClass();
9058
9116
  var logger5 = new logger$1.PackageLogger({ packageName: "core", service: "FrontendFilesDomainService" });
9059
9117
  var FrontendFilesDomainService = class _FrontendFilesDomainService extends BaseFrontendDomainService {
9060
9118
  constructor(config = {}, options) {
9061
- const apiBasePath = config.apiBasePath || "/api";
9119
+ const apiBasePath = config.apiBasePath || "";
9062
9120
  super({
9063
9121
  serviceName: "FrontendFilesDomainService",
9064
9122
  supportedRuntimes: ["frontend"],
@@ -9121,7 +9179,7 @@ var FrontendFilesDomainService = class _FrontendFilesDomainService extends BaseF
9121
9179
  // The ?? operator only falls through on null/undefined, not empty strings.
9122
9180
  // An empty string is not a valid API path, so we treat it as "not provided" and fall through to default.
9123
9181
  // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
9124
- apiBasePath: config.apiBasePath || options?.apiClient?.options?.baseURL || "/api"
9182
+ apiBasePath: config.apiBasePath || options?.apiClient?.options?.baseURL || ""
9125
9183
  };
9126
9184
  return new _FrontendFilesDomainService(mergedConfig, options);
9127
9185
  }