idea-aws 3.8.7 → 3.9.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.
@@ -30,6 +30,13 @@ export declare class Cognito {
30
30
  * Identify a user by its userId (sub), returning its attributes.
31
31
  */
32
32
  getUserBySub(sub: string, cognitoUserPoolId: string): Promise<CognitoUserGeneric>;
33
+ /**
34
+ * Get all the users of the pool.
35
+ */
36
+ getAllUsers(cognitoUserPoolId: string, options?: {
37
+ pagination?: string;
38
+ users: CognitoUser[];
39
+ }): Promise<CognitoUser[]>;
33
40
  /**
34
41
  * Create a new user (by its email) in the pool specified.
35
42
  * @return userId of the new user
@@ -72,6 +72,21 @@ class Cognito {
72
72
  throw new Error('User not found');
73
73
  return this.mapCognitoUserAttributesAsPlainObject(user);
74
74
  }
75
+ /**
76
+ * Get all the users of the pool.
77
+ */
78
+ async getAllUsers(cognitoUserPoolId, options = { users: [] }) {
79
+ const params = { UserPoolId: cognitoUserPoolId };
80
+ if (options.pagination)
81
+ params.PaginationToken = options.pagination;
82
+ const res = await this.cognito.listUsers(params).promise();
83
+ const pagination = res.PaginationToken;
84
+ const users = options.users.concat(res.Users.map(u => new idea_toolbox_1.CognitoUser(this.mapCognitoUserAttributesAsPlainObject(u))));
85
+ if (pagination)
86
+ return await this.getAllUsers(cognitoUserPoolId, { pagination, users });
87
+ else
88
+ return users;
89
+ }
75
90
  /**
76
91
  * Create a new user (by its email) in the pool specified.
77
92
  * @return userId of the new user
@@ -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: () => Promise<void>;
24
+ handleRequest: () => void;
25
25
  protected done(err: Error | null, res?: any, statusCode?: number): void;
26
26
  /**
27
27
  * To @override
@@ -81,12 +81,14 @@ export declare abstract class ResourceController extends GenericController {
81
81
  protected storeLog(succeeded: boolean): void;
82
82
  /**
83
83
  * Check whether shared resource exists in the back-end (translation, template, etc.).
84
+ * Search for the specified file path in both the Lambda function's main folder and the layers folder.
84
85
  */
85
- sharedResourceExists(path: string): boolean;
86
+ sharedResourceExists(filePath: string): boolean;
86
87
  /**
87
88
  * Load a shared resource in the back-end (translation, template, etc.).
89
+ * Search for the specified file path in both the Lambda function's main folder and the layers folder.
88
90
  */
89
- loadSharedResource(path: string): string;
91
+ loadSharedResource(filePath: string): string;
90
92
  /**
91
93
  * Simulate an internal API request, invoking directly the lambda and therefore saving resources.
92
94
  * @return the body of the response
@@ -16,72 +16,63 @@ class ResourceController extends genericController_1.GenericController {
16
16
  ///
17
17
  /// REQUEST HANDLERS
18
18
  ///
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
- }
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 */
48
45
  }
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
- }
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 */
73
68
  }
74
- this.done(null, response);
75
- }
76
- catch (err) {
77
- const errorMessage = err?.message || err?.errorMessage || 'Operation failed';
78
- this.done(new Error(errorMessage));
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));
79
73
  }
80
- }
81
- catch (err) {
82
- const errorMessage = err?.message || err?.errorMessage || 'Forbidden';
83
- this.done(new Error(errorMessage));
84
- }
74
+ })
75
+ .catch(err => this.done(new Error(err?.message ?? 'Forbidden')));
85
76
  };
86
77
  this.authorization = event.headers?.Authorization;
87
78
  this.claims = event.requestContext?.authorizer?.claims;
