b23-lib 1.2.13 → 1.4.0

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/dist/index.d.mts CHANGED
@@ -50,8 +50,9 @@ declare class DynamoDBUtility {
50
50
  }>;
51
51
  updateItem(TableName: string, key: object, condition: string, update: string, attributeName?: Record<string, string>, attributeValue?: Record<string, AttributeValue>, ReturnValues?: ReturnValue, ReturnValuesOnFailure?: ReturnValuesOnConditionCheckFailure): Promise<Record<string, any>>;
52
52
  deleteItem(TableName: string, key: object, condition: string, attributeName?: Record<string, string>, attributeValue?: Record<string, AttributeValue>, ReturnValues?: ReturnValue, ReturnValuesOnFailure?: ReturnValuesOnConditionCheckFailure): Promise<Record<string, any>>;
53
- getItemByIndex(TableName: string, index: string, keyCondition: string, consistent?: boolean, projection?: string, attributeName?: Record<string, string>, attributeValue?: Record<string, AttributeValue>): Promise<{
53
+ getItemByIndex(TableName: string, index: string, keyCondition: string, consistent?: boolean, projection?: string, attributeName?: Record<string, string>, attributeValue?: Record<string, AttributeValue>, lastEvaluatedKey?: Record<string, AttributeValue>): Promise<{
54
54
  Items: Record<string, any>[];
55
+ lastEvaluatedKey: Record<string, AttributeValue> | undefined;
55
56
  }>;
56
57
  }
57
58
 
@@ -248,11 +249,12 @@ interface AuthUtilityConfig {
248
249
  adminPublicKeys: StringifiedJSONArray;
249
250
  }
250
251
  declare const DefaultAuthUtilityConfig: Readonly<AuthUtilityConfig>;
251
- type AuthTokenType = 'Anon' | 'User' | 'System' | 'Admin';
252
+ type AuthTokenType = 'Anon' | 'User' | 'System' | 'Admin' | 'CDN';
252
253
  interface AuthMiddlewareConfig {
253
254
  allowAnonymous: boolean;
254
255
  allowSystem: boolean;
255
256
  allowUser: boolean;
257
+ allowCDN: boolean;
256
258
  }
257
259
  declare const DefaultAuthMiddlewareConfig: Readonly<AuthMiddlewareConfig>;
