zudello-execute-local 1.0.16 → 1.0.18
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/index.js +178 -155
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,183 +1,203 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const yargs = require(
|
|
4
|
-
const dotenv = require(
|
|
5
|
-
const fs = require(
|
|
6
|
-
const path = require(
|
|
7
|
-
const { NodeVM, makeResolverFromLegacyOptions } = require(
|
|
3
|
+
const yargs = require("yargs");
|
|
4
|
+
const dotenv = require("dotenv");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const { NodeVM, makeResolverFromLegacyOptions } = require("vm2");
|
|
8
8
|
|
|
9
9
|
const argv = yargs
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
dotenv.config({ path: argv.env })
|
|
10
|
+
.option("script", {
|
|
11
|
+
alias: "s",
|
|
12
|
+
description: "Path to the script file",
|
|
13
|
+
type: "string",
|
|
14
|
+
demandOption: true,
|
|
15
|
+
})
|
|
16
|
+
.option("env", {
|
|
17
|
+
alias: "e",
|
|
18
|
+
description: "Path to the .env file",
|
|
19
|
+
type: "string",
|
|
20
|
+
demandOption: true,
|
|
21
|
+
})
|
|
22
|
+
.option("handlerName", {
|
|
23
|
+
alias: "hn",
|
|
24
|
+
description: "Handler function name",
|
|
25
|
+
type: "string",
|
|
26
|
+
default: "handle",
|
|
27
|
+
})
|
|
28
|
+
.option("data", {
|
|
29
|
+
alias: "d",
|
|
30
|
+
description:
|
|
31
|
+
"Provided data that are passed to the script handler function (should be in JSON format)",
|
|
32
|
+
type: "string",
|
|
33
|
+
default: "{}",
|
|
34
|
+
})
|
|
35
|
+
.help()
|
|
36
|
+
.alias("help", "h").argv;
|
|
37
|
+
|
|
38
|
+
dotenv.config({ path: argv.env });
|
|
39
39
|
|
|
40
40
|
const init = async () => {
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
let data = {};
|
|
42
|
+
let scriptContent = "";
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
console.log(argv);
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
try {
|
|
47
|
+
data = JSON.parse(argv.data);
|
|
48
|
+
} catch (err) {
|
|
49
|
+
console.error("Error: Invalid JSON provided in --data");
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
const scriptPath = path.resolve(argv.script);
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
try {
|
|
56
|
+
scriptContent = fs.readFileSync(scriptPath, "utf8");
|
|
57
|
+
} catch (err) {
|
|
58
|
+
console.error(`Error: Unable to read script file at ${scriptPath}`);
|
|
59
|
+
console.error(err.message);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
}
|
|
63
|
+
await runScript(argv.handlerName, scriptContent, data);
|
|
64
|
+
};
|
|
65
65
|
|
|
66
66
|
const initNodeVM = () => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
67
|
+
return new NodeVM({
|
|
68
|
+
console: "inherit",
|
|
69
|
+
sandbox: {
|
|
70
|
+
process,
|
|
71
|
+
},
|
|
72
|
+
require: makeResolverFromLegacyOptions({
|
|
73
|
+
external: {
|
|
74
|
+
modules: [
|
|
75
|
+
"lodash",
|
|
76
|
+
"performance-now",
|
|
77
|
+
"moment",
|
|
78
|
+
"moment-timezone",
|
|
79
|
+
"he",
|
|
80
|
+
"zudello-integration-sdk",
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
builtin: ["https"],
|
|
84
|
+
root: path.resolve(__dirname),
|
|
85
|
+
import: [
|
|
86
|
+
"lodash",
|
|
87
|
+
"performance-now",
|
|
88
|
+
"moment",
|
|
89
|
+
"moment-timezone",
|
|
90
|
+
"he",
|
|
91
|
+
"zudello-integration-sdk",
|
|
92
|
+
],
|
|
93
|
+
mock: {
|
|
94
|
+
fs: {
|
|
95
|
+
readFileSync() {
|
|
96
|
+
return "Nice try!";
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
}),
|
|
101
|
+
});
|
|
102
|
+
};
|
|
89
103
|
|
|
90
104
|
const runScript = async (handler, source, object) => {
|
|
91
|
-
|
|
105
|
+
const nodeVM = initNodeVM();
|
|
92
106
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
107
|
+
const authData = {
|
|
108
|
+
team_uuid: process.env.AUTH_TEAM_UUID,
|
|
109
|
+
jwt_token: process.env.AUTH_JWT_TOKEN,
|
|
110
|
+
organization_uuid: process.env.AUTH_ORGANIZATION_UUID,
|
|
111
|
+
api_url: process.env.AUTH_API_URL,
|
|
112
|
+
api_version: process.env.AUTH_API_VERSION,
|
|
113
|
+
external_api_url: process.env.AUTH_EXTERNAL_API_URL,
|
|
114
|
+
};
|
|
101
115
|
|
|
102
|
-
|
|
103
|
-
|
|
116
|
+
const externalIntegrationName = process.env.EXTERNAL_INTEGRATION_NAME;
|
|
117
|
+
const externalConnectionUUID = process.env.EXTERNAL_CONNECTION_UUID;
|
|
104
118
|
|
|
105
|
-
|
|
119
|
+
const triggerAuthenticate = `
|
|
106
120
|
const auth = new Auth({
|
|
107
121
|
teamUUID: '${authData.team_uuid}',
|
|
108
122
|
token: '${authData.jwt_token}'
|
|
109
123
|
})
|
|
110
124
|
await auth.authenticate()
|
|
111
|
-
|
|
125
|
+
`;
|
|
112
126
|
|
|
113
|
-
|
|
127
|
+
const triggerZudello = `
|
|
114
128
|
const Zudello = new ZudelloSDK(auth, '${authData.organization_uuid}', '${authData.api_url}', '${authData.api_version}', logger)
|
|
115
|
-
|
|
129
|
+
`;
|
|
116
130
|
|
|
117
|
-
|
|
131
|
+
let triggerExternal = "";
|
|
118
132
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
133
|
+
if (externalIntegrationName && externalConnectionUUID) {
|
|
134
|
+
switch (externalIntegrationName) {
|
|
135
|
+
case "netsuite":
|
|
136
|
+
triggerExternal = `
|
|
123
137
|
const Netsuite = new NetsuiteSDK(auth, '${externalConnectionUUID}', '${authData.organization_uuid}', '${authData.external_api_url}', '${authData.api_version}', logger)
|
|
124
138
|
const NetsuiteSOAP = new NetsuiteSoapSDK(auth, '${externalConnectionUUID}', '${authData.organization_uuid}', '${authData.external_api_url}', '${authData.api_version}', logger)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
139
|
+
`;
|
|
140
|
+
break;
|
|
141
|
+
case "intacct":
|
|
142
|
+
triggerExternal = `
|
|
129
143
|
const Intacct = new IntacctSDK(auth, '${externalConnectionUUID}', '${authData.organization_uuid}', '${authData.external_api_url}', '${authData.api_version}', logger)
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
144
|
+
`;
|
|
145
|
+
break;
|
|
146
|
+
case "bc":
|
|
147
|
+
triggerExternal = `
|
|
134
148
|
const BC = new BusinessCentralSDK(auth, '${externalConnectionUUID}', '${authData.organization_uuid}', '${authData.external_api_url}', '${authData.api_version}', logger)
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
149
|
+
`;
|
|
150
|
+
break;
|
|
151
|
+
case "zenoti":
|
|
152
|
+
triggerExternal = `
|
|
139
153
|
const Zenoti = new ZenotiSDK(auth, '${externalConnectionUUID}', '${authData.organization_uuid}', '${authData.external_api_url}', '${authData.api_version}', logger)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
154
|
+
`;
|
|
155
|
+
break;
|
|
156
|
+
case "dear":
|
|
157
|
+
triggerExternal = `
|
|
144
158
|
const Dear = new DearSDK(auth, '${externalConnectionUUID}', '${authData.organization_uuid}', '${authData.external_api_url}', '${authData.api_version}', logger)
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
159
|
+
`;
|
|
160
|
+
break;
|
|
161
|
+
case "nexvia":
|
|
162
|
+
triggerExternal = `
|
|
149
163
|
const Nexvia = new NexviaSDK(auth, '${externalConnectionUUID}', '${authData.organization_uuid}', '${authData.external_api_url}', '${authData.api_version}', logger)
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
164
|
+
`;
|
|
165
|
+
break;
|
|
166
|
+
case "fo":
|
|
167
|
+
triggerExternal = `
|
|
154
168
|
const FO = new FoSDK(auth, '${externalConnectionUUID}', '${authData.organization_uuid}', '${authData.external_api_url}', '${authData.api_version}', logger)
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
169
|
+
`;
|
|
170
|
+
break;
|
|
171
|
+
case "retailExpress":
|
|
172
|
+
triggerExternal = `
|
|
159
173
|
const RetailExpress = new RetailExpressSDK(auth, '${externalConnectionUUID}', '${authData.organization_uuid}', '${authData.external_api_url}', '${authData.api_version}', logger)
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
174
|
+
`;
|
|
175
|
+
break;
|
|
176
|
+
case "myobAcumatica":
|
|
177
|
+
triggerExternal = `
|
|
164
178
|
const MYOBAcumatica = new MYOBAcumaticaSDK(auth, '${externalConnectionUUID}', '${authData.organization_uuid}', '${authData.external_api_url}', '${authData.api_version}', logger)
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
179
|
+
`;
|
|
180
|
+
break;
|
|
181
|
+
case "sybiz":
|
|
182
|
+
triggerExternal = `
|
|
169
183
|
const Sybiz = new SybizSDK(auth, '${externalConnectionUUID}', '${authData.organization_uuid}', '${authData.external_api_url}', '${authData.api_version}', logger)
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
184
|
+
`;
|
|
185
|
+
break;
|
|
186
|
+
case "xero":
|
|
187
|
+
triggerExternal = `
|
|
188
|
+
const Xero = new XeroSDK(auth, '${externalConnectionUUID}', '${authData.organization_uuid}', '${authData.external_api_url}', '${authData.api_version}', logger)
|
|
189
|
+
`;
|
|
190
|
+
break;
|
|
191
|
+
case "jobready":
|
|
192
|
+
triggerExternal = `
|
|
174
193
|
const JobReady = new JobReadySDK(auth, '${externalConnectionUUID}', '${authData.organization_uuid}', '${authData.external_api_url}', '${authData.api_version}', logger)
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
194
|
+
`;
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
179
198
|
|
|
180
|
-
|
|
199
|
+
let scriptFunction = nodeVM.run(
|
|
200
|
+
`module.exports = async function(callback) {
|
|
181
201
|
try {
|
|
182
202
|
const {
|
|
183
203
|
Auth,
|
|
@@ -193,6 +213,7 @@ const runScript = async (handler, source, object) => {
|
|
|
193
213
|
RetailExpressSDK,
|
|
194
214
|
MYOBAcumaticaSDK,
|
|
195
215
|
SybizSDK,
|
|
216
|
+
XeroSDK,
|
|
196
217
|
JobReadySDK,
|
|
197
218
|
Logger,
|
|
198
219
|
Metadata,
|
|
@@ -264,18 +285,20 @@ const runScript = async (handler, source, object) => {
|
|
|
264
285
|
} catch (error) {
|
|
265
286
|
callback(error)
|
|
266
287
|
}
|
|
267
|
-
}`,
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
|
|
288
|
+
}`,
|
|
289
|
+
path.resolve(__dirname, "index.js")
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
return new Promise((resolve, reject) => {
|
|
293
|
+
scriptFunction((err, response) => {
|
|
294
|
+
if (err) {
|
|
295
|
+
console.error(err);
|
|
296
|
+
reject(new Error(`Error executing script: ${err.message}`));
|
|
297
|
+
} else {
|
|
298
|
+
resolve(response);
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
init();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zudello-execute-local",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.18",
|
|
4
4
|
"description": "Zudello Execute tool for local runs",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -20,6 +20,6 @@
|
|
|
20
20
|
"performance-now": "^2.1.0",
|
|
21
21
|
"vm2": "^3.9.19",
|
|
22
22
|
"yargs": "^17.7.2",
|
|
23
|
-
"zudello-integration-sdk": "^1.0.
|
|
23
|
+
"zudello-integration-sdk": "^1.0.17"
|
|
24
24
|
}
|
|
25
25
|
}
|