@plyaz/core 1.10.1 → 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.
@@ -3794,26 +3794,76 @@ var Core = class _Core {
3794
3794
  errorStore,
3795
3795
  _Core.buildErrorHandlerConfig(_Core._errorConfig)
3796
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);
3797
3829
  const errorEventCleanup = CoreEventManager.on(
3798
3830
  core.CORE_EVENTS.SYSTEM.ERROR,
3799
3831
  (event) => {
3800
3832
  if (!_Core._rootStore) return;
3801
3833
  try {
3802
3834
  const { errors } = event.data;
3803
- if (errors && errors.length > 0) {
3804
- _Core._rootStore.getState().errors.addErrors(errors);
3805
- _Core.log(`Added ${errors.length} error(s) to store`, verbose);
3806
- }
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);
3807
3839
  } catch (e) {
3808
3840
  _Core.logger.error("Failed to handle error event", { error: e });
3809
3841
  }
3810
3842
  }
3811
3843
  );
3812
3844
  _Core._eventCleanupFns.push(errorEventCleanup);
3813
- _Core.log("Global error handler initialized with CoreEventManager integration", verbose);
3814
- if (_Core._errorConfig.httpHandler !== false) {
3815
- await _Core.createHttpErrorHandler(_Core._errorConfig, verbose);
3816
- }
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);
3817
3867
  }
3818
3868
  /**
3819
3869
  * Create HTTP error handler based on detected runtime.
@@ -6820,7 +6870,7 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
6820
6870
  // Constructor
6821
6871
  // ─────────────────────────────────────────────────────────────────────────
6822
6872
  constructor(config = {}, options) {
6823
- const apiBasePath = config.apiBasePath || "/api/examples";
6873
+ const apiBasePath = config.apiBasePath || "";
6824
6874
  super({
6825
6875
  serviceName: "ExampleFrontendService",
6826
6876
  supportedRuntimes: ["frontend"],
@@ -6845,20 +6895,20 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
6845
6895
  // Note: Use relative paths since apiClient.baseURL is already set to apiBasePath
6846
6896
  fetchers: {
6847
6897
  fetchAll: /* @__PURE__ */ __name(async (query) => {
6848
- return this.apiClient.get("", { params: query });
6898
+ return this.apiClient.get("/examples", { params: query });
6849
6899
  }, "fetchAll"),
6850
6900
  fetchById: /* @__PURE__ */ __name(async (id) => {
6851
- return this.apiClient.get(`/${id}`);
6901
+ return this.apiClient.get(`/examples/${id}`);
6852
6902
  }, "fetchById"),
6853
6903
  create: /* @__PURE__ */ __name(async (data) => {
6854
- return this.apiClient.post("", data);
6904
+ return this.apiClient.post("/examples", data);
6855
6905
  }, "create"),
6856
6906
  update: /* @__PURE__ */ __name(async (payload) => {
6857
6907
  const { id, data } = payload;
6858
- return this.apiClient.patch(`/${id}`, data);
6908
+ return this.apiClient.patch(`/examples/${id}`, data);
6859
6909
  }, "update"),
6860
6910
  delete: /* @__PURE__ */ __name(async (id) => {
6861
- return this.apiClient.delete(`/${id}`);
6911
+ return this.apiClient.delete(`/examples/${id}`);
6862
6912
  }, "delete")
6863
6913
  }
6864
6914
  // Store handlers - customize how data syncs to store
@@ -6926,7 +6976,7 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
6926
6976
  // The ?? operator only falls through on null/undefined, not empty strings.
6927
6977
  // An empty string is not a valid API path, so we treat it as "not provided" and fall through to default.
6928
6978
  // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
6929
- apiBasePath: config.apiBasePath || options?.apiClient?.options?.baseURL || "/api/examples"
6979
+ apiBasePath: config.apiBasePath || options?.apiClient?.options?.baseURL || ""
6930
6980
  };
6931
6981
  const service = new _FrontendExampleDomainService(mergedConfig, options);
6932
6982
  if (mergedConfig.autoFetch) {
@@ -9066,7 +9116,7 @@ var FilesMapper = new FilesMapperClass();
9066
9116
  var logger5 = new logger$1.PackageLogger({ packageName: "core", service: "FrontendFilesDomainService" });
9067
9117
  var FrontendFilesDomainService = class _FrontendFilesDomainService extends BaseFrontendDomainService {
9068
9118
  constructor(config = {}, options) {
9069
- const apiBasePath = config.apiBasePath || "/api";
9119
+ const apiBasePath = config.apiBasePath || "";
9070
9120
  super({
9071
9121
  serviceName: "FrontendFilesDomainService",
9072
9122
  supportedRuntimes: ["frontend"],
@@ -9129,7 +9179,7 @@ var FrontendFilesDomainService = class _FrontendFilesDomainService extends BaseF
9129
9179
  // The ?? operator only falls through on null/undefined, not empty strings.
9130
9180
  // An empty string is not a valid API path, so we treat it as "not provided" and fall through to default.
9131
9181
  // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
9132
- apiBasePath: config.apiBasePath || options?.apiClient?.options?.baseURL || "/api"
9182
+ apiBasePath: config.apiBasePath || options?.apiClient?.options?.baseURL || ""
9133
9183
  };
9134
9184
  return new _FrontendFilesDomainService(mergedConfig, options);
9135
9185
  }