@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.
package/dist/index.js CHANGED
@@ -36555,6 +36555,13 @@ var Core = class _Core {
36555
36555
  /** Create fetch flags function */
36556
36556
  static createFetchFlagsFn(config, verbose) {
36557
36557
  return async () => {
36558
+ if (config?.provider !== "api") {
36559
+ _Core.log(
36560
+ `Feature flags using ${config?.provider ?? "default"} provider (no API fetch)`,
36561
+ verbose
36562
+ );
36563
+ return config?.defaults ?? {};
36564
+ }
36558
36565
  try {
36559
36566
  const client = ApiClientService.getClient();
36560
36567
  const endpoint = config?.apiEndpoint ?? "/feature-flags";
@@ -36574,6 +36581,7 @@ var Core = class _Core {
36574
36581
  /**
36575
36582
  * Initialize feature flags slice within root store
36576
36583
  */
36584
+ // eslint-disable-next-line complexity
36577
36585
  static async initializeFeatureFlags(config, verbose) {
36578
36586
  if (config?.enabled === false) {
36579
36587
  _Core.log("Feature flags disabled by configuration", verbose);
@@ -36586,11 +36594,16 @@ var Core = class _Core {
36586
36594
  );
36587
36595
  }
36588
36596
  _Core._flagConfig = config ?? {};
36589
- _Core.log("Initializing feature flags from root store...", verbose);
36597
+ const isApiProvider = config?.provider === "api";
36598
+ _Core.log(
36599
+ `Initializing feature flags from root store (provider: ${config?.provider ?? "default"})...`,
36600
+ verbose
36601
+ );
36590
36602
  const state = _Core._rootStore.getState();
36591
36603
  await state.featureFlags.initialize({
36592
36604
  defaults: _Core._flagConfig.defaults,
36593
- polling: _Core._flagConfig.polling,
36605
+ // Only enable polling for API provider
36606
+ polling: isApiProvider ? _Core._flagConfig.polling : void 0,
36594
36607
  fetchFn: _Core.createFetchFlagsFn(_Core._flagConfig, verbose),
36595
36608
  onFlagChange: _Core._flagConfig.onFlagChange,
36596
36609
  onError: _Core._flagConfig.onError
@@ -37053,9 +37066,12 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
37053
37066
  this._primaryStore = primaryStore;
37054
37067
  this.logDebug(`Connected primary store: '${this.primaryStoreKey}'`);
37055
37068
  } else {
37056
- this.logWarn(
37057
- `Primary store '${this.primaryStoreKey}' not found. Store mutations (setData/updateData/setLoading) will be disabled. Configure stores in PlyazProvider to enable store integration.`
37058
- );
37069
+ const isServer = typeof globalThis.window === "undefined";
37070
+ if (!isServer) {
37071
+ this.logWarn(
37072
+ `Primary store '${this.primaryStoreKey}' not found. Store mutations (setData/updateData/setLoading) will be disabled. Configure stores in PlyazProvider to enable store integration.`
37073
+ );
37074
+ }
37059
37075
  }
37060
37076
  }
37061
37077
  for (const key of this.readStoreKeys) {
@@ -37110,6 +37126,36 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
37110
37126
  }
37111
37127
  return config;
37112
37128
  }
37129
+ /**
37130
+ * Initialize service and wait for API client to be ready.
37131
+ * Call this in child service's static create() method after constructing the instance.
37132
+ *
37133
+ * @param service - The service instance to initialize
37134
+ * @returns The initialized service (same instance, for chaining)
37135
+ *
37136
+ * @example
37137
+ * ```typescript
37138
+ * static async create(config, options): Promise<MyService> {
37139
+ * const service = new MyService(config, options);
37140
+ * return this.initializeService(service);
37141
+ * }
37142
+ * ```
37143
+ */
37144
+ static async initializeService(service) {
37145
+ await service.ensureApiClientInitialized();
37146
+ return service;
37147
+ }
37148
+ /**
37149
+ * Ensure service is ready for operations.
37150
+ * Checks enabled/available status AND waits for API client initialization.
37151
+ * Call this at the start of all CRUD methods.
37152
+ *
37153
+ * @throws CorePackageError if service is not enabled or available
37154
+ */
37155
+ async ensureReady() {
37156
+ this.assertReady();
37157
+ await this.ensureApiClientInitialized();
37158
+ }
37113
37159
  // ─────────────────────────────────────────────────────────────────────────
37114
37160
  // Store Management (Public API)
37115
37161
  // ─────────────────────────────────────────────────────────────────────────
@@ -37582,7 +37628,7 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
37582
37628
  */
37583
37629
  // eslint-disable-next-line complexity
37584
37630
  async fetchAll(query, options) {
37585
- this.assertReady();
37631
+ await this.ensureReady();
37586
37632
  const startTime = Date.now();
37587
37633
  if (!this.config.fetchers?.fetchAll) {
37588
37634
  throw new errors.CorePackageError(
@@ -37667,7 +37713,7 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
37667
37713
  */
37668
37714
  // eslint-disable-next-line complexity
37669
37715
  async fetchById(id, options) {
37670
- this.assertReady();
37716
+ await this.ensureReady();
37671
37717
  const startTime = Date.now();
37672
37718
  if (!this.config.fetchers?.fetchById) {
37673
37719
  throw new errors.CorePackageError(
@@ -37728,7 +37774,7 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
37728
37774
  */
37729
37775
  // eslint-disable-next-line complexity, max-lines-per-function
37730
37776
  async create(data, options) {
37731
- this.assertReady();
37777
+ await this.ensureReady();
37732
37778
  const startTime = Date.now();
37733
37779
  if (!this.config.fetchers?.create) {
37734
37780
  throw new errors.CorePackageError(
@@ -37821,7 +37867,7 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
37821
37867
  */
37822
37868
  // eslint-disable-next-line complexity, max-lines-per-function
37823
37869
  async update(id, data, options) {
37824
- this.assertReady();
37870
+ await this.ensureReady();
37825
37871
  const startTime = Date.now();
37826
37872
  if (!this.config.fetchers?.update) {
37827
37873
  throw new errors.CorePackageError(
@@ -37910,7 +37956,7 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
37910
37956
  */
37911
37957
  // eslint-disable-next-line complexity
37912
37958
  async delete(id, options) {
37913
- this.assertReady();
37959
+ await this.ensureReady();
37914
37960
  const startTime = Date.now();
37915
37961
  if (!this.config.fetchers?.delete) {
37916
37962
  throw new errors.CorePackageError(
@@ -45280,7 +45326,6 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
45280
45326
  // ─────────────────────────────────────────────────────────────────────────
45281
45327
  // Constructor
45282
45328
  // ─────────────────────────────────────────────────────────────────────────
45283
- // eslint-disable-next-line complexity
45284
45329
  constructor(config = {}, options) {
45285
45330
  const apiBasePath = config.apiBasePath ?? "/api/examples";
45286
45331
  super({