bunqueue 2.8.6 → 2.8.8

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 (50) hide show
  1. package/dist/application/operations/ack.d.ts +1 -1
  2. package/dist/application/operations/ack.js +2 -2
  3. package/dist/application/queueManager.d.ts +1 -1
  4. package/dist/application/queueManager.js +2 -2
  5. package/dist/application/statsManager.js +18 -8
  6. package/dist/cli/client.d.ts +3 -0
  7. package/dist/cli/client.js +13 -2
  8. package/dist/cli/commands/server.js +26 -2
  9. package/dist/cli/help.js +5 -0
  10. package/dist/cli/index.d.ts +5 -0
  11. package/dist/cli/index.js +53 -1
  12. package/dist/client/queue/dlq.js +1 -1
  13. package/dist/client/queue/operations/management.js +4 -2
  14. package/dist/client/queue/queue.js +2 -0
  15. package/dist/client/queue/scheduler.js +5 -0
  16. package/dist/client/tcp/client.js +1 -0
  17. package/dist/client/tcp/connection.d.ts +8 -1
  18. package/dist/client/tcp/connection.js +27 -1
  19. package/dist/client/tcp/index.d.ts +1 -1
  20. package/dist/client/tcp/shared.d.ts +6 -4
  21. package/dist/client/tcp/shared.js +27 -11
  22. package/dist/client/tcp/types.d.ts +13 -0
  23. package/dist/client/tcp/types.js +1 -0
  24. package/dist/client/tcpPool.js +11 -1
  25. package/dist/client/types.d.ts +8 -0
  26. package/dist/client/worker/worker.js +7 -2
  27. package/dist/client/worker/workerPull.d.ts +2 -0
  28. package/dist/client/worker/workerPull.js +12 -5
  29. package/dist/config/index.d.ts +1 -1
  30. package/dist/config/index.js +1 -1
  31. package/dist/config/resolve.d.ts +14 -0
  32. package/dist/config/resolve.js +19 -0
  33. package/dist/config/types.d.ts +4 -0
  34. package/dist/domain/types/command.d.ts +4 -0
  35. package/dist/infrastructure/server/handlers/advanced.js +60 -8
  36. package/dist/infrastructure/server/handlers/core.js +1 -1
  37. package/dist/infrastructure/server/handlers/cron.js +1 -0
  38. package/dist/infrastructure/server/handlers/monitoring.js +7 -2
  39. package/dist/infrastructure/server/http.d.ts +3 -0
  40. package/dist/infrastructure/server/http.js +30 -8
  41. package/dist/infrastructure/server/httpRouteJobs.js +14 -2
  42. package/dist/infrastructure/server/httpRouteQueueConfig.js +19 -3
  43. package/dist/infrastructure/server/httpRouteQueues.js +13 -1
  44. package/dist/infrastructure/server/httpRouteResources.js +4 -0
  45. package/dist/infrastructure/server/tcp.d.ts +6 -0
  46. package/dist/infrastructure/server/tcp.js +5 -1
  47. package/dist/infrastructure/server/tls.d.ts +21 -0
  48. package/dist/infrastructure/server/tls.js +19 -0
  49. package/dist/main.js +13 -1
  50. package/package.json +1 -1
@@ -11,6 +11,7 @@ import { getRateLimiter } from './rateLimiter';
11
11
  import { pack, unpack } from 'msgpackr';
12
12
  import { Semaphore, withSemaphore } from '../../shared/semaphore';
13
13
  import { SocketWriteQueue } from './socketWriteQueue';
14
+ import { loadTlsOptions } from './tls';
14
15
  /** Max concurrent commands per connection for pipelining */
15
16
  const MAX_CONCURRENT_PER_CONNECTION = 50;
