@sphereon/ssi-express-support 0.18.2-next.3 → 0.18.2-unstable.10

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.
@@ -1,280 +1,280 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.ExpressCorsConfigurer = exports.ExpressBuilder = void 0;
16
- /**
17
- * @public
18
- */
19
- const body_parser_1 = __importDefault(require("body-parser"));
20
- const cors_1 = __importDefault(require("cors"));
21
- const express_1 = __importDefault(require("express"));
22
- const express_session_1 = __importDefault(require("express-session"));
23
- const http_terminator_1 = require("http-terminator");
24
- const morgan_1 = __importDefault(require("morgan"));
25
- const passport_1 = __importDefault(require("passport"));
26
- const auth_utils_1 = require("./auth-utils");
27
- const express_utils_1 = require("./express-utils");
28
- const functions_1 = require("./functions");
29
- class ExpressBuilder {
30
- constructor(opts) {
31
- this._handlers = [];
32
- this._startListen = undefined;
33
- this._usePassportAuth = false;
34
- const { existingExpress, envVarPrefix } = opts !== null && opts !== void 0 ? opts : {};
35
- if (existingExpress) {
36
- this.withExpress(existingExpress);
37
- }
38
- this.envVarPrefix = envVarPrefix !== null && envVarPrefix !== void 0 ? envVarPrefix : '';
39
- }
40
- static fromExistingExpress(opts) {
41
- return new ExpressBuilder(opts !== null && opts !== void 0 ? opts : {});
42
- }
43
- static fromServerOpts(opts) {
44
- var _a;
45
- const builder = new ExpressBuilder({ existingExpress: opts === null || opts === void 0 ? void 0 : opts.existingExpress, envVarPrefix: opts === null || opts === void 0 ? void 0 : opts.envVarPrefix });
46
- return builder.withEnableListenOpts(Object.assign(Object.assign({}, opts), { hostnameOrIP: opts.hostname, startOnBuild: (_a = opts.startListening) !== null && _a !== void 0 ? _a : false }));
47
- }
48
- enableListen(startOnBuild) {
49
- if (startOnBuild !== undefined) {
50
- this._startListen = startOnBuild;
51
- }
52
- return this;
53
- }
54
- withMorganLogging(opts) {
55
- var _a, _b;
56
- if ((opts === null || opts === void 0 ? void 0 : opts.existingMorgan) && (opts.format || opts.options)) {
57
- throw Error('Cannot using an existing morgan with either a format or options');
58
- }
59
- this._morgan = (_a = opts === null || opts === void 0 ? void 0 : opts.existingMorgan) !== null && _a !== void 0 ? _a : (0, morgan_1.default)((_b = opts === null || opts === void 0 ? void 0 : opts.format) !== null && _b !== void 0 ? _b : 'dev', opts === null || opts === void 0 ? void 0 : opts.options);
60
- return this;
61
- }
62
- withEnableListenOpts({ port, hostnameOrIP, callback, startOnBuild, }) {
63
- port && this.withPort(port);
64
- hostnameOrIP && this.withHostname(hostnameOrIP);
65
- if (typeof callback === 'function') {
66
- this.withListenCallback(callback);
67
- }
68
- this._startListen = startOnBuild === true;
69
- return this;
70
- }
71
- withPort(port) {
72
- this.port = port;
73
- return this;
74
- }
75
- withHostname(hostnameOrIP) {
76
- this.hostnameOrIP = hostnameOrIP;
77
- return this;
78
- }
79
- withListenCallback(callback) {
80
- this.listenCallback = callback;
81
- return this;
82
- }
83
- withExpress(existingExpress) {
84
- this.existingExpress = existingExpress;
85
- this._startListen = false;
86
- return this;
87
- }
88
- withCorsConfigurer(configurer) {
89
- this._corsConfigurer = configurer;
90
- return this;
91
- }
92
- withPassportAuth(usePassport, initializeOptions) {
93
- this._usePassportAuth = usePassport;
94
- this._passportInitOpts = initializeOptions;
95
- return this;
96
- }
97
- withGlobalUserIsInRole(userIsInRole) {
98
- this._userIsInRole = userIsInRole;
99
- return this;
100
- }
101
- withEnforcer(enforcer) {
102
- this._enforcer = enforcer;
103
- return this;
104
- }
105
- startListening(express) {
106
- this._server = express.listen(this.getPort(), this.getHostname(), this.listenCallback);
107
- this._terminator = (0, http_terminator_1.createHttpTerminator)({
108
- server: this._server,
109
- // gracefulTerminationTimeout: 10
110
- });
111
- return { server: this._server, terminator: this._terminator };
112
- }
113
- getHostname() {
114
- var _a, _b;
115
- return (_b = (_a = this.hostnameOrIP) !== null && _a !== void 0 ? _a : (0, functions_1.env)('HOSTNAME', this.envVarPrefix)) !== null && _b !== void 0 ? _b : '0.0.0.0';
116
- }
117
- getPort() {
118
- var _a, _b;
119
- return ((_b = (_a = this.port) !== null && _a !== void 0 ? _a : (0, functions_1.env)('PORT', this.envVarPrefix)) !== null && _b !== void 0 ? _b : 5000);
120
- }
121
- setHandlers(handlers) {
122
- if (Array.isArray(handlers)) {
123
- this._handlers = handlers;
124
- }
125
- else if (handlers) {
126
- if (!this._handlers) {
127
- this._handlers = [];
128
- }
129
- this._handlers.push(handlers);
130
- }
131
- else {
132
- this._handlers = [];
133
- }
134
- return this;
135
- }
136
- addHandler(handler) {
137
- if (!this._handlers) {
138
- this._handlers = [];
139
- }
140
- this._handlers.push(handler);
141
- return this;
142
- }
143
- withSessionOptions(sessionOpts) {
144
- this._sessionOpts = sessionOpts;
145
- return this;
146
- }
147
- build(opts) {
148
- const express = this.buildExpress(opts);
149
- const startListening = (opts === null || opts === void 0 ? void 0 : opts.startListening) === undefined ? this._startListen !== true : opts.startListening;
150
- let started = this._server !== undefined;
151
- if (startListening && !started) {
152
- this.startListening(express);
153
- started = true;
154
- }
155
- return {
156
- express,
157
- port: this.getPort(),
158
- hostname: this.getHostname(),
159
- userIsInRole: this._userIsInRole,
160
- startListening,
161
- enforcer: this._enforcer,
162
- start: (opts) => {
163
- if (opts === null || opts === void 0 ? void 0 : opts.doNotStartListening) {
164
- console.log('Express will not start listening. You will have to start it yourself');
165
- }
166
- else {
167
- if (!started) {
168
- this.startListening(express);
169
- started = true;
170
- }
171
- }
172
- if ((opts === null || opts === void 0 ? void 0 : opts.disableErrorHandler) !== true) {
173
- express.use(express_utils_1.jsonErrorHandler);
174
- }
175
- return { server: this._server, terminator: this._terminator };
176
- },
177
- stop: (terminator) => __awaiter(this, void 0, void 0, function* () {
178
- const term = terminator !== null && terminator !== void 0 ? terminator : this._terminator;
179
- if (!term) {
180
- return false;
181
- }
182
- return yield term.terminate().then(() => true);
183
- }),
184
- };
185
- }
186
- buildExpress(opts) {
187
- var _a, _b, _c;
188
- const app = (_b = (_a = opts === null || opts === void 0 ? void 0 : opts.express) !== null && _a !== void 0 ? _a : this.existingExpress) !== null && _b !== void 0 ? _b : (0, express_1.default)();
189
- if (this._morgan) {
190
- app.use(this._morgan);
191
- }
192
- if (this._sessionOpts) {
193
- const store = (_c = this._sessionOpts.store) !== null && _c !== void 0 ? _c : new express_session_1.default.MemoryStore();
194
- this._sessionOpts.store = store;
195
- app.use((0, express_session_1.default)(this._sessionOpts));
196
- }
197
- if (this._usePassportAuth) {
198
- app.use(passport_1.default.initialize(this._passportInitOpts));
199
- if (this._sessionOpts) {
200
- // app.use(passport.authenticate('session'))
201
- //_sessionOpts are not for passport session, they are for express above
202
- app.use(passport_1.default.session());
203
- }
204
- }
205
- if (this._userIsInRole) {
206
- app.use((0, auth_utils_1.checkUserIsInRole)({ roles: this._userIsInRole }));
207
- }
208
- if (this._corsConfigurer) {
209
- this._corsConfigurer.configure({ existingExpress: app });
210
- }
211
- // @ts-ignore
212
- this._handlers && this._handlers.length > 0 && app.use(this._handlers);
213
- // @ts-ignore
214
- (opts === null || opts === void 0 ? void 0 : opts.handlers) && app.use(opts.handlers);
215
- app.use(body_parser_1.default.urlencoded({ extended: true }));
216
- app.use(body_parser_1.default.json());
217
- return app;
218
- }
219
- }
220
- exports.ExpressBuilder = ExpressBuilder;
221
- class ExpressCorsConfigurer {
222
- constructor(args) {
223
- const { existingExpress, envVarPrefix } = args !== null && args !== void 0 ? args : {};
224
- this._express = existingExpress;
225
- this._envVarPrefix = envVarPrefix;
226
- }
227
- allowOrigin(value) {
228
- this._allowOrigin = value;
229
- return this;
230
- }
231
- disableCors(value) {
232
- this._disableCors = value;
233
- return this;
234
- }
235
- allowMethods(value) {
236
- this._allowMethods = value;
237
- return this;
238
- }
239
- allowedHeaders(value) {
240
- this._allowedHeaders = value;
241
- return this;
242
- }
243
- allowCredentials(value) {
244
- this._allowCredentials = value;
245
- return this;
246
- }
247
- configure({ existingExpress }) {
248
- var _a, _b, _c;
249
- const express = existingExpress !== null && existingExpress !== void 0 ? existingExpress : this._express;
250
- if (!express) {
251
- throw Error('No express passed in during construction or configure');
252
- }
253
- const disableCorsEnv = (0, functions_1.env)('CORS_DISABLE', this._envVarPrefix);
254
- const corsDisabled = (_a = this._disableCors) !== null && _a !== void 0 ? _a : (disableCorsEnv ? /true/.test(disableCorsEnv) : false);
255
- if (corsDisabled) {
256
- return;
257
- }
258
- const envAllowOriginStr = (_b = (0, functions_1.env)('CORS_ALLOW_ORIGIN', this._envVarPrefix)) !== null && _b !== void 0 ? _b : '*';
259
- let envAllowOrigin;
260
- if (envAllowOriginStr.includes(',')) {
261
- envAllowOrigin = envAllowOriginStr.split(',');
262
- }
263
- else if (envAllowOriginStr.includes(' ')) {
264
- envAllowOrigin = envAllowOriginStr.split(' ');
265
- }
266
- else {
267
- envAllowOrigin = envAllowOriginStr;
268
- }
269
- if (Array.isArray(envAllowOrigin) && envAllowOrigin.length === 1) {
270
- envAllowOrigin = envAllowOrigin[0];
271
- }
272
- const corsOptions = Object.assign(Object.assign(Object.assign(Object.assign({ origin: (_c = this._allowOrigin) !== null && _c !== void 0 ? _c : envAllowOrigin }, (this._allowMethods && { methods: this._allowMethods })), (this._allowedHeaders && { allowedHeaders: this._allowedHeaders })), (this._allowCredentials !== undefined && { credentials: this._allowCredentials })), { optionsSuccessStatus: 204 });
273
- if (this._enablePreflightOptions) {
274
- express.options('*', (0, cors_1.default)(corsOptions));
275
- }
276
- express.use((0, cors_1.default)(corsOptions));
277
- }
278
- }
279
- exports.ExpressCorsConfigurer = ExpressCorsConfigurer;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ExpressCorsConfigurer = exports.ExpressBuilder = void 0;
16
+ /**
17
+ * @public
18
+ */
19
+ const body_parser_1 = __importDefault(require("body-parser"));
20
+ const cors_1 = __importDefault(require("cors"));
21
+ const express_1 = __importDefault(require("express"));
22
+ const express_session_1 = __importDefault(require("express-session"));
23
+ const http_terminator_1 = require("http-terminator");
24
+ const morgan_1 = __importDefault(require("morgan"));
25
+ const passport_1 = __importDefault(require("passport"));
26
+ const auth_utils_1 = require("./auth-utils");
27
+ const express_utils_1 = require("./express-utils");
28
+ const functions_1 = require("./functions");
29
+ class ExpressBuilder {
30
+ constructor(opts) {
31
+ this._handlers = [];
32
+ this._startListen = undefined;
33
+ this._usePassportAuth = false;
34
+ const { existingExpress, envVarPrefix } = opts !== null && opts !== void 0 ? opts : {};
35
+ if (existingExpress) {
36
+ this.withExpress(existingExpress);
37
+ }
38
+ this.envVarPrefix = envVarPrefix !== null && envVarPrefix !== void 0 ? envVarPrefix : '';
39
+ }
40
+ static fromExistingExpress(opts) {
41
+ return new ExpressBuilder(opts !== null && opts !== void 0 ? opts : {});
42
+ }
43
+ static fromServerOpts(opts) {
44
+ var _a;
45
+ const builder = new ExpressBuilder({ existingExpress: opts === null || opts === void 0 ? void 0 : opts.existingExpress, envVarPrefix: opts === null || opts === void 0 ? void 0 : opts.envVarPrefix });
46
+ return builder.withEnableListenOpts(Object.assign(Object.assign({}, opts), { hostnameOrIP: opts.hostname, startOnBuild: (_a = opts.startListening) !== null && _a !== void 0 ? _a : false }));
47
+ }
48
+ enableListen(startOnBuild) {
49
+ if (startOnBuild !== undefined) {
50
+ this._startListen = startOnBuild;
51
+ }
52
+ return this;
53
+ }
54
+ withMorganLogging(opts) {
55
+ var _a, _b;
56
+ if ((opts === null || opts === void 0 ? void 0 : opts.existingMorgan) && (opts.format || opts.options)) {
57
+ throw Error('Cannot using an existing morgan with either a format or options');
58
+ }
59
+ this._morgan = (_a = opts === null || opts === void 0 ? void 0 : opts.existingMorgan) !== null && _a !== void 0 ? _a : (0, morgan_1.default)((_b = opts === null || opts === void 0 ? void 0 : opts.format) !== null && _b !== void 0 ? _b : 'dev', opts === null || opts === void 0 ? void 0 : opts.options);
60
+ return this;
61
+ }
62
+ withEnableListenOpts({ port, hostnameOrIP, callback, startOnBuild, }) {
63
+ port && this.withPort(port);
64
+ hostnameOrIP && this.withHostname(hostnameOrIP);
65
+ if (typeof callback === 'function') {
66
+ this.withListenCallback(callback);
67
+ }
68
+ this._startListen = startOnBuild === true;
69
+ return this;
70
+ }
71
+ withPort(port) {
72
+ this.port = port;
73
+ return this;
74
+ }
75
+ withHostname(hostnameOrIP) {
76
+ this.hostnameOrIP = hostnameOrIP;
77
+ return this;
78
+ }
79
+ withListenCallback(callback) {
80
+ this.listenCallback = callback;
81
+ return this;
82
+ }
83
+ withExpress(existingExpress) {
84
+ this.existingExpress = existingExpress;
85
+ this._startListen = false;
86
+ return this;
87
+ }
88
+ withCorsConfigurer(configurer) {
89
+ this._corsConfigurer = configurer;
90
+ return this;
91
+ }
92
+ withPassportAuth(usePassport, initializeOptions) {
93
+ this._usePassportAuth = usePassport;
94
+ this._passportInitOpts = initializeOptions;
95
+ return this;
96
+ }
97
+ withGlobalUserIsInRole(userIsInRole) {
98
+ this._userIsInRole = userIsInRole;
99
+ return this;
100
+ }
101
+ withEnforcer(enforcer) {
102
+ this._enforcer = enforcer;
103
+ return this;
104
+ }
105
+ startListening(express) {
106
+ this._server = express.listen(this.getPort(), this.getHostname(), this.listenCallback);
107
+ this._terminator = (0, http_terminator_1.createHttpTerminator)({
108
+ server: this._server,
109
+ // gracefulTerminationTimeout: 10
110
+ });
111
+ return { server: this._server, terminator: this._terminator };
112
+ }
113
+ getHostname() {
114
+ var _a, _b;
115
+ return (_b = (_a = this.hostnameOrIP) !== null && _a !== void 0 ? _a : (0, functions_1.env)('HOSTNAME', this.envVarPrefix)) !== null && _b !== void 0 ? _b : '0.0.0.0';
116
+ }
117
+ getPort() {
118
+ var _a, _b;
119
+ return ((_b = (_a = this.port) !== null && _a !== void 0 ? _a : (0, functions_1.env)('PORT', this.envVarPrefix)) !== null && _b !== void 0 ? _b : 5000);
120
+ }
121
+ setHandlers(handlers) {
122
+ if (Array.isArray(handlers)) {
123
+ this._handlers = handlers;
124
+ }
125
+ else if (handlers) {
126
+ if (!this._handlers) {
127
+ this._handlers = [];
128
+ }
129
+ this._handlers.push(handlers);
130
+ }
131
+ else {
132
+ this._handlers = [];
133
+ }
134
+ return this;
135
+ }
136
+ addHandler(handler) {
137
+ if (!this._handlers) {
138
+ this._handlers = [];
139
+ }
140
+ this._handlers.push(handler);
141
+ return this;
142
+ }
143
+ withSessionOptions(sessionOpts) {
144
+ this._sessionOpts = sessionOpts;
145
+ return this;
146
+ }
147
+ build(opts) {
148
+ const express = this.buildExpress(opts);
149
+ const startListening = (opts === null || opts === void 0 ? void 0 : opts.startListening) === undefined ? this._startListen !== true : opts.startListening;
150
+ let started = this._server !== undefined;
151
+ if (startListening && !started) {
152
+ this.startListening(express);
153
+ started = true;
154
+ }
155
+ return {
156
+ express,
157
+ port: this.getPort(),
158
+ hostname: this.getHostname(),
159
+ userIsInRole: this._userIsInRole,
160
+ startListening,
161
+ enforcer: this._enforcer,
162
+ start: (opts) => {
163
+ if (opts === null || opts === void 0 ? void 0 : opts.doNotStartListening) {
164
+ console.log('Express will not start listening. You will have to start it yourself');
165
+ }
166
+ else {
167
+ if (!started) {
168
+ this.startListening(express);
169
+ started = true;
170
+ }
171
+ }
172
+ if ((opts === null || opts === void 0 ? void 0 : opts.disableErrorHandler) !== true) {
173
+ express.use(express_utils_1.jsonErrorHandler);
174
+ }
175
+ return { server: this._server, terminator: this._terminator };
176
+ },
177
+ stop: (terminator) => __awaiter(this, void 0, void 0, function* () {
178
+ const term = terminator !== null && terminator !== void 0 ? terminator : this._terminator;
179
+ if (!term) {
180
+ return false;
181
+ }
182
+ return yield term.terminate().then(() => true);
183
+ }),
184
+ };
185
+ }
186
+ buildExpress(opts) {
187
+ var _a, _b, _c;
188
+ const app = (_b = (_a = opts === null || opts === void 0 ? void 0 : opts.express) !== null && _a !== void 0 ? _a : this.existingExpress) !== null && _b !== void 0 ? _b : (0, express_1.default)();
189
+ if (this._morgan) {
190
+ app.use(this._morgan);
191
+ }
192
+ if (this._sessionOpts) {
193
+ const store = (_c = this._sessionOpts.store) !== null && _c !== void 0 ? _c : new express_session_1.default.MemoryStore();
194
+ this._sessionOpts.store = store;
195
+ app.use((0, express_session_1.default)(this._sessionOpts));
196
+ }
197
+ if (this._usePassportAuth) {
198
+ app.use(passport_1.default.initialize(this._passportInitOpts));
199
+ if (this._sessionOpts) {
200
+ // app.use(passport.authenticate('session'))
201
+ //_sessionOpts are not for passport session, they are for express above
202
+ app.use(passport_1.default.session());
203
+ }
204
+ }
205
+ if (this._userIsInRole) {
206
+ app.use((0, auth_utils_1.checkUserIsInRole)({ roles: this._userIsInRole }));
207
+ }
208
+ if (this._corsConfigurer) {
209
+ this._corsConfigurer.configure({ existingExpress: app });
210
+ }
211
+ // @ts-ignore
212
+ this._handlers && this._handlers.length > 0 && app.use(this._handlers);
213
+ // @ts-ignore
214
+ (opts === null || opts === void 0 ? void 0 : opts.handlers) && app.use(opts.handlers);
215
+ app.use(body_parser_1.default.urlencoded({ extended: true }));
216
+ app.use(body_parser_1.default.json());
217
+ return app;
218
+ }
219
+ }
220
+ exports.ExpressBuilder = ExpressBuilder;
221
+ class ExpressCorsConfigurer {
222
+ constructor(args) {
223
+ const { existingExpress, envVarPrefix } = args !== null && args !== void 0 ? args : {};
224
+ this._express = existingExpress;
225
+ this._envVarPrefix = envVarPrefix;
226
+ }
227
+ allowOrigin(value) {
228
+ this._allowOrigin = value;
229
+ return this;
230
+ }
231
+ disableCors(value) {
232
+ this._disableCors = value;
233
+ return this;
234
+ }
235
+ allowMethods(value) {
236
+ this._allowMethods = value;
237
+ return this;
238
+ }
239
+ allowedHeaders(value) {
240
+ this._allowedHeaders = value;
241
+ return this;
242
+ }
243
+ allowCredentials(value) {
244
+ this._allowCredentials = value;
245
+ return this;
246
+ }
247
+ configure({ existingExpress }) {
248
+ var _a, _b, _c;
249
+ const express = existingExpress !== null && existingExpress !== void 0 ? existingExpress : this._express;
250
+ if (!express) {
251
+ throw Error('No express passed in during construction or configure');
252
+ }
253
+ const disableCorsEnv = (0, functions_1.env)('CORS_DISABLE', this._envVarPrefix);
254
+ const corsDisabled = (_a = this._disableCors) !== null && _a !== void 0 ? _a : (disableCorsEnv ? /true/.test(disableCorsEnv) : false);
255
+ if (corsDisabled) {
256
+ return;
257
+ }
258
+ const envAllowOriginStr = (_b = (0, functions_1.env)('CORS_ALLOW_ORIGIN', this._envVarPrefix)) !== null && _b !== void 0 ? _b : '*';
259
+ let envAllowOrigin;
260
+ if (envAllowOriginStr.includes(',')) {
261
+ envAllowOrigin = envAllowOriginStr.split(',');
262
+ }
263
+ else if (envAllowOriginStr.includes(' ')) {
264
+ envAllowOrigin = envAllowOriginStr.split(' ');
265
+ }
266
+ else {
267
+ envAllowOrigin = envAllowOriginStr;
268
+ }
269
+ if (Array.isArray(envAllowOrigin) && envAllowOrigin.length === 1) {
270
+ envAllowOrigin = envAllowOrigin[0];
271
+ }
272
+ const corsOptions = Object.assign(Object.assign(Object.assign(Object.assign({ origin: (_c = this._allowOrigin) !== null && _c !== void 0 ? _c : envAllowOrigin }, (this._allowMethods && { methods: this._allowMethods })), (this._allowedHeaders && { allowedHeaders: this._allowedHeaders })), (this._allowCredentials !== undefined && { credentials: this._allowCredentials })), { optionsSuccessStatus: 204 });
273
+ if (this._enablePreflightOptions) {
274
+ express.options('*', (0, cors_1.default)(corsOptions));
275
+ }
276
+ express.use((0, cors_1.default)(corsOptions));
277
+ }
278
+ }
279
+ exports.ExpressCorsConfigurer = ExpressCorsConfigurer;
280
280
  //# sourceMappingURL=express-builders.js.map
@@ -1,4 +1,4 @@
1
- import express, { NextFunction } from 'express';
2
- export declare function sendErrorResponse(response: express.Response, statusCode: number, message: string | object, error?: any): express.Response<any, Record<string, any>>;
3
- export declare const jsonErrorHandler: (err: any, req: express.Request, res: express.Response, next: NextFunction) => void | express.Response<any, Record<string, any>>;
1
+ import express, { NextFunction } from 'express';
2
+ export declare function sendErrorResponse(response: express.Response, statusCode: number, message: string | object, error?: any): express.Response<any, Record<string, any>>;
3
+ export declare const jsonErrorHandler: (err: any, req: express.Request, res: express.Response, next: NextFunction) => void | express.Response<any, Record<string, any>>;
4
4
  //# sourceMappingURL=express-utils.d.ts.map