zudello-integration-sdk 1.0.76 → 1.0.78

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.76",
3
+ "version": "1.0.78",
4
4
  "description": "Zudello Integrations SDK",
5
5
  "main": "./src/index.js",
6
6
  "repository": {
package/src/index.js CHANGED
@@ -23,6 +23,7 @@ const JobReadyLiveSDK = require('./sdk/JobReadyLive')
23
23
  const InspHireSDK = require('./sdk/InspHire')
24
24
  const S4SDK = require('./sdk/S4')
25
25
  const AirwallexSDK = require('./sdk/Airwallex')
26
+ const SkriptSDK = require('./sdk/Skript')
26
27
  const X3SDK = require('./sdk/X3')
27
28
  const SAPB1SDK = require('./sdk/SAPB1')
28
29
  const GPSDK = require('./sdk/GP')
@@ -103,6 +104,7 @@ module.exports = {
103
104
  InspHireSDK,
104
105
  S4SDK,
105
106
  AirwallexSDK,
107
+ SkriptSDK,
106
108
  Logger,
107
109
  Metadata,
108
110
  Message,
@@ -0,0 +1,31 @@
1
+ 'use strict'
2
+
3
+ const BaseSDK = require('./Base')
4
+ const UniversalModule = require('./submodules/skript/Universal')
5
+
6
+ class SkriptSDK 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: 'skript',
20
+ integrationName: 'Skript',
21
+ loggerClass
22
+ })
23
+
24
+ /**
25
+ * Create submodule instances.
26
+ */
27
+ this.universal = new UniversalModule(this)
28
+ }
29
+ }
30
+
31
+ module.exports = SkriptSDK
@@ -68,7 +68,7 @@ class UniversalModule {
68
68
  if (orderBy) cursorSql += ` ORDER BY ${orderBy}`;
69
69
 
70
70
  if (!cursorSql.toLowerCase().match(/select\s+(top\s+\d+|distinct)/i)) {
71
- cursorSql = cursorSql.replace(/^SELECT\s+/i, `SELECT TOP ${limit} `);
71
+ cursorSql = cursorSql.replace(/^\s*SELECT\s+/i, `SELECT TOP ${limit} `);
72
72
  }
73
73
 
74
74
  return await this.query({ sql: cursorSql, queryParams });
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+
3
+ class UniversalModule {
4
+ /**
5
+ * Constructor.
6
+ * @param {class} parentModule Object of InspHire 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: size, ref, filter, sort, fields.
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/092f7915-fd58-4f43-8e85-47a0135bc54d`,
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: size, ref, filter, sort, fields.
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.size) {
67
+ qs.size = 100;
68
+ }
69
+
70
+ return await this.request({ url, method, qs, body });
71
+ }
72
+
73
+ /**
74
+ * Extract pagination reference from Link header.
75
+ * @param {string} linkHeader The Link header from the response.
76
+ * @returns {string|null} The ref value for the next page, or null if no next page.
77
+ * @example
78
+ * // Input: <https://api.sandbox.skript.com.au/v1/consumers?size=1&ref=7b226c223a...>; rel="next"
79
+ * // Output: "7b226c223a..."
80
+ */
81
+ extractRefFromLinkHeader(linkHeader) {
82
+ if (!linkHeader) return null;
83
+ if (!linkHeader.includes('rel="next"')) return null;
84
+
85
+ const refMatch = linkHeader.match(/[?&]ref=([^&>\s]+)/);
86
+ if (!refMatch) return null;
87
+
88
+ return refMatch[1];
89
+ }
90
+
91
+ /**
92
+ * Universal Auto Pagination Listing By URL and Method.
93
+ * Uses link-based pagination with 'ref' parameter from Link headers.
94
+ * @param {string} url URL of listed data.
95
+ * @param {string} method Method of listed data.
96
+ * @param {object} qs Some available filters inside: size, filter, sort, fields.
97
+ * @param {object} body Some available data inside.
98
+ * @returns {object} Auto Pagination responses.
99
+ */
100
+ async *autoPaginationList({ url, method, qs = {}, body = {} }) {
101
+ const qsCopy = { ...qs };
102
+
103
+ if (!qsCopy.size) {
104
+ qsCopy.size = 100;
105
+ }
106
+
107
+ let response = await this.list({ url, method, qs: qsCopy, body });
108
+ yield response;
109
+
110
+ let nextRef = this.extractRefFromLinkHeader(response?.headers?.link);
111
+
112
+ while (nextRef) {
113
+ qsCopy.ref = nextRef;
114
+ response = await this.list({ url, method, qs: qsCopy, body });
115
+ yield response;
116
+ nextRef = this.extractRefFromLinkHeader(response?.headers?.link);
117
+ }
118
+ }
119
+ }
120
+
121
+ module.exports = UniversalModule;