@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
@@ -0,0 +1,771 @@
1
+ #!/usr/bin/env NODE_OPTIONS=--no-warnings node
2
+
3
+ // src/bin/vsr.ts
4
+ import { fileURLToPath } from "node:url";
5
+ import path from "node:path";
6
+ import { spawn } from "node:child_process";
7
+ import { PathScurry } from "path-scurry";
8
+ import { PackageJson } from "@vltpkg/package-json";
9
+ import { PackageInfoClient } from "@vltpkg/package-info";
10
+ import { createServer } from "@vltpkg/server";
11
+ import { existsSync, readFileSync } from "node:fs";
12
+
13
+ // wrangler.json
14
+ var wrangler_default = {
15
+ name: "vsr",
16
+ main: "src/index.ts",
17
+ compatibility_date: "2024-09-23",
18
+ d1_databases: [
19
+ {
20
+ binding: "DB",
21
+ database_name: "vsr-local-database",
22
+ database_id: "74ce30e6-35cf-42b2-880e-be628f1e8bbb",
23
+ migrations_dir: "src/db/migrations"
24
+ }
25
+ ],
26
+ version_metadata: {
27
+ binding: "CF_VERSION_METADATA"
28
+ },
29
+ compatibility_flags: ["nodejs_compat"],
30
+ workers_dev: true,
31
+ r2_buckets: [
32
+ {
33
+ binding: "BUCKET",
34
+ bucket_name: "vsr-local-bucket"
35
+ }
36
+ ],
37
+ observability: {
38
+ logs: {
39
+ enabled: true
40
+ }
41
+ },
42
+ queues: {
43
+ producers: [
44
+ {
45
+ queue: "cache-refresh-queue",
46
+ binding: "CACHE_REFRESH_QUEUE"
47
+ }
48
+ ],
49
+ consumers: [
50
+ {
51
+ queue: "cache-refresh-queue",
52
+ max_batch_size: 10,
53
+ max_batch_timeout: 5,
54
+ max_retries: 3
55
+ }
56
+ ]
57
+ },
58
+ assets: {
59
+ directory: "./dist/assets/",
60
+ binding: "ASSETS"
61
+ },
62
+ dev: {
63
+ local_protocol: "http",
64
+ port: 1337
65
+ },
66
+ placement: {
67
+ mode: "smart"
68
+ },
69
+ vars: {
70
+ DAEMON_ENABLED: false,
71
+ TELEMETRY_ENABLED: true,
72
+ API_DOCS_ENABLED: true,
73
+ DEBUG_ENABLED: true,
74
+ SENTRY: {
75
+ dsn: "https://909b085eb764c00250ad312660c2fdf1@o4506397716054016.ingest.us.sentry.io/4509492612300800"
76
+ }
77
+ }
78
+ };
79
+
80
+ // package.json
81
+ var package_default = {
82
+ name: "@vltpkg/vsr",
83
+ version: "0.0.0-27",
84
+ repository: {
85
+ type: "git",
86
+ url: "git+https://github.com/vltpkg/vltpkg.git",
87
+ directory: "src/registry"
88
+ },
89
+ author: "vlt technology inc. <support@vlt.sh> (http://vlt.sh)",
90
+ bin: "./dist/bin/vsr.js",
91
+ dependencies: {
92
+ "@hono/sentry": "^1.2.2",
93
+ "@hono/zod-openapi": "^0.19.10",
94
+ "@libsql/client": "^0.15.14",
95
+ "@scalar/hono-api-reference": "^0.9.16",
96
+ "@vltpkg/package-info": "workspace:*",
97
+ "@vltpkg/package-json": "workspace:*",
98
+ "@vltpkg/server": "workspace:*",
99
+ "@vltpkg/vlt-json": "workspace:*",
100
+ "drizzle-orm": "^0.44.5",
101
+ hono: "^4.9.5",
102
+ minargs: "^2.1.0",
103
+ "path-scurry": "catalog:",
104
+ semver: "catalog:",
105
+ "validate-npm-package-name": "6.0.2",
106
+ wrangler: "^4.33.1",
107
+ zod: "^3.25.76"
108
+ },
109
+ devDependencies: {
110
+ "@cloudflare/vitest-pool-workers": "^0.8.68",
111
+ "@cloudflare/workers-types": "^4.20250829.0",
112
+ "@types/node": "catalog:",
113
+ "@types/validate-npm-package-name": "^4.0.2",
114
+ "@vltpkg/gui": "workspace:*",
115
+ "chokidar-cli": "^3.0.0",
116
+ "drizzle-kit": "^0.31.4",
117
+ esbuild: "^0.25.9",
118
+ eslint: "catalog:",
119
+ typedoc: "catalog:",
120
+ typescript: "catalog:",
121
+ "typescript-eslint": "catalog:",
122
+ vitest: "^3.2.4"
123
+ },
124
+ license: "FSL-1.1-MIT",
125
+ engines: {
126
+ node: ">=22"
127
+ },
128
+ scripts: {
129
+ build: "pnpm build:dist && pnpm build:assets && pnpm build:worker && pnpm build:bin",
130
+ "build:assets": "node scripts/build-assets.js",
131
+ "build:bin": "node scripts/build-bin.js",
132
+ "build:dist": `node -e "const fs=require('fs'); fs.rmSync('./dist', {recursive: true, force: true}); fs.mkdirSync('./dist/assets/public', {recursive: true});"`,
133
+ "build:worker": "npx wrangler deploy --dry-run --outdir dist",
134
+ "db:drop": `npx wrangler d1 execute vsr-local-database --file=src/db/migrations/drop.sql --local --persist-to=local-store --no-remote && node -e "const fs=require('fs'); fs.rmSync('local-store',{recursive:true,force:true}); fs.rmSync('.wrangler',{recursive:true,force:true});"`,
135
+ "db:generate": "drizzle-kit generate",
136
+ "db:migrate": "drizzle-kit migrate",
137
+ "db:push": "drizzle-kit push",
138
+ "db:setup": "npx wrangler d1 execute vsr-local-database --file=src/db/migrations/0000_initial.sql --local --persist-to=local-store --no-remote && npx wrangler d1 execute vsr-local-database --file=src/db/migrations/0001_wealthy_magdalene.sql --local --persist-to=local-store --no-remote",
139
+ "db:studio": "drizzle-kit studio --port 4985",
140
+ deploy: "pnpm build && npx wrangler deploy",
141
+ format: "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
142
+ "format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
143
+ lint: "eslint . --fix",
144
+ "lint:check": "eslint .",
145
+ prepack: "pnpm build && node scripts/prepack.js",
146
+ "serve:build": "pnpm --silent build && node ./dist/bin/vsr.js --debug --daemon=false",
147
+ "serve:build:daemon": "pnpm --silent build && node ./dist/bin/vsr.js --debug --daemon=true",
148
+ "serve:death": `echo "Killing wrangler dev processes..." && (pkill -f 'wrangler.*dev' || true) && sleep 1 && (pids=$(lsof -ti :1337 2>/dev/null; lsof -ti :3000 2>/dev/null) && [ -n "$pids" ] && echo "Force killing remaining processes: $pids" && kill -9 $pids || echo "No remaining processes found") && echo "Done."`,
149
+ "serve:watch": "chokidar './src/**/*' -c 'pnpm serve:death && pnpm serve:build'",
150
+ snap: "vitest --no-watch -u",
151
+ pretest: "pnpm build",
152
+ test: "vitest --no-watch",
153
+ posttest: "tsc --noEmit",
154
+ typecheck: "tsc --noEmit",
155
+ "typecheck:worker": "tsc -p tsconfig.worker.json --noEmit"
156
+ },
157
+ type: "module",
158
+ publishConfig: {
159
+ directory: "./.build-publish"
160
+ }
161
+ };
162
+
163
+ // src/utils/docs.ts
164
+ var apiBody = ({ YEAR: YEAR2 }) => {
165
+ return `The **vlt serverless registry** is the modern JavaScript package registry.
166
+
167
+ ### Compatible Clients
168
+
169
+ <table>
170
+ <tbody>
171
+ <tr>
172
+ <td><a href="https://vlt.sh" alt="vlt"><strong><code>vlt</code></strong></a></td>
173
+ <td><a href="https://npmjs.com/package/npm" alt="npm"><strong><code>npm</code></strong></a></td>
174
+ <td><a href="https://yarnpkg.com/" alt="yarn"><strong><code>yarn</code></strong></a></td>
175
+ <td><a href="https://pnpm.io/" alt="pnpm"><strong><code>pnpm</code></strong></a></td>
176
+ <td><a href="https://deno.com/" alt="deno"><strong><code>deno</code></strong></a></td>
177
+ <td><a href="https://bun.sh/" alt="bun"><strong><code>bun</code></strong></a></td>
178
+ </tr>
179
+ </tbody>
180
+ </table>
181
+
182
+ ### Resources
183
+
184
+ <ul alt="resources">
185
+ <li><a href="https://vlt.sh">https://<strong>vlt.sh</strong></a></li>
186
+ <li><a href="https://github.com/vltpkg/vsr">https://github.com/<strong>vltpkg/vsr</strong></a></li>
187
+ <li><a href="https://discord.gg/vltpkg">https://discord.gg/<strong>vltpkg</strong></a></li>
188
+ <li><a href="https://x.com/vltpkg">https://x.com/<strong>vltpkg</strong></a></li>
189
+ </ul>
190
+
191
+ ##### Trademark Disclaimer
192
+
193
+ <p alt="trademark-disclaimer">All trademarks, logos and brand names are the property of their respective owners. All company, product and service names used in this website are for identification purposes only. Use of these names, trademarks and brands does not imply endorsement.</p>
194
+
195
+ ### License
196
+
197
+ <details alt="license">
198
+ <summary><strong>Functional Source License</strong>, Version 1.1, MIT Future License</summary>
199
+ <h1>Functional Source License,<br />Version 1.1,<br />MIT Future License</h1>
200
+ <h2>Abbreviation</h2>
201
+
202
+ FSL-1.1-MIT
203
+
204
+ <h2>Notice</h2>
205
+
206
+ Copyright ${YEAR2} vlt technology inc.
207
+
208
+ <h2>Terms and Conditions</h2>
209
+
210
+ <h3>Licensor ("We")</h3>
211
+
212
+ The party offering the Software under these Terms and Conditions.
213
+
214
+ <h3>The Software</h3>
215
+
216
+ The "Software" is each version of the software that we make available under
217
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
218
+ Conditions with the Software.
219
+
220
+ <h3>License Grant</h3>
221
+
222
+ Subject to your compliance with this License Grant and the Patents,
223
+ Redistribution and Trademark clauses below, we hereby grant you the right to
224
+ use, copy, modify, create derivative works, publicly perform, publicly display
225
+ and redistribute the Software for any Permitted Purpose identified below.
226
+
227
+ <h3>Permitted Purpose</h3>
228
+
229
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
230
+ means making the Software available to others in a commercial product or
231
+ service that:
232
+
233
+ 1. substitutes for the Software;
234
+
235
+ 2. substitutes for any other product or service we offer using the Software
236
+ that exists as of the date we make the Software available; or
237
+
238
+ 3. offers the same or substantially similar functionality as the Software.
239
+
240
+ Permitted Purposes specifically include using the Software:
241
+
242
+ 1. for your internal use and access;
243
+
244
+ 2. for non-commercial education;
245
+
246
+ 3. for non-commercial research; and
247
+
248
+ 4. in connection with professional services that you provide to a licensee
249
+ using the Software in accordance with these Terms and Conditions.
250
+
251
+ <h3>Patents</h3>
252
+
253
+ To the extent your use for a Permitted Purpose would necessarily infringe our
254
+ patents, the license grant above includes a license under our patents. If you
255
+ make a claim against any party that the Software infringes or contributes to
256
+ the infringement of any patent, then your patent license to the Software ends
257
+ immediately.
258
+
259
+ <h3>Redistribution</h3>
260
+
261
+ The Terms and Conditions apply to all copies, modifications and derivatives of
262
+ the Software.
263
+
264
+ If you redistribute any copies, modifications or derivatives of the Software,
265
+ you must include a copy of or a link to these Terms and Conditions and not
266
+ remove any copyright notices provided in or with the Software.
267
+
268
+ <h3>Disclaimer</h3>
269
+
270
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
271
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
272
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
273
+
274
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
275
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
276
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
277
+
278
+ <h3>Trademarks</h3>
279
+
280
+ Except for displaying the License Details and identifying us as the origin of
281
+ the Software, you have no right under these Terms and Conditions to use our
282
+ trademarks, trade names, service marks or product names.
283
+
284
+ <h2>Grant of Future License</h2>
285
+
286
+ We hereby irrevocably grant you an additional license to use the Software under
287
+ the MIT license that is effective on the second anniversary of the date we make
288
+ the Software available. On or after that date, you may use the Software under
289
+ the MIT license, in which case the following will apply:
290
+
291
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
292
+ this software and associated documentation files (the "Software"), to deal in
293
+ the Software without restriction, including without limitation the rights to
294
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
295
+ of the Software, and to permit persons to whom the Software is furnished to do
296
+ so, subject to the following conditions:
297
+
298
+ The above copyright notice and this permission notice shall be included in all
299
+ copies or substantial portions of the Software.
300
+
301
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
302
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
303
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
304
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
305
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
306
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
307
+ SOFTWARE.
308
+ </dialog>`;
309
+ };
310
+
311
+ // config.ts
312
+ var YEAR = (/* @__PURE__ */ new Date()).getFullYear();
313
+ var WRANGLER_CONFIG = wrangler_default.dev;
314
+ var PORT = WRANGLER_CONFIG.port || 1337;
315
+ var DAEMON_PORT = 3e3;
316
+ var DAEMON_URL = `http://localhost:${DAEMON_PORT}`;
317
+ var VERSION = package_default.version;
318
+ var URL = `http://localhost:${PORT}`;
319
+ var REDIRECT_URI = `${URL}/-/auth/callback`;
320
+ var ORIGIN_CONFIG = {
321
+ default: "local",
322
+ upstreams: {
323
+ local: {
324
+ type: "local",
325
+ url: URL,
326
+ allowPublish: true
327
+ },
328
+ npm: {
329
+ type: "npm",
330
+ url: "https://registry.npmjs.org"
331
+ }
332
+ }
333
+ };
334
+ var PROXY = Object.keys(ORIGIN_CONFIG.upstreams).length > 1;
335
+ var PROXY_URL = ORIGIN_CONFIG.upstreams[ORIGIN_CONFIG.default]?.url;
336
+ var REQUEST_TIMEOUT = 60 * 1e3;
337
+ var OPEN_API_CONFIG = {
338
+ openapi: "3.1.0",
339
+ info: {
340
+ title: "vlt serverless registry",
341
+ version: VERSION,
342
+ description: "The vlt serverless registry API"
343
+ },
344
+ tags: [
345
+ {
346
+ name: "Health Check",
347
+ description: "Registry health and status endpoints"
348
+ },
349
+ {
350
+ name: "Authentication",
351
+ description: "User authentication and token management"
352
+ },
353
+ {
354
+ name: "Packages",
355
+ description: "Package publishing, downloading, and management"
356
+ },
357
+ {
358
+ name: "Dist-Tags",
359
+ description: "Package version tagging and lifecycle management"
360
+ },
361
+ {
362
+ name: "Access Control",
363
+ description: "Package access permissions and collaborator management"
364
+ },
365
+ {
366
+ name: "Search",
367
+ description: "Package discovery and search functionality"
368
+ },
369
+ {
370
+ name: "Security",
371
+ description: "Security auditing and vulnerability scanning"
372
+ },
373
+ {
374
+ name: "Dashboard",
375
+ description: "Registry dashboard and administration"
376
+ },
377
+ {
378
+ name: "Static Assets",
379
+ description: "Static file serving and web assets"
380
+ },
381
+ {
382
+ name: "NPM Compatibility",
383
+ description: "Legacy npm client compatibility redirects"
384
+ }
385
+ ]
386
+ };
387
+ var SCALAR_API_CONFIG = {
388
+ metaData: {
389
+ title: "vlt serverless registry"
390
+ },
391
+ hideModels: false,
392
+ hideDownloadButton: false,
393
+ darkMode: false,
394
+ favicon: "/public/images/favicon/favicon.svg",
395
+ defaultHttpClient: {
396
+ targetKey: "curl",
397
+ clientKey: "fetch"
398
+ },
399
+ authentication: {
400
+ http: {
401
+ bearer: {
402
+ token: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
403
+ },
404
+ basic: {
405
+ username: "user",
406
+ password: "pass"
407
+ }
408
+ }
409
+ },
410
+ hiddenClients: {
411
+ python: true,
412
+ c: true,
413
+ go: true,
414
+ java: true,
415
+ ruby: true,
416
+ shell: ["httpie", "wget", "fetch"],
417
+ clojure: true,
418
+ csharp: true,
419
+ kotlin: true,
420
+ objc: true,
421
+ swift: true,
422
+ r: true,
423
+ powershell: false,
424
+ ocaml: true,
425
+ curl: false,
426
+ http: true,
427
+ php: true,
428
+ node: ["request", "unirest"],
429
+ javascript: ["xhr", "jquery"]
430
+ },
431
+ spec: {
432
+ content: {
433
+ openapi: OPEN_API_CONFIG.openapi,
434
+ servers: [
435
+ {
436
+ url: URL,
437
+ description: "localhost"
438
+ }
439
+ ],
440
+ info: {
441
+ title: "vlt serverless registry",
442
+ version: VERSION,
443
+ license: {
444
+ identifier: "FSL-1.1-MIT",
445
+ name: "Functional Source License, Version 1.1, MIT Future License",
446
+ url: "https://fsl.software/FSL-1.1-MIT.template.md"
447
+ },
448
+ description: apiBody({ YEAR })
449
+ },
450
+ // Include tag ordering and descriptions
451
+ tags: OPEN_API_CONFIG.tags
452
+ }
453
+ },
454
+ customCss: `@import '${URL}/public/styles/styles.css';`
455
+ };
456
+
457
+ // src/bin/vsr.ts
458
+ import { minArgs } from "minargs";
459
+ import { load } from "@vltpkg/vlt-json";
460
+ import { createRequire } from "node:module";
461
+ var usage = `USAGE:
462
+
463
+ $ vsr [<command>] [<options>]
464
+
465
+ COMMANDS:
466
+
467
+ dev Start development server (default)
468
+ deploy Deploy to Cloudflare Workers
469
+
470
+ OPTIONS: DESCRIPTION:
471
+
472
+ --daemon=<boolean> Run filesystem daemon (default: true)
473
+ --telemetry=<boolean> Run with telemetry reporting (default: true)
474
+ -p, --port=<number> Run on a specific port (default: ${DAEMON_PORT})
475
+ -c, --config=<path> Load configuration from vlt.json file
476
+ -d, --debug Run in debug mode
477
+ -h, --help Print usage information
478
+
479
+ DEPLOY OPTIONS:
480
+
481
+ --env=<string> Environment to deploy to (dev, staging, prod)
482
+ --db-name=<string> Override D1 database name
483
+ --bucket-name=<string> Override R2 bucket name
484
+ --queue-name=<string> Override queue name
485
+ --dry-run Show what would be deployed without deploying
486
+
487
+ EXAMPLES:
488
+
489
+ $ vsr # Run dev server with all defaults
490
+ $ vsr dev --port=3000 --debug # Custom port with debug
491
+ $ vsr deploy # Deploy to default environment
492
+ $ vsr deploy --env=prod # Deploy to production
493
+ $ vsr deploy --dry-run # Preview deployment
494
+ $ vsr --config=/path/to/vlt.json # Use specific config file
495
+ `;
496
+ var defaults = {
497
+ daemon: true,
498
+ telemetry: true,
499
+ debug: false,
500
+ help: false,
501
+ port: WRANGLER_CONFIG.port,
502
+ config: void 0,
503
+ env: void 0,
504
+ "db-name": void 0,
505
+ "bucket-name": void 0,
506
+ "queue-name": void 0,
507
+ "dry-run": false
508
+ };
509
+ var opts = {
510
+ alias: {
511
+ p: "port",
512
+ c: "config",
513
+ d: "debug",
514
+ h: "help"
515
+ },
516
+ boolean: ["debug", "help", "daemon", "telemetry", "dry-run"],
517
+ string: [
518
+ "port",
519
+ "config",
520
+ "env",
521
+ "db-name",
522
+ "bucket-name",
523
+ "queue-name"
524
+ ],
525
+ default: defaults,
526
+ positionalValues: true
527
+ // Allow space-separated values like -p 3000
528
+ };
529
+ var { args, positionals } = minArgs(opts);
530
+ var command = positionals[0] || "dev";
531
+ function getBooleanValue(arg, defaultValue) {
532
+ if (!arg || arg.length === 0) return defaultValue;
533
+ const value = arg[0];
534
+ if (value === "" || value === void 0) return true;
535
+ return value !== "false" && value !== "0";
536
+ }
537
+ function getStringValue(arg, defaultValue) {
538
+ if (!arg || arg.length === 0) return defaultValue;
539
+ return arg[0] || defaultValue;
540
+ }
541
+ function getNumberValue(arg, defaultValue) {
542
+ if (!arg || arg.length === 0) return defaultValue;
543
+ const value = arg[0];
544
+ return Number(value) || defaultValue;
545
+ }
546
+ function loadVltConfig(configPath2) {
547
+ try {
548
+ const isVsrConfig = (x, _file) => {
549
+ if (x === null || typeof x !== "object") {
550
+ throw new Error("Config must be an object");
551
+ }
552
+ };
553
+ let configData;
554
+ if (configPath2) {
555
+ if (!existsSync(configPath2)) {
556
+ console.warn(`Config file not found: ${configPath2}`);
557
+ return {};
558
+ }
559
+ const configContent = readFileSync(configPath2, "utf8");
560
+ try {
561
+ configData = JSON.parse(configContent);
562
+ } catch (_err) {
563
+ console.warn(`Failed to parse config file ${configPath2}`);
564
+ return {};
565
+ }
566
+ } else {
567
+ try {
568
+ configData = load("config", isVsrConfig);
569
+ } catch (_err) {
570
+ configData = void 0;
571
+ }
572
+ }
573
+ return configData ?? {};
574
+ } catch (_err) {
575
+ return {};
576
+ }
577
+ }
578
+ var configPath = getStringValue(args.config);
579
+ var vltConfig = loadVltConfig(configPath);
580
+ var registryConfig = vltConfig.registry ?? {};
581
+ var PORT2 = getNumberValue(
582
+ args.port,
583
+ registryConfig.port ?? vltConfig.port ?? defaults.port
584
+ );
585
+ var TELEMETRY = getBooleanValue(
586
+ args.telemetry,
587
+ registryConfig.telemetry ?? vltConfig.telemetry ?? defaults.telemetry
588
+ );
589
+ var DAEMON = getBooleanValue(
590
+ args.daemon,
591
+ registryConfig.daemon ?? vltConfig.daemon ?? defaults.daemon
592
+ );
593
+ var DEBUG = getBooleanValue(
594
+ args.debug,
595
+ registryConfig.debug ?? vltConfig.debug ?? defaults.debug
596
+ );
597
+ var ENV = getStringValue(args.env, "dev");
598
+ var DRY_RUN = getBooleanValue(
599
+ args["dry-run"],
600
+ defaults["dry-run"] ?? false
601
+ );
602
+ var DB_NAME_OVERRIDE = getStringValue(args["db-name"]);
603
+ var BUCKET_NAME_OVERRIDE = getStringValue(args["bucket-name"]);
604
+ var QUEUE_NAME_OVERRIDE = getStringValue(args["queue-name"]);
605
+ function printUsage() {
606
+ console.log(usage);
607
+ }
608
+ async function deployToCloudflare() {
609
+ const deployConfig = registryConfig.deploy;
610
+ const envConfig = deployConfig?.environments?.[ENV ?? "dev"] ?? {};
611
+ const databaseName = DB_NAME_OVERRIDE ?? envConfig.databaseName ?? "vsr-database";
612
+ const bucketName = BUCKET_NAME_OVERRIDE ?? envConfig.bucketName ?? "vsr-bucket";
613
+ const queueName = QUEUE_NAME_OVERRIDE ?? envConfig.queueName ?? "cache-refresh-queue";
614
+ const sentryConfig = envConfig.sentry ?? deployConfig?.sentry ?? {};
615
+ const sentryDsn = sentryConfig.dsn ?? "https://909b085eb764c00250ad312660c2fdf1@o4506397716054016.ingest.us.sentry.io/4509492612300800";
616
+ const sentryEnv = sentryConfig.environment ?? ENV;
617
+ const wranglerArgs = [
618
+ "deploy",
619
+ indexPath,
620
+ "--name",
621
+ `vsr-${ENV}`,
622
+ "--compatibility-date",
623
+ "2024-09-23",
624
+ "--var",
625
+ `SENTRY_DSN:${sentryDsn}`,
626
+ "--var",
627
+ `SENTRY_ENVIRONMENT:${sentryEnv}`,
628
+ "--var",
629
+ `ARG_DEBUG:${DEBUG}`,
630
+ "--var",
631
+ `ARG_TELEMETRY:${TELEMETRY}`,
632
+ "--var",
633
+ `ARG_DAEMON:${DAEMON}`
634
+ ];
635
+ wranglerArgs.push("--d1", `DB=${databaseName}`);
636
+ wranglerArgs.push("--r2", `BUCKET=${bucketName}`);
637
+ wranglerArgs.push(
638
+ "--queue-producer",
639
+ `CACHE_REFRESH_QUEUE=${queueName}`
640
+ );
641
+ wranglerArgs.push("--queue-consumer", queueName);
642
+ if (envConfig.vars) {
643
+ for (const [key, value] of Object.entries(envConfig.vars)) {
644
+ wranglerArgs.push("--var", `${key}:${value}`);
645
+ }
646
+ }
647
+ if (DRY_RUN) {
648
+ wranglerArgs.push("--dry-run");
649
+ console.log(
650
+ "\u{1F50D} Dry run - would execute:",
651
+ wranglerBin,
652
+ wranglerArgs.join(" ")
653
+ );
654
+ console.log("\n\u{1F4CB} Deployment configuration:");
655
+ console.log(` Environment: ${ENV}`);
656
+ console.log(` Database: ${databaseName}`);
657
+ console.log(` Bucket: ${bucketName}`);
658
+ console.log(` Queue: ${queueName}`);
659
+ console.log(` Sentry DSN: ${sentryDsn}`);
660
+ console.log(` Sentry Environment: ${sentryEnv}`);
661
+ return;
662
+ }
663
+ console.log(`\u{1F680} Deploying VSR to ${ENV} environment...`);
664
+ return new Promise((resolve, reject) => {
665
+ const deployProcess = spawn(wranglerBin, wranglerArgs, {
666
+ cwd: registryRoot,
667
+ stdio: "inherit"
668
+ });
669
+ deployProcess.on("close", (code) => {
670
+ if (code === 0) {
671
+ console.log(`\u2705 Successfully deployed VSR to ${ENV}`);
672
+ resolve();
673
+ } else {
674
+ reject(new Error(`Deployment failed with exit code ${code}`));
675
+ }
676
+ });
677
+ deployProcess.on("error", (error) => {
678
+ reject(
679
+ new Error(`Failed to start deployment: ${error.message}`)
680
+ );
681
+ });
682
+ });
683
+ }
684
+ if (args.help) {
685
+ printUsage();
686
+ process.exit(0);
687
+ }
688
+ if (!["dev", "deploy"].includes(command)) {
689
+ console.error(`\u274C Unknown command: ${command}`);
690
+ printUsage();
691
+ process.exit(1);
692
+ }
693
+ var __filename = fileURLToPath(import.meta.url);
694
+ var __dirname = path.dirname(__filename);
695
+ var demo = path.resolve(__dirname, "./demo");
696
+ var require2 = createRequire(import.meta.url);
697
+ var registryRoot = path.resolve(__dirname, "../../");
698
+ var indexPath = path.resolve(registryRoot, "dist/index.js");
699
+ var wranglerPkgPath = require2.resolve("wrangler/package.json");
700
+ var wranglerRelBinPath = JSON.parse(readFileSync(wranglerPkgPath, "utf8")).bin.wrangler;
701
+ var wranglerBinPath = require2.resolve(
702
+ path.join("wrangler", wranglerRelBinPath)
703
+ );
704
+ var wranglerBin = existsSync(wranglerBinPath) ? wranglerBinPath : "wrangler";
705
+ var serverOptions = {
706
+ scurry: new PathScurry(demo),
707
+ projectRoot: demo,
708
+ packageJson: new PackageJson(),
709
+ catalog: {},
710
+ catalogs: {},
711
+ registry: "https://registry.npmjs.org/",
712
+ registries: {},
713
+ "scope-registries": {},
714
+ "git-hosts": {},
715
+ "git-host-archives": {}
716
+ };
717
+ void (async () => {
718
+ try {
719
+ if (command === "deploy") {
720
+ await deployToCloudflare();
721
+ return;
722
+ }
723
+ if (DAEMON) {
724
+ const originalArgv = process.argv.slice();
725
+ process.argv = [process.argv[0], process.argv[1]];
726
+ try {
727
+ const server = createServer({
728
+ ...serverOptions,
729
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
730
+ packageInfo: new PackageInfoClient()
731
+ });
732
+ await server.start({
733
+ port: DAEMON_PORT
734
+ });
735
+ console.log(`Daemon: ${DAEMON_URL}`);
736
+ } finally {
737
+ process.argv = originalArgv;
738
+ }
739
+ }
740
+ console.log(`VSR: ${URL}`);
741
+ const { stdout, stderr } = spawn(
742
+ wranglerBin,
743
+ [
744
+ "dev",
745
+ indexPath,
746
+ "--local",
747
+ "--persist-to=local-store",
748
+ "--no-remote",
749
+ `--port=${PORT2}`,
750
+ `--var=ARG_DEBUG:${DEBUG}`,
751
+ `--var=ARG_TELEMETRY:${TELEMETRY}`,
752
+ `--var=ARG_DAEMON:${DAEMON}`
753
+ ],
754
+ {
755
+ cwd: registryRoot
756
+ // Set working directory to registry root
757
+ }
758
+ );
759
+ if (DEBUG) {
760
+ stdout.on("data", (data) => {
761
+ console.log(data.toString());
762
+ });
763
+ stderr.on("data", (data) => {
764
+ console.error(data.toString());
765
+ });
766
+ }
767
+ } catch (error) {
768
+ console.error("Failed to start:", error);
769
+ process.exit(1);
770
+ }
771
+ })();