serverless-simple-middleware 0.0.61 → 0.0.63

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.
@@ -0,0 +1,99 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="AutoImportSettings">
4
+ <option name="autoReloadType" value="SELECTIVE" />
5
+ </component>
6
+ <component name="ChangeListManager">
7
+ <list default="true" id="d3e8841d-4c1b-4775-9eaf-7a7f45125ca6" name="Changes" comment="" />
8
+ <option name="SHOW_DIALOG" value="false" />
9
+ <option name="HIGHLIGHT_CONFLICTS" value="true" />
10
+ <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
11
+ <option name="LAST_RESOLUTION" value="IGNORE" />
12
+ </component>
13
+ <component name="Git.Settings">
14
+ <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
15
+ </component>
16
+ <component name="GitHubPullRequestSearchHistory">{
17
+ &quot;lastFilter&quot;: {
18
+ &quot;state&quot;: &quot;OPEN&quot;,
19
+ &quot;assignee&quot;: &quot;mintae-v6x&quot;
20
+ }
21
+ }</component>
22
+ <component name="GithubPullRequestsUISettings">{
23
+ &quot;selectedUrlAndAccountId&quot;: {
24
+ &quot;url&quot;: &quot;git@github.com:v6x/serverless-simple-middleware.git&quot;,
25
+ &quot;accountId&quot;: &quot;651af4d7-dc5b-4c87-ad25-95bb095bbdab&quot;
26
+ }
27
+ }</component>
28
+ <component name="ProjectColorInfo">{
29
+ &quot;customColor&quot;: &quot;&quot;,
30
+ &quot;associatedIndex&quot;: 0
31
+ }</component>
32
+ <component name="ProjectId" id="2wLO998bpCyv1XeFcGkak71tJ00" />
33
+ <component name="ProjectViewState">
34
+ <option name="hideEmptyMiddlePackages" value="true" />
35
+ <option name="showLibraryContents" value="true" />
36
+ </component>
37
+ <component name="PropertiesComponent"><![CDATA[{
38
+ "keyToString": {
39
+ "RunOnceActivity.ShowReadmeOnStart": "true",
40
+ "node.js.detected.package.eslint": "true",
41
+ "node.js.detected.package.tslint": "true",
42
+ "node.js.selected.package.eslint": "(autodetect)",
43
+ "node.js.selected.package.tslint": "(autodetect)",
44
+ "nodejs_package_manager_path": "yarn",
45
+ "ts.external.directory.path": "C:\\Users\\MintaeHwang\\Projects\\serverless-simple-middleware\\node_modules\\typescript\\lib",
46
+ "vue.rearranger.settings.migration": "true"
47
+ }
48
+ }]]></component>
49
+ <component name="SharedIndexes">
50
+ <attachedChunks>
51
+ <set>
52
+ <option value="bundled-js-predefined-1d06a55b98c1-0b3e54e931b4-JavaScript-WS-241.18034.50" />
53
+ </set>
54
+ </attachedChunks>
55
+ </component>
56
+ <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
57
+ <component name="TaskManager">
58
+ <task active="true" id="Default" summary="Default task">
59
+ <changelist id="d3e8841d-4c1b-4775-9eaf-7a7f45125ca6" name="Changes" comment="" />
60
+ <created>1745817233391</created>
61
+ <option name="number" value="Default" />
62
+ <option name="presentableId" value="Default" />
63
+ <updated>1745817233391</updated>
64
+ <workItem from="1745817234628" duration="4410000" />
65
+ <workItem from="1746006740077" duration="129000" />
66
+ <workItem from="1749703698039" duration="5259000" />
67
+ <workItem from="1749721908491" duration="1629000" />
68
+ <workItem from="1750211888403" duration="1739000" />
69
+ <workItem from="1750643159276" duration="1164000" />
70
+ <workItem from="1751023632877" duration="2292000" />
71
+ </task>
72
+ <servers />
73
+ </component>
74
+ <component name="TypeScriptGeneratedFilesManager">
75
+ <option name="version" value="3" />
76
+ </component>
77
+ <component name="Vcs.Log.Tabs.Properties">
78
+ <option name="TAB_STATES">
79
+ <map>
80
+ <entry key="MAIN">
81
+ <value>
82
+ <State />
83
+ </value>
84
+ </entry>
85
+ </map>
86
+ </option>
87
+ </component>
88
+ <component name="XDebuggerManager">
89
+ <breakpoint-manager>
90
+ <breakpoints>
91
+ <line-breakpoint enabled="true" type="javascript">
92
+ <url>file://$PROJECT_DIR$/src/middleware/trace.ts</url>
93
+ <line>118</line>
94
+ <option name="timeStamp" value="1" />
95
+ </line-breakpoint>
96
+ </breakpoints>
97
+ </breakpoint-manager>
98
+ </component>
99
+ </project>
package/.prettierignore CHANGED
@@ -1,3 +1,3 @@
1
- tslint.json
2
- tsconfig.json
1
+ tslint.json
2
+ tsconfig.json
3
3
  package.json
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
- # Serverless simple middleware
2
-
3
- This is just simple middleware for me to translate the interface of lambda's handler to use `request => response`.
1
+ # Serverless simple middleware
2
+
3
+ This is just simple middleware for me to translate the interface of lambda's handler to use `request => response`.
@@ -2,7 +2,7 @@ import { CloudfrontSignedCookiesOutput } from '@aws-sdk/cloudfront-signer';
2
2
  import { SimpleAWSConfig } from './config';
