diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 9ef8d6ecb..80ec2f211 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.1.26](https://github.com/launchql/launchql/compare/@launchql/cli@4.1.25...@launchql/cli@4.1.26) (2025-05-27) + +**Note:** Version bump only for package @launchql/cli + + + + + ## [4.1.25](https://github.com/launchql/launchql/compare/@launchql/cli@4.1.24...@launchql/cli@4.1.25) (2025-05-25) **Note:** Version bump only for package @launchql/cli diff --git a/packages/cli/package.json b/packages/cli/package.json index 86ab80e95..8915b45c5 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@launchql/cli", - "version": "4.1.25", + "version": "4.1.26", "author": "Dan Lynch ", "description": "LaunchQL CLI", "main": "index.js", @@ -41,12 +41,12 @@ "ts-node": "^10.9.2" }, "dependencies": { - "@launchql/core": "^2.1.16", - "@launchql/explorer": "^2.1.13", - "@launchql/server": "^2.1.15", - "@launchql/server-utils": "^2.1.10", + "@launchql/core": "^2.1.17", + "@launchql/explorer": "^2.1.14", + "@launchql/server": "^2.1.16", + "@launchql/server-utils": "^2.1.11", "@launchql/templatizer": "^2.1.4", - "@launchql/types": "^2.1.8", + "@launchql/types": "^2.1.9", "chalk": "^4.1.0", "deepmerge": "^4.3.1", "inquirerer": "^2.0.8", diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index f79dd5d13..6cfb3d756 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.1.17](https://github.com/launchql/launchql/compare/@launchql/core@2.1.16...@launchql/core@2.1.17) (2025-05-27) + +**Note:** Version bump only for package @launchql/core + + + + + ## [2.1.16](https://github.com/launchql/launchql/compare/@launchql/core@2.1.15...@launchql/core@2.1.16) (2025-05-25) **Note:** Version bump only for package @launchql/core diff --git a/packages/core/package.json b/packages/core/package.json index 41e11859e..d051db9ca 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@launchql/core", - "version": "2.1.16", + "version": "2.1.17", "author": "Dan Lynch ", "description": "LaunchQL Package and Migration Tools", "main": "index.js", @@ -42,9 +42,9 @@ "@types/rimraf": "^4.0.5" }, "dependencies": { - "@launchql/server-utils": "^2.1.10", + "@launchql/server-utils": "^2.1.11", "@launchql/templatizer": "^2.1.4", - "@launchql/types": "^2.1.8", + "@launchql/types": "^2.1.9", "case": "^1.6.3", "chalk": "^4.1.0", "csv-to-pg": "^2.0.9", diff --git a/packages/explorer/CHANGELOG.md b/packages/explorer/CHANGELOG.md index 85e205d73..6c680de5e 100644 --- a/packages/explorer/CHANGELOG.md +++ b/packages/explorer/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.1.14](https://github.com/launchql/launchql/compare/@launchql/explorer@2.1.13...@launchql/explorer@2.1.14) (2025-05-27) + +**Note:** Version bump only for package @launchql/explorer + + + + + ## [2.1.13](https://github.com/launchql/launchql/compare/@launchql/explorer@2.1.12...@launchql/explorer@2.1.13) (2025-05-25) **Note:** Version bump only for package @launchql/explorer diff --git a/packages/explorer/package.json b/packages/explorer/package.json index 6ef1d0309..4e3cc96e3 100644 --- a/packages/explorer/package.json +++ b/packages/explorer/package.json @@ -1,6 +1,6 @@ { "name": "@launchql/explorer", - "version": "2.1.13", + "version": "2.1.14", "author": "Dan Lynch ", "description": "LaunchQL Explorer", "main": "index.js", @@ -35,14 +35,14 @@ "test:watch": "jest --watch" }, "dependencies": { - "@launchql/s3-streamer": "^2.1.8", - "@launchql/server-utils": "^2.1.10", - "@launchql/types": "^2.1.8", + "@launchql/s3-streamer": "^2.1.9", + "@launchql/server-utils": "^2.1.11", + "@launchql/types": "^2.1.9", "@launchql/upload-names": "^2.1.3", "@launchql/url-domains": "^2.1.3", "express": "^5.1.0", "graphile-build": "^4.14.1", - "graphile-settings": "^2.1.12", + "graphile-settings": "^2.1.13", "graphql-upload": "^15.0.2", "postgraphile": "^4.14.1" }, diff --git a/packages/graphile-settings/CHANGELOG.md b/packages/graphile-settings/CHANGELOG.md index c14292efd..ce2876a9c 100644 --- a/packages/graphile-settings/CHANGELOG.md +++ b/packages/graphile-settings/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.1.13](https://github.com/launchql/launchql/compare/graphile-settings@2.1.12...graphile-settings@2.1.13) (2025-05-27) + +**Note:** Version bump only for package graphile-settings + + + + + ## [2.1.12](https://github.com/launchql/launchql/compare/graphile-settings@2.1.11...graphile-settings@2.1.12) (2025-05-25) **Note:** Version bump only for package graphile-settings diff --git a/packages/graphile-settings/package.json b/packages/graphile-settings/package.json index de43fea90..3408facad 100644 --- a/packages/graphile-settings/package.json +++ b/packages/graphile-settings/package.json @@ -1,6 +1,6 @@ { "name": "graphile-settings", - "version": "2.1.12", + "version": "2.1.13", "author": "Dan Lynch ", "description": "graphile settings", "main": "index.js", @@ -31,8 +31,8 @@ }, "dependencies": { "@graphile-contrib/pg-many-to-many": "^1.0.2", - "@launchql/s3-streamer": "^2.1.8", - "@launchql/types": "^2.1.8", + "@launchql/s3-streamer": "^2.1.9", + "@launchql/types": "^2.1.9", "@launchql/upload-names": "^2.1.3", "@pyramation/postgis": "^0.1.1", "@pyramation/postgraphile-plugin-fulltext-filter": "^2.0.0", @@ -43,7 +43,7 @@ "graphile-meta-schema": "^0.2.5", "graphile-query": "^2.1.6", "graphile-search-plugin": "^0.1.2", - "graphile-settings": "^2.1.12", + "graphile-settings": "^2.1.13", "graphile-simple-inflector": "^0.1.1", "graphql-tag": "2.12.6", "lru-cache": "^11.1.0", diff --git a/packages/graphile-test/CHANGELOG.md b/packages/graphile-test/CHANGELOG.md index d8d43bc7f..a5e7e54f0 100644 --- a/packages/graphile-test/CHANGELOG.md +++ b/packages/graphile-test/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.1.16](https://github.com/launchql/launchql/compare/graphile-test@2.1.15...graphile-test@2.1.16) (2025-05-27) + +**Note:** Version bump only for package graphile-test + + + + + ## [2.1.15](https://github.com/launchql/launchql/compare/graphile-test@2.1.14...graphile-test@2.1.15) (2025-05-25) **Note:** Version bump only for package graphile-test diff --git a/packages/graphile-test/package.json b/packages/graphile-test/package.json index cd0669140..806d36e26 100644 --- a/packages/graphile-test/package.json +++ b/packages/graphile-test/package.json @@ -1,6 +1,6 @@ { "name": "graphile-test", - "version": "2.1.15", + "version": "2.1.16", "author": "Dan Lynch ", "description": "PostGraphile Testing", "main": "index.js", @@ -34,8 +34,8 @@ "graphql-tag": "2.12.6" }, "dependencies": { - "@launchql/types": "^2.1.8", - "graphile-settings": "^2.1.12", + "@launchql/types": "^2.1.9", + "graphile-settings": "^2.1.13", "graphql": "^15.5.2", "mock-req": "^0.2.0", "pg": "^8.16.0", diff --git a/packages/introspectron/CHANGELOG.md b/packages/introspectron/CHANGELOG.md index d44b96aec..897ff74b6 100644 --- a/packages/introspectron/CHANGELOG.md +++ b/packages/introspectron/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.2.8](https://github.com/launchql/launchql/compare/introspectron@2.2.7...introspectron@2.2.8) (2025-05-27) + +**Note:** Version bump only for package introspectron + + + + + ## [2.2.7](https://github.com/launchql/launchql/compare/introspectron@2.2.6...introspectron@2.2.7) (2025-05-25) **Note:** Version bump only for package introspectron diff --git a/packages/introspectron/package.json b/packages/introspectron/package.json index 4675fdcb6..445ef0d5b 100644 --- a/packages/introspectron/package.json +++ b/packages/introspectron/package.json @@ -1,6 +1,6 @@ { "name": "introspectron", - "version": "2.2.7", + "version": "2.2.8", "description": "introspect your Postgres database and generate an SDK", "author": "Dan Lynch ", "main": "index.js", @@ -30,8 +30,8 @@ "test:watch": "jest --watch" }, "devDependencies": { - "graphile-test": "^2.1.15", - "pgsql-test": "^2.1.17" + "graphile-test": "^2.1.16", + "pgsql-test": "^2.1.18" }, "dependencies": { "graphql-tag": "2.12.6" diff --git a/packages/launchql-gen/CHANGELOG.md b/packages/launchql-gen/CHANGELOG.md index 0c462b47a..ce47b2808 100644 --- a/packages/launchql-gen/CHANGELOG.md +++ b/packages/launchql-gen/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.5.10](https://github.com/launchql/launchql/compare/@launchql/codegen@2.5.9...@launchql/codegen@2.5.10) (2025-05-27) + +**Note:** Version bump only for package @launchql/codegen + + + + + ## [2.5.9](https://github.com/launchql/launchql/compare/@launchql/codegen@2.5.8...@launchql/codegen@2.5.9) (2025-05-25) **Note:** Version bump only for package @launchql/codegen diff --git a/packages/launchql-gen/package.json b/packages/launchql-gen/package.json index e8c17988e..968f56716 100644 --- a/packages/launchql-gen/package.json +++ b/packages/launchql-gen/package.json @@ -1,6 +1,6 @@ { "name": "@launchql/codegen", - "version": "2.5.9", + "version": "2.5.10", "description": "Generate queries and mutations for use with Graphile", "author": "Dan Lynch ", "main": "index.js", @@ -31,8 +31,8 @@ }, "devDependencies": { "@types/pluralize": "0.0.33", - "graphile-test": "^2.1.15", - "introspectron": "^2.2.7" + "graphile-test": "^2.1.16", + "introspectron": "^2.2.8" }, "dependencies": { "gql-ast": "^2.1.4", diff --git a/packages/pg-codegen/CHANGELOG.md b/packages/pg-codegen/CHANGELOG.md index d48366993..ff7fd3e63 100644 --- a/packages/pg-codegen/CHANGELOG.md +++ b/packages/pg-codegen/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.2.5](https://github.com/launchql/launchql/compare/pg-codegen@2.2.4...pg-codegen@2.2.5) (2025-05-27) + +**Note:** Version bump only for package pg-codegen + + + + + ## [2.2.4](https://github.com/launchql/launchql/compare/pg-codegen@2.2.3...pg-codegen@2.2.4) (2025-05-25) **Note:** Version bump only for package pg-codegen diff --git a/packages/pg-codegen/package.json b/packages/pg-codegen/package.json index 9c45e80cf..ad4fc34be 100644 --- a/packages/pg-codegen/package.json +++ b/packages/pg-codegen/package.json @@ -1,6 +1,6 @@ { "name": "pg-codegen", - "version": "2.2.4", + "version": "2.2.5", "author": "Dan Lynch ", "description": "PostgreSQL Codegen", "main": "index.js", @@ -41,10 +41,10 @@ "dependencies": { "@babel/generator": "^7.26.3", "@babel/types": "^7.26.3", - "@launchql/server-utils": "^2.1.10", - "@launchql/types": "^2.1.8", + "@launchql/server-utils": "^2.1.11", + "@launchql/types": "^2.1.9", "pg": "^8.16.0", - "pgsql-test": "^2.1.17" + "pgsql-test": "^2.1.18" }, "devDependencies": { "@types/pg": "^8.15.2" diff --git a/packages/pgsql-test/CHANGELOG.md b/packages/pgsql-test/CHANGELOG.md index cca003aa1..e8f6d68c8 100644 --- a/packages/pgsql-test/CHANGELOG.md +++ b/packages/pgsql-test/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.1.18](https://github.com/launchql/launchql/compare/pgsql-test@2.1.17...pgsql-test@2.1.18) (2025-05-27) + +**Note:** Version bump only for package pgsql-test + + + + + ## [2.1.17](https://github.com/launchql/launchql/compare/pgsql-test@2.1.16...pgsql-test@2.1.17) (2025-05-25) **Note:** Version bump only for package pgsql-test diff --git a/packages/pgsql-test/package.json b/packages/pgsql-test/package.json index 445704e31..a2cb0c4a9 100644 --- a/packages/pgsql-test/package.json +++ b/packages/pgsql-test/package.json @@ -1,6 +1,6 @@ { "name": "pgsql-test", - "version": "2.1.17", + "version": "2.1.18", "author": "Dan Lynch ", "description": "pgsql-test offers isolated, role-aware, and rollback-friendly PostgreSQL environments for integration tests — giving developers realistic test coverage without external state pollution", "main": "index.js", @@ -60,9 +60,9 @@ "@types/pg-copy-streams": "^1.2.5" }, "dependencies": { - "@launchql/core": "^2.1.16", - "@launchql/server-utils": "^2.1.10", - "@launchql/types": "^2.1.8", + "@launchql/core": "^2.1.17", + "@launchql/server-utils": "^2.1.11", + "@launchql/types": "^2.1.9", "chalk": "^4.1.0", "deepmerge": "^4.3.1", "pg": "^8.16.0", diff --git a/packages/react/CHANGELOG.md b/packages/react/CHANGELOG.md index 93668913a..c93e96f84 100644 --- a/packages/react/CHANGELOG.md +++ b/packages/react/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.2.8](https://github.com/launchql/launchql/compare/@launchql/react@2.2.7...@launchql/react@2.2.8) (2025-05-27) + +**Note:** Version bump only for package @launchql/react + + + + + ## [2.2.7](https://github.com/launchql/launchql/compare/@launchql/react@2.2.6...@launchql/react@2.2.7) (2025-05-25) **Note:** Version bump only for package @launchql/react diff --git a/packages/react/package.json b/packages/react/package.json index b8e0faf41..c6c4e9bd2 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,6 +1,6 @@ { "name": "@launchql/react", - "version": "2.2.7", + "version": "2.2.8", "author": "Dan Lynch ", "description": "LaunchQL React", "main": "index.js", @@ -30,7 +30,7 @@ "dependencies": { "@launchql/query": "^2.1.4", "graphql-request": "^7.1.2", - "introspectron": "^2.2.7", + "introspectron": "^2.2.8", "react": "^19.1.0", "react-dom": "^19.1.0", "react-query": "^3.39.3" diff --git a/packages/s3-streamer/CHANGELOG.md b/packages/s3-streamer/CHANGELOG.md index de231d802..b6f0aea99 100644 --- a/packages/s3-streamer/CHANGELOG.md +++ b/packages/s3-streamer/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.1.9](https://github.com/launchql/launchql/compare/@launchql/s3-streamer@2.1.8...@launchql/s3-streamer@2.1.9) (2025-05-27) + +**Note:** Version bump only for package @launchql/s3-streamer + + + + + ## [2.1.8](https://github.com/launchql/launchql/compare/@launchql/s3-streamer@2.1.7...@launchql/s3-streamer@2.1.8) (2025-05-25) **Note:** Version bump only for package @launchql/s3-streamer diff --git a/packages/s3-streamer/package.json b/packages/s3-streamer/package.json index 2c49864c7..573ed16aa 100644 --- a/packages/s3-streamer/package.json +++ b/packages/s3-streamer/package.json @@ -1,6 +1,6 @@ { "name": "@launchql/s3-streamer", - "version": "2.1.8", + "version": "2.1.9", "author": "Dan Lynch ", "description": "stream files to s3", "main": "index.js", @@ -36,7 +36,7 @@ }, "dependencies": { "@launchql/content-type-stream": "^2.1.4", - "@launchql/types": "^2.1.8", + "@launchql/types": "^2.1.9", "aws-sdk": "^2.1692.0" }, "keywords": [ diff --git a/packages/server-utils/CHANGELOG.md b/packages/server-utils/CHANGELOG.md index 6832b4275..c35eab0a5 100644 --- a/packages/server-utils/CHANGELOG.md +++ b/packages/server-utils/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.1.11](https://github.com/launchql/launchql/compare/@launchql/server-utils@2.1.10...@launchql/server-utils@2.1.11) (2025-05-27) + +**Note:** Version bump only for package @launchql/server-utils + + + + + ## [2.1.10](https://github.com/launchql/launchql/compare/@launchql/server-utils@2.1.9...@launchql/server-utils@2.1.10) (2025-05-25) **Note:** Version bump only for package @launchql/server-utils diff --git a/packages/server-utils/package.json b/packages/server-utils/package.json index cef801c71..e50473589 100644 --- a/packages/server-utils/package.json +++ b/packages/server-utils/package.json @@ -1,6 +1,6 @@ { "name": "@launchql/server-utils", - "version": "2.1.10", + "version": "2.1.11", "author": "Dan Lynch ", "description": "LaunchQL server utils", "main": "index.js", @@ -30,7 +30,7 @@ "test:watch": "jest --watch" }, "dependencies": { - "@launchql/types": "^2.1.8", + "@launchql/types": "^2.1.9", "chalk": "^4.1.0", "cors": "^2.8.5", "express": "^5.1.0", diff --git a/packages/server/CHANGELOG.md b/packages/server/CHANGELOG.md index 6b3340004..57cd5ec84 100644 --- a/packages/server/CHANGELOG.md +++ b/packages/server/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.1.16](https://github.com/launchql/launchql/compare/@launchql/server@2.1.15...@launchql/server@2.1.16) (2025-05-27) + +**Note:** Version bump only for package @launchql/server + + + + + ## [2.1.15](https://github.com/launchql/launchql/compare/@launchql/server@2.1.14...@launchql/server@2.1.15) (2025-05-25) **Note:** Version bump only for package @launchql/server diff --git a/packages/server/package.json b/packages/server/package.json index b364a19c3..9de153caf 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -1,6 +1,6 @@ { "name": "@launchql/server", - "version": "2.1.15", + "version": "2.1.16", "author": "Dan Lynch ", "description": "LaunchQL Server", "main": "index.js", @@ -40,8 +40,8 @@ ], "dependencies": { "@graphile-contrib/pg-many-to-many": "^1.0.2", - "@launchql/server-utils": "^2.1.10", - "@launchql/types": "^2.1.8", + "@launchql/server-utils": "^2.1.11", + "@launchql/types": "^2.1.9", "@launchql/upload-names": "^2.1.3", "@launchql/url-domains": "^2.1.3", "@pyramation/postgis": "^0.1.1", @@ -53,7 +53,7 @@ "graphile-meta-schema": "^0.2.5", "graphile-query": "^2.1.6", "graphile-search-plugin": "^0.1.2", - "graphile-settings": "^2.1.12", + "graphile-settings": "^2.1.13", "graphile-simple-inflector": "^0.1.1", "graphql-tag": "2.12.6", "graphql-upload": "^15.0.2", diff --git a/packages/server/src/middleware/api.ts b/packages/server/src/middleware/api.ts index c315a472c..2b9af7c0c 100644 --- a/packages/server/src/middleware/api.ts +++ b/packages/server/src/middleware/api.ts @@ -9,6 +9,47 @@ import { LaunchQLOptions } from '@launchql/types'; import { Response, Request, NextFunction } from 'express'; import { Pool } from 'pg'; +/** + * Transforms the old service structure to the new api structure + */ +import { Service, ApiStructure, SchemaNode, Domain, Site } from '../types'; + +const transformServiceToApi = (svc: Service): ApiStructure => { + const api = svc.data.api; + const schemaNames = api.schemaNamesFromExt?.nodes?.map((n: SchemaNode) => n.schemaName) || []; + const additionalSchemas = api.schemaNames?.nodes?.map((n: SchemaNode) => n.schemaName) || []; + + let domains: string[] = []; + if (api.database?.sites?.nodes) { + domains = api.database.sites.nodes.reduce((acc: string[], site: Site) => { + if (site.domains?.nodes && site.domains.nodes.length) { + const siteUrls = site.domains.nodes.map((domain: Domain) => { + const hostname = domain.subdomain ? `${domain.subdomain}.${domain.domain}` : domain.domain; + const protocol = domain.domain === 'localhost' ? 'http://' : 'https://'; + return protocol + hostname; + }); + return [...acc, ...siteUrls]; + } + return acc; + }, []); + } + + return { + dbname: api.dbname, + anonRole: api.anonRole, + roleName: api.roleName, + schema: [...schemaNames, ...additionalSchemas], + apiModules: api.apiModules?.nodes?.map(node => ({ + name: node.name, + data: node.data + })) || [], + rlsModule: api.rlsModule, + domains, + databaseId: api.databaseId, + isPublic: api.isPublic + }; +}; + const getPortFromRequest = (req: Request): string | null => { const host = req.headers.host; if (!host) return null; @@ -34,14 +75,15 @@ export const createApiMiddleware = (opts: LaunchQLOptions) => { res.status(404).send(errorPage404Message('API service not found for the given domain/subdomain.')); return; } - req.apiInfo = svc; - req.databaseId = svc.data.api.databaseId; + const api = transformServiceToApi(svc); + req.api = api; + req.databaseId = api.databaseId; next(); } catch (e: any) { if (e.code === 'NO_VALID_SCHEMAS') { res.status(404).send(errorPage404Message(e.message)); } else if (e.message.match(/does not exist/)) { - res.status(404).send(errorPage404Message('The resource you’re looking for does not exist.')); + res.status(404).send(errorPage404Message('The resource you\'re looking for does not exist.')); } else { console.error(e); res.status(500).send(errorPage50x); @@ -76,7 +118,7 @@ const getHardCodedSchemata = ({ .map((schemaName) => ({ schemaName })) }, schemaNames: { nodes: [] as Array<{ schemaName: string }> }, - apiModules: { nodes: [] as Array } + apiModules: [] as Array } } }; @@ -106,7 +148,7 @@ const getMetaSchema = ({ nodes: schemata.map((schemaName: string) => ({ schemaName })) }, schemaNames: { nodes: [] as Array<{ schemaName: string }> }, - apiModules: { nodes: [] as Array } + apiModules: [] as Array } } }; @@ -209,7 +251,7 @@ const validateSchemata = async (pool: Pool, schemata: string[]): Promise row.schema_name); + return result.rows.map((row: { schema_name: string }) => row.schema_name); }; export const getApiConfig = async (opts: LaunchQLOptions, req: Request): Promise => { diff --git a/packages/server/src/middleware/auth.ts b/packages/server/src/middleware/auth.ts index ed33d5a09..bb3b2812b 100644 --- a/packages/server/src/middleware/auth.ts +++ b/packages/server/src/middleware/auth.ts @@ -6,7 +6,7 @@ import { LaunchQLOptions } from '@launchql/types'; export const createAuthenticateMiddleware = (opts: LaunchQLOptions): RequestHandler => { return async (req: Request, res: Response, next: NextFunction): Promise => { - const api = req.apiInfo?.data?.api; + const api = req.api; if (!api) { res.status(500).send('Missing API info'); return; diff --git a/packages/server/src/middleware/cors.ts b/packages/server/src/middleware/cors.ts index 428d3fcc4..0fce6126d 100644 --- a/packages/server/src/middleware/cors.ts +++ b/packages/server/src/middleware/cors.ts @@ -1,71 +1,14 @@ import corsPlugin from 'cors'; import { parseUrl } from '@launchql/url-domains'; import { Request, Response, NextFunction } from 'express'; +import { CorsModuleData } from '../types'; -interface Domain { - subdomain?: string; - domain: string; -} - -interface SiteDomainNode { - nodes: Domain[]; -} - -interface Site { - domains: SiteDomainNode; -} - -interface Sites { - nodes?: Site[]; -} - -interface ApiModule { - name: string; - data: { - urls: string[]; - }; -} - -interface ApiInfo { - data: { - api: { - apiModules: { - nodes: ApiModule[]; - }; - database?: { - sites: Sites; - }; - }; - }; -} - -const getUrlsFromDomains = (domains: Domain[]): string[] => { - return domains.reduce((m, { subdomain, domain }) => { - const hostname = subdomain ? `${subdomain}.${domain}` : domain; - const protocol = domain === 'localhost' ? 'http://' : 'https://'; - return [...m, protocol + hostname]; - }, []); -}; - -const getSiteUrls = (sites: Sites): string[] => { - let siteUrls: string[] = []; - if (sites.nodes) { - siteUrls = sites.nodes.reduce((m, site) => { - if (site.domains.nodes && site.domains.nodes.length) { - return [...m, ...getUrlsFromDomains(site.domains.nodes)]; - } - return m; - }, []); - } - return siteUrls; -}; - -export const cors = async (req: Request & { apiInfo: ApiInfo }, res: Response, next: NextFunction) => { - const api = req.apiInfo.data.api; - const corsModules = api.apiModules.nodes.filter((mod) => mod.name === 'cors'); +export const cors = async (req: Request, res: Response, next: NextFunction) => { + const api = req.api; + const corsModules = api.apiModules.filter((mod) => mod.name === 'cors') as { name: 'cors'; data: CorsModuleData }[]; let corsOptions = { origin: false as boolean | string | RegExp | (string | RegExp)[] }; // default: disabled - if (!api.database?.sites) { + if (!api.domains || api.domains.length === 0) { return corsPlugin({ ...corsOptions, credentials: true, @@ -73,8 +16,7 @@ export const cors = async (req: Request & { apiInfo: ApiInfo }, res: Response, n })(req, res, next); } - const sites = api.database.sites; - const siteUrls = getSiteUrls(sites); + const siteUrls = api.domains; const listOfDomains = corsModules.reduce((m, mod) => { return [...mod.data.urls, ...m]; diff --git a/packages/server/src/middleware/gql.ts b/packages/server/src/middleware/gql.ts index 651778c18..f1bc5a452 100644 --- a/packages/server/src/middleware/gql.ts +++ b/packages/server/src/middleware/gql.ts @@ -125,4 +125,4 @@ export const ListOfAllDomainsOfDb = gql` } } } -`; \ No newline at end of file +`; diff --git a/packages/server/src/middleware/graphile.ts b/packages/server/src/middleware/graphile.ts index 816516cfe..dfd5aa4b1 100644 --- a/packages/server/src/middleware/graphile.ts +++ b/packages/server/src/middleware/graphile.ts @@ -2,7 +2,7 @@ import { Request, Response, NextFunction, RequestHandler } from 'express'; import { graphileCache, getRootPgPool } from '@launchql/server-utils'; import { postgraphile, PostGraphileOptions } from 'postgraphile'; import { getGraphileSettings as getSettings } from 'graphile-settings'; -import PublicKeySignature from '../plugins/PublicKeySignature'; +import PublicKeySignature, { PublicKeyChallengeConfig } from '../plugins/PublicKeySignature'; import { LaunchQLOptions } from '@launchql/types'; export const graphile = (lOpts: LaunchQLOptions): RequestHandler => { @@ -10,15 +10,9 @@ export const graphile = (lOpts: LaunchQLOptions): RequestHandler => { // @ts-ignore return async (req: Request, res: Response, next: NextFunction) => { try { - const api = req.apiInfo.data.api; + const api = req.api; const key = req.svc_key; - const { dbname } = api; - const { anonRole, roleName } = api; - - const { schemaNamesFromExt, schemaNames } = api; - const schemas = [] - .concat(schemaNamesFromExt.nodes.map(({ schemaName }: any) => schemaName)) - .concat(schemaNames.nodes.map(({ schemaName }: any) => schemaName)); + const { dbname, anonRole, roleName, schema } = api; if (graphileCache.has(key)) { const { handler } = graphileCache.get(key)! @@ -29,16 +23,16 @@ export const graphile = (lOpts: LaunchQLOptions): RequestHandler => { ...lOpts, graphile: { ...lOpts.graphile, - schema: schemas + schema: schema } }); - const pubkey_challenge = api.apiModules.nodes.find( + const pubkey_challenge = api.apiModules.find( (mod: any) => mod.name === 'pubkey_challenge' ); if (pubkey_challenge && pubkey_challenge.data) { - options.appendPlugins.push(PublicKeySignature(pubkey_challenge.data)); + options.appendPlugins.push(PublicKeySignature(pubkey_challenge.data as PublicKeyChallengeConfig)); } options.appendPlugins = options.appendPlugins ?? []; @@ -87,7 +81,7 @@ export const graphile = (lOpts: LaunchQLOptions): RequestHandler => { ...lOpts.pg, database: dbname }); - const handler = postgraphile(pgPool, schemas, opts); + const handler = postgraphile(pgPool, schema, opts); graphileCache.set(key, { pgPool, diff --git a/packages/server/src/plugins/PublicKeySignature.ts b/packages/server/src/plugins/PublicKeySignature.ts index dba67af0a..737c8788e 100644 --- a/packages/server/src/plugins/PublicKeySignature.ts +++ b/packages/server/src/plugins/PublicKeySignature.ts @@ -12,7 +12,7 @@ interface Context { env: Record; } -interface PublicKeyChallengeConfig { +export interface PublicKeyChallengeConfig { schema: string; crypto_network: string; // crypto_network: keyof typeof Networks; diff --git a/packages/server/src/types.ts b/packages/server/src/types.ts new file mode 100644 index 000000000..5ebb8cec8 --- /dev/null +++ b/packages/server/src/types.ts @@ -0,0 +1,128 @@ +import { PostGraphileOptions } from 'postgraphile'; +import type { Plugin } from 'graphile-build'; + +export interface CorsModuleData { + urls: string[]; +} + +export interface PublicKeyChallengeData { + schema: string; + crypto_network: string; + sign_up_with_key: string; + sign_in_request_challenge: string; + sign_in_record_failure: string; + sign_in_with_challenge: string; +} + +export interface GenericModuleData { + [key: string]: any; +} + +export type ApiModule = + | { name: 'cors'; data: CorsModuleData } + | { name: 'pubkey_challenge'; data: PublicKeyChallengeData } + | { name: string; data?: GenericModuleData }; + +export interface RlsModule { + authenticate?: string; + authenticateStrict?: string; + privateSchema: { + schemaName: string; + }; +} + +declare module 'express-serve-static-core' { + interface Request { + api: { + dbname: string; + anonRole: string; + roleName: string; + schema: string[]; // Pre-processed schema names + apiModules: ApiModule[]; + rlsModule?: { + authenticate?: string; + authenticateStrict?: string; + privateSchema: { + schemaName: string; + }; + }; + domains?: string[]; // Simplified from database.sites.nodes + databaseId?: string; + isPublic?: boolean; + }; + svc_key: string; + clientIp?: string; + databaseId?: string; + token?: { + id: string; + user_id: string; + [key: string]: any; + }; + } +} + +export interface SchemaNode { + schemaName: string; +} + +export interface SchemaNodes { + nodes: SchemaNode[]; +} + +export interface Domain { + subdomain?: string; + domain: string; +} + +export interface DomainNodes { + nodes: Domain[]; +} + +export interface Site { + domains: DomainNodes; +} + +export interface SiteNodes { + nodes: Site[]; +} +export interface ApiModuleNodes { + nodes: ApiModule[]; +} + +export interface Database { + sites: SiteNodes; +} + + +export interface OldApiStructure { + dbname: string; + anonRole: string; + roleName: string; + schemaNames: SchemaNodes; + schemaNamesFromExt: SchemaNodes; + apiModules: ApiModuleNodes; + rlsModule?: RlsModule; + database?: Database; + databaseId?: string; + isPublic?: boolean; +} + +export interface ServiceData { + api: OldApiStructure; +} + +export interface Service { + data: ServiceData; +} + +export interface ApiStructure { + dbname: string; + anonRole: string; + roleName: string; + schema: string[]; + apiModules: ApiModule[]; + rlsModule?: RlsModule; + domains?: string[]; + databaseId?: string; + isPublic?: boolean; +} diff --git a/packages/types/CHANGELOG.md b/packages/types/CHANGELOG.md index 67bbadf78..8e5c5184f 100644 --- a/packages/types/CHANGELOG.md +++ b/packages/types/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.1.9](https://github.com/launchql/launchql/compare/@launchql/types@2.1.8...@launchql/types@2.1.9) (2025-05-27) + +**Note:** Version bump only for package @launchql/types + + + + + ## [2.1.8](https://github.com/launchql/launchql/compare/@launchql/types@2.1.7...@launchql/types@2.1.8) (2025-05-25) **Note:** Version bump only for package @launchql/types diff --git a/packages/types/package.json b/packages/types/package.json index be8123bff..784fac21a 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -1,6 +1,6 @@ { "name": "@launchql/types", - "version": "2.1.8", + "version": "2.1.9", "author": "Dan Lynch ", "description": "LaunchQL types", "main": "index.js", diff --git a/packages/types/src/launchql.ts b/packages/types/src/launchql.ts index 1fae477fa..d8d076419 100644 --- a/packages/types/src/launchql.ts +++ b/packages/types/src/launchql.ts @@ -1,46 +1,6 @@ import { PostGraphileOptions } from 'postgraphile'; import type { Plugin } from 'graphile-build'; import { execSync } from 'child_process'; -declare module 'express-serve-static-core' { - interface Request { - apiInfo: { - data: { - api: { - dbname: string; - anonRole: string; - roleName: string; - schemaNames: { - nodes: { schemaName: string }[]; - }; - schemaNamesFromExt: { - nodes: { schemaName: string }[]; - }; - apiModules: { - nodes: { - name: string; - data?: any; - }[]; - }; - rlsModule?: { - authenticate?: string; - authenticateStrict?: string; - privateSchema: { - schemaName: string; - }; - }; - }; - }; - }; - svc_key: string; - clientIp?: string; - databaseId?: string; - token?: { - id: string; - user_id: string; - [key: string]: any; - }; - } -} export interface PgConfig { host: string;