@webiny/api-composition-core 0.0.0-stage β 6.6.0-alpha.13
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/LICENSE +21 -0
- package/README.md +10 -2
- package/auth/extractAuthToken.d.ts +18 -0
- package/auth/extractAuthToken.js +33 -0
- package/auth/extractAuthToken.js.map +1 -0
- package/auth/extractTenantId.d.ts +6 -0
- package/auth/extractTenantId.js +7 -0
- package/auth/extractTenantId.js.map +1 -0
- package/auth/index.d.ts +2 -0
- package/auth/index.js +2 -0
- package/auth/rejectedTokenResponse.d.ts +8 -0
- package/auth/rejectedTokenResponse.js +15 -0
- package/auth/rejectedTokenResponse.js.map +1 -0
- package/buildParams/registerRootBuildParams.d.ts +15 -0
- package/buildParams/registerRootBuildParams.js +11 -0
- package/buildParams/registerRootBuildParams.js.map +1 -0
- package/http/HttpAssumePermissionsDecorator.d.ts +19 -0
- package/http/HttpAssumePermissionsDecorator.js +22 -0
- package/http/HttpAssumePermissionsDecorator.js.map +1 -0
- package/http/HttpIdentityLoaderDecorator.d.ts +28 -0
- package/http/HttpIdentityLoaderDecorator.js +33 -0
- package/http/HttpIdentityLoaderDecorator.js.map +1 -0
- package/http/HttpInputTenantSource.d.ts +13 -0
- package/http/HttpInputTenantSource.js +11 -0
- package/http/HttpInputTenantSource.js.map +1 -0
- package/http/HttpRequestContextFeature.d.ts +20 -0
- package/http/HttpRequestContextFeature.js +13 -0
- package/http/HttpRequestContextFeature.js.map +1 -0
- package/http/HttpTenantScopeRouter.d.ts +33 -0
- package/http/HttpTenantScopeRouter.js +58 -0
- package/http/HttpTenantScopeRouter.js.map +1 -0
- package/http/index.d.ts +3 -0
- package/http/index.js +2 -0
- package/http/readStreamInScope.d.ts +12 -0
- package/http/readStreamInScope.js +43 -0
- package/http/readStreamInScope.js.map +1 -0
- package/http/registerHttpTransport.d.ts +23 -0
- package/http/registerHttpTransport.js +13 -0
- package/http/registerHttpTransport.js.map +1 -0
- package/http/registerRootAllowedRequestHeaders.d.ts +26 -0
- package/http/registerRootAllowedRequestHeaders.js +39 -0
- package/http/registerRootAllowedRequestHeaders.js.map +1 -0
- package/index.d.ts +9 -0
- package/index.js +6 -0
- package/logger/PinoLogger.d.ts +13 -0
- package/logger/PinoLogger.js +29 -0
- package/logger/PinoLogger.js.map +1 -0
- package/logger/createLogger.d.ts +13 -0
- package/logger/createLogger.js +36 -0
- package/logger/createLogger.js.map +1 -0
- package/package.json +64 -5
- package/registerApiRequestStack.d.ts +81 -0
- package/registerApiRequestStack.js +75 -0
- package/registerApiRequestStack.js.map +1 -0
- package/requestRegistration/abstractions.d.ts +18 -0
- package/requestRegistration/abstractions.js +5 -0
- package/requestRegistration/abstractions.js.map +1 -0
- package/requestRegistration/index.d.ts +1 -0
- package/requestRegistration/index.js +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @webiny/api-composition-core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This package is part of the [Webiny](https://www.webiny.com) monorepo.
|
|
5
|
+
> Itβs **included in every Webiny project by default** and is not meant to be used as a standalone package.
|
|
6
|
+
|
|
7
|
+
π **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
_This README file is automatically generated during the publish process._
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { IHttpRequest } from "@webiny/api-kernel-core";
|
|
2
|
+
/**
|
|
3
|
+
* The `wby-id-token` cookie exists only for private file delivery: an `<img src>` cannot send an
|
|
4
|
+
* `Authorization` header. It must not log users in anywhere else, because the browser attaches it
|
|
5
|
+
* to cross-site requests too (`SameSite=None`), which would let any website call the API as the user.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isCookieAuthenticationAllowed(request: Pick<IHttpRequest, "method" | "path">): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Reads the auth token, preferring `x-webiny-authorization` over `Authorization`.
|
|
10
|
+
*
|
|
11
|
+
* The order matters for CloudFront β Lambda Function URL (the streaming routes, file delivery): the
|
|
12
|
+
* Origin Access Control signs those requests with SigV4 in the `Authorization` header, so a viewer's
|
|
13
|
+
* bearer token cannot survive to the origin, and clients send it in `x-webiny-authorization` instead.
|
|
14
|
+
* A Lambda web function origin is different: CloudFront keeps the viewer's `Authorization` there, so
|
|
15
|
+
* plain `Authorization` works for the API's main routes. The `wby-id-token` cookie is the last resort,
|
|
16
|
+
* and only for private file reads (see {@link isCookieAuthenticationAllowed}).
|
|
17
|
+
*/
|
|
18
|
+
export declare function extractAuthToken(request: Pick<IHttpRequest, "method" | "path" | "headers">): string | null;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getHeader } from "@webiny/api-kernel-core";
|
|
2
|
+
const WEBINY_AUTHORIZATION_HEADER = "x-webiny-authorization";
|
|
3
|
+
function readCookie(cookieHeader, name) {
|
|
4
|
+
let rawValue = null;
|
|
5
|
+
for (const pair of cookieHeader.split(";")){
|
|
6
|
+
const idx = pair.indexOf("=");
|
|
7
|
+
if (idx > 0 && pair.slice(0, idx).trim() === name) rawValue = pair.slice(idx + 1).trim();
|
|
8
|
+
}
|
|
9
|
+
if (null === rawValue) return null;
|
|
10
|
+
try {
|
|
11
|
+
return decodeURIComponent(rawValue);
|
|
12
|
+
} catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function isCookieAuthenticationAllowed(request) {
|
|
17
|
+
const method = request.method.toUpperCase();
|
|
18
|
+
if ("GET" !== method && "HEAD" !== method) return false;
|
|
19
|
+
return request.path.startsWith("/private/");
|
|
20
|
+
}
|
|
21
|
+
function extractAuthToken(request) {
|
|
22
|
+
const headers = request.headers;
|
|
23
|
+
const webinyAuth = getHeader(headers, WEBINY_AUTHORIZATION_HEADER).replace(/^Bearer\s+/i, "");
|
|
24
|
+
if (webinyAuth) return webinyAuth;
|
|
25
|
+
const bearer = getHeader(headers, "authorization").replace(/^Bearer\s+/i, "");
|
|
26
|
+
if (bearer) return bearer;
|
|
27
|
+
if (!isCookieAuthenticationAllowed(request)) return null;
|
|
28
|
+
const cookieHeader = getHeader(headers, "cookie");
|
|
29
|
+
return readCookie(cookieHeader, "wby-id-token");
|
|
30
|
+
}
|
|
31
|
+
export { extractAuthToken, isCookieAuthenticationAllowed };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=extractAuthToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth/extractAuthToken.js","sources":["../../src/auth/extractAuthToken.ts"],"sourcesContent":["import { getHeader } from \"@webiny/api-kernel-core\";\nimport type { IHttpRequest } from \"@webiny/api-kernel-core\";\n\nconst WEBINY_AUTHORIZATION_HEADER = \"x-webiny-authorization\";\n\n/**\n * Finds one cookie and decodes only its value. Decoding every cookie would let any other cookie on the\n * domain that isn't valid URI encoding (`promo=50%off`) throw and fail the request. If the cookie is\n * sent more than once (same name, different Path or Domain), the last one wins, as it always has.\n */\nfunction readCookie(cookieHeader: string, name: string): string | null {\n let rawValue: string | null = null;\n for (const pair of cookieHeader.split(\";\")) {\n const idx = pair.indexOf(\"=\");\n if (idx > 0 && pair.slice(0, idx).trim() === name) {\n rawValue = pair.slice(idx + 1).trim();\n }\n }\n if (rawValue === null) {\n return null;\n }\n try {\n return decodeURIComponent(rawValue);\n } catch {\n // Not valid URI encoding, so not a token we issued.\n return null;\n }\n}\n\n/**\n * The `wby-id-token` cookie exists only for private file delivery: an `<img src>` cannot send an\n * `Authorization` header. It must not log users in anywhere else, because the browser attaches it\n * to cross-site requests too (`SameSite=None`), which would let any website call the API as the user.\n */\nexport function isCookieAuthenticationAllowed(\n request: Pick<IHttpRequest, \"method\" | \"path\">\n): boolean {\n const method = request.method.toUpperCase();\n if (method !== \"GET\" && method !== \"HEAD\") {\n return false;\n }\n return request.path.startsWith(\"/private/\");\n}\n\n/**\n * Reads the auth token, preferring `x-webiny-authorization` over `Authorization`.\n *\n * The order matters for CloudFront β Lambda Function URL (the streaming routes, file delivery): the\n * Origin Access Control signs those requests with SigV4 in the `Authorization` header, so a viewer's\n * bearer token cannot survive to the origin, and clients send it in `x-webiny-authorization` instead.\n * A Lambda web function origin is different: CloudFront keeps the viewer's `Authorization` there, so\n * plain `Authorization` works for the API's main routes. The `wby-id-token` cookie is the last resort,\n * and only for private file reads (see {@link isCookieAuthenticationAllowed}).\n */\nexport function extractAuthToken(\n request: Pick<IHttpRequest, \"method\" | \"path\" | \"headers\">\n): string | null {\n const headers = request.headers;\n const webinyAuth = getHeader(headers, WEBINY_AUTHORIZATION_HEADER).replace(/^Bearer\\s+/i, \"\");\n if (webinyAuth) {\n return webinyAuth;\n }\n\n const bearer = getHeader(headers, \"authorization\").replace(/^Bearer\\s+/i, \"\");\n if (bearer) {\n return bearer;\n }\n\n if (!isCookieAuthenticationAllowed(request)) {\n return null;\n }\n\n const cookieHeader = getHeader(headers, \"cookie\");\n return readCookie(cookieHeader, \"wby-id-token\");\n}\n"],"names":["WEBINY_AUTHORIZATION_HEADER","readCookie","cookieHeader","name","rawValue","pair","idx","decodeURIComponent","isCookieAuthenticationAllowed","request","method","extractAuthToken","headers","webinyAuth","getHeader","bearer"],"mappings":";AAGA,MAAMA,8BAA8B;AAOpC,SAASC,WAAWC,YAAoB,EAAEC,IAAY;IAClD,IAAIC,WAA0B;IAC9B,KAAK,MAAMC,QAAQH,aAAa,KAAK,CAAC,KAAM;QACxC,MAAMI,MAAMD,KAAK,OAAO,CAAC;QACzB,IAAIC,MAAM,KAAKD,KAAK,KAAK,CAAC,GAAGC,KAAK,IAAI,OAAOH,MACzCC,WAAWC,KAAK,KAAK,CAACC,MAAM,GAAG,IAAI;IAE3C;IACA,IAAIF,AAAa,SAAbA,UACA,OAAO;IAEX,IAAI;QACA,OAAOG,mBAAmBH;IAC9B,EAAE,OAAM;QAEJ,OAAO;IACX;AACJ;AAOO,SAASI,8BACZC,OAA8C;IAE9C,MAAMC,SAASD,QAAQ,MAAM,CAAC,WAAW;IACzC,IAAIC,AAAW,UAAXA,UAAoBA,AAAW,WAAXA,QACpB,OAAO;IAEX,OAAOD,QAAQ,IAAI,CAAC,UAAU,CAAC;AACnC;AAYO,SAASE,iBACZF,OAA0D;IAE1D,MAAMG,UAAUH,QAAQ,OAAO;IAC/B,MAAMI,aAAaC,UAAUF,SAASZ,6BAA6B,OAAO,CAAC,eAAe;IAC1F,IAAIa,YACA,OAAOA;IAGX,MAAME,SAASD,UAAUF,SAAS,iBAAiB,OAAO,CAAC,eAAe;IAC1E,IAAIG,QACA,OAAOA;IAGX,IAAI,CAACP,8BAA8BC,UAC/B,OAAO;IAGX,MAAMP,eAAeY,UAAUF,SAAS;IACxC,OAAOX,WAAWC,cAAc;AACpC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { IHttpRequest } from "@webiny/api-kernel-core";
|
|
2
|
+
/**
|
|
3
|
+
* Reads the tenant id from the `x-tenant` header. A missing or empty header is no tenant, and the
|
|
4
|
+
* tenant loader then uses the root tenant.
|
|
5
|
+
*/
|
|
6
|
+
export declare function extractTenantId(request: Pick<IHttpRequest, "headers">): string | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth/extractTenantId.js","sources":["../../src/auth/extractTenantId.ts"],"sourcesContent":["import { getHeader } from \"@webiny/api-kernel-core\";\nimport type { IHttpRequest } from \"@webiny/api-kernel-core\";\n\n/**\n * Reads the tenant id from the `x-tenant` header. A missing or empty header is no tenant, and the\n * tenant loader then uses the root tenant.\n */\nexport function extractTenantId(request: Pick<IHttpRequest, \"headers\">): string | null {\n return getHeader(request.headers, \"x-tenant\") || null;\n}\n"],"names":["extractTenantId","request","getHeader"],"mappings":";AAOO,SAASA,gBAAgBC,OAAsC;IAClE,OAAOC,UAAUD,QAAQ,OAAO,EAAE,eAAe;AACrD"}
|
package/auth/index.d.ts
ADDED
package/auth/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AuthenticationError } from "@webiny/api-core/features/security/authentication/AuthenticationContext/index.js";
|
|
2
|
+
import type { IHttpResponse } from "@webiny/api-kernel-core";
|
|
3
|
+
/**
|
|
4
|
+
* The answer to a request whose token an identity provider rejected, for example in
|
|
5
|
+
* `verifyTokenClaims`. The body carries the error's `Authentication/...` code, which the Admin reads
|
|
6
|
+
* to recognise a bad login. `CorsHeadersDecorator` adds the CORS headers on the way out.
|
|
7
|
+
*/
|
|
8
|
+
export declare function rejectedTokenResponse(error: AuthenticationError): IHttpResponse;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { codedErrorBody } from "@webiny/api-kernel-core";
|
|
2
|
+
function rejectedTokenResponse(error) {
|
|
3
|
+
const body = codedErrorBody(error);
|
|
4
|
+
return {
|
|
5
|
+
statusCode: 401,
|
|
6
|
+
headers: {
|
|
7
|
+
"content-type": "application/json",
|
|
8
|
+
"www-authenticate": 'Bearer error="invalid_token"'
|
|
9
|
+
},
|
|
10
|
+
body
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export { rejectedTokenResponse };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=rejectedTokenResponse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth/rejectedTokenResponse.js","sources":["../../src/auth/rejectedTokenResponse.ts"],"sourcesContent":["import type { AuthenticationError } from \"@webiny/api-core/features/security/authentication/AuthenticationContext/index.js\";\nimport { codedErrorBody } from \"@webiny/api-kernel-core\";\nimport type { IHttpResponse } from \"@webiny/api-kernel-core\";\n\n/**\n * The answer to a request whose token an identity provider rejected, for example in\n * `verifyTokenClaims`. The body carries the error's `Authentication/...` code, which the Admin reads\n * to recognise a bad login. `CorsHeadersDecorator` adds the CORS headers on the way out.\n */\nexport function rejectedTokenResponse(error: AuthenticationError): IHttpResponse {\n const body = codedErrorBody(error);\n\n return {\n statusCode: 401,\n headers: {\n \"content-type\": \"application/json\",\n \"www-authenticate\": 'Bearer error=\"invalid_token\"'\n },\n body\n };\n}\n"],"names":["rejectedTokenResponse","error","body","codedErrorBody"],"mappings":";AASO,SAASA,sBAAsBC,KAA0B;IAC5D,MAAMC,OAAOC,eAAeF;IAE5B,OAAO;QACH,YAAY;QACZ,SAAS;YACL,gBAAgB;YAChB,oBAAoB;QACxB;QACAC;IACJ;AACJ"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Container } from "@webiny/di";
|
|
2
|
+
import { registerBuildParams } from "@webiny/handler";
|
|
3
|
+
import { BuildParams } from "@webiny/api-core/features/buildParams/index.js";
|
|
4
|
+
type Extensions = Parameters<typeof registerBuildParams>[1];
|
|
5
|
+
/**
|
|
6
|
+
* Registers the build params the project was built with, and their reader, in the root container.
|
|
7
|
+
* They come from the deploy, so they are the same for every request and every tenant: request
|
|
8
|
+
* containers and tenant scopes read them from the root. Call it once, in the root, before anything
|
|
9
|
+
* reads them (features gate themselves on `FeatureFlags`, a build param, at register() time).
|
|
10
|
+
*
|
|
11
|
+
* Returns the reader, for a root that needs a setting from them (or wants to check them) before any
|
|
12
|
+
* request runs.
|
|
13
|
+
*/
|
|
14
|
+
export declare function registerRootBuildParams(root: Container, extensions: Extensions): Promise<BuildParams.Interface>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { registerBuildParams } from "@webiny/handler";
|
|
2
|
+
import { BuildParams } from "@webiny/api-core/features/buildParams/index.js";
|
|
3
|
+
import { BuildParamsFeature } from "@webiny/api-core/features/buildParams/feature.js";
|
|
4
|
+
async function registerRootBuildParams(root, extensions) {
|
|
5
|
+
BuildParamsFeature.register(root);
|
|
6
|
+
await registerBuildParams(root, extensions);
|
|
7
|
+
return root.resolve(BuildParams);
|
|
8
|
+
}
|
|
9
|
+
export { registerRootBuildParams };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=registerRootBuildParams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildParams/registerRootBuildParams.js","sources":["../../src/buildParams/registerRootBuildParams.ts"],"sourcesContent":["import type { Container } from \"@webiny/di\";\nimport { registerBuildParams } from \"@webiny/handler\";\nimport { BuildParams } from \"@webiny/api-core/features/buildParams/index.js\";\nimport { BuildParamsFeature } from \"@webiny/api-core/features/buildParams/feature.js\";\n\ntype Extensions = Parameters<typeof registerBuildParams>[1];\n\n/**\n * Registers the build params the project was built with, and their reader, in the root container.\n * They come from the deploy, so they are the same for every request and every tenant: request\n * containers and tenant scopes read them from the root. Call it once, in the root, before anything\n * reads them (features gate themselves on `FeatureFlags`, a build param, at register() time).\n *\n * Returns the reader, for a root that needs a setting from them (or wants to check them) before any\n * request runs.\n */\nexport async function registerRootBuildParams(\n root: Container,\n extensions: Extensions\n): Promise<BuildParams.Interface> {\n BuildParamsFeature.register(root);\n await registerBuildParams(root, extensions);\n return root.resolve(BuildParams);\n}\n"],"names":["registerRootBuildParams","root","extensions","BuildParamsFeature","registerBuildParams","BuildParams"],"mappings":";;;AAgBO,eAAeA,wBAClBC,IAAe,EACfC,UAAsB;IAEtBC,mBAAmB,QAAQ,CAACF;IAC5B,MAAMG,oBAAoBH,MAAMC;IAChC,OAAOD,KAAK,OAAO,CAACI;AACxB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { HttpRouter } from "@webiny/api-kernel-core";
|
|
2
|
+
import type { IHttpRequest } from "@webiny/api-kernel-core";
|
|
3
|
+
import type { IHttpResponse } from "@webiny/api-kernel-core";
|
|
4
|
+
import { RawAssumePermissions } from "@webiny/api-core/features/requestContext/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Reads the `x-webiny-assume-permissions` header, the role or team the Admin is previewing, into
|
|
7
|
+
* RawAssumePermissions. Nothing is checked here: AssumedPermissions checks the caller's real
|
|
8
|
+
* permissions before it honours the header.
|
|
9
|
+
*/
|
|
10
|
+
declare class HttpAssumePermissionsDecoratorImpl implements HttpRouter.Interface {
|
|
11
|
+
private rawAssumePermissions;
|
|
12
|
+
private decoratee;
|
|
13
|
+
constructor(rawAssumePermissions: RawAssumePermissions.Interface, decoratee: HttpRouter.Interface);
|
|
14
|
+
route(request: IHttpRequest): Promise<IHttpResponse>;
|
|
15
|
+
}
|
|
16
|
+
export declare const HttpAssumePermissionsDecorator: typeof HttpAssumePermissionsDecoratorImpl & {
|
|
17
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-kernel-core").IHttpRouter>;
|
|
18
|
+
};
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { HttpRouter } from "@webiny/api-kernel-core";
|
|
2
|
+
import { RawAssumePermissions, extractAssumePermissions } from "@webiny/api-core/features/requestContext/index.js";
|
|
3
|
+
class HttpAssumePermissionsDecoratorImpl {
|
|
4
|
+
constructor(rawAssumePermissions, decoratee){
|
|
5
|
+
this.rawAssumePermissions = rawAssumePermissions;
|
|
6
|
+
this.decoratee = decoratee;
|
|
7
|
+
}
|
|
8
|
+
async route(request) {
|
|
9
|
+
const requested = extractAssumePermissions(request.headers);
|
|
10
|
+
this.rawAssumePermissions.set(requested);
|
|
11
|
+
return this.decoratee.route(request);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const HttpAssumePermissionsDecorator = HttpRouter.createDecorator({
|
|
15
|
+
decorator: HttpAssumePermissionsDecoratorImpl,
|
|
16
|
+
dependencies: [
|
|
17
|
+
RawAssumePermissions
|
|
18
|
+
]
|
|
19
|
+
});
|
|
20
|
+
export { HttpAssumePermissionsDecorator };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=HttpAssumePermissionsDecorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http/HttpAssumePermissionsDecorator.js","sources":["../../src/http/HttpAssumePermissionsDecorator.ts"],"sourcesContent":["import { HttpRouter } from \"@webiny/api-kernel-core\";\nimport type { IHttpRequest } from \"@webiny/api-kernel-core\";\nimport type { IHttpResponse } from \"@webiny/api-kernel-core\";\nimport { RawAssumePermissions } from \"@webiny/api-core/features/requestContext/index.js\";\nimport { extractAssumePermissions } from \"@webiny/api-core/features/requestContext/index.js\";\n\n/**\n * Reads the `x-webiny-assume-permissions` header, the role or team the Admin is previewing, into\n * RawAssumePermissions. Nothing is checked here: AssumedPermissions checks the caller's real\n * permissions before it honours the header.\n */\nclass HttpAssumePermissionsDecoratorImpl implements HttpRouter.Interface {\n constructor(\n private rawAssumePermissions: RawAssumePermissions.Interface,\n private decoratee: HttpRouter.Interface\n ) {}\n\n async route(request: IHttpRequest): Promise<IHttpResponse> {\n const requested = extractAssumePermissions(request.headers);\n this.rawAssumePermissions.set(requested);\n return this.decoratee.route(request);\n }\n}\n\nexport const HttpAssumePermissionsDecorator = HttpRouter.createDecorator({\n decorator: HttpAssumePermissionsDecoratorImpl,\n dependencies: [RawAssumePermissions]\n});\n"],"names":["HttpAssumePermissionsDecoratorImpl","rawAssumePermissions","decoratee","request","requested","extractAssumePermissions","HttpAssumePermissionsDecorator","HttpRouter","RawAssumePermissions"],"mappings":";;AAWA,MAAMA;IACF,YACYC,oBAAoD,EACpDC,SAA+B,CACzC;aAFUD,oBAAoB,GAApBA;aACAC,SAAS,GAATA;IACT;IAEH,MAAM,MAAMC,OAAqB,EAA0B;QACvD,MAAMC,YAAYC,yBAAyBF,QAAQ,OAAO;QAC1D,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAACC;QAC9B,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAACD;IAChC;AACJ;AAEO,MAAMG,iCAAiCC,WAAW,eAAe,CAAC;IACrE,WAAWP;IACX,cAAc;QAACQ;KAAqB;AACxC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { HttpRouteDispatcher } from "@webiny/api-kernel-core";
|
|
2
|
+
import type { IHttpRequest } from "@webiny/api-kernel-core";
|
|
3
|
+
import type { IHttpResponse } from "@webiny/api-kernel-core";
|
|
4
|
+
import { RawAuthToken } from "@webiny/api-core/features/requestContext/index.js";
|
|
5
|
+
import { RequestIdentityLoader } from "@webiny/api-core/features/requestContext/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Runs in the request's tenant scope, as a decorator of `HttpRouteDispatcher`: API-key
|
|
8
|
+
* authentication looks the key up in the tenant, and the identity's permissions are the tenant's.
|
|
9
|
+
*
|
|
10
|
+
* Reads the auth token from the request into RawAuthToken (see {@link extractAuthToken} for the
|
|
11
|
+
* header precedence and when the `wby-id-token` cookie counts), then runs the shared load step,
|
|
12
|
+
* RequestIdentityLoader, which authenticates it and sets IdentityContext. A missing token
|
|
13
|
+
* authenticates as anonymous.
|
|
14
|
+
*
|
|
15
|
+
* A token an identity provider rejects ends the request with a 401. Any other error propagates, and
|
|
16
|
+
* `ErrorResponseDecorator` answers it with a 500.
|
|
17
|
+
*/
|
|
18
|
+
declare class HttpIdentityLoaderDecoratorImpl implements HttpRouteDispatcher.Interface {
|
|
19
|
+
private rawAuthToken;
|
|
20
|
+
private identityLoader;
|
|
21
|
+
private decoratee;
|
|
22
|
+
constructor(rawAuthToken: RawAuthToken.Interface, identityLoader: RequestIdentityLoader.Interface, decoratee: HttpRouteDispatcher.Interface);
|
|
23
|
+
route(request: IHttpRequest): Promise<IHttpResponse>;
|
|
24
|
+
}
|
|
25
|
+
export declare const HttpIdentityLoaderDecorator: typeof HttpIdentityLoaderDecoratorImpl & {
|
|
26
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-kernel-core").IHttpRouter>;
|
|
27
|
+
};
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { HttpRouteDispatcher } from "@webiny/api-kernel-core";
|
|
2
|
+
import { RawAuthToken, RequestIdentityLoader } from "@webiny/api-core/features/requestContext/index.js";
|
|
3
|
+
import { AuthenticationError } from "@webiny/api-core/features/security/authentication/AuthenticationContext/index.js";
|
|
4
|
+
import { extractAuthToken } from "../auth/extractAuthToken.js";
|
|
5
|
+
import { rejectedTokenResponse } from "../auth/rejectedTokenResponse.js";
|
|
6
|
+
class HttpIdentityLoaderDecoratorImpl {
|
|
7
|
+
constructor(rawAuthToken, identityLoader, decoratee){
|
|
8
|
+
this.rawAuthToken = rawAuthToken;
|
|
9
|
+
this.identityLoader = identityLoader;
|
|
10
|
+
this.decoratee = decoratee;
|
|
11
|
+
}
|
|
12
|
+
async route(request) {
|
|
13
|
+
const authToken = extractAuthToken(request);
|
|
14
|
+
this.rawAuthToken.set(authToken);
|
|
15
|
+
try {
|
|
16
|
+
await this.identityLoader.establish();
|
|
17
|
+
} catch (error) {
|
|
18
|
+
if (error instanceof AuthenticationError) return rejectedTokenResponse(error);
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
return this.decoratee.route(request);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const HttpIdentityLoaderDecorator = HttpRouteDispatcher.createDecorator({
|
|
25
|
+
decorator: HttpIdentityLoaderDecoratorImpl,
|
|
26
|
+
dependencies: [
|
|
27
|
+
RawAuthToken,
|
|
28
|
+
RequestIdentityLoader
|
|
29
|
+
]
|
|
30
|
+
});
|
|
31
|
+
export { HttpIdentityLoaderDecorator };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=HttpIdentityLoaderDecorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http/HttpIdentityLoaderDecorator.js","sources":["../../src/http/HttpIdentityLoaderDecorator.ts"],"sourcesContent":["import { HttpRouteDispatcher } from \"@webiny/api-kernel-core\";\nimport type { IHttpRequest } from \"@webiny/api-kernel-core\";\nimport type { IHttpResponse } from \"@webiny/api-kernel-core\";\nimport { RawAuthToken } from \"@webiny/api-core/features/requestContext/index.js\";\nimport { RequestIdentityLoader } from \"@webiny/api-core/features/requestContext/index.js\";\nimport { AuthenticationError } from \"@webiny/api-core/features/security/authentication/AuthenticationContext/index.js\";\nimport { extractAuthToken } from \"~/auth/extractAuthToken.js\";\nimport { rejectedTokenResponse } from \"~/auth/rejectedTokenResponse.js\";\n\n/**\n * Runs in the request's tenant scope, as a decorator of `HttpRouteDispatcher`: API-key\n * authentication looks the key up in the tenant, and the identity's permissions are the tenant's.\n *\n * Reads the auth token from the request into RawAuthToken (see {@link extractAuthToken} for the\n * header precedence and when the `wby-id-token` cookie counts), then runs the shared load step,\n * RequestIdentityLoader, which authenticates it and sets IdentityContext. A missing token\n * authenticates as anonymous.\n *\n * A token an identity provider rejects ends the request with a 401. Any other error propagates, and\n * `ErrorResponseDecorator` answers it with a 500.\n */\nclass HttpIdentityLoaderDecoratorImpl implements HttpRouteDispatcher.Interface {\n constructor(\n private rawAuthToken: RawAuthToken.Interface,\n private identityLoader: RequestIdentityLoader.Interface,\n private decoratee: HttpRouteDispatcher.Interface\n ) {}\n\n async route(request: IHttpRequest): Promise<IHttpResponse> {\n /*\n * The method and path decide whether the `wby-id-token` cookie may be used (private file\n * reads only). Every transport hands the router the path with any API Gateway stage prefix\n * already stripped, so this is the path the route matched on.\n */\n const authToken = extractAuthToken(request);\n this.rawAuthToken.set(authToken);\n try {\n await this.identityLoader.establish();\n } catch (error) {\n if (error instanceof AuthenticationError) {\n return rejectedTokenResponse(error);\n }\n throw error;\n }\n return this.decoratee.route(request);\n }\n}\n\nexport const HttpIdentityLoaderDecorator = HttpRouteDispatcher.createDecorator({\n decorator: HttpIdentityLoaderDecoratorImpl,\n dependencies: [RawAuthToken, RequestIdentityLoader]\n});\n"],"names":["HttpIdentityLoaderDecoratorImpl","rawAuthToken","identityLoader","decoratee","request","authToken","extractAuthToken","error","AuthenticationError","rejectedTokenResponse","HttpIdentityLoaderDecorator","HttpRouteDispatcher","RawAuthToken","RequestIdentityLoader"],"mappings":";;;;;AAqBA,MAAMA;IACF,YACYC,YAAoC,EACpCC,cAA+C,EAC/CC,SAAwC,CAClD;aAHUF,YAAY,GAAZA;aACAC,cAAc,GAAdA;aACAC,SAAS,GAATA;IACT;IAEH,MAAM,MAAMC,OAAqB,EAA0B;QAMvD,MAAMC,YAAYC,iBAAiBF;QACnC,IAAI,CAAC,YAAY,CAAC,GAAG,CAACC;QACtB,IAAI;YACA,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS;QACvC,EAAE,OAAOE,OAAO;YACZ,IAAIA,iBAAiBC,qBACjB,OAAOC,sBAAsBF;YAEjC,MAAMA;QACV;QACA,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAACH;IAChC;AACJ;AAEO,MAAMM,8BAA8BC,oBAAoB,eAAe,CAAC;IAC3E,WAAWX;IACX,cAAc;QAACY;QAAcC;KAAsB;AACvD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Abstraction } from "@webiny/di";
|
|
2
|
+
import type { InputChainRunner, InputHandler } from "@webiny/api-kernel-core";
|
|
3
|
+
import { InputTenantSource } from "@webiny/api-core/features/tenancy/TenantScopes/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* An HTTP transport's handler chain runs at request level, in no tenant's scope: the HTTP router
|
|
6
|
+
* answers a CORS preflight there, and enters the request's tenant scope itself, once the tenant is
|
|
7
|
+
* loaded (`HttpTenantScopeRouter`).
|
|
8
|
+
*/
|
|
9
|
+
export declare class HttpInputTenantSource implements InputTenantSource.Interface {
|
|
10
|
+
private readonly inputHandler;
|
|
11
|
+
constructor(inputHandler: Abstraction<InputHandler.Interface>);
|
|
12
|
+
getTenant(request: InputChainRunner.Request): InputTenantSource.Tenant | undefined;
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
class HttpInputTenantSource {
|
|
2
|
+
constructor(inputHandler){
|
|
3
|
+
this.inputHandler = inputHandler;
|
|
4
|
+
}
|
|
5
|
+
getTenant(request) {
|
|
6
|
+
return request.abstraction === this.inputHandler ? "tenant-neutral" : void 0;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export { HttpInputTenantSource };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=HttpInputTenantSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http/HttpInputTenantSource.js","sources":["../../src/http/HttpInputTenantSource.ts"],"sourcesContent":["import type { Abstraction } from \"@webiny/di\";\nimport type { InputChainRunner, InputHandler } from \"@webiny/api-kernel-core\";\nimport { InputTenantSource } from \"@webiny/api-core/features/tenancy/TenantScopes/index.js\";\n\n/**\n * An HTTP transport's handler chain runs at request level, in no tenant's scope: the HTTP router\n * answers a CORS preflight there, and enters the request's tenant scope itself, once the tenant is\n * loaded (`HttpTenantScopeRouter`).\n */\nexport class HttpInputTenantSource implements InputTenantSource.Interface {\n constructor(private readonly inputHandler: Abstraction<InputHandler.Interface>) {}\n\n getTenant(request: InputChainRunner.Request): InputTenantSource.Tenant | undefined {\n return request.abstraction === this.inputHandler ? \"tenant-neutral\" : undefined;\n }\n}\n"],"names":["HttpInputTenantSource","inputHandler","request","undefined"],"mappings":"AASO,MAAMA;IACT,YAA6BC,YAAiD,CAAE;aAAnDA,YAAY,GAAZA;IAAoD;IAEjF,UAAUC,OAAiC,EAAwC;QAC/E,OAAOA,QAAQ,WAAW,KAAK,IAAI,CAAC,YAAY,GAAG,mBAAmBC;IAC1E;AACJ"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets up the previewed permissions and the identity for every HTTP request, on every transport.
|
|
3
|
+
* The tenant step, and the hand-off into the tenant's scope, is `HttpTenantScopeRouter`, which
|
|
4
|
+
* `registerHttpTransport` registers after the transport feature.
|
|
5
|
+
*
|
|
6
|
+
* Register it BEFORE the transport feature (`ApiGatewayFeature`, `FunctionUrlStreamFeature`,
|
|
7
|
+
* `NodeHttpFeature`), which registers `HttpFeature`. A decorator registered earlier sits further
|
|
8
|
+
* inside, so these run inside `CorsHeadersDecorator` and `ErrorResponseDecorator`: their responses and
|
|
9
|
+
* errors get the CORS headers, and a CORS preflight is answered before any of them runs. Registered
|
|
10
|
+
* after it, a rejected token's 401 reaches the browser without CORS headers and reads as a CORS
|
|
11
|
+
* failure.
|
|
12
|
+
*
|
|
13
|
+
* They run in this order: assume-permissions at request level (a raw header value), then the tenant
|
|
14
|
+
* step and the hand-off, then the identity in the tenant's scope. The tenant comes before the
|
|
15
|
+
* identity because API-key authentication looks the key up in the tenant's partition.
|
|
16
|
+
*/
|
|
17
|
+
export declare const HttpRequestContextFeature: {
|
|
18
|
+
name: string;
|
|
19
|
+
register(container: import("@webiny/di").Container): void;
|
|
20
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { HttpIdentityLoaderDecorator } from "./HttpIdentityLoaderDecorator.js";
|
|
3
|
+
import { HttpAssumePermissionsDecorator } from "./HttpAssumePermissionsDecorator.js";
|
|
4
|
+
const HttpRequestContextFeature = createFeature({
|
|
5
|
+
name: "HttpRequestContext",
|
|
6
|
+
register (container) {
|
|
7
|
+
container.registerDecorator(HttpIdentityLoaderDecorator);
|
|
8
|
+
container.registerDecorator(HttpAssumePermissionsDecorator);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
export { HttpRequestContextFeature };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=HttpRequestContextFeature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http/HttpRequestContextFeature.js","sources":["../../src/http/HttpRequestContextFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { HttpIdentityLoaderDecorator } from \"./HttpIdentityLoaderDecorator.js\";\nimport { HttpAssumePermissionsDecorator } from \"./HttpAssumePermissionsDecorator.js\";\n\n/**\n * Sets up the previewed permissions and the identity for every HTTP request, on every transport.\n * The tenant step, and the hand-off into the tenant's scope, is `HttpTenantScopeRouter`, which\n * `registerHttpTransport` registers after the transport feature.\n *\n * Register it BEFORE the transport feature (`ApiGatewayFeature`, `FunctionUrlStreamFeature`,\n * `NodeHttpFeature`), which registers `HttpFeature`. A decorator registered earlier sits further\n * inside, so these run inside `CorsHeadersDecorator` and `ErrorResponseDecorator`: their responses and\n * errors get the CORS headers, and a CORS preflight is answered before any of them runs. Registered\n * after it, a rejected token's 401 reaches the browser without CORS headers and reads as a CORS\n * failure.\n *\n * They run in this order: assume-permissions at request level (a raw header value), then the tenant\n * step and the hand-off, then the identity in the tenant's scope. The tenant comes before the\n * identity because API-key authentication looks the key up in the tenant's partition.\n */\nexport const HttpRequestContextFeature = createFeature({\n name: \"HttpRequestContext\",\n register(container) {\n // Decorates HttpRouteDispatcher, which the hand-off resolves from the tenant's scope.\n container.registerDecorator(HttpIdentityLoaderDecorator);\n // Decorates HttpRouter, at request level.\n container.registerDecorator(HttpAssumePermissionsDecorator);\n }\n});\n"],"names":["HttpRequestContextFeature","createFeature","container","HttpIdentityLoaderDecorator","HttpAssumePermissionsDecorator"],"mappings":";;;AAoBO,MAAMA,4BAA4BC,cAAc;IACnD,MAAM;IACN,UAASC,SAAS;QAEdA,UAAU,iBAAiB,CAACC;QAE5BD,UAAU,iBAAiB,CAACE;IAChC;AACJ"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { HttpRouter } from "@webiny/api-kernel-core";
|
|
2
|
+
import type { IHttpRequest } from "@webiny/api-kernel-core";
|
|
3
|
+
import type { IHttpResponse } from "@webiny/api-kernel-core";
|
|
4
|
+
import { RawTenantId } from "@webiny/api-core/features/requestContext/index.js";
|
|
5
|
+
import { RequestTenantLoader } from "@webiny/api-core/features/requestContext/index.js";
|
|
6
|
+
import { TenantScopes, TenantScopeUsage } from "@webiny/api-core/features/tenancy/TenantScopes/index.js";
|
|
7
|
+
/**
|
|
8
|
+
* The tenant step of an HTTP request, and its hand-off into the tenant's scope. Registered as
|
|
9
|
+
* `HttpRouter`'s implementation, so it runs at request level, inside `HttpRouter`'s decorators
|
|
10
|
+
* (errors, CORS, compression, assume-permissions). A CORS preflight is answered before it runs.
|
|
11
|
+
*
|
|
12
|
+
* It reads the tenant id from the `x-tenant` header (none means the root tenant), loads the tenant
|
|
13
|
+
* from the request's tenant registry, and runs the request's route in that tenant's scope:
|
|
14
|
+
* `HttpRouteDispatcher`, with its decorators (the identity loader), is resolved from the scope. An
|
|
15
|
+
* unknown tenant (`TenantNotFoundError`) or a disabled one fails here, before any scope is built, and
|
|
16
|
+
* `ErrorResponseDecorator` answers it with CORS headers.
|
|
17
|
+
*
|
|
18
|
+
* A streamed body is read in the scope too, and the scope stays in use until it is read. When the
|
|
19
|
+
* request's work in its scope ends, it logs what the request's tenant scopes held.
|
|
20
|
+
*/
|
|
21
|
+
declare class HttpTenantScopeRouterImpl implements HttpRouter.Interface {
|
|
22
|
+
private readonly rawTenantId;
|
|
23
|
+
private readonly tenantLoader;
|
|
24
|
+
private readonly tenantScopes;
|
|
25
|
+
private readonly usage;
|
|
26
|
+
constructor(rawTenantId: RawTenantId.Interface, tenantLoader: RequestTenantLoader.Interface, tenantScopes: TenantScopes.Interface, usage: TenantScopeUsage.Interface | undefined);
|
|
27
|
+
route(request: IHttpRequest): Promise<IHttpResponse>;
|
|
28
|
+
private routeInScope;
|
|
29
|
+
}
|
|
30
|
+
export declare const HttpTenantScopeRouter: typeof HttpTenantScopeRouterImpl & {
|
|
31
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-kernel-core").IHttpRouter>;
|
|
32
|
+
};
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { HttpRouteDispatcher, HttpRouter, HttpStreamBody } from "@webiny/api-kernel-core";
|
|
2
|
+
import { RawTenantId, RequestTenantLoader } from "@webiny/api-core/features/requestContext/index.js";
|
|
3
|
+
import { TenantScopeUsage, TenantScopes } from "@webiny/api-core/features/tenancy/TenantScopes/index.js";
|
|
4
|
+
import { extractTenantId } from "../auth/extractTenantId.js";
|
|
5
|
+
import { readStreamInScope } from "./readStreamInScope.js";
|
|
6
|
+
class HttpTenantScopeRouterImpl {
|
|
7
|
+
constructor(rawTenantId, tenantLoader, tenantScopes, usage){
|
|
8
|
+
this.rawTenantId = rawTenantId;
|
|
9
|
+
this.tenantLoader = tenantLoader;
|
|
10
|
+
this.tenantScopes = tenantScopes;
|
|
11
|
+
this.usage = usage;
|
|
12
|
+
}
|
|
13
|
+
async route(request) {
|
|
14
|
+
this.rawTenantId.set(extractTenantId(request));
|
|
15
|
+
const tenant = await this.tenantLoader.establish();
|
|
16
|
+
let streamed = ()=>{};
|
|
17
|
+
const streamResponse = new Promise((resolve)=>{
|
|
18
|
+
streamed = resolve;
|
|
19
|
+
});
|
|
20
|
+
const inScope = this.routeInScope(tenant, request, streamed).finally(()=>{
|
|
21
|
+
this.usage?.report();
|
|
22
|
+
});
|
|
23
|
+
return Promise.race([
|
|
24
|
+
inScope,
|
|
25
|
+
streamResponse
|
|
26
|
+
]);
|
|
27
|
+
}
|
|
28
|
+
routeInScope(tenant, request, streamed) {
|
|
29
|
+
return this.tenantScopes.withTenant(tenant, async (scope)=>{
|
|
30
|
+
const response = await scope.resolve(HttpRouteDispatcher).route(request);
|
|
31
|
+
if (!HttpStreamBody.is(response.body)) return response;
|
|
32
|
+
return new Promise((resolve)=>{
|
|
33
|
+
const body = readStreamInScope(response.body, ()=>resolve(response));
|
|
34
|
+
streamed({
|
|
35
|
+
...response,
|
|
36
|
+
body
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const HttpTenantScopeRouter = HttpRouter.createImplementation({
|
|
43
|
+
implementation: HttpTenantScopeRouterImpl,
|
|
44
|
+
dependencies: [
|
|
45
|
+
RawTenantId,
|
|
46
|
+
RequestTenantLoader,
|
|
47
|
+
TenantScopes,
|
|
48
|
+
[
|
|
49
|
+
TenantScopeUsage,
|
|
50
|
+
{
|
|
51
|
+
optional: true
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
]
|
|
55
|
+
});
|
|
56
|
+
export { HttpTenantScopeRouter };
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=HttpTenantScopeRouter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http/HttpTenantScopeRouter.js","sources":["../../src/http/HttpTenantScopeRouter.ts"],"sourcesContent":["import { HttpRouteDispatcher, HttpRouter, HttpStreamBody } from \"@webiny/api-kernel-core\";\nimport type { IHttpRequest } from \"@webiny/api-kernel-core\";\nimport type { IHttpResponse } from \"@webiny/api-kernel-core\";\nimport { RawTenantId } from \"@webiny/api-core/features/requestContext/index.js\";\nimport { RequestTenantLoader } from \"@webiny/api-core/features/requestContext/index.js\";\nimport {\n TenantScopes,\n TenantScopeUsage\n} from \"@webiny/api-core/features/tenancy/TenantScopes/index.js\";\nimport type { Tenant } from \"@webiny/api-core/types/tenancy.js\";\nimport { extractTenantId } from \"~/auth/extractTenantId.js\";\nimport { readStreamInScope } from \"./readStreamInScope.js\";\n\n/**\n * The tenant step of an HTTP request, and its hand-off into the tenant's scope. Registered as\n * `HttpRouter`'s implementation, so it runs at request level, inside `HttpRouter`'s decorators\n * (errors, CORS, compression, assume-permissions). A CORS preflight is answered before it runs.\n *\n * It reads the tenant id from the `x-tenant` header (none means the root tenant), loads the tenant\n * from the request's tenant registry, and runs the request's route in that tenant's scope:\n * `HttpRouteDispatcher`, with its decorators (the identity loader), is resolved from the scope. An\n * unknown tenant (`TenantNotFoundError`) or a disabled one fails here, before any scope is built, and\n * `ErrorResponseDecorator` answers it with CORS headers.\n *\n * A streamed body is read in the scope too, and the scope stays in use until it is read. When the\n * request's work in its scope ends, it logs what the request's tenant scopes held.\n */\nclass HttpTenantScopeRouterImpl implements HttpRouter.Interface {\n constructor(\n private readonly rawTenantId: RawTenantId.Interface,\n private readonly tenantLoader: RequestTenantLoader.Interface,\n private readonly tenantScopes: TenantScopes.Interface,\n private readonly usage: TenantScopeUsage.Interface | undefined\n ) {}\n\n async route(request: IHttpRequest): Promise<IHttpResponse> {\n this.rawTenantId.set(extractTenantId(request));\n const tenant = await this.tenantLoader.establish();\n\n let streamed: (response: IHttpResponse) => void = () => {};\n const streamResponse = new Promise<IHttpResponse>(resolve => {\n streamed = resolve;\n });\n\n const inScope = this.routeInScope(tenant, request, streamed).finally(() => {\n this.usage?.report();\n });\n\n // A buffered response once the scope's callback ends, a streamed one as soon as it starts.\n return Promise.race([inScope, streamResponse]);\n }\n\n private routeInScope(\n tenant: Tenant,\n request: IHttpRequest,\n streamed: (response: IHttpResponse) => void\n ): Promise<IHttpResponse> {\n return this.tenantScopes.withTenant(tenant, async scope => {\n const response = await scope.resolve(HttpRouteDispatcher).route(request);\n if (!HttpStreamBody.is(response.body)) {\n return response;\n }\n\n // The callback, and with it the scope's use, lasts until the transport has read the body.\n return new Promise<IHttpResponse>(resolve => {\n const body = readStreamInScope(response.body, () => resolve(response));\n streamed({ ...response, body });\n });\n });\n }\n}\n\nexport const HttpTenantScopeRouter = HttpRouter.createImplementation({\n implementation: HttpTenantScopeRouterImpl,\n dependencies: [\n RawTenantId,\n RequestTenantLoader,\n TenantScopes,\n [TenantScopeUsage, { optional: true }]\n ]\n});\n"],"names":["HttpTenantScopeRouterImpl","rawTenantId","tenantLoader","tenantScopes","usage","request","extractTenantId","tenant","streamed","streamResponse","Promise","resolve","inScope","scope","response","HttpRouteDispatcher","HttpStreamBody","body","readStreamInScope","HttpTenantScopeRouter","HttpRouter","RawTenantId","RequestTenantLoader","TenantScopes","TenantScopeUsage"],"mappings":";;;;;AA2BA,MAAMA;IACF,YACqBC,WAAkC,EAClCC,YAA2C,EAC3CC,YAAoC,EACpCC,KAA6C,CAChE;aAJmBH,WAAW,GAAXA;aACAC,YAAY,GAAZA;aACAC,YAAY,GAAZA;aACAC,KAAK,GAALA;IAClB;IAEH,MAAM,MAAMC,OAAqB,EAA0B;QACvD,IAAI,CAAC,WAAW,CAAC,GAAG,CAACC,gBAAgBD;QACrC,MAAME,SAAS,MAAM,IAAI,CAAC,YAAY,CAAC,SAAS;QAEhD,IAAIC,WAA8C,KAAO;QACzD,MAAMC,iBAAiB,IAAIC,QAAuBC,CAAAA;YAC9CH,WAAWG;QACf;QAEA,MAAMC,UAAU,IAAI,CAAC,YAAY,CAACL,QAAQF,SAASG,UAAU,OAAO,CAAC;YACjE,IAAI,CAAC,KAAK,EAAE;QAChB;QAGA,OAAOE,QAAQ,IAAI,CAAC;YAACE;YAASH;SAAe;IACjD;IAEQ,aACJF,MAAc,EACdF,OAAqB,EACrBG,QAA2C,EACrB;QACtB,OAAO,IAAI,CAAC,YAAY,CAAC,UAAU,CAACD,QAAQ,OAAMM;YAC9C,MAAMC,WAAW,MAAMD,MAAM,OAAO,CAACE,qBAAqB,KAAK,CAACV;YAChE,IAAI,CAACW,eAAe,EAAE,CAACF,SAAS,IAAI,GAChC,OAAOA;YAIX,OAAO,IAAIJ,QAAuBC,CAAAA;gBAC9B,MAAMM,OAAOC,kBAAkBJ,SAAS,IAAI,EAAE,IAAMH,QAAQG;gBAC5DN,SAAS;oBAAE,GAAGM,QAAQ;oBAAEG;gBAAK;YACjC;QACJ;IACJ;AACJ;AAEO,MAAME,wBAAwBC,WAAW,oBAAoB,CAAC;IACjE,gBAAgBpB;IAChB,cAAc;QACVqB;QACAC;QACAC;QACA;YAACC;YAAkB;gBAAE,UAAU;YAAK;SAAE;KACzC;AACL"}
|
package/http/index.d.ts
ADDED
package/http/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { HttpStreamBody } from "@webiny/api-kernel-core";
|
|
2
|
+
/**
|
|
3
|
+
* A streamed body that is read in the tenant scope it was created in.
|
|
4
|
+
*
|
|
5
|
+
* The transport reads a stream after the router has returned, so outside the scope's callback. Its
|
|
6
|
+
* chunks are produced by the route's services (an AI provider, a use case), which belong to the
|
|
7
|
+
* scope and throw `StaleKernelExecutionError` outside it. Call this inside the scope's callback: each
|
|
8
|
+
* read then runs in the async context captured here, the scope's.
|
|
9
|
+
*
|
|
10
|
+
* `onEnd` is called once, when the stream is fully read, fails, or the reader stops early.
|
|
11
|
+
*/
|
|
12
|
+
export declare function readStreamInScope(body: HttpStreamBody, onEnd: () => void): HttpStreamBody;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { HttpStreamBody } from "@webiny/api-kernel-core";
|
|
3
|
+
function readStreamInScope(body, onEnd) {
|
|
4
|
+
const runInScope = AsyncLocalStorage.snapshot();
|
|
5
|
+
let ended = false;
|
|
6
|
+
const end = ()=>{
|
|
7
|
+
if (!ended) {
|
|
8
|
+
ended = true;
|
|
9
|
+
onEnd();
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
return new HttpStreamBody({
|
|
13
|
+
[Symbol.asyncIterator] () {
|
|
14
|
+
const iterator = runInScope(()=>body.source[Symbol.asyncIterator]());
|
|
15
|
+
return {
|
|
16
|
+
async next () {
|
|
17
|
+
try {
|
|
18
|
+
const result = await runInScope(()=>iterator.next());
|
|
19
|
+
if (result.done) end();
|
|
20
|
+
return result;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
end();
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
async return (value) {
|
|
27
|
+
try {
|
|
28
|
+
if (iterator.return) return await runInScope(()=>iterator.return(value));
|
|
29
|
+
return {
|
|
30
|
+
done: true,
|
|
31
|
+
value
|
|
32
|
+
};
|
|
33
|
+
} finally{
|
|
34
|
+
end();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
export { readStreamInScope };
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=readStreamInScope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http/readStreamInScope.js","sources":["../../src/http/readStreamInScope.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport { HttpStreamBody } from \"@webiny/api-kernel-core\";\nimport type { HttpStreamChunk } from \"@webiny/api-kernel-core\";\n\n/**\n * A streamed body that is read in the tenant scope it was created in.\n *\n * The transport reads a stream after the router has returned, so outside the scope's callback. Its\n * chunks are produced by the route's services (an AI provider, a use case), which belong to the\n * scope and throw `StaleKernelExecutionError` outside it. Call this inside the scope's callback: each\n * read then runs in the async context captured here, the scope's.\n *\n * `onEnd` is called once, when the stream is fully read, fails, or the reader stops early.\n */\nexport function readStreamInScope(body: HttpStreamBody, onEnd: () => void): HttpStreamBody {\n const runInScope = AsyncLocalStorage.snapshot();\n\n let ended = false;\n const end = () => {\n if (!ended) {\n ended = true;\n onEnd();\n }\n };\n\n return new HttpStreamBody({\n [Symbol.asyncIterator](): AsyncIterator<HttpStreamChunk> {\n const iterator = runInScope(() => body.source[Symbol.asyncIterator]());\n return {\n async next() {\n try {\n const result = await runInScope(() => iterator.next());\n if (result.done) {\n end();\n }\n return result;\n } catch (error) {\n end();\n throw error;\n }\n },\n async return(value?: any) {\n try {\n if (iterator.return) {\n return await runInScope(() => iterator.return!(value));\n }\n return { done: true, value };\n } finally {\n end();\n }\n }\n };\n }\n });\n}\n"],"names":["readStreamInScope","body","onEnd","runInScope","AsyncLocalStorage","ended","end","HttpStreamBody","Symbol","iterator","result","error","value"],"mappings":";;AAcO,SAASA,kBAAkBC,IAAoB,EAAEC,KAAiB;IACrE,MAAMC,aAAaC,kBAAkB,QAAQ;IAE7C,IAAIC,QAAQ;IACZ,MAAMC,MAAM;QACR,IAAI,CAACD,OAAO;YACRA,QAAQ;YACRH;QACJ;IACJ;IAEA,OAAO,IAAIK,eAAe;QACtB,CAACC,OAAO,aAAa,CAAC;YAClB,MAAMC,WAAWN,WAAW,IAAMF,KAAK,MAAM,CAACO,OAAO,aAAa,CAAC;YACnE,OAAO;gBACH,MAAM;oBACF,IAAI;wBACA,MAAME,SAAS,MAAMP,WAAW,IAAMM,SAAS,IAAI;wBACnD,IAAIC,OAAO,IAAI,EACXJ;wBAEJ,OAAOI;oBACX,EAAE,OAAOC,OAAO;wBACZL;wBACA,MAAMK;oBACV;gBACJ;gBACA,MAAM,QAAOC,KAAW;oBACpB,IAAI;wBACA,IAAIH,SAAS,MAAM,EACf,OAAO,MAAMN,WAAW,IAAMM,SAAS,MAAM,CAAEG;wBAEnD,OAAO;4BAAE,MAAM;4BAAMA;wBAAM;oBAC/B,SAAU;wBACNN;oBACJ;gBACJ;YACJ;QACJ;IACJ;AACJ"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Abstraction, Container } from "@webiny/di";
|
|
2
|
+
import type { InputHandler } from "@webiny/api-kernel-core";
|
|
3
|
+
export interface IHttpTransportFeature {
|
|
4
|
+
register(container: Container): void;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Registers an HTTP transport feature (`ApiGatewayFeature`, `FunctionUrlStreamFeature`,
|
|
8
|
+
* `NodeHttpFeature`) together with the tenant, identity and assume-permissions loading every API
|
|
9
|
+
* request needs, in the one order that works. `inputHandler` is the transport's handler abstraction
|
|
10
|
+
* (`ApiGatewayInputHandler`, β¦).
|
|
11
|
+
*
|
|
12
|
+
* The request is handled at request level first, in no tenant's scope: compression, CORS, error
|
|
13
|
+
* responses, assume-permissions, then the tenant step. A CORS preflight is answered there, and an
|
|
14
|
+
* unknown or disabled tenant fails there, without building a scope. Only then does the request enter
|
|
15
|
+
* its tenant's scope (`HttpTenantScopeRouter`), where the identity loads and the route runs.
|
|
16
|
+
*
|
|
17
|
+
* `HttpRequestContextFeature` has to be registered first. A decorator registered earlier sits further
|
|
18
|
+
* inside, so its decorators then run inside `ErrorResponseDecorator` and `CorsHeadersDecorator`, which
|
|
19
|
+
* the transport feature registers through `HttpFeature`, and their responses and errors get the CORS
|
|
20
|
+
* headers. In the other order, a rejected token's 401 reaches the browser without them and reads as a
|
|
21
|
+
* CORS failure, and nothing else breaks to show it.
|
|
22
|
+
*/
|
|
23
|
+
export declare function registerHttpTransport(container: Container, transport: IHttpTransportFeature, inputHandler: Abstraction<InputHandler.Interface>): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { InputTenantSource } from "@webiny/api-core/features/tenancy/TenantScopes/index.js";
|
|
2
|
+
import { HttpRequestContextFeature } from "./HttpRequestContextFeature.js";
|
|
3
|
+
import { HttpTenantScopeRouter } from "./HttpTenantScopeRouter.js";
|
|
4
|
+
import { HttpInputTenantSource } from "./HttpInputTenantSource.js";
|
|
5
|
+
function registerHttpTransport(container, transport, inputHandler) {
|
|
6
|
+
HttpRequestContextFeature.register(container);
|
|
7
|
+
transport.register(container);
|
|
8
|
+
container.register(HttpTenantScopeRouter);
|
|
9
|
+
container.registerInstance(InputTenantSource, new HttpInputTenantSource(inputHandler));
|
|
10
|
+
}
|
|
11
|
+
export { registerHttpTransport };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=registerHttpTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http/registerHttpTransport.js","sources":["../../src/http/registerHttpTransport.ts"],"sourcesContent":["import type { Abstraction, Container } from \"@webiny/di\";\nimport type { InputHandler } from \"@webiny/api-kernel-core\";\nimport { InputTenantSource } from \"@webiny/api-core/features/tenancy/TenantScopes/index.js\";\nimport { HttpRequestContextFeature } from \"./HttpRequestContextFeature.js\";\nimport { HttpTenantScopeRouter } from \"./HttpTenantScopeRouter.js\";\nimport { HttpInputTenantSource } from \"./HttpInputTenantSource.js\";\n\nexport interface IHttpTransportFeature {\n register(container: Container): void;\n}\n\n/**\n * Registers an HTTP transport feature (`ApiGatewayFeature`, `FunctionUrlStreamFeature`,\n * `NodeHttpFeature`) together with the tenant, identity and assume-permissions loading every API\n * request needs, in the one order that works. `inputHandler` is the transport's handler abstraction\n * (`ApiGatewayInputHandler`, β¦).\n *\n * The request is handled at request level first, in no tenant's scope: compression, CORS, error\n * responses, assume-permissions, then the tenant step. A CORS preflight is answered there, and an\n * unknown or disabled tenant fails there, without building a scope. Only then does the request enter\n * its tenant's scope (`HttpTenantScopeRouter`), where the identity loads and the route runs.\n *\n * `HttpRequestContextFeature` has to be registered first. A decorator registered earlier sits further\n * inside, so its decorators then run inside `ErrorResponseDecorator` and `CorsHeadersDecorator`, which\n * the transport feature registers through `HttpFeature`, and their responses and errors get the CORS\n * headers. In the other order, a rejected token's 401 reaches the browser without them and reads as a\n * CORS failure, and nothing else breaks to show it.\n */\nexport function registerHttpTransport(\n container: Container,\n transport: IHttpTransportFeature,\n inputHandler: Abstraction<InputHandler.Interface>\n): void {\n HttpRequestContextFeature.register(container);\n transport.register(container);\n // Registered after HttpFeature, so it replaces the route matcher as HttpRouter's implementation.\n container.register(HttpTenantScopeRouter);\n // The transport's handler chain stays at request level; the router enters the tenant's scope.\n container.registerInstance(InputTenantSource, new HttpInputTenantSource(inputHandler));\n}\n"],"names":["registerHttpTransport","container","transport","inputHandler","HttpRequestContextFeature","HttpTenantScopeRouter","InputTenantSource","HttpInputTenantSource"],"mappings":";;;;AA4BO,SAASA,sBACZC,SAAoB,EACpBC,SAAgC,EAChCC,YAAiD;IAEjDC,0BAA0B,QAAQ,CAACH;IACnCC,UAAU,QAAQ,CAACD;IAEnBA,UAAU,QAAQ,CAACI;IAEnBJ,UAAU,gBAAgB,CAACK,mBAAmB,IAAIC,sBAAsBJ;AAC5E"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Container } from "@webiny/di";
|
|
2
|
+
export declare class AllowedRequestHeadersError extends Error {
|
|
3
|
+
constructor(cause: unknown);
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Registers, in the root container, the request headers the project's extensions allow in the CORS
|
|
7
|
+
* preflight answer (`HttpAllowedRequestHeaders`), as one list.
|
|
8
|
+
*
|
|
9
|
+
* `CorsHeadersDecorator` answers a preflight at request level, before any tenant scope exists, but
|
|
10
|
+
* extensions register in each tenant scope, where it can't see them. The list comes from the deploy's
|
|
11
|
+
* code and a preflight carries no tenant, so it is the same for every request and tenant: it is read
|
|
12
|
+
* once per process, when the root container is built (a Lambda's cold start, the standalone server's
|
|
13
|
+
* start).
|
|
14
|
+
*
|
|
15
|
+
* An extension registers everything in one callback, and may use what a request has while it
|
|
16
|
+
* registers (feature flags, for one). So a throwaway child of the root gets what a request has, the
|
|
17
|
+
* extensions included (`ApiRequestRegistration`), the allowed headers are read from it, and it is
|
|
18
|
+
* dropped. Registration is lazy: only the allowed-headers implementations are built there, with no
|
|
19
|
+
* tenant and no identity, so they must not depend on either: one that can't be built fails the start.
|
|
20
|
+
*
|
|
21
|
+
* A request's registration that fails there would fail every request the same way, which reports it.
|
|
22
|
+
* Here it is logged as a warning, and only the headers registered before it failed are allowed.
|
|
23
|
+
*
|
|
24
|
+
* Call it last in the root, once `ApiRequestRegistration` and the root's services are registered.
|
|
25
|
+
*/
|
|
26
|
+
export declare function registerRootAllowedRequestHeaders(root: Container): Promise<void>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { HttpAllowedRequestHeaders } from "@webiny/api-kernel-core";
|
|
2
|
+
import { Logger } from "@webiny/api-core/features/logger/index.js";
|
|
3
|
+
import { ApiRequestRegistration } from "../requestRegistration/index.js";
|
|
4
|
+
class AllowedRequestHeadersError extends Error {
|
|
5
|
+
constructor(cause){
|
|
6
|
+
const reason = cause instanceof Error ? cause.message : String(cause);
|
|
7
|
+
super([
|
|
8
|
+
"Could not read the request headers the project's extensions allow in CORS (HttpAllowedRequestHeaders).",
|
|
9
|
+
"They are read once per process, at start, in a container that has a request's services but no",
|
|
10
|
+
`tenant and no identity. ${reason}`
|
|
11
|
+
].join(" "), {
|
|
12
|
+
cause
|
|
13
|
+
});
|
|
14
|
+
this.name = "AllowedRequestHeadersError";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async function registerRootAllowedRequestHeaders(root) {
|
|
18
|
+
const throwaway = root.createChildContainer();
|
|
19
|
+
try {
|
|
20
|
+
await root.resolve(ApiRequestRegistration).register(throwaway);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
const [logger] = root.resolveAll(Logger);
|
|
23
|
+
logger?.warn({
|
|
24
|
+
error: error instanceof Error ? error.message : String(error)
|
|
25
|
+
}, "[cors] Registering a request's services failed while the CORS allowed headers were read, at start. Only headers registered before the failure are allowed.");
|
|
26
|
+
}
|
|
27
|
+
let headers;
|
|
28
|
+
try {
|
|
29
|
+
headers = throwaway.resolveAll(HttpAllowedRequestHeaders).flatMap((item)=>item.headers);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
throw new AllowedRequestHeadersError(error);
|
|
32
|
+
}
|
|
33
|
+
root.registerInstance(HttpAllowedRequestHeaders, {
|
|
34
|
+
headers
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export { AllowedRequestHeadersError, registerRootAllowedRequestHeaders };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=registerRootAllowedRequestHeaders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http/registerRootAllowedRequestHeaders.js","sources":["../../src/http/registerRootAllowedRequestHeaders.ts"],"sourcesContent":["import type { Container } from \"@webiny/di\";\nimport { HttpAllowedRequestHeaders } from \"@webiny/api-kernel-core\";\nimport { Logger } from \"@webiny/api-core/features/logger/index.js\";\nimport { ApiRequestRegistration } from \"~/requestRegistration/index.js\";\n\nexport class AllowedRequestHeadersError extends Error {\n constructor(cause: unknown) {\n const reason = cause instanceof Error ? cause.message : String(cause);\n super(\n [\n `Could not read the request headers the project's extensions allow in CORS (HttpAllowedRequestHeaders).`,\n `They are read once per process, at start, in a container that has a request's services but no`,\n `tenant and no identity. ${reason}`\n ].join(\" \"),\n { cause }\n );\n this.name = \"AllowedRequestHeadersError\";\n }\n}\n\n/**\n * Registers, in the root container, the request headers the project's extensions allow in the CORS\n * preflight answer (`HttpAllowedRequestHeaders`), as one list.\n *\n * `CorsHeadersDecorator` answers a preflight at request level, before any tenant scope exists, but\n * extensions register in each tenant scope, where it can't see them. The list comes from the deploy's\n * code and a preflight carries no tenant, so it is the same for every request and tenant: it is read\n * once per process, when the root container is built (a Lambda's cold start, the standalone server's\n * start).\n *\n * An extension registers everything in one callback, and may use what a request has while it\n * registers (feature flags, for one). So a throwaway child of the root gets what a request has, the\n * extensions included (`ApiRequestRegistration`), the allowed headers are read from it, and it is\n * dropped. Registration is lazy: only the allowed-headers implementations are built there, with no\n * tenant and no identity, so they must not depend on either: one that can't be built fails the start.\n *\n * A request's registration that fails there would fail every request the same way, which reports it.\n * Here it is logged as a warning, and only the headers registered before it failed are allowed.\n *\n * Call it last in the root, once `ApiRequestRegistration` and the root's services are registered.\n */\nexport async function registerRootAllowedRequestHeaders(root: Container): Promise<void> {\n const throwaway = root.createChildContainer();\n try {\n await root.resolve(ApiRequestRegistration).register(throwaway);\n } catch (error) {\n const [logger] = root.resolveAll(Logger);\n logger?.warn(\n { error: error instanceof Error ? error.message : String(error) },\n \"[cors] Registering a request's services failed while the CORS allowed headers were read, at start. Only headers registered before the failure are allowed.\"\n );\n }\n\n let headers: string[];\n try {\n headers = throwaway.resolveAll(HttpAllowedRequestHeaders).flatMap(item => item.headers);\n } catch (error) {\n throw new AllowedRequestHeadersError(error);\n }\n root.registerInstance(HttpAllowedRequestHeaders, { headers });\n}\n"],"names":["AllowedRequestHeadersError","Error","cause","reason","String","registerRootAllowedRequestHeaders","root","throwaway","ApiRequestRegistration","error","logger","Logger","headers","HttpAllowedRequestHeaders","item"],"mappings":";;;AAKO,MAAMA,mCAAmCC;IAC5C,YAAYC,KAAc,CAAE;QACxB,MAAMC,SAASD,iBAAiBD,QAAQC,MAAM,OAAO,GAAGE,OAAOF;QAC/D,KAAK,CACD;YACI;YACA;YACA,CAAC,wBAAwB,EAAEC,QAAQ;SACtC,CAAC,IAAI,CAAC,MACP;YAAED;QAAM;QAEZ,IAAI,CAAC,IAAI,GAAG;IAChB;AACJ;AAuBO,eAAeG,kCAAkCC,IAAe;IACnE,MAAMC,YAAYD,KAAK,oBAAoB;IAC3C,IAAI;QACA,MAAMA,KAAK,OAAO,CAACE,wBAAwB,QAAQ,CAACD;IACxD,EAAE,OAAOE,OAAO;QACZ,MAAM,CAACC,OAAO,GAAGJ,KAAK,UAAU,CAACK;QACjCD,QAAQ,KACJ;YAAE,OAAOD,iBAAiBR,QAAQQ,MAAM,OAAO,GAAGL,OAAOK;QAAO,GAChE;IAER;IAEA,IAAIG;IACJ,IAAI;QACAA,UAAUL,UAAU,UAAU,CAACM,2BAA2B,OAAO,CAACC,CAAAA,OAAQA,KAAK,OAAO;IAC1F,EAAE,OAAOL,OAAO;QACZ,MAAM,IAAIT,2BAA2BS;IACzC;IACAH,KAAK,gBAAgB,CAACO,2BAA2B;QAAED;IAAQ;AAC/D"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { registerApiRequestStack, registerApiRequestStackInOneContainer, registerApiTenantScope } from "./registerApiRequestStack.js";
|
|
2
|
+
export type { RegisterApiRequestStackConfig } from "./registerApiRequestStack.js";
|
|
3
|
+
export { createLogger } from "./logger/createLogger.js";
|
|
4
|
+
export { extractAuthToken, isCookieAuthenticationAllowed } from "./auth/index.js";
|
|
5
|
+
export { extractTenantId } from "./auth/index.js";
|
|
6
|
+
export { registerHttpTransport, registerRootAllowedRequestHeaders, AllowedRequestHeadersError } from "./http/index.js";
|
|
7
|
+
export type { IHttpTransportFeature } from "./http/index.js";
|
|
8
|
+
export { registerRootBuildParams } from "./buildParams/registerRootBuildParams.js";
|
|
9
|
+
export { ApiRequestRegistration } from "./requestRegistration/index.js";
|
package/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { registerApiRequestStack, registerApiRequestStackInOneContainer, registerApiTenantScope } from "./registerApiRequestStack.js";
|
|
2
|
+
export { createLogger } from "./logger/createLogger.js";
|
|
3
|
+
export { extractAuthToken, extractTenantId, isCookieAuthenticationAllowed } from "./auth/index.js";
|
|
4
|
+
export { AllowedRequestHeadersError, registerHttpTransport, registerRootAllowedRequestHeaders } from "./http/index.js";
|
|
5
|
+
export { registerRootBuildParams } from "./buildParams/registerRootBuildParams.js";
|
|
6
|
+
export { ApiRequestRegistration } from "./requestRegistration/index.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Logger as PinoInstance } from "pino";
|
|
2
|
+
import type { Logger } from "@webiny/api-core/features/logger/index.js";
|
|
3
|
+
export declare class PinoLogger implements Logger.Interface {
|
|
4
|
+
private readonly pinoLogger;
|
|
5
|
+
constructor(pinoLogger: PinoInstance);
|
|
6
|
+
trace(objOrMsg: object | string, ...args: any[]): void;
|
|
7
|
+
debug(objOrMsg: object | string, ...args: any[]): void;
|
|
8
|
+
info(objOrMsg: object | string, ...args: any[]): void;
|
|
9
|
+
warn(objOrMsg: object | string, ...args: any[]): void;
|
|
10
|
+
error(objOrMsg: object | string, ...args: any[]): void;
|
|
11
|
+
fatal(objOrMsg: object | string, ...args: any[]): void;
|
|
12
|
+
log(objOrMsg: object | string, ...args: any[]): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
class PinoLogger {
|
|
2
|
+
constructor(pinoLogger){
|
|
3
|
+
this.pinoLogger = pinoLogger;
|
|
4
|
+
}
|
|
5
|
+
trace(objOrMsg, ...args) {
|
|
6
|
+
this.pinoLogger.trace(objOrMsg, ...args);
|
|
7
|
+
}
|
|
8
|
+
debug(objOrMsg, ...args) {
|
|
9
|
+
this.pinoLogger.debug(objOrMsg, ...args);
|
|
10
|
+
}
|
|
11
|
+
info(objOrMsg, ...args) {
|
|
12
|
+
this.pinoLogger.info(objOrMsg, ...args);
|
|
13
|
+
}
|
|
14
|
+
warn(objOrMsg, ...args) {
|
|
15
|
+
this.pinoLogger.warn(objOrMsg, ...args);
|
|
16
|
+
}
|
|
17
|
+
error(objOrMsg, ...args) {
|
|
18
|
+
this.pinoLogger.error(objOrMsg, ...args);
|
|
19
|
+
}
|
|
20
|
+
fatal(objOrMsg, ...args) {
|
|
21
|
+
this.pinoLogger.fatal(objOrMsg, ...args);
|
|
22
|
+
}
|
|
23
|
+
log(objOrMsg, ...args) {
|
|
24
|
+
this.pinoLogger.info(objOrMsg, ...args);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export { PinoLogger };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=PinoLogger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger/PinoLogger.js","sources":["../../src/logger/PinoLogger.ts"],"sourcesContent":["import type { Logger as PinoInstance } from \"pino\";\nimport type { Logger } from \"@webiny/api-core/features/logger/index.js\";\n\n// A `Logger` that writes through one pino instance.\nexport class PinoLogger implements Logger.Interface {\n public constructor(private readonly pinoLogger: PinoInstance) {}\n\n public trace(objOrMsg: object | string, ...args: any[]) {\n this.pinoLogger.trace(objOrMsg, ...args);\n }\n\n public debug(objOrMsg: object | string, ...args: any[]) {\n this.pinoLogger.debug(objOrMsg, ...args);\n }\n\n public info(objOrMsg: object | string, ...args: any[]) {\n this.pinoLogger.info(objOrMsg, ...args);\n }\n\n public warn(objOrMsg: object | string, ...args: any[]) {\n this.pinoLogger.warn(objOrMsg, ...args);\n }\n\n public error(objOrMsg: object | string, ...args: any[]) {\n this.pinoLogger.error(objOrMsg, ...args);\n }\n\n public fatal(objOrMsg: object | string, ...args: any[]) {\n this.pinoLogger.fatal(objOrMsg, ...args);\n }\n\n public log(objOrMsg: object | string, ...args: any[]) {\n this.pinoLogger.info(objOrMsg, ...args);\n }\n}\n"],"names":["PinoLogger","pinoLogger","objOrMsg","args"],"mappings":"AAIO,MAAMA;IACT,YAAoCC,UAAwB,CAAE;aAA1BA,UAAU,GAAVA;IAA2B;IAExD,MAAMC,QAAyB,EAAE,GAAGC,IAAW,EAAE;QACpD,IAAI,CAAC,UAAU,CAAC,KAAK,CAACD,aAAaC;IACvC;IAEO,MAAMD,QAAyB,EAAE,GAAGC,IAAW,EAAE;QACpD,IAAI,CAAC,UAAU,CAAC,KAAK,CAACD,aAAaC;IACvC;IAEO,KAAKD,QAAyB,EAAE,GAAGC,IAAW,EAAE;QACnD,IAAI,CAAC,UAAU,CAAC,IAAI,CAACD,aAAaC;IACtC;IAEO,KAAKD,QAAyB,EAAE,GAAGC,IAAW,EAAE;QACnD,IAAI,CAAC,UAAU,CAAC,IAAI,CAACD,aAAaC;IACtC;IAEO,MAAMD,QAAyB,EAAE,GAAGC,IAAW,EAAE;QACpD,IAAI,CAAC,UAAU,CAAC,KAAK,CAACD,aAAaC;IACvC;IAEO,MAAMD,QAAyB,EAAE,GAAGC,IAAW,EAAE;QACpD,IAAI,CAAC,UAAU,CAAC,KAAK,CAACD,aAAaC;IACvC;IAEO,IAAID,QAAyB,EAAE,GAAGC,IAAW,EAAE;QAClD,IAAI,CAAC,UAAU,CAAC,IAAI,CAACD,aAAaC;IACtC;AACJ"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DestinationStream } from "pino";
|
|
2
|
+
import type { Logger } from "@webiny/api-core/features/logger/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* A Logger at the level `WEBINY_API_LOG_LEVEL` sets, writing to `destination`, or to stdout without
|
|
5
|
+
* one. Each event handler builds one at boot with its hosting type's destination: pino-lambda on AWS,
|
|
6
|
+
* plain stdout on a standalone server.
|
|
7
|
+
*
|
|
8
|
+
* `lineContext` returns fields every line carries, such as the id of the request that wrote it. It
|
|
9
|
+
* runs when the line is logged, in the caller's async context, so it can read which request is
|
|
10
|
+
* running. Its fields win over a log call's own fields of the same name: a line can't claim to
|
|
11
|
+
* belong to another request.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createLogger(destination?: DestinationStream, lineContext?: () => object): Logger.Interface;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { pino } from "pino";
|
|
2
|
+
import { PinoLogger } from "./PinoLogger.js";
|
|
3
|
+
const DEFAULT_LOG_LEVEL = "info";
|
|
4
|
+
function serializeError(error) {
|
|
5
|
+
try {
|
|
6
|
+
return pino.stdSerializers.err(error);
|
|
7
|
+
} catch {
|
|
8
|
+
return {
|
|
9
|
+
type: error.name,
|
|
10
|
+
message: error.message,
|
|
11
|
+
stack: error.stack
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function createLogger(destination, lineContext) {
|
|
16
|
+
const options = {
|
|
17
|
+
level: process.env.WEBINY_API_LOG_LEVEL || DEFAULT_LOG_LEVEL,
|
|
18
|
+
mixin: lineContext,
|
|
19
|
+
mixinMergeStrategy: (mergeObject, mixinObject)=>({
|
|
20
|
+
...mergeObject,
|
|
21
|
+
...mixinObject
|
|
22
|
+
}),
|
|
23
|
+
serializers: {
|
|
24
|
+
error: serializeError
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
if (destination) {
|
|
28
|
+
const pinoLogger = pino(options, destination);
|
|
29
|
+
return new PinoLogger(pinoLogger);
|
|
30
|
+
}
|
|
31
|
+
const pinoLogger = pino(options);
|
|
32
|
+
return new PinoLogger(pinoLogger);
|
|
33
|
+
}
|
|
34
|
+
export { createLogger };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=createLogger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger/createLogger.js","sources":["../../src/logger/createLogger.ts"],"sourcesContent":["import { pino } from \"pino\";\nimport type { DestinationStream } from \"pino\";\nimport type { LoggerOptions } from \"pino\";\nimport type { Logger } from \"@webiny/api-core/features/logger/index.js\";\nimport { PinoLogger } from \"./PinoLogger.js\";\n\nconst DEFAULT_LOG_LEVEL = \"info\";\n\n/*\n * pino's serializer marks each error it visits to detect cycles, which throws on a frozen error.\n * Logging must never throw, so that case falls back to the fields a reader needs.\n */\nfunction serializeError(error: Error) {\n try {\n return pino.stdSerializers.err(error);\n } catch {\n return {\n type: error.name,\n message: error.message,\n stack: error.stack\n };\n }\n}\n\n/**\n * A Logger at the level `WEBINY_API_LOG_LEVEL` sets, writing to `destination`, or to stdout without\n * one. Each event handler builds one at boot with its hosting type's destination: pino-lambda on AWS,\n * plain stdout on a standalone server.\n *\n * `lineContext` returns fields every line carries, such as the id of the request that wrote it. It\n * runs when the line is logged, in the caller's async context, so it can read which request is\n * running. Its fields win over a log call's own fields of the same name: a line can't claim to\n * belong to another request.\n */\nexport function createLogger(\n destination?: DestinationStream,\n lineContext?: () => object\n): Logger.Interface {\n const options: LoggerOptions = {\n level: process.env.WEBINY_API_LOG_LEVEL || DEFAULT_LOG_LEVEL,\n mixin: lineContext,\n // pino's default lets the log call's fields win, and writes them into the mixin's object.\n mixinMergeStrategy: (mergeObject, mixinObject) => {\n return { ...mergeObject, ...mixinObject };\n },\n /*\n * pino only serializes an Error under `err`. Backend code logs `{ error }`, which without\n * this prints `{}`, with no message or stack.\n */\n serializers: {\n error: serializeError\n }\n };\n if (destination) {\n const pinoLogger = pino(options, destination);\n return new PinoLogger(pinoLogger);\n }\n const pinoLogger = pino(options);\n return new PinoLogger(pinoLogger);\n}\n"],"names":["DEFAULT_LOG_LEVEL","serializeError","error","pino","createLogger","destination","lineContext","options","process","mergeObject","mixinObject","pinoLogger","PinoLogger"],"mappings":";;AAMA,MAAMA,oBAAoB;AAM1B,SAASC,eAAeC,KAAY;IAChC,IAAI;QACA,OAAOC,KAAK,cAAc,CAAC,GAAG,CAACD;IACnC,EAAE,OAAM;QACJ,OAAO;YACH,MAAMA,MAAM,IAAI;YAChB,SAASA,MAAM,OAAO;YACtB,OAAOA,MAAM,KAAK;QACtB;IACJ;AACJ;AAYO,SAASE,aACZC,WAA+B,EAC/BC,WAA0B;IAE1B,MAAMC,UAAyB;QAC3B,OAAOC,QAAQ,GAAG,CAAC,oBAAoB,IAAIR;QAC3C,OAAOM;QAEP,oBAAoB,CAACG,aAAaC,cACvB;gBAAE,GAAGD,WAAW;gBAAE,GAAGC,WAAW;YAAC;QAM5C,aAAa;YACT,OAAOT;QACX;IACJ;IACA,IAAII,aAAa;QACb,MAAMM,aAAaR,KAAKI,SAASF;QACjC,OAAO,IAAIO,WAAWD;IAC1B;IACA,MAAMA,aAAaR,KAAKI;IACxB,OAAO,IAAIK,WAAWD;AAC1B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@webiny/api-composition-core",
|
|
3
|
+
"version": "6.6.0-alpha.13",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./index.js",
|
|
8
|
+
"./*": "./*"
|
|
9
|
+
},
|
|
10
|
+
"types": "index.d.ts",
|
|
11
|
+
"description": "Composition of the Webiny API request stack shared by every transport, plus what transports share: auth token extraction and the Node HTTP decorators (`/nodeHttp`) used by the standalone server and the AWS Lambda web function.",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/webiny/webiny-js.git"
|
|
15
|
+
},
|
|
16
|
+
"contributors": [
|
|
17
|
+
"Webiny Team"
|
|
18
|
+
],
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@webiny/api-aco": "6.6.0-alpha.13",
|
|
22
|
+
"@webiny/api-audit-logs": "6.6.0-alpha.13",
|
|
23
|
+
"@webiny/api-core": "6.6.0-alpha.13",
|
|
24
|
+
"@webiny/api-dashboard": "6.6.0-alpha.13",
|
|
25
|
+
"@webiny/api-file-manager": "6.6.0-alpha.13",
|
|
26
|
+
"@webiny/api-file-manager-aco": "6.6.0-alpha.13",
|
|
27
|
+
"@webiny/api-graphql": "6.6.0-alpha.13",
|
|
28
|
+
"@webiny/api-headless-cms": "6.6.0-alpha.13",
|
|
29
|
+
"@webiny/api-headless-cms-aco": "6.6.0-alpha.13",
|
|
30
|
+
"@webiny/api-headless-cms-scheduler": "6.6.0-alpha.13",
|
|
31
|
+
"@webiny/api-headless-cms-tasks": "6.6.0-alpha.13",
|
|
32
|
+
"@webiny/api-headless-cms-workflows": "6.6.0-alpha.13",
|
|
33
|
+
"@webiny/api-kernel-core": "6.6.0-alpha.13",
|
|
34
|
+
"@webiny/api-mailer": "6.6.0-alpha.13",
|
|
35
|
+
"@webiny/api-record-locking": "6.6.0-alpha.13",
|
|
36
|
+
"@webiny/api-scheduler": "6.6.0-alpha.13",
|
|
37
|
+
"@webiny/api-website-builder": "6.6.0-alpha.13",
|
|
38
|
+
"@webiny/api-website-builder-scheduler": "6.6.0-alpha.13",
|
|
39
|
+
"@webiny/api-website-builder-workflows": "6.6.0-alpha.13",
|
|
40
|
+
"@webiny/api-websockets": "6.6.0-alpha.13",
|
|
41
|
+
"@webiny/api-workflows": "6.6.0-alpha.13",
|
|
42
|
+
"@webiny/background-tasks": "6.6.0-alpha.13",
|
|
43
|
+
"@webiny/feature": "6.6.0-alpha.13",
|
|
44
|
+
"@webiny/handler": "6.6.0-alpha.13",
|
|
45
|
+
"pino": "10.4.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"@webiny/di": "^2.0.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/jsonwebtoken": "9.0.10",
|
|
52
|
+
"@webiny/build-tools": "6.6.0-alpha.13",
|
|
53
|
+
"@webiny/di": "2.0.0",
|
|
54
|
+
"jsonwebtoken": "9.0.3",
|
|
55
|
+
"rimraf": "6.1.4",
|
|
56
|
+
"typescript": "7.0.2",
|
|
57
|
+
"vitest": "5.1.1"
|
|
58
|
+
},
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"access": "public"
|
|
61
|
+
},
|
|
62
|
+
"webiny": {
|
|
63
|
+
"publishFrom": "dist"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Container } from "@webiny/di";
|
|
2
|
+
import { registerExtensions } from "@webiny/handler";
|
|
3
|
+
/** Installs a hosting-specific transport adapter into the per-request container at its interleave point. */
|
|
4
|
+
export type TransportRegistrar = (container: Container) => void | Promise<void>;
|
|
5
|
+
export interface RegisterApiRequestStackConfig {
|
|
6
|
+
/**
|
|
7
|
+
* Project-defined extensions, applied at register() time (so extension features β including
|
|
8
|
+
* code-defined CMS models β are registered before anything lists/caches the model set).
|
|
9
|
+
*/
|
|
10
|
+
extensions: () => Parameters<typeof registerExtensions>[1];
|
|
11
|
+
/**
|
|
12
|
+
* Hosting-specific transport adapters, each installed at its exact interleave point in the stack.
|
|
13
|
+
* Every entry follows the same shape: it runs immediately AFTER the transport-agnostic domain
|
|
14
|
+
* Feature has registered its NULL default, and overrides that default (nearest-container-last-wins)
|
|
15
|
+
* with the real adapter. Each is optional β omit one for a deployment/transport that lacks that
|
|
16
|
+
* capability. AWS supplies AWS adapters (API Gateway Management API / EventBridge / S3); the
|
|
17
|
+
* standalone server supplies in-process adapters (server WebSockets / in-process scheduler / local disk).
|
|
18
|
+
*/
|
|
19
|
+
transports?: {
|
|
20
|
+
/**
|
|
21
|
+
* Hosting-specific replacements for api-core defaults, run right after `ApiCoreFeature`:
|
|
22
|
+
* `PublicUrls` (default: every URL unknown), `CdnCache` (default: nothing to invalidate), and
|
|
23
|
+
* `EncryptionConfig` / `HashingConfig` (default: read from build params).
|
|
24
|
+
*/
|
|
25
|
+
hostingConfig?: TransportRegistrar;
|
|
26
|
+
/**
|
|
27
|
+
* Real-time (WebSockets) transport, run right after `WebsocketsFeature`. Overrides the
|
|
28
|
+
* NullWebsocketsTransport, otherwise every serverβclient send() is a silent no-op.
|
|
29
|
+
*/
|
|
30
|
+
realtime?: TransportRegistrar;
|
|
31
|
+
/**
|
|
32
|
+
* Scheduler transport, run AFTER `SchedulerFeature` and BEFORE `CmsSchedulerFeature`.
|
|
33
|
+
*/
|
|
34
|
+
scheduler?: TransportRegistrar;
|
|
35
|
+
/**
|
|
36
|
+
* File-manager storage transport, run AFTER `FileManagerAppFeature` (which registers the
|
|
37
|
+
* AssetDeliveryRoute + NULL asset-delivery impls). Overrides those nulls with real impls and
|
|
38
|
+
* adds the file-operation features.
|
|
39
|
+
*/
|
|
40
|
+
fileManager?: TransportRegistrar;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Registers the transport-AGNOSTIC Webiny API request stack. This is shared by all transport
|
|
45
|
+
* composition packages (`@webiny/api-composition-aws`, `-standalone`) so the feature set and its
|
|
46
|
+
* ordering live in ONE place and can't drift between transports.
|
|
47
|
+
*
|
|
48
|
+
* The request container gets only the tenant-neutral part: the raw request values, the tenant
|
|
49
|
+
* registry the request's tenant is loaded from, and `TenantScopes`. Build params come from the
|
|
50
|
+
* deploy, the same for every request and tenant, so the transport registers them once in the root
|
|
51
|
+
* (`registerRootBuildParams`), before any request registers a feature that reads them (features
|
|
52
|
+
* gate themselves on `FeatureFlags`, a build param, at register() time). Everything else is
|
|
53
|
+
* tenant-specific and registers in each tenant scope the request enters, through the
|
|
54
|
+
* `TenantScopeRegistration` registered here ({@link registerApiTenantScope}). The request's own work
|
|
55
|
+
* runs in its tenant's scope (`TenantScopesRootFeature`, which the transport registers in the root).
|
|
56
|
+
*
|
|
57
|
+
* Transport- and storage-specific pieces are injected via the hooks in {@link RegisterApiRequestStackConfig}
|
|
58
|
+
* at their exact interleave points. The caller is responsible for the ROOT-container transport wiring
|
|
59
|
+
* (HTTP/event transport, tenant sources, identity loaders, DB + storage) before dispatch reaches
|
|
60
|
+
* this per-request stack. That includes the `Logger`: api-core registers none, so a root without one
|
|
61
|
+
* fails the first time anything that logs is built.
|
|
62
|
+
*/
|
|
63
|
+
export declare function registerApiRequestStack(container: Container, config: RegisterApiRequestStackConfig): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Registers the request stack in ONE container: the tenant-neutral part and a tenant scope's part.
|
|
66
|
+
* For work outside a request that needs everything a request has, without a tenant: the SQL schema
|
|
67
|
+
* setup, which sets up the tables of exactly the storages and modules the API runs.
|
|
68
|
+
*
|
|
69
|
+
* The container is its own `RequestContainer`, as a request's is: services built while it
|
|
70
|
+
* registers (`TenantContext`, through `TenantScopes`) depend on it.
|
|
71
|
+
*/
|
|
72
|
+
export declare function registerApiRequestStackInOneContainer(container: Container, config: RegisterApiRequestStackConfig): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Registers a tenant scope's part of the request stack: every domain feature + the GraphQL engine,
|
|
75
|
+
* in the correct (order-sensitive) sequence, on top of the tenant-neutral part its parent (the
|
|
76
|
+
* request container) has.
|
|
77
|
+
*
|
|
78
|
+
* ORDER IS LOAD-BEARING β do not reorder. Notably: extensions must be applied before anything that
|
|
79
|
+
* lists + caches the scope's model set; the GraphQL engine must be registered last.
|
|
80
|
+
*/
|
|
81
|
+
export declare function registerApiTenantScope(container: Container, config: RegisterApiRequestStackConfig, extensions?: ReturnType<RegisterApiRequestStackConfig["extensions"]>): Promise<void>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { registerExtensions } from "@webiny/handler";
|
|
2
|
+
import { RequestContainer } from "@webiny/api-kernel-core";
|
|
3
|
+
import { GraphQLEngineFeature } from "@webiny/api-graphql";
|
|
4
|
+
import { ApiCoreFeature, RequestStorage } from "@webiny/api-core";
|
|
5
|
+
import { TenantNeutralRequestFeature, TenantScopeRegistration } from "@webiny/api-core/features/tenancy/TenantScopes/index.js";
|
|
6
|
+
import { WcpLicenseLoader } from "@webiny/api-core/features/wcp/WcpLicenseLoader.js";
|
|
7
|
+
import { HeadlessCmsFeature } from "@webiny/api-headless-cms";
|
|
8
|
+
import { AcoHcmsFeature } from "@webiny/api-headless-cms-aco";
|
|
9
|
+
import { HcmsTasksFeature } from "@webiny/api-headless-cms-tasks";
|
|
10
|
+
import { CmsWorkflowsFeature } from "@webiny/api-headless-cms-workflows";
|
|
11
|
+
import { CmsSchedulerFeature } from "@webiny/api-headless-cms-scheduler";
|
|
12
|
+
import { MailerFeature } from "@webiny/api-mailer";
|
|
13
|
+
import { RecordLockingAppFeature } from "@webiny/api-record-locking";
|
|
14
|
+
import { AuditLogsFeature } from "@webiny/api-audit-logs";
|
|
15
|
+
import { DashboardAppFeature } from "@webiny/api-dashboard";
|
|
16
|
+
import { AcoFeature } from "@webiny/api-aco";
|
|
17
|
+
import { BackgroundTasksFeature } from "@webiny/background-tasks/api";
|
|
18
|
+
import { FileManagerAppFeature } from "@webiny/api-file-manager";
|
|
19
|
+
import { FileManagerAcoFeature } from "@webiny/api-file-manager-aco";
|
|
20
|
+
import { WebsiteBuilderFeature } from "@webiny/api-website-builder";
|
|
21
|
+
import { WebsiteBuilderWorkflowsFeature } from "@webiny/api-website-builder-workflows";
|
|
22
|
+
import { WebsiteBuilderSchedulerFeature } from "@webiny/api-website-builder-scheduler";
|
|
23
|
+
import { WebsocketsFeature } from "@webiny/api-websockets";
|
|
24
|
+
import { WorkflowsFeature } from "@webiny/api-workflows";
|
|
25
|
+
import { SchedulerFeature } from "@webiny/api-scheduler";
|
|
26
|
+
async function registerApiRequestStack(container, config) {
|
|
27
|
+
await WcpLicenseLoader.load();
|
|
28
|
+
const extensions = config.extensions();
|
|
29
|
+
TenantNeutralRequestFeature.register(container);
|
|
30
|
+
container.registerInstance(TenantScopeRegistration, {
|
|
31
|
+
register: (scope)=>registerApiTenantScope(scope, config, extensions)
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async function registerApiRequestStackInOneContainer(container, config) {
|
|
35
|
+
container.registerInstance(RequestContainer, container);
|
|
36
|
+
await registerApiRequestStack(container, config);
|
|
37
|
+
await registerApiTenantScope(container, config);
|
|
38
|
+
}
|
|
39
|
+
async function registerApiTenantScope(container, config, extensions = config.extensions()) {
|
|
40
|
+
for (const storage of container.resolveAll(RequestStorage))await storage.register(container);
|
|
41
|
+
ApiCoreFeature.register(container, {
|
|
42
|
+
wcpLicense: void 0,
|
|
43
|
+
tenantScope: true
|
|
44
|
+
});
|
|
45
|
+
await config.transports?.hostingConfig?.(container);
|
|
46
|
+
HeadlessCmsFeature.register(container, {
|
|
47
|
+
type: "manage"
|
|
48
|
+
});
|
|
49
|
+
AcoFeature.register(container);
|
|
50
|
+
AcoHcmsFeature.register(container);
|
|
51
|
+
HcmsTasksFeature.register(container);
|
|
52
|
+
FileManagerAppFeature.register(container);
|
|
53
|
+
FileManagerAcoFeature.register(container);
|
|
54
|
+
await config.transports?.fileManager?.(container);
|
|
55
|
+
WebsiteBuilderFeature.register(container);
|
|
56
|
+
WebsiteBuilderWorkflowsFeature.register(container);
|
|
57
|
+
WebsiteBuilderSchedulerFeature.register(container);
|
|
58
|
+
WebsocketsFeature.register(container);
|
|
59
|
+
await config.transports?.realtime?.(container);
|
|
60
|
+
MailerFeature.register(container);
|
|
61
|
+
RecordLockingAppFeature.register(container, {});
|
|
62
|
+
AuditLogsFeature.register(container, {});
|
|
63
|
+
DashboardAppFeature.register(container);
|
|
64
|
+
BackgroundTasksFeature.register(container);
|
|
65
|
+
WorkflowsFeature.register(container);
|
|
66
|
+
CmsWorkflowsFeature.register(container);
|
|
67
|
+
SchedulerFeature.register(container);
|
|
68
|
+
await config.transports?.scheduler?.(container);
|
|
69
|
+
CmsSchedulerFeature.register(container);
|
|
70
|
+
await registerExtensions(container, extensions);
|
|
71
|
+
GraphQLEngineFeature.register(container);
|
|
72
|
+
}
|
|
73
|
+
export { registerApiRequestStack, registerApiRequestStackInOneContainer, registerApiTenantScope };
|
|
74
|
+
|
|
75
|
+
//# sourceMappingURL=registerApiRequestStack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registerApiRequestStack.js","sources":["../src/registerApiRequestStack.ts"],"sourcesContent":["import type { Container } from \"@webiny/di\";\nimport { registerExtensions } from \"@webiny/handler\";\nimport { RequestContainer } from \"@webiny/api-kernel-core\";\nimport { GraphQLEngineFeature } from \"@webiny/api-graphql\";\nimport { ApiCoreFeature, RequestStorage } from \"@webiny/api-core\";\nimport {\n TenantNeutralRequestFeature,\n TenantScopeRegistration\n} from \"@webiny/api-core/features/tenancy/TenantScopes/index.js\";\nimport { WcpLicenseLoader } from \"@webiny/api-core/features/wcp/WcpLicenseLoader.js\";\nimport { HeadlessCmsFeature } from \"@webiny/api-headless-cms\";\nimport { AcoHcmsFeature } from \"@webiny/api-headless-cms-aco\";\nimport { HcmsTasksFeature } from \"@webiny/api-headless-cms-tasks\";\nimport { CmsWorkflowsFeature } from \"@webiny/api-headless-cms-workflows\";\nimport { CmsSchedulerFeature } from \"@webiny/api-headless-cms-scheduler\";\nimport { MailerFeature } from \"@webiny/api-mailer\";\nimport { RecordLockingAppFeature } from \"@webiny/api-record-locking\";\nimport { AuditLogsFeature } from \"@webiny/api-audit-logs\";\nimport { DashboardAppFeature } from \"@webiny/api-dashboard\";\nimport { AcoFeature } from \"@webiny/api-aco\";\nimport { BackgroundTasksFeature } from \"@webiny/background-tasks/api\";\nimport { FileManagerAppFeature } from \"@webiny/api-file-manager\";\nimport { FileManagerAcoFeature } from \"@webiny/api-file-manager-aco\";\nimport { WebsiteBuilderFeature } from \"@webiny/api-website-builder\";\nimport { WebsiteBuilderWorkflowsFeature } from \"@webiny/api-website-builder-workflows\";\nimport { WebsiteBuilderSchedulerFeature } from \"@webiny/api-website-builder-scheduler\";\nimport { WebsocketsFeature } from \"@webiny/api-websockets\";\nimport { WorkflowsFeature } from \"@webiny/api-workflows\";\nimport { SchedulerFeature } from \"@webiny/api-scheduler\";\n\n/** Installs a hosting-specific transport adapter into the per-request container at its interleave point. */\nexport type TransportRegistrar = (container: Container) => void | Promise<void>;\n\nexport interface RegisterApiRequestStackConfig {\n /**\n * Project-defined extensions, applied at register() time (so extension features β including\n * code-defined CMS models β are registered before anything lists/caches the model set).\n */\n extensions: () => Parameters<typeof registerExtensions>[1];\n /**\n * Hosting-specific transport adapters, each installed at its exact interleave point in the stack.\n * Every entry follows the same shape: it runs immediately AFTER the transport-agnostic domain\n * Feature has registered its NULL default, and overrides that default (nearest-container-last-wins)\n * with the real adapter. Each is optional β omit one for a deployment/transport that lacks that\n * capability. AWS supplies AWS adapters (API Gateway Management API / EventBridge / S3); the\n * standalone server supplies in-process adapters (server WebSockets / in-process scheduler / local disk).\n */\n transports?: {\n /**\n * Hosting-specific replacements for api-core defaults, run right after `ApiCoreFeature`:\n * `PublicUrls` (default: every URL unknown), `CdnCache` (default: nothing to invalidate), and\n * `EncryptionConfig` / `HashingConfig` (default: read from build params).\n */\n hostingConfig?: TransportRegistrar;\n /**\n * Real-time (WebSockets) transport, run right after `WebsocketsFeature`. Overrides the\n * NullWebsocketsTransport, otherwise every serverβclient send() is a silent no-op.\n */\n realtime?: TransportRegistrar;\n /**\n * Scheduler transport, run AFTER `SchedulerFeature` and BEFORE `CmsSchedulerFeature`.\n */\n scheduler?: TransportRegistrar;\n /**\n * File-manager storage transport, run AFTER `FileManagerAppFeature` (which registers the\n * AssetDeliveryRoute + NULL asset-delivery impls). Overrides those nulls with real impls and\n * adds the file-operation features.\n */\n fileManager?: TransportRegistrar;\n };\n}\n\n/**\n * Registers the transport-AGNOSTIC Webiny API request stack. This is shared by all transport\n * composition packages (`@webiny/api-composition-aws`, `-standalone`) so the feature set and its\n * ordering live in ONE place and can't drift between transports.\n *\n * The request container gets only the tenant-neutral part: the raw request values, the tenant\n * registry the request's tenant is loaded from, and `TenantScopes`. Build params come from the\n * deploy, the same for every request and tenant, so the transport registers them once in the root\n * (`registerRootBuildParams`), before any request registers a feature that reads them (features\n * gate themselves on `FeatureFlags`, a build param, at register() time). Everything else is\n * tenant-specific and registers in each tenant scope the request enters, through the\n * `TenantScopeRegistration` registered here ({@link registerApiTenantScope}). The request's own work\n * runs in its tenant's scope (`TenantScopesRootFeature`, which the transport registers in the root).\n *\n * Transport- and storage-specific pieces are injected via the hooks in {@link RegisterApiRequestStackConfig}\n * at their exact interleave points. The caller is responsible for the ROOT-container transport wiring\n * (HTTP/event transport, tenant sources, identity loaders, DB + storage) before dispatch reaches\n * this per-request stack. That includes the `Logger`: api-core registers none, so a root without one\n * fails the first time anything that logs is built.\n */\nexport async function registerApiRequestStack(\n container: Container,\n config: RegisterApiRequestStackConfig\n): Promise<void> {\n // Refresh the WCP license BEFORE any feature registers β this is the single per-request refresh.\n // register()-time feature-flag checks (e.g. the private-files gate) and WcpContext.canUse* both\n // read it via the process cache (`WcpLicenseProvider.get()` / `WcpLicenseLoader.getCached()`). Runs here\n // β the shared request stack both hosting types call β so no handler wires it. Process-cached\n // (~5-min TTL) + single-flighted β cheap no-op on warm requests.\n await WcpLicenseLoader.load();\n\n const extensions = config.extensions();\n\n // ββ Tenant-neutral request: raw values, tenant registry, TenantScopes ββ\n TenantNeutralRequestFeature.register(container);\n\n // ββ Everything tenant-specific: per tenant scope βββββββββββ\n container.registerInstance(TenantScopeRegistration, {\n register: scope => registerApiTenantScope(scope, config, extensions)\n });\n}\n\n/**\n * Registers the request stack in ONE container: the tenant-neutral part and a tenant scope's part.\n * For work outside a request that needs everything a request has, without a tenant: the SQL schema\n * setup, which sets up the tables of exactly the storages and modules the API runs.\n *\n * The container is its own `RequestContainer`, as a request's is: services built while it\n * registers (`TenantContext`, through `TenantScopes`) depend on it.\n */\nexport async function registerApiRequestStackInOneContainer(\n container: Container,\n config: RegisterApiRequestStackConfig\n): Promise<void> {\n container.registerInstance(RequestContainer, container);\n await registerApiRequestStack(container, config);\n await registerApiTenantScope(container, config);\n}\n\n/**\n * Registers a tenant scope's part of the request stack: every domain feature + the GraphQL engine,\n * in the correct (order-sensitive) sequence, on top of the tenant-neutral part its parent (the\n * request container) has.\n *\n * ORDER IS LOAD-BEARING β do not reorder. Notably: extensions must be applied before anything that\n * lists + caches the scope's model set; the GraphQL engine must be registered last.\n */\nexport async function registerApiTenantScope(\n container: Container,\n config: RegisterApiRequestStackConfig,\n extensions: ReturnType<RegisterApiRequestStackConfig[\"extensions\"]> = config.extensions()\n): Promise<void> {\n // ββ Storage (before ANY feature) βββββββββββββββββββββββββββ\n // Every storage that registers per request put a `RequestStorage` in the root; each registers\n // its storages here, in the scope's container. First, because `ApiCoreFeature` resolves the\n // core storage while it registers. A storage that keeps its storages in the root (the DynamoDB\n // variants) registers none, and this does nothing.\n for (const storage of container.resolveAll(RequestStorage)) {\n await storage.register(container);\n }\n\n // ββ Core API: tenant/identity contexts, security, users, ... (the tenant registry and the raw\n // request values come from the request container) βββββββββ\n ApiCoreFeature.register(container, { wcpLicense: undefined, tenantScope: true });\n await config.transports?.hostingConfig?.(container);\n\n // ββ CMS ββββββββββββββββββββββββββββββββββββββββββββββββββββ\n HeadlessCmsFeature.register(container, { type: \"manage\" });\n AcoFeature.register(container);\n AcoHcmsFeature.register(container);\n HcmsTasksFeature.register(container);\n\n // ββ File Manager (domain) + storage transport ββββββββββββββ\n FileManagerAppFeature.register(container);\n FileManagerAcoFeature.register(container);\n await config.transports?.fileManager?.(container);\n\n // ββ Website Builder ββββββββββββββββββββββββββββββββββββββββ\n WebsiteBuilderFeature.register(container);\n WebsiteBuilderWorkflowsFeature.register(container);\n WebsiteBuilderSchedulerFeature.register(container);\n\n // ββ Websockets (domain) + real-time transport ββββββββββββββ\n WebsocketsFeature.register(container);\n await config.transports?.realtime?.(container);\n\n // ββ Supporting services ββββββββββββββββββββββββββββββββββββ\n MailerFeature.register(container);\n RecordLockingAppFeature.register(container, {});\n AuditLogsFeature.register(container, {});\n DashboardAppFeature.register(container);\n BackgroundTasksFeature.register(container);\n\n // ββ Workflows ββββββββββββββββββββββββββββββββββββββββββββββ\n WorkflowsFeature.register(container);\n CmsWorkflowsFeature.register(container);\n\n // ββ Scheduler + scheduler transport ββββββββββββββββββββββββ\n SchedulerFeature.register(container);\n await config.transports?.scheduler?.(container);\n CmsSchedulerFeature.register(container);\n\n // ββ Extensions βββββββββββββββββββββββββββββββββββββββββββββ\n // Apply at register() time so extension features β including code-defined CMS models\n // (ModelFactory), e.g. Languages β are registered before anything populates ModelCache. Anything\n // reaching the model set through GetModel/ListModels (which go via ModelsFetcher ->\n // ModelCache.getOrSet) caches it for the rest of the request, so a set built before extensions\n // register would be missing their models. Every consumer now resolves models at schema-build or\n // resolver time, i.e. after all registration.\n await registerExtensions(container, extensions);\n\n // ββ GraphQL engine (always last) βββββββββββββββββββββββββββ\n GraphQLEngineFeature.register(container);\n}\n"],"names":["registerApiRequestStack","container","config","WcpLicenseLoader","extensions","TenantNeutralRequestFeature","TenantScopeRegistration","scope","registerApiTenantScope","registerApiRequestStackInOneContainer","RequestContainer","storage","RequestStorage","ApiCoreFeature","undefined","HeadlessCmsFeature","AcoFeature","AcoHcmsFeature","HcmsTasksFeature","FileManagerAppFeature","FileManagerAcoFeature","WebsiteBuilderFeature","WebsiteBuilderWorkflowsFeature","WebsiteBuilderSchedulerFeature","WebsocketsFeature","MailerFeature","RecordLockingAppFeature","AuditLogsFeature","DashboardAppFeature","BackgroundTasksFeature","WorkflowsFeature","CmsWorkflowsFeature","SchedulerFeature","CmsSchedulerFeature","registerExtensions","GraphQLEngineFeature"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA4FO,eAAeA,wBAClBC,SAAoB,EACpBC,MAAqC;IAOrC,MAAMC,iBAAiB,IAAI;IAE3B,MAAMC,aAAaF,OAAO,UAAU;IAGpCG,4BAA4B,QAAQ,CAACJ;IAGrCA,UAAU,gBAAgB,CAACK,yBAAyB;QAChD,UAAUC,CAAAA,QAASC,uBAAuBD,OAAOL,QAAQE;IAC7D;AACJ;AAUO,eAAeK,sCAClBR,SAAoB,EACpBC,MAAqC;IAErCD,UAAU,gBAAgB,CAACS,kBAAkBT;IAC7C,MAAMD,wBAAwBC,WAAWC;IACzC,MAAMM,uBAAuBP,WAAWC;AAC5C;AAUO,eAAeM,uBAClBP,SAAoB,EACpBC,MAAqC,EACrCE,aAAsEF,OAAO,UAAU,EAAE;IAOzF,KAAK,MAAMS,WAAWV,UAAU,UAAU,CAACW,gBACvC,MAAMD,QAAQ,QAAQ,CAACV;IAK3BY,eAAe,QAAQ,CAACZ,WAAW;QAAE,YAAYa;QAAW,aAAa;IAAK;IAC9E,MAAMZ,OAAO,UAAU,EAAE,gBAAgBD;IAGzCc,mBAAmB,QAAQ,CAACd,WAAW;QAAE,MAAM;IAAS;IACxDe,WAAW,QAAQ,CAACf;IACpBgB,eAAe,QAAQ,CAAChB;IACxBiB,iBAAiB,QAAQ,CAACjB;IAG1BkB,sBAAsB,QAAQ,CAAClB;IAC/BmB,sBAAsB,QAAQ,CAACnB;IAC/B,MAAMC,OAAO,UAAU,EAAE,cAAcD;IAGvCoB,sBAAsB,QAAQ,CAACpB;IAC/BqB,+BAA+B,QAAQ,CAACrB;IACxCsB,+BAA+B,QAAQ,CAACtB;IAGxCuB,kBAAkB,QAAQ,CAACvB;IAC3B,MAAMC,OAAO,UAAU,EAAE,WAAWD;IAGpCwB,cAAc,QAAQ,CAACxB;IACvByB,wBAAwB,QAAQ,CAACzB,WAAW,CAAC;IAC7C0B,iBAAiB,QAAQ,CAAC1B,WAAW,CAAC;IACtC2B,oBAAoB,QAAQ,CAAC3B;IAC7B4B,uBAAuB,QAAQ,CAAC5B;IAGhC6B,iBAAiB,QAAQ,CAAC7B;IAC1B8B,oBAAoB,QAAQ,CAAC9B;IAG7B+B,iBAAiB,QAAQ,CAAC/B;IAC1B,MAAMC,OAAO,UAAU,EAAE,YAAYD;IACrCgC,oBAAoB,QAAQ,CAAChC;IAS7B,MAAMiC,mBAAmBjC,WAAWG;IAGpC+B,qBAAqB,QAAQ,CAAClC;AAClC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Container } from "@webiny/di";
|
|
2
|
+
export interface IApiRequestRegistration {
|
|
3
|
+
/**
|
|
4
|
+
* Registers what a request has into `container`, exactly as the transport does for every request
|
|
5
|
+
* (its `child` step): the storages (every `RequestStorage`), the API's features with the
|
|
6
|
+
* transport's adapters, and the project's extensions.
|
|
7
|
+
*/
|
|
8
|
+
register(container: Container): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The transport's request registration, in the root container. Lets work that runs outside any
|
|
12
|
+
* request build a container a request would have: the SQL schema setup builds one on its own
|
|
13
|
+
* connection, so it sets up the tables of exactly the storages and modules the API runs.
|
|
14
|
+
*/
|
|
15
|
+
export declare const ApiRequestRegistration: import("@webiny/di").Abstraction<IApiRequestRegistration>;
|
|
16
|
+
export declare namespace ApiRequestRegistration {
|
|
17
|
+
type Interface = IApiRequestRegistration;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestRegistration/abstractions.js","sources":["../../src/requestRegistration/abstractions.ts"],"sourcesContent":["import type { Container } from \"@webiny/di\";\nimport { createAbstraction } from \"@webiny/feature/api\";\n\nexport interface IApiRequestRegistration {\n /**\n * Registers what a request has into `container`, exactly as the transport does for every request\n * (its `child` step): the storages (every `RequestStorage`), the API's features with the\n * transport's adapters, and the project's extensions.\n */\n register(container: Container): Promise<void>;\n}\n\n/**\n * The transport's request registration, in the root container. Lets work that runs outside any\n * request build a container a request would have: the SQL schema setup builds one on its own\n * connection, so it sets up the tables of exactly the storages and modules the API runs.\n */\nexport const ApiRequestRegistration = createAbstraction<IApiRequestRegistration>(\n \"Core/ApiRequestRegistration\"\n);\n\nexport namespace ApiRequestRegistration {\n export type Interface = IApiRequestRegistration;\n}\n"],"names":["ApiRequestRegistration","createAbstraction"],"mappings":";AAiBO,MAAMA,yBAAyBC,kBAClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ApiRequestRegistration } from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ApiRequestRegistration } from "./abstractions.js";
|