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.
Files changed (2) hide show
  1. package/index.js +178 -155
  2. 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('yargs')
4
- const dotenv = require('dotenv')
5
- const fs = require('fs')
6
- const path = require('path')
7
- const { NodeVM, makeResolverFromLegacyOptions } = require('vm2')
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
- .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: 'Provided data that are passed to the script handler function (should be in JSON format)',
31
- type: 'string',
32
- default: '{}'
33
- })
34
- .help()
35
- .alias('help', 'h')
36
- .argv
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
- let data = {}
42
- let scriptContent = ''
41
+ let data = {};
42
+ let scriptContent = "";
43
43
 
44
- console.log(argv)
44
+ console.log(argv);
45
45
 
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
- }
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
- const scriptPath = path.resolve(argv.script)
53
+ const scriptPath = path.resolve(argv.script);
54
54
 
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
- }
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
- await runScript(argv.handlerName, scriptContent, data)
64
- }
63
+ await runScript(argv.handlerName, scriptContent, data);
64
+ };
65
65
 
66
66
  const initNodeVM = () => {
67
- return new NodeVM({
68
- console: 'inherit',
69
- sandbox: {
70
- process
71
- },
72
- require: makeResolverFromLegacyOptions({
73
- external: {
74
- modules: ['lodash', 'performance-now', 'moment', 'moment-timezone', 'he', 'zudello-integration-sdk']
75
- },
76
- builtin: ['https'],
77
- root: path.resolve(__dirname),
78
- import: ['lodash', 'performance-now', 'moment', 'moment-timezone', 'he', 'zudello-integration-sdk'],
79
- mock: {
80
- fs: {
81
- readFileSync() {
82
- return 'Nice try!'
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
- const nodeVM = initNodeVM()
105
+ const nodeVM = initNodeVM();
92
106
 
93
- const authData = {
94
- team_uuid: process.env.AUTH_TEAM_UUID,
95
- jwt_token: process.env.AUTH_JWT_TOKEN,
96
- organization_uuid: process.env.AUTH_ORGANIZATION_UUID,
97
- api_url: process.env.AUTH_API_URL,
98
- api_version: process.env.AUTH_API_VERSION,
99
- external_api_url: process.env.AUTH_EXTERNAL_API_URL
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
- const externalIntegrationName = process.env.EXTERNAL_INTEGRATION_NAME
103
- const externalConnectionUUID = process.env.EXTERNAL_CONNECTION_UUID
116
+ const externalIntegrationName = process.env.EXTERNAL_INTEGRATION_NAME;
117
+ const externalConnectionUUID = process.env.EXTERNAL_CONNECTION_UUID;
104
118
 
105
- const triggerAuthenticate = `
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
- const triggerZudello = `
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
- let triggerExternal = ''
131
+ let triggerExternal = "";
118
132
 
119
- if (externalIntegrationName && externalConnectionUUID) {
120
- switch (externalIntegrationName) {
121
- case 'netsuite':
122
- triggerExternal = `
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
- break
127
- case 'intacct':
128
- triggerExternal = `
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
- break
132
- case 'bc':
133
- triggerExternal = `
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
- break
137
- case 'zenoti':
138
- triggerExternal = `
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
- break
142
- case 'dear':
143
- triggerExternal = `
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
- break
147
- case 'nexvia':
148
- triggerExternal = `
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
- break
152
- case 'fo':
153
- triggerExternal = `
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
- break
157
- case 'retailExpress':
158
- triggerExternal = `
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
- break
162
- case 'myobAcumatica':
163
- triggerExternal = `
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
- break
167
- case 'sybiz':
168
- triggerExternal = `
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
- break
172
- case 'jobready':
173
- triggerExternal = `
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
- break
177
- }
178
- }
194
+ `;
195
+ break;
196
+ }
197
+ }
179
198
 
180
- let scriptFunction = nodeVM.run(`module.exports = async function(callback) {
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
- }`, path.resolve(__dirname, 'index.js'))
268
-
269
- return new Promise((resolve, reject) => {
270
- scriptFunction((err, response) => {
271
- if (err) {
272
- console.error(err)
273
- reject(new Error(`Error executing script: ${err.message}`))
274
- } else {
275
- resolve(response)
276
- }
277
- })
278
- })
279
- }
280
-
281
- init()
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.16",
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.15"
23
+ "zudello-integration-sdk": "^1.0.17"
24
24
  }
25
25
  }