@sap-ux/system-access 0.3.28 → 0.3.30
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/base/connect.d.ts +10 -3
- package/dist/base/connect.js +69 -25
- package/dist/base/prompts.d.ts +1 -0
- package/dist/base/prompts.js +11 -0
- package/package.json +2 -1
package/dist/base/connect.d.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import type { Logger } from '@sap-ux/logger';
|
|
2
|
-
import type { AbapTarget, UrlAbapTarget } from '../types';
|
|
2
|
+
import type { AbapTarget, DestinationAbapTarget, UrlAbapTarget } from '../types';
|
|
3
3
|
import type { AbapServiceProvider, AxiosRequestConfig, ProviderConfiguration } from '@sap-ux/axios-extension';
|
|
4
4
|
/**
|
|
5
|
-
* Check if it is a url
|
|
5
|
+
* Check if it is a url target.
|
|
6
6
|
*
|
|
7
7
|
* @param target target configuration
|
|
8
|
-
* @returns true
|
|
8
|
+
* @returns true if it is a UrlAbapTarget
|
|
9
9
|
*/
|
|
10
10
|
export declare function isUrlTarget(target: AbapTarget): target is UrlAbapTarget;
|
|
11
|
+
/**
|
|
12
|
+
* Check if it is a destination target.
|
|
13
|
+
*
|
|
14
|
+
* @param target target configuration
|
|
15
|
+
* @returns true if it is a DestinationAbapTarget
|
|
16
|
+
*/
|
|
17
|
+
export declare function isDestinationTarget(target: AbapTarget): target is DestinationAbapTarget;
|
|
11
18
|
/**
|
|
12
19
|
* Create an instance of an ABAP service provider connected to the given target configuration.
|
|
13
20
|
*
|
package/dist/base/connect.js
CHANGED
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.createAbapServiceProvider = exports.isUrlTarget = void 0;
|
|
15
|
+
exports.createAbapServiceProvider = exports.isDestinationTarget = exports.isUrlTarget = void 0;
|
|
16
16
|
const axios_extension_1 = require("@sap-ux/axios-extension");
|
|
17
17
|
const credentials_1 = require("./credentials");
|
|
18
18
|
const btp_utils_1 = require("@sap-ux/btp-utils");
|
|
@@ -21,15 +21,25 @@ const prompts_2 = __importDefault(require("prompts"));
|
|
|
21
21
|
const fs_1 = require("fs");
|
|
22
22
|
const store_1 = require("@sap-ux/store");
|
|
23
23
|
/**
|
|
24
|
-
* Check if it is a url
|
|
24
|
+
* Check if it is a url target.
|
|
25
25
|
*
|
|
26
26
|
* @param target target configuration
|
|
27
|
-
* @returns true
|
|
27
|
+
* @returns true if it is a UrlAbapTarget
|
|
28
28
|
*/
|
|
29
29
|
function isUrlTarget(target) {
|
|
30
30
|
return target.url !== undefined;
|
|
31
31
|
}
|
|
32
32
|
exports.isUrlTarget = isUrlTarget;
|
|
33
|
+
/**
|
|
34
|
+
* Check if it is a destination target.
|
|
35
|
+
*
|
|
36
|
+
* @param target target configuration
|
|
37
|
+
* @returns true if it is a DestinationAbapTarget
|
|
38
|
+
*/
|
|
39
|
+
function isDestinationTarget(target) {
|
|
40
|
+
return target.destination !== undefined;
|
|
41
|
+
}
|
|
42
|
+
exports.isDestinationTarget = isDestinationTarget;
|
|
33
43
|
/**
|
|
34
44
|
* Enhance axios options and create a service provider instance for an ABAP Cloud system.
|
|
35
45
|
*
|
|
@@ -75,10 +85,6 @@ function createAbapCloudServiceProvider(options, target, prompt, logger) {
|
|
|
75
85
|
*/
|
|
76
86
|
function createAbapOnPremServiceProvider(options, target, prompt, logger) {
|
|
77
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
options.baseURL = target.url;
|
|
79
|
-
if (target.client) {
|
|
80
|
-
options.params['sap-client'] = target.client;
|
|
81
|
-
}
|
|
82
88
|
if (!options.auth) {
|
|
83
89
|
const storedOpts = yield (0, credentials_1.getCredentialsFromStore)(target, logger);
|
|
84
90
|
if ((0, credentials_1.isBasicAuth)(storedOpts)) {
|
|
@@ -92,16 +98,60 @@ function createAbapOnPremServiceProvider(options, target, prompt, logger) {
|
|
|
92
98
|
throw new Error('This is an ABAP Cloud system, please correct your configuration.');
|
|
93
99
|
}
|
|
94
100
|
if (prompt) {
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
101
|
+
const { authType } = yield (0, prompts_2.default)([prompts_1.questions.authType]);
|
|
102
|
+
if (authType === store_1.AuthenticationType.ReentranceTicket) {
|
|
103
|
+
target.authenticationType = store_1.AuthenticationType.ReentranceTicket;
|
|
104
|
+
return (0, axios_extension_1.createForAbapOnCloud)(Object.assign(Object.assign(Object.assign({}, options), target), { environment: axios_extension_1.AbapCloudEnvironment.EmbeddedSteampunk }));
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
const credentials = yield (0, credentials_1.getCredentialsWithPrompts)(storedOpts === null || storedOpts === void 0 ? void 0 : storedOpts.username);
|
|
108
|
+
options.auth = credentials;
|
|
109
|
+
process.env.FIORI_TOOLS_USER = credentials.username;
|
|
110
|
+
process.env.FIORI_TOOLS_PASSWORD = credentials.password;
|
|
111
|
+
}
|
|
99
112
|
}
|
|
100
113
|
}
|
|
101
114
|
}
|
|
102
115
|
return (0, axios_extension_1.createForAbap)(options);
|
|
103
116
|
});
|
|
104
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Enhance axios options and create a service provider instance for a destination.
|
|
120
|
+
*
|
|
121
|
+
* @param options predefined axios options
|
|
122
|
+
* @param target url target configuration
|
|
123
|
+
* @param prompt - prompt the user for missing information
|
|
124
|
+
* @returns an ABAPServiceProvider instance
|
|
125
|
+
*/
|
|
126
|
+
function createAbapDestinationServiceProvider(options, target, prompt) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
// Need additional properties to determine the type of destination we are dealing with
|
|
129
|
+
const destinations = yield (0, btp_utils_1.listDestinations)();
|
|
130
|
+
const destination = destinations === null || destinations === void 0 ? void 0 : destinations[target.destination];
|
|
131
|
+
if (!destination) {
|
|
132
|
+
throw new Error(`Destination ${target.destination} not found on subaccount`);
|
|
133
|
+
}
|
|
134
|
+
const provider = (0, axios_extension_1.createForDestination)(options, destination);
|
|
135
|
+
// if prompting is enabled, check if the destination works or basic auth is required
|
|
136
|
+
if (prompt) {
|
|
137
|
+
const id = provider.interceptors.response.use(undefined, (error) => __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
var _a;
|
|
139
|
+
provider.interceptors.response.eject(id);
|
|
140
|
+
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
|
|
141
|
+
const credentials = yield (0, credentials_1.getCredentialsWithPrompts)();
|
|
142
|
+
provider.defaults.auth = credentials;
|
|
143
|
+
process.env.FIORI_TOOLS_USER = credentials.username;
|
|
144
|
+
process.env.FIORI_TOOLS_PASSWORD = credentials.password;
|
|
145
|
+
return provider.request(error.config);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
return provider;
|
|
153
|
+
});
|
|
154
|
+
}
|
|
105
155
|
/**
|
|
106
156
|
* Create an instance of an ABAP service provider connected to the given target configuration.
|
|
107
157
|
*
|
|
@@ -116,28 +166,22 @@ function createAbapServiceProvider(target, requestOptions, prompt, logger) {
|
|
|
116
166
|
return __awaiter(this, void 0, void 0, function* () {
|
|
117
167
|
let provider;
|
|
118
168
|
const options = Object.assign({ params: (_a = target.params) !== null && _a !== void 0 ? _a : {} }, requestOptions);
|
|
119
|
-
// Destination only supported
|
|
120
|
-
if ((0, btp_utils_1.isAppStudio)() && target
|
|
121
|
-
|
|
122
|
-
const destinations = yield (0, btp_utils_1.listDestinations)();
|
|
123
|
-
const destination = destinations === null || destinations === void 0 ? void 0 : destinations[target.destination];
|
|
124
|
-
if (!destination) {
|
|
125
|
-
throw new Error(`Destination ${target.destination} not found on subaccount`);
|
|
126
|
-
}
|
|
127
|
-
provider = (0, axios_extension_1.createForDestination)(options, destination);
|
|
169
|
+
// Destination only supported in Business Application Studio
|
|
170
|
+
if ((0, btp_utils_1.isAppStudio)() && isDestinationTarget(target)) {
|
|
171
|
+
provider = yield createAbapDestinationServiceProvider(options, target, prompt);
|
|
128
172
|
}
|
|
129
173
|
else if (isUrlTarget(target)) {
|
|
130
174
|
if (target.scp) {
|
|
131
175
|
provider = yield createAbapCloudServiceProvider(options, target, prompt, logger);
|
|
132
176
|
}
|
|
133
177
|
else if (target.authenticationType === store_1.AuthenticationType.ReentranceTicket) {
|
|
134
|
-
provider = (0, axios_extension_1.createForAbapOnCloud)({
|
|
135
|
-
ignoreCertErrors: options.ignoreCertErrors,
|
|
136
|
-
environment: axios_extension_1.AbapCloudEnvironment.EmbeddedSteampunk,
|
|
137
|
-
url: target.url
|
|
138
|
-
});
|
|
178
|
+
provider = (0, axios_extension_1.createForAbapOnCloud)(Object.assign({ ignoreCertErrors: options.ignoreCertErrors, environment: axios_extension_1.AbapCloudEnvironment.EmbeddedSteampunk }, target));
|
|
139
179
|
}
|
|
140
180
|
else {
|
|
181
|
+
options.baseURL = target.url;
|
|
182
|
+
if (target.client) {
|
|
183
|
+
options.params['sap-client'] = target.client;
|
|
184
|
+
}
|
|
141
185
|
provider = yield createAbapOnPremServiceProvider(options, target, prompt, logger);
|
|
142
186
|
}
|
|
143
187
|
}
|
package/dist/base/prompts.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { PromptObject } from 'prompts';
|
|
|
3
3
|
* Export map of questions for usage with the prompts modules
|
|
4
4
|
*/
|
|
5
5
|
export declare const questions: {
|
|
6
|
+
readonly authType: PromptObject<string>;
|
|
6
7
|
readonly username: PromptObject<string>;
|
|
7
8
|
readonly password: PromptObject<string>;
|
|
8
9
|
readonly serviceKeysPath: PromptObject<string>;
|
package/dist/base/prompts.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.inquirer = exports.questions = void 0;
|
|
4
|
+
const store_1 = require("@sap-ux/store");
|
|
4
5
|
const fs_1 = require("fs");
|
|
6
|
+
const authType = {
|
|
7
|
+
type: 'autocomplete',
|
|
8
|
+
name: 'authType',
|
|
9
|
+
message: 'Type of authentication:',
|
|
10
|
+
choices: [
|
|
11
|
+
{ title: 'Basic authentication', value: store_1.AuthenticationType.Basic },
|
|
12
|
+
{ title: 'SAP reentrance tickets', value: store_1.AuthenticationType.ReentranceTicket }
|
|
13
|
+
]
|
|
14
|
+
};
|
|
5
15
|
const username = {
|
|
6
16
|
type: 'text',
|
|
7
17
|
name: 'username',
|
|
@@ -34,6 +44,7 @@ const systemName = {
|
|
|
34
44
|
* Export map of questions for usage with the prompts modules
|
|
35
45
|
*/
|
|
36
46
|
exports.questions = {
|
|
47
|
+
authType,
|
|
37
48
|
username,
|
|
38
49
|
password,
|
|
39
50
|
serviceKeysPath,
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"bugs": {
|
|
10
10
|
"url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Asystem-access"
|
|
11
11
|
},
|
|
12
|
-
"version": "0.3.
|
|
12
|
+
"version": "0.3.30",
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"author": "@SAP/ux-tools-team",
|
|
15
15
|
"main": "dist/index.js",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/prompts": "2.4.4",
|
|
33
|
+
"nock": "13.4.0",
|
|
33
34
|
"rimraf": "5.0.5",
|
|
34
35
|
"@sap-ux/project-access": "1.20.0"
|
|
35
36
|
},
|