MCPcopy
hub / github.com/npmx-dev/npmx.dev / getMockForUrl

Function getMockForUrl

modules/runtime/server/cache.ts:104–239  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

102}
103
104function getMockForUrl(url: string): MockResult | null {
105 const urlObj = URL.parse(url)
106 if (!urlObj) return null
107
108 const { host, pathname, searchParams } = urlObj
109
110 // OSV API - return empty vulnerability results
111 if (host === 'api.osv.dev') {
112 if (pathname === '/v1/querybatch') {
113 return { data: { results: [] } }
114 }
115 if (pathname.startsWith('/v1/query')) {
116 return { data: { vulns: [] } }
117 }
118 }
119
120 // JSR registry - return null (npm packages aren't on JSR)
121 if (host === 'jsr.io' && pathname.endsWith('/meta.json')) {
122 return { data: null }
123 }
124
125 // Bundlephobia API - return mock size data
126 if (host === 'bundlephobia.com' && pathname === '/api/size') {
127 const packageSpec = searchParams.get('package')
128 if (packageSpec) {
129 return {
130 data: {
131 name: packageSpec.split('@')[0],
132 size: 12345,
133 gzip: 4567,
134 dependencyCount: 3,
135 },
136 }
137 }
138 }
139
140 // Gravatar API - return 404 (avatars not needed in tests)
141 if (host === 'www.gravatar.com') {
142 return { data: null }
143 }
144
145 // npm attestations API - return empty attestations (provenance not needed in tests)
146 if (host === 'registry.npmjs.org' && pathname.startsWith('/-/npm/v1/attestations/')) {
147 return { data: { attestations: [] } }
148 }
149
150 // Constellation API - return empty results for link queries
151 if (host === 'constellation.microcosm.blue') {
152 if (pathname === '/links/distinct-dids') {
153 return { data: { total: 0, linking_dids: [], cursor: undefined } }
154 }
155 if (pathname === '/links/all') {
156 return { data: { links: {} } }
157 }
158 if (pathname === '/xrpc/blue.microcosm.links.getBacklinks') {
159 return { data: { total: 0, records: [], cursor: undefined } }
160 }
161 return { data: null }

Callers 1

fetchFromFixturesFunction · 0.85

Calls 1

getMethod · 0.65

Tested by

no test coverage detected