@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.
@@ -1,10 +1,10 @@
1
1
  import { HTTP_STATUS as HTTP_STATUS$1, CACHE_MAX_SIZE_DEFAULT, CACHE_CLEANUP_INTERVAL_DEFAULT, TIME_CONSTANTS, DEVELOPMENT_CONFIG, STAGING_CONFIG, PRODUCTION_CONFIG, MATH_CONSTANTS, ISO_STANDARDS, FNV_CONSTANTS } from '@plyaz/config';
2
2
  import { HTTP_STATUS, ERROR_CATEGORY, ERROR_CODES, CORE_EVENTS, PACKAGE_STATUS_CODES, API_ERROR_CODES, OPERATIONS, BACKEND_RUNTIMES, FRONTEND_RUNTIMES } from '@plyaz/types';
3
- import { generateRequestId, CorePackageError, initializeErrorSystem, BaseError, ValidateAndFormatErrors, ValidationError } from '@plyaz/errors';
3
+ import { generateRequestId, CorePackageError, BaseError, initializeErrorSystem, ValidateAndFormatErrors, ValidationError } from '@plyaz/errors';
4
4
  import { PackageLogger } from '@plyaz/logger';
5
5
  import { mergeConfigs, createApiClient, ApiPackageError, setDefaultApiClient, evaluateAllFeatureFlags, createFeatureFlag, updateFeatureFlag, deleteFeatureFlag, fetchFeatureFlagRules, ApiProvider as ApiProvider$1 } from '@plyaz/api/frontend';
6
6
  import { EventEmitter } from 'events';
7
- import { ERROR_CODES as ERROR_CODES$1, API_ERROR_CODES as API_ERROR_CODES$1 } from '@plyaz/types/errors';
7
+ import { ERROR_CODES as ERROR_CODES$1, ERROR_CATEGORY as ERROR_CATEGORY$1, API_ERROR_CODES as API_ERROR_CODES$1 } from '@plyaz/types/errors';
8
8
  import { OBSERVABILITY_METRICS } from '@plyaz/types/observability';
9
9
  import { clearEventEmitter, setEventEmitter, initializeGlobalErrorHandler } from '@plyaz/errors/middleware';
10
10
  import { STORE_KEYS, useRootStore, createStandaloneFeatureFlagStore } from '@plyaz/store';
@@ -244,6 +244,14 @@ var HEX_RADIX = 16;
244
244
  var HEX_SLICE_START = 2;
245
245
  var HEX_SLICE_END = 18;
246
246
  var SPAN_ID_LENGTH = 16;