258
260
  /**
package/dist/index.d.ts CHANGED
@@ -50,8 +50,9 @@ declare class DynamoDBUtility {
50
50
  }>;
51
51
  updateItem(TableName: string, key: object, condition: string, update: string, attributeName?: Record<string, string>, attributeValue?: Record<string, AttributeValue>, ReturnValues?: ReturnValue, ReturnValuesOnFailure?: ReturnValuesOnConditionCheckFailure): Promise<Record<string, any>>;
52
52
  deleteItem(TableName: string, key: object, condition: string, attributeName?: Record<string, string>, attributeValue?: Record<string, AttributeValue>, ReturnValues?: ReturnValue, ReturnValuesOnFailure?: ReturnValuesOnConditionCheckFailure): Promise<Record<string, any>>;
53
- getItemByIndex(TableName: string, index: string, keyCondition: string, consistent?: boolean, projection?: string, attributeName?: Record<string, string>, attributeValue?: Record<string, AttributeValue>): Promise<{
53
+ getItemByIndex(TableName: string, index: string, keyCondition: string, consistent?: boolean, projection?: string, attributeName?: Record<string, string>, attributeValue?: Record<string, AttributeValue>, lastEvaluatedKey?: Record<string, AttributeValue>): Promise<{
54
54
  Items: Record<string, any>[];
55
+ lastEvaluatedKey: Record<string, AttributeValue> | undefined;
55
56
  }>;
56
57
  }
57
58
 
@@ -248,11 +249,12 @@ interface AuthUtilityConfig {
248
249
  adminPublicKeys: StringifiedJSONArray;
249
250
  }
250
251
  declare const DefaultAuthUtilityConfig: Readonly<AuthUtilityConfig>;
251
- type AuthTokenType = 'Anon' | 'User' | 'System' | 'Admin';
252
+ type AuthTokenType = 'Anon' | 'User' | 'System' | 'Admin' | 'CDN';
252
253
  interface AuthMiddlewareConfig {
253
254
  allowAnonymous: boolean;
254
255
  allowSystem: boolean;
255
256
  allowUser: boolean;
257
+ allowCDN: boolean;
256
258
  }
257
259
  declare const DefaultAuthMiddlewareConfig: Readonly<AuthMiddlewareConfig>;
258
260
  /**
package/dist/index.js CHANGED
@@ -231,12 +231,13 @@ var DynamoDBUtility = class {
231
231
  this.log("Delete", result.ConsumedCapacity, result.ItemCollectionMetrics);
232
232
  return (0, import_util_dynamodb.unmarshall)(result.Attributes || {});
233
233
  }
234
- async getItemByIndex(TableName, index, keyCondition, consistent = false, projection, attributeName, attributeValue) {
234
+ async getItemByIndex(TableName, index, keyCondition, consistent = false, projection, attributeName, attributeValue, lastEvaluatedKey) {
235
235
  const input = {
236
236
  TableName,
237
237
  IndexName: index,
238
238
  KeyConditionExpression: keyCondition,
239
239
  ExpressionAttributeValues: attributeValue,
240
+ ExclusiveStartKey: lastEvaluatedKey,
240
241
  ConsistentRead: consistent,
241
242
  ProjectionExpression: projection,
242
243
  ExpressionAttributeNames: attributeName,
@@ -244,8 +245,11 @@ var DynamoDBUtility = class {
244
245
  };
245
246
  const command = new import_client_dynamodb.QueryCommand(input);
246
247
  const result = await this.client.send(command);
247
- this.log("Query", result.ConsumedCapacity);
248
- return { Items: result.Items?.map((item) => (0, import_util_dynamodb.unmarshall)(item)) || [] };
248
+ this.log("GetItemByIndex", result.ConsumedCapacity);
249
+ return {
250
+ Items: result.Items?.map((item) => (0, import_util_dynamodb.unmarshall)(item)) || [],
251
+ lastEvaluatedKey: result.LastEvaluatedKey
252
+ };
249
253
  }
250
254
  };
251
255
  var Dynamodb_default = DynamoDBUtility;
@@ -433,6 +437,7 @@ var ErrorTypes_default = Object.freeze({
433
437
  ANONYMOUS_SESSION_NOT_ALLOWED: "Anonymous Session Not Allowed",
434
438
  USER_SESSION_NOT_ALLOWED: "User Session Not Allowed",
435
439
  SYSTEM_SESSION_NOT_ALLOWED: "System Session Not Allowed",
440
+ CDN_SESSION_NOT_ALLOWED: "CDN Session Not Allowed",
436
441
  INTERNAL_SERVER_ERROR: "Internal Server Error"
437
442
  });
438
443
 
@@ -685,7 +690,8 @@ var DefaultAuthUtilityConfig = {
685
690
  var DefaultAuthMiddlewareConfig = {
686
691
  allowAnonymous: false,
687
692
  allowSystem: true,
688
- allowUser: true
693
+ allowUser: true,
694
+ allowCDN: false
689
695
  };
690
696
  var AuthUtility = class {
691
697
  maxTokenAge;
@@ -828,7 +834,7 @@ var AuthUtility = class {
828
834
  * @param config Configuration for middleware behavior.
829
835
  */
