@sap-ux/system-access 0.4.7 → 0.5.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.
@@ -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
- return __awaiter(this, void 0, void 0, function* () {
54
- const providerConfig = Object.assign(Object.assign({}, options), { environment: axios_extension_1.AbapCloudEnvironment.Standalone, service: target.serviceKey });
55
- if (!providerConfig.service) {
56
- // first try reading the keys from the store
57
- const storedOpts = yield (0, credentials_1.getCredentialsFromStore)(target, logger);
58
- if ((0, credentials_1.isServiceAuth)(storedOpts)) {
59
- providerConfig.service = storedOpts.serviceKeys;
60
- providerConfig.refreshToken = storedOpts.refreshToken;
61
- logger.info(`Using system [${storedOpts.name}] from System store`);
62
- }
63
- if (!providerConfig.service && prompt) {
64
- const { path } = yield (0, prompts_2.default)(prompts_1.questions.serviceKeysPath);
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
- // if no keys are available throw and error
69
- if (providerConfig.service) {
70
- return (0, axios_extension_1.createForAbapOnCloud)(providerConfig);
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
- else {
73
- throw new Error('Service keys required for ABAP Cloud environment.');
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
- var _a;
88
- return __awaiter(this, void 0, void 0, function* () {
89
- if (!options.auth) {
90
- const storedOpts = yield (0, credentials_1.getCredentialsFromStore)(target, logger);
91
- if ((0, credentials_1.isBasicAuth)(storedOpts)) {
92
- options.auth = {
93
- username: storedOpts.username,
94
- password: storedOpts.password
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
- else {
98
- if ((0, credentials_1.isServiceAuth)(storedOpts)) {
99
- throw new Error('This is an ABAP Cloud system, please correct your configuration.');
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
- (_a = options.auth) !== null && _a !== void 0 ? _a : (options.auth = (0, credentials_1.getCredentialsFromEnvVariables)());
102
- if (!options.auth && prompt) {
103
- const { authType } = yield (0, prompts_2.default)([prompts_1.questions.authType]);
104
- if (authType === store_1.AuthenticationType.ReentranceTicket) {
105
- target.authenticationType = store_1.AuthenticationType.ReentranceTicket;
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
- return target.authenticationType === store_1.AuthenticationType.ReentranceTicket
117
- ? (0, axios_extension_1.createForAbapOnCloud)(Object.assign(Object.assign(Object.assign({}, options), target), { environment: axios_extension_1.AbapCloudEnvironment.EmbeddedSteampunk }))
118
- : (0, axios_extension_1.createForAbap)(options);
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
- return __awaiter(this, void 0, void 0, function* () {
131
- // Need additional properties to determine the type of destination we are dealing with
132
- const destinations = yield (0, btp_utils_1.listDestinations)();
133
- const destination = destinations === null || destinations === void 0 ? void 0 : destinations[target.destination];
134
- if (!destination) {
135
- throw new Error(`Destination ${target.destination} not found on subaccount`);
136
- }
137
- const provider = (0, axios_extension_1.createForDestination)(options, destination);
138
- // if prompting is enabled, check if the destination works or basic auth is required
139
- if (prompt) {
140
- const id = provider.interceptors.response.use(undefined, (error) => __awaiter(this, void 0, void 0, function* () {
141
- var _a;
142
- provider.interceptors.response.eject(id);
143
- if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
144
- const credentials = yield (0, credentials_1.getCredentialsWithPrompts)();
145
- provider.defaults.auth = credentials;
146
- process.env.FIORI_TOOLS_USER = credentials.username;
147
- process.env.FIORI_TOOLS_PASSWORD = credentials.password;
148
- return provider.request(error.config);
149
- }
150
- else {
151
- throw error;
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
- var _a;
169
- return __awaiter(this, void 0, void 0, function* () {
170
- let provider;
171
- const options = Object.assign({ params: (_a = target.params) !== null && _a !== void 0 ? _a : {} }, requestOptions);
172
- // Destination only supported in Business Application Studio
173
- if ((0, btp_utils_1.isAppStudio)() && isDestinationTarget(target)) {
174
- provider = yield createAbapDestinationServiceProvider(options, target, prompt);
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 (isUrlTarget(target)) {
177
- if (target.scp) {
178
- provider = yield createAbapCloudServiceProvider(options, target, prompt, logger);
179
- }
180
- else if (target.authenticationType === store_1.AuthenticationType.ReentranceTicket) {
181
- provider = (0, axios_extension_1.createForAbapOnCloud)(Object.assign({ ignoreCertErrors: options.ignoreCertErrors, environment: axios_extension_1.AbapCloudEnvironment.EmbeddedSteampunk }, target));
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
- throw new Error('Unable to handle the configuration in the current environment.');
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
- return provider;
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
@@ -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
- return __awaiter(this, void 0, void 0, function* () {
49
- try {
50
- if (!(0, btp_utils_1.isAppStudio)()) {
51
- const systemService = yield (0, store_1.getService)({ entityName: 'system' });
52
- let system = yield systemService.read(new store_1.BackendSystemKey({ url: target.url, client: target.client }));
53
- // check if there are credentials for the default client
54
- if (!system && target.client) {
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
- catch (error) {
61
- logger.warn('Reading credentials from store failed');
62
- logger.debug(error.message);
63
- }
64
- return undefined;
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
- return __awaiter(this, void 0, void 0, function* () {
83
- try {
84
- const systemService = yield (0, store_1.getService)({ entityName: 'system' });
85
- const system = new store_1.BackendSystem(Object.assign(Object.assign({ name }, target), credentials));
86
- yield systemService.write(system);
87
- return true;
88
- }
89
- catch (error) {
90
- logger.error('Could not store credentials.');
91
- logger.debug(error);
92
- return false;
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
- return __awaiter(this, void 0, void 0, function* () {
122
- const credentials = yield (0, prompts_1.default)([
123
- Object.assign(Object.assign({}, prompts_2.questions.username), { initial: username }),
124
- prompts_2.questions.password
125
- ]);
126
- return credentials;
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.4.7",
12
+ "version": "0.5.2",
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.14.4",
27
- "@sap-ux/btp-utils": "0.14.4",
28
- "@sap-ux/store": "0.6.0",
29
- "@sap-ux/logger": "0.5.1"
26
+ "@sap-ux/axios-extension": "1.16.0",
27
+ "@sap-ux/btp-utils": "0.15.0",
28
+ "@sap-ux/store": "0.7.0",
29
+ "@sap-ux/logger": "0.6.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.22.3"
35
+ "@sap-ux/project-access": "1.25.5"
36
36
  },
37
37
  "engines": {
38
38
  "node": ">=18.x"