lambda-compression 0.2.0 → 0.2.1

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,3 @@
1
- import type { APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2 } from 'aws-lambda';
2
- export declare const compress: (event: APIGatewayProxyEventV2, result: APIGatewayProxyStructuredResultV2) => APIGatewayProxyStructuredResultV2;
1
+ import type { APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2 } from 'aws-lambda';
2
+ export declare const compress: (event: APIGatewayProxyEventV2, result: APIGatewayProxyStructuredResultV2) => APIGatewayProxyStructuredResultV2;
3
3
  //# sourceMappingURL=lambdaCompression.d.ts.map
@@ -1,46 +1,46 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.compress = void 0;
7
- const zlib_1 = __importDefault(require("zlib"));
8
- const compress = (event, result) => {
9
- // when there is no body, there is nothing to compress
10
- if (!result.body) {
11
- return result;
12
- }
13
- const acceptEncodingHeader = event.headers['accept-encoding'];
14
- // determine accepted encodings
15
- const encodings = new Set();
16
- if (acceptEncodingHeader) {
17
- acceptEncodingHeader.split(',').forEach((encoding) => {
18
- encodings.add(encoding.toLowerCase().trim());
19
- });
20
- }
21
- if (!result.headers) {
22
- result.headers = {};
23
- }
24
- if (encodings.has('br')) {
25
- result.headers['content-encoding'] = 'br';
26
- result.isBase64Encoded = true;
27
- result.body = zlib_1.default.brotliCompressSync(result.body).toString('base64');
28
- return result;
29
- }
30
- if (encodings.has('gzip')) {
31
- result.headers['content-encoding'] = 'gzip';
32
- result.isBase64Encoded = true;
33
- result.body = zlib_1.default.gzipSync(result.body).toString('base64');
34
- return result;
35
- }
36
- if (encodings.has('deflate')) {
37
- result.headers['content-encoding'] = 'deflate ';
38
- result.isBase64Encoded = true;
39
- result.body = zlib_1.default.deflateSync(result.body).toString('base64');
40
- return result;
41
- }
42
- // if there are no supported encodings, return unencoded message
43
- return result;
44
- };
45
- exports.compress = compress;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.compress = void 0;
7
+ const zlib_1 = __importDefault(require("zlib"));
8
+ const compress = (event, result) => {
9
+ // when there is no body, there is nothing to compress
10
+ if (!result.body) {
11
+ return result;
12
+ }
13
+ const acceptEncodingHeader = event.headers['accept-encoding'];
14
+ // determine accepted encodings
15
+ const encodings = new Set();
16
+ if (acceptEncodingHeader) {
17
+ acceptEncodingHeader.split(',').forEach((encoding) => {
18
+ encodings.add(encoding.toLowerCase().trim());
19
+ });
20
+ }
21
+ if (!result.headers) {
22
+ result.headers = {};
23
+ }
24
+ if (encodings.has('br')) {
25
+ result.headers['content-encoding'] = 'br';
26
+ result.isBase64Encoded = true;
27
+ result.body = zlib_1.default.brotliCompressSync(result.body).toString('base64');
28
+ return result;
29
+ }
30
+ if (encodings.has('gzip')) {
31
+ result.headers['content-encoding'] = 'gzip';
32
+ result.isBase64Encoded = true;
33
+ result.body = zlib_1.default.gzipSync(result.body).toString('base64');
34
+ return result;
35
+ }
36
+ if (encodings.has('deflate')) {
37
+ result.headers['content-encoding'] = 'deflate ';
38
+ result.isBase64Encoded = true;
39
+ result.body = zlib_1.default.deflateSync(result.body).toString('base64');
40
+ return result;
41
+ }
42
+ // if there are no supported encodings, return unencoded message
43
+ return result;
44
+ };
45
+ exports.compress = compress;
46
46
  //# sourceMappingURL=lambdaCompression.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lambda-compression",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "HTTP payload compression for AWS Lambda functions",
5
5
  "keywords": [
6
6
  "lambda",
@@ -35,7 +35,7 @@
35
35
  "version:apply": "utils-git changed --exec \"yarn version $@ && yarn version apply\""
36
36
  },
