@sasjs/adapter 6.2.2 → 6.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -6,4 +6,5 @@ export * from './SAS9ApiClient';
6
6
  export * from './SASjsApiClient';
7
7
  export * from './request/SasjsRequestClient';
8
8
  export type { OnTokensRefreshed } from './auth/getTokens';
9
+ export type { AuthConfig } from './auth/AuthConfig';
9
10
  export default SASjs;
@@ -1,4 +1,4 @@
1
- import { AuthConfig } from '@sasjs/utils/types';
1
+ import { AuthConfig } from '../auth/AuthConfig';
2
2
  import { SASViyaApiClient } from '../SASViyaApiClient';
3
3
  import { BaseJobExecutor } from './JobExecutor';
4
4
  export declare class ComputeJobExecutor extends BaseJobExecutor {
@@ -1,4 +1,4 @@
1
- import { AuthConfig } from '@sasjs/utils/types';
1
+ import { AuthConfig } from '../auth/AuthConfig';
2
2
  import { SASViyaApiClient } from '../SASViyaApiClient';
3
3
  import { ExtraResponseAttributes } from '@sasjs/utils/types';
4
4
  import { BaseJobExecutor } from './JobExecutor';
@@ -1,4 +1,5 @@
1
- import { AuthConfig, ServerType } from '@sasjs/utils/types';
1
+ import { AuthConfig } from '../auth/AuthConfig';
2
+ import { ServerType } from '@sasjs/utils/types';
2
3
  import { ExtraResponseAttributes } from '@sasjs/utils/types';
3
4
  export type ExecuteFunction = () => Promise<any>;
4
5
  export interface JobExecutor {
@@ -1,4 +1,5 @@
1
- import { AuthConfig, ExtraResponseAttributes } from '@sasjs/utils/types';
1
+ import { AuthConfig } from '../auth/AuthConfig';
2
+ import { ExtraResponseAttributes } from '@sasjs/utils/types';
2
3
  import { RequestClient } from '../request/RequestClient';
3
4
  import { BaseJobExecutor } from './JobExecutor';
4
5
  export declare class SasjsJobExecutor extends BaseJobExecutor {
@@ -1,4 +1,5 @@
1
- import { AuthConfig, ExtraResponseAttributes, ServerType } from '@sasjs/utils/types';
1
+ import { AuthConfig } from '../auth/AuthConfig';
2
+ import { ExtraResponseAttributes, ServerType } from '@sasjs/utils/types';
2
3
  import { RequestClient } from '../request/RequestClient';
3
4
  import { SASViyaApiClient } from '../SASViyaApiClient';
4
5
  import { BaseJobExecutor } from './JobExecutor';
@@ -18,6 +18,7 @@ const types_1 = require("@sasjs/utils/types");
18
18
  const errors_1 = require("../types/errors");
19
19
  const generateFileUploadForm_1 = require("../file/generateFileUploadForm");
20
20
  const generateTableUploadForm_1 = require("../file/generateTableUploadForm");
21
+ const getTokens_1 = require("../auth/getTokens");
21
22
  const utils_1 = require("../utils");
22
23
  const JobExecutor_1 = require("./JobExecutor");
23
24
  const unauthenticatedRequestMessage_1 = require("./unauthenticatedRequestMessage");
@@ -38,10 +39,12 @@ class WebJobExecutor extends JobExecutor_1.BaseJobExecutor {
38
39
  : sasJob
39
40
  : sasJob;
40
41
  let apiUrl = `${config.serverUrl}${this.jobsPath}/?${'_program=' + program}`;
42
+ const clientCredentials = config.serverType === types_1.ServerType.SasViya &&
43
+ (authConfig === null || authConfig === void 0 ? void 0 : authConfig.grantType) === 'client_credentials';
41
44
  if (config.serverType === types_1.ServerType.SasViya) {
42
45
  let jobUri;
43
46
  try {
44
- jobUri = yield this.getJobUri(program);
47
+ jobUri = yield this.getJobUri(program, clientCredentials ? authConfig : undefined);
45
48
  }
46
49
  catch (e) {
47
50
  return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
@@ -146,8 +149,11 @@ class WebJobExecutor extends JobExecutor_1.BaseJobExecutor {
146
149
  const contentType = formData instanceof form_data_1.default && typeof FormData === 'undefined'
147
150
  ? `multipart/form-data; boundary=${formData.getHeaders()['content-type']}`
148
151
  : 'multipart/form-data';
152
+ const accessToken = clientCredentials && authConfig
153
+ ? (yield (0, getTokens_1.getTokens)(this.requestClient, authConfig)).access_token
154
+ : authConfig === null || authConfig === void 0 ? void 0 : authConfig.access_token;
149
155
  const requestPromise = new Promise((resolve, reject) => {
150
- this.requestClient.post(apiUrl, formData, authConfig === null || authConfig === void 0 ? void 0 : authConfig.access_token, contentType)
156
+ this.requestClient.post(apiUrl, formData, accessToken, contentType)
151
157
  .then((res) => __awaiter(this, void 0, void 0, function* () {
152
158
  this.requestClient.appendRequest(res, sasJob, config.debug);
153
159
  let jsonResponse = res.result;
@@ -166,7 +172,10 @@ class WebJobExecutor extends JobExecutor_1.BaseJobExecutor {
166
172
  jsonResponse =
167
173
  typeof res.result !== 'string' || (0, utils_1.hasWeboutBlob)(res.result)
168
174
  ? yield (0, utils_1.parseSasViyaLogDebugResponse)(res.result)
169
- : yield (0, utils_1.parseSasViyaDebugResponse)(res.result, this.requestClient, this.serverUrl);
175
+ : yield (0, utils_1.parseSasViyaDebugResponse)(res.result, this.requestClient, this.serverUrl, clientCredentials && authConfig
176
+ ? (yield (0, getTokens_1.getTokens)(this.requestClient, authConfig))
177
+ .access_token
178
+ : authConfig === null || authConfig === void 0 ? void 0 : authConfig.access_token);
170
179
  break;
171
180
  case types_1.ServerType.Sas9:
172
181
  jsonResponse =
@@ -218,7 +227,7 @@ class WebJobExecutor extends JobExecutor_1.BaseJobExecutor {
218
227
  }
219
228
  return requestParams;
220
229
  }
221
- getJobUri(sasJob) {
230
+ getJobUri(sasJob, authConfig) {
222
231
  return __awaiter(this, void 0, void 0, function* () {
223
232
  if (!this.sasViyaApiClient)
224
233
  return '';
@@ -233,7 +242,10 @@ class WebJobExecutor extends JobExecutor_1.BaseJobExecutor {
233
242
  if (!jobName) {
234
243
  throw new Error('Job name is empty, null or undefined.');
235
244
  }
236
- const locJobs = yield this.sasViyaApiClient.getJobsInFolder(folderPath);
245
+ const api = authConfig
246
+ ? this.sasViyaApiClient.withAccessTokenProvider(() => __awaiter(this, void 0, void 0, function* () { return (yield (0, getTokens_1.getTokens)(this.requestClient, authConfig)).access_token; }))
247
+ : this.sasViyaApiClient;
248
+ const locJobs = yield api.getJobsInFolder(folderPath);
237
249
  if (locJobs) {
238
250
  const job = locJobs.find((el) => el.name === jobName && el.contentType === 'jobDefinition');
239
251
  if (job) {
package/package.json CHANGED
@@ -113,14 +113,14 @@
113
113
  "is-core-module": "npm:@socketregistry/is-core-module@1.0.11",
114
114
  "is-unicode-supported": "npm:@socketregistry/is-unicode-supported@1.0.5",
115
115
  "isarray": "npm:@socketregistry/isarray@1.0.8",
116
- "minimatch": "11.0.8",
116
+ "minimatch": "11.0.10",
117
117
  "object-assign": "npm:@socketregistry/object-assign@1.0.5",
118
118
  "path-parse": "npm:@socketregistry/path-parse@1.0.8",
119
119
  "safe-buffer": "npm:@socketregistry/safe-buffer@1.0.9",
120
120
  "safer-buffer": "npm:@socketregistry/safer-buffer@1.0.10",
121
121
  "side-channel": "npm:@socketregistry/side-channel@1.0.10"
122
122
  },
123
- "version": "6.2.2",
123
+ "version": "6.3.1",
124
124
  "engines": {
125
125
  "node": ">=22"
126
126
  },
@@ -9,4 +9,4 @@ import { RequestClient } from '../request/RequestClient';
9
9
  * @param serverUrl
10
10
  * @returns
11
11
  */
12
- export declare const parseSasViyaDebugResponse: (response: string, requestClient: RequestClient, serverUrl: string) => Promise<object>;
12
+ export declare const parseSasViyaDebugResponse: (response: string, requestClient: RequestClient, serverUrl: string, accessToken?: string) => Promise<object>;
@@ -22,7 +22,7 @@ const extractWeboutBlob_1 = require("./extractWeboutBlob");
22
22
  * @param serverUrl
23
23
  * @returns
24
24
  */
25
- const parseSasViyaDebugResponse = (response, requestClient, serverUrl) => __awaiter(void 0, void 0, void 0, function* () {
25
+ const parseSasViyaDebugResponse = (response, requestClient, serverUrl, accessToken) => __awaiter(void 0, void 0, void 0, function* () {
26
26
  // On viya 3.5, iframe is like <iframe style="width: 99%; height: 500px" src="..."></iframe>
27
27
  // On viya 4, iframe is like <iframe style="width: 99%; height: 500px; background-color:Canvas;" src=...></iframe>
28
28
  const iframeStart = response.split(/<iframe style="width: 99%; height: 500px" src="|<iframe style="width: 99%; height: 500px; background-color:Canvas;" src=/)[1];
@@ -31,7 +31,7 @@ const parseSasViyaDebugResponse = (response, requestClient, serverUrl) => __awai
31
31
  : null;
32
32
  if (jsonUrl) {
33
33
  return requestClient
34
- .get(serverUrl + jsonUrl, undefined, 'text/plain')
34
+ .get(serverUrl + jsonUrl, accessToken, 'text/plain')
35
35
  .then((res) => (0, utils_1.getValidJson)(res.result));
36
36
  }
37
37
  // Fallback: some Viya configurations inline the webout via a