@sasjs/cli 3.15.2 → 3.16.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.
Files changed (42) hide show
  1. package/README.md +3 -0
  2. package/build/commands/add/addCredential.js +25 -18
  3. package/build/commands/add/addTarget.js +14 -9
  4. package/build/commands/add/spec/addTarget.spec.js +7 -0
  5. package/build/commands/build/build.js +4 -4
  6. package/build/commands/compile/internal/spec/compileTestFile.spec.js +5 -3
  7. package/build/commands/deploy/spec/cbd.spec.js +38 -17
  8. package/build/commands/testing/spec/testing.spec.js +5 -0
  9. package/build/commands/web/internal/createAssetServices.d.ts +11 -2
  10. package/build/commands/web/internal/createAssetServices.js +83 -92
  11. package/build/commands/web/internal/getAssetPath.d.ts +2 -0
  12. package/build/commands/web/internal/getAssetPath.js +17 -0
  13. package/build/commands/web/internal/modifyLinksInContent.d.ts +2 -0
  14. package/build/commands/web/internal/modifyLinksInContent.js +11 -0
  15. package/build/commands/web/internal/sas9/createClickMeService.d.ts +6 -0
  16. package/build/commands/web/internal/sas9/createClickMeService.js +91 -0
  17. package/build/commands/web/internal/sas9/generateAssetService.d.ts +7 -0
  18. package/build/commands/web/internal/sas9/generateAssetService.js +75 -0
  19. package/build/commands/web/internal/sas9/getWebServiceContent.d.ts +7 -0
  20. package/build/commands/web/internal/{getWebServiceContent.js → sas9/getWebServiceContent.js} +12 -8
  21. package/build/commands/web/internal/sas9/index.d.ts +3 -0
  22. package/build/commands/web/internal/sas9/index.js +15 -0
  23. package/build/commands/web/internal/sasViya/createClickMeFile.d.ts +6 -0
  24. package/build/commands/web/internal/sasViya/createClickMeFile.js +63 -0
  25. package/build/commands/web/internal/sasViya/index.d.ts +1 -0
  26. package/build/commands/web/internal/sasViya/index.js +13 -0
  27. package/build/commands/web/internal/sasjsout.d.ts +1 -1
  28. package/build/commands/web/internal/sasjsout.js +2 -1
  29. package/build/commands/web/internal/updateAllTags.d.ts +7 -4
  30. package/build/commands/web/internal/updateAllTags.js +5 -0
  31. package/build/commands/web/internal/updateLinkTag.d.ts +2 -4
  32. package/build/commands/web/internal/updateScriptTag.d.ts +2 -4
  33. package/build/commands/web/internal/updateScriptTag.js +32 -32
  34. package/build/commands/web/internal/updateStyleTag.d.ts +2 -4
  35. package/build/commands/web/internal/updateStyleTag.js +32 -32
  36. package/build/commands/web/web.js +30 -79
  37. package/build/constants.d.ts +1 -0
  38. package/build/utils/setConstants.js +4 -2
  39. package/build/utils/utils.d.ts +1 -0
  40. package/build/utils/utils.js +22 -1
  41. package/package.json +1 -1
  42. package/build/commands/web/internal/getWebServiceContent.d.ts +0 -2
@@ -68,47 +68,67 @@ exports.createAssetServices = void 0;
68
68
  var path_1 = __importDefault(require("path"));
69
69
  var utils_1 = require("@sasjs/utils");
70
70
  var lodash_uniqby_1 = __importDefault(require("lodash.uniqby"));
