exodus-framework 2.1.1002 → 2.1.1004

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.
@@ -14,6 +14,7 @@ declare class ProcessEmitterManager extends System {
14
14
  private static clusterExitHandles;
15
15
  private static processSIGINTHandles;
16
16
  private static processSIGTERMHandles;
17
+ private static processSIGUSR2Handles;
17
18
  private static processExceptionHandles;
18
19
  private static processRejectionHandles;
19
20
  private static processExitHandles;
@@ -27,6 +28,7 @@ declare class ProcessEmitterManager extends System {
27
28
  static registerProcessRejectionHandle(handle: cbRejection): void;
28
29
  static registerProcessExitHandle(handle: cbProcessExit): void;
29
30
  static registerProcessMessageHandle(handle: cbMessage): void;
31
+ static registerProcessSIGUSR2Handle(handle: cbSignal): void;
30
32
  static Start(): void;
31
33
  }
32
34
  export default ProcessEmitterManager;
@@ -1 +1 @@
1
- {"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../../src/app/classes/event.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAEhE,KAAK,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;AACrE,KAAK,OAAO,GAAG,MAAM,IAAI,CAAC;AAC1B,KAAK,aAAa,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;AAC5C,KAAK,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,KAAK,IAAI,CAAC;AACjD,KAAK,WAAW,GAAG,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAC;AACxC,KAAK,WAAW,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,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E,MAAM;IAG/C,MAAM,CAAC,2BAA2B,CAAC,MAAM,EAAE,QAAQ;IAGnD,MAAM,CAAC,4BAA4B,CAAC,MAAM,EAAE,QAAQ;IAGpD,MAAM,CAAC,8BAA8B,CAAC,MAAM,EAAE,WAAW;IAGzD,MAAM,CAAC,8BAA8B,CAAC,MAAM,EAAE,WAAW;IAGzD,MAAM,CAAC,yBAAyB,CAAC,MAAM,EAAE,aAAa;IAGtD,MAAM,CAAC,4BAA4B,CAAC,MAAM,EAAE,SAAS;IAGrD,MAAM,CAAC,4BAA4B,CAAC,MAAM,EAAE,QAAQ;IAIpD,MAAM,CAAC,KAAK;CA6Db;AAED,eAAe,qBAAqB,CAAC"}
@@ -19,6 +19,7 @@ class ProcessEmitterManager extends _system.default {
19
19
  static clusterExitHandles = [];
20
20
  static processSIGINTHandles = [];
21
21
  static processSIGTERMHandles = [];
22
+ static processSIGUSR2Handles = [];
22
23
  static processExceptionHandles = [];
23
24
  static processRejectionHandles = [];
24
25
  static processExitHandles = [];
@@ -50,6 +51,9 @@ class ProcessEmitterManager extends _system.default {
50
51
  static registerProcessMessageHandle(handle) {
51
52
  this.processMessageHandles.push(handle);
52
53
  }
54
+ static registerProcessSIGUSR2Handle(handle) {
55
+ this.processSIGUSR2Handles.push(handle);
56
+ }
53
57
  static Start() {
54
58
  for (const cb of this.workerStartHandles) {
55
59
  if (cb) cb();
@@ -76,6 +80,11 @@ class ProcessEmitterManager extends _system.default {
76
80
  if (cb) cb(signal);
77
81
  }
78
82
  });
83
+ process.on('SIGUSR2', signal => {
84
+ for (const cb of this.processSIGUSR2Handles) {
85
+ if (cb) cb(signal);
86
+ }
87
+ });
79
88
  process.on('uncaughtException', err => {
80
89
  for (const cb of this.processExceptionHandles) {
81
90
  if (cb) cb(err);
@@ -18,6 +18,9 @@ declare abstract class Managed extends System {
18
18
  protected onSIGTERM(_signal: NodeJS.Signals): void;
19
19
  protected onClusterSIGTERM(_signal: NodeJS.Signals): void;
20
20
  protected onMasterSIGTERM(_signal: NodeJS.Signals): void;
21
+ protected onSIGUSR2(_signal: NodeJS.Signals): void;
22
+ protected onClusterSIGUSR2(_signal: NodeJS.Signals): void;
23
+ protected onMasterSIGUSR2(_signal: NodeJS.Signals): void;
21
24
  protected onUncaughtException(_err: Error): void;
22
25
  protected onClusterUncaughtException(_err: Error): void;
23
26
  protected onMasterUncaughtException(_err: Error): void;
@@ -1 +1 @@
1
- {"version":3,"file":"managed.d.ts","sourceRoot":"","sources":["../../../src/app/classes/managed.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAG1C,OAAO,MAAM,MAAM,UAAU,CAAC;AAS9B,uBAAe,OAAQ,SAAQ,MAAM;IACnC,OAAO,CAAC,SAAS,CAAU;IAC3B,OAAO,CAAC,UAAU,CAAU;;IAS5B,OAAO,CAAC,wBAAwB;IAWhC,SAAS,CAAC,MAAM;IAYhB,SAAS,CAAC,aAAa;IACvB,SAAS,CAAC,YAAY;IAOtB,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM;IAI9B,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM;IAGrC,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM;IAGpC,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAGvE,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO;IAM1C,SAAS,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO;IAIjD,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO;IAMhD,SAAS,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO;IAM3C,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO;IAIlD,SAAS,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,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T(signal));
30
30
  _event.default.registerProcessSIGTERMHandle(signal => this.onSIGTERM(signal));
31
+ _event.default.registerProcessSIGUSR2Handle(signal => this.onSIGUSR2(signal));
31
32
  _event.default.registerProcessExceptionHandle(err => this.onUncaughtException(err));
32
33
  _event.default.registerProcessExitHandle(code => this.onExit(code));
33
34
  _event.default.registerProcessRejectionHandle((reason, promise) => this.onUnhandledRejection(reason, promise));
@@ -64,57 +65,43 @@ class Managed extends _system.default {
64
65
 
65
66
  //# SIGINT
66
67
  onSIGINT(_signal) {
67
- this.log('Processo encerrado pelo usuário', 'especial');
68
68
  if (this.isMaster()) this.onMasterSIGINT(_signal);
69
69
  if (this.isCluster()) this.onClusterSIGINT(_signal);
70
70
  }
71
- onClusterSIGINT(_signal) {
72
- this.log('Processo encerrado pelo usuário', 'especial');
73
- process.exit(0);
74
- }
75
- onMasterSIGINT(_signal) {
76
- this.log('Processo encerrado pelo usuário', 'especial');
77
- process.exit(0);
78
- }
71
+ onClusterSIGINT(_signal) {}
72
+ onMasterSIGINT(_signal) {}
79
73
 
80
74
  //# SIGTERM
81
75
  onSIGTERM(_signal) {
82
- this.log('Processo encerrado pelo sistema', 'especial');
83
76
  if (this.isMaster()) this.onMasterSIGTERM(_signal);
84
77
  if (this.isCluster()) this.onClusterSIGTERM(_signal);
85
78
  }
86
- onClusterSIGTERM(_signal) {
87
- this.log('Processo encerrado pelo sistema', 'especial');
88
- process.exit(0);
89
- }
90
- onMasterSIGTERM(_signal) {
91
- this.log('Processo encerrado pelo sistema', 'especial');
92
- process.exit(0);
79
+ onClusterSIGTERM(_signal) {}
80
+ onMasterSIGTERM(_signal) {}
81
+
82
+ //# SIGUSR2
83
+ onSIGUSR2(_signal) {
84
+ if (this.isMaster()) this.onMasterSIGUSR2(_signal);
85
+ if (this.isCluster()) this.onClusterSIGUSR2(_signal);
93
86
  }
87
+ onClusterSIGUSR2(_signal) {}
88
+ onMasterSIGUSR2(_signal) {}
94
89
 
95
90
  //# UNCAUGHT EXCEPTION
96
91
  onUncaughtException(_err) {
97
92
  if (this.isMaster()) this.onMasterUncaughtException(_err);
98
93
  if (this.isCluster()) this.onClusterUncaughtException(_err);
99
94
  }
100
- onClusterUncaughtException(_err) {
101
- //
102
- }
103
- onMasterUncaughtException(_err) {
104
- //
105
- }
95
+ onClusterUncaughtException(_err) {}
96
+ onMasterUncaughtException(_err) {}
106
97
 
107
98
  //# UNHANDLED REJECTION
108
99
  onUnhandledRejection(_reason, _promise) {
109
100
  if (this.isMaster()) this.onMasterUnhandledRejection(_reason, _promise);
110
101
  if (this.isCluster()) this.onClusterUnhandledRejection(_reason, _promise);
111
102
  }
112
- onClusterUnhandledRejection(_reason, _promise) {
113
- //
114
- }
115
- onMasterUnhandledRejection(_reason, _promise) {
116
- //
117
- }
103
+ onClusterUnhandledRejection(_reason, _promise) {}
104
+ onMasterUnhandledRejection(_reason, _promise) {}
118
105
 
119
106
  //# Utils
120
107
  isMaster() {
@@ -3,6 +3,7 @@ import Managed from './classes/managed';
3
3
  import CoreSettings from './settings';
4
4
  declare class Exodus extends Managed {
5
5
  private services;
6
+ private isShuttingDown;
6
7
  static startedAt: Date;
7
8
  constructor(settings: CoreSettings);
8
9
  start(): Promise<void>;
@@ -11,10 +12,17 @@ declare class Exodus extends Managed {
11
12
  private initServices;
12
13
  private startService;
13
14
  static getStartedAt(): Date;
15
+ protected onExit(code: number): void;
16
+ protected onSIGTERM(signal: NodeJS.Signals): void;
17
+ protected onSIGINT(signal: NodeJS.Signals): void;
18
+ protected onSIGUSR2(signal: NodeJS.Signals): void;
14
19
  protected onClusterUncaughtException(err: Error): void;
15
20
  protected onMasterUncaughtException(err: Error): void;
16
21
  protected onClusterUnhandledRejection(reason: unknown, promise: Promise<unknown>): void;
17
22
  protected onMasterUnhandledRejection(reason: unknown, promise: Promise<unknown>): void;
23
+ private isCriticalRejection;
24
+ shutdown(reason?: string): Promise<void>;
25
+ private gracefulShutdown;
18
26
  }
19
27
  export default Exodus;
20
28
  //# sourceMappingURL=exodus.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"exodus.d.ts","sourceRoot":"","sources":["../../src/app/exodus.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,OAAO,EAAE,MAAM,GAAG,CAAC;AAG1C,OAAO,OAAO,MAAM,mBAAmB,CAAC;AAExC,OAAO,YAAY,MAAM,YAAY,CAAC;AAUtC,cAAM,MAAO,SAAQ,OAAO;IAC1B,OAAO,CAAC,QAAQ,CAAY;IAC5B,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC;gBAEX,QAAQ,EAAE,YAAY;IAUrB,KAAK;IAwBlB,OAAO,CAAC,cAAc;IAef,QAAQ,CAAC,OAAO,EAAE,OAAO,OAAO;YAGzB,YAAY;YAiBZ,YAAY;IAqB1B,MAAM,CAAC,YAAY,IAAI,IAAI;IAK3B,SAAS,CAAC,0BAA0B,CAAC,GAAG,EAAE,KAAK;IAQ/C,SAAS,CAAC,yBAAyB,CAAC,GAAG,EAAE,KAAK;IAU9C,SAAS,CAAC,2BAA2B,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;IAMhF,SAAS,CAAC,0BAA0B,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;CAMhF;AACD,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"exodus.d.ts","sourceRoot":"","sources":["../../src/app/exodus.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,OAAO,EAAE,MAAM,GAAG,CAAC;AAG1C,OAAO,OAAO,MAAM,mBAAmB,CAAC;AAExC,OAAO,YAAY,MAAM,YAAY,CAAC;AAWtC,cAAM,MAAO,SAAQ,OAAO;IAC1B,OAAO,CAAC,QAAQ,CAAY;IAC5B,OAAO,CAAC,cAAc,CAAkB;IACxC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC;gBAEX,QAAQ,EAAE,YAAY;IAUrB,KAAK;IAwBlB,OAAO,CAAC,cAAc;IAef,QAAQ,CAAC,OAAO,EAAE,OAAO,OAAO;YAGzB,YAAY;YAiBZ,YAAY;IAsB1B,MAAM,CAAC,YAAY,IAAI,IAAI;IAK3B,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM;IAM7B,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO;IAQ1C,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO;IAQzC,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO;IAO1C,SAAS,CAAC,0BAA0B,CAAC,GAAG,EAAE,KAAK;IAS/C,SAAS,CAAC,yBAAyB,CAAC,GAAG,EAAE,KAAK;IAW9C,SAAS,CAAC,2BAA2B,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;IAehF,SAAS,CAAC,0BAA0B,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;IAiB/E,OAAO,CAAC,mBAAmB;IAkBd,QAAQ,CAAC,MAAM,GAAE,MAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;YAGjD,gBAAgB;CAwF/B;AACD,eAAe,MAAM,CAAC"}
package/lib/app/exodus.js CHANGED
@@ -11,6 +11,7 @@ var _event = _interopRequireDefault(require("./classes/event"));
11
11
  var _managed = _interopRequireDefault(require("./classes/managed"));
12
12
  var _core = _interopRequireDefault(require("./core"));
13
13
  var _logger2 = _interopRequireDefault(require("../utils/logger"));
14
+ var _process = require("process");
14
15
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
16
  /**
16
17
  * Classe da aplicação principal
@@ -21,6 +22,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
21
22
  */
22
23
  class Exodus extends _managed.default {
23
24
  services;
25
+ isShuttingDown = false;
24
26
  static startedAt;
25
27
  constructor(settings) {
26
28
  super();
@@ -102,18 +104,47 @@ class Exodus extends _managed.default {
102
104
  return Exodus.startedAt;
103
105
  }
104
106
 
107
+ //# Exit
108
+ onExit(code) {
109
+ super.onExit(code);
110
+ (0, _process.exit)(code);
111
+ }
112
+
113
+ //# SIGNAL HANDLERS
114
+ onSIGTERM(signal) {
115
+ super.onSIGTERM(signal);
116
+ this.log('Recebido SIGTERM. Iniciando graceful shutdown...', 'comment');
117
+ this.log('Processo encerrado pelo sistema', 'especial');
118
+ this.gracefulShutdown('SIGTERM');
119
+ }
120
+ onSIGINT(signal) {
121
+ super.onSIGINT(signal);
122
+ this.log('Recebido SIGINT (Ctrl+C). Iniciando graceful shutdown...', 'comment');
123
+ this.log('Processo encerrado pelo usuário', 'especial');
124
+ this.gracefulShutdown('SIGINT');
125
+ }
126
+ onSIGUSR2(signal) {
127
+ super.onSIGUSR2(signal);
128
+ this.log('Recebido SIGUSR2. Iniciando graceful shutdown...', 'especial');
129
+ this.gracefulShutdown('SIGUSR2');
130
+ }
131
+
105
132
  //# UNCAUGHT EXCEPTION
106
133
  onClusterUncaughtException(err) {
107
134
  const msg = `Uma excessão ocorreu no cluster: ${err.message}`;
108
135
  this.log(msg, 'danger');
109
136
  (0, _logger2.default)().fatal(err, msg);
110
- throw err;
137
+
138
+ // Inicia graceful shutdown para cluster
139
+ this.gracefulShutdown('UNCAUGHT_EXCEPTION', err);
111
140
  }
112
141
  onMasterUncaughtException(err) {
113
142
  const msg = `Uma excessão ocorreu no master: ${err.message}`;
114
143
  this.log(msg, 'danger');
115
144
  (0, _logger2.default)().fatal(err, msg);
116
- throw err;
145
+
146
+ // Inicia graceful shutdown para master
147
+ this.gracefulShutdown('UNCAUGHT_EXCEPTION', err);
117
148
  }
118
149
 
119
150
  //# UNHANDLED REJECTION
@@ -124,6 +155,12 @@ class Exodus extends _managed.default {
124
155
  reason,
125
156
  promise
126
157
  }, msg);
158
+
159
+ // Para rejection críticas, também faz graceful shutdown
160
+ if (this.isCriticalRejection(reason)) {
161
+ this.log('Rejection crítica detectada. Iniciando graceful shutdown...', 'danger');
162
+ this.gracefulShutdown('CRITICAL_UNHANDLED_REJECTION', reason instanceof Error ? reason : new Error(String(reason)));
163
+ }
127
164
  }
128
165
  onMasterUnhandledRejection(reason, promise) {
129
166
  const msg = `Erro não tratado em uma promisse no master: ${reason}`;
@@ -132,6 +169,100 @@ class Exodus extends _managed.default {
132
169
  reason,
133
170
  promise
134
171
  }, msg);
172
+
173
+ // Para rejection críticas, também faz graceful shutdown
174
+ if (this.isCriticalRejection(reason)) {
175
+ this.log('Rejection crítica detectada. Iniciando graceful shutdown...', 'danger');
176
+ this.gracefulShutdown('CRITICAL_UNHANDLED_REJECTION', reason instanceof Error ? reason : new Error(String(reason)));
177
+ }
178
+ }
179
+
180
+ //# HELPER METHODS
181
+ isCriticalRejection(reason) {
182
+ if (!reason) return false;
183
+ const reasonStr = String(reason).toLowerCase();
184
+
185
+ // Lista de erros que consideramos críticos
186
+ const criticalPatterns = ['econnrefused', 'database connection', 'auth', 'permission denied', 'out of memory', 'disk space', 'network unreachable'];
187
+ return criticalPatterns.some(pattern => reasonStr.includes(pattern));
188
+ }
189
+ async shutdown(reason = 'MANUAL') {
190
+ return this.gracefulShutdown(reason);
191
+ }
192
+ async gracefulShutdown(reason, error) {
193
+ if (this.isShuttingDown) {
194
+ this.log('Shutdown já em andamento...', 'warning');
195
+ return;
196
+ }
197
+ this.isShuttingDown = true;
198
+ const startTime = Date.now();
199
+ this.log(`Iniciando graceful shutdown. Motivo: ${reason}`, 'warning');
200
+ try {
201
+ // Timeout para evitar shutdown infinito
202
+ const shutdownTimeout = setTimeout(() => {
203
+ this.log('Timeout no graceful shutdown. Forçando saída...', 'danger');
204
+ process.exit(1);
205
+ }, 30000); // 30 segundos
206
+
207
+ // Para serviços em ordem reversa
208
+ const reverseServices = [...this.services].reverse();
209
+ for (const service of reverseServices) {
210
+ try {
211
+ this.log(`Parando serviço: ${service.constructor.name}`, 'info');
212
+
213
+ // Se o serviço tem método de cleanup, chama ele
214
+ if (typeof service.onShutdown === 'function') {
215
+ await service.onShutdown();
216
+ }
217
+ this.log(`Serviço ${service.constructor.name} parado com sucesso`, 'info');
218
+ } catch (serviceError) {
219
+ this.log(`Erro ao parar serviço ${service.constructor.name}: ${serviceError.message}`, 'warning');
220
+ (0, _logger2.default)().error(serviceError, `Erro no shutdown do serviço ${service.constructor.name}`);
221
+ }
222
+ }
223
+
224
+ // Fecha conexões de cluster se for master
225
+ if (this.isMaster()) {
226
+ this.log('Encerrando clusters...', 'info');
227
+ _cluster.default.disconnect();
228
+
229
+ // Aguarda clusters fecharem graciosamente
230
+ await new Promise(resolve => {
231
+ const activeWorkers = Object.keys(_cluster.default.workers || {}).length;
232
+ if (activeWorkers === 0) {
233
+ resolve();
234
+ return;
235
+ }
236
+ const checkWorkers = setInterval(() => {
237
+ const currentWorkers = Object.keys(_cluster.default.workers || {}).length;
238
+ if (currentWorkers === 0) {
239
+ clearInterval(checkWorkers);
240
+ resolve();
241
+ }
242
+ }, 100);
243
+
244
+ // Timeout para workers
245
+ setTimeout(() => {
246
+ clearInterval(checkWorkers);
247
+ this.log('Timeout aguardando clusters. Forçando encerramento...', 'warning');
248
+ resolve();
249
+ }, 10000);
250
+ });
251
+ }
252
+ clearTimeout(shutdownTimeout);
253
+ const shutdownTime = Date.now() - startTime;
254
+ this.log(`Graceful shutdown concluído em ${shutdownTime}ms`, 'info');
255
+
256
+ // Log final do erro se existir
257
+ if (error) {
258
+ (0, _logger2.default)().fatal(error, `Aplicação encerrada devido a: ${reason}`);
259
+ }
260
+ process.exit(error ? 1 : 0);
261
+ } catch (shutdownError) {
262
+ this.log(`Erro durante graceful shutdown: ${shutdownError.message}`, 'danger');
263
+ (0, _logger2.default)().fatal(shutdownError, 'Erro crítico durante shutdown');
264
+ process.exit(1);
265
+ }
135
266
  }
136
267
  }
137
268
  var _default = exports.default = Exodus;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exodus-framework",
3
- "version": "2.1.01002",
3
+ "version": "2.1.1004",
4
4
  "description": "Exodus Framework",
5
5
  "author": "jhownpaixao",
6
6
  "license": "ISC",