@plyaz/core 1.11.0 → 1.11.1

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.
@@ -7,7 +7,7 @@ import { CoreLogger, PackageLogger } from '@plyaz/logger';
7
7
  import { ERROR_CODES, STORAGE_ERROR_CODES, NOTIFICATION_ERROR_CODES, DATABASE_ERROR_CODES, ERROR_CATEGORY, API_ERROR_CODES as API_ERROR_CODES$1 } from '@plyaz/types/errors';
8
8
  import { OBSERVABILITY_METRICS } from '@plyaz/types/observability';
9
9
  import { clearEventEmitter, setEventEmitter, initializeGlobalErrorHandler } from '@plyaz/errors/middleware';
10
- import { STORE_KEYS, useRootStore, createStandaloneFeatureFlagStore } from '@plyaz/store';
10
+ import { STORE_KEYS, createStandaloneFeatureFlagStore } from '@plyaz/store';
11
11
  import { CORE_EVENTS, FEATURE_FLAG_TABLE, FEATURE_FLAG_FIELD, SORT_DIRECTION, FEATURE_FLAG_RULE_FIELD, EVALUATION_REASONS, DATABASE_FIELDS, SYSTEM_USERS, FEATURE_FLAG_TYPES, SERVICE_KEYS, FEATURE_FLAG_PROVIDERS as FEATURE_FLAG_PROVIDERS$1, NODE_ENVIRONMENTS as NODE_ENVIRONMENTS$1, FEATURE_FLAG_DEFAULTS } from '@plyaz/types/core';
12
12
  import { deleteFile, getFile, downloadFile, getSignedUrl, uploadFile, uploadFiles, generateDocument } from '@plyaz/api';
13
13
  import { ENTITY_TYPE, FILE_CATEGORY } from '@plyaz/types/storage';
@@ -1452,8 +1452,6 @@ var init_CompositeAdapter = __esm({
1452
1452
  init_common();
1453
1453
  }
1454
1454
  });
1455
-
1456
- // src/base/observability/DatadogAdapter.ts
1457
1455
  var init_DatadogAdapter = __esm({
1458
1456
  "src/base/observability/DatadogAdapter.ts"() {
1459
1457
  init_common();
@@ -2938,6 +2936,24 @@ var init_CoreInitializer = __esm({
2938
2936
  */
2939
2937
  this._rootStore = null;
2940
2938
  }
2939
+ static {
2940
+ /**
2941
+ * Injected store hook for frontend (set via setRootStoreHook before initialize).
2942
+ * This is used instead of directly importing from @plyaz/store to prevent
2943
+ * duplicate store instances when bundlers create multiple module copies.
2944
+ */
2945
+ this._injectedStoreHook = null;
2946
+ }
2947
+ /**
2948
+ * Set the root store hook for frontend use.
2949
+ * Must be called before Core.initialize() when running in browser.
2950
+ * PlyazProvider calls this automatically with the store prop.
2951
+ *
2952
+ * @param store - The useRootStore hook from @plyaz/store
2953
+ */
2954
+ static setRootStoreHook(store) {
2955
+ _Core._injectedStoreHook = store;
2956
+ }
2941
2957
  /**
2942
2958
  * Setup environment and context
2943
2959
  */
@@ -3848,8 +3864,14 @@ var init_CoreInitializer = __esm({
3848
3864
  static async initializeRootStore(config, verbose) {
3849
3865
  const isFrontend = typeof window !== "undefined";
3850
3866
  if (isFrontend) {
3851
- _Core.log("Using frontend root store (Zustand)", verbose);
3852
- _Core._rootStore = useRootStore;
3867
+ if (!_Core._injectedStoreHook) {
3868
+ throw new CorePackageError(
3869
+ "Root store hook not set. Call Core.setRootStoreHook(useRootStore) before Core.initialize(), or use PlyazProvider with the store prop: <PlyazProvider store={useRootStore} ...>",
3870
+ ERROR_CODES$1.CLIENT_INITIALIZATION_FAILED
3871
+ );
3872
+ }
3873
+ _Core.log("Using frontend root store (Zustand) - injected via setRootStoreHook", verbose);
3874
+ _Core._rootStore = _Core._injectedStoreHook;
3853
3875
  } else {
3854
3876
  _Core.log("Creating backend composite store (in-memory)", verbose);
3855
3877
  const ServerErrorMiddleware2 = getCoreDependency("ServerErrorMiddleware");
@@ -9012,7 +9034,10 @@ var init_FrontendExampleDomainService = __esm({
9012
9034
  const response = await this.apiClient.post(endpoint, data);
9013
9035
  if (!this.isResponseSuccess(response)) {
9014
9036
  const error = this.extractResponseError(response);
9015
- throw new Error(`Failed to send email: ${JSON.stringify(error)}`);
9037
+ throw new CorePackageError(
9038
+ `Failed to send email: ${JSON.stringify(error)}`,
9039
+ ERROR_CODES$1.CORE_OPERATION_FAILED
9040
+ );
9016
9041
  }
9017
9042
  const result = this.unwrapResponseData(response.data);
9018
9043
  CoreEventManager.emit(`${this.eventPrefix}:email:sent`, { result });
@@ -11141,8 +11166,9 @@ var init_BackendFilesDomainService = __esm({
11141
11166
  try {
11142
11167
  await this.beforeDownloadFile?.(params);
11143
11168
  if (!this.storageService) {
11144
- throw new Error(
11145
- "Storage service not available. Ensure storage is configured in Core.initialize()."
11169
+ throw new CorePackageError(
11170
+ "Storage service not available. Ensure storage is configured in Core.initialize().",
11171
+ ERROR_CODES$1.CORE_PROVIDER_INITIALIZATION_FAILED
11146
11172
  );
11147
11173
  }
11148
11174
  const storage = this.storageService.getStorage();
@@ -11183,8 +11209,9 @@ var init_BackendFilesDomainService = __esm({
11183
11209
  try {
11184
11210
  await this.beforeGetSignedUrl?.(params);
11185
11211
  if (!this.storageService) {
11186
- throw new Error(
11187
- "Storage service not available. Ensure storage is configured in Core.initialize()."
11212
+ throw new CorePackageError(
11213
+ "Storage service not available. Ensure storage is configured in Core.initialize().",
11214
+ ERROR_CODES$1.CORE_PROVIDER_INITIALIZATION_FAILED
11188
11215
  );
11189
11216
  }
11190
11217
  const storage = this.storageService.getStorage();
@@ -15976,8 +16003,9 @@ function buildDatabaseProviderConfig(config) {
15976
16003
  __name(buildDatabaseProviderConfig, "buildDatabaseProviderConfig");
15977
16004
  function buildRedisProviderConfig(config) {
15978
16005
  if (!config.redis?.url) {
15979
- throw new Error(
15980
- 'Redis URL is required when using redis provider. Provide redis: { url: "redis://..." }'
16006
+ throw new CorePackageError(
16007
+ 'Redis URL is required when using redis provider. Provide redis: { url: "redis://..." }',
16008
+ ERROR_CODES$1.CORE_CONFIGURATION_INVALID
15981
16009
  );
15982
16010
  }
15983
16011
  return {