830
836
  AuthMiddleware(config = DefaultAuthMiddlewareConfig) {
831
- const { allowAnonymous, allowSystem, allowUser } = { ...DefaultAuthMiddlewareConfig, ...config };
837
+ const { allowAnonymous, allowSystem, allowUser, allowCDN } = { ...DefaultAuthMiddlewareConfig, ...config };
832
838
  return async (req, res, next) => {
833
839
  try {
834
840
  const [authType, token] = req.get("Authorization")?.split(" ") || [];
@@ -852,6 +858,11 @@ var AuthUtility = class {
852
858
  payload = await this.verifyAdminToken(token);
853
859
  Logger_default.logMessage("AuthMiddleware", `Admin Id - ${payload.id}`);
854
860
  break;
861
+ case "CDN":
862
+ if (!allowCDN) throw response_default.generateError(403, ErrorTypes_default.CDN_SESSION_NOT_ALLOWED);
863
+ (0, import_assert.default)(["E3CQMOP5FX6KD1", "E3TNCKKZ3FOX9W"].includes(token), ErrorTypes_default.INVALID_TOKEN);
864
+ Logger_default.logMessage("AuthMiddleware", `CDN DistributionId - ${token}`);
865
+ break;
855
866
  default:
856
867
  throw response_default.generateError(403, ErrorTypes_default.INVALID_AUTH_TYPE);
857
868
  }
package/dist/index.mjs CHANGED
@@ -202,12 +202,13 @@ var DynamoDBUtility = class {
202
202
  this.log("Delete", result.ConsumedCapacity, result.ItemCollectionMetrics);
203
203
  return unmarshall(result.Attributes || {});
204
204
  }
205
- async getItemByIndex(TableName, index, keyCondition, consistent = false, projection, attributeName, attributeValue) {
205
+ async getItemByIndex(TableName, index, keyCondition, consistent = false, projection, attributeName, attributeValue, lastEvaluatedKey) {
206
206
  const input = {
207
207
  TableName,
208
208
  IndexName: index,
209
209
  KeyConditionExpression: keyCondition,
210
210
  ExpressionAttributeValues: attributeValue,
211
+ ExclusiveStartKey: lastEvaluatedKey,
211
212
  ConsistentRead: consistent,
212
213
  ProjectionExpression: projection,
213
214
  ExpressionAttributeNames: attributeName,
@@ -215,8 +216,11 @@ var DynamoDBUtility = class {
215
216
  };
216
217
  const command = new QueryCommand(input);
217
218
  const result = await this.client.send(command);
218
- this.log("Query", result.ConsumedCapacity);
219
- return { Items: result.Items?.map((item) => unmarshall(item)) || [] };
219
+ this.log("GetItemByIndex", result.ConsumedCapacity);
220
+ return {
221
+ Items: result.Items?.map((item) => unmarshall(item)) || [],
222
+ lastEvaluatedKey: result.LastEvaluatedKey
223
+ };
220
224
  }
221
225
  };
222
226
  var Dynamodb_default = DynamoDBUtility;
@@ -404,6 +408,7 @@ var ErrorTypes_default = Object.freeze({
404
408
  ANONYMOUS_SESSION_NOT_ALLOWED: "Anonymous Session Not Allowed",
405
409
  USER_SESSION_NOT_ALLOWED: "User Session Not Allowed",
406
410
  SYSTEM_SESSION_NOT_ALLOWED: "System Session Not Allowed",
411
+ CDN_SESSION_NOT_ALLOWED: "CDN Session Not Allowed",
407
412
  INTERNAL_SERVER_ERROR: "Internal Server Error"
408
413
  });
409
414
 
@@ -656,7 +661,8 @@ var DefaultAuthUtilityConfig = {
656
661
  var DefaultAuthMiddlewareConfig = {
657
662
  allowAnonymous: false,
658
663
  allowSystem: true,
659
- allowUser: true
664
+ allowUser: true,
665
+ allowCDN: false
660
666
  };
661
667
  var AuthUtility = class {
662
668
  maxTokenAge;
@@ -799,7 +805,7 @@ var AuthUtility = class {
799
805
  * @param config Configuration for middleware behavior.
800
806
  */
801
807
  AuthMiddleware(config = DefaultAuthMiddlewareConfig) {
802
- const { allowAnonymous, allowSystem, allowUser } = { ...DefaultAuthMiddlewareConfig, ...config };
808
+ const { allowAnonymous, allowSystem, allowUser, allowCDN } = { ...DefaultAuthMiddlewareConfig, ...config };
803
809
  return async (req, res, next) => {
804
810
  try {
805
811
  const [authType, token] = req.get("Authorization")?.split(" ") || [];
@@ -823,6 +829,11 @@ var AuthUtility = class {
823
829
  payload = await this.verifyAdminToken(token);
824
830
  Logger_default.logMessage("AuthMiddleware", `Admin Id - ${payload.id}`);
825
831
  break;
832
+ case "CDN":
833
+ if (!allowCDN) throw response_default.generateError(403, ErrorTypes_default.CDN_SESSION_NOT_ALLOWED);
834
+ assert(["E3CQMOP5FX6KD1", "E3TNCKKZ3FOX9W"].includes(token), ErrorTypes_default.INVALID_TOKEN);
835
+ Logger_default.logMessage("AuthMiddleware", `CDN DistributionId - ${token}`);
836
+ break;
826
837
  default:
827
838
  throw response_default.generateError(403, ErrorTypes_default.INVALID_AUTH_TYPE);
828
839
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "b23-lib",
3
- "version": "1.2.13",
3
+ "version": "1.4.0",
4
4
  "description": "This repo hold common classes, type and util functiona",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",