@sasjs/cli 3.19.6 → 3.20.1

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 (31) hide show
  1. package/build/commands/compile/spec/compile.spec.js +2 -1
  2. package/build/commands/deploy/deploy.js +54 -108
  3. package/build/commands/deploy/spec/cbd.spec.js +31 -8
  4. package/build/commands/fs/fsCommand.d.ts +11 -0
  5. package/build/commands/fs/fsCommand.js +335 -0
  6. package/build/commands/fs/internal/executeCode.d.ts +4 -0
  7. package/build/commands/fs/internal/executeCode.js +126 -0
  8. package/build/commands/fs/internal/extractHashArray.d.ts +1 -0
  9. package/build/commands/fs/internal/extractHashArray.js +20 -0
  10. package/build/commands/fs/spec/executeCode.spec.d.ts +1 -0
  11. package/build/commands/fs/spec/executeCode.spec.js +197 -0
  12. package/build/commands/fs/spec/extractHashArray.spec.d.ts +1 -0
  13. package/build/commands/fs/spec/extractHashArray.spec.js +14 -0
  14. package/build/commands/fs/spec/fsCommand.spec.d.ts +1 -0
  15. package/build/commands/fs/spec/fsCommand.spec.js +297 -0
  16. package/build/commands/help/help.js +14 -0
  17. package/build/commands/job/internal/execute/sas9.d.ts +1 -1
  18. package/build/commands/job/internal/execute/sasjs.d.ts +3 -4
  19. package/build/commands/job/internal/execute/sasjs.js +36 -20
  20. package/build/commands/job/jobCommand.d.ts +4 -8
  21. package/build/commands/job/jobCommand.js +71 -97
  22. package/build/commands/job/spec/execute.spec.js +52 -7
  23. package/build/commands/job/spec/jobCommand.spec.js +8 -3
  24. package/build/commands/request/spec/request.spec.server.sas9.js +2 -0
  25. package/build/commands/run/run.js +70 -107
  26. package/build/types/command/commandFactory.js +2 -0
  27. package/build/utils/config.d.ts +28 -1
  28. package/build/utils/config.js +71 -1
  29. package/build/utils/index.d.ts +1 -0
  30. package/build/utils/index.js +1 -0
  31. package/package.json +8 -7
@@ -55,7 +55,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
55
55
  };
56
56
  Object.defineProperty(exports, "__esModule", { value: true });
57
57
  exports.JobCommand = void 0;
58
- var node_1 = __importDefault(require("@sasjs/adapter/node"));
59
58
  var utils_1 = require("@sasjs/utils");
60
59
  var path_1 = __importDefault(require("path"));
61
60
  var command_1 = require("../../types/command");
