idea-aws 3.9.1 → 3.9.2

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.
@@ -21,7 +21,7 @@ export declare abstract class ResourceController extends GenericController {
21
21
  protected translations: any;
22
22
  protected templateMatcher: RegExp;
23
23
  constructor(event: any, callback: any, options?: ResourceControllerOptions);
24
- handleRequest: () => void;
24
+ handleRequest: () => Promise<void>;
25
25
  protected done(err: Error | null, res?: any, statusCode?: number): void;
26
26
  /**
27
27
  * To @override
@@ -16,63 +16,72 @@ class ResourceController extends genericController_1.GenericController {
16
16
  ///
17
17
  /// REQUEST HANDLERS
18
18
  ///
19
- this.handleRequest = () => {
20
- this.checkAuthBeforeRequest()
21
- .then(() => {
22
- let request;
23
- if (this.resourceId)
24
- switch (this.httpMethod) {
25
- // resource/{resourceId}
26
- case 'GET':
27
- request = this.getResource();
28
- break;
29
- case 'POST':
30
- request = this.postResource();
31
- break;
32
- case 'PUT':
33
- request = this.putResource();
34
- break;
35
- case 'DELETE':
36
- request = this.deleteResource();
37
- break;
38
- case 'PATCH':
39
- request = this.patchResource();
40
- break;
41
- case 'HEAD':
42
- request = this.headResource();
43
- break;
44
- default: /* nope */
19
+ this.handleRequest = async () => {
20
+ try {
21
+ await this.checkAuthBeforeRequest();
22
+ try {
23
+ let response;
24
+ if (this.resourceId) {
25
+ switch (this.httpMethod) {
26
+ // resource/{resourceId}
27
+ case 'GET':
28
+ response = await this.getResource();
29
+ break;
30
+ case 'POST':
31
+ response = await this.postResource();
32
+ break;
33
+ case 'PUT':
34
+ response = await this.putResource();
35
+ break;
36
+ case 'DELETE':
37
+ response = await this.deleteResource();
38
+ break;
39
+ case 'PATCH':
40
+ response = await this.patchResource();
41
+ break;
42
+ case 'HEAD':
43
+ response = await this.headResource();
44
+ break;
45
+ default:
46
+ this.done(new Error('Unsupported method'));
47
+ }
45
48
  }
46
- else
47
- switch (this.httpMethod) {
48
- // resource
49
- case 'GET':
50
- request = this.getResources();
51
- break;
52
- case 'POST':
53
- request = this.postResources();
54
- break;
55
- case 'PUT':
56
- request = this.putResources();
57
- break;
58
- case 'DELETE':
59
- request = this.deleteResources();
60
- break;
61
- case 'PATCH':
62
- request = this.patchResources();
63
- break;
64
- case 'HEAD':
65
- request = this.headResources();
66
- break;
67
- default: /* nope */
49
+ else {
50
+ switch (this.httpMethod) {
51
+ // resource
52
+ case 'GET':
53
+ response = await this.getResources();
54
+ break;
55
+ case 'POST':
56
+ response = await this.postResources();
57
+ break;
58
+ case 'PUT':
59
+ response = await this.putResources();
60
+ break;
61
+ case 'DELETE':
62
+ response = await this.deleteResources();
63
+ break;
64
+ case 'PATCH':
65
+ response = await this.patchResources();
66
+ break;
67
+ case 'HEAD':
68
+ response = await this.headResources();
69
+ break;
70
+ default:
71
+ this.done(new Error('Unsupported method'));
72
+ }
68
73
  }
69
- if (!request)
70
- this.done(new Error('Unsupported method'));
71
- else {
72
- request.then((res) => this.done(null, res)).catch((err) => this.done(err));
74
+ this.done(null, response);
75
+ }
76
+ catch (err) {
77
+ const errorMessage = err?.message || err?.errorMessage || 'Operation failed';
78
+ this.done(new Error(errorMessage));
73
79
  }
74
- })
75
- .catch(err => this.done(new Error(err?.message ?? 'Forbidden')));
80
+ }
81
+ catch (err) {
82
+ const errorMessage = err?.message || err?.errorMessage || 'Forbidden';
83
+ this.done(new Error(errorMessage));
84
+ }
76
85
  };
77
86
  this.authorization = event.headers?.Authorization;
78
87
  this.claims = event.requestContext?.authorizer?.claims;
@@ -117,80 +126,80 @@ class ResourceController extends genericController_1.GenericController {
117
126
  /**
118
127
  * To @override
119
128
  */
120
- checkAuthBeforeRequest() {
121
- return new Promise(resolve => resolve());
129
+ async checkAuthBeforeRequest() {
130
+ return;
122
131
  }
123
132
  /**
124
133
  * To @override
125
134
  */
126
- getResource() {
127
- return new Promise((_, reject) => reject(new Error('Unsupported method')));
135
+ async getResource() {
136
+ throw new Error('Unsupported method');
128
137
  }
129
138
  /**
130
139
  * To @override
131
140
  */
132
- postResource() {
133
- return new Promise((_, reject) => reject(new Error('Unsupported method')));
141
+ async postResource() {
142
+ throw new Error('Unsupported method');
134
143
  }
135
144
  /**
136
145
  * To @override
137
146
  */
138
- putResource() {
139
- return new Promise((_, reject) => reject(new Error('Unsupported method')));
147
+ async putResource() {
148
+ throw new Error('Unsupported method');
140
149
  }
141
150
  /**
142
151
  * To @override
143
152
  */
144
- deleteResource() {
145
- return new Promise((_, reject) => reject(new Error('Unsupported method')));
153
+ async deleteResource() {
154
+ throw new Error('Unsupported method');
146
155
  }
147
156
  /**
148
157
  * To @override
149
158
  */
150
- headResource() {
151
- return new Promise((_, reject) => reject(new Error('Unsupported method')));
159
+ async headResource() {
160
+ throw new Error('Unsupported method');
152
161
  }
153
162
  /**
154
163
  * To @override
155
164
  */
156
- getResources() {
157
- return new Promise((_, reject) => reject(new Error('Unsupported method')));
165
+ async getResources() {
166
+ throw new Error('Unsupported method');
158
167
  }
159
168
  /**
160
169
  * To @override
161
170
  */
162
- postResources() {
163
- return new Promise((_, reject) => reject(new Error('Unsupported method')));
171
+ async postResources() {
172
+ throw new Error('Unsupported method');
164
173
  }
165
174
  /**
166
175
  * To @override
167
176
  */
168
- putResources() {
169
- return new Promise((_, reject) => reject(new Error('Unsupported method')));
177
+ async putResources() {
178
+ throw new Error('Unsupported method');
170
179
  }
171
180
  /**
172
181
  * To @override
173
182
  */
174
- patchResource() {
175
- return new Promise((_, reject) => reject(new Error('Unsupported method')));
183
+ async patchResource() {
184
+ throw new Error('Unsupported method');
176
185
  }
177
186
  /**
178
187
  * To @override
179
188
  */
180
- patchResources() {
181
- return new Promise((_, reject) => reject(new Error('Unsupported method')));
189
+ async patchResources() {
190
+ throw new Error('Unsupported method');
182
191
  }
183
192
  /**
184
193
  * To @override
185
194
  */
186
- deleteResources() {
187
- return new Promise((_, reject) => reject(new Error('Unsupported method')));
195
+ async deleteResources() {
196
+ throw new Error('Unsupported method');
188
197
  }
189
198
  /**
190
199
  * To @override
191
200
  */
192
- headResources() {
193
- return new Promise((_, reject) => reject(new Error('Unsupported method')));
201
+ async headResources() {
202
+ throw new Error('Unsupported method');
194
203
  }
195
204
  ///
196
205
  /// HELPERS
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "idea-aws",
3
- "version": "3.9.1",
3
+ "version": "3.9.2",
4
4
  "description": "AWS wrappers to use in IDEA's back-ends",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",