@tstdl/base 0.71.25 → 0.71.28
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,39 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.corsMiddleware = void 0;
|
|
4
|
+
const types_1 = require("../../types");
|
|
4
5
|
const type_guards_1 = require("../../../utils/type-guards");
|
|
5
6
|
// eslint-disable-next-line max-statements
|
|
6
7
|
async function corsMiddleware(request, next, context) {
|
|
7
|
-
var _a;
|
|
8
|
+
var _a, _b;
|
|
8
9
|
const response = await next(request);
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (corses.length == 0) {
|
|
10
|
+
const requestMethod = request.headers.tryGetSingle('Access-Control-Request-Method');
|
|
11
|
+
const cors = (_a = context.api.endpoints.get(requestMethod)) === null || _a === void 0 ? void 0 : _a.definition.cors;
|
|
12
|
+
if ((0, type_guards_1.isUndefined)(cors)) {
|
|
13
13
|
return response;
|
|
14
14
|
}
|
|
15
|
-
if (corses.length > 1) {
|
|
16
|
-
throw new Error('cors can only be defined once per resource');
|
|
17
|
-
}
|
|
18
|
-
const cors = corses[0];
|
|
19
15
|
if (request.method == 'OPTIONS') {
|
|
20
|
-
const allowMethods = [...context.api.endpoints.keys()].join(', ');
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
const allowMethods = (_b = (await (0, types_1.resolveApiEndpointDataProvider)(request, context, cors.accessControlAllowMethods))) !== null && _b !== void 0 ? _b : [...context.api.endpoints.keys()].join(', ');
|
|
17
|
+
const allowCredentials = (0, type_guards_1.isDefined)(cors.accessControlAllowCredentials) && (await (0, types_1.resolveApiEndpointDataProvider)(request, context, cors.accessControlAllowCredentials));
|
|
18
|
+
response.headers.setIfMissing('Access-Control-Allow-Methods', allowMethods);
|
|
19
|
+
if (allowCredentials) {
|
|
23
20
|
response.headers.setIfMissing('Access-Control-Allow-Credentials', 'true');
|
|
24
21
|
}
|
|
25
22
|
if ((0, type_guards_1.isDefined)(cors.accessControlAllowHeaders)) {
|
|
26
|
-
|
|
23
|
+
const value = await (0, types_1.resolveApiEndpointDataProvider)(request, context, cors.accessControlAllowHeaders);
|
|
24
|
+
response.headers.setIfMissing('Access-Control-Allow-Headers', value);
|
|
27
25
|
}
|
|
28
26
|
if ((0, type_guards_1.isDefined)(cors.accessControlExposeHeaders)) {
|
|
29
|
-
|
|
27
|
+
const value = await (0, types_1.resolveApiEndpointDataProvider)(request, context, cors.accessControlExposeHeaders);
|
|
28
|
+
response.headers.setIfMissing('Access-Control-Expose-Headers', value);
|
|
30
29
|
}
|
|
31
30
|
if ((0, type_guards_1.isDefined)(cors.accessControlMaxAge)) {
|
|
32
|
-
|
|
31
|
+
const value = await (0, types_1.resolveApiEndpointDataProvider)(request, context, cors.accessControlMaxAge);
|
|
32
|
+
response.headers.setIfMissing('Access-Control-Max-Age', value);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
if ((0, type_guards_1.isDefined)(cors.accessControlAllowOrigin)) {
|
|
36
|
-
|
|
36
|
+
const value = await (0, types_1.resolveApiEndpointDataProvider)(request, context, cors.accessControlAllowOrigin);
|
|
37
|
+
response.headers.setIfMissing('Access-Control-Allow-Origin', value);
|
|
37
38
|
}
|
|
38
39
|
return response;
|
|
39
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cors.middleware.js","sourceRoot":"","sources":["../../../../source/api/server/middlewares/cors.middleware.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"cors.middleware.js","sourceRoot":"","sources":["../../../../source/api/server/middlewares/cors.middleware.ts"],"names":[],"mappings":";;;AACA,uCAA6D;AAG7D,4DAA6D;AAG7D,0CAA0C;AACnC,KAAK,UAAU,cAAc,CAAC,OAA0B,EAAE,IAAgE,EAAE,OAAoC;;IACrK,MAAM,QAAQ,GAAG,MAAM,IAAI,CAA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,CAAC,0BAA0B,CAAC,EAAE;YAC9C,MAAM,KAAK,GAAG,MAAM,IAAA,sCAA8B,EAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,0BAA0B,CAAC,CAAC;YACtG,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;SACvE;QAED,IAAI,IAAA,uBAAS,EAAC,IAAI,CAAC,mBAAmB,CAAC,EAAE;YACvC,MAAM,KAAK,GAAG,MAAM,IAAA,sCAA8B,EAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;YAC/F,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;SAChE;KACF;IAED,IAAI,IAAA,uBAAS,EAAC,IAAI,CAAC,wBAAwB,CAAC,EAAE;QAC5C,MAAM,KAAK,GAAG,MAAM,IAAA,sCAA8B,EAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,wBAAwB,CAAC,CAAC;QACpG,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;KACrE;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AA1CD,wCA0CC"}
|
package/api/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { HttpServerRequest, HttpServerResponse } from "../http/server";
|
|
|
2
2
|
import type { HttpMethod } from "../http/types";
|
|
3
3
|
import type { ObjectSchemaValidator, SchemaInput, SchemaOutput, SchemaValidator, StringSchemaValidator, Uint8ArraySchemaValidator } from "../schema";
|
|
4
4
|
import type { NonUndefinable, OneOrMany, Record } from "../types";
|
|
5
|
+
import type { ApiGatewayMiddlewareContext } from './server';
|
|
5
6
|
export declare const rootResource = "$";
|
|
6
7
|
export declare type ApiRegistrationOptions = {
|
|
7
8
|
name?: string;
|
|
@@ -20,13 +21,14 @@ export declare type EndpointRegistrationOptions = {
|
|
|
20
21
|
export declare type ApiEndpointMethod = HttpMethod;
|
|
21
22
|
export declare type ApiEndpointDefinitionBody = StringSchemaValidator | ObjectSchemaValidator<any> | Uint8ArraySchemaValidator;
|
|
22
23
|
export declare type ApiEndpointDefinitionResult = SchemaValidator;
|
|
24
|
+
export declare type ApiEndpointDataProvider<T> = T | ((request: HttpServerRequest, context: ApiGatewayMiddlewareContext) => T | Promise<T>);
|
|
23
25
|
export declare type ApiEndpointDefinitionCors = {
|
|
24
|
-
accessControlAllowCredentials?: boolean
|
|
25
|
-
accessControlAllowHeaders?: OneOrMany<string
|
|
26
|
-
accessControlAllowMethods?: OneOrMany<HttpMethod
|
|
27
|
-
accessControlAllowOrigin?: string
|
|
28
|
-
accessControlExposeHeaders?: OneOrMany<string
|
|
29
|
-
accessControlMaxAge?: number
|
|
26
|
+
accessControlAllowCredentials?: ApiEndpointDataProvider<boolean>;
|
|
27
|
+
accessControlAllowHeaders?: ApiEndpointDataProvider<OneOrMany<string>>;
|
|
28
|
+
accessControlAllowMethods?: ApiEndpointDataProvider<OneOrMany<HttpMethod>>;
|
|
29
|
+
accessControlAllowOrigin?: ApiEndpointDataProvider<string>;
|
|
30
|
+
accessControlExposeHeaders?: ApiEndpointDataProvider<OneOrMany<string>>;
|
|
31
|
+
accessControlMaxAge?: ApiEndpointDataProvider<number>;
|
|
30
32
|
};
|
|
31
33
|
export declare type ApiEndpointDefinition = {
|
|
32
34
|
method?: OneOrMany<ApiEndpointMethod>;
|
|
@@ -68,3 +70,4 @@ export declare type ApiClientImplementation<T extends ApiDefinition = any> = {
|
|
|
68
70
|
[P in ApiEndpointKeys<T>]: ApiEndpointClientImplementation<T, P>;
|
|
69
71
|
};
|
|
70
72
|
export declare function defineApi<T extends ApiDefinition>(definition: T): T;
|
|
73
|
+
export declare function resolveApiEndpointDataProvider<T>(request: HttpServerRequest, context: ApiGatewayMiddlewareContext, provider: ApiEndpointDataProvider<T>): Promise<T>;
|
package/api/types.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defineApi = exports.rootResource = void 0;
|
|
3
|
+
exports.resolveApiEndpointDataProvider = exports.defineApi = exports.rootResource = void 0;
|
|
4
|
+
const type_guards_1 = require("../utils/type-guards");
|
|
4
5
|
exports.rootResource = '$';
|
|
5
6
|
function defineApi(definition) {
|
|
6
7
|
return definition;
|
|
7
8
|
}
|
|
8
9
|
exports.defineApi = defineApi;
|
|
10
|
+
async function resolveApiEndpointDataProvider(request, context, provider) {
|
|
11
|
+
if ((0, type_guards_1.isFunction)(provider)) {
|
|
12
|
+
return provider(request, context);
|
|
13
|
+
}
|
|
14
|
+
return provider;
|
|
15
|
+
}
|
|
16
|
+
exports.resolveApiEndpointDataProvider = resolveApiEndpointDataProvider;
|
|
9
17
|
//# sourceMappingURL=types.js.map
|
package/api/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../source/api/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../source/api/types.ts"],"names":[],"mappings":";;;AAIA,sDAAiD;AAGpC,QAAA,YAAY,GAAG,GAAG,CAAC;AA6FhC,SAAgB,SAAS,CAA0B,UAAa;IAC9D,OAAO,UAAU,CAAC;AACpB,CAAC;AAFD,8BAEC;AAEM,KAAK,UAAU,8BAA8B,CAAI,OAA0B,EAAE,OAAoC,EAAE,QAAoC;IAC5J,IAAI,IAAA,wBAAU,EAAC,QAAQ,CAAC,EAAE;QACxB,OAAO,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;KACnC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAND,wEAMC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.71.
|
|
3
|
+
"version": "0.71.28",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"@types/node": ">=16",
|
|
27
27
|
"@types/nodemailer": "^6.4.4",
|
|
28
28
|
"@types/yup": "0.29",
|
|
29
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
30
|
-
"@typescript-eslint/parser": "5.
|
|
29
|
+
"@typescript-eslint/eslint-plugin": "5.24",
|
|
30
|
+
"@typescript-eslint/parser": "5.24",
|
|
31
31
|
"eslint": "8.15",
|
|
32
32
|
"ttypescript": "1.5",
|
|
33
33
|
"typedoc": "0.22",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"typescript-transform-paths": "3.3"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@elastic/elasticsearch": "^8.2",
|
|
38
|
+
"@elastic/elasticsearch": "^8.2.0-patch.1",
|
|
39
39
|
"@koa/router": "^10.1",
|
|
40
40
|
"@tstdl/angular": "^0.10",
|
|
41
41
|
"chroma-js": "^2.4",
|