@sasjs/cli 3.19.5 → 3.20.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.
- package/build/commands/deploy/deploy.js +54 -108
- package/build/commands/deploy/spec/cbd.spec.js +31 -8
- package/build/commands/docs/internal/getDotFileContent.d.ts +2 -2
- package/build/commands/docs/internal/getDotFileContent.js +4 -4
- package/build/commands/fs/fsCommand.d.ts +11 -0
- package/build/commands/fs/fsCommand.js +335 -0
- package/build/commands/fs/internal/executeCode.d.ts +4 -0
- package/build/commands/fs/internal/executeCode.js +126 -0
- package/build/commands/fs/internal/extractHashArray.d.ts +1 -0
- package/build/commands/fs/internal/extractHashArray.js +20 -0
- package/build/commands/fs/spec/executeCode.spec.d.ts +1 -0
- package/build/commands/fs/spec/executeCode.spec.js +197 -0
- package/build/commands/fs/spec/extractHashArray.spec.d.ts +1 -0
- package/build/commands/fs/spec/extractHashArray.spec.js +14 -0
- package/build/commands/fs/spec/fsCommand.spec.d.ts +1 -0
- package/build/commands/fs/spec/fsCommand.spec.js +297 -0
- package/build/commands/job/internal/execute/sas9.d.ts +1 -1
- package/build/commands/job/internal/execute/sasjs.d.ts +3 -4
- package/build/commands/job/internal/execute/sasjs.js +36 -20
- package/build/commands/job/jobCommand.d.ts +4 -8
- package/build/commands/job/jobCommand.js +64 -98
- package/build/commands/job/spec/execute.spec.js +52 -7
- package/build/commands/request/spec/request.spec.server.sas9.js +2 -0
- package/build/commands/run/run.js +70 -107
- package/build/types/command/commandFactory.js +2 -0
- package/build/utils/config.d.ts +28 -1
- package/build/utils/config.js +71 -1
- package/build/utils/index.d.ts +1 -0
- package/build/utils/index.js +1 -0
- package/package.json +4 -4
|
@@ -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
|
|
143
|
+
var _a;
|
|
145
144
|
return __awaiter(this, void 0, void 0, function () {
|
|
146
|
-
var target,
|
|
147
|
-
return __generator(this, function (
|
|
148
|
-
switch (
|
|
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 = (
|
|
152
|
-
|
|
153
|
-
|
|
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*/,
|
|
163
|
-
case utils_1.ServerType.Sasjs: return [3 /*break*/,
|
|
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*/,
|
|
166
|
-
case 2:
|
|
167
|
-
|
|
168
|
-
|
|
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
|
-
|
|
173
|
-
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
case 5:
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
-
|
|
186
|
-
|
|
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
|
-
|
|
204
|
-
|
|
205
|
-
case 9:
|
|
206
|
-
|
|
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
|
-
|
|
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
|
-
|
|
219
|
-
|
|
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
|
-
|
|
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 (
|
|
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)(
|
|
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 (
|
|
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 (
|
|
274
|
-
switch (
|
|
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,12 @@ var JobCommand = /** @class */ (function (_super) {
|
|
|
279
233
|
? this.parsed.output
|
|
280
234
|
: undefined;
|
|
281
235
|
source = this.parsed.source;
|
|
282
|
-
return [4 /*yield*/, (0,
|
|
236
|
+
return [4 /*yield*/, (0, utils_2.getSASjsAndAuthConfig)(target)];
|
|
237
|
+
case 1:
|
|
238
|
+
_b = _c.sent(), sasjs = _b.sasjs, authConfigSas9 = _b.authConfigSas9;
|
|
239
|
+
userName = authConfigSas9.userName;
|
|
240
|
+
password = (0, utils_1.decodeFromBase64)(authConfigSas9.password);
|
|
241
|
+
return [4 /*yield*/, (0, execute_1.executeJobSas9)(sasjs, { userName: userName, password: password }, jobPath, log, output, source)
|
|
283
242
|
.then(function () {
|
|
284
243
|
return command_1.ReturnCode.Success;
|
|
285
244
|
})
|
|
@@ -288,19 +247,19 @@ var JobCommand = /** @class */ (function (_super) {
|
|
|
288
247
|
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Error executing job: ', err);
|
|
289
248
|
return command_1.ReturnCode.InternalError;
|
|
290
249
|
})];
|
|
291
|
-
case
|
|
292
|
-
returnCode =
|
|
250
|
+
case 2:
|
|
251
|
+
returnCode = _c.sent();
|
|
293
252
|
return [2 /*return*/, returnCode];
|
|
294
253
|
}
|
|
295
254
|
});
|
|
296
255
|
});
|
|
297
256
|
};
|
|
298
|
-
JobCommand.prototype.executeJobViya = function (target
|
|
299
|
-
var _a, _b, _c;
|
|
257
|
+
JobCommand.prototype.executeJobViya = function (target) {
|
|
258
|
+
var _a, _b, _c, _d;
|
|
300
259
|
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 (
|
|
303
|
-
switch (
|
|
260
|
+
var jobPath, log, wait, output, statusFile, returnStatusOnly, ignoreWarnings, source, streamLog, _e, sasjs, authConfig, returnCode;
|
|
261
|
+
return __generator(this, function (_f) {
|
|
262
|
+
switch (_f.label) {
|
|
304
263
|
case 0:
|
|
305
264
|
jobPath = (0, prefixAppLoc_1.prefixAppLoc)(target.appLoc, this.parsed.jobPath);
|
|
306
265
|
log = (0, getLogFilePath_1.getLogFilePath)(this.parsed.log, jobPath);
|
|
@@ -320,6 +279,13 @@ var JobCommand = /** @class */ (function (_super) {
|
|
|
320
279
|
if (ignoreWarnings && !returnStatusOnly) {
|
|
321
280
|
(_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
281
|
}
|
|
282
|
+
return [4 /*yield*/, (0, utils_2.getSASjsAndAuthConfig)(target)];
|
|
283
|
+
case 1:
|
|
284
|
+
_e = _f.sent(), sasjs = _e.sasjs, authConfig = _e.authConfig;
|
|
285
|
+
if (!authConfig) {
|
|
286
|
+
(_d = process.logger) === null || _d === void 0 ? void 0 : _d.error('Unable to execute job. Error fetching auth config.');
|
|
287
|
+
return [2 /*return*/, command_1.ReturnCode.InternalError];
|
|
288
|
+
}
|
|
323
289
|
return [4 /*yield*/, (0, execute_1.executeJobViya)(sasjs, authConfig, jobPath, target, wait, output, log, statusFile, returnStatusOnly, ignoreWarnings, source, streamLog)
|
|
324
290
|
.then(function () {
|
|
325
291
|
return command_1.ReturnCode.Success;
|
|
@@ -329,8 +295,8 @@ var JobCommand = /** @class */ (function (_super) {
|
|
|
329
295
|
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Error executing job: ', err);
|
|
330
296
|
return command_1.ReturnCode.InternalError;
|
|
331
297
|
})];
|
|
332
|
-
case
|
|
333
|
-
returnCode =
|
|
298
|
+
case 2:
|
|
299
|
+
returnCode = _f.sent();
|
|
334
300
|
return [2 /*return*/, returnCode];
|
|
335
301
|
}
|
|
336
302
|
});
|
|
@@ -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 =
|
|
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*/,
|
|
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*/,
|
|
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)(
|
|
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(
|
|
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
|
|
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,
|
|
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
|
+
}); };
|
|
@@ -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, "/");
|
|
@@ -66,8 +66,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
66
66
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
67
67
|
exports.runSasCode = void 0;
|
|
68
68
|
var path_1 = __importDefault(require("path"));
|
|
69
|
-
var node_1 =
|
|
70
|
-
var node_2 = require("@sasjs/adapter/node");
|
|
69
|
+
var node_1 = require("@sasjs/adapter/node");
|
|
71
70
|
var config_1 = require("../../utils/config");
|
|
72
71
|
var utils_1 = require("@sasjs/utils");
|
|
73
72
|
var __1 = require("../");
|
|
@@ -87,7 +86,7 @@ function runSasCode(target, filePath, compile, logFile, source) {
|
|
|
87
86
|
var _a;
|
|
88
87
|
if (compile === void 0) { compile = false; }
|
|
89
88
|
return __awaiter(this, void 0, void 0, function () {
|
|
90
|
-
var isTempFile, sourcefilePathParts, sourceFolderPath, sasFilePath, sasFileContent, linesToExecute, macroVars, macroVarStatements
|
|
89
|
+
var isTempFile, sourcefilePathParts, sourceFolderPath, sasFilePath, sasFileContent, linesToExecute, macroVars, macroVarStatements;
|
|
91
90
|
var _b;
|
|
92
91
|
return __generator(this, function (_c) {
|
|
93
92
|
switch (_c.label) {
|
|
@@ -127,59 +126,46 @@ function runSasCode(target, filePath, compile, logFile, source) {
|
|
|
127
126
|
linesToExecute = __spreadArray(__spreadArray([], __read(macroVarStatements), false), __read(linesToExecute), false);
|
|
128
127
|
_c.label = 8;
|
|
129
128
|
case 8:
|
|
130
|
-
if (!
|
|
131
|
-
return [4 /*yield*/,
|
|
129
|
+
if (!isTempFile) return [3 /*break*/, 10];
|
|
130
|
+
return [4 /*yield*/, (0, utils_1.deleteFile)(filePath)];
|
|
132
131
|
case 9:
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
_c.sent();
|
|
133
|
+
_c.label = 10;
|
|
135
134
|
case 10:
|
|
136
|
-
if (!(target.serverType === utils_1.ServerType.
|
|
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];
|
|
137
140
|
return [4 /*yield*/, executeOnSas9(target, linesToExecute, logFile)];
|
|
138
|
-
case
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
case 12: return [4 /*yield*/, executeOnSasJS(filePath, target, linesToExecute, logFile)];
|
|
142
|
-
case 13:
|
|
143
|
-
result = _c.sent();
|
|
144
|
-
_c.label = 14;
|
|
145
|
-
case 14:
|
|
146
|
-
if (!isTempFile) return [3 /*break*/, 16];
|
|
147
|
-
return [4 /*yield*/, (0, utils_1.deleteFile)(filePath)];
|
|
148
|
-
case 15:
|
|
149
|
-
_c.sent();
|
|
150
|
-
_c.label = 16;
|
|
151
|
-
case 16: return [2 /*return*/, result];
|
|
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()];
|
|
152
144
|
}
|
|
153
145
|
});
|
|
154
146
|
});
|
|
155
147
|
}
|
|
156
148
|
exports.runSasCode = runSasCode;
|
|
157
149
|
function executeOnSasViya(filePath, target, linesToExecute, logFile) {
|
|
158
|
-
var _a, _b, _c, _d
|
|
150
|
+
var _a, _b, _c, _d;
|
|
159
151
|
return __awaiter(this, void 0, void 0, function () {
|
|
160
|
-
var
|
|
152
|
+
var _e, sasjs, authConfig, contextName, log, buildDestinationResultsFolder, createdFilePath;
|
|
161
153
|
var _this = this;
|
|
162
154
|
return __generator(this, function (_f) {
|
|
163
155
|
switch (_f.label) {
|
|
164
156
|
case 0:
|
|
165
157
|
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.info("Sending ".concat(path_1.default.basename(filePath), " to SAS server for execution."));
|
|
166
|
-
|
|
167
|
-
serverUrl: target.serverUrl,
|
|
168
|
-
httpsAgentOptions: target.httpsAgentOptions,
|
|
169
|
-
appLoc: target.appLoc,
|
|
170
|
-
serverType: target.serverType,
|
|
171
|
-
debug: true,
|
|
172
|
-
useComputeApi: true
|
|
173
|
-
});
|
|
174
|
-
contextName = target.contextName;
|
|
175
|
-
if (!contextName) {
|
|
176
|
-
contextName = sasjs.getSasjsConfig().contextName;
|
|
177
|
-
}
|
|
178
|
-
return [4 /*yield*/, (0, config_1.getAuthConfig)(target)];
|
|
158
|
+
return [4 /*yield*/, (0, config_1.getSASjsAndAuthConfig)(target)];
|
|
179
159
|
case 1:
|
|
180
|
-
|
|
160
|
+
_e = _f.sent(), sasjs = _e.sasjs, authConfig = _e.authConfig;
|
|
161
|
+
contextName = target.contextName || sasjs.getSasjsConfig().contextName;
|
|
181
162
|
return [4 /*yield*/, sasjs
|
|
182
|
-
.
|
|
163
|
+
.executeScript({
|
|
164
|
+
fileName: path_1.default.basename(filePath),
|
|
165
|
+
linesOfCode: linesToExecute,
|
|
166
|
+
contextName: contextName,
|
|
167
|
+
authConfig: authConfig
|
|
168
|
+
})
|
|
183
169
|
.catch(function (err) { return __awaiter(_this, void 0, void 0, function () {
|
|
184
170
|
var log;
|
|
185
171
|
return __generator(this, function (_a) {
|
|
@@ -187,35 +173,23 @@ function executeOnSasViya(filePath, target, linesToExecute, logFile) {
|
|
|
187
173
|
case 0:
|
|
188
174
|
log = err.log;
|
|
189
175
|
if (!log)
|
|
190
|
-
throw new
|
|
176
|
+
throw new node_1.ErrorResponse('We were not able to fetch the log this time.');
|
|
191
177
|
return [4 /*yield*/, createOutputFile(log, logFile)];
|
|
192
178
|
case 1:
|
|
193
179
|
_a.sent();
|
|
194
|
-
throw new
|
|
180
|
+
throw new node_1.ErrorResponse('Find more error details in the log file.');
|
|
195
181
|
}
|
|
196
182
|
});
|
|
197
183
|
}); })];
|
|
198
184
|
case 2:
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
try {
|
|
202
|
-
log = executionResult.log.items
|
|
203
|
-
? executionResult.log.items.map(function (i) { return i.line; })
|
|
204
|
-
: executionResult.log;
|
|
205
|
-
}
|
|
206
|
-
catch (e) {
|
|
207
|
-
(0, utils_2.displayError)(e, 'An error occurred when parsing the execution log');
|
|
208
|
-
(_b = process.logger) === null || _b === void 0 ? void 0 : _b.info('The execution output will be saved to the log file.');
|
|
209
|
-
log = JSON.stringify(executionResult);
|
|
210
|
-
isOutput = true;
|
|
211
|
-
}
|
|
212
|
-
(_c = process.logger) === null || _c === void 0 ? void 0 : _c.success('Job execution completed!');
|
|
185
|
+
log = (_f.sent()).log;
|
|
186
|
+
(_b = process.logger) === null || _b === void 0 ? void 0 : _b.success('Job execution completed!');
|
|
213
187
|
buildDestinationResultsFolder = process.sasjsConstants.buildDestinationResultsFolder;
|
|
214
|
-
(
|
|
215
|
-
return [4 /*yield*/, createOutputFile(log,
|
|
188
|
+
(_c = process.logger) === null || _c === void 0 ? void 0 : _c.info("Creating log file in ".concat(buildDestinationResultsFolder, " ."));
|
|
189
|
+
return [4 /*yield*/, createOutputFile(log, logFile)];
|
|
216
190
|
case 3:
|
|
217
191
|
createdFilePath = _f.sent();
|
|
218
|
-
(
|
|
192
|
+
(_d = process.logger) === null || _d === void 0 ? void 0 : _d.success("Log file has been created at ".concat(createdFilePath, " ."));
|
|
219
193
|
return [2 /*return*/, { log: log }];
|
|
220
194
|
}
|
|
221
195
|
});
|
|
@@ -224,33 +198,20 @@ function executeOnSasViya(filePath, target, linesToExecute, logFile) {
|
|
|
224
198
|
function executeOnSas9(target, linesToExecute, logFile) {
|
|
225
199
|
var _a;
|
|
226
200
|
return __awaiter(this, void 0, void 0, function () {
|
|
227
|
-
var
|
|
201
|
+
var _b, sasjs, authConfigSas9, userName, password, executionResult;
|
|
228
202
|
var _this = this;
|
|
229
|
-
return __generator(this, function (
|
|
230
|
-
switch (
|
|
231
|
-
case 0:
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
else {
|
|
237
|
-
username = process.env.SAS_USERNAME;
|
|
238
|
-
password = process.env.SAS_PASSWORD;
|
|
239
|
-
}
|
|
240
|
-
if (!username || !password) {
|
|
241
|
-
sas9CredentialsError = process.sasjsConstants.sas9CredentialsError;
|
|
242
|
-
throw new Error(sas9CredentialsError);
|
|
243
|
-
}
|
|
244
|
-
password = (0, utils_1.decodeFromBase64)(password);
|
|
245
|
-
sasjs = new node_1.default({
|
|
246
|
-
serverUrl: target.serverUrl,
|
|
247
|
-
httpsAgentOptions: target.httpsAgentOptions,
|
|
248
|
-
appLoc: target.appLoc,
|
|
249
|
-
serverType: target.serverType,
|
|
250
|
-
debug: true
|
|
251
|
-
});
|
|
203
|
+
return __generator(this, function (_c) {
|
|
204
|
+
switch (_c.label) {
|
|
205
|
+
case 0: return [4 /*yield*/, (0, config_1.getSASjsAndAuthConfig)(target)];
|
|
206
|
+
case 1:
|
|
207
|
+
_b = _c.sent(), sasjs = _b.sasjs, authConfigSas9 = _b.authConfigSas9;
|
|
208
|
+
userName = authConfigSas9.userName;
|
|
209
|
+
password = (0, utils_1.decodeFromBase64)(authConfigSas9.password);
|
|
252
210
|
return [4 /*yield*/, sasjs
|
|
253
|
-
.
|
|
211
|
+
.executeScript({
|
|
212
|
+
linesOfCode: linesToExecute,
|
|
213
|
+
authConfigSas9: { userName: userName, password: password }
|
|
214
|
+
})
|
|
254
215
|
.catch(function (err) { return __awaiter(_this, void 0, void 0, function () {
|
|
255
216
|
var log;
|
|
256
217
|
return __generator(this, function (_a) {
|
|
@@ -261,21 +222,21 @@ function executeOnSas9(target, linesToExecute, logFile) {
|
|
|
261
222
|
return [4 /*yield*/, createOutputFile(log, logFile)];
|
|
262
223
|
case 1:
|
|
263
224
|
_a.sent();
|
|
264
|
-
throw new
|
|
225
|
+
throw new node_1.ErrorResponse('Find more error details in the log file.');
|
|
265
226
|
case 2:
|
|
266
227
|
if (err && err.errorCode === 404) {
|
|
267
|
-
(0, utils_2.displaySasjsRunnerError)(
|
|
228
|
+
(0, utils_2.displaySasjsRunnerError)(userName);
|
|
268
229
|
}
|
|
269
230
|
throw err;
|
|
270
231
|
}
|
|
271
232
|
});
|
|
272
233
|
}); })];
|
|
273
|
-
case
|
|
274
|
-
executionResult =
|
|
234
|
+
case 2:
|
|
235
|
+
executionResult = _c.sent();
|
|
275
236
|
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.success('Job execution completed!');
|
|
276
237
|
return [4 /*yield*/, createOutputFile(executionResult || '', logFile)];
|
|
277
|
-
case
|
|
278
|
-
|
|
238
|
+
case 3:
|
|
239
|
+
_c.sent();
|
|
279
240
|
return [2 /*return*/, { log: executionResult }];
|
|
280
241
|
}
|
|
281
242
|
});
|
|
@@ -284,32 +245,34 @@ function executeOnSas9(target, linesToExecute, logFile) {
|
|
|
284
245
|
function executeOnSasJS(filePath, target, linesToExecute, logFile) {
|
|
285
246
|
var _a;
|
|
286
247
|
return __awaiter(this, void 0, void 0, function () {
|
|
287
|
-
var authConfig, sasjs, fileExtension, executionResult;
|
|
288
|
-
return __generator(this, function (
|
|
289
|
-
switch (
|
|
248
|
+
var authConfig, _b, sasjs, fileExtension, executionResult;
|
|
249
|
+
return __generator(this, function (_c) {
|
|
250
|
+
switch (_c.label) {
|
|
290
251
|
case 0: return [4 /*yield*/, (0, utils_2.isSasJsServerInServerMode)(target)];
|
|
291
252
|
case 1:
|
|
292
|
-
if (!
|
|
253
|
+
if (!(_c.sent())) return [3 /*break*/, 3];
|
|
293
254
|
return [4 /*yield*/, (0, config_1.getAuthConfig)(target)];
|
|
294
255
|
case 2:
|
|
295
|
-
|
|
296
|
-
|
|
256
|
+
_b = _c.sent();
|
|
257
|
+
return [3 /*break*/, 4];
|
|
297
258
|
case 3:
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
httpsAgentOptions: target.httpsAgentOptions,
|
|
301
|
-
appLoc: target.appLoc,
|
|
302
|
-
serverType: target.serverType,
|
|
303
|
-
debug: true
|
|
304
|
-
});
|
|
305
|
-
fileExtension = path_1.default.extname(filePath).slice(1);
|
|
306
|
-
return [4 /*yield*/, sasjs.executeScriptSASjs(linesToExecute.join('\n'), fileExtension, authConfig)];
|
|
259
|
+
_b = undefined;
|
|
260
|
+
_c.label = 4;
|
|
307
261
|
case 4:
|
|
308
|
-
|
|
262
|
+
authConfig = _b;
|
|
263
|
+
sasjs = (0, config_1.getSASjs)(target);
|
|
264
|
+
fileExtension = path_1.default.extname(filePath).slice(1);
|
|
265
|
+
return [4 /*yield*/, sasjs.executeScript({
|
|
266
|
+
linesOfCode: linesToExecute,
|
|
267
|
+
runTime: fileExtension,
|
|
268
|
+
authConfig: authConfig
|
|
269
|
+
})];
|
|
270
|
+
case 5:
|
|
271
|
+
executionResult = _c.sent();
|
|
309
272
|
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.success('Job execution completed!');
|
|
310
273
|
return [4 /*yield*/, createOutputFile(executionResult || '', logFile)];
|
|
311
|
-
case
|
|
312
|
-
|
|
274
|
+
case 6:
|
|
275
|
+
_c.sent();
|
|
313
276
|
return [2 /*return*/, { log: executionResult }];
|
|
314
277
|
}
|
|
315
278
|
});
|