@webiny/api-composition-standalone 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/bulkActions/bulkActionsServer.d.ts +6 -0
- package/bulkActions/bulkActionsServer.js +26 -0
- package/bulkActions/bulkActionsServer.js.map +1 -0
- package/config/abstractions.d.ts +34 -0
- package/config/abstractions.js +5 -0
- package/config/abstractions.js.map +1 -0
- package/config/assertFileStorage.d.ts +8 -0
- package/config/assertFileStorage.js +8 -0
- package/config/assertFileStorage.js.map +1 -0
- package/config/bakedSecrets.d.ts +8 -0
- package/config/bakedSecrets.js +17 -0
- package/config/bakedSecrets.js.map +1 -0
- package/config/readStandaloneConfig.d.ts +12 -0
- package/config/readStandaloneConfig.js +52 -0
- package/config/readStandaloneConfig.js.map +1 -0
- package/createWebinyApiHandler.d.ts +20 -0
- package/createWebinyApiHandler.js +133 -0
- package/createWebinyApiHandler.js.map +1 -0
- package/crypto/StandaloneEncryptionConfig.d.ts +17 -0
- package/crypto/StandaloneEncryptionConfig.js +20 -0
- package/crypto/StandaloneEncryptionConfig.js.map +1 -0
- package/crypto/StandaloneHashingConfig.d.ts +16 -0
- package/crypto/StandaloneHashingConfig.js +20 -0
- package/crypto/StandaloneHashingConfig.js.map +1 -0
- package/crypto/feature.d.ts +5 -0
- package/crypto/feature.js +13 -0
- package/crypto/feature.js.map +1 -0
- package/index.d.ts +2 -0
- package/index.js +1 -0
- package/package.json +51 -5
- package/publicUrls/ConfigPublicUrls.d.ts +13 -0
- package/publicUrls/ConfigPublicUrls.js +22 -0
- package/publicUrls/ConfigPublicUrls.js.map +1 -0
- package/publicUrls/feature.d.ts +4 -0
- package/publicUrls/feature.js +11 -0
- package/publicUrls/feature.js.map +1 -0
- package/scheduler/RecoverScheduledActionsHandler.d.ts +27 -0
- package/scheduler/RecoverScheduledActionsHandler.js +77 -0
- package/scheduler/RecoverScheduledActionsHandler.js.map +1 -0
- package/scheduler/RunScheduledActionOnceDecorator.d.ts +34 -0
- package/scheduler/RunScheduledActionOnceDecorator.js +89 -0
- package/scheduler/RunScheduledActionOnceDecorator.js.map +1 -0
- package/scheduler/ScheduledActionRecoverInputHandler.d.ts +14 -0
- package/scheduler/ScheduledActionRecoverInputHandler.js +5 -0
- package/scheduler/ScheduledActionRecoverInputHandler.js.map +1 -0
- package/scheduler/ScheduledActionRecoverInputType.d.ts +17 -0
- package/scheduler/ScheduledActionRecoverInputType.js +18 -0
- package/scheduler/ScheduledActionRecoverInputType.js.map +1 -0
- package/scheduler/abstractions/SchedulerSingleton.d.ts +10 -0
- package/scheduler/abstractions/SchedulerSingleton.js +5 -0
- package/scheduler/abstractions/SchedulerSingleton.js.map +1 -0
- package/scheduler/schedulerServer.d.ts +25 -0
- package/scheduler/schedulerServer.js +81 -0
- package/scheduler/schedulerServer.js.map +1 -0
- package/websockets/createWebsocketsAuthenticator.d.ts +4 -0
- package/websockets/createWebsocketsAuthenticator.js +49 -0
- package/websockets/createWebsocketsAuthenticator.js.map +1 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Container } from "@webiny/di";
|
|
2
|
+
import { type RegisterApiRequestStackConfig } from "@webiny/api-composition-core";
|
|
3
|
+
import type { WebsocketsConnectionAuthenticator } from "@webiny/api-websockets-standalone";
|
|
4
|
+
export declare function createWebsocketsAuthenticator(rootContainer: Container, extensions: RegisterApiRequestStackConfig["extensions"]): WebsocketsConnectionAuthenticator;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { RequestContainer } from "@webiny/api-kernel-core";
|
|
2
|
+
import { registerApiRequestStack } from "@webiny/api-composition-core";
|
|
3
|
+
import { AuthenticationError } from "@webiny/api-core/features/security/authentication/AuthenticationContext/index.js";
|
|
4
|
+
import { RawAuthToken, RawTenantId, RequestIdentityLoader, RequestTenantLoader, TenantNotFoundError } from "@webiny/api-core/features/requestContext/index.js";
|
|
5
|
+
import { TenantScopes } from "@webiny/api-core/features/tenancy/TenantScopes/index.js";
|
|
6
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
7
|
+
import { CanAccessCurrentTenantUseCase } from "@webiny/api-core/features/security/CanAccessCurrentTenant/index.js";
|
|
8
|
+
import { Logger } from "@webiny/api-core/features/logger/index.js";
|
|
9
|
+
const refuseOnAuthenticationError = (logger)=>(error)=>{
|
|
10
|
+
if (!(error instanceof AuthenticationError)) throw error;
|
|
11
|
+
logger.warn({
|
|
12
|
+
code: error.code,
|
|
13
|
+
error: error.message
|
|
14
|
+
}, "[websockets] handshake refused");
|
|
15
|
+
return false;
|
|
16
|
+
};
|
|
17
|
+
const refuseUnknownTenant = (error)=>{
|
|
18
|
+
if (error instanceof TenantNotFoundError) return false;
|
|
19
|
+
throw error;
|
|
20
|
+
};
|
|
21
|
+
function createWebsocketsAuthenticator(rootContainer, extensions) {
|
|
22
|
+
return async (token, tenantId)=>{
|
|
23
|
+
const child = rootContainer.createChildContainer();
|
|
24
|
+
child.registerInstance(RequestContainer, child);
|
|
25
|
+
await registerApiRequestStack(child, {
|
|
26
|
+
extensions
|
|
27
|
+
});
|
|
28
|
+
child.resolve(RawTenantId).set(tenantId);
|
|
29
|
+
child.resolve(RawAuthToken).set(token);
|
|
30
|
+
const tenant = await child.resolve(RequestTenantLoader).establish().catch(refuseUnknownTenant);
|
|
31
|
+
if (!tenant) return null;
|
|
32
|
+
return child.resolve(TenantScopes).withTenant(tenant, async (scope)=>{
|
|
33
|
+
const refuse = refuseOnAuthenticationError(scope.resolve(Logger));
|
|
34
|
+
const authenticated = await scope.resolve(RequestIdentityLoader).establish().then(()=>true).catch(refuse);
|
|
35
|
+
if (!authenticated) return null;
|
|
36
|
+
const canAccessTenant = await scope.resolve(CanAccessCurrentTenantUseCase).execute();
|
|
37
|
+
if (!canAccessTenant) return null;
|
|
38
|
+
const identity = scope.resolve(IdentityContext).getIdentity();
|
|
39
|
+
return {
|
|
40
|
+
id: identity.id,
|
|
41
|
+
displayName: identity.displayName,
|
|
42
|
+
type: identity.type
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export { createWebsocketsAuthenticator };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=createWebsocketsAuthenticator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websockets/createWebsocketsAuthenticator.js","sources":["../../src/websockets/createWebsocketsAuthenticator.ts"],"sourcesContent":["import type { Container } from \"@webiny/di\";\nimport { RequestContainer } from \"@webiny/api-kernel-core\";\nimport {\n registerApiRequestStack,\n type RegisterApiRequestStackConfig\n} from \"@webiny/api-composition-core\";\nimport { AuthenticationError } from \"@webiny/api-core/features/security/authentication/AuthenticationContext/index.js\";\nimport { RawTenantId } from \"@webiny/api-core/features/requestContext/index.js\";\nimport { RawAuthToken } from \"@webiny/api-core/features/requestContext/index.js\";\nimport { RequestTenantLoader } from \"@webiny/api-core/features/requestContext/index.js\";\nimport { TenantNotFoundError } from \"@webiny/api-core/features/requestContext/index.js\";\nimport { RequestIdentityLoader } from \"@webiny/api-core/features/requestContext/index.js\";\nimport { TenantScopes } from \"@webiny/api-core/features/tenancy/TenantScopes/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { CanAccessCurrentTenantUseCase } from \"@webiny/api-core/features/security/CanAccessCurrentTenant/index.js\";\nimport { Logger } from \"@webiny/api-core/features/logger/index.js\";\nimport type { WebsocketsConnectionAuthenticator } from \"@webiny/api-websockets-standalone\";\n\n/*\n * An `AuthenticationError` refuses the handshake rather than failing it. That includes more than bad\n * tokens: `AuthenticationError.from` wraps every error an authenticator throws, a failed key lookup\n * as well, so the reason is logged here, where it would otherwise be lost.\n */\nconst refuseOnAuthenticationError = (logger: Logger.Interface) => {\n return (error: unknown): false => {\n if (!(error instanceof AuthenticationError)) {\n throw error;\n }\n logger.warn({ code: error.code, error: error.message }, \"[websockets] handshake refused\");\n return false;\n };\n};\n\n/**\n * Builds the `authenticate` callback the server WebSocket upgrade acceptor uses to turn a\n * connection's `?token` JWT into an identity in the connection's `?tenant`, in that tenant's scope.\n *\n * Each new WebSocket connection (the HTTP upgrade handshake) is authenticated from its `?token` JWT\n * so the connection is registered under the real identity — targeted server→client sends need this,\n * since SendToIdentity matches connections by identity id. The catch is that AuthenticationContext\n * lives in the per-request stack (registered by ApiCoreFeature, not registerRootStorage), so we can't\n * resolve it from the root container. Instead we spin up a short-lived request-scoped child container,\n * the same way createHandler does for each HTTP request, and resolve it there. We only need the core\n * stack, not the transports. Like an HTTP transport, it only extracts the raw tenant id and token and\n * leaves the rest to the shared request loaders, tenant first, because an API key is looked up in the\n * current tenant. The identity must then be able to access that tenant: the client names the tenant,\n * so a valid token alone would let a user of one tenant receive another tenant's messages.\n * Connections are rare (one per admin session), so a fresh child per connection is cheap enough.\n *\n * This is also why the WebSocket server takes `authenticate` as a plain callback instead of resolving\n * auth itself: AuthenticationContext isn't reachable from the root container (it's per-request), so\n * only the handler — which can build a request-scoped child — can supply it. So authenticate has to be\n * a callback the handler builds, regardless of DI.\n */\nconst refuseUnknownTenant = (error: unknown): false => {\n if (error instanceof TenantNotFoundError) {\n return false;\n }\n throw error;\n};\n\nexport function createWebsocketsAuthenticator(\n rootContainer: Container,\n extensions: RegisterApiRequestStackConfig[\"extensions\"]\n): WebsocketsConnectionAuthenticator {\n return async (token, tenantId) => {\n const child = rootContainer.createChildContainer();\n child.registerInstance(RequestContainer, child);\n await registerApiRequestStack(child, { extensions });\n\n child.resolve(RawTenantId).set(tenantId);\n child.resolve(RawAuthToken).set(token);\n\n const tenant = await child\n .resolve(RequestTenantLoader)\n .establish()\n .catch(refuseUnknownTenant);\n // An unknown tenant refuses the handshake rather than failing it.\n if (!tenant) {\n return null;\n }\n\n // Identity is the tenant's: an API key is looked up in it, and access is checked against it.\n return child.resolve(TenantScopes).withTenant(tenant, async scope => {\n const refuse = refuseOnAuthenticationError(scope.resolve(Logger));\n const authenticated = await scope\n .resolve(RequestIdentityLoader)\n .establish()\n .then(() => true)\n .catch(refuse);\n if (!authenticated) {\n return null;\n }\n\n // False for the anonymous identity, which is what a token no authenticator recognises gives.\n const canAccessTenant = await scope.resolve(CanAccessCurrentTenantUseCase).execute();\n if (!canAccessTenant) {\n return null;\n }\n\n const identity = scope.resolve(IdentityContext).getIdentity();\n return {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n };\n });\n };\n}\n"],"names":["refuseOnAuthenticationError","logger","error","AuthenticationError","refuseUnknownTenant","TenantNotFoundError","createWebsocketsAuthenticator","rootContainer","extensions","token","tenantId","child","RequestContainer","registerApiRequestStack","RawTenantId","RawAuthToken","tenant","RequestTenantLoader","TenantScopes","scope","refuse","Logger","authenticated","RequestIdentityLoader","canAccessTenant","CanAccessCurrentTenantUseCase","identity","IdentityContext"],"mappings":";;;;;;;;AAuBA,MAAMA,8BAA8B,CAACC,SAC1B,CAACC;QACJ,IAAI,CAAEA,CAAAA,iBAAiBC,mBAAkB,GACrC,MAAMD;QAEVD,OAAO,IAAI,CAAC;YAAE,MAAMC,MAAM,IAAI;YAAE,OAAOA,MAAM,OAAO;QAAC,GAAG;QACxD,OAAO;IACX;AAwBJ,MAAME,sBAAsB,CAACF;IACzB,IAAIA,iBAAiBG,qBACjB,OAAO;IAEX,MAAMH;AACV;AAEO,SAASI,8BACZC,aAAwB,EACxBC,UAAuD;IAEvD,OAAO,OAAOC,OAAOC;QACjB,MAAMC,QAAQJ,cAAc,oBAAoB;QAChDI,MAAM,gBAAgB,CAACC,kBAAkBD;QACzC,MAAME,wBAAwBF,OAAO;YAAEH;QAAW;QAElDG,MAAM,OAAO,CAACG,aAAa,GAAG,CAACJ;QAC/BC,MAAM,OAAO,CAACI,cAAc,GAAG,CAACN;QAEhC,MAAMO,SAAS,MAAML,MAChB,OAAO,CAACM,qBACR,SAAS,GACT,KAAK,CAACb;QAEX,IAAI,CAACY,QACD,OAAO;QAIX,OAAOL,MAAM,OAAO,CAACO,cAAc,UAAU,CAACF,QAAQ,OAAMG;YACxD,MAAMC,SAASpB,4BAA4BmB,MAAM,OAAO,CAACE;YACzD,MAAMC,gBAAgB,MAAMH,MACvB,OAAO,CAACI,uBACR,SAAS,GACT,IAAI,CAAC,IAAM,MACX,KAAK,CAACH;YACX,IAAI,CAACE,eACD,OAAO;YAIX,MAAME,kBAAkB,MAAML,MAAM,OAAO,CAACM,+BAA+B,OAAO;YAClF,IAAI,CAACD,iBACD,OAAO;YAGX,MAAME,WAAWP,MAAM,OAAO,CAACQ,iBAAiB,WAAW;YAC3D,OAAO;gBACH,IAAID,SAAS,EAAE;gBACf,aAAaA,SAAS,WAAW;gBACjC,MAAMA,SAAS,IAAI;YACvB;QACJ;IACJ;AACJ"}
|