@vltpkg/vsr 0.0.0-26 → 0.0.0-27

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 (107) hide show
  1. package/LICENSE +10 -114
  2. package/dist/README.md +1 -0
  3. package/dist/assets/public/favicon.ico +0 -0
  4. package/dist/assets/public/fonts/courier-bold-italic.ttf +0 -0
  5. package/dist/assets/public/fonts/courier-bold.ttf +0 -0
  6. package/dist/assets/public/fonts/courier-italic.ttf +0 -0
  7. package/dist/assets/public/fonts/courier-regular.ttf +0 -0
  8. package/dist/assets/public/fonts/geist-mono.ttf +0 -0
  9. package/dist/assets/public/fonts/inter.ttf +0 -0
  10. package/dist/assets/public/index.html +70 -0
  11. package/dist/assets/public/index.js +1300 -0
  12. package/dist/assets/public/index.js.map +7 -0
  13. package/dist/assets/public/main.css +1 -0
  14. package/dist/bin/vsr.js +771 -0
  15. package/dist/index.js +28283 -0
  16. package/dist/index.js.map +8 -0
  17. package/package.json +6 -49
  18. package/DEPLOY.md +0 -163
  19. package/config.ts +0 -221
  20. package/drizzle.config.js +0 -40
  21. package/info/COMPARISONS.md +0 -37
  22. package/info/CONFIGURATION.md +0 -143
  23. package/info/CONTRIBUTING.md +0 -32
  24. package/info/DATABASE_SETUP.md +0 -108
  25. package/info/GRANULAR_ACCESS_TOKENS.md +0 -160
  26. package/info/PROJECT_STRUCTURE.md +0 -291
  27. package/info/ROADMAP.md +0 -27
  28. package/info/SUPPORT.md +0 -39
  29. package/info/TESTING.md +0 -301
  30. package/info/USER_SUPPORT.md +0 -31
  31. package/scripts/build-assets.js +0 -31
  32. package/scripts/build-bin.js +0 -62
  33. package/scripts/prepack.js +0 -27
  34. package/src/bin/vsr.ts +0 -484
  35. package/src/db/client.ts +0 -590
  36. package/src/db/migrations/0000_faulty_ricochet.sql +0 -14
  37. package/src/db/migrations/0000_initial.sql +0 -29
  38. package/src/db/migrations/0001_uuid_validation.sql +0 -35
  39. package/src/db/migrations/0001_wealthy_magdalene.sql +0 -7
  40. package/src/db/migrations/drop.sql +0 -3
  41. package/src/db/migrations/meta/0000_snapshot.json +0 -104
  42. package/src/db/migrations/meta/0001_snapshot.json +0 -155
  43. package/src/db/migrations/meta/_journal.json +0 -20
  44. package/src/db/schema.ts +0 -43
  45. package/src/index.ts +0 -434
  46. package/src/middleware/config.ts +0 -79
  47. package/src/middleware/telemetry.ts +0 -43
  48. package/src/queue/index.ts +0 -97
  49. package/src/routes/access.ts +0 -852
  50. package/src/routes/docs.ts +0 -63
  51. package/src/routes/misc.ts +0 -469
  52. package/src/routes/packages.ts +0 -2823
  53. package/src/routes/ping.ts +0 -39
  54. package/src/routes/search.ts +0 -131
  55. package/src/routes/static.ts +0 -74
  56. package/src/routes/tokens.ts +0 -259
  57. package/src/routes/users.ts +0 -68
  58. package/src/utils/auth.ts +0 -202
  59. package/src/utils/cache.ts +0 -587
  60. package/src/utils/config.ts +0 -50
  61. package/src/utils/database.ts +0 -69
  62. package/src/utils/docs.ts +0 -146
  63. package/src/utils/packages.ts +0 -453
  64. package/src/utils/response.ts +0 -125
  65. package/src/utils/routes.ts +0 -64
  66. package/src/utils/spa.ts +0 -52
  67. package/src/utils/tracing.ts +0 -52
  68. package/src/utils/upstream.ts +0 -172
  69. package/test/access.test.ts +0 -705
  70. package/test/audit.test.ts +0 -828
  71. package/test/dashboard.test.ts +0 -693
  72. package/test/dist-tags.test.ts +0 -678
  73. package/test/manifest.test.ts +0 -436
  74. package/test/packument.test.ts +0 -530
  75. package/test/ping.test.ts +0 -41
  76. package/test/search.test.ts +0 -472
  77. package/test/setup.ts +0 -130
  78. package/test/static.test.ts +0 -646
  79. package/test/tokens.test.ts +0 -389
  80. package/test/utils/auth.test.ts +0 -214
  81. package/test/utils/packages.test.ts +0 -235
  82. package/test/utils/response.test.ts +0 -184
  83. package/test/whoami.test.ts +0 -119
  84. package/tsconfig.json +0 -16
  85. package/tsconfig.worker.json +0 -3
  86. package/typedoc.mjs +0 -2
  87. package/types.ts +0 -598
  88. package/vitest.config.ts +0 -25
  89. package/vlt.json.example +0 -56
  90. package/wrangler.json +0 -65
  91. /package/{src → dist}/assets/public/images/bg.png +0 -0
  92. /package/{src → dist}/assets/public/images/clients/logo-bun.png +0 -0
  93. /package/{src → dist}/assets/public/images/clients/logo-deno.png +0 -0
  94. /package/{src → dist}/assets/public/images/clients/logo-npm.png +0 -0
  95. /package/{src → dist}/assets/public/images/clients/logo-pnpm.png +0 -0
  96. /package/{src → dist}/assets/public/images/clients/logo-vlt.png +0 -0
  97. /package/{src → dist}/assets/public/images/clients/logo-yarn.png +0 -0
  98. /package/{src → dist}/assets/public/images/favicon/apple-touch-icon.png +0 -0
  99. /package/{src → dist}/assets/public/images/favicon/favicon-96x96.png +0 -0
  100. /package/{src → dist}/assets/public/images/favicon/favicon.ico +0 -0
  101. /package/{src → dist}/assets/public/images/favicon/favicon.svg +0 -0
  102. /package/{src → dist}/assets/public/images/favicon/site.webmanifest +0 -0
  103. /package/{src → dist}/assets/public/images/favicon/web-app-manifest-192x192.png +0 -0
  104. /package/{src → dist}/assets/public/images/favicon/web-app-manifest-512x512.png +0 -0
  105. /package/{src → dist}/assets/public/styles/styles.css +0 -0
  106. /package/{src → dist}/bin/demo/package.json +0 -0
  107. /package/{src → dist}/bin/demo/vlt.json +0 -0