71
- var getWebServiceContent_1 = require("./getWebServiceContent");
72
- var createAssetServices = function (target, destinationPath, streamConfig) { return __awaiter(void 0, void 0, void 0, function () {
73
- var webSourcePath, streamWebFolder, assetPaths, assetPathMap;
74
- return __generator(this, function (_a) {
75
- switch (_a.label) {
76
- case 0:
77
- webSourcePath = streamConfig.webSourcePath, streamWebFolder = streamConfig.streamWebFolder, assetPaths = streamConfig.assetPaths;
78
- assetPathMap = [];
79
- return [4 /*yield*/, (0, utils_1.asyncForEach)(__spreadArray([path_1.default.join(process.projectDir, webSourcePath)], __read((assetPaths !== null && assetPaths !== void 0 ? assetPaths : [])), false), function (assetPath) { return __awaiter(void 0, void 0, void 0, function () {
80
- var fullAssetPath, assetPathExists, assetPathMapNested;
81
- var _a;
82
- return __generator(this, function (_b) {
83
- switch (_b.label) {
84
- case 0:
85
- fullAssetPath = path_1.default.isAbsolute(assetPath)
86
- ? assetPath
87
- : path_1.default.isAbsolute(webSourcePath)
88
- ? path_1.default.join(webSourcePath, assetPath)
89
- : path_1.default.join(process.projectDir, webSourcePath, assetPath);
90
- return [4 /*yield*/, (0, utils_1.folderExists)(fullAssetPath)];
91
- case 1:
92
- assetPathExists = _b.sent();
93
- if (!assetPathExists) {
94
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.warn("Assets path '".concat(fullAssetPath, "' present in 'streamConfig' doesn't exist."));
71
+ var getAssetPath_1 = require("./getAssetPath");
72
+ var sas9_1 = require("./sas9");
73
+ /**
74
+ * Creates all the asset services for web streaming.
75
+ * Also prepares an asset-path Map based on server type.
76
+ * @param {Target} target the target to create asset service.
77
+ * @param {string} destinationPath the location of web streaming files.
78
+ * @param {StreamConfig} streamConfig stream configuration to be used.
79
+ * @returns {AssetPathMap[]} list of all the sources specified along server based paths.
80
+ */
81
+ var createAssetServices = function (target, destinationPath, _a) {
82
+ var webSourcePath = _a.webSourcePath, streamWebFolder = _a.streamWebFolder, assetPaths = _a.assetPaths;
83
+ return __awaiter(void 0, void 0, void 0, function () {
84
+ var assetPathMap;
85
+ return __generator(this, function (_b) {
86
+ switch (_b.label) {
87
+ case 0:
88
+ assetPathMap = [];
89
+ return [4 /*yield*/, (0, utils_1.asyncForEach)(__spreadArray([path_1.default.join(process.projectDir, webSourcePath)], __read((assetPaths !== null && assetPaths !== void 0 ? assetPaths : [])), false), function (assetPath) { return __awaiter(void 0, void 0, void 0, function () {
90
+ var fullAssetPath, assetPathExists, assetPathMapNested;
91
+ var _a;
92
+ return __generator(this, function (_b) {
93
+ switch (_b.label) {
94
+ case 0:
95
+ fullAssetPath = path_1.default.isAbsolute(assetPath)
96
+ ? assetPath
97
+ : path_1.default.isAbsolute(webSourcePath)
98
+ ? path_1.default.join(webSourcePath, assetPath)
99
+ : path_1.default.join(process.projectDir, webSourcePath, assetPath);
100
+ return [4 /*yield*/, (0, utils_1.folderExists)(fullAssetPath)];
101
+ case 1:
102
+ assetPathExists = _b.sent();
103
+ if (!assetPathExists) {
104
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.warn("Assets path '".concat(fullAssetPath, "' present in 'streamConfig' doesn't exist."));
105
+ return [2 /*return*/];
106
+ }
107
+ return [4 /*yield*/, createAssetsServicesNested(target, streamWebFolder, fullAssetPath, destinationPath)];
108
+ case 2:
109
+ assetPathMapNested = _b.sent();
110
+ assetPathMap.push.apply(assetPathMap, __spreadArray([], __read(assetPathMapNested), false));
95
111
  return [2 /*return*/];
96
- }
97
- return [4 /*yield*/, createAssetsServicesNested(target, streamWebFolder, fullAssetPath, destinationPath)];
98
- case 2:
99
- assetPathMapNested = _b.sent();
100
- assetPathMap.push.apply(assetPathMap, __spreadArray([], __read(assetPathMapNested), false));
101
- return [2 /*return*/];
102
- }
103
- });
104
- }); })];
105
- case 1:
106
- _a.sent();
107
- return [2 /*return*/, (0, lodash_uniqby_1.default)(assetPathMap, 'source')];
108
- }
112
+ }
113
+ });
114
+ }); })];
115
+ case 1:
116
+ _b.sent();
117
+ return [2 /*return*/, (0, lodash_uniqby_1.default)(assetPathMap, 'source')];
118
+ }
119
+ });
109
120
  });
110
- }); };
121
+ };
111
122
  exports.createAssetServices = createAssetServices;
123
+ /**
124
+ * Creates all the asset services for web streaming for a specific folder.
125
+ * Also prepares an asset-path Map based on server type.
126
+ * @param {Target} target the target to create asset service.
127
+ * @param {string} streamWebFolder the location of web streaming files.
128
+ * @param {string} fullAssetPath path of the specific folder used to create all services for.
129
+ * @param {string} destinationPath path of the destination folder for services.
130
+ * @returns {AssetPathMap[]} list of all the sources specified along server based paths.
131
+ */
112
132
  var createAssetsServicesNested = function (target, streamWebFolder, fullAssetPath, destinationPath) { return __awaiter(void 0, void 0, void 0, function () {
113
133
  var assetPathMap, filePaths, folderNames;
114
134
  return __generator(this, function (_a) {
@@ -119,37 +139,42 @@ var createAssetsServicesNested = function (target, streamWebFolder, fullAssetPat
119
139
  case 1:
120
140
  filePaths = _a.sent();
121
141
  return [4 /*yield*/, (0, utils_1.asyncForEach)(filePaths, function (filePath) { return __awaiter(void 0, void 0, void 0, function () {
122
- var fullFileName, fileName, fileExtension, sourcePath, assetServiceUrl, fileName_1, assetServiceUrl;
123
- return __generator(this, function (_a) {
124
- switch (_a.label) {
142
+ var fullFileName, fileName, fileExtension, sourcePath, assetServiceUrl, _a, fileName_1;
143
+ return __generator(this, function (_b) {
144
+ switch (_b.label) {
125
145
  case 0:
126
146
  fullFileName = path_1.default.basename(filePath);
127
147
  fileName = fullFileName.substring(0, fullFileName.lastIndexOf('.'));
128
148
  fileExtension = path_1.default
129
149
  .basename(filePath)
130
150
  .substring(fullFileName.lastIndexOf('.') + 1, fullFileName.length);
131
- if (!(fileName && fileExtension)) return [3 /*break*/, 4];
151
+ if (!(fileName && fileExtension)) return [3 /*break*/, 7];
132
152
  sourcePath = path_1.default.join(fullAssetPath, filePath);
133
- if (!(target.serverType === utils_1.ServerType.SasViya)) return [3 /*break*/, 2];
134
- return [4 /*yield*/, (0, utils_1.copy)(sourcePath, path_1.default.join(destinationPath, fullFileName))];
135
- case 1:
136
- _a.sent();
137
- assetServiceUrl = getAssetPath(target.appLoc, target.serverType, streamWebFolder, fullFileName);
138
- assetPathMap.push({
139
- source: fullFileName,
140
- target: assetServiceUrl
141
- });
142
- return [3 /*break*/, 4];
143
- case 2: return [4 /*yield*/, generateAssetService(sourcePath, filePath, destinationPath, target.serverType)];
144
- case 3:
145
- fileName_1 = _a.sent();
146
- assetServiceUrl = getAssetPath(target.appLoc, target.serverType, streamWebFolder, fileName_1.replace('.sas', ''));
153
+ assetServiceUrl = void 0;
154
+ _a = target.serverType;
155
+ switch (_a) {
156
+ case utils_1.ServerType.SasViya: return [3 /*break*/, 1];
157
+ case utils_1.ServerType.Sas9: return [3 /*break*/, 3];
158
+ }
159
+ return [3 /*break*/, 5];
160
+ case 1: return [4 /*yield*/, (0, utils_1.copy)(sourcePath, path_1.default.join(destinationPath, fullFileName))];
161
+ case 2:
162
+ _b.sent();
163
+ assetServiceUrl = (0, getAssetPath_1.getAssetPath)(target.appLoc, target.serverType, streamWebFolder, fullFileName);
164
+ return [3 /*break*/, 6];
165
+ case 3: return [4 /*yield*/, (0, sas9_1.generateAssetService)(sourcePath, destinationPath)];
166
+ case 4:
167
+ fileName_1 = _b.sent();
168
+ assetServiceUrl = (0, getAssetPath_1.getAssetPath)(target.appLoc, target.serverType, streamWebFolder, fileName_1.replace('.sas', ''));
169
+ return [3 /*break*/, 6];
170
+ case 5: throw new Error("Server Type: ".concat(target.serverType, " is not supported for processing streaming file."));
171
+ case 6:
147
172
  assetPathMap.push({
148
173
  source: fullFileName,
149
174
  target: assetServiceUrl
150
175
  });
151
- _a.label = 4;
152
- case 4: return [2 /*return*/];
176
+ _b.label = 7;
177
+ case 7: return [2 /*return*/];
153
178
  }
154
179
  });
155
180
  }); })];
@@ -187,37 +212,3 @@ var createAssetsServicesNested = function (target, streamWebFolder, fullAssetPat
187
212
  }
188
213
  });
189
214
  }); };
190
- var generateAssetService = function (sourcePath, filePath, destinationPath, serverType) { return __awaiter(void 0, void 0, void 0, function () {
191
- var fileExtension, fileType, fileName, base64string, serviceContent;
192
- return __generator(this, function (_a) {
193
- switch (_a.label) {
194
- case 0:
195
- fileExtension = path_1.default.extname(filePath);
196
- fileType = fileExtension.replace('.', '').toUpperCase();
197
- fileName = path_1.default
198
- .basename(filePath)
199
- .replace(new RegExp(fileExtension + '$'), fileExtension.replace('.', '-'));
200
- return [4 /*yield*/, (0, utils_1.base64EncodeFile)(sourcePath)];
201
- case 1:
202
- base64string = _a.sent();
203
- return [4 /*yield*/, (0, getWebServiceContent_1.getWebServiceContent)(base64string, fileType, serverType)];
204
- case 2:
205
- serviceContent = _a.sent();
206
- return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(destinationPath, "".concat(fileName, ".sas")), serviceContent)];
207
- case 3:
208
- _a.sent();
209
- return [2 /*return*/, "".concat(fileName, ".sas")];
210
- }
211
- });
212
- }); };
213
- var getAssetPath = function (appLoc, serverType, streamWebFolder, fileName) {
214
- var storedProcessPath =
215
- // the appLoc is inserted dynamically by SAS
216
- // using three forward slashes as a marker
217
- // for SAS 9 fileName is a program, with replacement in sasjsout.ts
218
- // for Viya, fileName is a FILE, with replacement in build.sas only
219
- serverType === utils_1.ServerType.SasViya
220
- ? "/SASJobExecution?_FILE=".concat(appLoc, "/services/").concat(streamWebFolder)
221
- : "/SASStoredProcess/?_PROGRAM=///".concat(streamWebFolder);
222
- return "".concat(storedProcessPath, "/").concat(fileName);
223
- };
@@ -0,0 +1,2 @@
1
+ import { ServerType } from '@sasjs/utils';
2
+ export declare const getAssetPath: (appLoc: string, serverType: ServerType, streamWebFolder: string, fileName: string) => string;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAssetPath = void 0;
4
+ var utils_1 = require("@sasjs/utils");
5
+ var getAssetPath = function (appLoc, serverType, streamWebFolder, fileName) {
6
+ var sas9GUID = process.sasjsConstants.sas9GUID;
7
+ var storedProcessPath =
8
+ // the appLoc is inserted dynamically
9
+ // for SAS 9 files are Base 64 encoded into STPs, with
10
+ // dynamic runtime replacement of appLoc (see sasjsout.ts)
11
+ // for Viya, fileName is a FILE, with replacement harcoded in build.sas
12
+ serverType === utils_1.ServerType.SasViya
13
+ ? "/SASJobExecution?_FILE=".concat(appLoc, "/services")
14
+ : "/SASStoredProcess/?_PROGRAM=".concat(sas9GUID);
15
+ return "".concat(storedProcessPath, "/").concat(streamWebFolder, "/").concat(fileName);
16
+ };
17
+ exports.getAssetPath = getAssetPath;
@@ -0,0 +1,2 @@
1
+ import { AssetPathMap } from './createAssetServices';
2
+ export declare const modifyLinksInContent: (_content: string, assetPathMap: AssetPathMap[]) => string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.modifyLinksInContent = void 0;
4
+ var modifyLinksInContent = function (_content, assetPathMap) {
5
+ var content = _content;
6
+ assetPathMap.forEach(function (pathEntry) {
7
+ content = content.replace(new RegExp(pathEntry.source, 'g'), pathEntry.target);
8
+ });
9
+ return content;
10
+ };
11
+ exports.modifyLinksInContent = modifyLinksInContent;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Creates index service file for SAS9 server only.
3
+ * @param {string} indexHtmlContent contents of index source file.
4
+ * @param {string} fileName name of index service file.
5
+ */
6
+ export declare const createClickMeService: (indexHtmlContent: string, fileName: string) => Promise<void>;
@@ -0,0 +1,91 @@
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.createClickMeService = void 0;
43
+ var path_1 = __importDefault(require("path"));
44
+ var utils_1 = require("@sasjs/utils");
45
+ var sasjsout_1 = require("../sasjsout");
46
+ /**
47
+ * Creates index service file for SAS9 server only.
48
+ * @param {string} indexHtmlContent contents of index source file.
49
+ * @param {string} fileName name of index service file.
50
+ */
51
+ var createClickMeService = function (indexHtmlContent, fileName) { return __awaiter(void 0, void 0, void 0, function () {
52
+ var lines, clickMeServiceContent, buildDestinationServicesFolder;
53
+ return __generator(this, function (_a) {
54
+ switch (_a.label) {
55
+ case 0:
56
+ lines = indexHtmlContent.replace(/\r\n/g, '\n').split('\n');
57
+ clickMeServiceContent = "".concat((0, sasjsout_1.sasjsout)(), "\nfilename sasjs temp lrecl=99999999;\ndata _null_;\nfile sasjs;\n");
58
+ lines.forEach(function (line) {
59
+ var chunkedLines = (0, utils_1.chunk)(line);
60
+ if (chunkedLines.length === 1) {
61
+ if (chunkedLines[0].length == 0)
62
+ chunkedLines[0] = ' ';
63
+ clickMeServiceContent += "put '".concat(chunkedLines[0]
64
+ .split("'")
65
+ .join("''"), "';\n");
66
+ }
67
+ else {
68
+ var combinedLines_1 = '';
69
+ chunkedLines.forEach(function (chunkedLine, index) {
70
+ var text = "put '".concat(chunkedLine.split("'").join("''"), "'");
71
+ if (index !== chunkedLines.length - 1) {
72
+ text += '@;\n';
73
+ }
74
+ else {
75
+ text += ';\n';
76
+ }
77
+ combinedLines_1 += text;
78
+ });
79
+ clickMeServiceContent += combinedLines_1;
80
+ }
81
+ });
82
+ clickMeServiceContent += 'run;\n%sasjsout(HTML)';
83
+ buildDestinationServicesFolder = process.sasjsConstants.buildDestinationServicesFolder;
84
+ return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(buildDestinationServicesFolder, "".concat(fileName, ".sas")), clickMeServiceContent)];
85
+ case 1:
86
+ _a.sent();
87
+ return [2 /*return*/];
88
+ }
89
+ });
90
+ }); };
91
+ exports.createClickMeService = createClickMeService;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Creates service file for SAS9 server only.
3
+ * @param {string} sourcePath path of source file.
4
+ * @param {string} destinationPath path of destination service file.
5
+ * @returns {string} name of created service file.
6
+ */
7
+ export declare const generateAssetService: (sourcePath: string, destinationPath: string) => Promise<string>;
@@ -0,0 +1,75 @@
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.generateAssetService = void 0;
43
+ var path_1 = __importDefault(require("path"));
44
+ var utils_1 = require("@sasjs/utils");
45
+ var _1 = require("./");
46
+ /**
47
+ * Creates service file for SAS9 server only.
48
+ * @param {string} sourcePath path of source file.
49
+ * @param {string} destinationPath path of destination service file.
50
+ * @returns {string} name of created service file.
51
+ */
52
+ var generateAssetService = function (sourcePath, destinationPath) { return __awaiter(void 0, void 0, void 0, function () {
53
+ var fileExtension, fileType, fileName, base64string, serviceContent;
54
+ return __generator(this, function (_a) {
55
+ switch (_a.label) {
56
+ case 0:
57
+ fileExtension = path_1.default.extname(sourcePath);
58
+ fileType = fileExtension.replace('.', '').toUpperCase();
59
+ fileName = path_1.default
60
+ .basename(sourcePath)
61
+ .replace(new RegExp(fileExtension + '$'), fileExtension.replace('.', '-'));
62
+ return [4 /*yield*/, (0, utils_1.base64EncodeFile)(sourcePath)];
63
+ case 1:
64
+ base64string = _a.sent();
65
+ return [4 /*yield*/, (0, _1.getWebServiceContent)(base64string, fileType)];
66
+ case 2:
67
+ serviceContent = _a.sent();
68
+ return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(destinationPath, "".concat(fileName, ".sas")), serviceContent)];
69
+ case 3:
70
+ _a.sent();
71
+ return [2 /*return*/, "".concat(fileName, ".sas")];
72
+ }
73
+ });
74
+ }); };
75
+ exports.generateAssetService = generateAssetService;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Prepares service code for SAS9 server only.
3
+ * @param {string} contentBase64 source code in base64.
4
+ * @param {string} type extension of source code's file in uppercase.
5
+ * @returns {string} service contents of provided source code.
6
+ */
7
+ export declare const getWebServiceContent: (contentBase64: string, type?: string) => Promise<string>;
@@ -38,8 +38,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.getWebServiceContent = void 0;
40
40
  var utils_1 = require("@sasjs/utils");
