@plyaz/core 1.8.2 → 1.8.4
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/domain/base/BaseDomainService.d.ts +1 -1
- package/dist/domain/base/BaseFrontendDomainService.d.ts +26 -0
- package/dist/domain/base/BaseFrontendDomainService.d.ts.map +1 -1
- package/dist/domain/example/FrontendExampleDomainService.d.ts.map +1 -1
- package/dist/domain/featureFlags/FrontendFeatureFlagDomainService.d.ts.map +1 -1
- package/dist/entry-backend.js +66 -14
- package/dist/entry-backend.js.map +1 -1
- package/dist/entry-backend.mjs +66 -14
- package/dist/entry-backend.mjs.map +1 -1
- package/dist/entry-frontend-browser.js +66 -14
- package/dist/entry-frontend-browser.js.map +1 -1
- package/dist/entry-frontend-browser.mjs +66 -14
- package/dist/entry-frontend-browser.mjs.map +1 -1
- package/dist/entry-frontend.js +66 -14
- package/dist/entry-frontend.js.map +1 -1
- package/dist/entry-frontend.mjs +66 -14
- package/dist/entry-frontend.mjs.map +1 -1
- package/dist/index.js +66 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -14
- package/dist/index.mjs.map +1 -1
- package/dist/init/CoreInitializer.d.ts.map +1 -1
- package/dist/init/nestjs/index.js +15 -2
- package/dist/init/nestjs/index.js.map +1 -1
- package/dist/init/nestjs/index.mjs +15 -2
- package/dist/init/nestjs/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -4059,6 +4059,13 @@ var Core = class _Core {
|
|
|
4059
4059
|
/** Create fetch flags function */
|
|
4060
4060
|
static createFetchFlagsFn(config, verbose) {
|
|
4061
4061
|
return async () => {
|
|
4062
|
+
if (config?.provider !== "api") {
|
|
4063
|
+
_Core.log(
|
|
4064
|
+
`Feature flags using ${config?.provider ?? "default"} provider (no API fetch)`,
|
|
4065
|
+
verbose
|
|
4066
|
+
);
|
|
4067
|
+
return config?.defaults ?? {};
|
|
4068
|
+
}
|
|
4062
4069
|
try {
|
|
4063
4070
|
const client = ApiClientService.getClient();
|
|
4064
4071
|
const endpoint = config?.apiEndpoint ?? "/feature-flags";
|
|
@@ -4078,6 +4085,7 @@ var Core = class _Core {
|
|
|
4078
4085
|
/**
|
|
4079
4086
|
* Initialize feature flags slice within root store
|
|
4080
4087
|
*/
|
|
4088
|
+
// eslint-disable-next-line complexity
|
|
4081
4089
|
static async initializeFeatureFlags(config, verbose) {
|
|
4082
4090
|
if (config?.enabled === false) {
|
|
4083
4091
|
_Core.log("Feature flags disabled by configuration", verbose);
|
|
@@ -4090,11 +4098,16 @@ var Core = class _Core {
|
|
|
4090
4098
|
);
|
|
4091
4099
|
}
|
|
4092
4100
|
_Core._flagConfig = config ?? {};
|
|
4093
|
-
|
|
4101
|
+
const isApiProvider = config?.provider === "api";
|
|
4102
|
+
_Core.log(
|
|
4103
|
+
`Initializing feature flags from root store (provider: ${config?.provider ?? "default"})...`,
|
|
4104
|
+
verbose
|
|
4105
|
+
);
|
|
4094
4106
|
const state = _Core._rootStore.getState();
|
|
4095
4107
|
await state.featureFlags.initialize({
|
|
4096
4108
|
defaults: _Core._flagConfig.defaults,
|
|
4097
|
-
polling
|
|
4109
|
+
// Only enable polling for API provider
|
|
4110
|
+
polling: isApiProvider ? _Core._flagConfig.polling : void 0,
|
|
4098
4111
|
fetchFn: _Core.createFetchFlagsFn(_Core._flagConfig, verbose),
|
|
4099
4112
|
onFlagChange: _Core._flagConfig.onFlagChange,
|
|
4100
4113
|
onError: _Core._flagConfig.onError
|
|
@@ -4557,9 +4570,12 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
|
|
|
4557
4570
|
this._primaryStore = primaryStore;
|
|
4558
4571
|
this.logDebug(`Connected primary store: '${this.primaryStoreKey}'`);
|
|
4559
4572
|
} else {
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4573
|
+
const isServer = typeof globalThis.window === "undefined";
|
|
4574
|
+
if (!isServer) {
|
|
4575
|
+
this.logWarn(
|
|
4576
|
+
`Primary store '${this.primaryStoreKey}' not found. Store mutations (setData/updateData/setLoading) will be disabled. Configure stores in PlyazProvider to enable store integration.`
|
|
4577
|
+
);
|
|
4578
|
+
}
|
|
4563
4579
|
}
|
|
4564
4580
|
}
|
|
4565
4581
|
for (const key of this.readStoreKeys) {
|
|
@@ -4614,6 +4630,36 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
|
|
|
4614
4630
|
}
|
|
4615
4631
|
return config;
|
|
4616
4632
|
}
|
|
4633
|
+
/**
|
|
4634
|
+
* Initialize service and wait for API client to be ready.
|
|
4635
|
+
* Call this in child service's static create() method after constructing the instance.
|
|
4636
|
+
*
|
|
4637
|
+
* @param service - The service instance to initialize
|
|
4638
|
+
* @returns The initialized service (same instance, for chaining)
|
|
4639
|
+
*
|
|
4640
|
+
* @example
|
|
4641
|
+
* ```typescript
|
|
4642
|
+
* static async create(config, options): Promise<MyService> {
|
|
4643
|
+
* const service = new MyService(config, options);
|
|
4644
|
+
* return this.initializeService(service);
|
|
4645
|
+
* }
|
|
4646
|
+
* ```
|
|
4647
|
+
*/
|
|
4648
|
+
static async initializeService(service) {
|
|
4649
|
+
await service.ensureApiClientInitialized();
|
|
4650
|
+
return service;
|
|
4651
|
+
}
|
|
4652
|
+
/**
|
|
4653
|
+
* Ensure service is ready for operations.
|
|
4654
|
+
* Checks enabled/available status AND waits for API client initialization.
|
|
4655
|
+
* Call this at the start of all CRUD methods.
|
|
4656
|
+
*
|
|
4657
|
+
* @throws CorePackageError if service is not enabled or available
|
|
4658
|
+
*/
|
|
4659
|
+
async ensureReady() {
|
|
4660
|
+
this.assertReady();
|
|
4661
|
+
await this.ensureApiClientInitialized();
|
|
4662
|
+
}
|
|
4617
4663
|
// ─────────────────────────────────────────────────────────────────────────
|
|
4618
4664
|
// Store Management (Public API)
|
|
4619
4665
|
// ─────────────────────────────────────────────────────────────────────────
|
|
@@ -5086,7 +5132,7 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
|
|
|
5086
5132
|
*/
|
|
5087
5133
|
// eslint-disable-next-line complexity
|
|
5088
5134
|
async fetchAll(query, options) {
|
|
5089
|
-
this.
|
|
5135
|
+
await this.ensureReady();
|
|
5090
5136
|
const startTime = Date.now();
|
|
5091
5137
|
if (!this.config.fetchers?.fetchAll) {
|
|
5092
5138
|
throw new CorePackageError(
|
|
@@ -5171,7 +5217,7 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
|
|
|
5171
5217
|
*/
|
|
5172
5218
|
// eslint-disable-next-line complexity
|
|
5173
5219
|
async fetchById(id, options) {
|
|
5174
|
-
this.
|
|
5220
|
+
await this.ensureReady();
|
|
5175
5221
|
const startTime = Date.now();
|
|
5176
5222
|
if (!this.config.fetchers?.fetchById) {
|
|
5177
5223
|
throw new CorePackageError(
|
|
@@ -5232,7 +5278,7 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
|
|
|
5232
5278
|
*/
|
|
5233
5279
|
// eslint-disable-next-line complexity, max-lines-per-function
|
|
5234
5280
|
async create(data, options) {
|
|
5235
|
-
this.
|
|
5281
|
+
await this.ensureReady();
|
|
5236
5282
|
const startTime = Date.now();
|
|
5237
5283
|
if (!this.config.fetchers?.create) {
|
|
5238
5284
|
throw new CorePackageError(
|
|
@@ -5325,7 +5371,7 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
|
|
|
5325
5371
|
*/
|
|
5326
5372
|
// eslint-disable-next-line complexity, max-lines-per-function
|
|
5327
5373
|
async update(id, data, options) {
|
|
5328
|
-
this.
|
|
5374
|
+
await this.ensureReady();
|
|
5329
5375
|
const startTime = Date.now();
|
|
5330
5376
|
if (!this.config.fetchers?.update) {
|
|
5331
5377
|
throw new CorePackageError(
|
|
@@ -5414,7 +5460,7 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
|
|
|
5414
5460
|
*/
|
|
5415
5461
|
// eslint-disable-next-line complexity
|
|
5416
5462
|
async delete(id, options) {
|
|
5417
|
-
this.
|
|
5463
|
+
await this.ensureReady();
|
|
5418
5464
|
const startTime = Date.now();
|
|
5419
5465
|
if (!this.config.fetchers?.delete) {
|
|
5420
5466
|
throw new CorePackageError(
|
|
@@ -11580,7 +11626,10 @@ var FrontendFeatureFlagDomainService = class _FrontendFeatureFlagDomainService e
|
|
|
11580
11626
|
}
|
|
11581
11627
|
/** Build API client for feature flags */
|
|
11582
11628
|
static async buildApiClient(config, options) {
|
|
11583
|
-
const apiBasePath =
|
|
11629
|
+
const apiBasePath = (
|
|
11630
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
11631
|
+
config.apiBasePath || options?.apiClient?.options?.baseURL || "/feature-flags"
|
|
11632
|
+
);
|
|
11584
11633
|
return createApiClient({ ...options?.apiClient?.options, baseURL: apiBasePath });
|
|
11585
11634
|
}
|
|
11586
11635
|
/** Build feature flag provider */
|
|
@@ -12784,9 +12833,8 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
|
|
|
12784
12833
|
// ─────────────────────────────────────────────────────────────────────────
|
|
12785
12834
|
// Constructor
|
|
12786
12835
|
// ─────────────────────────────────────────────────────────────────────────
|
|
12787
|
-
// eslint-disable-next-line complexity
|
|
12788
12836
|
constructor(config = {}, options) {
|
|
12789
|
-
const apiBasePath = config.apiBasePath
|
|
12837
|
+
const apiBasePath = config.apiBasePath || "/api/examples";
|
|
12790
12838
|
super({
|
|
12791
12839
|
serviceName: "ExampleFrontendService",
|
|
12792
12840
|
supportedRuntimes: ["frontend"],
|
|
@@ -12890,7 +12938,11 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
|
|
|
12890
12938
|
static async create(config, options) {
|
|
12891
12939
|
const mergedConfig = {
|
|
12892
12940
|
...config,
|
|
12893
|
-
|
|
12941
|
+
// Use || instead of ?? because api.baseURL may be '' (empty string) for same-origin requests.
|
|
12942
|
+
// The ?? operator only falls through on null/undefined, not empty strings.
|
|
12943
|
+
// An empty string is not a valid API path, so we treat it as "not provided" and fall through to default.
|
|
12944
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
12945
|
+
apiBasePath: config.apiBasePath || options?.apiClient?.options?.baseURL || "/api/examples"
|
|
12894
12946
|
};
|
|
12895
12947
|
const service = new _FrontendExampleDomainService(mergedConfig, options);
|
|
12896
12948
|
if (mergedConfig.autoFetch) {
|