@zintrust/zedgi 2.9.0 → 3.0.2

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.
package/README.md CHANGED
@@ -31,6 +31,10 @@ ZEDGI_REDIS_HEADER=
31
31
  ZEDGI_QUEUE_HEADER=
32
32
  ZEDGI_MYSQL_HEADER=
33
33
  ZEDGI_POSTGRES_HEADER=
34
+
35
+ # Optional Redis credential profile for queues. Falls back to ZEDGI_REDIS_PROFILE.
36
+ ZEDGI_QUEUE_PROFILE=
37
+ ZEDGI_REDIS_PROFILE=
34
38
  ```
35
39
 
36
40
  ## Drivers
@@ -40,6 +44,7 @@ CACHE_DRIVER=redis-zedgi
40
44
  DB_CONNECTION=mysql-zedgi
41
45
  # or DB_CONNECTION=postgres-zedgi
42
46
  # or DB_CONNECTION=pg-zedgi
47
+ QUEUE_CONNECTION=queue-zedgi
43
48
  QUEUE_DRIVER=queue-zedgi
44
49
  ```
45
50
 
@@ -55,11 +60,22 @@ The package uses one shared Zedgi client/options object so account key, signing
55
60
  `queue-zedgi` supports:
56
61
 
57
62
  - `enqueue`
63
+ - `dequeue`
64
+ - `ack`
65
+ - `fail`
58
66
  - `length`
59
67
  - `drain`
60
- - `ack`
61
68
 
62
- Pull-based `dequeue` is intentionally unsupported because the Zedgi queue API does not currently expose a safe visibility-timeout claim operation. Use `queue-zedgi` for producers and monitoring, and run workers against the same Redis service directly.
69
+ Pull-based workers use Zedgi's Redis RPC BullMQ-intent operations, so `queue-zedgi`
70
+ can be used for producers, monitoring, and consumers. When `QUEUE_CONNECTION` and
71
+ `QUEUE_DRIVER` are both present, ZinTrust resolves `QUEUE_CONNECTION` first; set it
72
+ to `queue-zedgi` to keep workers, monitors, and producers on the same Zedgi-backed
73
+ Redis target.
74
+
75
+ When `ZEDGI_QUEUE_PROFILE` is set, the queue driver uses that named Redis
76
+ credential profile. ZinTrust registers the profile with the configured Redis DB
77
+ (`REDIS_QUEUE_DB` or `WORKERS_REDIS_QUEUE_DB`) so BullMQ keys are read from the
78
+ intended logical database.
63
79
 
64
80
  ## Registration
65
81
 
@@ -4,6 +4,7 @@ type RedisConfig = {
4
4
  db?: number;
5
5
  database?: number;
6
6
  header?: Record<string, unknown>;
7
+ profile?: string;
7
8
  };
8
9
  declare const createZedgiMonitorDriver: (config: RedisConfig) => QueueDriver;
9
10
  export { createZedgiMonitorDriver };
@@ -111,6 +111,7 @@ const createZedgiMonitorDriver = (config) => {
111
111
  password: config.password,
112
112
  database: config.db ?? config.database,
113
113
  header: config.header,
114
+ profile: config.profile,
114
115
  });
