@detiq/crawler 1.1.9 → 1.1.11

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 (83) hide show
  1. package/dist/accessibility-auditor.js +54 -74
  2. package/dist/ai-login.js +227 -249
  3. package/dist/auth-token-rotator.js +57 -67
  4. package/dist/auth.js +299 -336
  5. package/dist/browser-extension.js +104 -142
  6. package/dist/captcha-solver.js +98 -125
  7. package/dist/color-contrast.js +77 -89
  8. package/dist/content-chunker.js +126 -126
  9. package/dist/content-dedup.js +54 -71
  10. package/dist/cookie-consent.js +68 -83
  11. package/dist/cookie-jar.js +53 -60
  12. package/dist/crawler.js +4494 -5353
  13. package/dist/custom-js-injector.js +45 -61
  14. package/dist/dark-mode-capture.js +67 -81
  15. package/dist/dead-link-detector.js +47 -55
  16. package/dist/element-hash.js +8 -12
  17. package/dist/email-otp.js +154 -195
  18. package/dist/engine-router.js +87 -98
  19. package/dist/export/bulk-export.js +70 -55
  20. package/dist/export/vector-export.js +77 -105
  21. package/dist/extractors/advanced.js +249 -266
  22. package/dist/extractors/artifact-envelope.js +59 -58
  23. package/dist/failure-analysis-agent.js +37 -33
  24. package/dist/feature-flag-detector.js +51 -66
  25. package/dist/form-detector.js +55 -75
  26. package/dist/frontier.js +76 -101
  27. package/dist/gap-pass.js +68 -89
  28. package/dist/graphql-detector.js +62 -72
  29. package/dist/http-engine.js +282 -330
  30. package/dist/incremental-diff.js +54 -87
  31. package/dist/index.js +67 -28
  32. package/dist/input-fuzzer.js +93 -97
  33. package/dist/interactive-probe.js +715 -827
  34. package/dist/job-queue.js +2151 -2169
  35. package/dist/js-coverage.js +52 -56
  36. package/dist/js-router-detector.js +86 -117
  37. package/dist/language-detector.js +51 -63
  38. package/dist/link-classifier.js +32 -50
  39. package/dist/live-view.js +91 -108
  40. package/dist/locator-extractor.js +151 -187
  41. package/dist/logger.js +9 -7
  42. package/dist/markdown-extract.js +48 -61
  43. package/dist/native-crawler.js +780 -946
  44. package/dist/network-observer.js +135 -156
  45. package/dist/network-throttle.js +29 -40
  46. package/dist/openapi-generator.js +77 -92
  47. package/dist/pdf-extractor.js +72 -90
  48. package/dist/performance-metrics.js +80 -102
  49. package/dist/phash.js +125 -144
  50. package/dist/pii-scrubber.js +65 -68
  51. package/dist/playwright-recorder.js +70 -58
  52. package/dist/policies/crawl-safety.js +31 -34
  53. package/dist/profiles/domain-profile.js +130 -125
  54. package/dist/proxy.js +146 -172
  55. package/dist/rate-limiter.js +58 -65
  56. package/dist/redirect-tracker.js +60 -64
  57. package/dist/redis-frontier.js +116 -136
  58. package/dist/redis-queue.js +157 -144
  59. package/dist/response-cache.js +127 -140
  60. package/dist/responsive-detector.js +42 -46
  61. package/dist/retry-policy.js +46 -50
  62. package/dist/robots-txt.js +69 -83
  63. package/dist/screen-reader.js +45 -70
  64. package/dist/screenshot-masker.js +59 -77
  65. package/dist/seo-checker.js +88 -107
  66. package/dist/session-capture.js +192 -212
  67. package/dist/session-export.js +107 -133
  68. package/dist/sitemap-writer.js +38 -41
  69. package/dist/sitemap.js +141 -202
  70. package/dist/skyvern.js +123 -148
  71. package/dist/sqs-queue.js +42 -42
  72. package/dist/sso-token.js +74 -90
  73. package/dist/stealth/human-behavior.js +156 -173
  74. package/dist/telemetry.js +68 -82
  75. package/dist/test-executor.js +309 -335
  76. package/dist/tls-fingerprint.js +77 -88
  77. package/dist/url-pattern-completer.js +71 -90
  78. package/dist/visual-diff-verdict.js +23 -38
  79. package/dist/webhook-notifier.js +71 -69
  80. package/dist/websocket-detector.js +56 -68
  81. package/dist/worker.js +29 -38
  82. package/package.json +1 -1
  83. package/src/job-queue.ts +136 -0
