anhedral 0.11.0 → 0.11.1
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/README.md +73 -157
- package/assets/patches/LICENSE.braces +21 -0
- package/assets/patches/LICENSE.node-forge +50 -0
- package/assets/patches/audit-deps.mjs +167 -0
- package/assets/patches/braces@3.0.3.patch +127 -0
- package/assets/patches/node-forge@1.4.0.patch +41 -0
- package/dist/auth-schema.js +3 -3
- package/dist/bin.js +15 -11
- package/dist/capabilities.d.ts +4 -4
- package/dist/capabilities.js +6 -2
- package/dist/capability-contract.js +22 -5
- package/dist/catalog-model.d.ts +24 -0
- package/dist/catalog-model.js +1 -0
- package/dist/catalog-registration.d.ts +16 -0
- package/dist/catalog-registration.js +22 -0
- package/dist/catalog-snapshot.d.ts +5 -0
- package/dist/catalog-snapshot.js +97 -0
- package/dist/cli-arguments.js +1 -1
- package/dist/cli-output.js +27 -2
- package/dist/cloudflare.d.ts +7 -1
- package/dist/cloudflare.js +36 -6
- package/dist/command-schema.js +49 -5
- package/dist/delivery.d.ts +10 -3
- package/dist/delivery.js +154 -37
- package/dist/dependencies.d.ts +24 -0
- package/dist/dependencies.js +48 -0
- package/dist/dependency-patches.d.ts +7 -0
- package/dist/dependency-patches.js +125 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/inspector-model.d.ts +9 -1
- package/dist/integration-service-readers.d.ts +13 -0
- package/dist/integration-service-readers.js +173 -0
- package/dist/lifecycle.d.ts +0 -1
- package/dist/lifecycle.js +0 -1
- package/dist/neon-service-data.d.ts +8 -0
- package/dist/neon-service-data.js +117 -0
- package/dist/pnpm-policy.d.ts +2 -2
- package/dist/pnpm-policy.js +19 -45
- package/dist/project-catalog.d.ts +41 -0
- package/dist/project-catalog.js +288 -0
- package/dist/project-config.d.ts +14 -0
- package/dist/project-config.js +89 -0
- package/dist/project-inspector.js +73 -17
- package/dist/project-lifecycle.d.ts +25 -0
- package/dist/project-lifecycle.js +57 -0
- package/dist/project-state.d.ts +5 -1
- package/dist/project-state.js +122 -16
- package/dist/provider-auth.js +2 -3
- package/dist/provider-readiness.js +27 -10
- package/dist/providers/adapters.js +4 -1
- package/dist/providers/api.d.ts +1 -0
- package/dist/providers/api.js +1 -0
- package/dist/providers/config.js +6 -8
- package/dist/providers/provision.js +1 -1
- package/dist/providers/recovery.d.ts +1 -1
- package/dist/providers/runtime.d.ts +1 -1
- package/dist/providers/runtime.js +46 -23
- package/dist/providers/state.d.ts +1 -2
- package/dist/providers/state.js +14 -54
- package/dist/provision.d.ts +9 -0
- package/dist/provision.js +30 -1
- package/dist/r2-service-data.d.ts +2 -0
- package/dist/r2-service-data.js +136 -0
- package/dist/readiness.js +9 -13
- package/dist/registry/add.js +64 -21
- package/dist/registry/commands.js +7 -9
- package/dist/registry/options.d.ts +1 -1
- package/dist/registry/options.js +4 -4
- package/dist/registry/receipt.d.ts +1 -0
- package/dist/registry/receipt.js +19 -4
- package/dist/registry/resolve.js +5 -1
- package/dist/registry/usage.js +1 -5
- package/dist/render.d.ts +2 -0
- package/dist/render.js +6 -0
- package/dist/runtime-policy.d.ts +4 -0
- package/dist/runtime-policy.js +21 -0
- package/dist/scaffold/bootstrap.js +2 -2
- package/dist/scaffold/compose.js +9 -3
- package/dist/scaffold/database.js +107 -25
- package/dist/scaffold/documentation.js +18 -13
- package/dist/scaffold/lint.d.ts +4 -0
- package/dist/scaffold/lint.js +56 -0
- package/dist/scaffold/neon-realtime.d.ts +2 -0
- package/dist/scaffold/neon-realtime.js +97 -0
- package/dist/scaffold/stack-documentation.js +1 -1
- package/dist/scaffold/void.d.ts +4 -0
- package/dist/scaffold/void.js +256 -0
- package/dist/scaffold/web.js +7 -1
- package/dist/scaffold/workspace.js +120 -29
- package/dist/service-deletion.d.ts +29 -0
- package/dist/service-deletion.js +195 -0
- package/dist/service-descriptor.d.ts +10 -0
- package/dist/service-descriptor.js +78 -0
- package/dist/service-model.d.ts +49 -0
- package/dist/service-model.js +8 -0
- package/dist/service-operations.d.ts +29 -0
- package/dist/service-operations.js +78 -0
- package/dist/service-readers.d.ts +8 -0
- package/dist/service-readers.js +247 -0
- package/dist/services-command.d.ts +39 -0
- package/dist/services-command.js +100 -0
- package/dist/ship.d.ts +36 -8
- package/dist/ship.js +39 -13
- package/dist/stack-registry.d.ts +4 -2
- package/dist/stack-registry.js +41 -11
- package/dist/standard.js +23 -4
- package/dist/transaction.d.ts +2 -0
- package/dist/transaction.js +10 -0
- package/dist/util.js +17 -2
- package/dist/vercel.d.ts +2 -0
- package/dist/vercel.js +69 -13
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/vinext.d.ts +1 -0
- package/dist/vinext.js +13 -1
- package/dist/void-execution.d.ts +10 -0
- package/dist/void-execution.js +94 -0
- package/dist/void-migrations.d.ts +6 -0
- package/dist/void-migrations.js +110 -0
- package/dist/void-state.d.ts +16 -0
- package/dist/void-state.js +65 -0
- package/dist/void.d.ts +3 -0
- package/dist/void.js +5 -0
- package/docs/cli-design.md +2 -2
- package/docs/delivery-workflow.md +8 -7
- package/docs/plugin-ui.md +51 -10
- package/docs/provider-configuration.md +10 -11
- package/docs/stack-standard.md +175 -0
- package/docs/void-verification.md +185 -0
- package/package.json +22 -20
- package/assets/anhedral-mark.svg +0 -4
- package/assets/anhedral-stack-technical.svg +0 -322
- package/assets/anhedral-stack.svg +0 -322
- package/assets/anhedral.svg +0 -4
- package/assets/favicon.ico +0 -0
- package/assets/security/LICENSES.txt +0 -63
- package/assets/security/audit-deps.mjs +0 -300
- package/assets/security/braces-regression.mjs +0 -102
- package/assets/security/braces@3.0.3.patch +0 -285
- package/assets/security/decode-uri-component@0.2.2.patch +0 -149
- package/assets/security/decoder-regression.mjs +0 -37
- package/assets/security/forge-regression.mjs +0 -46
- package/assets/security/manifest.json +0 -53
- package/assets/security/node-forge@1.4.0.patch +0 -26
- package/dist/security-backports.d.ts +0 -3
- package/dist/security-backports.js +0 -26
- package/docs/application-stack-standard.md +0 -75
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type CloudflareRequest } from './cloudflare.js';
|
|
2
|
+
import type { ServiceDeletionStore, DeletionPlan } from './service-deletion.js';
|
|
3
|
+
import type { ServiceData, ServiceMetrics, ServiceObservation, ServiceAction } from './service-model.js';
|
|
4
|
+
export interface ServiceOptions {
|
|
5
|
+
hours?: number;
|
|
6
|
+
table?: string;
|
|
7
|
+
offset?: number;
|
|
8
|
+
cursor?: string;
|
|
9
|
+
token?: string;
|
|
10
|
+
typedName?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ServiceResult {
|
|
13
|
+
status?: ServiceObservation;
|
|
14
|
+
metrics?: ServiceMetrics;
|
|
15
|
+
tables?: string[];
|
|
16
|
+
data?: ServiceData;
|
|
17
|
+
plan?: DeletionPlan;
|
|
18
|
+
deletion?: {
|
|
19
|
+
state: 'deleted' | 'uncertain';
|
|
20
|
+
resourceId: string;
|
|
21
|
+
message: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export type ServiceRequestFactory = (root: string, analytics: boolean) => Promise<CloudflareRequest>;
|
|
25
|
+
/** Shared operations; transports decide how private results are presented. */
|
|
26
|
+
export declare function serviceOperation(root: string, action: ServiceAction, key: string, options?: ServiceOptions, context?: {
|
|
27
|
+
request?: ServiceRequestFactory;
|
|
28
|
+
deletions?: ServiceDeletionStore;
|
|
29
|
+
}): Promise<ServiceResult>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { resolveIntegrationService, integrationRequest, observeIntegrationService, posthogServiceMetrics, } from './integration-service-readers.js';
|
|
2
|
+
import { neonReadConnection, listNeonTables, browseNeonData } from './neon-service-data.js';
|
|
3
|
+
import { vercelApplicationStatus, vercelServiceMetrics } from './vercel.js';
|
|
4
|
+
import { browseR2Objects } from './r2-service-data.js';
|
|
5
|
+
import { inspectApplication } from './project-inspector.js';
|
|
6
|
+
import { readApplication, defaultRunner, targetDirectory } from './project-state.js';
|
|
7
|
+
import { cloudflareRequest } from './cloudflare.js';
|
|
8
|
+
import { resolveService } from './service-descriptor.js';
|
|
9
|
+
import { observeService, readServiceMetrics, listServiceTables, browseServiceData, } from './service-readers.js';
|
|
10
|
+
const requestFor = async (root, analytics) => {
|
|
11
|
+
const project = readApplication(root);
|
|
12
|
+
return cloudflareRequest(project, targetDirectory(root, project.targets[0]), defaultRunner, { ...process.env, ANHEDRAL_COMMAND_TIMEOUT_MS: '10000' }, { analytics, timeoutMs: 10000 });
|
|
13
|
+
};
|
|
14
|
+
const vercelRunner = (command, args, cwd, env, input) => defaultRunner(command, args, cwd, { ...env, ANHEDRAL_COMMAND_TIMEOUT_MS: '30000' }, input);
|
|
15
|
+
/** Shared operations; transports decide how private results are presented. */
|
|
16
|
+
export async function serviceOperation(root, action, key, options = {}, context = {}) {
|
|
17
|
+
if (key.startsWith('provider:') || key.startsWith('integration:')) {
|
|
18
|
+
const service = resolveIntegrationService(root, key);
|
|
19
|
+
const api = integrationRequest(service);
|
|
20
|
+
if (action === 'status')
|
|
21
|
+
return { status: await observeIntegrationService(service, api) };
|
|
22
|
+
if (action === 'metrics')
|
|
23
|
+
return { metrics: await posthogServiceMetrics(service, api, options.hours ?? 24) };
|
|
24
|
+
if (action === 'tables' && service.provider === 'neon')
|
|
25
|
+
return { tables: await listNeonTables(await neonReadConnection(service, api)) };
|
|
26
|
+
if (action === 'data' && service.provider === 'neon')
|
|
27
|
+
return {
|
|
28
|
+
data: await browseNeonData(await neonReadConnection(service, api), options.table ?? '', options.offset ?? 0),
|
|
29
|
+
};
|
|
30
|
+
throw new Error('This integration does not support that operation.');
|
|
31
|
+
}
|
|
32
|
+
if (key.startsWith('target:vercel:')) {
|
|
33
|
+
if (!inspectApplication(root).targets.data.some((target) => key === `target:${target.provider}:${target.id}` && target.provider === 'vercel'))
|
|
34
|
+
throw new Error('Choose a validated Vercel target.');
|
|
35
|
+
if (action === 'metrics')
|
|
36
|
+
return { metrics: await vercelServiceMetrics(root, options.hours ?? 24, vercelRunner) };
|
|
37
|
+
if (action !== 'status')
|
|
38
|
+
throw new Error('Unsupported Vercel operation.');
|
|
39
|
+
const status = await vercelApplicationStatus(root, true, vercelRunner);
|
|
40
|
+
return {
|
|
41
|
+
status: {
|
|
42
|
+
state: 'available',
|
|
43
|
+
fetchedAt: new Date().toISOString(),
|
|
44
|
+
message: status.activeRecordedVersion
|
|
45
|
+
? 'Provider confirmed the recorded deployment is active. Application health is separate.'
|
|
46
|
+
: 'Provider project verified. The recorded deployment is not confirmed active.',
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const service = resolveService(root, key);
|
|
51
|
+
if (service.kind === 'r2' && action === 'tables')
|
|
52
|
+
return { tables: ['objects'] };
|
|
53
|
+
if (service.kind === 'r2' && action === 'data') {
|
|
54
|
+
if (options.table !== 'objects')
|
|
55
|
+
throw new Error('Choose object metadata.');
|
|
56
|
+
return { data: await browseR2Objects(service, options.cursor) };
|
|
57
|
+
}
|
|
58
|
+
const request = await (context.request ?? requestFor)(root, action === 'metrics');
|
|
59
|
+
if (action === 'status')
|
|
60
|
+
return { status: await observeService(service, request) };
|
|
61
|
+
if (action === 'metrics')
|
|
62
|
+
return { metrics: await readServiceMetrics(service, request, options.hours ?? 24) };
|
|
63
|
+
if (action === 'tables')
|
|
64
|
+
return { tables: service.kind === 'kv' ? ['keys'] : await listServiceTables(service, request) };
|
|
65
|
+
if (action === 'data')
|
|
66
|
+
return {
|
|
67
|
+
data: await browseServiceData(service, request, options.table ?? '', options.offset ?? 0, 25, options.cursor),
|
|
68
|
+
};
|
|
69
|
+
if (!context.deletions)
|
|
70
|
+
throw new Error('A deletion confirmation store is required.');
|
|
71
|
+
if (action === 'delete-plan')
|
|
72
|
+
return { plan: await context.deletions.plan(root, key, request) };
|
|
73
|
+
if (!options.token || !options.typedName)
|
|
74
|
+
throw new Error('Review a deletion plan and type the exact resource name.');
|
|
75
|
+
return {
|
|
76
|
+
deletion: await context.deletions.execute(root, key, options.token, options.typedName, request),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type CloudflareRequest } from './cloudflare.js';
|
|
2
|
+
import type { ServiceData, ServiceDescriptor, ServiceMetrics, ServiceObservation } from './service-model.js';
|
|
3
|
+
export declare const serviceEndpoint: (service: ServiceDescriptor) => string;
|
|
4
|
+
export declare function record(value: unknown): Record<string, unknown>;
|
|
5
|
+
export declare function observeService(service: ServiceDescriptor, request: CloudflareRequest): Promise<ServiceObservation>;
|
|
6
|
+
export declare function listServiceTables(service: ServiceDescriptor, request: CloudflareRequest): Promise<string[]>;
|
|
7
|
+
export declare function browseServiceData(service: ServiceDescriptor, request: CloudflareRequest, table: string, offset?: number, limit?: number, cursor?: string): Promise<ServiceData>;
|
|
8
|
+
export declare function readServiceMetrics(service: ServiceDescriptor, analytics: CloudflareRequest, hours?: number): Promise<ServiceMetrics>;
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { CloudflareRequestError } from './cloudflare.js';
|
|
2
|
+
export const serviceEndpoint = (service) => {
|
|
3
|
+
const id = encodeURIComponent(service.kind === 'r2' ? (service.name ?? service.id) : service.id);
|
|
4
|
+
return {
|
|
5
|
+
d1: `/d1/database/${id}`,
|
|
6
|
+
kv: `/storage/kv/namespaces/${id}`,
|
|
7
|
+
r2: `/r2/buckets/${id}`,
|
|
8
|
+
queue: `/queues/${id}`,
|
|
9
|
+
worker: `/workers/scripts/${id}/settings`,
|
|
10
|
+
}[service.kind];
|
|
11
|
+
};
|
|
12
|
+
export function record(value) {
|
|
13
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
14
|
+
throw new Error('Unsupported service response.');
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
export async function observeService(service, request) {
|
|
18
|
+
const fetchedAt = new Date().toISOString();
|
|
19
|
+
try {
|
|
20
|
+
const value = record((await request('GET', serviceEndpoint(service))).result);
|
|
21
|
+
const id = service.kind === 'd1'
|
|
22
|
+
? value.uuid
|
|
23
|
+
: service.kind === 'kv'
|
|
24
|
+
? value.id
|
|
25
|
+
: service.kind === 'queue'
|
|
26
|
+
? value.queue_id
|
|
27
|
+
: undefined;
|
|
28
|
+
if (service.kind !== 'worker' && service.kind !== 'r2' && id !== service.id)
|
|
29
|
+
throw new Error('Provider resource identity differs from the source.');
|
|
30
|
+
const name = value.name ?? value.title ?? value.queue_name;
|
|
31
|
+
if (name !== undefined &&
|
|
32
|
+
(typeof name !== 'string' ||
|
|
33
|
+
name.length > 256 ||
|
|
34
|
+
(service.name !== null && name !== service.name)))
|
|
35
|
+
throw new Error('Provider resource name differs from the source.');
|
|
36
|
+
return {
|
|
37
|
+
state: 'available',
|
|
38
|
+
fetchedAt,
|
|
39
|
+
...(typeof name === 'string' ? { name } : {}),
|
|
40
|
+
...(service.kind === 'd1' &&
|
|
41
|
+
typeof value.file_size === 'number' &&
|
|
42
|
+
Number.isSafeInteger(value.file_size) &&
|
|
43
|
+
value.file_size >= 0
|
|
44
|
+
? { storageBytes: value.file_size }
|
|
45
|
+
: {}),
|
|
46
|
+
message: 'Provider confirmed this resource exists. Application health is separate.',
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
const status = error instanceof CloudflareRequestError ? error.status : undefined;
|
|
51
|
+
return {
|
|
52
|
+
state: status === 404
|
|
53
|
+
? 'not-found'
|
|
54
|
+
: status === 401 || status === 403
|
|
55
|
+
? 'permission-required'
|
|
56
|
+
: 'unavailable',
|
|
57
|
+
fetchedAt,
|
|
58
|
+
message: status === 404
|
|
59
|
+
? 'Resource not found in the selected account.'
|
|
60
|
+
: status === 401 || status === 403
|
|
61
|
+
? 'Sign in with the required resource-read permissions.'
|
|
62
|
+
: 'Service could not be verified. Check identity, connectivity, and provider availability.',
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async function d1Query(service, request, sql, params = []) {
|
|
67
|
+
const value = (await request('POST', `${serviceEndpoint(service)}/query`, { sql, params }))
|
|
68
|
+
.result;
|
|
69
|
+
if (!Array.isArray(value) || value.length !== 1)
|
|
70
|
+
throw new Error('Unsupported database response.');
|
|
71
|
+
const result = record(value[0]);
|
|
72
|
+
const meta = record(result.meta ?? {});
|
|
73
|
+
if (result.success !== true ||
|
|
74
|
+
meta.changed_db === true ||
|
|
75
|
+
(typeof meta.changes === 'number' && meta.changes !== 0))
|
|
76
|
+
throw new Error('Read-only data operation did not complete safely.');
|
|
77
|
+
if (!Array.isArray(result.results) || result.results.length > 1001)
|
|
78
|
+
throw new Error('Database output exceeded its row limit.');
|
|
79
|
+
return result.results.map(record);
|
|
80
|
+
}
|
|
81
|
+
export async function listServiceTables(service, request) {
|
|
82
|
+
if (service.kind !== 'd1')
|
|
83
|
+
throw new Error('Schema browsing is supported for D1 databases.');
|
|
84
|
+
const rows = await d1Query(service, request, "SELECT name FROM sqlite_schema WHERE type = 'table' AND name NOT LIKE 'sqlite_%' AND name NOT LIKE '_cf_%' ORDER BY name LIMIT 1001");
|
|
85
|
+
if (rows.length > 1000)
|
|
86
|
+
throw new Error('Database schema exceeds its table limit.');
|
|
87
|
+
return rows.map((row) => {
|
|
88
|
+
if (typeof row.name !== 'string' || !/^[a-zA-Z_][a-zA-Z0-9_]{0,127}$/.test(row.name))
|
|
89
|
+
throw new Error('Unsupported table identifier.');
|
|
90
|
+
return row.name;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
export async function browseServiceData(service, request, table, offset = 0, limit = 25, cursor) {
|
|
94
|
+
if (!Number.isSafeInteger(offset) ||
|
|
95
|
+
offset < 0 ||
|
|
96
|
+
offset > 10_000 ||
|
|
97
|
+
!Number.isInteger(limit) ||
|
|
98
|
+
limit < 1 ||
|
|
99
|
+
limit > 100)
|
|
100
|
+
throw new Error('Choose a bounded data page.');
|
|
101
|
+
if (cursor !== undefined && (cursor.length > 4096 || /[\x00-\x1f\x7f]/.test(cursor)))
|
|
102
|
+
throw new Error('Choose a bounded metadata cursor.');
|
|
103
|
+
if (service.kind === 'kv') {
|
|
104
|
+
if (offset !== 0 || table !== 'keys')
|
|
105
|
+
throw new Error('KV metadata uses cursors; key values are not read.');
|
|
106
|
+
const query = new URLSearchParams({ limit: String(limit), ...(cursor ? { cursor } : {}) });
|
|
107
|
+
const response = await request('GET', `${serviceEndpoint(service)}/keys?${query}`);
|
|
108
|
+
if (!Array.isArray(response.result) || response.result.length > limit)
|
|
109
|
+
throw new Error('Unsupported KV metadata.');
|
|
110
|
+
return {
|
|
111
|
+
fetchedAt: new Date().toISOString(),
|
|
112
|
+
columns: ['Key', 'Expiration'],
|
|
113
|
+
rows: response.result.map((item) => {
|
|
114
|
+
const key = record(item);
|
|
115
|
+
return [
|
|
116
|
+
typeof key.name === 'string' ? key.name.slice(0, 256) : null,
|
|
117
|
+
typeof key.expiration === 'number' ? key.expiration : null,
|
|
118
|
+
];
|
|
119
|
+
}),
|
|
120
|
+
offset,
|
|
121
|
+
hasMore: Boolean(response.result_info?.cursor),
|
|
122
|
+
...(response.result_info?.cursor ? { nextCursor: response.result_info.cursor } : {}),
|
|
123
|
+
masked: true,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (cursor !== undefined)
|
|
127
|
+
throw new Error('Database pages use offsets, not metadata cursors.');
|
|
128
|
+
if (service.kind !== 'd1' ||
|
|
129
|
+
!/^[a-zA-Z_][a-zA-Z0-9_]{0,127}$/.test(table) ||
|
|
130
|
+
!(await listServiceTables(service, request)).includes(table))
|
|
131
|
+
throw new Error('Choose an existing supported database table.');
|
|
132
|
+
const fields = await d1Query(service, request, `PRAGMA table_info("${table}")`);
|
|
133
|
+
if (!fields.length || fields.length > 50)
|
|
134
|
+
throw new Error('Table exceeds its supported column limit.');
|
|
135
|
+
const columns = fields.map((field) => {
|
|
136
|
+
if (typeof field.name !== 'string' || !/^[a-zA-Z_][a-zA-Z0-9_]{0,127}$/.test(field.name))
|
|
137
|
+
throw new Error('Unsupported database column.');
|
|
138
|
+
return field.name;
|
|
139
|
+
});
|
|
140
|
+
const sensitive = /password|secret|token|email|phone|address|authorization|cookie|session|private|credential/i;
|
|
141
|
+
const projection = columns
|
|
142
|
+
.map((column) => sensitive.test(column)
|
|
143
|
+
? `'[masked]' AS "${column}"`
|
|
144
|
+
: `CASE WHEN typeof("${column}") IN ('text', 'blob') THEN substr(CAST("${column}" AS TEXT), 1, 1000) ELSE "${column}" END AS "${column}"`)
|
|
145
|
+
.join(', ');
|
|
146
|
+
const ordering = columns.map((_, index) => index + 1).join(', ');
|
|
147
|
+
const rows = await d1Query(service, request, `SELECT ${projection} FROM "${table}" ORDER BY ${ordering} LIMIT ? OFFSET ?`, [limit + 1, offset]);
|
|
148
|
+
let masked = columns.some((column) => sensitive.test(column));
|
|
149
|
+
const outputRows = rows.slice(0, limit).map((row) => columns.map((column) => {
|
|
150
|
+
const value = row[column];
|
|
151
|
+
if (sensitive.test(column)) {
|
|
152
|
+
masked = true;
|
|
153
|
+
return '[masked]';
|
|
154
|
+
}
|
|
155
|
+
if (value === null || typeof value === 'boolean' || typeof value === 'number')
|
|
156
|
+
return value;
|
|
157
|
+
if (typeof value === 'string') {
|
|
158
|
+
if (/^(?:sk[-_]|rk[-_]|whsec[-_]|Bearer )/i.test(value)) {
|
|
159
|
+
masked = true;
|
|
160
|
+
return '[masked]';
|
|
161
|
+
}
|
|
162
|
+
return value.slice(0, 1000);
|
|
163
|
+
}
|
|
164
|
+
return '[complex value]';
|
|
165
|
+
}));
|
|
166
|
+
return {
|
|
167
|
+
fetchedAt: new Date().toISOString(),
|
|
168
|
+
columns,
|
|
169
|
+
offset,
|
|
170
|
+
hasMore: rows.length > limit,
|
|
171
|
+
masked,
|
|
172
|
+
rows: outputRows,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
export async function readServiceMetrics(service, analytics, hours = 24) {
|
|
176
|
+
if (![1, 24, 168].includes(hours) ||
|
|
177
|
+
!['worker', 'd1'].includes(service.kind) ||
|
|
178
|
+
(service.kind === 'd1' && hours === 1))
|
|
179
|
+
throw new Error('Unsupported service or analytics window.');
|
|
180
|
+
const worker = service.kind === 'worker';
|
|
181
|
+
const end = worker
|
|
182
|
+
? new Date().toISOString()
|
|
183
|
+
: new Date(new Date().toISOString().slice(0, 10) + 'T00:00:00.000Z').toISOString();
|
|
184
|
+
const start = new Date(Date.parse(end) - hours * 3600000).toISOString();
|
|
185
|
+
const query = worker
|
|
186
|
+
? `query($accountTag: string!, $id: string!, $start: string!, $end: string!) { viewer { accounts(filter: {accountTag: $accountTag}) { workersInvocationsAdaptive(limit: 1000, filter: {scriptName: $id, datetime_geq: $start, datetime_leq: $end}) { dimensions { datetime scriptName } sum { requests errors } quantiles { cpuTimeP50 cpuTimeP99 } } } } }`
|
|
187
|
+
: `query($accountTag: string!, $id: string!, $start: Date!, $end: Date!) { viewer { accounts(filter: {accountTag: $accountTag}) { d1AnalyticsAdaptiveGroups(limit: 1000, filter: {databaseId: $id, date_geq: $start, date_leq: $end}, orderBy: [date_ASC]) { dimensions { date databaseId } sum { readQueries writeQueries } quantiles { queryBatchTimeMsP90 } } } } }`;
|
|
188
|
+
const response = record((await analytics('POST', '/graphql', {
|
|
189
|
+
query,
|
|
190
|
+
variables: {
|
|
191
|
+
accountTag: service.accountId,
|
|
192
|
+
id: service.id,
|
|
193
|
+
start: worker ? start : start.slice(0, 10),
|
|
194
|
+
end: worker ? end : new Date(Date.parse(end) - 1).toISOString().slice(0, 10),
|
|
195
|
+
},
|
|
196
|
+
})).result);
|
|
197
|
+
const accounts = record(response.viewer).accounts;
|
|
198
|
+
if (!Array.isArray(accounts) || accounts.length !== 1)
|
|
199
|
+
throw new Error('Analytics account response is unavailable.');
|
|
200
|
+
const rows = record(accounts[0])[worker ? 'workersInvocationsAdaptive' : 'd1AnalyticsAdaptiveGroups'];
|
|
201
|
+
if (!Array.isArray(rows) || rows.length >= 1000)
|
|
202
|
+
throw new Error('Analytics is truncated or unavailable; choose a smaller window.');
|
|
203
|
+
const names = worker ? ['requests', 'errors'] : ['readQueries', 'writeQueries'];
|
|
204
|
+
const points = rows
|
|
205
|
+
.map((entry) => {
|
|
206
|
+
const value = record(entry);
|
|
207
|
+
const dimensions = record(value.dimensions);
|
|
208
|
+
const sum = record(value.sum);
|
|
209
|
+
if (dimensions[worker ? 'scriptName' : 'databaseId'] !== service.id)
|
|
210
|
+
throw new Error('Analytics resource identity differs from the selection.');
|
|
211
|
+
const time = dimensions[worker ? 'datetime' : 'date'];
|
|
212
|
+
if (typeof time !== 'string' ||
|
|
213
|
+
!Number.isFinite(Date.parse(time)) ||
|
|
214
|
+
Date.parse(time) < Date.parse(start) ||
|
|
215
|
+
Date.parse(time) > Date.parse(end))
|
|
216
|
+
throw new Error('Invalid analytics time.');
|
|
217
|
+
const values = {};
|
|
218
|
+
for (const name of names) {
|
|
219
|
+
if (typeof sum[name] !== 'number' || !Number.isFinite(sum[name]) || Number(sum[name]) < 0)
|
|
220
|
+
throw new Error('Invalid analytics count.');
|
|
221
|
+
values[name] = Number(sum[name]);
|
|
222
|
+
}
|
|
223
|
+
const quantiles = record(value.quantiles ?? {});
|
|
224
|
+
for (const name of worker ? ['cpuTimeP50', 'cpuTimeP99'] : ['queryBatchTimeMsP90'])
|
|
225
|
+
if (typeof quantiles[name] === 'number' &&
|
|
226
|
+
Number.isFinite(quantiles[name]) &&
|
|
227
|
+
Number(quantiles[name]) >= 0)
|
|
228
|
+
values[name] = Number(quantiles[name]);
|
|
229
|
+
return { time, values };
|
|
230
|
+
})
|
|
231
|
+
.sort((a, b) => a.time.localeCompare(b.time));
|
|
232
|
+
return {
|
|
233
|
+
fetchedAt: new Date().toISOString(),
|
|
234
|
+
start,
|
|
235
|
+
end,
|
|
236
|
+
timezone: 'UTC',
|
|
237
|
+
source: worker ? 'Cloudflare Workers GraphQL' : 'Cloudflare D1 GraphQL (daily buckets)',
|
|
238
|
+
sampled: true,
|
|
239
|
+
points,
|
|
240
|
+
units: {
|
|
241
|
+
...Object.fromEntries(names.map((name) => [name, 'count'])),
|
|
242
|
+
...(worker
|
|
243
|
+
? { cpuTimeP50: 'microseconds', cpuTimeP99: 'microseconds' }
|
|
244
|
+
: { queryBatchTimeMsP90: 'milliseconds' }),
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare function runServiceCommand(root: string, input: string[]): Promise<string[] | import("./service-model.js").ServiceObservation | import("./service-model.js").ServiceMetrics | import("./service-model.js").ServiceData | import("./service-deletion.js").DeletionPlan | {
|
|
2
|
+
state: "deleted" | "uncertain";
|
|
3
|
+
resourceId: string;
|
|
4
|
+
message: string;
|
|
5
|
+
} | {
|
|
6
|
+
services: ({
|
|
7
|
+
key: string;
|
|
8
|
+
provider: string;
|
|
9
|
+
capabilities: {
|
|
10
|
+
status: boolean;
|
|
11
|
+
metrics: boolean;
|
|
12
|
+
data: boolean;
|
|
13
|
+
delete: boolean;
|
|
14
|
+
};
|
|
15
|
+
state?: undefined;
|
|
16
|
+
} | {
|
|
17
|
+
capabilities: {
|
|
18
|
+
status: boolean;
|
|
19
|
+
metrics: boolean;
|
|
20
|
+
data: boolean;
|
|
21
|
+
delete: boolean;
|
|
22
|
+
};
|
|
23
|
+
key: string;
|
|
24
|
+
kind: import("./service-model.js").ServiceKind;
|
|
25
|
+
id: string;
|
|
26
|
+
name: string | null;
|
|
27
|
+
accountId: string;
|
|
28
|
+
projectId: string;
|
|
29
|
+
applications: string[];
|
|
30
|
+
ownership: "created" | "reused" | "unknown";
|
|
31
|
+
provider?: undefined;
|
|
32
|
+
state?: undefined;
|
|
33
|
+
} | {
|
|
34
|
+
key: string;
|
|
35
|
+
capabilities: null;
|
|
36
|
+
state: string;
|
|
37
|
+
provider?: undefined;
|
|
38
|
+
})[];
|
|
39
|
+
} | undefined>;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { resolveIntegrationService } from './integration-service-readers.js';
|
|
3
|
+
import { inspectApplication } from './project-inspector.js';
|
|
4
|
+
import { resolveService, serviceCapabilities, unboundResourceSelectors, } from './service-descriptor.js';
|
|
5
|
+
import { ServiceDeletionStore } from './service-deletion.js';
|
|
6
|
+
import { catalogDirectory } from './catalog-registration.js';
|
|
7
|
+
import { serviceOperation } from './service-operations.js';
|
|
8
|
+
export async function runServiceCommand(root, input) {
|
|
9
|
+
const args = input.filter((arg) => arg !== '--json');
|
|
10
|
+
const action = args.shift();
|
|
11
|
+
const actions = ['list', 'status', 'metrics', 'tables', 'data', 'delete-plan', 'delete'];
|
|
12
|
+
if (!action || !actions.includes(action))
|
|
13
|
+
throw new Error('Choose a supported services operation.');
|
|
14
|
+
if (action === 'list') {
|
|
15
|
+
if (args.length)
|
|
16
|
+
throw new Error('services list accepts no service selector.');
|
|
17
|
+
const inspection = inspectApplication(root);
|
|
18
|
+
const keys = [
|
|
19
|
+
...inspection.setupProviders.data
|
|
20
|
+
.filter((provider) => !['cloudflare', 'vercel', 'expo'].includes(provider.id))
|
|
21
|
+
.map((provider) => `provider:${provider.id}`),
|
|
22
|
+
...inspection.integrations.data.flatMap((provider) => provider.operations.map((operation) => `integration:${provider.provider}:${operation.operation}`)),
|
|
23
|
+
...inspection.targets.data.map((target) => `target:${target.provider}:${target.id}`),
|
|
24
|
+
...inspection.configuration.data.bindings.map((binding) => `binding:${binding.application}:${binding.kind}:${binding.name}`),
|
|
25
|
+
...unboundResourceSelectors(inspection),
|
|
26
|
+
];
|
|
27
|
+
return {
|
|
28
|
+
services: keys.map((key) => {
|
|
29
|
+
try {
|
|
30
|
+
if (key.startsWith('provider:') || key.startsWith('integration:')) {
|
|
31
|
+
const service = resolveIntegrationService(root, key);
|
|
32
|
+
return {
|
|
33
|
+
key,
|
|
34
|
+
provider: service.provider,
|
|
35
|
+
capabilities: {
|
|
36
|
+
status: true,
|
|
37
|
+
metrics: service.provider === 'posthog',
|
|
38
|
+
data: service.provider === 'neon',
|
|
39
|
+
delete: false,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (key.startsWith('target:vercel:'))
|
|
44
|
+
return {
|
|
45
|
+
key,
|
|
46
|
+
provider: 'vercel',
|
|
47
|
+
capabilities: { status: true, metrics: true, data: false, delete: false },
|
|
48
|
+
};
|
|
49
|
+
const service = resolveService(root, key);
|
|
50
|
+
return { ...service, capabilities: serviceCapabilities(service.kind) };
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return { key, capabilities: null, state: 'unsupported-or-unconfigured' };
|
|
54
|
+
}
|
|
55
|
+
}),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const key = args.shift();
|
|
59
|
+
if (!key || key.startsWith('-') || key.length > 1024)
|
|
60
|
+
throw new Error('Choose the exact service key from services list.');
|
|
61
|
+
const options = {};
|
|
62
|
+
for (let i = 0; i < args.length; i += 2) {
|
|
63
|
+
if (!['--hours', '--table', '--offset', '--token', '--confirm-name', '--cursor'].includes(args[i]) ||
|
|
64
|
+
options[args[i]] !== undefined ||
|
|
65
|
+
!args[i + 1] ||
|
|
66
|
+
args[i + 1].startsWith('-'))
|
|
67
|
+
throw new Error('Invalid services options.');
|
|
68
|
+
options[args[i]] = args[i + 1];
|
|
69
|
+
}
|
|
70
|
+
const allowed = {
|
|
71
|
+
status: [],
|
|
72
|
+
metrics: ['--hours'],
|
|
73
|
+
tables: [],
|
|
74
|
+
data: ['--table', '--offset', '--cursor'],
|
|
75
|
+
'delete-plan': [],
|
|
76
|
+
delete: ['--token', '--confirm-name'],
|
|
77
|
+
};
|
|
78
|
+
if (Object.keys(options).some((option) => !allowed[action].includes(option)))
|
|
79
|
+
throw new Error('This services operation does not accept that option.');
|
|
80
|
+
if (action === 'delete' && (!options['--token'] || !options['--confirm-name']))
|
|
81
|
+
throw new Error('Deletion requires its plan token and exact resource name.');
|
|
82
|
+
const result = await serviceOperation(root, action, key, {
|
|
83
|
+
hours: options['--hours'] === undefined ? undefined : Number(options['--hours']),
|
|
84
|
+
table: options['--table'],
|
|
85
|
+
offset: options['--offset'] === undefined ? undefined : Number(options['--offset']),
|
|
86
|
+
cursor: options['--cursor'],
|
|
87
|
+
token: options['--token'],
|
|
88
|
+
typedName: options['--confirm-name'],
|
|
89
|
+
}, action === 'delete-plan' || action === 'delete'
|
|
90
|
+
? {
|
|
91
|
+
deletions: new ServiceDeletionStore(path.join(catalogDirectory(), 'service-confirmations')),
|
|
92
|
+
}
|
|
93
|
+
: {});
|
|
94
|
+
return (result.status ??
|
|
95
|
+
result.metrics ??
|
|
96
|
+
result.tables ??
|
|
97
|
+
result.data ??
|
|
98
|
+
result.plan ??
|
|
99
|
+
result.deletion);
|
|
100
|
+
}
|
package/dist/ship.d.ts
CHANGED
|
@@ -2,12 +2,18 @@ import { type DeliveryRunner } from './project-state.js';
|
|
|
2
2
|
import { planProvisioning, provisionApplication } from './provision.js';
|
|
3
3
|
import type { CloudflareRequest } from './cloudflare.js';
|
|
4
4
|
import { planProviderProvisioning, provisionSelectedProviders } from './providers/provision.js';
|
|
5
|
-
export declare function shipCloudflareApplication(root: string, dryRun?: boolean, run?: DeliveryRunner, request?: CloudflareRequest, send?: typeof fetch, providerEnvironment?: NodeJS.ProcessEnv
|
|
5
|
+
export declare function shipCloudflareApplication(root: string, dryRun?: boolean, run?: DeliveryRunner, request?: CloudflareRequest, send?: typeof fetch, providerEnvironment?: NodeJS.ProcessEnv, options?: {
|
|
6
|
+
voidLogsDirectory?: string;
|
|
7
|
+
}): Promise<{
|
|
8
|
+
management: string;
|
|
9
|
+
state?: "configuration-required" | undefined;
|
|
10
|
+
deployed?: false | undefined;
|
|
11
|
+
activated?: true | undefined;
|
|
12
|
+
nextAction?: string | undefined;
|
|
6
13
|
projectId: string;
|
|
7
14
|
release: import("./delivery.js").Release;
|
|
8
15
|
managementFile: string;
|
|
9
16
|
productVerification: string;
|
|
10
|
-
management: string;
|
|
11
17
|
} | ({
|
|
12
18
|
project: import("./project-state.js").ApplicationProject;
|
|
13
19
|
checks: string[][];
|
|
@@ -74,13 +80,17 @@ export declare function shipSelectedVercelApplication(root: string, dryRun?: boo
|
|
|
74
80
|
/** Each mixed target keeps its own release receipt; this is not a provider transaction. */
|
|
75
81
|
export declare function shipSelectedStack(root: string, dryRun?: boolean, run?: DeliveryRunner, request?: CloudflareRequest, send?: typeof fetch, providerEnvironment?: NodeJS.ProcessEnv): Promise<{
|
|
76
82
|
projectId: string;
|
|
77
|
-
release: import("./
|
|
78
|
-
managementFile: string;
|
|
83
|
+
release: import("./vercel.js").WebRelease;
|
|
79
84
|
productVerification: string;
|
|
80
|
-
management: string;
|
|
81
85
|
} | {
|
|
86
|
+
management: string;
|
|
87
|
+
state?: "configuration-required" | undefined;
|
|
88
|
+
deployed?: false | undefined;
|
|
89
|
+
activated?: true | undefined;
|
|
90
|
+
nextAction?: string | undefined;
|
|
82
91
|
projectId: string;
|
|
83
|
-
release: import("./
|
|
92
|
+
release: import("./delivery.js").Release;
|
|
93
|
+
managementFile: string;
|
|
84
94
|
productVerification: string;
|
|
85
95
|
} | ({
|
|
86
96
|
project: import("./project-state.js").ApplicationProject;
|
|
@@ -141,6 +151,16 @@ export declare function shipSelectedStack(root: string, dryRun?: boolean, run?:
|
|
|
141
151
|
targets: {
|
|
142
152
|
provider: string;
|
|
143
153
|
result: {
|
|
154
|
+
management: string;
|
|
155
|
+
state?: "configuration-required" | undefined;
|
|
156
|
+
deployed?: false | undefined;
|
|
157
|
+
activated?: true | undefined;
|
|
158
|
+
nextAction?: string | undefined;
|
|
159
|
+
projectId: string;
|
|
160
|
+
release: import("./delivery.js").Release;
|
|
161
|
+
managementFile: string;
|
|
162
|
+
productVerification: string;
|
|
163
|
+
} | {
|
|
144
164
|
state: "configuration-required";
|
|
145
165
|
resources: Awaited<ReturnType<typeof provisionApplication>>;
|
|
146
166
|
deployed: false;
|
|
@@ -162,11 +182,15 @@ export declare function shipSelectedStack(root: string, dryRun?: boolean, run?:
|
|
|
162
182
|
targets: ({
|
|
163
183
|
provider: string;
|
|
164
184
|
result: {
|
|
185
|
+
management: string;
|
|
186
|
+
state?: "configuration-required" | undefined;
|
|
187
|
+
deployed?: false | undefined;
|
|
188
|
+
activated?: true | undefined;
|
|
189
|
+
nextAction?: string | undefined;
|
|
165
190
|
projectId: string;
|
|
166
191
|
release: import("./delivery.js").Release;
|
|
167
192
|
managementFile: string;
|
|
168
193
|
productVerification: string;
|
|
169
|
-
management: string;
|
|
170
194
|
} | ({
|
|
171
195
|
project: import("./project-state.js").ApplicationProject;
|
|
172
196
|
checks: string[][];
|
|
@@ -242,11 +266,15 @@ export declare function shipSelectedStack(root: string, dryRun?: boolean, run?:
|
|
|
242
266
|
targets: ({
|
|
243
267
|
provider: string;
|
|
244
268
|
result: {
|
|
269
|
+
management: string;
|
|
270
|
+
state?: "configuration-required" | undefined;
|
|
271
|
+
deployed?: false | undefined;
|
|
272
|
+
activated?: true | undefined;
|
|
273
|
+
nextAction?: string | undefined;
|
|
245
274
|
projectId: string;
|
|
246
275
|
release: import("./delivery.js").Release;
|
|
247
276
|
managementFile: string;
|
|
248
277
|
productVerification: string;
|
|
249
|
-
management: string;
|
|
250
278
|
} | ({
|
|
251
279
|
project: import("./project-state.js").ApplicationProject;
|
|
252
280
|
checks: string[][];
|