@@ -141,106 +140,61 @@ var JobCommand = /** @class */ (function (_super) {
141
140
  return _this;
142
141
  }
143
142
  JobCommand.prototype.execute = function () {
144
- var _a, _b;
143
+ var _a;
145
144
  return __awaiter(this, void 0, void 0, function () {
146
- var target, sasjs, authConfig, _c, _d, username, password, _e, e_1, _f;
147
- return __generator(this, function (_g) {
148
- switch (_g.label) {
145
+ var target, _b, _c, _d, _e;
146
+ return __generator(this, function (_f) {
147
+ switch (_f.label) {
149
148
  case 0: return [4 /*yield*/, this.getTargetInfo()];
150
149
  case 1:
151
- target = (_g.sent()).target;
152
- sasjs = new node_1.default({
153
- serverUrl: target.serverUrl,
154
- httpsAgentOptions: target.httpsAgentOptions,
155
- appLoc: target.appLoc,
156
- serverType: target.serverType,
157
- debug: true
158
- });
159
- _c = target.serverType;
160
- switch (_c) {
150
+ target = (_f.sent()).target;
151
+ _b = target.serverType;
152
+ switch (_b) {
161
153
  case utils_1.ServerType.SasViya: return [3 /*break*/, 2];
162
- case utils_1.ServerType.Sas9: return [3 /*break*/, 7];
163
- case utils_1.ServerType.Sasjs: return [3 /*break*/, 11];
154
+ case utils_1.ServerType.Sas9: return [3 /*break*/, 6];
155
+ case utils_1.ServerType.Sasjs: return [3 /*break*/, 10];
164
156
  }
165
- return [3 /*break*/, 19];
166
- case 2: return [4 /*yield*/, (0, utils_2.getAuthConfig)(target).catch(function (err) {
167
- var _a;
168
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Unable to execute job. Error fetching auth config: ', err);
169
- return undefined;
170
- })];
157
+ return [3 /*break*/, 14];
158
+ case 2:
159
+ if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 4];
160
+ return [4 /*yield*/, this.executeJobViya(target)];
171
161
  case 3:
172
- authConfig = _g.sent();
173
- if (!authConfig)
174
- return [2 /*return*/, command_1.ReturnCode.InternalError];
175
- if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 5];
176
- return [4 /*yield*/, this.executeJobViya(target, sasjs, authConfig)];
162
+ _c = _f.sent();
163
+ return [3 /*break*/, 5];
177
164
  case 4:
178
- _d = _g.sent();
179
- return [3 /*break*/, 6];
180
- case 5:
181
- _d = command_1.ReturnCode.InvalidCommand;
182
- _g.label = 6;
183
- case 6: return [2 /*return*/, _d];
165
+ _c = command_1.ReturnCode.InvalidCommand;
166
+ _f.label = 5;
167
+ case 5: return [2 /*return*/, _c];
168
+ case 6:
169
+ if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 8];
170
+ return [4 /*yield*/, this.executeJobSas9(target)];
184
171
  case 7:
185
- username = void 0;
186
- password = void 0;
187
- if (target.authConfigSas9) {
188
- username = target.authConfigSas9.userName;
189
- password = target.authConfigSas9.password;
190
- }
191
- else {
192
- username = process.env.SAS_USERNAME;
193
- password = process.env.SAS_PASSWORD;
194
- }
195
- if (!username || !password) {
196
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Unable to execute job. username and password not found');
197
- return [2 /*return*/, command_1.ReturnCode.InternalError];
198
- }
199
- password = (0, utils_1.decodeFromBase64)(password);
200
- if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 9];
201
- return [4 /*yield*/, this.executeJobSas9(sasjs, target, { username: username, password: password })];
172
+ _d = _f.sent();
173
+ return [3 /*break*/, 9];
202
174
  case 8:
203
- _e = _g.sent();
204
- return [3 /*break*/, 10];
205
- case 9:
206
- _e = command_1.ReturnCode.InvalidCommand;
207
- _g.label = 10;
208
- case 10: return [2 /*return*/, _e];
209
- case 11:
210
- sasjs = new node_1.default({
211
- serverType: target.serverType,
212
- serverUrl: target.serverUrl
213
- });
175
+ _d = command_1.ReturnCode.InvalidCommand;
176
+ _f.label = 9;
177
+ case 9: return [2 /*return*/, _d];
178
+ case 10:
214
179
  if (typeof this.parsed.jobPath !== 'string')
215
180
  return [2 /*return*/, command_1.ReturnCode.InvalidCommand];
216
- _g.label = 12;
181
+ if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 12];
182
+ return [4 /*yield*/, this.executeJobSasjs(target)];
183
+ case 11:
184
+ _e = _f.sent();
185
+ return [3 /*break*/, 13];
217
186
  case 12:
218
- _g.trys.push([12, 14, , 15]);
219
- return [4 /*yield*/, (0, utils_2.getAuthConfig)(target)];
220
- case 13:
221
- authConfig = _g.sent();
222
- return [3 /*break*/, 15];
187
+ _e = command_1.ReturnCode.InvalidCommand;
188
+ _f.label = 13;
189
+ case 13: return [2 /*return*/, _e];
223
190
  case 14:
224
- e_1 = _g.sent();
225
- return [3 /*break*/, 15];
226
- case 15:
227
- if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 17];
228
- return [4 /*yield*/, this.executeJobSasjs(sasjs, target, authConfig)];
229
- case 16:
230
- _f = _g.sent();
231
- return [3 /*break*/, 18];
232
- case 17:
233
- _f = command_1.ReturnCode.InvalidCommand;
234
- _g.label = 18;
235
- case 18: return [2 /*return*/, _f];
236
- case 19:
237
- (_b = process.logger) === null || _b === void 0 ? void 0 : _b.error("This command is not supported for specified server type.\nPlease try again with a different server type.");
191
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error("This command is not supported for specified server type.\nPlease try again with a different server type.");
238
192
  return [2 /*return*/, command_1.ReturnCode.InternalError];
239
193
  }
240
194
  });
241
195
  });
