@sasjs/adapter 5.1.1 → 5.1.3

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 (50) hide show
  1. package/ContextManager.js +2 -2
  2. package/README.md +14 -0
  3. package/SAS9ApiClient.d.ts +2 -3
  4. package/SAS9ApiClient.js +2 -2
  5. package/SASViyaApiClient.d.ts +0 -1
  6. package/SASViyaApiClient.js +11 -11
  7. package/SASjs.d.ts +6 -2
  8. package/SASjs.js +23 -23
  9. package/SASjsApiClient.d.ts +4 -4
  10. package/SASjsApiClient.js +2 -2
  11. package/SessionManager.js +1 -1
  12. package/api/viya/executeOnComputeApi.js +9 -10
  13. package/api/viya/pollJobState.js +3 -3
  14. package/api/viya/saveLog.js +1 -2
  15. package/api/viya/uploadTables.js +1 -2
  16. package/auth/AuthManager.js +2 -2
  17. package/auth/getAccessTokenForSasjs.js +1 -2
  18. package/auth/getAccessTokenForViya.js +1 -2
  19. package/auth/getTokens.js +3 -4
  20. package/auth/openWebPage.js +3 -4
  21. package/auth/refreshTokensForSasjs.js +1 -2
  22. package/auth/refreshTokensForViya.js +1 -2
  23. package/auth/verifySas9Login.js +1 -2
  24. package/auth/verifySasViyaLogin.js +3 -3
  25. package/dist/minified_sas9.js +103 -43
  26. package/dist/sasjs-adapter.js +7309 -7767
  27. package/job-execution/JesJobExecutor.js +2 -2
  28. package/job-execution/Sas9JobExecutor.d.ts +5 -1
  29. package/job-execution/Sas9JobExecutor.js +5 -0
  30. package/job-execution/SasjsJobExecutor.js +2 -2
  31. package/job-execution/WebJobExecutor.js +3 -3
  32. package/minified/sas9/SASjs.js +6 -6
  33. package/minified/sas9/WebJobExecutor.js +2 -2
  34. package/package.json +18 -17
  35. package/request/RequestClient.d.ts +1 -2
  36. package/request/RequestClient.js +10 -10
  37. package/request/Sas9RequestClient.d.ts +22 -5
  38. package/request/Sas9RequestClient.js +90 -22
  39. package/types/SASjsConfig.d.ts +0 -1
  40. package/types/SASjsConfig.js +1 -1
  41. package/types/Session.js +1 -1
  42. package/types/WriteStream.d.ts +0 -2
  43. package/types/errors/UnsafeRedirectError.d.ts +15 -0
  44. package/types/errors/UnsafeRedirectError.js +24 -0
  45. package/types/errors/index.d.ts +1 -0
  46. package/types/errors/index.js +1 -0
  47. package/utils/appendExtraResponseAttributes.js +1 -2
  48. package/utils/asyncForEach.js +1 -2
  49. package/utils/isIeOrEdge.js +1 -2
  50. package/utils/validateInput.d.ts +1 -1
