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
|
-
|
|
21
|
-
.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
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
|
|
129
|
+
async checkAuthBeforeRequest() {
|
|
130
|
+
return;
|
|
122
131
|
}
|
|
123
132
|
/**
|
|
124
133
|
* To @override
|
|
125
134
|
*/
|
|
126
|
-
getResource() {
|
|
127
|
-
|
|
135
|
+
async getResource() {
|
|
136
|
+
throw new Error('Unsupported method');
|
|
128
137
|
}
|
|
129
138
|
/**
|
|
130
139
|
* To @override
|
|
131
140
|
*/
|
|
132
|
-
postResource() {
|
|
133
|
-
|
|
141
|
+
async postResource() {
|
|
142
|
+
throw new Error('Unsupported method');
|
|
134
143
|
}
|
|
135
144
|
/**
|
|
136
145
|
* To @override
|
|
137
146
|
*/
|
|
138
|
-
putResource() {
|
|
139
|
-
|
|
147
|
+
async putResource() {
|
|
148
|
+
throw new Error('Unsupported method');
|
|
140
149
|
}
|
|
141
150
|
/**
|
|
142
151
|
* To @override
|
|
143
152
|
*/
|
|
144
|
-
deleteResource() {
|
|
145
|
-
|
|
153
|
+
async deleteResource() {
|
|
154
|
+
throw new Error('Unsupported method');
|
|
146
155
|
}
|
|
147
156
|
/**
|
|
148
157
|
* To @override
|
|
149
158
|
*/
|
|
150
|
-
headResource() {
|
|
151
|
-
|
|
159
|
+
async headResource() {
|
|
160
|
+
throw new Error('Unsupported method');
|
|
152
161
|
}
|
|
153
162
|
/**
|
|
154
163
|
* To @override
|
|
155
164
|
*/
|
|
156
|
-
getResources() {
|
|
157
|
-
|
|
165
|
+
async getResources() {
|
|
166
|
+
throw new Error('Unsupported method');
|
|
158
167
|
}
|
|
159
168
|
/**
|
|
160
169
|
* To @override
|
|
161
170
|
*/
|
|
162
|
-
postResources() {
|
|
163
|
-
|
|
171
|
+
async postResources() {
|
|
172
|
+
throw new Error('Unsupported method');
|
|
164
173
|
}
|
|
165
174
|
/**
|
|
166
175
|
* To @override
|
|
167
176
|
*/
|
|
168
|
-
putResources() {
|
|
169
|
-
|
|
177
|
+
async putResources() {
|
|
178
|
+
throw new Error('Unsupported method');
|
|
170
179
|
}
|
|
171
180
|
/**
|
|
172
181
|
* To @override
|
|
173
182
|
*/
|
|
174
|
-
patchResource() {
|
|
175
|
-
|
|
183
|
+
async patchResource() {
|
|
184
|
+
throw new Error('Unsupported method');
|
|
176
185
|
}
|
|
177
186
|
/**
|
|
178
187
|
* To @override
|
|
179
188
|
*/
|
|
180
|
-
patchResources() {
|
|
181
|
-
|
|
189
|
+
async patchResources() {
|
|
190
|
+
throw new Error('Unsupported method');
|
|
182
191
|
}
|
|
183
192
|
/**
|
|
184
193
|
* To @override
|
|
185
194
|
*/
|
|
186
|
-
deleteResources() {
|
|
187
|
-
|
|
195
|
+
async deleteResources() {
|
|
196
|
+
throw new Error('Unsupported method');
|
|
188
197
|
}
|
|
189
198
|
/**
|
|
190
199
|
* To @override
|
|
191
200
|
*/
|
|
192
|
-
headResources() {
|
|
193
|
-
|
|
201
|
+
async headResources() {
|
|
202
|
+
throw new Error('Unsupported method');
|
|
194
203
|
}
|
|
195
204
|
///
|
|
196
205
|
/// HELPERS
|