@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/entry-frontend.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
-
|
|
4335
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
5237
|
+
await this.ensureReady();
|
|
5192
5238
|
const startTime = Date.now();
|
|
5193
5239
|
if (!this.config.fetchers?.delete) {
|
|
5194
5240
|
throw new errors.CorePackageError(
|
|
@@ -6159,9 +6205,8 @@ 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
|
-
const apiBasePath = config.apiBasePath
|
|
6209
|
+
const apiBasePath = config.apiBasePath || "/api/examples";
|
|
6165
6210
|
super({
|
|
6166
6211
|
serviceName: "ExampleFrontendService",
|
|
6167
6212
|
supportedRuntimes: ["frontend"],
|
|
@@ -6265,7 +6310,11 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
|
|
|
6265
6310
|
static async create(config, options) {
|
|
6266
6311
|
const mergedConfig = {
|
|
6267
6312
|
...config,
|
|
6268
|
-
|
|
6313
|
+
// Use || instead of ?? because api.baseURL may be '' (empty string) for same-origin requests.
|
|
6314
|
+
// The ?? operator only falls through on null/undefined, not empty strings.
|
|
6315
|
+
// An empty string is not a valid API path, so we treat it as "not provided" and fall through to default.
|
|
6316
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
6317
|
+
apiBasePath: config.apiBasePath || options?.apiClient?.options?.baseURL || "/api/examples"
|
|
6269
6318
|
};
|
|
6270
6319
|
const service = new _FrontendExampleDomainService(mergedConfig, options);
|
|
6271
6320
|
if (mergedConfig.autoFetch) {
|
|
@@ -7574,7 +7623,10 @@ var FrontendFeatureFlagDomainService = class _FrontendFeatureFlagDomainService e
|
|
|
7574
7623
|
}
|
|
7575
7624
|
/** Build API client for feature flags */
|
|
7576
7625
|
static async buildApiClient(config, options) {
|
|
7577
|
-
const apiBasePath =
|
|
7626
|
+
const apiBasePath = (
|
|
7627
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
7628
|
+
config.apiBasePath || options?.apiClient?.options?.baseURL || "/feature-flags"
|
|
7629
|
+
);
|
|
7578
7630
|
return frontend.createApiClient({ ...options?.apiClient?.options, baseURL: apiBasePath });
|
|
7579
7631
|
}
|
|
7580
7632
|
/** Build feature flag provider */
|