zudello-integration-sdk 1.0.85 → 1.0.86

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.86",
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,31 @@
1
+ 'use strict'
2
+
3
+ const ApiInstance = require('./apiInstance')
4
+ const config = require('./config')
5
+
6
+ class GlobalState {
7
+ static load () {
8
+ try {
9
+ return JSON.parse(config.envs.GLOBAL_STATE || '{}')
10
+ } catch (err) {
11
+ return {}
12
+ }
13
+ }
14
+
15
+ static async pause (globalState = {}) {
16
+ await this.sync(globalState)
17
+ process.exit(config.envs.PAUSE_PROCESS_EXIT_CODE)
18
+ }
19
+
20
+ static async sync (globalState = {}) {
21
+ const apiInstance = new ApiInstance()
22
+
23
+ return await apiInstance.post(`${config.envs.ZUDELLO_API_URL}/execution/state/${config.envs.EXECUTION_UUID}`, {
24
+ global_state: globalState
25
+ }, {
26
+ 'x-team': config.envs.TEAM_UUID
27
+ })
28
+ }
29
+ }
30
+
31
+ 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
  /**
@@ -127,6 +129,11 @@ class Logger {
127
129
  setLogs(logs = []) {
128
130
  this.logs = logs
129
131
  }
132
+
133
+ async sync() {
134
+ const globalState = GlobalState.load()
135
+ await appendJsonArray(config.envs.AWS_BUCKET, globalState.logFilePath, this.getLogs())
136
+ }
130
137
  }
131
138
 
132
139
  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,7 +14,11 @@ 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
17
24
  }
@@ -108,6 +115,17 @@ class Metadata {
108
115
  this.metadata = this.metadata.filter(obj => obj.property !== key)
109
116
  }
110
117
  }
118
+
119
+ async sync() {
120
+ return await this.apiInstance.post(`${config.envs.ZUDELLO_API_URL}/trigger/metadata/sync`, {
121
+ metas: this.getAll(),
122
+ connection_uuid: this.connectionUUID,
123
+ trigger_uuid: config.envs.TRIGGER_UUID,
124
+ team_uuid: config.envs.TEAM_UUID
125
+ }, {
126
+ 'x-team': config.envs.TEAM_UUID
127
+ })
128
+ }
111
129
  }
112
130
 
113
131
  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,7 @@
1
1
  'use strict'
2
2
 
3
+ const ApiInstance = require('./apiInstance')
4
+
3
5
  /**
4
6
  * Class representing a collection of tags.
5
7
  */
@@ -10,6 +12,7 @@ class Tags {
10
12
  */
11
13
  constructor(tags = []) {
12
14
  this.tags = tags
15
+ this.apiInstance = new ApiInstance()
13
16
  }
14
17
 
15
18
  /**
@@ -35,6 +38,14 @@ class Tags {
35
38
  setAll(tags = []) {
36
39
  this.tags = tags
37
40
  }
41
+
42
+ async sync() {
43
+ return await this.apiInstance.post(`${config.envs.ZUDELLO_API_URL}/execution/tags/${config.envs.EXECUTION_UUID}`, {
44
+ tags: this.getAll()
45
+ }, {
46
+ 'x-team': config.envs.TEAM_UUID
47
+ })
48
+ }
38
49
  }
39
50
 
40
51
  module.exports = Tags