eip-cloud-services 1.0.9 → 1.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eip-cloud-services",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "Houses a collection of helpers for connecting with Cloud services.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,4 +22,4 @@
22
22
  "mysql": "^2.18.1",
23
23
  "redis": "^4.6.7"
24
24
  }
25
- }
25
+ }
package/src/redis.js CHANGED
@@ -49,6 +49,37 @@ exports.keys = async ( pattern ) => {
49
49
  }
50
50
  };
51
51
 
52
+ /**
53
+ * Iteratively scans through keys in the Redis database.
54
+ * @param {number} cursor - The cursor to start scanning from. Use 0 to start a new scan.
55
+ * @param {string} [matchPattern='*'] - The pattern to match keys against. Defaults to '*' to match all keys.
56
+ * @param {number} [count=100] - The number of keys to return per call. Defaults to 100.
57
+ * @returns {Promise<Array>} - A promise that resolves with an array containing the next cursor and an array of keys.
58
+ *
59
+ * @description
60
+ * This method uses the SCAN command to iteratively scan through the keys in the Redis database.
61
+ * It allows for efficient scanning of large datasets without the risk of blocking the server for a long time.
62
+ * The method returns a promise that resolves with an array, where the first element is the next cursor to be used
63
+ * for subsequent calls, and the second element is an array of keys that matched the pattern.
64
+ */
65
+ exports.scan = async ( cursor, matchPattern = '*', count = 100 ) => {
66
+ try {
67
+ const client = await getClient ();
68
+
69
+ const commandArgs = [
70
+ String ( cursor ),
71
+ 'MATCH', matchPattern.startsWith ( config.redis.prefix ) ? matchPattern : config.redis.prefix + matchPattern,
72
+ 'COUNT', String ( count ),
73
+ ];
74
+
75
+ return await client.sendCommand ( [ 'SCAN', ...commandArgs ] );
76
+ }
77
+ catch ( error ) {
78
+ console.log ( 'REDIS LIB ERROR [scan]', error );
79
+ throw error;
80
+ }
81
+ };
82
+
52
83
  /**
53
84
  * Retrieves the value of a key.
54
85
  * @param {string} key - The key to retrieve.
package/src/s3.js CHANGED
@@ -105,14 +105,14 @@ exports.get = async ( key, bucket = config.s3.Bucket ) => {
105
105
  data = zlib.unzipSync ( data );
106
106
  }
107
107
 
108
- if ( response.ContentType !== 'application/json' ) {
108
+ if ( response.ContentType !== 'application/json' && !response.Metadata[ 'tmg-json' ] ) {
109
109
  if ( config.s3.logs === 'output' )
110
110
  log ( `S3 [GET]: Returned ${response.ContentType} from ${bucket}/${key}.` );
111
111
 
112
112
  return data.toString ( 'utf8' );
113
113
  }
114
114
 
115
- if ( response.ContentType === 'application/json' && response.Metadata[ 'tmg-crypt' ] && response.Metadata[ 'tmg-crypt-vec' ] ) {
115
+ if ( ( response.ContentType === 'application/json' || response.Metadata[ 'tmg-json' ] ) && response.Metadata[ 'tmg-crypt' ] && response.Metadata[ 'tmg-crypt-vec' ] ) {
116
116
  const key = await crypto.subtle.importKey (
117
117
  'raw',
118
118
  Buffer.from ( response.Metadata[ 'tmg-crypt' ], 'base64' ),
@@ -172,7 +172,7 @@ exports.set = async ( key, body, options = {} ) => {
172
172
  metadata = {}
173
173
  } = options;
174
174
 
175
- if ( encrypt && contentType === 'application/json' ) {
175
+ if ( encrypt && ( contentType === 'application/json' || contentType === 'text/plain' ) ) {
176
176
 
177
177
  if ( config.s3.logs === 'verbose' )
178
178
  log ( `S3 [SET]: ${bucket}/${key} - Encrypting.` );