@zintrust/redis-rpc 2.4.6 → 2.4.7

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 (2) hide show
  1. package/dist/client.js +26 -35
  2. package/package.json +1 -1
package/dist/client.js CHANGED
@@ -1,39 +1,30 @@
1
1
  import { ErrorFactory, isUndefinedOrNull } from '@zintrust/core/runtime';
2
- import { randomUUID } from 'node:crypto';
3
- import http from 'node:http';
4
- import https from 'node:https';
5
2
  import { rpcClientHeaders, rpcServerOptions } from './env.js';
6
- const requestJson = (url, body, headers) => {
7
- return new Promise((resolve, reject) => {
8
- const transport = url.protocol === 'https:' ? https : http;
9
- const request = transport.request(url, {
10
- method: 'POST',
11
- agent: false,
12
- headers: {
13
- ...headers,
14
- 'content-length': String(Buffer.byteLength(body)),
15
- },
16
- }, (response) => {
17
- const chunks = [];
18
- response.setEncoding('utf8');
19
- response.on('data', (chunk) => chunks.push(chunk));
20
- response.on('end', () => {
21
- const text = chunks.join('');
22
- try {
23
- resolve({
24
- statusCode: response.statusCode || 0,
25
- ok: (response.statusCode || 0) >= 200 && (response.statusCode || 0) < 300,
26
- body: isUndefinedOrNull(text.trim()) ? {} : JSON.parse(text),
27
- });
28
- }
29
- catch (error) {
30
- reject(ErrorFactory.createTryCatchError('Redis RPC response parse failed', { error }));
31
- }
32
- });
33
- });
34
- request.on('error', (error) => reject(ErrorFactory.createConnectionError('Redis RPC request failed', { error })));
35
- request.end(body);
36
- });
3
+ const requestJson = async (url, body, headers) => {
4
+ let response;
5
+ try {
6
+ response = await fetch(url, { method: 'POST', headers, body });
7
+ }
8
+ catch (error) {
9
+ throw ErrorFactory.createConnectionError('Redis RPC request failed', { error });
10
+ }
11
+ let text;
12
+ try {
13
+ text = await response.text();
14
+ }
15
+ catch (error) {
16
+ throw ErrorFactory.createTryCatchError('Redis RPC response read failed', { error });
17
+ }
18
+ try {
19
+ return {
20
+ statusCode: response.status,
21
+ ok: response.ok,
22
+ body: isUndefinedOrNull(text.trim()) ? {} : JSON.parse(text),
23
+ };
24
+ }
25
+ catch (error) {
26
+ throw ErrorFactory.createTryCatchError('Redis RPC response parse failed', { error });
27
+ }
37
28
  };
38
29
  const createServiceProxy = (client, service, target) => {
39
30
  return new Proxy(Object.create(null), {
@@ -54,7 +45,7 @@ export const createRedisRpcClient = (options = {}) => {
54
45
  call: async (service, method, payload = {}) => {
55
46
  const url = new URL('/rpc', baseUrl);
56
47
  const body = JSON.stringify({
57
- requestId: randomUUID(),
48
+ requestId: globalThis.crypto.randomUUID(),
58
49
  service,
59
50
  method,
60
51
  payload,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zintrust/redis-rpc",
3
- "version": "2.4.6",
3
+ "version": "2.4.7",
4
4
  "description": "Redis RPC backend for BullMQ queue operations in ZinTrust.",
5
5
  "private": false,
6
6
  "type": "module",