zudello-integration-sdk 1.0.86 → 1.0.88

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zudello-integration-sdk",
3
- "version": "1.0.86",
3
+ "version": "1.0.88",
4
4
  "description": "Zudello Integrations SDK",
5
5
  "main": "./src/index.js",
6
6
  "repository": {
package/src/sdk/Base.js CHANGED
@@ -28,7 +28,7 @@ class BaseSDK {
28
28
  this.apiInstance = new ApiInstance()
29
29
  this.validator = new Validator()
30
30
  this.responseHandler = new ResponseHandler()
31
- this.logger = new Logger()
31
+ this.logger = Logger.init()
32
32
 
33
33
  this.organizationUUID = config.envs.ORGANIZATION_UUID
34
34
  this.teamUUID = config.envs.TEAM_UUID
@@ -7,7 +7,7 @@ const Logger = require('./logger')
7
7
  class DatasetHelper {
8
8
  constructor(data = null, uuid = null) {
9
9
  this.zudello = new Zudello()
10
- this.logger = new Logger()
10
+ this.logger = Logger.init()
11
11
 
12
12
  this.data = data
13
13
  this.uuid = uuid
@@ -8,7 +8,7 @@ const config = require('./config')
8
8
  class FormHelper {
9
9
  constructor(data) {
10
10
  this.apiInstance = new ApiInstance()
11
- this.logger = new Logger()
11
+ this.logger = Logger.init()
12
12
 
13
13
  this.teamUUID = config.envs.TEAM_UUID
14
14
  this.apiURL = config.envs.ZUDELLO_API_URL
@@ -4,24 +4,64 @@ const ApiInstance = require('./apiInstance')
4
4
  const config = require('./config')
5
5
 
6
6
  class GlobalState {
7
- static load () {
7
+ /**
8
+ * Constructor.
9
+ */
10
+ constructor() {
11
+ this.apiInstance = new ApiInstance()
12
+
13
+ this.globalState = {}
14
+
15
+ this._synced = false
16
+
17
+ this._loadState()
18
+ this._registerAutoSync()
19
+ }
20
+
21
+ static init() {
22
+ if (!GlobalState._instance) {
23
+ GlobalState._instance = new GlobalState()
24
+ }
25
+
26
+ return GlobalState._instance
27
+ }
28
+
29
+ _loadState () {
8
30
  try {
9
- return JSON.parse(config.envs.GLOBAL_STATE || '{}')
31
+ this.globalState = JSON.parse(config.envs.GLOBAL_STATE || '{}')
10
32
  } catch (err) {
11
- return {}
33
+ this.globalState = {}
12
34
  }
13
35
  }
14
36
 
15
- static async pause (globalState = {}) {
16
- await this.sync(globalState)
17
- process.exit(config.envs.PAUSE_PROCESS_EXIT_CODE)
37
+ _registerAutoSync () {
38
+ const syncOnExit = async () => {
39
+ if (this._synced) {
40
+ return
41
+ }
42
+
43
+ try {
44
+ await this.sync()
45
+ this._synced = true
46
+ } catch (err) {
47
+ console.error('Failed to sync global state on exit:', err)
48
+ }
49
+ }
50
+
51
+ process.on('beforeExit', syncOnExit)
18
52
  }
19
53
 
20
- static async sync (globalState = {}) {
21
- const apiInstance = new ApiInstance()
54
+ pause () {
55
+ process.exitCode = config.envs.PAUSE_PROCESS_EXIT_CODE
56
+ }
57
+
58
+ async sync () {
59
+ if (this._synced) {
60
+ return
61
+ }
22
62
 
23
- return await apiInstance.post(`${config.envs.ZUDELLO_API_URL}/execution/state/${config.envs.EXECUTION_UUID}`, {
24
- global_state: globalState
63
+ return await this.apiInstance.post(`${config.envs.ZUDELLO_API_URL}/execution/state/${config.envs.EXECUTION_UUID}`, {
64
+ global_state: this.globalState
25
65
  }, {
26
66
  'x-team': config.envs.TEAM_UUID
27
67
  })
@@ -12,6 +12,34 @@ class Logger {
12
12
  this.mode = config.envs.MODE || 'PRODUCTION'
13
13
  this.productionMode = 'PRODUCTION'
14
14
  this.logs = []
15
+ this._synced = false
16
+
17
+ this._registerAutoSync()
18
+ }
19
+
20
+ static init() {
21
+ if (!Logger._instance) {
22
+ Logger._instance = new Logger()
23
+ }
24
+
25
+ return Logger._instance
26
+ }
27
+
28
+ _registerAutoSync() {
29
+ const syncOnExit = async () => {
30
+ if (this._synced) {
31
+ return
32
+ }
33
+
34
+ try {
35
+ await this.sync()
36
+ this._synced = true
37
+ } catch (err) {
38
+ console.error('Failed to sync logs on exit:', err)
39
+ }
40
+ }
41
+
42
+ process.on('beforeExit', syncOnExit)
15
43
  }
16
44
 
17
45
  /**
@@ -131,8 +159,12 @@ class Logger {
131
159
  }
132
160
 
133
161
  async sync() {
134
- const globalState = GlobalState.load()
135
- await appendJsonArray(config.envs.AWS_BUCKET, globalState.logFilePath, this.getLogs())
162
+ if (this._synced) {
163
+ return
164
+ }
165
+
166
+ const globalStateClass = GlobalState.init()
167
+ await appendJsonArray(config.envs.AWS_BUCKET, globalStateClass.globalState.logFilePath, this.getLogs())
136
168
  }
137
169
  }
138
170
 
@@ -21,6 +21,27 @@ class Metadata {
21
21
 
22
22
  this.metadata = metadata
23
23
  this.globalMetadata = globalMetadata
24
+
25
+ this._synced = false
26
+
27
+ this._registerAutoSync()
28
+ }
29
+
30
+ _registerAutoSync() {
31
+ const syncOnExit = async () => {
32
+ if (this._synced) {
33
+ return
34
+ }
35
+
36
+ try {
37
+ await this.sync()
38
+ this._synced = true
39
+ } catch (err) {
40
+ console.error('Failed to sync metadata on exit:', err)
41
+ }
42
+ }
43
+
44
+ process.on('beforeExit', syncOnExit)
24
45
  }
25
46
 
26
47
  /**
@@ -117,6 +138,10 @@ class Metadata {
117
138
  }
118
139
 
119
140
  async sync() {
141
+ if (this._synced) {
142
+ return
143
+ }
144
+
120
145
  return await this.apiInstance.post(`${config.envs.ZUDELLO_API_URL}/trigger/metadata/sync`, {
121
146
  metas: this.getAll(),
122
147
  connection_uuid: this.connectionUUID,
@@ -7,7 +7,7 @@ const Logger = require('./logger')
7
7
  class ModelHelper {
8
8
  constructor(data = null, model = null, uuid = null) {
9
9
  this.zudello = new Zudello()
10
- this.logger = new Logger()
10
+ this.logger = Logger.init()
11
11
 
12
12
  this.modelData = data
13
13
  this.model = model
@@ -8,7 +8,7 @@ const config = require('./config')
8
8
  class ResponseHelper {
9
9
  constructor(data) {
10
10
  this.apiInstance = new ApiInstance()
11
- this.logger = new Logger()
11
+ this.logger = Logger.init()
12
12
 
13
13
  this.teamUUID = config.envs.TEAM_UUID
14
14
  this.apiURL = config.envs.ZUDELLO_API_URL
package/src/utils/tags.js CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
 
3
+ const config = require('./config')
3
4
  const ApiInstance = require('./apiInstance')
4
5
 
5
6
  /**
@@ -13,6 +14,26 @@ class Tags {
13
14
  constructor(tags = []) {
14
15
  this.tags = tags
15
16
  this.apiInstance = new ApiInstance()
17
+ this._synced = false
18
+
19
+ this._registerAutoSync()
20
+ }
21
+
22
+ _registerAutoSync() {
23
+ const syncOnExit = async () => {
24
+ if (this._synced) {
25
+ return
26
+ }
27
+
28
+ try {
29
+ await this.sync()
30
+ this._synced = true
31
+ } catch (err) {
32
+ console.error('Failed to sync tags on exit:', err)
33
+ }
34
+ }
35
+
36
+ process.on('beforeExit', syncOnExit)
16
37
  }
17
38
 
18
39
  /**
@@ -40,6 +61,10 @@ class Tags {
40
61
  }
41
62
 
42
63
  async sync() {
64
+ if (this._synced) {
65
+ return
66
+ }
67
+
43
68
  return await this.apiInstance.post(`${config.envs.ZUDELLO_API_URL}/execution/tags/${config.envs.EXECUTION_UUID}`, {
44
69
  tags: this.getAll()
45
70
  }, {