@webiny/api-composition-core 6.6.0-alpha.13 → 6.6.0-alpha.14
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/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { registerApiRequestStack, registerApiRequestStackInOneContainer, registerApiTenantScope } from "./registerApiRequestStack.js";
|
|
2
|
-
export type { RegisterApiRequestStackConfig } from "./registerApiRequestStack.js";
|
|
2
|
+
export type { RegisterApiRequestStackConfig, RegisterApiRequestStackInOneContainerOptions } from "./registerApiRequestStack.js";
|
|
3
3
|
export { createLogger } from "./logger/createLogger.js";
|
|
4
4
|
export { extractAuthToken, isCookieAuthenticationAllowed } from "./auth/index.js";
|
|
5
5
|
export { extractTenantId } from "./auth/index.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-composition-core",
|
|
3
|
-
"version": "6.6.0-alpha.
|
|
3
|
+
"version": "6.6.0-alpha.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"exports": {
|
|
@@ -18,30 +18,30 @@
|
|
|
18
18
|
],
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@webiny/api-aco": "6.6.0-alpha.
|
|
22
|
-
"@webiny/api-audit-logs": "6.6.0-alpha.
|
|
23
|
-
"@webiny/api-core": "6.6.0-alpha.
|
|
24
|
-
"@webiny/api-dashboard": "6.6.0-alpha.
|
|
25
|
-
"@webiny/api-file-manager": "6.6.0-alpha.
|
|
26
|
-
"@webiny/api-file-manager-aco": "6.6.0-alpha.
|
|
27
|
-
"@webiny/api-graphql": "6.6.0-alpha.
|
|
28
|
-
"@webiny/api-headless-cms": "6.6.0-alpha.
|
|
29
|
-
"@webiny/api-headless-cms-aco": "6.6.0-alpha.
|
|
30
|
-
"@webiny/api-headless-cms-scheduler": "6.6.0-alpha.
|
|
31
|
-
"@webiny/api-headless-cms-tasks": "6.6.0-alpha.
|
|
32
|
-
"@webiny/api-headless-cms-workflows": "6.6.0-alpha.
|
|
33
|
-
"@webiny/api-kernel-core": "6.6.0-alpha.
|
|
34
|
-
"@webiny/api-mailer": "6.6.0-alpha.
|
|
35
|
-
"@webiny/api-record-locking": "6.6.0-alpha.
|
|
36
|
-
"@webiny/api-scheduler": "6.6.0-alpha.
|
|
37
|
-
"@webiny/api-website-builder": "6.6.0-alpha.
|
|
38
|
-
"@webiny/api-website-builder-scheduler": "6.6.0-alpha.
|
|
39
|
-
"@webiny/api-website-builder-workflows": "6.6.0-alpha.
|
|
40
|
-
"@webiny/api-websockets": "6.6.0-alpha.
|
|
41
|
-
"@webiny/api-workflows": "6.6.0-alpha.
|
|
42
|
-
"@webiny/background-tasks": "6.6.0-alpha.
|
|
43
|
-
"@webiny/feature": "6.6.0-alpha.
|
|
44
|
-
"@webiny/handler": "6.6.0-alpha.
|
|
21
|
+
"@webiny/api-aco": "6.6.0-alpha.14",
|
|
22
|
+
"@webiny/api-audit-logs": "6.6.0-alpha.14",
|
|
23
|
+
"@webiny/api-core": "6.6.0-alpha.14",
|
|
24
|
+
"@webiny/api-dashboard": "6.6.0-alpha.14",
|
|
25
|
+
"@webiny/api-file-manager": "6.6.0-alpha.14",
|
|
26
|
+
"@webiny/api-file-manager-aco": "6.6.0-alpha.14",
|
|
27
|
+
"@webiny/api-graphql": "6.6.0-alpha.14",
|
|
28
|
+
"@webiny/api-headless-cms": "6.6.0-alpha.14",
|
|
29
|
+
"@webiny/api-headless-cms-aco": "6.6.0-alpha.14",
|
|
30
|
+
"@webiny/api-headless-cms-scheduler": "6.6.0-alpha.14",
|
|
31
|
+
"@webiny/api-headless-cms-tasks": "6.6.0-alpha.14",
|
|
32
|
+
"@webiny/api-headless-cms-workflows": "6.6.0-alpha.14",
|
|
33
|
+
"@webiny/api-kernel-core": "6.6.0-alpha.14",
|
|
34
|
+
"@webiny/api-mailer": "6.6.0-alpha.14",
|
|
35
|
+
"@webiny/api-record-locking": "6.6.0-alpha.14",
|
|
36
|
+
"@webiny/api-scheduler": "6.6.0-alpha.14",
|
|
37
|
+
"@webiny/api-website-builder": "6.6.0-alpha.14",
|
|
38
|
+
"@webiny/api-website-builder-scheduler": "6.6.0-alpha.14",
|
|
39
|
+
"@webiny/api-website-builder-workflows": "6.6.0-alpha.14",
|
|
40
|
+
"@webiny/api-websockets": "6.6.0-alpha.14",
|
|
41
|
+
"@webiny/api-workflows": "6.6.0-alpha.14",
|
|
42
|
+
"@webiny/background-tasks": "6.6.0-alpha.14",
|
|
43
|
+
"@webiny/feature": "6.6.0-alpha.14",
|
|
44
|
+
"@webiny/handler": "6.6.0-alpha.14",
|
|
45
45
|
"pino": "10.4.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/jsonwebtoken": "9.0.10",
|
|
52
|
-
"@webiny/build-tools": "6.6.0-alpha.
|
|
52
|
+
"@webiny/build-tools": "6.6.0-alpha.14",
|
|
53
53
|
"@webiny/di": "2.0.0",
|
|
54
54
|
"jsonwebtoken": "9.0.3",
|
|
55
55
|
"rimraf": "6.1.4",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Container } from "@webiny/di";
|
|
2
2
|
import { registerExtensions } from "@webiny/handler";
|
|
3
|
+
import type { TenantStorageBackend } from "@webiny/api-core/features/tenancy/TenantStorages/index.js";
|
|
3
4
|
/** Installs a hosting-specific transport adapter into the per-request container at its interleave point. */
|
|
4
5
|
export type TransportRegistrar = (container: Container) => void | Promise<void>;
|
|
5
6
|
export interface RegisterApiRequestStackConfig {
|
|
@@ -45,8 +46,8 @@ export interface RegisterApiRequestStackConfig {
|
|
|
45
46
|
* composition packages (`@webiny/api-composition-aws`, `-standalone`) so the feature set and its
|
|
46
47
|
* ordering live in ONE place and can't drift between transports.
|
|
47
48
|
*
|
|
48
|
-
* The request container gets only the tenant-neutral part: the raw request values, the
|
|
49
|
-
*
|
|
49
|
+
* The request container gets only the tenant-neutral part: the raw request values, the request's
|
|
50
|
+
* tenant cache and `TenantScopes`. It holds no storage: the request's tenant is read in root's scope. Build params come from the
|
|
50
51
|
* deploy, the same for every request and tenant, so the transport registers them once in the root
|
|
51
52
|
* (`registerRootBuildParams`), before any request registers a feature that reads them (features
|
|
52
53
|
* gate themselves on `FeatureFlags`, a build param, at register() time). Everything else is
|
|
@@ -61,19 +62,25 @@ export interface RegisterApiRequestStackConfig {
|
|
|
61
62
|
* fails the first time anything that logs is built.
|
|
62
63
|
*/
|
|
63
64
|
export declare function registerApiRequestStack(container: Container, config: RegisterApiRequestStackConfig): Promise<void>;
|
|
65
|
+
export interface RegisterApiRequestStackInOneContainerOptions {
|
|
66
|
+
/** The storage's backend to register. Default: the default storage's. */
|
|
67
|
+
backend?: TenantStorageBackend.Interface;
|
|
68
|
+
}
|
|
64
69
|
/**
|
|
65
|
-
* Registers the request stack in ONE container: the tenant-neutral part and a tenant scope's part
|
|
66
|
-
*
|
|
67
|
-
*
|
|
70
|
+
* Registers the request stack in ONE container: the tenant-neutral part and a tenant scope's part on
|
|
71
|
+
* the default storage, or on the storage of `options.backend`. For work outside a request that needs
|
|
72
|
+
* everything a request has, without a tenant: the SQL schema setup, which sets up the tables of
|
|
73
|
+
* exactly the storages and modules the API runs, once per storage.
|
|
68
74
|
*
|
|
69
75
|
* The container is its own `RequestContainer`, as a request's is: services built while it
|
|
70
76
|
* registers (`TenantContext`, through `TenantScopes`) depend on it.
|
|
71
77
|
*/
|
|
72
|
-
export declare function registerApiRequestStackInOneContainer(container: Container, config: RegisterApiRequestStackConfig): Promise<void>;
|
|
78
|
+
export declare function registerApiRequestStackInOneContainer(container: Container, config: RegisterApiRequestStackConfig, options?: RegisterApiRequestStackInOneContainerOptions): Promise<void>;
|
|
73
79
|
/**
|
|
74
80
|
* Registers a tenant scope's part of the request stack: every domain feature + the GraphQL engine,
|
|
75
81
|
* in the correct (order-sensitive) sequence, on top of the tenant-neutral part its parent (the
|
|
76
|
-
* request container) has.
|
|
82
|
+
* request container) has. The scope's storage is already there: `TenantScopes` registers the
|
|
83
|
+
* scope's storage backend first.
|
|
77
84
|
*
|
|
78
85
|
* ORDER IS LOAD-BEARING — do not reorder. Notably: extensions must be applied before anything that
|
|
79
86
|
* lists + caches the scope's model set; the GraphQL engine must be registered last.
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { registerExtensions } from "@webiny/handler";
|
|
2
2
|
import { RequestContainer } from "@webiny/api-kernel-core";
|
|
3
3
|
import { GraphQLEngineFeature } from "@webiny/api-graphql";
|
|
4
|
-
import { ApiCoreFeature
|
|
4
|
+
import { ApiCoreFeature } from "@webiny/api-core";
|
|
5
5
|
import { TenantNeutralRequestFeature, TenantScopeRegistration } from "@webiny/api-core/features/tenancy/TenantScopes/index.js";
|
|
6
|
+
import { DEFAULT_TENANT_STORAGE, TenantStorages, createDefaultTenantStorageBackend } from "@webiny/api-core/features/tenancy/TenantStorages/index.js";
|
|
6
7
|
import { WcpLicenseLoader } from "@webiny/api-core/features/wcp/WcpLicenseLoader.js";
|
|
7
8
|
import { HeadlessCmsFeature } from "@webiny/api-headless-cms";
|
|
8
9
|
import { AcoHcmsFeature } from "@webiny/api-headless-cms-aco";
|
|
@@ -31,13 +32,19 @@ async function registerApiRequestStack(container, config) {
|
|
|
31
32
|
register: (scope)=>registerApiTenantScope(scope, config, extensions)
|
|
32
33
|
});
|
|
33
34
|
}
|
|
34
|
-
async function registerApiRequestStackInOneContainer(container, config) {
|
|
35
|
+
async function registerApiRequestStackInOneContainer(container, config, options = {}) {
|
|
35
36
|
container.registerInstance(RequestContainer, container);
|
|
36
37
|
await registerApiRequestStack(container, config);
|
|
38
|
+
const backend = options.backend ?? getDefaultBackend(container);
|
|
39
|
+
await backend.registerScope(container);
|
|
37
40
|
await registerApiTenantScope(container, config);
|
|
38
41
|
}
|
|
42
|
+
const getDefaultBackend = (container)=>{
|
|
43
|
+
const [storages] = container.resolveAll(TenantStorages);
|
|
44
|
+
const declared = storages?.getBackend(DEFAULT_TENANT_STORAGE);
|
|
45
|
+
return declared ?? createDefaultTenantStorageBackend();
|
|
46
|
+
};
|
|
39
47
|
async function registerApiTenantScope(container, config, extensions = config.extensions()) {
|
|
40
|
-
for (const storage of container.resolveAll(RequestStorage))await storage.register(container);
|
|
41
48
|
ApiCoreFeature.register(container, {
|
|
42
49
|
wcpLicense: void 0,
|
|
43
50
|
tenantScope: true
|
|
@@ -1 +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"}
|
|
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 } from \"@webiny/api-core\";\nimport { TenantNeutralRequestFeature } from \"@webiny/api-core/features/tenancy/TenantScopes/index.js\";\nimport { TenantScopeRegistration } from \"@webiny/api-core/features/tenancy/TenantScopes/index.js\";\nimport { TenantStorages } from \"@webiny/api-core/features/tenancy/TenantStorages/index.js\";\nimport { DEFAULT_TENANT_STORAGE } from \"@webiny/api-core/features/tenancy/TenantStorages/index.js\";\nimport { createDefaultTenantStorageBackend } from \"@webiny/api-core/features/tenancy/TenantStorages/index.js\";\nimport type { TenantStorageBackend } from \"@webiny/api-core/features/tenancy/TenantStorages/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 request's\n * tenant cache and `TenantScopes`. It holds no storage: the request's tenant is read in root's scope. 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 cache, 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\nexport interface RegisterApiRequestStackInOneContainerOptions {\n /** The storage's backend to register. Default: the default storage's. */\n backend?: TenantStorageBackend.Interface;\n}\n\n/**\n * Registers the request stack in ONE container: the tenant-neutral part and a tenant scope's part on\n * the default storage, or on the storage of `options.backend`. For work outside a request that needs\n * everything a request has, without a tenant: the SQL schema setup, which sets up the tables of\n * exactly the storages and modules the API runs, once per storage.\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 options: RegisterApiRequestStackInOneContainerOptions = {}\n): Promise<void> {\n container.registerInstance(RequestContainer, container);\n await registerApiRequestStack(container, config);\n\n // A tenant scope gets its storage from `TenantScopes`; this container is none, so it registers\n // the storage's itself, before any feature.\n const backend = options.backend ?? getDefaultBackend(container);\n await backend.registerScope(container);\n\n await registerApiTenantScope(container, config);\n}\n\nconst getDefaultBackend = (container: Container): TenantStorageBackend.Interface => {\n const [storages] = container.resolveAll(TenantStorages);\n const declared = storages?.getBackend(DEFAULT_TENANT_STORAGE);\n return declared ?? createDefaultTenantStorageBackend();\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. The scope's storage is already there: `TenantScopes` registers the\n * scope's storage backend first.\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 // ── 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","options","RequestContainer","backend","getDefaultBackend","storages","TenantStorages","declared","DEFAULT_TENANT_STORAGE","createDefaultTenantStorageBackend","ApiCoreFeature","undefined","HeadlessCmsFeature","AcoFeature","AcoHcmsFeature","HcmsTasksFeature","FileManagerAppFeature","FileManagerAcoFeature","WebsiteBuilderFeature","WebsiteBuilderWorkflowsFeature","WebsiteBuilderSchedulerFeature","WebsocketsFeature","MailerFeature","RecordLockingAppFeature","AuditLogsFeature","DashboardAppFeature","BackgroundTasksFeature","WorkflowsFeature","CmsWorkflowsFeature","SchedulerFeature","CmsSchedulerFeature","registerExtensions","GraphQLEngineFeature"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA8FO,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;AAgBO,eAAeK,sCAClBR,SAAoB,EACpBC,MAAqC,EACrCQ,UAAwD,CAAC,CAAC;IAE1DT,UAAU,gBAAgB,CAACU,kBAAkBV;IAC7C,MAAMD,wBAAwBC,WAAWC;IAIzC,MAAMU,UAAUF,QAAQ,OAAO,IAAIG,kBAAkBZ;IACrD,MAAMW,QAAQ,aAAa,CAACX;IAE5B,MAAMO,uBAAuBP,WAAWC;AAC5C;AAEA,MAAMW,oBAAoB,CAACZ;IACvB,MAAM,CAACa,SAAS,GAAGb,UAAU,UAAU,CAACc;IACxC,MAAMC,WAAWF,UAAU,WAAWG;IACtC,OAAOD,YAAYE;AACvB;AAWO,eAAeV,uBAClBP,SAAoB,EACpBC,MAAqC,EACrCE,aAAsEF,OAAO,UAAU,EAAE;IAIzFiB,eAAe,QAAQ,CAAClB,WAAW;QAAE,YAAYmB;QAAW,aAAa;IAAK;IAC9E,MAAMlB,OAAO,UAAU,EAAE,gBAAgBD;IAGzCoB,mBAAmB,QAAQ,CAACpB,WAAW;QAAE,MAAM;IAAS;IACxDqB,WAAW,QAAQ,CAACrB;IACpBsB,eAAe,QAAQ,CAACtB;IACxBuB,iBAAiB,QAAQ,CAACvB;IAG1BwB,sBAAsB,QAAQ,CAACxB;IAC/ByB,sBAAsB,QAAQ,CAACzB;IAC/B,MAAMC,OAAO,UAAU,EAAE,cAAcD;IAGvC0B,sBAAsB,QAAQ,CAAC1B;IAC/B2B,+BAA+B,QAAQ,CAAC3B;IACxC4B,+BAA+B,QAAQ,CAAC5B;IAGxC6B,kBAAkB,QAAQ,CAAC7B;IAC3B,MAAMC,OAAO,UAAU,EAAE,WAAWD;IAGpC8B,cAAc,QAAQ,CAAC9B;IACvB+B,wBAAwB,QAAQ,CAAC/B,WAAW,CAAC;IAC7CgC,iBAAiB,QAAQ,CAAChC,WAAW,CAAC;IACtCiC,oBAAoB,QAAQ,CAACjC;IAC7BkC,uBAAuB,QAAQ,CAAClC;IAGhCmC,iBAAiB,QAAQ,CAACnC;IAC1BoC,oBAAoB,QAAQ,CAACpC;IAG7BqC,iBAAiB,QAAQ,CAACrC;IAC1B,MAAMC,OAAO,UAAU,EAAE,YAAYD;IACrCsC,oBAAoB,QAAQ,CAACtC;IAS7B,MAAMuC,mBAAmBvC,WAAWG;IAGpCqC,qBAAqB,QAAQ,CAACxC;AAClC"}
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import type { Container } from "@webiny/di";
|
|
2
|
+
import type { TenantStorageBackend } from "@webiny/api-core/features/tenancy/TenantStorages/index.js";
|
|
3
|
+
export interface IApiRequestRegistrationOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The storage to register, as a tenant scope on it would: an extra storage's backend (the SQL
|
|
6
|
+
* schema setup binds it to its own connection). Default: the default storage's.
|
|
7
|
+
*/
|
|
8
|
+
backend?: TenantStorageBackend.Interface;
|
|
9
|
+
}
|
|
2
10
|
export interface IApiRequestRegistration {
|
|
3
11
|
/**
|
|
4
12
|
* Registers what a request has into `container`, exactly as the transport does for every request
|
|
5
|
-
* (its `child` step)
|
|
6
|
-
*
|
|
13
|
+
* (its `child` step) and the tenant scope on the storage: the storage (the default storage's
|
|
14
|
+
* backend unless `options.backend` names another), the API's features with the transport's
|
|
15
|
+
* adapters, and the project's extensions.
|
|
7
16
|
*/
|
|
8
|
-
register(container: Container): Promise<void>;
|
|
17
|
+
register(container: Container, options?: IApiRequestRegistrationOptions): Promise<void>;
|
|
9
18
|
}
|
|
10
19
|
/**
|
|
11
20
|
* The transport's request registration, in the root container. Lets work that runs outside any
|
|
@@ -15,4 +24,5 @@ export interface IApiRequestRegistration {
|
|
|
15
24
|
export declare const ApiRequestRegistration: import("@webiny/di").Abstraction<IApiRequestRegistration>;
|
|
16
25
|
export declare namespace ApiRequestRegistration {
|
|
17
26
|
type Interface = IApiRequestRegistration;
|
|
27
|
+
type Options = IApiRequestRegistrationOptions;
|
|
18
28
|
}
|
|
@@ -1 +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
|
|
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\";\nimport type { TenantStorageBackend } from \"@webiny/api-core/features/tenancy/TenantStorages/index.js\";\n\nexport interface IApiRequestRegistrationOptions {\n /**\n * The storage to register, as a tenant scope on it would: an extra storage's backend (the SQL\n * schema setup binds it to its own connection). Default: the default storage's.\n */\n backend?: TenantStorageBackend.Interface;\n}\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) and the tenant scope on the storage: the storage (the default storage's\n * backend unless `options.backend` names another), the API's features with the transport's\n * adapters, and the project's extensions.\n */\n register(container: Container, options?: IApiRequestRegistrationOptions): 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 export type Options = IApiRequestRegistrationOptions;\n}\n"],"names":["ApiRequestRegistration","createAbstraction"],"mappings":";AA2BO,MAAMA,yBAAyBC,kBAClC"}
|