@@ -985,14 +985,45 @@ const validateStreamConfig = (streamConfig) => {
985
985
  if (!streamConfig) {
986
986
  throw new Error('Invalid stream config: JSON cannot be null or undefined.');
987
987
  }
988
- if (streamConfig.streamWeb !== true && streamConfig.streamWeb !== false) {
988
+ // Presence is optional - a target can build a browser app without ever
989
+ // streaming from SAS - but a value that is present has to be a boolean.
990
+ if (streamConfig.streamWeb !== undefined &&
991
+ typeof streamConfig.streamWeb !== 'boolean') {
989
992
  throw new Error('Invalid stream config: `streamWeb` cannot be a non-boolean value.');
990
993
  }
991
- if (streamConfig.streamWeb && !streamConfig.streamWebFolder) {
992
- throw new Error('Invalid stream config: `streamWebFolder` cannot be empty, null or undefined when `streamWeb` is true.');
993
- }
994
- if (streamConfig.streamWeb && !streamConfig.webSourcePath) {
995
- throw new Error('Invalid stream config: `webSourcePath` should contain the path to your frontend application eg build, dist, or src.');
994
+ // `streamWebFolder` follows the same contract as `webSourcePath`: the schema
995
+ // documents a default (web), which is applied when the key is absent, and a
996
+ // value that is present but blank is rejected as a typo.
997
+ if (streamConfig.streamWebFolder !== undefined &&
998
+ streamConfig.streamWebFolder !== null &&
999
+ !String(streamConfig.streamWebFolder).trim()) {
1000
+ throw new Error('Invalid stream config: `streamWebFolder` cannot be empty - omit it to use the default (web).');
1001
+ }
1002
+ if (streamConfig.streamWeb === true && streamConfig.streamWebFolder == null) {
1003
+ streamConfig.streamWebFolder = 'web';
1004
+ }
1005
+ if (streamConfig.mockWeb !== undefined &&
1006
+ typeof streamConfig.mockWeb !== 'boolean') {
1007
+ throw new Error('Invalid stream config: `mockWeb` cannot be a non-boolean value.');
1008
+ }
1009
+ if (streamConfig.mockWebFolder !== undefined &&
1010
+ typeof streamConfig.mockWebFolder !== 'string') {
1011
+ throw new Error('Invalid stream config: `mockWebFolder` cannot be a non-string value.');
1012
+ }
1013
+ // `webSourcePath` is optional: the schema documents `dist` as its default and
1014
+ // most projects build into ./dist or ./build, so it is filled in below when a
1015
+ // switch needs it. A value that is present but blank is a typo rather than a
1016
+ // decision to accept the default, so it is rejected - the schema's minLength
1017
+ // of 1 says the same thing.
1018
+ if (streamConfig.webSourcePath !== undefined &&
1019
+ streamConfig.webSourcePath !== null &&
1020
+ !String(streamConfig.webSourcePath).trim()) {
1021
+ throw new Error('Invalid stream config: `webSourcePath` cannot be empty - omit it to use the default (dist).');
1022
+ }
1023
+ // Both switches build from the same folder, so one default covers them.
1024
+ if ((streamConfig.streamWeb === true || streamConfig.mockWeb === true) &&
1025
+ streamConfig.webSourcePath == null) {
1026
+ streamConfig.webSourcePath = 'dist';
996
1027
  }
997
1028
  if (streamConfig.streamLogo && typeof streamConfig.streamLogo !== 'string') {
998
1029
  streamConfig.streamLogo = undefined;
@@ -1227,8 +1258,8 @@ class AuthManager {
1227
1258
  * Opens Pop up window to SAS Login screen.
1228
1259
  * And checks if user has finished login process.
1229
1260
  */
1230
- redirectedLogIn({ onLoggedOut }) {
1231
- return __awaiter(this, void 0, void 0, function* () {
1261
+ redirectedLogIn(_a) {
1262
+ return __awaiter(this, arguments, void 0, function* ({ onLoggedOut }) {
1232
1263
  const { isLoggedIn: isLoggedInAlready, userName: currentSessionUserName, userLongName: currentSessionUserLongName } = yield this.fetchUserName();
1233
1264
  if (isLoggedInAlready) {
1234
1265
  const logger = (0, host_1.getLogger)();
@@ -1623,11 +1654,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
1623
1654
  });
1624
1655
  };
1625
1656
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1626
- exports.openWebPage = void 0;
1657
+ exports.openWebPage = openWebPage;
1627
1658
  const loginPrompt_1 = __webpack_require__(2986);
1628
1659
  const defaultWindowFeatures = { width: 500, height: 600 };
1629
- function openWebPage(url, windowName = '', WindowFeatures = defaultWindowFeatures, onLoggedOut) {
1630
- return __awaiter(this, void 0, void 0, function* () {
1660
+ function openWebPage(url_1) {
1661
+ return __awaiter(this, arguments, void 0, function* (url, windowName = '', WindowFeatures = defaultWindowFeatures, onLoggedOut) {
1631
1662
  const { width, height } = WindowFeatures;
1632
1663
  const left = screen.width / 2 - width / 2;
1633
1664
  const top = screen.height / 2 - height / 2;
@@ -1642,7 +1673,6 @@ function openWebPage(url, windowName = '', WindowFeatures = defaultWindowFeature
1642
1673
  return loginPopup;
1643
1674
  });
1644
1675
  }
1645
- exports.openWebPage = openWebPage;
1646
1676
 
1647
1677
 
1648
1678
  /***/ },
@@ -1662,7 +1692,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
1662
1692
  });
1663
1693
  };
1664
1694
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1665
- exports.verifySas9Login = void 0;
1695
+ exports.verifySas9Login = verifySas9Login;
1666
1696
  const utils_1 = __webpack_require__(9266);
1667
1697
  const _1 = __webpack_require__(4879);
1668
1698
  function verifySas9Login(loginPopup) {
@@ -1682,7 +1712,6 @@ function verifySas9Login(loginPopup) {
1682
1712
  return { isLoggedIn };
1683
1713
  });
1684
1714
  }
1685
- exports.verifySas9Login = verifySas9Login;
1686
1715
 
1687
1716
 
1688
1717
  /***/ },
@@ -1702,12 +1731,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
1702
1731
  });
1703
1732
  };
1704
1733
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1705
- exports.isLoggedInSASVIYA = exports.verifySasViyaLogin = void 0;
1734
+ exports.isLoggedInSASVIYA = void 0;
1735
+ exports.verifySasViyaLogin = verifySasViyaLogin;
1706
1736
  const utils_1 = __webpack_require__(9266);
1707
1737
  const _1 = __webpack_require__(4879);
1708
1738
  function verifySasViyaLogin(loginPopup) {
1709
- var _a, _b;
1710
1739
  return __awaiter(this, void 0, void 0, function* () {
1740
+ var _a, _b;
1711
1741
  let isLoggedIn = false;
1712
1742
  let startTime = new Date();
1713
1743
  let elapsedSeconds = 0;
@@ -1732,7 +1762,6 @@ function verifySasViyaLogin(loginPopup) {
1732
1762
  return { isLoggedIn: isLoggedIn && isAuthorized };
1733
1763
  });
1734
1764
  }
1735
- exports.verifySasViyaLogin = verifySasViyaLogin;
1736
1765
  const isLoggedInSASVIYA = () => document.cookie.includes('Current-User') && document.cookie.includes('userId');
1737
1766
  exports.isLoggedInSASVIYA = isLoggedInSASVIYA;
1738
1767
 
@@ -1930,7 +1959,7 @@ const auth_1 = __webpack_require__(4879);
1930
1959
  const types_2 = __webpack_require__(3631);
1931
1960
  const RequestClient_1 = __webpack_require__(8816);
1932
1961
  const FileUploader_1 = __webpack_require__(3871);
1933
- const WebJobExecutor_1 = __webpack_require__(5596);
1962
+ const WebJobExecutor_1 = __webpack_require__(3215);
1934
1963
  const ErrorResponse_1 = __webpack_require__(4845);
1935
1964
  const defaultConfig = {
1936
1965
  serverUrl: '',
@@ -1970,8 +1999,8 @@ class SASjs {
1970
1999
  * @param password - a string representing the password.
1971
2000
  * @param clientId - a string representing the client ID.
1972
2001
  */
1973
- logIn(username, password, clientId, options = {}) {
1974
- return __awaiter(this, void 0, void 0, function* () {
2002
+ logIn(username_1, password_1, clientId_1) {
2003
+ return __awaiter(this, arguments, void 0, function* (username, password, clientId, options = {}) {
1975
2004
  if (this.sasjsConfig.loginMechanism === types_1.LoginMechanism.Default) {
1976
2005
  if (!username || !password)
1977
2006
  throw new Error('A username and password are required when using the default login mechanism.');
@@ -2026,8 +2055,8 @@ class SASjs {
2026
2055
  * user is not logged in (eg to display a login form). The request will be
2027
2056
  * resubmitted after successful login.
2028
2057
  */
2029
- uploadFile(sasJob, files, params, config = {}, loginRequiredCallback) {
2030
- return __awaiter(this, void 0, void 0, function* () {
2058
+ uploadFile(sasJob_1, files_1, params_1) {
2059
+ return __awaiter(this, arguments, void 0, function* (sasJob, files, params, config = {}, loginRequiredCallback) {
2031
2060
  config = Object.assign(Object.assign({}, this.sasjsConfig), config);
2032
2061
  const data = { files, params };
2033
2062
  return yield this.fileUploader.execute(sasJob, data, config, loginRequiredCallback);
@@ -2060,8 +2089,8 @@ class SASjs {
2060
2089
  * to provide extra attributes (same names as those values) to be added in response
2061
2090
  * Supported values are declared in ExtraResponseAttributes type.
2062
2091
  */
2063
- request(sasJob, data, config = {}, loginRequiredCallback, authConfig, extraResponseAttributes = []) {
2064
- return __awaiter(this, void 0, void 0, function* () {
2092
+ request(sasJob_1, data_1) {
2093
+ return __awaiter(this, arguments, void 0, function* (sasJob, data, config = {}, loginRequiredCallback, authConfig, extraResponseAttributes = []) {
2065
2094
  config = Object.assign(Object.assign({}, this.sasjsConfig), config);
2066
2095
  const validationResult = (0, utils_1.validateInput)(data);
2067
2096
  // status is true if the data passes validation checks above
@@ -2115,7 +2144,7 @@ exports["default"] = SASjs;
2115
2144
 
2116
2145
  /***/ },
2117
2146
 
2118
- /***/ 5596
2147
+ /***/ 3215
2119
2148
  (__unused_webpack_module, exports, __webpack_require__) {
2120
2149
 
2121
2150
  "use strict";
@@ -2141,8 +2170,8 @@ class WebJobExecutor extends JobExecutor_1.BaseJobExecutor {
2141
2170
  this.jobsPath = jobsPath;
2142
2171
  this.requestClient = requestClient;
2143
2172
  }
2144
- execute(sasJob, data, config, loginRequiredCallback, authConfig, extraResponseAttributes = []) {
2145
- return __awaiter(this, void 0, void 0, function* () {
2173
+ execute(sasJob_1, data_1, config_1, loginRequiredCallback_1, authConfig_1) {
2174
+ return __awaiter(this, arguments, void 0, function* (sasJob, data, config, loginRequiredCallback, authConfig, extraResponseAttributes = []) {
2146
2175
  const loginCallback = loginRequiredCallback;
2147
2176
  const program = (0, utils_1.isRelativePath)(sasJob)
2148
2177
  ? config.appLoc
@@ -2520,7 +2549,7 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
2520
2549
  return csrfToken;
2521
2550
  }
2522
2551
  };
2523
- this.handleError = (e, callback, debug = false) => __awaiter(this, void 0, void 0, function* () {
2552
+ this.handleError = (e_1, callback_1, ...args_1) => __awaiter(this, [e_1, callback_1, ...args_1], void 0, function* (e, callback, debug = false) {
2524
2553
  var _a;
2525
2554
  const response = e.response;
2526
2555
  if (e instanceof errors_1.AuthorizeError) {
@@ -2713,8 +2742,8 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
2713
2742
  this.requests.splice(0, 1);
2714
2743
  }
2715
2744
  }
2716
- get(url, accessToken, contentType = 'application/json', overrideHeaders = {}, debug = false) {
2717
- return __awaiter(this, void 0, void 0, function* () {
2745
+ get(url_1, accessToken_1) {
2746
+ return __awaiter(this, arguments, void 0, function* (url, accessToken, contentType = 'application/json', overrideHeaders = {}, debug = false) {
2718
2747
  const headers = Object.assign(Object.assign({}, this.getHeaders(accessToken, contentType)), overrideHeaders);
2719
2748
  const requestConfig = {
2720
2749
  headers,
@@ -2744,8 +2773,8 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
2744
2773
  * Instead, it serializes data as JSON—resulting in a payload like
2745
2774
  * {"sometable":{}} and we lose the multipart/form-data formatting.
2746
2775
  */
2747
- post(url, data, accessToken, contentType = 'application/json', overrideHeaders = {}, additionalSettings = {}) {
2748
- return __awaiter(this, void 0, void 0, function* () {
2776
+ post(url_1, data_1, accessToken_1) {
2777
+ return __awaiter(this, arguments, void 0, function* (url, data, accessToken, contentType = 'application/json', overrideHeaders = {}, additionalSettings = {}) {
2749
2778
  const headers = Object.assign(Object.assign({}, this.getHeaders(accessToken, contentType)), overrideHeaders);
2750
2779
  return this.httpClient
2751
2780
  .post(url, data, Object.assign({ headers, withXSRFToken: true }, additionalSettings))
@@ -2758,8 +2787,8 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
2758
2787
  }));
2759
2788
  });
2760
2789
  }
2761
- put(url, data, accessToken, overrideHeaders = {}) {
2762
- return __awaiter(this, void 0, void 0, function* () {
2790
+ put(url_1, data_1, accessToken_1) {
2791
+ return __awaiter(this, arguments, void 0, function* (url, data, accessToken, overrideHeaders = {}) {
2763
2792
  const headers = Object.assign(Object.assign({}, this.getHeaders(accessToken, 'application/json')), overrideHeaders);
2764
2793
  return this.httpClient
2765
2794
  .put(url, data, { headers, withXSRFToken: true })
@@ -2786,8 +2815,8 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
2786
2815
  }));
2787
2816
  });
2788
2817
  }
2789
- patch(url, data = {}, accessToken, overrideHeaders = {}) {
2790
- return __awaiter(this, void 0, void 0, function* () {
2818
+ patch(url_1) {
2819
+ return __awaiter(this, arguments, void 0, function* (url, data = {}, accessToken, overrideHeaders = {}) {
2791
2820
  const headers = Object.assign(Object.assign({}, this.getHeaders(accessToken, 'application/json')), overrideHeaders);
2792
2821
  return this.httpClient
2793
2822
  .patch(url, data, { headers, withXSRFToken: true })
@@ -2801,8 +2830,8 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
2801
2830
  });
2802
2831
  }
2803
2832
  uploadFile(url, content, accessToken) {
2804
- var _a;
2805
2833
  return __awaiter(this, void 0, void 0, function* () {
2834
+ var _a;
2806
2835
  const headers = this.getHeaders(accessToken, 'application/json');
2807
2836
  if ((_a = this.fileUploadCsrfToken) === null || _a === void 0 ? void 0 : _a.value) {
2808
2837
  headers[this.fileUploadCsrfToken.headerName] =
@@ -3197,7 +3226,7 @@ var LoginMechanism;
3197
3226
  (function (LoginMechanism) {
3198
3227
  LoginMechanism["Default"] = "Default";
3199
3228
  LoginMechanism["Redirected"] = "Redirected";
3200
- })(LoginMechanism = exports.LoginMechanism || (exports.LoginMechanism = {}));
3229
+ })(LoginMechanism || (exports.LoginMechanism = LoginMechanism = {}));
3201
3230
 
3202
3231
 
3203
3232
  /***/ },
@@ -3219,7 +3248,7 @@ var SessionState;
3219
3248
  SessionState["NoState"] = "";
3220
3249
  SessionState["Failed"] = "failed";
3221
3250
  SessionState["Error"] = "error";
3222
- })(SessionState = exports.SessionState || (exports.SessionState = {}));
3251
+ })(SessionState || (exports.SessionState = SessionState = {}));
3223
3252
 
3224
3253
 
3225
3254
  /***/ },
@@ -3625,6 +3654,38 @@ class SAS9AuthError extends Error {
3625
3654
  exports.SAS9AuthError = SAS9AuthError;
3626
3655
 
3627
3656
 
3657
+ /***/ },
3658
+
3659
+ /***/ 996
3660
+ (__unused_webpack_module, exports) {
3661
+
3662
+ "use strict";
3663
+
3664
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
3665
+ exports.UnsafeRedirectError = void 0;
3666
+ /**
3667
+ * Thrown when a 302 cannot be followed safely.
3668
+ *
3669
+ * The SAS 9 client follows a redirect by hand, and the request carries the
3670
+ * access token, so a Location pointing at another origin is how that token
3671
+ * would reach a third party. A response that names no Location at all is
3672
+ * refused for the same reason - there is nothing safe to follow, and following
3673
+ * the original url again would loop.
3674
+ */
3675
+ class UnsafeRedirectError extends Error {
3676
+ constructor(requestedUrl, reason, location) {
3677
+ super(`Refusing to follow the redirect from ${requestedUrl}: ${reason}` +
3678
+ (location === undefined ? '' : ` (Location: ${location})`));
3679
+ this.requestedUrl = requestedUrl;
3680
+ this.reason = reason;
3681
+ this.location = location;
3682
+ this.name = 'UnsafeRedirectError';
3683
+ Object.setPrototypeOf(this, UnsafeRedirectError.prototype);
3684
+ }
3685
+ }
3686
+ exports.UnsafeRedirectError = UnsafeRedirectError;
3687
+
3688
+
3628
3689
  /***/ },
3629
3690
 
3630
3691
  /***/ 9997
@@ -3681,6 +3742,7 @@ __exportStar(__webpack_require__(3104), exports);
3681
3742
  __exportStar(__webpack_require__(1976), exports);
3682
3743
  __exportStar(__webpack_require__(7403), exports);
3683
3744
  __exportStar(__webpack_require__(5395), exports);
3745
+ __exportStar(__webpack_require__(996), exports);
3684
3746
  __exportStar(__webpack_require__(9997), exports);
3685
3747
 
3686
3748
 
@@ -3743,7 +3805,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
3743
3805
  });
3744
3806
  };
3745
3807
  Object.defineProperty(exports, "__esModule", ({ value: true }));
3746
- exports.appendExtraResponseAttributes = void 0;
3808
+ exports.appendExtraResponseAttributes = appendExtraResponseAttributes;
3747
3809
  function appendExtraResponseAttributes(response, extraResponseAttributes) {
3748
3810
  return __awaiter(this, void 0, void 0, function* () {
3749
3811
  let responseObject = {};
@@ -3756,7 +3818,6 @@ function appendExtraResponseAttributes(response, extraResponseAttributes) {
3756
3818
  return responseObject;
3757
3819
  });
3758
3820
  }
3759
- exports.appendExtraResponseAttributes = appendExtraResponseAttributes;
3760
3821
 
3761
3822
 
3762
3823
  /***/ },
@@ -3776,7 +3837,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
3776
3837
  });
3777
3838
  };
3778
3839
  Object.defineProperty(exports, "__esModule", ({ value: true }));
3779
- exports.asyncForEach = void 0;
3840
+ exports.asyncForEach = asyncForEach;
3780
3841
  function asyncForEach(array, callback) {
3781
3842
  return __awaiter(this, void 0, void 0, function* () {
3782
3843
  for (let index = 0; index < array.length; index++) {
@@ -3784,7 +3845,6 @@ function asyncForEach(array, callback) {
3784
3845
  }
3785
3846
  });
3786
3847
  }
3787
- exports.asyncForEach = asyncForEach;
3788
3848
 
3789
3849
 
3790
3850
  /***/ },