115
116
  return {
116
117
  enqueue: createZedgiEnqueue(getQueueConfig),
@@ -1,5 +1,4 @@
1
1
  import { Env } from '@zintrust/core/config';
2
- import { ErrorFactory } from '@zintrust/core/errors';
3
2
  import { generateUuid } from '@zintrust/core/utils';
4
3
  import { ZedgiRuntime } from './ZedgiRuntime.js';
5
4
  const resolveRequestedJobId = (payload) => {
@@ -32,6 +31,17 @@ const resolveJobId = (result, fallback) => {
32
31
  }
33
32
  return fallback;
34
33
  };
34
+ const resolveVisibilityTimeoutMs = () => Env.getInt('QUEUE_ZEDGI_VISIBILITY_TIMEOUT_MS', Env.getInt('QUEUE_REDIS_VISIBILITY_TIMEOUT_MS', 30_000));
35
+ const callQueueRpc = async (config, queueName, method, payload) => {
36
+ const redis = ZedgiRuntime.redis(config);
37
+ if (typeof redis.hook === 'function') {
38
+ return redis.hook(`bull:${method}`, {
39
+ target: queueName,
40
+ ...payload,
41
+ });
42
+ }
43
+ throw new Error('Zedgi Redis RPC hook support is required for queue consumption');
44
+ };
35
45
  const createDriver = (config) => {
36
46
  const queue = (name) => ZedgiRuntime.queue(name, config);
37
47
  return {
@@ -40,11 +50,31 @@ const createDriver = (config) => {
40
50
  const result = await queue(queueName).add(`${queueName}-job`, payload, createJobOptions(payload, fallbackJobId));
41
51
  return resolveJobId(result, fallbackJobId);
42
52
  },
43
- async dequeue(_queueName) {
44
- throw ErrorFactory.createConfigError('queue-zedgi does not support pull-based dequeue yet because the Zedgi queue API does not expose a safe visibility-timeout claim operation. Use it for enqueue and monitoring, or run workers against the same Redis service.');
53
+ async dequeue(queueName) {
54
+ const visibilityTimeoutMs = resolveVisibilityTimeoutMs();
55
+ const client = queue(queueName);
56
+ if (typeof client.dequeue === 'function') {
57
+ return client.dequeue(visibilityTimeoutMs);
58
+ }
59
+ return callQueueRpc(config, queueName, 'dequeue', {
60
+ visibilityTimeoutMs,
61
+ });
45
62
  },
46
63
  async ack(queueName, id) {
47
- await queue(queueName).removeJob(id);
64
+ const client = queue(queueName);
65
+ if (typeof client.ack === 'function') {
66
+ await client.ack(id, 'acknowledged');
67
+ return;
68
+ }
69
+ await callQueueRpc(config, queueName, 'ack', { args: [id, 'acknowledged'] });
70
+ },
71
+ async fail(queueName, id, reason = 'failed by queue-zedgi worker') {
72
+ const client = queue(queueName);
73
+ if (typeof client.fail === 'function') {
74
+ await client.fail(id, reason);
75
+ return;
76
+ }
77
+ await callQueueRpc(config, queueName, 'fail', { args: [id, reason] });
48
78
  },
49
79
  async length(queueName) {
50
80
  return queue(queueName).count();
@@ -112,6 +112,15 @@ const redisCredentialFromConfig = (config, fallbackHeaderKey) => {
112
112
  credential['header'] = header;
113
113
  return credential;
114
114
  };
115
+ const resolveCredentialProfile = (config) => {
116
+ if (config === null || typeof config !== 'object')
117
+ return undefined;
118
+ const profile = config.profile;
119
+ if (typeof profile !== 'string')
120
+ return undefined;
121
+ const normalized = profile.trim();
122
+ return normalized === '' ? undefined : normalized;
123
+ };
115
124
  const sqlCredentialFromConfig = (config, fallbackHeaderKey) => {
116
125
  const credential = {};
117
126
  if (hasText(config.username))
@@ -144,10 +153,22 @@ export const ZedgiRuntime = Object.freeze({
144
153
  client = undefined;
145
154
  },
146
155
  redis(config = {}) {
156
+ const explicitProfile = resolveCredentialProfile(config);
157
+ if (explicitProfile !== undefined) {
158
+ const credential = redisCredentialFromConfig(config, 'ZEDGI_REDIS_HEADER');
159
+ registerProfile('redis', explicitProfile, credential);
160
+ return ensureClient().redis(explicitProfile);
161
+ }
147
162
  const credential = memoizeCredential('redis', 'redis', redisCredentialFromConfig(config, 'ZEDGI_REDIS_HEADER'), redisCredentials);
148
163
  return ensureClient().redis(getProfileName(credential));
149
164
  },
150
165
  queue(name, config = {}) {
166
+ const explicitProfile = resolveCredentialProfile(config);
167
+ if (explicitProfile !== undefined) {
168
+ const credential = redisCredentialFromConfig(config, 'ZEDGI_QUEUE_HEADER');
169
+ registerProfile('redis', explicitProfile, credential);
170
+ return ensureClient().queue(name, explicitProfile);
171
+ }
151
172
  const credential = memoizeCredential('redis', 'redis', redisCredentialFromConfig(config, 'ZEDGI_QUEUE_HEADER'), redisCredentials);
152
173
  return ensureClient().queue(name, getProfileName(credential));
153
174
  },
package/dist/types.d.ts CHANGED
@@ -18,6 +18,7 @@ export type ZedgiQueueConfig = {
18
18
  password?: string;
19
19
  database?: number;
20
20
  header?: Record<string, unknown>;
21
+ profile?: string;
21
22
  };
22
23
  export type CacheDriver = {
23
24
  get<T>(key: string): Promise<T | null>;
@@ -58,6 +59,7 @@ export type QueueDriver = {
58
59
  enqueue(queue: string, payload: BullMQPayload): Promise<string>;
59
60
  dequeue<T = unknown>(queue: string): Promise<QueueMessage<T> | undefined>;
60
61
  ack(queue: string, id: string): Promise<void>;
62
+ fail?(queue: string, id: string, reason?: string): Promise<void>;
61
63
  length(queue: string): Promise<number>;
62
64
  drain(queue: string): Promise<void>;
63
65
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zintrust/zedgi",
3
- "version": "2.9.0",
3
+ "version": "3.0.2",
4
4
  "description": "Zedgi HTTPS transport drivers for ZinTrust cache, database, and queue.",
5
5
  "private": false,
6
6
  "type": "module",
@@ -44,4 +44,4 @@
44
44
  "build": "tsc -p tsconfig.json",
45
45
  "prepublishOnly": "npm run build"
46
46
  }
47
- }
47
+ }
@@ -1,99 +0,0 @@
1
- {
2
- "name": "@zintrust/zedgi",
3
- "version": "2.9.0",
4
- "buildDate": "2026-07-02T15:55:52.782Z",
5
- "buildEnvironment": {
6
- "node": "v20.20.2",
7
- "platform": "linux",
8
- "arch": "x64"
9
- },
10
- "git": {
11
- "commit": "79062f7f",
12
- "branch": "master"
13
- },
14
- "package": {
15
- "engines": {
16
- "node": ">=20.0.0"
17
- },
18
- "dependencies": [
19
- "@zedgi/zedgi-client"
20
- ],
21
- "peerDependencies": [
22
- "@zintrust/core"
23
- ]
24
- },
25
- "files": {
26
- "ZedgiCacheDriver.d.ts": {
27
- "size": 213,
28
- "sha256": "8d90873a95474d3c6461f0a4a5c79ecd3ea4a1b66e1e36caa890675ee6238d25"
29
- },
30
- "ZedgiCacheDriver.js": {
31
- "size": 2063,
32
- "sha256": "76cfb566a2f7ea53ae0431fdfac904bfb44665fe12267909a717027dc5460ed1"
33
- },
34
- "ZedgiDatabaseAdapter.d.ts": {
35
- "size": 225,
36
- "sha256": "b7eb5ad57871368e387e7782656b8cb24a4435d66320ad81d691ec5ff9b2daa8"
37
- },
38
- "ZedgiDatabaseAdapter.js": {
39
- "size": 4344,
40
- "sha256": "67b543a3c3aa778a30a33138223d73810885592c34046d56311e56480f981bd7"
41
- },
42
- "ZedgiMonitorDriver.d.ts": {
43
- "size": 307,
44
- "sha256": "f08ef07ea4f037e2997a2f8a7cdf39ee8d0dc5f0eb19d9141f5d5a790dd47992"
45
- },
46
- "ZedgiMonitorDriver.js": {
47
- "size": 4874,
48
- "sha256": "fee2719d0b16d3538a1a8e0314081218520e5a9e6679c38a31808c7a003391ab"
49
- },
50
- "ZedgiQueueDriver.d.ts": {
51
- "size": 203,
52
- "sha256": "3c53da5178ad6cb7a6f7b38faec8046027374c02dc2a6737d611dcda7504f9f1"
53
- },
54
- "ZedgiQueueDriver.js": {
55
- "size": 2616,
56
- "sha256": "be242b00ab170d0c8f03ce53ca3962954eaa723a5f77635e41fa43577010eb9a"
57
- },
58
- "ZedgiRedisExecutor.d.ts": {
59
- "size": 295,
60
- "sha256": "9fbcc47ef25549ff15bc958863e78257e6098c0fa7234517bb9b3e85d6de8838"
61
- },
62
- "ZedgiRedisExecutor.js": {
63
- "size": 681,
64
- "sha256": "c5defa05f4e6e4764f1d7328c9e8df8c2a727741e08fac27c1155aeb7400f380"
65
- },
66
- "ZedgiRuntime.d.ts": {
67
- "size": 2201,
68
- "sha256": "991a93be66585ee627121ace81c9cd745d508e8d0de67b2a42e674af44db1c77"
69
- },
70
- "ZedgiRuntime.js": {
71
- "size": 6033,
72
- "sha256": "a0401155f4004b192405b0e2f553e0768592ce26d6b0e727ad51280fef00be79"
73
- },
74
- "index.d.ts": {
75
- "size": 455,
76
- "sha256": "91891bce604051300c6e9bfa1a0d1d4583fbbf9abb1c4c657dd2c142af8d5a82"
77
- },
78
- "index.js": {
79
- "size": 494,
80
- "sha256": "435173dc9c0cc295b14e41623c35b40dd55e4b20a9f5de78a24c07e81a457a2e"
81
- },
82
- "register.d.ts": {
83
- "size": 617,
84
- "sha256": "119d77308db3a17052926c95ea145d580a3ebecd57f69429cc1c07af89d83ac9"
85
- },
86
- "register.js": {
87
- "size": 2516,
88
- "sha256": "45eb897f2c8b34a3953a19fda2697fd3ef09e5d64aee8d858d936b06d4298ef1"
89
- },
90
- "types.d.ts": {
91
- "size": 2172,
92
- "sha256": "2524dffbd9f01f4d546f488ea84d6344796f92b577c573b8b4a48b24c48a12e8"
93
- },
94
- "types.js": {
95
- "size": 11,
96
- "sha256": "8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"
97
- }
98
- }
99
- }