@entur-partner/bff 1.1.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/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # Entur partner backend for frontend
2
+
3
+ this package contains utils for microfrontend-bff's
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install @entur-partner/bff
9
+
10
+ # or if you are using Yarn:
11
+ yarn add @entur-partner/bff
12
+ ```
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var proxy = require('express-http-proxy');
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
9
+ var proxy__default = /*#__PURE__*/_interopDefaultLegacy(proxy);
10
+
11
+ var requireOAuth = function requireOAuth(req) {
12
+ return /(^undefined$)|(^Bearer .+$)/gim.test(req.headers.authorization || '');
13
+ };
14
+
15
+ var proxyConfig = function proxyConfig(methods, proxyReqPathResolver) {
16
+ var httpMethods = Array.isArray(methods) ? methods : [methods];
17
+ return {
18
+ filter: function filter(req) {
19
+ return httpMethods.includes(req.method) && requireOAuth(req);
20
+ },
21
+ proxyReqPathResolver: proxyReqPathResolver,
22
+ proxyReqBodyDecorator: function proxyReqBodyDecorator(bodyContent, _srcReq) {
23
+ return bodyContent;
24
+ },
25
+ limit: (process.env.UPLOAD_LIMIT_MB || 200) + "mb"
26
+ };
27
+ };
28
+
29
+ var stripTrailingSlash = function stripTrailingSlash(url) {
30
+ return url.endsWith('/') ? url.substring(0, url.length - 1) : url;
31
+ }; // forwards a call of a specific url / set of methods to a remote server
32
+
33
+
34
+ var forwardingProxy = function forwardingProxy(apiUrl) {
35
+ return function (method, forwardPath) {
36
+ return proxy__default["default"](apiUrl, proxyConfig(method, function () {
37
+ return stripTrailingSlash(new URL(apiUrl).pathname) + forwardPath.apply(void 0, arguments);
38
+ }));
39
+ };
40
+ };
41
+
42
+ exports.forwardingProxy = forwardingProxy;
43
+ exports.proxyConfig = proxyConfig;
44
+ //# sourceMappingURL=bff.cjs.development.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bff.cjs.development.js","sources":["../src/forwardingproxy.ts"],"sourcesContent":["import proxy, { ProxyOptions } from 'express-http-proxy';\nimport { Request } from 'express';\n\nconst requireOAuth = (req: Request) =>\n /(^undefined$)|(^Bearer .+$)/gim.test(req.headers.authorization || '');\n\nexport const proxyConfig = (\n methods: string[],\n proxyReqPathResolver: Required<ProxyOptions>['proxyReqPathResolver']\n): Parameters<typeof proxy>[1] => {\n const httpMethods = Array.isArray(methods) ? methods : [methods];\n\n return {\n filter: (req: Request) =>\n httpMethods.includes(req.method) && requireOAuth(req),\n proxyReqPathResolver,\n proxyReqBodyDecorator: (bodyContent, _srcReq) => bodyContent,\n limit: `${process.env.UPLOAD_LIMIT_MB || 200}mb`,\n };\n};\n\nconst stripTrailingSlash = (url: string) =>\n url.endsWith('/') ? url.substring(0, url.length - 1) : url;\n\n// forwards a call of a specific url / set of methods to a remote server\nexport const forwardingProxy =\n (apiUrl: string) =>\n (method: string[], forwardPath: (...reqs: Request[]) => string) =>\n proxy(\n apiUrl,\n proxyConfig(\n method,\n (...params) =>\n stripTrailingSlash(new URL(apiUrl).pathname) + forwardPath(...params)\n )\n );\n"],"names":["requireOAuth","req","test","headers","authorization","proxyConfig","methods","proxyReqPathResolver","httpMethods","Array","isArray","filter","includes","method","proxyReqBodyDecorator","bodyContent","_srcReq","limit","process","env","UPLOAD_LIMIT_MB","stripTrailingSlash","url","endsWith","substring","length","forwardingProxy","apiUrl","forwardPath","proxy","URL","pathname"],"mappings":";;;;;;;;;;AAGA,IAAMA,YAAY,GAAG,SAAfA,YAAe,CAACC,GAAD,EAAA;AAAA,EACnB,OAAA,gCAAA,CAAiCC,IAAjC,CAAsCD,GAAG,CAACE,OAAJ,CAAYC,aAAZ,IAA6B,EAAnE,CADmB,CAAA;AAAA,CAArB,CAAA;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AAA,CAAA;AAAA,KAFS,CAFR,CADP,CAAA;AAAA,GADA,CAAA;AAAA;;;;;"}
@@ -0,0 +1,2 @@
1
+ "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var r=e(require("express-http-proxy")),t=function(e,r){var t=Array.isArray(e)?e:[e];return{filter:function(e){return t.includes(e.method)&&function(e){return/(^undefined$)|(^Bearer .+$)/gim.test(e.headers.authorization||"")}(e)},proxyReqPathResolver:r,proxyReqBodyDecorator:function(e,r){return e},limit:(process.env.UPLOAD_LIMIT_MB||200)+"mb"}},n=function(e){return e.endsWith("/")?e.substring(0,e.length-1):e};exports.forwardingProxy=function(e){return function(o,u){return r.default(e,t(o,(function(){return n(new URL(e).pathname)+u.apply(void 0,arguments)})))}},exports.proxyConfig=t;
2
+ //# sourceMappingURL=bff.cjs.production.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bff.cjs.production.min.js","sources":["../src/forwardingproxy.ts"],"sourcesContent":["import proxy, { ProxyOptions } from 'express-http-proxy';\nimport { Request } from 'express';\n\nconst requireOAuth = (req: Request) =>\n /(^undefined$)|(^Bearer .+$)/gim.test(req.headers.authorization || '');\n\nexport const proxyConfig = (\n methods: string[],\n proxyReqPathResolver: Required<ProxyOptions>['proxyReqPathResolver']\n): Parameters<typeof proxy>[1] => {\n const httpMethods = Array.isArray(methods) ? methods : [methods];\n\n return {\n filter: (req: Request) =>\n httpMethods.includes(req.method) && requireOAuth(req),\n proxyReqPathResolver,\n proxyReqBodyDecorator: (bodyContent, _srcReq) => bodyContent,\n limit: `${process.env.UPLOAD_LIMIT_MB || 200}mb`,\n };\n};\n\nconst stripTrailingSlash = (url: string) =>\n url.endsWith('/') ? url.substring(0, url.length - 1) : url;\n\n// forwards a call of a specific url / set of methods to a remote server\nexport const forwardingProxy =\n (apiUrl: string) =>\n (method: string[], forwardPath: (...reqs: Request[]) => string) =>\n proxy(\n apiUrl,\n proxyConfig(\n method,\n (...params) =>\n stripTrailingSlash(new URL(apiUrl).pathname) + forwardPath(...params)\n )\n );\n"],"names":["proxyConfig","methods","proxyReqPathResolver","httpMethods","Array","isArray","filter","req","includes","method","test","headers","authorization","requireOAuth","proxyReqBodyDecorator","bodyContent","_srcReq","limit","process","env","UPLOAD_LIMIT_MB","stripTrailingSlash","url","endsWith","substring","length","apiUrl","forwardPath","proxy","URL","pathname","apply","arguments"],"mappings":"mLAMaA,EAAc,SACzBC,EACAC,GAEA,IAAMC,EAAcC,MAAMC,QAAQJ,GAAWA,EAAU,CAACA,GAEjD,MAAA,CACLK,OAAQ,SAACC,GACPJ,OAAAA,EAAYK,SAASD,EAAIE,SAXV,SAACF,GACpB,MAAA,iCAAiCG,KAAKH,EAAII,QAAQC,eAAiB,IAU3BC,CAAaN,IACnDL,qBAAAA,EACAY,sBAAuB,SAACC,EAAaC,GAAd,OAA0BD,GACjDE,OAAUC,QAAQC,IAAIC,iBAAmB,KAApC,OAIHC,EAAqB,SAACC,GAAD,OACzBA,EAAIC,SAAS,KAAOD,EAAIE,UAAU,EAAGF,EAAIG,OAAS,GAAKH,2BAIvD,SAACI,GACD,OAAA,SAACjB,EAAkBkB,GAAnB,OACEC,UACEF,EACA1B,EACES,GACA,WAAA,OACEY,EAAmB,IAAIQ,IAAIH,GAAQI,UAAYH,EAAWI,WAD5D,EAAAC"}
@@ -0,0 +1,35 @@
1
+ import proxy from 'express-http-proxy';
2
+
3
+ var requireOAuth = function requireOAuth(req) {
4
+ return /(^undefined$)|(^Bearer .+$)/gim.test(req.headers.authorization || '');
5
+ };
6
+
7
+ var proxyConfig = function proxyConfig(methods, proxyReqPathResolver) {
8
+ var httpMethods = Array.isArray(methods) ? methods : [methods];
9
+ return {
10
+ filter: function filter(req) {
11
+ return httpMethods.includes(req.method) && requireOAuth(req);
12
+ },
13
+ proxyReqPathResolver: proxyReqPathResolver,
14
+ proxyReqBodyDecorator: function proxyReqBodyDecorator(bodyContent, _srcReq) {
15
+ return bodyContent;
16
+ },
17
+ limit: (process.env.UPLOAD_LIMIT_MB || 200) + "mb"
18
+ };
19
+ };
20
+
21
+ var stripTrailingSlash = function stripTrailingSlash(url) {
22
+ return url.endsWith('/') ? url.substring(0, url.length - 1) : url;
23
+ }; // forwards a call of a specific url / set of methods to a remote server
24
+
25
+
26
+ var forwardingProxy = function forwardingProxy(apiUrl) {
27
+ return function (method, forwardPath) {
28
+ return proxy(apiUrl, proxyConfig(method, function () {
29
+ return stripTrailingSlash(new URL(apiUrl).pathname) + forwardPath.apply(void 0, arguments);
30
+ }));
31
+ };
32
+ };
33
+
34
+ export { forwardingProxy, proxyConfig };
35
+ //# sourceMappingURL=bff.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bff.esm.js","sources":["../src/forwardingproxy.ts"],"sourcesContent":["import proxy, { ProxyOptions } from 'express-http-proxy';\nimport { Request } from 'express';\n\nconst requireOAuth = (req: Request) =>\n /(^undefined$)|(^Bearer .+$)/gim.test(req.headers.authorization || '');\n\nexport const proxyConfig = (\n methods: string[],\n proxyReqPathResolver: Required<ProxyOptions>['proxyReqPathResolver']\n): Parameters<typeof proxy>[1] => {\n const httpMethods = Array.isArray(methods) ? methods : [methods];\n\n return {\n filter: (req: Request) =>\n httpMethods.includes(req.method) && requireOAuth(req),\n proxyReqPathResolver,\n proxyReqBodyDecorator: (bodyContent, _srcReq) => bodyContent,\n limit: `${process.env.UPLOAD_LIMIT_MB || 200}mb`,\n };\n};\n\nconst stripTrailingSlash = (url: string) =>\n url.endsWith('/') ? url.substring(0, url.length - 1) : url;\n\n// forwards a call of a specific url / set of methods to a remote server\nexport const forwardingProxy =\n (apiUrl: string) =>\n (method: string[], forwardPath: (...reqs: Request[]) => string) =>\n proxy(\n apiUrl,\n proxyConfig(\n method,\n (...params) =>\n stripTrailingSlash(new URL(apiUrl).pathname) + forwardPath(...params)\n )\n );\n"],"names":["requireOAuth","req","test","headers","authorization","proxyConfig","methods","proxyReqPathResolver","httpMethods","Array","isArray","filter","includes","method","proxyReqBodyDecorator","bodyContent","_srcReq","limit","process","env","UPLOAD_LIMIT_MB","stripTrailingSlash","url","endsWith","substring","length","forwardingProxy","apiUrl","forwardPath","proxy","URL","pathname"],"mappings":";;AAGA,IAAMA,YAAY,GAAG,SAAfA,YAAe,CAACC,GAAD,EAAA;AAAA,EACnB,OAAA,gCAAA,CAAiCC,IAAjC,CAAsCD,GAAG,CAACE,OAAJ,CAAYC,aAAZ,IAA6B,EAAnE,CADmB,CAAA;AAAA,CAArB,CAAA;;AAGO,IAAMC,WAAW,GAAG,SAAdA,WAAc,CACzBC,OADyB,EAEzBC,oBAFyB,EAGM;AAC/B,EAAA,IAAMC,WAAW,GAAGC,KAAK,CAACC,OAAN,CAAcJ,OAAd,CAAA,GAAyBA,OAAzB,GAAmC,CAACA,OAAD,CAAvD,CAAA;AAEA,EAAO,OAAA;AACLK,IAAAA,MAAM,EAAE,SAAA,MAAA,CAACV,GAAD,EAAA;AAAA,MACNO,OAAAA,WAAW,CAACI,QAAZ,CAAqBX,GAAG,CAACY,MAAzB,CAAoCb,IAAAA,YAAY,CAACC,GAAD,CAD1C,CAAA;AAAA,KADH;AAGLM,IAAAA,oBAAoB,EAApBA,oBAHK;AAILO,IAAAA,qBAAqB,EAAE,SAACC,qBAAAA,CAAAA,WAAD,EAAcC,OAAd,EAAA;AAAA,MAAA,OAA0BD,WAA1B,CAAA;AAAA,KAJlB;AAKLE,IAAAA,KAAK,GAAKC,OAAO,CAACC,GAAR,CAAYC,eAAZ,IAA+B,GAApC,IAAA,IAAA;AALA,GAAP,CAAA;AAOD,EAbM;;AAeP,IAAMC,kBAAkB,GAAG,SAArBA,kBAAqB,CAACC,GAAD,EAAA;AAAA,EAAA,OACzBA,GAAG,CAACC,QAAJ,CAAa,GAAb,CAAA,GAAoBD,GAAG,CAACE,SAAJ,CAAc,CAAd,EAAiBF,GAAG,CAACG,MAAJ,GAAa,CAA9B,CAApB,GAAuDH,GAD9B,CAAA;AAAA,CAA3B;;;IAIaI,eAAe,GAC1B,SADWA,eACX,CAACC,MAAD,EAAA;AAAA,EACA,OAAA,UAACd,MAAD,EAAmBe,WAAnB,EAAA;AAAA,IAAA,OACEC,KAAK,CACHF,MADG,EAEHtB,WAAW,CACTQ,MADS,EAET,YAAA;AAAA,MAAA,OACEQ,kBAAkB,CAAC,IAAIS,GAAJ,CAAQH,MAAR,CAAgBI,CAAAA,QAAjB,CAAlB,GAA+CH,WAAW,CAAA,KAAX,CADjD,KAAA,CAAA,EAAA,SAAA,CAAA,CAAA;AAAA,KAFS,CAFR,CADP,CAAA;AAAA,GADA,CAAA;AAAA;;;;"}
@@ -0,0 +1,5 @@
1
+ /// <reference types="qs" />
2
+ import proxy, { ProxyOptions } from 'express-http-proxy';
3
+ import { Request } from 'express';
4
+ export declare const proxyConfig: (methods: string[], proxyReqPathResolver: Required<ProxyOptions>['proxyReqPathResolver']) => Parameters<typeof proxy>[1];
5
+ export declare const forwardingProxy: (apiUrl: string) => (method: string[], forwardPath: (...reqs: Request[]) => string) => import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
@@ -0,0 +1 @@
1
+ export * from './forwardingproxy';
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+
2
+ 'use strict'
3
+
4
+ if (process.env.NODE_ENV === 'production') {
5
+ module.exports = require('./bff.cjs.production.min.js')
6
+ } else {
7
+ module.exports = require('./bff.cjs.development.js')
8
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@entur-partner/bff",
3
+ "version": "1.1.0",
4
+ "license": "EUPL-1.2",
5
+ "main": "dist/index.js",
6
+ "module": "dist/bff.esm.js",
7
+ "typings": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://bitbucket.org/enturas/entur-partner-packages.git",
14
+ "directory": "packages/bff"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "scripts": {
20
+ "watch": "dts watch --noClean --verbose",
21
+ "build": "dts build",
22
+ "test": "dts test --env=jsdom --passWithNoTests",
23
+ "lint": "dts lint"
24
+ },
25
+ "dependencies": {
26
+ "express-http-proxy": "1.6.3"
27
+ },
28
+ "devDependencies": {
29
+ "@types/express-http-proxy": "1.6.3"
30
+ },
31
+ "jest": {
32
+ "collectCoverageFrom": [
33
+ "<rootDir>/src/**/*.{js,jsx,ts,tsx}"
34
+ ]
35
+ },
36
+ "jestSonar": {
37
+ "reportPath": "reports/jest/",
38
+ "reportFile": "jest-sonar-report.xml",
39
+ "indent": 4
40
+ },
41
+ "gitHead": "1b60c3d704fdb4d30d0a24d5eb68c4334d065ae0"
42
+ }