@sasjs/adapter 5.1.2 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) 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 +36 -28
  9. package/SASjsApiClient.d.ts +40 -6
  10. package/SASjsApiClient.js +103 -3
  11. package/SessionManager.js +1 -1
  12. package/api/viya/executeOnComputeApi.js +9 -10
  13. package/api/viya/pollJobState.d.ts +26 -3
  14. package/api/viya/pollJobState.js +29 -13
  15. package/api/viya/saveLog.js +1 -2
  16. package/api/viya/uploadTables.js +1 -2
  17. package/auth/AuthManager.js +2 -2
  18. package/auth/getAccessTokenForSasjs.js +1 -2
  19. package/auth/getAccessTokenForViya.js +1 -2
  20. package/auth/getTokens.js +3 -4
  21. package/auth/openWebPage.js +3 -4
  22. package/auth/refreshTokensForSasjs.js +1 -2
  23. package/auth/refreshTokensForViya.js +1 -2
  24. package/auth/verifySas9Login.js +1 -2
  25. package/auth/verifySasViyaLogin.js +3 -3
  26. package/dist/minified_sas9.js +103 -43
  27. package/dist/sasjs-adapter.js +7449 -7783
  28. package/job-execution/JesJobExecutor.js +2 -2
  29. package/job-execution/Sas9JobExecutor.d.ts +5 -1
  30. package/job-execution/Sas9JobExecutor.js +5 -0
  31. package/job-execution/SasjsJobExecutor.js +2 -2
  32. package/job-execution/WebJobExecutor.js +3 -3
  33. package/minified/sas9/SASjs.js +6 -6
  34. package/minified/sas9/WebJobExecutor.js +2 -2
  35. package/package.json +18 -17
  36. package/request/RequestClient.d.ts +1 -2
  37. package/request/RequestClient.js +10 -10
  38. package/request/Sas9RequestClient.d.ts +22 -5
  39. package/request/Sas9RequestClient.js +90 -22
  40. package/types/SASjsConfig.d.ts +0 -1
  41. package/types/SASjsConfig.js +1 -1
  42. package/types/Session.js +1 -1
  43. package/types/WriteStream.d.ts +0 -2
  44. package/types/errors/UnsafeRedirectError.d.ts +15 -0
  45. package/types/errors/UnsafeRedirectError.js +24 -0
  46. package/types/errors/index.d.ts +1 -0
  47. package/types/errors/index.js +1 -0
  48. package/utils/appendExtraResponseAttributes.js +1 -2
  49. package/utils/asyncForEach.js +1 -2
  50. package/utils/isIeOrEdge.js +1 -2
  51. package/utils/validateInput.d.ts +1 -1
@@ -19,8 +19,8 @@ class JesJobExecutor extends JobExecutor_1.BaseJobExecutor {
19
19
  super(serverUrl, types_1.ServerType.SasViya);
20
20
  this.sasViyaApiClient = sasViyaApiClient;
21
21
  }
