@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 ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,153 @@
1
+ # `@sap-ux/backend-proxy-middleware`
2
+
3
+ The `@sap-ux/backend-proxy-middleware` is a [Custom UI5 Server Middleware](https://sap.github.io/ui5-tooling/pages/extensibility/CustomServerMiddleware) for proxying requests to backend servers. The middleware is agnostic to running in local environments and SAP Business Application Studio. Additionally, if credentials are maintained with the SAP Fiori tools then these will be used.
4
+
5
+ It can be used either with the `ui5 serve` or the `fiori run` commands.
6
+
7
+ ## Configuration Options
8
+
9
+ ### `backend`
10
+ | Option | Type | Description |
11
+ | ------------- | ------------- | ----------- |
12
+ | `url` | `string` mandatory (local) | Mandatory URL pointing to the backend system. *Not required if destination is provided and the proxy is running SAP Business Application Studio |
13
+ | `destination` | `string` mandatory (if no url) | Required if the backend system is available as destination in SAP Business Application Studio. |
14
+ | `destinationInstance` | `string` optional | 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`.|
15
+ | `path` | `string` mandatory | Path that is to be proxied |
16
+ | `pathReplace` | `string` optional | If provided then the path will be replaced with this value before forwarding |
17
+ | `client` | `string` optional | sap-client parameter |
18
+ | `scp` | `boolean` optional | If set to true the proxy will execute the required OAuth routine for the ABAP environment on SAP BTP |
19
+ | `apiHub` | `boolean` optional | If set to true then the proxy will connect to the SAP API Business Hub
20
+ | `proxy` | `string` optional | If set then it will override the proxy settings from node.
21
+
22
+ Additional optional experimental property `bsp` (type `string`): The BSP property is only needed for the FLP Embedded Flow. The property refers to the BSP Application Name. 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.
23
+
24
+ ### `options`
25
+ Optional object that can be used to directly set options of the used `http-proxy-middleware` modules (https://www.npmjs.com/package/http-proxy-middleware#http-proxy-middleware-options). Note: only declarative options (i.e. no functions) are supported.
26
+
27
+ ## Configuration Examples
28
+
29
+ ### [Connecting to a backend system](#connecting-to-a-backend-system)
30
+
31
+ Executing `ui5 serve` in your project with the configuration below in the `ui5.yaml` file would forward any request starting with the `path` parameter to the provided backend `url`.
32
+
33
+ ```
34
+ - name: backend-proxy-middleware
35
+ afterMiddleware: compression
36
+ configuration:
37
+ backend:
38
+ path: /sap
39
+ url: https://my.backend.example:1234
40
+ ```
41
+
42
+ ### [Connecting to a backend system with destination](#connecting-to-a-backend-system-with-destination)
43
+
44
+ If working in SAP Business Application Studio and the backend is configured as destination then you can also provide the `destination` in the configuration.
45
+ 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`.
46
+
47
+ ```
48
+ - name: backend-proxy-middleware
49
+ afterMiddleware: compression
50
+ configuration:
51
+ backend:
52
+ path: /sap
53
+ destination: my_example_destination
54
+ ```
55
+
56
+ ### [Connecting to a backend system with destination and principal propagation](#connecting-to-a-backend-system-with-destination-and-principal-propagation)
57
+
58
+ If the backend destination is configured to use principal propagation, then in some cases the requests might fail. If this occurs then you will need to set the optional property `xfwd` to `true`. This will add the x-forwared headers to the proxy requests.
59
+
60
+ ```
61
+ - name: backend-proxy-middleware
62
+ afterMiddleware: compression
63
+ configuration:
64
+ backend:
65
+ path: /sap
66
+ destination: my_example_destination
67
+ options:
68
+ xfwd: true
69
+ ```
70
+
71
+ ### [Connecting to the SAP Business Technology Platform](#connecting-to-the-sap-business-technology-platform)
72
+ If you want to connect to an ABAP Environment on SAP Business Technology Platform then you will need to set the optional property `scp` to `true`. For any other target, remove this property or set it to `false`.
73
+
74
+ ```
75
+ - name: backend-proxy-middleware
76
+ afterMiddleware: compression
77
+ configuration:
78
+ backend:
79
+ path: /sap
80
+ url: https://my.steampunk.example:1234
81
+ scp: true
82
+ ```
83
+
84
+ ### [Connecting to the SAP API Business Hub](#connecting-to-the-sap-api-business-hub)
85
+ If you want to connect to the SAP API Business Hub then you will need to set the optional property `apiHub` to `true`, and set the corresponding `path` and `url`, e.g.
86
+
87
+ ```
88
+ - name: backend-proxy-middleware
89
+ afterMiddleware: compression
90
+ configuration:
91
+ backend:
92
+ path: /s4hanacloud
93
+ url: https://api.sap.com
94
+ apiHub: true
95
+ ```
96
+
97
+ ### [Proxying WebSockets](#proxying-websockets)
98
+ If you want the proxy to handle also WebSockets, then you need to set the optional property `ws` to `true`, e.g.
99
+
100
+ ```
101
+ - name: backend-proxy-middleware
102
+ afterMiddleware: compression
103
+ configuration:
104
+ backend:
105
+ path: /sap
106
+ url: https://my.backend.example:1234
107
+ options:
108
+ ws: true
109
+ ```
110
+
111
+ ### [Changing the path to which a request is proxied](#changing-the-path-to-which-a-request-is-proxied)
112
+ If you want to configure the proxy to send requests from a certain path `/services/odata` to your backend (local url or destination) with a specified entry path `/my/entry/path`. Then you need to do the following:
113
+
114
+ ```
115
+ - name: backend-proxy-middleware
116
+ afterMiddleware: compression
117
+ configuration:
118
+ backend:
119
+ - path: /services/odata
120
+ pathReplace: /my/entry/path
121
+ url: https://my.backend.example:1234
122
+ destination: my_example_destination
123
+ ```
124
+
125
+ ### [Providing Proxy Configuration](#providing-proxy-configuration)
126
+ By default the `backend-proxy-middleware` will read the proxy configuration from the Node.js environment variables `proxy`, `https-proxy` and `noproxy`. If those variables are not set, then you can also provide the proxy configuration in the `ui5.yaml` file.
127
+ **Please note: if you want to exclude any domains from the proxy then you will need to set the `noproxy` variable, e.g. `npm config set noproxy "sap.com"`**.
128
+
129
+ ```
130
+ - name: backend-proxy-middleware
131
+ afterMiddleware: compression
132
+ configuration:
133
+ proxy: https://myproxy.example:8443
134
+ backend:
135
+ - path: /sap
136
+ url: https://my.backend.example:1234
137
+
138
+ ```
139
+ ## Programmatic Usage
140
+ Alternatively you can only use the underlying proxy function, e.g. for the case when you want to use the `backend-proxy-middleware` functionality in your `express` server.
141
+
142
+ ```Typescript
143
+ import { createProxy } from '@sap-ux/backend-proxy-middleware';
144
+ const proxy = createProxy(backend, options);
145
+ ```
146
+ - **config** - The backend configuration
147
+ - **options** - Options of the [http-proxy-middleware](https://www.npmjs.com/package/http-proxy-middleware#options)
148
+
149
+ ## Keywords
150
+ * Backend Proxy Middleware
151
+ * Fiori tools
152
+ * Fiori elements
153
+ * SAP UI5
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Get the effective proxy string from runtime args (highest priority), given config value or environment variables.
3
+ *
4
+ * @param proxyFromConfig - optional proxy string from configuration
5
+ * @returns proxy server if required, otherwise undefined
6
+ */
7
+ export declare function getCorporateProxyServer(proxyFromConfig?: string): string | undefined;
8
+ /**
9
+ * Checks if a host is excluded from user's corporate proxy.
10
+ *
11
+ * @param url - url to be checked
12
+ * @returns true if host is excluded from user's corporate server, false otherwise
13
+ */
14
+ export declare const isHostExcludedFromProxy: (url: string) => boolean;
15
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/base/config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAkBpF;AAED;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,QAAS,MAAM,KAAG,OAWrD,CAAC"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isHostExcludedFromProxy = exports.getCorporateProxyServer = void 0;
4
+ /**
5
+ * Get the effective proxy string from runtime args (highest priority), given config value or environment variables.
6
+ *
7
+ * @param proxyFromConfig - optional proxy string from configuration
8
+ * @returns proxy server if required, otherwise undefined
9
+ */
10
+ function getCorporateProxyServer(proxyFromConfig) {
11
+ let proxyFromArgs;
12
+ process.argv.forEach((arg) => {
13
+ if (arg.match(/proxy=/g)) {
14
+ proxyFromArgs = arg.split('=')[1];
15
+ }
16
+ });
17
+ return (proxyFromArgs ||
18
+ proxyFromConfig ||
19
+ process.env.FIORI_TOOLS_PROXY ||
20
+ process.env.http_proxy ||
21
+ process.env.HTTP_PROXY ||
22
+ process.env.https_proxy ||
23
+ process.env.HTTPS_PROXY ||
24
+ process.env.npm_config_proxy ||
25
+ process.env.npm_config_https_proxy);
26
+ }
27
+ exports.getCorporateProxyServer = getCorporateProxyServer;
28
+ /**
29
+ * Checks if a host is excluded from user's corporate proxy.
30
+ *
31
+ * @param url - url to be checked
32
+ * @returns true if host is excluded from user's corporate server, false otherwise
33
+ */
34
+ exports.isHostExcludedFromProxy = (url) => {
35
+ const noProxyConfig = process.env.no_proxy || process.env.npm_config_noproxy;
36
+ if (noProxyConfig === '*') {
37
+ return true;
38
+ }
39
+ else {
40
+ const host = new URL(url).host;
41
+ const noProxyList = noProxyConfig ? noProxyConfig.split(',') : [];
42
+ return !!noProxyList.find((entry) => entry.startsWith('.') ? host.endsWith(entry) : host.endsWith(`.${entry}`));
43
+ }
44
+ };
45
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/base/config.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,SAAgB,uBAAuB,CAAC,eAAwB;IAC5D,IAAI,aAAiC,CAAC;IACtC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACzB,IAAI,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE;YACtB,aAAa,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;SACrC;IACL,CAAC,CAAC,CAAC;IACH,OAAO,CACH,aAAa;QACb,eAAe;QACf,OAAO,CAAC,GAAG,CAAC,iBAAiB;QAC7B,OAAO,CAAC,GAAG,CAAC,UAAU;QACtB,OAAO,CAAC,GAAG,CAAC,UAAU;QACtB,OAAO,CAAC,GAAG,CAAC,WAAW;QACvB,OAAO,CAAC,GAAG,CAAC,WAAW;QACvB,OAAO,CAAC,GAAG,CAAC,gBAAgB;QAC5B,OAAO,CAAC,GAAG,CAAC,sBAAsB,CACrC,CAAC;AACN,CAAC;AAlBD,0DAkBC;AAED;;;;;GAKG;AACU,QAAA,uBAAuB,GAAG,CAAC,GAAW,EAAW,EAAE;IAC5D,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;IAC7E,IAAI,aAAa,KAAK,GAAG,EAAE;QACvB,OAAO,IAAI,CAAC;KACf;SAAM;QACH,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;QAC/B,MAAM,WAAW,GAAG,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAClE,OAAO,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAChC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,EAAE,CAAC,CAC5E,CAAC;KACL;AACL,CAAC,CAAC"}
@@ -0,0 +1,14 @@
1
+ {
2
+ "info": {
3
+ "username": "Username",
4
+ "password": "Password",
5
+ "credentialsRequiredForFLP": "The FLP Embedded Preview requires credentials. Please enter your credentials below",
6
+ "authNeeded": "The FLP Embedded Preview might require credentials. Do you want to enter your credentials?",
7
+ "operationAborted": "Operation aborted by the user."
8
+ },
9
+ "error": {
10
+ "emptyUsername": "Username can not be empty.",
11
+ "emptyPassword": "Password can not be empty.",
12
+ "sslProxy": "You are trying to connect to a server with a self signed certificate. Please check (https://help.sap.com/viewer/17d50220bcd848aa854c9c182d65b699/Latest/en-US/4b318bede7eb4021a8be385c46c74045.html) for guidance."
13
+ }
14
+ }
@@ -0,0 +1,114 @@
1
+ /// <reference types="node" />
2
+ import type { ServerOptions } from 'http-proxy';
3
+ import type { RequestHandler, Options } from 'http-proxy-middleware';
4
+ import type { ClientRequest, IncomingMessage, ServerResponse } from 'http';
5
+ import type { Logger } from '@sap-ux/logger';
6
+ import type { BackendConfig, DestinationBackendConfig } from './types';
7
+ import type { BackendSystem } from '@sap-ux/store';
8
+ import type { Url } from 'url';
9
+ /**
10
+ * Collection of custom event handler for the proxy.
11
+ */
12
+ export declare const ProxyEventHandlers: {
13
+ /**
14
+ * Modifies the request to the proxy server if the `FioriLaunchpad.html` is requested to add a required header.
15
+ *
16
+ * @param proxyReq request to the proxy server that can be modified
17
+ * @param _req (not used) original request
18
+ * @param _res (not used)
19
+ * @param _options (not used)
20
+ */
21
+ onProxyReq(proxyReq: ClientRequest, _req?: IncomingMessage | undefined, _res?: ServerResponse | undefined, _options?: ServerOptions | undefined): void;
22
+ /**
23
+ * Retrieve the set-cookie headers from the response and transform secure cookies to insecure ones.
24
+ *
25
+ * @param proxyRes request to the proxy server that can be modified
26
+ * @param _req (not used) original request
27
+ * @param _res (not used)
28
+ */
29
+ onProxyRes(proxyRes: IncomingMessage, _req?: IncomingMessage | undefined, _res?: ServerResponse | undefined): void;
30
+ /**
31
+ * Specifically handling errors due to unsigned certificates.
32
+ *
33
+ * @param err the error thrown when proxying the request or processing the response
34
+ * @param req request causing the error
35
+ * @param _res (not used)
36
+ * @param _target (not used)
37
+ */
38
+ onError(err: Error & {
39
+ code?: string;
40
+ }, req: IncomingMessage & {
41
+ next?: Function;
42
+ }, _res?: ServerResponse | undefined, _target?: string | Partial<Url> | undefined): void;
43
+ };
44
+ /**
45
+ * Collection of path rewrite functions.
46
+ */
47
+ export declare const PathRewriters: {
48
+ /**
49
+ * Generates a rewrite funtion that replace the match string with the prefix in the given string.
50
+ *
51
+ * @param match part of the path that is to be replaced
52
+ * @param prefix new path that is used as replacement
53
+ * @returns a path rewrite function
54
+ */
55
+ replacePrefix(match: string, prefix: string): (path: string) => string;
56
+ /**
57
+ * Add or replace the sap-client url parameter if missing or inocrrect in the original request path.
58
+ *
59
+ * @param client sap-client as string
60
+ * @returns a path rewrite function
61
+ */
62
+ replaceClient(client: string): (path: string) => string;
63
+ /**
64
+ * Create a chain of rewrite function calls based on the provided configuration.
65
+ *
66
+ * @param config backend configuration
67
+ * @param log logger instance
68
+ * @returns a path rewrite function
69
+ */
70
+ getPathRewrite(config: BackendConfig, log: Logger): ((path: string) => string) | undefined;
71
+ };
72
+ /**
73
+ * Initialize i18next with the translations for this module.
74
+ */
75
+ export declare function initI18n(): Promise<void>;
76
+ /**
77
+ * Enhance the proxy options and backend configurations for the usage of destinations in SAP Business Application Studio.
78
+ *
79
+ * @param proxyOptions reference to a proxy options object that the function will enhance
80
+ * @param backend reference to the backend configuration that the the function may enhance
81
+ */
82
+ export declare function enhanceConfigsForDestination(proxyOptions: Options & {
83
+ headers: object;
84
+ }, backend: DestinationBackendConfig): Promise<void>;
85
+ /**
86
+ * Enhance the proxy options with information read from the store.
87
+ *
88
+ * @param proxyOptions reference to a proxy options object that the function will enhance
89
+ * @param system backend system information (most likely) read from the store
90
+ * @param oAuthRequired if true then the OAuth flow is triggered to get cookies
91
+ * @param tokenChangedCallback function to call if a new refreshToken is available
92
+ */
93
+ export declare function enhanceConfigForSystem(proxyOptions: Options & {
94
+ headers: object;
95
+ }, system: BackendSystem, oAuthRequired: boolean | undefined, tokenChangedCallback: (refreshToken?: string) => void): Promise<void>;
96
+ /**
97
+ * Generate options for the proxy middleware based on the input.
98
+ *
99
+ * @param backend backend system specific configuration
100
+ * @param options optional base options for the http-proxy-middleware
101
+ * @param logger optional logger instance
102
+ * @returns options for the http-proxy-middleware
103
+ */
104
+ export declare function generateProxyMiddlewareOptions(backend: BackendConfig, options?: Options, logger?: Logger): Promise<Options>;
105
+ /**
106
+ * Generate an instance of the proxy middleware based on the input.
107
+ *
108
+ * @param backend backend system specific configuration
109
+ * @param options optional base options for the http-proxy-middleware
110
+ * @param logger optional logger instance
111
+ * @returns an instance of http-proxy-middleware
112
+ */
113
+ export declare function createProxy(backend: BackendConfig, options?: Options, logger?: Logger): Promise<RequestHandler>;
114
+ //# sourceMappingURL=proxy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/base/proxy.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAGrE,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAC3E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAW7C,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB,EAAsB,MAAM,SAAS,CAAC;AAG3F,OAAO,KAAK,EAA4D,aAAa,EAAE,MAAM,eAAe,CAAC;AAG7G,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE/B;;GAEG;AACH,eAAO,MAAM,kBAAkB;IAC3B;;;;;;;OAOG;yBACkB,aAAa;IAMlC;;;;;;OAMG;yBACkB,eAAe;IAUpC;;;;;;;OAOG;iBAEM,KAAK,GAAG;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,OACzB,eAAe,GAAG;QAAE,IAAI,CAAC,EAAE,QAAQ,CAAA;KAAE;CAkBjD,CAAC;AAqBF;;GAEG;AACH,eAAO,MAAM,aAAa;IACtB;;;;;;OAMG;yBACkB,MAAM,UAAU,MAAM,UAAU,MAAM,KAAK,MAAM;IAItE;;;;;OAKG;0BACmB,MAAM,UAAU,MAAM,KAAK,MAAM;IAWvD;;;;;;OAMG;2BACoB,aAAa,OAAO,MAAM,WAAW,MAAM,KAAK,MAAM;CAuBhF,CAAC;AAEF;;GAEG;AACH,wBAAsB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAa9C;AAED;;;;;GAKG;AACH,wBAAsB,4BAA4B,CAC9C,YAAY,EAAE,OAAO,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,EAC3C,OAAO,EAAE,wBAAwB,GAClC,OAAO,CAAC,IAAI,CAAC,CAqBf;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CACxC,YAAY,EAAE,OAAO,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,EAC3C,MAAM,EAAE,aAAa,EACrB,aAAa,EAAE,OAAO,GAAG,SAAS,EAClC,oBAAoB,EAAE,CAAC,YAAY,CAAC,EAAE,MAAM,KAAK,IAAI,GACtD,OAAO,CAAC,IAAI,CAAC,CAgCf;AAED;;;;;;;GAOG;AACH,wBAAsB,8BAA8B,CAChD,OAAO,EAAE,aAAa,EACtB,OAAO,GAAE,OAAY,EACrB,MAAM,GAAE,MAA0B,GACnC,OAAO,CAAC,OAAO,CAAC,CAwDlB;AAED;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAErH"}