16
17
  /**
@@ -236,10 +237,13 @@ export function createTcpServer(queueManager, config) {
236
237
  socket.data.writeQueue.flush(socket);
237
238
  },
238
239
  };
239
- // Create TCP server
240
+ // Create TCP server (validate TLS files BEFORE binding the port, so a bad
241
+ // path doesn't leave a half-started listener behind)
242
+ const tlsOptions = config.tls ? loadTlsOptions(config.tls) : undefined;
240
243
  const server = Bun.listen({
241
244
  hostname: config.hostname ?? '0.0.0.0',
242
245
  port: config.port ?? 6789,
246
+ ...(tlsOptions && { tls: tlsOptions }),
243
247
  socket: socketHandlers,
244
248
  });
245
249
  return {
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Server TLS options
3
+ * Shared by the TCP (Bun.listen) and HTTP (Bun.serve) servers.
4
+ */
5
+ import type { BunFile } from 'bun';
6
+ /** TLS configuration for a server (paths to PEM files) */
7
+ export interface TlsServerOptions {
8
+ /** Path to the PEM certificate (or full chain) file */
9
+ certFile: string;
10
+ /** Path to the PEM private key file */
11
+ keyFile: string;
12
+ }
13
+ /**
14
+ * Validate cert/key paths and build the `tls` option object for
15
+ * Bun.listen/Bun.serve. Fails fast with a descriptive error so a typo in a
16
+ * path surfaces at startup instead of as an opaque handshake failure.
17
+ */
18
+ export declare function loadTlsOptions(tls: TlsServerOptions): {
19
+ cert: BunFile;
20
+ key: BunFile;
21
+ };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Server TLS options
3
+ * Shared by the TCP (Bun.listen) and HTTP (Bun.serve) servers.
4
+ */
5
+ import { existsSync } from 'node:fs';
6
+ /**
7
+ * Validate cert/key paths and build the `tls` option object for
8
+ * Bun.listen/Bun.serve. Fails fast with a descriptive error so a typo in a
9
+ * path surfaces at startup instead of as an opaque handshake failure.
10
+ */
11
+ export function loadTlsOptions(tls) {
12
+ if (!existsSync(tls.certFile)) {
13
+ throw new Error(`TLS cert file not found: ${tls.certFile}`);
14
+ }
15
+ if (!existsSync(tls.keyFile)) {
16
+ throw new Error(`TLS key file not found: ${tls.keyFile}`);
17
+ }
18
+ return { cert: Bun.file(tls.certFile), key: Bun.file(tls.keyFile) };
19
+ }
package/dist/main.js CHANGED
@@ -48,7 +48,7 @@ import { VERSION } from './shared/version';
48
48
  import { S3BackupManager } from './infrastructure/backup';
49
49
  import { CloudAgent } from './infrastructure/cloud';
50
50
  import { SHARD_COUNT } from './shared/hash';
51
- import { loadConfigFile, resolveServerConfig, resolveCloudConfig, resolveBackupConfig, } from './config';
51
+ import { loadConfigFile, resolveServerConfig, resolveCloudConfig, resolveBackupConfig, resolveTlsServerOptions, } from './config';
52
52
  export { defineConfig } from './config';
53
53
  /** Print startup banner */
54
54
  function printBanner(config, cloudUrl) {
@@ -82,6 +82,7 @@ ${dim}────────────────────────
82
82
  ${green}●${reset} HTTP ${httpDisplay}
83
83
  ${yellow}●${reset} Socket ${socketDisplay}
84
84
  ${yellow}●${reset} Data ${config.dataPath ?? 'in-memory'}
85
+ ${yellow}●${reset} TLS ${config.tlsCertFile ? `${green}enabled${reset}` : `${dim}disabled${reset}`}
85
86
  ${yellow}●${reset} Auth ${config.authTokens.length > 0 ? `${green}enabled${reset}` : `${dim}disabled${reset}`}
86
87
  ${yellow}●${reset} S3 Backup ${config.s3BackupEnabled ? `${green}enabled${reset}` : `${dim}disabled${reset}`}
87
88
  ${yellow}●${reset} Cloud ${cloudUrl ? `${green}enabled${reset} ${dim}→ ${cloudUrl}${reset}` : `${dim}disabled${reset}`}
@@ -108,6 +109,15 @@ async function startServer() {
108
109
  }
109
110
  // Resolve cloud config
110
111
  const cloudConfig = resolveCloudConfig(fileConfig, config.dataPath);
112
+ // Resolve TLS config — fail fast on partial cert/key before binding anything
113
+ let tlsConfig;
114
+ try {
115
+ tlsConfig = resolveTlsServerOptions(config);
116
+ }
117
+ catch (err) {
118
+ serverLog.error(err instanceof Error ? err.message : String(err));
119
+ process.exit(1);
120
+ }
111
121
  printBanner(config, cloudConfig?.url);
112
122
  // Create queue manager
113
123
  const queueManager = new QueueManager({
@@ -118,6 +128,7 @@ async function startServer() {
118
128
  port: config.tcpPort,
119
129
  hostname: config.hostname,
120
130
  authTokens: config.authTokens,
131
+ ...(tlsConfig && { tls: tlsConfig }),
121
132
  });
122
133
  // Start HTTP server
123
134
  const httpServer = createHttpServer(queueManager, {
@@ -126,6 +137,7 @@ async function startServer() {
126
137
  authTokens: config.authTokens,
127
138
  corsOrigins: config.corsOrigins,
128
139
  requireAuthForMetrics: config.requireAuthForMetrics,
140
+ ...(tlsConfig && { tls: tlsConfig }),
129
141
  });
130
142
  // Initialize S3 backup manager
131
143
  let backupManager = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunqueue",
3
- "version": "2.8.6",
3
+ "version": "2.8.8",
4
4
  "description": "High-performance job queue for Bun & AI agents. SQLite persistence, cron scheduling, priorities, retries, DLQ, webhooks, native MCP server. Zero external dependencies.",
5
5
  "type": "module",
6
6
  "main": "dist/main.js",