zudello-integration-sdk 1.0.86 → 1.0.87

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.87",
4
4
  "description": "Zudello Integrations SDK",
5
5
  "main": "./src/index.js",
6
6
  "repository": {
@@ -4,24 +4,56 @@ 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
+ _loadState () {
8
22
  try {
9
- return JSON.parse(config.envs.GLOBAL_STATE || '{}')
23
+ this.globalState = JSON.parse(config.envs.GLOBAL_STATE || '{}')
10
24
  } catch (err) {
11
- return {}
25
+ this.globalState = {}
12
26
  }
13
27
  }
14
28
 
15
- static async pause (globalState = {}) {
16
- await this.sync(globalState)
17
- process.exit(config.envs.PAUSE_PROCESS_EXIT_CODE)
29
+ _registerAutoSync () {
30
+ const syncOnExit = async () => {
31
+ if (this._synced) {
32
+ return
33
+ }
34
+
35
+ try {
36
+ await this.sync()
37
+ this._synced = true
38
+ } catch (err) {
39
+ console.error('Failed to sync global state on exit:', err)
40
+ }
41
+ }
42
+
43
+ process.on('beforeExit', syncOnExit)
18
44
  }
19
45
 
20
- static async sync (globalState = {}) {
21
- const apiInstance = new ApiInstance()
46
+ pause () {
47
+ process.exitCode = config.envs.PAUSE_PROCESS_EXIT_CODE
48
+ }
49
+
50
+ async sync () {
51
+ if (this._synced) {
52
+ return
53
+ }
22
54
 
23
- return await apiInstance.post(`${config.envs.ZUDELLO_API_URL}/execution/state/${config.envs.EXECUTION_UUID}`, {
24
- global_state: globalState
55
+ return await this.apiInstance.post(`${config.envs.ZUDELLO_API_URL}/execution/state/${config.envs.EXECUTION_UUID}`, {
56
+ global_state: this.globalState
25
57
  }, {
26
58
  'x-team': config.envs.TEAM_UUID
27
59
  })
@@ -12,6 +12,26 @@ 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
+ _registerAutoSync() {
21
+ const syncOnExit = async () => {
22
+ if (this._synced) {
23
+ return
24
+ }
25
+
26
+ try {
27
+ await this.sync()
28
+ this._synced = true
29
+ } catch (err) {
30
+ console.error('Failed to sync logs on exit:', err)
31
+ }
32
+ }
33
+
34
+ process.on('beforeExit', syncOnExit)
15
35
  }
16
36
 
17
37
  /**
@@ -131,8 +151,12 @@ class Logger {
131
151
  }
132
152
 
133
153
  async sync() {
134
- const globalState = GlobalState.load()
135
- await appendJsonArray(config.envs.AWS_BUCKET, globalState.logFilePath, this.getLogs())
154
+ if (this._synced) {
155
+ return
156
+ }
157
+
158
+ const globalStateClass = new GlobalState()
159
+ await appendJsonArray(config.envs.AWS_BUCKET, globalStateClass.globalState.logFilePath, this.getLogs())
136
160
  }
137
161
  }
138
162
 
@@ -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,
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
  }, {