@@ -1,146 +1,126 @@
1
- /**
2
- * Redis-backed distributed crawl frontier.
3
- *
4
- * Replaces the in-memory CrawlFrontier for horizontally-scaled crawler deployments.
5
- * Multiple crawler workers on different containers can share the same URL queue for
6
- * a given job — enabling 10x crawl throughput on large enterprise apps.
7
- *
8
- * Redis key namespace: zeta:frontier:{jobId}
9
- * LIST zeta:frontier:{jobId}:queue — BFS queue (LPUSH/RPOP)
10
- * SET zeta:frontier:{jobId}:visited — deduplication set
11
- * EXPIRE — 24h TTL on all keys
12
- *
13
- * Graceful fallback: if REDIS_URL is not set, RedisCrawlFrontier silently falls
14
- * back to in-memory arrays so local development works without Redis.
15
- */
16
- const FRONTIER_TTL = 86400; // 24h in seconds
17
- export class RedisCrawlFrontier {
18
- jobId;
19
- redis;
20
- queueKey;
21
- visitedKey;
22
- inMemoryQueue = [];
23
- inMemoryVisited = new Set();
24
- useRedis;
25
- constructor(jobId) {
26
- this.jobId = jobId;
27
- this.queueKey = `zeta:frontier:${jobId}:queue`;
28
- this.visitedKey = `zeta:frontier:${jobId}:visited`;
29
- this.useRedis = !!process.env.REDIS_URL;
1
+ const FRONTIER_TTL = 86400;
2
+ class RedisCrawlFrontier {
3
+ constructor(jobId) {
4
+ this.jobId = jobId;
5
+ this.queueKey = `zeta:frontier:${jobId}:queue`;
6
+ this.visitedKey = `zeta:frontier:${jobId}:visited`;
7
+ this.useRedis = !!process.env.REDIS_URL;
8
+ }
9
+ jobId;
10
+ redis;
11
+ queueKey;
12
+ visitedKey;
13
+ inMemoryQueue = [];
14
+ inMemoryVisited = /* @__PURE__ */ new Set();
15
+ useRedis;
16
+ async init() {
17
+ if (!this.useRedis) return;
18
+ try {
19
+ const Redis = await import("ioredis").then((m) => m.default ?? m);
20
+ this.redis = new Redis(process.env.REDIS_URL, {
21
+ maxRetriesPerRequest: 2,
22
+ enableReadyCheck: false,
23
+ lazyConnect: true
24
+ });
25
+ await this.redis.connect().catch(() => {
26
+ this.useRedis = false;
27
+ this.redis = null;
28
+ });
29
+ } catch {
30
+ this.useRedis = false;
31
+ this.redis = null;
30
32
  }
31
- async init() {
32
- if (!this.useRedis)
33
- return;
34
- try {
35
- const Redis = await import('ioredis').then(m => m.default ?? m);
36
- this.redis = new Redis(process.env.REDIS_URL, {
37
- maxRetriesPerRequest: 2,
38
- enableReadyCheck: false,
39
- lazyConnect: true,
40
- });
41
- await this.redis.connect().catch(() => {
42
- this.useRedis = false;
43
- this.redis = null;
44
- });
45
- }
46
- catch {
47
- this.useRedis = false;
48
- this.redis = null;
49
- }
50
- }
51
- /** Add a URL to the frontier. No-op if already visited. Returns true if added. */
52
- async push(url) {
53
- if (this.useRedis && this.redis) {
54
- try {
55
- const isNew = await this.redis.sadd(this.visitedKey, url);
56
- if (!isNew)
57
- return false;
58
- await this.redis.lpush(this.queueKey, url);
59
- await this.redis.expire(this.queueKey, FRONTIER_TTL);
60
- await this.redis.expire(this.visitedKey, FRONTIER_TTL);
61
- return true;
62
- }
63
- catch {
64
- // Fall through to in-memory on Redis error
65
- }
66
- }
67
- if (this.inMemoryVisited.has(url))
68
- return false;
69
- this.inMemoryVisited.add(url);
70
- this.inMemoryQueue.push(url);
33
+ }
34
+ /** Add a URL to the frontier. No-op if already visited. Returns true if added. */
35
+ async push(url) {
36
+ if (this.useRedis && this.redis) {
37
+ try {
38
+ const isNew = await this.redis.sadd(this.visitedKey, url);
39
+ if (!isNew) return false;
40
+ await this.redis.lpush(this.queueKey, url);
41
+ await this.redis.expire(this.queueKey, FRONTIER_TTL);
42
+ await this.redis.expire(this.visitedKey, FRONTIER_TTL);
71
43
  return true;
44
+ } catch {
45
+ }
72
46
  }
73
- /** Pop the next URL (FIFO/BFS). Returns null if queue empty. */
74
- async shift() {
75
- if (this.useRedis && this.redis) {
76
- try {
77
- const url = await this.redis.rpop(this.queueKey);
78
- return url ?? null;
79
- }
80
- catch {
81
- // Fall through
82
- }
83
- }
84
- return this.inMemoryQueue.shift() ?? null;
85
- }
86
- /** Check if a URL has already been visited/queued. */
87
- async hasVisited(url) {
88
- if (this.useRedis && this.redis) {
89
- try {
90
- return (await this.redis.sismember(this.visitedKey, url)) === 1;
91
- }
92
- catch { /* fall through */ }
93
- }
94
- return this.inMemoryVisited.has(url);
95
- }
96
- /** Current queue length. */
97
- async length() {
98
- if (this.useRedis && this.redis) {
99
- try {
100
- return await this.redis.llen(this.queueKey);
101
- }
102
- catch { /* fall through */ }
103
- }
104
- return this.inMemoryQueue.length;
47
+ if (this.inMemoryVisited.has(url)) return false;
48
+ this.inMemoryVisited.add(url);
49
+ this.inMemoryQueue.push(url);
50
+ return true;
51
+ }
52
+ /** Pop the next URL (FIFO/BFS). Returns null if queue empty. */
53
+ async shift() {
54
+ if (this.useRedis && this.redis) {
55
+ try {
56
+ const url = await this.redis.rpop(this.queueKey);
57
+ return url ?? null;
58
+ } catch {
59
+ }
105
60
  }
106
- /** Total visited count. */
107
- async visitedCount() {
108
- if (this.useRedis && this.redis) {
109
- try {
110
- return await this.redis.scard(this.visitedKey);
111
- }
112
- catch { /* fall through */ }
113
- }
114
- return this.inMemoryVisited.size;
61
+ return this.inMemoryQueue.shift() ?? null;
62
+ }
63
+ /** Check if a URL has already been visited/queued. */
64
+ async hasVisited(url) {
65
+ if (this.useRedis && this.redis) {
66
+ try {
67
+ return await this.redis.sismember(this.visitedKey, url) === 1;
68
+ } catch {
69
+ }
115
70
  }
116
- /** Seed initial URLs (used at job start). */
117
- async seed(urls) {
118
- for (const url of urls)
119
- await this.push(url);
71
+ return this.inMemoryVisited.has(url);
72
+ }
73
+ /** Current queue length. */
74
+ async length() {
75
+ if (this.useRedis && this.redis) {
76
+ try {
77
+ return await this.redis.llen(this.queueKey);
78
+ } catch {
79
+ }
120
80
  }
121
- /** Clean up all Redis keys for this frontier. Call at job completion. */
122
- async cleanup() {
123
- if (this.useRedis && this.redis) {
124
- try {
125
- await this.redis.del(this.queueKey, this.visitedKey);
126
- }
127
- catch { /* ignore */ }
128
- try {
129
- await this.redis.quit();
130
- }
131
- catch { /* ignore */ }
132
- }
81
+ return this.inMemoryQueue.length;
82
+ }
83
+ /** Total visited count. */
84
+ async visitedCount() {
85
+ if (this.useRedis && this.redis) {
86
+ try {
87
+ return await this.redis.scard(this.visitedKey);
88
+ } catch {
89
+ }
133
90
  }
134
- /** Stats for monitoring. */
135
- async stats() {
136
- return {
137
- backend: this.useRedis && this.redis ? 'redis' : 'memory',
138
- queued: await this.length(),
139
- visited: await this.visitedCount(),
140
- };
91
+ return this.inMemoryVisited.size;
92
+ }
93
+ /** Seed initial URLs (used at job start). */
94
+ async seed(urls) {
95
+ for (const url of urls) await this.push(url);
96
+ }
97
+ /** Clean up all Redis keys for this frontier. Call at job completion. */
98
+ async cleanup() {
99
+ if (this.useRedis && this.redis) {
100
+ try {
101
+ await this.redis.del(this.queueKey, this.visitedKey);
102
+ } catch {
103
+ }
104
+ try {
105
+ await this.redis.quit();
106
+ } catch {
107
+ }
141
108
  }
109
+ }
110
+ /** Stats for monitoring. */
111
+ async stats() {
112
+ return {
113
+ backend: this.useRedis && this.redis ? "redis" : "memory",
114
+ queued: await this.length(),
115
+ visited: await this.visitedCount()
116
+ };
117
+ }
142
118
  }
143
- /** Check if Redis is configured for distributed frontier. */
144
- export function isRedisFrontierEnabled() {
145
- return !!process.env.REDIS_URL;
119
+ function isRedisFrontierEnabled() {
120
+ return !!process.env.REDIS_URL;
146
121
  }
122
+ export {
123
+ RedisCrawlFrontier,
124
+ isRedisFrontierEnabled
125
+ };
126
+ //# sourceMappingURL=redis-frontier.js.map
@@ -1,152 +1,165 @@
1
- /**
2
- * Redis Streams distributed job queue.
3
- *
4
- * Provides horizontal crawler scaling via Redis Streams consumer groups.
5
- * Multiple crawler nodes can pull from the same stream — each job is
6
- * delivered to exactly one consumer (at-least-once via ACK/PENDING).
7
- *
8
- * Used when REDIS_URL is set AND JOB_QUEUE_BACKEND=redis.
9
- * Falls back to the Postgres-backed queue when Redis is unavailable.
10
- *
11
- * Stream key: zeta:crawl:stream
12
- * Group name: zeta:crawl:workers
13
- * Consumer id: zeta:worker:<hostname>:<pid>
14
- */
15
- import { hostname } from 'node:os';
16
- const STREAM_KEY = 'zeta:crawl:stream';
17
- const GROUP_NAME = 'zeta:crawl:workers';
18
- const MAX_LEN = 10_000; // approx cap on stream length
1
+ import { hostname } from "node:os";
2
+ const STREAM_KEY = "zeta:crawl:stream";
3
+ const GROUP_NAME = "zeta:crawl:workers";
4
+ const MAX_LEN = 1e4;
19
5
  function consumerId() {
20
- return `zeta:worker:${hostname()}:${process.pid}`;
6
+ return `zeta:worker:${hostname()}:${process.pid}`;
21
7
  }
22
8
  let ioredis;
23
9
  async function getIoredis() {
24
- if (!ioredis) {
25
- ioredis = await import('ioredis').then(m => m.default ?? m);
26
- }
27
- return ioredis;
10
+ if (!ioredis) {
11
+ ioredis = await import("ioredis").then((m) => m.default ?? m);
12
+ }
13
+ return ioredis;
28
14
  }
29
- /**
30
- * Create a Redis Streams job queue client.
31
- * Throws if REDIS_URL is not set.
32
- */
33
- export async function createRedisQueue() {
34
- const redisUrl = process.env.REDIS_URL;
35
- if (!redisUrl)
36
- throw new Error('REDIS_URL env var required for redis queue backend');
37
- const Redis = await getIoredis();
38
- const redis = new Redis(redisUrl, {
39
- maxRetriesPerRequest: 3,
40
- enableReadyCheck: true,
41
- lazyConnect: false,
42
- });
43
- // Create stream + consumer group if they don't exist
44
- await redis.xgroup('CREATE', STREAM_KEY, GROUP_NAME, '$', 'MKSTREAM').catch((e) => {
45
- if (!e.message?.includes('BUSYGROUP'))
46
- throw e;
47
- });
48
- const consumer = consumerId();
49
- return {
50
- async enqueue(jobId, tenantId, projectId, payload = {}) {
51
- const entryId = await redis.xadd(STREAM_KEY, 'MAXLEN', '~', MAX_LEN, '*', 'jobId', jobId, 'tenantId', tenantId, 'projectId', projectId, 'payload', JSON.stringify(payload), 'enqueuedAt', new Date().toISOString());
52
- return entryId;
53
- },
54
- async dequeue(timeoutMs = 5_000) {
55
- // First drain pending (unacknowledged) messages for this consumer
56
- const pending = await redis.xreadgroup('GROUP', GROUP_NAME, consumer, 'COUNT', '1', 'STREAMS', STREAM_KEY, '0') ?? [];
57
- let entries = pending?.[0]?.[1] ?? [];
58
- if (!entries.length) {
59
- // Block-read for new messages
60
- const fresh = await redis.xreadgroup('GROUP', GROUP_NAME, consumer, 'COUNT', '1', 'BLOCK', timeoutMs, 'STREAMS', STREAM_KEY, '>') ?? [];
61
- entries = fresh?.[0]?.[1] ?? [];
62
- }
63
- if (!entries.length)
64
- return null;
65
- const [entryId, fields] = entries[0];
66
- const obj = {};
67
- for (let i = 0; i < fields.length; i += 2) {
68
- obj[fields[i]] = fields[i + 1];
69
- }
70
- return {
71
- id: entryId,
72
- jobId: obj.jobId,
73
- tenantId: obj.tenantId,
74
- projectId: obj.projectId,
75
- payload: JSON.parse(obj.payload ?? '{}'),
76
- enqueuedAt: obj.enqueuedAt,
77
- };
78
- },
79
- async ack(streamEntryId) {
80
- await redis.xack(STREAM_KEY, GROUP_NAME, streamEntryId);
81
- },
82
- async nack(streamEntryId) {
83
- // Move back to '>'-readable by deleting and re-adding (simplest approach)
84
- // In production, prefer a dead-letter stream instead.
85
- await redis.xack(STREAM_KEY, GROUP_NAME, streamEntryId);
86
- },
87
- async reclaimStale(maxIdleMs = 60_000) {
88
- const result = await redis.xautoclaim(STREAM_KEY, GROUP_NAME, consumer, maxIdleMs, '0-0', 'COUNT', '10');
89
- const entries = Array.isArray(result) ? (result[1] ?? []) : [];
90
- return entries.map(([entryId, fields]) => {
91
- const obj = {};
92
- for (let i = 0; i < fields.length; i += 2)
93
- obj[fields[i]] = fields[i + 1];
94
- return {
95
- id: entryId,
96
- jobId: obj.jobId,
97
- tenantId: obj.tenantId,
98
- projectId: obj.projectId,
99
- payload: JSON.parse(obj.payload ?? '{}'),
100
- enqueuedAt: obj.enqueuedAt,
101
- };
102
- });
103
- },
104
- async stats() {
105
- const info = await redis.xinfo('GROUPS', STREAM_KEY);
106
- // xinfo groups returns array of arrays: [name, ..., pel-count, ..., lag, ...]
107
- const group = info.find((g) => {
108
- const arr = Array.isArray(g) ? g : [];
109
- for (let i = 0; i < arr.length; i += 2) {
110
- if (arr[i] === 'name' && arr[i + 1] === GROUP_NAME)
111
- return true;
112
- }
113
- return false;
114
- });
115
- if (!group)
116
- return { pending: 0, delivered: 0, groupLag: 0 };
117
- const flat = Array.isArray(group) ? group : [];
118
- const get = (key) => {
119
- for (let i = 0; i < flat.length - 1; i += 2) {
120
- if (flat[i] === key)
121
- return Number(flat[i + 1]) || 0;
122
- }
123
- return 0;
124
- };
125
- return {
126
- pending: get('pel-count'),
127
- delivered: get('delivered-count'),
128
- groupLag: get('lag'),
129
- };
130
- },
131
- async close() {
132
- await redis.quit().catch(() => { });
133
- },
134
- };
15
+ async function createRedisQueue() {
16
+ const redisUrl = process.env.REDIS_URL;
17
+ if (!redisUrl) throw new Error("REDIS_URL env var required for redis queue backend");
18
+ const Redis = await getIoredis();
19
+ const redis = new Redis(redisUrl, {
20
+ maxRetriesPerRequest: 3,
21
+ enableReadyCheck: true,
22
+ lazyConnect: false
23
+ });
24
+ await redis.xgroup("CREATE", STREAM_KEY, GROUP_NAME, "$", "MKSTREAM").catch((e) => {
25
+ if (!e.message?.includes("BUSYGROUP")) throw e;
26
+ });
27
+ const consumer = consumerId();
28
+ return {
29
+ async enqueue(jobId, tenantId, projectId, payload = {}) {
30
+ const entryId = await redis.xadd(
31
+ STREAM_KEY,
32
+ "MAXLEN",
33
+ "~",
34
+ MAX_LEN,
35
+ "*",
36
+ "jobId",
37
+ jobId,
38
+ "tenantId",
39
+ tenantId,
40
+ "projectId",
41
+ projectId,
42
+ "payload",
43
+ JSON.stringify(payload),
44
+ "enqueuedAt",
45
+ (/* @__PURE__ */ new Date()).toISOString()
46
+ );
47
+ return entryId;
48
+ },
49
+ async dequeue(timeoutMs = 5e3) {
50
+ const pending = await redis.xreadgroup(
51
+ "GROUP",
52
+ GROUP_NAME,
53
+ consumer,
54
+ "COUNT",
55
+ "1",
56
+ "STREAMS",
57
+ STREAM_KEY,
58
+ "0"
59
+ ) ?? [];
60
+ let entries = pending?.[0]?.[1] ?? [];
61
+ if (!entries.length) {
62
+ const fresh = await redis.xreadgroup(
63
+ "GROUP",
64
+ GROUP_NAME,
65
+ consumer,
66
+ "COUNT",
67
+ "1",
68
+ "BLOCK",
69
+ timeoutMs,
70
+ "STREAMS",
71
+ STREAM_KEY,
72
+ ">"
73
+ ) ?? [];
74
+ entries = fresh?.[0]?.[1] ?? [];
75
+ }
76
+ if (!entries.length) return null;
77
+ const [entryId, fields] = entries[0];
78
+ const obj = {};
79
+ for (let i = 0; i < fields.length; i += 2) {
80
+ obj[fields[i]] = fields[i + 1];
81
+ }
82
+ return {
83
+ id: entryId,
84
+ jobId: obj.jobId,
85
+ tenantId: obj.tenantId,
86
+ projectId: obj.projectId,
87
+ payload: JSON.parse(obj.payload ?? "{}"),
88
+ enqueuedAt: obj.enqueuedAt
89
+ };
90
+ },
91
+ async ack(streamEntryId) {
92
+ await redis.xack(STREAM_KEY, GROUP_NAME, streamEntryId);
93
+ },
94
+ async nack(streamEntryId) {
95
+ await redis.xack(STREAM_KEY, GROUP_NAME, streamEntryId);
96
+ },
97
+ async reclaimStale(maxIdleMs = 6e4) {
98
+ const result = await redis.xautoclaim(
99
+ STREAM_KEY,
100
+ GROUP_NAME,
101
+ consumer,
102
+ maxIdleMs,
103
+ "0-0",
104
+ "COUNT",
105
+ "10"
106
+ );
107
+ const entries = Array.isArray(result) ? result[1] ?? [] : [];
108
+ return entries.map(([entryId, fields]) => {
109
+ const obj = {};
110
+ for (let i = 0; i < fields.length; i += 2) obj[fields[i]] = fields[i + 1];
111
+ return {
112
+ id: entryId,
113
+ jobId: obj.jobId,
114
+ tenantId: obj.tenantId,
115
+ projectId: obj.projectId,
116
+ payload: JSON.parse(obj.payload ?? "{}"),
117
+ enqueuedAt: obj.enqueuedAt
118
+ };
119
+ });
120
+ },
121
+ async stats() {
122
+ const info = await redis.xinfo("GROUPS", STREAM_KEY);
123
+ const group = info.find((g) => {
124
+ const arr = Array.isArray(g) ? g : [];
125
+ for (let i = 0; i < arr.length; i += 2) {
126
+ if (arr[i] === "name" && arr[i + 1] === GROUP_NAME) return true;
127
+ }
128
+ return false;
129
+ });
130
+ if (!group) return { pending: 0, delivered: 0, groupLag: 0 };
131
+ const flat = Array.isArray(group) ? group : [];
132
+ const get = (key) => {
133
+ for (let i = 0; i < flat.length - 1; i += 2) {
134
+ if (flat[i] === key) return Number(flat[i + 1]) || 0;
135
+ }
136
+ return 0;
137
+ };
138
+ return {
139
+ pending: get("pel-count"),
140
+ delivered: get("delivered-count"),
141
+ groupLag: get("lag")
142
+ };
143
+ },
144
+ async close() {
145
+ await redis.quit().catch(() => {
146
+ });
147
+ }
148
+ };
135
149
  }
136
- /**
137
- * Check if Redis queue backend is configured.
138
- */
139
- export function isRedisQueueEnabled() {
140
- return !!(process.env.REDIS_URL && process.env.JOB_QUEUE_BACKEND === 'redis');
150
+ function isRedisQueueEnabled() {
151
+ return !!(process.env.REDIS_URL && process.env.JOB_QUEUE_BACKEND === "redis");
141
152
  }
142
- /**
143
- * Convenience: create queue only if enabled, else return null.
144
- */
145
- export async function maybeCreateRedisQueue() {
146
- if (!isRedisQueueEnabled())
147
- return null;
148
- return createRedisQueue().catch((e) => {
149
- console.error('[redis-queue] Failed to connect:', e.message);
150
- return null;
151
- });
153
+ async function maybeCreateRedisQueue() {
154
+ if (!isRedisQueueEnabled()) return null;
155
+ return createRedisQueue().catch((e) => {
156
+ console.error("[redis-queue] Failed to connect:", e.message);
157
+ return null;
158
+ });
152
159
  }
160
+ export {
161
+ createRedisQueue,
162
+ isRedisQueueEnabled,
163
+ maybeCreateRedisQueue
164
+ };
165
+ //# sourceMappingURL=redis-queue.js.map