37
37
  "devDependencies": {
38
- "@goldstack/utils-git": "0.2.0",
38
+ "@goldstack/utils-git": "0.2.1",
39
39
  "@types/aws-lambda": "^8.10.88",
40
40
  "@types/jest": "^28.1.8",
41
41
  "@types/node": "^18.7.13",
@@ -1,7 +0,0 @@
1
- export interface ExecParams {
2
- silent?: boolean;
3
- }
4
- export declare const hash: () => string;
5
- export declare const filesChanged: () => boolean;
6
- export declare const run: (args: string[]) => void;
7
- //# sourceMappingURL=utilsGit.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utilsGit.d.ts","sourceRoot":"","sources":["../../src/utilsGit.ts"],"names":[],"mappings":"AAuBA,MAAM,WAAW,UAAU;IACzB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,eAAO,MAAM,IAAI,QAAO,MAMvB,CAAC;AAEF,eAAO,MAAM,YAAY,QAAO,OAqB/B,CAAC;AAEF,eAAO,MAAM,GAAG,SAAU,MAAM,EAAE,KAAG,IAoBpC,CAAC"}
@@ -1,85 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.run = exports.filesChanged = exports.hash = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- // included here in preference to goldstack utils-sh to avoid circular dependency
9
- const console_1 = require("console");
10
- const child_process_1 = require("child_process");
11
- const command_exists_1 = __importDefault(require("command-exists"));
12
- const isDebug = process.env.GOLDSTACK_DEBUG || process.env.DEBUG;
13
- // included here to avoid circular dependency for log package
14
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- const debug = (msg) => {
16
- if (isDebug) {
17
- console.log(msg);
18
- }
19
- };
20
- const exec = (cmd, params) => {
21
- const res = (0, child_process_1.execSync)(cmd);
22
- if (!(params === null || params === void 0 ? void 0 : params.silent)) {
23
- console.log(res.toString());
24
- }
25
- return res.toString();
26
- };
27
- const hash = () => {
28
- if (!(0, command_exists_1.default)('git')) {
29
- throw new Error('git is not installed or not available as command.');
30
- }
31
- const hash = exec('git rev-parse --short HEAD', { silent: true }).trim();
32
- return hash;
33
- };
34
- exports.hash = hash;
35
- const filesChanged = () => {
36
- let headChanged = false;
37
- let fileChanged = false;
38
- try {
39
- exec('git diff "HEAD..HEAD^1" --quiet -- . ');
40
- }
41
- catch (e) {
42
- debug('Detected change against HEAD^1 in ' + path_1.default.resolve('.'));
43
- headChanged = true;
44
- }
45
- try {
46
- exec('git diff --quiet -- . ');
47
- }
48
- catch (e) {
49
- debug('Detected uncommited change in ' + path_1.default.resolve('.'));
50
- fileChanged = true;
51
- }
52
- if (headChanged || fileChanged) {
53
- return true;
54
- }
55
- else {
56
- return false;
57
- }
58
- };
59
- exports.filesChanged = filesChanged;
60
- const run = (args) => {
61
- (0, console_1.assert)(args[3] === '--exec');
62
- const [, , , , ...execCommands] = args;
63
- const execCommand = execCommands.join(' ');
64
- if (args[2] === 'changed') {
65
- if ((0, exports.filesChanged)()) {
66
- try {
67
- const res = exec(execCommand);
68
- console.log(res);
69
- }
70
- catch (e) {
71
- console.error('Error when running "' + execCommand + '"');
72
- process.exit(1);
73
- }
74
- }
75
- else {
76
- console.log('No file changes detected in ' + path_1.default.resolve('.'));
77
- }
78
- }
79
- else {
80
- console.log('Please provide argument changed.');
81
- process.exit(1);
82
- }
83
- };
84
- exports.run = run;
85
- //# sourceMappingURL=utilsGit.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utilsGit.js","sourceRoot":"","sources":["../../src/utilsGit.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,iFAAiF;AACjF,qCAAiC;AACjC,iDAAyC;AACzC,oEAAuC;AAEvC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;AAEjE,6DAA6D;AAC7D,8DAA8D;A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