@specdest/devkit 0.4.19 → 0.4.20
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 +105 -28
- package/dist/npm/cli.js +16 -26
- package/dist/npm/index.js +4 -1
- package/dist/npm/native/specdest-darwin-arm64 +0 -0
- package/dist/npm/native/specdest-darwin-x64 +0 -0
- package/dist/npm/native/specdest-linux-arm64 +0 -0
- package/dist/npm/native/specdest-linux-x64 +0 -0
- package/package.json +8 -5
- package/dist/npm/automation-policy.d.ts +0 -2
- package/dist/npm/automation-policy.js +0 -30
- package/dist/npm/canonical-project-operations.d.ts +0 -5
- package/dist/npm/canonical-project-operations.js +0 -5
- package/dist/npm/canonical-project.d.ts +0 -21
- package/dist/npm/canonical-project.js +0 -115
- package/dist/npm/catalog-snapshot.d.ts +0 -53
- package/dist/npm/catalog-snapshot.js +0 -35
- package/dist/npm/client-only-boundary.d.ts +0 -1
- package/dist/npm/client-only-boundary.js +0 -29
- package/dist/npm/commands.d.ts +0 -16
- package/dist/npm/commands.js +0 -194
- package/dist/npm/git-catalog.d.ts +0 -40
- package/dist/npm/git-catalog.js +0 -222
- package/dist/npm/github-doppler-secrets.d.ts +0 -8
- package/dist/npm/github-doppler-secrets.js +0 -156
- package/dist/npm/host-automation.d.ts +0 -9
- package/dist/npm/host-automation.js +0 -87
- package/dist/npm/installer-primitives.d.ts +0 -3
- package/dist/npm/installer-primitives.js +0 -50
- package/dist/npm/predefined-packages/abac.d.ts +0 -2
- package/dist/npm/predefined-packages/abac.js +0 -45
- package/dist/npm/predefined-packages/admin-ui-templates/AdminAccessAssignments.tsx.template +0 -67
- package/dist/npm/predefined-packages/admin-ui-templates/AdminConfirmDialog.tsx.template +0 -46
- package/dist/npm/predefined-packages/admin-ui-templates/AdminDataTable.tsx.template +0 -49
- package/dist/npm/predefined-packages/admin-ui-templates/AdminDetailLayout.tsx.template +0 -15
- package/dist/npm/predefined-packages/admin-ui-templates/AdminEmptyState.tsx.template +0 -17
- package/dist/npm/predefined-packages/admin-ui-templates/AdminFilterBar.tsx.template +0 -16
- package/dist/npm/predefined-packages/admin-ui-templates/AdminFormLayout.tsx.template +0 -19
- package/dist/npm/predefined-packages/admin-ui-templates/AdminMembershipManager.tsx.template +0 -56
- package/dist/npm/predefined-packages/admin-ui-templates/AdminPage.tsx.template +0 -19
- package/dist/npm/predefined-packages/admin-ui-templates/AdminPageHeader.tsx.template +0 -19
- package/dist/npm/predefined-packages/admin-ui-templates/AdminPagination.tsx.template +0 -20
- package/dist/npm/predefined-packages/admin-ui-templates/AdminPermissionMatrix.tsx.template +0 -54
- package/dist/npm/predefined-packages/admin-ui-templates/AdminRoleManager.tsx.template +0 -81
- package/dist/npm/predefined-packages/admin-ui-templates/AdminShell.tsx.template +0 -20
- package/dist/npm/predefined-packages/admin-ui-templates/AdminSidebar.tsx.template +0 -18
- package/dist/npm/predefined-packages/admin-ui-templates/AdminStatCard.tsx.template +0 -22
- package/dist/npm/predefined-packages/admin-ui.d.ts +0 -2
- package/dist/npm/predefined-packages/admin-ui.js +0 -83
- package/dist/npm/predefined-packages/auth-templates/README.md.template +0 -9
- package/dist/npm/predefined-packages/auth-templates/convex.ts.template +0 -18
- package/dist/npm/predefined-packages/auth-templates/identity.ts.template +0 -2
- package/dist/npm/predefined-packages/auth-templates/supabase.ts.template +0 -36
- package/dist/npm/predefined-packages/auth.d.ts +0 -2
- package/dist/npm/predefined-packages/auth.js +0 -36
- package/dist/npm/predefined-packages/convex.d.ts +0 -2
- package/dist/npm/predefined-packages/convex.js +0 -53
- package/dist/npm/predefined-packages/expo.d.ts +0 -2
- package/dist/npm/predefined-packages/expo.js +0 -88
- package/dist/npm/predefined-packages/firebase-hosting.d.ts +0 -2
- package/dist/npm/predefined-packages/firebase-hosting.js +0 -24
- package/dist/npm/predefined-packages/health.d.ts +0 -10
- package/dist/npm/predefined-packages/health.js +0 -52
- package/dist/npm/predefined-packages/husky.d.ts +0 -2
- package/dist/npm/predefined-packages/husky.js +0 -57
- package/dist/npm/predefined-packages/index.d.ts +0 -12
- package/dist/npm/predefined-packages/index.js +0 -97
- package/dist/npm/predefined-packages/install.d.ts +0 -19
- package/dist/npm/predefined-packages/install.js +0 -86
- package/dist/npm/predefined-packages/local-logging.d.ts +0 -2
- package/dist/npm/predefined-packages/local-logging.js +0 -17
- package/dist/npm/predefined-packages/logging.d.ts +0 -2
- package/dist/npm/predefined-packages/logging.js +0 -21
- package/dist/npm/predefined-packages/multi-tenancy.d.ts +0 -2
- package/dist/npm/predefined-packages/multi-tenancy.js +0 -37
- package/dist/npm/predefined-packages/nps.d.ts +0 -2
- package/dist/npm/predefined-packages/nps.js +0 -32
- package/dist/npm/predefined-packages/oxfmt.d.ts +0 -2
- package/dist/npm/predefined-packages/oxfmt.js +0 -22
- package/dist/npm/predefined-packages/oxlint.d.ts +0 -2
- package/dist/npm/predefined-packages/oxlint.js +0 -35
- package/dist/npm/predefined-packages/package-json.d.ts +0 -3
- package/dist/npm/predefined-packages/package-json.js +0 -61
- package/dist/npm/predefined-packages/payments.d.ts +0 -2
- package/dist/npm/predefined-packages/payments.js +0 -31
- package/dist/npm/predefined-packages/playwright.d.ts +0 -2
- package/dist/npm/predefined-packages/playwright.js +0 -35
- package/dist/npm/predefined-packages/project-signals.d.ts +0 -4
- package/dist/npm/predefined-packages/project-signals.js +0 -39
- package/dist/npm/predefined-packages/registry.d.ts +0 -3
- package/dist/npm/predefined-packages/registry.js +0 -65
- package/dist/npm/predefined-packages/resolver.d.ts +0 -8
- package/dist/npm/predefined-packages/resolver.js +0 -35
- package/dist/npm/predefined-packages/security-templates/README.md.template +0 -15
- package/dist/npm/predefined-packages/security-templates/convex-authorization.ts.template +0 -109
- package/dist/npm/predefined-packages/security-templates/permissions.ts.template +0 -40
- package/dist/npm/predefined-packages/security-templates/supabase-admin-rpc.sql.template +0 -54
- package/dist/npm/predefined-packages/security-templates/supabase-authorization.sql.template +0 -138
- package/dist/npm/predefined-packages/security-templates/supabase-posts-example.sql.template +0 -39
- package/dist/npm/predefined-packages/sentry.d.ts +0 -2
- package/dist/npm/predefined-packages/sentry.js +0 -29
- package/dist/npm/predefined-packages/shadcn.d.ts +0 -2
- package/dist/npm/predefined-packages/shadcn.js +0 -23
- package/dist/npm/predefined-packages/storybook.d.ts +0 -2
- package/dist/npm/predefined-packages/storybook.js +0 -25
- package/dist/npm/predefined-packages/stryker.d.ts +0 -2
- package/dist/npm/predefined-packages/stryker.js +0 -48
- package/dist/npm/predefined-packages/supabase.d.ts +0 -2
- package/dist/npm/predefined-packages/supabase.js +0 -355
- package/dist/npm/predefined-packages/tailwind.d.ts +0 -2
- package/dist/npm/predefined-packages/tailwind.js +0 -18
- package/dist/npm/predefined-packages/tanstack-form.d.ts +0 -2
- package/dist/npm/predefined-packages/tanstack-form.js +0 -19
- package/dist/npm/predefined-packages/tanstack-query.d.ts +0 -2
- package/dist/npm/predefined-packages/tanstack-query.js +0 -15
- package/dist/npm/predefined-packages/tanstack-router.d.ts +0 -2
- package/dist/npm/predefined-packages/tanstack-router.js +0 -18
- package/dist/npm/predefined-packages/tenant-templates/README.md.template +0 -11
- package/dist/npm/predefined-packages/tenant-templates/tenant-context.ts.template +0 -22
- package/dist/npm/predefined-packages/types.d.ts +0 -38
- package/dist/npm/predefined-packages/types.js +0 -1
- package/dist/npm/predefined-packages/vite.d.ts +0 -2
- package/dist/npm/predefined-packages/vite.js +0 -127
- package/dist/npm/predefined-packages/vitest.d.ts +0 -2
- package/dist/npm/predefined-packages/vitest.js +0 -20
- package/dist/npm/predefined-packages/zod.d.ts +0 -2
- package/dist/npm/predefined-packages/zod.js +0 -18
- package/dist/npm/project-check.d.ts +0 -37
- package/dist/npm/project-check.js +0 -231
- package/dist/npm/project-context.d.ts +0 -52
- package/dist/npm/project-context.js +0 -211
- package/dist/npm/project-install-guard.d.ts +0 -2
- package/dist/npm/project-install-guard.js +0 -51
- package/dist/npm/project-rules.d.ts +0 -25
- package/dist/npm/project-rules.js +0 -106
- package/dist/npm/project-runtime.d.ts +0 -21
- package/dist/npm/project-runtime.js +0 -41
- package/dist/npm/project-status.d.ts +0 -32
- package/dist/npm/project-status.js +0 -70
- package/dist/npm/project-sync.d.ts +0 -7
- package/dist/npm/project-sync.js +0 -143
- package/dist/npm/remote-installer.d.ts +0 -35
- package/dist/npm/remote-installer.js +0 -351
- package/dist/npm/rule-id-migrations.d.ts +0 -6
- package/dist/npm/rule-id-migrations.js +0 -19
- package/dist/npm/slack.d.ts +0 -16
- package/dist/npm/slack.js +0 -135
- package/dist/npm/snapshot/config.d.ts +0 -10
- package/dist/npm/snapshot/config.js +0 -24
- package/dist/npm/snapshot/policy.d.ts +0 -1
- package/dist/npm/snapshot/policy.js +0 -64
- package/dist/npm/snapshot/restore.d.ts +0 -10
- package/dist/npm/snapshot/restore.js +0 -19
- package/dist/npm/snapshot/sql.d.ts +0 -2
- package/dist/npm/snapshot/sql.js +0 -113
- package/dist/npm/snapshot/storage.d.ts +0 -8
- package/dist/npm/snapshot/storage.js +0 -70
- package/dist/npm/snapshot/verify.d.ts +0 -11
- package/dist/npm/snapshot/verify.js +0 -13
- package/dist/npm/snapshot-cli.d.ts +0 -6
- package/dist/npm/snapshot-cli.js +0 -45
- package/dist/npm/state.d.ts +0 -14
- package/dist/npm/state.js +0 -269
- package/dist/npm/supabase-local.d.ts +0 -2
- package/dist/npm/supabase-local.js +0 -63
package/dist/npm/slack.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { readFile, stat } from 'node:fs/promises';
|
|
2
|
-
import { basename, isAbsolute, resolve } from 'node:path';
|
|
3
|
-
import { homedir } from 'node:os';
|
|
4
|
-
function parseArgs(args) {
|
|
5
|
-
if (args[0] !== 'send')
|
|
6
|
-
throw new Error('Usage: specdest slack send [--message text] [--thread timestamp] <files...>');
|
|
7
|
-
let message = 'Development artifacts';
|
|
8
|
-
let thread;
|
|
9
|
-
const paths = [];
|
|
10
|
-
for (let i = 1; i < args.length; i++) {
|
|
11
|
-
if ((args[i] === '--message' || args[i] === '--thread') && args[i + 1]) {
|
|
12
|
-
if (args[i] === '--message')
|
|
13
|
-
message = args[++i];
|
|
14
|
-
else
|
|
15
|
-
thread = args[++i];
|
|
16
|
-
}
|
|
17
|
-
else if (args[i].startsWith('-'))
|
|
18
|
-
throw new Error(`Unknown option: ${args[i]}`);
|
|
19
|
-
else
|
|
20
|
-
paths.push(args[i]);
|
|
21
|
-
}
|
|
22
|
-
if (!paths.length)
|
|
23
|
-
throw new Error('Specify at least one file');
|
|
24
|
-
if (thread && !/^\d+\.\d+$/.test(thread))
|
|
25
|
-
throw new Error('Invalid Slack thread timestamp');
|
|
26
|
-
return { paths, message, thread };
|
|
27
|
-
}
|
|
28
|
-
async function readEnvFile(path) {
|
|
29
|
-
let content;
|
|
30
|
-
try {
|
|
31
|
-
content = await readFile(path, 'utf8');
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
if (error.code === 'ENOENT')
|
|
35
|
-
return {};
|
|
36
|
-
throw error;
|
|
37
|
-
}
|
|
38
|
-
const values = {};
|
|
39
|
-
for (const line of content.split(/\r?\n/)) {
|
|
40
|
-
const match = line.match(/^\s*(?:export\s+)?(SLACK_BOT_TOKEN|SLACK_CHANNEL_ID)=(.*)$/);
|
|
41
|
-
if (match)
|
|
42
|
-
values[match[1]] = match[2].trim().replace(/^['"]|['"]$/g, '');
|
|
43
|
-
}
|
|
44
|
-
return values;
|
|
45
|
-
}
|
|
46
|
-
async function slackCredentials(cwd, env, home) {
|
|
47
|
-
const local = await readEnvFile(resolve(cwd, '.env.e2e.local'));
|
|
48
|
-
const shared = await readEnvFile(resolve(home, '.config/specdest/slack.env'));
|
|
49
|
-
const token = env.SLACK_BOT_TOKEN?.trim() || local.SLACK_BOT_TOKEN || shared.SLACK_BOT_TOKEN;
|
|
50
|
-
if (!token)
|
|
51
|
-
throw new Error('Slack token missing: set SLACK_BOT_TOKEN or configure .env.e2e.local or ~/.config/specdest/slack.env');
|
|
52
|
-
return { token, channel: env.SLACK_CHANNEL_ID?.trim() || local.SLACK_CHANNEL_ID };
|
|
53
|
-
}
|
|
54
|
-
async function slackJson(transport, token, method, params) {
|
|
55
|
-
const response = await transport(`https://slack.com/api/${method}`, {
|
|
56
|
-
method: 'POST',
|
|
57
|
-
headers: {
|
|
58
|
-
Authorization: `Bearer ${token}`,
|
|
59
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
60
|
-
},
|
|
61
|
-
body: new URLSearchParams(params),
|
|
62
|
-
signal: AbortSignal.timeout(30000),
|
|
63
|
-
});
|
|
64
|
-
if (!response.ok)
|
|
65
|
-
throw new Error(`Slack ${method} HTTP ${response.status}`);
|
|
66
|
-
const data = (await response.json());
|
|
67
|
-
if (!data.ok)
|
|
68
|
-
throw new Error(`Slack ${method}: ${data.error ?? 'unknown error'}`);
|
|
69
|
-
return data;
|
|
70
|
-
}
|
|
71
|
-
export async function sendSlackFiles(args, io = process, options = {}) {
|
|
72
|
-
try {
|
|
73
|
-
const { paths, message, thread } = parseArgs(args);
|
|
74
|
-
const cwd = options.cwd ?? process.cwd();
|
|
75
|
-
const env = options.env ?? process.env;
|
|
76
|
-
const { token, channel: envChannel } = await slackCredentials(cwd, env, options.home ?? homedir());
|
|
77
|
-
let projectChannel;
|
|
78
|
-
if (!envChannel) {
|
|
79
|
-
try {
|
|
80
|
-
const configuration = JSON.parse(await readFile(resolve(cwd, '.spd/config.json'), 'utf8'));
|
|
81
|
-
projectChannel = configuration.slack?.channel;
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
if (error.code !== 'ENOENT')
|
|
85
|
-
throw error;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
const channel = envChannel || projectChannel;
|
|
89
|
-
if (typeof channel !== 'string' || !/^[CGD][A-Z0-9]+$/.test(channel))
|
|
90
|
-
throw new Error('Set SLACK_CHANNEL_ID or slack.channel in .spd/config.json');
|
|
91
|
-
const files = await Promise.all(paths.map(async (path) => {
|
|
92
|
-
const absolute = isAbsolute(path) ? path : resolve(cwd, path);
|
|
93
|
-
const metadata = await stat(absolute);
|
|
94
|
-
if (!metadata.isFile() || metadata.size === 0)
|
|
95
|
-
throw new Error(`Not a nonempty file: ${path}`);
|
|
96
|
-
return { name: basename(path), data: await readFile(absolute) };
|
|
97
|
-
}));
|
|
98
|
-
const transport = options.transport ?? fetch;
|
|
99
|
-
const parent = thread ??
|
|
100
|
-
(await slackJson(transport, token, 'chat.postMessage', { channel, text: message })).ts;
|
|
101
|
-
if (!parent)
|
|
102
|
-
throw new Error('Slack did not return a thread timestamp');
|
|
103
|
-
const uploaded = [];
|
|
104
|
-
for (const file of files) {
|
|
105
|
-
const slot = await slackJson(transport, token, 'files.getUploadURLExternal', {
|
|
106
|
-
filename: file.name,
|
|
107
|
-
length: String(file.data.length),
|
|
108
|
-
});
|
|
109
|
-
if (!slot.upload_url || !slot.file_id)
|
|
110
|
-
throw new Error('Slack did not return a file upload URL');
|
|
111
|
-
const response = await transport(slot.upload_url, {
|
|
112
|
-
method: 'POST',
|
|
113
|
-
body: file.data,
|
|
114
|
-
signal: AbortSignal.timeout(60000),
|
|
115
|
-
});
|
|
116
|
-
if (!response.ok)
|
|
117
|
-
throw new Error(`Slack file upload HTTP ${response.status}`);
|
|
118
|
-
uploaded.push({ id: slot.file_id, title: file.name });
|
|
119
|
-
}
|
|
120
|
-
await slackJson(transport, token, 'files.completeUploadExternal', {
|
|
121
|
-
files: JSON.stringify(uploaded),
|
|
122
|
-
channel_id: channel,
|
|
123
|
-
thread_ts: parent,
|
|
124
|
-
...(thread ? { initial_comment: message } : {}),
|
|
125
|
-
});
|
|
126
|
-
for (const file of files)
|
|
127
|
-
io.stdout.write(`Uploaded ${file.name}\n`);
|
|
128
|
-
io.stdout.write(`Slack thread: ${parent}\n`);
|
|
129
|
-
return 0;
|
|
130
|
-
}
|
|
131
|
-
catch (error) {
|
|
132
|
-
io.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
133
|
-
return 1;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/** Declarative, non-secret project configuration. Never authorizes a host operation. */
|
|
2
|
-
export interface SnapshotConfig {
|
|
3
|
-
version: 1;
|
|
4
|
-
project: string;
|
|
5
|
-
policyFile: string;
|
|
6
|
-
storage: {
|
|
7
|
-
buckets: string[];
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
export declare function validateSnapshotConfig(input: unknown): SnapshotConfig;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const identifier = /^[a-z][a-z0-9_-]*$/;
|
|
2
|
-
export function validateSnapshotConfig(input) {
|
|
3
|
-
if (!input || typeof input !== 'object' || Array.isArray(input))
|
|
4
|
-
throw new Error('config must be an object');
|
|
5
|
-
const config = input;
|
|
6
|
-
if (Object.keys(config).some((key) => !['version', 'project', 'policyFile', 'storage'].includes(key)))
|
|
7
|
-
throw new Error('unknown config field');
|
|
8
|
-
if (config.version !== 1)
|
|
9
|
-
throw new Error('unsupported config version');
|
|
10
|
-
if (typeof config.project !== 'string' || !identifier.test(config.project))
|
|
11
|
-
throw new Error('invalid project');
|
|
12
|
-
if (typeof config.policyFile !== 'string' || !/^[a-z][a-z0-9_.-]*\.json$/.test(config.policyFile))
|
|
13
|
-
throw new Error('invalid policyFile');
|
|
14
|
-
const storage = config.storage;
|
|
15
|
-
if (!storage || typeof storage !== 'object' || Array.isArray(storage))
|
|
16
|
-
throw new Error('invalid storage');
|
|
17
|
-
const s = storage;
|
|
18
|
-
if (Object.keys(s).some((key) => key !== 'buckets') ||
|
|
19
|
-
!Array.isArray(s.buckets) ||
|
|
20
|
-
s.buckets.some((v) => typeof v !== 'string' || !identifier.test(v)) ||
|
|
21
|
-
new Set(s.buckets).size !== s.buckets.length)
|
|
22
|
-
throw new Error('invalid storage buckets');
|
|
23
|
-
return input;
|
|
24
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function validateMaskPolicy(policy: unknown, observed: Record<string, string[]>, project: string): true;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/** Fail-closed policy coverage checks. These do not constitute privacy approval. */
|
|
2
|
-
const safeName = /^[a-z_][a-z0-9_]*$/;
|
|
3
|
-
const sensitive = /(token(?!_expires_at)|secret|password|email|phone|credential|oauth|api_key|authorization|auth_data|refresh_key|access_key)/i;
|
|
4
|
-
const transforms = new Set([
|
|
5
|
-
'keep',
|
|
6
|
-
'null',
|
|
7
|
-
'pseudonym',
|
|
8
|
-
'email',
|
|
9
|
-
'phone',
|
|
10
|
-
'constant',
|
|
11
|
-
'json_object',
|
|
12
|
-
'json_array',
|
|
13
|
-
'uuid_array',
|
|
14
|
-
'empty_text_array',
|
|
15
|
-
'empty_uuid_array',
|
|
16
|
-
'allow_values',
|
|
17
|
-
'disable',
|
|
18
|
-
]);
|
|
19
|
-
const object = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
20
|
-
const equalKeys = (a, b) => a.length === b.length && a.every((v) => b.includes(v));
|
|
21
|
-
export function validateMaskPolicy(policy, observed, project) {
|
|
22
|
-
if (!object(policy) ||
|
|
23
|
-
!equalKeys(Object.keys(policy), ['format', 'project', 'tables']) ||
|
|
24
|
-
policy.format !== 1 ||
|
|
25
|
-
policy.project !== project)
|
|
26
|
-
throw new Error('invalid policy format or project');
|
|
27
|
-
if (!object(policy.tables) ||
|
|
28
|
-
!Object.keys(policy.tables).length ||
|
|
29
|
-
!equalKeys(Object.keys(policy.tables), Object.keys(observed)))
|
|
30
|
-
throw new Error('table coverage mismatch');
|
|
31
|
-
for (const [table, columns] of Object.entries(observed)) {
|
|
32
|
-
if (!safeName.test(table) || !columns.length || columns.some((c) => !safeName.test(c)))
|
|
33
|
-
throw new Error('invalid inventory');
|
|
34
|
-
const def = policy.tables[table];
|
|
35
|
-
if (!object(def) ||
|
|
36
|
-
!equalKeys(Object.keys(def), ['columns']) ||
|
|
37
|
-
!object(def.columns) ||
|
|
38
|
-
!equalKeys(Object.keys(def.columns), columns))
|
|
39
|
-
throw new Error(`column coverage mismatch: ${table}`);
|
|
40
|
-
for (const [column, raw] of Object.entries(def.columns)) {
|
|
41
|
-
if (!object(raw) ||
|
|
42
|
-
typeof raw.transform !== 'string' ||
|
|
43
|
-
!transforms.has(raw.transform) ||
|
|
44
|
-
Object.keys(raw).some((k) => !['transform', 'value', 'values'].includes(k)))
|
|
45
|
-
throw new Error(`invalid transform: ${table}.${column}`);
|
|
46
|
-
if (raw.transform === 'allow_values'
|
|
47
|
-
? !Array.isArray(raw.values) ||
|
|
48
|
-
raw.values.length < 1 ||
|
|
49
|
-
raw.values.length > 64 ||
|
|
50
|
-
raw.values.some((v) => typeof v !== 'string' || !v || v.length > 100) ||
|
|
51
|
-
new Set(raw.values).size !== raw.values.length ||
|
|
52
|
-
'value' in raw
|
|
53
|
-
: 'values' in raw)
|
|
54
|
-
throw new Error(`invalid transform allowlist: ${table}.${column}`);
|
|
55
|
-
if (raw.transform === 'constant'
|
|
56
|
-
? typeof raw.value !== 'string' || raw.value.length > 256
|
|
57
|
-
: 'value' in raw)
|
|
58
|
-
throw new Error(`invalid transform options: ${table}.${column}`);
|
|
59
|
-
if (raw.transform === 'keep' && sensitive.test(column))
|
|
60
|
-
throw new Error(`sensitive column cannot be kept: ${table}.${column}`);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/** A plan is descriptive only. Controller must independently authorize every step. */
|
|
2
|
-
export interface RestorePreflight {
|
|
3
|
-
config: unknown;
|
|
4
|
-
snapshotProject: string;
|
|
5
|
-
targetProject: string;
|
|
6
|
-
targetKind: 'local' | 'remote';
|
|
7
|
-
targetPopulated: boolean;
|
|
8
|
-
backupAvailable: boolean;
|
|
9
|
-
}
|
|
10
|
-
export declare function planLocalRestore(input: RestorePreflight): readonly string[];
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { validateSnapshotConfig } from "./config.js";
|
|
2
|
-
export function planLocalRestore(input) {
|
|
3
|
-
const config = validateSnapshotConfig(input.config);
|
|
4
|
-
if (input.snapshotProject !== config.project)
|
|
5
|
-
throw new Error('wrong snapshot project');
|
|
6
|
-
if (input.targetProject !== config.project)
|
|
7
|
-
throw new Error('mismatched restore target');
|
|
8
|
-
if (input.targetKind !== 'local')
|
|
9
|
-
throw new Error('remote restore forbidden');
|
|
10
|
-
if (input.targetPopulated && !input.backupAvailable)
|
|
11
|
-
throw new Error('populated target requires backup');
|
|
12
|
-
return Object.freeze([
|
|
13
|
-
'verify approved sanitized snapshot and target identity on trusted host',
|
|
14
|
-
'capture verified local-target backup before any mutation',
|
|
15
|
-
'restore to isolated local staging with transactional SQL validation',
|
|
16
|
-
'verify database and Storage referential integrity',
|
|
17
|
-
'promote only after approval; on failure roll back from verified backup',
|
|
18
|
-
]);
|
|
19
|
-
}
|
package/dist/npm/snapshot/sql.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/** Fixture-only allowlist for sanitized INSERT-format SQL; never executes SQL. */
|
|
2
|
-
const sessions = new Set([
|
|
3
|
-
'SET statement_timeout = 0;',
|
|
4
|
-
'SET lock_timeout = 0;',
|
|
5
|
-
'SET transaction_timeout = 0;',
|
|
6
|
-
'SET idle_in_transaction_session_timeout = 0;',
|
|
7
|
-
"SET client_encoding = 'UTF8';",
|
|
8
|
-
'SET standard_conforming_strings = on;',
|
|
9
|
-
'SET check_function_bodies = false;',
|
|
10
|
-
'SET xmloption = content;',
|
|
11
|
-
'SET client_min_messages = warning;',
|
|
12
|
-
'SET row_security = off;',
|
|
13
|
-
"SET default_tablespace = '';",
|
|
14
|
-
'SET default_table_access_method = heap;',
|
|
15
|
-
"SET search_path = '';",
|
|
16
|
-
]);
|
|
17
|
-
const insert = /^INSERT INTO public\."?[a-z_][a-z0-9_]*"?\s*(?:\([^;]*\)\s*)?(?:OVERRIDING SYSTEM VALUE\s+)?VALUES\s*\(.+\);$/is;
|
|
18
|
-
const sequence = /^SELECT pg_catalog\.setval\('public\.(?:[a-z_][a-z0-9_]*|"[a-z_][a-z0-9_]*")'(?:::regclass)?,\s*-?[0-9]+,\s*(?:true|false)\);$/i;
|
|
19
|
-
/** Replace quoted text while preserving all unquoted syntax. */
|
|
20
|
-
function neutralize(source) {
|
|
21
|
-
let result = '';
|
|
22
|
-
for (let i = 0; i < source.length; i++) {
|
|
23
|
-
if (source[i] !== "'") {
|
|
24
|
-
result += source[i];
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
result += "'text'";
|
|
28
|
-
let closed = false;
|
|
29
|
-
while (++i < source.length) {
|
|
30
|
-
if (source[i] !== "'")
|
|
31
|
-
continue;
|
|
32
|
-
if (source[i + 1] === "'") {
|
|
33
|
-
i++;
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
closed = true;
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
if (!closed)
|
|
40
|
-
throw new Error('unclosed SQL string literal');
|
|
41
|
-
}
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
function statements(source, native) {
|
|
45
|
-
const found = [];
|
|
46
|
-
let buffer = [];
|
|
47
|
-
for (const raw of source.split(/\r?\n/)) {
|
|
48
|
-
const line = raw.trim();
|
|
49
|
-
if (!buffer.length &&
|
|
50
|
-
(!line ||
|
|
51
|
-
line.startsWith('--') ||
|
|
52
|
-
(native && (line.startsWith('\\restrict ') || line.startsWith('\\unrestrict ')))))
|
|
53
|
-
continue;
|
|
54
|
-
buffer.push(raw);
|
|
55
|
-
const statement = buffer.join('\n').trim();
|
|
56
|
-
let syntax;
|
|
57
|
-
try {
|
|
58
|
-
syntax = neutralize(statement);
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
if (error instanceof Error && error.message === 'unclosed SQL string literal')
|
|
62
|
-
continue;
|
|
63
|
-
throw error;
|
|
64
|
-
}
|
|
65
|
-
const semicolons = syntax.match(/;/g)?.length ?? 0;
|
|
66
|
-
if (semicolons > 1 || (semicolons === 1 && !syntax.endsWith(';')))
|
|
67
|
-
throw new Error('extra SQL statement');
|
|
68
|
-
if (semicolons === 1) {
|
|
69
|
-
found.push(statement);
|
|
70
|
-
buffer = [];
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (buffer.length)
|
|
74
|
-
throw new Error('unterminated SQL statement');
|
|
75
|
-
return found;
|
|
76
|
-
}
|
|
77
|
-
function assertInsert(statement) {
|
|
78
|
-
if (!insert.test(statement))
|
|
79
|
-
throw new Error('unsupported restore SQL');
|
|
80
|
-
const syntax = neutralize(statement);
|
|
81
|
-
if ((syntax.match(/;/g)?.length ?? 0) !== 1 ||
|
|
82
|
-
/\\|\$\$|\/\*|\*\/|--|\b(SELECT|DO|COPY|ALTER|CREATE|DROP|EXECUTE|PERFORM)\b/i.test(syntax))
|
|
83
|
-
throw new Error('unsafe restore SQL');
|
|
84
|
-
const values = syntax.split(/\bVALUES\s*\(/i);
|
|
85
|
-
if (values.length !== 2 || /\b[a-z_][a-z0-9_]*\s*\(/i.test(values[1]))
|
|
86
|
-
throw new Error('nonliteral restore SQL');
|
|
87
|
-
}
|
|
88
|
-
export function validateRestoreSql(source) {
|
|
89
|
-
let count = 0;
|
|
90
|
-
for (const statement of statements(source, false)) {
|
|
91
|
-
if (sessions.has(statement) || sequence.test(statement))
|
|
92
|
-
continue;
|
|
93
|
-
assertInsert(statement);
|
|
94
|
-
count++;
|
|
95
|
-
}
|
|
96
|
-
if (!count)
|
|
97
|
-
throw new Error('no INSERT statements');
|
|
98
|
-
return count;
|
|
99
|
-
}
|
|
100
|
-
export function normalizePgDump(source) {
|
|
101
|
-
const kept = [];
|
|
102
|
-
for (const statement of statements(source, true)) {
|
|
103
|
-
if (sessions.has(statement) ||
|
|
104
|
-
statement === "SELECT pg_catalog.set_config('search_path', '', false);")
|
|
105
|
-
continue;
|
|
106
|
-
if (!insert.test(statement) && !sequence.test(statement))
|
|
107
|
-
throw new Error('unsupported native dump statement');
|
|
108
|
-
kept.push(statement);
|
|
109
|
-
}
|
|
110
|
-
const normalized = kept.join('\n') + '\n';
|
|
111
|
-
validateRestoreSql(normalized);
|
|
112
|
-
return normalized;
|
|
113
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export declare function validateStorageManifest(input: unknown, allowedBuckets: readonly string[], project: string): true;
|
|
2
|
-
/** Compare trusted-runner digest inventories without reading Storage objects. */
|
|
3
|
-
export declare function reconcileStorageObjects(expected: unknown, actual: unknown, allowedBuckets: readonly string[], project: string): true;
|
|
4
|
-
/** Cross-check sanitized Storage metadata against the object bundle. */
|
|
5
|
-
export declare function reconcileStorageMetadata(manifest: unknown, references: readonly {
|
|
6
|
-
bucket: string;
|
|
7
|
-
path: string;
|
|
8
|
-
}[], allowedBuckets: readonly string[], project: string): true;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
2
|
-
const keys = (value, expected) => Object.keys(value).length === expected.length &&
|
|
3
|
-
Object.keys(value).every((key) => expected.includes(key));
|
|
4
|
-
const validPath = (path) => path.length > 0 &&
|
|
5
|
-
path.length <= 1024 &&
|
|
6
|
-
!path.startsWith('/') &&
|
|
7
|
-
!path.includes('\\') &&
|
|
8
|
-
![...path].some((ch) => ch.charCodeAt(0) < 32 || ch.charCodeAt(0) === 127 || '?#%'.includes(ch)) &&
|
|
9
|
-
!path.split('/').some((part) => part === '' || part === '.' || part === '..');
|
|
10
|
-
export function validateStorageManifest(input, allowedBuckets, project) {
|
|
11
|
-
if (!isRecord(input) || !keys(input, ['version', 'project', 'objects']))
|
|
12
|
-
throw new Error('invalid manifest fields');
|
|
13
|
-
if (input.version !== 1 || input.project !== project)
|
|
14
|
-
throw new Error('manifest project/version mismatch');
|
|
15
|
-
if (!Array.isArray(input.objects) || input.objects.length > 3000)
|
|
16
|
-
throw new Error('invalid objects');
|
|
17
|
-
const seen = new Set();
|
|
18
|
-
for (const value of input.objects) {
|
|
19
|
-
if (!isRecord(value) || !keys(value, ['bucket', 'path', 'sha256', 'bytes']))
|
|
20
|
-
throw new Error('invalid object fields');
|
|
21
|
-
const entry = value;
|
|
22
|
-
if (typeof entry.bucket !== 'string' || !allowedBuckets.includes(entry.bucket))
|
|
23
|
-
throw new Error('unapproved bucket');
|
|
24
|
-
if (typeof entry.path !== 'string' || !validPath(entry.path))
|
|
25
|
-
throw new Error('unsafe object path');
|
|
26
|
-
if (typeof entry.sha256 !== 'string' || !/^[a-f0-9]{64}$/.test(entry.sha256))
|
|
27
|
-
throw new Error('invalid hash');
|
|
28
|
-
if (!Number.isSafeInteger(entry.bytes) || entry.bytes < 0)
|
|
29
|
-
throw new Error('invalid byte length');
|
|
30
|
-
const key = JSON.stringify([entry.bucket, entry.path]);
|
|
31
|
-
if (seen.has(key))
|
|
32
|
-
throw new Error('duplicate storage object');
|
|
33
|
-
seen.add(key);
|
|
34
|
-
}
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
/** Compare trusted-runner digest inventories without reading Storage objects. */
|
|
38
|
-
export function reconcileStorageObjects(expected, actual, allowedBuckets, project) {
|
|
39
|
-
validateStorageManifest(expected, allowedBuckets, project);
|
|
40
|
-
validateStorageManifest(actual, allowedBuckets, project);
|
|
41
|
-
if (!isRecord(expected) || !isRecord(actual))
|
|
42
|
-
throw new Error('invalid manifest');
|
|
43
|
-
const planned = expected.objects;
|
|
44
|
-
const observed = actual.objects;
|
|
45
|
-
const byKey = new Map(observed.map((entry) => [JSON.stringify([entry.bucket, entry.path]), entry]));
|
|
46
|
-
if (planned.length !== observed.length)
|
|
47
|
-
throw new Error('storage object count mismatch');
|
|
48
|
-
for (const entry of planned) {
|
|
49
|
-
const match = byKey.get(JSON.stringify([entry.bucket, entry.path]));
|
|
50
|
-
if (!match)
|
|
51
|
-
throw new Error('missing storage object');
|
|
52
|
-
if (entry.sha256 !== match.sha256 || entry.bytes !== match.bytes)
|
|
53
|
-
throw new Error('modified storage object');
|
|
54
|
-
}
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
/** Cross-check sanitized Storage metadata against the object bundle. */
|
|
58
|
-
export function reconcileStorageMetadata(manifest, references, allowedBuckets, project) {
|
|
59
|
-
validateStorageManifest(manifest, allowedBuckets, project);
|
|
60
|
-
if (!isRecord(manifest))
|
|
61
|
-
throw new Error('invalid manifest');
|
|
62
|
-
const objects = manifest.objects;
|
|
63
|
-
const expected = new Set(objects.map((item) => JSON.stringify([item.bucket, item.path])));
|
|
64
|
-
const observed = new Set(references.map((item) => JSON.stringify([item.bucket, item.path])));
|
|
65
|
-
if (observed.size !== references.length)
|
|
66
|
-
throw new Error('duplicate storage metadata');
|
|
67
|
-
if (observed.size !== expected.size || [...expected].some((key) => !observed.has(key)))
|
|
68
|
-
throw new Error('storage DB manifest mismatch');
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export interface SnapshotVerificationInput {
|
|
2
|
-
config: unknown;
|
|
3
|
-
policy: unknown;
|
|
4
|
-
inventory: Record<string, string[]>;
|
|
5
|
-
storageManifest: unknown;
|
|
6
|
-
sanitizedSql: string;
|
|
7
|
-
}
|
|
8
|
-
export declare function verifySnapshotArtifacts(input: SnapshotVerificationInput): {
|
|
9
|
-
project: string;
|
|
10
|
-
verifiedInserts: number;
|
|
11
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/** Nonprivileged, offline snapshot artifact verification. Never connects to production. */
|
|
2
|
-
import { validateSnapshotConfig } from "./config.js";
|
|
3
|
-
import { validateMaskPolicy } from "./policy.js";
|
|
4
|
-
import { validateStorageManifest } from "./storage.js";
|
|
5
|
-
import { validateRestoreSql } from "./sql.js";
|
|
6
|
-
export function verifySnapshotArtifacts(input) {
|
|
7
|
-
const config = validateSnapshotConfig(input.config);
|
|
8
|
-
// Policy must explicitly cover every observed table and column; partial policies fail.
|
|
9
|
-
validateMaskPolicy(input.policy, input.inventory, config.project);
|
|
10
|
-
validateStorageManifest(input.storageManifest, config.storage.buckets, config.project);
|
|
11
|
-
const verifiedInserts = validateRestoreSql(input.sanitizedSql);
|
|
12
|
-
return { project: config.project, verifiedInserts };
|
|
13
|
-
}
|
package/dist/npm/snapshot-cli.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/** Offline validation of a trusted-runner-produced sanitized artifact bundle. */
|
|
3
|
-
import { readFileSync, lstatSync } from 'node:fs';
|
|
4
|
-
import { resolve, join } from 'node:path';
|
|
5
|
-
import { verifySnapshotArtifacts } from "./snapshot/verify.js";
|
|
6
|
-
import { reconcileStorageObjects, reconcileStorageMetadata } from "./snapshot/storage.js";
|
|
7
|
-
import { validateSnapshotConfig } from "./snapshot/config.js";
|
|
8
|
-
export function verifyBundle(directory) {
|
|
9
|
-
const root = resolve(directory);
|
|
10
|
-
function read(name) {
|
|
11
|
-
const path = join(root, name);
|
|
12
|
-
if (lstatSync(path).isSymbolicLink())
|
|
13
|
-
throw new Error('symlinked snapshot input');
|
|
14
|
-
return readFileSync(path, 'utf8');
|
|
15
|
-
}
|
|
16
|
-
function json(name) {
|
|
17
|
-
return JSON.parse(read(name));
|
|
18
|
-
}
|
|
19
|
-
const config = validateSnapshotConfig(json('config.json'));
|
|
20
|
-
const input = {
|
|
21
|
-
config,
|
|
22
|
-
policy: json(config.policyFile),
|
|
23
|
-
inventory: json('inventory.json'),
|
|
24
|
-
storageManifest: json('storage-manifest.json'),
|
|
25
|
-
sanitizedSql: read('sanitized.sql'),
|
|
26
|
-
};
|
|
27
|
-
const result = verifySnapshotArtifacts(input);
|
|
28
|
-
reconcileStorageObjects(input.storageManifest, json('storage-observed.json'), config.storage.buckets, config.project);
|
|
29
|
-
reconcileStorageMetadata(input.storageManifest, json('storage-references.json'), config.storage.buckets, config.project);
|
|
30
|
-
return result;
|
|
31
|
-
}
|
|
32
|
-
export async function runSnapshot(args, io = process) {
|
|
33
|
-
if (args.length !== 2 || args[0] !== 'verify') {
|
|
34
|
-
io.stderr.write('Usage: specdest snapshot verify <offline-bundle-directory>\n');
|
|
35
|
-
return 2;
|
|
36
|
-
}
|
|
37
|
-
try {
|
|
38
|
-
io.stdout.write(JSON.stringify(verifyBundle(args[1])) + '\n');
|
|
39
|
-
return 0;
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
io.stderr.write('Snapshot verification rejected\n');
|
|
43
|
-
return 1;
|
|
44
|
-
}
|
|
45
|
-
}
|
package/dist/npm/state.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare const STATE_SCHEMA_VERSION = 2;
|
|
2
|
-
export declare const CHECKS_SCHEMA_VERSION = 2;
|
|
3
|
-
export declare const METADATA_DIRECTORY = ".spd";
|
|
4
|
-
export declare const LEGACY_METADATA_DIRECTORY = ".specdest";
|
|
5
|
-
export declare const INSTALLED_RELATIVE_PATH = ".spd/installed.json";
|
|
6
|
-
export declare const STATE_RELATIVE_PATH = ".spd/state.json";
|
|
7
|
-
export declare const CHECKS_RELATIVE_PATH = ".spd/state.json";
|
|
8
|
-
export declare const LEGACY_CHECKS_RELATIVE_PATH = ".spd/checks.json";
|
|
9
|
-
export declare function formatJsonState(value: unknown): string;
|
|
10
|
-
export declare function ensureMetadataNamespace(projectRoot: string): Promise<void>;
|
|
11
|
-
export declare function readInstalledState(projectRoot: string): Promise<any>;
|
|
12
|
-
export declare function writeInstalledState(projectRoot: string, state: any): Promise<void>;
|
|
13
|
-
export declare function readChecksState(projectRoot: string): Promise<any>;
|
|
14
|
-
export declare function writeChecksState(projectRoot: string, state: any): Promise<void>;
|