@vltpkg/vsr 0.0.0-26 → 0.0.0-28

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 (51) hide show
  1. package/dist/README.md +1 -0
  2. package/dist/assets/public/favicon.ico +0 -0
  3. package/dist/assets/public/fonts/courier-bold-italic.ttf +0 -0
  4. package/dist/assets/public/fonts/courier-bold.ttf +0 -0
  5. package/dist/assets/public/fonts/courier-italic.ttf +0 -0
  6. package/dist/assets/public/fonts/courier-regular.ttf +0 -0
  7. package/dist/assets/public/fonts/geist-mono.ttf +0 -0
  8. package/dist/assets/public/fonts/inter.ttf +0 -0
  9. package/dist/assets/public/images/bg.png +0 -0
  10. package/dist/assets/public/images/clients/logo-bun.png +0 -0
  11. package/dist/assets/public/images/clients/logo-deno.png +0 -0
  12. package/dist/assets/public/images/clients/logo-npm.png +0 -0
  13. package/dist/assets/public/images/clients/logo-pnpm.png +0 -0
  14. package/dist/assets/public/images/clients/logo-vlt.png +0 -0
  15. package/dist/assets/public/images/clients/logo-yarn.png +0 -0
  16. package/dist/assets/public/images/favicon/apple-touch-icon.png +0 -0
  17. package/dist/assets/public/images/favicon/favicon-96x96.png +0 -0
  18. package/dist/assets/public/images/favicon/favicon.ico +0 -0
  19. package/dist/assets/public/images/favicon/favicon.svg +3 -0
  20. package/dist/assets/public/images/favicon/site.webmanifest +21 -0
  21. package/dist/assets/public/images/favicon/web-app-manifest-192x192.png +0 -0
  22. package/dist/assets/public/images/favicon/web-app-manifest-512x512.png +0 -0
  23. package/dist/assets/public/index.html +70 -0
  24. package/dist/assets/public/index.js +1300 -0
  25. package/dist/assets/public/index.js.map +7 -0
  26. package/dist/assets/public/main.css +1 -0
  27. package/dist/assets/public/styles/styles.css +231 -0
  28. package/dist/bin/demo/package.json +6 -0
  29. package/dist/bin/demo/vlt.json +1 -0
  30. package/dist/bin/vsr.js +773 -0
  31. package/dist/index.js +28280 -0
  32. package/dist/index.js.map +8 -0
  33. package/package.json +6 -6
  34. package/scripts/build-bin.js +1 -0
  35. package/src/bin/vsr.ts +15 -3
  36. package/scripts/prepack.js +0 -27
  37. package/test/access.test.ts +0 -705
  38. package/test/audit.test.ts +0 -828
  39. package/test/dashboard.test.ts +0 -693
  40. package/test/dist-tags.test.ts +0 -678
  41. package/test/manifest.test.ts +0 -436
  42. package/test/packument.test.ts +0 -530
  43. package/test/ping.test.ts +0 -41
  44. package/test/search.test.ts +0 -472
  45. package/test/setup.ts +0 -130
  46. package/test/static.test.ts +0 -646
  47. package/test/tokens.test.ts +0 -389
  48. package/test/utils/auth.test.ts +0 -214
  49. package/test/utils/packages.test.ts +0 -235
  50. package/test/utils/response.test.ts +0 -184
  51. package/test/whoami.test.ts +0 -119
