zudello-integration-sdk 1.0.57 → 1.0.58

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.57",
3
+ "version": "1.0.58",
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 = {}, appendLimit = false }) {
21
+ async request({ url, method, qs = {}, body = {}}) {
22
22
  const validateIsEmpty = this.module.validator.isEmpty({ url, method });
23
23
 
24
24
  if (!validateIsEmpty.valid) {
@@ -53,54 +53,61 @@ class UniversalModule {
53
53
  }
54
54
 
55
55
  /**
56
- * Universal List By URL.
57
- * @param {number} offset Offset of listed data.
58
- * @param {number} limit Limit of listed data.
59
- * @param {string} query Query of listed data.
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.
60
61
  * @returns {object} Universal List Response.
61
62
  */
62
- async list({ after = "", limit = 100, query = "", variables = {} }) {
63
- return await this.request({
64
- method: "POST",
65
- body: {
66
- query,
67
- variables: {
68
- after,
69
- first: limit,
70
- ...variables,
71
- },
72
- },
73
- });
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 });
74
79
  }
75
80
 
76
81
  /**
77
- * Universal Auto Pagination Listing.
78
- * @param {number} offset Offset of listed data.
79
- * @param {number} limit Limit of listed data.
80
- * @param {string} query Query of listed data.
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.
81
87
  * @returns {object} Auto Pagination responses.
82
88
  */
83
- async *autoPaginationList({
84
- after = "",
85
- limit = 100,
86
- query = "",
87
- variables = {},
88
- pageInfoPath = "",
89
- }) {
90
- let response = await this.list({ after, limit, query, variables });
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;
91
100
 
92
101
  yield response;
93
102
 
94
- pageInfo = _.get(response, pageInfoPath);
95
- if (pageInfo.hasNextPage) {
96
- while (pageInfo.hasNextPage) {
97
- after = pageInfo.endCursor;
103
+ if (currentPageCount && currentPageCount === qs.pagesize) {
104
+ while (currentPageCount === qs.pagesize) {
105
+ qs.page = qs.page + 1;
98
106
 
99
- response = await this.list({ after, limit, query, variables });
107
+ response = await this.list({ url, method, qs, body });
108
+ currentPageCount = response?.data?.length;
100
109
 
101
110
  yield response;
102
-
103
- pageInfo = _.get(response, pageInfoPath);
104
111
  }
105
112
  }
106
113
  }