@webiny/api-composition-core 0.0.0-stage β 0.0.0-unstable.e1999482d0
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 +21 -0
- package/auth/extractAuthToken.js +32 -0
- package/auth/extractAuthToken.js.map +1 -0
- package/auth/extractTenantId.d.ts +5 -0
- package/auth/extractTenantId.js +7 -0
- package/auth/extractTenantId.js.map +1 -0
- package/auth/getHeader.d.ts +5 -0
- package/auth/getHeader.js +8 -0
- package/auth/getHeader.js.map +1 -0
- package/auth/index.d.ts +4 -0
- package/auth/index.js +3 -0
- package/auth/rejectedTokenResponse.d.ts +11 -0
- package/auth/rejectedTokenResponse.js +19 -0
- package/auth/rejectedTokenResponse.js.map +1 -0
- package/buildParams/readBuildParams.d.ts +10 -0
- package/buildParams/readBuildParams.js +13 -0
- package/buildParams/readBuildParams.js.map +1 -0
- package/index.d.ts +9 -0
- package/index.js +5 -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/nodeHttp/NodeHttpAssumePermissionsDecorator.d.ts +19 -0
- package/nodeHttp/NodeHttpAssumePermissionsDecorator.js +23 -0
- package/nodeHttp/NodeHttpAssumePermissionsDecorator.js.map +1 -0
- package/nodeHttp/NodeHttpIdentityLoaderDecorator.d.ts +34 -0
- package/nodeHttp/NodeHttpIdentityLoaderDecorator.js +38 -0
- package/nodeHttp/NodeHttpIdentityLoaderDecorator.js.map +1 -0
- package/nodeHttp/NodeHttpTenantLoaderDecorator.d.ts +24 -0
- package/nodeHttp/NodeHttpTenantLoaderDecorator.js +28 -0
- package/nodeHttp/NodeHttpTenantLoaderDecorator.js.map +1 -0
- package/nodeHttp/headersFromIncomingMessage.d.ts +6 -0
- package/nodeHttp/headersFromIncomingMessage.js +9 -0
- package/nodeHttp/headersFromIncomingMessage.js.map +1 -0
- package/nodeHttp/index.d.ts +3 -0
- package/nodeHttp/index.js +3 -0
- package/package.json +64 -5
- package/registerApiRequestStack.d.ts +58 -0
- package/registerApiRequestStack.js +62 -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,21 @@
|
|
|
1
|
+
export interface AuthTokenRequest {
|
|
2
|
+
method: string | undefined;
|
|
3
|
+
path: string | undefined;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* The `wby-id-token` cookie exists only for private file delivery: an `<img src>` cannot send an
|
|
7
|
+
* `Authorization` header. It must not log users in anywhere else, because the browser attaches it
|
|
8
|
+
* to cross-site requests too (`SameSite=None`), which would let any website call the API as the user.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isCookieAuthenticationAllowed(request: AuthTokenRequest): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Reads the auth token, preferring `x-webiny-authorization` over `Authorization`.
|
|
13
|
+
*
|
|
14
|
+
* The order matters for CloudFront β Lambda Function URL (the streaming routes, file delivery): the
|
|
15
|
+
* Origin Access Control signs those requests with SigV4 in the `Authorization` header, so a viewer's
|
|
16
|
+
* bearer token cannot survive to the origin, and clients send it in `x-webiny-authorization` instead.
|
|
17
|
+
* A Lambda web function origin is different: CloudFront keeps the viewer's `Authorization` there, so
|
|
18
|
+
* plain `Authorization` works for the API's main routes. The `wby-id-token` cookie is the last resort,
|
|
19
|
+
* and only for private file reads (see {@link isCookieAuthenticationAllowed}).
|
|
20
|
+
*/
|
|
21
|
+
export declare function extractAuthToken(headers: Record<string, string> | undefined, request: AuthTokenRequest): string | null;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { getHeader } from "./getHeader.js";
|
|
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(headers, request) {
|
|
22
|
+
const webinyAuth = getHeader(headers, WEBINY_AUTHORIZATION_HEADER).replace(/^Bearer\s+/i, "");
|
|
23
|
+
if (webinyAuth) return webinyAuth;
|
|
24
|
+
const bearer = getHeader(headers, "authorization").replace(/^Bearer\s+/i, "");
|
|
25
|
+
if (bearer) return bearer;
|
|
26
|
+
if (!isCookieAuthenticationAllowed(request)) return null;
|
|
27
|
+
const cookieHeader = getHeader(headers, "cookie");
|
|
28
|
+
return readCookie(cookieHeader, "wby-id-token");
|
|
29
|
+
}
|
|
30
|
+
export { extractAuthToken, isCookieAuthenticationAllowed };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=extractAuthToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth/extractAuthToken.js","sources":["../../src/auth/extractAuthToken.ts"],"sourcesContent":["import { getHeader } from \"./getHeader.js\";\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\nexport interface AuthTokenRequest {\n method: string | undefined;\n path: string | undefined;\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(request: AuthTokenRequest): 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 headers: Record<string, string> | undefined,\n request: AuthTokenRequest\n): string | null {\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":";AAEA,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;AAYO,SAASI,8BAA8BC,OAAyB;IACnE,MAAMC,SAAUD,AAAAA,CAAAA,QAAQ,MAAM,IAAI,EAAC,EAAG,WAAW;IACjD,IAAIC,AAAW,UAAXA,UAAoBA,AAAW,WAAXA,QACpB,OAAO;IAEX,OAAQD,AAAAA,CAAAA,QAAQ,IAAI,IAAI,EAAC,EAAG,UAAU,CAAC;AAC3C;AAYO,SAASE,iBACZC,OAA2C,EAC3CH,OAAyB;IAEzB,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 @@
|
|
|
1
|
+
{"version":3,"file":"auth/extractTenantId.js","sources":["../../src/auth/extractTenantId.ts"],"sourcesContent":["import { getHeader } from \"./getHeader.js\";\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(headers: Record<string, string> | undefined): string | null {\n return getHeader(headers, \"x-tenant\") || null;\n}\n"],"names":["extractTenantId","headers","getHeader"],"mappings":";AAMO,SAASA,gBAAgBC,OAA2C;IACvE,OAAOC,UAAUD,SAAS,eAAe;AAC7C"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads one header from a plain header map. Header names are case-insensitive, and the casing that
|
|
3
|
+
* reaches us depends on the transport and on the client, so this matches on the lowercased key.
|
|
4
|
+
*/
|
|
5
|
+
export declare function getHeader(headers: Record<string, string> | undefined, name: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth/getHeader.js","sources":["../../src/auth/getHeader.ts"],"sourcesContent":["/**\n * Reads one header from a plain header map. Header names are case-insensitive, and the casing that\n * reaches us depends on the transport and on the client, so this matches on the lowercased key.\n */\nexport function getHeader(headers: Record<string, string> | undefined, name: string): string {\n if (!headers) {\n return \"\";\n }\n for (const key of Object.keys(headers)) {\n if (key.toLowerCase() === name) {\n return headers[key] ?? \"\";\n }\n }\n return \"\";\n}\n"],"names":["getHeader","headers","name","key","Object"],"mappings":"AAIO,SAASA,UAAUC,OAA2C,EAAEC,IAAY;IAC/E,IAAI,CAACD,SACD,OAAO;IAEX,KAAK,MAAME,OAAOC,OAAO,IAAI,CAACH,SAC1B,IAAIE,IAAI,WAAW,OAAOD,MACtB,OAAOD,OAAO,CAACE,IAAI,IAAI;IAG/B,OAAO;AACX"}
|
package/auth/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { extractAuthToken, isCookieAuthenticationAllowed } from "./extractAuthToken.js";
|
|
2
|
+
export type { AuthTokenRequest } from "./extractAuthToken.js";
|
|
3
|
+
export { extractTenantId } from "./extractTenantId.js";
|
|
4
|
+
export { rejectedTokenResponse } from "./rejectedTokenResponse.js";
|
package/auth/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
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`. Every transport's identity loader returns it, so a rejected token gets the same
|
|
6
|
+
* 401 on AWS and on standalone.
|
|
7
|
+
*
|
|
8
|
+
* The identity loaders run before the router, so `SecureHeadersDecorator` never sees this response and
|
|
9
|
+
* the CORS headers are added here. Without them the browser reports a CORS failure instead of the 401.
|
|
10
|
+
*/
|
|
11
|
+
export declare function rejectedTokenResponse(error: AuthenticationError, headers: Record<string, string> | undefined): IHttpResponse;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { codedErrorBody, corsHeaders } from "@webiny/api-kernel-core";
|
|
2
|
+
import { getHeader } from "./getHeader.js";
|
|
3
|
+
function rejectedTokenResponse(error, headers) {
|
|
4
|
+
const origin = getHeader(headers, "origin");
|
|
5
|
+
const cors = corsHeaders(origin);
|
|
6
|
+
const body = codedErrorBody(error);
|
|
7
|
+
return {
|
|
8
|
+
statusCode: 401,
|
|
9
|
+
headers: {
|
|
10
|
+
...cors,
|
|
11
|
+
"content-type": "application/json",
|
|
12
|
+
"www-authenticate": 'Bearer error="invalid_token"'
|
|
13
|
+
},
|
|
14
|
+
body
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export { rejectedTokenResponse };
|
|
18
|
+
|
|
19
|
+
//# 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 { corsHeaders } from \"@webiny/api-kernel-core\";\nimport { codedErrorBody } from \"@webiny/api-kernel-core\";\nimport type { IHttpResponse } from \"@webiny/api-kernel-core\";\nimport { getHeader } from \"./getHeader.js\";\n\n/**\n * The answer to a request whose token an identity provider rejected, for example in\n * `verifyTokenClaims`. Every transport's identity loader returns it, so a rejected token gets the same\n * 401 on AWS and on standalone.\n *\n * The identity loaders run before the router, so `SecureHeadersDecorator` never sees this response and\n * the CORS headers are added here. Without them the browser reports a CORS failure instead of the 401.\n */\nexport function rejectedTokenResponse(\n error: AuthenticationError,\n headers: Record<string, string> | undefined\n): IHttpResponse {\n const origin = getHeader(headers, \"origin\");\n const cors = corsHeaders(origin);\n const body = codedErrorBody(error);\n\n return {\n statusCode: 401,\n headers: {\n ...cors,\n \"content-type\": \"application/json\",\n \"www-authenticate\": 'Bearer error=\"invalid_token\"'\n },\n body\n };\n}\n"],"names":["rejectedTokenResponse","error","headers","origin","getHeader","cors","corsHeaders","body","codedErrorBody"],"mappings":";;AAcO,SAASA,sBACZC,KAA0B,EAC1BC,OAA2C;IAE3C,MAAMC,SAASC,UAAUF,SAAS;IAClC,MAAMG,OAAOC,YAAYH;IACzB,MAAMI,OAAOC,eAAeP;IAE5B,OAAO;QACH,YAAY;QACZ,SAAS;YACL,GAAGI,IAAI;YACP,gBAAgB;YAChB,oBAAoB;QACxB;QACAE;IACJ;AACJ"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { registerBuildParams } from "@webiny/handler";
|
|
2
|
+
import { BuildParams } from "@webiny/api-core/features/buildParams/index.js";
|
|
3
|
+
type Extensions = Parameters<typeof registerBuildParams>[1];
|
|
4
|
+
/**
|
|
5
|
+
* The build params the project was built with, read in a throwaway container. Requests register
|
|
6
|
+
* them in their own containers; this copy is for the root, which needs a setting from them (or wants
|
|
7
|
+
* to check them) before any request runs. Call it once per process.
|
|
8
|
+
*/
|
|
9
|
+
export declare function readBuildParams(extensions: Extensions): Promise<BuildParams.Interface>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Container } from "@webiny/di";
|
|
2
|
+
import { registerBuildParams } from "@webiny/handler";
|
|
3
|
+
import { BuildParams } from "@webiny/api-core/features/buildParams/index.js";
|
|
4
|
+
import { BuildParamsFeature } from "@webiny/api-core/features/buildParams/feature.js";
|
|
5
|
+
async function readBuildParams(extensions) {
|
|
6
|
+
const container = new Container();
|
|
7
|
+
BuildParamsFeature.register(container);
|
|
8
|
+
await registerBuildParams(container, extensions);
|
|
9
|
+
return container.resolve(BuildParams);
|
|
10
|
+
}
|
|
11
|
+
export { readBuildParams };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=readBuildParams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildParams/readBuildParams.js","sources":["../../src/buildParams/readBuildParams.ts"],"sourcesContent":["import { 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 * The build params the project was built with, read in a throwaway container. Requests register\n * them in their own containers; this copy is for the root, which needs a setting from them (or wants\n * to check them) before any request runs. Call it once per process.\n */\nexport async function readBuildParams(extensions: Extensions): Promise<BuildParams.Interface> {\n const container = new Container();\n BuildParamsFeature.register(container);\n await registerBuildParams(container, extensions);\n return container.resolve(BuildParams);\n}\n"],"names":["readBuildParams","extensions","container","Container","BuildParamsFeature","registerBuildParams","BuildParams"],"mappings":";;;;AAYO,eAAeA,gBAAgBC,UAAsB;IACxD,MAAMC,YAAY,IAAIC;IACtBC,mBAAmB,QAAQ,CAACF;IAC5B,MAAMG,oBAAoBH,WAAWD;IACrC,OAAOC,UAAU,OAAO,CAACI;AAC7B"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { registerApiRequestStack } 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 type { AuthTokenRequest } from "./auth/index.js";
|
|
6
|
+
export { extractTenantId } from "./auth/index.js";
|
|
7
|
+
export { rejectedTokenResponse } from "./auth/index.js";
|
|
8
|
+
export { readBuildParams } from "./buildParams/readBuildParams.js";
|
|
9
|
+
export { ApiRequestRegistration } from "./requestRegistration/index.js";
|
package/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { registerApiRequestStack } from "./registerApiRequestStack.js";
|
|
2
|
+
export { createLogger } from "./logger/createLogger.js";
|
|
3
|
+
export { extractAuthToken, extractTenantId, isCookieAuthenticationAllowed, rejectedTokenResponse } from "./auth/index.js";
|
|
4
|
+
export { readBuildParams } from "./buildParams/readBuildParams.js";
|
|
5
|
+
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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IncomingMessage } from "node:http";
|
|
2
|
+
import { NodeHttpInputHandler } from "@webiny/api-kernel-core/nodeHttp/index.js";
|
|
3
|
+
import { RawAssumePermissions } from "@webiny/api-core/features/requestContext/index.js";
|
|
4
|
+
import type { InputContext } from "@webiny/api-kernel-core";
|
|
5
|
+
import type { NextFunction } from "@webiny/api-kernel-core";
|
|
6
|
+
/**
|
|
7
|
+
* EXTRACT (transport-specific): reads the `x-webiny-assume-permissions` header of a Node
|
|
8
|
+
* `IncomingMessage` into RawAssumePermissions. Node mirror of ApiGatewayAssumePermissionsDecorator.
|
|
9
|
+
*/
|
|
10
|
+
declare class NodeHttpAssumePermissionsDecoratorImpl implements NodeHttpInputHandler.Interface {
|
|
11
|
+
private rawAssumePermissions;
|
|
12
|
+
private decoratee;
|
|
13
|
+
constructor(rawAssumePermissions: RawAssumePermissions.Interface, decoratee: NodeHttpInputHandler.Interface);
|
|
14
|
+
execute(ctx: InputContext<IncomingMessage>, next: NextFunction): Promise<any>;
|
|
15
|
+
}
|
|
16
|
+
export declare const NodeHttpAssumePermissionsDecorator: typeof NodeHttpAssumePermissionsDecoratorImpl & {
|
|
17
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-kernel-core/nodeHttp/index.js").INodeHttpInputHandler>;
|
|
18
|
+
};
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { NodeHttpInputHandler } from "@webiny/api-kernel-core/nodeHttp/index.js";
|
|
2
|
+
import { RawAssumePermissions, extractAssumePermissions } from "@webiny/api-core/features/requestContext/index.js";
|
|
3
|
+
class NodeHttpAssumePermissionsDecoratorImpl {
|
|
4
|
+
constructor(rawAssumePermissions, decoratee){
|
|
5
|
+
this.rawAssumePermissions = rawAssumePermissions;
|
|
6
|
+
this.decoratee = decoratee;
|
|
7
|
+
}
|
|
8
|
+
async execute(ctx, next) {
|
|
9
|
+
const headers = ctx.input?.headers;
|
|
10
|
+
const requested = extractAssumePermissions(headers);
|
|
11
|
+
this.rawAssumePermissions.set(requested);
|
|
12
|
+
return this.decoratee.execute(ctx, next);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const NodeHttpAssumePermissionsDecorator = NodeHttpInputHandler.createDecorator({
|
|
16
|
+
decorator: NodeHttpAssumePermissionsDecoratorImpl,
|
|
17
|
+
dependencies: [
|
|
18
|
+
RawAssumePermissions
|
|
19
|
+
]
|
|
20
|
+
});
|
|
21
|
+
export { NodeHttpAssumePermissionsDecorator };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=NodeHttpAssumePermissionsDecorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodeHttp/NodeHttpAssumePermissionsDecorator.js","sources":["../../src/nodeHttp/NodeHttpAssumePermissionsDecorator.ts"],"sourcesContent":["import type { IncomingMessage } from \"node:http\";\nimport { NodeHttpInputHandler } from \"@webiny/api-kernel-core/nodeHttp/index.js\";\nimport { RawAssumePermissions } from \"@webiny/api-core/features/requestContext/index.js\";\nimport { extractAssumePermissions } from \"@webiny/api-core/features/requestContext/index.js\";\nimport type { InputContext } from \"@webiny/api-kernel-core\";\nimport type { NextFunction } from \"@webiny/api-kernel-core\";\n\n/**\n * EXTRACT (transport-specific): reads the `x-webiny-assume-permissions` header of a Node\n * `IncomingMessage` into RawAssumePermissions. Node mirror of ApiGatewayAssumePermissionsDecorator.\n */\nclass NodeHttpAssumePermissionsDecoratorImpl implements NodeHttpInputHandler.Interface {\n constructor(\n private rawAssumePermissions: RawAssumePermissions.Interface,\n private decoratee: NodeHttpInputHandler.Interface\n ) {}\n\n async execute(ctx: InputContext<IncomingMessage>, next: NextFunction): Promise<any> {\n const headers = ctx.input?.headers;\n const requested = extractAssumePermissions(headers);\n\n this.rawAssumePermissions.set(requested);\n\n return this.decoratee.execute(ctx, next);\n }\n}\n\nexport const NodeHttpAssumePermissionsDecorator = NodeHttpInputHandler.createDecorator({\n decorator: NodeHttpAssumePermissionsDecoratorImpl,\n dependencies: [RawAssumePermissions]\n});\n"],"names":["NodeHttpAssumePermissionsDecoratorImpl","rawAssumePermissions","decoratee","ctx","next","headers","requested","extractAssumePermissions","NodeHttpAssumePermissionsDecorator","NodeHttpInputHandler","RawAssumePermissions"],"mappings":";;AAWA,MAAMA;IACF,YACYC,oBAAoD,EACpDC,SAAyC,CACnD;aAFUD,oBAAoB,GAApBA;aACAC,SAAS,GAATA;IACT;IAEH,MAAM,QAAQC,GAAkC,EAAEC,IAAkB,EAAgB;QAChF,MAAMC,UAAUF,IAAI,KAAK,EAAE;QAC3B,MAAMG,YAAYC,yBAAyBF;QAE3C,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAACC;QAE9B,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAACH,KAAKC;IACvC;AACJ;AAEO,MAAMI,qCAAqCC,qBAAqB,eAAe,CAAC;IACnF,WAAWT;IACX,cAAc;QAACU;KAAqB;AACxC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { IncomingMessage } from "node:http";
|
|
2
|
+
import { NodeHttpInputHandler } from "@webiny/api-kernel-core/nodeHttp/index.js";
|
|
3
|
+
import { RawAuthToken } from "@webiny/api-core/features/requestContext/index.js";
|
|
4
|
+
import type { IRequestIdentityLoader } from "@webiny/api-core/features/requestContext/abstractions.js";
|
|
5
|
+
import type { InputContext, NextFunction } from "@webiny/api-kernel-core";
|
|
6
|
+
/**
|
|
7
|
+
* EXTRACT (transport-specific): reads the auth token from a Node `IncomingMessage` β
|
|
8
|
+
* `x-webiny-authorization` first, then the bearer `Authorization` header, then the `wby-id-token`
|
|
9
|
+
* cookie (private file reads only) β into RawAuthToken, then invokes the shared LOAD step (RequestIdentityLoader) which
|
|
10
|
+
* authenticates it (via the registered identity provider, e.g. the self-hosted JWT IdP) and sets
|
|
11
|
+
* IdentityContext.
|
|
12
|
+
*
|
|
13
|
+
* `x-webiny-authorization` exists for AWS parity: behind CloudFront with Origin Access Control, SigV4
|
|
14
|
+
* occupies the `Authorization` header, so clients that may traverse such an origin send the token in
|
|
15
|
+
* that header instead. Standalone has no such constraint, but it accepts the same header so one
|
|
16
|
+
* client works against both deployments.
|
|
17
|
+
*
|
|
18
|
+
* A token an identity provider rejects ends the request with a 401. Any other error propagates.
|
|
19
|
+
*
|
|
20
|
+
* Node counterpart of ApiGatewayIdentityLoaderDecorator. Registered before the tenant loader, which
|
|
21
|
+
* makes it the inner wrapper: the tenant is loaded first, because API-key authentication looks the key up
|
|
22
|
+
* in the tenant's partition.
|
|
23
|
+
*/
|
|
24
|
+
declare class NodeHttpIdentityLoaderDecoratorImpl implements NodeHttpInputHandler.Interface {
|
|
25
|
+
private rawAuthToken;
|
|
26
|
+
private identityLoader;
|
|
27
|
+
private decoratee;
|
|
28
|
+
constructor(rawAuthToken: RawAuthToken.Interface, identityLoader: IRequestIdentityLoader, decoratee: NodeHttpInputHandler.Interface);
|
|
29
|
+
execute(ctx: InputContext<IncomingMessage>, next: NextFunction): Promise<any>;
|
|
30
|
+
}
|
|
31
|
+
export declare const NodeHttpIdentityLoaderDecorator: typeof NodeHttpIdentityLoaderDecoratorImpl & {
|
|
32
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-kernel-core/nodeHttp/index.js").INodeHttpInputHandler>;
|
|
33
|
+
};
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { NodeHttpInputHandler } from "@webiny/api-kernel-core/nodeHttp/index.js";
|
|
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
|
+
import { headersFromIncomingMessage } from "./headersFromIncomingMessage.js";
|
|
7
|
+
class NodeHttpIdentityLoaderDecoratorImpl {
|
|
8
|
+
constructor(rawAuthToken, identityLoader, decoratee){
|
|
9
|
+
this.rawAuthToken = rawAuthToken;
|
|
10
|
+
this.identityLoader = identityLoader;
|
|
11
|
+
this.decoratee = decoratee;
|
|
12
|
+
}
|
|
13
|
+
async execute(ctx, next) {
|
|
14
|
+
const headers = headersFromIncomingMessage(ctx.input);
|
|
15
|
+
const authToken = extractAuthToken(headers, {
|
|
16
|
+
method: ctx.input.method,
|
|
17
|
+
path: ctx.input.url
|
|
18
|
+
});
|
|
19
|
+
this.rawAuthToken.set(authToken);
|
|
20
|
+
try {
|
|
21
|
+
await this.identityLoader.establish();
|
|
22
|
+
} catch (error) {
|
|
23
|
+
if (error instanceof AuthenticationError) return rejectedTokenResponse(error, headers);
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
return this.decoratee.execute(ctx, next);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const NodeHttpIdentityLoaderDecorator = NodeHttpInputHandler.createDecorator({
|
|
30
|
+
decorator: NodeHttpIdentityLoaderDecoratorImpl,
|
|
31
|
+
dependencies: [
|
|
32
|
+
RawAuthToken,
|
|
33
|
+
RequestIdentityLoader
|
|
34
|
+
]
|
|
35
|
+
});
|
|
36
|
+
export { NodeHttpIdentityLoaderDecorator };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=NodeHttpIdentityLoaderDecorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodeHttp/NodeHttpIdentityLoaderDecorator.js","sources":["../../src/nodeHttp/NodeHttpIdentityLoaderDecorator.ts"],"sourcesContent":["import type { IncomingMessage } from \"node:http\";\nimport { NodeHttpInputHandler } from \"@webiny/api-kernel-core/nodeHttp/index.js\";\nimport {\n RawAuthToken,\n RequestIdentityLoader\n} from \"@webiny/api-core/features/requestContext/index.js\";\nimport type { IRequestIdentityLoader } from \"@webiny/api-core/features/requestContext/abstractions.js\";\nimport { AuthenticationError } from \"@webiny/api-core/features/security/authentication/AuthenticationContext/index.js\";\nimport type { InputContext, NextFunction } from \"@webiny/api-kernel-core\";\nimport { extractAuthToken } from \"~/auth/extractAuthToken.js\";\nimport { rejectedTokenResponse } from \"~/auth/rejectedTokenResponse.js\";\nimport { headersFromIncomingMessage } from \"./headersFromIncomingMessage.js\";\n\n/**\n * EXTRACT (transport-specific): reads the auth token from a Node `IncomingMessage` β\n * `x-webiny-authorization` first, then the bearer `Authorization` header, then the `wby-id-token`\n * cookie (private file reads only) β into RawAuthToken, then invokes the shared LOAD step (RequestIdentityLoader) which\n * authenticates it (via the registered identity provider, e.g. the self-hosted JWT IdP) and sets\n * IdentityContext.\n *\n * `x-webiny-authorization` exists for AWS parity: behind CloudFront with Origin Access Control, SigV4\n * occupies the `Authorization` header, so clients that may traverse such an origin send the token in\n * that header instead. Standalone has no such constraint, but it accepts the same header so one\n * client works against both deployments.\n *\n * A token an identity provider rejects ends the request with a 401. Any other error propagates.\n *\n * Node counterpart of ApiGatewayIdentityLoaderDecorator. Registered before the tenant loader, which\n * makes it the inner wrapper: the tenant is loaded first, because API-key authentication looks the key up\n * in the tenant's partition.\n */\nclass NodeHttpIdentityLoaderDecoratorImpl implements NodeHttpInputHandler.Interface {\n constructor(\n private rawAuthToken: RawAuthToken.Interface,\n private identityLoader: IRequestIdentityLoader,\n private decoratee: NodeHttpInputHandler.Interface\n ) {}\n\n async execute(ctx: InputContext<IncomingMessage>, next: NextFunction): Promise<any> {\n const headers = headersFromIncomingMessage(ctx.input);\n const authToken = extractAuthToken(headers, {\n method: ctx.input.method,\n path: ctx.input.url\n });\n this.rawAuthToken.set(authToken);\n try {\n await this.identityLoader.establish();\n } catch (error) {\n if (error instanceof AuthenticationError) {\n return rejectedTokenResponse(error, headers);\n }\n throw error;\n }\n return this.decoratee.execute(ctx, next);\n }\n}\n\nexport const NodeHttpIdentityLoaderDecorator = NodeHttpInputHandler.createDecorator({\n decorator: NodeHttpIdentityLoaderDecoratorImpl,\n dependencies: [RawAuthToken, RequestIdentityLoader]\n});\n"],"names":["NodeHttpIdentityLoaderDecoratorImpl","rawAuthToken","identityLoader","decoratee","ctx","next","headers","headersFromIncomingMessage","authToken","extractAuthToken","error","AuthenticationError","rejectedTokenResponse","NodeHttpIdentityLoaderDecorator","NodeHttpInputHandler","RawAuthToken","RequestIdentityLoader"],"mappings":";;;;;;AA+BA,MAAMA;IACF,YACYC,YAAoC,EACpCC,cAAsC,EACtCC,SAAyC,CACnD;aAHUF,YAAY,GAAZA;aACAC,cAAc,GAAdA;aACAC,SAAS,GAATA;IACT;IAEH,MAAM,QAAQC,GAAkC,EAAEC,IAAkB,EAAgB;QAChF,MAAMC,UAAUC,2BAA2BH,IAAI,KAAK;QACpD,MAAMI,YAAYC,iBAAiBH,SAAS;YACxC,QAAQF,IAAI,KAAK,CAAC,MAAM;YACxB,MAAMA,IAAI,KAAK,CAAC,GAAG;QACvB;QACA,IAAI,CAAC,YAAY,CAAC,GAAG,CAACI;QACtB,IAAI;YACA,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS;QACvC,EAAE,OAAOE,OAAO;YACZ,IAAIA,iBAAiBC,qBACjB,OAAOC,sBAAsBF,OAAOJ;YAExC,MAAMI;QACV;QACA,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAACN,KAAKC;IACvC;AACJ;AAEO,MAAMQ,kCAAkCC,qBAAqB,eAAe,CAAC;IAChF,WAAWd;IACX,cAAc;QAACe;QAAcC;KAAsB;AACvD"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { IncomingMessage } from "node:http";
|
|
2
|
+
import { NodeHttpInputHandler } from "@webiny/api-kernel-core/nodeHttp/index.js";
|
|
3
|
+
import { RawTenantId } from "@webiny/api-core/features/requestContext/index.js";
|
|
4
|
+
import type { IRequestTenantLoader } from "@webiny/api-core/features/requestContext/abstractions.js";
|
|
5
|
+
import type { InputContext, NextFunction } from "@webiny/api-kernel-core";
|
|
6
|
+
/**
|
|
7
|
+
* EXTRACT (transport-specific): reads the tenant id from the `x-tenant` header of a Node
|
|
8
|
+
* `IncomingMessage` into RawTenantId, then invokes the shared LOAD step (RequestTenantLoader) which
|
|
9
|
+
* resolves the Tenant and sets TenantContext. A missing header leaves RawTenantId null β the loader
|
|
10
|
+
* defaults to the "root" tenant.
|
|
11
|
+
*
|
|
12
|
+
* Node mirror of ApiGatewayTenantLoaderDecorator. Registered AFTER the identity loader.
|
|
13
|
+
*/
|
|
14
|
+
declare class NodeHttpTenantLoaderDecoratorImpl implements NodeHttpInputHandler.Interface {
|
|
15
|
+
private rawTenantId;
|
|
16
|
+
private tenantLoader;
|
|
17
|
+
private decoratee;
|
|
18
|
+
constructor(rawTenantId: RawTenantId.Interface, tenantLoader: IRequestTenantLoader, decoratee: NodeHttpInputHandler.Interface);
|
|
19
|
+
execute(ctx: InputContext<IncomingMessage>, next: NextFunction): Promise<any>;
|
|
20
|
+
}
|
|
21
|
+
export declare const NodeHttpTenantLoaderDecorator: typeof NodeHttpTenantLoaderDecoratorImpl & {
|
|
22
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-kernel-core/nodeHttp/index.js").INodeHttpInputHandler>;
|
|
23
|
+
};
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { NodeHttpInputHandler } from "@webiny/api-kernel-core/nodeHttp/index.js";
|
|
2
|
+
import { RawTenantId, RequestTenantLoader } from "@webiny/api-core/features/requestContext/index.js";
|
|
3
|
+
import { extractTenantId } from "../auth/extractTenantId.js";
|
|
4
|
+
import { headersFromIncomingMessage } from "./headersFromIncomingMessage.js";
|
|
5
|
+
class NodeHttpTenantLoaderDecoratorImpl {
|
|
6
|
+
constructor(rawTenantId, tenantLoader, decoratee){
|
|
7
|
+
this.rawTenantId = rawTenantId;
|
|
8
|
+
this.tenantLoader = tenantLoader;
|
|
9
|
+
this.decoratee = decoratee;
|
|
10
|
+
}
|
|
11
|
+
async execute(ctx, next) {
|
|
12
|
+
const headers = headersFromIncomingMessage(ctx.input);
|
|
13
|
+
const tenantId = extractTenantId(headers);
|
|
14
|
+
this.rawTenantId.set(tenantId);
|
|
15
|
+
await this.tenantLoader.establish();
|
|
16
|
+
return this.decoratee.execute(ctx, next);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const NodeHttpTenantLoaderDecorator = NodeHttpInputHandler.createDecorator({
|
|
20
|
+
decorator: NodeHttpTenantLoaderDecoratorImpl,
|
|
21
|
+
dependencies: [
|
|
22
|
+
RawTenantId,
|
|
23
|
+
RequestTenantLoader
|
|
24
|
+
]
|
|
25
|
+
});
|
|
26
|
+
export { NodeHttpTenantLoaderDecorator };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=NodeHttpTenantLoaderDecorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodeHttp/NodeHttpTenantLoaderDecorator.js","sources":["../../src/nodeHttp/NodeHttpTenantLoaderDecorator.ts"],"sourcesContent":["import type { IncomingMessage } from \"node:http\";\nimport { NodeHttpInputHandler } from \"@webiny/api-kernel-core/nodeHttp/index.js\";\nimport {\n RawTenantId,\n RequestTenantLoader\n} from \"@webiny/api-core/features/requestContext/index.js\";\nimport type { IRequestTenantLoader } from \"@webiny/api-core/features/requestContext/abstractions.js\";\nimport type { InputContext, NextFunction } from \"@webiny/api-kernel-core\";\nimport { extractTenantId } from \"~/auth/extractTenantId.js\";\nimport { headersFromIncomingMessage } from \"./headersFromIncomingMessage.js\";\n\n/**\n * EXTRACT (transport-specific): reads the tenant id from the `x-tenant` header of a Node\n * `IncomingMessage` into RawTenantId, then invokes the shared LOAD step (RequestTenantLoader) which\n * resolves the Tenant and sets TenantContext. A missing header leaves RawTenantId null β the loader\n * defaults to the \"root\" tenant.\n *\n * Node mirror of ApiGatewayTenantLoaderDecorator. Registered AFTER the identity loader.\n */\nclass NodeHttpTenantLoaderDecoratorImpl implements NodeHttpInputHandler.Interface {\n constructor(\n private rawTenantId: RawTenantId.Interface,\n private tenantLoader: IRequestTenantLoader,\n private decoratee: NodeHttpInputHandler.Interface\n ) {}\n\n async execute(ctx: InputContext<IncomingMessage>, next: NextFunction): Promise<any> {\n const headers = headersFromIncomingMessage(ctx.input);\n const tenantId = extractTenantId(headers);\n this.rawTenantId.set(tenantId);\n await this.tenantLoader.establish();\n return this.decoratee.execute(ctx, next);\n }\n}\n\nexport const NodeHttpTenantLoaderDecorator = NodeHttpInputHandler.createDecorator({\n decorator: NodeHttpTenantLoaderDecoratorImpl,\n dependencies: [RawTenantId, RequestTenantLoader]\n});\n"],"names":["NodeHttpTenantLoaderDecoratorImpl","rawTenantId","tenantLoader","decoratee","ctx","next","headers","headersFromIncomingMessage","tenantId","extractTenantId","NodeHttpTenantLoaderDecorator","NodeHttpInputHandler","RawTenantId","RequestTenantLoader"],"mappings":";;;;AAmBA,MAAMA;IACF,YACYC,WAAkC,EAClCC,YAAkC,EAClCC,SAAyC,CACnD;aAHUF,WAAW,GAAXA;aACAC,YAAY,GAAZA;aACAC,SAAS,GAATA;IACT;IAEH,MAAM,QAAQC,GAAkC,EAAEC,IAAkB,EAAgB;QAChF,MAAMC,UAAUC,2BAA2BH,IAAI,KAAK;QACpD,MAAMI,WAAWC,gBAAgBH;QACjC,IAAI,CAAC,WAAW,CAAC,GAAG,CAACE;QACrB,MAAM,IAAI,CAAC,YAAY,CAAC,SAAS;QACjC,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAACJ,KAAKC;IACvC;AACJ;AAEO,MAAMK,gCAAgCC,qBAAqB,eAAe,CAAC;IAC9E,WAAWX;IACX,cAAc;QAACY;QAAaC;KAAoB;AACpD"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { IncomingMessage } from "node:http";
|
|
2
|
+
/**
|
|
3
|
+
* Node gives a header that appears more than once as an array; the auth and tenant headers are read
|
|
4
|
+
* from the first value.
|
|
5
|
+
*/
|
|
6
|
+
export declare function headersFromIncomingMessage(event: IncomingMessage): Record<string, string>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
function headersFromIncomingMessage(event) {
|
|
2
|
+
const headers = {};
|
|
3
|
+
for (const [name, value] of Object.entries(event?.headers ?? {}))if (Array.isArray(value)) headers[name] = value[0] ?? "";
|
|
4
|
+
else if (void 0 !== value) headers[name] = value;
|
|
5
|
+
return headers;
|
|
6
|
+
}
|
|
7
|
+
export { headersFromIncomingMessage };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=headersFromIncomingMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodeHttp/headersFromIncomingMessage.js","sources":["../../src/nodeHttp/headersFromIncomingMessage.ts"],"sourcesContent":["import type { IncomingMessage } from \"node:http\";\n\n/**\n * Node gives a header that appears more than once as an array; the auth and tenant headers are read\n * from the first value.\n */\nexport function headersFromIncomingMessage(event: IncomingMessage): Record<string, string> {\n const headers: Record<string, string> = {};\n for (const [name, value] of Object.entries(event?.headers ?? {})) {\n if (Array.isArray(value)) {\n headers[name] = value[0] ?? \"\";\n } else if (value !== undefined) {\n headers[name] = value;\n }\n }\n return headers;\n}\n"],"names":["headersFromIncomingMessage","event","headers","name","value","Object","Array","undefined"],"mappings":"AAMO,SAASA,2BAA2BC,KAAsB;IAC7D,MAAMC,UAAkC,CAAC;IACzC,KAAK,MAAM,CAACC,MAAMC,MAAM,IAAIC,OAAO,OAAO,CAACJ,OAAO,WAAW,CAAC,GAC1D,IAAIK,MAAM,OAAO,CAACF,QACdF,OAAO,CAACC,KAAK,GAAGC,KAAK,CAAC,EAAE,IAAI;SACzB,IAAIA,AAAUG,WAAVH,OACPF,OAAO,CAACC,KAAK,GAAGC;IAGxB,OAAOF;AACX"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@webiny/api-composition-core",
|
|
3
|
+
"version": "0.0.0-unstable.e1999482d0",
|
|
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": "0.0.0-unstable.e1999482d0",
|
|
22
|
+
"@webiny/api-audit-logs": "0.0.0-unstable.e1999482d0",
|
|
23
|
+
"@webiny/api-core": "0.0.0-unstable.e1999482d0",
|
|
24
|
+
"@webiny/api-dashboard": "0.0.0-unstable.e1999482d0",
|
|
25
|
+
"@webiny/api-file-manager": "0.0.0-unstable.e1999482d0",
|
|
26
|
+
"@webiny/api-file-manager-aco": "0.0.0-unstable.e1999482d0",
|
|
27
|
+
"@webiny/api-graphql": "0.0.0-unstable.e1999482d0",
|
|
28
|
+
"@webiny/api-headless-cms": "0.0.0-unstable.e1999482d0",
|
|
29
|
+
"@webiny/api-headless-cms-aco": "0.0.0-unstable.e1999482d0",
|
|
30
|
+
"@webiny/api-headless-cms-scheduler": "0.0.0-unstable.e1999482d0",
|
|
31
|
+
"@webiny/api-headless-cms-tasks": "0.0.0-unstable.e1999482d0",
|
|
32
|
+
"@webiny/api-headless-cms-workflows": "0.0.0-unstable.e1999482d0",
|
|
33
|
+
"@webiny/api-kernel-core": "0.0.0-unstable.e1999482d0",
|
|
34
|
+
"@webiny/api-mailer": "0.0.0-unstable.e1999482d0",
|
|
35
|
+
"@webiny/api-record-locking": "0.0.0-unstable.e1999482d0",
|
|
36
|
+
"@webiny/api-scheduler": "0.0.0-unstable.e1999482d0",
|
|
37
|
+
"@webiny/api-website-builder": "0.0.0-unstable.e1999482d0",
|
|
38
|
+
"@webiny/api-website-builder-scheduler": "0.0.0-unstable.e1999482d0",
|
|
39
|
+
"@webiny/api-website-builder-workflows": "0.0.0-unstable.e1999482d0",
|
|
40
|
+
"@webiny/api-websockets": "0.0.0-unstable.e1999482d0",
|
|
41
|
+
"@webiny/api-workflows": "0.0.0-unstable.e1999482d0",
|
|
42
|
+
"@webiny/background-tasks": "0.0.0-unstable.e1999482d0",
|
|
43
|
+
"@webiny/feature": "0.0.0-unstable.e1999482d0",
|
|
44
|
+
"@webiny/handler": "0.0.0-unstable.e1999482d0",
|
|
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": "0.0.0-unstable.e1999482d0",
|
|
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,58 @@
|
|
|
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: every domain feature + the GraphQL
|
|
45
|
+
* engine, in the correct (order-sensitive) sequence. This is shared by all transport composition
|
|
46
|
+
* packages (`@webiny/api-composition-aws`, and the future `-server`) so the feature set and its
|
|
47
|
+
* ordering live in ONE place and can't drift between transports.
|
|
48
|
+
*
|
|
49
|
+
* Transport- and storage-specific pieces are injected via the hooks in {@link RegisterApiRequestStackConfig}
|
|
50
|
+
* at their exact interleave points. The caller is responsible for the ROOT-container transport wiring
|
|
51
|
+
* (HTTP/event transport, auth/tenant loaders, identity provider, DB + storage) before dispatch reaches
|
|
52
|
+
* this per-request stack. That includes the `Logger`: api-core registers none, so a root without one
|
|
53
|
+
* fails the first time anything that logs is built.
|
|
54
|
+
*
|
|
55
|
+
* ORDER IS LOAD-BEARING β do not reorder. Notably: extensions must be applied before anything that
|
|
56
|
+
* lists + caches the per-request model set; the GraphQL engine must be registered last.
|
|
57
|
+
*/
|
|
58
|
+
export declare function registerApiRequestStack(container: Container, config: RegisterApiRequestStackConfig): Promise<void>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { registerBuildParams, registerExtensions } from "@webiny/handler";
|
|
2
|
+
import { GraphQLEngineFeature } from "@webiny/api-graphql";
|
|
3
|
+
import { ApiCoreFeature, RequestStorage } from "@webiny/api-core";
|
|
4
|
+
import { WcpLicenseLoader } from "@webiny/api-core/features/wcp/WcpLicenseLoader.js";
|
|
5
|
+
import { HeadlessCmsFeature } from "@webiny/api-headless-cms";
|
|
6
|
+
import { AcoHcmsFeature } from "@webiny/api-headless-cms-aco";
|
|
7
|
+
import { HcmsTasksFeature } from "@webiny/api-headless-cms-tasks";
|
|
8
|
+
import { CmsWorkflowsFeature } from "@webiny/api-headless-cms-workflows";
|
|
9
|
+
import { CmsSchedulerFeature } from "@webiny/api-headless-cms-scheduler";
|
|
10
|
+
import { MailerFeature } from "@webiny/api-mailer";
|
|
11
|
+
import { RecordLockingAppFeature } from "@webiny/api-record-locking";
|
|
12
|
+
import { AuditLogsFeature } from "@webiny/api-audit-logs";
|
|
13
|
+
import { DashboardAppFeature } from "@webiny/api-dashboard";
|
|
14
|
+
import { AcoFeature } from "@webiny/api-aco";
|
|
15
|
+
import { BackgroundTasksFeature } from "@webiny/background-tasks/api";
|
|
16
|
+
import { FileManagerAppFeature } from "@webiny/api-file-manager";
|
|
17
|
+
import { FileManagerAcoFeature } from "@webiny/api-file-manager-aco";
|
|
18
|
+
import { WebsiteBuilderFeature } from "@webiny/api-website-builder";
|
|
19
|
+
import { WebsiteBuilderWorkflowsFeature } from "@webiny/api-website-builder-workflows";
|
|
20
|
+
import { WebsiteBuilderSchedulerFeature } from "@webiny/api-website-builder-scheduler";
|
|
21
|
+
import { WebsocketsFeature } from "@webiny/api-websockets";
|
|
22
|
+
import { WorkflowsFeature } from "@webiny/api-workflows";
|
|
23
|
+
import { SchedulerFeature } from "@webiny/api-scheduler";
|
|
24
|
+
async function registerApiRequestStack(container, config) {
|
|
25
|
+
await WcpLicenseLoader.load();
|
|
26
|
+
for (const storage of container.resolveAll(RequestStorage))await storage.register(container);
|
|
27
|
+
const extensions = config.extensions();
|
|
28
|
+
await registerBuildParams(container, extensions);
|
|
29
|
+
ApiCoreFeature.register(container, {
|
|
30
|
+
wcpLicense: void 0
|
|
31
|
+
});
|
|
32
|
+
await config.transports?.hostingConfig?.(container);
|
|
33
|
+
HeadlessCmsFeature.register(container, {
|
|
34
|
+
type: "manage"
|
|
35
|
+
});
|
|
36
|
+
AcoFeature.register(container);
|
|
37
|
+
AcoHcmsFeature.register(container);
|
|
38
|
+
HcmsTasksFeature.register(container);
|
|
39
|
+
FileManagerAppFeature.register(container);
|
|
40
|
+
FileManagerAcoFeature.register(container);
|
|
41
|
+
await config.transports?.fileManager?.(container);
|
|
42
|
+
WebsiteBuilderFeature.register(container);
|
|
43
|
+
WebsiteBuilderWorkflowsFeature.register(container);
|
|
44
|
+
WebsiteBuilderSchedulerFeature.register(container);
|
|
45
|
+
WebsocketsFeature.register(container);
|
|
46
|
+
await config.transports?.realtime?.(container);
|
|
47
|
+
MailerFeature.register(container);
|
|
48
|
+
RecordLockingAppFeature.register(container, {});
|
|
49
|
+
AuditLogsFeature.register(container, {});
|
|
50
|
+
DashboardAppFeature.register(container);
|
|
51
|
+
BackgroundTasksFeature.register(container);
|
|
52
|
+
WorkflowsFeature.register(container);
|
|
53
|
+
CmsWorkflowsFeature.register(container);
|
|
54
|
+
SchedulerFeature.register(container);
|
|
55
|
+
await config.transports?.scheduler?.(container);
|
|
56
|
+
CmsSchedulerFeature.register(container);
|
|
57
|
+
await registerExtensions(container, extensions);
|
|
58
|
+
GraphQLEngineFeature.register(container);
|
|
59
|
+
}
|
|
60
|
+
export { registerApiRequestStack };
|
|
61
|
+
|
|
62
|
+
//# 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 { registerBuildParams, registerExtensions } from \"@webiny/handler\";\nimport { GraphQLEngineFeature } from \"@webiny/api-graphql\";\nimport { ApiCoreFeature, RequestStorage } from \"@webiny/api-core\";\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: every domain feature + the GraphQL\n * engine, in the correct (order-sensitive) sequence. This is shared by all transport composition\n * packages (`@webiny/api-composition-aws`, and the future `-server`) so the feature set and its\n * ordering live in ONE place and can't drift between transports.\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, auth/tenant loaders, identity provider, 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 *\n * ORDER IS LOAD-BEARING β do not reorder. Notably: extensions must be applied before anything that\n * lists + caches the per-request model set; the GraphQL engine must be registered last.\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 // ββ Storage (before ANY feature) βββββββββββββββββββββββββββ\n // Every storage that registers per request put a `RequestStorage` in the root; each registers\n // its storages here, in this request'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 // ββ Build params (before ANY feature) ββββββββββββββββββββββ\n // Features gate themselves on FeatureFlags at register() time (AuditLogs, RecordLocking,\n // Workflows, ...), and FeatureFlags is a BuildParam. Registered with the rest of the extensions\n // below, it arrived too late: those gates read `{}`, and a license-granted feature couldn't be\n // disabled from config.\n const extensions = config.extensions();\n await registerBuildParams(container, extensions);\n\n // ββ Core API (per-request: EventPublisher + tenant/identity/request contexts must bind to the\n // request child container so per-request event handlers are resolvable) βββββββββ\n ApiCoreFeature.register(container, { wcpLicense: undefined });\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","storage","RequestStorage","extensions","registerBuildParams","ApiCoreFeature","undefined","HeadlessCmsFeature","AcoFeature","AcoHcmsFeature","HcmsTasksFeature","FileManagerAppFeature","FileManagerAcoFeature","WebsiteBuilderFeature","WebsiteBuilderWorkflowsFeature","WebsiteBuilderSchedulerFeature","WebsocketsFeature","MailerFeature","RecordLockingAppFeature","AuditLogsFeature","DashboardAppFeature","BackgroundTasksFeature","WorkflowsFeature","CmsWorkflowsFeature","SchedulerFeature","CmsSchedulerFeature","registerExtensions","GraphQLEngineFeature"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAkFO,eAAeA,wBAClBC,SAAoB,EACpBC,MAAqC;IAOrC,MAAMC,iBAAiB,IAAI;IAO3B,KAAK,MAAMC,WAAWH,UAAU,UAAU,CAACI,gBACvC,MAAMD,QAAQ,QAAQ,CAACH;IAQ3B,MAAMK,aAAaJ,OAAO,UAAU;IACpC,MAAMK,oBAAoBN,WAAWK;IAIrCE,eAAe,QAAQ,CAACP,WAAW;QAAE,YAAYQ;IAAU;IAC3D,MAAMP,OAAO,UAAU,EAAE,gBAAgBD;IAGzCS,mBAAmB,QAAQ,CAACT,WAAW;QAAE,MAAM;IAAS;IACxDU,WAAW,QAAQ,CAACV;IACpBW,eAAe,QAAQ,CAACX;IACxBY,iBAAiB,QAAQ,CAACZ;IAG1Ba,sBAAsB,QAAQ,CAACb;IAC/Bc,sBAAsB,QAAQ,CAACd;IAC/B,MAAMC,OAAO,UAAU,EAAE,cAAcD;IAGvCe,sBAAsB,QAAQ,CAACf;IAC/BgB,+BAA+B,QAAQ,CAAChB;IACxCiB,+BAA+B,QAAQ,CAACjB;IAGxCkB,kBAAkB,QAAQ,CAAClB;IAC3B,MAAMC,OAAO,UAAU,EAAE,WAAWD;IAGpCmB,cAAc,QAAQ,CAACnB;IACvBoB,wBAAwB,QAAQ,CAACpB,WAAW,CAAC;IAC7CqB,iBAAiB,QAAQ,CAACrB,WAAW,CAAC;IACtCsB,oBAAoB,QAAQ,CAACtB;IAC7BuB,uBAAuB,QAAQ,CAACvB;IAGhCwB,iBAAiB,QAAQ,CAACxB;IAC1ByB,oBAAoB,QAAQ,CAACzB;IAG7B0B,iBAAiB,QAAQ,CAAC1B;IAC1B,MAAMC,OAAO,UAAU,EAAE,YAAYD;IACrC2B,oBAAoB,QAAQ,CAAC3B;IAS7B,MAAM4B,mBAAmB5B,WAAWK;IAGpCwB,qBAAqB,QAAQ,CAAC7B;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";
|