@ucptools/validator 1.0.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/CLAUDE.md +109 -0
- package/CONTRIBUTING.md +113 -0
- package/LICENSE +21 -0
- package/README.md +203 -0
- package/api/analyze-feed.js +140 -0
- package/api/badge.js +185 -0
- package/api/benchmark.js +177 -0
- package/api/directory-stats.ts +29 -0
- package/api/directory.ts +73 -0
- package/api/generate-compliance.js +143 -0
- package/api/generate-schema.js +457 -0
- package/api/generate.js +132 -0
- package/api/security-scan.js +133 -0
- package/api/simulate.js +187 -0
- package/api/tsconfig.json +10 -0
- package/api/validate.js +1351 -0
- package/apify-actor/.actor/actor.json +68 -0
- package/apify-actor/.actor/input_schema.json +32 -0
- package/apify-actor/APIFY-STORE-LISTING.md +412 -0
- package/apify-actor/Dockerfile +8 -0
- package/apify-actor/README.md +166 -0
- package/apify-actor/main.ts +111 -0
- package/apify-actor/package.json +17 -0
- package/apify-actor/src/main.js +199 -0
- package/docs/BRAND-IDENTITY.md +238 -0
- package/docs/BRAND-STYLE-GUIDE.md +356 -0
- package/drizzle/0000_black_king_cobra.sql +39 -0
- package/drizzle/meta/0000_snapshot.json +309 -0
- package/drizzle/meta/_journal.json +13 -0
- package/drizzle.config.ts +10 -0
- package/examples/full-profile.json +70 -0
- package/examples/minimal-profile.json +23 -0
- package/package.json +69 -0
- package/public/.well-known/ucp +25 -0
- package/public/android-chrome-192x192.png +0 -0
- package/public/android-chrome-512x512.png +0 -0
- package/public/apple-touch-icon.png +0 -0
- package/public/brand.css +321 -0
- package/public/directory.html +701 -0
- package/public/favicon-16x16.png +0 -0
- package/public/favicon-32x32.png +0 -0
- package/public/favicon.ico +0 -0
- package/public/guides/bigcommerce.html +743 -0
- package/public/guides/fastucp.html +838 -0
- package/public/guides/magento.html +779 -0
- package/public/guides/shopify.html +726 -0
- package/public/guides/squarespace.html +749 -0
- package/public/guides/wix.html +747 -0
- package/public/guides/woocommerce.html +733 -0
- package/public/index.html +3835 -0
- package/public/learn.html +396 -0
- package/public/logo.jpeg +0 -0
- package/public/og-image-icon.png +0 -0
- package/public/og-image.png +0 -0
- package/public/robots.txt +6 -0
- package/public/site.webmanifest +31 -0
- package/public/sitemap.xml +69 -0
- package/public/social/linkedin-banner-1128x191.png +0 -0
- package/public/social/temp.PNG +0 -0
- package/public/social/x-header-1500x500.png +0 -0
- package/public/verify.html +410 -0
- package/scripts/generate-favicons.js +44 -0
- package/scripts/generate-ico.js +23 -0
- package/scripts/generate-og-image.js +45 -0
- package/scripts/reset-db.ts +77 -0
- package/scripts/seed-db.ts +71 -0
- package/scripts/setup-benchmark-db.js +70 -0
- package/src/api/server.ts +266 -0
- package/src/cli/index.ts +302 -0
- package/src/compliance/compliance-generator.ts +452 -0
- package/src/compliance/index.ts +28 -0
- package/src/compliance/templates.ts +338 -0
- package/src/compliance/types.ts +170 -0
- package/src/db/index.ts +28 -0
- package/src/db/schema.ts +84 -0
- package/src/feed-analyzer/feed-analyzer.ts +726 -0
- package/src/feed-analyzer/index.ts +34 -0
- package/src/feed-analyzer/types.ts +354 -0
- package/src/generator/index.ts +7 -0
- package/src/generator/key-generator.ts +124 -0
- package/src/generator/profile-builder.ts +402 -0
- package/src/hosting/artifacts-generator.ts +679 -0
- package/src/hosting/index.ts +6 -0
- package/src/index.ts +105 -0
- package/src/security/index.ts +15 -0
- package/src/security/security-scanner.ts +604 -0
- package/src/security/types.ts +55 -0
- package/src/services/directory.ts +434 -0
- package/src/simulator/agent-simulator.ts +941 -0
- package/src/simulator/index.ts +7 -0
- package/src/simulator/types.ts +170 -0
- package/src/types/generator.ts +140 -0
- package/src/types/index.ts +7 -0
- package/src/types/ucp-profile.ts +140 -0
- package/src/types/validation.ts +89 -0
- package/src/validator/index.ts +194 -0
- package/src/validator/network-validator.ts +417 -0
- package/src/validator/rules-validator.ts +297 -0
- package/src/validator/sdk-validator.ts +330 -0
- package/src/validator/structural-validator.ts +476 -0
- package/tests/fixtures/non-compliant-profile.json +25 -0
- package/tests/fixtures/official-sample-profile.json +75 -0
- package/tests/integration/benchmark.test.ts +207 -0
- package/tests/integration/database.test.ts +163 -0
- package/tests/integration/directory-api.test.ts +268 -0
- package/tests/integration/simulate-api.test.ts +230 -0
- package/tests/integration/validate-api.test.ts +269 -0
- package/tests/setup.ts +15 -0
- package/tests/unit/agent-simulator.test.ts +575 -0
- package/tests/unit/compliance-generator.test.ts +374 -0
- package/tests/unit/directory-service.test.ts +272 -0
- package/tests/unit/feed-analyzer.test.ts +517 -0
- package/tests/unit/lint-suggestions.test.ts +423 -0
- package/tests/unit/official-samples.test.ts +211 -0
- package/tests/unit/pdf-report.test.ts +390 -0
- package/tests/unit/sdk-validator.test.ts +531 -0
- package/tests/unit/security-scanner.test.ts +410 -0
- package/tests/unit/validation.test.ts +390 -0
- package/tsconfig.json +20 -0
- package/vercel.json +34 -0
- package/vitest.config.ts +22 -0
package/api/badge.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vercel Serverless Function: Generate AI Commerce Ready Badge
|
|
3
|
+
* GET /api/badge?domain=example.com&style=flat
|
|
4
|
+
*
|
|
5
|
+
* Returns an SVG badge showing the AI readiness grade
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const GRADE_COLORS = {
|
|
9
|
+
A: { bg: '#16A34A', text: '#DCFCE7' },
|
|
10
|
+
B: { bg: '#2563EB', text: '#DBEAFE' },
|
|
11
|
+
C: { bg: '#CA8A04', text: '#FEF9C3' },
|
|
12
|
+
D: { bg: '#EA580C', text: '#FED7AA' },
|
|
13
|
+
F: { bg: '#DC2626', text: '#FEE2E2' },
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const READINESS_LABELS = {
|
|
17
|
+
A: 'AI Commerce Ready',
|
|
18
|
+
B: 'Mostly Ready',
|
|
19
|
+
C: 'Partially Ready',
|
|
20
|
+
D: 'Limited Readiness',
|
|
21
|
+
F: 'Not Ready',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function generateFlatBadge(grade, domain, score) {
|
|
25
|
+
const colors = GRADE_COLORS[grade] || GRADE_COLORS.F;
|
|
26
|
+
const label = READINESS_LABELS[grade] || 'Not Ready';
|
|
27
|
+
|
|
28
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="180" height="20" role="img" aria-label="AI Commerce: ${grade}">
|
|
29
|
+
<title>AI Commerce: Grade ${grade} - ${label}</title>
|
|
30
|
+
<linearGradient id="s" x2="0" y2="100%">
|
|
31
|
+
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
|
|
32
|
+
<stop offset="1" stop-opacity=".1"/>
|
|
33
|
+
</linearGradient>
|
|
34
|
+
<clipPath id="r">
|
|
35
|
+
<rect width="180" height="20" rx="3" fill="#fff"/>
|
|
36
|
+
</clipPath>
|
|
37
|
+
<g clip-path="url(#r)">
|
|
38
|
+
<rect width="95" height="20" fill="#555"/>
|
|
39
|
+
<rect x="95" width="85" height="20" fill="${colors.bg}"/>
|
|
40
|
+
<rect width="180" height="20" fill="url(#s)"/>
|
|
41
|
+
</g>
|
|
42
|
+
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="11">
|
|
43
|
+
<text x="48.5" y="14">AI Commerce</text>
|
|
44
|
+
<text x="137.5" y="14" font-weight="bold">${grade} ${score}/100</text>
|
|
45
|
+
</g>
|
|
46
|
+
</svg>`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function generateFlatSquareBadge(grade, domain, score) {
|
|
50
|
+
const colors = GRADE_COLORS[grade] || GRADE_COLORS.F;
|
|
51
|
+
const label = READINESS_LABELS[grade] || 'Not Ready';
|
|
52
|
+
|
|
53
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="180" height="20" role="img" aria-label="AI Commerce: ${grade}">
|
|
54
|
+
<title>AI Commerce: Grade ${grade} - ${label}</title>
|
|
55
|
+
<g shape-rendering="crispEdges">
|
|
56
|
+
<rect width="95" height="20" fill="#555"/>
|
|
57
|
+
<rect x="95" width="85" height="20" fill="${colors.bg}"/>
|
|
58
|
+
</g>
|
|
59
|
+
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="11">
|
|
60
|
+
<text x="48.5" y="14">AI Commerce</text>
|
|
61
|
+
<text x="137.5" y="14" font-weight="bold">${grade} ${score}/100</text>
|
|
62
|
+
</g>
|
|
63
|
+
</svg>`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function generateLargeBadge(grade, domain, score) {
|
|
67
|
+
const colors = GRADE_COLORS[grade] || GRADE_COLORS.F;
|
|
68
|
+
const label = READINESS_LABELS[grade] || 'Not Ready';
|
|
69
|
+
|
|
70
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="200" height="80" role="img" aria-label="AI Commerce Ready: ${grade}">
|
|
71
|
+
<title>AI Commerce: Grade ${grade} - ${label}</title>
|
|
72
|
+
<defs>
|
|
73
|
+
<linearGradient id="grad" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
74
|
+
<stop offset="0%" style="stop-color:#2E86AB;stop-opacity:1" />
|
|
75
|
+
<stop offset="50%" style="stop-color:#36B5A2;stop-opacity:1" />
|
|
76
|
+
<stop offset="100%" style="stop-color:#47C97A;stop-opacity:1" />
|
|
77
|
+
</linearGradient>
|
|
78
|
+
</defs>
|
|
79
|
+
<rect width="200" height="80" rx="8" fill="#1A2B3C"/>
|
|
80
|
+
<rect x="2" y="2" width="196" height="76" rx="6" fill="none" stroke="url(#grad)" stroke-width="2"/>
|
|
81
|
+
|
|
82
|
+
<!-- Grade circle -->
|
|
83
|
+
<circle cx="40" cy="40" r="25" fill="${colors.bg}"/>
|
|
84
|
+
<text x="40" y="47" text-anchor="middle" font-family="Verdana,Geneva,sans-serif" font-size="24" font-weight="bold" fill="#fff">${grade}</text>
|
|
85
|
+
|
|
86
|
+
<!-- Text -->
|
|
87
|
+
<text x="75" y="30" font-family="Verdana,Geneva,sans-serif" font-size="11" fill="#94A3B8">AI Commerce</text>
|
|
88
|
+
<text x="75" y="48" font-family="Verdana,Geneva,sans-serif" font-size="14" font-weight="bold" fill="#fff">${label}</text>
|
|
89
|
+
<text x="75" y="65" font-family="Verdana,Geneva,sans-serif" font-size="10" fill="#94A3B8">Score: ${score}/100 • ucptools.dev</text>
|
|
90
|
+
</svg>`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function generateMiniBadge(grade) {
|
|
94
|
+
const colors = GRADE_COLORS[grade] || GRADE_COLORS.F;
|
|
95
|
+
|
|
96
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="40" height="20" role="img" aria-label="Grade ${grade}">
|
|
97
|
+
<title>AI Commerce Grade ${grade}</title>
|
|
98
|
+
<rect width="40" height="20" rx="3" fill="${colors.bg}"/>
|
|
99
|
+
<text x="20" y="14" text-anchor="middle" font-family="Verdana,Geneva,sans-serif" font-size="11" font-weight="bold" fill="#fff">${grade}</text>
|
|
100
|
+
</svg>`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export default async function handler(req, res) {
|
|
104
|
+
// CORS headers
|
|
105
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
106
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
|
|
107
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
|
108
|
+
res.setHeader('Cache-Control', 'public, max-age=3600'); // Cache for 1 hour
|
|
109
|
+
|
|
110
|
+
if (req.method === 'OPTIONS') {
|
|
111
|
+
return res.status(200).end();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (req.method !== 'GET') {
|
|
115
|
+
return res.status(405).json({ error: 'Method not allowed' });
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const { domain, style = 'flat', grade: staticGrade, score: staticScore } = req.query;
|
|
119
|
+
|
|
120
|
+
// If static grade provided (for previews), use that
|
|
121
|
+
if (staticGrade) {
|
|
122
|
+
const grade = staticGrade.toUpperCase();
|
|
123
|
+
const score = parseInt(staticScore) || (grade === 'A' ? 95 : grade === 'B' ? 82 : grade === 'C' ? 71 : grade === 'D' ? 55 : 30);
|
|
124
|
+
|
|
125
|
+
res.setHeader('Content-Type', 'image/svg+xml');
|
|
126
|
+
|
|
127
|
+
switch (style) {
|
|
128
|
+
case 'flat-square':
|
|
129
|
+
return res.send(generateFlatSquareBadge(grade, '', score));
|
|
130
|
+
case 'large':
|
|
131
|
+
return res.send(generateLargeBadge(grade, '', score));
|
|
132
|
+
case 'mini':
|
|
133
|
+
return res.send(generateMiniBadge(grade));
|
|
134
|
+
default:
|
|
135
|
+
return res.send(generateFlatBadge(grade, '', score));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (!domain) {
|
|
140
|
+
return res.status(400).json({ error: 'Missing required parameter: domain' });
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const cleanDomain = domain.replace(/^https?:\/\//, '').replace(/\/$/, '').split('/')[0];
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
// Fetch validation data from our own API
|
|
147
|
+
const baseUrl = process.env.VERCEL_URL
|
|
148
|
+
? `https://${process.env.VERCEL_URL}`
|
|
149
|
+
: 'https://ucptools.dev';
|
|
150
|
+
|
|
151
|
+
const validateRes = await fetch(`${baseUrl}/api/validate`, {
|
|
152
|
+
method: 'POST',
|
|
153
|
+
headers: { 'Content-Type': 'application/json' },
|
|
154
|
+
body: JSON.stringify({ domain: cleanDomain }),
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
if (!validateRes.ok) {
|
|
158
|
+
throw new Error('Validation failed');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const data = await validateRes.json();
|
|
162
|
+
const grade = data.ai_readiness?.grade || 'F';
|
|
163
|
+
const score = data.ai_readiness?.score || 0;
|
|
164
|
+
|
|
165
|
+
res.setHeader('Content-Type', 'image/svg+xml');
|
|
166
|
+
|
|
167
|
+
switch (style) {
|
|
168
|
+
case 'flat-square':
|
|
169
|
+
return res.send(generateFlatSquareBadge(grade, cleanDomain, score));
|
|
170
|
+
case 'large':
|
|
171
|
+
return res.send(generateLargeBadge(grade, cleanDomain, score));
|
|
172
|
+
case 'mini':
|
|
173
|
+
return res.send(generateMiniBadge(grade));
|
|
174
|
+
default:
|
|
175
|
+
return res.send(generateFlatBadge(grade, cleanDomain, score));
|
|
176
|
+
}
|
|
177
|
+
} catch (error) {
|
|
178
|
+
// Return a gray "unknown" badge on error
|
|
179
|
+
res.setHeader('Content-Type', 'image/svg+xml');
|
|
180
|
+
return res.send(`<svg xmlns="http://www.w3.org/2000/svg" width="180" height="20" role="img">
|
|
181
|
+
<rect width="180" height="20" rx="3" fill="#9CA3AF"/>
|
|
182
|
+
<text x="90" y="14" text-anchor="middle" font-family="Verdana,Geneva,sans-serif" font-size="11" fill="#fff">AI Commerce • Unknown</text>
|
|
183
|
+
</svg>`);
|
|
184
|
+
}
|
|
185
|
+
}
|
package/api/benchmark.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vercel Serverless Function: Benchmark Statistics
|
|
3
|
+
*
|
|
4
|
+
* POST /api/benchmark - Record a new validation score
|
|
5
|
+
* GET /api/benchmark - Get benchmark statistics and percentile
|
|
6
|
+
*
|
|
7
|
+
* Privacy: Only stores aggregate statistics, not individual domains
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import pg from 'pg';
|
|
11
|
+
|
|
12
|
+
const { Pool } = pg;
|
|
13
|
+
|
|
14
|
+
let pool = null;
|
|
15
|
+
|
|
16
|
+
function getPool() {
|
|
17
|
+
if (!pool) {
|
|
18
|
+
pool = new Pool({
|
|
19
|
+
connectionString: process.env.DATABASE_URL,
|
|
20
|
+
ssl: { rejectUnauthorized: false },
|
|
21
|
+
max: 5,
|
|
22
|
+
idleTimeoutMillis: 30000,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return pool;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Get the score bucket for a given score (0, 10, 20, ..., 100)
|
|
30
|
+
*/
|
|
31
|
+
function getScoreBucket(score) {
|
|
32
|
+
return Math.floor(score / 10) * 10;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Calculate percentile for a given score based on distribution
|
|
37
|
+
*/
|
|
38
|
+
async function calculatePercentile(pool, score) {
|
|
39
|
+
const result = await pool.query(`
|
|
40
|
+
SELECT
|
|
41
|
+
score_bucket,
|
|
42
|
+
count,
|
|
43
|
+
SUM(count) OVER (ORDER BY score_bucket) as cumulative
|
|
44
|
+
FROM benchmark_stats
|
|
45
|
+
ORDER BY score_bucket
|
|
46
|
+
`);
|
|
47
|
+
|
|
48
|
+
const summary = await pool.query('SELECT total_validations FROM benchmark_summary WHERE id = 1');
|
|
49
|
+
const total = summary.rows[0]?.total_validations || 0;
|
|
50
|
+
|
|
51
|
+
if (total === 0) {
|
|
52
|
+
return 50; // Default to 50th percentile if no data
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const scoreBucket = getScoreBucket(score);
|
|
56
|
+
let belowCount = 0;
|
|
57
|
+
|
|
58
|
+
for (const row of result.rows) {
|
|
59
|
+
if (row.score_bucket < scoreBucket) {
|
|
60
|
+
belowCount = row.cumulative;
|
|
61
|
+
} else if (row.score_bucket === scoreBucket) {
|
|
62
|
+
// For the current bucket, count half of it (assume uniform distribution within bucket)
|
|
63
|
+
belowCount = (row.cumulative - row.count) + Math.floor(row.count / 2);
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return Math.round((belowCount / total) * 100);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Record a new validation score
|
|
73
|
+
*/
|
|
74
|
+
async function recordScore(pool, score) {
|
|
75
|
+
const bucket = getScoreBucket(score);
|
|
76
|
+
|
|
77
|
+
// Increment the bucket count
|
|
78
|
+
await pool.query(`
|
|
79
|
+
UPDATE benchmark_stats
|
|
80
|
+
SET count = count + 1
|
|
81
|
+
WHERE score_bucket = $1
|
|
82
|
+
`, [bucket]);
|
|
83
|
+
|
|
84
|
+
// Update summary statistics
|
|
85
|
+
await pool.query(`
|
|
86
|
+
UPDATE benchmark_summary
|
|
87
|
+
SET
|
|
88
|
+
total_validations = total_validations + 1,
|
|
89
|
+
avg_score = (avg_score * total_validations + $1) / (total_validations + 1),
|
|
90
|
+
updated_at = NOW()
|
|
91
|
+
WHERE id = 1
|
|
92
|
+
`, [score]);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Get benchmark statistics
|
|
97
|
+
*/
|
|
98
|
+
async function getStats(pool) {
|
|
99
|
+
const summary = await pool.query('SELECT * FROM benchmark_summary WHERE id = 1');
|
|
100
|
+
const distribution = await pool.query('SELECT score_bucket, count FROM benchmark_stats ORDER BY score_bucket');
|
|
101
|
+
|
|
102
|
+
const stats = summary.rows[0] || { total_validations: 0, avg_score: 0 };
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
total_validations: stats.total_validations,
|
|
106
|
+
avg_score: Math.round(stats.avg_score * 10) / 10,
|
|
107
|
+
distribution: distribution.rows.reduce((acc, row) => {
|
|
108
|
+
acc[row.score_bucket] = row.count;
|
|
109
|
+
return acc;
|
|
110
|
+
}, {}),
|
|
111
|
+
updated_at: stats.updated_at,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export default async function handler(req, res) {
|
|
116
|
+
// CORS headers
|
|
117
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
118
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
|
119
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
|
120
|
+
|
|
121
|
+
if (req.method === 'OPTIONS') {
|
|
122
|
+
return res.status(200).end();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (!process.env.DATABASE_URL) {
|
|
126
|
+
return res.status(500).json({ error: 'Database not configured' });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const pool = getPool();
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
if (req.method === 'POST') {
|
|
133
|
+
// Record a new score
|
|
134
|
+
const { score } = req.body;
|
|
135
|
+
|
|
136
|
+
if (typeof score !== 'number' || score < 0 || score > 100) {
|
|
137
|
+
return res.status(400).json({ error: 'Invalid score. Must be a number between 0 and 100.' });
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
await recordScore(pool, score);
|
|
141
|
+
const percentile = await calculatePercentile(pool, score);
|
|
142
|
+
const stats = await getStats(pool);
|
|
143
|
+
|
|
144
|
+
return res.status(200).json({
|
|
145
|
+
recorded: true,
|
|
146
|
+
percentile,
|
|
147
|
+
stats: {
|
|
148
|
+
total_validations: stats.total_validations,
|
|
149
|
+
avg_score: stats.avg_score,
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
} else if (req.method === 'GET') {
|
|
154
|
+
// Get benchmark statistics
|
|
155
|
+
const score = req.query.score ? parseInt(req.query.score, 10) : null;
|
|
156
|
+
const stats = await getStats(pool);
|
|
157
|
+
|
|
158
|
+
const response = {
|
|
159
|
+
stats,
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// If score provided, calculate percentile
|
|
163
|
+
if (score !== null && !isNaN(score) && score >= 0 && score <= 100) {
|
|
164
|
+
response.percentile = await calculatePercentile(pool, score);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return res.status(200).json(response);
|
|
168
|
+
|
|
169
|
+
} else {
|
|
170
|
+
return res.status(405).json({ error: 'Method not allowed' });
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
} catch (error) {
|
|
174
|
+
console.error('Benchmark API error:', error);
|
|
175
|
+
return res.status(500).json({ error: 'Internal server error' });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vercel Serverless Function: Directory Statistics
|
|
3
|
+
* GET /api/directory-stats
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { VercelRequest, VercelResponse } from '@vercel/node';
|
|
7
|
+
import { getDirectoryStats } from '../src/services/directory.js';
|
|
8
|
+
|
|
9
|
+
export default async function handler(req: VercelRequest, res: VercelResponse) {
|
|
10
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
11
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
|
|
12
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
|
13
|
+
|
|
14
|
+
if (req.method === 'OPTIONS') {
|
|
15
|
+
return res.status(200).end();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (req.method !== 'GET') {
|
|
19
|
+
return res.status(405).json({ error: 'Method not allowed' });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const stats = await getDirectoryStats();
|
|
24
|
+
return res.status(200).json(stats);
|
|
25
|
+
} catch (error: any) {
|
|
26
|
+
console.error('Directory stats error:', error);
|
|
27
|
+
return res.status(500).json({ error: 'Internal server error' });
|
|
28
|
+
}
|
|
29
|
+
}
|
package/api/directory.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vercel Serverless Function: UCP Merchant Directory
|
|
3
|
+
*
|
|
4
|
+
* GET /api/directory - List merchants with pagination and filters
|
|
5
|
+
* POST /api/directory - Submit a new merchant to the directory
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { VercelRequest, VercelResponse } from '@vercel/node';
|
|
9
|
+
import { listMerchants, submitMerchant } from '../src/services/directory.js';
|
|
10
|
+
|
|
11
|
+
export default async function handler(req: VercelRequest, res: VercelResponse) {
|
|
12
|
+
// CORS handled by vercel.json, but keep for local dev
|
|
13
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
14
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
|
15
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
|
16
|
+
|
|
17
|
+
if (req.method === 'OPTIONS') {
|
|
18
|
+
return res.status(200).end();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
if (req.method === 'GET') {
|
|
23
|
+
const result = await listMerchants({
|
|
24
|
+
page: parseInt(req.query.page as string) || 1,
|
|
25
|
+
limit: parseInt(req.query.limit as string) || 20,
|
|
26
|
+
category: req.query.category as string,
|
|
27
|
+
country: req.query.country as string,
|
|
28
|
+
search: req.query.search as string,
|
|
29
|
+
sort: req.query.sort as 'score' | 'domain' | 'displayName' | 'createdAt',
|
|
30
|
+
order: req.query.order as 'asc' | 'desc',
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return res.status(200).json(result);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (req.method === 'POST') {
|
|
37
|
+
const { domain, displayName, description, logoUrl, websiteUrl, category, countryCode } = req.body;
|
|
38
|
+
|
|
39
|
+
if (!domain) {
|
|
40
|
+
return res.status(400).json({ error: 'Missing required field: domain' });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const result = await submitMerchant({
|
|
44
|
+
domain,
|
|
45
|
+
displayName,
|
|
46
|
+
description,
|
|
47
|
+
logoUrl,
|
|
48
|
+
websiteUrl,
|
|
49
|
+
category,
|
|
50
|
+
countryCode,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
if (!result.success) {
|
|
54
|
+
return res.status(400).json({
|
|
55
|
+
error: result.error,
|
|
56
|
+
details: result.details,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return res.status(201).json({
|
|
61
|
+
success: true,
|
|
62
|
+
message: 'Merchant added to directory',
|
|
63
|
+
merchant: result.merchant,
|
|
64
|
+
directoryUrl: `https://ucptools.dev/directory#${result.merchant?.domain}`,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return res.status(405).json({ error: 'Method not allowed' });
|
|
69
|
+
} catch (error: any) {
|
|
70
|
+
console.error('Directory API error:', error);
|
|
71
|
+
return res.status(500).json({ error: 'Internal server error' });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vercel Serverless Function: GDPR/Privacy Compliance Generator
|
|
3
|
+
* POST /api/generate-compliance
|
|
4
|
+
*
|
|
5
|
+
* Generates privacy policy addendums and consent language for agentic commerce.
|
|
6
|
+
*
|
|
7
|
+
* Request body:
|
|
8
|
+
* {
|
|
9
|
+
* "companyName": "Your Company",
|
|
10
|
+
* "companyEmail": "privacy@example.com",
|
|
11
|
+
* "dpoEmail": "dpo@example.com",
|
|
12
|
+
* "regions": ["eu", "uk", "california"],
|
|
13
|
+
* "platforms": ["openai", "google"],
|
|
14
|
+
* "lawfulBasis": "contract",
|
|
15
|
+
* "includeMarketingConsent": true,
|
|
16
|
+
* "includeDataRetention": true,
|
|
17
|
+
* "retentionPeriodYears": 7
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* GET /api/generate-compliance
|
|
21
|
+
* Returns available options for regions, platforms, and lawful bases.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export default async function handler(req, res) {
|
|
25
|
+
// Handle CORS
|
|
26
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
27
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
|
28
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
|
29
|
+
|
|
30
|
+
if (req.method === 'OPTIONS') {
|
|
31
|
+
return res.status(200).end();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// GET: Return available options
|
|
35
|
+
if (req.method === 'GET') {
|
|
36
|
+
try {
|
|
37
|
+
const {
|
|
38
|
+
getAvailableRegions,
|
|
39
|
+
getLawfulBasisOptions,
|
|
40
|
+
getAiPlatformOptions,
|
|
41
|
+
} = await import('../src/compliance/index.js');
|
|
42
|
+
|
|
43
|
+
return res.status(200).json({
|
|
44
|
+
success: true,
|
|
45
|
+
options: {
|
|
46
|
+
regions: getAvailableRegions(),
|
|
47
|
+
lawfulBases: getLawfulBasisOptions(),
|
|
48
|
+
platforms: getAiPlatformOptions(),
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error('Error getting options:', error);
|
|
53
|
+
return res.status(500).json({
|
|
54
|
+
error: 'Failed to get options',
|
|
55
|
+
message: error.message,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// POST: Generate compliance documents
|
|
61
|
+
if (req.method === 'POST') {
|
|
62
|
+
try {
|
|
63
|
+
const {
|
|
64
|
+
companyName,
|
|
65
|
+
companyEmail,
|
|
66
|
+
companyAddress,
|
|
67
|
+
dpoEmail,
|
|
68
|
+
regions,
|
|
69
|
+
platforms,
|
|
70
|
+
lawfulBasis,
|
|
71
|
+
includeMarketingConsent,
|
|
72
|
+
includeDataRetention,
|
|
73
|
+
retentionPeriodYears,
|
|
74
|
+
additionalProcessors,
|
|
75
|
+
} = req.body || {};
|
|
76
|
+
|
|
77
|
+
// Validate required fields
|
|
78
|
+
if (!companyName || companyName.trim() === '') {
|
|
79
|
+
return res.status(400).json({
|
|
80
|
+
error: 'Missing company name',
|
|
81
|
+
message: 'Please provide your company name',
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!regions || regions.length === 0) {
|
|
86
|
+
return res.status(400).json({
|
|
87
|
+
error: 'Missing regions',
|
|
88
|
+
message: 'Please select at least one compliance region',
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (!platforms || platforms.length === 0) {
|
|
93
|
+
return res.status(400).json({
|
|
94
|
+
error: 'Missing platforms',
|
|
95
|
+
message: 'Please select at least one AI platform',
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (!lawfulBasis) {
|
|
100
|
+
return res.status(400).json({
|
|
101
|
+
error: 'Missing lawful basis',
|
|
102
|
+
message: 'Please select a lawful basis for processing',
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Import the generator
|
|
107
|
+
const { generateComplianceDocuments } = await import('../src/compliance/index.js');
|
|
108
|
+
|
|
109
|
+
// Generate documents
|
|
110
|
+
const result = generateComplianceDocuments({
|
|
111
|
+
companyName: companyName.trim(),
|
|
112
|
+
companyEmail: companyEmail || `privacy@${companyName.toLowerCase().replace(/\s+/g, '')}.com`,
|
|
113
|
+
companyAddress,
|
|
114
|
+
dpoEmail,
|
|
115
|
+
regions,
|
|
116
|
+
platforms,
|
|
117
|
+
lawfulBasis,
|
|
118
|
+
includeMarketingConsent: includeMarketingConsent || false,
|
|
119
|
+
includeDataRetention: includeDataRetention || false,
|
|
120
|
+
retentionPeriodYears: retentionPeriodYears || 7,
|
|
121
|
+
additionalProcessors,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
return res.status(200).json({
|
|
125
|
+
success: true,
|
|
126
|
+
...result,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
} catch (error) {
|
|
130
|
+
console.error('Compliance generation error:', error);
|
|
131
|
+
return res.status(500).json({
|
|
132
|
+
error: 'Generation failed',
|
|
133
|
+
message: error.message || 'An unexpected error occurred',
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Method not allowed
|
|
139
|
+
return res.status(405).json({
|
|
140
|
+
error: 'Method not allowed',
|
|
141
|
+
message: 'Use GET for options or POST to generate documents',
|
|
142
|
+
});
|
|
143
|
+
}
|