eip-cloud-services 1.2.2 → 1.2.3
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/package.json +1 -1
- package/src/redis.js +16 -8
- package/src/s3.js +12 -16
package/package.json
CHANGED
package/src/redis.js
CHANGED
|
@@ -8,6 +8,11 @@ if ( fs.existsSync ( configDirPath ) && fs.statSync ( configDirPath ).isDirector
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
const clients = {};
|
|
11
|
+
const applyPrefix = (value) => {
|
|
12
|
+
const prefix = config?.redis?.prefix;
|
|
13
|
+
if (!prefix || typeof value !== 'string') return value;
|
|
14
|
+
return value.startsWith(prefix) ? value : `${prefix}${value}`;
|
|
15
|
+
};
|
|
11
16
|
|
|
12
17
|
/**
|
|
13
18
|
* Creates or retrieves a Redis client instance based on a given client identifier.
|
|
@@ -725,9 +730,10 @@ exports.setExpiry = async ( key, seconds = 0 ) => {
|
|
|
725
730
|
exports.publish = async ( channel, message ) => {
|
|
726
731
|
try {
|
|
727
732
|
if ( typeof channel === 'string' && typeof message === 'string' ) {
|
|
728
|
-
const
|
|
733
|
+
const fullChannel = applyPrefix ( channel );
|
|
734
|
+
const client = await getClient ( `${fullChannel}_pub` );
|
|
729
735
|
|
|
730
|
-
return client.publish (
|
|
736
|
+
return client.publish ( fullChannel, message );
|
|
731
737
|
}
|
|
732
738
|
|
|
733
739
|
throw new Error ( 'redis.publish expects string types for both channel and message' );
|
|
@@ -749,15 +755,16 @@ exports.publish = async ( channel, message ) => {
|
|
|
749
755
|
exports.subscribe = async ( channel, messageHandler ) => {
|
|
750
756
|
try {
|
|
751
757
|
if ( typeof channel === 'string' && typeof messageHandler === 'function' ) {
|
|
752
|
-
const
|
|
758
|
+
const fullChannel = applyPrefix ( channel );
|
|
759
|
+
const client = await getClient ( `${fullChannel}_sub` );
|
|
753
760
|
|
|
754
761
|
client.on ( 'message', ( receivedChannel, message ) => {
|
|
755
|
-
if ( receivedChannel ===
|
|
762
|
+
if ( receivedChannel === fullChannel ) {
|
|
756
763
|
messageHandler ( message );
|
|
757
764
|
}
|
|
758
765
|
} );
|
|
759
766
|
|
|
760
|
-
await client.subscribe (
|
|
767
|
+
await client.subscribe ( fullChannel );
|
|
761
768
|
|
|
762
769
|
return;
|
|
763
770
|
}
|
|
@@ -781,12 +788,13 @@ exports.subscribe = async ( channel, messageHandler ) => {
|
|
|
781
788
|
exports.unsubscribe = async ( channel ) => {
|
|
782
789
|
try {
|
|
783
790
|
if ( typeof channel === 'string' ) {
|
|
784
|
-
const
|
|
791
|
+
const fullChannel = applyPrefix ( channel );
|
|
792
|
+
const client = await getClient ( `${fullChannel}_sub` );
|
|
785
793
|
|
|
786
794
|
client.removeAllListeners ( 'message' );
|
|
787
795
|
|
|
788
|
-
await client.unsubscribe (
|
|
789
|
-
await deleteClient ( `${
|
|
796
|
+
await client.unsubscribe ( fullChannel );
|
|
797
|
+
await deleteClient ( `${fullChannel}_sub` );
|
|
790
798
|
|
|
791
799
|
return;
|
|
792
800
|
}
|
package/src/s3.js
CHANGED
|
@@ -197,13 +197,14 @@ exports.get = async ( key, bucket = config?.s3?.Bucket, options = {} ) => {
|
|
|
197
197
|
* @description Sets an object in S3 with the provided key, body, and optional parameters.
|
|
198
198
|
*/
|
|
199
199
|
exports.set = async ( key, body, options = {} ) => {
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
200
|
+
const {
|
|
201
|
+
bucket = config?.s3?.Bucket,
|
|
202
|
+
contentType = 'application/json',
|
|
203
|
+
acl = 'public-read',
|
|
204
|
+
cacheControl = 'max-age=25,s-maxage=30,must-revalidate',
|
|
205
|
+
encrypt = false,
|
|
206
|
+
metadata = {}
|
|
207
|
+
} = options;
|
|
207
208
|
|
|
208
209
|
if ( encrypt && ( contentType === 'application/json' || contentType === 'text/plain' ) ) {
|
|
209
210
|
|
|
@@ -233,21 +234,16 @@ exports.set = async ( key, body, options = {} ) => {
|
|
|
233
234
|
}
|
|
234
235
|
|
|
235
236
|
try {
|
|
236
|
-
const
|
|
237
|
+
const command = new PutObjectCommand ( {
|
|
237
238
|
Bucket: bucket,
|
|
238
239
|
Key: key,
|
|
239
240
|
Body: body,
|
|
240
241
|
ContentType: contentType,
|
|
242
|
+
ACL: acl,
|
|
241
243
|
CacheControl: cacheControl,
|
|
242
244
|
Metadata: metadata,
|
|
243
245
|
ContentLength: Buffer.byteLength ( body )
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
if ( acl !== null && acl !== undefined && acl !== false ) {
|
|
247
|
-
params.ACL = acl;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const command = new PutObjectCommand ( params );
|
|
246
|
+
} );
|
|
251
247
|
|
|
252
248
|
const data = await S3.send ( command );
|
|
253
249
|
|
|
@@ -412,4 +408,4 @@ const streamToBuffer = async ( stream ) => {
|
|
|
412
408
|
await pipelineAsync ( stream, collectorStream );
|
|
413
409
|
|
|
414
410
|
return Buffer.concat ( chunks );
|
|
415
|
-
};
|
|
411
|
+
};
|