242
196
  };
243
- JobCommand.prototype.executeJobSasjs = function (sasjs, target, authConfig) {
197
+ JobCommand.prototype.executeJobSasjs = function (target) {
244
198
  var _a;
245
199
  return __awaiter(this, void 0, void 0, function () {
246
200
  var jobPath, log, output, returnCode;
@@ -252,7 +206,7 @@ var JobCommand = /** @class */ (function (_super) {
252
206
  output = ((_a = this.parsed.output) === null || _a === void 0 ? void 0 : _a.length)
253
207
  ? this.parsed.output
254
208
  : undefined;
255
- return [4 /*yield*/, (0, execute_1.executeJobSasjs)(sasjs, jobPath, log, output, authConfig)
209
+ return [4 /*yield*/, (0, execute_1.executeJobSasjs)(target, jobPath, log, output)
256
210
  .then(function () { return command_1.ReturnCode.Success; })
257
211
  .catch(function (err) {
258
212
  var _a;
@@ -266,12 +220,12 @@ var JobCommand = /** @class */ (function (_super) {
266
220
  });
267
221
  });
268
222
  };
269
- JobCommand.prototype.executeJobSas9 = function (sasjs, target, config) {
223
+ JobCommand.prototype.executeJobSas9 = function (target) {
270
224
  var _a;
271
225
  return __awaiter(this, void 0, void 0, function () {
272
- var jobPath, log, output, source, returnCode;
273
- return __generator(this, function (_b) {
274
- switch (_b.label) {
226
+ var jobPath, log, output, source, _b, sasjs, authConfigSas9, userName, password, returnCode;
227
+ return __generator(this, function (_c) {
228
+ switch (_c.label) {
275
229
  case 0:
276
230
  jobPath = (0, prefixAppLoc_1.prefixAppLoc)(target.appLoc, this.parsed.jobPath);
277
231
  log = (0, getLogFilePath_1.getLogFilePath)(this.parsed.log, jobPath);
@@ -279,7 +233,18 @@ var JobCommand = /** @class */ (function (_super) {
279
233
  ? this.parsed.output
280
234
  : undefined;
281
235
  source = this.parsed.source;
282
- return [4 /*yield*/, (0, execute_1.executeJobSas9)(sasjs, config, jobPath, log, output, source)
236
+ return [4 /*yield*/, (0, utils_2.getSASjsAndAuthConfig)(target).catch(function (err) {
237
+ var _a;
238
+ (_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 };
240
+ })];
241
+ case 1:
242
+ _b = _c.sent(), sasjs = _b.sasjs, authConfigSas9 = _b.authConfigSas9;
243
+ if (!authConfigSas9)
244
+ return [2 /*return*/, command_1.ReturnCode.InternalError];
245
+ userName = authConfigSas9.userName;
246
+ password = (0, utils_1.decodeFromBase64)(authConfigSas9.password);
247
+ return [4 /*yield*/, (0, execute_1.executeJobSas9)(sasjs, { userName: userName, password: password }, jobPath, log, output, source)
283
248
  .then(function () {
284
249
  return command_1.ReturnCode.Success;
285
250
  })
@@ -288,19 +253,19 @@ var JobCommand = /** @class */ (function (_super) {
288
253
  (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Error executing job: ', err);
289
254
  return command_1.ReturnCode.InternalError;
290
255
  })];
291
- case 1:
292
- returnCode = _b.sent();
256
+ case 2:
257
+ returnCode = _c.sent();
293
258
  return [2 /*return*/, returnCode];
294
259
  }
295
260
  });
296
261
  });
297
262
  };
298
- JobCommand.prototype.executeJobViya = function (target, sasjs, authConfig) {
263
+ JobCommand.prototype.executeJobViya = function (target) {
299
264
  var _a, _b, _c;
300
265
  return __awaiter(this, void 0, void 0, function () {
301
- var jobPath, log, wait, output, statusFile, returnStatusOnly, ignoreWarnings, source, streamLog, returnCode;
302
- return __generator(this, function (_d) {
303
- switch (_d.label) {
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) {
304
269
  case 0:
305
270
  jobPath = (0, prefixAppLoc_1.prefixAppLoc)(target.appLoc, this.parsed.jobPath);
306
271
  log = (0, getLogFilePath_1.getLogFilePath)(this.parsed.log, jobPath);
@@ -320,6 +285,15 @@ var JobCommand = /** @class */ (function (_super) {
320
285
  if (ignoreWarnings && !returnStatusOnly) {
321
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.");
322
287
  }
288
+ return [4 /*yield*/, (0, utils_2.getSASjsAndAuthConfig)(target).catch(function (err) {
289
+ var _a;
290
+ (_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 };
292
+ })];
293
+ case 1:
294
+ _d = _e.sent(), sasjs = _d.sasjs, authConfig = _d.authConfig;
295
+ if (!authConfig)
296
+ return [2 /*return*/, command_1.ReturnCode.InternalError];
323
297
  return [4 /*yield*/, (0, execute_1.executeJobViya)(sasjs, authConfig, jobPath, target, wait, output, log, statusFile, returnStatusOnly, ignoreWarnings, source, streamLog)
324
298
  .then(function () {
325
299
  return command_1.ReturnCode.Success;
@@ -329,8 +303,8 @@ var JobCommand = /** @class */ (function (_super) {
329
303
  (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Error executing job: ', err);
330
304
  return command_1.ReturnCode.InternalError;
331
305
  })];
332
- case 1:
333
- returnCode = _d.sent();
306
+ case 2:
307
+ returnCode = _e.sent();
334
308
  return [2 /*return*/, returnCode];
335
309
  }
336
310
  });
@@ -1,4 +1,23 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
2
21
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
22
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
23
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -39,14 +58,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
58
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
59
  };
41
60
  Object.defineProperty(exports, "__esModule", { value: true });
42
- var node_1 = __importDefault(require("@sasjs/adapter/node"));
61
+ var node_1 = __importStar(require("@sasjs/adapter/node"));
43
62
  var utils_1 = require("@sasjs/utils");
44
63
  var types_1 = require("@sasjs/utils/types");
45
64
  var path_1 = __importDefault(require("path"));
46
65
  var utils_2 = require("../../../utils");
66
+ var utilsModule = __importStar(require("../../../utils/utils"));
47
67
  var execute_1 = require("../internal/execute");
48
68
  var mocks_1 = require("./mocks");
49
69
  var sasjs = new node_1.default();
70
+ var executeJobMock;
50
71
  var target = new types_1.Target({
51
72
  name: 'test',
52
73
  serverType: types_1.ServerType.Sasjs,
@@ -58,7 +79,7 @@ describe('executeJobViya', function () {
58
79
  beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
59
80
  return __generator(this, function (_a) {
60
81
  switch (_a.label) {
61
- case 0: return [4 /*yield*/, setupMocks(types_1.ServerType.SasViya)];
82
+ case 0: return [4 /*yield*/, setupMocksForViya()];
62
83
  case 1:
63
84
  _a.sent();
64
85
  return [2 /*return*/];
@@ -114,7 +135,7 @@ describe('executeJobSasjs', function () {
114
135
  beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
115
136
  return __generator(this, function (_a) {
116
137
  switch (_a.label) {
117
- case 0: return [4 /*yield*/, setupMocks(types_1.ServerType.Sasjs)];
138
+ case 0: return [4 /*yield*/, setupMocksForSasjs()];
118
139
  case 1:
119
140
  _a.sent();
120
141
  return [2 /*return*/];
@@ -124,16 +145,16 @@ describe('executeJobSasjs', function () {
124
145
  it('should pass job pass as a _program parameter', function () { return __awaiter(void 0, void 0, void 0, function () {
125
146
  return __generator(this, function (_a) {
126
147
  switch (_a.label) {
127
- case 0: return [4 /*yield*/, (0, execute_1.executeJobSasjs)(sasjs, 'test/job', path_1.default.join(process.projectDir, 'logs'))];
148
+ case 0: return [4 /*yield*/, (0, execute_1.executeJobSasjs)(target, 'test/job', path_1.default.join(process.projectDir, 'logs'))];
128
149
  case 1:
129
150
  _a.sent();
130
- expect(sasjs.executeJobSASjs).toHaveBeenCalledWith({ _program: 'test/job' }, undefined);
151
+ expect(executeJobMock).toHaveBeenCalledWith({ _program: 'test/job' }, target.appLoc, undefined);
131
152
  return [2 /*return*/];
132
153
  }
133
154
  });
134
155
  }); });
135
156
  });
136
- var setupMocks = function (serverType) { return __awaiter(void 0, void 0, void 0, function () {
157
+ var setupMocksForViya = function () { return __awaiter(void 0, void 0, void 0, function () {
137
158
  return __generator(this, function (_a) {
138
159
  switch (_a.label) {
139
160
  case 0:
@@ -144,9 +165,33 @@ var setupMocks = function (serverType) { return __awaiter(void 0, void 0, void 0
144
165
  jest.restoreAllMocks();
145
166
  jest.mock('@sasjs/adapter');
146
167
  jest
147
- .spyOn(sasjs, serverType === types_1.ServerType.SasViya ? 'startComputeJob' : 'executeJobSASjs')
168
+ .spyOn(sasjs, 'startComputeJob')
148
169
  .mockImplementation(function () { return Promise.resolve(); });
149
170
  return [2 /*return*/];
150
171
  }
151
172
  });
152
173
  }); };
174
+ var setupMocksForSasjs = function () { return __awaiter(void 0, void 0, void 0, function () {
175
+ return __generator(this, function (_a) {
176
+ switch (_a.label) {
177
+ case 0:
178
+ process.projectDir = process.cwd();
179
+ return [4 /*yield*/, (0, utils_2.setConstants)()];
180
+ case 1:
181
+ _a.sent();
182
+ jest.restoreAllMocks();
183
+ executeJobMock = jest
184
+ .spyOn(node_1.SASjsApiClient.prototype, 'executeJob')
185
+ .mockImplementation(function () {
186
+ return Promise.resolve({
187
+ result: '',
188
+ log: ''
189
+ });
190
+ });
191
+ jest
192
+ .spyOn(utilsModule, 'isSasJsServerInServerMode')
193
+ .mockImplementation(function () { return Promise.resolve(false); });
194
+ return [2 /*return*/];
195
+ }
196
+ });
197
+ }); };
@@ -289,7 +289,7 @@ describe('JobCommand', function () {
289
289
  switch (_a.label) {
290
290
  case 0:
291
291
  jest
292
- .spyOn(configUtils, 'getAuthConfig')
292
+ .spyOn(configUtils, 'getSASjsAndAuthConfig')
293
293
  .mockImplementation(function () { return Promise.reject(new Error('Test Error')); });
294
294
  return [4 /*yield*/, executeCommandWrapper([jobPath])];
295
295
  case 1:
@@ -488,8 +488,13 @@ var setupMocksForViya = function () {
488
488
  return Promise.resolve({ target: targetViya, isLocal: true });
489
489
  });
490
490
  jest
491
- .spyOn(configUtils, 'getAuthConfig')
492
- .mockImplementation(function () { return Promise.resolve(authConfig); });
491
+ .spyOn(configUtils, 'getSASjsAndAuthConfig')
492
+ .mockImplementation(function (target) {
493
+ return Promise.resolve({
494
+ sasjs: configUtils.getSASjs(target),
495
+ authConfig: authConfig
496
+ });
497
+ });
493
498
  process.logger = new utils_1.Logger(utils_1.LogLevel.Off);
494
499
  jest.spyOn(process.logger, 'error');
495
500
  };
@@ -70,6 +70,8 @@ var utils_3 = require("../../../utils");
70
70
  var getLogFilePath_1 = require("../../../utils/getLogFilePath");
71
71
  var fs_1 = require("fs");
72
72
  var utils_4 = require("./utils");
73
+ var dotenv_1 = __importDefault(require("dotenv"));
74
+ dotenv_1.default.config();
73
75
  describe('sasjs request with SAS9', function () {
74
76
  var appName = 'cli-tests-request-sas9-' + (0, utils_2.generateTimestamp)();
75
77
  var locationPrefix = "/User Folders/cli-tests/".concat(process.env.SAS_USERNAME, "/");