@sasjs/cli 4.4.1 → 4.5.0

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.
@@ -82,7 +82,7 @@ var executeParseOptions = {
82
82
  type: 'boolean',
83
83
  alias: 'i',
84
84
  default: false,
85
- description: 'If present and return status only is provided, CLI will return status 0 when the job state is warning.'
85
+ description: 'If present, CLI will return status 0 when the job state is warning.'
86
86
  },
87
87
  log: {
88
88
  type: 'string',
@@ -94,6 +94,7 @@ var executeParseOptions = {
94
94
  alias: 'o',
95
95
  description: 'path where output of the finished job execution will be saved.'
96
96
  },
97
+ // returnStatusOnly flag is deprecated and is left to display warning if used
97
98
  returnStatusOnly: {
98
99
  type: 'boolean',
99
100
  default: false,
@@ -118,6 +119,12 @@ var executeParseOptions = {
118
119
  streamLog: {
119
120
  type: 'boolean',
120
121
  description: 'Flag indicating whether the logs should be streamed to a local file as the job executes.'
122
+ },
123
+ verbose: {
124
+ type: 'boolean',
125
+ alias: 'v',
126
+ default: false,
127
+ description: 'If present, CLI will return status 0, 1 or 2 together with HTTP response summaries.'
121
128
  }
122
129
  };
123
130
  var JobCommand = /** @class */ (function (_super) {
@@ -139,15 +146,25 @@ var JobCommand = /** @class */ (function (_super) {
139
146
  _this.jobSubCommands = jobSubCommands;
140
147
  return _this;
141
148
  }
149
+ /**
150
+ * Method responsible for command execution.
151
+ * @returns - promise that resolves into return code.
152
+ */
142
153
  JobCommand.prototype.execute = function () {
143
154
  var _a;
144
155
  return __awaiter(this, void 0, void 0, function () {
145
- var target, _b, _c, _d, _e;
156
+ var target, returnStatusOnly, _b, _c, _d, _e;
146
157
  return __generator(this, function (_f) {
147
158
  switch (_f.label) {
148
- case 0: return [4 /*yield*/, this.getTargetInfo()];
159
+ case 0: return [4 /*yield*/, this.getTargetInfo()
160
+ // returnStatusOnly flag is deprecated and is left to display warning if used
161
+ ];
149
162
  case 1:
150
163
  target = (_f.sent()).target;
164
+ returnStatusOnly = !!this.parsed.returnStatusOnly;
165
+ if (returnStatusOnly) {
166
+ process.logger.warn('--returnStatusOnly (-r) flag is deprecated.');
167
+ }
151
168
  _b = target.serverType;
152
169
  switch (_b) {
153
170
  case utils_1.ServerType.SasViya: return [3 /*break*/, 2];
@@ -194,6 +211,11 @@ var JobCommand = /** @class */ (function (_super) {
194
211
  });
195
212
  });
196
213
  };
214
+ /**
215
+ * Executes job on SASJS server.
216
+ * @param target - SASJS server configuration.
217
+ * @returns - promise that resolves into return code.
218
+ */
197
219
  JobCommand.prototype.executeJobSasjs = function (target) {
198
220
  var _a;
199
221
  return __awaiter(this, void 0, void 0, function () {
@@ -210,6 +232,7 @@ var JobCommand = /** @class */ (function (_super) {
210
232
  .then(function () { return command_1.ReturnCode.Success; })
211
233
  .catch(function (err) {
212
234
  var _a;
235
+ // handle job execution failure
213
236
  (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Error executing job: ', err);
214
237
  return command_1.ReturnCode.InternalError;
215
238
  })];
@@ -220,36 +243,41 @@ var JobCommand = /** @class */ (function (_super) {
220
243
  });
221
244
  });
222
245
  };
246
+ /**
247
+ * Executes job on SAS9 server.
248
+ * @param target - SAS9 server configuration.
249
+ * @returns - promise that resolves into return code.
250
+ */
223
251
  JobCommand.prototype.executeJobSas9 = function (target) {
224
252
  var _a;
225
253
  return __awaiter(this, void 0, void 0, function () {
226
- var jobPath, log, output, source, _b, sasjs, authConfigSas9, userName, password, returnCode;
254
+ var jobPath, log, source, output, _b, sasjs, authConfigSas9, userName, password, returnCode;
227
255
  return __generator(this, function (_c) {
228
256
  switch (_c.label) {
229
257
  case 0:
230
258
  jobPath = (0, prefixAppLoc_1.prefixAppLoc)(target.appLoc, this.parsed.jobPath);
231
259
  log = (0, getLogFilePath_1.getLogFilePath)(this.parsed.log, jobPath);
260
+ source = this.parsed.source;
232
261
  output = ((_a = this.parsed.output) === null || _a === void 0 ? void 0 : _a.length)
233
262
  ? this.parsed.output
234
263
  : undefined;
235
- source = this.parsed.source;
236
264
  return [4 /*yield*/, (0, utils_2.getSASjsAndAuthConfig)(target).catch(function (err) {
237
265
  var _a;
266
+ // handle getting instance of @sasjs/adapter and auth config failure
238
267
  (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Unable to execute job. Error fetching auth config: ', err);
239
- return { sasjs: (0, utils_2.getSASjs)(target), authConfigSas9: undefined };
268
+ return { sasjs: undefined, authConfigSas9: undefined };
240
269
  })];
241
270
  case 1:
242
271
  _b = _c.sent(), sasjs = _b.sasjs, authConfigSas9 = _b.authConfigSas9;
243
- if (!authConfigSas9)
272
+ if (!authConfigSas9 || !sasjs)
244
273
  return [2 /*return*/, command_1.ReturnCode.InternalError];
245
274
  userName = authConfigSas9.userName;
246
275
  password = (0, utils_1.decodeFromBase64)(authConfigSas9.password);
247
276
  return [4 /*yield*/, (0, execute_1.executeJobSas9)(sasjs, { userName: userName, password: password }, jobPath, log, output, source)
248
- .then(function () {
249
- return command_1.ReturnCode.Success;
250
- })
277
+ .then(function () { return command_1.ReturnCode.Success; })
251
278
  .catch(function (err) {
252
279
  var _a;
280
+ // handle job execution failure
253
281
  (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Error executing job: ', err);
254
282
  return command_1.ReturnCode.InternalError;
255
283
  })];
@@ -260,51 +288,53 @@ var JobCommand = /** @class */ (function (_super) {
260
288
  });
261
289
  });
262
290
  };
291
+ /**
292
+ * Executes job on Viya server.
293
+ * @param target - Viya server configuration.
294
+ * @returns - promise that resolves into return code.
295
+ */
263
296
  JobCommand.prototype.executeJobViya = function (target) {
264
- var _a, _b, _c;
297
+ var _a, _b;
265
298
  return __awaiter(this, void 0, void 0, function () {
266
- var jobPath, log, wait, output, statusFile, returnStatusOnly, ignoreWarnings, source, streamLog, _d, sasjs, authConfig, returnCode;
267
- return __generator(this, function (_e) {
268
- switch (_e.label) {
299
+ var jobPath, statusFile, log, ignoreWarnings, streamLog, verbose, source, wait, output, _c, sasjs, authConfig, returnCode;
300
+ return __generator(this, function (_d) {
301
+ switch (_d.label) {
269
302
  case 0:
270
303
  jobPath = (0, prefixAppLoc_1.prefixAppLoc)(target.appLoc, this.parsed.jobPath);
304
+ statusFile = getStatusFilePath(this.parsed.statusFile);
271
305
  log = (0, getLogFilePath_1.getLogFilePath)(this.parsed.log, jobPath);
306
+ ignoreWarnings = !!this.parsed.ignoreWarnings;
307
+ streamLog = !!this.parsed.streamLog;
308
+ verbose = !!this.parsed.verbose;
309
+ source = this.parsed.source;
272
310
  wait = this.parsed.wait || !!log;
273
311
  output = ((_a = this.parsed.output) === null || _a === void 0 ? void 0 : _a.length)
274
312
  ? this.parsed.output
275
313
  : ((_b = this.parsed.output) === null || _b === void 0 ? void 0 : _b.length) === 0
276
314
  ? true
277
315
  : false;
278
- statusFile = getStatusFilePath(this.parsed.statusFile);
279
- returnStatusOnly = !!this.parsed.returnStatusOnly;
280
- ignoreWarnings = !!this.parsed.ignoreWarnings;
281
- source = this.parsed.source;
282
- streamLog = !!this.parsed.streamLog;
283
- if (returnStatusOnly && !wait)
316
+ if (verbose && !wait)
284
317
  wait = true;
285
- if (ignoreWarnings && !returnStatusOnly) {
286
- (_c = process.logger) === null || _c === void 0 ? void 0 : _c.warn("Using the 'ignoreWarnings' flag without 'returnStatusOnly' flag will not affect the sasjs job execute command.");
287
- }
288
318
  return [4 /*yield*/, (0, utils_2.getSASjsAndAuthConfig)(target).catch(function (err) {
289
319
  var _a;
320
+ // handle getting instance of @sasjs/adapter and auth config failure
290
321
  (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Unable to execute job. Error fetching auth config: ', err);
291
- return { sasjs: (0, utils_2.getSASjs)(target), authConfig: undefined };
322
+ return { sasjs: undefined, authConfig: undefined };
292
323
  })];
293
324
  case 1:
294
- _d = _e.sent(), sasjs = _d.sasjs, authConfig = _d.authConfig;
295
- if (!authConfig)
325
+ _c = _d.sent(), sasjs = _c.sasjs, authConfig = _c.authConfig;
326
+ if (!authConfig || !sasjs)
296
327
  return [2 /*return*/, command_1.ReturnCode.InternalError];
297
- return [4 /*yield*/, (0, execute_1.executeJobViya)(sasjs, authConfig, jobPath, target, wait, output, log, statusFile, returnStatusOnly, ignoreWarnings, source, streamLog)
298
- .then(function () {
299
- return command_1.ReturnCode.Success;
300
- })
328
+ return [4 /*yield*/, (0, execute_1.executeJobViya)(sasjs, authConfig, jobPath, target, wait, output, log, statusFile, ignoreWarnings, source, streamLog, verbose)
329
+ .then(function () { return command_1.ReturnCode.Success; })
301
330
  .catch(function (err) {
302
331
  var _a;
332
+ // handle job execution failure
303
333
  (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Error executing job: ', err);
304
334
  return command_1.ReturnCode.InternalError;
305
335
  })];
306
336
  case 2:
307
- returnCode = _e.sent();
337
+ returnCode = _d.sent();
308
338
  return [2 /*return*/, returnCode];
309
339
  }
310
340
  });
@@ -313,6 +343,11 @@ var JobCommand = /** @class */ (function (_super) {
313
343
  return JobCommand;
314
344
  }(targetCommand_1.TargetCommand));
315
345
  exports.JobCommand = JobCommand;
346
+ /**
347
+ * Gets status file path.
348
+ * @param statusFileArg - file path provided as command attribute.
349
+ * @returns - absolute status file path or undefined if command attribute wasn't provided.
350
+ */
316
351
  var getStatusFilePath = function (statusFileArg) {
317
352
  if (statusFileArg) {
318
353
  var currentDirPath = path_1.default.isAbsolute(statusFileArg)
@@ -78,7 +78,6 @@ var target = new types_1.Target({
78
78
  appLoc: '/test',
79
79
  contextName: 'Mock Context'
80
80
  });
81
- var statusFile;
82
81
  describe('executeJobViya', function () {
83
82
  beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
84
83
  return __generator(this, function (_a) {
@@ -95,7 +94,7 @@ describe('executeJobViya', function () {
95
94
  it('should set streamLog to true when the flag is passed in', function () { return __awaiter(void 0, void 0, void 0, function () {
96
95
  return __generator(this, function (_a) {
97
96
  switch (_a.label) {
98
- case 0: return [4 /*yield*/, (0, execute_1.executeJobViya)(sasjs, mocks_1.mockAuthConfig, 'test/job', target, false, false, testLogsPath, testFilePath, false, false, undefined, true)];
97
+ case 0: return [4 /*yield*/, (0, execute_1.executeJobViya)(sasjs, mocks_1.mockAuthConfig, 'test/job', target, false, false, testLogsPath, testFilePath, false, undefined, true, false)];
99
98
  case 1:
100
99
  _a.sent();
101
100
  expect(sasjs.startComputeJob).toHaveBeenCalledWith('test/job', null, {
@@ -105,7 +104,7 @@ describe('executeJobViya', function () {
105
104
  pollInterval: 1000,
106
105
  streamLog: true,
107
106
  logFolderPath: testLogsPath
108
- }, true, undefined);
107
+ }, true, undefined, undefined);
109
108
  return [4 /*yield*/, (0, utils_1.deleteFile)(testFilePath)];
110
109
  case 2:
111
110
  _a.sent();
@@ -116,7 +115,7 @@ describe('executeJobViya', function () {
116
115
  it('should set streamLog to false when the flag is false', function () { return __awaiter(void 0, void 0, void 0, function () {
117
116
  return __generator(this, function (_a) {
118
117
  switch (_a.label) {
119
- case 0: return [4 /*yield*/, (0, execute_1.executeJobViya)(sasjs, mocks_1.mockAuthConfig, 'test/job', target, false, false, testLogsPath, testFilePath, false, false, undefined, false)];
118
+ case 0: return [4 /*yield*/, (0, execute_1.executeJobViya)(sasjs, mocks_1.mockAuthConfig, 'test/job', target, false, false, testLogsPath, testFilePath, false, undefined, false, false)];
120
119
  case 1:
121
120
  _a.sent();
122
121
  expect(sasjs.startComputeJob).toHaveBeenCalledWith('test/job', null, {
@@ -126,7 +125,52 @@ describe('executeJobViya', function () {
126
125
  pollInterval: 1000,
127
126
  streamLog: false,
128
127
  logFolderPath: testLogsPath
129
- }, true, undefined);
128
+ }, true, undefined, undefined);
129
+ return [4 /*yield*/, (0, utils_1.deleteFile)(testFilePath)];
130
+ case 2:
131
+ _a.sent();
132
+ return [2 /*return*/];
133
+ }
134
+ });
135
+ }); });
136
+ it('should pass verbose as undefined when the flag is false', function () { return __awaiter(void 0, void 0, void 0, function () {
137
+ return __generator(this, function (_a) {
138
+ switch (_a.label) {
139
+ case 0: return [4 /*yield*/, (0, execute_1.executeJobViya)(sasjs, mocks_1.mockAuthConfig, 'test/job', target, false, false, testLogsPath, testFilePath, false, undefined, false, false)];
140
+ case 1:
141
+ _a.sent();
142
+ expect(sasjs.startComputeJob).toHaveBeenCalledWith('test/job', null, {
143
+ contextName: 'Mock Context'
144
+ }, mocks_1.mockAuthConfig, true, {
145
+ maxPollCount: 24 * 60 * 60,
146
+ pollInterval: 1000,
147
+ streamLog: false,
148
+ logFolderPath: testLogsPath
149
+ }, true, undefined, undefined);
150
+ return [4 /*yield*/, (0, utils_1.deleteFile)(testFilePath)];
151
+ case 2:
152
+ _a.sent();
153
+ return [2 /*return*/];
154
+ }
155
+ });
156
+ }); });
157
+ it('should pass verbose as true when the flag is true', function () { return __awaiter(void 0, void 0, void 0, function () {
158
+ var verbose;
159
+ return __generator(this, function (_a) {
160
+ switch (_a.label) {
161
+ case 0:
162
+ verbose = true;
163
+ return [4 /*yield*/, (0, execute_1.executeJobViya)(sasjs, mocks_1.mockAuthConfig, 'test/job', target, false, false, testLogsPath, testFilePath, false, undefined, false, verbose)];
164
+ case 1:
165
+ _a.sent();
166
+ expect(sasjs.startComputeJob).toHaveBeenCalledWith('test/job', null, {
167
+ contextName: 'Mock Context'
168
+ }, mocks_1.mockAuthConfig, true, {
169
+ maxPollCount: 24 * 60 * 60,
170
+ pollInterval: 1000,
171
+ streamLog: false,
172
+ logFolderPath: testLogsPath
173
+ }, true, undefined, verbose);
130
174
  return [4 /*yield*/, (0, utils_1.deleteFile)(testFilePath)];
131
175
  case 2:
132
176
  _a.sent();
@@ -470,8 +470,7 @@ describe('sasjs job execute with Viya', function () {
470
470
  mockExit = (0, test_1.mockProcessExit)();
471
471
  return [4 /*yield*/, expect(executeWrapper({
472
472
  jobPath: 'jobs/testJob/job',
473
- waitForJob: true,
474
- returnStatusOnly: true
473
+ waitForJob: true
475
474
  })).toResolve()];
476
475
  case 1:
477
476
  _a.sent();
@@ -488,8 +487,7 @@ describe('sasjs job execute with Viya', function () {
488
487
  mockExit = (0, test_1.mockProcessExit)();
489
488
  return [4 /*yield*/, expect(executeWrapper({
490
489
  jobPath: 'jobs/testJob/jobWithWarning',
491
- waitForJob: true,
492
- returnStatusOnly: true
490
+ waitForJob: true
493
491
  })).toResolve()];
494
492
  case 1:
495
493
  _a.sent();
@@ -507,7 +505,6 @@ describe('sasjs job execute with Viya', function () {
507
505
  return [4 /*yield*/, expect(executeWrapper({
508
506
  jobPath: 'jobs/testJob/jobWithWarning',
509
507
  waitForJob: true,
510
- returnStatusOnly: true,
511
508
  ignoreWarnings: true
512
509
  })).toResolve()];
513
510
  case 1:
@@ -526,8 +523,7 @@ describe('sasjs job execute with Viya', function () {
526
523
  return [4 /*yield*/, expect(executeWrapper({
527
524
  jobPath: 'jobs/testJob/failingJob',
528
525
  waitForJob: true,
529
- logFile: path_1.default.join(process.projectDir, 'failingJob.log'),
530
- returnStatusOnly: true
526
+ logFile: path_1.default.join(process.projectDir, 'failingJob.log')
531
527
  })).toResolve()];
532
528
  case 1:
533
529
  _a.sent();
@@ -556,8 +552,7 @@ describe('sasjs job execute with Viya', function () {
556
552
  mockExit = (0, test_1.mockProcessExit)();
557
553
  return [4 /*yield*/, expect(executeWrapper({
558
554
  jobPath: 'jobs/testJob/failingJob_DOES_NOT_EXIST',
559
- waitForJob: true,
560
- returnStatusOnly: true
555
+ waitForJob: true
561
556
  })).toResolve()];
562
557
  case 1:
563
558
  _a.sent();
@@ -601,10 +596,10 @@ describe('sasjs job execute with Viya', function () {
601
596
  }); });
602
597
  });
603
598
  var executeWrapper = function (_a) {
604
- var _b = _a.adapter, adapter = _b === void 0 ? sasjs : _b, jobPath = _a.jobPath, _c = _a.waitForJob, waitForJob = _c === void 0 ? false : _c, _d = _a.output, output = _d === void 0 ? false : _d, _e = _a.logFile, logFile = _e === void 0 ? undefined : _e, _f = _a.statusFile, statusFile = _f === void 0 ? undefined : _f, _g = _a.returnStatusOnly, returnStatusOnly = _g === void 0 ? false : _g, _h = _a.ignoreWarnings, ignoreWarnings = _h === void 0 ? false : _h, _j = _a.source, source = _j === void 0 ? undefined : _j, _k = _a.streamLog, streamLog = _k === void 0 ? false : _k;
599
+ var _b = _a.adapter, adapter = _b === void 0 ? sasjs : _b, jobPath = _a.jobPath, _c = _a.waitForJob, waitForJob = _c === void 0 ? false : _c, _d = _a.output, output = _d === void 0 ? false : _d, _e = _a.logFile, logFile = _e === void 0 ? undefined : _e, _f = _a.statusFile, statusFile = _f === void 0 ? undefined : _f, _g = _a.ignoreWarnings, ignoreWarnings = _g === void 0 ? false : _g, _h = _a.source, source = _h === void 0 ? undefined : _h, _j = _a.streamLog, streamLog = _j === void 0 ? false : _j;
605
600
  return __awaiter(void 0, void 0, void 0, function () {
606
- return __generator(this, function (_l) {
607
- return [2 /*return*/, (0, execute_1.executeJobViya)(adapter, authConfig, jobPath, target, waitForJob, output, logFile, statusFile, returnStatusOnly, ignoreWarnings, source, streamLog)];
601
+ return __generator(this, function (_k) {
602
+ return [2 /*return*/, (0, execute_1.executeJobViya)(adapter, authConfig, jobPath, target, waitForJob, output, logFile, statusFile, ignoreWarnings, source, streamLog, false)];
608
603
  });
609
604
  });
610
605
  };
@@ -183,17 +183,17 @@ describe('JobCommand', function () {
183
183
  }
184
184
  });
185
185
  }); });
186
- it('should pass wait as true if returnStatusOnly flag is present', function () { return __awaiter(void 0, void 0, void 0, function () {
186
+ it('should pass wait as true if verbose flag is present', function () { return __awaiter(void 0, void 0, void 0, function () {
187
187
  var _a;
188
188
  return __generator(this, function (_b) {
189
189
  switch (_b.label) {
190
- case 0: return [4 /*yield*/, executeCommandWrapper([jobPath, '--returnStatusOnly'])];
190
+ case 0: return [4 /*yield*/, executeCommandWrapper([jobPath, '--verbose'])];
191
191
  case 1:
192
192
  _b.sent();
193
193
  (_a = expect(viyaExecuteModule.executeJobViya)).toHaveBeenCalledWith.apply(_a, __spreadArray([], __read(executeCalledWith({
194
194
  jobPath: jobPath,
195
195
  waitForJob: true,
196
- returnStatusOnly: true
196
+ verbose: true
197
197
  })), false));
198
198
  return [2 /*return*/];
199
199
  }
@@ -215,10 +215,10 @@ describe('JobCommand', function () {
215
215
  statusFile,
216
216
  '--source',
217
217
  source,
218
- '--returnStatusOnly',
219
218
  '--ignoreWarnings',
220
219
  '--wait',
221
- '--streamLog'
220
+ '--streamLog',
221
+ '--verbose'
222
222
  ])];
223
223
  case 1:
224
224
  _b.sent();
@@ -228,10 +228,10 @@ describe('JobCommand', function () {
228
228
  output: output,
229
229
  logFile: path_1.default.join(projectFolder, log),
230
230
  statusFile: path_1.default.join(projectFolder, statusFile),
231
- returnStatusOnly: true,
232
231
  ignoreWarnings: true,
233
232
  source: source,
234
- streamLog: true
233
+ streamLog: true,
234
+ verbose: true
235
235
  })), false));
236
236
  return [2 /*return*/];
237
237
  }
@@ -253,10 +253,10 @@ describe('JobCommand', function () {
253
253
  statusFile,
254
254
  '-s',
255
255
  source,
256
- '-r',
257
256
  '-i',
258
257
  '-w',
259
- '--streamLog'
258
+ '--streamLog',
259
+ '-v'
260
260
  ])];
261
261
  case 1:
262
262
  _b.sent();
@@ -266,10 +266,10 @@ describe('JobCommand', function () {
266
266
  output: output,
267
267
  logFile: path_1.default.join(projectFolder, log),
268
268
  statusFile: path_1.default.join(projectFolder, statusFile),
269
- returnStatusOnly: true,
270
269
  ignoreWarnings: true,
271
270
  source: source,
272
- streamLog: true
271
+ streamLog: true,
272
+ verbose: true
273
273
  })), false));
274
274
  return [2 /*return*/];
275
275
  }
@@ -478,6 +478,19 @@ describe('JobCommand', function () {
478
478
  });
479
479
  }); });
480
480
  });
481
+ it('should log deprecation warning if returnStatusOnly flag is present', function () { return __awaiter(void 0, void 0, void 0, function () {
482
+ return __generator(this, function (_a) {
483
+ switch (_a.label) {
484
+ case 0:
485
+ jest.spyOn(process.logger, 'warn');
486
+ return [4 /*yield*/, executeCommandWrapper([jobPath, '--returnStatusOnly'])];
487
+ case 1:
488
+ _a.sent();
489
+ expect(process.logger.warn).toHaveBeenCalledWith('--returnStatusOnly (-r) flag is deprecated.');
490
+ return [2 /*return*/];
491
+ }
492
+ });
493
+ }); });
481
494
  });
482
495
  var setupMocksForViya = function () {
483
496
  jest.resetAllMocks();
@@ -527,7 +540,7 @@ var setupMocksForSAS9 = function () {
527
540
  jest.spyOn(process.logger, 'error');
528
541
  };
529
542
  var executeCalledWith = function (_a) {
530
- var jobPath = _a.jobPath, _b = _a.waitForJob, waitForJob = _b === void 0 ? false : _b, _c = _a.output, output = _c === void 0 ? false : _c, _d = _a.logFile, logFile = _d === void 0 ? undefined : _d, _e = _a.statusFile, statusFile = _e === void 0 ? undefined : _e, _f = _a.returnStatusOnly, returnStatusOnly = _f === void 0 ? false : _f, _g = _a.ignoreWarnings, ignoreWarnings = _g === void 0 ? false : _g, _h = _a.source, source = _h === void 0 ? undefined : _h, _j = _a.streamLog, streamLog = _j === void 0 ? false : _j;
543
+ var jobPath = _a.jobPath, _b = _a.waitForJob, waitForJob = _b === void 0 ? false : _b, _c = _a.output, output = _c === void 0 ? false : _c, _d = _a.logFile, logFile = _d === void 0 ? undefined : _d, _e = _a.statusFile, statusFile = _e === void 0 ? undefined : _e, _f = _a.ignoreWarnings, ignoreWarnings = _f === void 0 ? false : _f, _g = _a.source, source = _g === void 0 ? undefined : _g, _h = _a.streamLog, streamLog = _h === void 0 ? false : _h, _j = _a.verbose, verbose = _j === void 0 ? false : _j;
531
544
  return [
532
545
  expect.anything(),
533
546
  authConfig,
@@ -537,10 +550,10 @@ var executeCalledWith = function (_a) {
537
550
  output,
538
551
  logFile,
539
552
  statusFile,
540
- returnStatusOnly,
541
553
  ignoreWarnings,
542
554
  source,
543
- streamLog
555
+ streamLog,
556
+ verbose
544
557
  ];
545
558
  };
546
559
  var executeCommandWrapper = function (additionalParams) { return __awaiter(void 0, void 0, void 0, function () {
@@ -86,18 +86,18 @@ function runSasCode(target, filePath, compile, logFile, source) {
86
86
  var _a;
87
87
  if (compile === void 0) { compile = false; }
88
88
  return __awaiter(this, void 0, void 0, function () {
89
- var isTempFile, sourcefilePathParts, sourceFolderPath, sasFilePath, sasFileContent, linesToExecute, macroVars, macroVarStatements;
90
- var _b;
91
- return __generator(this, function (_c) {
92
- switch (_c.label) {
89
+ var isTempFile, sourcefilePathParts, sourceFolderPath, sasFilePath, sasFileContent, linesToExecute, macroVars, macroVarStatements, _b;
90
+ var _c;
91
+ return __generator(this, function (_d) {
92
+ switch (_d.label) {
93
93
  case 0:
94
94
  isTempFile = false;
95
95
  if (!isUrl(filePath)) return [3 /*break*/, 2];
96
96
  ;
97
97
  return [4 /*yield*/, createFileFromUrl(filePath)];
98
98
  case 1:
99
- (_b = _c.sent(), isTempFile = _b.isTempFile, filePath = _b.tempFilePath);
100
- _c.label = 2;
99
+ (_c = _d.sent(), isTempFile = _c.isTempFile, filePath = _c.tempFilePath);
100
+ _d.label = 2;
101
101
  case 2:
102
102
  if (!compile) return [3 /*break*/, 5];
103
103
  if (!/\.sas$/i.test(filePath)) return [3 /*break*/, 4];
@@ -106,41 +106,46 @@ function runSasCode(target, filePath, compile, logFile, source) {
106
106
  sourceFolderPath = sourcefilePathParts.join(path_1.default.sep);
107
107
  return [4 /*yield*/, (0, __1.compileSingleFile)(target, 'identify', filePath, (0, internal_1.getDestinationServicePath)(sourceFolderPath), true)];
108
108
  case 3:
109
- (filePath = (_c.sent()).destinationPath);
109
+ (filePath = (_d.sent()).destinationPath);
110
110
  (_a = process.logger) === null || _a === void 0 ? void 0 : _a.success("File Compiled and placed at: ".concat(filePath, " ."));
111
111
  return [3 /*break*/, 5];
112
112
  case 4:
113
113
  process.logger.info('Compile flag has no effect on files with extension type other than sas');
114
- _c.label = 5;
114
+ _d.label = 5;
115
115
  case 5:
116
116
  sasFilePath = (0, utils_1.getAbsolutePath)(filePath, process.currentDir);
117
117
  return [4 /*yield*/, (0, utils_1.readFile)(sasFilePath)];
118
118
  case 6:
119
- sasFileContent = _c.sent();
119
+ sasFileContent = _d.sent();
120
120
  linesToExecute = sasFileContent.replace(/\r\n/g, '\n').split('\n');
121
121
  if (!source) return [3 /*break*/, 8];
122
122
  return [4 /*yield*/, (0, parseSourceFile_1.parseSourceFile)(source)];
123
123
  case 7:
124
- macroVars = _c.sent();
124
+ macroVars = _d.sent();
125
125
  macroVarStatements = (0, utils_2.convertToSASStatements)(macroVars).split('\n');
126
126
  linesToExecute = __spreadArray(__spreadArray([], __read(macroVarStatements), false), __read(linesToExecute), false);
127
- _c.label = 8;
127
+ _d.label = 8;
128
128
  case 8:
129
129
  if (!isTempFile) return [3 /*break*/, 10];
130
130
  return [4 /*yield*/, (0, utils_1.deleteFile)(filePath)];
131
131
  case 9:
132
- _c.sent();
133
- _c.label = 10;
132
+ _d.sent();
133
+ _d.label = 10;
134
134
  case 10:
135
- if (!(target.serverType === utils_1.ServerType.SasViya)) return [3 /*break*/, 12];
136
- return [4 /*yield*/, executeOnSasViya(filePath, target, linesToExecute, logFile)];
137
- case 11: return [2 /*return*/, _c.sent()];
138
- case 12:
139
- if (!(target.serverType === utils_1.ServerType.Sas9)) return [3 /*break*/, 14];
140
- return [4 /*yield*/, executeOnSas9(target, linesToExecute, logFile)];
141
- case 13: return [2 /*return*/, _c.sent()];
142
- case 14: return [4 /*yield*/, executeOnSasJS(filePath, target, linesToExecute, logFile)];
143
- case 15: return [2 /*return*/, _c.sent()];
135
+ _b = target.serverType;
136
+ switch (_b) {
137
+ case utils_1.ServerType.SasViya: return [3 /*break*/, 11];
138
+ case utils_1.ServerType.Sas9: return [3 /*break*/, 13];
139
+ case utils_1.ServerType.Sasjs: return [3 /*break*/, 15];
140
+ }
141
+ return [3 /*break*/, 17];
142
+ case 11: return [4 /*yield*/, executeOnSasViya(filePath, target, linesToExecute, logFile)];
143
+ case 12: return [2 /*return*/, _d.sent()];
144
+ case 13: return [4 /*yield*/, executeOnSas9(target, linesToExecute, logFile)];
145
+ case 14: return [2 /*return*/, _d.sent()];
146
+ case 15: return [4 /*yield*/, executeOnSasJS(filePath, target, linesToExecute, logFile)];
147
+ case 16: return [2 /*return*/, _d.sent()];
148
+ case 17: return [2 /*return*/];
144
149
  }
145
150
  });
146
151
  });
@@ -245,10 +250,12 @@ function executeOnSas9(target, linesToExecute, logFile) {
245
250
  function executeOnSasJS(filePath, target, linesToExecute, logFile) {
246
251
  var _a;
247
252
  return __awaiter(this, void 0, void 0, function () {
248
- var authConfig, _b, sasjs, fileExtension, executionResult;
253
+ var sasjs, authConfig, _b, fileExtension, log;
249
254
  return __generator(this, function (_c) {
250
255
  switch (_c.label) {
251
- case 0: return [4 /*yield*/, (0, utils_2.isSasJsServerInServerMode)(target)];
256
+ case 0:
257
+ sasjs = (0, config_1.getSASjs)(target);
258
+ return [4 /*yield*/, (0, utils_2.isSasJsServerInServerMode)(target)];
252
259
  case 1:
253
260
  if (!(_c.sent())) return [3 /*break*/, 3];
254
261
  return [4 /*yield*/, (0, config_1.getAuthConfig)(target)];
@@ -260,7 +267,6 @@ function executeOnSasJS(filePath, target, linesToExecute, logFile) {
260
267
  _c.label = 4;
261
268
  case 4:
262
269
  authConfig = _b;
263
- sasjs = (0, config_1.getSASjs)(target);
264
270
  fileExtension = path_1.default.extname(filePath).slice(1);
265
271
  return [4 /*yield*/, sasjs.executeScript({
266
272
  linesOfCode: linesToExecute,
@@ -268,12 +274,15 @@ function executeOnSasJS(filePath, target, linesToExecute, logFile) {
268
274
  authConfig: authConfig
269
275
  })];
270
276
  case 5:
271
- executionResult = _c.sent();
277
+ log = (_c.sent()).log;
278
+ if (!log) {
279
+ throw new node_1.ErrorResponse('We were not able to fetch the log this time.');
280
+ }
272
281
  (_a = process.logger) === null || _a === void 0 ? void 0 : _a.success('Job execution completed!');
273
- return [4 /*yield*/, createOutputFile(executionResult || '', logFile)];
282
+ return [4 /*yield*/, createOutputFile(log, logFile)];
274
283
  case 6:
275
284
  _c.sent();
276
- return [2 /*return*/, { log: executionResult }];
285
+ return [2 /*return*/, { log: log }];
277
286
  }
278
287
  });
279
288
  });
@@ -289,7 +298,7 @@ function createOutputFile(log, logFilePath, silent) {
289
298
  if (!logFilePath) {
290
299
  logFilePath = path_1.default.join(buildDestinationResultsFolder, "sasjs-run-".concat(timestamp, ".log"));
291
300
  }
292
- return [4 /*yield*/, (0, saveLog_1.saveLog)(log || '', logFilePath, '', false, silent)];
301
+ return [4 /*yield*/, (0, saveLog_1.saveLog)(log || '', logFilePath, '', silent)];
293
302
  case 1:
294
303
  _a.sent();
295
304
  return [2 /*return*/, logFilePath];
@@ -0,0 +1 @@
1
+ export {};