zudello-integration-sdk 1.0.58 → 1.0.59

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