247
+ function generateId() {
248
+ const cryptoApi = globalThis.crypto;
249
+ if (cryptoApi?.randomUUID) {
250
+ return cryptoApi.randomUUID();
251
+ }
252
+ return `${Date.now()}-${Math.random().toString(RANDOM_ID_RADIX).slice(RANDOM_ID_SLICE_START)}`;
253
+ }
254
+ __name(generateId, "generateId");
247
255
  function generateShortId() {
248
256
  const cryptoApi = globalThis.crypto;
249
257
  if (cryptoApi?.randomUUID) {
@@ -556,6 +564,80 @@ var ApiClientService = class _ApiClientService {
556
564
  static {
557
565
  this.initPromise = null;
558
566
  }
567
+ /**
568
+ * Build the core error handler for API clients.
569
+ * This handler emits errors to CoreEventManager for global error handling.
570
+ *
571
+ * Handles:
572
+ * - Single errors (network, timeout)
573
+ * - Array of errors from API responses (validation, business logic)
574
+ * - Serialization to unified SerializedError format
575
+ * - Event emission to CORE_EVENTS.SYSTEM.ERROR and CORE_EVENTS.API.REQUEST_ERROR
576
+ *
577
+ * @returns Error handler function compatible with ApiClientOptions.onError
578
+ */
579
+ static buildCoreErrorHandler() {
580
+ return async (error) => {
581
+ const requestId = generateRequestId();
582
+ const method = error.config?.method ?? "UNKNOWN";
583
+ const url = error.config?.url ?? "unknown";
584
+ try {
585
+ const errorDetails = Array.isArray(error.response?.data) ? error.response.data : [];
586
+ if (errorDetails.length === 0) {
587
+ const serializedError = {
588
+ id: requestId,
589
+ code: ERROR_CODES.CORE_API_CLIENT_REQUEST_FAILED,
590
+ message: error.message ?? "API request failed",
591
+ status: error.status,
592
+ category: ERROR_CATEGORY.Network,
593
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
594
+ isRetryable: error.status ? error.status >= HTTP_STATUS.INTERNAL_SERVER_ERROR : false,
595
+ source: "api-client",
596
+ dismissed: false,
597
+ context: {
598
+ method,
599
+ url,
600
+ requestId
601
+ }
602
+ };
603
+ CoreEventManager.emit(CORE_EVENTS.SYSTEM.ERROR, { errors: [serializedError] });
604
+ } else {
605
+ const serializedErrors = errorDetails.map(
606
+ (detail, index) => ({
607
+ id: `${requestId}-${index}`,
608
+ code: detail.errorCode ?? ERROR_CODES.CORE_API_CLIENT_REQUEST_FAILED,
609
+ message: detail.message ?? error.message ?? "API request failed",
610
+ status: error.status,
611
+ category: ERROR_CATEGORY.Network,
612
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
613
+ isRetryable: error.status ? error.status >= HTTP_STATUS.INTERNAL_SERVER_ERROR : false,
614
+ source: "api-client",
615
+ dismissed: false,
616
+ context: {
617
+ method,
618
+ url,
619
+ requestId,
620
+ field: detail.field,
621
+ valueGiven: detail.valueGiven,
622
+ allowedValues: detail.allowedValues,
623
+ constraints: detail.constraints
624
+ }
625
+ })
626
+ );
627
+ CoreEventManager.emit(CORE_EVENTS.SYSTEM.ERROR, { errors: serializedErrors });
628
+ }
629
+ } catch (e) {
630
+ console.error("[ApiClientService] Failed to emit error event:", e);
631
+ }
632
+ _ApiClientService.emitApiError(error, {
633
+ method,
634
+ url,
635
+ requestId,
636
+ status: error.status,
637
+ duration: 0
638
+ });
639
+ };
640
+ }
559
641
  /**
560
642
  * Initialize the API client with environment config and API options
561
643
  *
@@ -593,71 +675,12 @@ var ApiClientService = class _ApiClientService {
593
675
  * 2. Environment metadata (envConfig - apiKey)
594
676
  * 3. API configuration (apiConfig - baseURL, encryption, timeout, etc.)
595
677
  */
596
- // eslint-disable-next-line max-lines-per-function, complexity
678
+ // eslint-disable-next-line complexity
597
679
  static async createClient(envConfig, apiConfig) {
598
680
  try {
599
681
  const envDefaults = getConfigForEnvironment(envConfig.env);
600
682
  const envMetadataMapped = mapEnvironmentMetadata(envConfig, envDefaults);
601
- const coreErrorHandler = /* @__PURE__ */ __name(async (error) => {
602
- const requestId = generateRequestId();
603
- const method = error.config?.method ?? "UNKNOWN";
604
- const url = error.config?.url ?? "unknown";
605
- try {
606
- const errorDetails = Array.isArray(error.response?.data) ? error.response.data : [];
607
- if (errorDetails.length === 0) {
608
- const serializedError = {
609
- id: requestId,
610
- code: ERROR_CODES.CORE_API_CLIENT_REQUEST_FAILED,
611
- message: error.message ?? "API request failed",
612
- status: error.status,
613
- category: ERROR_CATEGORY.Network,
614
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
615
- isRetryable: error.status ? error.status >= HTTP_STATUS.INTERNAL_SERVER_ERROR : false,
616
- source: "api-client",
617
- dismissed: false,
618
- context: {
619
- method,
620
- url,
621
- requestId
622
- }
623
- };
624
- CoreEventManager.emit(CORE_EVENTS.SYSTEM.ERROR, { errors: [serializedError] });
625
- } else {
626
- const serializedErrors = errorDetails.map(
627
- (detail, index) => ({
628
- id: `${requestId}-${index}`,
629
- code: detail.errorCode ?? ERROR_CODES.CORE_API_CLIENT_REQUEST_FAILED,
630
- message: detail.message ?? error.message ?? "API request failed",
631
- status: error.status,
632
- category: ERROR_CATEGORY.Network,
633
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
634
- isRetryable: error.status ? error.status >= HTTP_STATUS.INTERNAL_SERVER_ERROR : false,
635
- source: "api-client",
636
- dismissed: false,
637
- context: {
638
- method,
639
- url,
640
- requestId,
641
- field: detail.field,
642
- valueGiven: detail.valueGiven,
643
- allowedValues: detail.allowedValues,
644
- constraints: detail.constraints
645
- }
646
- })
647
- );
648
- CoreEventManager.emit(CORE_EVENTS.SYSTEM.ERROR, { errors: serializedErrors });
649
- }
650
- } catch (e) {
651
- console.error("[ApiClientService] Failed to emit error event:", e);
652
- }
653
- _ApiClientService.emitApiError(error, {
654
- method,
655
- url,
656
- requestId,
657
- status: error.status,
658
- duration: 0
659
- });
660
- }, "coreErrorHandler");
683
+ const coreErrorHandler = _ApiClientService.buildCoreErrorHandler();
661
684
  const userOnError = apiConfig?.onError;
662
685
  const combinedOnError = userOnError ? Array.isArray(userOnError) ? [...userOnError, coreErrorHandler] : [userOnError, coreErrorHandler] : coreErrorHandler;
663
686
  const mergedOptions = mergeConfigs(
@@ -832,11 +855,13 @@ var ApiClientService = class _ApiClientService {
832
855
  try {
833
856
  const envDefaults = getConfigForEnvironment(envConfig.env);
834
857
  const envMetadataMapped = mapEnvironmentMetadata(envConfig, envDefaults);
835
- const mergedOptions = mergeConfigs(
836
- envDefaults,
837
- envMetadataMapped,
838
- apiConfig ?? {}
839
- );
858
+ const coreErrorHandler = _ApiClientService.buildCoreErrorHandler();
859
+ const userOnError = apiConfig?.onError;
860
+ const combinedOnError = userOnError ? Array.isArray(userOnError) ? [...userOnError, coreErrorHandler] : [userOnError, coreErrorHandler] : coreErrorHandler;
861
+ const mergedOptions = mergeConfigs(envDefaults, envMetadataMapped, {
862
+ ...apiConfig ?? {},
863
+ onError: combinedOnError
864
+ });
840
865
  validateEnvironmentConfig(envConfig, mergedOptions);
841
866
  const dedicatedClient = await createApiClient(mergedOptions);
842
867
  return dedicatedClient;
@@ -858,6 +883,61 @@ var ApiClientService = class _ApiClientService {
858
883
  );
859
884
  }
860
885
  }
886
+ /**
887
+ * Create a standalone API client with Core error handling.
888
+ *
889
+ * This is a simpler alternative to `createInstance()` that doesn't require
890
+ * environment config. Use this when you just need the error handling without
891
+ * environment-specific defaults (production validation, etc.).
892
+ *
893
+ * **Use cases:**
894
+ * - Domain services that need their own API client
895
+ * - Testing with isolated API clients
896
+ * - Simple client creation without environment setup
897
+ *
898
+ * @param apiConfig - API configuration (baseURL, timeout, etc.)
899
+ * @returns Promise that resolves to a client with Core error handling
900
+ *
901
+ * @example
902
+ * ```typescript
903
+ * // In BaseDomainService or any service
904
+ * const client = await ApiClientService.createStandaloneClient({
905
+ * baseURL: '/api/examples',
906
+ * timeout: 10000,
907
+ * });
908
+ *
909
+ * // Errors are automatically emitted to CoreEventManager
910
+ * const response = await client.get('/items');
911
+ * ```
912
+ */
913
+ static async createStandaloneClient(apiConfig) {
914
+ try {
915
+ const coreErrorHandler = _ApiClientService.buildCoreErrorHandler();
916
+ const userOnError = apiConfig.onError;
917
+ const combinedOnError = userOnError ? Array.isArray(userOnError) ? [...userOnError, coreErrorHandler] : [userOnError, coreErrorHandler] : coreErrorHandler;
918
+ const client = await createApiClient({
919
+ ...apiConfig,
920
+ onError: combinedOnError
921
+ });
922
+ return client;
923
+ } catch (error) {
924
+ throw new ApiPackageError(
925
+ "service.standalone_client_creation.failed",
926
+ PACKAGE_STATUS_CODES.INITIALIZATION_FAILED,
927
+ API_ERROR_CODES.CLIENT_INITIALIZATION_FAILED,
928
+ {
929
+ cause: error instanceof Error ? error : void 0,
930
+ context: {
931
+ operation: OPERATIONS.INITIALIZATION,
932
+ originalError: error instanceof Error ? error.message : String(error),
933
+ i18n: {
934
+ error: error instanceof Error ? error.message : String(error)
935
+ }
936
+ }
937
+ }
938
+ );
939
+ }
940
+ }
861
941
  };
862
942
  var BaseAdapter = class {
863
943
  constructor() {
@@ -3414,6 +3494,7 @@ var Core = class _Core {
3414
3494
  _Core._errorHandler.destroy();
3415
3495
  _Core._errorHandler = null;
3416
3496
  clearEventEmitter();
3497
+ BaseError.clearEventEmitter();
3417
3498
  }
3418
3499
  _Core._errorConfig = {};
3419
3500
  _Core._httpErrorHandler = null;
@@ -3602,6 +3683,28 @@ var Core = class _Core {
3602
3683
  };
3603
3684
  }
3604
3685
  }
3686
+ /**
3687
+ * Serialize a PackageErrorLike to SerializedError format.
3688
+ * Used by BaseError.setEventEmitter() to convert errors for the store.
3689
+ */
3690
+ static serializePackageError(error) {
3691
+ const serviceName = typeof error.context?.service === "string" ? error.context.service : "core";
3692
+ return {
3693
+ id: generateId(),
3694
+ code: error.errorCode ?? ERROR_CODES.UNKNOWN_ERROR,
3695
+ message: error.message,
3696
+ status: error.statusCode,
3697
+ category: error.category ?? ERROR_CATEGORY$1.Server,
3698
+ timestamp: error.timestamp ?? (/* @__PURE__ */ new Date()).toISOString(),
3699
+ isRetryable: error.retryable ?? false,
3700
+ source: serviceName,
3701
+ dismissed: false,
3702
+ context: {
3703
+ correlationId: error.correlationId,
3704
+ ...error.context
3705
+ }
3706
+ };
3707
+ }
3605
3708
  /** Get error store actions from root store */
3606
3709
  static getErrorStoreActions() {
3607
3710
  if (!_Core._rootStore) {
@@ -3613,12 +3716,17 @@ var Core = class _Core {
3613
3716
  return _Core._rootStore.getState().errors;
3614
3717
  }
3615
3718
  /** Build global error handler config */
3616
- // eslint-disable-next-line complexity
3617
3719
  static buildErrorHandlerConfig(config) {
3720
+ const baseErrorFilter = /* @__PURE__ */ __name((error) => {
3721
+ if (error instanceof BaseError) {
3722
+ return false;
3723
+ }
3724
+ return config?.filter ? config.filter(error) : true;
3725
+ }, "baseErrorFilter");
3618
3726
  return {
3619
3727
  source: config?.source ?? "global",
3620
3728
  maxErrors: config?.maxErrors ?? DEFAULT_MAX_ERRORS,
3621
- filter: config?.filter,
3729
+ filter: baseErrorFilter,
3622
3730
  onError: config?.onError,
3623
3731
  logToConsole: config?.logToConsole ?? false
3624
3732
  };
@@ -3639,6 +3747,15 @@ var Core = class _Core {
3639
3747
  });
3640
3748
  await _Core.initializeRootStore(_Core._errorConfig, verbose);
3641
3749
  setEventEmitter(CoreEventManager.emit.bind(CoreEventManager));
3750
+ BaseError.setEventEmitter((error) => {
3751
+ const serializedError = _Core.serializePackageError(error);
3752
+ const serviceName = serializedError.source ?? "core";
3753
+ CoreEventManager.emit(CORE_EVENTS$1.SYSTEM.ERROR, {
3754
+ errors: [serializedError],
3755
+ context: serviceName,
3756
+ recoverable: error.retryable ?? false
3757
+ });
3758
+ });
3642
3759
  const errorStore = _Core.getErrorStoreActions();
3643
3760
  _Core._errorHandler = initializeGlobalErrorHandler(
3644
3761
  errorStore,
@@ -3734,9 +3851,15 @@ var Core = class _Core {
3734
3851
  }
3735
3852
  /**
3736
3853
  * Subscribe to CoreEventManager error events
3737
- * Forwards system, entity, API, validation, database, and auth errors to the global error handler.
3854
+ * Forwards entity, API, validation, database, and auth errors to the global error handler.
3738
3855
  *
3739
- * Note: Database errors (DATABASE.ERROR) are only subscribed on backend runtimes since
3856
+ * NOTE: SYSTEM.ERROR is NOT subscribed here - it's handled in initializeErrorHandler()
3857
+ * via the BaseError.setEventEmitter() + addErrors() pattern to avoid duplicate subscriptions.
3858
+ *
3859
+ * For non-BaseError errors, domain-specific events (ENTITY.ERROR, API.REQUEST_ERROR, etc.)
3860
+ * are captured here. BaseError instances are skipped (they already auto-emit via SYSTEM.ERROR).
3861
+ *
3862
+ * Database errors (DATABASE.ERROR) are only subscribed on backend runtimes since
3740
3863
  * DbService is backend-only (skipDb: true on frontend).
3741
3864
  */
3742
3865
  static subscribeToErrorEvents(verbose) {
@@ -3744,78 +3867,36 @@ var Core = class _Core {
3744
3867
  return;
3745
3868
  }
3746
3869
  _Core.log("Subscribing to error events...", verbose);
3747
- const cleanupSystemError = CoreEventManager.on(CORE_EVENTS$1.SYSTEM.ERROR, (event) => {
3748
- if (_Core._errorHandler && event.data?.errors?.length) {
3749
- for (const err of event.data.errors) {
3750
- _Core._errorHandler.captureError(err, "system");
3870
+ const subscribeError = /* @__PURE__ */ __name((event, source) => {
3871
+ return CoreEventManager.on(event, (e) => {
3872
+ if (_Core._errorHandler && e.data?.error && !(e.data.error instanceof BaseError)) {
3873
+ _Core._errorHandler.captureError(e.data.error, source);
3751
3874
  }
3752
- }
3753
- });
3754
- const cleanupEntityError = CoreEventManager.on(CORE_EVENTS$1.ENTITY.ERROR, (event) => {
3755
- if (_Core._errorHandler && event.data) {
3756
- _Core._errorHandler.captureError(event.data.error, "entity");
3757
- }
3758
- });
3759
- const cleanupApiError = CoreEventManager.on(CORE_EVENTS$1.API.REQUEST_ERROR, (event) => {
3760
- if (_Core._errorHandler && event.data) {
3761
- _Core._errorHandler.captureError(event.data.error, "api");
3762
- }
3763
- });
3764
- const cleanupValidationError = CoreEventManager.on(CORE_EVENTS$1.VALIDATION.FAILED, (event) => {
3765
- if (_Core._errorHandler && event.data) {
3766
- _Core._errorHandler.captureError(event.data.error, "validation");
3767
- }
3768
- });
3769
- const cleanupAuthUnauthorized = CoreEventManager.on(CORE_EVENTS$1.AUTH.UNAUTHORIZED, (event) => {
3770
- if (_Core._errorHandler && event.data?.error) {
3771
- _Core._errorHandler.captureError(event.data.error, "auth");
3772
- }
3773
- });
3774
- const cleanupAuthSessionExpired = CoreEventManager.on(
3775
- CORE_EVENTS$1.AUTH.SESSION_EXPIRED,
3776
- (event) => {
3777
- if (_Core._errorHandler && event.data?.error) {
3778
- _Core._errorHandler.captureError(event.data.error, "auth");
3779
- }
3780
- }
3781
- );
3875
+ });
3876
+ }, "subscribeError");
3782
3877
  _Core._eventCleanupFns.push(
3783
- cleanupSystemError,
3784
- cleanupEntityError,
3785
- cleanupApiError,
3786
- cleanupValidationError,
3787
- cleanupAuthUnauthorized,
3788
- cleanupAuthSessionExpired
3878
+ subscribeError(CORE_EVENTS$1.ENTITY.ERROR, "entity"),
3879
+ subscribeError(CORE_EVENTS$1.API.REQUEST_ERROR, "api"),
3880
+ subscribeError(CORE_EVENTS$1.VALIDATION.FAILED, "validation"),
3881
+ subscribeError(CORE_EVENTS$1.AUTH.UNAUTHORIZED, "auth"),
3882
+ subscribeError(CORE_EVENTS$1.AUTH.SESSION_EXPIRED, "auth")
3789
3883
  );
3790
3884
  if (_Core.isRuntimeCompatible("backend")) {
3791
- const cleanupDatabaseError = CoreEventManager.on(CORE_EVENTS$1.DATABASE.ERROR, (event) => {
3792
- if (_Core._errorHandler && event.data) {
3793
- _Core._errorHandler.captureError(event.data.error, "database");
3794
- }
3795
- });
3796
- _Core._eventCleanupFns.push(cleanupDatabaseError);
3797
- const cleanupStorageError = CoreEventManager.on(CORE_EVENTS$1.STORAGE.ERROR, (event) => {
3798
- if (_Core._errorHandler && event.data) {
3799
- _Core._errorHandler.captureError(event.data.error, "storage");
3800
- }
3801
- });
3802
- _Core._eventCleanupFns.push(cleanupStorageError);
3803
- const cleanupNotificationError = CoreEventManager.on(
3804
- CORE_EVENTS$1.NOTIFICATION.ERROR,
3805
- (event) => {
3806
- if (_Core._errorHandler && event.data) {
3807
- _Core._errorHandler.captureError(event.data.error, "notification");
3808
- }
3809
- }
3885
+ _Core._eventCleanupFns.push(
3886
+ subscribeError(CORE_EVENTS$1.DATABASE.ERROR, "database"),
3887
+ subscribeError(CORE_EVENTS$1.STORAGE.ERROR, "storage"),
3888
+ subscribeError(CORE_EVENTS$1.NOTIFICATION.ERROR, "notification"),
3889
+ subscribeError(CORE_EVENTS$1.CACHE.ERROR, "cache")
3890
+ );
3891
+ _Core.log(
3892
+ "Subscribed to backend error events (database, storage, notification, cache)",
3893
+ verbose
3810
3894
  );
3811
- _Core._eventCleanupFns.push(cleanupNotificationError);
3812
- _Core.log("Subscribed to backend error events (database, storage, notification)", verbose);
3813
- }
3814
- const eventTypes = ["system", "entity", "api", "validation", "auth"];
3815
- if (_Core.isRuntimeCompatible("backend")) {
3816
- eventTypes.push("database", "storage", "notification");
3817
3895
  }
3818
- _Core.log(`Subscribed to error events: ${eventTypes.join(", ")}`, verbose);
3896
+ const eventTypes = ["entity", "api", "validation", "auth"];
3897
+ if (_Core.isRuntimeCompatible("backend"))
3898
+ eventTypes.push("database", "storage", "notification", "cache");
3899
+ _Core.log(`Subscribed to domain error events: ${eventTypes.join(", ")}`, verbose);
3819
3900
  }
3820
3901
  /** Handle fetch flags error and return empty flags */
3821
3902
  static handleFetchFlagsError(error, config, verbose) {
@@ -4062,6 +4143,11 @@ var BaseDomainService = class {
4062
4143
  /**
4063
4144
  * Initialize API client asynchronously
4064
4145
  * Called from constructor if apiClientConfig is provided
4146
+ *
4147
+ * Uses ApiClientService.createStandaloneClient() which includes:
4148
+ * - Automatic error handling (single errors and arrays)
4149
+ * - Event emission to CORE_EVENTS.SYSTEM.ERROR and CORE_EVENTS.API.REQUEST_ERROR
4150
+ * - Serialization to unified SerializedError format
4065
4151
  */
4066
4152
  initializeApiClient() {
4067
4153
  if (this._clientInitPromise || !this._apiClientConfig) {
@@ -4069,7 +4155,7 @@ var BaseDomainService = class {
4069
4155
  }
4070
4156
  this._clientInitPromise = (async () => {
4071
4157
  try {
4072
- this._apiClient = await createApiClient(this._apiClientConfig);
4158
+ this._apiClient = await ApiClientService.createStandaloneClient(this._apiClientConfig);
4073
4159
  if (this._setAsDefaultClient) {
4074
4160
  setDefaultApiClient(this._apiClient);
4075
4161
  }
@@ -7978,7 +8064,11 @@ async function initializeCore(config) {
7978
8064
  apiKey: config.api.apiKey,
7979
8065
  setAsDefault: true,
7980
8066
  ...apiConfig
7981
- }
8067
+ },
8068
+ // Feature flags config (passed to Core for memory provider setup)
8069
+ featureFlags: config.featureFlags
8070
+ // Error handler is auto-initialized by Core.initialize()
8071
+ // Store (Zustand) is auto-connected via useRootStore in Core.initializeRootStore()
7982
8072
  });
7983
8073
  }
7984
8074
  __name(initializeCore, "initializeCore");