@sap-ux/axios-extension 1.26.1 → 2.0.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.
- package/dist/abap/abap-service-provider.d.ts +11 -11
- package/dist/abap/abap-service-provider.js +43 -47
- package/dist/abap/adt-catalog/adt-catalog-service.d.ts +2 -2
- package/dist/abap/adt-catalog/adt-catalog-service.js +7 -11
- package/dist/abap/adt-catalog/adt-schema-store.d.ts +1 -1
- package/dist/abap/adt-catalog/adt-schema-store.js +1 -5
- package/dist/abap/adt-catalog/generators/index.d.ts +2 -2
- package/dist/abap/adt-catalog/generators/index.js +2 -7
- package/dist/abap/adt-catalog/generators/odata-service-generator.d.ts +3 -3
- package/dist/abap/adt-catalog/generators/odata-service-generator.js +2 -6
- package/dist/abap/adt-catalog/generators/types.js +1 -2
- package/dist/abap/adt-catalog/generators/ui-service-generator.d.ts +3 -3
- package/dist/abap/adt-catalog/generators/ui-service-generator.js +2 -6
- package/dist/abap/adt-catalog/index.d.ts +3 -3
- package/dist/abap/adt-catalog/index.js +3 -19
- package/dist/abap/adt-catalog/services/abapcdsview-service.d.ts +2 -2
- package/dist/abap/adt-catalog/services/abapcdsview-service.js +2 -6
- package/dist/abap/adt-catalog/services/adt-service.d.ts +1 -1
- package/dist/abap/adt-catalog/services/adt-service.js +5 -9
- package/dist/abap/adt-catalog/services/ato-service.d.ts +2 -2
- package/dist/abap/adt-catalog/services/ato-service.js +5 -9
- package/dist/abap/adt-catalog/services/businessobjects-service.d.ts +2 -2
- package/dist/abap/adt-catalog/services/businessobjects-service.js +2 -6
- package/dist/abap/adt-catalog/services/filestore-service.d.ts +2 -2
- package/dist/abap/adt-catalog/services/filestore-service.js +5 -9
- package/dist/abap/adt-catalog/services/generator-service.d.ts +3 -3
- package/dist/abap/adt-catalog/services/generator-service.js +2 -6
- package/dist/abap/adt-catalog/services/index.d.ts +13 -12
- package/dist/abap/adt-catalog/services/index.js +12 -27
- package/dist/abap/adt-catalog/services/list-package-service.d.ts +2 -2
- package/dist/abap/adt-catalog/services/list-package-service.js +5 -9
- package/dist/abap/adt-catalog/services/publish-service.d.ts +2 -2
- package/dist/abap/adt-catalog/services/publish-service.js +2 -6
- package/dist/abap/adt-catalog/services/rap-generator-service.d.ts +3 -3
- package/dist/abap/adt-catalog/services/rap-generator-service.js +2 -6
- package/dist/abap/adt-catalog/services/systeminfo-service.d.ts +2 -2
- package/dist/abap/adt-catalog/services/systeminfo-service.js +2 -6
- package/dist/abap/adt-catalog/services/transportcheck-service.d.ts +2 -2
- package/dist/abap/adt-catalog/services/transportcheck-service.js +9 -46
- package/dist/abap/adt-catalog/services/transportrequest-service.d.ts +2 -2
- package/dist/abap/adt-catalog/services/transportrequest-service.js +2 -6
- package/dist/abap/adt-catalog/services/ui5-rt-version-service.d.ts +2 -2
- package/dist/abap/adt-catalog/services/ui5-rt-version-service.js +2 -6
- package/dist/abap/app-index-service.d.ts +1 -1
- package/dist/abap/app-index-service.js +3 -7
- package/dist/abap/catalog/base.d.ts +2 -2
- package/dist/abap/catalog/base.js +3 -7
- package/dist/abap/catalog/index.d.ts +3 -3
- package/dist/abap/catalog/index.js +3 -19
- package/dist/abap/catalog/v2-catalog-service.d.ts +2 -2
- package/dist/abap/catalog/v2-catalog-service.js +7 -11
- package/dist/abap/catalog/v4-catalog-service.d.ts +2 -2
- package/dist/abap/catalog/v4-catalog-service.js +11 -15
- package/dist/abap/index.d.ts +12 -8
- package/dist/abap/index.js +8 -31
- package/dist/abap/lrep-service.d.ts +2 -2
- package/dist/abap/lrep-service.js +24 -31
- package/dist/abap/message.js +10 -18
- package/dist/abap/types/adt-internal-types.js +1 -2
- package/dist/abap/types/adt-types.js +3 -6
- package/dist/abap/types/external-services.js +1 -2
- package/dist/abap/types/index.d.ts +2 -2
- package/dist/abap/types/index.js +2 -18
- package/dist/abap/ui5-abap-repository-service.d.ts +1 -1
- package/dist/abap/ui5-abap-repository-service.js +14 -18
- package/dist/abap/ui5-version-service.d.ts +1 -1
- package/dist/abap/ui5-version-service.js +2 -6
- package/dist/auth/connection.d.ts +1 -1
- package/dist/auth/connection.js +10 -18
- package/dist/auth/error.js +4 -11
- package/dist/auth/index.d.ts +8 -6
- package/dist/auth/index.js +14 -35
- package/dist/auth/redirect.js +1 -5
- package/dist/auth/reentrance-ticket/abap-virtual-host-provider.js +5 -12
- package/dist/auth/reentrance-ticket/index.d.ts +1 -1
- package/dist/auth/reentrance-ticket/index.js +7 -10
- package/dist/auth/reentrance-ticket/redirect.d.ts +1 -1
- package/dist/auth/reentrance-ticket/redirect.js +10 -16
- package/dist/auth/static.js +2 -7
- package/dist/auth/uaa.d.ts +1 -1
- package/dist/auth/uaa.js +24 -31
- package/dist/base/odata-request-error.js +2 -7
- package/dist/base/odata-service.js +4 -8
- package/dist/base/patchTls.js +6 -13
- package/dist/base/service-provider.d.ts +2 -2
- package/dist/base/service-provider.js +8 -12
- package/dist/cacerts/sap-global-root-ca.js +1 -4
- package/dist/factory.d.ts +5 -5
- package/dist/factory.js +44 -56
- package/dist/index.d.ts +9 -9
- package/dist/index.js +10 -28
- package/package.json +9 -7
package/dist/auth/error.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UAATimeoutError = exports.TimeoutError = exports.ConnectionError = exports.BaseError = void 0;
|
|
4
1
|
/** Wraps `Error`. Used as base class for other specific errors */
|
|
5
|
-
class BaseError extends Error {
|
|
2
|
+
export class BaseError extends Error {
|
|
6
3
|
cause;
|
|
7
4
|
/**
|
|
8
5
|
* Constructor taking a message and any object.
|
|
@@ -16,23 +13,19 @@ class BaseError extends Error {
|
|
|
16
13
|
this.name = this.constructor.name;
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
|
-
exports.BaseError = BaseError;
|
|
20
16
|
/**
|
|
21
17
|
* Error representing a connection problem.
|
|
22
18
|
*/
|
|
23
|
-
class ConnectionError extends BaseError {
|
|
19
|
+
export class ConnectionError extends BaseError {
|
|
24
20
|
}
|
|
25
|
-
exports.ConnectionError = ConnectionError;
|
|
26
21
|
/**
|
|
27
22
|
* Error representing a timeout.
|
|
28
23
|
*/
|
|
29
|
-
class TimeoutError extends BaseError {
|
|
24
|
+
export class TimeoutError extends BaseError {
|
|
30
25
|
}
|
|
31
|
-
exports.TimeoutError = TimeoutError;
|
|
32
26
|
/**
|
|
33
27
|
* Error representing a timeout from a UAA service.
|
|
34
28
|
*/
|
|
35
|
-
class UAATimeoutError extends TimeoutError {
|
|
29
|
+
export class UAATimeoutError extends TimeoutError {
|
|
36
30
|
}
|
|
37
|
-
exports.UAATimeoutError = UAATimeoutError;
|
|
38
31
|
//# sourceMappingURL=error.js.map
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { Axios, InternalAxiosRequestConfig } from 'axios';
|
|
2
|
-
import type { ServiceProvider } from '../base/service-provider';
|
|
3
|
-
import {
|
|
4
|
-
import type { AbapServiceProvider } from 'abap/abap-service-provider';
|
|
2
|
+
import type { ServiceProvider } from '../base/service-provider.js';
|
|
3
|
+
import type { AbapServiceProvider } from '../abap/abap-service-provider.js';
|
|
5
4
|
import type { ServiceInfo } from '@sap-ux/btp-utils';
|
|
6
|
-
|
|
7
|
-
export * from './
|
|
8
|
-
export
|
|
5
|
+
import type { RefreshTokenChanged } from './uaa.js';
|
|
6
|
+
export * from './connection.js';
|
|
7
|
+
export * from './error.js';
|
|
8
|
+
export type { ServiceInfo } from '@sap-ux/btp-utils';
|
|
9
|
+
export type { RefreshTokenChanged } from './uaa.js';
|
|
10
|
+
export { Uaa } from './uaa.js';
|
|
9
11
|
/**
|
|
10
12
|
* @param provider Basic Auth Provider
|
|
11
13
|
*/
|
package/dist/auth/index.js
CHANGED
|
@@ -1,34 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.Uaa = void 0;
|
|
18
|
-
exports.attachBasicAuthInterceptor = attachBasicAuthInterceptor;
|
|
19
|
-
exports.attachUaaAuthInterceptor = attachUaaAuthInterceptor;
|
|
20
|
-
exports.attachReentranceTicketAuthInterceptor = attachReentranceTicketAuthInterceptor;
|
|
21
|
-
exports.getReentranceTicketAuthInterceptor = getReentranceTicketAuthInterceptor;
|
|
22
|
-
const axios_1 = require("axios");
|
|
23
|
-
const reentrance_ticket_1 = require("./reentrance-ticket");
|
|
24
|
-
const uaa_1 = require("./uaa");
|
|
25
|
-
Object.defineProperty(exports, "Uaa", { enumerable: true, get: function () { return uaa_1.Uaa; } });
|
|
26
|
-
__exportStar(require("./connection"), exports);
|
|
27
|
-
__exportStar(require("./error"), exports);
|
|
1
|
+
import { AxiosHeaders } from 'axios';
|
|
2
|
+
import { getReentranceTicket } from './reentrance-ticket/index.js';
|
|
3
|
+
import { Uaa } from './uaa.js';
|
|
4
|
+
export * from './connection.js';
|
|
5
|
+
export * from './error.js';
|
|
6
|
+
export { Uaa } from './uaa.js';
|
|
28
7
|
/**
|
|
29
8
|
* @param provider Basic Auth Provider
|
|
30
9
|
*/
|
|
31
|
-
function attachBasicAuthInterceptor(provider) {
|
|
10
|
+
export function attachBasicAuthInterceptor(provider) {
|
|
32
11
|
const oneTimeInterceptorId = provider.interceptors.response.use((response) => {
|
|
33
12
|
delete provider.defaults.auth;
|
|
34
13
|
provider.interceptors.response.eject(oneTimeInterceptorId);
|
|
@@ -41,8 +20,8 @@ function attachBasicAuthInterceptor(provider) {
|
|
|
41
20
|
* @param refreshToken refreshToken
|
|
42
21
|
* @param refreshTokenUpdateCb refreshTokenUpdate callback function
|
|
43
22
|
*/
|
|
44
|
-
function attachUaaAuthInterceptor(provider, service, refreshToken, refreshTokenUpdateCb) {
|
|
45
|
-
const uaa = new
|
|
23
|
+
export function attachUaaAuthInterceptor(provider, service, refreshToken, refreshTokenUpdateCb) {
|
|
24
|
+
const uaa = new Uaa(service, provider.log);
|
|
46
25
|
let token;
|
|
47
26
|
const getToken = async () => {
|
|
48
27
|
return service.uaa?.username
|
|
@@ -57,7 +36,7 @@ function attachUaaAuthInterceptor(provider, service, refreshToken, refreshTokenU
|
|
|
57
36
|
provider.interceptors.request.use(async (request) => {
|
|
58
37
|
token = token ?? (await getToken());
|
|
59
38
|
// add token as auth header
|
|
60
|
-
request.headers = request.headers ?? new
|
|
39
|
+
request.headers = request.headers ?? new AxiosHeaders();
|
|
61
40
|
request.headers.authorization = `bearer ${token}`;
|
|
62
41
|
return request;
|
|
63
42
|
});
|
|
@@ -68,7 +47,7 @@ function attachUaaAuthInterceptor(provider, service, refreshToken, refreshTokenU
|
|
|
68
47
|
* @param options options
|
|
69
48
|
* @param options.provider an instance of an ABAP service provider
|
|
70
49
|
*/
|
|
71
|
-
function attachReentranceTicketAuthInterceptor({ provider }) {
|
|
50
|
+
export function attachReentranceTicketAuthInterceptor({ provider }) {
|
|
72
51
|
/* This cannot be a const like eslint claims */
|
|
73
52
|
/* eslint-disable prefer-const */
|
|
74
53
|
let oneTimeInterceptorId;
|
|
@@ -83,15 +62,15 @@ function attachReentranceTicketAuthInterceptor({ provider }) {
|
|
|
83
62
|
* @param options.ejectCallback eject Callback Function
|
|
84
63
|
* @returns the interceptor function to fetch and use reentrace tickets
|
|
85
64
|
*/
|
|
86
|
-
function getReentranceTicketAuthInterceptor({ provider, ejectCallback }) {
|
|
65
|
+
export function getReentranceTicketAuthInterceptor({ provider, ejectCallback }) {
|
|
87
66
|
return async (request) => {
|
|
88
|
-
const { reentranceTicket, backend } = await
|
|
67
|
+
const { reentranceTicket, backend } = await getReentranceTicket({
|
|
89
68
|
backendUrl: provider.defaults.baseURL,
|
|
90
69
|
logger: provider.log
|
|
91
70
|
});
|
|
92
71
|
// Update the base host (provided system url) to the API host for subsequent calls as only this should be used with re-entrance tickets to generate a secure session
|
|
93
72
|
provider.defaults.baseURL = (await backend?.apiHostname()) ?? provider.defaults.baseURL;
|
|
94
|
-
request.headers = request.headers ?? new
|
|
73
|
+
request.headers = request.headers ?? new AxiosHeaders();
|
|
95
74
|
request.headers.MYSAPSSO2 = reentranceTicket;
|
|
96
75
|
// Request a secure session using the reentrance token
|
|
97
76
|
request.headers['x-sap-security-session'] = 'create';
|
package/dist/auth/redirect.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Redirect = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Class representing a local OAuth redirect listener.
|
|
6
3
|
*/
|
|
7
|
-
class Redirect {
|
|
4
|
+
export class Redirect {
|
|
8
5
|
static path = '/oauth/client/redirect';
|
|
9
6
|
port;
|
|
10
7
|
/**
|
|
@@ -24,5 +21,4 @@ class Redirect {
|
|
|
24
21
|
return `http://localhost:${this.port}${Redirect.path}`;
|
|
25
22
|
}
|
|
26
23
|
}
|
|
27
|
-
exports.Redirect = Redirect;
|
|
28
24
|
//# sourceMappingURL=redirect.js.map
|
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ABAPVirtualHostProvider = void 0;
|
|
7
|
-
const logger_1 = require("@sap-ux/logger");
|
|
8
|
-
const axios_1 = __importDefault(require("axios"));
|
|
1
|
+
import { ToolsLogger } from '@sap-ux/logger';
|
|
2
|
+
import axios from 'axios';
|
|
9
3
|
/**
|
|
10
4
|
* Makes requests to determine the virtual host names for UI and API access.
|
|
11
5
|
*/
|
|
12
|
-
class ABAPVirtualHostProvider {
|
|
6
|
+
export class ABAPVirtualHostProvider {
|
|
13
7
|
apiURL;
|
|
14
8
|
uiURL;
|
|
15
9
|
systemURL;
|
|
16
10
|
relatedUrls;
|
|
17
|
-
logger = new
|
|
11
|
+
logger = new ToolsLogger();
|
|
18
12
|
/**
|
|
19
13
|
*
|
|
20
14
|
* @param backendUrl backend Url
|
|
@@ -35,7 +29,7 @@ class ABAPVirtualHostProvider {
|
|
|
35
29
|
if (!this.relatedUrls) {
|
|
36
30
|
this.logger.debug(`Requesting virtual hosts from: ${this.systemURL}`);
|
|
37
31
|
const url = new URL('/sap/public/bc/icf/virtualhost', this.systemURL.origin);
|
|
38
|
-
const response = await
|
|
32
|
+
const response = await axios.get(url.href, {
|
|
39
33
|
headers: {
|
|
40
34
|
Accept: 'application/json'
|
|
41
35
|
}
|
|
@@ -79,5 +73,4 @@ class ABAPVirtualHostProvider {
|
|
|
79
73
|
return (await this.uiHostname()) + '/sap/public/bc/icf/logoff';
|
|
80
74
|
}
|
|
81
75
|
}
|
|
82
|
-
exports.ABAPVirtualHostProvider = ABAPVirtualHostProvider;
|
|
83
76
|
//# sourceMappingURL=abap-virtual-host-provider.js.map
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const connection_1 = require("../connection");
|
|
6
|
-
const abap_virtual_host_provider_1 = require("./abap-virtual-host-provider");
|
|
7
|
-
const redirect_1 = require("./redirect");
|
|
1
|
+
import open from 'open';
|
|
2
|
+
import { defaultTimeout } from '../connection.js';
|
|
3
|
+
import { ABAPVirtualHostProvider } from './abap-virtual-host-provider.js';
|
|
4
|
+
import { setupRedirectHandling } from './redirect.js';
|
|
8
5
|
const ADT_REENTRANCE_ENDPOINT = '/sap/bc/sec/reentrance';
|
|
9
6
|
/**
|
|
10
7
|
* Get the reentrance ticket from the backend.
|
|
@@ -14,12 +11,12 @@ const ADT_REENTRANCE_ENDPOINT = '/sap/bc/sec/reentrance';
|
|
|
14
11
|
* @param options.logger logger
|
|
15
12
|
* @param options.timeout timeout in milliseconds
|
|
16
13
|
*/
|
|
17
|
-
async function getReentranceTicket({ backendUrl, logger, timeout =
|
|
18
|
-
const backend = new
|
|
14
|
+
export async function getReentranceTicket({ backendUrl, logger, timeout = defaultTimeout }) {
|
|
15
|
+
const backend = new ABAPVirtualHostProvider(backendUrl, logger);
|
|
19
16
|
const uiHostname = await backend.uiHostname();
|
|
20
17
|
return new Promise((resolve, reject) => {
|
|
21
18
|
// Start local server to listen to redirect call, with timeout
|
|
22
|
-
const { server, redirectUrl } =
|
|
19
|
+
const { server, redirectUrl } = setupRedirectHandling({ resolve, reject, timeout, backend, logger });
|
|
23
20
|
server.listen();
|
|
24
21
|
const redirectPort = server.address().port;
|
|
25
22
|
// Open browser to handle SAML flow and return the reentrance ticket
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Logger } from '@sap-ux/logger';
|
|
2
2
|
import http from 'node:http';
|
|
3
|
-
import type { ABAPVirtualHostProvider } from './abap-virtual-host-provider';
|
|
3
|
+
import type { ABAPVirtualHostProvider } from './abap-virtual-host-provider.js';
|
|
4
4
|
interface Redirect {
|
|
5
5
|
server: http.Server;
|
|
6
6
|
/**
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.setupRedirectHandling = setupRedirectHandling;
|
|
7
|
-
const node_http_1 = __importDefault(require("node:http"));
|
|
8
|
-
const error_1 = require("../error");
|
|
9
|
-
const message_1 = require("../../abap/message");
|
|
10
|
-
const static_1 = require("../static");
|
|
1
|
+
import http from 'node:http';
|
|
2
|
+
import { ConnectionError, TimeoutError } from '../error.js';
|
|
3
|
+
import { prettyPrintTimeInMs } from '../../abap/message.js';
|
|
4
|
+
import { redirectErrorHtml, redirectSuccessHtml } from '../static.js';
|
|
11
5
|
/**
|
|
12
6
|
*
|
|
13
7
|
* @param options options object
|
|
@@ -18,16 +12,16 @@ const static_1 = require("../static");
|
|
|
18
12
|
* @param options.logger logger
|
|
19
13
|
* @returns a `Redirect` object
|
|
20
14
|
*/
|
|
21
|
-
function setupRedirectHandling({ resolve, reject, timeout, backend, logger }) {
|
|
15
|
+
export function setupRedirectHandling({ resolve, reject, timeout, backend, logger }) {
|
|
22
16
|
const REDIRECT_PATH = '/redirect';
|
|
23
17
|
// eslint-disable-next-line prefer-const
|
|
24
18
|
let server;
|
|
25
19
|
const handleTimeout = () => {
|
|
26
20
|
server?.close();
|
|
27
|
-
reject(new
|
|
21
|
+
reject(new TimeoutError(`Timeout. Did not get a response within ${prettyPrintTimeInMs(timeout)}`));
|
|
28
22
|
};
|
|
29
23
|
const timer = setTimeout(handleTimeout, timeout);
|
|
30
|
-
server =
|
|
24
|
+
server = http.createServer((req, res) => {
|
|
31
25
|
const reqUrl = new URL(req.url, `http://${req.headers.host}`);
|
|
32
26
|
if (reqUrl.pathname === REDIRECT_PATH) {
|
|
33
27
|
if (timer) {
|
|
@@ -40,7 +34,7 @@ function setupRedirectHandling({ resolve, reject, timeout, backend, logger }) {
|
|
|
40
34
|
.logoffUrl()
|
|
41
35
|
.then((url) => {
|
|
42
36
|
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
43
|
-
res.end(Buffer.from(
|
|
37
|
+
res.end(Buffer.from(redirectSuccessHtml(url)));
|
|
44
38
|
})
|
|
45
39
|
.catch(() => { });
|
|
46
40
|
server.close();
|
|
@@ -51,9 +45,9 @@ function setupRedirectHandling({ resolve, reject, timeout, backend, logger }) {
|
|
|
51
45
|
logger.error('Error getting reentrance ticket');
|
|
52
46
|
logger.debug(req);
|
|
53
47
|
res.writeHead(500, { 'Content-Type': 'text/html' });
|
|
54
|
-
res.end(Buffer.from(
|
|
48
|
+
res.end(Buffer.from(redirectErrorHtml()));
|
|
55
49
|
server.close();
|
|
56
|
-
reject(new
|
|
50
|
+
reject(new ConnectionError('Error getting reentrance ticket'));
|
|
57
51
|
}
|
|
58
52
|
}
|
|
59
53
|
});
|
package/dist/auth/static.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.redirectErrorHtml = exports.redirectSuccessHtml = void 0;
|
|
4
|
-
const redirectSuccessHtml = (logoutUrl, systemId) => {
|
|
1
|
+
export const redirectSuccessHtml = (logoutUrl, systemId) => {
|
|
5
2
|
const title = `${systemId ? systemId + ': ' : ''}Authentication Successful`;
|
|
6
3
|
const content = logoutUrl
|
|
7
4
|
? '<a class="centerLink" href="' + logoutUrl + '">(Click here to log off the current user)</a>'
|
|
8
5
|
: '';
|
|
9
6
|
return redirectHtml({ title, content });
|
|
10
7
|
};
|
|
11
|
-
|
|
12
|
-
const redirectErrorHtml = (systemId) => {
|
|
8
|
+
export const redirectErrorHtml = (systemId) => {
|
|
13
9
|
const title = `${systemId ? systemId + ': ' : ''}Authentication Successful`;
|
|
14
10
|
const content = 'Login failed, please check the logs in the console';
|
|
15
11
|
return redirectHtml({ title, content });
|
|
16
12
|
};
|
|
17
|
-
exports.redirectErrorHtml = redirectErrorHtml;
|
|
18
13
|
/**
|
|
19
14
|
*
|
|
20
15
|
* @param options options object
|
package/dist/auth/uaa.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import type { Logger } from '@sap-ux/logger';
|
|
3
3
|
import type { ServiceInfo } from '@sap-ux/btp-utils';
|
|
4
|
-
import { Redirect } from './redirect';
|
|
4
|
+
import { Redirect } from './redirect.js';
|
|
5
5
|
export type RefreshTokenChanged = (refreshToken?: string, accessToken?: string) => void | Promise<void>;
|
|
6
6
|
/**
|
|
7
7
|
* A class representing interactions with an SAP BTP UAA service
|
package/dist/auth/uaa.js
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const qs_1 = __importDefault(require("qs"));
|
|
11
|
-
const redirect_1 = require("./redirect");
|
|
12
|
-
const message_1 = require("../abap/message");
|
|
13
|
-
const error_1 = require("./error");
|
|
14
|
-
const static_1 = require("./static");
|
|
15
|
-
const connection_1 = require("./connection");
|
|
1
|
+
import open from 'open';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import http from 'node:http';
|
|
4
|
+
import qs from 'qs';
|
|
5
|
+
import { Redirect } from './redirect.js';
|
|
6
|
+
import { prettyPrintTimeInMs } from '../abap/message.js';
|
|
7
|
+
import { UAATimeoutError } from './error.js';
|
|
8
|
+
import { redirectSuccessHtml } from './static.js';
|
|
9
|
+
import { defaultTimeout } from './connection.js';
|
|
16
10
|
/**
|
|
17
11
|
* A class representing interactions with an SAP BTP UAA service
|
|
18
12
|
*/
|
|
19
|
-
class Uaa {
|
|
13
|
+
export class Uaa {
|
|
20
14
|
log;
|
|
21
15
|
serviceInfo;
|
|
22
16
|
/**
|
|
@@ -105,7 +99,7 @@ class Uaa {
|
|
|
105
99
|
getAuthCodeUrl({ redirectUri }) {
|
|
106
100
|
return (this.url +
|
|
107
101
|
'/oauth/authorize?' +
|
|
108
|
-
|
|
102
|
+
qs.stringify({
|
|
109
103
|
'response_type': 'code',
|
|
110
104
|
'redirect_uri': redirectUri,
|
|
111
105
|
'client_id': this.clientid
|
|
@@ -121,7 +115,7 @@ class Uaa {
|
|
|
121
115
|
return {
|
|
122
116
|
url: `${this.url}/oauth/token`,
|
|
123
117
|
method: 'POST',
|
|
124
|
-
data:
|
|
118
|
+
data: qs.stringify({
|
|
125
119
|
'grant_type': 'password',
|
|
126
120
|
'username': this.username,
|
|
127
121
|
'password': this.password
|
|
@@ -146,7 +140,7 @@ class Uaa {
|
|
|
146
140
|
url: `${this.url}/oauth/token`,
|
|
147
141
|
auth: { username: this.clientid, password: this.clientsecret },
|
|
148
142
|
method: 'POST',
|
|
149
|
-
data:
|
|
143
|
+
data: qs.stringify({
|
|
150
144
|
code: authCode,
|
|
151
145
|
'grant_type': 'authorization_code',
|
|
152
146
|
'redirect_uri': redirectUri,
|
|
@@ -169,7 +163,7 @@ class Uaa {
|
|
|
169
163
|
url: `${this.url}/oauth/token`,
|
|
170
164
|
auth: { username: this.clientid, password: this.clientsecret },
|
|
171
165
|
method: 'POST',
|
|
172
|
-
data:
|
|
166
|
+
data: qs.stringify({
|
|
173
167
|
'grant_type': 'refresh_token',
|
|
174
168
|
'refresh_token': refreshToken
|
|
175
169
|
}),
|
|
@@ -186,7 +180,7 @@ class Uaa {
|
|
|
186
180
|
* @returns user name or undefined
|
|
187
181
|
*/
|
|
188
182
|
async getUserInfo(accessToken) {
|
|
189
|
-
const userInfoResp = await
|
|
183
|
+
const userInfoResp = await axios.request({
|
|
190
184
|
url: `${this.url}/userinfo`,
|
|
191
185
|
method: 'GET',
|
|
192
186
|
headers: {
|
|
@@ -201,7 +195,7 @@ class Uaa {
|
|
|
201
195
|
* @param timeout timeout
|
|
202
196
|
* @returns an object containing an authentication code and a redirect object
|
|
203
197
|
*/
|
|
204
|
-
async getAuthCode(timeout =
|
|
198
|
+
async getAuthCode(timeout = defaultTimeout) {
|
|
205
199
|
return new Promise((resolve, reject) => {
|
|
206
200
|
// eslint-disable-next-line prefer-const
|
|
207
201
|
let redirect;
|
|
@@ -209,14 +203,14 @@ class Uaa {
|
|
|
209
203
|
let server;
|
|
210
204
|
const handleTimeout = () => {
|
|
211
205
|
server?.close();
|
|
212
|
-
reject(new
|
|
206
|
+
reject(new UAATimeoutError(`Timeout. Did not get a response within ${prettyPrintTimeInMs(timeout)}`));
|
|
213
207
|
};
|
|
214
208
|
const timer = setTimeout(handleTimeout, timeout);
|
|
215
|
-
server =
|
|
209
|
+
server = http.createServer((req, res) => {
|
|
216
210
|
const reqUrl = new URL(req.url, `http://${req.headers.host}`);
|
|
217
|
-
if (reqUrl.pathname ===
|
|
211
|
+
if (reqUrl.pathname === Redirect.path) {
|
|
218
212
|
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
219
|
-
res.end(Buffer.from(
|
|
213
|
+
res.end(Buffer.from(redirectSuccessHtml(this.logoutUrl, this.systemId)));
|
|
220
214
|
this.log.info('Got authCode');
|
|
221
215
|
resolve({ authCode: reqUrl.searchParams.get('code') + '', redirect });
|
|
222
216
|
if (timer) {
|
|
@@ -227,7 +221,7 @@ class Uaa {
|
|
|
227
221
|
});
|
|
228
222
|
// Start listening. Let the OS assign an available port
|
|
229
223
|
server.listen();
|
|
230
|
-
redirect = new
|
|
224
|
+
redirect = new Redirect(server.address().port);
|
|
231
225
|
const oauthUrl = this.getAuthCodeUrl({ redirectUri: redirect.url() });
|
|
232
226
|
open(oauthUrl)?.catch((error) => this.log.error(error));
|
|
233
227
|
});
|
|
@@ -245,7 +239,7 @@ class Uaa {
|
|
|
245
239
|
this.log.info('Refresh token passed in');
|
|
246
240
|
const tokenRequest = this.getTokenRequestForRefreshToken(refreshToken);
|
|
247
241
|
try {
|
|
248
|
-
response = await
|
|
242
|
+
response = await axios.request(tokenRequest);
|
|
249
243
|
// Has refresh token expired?
|
|
250
244
|
if (response.status === 401 || response.data.error === 'invalid_token') {
|
|
251
245
|
startFreshLogin = true;
|
|
@@ -266,7 +260,7 @@ class Uaa {
|
|
|
266
260
|
redirectUri: redirect.url(), // Redirection URL needs to match
|
|
267
261
|
authCode
|
|
268
262
|
});
|
|
269
|
-
response = await
|
|
263
|
+
response = await axios.request(tokenRequest);
|
|
270
264
|
this.log.info('Refresh token issued');
|
|
271
265
|
newRefreshToken = response.data.refresh_token;
|
|
272
266
|
}
|
|
@@ -284,10 +278,9 @@ class Uaa {
|
|
|
284
278
|
*/
|
|
285
279
|
async getAccessTokenWithClientCredentials() {
|
|
286
280
|
const tokenRequest = this.getTokenRequestForClientCredential();
|
|
287
|
-
const response = await
|
|
281
|
+
const response = await axios.request(tokenRequest);
|
|
288
282
|
this.log.info('Got access token successfully using client credentials');
|
|
289
283
|
return response?.data?.access_token;
|
|
290
284
|
}
|
|
291
285
|
}
|
|
292
|
-
exports.Uaa = Uaa;
|
|
293
286
|
//# sourceMappingURL=uaa.js.map
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ODataRequestError = void 0;
|
|
4
|
-
exports.isAxiosError = isAxiosError;
|
|
5
1
|
/**
|
|
6
2
|
* Type guard to narrow an unknown exception to the AxiosError type if it is compatible.
|
|
7
3
|
*
|
|
8
4
|
* @param e unknown error
|
|
9
5
|
* @returns exception cast to AxiosError if it is one
|
|
10
6
|
*/
|
|
11
|
-
function isAxiosError(e) {
|
|
7
|
+
export function isAxiosError(e) {
|
|
12
8
|
return typeof e === 'object' && e !== null && 'isAxiosError' in e;
|
|
13
9
|
}
|
|
14
10
|
/**
|
|
15
11
|
* Error object that is to be thrown if an OData service responds with an error
|
|
16
12
|
*/
|
|
17
|
-
class ODataRequestError extends Error {
|
|
13
|
+
export class ODataRequestError extends Error {
|
|
18
14
|
/**
|
|
19
15
|
* Helper function to check if a parsed OData response contains an error.
|
|
20
16
|
*
|
|
@@ -40,5 +36,4 @@ class ODataRequestError extends Error {
|
|
|
40
36
|
this.name = this.constructor.name;
|
|
41
37
|
}
|
|
42
38
|
}
|
|
43
|
-
exports.ODataRequestError = ODataRequestError;
|
|
44
39
|
//# sourceMappingURL=odata-request-error.js.map
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ODataService = exports.ODataVersion = void 0;
|
|
4
|
-
const axios_1 = require("axios");
|
|
1
|
+
import { Axios } from 'axios';
|
|
5
2
|
/**
|
|
6
3
|
* OData versions supported by Fiori elements
|
|
7
4
|
*/
|
|
8
|
-
var ODataVersion;
|
|
5
|
+
export var ODataVersion;
|
|
9
6
|
(function (ODataVersion) {
|
|
10
7
|
ODataVersion["v2"] = "2";
|
|
11
8
|
ODataVersion["v4"] = "4";
|
|
12
|
-
})(ODataVersion || (
|
|
9
|
+
})(ODataVersion || (ODataVersion = {}));
|
|
13
10
|
/**
|
|
14
11
|
* Parse a JSON based OData response and extract the content from the OData structure.
|
|
15
12
|
*
|
|
@@ -42,7 +39,7 @@ function parseODataResponse(includeV4ControlData = false) {
|
|
|
42
39
|
/**
|
|
43
40
|
* Class extending Axios representing an OData service.
|
|
44
41
|
*/
|
|
45
|
-
class ODataService extends
|
|
42
|
+
export class ODataService extends Axios {
|
|
46
43
|
log;
|
|
47
44
|
doc;
|
|
48
45
|
metadataDoc;
|
|
@@ -109,5 +106,4 @@ class ODataService extends axios_1.Axios {
|
|
|
109
106
|
return response;
|
|
110
107
|
}
|
|
111
108
|
}
|
|
112
|
-
exports.ODataService = ODataService;
|
|
113
109
|
//# sourceMappingURL=odata-service.js.map
|
package/dist/base/patchTls.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TlsPatch = void 0;
|
|
7
|
-
const node_tls_1 = __importDefault(require("node:tls"));
|
|
8
|
-
const sap_global_root_ca_1 = require("../cacerts/sap-global-root-ca");
|
|
1
|
+
import tls from 'node:tls';
|
|
2
|
+
import { sapGlobalRootCaCert } from '../cacerts/sap-global-root-ca.js';
|
|
9
3
|
/**
|
|
10
4
|
* Test for sap domains and patching to trust SAPs root certificate
|
|
11
5
|
*
|
|
12
6
|
*/
|
|
13
|
-
class TlsPatch {
|
|
7
|
+
export class TlsPatch {
|
|
14
8
|
static _patched;
|
|
15
9
|
/**
|
|
16
10
|
* Test if the patch is already applied.
|
|
@@ -36,10 +30,10 @@ class TlsPatch {
|
|
|
36
30
|
if (TlsPatch.isPatched) {
|
|
37
31
|
return;
|
|
38
32
|
}
|
|
39
|
-
const origCreateSecureContext =
|
|
40
|
-
|
|
33
|
+
const origCreateSecureContext = tls.createSecureContext;
|
|
34
|
+
tls.createSecureContext = (options) => {
|
|
41
35
|
const context = origCreateSecureContext(options);
|
|
42
|
-
const pem =
|
|
36
|
+
const pem = sapGlobalRootCaCert.replace(/\r\n/g, '\n');
|
|
43
37
|
const certs = pem.match(/-----BEGIN CERTIFICATE-----\n[\s\S]+?\n-----END CERTIFICATE-----/g);
|
|
44
38
|
certs.forEach((cert) => {
|
|
45
39
|
context.context.addCACert(cert.trim());
|
|
@@ -49,5 +43,4 @@ class TlsPatch {
|
|
|
49
43
|
TlsPatch._patched = true;
|
|
50
44
|
}
|
|
51
45
|
}
|
|
52
|
-
exports.TlsPatch = TlsPatch;
|
|
53
46
|
//# sourceMappingURL=patchTls.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import { Axios } from 'axios';
|
|
3
3
|
import type { Logger } from '@sap-ux/logger';
|
|
4
|
-
import { ODataService } from './odata-service';
|
|
5
|
-
import { Cookies } from '../auth';
|
|
4
|
+
import { ODataService } from './odata-service.js';
|
|
5
|
+
import { Cookies } from '../auth/index.js';
|
|
6
6
|
export type Service = Axios & {
|
|
7
7
|
log: Logger;
|
|
8
8
|
};
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const logger_1 = require("@sap-ux/logger");
|
|
6
|
-
const odata_service_1 = require("./odata-service");
|
|
7
|
-
const auth_1 = require("../auth");
|
|
1
|
+
import { Axios } from 'axios';
|
|
2
|
+
import { ToolsLogger } from '@sap-ux/logger';
|
|
3
|
+
import { ODataService } from './odata-service.js';
|
|
4
|
+
import { Cookies } from '../auth/index.js';
|
|
8
5
|
/**
|
|
9
6
|
* Basic service provider class containing generic functionality to create and keep service instances as well as logging
|
|
10
7
|
*/
|
|
11
|
-
class ServiceProvider extends
|
|
12
|
-
_log = new
|
|
13
|
-
cookies = new
|
|
8
|
+
export class ServiceProvider extends Axios {
|
|
9
|
+
_log = new ToolsLogger();
|
|
10
|
+
cookies = new Cookies();
|
|
14
11
|
services = {};
|
|
15
12
|
/**
|
|
16
13
|
*
|
|
@@ -47,7 +44,7 @@ class ServiceProvider extends axios_1.Axios {
|
|
|
47
44
|
*/
|
|
48
45
|
service(path) {
|
|
49
46
|
if (!this.services[path]) {
|
|
50
|
-
this.services[path] = this.createService(path,
|
|
47
|
+
this.services[path] = this.createService(path, ODataService);
|
|
51
48
|
}
|
|
52
49
|
return this.services[path];
|
|
53
50
|
}
|
|
@@ -93,5 +90,4 @@ class ServiceProvider extends axios_1.Axios {
|
|
|
93
90
|
return this.defaults.baseURL;
|
|
94
91
|
}
|
|
95
92
|
}
|
|
96
|
-
exports.ServiceProvider = ServiceProvider;
|
|
97
93
|
//# sourceMappingURL=service-provider.js.map
|