@ucptools/validator 1.0.0 → 1.1.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.
Files changed (330) hide show
  1. package/dist/auth/config.d.ts +20 -0
  2. package/dist/auth/config.d.ts.map +1 -0
  3. package/dist/auth/config.js +114 -0
  4. package/dist/auth/config.js.map +1 -0
  5. package/dist/auth/index.d.ts +5 -0
  6. package/dist/auth/index.d.ts.map +1 -0
  7. package/dist/auth/index.js +17 -0
  8. package/dist/auth/index.js.map +1 -0
  9. package/dist/auth/middleware.d.ts +45 -0
  10. package/dist/auth/middleware.d.ts.map +1 -0
  11. package/dist/auth/middleware.js +170 -0
  12. package/dist/auth/middleware.js.map +1 -0
  13. package/dist/auth/service.d.ts +80 -0
  14. package/dist/auth/service.d.ts.map +1 -0
  15. package/dist/auth/service.js +298 -0
  16. package/dist/auth/service.js.map +1 -0
  17. package/dist/cli/index.d.ts +6 -0
  18. package/dist/cli/index.d.ts.map +1 -0
  19. package/dist/cli/index.js +375 -0
  20. package/dist/cli/index.js.map +1 -0
  21. package/dist/cli/mock-server.d.ts +20 -0
  22. package/dist/cli/mock-server.d.ts.map +1 -0
  23. package/dist/cli/mock-server.js +261 -0
  24. package/dist/cli/mock-server.js.map +1 -0
  25. package/dist/compliance/compliance-generator.d.ts +34 -0
  26. package/dist/compliance/compliance-generator.d.ts.map +1 -0
  27. package/dist/compliance/compliance-generator.js +320 -0
  28. package/dist/compliance/compliance-generator.js.map +1 -0
  29. package/dist/compliance/index.d.ts +8 -0
  30. package/dist/compliance/index.d.ts.map +1 -0
  31. package/dist/compliance/index.js +17 -0
  32. package/dist/compliance/index.js.map +1 -0
  33. package/dist/compliance/templates.d.ts +34 -0
  34. package/dist/compliance/templates.d.ts.map +1 -0
  35. package/{src/compliance/templates.ts → dist/compliance/templates.js} +117 -155
  36. package/dist/compliance/templates.js.map +1 -0
  37. package/dist/compliance/types.d.ts +64 -0
  38. package/dist/compliance/types.d.ts.map +1 -0
  39. package/dist/compliance/types.js +64 -0
  40. package/dist/compliance/types.js.map +1 -0
  41. package/dist/db/index.d.ts +17 -0
  42. package/dist/db/index.d.ts.map +1 -0
  43. package/dist/db/index.js +80 -0
  44. package/dist/db/index.js.map +1 -0
  45. package/dist/db/schema.d.ts +3886 -0
  46. package/dist/db/schema.d.ts.map +1 -0
  47. package/dist/db/schema.js +425 -0
  48. package/dist/db/schema.js.map +1 -0
  49. package/dist/db/utils.d.ts +252 -0
  50. package/dist/db/utils.d.ts.map +1 -0
  51. package/dist/db/utils.js +295 -0
  52. package/dist/db/utils.js.map +1 -0
  53. package/dist/feed-analyzer/feed-analyzer.d.ts +26 -0
  54. package/dist/feed-analyzer/feed-analyzer.d.ts.map +1 -0
  55. package/{src/feed-analyzer/feed-analyzer.ts → dist/feed-analyzer/feed-analyzer.js} +856 -726
  56. package/dist/feed-analyzer/feed-analyzer.js.map +1 -0
  57. package/dist/feed-analyzer/index.d.ts +8 -0
  58. package/dist/feed-analyzer/index.d.ts.map +1 -0
  59. package/dist/feed-analyzer/index.js +19 -0
  60. package/dist/feed-analyzer/index.js.map +1 -0
  61. package/dist/feed-analyzer/types.d.ts +285 -0
  62. package/dist/feed-analyzer/types.d.ts.map +1 -0
  63. package/dist/feed-analyzer/types.js +175 -0
  64. package/dist/feed-analyzer/types.js.map +1 -0
  65. package/{src/generator/index.ts → dist/generator/index.d.ts} +1 -1
  66. package/dist/generator/index.d.ts.map +1 -0
  67. package/dist/generator/index.js +13 -0
  68. package/dist/generator/index.js.map +1 -0
  69. package/dist/generator/key-generator.d.ts +24 -0
  70. package/dist/generator/key-generator.d.ts.map +1 -0
  71. package/dist/generator/key-generator.js +144 -0
  72. package/dist/generator/key-generator.js.map +1 -0
  73. package/dist/generator/profile-builder.d.ts +15 -0
  74. package/dist/generator/profile-builder.d.ts.map +1 -0
  75. package/dist/generator/profile-builder.js +338 -0
  76. package/dist/generator/profile-builder.js.map +1 -0
  77. package/dist/hosting/artifacts-generator.d.ts +10 -0
  78. package/dist/hosting/artifacts-generator.d.ts.map +1 -0
  79. package/{src/hosting/artifacts-generator.ts → dist/hosting/artifacts-generator.js} +191 -241
  80. package/dist/hosting/artifacts-generator.js.map +1 -0
  81. package/{src/hosting/index.ts → dist/hosting/index.d.ts} +1 -1
  82. package/dist/hosting/index.d.ts.map +1 -0
  83. package/dist/hosting/index.js +10 -0
  84. package/dist/hosting/index.js.map +1 -0
  85. package/dist/index.d.ts +18 -0
  86. package/dist/index.d.ts.map +1 -0
  87. package/dist/index.js +78 -0
  88. package/dist/index.js.map +1 -0
  89. package/dist/lib/analytics.d.ts +337 -0
  90. package/dist/lib/analytics.d.ts.map +1 -0
  91. package/dist/lib/analytics.js +188 -0
  92. package/dist/lib/analytics.js.map +1 -0
  93. package/{src/security/index.ts → dist/security/index.d.ts} +8 -15
  94. package/dist/security/index.d.ts.map +1 -0
  95. package/dist/security/index.js +12 -0
  96. package/dist/security/index.js.map +1 -0
  97. package/dist/security/security-scanner.d.ts +10 -0
  98. package/dist/security/security-scanner.d.ts.map +1 -0
  99. package/dist/security/security-scanner.js +669 -0
  100. package/dist/security/security-scanner.js.map +1 -0
  101. package/dist/security/types.d.ts +80 -0
  102. package/dist/security/types.d.ts.map +1 -0
  103. package/dist/security/types.js +21 -0
  104. package/dist/security/types.js.map +1 -0
  105. package/dist/services/analytics.d.ts +114 -0
  106. package/dist/services/analytics.d.ts.map +1 -0
  107. package/dist/services/analytics.js +862 -0
  108. package/dist/services/analytics.js.map +1 -0
  109. package/dist/services/badge.d.ts +31 -0
  110. package/dist/services/badge.d.ts.map +1 -0
  111. package/dist/services/badge.js +152 -0
  112. package/dist/services/badge.js.map +1 -0
  113. package/dist/services/cron.d.ts +125 -0
  114. package/dist/services/cron.d.ts.map +1 -0
  115. package/dist/services/cron.js +613 -0
  116. package/dist/services/cron.js.map +1 -0
  117. package/dist/services/directory.d.ts +106 -0
  118. package/dist/services/directory.d.ts.map +1 -0
  119. package/dist/services/directory.js +351 -0
  120. package/dist/services/directory.js.map +1 -0
  121. package/dist/services/email.d.ts +112 -0
  122. package/dist/services/email.d.ts.map +1 -0
  123. package/dist/services/email.js +772 -0
  124. package/dist/services/email.js.map +1 -0
  125. package/dist/services/hosted-profiles.d.ts +77 -0
  126. package/dist/services/hosted-profiles.d.ts.map +1 -0
  127. package/dist/services/hosted-profiles.js +433 -0
  128. package/dist/services/hosted-profiles.js.map +1 -0
  129. package/dist/services/latency.d.ts +67 -0
  130. package/dist/services/latency.d.ts.map +1 -0
  131. package/dist/services/latency.js +274 -0
  132. package/dist/services/latency.js.map +1 -0
  133. package/dist/services/manifest-compliance.d.ts +64 -0
  134. package/dist/services/manifest-compliance.d.ts.map +1 -0
  135. package/dist/services/manifest-compliance.js +271 -0
  136. package/dist/services/manifest-compliance.js.map +1 -0
  137. package/dist/services/monitoring-diff.d.ts +31 -0
  138. package/dist/services/monitoring-diff.d.ts.map +1 -0
  139. package/dist/services/monitoring-diff.js +189 -0
  140. package/dist/services/monitoring-diff.js.map +1 -0
  141. package/dist/services/notifications.d.ts +46 -0
  142. package/dist/services/notifications.d.ts.map +1 -0
  143. package/dist/services/notifications.js +88 -0
  144. package/dist/services/notifications.js.map +1 -0
  145. package/dist/services/stripe.d.ts +93 -0
  146. package/dist/services/stripe.d.ts.map +1 -0
  147. package/dist/services/stripe.js +490 -0
  148. package/dist/services/stripe.js.map +1 -0
  149. package/dist/services/validation-history.d.ts +99 -0
  150. package/dist/services/validation-history.d.ts.map +1 -0
  151. package/dist/services/validation-history.js +344 -0
  152. package/dist/services/validation-history.js.map +1 -0
  153. package/dist/services/validation-logging.d.ts +103 -0
  154. package/dist/services/validation-logging.d.ts.map +1 -0
  155. package/dist/services/validation-logging.js +210 -0
  156. package/dist/services/validation-logging.js.map +1 -0
  157. package/dist/services/validation.d.ts +119 -0
  158. package/dist/services/validation.d.ts.map +1 -0
  159. package/dist/services/validation.js +1185 -0
  160. package/dist/services/validation.js.map +1 -0
  161. package/dist/simulator/agent-simulator.d.ts +69 -0
  162. package/dist/simulator/agent-simulator.d.ts.map +1 -0
  163. package/dist/simulator/agent-simulator.js +870 -0
  164. package/dist/simulator/agent-simulator.js.map +1 -0
  165. package/{src/simulator/index.ts → dist/simulator/index.d.ts} +7 -7
  166. package/dist/simulator/index.d.ts.map +1 -0
  167. package/dist/simulator/index.js +23 -0
  168. package/dist/simulator/index.js.map +1 -0
  169. package/{src/simulator/types.ts → dist/simulator/types.d.ts} +171 -170
  170. package/dist/simulator/types.d.ts.map +1 -0
  171. package/dist/simulator/types.js +18 -0
  172. package/dist/simulator/types.js.map +1 -0
  173. package/dist/types/acp-validation.d.ts +87 -0
  174. package/dist/types/acp-validation.d.ts.map +1 -0
  175. package/dist/types/acp-validation.js +40 -0
  176. package/dist/types/acp-validation.js.map +1 -0
  177. package/dist/types/analytics.d.ts +182 -0
  178. package/dist/types/analytics.d.ts.map +1 -0
  179. package/dist/types/analytics.js +7 -0
  180. package/dist/types/analytics.js.map +1 -0
  181. package/dist/types/generator.d.ts +106 -0
  182. package/dist/types/generator.d.ts.map +1 -0
  183. package/dist/types/generator.js +6 -0
  184. package/dist/types/generator.js.map +1 -0
  185. package/{src/types/index.ts → dist/types/index.d.ts} +1 -1
  186. package/dist/types/index.d.ts.map +1 -0
  187. package/dist/types/index.js +23 -0
  188. package/dist/types/index.js.map +1 -0
  189. package/dist/types/ucp-profile.d.ts +111 -0
  190. package/dist/types/ucp-profile.d.ts.map +1 -0
  191. package/dist/types/ucp-profile.js +45 -0
  192. package/dist/types/ucp-profile.js.map +1 -0
  193. package/dist/types/validation.d.ts +76 -0
  194. package/dist/types/validation.d.ts.map +1 -0
  195. package/dist/types/validation.js +42 -0
  196. package/dist/types/validation.js.map +1 -0
  197. package/dist/validator/acp/index.d.ts +31 -0
  198. package/dist/validator/acp/index.d.ts.map +1 -0
  199. package/dist/validator/acp/index.js +574 -0
  200. package/dist/validator/acp/index.js.map +1 -0
  201. package/dist/validator/index.d.ts +26 -0
  202. package/dist/validator/index.d.ts.map +1 -0
  203. package/dist/validator/index.js +161 -0
  204. package/dist/validator/index.js.map +1 -0
  205. package/dist/validator/network-validator.d.ts +28 -0
  206. package/dist/validator/network-validator.d.ts.map +1 -0
  207. package/dist/validator/network-validator.js +319 -0
  208. package/dist/validator/network-validator.js.map +1 -0
  209. package/dist/validator/rules-validator.d.ts +19 -0
  210. package/dist/validator/rules-validator.d.ts.map +1 -0
  211. package/dist/validator/rules-validator.js +306 -0
  212. package/dist/validator/rules-validator.js.map +1 -0
  213. package/dist/validator/sdk-validator.d.ts +58 -0
  214. package/dist/validator/sdk-validator.d.ts.map +1 -0
  215. package/{src/validator/sdk-validator.ts → dist/validator/sdk-validator.js} +273 -330
  216. package/dist/validator/sdk-validator.js.map +1 -0
  217. package/dist/validator/structural-validator.d.ts +11 -0
  218. package/dist/validator/structural-validator.d.ts.map +1 -0
  219. package/dist/validator/structural-validator.js +549 -0
  220. package/dist/validator/structural-validator.js.map +1 -0
  221. package/dist/validator/utils.d.ts +51 -0
  222. package/dist/validator/utils.d.ts.map +1 -0
  223. package/dist/validator/utils.js +132 -0
  224. package/dist/validator/utils.js.map +1 -0
  225. package/package.json +44 -12
  226. package/CLAUDE.md +0 -109
  227. package/api/analyze-feed.js +0 -140
  228. package/api/badge.js +0 -185
  229. package/api/benchmark.js +0 -177
  230. package/api/directory-stats.ts +0 -29
  231. package/api/directory.ts +0 -73
  232. package/api/generate-compliance.js +0 -143
  233. package/api/generate-schema.js +0 -457
  234. package/api/generate.js +0 -132
  235. package/api/security-scan.js +0 -133
  236. package/api/simulate.js +0 -187
  237. package/api/tsconfig.json +0 -10
  238. package/api/validate.js +0 -1351
  239. package/apify-actor/.actor/actor.json +0 -68
  240. package/apify-actor/.actor/input_schema.json +0 -32
  241. package/apify-actor/APIFY-STORE-LISTING.md +0 -412
  242. package/apify-actor/Dockerfile +0 -8
  243. package/apify-actor/README.md +0 -166
  244. package/apify-actor/main.ts +0 -111
  245. package/apify-actor/package.json +0 -17
  246. package/apify-actor/src/main.js +0 -199
  247. package/docs/BRAND-IDENTITY.md +0 -238
  248. package/docs/BRAND-STYLE-GUIDE.md +0 -356
  249. package/drizzle/0000_black_king_cobra.sql +0 -39
  250. package/drizzle/meta/0000_snapshot.json +0 -309
  251. package/drizzle/meta/_journal.json +0 -13
  252. package/drizzle.config.ts +0 -10
  253. package/public/.well-known/ucp +0 -25
  254. package/public/android-chrome-192x192.png +0 -0
  255. package/public/android-chrome-512x512.png +0 -0
  256. package/public/apple-touch-icon.png +0 -0
  257. package/public/brand.css +0 -321
  258. package/public/directory.html +0 -701
  259. package/public/favicon-16x16.png +0 -0
  260. package/public/favicon-32x32.png +0 -0
  261. package/public/favicon.ico +0 -0
  262. package/public/guides/bigcommerce.html +0 -743
  263. package/public/guides/fastucp.html +0 -838
  264. package/public/guides/magento.html +0 -779
  265. package/public/guides/shopify.html +0 -726
  266. package/public/guides/squarespace.html +0 -749
  267. package/public/guides/wix.html +0 -747
  268. package/public/guides/woocommerce.html +0 -733
  269. package/public/index.html +0 -3835
  270. package/public/learn.html +0 -396
  271. package/public/logo.jpeg +0 -0
  272. package/public/og-image-icon.png +0 -0
  273. package/public/og-image.png +0 -0
  274. package/public/robots.txt +0 -6
  275. package/public/site.webmanifest +0 -31
  276. package/public/sitemap.xml +0 -69
  277. package/public/social/linkedin-banner-1128x191.png +0 -0
  278. package/public/social/temp.PNG +0 -0
  279. package/public/social/x-header-1500x500.png +0 -0
  280. package/public/verify.html +0 -410
  281. package/scripts/generate-favicons.js +0 -44
  282. package/scripts/generate-ico.js +0 -23
  283. package/scripts/generate-og-image.js +0 -45
  284. package/scripts/reset-db.ts +0 -77
  285. package/scripts/seed-db.ts +0 -71
  286. package/scripts/setup-benchmark-db.js +0 -70
  287. package/src/api/server.ts +0 -266
  288. package/src/cli/index.ts +0 -302
  289. package/src/compliance/compliance-generator.ts +0 -452
  290. package/src/compliance/index.ts +0 -28
  291. package/src/compliance/types.ts +0 -170
  292. package/src/db/index.ts +0 -28
  293. package/src/db/schema.ts +0 -84
  294. package/src/feed-analyzer/index.ts +0 -34
  295. package/src/feed-analyzer/types.ts +0 -354
  296. package/src/generator/key-generator.ts +0 -124
  297. package/src/generator/profile-builder.ts +0 -402
  298. package/src/index.ts +0 -105
  299. package/src/security/security-scanner.ts +0 -604
  300. package/src/security/types.ts +0 -55
  301. package/src/services/directory.ts +0 -434
  302. package/src/simulator/agent-simulator.ts +0 -941
  303. package/src/types/generator.ts +0 -140
  304. package/src/types/ucp-profile.ts +0 -140
  305. package/src/types/validation.ts +0 -89
  306. package/src/validator/index.ts +0 -194
  307. package/src/validator/network-validator.ts +0 -417
  308. package/src/validator/rules-validator.ts +0 -297
  309. package/src/validator/structural-validator.ts +0 -476
  310. package/tests/fixtures/non-compliant-profile.json +0 -25
  311. package/tests/fixtures/official-sample-profile.json +0 -75
  312. package/tests/integration/benchmark.test.ts +0 -207
  313. package/tests/integration/database.test.ts +0 -163
  314. package/tests/integration/directory-api.test.ts +0 -268
  315. package/tests/integration/simulate-api.test.ts +0 -230
  316. package/tests/integration/validate-api.test.ts +0 -269
  317. package/tests/setup.ts +0 -15
  318. package/tests/unit/agent-simulator.test.ts +0 -575
  319. package/tests/unit/compliance-generator.test.ts +0 -374
  320. package/tests/unit/directory-service.test.ts +0 -272
  321. package/tests/unit/feed-analyzer.test.ts +0 -517
  322. package/tests/unit/lint-suggestions.test.ts +0 -423
  323. package/tests/unit/official-samples.test.ts +0 -211
  324. package/tests/unit/pdf-report.test.ts +0 -390
  325. package/tests/unit/sdk-validator.test.ts +0 -531
  326. package/tests/unit/security-scanner.test.ts +0 -410
  327. package/tests/unit/validation.test.ts +0 -390
  328. package/tsconfig.json +0 -20
  329. package/vercel.json +0 -34
  330. package/vitest.config.ts +0 -22
