@63klabs/cache-data 1.2.2 → 1.2.5

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/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  > Note: This project is still in beta. Even though changes are tested and breaking changes are avoided, things may break. The latest 1.1.x version is stable.
6
6
 
7
+ ## 1.2.5 (2025-06-23)
8
+
9
+ - Updated suggested Lambda environment variables to uppercase: `CACHE_DATA_`
10
+ - Added check for environment variable `DEPLOY_ENVIRONMENT` among current list of variables checked to determine environment.
11
+
7
12
  ## 1.1.6 (2025-05-05) Moving to @63Klabs
8
13
 
9
14
  This package has come a long way and is stable. To enhance its longevity I am moving it out of my personal GitHub and NPM accounts an into an organizational account managed by me (chadkluck).
package/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  A package for node.js applications to access and cache data from remote API endpoints or other sources using AWS S3 and DynamoDb.
4
4
 
5
- > Note: This repository and package is moving to 63Klabs
5
+ > Note: This repository and package has moved from chadkluck to 63Klabs but is still managed by the same developer.
6
6
 
7
- [@chadkluck/cache-data on npmjs.com](https://www.npmjs.com/package/@chadkluck/cache-data)
7
+ [@63klabs/cache-data on npmjs.com](https://www.npmjs.com/package/@63klabs/cache-data)
8
8
 
9
9
  ## Description
10
10
 
@@ -29,7 +29,7 @@ This package has been used in production for applications receiving over 1 milli
29
29
  1. Make sure your function is using an AWS Lambda supported version of Node and has at least 256MB allocated (512-1024MB recommended).
30
30
  2. Add the cache-data environment variables to your Lambda function. Also update your Lambda's execution role to access your S3 and DynamoDb.
31
31
  3. Add an S3 bucket and DynamoDb table to store your cache either in the application CloudFormation template or as separate infrastructure.
32
- 4. Install the @chadkluck/cache-data package `npm install @chadkluck/cache-data`
32
+ 4. Install the @63klabs/cache-data package `npm install @63klabs/cache-data`
33
33
  5. Add the cache code to your Lambda function
34
34
 
35
35
  #### Lambda Memory Allocation
@@ -81,21 +81,22 @@ Resources:
81
81
 
82
82
  Environment:
83
83
  Variables:
84
- detailedLogs: "5" # Use "0" for production
85
- deployEnvironment: "TEST" # "PROD"
86
- paramStore: "/" # SSM Parameter store can use a hierarchy to organize your apps parameters
87
-
88
- # Cache-Data settings (from: https://www.npmjs.com/package/@chadkluck/cache-data)
89
- CacheData_DynamoDbTable: !Ref CacheDataDynamoDbTable
90
- CacheData_S3Bucket: !Ref CacheDataS3Bucket
91
- CacheData_CryptSecureDataAlgorithm: !Ref CacheDataCryptSecureDataAlg
92
- CacheData_CryptIdHashAlgorithm: !Ref CacheDataCryptIdHashAlgorithm
93
- CacheData_DynamoDb_maxCacheSize_kb: !Ref CacheDataDbMaxCacheSizeInKB
94
- CacheData_PurgeExpiredCacheEntriesAfterXHours: !Ref CacheDataPurgeExpiredCacheEntriesInHours
95
- CacheData_ErrorExpirationInSeconds: !Ref CacheDataErrorExpirationInSeconds
96
- CacheData_TimeZoneForInterval: !Ref CacheDataTimeZoneForInterval
97
- CacheData_AWSXRayOn: !Ref CacheDataAWSXRayOn
98
84
 
85
+ NODE_ENV: !If [ IsProduction, "production", "development"] # Note we are past the build installation phase so devDependencies are not installed, however, we can utilize certain tools in development mode
86
+ DEPLOY_ENVIRONMENT: !Ref DeployEnvironment # PROD, TEST, DEV - a different category of environment
87
+ LOG_LEVEL: !If [ IsProduction, "0", "5"] # 0 for prod, 2-5 for non-prod
88
+ PARAM_STORE_PATH: "/" # SSM Parameter store can use a hierarchy to organize your apps parameters
89
+
90
+ # Cache-Data settings (from: https://www.npmjs.com/package/@63klabs/cache-data)
91
+ CACHE_DATA_DYNAMO_DB_TABLE: !Ref CacheDataDynamoDbTable
92
+ CACHE_DATA_S3_BUCKET: !Ref CacheDataS3Bucket
93
+ CACHE_DATA_SECURE_DATA_ALGORITHM: !Ref CacheDataCryptSecureDataAlg
94
+ CACHE_DATA_ID_HASH_ALGORITHM: !Ref CacheDataCryptIdHashAlgorithm
95
+ CACHE_DATA_DYNAMO_DB_MAX_CACHE_SIZE_KB: !Ref CacheDataDbMaxCacheSizeInKB
96
+ CACHE_DATA_PURGE_EXPIRED_CACHE_ENTRIES_AFTER_X_HRS: !Ref CacheDataPurgeExpiredCacheEntriesInHours
97
+ CACHE_DATA_ERROR_EXP_IN_SECONDS: !Ref CacheDataErrorExpirationInSeconds
98
+ CACHE_DATA_TIME_ZONE_FOR_INTERVAL: !Ref CacheDataTimeZoneForInterval
99
+ CACHE_DATA_AWS_X_RAY_ON: !Ref CacheDataAWSXRayOn
99
100
 
100
101
  # -- LambdaFunction Execution Role --
101
102
 
@@ -134,7 +135,7 @@ Resources:
134
135
  Effect: Allow
135
136
  Resource: !GetAtt AppLogGroup.Arn
136
137
 
137
- # cache-data Parameter Read Access (from: https://www.npmjs.com/package/@chadkluck/cache-data)
138
+ # cache-data Parameter Read Access (from: https://www.npmjs.com/package/@63klabs/cache-data)
138
139
  - Sid: LambdaAccessToSSMParameters
139
140
  Action:
140
141
  - ssm:DescribeParameters
@@ -145,7 +146,7 @@ Resources:
145
146
  Resource:
146
147
  - !Sub "arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter${ParameterStoreHierarchy}*"
147
148
 
148
- # cache-data S3 bucket (from: https://www.npmjs.com/package/@chadkluck/cache-data)
149
+ # cache-data S3 bucket (from: https://www.npmjs.com/package/@63klabs/cache-data)
149
150
  - Sid: LambdaAccessToS3BucketCacheData
150
151
  Action:
151
152
  - s3:PutObject
@@ -154,7 +155,7 @@ Resources:
154
155
  Effect: Allow
155
156
  Resource: !Join [ '', [ !GetAtt CacheDataS3Bucket.Arn, '/cache/*' ] ]
156
157
 
157
- # cache-data DynamoDb table (from: https://www.npmjs.com/package/@chadkluck/cache-data)
158
+ # cache-data DynamoDb table (from: https://www.npmjs.com/package/@63klabs/cache-data)
158
159
  - Sid: LambdaAccessToDynamoDBTableCacheData
159
160
  Action:
160
161
  - dynamodb:GetItem
@@ -177,7 +178,7 @@ Parameters:
177
178
 
178
179
  # ---------------------------------------------------------------------------
179
180
  # Cache-Data Parameters
180
- # From: https://www.npmjs.com/package/@chadkluck/cache-data
181
+ # From: https://www.npmjs.com/package/@63klabs/cache-data
181
182
 
182
183
  CacheDataDbMaxCacheSizeInKB:
183
184
  Type: Number
@@ -244,7 +245,7 @@ Resources:
244
245
 
245
246
  # ---------------------------------------------------------------------------
246
247
  # Cache-Data
247
- # From: https://www.npmjs.com/package/@chadkluck/cache-data
248
+ # From: https://www.npmjs.com/package/@63klabs/cache-data
248
249
  # Your Lambda function will need access via the Execution Role
249
250
 
250
251
  # -- Cache-Data DynamoDb Table --
@@ -318,14 +319,14 @@ Resources:
318
319
  #### Install npm Package and Add Starter Code
319
320
 
320
321
  1. Go to your application directory
321
- 2. Run the command `npm i @chadkluck/cache-data`
322
- 3. Add `const { tools, cache, endpoint } = require('@chadkluck/cache-data');` to your script
322
+ 2. Run the command `npm i @63klabs/cache-data`
323
+ 3. Add `const { tools, cache, endpoint } = require('@63klabs/cache-data');` to your script
323
324
  4. Add a Config class to your script. This should be placed before the handler so it only is defined during cold starts. This can also be imported from a separate script.
324
325
  5. Add `Config.init()` after the Config class but before the handler.
325
326
  5. Add `await tools.Config.promise();` in the handler to make sure the Config has completed.
326
327
 
327
328
  ```javascript
328
- const { tools, cache, endpoint } = require('@chadkluck/cache-data');
329
+ const { tools, cache, endpoint } = require('@63klabs/cache-data');
329
330
 
330
331
  class Config extends tools._ConfigSuperClass {
331
332
  static async init() {
@@ -386,7 +387,7 @@ class Config extends tools._ConfigSuperClass {
386
387
  [
387
388
  {
388
389
  "group": "app", // so we can do params.app.weatherapikey later
389
- "path": process.env.paramStore
390
+ "path": process.env.PARAM_STORE_PATH
390
391
  }
391
392
  ]
392
393
  );
@@ -487,7 +488,7 @@ This code can be put into a separate file and brought in using a `require` state
487
488
  /* EXAMPLE USING the this._initParameters method of obtaining parameters during Config.init() */
488
489
 
489
490
  // require cache-data
490
- const { tools, cache, endpoint } = require('@chadkluck/cache-data');
491
+ const { tools, cache, endpoint } = require('@63klabs/cache-data');
491
492
 
492
493
  /**
493
494
  * Extends tools._ConfigSuperClass
@@ -516,7 +517,7 @@ class Config extends tools._ConfigSuperClass {
516
517
  [
517
518
  {
518
519
  "group": "app", // so we can do params.app.weatherapikey later
519
- "path": "/apps/my_cool_app/" // process.env.paramStorePath // or store as a Lambda environment variable
520
+ "path": "/apps/my_cool_app/" // process.env.PARAM_STORE_PATH // or store as a Lambda environment variable
520
521
  }
521
522
  ]
522
523
  );
@@ -634,7 +635,7 @@ Once the `Config` object is initialized, the following code can be used to acces
634
635
  /*
635
636
  Note that cache object was already set by the require statement
636
637
  assuming:
637
- const { tools, cache, endpoint } = require('@chadkluck/cache-data');
638
+ const { tools, cache, endpoint } = require('@63klabs/cache-data');
638
639
  */
639
640
 
640
641
  let connection = Config.getConnection("demo"); // corresponds with the name we gave it during connections.add()
@@ -886,7 +887,7 @@ In its simplist form we can do the following:
886
887
  ```js
887
888
  /*
888
889
  Assuming:
889
- const { tools, cache, endpoint } = require('@chadkluck/cache-data');
890
+ const { tools, cache, endpoint } = require('@63klabs/cache-data');
890
891
  */
891
892
 
892
893
  const timerTaskGetGames = new tools.Timer("Getting games", true); // We give it a name for logging, and we set to true so the timer starts right away
@@ -911,7 +912,7 @@ You are able to get the current time elapsed in milliseconds from a running Time
911
912
  ```js
912
913
  /*
913
914
  Assuming:
914
- const { tools, cache, endpoint } = require('@chadkluck/cache-data');
915
+ const { tools, cache, endpoint } = require('@63klabs/cache-data');
915
916
  */
916
917
 
917
918
  /* increase the log level - comment out when not needed */
@@ -1044,13 +1045,13 @@ console.log( tools.obfuscate(str, opt) );
1044
1045
 
1045
1046
  ### AWS-SDK
1046
1047
 
1047
- The @chadkluck/cache-data package will automatically detect and use the correct AWS SDK based on the version of Node.
1048
+ The @63klabs/cache-data package will automatically detect and use the correct AWS SDK based on the version of Node.
1048
1049
 
1049
1050
  Node 16 environments will use AWS-SDK version 2.
1050
1051
 
1051
1052
  Node 18+ environments will use AWS-SDK version 3.
1052
1053
 
1053
- Note that `package.json` for @chadkluck/cache-data only installs the AWS-SDK on dev environments. This is because AWS Lambda already includes the AWS-SDK without requiring installs. This makes your application lighter and ensures you are always running the most recent SDK release. Given this, that means that AWS SDK v3 is not available in Lambda functions using Node 16, and v2 is not available in Lambda Node >=18 environments.
1054
+ Note that `package.json` for @63klabs/cache-data only installs the AWS-SDK on dev environments. This is because AWS Lambda already includes the AWS-SDK without requiring installs. This makes your application lighter and ensures you are always running the most recent SDK release. Given this, that means that AWS SDK v3 is not available in Lambda functions using Node 16, and v2 is not available in Lambda Node >=18 environments.
1054
1055
 
1055
1056
  Because DynamoDb, S3, and SSM Parameter store are used by cache-data, only those SDKs are included. A client is provided for each along with limited number of commands. To make gets and puts easier a get and put command is mapped for DynamoDb and S3. (Uses appropriate commands underneath for V2 and V3 so your code wouldn't need to change.)
1056
1057
 
@@ -1059,7 +1060,7 @@ Because DynamoDb, S3, and SSM Parameter store are used by cache-data, only those
1059
1060
  When `tools` is imported, you can use the `tools.AWS` object to perform common read/write operations on S3, DynamoDb, and SSM Parameter Store.
1060
1061
 
1061
1062
  ```javascript
1062
- const { tools } = require('@chadkluck/cache-data');
1063
+ const { tools } = require('@63klabs/cache-data');
1063
1064
 
1064
1065
  console.log(`NODE VERSION ${tools.AWS.NODE_VER} USING AWS SDK ${tools.AWS.SDK_VER}`);
1065
1066
  console.log(`REGION: ${tools.AWS.REGION}`); // set from Lambda environment variable AWS_REGION
@@ -1184,7 +1185,7 @@ const dbGetResult = await dbDocClient.send(GetCommand(paramsForGetRecord));
1184
1185
 
1185
1186
  ```javascript
1186
1187
  // Using tools to handle the SDK version and basic calls for you
1187
- const { tools } = require('@chadkluck/cache-data');
1188
+ const { tools } = require('@63klabs/cache-data');
1188
1189
 
1189
1190
  const dbPutResult = await tools.AWS.dynamodb.put(paramsForNewRecord);
1190
1191
  const dbGetResult = await tools.AWS.dynamodb.get(paramsForGetRecrod);
@@ -1203,7 +1204,7 @@ For more on creating parameter/query objects for S3, DynamoDb, and SSM Parameter
1203
1204
  When using AWS SDK version 3, you can import additional commands and use them with the client provided by `tools.AWS`.
1204
1205
 
1205
1206
  ```javascript
1206
- const { tools } = require('@chadkluck/cache-data');
1207
+ const { tools } = require('@63klabs/cache-data');
1207
1208
  const { DeleteObjectCommand } = require('@aws-sdk/client-s3'); // AWS SDK v3
1208
1209
 
1209
1210
  const command = new DeleteObjectCommand({
@@ -1220,7 +1221,7 @@ Because Node 16 and the AWS SDK v2 is being deprecated, this documentation will
1220
1221
 
1221
1222
  ```js
1222
1223
  // NodeJS 16 using AWS SDK v2
1223
- const {tools} = require("@chadkluck/cache-data");
1224
+ const {tools} = require("@63klabs/cache-data");
1224
1225
 
1225
1226
  // using the provided S3 client
1226
1227
  const s3result1 = await tools.AWS.s3.client.putObject(params).promise();
@@ -1253,7 +1254,7 @@ Make sure you have your S3 bucket, DynamoDb table, and SSM Parameter store set u
1253
1254
 
1254
1255
  - [Website](https://chadkluck.me/)
1255
1256
  - [GitHub](https://github.com/chadkluck)
1256
- - [Mastodon: @chadkluck@universeodon.com](https://universeodon.com/@chadkluck)
1257
+ - [Mastodon: @63klabs@universeodon.com](https://universeodon.com/@63klabs)
1257
1258
  - [X: @ChadKluck](https://x.com/chadkluck)
1258
1259
 
1259
1260
  ## Version History
package/SECURITY.md CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  ## Reporting a Vulnerability
4
4
 
5
- Report all vulnerabilities under the [Security menu in the Cache-Data GitHub repository](https://github.com/chadkluck/npm-chadkluck-cache-data/security/advisories).
5
+ Report all vulnerabilities under the [Security menu in the Cache-Data GitHub repository](https://github.com/63klabs/npm-cache-data/security/advisories).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@63klabs/cache-data",
3
- "version": "1.2.2",
3
+ "version": "1.2.5",
4
4
  "description": "Cache data from an API endpoint or application process using AWS S3 and DynamoDb",
5
5
  "author": "Chad Leigh Kluck (https://chadkluck.me)",
6
6
  "license": "MIT",
@@ -17,7 +17,7 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "aws-xray-sdk-core": "^3.6.0",
20
- "moment-timezone": "^0.5.43",
20
+ "moment-timezone": "^0.6.0",
21
21
  "object-hash": "^3.0.0"
22
22
  },
23
23
  "devDependencies": {
@@ -30,7 +30,7 @@
30
30
  "chai-http": "^5.1.1",
31
31
  "lambda-tester": "^4.0.1",
32
32
  "mocha": "^11.1.0",
33
- "sinon": "^20.0.0"
33
+ "sinon": "^21.0.0"
34
34
  },
35
35
  "scripts": {
36
36
  "test": "mocha 'test/**/*-tests.mjs'",
@@ -54,5 +54,5 @@
54
54
  "bugs": {
55
55
  "url": "https://github.com/63klabs/npm-cache-data/issues"
56
56
  },
57
- "homepage": "https://github.com/chadkluck/npm-chadkluck-cache-data#readme"
57
+ "homepage": "https://github.com/63klabs/npm-cache-data#readme"
58
58
  }
@@ -1054,14 +1054,14 @@ class Cache {
1054
1054
  * Sample param object:
1055
1055
  * @example
1056
1056
  * cache.Cache.init({
1057
- * dynamoDbTable: process.env.CacheData_DynamoDbTable,
1058
- * s3Bucket: process.env.CacheData_S3Bucket,
1059
- * secureDataAlgorithm: process.env.CacheData_CryptSecureDataAlgorithm,
1057
+ * dynamoDbTable: process.env.CACHE_DATA_DYNAMO_DB_TABLE,
1058
+ * s3Bucket: process.env.CACHE_DATA_S3_BUCKET,
1059
+ * secureDataAlgorithm: process.env.CACHE_DATA_SECURE_DATA_ALGORITHM,
1060
1060
  * secureDataKey: Buffer.from(params.app.crypt_secureDataKey, cache.Cache.CRYPT_ENCODING),
1061
- * idHashAlgorithm: process.env.CacheData_CryptIdHashAlgorithm,
1062
- * DynamoDbMaxCacheSize_kb: parseInt(process.env.CacheData_DynamoDb_maxCacheSize_kb, 10),
1063
- * purgeExpiredCacheEntriesAfterXHours: parseInt(process.env.CacheData_PurgeExpiredCacheEntriesAfterXHours, 10),
1064
- * timeZoneForInterval: process.env.CacheData_TimeZoneForInterval // if caching on interval, we need a timezone to account for calculating hours, days, and weeks. List: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
1061
+ * idHashAlgorithm: process.env.CACHE_DATA_ID_HASH_ALGORITHM, // sha1, sha256, sha512, etc.
1062
+ * DynamoDbMaxCacheSize_kb: parseInt(process.env.CACHE_DATA_DYNAMO_DB_MAX_CACHE_SIZE_KB, 10),
1063
+ * purgeExpiredCacheEntriesAfterXHours: parseInt(process.env.CACHE_DATA_PURGE_EXPIRED_CACHE_ENTRIES_AFTER_X_HRS, 10),
1064
+ * timeZoneForInterval: process.env.CACHE_DATA_TIME_ZONE_FOR_INTERVAL // if caching on interval, we need a timezone to account for calculating hours, days, and weeks. List: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
1065
1065
  * });
1066
1066
  *
1067
1067
  * @param {Object} parameters
@@ -104,8 +104,8 @@ class DebugAndLog {
104
104
  * @returns {string} The current environment.
105
105
  */
106
106
  static getEnv() {
107
- var possibleVars = ["env", "deployEnvironment", "environment", "stage"]; // this is the application env, not the NODE_ENV
108
- var env = DebugAndLog.PROD; // if env or deployEnvironment not set, fail to safe
107
+ var possibleVars = ["env", "deployEnvironment", "environment", "stage, deploy_environment"]; // this is the application env, not the NODE_ENV
108
+ var env = (process.env?.NODE_ENV === "development" ? DebugAndLog.DEV : DebugAndLog.PROD); // if env or deployEnvironment not set, fail to safe
109
109
 
110
110
  if ( "env" in process ) {
111
111
  for (let i in possibleVars) {
@@ -249,18 +249,18 @@ class _ConfigSuperClass {
249
249
  * let params = await this._initParameters(
250
250
  * [
251
251
  * {
252
- * "group": "appone", // so we can do params.app.authOSTActionsUsername later
253
- * "path": process.env.paramStorePath, // Lambda environment variable
252
+ * "group": "appone", // so we can do params.app.authUsername later
253
+ * "path": process.env.PARAM_STORE_PATH, // Lambda environment variable
254
254
  * "names": [
255
- * "authOSTActionsUsername",
256
- * "authOSTActionsPassword",
257
- * "authExLibrisAPIkey",
255
+ * "authUsername",
256
+ * "authPassword",
257
+ * "authAPIkey",
258
258
  * "crypt_secureDataKey"
259
259
  * ]
260
260
  * }, // OR get all under a single path
261
261
  * {
262
- * "group": "app", // so we can do params.app.authOSTActionsUsername later
263
- * "path": process.env.paramStorePath // Lambda environment variable
262
+ * "group": "app", // so we can do params.app.authUsername later
263
+ * "path": process.env.PARAM_STORE_PATH // Lambda environment variable
264
264
  * }
265
265
  * ]
266
266
  * );
@@ -22,7 +22,7 @@ const nodeVerMinor = AWS.NODE_VER_MINOR;
22
22
  const nodeVerMajorMinor = AWS.NODE_VER_MAJOR_MINOR;
23
23
 
24
24
  if (nodeVerMajor < 16) {
25
- console.error(`Node.js version 16 or higher is required for @chadkluck/cache-data. Version ${nodeVer} detected. Please install at least Node version 16 (>18 preferred) in your environment.`);
25
+ console.error(`Node.js version 16 or higher is required for @63klabs/cache-data. Version ${nodeVer} detected. Please install at least Node version 16 (>18 preferred) in your environment.`);
26
26
  process.exit(1);
27
27
  }
28
28