41
- var sasjsout_1 = require("./sasjsout");
42
- var getWebServiceContent = function (contentBase64, type, serverType) {
41
+ var sasjsout_1 = require("../sasjsout");
42
+ /**
43
+ * Prepares service code for SAS9 server only.
44
+ * @param {string} contentBase64 source code in base64.
45
+ * @param {string} type extension of source code's file in uppercase.
46
+ * @returns {string} service contents of provided source code.
47
+ */
48
+ var getWebServiceContent = function (contentBase64, type) {
43
49
  if (type === void 0) { type = 'JS'; }
44
50
  return __awaiter(void 0, void 0, void 0, function () {
45
51
  var lines, typesToEncode, serviceContent;
@@ -47,9 +53,10 @@ var getWebServiceContent = function (contentBase64, type, serverType) {
47
53
  lines = [contentBase64];
48
54
  typesToEncode = {
49
55
  JS: 'JS64',
50
- CSS: 'CSS64'
56
+ CSS: 'CSS64',
57
+ SVG: 'SVG64'
51
58
  };
52
- serviceContent = "".concat(sasjsout_1.sasjsout, "\nfilename sasjs temp lrecl=99999999;\ndata _null_;\nfile sasjs;\n");
59
+ serviceContent = "".concat((0, sasjsout_1.sasjsout)(), "\nfilename sasjs temp lrecl=99999999;\ndata _null_;\nfile sasjs;\n");
53
60
  lines.forEach(function (line) {
54
61
  var chunkedLines = (0, utils_1.chunk)(line);
55
62
  if (chunkedLines.length === 1) {
@@ -70,12 +77,9 @@ var getWebServiceContent = function (contentBase64, type, serverType) {
70
77
  serviceContent += combinedLines_1;
71
78
  }
72
79
  });
73
- if (serverType === utils_1.ServerType.Sas9 && typesToEncode.hasOwnProperty(type)) {
80
+ if (typesToEncode.hasOwnProperty(type)) {
74
81
  serviceContent += "\nrun;\n%sasjsout(".concat(typesToEncode[type], ")");
75
82
  }
76
- else {
77
- serviceContent += "\nrun;\n%sasjsout(".concat(type, ")");
78
- }
79
83
  return [2 /*return*/, serviceContent];
80
84
  });
81
85
  });
@@ -0,0 +1,3 @@
1
+ export * from './createClickMeService';
2
+ export * from './generateAssetService';
3
+ export * from './getWebServiceContent';
@@ -0,0 +1,15 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./createClickMeService"), exports);
14
+ __exportStar(require("./generateAssetService"), exports);
15
+ __exportStar(require("./getWebServiceContent"), exports);
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Creates index file for SASVIYA server only.
3
+ * @param {string} indexHtmlContent contents of index file.
4
+ * @param {string} fileName name of index file.
5
+ */
6
+ export declare const createClickMeFile: (indexHtmlContent: string, fileName: string) => Promise<void>;
@@ -0,0 +1,63 @@
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.createClickMeFile = void 0;
43
+ var utils_1 = require("@sasjs/utils");
44
+ var path_1 = __importDefault(require("path"));
45
+ /**
46
+ * Creates index file for SASVIYA server only.
47
+ * @param {string} indexHtmlContent contents of index file.
48
+ * @param {string} fileName name of index file.
49
+ */
50
+ var createClickMeFile = function (indexHtmlContent, fileName) { return __awaiter(void 0, void 0, void 0, function () {
51
+ var buildDestinationServicesFolder;
52
+ return __generator(this, function (_a) {
53
+ switch (_a.label) {
54
+ case 0:
55
+ buildDestinationServicesFolder = process.sasjsConstants.buildDestinationServicesFolder;
56
+ return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(buildDestinationServicesFolder, "".concat(fileName, ".html")), indexHtmlContent)];
57
+ case 1:
58
+ _a.sent();
59
+ return [2 /*return*/];
60
+ }
61
+ });
62
+ }); };
63
+ exports.createClickMeFile = createClickMeFile;
@@ -0,0 +1 @@
1
+ export * from './createClickMeFile';
@@ -0,0 +1,13 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./createClickMeFile"), exports);
@@ -1 +1 @@
1
- export declare const sasjsout = "\n%macro sasjsout(type,fref=sasjs);\n%global sysprocessmode SYS_JES_JOB_URI;\n%if \"&sysprocessmode\"=\"SAS Compute Server\" %then %do;\n %if &type=HTML %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name=\"_webout.json\"\n contenttype=\"text/html\";\n %end;\n %else %if &type=JS or &type=JS64 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.js'\n contenttype='application/javascript';\n %end;\n %else %if &type=CSS or &type=CSS64 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.css'\n contenttype='text/css';\n %end;\n %else %if &type=PNG or &type=GIF or &type=JPEG or &type=JPG %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\"\n name=\"_webout.%lowcase(&type)\"\n contenttype=\"image/%lowcase(&type)\" lrecl=2000000 recfm=n;\n %end;\n %else %if &type=ICO %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.ico'\n contenttype='image/vnd.microsoft.icon' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=JSON %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.json'\n contenttype='application/json' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=MP3 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.mp3'\n contenttype='audio/mpeg' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=WAV %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.wav'\n contenttype='audio/x-wav' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=OGG %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.ogg'\n contenttype='audio/ogg' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=WOFF or &type=WOFF2 or &type=TTF %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\"\n contenttype=\"font/%lowcase(&type)\";\n %end;\n %else %if &type=MP4 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\"\n contenttype=\"video/mp4\";\n %end;\n%end;\n%else %do;\n %if &type=JS or &type=JS64 %then %do;\n %let rc=%sysfunc(stpsrv_header(\n Content-type,application/javascript%str(;)charset=UTF-8\n ));\n %end;\n %else %if &type=CSS or &type=CSS64 %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,text/css));\n %end;\n %else %if &type=PNG or &type=GIF or &type=JPEG or &type=JPG %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,image/%lowcase(&type)));\n %end;\n %else %if &type=ICO %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,image/vnd.microsoft.icon));\n %end;\n %else %if &type=JSON %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,application/json));\n %end;\n %else %if &type=MP3 %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,audio/mpeg));\n %end;\n %else %if &type=WAV %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,audio/x-wav));\n %end;\n %else %if &type=OGG %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,audio/ogg));\n %end;\n %else %if &type=WOFF or &type=WOFF2 or &type=TTF %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,font/%lowcase(&type)));\n %end;\n %else %if &type=MP4 %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,video/mp4));\n %end;\n%end;\n%if &type=HTML %then %do;\n /*\n We need to perform some substitutions -eg to get the APPLOC and SERVERTYPE.\n Therefore the developer should avoid writing lines that exceed 32k\n characters (eg base64 encoded images) as they will get truncated when passing\n through the datastep. This could of course be re-written using LUA, removing\n the length restriction. Pull requests are welcome!\n */\n filename _sjs temp;\n data _null_;\n file _sjs lrecl=32767 encoding='utf-8';\n infile &fref lrecl=32767;\n input;\n length appLoc expanded_path $1048;\n if _n_=1 then do;\n retain pgm \"&_program\" appLoc expanded_path;\n /* index is deployed in the /services/ folder under the appLoc */\n appLoc=substr(pgm,1,find(pgm,'/services/')-1);\n expanded_path=cats('?_PROGRAM=',appLoc,'/services/');\n end;\n if find(_infile_,' appLoc: ') then put ' appLoc: ' apploc:$quote1048. ',';\n else if find(_infile_,' serverType: ') then do;\n if symexist('_metaperson') then put ' serverType: \"SAS9\" ,';\n else put ' serverType: \"SASVIYA\" ,';\n end;\n else if find(_infile_,' serverUrl: ') then do;\n /* nothing - we are streaming, so remove to default as hostname */\n end;\n else do;\n /* More recently, SASjs apps avoid inline JS to allow strict CSP */\n length infile in1 in2 $32767;\n infile=cats(_infile_);\n spos1=index(upcase(infile),'APPLOC=\"');\n if spos1>0 then do;\n in1=substr(infile,1,spos1+7);\n in2=subpad(infile,spos1+8);\n in2=substr(in2,index(in2,'\"'));\n infile=cats(in1,appLoc,in2);\n putlog \"new apploc: \" infile=;\n end;\n /* find & replace serverType in HTML attributes */\n spos2=index(upcase(infile),'SERVERTYPE=\"');\n if spos2>0 then do;\n in1=substr(infile,1,spos2+11);\n in2=subpad(infile,spos2+12);\n in2=substr(in2,index(in2,'\"'));\n if symexist('sasjsprocessmode') then infile=cats(in1,\"SASJS\",in2);\n else if \"&sysprocessmode\"=\"SAS Object Server\"\n or \"&sysprocessmode\"= \"SAS Compute Server\"\n then infile=cats(in1,\"SASVIYA\",in2);\n else infile=cats(in1,\"SAS9\",in2);\n putlog \"new servertype: \" infile=;\n end;\n /* find & replace serverUrl in HTML attributes */\n spos3=index(upcase(infile),'SERVERURL=\"');\n if spos3>0 then do;\n in1=substr(infile,1,spos3+10);\n in2=subpad(infile,spos3+11);\n in2=substr(in2,index(in2,'\"'));\n infile=cats(in1,in2);\n putlog \"new serverUrl: \" infile=;\n end;\n if sum(spos1,spos2,spos3)>0 then put infile;\n else do;\n /* during SAS9 sasjs compile, dependencies get three slashes /// */\n infile=tranwrd(_infile_,'?_PROGRAM=///',cats(expanded_path));\n put infile;\n end;\n end;\n run;\n %let fref=_sjs;\n%end;\n\n/**\n * In SAS9, JS & CSS files are base64 encoded to avoid UTF8 issues in WLATIN1\n * metadata - so in this case, decode and stream byte by byte.\n * */\n%if &type=GIF or &type=PNG or &type=JPG or &type=JPEG or &type=ICO or &type=MP3\nor &type=JS64 or &type=CSS64 or &type=WAV or &type=OGG or &type=WOFF\nor &type=WOFF2 or &type=TTF or &type=MP4\n%then %do;\n data _null_;\n length filein 8 fileout 8;\n filein = fopen(\"&fref\",'I',4,'B');\n fileout = fopen(\"_webout\",'A',1,'B');\n char= '20'x;\n do while(fread(filein)=0);\n length raw $4 ;\n do i=1 to 4;\n rc=fget(filein,char,1);\n substr(raw,i,1)=char;\n end;\n rc = fput(fileout, input(raw,$base64X4.));\n rc =fwrite(fileout);\n end;\n rc = fclose(filein);\n rc = fclose(fileout);\n run;\n%end;\n%else %do;\n data _null_;\n length filein 8 fileid 8;\n filein = fopen(\"&fref\",'I',1,'B');\n fileid = fopen(\"_webout\",'A',1,'B');\n rec = '20'x;\n do while(fread(filein)=0);\n rc = fget(filein,rec,1);\n rc = fput(fileid, rec);\n rc =fwrite(fileid);\n end;\n rc = fclose(filein);\n rc = fclose(fileid);\n run;\n%end;\n%mend;";
1
+ export declare const sasjsout: () => string;