datastake-daf 0.6.549 → 0.6.551

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.
@@ -41063,12 +41063,98 @@ const createErrorHandler = (config = {}) => {
41063
41063
  };
41064
41064
  };
41065
41065
 
41066
- let globalConfig = {};
41066
+ /**
41067
+ * DafConfig - Singleton class for managing DAF configuration
41068
+ * This class ensures only one instance exists throughout the application lifecycle
41069
+ * and provides centralized config management for all services.
41070
+ */
41071
+ class DafConfig {
41072
+ static #instance = null;
41073
+ #config = {
41074
+ application: null,
41075
+ mainApiUrl: null,
41076
+ storeUrl: null,
41077
+ language: 'en',
41078
+ onError: null,
41079
+ messageHandler: null,
41080
+ store: null,
41081
+ addToastAction: null
41082
+ };
41083
+
41084
+ /**
41085
+ * Private constructor - prevents direct instantiation
41086
+ * Use DafConfig.getInstance() instead
41087
+ */
41088
+ constructor() {
41089
+ if (DafConfig.#instance) {
41090
+ throw new Error('DafConfig is a singleton. Use DafConfig.getInstance() instead.');
41091
+ }
41092
+ DafConfig.#instance = this;
41093
+ }
41094
+
41095
+ /**
41096
+ * Get the singleton instance of DafConfig
41097
+ * @returns {DafConfig} The singleton instance
41098
+ */
41099
+ static getInstance() {
41100
+ if (!DafConfig.#instance) {
41101
+ DafConfig.#instance = new DafConfig();
41102
+ }
41103
+ return DafConfig.#instance;
41104
+ }
41105
+
41106
+ /**
41107
+ * Set configuration values (merges with existing config)
41108
+ * @param {Object} config - Configuration object to merge
41109
+ */
41110
+ setConfig(config) {
41111
+ this.#config = {
41112
+ ...this.#config,
41113
+ ...config
41114
+ };
41115
+ console.log('[DafConfig] Configuration updated:', this.#config);
41116
+ }
41117
+
41118
+ /**
41119
+ * Get the current configuration
41120
+ * @returns {Object} The current configuration object
41121
+ */
41122
+ getConfig() {
41123
+ console.log('[DafConfig] Configuration retrieved:', this.#config);
41124
+ return this.#config;
41125
+ }
41126
+
41127
+ /**
41128
+ * Get a specific config value by key
41129
+ * @param {string} key - The config key to retrieve
41130
+ * @returns {*} The config value
41131
+ */
41132
+ get(key) {
41133
+ return this.#config[key];
41134
+ }
41135
+
41136
+ /**
41137
+ * Reset configuration to default values
41138
+ */
41139
+ reset() {
41140
+ this.#config = {
41141
+ application: null,
41142
+ mainApiUrl: null,
41143
+ storeUrl: null,
41144
+ language: 'en',
41145
+ onError: null,
41146
+ messageHandler: null,
41147
+ store: null,
41148
+ addToastAction: null
41149
+ };
41150
+ console.log('[DafConfig] Configuration reset to defaults');
41151
+ }
41152
+ }
41153
+
41154
+ // Export singleton instance
41155
+ const dafConfig = DafConfig.getInstance();
41067
41156
  const getConfig$1 = () => {
41068
- console.log({
41069
- getConfig: globalConfig
41070
- });
41071
- return globalConfig;
41157
+ return dafConfig.getConfig();
41072
41158
  };
41073
41159
 
