@webiny/api-composition-standalone 0.0.0-stage → 0.0.0-unstable.48a4e5b6c1

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.
Files changed (62) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +10 -2
  3. package/bulkActions/bulkActionsServer.d.ts +6 -0
  4. package/bulkActions/bulkActionsServer.js +26 -0
  5. package/bulkActions/bulkActionsServer.js.map +1 -0
  6. package/config/abstractions.d.ts +40 -0
  7. package/config/abstractions.js +5 -0
  8. package/config/abstractions.js.map +1 -0
  9. package/config/assertFileStorage.d.ts +8 -0
  10. package/config/assertFileStorage.js +8 -0
  11. package/config/assertFileStorage.js.map +1 -0
  12. package/config/bakedSecrets.d.ts +8 -0
  13. package/config/bakedSecrets.js +17 -0
  14. package/config/bakedSecrets.js.map +1 -0
  15. package/config/readStandaloneConfig.d.ts +12 -0
  16. package/config/readStandaloneConfig.js +56 -0
  17. package/config/readStandaloneConfig.js.map +1 -0
  18. package/createWebinyApiHandler.d.ts +20 -0
  19. package/createWebinyApiHandler.js +139 -0
  20. package/createWebinyApiHandler.js.map +1 -0
  21. package/crypto/StandaloneEncryptionConfig.d.ts +17 -0
  22. package/crypto/StandaloneEncryptionConfig.js +20 -0
  23. package/crypto/StandaloneEncryptionConfig.js.map +1 -0
  24. package/crypto/StandaloneHashingConfig.d.ts +16 -0
  25. package/crypto/StandaloneHashingConfig.js +20 -0
  26. package/crypto/StandaloneHashingConfig.js.map +1 -0
  27. package/crypto/feature.d.ts +5 -0
  28. package/crypto/feature.js +13 -0
  29. package/crypto/feature.js.map +1 -0
  30. package/index.d.ts +3 -0
  31. package/index.js +2 -0
  32. package/package.json +51 -5
  33. package/publicUrls/ConfigPublicUrls.d.ts +13 -0
  34. package/publicUrls/ConfigPublicUrls.js +22 -0
  35. package/publicUrls/ConfigPublicUrls.js.map +1 -0
  36. package/publicUrls/feature.d.ts +4 -0
  37. package/publicUrls/feature.js +11 -0
  38. package/publicUrls/feature.js.map +1 -0
  39. package/scheduler/RecoverScheduledActionsHandler.d.ts +27 -0
  40. package/scheduler/RecoverScheduledActionsHandler.js +77 -0
  41. package/scheduler/RecoverScheduledActionsHandler.js.map +1 -0
  42. package/scheduler/RunScheduledActionOnceDecorator.d.ts +34 -0
  43. package/scheduler/RunScheduledActionOnceDecorator.js +89 -0
  44. package/scheduler/RunScheduledActionOnceDecorator.js.map +1 -0
  45. package/scheduler/ScheduledActionRecoverInputHandler.d.ts +14 -0
  46. package/scheduler/ScheduledActionRecoverInputHandler.js +5 -0
  47. package/scheduler/ScheduledActionRecoverInputHandler.js.map +1 -0
  48. package/scheduler/ScheduledActionRecoverInputType.d.ts +17 -0
  49. package/scheduler/ScheduledActionRecoverInputType.js +18 -0
  50. package/scheduler/ScheduledActionRecoverInputType.js.map +1 -0
  51. package/scheduler/abstractions/SchedulerSingleton.d.ts +10 -0
  52. package/scheduler/abstractions/SchedulerSingleton.js +5 -0
  53. package/scheduler/abstractions/SchedulerSingleton.js.map +1 -0
  54. package/scheduler/schedulerServer.d.ts +25 -0
  55. package/scheduler/schedulerServer.js +81 -0
  56. package/scheduler/schedulerServer.js.map +1 -0
  57. package/tenantStorages/guardDeclaredTenantStorages.d.ts +36 -0
  58. package/tenantStorages/guardDeclaredTenantStorages.js +60 -0
  59. package/tenantStorages/guardDeclaredTenantStorages.js.map +1 -0
  60. package/websockets/createWebsocketsAuthenticator.d.ts +4 -0
  61. package/websockets/createWebsocketsAuthenticator.js +49 -0
  62. package/websockets/createWebsocketsAuthenticator.js.map +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
