@sap-ux/backend-proxy-middleware 0.5.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/LICENSE +201 -0
- package/README.md +153 -0
- package/dist/base/config.d.ts +15 -0
- package/dist/base/config.d.ts.map +1 -0
- package/dist/base/config.js +45 -0
- package/dist/base/config.js.map +1 -0
- package/dist/base/i18n.json +14 -0
- package/dist/base/proxy.d.ts +114 -0
- package/dist/base/proxy.d.ts.map +1 -0
- package/dist/base/proxy.js +328 -0
- package/dist/base/proxy.js.map +1 -0
- package/dist/base/types.d.ts +60 -0
- package/dist/base/types.d.ts.map +1 -0
- package/dist/base/types.js +3 -0
- package/dist/base/types.js.map +1 -0
- package/dist/ext/bsp.d.ts +25 -0
- package/dist/ext/bsp.d.ts.map +1 -0
- package/dist/ext/bsp.js +124 -0
- package/dist/ext/bsp.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware.d.ts +2 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +69 -0
- package/dist/middleware.js.map +1 -0
- package/package.json +58 -0
- package/ui5.yaml +7 -0
|
@@ -0,0 +1,328 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.createProxy = exports.generateProxyMiddlewareOptions = exports.enhanceConfigForSystem = exports.enhanceConfigsForDestination = exports.initI18n = exports.PathRewriters = exports.ProxyEventHandlers = void 0;
|
|
16
|
+
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
17
|
+
const http_proxy_middleware_1 = require("http-proxy-middleware");
|
|
18
|
+
const i18next_1 = __importDefault(require("i18next"));
|
|
19
|
+
const logger_1 = require("@sap-ux/logger");
|
|
20
|
+
const axios_extension_1 = require("@sap-ux/axios-extension");
|
|
21
|
+
const btp_utils_1 = require("@sap-ux/btp-utils");
|
|
22
|
+
const i18n_json_1 = __importDefault(require("./i18n.json"));
|
|
23
|
+
const store_1 = require("@sap-ux/store");
|
|
24
|
+
const config_1 = require("./config");
|
|
25
|
+
/**
|
|
26
|
+
* Collection of custom event handler for the proxy.
|
|
27
|
+
*/
|
|
28
|
+
exports.ProxyEventHandlers = {
|
|
29
|
+
/**
|
|
30
|
+
* Modifies the request to the proxy server if the `FioriLaunchpad.html` is requested to add a required header.
|
|
31
|
+
*
|
|
32
|
+
* @param proxyReq request to the proxy server that can be modified
|
|
33
|
+
* @param _req (not used) original request
|
|
34
|
+
* @param _res (not used)
|
|
35
|
+
* @param _options (not used)
|
|
36
|
+
*/
|
|
37
|
+
onProxyReq(proxyReq, _req, _res, _options) {
|
|
38
|
+
if (proxyReq.path.indexOf('Fiorilaunchpad.html') !== -1 && !proxyReq.headersSent) {
|
|
39
|
+
proxyReq.setHeader('accept-encoding', 'br');
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* Retrieve the set-cookie headers from the response and transform secure cookies to insecure ones.
|
|
44
|
+
*
|
|
45
|
+
* @param proxyRes request to the proxy server that can be modified
|
|
46
|
+
* @param _req (not used) original request
|
|
47
|
+
* @param _res (not used)
|
|
48
|
+
*/
|
|
49
|
+
onProxyRes(proxyRes, _req, _res) {
|
|
50
|
+
var _a;
|
|
51
|
+
const header = (_a = proxyRes === null || proxyRes === void 0 ? void 0 : proxyRes.headers) === null || _a === void 0 ? void 0 : _a['set-cookie'];
|
|
52
|
+
if (header === null || header === void 0 ? void 0 : header.length) {
|
|
53
|
+
for (let i = header.length - 1; i >= 0; i--) {
|
|
54
|
+
const cookie = header[i].replace(/\s?Domain=[^\s]*\s?|\s?SameSite=[^\s]*\s?|\s?Secure[^\s]*\s?/gi, '');
|
|
55
|
+
header[i] = cookie;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
/**
|
|
60
|
+
* Specifically handling errors due to unsigned certificates.
|
|
61
|
+
*
|
|
62
|
+
* @param err the error thrown when proxying the request or processing the response
|
|
63
|
+
* @param req request causing the error
|
|
64
|
+
* @param _res (not used)
|
|
65
|
+
* @param _target (not used)
|
|
66
|
+
*/
|
|
67
|
+
onError(err, req, _res, _target) {
|
|
68
|
+
if (err) {
|
|
69
|
+
let error;
|
|
70
|
+
if (err.code === 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY') {
|
|
71
|
+
error = new Error(i18next_1.default.t('error.sslProxy'));
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
error = err;
|
|
75
|
+
}
|
|
76
|
+
if (typeof req.next === 'function') {
|
|
77
|
+
req.next(error);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Return the SAP API Hub key either provided as environment variable (including .env file) or from the secure store when not running in AppStudio.
|
|
87
|
+
* not found or error while extracting the key.
|
|
88
|
+
*
|
|
89
|
+
* @param logger - logger to report errors
|
|
90
|
+
*/
|
|
91
|
+
function getApiHubKey(logger) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
let apiHubKey = process.env.API_HUB_API_KEY;
|
|
94
|
+
if (!apiHubKey && !btp_utils_1.isAppStudio()) {
|
|
95
|
+
const apiHubStore = (yield store_1.getService({
|
|
96
|
+
logger,
|
|
97
|
+
entityName: 'api-hub'
|
|
98
|
+
}));
|
|
99
|
+
const apiHubSettings = yield apiHubStore.read();
|
|
100
|
+
apiHubKey = apiHubSettings ? apiHubSettings.apiKey : undefined;
|
|
101
|
+
}
|
|
102
|
+
return apiHubKey;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Collection of path rewrite functions.
|
|
107
|
+
*/
|
|
108
|
+
exports.PathRewriters = {
|
|
109
|
+
/**
|
|
110
|
+
* Generates a rewrite funtion that replace the match string with the prefix in the given string.
|
|
111
|
+
*
|
|
112
|
+
* @param match part of the path that is to be replaced
|
|
113
|
+
* @param prefix new path that is used as replacement
|
|
114
|
+
* @returns a path rewrite function
|
|
115
|
+
*/
|
|
116
|
+
replacePrefix(match, prefix) {
|
|
117
|
+
return (path) => path.replace(match, prefix.replace(/\/$/, ''));
|
|
118
|
+
},
|
|
119
|
+
/**
|
|
120
|
+
* Add or replace the sap-client url parameter if missing or inocrrect in the original request path.
|
|
121
|
+
*
|
|
122
|
+
* @param client sap-client as string
|
|
123
|
+
* @returns a path rewrite function
|
|
124
|
+
*/
|
|
125
|
+
replaceClient(client) {
|
|
126
|
+
const sapClient = 'sap-client=' + client;
|
|
127
|
+
return (path) => {
|
|
128
|
+
if (path.match(/sap-client=\d{3}/)) {
|
|
129
|
+
return path.replace(/sap-client=\d{3}/, sapClient);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
return path.indexOf('?') !== -1 ? path + '&' + sapClient : path + '?' + sapClient;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
/**
|
|
137
|
+
* Create a chain of rewrite function calls based on the provided configuration.
|
|
138
|
+
*
|
|
139
|
+
* @param config backend configuration
|
|
140
|
+
* @param log logger instance
|
|
141
|
+
* @returns a path rewrite function
|
|
142
|
+
*/
|
|
143
|
+
getPathRewrite(config, log) {
|
|
144
|
+
const functions = [];
|
|
145
|
+
if (config.pathReplace) {
|
|
146
|
+
functions.push(exports.PathRewriters.replacePrefix(config.path, config.pathReplace));
|
|
147
|
+
}
|
|
148
|
+
if (config.client) {
|
|
149
|
+
functions.push(exports.PathRewriters.replaceClient(config.client));
|
|
150
|
+
}
|
|
151
|
+
if (functions.length > 0) {
|
|
152
|
+
return (path) => {
|
|
153
|
+
let newPath = path;
|
|
154
|
+
functions.forEach((func) => (newPath = func(newPath)));
|
|
155
|
+
if (newPath !== path) {
|
|
156
|
+
log.info(`Rewrite path ${path} > ${newPath}`);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
log.info(path);
|
|
160
|
+
}
|
|
161
|
+
return newPath;
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Initialize i18next with the translations for this module.
|
|
171
|
+
*/
|
|
172
|
+
function initI18n() {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
const ns = 'backend-proxy-middleware';
|
|
175
|
+
yield i18next_1.default.init({
|
|
176
|
+
resources: {
|
|
177
|
+
en: {
|
|
178
|
+
[ns]: i18n_json_1.default
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
lng: 'en',
|
|
182
|
+
fallbackLng: 'en',
|
|
183
|
+
defaultNS: ns,
|
|
184
|
+
ns: [ns]
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
exports.initI18n = initI18n;
|
|
189
|
+
/**
|
|
190
|
+
* Enhance the proxy options and backend configurations for the usage of destinations in SAP Business Application Studio.
|
|
191
|
+
*
|
|
192
|
+
* @param proxyOptions reference to a proxy options object that the function will enhance
|
|
193
|
+
* @param backend reference to the backend configuration that the the function may enhance
|
|
194
|
+
*/
|
|
195
|
+
function enhanceConfigsForDestination(proxyOptions, backend) {
|
|
196
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
197
|
+
proxyOptions.target = btp_utils_1.getDestinationUrlForAppStudio(backend.destination);
|
|
198
|
+
if (backend.destinationInstance) {
|
|
199
|
+
proxyOptions.headers[btp_utils_1.BAS_DEST_INSTANCE_CRED_HEADER] = yield btp_utils_1.getCredentialsForDestinationService(backend.destinationInstance);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
const destinations = yield btp_utils_1.listDestinations();
|
|
203
|
+
const destination = destinations[backend.destination];
|
|
204
|
+
if (destination) {
|
|
205
|
+
// in case of a full url destination remove the path defined in the destination from the forwarded call
|
|
206
|
+
if (btp_utils_1.isFullUrlDestination(destination)) {
|
|
207
|
+
const destPath = new URL(destination.Host).pathname.replace(/\/$/, '');
|
|
208
|
+
if (backend.path.startsWith(destPath) && !backend.pathReplace) {
|
|
209
|
+
backend.pathReplace = backend.path.replace(destPath, '');
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
throw new Error();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
exports.enhanceConfigsForDestination = enhanceConfigsForDestination;
|
|
220
|
+
/**
|
|
221
|
+
* Enhance the proxy options with information read from the store.
|
|
222
|
+
*
|
|
223
|
+
* @param proxyOptions reference to a proxy options object that the function will enhance
|
|
224
|
+
* @param system backend system information (most likely) read from the store
|
|
225
|
+
* @param oAuthRequired if true then the OAuth flow is triggered to get cookies
|
|
226
|
+
* @param tokenChangedCallback function to call if a new refreshToken is available
|
|
227
|
+
*/
|
|
228
|
+
function enhanceConfigForSystem(proxyOptions, system, oAuthRequired, tokenChangedCallback) {
|
|
229
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
230
|
+
if (oAuthRequired) {
|
|
231
|
+
if (system.serviceKeys) {
|
|
232
|
+
const provider = axios_extension_1.createForAbapOnBtp(JSON.parse(system.serviceKeys), system.refreshToken, tokenChangedCallback);
|
|
233
|
+
// sending a request to the backend to get cookies
|
|
234
|
+
yield provider.getAtoInfo();
|
|
235
|
+
proxyOptions.headers['cookie'] = provider.cookies.toString();
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
throw new Error('Cannot connect to ABAP Environment on BTP without service keys.');
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
else if (system.authenticationType === store_1.AuthenticationType.ReentranceTicket) {
|
|
242
|
+
throw new Error('Feature comes with https://github.com/SAP/open-ux-tools/pull/485');
|
|
243
|
+
/*
|
|
244
|
+
const provider = createForAbapOnBtp(
|
|
245
|
+
...
|
|
246
|
+
);
|
|
247
|
+
// sending a request to the backend to get cookies
|
|
248
|
+
await provider.getAtoInfo();
|
|
249
|
+
proxyOptions.headers['cookie'] = provider.cookies.toString();
|
|
250
|
+
*/
|
|
251
|
+
}
|
|
252
|
+
else if ((system.username || process.env.FIORI_TOOLS_USER) &&
|
|
253
|
+
(system.password || process.env.FIORI_TOOLS_PASSWORD)) {
|
|
254
|
+
proxyOptions.auth = `${system.username || process.env.FIORI_TOOLS_USER}:${system.password || process.env.FIORI_TOOLS_PASSWORD}`;
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
exports.enhanceConfigForSystem = enhanceConfigForSystem;
|
|
259
|
+
/**
|
|
260
|
+
* Generate options for the proxy middleware based on the input.
|
|
261
|
+
*
|
|
262
|
+
* @param backend backend system specific configuration
|
|
263
|
+
* @param options optional base options for the http-proxy-middleware
|
|
264
|
+
* @param logger optional logger instance
|
|
265
|
+
* @returns options for the http-proxy-middleware
|
|
266
|
+
*/
|
|
267
|
+
function generateProxyMiddlewareOptions(backend, options = {}, logger = new logger_1.ToolsLogger()) {
|
|
268
|
+
var _a;
|
|
269
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
270
|
+
// add required options
|
|
271
|
+
const proxyOptions = Object.assign(Object.assign({ headers: {} }, exports.ProxyEventHandlers), options);
|
|
272
|
+
proxyOptions.changeOrigin = true;
|
|
273
|
+
proxyOptions.logProvider = () => logger;
|
|
274
|
+
// overwrite url if running in AppStudio
|
|
275
|
+
if (btp_utils_1.isAppStudio()) {
|
|
276
|
+
const destBackend = backend;
|
|
277
|
+
destBackend.destination = (_a = destBackend.destination) !== null && _a !== void 0 ? _a : process.env.FIORI_TOOLS_DESTINATION;
|
|
278
|
+
if (destBackend.destination) {
|
|
279
|
+
yield enhanceConfigsForDestination(proxyOptions, destBackend);
|
|
280
|
+
logger.info('Using destination: ' + destBackend.destination);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
const localBackend = backend;
|
|
285
|
+
proxyOptions.target = localBackend.url;
|
|
286
|
+
// check if system credentials are stored in the store
|
|
287
|
+
const systemStore = yield store_1.getService({ logger, entityName: 'system' });
|
|
288
|
+
const system = yield systemStore.read(new store_1.BackendSystemKey({ url: localBackend.url, client: localBackend.client }));
|
|
289
|
+
if (system) {
|
|
290
|
+
yield enhanceConfigForSystem(proxyOptions, system, backend.scp, (refreshToken) => {
|
|
291
|
+
if (refreshToken) {
|
|
292
|
+
logger.info('Updating refresh token for: ' + localBackend.url);
|
|
293
|
+
systemStore.write(Object.assign(Object.assign({}, system), { refreshToken }));
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
proxyOptions.pathRewrite = exports.PathRewriters.getPathRewrite(backend, logger);
|
|
299
|
+
if (backend.apiHub) {
|
|
300
|
+
const apiHubKey = yield getApiHubKey(logger);
|
|
301
|
+
if (apiHubKey) {
|
|
302
|
+
proxyOptions.headers['apikey'] = apiHubKey;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
backend.proxy = config_1.getCorporateProxyServer(backend.proxy);
|
|
306
|
+
if (backend.proxy && !config_1.isHostExcludedFromProxy(proxyOptions.target)) {
|
|
307
|
+
proxyOptions.agent = new https_proxy_agent_1.HttpsProxyAgent(backend.proxy);
|
|
308
|
+
}
|
|
309
|
+
logger.info(`Backend proxy created for ${proxyOptions.target ? proxyOptions.target : ''} ${backend.path ? backend.path : ''}`);
|
|
310
|
+
return proxyOptions;
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
exports.generateProxyMiddlewareOptions = generateProxyMiddlewareOptions;
|
|
314
|
+
/**
|
|
315
|
+
* Generate an instance of the proxy middleware based on the input.
|
|
316
|
+
*
|
|
317
|
+
* @param backend backend system specific configuration
|
|
318
|
+
* @param options optional base options for the http-proxy-middleware
|
|
319
|
+
* @param logger optional logger instance
|
|
320
|
+
* @returns an instance of http-proxy-middleware
|
|
321
|
+
*/
|
|
322
|
+
function createProxy(backend, options, logger) {
|
|
323
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
324
|
+
return http_proxy_middleware_1.createProxyMiddleware(yield generateProxyMiddlewareOptions(backend, options, logger));
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
exports.createProxy = createProxy;
|
|
328
|
+
//# sourceMappingURL=proxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../src/base/proxy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,yDAAoD;AAGpD,iEAA8D;AAC9D,sDAA2B;AAG3B,2CAA6C;AAC7C,6DAA6D;AAC7D,iDAO2B;AAE3B,4DAAuC;AAGvC,yCAAiF;AACjF,qCAA4E;AAG5E;;GAEG;AACU,QAAA,kBAAkB,GAAG;IAC9B;;;;;;;OAOG;IACH,UAAU,CAAC,QAAuB,EAAE,IAAsB,EAAE,IAAqB,EAAE,QAAwB;QACvG,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC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CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;SAC3D;QAED,MAAM,CAAC,IAAI,CACP,6BAA6B,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IACvE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAClC,EAAE,CACL,CAAC;QACF,OAAO,YAAY,CAAC;;CACvB;AA5DD,wEA4DC;AAED;;;;;;;GAOG;AACH,SAAsB,WAAW,CAAC,OAAsB,EAAE,OAAiB,EAAE,MAAe;;QACxF,OAAO,6CAAqB,CAAC,MAAM,8BAA8B,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;IACjG,CAAC;CAAA;AAFD,kCAEC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Options } from 'http-proxy-middleware';
|
|
2
|
+
export interface BaseBackendConfig {
|
|
3
|
+
/**
|
|
4
|
+
* Path that is to be proxied
|
|
5
|
+
*/
|
|
6
|
+
path: string;
|
|
7
|
+
/**
|
|
8
|
+
* If provided then the path will be replaced with this value before forwarding.
|
|
9
|
+
*/
|
|
10
|
+
pathReplace?: string;
|
|
11
|
+
/**
|
|
12
|
+
* sap-client parameter
|
|
13
|
+
*/
|
|
14
|
+
client?: string;
|
|
15
|
+
/**
|
|
16
|
+
* If set to true the proxy will execute the required OAuth routine for the ABAP environment on SAP BTP
|
|
17
|
+
*/
|
|
18
|
+
scp?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* If set to true then the proxy will connect to the SAP API Business Hub
|
|
21
|
+
*/
|
|
22
|
+
apiHub?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* If set then it will override the proxy settings from node.
|
|
25
|
+
*/
|
|
26
|
+
proxy?: string;
|
|
27
|
+
/**
|
|
28
|
+
* The BSP property for the FLP Embedded Flow. The property refers to the BSP Application Name.
|
|
29
|
+
* In that case, we need to redirect the manifest.appdescr request to the local manifest.json in order to overwrite the deployed application with the local one.
|
|
30
|
+
*/
|
|
31
|
+
bsp?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface DestinationBackendConfig extends BaseBackendConfig {
|
|
34
|
+
/**
|
|
35
|
+
* Required if the backend system is available as destination in SAP Business Application Studio.
|
|
36
|
+
*/
|
|
37
|
+
destination: string;
|
|
38
|
+
/**
|
|
39
|
+
* If a destination needs to be read by a specific instance of a destination service then you need to provide the id of the service as optional property `destinationInstance`.
|
|
40
|
+
*/
|
|
41
|
+
destinationInstance?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface LocalBackendConfig extends BaseBackendConfig {
|
|
44
|
+
/**
|
|
45
|
+
* Mandatory URL pointing to the backend system
|
|
46
|
+
*/
|
|
47
|
+
url: string;
|
|
48
|
+
}
|
|
49
|
+
export declare type BackendConfig = LocalBackendConfig | DestinationBackendConfig;
|
|
50
|
+
export interface BackendMiddlewareConfig {
|
|
51
|
+
backend: BackendConfig;
|
|
52
|
+
options?: Partial<Options>;
|
|
53
|
+
}
|
|
54
|
+
export interface MiddlewareParameters<T> {
|
|
55
|
+
resources: object;
|
|
56
|
+
options: {
|
|
57
|
+
configuration: T;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/base/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,MAAM,WAAW,iBAAiB;IAC9B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;IACd;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,wBAAyB,SAAQ,iBAAiB;IAC/D;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB;IACzD;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;CACf;AAED,oBAAY,aAAa,GAAG,kBAAkB,GAAG,wBAAwB,CAAC;AAE1E,MAAM,WAAW,uBAAuB;IACpC,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;CAC9B;AAED,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE;QACL,aAAa,EAAE,CAAC,CAAC;KACpB,CAAC;CACL"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/base/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Options } from 'http-proxy-middleware';
|
|
2
|
+
import type { Logger } from '@sap-ux/logger';
|
|
3
|
+
/**
|
|
4
|
+
* Replace calls to manifest.appdescr file if we are running the FLP embedded flow.
|
|
5
|
+
*
|
|
6
|
+
* @param bsp path of the BSP page
|
|
7
|
+
* @returns a path rewrite function
|
|
8
|
+
*/
|
|
9
|
+
export declare function convertAppDescriptorToManifest(bsp: string): (path: string) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Prompts the user for credentials.
|
|
12
|
+
*
|
|
13
|
+
* @param log logger to report info to the user
|
|
14
|
+
* @returns prompted user and password serialized for a basic auth header
|
|
15
|
+
*/
|
|
16
|
+
export declare function promptUserPass(log: Logger): Promise<string | undefined>;
|
|
17
|
+
/**
|
|
18
|
+
* Add additional options required for the special use case embedded FLP.
|
|
19
|
+
*
|
|
20
|
+
* @param bspPath path of the BSP hosting the app
|
|
21
|
+
* @param proxyOptions existing http-proxy-middleware options
|
|
22
|
+
* @param logger logger to report info to the user
|
|
23
|
+
*/
|
|
24
|
+
export declare function addOptionsForEmbeddedBSP(bspPath: string, proxyOptions: Options, logger: Logger): Promise<void>;
|
|
25
|
+
//# sourceMappingURL=bsp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bsp.d.ts","sourceRoot":"","sources":["../../src/ext/bsp.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAGrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAG7C;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAGpF;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAoD7E;AAED;;;;;;GAMG;AACH,wBAAsB,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAqBpG"}
|
package/dist/ext/bsp.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.addOptionsForEmbeddedBSP = exports.promptUserPass = exports.convertAppDescriptorToManifest = void 0;
|
|
16
|
+
const chalk_1 = require("chalk");
|
|
17
|
+
const i18next_1 = __importDefault(require("i18next"));
|
|
18
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
19
|
+
const btp_utils_1 = require("@sap-ux/btp-utils");
|
|
20
|
+
/**
|
|
21
|
+
* Replace calls to manifest.appdescr file if we are running the FLP embedded flow.
|
|
22
|
+
*
|
|
23
|
+
* @param bsp path of the BSP page
|
|
24
|
+
* @returns a path rewrite function
|
|
25
|
+
*/
|
|
26
|
+
function convertAppDescriptorToManifest(bsp) {
|
|
27
|
+
const regex = new RegExp('(' + bsp + '/manifest\\.appdescr\\b)');
|
|
28
|
+
return (path) => (path.match(regex) ? '/manifest.json' : path);
|
|
29
|
+
}
|
|
30
|
+
exports.convertAppDescriptorToManifest = convertAppDescriptorToManifest;
|
|
31
|
+
/**
|
|
32
|
+
* Prompts the user for credentials.
|
|
33
|
+
*
|
|
34
|
+
* @param log logger to report info to the user
|
|
35
|
+
* @returns prompted user and password serialized for a basic auth header
|
|
36
|
+
*/
|
|
37
|
+
function promptUserPass(log) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
if (btp_utils_1.isAppStudio()) {
|
|
40
|
+
const { authNeeded } = yield prompts_1.default([
|
|
41
|
+
{
|
|
42
|
+
type: 'confirm',
|
|
43
|
+
name: 'authNeeded',
|
|
44
|
+
message: `${chalk_1.cyan(i18next_1.default.t('info.authNeeded'))}\n\n`
|
|
45
|
+
}
|
|
46
|
+
]);
|
|
47
|
+
if (!authNeeded) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
log.info(chalk_1.yellow(i18next_1.default.t('info.credentialsRequiredForFLP')));
|
|
53
|
+
}
|
|
54
|
+
const { username, password } = yield prompts_1.default([
|
|
55
|
+
{
|
|
56
|
+
type: 'text',
|
|
57
|
+
name: 'username',
|
|
58
|
+
message: `${chalk_1.cyan(i18next_1.default.t('info.username'))}\n\n`,
|
|
59
|
+
validate: (value) => {
|
|
60
|
+
if (!value || !value.trim()) {
|
|
61
|
+
return `${i18next_1.default.t('error.emptyUsername')}`;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
type: 'password',
|
|
70
|
+
name: 'password',
|
|
71
|
+
message: `${chalk_1.cyan(i18next_1.default.t('info.password'))}\n\n`,
|
|
72
|
+
validate: (value) => {
|
|
73
|
+
if (!value || !value.trim()) {
|
|
74
|
+
return `${i18next_1.default.t('error.emptyPassword')}`;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
], {
|
|
82
|
+
onCancel: () => {
|
|
83
|
+
log.info(chalk_1.yellow(i18next_1.default.t('info.operationAborted')));
|
|
84
|
+
return process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
return `${username}:${password}`;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
exports.promptUserPass = promptUserPass;
|
|
91
|
+
/**
|
|
92
|
+
* Add additional options required for the special use case embedded FLP.
|
|
93
|
+
*
|
|
94
|
+
* @param bspPath path of the BSP hosting the app
|
|
95
|
+
* @param proxyOptions existing http-proxy-middleware options
|
|
96
|
+
* @param logger logger to report info to the user
|
|
97
|
+
*/
|
|
98
|
+
function addOptionsForEmbeddedBSP(bspPath, proxyOptions, logger) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
const regex = new RegExp('(' + bspPath + '/manifest\\.appdescr\\b)');
|
|
101
|
+
proxyOptions.router = (req) => {
|
|
102
|
+
// redirects the request for manifest.appdescr to localhost
|
|
103
|
+
if (req.path.match(regex)) {
|
|
104
|
+
return req.protocol + '://' + req.headers.host;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
if (proxyOptions.pathRewrite) {
|
|
111
|
+
const oldRewrite = proxyOptions.pathRewrite;
|
|
112
|
+
const appDescrRewrite = convertAppDescriptorToManifest(bspPath);
|
|
113
|
+
proxyOptions.pathRewrite = (path) => appDescrRewrite(oldRewrite(path));
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
proxyOptions.pathRewrite = convertAppDescriptorToManifest(bspPath);
|
|
117
|
+
}
|
|
118
|
+
if (!proxyOptions.auth) {
|
|
119
|
+
proxyOptions.auth = yield promptUserPass(logger);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
exports.addOptionsForEmbeddedBSP = addOptionsForEmbeddedBSP;
|
|
124
|
+
//# sourceMappingURL=bsp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bsp.js","sourceRoot":"","sources":["../../src/ext/bsp.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iCAAqC;AAErC,sDAA2B;AAC3B,sDAA8B;AAE9B,iDAAgD;AAEhD;;;;;GAKG;AACH,SAAgB,8BAA8B,CAAC,GAAW;IACtD,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,GAAG,GAAG,GAAG,GAAG,0BAA0B,CAAC,CAAC;IACjE,OAAO,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,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AAO,CAAC,CAAC;SACtE;QAED,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE;YACpB,YAAY,CAAC,IAAI,GAAG,MAAM,cAAc,CAAC,MAAM,CAAC,CAAC;SACpD;IACL,CAAC;CAAA;AArBD,4DAqBC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,WAAW,EAAY,MAAM,cAAc,CAAC;AAErF,OAAO,EAAE,8BAA8B,EAAE,WAAW,EAAE,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createProxy = exports.generateProxyMiddlewareOptions = void 0;
|
|
4
|
+
const proxy_1 = require("./base/proxy");
|
|
5
|
+
Object.defineProperty(exports, "generateProxyMiddlewareOptions", { enumerable: true, get: function () { return proxy_1.generateProxyMiddlewareOptions; } });
|
|
6
|
+
Object.defineProperty(exports, "createProxy", { enumerable: true, get: function () { return proxy_1.createProxy; } });
|
|
7
|
+
proxy_1.initI18n();
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,wCAAqF;AAE5E,+GAFA,sCAA8B,OAEA;AAAE,4FAFA,mBAAW,OAEA;AAEpD,gBAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":""}
|