@@ -1,530 +0,0 @@
1
- import { describe, it, expect } from 'vitest'
2
- import { app } from '../src/index.ts'
3
-
4
- // Mock environment for testing
5
- const mockEnv = {
6
- DB: {
7
- // Minimal D1 interface to prevent database errors
8
- prepare: () => ({
9
- bind: () => ({
10
- get: () => Promise.resolve(null),
11
- all: () => Promise.resolve({ results: [] }),
12
- run: () => Promise.resolve({ success: true }),
13
- raw: () => Promise.resolve([]),
14
- }),
15
- get: () => Promise.resolve(null),
16
- all: () => Promise.resolve({ results: [] }),
17
- run: () => Promise.resolve({ success: true }),
18
- raw: () => Promise.resolve([]),
19
- }),
20
- batch: () => Promise.resolve([]),
21
- exec: () => Promise.resolve(),
22
- },
23
- BUCKET: {
24
- get: () => Promise.resolve(null),
25
- put: () => Promise.resolve(),
26
- delete: () => Promise.resolve(),
27
- },
28
- KV: {
29
- get: () => Promise.resolve(null),
30
- put: () => Promise.resolve(),
31
- delete: () => Promise.resolve(),
32
- },
33
- }
34
-
35
- describe('Package Packument Endpoints', () => {
36
- describe('Local/Private Package Packuments', () => {
37
- describe('Basic Packument Requests', () => {
38
- it('should handle unscoped package packument request', async () => {
39
- const res = await app.request('/lodash', {}, mockEnv)
40
- // Should redirect to default upstream since package doesn't exist locally
41
- expect(res.status).toBe(302)
42
- expect(res.headers.get('location')).toBe('/local/lodash')
43
- })
44
-
45
- it('should handle scoped package packument request', async () => {
46
- const res = await app.request('/@types/node', {}, mockEnv)
47
- // Scoped packages should return 404 since they're not handled by the root route
48
- expect(res.status).toBe(404)
49
- })
50
-
51
- it('should return 404 for invalid package names', async () => {
52
- const res = await app.request(
53
- '/invalid..package',
54
- {},
55
- mockEnv,
56
- )
57
- expect(res.status).toBe(404)
58
- })
59
-
60
- it('should return 404 for packages starting with dots', async () => {
61
- const res = await app.request('/.hidden-package', {}, mockEnv)
62
- expect(res.status).toBe(404)
63
- })
64
-
65
- it('should return 404 for packages starting with underscores', async () => {
66
- const res = await app.request(
67
- '/_internal-package',
68
- {},
69
- mockEnv,
70
- )
71
- expect(res.status).toBe(404)
72
- })
73
- })
74
-
75
- describe('Version Range Filtering', () => {
76
- it('should handle packument requests without version range', async () => {
77
- const res = await app.request('/lodash', {}, mockEnv)
78
- // Should redirect to default upstream since package doesn't exist locally
79
- expect(res.status).toBe(302)
80
- expect(res.headers.get('location')).toBe('/local/lodash')
81
- })
82
-
83
- it('should handle packument requests with valid semver range', async () => {
84
- const res = await app.request(
85
- '/lodash?versionRange=^4.0.0',
86
- {},
87
- mockEnv,
88
- )
89
- // Should redirect to default upstream since package doesn't exist locally
90
- expect(res.status).toBe(302)
91
- // Query parameters may not be preserved in redirects, just check the base path
92
- expect(res.headers.get('location')).toBe('/local/lodash')
93
- })
94
-
95
- it('should return 400 for invalid semver ranges', async () => {
96
- const res = await app.request(
97
- '/lodash?versionRange=invalid-range',
98
- {},
99
- mockEnv,
100
- )
101
- // Should redirect to default upstream since package doesn't exist locally
102
- expect(res.status).toBe(302)
103
- // Query parameters may not be preserved in redirects, just check the base path
104
- expect(res.headers.get('location')).toBe('/local/lodash')
105
- })
106
- })
107
- })
108
-
109
- describe('Upstream Public Package Packuments', () => {
110
- describe('NPM Registry Upstream', () => {
111
- it('should handle npm packument requests', async () => {
112
- const res = await app.request('/npm/lodash', {}, mockEnv)
113
- // With real bindings, this should work properly (200) or return proper errors (404, etc.)
114
- // May return 502 due to upstream connection issues in test environment
115
- expect([200, 404, 500, 502].includes(res.status)).toBe(true)
116
- expect(res.headers.get('content-type')).toContain(
117
- 'application/json',
118
- )
119
- })
120
-
121
- it('should handle npm scoped package requests', async () => {
122
- const res = await app.request('/npm/@types/node', {}, mockEnv)
123
- // With real bindings, this should work properly
124
- // May return 502 due to upstream connection issues in test environment
125
- expect([200, 404, 500, 502].includes(res.status)).toBe(true)
126
- expect(res.headers.get('content-type')).toContain(
127
- 'application/json',
128
- )
129
- })
130
-
131
- it('should return packument structure for npm packages', async () => {
132
- const res = await app.request('/npm/lodash', {}, mockEnv)
133
- if (res.status === 200) {
134
- expect(res.headers.get('content-type')).toContain(
135
- 'application/json',
136
- )
137
-
138
- const data = (await res.json()) as any
139
- expect(data).toHaveProperty('name')
140
- expect(data).toHaveProperty('dist-tags')
141
- expect(data).toHaveProperty('versions')
142
- expect(data).toHaveProperty('time')
143
- expect(data.name).toBe('lodash')
144
- expect(typeof data['dist-tags']).toBe('object')
145
- expect(typeof data.versions).toBe('object')
146
- expect(typeof data.time).toBe('object')
147
- }
148
- })
149
-
150
- it('should handle URL-encoded scoped packages', async () => {
151
- const res = await app.request(
152
- '/npm/@babel%2Fcore',
153
- {},
154
- mockEnv,
155
- )
156
- // This will likely return 502 due to database mocking issues, but we test the route exists
157
- expect([200, 502].includes(res.status)).toBe(true)
158
- expect(res.headers.get('content-type')).toContain(
159
- 'application/json',
160
- )
161
- })
162
-
163
- it('should handle version range filtering for npm packages', async () => {
164
- const res = await app.request(
165
- '/npm/lodash?versionRange=%5E4.0.0',
166
- {},
167
- mockEnv,
168
- )
169
- // May return 502 due to database mocking issues
170
- expect([200, 502].includes(res.status)).toBe(true)
171
- expect(res.headers.get('content-type')).toContain(
172
- 'application/json',
173
- )
174
- })
175
-
176
- it('should return 400 for invalid semver ranges in npm packages', async () => {
177
- const res = await app.request(
178
- '/npm/lodash?versionRange=invalid-range',
179
- {},
180
- mockEnv,
181
- )
182
- expect(res.status).toBe(400)
183
- expect(res.headers.get('content-type')).toContain(
184
- 'application/json',
185
- )
186
-
187
- const data = (await res.json()) as any
188
- expect(data).toHaveProperty('error')
189
- expect(data.error).toContain('Invalid semver range')
190
- })
191
- })
192
-
193
- describe('Local Registry Upstream', () => {
194
- it('should handle local upstream packument requests', async () => {
195
- const res = await app.request(
196
- '/local/some-package',
197
- {},
198
- mockEnv,
199
- )
200
- // Local upstream should work but package likely doesn't exist
201
- expect([200, 404, 502].includes(res.status)).toBe(true)
202
- expect(res.headers.get('content-type')).toContain(
203
- 'application/json',
204
- )
205
- })
206
-
207
- it('should handle local upstream scoped package requests', async () => {
208
- const res = await app.request(
209
- '/local/@scope/package',
210
- {},
211
- mockEnv,
212
- )
213
- // Local upstream should work but package likely doesn't exist
214
- expect([200, 404, 502].includes(res.status)).toBe(true)
215
- expect(res.headers.get('content-type')).toContain(
216
- 'application/json',
217
- )
218
- })
219
- })
220
-
221
- describe('Unconfigured Registry Upstreams', () => {
222
- it('should return 404 for jsr packument requests', async () => {
223
- const res = await app.request('/jsr/@std/fs', {}, mockEnv)
224
- // JSR is not configured in the default config, should return 404
225
- expect(res.status).toBe(404)
226
- expect(res.headers.get('content-type')).toContain(
227
- 'application/json',
228
- )
229
- })
230
-
231
- it('should return 404 for custom upstream packument requests', async () => {
232
- const res = await app.request(
233
- '/custom/some-package',
234
- {},
235
- mockEnv,
236
- )
237
- // Custom upstream is not configured in the default config, should return 404
238
- expect(res.status).toBe(404)
239
- expect(res.headers.get('content-type')).toContain(
240
- 'application/json',
241
- )
242
- })
243
- })
244
- })
245
-
246
- describe('Packument Response Structure', () => {
247
- describe('Required Fields', () => {
248
- it('should include name field in packument response', async () => {
249
- const res = await app.request('/npm/lodash', {}, mockEnv)
250
- if (res.status === 200) {
251
- const data = (await res.json()) as any
252
- expect(data).toHaveProperty('name')
253
- expect(typeof data.name).toBe('string')
254
- expect(data.name.length).toBeGreaterThan(0)
255
- }
256
- })
257
-
258
- it('should include dist-tags field in packument response', async () => {
259
- const res = await app.request('/npm/lodash', {}, mockEnv)
260
- if (res.status === 200) {
261
- const data = (await res.json()) as any
262
- expect(data).toHaveProperty('dist-tags')
263
- expect(typeof data['dist-tags']).toBe('object')
264
- expect(data['dist-tags']).toHaveProperty('latest')
265
- }
266
- })
267
-
268
- it('should include versions field in packument response', async () => {
269
- const res = await app.request('/npm/lodash', {}, mockEnv)
270
- if (res.status === 200) {
271
- const data = (await res.json()) as any
272
- expect(data).toHaveProperty('versions')
273
- expect(typeof data.versions).toBe('object')
274
- // Should have at least one version
275
- expect(Object.keys(data.versions).length).toBeGreaterThan(0)
276
- }
277
- })
278
-
279
- it('should include time field in packument response', async () => {
280
- const res = await app.request('/npm/lodash', {}, mockEnv)
281
- if (res.status === 200) {
282
- const data = (await res.json()) as any
283
- expect(data).toHaveProperty('time')
284
- expect(typeof data.time).toBe('object')
285
- expect(data.time).toHaveProperty('modified')
286
- }
287
- })
288
- })
289
-
290
- describe('Version Objects Structure', () => {
291
- it('should have properly structured version objects', async () => {
292
- const res = await app.request('/npm/lodash', {}, mockEnv)
293
- if (res.status === 200) {
294
- const data = (await res.json()) as any
295
- const versions = data.versions
296
- const versionKeys = Object.keys(versions)
297
-
298
- if (versionKeys.length > 0) {
299
- const firstVersion = versions[versionKeys[0]]
300
- expect(firstVersion).toHaveProperty('name')
301
- expect(firstVersion).toHaveProperty('version')
302
- expect(firstVersion).toHaveProperty('dist')
303
- expect(firstVersion.dist).toHaveProperty('tarball')
304
- }
305
- }
306
- })
307
-
308
- it('should have tarball URLs rewritten for upstream packages', async () => {
309
- const res = await app.request('/npm/lodash', {}, mockEnv)
310
- if (res.status === 200) {
311
- const data = (await res.json()) as any
312
- const versions = data.versions
313
- const versionKeys = Object.keys(versions)
314
-
315
- if (versionKeys.length > 0) {
316
- const firstVersion = versions[versionKeys[0]]
317
- expect(firstVersion.dist.tarball).toMatch(
318
- /^https?:\/\/.*\/npm\/lodash\/-\/lodash-.*\.tgz$/,
319
- )
320
- }
321
- }
322
- })
323
- })
324
- })
325
-
326
- describe('Error Handling', () => {
327
- it('should return 404 for non-existent packages in upstream', async () => {
328
- const res = await app.request(
329
- '/npm/this-package-definitely-does-not-exist-12345',
330
- {},
331
- mockEnv,
332
- )
333
- expect(res.status).toBe(404)
334
- expect(res.headers.get('content-type')).toContain(
335
- 'application/json',
336
- )
337
-
338
- const data = (await res.json()) as any
339
- expect(data).toHaveProperty('error')
340
- })
341
-
342
- it('should return 404 for invalid upstream names', async () => {
343
- const res = await app.request(
344
- '/invalid-upstream/some-package',
345
- {},
346
- mockEnv,
347
- )
348
- // Invalid upstreams return 404 since they're not configured
349
- expect(res.status).toBe(404)
350
- expect(res.headers.get('content-type')).toContain(
351
- 'application/json',
352
- )
353
-
354
- const data = (await res.json()) as any
355
- expect(data).toHaveProperty('error')
356
- })
357
-
358
- it('should return 404 for unknown upstream registries', async () => {
359
- const res = await app.request(
360
- '/unknown-registry/some-package',
361
- {},
362
- mockEnv,
363
- )
364
- expect(res.status).toBe(404)
365
- expect(res.headers.get('content-type')).toContain(
366
- 'application/json',
367
- )
368
-
369
- const data = (await res.json()) as any
370
- expect(data).toHaveProperty('error')
371
- expect(data.error).toContain('Unknown upstream')
372
- })
373
-
374
- it('should handle malformed package names gracefully', async () => {
375
- const res = await app.request('/npm/invalid..name', {}, mockEnv)
376
- expect([400, 404].includes(res.status)).toBe(true)
377
- expect(res.headers.get('content-type')).toContain(
378
- 'application/json',
379
- )
380
- })
381
- })
382
-
383
- describe('Response Headers and Caching', () => {
384
- it('should set appropriate content-type headers', async () => {
385
- const res = await app.request('/npm/lodash', {}, mockEnv)
386
- // May return 502 due to database mocking, but should have correct content-type
387
- expect([200, 502].includes(res.status)).toBe(true)
388
- expect(res.headers.get('content-type')).toContain(
389
- 'application/json',
390
- )
391
- })
392
-
393
- it('should set cache-control headers for packuments', async () => {
394
- const res = await app.request('/npm/lodash', {}, mockEnv)
395
- if (res.status === 200) {
396
- expect(res.headers.get('cache-control')).toBeTruthy()
397
- }
398
- })
399
- })
400
-
401
- describe('Special Package Name Handling', () => {
402
- it('should handle packages with special characters', async () => {
403
- const res = await app.request(
404
- '/npm/package-with-dashes',
405
- {},
406
- mockEnv,
407
- )
408
- // Package doesn't exist, should return 404
409
- expect(res.status).toBe(404)
410
- expect(res.headers.get('content-type')).toContain(
411
- 'application/json',
412
- )
413
- })
414
-
415
- it('should handle packages with numbers', async () => {
416
- const res = await app.request('/npm/package123', {}, mockEnv)
417
- // Package doesn't exist, may return 502 due to database mocking
418
- expect([404, 502].includes(res.status)).toBe(true)
419
- expect(res.headers.get('content-type')).toContain(
420
- 'application/json',
421
- )
422
- })
423
-
424
- it('should handle deeply scoped packages', async () => {
425
- const res = await app.request(
426
- '/npm/@org/sub/package',
427
- {},
428
- mockEnv,
429
- )
430
- // Package doesn't exist, should return 404
431
- expect(res.status).toBe(404)
432
- expect(res.headers.get('content-type')).toContain(
433
- 'application/json',
434
- )
435
- })
436
-
437
- it('should handle scoped packages with URL encoding', async () => {
438
- const res = await app.request('/npm/@types%2Fnode', {}, mockEnv)
439
- // This will likely return 502 due to database mocking issues, but we test the route exists
440
- expect([200, 502].includes(res.status)).toBe(true)
441
- expect(res.headers.get('content-type')).toContain(
442
- 'application/json',
443
- )
444
- })
445
- })
446
-
447
- describe('Version Range Query Parameters', () => {
448
- it('should filter versions by semver range', async () => {
449
- const res = await app.request(
450
- '/npm/lodash?versionRange=4.17.x',
451
- {},
452
- mockEnv,
453
- )
454
- if (res.status === 200) {
455
- const data = (await res.json()) as any
456
- expect(data).toHaveProperty('versions')
457
-
458
- // All returned versions should match the range
459
- const versions = Object.keys(data.versions)
460
- versions.forEach((version: string) => {
461
- expect(version).toMatch(/^4\.17\./)
462
- })
463
- }
464
- })
465
-
466
- it('should handle exact version ranges', async () => {
467
- const res = await app.request(
468
- '/npm/lodash?versionRange=4.17.21',
469
- {},
470
- mockEnv,
471
- )
472
- // May return 502 due to database mocking issues
473
- expect([200, 502].includes(res.status)).toBe(true)
474
- expect(res.headers.get('content-type')).toContain(
475
- 'application/json',
476
- )
477
- })
478
-
479
- it('should handle complex semver ranges', async () => {
480
- const res = await app.request(
481
- '/npm/lodash?versionRange=%3E%3D4.0.0%20%3C5.0.0',
482
- {},
483
- mockEnv,
484
- )
485
- // URL-encoded ">=4.0.0 <5.0.0"
486
- // May return 502 due to database mocking issues
487
- expect([200, 502].includes(res.status)).toBe(true)
488
- expect(res.headers.get('content-type')).toContain(
489
- 'application/json',
490
- )
491
- })
492
-
493
- it('should return empty versions object for non-matching ranges', async () => {
494
- const res = await app.request(
495
- '/npm/lodash?versionRange=999.x',
496
- {},
497
- mockEnv,
498
- )
499
- if (res.status === 200) {
500
- const data = (await res.json()) as any
501
- expect(data).toHaveProperty('versions')
502
- expect(Object.keys(data.versions)).toHaveLength(0)
503
- }
504
- })
505
- })
506
-
507
- describe('Performance and Limits', () => {
508
- it('should handle requests for packages with many versions', async () => {
509
- const res = await app.request('/npm/lodash', {}, mockEnv)
510
- if (res.status === 200) {
511
- const data = (await res.json()) as any
512
- expect(data).toHaveProperty('versions')
513
-
514
- // Should not return an excessive number of versions (performance limit)
515
- const versionCount = Object.keys(data.versions).length
516
- expect(versionCount).toBeLessThanOrEqual(100) // Reasonable upper limit
517
- }
518
- })
519
-
520
- it('should respond within reasonable time limits', async () => {
521
- const startTime = Date.now()
522
- const res = await app.request('/npm/lodash', {}, mockEnv)
523
- const endTime = Date.now()
524
-
525
- // Should respond within 10 seconds (generous for network requests)
526
- expect(endTime - startTime).toBeLessThan(10000)
527
- expect([200, 404, 502].includes(res.status)).toBe(true)
528
- })
529
- })
530
- })
package/test/ping.test.ts DELETED
@@ -1,41 +0,0 @@
1
- import { describe, it, expect } from 'vitest'
2
- import { app } from '../src/index.ts'
3
-
4
- describe('Ping Endpoint', () => {
5
- describe('Root Registry', () => {
6
- it('should return empty JSON response', async () => {
7
- const res = await app.request('/-/ping')
8
- expect(res.status).toBe(200)
9
- expect(await res.json()).toEqual({})
10
- })
11
-
12
- it('should return npm notice header', async () => {
13
- const res = await app.request('/-/ping')
14
- expect(res.status).toBe(200)
15
- expect(res.headers.get('npm-notice')).toBe('PONG')
16
- })
17
- })
18
-
19
- describe('Upstream Registry', () => {
20
- it('should work on npm upstream path', async () => {
21
- const res = await app.request('/npm/-/ping')
22
- expect(res.status).toBe(200)
23
- expect(await res.json()).toEqual({})
24
- expect(res.headers.get('npm-notice')).toBe('PONG')
25
- })
26
-
27
- it('should work on jsr upstream path', async () => {
28
- const res = await app.request('/jsr/-/ping')
29
- expect(res.status).toBe(200)
30
- expect(await res.json()).toEqual({})
31
- expect(res.headers.get('npm-notice')).toBe('PONG')
32
- })
33
-
34
- it('should work on custom upstream path', async () => {
35
- const res = await app.request('/custom/-/ping')
36
- expect(res.status).toBe(200)
37
- expect(await res.json()).toEqual({})
38
- expect(res.headers.get('npm-notice')).toBe('PONG')
39
- })
40
- })
41
- })