serverless-simple-middleware 0.0.68 → 0.0.69

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.
@@ -35,6 +35,11 @@ export declare class SimpleAWS {
35
35
  writeFile: (bucket: string, key: string, content: string) => Promise<void>;
36
36
  getSignedUrl(options: PresignerOptions): Promise<string>;
37
37
  getSignedCookie: (keyPairId: string, privateKey: string, url: string, expires: number) => CloudfrontSignedCookiesOutput;
38
+ /**
39
+ * Get signed URL for CloudFront
40
+ * @param expiresSec - The expiration time in seconds (default 7 days)
41
+ */
42
+ getCloudFrontSignedUrl: (keyPairId: string, privateKey: string, url: string, expiresSec?: number) => string;
38
43
  getDynamoDbItem: <T>(tableName: string, key: {
39
44
  [keyColumn: string]: string;
40
45
  }, defaultValue?: T) => Promise<T | undefined>;
@@ -437,6 +437,18 @@ class SimpleAWS {
437
437
  policy,
438
438
  });
439
439
  };
440
+ /**
441
+ * Get signed URL for CloudFront
442
+ * @param expiresSec - The expiration time in seconds (default 7 days)
443
+ */
444
+ getCloudFrontSignedUrl = (keyPairId, privateKey, url, expiresSec = 7 * 24 * 60 * 60) => {
445
+ return (0, cloudfront_signer_1.getSignedUrl)({
446
+ keyPairId,
447
+ privateKey,
448
+ url,
449
+ dateLessThan: new Date(Date.now() + expiresSec * 1000),
450
+ });
451
+ };
440
452
  getDynamoDbItem = async (tableName, key, defaultValue) => {
441
453
  logger.debug(`Read an item with key[${JSON.stringify(key)}] from ${tableName}.`);
442
454
  const getResult = await this.dynamodb.get({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "serverless-simple-middleware",
3
3
  "description": "Simple middleware to translate the interface of lambda's handler to request => response",
4
- "version": "0.0.68",
4
+ "version": "0.0.69",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "author": "VoyagerX",
package/src/aws/simple.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  CloudfrontSignedCookiesOutput,
3
+ getSignedUrl as getCloudFrontSignedUrl,
3
4
  getSignedCookies,
4
5
  } from '@aws-sdk/cloudfront-signer';
5
6
 
@@ -544,6 +545,24 @@ export class SimpleAWS {
544
545
  });
545
546
  };
546
547
 
548
+ /**
549
+ * Get signed URL for CloudFront
550
+ * @param expiresSec - The expiration time in seconds (default 7 days)
551
+ */
552
+ public getCloudFrontSignedUrl = (
553
+ keyPairId: string,
554
+ privateKey: string,
555
+ url: string,
556
+ expiresSec: number = 7 * 24 * 60 * 60, // 7 days
557
+ ): string => {
558
+ return getCloudFrontSignedUrl({
559
+ keyPairId,
560
+ privateKey,
561
+ url,
562
+ dateLessThan: new Date(Date.now() + expiresSec * 1000),
563
+ });
564
+ };
565
+
547
566
  public getDynamoDbItem = async <T>(
548
567
  tableName: string,
549
568
  key: { [keyColumn: string]: string },