zudello-integration-sdk 1.0.66 → 1.0.68

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.66",
3
+ "version": "1.0.68",
4
4
  "description": "Zudello Integrations SDK",
5
5
  "main": "./src/index.js",
6
6
  "repository": {
package/src/index.js CHANGED
@@ -22,6 +22,7 @@ const JobReadySDK = require('./sdk/JobReady')
22
22
  const JobReadyLiveSDK = require('./sdk/JobReadyLive')
23
23
  const InspHireSDK = require('./sdk/InspHire')
24
24
  const S4SDK = require('./sdk/S4')
25
+ const AirwallexSDK = require('./sdk/Airwallex')
25
26
  const X3SDK = require('./sdk/X3')
26
27
  const SAPB1SDK = require('./sdk/SAPB1')
27
28
  const GPSDK = require('./sdk/GP')
@@ -99,6 +100,7 @@ module.exports = {
99
100
  JobReadyLiveSDK,
100
101
  InspHireSDK,
101
102
  S4SDK,
103
+ AirwallexSDK,
102
104
  Logger,
103
105
  Metadata,
104
106
  Message,
@@ -0,0 +1,31 @@
1
+ 'use strict'
2
+
3
+ const BaseSDK = require('./Base')
4
+ const UniversalModule = require('./submodules/airwallex/Universal')
5
+
6
+ class AirwallexSDK extends BaseSDK {
7
+ /**
8
+ * Constructor.
9
+ * @param {class} auth Auth class object with authorized api instance.
10
+ * @param {string} connectionUUID The UUID of the Connection we're working on.
11
+ */
12
+ constructor (auth, connectionUUID, organizationUUID, apiURL, apiVersion, loggerClass = null) {
13
+ super({
14
+ auth,
15
+ connectionUUID,
16
+ organizationUUID,
17
+ apiURL,
18
+ apiVersion,
19
+ appUUIDKey: 'airwallex',
20
+ integrationName: 'Airwallex',
21
+ loggerClass
22
+ })
23
+
24
+ /**
25
+ * Create submodule instances.
26
+ */
27
+ this.universal = new UniversalModule(this)
28
+ }
29
+ }
30
+
31
+ module.exports = AirwallexSDK
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+
3
+ class UniversalModule {
4
+ /**
5
+ * Constructor.
6
+ * @param {class} parentModule Object of Airwallex 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
+ const mappableParameters = {
28
+ url: {
29
+ value: url,
30
+ },
31
+ method: {
32
+ value: method,
33
+ },
34
+ qs: {
35
+ isMap: true,
36
+ value: JSON.stringify(qs),
37
+ },
38
+ };
39
+
40
+ if (Object.keys(body).length > 0) {
41
+ mappableParameters.body = {
42
+ isMap: true,
43
+ value: JSON.stringify(body),
44
+ };
45
+ }
46
+
47
+ return await this.module.makeRequest(
48
+ "POST",
49
+ `${this.module.apiURL}/zintegrations/action/42819921-298d-4bb8-838d-1aff425aad83`,
50
+ {
51
+ mappable_parameters: mappableParameters,
52
+ }
53
+ );
54
+ }
55
+
56
+ /**
57
+ * Universal List By URL and Method.
58
+ * @param {string} url URL of listed data.
59
+ * @param {string} method Method of listed data.
60
+ * @param {object} qs Some available filters inside: page_num, page_size.
61
+ * @param {object} body Some available data inside.
62
+ * @returns {object} Universal List Response.
63
+ */
64
+ async list({ url, method, qs = {}, body = {} }) {
65
+ const validateIsEmpty = this.module.validator.isEmpty({ url, method });
66
+
67
+ if (!validateIsEmpty.valid) {
68
+ return this.module.responseHandler.error(validateIsEmpty.errors);
69
+ }
70
+
71
+ if (!qs.page_num && qs.page_num !== 0) {
72
+ qs.page_num = 0;
73
+ }
74
+
75
+ if (!qs.page_size) {
76
+ qs.page_size = 200;
77
+ }
78
+
79
+ return await this.request({ url, method, qs, body });
80
+ }
81
+
82
+ /**
83
+ * Universal Auto Pagination Listing By URL and Method (Airwallex optimized).
84
+ * @param {string} url URL of listed data.
85
+ * @param {string} method Method of listed data.
86
+ * @param {object} qs Some available filters inside: page_num, page_size.
87
+ * @param {object} body Some available data inside.
88
+ * @returns {object} Auto Pagination responses.
89
+ */
90
+ async *autoPaginationList({ url, method, qs = {}, body = {} }) {
91
+ if (!qs.page_num && qs.page_num !== 0) {
92
+ qs.page_num = 0;
93
+ }
94
+
95
+ if (!qs.page_size) {
96
+ qs.page_size = 200;
97
+ }
98
+
99
+ let response = await this.list({ url, method, qs, body });
100
+
101
+ yield response;
102
+
103
+ let hasMore =
104
+ response?.has_more ||
105
+ response?.data?.has_more ||
106
+ response?.response?.has_more ||
107
+ false;
108
+
109
+ while (hasMore) {
110
+ qs.page_num = qs.page_num + 1;
111
+
112
+ response = await this.list({ url, method, qs, body });
113
+
114
+ yield response;
115
+
116
+ hasMore =
117
+ response?.has_more ||
118
+ response?.data?.has_more ||
119
+ response?.response?.has_more ||
120
+ false;
121
+ }
122
+ }
123
+ }
124
+
125
+ module.exports = UniversalModule;
@@ -0,0 +1,63 @@
1
+ 'use strict'
2
+
3
+ class PaymentModule {
4
+ /**
5
+ * Constructor.
6
+ * @param {class} parentModule Object of ZudelloV3 class.
7
+ */
8
+ constructor (parentModule) {
9
+ this.module = parentModule
10
+
11
+ this.staticFields = {
12
+ model: 'Transaction',
13
+ module: 'EXPENSES',
14
+ submodule: 'PAYMENT',
15
+ documentType: 'PAYMENT',
16
+ enrich: false,
17
+ extractedEvent: false,
18
+ update: true,
19
+ create: true
20
+ }
21
+ }
22
+
23
+ async fetch ({ uuid, fetchDetails = true, simplified = true }) {
24
+ const validateIsEmpty = this.module.validator.isEmpty({ uuid })
25
+
26
+ if (!validateIsEmpty.valid) {
27
+ return this.module.responseHandler.error(validateIsEmpty.errors)
28
+ }
29
+
30
+ return await this.module.fetch({
31
+ model: this.staticFields.model,
32
+ uuid,
33
+ fetchDetails,
34
+ simplified
35
+ })
36
+ }
37
+
38
+ async updateOrCreate ({ data, clearNulls = true, simplified = false, submit = false, updateStatus = false }) {
39
+ const validateIsEmpty = this.module.validator.isEmpty({ data })
40
+
41
+ if (!validateIsEmpty.valid) {
42
+ return this.module.responseHandler.error(validateIsEmpty.errors)
43
+ }
44
+
45
+ this.module.logger.log(`[UPDATE OR CREATE]: ZudelloV3 [model - ${this.staticFields.model}]`)
46
+ this.module.logger.log('[PAGE DATA]:')
47
+ this.module.logger.log(data)
48
+
49
+ data = this.module.mapUpdateOrCreateData({
50
+ data,
51
+ staticFields: this.staticFields,
52
+ submit,
53
+ updateStatus
54
+ })
55
+
56
+ this.module.logger.log('[MAPPED PAGE DATA]:')
57
+ this.module.logger.log(data)
58
+
59
+ return await this.module.updateOrCreate({ data, clearNulls, simplified })
60
+ }
61
+ }
62
+
63
+ module.exports = PaymentModule
@@ -0,0 +1,63 @@
1
+ 'use strict'
2
+
3
+ class RefundModule {
4
+ /**
5
+ * Constructor.
6
+ * @param {class} parentModule Object of ZudelloV3 class.
7
+ */
8
+ constructor (parentModule) {
9
+ this.module = parentModule
10
+
11
+ this.staticFields = {
12
+ model: 'Transaction',
13
+ module: 'EXPENSES',
14
+ submodule: 'REFUND',
15
+ documentType: 'REFUND',
16
+ enrich: false,
17
+ extractedEvent: false,
18
+ update: true,
19
+ create: true
20
+ }
21
+ }
22
+
23
+ async fetch ({ uuid, fetchDetails = true, simplified = true }) {
24
+ const validateIsEmpty = this.module.validator.isEmpty({ uuid })
25
+
26
+ if (!validateIsEmpty.valid) {
27
+ return this.module.responseHandler.error(validateIsEmpty.errors)
28
+ }
29
+
30
+ return await this.module.fetch({
31
+ model: this.staticFields.model,
32
+ uuid,
33
+ fetchDetails,
34
+ simplified
35
+ })
36
+ }
37
+
38
+ async updateOrCreate ({ data, clearNulls = true, simplified = false, submit = false, updateStatus = false }) {
39
+ const validateIsEmpty = this.module.validator.isEmpty({ data })
40
+
41
+ if (!validateIsEmpty.valid) {
42
+ return this.module.responseHandler.error(validateIsEmpty.errors)
43
+ }
44
+
45
+ this.module.logger.log(`[UPDATE OR CREATE]: ZudelloV3 [model - ${this.staticFields.model}]`)
46
+ this.module.logger.log('[PAGE DATA]:')
47
+ this.module.logger.log(data)
48
+
49
+ data = this.module.mapUpdateOrCreateData({
50
+ data,
51
+ staticFields: this.staticFields,
52
+ submit,
53
+ updateStatus
54
+ })
55
+
56
+ this.module.logger.log('[MAPPED PAGE DATA]:')
57
+ this.module.logger.log(data)
58
+
59
+ return await this.module.updateOrCreate({ data, clearNulls, simplified })
60
+ }
61
+ }
62
+
63
+ module.exports = RefundModule