@plyaz/core 1.8.2 → 1.8.3

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.
@@ -3833,6 +3833,13 @@ var Core = class _Core {
3833
3833
  /** Create fetch flags function */
3834
3834
  static createFetchFlagsFn(config, verbose) {
3835
3835
  return async () => {
3836
+ if (config?.provider !== "api") {
3837
+ _Core.log(
3838
+ `Feature flags using ${config?.provider ?? "default"} provider (no API fetch)`,
3839
+ verbose
3840
+ );
3841
+ return config?.defaults ?? {};
3842
+ }
3836
3843
  try {
3837
3844
  const client = ApiClientService.getClient();
3838
3845
  const endpoint = config?.apiEndpoint ?? "/feature-flags";
@@ -3852,6 +3859,7 @@ var Core = class _Core {
3852
3859
  /**
3853
3860
  * Initialize feature flags slice within root store
3854
3861
  */
3862
+ // eslint-disable-next-line complexity
3855
3863
  static async initializeFeatureFlags(config, verbose) {
3856
3864
  if (config?.enabled === false) {
3857
3865
  _Core.log("Feature flags disabled by configuration", verbose);
@@ -3864,11 +3872,16 @@ var Core = class _Core {
3864
3872
  );
3865
3873
  }
3866
3874
  _Core._flagConfig = config ?? {};
3867
- _Core.log("Initializing feature flags from root store...", verbose);
3875
+ const isApiProvider = config?.provider === "api";
3876
+ _Core.log(
3877
+ `Initializing feature flags from root store (provider: ${config?.provider ?? "default"})...`,
3878
+ verbose
3879
+ );
3868
3880
  const state = _Core._rootStore.getState();
3869
3881
  await state.featureFlags.initialize({
3870
3882
  defaults: _Core._flagConfig.defaults,
3871
- polling: _Core._flagConfig.polling,
3883
+ // Only enable polling for API provider
3884
+ polling: isApiProvider ? _Core._flagConfig.polling : void 0,
3872
3885
  fetchFn: _Core.createFetchFlagsFn(_Core._flagConfig, verbose),
3873
3886
  onFlagChange: _Core._flagConfig.onFlagChange,
3874
3887
  onError: _Core._flagConfig.onError
@@ -4331,9 +4344,12 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
4331
4344
  this._primaryStore = primaryStore;
4332
4345
  this.logDebug(`Connected primary store: '${this.primaryStoreKey}'`);
4333
4346
  } else {
4334
- this.logWarn(
4335
- `Primary store '${this.primaryStoreKey}' not found. Store mutations (setData/updateData/setLoading) will be disabled. Configure stores in PlyazProvider to enable store integration.`
4336
- );
4347
+ const isServer = typeof globalThis.window === "undefined";
4348
+ if (!isServer) {
4349
+ this.logWarn(
4350
+ `Primary store '${this.primaryStoreKey}' not found. Store mutations (setData/updateData/setLoading) will be disabled. Configure stores in PlyazProvider to enable store integration.`
4351
+ );
4352
+ }
4337
4353
  }
4338
4354
  }
4339
4355
  for (const key of this.readStoreKeys) {
@@ -4388,6 +4404,36 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
4388
4404
  }
4389
4405
  return config;
4390
4406
  }
4407
+ /**
4408
+ * Initialize service and wait for API client to be ready.
4409
+ * Call this in child service's static create() method after constructing the instance.
4410
+ *
4411
+ * @param service - The service instance to initialize
4412
+ * @returns The initialized service (same instance, for chaining)
4413
+ *
4414
+ * @example
4415
+ * ```typescript
4416
+ * static async create(config, options): Promise<MyService> {
4417
+ * const service = new MyService(config, options);
4418
+ * return this.initializeService(service);
4419
+ * }
4420
+ * ```
4421
+ */
4422
+ static async initializeService(service) {
4423
+ await service.ensureApiClientInitialized();
4424
+ return service;
4425
+ }
4426
+ /**
4427
+ * Ensure service is ready for operations.
4428
+ * Checks enabled/available status AND waits for API client initialization.
4429
+ * Call this at the start of all CRUD methods.
4430
+ *
4431
+ * @throws CorePackageError if service is not enabled or available
4432
+ */
4433
+ async ensureReady() {
4434
+ this.assertReady();
4435
+ await this.ensureApiClientInitialized();
4436
+ }
4391
4437
  // ─────────────────────────────────────────────────────────────────────────
4392
4438
  // Store Management (Public API)
4393
4439
  // ─────────────────────────────────────────────────────────────────────────
@@ -4860,7 +4906,7 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
4860
4906
  */
4861
4907
  // eslint-disable-next-line complexity
4862
4908
  async fetchAll(query, options) {
4863
- this.assertReady();
4909
+ await this.ensureReady();
4864
4910
  const startTime = Date.now();
4865
4911
  if (!this.config.fetchers?.fetchAll) {
4866
4912
  throw new errors.CorePackageError(
@@ -4945,7 +4991,7 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
4945
4991
  */
4946
4992
  // eslint-disable-next-line complexity
4947
4993
  async fetchById(id, options) {
4948
- this.assertReady();
4994
+ await this.ensureReady();
4949
4995
  const startTime = Date.now();
4950
4996
  if (!this.config.fetchers?.fetchById) {
4951
4997
  throw new errors.CorePackageError(
@@ -5006,7 +5052,7 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
5006
5052
  */
5007
5053
  // eslint-disable-next-line complexity, max-lines-per-function
5008
5054
  async create(data, options) {
5009
- this.assertReady();
5055
+ await this.ensureReady();
5010
5056
  const startTime = Date.now();
5011
5057
  if (!this.config.fetchers?.create) {
5012
5058
  throw new errors.CorePackageError(
@@ -5099,7 +5145,7 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
5099
5145
  */
5100
5146
  // eslint-disable-next-line complexity, max-lines-per-function
5101
5147
  async update(id, data, options) {
5102
- this.assertReady();
5148
+ await this.ensureReady();
5103
5149
  const startTime = Date.now();
5104
5150
  if (!this.config.fetchers?.update) {
5105
5151
  throw new errors.CorePackageError(
@@ -5188,7 +5234,7 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
5188
5234
  */
5189
5235
  // eslint-disable-next-line complexity
5190
5236
  async delete(id, options) {
5191
- this.assertReady();
5237
+ await this.ensureReady();
5192
5238
  const startTime = Date.now();
5193
5239
  if (!this.config.fetchers?.delete) {
5194
5240
  throw new errors.CorePackageError(
@@ -6159,7 +6205,6 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
6159
6205
  // ─────────────────────────────────────────────────────────────────────────
6160
6206
  // Constructor
6161
6207
  // ─────────────────────────────────────────────────────────────────────────
6162
- // eslint-disable-next-line complexity
6163
6208
  constructor(config = {}, options) {
6164
6209
  const apiBasePath = config.apiBasePath ?? "/api/examples";
6165
6210
  super({