zudello-integration-sdk 1.0.72 → 1.0.74
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,12 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
class UniversalModule {
|
|
4
4
|
/**
|
|
5
5
|
* Constructor.
|
|
6
6
|
* @param {class} parentModule Object of MSSQL class.
|
|
7
7
|
*/
|
|
8
|
-
constructor
|
|
9
|
-
this.module = parentModule
|
|
8
|
+
constructor(parentModule) {
|
|
9
|
+
this.module = parentModule;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -15,27 +15,92 @@ class UniversalModule {
|
|
|
15
15
|
* @param {string} queryParams Query .
|
|
16
16
|
* @returns {object} Universal Request Response.
|
|
17
17
|
*/
|
|
18
|
-
async query
|
|
19
|
-
const validateIsEmpty = this.module.validator.isEmpty({ sql })
|
|
18
|
+
async query({ sql, queryParams = {} }) {
|
|
19
|
+
const validateIsEmpty = this.module.validator.isEmpty({ sql });
|
|
20
20
|
|
|
21
21
|
if (!validateIsEmpty.valid) {
|
|
22
|
-
return this.module.responseHandler.error(validateIsEmpty.errors)
|
|
22
|
+
return this.module.responseHandler.error(validateIsEmpty.errors);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const mappableParams = {
|
|
26
26
|
sql: {
|
|
27
|
-
value:
|
|
27
|
+
value: sql,
|
|
28
28
|
},
|
|
29
29
|
queryParams: {
|
|
30
30
|
isMap: true,
|
|
31
|
-
value: JSON.stringify(queryParams)
|
|
31
|
+
value: JSON.stringify(queryParams),
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return await this.module.makeRequest(
|
|
36
|
+
"POST",
|
|
37
|
+
`${this.module.apiURL}/zintegrations/action/d133d755-a201-4e43-8ac1-2f124074e357`,
|
|
38
|
+
{
|
|
39
|
+
mappable_parameters: mappableParams,
|
|
32
40
|
}
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Execute cursor-based paginated query (recommended for large datasets).
|
|
46
|
+
* @param {string} sql Base SQL Query with WHERE clause.
|
|
47
|
+
* @param {object} options Cursor options: { cursorField, cursorValue, limit, orderBy }.
|
|
48
|
+
* @param {object} queryParams Query parameters.
|
|
49
|
+
* @returns {object} Cursor-based query response.
|
|
50
|
+
*/
|
|
51
|
+
async cursorQuery({ sql, options = {}, queryParams = {} }) {
|
|
52
|
+
const { cursorField, cursorValue, limit = 100, orderBy } = options;
|
|
53
|
+
|
|
54
|
+
const validateIsEmpty = this.module.validator.isEmpty({ sql, cursorField });
|
|
55
|
+
|
|
56
|
+
if (!validateIsEmpty.valid) {
|
|
57
|
+
return this.module.responseHandler.error(validateIsEmpty.errors);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let cursorSql = sql;
|
|
61
|
+
|
|
62
|
+
if (cursorField && cursorValue) {
|
|
63
|
+
const whereClause = sql.toLowerCase().includes("where") ? "AND" : "WHERE";
|
|
64
|
+
cursorSql += ` ${whereClause} ${cursorField} > '${cursorValue}'`;
|
|
33
65
|
}
|
|
34
66
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
})
|
|
67
|
+
if (orderBy) cursorSql += ` ORDER BY ${orderBy}`;
|
|
68
|
+
|
|
69
|
+
cursorSql = cursorSql.replace(/^SELECT/i, `SELECT TOP ${limit}`);
|
|
70
|
+
|
|
71
|
+
return await this.query({ sql: cursorSql, queryParams });
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Auto-pagination generator using cursor-based pagination (recommended).
|
|
76
|
+
* @param {string} sql Base SQL Query.
|
|
77
|
+
* @param {object} options Cursor options: { cursorField, limit, orderBy }.
|
|
78
|
+
* @param {object} queryParams Query parameters.
|
|
79
|
+
* @returns {AsyncGenerator} Yields cursor-based responses.
|
|
80
|
+
*/
|
|
81
|
+
async *autoCursorQuery({ sql, options = {}, queryParams = {} }) {
|
|
82
|
+
const { cursorField, limit = 100, orderBy } = options;
|
|
83
|
+
|
|
84
|
+
let cursorValue = null;
|
|
85
|
+
let hasMoreData = true;
|
|
86
|
+
|
|
87
|
+
while (hasMoreData) {
|
|
88
|
+
const response = await this.cursorQuery({
|
|
89
|
+
sql,
|
|
90
|
+
options: { cursorField, cursorValue, limit, orderBy },
|
|
91
|
+
queryParams,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
yield response;
|
|
95
|
+
|
|
96
|
+
const records = response?.data?.recordset || [];
|
|
97
|
+
if (records.length > 0 && cursorField) {
|
|
98
|
+
cursorValue = records[records.length - 1][cursorField];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
hasMoreData = records.length === limit;
|
|
102
|
+
}
|
|
38
103
|
}
|
|
39
104
|
}
|
|
40
105
|
|
|
41
|
-
module.exports = UniversalModule
|
|
106
|
+
module.exports = UniversalModule;
|