@sasjs/cli 4.4.2 → 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 () {
@@ -298,7 +298,7 @@ function createOutputFile(log, logFilePath, silent) {
298
298
  if (!logFilePath) {
299
299
  logFilePath = path_1.default.join(buildDestinationResultsFolder, "sasjs-run-".concat(timestamp, ".log"));
300
300
  }
301
- return [4 /*yield*/, (0, saveLog_1.saveLog)(log || '', logFilePath, '', false, silent)];
301
+ return [4 /*yield*/, (0, saveLog_1.saveLog)(log || '', logFilePath, '', silent)];
302
302
  case 1:
303
303
  _a.sent();
304
304
  return [2 /*return*/, logFilePath];
@@ -104,7 +104,7 @@ describe('sasjs run', function () {
104
104
  return [4 /*yield*/, (0, run_1.runSasCode)(target, filePath, false, '')];
105
105
  case 1:
106
106
  _a.sent();
107
- expect(utils_2.saveLog).toHaveBeenCalledWith(logData, expect.stringMatching(/sasjs-run-\d{14}\.log$/), '', false, undefined);
107
+ expect(utils_2.saveLog).toHaveBeenCalledWith(logData, expect.stringMatching(/sasjs-run-\d{14}\.log$/), '', undefined);
108
108
  return [2 /*return*/];
109
109
  }
110
110
  });
@@ -97,8 +97,9 @@ export declare const overrideEnvVariables: (targetName: string) => Promise<void>
97
97
  export declare const getTestSetUp: (target: Target) => Promise<string | undefined>;
98
98
  export declare const getTestTearDown: (target: Target) => Promise<string | undefined>;
99
99
  /**
100
- * Returns configuration object of SAS Adapter and authentication configuration
101
- * @param {Target} target - the target to get auth configuration from.
100
+ * Provides instance of @sasjs/adapter.
101
+ * @param target - server server.
102
+ * @returns - instance of @sasjs/adapter.
102
103
  */
103
104
  export declare function getSASjs(target: Target): SASjs;
104
105
  /**
@@ -1143,8 +1143,9 @@ var getTestTearDown = function (target) { return __awaiter(void 0, void 0, void
1143
1143
  }); };
1144
1144
  exports.getTestTearDown = getTestTearDown;
1145
1145
  /**
1146
- * Returns configuration object of SAS Adapter and authentication configuration
1147
- * @param {Target} target - the target to get auth configuration from.
1146
+ * Provides instance of @sasjs/adapter.
1147
+ * @param target - server server.
1148
+ * @returns - instance of @sasjs/adapter.
1148
1149
  */
1149
1150
  function getSASjs(target) {
1150
1151
  return new node_1.default({
@@ -1154,7 +1155,8 @@ function getSASjs(target) {
1154
1155
  contextName: target.contextName,
1155
1156
  httpsAgentOptions: target.httpsAgentOptions,
1156
1157
  debug: true,
1157
- useComputeApi: target.serverType === utils_1.ServerType.SasViya
1158
+ useComputeApi: target.serverType === utils_1.ServerType.SasViya,
1159
+ verbose: !!process.env.VERBOSE // any not empty string should be considered as true
1158
1160
  });
1159
1161
  }
1160
1162
  exports.getSASjs = getSASjs;
@@ -1,2 +1,9 @@
1
1
  import { LogJson } from '../types';
2
- export declare const saveLog: (logData: LogJson | string, logFile: string | undefined, jobPath: string, returnStatusOnly: boolean, silent?: boolean) => Promise<void>;
2
+ /**
3
+ * Saves log to the log file.
4
+ * @param logData - log content.
5
+ * @param logFile - file path to log file.
6
+ * @param jobPath - file path to job, job name will be used as a fallback name for log file.
7
+ * @param silent - boolean indicating if additional info should be logged.
8
+ */
9
+ export declare const saveLog: (logData: LogJson | string, logFile: string | undefined, jobPath: string, silent?: boolean) => Promise<void>;
@@ -43,7 +43,14 @@ exports.saveLog = void 0;
43
43
  var utils_1 = require("@sasjs/utils");
44
44
  var path_1 = __importDefault(require("path"));
45
45
  var _1 = require(".");
46
- var saveLog = function (logData, logFile, jobPath, returnStatusOnly, silent) {
46
+ /**
47
+ * Saves log to the log file.
48
+ * @param logData - log content.
49
+ * @param logFile - file path to log file.
50
+ * @param jobPath - file path to job, job name will be used as a fallback name for log file.
51
+ * @param silent - boolean indicating if additional info should be logged.
52
+ */
53
+ var saveLog = function (logData, logFile, jobPath, silent) {
47
54
  if (silent === void 0) { silent = false; }
48
55
  return __awaiter(void 0, void 0, void 0, function () {
49
56
  var error, logPath, folderPath, parentFolderPath, logLines;
@@ -51,6 +58,7 @@ var saveLog = function (logData, logFile, jobPath, returnStatusOnly, silent) {
51
58
  return __generator(this, function (_b) {
52
59
  switch (_b.label) {
53
60
  case 0:
61
+ // throw an error if log is an object containing error property
54
62
  if (typeof logData !== 'string') {
55
63
  error = logData.error;
56
64
  if (error)
@@ -75,7 +83,7 @@ var saveLog = function (logData, logFile, jobPath, returnStatusOnly, silent) {
75
83
  return [4 /*yield*/, (0, utils_1.createFile)(logPath, logLines)];
76
84
  case 4:
77
85
  _b.sent();
78
- if (!returnStatusOnly && !silent)
86
+ if (!silent)
79
87
  (0, _1.displaySuccess)("Log saved to ".concat(logPath));
80
88
  return [2 /*return*/];
81
89
  }
@@ -70,7 +70,6 @@ var path_1 = __importDefault(require("path"));
70
70
  var utils_1 = require("@sasjs/utils");
71
71
  var test_1 = require("../test");
72
72
  var setConstants_1 = require("../setConstants");
73
- jest.mock('@sasjs/adapter/node');
74
73
  describe('getAccessToken', function () {
75
74
  beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
76
75
  return __generator(this, function (_a) {
@@ -726,3 +725,63 @@ describe('removeFromLocalConfig', function () {
726
725
  });
727
726
  }); });
728
727
  });
728
+ describe('getSASjs', function () {
729
+ it('should set sasjsConfig according to target', function () {
730
+ var target = {
731
+ serverUrl: 'test_serverUrl',
732
+ appLoc: 'test_appLoc',
733
+ serverType: utils_1.ServerType.SasViya,
734
+ contextName: 'test_contextName',
735
+ httpsAgentOptions: {
736
+ caPath: 'test_caPath',
737
+ keyPath: 'test_keyPath',
738
+ certPath: 'test_certPath',
739
+ allowInsecureRequests: false
740
+ }
741
+ };
742
+ var sasjs = (0, config_1.getSASjs)(target);
743
+ var sasjsConfig = sasjs.getSasjsConfig();
744
+ var serverUrl = sasjsConfig.serverUrl, appLoc = sasjsConfig.appLoc, serverType = sasjsConfig.serverType, contextName = sasjsConfig.contextName, httpsAgentOptions = sasjsConfig.httpsAgentOptions;
745
+ expect(serverUrl).toEqual(target.serverUrl);
746
+ expect(appLoc).toEqual(target.appLoc);
747
+ expect(serverType).toEqual(target.serverType);
748
+ expect(contextName).toEqual(target.contextName);
749
+ expect(httpsAgentOptions).toEqual(target.httpsAgentOptions);
750
+ });
751
+ it('should set debug to true by default', function () {
752
+ var sasjs = (0, config_1.getSASjs)({});
753
+ var sasjsConfig = sasjs.getSasjsConfig();
754
+ var debug = sasjsConfig.debug;
755
+ expect(debug).toEqual(true);
756
+ });
757
+ it('should set useComputeApi to true if server type is Viya', function () {
758
+ var sasjs = (0, config_1.getSASjs)({ serverType: utils_1.ServerType.SasViya });
759
+ var sasjsConfig = sasjs.getSasjsConfig();
760
+ var useComputeApi = sasjsConfig.useComputeApi;
761
+ expect(useComputeApi).toEqual(true);
762
+ });
763
+ it('should set useComputeApi to false if server type is not Viya', function () {
764
+ var sasjs = (0, config_1.getSASjs)({ serverType: utils_1.ServerType.Sas9 });
765
+ var sasjsConfig = sasjs.getSasjsConfig();
766
+ var useComputeApi = sasjsConfig.useComputeApi;
767
+ expect(useComputeApi).toEqual(false);
768
+ sasjs = (0, config_1.getSASjs)({ serverType: utils_1.ServerType.Sasjs });
769
+ sasjsConfig = sasjs.getSasjsConfig();
770
+ useComputeApi = sasjsConfig.useComputeApi;
771
+ expect(useComputeApi).toEqual(false);
772
+ });
773
+ it('should enable verbose mode if VERBOSE env is present', function () {
774
+ process.env.VERBOSE = 'on';
775
+ var sasjs = (0, config_1.getSASjs)({});
776
+ var sasjsConfig = sasjs.getSasjsConfig();
777
+ var verbose = sasjsConfig.verbose;
778
+ expect(verbose).toEqual(true);
779
+ });
780
+ it('should disable verbose mode if VERBOSE env is not present', function () {
781
+ process.env.VERBOSE = '';
782
+ var sasjs = (0, config_1.getSASjs)({});
783
+ var sasjsConfig = sasjs.getSasjsConfig();
784
+ var verbose = sasjsConfig.verbose;
785
+ expect(verbose).toEqual(false);
786
+ });
787
+ });