package/src/utils/auth.ts DELETED
@@ -1,202 +0,0 @@
1
- import { packageSpec } from './packages.ts'
2
- import type {
3
- HonoContext,
4
- TokenScope,
5
- TokenAccess,
6
- AuthUser,
7
- DatabaseOperations,
8
- } from '../../types.ts'
9
-
10
- // Helper function to get typed database from context
11
- function getDb(c: HonoContext): DatabaseOperations {
12
- return c.get('db')
13
- }
14
-
15
- export function getTokenFromHeader(c: HonoContext): string | null {
16
- const auth = c.req.header('Authorization')
17
- if (auth?.startsWith('Bearer ')) {
18
- return auth.substring(7).trim()
19
- }
20
- return null
21
- }
22
-
23
- export function parseTokenAccess({
24
- scope,
25
- pkg,
26
- uuid,
27
- }: {
28
- scope: TokenScope[]
29
- pkg?: string
30
- uuid: string
31
- }): TokenAccess {
32
- const read = ['get']
33
- const write = ['put', 'post', 'delete']
34
- const temp: TokenAccess = {
35
- anyUser: false,
36
- specificUser: false,
37
- anyPackage: false,
38
- specificPackage: false,
39
- readAccess: false,
40
- writeAccess: false,
41
- methods: [],
42
- }
43
-
44
- // TODO: add for multiple package access/aliases in scopes
45
- const alternates: Record<string, string> = {}
46
-
47
- scope.map(s => {
48
- if (s.types.pkg) {
49
- if (s.values.includes('*')) {
50
- temp.anyPackage = true
51
- }
52
- if (
53
- pkg &&
54
- (s.values.includes(pkg) ||
55
- (alternates[pkg] && s.values.includes(alternates[pkg])))
56
- ) {
57
- temp.specificPackage = true
58
- }
59
- if (
60
- (temp.anyPackage || temp.specificPackage) &&
61
- s.types.pkg.read
62
- ) {
63
- temp.readAccess = true
64
- }
65
- if (
66
- (temp.anyPackage || temp.specificPackage) &&
67
- s.types.pkg.write
68
- ) {
69
- temp.writeAccess = true
70
- }
71
- }
72
- if (s.types.user) {
73
- if (s.values.includes('*')) {
74
- temp.anyUser = true
75
- }
76
- if (s.values.includes(`~${uuid}`)) {
77
- temp.specificUser = true
78
- }
79
- if ((temp.anyUser || temp.specificUser) && s.types.user.read) {
80
- temp.readAccess = true
81
- }
82
- if ((temp.anyUser || temp.specificUser) && s.types.user.write) {
83
- temp.writeAccess = true
84
- }
85
- }
86
- })
87
-
88
- temp.methods = (temp.readAccess ? read : []).concat(
89
- temp.writeAccess ? write : [],
90
- )
91
- return temp
92
- }
93
-
94
- export function isUserRoute(path: string): boolean {
95
- const routes = [
96
- 'ping',
97
- 'whoami',
98
- 'vlt/tokens',
99
- 'npm/v1/user',
100
- 'npm/v1/tokens',
101
- 'org/',
102
- ]
103
- return !!routes.filter(r => path.startsWith(`/-/${r}`)).length
104
- }
105
-
106
- export async function getUserFromToken({
107
- c,
108
- token,
109
- }: {
110
- c: HonoContext
111
- token: string
112
- }): Promise<AuthUser> {
113
- const result = await getDb(c).getToken(token)
114
- if (!result) return { uuid: null, scope: null, token }
115
-
116
- // Handle the case when scope is already an object (for tests)
117
- let scope = result.scope
118
- if (typeof scope === 'string') {
119
- try {
120
- scope = JSON.parse(scope) as TokenScope[]
121
- } catch (_e) {
122
- // Log error to monitoring system instead of console
123
- return { uuid: null, scope: null, token }
124
- }
125
- }
126
-
127
- return {
128
- uuid: result.uuid,
129
- scope,
130
- token,
131
- }
132
- }
133
-
134
- export async function getAuthedUser({
135
- c,
136
- token,
137
- }: {
138
- c: HonoContext
139
- token?: string | null
140
- }): Promise<AuthUser | null> {
141
- const authToken = token || getTokenFromHeader(c)
142
- if (!authToken) {
143
- return null
144
- }
145
- return await getUserFromToken({ c, token: authToken })
146
- }
147
-
148
- export async function verifyToken(
149
- token: string,
150
- c: HonoContext,
151
- ): Promise<boolean> {
152
- const method = c.req.method ? c.req.method.toLowerCase() : ''
153
-
154
- if (!token) {
155
- return false
156
- }
157
-
158
- const { uuid, scope } = await getUserFromToken({ c, token })
159
-
160
- if (!uuid || !scope?.length) {
161
- return false
162
- } else {
163
- const { path } = c.req
164
- const { pkg } = packageSpec(c)
165
- const routeType =
166
- isUserRoute(path) ? 'user'
167
- : pkg ? 'pkg'
168
- : null
169
-
170
- // determine access
171
- const parseParams: {
172
- scope: TokenScope[]
173
- uuid: string
174
- pkg?: string
175
- } = { scope, uuid }
176
- if (pkg) {
177
- parseParams.pkg = pkg
178
- }
179
- const {
180
- anyUser,
181
- specificUser,
182
- anyPackage,
183
- specificPackage,
184
- methods,
185
- } = parseTokenAccess(parseParams)
186
-
187
- const methodAllowed = methods.includes(method)
188
-
189
- // if the route is a user route
190
- if (routeType === 'user') {
191
- return methodAllowed && (anyUser || specificUser)
192
- }
193
-
194
- // handle package routes
195
- if (routeType === 'pkg') {
196
- return methodAllowed && (anyPackage || specificPackage)
197
- }
198
-
199
- // fallback to false (should be unreachable code path)
200
- return false
201
- }
202
- }