3
3
  import { SQSMessageBody } from './define';
4
4
  import { DynamoDB } from '@aws-sdk/client-dynamodb';
5
- import { S3 } from '@aws-sdk/client-s3';
5
+ import { S3, Tag } from '@aws-sdk/client-s3';
6
6
  import { SQS } from '@aws-sdk/client-sqs';
7
7
  import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';
8
8
  import { PresignerOptions } from '../internal/s3';
@@ -13,6 +13,8 @@ export declare class SimpleAWS {
13
13
  private lazySqs;
14
14
  private lazyDynamodb;
15
15
  private lazyDynamodbAdmin;
16
+ private static readonly stageTag;
17
+ private static readonly stringifiedStageTag;
16
18
  constructor(config?: SimpleAWSConfig);
17
19
  get s3(): S3;
18
20
  get sqs(): SQS;
@@ -28,8 +30,8 @@ export declare class SimpleAWS {
28
30
  download: (bucket: string, key: string, localPath: string) => Promise<string>;
29
31
  readFile: (bucket: string, key: string) => Promise<string>;
30
32
  readFileBuffer: (bucket: string, key: string) => Promise<Buffer>;
31
- upload: (bucket: string, localPath: string, key: string) => Promise<string>;
32
- uploadFromBuffer: (bucket: string, key: string, buffer: Buffer) => Promise<string>;
33
+ upload: (bucket: string, localPath: string, key: string, tags?: Tag[]) => Promise<string>;
34
+ uploadFromBuffer: (bucket: string, key: string, buffer: Buffer, tags?: Tag[]) => Promise<string>;
33
35
  writeFile: (bucket: string, key: string, content: string) => Promise<void>;
34
36
  getSignedUrl(options: PresignerOptions): Promise<string>;
35
37
  getSignedCookie: (keyPairId: string, privateKey: string, url: string, expires: number) => CloudfrontSignedCookiesOutput;
@@ -58,6 +58,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
58
58
  Object.defineProperty(exports, "__esModule", { value: true });
59
59
  exports.SimpleAWS = void 0;
60
60
  var cloudfront_signer_1 = require("@aws-sdk/cloudfront-signer");
61
+ var simple_staging_1 = require("simple-staging");
61
62
  var fs = require("fs");
62
63
  var os = require("os");
63
64
  var non_secure_1 = require("nanoid/non-secure");
@@ -366,7 +367,7 @@ var SimpleAWS = /** @class */ (function () {
366
367
  }
367
368
  });
368
369
  }); };