41074
41160
  class ErrorService {
@@ -41098,10 +41184,7 @@ class ErrorService {
41098
41184
  // In datastake-daf - src/services/BaseService.js
41099
41185
  class BaseService extends BaseHTTPService {
41100
41186
  constructor() {
41101
- const config = getConfig$1();
41102
- console.log({
41103
- config1: config
41104
- });
41187
+ getConfig$1();
41105
41188
  const errorHandler = createErrorHandler({
41106
41189
  getStorageManager: () => StorageManager,
41107
41190
  handleError: ({
@@ -41139,9 +41222,6 @@ class BaseService extends BaseHTTPService {
41139
41222
  getToken: () => getToken(),
41140
41223
  getHeaders: () => {
41141
41224
  const config = getConfig$1();
41142
- console.log({
41143
- config2: config
41144
- });
41145
41225
  return {
41146
41226
  Language: config.language || StorageManager.get('datastakeLng') || 'en',
41147
41227
  'ngrok-skip-browser-warning': true,
@@ -841,12 +841,98 @@ const createErrorHandler = (config = {}) => {
841
841
  };
842
842
  };
843
843
 
844
- let globalConfig = {};
844
+ /**
845
+ * DafConfig - Singleton class for managing DAF configuration
846
+ * This class ensures only one instance exists throughout the application lifecycle
847
+ * and provides centralized config management for all services.
848
+ */
849
+ class DafConfig {
850
+ static #instance = null;
851
+ #config = {
852
+ application: null,
853
+ mainApiUrl: null,
854
+ storeUrl: null,
855
+ language: 'en',
856
+ onError: null,
857
+ messageHandler: null,
858
+ store: null,
859
+ addToastAction: null
860
+ };
861
+
862
+ /**
863
+ * Private constructor - prevents direct instantiation
864
+ * Use DafConfig.getInstance() instead
865
+ */
866
+ constructor() {
867
+ if (DafConfig.#instance) {
868
+ throw new Error('DafConfig is a singleton. Use DafConfig.getInstance() instead.');
869
+ }
870
+ DafConfig.#instance = this;
871
+ }
872
+
873
+ /**
874
+ * Get the singleton instance of DafConfig
875
+ * @returns {DafConfig} The singleton instance
876
+ */
877
+ static getInstance() {
878
+ if (!DafConfig.#instance) {
879
+ DafConfig.#instance = new DafConfig();
880
+ }
881
+ return DafConfig.#instance;
882
+ }
883
+
884
+ /**
885
+ * Set configuration values (merges with existing config)
886
+ * @param {Object} config - Configuration object to merge
887
+ */
888
+ setConfig(config) {
889
+ this.#config = {
890
+ ...this.#config,
891
+ ...config
892
+ };
893
+ console.log('[DafConfig] Configuration updated:', this.#config);
894
+ }
895
+
896
+ /**
897
+ * Get the current configuration
898
+ * @returns {Object} The current configuration object
899
+ */
900
+ getConfig() {
901
+ console.log('[DafConfig] Configuration retrieved:', this.#config);
902
+ return this.#config;
903
+ }
904
+
905
+ /**
906
+ * Get a specific config value by key
907
+ * @param {string} key - The config key to retrieve
908
+ * @returns {*} The config value
909
+ */
910
+ get(key) {
911
+ return this.#config[key];
912
+ }
913
+
914
+ /**
915
+ * Reset configuration to default values
916
+ */
917
+ reset() {
918
+ this.#config = {
919
+ application: null,
920
+ mainApiUrl: null,
921
+ storeUrl: null,
922
+ language: 'en',
923
+ onError: null,
924
+ messageHandler: null,
925
+ store: null,
926
+ addToastAction: null
927
+ };
928
+ console.log('[DafConfig] Configuration reset to defaults');
929
+ }
930
+ }
931
+
932
+ // Export singleton instance
933
+ const dafConfig = DafConfig.getInstance();
845
934
  const getConfig = () => {
846
- console.log({
847
- getConfig: globalConfig
848
- });
849
- return globalConfig;
935
+ return dafConfig.getConfig();
850
936
  };
851
937
 
852
938
  class ErrorService {
@@ -876,10 +962,7 @@ class ErrorService {
876
962
  // In datastake-daf - src/services/BaseService.js
877
963
  class BaseService extends BaseHTTPService {
878
964
  constructor() {
879
- const config = getConfig();
880
- console.log({
881
- config1: config
882
- });
965
+ getConfig();
883
966
  const errorHandler = createErrorHandler({
884
967
  getStorageManager: () => StorageManager$1,
885
968
  handleError: ({
@@ -917,9 +1000,6 @@ class BaseService extends BaseHTTPService {
917
1000
  getToken: () => getToken(),
918
1001
  getHeaders: () => {
919
1002
  const config = getConfig();
920
- console.log({
921
- config2: config
922
- });
923
1003
  return {
924
1004
  Language: config.language || StorageManager$1.get('datastakeLng') || 'en',
925
1005
  'ngrok-skip-browser-warning': true,
@@ -470,21 +470,103 @@ class ErrorHandler {
470
470
  }
471
471
  }
472
472
 
473
- let globalConfig = {};
474
- const configureServices = config => {
475
- globalConfig = {
476
- ...globalConfig,
477
- ...config
473
+ /**
474
+ * DafConfig - Singleton class for managing DAF configuration
475
+ * This class ensures only one instance exists throughout the application lifecycle
476
+ * and provides centralized config management for all services.
477
+ */
478
+ class DafConfig {
479
+ static #instance = null;
480
+ #config = {
481
+ application: null,
482
+ mainApiUrl: null,
483
+ storeUrl: null,
484
+ language: 'en',
485
+ onError: null,
486
+ messageHandler: null,
487
+ store: null,
488
+ addToastAction: null
478
489
  };
479
- console.log({
480
- configureServices: globalConfig
481
- });
490
+
491
+ /**
492
+ * Private constructor - prevents direct instantiation
493
+ * Use DafConfig.getInstance() instead
494
+ */
495
+ constructor() {
496
+ if (DafConfig.#instance) {
497
+ throw new Error('DafConfig is a singleton. Use DafConfig.getInstance() instead.');
498
+ }
499
+ DafConfig.#instance = this;
500
+ }
501
+
502
+ /**
503
+ * Get the singleton instance of DafConfig
504
+ * @returns {DafConfig} The singleton instance
505
+ */
506
+ static getInstance() {
507
+ if (!DafConfig.#instance) {
508
+ DafConfig.#instance = new DafConfig();
509
+ }
510
+ return DafConfig.#instance;
511
+ }
512
+
513
+ /**
514
+ * Set configuration values (merges with existing config)
515
+ * @param {Object} config - Configuration object to merge
516
+ */
517
+ setConfig(config) {
518
+ this.#config = {
519
+ ...this.#config,
520
+ ...config
521
+ };
522
+ console.log('[DafConfig] Configuration updated:', this.#config);
523
+ }
524
+
525
+ /**
526
+ * Get the current configuration
527
+ * @returns {Object} The current configuration object
528
+ */
529
+ getConfig() {
530
+ console.log('[DafConfig] Configuration retrieved:', this.#config);
531
+ return this.#config;
532
+ }
533
+
534
+ /**
535
+ * Get a specific config value by key
536
+ * @param {string} key - The config key to retrieve
537
+ * @returns {*} The config value
538
+ */
539
+ get(key) {
540
+ return this.#config[key];
541
+ }
542
+
543
+ /**
544
+ * Reset configuration to default values
545
+ */
546
+ reset() {
547
+ this.#config = {
548
+ application: null,
549
+ mainApiUrl: null,
550
+ storeUrl: null,
551
+ language: 'en',
552
+ onError: null,
553
+ messageHandler: null,
554
+ store: null,
555
+ addToastAction: null
556
+ };
557
+ console.log('[DafConfig] Configuration reset to defaults');
558
+ }
559
+ }
560
+
561
+ // Export singleton instance
562
+ const dafConfig = DafConfig.getInstance();
563
+
564
+ // Backward compatibility exports
565
+ const configureServices = config => {
566
+ dafConfig.setConfig(config);
482
567
  };
483
568
  const getConfig = () => {
484
- console.log({
485
- getConfig: globalConfig
486
- });
487
- return globalConfig;
569
+ return dafConfig.getConfig();
488
570
  };
489
571
 
490
572
  /**
@@ -623,10 +705,7 @@ class ErrorService {
623
705
  // In datastake-daf - src/services/BaseService.js
624
706
  class BaseService extends BaseHTTPService {
625
707
  constructor() {
626
- const config = getConfig();
627
- console.log({
628
- config1: config
629
- });
708
+ getConfig();
630
709
  const errorHandler = createErrorHandler({
631
710
  getStorageManager: () => StorageManager$1,
632
711
  handleError: ({
@@ -664,9 +743,6 @@ class BaseService extends BaseHTTPService {
664
743
  getToken: () => getToken(),
665
744
  getHeaders: () => {
666
745
  const config = getConfig();
667
- console.log({
668
- config2: config
669
- });
670
746
  return {
671
747
  Language: config.language || StorageManager$1.get('datastakeLng') || 'en',
672
748
  'ngrok-skip-browser-warning': true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datastake-daf",
3
- "version": "0.6.549",
3
+ "version": "0.6.551",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.2.5",
6
6
  "@antv/g2": "^5.1.1",
@@ -9,7 +9,6 @@ import { ErrorService } from './ErrorService.js';
9
9
  export class BaseService extends BaseHTTPService {
10
10
  constructor() {
11
11
  const config = getConfig();
12
- console.log({config1: config})
13
12
 
14
13
  const errorHandler = createErrorHandler({
15
14
  getStorageManager: () => StorageManager,
@@ -36,7 +35,6 @@ export class BaseService extends BaseHTTPService {
36
35
  getToken: () => getToken(),
37
36
  getHeaders: () => {
38
37
  const config = getConfig();
39
- console.log({config2: config})
40
38
  return {
41
39
  Language: config.language || StorageManager.get('datastakeLng') || 'en',
42
40
  'ngrok-skip-browser-warning': true,
@@ -0,0 +1,36 @@
1
+ let globalConfig = {
2
+ application: null,
3
+ mainApiUrl: null,
4
+ storeUrl: null,
5
+ language: 'en',
6
+ onError: null,
7
+ messageHandler: null,
8
+ store: null,
9
+ addToastAction: null,
10
+ };
11
+
12
+ export const configureServices = (config) => {
13
+ globalConfig = { ...globalConfig, ...config };
14
+ console.log({configureServices: globalConfig})
15
+ };
16
+
17
+ export const getConfig = () => {
18
+ console.log({getConfig: globalConfig})
19
+ return globalConfig;
20
+ };
21
+
22
+
23
+ class DafConfig {
24
+ constructor() {
25
+ this.config = {};
26
+ }
27
+
28
+ setConfig(config) {
29
+ this.config = config;
30
+ }
31
+ getConfig() {
32
+ return this.config;
33
+ }
34
+ }
35
+
36
+ export const dafConfig = new DafConfig();
@@ -1,11 +1,99 @@
1
- let globalConfig = {};
2
-
1
+ /**
2
+ * DafConfig - Singleton class for managing DAF configuration
3
+ * This class ensures only one instance exists throughout the application lifecycle
4
+ * and provides centralized config management for all services.
5
+ */
6
+ class DafConfig {
7
+ static #instance = null;
8
+ #config = {
9
+ application: null,
10
+ mainApiUrl: null,
11
+ storeUrl: null,
12
+ language: 'en',
13
+ onError: null,
14
+ messageHandler: null,
15
+ store: null,
16
+ addToastAction: null,
17
+ };
18
+
19
+ /**
20
+ * Private constructor - prevents direct instantiation
21
+ * Use DafConfig.getInstance() instead
22
+ */
23
+ constructor() {
24
+ if (DafConfig.#instance) {
25
+ throw new Error('DafConfig is a singleton. Use DafConfig.getInstance() instead.');
26
+ }
27
+ DafConfig.#instance = this;
28
+ }
29
+
30
+ /**
31
+ * Get the singleton instance of DafConfig
32
+ * @returns {DafConfig} The singleton instance
33
+ */
34
+ static getInstance() {
35
+ if (!DafConfig.#instance) {
36
+ DafConfig.#instance = new DafConfig();
37
+ }
38
+ return DafConfig.#instance;
39
+ }
40
+
41
+ /**
42
+ * Set configuration values (merges with existing config)
43
+ * @param {Object} config - Configuration object to merge
44
+ */
45
+ setConfig(config) {
46
+ this.#config = { ...this.#config, ...config };
47
+ console.log('[DafConfig] Configuration updated:', this.#config);
48
+ }
49
+
50
+ /**
51
+ * Get the current configuration
52
+ * @returns {Object} The current configuration object
53
+ */
54
+ getConfig() {
55
+ console.log('[DafConfig] Configuration retrieved:', this.#config);
56
+ return this.#config;
57
+ }
58
+
59
+ /**
60
+ * Get a specific config value by key
61
+ * @param {string} key - The config key to retrieve
62
+ * @returns {*} The config value
63
+ */
64
+ get(key) {
65
+ return this.#config[key];
66
+ }
67
+
68
+ /**
69
+ * Reset configuration to default values
70
+ */
71
+ reset() {
72
+ this.#config = {
73
+ application: null,
74
+ mainApiUrl: null,
75
+ storeUrl: null,
76
+ language: 'en',
77
+ onError: null,
78
+ messageHandler: null,
79
+ store: null,
80
+ addToastAction: null,
81
+ };
82
+ console.log('[DafConfig] Configuration reset to defaults');
83
+ }
84
+ }
85
+
86
+ // Export singleton instance
87
+ export const dafConfig = DafConfig.getInstance();
88
+
89
+ // Backward compatibility exports
3
90
  export const configureServices = (config) => {
4
- globalConfig = { ...globalConfig, ...config };
5
- console.log({configureServices: globalConfig})
91
+ dafConfig.setConfig(config);
6
92
  };
7
-
93
+
8
94
  export const getConfig = () => {
9
- console.log({getConfig: globalConfig})
10
- return globalConfig;
11
- };
95
+ return dafConfig.getConfig();
96
+ };
97
+
98
+ // Also export the class itself if needed for type checking or testing
99
+ export { DafConfig };