@sasjs/adapter 6.2.0 → 6.2.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.
- package/README.md +14 -0
- package/SASViyaApiClient.d.ts +15 -0
- package/SASViyaApiClient.js +252 -17
- package/SASjs.d.ts +3 -6
- package/SASjs.js +86 -25
- package/dist/minified_sas9.js +76 -18
- package/dist/sasjs-adapter.js +496 -60
- package/package.json +3 -3
- package/request/RequestClient.d.ts +7 -11
- package/request/RequestClient.js +76 -18
- package/types/Folder.d.ts +3 -0
- package/utils/validateForcedServicePack.d.ts +2 -0
- package/utils/validateForcedServicePack.js +73 -0
package/package.json
CHANGED
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"es-define-property": "npm:@socketregistry/es-define-property@1.0.7",
|
|
106
106
|
"es-set-tostringtag": "npm:@socketregistry/es-set-tostringtag@1.0.10",
|
|
107
107
|
"function-bind": "npm:@socketregistry/function-bind@1.0.7",
|
|
108
|
-
"glob": "14.0.
|
|
108
|
+
"glob": "14.0.6",
|
|
109
109
|
"gopd": "npm:@socketregistry/gopd@1.0.7",
|
|
110
110
|
"has-symbols": "npm:@socketregistry/has-symbols@1.0.7",
|
|
111
111
|
"has-tostringtag": "npm:@socketregistry/has-tostringtag@1.0.7",
|
|
@@ -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.
|
|
116
|
+
"minimatch": "11.0.8",
|
|
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.
|
|
123
|
+
"version": "6.2.2",
|
|
124
124
|
"engines": {
|
|
125
125
|
"node": ">=22"
|
|
126
126
|
},
|
|
@@ -12,6 +12,7 @@ export declare class RequestClient implements HttpClient {
|
|
|
12
12
|
protected fileUploadCsrfToken: CsrfToken | undefined;
|
|
13
13
|
protected httpClient: AxiosInstance;
|
|
14
14
|
private isRecoveringFromNetworkError;
|
|
15
|
+
private deploymentTransport;
|
|
15
16
|
private mockReadiness;
|
|
16
17
|
constructor(baseUrl: string, httpsAgentOptions?: https.AgentOptions, requestsLimit?: number, verboseMode?: VerboseMode);
|
|
17
18
|
setConfig(baseUrl: string, httpsAgentOptions?: https.AgentOptions): void;
|
|
@@ -21,6 +22,10 @@ export declare class RequestClient implements HttpClient {
|
|
|
21
22
|
clearLocalStorageTokens(): void;
|
|
22
23
|
resetInMemoryAuthState(): void;
|
|
23
24
|
private clearAllCookies;
|
|
25
|
+
copyCsrfFrom(source: RequestClient): void;
|
|
26
|
+
/** Restrict a dedicated deployment client to its origin and prohibit redirects. */
|
|
27
|
+
restrictDeploymentTransport(): void;
|
|
28
|
+
isDeploymentTransport(): boolean;
|
|
24
29
|
getBaseUrl(): string;
|
|
25
30
|
/**
|
|
26
31
|
* this method returns all requests, an array of SASjsRequest type
|
|
@@ -59,6 +64,7 @@ export declare class RequestClient implements HttpClient {
|
|
|
59
64
|
}): Promise<{
|
|
60
65
|
result: T;
|
|
61
66
|
etag: string;
|
|
67
|
+
status?: number;
|
|
62
68
|
}>;
|
|
63
69
|
put<T>(url: string, data: any, accessToken: string | undefined, overrideHeaders?: {
|
|
64
70
|
[key: string]: string | number;
|
|
@@ -75,6 +81,7 @@ export declare class RequestClient implements HttpClient {
|
|
|
75
81
|
}): Promise<{
|
|
76
82
|
result: T;
|
|
77
83
|
etag: string;
|
|
84
|
+
status: number;
|
|
78
85
|
}>;
|
|
79
86
|
uploadFile(url: string, content: string, accessToken?: string): Promise<any>;
|
|
80
87
|
authorize: (response: string) => Promise<any>;
|
|
@@ -122,15 +129,4 @@ export declare class RequestClient implements HttpClient {
|
|
|
122
129
|
};
|
|
123
130
|
private createHttpClient;
|
|
124
131
|
}
|
|
125
|
-
/**
|
|
126
|
-
* Raises the error a response status implies, marked as one built from a
|
|
127
|
-
* response.
|
|
128
|
-
*
|
|
129
|
-
* The marking has to happen here: every error below is a new object carrying
|
|
130
|
-
* the body, so the axios error - the thing that knew a response had arrived -
|
|
131
|
-
* is gone by the time a caller catches it (sasjs/adapter#895). A 401 from a
|
|
132
|
-
* refresh route is named by `throwForStatus` as a rejected refresh token
|
|
133
|
-
* (sasjs/adapter#975); this marks it as an answer that arrived, so a transport
|
|
134
|
-
* failure and a refusal are not reported with the same title.
|
|
135
|
-
*/
|
|
136
132
|
export declare const throwIfError: (response: AxiosResponse) => void;
|
package/request/RequestClient.js
CHANGED
|
@@ -30,6 +30,7 @@ class RequestClient {
|
|
|
30
30
|
this.verboseMode = false;
|
|
31
31
|
this.csrfToken = { headerName: '', value: '' };
|
|
32
32
|
this.isRecoveringFromNetworkError = false;
|
|
33
|
+
this.deploymentTransport = false;
|
|
33
34
|
this.mockReadiness = (0, mockReadiness_1.captureMockReadiness)();
|
|
34
35
|
/**
|
|
35
36
|
* this method returns all requests, an array of SASjsRequest type
|
|
@@ -263,8 +264,19 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
|
|
|
263
264
|
}
|
|
264
265
|
};
|
|
265
266
|
this.handleError = (e_1, callback_1, ...args_1) => __awaiter(this, [e_1, callback_1, ...args_1], void 0, function* (e, callback, debug = false) {
|
|
266
|
-
var _a;
|
|
267
|
+
var _a, _b;
|
|
267
268
|
const response = e.response;
|
|
269
|
+
// A missing response may mean a write succeeded or a redirect was blocked.
|
|
270
|
+
// Retrying would repeat an operation whose outcome is unknown.
|
|
271
|
+
if (this.deploymentTransport && !response && e.isAxiosError) {
|
|
272
|
+
throw (0, responseReceived_1.markResponseReceived)(e, false);
|
|
273
|
+
}
|
|
274
|
+
// These recovery callbacks recursively replay the original operation and can
|
|
275
|
+
// repeat an uncertain deployment write. Only the bounded CSRF challenge
|
|
276
|
+
// retry below is permitted on the restricted transport.
|
|
277
|
+
if (this.deploymentTransport &&
|
|
278
|
+
(e instanceof errors_1.AuthorizeError || e instanceof InvalidSASjsCsrfError_1.InvalidSASjsCsrfError))
|
|
279
|
+
throw e;
|
|
268
280
|
if (e instanceof errors_1.AuthorizeError) {
|
|
269
281
|
const res = yield this.httpClient
|
|
270
282
|
.get(e.confirmUrl, {
|
|
@@ -307,6 +319,26 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
|
|
|
307
319
|
});
|
|
308
320
|
}
|
|
309
321
|
if ((response === null || response === void 0 ? void 0 : response.status) === 403 || (response === null || response === void 0 ? void 0 : response.status) === 449) {
|
|
322
|
+
if (this.deploymentTransport) {
|
|
323
|
+
const challenge = this.parseCsrfToken(response);
|
|
324
|
+
const previous = challenge && ((_a = response.config.headers) === null || _a === void 0 ? void 0 : _a.get(challenge.headerName));
|
|
325
|
+
if (!(challenge === null || challenge === void 0 ? void 0 : challenge.headerName) ||
|
|
326
|
+
!/^x-[a-z0-9-]*(?:csrf|xsrf)[a-z0-9-]*$/.test(challenge.headerName) ||
|
|
327
|
+
!challenge.value ||
|
|
328
|
+
previous === challenge.value)
|
|
329
|
+
throw (0, responseReceived_1.markResponseReceived)(e, true);
|
|
330
|
+
this.csrfToken = challenge;
|
|
331
|
+
try {
|
|
332
|
+
const config = response.config;
|
|
333
|
+
config.headers.set(challenge.headerName, challenge.value);
|
|
334
|
+
const retried = yield this.httpClient.request(config);
|
|
335
|
+
(0, exports.throwIfError)(retried);
|
|
336
|
+
return this.parseResponse(retried);
|
|
337
|
+
}
|
|
338
|
+
catch (retryError) {
|
|
339
|
+
throw (0, responseReceived_1.markResponseReceived)(retryError, Boolean(retryError.response));
|
|
340
|
+
}
|
|
341
|
+
}
|
|
310
342
|
this.parseAndSetCsrfToken(response);
|
|
311
343
|
if (this.csrfToken.headerName && this.csrfToken.value) {
|
|
312
344
|
return yield callback().catch((err) => {
|
|
@@ -342,7 +374,7 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
|
|
|
342
374
|
.get('/', { withXSRFToken: true })
|
|
343
375
|
.catch((err) => err.response);
|
|
344
376
|
if (rootResponse === null || rootResponse === void 0 ? void 0 : rootResponse.data) {
|
|
345
|
-
const cookie = (
|
|
377
|
+
const cookie = (_b = /<script>document.cookie = '(XSRF-TOKEN=.*; Max-Age=86400; SameSite=Strict; Path=\/;)'<\/script>/.exec(rootResponse.data)) === null || _b === void 0 ? void 0 : _b[1];
|
|
346
378
|
if (cookie && typeof document !== 'undefined') {
|
|
347
379
|
document.cookie = cookie;
|
|
348
380
|
}
|
|
@@ -351,10 +383,7 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
|
|
|
351
383
|
return yield callback();
|
|
352
384
|
}
|
|
353
385
|
catch (retryError) {
|
|
354
|
-
// Session could not be recovered — surface LoginRequiredError
|
|
355
|
-
// retry itself may have reached the server and been refused, which is
|
|
356
|
-
// not the same as never arriving: the marker follows the retry's own
|
|
357
|
-
// answer, not the opaque network error that started this.
|
|
386
|
+
// Session could not be recovered — surface LoginRequiredError
|
|
358
387
|
throw (0, responseReceived_1.markResponseReceived)(new errors_1.LoginRequiredError(), (0, responseReceived_1.responseWasReceived)(retryError));
|
|
359
388
|
}
|
|
360
389
|
finally {
|
|
@@ -374,6 +403,7 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
|
|
|
374
403
|
}
|
|
375
404
|
}
|
|
376
405
|
setConfig(baseUrl, httpsAgentOptions) {
|
|
406
|
+
this.deploymentTransport = false;
|
|
377
407
|
this.createHttpClient(baseUrl, httpsAgentOptions);
|
|
378
408
|
}
|
|
379
409
|
saveLocalStorageToken(accessToken, refreshToken) {
|
|
@@ -409,6 +439,45 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
|
|
|
409
439
|
document.cookie = `${name}=; Max-Age=0; Path=/;`;
|
|
410
440
|
}
|
|
411
441
|
}
|
|
442
|
+
copyCsrfFrom(source) {
|
|
443
|
+
const locationBase = typeof location !== 'undefined' ? location.href : undefined;
|
|
444
|
+
const targetUrl = new URL(this.getBaseUrl() || locationBase || '', locationBase);
|
|
445
|
+
const sourceUrl = new URL(source.getBaseUrl() || locationBase || '', locationBase);
|
|
446
|
+
if (targetUrl.origin !== sourceUrl.origin)
|
|
447
|
+
throw new Error('Cannot copy cross-origin CSRF state');
|
|
448
|
+
this.csrfToken = Object.assign({}, source.csrfToken);
|
|
449
|
+
}
|
|
450
|
+
/** Restrict a dedicated deployment client to its origin and prohibit redirects. */
|
|
451
|
+
restrictDeploymentTransport() {
|
|
452
|
+
const locationBase = typeof location !== 'undefined' ? location.href : undefined;
|
|
453
|
+
const base = new URL(this.getBaseUrl() || locationBase || '', locationBase);
|
|
454
|
+
this.httpClient.defaults.maxRedirects = 0;
|
|
455
|
+
if (!(0, isNode_1.isNode)()) {
|
|
456
|
+
if (typeof Request === 'undefined' ||
|
|
457
|
+
new Request(base.href, { redirect: 'error' }).redirect !== 'error')
|
|
458
|
+
throw new Error('Safe deployment requires fetch redirect support');
|
|
459
|
+
this.httpClient.defaults.adapter = 'fetch';
|
|
460
|
+
this.httpClient.defaults.fetchOptions = { redirect: 'error' };
|
|
461
|
+
}
|
|
462
|
+
this.httpClient.interceptors.request.use((config) => {
|
|
463
|
+
if (config.data &&
|
|
464
|
+
typeof config.data.getBuffer === 'function' &&
|
|
465
|
+
typeof config.data.getBoundary === 'function') {
|
|
466
|
+
const boundary = config.data.getBoundary();
|
|
467
|
+
config.data = config.data.getBuffer();
|
|
468
|
+
config.headers.set('Content-Type', `multipart/form-data; boundary=${boundary}`);
|
|
469
|
+
}
|
|
470
|
+
const url = new URL(config.url || '', config.baseURL || base.href);
|
|
471
|
+
if (url.origin !== base.origin ||
|
|
472
|
+
/[\\\u0000-\u001f\u007f]/.test(config.url || ''))
|
|
473
|
+
throw new Error('Unsafe deployment request URL');
|
|
474
|
+
return config;
|
|
475
|
+
});
|
|
476
|
+
this.deploymentTransport = true;
|
|
477
|
+
}
|
|
478
|
+
isDeploymentTransport() {
|
|
479
|
+
return this.deploymentTransport;
|
|
480
|
+
}
|
|
412
481
|
getBaseUrl() {
|
|
413
482
|
return this.httpClient.defaults.baseURL || '';
|
|
414
483
|
}
|
|
@@ -540,7 +609,7 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
|
|
|
540
609
|
return this.parseResponse(response);
|
|
541
610
|
})
|
|
542
611
|
.catch((e) => __awaiter(this, void 0, void 0, function* () {
|
|
543
|
-
return yield this.handleError(e, () => this.patch(url, data, accessToken));
|
|
612
|
+
return yield this.handleError(e, () => this.patch(url, data, accessToken, overrideHeaders));
|
|
544
613
|
}));
|
|
545
614
|
});
|
|
546
615
|
}
|
|
@@ -632,17 +701,6 @@ exports.RequestClient = RequestClient;
|
|
|
632
701
|
* included here.
|
|
633
702
|
*/
|
|
634
703
|
const isTokenRefreshUrl = (url) => !!url && /(^|\/)auth\/refresh(\?|$)/.test(url);
|
|
635
|
-
/**
|
|
636
|
-
* Raises the error a response status implies, marked as one built from a
|
|
637
|
-
* response.
|
|
638
|
-
*
|
|
639
|
-
* The marking has to happen here: every error below is a new object carrying
|
|
640
|
-
* the body, so the axios error - the thing that knew a response had arrived -
|
|
641
|
-
* is gone by the time a caller catches it (sasjs/adapter#895). A 401 from a
|
|
642
|
-
* refresh route is named by `throwForStatus` as a rejected refresh token
|
|
643
|
-
* (sasjs/adapter#975); this marks it as an answer that arrived, so a transport
|
|
644
|
-
* failure and a refusal are not reported with the same title.
|
|
645
|
-
*/
|
|
646
704
|
const throwIfError = (response) => {
|
|
647
705
|
try {
|
|
648
706
|
throwForStatus(response);
|
package/types/Folder.d.ts
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateForcedServicePack = validateForcedServicePack;
|
|
4
|
+
/** Validate the entire destructive deployment scope before making any request. */
|
|
5
|
+
function validateForcedServicePack(appLoc, pack) {
|
|
6
|
+
const safeName = (value) => typeof value === 'string' &&
|
|
7
|
+
value.length > 0 &&
|
|
8
|
+
value.trim() === value &&
|
|
9
|
+
value !== '.' &&
|
|
10
|
+
value !== '..' &&
|
|
11
|
+
!/[\/\\%?#\u0000-\u001f\u007f]/.test(value) &&
|
|
12
|
+
!/[. ]$/.test(value) &&
|
|
13
|
+
!/[\u200b-\u200f\u202a-\u202e\u2060-\u206f\ufeff]/.test(value);
|
|
14
|
+
if (typeof appLoc !== 'string' || !appLoc.startsWith('/'))
|
|
15
|
+
throw new Error('Invalid forced deployment appLoc');
|
|
16
|
+
const parts = appLoc.slice(1).split('/');
|
|
17
|
+
if (parts.length < 2 ||
|
|
18
|
+
!parts.every(safeName) ||
|
|
19
|
+
/^(home|homes|user|my folder|myfolder|@myfolder|@myrecyclebin)$/i.test(parts[0]) ||
|
|
20
|
+
(/^users$/i.test(parts[0]) && parts.length < 3) ||
|
|
21
|
+
(/^users$/i.test(parts[0]) &&
|
|
22
|
+
parts.length === 3 &&
|
|
23
|
+
/^my folder$/i.test(parts[2])) ||
|
|
24
|
+
parts.slice(1).some((part) => /^users$/i.test(part)))
|
|
25
|
+
throw new Error('Unsafe forced deployment appLoc');
|
|
26
|
+
const seen = new Set();
|
|
27
|
+
const validate = (members) => {
|
|
28
|
+
if (!Array.isArray(members))
|
|
29
|
+
throw new Error('Invalid service pack members');
|
|
30
|
+
if (seen.has(members))
|
|
31
|
+
throw new Error('Cyclic service pack');
|
|
32
|
+
seen.add(members);
|
|
33
|
+
const names = new Set();
|
|
34
|
+
for (const member of members) {
|
|
35
|
+
if (!member || typeof member !== 'object' || !safeName(member.name))
|
|
36
|
+
throw new Error('Invalid service pack member name');
|
|
37
|
+
const name = member.name.toLowerCase();
|
|
38
|
+
if (names.has(name))
|
|
39
|
+
throw new Error('Ambiguous service pack member name');
|
|
40
|
+
names.add(name);
|
|
41
|
+
if (member.type === 'folder') {
|
|
42
|
+
if (member.members !== undefined)
|
|
43
|
+
validate(member.members);
|
|
44
|
+
}
|
|
45
|
+
else if (member.type === 'service') {
|
|
46
|
+
if (Array.from(member.name).length > 100)
|
|
47
|
+
throw new Error('Invalid service name: exceeds 100 characters');
|
|
48
|
+
if (typeof member.code !== 'string')
|
|
49
|
+
throw new Error('Invalid service code');
|
|
50
|
+
if (member.members !== undefined)
|
|
51
|
+
throw new Error('Invalid service members');
|
|
52
|
+
}
|
|
53
|
+
else if (member.type === 'file') {
|
|
54
|
+
// The existing file API sends this name verbatim in a quoted HTTP header.
|
|
55
|
+
// Without a verified Viya encoding contract, reject unsafe values before
|
|
56
|
+
// the destructive move rather than silently rename or escape them.
|
|
57
|
+
if (!/^[\x20-\x21\x23-\x7e]+$/.test(member.name))
|
|
58
|
+
throw new Error('Invalid file name for forced deployment HTTP header');
|
|
59
|
+
if (typeof member.code !== 'string' && !ArrayBuffer.isView(member.code))
|
|
60
|
+
throw new Error('Invalid file content');
|
|
61
|
+
if (member.members !== undefined)
|
|
62
|
+
throw new Error('Invalid file members');
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
throw new Error('Invalid service pack member type');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
seen.delete(members);
|
|
69
|
+
};
|
|
70
|
+
if (!pack || typeof pack !== 'object')
|
|
71
|
+
throw new Error('Invalid service pack');
|
|
72
|
+
validate(pack.members);
|
|
73
|
+
}
|