@sasjs/cli 3.7.9 → 3.8.2
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/add/addCredential.js +1 -1
- package/build/commands/build/build.js +1 -1
- package/build/commands/build/internal/getLaunchPageCode.js +1 -1
- package/build/commands/job/internal/execute/index.d.ts +1 -0
- package/build/commands/job/internal/execute/index.js +1 -0
- package/build/commands/job/internal/execute/sas9.d.ts +14 -0
- package/build/commands/job/internal/execute/sas9.js +139 -0
- package/build/commands/job/jobCommand.d.ts +4 -0
- package/build/commands/job/jobCommand.js +86 -32
- package/build/commands/job/spec/jobCommand.spec.js +406 -251
- package/build/utils/auth.js +8 -1
- package/package.json +3 -3
|
@@ -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: "
|
|
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"));
|
|
178
178
|
throw e;
|
|
179
179
|
})];
|
|
180
180
|
case 1:
|
|
@@ -221,7 +221,7 @@ function getBuildInfo(target, streamWeb) {
|
|
|
221
221
|
];
|
|
222
222
|
case 5:
|
|
223
223
|
dependencyFilePathsForCreateFile = _a.sent();
|
|
224
|
-
return [4 /*yield*/, (0, utils_1.readFile)("".concat((0, config_1.getMacroCorePath)(), "/base/
|
|
224
|
+
return [4 /*yield*/, (0, utils_1.readFile)("".concat((0, config_1.getMacroCorePath)(), "/base/mp_replace.sas"))];
|
|
225
225
|
case 6:
|
|
226
226
|
gsubScript = _a.sent();
|
|
227
227
|
buildConfig += "".concat(gsubScript, "\n");
|
|
@@ -4,7 +4,7 @@ exports.getLaunchPageCode = void 0;
|
|
|
4
4
|
var error_1 = require("@sasjs/utils/error");
|
|
5
5
|
var types_1 = require("@sasjs/utils/types");
|
|
6
6
|
var SAS9Code = function (streamServiceName) { return "\noptions notes;\ndata _null_;\n format url $256.;\n rc=METADATA_GETURI(\"Stored Process Web App\",url);\n url=coalescec(url,\"localhost/SASStoredProcess\");\n urlEscaped = tranwrd(trim(url),\" \",\"%20\");\n putlog \"NOTE: SASjs Streaming App Created! Check it out here:\" ;\n putlog \"NOTE- \";putlog \"NOTE- \";putlog \"NOTE- \";putlog \"NOTE- \";\n putlog \"NOTE- \" urlEscaped +(-1) \"?_program=&appLoc/services/".concat(streamServiceName, "\" ;\n putlog \"NOTE- \";putlog \"NOTE- \";putlog \"NOTE- \";putlog \"NOTE- \";\nrun;\n"); };
|
|
7
|
-
var SASViyaCode = function (streamServiceName) { return "\n\n/**\n * The streamService we just deployed (as a _FILE) had the compile-time appLoc\n * In this section we replace with the deploy-time appLoc\n */\n\nfilename _homein filesrvc\n folderPath=\"&apploc/services\"\n filename=\"".concat(streamServiceName, ".html\"\n recfm=v\n lrecl=1048544;\n\n%let local_file=%sysfunc(pathname(work))/service.html;\nfilename _homeout \"&local_file\";\n\ndata _null_;\n rc=fcopy('_homein','_homeout');\n put rc=;\nrun;\n\n%
|
|
7
|
+
var SASViyaCode = function (streamServiceName) { return "\n\n/**\n * The streamService we just deployed (as a _FILE) had the compile-time appLoc\n * In this section we replace with the deploy-time appLoc\n */\n\nfilename _homein filesrvc\n folderPath=\"&apploc/services\"\n filename=\"".concat(streamServiceName, ".html\"\n recfm=v\n lrecl=1048544;\n\n%let local_file=%sysfunc(pathname(work))/service.html;\nfilename _homeout \"&local_file\";\n\ndata _null_;\n rc=fcopy('_homein','_homeout');\n put rc=;\nrun;\n\n%mp_replace(infile=\"&local_file\", findvar=compiled_apploc, replacevar=apploc)\n\ndata _null_;\n rc=fcopy('_homeout','_homein');\n put rc=;\nrun;\n\n/* Tell the user where the app was deployed so they can open it */\noptions notes;\ndata _null_;\n if symexist('_baseurl') then do;\n url=symget('_baseurl');\n if subpad(url,length(url)-9,9)='SASStudio'\n then url=substr(url,1,length(url)-11);\n else url=\"&systcpiphostname\";\n end;\n else url=\"&systcpiphostname\";\n url=cats(url,\"/SASJobExecution?_FILE=&appLoc/services/\");\n urlEscaped = tranwrd(trim(url),\" \",\"%20\");\n putlog \"NOTE: SASjs Streaming App Created! Check it out here:\" ;\n putlog \"NOTE- \";putlog \"NOTE- \";putlog \"NOTE- \";putlog \"NOTE- \";\n putlog \"NOTE- \" urlEscaped +(-1) '").concat(streamServiceName, ".html&_debug=2' ;\n putlog \"NOTE- \";putlog \"NOTE- \";putlog \"NOTE- \";putlog \"NOTE- \";\nrun;\n"); };
|
|
8
8
|
var getLaunchPageCode = function (serverType, streamServiceName) {
|
|
9
9
|
switch (serverType) {
|
|
10
10
|
case types_1.ServerType.SasViya:
|
|
@@ -12,3 +12,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./viya"), exports);
|
|
14
14
|
__exportStar(require("./sasjs"), exports);
|
|
15
|
+
__exportStar(require("./sas9"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import SASjs from '@sasjs/adapter/node';
|
|
2
|
+
/**
|
|
3
|
+
* Triggers an existing Stored Process for execution as a "job". See online documentation here: https://cli.sasjs.io/job/
|
|
4
|
+
* @param {object} sasjs - Configuration object of the SASJS adapter.
|
|
5
|
+
* @param {object} config - An object containing the username and password for authentication.
|
|
6
|
+
* @param {string} jobPath - Location of the Stored Process in SAS metadata (_program).
|
|
7
|
+
* @param {string | undefined} logFile - If provided, the CLI will write the log here.
|
|
8
|
+
* @param {string | undefined} output - If provided, and valid JSON is returned (ie using the SASjs macros), it will be written to this file location.
|
|
9
|
+
* @param {string | undefined} source - An optional path to a JSON file containing input macro variables.
|
|
10
|
+
*/
|
|
11
|
+
export declare function executeJobSas9(sasjs: SASjs, config: {
|
|
12
|
+
username: string;
|
|
13
|
+
password: string;
|
|
14
|
+
}, jobPath: string, logFile?: string, output?: string, source?: string): Promise<any>;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.executeJobSas9 = void 0;
|
|
43
|
+
var path_1 = __importDefault(require("path"));
|
|
44
|
+
var utils_1 = require("@sasjs/utils");
|
|
45
|
+
var file_1 = require("../../../../utils/file");
|
|
46
|
+
var displayResult_1 = require("../../../../utils/displayResult");
|
|
47
|
+
var utils_2 = require("../utils");
|
|
48
|
+
/**
|
|
49
|
+
* Triggers an existing Stored Process for execution as a "job". See online documentation here: https://cli.sasjs.io/job/
|
|
50
|
+
* @param {object} sasjs - Configuration object of the SASJS adapter.
|
|
51
|
+
* @param {object} config - An object containing the username and password for authentication.
|
|
52
|
+
* @param {string} jobPath - Location of the Stored Process in SAS metadata (_program).
|
|
53
|
+
* @param {string | undefined} logFile - If provided, the CLI will write the log here.
|
|
54
|
+
* @param {string | undefined} output - If provided, and valid JSON is returned (ie using the SASjs macros), it will be written to this file location.
|
|
55
|
+
* @param {string | undefined} source - An optional path to a JSON file containing input macro variables.
|
|
56
|
+
*/
|
|
57
|
+
function executeJobSas9(sasjs, config, jobPath, logFile, output, source) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
59
|
+
var macroVars, currentDirPath, startTime, result, endTime, outputJson, currentDirPath, outputPath, folderPath, parentFolderPath, error_1;
|
|
60
|
+
return __generator(this, function (_a) {
|
|
61
|
+
switch (_a.label) {
|
|
62
|
+
case 0:
|
|
63
|
+
macroVars = null;
|
|
64
|
+
if (!source) return [3 /*break*/, 3];
|
|
65
|
+
currentDirPath = path_1.default.isAbsolute(source) ? '' : process.projectDir;
|
|
66
|
+
source = path_1.default.join(currentDirPath, source);
|
|
67
|
+
if (!(0, file_1.isJsonFile)(source))
|
|
68
|
+
throw 'Source file has to be JSON.';
|
|
69
|
+
return [4 /*yield*/, (0, utils_1.fileExists)(source).catch(function (_) {
|
|
70
|
+
throw 'Error while checking if source file exists.';
|
|
71
|
+
})];
|
|
72
|
+
case 1:
|
|
73
|
+
_a.sent();
|
|
74
|
+
return [4 /*yield*/, (0, utils_1.readFile)(source).catch(function (_) {
|
|
75
|
+
throw 'Error while reading source file.';
|
|
76
|
+
})];
|
|
77
|
+
case 2:
|
|
78
|
+
source = _a.sent();
|
|
79
|
+
macroVars = JSON.parse(source);
|
|
80
|
+
if (!(0, utils_1.isMacroVars)(macroVars)) {
|
|
81
|
+
throw "Provided source is not valid. An example of valid source:\n{ macroVars: { name1: 'value1', name2: 'value2' } }";
|
|
82
|
+
}
|
|
83
|
+
_a.label = 3;
|
|
84
|
+
case 3:
|
|
85
|
+
startTime = new Date().getTime();
|
|
86
|
+
return [4 /*yield*/, sasjs.request(jobPath, macroVars, config)];
|
|
87
|
+
case 4:
|
|
88
|
+
result = _a.sent();
|
|
89
|
+
endTime = new Date().getTime();
|
|
90
|
+
if (!result) return [3 /*break*/, 15];
|
|
91
|
+
if (!(result.status === 200)) return [3 /*break*/, 14];
|
|
92
|
+
process.logger.success("Job executed successfully! in ".concat((endTime - startTime) / 1000, " seconds"));
|
|
93
|
+
if (!(!!logFile && result.log)) return [3 /*break*/, 6];
|
|
94
|
+
return [4 /*yield*/, (0, utils_2.saveLog)(result.log, logFile, jobPath, false)];
|
|
95
|
+
case 5:
|
|
96
|
+
_a.sent();
|
|
97
|
+
_a.label = 6;
|
|
98
|
+
case 6:
|
|
99
|
+
if (!(!!output && result.result)) return [3 /*break*/, 13];
|
|
100
|
+
_a.label = 7;
|
|
101
|
+
case 7:
|
|
102
|
+
_a.trys.push([7, 12, , 13]);
|
|
103
|
+
outputJson = JSON.stringify(result.result, null, 2);
|
|
104
|
+
currentDirPath = path_1.default.isAbsolute(output)
|
|
105
|
+
? ''
|
|
106
|
+
: process.projectDir;
|
|
107
|
+
outputPath = path_1.default.join(currentDirPath, /\.[a-z]{3,4}$/i.test(output)
|
|
108
|
+
? output
|
|
109
|
+
: path_1.default.join(output, 'output.json'));
|
|
110
|
+
folderPath = outputPath.split(path_1.default.sep);
|
|
111
|
+
folderPath.pop();
|
|
112
|
+
parentFolderPath = folderPath.join(path_1.default.sep);
|
|
113
|
+
return [4 /*yield*/, (0, utils_1.folderExists)(parentFolderPath)];
|
|
114
|
+
case 8:
|
|
115
|
+
if (!!(_a.sent())) return [3 /*break*/, 10];
|
|
116
|
+
return [4 /*yield*/, (0, utils_1.createFolder)(parentFolderPath)];
|
|
117
|
+
case 9:
|
|
118
|
+
_a.sent();
|
|
119
|
+
_a.label = 10;
|
|
120
|
+
case 10: return [4 /*yield*/, (0, utils_1.createFile)(outputPath, outputJson)];
|
|
121
|
+
case 11:
|
|
122
|
+
_a.sent();
|
|
123
|
+
(0, displayResult_1.displaySuccess)("Output saved to: ".concat(outputPath));
|
|
124
|
+
return [3 /*break*/, 13];
|
|
125
|
+
case 12:
|
|
126
|
+
error_1 = _a.sent();
|
|
127
|
+
(0, displayResult_1.displayError)(error_1, 'An error has occurred when parsing an output of the job.');
|
|
128
|
+
return [3 /*break*/, 13];
|
|
129
|
+
case 13: return [3 /*break*/, 15];
|
|
130
|
+
case 14:
|
|
131
|
+
process.logger.error(result.message);
|
|
132
|
+
process.logger.error(JSON.stringify(result.error, null, 2));
|
|
133
|
+
_a.label = 15;
|
|
134
|
+
case 15: return [2 /*return*/, result];
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
exports.executeJobSas9 = executeJobSas9;
|
|
@@ -7,5 +7,9 @@ export declare class JobCommand extends TargetCommand {
|
|
|
7
7
|
constructor(args: string[]);
|
|
8
8
|
execute(): Promise<ReturnCode>;
|
|
9
9
|
executeJobSasjs(sasjs: SASjs, target: Target): Promise<ReturnCode>;
|
|
10
|
+
executeJobSas9(sasjs: SASjs, target: Target, config: {
|
|
11
|
+
username: string;
|
|
12
|
+
password: string;
|
|
13
|
+
}): Promise<ReturnCode>;
|
|
10
14
|
executeJobViya(target: Target, sasjs: SASjs, authConfig: AuthConfig): Promise<ReturnCode>;
|
|
11
15
|
}
|
|
@@ -141,21 +141,14 @@ var JobCommand = /** @class */ (function (_super) {
|
|
|
141
141
|
return _this;
|
|
142
142
|
}
|
|
143
143
|
JobCommand.prototype.execute = function () {
|
|
144
|
-
var _a;
|
|
144
|
+
var _a, _b;
|
|
145
145
|
return __awaiter(this, void 0, void 0, function () {
|
|
146
|
-
var target, sasjs,
|
|
147
|
-
return __generator(this, function (
|
|
148
|
-
switch (
|
|
146
|
+
var target, sasjs, _c, authConfig, _d, username, password, _e, _f;
|
|
147
|
+
return __generator(this, function (_g) {
|
|
148
|
+
switch (_g.label) {
|
|
149
149
|
case 0: return [4 /*yield*/, this.getTargetInfo()];
|
|
150
150
|
case 1:
|
|
151
|
-
target = (
|
|
152
|
-
_b = target.serverType;
|
|
153
|
-
switch (_b) {
|
|
154
|
-
case utils_1.ServerType.SasViya: return [3 /*break*/, 2];
|
|
155
|
-
case utils_1.ServerType.Sasjs: return [3 /*break*/, 7];
|
|
156
|
-
}
|
|
157
|
-
return [3 /*break*/, 11];
|
|
158
|
-
case 2:
|
|
151
|
+
target = (_g.sent()).target;
|
|
159
152
|
sasjs = new node_1.default({
|
|
160
153
|
serverUrl: target.serverUrl,
|
|
161
154
|
httpsAgentOptions: target.httpsAgentOptions,
|
|
@@ -163,42 +156,74 @@ var JobCommand = /** @class */ (function (_super) {
|
|
|
163
156
|
serverType: target.serverType,
|
|
164
157
|
debug: true
|
|
165
158
|
});
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
159
|
+
_c = target.serverType;
|
|
160
|
+
switch (_c) {
|
|
161
|
+
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];
|
|
164
|
+
}
|
|
165
|
+
return [3 /*break*/, 15];
|
|
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 null;
|
|
170
|
+
})];
|
|
171
171
|
case 3:
|
|
172
|
-
authConfig =
|
|
172
|
+
authConfig = _g.sent();
|
|
173
173
|
if (!authConfig)
|
|
174
174
|
return [2 /*return*/, command_1.ReturnCode.InternalError];
|
|
175
175
|
if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 5];
|
|
176
176
|
return [4 /*yield*/, this.executeJobViya(target, sasjs, authConfig)];
|
|
177
177
|
case 4:
|
|
178
|
-
|
|
178
|
+
_d = _g.sent();
|
|
179
179
|
return [3 /*break*/, 6];
|
|
180
180
|
case 5:
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
case 6: return [2 /*return*/,
|
|
181
|
+
_d = command_1.ReturnCode.InvalidCommand;
|
|
182
|
+
_g.label = 6;
|
|
183
|
+
case 6: return [2 /*return*/, _d];
|
|
184
184
|
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 })];
|
|
202
|
+
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:
|
|
185
210
|
sasjs = new node_1.default({
|
|
186
211
|
serverType: target.serverType,
|
|
187
212
|
serverUrl: target.serverUrl
|
|
188
213
|
});
|
|
189
214
|
if (typeof this.parsed.jobPath !== 'string')
|
|
190
215
|
return [2 /*return*/, command_1.ReturnCode.InvalidCommand];
|
|
191
|
-
if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/,
|
|
216
|
+
if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 13];
|
|
192
217
|
return [4 /*yield*/, this.executeJobSasjs(sasjs, target)];
|
|
193
|
-
case
|
|
194
|
-
|
|
195
|
-
return [3 /*break*/,
|
|
196
|
-
case
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
case
|
|
200
|
-
case
|
|
201
|
-
(
|
|
218
|
+
case 12:
|
|
219
|
+
_f = _g.sent();
|
|
220
|
+
return [3 /*break*/, 14];
|
|
221
|
+
case 13:
|
|
222
|
+
_f = command_1.ReturnCode.InvalidCommand;
|
|
223
|
+
_g.label = 14;
|
|
224
|
+
case 14: return [2 /*return*/, _f];
|
|
225
|
+
case 15:
|
|
226
|
+
(_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.");
|
|
202
227
|
return [2 /*return*/, command_1.ReturnCode.InternalError];
|
|
203
228
|
}
|
|
204
229
|
});
|
|
@@ -225,6 +250,35 @@ var JobCommand = /** @class */ (function (_super) {
|
|
|
225
250
|
});
|
|
226
251
|
});
|
|
227
252
|
};
|
|
253
|
+
JobCommand.prototype.executeJobSas9 = function (sasjs, target, config) {
|
|
254
|
+
var _a;
|
|
255
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
256
|
+
var jobPath, log, output, source, returnCode;
|
|
257
|
+
return __generator(this, function (_b) {
|
|
258
|
+
switch (_b.label) {
|
|
259
|
+
case 0:
|
|
260
|
+
jobPath = (0, prefixAppLoc_1.prefixAppLoc)(target.appLoc, this.parsed.jobPath);
|
|
261
|
+
log = (0, getLogFilePath_1.getLogFilePath)(this.parsed.log, jobPath);
|
|
262
|
+
output = ((_a = this.parsed.output) === null || _a === void 0 ? void 0 : _a.length)
|
|
263
|
+
? this.parsed.output
|
|
264
|
+
: undefined;
|
|
265
|
+
source = this.parsed.source;
|
|
266
|
+
return [4 /*yield*/, (0, execute_1.executeJobSas9)(sasjs, config, jobPath, log, output, source)
|
|
267
|
+
.then(function () {
|
|
268
|
+
return command_1.ReturnCode.Success;
|
|
269
|
+
})
|
|
270
|
+
.catch(function (err) {
|
|
271
|
+
var _a;
|
|
272
|
+
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Error executing job: ', err);
|
|
273
|
+
return command_1.ReturnCode.InternalError;
|
|
274
|
+
})];
|
|
275
|
+
case 1:
|
|
276
|
+
returnCode = _b.sent();
|
|
277
|
+
return [2 /*return*/, returnCode];
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
};
|
|
228
282
|
JobCommand.prototype.executeJobViya = function (target, sasjs, authConfig) {
|
|
229
283
|
var _a, _b, _c;
|
|
230
284
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
3
|
if (k2 === undefined) k2 = k;
|
|
15
4
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
@@ -96,17 +85,37 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
96
85
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
97
86
|
var path_1 = __importDefault(require("path"));
|
|
98
87
|
var viyaExecuteModule = __importStar(require("../internal/execute/viya"));
|
|
88
|
+
var sas9ExecuteModule = __importStar(require("../internal/execute/sas9"));
|
|
89
|
+
var node_1 = __importDefault(require("@sasjs/adapter/node"));
|
|
99
90
|
var jobCommand_1 = require("../jobCommand");
|
|
100
91
|
var utils_1 = require("@sasjs/utils");
|
|
92
|
+
var SasjsUtilsFilesModule = __importStar(require("@sasjs/utils/file"));
|
|
101
93
|
var configUtils = __importStar(require("../../../utils/config"));
|
|
102
94
|
var command_1 = require("../../../types/command");
|
|
95
|
+
var utilsModule = __importStar(require("../internal/utils"));
|
|
103
96
|
var defaultArgs = ['node', 'sasjs', 'job', 'execute'];
|
|
104
|
-
var
|
|
97
|
+
var targetViya = new utils_1.Target({
|
|
105
98
|
name: 'test',
|
|
106
99
|
appLoc: '/Public/test/',
|
|
107
100
|
serverType: utils_1.ServerType.SasViya,
|
|
108
101
|
contextName: 'test context'
|
|
109
102
|
});
|
|
103
|
+
var target9 = new utils_1.Target({
|
|
104
|
+
name: 'test',
|
|
105
|
+
appLoc: '/Public/test/',
|
|
106
|
+
serverType: utils_1.ServerType.Sas9,
|
|
107
|
+
contextName: 'test context',
|
|
108
|
+
authConfigSas9: {
|
|
109
|
+
userName: 'testUser',
|
|
110
|
+
password: 'password'
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
var sas9TargetWithoutAuthConfig = new utils_1.Target({
|
|
114
|
+
name: 'test',
|
|
115
|
+
appLoc: '/Public/test/',
|
|
116
|
+
serverType: utils_1.ServerType.Sas9,
|
|
117
|
+
contextName: 'test context'
|
|
118
|
+
});
|
|
110
119
|
var authConfig = {};
|
|
111
120
|
var jobFileName = 'someJob';
|
|
112
121
|
var jobPath = "/Public/folder/".concat(jobFileName);
|
|
@@ -122,215 +131,351 @@ describe('JobCommand', function () {
|
|
|
122
131
|
return [2 /*return*/];
|
|
123
132
|
});
|
|
124
133
|
}); });
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
it('should parse sasjs job execute command', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
129
|
-
var _a;
|
|
130
|
-
return __generator(this, function (_b) {
|
|
131
|
-
switch (_b.label) {
|
|
132
|
-
case 0: return [4 /*yield*/, executeCommandWrapper([jobPath])];
|
|
133
|
-
case 1:
|
|
134
|
-
_b.sent();
|
|
135
|
-
(_a = expect(viyaExecuteModule.executeJobViya)).toHaveBeenCalledWith.apply(_a, __spreadArray([], __read(executeCalledWith({ jobPath: jobPath })), false));
|
|
136
|
-
return [2 /*return*/];
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
}); });
|
|
140
|
-
it('should pass wait as true if log flag with value is present', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
141
|
-
var _a;
|
|
142
|
-
return __generator(this, function (_b) {
|
|
143
|
-
switch (_b.label) {
|
|
144
|
-
case 0: return [4 /*yield*/, executeCommandWrapper([jobPath, '--log', log])];
|
|
145
|
-
case 1:
|
|
146
|
-
_b.sent();
|
|
147
|
-
(_a = expect(viyaExecuteModule.executeJobViya)).toHaveBeenCalledWith.apply(_a, __spreadArray([], __read(executeCalledWith({
|
|
148
|
-
jobPath: jobPath,
|
|
149
|
-
waitForJob: true,
|
|
150
|
-
logFile: path_1.default.join(projectFolder, log)
|
|
151
|
-
})), false));
|
|
152
|
-
return [2 /*return*/];
|
|
153
|
-
}
|
|
134
|
+
describe('for server type viya', function () {
|
|
135
|
+
beforeEach(function () {
|
|
136
|
+
setupMocksForViya();
|
|
154
137
|
});
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
138
|
+
it('should parse sasjs job execute command', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
139
|
+
var _a;
|
|
140
|
+
return __generator(this, function (_b) {
|
|
141
|
+
switch (_b.label) {
|
|
142
|
+
case 0: return [4 /*yield*/, executeCommandWrapper([jobPath])];
|
|
143
|
+
case 1:
|
|
144
|
+
_b.sent();
|
|
145
|
+
(_a = expect(viyaExecuteModule.executeJobViya)).toHaveBeenCalledWith.apply(_a, __spreadArray([], __read(executeCalledWith({ jobPath: jobPath })), false));
|
|
146
|
+
return [2 /*return*/];
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}); });
|
|
150
|
+
it('should pass wait as true if log flag with value is present', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
151
|
+
var _a;
|
|
152
|
+
return __generator(this, function (_b) {
|
|
153
|
+
switch (_b.label) {
|
|
154
|
+
case 0: return [4 /*yield*/, executeCommandWrapper([jobPath, '--log', log])];
|
|
155
|
+
case 1:
|
|
156
|
+
_b.sent();
|
|
157
|
+
(_a = expect(viyaExecuteModule.executeJobViya)).toHaveBeenCalledWith.apply(_a, __spreadArray([], __read(executeCalledWith({
|
|
158
|
+
jobPath: jobPath,
|
|
159
|
+
waitForJob: true,
|
|
160
|
+
logFile: path_1.default.join(projectFolder, log)
|
|
161
|
+
})), false));
|
|
162
|
+
return [2 /*return*/];
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}); });
|
|
166
|
+
it('should pass path for log file and wait to true if log flag without value is present', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
167
|
+
var _a;
|
|
168
|
+
return __generator(this, function (_b) {
|
|
169
|
+
switch (_b.label) {
|
|
170
|
+
case 0: return [4 /*yield*/, executeCommandWrapper([jobPath, '--log'])];
|
|
171
|
+
case 1:
|
|
172
|
+
_b.sent();
|
|
173
|
+
(_a = expect(viyaExecuteModule.executeJobViya)).toHaveBeenCalledWith.apply(_a, __spreadArray([], __read(executeCalledWith({
|
|
174
|
+
jobPath: jobPath,
|
|
175
|
+
waitForJob: true,
|
|
176
|
+
logFile: path_1.default.join(process.projectDir, "".concat(jobFileName, ".log"))
|
|
177
|
+
})), false));
|
|
178
|
+
return [2 /*return*/];
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}); });
|
|
182
|
+
it('should pass wait as true if returnStatusOnly flag is present', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
183
|
+
var _a;
|
|
184
|
+
return __generator(this, function (_b) {
|
|
185
|
+
switch (_b.label) {
|
|
186
|
+
case 0: return [4 /*yield*/, executeCommandWrapper([jobPath, '--returnStatusOnly'])];
|
|
187
|
+
case 1:
|
|
188
|
+
_b.sent();
|
|
189
|
+
(_a = expect(viyaExecuteModule.executeJobViya)).toHaveBeenCalledWith.apply(_a, __spreadArray([], __read(executeCalledWith({
|
|
190
|
+
jobPath: jobPath,
|
|
191
|
+
waitForJob: true,
|
|
192
|
+
returnStatusOnly: true
|
|
193
|
+
})), false));
|
|
194
|
+
return [2 /*return*/];
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}); });
|
|
198
|
+
it('should parse sasjs job execute command with all arguments', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
199
|
+
var _a;
|
|
200
|
+
return __generator(this, function (_b) {
|
|
201
|
+
switch (_b.label) {
|
|
202
|
+
case 0: return [4 /*yield*/, executeCommandWrapper([
|
|
203
|
+
jobPath,
|
|
204
|
+
'--target',
|
|
205
|
+
'test',
|
|
206
|
+
'--log',
|
|
207
|
+
log,
|
|
208
|
+
'--output',
|
|
209
|
+
output,
|
|
210
|
+
'--statusFile',
|
|
211
|
+
statusFile,
|
|
212
|
+
'--source',
|
|
213
|
+
source,
|
|
214
|
+
'--returnStatusOnly',
|
|
215
|
+
'--ignoreWarnings',
|
|
216
|
+
'--wait',
|
|
217
|
+
'--streamLog'
|
|
218
|
+
])];
|
|
219
|
+
case 1:
|
|
220
|
+
_b.sent();
|
|
221
|
+
(_a = expect(viyaExecuteModule.executeJobViya)).toHaveBeenCalledWith.apply(_a, __spreadArray([], __read(executeCalledWith({
|
|
222
|
+
jobPath: jobPath,
|
|
223
|
+
waitForJob: true,
|
|
224
|
+
output: output,
|
|
225
|
+
logFile: path_1.default.join(projectFolder, log),
|
|
226
|
+
statusFile: path_1.default.join(projectFolder, statusFile),
|
|
227
|
+
returnStatusOnly: true,
|
|
228
|
+
ignoreWarnings: true,
|
|
229
|
+
source: source,
|
|
230
|
+
streamLog: true
|
|
231
|
+
})), false));
|
|
232
|
+
return [2 /*return*/];
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}); });
|
|
236
|
+
it('should parse a sasjs job execute command with all shorthand arguments', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
237
|
+
var _a;
|
|
238
|
+
return __generator(this, function (_b) {
|
|
239
|
+
switch (_b.label) {
|
|
240
|
+
case 0: return [4 /*yield*/, executeCommandWrapper([
|
|
241
|
+
jobPath,
|
|
242
|
+
'-t',
|
|
243
|
+
'test',
|
|
244
|
+
'-l',
|
|
245
|
+
log,
|
|
246
|
+
'-o',
|
|
247
|
+
output,
|
|
248
|
+
'--statusFile',
|
|
249
|
+
statusFile,
|
|
250
|
+
'-s',
|
|
251
|
+
source,
|
|
252
|
+
'-r',
|
|
253
|
+
'-i',
|
|
254
|
+
'-w',
|
|
255
|
+
'--streamLog'
|
|
256
|
+
])];
|
|
257
|
+
case 1:
|
|
258
|
+
_b.sent();
|
|
259
|
+
(_a = expect(viyaExecuteModule.executeJobViya)).toHaveBeenCalledWith.apply(_a, __spreadArray([], __read(executeCalledWith({
|
|
260
|
+
jobPath: jobPath,
|
|
261
|
+
waitForJob: true,
|
|
262
|
+
output: output,
|
|
263
|
+
logFile: path_1.default.join(projectFolder, log),
|
|
264
|
+
statusFile: path_1.default.join(projectFolder, statusFile),
|
|
265
|
+
returnStatusOnly: true,
|
|
266
|
+
ignoreWarnings: true,
|
|
267
|
+
source: source,
|
|
268
|
+
streamLog: true
|
|
269
|
+
})), false));
|
|
270
|
+
return [2 /*return*/];
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}); });
|
|
274
|
+
it('should log success and return the success code when execution is successful', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
275
|
+
var returnCode;
|
|
276
|
+
return __generator(this, function (_a) {
|
|
277
|
+
switch (_a.label) {
|
|
278
|
+
case 0: return [4 /*yield*/, executeCommandWrapper([jobPath])];
|
|
279
|
+
case 1:
|
|
280
|
+
returnCode = _a.sent();
|
|
281
|
+
expect(returnCode).toEqual(command_1.ReturnCode.Success);
|
|
282
|
+
return [2 /*return*/];
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
}); });
|
|
286
|
+
it('should return the error code when getting Auth Config is unsuccessful', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
287
|
+
var returnCode;
|
|
288
|
+
return __generator(this, function (_a) {
|
|
289
|
+
switch (_a.label) {
|
|
290
|
+
case 0:
|
|
291
|
+
jest
|
|
292
|
+
.spyOn(configUtils, 'getAuthConfig')
|
|
293
|
+
.mockImplementation(function () { return Promise.reject(new Error('Test Error')); });
|
|
294
|
+
return [4 /*yield*/, executeCommandWrapper([jobPath])];
|
|
295
|
+
case 1:
|
|
296
|
+
returnCode = _a.sent();
|
|
297
|
+
expect(returnCode).toEqual(command_1.ReturnCode.InternalError);
|
|
298
|
+
expect(process.logger.error).toHaveBeenCalled();
|
|
299
|
+
return [2 /*return*/];
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
}); });
|
|
303
|
+
it('should log the error and return the error code when execution is unsuccessful', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
304
|
+
var returnCode;
|
|
305
|
+
return __generator(this, function (_a) {
|
|
306
|
+
switch (_a.label) {
|
|
307
|
+
case 0:
|
|
308
|
+
jest
|
|
309
|
+
.spyOn(viyaExecuteModule, 'executeJobViya')
|
|
310
|
+
.mockImplementation(function () { return Promise.reject(new Error('Test Error')); });
|
|
311
|
+
return [4 /*yield*/, executeCommandWrapper([jobPath])];
|
|
312
|
+
case 1:
|
|
313
|
+
returnCode = _a.sent();
|
|
314
|
+
expect(returnCode).toEqual(command_1.ReturnCode.InternalError);
|
|
315
|
+
expect(process.logger.error).toHaveBeenCalled();
|
|
316
|
+
return [2 /*return*/];
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
}); });
|
|
320
|
+
});
|
|
321
|
+
describe('for server type sas9', function () {
|
|
322
|
+
beforeEach(function () {
|
|
323
|
+
setupMocksForSAS9();
|
|
274
324
|
});
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
.
|
|
283
|
-
.
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
325
|
+
it('should return the error code when user credentials are not found', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
326
|
+
var username, password, returnCode;
|
|
327
|
+
return __generator(this, function (_a) {
|
|
328
|
+
switch (_a.label) {
|
|
329
|
+
case 0:
|
|
330
|
+
username = process.env.SAS_USERNAME;
|
|
331
|
+
password = process.env.SAS_PASSWORD;
|
|
332
|
+
process.env.SAS_USERNAME = '';
|
|
333
|
+
process.env.SAS_PASSWORD = '';
|
|
334
|
+
jest
|
|
335
|
+
.spyOn(configUtils, 'findTargetInConfiguration')
|
|
336
|
+
.mockImplementation(function () {
|
|
337
|
+
return Promise.resolve({
|
|
338
|
+
target: sas9TargetWithoutAuthConfig,
|
|
339
|
+
isLocal: true
|
|
340
|
+
});
|
|
287
341
|
});
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
342
|
+
return [4 /*yield*/, executeCommandWrapper([jobPath])];
|
|
343
|
+
case 1:
|
|
344
|
+
returnCode = _a.sent();
|
|
345
|
+
expect(returnCode).toEqual(command_1.ReturnCode.InternalError);
|
|
346
|
+
expect(process.logger.error).toHaveBeenCalled();
|
|
347
|
+
process.env.SAS_USERNAME = username;
|
|
348
|
+
process.env.SAS_PASSWORD = password;
|
|
349
|
+
return [2 /*return*/];
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
}); });
|
|
353
|
+
it('should log success and return the success code when execution is successful', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
354
|
+
var returnCode;
|
|
355
|
+
return __generator(this, function (_a) {
|
|
356
|
+
switch (_a.label) {
|
|
357
|
+
case 0:
|
|
358
|
+
jest
|
|
359
|
+
.spyOn(sas9ExecuteModule, 'executeJobSas9')
|
|
360
|
+
.mockImplementation(function () { return Promise.resolve(); });
|
|
361
|
+
return [4 /*yield*/, executeCommandWrapper([jobPath])];
|
|
362
|
+
case 1:
|
|
363
|
+
returnCode = _a.sent();
|
|
364
|
+
expect(returnCode).toEqual(command_1.ReturnCode.Success);
|
|
365
|
+
return [2 /*return*/];
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
}); });
|
|
369
|
+
it('should log the error and return the error code when execution is unsuccessful', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
370
|
+
var returnCode;
|
|
371
|
+
return __generator(this, function (_a) {
|
|
372
|
+
switch (_a.label) {
|
|
373
|
+
case 0:
|
|
374
|
+
jest
|
|
375
|
+
.spyOn(sas9ExecuteModule, 'executeJobSas9')
|
|
376
|
+
.mockImplementation(function () { return Promise.reject(new Error('Test Error')); });
|
|
377
|
+
return [4 /*yield*/, executeCommandWrapper([jobPath])];
|
|
378
|
+
case 1:
|
|
379
|
+
returnCode = _a.sent();
|
|
380
|
+
expect(returnCode).toEqual(command_1.ReturnCode.InternalError);
|
|
381
|
+
expect(process.logger.error).toHaveBeenCalled();
|
|
382
|
+
return [2 /*return*/];
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
}); });
|
|
386
|
+
it('should log success and return the success code with source argument', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
387
|
+
var returnCode;
|
|
388
|
+
return __generator(this, function (_a) {
|
|
389
|
+
switch (_a.label) {
|
|
390
|
+
case 0: return [4 /*yield*/, executeCommandWrapper([
|
|
391
|
+
jobPath,
|
|
392
|
+
'--source',
|
|
393
|
+
'testSource/source.json'
|
|
394
|
+
])];
|
|
395
|
+
case 1:
|
|
396
|
+
returnCode = _a.sent();
|
|
397
|
+
expect(returnCode).toEqual(command_1.ReturnCode.Success);
|
|
398
|
+
return [2 /*return*/];
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
}); });
|
|
402
|
+
it('should log the error and return the error code when source argument is provide but source file does not exists', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
403
|
+
var returnCode;
|
|
404
|
+
return __generator(this, function (_a) {
|
|
405
|
+
switch (_a.label) {
|
|
406
|
+
case 0: return [4 /*yield*/, executeCommandWrapper([
|
|
407
|
+
jobPath,
|
|
408
|
+
'--source',
|
|
409
|
+
'source.json'
|
|
410
|
+
])];
|
|
411
|
+
case 1:
|
|
412
|
+
returnCode = _a.sent();
|
|
413
|
+
expect(returnCode).toEqual(command_1.ReturnCode.InternalError);
|
|
414
|
+
expect(process.logger.error).toHaveBeenCalled();
|
|
415
|
+
return [2 /*return*/];
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
}); });
|
|
419
|
+
it('should log the error and return the error code when source argument is provide but source does not contain valid macroVars', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
420
|
+
var returnCode;
|
|
421
|
+
return __generator(this, function (_a) {
|
|
422
|
+
switch (_a.label) {
|
|
423
|
+
case 0: return [4 /*yield*/, executeCommandWrapper([
|
|
424
|
+
jobPath,
|
|
425
|
+
'--source',
|
|
426
|
+
'testSource/invalid.json'
|
|
427
|
+
])];
|
|
428
|
+
case 1:
|
|
429
|
+
returnCode = _a.sent();
|
|
430
|
+
expect(returnCode).toEqual(command_1.ReturnCode.InternalError);
|
|
431
|
+
expect(process.logger.error).toHaveBeenCalled();
|
|
432
|
+
return [2 /*return*/];
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
}); });
|
|
436
|
+
it('should log success and return the success code with log argument', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
437
|
+
var returnCode;
|
|
438
|
+
return __generator(this, function (_a) {
|
|
439
|
+
switch (_a.label) {
|
|
440
|
+
case 0:
|
|
441
|
+
jest
|
|
442
|
+
.spyOn(utilsModule, 'saveLog')
|
|
443
|
+
.mockImplementation(function () { return Promise.resolve(); });
|
|
444
|
+
return [4 /*yield*/, executeCommandWrapper([
|
|
445
|
+
jobPath,
|
|
446
|
+
'--log',
|
|
447
|
+
'sample.log'
|
|
448
|
+
])];
|
|
449
|
+
case 1:
|
|
450
|
+
returnCode = _a.sent();
|
|
451
|
+
expect(returnCode).toEqual(command_1.ReturnCode.Success);
|
|
452
|
+
return [2 /*return*/];
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
}); });
|
|
456
|
+
it('should log success and return the success code with output argument', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
457
|
+
var returnCode;
|
|
458
|
+
return __generator(this, function (_a) {
|
|
459
|
+
switch (_a.label) {
|
|
460
|
+
case 0:
|
|
461
|
+
jest
|
|
462
|
+
.spyOn(SasjsUtilsFilesModule, 'createFile')
|
|
463
|
+
.mockImplementation(function () { return Promise.resolve(); });
|
|
464
|
+
return [4 /*yield*/, executeCommandWrapper([
|
|
465
|
+
jobPath,
|
|
466
|
+
'--output',
|
|
467
|
+
'output.json'
|
|
468
|
+
])];
|
|
469
|
+
case 1:
|
|
470
|
+
returnCode = _a.sent();
|
|
471
|
+
expect(returnCode).toEqual(command_1.ReturnCode.Success);
|
|
472
|
+
return [2 /*return*/];
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
}); });
|
|
476
|
+
});
|
|
332
477
|
});
|
|
333
|
-
var
|
|
478
|
+
var setupMocksForViya = function () {
|
|
334
479
|
jest.resetAllMocks();
|
|
335
480
|
jest.mock('../internal/execute');
|
|
336
481
|
jest.mock('../../../utils/config');
|
|
@@ -339,20 +484,40 @@ var setupMocks = function () {
|
|
|
339
484
|
.mockImplementation(function () { return Promise.resolve(); });
|
|
340
485
|
jest
|
|
341
486
|
.spyOn(configUtils, 'findTargetInConfiguration')
|
|
342
|
-
.mockImplementation(function () {
|
|
487
|
+
.mockImplementation(function () {
|
|
488
|
+
return Promise.resolve({ target: targetViya, isLocal: true });
|
|
489
|
+
});
|
|
343
490
|
jest
|
|
344
491
|
.spyOn(configUtils, 'getAuthConfig')
|
|
345
492
|
.mockImplementation(function () { return Promise.resolve(authConfig); });
|
|
346
493
|
process.logger = new utils_1.Logger(utils_1.LogLevel.Off);
|
|
347
494
|
jest.spyOn(process.logger, 'error');
|
|
348
495
|
};
|
|
496
|
+
var setupMocksForSAS9 = function () {
|
|
497
|
+
jest.resetAllMocks();
|
|
498
|
+
jest.mock('../internal/execute');
|
|
499
|
+
jest.spyOn(node_1.default.prototype, 'request').mockImplementation(function () {
|
|
500
|
+
return Promise.resolve({
|
|
501
|
+
status: 200,
|
|
502
|
+
result: { data: 'test data' },
|
|
503
|
+
log: 'test log'
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
|
+
jest
|
|
507
|
+
.spyOn(configUtils, 'findTargetInConfiguration')
|
|
508
|
+
.mockImplementation(function () {
|
|
509
|
+
return Promise.resolve({ target: target9, isLocal: true });
|
|
510
|
+
});
|
|
511
|
+
process.logger = new utils_1.Logger(utils_1.LogLevel.Off);
|
|
512
|
+
jest.spyOn(process.logger, 'error');
|
|
513
|
+
};
|
|
349
514
|
var executeCalledWith = function (_a) {
|
|
350
515
|
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;
|
|
351
516
|
return [
|
|
352
517
|
expect.anything(),
|
|
353
518
|
authConfig,
|
|
354
519
|
jobPath,
|
|
355
|
-
|
|
520
|
+
targetViya,
|
|
356
521
|
waitForJob,
|
|
357
522
|
output,
|
|
358
523
|
logFile,
|
|
@@ -363,36 +528,26 @@ var executeCalledWith = function (_a) {
|
|
|
363
528
|
streamLog
|
|
364
529
|
];
|
|
365
530
|
};
|
|
366
|
-
var executeCommandWrapper = function (additionalParams,
|
|
367
|
-
|
|
368
|
-
return
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
if (!checkTarget) return [3 /*break*/, 3];
|
|
388
|
-
return [4 /*yield*/, command.getTargetInfo()];
|
|
389
|
-
case 2:
|
|
390
|
-
targetInfo = _a.sent();
|
|
391
|
-
expect(targetInfo.target).toEqual(target);
|
|
392
|
-
expect(targetInfo.isLocal).toBeTrue();
|
|
393
|
-
_a.label = 3;
|
|
394
|
-
case 3: return [2 /*return*/, returnCode];
|
|
395
|
-
}
|
|
396
|
-
});
|
|
531
|
+
var executeCommandWrapper = function (additionalParams) { return __awaiter(void 0, void 0, void 0, function () {
|
|
532
|
+
var subCommand, args, command, returnCode;
|
|
533
|
+
return __generator(this, function (_a) {
|
|
534
|
+
switch (_a.label) {
|
|
535
|
+
case 0:
|
|
536
|
+
subCommand = 'execute';
|
|
537
|
+
args = __spreadArray(__spreadArray([], __read(defaultArgs), false), __read(additionalParams), false).map(function (arg) {
|
|
538
|
+
if (arg === 'execute') {
|
|
539
|
+
arg = Math.random() > 0.5 ? 'exec' : arg;
|
|
540
|
+
subCommand = arg;
|
|
541
|
+
}
|
|
542
|
+
return arg;
|
|
543
|
+
});
|
|
544
|
+
command = new jobCommand_1.JobCommand(args);
|
|
545
|
+
return [4 /*yield*/, command.execute()];
|
|
546
|
+
case 1:
|
|
547
|
+
returnCode = _a.sent();
|
|
548
|
+
expect(command.name).toEqual('job');
|
|
549
|
+
expect(command.subCommand).toEqual(subCommand);
|
|
550
|
+
return [2 /*return*/, returnCode];
|
|
551
|
+
}
|
|
397
552
|
});
|
|
398
|
-
};
|
|
553
|
+
}); };
|
package/build/utils/auth.js
CHANGED
|
@@ -124,7 +124,14 @@ 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
|
|
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
|
+
})];
|
|
128
135
|
case 2:
|
|
129
136
|
_a = _b.sent(), access_token = _a.access_token, refresh_token = _a.refresh_token;
|
|
130
137
|
return [2 /*return*/, { access_token: access_token, refresh_token: refresh_token }];
|
package/package.json
CHANGED
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@sasjs/adapter": "3.7.
|
|
51
|
-
"@sasjs/core": "4.
|
|
50
|
+
"@sasjs/adapter": "3.7.8",
|
|
51
|
+
"@sasjs/core": "4.13.0",
|
|
52
52
|
"@sasjs/lint": "1.11.2",
|
|
53
53
|
"@sasjs/utils": "2.36.0",
|
|
54
54
|
"chalk": "4.1.2",
|
|
@@ -94,5 +94,5 @@
|
|
|
94
94
|
"typescript": "4.5.4",
|
|
95
95
|
"util": "0.12.4"
|
|
96
96
|
},
|
|
97
|
-
"version": "3.
|
|
97
|
+
"version": "3.8.2"
|
|
98
98
|
}
|