@sasjs/cli 3.8.3 → 3.8.6

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.
@@ -158,7 +158,7 @@ var AddCommand = /** @class */ (function (_super) {
158
158
  })
159
159
  .catch(function (err) {
160
160
  var _a;
161
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Error adding credentials: ', err);
161
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Error adding credentials: ', err.toString());
162
162
  return command_1.ReturnCode.InternalError;
163
163
  })];
164
164
  case 2: return [2 /*return*/, _b.sent()];
@@ -174,7 +174,7 @@ var getTokens = function (target, client, secret, httpsAgentOptions) { return __
174
174
  });
175
175
  return [4 /*yield*/, (0, auth_1.getNewAccessToken)(adapter, client, secret, target).catch(function (e) {
176
176
  var _a;
177
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error("An error has occurred while validating your credentials: ", e, "\nPlease check your Client ID ".concat(target.serverType === types_1.ServerType.Sasjs ? '' : 'and Client Secret ', "and try again.\n"));
177
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error("An error has occurred while validating your credentials: ".concat(e, "\nPlease check your Client ID ").concat(target.serverType === types_1.ServerType.Sasjs ? '' : 'and Client Secret ', "and try again.\n"));
178
178
  throw e;
179
179
  })];
180
180
  case 1:
@@ -160,7 +160,7 @@ function getAndValidateServerUrl(target) {
160
160
  case 0: return [4 /*yield*/, (0, input_1.getUrl)('Please enter a target server URL (including port, if relevant): ', 'Server URL is required.', target === null || target === void 0 ? void 0 : target.serverUrl)];
161
161
  case 1:
162
162
  serverUrl = _a.sent();
163
- return [2 /*return*/, serverUrl];
163
+ return [2 /*return*/, serverUrl.replace(/\/$/, '')];
164
164
  }
165
165
  });
166
166
  });
@@ -254,7 +254,7 @@ describe('AddCommand - cred', function () {
254
254
  case 1:
255
255
  returnCode = _a.sent();
256
256
  expect(returnCode).toEqual(command_1.ReturnCode.InternalError);
257
- expect(process.logger.error).toHaveBeenCalledWith('Error adding credentials: ', new Error('Test Error'));
257
+ expect(process.logger.error).toHaveBeenCalledWith('Error adding credentials: ', new Error('Test Error').toString());
258
258
  return [2 /*return*/];
259
259
  }
260
260
  });
@@ -50,7 +50,7 @@ var saveLog_1 = require("../../utils/saveLog");
50
50
  var getLogFilePath_1 = require("../../utils/getLogFilePath");