@@ -126,80 +117,80 @@ class ResourceController extends genericController_1.GenericController {
126
117
  /**
127
118
  * To @override
128
119
  */
129
- async checkAuthBeforeRequest() {
130
- return;
120
+ checkAuthBeforeRequest() {
121
+ return new Promise(resolve => resolve());
131
122
  }
132
123
  /**
133
124
  * To @override
134
125
  */
135
- async getResource() {
136
- throw new Error('Unsupported method');
126
+ getResource() {
127
+ return new Promise((_, reject) => reject(new Error('Unsupported method')));
137
128
  }
138
129
  /**
139
130
  * To @override
140
131
  */
141
- async postResource() {
142
- throw new Error('Unsupported method');
132
+ postResource() {
133
+ return new Promise((_, reject) => reject(new Error('Unsupported method')));
143
134
  }
144
135
  /**
145
136
  * To @override
146
137
  */
147
- async putResource() {
148
- throw new Error('Unsupported method');
138
+ putResource() {
139
+ return new Promise((_, reject) => reject(new Error('Unsupported method')));
149
140
  }
150
141
  /**
151
142
  * To @override
152
143
  */
153
- async deleteResource() {
154
- throw new Error('Unsupported method');
144
+ deleteResource() {
145
+ return new Promise((_, reject) => reject(new Error('Unsupported method')));
155
146
  }
156
147
  /**
157
148
  * To @override
158
149
  */
159
- async headResource() {
160
- throw new Error('Unsupported method');
150
+ headResource() {
151
+ return new Promise((_, reject) => reject(new Error('Unsupported method')));
161
152
  }
162
153
  /**
163
154
  * To @override
164
155
  */
165
- async getResources() {
166
- throw new Error('Unsupported method');
156
+ getResources() {
157
+ return new Promise((_, reject) => reject(new Error('Unsupported method')));
167
158
  }
168
159
  /**
169
160
  * To @override
170
161
  */
171
- async postResources() {
172
- throw new Error('Unsupported method');
162
+ postResources() {
163
+ return new Promise((_, reject) => reject(new Error('Unsupported method')));
173
164
  }
174
165
  /**
175
166
  * To @override
176
167
  */
177
- async putResources() {
178
- throw new Error('Unsupported method');
168
+ putResources() {
169
+ return new Promise((_, reject) => reject(new Error('Unsupported method')));
179
170
  }
180
171
  /**
181
172
  * To @override
182
173
  */
183
- async patchResource() {
184
- throw new Error('Unsupported method');
174
+ patchResource() {
175
+ return new Promise((_, reject) => reject(new Error('Unsupported method')));
185
176
  }
186
177
  /**
187
178
  * To @override
188
179
  */
189
- async patchResources() {
190
- throw new Error('Unsupported method');
180
+ patchResources() {
181
+ return new Promise((_, reject) => reject(new Error('Unsupported method')));
191
182
  }
192
183
  /**
193
184
  * To @override
194
185
  */
195
- async deleteResources() {
196
- throw new Error('Unsupported method');
186
+ deleteResources() {
187
+ return new Promise((_, reject) => reject(new Error('Unsupported method')));
197
188
  }
198
189
  /**
199
190
  * To @override
200
191
  */
201
- async headResources() {
202
- throw new Error('Unsupported method');
192
+ headResources() {
193
+ return new Promise((_, reject) => reject(new Error('Unsupported method')));
203
194
  }
204
195
  ///
205
196
  /// HELPERS
@@ -226,15 +217,22 @@ class ResourceController extends genericController_1.GenericController {
226
217
  }
227
218
  /**
228
219
  * Check whether shared resource exists in the back-end (translation, template, etc.).
220
+ * Search for the specified file path in both the Lambda function's main folder and the layers folder.
229
221
  */
230
- sharedResourceExists(path) {
231
- return (0, fs_1.existsSync)(`assets/${path}`);
222
+ sharedResourceExists(filePath) {
223
+ return (0, fs_1.existsSync)(`assets/${filePath}`) || (0, fs_1.existsSync)(`/opt/nodejs/assets/${filePath}`);
232
224
  }
233
225
  /**
234
226
  * Load a shared resource in the back-end (translation, template, etc.).
227
+ * Search for the specified file path in both the Lambda function's main folder and the layers folder.
235
228
  */
236
- loadSharedResource(path) {
237
- return (0, fs_1.readFileSync)(`assets/${path}`, { encoding: 'utf-8' });
229
+ loadSharedResource(filePath) {
230
+ let path = null;
231
+ if ((0, fs_1.existsSync)(`assets/${filePath}`))
232
+ path = `assets/${filePath}`;
233
+ else if ((0, fs_1.existsSync)(`/opt/nodejs/assets/${filePath}`))
234
+ path = `/opt/nodejs/assets/${filePath}`;
235
+ return path ? (0, fs_1.readFileSync)(path, { encoding: 'utf-8' }) : null;
238
236
  }
239
237
  ///
240
238
  /// MANAGE INTERNAL API REQUESTS (lambda invokes masked as API requests)
package/dist/src/ses.d.ts CHANGED
@@ -112,9 +112,10 @@ export interface TemplatedEmailData extends BasicEmailData {
112
112
  template: string;
113
113
  /**
114
114
  * An object containing key-value pairs of variable-content to substitute.
115
+ * It supports handlebars.js templating.
115
116
  */
116
117
  templateData: {
117
- [variable: string]: string;
118
+ [variable: string]: any;
118
119
  };
119
120
  /**
120
121
  * The name of the configuration set to use for the sending.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "idea-aws",
3
- "version": "3.8.7",
3
+ "version": "3.9.1",
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",