zudello-integration-sdk 1.0.20 → 1.0.21

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.20",
3
+ "version": "1.0.21",
4
4
  "description": "Zudello Integrations SDK",
5
5
  "main": "./src/index.js",
6
6
  "repository": {
@@ -1,108 +1,112 @@
1
- 'use strict'
1
+ "use strict";
2
2
 
3
3
  class UniversalModule {
4
- /**
5
- * Constructor.
6
- * @param {class} parentModule Object of Sybiz class.
7
- */
8
- constructor (parentModule) {
9
- this.module = parentModule
10
- }
11
-
12
- /**
13
- * Universal Request By URL and Method.
14
- * @param {string} url URL of request.
15
- * @param {string} method Method of request.
16
- * @param {object} qs Some available filters inside: offset, limit.
17
- * @param {object} body Some available data inside.
18
- * @returns {object} Universal Request Response.
19
- */
20
- async request ({ url, method, qs = {}, body = {} }) {
21
- const validateIsEmpty = this.module.validator.isEmpty({ url, method })
22
-
23
- if (!validateIsEmpty.valid) {
24
- return this.module.responseHandler.error(validateIsEmpty.errors)
25
- }
26
-
27
- return await this.module.makeRequest('POST', `${this.module.apiURL}/zintegrations/action/37e52a1d-aa46-4f9c-9931-bd651e5081f2`, {
28
- mappable_parameters: {
29
- url: {
30
- value: url
31
- },
32
- method: {
33
- value: method
34
- },
35
- qs: {
36
- isMap: true,
37
- value: JSON.stringify(qs)
38
- },
39
- body: {
40
- isMap: true,
41
- value: JSON.stringify(body)
42
- }
43
- }
44
- })
45
- }
46
-
47
- /**
48
- * Universal List By URL and Method.
49
- * @param {string} url URL of listed data.
50
- * @param {string} method Method of listed data.
51
- * @param {object} qs Some available filters inside: Page, Limit.
52
- * @param {object} body Some available data inside.
53
- * @returns {object} Universal List Response.
54
- */
55
- async list ({ url, method, qs = {}, body = {} }) {
56
- const validateIsEmpty = this.module.validator.isEmpty({ url, method })
57
-
58
- if (!validateIsEmpty.valid) {
59
- return this.module.responseHandler.error(validateIsEmpty.errors)
60
- }
61
-
62
- if (!qs.page) {
63
- qs.page = 1
64
- }
65
-
66
- if (!qs.pagesize) {
67
- qs.pagesize = 100
68
- }
69
-
70
- return await this.request({ url, method, qs, body })
71
- }
72
-
73
- /**
74
- * Universal Auto Pagination Listing By URL and Method.
75
- * @param {string} url URL of listed data.
76
- * @param {string} method Method of listed data.
77
- * @param {object} qs Some available filters inside: Page, Limit.
78
- * @param {object} body Some available data inside.
79
- * @returns {object} Auto Pagination responses.
80
- */
81
- async * autoPaginationList ({ url, method, qs = {}, body = {} }) {
82
- if (!qs.page) {
83
- qs.page = 1
84
- }
85
-
86
- if (!qs.pagesize) {
87
- qs.pagesize = 100
88
- }
89
-
90
- let response = await this.list({ url, method, qs, body })
91
- let currentPageCount = response?.data?.length
92
-
93
- yield response
94
-
95
- if (currentPageCount && currentPageCount === qs.limit) {
96
- while (currentPageCount === qs.limit) {
97
- qs.page = qs.page + 1
98
-
99
- response = await this.list({ url, method, qs, body })
100
- currentPageCount = response?.data?.length
101
-
102
- yield response
103
- }
104
- }
105
- }
4
+ /**
5
+ * Constructor.
6
+ * @param {class} parentModule Object of Sybiz class.
7
+ */
8
+ constructor(parentModule) {
9
+ this.module = parentModule;
10
+ }
11
+
12
+ /**
13
+ * Universal Request By URL and Method.
14
+ * @param {string} url URL of request.
15
+ * @param {string} method Method of request.
16
+ * @param {object} qs Some available filters inside: offset, limit.
17
+ * @param {object} body Some available data inside.
18
+ * @returns {object} Universal Request Response.
19
+ */
20
+ async request({ url, method, qs = {}, body = {} }) {
21
+ const validateIsEmpty = this.module.validator.isEmpty({ url, method });
22
+
23
+ if (!validateIsEmpty.valid) {
24
+ return this.module.responseHandler.error(validateIsEmpty.errors);
25
+ }
26
+
27
+ return await this.module.makeRequest(
28
+ "POST",
29
+ `${this.module.apiURL}/zintegrations/action/37e52a1d-aa46-4f9c-9931-bd651e5081f2`,
30
+ {
31
+ mappable_parameters: {
32
+ url: {
33
+ value: url,
34
+ },
35
+ method: {
36
+ value: method,
37
+ },
38
+ qs: {
39
+ isMap: true,
40
+ value: JSON.stringify(qs),
41
+ },
42
+ body: {
43
+ isMap: true,
44
+ value: JSON.stringify(body),
45
+ },
46
+ },
47
+ }
48
+ );
49
+ }
50
+
51
+ /**
52
+ * Universal List By URL and Method.
53
+ * @param {string} url URL of listed data.
54
+ * @param {string} method Method of listed data.
55
+ * @param {object} qs Some available filters inside: Page, Limit.
56
+ * @param {object} body Some available data inside.
57
+ * @returns {object} Universal List Response.
58
+ */
59
+ async list({ url, method, qs = {}, body = {} }) {
60
+ const validateIsEmpty = this.module.validator.isEmpty({ url, method });
61
+
62
+ if (!validateIsEmpty.valid) {
63
+ return this.module.responseHandler.error(validateIsEmpty.errors);
64
+ }
65
+
66
+ if (!qs.page) {
67
+ qs.page = 1;
68
+ }
69
+
70
+ if (!qs.pagesize) {
71
+ qs.pagesize = 100;
72
+ }
73
+
74
+ return await this.request({ url, method, qs, body });
75
+ }
76
+
77
+ /**
78
+ * Universal Auto Pagination Listing By URL and Method.
79
+ * @param {string} url URL of listed data.
80
+ * @param {string} method Method of listed data.
81
+ * @param {object} qs Some available filters inside: Page, Limit.
82
+ * @param {object} body Some available data inside.
83
+ * @returns {object} Auto Pagination responses.
84
+ */
85
+ async *autoPaginationList({ url, method, qs = {}, body = {} }) {
86
+ if (!qs.page) {
87
+ qs.page = 1;
88
+ }
89
+
90
+ if (!qs.pagesize) {
91
+ qs.pagesize = 100;
92
+ }
93
+
94
+ let response = await this.list({ url, method, qs, body });
95
+ let currentPageCount = response?.data?.length;
96
+
97
+ yield response;
98
+
99
+ if (currentPageCount && currentPageCount === qs.pagesize) {
100
+ while (currentPageCount === qs.pagesize) {
101
+ qs.page = qs.page + 1;
102
+
103
+ response = await this.list({ url, method, qs, body });
104
+ currentPageCount = response?.data?.length;
105
+
106
+ yield response;
107
+ }
108
+ }
109
+ }
106
110
  }
107
111
 
108
- module.exports = UniversalModule
112
+ module.exports = UniversalModule;