mcpmake 0.1.1 → 0.2.0
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/dist/commands/bundle.d.ts +1 -0
- package/dist/commands/bundle.d.ts.map +1 -0
- package/dist/commands/bundle.js +5 -4
- package/dist/commands/bundle.js.map +1 -0
- package/dist/commands/ci.d.ts +1 -0
- package/dist/commands/ci.d.ts.map +1 -0
- package/dist/commands/ci.js +3 -2
- package/dist/commands/ci.js.map +1 -0
- package/dist/commands/deploy.d.ts +1 -0
- package/dist/commands/deploy.d.ts.map +1 -0
- package/dist/commands/deploy.js +4 -3
- package/dist/commands/deploy.js.map +1 -0
- package/dist/commands/diff.d.ts +1 -0
- package/dist/commands/diff.d.ts.map +1 -0
- package/dist/commands/diff.js +5 -4
- package/dist/commands/diff.js.map +1 -0
- package/dist/commands/from/describe.d.ts +1 -0
- package/dist/commands/from/describe.d.ts.map +1 -0
- package/dist/commands/from/describe.js +11 -10
- package/dist/commands/from/describe.js.map +1 -0
- package/dist/commands/from/har.d.ts +1 -0
- package/dist/commands/from/har.d.ts.map +1 -0
- package/dist/commands/from/har.js +14 -13
- package/dist/commands/from/har.js.map +1 -0
- package/dist/commands/from/openapi.d.ts +1 -0
- package/dist/commands/from/openapi.d.ts.map +1 -0
- package/dist/commands/from/openapi.js +17 -16
- package/dist/commands/from/openapi.js.map +1 -0
- package/dist/commands/from/postman.d.ts +1 -0
- package/dist/commands/from/postman.d.ts.map +1 -0
- package/dist/commands/from/postman.js +13 -12
- package/dist/commands/from/postman.js.map +1 -0
- package/dist/commands/from/stainless.d.ts +110 -0
- package/dist/commands/from/stainless.d.ts.map +1 -0
- package/dist/commands/from/stainless.js +272 -0
- package/dist/commands/from/stainless.js.map +1 -0
- package/dist/commands/from/target-support.d.ts +1 -0
- package/dist/commands/from/target-support.d.ts.map +1 -0
- package/dist/commands/from/target-support.js +2 -1
- package/dist/commands/from/target-support.js.map +1 -0
- package/dist/commands/from/url.d.ts +1 -0
- package/dist/commands/from/url.d.ts.map +1 -0
- package/dist/commands/from/url.js +14 -13
- package/dist/commands/from/url.js.map +1 -0
- package/dist/commands/from/website.d.ts +1 -0
- package/dist/commands/from/website.d.ts.map +1 -0
- package/dist/commands/from/website.js +17 -16
- package/dist/commands/from/website.js.map +1 -0
- package/dist/commands/lint.d.ts +1 -0
- package/dist/commands/lint.d.ts.map +1 -0
- package/dist/commands/lint.js +6 -5
- package/dist/commands/lint.js.map +1 -0
- package/dist/commands/merge.d.ts +1 -0
- package/dist/commands/merge.d.ts.map +1 -0
- package/dist/commands/merge.js +3 -2
- package/dist/commands/merge.js.map +1 -0
- package/dist/commands/publish.d.ts +1 -0
- package/dist/commands/publish.d.ts.map +1 -0
- package/dist/commands/publish.js +4 -3
- package/dist/commands/publish.js.map +1 -0
- package/dist/commands/rescan.d.ts +1 -0
- package/dist/commands/rescan.d.ts.map +1 -0
- package/dist/commands/rescan.js +12 -11
- package/dist/commands/rescan.js.map +1 -0
- package/dist/commands/update.d.ts +1 -0
- package/dist/commands/update.d.ts.map +1 -0
- package/dist/commands/update.js +10 -9
- package/dist/commands/update.js.map +1 -0
- package/dist/commands/verify.d.ts +1 -0
- package/dist/commands/verify.d.ts.map +1 -0
- package/dist/commands/verify.js +7 -6
- package/dist/commands/verify.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -2
- package/dist/index.js.map +1 -0
- package/dist/registry/official-registry.d.ts +1 -0
- package/dist/registry/official-registry.d.ts.map +1 -0
- package/dist/registry/official-registry.js +1 -0
- package/dist/registry/official-registry.js.map +1 -0
- package/package.json +20 -46
- package/README.md +0 -691
- package/dist/analyzer/auth-detector.d.ts +0 -12
- package/dist/analyzer/auth-detector.js +0 -142
- package/dist/analyzer/dom-parser.d.ts +0 -10
- package/dist/analyzer/dom-parser.js +0 -259
- package/dist/analyzer/goal-crawler.d.ts +0 -25
- package/dist/analyzer/goal-crawler.js +0 -177
- package/dist/analyzer/hybrid-detector.d.ts +0 -28
- package/dist/analyzer/hybrid-detector.js +0 -96
- package/dist/analyzer/index.d.ts +0 -12
- package/dist/analyzer/index.js +0 -8
- package/dist/analyzer/screenshot-capture.d.ts +0 -29
- package/dist/analyzer/screenshot-capture.js +0 -42
- package/dist/analyzer/selector-builder.d.ts +0 -19
- package/dist/analyzer/selector-builder.js +0 -199
- package/dist/analyzer/semantic-analyzer.d.ts +0 -13
- package/dist/analyzer/semantic-analyzer.js +0 -145
- package/dist/analyzer/site-crawler.d.ts +0 -38
- package/dist/analyzer/site-crawler.js +0 -235
- package/dist/cloud/billing/billing-engine.d.ts +0 -44
- package/dist/cloud/billing/billing-engine.js +0 -81
- package/dist/cloud/billing/credit-store.d.ts +0 -64
- package/dist/cloud/billing/credit-store.js +0 -168
- package/dist/cloud/billing/index.d.ts +0 -4
- package/dist/cloud/billing/index.js +0 -2
- package/dist/cloud/billing/usage-store.d.ts +0 -42
- package/dist/cloud/billing/usage-store.js +0 -85
- package/dist/cloud/billing/usage-tracker.d.ts +0 -38
- package/dist/cloud/billing/usage-tracker.js +0 -95
- package/dist/cloud/build-pipeline.d.ts +0 -39
- package/dist/cloud/build-pipeline.js +0 -310
- package/dist/cloud/build-queue.d.ts +0 -30
- package/dist/cloud/build-queue.js +0 -70
- package/dist/cloud/caddy-manager.d.ts +0 -18
- package/dist/cloud/caddy-manager.js +0 -97
- package/dist/cloud/container-backend.d.ts +0 -62
- package/dist/cloud/container-backend.js +0 -59
- package/dist/cloud/container-manager.d.ts +0 -64
- package/dist/cloud/container-manager.js +0 -301
- package/dist/cloud/crypto.d.ts +0 -27
- package/dist/cloud/crypto.js +0 -63
- package/dist/cloud/db/index.d.ts +0 -27
- package/dist/cloud/db/index.js +0 -53
- package/dist/cloud/db/migrations.d.ts +0 -12
- package/dist/cloud/db/migrations.js +0 -329
- package/dist/cloud/db/pg-store.d.ts +0 -45
- package/dist/cloud/db/pg-store.js +0 -336
- package/dist/cloud/failure-tracker.d.ts +0 -51
- package/dist/cloud/failure-tracker.js +0 -102
- package/dist/cloud/idle-monitor.d.ts +0 -30
- package/dist/cloud/idle-monitor.js +0 -70
- package/dist/cloud/mailer.d.ts +0 -21
- package/dist/cloud/mailer.js +0 -193
- package/dist/cloud/mcp-proxy.d.ts +0 -58
- package/dist/cloud/mcp-proxy.js +0 -203
- package/dist/cloud/metric-samples.d.ts +0 -43
- package/dist/cloud/metric-samples.js +0 -85
- package/dist/cloud/metrics.d.ts +0 -26
- package/dist/cloud/metrics.js +0 -59
- package/dist/cloud/multipart.d.ts +0 -26
- package/dist/cloud/multipart.js +0 -132
- package/dist/cloud/observability.d.ts +0 -27
- package/dist/cloud/observability.js +0 -98
- package/dist/cloud/rate-limiter.d.ts +0 -31
- package/dist/cloud/rate-limiter.js +0 -58
- package/dist/cloud/request-security.d.ts +0 -5
- package/dist/cloud/request-security.js +0 -74
- package/dist/cloud/resource-monitor.d.ts +0 -69
- package/dist/cloud/resource-monitor.js +0 -130
- package/dist/cloud/secret-store.d.ts +0 -38
- package/dist/cloud/secret-store.js +0 -103
- package/dist/cloud/security.d.ts +0 -26
- package/dist/cloud/security.js +0 -142
- package/dist/cloud/server.d.ts +0 -21
- package/dist/cloud/server.js +0 -1079
- package/dist/cloud/shared-state.d.ts +0 -72
- package/dist/cloud/shared-state.js +0 -159
- package/dist/cloud/ssrf.d.ts +0 -43
- package/dist/cloud/ssrf.js +0 -150
- package/dist/cloud/store.d.ts +0 -41
- package/dist/cloud/store.js +0 -75
- package/dist/cloud/stripe.d.ts +0 -78
- package/dist/cloud/stripe.js +0 -317
- package/dist/cloud/telemetry-store.d.ts +0 -53
- package/dist/cloud/telemetry-store.js +0 -108
- package/dist/cloud/web/auth.d.ts +0 -225
- package/dist/cloud/web/auth.js +0 -555
- package/dist/cloud/web/charts.d.ts +0 -70
- package/dist/cloud/web/charts.js +0 -178
- package/dist/cloud/web/csrf.d.ts +0 -14
- package/dist/cloud/web/csrf.js +0 -22
- package/dist/cloud/web/docs.d.ts +0 -40
- package/dist/cloud/web/docs.js +0 -174
- package/dist/cloud/web/router.d.ts +0 -25
- package/dist/cloud/web/router.js +0 -1921
- package/dist/cloud/web/static/alpine.min.js +0 -5
- package/dist/cloud/web/static/favicon.svg +0 -4
- package/dist/cloud/web/static/htmx-sse.js +0 -290
- package/dist/cloud/web/static/htmx.min.js +0 -1
- package/dist/cloud/web/static/style.css +0 -2683
- package/dist/cloud/web/static-server.d.ts +0 -13
- package/dist/cloud/web/static-server.js +0 -73
- package/dist/cloud/web/template-engine.d.ts +0 -27
- package/dist/cloud/web/template-engine.js +0 -146
- package/dist/cloud/web/templates/layouts/admin.hbs +0 -57
- package/dist/cloud/web/templates/layouts/auth.hbs +0 -138
- package/dist/cloud/web/templates/layouts/base.hbs +0 -16
- package/dist/cloud/web/templates/layouts/dashboard.hbs +0 -39
- package/dist/cloud/web/templates/layouts/landing.hbs +0 -82
- package/dist/cloud/web/templates/pages/admin/overview.hbs +0 -123
- package/dist/cloud/web/templates/pages/admin/servers.hbs +0 -129
- package/dist/cloud/web/templates/pages/admin/telemetry.hbs +0 -39
- package/dist/cloud/web/templates/pages/admin/user-edit.hbs +0 -91
- package/dist/cloud/web/templates/pages/admin/users.hbs +0 -179
- package/dist/cloud/web/templates/pages/auth/forgot-password.hbs +0 -25
- package/dist/cloud/web/templates/pages/auth/login.hbs +0 -33
- package/dist/cloud/web/templates/pages/auth/register.hbs +0 -32
- package/dist/cloud/web/templates/pages/auth/reset-password.hbs +0 -34
- package/dist/cloud/web/templates/pages/dashboard/billing.hbs +0 -140
- package/dist/cloud/web/templates/pages/dashboard/create.hbs +0 -173
- package/dist/cloud/web/templates/pages/dashboard/index.hbs +0 -8
- package/dist/cloud/web/templates/pages/dashboard/server-detail.hbs +0 -280
- package/dist/cloud/web/templates/pages/dashboard/server-logs.hbs +0 -35
- package/dist/cloud/web/templates/pages/dashboard/server-metrics.hbs +0 -63
- package/dist/cloud/web/templates/pages/dashboard/servers-partial.hbs +0 -21
- package/dist/cloud/web/templates/pages/dashboard/servers.hbs +0 -44
- package/dist/cloud/web/templates/pages/docs/show.hbs +0 -16
- package/dist/cloud/web/templates/pages/errors/404.hbs +0 -9
- package/dist/cloud/web/templates/pages/errors/500.hbs +0 -8
- package/dist/cloud/web/templates/pages/landing/index.hbs +0 -223
- package/dist/cloud/web/templates/pages/legal/privacy.hbs +0 -71
- package/dist/cloud/web/templates/pages/legal/terms.hbs +0 -73
- package/dist/cloud/web/templates/partials/admin-stats.hbs +0 -52
- package/dist/cloud/web/templates/partials/flash-message.hbs +0 -6
- package/dist/cloud/web/templates/partials/pricing-table.hbs +0 -103
- package/dist/cloud/web/templates/partials/server-card.hbs +0 -19
- package/dist/cloud/web/templates/partials/status-badge.hbs +0 -1
- package/dist/config/configurable-command.d.ts +0 -13
- package/dist/config/configurable-command.js +0 -70
- package/dist/config/mcpmake-config.d.ts +0 -68
- package/dist/config/mcpmake-config.js +0 -207
- package/dist/docs/cli.md +0 -400
- package/dist/docs/mcp-2026-07-28-migration.md +0 -78
- package/dist/docs/migrate-from-stainless.md +0 -94
- package/dist/docs/quickstart.md +0 -166
- package/dist/docs/show-hn.md +0 -26
- package/dist/docs/website-servers.md +0 -169
- package/dist/emitter/code-writer.d.ts +0 -8
- package/dist/emitter/code-writer.js +0 -25
- package/dist/emitter/index.d.ts +0 -32
- package/dist/emitter/index.js +0 -280
- package/dist/emitter/mcpb-bundler.d.ts +0 -31
- package/dist/emitter/mcpb-bundler.js +0 -172
- package/dist/emitter/project-scaffolder.d.ts +0 -4
- package/dist/emitter/project-scaffolder.js +0 -89
- package/dist/emitter/python-template-loader.d.ts +0 -4
- package/dist/emitter/python-template-loader.js +0 -30
- package/dist/emitter/python-templates/dockerfile.hbs +0 -14
- package/dist/emitter/python-templates/env.example.hbs +0 -6
- package/dist/emitter/python-templates/requirements.txt.hbs +0 -4
- package/dist/emitter/python-templates/server.py.hbs +0 -77
- package/dist/emitter/site-scaffolder.d.ts +0 -13
- package/dist/emitter/site-scaffolder.js +0 -70
- package/dist/emitter/site-template-loader.d.ts +0 -5
- package/dist/emitter/site-template-loader.js +0 -47
- package/dist/emitter/site-templates/browser-manager.ts.hbs +0 -233
- package/dist/emitter/site-templates/config.ts.hbs +0 -28
- package/dist/emitter/site-templates/dockerfile.hbs +0 -31
- package/dist/emitter/site-templates/env.example.hbs +0 -19
- package/dist/emitter/site-templates/package.json.hbs +0 -26
- package/dist/emitter/site-templates/server-main-http.ts.hbs +0 -108
- package/dist/emitter/site-templates/server-main.ts.hbs +0 -23
- package/dist/emitter/site-templates/tool-handler-action.ts.hbs +0 -86
- package/dist/emitter/site-templates/tool-handler-form.ts.hbs +0 -116
- package/dist/emitter/site-templates/tool-handler-lifecycle.ts.hbs +0 -146
- package/dist/emitter/site-templates/tool-index.ts.hbs +0 -11
- package/dist/emitter/template-loader.d.ts +0 -1
- package/dist/emitter/template-loader.js +0 -27
- package/dist/emitter/templates/auth-provider.ts.hbs +0 -57
- package/dist/emitter/templates/config.ts.hbs +0 -63
- package/dist/emitter/templates/discovery.ts.hbs +0 -301
- package/dist/emitter/templates/dockerfile.hbs +0 -34
- package/dist/emitter/templates/env.example.hbs +0 -28
- package/dist/emitter/templates/gitignore.hbs +0 -5
- package/dist/emitter/templates/http-executor.ts.hbs +0 -117
- package/dist/emitter/templates/oauth.ts.hbs +0 -188
- package/dist/emitter/templates/package.json.hbs +0 -25
- package/dist/emitter/templates/prompts.ts.hbs +0 -22
- package/dist/emitter/templates/readme.md.hbs +0 -123
- package/dist/emitter/templates/resources.ts.hbs +0 -63
- package/dist/emitter/templates/server-main-http.ts.hbs +0 -407
- package/dist/emitter/templates/server-main.ts.hbs +0 -40
- package/dist/emitter/templates/task-handlers.ts.hbs +0 -189
- package/dist/emitter/templates/task-manager.ts.hbs +0 -139
- package/dist/emitter/templates/task-sse.ts.hbs +0 -105
- package/dist/emitter/templates/tool-handler.ts.hbs +0 -124
- package/dist/emitter/templates/tool-index.ts.hbs +0 -11
- package/dist/emitter/templates/tool-test.ts.hbs +0 -57
- package/dist/emitter/templates/trace.ts.hbs +0 -79
- package/dist/emitter/templates/tsconfig.json.hbs +0 -16
- package/dist/emitter/templates/types.ts.hbs +0 -5
- package/dist/emitter/worker-template-loader.d.ts +0 -5
- package/dist/emitter/worker-template-loader.js +0 -33
- package/dist/emitter/worker-templates/config.ts.hbs +0 -54
- package/dist/emitter/worker-templates/dev-vars.example.hbs +0 -10
- package/dist/emitter/worker-templates/gitignore.hbs +0 -6
- package/dist/emitter/worker-templates/package.json.hbs +0 -24
- package/dist/emitter/worker-templates/readme.md.hbs +0 -53
- package/dist/emitter/worker-templates/server.test.ts.hbs +0 -20
- package/dist/emitter/worker-templates/tool-handler.ts.hbs +0 -85
- package/dist/emitter/worker-templates/tool-index.ts.hbs +0 -28
- package/dist/emitter/worker-templates/tsconfig.json.hbs +0 -17
- package/dist/emitter/worker-templates/worker.ts.hbs +0 -242
- package/dist/emitter/worker-templates/wrangler.toml.hbs +0 -19
- package/dist/generator/spec-generator.d.ts +0 -6
- package/dist/generator/spec-generator.js +0 -50
- package/dist/parser/har-filter.d.ts +0 -8
- package/dist/parser/har-filter.js +0 -71
- package/dist/parser/har-loader.d.ts +0 -2
- package/dist/parser/har-loader.js +0 -14
- package/dist/parser/har-normalizer.d.ts +0 -20
- package/dist/parser/har-normalizer.js +0 -78
- package/dist/parser/index.d.ts +0 -10
- package/dist/parser/index.js +0 -6
- package/dist/parser/openapi-loader.d.ts +0 -6
- package/dist/parser/openapi-loader.js +0 -308
- package/dist/parser/operation-extractor.d.ts +0 -13
- package/dist/parser/operation-extractor.js +0 -155
- package/dist/parser/overlay-loader.d.ts +0 -10
- package/dist/parser/overlay-loader.js +0 -184
- package/dist/parser/postman-loader.d.ts +0 -9
- package/dist/parser/postman-loader.js +0 -106
- package/dist/parser/schema-converter.d.ts +0 -12
- package/dist/parser/schema-converter.js +0 -117
- package/dist/plugins/adapter.d.ts +0 -40
- package/dist/plugins/adapter.js +0 -15
- package/dist/plugins/loader.d.ts +0 -25
- package/dist/plugins/loader.js +0 -58
- package/dist/pricing.d.ts +0 -55
- package/dist/pricing.js +0 -133
- package/dist/providers/index.d.ts +0 -15
- package/dist/providers/index.js +0 -56
- package/dist/recorder/browser-recorder.d.ts +0 -22
- package/dist/recorder/browser-recorder.js +0 -205
- package/dist/rescan/diff-engine.d.ts +0 -5
- package/dist/rescan/diff-engine.js +0 -312
- package/dist/rescan/index.d.ts +0 -3
- package/dist/rescan/index.js +0 -2
- package/dist/rescan/rescan-runner.d.ts +0 -42
- package/dist/rescan/rescan-runner.js +0 -69
- package/dist/rescan/rescan-scheduler.d.ts +0 -41
- package/dist/rescan/rescan-scheduler.js +0 -179
- package/dist/site-transformer/browser-tools.d.ts +0 -10
- package/dist/site-transformer/browser-tools.js +0 -59
- package/dist/site-transformer/index.d.ts +0 -2
- package/dist/site-transformer/index.js +0 -2
- package/dist/site-transformer/selector-healer.d.ts +0 -8
- package/dist/site-transformer/selector-healer.js +0 -106
- package/dist/site-transformer/tool-generator.d.ts +0 -13
- package/dist/site-transformer/tool-generator.js +0 -245
- package/dist/transformer/auth-detector.d.ts +0 -13
- package/dist/transformer/auth-detector.js +0 -90
- package/dist/transformer/catalog-builder.d.ts +0 -18
- package/dist/transformer/catalog-builder.js +0 -56
- package/dist/transformer/client-compat.d.ts +0 -6
- package/dist/transformer/client-compat.js +0 -44
- package/dist/transformer/har-clusterer.d.ts +0 -9
- package/dist/transformer/har-clusterer.js +0 -27
- package/dist/transformer/har-dedup.d.ts +0 -10
- package/dist/transformer/har-dedup.js +0 -81
- package/dist/transformer/har-schema-inferrer.d.ts +0 -15
- package/dist/transformer/har-schema-inferrer.js +0 -90
- package/dist/transformer/har-to-operations.d.ts +0 -13
- package/dist/transformer/har-to-operations.js +0 -192
- package/dist/transformer/index.d.ts +0 -8
- package/dist/transformer/index.js +0 -6
- package/dist/transformer/llm-namer.d.ts +0 -6
- package/dist/transformer/llm-namer.js +0 -59
- package/dist/transformer/naming.d.ts +0 -4
- package/dist/transformer/naming.js +0 -30
- package/dist/transformer/operation-filter.d.ts +0 -13
- package/dist/transformer/operation-filter.js +0 -52
- package/dist/transformer/resource-builder.d.ts +0 -12
- package/dist/transformer/resource-builder.js +0 -80
- package/dist/transformer/schema-merger.d.ts +0 -14
- package/dist/transformer/schema-merger.js +0 -65
- package/dist/transformer/tool-builder.d.ts +0 -3
- package/dist/transformer/tool-builder.js +0 -114
- package/dist/types/index.d.ts +0 -131
- package/dist/types/index.js +0 -1
- package/dist/types/site.d.ts +0 -284
- package/dist/types/site.js +0 -8
- package/dist/utils/fail.d.ts +0 -48
- package/dist/utils/fail.js +0 -204
- package/dist/utils/fs.d.ts +0 -5
- package/dist/utils/fs.js +0 -28
- package/dist/utils/interactive.d.ts +0 -6
- package/dist/utils/interactive.js +0 -30
- package/dist/utils/logger.d.ts +0 -1
- package/dist/utils/logger.js +0 -2
- package/dist/utils/sanitize.d.ts +0 -28
- package/dist/utils/sanitize.js +0 -44
- package/dist/utils/watcher.d.ts +0 -11
- package/dist/utils/watcher.js +0 -36
package/dist/cloud/db/index.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Database connection manager.
|
|
3
|
-
*
|
|
4
|
-
* Provides a thin abstraction over PostgreSQL via the `pg` module.
|
|
5
|
-
* Uses dynamic import so the rest of the app doesn't fail when pg
|
|
6
|
-
* isn't installed (i.e. in-memory-only mode).
|
|
7
|
-
*/
|
|
8
|
-
export interface QueryResult<T> {
|
|
9
|
-
rows: T[];
|
|
10
|
-
}
|
|
11
|
-
export interface Database {
|
|
12
|
-
query<T>(sql: string, params?: unknown[]): Promise<QueryResult<T>>;
|
|
13
|
-
}
|
|
14
|
-
export declare class PgDatabase implements Database {
|
|
15
|
-
private pool;
|
|
16
|
-
constructor(pool: any);
|
|
17
|
-
query<T>(sql: string, params?: unknown[]): Promise<QueryResult<T>>;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Create a Database backed by PostgreSQL and store it as the singleton.
|
|
21
|
-
* Verifies connectivity before returning.
|
|
22
|
-
*/
|
|
23
|
-
export declare function createDatabase(url: string): Promise<Database>;
|
|
24
|
-
/**
|
|
25
|
-
* Return the current database singleton, or null if not initialised.
|
|
26
|
-
*/
|
|
27
|
-
export declare function getDatabase(): Database | null;
|
package/dist/cloud/db/index.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Database connection manager.
|
|
3
|
-
*
|
|
4
|
-
* Provides a thin abstraction over PostgreSQL via the `pg` module.
|
|
5
|
-
* Uses dynamic import so the rest of the app doesn't fail when pg
|
|
6
|
-
* isn't installed (i.e. in-memory-only mode).
|
|
7
|
-
*/
|
|
8
|
-
// ---------------------------------------------------------------------------
|
|
9
|
-
// PostgreSQL implementation
|
|
10
|
-
// ---------------------------------------------------------------------------
|
|
11
|
-
export class PgDatabase {
|
|
12
|
-
pool; // pg.Pool — typed as any to avoid hard dep
|
|
13
|
-
constructor(pool) {
|
|
14
|
-
this.pool = pool;
|
|
15
|
-
}
|
|
16
|
-
async query(sql, params) {
|
|
17
|
-
const result = await this.pool.query(sql, params);
|
|
18
|
-
return { rows: result.rows };
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
// ---------------------------------------------------------------------------
|
|
22
|
-
// Singleton
|
|
23
|
-
// ---------------------------------------------------------------------------
|
|
24
|
-
let instance = null;
|
|
25
|
-
/**
|
|
26
|
-
* Create a Database backed by PostgreSQL and store it as the singleton.
|
|
27
|
-
* Verifies connectivity before returning.
|
|
28
|
-
*/
|
|
29
|
-
export async function createDatabase(url) {
|
|
30
|
-
// Dynamic import — pg is a CommonJS module, use createRequire for reliable loading
|
|
31
|
-
let Pool;
|
|
32
|
-
try {
|
|
33
|
-
const { createRequire } = await import('node:module');
|
|
34
|
-
const require = createRequire(import.meta.url);
|
|
35
|
-
const pg = require('pg');
|
|
36
|
-
Pool = pg.Pool;
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
throw new Error('pg package not installed. Install it with: npm install pg');
|
|
40
|
-
}
|
|
41
|
-
const pool = new Pool({ connectionString: url, max: 10 });
|
|
42
|
-
// Verify the connection is good
|
|
43
|
-
await pool.query('SELECT 1');
|
|
44
|
-
const db = new PgDatabase(pool);
|
|
45
|
-
instance = db;
|
|
46
|
-
return db;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Return the current database singleton, or null if not initialised.
|
|
50
|
-
*/
|
|
51
|
-
export function getDatabase() {
|
|
52
|
-
return instance;
|
|
53
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Simple sequential migration runner.
|
|
3
|
-
*
|
|
4
|
-
* Stores the current schema version in a `_migrations` table.
|
|
5
|
-
* Each migration is a plain SQL string executed in order.
|
|
6
|
-
*/
|
|
7
|
-
import type { Database } from './index.js';
|
|
8
|
-
/**
|
|
9
|
-
* Run all pending migrations in order.
|
|
10
|
-
* Creates the `_migrations` meta-table on first run.
|
|
11
|
-
*/
|
|
12
|
-
export declare function runMigrations(db: Database): Promise<void>;
|
|
@@ -1,329 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Simple sequential migration runner.
|
|
3
|
-
*
|
|
4
|
-
* Stores the current schema version in a `_migrations` table.
|
|
5
|
-
* Each migration is a plain SQL string executed in order.
|
|
6
|
-
*/
|
|
7
|
-
const migrations = [
|
|
8
|
-
{
|
|
9
|
-
version: 1,
|
|
10
|
-
description: 'Initial schema',
|
|
11
|
-
sql: `
|
|
12
|
-
-- Users -----------------------------------------------------------------
|
|
13
|
-
CREATE TABLE IF NOT EXISTS users (
|
|
14
|
-
id TEXT PRIMARY KEY,
|
|
15
|
-
email TEXT NOT NULL UNIQUE,
|
|
16
|
-
password_hash TEXT NOT NULL,
|
|
17
|
-
plan TEXT NOT NULL DEFAULT 'free',
|
|
18
|
-
is_admin BOOLEAN NOT NULL DEFAULT FALSE,
|
|
19
|
-
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
20
|
-
last_login_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
21
|
-
);
|
|
22
|
-
CREATE INDEX IF NOT EXISTS idx_users_email ON users (email);
|
|
23
|
-
|
|
24
|
-
-- Sessions --------------------------------------------------------------
|
|
25
|
-
CREATE TABLE IF NOT EXISTS sessions (
|
|
26
|
-
token TEXT PRIMARY KEY,
|
|
27
|
-
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
28
|
-
csrf_token TEXT NOT NULL,
|
|
29
|
-
created_at BIGINT NOT NULL,
|
|
30
|
-
expires_at BIGINT NOT NULL,
|
|
31
|
-
pending_server_tokens JSONB
|
|
32
|
-
);
|
|
33
|
-
CREATE INDEX IF NOT EXISTS idx_sessions_user_id ON sessions (user_id);
|
|
34
|
-
CREATE INDEX IF NOT EXISTS idx_sessions_expires_at ON sessions (expires_at);
|
|
35
|
-
|
|
36
|
-
-- Servers ---------------------------------------------------------------
|
|
37
|
-
CREATE TABLE IF NOT EXISTS servers (
|
|
38
|
-
slug TEXT PRIMARY KEY,
|
|
39
|
-
user_id TEXT REFERENCES users(id) ON DELETE SET NULL,
|
|
40
|
-
spec_hash TEXT NOT NULL,
|
|
41
|
-
container_id TEXT NOT NULL,
|
|
42
|
-
port INTEGER NOT NULL,
|
|
43
|
-
bearer_token TEXT NOT NULL,
|
|
44
|
-
status TEXT NOT NULL DEFAULT 'building',
|
|
45
|
-
server_type TEXT NOT NULL DEFAULT 'api',
|
|
46
|
-
tool_count INTEGER NOT NULL DEFAULT 0,
|
|
47
|
-
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
48
|
-
last_active_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
49
|
-
);
|
|
50
|
-
CREATE INDEX IF NOT EXISTS idx_servers_user_id ON servers (user_id);
|
|
51
|
-
CREATE INDEX IF NOT EXISTS idx_servers_port ON servers (port);
|
|
52
|
-
CREATE INDEX IF NOT EXISTS idx_servers_status ON servers (status);
|
|
53
|
-
|
|
54
|
-
-- Site descriptors (Website-to-MCP) ------------------------------------
|
|
55
|
-
CREATE TABLE IF NOT EXISTS site_descriptors (
|
|
56
|
-
id TEXT PRIMARY KEY,
|
|
57
|
-
server_id TEXT NOT NULL REFERENCES servers(slug) ON DELETE CASCADE,
|
|
58
|
-
url TEXT NOT NULL,
|
|
59
|
-
descriptor JSONB NOT NULL,
|
|
60
|
-
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
61
|
-
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
62
|
-
);
|
|
63
|
-
CREATE INDEX IF NOT EXISTS idx_site_descriptors_server_id ON site_descriptors (server_id);
|
|
64
|
-
CREATE INDEX IF NOT EXISTS idx_site_descriptors_url ON site_descriptors (url);
|
|
65
|
-
|
|
66
|
-
-- Site screenshots (binary, deduplicated by hash) ----------------------
|
|
67
|
-
CREATE TABLE IF NOT EXISTS site_screenshots (
|
|
68
|
-
id TEXT PRIMARY KEY,
|
|
69
|
-
descriptor_id TEXT NOT NULL REFERENCES site_descriptors(id) ON DELETE CASCADE,
|
|
70
|
-
hash TEXT NOT NULL,
|
|
71
|
-
data BYTEA NOT NULL,
|
|
72
|
-
content_type TEXT NOT NULL DEFAULT 'image/png',
|
|
73
|
-
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
74
|
-
);
|
|
75
|
-
CREATE INDEX IF NOT EXISTS idx_site_screenshots_descriptor_id ON site_screenshots (descriptor_id);
|
|
76
|
-
CREATE INDEX IF NOT EXISTS idx_site_screenshots_hash ON site_screenshots (hash);
|
|
77
|
-
|
|
78
|
-
-- Site changes (changelog) ---------------------------------------------
|
|
79
|
-
CREATE TABLE IF NOT EXISTS site_changes (
|
|
80
|
-
id TEXT PRIMARY KEY,
|
|
81
|
-
descriptor_id TEXT NOT NULL REFERENCES site_descriptors(id) ON DELETE CASCADE,
|
|
82
|
-
change_type TEXT NOT NULL,
|
|
83
|
-
summary TEXT,
|
|
84
|
-
diff JSONB,
|
|
85
|
-
detected_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
86
|
-
);
|
|
87
|
-
CREATE INDEX IF NOT EXISTS idx_site_changes_descriptor_id ON site_changes (descriptor_id);
|
|
88
|
-
CREATE INDEX IF NOT EXISTS idx_site_changes_detected_at ON site_changes (detected_at);
|
|
89
|
-
|
|
90
|
-
-- Browser sessions (Playwright) ----------------------------------------
|
|
91
|
-
CREATE TABLE IF NOT EXISTS browser_sessions (
|
|
92
|
-
id TEXT PRIMARY KEY,
|
|
93
|
-
server_id TEXT NOT NULL REFERENCES servers(slug) ON DELETE CASCADE,
|
|
94
|
-
status TEXT NOT NULL DEFAULT 'active',
|
|
95
|
-
started_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
96
|
-
ended_at TIMESTAMPTZ,
|
|
97
|
-
pages_count INTEGER NOT NULL DEFAULT 0
|
|
98
|
-
);
|
|
99
|
-
CREATE INDEX IF NOT EXISTS idx_browser_sessions_server_id ON browser_sessions (server_id);
|
|
100
|
-
CREATE INDEX IF NOT EXISTS idx_browser_sessions_status ON browser_sessions (status);
|
|
101
|
-
|
|
102
|
-
-- Billing events -------------------------------------------------------
|
|
103
|
-
CREATE TABLE IF NOT EXISTS billing_events (
|
|
104
|
-
id TEXT PRIMARY KEY,
|
|
105
|
-
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
106
|
-
event_type TEXT NOT NULL,
|
|
107
|
-
amount INTEGER NOT NULL DEFAULT 0,
|
|
108
|
-
currency TEXT NOT NULL DEFAULT 'usd',
|
|
109
|
-
metadata JSONB,
|
|
110
|
-
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
111
|
-
);
|
|
112
|
-
CREATE INDEX IF NOT EXISTS idx_billing_events_user_id ON billing_events (user_id);
|
|
113
|
-
CREATE INDEX IF NOT EXISTS idx_billing_events_event_type ON billing_events (event_type);
|
|
114
|
-
CREATE INDEX IF NOT EXISTS idx_billing_events_created_at ON billing_events (created_at);
|
|
115
|
-
|
|
116
|
-
-- Usage summaries (pre-aggregated) -------------------------------------
|
|
117
|
-
CREATE TABLE IF NOT EXISTS usage_summaries (
|
|
118
|
-
id TEXT PRIMARY KEY,
|
|
119
|
-
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
120
|
-
period_start TIMESTAMPTZ NOT NULL,
|
|
121
|
-
period_end TIMESTAMPTZ NOT NULL,
|
|
122
|
-
request_count INTEGER NOT NULL DEFAULT 0,
|
|
123
|
-
tool_calls INTEGER NOT NULL DEFAULT 0,
|
|
124
|
-
metadata JSONB,
|
|
125
|
-
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
126
|
-
);
|
|
127
|
-
CREATE INDEX IF NOT EXISTS idx_usage_summaries_user_id ON usage_summaries (user_id);
|
|
128
|
-
CREATE INDEX IF NOT EXISTS idx_usage_summaries_period ON usage_summaries (period_start, period_end);
|
|
129
|
-
|
|
130
|
-
-- Rescan schedules (Website-to-MCP periodic re-crawl) ------------------
|
|
131
|
-
CREATE TABLE IF NOT EXISTS rescan_schedules (
|
|
132
|
-
id TEXT PRIMARY KEY,
|
|
133
|
-
descriptor_id TEXT NOT NULL REFERENCES site_descriptors(id) ON DELETE CASCADE,
|
|
134
|
-
cron_expr TEXT NOT NULL,
|
|
135
|
-
enabled BOOLEAN NOT NULL DEFAULT TRUE,
|
|
136
|
-
last_run_at TIMESTAMPTZ,
|
|
137
|
-
next_run_at TIMESTAMPTZ,
|
|
138
|
-
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
139
|
-
);
|
|
140
|
-
CREATE INDEX IF NOT EXISTS idx_rescan_schedules_descriptor_id ON rescan_schedules (descriptor_id);
|
|
141
|
-
CREATE INDEX IF NOT EXISTS idx_rescan_schedules_next_run ON rescan_schedules (next_run_at) WHERE enabled = TRUE;
|
|
142
|
-
`,
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
version: 2,
|
|
146
|
-
description: 'Server secrets table for encrypted credential storage',
|
|
147
|
-
sql: `
|
|
148
|
-
CREATE TABLE IF NOT EXISTS server_secrets (
|
|
149
|
-
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
150
|
-
slug TEXT NOT NULL REFERENCES servers(slug) ON DELETE CASCADE,
|
|
151
|
-
name TEXT NOT NULL,
|
|
152
|
-
encrypted_value TEXT NOT NULL,
|
|
153
|
-
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
154
|
-
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
155
|
-
UNIQUE (slug, name)
|
|
156
|
-
);
|
|
157
|
-
CREATE INDEX IF NOT EXISTS idx_secrets_slug ON server_secrets(slug);
|
|
158
|
-
`,
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
version: 3,
|
|
162
|
-
description: 'Add Stripe customer ID to users',
|
|
163
|
-
sql: `
|
|
164
|
-
ALTER TABLE users ADD COLUMN IF NOT EXISTS stripe_customer_id TEXT;
|
|
165
|
-
CREATE INDEX IF NOT EXISTS idx_users_stripe_customer_id ON users (stripe_customer_id) WHERE stripe_customer_id IS NOT NULL;
|
|
166
|
-
`,
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
version: 4,
|
|
170
|
-
description: 'Add password reset token fields to users',
|
|
171
|
-
sql: `
|
|
172
|
-
ALTER TABLE users ADD COLUMN IF NOT EXISTS password_reset_token_hash TEXT;
|
|
173
|
-
ALTER TABLE users ADD COLUMN IF NOT EXISTS password_reset_expires_at BIGINT;
|
|
174
|
-
CREATE INDEX IF NOT EXISTS idx_users_reset_token ON users (password_reset_token_hash) WHERE password_reset_token_hash IS NOT NULL;
|
|
175
|
-
`,
|
|
176
|
-
},
|
|
177
|
-
{
|
|
178
|
-
version: 5,
|
|
179
|
-
description: 'Unique index for per-user usage period upserts',
|
|
180
|
-
sql: `
|
|
181
|
-
-- Collapse any pre-existing duplicate (user_id, period_start) rows so the
|
|
182
|
-
-- unique index can be created, summing their counters into one row.
|
|
183
|
-
WITH ranked AS (
|
|
184
|
-
SELECT id,
|
|
185
|
-
row_number() OVER (PARTITION BY user_id, period_start ORDER BY created_at) AS rn,
|
|
186
|
-
SUM(request_count) OVER (PARTITION BY user_id, period_start) AS sum_requests,
|
|
187
|
-
SUM(tool_calls) OVER (PARTITION BY user_id, period_start) AS sum_calls
|
|
188
|
-
FROM usage_summaries
|
|
189
|
-
)
|
|
190
|
-
UPDATE usage_summaries u
|
|
191
|
-
SET request_count = r.sum_requests, tool_calls = r.sum_calls
|
|
192
|
-
FROM ranked r
|
|
193
|
-
WHERE u.id = r.id AND r.rn = 1;
|
|
194
|
-
|
|
195
|
-
DELETE FROM usage_summaries u
|
|
196
|
-
USING (
|
|
197
|
-
SELECT id, row_number() OVER (PARTITION BY user_id, period_start ORDER BY created_at) AS rn
|
|
198
|
-
FROM usage_summaries
|
|
199
|
-
) r
|
|
200
|
-
WHERE u.id = r.id AND r.rn > 1;
|
|
201
|
-
|
|
202
|
-
CREATE UNIQUE INDEX IF NOT EXISTS idx_usage_summaries_user_period
|
|
203
|
-
ON usage_summaries (user_id, period_start);
|
|
204
|
-
`,
|
|
205
|
-
},
|
|
206
|
-
{
|
|
207
|
-
version: 6,
|
|
208
|
-
description: 'Add email verification fields to users',
|
|
209
|
-
sql: `
|
|
210
|
-
ALTER TABLE users ADD COLUMN IF NOT EXISTS email_verified BOOLEAN NOT NULL DEFAULT FALSE;
|
|
211
|
-
ALTER TABLE users ADD COLUMN IF NOT EXISTS email_verification_token_hash TEXT;
|
|
212
|
-
CREATE INDEX IF NOT EXISTS idx_users_verify_token ON users (email_verification_token_hash) WHERE email_verification_token_hash IS NOT NULL;
|
|
213
|
-
`,
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
version: 7,
|
|
217
|
-
description: 'Add Stripe subscription period end to users',
|
|
218
|
-
sql: `
|
|
219
|
-
ALTER TABLE users ADD COLUMN IF NOT EXISTS subscription_period_end BIGINT;
|
|
220
|
-
`,
|
|
221
|
-
},
|
|
222
|
-
{
|
|
223
|
-
version: 8,
|
|
224
|
-
description: 'Idempotency ledger for Stripe webhook events',
|
|
225
|
-
sql: `
|
|
226
|
-
CREATE TABLE IF NOT EXISTS processed_stripe_events (
|
|
227
|
-
id TEXT PRIMARY KEY,
|
|
228
|
-
processed_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
229
|
-
);
|
|
230
|
-
`,
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
version: 9,
|
|
234
|
-
description: 'Promotional tool-call credits + audit ledger',
|
|
235
|
-
sql: `
|
|
236
|
-
-- Persistent balance of bonus tool-calls, consumed when a user is over
|
|
237
|
-
-- their plan's monthly call quota (before the 429 hard cap).
|
|
238
|
-
ALTER TABLE users ADD COLUMN IF NOT EXISTS credits_calls INTEGER NOT NULL DEFAULT 0;
|
|
239
|
-
|
|
240
|
-
-- Append-only audit trail for every grant / revoke / consume.
|
|
241
|
-
CREATE TABLE IF NOT EXISTS credit_ledger (
|
|
242
|
-
id TEXT PRIMARY KEY,
|
|
243
|
-
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
244
|
-
delta INTEGER NOT NULL,
|
|
245
|
-
reason TEXT NOT NULL,
|
|
246
|
-
actor_id TEXT,
|
|
247
|
-
balance_after INTEGER,
|
|
248
|
-
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
249
|
-
);
|
|
250
|
-
CREATE INDEX IF NOT EXISTS idx_credit_ledger_user ON credit_ledger (user_id, created_at);
|
|
251
|
-
`,
|
|
252
|
-
},
|
|
253
|
-
{
|
|
254
|
-
version: 10,
|
|
255
|
-
description: 'Time-series metric samples for admin charts',
|
|
256
|
-
sql: `
|
|
257
|
-
CREATE TABLE IF NOT EXISTS metric_samples (
|
|
258
|
-
id TEXT PRIMARY KEY,
|
|
259
|
-
sampled_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
260
|
-
requests INTEGER NOT NULL DEFAULT 0,
|
|
261
|
-
errors_4xx INTEGER NOT NULL DEFAULT 0,
|
|
262
|
-
errors_5xx INTEGER NOT NULL DEFAULT 0,
|
|
263
|
-
active_containers INTEGER NOT NULL DEFAULT 0,
|
|
264
|
-
mem_used_pct REAL NOT NULL DEFAULT 0,
|
|
265
|
-
disk_used_pct REAL NOT NULL DEFAULT 0,
|
|
266
|
-
total_users INTEGER NOT NULL DEFAULT 0,
|
|
267
|
-
total_servers INTEGER NOT NULL DEFAULT 0
|
|
268
|
-
);
|
|
269
|
-
CREATE INDEX IF NOT EXISTS idx_metric_samples_sampled_at ON metric_samples (sampled_at);
|
|
270
|
-
`,
|
|
271
|
-
},
|
|
272
|
-
{
|
|
273
|
-
version: 11,
|
|
274
|
-
description: 'CLI telemetry / crash reports',
|
|
275
|
-
sql: `
|
|
276
|
-
CREATE TABLE IF NOT EXISTS telemetry_reports (
|
|
277
|
-
id TEXT PRIMARY KEY,
|
|
278
|
-
received_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
279
|
-
client_ip TEXT,
|
|
280
|
-
cli_version TEXT,
|
|
281
|
-
platform TEXT,
|
|
282
|
-
node_version TEXT,
|
|
283
|
-
command TEXT,
|
|
284
|
-
error_message TEXT,
|
|
285
|
-
stack TEXT,
|
|
286
|
-
fingerprint TEXT NOT NULL
|
|
287
|
-
);
|
|
288
|
-
CREATE INDEX IF NOT EXISTS idx_telemetry_fingerprint ON telemetry_reports (fingerprint, received_at);
|
|
289
|
-
`,
|
|
290
|
-
},
|
|
291
|
-
];
|
|
292
|
-
// ---------------------------------------------------------------------------
|
|
293
|
-
// Runner
|
|
294
|
-
// ---------------------------------------------------------------------------
|
|
295
|
-
/**
|
|
296
|
-
* Run all pending migrations in order.
|
|
297
|
-
* Creates the `_migrations` meta-table on first run.
|
|
298
|
-
*/
|
|
299
|
-
export async function runMigrations(db) {
|
|
300
|
-
// Ensure meta-table exists
|
|
301
|
-
await db.query(`
|
|
302
|
-
CREATE TABLE IF NOT EXISTS _migrations (
|
|
303
|
-
version INTEGER PRIMARY KEY,
|
|
304
|
-
description TEXT NOT NULL,
|
|
305
|
-
applied_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
306
|
-
)
|
|
307
|
-
`);
|
|
308
|
-
// Determine current version
|
|
309
|
-
const { rows } = await db.query('SELECT version FROM _migrations ORDER BY version DESC LIMIT 1');
|
|
310
|
-
const currentVersion = rows.length > 0 ? rows[0].version : 0;
|
|
311
|
-
// Apply pending migrations
|
|
312
|
-
for (const migration of migrations) {
|
|
313
|
-
if (migration.version <= currentVersion)
|
|
314
|
-
continue;
|
|
315
|
-
await db.query('BEGIN');
|
|
316
|
-
try {
|
|
317
|
-
await db.query(migration.sql);
|
|
318
|
-
await db.query('INSERT INTO _migrations (version, description) VALUES ($1, $2)', [
|
|
319
|
-
migration.version,
|
|
320
|
-
migration.description,
|
|
321
|
-
]);
|
|
322
|
-
await db.query('COMMIT');
|
|
323
|
-
}
|
|
324
|
-
catch (err) {
|
|
325
|
-
await db.query('ROLLBACK');
|
|
326
|
-
throw new Error(`Migration v${migration.version} (${migration.description}) failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PostgreSQL-backed store implementations.
|
|
3
|
-
*
|
|
4
|
-
* Drop-in replacements for the in-memory ServerStore, UserStore, and
|
|
5
|
-
* SessionStore. Every query is parameterized.
|
|
6
|
-
*/
|
|
7
|
-
import type { Database } from './index.js';
|
|
8
|
-
import type { ServerRecord } from '../store.js';
|
|
9
|
-
import type { UserRecord, SessionRecord } from '../web/auth.js';
|
|
10
|
-
export declare class PgServerStore {
|
|
11
|
-
private db;
|
|
12
|
-
constructor(db: Database);
|
|
13
|
-
create(record: ServerRecord): Promise<void>;
|
|
14
|
-
get(slug: string): Promise<ServerRecord | undefined>;
|
|
15
|
-
list(): Promise<ServerRecord[]>;
|
|
16
|
-
update(slug: string, updates: Partial<ServerRecord>): Promise<void>;
|
|
17
|
-
delete(slug: string): Promise<void>;
|
|
18
|
-
findByPort(port: number): Promise<ServerRecord | undefined>;
|
|
19
|
-
}
|
|
20
|
-
export declare class PgUserStore {
|
|
21
|
-
private db;
|
|
22
|
-
constructor(db: Database);
|
|
23
|
-
create(record: UserRecord): Promise<void>;
|
|
24
|
-
getById(id: string): Promise<UserRecord | undefined>;
|
|
25
|
-
getByEmail(email: string): Promise<UserRecord | undefined>;
|
|
26
|
-
list(): Promise<UserRecord[]>;
|
|
27
|
-
update(id: string, updates: Partial<UserRecord>): Promise<void>;
|
|
28
|
-
getByResetToken(tokenHash: string): Promise<UserRecord | undefined>;
|
|
29
|
-
getByVerificationToken(tokenHash: string): Promise<UserRecord | undefined>;
|
|
30
|
-
getByStripeCustomerId(customerId: string): Promise<UserRecord | undefined>;
|
|
31
|
-
clearResetToken(id: string): Promise<void>;
|
|
32
|
-
clearVerificationToken(id: string): Promise<void>;
|
|
33
|
-
delete(id: string): Promise<void>;
|
|
34
|
-
count(): Promise<number>;
|
|
35
|
-
}
|
|
36
|
-
export declare class PgSessionStore {
|
|
37
|
-
private db;
|
|
38
|
-
constructor(db: Database);
|
|
39
|
-
create(userId: string): Promise<SessionRecord>;
|
|
40
|
-
get(token: string): Promise<SessionRecord | undefined>;
|
|
41
|
-
destroy(token: string): Promise<void>;
|
|
42
|
-
setPendingServerToken(sessionToken: string, slug: string, serverBearerToken: string): Promise<void>;
|
|
43
|
-
consumePendingServerToken(sessionToken: string, slug: string): Promise<string | undefined>;
|
|
44
|
-
cleanup(): Promise<void>;
|
|
45
|
-
}
|