serverless-simple-middleware 0.0.56 → 0.0.57

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.
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import * as AWS from 'aws-sdk';
2
3
  import { SimpleAWSConfig } from './config';
3
4
  import { S3SignedUrlParams, S3SignedUrlResult, SQSMessageBody } from './define';
@@ -22,6 +23,7 @@ export declare class SimpleAWS {
22
23
  completeMessages: (queueName: string, handles: string[]) => Promise<string[]>;
23
24
  download: (bucket: string, key: string, localPath: string) => Promise<string>;
24
25
  readFile: (bucket: string, key: string) => Promise<string>;
26
+ readFileBuffer: (bucket: string, key: string) => Promise<Buffer>;
25
27
  upload: (bucket: string, localPath: string, key: string) => Promise<string>;
26
28
  writeFile: (bucket: string, key: string, content: string) => Promise<void>;
27
29
  getSignedUrl: (bucketName: string, key: string, operation?: "getObject" | "putObject", params?: S3SignedUrlParams | undefined) => S3SignedUrlResult;
@@ -37,7 +39,7 @@ export declare class SimpleAWS {
37
39
  }) => Promise<import("aws-sdk/lib/request").PromiseResult<AWS.DynamoDB.DocumentClient.UpdateItemOutput, AWS.AWSError>>;
38
40
  setupQueue: (queueName: string) => Promise<boolean>;
39
41
  setupStorage: (bucketName: string, cors: {
40
- methods: ("DELETE" | "GET" | "HEAD" | "POST" | "PUT")[];
42
+ methods: ("DELETE" | "GET" | "POST" | "PUT" | "HEAD")[];
41
43
  origins: string[];
42
44
  }) => Promise<boolean>;
43
45
  setupDynamoDb: (tableName: string, keyColumn: string) => Promise<boolean>;
@@ -338,6 +338,29 @@ var SimpleAWS = /** @class */ (function () {
338
338
  }
339
339
  });
340
340
  }); };
341
+ this.readFileBuffer = function (bucket, key) { return __awaiter(_this, void 0, void 0, function () {
342
+ var params, data;
343
+ return __generator(this, function (_a) {
344
+ switch (_a.label) {
345
+ case 0:
346
+ logger.debug("Read item[" + key + "] from bucket[" + bucket + "]");
347
+ params = {
348
+ Bucket: bucket,
349
+ Key: key,
350
+ };
351
+ return [4 /*yield*/, this.s3.getObject(params).promise()];
352
+ case 1:
353
+ data = _a.sent();
354
+ if (data.Body) {
355
+ return [2 /*return*/, data.Body];
356
+ }
357
+ else {
358
+ throw new Error("Failed to read file " + key + " from bucket " + bucket);
359
+ }
360
+ return [2 /*return*/];
361
+ }
362
+ });
363
+ }); };
341
364
  this.upload = function (bucket, localPath, key) { return __awaiter(_this, void 0, void 0, function () {
342
365
  var putResult;
343
366
  return __generator(this, function (_a) {
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.56",
4
+ "version": "0.0.57",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "author": "VoyagerX",
@@ -38,7 +38,7 @@
38
38
  "uuid": "^3.3.2"
39
39
  },
40
40
  "optionalDependencies": {
41
- "aws-sdk": "^2.288.0"
41
+ "aws-sdk": "2.1664.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/jest": "^23.3.1",
package/src/aws/simple.ts CHANGED
@@ -278,6 +278,24 @@ export class SimpleAWS {
278
278
  }
279
279
  };
280
280
 
281
+ public readFileBuffer = async (
282
+ bucket: string,
283
+ key: string,
284
+ ): Promise<Buffer> => {
285
+ logger.debug(`Read item[${key}] from bucket[${bucket}]`);
286
+ const params = {
287
+ Bucket: bucket,
288
+ Key: key,
289
+ };
290
+
291
+ const data = await this.s3.getObject(params).promise();
292
+ if (data.Body) {
293
+ return data.Body as Buffer;
294
+ } else {
295
+ throw new Error(`Failed to read file ${key} from bucket ${bucket}`);
296
+ }
297
+ };
298
+
281
299
  public upload = async (
282
300
  bucket: string,
283
301
  localPath: string,