369
- this.upload = function (bucket, localPath, key) { return __awaiter(_this, void 0, void 0, function () {
370
+ this.upload = function (bucket, localPath, key, tags) { return __awaiter(_this, void 0, void 0, function () {
370
371
  var upload;
371
372
  return __generator(this, function (_a) {
372
373
  switch (_a.label) {
@@ -381,6 +382,7 @@ var SimpleAWS = /** @class */ (function () {
381
382
  },
382
383
  partSize: 5 * 1024 * 1024, // 5MB
383
384
  queueSize: 4,
385
+ tags: __spreadArray([SimpleAWS.stageTag], (tags || []), true),
384
386
  });
385
387
  return [4 /*yield*/, upload.done()];
386
388
  case 1:
@@ -389,7 +391,7 @@ var SimpleAWS = /** @class */ (function () {
389
391
  }
390
392
  });
391
393
  }); };
392
- this.uploadFromBuffer = function (bucket, key, buffer) { return __awaiter(_this, void 0, void 0, function () {
394
+ this.uploadFromBuffer = function (bucket, key, buffer, tags) { return __awaiter(_this, void 0, void 0, function () {
393
395
  var upload;
394
396
  return __generator(this, function (_a) {
395
397
  switch (_a.label) {
@@ -404,6 +406,7 @@ var SimpleAWS = /** @class */ (function () {
404
406
  },
405
407
  partSize: 5 * 1024 * 1024, // 5MB
406
408
  queueSize: 4,
409
+ tags: __spreadArray([SimpleAWS.stageTag], (tags || []), true),
407
410
  });
408
411
  return [4 /*yield*/, upload.done()];
409
412
  case 1:
@@ -696,12 +699,16 @@ var SimpleAWS = /** @class */ (function () {
696
699
  });
697
700
  SimpleAWS.prototype.getSignedUrl = function (options) {
698
701
  return __awaiter(this, void 0, void 0, function () {
699
- var _a, expiresIn, unhoistableHeaders, cmd, cmd, cmd, cmd, cmd, cmd, cmd, cmd, cmd, cmd, cmd, cmd;
700
- return __generator(this, function (_b) {
702
+ var _a, expiresIn, unhoistableHeaders, tagging, cmd, cmd, cmd, cmd, cmd, cmd, cmd, cmd, tagging, cmd, cmd, cmd, cmd;
703
+ var _b, _c;
704
+ return __generator(this, function (_d) {
701
705
  _a = options.expiresIn, expiresIn = _a === void 0 ? 600 : _a, unhoistableHeaders = options.unhoistableHeaders;
702
706
  switch (options.operation) {
703
707
  case 'putObject': {
704
- cmd = new client_s3_1.PutObjectCommand(__assign({ Bucket: options.bucket, Key: options.key }, options.params));
708
+ tagging = ((_b = options.params) === null || _b === void 0 ? void 0 : _b.Tagging)
709
+ ? SimpleAWS.stringifiedStageTag + '&' + options.params.Tagging
710
+ : SimpleAWS.stringifiedStageTag;
711
+ cmd = new client_s3_1.PutObjectCommand(__assign(__assign({ Bucket: options.bucket, Key: options.key }, options.params), { Tagging: tagging }));
705
712
  return [2 /*return*/, (0, s3_request_presigner_1.getSignedUrl)(this.s3, cmd, {
706
713
  expiresIn: expiresIn,
707
714
  unhoistableHeaders: unhoistableHeaders,
@@ -757,7 +764,10 @@ var SimpleAWS = /** @class */ (function () {
757
764
  })];
758
765
  }
759
766
  case 'createMultipartUpload': {
760
- cmd = new client_s3_1.CreateMultipartUploadCommand(__assign({ Bucket: options.bucket, Key: options.key }, options.params));
767
+ tagging = ((_c = options.params) === null || _c === void 0 ? void 0 : _c.Tagging)
768
+ ? SimpleAWS.stringifiedStageTag + '&' + options.params.Tagging
769
+ : SimpleAWS.stringifiedStageTag;
770
+ cmd = new client_s3_1.CreateMultipartUploadCommand(__assign(__assign({ Bucket: options.bucket, Key: options.key }, options.params), { Tagging: tagging }));
761
771
  return [2 /*return*/, (0, s3_request_presigner_1.getSignedUrl)(this.s3, cmd, {
762
772
  expiresIn: expiresIn,
763
773
  unhoistableHeaders: unhoistableHeaders,
@@ -789,6 +799,11 @@ var SimpleAWS = /** @class */ (function () {
789
799
  });
790
800
  });
791
801
  };
802
+ SimpleAWS.stageTag = {
803
+ Key: 'STAGE',
804
+ Value: simple_staging_1.envDefault.level,
805
+ };
806
+ SimpleAWS.stringifiedStageTag = "STAGE=".concat(simple_staging_1.envDefault.level);
792
807
  return SimpleAWS;
793
808
  }());
794
809
  exports.SimpleAWS = SimpleAWS;
@@ -28,7 +28,7 @@ export declare class HandlerResponse {
28
28
  constructor(callback: any);
29
29
  ok(body?: {}, code?: number): any;
30
30
  fail(body?: {}, code?: number): any;
31
- addCookie(key: string, value: string, domain?: string, specifyCrossOrigin?: true, path?: string): void;
31
+ addCookie(key: string, value: string, domain?: string, sameSite?: 'None' | 'Lax' | 'Strict', secure?: boolean, path?: string, httpOnly?: boolean, maxAgeSeconds?: number): void;
32
32
  setCrossOrigin: (origin?: string) => void;
33
33
  addHeader: (header: string, value: string) => void;
34
34
  }
@@ -111,13 +111,23 @@ var HandlerResponse = /** @class */ (function () {
111
111
  this.completed = true;
112
112
  return result;
113
113
  };
114
- HandlerResponse.prototype.addCookie = function (key, value, domain, specifyCrossOrigin, path) {
114
+ HandlerResponse.prototype.addCookie = function (key, value, domain, sameSite, secure, path, httpOnly, maxAgeSeconds) {
115
115
  var keyValueStr = "".concat(key, "=").concat(value);
116
116
  var domainStr = domain ? "Domain=".concat(domain) : '';
117
- var sameSiteStr = specifyCrossOrigin ? 'SameSite=None' : '';
118
- var secureStr = specifyCrossOrigin ? 'Secure' : '';
117
+ var sameSiteStr = sameSite ? "SameSite=".concat(sameSite) : '';
118
+ var secureStr = secure ? 'Secure' : '';
119
119
  var pathStr = path !== undefined ? "Path=".concat(path) : '';
120
- var cookieStr = [keyValueStr, domainStr, sameSiteStr, secureStr, pathStr]
120
+ var httpOnlyStr = httpOnly ? 'HttpOnly' : '';
121
+ var maxAgeStr = maxAgeSeconds || maxAgeSeconds === 0 ? "Max-Age=".concat(maxAgeSeconds) : '';
122
+ var cookieStr = [
123
+ keyValueStr,
124
+ domainStr,
125
+ sameSiteStr,
126
+ secureStr,
127
+ pathStr,
128
+ httpOnlyStr,
129
+ maxAgeStr,
130
+ ]
121
131
  .filter(function (x) { return x; })
122
132
  .join('; ');
123
133
  this.cookies.push(cookieStr);
package/jest.config.js CHANGED
@@ -1,7 +1,7 @@
1
- module.exports = {
2
- transform: {
3
- '^.+\\.tsx?$': 'ts-jest',
4
- },
5
- testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
6
- moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
7
- };
1
+ module.exports = {
2
+ transform: {
3
+ '^.+\\.tsx?$': 'ts-jest',
4
+ },
5
+ testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
6
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
7
+ };
package/package.json CHANGED
@@ -1,69 +1,69 @@
1
- {
2
- "name": "serverless-simple-middleware",
3
- "description": "Simple middleware to translate the interface of lambda's handler to request => response",
4
- "version": "0.0.61",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "author": "VoyagerX",
8
- "license": "MIT",
9
- "repository": {
10
- "type": "git",
11
- "url": "git+ssh://git@github.com/v6x/serverless-simple-middleware.git"
12
- },
13
- "engines": {
14
- "node": ">=18"
15
- },
16
- "keywords": [
17
- "serverless"
18
- ],
19
- "bugs": {
20
- "url": "https://github.com/v6x/serverless-simple-middleware/issues"
21
- },
22
- "homepage": "https://github.com/v6x/serverless-simple-middleware#readme",
23
- "scripts": {
24
- "lint": "tslint --project tsconfig.json",
25
- "build": "tsc --project tsconfig.json",
26
- "build:watch": "tsc --project tsconfig.json --watch",
27
- "test": "jest --config jest.config.js",
28
- "test:watch": "jest --config jest.config.js --watch",
29
- "deploy": "yarn build && yarn publish",
30
- "clean": "rm -rf dist && rm -rf node_modules && yarn install"
31
- },
32
- "dependencies": {
33
- "@aws-sdk/client-dynamodb": "^3.828.0",
34
- "@aws-sdk/client-s3": "^3.828.0",
35
- "@aws-sdk/client-sqs": "^3.828.0",
36
- "@aws-sdk/cloudfront-signer": "^3.821.0",
37
- "@aws-sdk/lib-dynamodb": "^3.828.0",
38
- "@aws-sdk/lib-storage": "^3.828.0",
39
- "@aws-sdk/s3-request-presigner": "^3.828.0",
40
- "@types/aws-lambda": "8",
41
- "@types/mysql": "^2.15.5",
42
- "cross-fetch": "^2.2.2",
43
- "mysql": "^2.16.0",
44
- "nanoid": "4.0.2",
45
- "p-limit": "^2.0.0",
46
- "simple-staging": "^0.0.12",
47
- "ts-enum-util": "^3.1.0",
48
- "uuid": "^3.3.2"
49
- },
50
- "devDependencies": {
51
- "@types/jest": "^23.3.1",
52
- "@types/node": "18",
53
- "@types/uuid": "^3.4.4",
54
- "babel-core": "6.26.0",
55
- "babel-jest": "^23.4.2",
56
- "cross-env": "^5.2.0",
57
- "jest": "^23.4.2",
58
- "prettier": "3.3.3",
59
- "ts-jest": "^23.1.3",
60
- "tslint": "^5.11.0",
61
- "tslint-config-prettier": "^1.14.0",
62
- "typescript": "5.5.3"
63
- },
64
- "prettier": {
65
- "printWidth": 80,
66
- "singleQuote": true,
67
- "trailingComma": "all"
68
- }
69
- }
1
+ {
2
+ "name": "serverless-simple-middleware",
3
+ "description": "Simple middleware to translate the interface of lambda's handler to request => response",
4
+ "version": "0.0.63",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "author": "VoyagerX",
8
+ "license": "MIT",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+ssh://git@github.com/v6x/serverless-simple-middleware.git"
12
+ },
13
+ "engines": {
14
+ "node": ">=18"
15
+ },
16
+ "keywords": [
17
+ "serverless"
18
+ ],
19
+ "bugs": {
20
+ "url": "https://github.com/v6x/serverless-simple-middleware/issues"
21
+ },
22
+ "homepage": "https://github.com/v6x/serverless-simple-middleware#readme",
23
+ "scripts": {
24
+ "lint": "tslint --project tsconfig.json",
25
+ "build": "tsc --project tsconfig.json",
26
+ "build:watch": "tsc --project tsconfig.json --watch",
27
+ "test": "jest --config jest.config.js",
28
+ "test:watch": "jest --config jest.config.js --watch",
29
+ "deploy": "yarn build && yarn publish",
30
+ "clean": "rm -rf dist && rm -rf node_modules && yarn install"
31
+ },
32
+ "dependencies": {
33
+ "@aws-sdk/client-dynamodb": "^3.828.0",
34
+ "@aws-sdk/client-s3": "^3.828.0",
35
+ "@aws-sdk/client-sqs": "^3.828.0",
36
+ "@aws-sdk/cloudfront-signer": "^3.821.0",
37
+ "@aws-sdk/lib-dynamodb": "^3.828.0",
38
+ "@aws-sdk/lib-storage": "^3.828.0",
39
+ "@aws-sdk/s3-request-presigner": "^3.828.0",
40
+ "@types/aws-lambda": "8",
41
+ "@types/mysql": "^2.15.5",
42
+ "cross-fetch": "^2.2.2",
43
+ "mysql": "^2.16.0",
44
+ "nanoid": "4.0.2",
45
+ "p-limit": "^2.0.0",
46
+ "simple-staging": "^0.0.12",
47
+ "ts-enum-util": "^3.1.0",
48
+ "uuid": "^3.3.2"
49
+ },
50
+ "devDependencies": {
51
+ "@types/jest": "^23.3.1",
52
+ "@types/node": "18",
53
+ "@types/uuid": "^3.4.4",
54
+ "babel-core": "6.26.0",
55
+ "babel-jest": "^23.4.2",
56
+ "cross-env": "^5.2.0",
57
+ "jest": "^23.4.2",
58
+ "prettier": "3.3.3",
59
+ "ts-jest": "^23.1.3",
60
+ "tslint": "^5.11.0",
61
+ "tslint-config-prettier": "^1.14.0",
62
+ "typescript": "5.5.3"
63
+ },
64
+ "prettier": {
65
+ "printWidth": 80,
66
+ "singleQuote": true,
67
+ "trailingComma": "all"
68
+ }
69
+ }
package/src/aws/config.ts CHANGED
@@ -1,46 +1,46 @@
1
- import fetch from 'cross-fetch';
2
- import * as fs from 'fs';
3
-
4
- import { AWSComponent } from './define';
5
-
6
- export interface AWSConfig {
7
- [key: string]: string | boolean | number | undefined;
8
- }
9
-
10
- export interface AWSConfigs {
11
- [service: string]: AWSConfig;
12
- }
13
-
14
- export type AWSConfigResolver = (service: string) => AWSConfig;
15
-
16
- export type SimpleAWSConfigLoadParam = AWSConfigs | string;
17
-
18
- export class SimpleAWSConfig {
19
- private configs: AWSConfigs | undefined;
20
-
21
- public constructor(configs?: AWSConfigs) {
22
- this.configs = configs;
23
- }
24
-
25
- public get = (service: AWSComponent): AWSConfig | undefined => {
26
- return this.configs ? this.configs[service] : undefined;
27
- };
28
- }
29
-
30
- export const loadAWSConfig = (
31
- newConfigsOrUrl: SimpleAWSConfigLoadParam,
32
- ): Promise<SimpleAWSConfig> => {
33
- if (typeof newConfigsOrUrl === 'string') {
34
- if (/^http.*json$/.test(newConfigsOrUrl)) {
35
- return fetch(newConfigsOrUrl)
36
- .then((r) => r.json())
37
- .then(loadAWSConfig);
38
- } else if (/json$/.test(newConfigsOrUrl)) {
39
- return loadAWSConfig(
40
- JSON.parse(fs.readFileSync(newConfigsOrUrl, 'utf-8')),
41
- );
42
- }
43
- return loadAWSConfig(JSON.parse(newConfigsOrUrl));
44
- }
45
- return Promise.resolve(new SimpleAWSConfig(newConfigsOrUrl));
46
- };
1
+ import fetch from 'cross-fetch';
2
+ import * as fs from 'fs';
3
+
4
+ import { AWSComponent } from './define';
5
+
6
+ export interface AWSConfig {
7
+ [key: string]: string | boolean | number | undefined;
8
+ }
9
+
10
+ export interface AWSConfigs {
11
+ [service: string]: AWSConfig;
12
+ }
13
+
14
+ export type AWSConfigResolver = (service: string) => AWSConfig;
15
+
16
+ export type SimpleAWSConfigLoadParam = AWSConfigs | string;
17
+
18
+ export class SimpleAWSConfig {
19
+ private configs: AWSConfigs | undefined;
20
+
21
+ public constructor(configs?: AWSConfigs) {
22
+ this.configs = configs;
23
+ }
24
+
25
+ public get = (service: AWSComponent): AWSConfig | undefined => {
26
+ return this.configs ? this.configs[service] : undefined;
27
+ };
28
+ }
29
+
30
+ export const loadAWSConfig = (
31
+ newConfigsOrUrl: SimpleAWSConfigLoadParam,
32
+ ): Promise<SimpleAWSConfig> => {
33
+ if (typeof newConfigsOrUrl === 'string') {
34
+ if (/^http.*json$/.test(newConfigsOrUrl)) {
35
+ return fetch(newConfigsOrUrl)
36
+ .then((r) => r.json())
37
+ .then(loadAWSConfig);
38
+ } else if (/json$/.test(newConfigsOrUrl)) {
39
+ return loadAWSConfig(
40
+ JSON.parse(fs.readFileSync(newConfigsOrUrl, 'utf-8')),
41
+ );
42
+ }
43
+ return loadAWSConfig(JSON.parse(newConfigsOrUrl));
44
+ }
45
+ return Promise.resolve(new SimpleAWSConfig(newConfigsOrUrl));
46
+ };
package/src/aws/define.ts CHANGED
@@ -1,10 +1,10 @@
1
- export enum AWSComponent {
2
- s3 = 's3',
3
- sqs = 'sqs',
4
- dynamodb = 'dynamodb',
5
- }
6
-
7
- export interface SQSMessageBody<T> {
8
- handle: string;
9
- body?: T;
10
- }
1
+ export enum AWSComponent {
2
+ s3 = 's3',
3
+ sqs = 'sqs',
4
+ dynamodb = 'dynamodb',
5
+ }
6
+
7
+ export interface SQSMessageBody<T> {
8
+ handle: string;
9
+ body?: T;
10
+ }
package/src/aws/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './define';
2
- export * from './config';
3
- export * from './simple';
1
+ export * from './define';
2
+ export * from './config';
3
+ export * from './simple';