@sasjs/cli 3.6.5 → 3.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,10 @@
1
1
  import SASjs from '@sasjs/adapter/node';
2
2
  import { Target } from '@sasjs/utils';
3
+ /**
4
+ * Deploys app to serverUrl/appLoc mentioned in specified target.
5
+ * @param {Target} target- the target having deploy configuration.
6
+ * @param {boolean} isLocal- flag indicating if specified target is
7
+ * from local sasjsconfig or global sasjsconfig file.
8
+ * @param {object} sasjs - optional configuration object of SAS adapter.
9
+ */
3
10
  export declare function deploy(target: Target, isLocal: boolean, sasjs?: SASjs): Promise<void>;
@@ -49,6 +49,13 @@ var utils_2 = require("@sasjs/utils");
49
49
  var file_1 = require("../../utils/file");
50
50
  var getDeployScripts_1 = require("./internal/getDeployScripts");
51
51
  var deployToSasViyaWithServicePack_1 = require("../shared/deployToSasViyaWithServicePack");
52
+ /**
53
+ * Deploys app to serverUrl/appLoc mentioned in specified target.
54
+ * @param {Target} target- the target having deploy configuration.
55
+ * @param {boolean} isLocal- flag indicating if specified target is
56
+ * from local sasjsconfig or global sasjsconfig file.
57
+ * @param {object} sasjs - optional configuration object of SAS adapter.
58
+ */
52
59
  function deploy(target, isLocal, sasjs) {
53
60
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
54
61
  return __awaiter(this, void 0, void 0, function () {
@@ -83,12 +90,12 @@ function deploy(target, isLocal, sasjs) {
83
90
  buildDestinationFolder = process.sasjsConstants.buildDestinationFolder;
84
91
  logFilePath = buildDestinationFolder;
85
92
  if (!(target.serverType === utils_2.ServerType.Sasjs)) return [3 /*break*/, 5];
86
- return [4 /*yield*/, deployToSasjs(target, sasjs)];
93
+ return [4 /*yield*/, deployToSasjs(target, isLocal, sasjs)];
87
94
  case 4:
88
95
  _k.sent();
89
96
  return [3 /*break*/, 7];
90
97
  case 5: return [4 /*yield*/, (0, utils_2.asyncForEach)(deployScripts, function (deployScript) { return __awaiter(_this, void 0, void 0, function () {
91
- var deployScriptPath, deployScriptFile, linesToExecute, streamConfig, logPath;
98
+ var deployScriptPath, deployScriptContent, linesToExecute, streamConfig, deployScriptName, logPath;
92
99
  var _a, _b, _c;
93
100
  return __generator(this, function (_d) {
94
101
  switch (_d.label) {
@@ -100,19 +107,20 @@ function deploy(target, isLocal, sasjs) {
100
107
  // split into lines
101
108
  ];
102
109
  case 1:
103
- deployScriptFile = _d.sent();
104
- linesToExecute = deployScriptFile
110
+ deployScriptContent = _d.sent();
111
+ linesToExecute = deployScriptContent
105
112
  .replace(/\r\n/g, '\n')
106
113
  .split('\n');
107
114
  return [4 /*yield*/, (0, config_1.getStreamConfig)(target)];
108
115
  case 2:
109
116
  streamConfig = _d.sent();
117
+ deployScriptName = path_1.default.basename(deployScript);
110
118
  if (!(target.serverType === utils_2.ServerType.SasViya)) return [3 /*break*/, 4];
111
- return [4 /*yield*/, deployToSasViya(deployScript, target, isLocal, linesToExecute, logFilePath, streamConfig)];
119
+ return [4 /*yield*/, deployToSasViya(deployScriptName, target, isLocal, linesToExecute, logFilePath, streamConfig)];
112
120
  case 3:
113
121
  _d.sent();
114
122
  return [3 /*break*/, 6];
115
- case 4: return [4 /*yield*/, deployToSas9(deployScript, target, linesToExecute, logFilePath, streamConfig)];
123
+ case 4: return [4 /*yield*/, deployToSas9(deployScriptName, target, linesToExecute, logFilePath, streamConfig)];
116
124
  case 5:
117
125
  _d.sent();
118
126
  _d.label = 6;
@@ -139,6 +147,14 @@ function deploy(target, isLocal, sasjs) {
139
147
  });
140
148
  }
141
149
  exports.deploy = deploy;
150
+ /**
151
+ * Returns configuration object of SAS Adapter and authentication configuration
152
+ * @param {Target} target- the target to get auth configuration from.
153
+ * @param {boolean} isLocal- flag indicating if specified target is
154
+ * from local sasjsconfig or global sasjsconfig file.
155
+ * @returns an object containing a SAS Adapter configuration object `sasjs`
156
+ * and auth configuration `authConfig`.
157
+ */
142
158
  function getSASjsAndAuthConfig(target, isLocal) {
143
159
  return __awaiter(this, void 0, void 0, function () {
144
160
  var sasjs, authConfig, e_1;
@@ -171,14 +187,26 @@ function getSASjsAndAuthConfig(target, isLocal) {
171
187
  });
172
188
  });
173
189
  }
174
- function deployToSasViya(deployScript, target, isLocal, linesToExecute, logFilePath, streamConfig) {
190
+ /**
191
+ * Deploys app to `SASVIYA` server through deployScript.
192
+ * @param {string} deployScriptName- name of deploy script.
193
+ * @param {Target} target- the target having deploy configuration.
194
+ * @param {boolean} isLocal- flag indicating if specified target is
195
+ * from local sasjsconfig or global sasjsconfig file.
196
+ * @param {string[]} linesToExecute - array of SAS code lines of deploy script to execute.
197
+ * @param {string} logFolder - optional path to log folder,
198
+ * log file name will be <deploy-script-name>.log
199
+ * @param {object} streamConfig - optional configuration object of StreamConfig
200
+ * for printing web app url on console.
201
+ */
202
+ function deployToSasViya(deployScriptName, target, isLocal, linesToExecute, logFolder, streamConfig) {
175
203
  var _a, _b, _c, _d, _e;
176
204
  return __awaiter(this, void 0, void 0, function () {
177
205
  var contextName, _f, sasjs, authConfig, executionResult, log, appLoc, webAppStreamUrl;
178
206
  return __generator(this, function (_g) {
179
207
  switch (_g.label) {
180
208
  case 0:
181
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.info("Sending ".concat(path_1.default.basename(deployScript), " to SAS server for execution."));
209
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.info("Sending ".concat(deployScriptName, " to SAS server for execution."));
182
210
  contextName = target.contextName;
183
211
  if (!contextName) {
184
212
  throw new Error('Compute Context Name is required for SAS Viya deployments.\n Please ensure that `contextName` is present in your build target configuration or in your .env file, and try again.\n');
@@ -186,7 +214,7 @@ function deployToSasViya(deployScript, target, isLocal, linesToExecute, logFileP
186
214
  return [4 /*yield*/, getSASjsAndAuthConfig(target, isLocal)];
187
215
  case 1:
188
216
  _f = _g.sent(), sasjs = _f.sasjs, authConfig = _f.authConfig;
189
- return [4 /*yield*/, sasjs.executeScriptSASViya(path_1.default.basename(deployScript), linesToExecute, contextName, authConfig)];
217
+ return [4 /*yield*/, sasjs.executeScriptSASViya(deployScriptName, linesToExecute, contextName, authConfig)];
190
218
  case 2:
191
219
  executionResult = _g.sent();
192
220
  try {
@@ -200,26 +228,37 @@ function deployToSasViya(deployScript, target, isLocal, linesToExecute, logFileP
200
228
  (_b = process.logger) === null || _b === void 0 ? void 0 : _b.error("An error occurred when parsing the execution response: ".concat(e.message));
201
229
  log = executionResult;
202
230
  }
203
- if (!logFilePath) return [3 /*break*/, 4];
204
- return [4 /*yield*/, (0, utils_2.createFile)(path_1.default.join(logFilePath, "".concat(path_1.default.basename(deployScript).replace('.sas', ''), ".log")), log)];
231
+ if (!logFolder) return [3 /*break*/, 4];
232
+ return [4 /*yield*/, (0, utils_2.createFile)(path_1.default.join(logFolder, "".concat(deployScriptName.replace('.sas', ''), ".log")), log)];
205
233
  case 3:
206
234
  _g.sent();
207
- (_c = process.logger) === null || _c === void 0 ? void 0 : _c.success("Deployment completed! Log is available at ".concat(path_1.default.join(logFilePath, "".concat(path_1.default.basename(deployScript).replace('.sas', ''), ".log"))));
235
+ (_c = process.logger) === null || _c === void 0 ? void 0 : _c.success("Deployment completed! Log is available at ".concat(path_1.default.join(logFolder, "".concat(deployScriptName.replace('.sas', ''), ".log"))));
236
+ return [3 /*break*/, 5];
237
+ case 4:
238
+ (_d = process.logger) === null || _d === void 0 ? void 0 : _d.error('Unable to create log file.');
239
+ _g.label = 5;
240
+ case 5:
208
241
  if (streamConfig === null || streamConfig === void 0 ? void 0 : streamConfig.streamWeb) {
209
242
  appLoc = target.appLoc.replace(/\ /g, '%20');
210
243
  webAppStreamUrl = "".concat(target.serverUrl, "/SASJobExecution?_FILE=").concat(appLoc, "/services/").concat(streamConfig.streamServiceName, ".html&_debug=2");
211
- (_d = process.logger) === null || _d === void 0 ? void 0 : _d.info("Web app is available at ".concat(webAppStreamUrl));
244
+ (_e = process.logger) === null || _e === void 0 ? void 0 : _e.info("Web app is available at ".concat(webAppStreamUrl));
212
245
  }
213
- return [3 /*break*/, 5];
214
- case 4:
215
- (_e = process.logger) === null || _e === void 0 ? void 0 : _e.error('Unable to create log file.');
216
- _g.label = 5;
217
- case 5: return [2 /*return*/];
246
+ return [2 /*return*/];
218
247
  }
219
248
  });
220
249
  });
221
250
  }
222
- function deployToSas9(deployScript, target, linesToExecute, logFilePath, streamConfig) {
251
+ /**
252
+ * Deploys app to `SAS9` server through deployScript.
253
+ * @param {string} deployScriptName- name of deploy script.
254
+ * @param {Target} target- the target having deploy configuration.
255
+ * @param {string[]} linesToExecute - array of SAS code lines of deploy script to execute.
256
+ * @param {string} logFolder - optional path to log folder,
257
+ * log file name will be <deploy-script-name>.log
258
+ * @param {object} streamConfig - optional configuration object of StreamConfig
259
+ * for printing web app url on console.
260
+ */
261
+ function deployToSas9(deployScriptName, target, linesToExecute, logFolder, streamConfig) {
223
262
  var _a, _b, _c, _d;
224
263
  return __awaiter(this, void 0, void 0, function () {
225
264
  var username, password, sas9CredentialsError, sasjs, executionResult, appLoc, webAppStreamUrl;
@@ -256,55 +295,66 @@ function deployToSas9(deployScript, target, linesToExecute, logFilePath, streamC
256
295
  })];
257
296
  case 1:
258
297
  executionResult = _e.sent();
259
- if (!!executionResult) return [3 /*break*/, 2];
260
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Error getting execution log');
261
- return [3 /*break*/, 5];
298
+ if (!executionResult) return [3 /*break*/, 5];
299
+ if (!logFolder) return [3 /*break*/, 3];
300
+ return [4 /*yield*/, (0, utils_2.createFile)(path_1.default.join(logFolder, "".concat(deployScriptName.replace('.sas', ''), ".log")), executionResult !== null && executionResult !== void 0 ? executionResult : '')];
262
301
  case 2:
263
- if (!logFilePath) return [3 /*break*/, 4];
264
- return [4 /*yield*/, (0, utils_2.createFile)(path_1.default.join(logFilePath, "".concat(path_1.default.basename(deployScript).replace('.sas', ''), ".log")), executionResult !== null && executionResult !== void 0 ? executionResult : '')];
265
- case 3:
266
302
  _e.sent();
267
- (_b = process.logger) === null || _b === void 0 ? void 0 : _b.success("Deployment completed! Log is available at ".concat(path_1.default.join(logFilePath, "".concat(path_1.default.basename(deployScript).replace('.sas', ''), ".log"))));
303
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.success("Deployment completed! Log is available at ".concat(path_1.default.join(logFolder, "".concat(deployScriptName.replace('.sas', ''), ".log"))));
304
+ return [3 /*break*/, 4];
305
+ case 3:
306
+ (_b = process.logger) === null || _b === void 0 ? void 0 : _b.error('Unable to create log file.');
307
+ _e.label = 4;
308
+ case 4:
268
309
  if (streamConfig === null || streamConfig === void 0 ? void 0 : streamConfig.streamWeb) {
269
310
  appLoc = target.appLoc.replace(/\ /g, '%20');
270
311
  webAppStreamUrl = "".concat(target.serverUrl, "/SASStoredProcess/?_PROGRAM=").concat(appLoc, "/services/").concat(streamConfig.streamServiceName);
271
312
  (_c = process.logger) === null || _c === void 0 ? void 0 : _c.info("Web app is available at ".concat(webAppStreamUrl));
272
313
  }
273
- return [3 /*break*/, 5];
274
- case 4:
275
- (_d = process.logger) === null || _d === void 0 ? void 0 : _d.error('Unable to create log file.');
276
- _e.label = 5;
277
- case 5: return [2 /*return*/];
314
+ return [3 /*break*/, 6];
315
+ case 5:
316
+ (_d = process.logger) === null || _d === void 0 ? void 0 : _d.error('Error getting execution log');
317
+ _e.label = 6;
318
+ case 6: return [2 /*return*/];
278
319
  }
279
320
  });
280
321
  });
281
322
  }
282
- function deployToSasjs(target, sasjs) {
323
+ /**
324
+ * Deploys app to `SASJS` server.
325
+ * @param {Target} target- the target having deploy configuration.
326
+ * @param {boolean} isLocal- flag indicating if specified target is
327
+ * from local sasjsconfig or global sasjsconfig file.
328
+ * @param {object} sasjs - optional configuration object of SAS adapter.
329
+ */
330
+ function deployToSasjs(target, isLocal, sasjs) {
283
331
  var _a, _b;
284
332
  return __awaiter(this, void 0, void 0, function () {
285
- var buildDestinationFolder, finalFilePathJSON, jsonContent, payload, result;
286
- return __generator(this, function (_c) {
287
- switch (_c.label) {
333
+ var buildDestinationFolder, finalFilePathJSON, jsonContent, payload, authConfig, result;
334
+ var _c;
335
+ return __generator(this, function (_d) {
336
+ switch (_d.label) {
288
337
  case 0:
289
338
  buildDestinationFolder = process.sasjsConstants.buildDestinationFolder;
290
339
  finalFilePathJSON = path_1.default.join(buildDestinationFolder, "".concat(target.name, ".json"));
291
340
  return [4 /*yield*/, (0, utils_2.readFile)(finalFilePathJSON)];
292
341
  case 1:
293
- jsonContent = _c.sent();
342
+ jsonContent = _d.sent();
294
343
  payload = JSON.parse(jsonContent);
295
- sasjs = sasjs
296
- ? sasjs
297
- : new node_1.default({
298
- serverType: target.serverType,
299
- serverUrl: target.serverUrl,
300
- appLoc: target.appLoc
301
- });
302
- return [4 /*yield*/, sasjs.deployToSASjs(payload).catch(function (err) {
303
- var _a;
304
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error(err);
305
- })];
344
+ if (!!sasjs) return [3 /*break*/, 3];
345
+ ;
346
+ return [4 /*yield*/, getSASjsAndAuthConfig(target, isLocal)];
306
347
  case 2:
307
- result = _c.sent();
348
+ (_c = _d.sent(), sasjs = _c.sasjs, authConfig = _c.authConfig);
349
+ _d.label = 3;
350
+ case 3: return [4 /*yield*/, sasjs
351
+ .deployToSASjs(payload, undefined, authConfig)
352
+ .catch(function (err) {
353
+ var _a;
354
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error(err);
355
+ })];
356
+ case 4:
357
+ result = _d.sent();
308
358
  if ((result === null || result === void 0 ? void 0 : result.status) === 'failure') {
309
359
  (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error(result.message);
310
360
  if (result.example) {
@@ -152,7 +152,7 @@ describe('sasjs cbd with server type SASJS', function () {
152
152
  ]
153
153
  }
154
154
  ]
155
- });
155
+ }, undefined, undefined);
156
156
  return [2 /*return*/];
157
157
  }
158
158
  });
@@ -830,7 +830,10 @@ function getAuthConfig(target) {
830
830
  ? undefined
831
831
  : secret;
832
832
  if (!secret) {
833
- throw new Error("Client secret was not found.\n Please make sure that the 'secret' property is set in your local .env file or in the correct target authConfig in your global ~".concat(path_1.default.sep, ".sasjsrc file."));
833
+ if (target.serverType === utils_1.ServerType.Sasjs)
834
+ secret = '';
835
+ else
836
+ throw new Error("Client secret was not found.\n Please make sure that the 'secret' property is set in your local .env file or in the correct target authConfig in your global ~".concat(path_1.default.sep, ".sasjsrc file."));
834
837
  }
835
838
  if (!(0, auth_1.isAccessTokenExpiring)(access_token)) return [3 /*break*/, 7];
836
839
  sasjs = new node_1.default({
package/package.json CHANGED
@@ -49,7 +49,7 @@
49
49
  "access": "public"
50
50
  },
51
51
  "dependencies": {
52
- "@sasjs/adapter": "3.4.1",
52
+ "@sasjs/adapter": "3.4.2",
53
53
  "@sasjs/core": "3.10.0",
54
54
  "@sasjs/lint": "1.11.2",
55
55
  "@sasjs/utils": "2.36.0",
@@ -97,5 +97,5 @@
97
97
  "typescript": "4.5.4",
98
98
  "util": "0.12.4"
99
99
  },
100
- "version": "3.6.5"
100
+ "version": "3.6.6"
101
101
  }