51
51
  function runSasJob(target, isLocal, sasJobLocation, dataFilePath, configFilePath, authConfig, logFile, jobPath, outputPathParam) {
52
52
  return __awaiter(this, void 0, void 0, function () {
53
- var dataJson, configJson, dataFile, configFile, sas9CredentialsError, sasjs, result, isError, sasRequests, currentRequestLog;
53
+ var dataJson, configJson, dataFile, configFile, sas9CredentialsError, sasjs, result;
54
54
  var _this = this;
55
55
  return __generator(this, function (_a) {
56
56
  switch (_a.label) {
@@ -112,34 +112,25 @@ function runSasJob(target, isLocal, sasJobLocation, dataFilePath, configFilePath
112
112
  useComputeApi: false,
113
113
  debug: true
114
114
  });
115
- isError = false;
116
115
  return [4 /*yield*/, sasjs
117
116
  .request(sasJobLocation, dataJson, configJson, function () {
118
117
  (0, displayResult_1.displayError)(null, 'Login callback called. Request failed.');
119
118
  }, authConfig)
120
119
  .then(function (res) { return __awaiter(_this, void 0, void 0, function () {
121
- var output;
122
120
  return __generator(this, function (_a) {
123
121
  switch (_a.label) {
124
122
  case 0:
125
- if ((res && res.errorCode) || res.error)
126
- isError = true;
123
+ if (!((res && res.errorCode) || res.error)) return [3 /*break*/, 2];
124
+ (0, displayResult_1.displayError)('Request finished with errors.');
125
+ return [4 /*yield*/, saveLogFile(sasjs, sasJobLocation, logFile, jobPath)];
126
+ case 1:
127
+ _a.sent();
128
+ return [2 /*return*/];
129
+ case 2:
127
130
  if (res === null || res === void 0 ? void 0 : res.result)
128
131
  res = res.result;
129
- if (typeof res !== 'object') {
130
- try {
131
- output = JSON.stringify(res, null, 2);
132
- }
133
- catch (error) {
134
- (0, displayResult_1.displayError)(error, 'Result parsing failed.');
135
- return [2 /*return*/, error];
136
- }
137
- }
138
- else {
139
- output = res;
140
- }
141
- return [4 /*yield*/, writeOutput(outputPathParam, output, isLocal)];
142
- case 1:
132
+ return [4 /*yield*/, writeOutput(outputPathParam, res, isLocal)];
133
+ case 3:
143
134
  _a.sent();
144
135
  result = true;
145
136
  return [2 /*return*/];
@@ -150,14 +141,13 @@ function runSasJob(target, isLocal, sasJobLocation, dataFilePath, configFilePath
150
141
  return __generator(this, function (_a) {
151
142
  switch (_a.label) {
152
143
  case 0:
153
- isError = true;
154
144
  if (err && err.errorCode === 404) {
155
145
  (0, utils_2.displaySasjsRunnerError)(configJson.username);
156
146
  }
157
147
  else {
158
- (0, displayResult_1.displayError)('', 'An error occurred while executing the request.');
148
+ (0, displayResult_1.displayError)(err, 'An error occurred while executing the request.');
159
149
  }
160
- return [4 /*yield*/, writeOutput(outputPathParam, err, isLocal)];
150
+ return [4 /*yield*/, saveLogFile(sasjs, sasJobLocation, logFile, jobPath)];
161
151
  case 1:
162
152
  _a.sent();
163
153
  result = err;
@@ -167,21 +157,30 @@ function runSasJob(target, isLocal, sasJobLocation, dataFilePath, configFilePath
167
157
  }); })];
168
158
  case 5:
169
159
  _a.sent();
170
- sasRequests = sasjs.getSasRequests();
171
- currentRequestLog = sasRequests.find(function (x) { return x.serviceLink === sasJobLocation; });
172
- if (!(currentRequestLog && ((logFile && jobPath) || isError))) return [3 /*break*/, 7];
173
- if (!logFile)
174
- logFile = (0, getLogFilePath_1.getLogFilePath)('', jobPath || '');
175
- return [4 /*yield*/, (0, saveLog_1.saveLog)(currentRequestLog.logFile, logFile, jobPath || '', false)];
176
- case 6:
177
- _a.sent();
178
- _a.label = 7;
179
- case 7: return [2 /*return*/, result];
160
+ return [2 /*return*/, result];
180
161
  }
181
162
  });
182
163
  });
183
164
  }
184
165
  exports.runSasJob = runSasJob;
166
+ var saveLogFile = function (sasjs, sasJobLocation, logFile, jobPath) { return __awaiter(void 0, void 0, void 0, function () {
167
+ var sasRequests, currentRequestLog;
168
+ return __generator(this, function (_a) {
169
+ switch (_a.label) {
170
+ case 0:
171
+ sasRequests = sasjs.getSasRequests();
172
+ currentRequestLog = sasRequests.find(function (x) { return x.serviceLink === sasJobLocation; });
173
+ if (!(currentRequestLog && jobPath)) return [3 /*break*/, 2];
174
+ if (!logFile)
175
+ logFile = (0, getLogFilePath_1.getLogFilePath)('', jobPath || '');
176
+ return [4 /*yield*/, (0, saveLog_1.saveLog)(currentRequestLog.logFile, logFile, jobPath || '', false)];
177
+ case 1:
178
+ _a.sent();
179
+ _a.label = 2;
180
+ case 2: return [2 /*return*/];
181
+ }
182
+ });
183
+ }); };
185
184
  /**
186
185
  * Writes output to the file
187
186
  * @param outputPathParam path to output file
@@ -217,7 +216,13 @@ var writeOutput = function (outputPathParam, output, isLocal) { return __awaiter
217
216
  }
218
217
  outputString = '';
219
218
  if (typeof output === 'object') {
220
- outputString = JSON.stringify(output);
219
+ try {
220
+ outputString = JSON.stringify(output, null, 2);
221
+ }
222
+ catch (error) {
223
+ (0, displayResult_1.displayError)(error, 'Result parsing failed.');
224
+ return [2 /*return*/];
225
+ }
221
226
  }
222
227
  else {
223
228
  outputString = output;
@@ -124,14 +124,7 @@ function getNewAccessToken(sasjsInstance, clientId, clientSecret, target) {
124
124
  return [4 /*yield*/, getAuthCode(authUrl)];
125
125
  case 1:
126
126
  authCode = _b.sent();
127
- return [4 /*yield*/, sasjsInstance
128
- .getAccessToken(clientId, clientSecret, authCode)
129
- .then(function (res) {
130
- var access_token = res.access_token, refresh_token = res.refresh_token;
131
- if (access_token && refresh_token)
132
- return res;
133
- throw res;
134
- })];
127
+ return [4 /*yield*/, sasjsInstance.getAccessToken(clientId, clientSecret, authCode)];
135
128
  case 2:
136
129
  _a = _b.sent(), access_token = _a.access_token, refresh_token = _a.refresh_token;
137
130
  return [2 /*return*/, { access_token: access_token, refresh_token: refresh_token }];
package/package.json CHANGED
@@ -47,7 +47,7 @@
47
47
  "access": "public"
48
48
  },
49
49
  "dependencies": {
50
- "@sasjs/adapter": "3.7.8",
50
+ "@sasjs/adapter": "^3.7.13",
51
51
  "@sasjs/core": "4.15.3",
52
52
  "@sasjs/lint": "1.11.2",
53
53
  "@sasjs/utils": "2.36.0",
@@ -94,5 +94,5 @@
94
94
  "typescript": "4.5.4",
95
95
  "util": "0.12.4"
96
96
  },
97
- "version": "3.8.3"
97
+ "version": "3.8.6"
98
98
  }