@studyportals/cors 2.6.1 → 2.6.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.
Files changed (47) hide show
  1. package/{bin/index.d.ts → index.d.ts} +2 -2
  2. package/{bin/index.js → index.js} +18 -18
  3. package/package.json +38 -38
  4. package/{bin/src → src}/domain/allowed-domain-reg-ex-list.d.ts +10 -10
  5. package/{bin/src → src}/domain/allowed-domain-reg-ex-list.js +28 -27
  6. package/{bin/src → src}/domain/allowed-explicit-domains-rules.d.ts +42 -42
  7. package/{bin/src → src}/domain/allowed-explicit-domains-rules.js +46 -42
  8. package/{bin/src → src}/domain/cors.d.ts +16 -16
  9. package/{bin/src → src}/domain/cors.js +37 -37
  10. package/{bin/src → src}/domain/enums/environment.d.ts +4 -4
  11. package/{bin/src → src}/domain/enums/environment.js +8 -8
  12. package/{bin/src → src}/domain/enums/index.d.ts +2 -2
  13. package/{bin/src → src}/domain/enums/index.js +18 -18
  14. package/{bin/src → src}/domain/enums/scope.d.ts +4 -4
  15. package/{bin/src → src}/domain/enums/scope.js +8 -8
  16. package/{bin/src → src}/domain/index.d.ts +3 -3
  17. package/{bin/src → src}/domain/index.js +19 -19
  18. package/{bin/src → src}/implementations/express-middleware.d.ts +5 -5
  19. package/{bin/src → src}/implementations/express-middleware.js +27 -27
  20. package/{bin/src → src}/implementations/index.d.ts +3 -3
  21. package/{bin/src → src}/implementations/index.js +19 -19
  22. package/{bin/src → src}/implementations/options.d.ts +8 -8
  23. package/{bin/src → src}/implementations/options.js +49 -49
  24. package/{bin/src → src}/implementations/s3-rules.d.ts +5 -5
  25. package/{bin/src → src}/implementations/s3-rules.js +12 -12
  26. package/.codeclimate.yml +0 -25
  27. package/.github/CODEOWNERS +0 -1
  28. package/.nycrc +0 -22
  29. package/.travis.yml +0 -18
  30. package/README.md +0 -110
  31. package/index.ts +0 -2
  32. package/src/domain/allowed-domain-reg-ex-list.ts +0 -26
  33. package/src/domain/allowed-explicit-domains-rules.ts +0 -56
  34. package/src/domain/cors.ts +0 -32
  35. package/src/domain/enums/environment.ts +0 -4
  36. package/src/domain/enums/index.ts +0 -2
  37. package/src/domain/enums/scope.ts +0 -4
  38. package/src/domain/index.ts +0 -3
  39. package/src/implementations/express-middleware.ts +0 -21
  40. package/src/implementations/index.ts +0 -3
  41. package/src/implementations/options.ts +0 -50
  42. package/src/implementations/s3-rules.ts +0 -12
  43. package/test/domain/cors.s3.test.ts +0 -92
  44. package/test/domain/cors.valid.domain.test.ts +0 -155
  45. package/test/mocha.opts +0 -3
  46. package/tsconfig.json +0 -38
  47. package/tslint.json +0 -132
