@studyportals/cors 2.7.0 → 2.8.1-alpha.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/.codeclimate.yml +25 -0
- package/.github/CODEOWNERS +1 -0
- package/.nycrc +22 -0
- package/.travis.yml +18 -0
- package/README.md +110 -0
- package/{index.d.ts → bin/index.d.ts} +2 -2
- package/{index.js → bin/index.js} +18 -18
- package/bin/package.json +38 -0
- package/{src → bin/src}/domain/allowed-domain-reg-ex-list.d.ts +10 -10
- package/{src → bin/src}/domain/allowed-domain-reg-ex-list.js +30 -29
- package/{src → bin/src}/domain/allowed-explicit-domains-rules.d.ts +42 -42
- package/{src → bin/src}/domain/allowed-explicit-domains-rules.js +43 -46
- package/{src → bin/src}/domain/cors.d.ts +16 -16
- package/{src → bin/src}/domain/cors.js +37 -37
- package/{src → bin/src}/domain/enums/environment.d.ts +4 -4
- package/{src → bin/src}/domain/enums/environment.js +8 -8
- package/{src → bin/src}/domain/enums/index.d.ts +2 -2
- package/{src → bin/src}/domain/enums/index.js +18 -18
- package/{src → bin/src}/domain/enums/scope.d.ts +4 -4
- package/{src → bin/src}/domain/enums/scope.js +8 -8
- package/{src → bin/src}/domain/index.d.ts +3 -3
- package/{src → bin/src}/domain/index.js +19 -19
- package/{src → bin/src}/implementations/express-middleware.d.ts +5 -5
- package/{src → bin/src}/implementations/express-middleware.js +27 -27
- package/{src → bin/src}/implementations/index.d.ts +3 -3
- package/{src → bin/src}/implementations/index.js +19 -19
- package/{src → bin/src}/implementations/options.d.ts +8 -8
- package/{src → bin/src}/implementations/options.js +49 -49
- package/{src → bin/src}/implementations/s3-rules.d.ts +5 -5
- package/{src → bin/src}/implementations/s3-rules.js +12 -12
- package/index.ts +2 -0
- package/package.json +38 -38
- package/src/domain/allowed-domain-reg-ex-list.ts +28 -0
- package/src/domain/allowed-explicit-domains-rules.ts +53 -0
- package/src/domain/cors.ts +32 -0
- package/src/domain/enums/environment.ts +4 -0
- package/src/domain/enums/index.ts +2 -0
- package/src/domain/enums/scope.ts +4 -0
- package/src/domain/index.ts +3 -0
- package/src/implementations/express-middleware.ts +21 -0
- package/src/implementations/index.ts +3 -0
- package/src/implementations/options.ts +50 -0
- package/src/implementations/s3-rules.ts +12 -0
- package/test/domain/cors.s3.test.ts +92 -0
- package/test/domain/cors.valid.domain.test.ts +155 -0
- package/test/mocha.opts +3 -0
- package/tsconfig.json +38 -0
- package/tslint.json +132 -0
package/.codeclimate.yml
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
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/"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* @studyportals/plop @studyportals/samurai-pizza-cats
|
package/.nycrc
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
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.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './src/domain';
|
|
2
|
-
export * from './src/implementations';
|
|
1
|
+
export * from './src/domain';
|
|
2
|
+
export * from './src/implementations';
|
|
@@ -1,18 +1,18 @@
|
|
|
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("./src/domain"), exports);
|
|
18
|
-
__exportStar(require("./src/implementations"), 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("./src/domain"), exports);
|
|
18
|
+
__exportStar(require("./src/implementations"), exports);
|
package/bin/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@studyportals/cors",
|
|
3
|
+
"version": "2.8.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "mocha test/**/*.test.ts",
|
|
8
|
+
"test:watch": "mocha -w --reporter min test/**/*.test.ts",
|
|
9
|
+
"deploy-patch": "npm version patch && npm run deploy",
|
|
10
|
+
"deploy-minor": "npm version minor && npm run deploy",
|
|
11
|
+
"deploy-major": "npm version major && npm run deploy",
|
|
12
|
+
"prepare-deployment": "cp package.json bin/package.json",
|
|
13
|
+
"deploy": "npm run build && npm run prepare-deployment && npm publish ./bin",
|
|
14
|
+
"build": "rm -rf bin && tsc && rm -rf bin/test",
|
|
15
|
+
"lint": "tslint 'src/**/*.ts'",
|
|
16
|
+
"lint-fix": "tslint --fix 'src/**/*.ts'",
|
|
17
|
+
"test:coverage": "nyc mocha test/**/*.test.ts"
|
|
18
|
+
},
|
|
19
|
+
"private": false,
|
|
20
|
+
"author": "SP - Samurai Pizza Cats",
|
|
21
|
+
"license": "BSD3",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@types/express": "^4.17.3"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/chai": "^4.1.7",
|
|
27
|
+
"@types/node": "^10.12.15",
|
|
28
|
+
"chai": "^4.2.0",
|
|
29
|
+
"mocha": "^5.2.0",
|
|
30
|
+
"mocha-typescript": "1.1.12",
|
|
31
|
+
"nyc": "^13.3.0",
|
|
32
|
+
"ts-loader": "^2.3.7",
|
|
33
|
+
"ts-node": "^7.0.1",
|
|
34
|
+
"tslint": "^5.11.0",
|
|
35
|
+
"typemoq": "^2.1.0",
|
|
36
|
+
"typescript": "^4.8.4"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export declare const AllowedDomainRegExList: {
|
|
2
|
-
0: {
|
|
3
|
-
0: RegExp[];
|
|
4
|
-
1: RegExp[];
|
|
5
|
-
};
|
|
6
|
-
1: {
|
|
7
|
-
0: RegExp[];
|
|
8
|
-
1: RegExp[];
|
|
9
|
-
};
|
|
10
|
-
};
|
|
1
|
+
export declare const AllowedDomainRegExList: {
|
|
2
|
+
0: {
|
|
3
|
+
0: RegExp[];
|
|
4
|
+
1: RegExp[];
|
|
5
|
+
};
|
|
6
|
+
1: {
|
|
7
|
+
0: RegExp[];
|
|
8
|
+
1: RegExp[];
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AllowedDomainRegExList = void 0;
|
|
4
|
-
const environment_1 = require("./enums/environment");
|
|
5
|
-
const scope_1 = require("./enums/scope");
|
|
6
|
-
exports.AllowedDomainRegExList = {
|
|
7
|
-
[scope_1.Scope.Student]: {
|
|
8
|
-
[environment_1.Environment.Production]: [
|
|
9
|
-
/^https?:\/\/(www(?:\.dev)?|cypress\.rc|rc|beta|[0-9]{4,16}(?:-bob)?\.rc)\.mastersportal\.(com|fyi)(?::3030)?$/,
|
|
10
|
-
/^https?:\/\/(www(?:\.dev)?|cypress\.rc|rc|beta|[0-9]{4,16}(?:-bob)?\.rc)\.bachelorsportal\.(com|fyi)(?::3030)?$/,
|
|
11
|
-
/^https?:\/\/(www(?:\.dev)?|cypress\.rc|rc|beta|[0-9]{4,16}(?:-bob)?\.rc)\.phdportal\.(com|fyi)(?::3030)?$/,
|
|
12
|
-
/^https?:\/\/(www(?:\.dev)?|cypress\.rc|rc|beta|[0-9]{4,16}(?:-bob)?\.rc)\.preparationcoursesportal\.(com|fyi)(?::3030)?$/,
|
|
13
|
-
/^https?:\/\/(www(?:\.dev)?|cypress\.rc|rc|beta|[0-9]{4,16}(?:-bob)?\.rc)\.distancelearningportal\.(com|fyi)(?::3030)?$/,
|
|
14
|
-
/^https?:\/\/(www(?:\.dev)?|cypress\.rc|rc|beta|[0-9]{4,16}(?:-bob)?\.rc)\.shortcoursesportal\.(com|fyi)(?::3030)?$/,
|
|
15
|
-
/^https?:\/\/(www.)?admissiontestportal.com?$/,
|
|
16
|
-
/^https?:\/\/studentemailing\.prtl\.co$/,
|
|
17
|
-
/^https?:\/\/scholarship\.mastersportal\.com$/,
|
|
18
|
-
/^https?:\/\/students\.mastersportal\.com$/,
|
|
19
|
-
/^https?:\/\/search-page\.prtl\.co$/,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
[environment_1.Environment.
|
|
28
|
-
|
|
29
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AllowedDomainRegExList = void 0;
|
|
4
|
+
const environment_1 = require("./enums/environment");
|
|
5
|
+
const scope_1 = require("./enums/scope");
|
|
6
|
+
exports.AllowedDomainRegExList = {
|
|
7
|
+
[scope_1.Scope.Student]: {
|
|
8
|
+
[environment_1.Environment.Production]: [
|
|
9
|
+
/^https?:\/\/(www(?:\.dev)?|cypress\.rc|rc|beta|[0-9]{4,16}(?:-bob)?\.rc)\.mastersportal\.(com|fyi)(?::3030)?$/,
|
|
10
|
+
/^https?:\/\/(www(?:\.dev)?|cypress\.rc|rc|beta|[0-9]{4,16}(?:-bob)?\.rc)\.bachelorsportal\.(com|fyi)(?::3030)?$/,
|
|
11
|
+
/^https?:\/\/(www(?:\.dev)?|cypress\.rc|rc|beta|[0-9]{4,16}(?:-bob)?\.rc)\.phdportal\.(com|fyi)(?::3030)?$/,
|
|
12
|
+
/^https?:\/\/(www(?:\.dev)?|cypress\.rc|rc|beta|[0-9]{4,16}(?:-bob)?\.rc)\.preparationcoursesportal\.(com|fyi)(?::3030)?$/,
|
|
13
|
+
/^https?:\/\/(www(?:\.dev)?|cypress\.rc|rc|beta|[0-9]{4,16}(?:-bob)?\.rc)\.distancelearningportal\.(com|fyi)(?::3030)?$/,
|
|
14
|
+
/^https?:\/\/(www(?:\.dev)?|cypress\.rc|rc|beta|[0-9]{4,16}(?:-bob)?\.rc)\.shortcoursesportal\.(com|fyi)(?::3030)?$/,
|
|
15
|
+
/^https?:\/\/(www.)?admissiontestportal.com?$/,
|
|
16
|
+
/^https?:\/\/studentemailing\.prtl\.co$/,
|
|
17
|
+
/^https?:\/\/scholarship\.mastersportal\.com$/,
|
|
18
|
+
/^https?:\/\/students\.mastersportal\.com$/,
|
|
19
|
+
/^https?:\/\/search-page\.prtl\.co$/,
|
|
20
|
+
/^https?:\/\/reviews\.studyportals\.com$/,
|
|
21
|
+
],
|
|
22
|
+
[environment_1.Environment.Testing]: [
|
|
23
|
+
/(.*?)/,
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
[scope_1.Scope.UniAdmin]: {
|
|
27
|
+
[environment_1.Environment.Production]: [/(.*?)/],
|
|
28
|
+
[environment_1.Environment.Testing]: [/(.*?)/],
|
|
29
|
+
},
|
|
30
|
+
};
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
export declare type AllowedExplicitDomainsRulesType = typeof AllowedExplicitDomainsRules;
|
|
2
|
-
export declare type CorsRule = {
|
|
3
|
-
allowedOrigins: string[];
|
|
4
|
-
allowedMethods: string[];
|
|
5
|
-
allowedHeaders: string[];
|
|
6
|
-
exposedHeaders: string[];
|
|
7
|
-
maxAge: number;
|
|
8
|
-
};
|
|
9
|
-
export declare const AllowedExplicitDomainsRules: {
|
|
10
|
-
0: {
|
|
11
|
-
0: {
|
|
12
|
-
allowedOrigins: string[];
|
|
13
|
-
allowedHeaders: string[];
|
|
14
|
-
allowedMethods: string[];
|
|
15
|
-
exposedHeaders: never[];
|
|
16
|
-
maxAge: number;
|
|
17
|
-
};
|
|
18
|
-
1: {
|
|
19
|
-
allowedOrigins: string[];
|
|
20
|
-
allowedMethods: string[];
|
|
21
|
-
allowedHeaders: string[];
|
|
22
|
-
exposedHeaders: never[];
|
|
23
|
-
maxAge: number;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
1: {
|
|
27
|
-
0: {
|
|
28
|
-
allowedOrigins: string[];
|
|
29
|
-
allowedHeaders: string[];
|
|
30
|
-
allowedMethods: string[];
|
|
31
|
-
exposedHeaders: never[];
|
|
32
|
-
maxAge: number;
|
|
33
|
-
};
|
|
34
|
-
1: {
|
|
35
|
-
allowedOrigins: string[];
|
|
36
|
-
allowedMethods: string[];
|
|
37
|
-
allowedHeaders: string[];
|
|
38
|
-
exposedHeaders: never[];
|
|
39
|
-
maxAge: number;
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
};
|
|
1
|
+
export declare type AllowedExplicitDomainsRulesType = typeof AllowedExplicitDomainsRules;
|
|
2
|
+
export declare type CorsRule = {
|
|
3
|
+
allowedOrigins: string[];
|
|
4
|
+
allowedMethods: string[];
|
|
5
|
+
allowedHeaders: string[];
|
|
6
|
+
exposedHeaders: string[];
|
|
7
|
+
maxAge: number;
|
|
8
|
+
};
|
|
9
|
+
export declare const AllowedExplicitDomainsRules: {
|
|
10
|
+
0: {
|
|
11
|
+
0: {
|
|
12
|
+
allowedOrigins: string[];
|
|
13
|
+
allowedHeaders: string[];
|
|
14
|
+
allowedMethods: string[];
|
|
15
|
+
exposedHeaders: never[];
|
|
16
|
+
maxAge: number;
|
|
17
|
+
};
|
|
18
|
+
1: {
|
|
19
|
+
allowedOrigins: string[];
|
|
20
|
+
allowedMethods: string[];
|
|
21
|
+
allowedHeaders: string[];
|
|
22
|
+
exposedHeaders: never[];
|
|
23
|
+
maxAge: number;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
1: {
|
|
27
|
+
0: {
|
|
28
|
+
allowedOrigins: string[];
|
|
29
|
+
allowedHeaders: string[];
|
|
30
|
+
allowedMethods: string[];
|
|
31
|
+
exposedHeaders: never[];
|
|
32
|
+
maxAge: number;
|
|
33
|
+
};
|
|
34
|
+
1: {
|
|
35
|
+
allowedOrigins: string[];
|
|
36
|
+
allowedMethods: string[];
|
|
37
|
+
allowedHeaders: string[];
|
|
38
|
+
exposedHeaders: never[];
|
|
39
|
+
maxAge: number;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
|
@@ -1,46 +1,43 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AllowedExplicitDomainsRules = void 0;
|
|
4
|
-
const environment_1 = require("./enums/environment");
|
|
5
|
-
const scope_1 = require("./enums/scope");
|
|
6
|
-
exports.AllowedExplicitDomainsRules = {
|
|
7
|
-
[scope_1.Scope.Student]: {
|
|
8
|
-
[environment_1.Environment.Production]: {
|
|
9
|
-
allowedOrigins: ["*.mastersportal.com", "*.bachelorsportal.com", "*.shortcoursesportal.com",
|
|
10
|
-
"*.distancelearningportal.com", "*.preparationcoursesportal.com", "*.phdportal.com",
|
|
11
|
-
"*.prtl.co", "*.rc.mastersportal.fyi", "*.rc.bachelorsportal.fyi", "*.rc.shortcoursesportal.fyi",
|
|
12
|
-
"*.rc.distancelearningportal.fyi", "*.rc.preparationcoursesportal.fyi", "*.rc.phdportal.fyi",
|
|
13
|
-
"*.admissiontestportal.com", "https://admissiontestportal.com"],
|
|
14
|
-
allowedHeaders: ["Authorization"],
|
|
15
|
-
allowedMethods: ["GET"],
|
|
16
|
-
exposedHeaders: [],
|
|
17
|
-
maxAge: 3000
|
|
18
|
-
},
|
|
19
|
-
[environment_1.Environment.Testing]: {
|
|
20
|
-
allowedOrigins: ["*"],
|
|
21
|
-
allowedMethods: ["GET"],
|
|
22
|
-
allowedHeaders: ["Authorization"],
|
|
23
|
-
exposedHeaders: [],
|
|
24
|
-
maxAge: 3000
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
[scope_1.Scope.UniAdmin]: {
|
|
28
|
-
[environment_1.Environment.Production]: {
|
|
29
|
-
allowedOrigins: ["*.studyportals.eu"],
|
|
30
|
-
allowedHeaders: ["Authorization"],
|
|
31
|
-
allowedMethods: ["GET", "POST"],
|
|
32
|
-
exposedHeaders: [],
|
|
33
|
-
maxAge: 3000
|
|
34
|
-
},
|
|
35
|
-
[environment_1.Environment.Testing]: {
|
|
36
|
-
allowedOrigins: ["
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AllowedExplicitDomainsRules = void 0;
|
|
4
|
+
const environment_1 = require("./enums/environment");
|
|
5
|
+
const scope_1 = require("./enums/scope");
|
|
6
|
+
exports.AllowedExplicitDomainsRules = {
|
|
7
|
+
[scope_1.Scope.Student]: {
|
|
8
|
+
[environment_1.Environment.Production]: {
|
|
9
|
+
allowedOrigins: ["*.mastersportal.com", "*.bachelorsportal.com", "*.shortcoursesportal.com",
|
|
10
|
+
"*.distancelearningportal.com", "*.preparationcoursesportal.com", "*.phdportal.com",
|
|
11
|
+
"*.prtl.co", "*.rc.mastersportal.fyi", "*.rc.bachelorsportal.fyi", "*.rc.shortcoursesportal.fyi",
|
|
12
|
+
"*.rc.distancelearningportal.fyi", "*.rc.preparationcoursesportal.fyi", "*.rc.phdportal.fyi",
|
|
13
|
+
"*.admissiontestportal.com", "https://admissiontestportal.com", "*.studyportals.com"],
|
|
14
|
+
allowedHeaders: ["Authorization"],
|
|
15
|
+
allowedMethods: ["GET"],
|
|
16
|
+
exposedHeaders: [],
|
|
17
|
+
maxAge: 3000
|
|
18
|
+
},
|
|
19
|
+
[environment_1.Environment.Testing]: {
|
|
20
|
+
allowedOrigins: ["*"],
|
|
21
|
+
allowedMethods: ["GET"],
|
|
22
|
+
allowedHeaders: ["Authorization"],
|
|
23
|
+
exposedHeaders: [],
|
|
24
|
+
maxAge: 3000
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
[scope_1.Scope.UniAdmin]: {
|
|
28
|
+
[environment_1.Environment.Production]: {
|
|
29
|
+
allowedOrigins: ["*.studyportals.eu"],
|
|
30
|
+
allowedHeaders: ["Authorization"],
|
|
31
|
+
allowedMethods: ["GET", "POST"],
|
|
32
|
+
exposedHeaders: [],
|
|
33
|
+
maxAge: 3000
|
|
34
|
+
},
|
|
35
|
+
[environment_1.Environment.Testing]: {
|
|
36
|
+
allowedOrigins: ["*.studyportals.eu"],
|
|
37
|
+
allowedMethods: ["GET"],
|
|
38
|
+
allowedHeaders: ["*"],
|
|
39
|
+
exposedHeaders: [],
|
|
40
|
+
maxAge: 3000
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { CorsRule } from './allowed-explicit-domains-rules';
|
|
2
|
-
import { Environment } from './enums/environment';
|
|
3
|
-
import { Scope } from './enums/scope';
|
|
4
|
-
export declare class CORS {
|
|
5
|
-
private regExes;
|
|
6
|
-
private s3Rules;
|
|
7
|
-
constructor(scope: Scope, environment?: Environment);
|
|
8
|
-
/**
|
|
9
|
-
* isValidDomain
|
|
10
|
-
*/
|
|
11
|
-
isValidDomain(domain: string): Promise<boolean>;
|
|
12
|
-
/**
|
|
13
|
-
* getIamRules
|
|
14
|
-
*/
|
|
15
|
-
getS3Rules(): CorsRule[];
|
|
16
|
-
}
|
|
1
|
+
import { CorsRule } from './allowed-explicit-domains-rules';
|
|
2
|
+
import { Environment } from './enums/environment';
|
|
3
|
+
import { Scope } from './enums/scope';
|
|
4
|
+
export declare class CORS {
|
|
5
|
+
private regExes;
|
|
6
|
+
private s3Rules;
|
|
7
|
+
constructor(scope: Scope, environment?: Environment);
|
|
8
|
+
/**
|
|
9
|
+
* isValidDomain
|
|
10
|
+
*/
|
|
11
|
+
isValidDomain(domain: string): Promise<boolean>;
|
|
12
|
+
/**
|
|
13
|
+
* getIamRules
|
|
14
|
+
*/
|
|
15
|
+
getS3Rules(): CorsRule[];
|
|
16
|
+
}
|
|
@@ -1,37 +1,37 @@
|
|
|
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.CORS = void 0;
|
|
13
|
-
const allowed_domain_reg_ex_list_1 = require("./allowed-domain-reg-ex-list");
|
|
14
|
-
const allowed_explicit_domains_rules_1 = require("./allowed-explicit-domains-rules");
|
|
15
|
-
const environment_1 = require("./enums/environment");
|
|
16
|
-
class CORS {
|
|
17
|
-
constructor(scope, environment = environment_1.Environment.Production) {
|
|
18
|
-
this.regExes = allowed_domain_reg_ex_list_1.AllowedDomainRegExList[scope][environment];
|
|
19
|
-
this.s3Rules = [allowed_explicit_domains_rules_1.AllowedExplicitDomainsRules[scope][environment]];
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* isValidDomain
|
|
23
|
-
*/
|
|
24
|
-
isValidDomain(domain) {
|
|
25
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
const hasMatch = this.regExes.filter((regex) => domain.match(regex) !== null);
|
|
27
|
-
return (hasMatch.length !== 0);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* getIamRules
|
|
32
|
-
*/
|
|
33
|
-
getS3Rules() {
|
|
34
|
-
return this.s3Rules;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.CORS = CORS;
|
|
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.CORS = void 0;
|
|
13
|
+
const allowed_domain_reg_ex_list_1 = require("./allowed-domain-reg-ex-list");
|
|
14
|
+
const allowed_explicit_domains_rules_1 = require("./allowed-explicit-domains-rules");
|
|
15
|
+
const environment_1 = require("./enums/environment");
|
|
16
|
+
class CORS {
|
|
17
|
+
constructor(scope, environment = environment_1.Environment.Production) {
|
|
18
|
+
this.regExes = allowed_domain_reg_ex_list_1.AllowedDomainRegExList[scope][environment];
|
|
19
|
+
this.s3Rules = [allowed_explicit_domains_rules_1.AllowedExplicitDomainsRules[scope][environment]];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* isValidDomain
|
|
23
|
+
*/
|
|
24
|
+
isValidDomain(domain) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const hasMatch = this.regExes.filter((regex) => domain.match(regex) !== null);
|
|
27
|
+
return (hasMatch.length !== 0);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* getIamRules
|
|
32
|
+
*/
|
|
33
|
+
getS3Rules() {
|
|
34
|
+
return this.s3Rules;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.CORS = CORS;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare enum Environment {
|
|
2
|
-
Production = 0,
|
|
3
|
-
Testing = 1
|
|
4
|
-
}
|
|
1
|
+
export declare enum Environment {
|
|
2
|
+
Production = 0,
|
|
3
|
+
Testing = 1
|
|
4
|
+
}
|