zudello-integration-sdk 1.0.85 → 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.85",
3
+ "version": "1.0.87",
4
4
  "description": "Zudello Integrations SDK",
5
5
  "main": "./src/index.js",
6
6
  "repository": {
package/src/index.js CHANGED
@@ -49,6 +49,8 @@ const DatasetHelper = require('./utils/datasetHelper')
49
49
  const FormHelper = require('./utils/formHelper')
50
50
  const ResponseHelper = require('./utils/responseHelper')
51
51
  const Context = require('./utils/context')
52
+ const GlobalState = require('./utils/globalState')
53
+ const ResumePayload = require('./utils/resumePayload')
52
54
  const {
53
55
  getFileContent,
54
56
  uploadFile,
@@ -116,5 +118,7 @@ module.exports = {
116
118
  FormHelper,
117
119
  ResponseHelper,
118
120
  Context,
121
+ GlobalState,
122
+ ResumePayload,
119
123
  S3Client,
120
124
  }
package/src/sdk/SFTP.js CHANGED
@@ -3,7 +3,7 @@
3
3
  const BaseSDK = require('./Base')
4
4
  const UniversalModule = require('./submodules/sftp/Universal')
5
5
 
6
- class SharepointSDK extends BaseSDK {
6
+ class SFTPSDK extends BaseSDK {
7
7
  /**
8
8
  * Constructor.
9
9
  * @param {string} connectionUUID The UUID of the Connection we're working on.
@@ -22,4 +22,4 @@ class SharepointSDK extends BaseSDK {
22
22
  }
23
23
  }
24
24
 
25
- module.exports = SharepointSDK
25
+ module.exports = SFTPSDK
@@ -93,7 +93,7 @@ class UniversalModule {
93
93
  }
94
94
 
95
95
  let response = await this.list({ url, method, header, qs, body });
96
- let currentPageCount = response?.data?.length;
96
+ let currentPageCount = response?.data?.data?.length || 0;
97
97
 
98
98
  yield response;
99
99
 
@@ -102,7 +102,7 @@ class UniversalModule {
102
102
  qs.page = qs.page + 1;
103
103
 
104
104
  response = await this.list({ url, method, header, qs, body });
105
- currentPageCount = response?.data?.length;
105
+ currentPageCount = response?.data?.data?.length || 0;
106
106
 
107
107
  yield response;
108
108
  }
@@ -77,12 +77,12 @@ class UniversalModule {
77
77
  /**
78
78
  * Auto-pagination generator using cursor-based pagination (recommended).
79
79
  * @param {string} sql Base SQL Query.
80
- * @param {object} options Cursor options: { cursorField, limit, orderBy }.
80
+ * @param {object} options Cursor options: { cursorField, cursorFieldAlias, limit, orderBy }.
81
81
  * @param {object} queryParams Query parameters.
82
82
  * @returns {AsyncGenerator} Yields cursor-based responses.
83
83
  */
84
84
  async *autoCursorQuery({ sql, options = {}, queryParams = {} }) {
85
- const { cursorField, limit = 100, orderBy } = options;
85
+ const { cursorField, cursorFieldAlias, limit = 100, orderBy } = options;
86
86
 
87
87
  let cursorValue = null;
88
88
  let hasMoreData = true;
@@ -98,7 +98,8 @@ class UniversalModule {
98
98
 
99
99
  const records = response?.data || [];
100
100
  if (records.length > 0 && cursorField) {
101
- cursorValue = records[records.length - 1][cursorField];
101
+ const fieldToExtract = cursorFieldAlias || cursorField;
102
+ cursorValue = records[records.length - 1][fieldToExtract];
102
103
  }
103
104
 
104
105
  hasMoreData = records.length === limit;
@@ -36,16 +36,22 @@ module.exports = {
36
36
  AUTH_API_URL: process.env.AUTH_API_URL,
37
37
  ORGANIZATION_UUID: process.env.ORGANIZATION_UUID,
38
38
  TEAM_UUID: process.env.TEAM_UUID,
39
+ TRIGGER_UUID: process.env.TRIGGER_UUID,
39
40
  EXECUTION_UUID: process.env.EXECUTION_UUID,
40
41
  MODE: process.env.MODE,
41
- CONTEXT_DATA: process.env.CONTEXT_DATA,
42
42
 
43
43
  // GLOBAL ENVS
44
44
  ZUDELLO_API_URL: process.env.ZUDELLO_API_URL,
45
+ PAUSE_PROCESS_EXIT_CODE: process.env.PAUSE_PROCESS_EXIT_CODE,
45
46
 
46
47
  // AWS ENVS
47
48
  AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID,
48
49
  AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY,
49
- AWS_REGION: process.env.AWS_REGION
50
+ AWS_REGION: process.env.AWS_REGION,
51
+ AWS_BUCKET: process.env.AWS_BUCKET,
52
+
53
+ CONTEXT_DATA: process.env.CONTEXT_DATA,
54
+ GLOBAL_STATE: process.env.GLOBAL_STATE,
55
+ RESUME_PAYLOAD: process.env.RESUME_PAYLOAD,
50
56
  }
51
57
  }
@@ -0,0 +1,63 @@
1
+ 'use strict'
2
+
3
+ const ApiInstance = require('./apiInstance')
4
+ const config = require('./config')
5
+
6
+ class GlobalState {
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 () {
22
+ try {
23
+ this.globalState = JSON.parse(config.envs.GLOBAL_STATE || '{}')
24
+ } catch (err) {
25
+ this.globalState = {}
26
+ }
27
+ }
28
+
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)
44
+ }
45
+
46
+ pause () {
47
+ process.exitCode = config.envs.PAUSE_PROCESS_EXIT_CODE
48
+ }
49
+
50
+ async sync () {
51
+ if (this._synced) {
52
+ return
53
+ }
54
+
55
+ return await this.apiInstance.post(`${config.envs.ZUDELLO_API_URL}/execution/state/${config.envs.EXECUTION_UUID}`, {
56
+ global_state: this.globalState
57
+ }, {
58
+ 'x-team': config.envs.TEAM_UUID
59
+ })
60
+ }
61
+ }
62
+
63
+ module.exports = GlobalState
@@ -1,6 +1,8 @@
1
1
  'use strict'
2
2
 
3
3
  const config = require('./config')
4
+ const GlobalState = require('./globalState')
5
+ const { appendJsonArray } = require('./s3Client')
4
6
 
5
7
  class Logger {
6
8
  /**
@@ -10,6 +12,26 @@ class Logger {
10
12
  this.mode = config.envs.MODE || 'PRODUCTION'
11
13
  this.productionMode = 'PRODUCTION'
12
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)
13
35
  }
14
36
 
15
37
  /**
@@ -127,6 +149,15 @@ class Logger {
127
149
  setLogs(logs = []) {
128
150
  this.logs = logs
129
151
  }
152
+
153
+ async sync() {
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())
160
+ }
130
161
  }
131
162
 
132
163
  module.exports = Logger
@@ -1,5 +1,8 @@
1
1
  'use strict'
2
2
 
3
+ const ApiInstance = require('./apiInstance')
4
+ const config = require('./config')
5
+
3
6
  /**
4
7
  * Metadata class to handle operations on metadata and global metadata.
5
8
  * This class provides methods to get, set, and delete metadata properties.
@@ -11,9 +14,34 @@ class Metadata {
11
14
  * @param {Array} metadata - Array of metadata objects (each object should have `property` and `value`).
12
15
  * @param {Array} globalMetadata - Array of global metadata objects (each object should have `property` and `value`).
13
16
  */
14
- constructor(metadata = [], globalMetadata = []) {
17
+ constructor(connectionUUID = null, metadata = [], globalMetadata = []) {
18
+ this.apiInstance = new ApiInstance()
19
+
20
+ this.connectionUUID = connectionUUID
21
+
15
22
  this.metadata = metadata
16
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)
17
45
  }
18
46
 
19
47
  /**
@@ -108,6 +136,21 @@ class Metadata {
108
136
  this.metadata = this.metadata.filter(obj => obj.property !== key)
109
137
  }
110
138
  }
139
+
140
+ async sync() {
141
+ if (this._synced) {
142
+ return
143
+ }
144
+
145
+ return await this.apiInstance.post(`${config.envs.ZUDELLO_API_URL}/trigger/metadata/sync`, {
146
+ metas: this.getAll(),
147
+ connection_uuid: this.connectionUUID,
148
+ trigger_uuid: config.envs.TRIGGER_UUID,
149
+ team_uuid: config.envs.TEAM_UUID
150
+ }, {
151
+ 'x-team': config.envs.TEAM_UUID
152
+ })
153
+ }
111
154
  }
112
155
 
113
156
  module.exports = Metadata
@@ -0,0 +1,15 @@
1
+ 'use strict'
2
+
3
+ const config = require('./config')
4
+
5
+ class ResumePayload {
6
+ static load () {
7
+ try {
8
+ return JSON.parse(config.envs.RESUME_PAYLOAD || '{}')
9
+ } catch (err) {
10
+ return {}
11
+ }
12
+ }
13
+ }
14
+
15
+ module.exports = ResumePayload
package/src/utils/tags.js CHANGED
@@ -1,5 +1,8 @@
1
1
  'use strict'
2
2
 
3
+ const config = require('./config')
4
+ const ApiInstance = require('./apiInstance')
5
+
3
6
  /**
4
7
  * Class representing a collection of tags.
5
8
  */
@@ -10,6 +13,27 @@ class Tags {
10
13
  */
11
14
  constructor(tags = []) {
12
15
  this.tags = tags
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)
13
37
  }
14
38
 
15
39
  /**
@@ -35,6 +59,18 @@ class Tags {
35
59
  setAll(tags = []) {
36
60
  this.tags = tags
37
61
  }
62
+
63
+ async sync() {
64
+ if (this._synced) {
65
+ return
66
+ }
67
+
68
+ return await this.apiInstance.post(`${config.envs.ZUDELLO_API_URL}/execution/tags/${config.envs.EXECUTION_UUID}`, {
69
+ tags: this.getAll()
70
+ }, {
71
+ 'x-team': config.envs.TEAM_UUID
72
+ })
73
+ }
38
74
  }
39
75
 
40
76
  module.exports = Tags