@@ -1,5 +1,5 @@
1
- import { RequestHandler } from 'express';
2
- import { Environment, Scope } from '../domain/enums';
3
- export declare class ExpressMiddleware {
4
- static getMiddleWare(scope: Scope, environment?: Environment): RequestHandler;
5
- }
1
+ import { RequestHandler } from 'express';
2
+ import { Environment, Scope } from '../domain/enums';
3
+ export declare class ExpressMiddleware {
4
+ static getMiddleWare(scope: Scope, environment?: Environment): RequestHandler;
5
+ }
@@ -1,27 +1,27 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ExpressMiddleware = void 0;
13
- const domain_1 = require("../domain");
14
- const enums_1 = require("../domain/enums");
15
- class ExpressMiddleware {
16
- static getMiddleWare(scope, environment = enums_1.Environment.Production) {
17
- const cors = new domain_1.CORS(scope, environment);
18
- return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
19
- const origin = req.get('origin') || '';
20
- if (yield cors.isValidDomain(origin)) {
21
- res.header('Access-Control-Allow-Origin', origin);
22
- }
23
- next();
24
- });
25
- }
26
- }
27
- exports.ExpressMiddleware = ExpressMiddleware;
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ExpressMiddleware = void 0;
13
+ const domain_1 = require("../domain");
14
+ const enums_1 = require("../domain/enums");
15
+ class ExpressMiddleware {
16
+ static getMiddleWare(scope, environment = enums_1.Environment.Production) {
17
+ const cors = new domain_1.CORS(scope, environment);
18
+ return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
19
+ const origin = req.get('origin') || '';
20
+ if (yield cors.isValidDomain(origin)) {
21
+ res.header('Access-Control-Allow-Origin', origin);
22
+ }
23
+ next();
24
+ });
25
+ }
26
+ }
27
+ exports.ExpressMiddleware = ExpressMiddleware;
@@ -1,3 +1,3 @@
1
- export * from './options';
2
- export * from './express-middleware';
3
- export * from './s3-rules';
1
+ export * from './options';
2
+ export * from './express-middleware';
3
+ export * from './s3-rules';
@@ -1,19 +1,19 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./options"), exports);
18
- __exportStar(require("./express-middleware"), exports);
19
- __exportStar(require("./s3-rules"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./options"), exports);
18
+ __exportStar(require("./express-middleware"), exports);
19
+ __exportStar(require("./s3-rules"), exports);
@@ -1,8 +1,8 @@
1
- import { Environment, Scope } from '../domain/enums';
2
- export declare class OptionsLambda {
3
- private cors;
4
- constructor(scope: Scope, environment?: Environment);
5
- getLowercasedHeaders(event: any): any;
6
- getOrigin(event: any): string;
7
- getHandler(): (event: any) => Promise<any>;
8
- }
1
+ import { Environment, Scope } from '../domain/enums';
2
+ export declare class OptionsLambda {
3
+ private cors;
4
+ constructor(scope: Scope, environment?: Environment);
5
+ getLowercasedHeaders(event: any): any;
6
+ getOrigin(event: any): string;
7
+ getHandler(): (event: any) => Promise<any>;
8
+ }
@@ -1,49 +1,49 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.OptionsLambda = void 0;
13
- const domain_1 = require("../domain");
14
- const enums_1 = require("../domain/enums");
15
- class OptionsLambda {
16
- constructor(scope, environment = enums_1.Environment.Production) {
17
- this.cors = new domain_1.CORS(scope, environment);
18
- }
19
- getLowercasedHeaders(event) {
20
- const headers = {};
21
- Object.keys(event.headers).forEach((key) => {
22
- headers[key.toLowerCase()] = event.headers[key];
23
- });
24
- return headers;
25
- }
26
- getOrigin(event) {
27
- const headers = this.getLowercasedHeaders(event);
28
- return headers['origin'];
29
- }
30
- getHandler() {
31
- return (event) => __awaiter(this, void 0, void 0, function* () {
32
- const origin = this.getOrigin(event);
33
- const headers = {
34
- 'Cache-Control': 'max-age=600, s-maxage=600, proxy-revalidate',
35
- };
36
- if (yield this.cors.isValidDomain(origin)) {
37
- headers['Access-Control-Allow-Origin'] = origin;
38
- headers['Access-Control-Allow-Headers'] = 'authorization, x-api-key, content-type';
39
- headers['Access-Control-Allow-Methods'] = 'GET, POST, DELETE, PATCH, HEAD, PUT, OPTIONS';
40
- headers['Access-Control-Max-Age'] = '600';
41
- }
42
- return {
43
- statusCode: 200,
44
- headers,
45
- };
46
- });
47
- }
48
- }
49
- exports.OptionsLambda = OptionsLambda;
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.OptionsLambda = void 0;
13
+ const domain_1 = require("../domain");
14
+ const enums_1 = require("../domain/enums");
15
+ class OptionsLambda {
16
+ constructor(scope, environment = enums_1.Environment.Production) {
17
+ this.cors = new domain_1.CORS(scope, environment);
18
+ }
19
+ getLowercasedHeaders(event) {
20
+ const headers = {};
21
+ Object.keys(event.headers).forEach((key) => {
22
+ headers[key.toLowerCase()] = event.headers[key];
23
+ });
24
+ return headers;
25
+ }
26
+ getOrigin(event) {
27
+ const headers = this.getLowercasedHeaders(event);
28
+ return headers['origin'];
29
+ }
30
+ getHandler() {
31
+ return (event) => __awaiter(this, void 0, void 0, function* () {
32
+ const origin = this.getOrigin(event);
33
+ const headers = {
34
+ 'Cache-Control': 'max-age=600, s-maxage=600, proxy-revalidate',
35
+ };
36
+ if (yield this.cors.isValidDomain(origin)) {
37
+ headers['Access-Control-Allow-Origin'] = origin;
38
+ headers['Access-Control-Allow-Headers'] = 'authorization, x-api-key, content-type';
39
+ headers['Access-Control-Allow-Methods'] = 'GET, POST, DELETE, PATCH, HEAD, PUT, OPTIONS';
40
+ headers['Access-Control-Max-Age'] = '600';
41
+ }
42
+ return {
43
+ statusCode: 200,
44
+ headers,
45
+ };
46
+ });
47
+ }
48
+ }
49
+ exports.OptionsLambda = OptionsLambda;
@@ -1,5 +1,5 @@
1
- import { CorsRule } from '../domain/allowed-explicit-domains-rules';
2
- import { Environment, Scope } from '../domain/enums';
3
- export declare class S3Rules {
4
- static generate(scope: Scope, environment?: Environment): CorsRule[];
5
- }
1
+ import { CorsRule } from '../domain/allowed-explicit-domains-rules';
2
+ import { Environment, Scope } from '../domain/enums';
3
+ export declare class S3Rules {
4
+ static generate(scope: Scope, environment?: Environment): CorsRule[];
5
+ }
@@ -1,12 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.S3Rules = void 0;
4
- const domain_1 = require("../domain");
5
- const enums_1 = require("../domain/enums");
6
- class S3Rules {
7
- static generate(scope, environment = enums_1.Environment.Production) {
8
- const cors = new domain_1.CORS(scope, environment);
9
- return cors.getS3Rules();
10
- }
11
- }
12
- exports.S3Rules = S3Rules;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.S3Rules = void 0;
4
+ const domain_1 = require("../domain");
5
+ const enums_1 = require("../domain/enums");
6
+ class S3Rules {
7
+ static generate(scope, environment = enums_1.Environment.Production) {
8
+ const cors = new domain_1.CORS(scope, environment);
9
+ return cors.getS3Rules();
10
+ }
11
+ }
12
+ exports.S3Rules = S3Rules;
package/.codeclimate.yml DELETED
@@ -1,25 +0,0 @@
1
- engines:
2
- duplication:
3
- enabled: true
4
- config:
5
- languages:
6
- - ruby:
7
- - javascript:
8
- - php:
9
- - python:
10
- eslint:
11
- enabled: true
12
- # 5.7.0
13
- channel: "eslint-5"
14
- tslint:
15
- enabled: true
16
- # 5.9.1
17
- config: tslint.json
18
- fixme:
19
- enabled: true
20
- ratings:
21
- paths:
22
- - "**.js"
23
- - "**.ts"
24
- exclude_paths:
25
- - "**/node_modules/"
@@ -1 +0,0 @@
1
- * @studyportals/plop @studyportals/samurai-pizza-cats
package/.nycrc DELETED
@@ -1,22 +0,0 @@
1
- {
2
- "include": [
3
- "src/**/*.ts"
4
- ],
5
- "exclude": [
6
- "src/**/*.interface.ts"
7
- ],
8
- "require": [
9
- "ts-node/register"
10
- ],
11
- "extension": [
12
- ".ts"
13
- ],
14
- "reporter": [
15
- "lcov",
16
- "text-summary",
17
- "html"
18
- ],
19
- "sourceMap": true,
20
- "instrument": true,
21
- "all": false
22
- }
package/.travis.yml DELETED
@@ -1,18 +0,0 @@
1
- env:
2
- global:
3
- - CC_TEST_REPORTER_ID=81a49eda82f1c6ca2bcaf8475befb5a95136032496a53d6754f5e657d8c56a48
4
- language: node_js
5
- node_js:
6
- - "8"
7
- cache:
8
- npm: true # this cashes ~/.npm folder on Travis
9
- install:
10
- - npm ci
11
- script:
12
- - npm run test:coverage
13
- before_script:
14
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
15
- - chmod +x ./cc-test-reporter
16
- - ./cc-test-reporter before-build
17
- after_script:
18
- - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
package/README.md DELETED
@@ -1,110 +0,0 @@
1
- ![volkswagen status](https://auchenberg.github.io/volkswagen/volkswargen_ci.svg?v=1)
2
- # CORS
3
-
4
- # Getting Started
5
-
6
- This library can be used to add CORS validation to your API. It can also replace API gateway's implementation of CORS by adding an OPTIONS lambda. This is necessary when you API needs to function for wildcard domains like release candidates.
7
-
8
- ## Installation
9
-
10
- ```bash
11
- npm install @studyportals/cors
12
- ```
13
-
14
- ## Setting up the CORS check in your repo
15
- To use this package in a Lambda the CORS class needs to be constructed outside of the lambda handler. Example:
16
-
17
- ```typescript
18
- import {CORS, Scope, Environment} from '@studyportals/cors'
19
-
20
- const cors = new CORS(Scope.Student, Environment.Production)
21
-
22
- export async function handler(event: any) {
23
- const response = {body: 'someBody', headers: {}};
24
- const origin = event.headers['Origin']; // BEAWARE HEADERS ARE CASE SENSITIVE!!
25
-
26
- if(await cors.isValidDomain(origin)){
27
- response.headers['Access-Control-Allow-Origin'] = origin;
28
- }
29
-
30
- return response;
31
- }
32
-
33
- ```
34
-
35
- Make sure to use the correct `Scope` And `Environment`
36
-
37
- The lambda needs to have access to these buckets. If this bucket is not in your account you need to ask `Samurai Pizza Cats` for access.
38
-
39
- ## Setting up the Options lambda.
40
- To add the OPTIONS lambda you need to make sure all lambda's have CORS disabled. After this you can create a lambda using the following snippet:
41
-
42
- ```typescript
43
- import {OptionsLambda, Scope, Environment} from '@studyportals/cors'
44
-
45
- const optionsLambda = new OptionsLambda(Scope.Student, Environment.Production);
46
- const handler = optionsLambda.getHandler();
47
-
48
- // Lambda hook
49
- export function handler;
50
- ```
51
-
52
- This lambda handler needs to be added to the `serverless.yaml` file. The incoming event needs to be a http event with the path `/{any+}` and method `OPTIONS`
53
-
54
-
55
- ## Express CORS
56
- Express applications can use the `ExpressMiddleware` provided by this package. Example:
57
- ```typescript
58
- import { express } from 'express';
59
- import {ExpressMiddleware, Scope, Environment} from '@studyportals/cors'
60
- const app = express();
61
-
62
- const corsMiddleWare = ExpressMiddleware.getMiddleWare(Scope.Student, Environment.Production);
63
- app.use(corsMiddleWare);
64
- ```
65
-
66
- ## S3 CORS rules
67
- [GoldenEye](https://github.com/studyportals/goldeneye) and other tools that need to generate S3 IAM policies can use the `S3Rules` provided in this package. Example:
68
- ```typescript
69
- import { CorsRule } from "aws-cdk-lib/aws-s3";
70
- import * as cors from "@studyportals/cors";
71
-
72
- generateRules = (scope: cors.Scope, environment: cors.Environment): CorsRule[] => {
73
- return cors.S3Rules.generate(scope, environment) as CorsRule[];
74
- };
75
- ```
76
-
77
-
78
- # Developing the package
79
-
80
- ## Modifying allowed domain list
81
- When modifying the allowed domain list follow the following rules
82
-
83
- 1. When a domain is added or removed for security reasons (Unauthorized access by thirdparty) the major version should be increased. All microservices need to update their version of this package ASAP.
84
-
85
- 2. When a domain is added for feature reasons (Added another micro website) the minor version should be increased. Only affected microservices should be required to update their CORS package ASAP
86
-
87
- ## Compiling
88
- In a terminal, run
89
- ```
90
- tsc
91
- ```
92
-
93
- The output JavaScript can be found in `/bin`.
94
-
95
- ## Testing
96
-
97
- Run `npm test` to execute the unit tests.
98
-
99
- run `npm test:coverage` to run the unit tests as well as generate a coverage report.
100
-
101
- If `test` fails, publishing will not continue.
102
- Consult the terminal to find out why this has happened.
103
-
104
- We have a reference document for writing tests [here](https://github.com/studyportals/SamuraiPizzaCats/blob/master/Testing.md "SamuraiPizzaCats/Testing.md").
105
-
106
- ## Deploying
107
- We publish an npm package, this is done by first committing and pushing the changes. updating the version number, followed by a `npm run deploy` command. This command prepares for deployment and then automatically publishes and pushes to GitHub.
108
-
109
- # House Rules
110
- House Rules are located in the [SamuraiPizzaCats](https://github.com/studyportals/SamuraiPizzaCats) repository.
package/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './src/domain';
2
- export * from './src/implementations';
@@ -1,26 +0,0 @@
1
- import { Environment } from './enums/environment';
2
- import { Scope } from './enums/scope';
3
-
4
- export const AllowedDomainRegExList = {
5
- [Scope.Student]: {
6
- [Environment.Production]: [
7
- /^https?:\/\/(www(?:\.dev)?|cypress\.rc|rc|beta|[0-9]{4,16}(?:-bob)?\.rc)\.mastersportal\.(com|fyi)(?::3030)?$/,
8
- /^https?:\/\/(www(?:\.dev)?|cypress\.rc|rc|beta|[0-9]{4,16}(?:-bob)?\.rc)\.bachelorsportal\.(com|fyi)(?::3030)?$/,
9
- /^https?:\/\/(www(?:\.dev)?|cypress\.rc|rc|beta|[0-9]{4,16}(?:-bob)?\.rc)\.phdportal\.(com|fyi)(?::3030)?$/,
10
- /^https?:\/\/(www(?:\.dev)?|cypress\.rc|rc|beta|[0-9]{4,16}(?:-bob)?\.rc)\.preparationcoursesportal\.(com|fyi)(?::3030)?$/,
11
- /^https?:\/\/(www(?:\.dev)?|cypress\.rc|rc|beta|[0-9]{4,16}(?:-bob)?\.rc)\.distancelearningportal\.(com|fyi)(?::3030)?$/,
12
- /^https?:\/\/(www(?:\.dev)?|cypress\.rc|rc|beta|[0-9]{4,16}(?:-bob)?\.rc)\.shortcoursesportal\.(com|fyi)(?::3030)?$/,
13
- /^https?:\/\/(www.)?admissiontestportal.com?$/,
14
- /^https?:\/\/studentemailing\.prtl\.co$/,
15
- /^https?:\/\/scholarship\.mastersportal\.com$/,
16
- /^https?:\/\/search-page\.prtl\.co$/,
17
- ],
18
- [Environment.Testing]: [
19
- /(.*?)/,
20
- ],
21
- },
22
- [Scope.UniAdmin]: {
23
- [Environment.Production]: [/(.*?)/],
24
- [Environment.Testing]: [/(.*?)/],
25
- },
26
- };
@@ -1,56 +0,0 @@
1
- import { Environment } from "./enums/environment";
2
- import { Scope } from "./enums/scope";
3
-
4
- export type AllowedExplicitDomainsRulesType = typeof AllowedExplicitDomainsRules
5
-
6
- export type CorsRule = {
7
- allowedOrigins: string[],
8
- allowedMethods: string[],
9
- allowedHeaders: string[],
10
- exposedHeaders: string[],
11
- maxAge: number,
12
- }
13
-
14
- export const AllowedExplicitDomainsRules = {
15
- [Scope.Student]: {
16
- [Environment.Production]: {
17
- allowedOrigins: ["*.mastersportal.com","*.bachelorsportal.com","*.shortcoursesportal.com",
18
- "*.distancelearningportal.com","*.preparationcoursesportal.com","*.phdportal.com",
19
- "*.prtl.co","*.rc.mastersportal.fyi","*.rc.bachelorsportal.fyi","*.rc.shortcoursesportal.fyi",
20
- "*.rc.distancelearningportal.fyi","*.rc.preparationcoursesportal.fyi","*.rc.phdportal.fyi",
21
- "*.admissiontestportal.com", "https://admissiontestportal.com"],
22
- allowedHeaders: ["Authorization"],
23
- allowedMethods: ["GET"],
24
- exposedHeaders: [],
25
- maxAge: 3000
26
-
27
- },
28
- [Environment.Testing]: {
29
- allowedOrigins: ["*"],
30
- allowedMethods: ["GET"],
31
- allowedHeaders: ["Authorization"],
32
- exposedHeaders: [],
33
- maxAge: 3000
34
- }
35
- },
36
- [Scope.UniAdmin]: {
37
- [Environment.Production]: {
38
- allowedOrigins: ["*.studyportals.eu"],
39
- allowedHeaders: ["Authorization"],
40
- allowedMethods: ["GET","POST"],
41
- exposedHeaders: [],
42
- maxAge: 3000
43
-
44
- },
45
- [Environment.Testing]: {
46
- allowedOrigins: [ "*-uniadmin.prtl.fyi",
47
- "*.administration.tst.studyportals.eu","administration.tst.studyportals.eu",
48
- "https://administration.dev.studyportals.eu:*",
49
- "*-uniadmin.studyportals.eu"],
50
- allowedMethods: ["GET"],
51
- allowedHeaders: ["*"],
52
- exposedHeaders: [],
53
- maxAge: 3000
54
- }
55
- }
56
- };
@@ -1,32 +0,0 @@
1
- import { AllowedDomainRegExList } from './allowed-domain-reg-ex-list';
2
- import { AllowedExplicitDomainsRules, CorsRule } from './allowed-explicit-domains-rules';
3
- import { Environment } from './enums/environment';
4
- import { Scope } from './enums/scope';
5
-
6
- export class CORS {
7
-
8
- private regExes: RegExp[];
9
- private s3Rules: CorsRule[]
10
-
11
- constructor(scope: Scope, environment: Environment = Environment.Production) {
12
- this.regExes = AllowedDomainRegExList[scope][environment];
13
- this.s3Rules = [ AllowedExplicitDomainsRules[scope][environment] ] ;
14
- }
15
-
16
- /**
17
- * isValidDomain
18
- */
19
- public async isValidDomain(domain: string): Promise<boolean> {
20
- const hasMatch = this.regExes.filter((regex) => domain.match(regex) !== null);
21
- return (hasMatch.length !== 0);
22
-
23
- }
24
-
25
- /**
26
- * getIamRules
27
- */
28
- public getS3Rules(): CorsRule[] {
29
- return this.s3Rules;
30
- }
31
-
32
- }
@@ -1,4 +0,0 @@
1
- export enum Environment {
2
- Production,
3
- Testing,
4
- }
@@ -1,2 +0,0 @@
1
- export * from './environment';
2
- export * from './scope';
@@ -1,4 +0,0 @@
1
- export enum Scope {
2
- Student,
3
- UniAdmin
4
- }
@@ -1,3 +0,0 @@
1
- export * from './cors';
2
- export * from './allowed-domain-reg-ex-list';
3
- export * from './enums';
@@ -1,21 +0,0 @@
1
- import { NextFunction, Request, RequestHandler, Response } from 'express';
2
- import { CORS } from '../domain';
3
- import { Environment, Scope } from '../domain/enums';
4
-
5
- export class ExpressMiddleware {
6
-
7
- public static getMiddleWare(scope: Scope, environment: Environment = Environment.Production): RequestHandler {
8
- const cors = new CORS(scope, environment);
9
-
10
- return async (req: Request, res: Response, next: NextFunction) => {
11
- const origin = req.get('origin') || '';
12
-
13
- if (await cors.isValidDomain(origin)) {
14
- res.header('Access-Control-Allow-Origin', origin);
15
- }
16
-
17
- next();
18
- };
19
-
20
- }
21
- }
@@ -1,3 +0,0 @@
1
- export * from './options';
2
- export * from './express-middleware';
3
- export * from './s3-rules';