@webiny/api-composition-standalone-sql 0.0.0-stage β†’ 0.0.0-unstable.e1999482d0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE 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-sql
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,34 @@
1
+ /**
2
+ * Webiny API handler for the standalone Node server transport on a SQL storage.
3
+ *
4
+ * Thin variant over the transport base (@webiny/api-composition-standalone): takes the storage
5
+ * (`createSqliteStorage` from @webiny/api-storage-sqlite, or `createPgStorage` from
6
+ * @webiny/api-storage-pg, each built from its connection) and adds the self-hosted identity provider
7
+ * (JWT IdP + SQL credential storage) on the storage's connection.
8
+ *
9
+ * At start, before the server accepts a request, it runs the storage's schema setup
10
+ * (`SqlSchemaSetupRunner`) on a container built the way a request's is, so the storage, the login
11
+ * tables and the modules among the project's extensions set up theirs. Then the storage is
12
+ * schema-managed: no request checks for or creates tables. The JWT signing secret is read from
13
+ * `WEBINY_SELF_HOSTED_AUTH_SECRET` when the handler is created.
14
+ */
15
+ import type { Container } from "@webiny/di";
16
+ import { type SqlStorage } from "@webiny/api-core-sql";
17
+ import { type CreateWebinyApiHandlerConfig as BaseConfig } from "@webiny/api-composition-standalone";
18
+ export type CreateSqlApiHandlerConfig = Pick<BaseConfig, "extensions"> & {
19
+ /** The SQL storage of the API, built from its connection. */
20
+ storage: SqlStorage;
21
+ };
22
+ /**
23
+ * What the handler puts in the root container, once per process: the storage (the connection and
24
+ * its settings, its `RequestStorage` and its schema setup runner), the login storage's
25
+ * `RequestStorage`, and the self-hosted JWT identity provider. The IdP is in the root so the
26
+ * RequestIdentityLoader (driven by NodeHttpIdentityLoaderDecorator) can resolve it; it only needs the
27
+ * token issuer, and the login use cases it registers resolve the credential storage from the
28
+ * request's container.
29
+ */
30
+ export declare function registerSqlApiRoot(container: Container, params: {
31
+ storage: SqlStorage;
32
+ signingSecret: string;
33
+ }): void;
34
+ export declare function createSqlApiHandler(config: CreateSqlApiHandlerConfig): Promise<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>>;
@@ -0,0 +1,38 @@
1
+ import { RequestStorage } from "@webiny/api-core";
2
+ import { SqlSchemaSetupRunner } from "@webiny/api-core-sql";
3
+ import { ApiRequestRegistration } from "@webiny/api-composition-core";
4
+ import { createWebinyApiHandler } from "@webiny/api-composition-standalone";
5
+ import { SelfHostedAuthApiFeature } from "@webiny/self-hosted-auth";
6
+ import { SelfHostedAuthSqlFeature } from "@webiny/self-hosted-auth-sql";
7
+ import { readSigningSecret } from "./readSigningSecret.js";
8
+ const SelfHostedAuthRequestStorage = {
9
+ register (container) {
10
+ SelfHostedAuthSqlFeature.register(container);
11
+ }
12
+ };
13
+ function registerSqlApiRoot(container, params) {
14
+ params.storage.register(container);
15
+ container.registerInstance(RequestStorage, SelfHostedAuthRequestStorage);
16
+ SelfHostedAuthApiFeature.register(container, {
17
+ signingSecret: params.signingSecret
18
+ });
19
+ }
20
+ function createSqlApiHandler(config) {
21
+ const { storage } = config;
22
+ const signingSecret = readSigningSecret(process.env);
23
+ return createWebinyApiHandler({
24
+ extensions: config.extensions,
25
+ registerRootStorage: async (container)=>{
26
+ registerSqlApiRoot(container, {
27
+ storage,
28
+ signingSecret
29
+ });
30
+ await container.resolve(SqlSchemaSetupRunner).run({
31
+ request: container.resolve(ApiRequestRegistration)
32
+ });
33
+ }
34
+ });
35
+ }
36
+ export { createSqlApiHandler, registerSqlApiRoot };
37
+
38
+ //# 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 server transport on a SQL storage.\n *\n * Thin variant over the transport base (@webiny/api-composition-standalone): takes the storage\n * (`createSqliteStorage` from @webiny/api-storage-sqlite, or `createPgStorage` from\n * @webiny/api-storage-pg, each built from its connection) and adds the self-hosted identity provider\n * (JWT IdP + SQL credential storage) on the storage's connection.\n *\n * At start, before the server accepts a request, it runs the storage's schema setup\n * (`SqlSchemaSetupRunner`) on a container built the way a request's is, so the storage, the login\n * tables and the modules among the project's extensions set up theirs. Then the storage is\n * schema-managed: no request checks for or creates tables. The JWT signing secret is read from\n * `WEBINY_SELF_HOSTED_AUTH_SECRET` when the handler is created.\n */\nimport type { Container } from \"@webiny/di\";\nimport { RequestStorage } from \"@webiny/api-core\";\nimport { SqlSchemaSetupRunner, type SqlStorage } from \"@webiny/api-core-sql\";\nimport { ApiRequestRegistration } from \"@webiny/api-composition-core\";\nimport {\n createWebinyApiHandler as createBaseHandler,\n type CreateWebinyApiHandlerConfig as BaseConfig\n} from \"@webiny/api-composition-standalone\";\nimport { SelfHostedAuthApiFeature } from \"@webiny/self-hosted-auth\";\nimport { SelfHostedAuthSqlFeature } from \"@webiny/self-hosted-auth-sql\";\nimport { readSigningSecret } from \"~/readSigningSecret.js\";\n\nexport type CreateSqlApiHandlerConfig = Pick<BaseConfig, \"extensions\"> & {\n /** The SQL storage of the API, built from its connection. */\n storage: SqlStorage;\n};\n\n/*\n * The login storage of a request: the credentials and reset codes, on the storage's connection and\n * table settings (`KnexClient`, `SqlSchemaConfig`, in the root).\n */\nconst SelfHostedAuthRequestStorage: RequestStorage.Interface = {\n register(container) {\n SelfHostedAuthSqlFeature.register(container);\n }\n};\n\n/**\n * What the handler puts in the root container, once per process: the storage (the connection and\n * its settings, its `RequestStorage` and its schema setup runner), the login storage's\n * `RequestStorage`, and the self-hosted JWT identity provider. The IdP is in the root so the\n * RequestIdentityLoader (driven by NodeHttpIdentityLoaderDecorator) can resolve it; it only needs the\n * token issuer, and the login use cases it registers resolve the credential storage from the\n * request's container.\n */\nexport function registerSqlApiRoot(\n container: Container,\n params: { storage: SqlStorage; signingSecret: string }\n): void {\n params.storage.register(container);\n container.registerInstance(RequestStorage, SelfHostedAuthRequestStorage);\n SelfHostedAuthApiFeature.register(container, { signingSecret: params.signingSecret });\n}\n\nexport function createSqlApiHandler(config: CreateSqlApiHandlerConfig) {\n const { storage } = config;\n // Read once, so a missing secret stops the server at boot instead of failing the first login.\n const signingSecret = readSigningSecret(process.env);\n\n return createBaseHandler({\n extensions: config.extensions,\n registerRootStorage: async container => {\n registerSqlApiRoot(container, { storage, signingSecret });\n /*\n * Before the server takes traffic: `root` runs before the server is handed back to\n * listen. The setup's container is built as a request's (`ApiRequestRegistration`), so\n * the login storage's `RequestStorage` adds the login tables. A failure (a missing\n * module, a database that's down) stops the server here.\n */\n await container.resolve(SqlSchemaSetupRunner).run({\n request: container.resolve(ApiRequestRegistration)\n });\n }\n });\n}\n"],"names":["SelfHostedAuthRequestStorage","container","SelfHostedAuthSqlFeature","registerSqlApiRoot","params","RequestStorage","SelfHostedAuthApiFeature","createSqlApiHandler","config","storage","signingSecret","readSigningSecret","process","createBaseHandler","SqlSchemaSetupRunner","ApiRequestRegistration"],"mappings":";;;;;;;AAmCA,MAAMA,+BAAyD;IAC3D,UAASC,SAAS;QACdC,yBAAyB,QAAQ,CAACD;IACtC;AACJ;AAUO,SAASE,mBACZF,SAAoB,EACpBG,MAAsD;IAEtDA,OAAO,OAAO,CAAC,QAAQ,CAACH;IACxBA,UAAU,gBAAgB,CAACI,gBAAgBL;IAC3CM,yBAAyB,QAAQ,CAACL,WAAW;QAAE,eAAeG,OAAO,aAAa;IAAC;AACvF;AAEO,SAASG,oBAAoBC,MAAiC;IACjE,MAAM,EAAEC,OAAO,EAAE,GAAGD;IAEpB,MAAME,gBAAgBC,kBAAkBC,QAAQ,GAAG;IAEnD,OAAOC,uBAAkB;QACrB,YAAYL,OAAO,UAAU;QAC7B,qBAAqB,OAAMP;YACvBE,mBAAmBF,WAAW;gBAAEQ;gBAASC;YAAc;YAOvD,MAAMT,UAAU,OAAO,CAACa,sBAAsB,GAAG,CAAC;gBAC9C,SAASb,UAAU,OAAO,CAACc;YAC/B;QACJ;IACJ;AACJ"}
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { createSqlApiHandler } from "./createWebinyApiHandler.js";
2
+ export type { CreateSqlApiHandlerConfig } from "./createWebinyApiHandler.js";
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export { createSqlApiHandler } from "./createWebinyApiHandler.js";
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
- "name": "@webiny/api-composition-standalone-sql",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@webiny/api-composition-standalone-sql",
3
+ "version": "0.0.0-unstable.e1999482d0",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "exports": {
7
+ ".": "./index.js",
8
+ "./*": "./*"
9
+ },
10
+ "types": "index.d.ts",
11
+ "description": "EXPERIMENTAL: Webiny API handler for the Node server transport on a SQL storage (SQLite or Postgres).",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/webiny/webiny-js.git"
15
+ },
16
+ "contributors": [
17
+ "Webiny Team"
18
+ ],
19
+ "license": "MIT",
20
+ "dependencies": {
21
+ "@webiny/api-composition-core": "0.0.0-unstable.e1999482d0",
22
+ "@webiny/api-composition-standalone": "0.0.0-unstable.e1999482d0",
23
+ "@webiny/api-core": "0.0.0-unstable.e1999482d0",
24
+ "@webiny/api-core-sql": "0.0.0-unstable.e1999482d0",
25
+ "@webiny/api-mailer": "0.0.0-unstable.e1999482d0",
26
+ "@webiny/di": "2.0.0",
27
+ "@webiny/handler": "0.0.0-unstable.e1999482d0",
28
+ "@webiny/self-hosted-auth": "0.0.0-unstable.e1999482d0",
29
+ "@webiny/self-hosted-auth-sql": "0.0.0-unstable.e1999482d0"
30
+ },
31
+ "devDependencies": {
32
+ "@electric-sql/pglite": "0.5.17",
33
+ "@electric-sql/pglite-socket": "0.2.20",
34
+ "@types/ws": "8.18.2",
35
+ "@webiny/api-aco": "0.0.0-unstable.e1999482d0",
36
+ "@webiny/api-aco-pg": "0.0.0-unstable.e1999482d0",
37
+ "@webiny/api-audit-logs": "0.0.0-unstable.e1999482d0",
38
+ "@webiny/api-headless-cms": "0.0.0-unstable.e1999482d0",
39
+ "@webiny/api-headless-cms-pg": "0.0.0-unstable.e1999482d0",
40
+ "@webiny/api-storage-pg": "0.0.0-unstable.e1999482d0",
41
+ "@webiny/api-storage-sqlite": "0.0.0-unstable.e1999482d0",
42
+ "@webiny/api-websockets": "0.0.0-unstable.e1999482d0",
43
+ "@webiny/build-tools": "0.0.0-unstable.e1999482d0",
44
+ "knex": "3.3.0",
45
+ "rimraf": "6.1.4",
46
+ "typescript": "7.0.2",
47
+ "vitest": "5.1.1",
48
+ "ws": "8.23.0"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ },
53
+ "webiny": {
54
+ "publishFrom": "dist"
55
+ }
56
+ }
@@ -0,0 +1,7 @@
1
+ type Env = Record<string, string | undefined>;
2
+ /**
3
+ * The self-hosted auth signing secret, from env. Throws when it is missing or blank: without it no
4
+ * one can log in, and falling back to a known value would let anyone mint a login token.
5
+ */
6
+ export declare function readSigningSecret(env: Env): string;
7
+ export {};
@@ -0,0 +1,9 @@
1
+ import { SIGNING_SECRET_ENV_VAR } from "@webiny/self-hosted-auth";
2
+ function readSigningSecret(env) {
3
+ const secret = env[SIGNING_SECRET_ENV_VAR];
4
+ if (!secret?.trim()) throw new Error(`The standalone API is missing required configuration: ${SIGNING_SECRET_ENV_VAR} is not set.`);
5
+ return secret;
6
+ }
7
+ export { readSigningSecret };
8
+
9
+ //# sourceMappingURL=readSigningSecret.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readSigningSecret.js","sources":["../src/readSigningSecret.ts"],"sourcesContent":["import { SIGNING_SECRET_ENV_VAR } from \"@webiny/self-hosted-auth\";\n\ntype Env = Record<string, string | undefined>;\n\n/**\n * The self-hosted auth signing secret, from env. Throws when it is missing or blank: without it no\n * one can log in, and falling back to a known value would let anyone mint a login token.\n */\nexport function readSigningSecret(env: Env): string {\n /*\n * Blank means unset, but the value itself is used as given: `webiny reset-password` signs with\n * the untrimmed value, and existing tokens were signed with it.\n */\n const secret = env[SIGNING_SECRET_ENV_VAR];\n if (!secret?.trim()) {\n throw new Error(\n `The standalone API is missing required configuration: ${SIGNING_SECRET_ENV_VAR} is not set.`\n );\n }\n\n return secret;\n}\n"],"names":["readSigningSecret","env","secret","SIGNING_SECRET_ENV_VAR","Error"],"mappings":";AAQO,SAASA,kBAAkBC,GAAQ;IAKtC,MAAMC,SAASD,GAAG,CAACE,uBAAuB;IAC1C,IAAI,CAACD,QAAQ,QACT,MAAM,IAAIE,MACN,CAAC,sDAAsD,EAAED,uBAAuB,YAAY,CAAC;IAIrG,OAAOD;AACX"}