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