zudello-integration-sdk 1.0.58 → 1.0.60
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,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
const _ = require("lodash");
|
|
4
|
+
|
|
3
5
|
class UniversalModule {
|
|
4
6
|
/**
|
|
5
7
|
* Constructor.
|
|
@@ -18,7 +20,7 @@ class UniversalModule {
|
|
|
18
20
|
* @param {boolean} appendLimit Append limit & offset to URL.
|
|
19
21
|
* @returns {object} Universal Request Response.
|
|
20
22
|
*/
|
|
21
|
-
async request({ url, method, qs = {}, body = {}}) {
|
|
23
|
+
async request({ url, method, qs = {}, body = {}, appendLimit = false }) {
|
|
22
24
|
const validateIsEmpty = this.module.validator.isEmpty({ url, method });
|
|
23
25
|
|
|
24
26
|
if (!validateIsEmpty.valid) {
|
|
@@ -53,64 +55,66 @@ class UniversalModule {
|
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
/**
|
|
56
|
-
* Universal List By URL
|
|
57
|
-
* @param {string} url URL of
|
|
58
|
-
* @param {string}
|
|
59
|
-
* @param {
|
|
60
|
-
* @param {
|
|
58
|
+
* Universal List By URL.
|
|
59
|
+
* @param {string} url URL of the request.
|
|
60
|
+
* @param {string} after Cursor for pagination.
|
|
61
|
+
* @param {number} limit Limit of listed data.
|
|
62
|
+
* @param {string} query Query of listed data.
|
|
63
|
+
* @param {object} variables Additional variables for the query.
|
|
61
64
|
* @returns {object} Universal List Response.
|
|
62
65
|
*/
|
|
63
|
-
async list({ url,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return await this.request({ url, method, qs, body });
|
|
66
|
+
async list({ url, after = "", limit = 100, query = "", variables = {} }) {
|
|
67
|
+
return await this.request({
|
|
68
|
+
url,
|
|
69
|
+
method: "POST",
|
|
70
|
+
body: {
|
|
71
|
+
query,
|
|
72
|
+
variables: {
|
|
73
|
+
after,
|
|
74
|
+
first: limit,
|
|
75
|
+
...variables,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
|
-
* Universal Auto Pagination Listing
|
|
83
|
-
* @param {string} url URL of
|
|
84
|
-
* @param {string}
|
|
85
|
-
* @param {
|
|
86
|
-
* @param {
|
|
87
|
-
* @
|
|
82
|
+
* Universal Auto Pagination Listing.
|
|
83
|
+
* @param {string} url URL of the request.
|
|
84
|
+
* @param {string} after Cursor for pagination.
|
|
85
|
+
* @param {number} limit Limit of listed data.
|
|
86
|
+
* @param {string} query Query of listed data.
|
|
87
|
+
* @param {object} variables Additional variables for the query.
|
|
88
|
+
* @param {string} pageInfoPath Path to pageInfo in the response (e.g., "data.users.pageInfo").
|
|
89
|
+
* @returns {AsyncGenerator} Auto Pagination responses.
|
|
88
90
|
*/
|
|
89
|
-
async *autoPaginationList({
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
let response = await this.list({ url, method, qs, body });
|
|
99
|
-
let currentPageCount = response?.data?.length;
|
|
100
|
-
|
|
91
|
+
async *autoPaginationList({
|
|
92
|
+
url,
|
|
93
|
+
after = "",
|
|
94
|
+
limit = 100,
|
|
95
|
+
query = "",
|
|
96
|
+
variables = {},
|
|
97
|
+
pageInfoPath = "",
|
|
98
|
+
}) {
|
|
99
|
+
let response = await this.list({ url, after, limit, query, variables });
|
|
101
100
|
yield response;
|
|
102
101
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
response = await this.list({ url, method, qs, body });
|
|
108
|
-
currentPageCount = response?.data?.length;
|
|
102
|
+
let pageInfo = _.get(response, pageInfoPath);
|
|
103
|
+
if (pageInfo && pageInfo.hasNextPage) {
|
|
104
|
+
while (pageInfo.hasNextPage) {
|
|
105
|
+
after = pageInfo.endCursor;
|
|
109
106
|
|
|
107
|
+
response = await this.list({ url, after, limit, query, variables });
|
|
110
108
|
yield response;
|
|
109
|
+
|
|
110
|
+
pageInfo = _.get(response, pageInfoPath);
|
|
111
|
+
|
|
112
|
+
if (!pageInfo) {
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
111
115
|
}
|
|
112
116
|
}
|
|
113
117
|
}
|
|
114
118
|
}
|
|
115
119
|
|
|
116
|
-
module.exports = UniversalModule;
|
|
120
|
+
module.exports = UniversalModule;
|