@sap-ux/system-access 0.4.7 → 0.5.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/dist/base/connect.js +108 -113
- package/dist/base/credentials.js +40 -48
- package/package.json +6 -6
package/dist/base/connect.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -49,30 +40,32 @@ exports.isDestinationTarget = isDestinationTarget;
|
|
|
49
40
|
* @param logger - reference to the logger instance
|
|
50
41
|
* @returns an abap service provider
|
|
51
42
|
*/
|
|
52
|
-
function createAbapCloudServiceProvider(options, target, prompt, logger) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
providerConfig.service = JSON.parse((0, fs_1.readFileSync)(path, 'utf-8'));
|
|
66
|
-
}
|
|
43
|
+
async function createAbapCloudServiceProvider(options, target, prompt, logger) {
|
|
44
|
+
const providerConfig = {
|
|
45
|
+
...options,
|
|
46
|
+
environment: axios_extension_1.AbapCloudEnvironment.Standalone,
|
|
47
|
+
service: target.serviceKey
|
|
48
|
+
};
|
|
49
|
+
if (!providerConfig.service) {
|
|
50
|
+
// first try reading the keys from the store
|
|
51
|
+
const storedOpts = await (0, credentials_1.getCredentialsFromStore)(target, logger);
|
|
52
|
+
if ((0, credentials_1.isServiceAuth)(storedOpts)) {
|
|
53
|
+
providerConfig.service = storedOpts.serviceKeys;
|
|
54
|
+
providerConfig.refreshToken = storedOpts.refreshToken;
|
|
55
|
+
logger.info(`Using system [${storedOpts.name}] from System store`);
|
|
67
56
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
57
|
+
if (!providerConfig.service && prompt) {
|
|
58
|
+
const { path } = await (0, prompts_2.default)(prompts_1.questions.serviceKeysPath);
|
|
59
|
+
providerConfig.service = JSON.parse((0, fs_1.readFileSync)(path, 'utf-8'));
|
|
71
60
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
61
|
+
}
|
|
62
|
+
// if no keys are available throw and error
|
|
63
|
+
if (providerConfig.service) {
|
|
64
|
+
return (0, axios_extension_1.createForAbapOnCloud)(providerConfig);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
throw new Error('Service keys required for ABAP Cloud environment.');
|
|
68
|
+
}
|
|
76
69
|
}
|
|
77
70
|
/**
|
|
78
71
|
* Enhance axios options and create a service provider instance for an on-premise ABAP system.
|
|
@@ -83,40 +76,41 @@ function createAbapCloudServiceProvider(options, target, prompt, logger) {
|
|
|
83
76
|
* @param logger reference to the logger instance
|
|
84
77
|
* @returns an ABAPServiceProvider instance
|
|
85
78
|
*/
|
|
86
|
-
function createAbapOnPremServiceProvider(options, target, prompt, logger) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
79
|
+
async function createAbapOnPremServiceProvider(options, target, prompt, logger) {
|
|
80
|
+
if (!options.auth) {
|
|
81
|
+
const storedOpts = await (0, credentials_1.getCredentialsFromStore)(target, logger);
|
|
82
|
+
if ((0, credentials_1.isBasicAuth)(storedOpts)) {
|
|
83
|
+
options.auth = {
|
|
84
|
+
username: storedOpts.username,
|
|
85
|
+
password: storedOpts.password
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
if ((0, credentials_1.isServiceAuth)(storedOpts)) {
|
|
90
|
+
throw new Error('This is an ABAP Cloud system, please correct your configuration.');
|
|
96
91
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
92
|
+
options.auth ??= (0, credentials_1.getCredentialsFromEnvVariables)();
|
|
93
|
+
if (!options.auth && prompt) {
|
|
94
|
+
const { authType } = await (0, prompts_2.default)([prompts_1.questions.authType]);
|
|
95
|
+
if (authType === store_1.AuthenticationType.ReentranceTicket) {
|
|
96
|
+
target.authenticationType = store_1.AuthenticationType.ReentranceTicket;
|
|
100
97
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
const credentials = yield (0, credentials_1.getCredentialsWithPrompts)(storedOpts === null || storedOpts === void 0 ? void 0 : storedOpts.username);
|
|
109
|
-
options.auth = credentials;
|
|
110
|
-
process.env.FIORI_TOOLS_USER = credentials.username;
|
|
111
|
-
process.env.FIORI_TOOLS_PASSWORD = credentials.password;
|
|
112
|
-
}
|
|
98
|
+
else {
|
|
99
|
+
const credentials = await (0, credentials_1.getCredentialsWithPrompts)(storedOpts?.username);
|
|
100
|
+
options.auth = credentials;
|
|
101
|
+
process.env.FIORI_TOOLS_USER = credentials.username;
|
|
102
|
+
process.env.FIORI_TOOLS_PASSWORD = credentials.password;
|
|
113
103
|
}
|
|
114
104
|
}
|
|
115
105
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
106
|
+
}
|
|
107
|
+
return target.authenticationType === store_1.AuthenticationType.ReentranceTicket
|
|
108
|
+
? (0, axios_extension_1.createForAbapOnCloud)({
|
|
109
|
+
...options,
|
|
110
|
+
...target,
|
|
111
|
+
environment: axios_extension_1.AbapCloudEnvironment.EmbeddedSteampunk
|
|
112
|
+
})
|
|
113
|
+
: (0, axios_extension_1.createForAbap)(options);
|
|
120
114
|
}
|
|
121
115
|
/**
|
|
122
116
|
* Enhance axios options and create a service provider instance for a destination.
|
|
@@ -126,34 +120,31 @@ function createAbapOnPremServiceProvider(options, target, prompt, logger) {
|
|
|
126
120
|
* @param prompt - prompt the user for missing information
|
|
127
121
|
* @returns an ABAPServiceProvider instance
|
|
128
122
|
*/
|
|
129
|
-
function createAbapDestinationServiceProvider(options, target, prompt) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
return provider;
|
|
156
|
-
});
|
|
123
|
+
async function createAbapDestinationServiceProvider(options, target, prompt) {
|
|
124
|
+
// Need additional properties to determine the type of destination we are dealing with
|
|
125
|
+
const destinations = await (0, btp_utils_1.listDestinations)();
|
|
126
|
+
const destination = destinations?.[target.destination];
|
|
127
|
+
if (!destination) {
|
|
128
|
+
throw new Error(`Destination ${target.destination} not found on subaccount`);
|
|
129
|
+
}
|
|
130
|
+
const provider = (0, axios_extension_1.createForDestination)(options, destination);
|
|
131
|
+
// if prompting is enabled, check if the destination works or basic auth is required
|
|
132
|
+
if (prompt) {
|
|
133
|
+
const id = provider.interceptors.response.use(undefined, async (error) => {
|
|
134
|
+
provider.interceptors.response.eject(id);
|
|
135
|
+
if (error.response?.status === 401) {
|
|
136
|
+
const credentials = await (0, credentials_1.getCredentialsWithPrompts)();
|
|
137
|
+
provider.defaults.auth = credentials;
|
|
138
|
+
process.env.FIORI_TOOLS_USER = credentials.username;
|
|
139
|
+
process.env.FIORI_TOOLS_PASSWORD = credentials.password;
|
|
140
|
+
return provider.request(error.config);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return provider;
|
|
157
148
|
}
|
|
158
149
|
/**
|
|
159
150
|
* Create an instance of an ABAP service provider connected to the given target configuration.
|
|
@@ -164,35 +155,39 @@ function createAbapDestinationServiceProvider(options, target, prompt) {
|
|
|
164
155
|
* @param logger - optional reference to the logger instance
|
|
165
156
|
* @returns service instance
|
|
166
157
|
*/
|
|
167
|
-
function createAbapServiceProvider(target, requestOptions, prompt, logger) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
158
|
+
async function createAbapServiceProvider(target, requestOptions, prompt, logger) {
|
|
159
|
+
let provider;
|
|
160
|
+
const options = {
|
|
161
|
+
params: target.params ?? {},
|
|
162
|
+
...requestOptions
|
|
163
|
+
};
|
|
164
|
+
// Destination only supported in Business Application Studio
|
|
165
|
+
if ((0, btp_utils_1.isAppStudio)() && isDestinationTarget(target)) {
|
|
166
|
+
provider = await createAbapDestinationServiceProvider(options, target, prompt);
|
|
167
|
+
}
|
|
168
|
+
else if (isUrlTarget(target)) {
|
|
169
|
+
if (target.scp) {
|
|
170
|
+
provider = await createAbapCloudServiceProvider(options, target, prompt, logger);
|
|
175
171
|
}
|
|
176
|
-
else if (
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
options.baseURL = target.url;
|
|
185
|
-
if (target.client) {
|
|
186
|
-
options.params['sap-client'] = target.client;
|
|
187
|
-
}
|
|
188
|
-
provider = yield createAbapOnPremServiceProvider(options, target, prompt, logger);
|
|
189
|
-
}
|
|
172
|
+
else if (target.authenticationType === store_1.AuthenticationType.ReentranceTicket) {
|
|
173
|
+
provider = (0, axios_extension_1.createForAbapOnCloud)({
|
|
174
|
+
ignoreCertErrors: options.ignoreCertErrors,
|
|
175
|
+
environment: axios_extension_1.AbapCloudEnvironment.EmbeddedSteampunk,
|
|
176
|
+
...target
|
|
177
|
+
});
|
|
190
178
|
}
|
|
191
179
|
else {
|
|
192
|
-
|
|
180
|
+
options.baseURL = target.url;
|
|
181
|
+
if (target.client) {
|
|
182
|
+
options.params['sap-client'] = target.client;
|
|
183
|
+
}
|
|
184
|
+
provider = await createAbapOnPremServiceProvider(options, target, prompt, logger);
|
|
193
185
|
}
|
|
194
|
-
|
|
195
|
-
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
throw new Error('Unable to handle the configuration in the current environment.');
|
|
189
|
+
}
|
|
190
|
+
return provider;
|
|
196
191
|
}
|
|
197
192
|
exports.createAbapServiceProvider = createAbapServiceProvider;
|
|
198
193
|
//# sourceMappingURL=connect.js.map
|
package/dist/base/credentials.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -44,25 +35,23 @@ exports.isServiceAuth = isServiceAuth;
|
|
|
44
35
|
* @param logger - reference to the logger instance
|
|
45
36
|
* @returns credentials from the store or undefined.
|
|
46
37
|
*/
|
|
47
|
-
function getCredentialsFromStore(target, logger) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
system = yield systemService.read(new store_1.BackendSystemKey({ url: target.url }));
|
|
56
|
-
}
|
|
57
|
-
return system;
|
|
38
|
+
async function getCredentialsFromStore(target, logger) {
|
|
39
|
+
try {
|
|
40
|
+
if (!(0, btp_utils_1.isAppStudio)()) {
|
|
41
|
+
const systemService = await (0, store_1.getService)({ entityName: 'system' });
|
|
42
|
+
let system = await systemService.read(new store_1.BackendSystemKey({ url: target.url, client: target.client }));
|
|
43
|
+
// check if there are credentials for the default client
|
|
44
|
+
if (!system && target.client) {
|
|
45
|
+
system = await systemService.read(new store_1.BackendSystemKey({ url: target.url }));
|
|
58
46
|
}
|
|
47
|
+
return system;
|
|
59
48
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
logger.warn('Reading credentials from store failed');
|
|
52
|
+
logger.debug(error.message);
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
66
55
|
}
|
|
67
56
|
exports.getCredentialsFromStore = getCredentialsFromStore;
|
|
68
57
|
/**
|
|
@@ -78,20 +67,22 @@ exports.getCredentialsFromStore = getCredentialsFromStore;
|
|
|
78
67
|
* @param logger reference to the logger instance
|
|
79
68
|
* @returns true if the credentials are successfully stored
|
|
80
69
|
*/
|
|
81
|
-
function storeCredentials(name, target, credentials, logger) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
70
|
+
async function storeCredentials(name, target, credentials, logger) {
|
|
71
|
+
try {
|
|
72
|
+
const systemService = await (0, store_1.getService)({ entityName: 'system' });
|
|
73
|
+
const system = new store_1.BackendSystem({
|
|
74
|
+
name,
|
|
75
|
+
...target,
|
|
76
|
+
...credentials
|
|
77
|
+
});
|
|
78
|
+
await systemService.write(system);
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
logger.error('Could not store credentials.');
|
|
83
|
+
logger.debug(error);
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
95
86
|
}
|
|
96
87
|
exports.storeCredentials = storeCredentials;
|
|
97
88
|
/**
|
|
@@ -117,14 +108,15 @@ exports.getCredentialsFromEnvVariables = getCredentialsFromEnvVariables;
|
|
|
117
108
|
* @param username - optional username that is to be offered as default
|
|
118
109
|
* @returns credentials object with username/password
|
|
119
110
|
*/
|
|
120
|
-
function getCredentialsWithPrompts(username) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
111
|
+
async function getCredentialsWithPrompts(username) {
|
|
112
|
+
const credentials = await (0, prompts_1.default)([
|
|
113
|
+
{
|
|
114
|
+
...prompts_2.questions.username,
|
|
115
|
+
initial: username
|
|
116
|
+
},
|
|
117
|
+
prompts_2.questions.password
|
|
118
|
+
]);
|
|
119
|
+
return credentials;
|
|
128
120
|
}
|
|
129
121
|
exports.getCredentialsWithPrompts = getCredentialsWithPrompts;
|
|
130
122
|
//# sourceMappingURL=credentials.js.map
|
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.
|
|
12
|
+
"version": "0.5.1",
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"author": "@SAP/ux-tools-team",
|
|
15
15
|
"main": "dist/index.js",
|
|
@@ -23,16 +23,16 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"prompts": "2.4.2",
|
|
26
|
-
"@sap-ux/axios-extension": "1.
|
|
27
|
-
"@sap-ux/btp-utils": "0.
|
|
28
|
-
"@sap-ux/
|
|
29
|
-
"@sap-ux/
|
|
26
|
+
"@sap-ux/axios-extension": "1.15.1",
|
|
27
|
+
"@sap-ux/btp-utils": "0.15.0",
|
|
28
|
+
"@sap-ux/logger": "0.6.0",
|
|
29
|
+
"@sap-ux/store": "0.7.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/prompts": "2.4.4",
|
|
33
33
|
"nock": "13.4.0",
|
|
34
34
|
"rimraf": "5.0.5",
|
|
35
|
-
"@sap-ux/project-access": "1.
|
|
35
|
+
"@sap-ux/project-access": "1.23.0"
|
|
36
36
|
},
|
|
37
37
|
"engines": {
|
|
38
38
|
"node": ">=18.x"
|