22
- execute(sasJob, data, config, loginRequiredCallback, authConfig, extraResponseAttributes = []) {
23
- return __awaiter(this, void 0, void 0, function* () {
22
+ execute(sasJob_1, data_1, config_1, loginRequiredCallback_1, authConfig_1) {
23
+ return __awaiter(this, arguments, void 0, function* (sasJob, data, config, loginRequiredCallback, authConfig, extraResponseAttributes = []) {
24
24
  const loginCallback = loginRequiredCallback || (() => Promise.resolve());
25
25
  const requestPromise = new Promise((resolve, reject) => {
26
26
  var _a;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import type * as https from 'https';
3
2
  import { ServerType } from '@sasjs/utils/types';
4
3
  import { BaseJobExecutor } from './JobExecutor';
@@ -8,6 +7,11 @@ import { RequestClient } from '../request/RequestClient';
8
7
  * Initiates login with the provided username and password from the config
9
8
  * The cookies are stored in the request client and used in subsequent
10
9
  * job execution requests.
10
+ *
11
+ * The username and password are deprecated with the SAS 9 username / password
12
+ * login: they are appended to the `_program` query string, which SAS 9 only
13
+ * accepts when the platform is configured to allow URL credentials. See the
14
+ * "SAS 9 credentials" note in the README.
11
15
  */
12
16
  export declare class Sas9JobExecutor extends BaseJobExecutor {
13
17
  private jobsPath;
@@ -23,6 +23,11 @@ const Sas9RequestClient_1 = require("../request/Sas9RequestClient");
23
23
  * Initiates login with the provided username and password from the config
24
24
  * The cookies are stored in the request client and used in subsequent
25
25
  * job execution requests.
26
+ *
27
+ * The username and password are deprecated with the SAS 9 username / password
28
+ * login: they are appended to the `_program` query string, which SAS 9 only
29
+ * accepts when the platform is configured to allow URL credentials. See the
30
+ * "SAS 9 credentials" note in the README.
26
31
  */
27
32
  class Sas9JobExecutor extends JobExecutor_1.BaseJobExecutor {
28
33
  constructor(serverUrl, serverType, jobsPath, requestClient, httpsAgentOptions) {
@@ -26,8 +26,8 @@ class SasjsJobExecutor extends JobExecutor_1.BaseJobExecutor {
26
26
  this.jobsPath = jobsPath;
27
27
  this.requestClient = requestClient;
28
28
  }
29
- execute(sasJob, data, config, loginRequiredCallback, authConfig, extraResponseAttributes = []) {
30
- return __awaiter(this, void 0, void 0, function* () {
29
+ execute(sasJob_1, data_1, config_1, loginRequiredCallback_1, authConfig_1) {
30
+ return __awaiter(this, arguments, void 0, function* (sasJob, data, config, loginRequiredCallback, authConfig, extraResponseAttributes = []) {
31
31
  const loginCallback = loginRequiredCallback;
32
32
  const program = (0, utils_2.isRelativePath)(sasJob) && config.appLoc
33
33
  ? config.appLoc.replace(/\/?$/, '/') + sasJob.replace(/^\//, '')
@@ -27,9 +27,9 @@ class WebJobExecutor extends JobExecutor_1.BaseJobExecutor {
27
27
  this.requestClient = requestClient;
28
28
  this.sasViyaApiClient = sasViyaApiClient;
29
29
  }
30
- execute(sasJob, data, config, loginRequiredCallback, authConfig, extraResponseAttributes = []) {
31
- var _a;
32
- return __awaiter(this, void 0, void 0, function* () {
30
+ execute(sasJob_1, data_1, config_1, loginRequiredCallback_1, authConfig_1) {
31
+ return __awaiter(this, arguments, void 0, function* (sasJob, data, config, loginRequiredCallback, authConfig, extraResponseAttributes = []) {
32
+ var _a;
33
33
  const loginCallback = loginRequiredCallback;
34
34
  const program = (0, utils_1.isRelativePath)(sasJob)
35
35
  ? config.appLoc
@@ -55,8 +55,8 @@ class SASjs {
55
55
  * @param password - a string representing the password.
56
56
  * @param clientId - a string representing the client ID.
57
57
  */
58
- logIn(username, password, clientId, options = {}) {
59
- return __awaiter(this, void 0, void 0, function* () {
58
+ logIn(username_1, password_1, clientId_1) {
59
+ return __awaiter(this, arguments, void 0, function* (username, password, clientId, options = {}) {
60
60
  if (this.sasjsConfig.loginMechanism === types_1.LoginMechanism.Default) {
61
61
  if (!username || !password)
62
62
  throw new Error('A username and password are required when using the default login mechanism.');
@@ -111,8 +111,8 @@ class SASjs {
111
111
  * user is not logged in (eg to display a login form). The request will be
112
112
  * resubmitted after successful login.
113
113
  */
114
- uploadFile(sasJob, files, params, config = {}, loginRequiredCallback) {
115
- return __awaiter(this, void 0, void 0, function* () {
114
+ uploadFile(sasJob_1, files_1, params_1) {
115
+ return __awaiter(this, arguments, void 0, function* (sasJob, files, params, config = {}, loginRequiredCallback) {
116
116
  config = Object.assign(Object.assign({}, this.sasjsConfig), config);
117
117
  const data = { files, params };
118
118
  return yield this.fileUploader.execute(sasJob, data, config, loginRequiredCallback);
@@ -145,8 +145,8 @@ class SASjs {
145
145
  * to provide extra attributes (same names as those values) to be added in response
146
146
  * Supported values are declared in ExtraResponseAttributes type.
147
147
  */
148
- request(sasJob, data, config = {}, loginRequiredCallback, authConfig, extraResponseAttributes = []) {
149
- return __awaiter(this, void 0, void 0, function* () {
148
+ request(sasJob_1, data_1) {
149
+ return __awaiter(this, arguments, void 0, function* (sasJob, data, config = {}, loginRequiredCallback, authConfig, extraResponseAttributes = []) {
150
150
  config = Object.assign(Object.assign({}, this.sasjsConfig), config);
151
151
  const validationResult = (0, utils_1.validateInput)(data);
152
152
  // status is true if the data passes validation checks above
@@ -20,8 +20,8 @@ class WebJobExecutor extends JobExecutor_1.BaseJobExecutor {
20
20
  this.jobsPath = jobsPath;
21
21
  this.requestClient = requestClient;
22
22
  }
23
- execute(sasJob, data, config, loginRequiredCallback, authConfig, extraResponseAttributes = []) {
24
- return __awaiter(this, void 0, void 0, function* () {
23
+ execute(sasJob_1, data_1, config_1, loginRequiredCallback_1, authConfig_1) {
24
+ return __awaiter(this, arguments, void 0, function* (sasJob, data, config, loginRequiredCallback, authConfig, extraResponseAttributes = []) {
25
25
  const loginCallback = loginRequiredCallback;
26
26
  const program = (0, utils_1.isRelativePath)(sasJob)
27
27
  ? config.appLoc
package/package.json CHANGED
@@ -59,27 +59,28 @@
59
59
  "@cypress/webpack-preprocessor": "8.0.0",
60
60
  "@types/cors": "2.8.19",
61
61
  "@types/express": "5.0.6",
62
- "@types/jest": "29.5.14",
62
+ "@types/jest": "30.0.0",
63
+ "@types/node": "22.20.5",
63
64
  "@types/pem": "1.14.4",
64
65
  "copyfiles": "2.4.1",
65
66
  "cors": "2.8.6",
66
- "cypress": "15.18.1",
67
- "dotenv": "18.0.5",
68
- "express": "5.2.1",
69
- "jest": "29.7.0",
70
- "jest-environment-jsdom": "29.7.0",
71
- "jest-extended": "4.0.2",
67
+ "cypress": "16.2.0",
68
+ "dotenv": "18.0.9",
69
+ "express": "5.3.0",
70
+ "jest": "30.5.2",
71
+ "jest-environment-jsdom": "30.5.2",
72
+ "jest-extended": "7.0.0",
72
73
  "pem": "1.14.8",
73
- "prettier": "3.9.9",
74
- "ts-jest": "29.4.14",
74
+ "prettier": "3.9.10",
75
+ "ts-jest": "29.4.15",
75
76
  "ts-loader": "9.6.2",
76
77
  "tslint": "6.1.3",
77
78
  "tslint-config-prettier": "1.18.0",
78
- "typedoc": "0.23.24",
79
- "typedoc-plugin-rename-defaults": "0.6.4",
80
- "typescript": "4.9.5",
81
- "webpack": "5.111.1",
82
- "webpack-cli": "4.9.2"
79
+ "typedoc": "0.28.20",
80
+ "typedoc-plugin-rename-defaults": "0.7.3",
81
+ "typescript": "5.9.3",
82
+ "webpack": "5.112.2",
83
+ "webpack-cli": "7.2.3"
83
84
  },
84
85
  "main": "index.js",
85
86
  "types": "index.d.ts",
@@ -112,13 +113,13 @@
112
113
  "!node_modules/**"
113
114
  ],
114
115
  "dependencies": {
115
- "@sasjs/utils": "4.0.1",
116
+ "@sasjs/utils": "^4.1.0",
116
117
  "axios": "1.20.0",
117
118
  "axios-cookiejar-support": "5.0.5",
118
119
  "form-data": "4.0.6",
119
- "tough-cookie": "5.1.2"
120
+ "tough-cookie": "6.0.2"
120
121
  },
121
- "version": "5.1.2",
122
+ "version": "5.2.0",
122
123
  "engines": {
123
124
  "node": ">=22"
124
125
  },
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { AxiosError, AxiosInstance, AxiosResponse } from 'axios';
3
2
  import type * as https from 'https';
4
3
  import { CsrfToken } from '..';
@@ -117,7 +116,7 @@ export declare class RequestClient implements HttpClient {
117
116
  protected parseResponse<T>(response: AxiosResponse<any>): {
118
117
  result: T;
119
118
  etag: any;
120
- log?: string | undefined;
119
+ log?: string;
121
120
  status: number;
122
121
  };
123
122
  private createHttpClient;
@@ -256,7 +256,7 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
256
256
  return csrfToken;
257
257
  }
258
258
  };
259
- this.handleError = (e, callback, debug = false) => __awaiter(this, void 0, void 0, function* () {
259
+ this.handleError = (e_1, callback_1, ...args_1) => __awaiter(this, [e_1, callback_1, ...args_1], void 0, function* (e, callback, debug = false) {
260
260
  var _a;
261
261
  const response = e.response;
262
262
  if (e instanceof errors_1.AuthorizeError) {
@@ -449,8 +449,8 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
449
449
  this.requests.splice(0, 1);
450
450
  }
451
451
  }
452
- get(url, accessToken, contentType = 'application/json', overrideHeaders = {}, debug = false) {
453
- return __awaiter(this, void 0, void 0, function* () {
452
+ get(url_1, accessToken_1) {
453
+ return __awaiter(this, arguments, void 0, function* (url, accessToken, contentType = 'application/json', overrideHeaders = {}, debug = false) {
454
454
  const headers = Object.assign(Object.assign({}, this.getHeaders(accessToken, contentType)), overrideHeaders);
455
455
  const requestConfig = {
456
456
  headers,
@@ -480,8 +480,8 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
480
480
  * Instead, it serializes data as JSON—resulting in a payload like
481
481
  * {"sometable":{}} and we lose the multipart/form-data formatting.
482
482
  */
483
- post(url, data, accessToken, contentType = 'application/json', overrideHeaders = {}, additionalSettings = {}) {
484
- return __awaiter(this, void 0, void 0, function* () {
483
+ post(url_1, data_1, accessToken_1) {
484
+ return __awaiter(this, arguments, void 0, function* (url, data, accessToken, contentType = 'application/json', overrideHeaders = {}, additionalSettings = {}) {
485
485
  const headers = Object.assign(Object.assign({}, this.getHeaders(accessToken, contentType)), overrideHeaders);
486
486
  return this.httpClient
487
487
  .post(url, data, Object.assign({ headers, withXSRFToken: true }, additionalSettings))
@@ -494,8 +494,8 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
494
494
  }));
495
495
  });
496
496
  }
497
- put(url, data, accessToken, overrideHeaders = {}) {
498
- return __awaiter(this, void 0, void 0, function* () {
497
+ put(url_1, data_1, accessToken_1) {
498
+ return __awaiter(this, arguments, void 0, function* (url, data, accessToken, overrideHeaders = {}) {
499
499
  const headers = Object.assign(Object.assign({}, this.getHeaders(accessToken, 'application/json')), overrideHeaders);
500
500
  return this.httpClient
501
501
  .put(url, data, { headers, withXSRFToken: true })
@@ -522,8 +522,8 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
522
522
  }));
523
523
  });
524
524
  }
525
- patch(url, data = {}, accessToken, overrideHeaders = {}) {
526
- return __awaiter(this, void 0, void 0, function* () {
525
+ patch(url_1) {
526
+ return __awaiter(this, arguments, void 0, function* (url, data = {}, accessToken, overrideHeaders = {}) {
527
527
  const headers = Object.assign(Object.assign({}, this.getHeaders(accessToken, 'application/json')), overrideHeaders);
528
528
  return this.httpClient
529
529
  .patch(url, data, { headers, withXSRFToken: true })
@@ -537,8 +537,8 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
537
537
  });
538
538
  }
539
539
  uploadFile(url, content, accessToken) {
540
- var _a;
541
540
  return __awaiter(this, void 0, void 0, function* () {
541
+ var _a;
542
542
  const headers = this.getHeaders(accessToken, 'application/json');
543
543
  if ((_a = this.fileUploadCsrfToken) === null || _a === void 0 ? void 0 : _a.value) {
544
544
  headers[this.fileUploadCsrfToken.headerName] =
@@ -1,14 +1,31 @@
1
- /// <reference types="node" />
2
1
  import type * as https from 'https';
3
2
  import { RequestClient } from './RequestClient';
4
- /**
5
- * Specific request client for SAS9 in Node.js environments.
6
- * Handles redirects and cookie management.
7
- */
8
3
  export declare class Sas9RequestClient extends RequestClient {
9
4
  constructor(baseUrl: string, httpsAgentOptions?: https.AgentOptions);
10
5
  resetInMemoryAuthState(): void;
6
+ /**
7
+ * Logs into SAS 9 by appending the credentials to a `_program` call.
8
+ *
9
+ * @deprecated The credentials travel in the query string, and SAS 9 only
10
+ * accepts them when the platform is configured to allow URL credentials -
11
+ * which is why this was never usable without a server-side change. There is
12
+ * no drop-in replacement for the mechanism itself; it will be removed in a
13
+ * future major version, so new work should not depend on it.
14
+ */
11
15
  login(username: string, password: string, jobsPath: string): Promise<void>;
16
+ /**
17
+ * A 302 is followed by hand rather than by axios (maxRedirects is 0), and the
18
+ * request carries the access token, so the token would otherwise travel to
19
+ * whatever host the response names. Only a redirect to the origin of the
20
+ * request is followed.
21
+ *
22
+ * Resolving against `url` and `baseUrl` is what makes the check hold for
23
+ * every form a Location can take: a relative path or a protocol-relative
24
+ * value resolves to the origin it was resolved against, and an absolute one
25
+ * that leaves it is refused. The Location is passed through unchanged, so a
26
+ * same-origin redirect behaves exactly as it did before.
27
+ */
28
+ private assertSafeRedirect;
12
29
  get<T>(url: string, accessToken: string | undefined, contentType?: string, overrideHeaders?: {
13
30
  [key: string]: string | number;
14
31
  }, debug?: boolean): Promise<{
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -38,39 +48,93 @@ const tough = __importStar(require("tough-cookie"));
38
48
  const error_1 = require("@sasjs/utils/error");
39
49
  const RequestClient_1 = require("./RequestClient");
40
50
  const errors_1 = require("../types/errors");
51
+ const host_1 = require("../utils/host");
52
+ let hasWarnedAboutSas9Login = false;
53
+ /**
54
+ * Warns once per process rather than per request: a job that runs repeatedly
55
+ * through the SAS 9 credential path should not repeat this on every call, and
56
+ * a single line is enough for the reader to find the README note.
57
+ */
58
+ const warnDeprecatedSas9Login = () => {
59
+ if (hasWarnedAboutSas9Login)
60
+ return;
61
+ hasWarnedAboutSas9Login = true;
62
+ (0, host_1.getLogger)().warn('The SAS 9 username / password login is deprecated and will be removed in a future major version. It appends the credentials to the _program query string, which SAS 9 only accepts when the platform is configured to allow URL credentials.');
63
+ };
41
64
  /**
42
65
  * Specific request client for SAS9 in Node.js environments.
43
66
  * Handles redirects and cookie management.
44
67
  */
68
+ /**
69
+ * The cookie wrapper carries its jar on the request config, and axios types
70
+ * `defaults` as a separate shape, so the property is named here rather than
71
+ * relied on through the package's module augmentation.
72
+ */
73
+ const jarredDefaults = (client) => client.defaults;
45
74
  class Sas9RequestClient extends RequestClient_1.RequestClient {
46
75
  constructor(baseUrl, httpsAgentOptions) {
47
76
  super(baseUrl, httpsAgentOptions);
48
77
  this.httpClient.defaults.maxRedirects = 0;
49
78
  this.httpClient.defaults.validateStatus = (status) => status >= 200 && status < 303;
50
79
  if (axios_cookiejar_support_1.wrapper) {
51
- (0, axios_cookiejar_support_1.wrapper)(this.httpClient);
52
- this.httpClient.defaults.jar = new tough.CookieJar();
80
+ // the published signature is a union over axios's two declaration files,
81
+ // which TypeScript resolves as distinct types here; the call is unchanged
82
+ ;
83
+ axios_cookiejar_support_1.wrapper(this.httpClient);
84
+ jarredDefaults(this.httpClient).jar = new tough.CookieJar();
53
85
  }
54
86
  }
55
87
  resetInMemoryAuthState() {
56
88
  super.resetInMemoryAuthState();
57
- if (this.httpClient.defaults.jar) {
58
- ;
59
- this.httpClient.defaults.jar.removeAllCookiesSync();
60
- }
89
+ const jar = jarredDefaults(this.httpClient).jar;
90
+ if (jar)
91
+ jar.removeAllCookiesSync();
61
92
  }
93
+ /**
94
+ * Logs into SAS 9 by appending the credentials to a `_program` call.
95
+ *
96
+ * @deprecated The credentials travel in the query string, and SAS 9 only
97
+ * accepts them when the platform is configured to allow URL credentials -
98
+ * which is why this was never usable without a server-side change. There is
99
+ * no drop-in replacement for the mechanism itself; it will be removed in a
100
+ * future major version, so new work should not depend on it.
101
+ */
62
102
  login(username, password, jobsPath) {
63
103
  return __awaiter(this, void 0, void 0, function* () {
104
+ if (username && password)
105
+ warnDeprecatedSas9Login();
64
106
  const codeInjectorPath = `/User Folders/${username}/My Folder/sasjs/runner`;
65
- if (this.httpClient.defaults.jar) {
66
- ;
67
- this.httpClient.defaults.jar.removeAllCookies();
107
+ const jar = jarredDefaults(this.httpClient).jar;
108
+ if (jar) {
109
+ jar.removeAllCookies();
68
110
  yield this.get(`${jobsPath}?_program=${codeInjectorPath}&_username=${username}&_password=${password}`, undefined, 'text/plain');
69
111
  }
70
112
  });
71
113
  }
72
- get(url, accessToken, contentType = 'application/json', overrideHeaders = {}, debug = false) {
73
- return __awaiter(this, void 0, void 0, function* () {
114
+ /**
115
+ * A 302 is followed by hand rather than by axios (maxRedirects is 0), and the
116
+ * request carries the access token, so the token would otherwise travel to
117
+ * whatever host the response names. Only a redirect to the origin of the
118
+ * request is followed.
119
+ *
120
+ * Resolving against `url` and `baseUrl` is what makes the check hold for
121
+ * every form a Location can take: a relative path or a protocol-relative
122
+ * value resolves to the origin it was resolved against, and an absolute one
123
+ * that leaves it is refused. The Location is passed through unchanged, so a
124
+ * same-origin redirect behaves exactly as it did before.
125
+ */
126
+ assertSafeRedirect(location, url) {
127
+ if (!location) {
128
+ throw new errors_1.UnsafeRedirectError(url, 'the response carried no Location header');
129
+ }
130
+ const requested = new URL(url, this.baseUrl);
131
+ const target = new URL(location, requested);
132
+ if (target.origin !== requested.origin) {
133
+ throw new errors_1.UnsafeRedirectError(url, `${target.origin} is not the origin of the request`, location);
134
+ }
135
+ }
136
+ get(url_1, accessToken_1) {
137
+ return __awaiter(this, arguments, void 0, function* (url, accessToken, contentType = 'application/json', overrideHeaders = {}, debug = false) {
74
138
  const headers = Object.assign(Object.assign({}, this.getHeaders(accessToken, contentType)), overrideHeaders);
75
139
  const requestConfig = {
76
140
  headers,
@@ -84,7 +148,9 @@ class Sas9RequestClient extends RequestClient_1.RequestClient {
84
148
  .get(url, requestConfig)
85
149
  .then((response) => {
86
150
  if (response.status === 302) {
87
- return this.get(response.headers['location'], accessToken, contentType);
151
+ const location = response.headers['location'];
152
+ this.assertSafeRedirect(location, url);
153
+ return this.get(location, accessToken, contentType);
88
154
  }
89
155
  (0, RequestClient_1.throwIfError)(response);
90
156
  return this.parseResponse(response);
@@ -100,14 +166,16 @@ class Sas9RequestClient extends RequestClient_1.RequestClient {
100
166
  }));
101
167
  });
102
168
  }
103
- post(url, data, accessToken, contentType = 'application/json', overrideHeaders = {}) {
104
- return __awaiter(this, void 0, void 0, function* () {
169
+ post(url_1, data_1, accessToken_1) {
170
+ return __awaiter(this, arguments, void 0, function* (url, data, accessToken, contentType = 'application/json', overrideHeaders = {}) {
105
171
  const headers = Object.assign(Object.assign({}, this.getHeaders(accessToken, contentType)), overrideHeaders);
106
172
  return this.httpClient
107
173
  .post(url, data, { headers, withXSRFToken: true })
108
174
  .then((response) => __awaiter(this, void 0, void 0, function* () {
109
175
  if (response.status === 302) {
110
- return yield this.get(response.headers['location'], undefined, contentType, overrideHeaders);
176
+ const location = response.headers['location'];
177
+ this.assertSafeRedirect(location, url);
178
+ return yield this.get(location, undefined, contentType, overrideHeaders);
111
179
  }
112
180
  (0, RequestClient_1.throwIfError)(response);
113
181
  return this.parseResponse(response);
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import type * as https from 'https';
3
2
  import { ServerType } from '@sasjs/utils/types';
4
3
  import { VerboseMode } from '../types';
@@ -88,4 +88,4 @@ var LoginMechanism;
88
88
  (function (LoginMechanism) {
89
89
  LoginMechanism["Default"] = "Default";
90
90
  LoginMechanism["Redirected"] = "Redirected";
91
- })(LoginMechanism = exports.LoginMechanism || (exports.LoginMechanism = {}));
91
+ })(LoginMechanism || (exports.LoginMechanism = LoginMechanism = {}));
package/types/Session.js CHANGED
@@ -11,4 +11,4 @@ var SessionState;
11
11
  SessionState["NoState"] = "";
12
12
  SessionState["Failed"] = "failed";
13
13
  SessionState["Error"] = "error";
14
- })(SessionState = exports.SessionState || (exports.SessionState = {}));
14
+ })(SessionState || (exports.SessionState = SessionState = {}));
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import type { WriteStream as FsWriteStream } from 'fs';
4
2
  export interface WriteStream extends FsWriteStream {
5
3
  write(chunk: any, encoding?: BufferEncoding | ((error: Error | null | undefined) => void), cb?: (error: Error | null | undefined) => void): boolean;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Thrown when a 302 cannot be followed safely.
3
+ *
4
+ * The SAS 9 client follows a redirect by hand, and the request carries the
5
+ * access token, so a Location pointing at another origin is how that token
6
+ * would reach a third party. A response that names no Location at all is
7
+ * refused for the same reason - there is nothing safe to follow, and following
8
+ * the original url again would loop.
9
+ */
10
+ export declare class UnsafeRedirectError extends Error {
11
+ requestedUrl: string;
12
+ reason: string;
13
+ location?: string | undefined;
14
+ constructor(requestedUrl: string, reason: string, location?: string | undefined);
15
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnsafeRedirectError = void 0;
4
+ /**
5
+ * Thrown when a 302 cannot be followed safely.
6
+ *
7
+ * The SAS 9 client follows a redirect by hand, and the request carries the
8
+ * access token, so a Location pointing at another origin is how that token
9
+ * would reach a third party. A response that names no Location at all is
10
+ * refused for the same reason - there is nothing safe to follow, and following
11
+ * the original url again would loop.
12
+ */
13
+ class UnsafeRedirectError extends Error {
14
+ constructor(requestedUrl, reason, location) {
15
+ super(`Refusing to follow the redirect from ${requestedUrl}: ${reason}` +
16
+ (location === undefined ? '' : ` (Location: ${location})`));
17
+ this.requestedUrl = requestedUrl;
18
+ this.reason = reason;
19
+ this.location = location;
20
+ this.name = 'UnsafeRedirectError';
21
+ Object.setPrototypeOf(this, UnsafeRedirectError.prototype);
22
+ }
23
+ }
24
+ exports.UnsafeRedirectError = UnsafeRedirectError;
@@ -12,4 +12,5 @@ export * from './LoginRequiredError';
12
12
  export * from './NoSessionStateError';
13
13
  export * from './NotFoundError';
14
14
  export * from './RootFolderNotFoundError';
15
+ export * from './UnsafeRedirectError';
15
16
  export * from './WeboutResponseError';
@@ -28,4 +28,5 @@ __exportStar(require("./LoginRequiredError"), exports);
28
28
  __exportStar(require("./NoSessionStateError"), exports);
29
29
  __exportStar(require("./NotFoundError"), exports);
30
30
  __exportStar(require("./RootFolderNotFoundError"), exports);
31
+ __exportStar(require("./UnsafeRedirectError"), exports);
31
32
  __exportStar(require("./WeboutResponseError"), exports);
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.appendExtraResponseAttributes = void 0;
12
+ exports.appendExtraResponseAttributes = appendExtraResponseAttributes;
13
13
  function appendExtraResponseAttributes(response, extraResponseAttributes) {
14
14
  return __awaiter(this, void 0, void 0, function* () {
15
15
  let responseObject = {};
@@ -22,4 +22,3 @@ function appendExtraResponseAttributes(response, extraResponseAttributes) {
22
22
  return responseObject;
23
23
  });
24
24
  }
25
- exports.appendExtraResponseAttributes = appendExtraResponseAttributes;
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.asyncForEach = void 0;
12
+ exports.asyncForEach = asyncForEach;
13
13
  function asyncForEach(array, callback) {
14
14
  return __awaiter(this, void 0, void 0, function* () {
15
15
  for (let index = 0; index < array.length; index++) {
@@ -17,4 +17,3 @@ function asyncForEach(array, callback) {
17
17
  }
18
18
  });
19
19
  }
20
- exports.asyncForEach = asyncForEach;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isIEorEdgeOrOldFirefox = void 0;
3
+ exports.isIEorEdgeOrOldFirefox = isIEorEdgeOrOldFirefox;
4
4
  function isIEorEdgeOrOldFirefox() {
5
5
  if (typeof window === 'undefined') {
6
6
  return false;
@@ -27,4 +27,3 @@ function isIEorEdgeOrOldFirefox() {
27
27
  // other browser
28
28
  return false;
29
29
  }
30
- exports.isIEorEdgeOrOldFirefox = isIEorEdgeOrOldFirefox;
@@ -1,5 +1,5 @@
1
1
  export declare const MORE_INFO = "For more info see https://sasjs.io/sasjs-adapter/#request-response";
2
- export declare const INVALID_TABLE_STRUCTURE: string;
2
+ export declare const INVALID_TABLE_STRUCTURE = "Parameter data contains invalid table structure. For more info see https://sasjs.io/sasjs-adapter/#request-response";
3
3
  /**
4
4
  * This function validates the input data structure and table naming convention
5
5
  *