@@ -1,374 +0,0 @@
1
- /**
2
- * Tests for GDPR/Privacy Compliance Generator
3
- */
4
-
5
- import { describe, it, expect } from 'vitest';
6
- import {
7
- generateComplianceDocuments,
8
- getAvailableRegions,
9
- getLawfulBasisOptions,
10
- getAiPlatformOptions,
11
- AI_PLATFORM_PROCESSORS,
12
- REGION_NAMES,
13
- LAWFUL_BASIS_DESCRIPTIONS,
14
- } from '../../src/compliance/index.js';
15
- import type { ComplianceGeneratorInput } from '../../src/compliance/index.js';
16
-
17
- describe('Compliance Generator', () => {
18
- describe('generateComplianceDocuments', () => {
19
- const validInput: ComplianceGeneratorInput = {
20
- companyName: 'Test Company',
21
- companyEmail: 'privacy@test.com',
22
- regions: ['eu'],
23
- platforms: ['openai'],
24
- lawfulBasis: 'contract',
25
- };
26
-
27
- it('should generate complete compliance documents', () => {
28
- const result = generateComplianceDocuments(validInput);
29
-
30
- expect(result).toBeDefined();
31
- expect(result.privacyAddendum).toBeDefined();
32
- expect(result.snippets).toBeDefined();
33
- expect(result.embedHtml).toBeDefined();
34
- expect(result.plainText).toBeDefined();
35
- expect(result.generatedAt).toBeDefined();
36
- expect(result.lawfulBasis).toBe('contract');
37
- expect(result.regions).toContain('eu');
38
- });
39
-
40
- it('should include company name in generated content', () => {
41
- const result = generateComplianceDocuments(validInput);
42
-
43
- expect(result.snippets.aiCommerceSection).toContain('Test Company');
44
- expect(result.plainText).toContain('Test Company');
45
- expect(result.embedHtml).toContain('Test Company');
46
- });
47
-
48
- it('should include selected AI platforms', () => {
49
- const input: ComplianceGeneratorInput = {
50
- ...validInput,
51
- platforms: ['openai', 'google'],
52
- };
53
-
54
- const result = generateComplianceDocuments(input);
55
-
56
- expect(result.snippets.processorDisclosures).toContain('OpenAI');
57
- expect(result.snippets.processorDisclosures).toContain('Google');
58
- });
59
-
60
- it('should include GDPR-specific content for EU region', () => {
61
- const result = generateComplianceDocuments(validInput);
62
-
63
- expect(result.snippets.aiCommerceSection).toContain('GDPR');
64
- expect(result.snippets.dataSubjectRights).toContain('Article');
65
- });
66
-
67
- it('should include CCPA content for California region', () => {
68
- const input: ComplianceGeneratorInput = {
69
- ...validInput,
70
- regions: ['california'],
71
- };
72
-
73
- const result = generateComplianceDocuments(input);
74
-
75
- expect(result.snippets.aiCommerceSection).toContain('California');
76
- expect(result.snippets.aiCommerceSection).toContain('CCPA');
77
- });
78
-
79
- it('should include UK GDPR content for UK region', () => {
80
- const input: ComplianceGeneratorInput = {
81
- ...validInput,
82
- regions: ['uk'],
83
- };
84
-
85
- const result = generateComplianceDocuments(input);
86
-
87
- expect(result.snippets.aiCommerceSection).toContain('United Kingdom');
88
- });
89
-
90
- it('should include marketing consent when requested', () => {
91
- const input: ComplianceGeneratorInput = {
92
- ...validInput,
93
- includeMarketingConsent: true,
94
- };
95
-
96
- const result = generateComplianceDocuments(input);
97
-
98
- expect(result.snippets.marketingOptIn).toBeDefined();
99
- expect(result.snippets.marketingOptIn).toContain('marketing');
100
- expect(result.snippets.consentLanguage).toContain('marketing');
101
- });
102
-
103
- it('should not include marketing consent when not requested', () => {
104
- const input: ComplianceGeneratorInput = {
105
- ...validInput,
106
- includeMarketingConsent: false,
107
- };
108
-
109
- const result = generateComplianceDocuments(input);
110
-
111
- expect(result.snippets.marketingOptIn).toBeUndefined();
112
- });
113
-
114
- it('should include data retention section when requested', () => {
115
- const input: ComplianceGeneratorInput = {
116
- ...validInput,
117
- includeDataRetention: true,
118
- retentionPeriodYears: 5,
119
- };
120
-
121
- const result = generateComplianceDocuments(input);
122
-
123
- const retentionSection = result.privacyAddendum.sections.find(s => s.id === 'retention');
124
- expect(retentionSection).toBeDefined();
125
- expect(retentionSection?.content).toContain('5 years');
126
- });
127
-
128
- it('should use default retention period of 7 years', () => {
129
- const input: ComplianceGeneratorInput = {
130
- ...validInput,
131
- includeDataRetention: true,
132
- };
133
-
134
- const result = generateComplianceDocuments(input);
135
-
136
- const retentionSection = result.privacyAddendum.sections.find(s => s.id === 'retention');
137
- expect(retentionSection?.content).toContain('7 years');
138
- });
139
-
140
- it('should include correct lawful basis information', () => {
141
- const bases: Array<ComplianceGeneratorInput['lawfulBasis']> = ['contract', 'consent', 'legitimate', 'legal'];
142
-
143
- for (const basis of bases) {
144
- const input: ComplianceGeneratorInput = {
145
- ...validInput,
146
- lawfulBasis: basis,
147
- };
148
-
149
- const result = generateComplianceDocuments(input);
150
- const basisInfo = LAWFUL_BASIS_DESCRIPTIONS[basis];
151
-
152
- expect(result.snippets.aiCommerceSection).toContain(basisInfo.title);
153
- expect(result.lawfulBasis).toBe(basis);
154
- }
155
- });
156
-
157
- it('should include DPO email when provided', () => {
158
- const input: ComplianceGeneratorInput = {
159
- ...validInput,
160
- dpoEmail: 'dpo@test.com',
161
- };
162
-
163
- const result = generateComplianceDocuments(input);
164
-
165
- expect(result.snippets.dataSubjectRights).toContain('dpo@test.com');
166
- });
167
-
168
- it('should include additional custom processors', () => {
169
- const input: ComplianceGeneratorInput = {
170
- ...validInput,
171
- additionalProcessors: [
172
- {
173
- name: 'Custom Processor Inc',
174
- purpose: 'Custom processing',
175
- country: 'Germany',
176
- },
177
- ],
178
- };
179
-
180
- const result = generateComplianceDocuments(input);
181
-
182
- expect(result.snippets.processorDisclosures).toContain('Custom Processor Inc');
183
- expect(result.snippets.processorDisclosures).toContain('Germany');
184
- });
185
-
186
- it('should generate valid HTML embed code', () => {
187
- const result = generateComplianceDocuments(validInput);
188
-
189
- expect(result.embedHtml).toContain('<div class="ucp-privacy-addendum">');
190
- expect(result.embedHtml).toContain('</div>');
191
- expect(result.embedHtml).toContain('<style>');
192
- });
193
-
194
- it('should include multiple regions when selected', () => {
195
- const input: ComplianceGeneratorInput = {
196
- ...validInput,
197
- regions: ['eu', 'uk', 'california'],
198
- };
199
-
200
- const result = generateComplianceDocuments(input);
201
-
202
- expect(result.regions).toHaveLength(3);
203
- expect(result.snippets.aiCommerceSection).toContain('GDPR');
204
- expect(result.snippets.aiCommerceSection).toContain('California');
205
- });
206
-
207
- it('should throw error for missing company name', () => {
208
- const input: ComplianceGeneratorInput = {
209
- ...validInput,
210
- companyName: '',
211
- };
212
-
213
- expect(() => generateComplianceDocuments(input)).toThrow('Company name is required');
214
- });
215
-
216
- it('should throw error for empty regions', () => {
217
- const input: ComplianceGeneratorInput = {
218
- ...validInput,
219
- regions: [],
220
- };
221
-
222
- expect(() => generateComplianceDocuments(input)).toThrow('At least one region must be selected');
223
- });
224
-
225
- it('should throw error for empty platforms', () => {
226
- const input: ComplianceGeneratorInput = {
227
- ...validInput,
228
- platforms: [],
229
- };
230
-
231
- expect(() => generateComplianceDocuments(input)).toThrow('At least one AI platform must be selected');
232
- });
233
-
234
- it('should include consent language for checkout', () => {
235
- const result = generateComplianceDocuments(validInput);
236
-
237
- expect(result.snippets.consentLanguage).toContain('checkout');
238
- expect(result.snippets.consentLanguage).toContain('AI shopping assistant');
239
- });
240
-
241
- it('should include tracking notice', () => {
242
- const result = generateComplianceDocuments(validInput);
243
-
244
- expect(result.snippets.trackingNotice).toBeDefined();
245
- expect(result.snippets.trackingNotice).toContain('cookie');
246
- expect(result.snippets.trackingNotice).toContain('AI agent');
247
- });
248
-
249
- it('should include disclaimer in generated documents', () => {
250
- const result = generateComplianceDocuments(validInput);
251
-
252
- expect(result.privacyAddendum.disclaimer).toContain('NOT constitute legal advice');
253
- expect(result.plainText).toContain('DISCLAIMER');
254
- });
255
-
256
- it('should include all required sections in privacy addendum', () => {
257
- const result = generateComplianceDocuments(validInput);
258
-
259
- const sectionIds = result.privacyAddendum.sections.map(s => s.id);
260
- expect(sectionIds).toContain('ai-commerce');
261
- expect(sectionIds).toContain('processors');
262
- expect(sectionIds).toContain('rights');
263
- expect(sectionIds).toContain('tracking');
264
- });
265
-
266
- it('should handle Microsoft Copilot platform', () => {
267
- const input: ComplianceGeneratorInput = {
268
- ...validInput,
269
- platforms: ['microsoft'],
270
- };
271
-
272
- const result = generateComplianceDocuments(input);
273
-
274
- expect(result.snippets.processorDisclosures).toContain('Microsoft');
275
- expect(result.snippets.processorDisclosures).toContain('Copilot');
276
- });
277
- });
278
-
279
- describe('getAvailableRegions', () => {
280
- it('should return all available regions', () => {
281
- const regions = getAvailableRegions();
282
-
283
- expect(regions).toHaveLength(4);
284
- expect(regions.map(r => r.id)).toContain('eu');
285
- expect(regions.map(r => r.id)).toContain('uk');
286
- expect(regions.map(r => r.id)).toContain('california');
287
- expect(regions.map(r => r.id)).toContain('global');
288
- });
289
-
290
- it('should include display names for regions', () => {
291
- const regions = getAvailableRegions();
292
-
293
- const euRegion = regions.find(r => r.id === 'eu');
294
- expect(euRegion?.name).toContain('GDPR');
295
- });
296
- });
297
-
298
- describe('getLawfulBasisOptions', () => {
299
- it('should return all lawful basis options', () => {
300
- const options = getLawfulBasisOptions();
301
-
302
- expect(options).toHaveLength(4);
303
- expect(options.map(o => o.id)).toContain('contract');
304
- expect(options.map(o => o.id)).toContain('consent');
305
- expect(options.map(o => o.id)).toContain('legitimate');
306
- expect(options.map(o => o.id)).toContain('legal');
307
- });
308
-
309
- it('should include descriptions and GDPR articles', () => {
310
- const options = getLawfulBasisOptions();
311
-
312
- const contractOption = options.find(o => o.id === 'contract');
313
- expect(contractOption?.title).toBeDefined();
314
- expect(contractOption?.description).toBeDefined();
315
- expect(contractOption?.gdprArticle).toContain('Article');
316
- });
317
- });
318
-
319
- describe('getAiPlatformOptions', () => {
320
- it('should return all AI platform options', () => {
321
- const options = getAiPlatformOptions();
322
-
323
- expect(options.length).toBeGreaterThanOrEqual(3);
324
- expect(options.map(o => o.id)).toContain('openai');
325
- expect(options.map(o => o.id)).toContain('google');
326
- expect(options.map(o => o.id)).toContain('microsoft');
327
- });
328
-
329
- it('should include platform names and descriptions', () => {
330
- const options = getAiPlatformOptions();
331
-
332
- const openaiOption = options.find(o => o.id === 'openai');
333
- expect(openaiOption?.name).toContain('OpenAI');
334
- expect(openaiOption?.description).toBeDefined();
335
- });
336
- });
337
-
338
- describe('AI_PLATFORM_PROCESSORS', () => {
339
- it('should have processor info for all main platforms', () => {
340
- expect(AI_PLATFORM_PROCESSORS.openai).toBeDefined();
341
- expect(AI_PLATFORM_PROCESSORS.google).toBeDefined();
342
- expect(AI_PLATFORM_PROCESSORS.microsoft).toBeDefined();
343
- });
344
-
345
- it('should include privacy policy URLs', () => {
346
- expect(AI_PLATFORM_PROCESSORS.openai.privacyPolicyUrl).toContain('openai.com');
347
- expect(AI_PLATFORM_PROCESSORS.google.privacyPolicyUrl).toContain('google.com');
348
- expect(AI_PLATFORM_PROCESSORS.microsoft.privacyPolicyUrl).toContain('microsoft.com');
349
- });
350
- });
351
-
352
- describe('REGION_NAMES', () => {
353
- it('should have display names for all regions', () => {
354
- expect(REGION_NAMES.eu).toContain('European Union');
355
- expect(REGION_NAMES.uk).toContain('United Kingdom');
356
- expect(REGION_NAMES.california).toContain('California');
357
- expect(REGION_NAMES.global).toContain('Global');
358
- });
359
- });
360
-
361
- describe('LAWFUL_BASIS_DESCRIPTIONS', () => {
362
- it('should have descriptions for all lawful bases', () => {
363
- expect(LAWFUL_BASIS_DESCRIPTIONS.contract.title).toBeDefined();
364
- expect(LAWFUL_BASIS_DESCRIPTIONS.consent.title).toBeDefined();
365
- expect(LAWFUL_BASIS_DESCRIPTIONS.legitimate.title).toBeDefined();
366
- expect(LAWFUL_BASIS_DESCRIPTIONS.legal.title).toBeDefined();
367
- });
368
-
369
- it('should include GDPR article references', () => {
370
- expect(LAWFUL_BASIS_DESCRIPTIONS.contract.gdprArticle).toContain('6(1)(b)');
371
- expect(LAWFUL_BASIS_DESCRIPTIONS.consent.gdprArticle).toContain('6(1)(a)');
372
- });
373
- });
374
- });
@@ -1,272 +0,0 @@
1
- /**
2
- * Unit Tests for Directory Service
3
- * Tests Issue #1: UCP Merchant Directory
4
- */
5
-
6
- import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
7
-
8
- // Mock the database module before importing the service
9
- vi.mock('../../src/db/index.js', () => {
10
- const mockMerchants: any[] = [];
11
-
12
- return {
13
- getDb: vi.fn(() => ({
14
- select: vi.fn(() => ({
15
- from: vi.fn(() => ({
16
- where: vi.fn(() => ({
17
- orderBy: vi.fn(() => ({
18
- limit: vi.fn(() => ({
19
- offset: vi.fn(() => Promise.resolve(mockMerchants)),
20
- })),
21
- })),
22
- groupBy: vi.fn(() => ({
23
- orderBy: vi.fn(() => Promise.resolve([])),
24
- })),
25
- limit: vi.fn(() => Promise.resolve([])),
26
- })),
27
- })),
28
- })),
29
- insert: vi.fn(() => ({
30
- values: vi.fn(() => ({
31
- returning: vi.fn(() => Promise.resolve([{ id: 'test-id', domain: 'test.com' }])),
32
- })),
33
- })),
34
- update: vi.fn(() => ({
35
- set: vi.fn(() => ({
36
- where: vi.fn(() => Promise.resolve()),
37
- })),
38
- })),
39
- })),
40
- merchants: {
41
- id: 'id',
42
- domain: 'domain',
43
- displayName: 'display_name',
44
- isPublic: 'is_public',
45
- category: 'category',
46
- countryCode: 'country_code',
47
- ucpScore: 'ucp_score',
48
- ucpGrade: 'ucp_grade',
49
- isVerified: 'is_verified',
50
- createdAt: 'created_at',
51
- },
52
- benchmarkStats: {},
53
- benchmarkSummary: {},
54
- };
55
- });
56
-
57
- // Import after mocking
58
- import * as directoryService from '../../src/services/directory.js';
59
-
60
- describe('Directory Service', () => {
61
- beforeEach(() => {
62
- vi.clearAllMocks();
63
- });
64
-
65
- afterEach(() => {
66
- vi.restoreAllMocks();
67
- });
68
-
69
- describe('validateDomain', () => {
70
- it('should return invalid for non-existent domain', async () => {
71
- global.fetch = vi.fn().mockRejectedValue(new Error('ENOTFOUND'));
72
-
73
- const result = await directoryService.validateDomain('nonexistent-domain-xyz.com');
74
-
75
- expect(result.valid).toBe(false);
76
- expect(result.error).toBeDefined();
77
- });
78
-
79
- it('should return invalid for HTTP error responses', async () => {
80
- global.fetch = vi.fn().mockResolvedValue({
81
- ok: false,
82
- status: 404,
83
- });
84
-
85
- const result = await directoryService.validateDomain('example.com');
86
-
87
- expect(result.valid).toBe(false);
88
- expect(result.error).toContain('No UCP profile found');
89
- });
90
-
91
- it('should return invalid for malformed UCP profile', async () => {
92
- global.fetch = vi.fn().mockResolvedValue({
93
- ok: true,
94
- text: () => Promise.resolve(JSON.stringify({ invalid: 'structure' })),
95
- });
96
-
97
- const result = await directoryService.validateDomain('example.com');
98
-
99
- expect(result.valid).toBe(false);
100
- expect(result.error).toBe('Invalid UCP profile structure');
101
- });
102
-
103
- it('should return valid with correct score for valid UCP profile', async () => {
104
- const validProfile = {
105
- ucp: {
106
- version: '2024-01-01',
107
- services: {
108
- shopping: {
109
- rest: { endpoint: 'https://api.example.com' },
110
- },
111
- },
112
- capabilities: [
113
- { name: 'dev.ucp.shopping.checkout' },
114
- { name: 'dev.ucp.shopping.cart' },
115
- ],
116
- },
117
- signing_keys: [{ kid: 'key1' }],
118
- };
119
-
120
- global.fetch = vi.fn().mockResolvedValue({
121
- ok: true,
122
- text: () => Promise.resolve(JSON.stringify(validProfile)),
123
- });
124
-
125
- const result = await directoryService.validateDomain('example.com');
126
-
127
- expect(result.valid).toBe(true);
128
- expect(result.score).toBeGreaterThanOrEqual(50);
129
- expect(result.grade).toBeDefined();
130
- expect(result.transports).toContain('REST');
131
- expect(result.ucpVersion).toBe('2024-01-01');
132
- });
133
-
134
- it('should calculate correct score based on capabilities', async () => {
135
- // Base profile: 50 points
136
- // checkout: +20, cart: +10, order: +10, signing_keys: +10
137
- const fullProfile = {
138
- ucp: {
139
- version: '2024-01-01',
140
- services: { shopping: { rest: {} } },
141
- capabilities: [
142
- { name: 'dev.ucp.shopping.checkout' },
143
- { name: 'dev.ucp.shopping.cart' },
144
- { name: 'dev.ucp.shopping.order' },
145
- ],
146
- },
147
- signing_keys: [{ kid: 'key1' }],
148
- };
149
-
150
- global.fetch = vi.fn().mockResolvedValue({
151
- ok: true,
152
- text: () => Promise.resolve(JSON.stringify(fullProfile)),
153
- });
154
-
155
- const result = await directoryService.validateDomain('example.com');
156
-
157
- // 50 + 20 + 10 + 10 + 10 = 100
158
- expect(result.score).toBe(100);
159
- expect(result.grade).toBe('A');
160
- });
161
-
162
- it('should detect multiple transport types', async () => {
163
- const multiTransportProfile = {
164
- ucp: {
165
- version: '2024-01-01',
166
- services: {
167
- shopping: {
168
- rest: { endpoint: 'https://api.example.com' },
169
- mcp: { server: 'mcp://example.com' },
170
- },
171
- catalog: {
172
- a2a: { url: 'https://a2a.example.com' },
173
- },
174
- },
175
- capabilities: [],
176
- },
177
- };
178
-
179
- global.fetch = vi.fn().mockResolvedValue({
180
- ok: true,
181
- text: () => Promise.resolve(JSON.stringify(multiTransportProfile)),
182
- });
183
-
184
- const result = await directoryService.validateDomain('example.com');
185
-
186
- expect(result.valid).toBe(true);
187
- expect(result.transports).toContain('REST');
188
- expect(result.transports).toContain('MCP');
189
- expect(result.transports).toContain('A2A');
190
- });
191
- });
192
-
193
- describe('listMerchants', () => {
194
- it('should apply default pagination', async () => {
195
- const result = await directoryService.listMerchants({});
196
-
197
- expect(result.pagination.page).toBe(1);
198
- expect(result.pagination.limit).toBe(20);
199
- });
200
-
201
- it('should enforce maximum limit of 100', async () => {
202
- const result = await directoryService.listMerchants({ limit: 500 });
203
-
204
- expect(result.pagination.limit).toBe(100);
205
- });
206
-
207
- it('should enforce minimum page of 1', async () => {
208
- const result = await directoryService.listMerchants({ page: -5 });
209
-
210
- expect(result.pagination.page).toBe(1);
211
- });
212
- });
213
-
214
- describe('submitMerchant', () => {
215
- it('should clean domain properly', async () => {
216
- global.fetch = vi.fn().mockResolvedValue({
217
- ok: true,
218
- text: () => Promise.resolve(JSON.stringify({
219
- ucp: { version: '2024-01-01', services: {}, capabilities: [] },
220
- })),
221
- });
222
-
223
- // The function should strip protocol and trailing slash
224
- await directoryService.submitMerchant({
225
- domain: 'https://EXAMPLE.COM/',
226
- });
227
-
228
- expect(global.fetch).toHaveBeenCalledWith(
229
- 'https://example.com/.well-known/ucp',
230
- expect.any(Object)
231
- );
232
- });
233
- });
234
- });
235
-
236
- describe('Grade Calculation', () => {
237
- it('should assign correct grades based on score', async () => {
238
- const testCases = [
239
- { score: 95, expectedGrade: 'A' },
240
- { score: 90, expectedGrade: 'A' },
241
- { score: 85, expectedGrade: 'B' },
242
- { score: 80, expectedGrade: 'B' },
243
- { score: 75, expectedGrade: 'C' },
244
- { score: 70, expectedGrade: 'C' },
245
- { score: 65, expectedGrade: 'D' },
246
- { score: 60, expectedGrade: 'D' },
247
- { score: 55, expectedGrade: 'F' },
248
- { score: 0, expectedGrade: 'F' },
249
- ];
250
-
251
- for (const { score, expectedGrade } of testCases) {
252
- const profile = {
253
- ucp: {
254
- version: '2024-01-01',
255
- services: { s: { rest: {} } },
256
- capabilities: score >= 70 ? [{ name: 'dev.ucp.shopping.checkout' }] : [],
257
- },
258
- signing_keys: score >= 60 ? [{}] : undefined,
259
- };
260
-
261
- global.fetch = vi.fn().mockResolvedValue({
262
- ok: true,
263
- text: () => Promise.resolve(JSON.stringify(profile)),
264
- });
265
-
266
- const result = await directoryService.validateDomain('test.com');
267
-
268
- // Verify grade assignment logic works (scores may vary based on capabilities)
269
- expect(['A', 'B', 'C', 'D', 'F']).toContain(result.grade);
270
- }
271
- });
272
- });