@plyaz/core 1.8.4 → 1.9.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/dist/index.js CHANGED
@@ -33261,6 +33261,80 @@ var ApiClientService = class _ApiClientService {
33261
33261
  static {
33262
33262
  this.initPromise = null;
33263
33263
  }
33264
+ /**
33265
+ * Build the core error handler for API clients.
33266
+ * This handler emits errors to CoreEventManager for global error handling.
33267
+ *
33268
+ * Handles:
33269
+ * - Single errors (network, timeout)
33270
+ * - Array of errors from API responses (validation, business logic)
33271
+ * - Serialization to unified SerializedError format
33272
+ * - Event emission to CORE_EVENTS.SYSTEM.ERROR and CORE_EVENTS.API.REQUEST_ERROR
33273
+ *
33274
+ * @returns Error handler function compatible with ApiClientOptions.onError
33275
+ */
33276
+ static buildCoreErrorHandler() {
33277
+ return async (error) => {
33278
+ const requestId = errors.generateRequestId();
33279
+ const method = error.config?.method ?? "UNKNOWN";
33280
+ const url = error.config?.url ?? "unknown";
33281
+ try {
33282
+ const errorDetails = Array.isArray(error.response?.data) ? error.response.data : [];
33283
+ if (errorDetails.length === 0) {
33284
+ const serializedError = {
33285
+ id: requestId,
33286
+ code: types.ERROR_CODES.CORE_API_CLIENT_REQUEST_FAILED,
33287
+ message: error.message ?? "API request failed",
33288
+ status: error.status,
33289
+ category: types.ERROR_CATEGORY.Network,
33290
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
33291
+ isRetryable: error.status ? error.status >= types.HTTP_STATUS.INTERNAL_SERVER_ERROR : false,
33292
+ source: "api-client",
33293
+ dismissed: false,
33294
+ context: {
33295
+ method,
33296
+ url,
33297
+ requestId
33298
+ }
33299
+ };
33300
+ CoreEventManager.emit(types.CORE_EVENTS.SYSTEM.ERROR, { errors: [serializedError] });
33301
+ } else {
33302
+ const serializedErrors = errorDetails.map(
33303
+ (detail, index) => ({
33304
+ id: `${requestId}-${index}`,
33305
+ code: detail.errorCode ?? types.ERROR_CODES.CORE_API_CLIENT_REQUEST_FAILED,
33306
+ message: detail.message ?? error.message ?? "API request failed",
33307
+ status: error.status,
33308
+ category: types.ERROR_CATEGORY.Network,
33309
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
33310
+ isRetryable: error.status ? error.status >= types.HTTP_STATUS.INTERNAL_SERVER_ERROR : false,
33311
+ source: "api-client",
33312
+ dismissed: false,
33313
+ context: {
33314
+ method,
33315
+ url,
33316
+ requestId,
33317
+ field: detail.field,
33318
+ valueGiven: detail.valueGiven,
33319
+ allowedValues: detail.allowedValues,
33320
+ constraints: detail.constraints
33321
+ }
33322
+ })
33323
+ );
33324
+ CoreEventManager.emit(types.CORE_EVENTS.SYSTEM.ERROR, { errors: serializedErrors });
33325
+ }
33326
+ } catch (e) {
33327
+ console.error("[ApiClientService] Failed to emit error event:", e);
33328
+ }
33329
+ _ApiClientService.emitApiError(error, {
33330
+ method,
33331
+ url,
33332
+ requestId,
33333
+ status: error.status,
33334
+ duration: 0
33335
+ });
33336
+ };
33337
+ }
33264
33338
  /**
33265
33339
  * Initialize the API client with environment config and API options
33266
33340
  *
@@ -33298,71 +33372,12 @@ var ApiClientService = class _ApiClientService {
33298
33372
  * 2. Environment metadata (envConfig - apiKey)
33299
33373
  * 3. API configuration (apiConfig - baseURL, encryption, timeout, etc.)
33300
33374
  */
33301
- // eslint-disable-next-line max-lines-per-function, complexity
33375
+ // eslint-disable-next-line complexity
33302
33376
  static async createClient(envConfig, apiConfig) {
33303
33377
  try {
33304
33378
  const envDefaults = getConfigForEnvironment(envConfig.env);
33305
33379
  const envMetadataMapped = mapEnvironmentMetadata(envConfig, envDefaults);
33306
- const coreErrorHandler = /* @__PURE__ */ __name(async (error) => {
33307
- const requestId = errors.generateRequestId();
33308
- const method = error.config?.method ?? "UNKNOWN";
33309
- const url = error.config?.url ?? "unknown";
33310
- try {
33311
- const errorDetails = Array.isArray(error.response?.data) ? error.response.data : [];
33312
- if (errorDetails.length === 0) {
33313
- const serializedError = {
33314
- id: requestId,
33315
- code: types.ERROR_CODES.CORE_API_CLIENT_REQUEST_FAILED,
33316
- message: error.message ?? "API request failed",
33317
- status: error.status,
33318
- category: types.ERROR_CATEGORY.Network,
33319
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
33320
- isRetryable: error.status ? error.status >= types.HTTP_STATUS.INTERNAL_SERVER_ERROR : false,
33321
- source: "api-client",
33322
- dismissed: false,
33323
- context: {
33324
- method,
33325
- url,
33326
- requestId
33327
- }
33328
- };
33329
- CoreEventManager.emit(types.CORE_EVENTS.SYSTEM.ERROR, { errors: [serializedError] });
33330
- } else {
33331
- const serializedErrors = errorDetails.map(
33332
- (detail, index) => ({
33333
- id: `${requestId}-${index}`,
33334
- code: detail.errorCode ?? types.ERROR_CODES.CORE_API_CLIENT_REQUEST_FAILED,
33335
- message: detail.message ?? error.message ?? "API request failed",
33336
- status: error.status,
33337
- category: types.ERROR_CATEGORY.Network,
33338
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
33339
- isRetryable: error.status ? error.status >= types.HTTP_STATUS.INTERNAL_SERVER_ERROR : false,
33340
- source: "api-client",
33341
- dismissed: false,
33342
- context: {
33343
- method,
33344
- url,
33345
- requestId,
33346
- field: detail.field,
33347
- valueGiven: detail.valueGiven,
33348
- allowedValues: detail.allowedValues,
33349
- constraints: detail.constraints
33350
- }
33351
- })
33352
- );
33353
- CoreEventManager.emit(types.CORE_EVENTS.SYSTEM.ERROR, { errors: serializedErrors });
33354
- }
33355
- } catch (e) {
33356
- console.error("[ApiClientService] Failed to emit error event:", e);
33357
- }
33358
- _ApiClientService.emitApiError(error, {
33359
- method,
33360
- url,
33361
- requestId,
33362
- status: error.status,
33363
- duration: 0
33364
- });
33365
- }, "coreErrorHandler");
33380
+ const coreErrorHandler = _ApiClientService.buildCoreErrorHandler();
33366
33381
  const userOnError = apiConfig?.onError;
33367
33382
  const combinedOnError = userOnError ? Array.isArray(userOnError) ? [...userOnError, coreErrorHandler] : [userOnError, coreErrorHandler] : coreErrorHandler;
33368
33383
  const mergedOptions = frontend.mergeConfigs(
@@ -33537,11 +33552,13 @@ var ApiClientService = class _ApiClientService {
33537
33552
  try {
33538
33553
  const envDefaults = getConfigForEnvironment(envConfig.env);
33539
33554
  const envMetadataMapped = mapEnvironmentMetadata(envConfig, envDefaults);
33540
- const mergedOptions = frontend.mergeConfigs(
33541
- envDefaults,
33542
- envMetadataMapped,
33543
- apiConfig ?? {}
33544
- );
33555
+ const coreErrorHandler = _ApiClientService.buildCoreErrorHandler();
33556
+ const userOnError = apiConfig?.onError;
33557
+ const combinedOnError = userOnError ? Array.isArray(userOnError) ? [...userOnError, coreErrorHandler] : [userOnError, coreErrorHandler] : coreErrorHandler;
33558
+ const mergedOptions = frontend.mergeConfigs(envDefaults, envMetadataMapped, {
33559
+ ...apiConfig ?? {},
33560
+ onError: combinedOnError
33561
+ });
33545
33562
  validateEnvironmentConfig(envConfig, mergedOptions);
33546
33563
  const dedicatedClient = await frontend.createApiClient(mergedOptions);
33547
33564
  return dedicatedClient;
@@ -33563,10 +33580,66 @@ var ApiClientService = class _ApiClientService {
33563
33580
  );
33564
33581
  }
33565
33582
  }
33583
+ /**
33584
+ * Create a standalone API client with Core error handling.
33585
+ *
33586
+ * This is a simpler alternative to `createInstance()` that doesn't require
33587
+ * environment config. Use this when you just need the error handling without
33588
+ * environment-specific defaults (production validation, etc.).
33589
+ *
33590
+ * **Use cases:**
33591
+ * - Domain services that need their own API client
33592
+ * - Testing with isolated API clients
33593
+ * - Simple client creation without environment setup
33594
+ *
33595
+ * @param apiConfig - API configuration (baseURL, timeout, etc.)
33596
+ * @returns Promise that resolves to a client with Core error handling
33597
+ *
33598
+ * @example
33599
+ * ```typescript
33600
+ * // In BaseDomainService or any service
33601
+ * const client = await ApiClientService.createStandaloneClient({
33602
+ * baseURL: '/api/examples',
33603
+ * timeout: 10000,
33604
+ * });
33605
+ *
33606
+ * // Errors are automatically emitted to CoreEventManager
33607
+ * const response = await client.get('/items');
33608
+ * ```
33609
+ */
33610
+ static async createStandaloneClient(apiConfig) {
33611
+ try {
33612
+ const coreErrorHandler = _ApiClientService.buildCoreErrorHandler();
33613
+ const userOnError = apiConfig.onError;
33614
+ const combinedOnError = userOnError ? Array.isArray(userOnError) ? [...userOnError, coreErrorHandler] : [userOnError, coreErrorHandler] : coreErrorHandler;
33615
+ const client = await frontend.createApiClient({
33616
+ ...apiConfig,
33617
+ onError: combinedOnError
33618
+ });
33619
+ return client;
33620
+ } catch (error) {
33621
+ throw new frontend.ApiPackageError(
33622
+ "service.standalone_client_creation.failed",
33623
+ types.PACKAGE_STATUS_CODES.INITIALIZATION_FAILED,
33624
+ types.API_ERROR_CODES.CLIENT_INITIALIZATION_FAILED,
33625
+ {
33626
+ cause: error instanceof Error ? error : void 0,
33627
+ context: {
33628
+ operation: types.OPERATIONS.INITIALIZATION,
33629
+ originalError: error instanceof Error ? error.message : String(error),
33630
+ i18n: {
33631
+ error: error instanceof Error ? error.message : String(error)
33632
+ }
33633
+ }
33634
+ }
33635
+ );
33636
+ }
33637
+ }
33566
33638
  };
33567
33639
  var getApiClient = /* @__PURE__ */ __name(() => ApiClientService.getClient(), "getApiClient");
33568
33640
  var initApiClient = /* @__PURE__ */ __name((envConfig, apiConfig) => ApiClientService.init(envConfig, apiConfig), "initApiClient");
33569
33641
  var createApiClientInstance = /* @__PURE__ */ __name((envConfig, apiConfig) => ApiClientService.createInstance(envConfig, apiConfig), "createApiClientInstance");
33642
+ var createStandaloneApiClient = /* @__PURE__ */ __name((apiConfig) => ApiClientService.createStandaloneClient(apiConfig), "createStandaloneApiClient");
33570
33643
  var BaseAdapter = class {
33571
33644
  constructor() {
33572
33645
  this._isInitialized = false;
@@ -36138,6 +36211,7 @@ var Core = class _Core {
36138
36211
  _Core._errorHandler.destroy();
36139
36212
  _Core._errorHandler = null;
36140
36213
  middleware.clearEventEmitter();
36214
+ errors.BaseError.clearEventEmitter();
36141
36215
  }
36142
36216
  _Core._errorConfig = {};
36143
36217
  _Core._httpErrorHandler = null;
@@ -36326,6 +36400,28 @@ var Core = class _Core {
36326
36400
  };
36327
36401
  }
36328
36402
  }
36403
+ /**
36404
+ * Serialize a PackageErrorLike to SerializedError format.
36405
+ * Used by BaseError.setEventEmitter() to convert errors for the store.
36406
+ */
36407
+ static serializePackageError(error) {
36408
+ const serviceName = typeof error.context?.service === "string" ? error.context.service : "core";
36409
+ return {
36410
+ id: generateId(),
36411
+ code: error.errorCode ?? types.ERROR_CODES.UNKNOWN_ERROR,
36412
+ message: error.message,
36413
+ status: error.statusCode,
36414
+ category: error.category ?? errors$1.ERROR_CATEGORY.Server,
36415
+ timestamp: error.timestamp ?? (/* @__PURE__ */ new Date()).toISOString(),
36416
+ isRetryable: error.retryable ?? false,
36417
+ source: serviceName,
36418
+ dismissed: false,
36419
+ context: {
36420
+ correlationId: error.correlationId,
36421
+ ...error.context
36422
+ }
36423
+ };
36424
+ }
36329
36425
  /** Get error store actions from root store */
36330
36426
  static getErrorStoreActions() {
36331
36427
  if (!_Core._rootStore) {
@@ -36337,12 +36433,17 @@ var Core = class _Core {
36337
36433
  return _Core._rootStore.getState().errors;
36338
36434
  }
36339
36435
  /** Build global error handler config */
36340
- // eslint-disable-next-line complexity
36341
36436
  static buildErrorHandlerConfig(config) {
36437
+ const baseErrorFilter = /* @__PURE__ */ __name((error) => {
36438
+ if (error instanceof errors.BaseError) {
36439
+ return false;
36440
+ }
36441
+ return config?.filter ? config.filter(error) : true;
36442
+ }, "baseErrorFilter");
36342
36443
  return {
36343
36444
  source: config?.source ?? "global",
36344
36445
  maxErrors: config?.maxErrors ?? DEFAULT_MAX_ERRORS,
36345
- filter: config?.filter,
36446
+ filter: baseErrorFilter,
36346
36447
  onError: config?.onError,
36347
36448
  logToConsole: config?.logToConsole ?? false
36348
36449
  };
@@ -36363,6 +36464,15 @@ var Core = class _Core {
36363
36464
  });
36364
36465
  await _Core.initializeRootStore(_Core._errorConfig, verbose);
36365
36466
  middleware.setEventEmitter(CoreEventManager.emit.bind(CoreEventManager));
36467
+ errors.BaseError.setEventEmitter((error) => {
36468
+ const serializedError = _Core.serializePackageError(error);
36469
+ const serviceName = serializedError.source ?? "core";
36470
+ CoreEventManager.emit(core.CORE_EVENTS.SYSTEM.ERROR, {
36471
+ errors: [serializedError],
36472
+ context: serviceName,
36473
+ recoverable: error.retryable ?? false
36474
+ });
36475
+ });
36366
36476
  const errorStore = _Core.getErrorStoreActions();
36367
36477
  _Core._errorHandler = middleware.initializeGlobalErrorHandler(
36368
36478
  errorStore,
@@ -36458,9 +36568,15 @@ var Core = class _Core {
36458
36568
  }
36459
36569
  /**
36460
36570
  * Subscribe to CoreEventManager error events
36461
- * Forwards system, entity, API, validation, database, and auth errors to the global error handler.
36571
+ * Forwards entity, API, validation, database, and auth errors to the global error handler.
36572
+ *
36573
+ * NOTE: SYSTEM.ERROR is NOT subscribed here - it's handled in initializeErrorHandler()
36574
+ * via the BaseError.setEventEmitter() + addErrors() pattern to avoid duplicate subscriptions.
36575
+ *
36576
+ * For non-BaseError errors, domain-specific events (ENTITY.ERROR, API.REQUEST_ERROR, etc.)
36577
+ * are captured here. BaseError instances are skipped (they already auto-emit via SYSTEM.ERROR).
36462
36578
  *
36463
- * Note: Database errors (DATABASE.ERROR) are only subscribed on backend runtimes since
36579
+ * Database errors (DATABASE.ERROR) are only subscribed on backend runtimes since
36464
36580
  * DbService is backend-only (skipDb: true on frontend).
36465
36581
  */
36466
36582
  static subscribeToErrorEvents(verbose) {
@@ -36468,78 +36584,36 @@ var Core = class _Core {
36468
36584
  return;
36469
36585
  }
36470
36586
  _Core.log("Subscribing to error events...", verbose);
36471
- const cleanupSystemError = CoreEventManager.on(core.CORE_EVENTS.SYSTEM.ERROR, (event) => {
36472
- if (_Core._errorHandler && event.data?.errors?.length) {
36473
- for (const err of event.data.errors) {
36474
- _Core._errorHandler.captureError(err, "system");
36587
+ const subscribeError = /* @__PURE__ */ __name((event, source) => {
36588
+ return CoreEventManager.on(event, (e) => {
36589
+ if (_Core._errorHandler && e.data?.error && !(e.data.error instanceof errors.BaseError)) {
36590
+ _Core._errorHandler.captureError(e.data.error, source);
36475
36591
  }
36476
- }
36477
- });
36478
- const cleanupEntityError = CoreEventManager.on(core.CORE_EVENTS.ENTITY.ERROR, (event) => {
36479
- if (_Core._errorHandler && event.data) {
36480
- _Core._errorHandler.captureError(event.data.error, "entity");
36481
- }
36482
- });
36483
- const cleanupApiError = CoreEventManager.on(core.CORE_EVENTS.API.REQUEST_ERROR, (event) => {
36484
- if (_Core._errorHandler && event.data) {
36485
- _Core._errorHandler.captureError(event.data.error, "api");
36486
- }
36487
- });
36488
- const cleanupValidationError = CoreEventManager.on(core.CORE_EVENTS.VALIDATION.FAILED, (event) => {
36489
- if (_Core._errorHandler && event.data) {
36490
- _Core._errorHandler.captureError(event.data.error, "validation");
36491
- }
36492
- });
36493
- const cleanupAuthUnauthorized = CoreEventManager.on(core.CORE_EVENTS.AUTH.UNAUTHORIZED, (event) => {
36494
- if (_Core._errorHandler && event.data?.error) {
36495
- _Core._errorHandler.captureError(event.data.error, "auth");
36496
- }
36497
- });
36498
- const cleanupAuthSessionExpired = CoreEventManager.on(
36499
- core.CORE_EVENTS.AUTH.SESSION_EXPIRED,
36500
- (event) => {
36501
- if (_Core._errorHandler && event.data?.error) {
36502
- _Core._errorHandler.captureError(event.data.error, "auth");
36503
- }
36504
- }
36505
- );
36592
+ });
36593
+ }, "subscribeError");
36506
36594
  _Core._eventCleanupFns.push(
36507
- cleanupSystemError,
36508
- cleanupEntityError,
36509
- cleanupApiError,
36510
- cleanupValidationError,
36511
- cleanupAuthUnauthorized,
36512
- cleanupAuthSessionExpired
36595
+ subscribeError(core.CORE_EVENTS.ENTITY.ERROR, "entity"),
36596
+ subscribeError(core.CORE_EVENTS.API.REQUEST_ERROR, "api"),
36597
+ subscribeError(core.CORE_EVENTS.VALIDATION.FAILED, "validation"),
36598
+ subscribeError(core.CORE_EVENTS.AUTH.UNAUTHORIZED, "auth"),
36599
+ subscribeError(core.CORE_EVENTS.AUTH.SESSION_EXPIRED, "auth")
36513
36600
  );
36514
36601
  if (_Core.isRuntimeCompatible("backend")) {
36515
- const cleanupDatabaseError = CoreEventManager.on(core.CORE_EVENTS.DATABASE.ERROR, (event) => {
36516
- if (_Core._errorHandler && event.data) {
36517
- _Core._errorHandler.captureError(event.data.error, "database");
36518
- }
36519
- });
36520
- _Core._eventCleanupFns.push(cleanupDatabaseError);
36521
- const cleanupStorageError = CoreEventManager.on(core.CORE_EVENTS.STORAGE.ERROR, (event) => {
36522
- if (_Core._errorHandler && event.data) {
36523
- _Core._errorHandler.captureError(event.data.error, "storage");
36524
- }
36525
- });
36526
- _Core._eventCleanupFns.push(cleanupStorageError);
36527
- const cleanupNotificationError = CoreEventManager.on(
36528
- core.CORE_EVENTS.NOTIFICATION.ERROR,
36529
- (event) => {
36530
- if (_Core._errorHandler && event.data) {
36531
- _Core._errorHandler.captureError(event.data.error, "notification");
36532
- }
36533
- }
36602
+ _Core._eventCleanupFns.push(
36603
+ subscribeError(core.CORE_EVENTS.DATABASE.ERROR, "database"),
36604
+ subscribeError(core.CORE_EVENTS.STORAGE.ERROR, "storage"),
36605
+ subscribeError(core.CORE_EVENTS.NOTIFICATION.ERROR, "notification"),
36606
+ subscribeError(core.CORE_EVENTS.CACHE.ERROR, "cache")
36607
+ );
36608
+ _Core.log(
36609
+ "Subscribed to backend error events (database, storage, notification, cache)",
36610
+ verbose
36534
36611
  );
36535
- _Core._eventCleanupFns.push(cleanupNotificationError);
36536
- _Core.log("Subscribed to backend error events (database, storage, notification)", verbose);
36537
- }
36538
- const eventTypes = ["system", "entity", "api", "validation", "auth"];
36539
- if (_Core.isRuntimeCompatible("backend")) {
36540
- eventTypes.push("database", "storage", "notification");
36541
36612
  }
36542
- _Core.log(`Subscribed to error events: ${eventTypes.join(", ")}`, verbose);
36613
+ const eventTypes = ["entity", "api", "validation", "auth"];
36614
+ if (_Core.isRuntimeCompatible("backend"))
36615
+ eventTypes.push("database", "storage", "notification", "cache");
36616
+ _Core.log(`Subscribed to domain error events: ${eventTypes.join(", ")}`, verbose);
36543
36617
  }
36544
36618
  /** Handle fetch flags error and return empty flags */
36545
36619
  static handleFetchFlagsError(error, config, verbose) {
@@ -36786,6 +36860,11 @@ var BaseDomainService = class {
36786
36860
  /**
36787
36861
  * Initialize API client asynchronously
36788
36862
  * Called from constructor if apiClientConfig is provided
36863
+ *
36864
+ * Uses ApiClientService.createStandaloneClient() which includes:
36865
+ * - Automatic error handling (single errors and arrays)
36866
+ * - Event emission to CORE_EVENTS.SYSTEM.ERROR and CORE_EVENTS.API.REQUEST_ERROR
36867
+ * - Serialization to unified SerializedError format
36789
36868
  */
36790
36869
  initializeApiClient() {
36791
36870
  if (this._clientInitPromise || !this._apiClientConfig) {
@@ -36793,7 +36872,7 @@ var BaseDomainService = class {
36793
36872
  }
36794
36873
  this._clientInitPromise = (async () => {
36795
36874
  try {
36796
- this._apiClient = await frontend.createApiClient(this._apiClientConfig);
36875
+ this._apiClient = await ApiClientService.createStandaloneClient(this._apiClientConfig);
36797
36876
  if (this._setAsDefaultClient) {
36798
36877
  frontend.setDefaultApiClient(this._apiClient);
36799
36878
  }
@@ -45617,6 +45696,22 @@ var CacheService = class _CacheService {
45617
45696
  /** Singleton instance */
45618
45697
  this.instance = null;
45619
45698
  }
45699
+ // ─────────────────────────────────────────────────────────────────
45700
+ // Error Handling
45701
+ // ─────────────────────────────────────────────────────────────────
45702
+ /**
45703
+ * Emits a cache error event via CoreEventManager.
45704
+ * Called when cache operations fail to integrate with global error handling.
45705
+ */
45706
+ emitCacheError(error, operation, options) {
45707
+ const payload = {
45708
+ error,
45709
+ operation,
45710
+ key: options?.key,
45711
+ recoverable: options?.recoverable ?? true
45712
+ };
45713
+ CoreEventManager.emit(core.CORE_EVENTS.CACHE.ERROR, payload);
45714
+ }
45620
45715
  /**
45621
45716
  * Initialize the cache service with configuration
45622
45717
  *
@@ -45661,6 +45756,7 @@ var CacheService = class _CacheService {
45661
45756
  });
45662
45757
  } catch (error) {
45663
45758
  service.logger.error("[CacheService] Failed to initialize cache", { error });
45759
+ service.emitCacheError(error, "initialize", { recoverable: false });
45664
45760
  throw new errors.CorePackageError(
45665
45761
  `Failed to initialize cache: ${error instanceof Error ? error.message : String(error)}`,
45666
45762
  errors$1.ERROR_CODES.VALIDATION_ERROR,
@@ -46218,10 +46314,10 @@ __export(backend_exports, {
46218
46314
  });
46219
46315
 
46220
46316
  // src/backend/example/example.module.ts
46221
- var import_common10 = __toESM(require_common(), 1);
46317
+ var import_common11 = __toESM(require_common(), 1);
46222
46318
 
46223
46319
  // src/backend/example/example.controller.ts
46224
- var import_common9 = __toESM(require_common(), 1);
46320
+ var import_common10 = __toESM(require_common(), 1);
46225
46321
  var BACKEND_EXAMPLE_DOMAIN_SERVICE = "BACKEND_EXAMPLE_DOMAIN_SERVICE";
46226
46322
  var ExampleController = class {
46227
46323
  constructor(exampleService) {
@@ -46262,41 +46358,41 @@ var ExampleController = class {
46262
46358
  };
46263
46359
  __name(ExampleController, "ExampleController");
46264
46360
  __decorateClass([
46265
- (0, import_common9.Get)("health")
46361
+ (0, import_common10.Get)("health")
46266
46362
  ], ExampleController.prototype, "health", 1);
46267
46363
  __decorateClass([
46268
- (0, import_common9.Get)("entities/:id"),
46269
- __decorateParam(0, (0, import_common9.Param)("id"))
46364
+ (0, import_common10.Get)("entities/:id"),
46365
+ __decorateParam(0, (0, import_common10.Param)("id"))
46270
46366
  ], ExampleController.prototype, "getEntity", 1);
46271
46367
  __decorateClass([
46272
- (0, import_common9.Post)("entities"),
46273
- (0, import_common9.HttpCode)(import_common9.HttpStatus.CREATED),
46274
- __decorateParam(0, (0, import_common9.Body)())
46368
+ (0, import_common10.Post)("entities"),
46369
+ (0, import_common10.HttpCode)(import_common10.HttpStatus.CREATED),
46370
+ __decorateParam(0, (0, import_common10.Body)())
46275
46371
  ], ExampleController.prototype, "createEntity", 1);
46276
46372
  __decorateClass([
46277
- (0, import_common9.Patch)("entities/:id"),
46278
- __decorateParam(0, (0, import_common9.Param)("id")),
46279
- __decorateParam(1, (0, import_common9.Body)())
46373
+ (0, import_common10.Patch)("entities/:id"),
46374
+ __decorateParam(0, (0, import_common10.Param)("id")),
46375
+ __decorateParam(1, (0, import_common10.Body)())
46280
46376
  ], ExampleController.prototype, "updateEntity", 1);
46281
46377
  __decorateClass([
46282
- (0, import_common9.Delete)("entities/:id"),
46283
- (0, import_common9.HttpCode)(import_common9.HttpStatus.OK),
46284
- __decorateParam(0, (0, import_common9.Param)("id"))
46378
+ (0, import_common10.Delete)("entities/:id"),
46379
+ (0, import_common10.HttpCode)(import_common10.HttpStatus.OK),
46380
+ __decorateParam(0, (0, import_common10.Param)("id"))
46285
46381
  ], ExampleController.prototype, "deleteEntity", 1);
46286
46382
  __decorateClass([
46287
- (0, import_common9.Post)("entities/validated"),
46288
- (0, import_common9.HttpCode)(import_common9.HttpStatus.CREATED),
46289
- __decorateParam(0, (0, import_common9.Body)())
46383
+ (0, import_common10.Post)("entities/validated"),
46384
+ (0, import_common10.HttpCode)(import_common10.HttpStatus.CREATED),
46385
+ __decorateParam(0, (0, import_common10.Body)())
46290
46386
  ], ExampleController.prototype, "createEntityWithValidation", 1);
46291
46387
  __decorateClass([
46292
- (0, import_common9.Get)("errors/single")
46388
+ (0, import_common10.Get)("errors/single")
46293
46389
  ], ExampleController.prototype, "demoSingleError", 1);
46294
46390
  __decorateClass([
46295
- (0, import_common9.Get)("errors/array")
46391
+ (0, import_common10.Get)("errors/array")
46296
46392
  ], ExampleController.prototype, "demoArrayErrors", 1);
46297
46393
  ExampleController = __decorateClass([
46298
- (0, import_common9.Controller)("example"),
46299
- __decorateParam(0, (0, import_common9.Inject)(BACKEND_EXAMPLE_DOMAIN_SERVICE))
46394
+ (0, import_common10.Controller)("example"),
46395
+ __decorateParam(0, (0, import_common10.Inject)(BACKEND_EXAMPLE_DOMAIN_SERVICE))
46300
46396
  ], ExampleController);
46301
46397
 
46302
46398
  // src/backend/example/example.module.ts
@@ -46304,7 +46400,7 @@ var ExampleModule = class {
46304
46400
  };
46305
46401
  __name(ExampleModule, "ExampleModule");
46306
46402
  ExampleModule = __decorateClass([
46307
- (0, import_common10.Module)({
46403
+ (0, import_common11.Module)({
46308
46404
  controllers: [ExampleController],
46309
46405
  providers: [
46310
46406
  // Provide BackendExampleDomainService via factory using the singleton instance
@@ -46596,10 +46692,10 @@ var FeatureFlagDomainService = class extends BaseDomainService {
46596
46692
  };
46597
46693
 
46598
46694
  // src/backend/featureFlags/feature-flag.module.ts
46599
- var import_common12 = __toESM(require_common(), 1);
46695
+ var import_common13 = __toESM(require_common(), 1);
46600
46696
 
46601
46697
  // src/backend/featureFlags/feature-flag.controller.ts
46602
- var import_common11 = __toESM(require_common(), 1);
46698
+ var import_common12 = __toESM(require_common(), 1);
46603
46699
  var FeatureFlagController = class {
46604
46700
  constructor(featureFlagService) {
46605
46701
  this.featureFlagService = featureFlagService;
@@ -46728,54 +46824,54 @@ var FeatureFlagController = class {
46728
46824
  };
46729
46825
  __name(FeatureFlagController, "FeatureFlagController");
46730
46826
  __decorateClass([
46731
- (0, import_common11.Post)(":key/evaluate"),
46732
- __decorateParam(0, (0, import_common11.Param)("key")),
46733
- __decorateParam(1, (0, import_common11.Body)())
46827
+ (0, import_common12.Post)(":key/evaluate"),
46828
+ __decorateParam(0, (0, import_common12.Param)("key")),
46829
+ __decorateParam(1, (0, import_common12.Body)())
46734
46830
  ], FeatureFlagController.prototype, "evaluateFlag", 1);
46735
46831
  __decorateClass([
46736
- (0, import_common11.Post)(":key/enabled"),
46737
- __decorateParam(0, (0, import_common11.Param)("key")),
46738
- __decorateParam(1, (0, import_common11.Body)())
46832
+ (0, import_common12.Post)(":key/enabled"),
46833
+ __decorateParam(0, (0, import_common12.Param)("key")),
46834
+ __decorateParam(1, (0, import_common12.Body)())
46739
46835
  ], FeatureFlagController.prototype, "isEnabled", 1);
46740
46836
  __decorateClass([
46741
- (0, import_common11.Post)("evaluate-all"),
46742
- __decorateParam(0, (0, import_common11.Body)())
46837
+ (0, import_common12.Post)("evaluate-all"),
46838
+ __decorateParam(0, (0, import_common12.Body)())
46743
46839
  ], FeatureFlagController.prototype, "evaluateAllFlags", 1);
46744
46840
  __decorateClass([
46745
- (0, import_common11.Post)(),
46746
- __decorateParam(0, (0, import_common11.Body)())
46841
+ (0, import_common12.Post)(),
46842
+ __decorateParam(0, (0, import_common12.Body)())
46747
46843
  ], FeatureFlagController.prototype, "createFlag", 1);
46748
46844
  __decorateClass([
46749
- (0, import_common11.Put)(":key"),
46750
- __decorateParam(0, (0, import_common11.Param)("key")),
46751
- __decorateParam(1, (0, import_common11.Body)())
46845
+ (0, import_common12.Put)(":key"),
46846
+ __decorateParam(0, (0, import_common12.Param)("key")),
46847
+ __decorateParam(1, (0, import_common12.Body)())
46752
46848
  ], FeatureFlagController.prototype, "updateFlag", 1);
46753
46849
  __decorateClass([
46754
- (0, import_common11.Delete)(":key"),
46755
- __decorateParam(0, (0, import_common11.Param)("key"))
46850
+ (0, import_common12.Delete)(":key"),
46851
+ __decorateParam(0, (0, import_common12.Param)("key"))
46756
46852
  ], FeatureFlagController.prototype, "deleteFlag", 1);
46757
46853
  __decorateClass([
46758
- (0, import_common11.Post)(":key/override"),
46759
- __decorateParam(0, (0, import_common11.Param)("key")),
46760
- __decorateParam(1, (0, import_common11.Body)("value"))
46854
+ (0, import_common12.Post)(":key/override"),
46855
+ __decorateParam(0, (0, import_common12.Param)("key")),
46856
+ __decorateParam(1, (0, import_common12.Body)("value"))
46761
46857
  ], FeatureFlagController.prototype, "setOverride", 1);
46762
46858
  __decorateClass([
46763
- (0, import_common11.Delete)(":key/override"),
46764
- __decorateParam(0, (0, import_common11.Param)("key"))
46859
+ (0, import_common12.Delete)(":key/override"),
46860
+ __decorateParam(0, (0, import_common12.Param)("key"))
46765
46861
  ], FeatureFlagController.prototype, "removeOverride", 1);
46766
46862
  __decorateClass([
46767
- (0, import_common11.Get)(":key/rules"),
46768
- __decorateParam(0, (0, import_common11.Param)("key"))
46863
+ (0, import_common12.Get)(":key/rules"),
46864
+ __decorateParam(0, (0, import_common12.Param)("key"))
46769
46865
  ], FeatureFlagController.prototype, "getFlagRules", 1);
46770
46866
  __decorateClass([
46771
- (0, import_common11.Post)("refresh")
46867
+ (0, import_common12.Post)("refresh")
46772
46868
  ], FeatureFlagController.prototype, "refreshCache", 1);
46773
46869
  __decorateClass([
46774
- (0, import_common11.Get)("health")
46870
+ (0, import_common12.Get)("health")
46775
46871
  ], FeatureFlagController.prototype, "getHealth", 1);
46776
46872
  FeatureFlagController = __decorateClass([
46777
- (0, import_common11.Controller)("feature-flags"),
46778
- __decorateParam(0, (0, import_common11.Inject)(FEATURE_FLAG_SERVICE))
46873
+ (0, import_common12.Controller)("feature-flags"),
46874
+ __decorateParam(0, (0, import_common12.Inject)(FEATURE_FLAG_SERVICE))
46779
46875
  ], FeatureFlagController);
46780
46876
 
46781
46877
  // src/backend/featureFlags/feature-flag.module.ts
@@ -46867,16 +46963,16 @@ var FeatureFlagModule = class {
46867
46963
  __name(FeatureFlagModule, "FeatureFlagModule");
46868
46964
  FeatureFlagModule.serviceInstance = null;
46869
46965
  FeatureFlagModule = __decorateClass([
46870
- (0, import_common12.Global)(),
46871
- (0, import_common12.Module)({
46966
+ (0, import_common13.Global)(),
46967
+ (0, import_common13.Module)({
46872
46968
  controllers: [FeatureFlagController]
46873
46969
  })
46874
46970
  ], FeatureFlagModule);
46875
46971
 
46876
46972
  // src/backend/featureFlags/decorators/feature-flag.decorator.ts
46877
- var import_common13 = __toESM(require_common(), 1);
46973
+ var import_common14 = __toESM(require_common(), 1);
46878
46974
  function FeatureFlag(key, expected = true) {
46879
- return (0, import_common13.SetMetadata)(types.FEATURE_FLAG_METADATA.FLAG_CHECK, { key, expected });
46975
+ return (0, import_common14.SetMetadata)(types.FEATURE_FLAG_METADATA.FLAG_CHECK, { key, expected });
46880
46976
  }
46881
46977
  __name(FeatureFlag, "FeatureFlag");
46882
46978
 
@@ -46893,7 +46989,7 @@ function FeatureEnabled(key) {
46893
46989
  __name(FeatureEnabled, "FeatureEnabled");
46894
46990
 
46895
46991
  // src/backend/featureFlags/guards/feature-flag.guard.ts
46896
- var import_common14 = __toESM(require_common(), 1);
46992
+ var import_common15 = __toESM(require_common(), 1);
46897
46993
  var FeatureFlagGuard = class {
46898
46994
  constructor(reflector, featureFlagService) {
46899
46995
  this.reflector = reflector;
@@ -46937,12 +47033,12 @@ var FeatureFlagGuard = class {
46937
47033
  };
46938
47034
  __name(FeatureFlagGuard, "FeatureFlagGuard");
46939
47035
  FeatureFlagGuard = __decorateClass([
46940
- (0, import_common14.Injectable)(),
46941
- __decorateParam(1, (0, import_common14.Inject)(FEATURE_FLAG_SERVICE))
47036
+ (0, import_common15.Injectable)(),
47037
+ __decorateParam(1, (0, import_common15.Inject)(FEATURE_FLAG_SERVICE))
46942
47038
  ], FeatureFlagGuard);
46943
47039
 
46944
47040
  // src/backend/featureFlags/middleware/feature-flag-middleware.ts
46945
- var import_common15 = __toESM(require_common(), 1);
47041
+ var import_common16 = __toESM(require_common(), 1);
46946
47042
  function isFeatureFlagKey(value) {
46947
47043
  return Object.keys(config.FEATURES).includes(value);
46948
47044
  }
@@ -47020,12 +47116,12 @@ var FeatureFlagMiddleware = class {
47020
47116
  };
47021
47117
  __name(FeatureFlagMiddleware, "FeatureFlagMiddleware");
47022
47118
  FeatureFlagMiddleware = __decorateClass([
47023
- (0, import_common15.Injectable)(),
47024
- __decorateParam(0, (0, import_common15.Inject)(FEATURE_FLAG_SERVICE))
47119
+ (0, import_common16.Injectable)(),
47120
+ __decorateParam(0, (0, import_common16.Inject)(FEATURE_FLAG_SERVICE))
47025
47121
  ], FeatureFlagMiddleware);
47026
47122
 
47027
47123
  // src/backend/featureFlags/interceptors/feature-flag-logging-interceptor.ts
47028
- var import_common16 = __toESM(require_common(), 1);
47124
+ var import_common17 = __toESM(require_common(), 1);
47029
47125
  var import_rxjs = __toESM(require_cjs(), 1);
47030
47126
  var FeatureFlagLoggingInterceptor = class {
47031
47127
  constructor() {
@@ -47058,11 +47154,11 @@ var FeatureFlagLoggingInterceptor = class {
47058
47154
  };
47059
47155
  __name(FeatureFlagLoggingInterceptor, "FeatureFlagLoggingInterceptor");
47060
47156
  FeatureFlagLoggingInterceptor = __decorateClass([
47061
- (0, import_common16.Injectable)()
47157
+ (0, import_common17.Injectable)()
47062
47158
  ], FeatureFlagLoggingInterceptor);
47063
47159
 
47064
47160
  // src/backend/featureFlags/interceptors/error-handling-interceptor.ts
47065
- var import_common17 = __toESM(require_common(), 1);
47161
+ var import_common18 = __toESM(require_common(), 1);
47066
47162
  var import_operators = __toESM(require_operators(), 1);
47067
47163
  var ErrorHandlingInterceptor = class {
47068
47164
  constructor() {
@@ -47091,7 +47187,7 @@ var ErrorHandlingInterceptor = class {
47091
47187
  };
47092
47188
  __name(ErrorHandlingInterceptor, "ErrorHandlingInterceptor");
47093
47189
  ErrorHandlingInterceptor = __decorateClass([
47094
- (0, import_common17.Injectable)()
47190
+ (0, import_common18.Injectable)()
47095
47191
  ], ErrorHandlingInterceptor);
47096
47192
  var logger2 = new logger$1.PackageLogger({
47097
47193
  packageName: "core",
@@ -47438,7 +47534,7 @@ var FeatureFlagConfigFactory = class {
47438
47534
  };
47439
47535
 
47440
47536
  // src/base/cache/feature/caching.ts
47441
- var import_common18 = __toESM(require_common(), 1);
47537
+ var import_common19 = __toESM(require_common(), 1);
47442
47538
  var import_rxjs2 = __toESM(require_cjs(), 1);
47443
47539
  var Caching = class {
47444
47540
  constructor() {
@@ -47461,7 +47557,7 @@ var Caching = class {
47461
47557
  };
47462
47558
  __name(Caching, "Caching");
47463
47559
  Caching = __decorateClass([
47464
- (0, import_common18.Injectable)()
47560
+ (0, import_common19.Injectable)()
47465
47561
  ], Caching);
47466
47562
 
47467
47563
  // src/frontend/index.ts
@@ -47660,7 +47756,11 @@ async function initializeCore(config) {
47660
47756
  apiKey: config.api.apiKey,
47661
47757
  setAsDefault: true,
47662
47758
  ...apiConfig
47663
- }
47759
+ },
47760
+ // Feature flags config (passed to Core for memory provider setup)
47761
+ featureFlags: config.featureFlags
47762
+ // Error handler is auto-initialized by Core.initialize()
47763
+ // Store (Zustand) is auto-connected via useRootStore in Core.initializeRootStore()
47664
47764
  });
47665
47765
  }
47666
47766
  __name(initializeCore, "initializeCore");
@@ -48023,6 +48123,7 @@ exports.createBackendContext = createBackendContext;
48023
48123
  exports.createFeatureFlagService = createFeatureFlagService;
48024
48124
  exports.createFrontendContext = createFrontendContext;
48025
48125
  exports.createRolloutIdentifier = createRolloutIdentifier;
48126
+ exports.createStandaloneApiClient = createStandaloneApiClient;
48026
48127
  exports.detectRuntime = detectRuntime;
48027
48128
  exports.evaluateArrayOperator = evaluateArrayOperator;
48028
48129
  exports.evaluateConditionOperator = evaluateConditionOperator;