- # Temporary Holding Version
1
+ # @webiny/api-composition-standalone
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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,6 @@
1
+ import type { Container } from "@webiny/di";
2
+ /**
3
+ * Empties the trash bins on a timer by dispatching an `EmptyTrashBinsEvent`. The standalone
4
+ * counterpart of the EventBridge rule that does it on AWS.
5
+ */
6
+ export declare function startBulkActionsServer(rootContainer: Container): void;
@@ -0,0 +1,26 @@
1
+ import { InputDispatcher } from "@webiny/api-kernel-core";
2
+ import { Logger } from "@webiny/api-core/features/logger/index.js";
3
+ import { EMPTY_TRASH_BINS_EVENT_IDENTIFIER } from "@webiny/api-headless-cms-bulk-actions-standalone";
4
+ const EMPTY_TRASH_INTERVAL_MS = 21600000;
5
+ const FIRST_RUN_DELAY_MS = 5000;
6
+ function startBulkActionsServer(rootContainer) {
7
+ const dispatcher = rootContainer.resolve(InputDispatcher);
8
+ const logger = rootContainer.resolve(Logger);
9
+ const event = {
10
+ [EMPTY_TRASH_BINS_EVENT_IDENTIFIER]: true
11
+ };
12
+ const trigger = async ()=>{
13
+ try {
14
+ await dispatcher.dispatch(event);
15
+ } catch (err) {
16
+ logger.error({
17
+ error: err
18
+ }, "[bulk-actions] failed to start emptying the trash bins");
19
+ }
20
+ };
21
+ setTimeout(trigger, FIRST_RUN_DELAY_MS);
22
+ setInterval(trigger, EMPTY_TRASH_INTERVAL_MS);
23
+ }
24
+ export { startBulkActionsServer };
25
+
26
+ //# sourceMappingURL=bulkActionsServer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bulkActions/bulkActionsServer.js","sources":["../../src/bulkActions/bulkActionsServer.ts"],"sourcesContent":["import type { Container } from \"@webiny/di\";\nimport { InputDispatcher } from \"@webiny/api-kernel-core\";\nimport { Logger } from \"@webiny/api-core/features/logger/index.js\";\nimport { EMPTY_TRASH_BINS_EVENT_IDENTIFIER } from \"@webiny/api-headless-cms-bulk-actions-standalone\";\nimport type { IEmptyTrashBinsEvent } from \"@webiny/api-headless-cms-bulk-actions-standalone\";\n\n// Every 6 hours.\nconst EMPTY_TRASH_INTERVAL_MS = 6 * 60 * 60 * 1000;\n\n// Shortly after boot, so the first run doesn't compete with startup.\nconst FIRST_RUN_DELAY_MS = 5000;\n\n/**\n * Empties the trash bins on a timer by dispatching an `EmptyTrashBinsEvent`. The standalone\n * counterpart of the EventBridge rule that does it on AWS.\n */\nexport function startBulkActionsServer(rootContainer: Container): void {\n const dispatcher = rootContainer.resolve(InputDispatcher);\n const logger = rootContainer.resolve(Logger);\n const event: IEmptyTrashBinsEvent = { [EMPTY_TRASH_BINS_EVENT_IDENTIFIER]: true };\n\n const trigger = async () => {\n try {\n await dispatcher.dispatch(event);\n } catch (err) {\n logger.error({ error: err }, \"[bulk-actions] failed to start emptying the trash bins\");\n }\n };\n\n setTimeout(trigger, FIRST_RUN_DELAY_MS);\n setInterval(trigger, EMPTY_TRASH_INTERVAL_MS);\n}\n"],"names":["EMPTY_TRASH_INTERVAL_MS","FIRST_RUN_DELAY_MS","startBulkActionsServer","rootContainer","dispatcher","InputDispatcher","logger","Logger","event","EMPTY_TRASH_BINS_EVENT_IDENTIFIER","trigger","err","setTimeout","setInterval"],"mappings":";;;AAOA,MAAMA,0BAA0B;AAGhC,MAAMC,qBAAqB;AAMpB,SAASC,uBAAuBC,aAAwB;IAC3D,MAAMC,aAAaD,cAAc,OAAO,CAACE;IACzC,MAAMC,SAASH,cAAc,OAAO,CAACI;IACrC,MAAMC,QAA8B;QAAE,CAACC,kCAAkC,EAAE;IAAK;IAEhF,MAAMC,UAAU;QACZ,IAAI;YACA,MAAMN,WAAW,QAAQ,CAACI;QAC9B,EAAE,OAAOG,KAAK;YACVL,OAAO,KAAK,CAAC;gBAAE,OAAOK;YAAI,GAAG;QACjC;IACJ;IAEAC,WAAWF,SAAST;IACpBY,YAAYH,SAASV;AACzB"}
@@ -0,0 +1,40 @@
1
+ import type { PublicUrl } from "@webiny/api-core/features/publicUrls/index.js";
2
+ export interface IStandaloneConfig {
3
+ /** `WEBINY_API_URL`. Required. */
4
+ readonly apiUrl: PublicUrl;
5
+ /** `WEBINY_ADMIN_URL`. Optional: unknown when not set. */
6
+ readonly adminUrl: PublicUrl;
7
+ readonly fileStorage: {
8
+ /** `WEBINY_UPLOAD_SECRET`. Required. */
9
+ readonly uploadSecret: string;
10
+ };
11
+ readonly encryption: {
12
+ /** `WEBINY_ENCRYPTION_PASSPHRASE`. Required: standalone always encrypts. */
13
+ readonly passphrase: string;
14
+ /** `WEBINY_ENCRYPTION_SALT`. Optional. */
15
+ readonly salt: string;
16
+ };
17
+ readonly hashing: {
18
+ /** `WEBINY_HASHING_PEPPER`. Required: standalone always peppers its hashes. */
19
+ readonly pepper: string;
20
+ };
21
+ /**
22
+ * `WEBINY_REDIS_URL`. Optional. When set, websocket messages travel between API processes
23
+ * through this Redis or Valkey server; required when more than one API process runs.
24
+ */
25
+ readonly redisUrl: string | undefined;
26
+ /**
27
+ * `WEBINY_KEEP_ALIVE_TIMEOUT_MS`. Optional. How long an idle HTTP connection stays open; set it
28
+ * above the idle timeout of the proxy in front of the API. Unset keeps the server's default of
29
+ * 65 s, above an AWS Application Load Balancer's 60 s.
30
+ */
31
+ readonly keepAliveTimeoutMs: number | undefined;
32
+ }
33
+ /**
34
+ * Deployment-specific settings of a standalone API, read from env once when the server starts.
35
+ * Nothing here is baked into the build, so one build runs in every environment.
36
+ */
37
+ export declare const StandaloneConfig: import("@webiny/di").Abstraction<IStandaloneConfig>;
38
+ export declare namespace StandaloneConfig {
39
+ type Interface = IStandaloneConfig;
40
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const StandaloneConfig = createAbstraction("Standalone/Config");
3
+ export { StandaloneConfig };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config/abstractions.js","sources":["../../src/config/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { PublicUrl } from \"@webiny/api-core/features/publicUrls/index.js\";\n\nexport interface IStandaloneConfig {\n /** `WEBINY_API_URL`. Required. */\n readonly apiUrl: PublicUrl;\n /** `WEBINY_ADMIN_URL`. Optional: unknown when not set. */\n readonly adminUrl: PublicUrl;\n readonly fileStorage: {\n /** `WEBINY_UPLOAD_SECRET`. Required. */\n readonly uploadSecret: string;\n };\n readonly encryption: {\n /** `WEBINY_ENCRYPTION_PASSPHRASE`. Required: standalone always encrypts. */\n readonly passphrase: string;\n /** `WEBINY_ENCRYPTION_SALT`. Optional. */\n readonly salt: string;\n };\n readonly hashing: {\n /** `WEBINY_HASHING_PEPPER`. Required: standalone always peppers its hashes. */\n readonly pepper: string;\n };\n /**\n * `WEBINY_REDIS_URL`. Optional. When set, websocket messages travel between API processes\n * through this Redis or Valkey server; required when more than one API process runs.\n */\n readonly redisUrl: string | undefined;\n /**\n * `WEBINY_KEEP_ALIVE_TIMEOUT_MS`. Optional. How long an idle HTTP connection stays open; set it\n * above the idle timeout of the proxy in front of the API. Unset keeps the server's default of\n * 65 s, above an AWS Application Load Balancer's 60 s.\n */\n readonly keepAliveTimeoutMs: number | undefined;\n}\n\n/**\n * Deployment-specific settings of a standalone API, read from env once when the server starts.\n * Nothing here is baked into the build, so one build runs in every environment.\n */\nexport const StandaloneConfig = createAbstraction<IStandaloneConfig>(\"Standalone/Config\");\n\nexport namespace StandaloneConfig {\n export type Interface = IStandaloneConfig;\n}\n"],"names":["StandaloneConfig","createAbstraction"],"mappings":";AAuCO,MAAMA,mBAAmBC,kBAAqC"}
@@ -0,0 +1,8 @@
1
+ import type { BuildParams } from "@webiny/api-core/features/buildParams/index.js";
2
+ /**
3
+ * Throws unless the build has a storage for uploaded files: a project extension that provides
4
+ * `ObjectStorage` says so with the `ObjectStorage` build param (`<Infra.FileStorage.Disk />` sets
5
+ * `"disk"`, `<Infra.FileStorage.S3 />` sets `"s3"`). Checked when the API starts, before any request
6
+ * registers the extension.
7
+ */
8
+ export declare function assertFileStorage(buildParams: BuildParams.Interface): void;
@@ -0,0 +1,8 @@
1
+ import { OBJECT_STORAGE_BUILD_PARAM } from "@webiny/api-object-storage";
2
+ function assertFileStorage(buildParams) {
3
+ const storage = buildParams.get(OBJECT_STORAGE_BUILD_PARAM);
4
+ if (!storage) throw new Error("No file storage is in the build. Add <Infra.FileStorage.Disk /> or <Infra.FileStorage.S3 />.");
5
+ }
6
+ export { assertFileStorage };
7
+
8
+ //# sourceMappingURL=assertFileStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config/assertFileStorage.js","sources":["../../src/config/assertFileStorage.ts"],"sourcesContent":["import type { BuildParams } from \"@webiny/api-core/features/buildParams/index.js\";\nimport { OBJECT_STORAGE_BUILD_PARAM } from \"@webiny/api-object-storage\";\n\n/**\n * Throws unless the build has a storage for uploaded files: a project extension that provides\n * `ObjectStorage` says so with the `ObjectStorage` build param (`<Infra.FileStorage.Disk />` sets\n * `\"disk\"`, `<Infra.FileStorage.S3 />` sets `\"s3\"`). Checked when the API starts, before any request\n * registers the extension.\n */\nexport function assertFileStorage(buildParams: BuildParams.Interface): void {\n const storage = buildParams.get<string>(OBJECT_STORAGE_BUILD_PARAM);\n if (!storage) {\n throw new Error(\n \"No file storage is in the build. Add <Infra.FileStorage.Disk /> or \" +\n \"<Infra.FileStorage.S3 />.\"\n );\n }\n}\n"],"names":["assertFileStorage","buildParams","storage","OBJECT_STORAGE_BUILD_PARAM","Error"],"mappings":";AASO,SAASA,kBAAkBC,WAAkC;IAChE,MAAMC,UAAUD,YAAY,GAAG,CAASE;IACxC,IAAI,CAACD,SACD,MAAM,IAAIE,MACN;AAIZ"}
@@ -0,0 +1,8 @@
1
+ import type { BuildParams } from "@webiny/api-core/features/buildParams/index.js";
2
+ /**
3
+ * Throws when the build contains the encryption passphrase or the hashing pepper. That happens when
4
+ * webiny.config.tsx uses the shared <Infra.Crypto.*> from @webiny/project instead of the standalone
5
+ * ones: the secret would sit in the image, and a different value in env would not match what the
6
+ * project was configured with.
7
+ */
8
+ export declare function assertNoBakedSecrets(buildParams: BuildParams.Interface): void;
@@ -0,0 +1,17 @@
1
+ const BAKED_ENCRYPTION_PASSPHRASE_BUILD_PARAM = "EncryptionPassphrase";
2
+ const BAKED_HASHING_PEPPER_BUILD_PARAM = "HashingPepper";
3
+ function assertNoBakedSecrets(buildParams) {
4
+ const problems = [];
5
+ if (buildParams.get(BAKED_ENCRYPTION_PASSPHRASE_BUILD_PARAM)) problems.push("The build contains the encryption passphrase (EncryptionPassphrase build param), so webiny.config.tsx uses <Infra.Crypto.Encryption> from @webiny/project. Use the one from @webiny/project-standalone, which reads WEBINY_ENCRYPTION_PASSPHRASE at startup.");
6
+ if (buildParams.get(BAKED_HASHING_PEPPER_BUILD_PARAM)) problems.push("The build contains the hashing pepper (HashingPepper build param), so webiny.config.tsx uses <Infra.Crypto.Hashing> from @webiny/project. Use the one from @webiny/project-standalone, which reads WEBINY_HASHING_PEPPER at startup.");
7
+ if (problems.length > 0) {
8
+ const message = [
9
+ "The standalone API build is misconfigured:",
10
+ ...problems
11
+ ].join("\n ");
12
+ throw new Error(message);
13
+ }
14
+ }
15
+ export { assertNoBakedSecrets };
16
+
17
+ //# sourceMappingURL=bakedSecrets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config/bakedSecrets.js","sources":["../../src/config/bakedSecrets.ts"],"sourcesContent":["import type { BuildParams } from \"@webiny/api-core/features/buildParams/index.js\";\n\n// Baked by the shared <Infra.Crypto.*> from @webiny/project (used on AWS). Never valid in standalone.\nconst BAKED_ENCRYPTION_PASSPHRASE_BUILD_PARAM = \"EncryptionPassphrase\";\nconst BAKED_HASHING_PEPPER_BUILD_PARAM = \"HashingPepper\";\n\n/**\n * Throws when the build contains the encryption passphrase or the hashing pepper. That happens when\n * webiny.config.tsx uses the shared <Infra.Crypto.*> from @webiny/project instead of the standalone\n * ones: the secret would sit in the image, and a different value in env would not match what the\n * project was configured with.\n */\nexport function assertNoBakedSecrets(buildParams: BuildParams.Interface): void {\n const problems: string[] = [];\n\n if (buildParams.get<string>(BAKED_ENCRYPTION_PASSPHRASE_BUILD_PARAM)) {\n problems.push(\n \"The build contains the encryption passphrase (EncryptionPassphrase build param), so \" +\n \"webiny.config.tsx uses <Infra.Crypto.Encryption> from @webiny/project. Use the one \" +\n \"from @webiny/project-standalone, which reads WEBINY_ENCRYPTION_PASSPHRASE at startup.\"\n );\n }\n\n if (buildParams.get<string>(BAKED_HASHING_PEPPER_BUILD_PARAM)) {\n problems.push(\n \"The build contains the hashing pepper (HashingPepper build param), so webiny.config.tsx \" +\n \"uses <Infra.Crypto.Hashing> from @webiny/project. Use the one from \" +\n \"@webiny/project-standalone, which reads WEBINY_HASHING_PEPPER at startup.\"\n );\n }\n\n if (problems.length > 0) {\n const message = [\"The standalone API build is misconfigured:\", ...problems].join(\"\\n \");\n throw new Error(message);\n }\n}\n"],"names":["BAKED_ENCRYPTION_PASSPHRASE_BUILD_PARAM","BAKED_HASHING_PEPPER_BUILD_PARAM","assertNoBakedSecrets","buildParams","problems","message","Error"],"mappings":"AAGA,MAAMA,0CAA0C;AAChD,MAAMC,mCAAmC;AAQlC,SAASC,qBAAqBC,WAAkC;IACnE,MAAMC,WAAqB,EAAE;IAE7B,IAAID,YAAY,GAAG,CAASH,0CACxBI,SAAS,IAAI,CACT;IAMR,IAAID,YAAY,GAAG,CAASF,mCACxBG,SAAS,IAAI,CACT;IAMR,IAAIA,SAAS,MAAM,GAAG,GAAG;QACrB,MAAMC,UAAU;YAAC;eAAiDD;SAAS,CAAC,IAAI,CAAC;QACjF,MAAM,IAAIE,MAAMD;IACpB;AACJ"}
@@ -0,0 +1,12 @@
1
+ import type { StandaloneConfig } from "./abstractions.js";
2
+ type Env = Record<string, string | undefined>;
3
+ /**
4
+ * Reads the standalone API's settings from env. Throws one error naming every missing or invalid
5
+ * variable, so a misconfigured container fails at boot instead of on the first upload or login.
6
+ *
7
+ * Nothing falls back to a default: `webiny watch` and `webiny serve` get their values from
8
+ * `<Infra.ApiUrl>`, `<Infra.AdminUrl>`, `<Infra.FileStorage.*>` and `<Infra.Crypto.*>` in
9
+ * webiny.config, and a deployed container must set them explicitly.
10
+ */
11
+ export declare function readStandaloneConfig(env: Env): StandaloneConfig.Interface;
12
+ export {};
@@ -0,0 +1,56 @@
1
+ import { PublicUrl } from "@webiny/api-core/features/publicUrls/index.js";
2
+ function read(env, name) {
3
+ return env[name]?.trim() ?? "";
4
+ }
5
+ function readSecret(env, name) {
6
+ const value = env[name] ?? "";
7
+ return value.trim() ? value : "";
8
+ }
9
+ function readStandaloneConfig(env) {
10
+ const problems = [];
11
+ const apiUrlValue = read(env, "WEBINY_API_URL");
12
+ const apiUrl = PublicUrl.from(apiUrlValue);
13
+ if (apiUrlValue) {
14
+ if (!apiUrl.isKnown()) problems.push(`WEBINY_API_URL is not an absolute http(s) URL: "${apiUrlValue}".`);
15
+ } else problems.push("WEBINY_API_URL is not set.");
16
+ const adminUrlValue = read(env, "WEBINY_ADMIN_URL");
17
+ const adminUrl = PublicUrl.from(adminUrlValue);
18
+ if (adminUrlValue && !adminUrl.isKnown()) problems.push(`WEBINY_ADMIN_URL is not an absolute http(s) URL: "${adminUrlValue}".`);
19
+ const uploadSecret = readSecret(env, "WEBINY_UPLOAD_SECRET");
20
+ if (!uploadSecret) problems.push("WEBINY_UPLOAD_SECRET is not set.");
21
+ const encryptionPassphrase = readSecret(env, "WEBINY_ENCRYPTION_PASSPHRASE");
22
+ if (!encryptionPassphrase) problems.push("WEBINY_ENCRYPTION_PASSPHRASE is not set.");
23
+ const hashingPepper = readSecret(env, "WEBINY_HASHING_PEPPER");
24
+ if (!hashingPepper) problems.push("WEBINY_HASHING_PEPPER is not set.");
25
+ const redisUrl = read(env, "WEBINY_REDIS_URL");
26
+ if (redisUrl && !/^rediss?:\/\//.test(redisUrl)) problems.push("WEBINY_REDIS_URL must start with redis:// or rediss://.");
27
+ const keepAliveTimeoutValue = read(env, "WEBINY_KEEP_ALIVE_TIMEOUT_MS");
28
+ const keepAliveTimeoutMs = keepAliveTimeoutValue ? Number(keepAliveTimeoutValue) : void 0;
29
+ if (void 0 !== keepAliveTimeoutMs && (!Number.isInteger(keepAliveTimeoutMs) || keepAliveTimeoutMs <= 0)) problems.push(`WEBINY_KEEP_ALIVE_TIMEOUT_MS must be a positive whole number of milliseconds: "${keepAliveTimeoutValue}".`);
30
+ if (problems.length > 0) {
31
+ const message = [
32
+ "The standalone API is missing required configuration:",
33
+ ...problems
34
+ ].join("\n ");
35
+ throw new Error(message);
36
+ }
37
+ return {
38
+ apiUrl,
39
+ adminUrl,
40
+ fileStorage: {
41
+ uploadSecret
42
+ },
43
+ encryption: {
44
+ passphrase: encryptionPassphrase,
45
+ salt: readSecret(env, "WEBINY_ENCRYPTION_SALT")
46
+ },
47
+ hashing: {
48
+ pepper: hashingPepper
49
+ },
50
+ redisUrl: redisUrl || void 0,
51
+ keepAliveTimeoutMs
52
+ };
53
+ }
54
+ export { readStandaloneConfig };
55
+
56
+ //# sourceMappingURL=readStandaloneConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config/readStandaloneConfig.js","sources":["../../src/config/readStandaloneConfig.ts"],"sourcesContent":["import { PublicUrl } from \"@webiny/api-core/features/publicUrls/index.js\";\nimport type { StandaloneConfig } from \"./abstractions.js\";\n\ntype Env = Record<string, string | undefined>;\n\nfunction read(env: Env, name: string): string {\n return env[name]?.trim() ?? \"\";\n}\n\n/**\n * Secrets are used exactly as given: trimming would change the derived key or signature, so a value\n * with surrounding whitespace would no longer match what was encrypted, hashed or signed with it.\n * A blank value counts as unset.\n */\nfunction readSecret(env: Env, name: string): string {\n const value = env[name] ?? \"\";\n return value.trim() ? value : \"\";\n}\n\n/**\n * Reads the standalone API's settings from env. Throws one error naming every missing or invalid\n * variable, so a misconfigured container fails at boot instead of on the first upload or login.\n *\n * Nothing falls back to a default: `webiny watch` and `webiny serve` get their values from\n * `<Infra.ApiUrl>`, `<Infra.AdminUrl>`, `<Infra.FileStorage.*>` and `<Infra.Crypto.*>` in\n * webiny.config, and a deployed container must set them explicitly.\n */\nexport function readStandaloneConfig(env: Env): StandaloneConfig.Interface {\n const problems: string[] = [];\n\n const apiUrlValue = read(env, \"WEBINY_API_URL\");\n const apiUrl = PublicUrl.from(apiUrlValue);\n if (!apiUrlValue) {\n problems.push(\"WEBINY_API_URL is not set.\");\n } else if (!apiUrl.isKnown()) {\n problems.push(`WEBINY_API_URL is not an absolute http(s) URL: \"${apiUrlValue}\".`);\n }\n\n const adminUrlValue = read(env, \"WEBINY_ADMIN_URL\");\n const adminUrl = PublicUrl.from(adminUrlValue);\n if (adminUrlValue && !adminUrl.isKnown()) {\n problems.push(`WEBINY_ADMIN_URL is not an absolute http(s) URL: \"${adminUrlValue}\".`);\n }\n\n const uploadSecret = readSecret(env, \"WEBINY_UPLOAD_SECRET\");\n if (!uploadSecret) {\n problems.push(\"WEBINY_UPLOAD_SECRET is not set.\");\n }\n\n /*\n * Always required: a standalone project always encrypts and always peppers its hashes. There is\n * no deploy step that could check this for production, so it is checked here for every start.\n */\n const encryptionPassphrase = readSecret(env, \"WEBINY_ENCRYPTION_PASSPHRASE\");\n if (!encryptionPassphrase) {\n problems.push(\"WEBINY_ENCRYPTION_PASSPHRASE is not set.\");\n }\n\n const hashingPepper = readSecret(env, \"WEBINY_HASHING_PEPPER\");\n if (!hashingPepper) {\n problems.push(\"WEBINY_HASHING_PEPPER is not set.\");\n }\n\n const redisUrl = read(env, \"WEBINY_REDIS_URL\");\n if (redisUrl && !/^rediss?:\\/\\//.test(redisUrl)) {\n problems.push(\"WEBINY_REDIS_URL must start with redis:// or rediss://.\");\n }\n\n const keepAliveTimeoutValue = read(env, \"WEBINY_KEEP_ALIVE_TIMEOUT_MS\");\n const keepAliveTimeoutMs = keepAliveTimeoutValue ? Number(keepAliveTimeoutValue) : undefined;\n if (\n keepAliveTimeoutMs !== undefined &&\n (!Number.isInteger(keepAliveTimeoutMs) || keepAliveTimeoutMs <= 0)\n ) {\n problems.push(\n `WEBINY_KEEP_ALIVE_TIMEOUT_MS must be a positive whole number of milliseconds: \"${keepAliveTimeoutValue}\".`\n );\n }\n\n if (problems.length > 0) {\n const message = [\"The standalone API is missing required configuration:\", ...problems].join(\n \"\\n \"\n );\n throw new Error(message);\n }\n\n return {\n apiUrl,\n adminUrl,\n fileStorage: {\n uploadSecret\n },\n encryption: {\n passphrase: encryptionPassphrase,\n salt: readSecret(env, \"WEBINY_ENCRYPTION_SALT\")\n },\n hashing: {\n pepper: hashingPepper\n },\n redisUrl: redisUrl || undefined,\n keepAliveTimeoutMs\n };\n}\n"],"names":["read","env","name","readSecret","value","readStandaloneConfig","problems","apiUrlValue","apiUrl","PublicUrl","adminUrlValue","adminUrl","uploadSecret","encryptionPassphrase","hashingPepper","redisUrl","keepAliveTimeoutValue","keepAliveTimeoutMs","Number","undefined","message","Error"],"mappings":";AAKA,SAASA,KAAKC,GAAQ,EAAEC,IAAY;IAChC,OAAOD,GAAG,CAACC,KAAK,EAAE,UAAU;AAChC;AAOA,SAASC,WAAWF,GAAQ,EAAEC,IAAY;IACtC,MAAME,QAAQH,GAAG,CAACC,KAAK,IAAI;IAC3B,OAAOE,MAAM,IAAI,KAAKA,QAAQ;AAClC;AAUO,SAASC,qBAAqBJ,GAAQ;IACzC,MAAMK,WAAqB,EAAE;IAE7B,MAAMC,cAAcP,KAAKC,KAAK;IAC9B,MAAMO,SAASC,UAAU,IAAI,CAACF;IAC9B,IAAKA,aAEE;QAAA,IAAI,CAACC,OAAO,OAAO,IACtBF,SAAS,IAAI,CAAC,CAAC,gDAAgD,EAAEC,YAAY,EAAE,CAAC;IACpF,OAHID,SAAS,IAAI,CAAC;IAKlB,MAAMI,gBAAgBV,KAAKC,KAAK;IAChC,MAAMU,WAAWF,UAAU,IAAI,CAACC;IAChC,IAAIA,iBAAiB,CAACC,SAAS,OAAO,IAClCL,SAAS,IAAI,CAAC,CAAC,kDAAkD,EAAEI,cAAc,EAAE,CAAC;IAGxF,MAAME,eAAeT,WAAWF,KAAK;IACrC,IAAI,CAACW,cACDN,SAAS,IAAI,CAAC;IAOlB,MAAMO,uBAAuBV,WAAWF,KAAK;IAC7C,IAAI,CAACY,sBACDP,SAAS,IAAI,CAAC;IAGlB,MAAMQ,gBAAgBX,WAAWF,KAAK;IACtC,IAAI,CAACa,eACDR,SAAS,IAAI,CAAC;IAGlB,MAAMS,WAAWf,KAAKC,KAAK;IAC3B,IAAIc,YAAY,CAAC,gBAAgB,IAAI,CAACA,WAClCT,SAAS,IAAI,CAAC;IAGlB,MAAMU,wBAAwBhB,KAAKC,KAAK;IACxC,MAAMgB,qBAAqBD,wBAAwBE,OAAOF,yBAAyBG;IACnF,IACIF,AAAuBE,WAAvBF,sBACC,EAACC,OAAO,SAAS,CAACD,uBAAuBA,sBAAsB,IAEhEX,SAAS,IAAI,CACT,CAAC,+EAA+E,EAAEU,sBAAsB,EAAE,CAAC;IAInH,IAAIV,SAAS,MAAM,GAAG,GAAG;QACrB,MAAMc,UAAU;YAAC;eAA4Dd;SAAS,CAAC,IAAI,CACvF;QAEJ,MAAM,IAAIe,MAAMD;IACpB;IAEA,OAAO;QACHZ;QACAG;QACA,aAAa;YACTC;QACJ;QACA,YAAY;YACR,YAAYC;YACZ,MAAMV,WAAWF,KAAK;QAC1B;QACA,SAAS;YACL,QAAQa;QACZ;QACA,UAAUC,YAAYI;QACtBF;IACJ;AACJ"}
@@ -0,0 +1,20 @@
1
+ import type { Container } from "@webiny/di";
2
+ import { registerExtensions } from "@webiny/handler";
3
+ import type { BuildParams } from "@webiny/api-core/features/buildParams/index.js";
4
+ export interface CreateWebinyApiHandlerConfig {
5
+ /**
6
+ * Project-defined extensions, applied at register() time.
7
+ */
8
+ extensions: () => Parameters<typeof registerExtensions>[1];
9
+ /**
10
+ * Register the storage for this deployment AND the identity provider in the root container.
11
+ * Unlike the AWS base, the server base bakes in no DB or IdP assumption — the variant supplies
12
+ * the complete storage + auth wiring. A storage that registers per request puts only its
13
+ * connection and a `RequestStorage` in the root (see `registerApiRequestStack`). `buildParams`
14
+ * are the build params the project was built with (requests register their own copy).
15
+ */
16
+ registerRootStorage: (container: Container, params: {
17
+ buildParams: BuildParams.Interface;
18
+ }) => void | Promise<void>;
19
+ }
20
+ export declare function createWebinyApiHandler(config: CreateWebinyApiHandlerConfig): Promise<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>>;
@@ -0,0 +1,139 @@
1
+ import { GraphQLSchemaCacheFeature } from "@webiny/api-graphql";
2
+ import { EncryptionKeyCacheFeature } from "@webiny/api-core/features/encryption/index.js";
3
+ import { JwksStoreFeature } from "@webiny/api-core/idp/index.js";
4
+ import { NodeHttpFeature, NodeHttpInputHandler, createServerHandler } from "@webiny/api-kernel-core/nodeHttp/index.js";
5
+ import { ApiRequestRegistration, createLogger, registerApiRequestStack, registerApiRequestStackInOneContainer, registerHttpTransport, registerRootAllowedRequestHeaders, registerRootBuildParams } from "@webiny/api-composition-core";
6
+ import { ProcessOwner, RandomProcessOwner } from "@webiny/api-kernel-core";
7
+ import { TenantScopesRootFeature } from "@webiny/api-core/features/tenancy/TenantScopes/index.js";
8
+ import { InProcessMessageBus, WebsocketsConnectionManager, WebsocketsMessageBus, WebsocketsServerAdapter, WebsocketsServerRootFeature, WebsocketsStandaloneFeature, attachWebsocketsServer, createBusMessageHandler } from "@webiny/api-websockets-standalone";
9
+ import { WebsocketsRedisFeature } from "@webiny/api-websockets-standalone-redis";
10
+ import { BackgroundTasksStandaloneFeature, startTaskRecovery, stopBackgroundTasks } from "@webiny/background-tasks-standalone";
11
+ import { FileManagerStandaloneFeature } from "@webiny/api-file-manager-standalone";
12
+ import { registerSchedulerServer, startSchedulerServer } from "./scheduler/schedulerServer.js";
13
+ import { startBulkActionsServer } from "./bulkActions/bulkActionsServer.js";
14
+ import { createWebsocketsAuthenticator } from "./websockets/createWebsocketsAuthenticator.js";
15
+ import { EmptyTrashBinsFeature } from "@webiny/api-headless-cms-bulk-actions-standalone";
16
+ import { ConfigPublicUrlsFeature } from "./publicUrls/feature.js";
17
+ import { StandaloneConfig } from "./config/abstractions.js";
18
+ import { readStandaloneConfig } from "./config/readStandaloneConfig.js";
19
+ import { assertNoBakedSecrets } from "./config/bakedSecrets.js";
20
+ import { assertFileStorage } from "./config/assertFileStorage.js";
21
+ import { StandaloneCryptoConfigFeature } from "./crypto/feature.js";
22
+ import { Logger } from "@webiny/api-core/features/logger/index.js";
23
+ import { guardDeclaredTenantStorages } from "./tenantStorages/guardDeclaredTenantStorages.js";
24
+ const SHUTDOWN_WAIT_MS = 6000;
25
+ function createWebinyApiHandler(config) {
26
+ let stopTaskRecovery;
27
+ let stopScheduler;
28
+ let stopWebsockets;
29
+ let closeMessageBus;
30
+ const standaloneConfig = readStandaloneConfig(process.env);
31
+ const logger = createLogger();
32
+ const stackConfig = {
33
+ extensions: config.extensions,
34
+ transports: {
35
+ hostingConfig: (scopeContainer)=>{
36
+ ConfigPublicUrlsFeature.register(scopeContainer);
37
+ StandaloneCryptoConfigFeature.register(scopeContainer);
38
+ },
39
+ realtime: (scopeContainer)=>{
40
+ WebsocketsStandaloneFeature.register(scopeContainer);
41
+ },
42
+ fileManager: (scopeContainer)=>{
43
+ const { uploadSecret } = standaloneConfig.fileStorage;
44
+ FileManagerStandaloneFeature.register(scopeContainer, {
45
+ uploadSecret
46
+ });
47
+ }
48
+ }
49
+ };
50
+ return createServerHandler({
51
+ keepAliveTimeoutMs: standaloneConfig.keepAliveTimeoutMs,
52
+ root: async (rootContainer)=>{
53
+ const buildParams = await registerRootBuildParams(rootContainer, config.extensions());
54
+ assertNoBakedSecrets(buildParams);
55
+ assertFileStorage(buildParams);
56
+ rootContainer.registerInstance(StandaloneConfig, standaloneConfig);
57
+ rootContainer.registerInstance(Logger, logger);
58
+ rootContainer.register(RandomProcessOwner).inSingletonScope();
59
+ registerHttpTransport(rootContainer, NodeHttpFeature, NodeHttpInputHandler);
60
+ TenantScopesRootFeature.register(rootContainer);
61
+ rootContainer.registerInstance(ApiRequestRegistration, {
62
+ register: (container, options)=>registerApiRequestStackInOneContainer(container, stackConfig, options)
63
+ });
64
+ await config.registerRootStorage(rootContainer, {
65
+ buildParams
66
+ });
67
+ WebsocketsServerRootFeature.register(rootContainer);
68
+ if (standaloneConfig.redisUrl) WebsocketsRedisFeature.register(rootContainer, {
69
+ url: standaloneConfig.redisUrl,
70
+ logger
71
+ });
72
+ else rootContainer.register(InProcessMessageBus).inSingletonScope();
73
+ GraphQLSchemaCacheFeature.register(rootContainer);
74
+ EncryptionKeyCacheFeature.register(rootContainer);
75
+ JwksStoreFeature.register(rootContainer);
76
+ BackgroundTasksStandaloneFeature.register(rootContainer);
77
+ registerSchedulerServer(rootContainer);
78
+ EmptyTrashBinsFeature.register(rootContainer);
79
+ await registerRootAllowedRequestHeaders(rootContainer);
80
+ await guardDeclaredTenantStorages({
81
+ root: rootContainer,
82
+ registerRequest: (container)=>registerApiRequestStack(container, stackConfig)
83
+ });
84
+ },
85
+ child: async (container)=>{
86
+ await registerApiRequestStack(container, stackConfig);
87
+ },
88
+ onServer: async (server, rootContainer)=>{
89
+ const connectionManager = rootContainer.resolve(WebsocketsConnectionManager);
90
+ const adapter = rootContainer.resolve(WebsocketsServerAdapter);
91
+ const websockets = attachWebsocketsServer({
92
+ server,
93
+ connectionManager,
94
+ adapter,
95
+ authenticate: createWebsocketsAuthenticator(rootContainer, config.extensions)
96
+ });
97
+ await websockets.start();
98
+ stopWebsockets = ()=>websockets.stop();
99
+ const messageBus = rootContainer.resolve(WebsocketsMessageBus);
100
+ const processOwner = rootContainer.resolve(ProcessOwner);
101
+ const handleBusMessage = createBusMessageHandler({
102
+ connectionManager,
103
+ adapter,
104
+ logger
105
+ });
106
+ await messageBus.subscribe(processOwner.id, handleBusMessage);
107
+ closeMessageBus = ()=>messageBus.close();
108
+ logger.info({
109
+ messageBus: standaloneConfig.redisUrl ? "redis" : "in-process"
110
+ }, "[websockets] using message bus");
111
+ stopScheduler = await startSchedulerServer(rootContainer);
112
+ startBulkActionsServer(rootContainer);
113
+ stopTaskRecovery = startTaskRecovery(rootContainer);
114
+ },
115
+ onShutdown: async (rootContainer, { requestsFinished })=>{
116
+ stopTaskRecovery?.();
117
+ const tasks = stopBackgroundTasks(rootContainer, SHUTDOWN_WAIT_MS);
118
+ const scheduledActions = stopScheduler?.(SHUTDOWN_WAIT_MS);
119
+ const websockets = stopWebsockets?.();
120
+ const workDone = Promise.allSettled([
121
+ tasks,
122
+ scheduledActions,
123
+ requestsFinished
124
+ ]);
125
+ const messageBus = workDone.then(()=>closeMessageBus?.());
126
+ const results = await Promise.allSettled([
127
+ tasks,
128
+ scheduledActions,
129
+ websockets,
130
+ messageBus
131
+ ]);
132
+ const failed = results.find((result)=>"rejected" === result.status);
133
+ if (failed) throw failed.reason;
134
+ }
135
+ });
136
+ }
137
+ export { createWebinyApiHandler };
138
+
139
+ //# sourceMappingURL=createWebinyApiHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createWebinyApiHandler.js","sources":["../src/createWebinyApiHandler.ts"],"sourcesContent":["/**\n * Webiny API handler for the standalone Node HTTP server transport — storage-agnostic BASE.\n *\n * The ROOT container wires the Node HTTP transport (NodeHttpFeature = event type + router + HttpFeature)\n * plus the auth/tenant loader decorators (extract token / x-tenant from the IncomingMessage → shared\n * RequestIdentityLoader / RequestTenantLoader). The per-request feature stack is the transport-agnostic\n * `registerApiRequestStack` from `@webiny/api-composition-core` — the SAME stack the AWS handler uses.\n * The realtime transport hook installs the server WebSockets transport (vs AWS's API Gateway Management\n * API) with a SINGLE-PROCESS, in-process implementation. Background tasks and the scheduler are\n * ROOT-container singletons (below) — mirroring how the AWS handler registers background tasks at root,\n * and the WebSockets connection manager — rather than per-request transports; the scheduler fires timers\n * in-process (vs AWS's EventBridge). The storage variant (and identity provider) is injected via\n * `registerRootStorage`.\n *\n * The identity provider (e.g. `@webiny/self-hosted-auth`'s JWT IdP) must be registered by the variant\n * in `registerRootStorage`, so the RequestIdentityLoader driven by the identity decorator can resolve it.\n */\nimport { GraphQLSchemaCacheFeature } from \"@webiny/api-graphql\";\nimport { EncryptionKeyCacheFeature } from \"@webiny/api-core/features/encryption/index.js\";\nimport { JwksStoreFeature } from \"@webiny/api-core/idp/index.js\";\nimport type { Container } from \"@webiny/di\";\nimport {\n createServerHandler,\n NodeHttpFeature,\n NodeHttpInputHandler\n} from \"@webiny/api-kernel-core/nodeHttp/index.js\";\nimport { registerHttpTransport } from \"@webiny/api-composition-core\";\nimport { RandomProcessOwner } from \"@webiny/api-kernel-core\";\nimport { registerExtensions } from \"@webiny/handler\";\nimport {\n ApiRequestRegistration,\n registerApiRequestStack,\n registerApiRequestStackInOneContainer,\n type RegisterApiRequestStackConfig\n} from \"@webiny/api-composition-core\";\nimport { TenantScopesRootFeature } from \"@webiny/api-core/features/tenancy/TenantScopes/index.js\";\nimport {\n WebsocketsServerRootFeature,\n WebsocketsStandaloneFeature,\n WebsocketsConnectionManager,\n attachWebsocketsServer\n} from \"@webiny/api-websockets-standalone\";\nimport { WebsocketsServerAdapter } from \"@webiny/api-websockets-standalone\";\nimport { WebsocketsMessageBus } from \"@webiny/api-websockets-standalone\";\nimport { InProcessMessageBus } from \"@webiny/api-websockets-standalone\";\nimport { createBusMessageHandler } from \"@webiny/api-websockets-standalone\";\nimport { WebsocketsRedisFeature } from \"@webiny/api-websockets-standalone-redis\";\nimport { ProcessOwner } from \"@webiny/api-kernel-core\";\nimport { BackgroundTasksStandaloneFeature } from \"@webiny/background-tasks-standalone\";\nimport { startTaskRecovery } from \"@webiny/background-tasks-standalone\";\nimport { stopBackgroundTasks } from \"@webiny/background-tasks-standalone\";\nimport { FileManagerStandaloneFeature } from \"@webiny/api-file-manager-standalone\";\nimport { registerSchedulerServer, startSchedulerServer } from \"~/scheduler/schedulerServer.js\";\nimport { startBulkActionsServer } from \"~/bulkActions/bulkActionsServer.js\";\nimport { createWebsocketsAuthenticator } from \"~/websockets/createWebsocketsAuthenticator.js\";\nimport { EmptyTrashBinsFeature } from \"@webiny/api-headless-cms-bulk-actions-standalone\";\nimport { ConfigPublicUrlsFeature } from \"~/publicUrls/feature.js\";\nimport { StandaloneConfig } from \"~/config/abstractions.js\";\nimport { readStandaloneConfig } from \"~/config/readStandaloneConfig.js\";\nimport type { BuildParams } from \"@webiny/api-core/features/buildParams/index.js\";\nimport { assertNoBakedSecrets } from \"~/config/bakedSecrets.js\";\nimport { assertFileStorage } from \"~/config/assertFileStorage.js\";\nimport { StandaloneCryptoConfigFeature } from \"~/crypto/feature.js\";\nimport {\n createLogger,\n registerRootAllowedRequestHeaders,\n registerRootBuildParams\n} from \"@webiny/api-composition-core\";\nimport { Logger } from \"@webiny/api-core/features/logger/index.js\";\nimport { guardDeclaredTenantStorages } from \"~/tenantStorages/guardDeclaredTenantStorages.js\";\n\nexport interface CreateWebinyApiHandlerConfig {\n /**\n * Project-defined extensions, applied at register() time.\n */\n extensions: () => Parameters<typeof registerExtensions>[1];\n /**\n * Register the storage for this deployment AND the identity provider in the root container.\n * Unlike the AWS base, the server base bakes in no DB or IdP assumption — the variant supplies\n * the complete storage + auth wiring. A storage that registers per request puts only its\n * connection and a `RequestStorage` in the root (see `registerApiRequestStack`). `buildParams`\n * are the build params the project was built with (requests register their own copy).\n */\n registerRootStorage: (\n container: Container,\n params: { buildParams: BuildParams.Interface }\n ) => void | Promise<void>;\n}\n\n/*\n * The part of the 8 seconds a shutdown gets that running tasks and scheduled actions may spend\n * finishing or handing back; both wait at the same time. The rest leaves room to exit before a\n * process manager loses patience.\n */\nconst SHUTDOWN_WAIT_MS = 6000;\n\nexport function createWebinyApiHandler(config: CreateWebinyApiHandlerConfig) {\n let stopTaskRecovery: (() => void) | undefined;\n let stopScheduler: ((timeoutMs: number) => Promise<void>) | undefined;\n let stopWebsockets: (() => Promise<void>) | undefined;\n let closeMessageBus: (() => Promise<void>) | undefined;\n\n /*\n * Deployment-specific settings (public URLs, file storage, secrets) come from env, read once here\n * so a missing value stops the server at boot. Nothing deployment-specific is baked into the build.\n */\n const standaloneConfig = readStandaloneConfig(process.env);\n\n // One per process, to stdout. The root singletons below log through it, and so does every request.\n const logger = createLogger();\n\n /*\n * The transport-agnostic request stack, with the server's adapters. Every request's container\n * gets its tenant-neutral part (`child`), and each tenant scope of the request the rest. In one\n * container, it is also in the root as `ApiRequestRegistration`, for work outside a request that\n * needs a container a request would have: the SQL schema setup builds one on its own connection.\n */\n const stackConfig: RegisterApiRequestStackConfig = {\n extensions: config.extensions,\n // Why hooks (and not just registering the transports ourselves): `.register()` calls\n // are otherwise order-independent — you can register Features in any order, because\n // they only REGISTER, they don't RESOLVE during registration (resolution happens\n // later, in Initializers / SchemaFactories). The one thing that makes order matter is\n // a DEFAULT registration: e.g. `WebsocketsFeature` registers `NullWebsocketsTransport`\n // so the abstraction is always resolvable. Overriding it (last-registration-wins) means\n // our transport MUST be registered AFTER that Feature. These hooks are the seams\n // `registerApiRequestStack` provides for exactly that — each runs right after its Null\n // default, so the override is guaranteed without the caller knowing the internal order.\n transports: {\n /*\n * Public URLs and crypto secrets: no deploy step to discover them from, so they\n * come from env (StandaloneConfig, registered on the root).\n */\n hostingConfig: scopeContainer => {\n ConfigPublicUrlsFeature.register(scopeContainer);\n StandaloneCryptoConfigFeature.register(scopeContainer);\n },\n // Server WebSockets transport; resolves the shared connection manager + adapter\n // from the root (registered as singletons in `root`). Scheduler is NOT a per-request\n // transport here — it's a root singleton wired in `root` + `onServer` (see below).\n realtime: scopeContainer => {\n WebsocketsStandaloneFeature.register(scopeContainer);\n },\n /*\n * File-manager storage transport. Where AWS uploads straight to S3 (+ a separate\n * asset-delivery Lambda), the server takes uploads and serves files in-process.\n * FileManagerStandaloneFeature registers asset delivery (overriding the domain's\n * null impls) and the upload/multipart HTTP routes; they store through\n * `ObjectStorage`, which a project extension registers (`<Infra.FileStorage.Disk />`\n * a folder on disk, `<Infra.FileStorage.S3 />` an S3-compatible bucket).\n * `assertFileStorage` has made sure the build has one.\n */\n fileManager: scopeContainer => {\n const { uploadSecret } = standaloneConfig.fileStorage;\n FileManagerStandaloneFeature.register(scopeContainer, { uploadSecret });\n }\n }\n };\n\n return createServerHandler({\n keepAliveTimeoutMs: standaloneConfig.keepAliveTimeoutMs,\n root: async rootContainer => {\n /*\n * Secrets come from env only. A build that bakes one (the shared <Infra.Crypto.*> from\n * @webiny/project) is refused here, before the server accepts a request.\n */\n // Build params come from the deploy, the same for every request and tenant: they live in\n // the root, and every request container and tenant scope reads them from here.\n const buildParams = await registerRootBuildParams(rootContainer, config.extensions());\n assertNoBakedSecrets(buildParams);\n assertFileStorage(buildParams);\n\n rootContainer.registerInstance(StandaloneConfig, standaloneConfig);\n rootContainer.registerInstance(Logger, logger);\n\n // Names this process in shared storage: task claims and websocket connections.\n rootContainer.register(RandomProcessOwner).inSingletonScope();\n\n // ── Transport (Node HTTP) ──────────────────────────────────\n // NodeHttpFeature registers the event type + HttpFeature (router) + the routing terminal.\n // registerHttpTransport also registers the tenant, identity and preview-as loading, and the\n // hand-off of each request into its tenant's scope once CORS and the tenant step are done.\n registerHttpTransport(rootContainer, NodeHttpFeature, NodeHttpInputHandler);\n\n // Every other event's handler chain runs in its tenant's scope: a background task or\n // scheduled action in the tenant of its payload, anything else as the root tenant.\n TenantScopesRootFeature.register(rootContainer);\n\n rootContainer.registerInstance(ApiRequestRegistration, {\n register: (container, options) => {\n return registerApiRequestStackInOneContainer(container, stackConfig, options);\n }\n });\n\n // ── Storage + identity provider (variant-supplied) ─────────\n await config.registerRootStorage(rootContainer, { buildParams });\n\n // ── WebSockets transport (root) ────────────────────────────\n // The live sockets, the connection manager and the adapter live in the root as\n // singletons, shared between the upgrade acceptor (attachWebsocketsServer, below) and the\n // per-request ServerWebsocketsTransport that sends to those live sockets. The connections'\n // rows (ConnectionRegistry) are a storage, so they live in request containers: the\n // manager changes them by dispatching an event, which runs in a fresh one.\n WebsocketsServerRootFeature.register(rootContainer);\n\n /*\n * How a send reaches a socket another API process holds. Without a Redis URL there is\n * one process, and every socket is in it.\n */\n if (standaloneConfig.redisUrl) {\n WebsocketsRedisFeature.register(rootContainer, {\n url: standaloneConfig.redisUrl,\n logger\n });\n } else {\n rootContainer.register(InProcessMessageBus).inSingletonScope();\n }\n\n // ── GraphQL schema cache (root) ────────────────────────────\n // Root, so a built schema outlives the request that built it.\n GraphQLSchemaCacheFeature.register(rootContainer);\n\n // ── Encryption key cache (root) ────────────────────────────\n // Root, so the scrypt-derived key is computed once per process instead of per request.\n EncryptionKeyCacheFeature.register(rootContainer);\n // Root, so identity providers' signing keys are fetched once per process, not per request.\n JwksStoreFeature.register(rootContainer);\n\n // ── Background tasks (root) ────────────────────────────────\n // Mirrors the AWS handler registering its background-task transport at root. Where AWS\n // has Step Functions invoke the Lambda once per iteration, a root task loop dispatches a\n // BackgroundTaskEvent per iteration through the InputDispatcher (registered by\n // createServerHandler), and each one runs in a fresh request container.\n BackgroundTasksStandaloneFeature.register(rootContainer);\n\n // ── Scheduler (root) ───────────────────────────────────────\n // The scheduler is a single long-lived instance for ALL tenants, started once at boot\n // (onServer, below) — the counterpart of the WebSockets connection manager, NOT a per-request\n // transport. Registered here as SchedulerService (per-request create/update/delete during\n // mutations manipulate this one live timer set) plus the run/recover event handlers. When a\n // timer fires (outside any request) it dispatches a ScheduledActionEvent, handled in a fresh\n // request container by the same handler AWS uses.\n registerSchedulerServer(rootContainer);\n\n // ── Bulk actions (root) ───────────────────────────────────\n // Registers the EmptyTrashBinsEvent handler that the periodic trigger\n // (startBulkActionsServer, onServer below) dispatches.\n EmptyTrashBinsFeature.register(rootContainer);\n\n // ── CORS allowed headers (root) ────────────────────────────\n // The request headers extensions allow in the CORS preflight: read once, at start, for\n // the CORS step, which runs at request level, before any tenant scope (where extensions\n // register). Last: it registers what a request has, the extensions included, in a\n // throwaway container.\n await registerRootAllowedRequestHeaders(rootContainer);\n\n // ── Declared storages (root) ───────────────────────────────\n // Refuses to start when an extra storage that wasn't retired was removed from the\n // config: tenants may still run on it. Needs a request's services, so it runs last.\n await guardDeclaredTenantStorages({\n root: rootContainer,\n registerRequest: container => registerApiRequestStack(container, stackConfig)\n });\n },\n\n child: async container => {\n await registerApiRequestStack(container, stackConfig);\n },\n\n onServer: async (server, rootContainer) => {\n // Attach the WebSockets upgrade handler to the running HTTP server, backed by the shared\n // (root) connection manager so request-time sends reach the live sockets.\n //\n // Authenticate each WebSocket connection from its `?token` JWT so it's registered under\n // the real identity (targeted server→client sends match by identity id). It's a callback\n // the handler supplies rather than something the WS server resolves itself — see\n // createWebsocketsAuthenticator for why (AuthenticationContext is per-request, unreachable\n // from the root container the WS server is attached to).\n const connectionManager = rootContainer.resolve(WebsocketsConnectionManager);\n const adapter = rootContainer.resolve(WebsocketsServerAdapter);\n const websockets = attachWebsocketsServer({\n server,\n connectionManager,\n adapter,\n authenticate: createWebsocketsAuthenticator(rootContainer, config.extensions)\n });\n await websockets.start();\n stopWebsockets = () => websockets.stop();\n\n // Receive sends and disconnects other API processes publish for this one's sockets.\n const messageBus = rootContainer.resolve(WebsocketsMessageBus);\n const processOwner = rootContainer.resolve(ProcessOwner);\n const handleBusMessage = createBusMessageHandler({\n connectionManager,\n adapter,\n logger\n });\n await messageBus.subscribe(processOwner.id, handleBusMessage);\n closeMessageBus = () => messageBus.close();\n logger.info(\n { messageBus: standaloneConfig.redisUrl ? \"redis\" : \"in-process\" },\n \"[websockets] using message bus\"\n );\n\n /*\n * Start the in-process scheduler timers, then re-arm persisted schedules in the\n * background, at boot and then every minute (see startSchedulerServer).\n */\n stopScheduler = await startSchedulerServer(rootContainer);\n\n // Start the periodic empty-trash-bin trigger.\n startBulkActionsServer(rootContainer);\n\n /*\n * Take over tasks a restart or another process left behind, at boot and then every\n * minute (see startTaskRecovery).\n */\n stopTaskRecovery = startTaskRecovery(rootContainer);\n },\n\n onShutdown: async (rootContainer, { requestsFinished }) => {\n /*\n * Stop starting new work first: task recovery, and the scheduler's timers and recovery.\n * Then wait for what is running: tasks hand themselves back, so another process picks\n * them up at its next sweep, and scheduled actions already running get to finish.\n * Websockets close at the same time, with 1012 so clients reconnect to a process that\n * is up, and their connections leave the registry; that takes about a second. The\n * message bus closes last, once tasks, scheduled actions and HTTP requests in flight\n * are done: what they still send to browsers on other processes goes through it.\n */\n stopTaskRecovery?.();\n const tasks = stopBackgroundTasks(rootContainer, SHUTDOWN_WAIT_MS);\n const scheduledActions = stopScheduler?.(SHUTDOWN_WAIT_MS);\n const websockets = stopWebsockets?.();\n const workDone = Promise.allSettled([tasks, scheduledActions, requestsFinished]);\n const messageBus = workDone.then(() => closeMessageBus?.());\n\n // One failing part must not cut the others short; the first failure is reported after.\n const results = await Promise.allSettled([\n tasks,\n scheduledActions,\n websockets,\n messageBus\n ]);\n const failed = results.find((result): result is PromiseRejectedResult => {\n return result.status === \"rejected\";\n });\n if (failed) {\n throw failed.reason;\n }\n }\n });\n}\n"],"names":["SHUTDOWN_WAIT_MS","createWebinyApiHandler","config","stopTaskRecovery","stopScheduler","stopWebsockets","closeMessageBus","standaloneConfig","readStandaloneConfig","process","logger","createLogger","stackConfig","scopeContainer","ConfigPublicUrlsFeature","StandaloneCryptoConfigFeature","WebsocketsStandaloneFeature","uploadSecret","FileManagerStandaloneFeature","createServerHandler","rootContainer","buildParams","registerRootBuildParams","assertNoBakedSecrets","assertFileStorage","StandaloneConfig","Logger","RandomProcessOwner","registerHttpTransport","NodeHttpFeature","NodeHttpInputHandler","TenantScopesRootFeature","ApiRequestRegistration","container","options","registerApiRequestStackInOneContainer","WebsocketsServerRootFeature","WebsocketsRedisFeature","InProcessMessageBus","GraphQLSchemaCacheFeature","EncryptionKeyCacheFeature","JwksStoreFeature","BackgroundTasksStandaloneFeature","registerSchedulerServer","EmptyTrashBinsFeature","registerRootAllowedRequestHeaders","guardDeclaredTenantStorages","registerApiRequestStack","server","connectionManager","WebsocketsConnectionManager","adapter","WebsocketsServerAdapter","websockets","attachWebsocketsServer","createWebsocketsAuthenticator","messageBus","WebsocketsMessageBus","processOwner","ProcessOwner","handleBusMessage","createBusMessageHandler","startSchedulerServer","startBulkActionsServer","startTaskRecovery","requestsFinished","tasks","stopBackgroundTasks","scheduledActions","workDone","Promise","results","failed","result"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA8FA,MAAMA,mBAAmB;AAElB,SAASC,uBAAuBC,MAAoC;IACvE,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IAMJ,MAAMC,mBAAmBC,qBAAqBC,QAAQ,GAAG;IAGzD,MAAMC,SAASC;IAQf,MAAMC,cAA6C;QAC/C,YAAYV,OAAO,UAAU;QAU7B,YAAY;YAKR,eAAeW,CAAAA;gBACXC,wBAAwB,QAAQ,CAACD;gBACjCE,8BAA8B,QAAQ,CAACF;YAC3C;YAIA,UAAUA,CAAAA;gBACNG,4BAA4B,QAAQ,CAACH;YACzC;YAUA,aAAaA,CAAAA;gBACT,MAAM,EAAEI,YAAY,EAAE,GAAGV,iBAAiB,WAAW;gBACrDW,6BAA6B,QAAQ,CAACL,gBAAgB;oBAAEI;gBAAa;YACzE;QACJ;IACJ;IAEA,OAAOE,oBAAoB;QACvB,oBAAoBZ,iBAAiB,kBAAkB;QACvD,MAAM,OAAMa;YAOR,MAAMC,cAAc,MAAMC,wBAAwBF,eAAelB,OAAO,UAAU;YAClFqB,qBAAqBF;YACrBG,kBAAkBH;YAElBD,cAAc,gBAAgB,CAACK,kBAAkBlB;YACjDa,cAAc,gBAAgB,CAACM,QAAQhB;YAGvCU,cAAc,QAAQ,CAACO,oBAAoB,gBAAgB;YAM3DC,sBAAsBR,eAAeS,iBAAiBC;YAItDC,wBAAwB,QAAQ,CAACX;YAEjCA,cAAc,gBAAgB,CAACY,wBAAwB;gBACnD,UAAU,CAACC,WAAWC,UACXC,sCAAsCF,WAAWrB,aAAasB;YAE7E;YAGA,MAAMhC,OAAO,mBAAmB,CAACkB,eAAe;gBAAEC;YAAY;YAQ9De,4BAA4B,QAAQ,CAAChB;YAMrC,IAAIb,iBAAiB,QAAQ,EACzB8B,uBAAuB,QAAQ,CAACjB,eAAe;gBAC3C,KAAKb,iBAAiB,QAAQ;gBAC9BG;YACJ;iBAEAU,cAAc,QAAQ,CAACkB,qBAAqB,gBAAgB;YAKhEC,0BAA0B,QAAQ,CAACnB;YAInCoB,0BAA0B,QAAQ,CAACpB;YAEnCqB,iBAAiB,QAAQ,CAACrB;YAO1BsB,iCAAiC,QAAQ,CAACtB;YAS1CuB,wBAAwBvB;YAKxBwB,sBAAsB,QAAQ,CAACxB;YAO/B,MAAMyB,kCAAkCzB;YAKxC,MAAM0B,4BAA4B;gBAC9B,MAAM1B;gBACN,iBAAiBa,CAAAA,YAAac,wBAAwBd,WAAWrB;YACrE;QACJ;QAEA,OAAO,OAAMqB;YACT,MAAMc,wBAAwBd,WAAWrB;QAC7C;QAEA,UAAU,OAAOoC,QAAQ5B;YASrB,MAAM6B,oBAAoB7B,cAAc,OAAO,CAAC8B;YAChD,MAAMC,UAAU/B,cAAc,OAAO,CAACgC;YACtC,MAAMC,aAAaC,uBAAuB;gBACtCN;gBACAC;gBACAE;gBACA,cAAcI,8BAA8BnC,eAAelB,OAAO,UAAU;YAChF;YACA,MAAMmD,WAAW,KAAK;YACtBhD,iBAAiB,IAAMgD,WAAW,IAAI;YAGtC,MAAMG,aAAapC,cAAc,OAAO,CAACqC;YACzC,MAAMC,eAAetC,cAAc,OAAO,CAACuC;YAC3C,MAAMC,mBAAmBC,wBAAwB;gBAC7CZ;gBACAE;gBACAzC;YACJ;YACA,MAAM8C,WAAW,SAAS,CAACE,aAAa,EAAE,EAAEE;YAC5CtD,kBAAkB,IAAMkD,WAAW,KAAK;YACxC9C,OAAO,IAAI,CACP;gBAAE,YAAYH,iBAAiB,QAAQ,GAAG,UAAU;YAAa,GACjE;YAOJH,gBAAgB,MAAM0D,qBAAqB1C;YAG3C2C,uBAAuB3C;YAMvBjB,mBAAmB6D,kBAAkB5C;QACzC;QAEA,YAAY,OAAOA,eAAe,EAAE6C,gBAAgB,EAAE;YAUlD9D;YACA,MAAM+D,QAAQC,oBAAoB/C,eAAepB;YACjD,MAAMoE,mBAAmBhE,gBAAgBJ;YACzC,MAAMqD,aAAahD;YACnB,MAAMgE,WAAWC,QAAQ,UAAU,CAAC;gBAACJ;gBAAOE;gBAAkBH;aAAiB;YAC/E,MAAMT,aAAaa,SAAS,IAAI,CAAC,IAAM/D;YAGvC,MAAMiE,UAAU,MAAMD,QAAQ,UAAU,CAAC;gBACrCJ;gBACAE;gBACAf;gBACAG;aACH;YACD,MAAMgB,SAASD,QAAQ,IAAI,CAAC,CAACE,SAClBA,AAAkB,eAAlBA,OAAO,MAAM;YAExB,IAAID,QACA,MAAMA,OAAO,MAAM;QAE3B;IACJ;AACJ"}
@@ -0,0 +1,17 @@
1
+ import { EncryptionConfig } from "@webiny/api-core/features/encryption/index.js";
2
+ import { BuildParams } from "@webiny/api-core/features/buildParams/index.js";
3
+ import { StandaloneConfig } from "../config/abstractions.js";
4
+ /**
5
+ * Standalone: encryption is always on. The passphrase and salt come from env
6
+ * (`WEBINY_ENCRYPTION_PASSPHRASE`, `WEBINY_ENCRYPTION_SALT`), the algorithm from the build.
7
+ */
8
+ declare class StandaloneEncryptionConfigImpl implements EncryptionConfig.Interface {
9
+ readonly passphrase: string;
10
+ readonly salt: string;
11
+ readonly algorithm: string;
12
+ constructor(config: StandaloneConfig.Interface, buildParams: BuildParams.Interface);
13
+ }
14
+ export declare const StandaloneEncryptionConfig: typeof StandaloneEncryptionConfigImpl & {
15
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/encryption/abstractions").IEncryptionConfig>;
16
+ };
17
+ export {};
@@ -0,0 +1,20 @@
1
+ import { DEFAULT_ENCRYPTION_ALGORITHM, EncryptionConfig } from "@webiny/api-core/features/encryption/index.js";
2
+ import { BuildParams } from "@webiny/api-core/features/buildParams/index.js";
3
+ import { StandaloneConfig } from "../config/abstractions.js";
4
+ class StandaloneEncryptionConfigImpl {
5
+ constructor(config, buildParams){
6
+ this.passphrase = config.encryption.passphrase;
7
+ this.salt = config.encryption.salt;
8
+ this.algorithm = buildParams.get("EncryptionAlgorithm") ?? DEFAULT_ENCRYPTION_ALGORITHM;
9
+ }
10
+ }
11
+ const StandaloneEncryptionConfig = EncryptionConfig.createImplementation({
12
+ implementation: StandaloneEncryptionConfigImpl,
13
+ dependencies: [
14
+ StandaloneConfig,
15
+ BuildParams
16
+ ]
17
+ });
18
+ export { StandaloneEncryptionConfig };
19
+
20
+ //# sourceMappingURL=StandaloneEncryptionConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto/StandaloneEncryptionConfig.js","sources":["../../src/crypto/StandaloneEncryptionConfig.ts"],"sourcesContent":["import { EncryptionConfig } from \"@webiny/api-core/features/encryption/index.js\";\nimport { DEFAULT_ENCRYPTION_ALGORITHM } from \"@webiny/api-core/features/encryption/index.js\";\nimport { BuildParams } from \"@webiny/api-core/features/buildParams/index.js\";\nimport { StandaloneConfig } from \"~/config/abstractions.js\";\n\n/**\n * Standalone: encryption is always on. The passphrase and salt come from env\n * (`WEBINY_ENCRYPTION_PASSPHRASE`, `WEBINY_ENCRYPTION_SALT`), the algorithm from the build.\n */\nclass StandaloneEncryptionConfigImpl implements EncryptionConfig.Interface {\n readonly passphrase: string;\n readonly salt: string;\n readonly algorithm: string;\n\n constructor(config: StandaloneConfig.Interface, buildParams: BuildParams.Interface) {\n this.passphrase = config.encryption.passphrase;\n this.salt = config.encryption.salt;\n this.algorithm =\n buildParams.get<string>(\"EncryptionAlgorithm\") ?? DEFAULT_ENCRYPTION_ALGORITHM;\n }\n}\n\nexport const StandaloneEncryptionConfig = EncryptionConfig.createImplementation({\n implementation: StandaloneEncryptionConfigImpl,\n dependencies: [StandaloneConfig, BuildParams]\n});\n"],"names":["StandaloneEncryptionConfigImpl","config","buildParams","DEFAULT_ENCRYPTION_ALGORITHM","StandaloneEncryptionConfig","EncryptionConfig","StandaloneConfig","BuildParams"],"mappings":";;;AASA,MAAMA;IAKF,YAAYC,MAAkC,EAAEC,WAAkC,CAAE;QAChF,IAAI,CAAC,UAAU,GAAGD,OAAO,UAAU,CAAC,UAAU;QAC9C,IAAI,CAAC,IAAI,GAAGA,OAAO,UAAU,CAAC,IAAI;QAClC,IAAI,CAAC,SAAS,GACVC,YAAY,GAAG,CAAS,0BAA0BC;IAC1D;AACJ;AAEO,MAAMC,6BAA6BC,iBAAiB,oBAAoB,CAAC;IAC5E,gBAAgBL;IAChB,cAAc;QAACM;QAAkBC;KAAY;AACjD"}
@@ -0,0 +1,16 @@
1
+ import { HashingConfig } from "@webiny/api-core/features/hashing/index.js";
2
+ import { BuildParams } from "@webiny/api-core/features/buildParams/index.js";
3
+ import { StandaloneConfig } from "../config/abstractions.js";
4
+ /**
5
+ * Standalone: every hash is peppered. The pepper comes from env (`WEBINY_HASHING_PEPPER`), the cost
6
+ * from the build.
7
+ */
8
+ declare class StandaloneHashingConfigImpl implements HashingConfig.Interface {
9
+ readonly pepper: string;
10
+ readonly costN: number | null;
11
+ constructor(config: StandaloneConfig.Interface, buildParams: BuildParams.Interface);
12
+ }
13
+ export declare const StandaloneHashingConfig: typeof StandaloneHashingConfigImpl & {
14
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/hashing/abstractions").IHashingConfig>;
15
+ };
16
+ export {};
@@ -0,0 +1,20 @@
1
+ import { HashingConfig } from "@webiny/api-core/features/hashing/index.js";
2
+ import { BuildParams } from "@webiny/api-core/features/buildParams/index.js";
3
+ import { StandaloneConfig } from "../config/abstractions.js";
4
+ class StandaloneHashingConfigImpl {
5
+ constructor(config, buildParams){
6
+ this.pepper = config.hashing.pepper;
7
+ const costN = buildParams.get("HashingCost");
8
+ this.costN = costN ? Number(costN) : null;
9
+ }
10
+ }
11
+ const StandaloneHashingConfig = HashingConfig.createImplementation({
12
+ implementation: StandaloneHashingConfigImpl,
13
+ dependencies: [
14
+ StandaloneConfig,
15
+ BuildParams
16
+ ]
17
+ });
18
+ export { StandaloneHashingConfig };
19
+
20
+ //# sourceMappingURL=StandaloneHashingConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto/StandaloneHashingConfig.js","sources":["../../src/crypto/StandaloneHashingConfig.ts"],"sourcesContent":["import { HashingConfig } from \"@webiny/api-core/features/hashing/index.js\";\nimport { BuildParams } from \"@webiny/api-core/features/buildParams/index.js\";\nimport { StandaloneConfig } from \"~/config/abstractions.js\";\n\n/**\n * Standalone: every hash is peppered. The pepper comes from env (`WEBINY_HASHING_PEPPER`), the cost\n * from the build.\n */\nclass StandaloneHashingConfigImpl implements HashingConfig.Interface {\n readonly pepper: string;\n readonly costN: number | null;\n\n constructor(config: StandaloneConfig.Interface, buildParams: BuildParams.Interface) {\n this.pepper = config.hashing.pepper;\n const costN = buildParams.get<number | string>(\"HashingCost\");\n this.costN = costN ? Number(costN) : null;\n }\n}\n\nexport const StandaloneHashingConfig = HashingConfig.createImplementation({\n implementation: StandaloneHashingConfigImpl,\n dependencies: [StandaloneConfig, BuildParams]\n});\n"],"names":["StandaloneHashingConfigImpl","config","buildParams","costN","Number","StandaloneHashingConfig","HashingConfig","StandaloneConfig","BuildParams"],"mappings":";;;AAQA,MAAMA;IAIF,YAAYC,MAAkC,EAAEC,WAAkC,CAAE;QAChF,IAAI,CAAC,MAAM,GAAGD,OAAO,OAAO,CAAC,MAAM;QACnC,MAAME,QAAQD,YAAY,GAAG,CAAkB;QAC/C,IAAI,CAAC,KAAK,GAAGC,QAAQC,OAAOD,SAAS;IACzC;AACJ;AAEO,MAAME,0BAA0BC,cAAc,oBAAoB,CAAC;IACtE,gBAAgBN;IAChB,cAAc;QAACO;QAAkBC;KAAY;AACjD"}
@@ -0,0 +1,5 @@
1
+ /** Replaces api-core's build-param crypto configs with ones that read secrets from env. */
2
+ export declare const StandaloneCryptoConfigFeature: {
3
+ name: string;
4
+ register(container: import("@webiny/di").Container): void;
5
+ };
@@ -0,0 +1,13 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { StandaloneEncryptionConfig } from "./StandaloneEncryptionConfig.js";
3
+ import { StandaloneHashingConfig } from "./StandaloneHashingConfig.js";
4
+ const StandaloneCryptoConfigFeature = createFeature({
5
+ name: "StandaloneCryptoConfigFeature",
6
+ register (container) {
7
+ container.register(StandaloneEncryptionConfig);
8
+ container.register(StandaloneHashingConfig);
9
+ }
10
+ });
11
+ export { StandaloneCryptoConfigFeature };
12
+
13
+ //# sourceMappingURL=feature.js.map