lambda-toolkit 1.0.0 → 1.1.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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +2053 -2019
  3. package/package.json +18 -17
package/dist/index.js CHANGED
@@ -1,44 +1,227 @@
1
1
  /******/ (() => { // webpackBootstrap
2
2
  /******/ var __webpack_modules__ = ({
3
3
 
4
- /***/ 44:
5
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
4
+ /***/ 8278
5
+ (module, __unused_webpack_exports, __webpack_require__) {
6
6
 
7
- const { LambdaApi } = __webpack_require__( 2705 );
8
- const array = __webpack_require__( 8278 );
9
- const aws = __webpack_require__( 4870 );
10
- const epoch = __webpack_require__( 3830 );
11
- const math = __webpack_require__( 943 );
12
- const object = __webpack_require__( 5762 );
13
- const redis = __webpack_require__( 4528 );
14
- const string = __webpack_require__( 268 );
15
- const utils = __webpack_require__( 6878 );
7
+ const joinUnique = __webpack_require__( 2836 );
8
+ const joinUniqueCustom = __webpack_require__( 536 );
9
+ const splitBatches = __webpack_require__( 4821 );
16
10
 
17
11
  module.exports = {
18
- array,
19
- aws,
20
- epoch,
21
- LambdaApi,
22
- math,
23
- object,
24
- redis,
25
- string,
26
- utils
12
+ joinUnique,
13
+ joinUniqueCustom,
14
+ splitBatches
27
15
  };
28
16
 
29
17
 
30
- /***/ }),
18
+ /***/ },
31
19
 
32
- /***/ 115:
33
- /***/ ((module) => {
20
+ /***/ 2836
21
+ (module) {
34
22
 
35
- module.exports = ( n, d = 2 ) => Math.round( n * ( 10 ** d ) ) / ( 10 ** d );
23
+ module.exports = ( ...args ) => [ ...new Set( args.filter( Array.isArray ).flat() ) ];
24
+
25
+
26
+ /***/ },
27
+
28
+ /***/ 536
29
+ (module) {
30
+
31
+ module.exports = ( { key, items } ) => [
32
+ ...items.filter( Array.isArray ).flat().reduce( ( map, v ) => {
33
+ const k = key( v );
34
+ if ( !map.has( k ) ) {
35
+ map.set( k, v );
36
+ }
37
+ return map;
38
+ }, new Map() ).values()
39
+ ];
40
+
41
+
42
+ /***/ },
43
+
44
+ /***/ 4821
45
+ (module) {
46
+
47
+ module.exports = ( items, size ) => items.reduce( ( arrs, item ) =>
48
+ ( arrs[0] && arrs[0].length < size ) ?
49
+ [ [ ...arrs[0], item ] ].concat( arrs.slice( 1 ) ) :
50
+ [ [ item ] ].concat( arrs )
51
+ , [] ).reverse();
52
+
53
+
54
+ /***/ },
55
+
56
+ /***/ 228
57
+ (module, __unused_webpack_exports, __webpack_require__) {
58
+
59
+ const { AthenaClient } = __webpack_require__( 3744 );
60
+ const clientProvider = __webpack_require__( 9039 );
61
+ const query = __webpack_require__( 140 );
62
+ const createInstance = __webpack_require__( 5438 );
63
+
64
+ const methods = {
65
+ query
66
+ };
67
+
68
+ module.exports = createInstance( clientProvider.bind( null, AthenaClient ), methods );
69
+
70
+
71
+ /***/ },
72
+
73
+ /***/ 7337
74
+ (module, __unused_webpack_exports, __webpack_require__) {
75
+
76
+ const { GetQueryExecutionCommand, GetQueryResultsCommand } = __webpack_require__( 3744 );
77
+ const parseResults = __webpack_require__( 834 );
78
+ const pollingDelay = __webpack_require__( 4127 );
79
+
80
+ const sleep = t => new Promise( r => setTimeout( () => r(), t ) );
81
+
82
+ const getQueryResults = async ( { client, queryExecutionId, maxResults, token } ) => {
83
+ const { NextToken: nextToken, ResultSet } = await client.send( new GetQueryResultsCommand( {
84
+ ...{ QueryExecutionId: queryExecutionId },
85
+ ...( maxResults ? { MaxResults: maxResults } : {} ),
86
+ ...( token ? { NextToken: token } : {} )
87
+ } ) );
88
+
89
+ return { nextToken, items: parseResults( ResultSet ) };
90
+ };
91
+ const getQueryResultsRecursive = async ( { client, queryExecutionId, token } ) => {
92
+ const { nextToken, items } = await getQueryResults( { client, queryExecutionId, token } );
93
+
94
+ if ( nextToken ) {
95
+ return { items: items.concat( ( await getQueryResultsRecursive( { client, queryExecutionId, token: nextToken } ) ).items ) };
96
+ }
97
+ return { items };
98
+ };
99
+
100
+ /**
101
+ * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/athena/command/GetQueryResultsCommand/
102
+ * { client, recursive, queryExecutionId, maxResults, paginationToken }
103
+ */
104
+ const getResults = async ( { client, recursive, queryExecutionId, token, maxResults } ) => {
105
+ const { QueryExecution: { Status: status } } = await client.send( new GetQueryExecutionCommand( { QueryExecutionId: queryExecutionId } ) );
106
+
107
+ if ( status.State === 'FAILED' ) {
108
+ throw new Error( status.AthenaError?.ErrorMessage ?? status.StateChangeReason );
109
+ }
110
+
111
+ if ( status.State === 'SUCCEEDED' ) {
112
+ const fn = recursive ? getQueryResultsRecursive : getQueryResults;
113
+ return fn( { client, recursive, queryExecutionId, token, maxResults } );
114
+ }
115
+
116
+ // sleep an try again
117
+ await sleep( pollingDelay );
118
+ return getResults( { client, recursive, queryExecutionId, token, maxResults } );
119
+ };
120
+
121
+ module.exports = getResults;
122
+
123
+
124
+ /***/ },
125
+
126
+ /***/ 834
127
+ (module, __unused_webpack_exports, __webpack_require__) {
128
+
129
+ const parseValue = __webpack_require__( 9129 );
130
+
131
+ module.exports = resultSet => {
132
+ const columns = resultSet.ResultSetMetadata.ColumnInfo
133
+ .map( col => ( { name: col.Name, type: col.Type } ) );
134
+
135
+ // first data row contains the table field names
136
+ return resultSet.Rows.slice( 1 ).map( row => {
137
+ const values = row.Data.map( d => d.VarCharValue );
138
+ return columns.reduce( ( obj, p, i ) => Object.assign( obj, { [p.name]: parseValue( values[i], p.type ) } ), {} );
139
+ } );
140
+ };
36
141
 
37
142
 
38
- /***/ }),
143
+ /***/ },
39
144
 
40
- /***/ 140:
41
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
145
+ /***/ 9129
146
+ (module) {
147
+
148
+ /* eslint consistent-return: 0 */
149
+ const removeNullValues = ( o, isArray = Array.isArray( o ) ) =>
150
+ Object.entries( o ).reduce( ( newObj, [ k, v ] ) => {
151
+ if ( v === null && !isArray ) { return newObj; }
152
+ return Object.assign( newObj, { [k]: v?.constructor === Object ? removeNullValues( v ) : v } );
153
+ }, isArray ? [] : {} );
154
+
155
+ module.exports = ( v, type ) => {
156
+ if ( [ null, undefined ].includes( v ) ) {
157
+ return undefined;
158
+ }
159
+ if ( v === '' && type !== 'varchar' ) {
160
+ return undefined;
161
+ }
162
+ if ( type === 'boolean' ) {
163
+ return v === 'true';
164
+ }
165
+ if ( [ 'float', 'decimal', 'double' ].includes( type ) ) {
166
+ return parseFloat( v );
167
+ }
168
+ if ( [ 'tinyint', 'smallint', 'int', 'bigint' ].includes( type ) ) {
169
+ return parseInt( v );
170
+ }
171
+ if ( 'timestamp' === type ) {
172
+ return new Date( v ).getTime();
173
+ }
174
+ if ( [ 'row', 'array' ].includes( type ) ) {
175
+ const obj = v.replace( /(?<=(?:{|,\s)[\w-_]+)=/g, '@@DELIMITER@@' ) // replaces delimiter = with @@DELIMITER@@
176
+ .replace( /(?<={|,\s)([\w_-]+)(?=@@DELIMITER@@)/g, '"$1"' ) // wrap object keys
177
+ .replace( /(?<=@@DELIMITER@@)((?:(?!,\s|}|\[|{).)+)/g, '"$1"' ) // wrap object values
178
+ .replace( /(?<=\[|,\s)((?:(?!,\s|{|\]|").)+)/g, '"$1"' ) // wrap array values
179
+ .replace( /"null"/g, 'null' ) // convert "null" to null
180
+ .replace( /@@DELIMITER@@/g, ':' ); // replaces @@DELIMITER@@ for :
181
+
182
+ return removeNullValues( JSON.parse( obj ) );
183
+ }
184
+ if ( 'json' === type ) {
185
+ return JSON.parse( v );
186
+ }
187
+ return v;
188
+ };
189
+
190
+
191
+ /***/ },
192
+
193
+ /***/ 4127
194
+ (module) {
195
+
196
+ module.exports = 500;
197
+
198
+
199
+ /***/ },
200
+
201
+ /***/ 5723
202
+ (module, __unused_webpack_exports, __webpack_require__) {
203
+
204
+ const { randomBytes } = __webpack_require__( 6982 );
205
+ const { StartQueryExecutionCommand } = __webpack_require__( 3744 );
206
+
207
+ /**
208
+ * args : https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/athena/command/StartQueryExecutionCommand/
209
+ * A ClientRequestToken is created automatically
210
+ */
211
+ module.exports = async ( { client, ...args } ) => {
212
+ const cmd = new StartQueryExecutionCommand( {
213
+ ClientRequestToken: randomBytes( 16 ).toString( 'hex' ),
214
+ ...args
215
+ } );
216
+ const { QueryExecutionId: queryId } = await client.send( cmd );
217
+ return queryId;
218
+ };
219
+
220
+
221
+ /***/ },
222
+
223
+ /***/ 140
224
+ (module, __unused_webpack_exports, __webpack_require__) {
42
225
 
43
226
  const { encode, decode } = __webpack_require__( 5744 );
44
227
  const startQuery = __webpack_require__( 5723 );
@@ -81,851 +264,225 @@ module.exports = async ( client, nativeArgs, options ) => {
81
264
  };
82
265
 
83
266
 
84
- /***/ }),
85
-
86
- /***/ 228:
87
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
88
-
89
- const { AthenaClient } = __webpack_require__( 3744 );
90
- const clientProvider = __webpack_require__( 9039 );
91
- const query = __webpack_require__( 140 );
92
- const createInstance = __webpack_require__( 5438 );
93
-
94
- const methods = {
95
- query
96
- };
97
-
98
- module.exports = createInstance( clientProvider.bind( null, AthenaClient ), methods );
267
+ /***/ },
99
268
 
269
+ /***/ 4164
270
+ (module, __unused_webpack_exports, __webpack_require__) {
100
271
 
101
- /***/ }),
272
+ const cacheSym = Symbol.for( 'cache' );
273
+ const crypto = __webpack_require__( 6982 );
102
274
 
103
- /***/ 268:
104
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
275
+ const hash = text => crypto.createHash( 'md5' ).update( text ).digest( 'hex' );
105
276
 
106
- const camelize = __webpack_require__( 3914 );
107
- const capitalizeWords = __webpack_require__( 3258 );
108
- const snakelize = __webpack_require__( 3402 );
277
+ const propOpts = {
278
+ enumerable: false,
279
+ configurable: false,
280
+ writable: false
281
+ };
109
282
 
110
283
  module.exports = {
111
- camelize,
112
- capitalizeWords,
113
- snakelize
114
- };
284
+ set: ( key, value ) => {
285
+ const keySym = Symbol.for( hash( key ) );
115
286
 
287
+ if ( !global[cacheSym] ) {
288
+ Object.defineProperty( global, cacheSym, { ...propOpts, value: {} } );
289
+ }
116
290
 
117
- /***/ }),
291
+ Object.defineProperty( global[cacheSym], keySym, { ...propOpts, value } );
292
+ },
293
+ get: key => {
294
+ return global[cacheSym]?.[Symbol.for( hash( key ) )];
295
+ }
296
+ };
118
297
 
119
- /***/ 279:
120
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
121
298
 
122
- const { HeadObjectCommand } = __webpack_require__( 5725 );
299
+ /***/ },
123
300
 
124
- module.exports = async ( client, bucket, key ) =>
125
- client.send( new HeadObjectCommand( { Bucket: bucket, Key: key } ) );
301
+ /***/ 5438
302
+ (module) {
126
303
 
304
+ /**
305
+ * This is base object each AWS abstraction will provide
306
+ */
307
+ module.exports = ( providerFn, methods ) => {
308
+ // This creates the "instance",
309
+ // so calling the method as a function returns a copy of its client instantiated with the given args
310
+ // every method called from it will use this instance
311
+ const factory = args => {
312
+ const client = providerFn( args );
313
+ // return self, so it is possible use the native client
314
+ methods.getClient = () => client;
315
+ return Object.entries( methods ).reduce( ( o, [ k, v ] ) => Object.assign( o, { [k]: v.bind( null, client ) } ), { } );
316
+ };
127
317
 
128
- /***/ }),
318
+ // This is the singleton part;
319
+ // First add the static method to the factory;
320
+ Object.entries( methods ).forEach( ( [ key, value ] ) => factory[key] = value );
129
321
 
130
- /***/ 321:
131
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
322
+ // Then add the special method "getClient", so it is possible use the native client
323
+ factory.getClient = client => client;
132
324
 
133
- const validators = __webpack_require__( 8994 );
134
- const ApiResponse = __webpack_require__( 3119 );
135
- const Event = __webpack_require__( 329 );
136
- const Handler = __webpack_require__( 3109 );
137
- const Hook = __webpack_require__( 798 );
138
- const UserResponse = __webpack_require__( 8282 );
139
- const Text = __webpack_require__( 9760 );
140
-
141
- module.exports = class LambdaApi {
142
- #apiResponse = null;
143
- #handlers = [];
144
- #errorResponses = [];
145
- #beforeHooks = [];
146
- #afterHooks = [];
147
- #transformRequest = [];
148
-
149
- /**
150
- * Creates a new Lambda Api
151
- *
152
- * @param {Object} headers Any headers you want to be included in all responses
153
- */
154
- constructor( { headers = {}, transformRequest = false, transformResponse = false } = {} ) {
155
- validators.transformRequest( transformRequest );
156
- validators.transformResponse( transformResponse );
157
-
158
- this.#transformRequest = transformRequest;
159
- this.#apiResponse = new ApiResponse( { headers, transform: transformResponse } );
160
- }
161
-
162
- /**
163
- * Register a function that will run before the matching route (only if matches)
164
- *
165
- * @param {Object} args
166
- * @param {function} args.fn A function
167
- */
168
- addBeforeHook( { fn } = {} ) {
169
- this.#beforeHooks.push( new Hook( { fn } ) );
170
- }
171
-
172
- /**
173
- * Register a function that will run after the matching route (only if matches)
174
- *
175
- * @param {Object} args
176
- * @param {function} args.fn A function
177
- */
178
- addAfterHook( { fn } = {} ) {
179
- this.#afterHooks.push( new Hook( { fn } ) );
180
- }
181
-
182
- /**
183
- * Register a handler for a given request method and optionally a path
184
- *
185
- * @param {Object} args
186
- * @param {string} args.method The method to match this handler
187
- * @param {function} args.fn The handler function
188
- * @param {string} [args.route] A route to match this handler
189
- * @param {string} [args.routeIncludes] A part of the route to match this handler
190
- * @param {string} [args.routeNotIncludes] A part of the route to not match this handler
191
- * @param {RegExp} [args.routeMatches] A RegExp to match the route
192
- * @param {string} [args.path] A path to match this handler
193
- * @param {string} [args.pathIncludes] A part of the path to match this handler
194
- * @param {string} [args.pathNotIncludes] A part of the path to not match this handler
195
- * @param {RegExp} [args.pathMatches] A RegExp to match the path
196
- */
197
- addHandler( { method, fn, ...matchers } = {} ) {
198
- this.#handlers.push( new Handler( { method, fn, ...matchers } ) );
199
- }
200
-
201
- /**
202
- * Register an automatic error code response for given error class (constructor name)
203
- *
204
- * @param {Object} args
205
- * @param {string} args.code The HTTP status code to return
206
- * @param {class} args.errorType The error class
207
- * @param {string} [args.message=null] Optional message to return for the status code, if not present will default to Error.message
208
- * @param {message} [args.errorType] And optional message to display
209
- */
210
- addErrorHandler( { errorType, code, message = null } = {} ) {
211
- validators.statusCode( code );
212
- validators.errorType( errorType );
213
- this.#errorResponses.push( { errorType, code, message } );
214
- }
215
-
216
- /**
217
- * Init the flow using a given AWS Lambda APIGateway event (v2 syntax)
218
- *
219
- * @param {Object} ApiGatewayPayload The raw API Gateway event
220
- * @returns {Object} The http response with status, body and headers
221
- */
222
- async process( awsEvent ) {
223
- const event = new Event( { transform: this.#transformRequest } );
224
- event.parseFromAwsEvent( awsEvent );
225
-
226
- if ( event.method === 'HEAD' ) {
227
- return this.#apiResponse.setContent( 204 ).toJSON();
228
- }
229
-
230
- const handler = this.#handlers.find( h => h.match( event ) );
231
- if ( !handler ) {
232
- return this.#apiResponse.setContent( 405, Text.ERROR_405 ).toJSON();
233
- }
234
-
235
- const chain = [
236
- ...this.#beforeHooks.map( b => b.fn ),
237
- async ev => {
238
- const result = await handler.fn( ev );
239
- const response = new UserResponse( result );
240
- this.#apiResponse.setContent( ...response.values ).toJSON();
241
- },
242
- ...this.#afterHooks.map( a => a.fn )
243
- ];
244
-
245
- try {
246
- for ( const fn of chain ) {
247
- await fn( event );
248
- }
249
- return this.#apiResponse.toJSON();
250
-
251
- } catch ( error ) {
252
- console.error( 'Lambda API Error', { error, event } );
253
-
254
- const response = this.#errorResponses.find( e => error instanceof e.errorType );
255
- if ( response ) {
256
- return this.#apiResponse.setContent( response.code, response.message ?? error.message ).toJSON();
257
- }
258
- return this.#apiResponse.setContent( 500, Text.ERROR_500 ).toJSON();
259
- }
260
- }
261
- };
262
-
263
-
264
- /***/ }),
265
-
266
- /***/ 329:
267
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
268
-
269
- const { camelize, snakelize } = __webpack_require__( 5762 );
270
-
271
- const transformFns = {
272
- camelcase: camelize,
273
- snakecase: snakelize
274
- };
275
-
276
- const parseJson = content => {
277
- try {
278
- return JSON.parse( content );
279
- } catch {
280
- return content;
281
- }
282
- };
283
-
284
- module.exports = class Event {
285
- #transformFn;
286
- authorizer;
287
- body;
288
- headers;
289
- method;
290
- params;
291
- path;
292
- queryString;
293
- route;
294
-
295
- context = {};
296
-
297
- constructor( { transform = false } = {} ) {
298
- this.#transformFn = transformFns[transform] ?? ( v => v );
299
- }
300
-
301
- parseFromAwsEvent( awsEvent ) {
302
- this[`parseFromAwsEventV${awsEvent.version === '2.0' ? 2 : 1}`]( awsEvent );
303
- }
304
-
305
- parseFromAwsEventV1( awsEvent ) {
306
- const {
307
- body,
308
- path,
309
- resource,
310
- httpMethod,
311
- requestContext,
312
- pathParameters,
313
- headers,
314
- multiValueHeaders,
315
- queryStringParameters,
316
- multiValueQueryStringParameters: multiValueQueryString,
317
- isBase64Encoded
318
- } = awsEvent;
319
-
320
- const unifiedHeaders = {
321
- ...headers,
322
- ...Object.fromEntries( Object.entries( multiValueHeaders ?? {} ).map( ( [ k, v ] ) => [ k, Array.isArray( v ) ? v.join( ',' ) : k ] ) )
323
- };
324
-
325
- const unifiedQueryString = {
326
- ...queryStringParameters,
327
- ...Object.fromEntries( Object.entries( multiValueQueryString ?? {} ).map( ( [ k, v ] ) => [ k, Array.isArray( v ) ? v.join( ',' ) : k ] ) )
328
- };
329
-
330
- this.authorizer = requestContext?.authorizer;
331
- this.body = body ? this.#transformFn( parseJson( body ) ) : null;
332
- this.headers = unifiedHeaders ?? {};
333
- this.method = httpMethod;
334
- this.params = this.#transformFn( pathParameters ) ?? {};
335
- this.path = path;
336
- this.queryString = this.#transformFn( unifiedQueryString ) ?? {};
337
- this.route = resource;
338
- this.isBase64Encoded = isBase64Encoded ?? false;
339
- }
340
-
341
- parseFromAwsEventV2( awsEvent ) {
342
- const {
343
- body,
344
- routeKey,
345
- requestContext,
346
- pathParameters,
347
- headers,
348
- queryStringParameters,
349
- isBase64Encoded
350
- } = awsEvent;
351
-
352
- const { http: { method, path } } = requestContext;
353
-
354
- this.authorizer = requestContext?.authorizer;
355
- this.body = body ? this.#transformFn( parseJson( body ) ) : null;
356
- this.headers = headers ?? {};
357
- this.method = method;
358
- this.params = this.#transformFn( pathParameters ) ?? {};
359
- this.path = path;
360
- this.queryString = this.#transformFn( queryStringParameters ) ?? {};
361
- this.route = routeKey?.split( ' ' )[1].replace( /\/$/, '' );
362
- this.isBase64Encoded = isBase64Encoded ?? false;
363
- }
364
- };
365
-
366
-
367
- /***/ }),
368
-
369
- /***/ 345:
370
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
371
-
372
- const { GetObjectCommand } = __webpack_require__( 5725 );
373
-
374
- module.exports = async ( client, bucket, key, nativeArgs ) => {
375
- const response = await client.send( new GetObjectCommand( {
376
- ...nativeArgs,
377
- Bucket: bucket,
378
- Key: key
379
- } ) );
380
- const stream = response.Body;
381
- return Buffer.concat( await stream.toArray() ).toString( 'utf-8' );
382
- };
383
-
384
-
385
- /***/ }),
386
-
387
- /***/ 468:
388
- /***/ ((module) => {
389
-
390
- const parsePayload = payload => {
391
- try {
392
- return JSON.parse( Buffer.from( payload ).toString( 'utf-8' ) );
393
- } catch {
394
- return null;
395
- }
396
- };
397
-
398
- module.exports = class LambdaError extends Error {
399
- constructor( response ) {
400
- const { StatusCode: statusCode, Payload: rawPayload } = response;
401
- const payload = parsePayload( rawPayload );
402
- const lambdaErrorType = payload?.errorType ?? Error.name;
403
- const lambdaErrorMessage = payload?.errorMessage;
404
- if ( statusCode === 200 ) {
405
- super( `Invoked function threw "[${lambdaErrorType}]${lambdaErrorMessage ? ' ' + lambdaErrorMessage : ''}"` );
406
- } else {
407
- super( 'Error invoking the function' );
408
- }
409
- this.statusCode = statusCode;
410
- this.lambdaErrorType = lambdaErrorType;
411
- this.lambdaErrorMessage = lambdaErrorMessage;
412
- }
413
- };
414
-
415
-
416
- /***/ }),
417
-
418
- /***/ 536:
419
- /***/ ((module) => {
420
-
421
- module.exports = ( { key, items } ) => [
422
- ...items.filter( Array.isArray ).flat().reduce( ( map, v ) => {
423
- const k = key( v );
424
- if ( !map.has( k ) ) {
425
- map.set( k, v );
426
- }
427
- return map;
428
- }, new Map() ).values()
429
- ];
430
-
431
-
432
- /***/ }),
433
-
434
- /***/ 637:
435
- /***/ ((module) => {
436
-
437
- module.exports = ( n, d = 2 ) => {
438
- if ( !isFinite( n ) || typeof n !== 'number' ) { return NaN; }
439
-
440
- const m = Math.pow( 10, d );
441
- const num = +( n * m ).toFixed( 8 ); // Avoid rounding errors
442
- const i = Math.floor( num );
443
- const f = num - i;
444
- const e = 1e-8; // Allow for rounding errors in f
445
- const r = ( f > 0.5 - e && f < 0.5 + e ) ? // eslint-disable-line no-nested-ternary
446
- ( ( i % 2 === 0 ) ? i : i + 1 ) : Math.round( num );
447
- return r / m;
448
- };
449
-
450
-
451
- /***/ }),
452
-
453
- /***/ 645:
454
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
455
-
456
- const copy = __webpack_require__( 3936 );
457
- const download = __webpack_require__( 345 );
458
- const getSignedUrl = __webpack_require__( 3758 );
459
- const head = __webpack_require__( 279 );
460
- const upload = __webpack_require__( 9704 );
461
- const { S3Client } = __webpack_require__( 5725 );
462
- const clientProvider = __webpack_require__( 9039 );
463
- const createInstance = __webpack_require__( 5438 );
464
-
465
- const methods = {
466
- copy,
467
- download,
468
- getSignedUrl,
469
- head,
470
- upload
471
- };
472
-
473
- module.exports = createInstance( clientProvider.bind( null, S3Client ), methods );
474
-
475
-
476
- /***/ }),
477
-
478
- /***/ 739:
479
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
480
-
481
- const { GetQueryResultsCommand } = __webpack_require__( 7493 );
482
- const pollingDelay = __webpack_require__( 2549 );
483
- const sleep = t => new Promise( r => setTimeout( () => r(), t ) );
484
-
485
- const getResults = async ( { client, command } ) => {
486
- const { results, status } = await client.send( command );
487
-
488
- if ( [ 'Cancelled', 'Failed', 'Timeout', 'Unknown' ].includes( status ) ) {
489
- throw new Error( `Query status is "${status}"` );
490
- }
491
-
492
- if ( status === 'Complete' ) {
493
- return results;
494
- }
495
-
496
- // Running, Scheduled
497
- await sleep( pollingDelay );
498
- return getResults( { client, command } );
499
- };
500
-
501
- module.exports = async ( { client, queryId } ) => {
502
- const command = new GetQueryResultsCommand( { queryId } );
503
- return getResults( { client, command } );
504
- };
505
-
506
-
507
- /***/ }),
508
-
509
- /***/ 748:
510
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
511
-
512
- const select = __webpack_require__( 2157 );
513
-
514
- module.exports = async ( client, ...args ) => select( client, 'scan', ...args );
515
-
516
-
517
- /***/ }),
518
-
519
- /***/ 798:
520
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
521
-
522
- const validators = __webpack_require__( 8994 );
523
-
524
- module.exports = class Hook {
525
- #fn;
526
-
527
- constructor( { fn } ) {
528
- validators.function( fn );
529
- this.#fn = fn;
530
- }
531
-
532
- get fn() { return this.#fn; }
533
- };
534
-
535
-
536
- /***/ }),
537
-
538
- /***/ 809:
539
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
540
-
541
- const { DeleteSuppressedDestinationCommand } = __webpack_require__( 9556 );
542
-
543
- module.exports = ( client, address ) => client.send( new DeleteSuppressedDestinationCommand( { EmailAddress: address } ) );
544
-
545
-
546
- /***/ }),
547
-
548
- /***/ 834:
549
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
550
-
551
- const parseValue = __webpack_require__( 9129 );
552
-
553
- module.exports = resultSet => {
554
- const columns = resultSet.ResultSetMetadata.ColumnInfo
555
- .map( col => ( { name: col.Name, type: col.Type } ) );
556
-
557
- // first data row contains the table field names
558
- return resultSet.Rows.slice( 1 ).map( row => {
559
- const values = row.Data.map( d => d.VarCharValue );
560
- return columns.reduce( ( obj, p, i ) => Object.assign( obj, { [p.name]: parseValue( values[i], p.type ) } ), {} );
561
- } );
562
- };
563
-
564
-
565
- /***/ }),
566
-
567
- /***/ 943:
568
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
569
-
570
- const calcMean = __webpack_require__( 4124 );
571
- const calcMedian = __webpack_require__( 3187 );
572
- const calcMedianAbsDev = __webpack_require__( 4692 );
573
- const calcStdDevPopulation = __webpack_require__( 2736 );
574
- const calcStdDevSample = __webpack_require__( 6089 );
575
- const calcZScore = __webpack_require__( 4110 );
576
- const roundGaussian = __webpack_require__( 637 );
577
- const roundStandard = __webpack_require__( 115 );
578
-
579
- module.exports = {
580
- calcMean,
581
- calcMedian,
582
- calcMedianAbsDev,
583
- calcStdDevPopulation,
584
- calcStdDevSample,
585
- calcZScore,
586
- roundGaussian,
587
- roundStandard
588
- };
589
-
590
-
591
- /***/ }),
592
-
593
- /***/ 1417:
594
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
595
-
596
- const { GetCommand } = __webpack_require__( 3489 );
597
-
598
- const parseArgs = args => {
599
- // native args mode
600
- if ( args[0] instanceof Object ) {
601
- return args[0];
602
- }
603
- // sugar mode
604
- return {
605
- TableName: args[0],
606
- Key: args[1]
607
- };
608
- };
609
-
610
- module.exports = async ( client, ...args ) => {
611
- const response = await client.send( new GetCommand( parseArgs( args ) ) );
612
- return response.Item;
613
- };
614
-
615
-
616
- /***/ }),
617
-
618
- /***/ 1505:
619
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
620
-
621
- const documentClientProvider = __webpack_require__( 2966 );
622
- const get = __webpack_require__( 1417 );
623
- const put = __webpack_require__( 9628 );
624
- const putBatch = __webpack_require__( 5847 );
625
- const query = __webpack_require__( 5265 );
626
- const remove = __webpack_require__( 6777 );
627
- const removeBatch = __webpack_require__( 3862 );
628
- const scan = __webpack_require__( 748 );
629
- const smartUpdate = __webpack_require__( 2266 );
630
- const transactWrite = __webpack_require__( 1659 );
631
- const update = __webpack_require__( 4144 );
632
- const createInstance = __webpack_require__( 5438 );
633
-
634
- const methods = {
635
- get,
636
- put,
637
- putBatch,
638
- query,
639
- remove,
640
- removeBatch,
641
- scan,
642
- smartUpdate,
643
- transactWrite,
644
- update
325
+ // Finally makes the proxy which will allow each singleton method to use the client provider of the AWS service+
326
+ return new Proxy( factory, {
327
+ get( target, key ) {
328
+ const t = target[key];
329
+ return ( typeof t === 'function' ) ? t.bind( null, providerFn() ) : t;
330
+ }
331
+ } );
645
332
  };
646
333
 
647
- module.exports = createInstance( documentClientProvider, methods );
648
334
 
335
+ /***/ },
649
336
 
650
- /***/ }),
337
+ /***/ 5744
338
+ (module) {
651
339
 
652
- /***/ 1659:
653
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
340
+ module.exports = {
341
+ encode: k => {
342
+ if ( k === null || k === undefined ) { return k; }
654
343
 
655
- const { TransactWriteCommand } = __webpack_require__( 3489 );
344
+ return Buffer.from( JSON.stringify( k ) ).toString( 'base64' );
345
+ },
346
+ decode: k => {
347
+ if ( k === null || k === undefined ) { return k; }
656
348
 
657
- module.exports = async ( client, items ) => {
658
- const response = await client.send( new TransactWriteCommand( { TransactItems: items } ) );
659
- return response;
349
+ const result = Buffer.from( k, 'base64' ).toString( 'utf8' );
350
+ try {
351
+ return JSON.parse( result );
352
+ } catch {
353
+ return result;
354
+ }
355
+ }
660
356
  };
661
357
 
662
358
 
663
- /***/ }),
664
-
665
- /***/ 1671:
666
- /***/ ((module) => {
667
-
668
- "use strict";
669
- module.exports = require("@aws-sdk/client-timestream-query");
670
-
671
- /***/ }),
672
-
673
- /***/ 1783:
674
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
675
-
676
- const { SendEmailCommand } = __webpack_require__( 9556 );
677
-
678
- module.exports = ( client, { to = [], from, html, subject }, args ) =>
679
- client.send( new SendEmailCommand( {
680
- Destination: {
681
- ToAddresses: to
682
- },
683
- Content: {
684
- Simple: {
685
- Body: {
686
- Html: {
687
- Data: html,
688
- Charset: 'utf-8'
689
- }
690
- },
691
- Subject: {
692
- Data: subject
693
- }
694
- }
695
- },
696
- FromEmailAddress: from,
697
- ...args
698
- } ) );
699
-
700
-
701
- /***/ }),
702
-
703
- /***/ 1976:
704
- /***/ ((module) => {
705
-
706
- "use strict";
707
- module.exports = require("@aws-sdk/client-sqs");
708
-
709
- /***/ }),
710
-
711
- /***/ 2047:
712
- /***/ ((module) => {
713
-
714
- module.exports = o => Object.fromEntries( Object.entries( o ).filter( ( [ , v ] ) => !Array.isArray( v ) || v.length > 0 ) );
715
-
716
-
717
- /***/ }),
718
-
719
- /***/ 2157:
720
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
721
-
722
- const { encode, decode } = __webpack_require__( 5744 );
723
- const { ScanCommand, QueryCommand } = __webpack_require__( 3489 );
724
-
725
- const query = async ( { client, command, args, recursive, startKey, items = [], count = 0 } ) => {
726
- const response = await client.send( new command( {
727
- ...args,
728
- ...( startKey && { ExclusiveStartKey: startKey } )
729
- } ) );
730
-
731
- const isCount = args.Select === 'COUNT';
732
- const hasLimit = Number.isFinite( args.Limit );
733
-
734
- const result = {
735
- items: isCount ? null : items.concat( response.Items ),
736
- count: count + response.Count,
737
- startKey: response.LastEvaluatedKey
738
- };
739
-
740
- if ( !recursive ) {
741
- return { items: result.items, count: result.count, ...( result.startKey && { nextToken: encode( result.startKey ) } ) };
742
- }
743
-
744
- if ( result.startKey && ( isCount || ( hasLimit && result.items.length < args.Limit ) || ( !isCount && !hasLimit ) ) ) {
745
- return query( { client, command, args, recursive, ...result } );
746
- }
359
+ /***/ },
747
360
 
748
- if ( isCount ) {
749
- return { items: null, count: result.count };
750
- }
751
- const trimmedItems = result.items.slice( 0, args.Limit );
752
- return { items: trimmedItems, count: trimmedItems.length };
753
- };
361
+ /***/ 9039
362
+ (module, __unused_webpack_exports, __webpack_require__) {
754
363
 
755
- module.exports = async ( client, method, args, options = { recursive: false, paginationToken: null } ) => {
756
- const command = method === 'scan' ? ScanCommand : QueryCommand;
364
+ const cache = __webpack_require__( 4164 );
757
365
 
758
- return query( { client, command, args, recursive: options.recursive, startKey: decode( options.paginationToken ) } );
366
+ module.exports = ( constructor, args = [] ) => {
367
+ const cacheKey = `${constructor.name}(${args.map( arg => JSON.stringify( arg ) ).join( ',' )})`;
368
+ return cache.get( cacheKey ) ?? ( () => {
369
+ const client = Reflect.construct( constructor, args );
370
+ cache.set( cacheKey, client );
371
+ return client;
372
+ } )();
759
373
  };
760
374
 
761
375
 
762
- /***/ }),
376
+ /***/ },
763
377
 
764
- /***/ 2266:
765
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
378
+ /***/ 2710
379
+ (module, __unused_webpack_exports, __webpack_require__) {
766
380
 
767
- const { UpdateCommand } = __webpack_require__( 3489 );
381
+ const { CloudWatchLogsClient } = __webpack_require__( 7493 );
382
+ const clientProvider = __webpack_require__( 9039 );
383
+ const query = __webpack_require__( 4338 );
384
+ const createInstance = __webpack_require__( 5438 );
768
385
 
769
- module.exports = async ( client, tableName, key, keyValues ) => {
770
- const { updates, removals, names, values } = Object.entries( keyValues ).reduce( ( args, [ k, value ], index ) => {
771
- const isRemoval = value === undefined;
386
+ const methods = {
387
+ query
388
+ };
772
389
 
773
- const attrs = k.split( '.' ).map( ( attr, i ) => {
774
- const arrayPosition = attr.match( /\[(\d+)\]$/ )?.[1];
775
- return {
776
- key: `#${attr.replace( /\[\d+\]$|[^a-zA-Z0-9_]/g, '' )}${i}`,
777
- name: attr.replace( /\[\d+\]$/g, '' ),
778
- arrayPosition
779
- };
780
- } );
781
- const fullPath = attrs.map( attr => attr.key + ( attr.arrayPosition ? `[${attr.arrayPosition}]` : '' ) ).join( '.' );
782
- const valueId = `:v${index}`;
783
- const expAttrNames = attrs.reduce( ( obj, attr ) =>
784
- Object.assign( {}, obj, { [attr.key]: attr.name } )
785
- , {} );
390
+ module.exports = createInstance( clientProvider.bind( null, CloudWatchLogsClient ), methods );
786
391
 
787
- Object.assign( args.names, expAttrNames );
788
392
 
789
- if ( isRemoval ) {
790
- args.removals.push( fullPath );
791
- } else {
792
- args.updates.push( fullPath + ' = ' + valueId );
793
- Object.assign( args.values, { [valueId]: value } );
794
- }
393
+ /***/ },
795
394
 
796
- return args;
797
- }, { removals: [], updates: [], names: {}, values: {} } );
395
+ /***/ 739
396
+ (module, __unused_webpack_exports, __webpack_require__) {
798
397
 
799
- const conditionalExpressions = [];
800
- for ( const k of Object.keys( key ) ) {
801
- Object.assign( names, { [`#key_${k}`]: k } );
802
- conditionalExpressions.push( `attribute_exists(#key_${k})` );
803
- }
398
+ const { GetQueryResultsCommand } = __webpack_require__( 7493 );
399
+ const pollingDelay = __webpack_require__( 2549 );
400
+ const sleep = t => new Promise( r => setTimeout( () => r(), t ) );
804
401
 
805
- if ( updates.length + removals.length === 0 ) { return null; }
402
+ const getResults = async ( { client, command } ) => {
403
+ const { results, status } = await client.send( command );
806
404
 
807
- const expressions = [];
808
- if ( updates.length ) {
809
- expressions.push( 'SET ' + updates.join( ', ' ) );
810
- } if ( removals.length ) {
811
- expressions.push( 'REMOVE ' + removals.join( ', ' ) );
405
+ if ( [ 'Cancelled', 'Failed', 'Timeout', 'Unknown' ].includes( status ) ) {
406
+ throw new Error( `Query status is "${status}"` );
812
407
  }
813
408
 
814
- const statement = {
815
- TableName: tableName,
816
- ReturnValues: 'ALL_NEW',
817
- Key: key,
818
- ConditionExpression: conditionalExpressions.join( ' AND ' ),
819
- UpdateExpression: expressions.join( ' ' ),
820
- ExpressionAttributeNames: names
821
- };
822
- if ( Object.keys( values ).length > 0 ) {
823
- statement.ExpressionAttributeValues = values;
409
+ if ( status === 'Complete' ) {
410
+ return results;
824
411
  }
825
412
 
826
- try {
827
- const response = await client.send( new UpdateCommand( statement ) );
828
- return response.Attributes;
829
- } catch ( error ) {
830
- if ( error.constructor.name === 'ConditionalCheckFailedException' ) {
831
- console.info( 'Fail to update a record that was not found.' );
832
- return null;
833
- }
834
- throw error;
835
- }
413
+ // Running, Scheduled
414
+ await sleep( pollingDelay );
415
+ return getResults( { client, command } );
836
416
  };
837
417
 
838
-
839
- /***/ }),
840
-
841
- /***/ 2445:
842
- /***/ ((module) => {
843
-
844
- module.exports = t => new Promise( r => setTimeout( r, t ) );
845
-
846
-
847
- /***/ }),
848
-
849
- /***/ 2538:
850
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
851
-
852
- const writeRecords = __webpack_require__( 8936 );
853
- const { TimestreamWriteClient } = __webpack_require__( 8248 );
854
- const { Agent } = __webpack_require__( 5692 );
855
- const clientProvider = __webpack_require__( 9039 );
856
- const createInstance = __webpack_require__( 5438 );
857
-
858
- const methods = { writeRecords };
859
- const defaultArgs = {
860
- maxRetries: 10,
861
- httpOptions: { timeout: 60000, agent: new Agent( { maxSockets: 5000 } ) }
418
+ module.exports = async ( { client, queryId } ) => {
419
+ const command = new GetQueryResultsCommand( { queryId } );
420
+ return getResults( { client, command } );
862
421
  };
863
422
 
864
- module.exports = createInstance( args => clientProvider( TimestreamWriteClient, [ Object.assign( {}, defaultArgs, args ) ] ), methods );
865
-
866
-
867
- /***/ }),
868
-
869
- /***/ 2549:
870
- /***/ ((module) => {
871
-
872
- module.exports = 500;
873
-
874
-
875
- /***/ }),
876
-
877
- /***/ 2705:
878
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
879
-
880
- const LambdaApi = __webpack_require__( 321 );
881
-
882
- module.exports = { LambdaApi };
883
423
 
424
+ /***/ },
884
425
 
885
- /***/ }),
426
+ /***/ 4338
427
+ (module, __unused_webpack_exports, __webpack_require__) {
886
428
 
887
- /***/ 2710:
888
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
429
+ const startQuery = __webpack_require__( 3649 );
430
+ const getResults = __webpack_require__( 739 );
431
+ const parseResults = __webpack_require__( 9552 );
889
432
 
890
- const { CloudWatchLogsClient } = __webpack_require__( 7493 );
891
- const clientProvider = __webpack_require__( 9039 );
892
- const query = __webpack_require__( 4338 );
893
- const createInstance = __webpack_require__( 5438 );
433
+ /**
434
+ * @class Result
435
+ * @type {Object}
436
+ * @property {Object[]} items Each query result row, parsed to a camelized js object
437
+ * @property {Number} count Total number of results
438
+ */
894
439
 
895
- const methods = {
896
- query
440
+ /**
441
+ * Executes an Athena Query
442
+ * @param {*} client The native client
443
+ * @param {Object} nativeArgs The native args to start the Cloudwatch Query
444
+ * @param {Object=} options Extra options for this command
445
+ * @param {Object=} options.range Since the nativeArgs "startTime" and "endTime" are second based epochs, the "range" argument accepts milliseconds based epochs for convenience, thus overwriting the "nativeArgs"
446
+ * @param {Number} options.range.from The beginning of the time range to query, overwrites "startTime"
447
+ * @param {Number} options.range.to The end of the time range to query, overwrites "endTime"
448
+ * @returns {Result} The query result
449
+ */
450
+ module.exports = async ( client, nativeArgs, { range = {} } = {} ) => {
451
+ const queryId = await startQuery( { client, nativeArgs, range } );
452
+ const results = await getResults( { client, queryId } );
453
+ const items = parseResults( results );
454
+ return { items, count: items.length };
897
455
  };
898
456
 
899
- module.exports = createInstance( clientProvider.bind( null, CloudWatchLogsClient ), methods );
900
457
 
458
+ /***/ },
901
459
 
902
- /***/ }),
460
+ /***/ 9179
461
+ (module, __unused_webpack_exports, __webpack_require__) {
903
462
 
904
- /***/ 2736:
905
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
463
+ const parseValue = __webpack_require__( 2847 );
906
464
 
907
- const calcMean = __webpack_require__( 4124 );
465
+ module.exports = item =>
466
+ item.reduce( ( row, { field, value } ) =>
467
+ Object.assign( row, {
468
+ [field]: parseValue( value )
469
+ } ), {} );
908
470
 
909
- module.exports = values => {
910
- const mean = calcMean( values );
911
- const squareDiffs = values.map( value => Math.pow( value - mean, 2 ) );
912
- const avgSquareDiff = calcMean( squareDiffs );
913
- return Math.sqrt( avgSquareDiff );
914
- };
915
471
 
472
+ /***/ },
916
473
 
917
- /***/ }),
474
+ /***/ 9552
475
+ (module, __unused_webpack_exports, __webpack_require__) {
918
476
 
919
- /***/ 2836:
920
- /***/ ((module) => {
477
+ const parseItem = __webpack_require__( 9179 );
921
478
 
922
- module.exports = ( ...args ) => [ ...new Set( args.filter( Array.isArray ).flat() ) ];
479
+ module.exports = results => results.map( item => parseItem( item ) );
923
480
 
924
481
 
925
- /***/ }),
482
+ /***/ },
926
483
 
927
- /***/ 2847:
928
- /***/ ((module) => {
484
+ /***/ 2847
485
+ (module) {
929
486
 
930
487
  const parseInteger = value => {
931
488
  const number = parseInt( value, 10 );
@@ -973,10 +530,62 @@ module.exports = value => {
973
530
  };
974
531
 
975
532
 
976
- /***/ }),
533
+ /***/ },
534
+
535
+ /***/ 2549
536
+ (module) {
537
+
538
+ module.exports = 500;
539
+
540
+
541
+ /***/ },
542
+
543
+ /***/ 3649
544
+ (module, __unused_webpack_exports, __webpack_require__) {
545
+
546
+ const { StartQueryCommand } = __webpack_require__( 7493 );
547
+
548
+ module.exports = async ( { client, nativeArgs, range } ) => {
549
+ const startTime = range?.from ? Math.trunc( range.from / 1000 ) : nativeArgs.startTime;
550
+ const endTime = range?.to ? Math.trunc( range.to / 1000 ) : nativeArgs.endTime;
551
+
552
+ const { queryId } = await client.send( new StartQueryCommand( { ...nativeArgs, startTime, endTime } ) );
553
+ return queryId;
554
+ };
555
+
556
+
557
+ /***/ },
558
+
559
+ /***/ 8593
560
+ (module, __unused_webpack_exports, __webpack_require__) {
561
+
562
+ const { BatchWriteCommand } = __webpack_require__( 3489 );
563
+ const splitBatches = __webpack_require__( 4821 );
564
+
565
+ const batchSize = 25;
566
+
567
+ const getMapper = method => method === 'put' ? v => ( { PutRequest: { Item: v } } ) : v => ( { DeleteRequest: { Key: v } } );
568
+
569
+ const process = async ( { client, method, table, batches } ) => {
570
+ if ( batches.length === 0 ) { return true; }
571
+
572
+ const response = await client.send( new BatchWriteCommand( { RequestItems: { [table]: batches[0] } } ) );
573
+
574
+ const unprocessed = response.UnprocessedItems?.[table];
575
+ return process( {
576
+ client, method, table,
577
+ batches: unprocessed ? splitBatches( batches.slice( 1 ).flat().concat( unprocessed ), batchSize ) : batches.slice( 1 )
578
+ } );
579
+ };
580
+
581
+ module.exports = async ( client, method, table, items ) =>
582
+ process( { client, method, table, batches: splitBatches( items.map( getMapper( method ) ), batchSize ) } );
583
+
977
584
 
978
- /***/ 2966:
979
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
585
+ /***/ },
586
+
587
+ /***/ 2966
588
+ (module, __unused_webpack_exports, __webpack_require__) {
980
589
 
981
590
  const { DynamoDBClient } = __webpack_require__( 4671 );
982
591
  const { DynamoDBDocumentClient } = __webpack_require__( 3489 );
@@ -1011,395 +620,418 @@ module.exports = nativeArgs => {
1011
620
  };
1012
621
 
1013
622
 
1014
- /***/ }),
623
+ /***/ },
1015
624
 
1016
- /***/ 3099:
1017
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
625
+ /***/ 1417
626
+ (module, __unused_webpack_exports, __webpack_require__) {
1018
627
 
1019
- const publish = __webpack_require__( 8080 );
1020
- const { SNSClient } = __webpack_require__( 7651 );
1021
- const clientProvider = __webpack_require__( 9039 );
1022
- const createInstance = __webpack_require__( 5438 );
628
+ const { GetCommand } = __webpack_require__( 3489 );
1023
629
 
1024
- const methods = {
1025
- publish
630
+ const parseArgs = args => {
631
+ // native args mode
632
+ if ( args[0] instanceof Object ) {
633
+ return args[0];
634
+ }
635
+ // sugar mode
636
+ return {
637
+ TableName: args[0],
638
+ Key: args[1]
639
+ };
1026
640
  };
1027
641
 
1028
- module.exports = createInstance( clientProvider.bind( null, SNSClient ), methods );
642
+ module.exports = async ( client, ...args ) => {
643
+ const response = await client.send( new GetCommand( parseArgs( args ) ) );
644
+ return response.Item;
645
+ };
1029
646
 
1030
647
 
1031
- /***/ }),
648
+ /***/ },
1032
649
 
1033
- /***/ 3106:
1034
- /***/ ((module) => {
650
+ /***/ 1505
651
+ (module, __unused_webpack_exports, __webpack_require__) {
1035
652
 
1036
- "use strict";
1037
- module.exports = require("zlib");
653
+ const documentClientProvider = __webpack_require__( 2966 );
654
+ const get = __webpack_require__( 1417 );
655
+ const put = __webpack_require__( 9628 );
656
+ const putBatch = __webpack_require__( 5847 );
657
+ const query = __webpack_require__( 5265 );
658
+ const remove = __webpack_require__( 6777 );
659
+ const removeBatch = __webpack_require__( 3862 );
660
+ const scan = __webpack_require__( 748 );
661
+ const smartUpdate = __webpack_require__( 2266 );
662
+ const transactWrite = __webpack_require__( 1659 );
663
+ const update = __webpack_require__( 4144 );
664
+ const createInstance = __webpack_require__( 5438 );
1038
665
 
1039
- /***/ }),
666
+ const methods = {
667
+ get,
668
+ put,
669
+ putBatch,
670
+ query,
671
+ remove,
672
+ removeBatch,
673
+ scan,
674
+ smartUpdate,
675
+ transactWrite,
676
+ update
677
+ };
1040
678
 
1041
- /***/ 3109:
1042
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
679
+ module.exports = createInstance( documentClientProvider, methods );
1043
680
 
1044
- const validators = __webpack_require__( 8994 );
1045
681
 
1046
- module.exports = class Handler {
1047
- #method;
1048
- #fn;
1049
- #route;
1050
- #routeIncludes;
1051
- #routeNotIncludes;
1052
- #routeMatches;
1053
- #path;
1054
- #pathIncludes;
1055
- #pathNotIncludes;
1056
- #pathMatches;
682
+ /***/ },
1057
683
 
1058
- constructor( { method, fn, ...matchers } ) {
1059
- validators.httpMethod( method );
1060
- validators.function( fn );
1061
- validators.matcherRoute( matchers.route );
1062
- validators.matcherRouteIncludes( matchers.routeIncludes );
1063
- validators.matcherRouteNotIncludes( matchers.routeNotIncludes );
1064
- validators.matcherRouteMatch( matchers.routeMatch );
1065
- validators.matcherPath( matchers.path );
1066
- validators.matcherPathIncludes( matchers.pathIncludes );
1067
- validators.matcherPathNotIncludes( matchers.pathNotIncludes );
1068
- validators.matcherPathMatch( matchers.pathMatch );
684
+ /***/ 9628
685
+ (module, __unused_webpack_exports, __webpack_require__) {
1069
686
 
1070
- this.#method = method;
1071
- this.#fn = fn;
1072
- this.#route = matchers.route;
1073
- this.#routeIncludes = matchers.routeIncludes;
1074
- this.#routeNotIncludes = matchers.routeNotIncludes;
1075
- this.#routeMatches = matchers.routeMatches;
1076
- this.#path = matchers.path;
1077
- this.#pathIncludes = matchers.pathIncludes;
1078
- this.#pathNotIncludes = matchers.pathNotIncludes;
1079
- this.#pathMatches = matchers.pathMatches;
1080
- }
687
+ const { PutCommand } = __webpack_require__( 3489 );
1081
688
 
1082
- match( event ) {
1083
- if ( this.#method !== event.method ) {
1084
- return false;
1085
- }
1086
- if ( this.#route ) {
1087
- return this.#route === event.route;
1088
- }
1089
- if ( this.#path ) {
1090
- return this.#path === event.path;
1091
- }
1092
- if ( this.#routeIncludes && !event.route.includes( this.#routeIncludes ) ) {
1093
- return false;
1094
- }
1095
- if ( this.#routeNotIncludes && event.route.includes( this.#routeNotIncludes ) ) {
1096
- return false;
1097
- }
1098
- if ( this.#routeMatches && !this.#routeMatches.test( event.route ) ) {
1099
- return false;
1100
- }
1101
- if ( this.#pathIncludes && !event.path.includes( this.#pathIncludes ) ) {
1102
- return false;
1103
- }
1104
- if ( this.#pathNotIncludes && event.path.includes( this.#pathNotIncludes ) ) {
1105
- return false;
1106
- }
1107
- if ( this.#pathMatches && !this.#pathMatches.test( event.path ) ) {
1108
- return false;
1109
- }
1110
- return true;
689
+ const parseArgs = args => {
690
+ // native args mode
691
+ if ( args[0] instanceof Object ) {
692
+ return args[0];
1111
693
  }
694
+ // sugar mode
695
+ return {
696
+ TableName: args[0],
697
+ Item: args[1],
698
+ ReturnValues: 'NONE',
699
+ ReturnConsumedCapacity: 'NONE'
700
+ };
701
+ };
1112
702
 
1113
- get fn() { return this.#fn; }
703
+ /**
704
+ *
705
+ * @param {*} client
706
+ * @param {...any} args The args. either one object with the native args or two string args, tableName and item.
707
+ * @returns
708
+ */
709
+ module.exports = async ( client, ...args ) => {
710
+ const nativeArgs = parseArgs( args );
711
+ const response = await client.send( new PutCommand( nativeArgs ) );
712
+ return response.Attributes ?? nativeArgs.Item;
1114
713
  };
1115
714
 
1116
715
 
1117
- /***/ }),
716
+ /***/ },
1118
717
 
1119
- /***/ 3119:
1120
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
718
+ /***/ 5847
719
+ (module, __unused_webpack_exports, __webpack_require__) {
1121
720
 
1122
- const { snakelize, camelize } = __webpack_require__( 5762 );
1123
- const charset = 'utf-8';
721
+ const batchWrite = __webpack_require__( 8593 );
1124
722
 
1125
- const transformFns = {
1126
- camelcase: camelize,
1127
- snakecase: snakelize
1128
- };
723
+ module.exports = async ( client, ...args ) => batchWrite( client, 'put', ...args );
1129
724
 
1130
- module.exports = class ApiResponse {
1131
- #headers = null;
1132
- #statusCode = null;
1133
- #transformFn = false;
1134
- #isBase64Encoded = false;
1135
- #body = '';
1136
725
 
1137
- constructor( { headers = {}, transform } = {} ) {
1138
- this.#transformFn = transformFns[transform] ?? ( v => v );
1139
- this.#headers = Object.assign( {
1140
- 'Cache-Control': 'no-store',
1141
- 'Access-Control-Allow-Origin': '*'
1142
- }, headers );
1143
- }
726
+ /***/ },
1144
727
 
1145
- setContent( statusCode, body, headers = {}, isBase64Encoded = false ) {
1146
- this.#statusCode = statusCode;
1147
- this.#isBase64Encoded = isBase64Encoded;
1148
- if ( body?.length === 0 || [ null, undefined ].includes( body ) ) {
1149
- this.#body = '';
1150
- } else if ( typeof body === 'object' ) {
1151
- this.#body = JSON.stringify( this.#transformFn( body ) );
1152
- this.#headers['Content-Type'] = `application/json; charset=${charset}`;
1153
- } else {
1154
- this.#body = String( body );
1155
- this.#headers['Content-Type'] = `text/plain; charset=${charset}`;
1156
- }
1157
- this.#headers['Content-Length'] = this.#body.length;
1158
- Object.assign( this.#headers, headers ?? {} );
1159
- return this;
1160
- }
728
+ /***/ 5265
729
+ (module, __unused_webpack_exports, __webpack_require__) {
730
+
731
+ const select = __webpack_require__( 2157 );
732
+
733
+ module.exports = async ( client, ...args ) => select( client, 'query', ...args );
734
+
735
+
736
+ /***/ },
737
+
738
+ /***/ 6777
739
+ (module, __unused_webpack_exports, __webpack_require__) {
740
+
741
+ const { DeleteCommand } = __webpack_require__( 3489 );
1161
742
 
1162
- toJSON() {
1163
- return {
1164
- isBase64Encoded: this.#isBase64Encoded,
1165
- statusCode: this.#statusCode,
1166
- body: this.#body,
1167
- headers: this.#headers
1168
- };
1169
- }
743
+ module.exports = async ( client, tableName, key ) => {
744
+ const { Attributes: item } = await client.send( new DeleteCommand( {
745
+ ReturnValues: 'ALL_OLD',
746
+ TableName: tableName,
747
+ Key: key
748
+ } ) );
749
+ return item;
1170
750
  };
1171
751
 
1172
752
 
1173
- /***/ }),
753
+ /***/ },
1174
754
 
1175
- /***/ 3131:
1176
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
755
+ /***/ 3862
756
+ (module, __unused_webpack_exports, __webpack_require__) {
1177
757
 
1178
- const { SendMessageBatchCommand } = __webpack_require__( 1976 );
1179
- const sanitizeSqs = __webpack_require__( 8175 );
758
+ const batchWrite = __webpack_require__( 8593 );
1180
759
 
1181
- module.exports = async ( client, queue, messages ) => {
1182
- if ( messages.length > 10 ) {
1183
- throw new Error( 'SQS.sendMessageBatch only accepts up to then messages.' );
1184
- }
1185
- const response = await client.send( new SendMessageBatchCommand( {
1186
- QueueUrl: queue,
1187
- Entries: messages.map( ( { body, id = null, nativeArgs }, index ) => ( {
1188
- Id: id ?? `message_${index}`,
1189
- MessageBody: sanitizeSqs( typeof body === 'string' ? body : JSON.stringify( body ) ),
1190
- ...nativeArgs
1191
- } ) )
1192
- } ) );
760
+ module.exports = async ( client, ...args ) => batchWrite( client, 'remove', ...args );
1193
761
 
1194
- if ( response.Failed?.length > 0 ) {
1195
- const error = new Error( 'SQS.sendMessageBatch Failed. See error details' );
1196
- error.details = response.Failed;
1197
- throw error;
1198
- }
1199
- return response;
1200
- };
1201
762
 
763
+ /***/ },
1202
764
 
1203
- /***/ }),
765
+ /***/ 748
766
+ (module, __unused_webpack_exports, __webpack_require__) {
1204
767
 
1205
- /***/ 3187:
1206
- /***/ ((module) => {
768
+ const select = __webpack_require__( 2157 );
1207
769
 
1208
- module.exports = values => {
1209
- //Sort bug: https://www.tutorialrepublic.com/faq/how-to-sort-an-array-of-integers-correctly-in-javascript.php
1210
- const sorted = values.slice().sort( ( a, b ) => a - b );
1211
- const evenArray = values.length % 2 === 0;
1212
- const midIndex = Math.floor( values.length / 2 );
1213
- return evenArray ? ( sorted[midIndex - 1] + sorted[midIndex] ) / 2 : sorted[midIndex];
1214
- };
770
+ module.exports = async ( client, ...args ) => select( client, 'scan', ...args );
1215
771
 
1216
772
 
1217
- /***/ }),
773
+ /***/ },
1218
774
 
1219
- /***/ 3258:
1220
- /***/ ((module) => {
775
+ /***/ 2157
776
+ (module, __unused_webpack_exports, __webpack_require__) {
1221
777
 
1222
- module.exports = input =>
1223
- // Break the string into sequences to rebuild later
1224
- !input ? input : input.split( /\s/ )
1225
- // ALL_CAPS terms are ignored
1226
- .map( term => [ term, term.charAt( 0 ).toUpperCase() + term.slice( 1 ).toLowerCase() ] )
1227
- // Rebuild the string replacing the converter terms keeping the original delimiters
1228
- .reduce( ( result, [ term, repl ] ) => result.replace( term, repl ), input );
778
+ const { encode, decode } = __webpack_require__( 5744 );
779
+ const { ScanCommand, QueryCommand } = __webpack_require__( 3489 );
780
+
781
+ const query = async ( { client, command, args, recursive, startKey, items = [], count = 0 } ) => {
782
+ const response = await client.send( new command( {
783
+ ...args,
784
+ ...( startKey && { ExclusiveStartKey: startKey } )
785
+ } ) );
1229
786
 
787
+ const isCount = args.Select === 'COUNT';
788
+ const hasLimit = Number.isFinite( args.Limit );
1230
789
 
1231
- /***/ }),
790
+ const result = {
791
+ items: isCount ? null : items.concat( response.Items ),
792
+ count: count + response.Count,
793
+ startKey: response.LastEvaluatedKey
794
+ };
1232
795
 
1233
- /***/ 3340:
1234
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
796
+ if ( !recursive ) {
797
+ return { items: result.items, count: result.count, ...( result.startKey && { nextToken: encode( result.startKey ) } ) };
798
+ }
1235
799
 
1236
- const deleteMessage = __webpack_require__( 5637 );
1237
- const sendMessage = __webpack_require__( 6720 );
1238
- const sendMessageBatch = __webpack_require__( 3131 );
1239
- const { SQSClient } = __webpack_require__( 1976 );
1240
- const clientProvider = __webpack_require__( 9039 );
1241
- const createInstance = __webpack_require__( 5438 );
800
+ if ( result.startKey && ( isCount || ( hasLimit && result.items.length < args.Limit ) || ( !isCount && !hasLimit ) ) ) {
801
+ return query( { client, command, args, recursive, ...result } );
802
+ }
1242
803
 
1243
- const methods = {
1244
- deleteMessage,
1245
- sendMessage,
1246
- sendMessageBatch
804
+ if ( isCount ) {
805
+ return { items: null, count: result.count };
806
+ }
807
+ const trimmedItems = result.items.slice( 0, args.Limit );
808
+ return { items: trimmedItems, count: trimmedItems.length };
1247
809
  };
1248
810
 
1249
- module.exports = createInstance( clientProvider.bind( null, SQSClient ), methods );
1250
-
811
+ module.exports = async ( client, method, args, options = { recursive: false, paginationToken: null } ) => {
812
+ const command = method === 'scan' ? ScanCommand : QueryCommand;
1251
813
 
1252
- /***/ }),
814
+ return query( { client, command, args, recursive: options.recursive, startKey: decode( options.paginationToken ) } );
815
+ };
1253
816
 
1254
- /***/ 3402:
1255
- /***/ ((module) => {
1256
817
 
1257
- // convert a string to snake_case
1258
- module.exports = ( input, { keepAllCaps = false } = {} ) =>
1259
- // Break the string into sequences to rebuild later
1260
- !input ? input : input.split( /\s/ )
1261
- // ALL_CAPS terms are ignored
1262
- .map( term => [ term, keepAllCaps && /^[A-Z_]+$/g.test( term ) ? term : term
1263
- .replace( /-/g, '_' ) // replaces hyphen
1264
- .replace( /([a-z\d])([A-Z])/g, '$1_$2' ) // add _ between lower and upper case letters
1265
- .replace( /([A-Z])([A-Z])(?=[a-z\d])/g, '$1_$2' ).toLowerCase() // add _ between uppercase char and next uppercase char follow by lowercase
1266
- ] )
1267
- // Rebuild the string replacing the converter terms keeping the original delimiters
1268
- .reduce( ( result, [ term, repl ] ) => result.replace( term, repl ), input );
818
+ /***/ },
1269
819
 
820
+ /***/ 2266
821
+ (module, __unused_webpack_exports, __webpack_require__) {
1270
822
 
1271
- /***/ }),
823
+ const { UpdateCommand } = __webpack_require__( 3489 );
1272
824
 
1273
- /***/ 3446:
1274
- /***/ ((module) => {
825
+ module.exports = async ( client, tableName, key, keyValues ) => {
826
+ const { updates, removals, names, values } = Object.entries( keyValues ).reduce( ( args, [ k, value ], index ) => {
827
+ const isRemoval = value === undefined;
1275
828
 
1276
- module.exports = class LambdaApiValidationError extends Error {};
829
+ const attrs = k.split( '.' ).map( ( attr, i ) => {
830
+ const arrayPosition = attr.match( /\[(\d+)\]$/ )?.[1];
831
+ return {
832
+ key: `#${attr.replace( /\[\d+\]$|[^a-zA-Z0-9_]/g, '' )}${i}`,
833
+ name: attr.replace( /\[\d+\]$/g, '' ),
834
+ arrayPosition
835
+ };
836
+ } );
837
+ const fullPath = attrs.map( attr => attr.key + ( attr.arrayPosition ? `[${attr.arrayPosition}]` : '' ) ).join( '.' );
838
+ const valueId = `:v${index}`;
839
+ const expAttrNames = attrs.reduce( ( obj, attr ) =>
840
+ Object.assign( {}, obj, { [attr.key]: attr.name } )
841
+ , {} );
1277
842
 
843
+ Object.assign( args.names, expAttrNames );
1278
844
 
1279
- /***/ }),
845
+ if ( isRemoval ) {
846
+ args.removals.push( fullPath );
847
+ } else {
848
+ args.updates.push( fullPath + ' = ' + valueId );
849
+ Object.assign( args.values, { [valueId]: value } );
850
+ }
1280
851
 
1281
- /***/ 3489:
1282
- /***/ ((module) => {
852
+ return args;
853
+ }, { removals: [], updates: [], names: {}, values: {} } );
1283
854
 
1284
- "use strict";
1285
- module.exports = require("@aws-sdk/lib-dynamodb");
855
+ const conditionalExpressions = [];
856
+ for ( const k of Object.keys( key ) ) {
857
+ Object.assign( names, { [`#key_${k}`]: k } );
858
+ conditionalExpressions.push( `attribute_exists(#key_${k})` );
859
+ }
1286
860
 
1287
- /***/ }),
861
+ if ( updates.length + removals.length === 0 ) { return null; }
1288
862
 
1289
- /***/ 3544:
1290
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
863
+ const expressions = [];
864
+ if ( updates.length ) {
865
+ expressions.push( 'SET ' + updates.join( ', ' ) );
866
+ } if ( removals.length ) {
867
+ expressions.push( 'REMOVE ' + removals.join( ', ' ) );
868
+ }
1291
869
 
1292
- const invoke = __webpack_require__( 5894 );
1293
- const { LambdaClient } = __webpack_require__( 5892 );
1294
- const clientProvider = __webpack_require__( 9039 );
1295
- const createInstance = __webpack_require__( 5438 );
870
+ const statement = {
871
+ TableName: tableName,
872
+ ReturnValues: 'ALL_NEW',
873
+ Key: key,
874
+ ConditionExpression: conditionalExpressions.join( ' AND ' ),
875
+ UpdateExpression: expressions.join( ' ' ),
876
+ ExpressionAttributeNames: names
877
+ };
878
+ if ( Object.keys( values ).length > 0 ) {
879
+ statement.ExpressionAttributeValues = values;
880
+ }
1296
881
 
1297
- const methods = {
1298
- invoke
882
+ try {
883
+ const response = await client.send( new UpdateCommand( statement ) );
884
+ return response.Attributes;
885
+ } catch ( error ) {
886
+ if ( error.constructor.name === 'ConditionalCheckFailedException' ) {
887
+ console.info( 'Fail to update a record that was not found.' );
888
+ return null;
889
+ }
890
+ throw error;
891
+ }
1299
892
  };
1300
893
 
1301
- module.exports = createInstance( clientProvider.bind( null, LambdaClient ), methods );
1302
894
 
895
+ /***/ },
1303
896
 
1304
- /***/ }),
897
+ /***/ 1659
898
+ (module, __unused_webpack_exports, __webpack_require__) {
1305
899
 
1306
- /***/ 3649:
1307
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
900
+ const { TransactWriteCommand } = __webpack_require__( 3489 );
1308
901
 
1309
- const { StartQueryCommand } = __webpack_require__( 7493 );
902
+ module.exports = async ( client, items ) => {
903
+ const response = await client.send( new TransactWriteCommand( { TransactItems: items } ) );
904
+ return response;
905
+ };
1310
906
 
1311
- module.exports = async ( { client, nativeArgs, range } ) => {
1312
- const startTime = range?.from ? Math.trunc( range.from / 1000 ) : nativeArgs.startTime;
1313
- const endTime = range?.to ? Math.trunc( range.to / 1000 ) : nativeArgs.endTime;
1314
907
 
1315
- const { queryId } = await client.send( new StartQueryCommand( { ...nativeArgs, startTime, endTime } ) );
1316
- return queryId;
1317
- };
908
+ /***/ },
1318
909
 
910
+ /***/ 4144
911
+ (module, __unused_webpack_exports, __webpack_require__) {
1319
912
 
1320
- /***/ }),
913
+ const { UpdateCommand } = __webpack_require__( 3489 );
1321
914
 
1322
- /***/ 3744:
1323
- /***/ ((module) => {
915
+ module.exports = async ( client, nativeArgs ) => {
916
+ const args = Object.assign( { ReturnValues: 'ALL_NEW' }, nativeArgs );
917
+ const response = await client.send( new UpdateCommand( args ) );
918
+ return response.Attributes;
919
+ };
1324
920
 
1325
- "use strict";
1326
- module.exports = require("@aws-sdk/client-athena");
1327
921
 
1328
- /***/ }),
922
+ /***/ },
1329
923
 
1330
- /***/ 3758:
1331
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
924
+ /***/ 4870
925
+ (module, __unused_webpack_exports, __webpack_require__) {
1332
926
 
1333
- const { getSignedUrl } = __webpack_require__( 4991 );
1334
- const { GetObjectCommand } = __webpack_require__( 5725 );
927
+ const athena = __webpack_require__( 228 );
928
+ const cwLogs = __webpack_require__( 2710 );
929
+ const dynamo = __webpack_require__( 1505 );
930
+ const lambda = __webpack_require__( 3544 );
931
+ const s3 = __webpack_require__( 645 );
932
+ const ses = __webpack_require__( 5624 );
933
+ const sns = __webpack_require__( 3099 );
934
+ const sqs = __webpack_require__( 3340 );
935
+ const ssm = __webpack_require__( 5888 );
936
+ const timestreamQuery = __webpack_require__( 4225 );
937
+ const timestreamWrite = __webpack_require__( 2538 );
1335
938
 
1336
- module.exports = async ( client, bucket, key, expiration ) => {
1337
- const getObjectCmd = new GetObjectCommand( { Bucket: bucket, Key: key } );
1338
- const url = await getSignedUrl( client, getObjectCmd, { expiresIn: expiration } );
1339
- return url;
939
+ module.exports = {
940
+ athena,
941
+ cwLogs,
942
+ dynamo,
943
+ lambda,
944
+ s3,
945
+ ses,
946
+ sns,
947
+ sqs,
948
+ ssm,
949
+ timestreamQuery,
950
+ timestreamWrite
1340
951
  };
1341
952
 
1342
953
 
1343
- /***/ }),
954
+ /***/ },
1344
955
 
1345
- /***/ 3830:
1346
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
956
+ /***/ 3544
957
+ (module, __unused_webpack_exports, __webpack_require__) {
1347
958
 
1348
- const days = __webpack_require__( 5263 );
1349
- const hours = __webpack_require__( 6961 );
1350
- const minutes = __webpack_require__( 6635 );
1351
- const months = __webpack_require__( 8119 );
1352
- const msToS = __webpack_require__( 7416 );
1353
- const round = __webpack_require__( 3990 );
1354
- const seconds = __webpack_require__( 7051 );
959
+ const invoke = __webpack_require__( 5894 );
960
+ const { LambdaClient } = __webpack_require__( 5892 );
961
+ const clientProvider = __webpack_require__( 9039 );
962
+ const createInstance = __webpack_require__( 5438 );
1355
963
 
1356
- module.exports = {
1357
- days,
1358
- hours,
1359
- minutes,
1360
- months,
1361
- msToS,
1362
- round,
1363
- seconds
964
+ const methods = {
965
+ invoke
1364
966
  };
1365
967
 
968
+ module.exports = createInstance( clientProvider.bind( null, LambdaClient ), methods );
969
+
970
+
971
+ /***/ },
972
+
973
+ /***/ 5894
974
+ (module, __unused_webpack_exports, __webpack_require__) {
975
+
976
+ const { InvokeCommand } = __webpack_require__( 5892 );
977
+ const AWSLambdaError = __webpack_require__( 468 );
978
+
979
+ module.exports = async ( client, name, payload = {}, type = 'RequestResponse' ) => {
980
+ const response = await client.send( new InvokeCommand( {
981
+ FunctionName: name,
982
+ InvocationType: type,
983
+ Payload: Buffer.from( JSON.stringify( payload ) )
984
+ } ) );
1366
985
 
1367
- /***/ }),
986
+ if ( response.FunctionError ) {
987
+ throw new AWSLambdaError( response );
988
+ }
1368
989
 
1369
- /***/ 3862:
1370
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
990
+ if ( type !== 'RequestResponse' ) { return true; }
1371
991
 
1372
- const batchWrite = __webpack_require__( 8593 );
992
+ try {
993
+ return JSON.parse( Buffer.from( response.Payload ).toString() );
994
+ } catch {
995
+ return response.Payload;
996
+ }
997
+ };
1373
998
 
1374
- module.exports = async ( client, ...args ) => batchWrite( client, 'remove', ...args );
1375
999
 
1000
+ /***/ },
1376
1001
 
1377
- /***/ }),
1002
+ /***/ 468
1003
+ (module) {
1378
1004
 
1379
- /***/ 3914:
1380
- /***/ ((module) => {
1005
+ const parsePayload = payload => {
1006
+ try {
1007
+ return JSON.parse( Buffer.from( payload ).toString( 'utf-8' ) );
1008
+ } catch {
1009
+ return null;
1010
+ }
1011
+ };
1381
1012
 
1382
- // Convert a string to camelCase
1383
- module.exports = ( input, { keepAllCaps = false } = {} ) =>
1384
- // Break the string into sequences to rebuild later
1385
- !input ? input : input.split( /\s/ )
1386
- // ALL_CAPS terms are ignored
1387
- .map( term => [ term, keepAllCaps && /^[A-Z_]+$/g.test( term ) ? term : term
1388
- // Matches the penultimate letter in a sequence of upper case followed by lower case and convert it to lower case
1389
- // Effectively creating a word break eg: BDay => bDay
1390
- .replace( /[A-Z](?=[A-Z][a-z])/g, c => `${c[0].toLowerCase()}` )
1391
- .replace( /([A-Z])([A-Z]+)/g, c => `${c[0]}${c.slice( 1 ).toLowerCase()}` ) // Sequences of upper case
1392
- .replace( /([-_]\w)/g, c => c[1].toUpperCase() ) // first letter after hyphen and underline
1393
- .replace( /^([A-Z])/g, c => c[0].toLowerCase() ) // first letter
1394
- ] )
1395
- // Rebuild the string replacing the converter terms keeping the original delimiters
1396
- .reduce( ( result, [ term, repl ] ) => result.replace( term, repl ), input );
1013
+ module.exports = class LambdaError extends Error {
1014
+ constructor( response ) {
1015
+ const { StatusCode: statusCode, Payload: rawPayload } = response;
1016
+ const payload = parsePayload( rawPayload );
1017
+ const lambdaErrorType = payload?.errorType ?? Error.name;
1018
+ const lambdaErrorMessage = payload?.errorMessage;
1019
+ if ( statusCode === 200 ) {
1020
+ super( `Invoked function threw "[${lambdaErrorType}]${lambdaErrorMessage ? ' ' + lambdaErrorMessage : ''}"` );
1021
+ } else {
1022
+ super( 'Error invoking the function' );
1023
+ }
1024
+ this.statusCode = statusCode;
1025
+ this.lambdaErrorType = lambdaErrorType;
1026
+ this.lambdaErrorMessage = lambdaErrorMessage;
1027
+ }
1028
+ };
1397
1029
 
1398
1030
 
1399
- /***/ }),
1031
+ /***/ },
1400
1032
 
1401
- /***/ 3936:
1402
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1033
+ /***/ 3936
1034
+ (module, __unused_webpack_exports, __webpack_require__) {
1403
1035
 
1404
1036
  const { CopyObjectCommand } = __webpack_require__( 5725 );
1405
1037
 
@@ -1414,1076 +1046,1328 @@ module.exports = async ( client, bucket, key, source, nativeArgs ) => {
1414
1046
  };
1415
1047
 
1416
1048
 
1417
- /***/ }),
1049
+ /***/ },
1418
1050
 
1419
- /***/ 3990:
1420
- /***/ ((module) => {
1421
-
1422
- module.exports = ( time, interval ) => time - ( time % interval );
1051
+ /***/ 345
1052
+ (module, __unused_webpack_exports, __webpack_require__) {
1423
1053
 
1054
+ const { GetObjectCommand } = __webpack_require__( 5725 );
1424
1055
 
1425
- /***/ }),
1056
+ module.exports = async ( client, bucket, key, nativeArgs ) => {
1057
+ const response = await client.send( new GetObjectCommand( {
1058
+ ...nativeArgs,
1059
+ Bucket: bucket,
1060
+ Key: key
1061
+ } ) );
1062
+ const stream = response.Body;
1063
+ return Buffer.concat( await stream.toArray() ).toString( 'utf-8' );
1064
+ };
1426
1065
 
1427
- /***/ 4110:
1428
- /***/ ((module) => {
1429
1066
 
1430
- module.exports = ( sample, mean, stdDev ) => stdDev === 0 ? NaN : ( sample - mean ) / stdDev;
1067
+ /***/ },
1431
1068
 
1069
+ /***/ 3758
1070
+ (module, __unused_webpack_exports, __webpack_require__) {
1432
1071
 
1433
- /***/ }),
1072
+ const { getSignedUrl } = __webpack_require__( 4991 );
1073
+ const { GetObjectCommand } = __webpack_require__( 5725 );
1434
1074
 
1435
- /***/ 4124:
1436
- /***/ ((module) => {
1075
+ module.exports = async ( client, bucket, key, expiration ) => {
1076
+ const getObjectCmd = new GetObjectCommand( { Bucket: bucket, Key: key } );
1077
+ const url = await getSignedUrl( client, getObjectCmd, { expiresIn: expiration } );
1078
+ return url;
1079
+ };
1437
1080
 
1438
- module.exports = values => values.reduce( ( sum, value ) => sum + value, 0 ) / values.length;
1439
1081
 
1082
+ /***/ },
1440
1083
 
1441
- /***/ }),
1084
+ /***/ 279
1085
+ (module, __unused_webpack_exports, __webpack_require__) {
1442
1086
 
1443
- /***/ 4127:
1444
- /***/ ((module) => {
1087
+ const { HeadObjectCommand } = __webpack_require__( 5725 );
1445
1088
 
1446
- module.exports = 500;
1089
+ module.exports = async ( client, bucket, key ) =>
1090
+ client.send( new HeadObjectCommand( { Bucket: bucket, Key: key } ) );
1447
1091
 
1448
1092
 
1449
- /***/ }),
1093
+ /***/ },
1450
1094
 
1451
- /***/ 4144:
1452
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1095
+ /***/ 645
1096
+ (module, __unused_webpack_exports, __webpack_require__) {
1453
1097
 
1454
- const { UpdateCommand } = __webpack_require__( 3489 );
1098
+ const copy = __webpack_require__( 3936 );
1099
+ const download = __webpack_require__( 345 );
1100
+ const getSignedUrl = __webpack_require__( 3758 );
1101
+ const head = __webpack_require__( 279 );
1102
+ const upload = __webpack_require__( 9704 );
1103
+ const { S3Client } = __webpack_require__( 5725 );
1104
+ const clientProvider = __webpack_require__( 9039 );
1105
+ const createInstance = __webpack_require__( 5438 );
1455
1106
 
1456
- module.exports = async ( client, nativeArgs ) => {
1457
- const args = Object.assign( { ReturnValues: 'ALL_NEW' }, nativeArgs );
1458
- const response = await client.send( new UpdateCommand( args ) );
1459
- return response.Attributes;
1107
+ const methods = {
1108
+ copy,
1109
+ download,
1110
+ getSignedUrl,
1111
+ head,
1112
+ upload
1460
1113
  };
1461
1114
 
1115
+ module.exports = createInstance( clientProvider.bind( null, S3Client ), methods );
1462
1116
 
1463
- /***/ }),
1464
1117
 
1465
- /***/ 4164:
1466
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1118
+ /***/ },
1467
1119
 
1468
- const cacheSym = Symbol.for( 'cache' );
1469
- const crypto = __webpack_require__( 6982 );
1120
+ /***/ 9704
1121
+ (module, __unused_webpack_exports, __webpack_require__) {
1470
1122
 
1471
- const hash = text => crypto.createHash( 'md5' ).update( text ).digest( 'hex' );
1123
+ const { PutObjectCommand } = __webpack_require__( 5725 );
1472
1124
 
1473
- const propOpts = {
1474
- enumerable: false,
1475
- configurable: false,
1476
- writable: false
1477
- };
1125
+ module.exports = ( client, bucket, key, body, nativeArgs ) =>
1126
+ client.send( new PutObjectCommand( {
1127
+ ...nativeArgs,
1128
+ Bucket: bucket,
1129
+ Key: key,
1130
+ Body: typeof body === 'string' || Buffer.isBuffer( body ) ? body : JSON.stringify( body )
1131
+ } ) );
1478
1132
 
1479
- module.exports = {
1480
- set: ( key, value ) => {
1481
- const keySym = Symbol.for( hash( key ) );
1482
1133
 
1483
- if ( !global[cacheSym] ) {
1484
- Object.defineProperty( global, cacheSym, { ...propOpts, value: {} } );
1485
- }
1134
+ /***/ },
1486
1135
 
1487
- Object.defineProperty( global[cacheSym], keySym, { ...propOpts, value } );
1488
- },
1489
- get: key => {
1490
- return global[cacheSym]?.[Symbol.for( hash( key ) )];
1491
- }
1492
- };
1136
+ /***/ 809
1137
+ (module, __unused_webpack_exports, __webpack_require__) {
1138
+
1139
+ const { DeleteSuppressedDestinationCommand } = __webpack_require__( 9556 );
1493
1140
 
1141
+ module.exports = ( client, address ) => client.send( new DeleteSuppressedDestinationCommand( { EmailAddress: address } ) );
1494
1142
 
1495
- /***/ }),
1496
1143
 
1497
- /***/ 4225:
1498
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1144
+ /***/ },
1499
1145
 
1500
- const query = __webpack_require__( 6030 );
1501
- const { TimestreamQueryClient } = __webpack_require__( 1671 );
1502
- const { Agent } = __webpack_require__( 5692 );
1146
+ /***/ 5624
1147
+ (module, __unused_webpack_exports, __webpack_require__) {
1148
+
1149
+ const deleteSuppressedDestination = __webpack_require__( 809 );
1150
+ const sendEmail = __webpack_require__( 1783 );
1151
+ const { SESv2Client } = __webpack_require__( 9556 );
1503
1152
  const clientProvider = __webpack_require__( 9039 );
1504
1153
  const createInstance = __webpack_require__( 5438 );
1505
1154
 
1506
- const methods = { query };
1507
- const defaultArgs = {
1508
- maxRetries: 10,
1509
- httpOptions: { timeout: 60000, agent: new Agent( { maxSockets: 5000 } ) }
1155
+ const methods = {
1156
+ deleteSuppressedDestination,
1157
+ sendEmail
1510
1158
  };
1511
1159
 
1512
- module.exports = createInstance( args => clientProvider( TimestreamQueryClient, [ Object.assign( {}, defaultArgs, args ) ] ), methods );
1160
+ module.exports = createInstance( clientProvider.bind( null, SESv2Client ), methods );
1513
1161
 
1514
1162
 
1515
- /***/ }),
1163
+ /***/ },
1516
1164
 
1517
- /***/ 4243:
1518
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1165
+ /***/ 1783
1166
+ (module, __unused_webpack_exports, __webpack_require__) {
1519
1167
 
1520
- const sleep = __webpack_require__( 2445 );
1168
+ const { SendEmailCommand } = __webpack_require__( 9556 );
1521
1169
 
1522
- const execWithRetry = async ( closure, { limit, delay, retryHook, execCount = 0 } ) => {
1523
- if ( !( closure instanceof Function ) ) {
1524
- throw new Error( 'Closure is not a function' );
1525
- }
1170
+ module.exports = ( client, { to = [], from, html, subject }, args ) =>
1171
+ client.send( new SendEmailCommand( {
1172
+ Destination: {
1173
+ ToAddresses: to
1174
+ },
1175
+ Content: {
1176
+ Simple: {
1177
+ Body: {
1178
+ Html: {
1179
+ Data: html,
1180
+ Charset: 'utf-8'
1181
+ }
1182
+ },
1183
+ Subject: {
1184
+ Data: subject
1185
+ }
1186
+ }
1187
+ },
1188
+ FromEmailAddress: from,
1189
+ ...args
1190
+ } ) );
1526
1191
 
1527
- try {
1528
- return await closure();
1529
- } catch ( error ) {
1530
- // exhausted
1531
- if ( execCount === limit ) { throw error; }
1532
1192
 
1533
- // async retry hook to check if it should retry or give up and throw
1534
- if ( retryHook instanceof Function ) {
1535
- try {
1536
- const retry = await retryHook( error, execCount );
1537
- if ( retry === false ) { return false; }
1193
+ /***/ },
1538
1194
 
1539
- // Hook errors break the flow
1540
- } catch ( hookError ) {
1541
- console.debug( hookError );
1542
- throw hookError;
1543
- }
1544
- }
1195
+ /***/ 3099
1196
+ (module, __unused_webpack_exports, __webpack_require__) {
1545
1197
 
1546
- // if there is no hook back-off and retry
1547
- if ( delay > 0 ) {
1548
- await sleep( delay ** ( 1 + execCount ) );
1549
- }
1550
- return execWithRetry( closure, { limit, delay, retryHook, execCount: execCount + 1 } );
1551
- }
1198
+ const publish = __webpack_require__( 8080 );
1199
+ const publishBatch = __webpack_require__( 3531 );
1200
+ const { SNSClient } = __webpack_require__( 7651 );
1201
+ const clientProvider = __webpack_require__( 9039 );
1202
+ const createInstance = __webpack_require__( 5438 );
1203
+
1204
+ const methods = {
1205
+ publish,
1206
+ publishBatch
1552
1207
  };
1553
1208
 
1554
- /**
1555
- *
1556
- * @param {Function} closure A self contained function that will be invoked
1557
- * @param {Object} config
1558
- * @param {Number} limit The max number of retries
1559
- * @param {Number} delay The delay between each retry (it will be multiplied by the number of retries, so, it is linear back-off)
1560
- * @param {Function} retryHook A function to be called every-time a retry is needed.
1561
- * If this functions returns false, the retry error is raised
1562
- * If this functions throws error, the thrown error is raised
1563
- * @returns {Any} The closure result
1564
- */
1565
- module.exports = async ( closure, { limit = 0, delay = 0, retryHook = null } = {} ) =>
1566
- execWithRetry( closure, { limit, delay, retryHook } );
1209
+ module.exports = createInstance( clientProvider.bind( null, SNSClient ), methods );
1567
1210
 
1568
1211
 
1569
- /***/ }),
1212
+ /***/ },
1570
1213
 
1571
- /***/ 4338:
1572
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1214
+ /***/ 8080
1215
+ (module, __unused_webpack_exports, __webpack_require__) {
1573
1216
 
1574
- const startQuery = __webpack_require__( 3649 );
1575
- const getResults = __webpack_require__( 739 );
1576
- const parseResults = __webpack_require__( 9552 );
1217
+ const { PublishCommand } = __webpack_require__( 7651 );
1577
1218
 
1578
- /**
1579
- * @class Result
1580
- * @type {Object}
1581
- * @property {Object[]} items Each query result row, parsed to a camelized js object
1582
- * @property {Number} count Total number of results
1583
- */
1219
+ module.exports = async ( client, topic, message, args = {} ) => {
1220
+ const response = await client.send( new PublishCommand( {
1221
+ ...args,
1222
+ TopicArn: topic,
1223
+ Message: typeof message === 'string' ? message : JSON.stringify( message )
1224
+ } ) );
1225
+ return response.MessageId;
1226
+ };
1584
1227
 
1585
- /**
1586
- * Executes an Athena Query
1587
- * @param {*} client The native client
1588
- * @param {Object} nativeArgs The native args to start the Cloudwatch Query
1589
- * @param {Object=} options Extra options for this command
1590
- * @param {Object=} options.range Since the nativeArgs "startTime" and "endTime" are second based epochs, the "range" argument accepts milliseconds based epochs for convenience, thus overwriting the "nativeArgs"
1591
- * @param {Number} options.range.from The beginning of the time range to query, overwrites "startTime"
1592
- * @param {Number} options.range.to The end of the time range to query, overwrites "endTime"
1593
- * @returns {Result} The query result
1594
- */
1595
- module.exports = async ( client, nativeArgs, { range = {} } = {} ) => {
1596
- const queryId = await startQuery( { client, nativeArgs, range } );
1597
- const results = await getResults( { client, queryId } );
1598
- const items = parseResults( results );
1599
- return { items, count: items.length };
1228
+
1229
+ /***/ },
1230
+
1231
+ /***/ 3531
1232
+ (module, __unused_webpack_exports, __webpack_require__) {
1233
+
1234
+ const { PublishBatchCommand } = __webpack_require__( 7651 );
1235
+
1236
+ module.exports = async ( client, topic, messages ) => {
1237
+ if ( messages.length > 10 ) {
1238
+ throw new Error( 'SNS.publishBatch only accepts up to 10 messages.' );
1239
+ }
1240
+ const response = await client.send( new PublishBatchCommand( {
1241
+ TopicArn: topic,
1242
+ PublishBatchRequestEntries: messages.map( ( { body, id = null, nativeArgs }, index ) => ( {
1243
+ Id: id ?? `message_${index}`,
1244
+ Message: typeof body === 'string' ? body : JSON.stringify( body ),
1245
+ ...nativeArgs
1246
+ } ) )
1247
+ } ) );
1248
+
1249
+ if ( response.Failed?.length > 0 ) {
1250
+ const error = new Error( 'SNS.publishBatch Failed. See error details' );
1251
+ error.details = response.Failed;
1252
+ throw error;
1253
+ }
1254
+ return response;
1600
1255
  };
1601
1256
 
1602
1257
 
1603
- /***/ }),
1258
+ /***/ },
1604
1259
 
1605
- /***/ 4348:
1606
- /***/ ((module) => {
1260
+ /***/ 5637
1261
+ (module, __unused_webpack_exports, __webpack_require__) {
1607
1262
 
1608
- "use strict";
1609
- module.exports = require("@aws-sdk/client-ssm");
1263
+ const { DeleteMessageCommand } = __webpack_require__( 1976 );
1264
+
1265
+ module.exports = async ( client, queue, receiptHandle ) =>
1266
+ client.send( new DeleteMessageCommand( {
1267
+ QueueUrl: queue,
1268
+ ReceiptHandle: receiptHandle
1269
+ } ) );
1610
1270
 
1611
- /***/ }),
1612
1271
 
1613
- /***/ 4528:
1614
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1272
+ /***/ },
1615
1273
 
1616
- const createClient = __webpack_require__( 5422 );
1274
+ /***/ 3340
1275
+ (module, __unused_webpack_exports, __webpack_require__) {
1617
1276
 
1618
- module.exports = {
1619
- createClient
1277
+ const deleteMessage = __webpack_require__( 5637 );
1278
+ const sendMessage = __webpack_require__( 6720 );
1279
+ const sendMessageBatch = __webpack_require__( 3131 );
1280
+ const { SQSClient } = __webpack_require__( 1976 );
1281
+ const clientProvider = __webpack_require__( 9039 );
1282
+ const createInstance = __webpack_require__( 5438 );
1283
+
1284
+ const methods = {
1285
+ deleteMessage,
1286
+ sendMessage,
1287
+ sendMessageBatch
1620
1288
  };
1621
1289
 
1290
+ module.exports = createInstance( clientProvider.bind( null, SQSClient ), methods );
1622
1291
 
1623
- /***/ }),
1624
1292
 
1625
- /***/ 4671:
1626
- /***/ ((module) => {
1293
+ /***/ },
1627
1294
 
1628
- "use strict";
1629
- module.exports = require("@aws-sdk/client-dynamodb");
1295
+ /***/ 8175
1296
+ (module) {
1297
+
1298
+ /*
1299
+ References:
1300
+ - https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_SendMessage.html
1301
+ - https://stackoverflow.com/questions/58809098/remove-invalid-characters-from-message-sent-to-aws-amazon-sqs
1302
+ */
1303
+ module.exports = v => v?.replace( /[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/ug, '' ) // eslint-disable-line
1630
1304
 
1631
- /***/ }),
1632
1305
 
1633
- /***/ 4692:
1634
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1306
+ /***/ },
1635
1307
 
1636
- const calcMedian = __webpack_require__( 3187 );
1308
+ /***/ 6720
1309
+ (module, __unused_webpack_exports, __webpack_require__) {
1637
1310
 
1638
- module.exports = pop => {
1639
- const center = calcMedian( pop );
1640
- return calcMedian( pop.map( v => Math.abs( v - center ) ) );
1311
+ const { SendMessageCommand } = __webpack_require__( 1976 );
1312
+ const sanitizeSqs = __webpack_require__( 8175 );
1313
+
1314
+ module.exports = async ( client, queue, body, args ) => {
1315
+ const response = await client.send( new SendMessageCommand( {
1316
+ ...args,
1317
+ MessageBody: sanitizeSqs( typeof body === 'string' ? body : JSON.stringify( body ) ),
1318
+ QueueUrl: queue
1319
+ } ) );
1320
+ return response.MessageId;
1641
1321
  };
1642
1322
 
1643
1323
 
1644
- /***/ }),
1324
+ /***/ },
1645
1325
 
1646
- /***/ 4821:
1647
- /***/ ((module) => {
1326
+ /***/ 3131
1327
+ (module, __unused_webpack_exports, __webpack_require__) {
1648
1328
 
1649
- module.exports = ( items, size ) => items.reduce( ( arrs, item ) =>
1650
- ( arrs[0] && arrs[0].length < size ) ?
1651
- [ [ ...arrs[0], item ] ].concat( arrs.slice( 1 ) ) :
1652
- [ [ item ] ].concat( arrs )
1653
- , [] ).reverse();
1329
+ const { SendMessageBatchCommand } = __webpack_require__( 1976 );
1330
+ const sanitizeSqs = __webpack_require__( 8175 );
1331
+
1332
+ module.exports = async ( client, queue, messages ) => {
1333
+ if ( messages.length > 10 ) {
1334
+ throw new Error( 'SQS.sendMessageBatch only accepts up to 10 messages.' );
1335
+ }
1336
+ const response = await client.send( new SendMessageBatchCommand( {
1337
+ QueueUrl: queue,
1338
+ Entries: messages.map( ( { body, id = null, nativeArgs }, index ) => ( {
1339
+ Id: id ?? `message_${index}`,
1340
+ MessageBody: sanitizeSqs( typeof body === 'string' ? body : JSON.stringify( body ) ),
1341
+ ...nativeArgs
1342
+ } ) )
1343
+ } ) );
1654
1344
 
1345
+ if ( response.Failed?.length > 0 ) {
1346
+ const error = new Error( 'SQS.sendMessageBatch Failed. See error details' );
1347
+ error.details = response.Failed;
1348
+ throw error;
1349
+ }
1350
+ return response;
1351
+ };
1655
1352
 
1656
- /***/ }),
1657
1353
 
1658
- /***/ 4870:
1659
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1354
+ /***/ },
1660
1355
 
1661
- const athena = __webpack_require__( 228 );
1662
- const cwLogs = __webpack_require__( 2710 );
1663
- const dynamo = __webpack_require__( 1505 );
1664
- const lambda = __webpack_require__( 3544 );
1665
- const s3 = __webpack_require__( 645 );
1666
- const ses = __webpack_require__( 5624 );
1667
- const sns = __webpack_require__( 3099 );
1668
- const sqs = __webpack_require__( 3340 );
1669
- const ssm = __webpack_require__( 5888 );
1670
- const timestreamQuery = __webpack_require__( 4225 );
1671
- const timestreamWrite = __webpack_require__( 2538 );
1356
+ /***/ 8660
1357
+ (module, __unused_webpack_exports, __webpack_require__) {
1672
1358
 
1673
- module.exports = {
1674
- athena,
1675
- cwLogs,
1676
- dynamo,
1677
- lambda,
1678
- s3,
1679
- ses,
1680
- sns,
1681
- sqs,
1682
- ssm,
1683
- timestreamQuery,
1684
- timestreamWrite
1359
+ const cacheStorage = __webpack_require__( 4164 );
1360
+ const { GetParameterCommand } = __webpack_require__( 4348 );
1361
+
1362
+ module.exports = async ( client, name ) => {
1363
+ const key = `SSM_${name}`;
1364
+ const cacheValue = cacheStorage.get( key );
1365
+ if ( cacheValue ) { return cacheValue; }
1366
+
1367
+ try {
1368
+ const response = await client.send( new GetParameterCommand( { Name: name, WithDecryption: true } ) );
1369
+ const value = response?.Parameter?.Value;
1370
+ cacheStorage.set( key, value );
1371
+ return value;
1372
+ } catch ( error ) {
1373
+ if ( error.constructor.name === 'ParameterNotFound' ) {
1374
+ return null;
1375
+ }
1376
+ throw error;
1377
+ }
1685
1378
  };
1686
1379
 
1687
1380
 
1688
- /***/ }),
1381
+ /***/ },
1689
1382
 
1690
- /***/ 4991:
1691
- /***/ ((module) => {
1383
+ /***/ 5888
1384
+ (module, __unused_webpack_exports, __webpack_require__) {
1692
1385
 
1693
- "use strict";
1694
- module.exports = require("@aws-sdk/s3-request-presigner");
1386
+ const get = __webpack_require__( 8660 );
1387
+ const { SSMClient } = __webpack_require__( 4348 );
1388
+ const clientProvider = __webpack_require__( 9039 );
1389
+ const createInstance = __webpack_require__( 5438 );
1695
1390
 
1696
- /***/ }),
1391
+ const methods = { get };
1697
1392
 
1698
- /***/ 5263:
1699
- /***/ ((module) => {
1393
+ module.exports = createInstance( clientProvider.bind( null, SSMClient ), methods );
1700
1394
 
1701
- module.exports = t => t * 24 * 60 * 60 * 1000;
1702
1395
 
1396
+ /***/ },
1703
1397
 
1704
- /***/ }),
1398
+ /***/ 4225
1399
+ (module, __unused_webpack_exports, __webpack_require__) {
1705
1400
 
1706
- /***/ 5265:
1707
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1401
+ const query = __webpack_require__( 6030 );
1402
+ const { TimestreamQueryClient } = __webpack_require__( 1671 );
1403
+ const { Agent } = __webpack_require__( 5692 );
1404
+ const clientProvider = __webpack_require__( 9039 );
1405
+ const createInstance = __webpack_require__( 5438 );
1708
1406
 
1709
- const select = __webpack_require__( 2157 );
1407
+ const methods = { query };
1408
+ const defaultArgs = {
1409
+ maxRetries: 10,
1410
+ httpOptions: { timeout: 60000, agent: new Agent( { maxSockets: 5000 } ) }
1411
+ };
1710
1412
 
1711
- module.exports = async ( client, ...args ) => select( client, 'query', ...args );
1413
+ module.exports = createInstance( args => clientProvider( TimestreamQueryClient, [ Object.assign( {}, defaultArgs, args ) ] ), methods );
1712
1414
 
1713
1415
 
1714
- /***/ }),
1416
+ /***/ },
1715
1417
 
1716
- /***/ 5422:
1717
- /***/ ((module) => {
1418
+ /***/ 7261
1419
+ (module, __unused_webpack_exports, __webpack_require__) {
1718
1420
 
1719
- global.__redisInstances = {};
1421
+ // https://docs.aws.amazon.com/timestream/latest/developerguide/API_query_Type.html
1422
+ // https://docs.aws.amazon.com/timestream/latest/developerguide/supported-data-types.html
1720
1423
 
1721
- /**
1722
- * Create a redis client instance
1723
- * @param {Object} redis Redis npm dependency
1724
- * @param {String} address Redis DB address (either RW or RO)
1725
- * @returns redisClient A new redis client instance connected to the database
1726
- */
1727
- module.exports = async ( { redis, address, protocol = 'rediss', port = 6379 } ) => {
1728
- if ( global.__redisInstances[address] ) {
1729
- try {
1730
- const r = await global.__redisInstances[address].ping();
1731
- if ( r === 'PONG' ) {
1732
- return global.__redisInstances[address];
1733
- } else {
1734
- delete global.__redisInstances[address];
1735
- }
1736
- } catch {
1737
- delete global.__redisInstances[address];
1738
- }
1424
+ const { ScalarType } = __webpack_require__( 1671 );
1425
+
1426
+ const parseBigInt = value => {
1427
+ const asInt = parseInt( value, 10 );
1428
+ return asInt <= Number.MAX_SAFE_INTEGER && asInt >= Number.MIN_SAFE_INTEGER ? asInt : value;
1429
+ };
1430
+
1431
+ const parseScalarValue = ( type, value ) => {
1432
+ switch ( type ) {
1433
+ case ScalarType.BOOLEAN:
1434
+ return value === 'true';
1435
+ case ScalarType.DOUBLE:
1436
+ return parseFloat( value );
1437
+ case ScalarType.TIMESTAMP:
1438
+ return new Date( `${value.replace( ' ', 'T' )}Z` );
1439
+ case ScalarType.INTEGER:
1440
+ return parseInt( value, 10 );
1441
+ case ScalarType.UNKNOWN: // is NULL
1442
+ return null;
1443
+ case ScalarType.BIGINT:
1444
+ return parseBigInt( value );
1445
+ case ScalarType.VARCHAR:
1446
+ case ScalarType.DATE:
1447
+ case ScalarType.TIME:
1448
+ case ScalarType.INTERVAL_DAY_TO_SECOND:
1449
+ case ScalarType.INTERVAL_YEAR_TO_MONTH:
1450
+ default:
1451
+ return value;
1739
1452
  }
1453
+ };
1740
1454
 
1741
- const client = redis.createClient( { url: `${protocol}://${address}:${port}`, socket: { keepAlive: 15000 } } );
1455
+ const parseValue = ( typeInfo, datum ) => {
1456
+ // value might be null
1457
+ if ( datum['NullValue'] === true ) {
1458
+ return null;
1459
+ }
1742
1460
 
1743
- await client.connect();
1461
+ // or a time series
1462
+ if ( Object.hasOwn( typeInfo, 'TimeSeriesMeasureValueColumnInfo' ) ) {
1463
+ return datum.TimeSeriesValue.map( v => ( {
1464
+ time: new Date( v.Time ),
1465
+ value: parseValue( typeInfo.TimeSeriesMeasureValueColumnInfo.Type, v.Value )
1466
+ } ) );
1467
+ }
1744
1468
 
1745
- global.__redisInstances[address] = client;
1746
- return client;
1469
+ // maybe an array
1470
+ if ( Object.hasOwn( typeInfo, 'ArrayColumnInfo' ) ) {
1471
+ return datum.ArrayValue.map( v => parseValue( typeInfo.ArrayColumnInfo.Type, v ) );
1472
+ }
1473
+
1474
+ // or even a row
1475
+ if ( Object.hasOwn( typeInfo, 'RowColumnInfo' ) ) {
1476
+ const rowColumnInfo = typeInfo.RowColumnInfo;
1477
+ return datum.RowValue.Data.reduce( ( object, value, index ) => {
1478
+ const { Name: name, Type: typeInfo } = rowColumnInfo[index];
1479
+ return Object.assign( object, { [name]: parseValue( typeInfo, value ) } );
1480
+ }, {} );
1481
+ }
1482
+
1483
+ // if none, it is scalar
1484
+ return parseScalarValue( typeInfo.ScalarType, datum['ScalarValue'] );
1747
1485
  };
1748
1486
 
1487
+ module.exports = response => {
1488
+ const { ColumnInfo: colInfo, Rows: rows } = response;
1489
+ return rows.map( row =>
1490
+ row.Data.reduce( ( entry, value, index ) => {
1491
+ const { Name: name, Type: typeInfo } = colInfo[index];
1492
+ return Object.assign( entry, { [name]: parseValue( typeInfo, value ) } );
1493
+ }, { } )
1494
+ );
1495
+ };
1749
1496
 
1750
- /***/ }),
1751
1497
 
1752
- /***/ 5438:
1753
- /***/ ((module) => {
1498
+ /***/ },
1754
1499
 
1755
- /**
1756
- * This is base object each AWS abstraction will provide
1757
- */
1758
- module.exports = ( providerFn, methods ) => {
1759
- // This creates the "instance",
1760
- // so calling the method as a function returns a copy of its client instantiated with the given args
1761
- // every method called from it will use this instance
1762
- const factory = args => {
1763
- const client = providerFn( args );
1764
- // return self, so it is possible use the native client
1765
- methods.getClient = () => client;
1766
- return Object.entries( methods ).reduce( ( o, [ k, v ] ) => Object.assign( o, { [k]: v.bind( null, client ) } ), { } );
1767
- };
1500
+ /***/ 6030
1501
+ (module, __unused_webpack_exports, __webpack_require__) {
1768
1502
 
1769
- // This is the singleton part;
1770
- // First add the static method to the factory;
1771
- Object.entries( methods ).forEach( ( [ key, value ] ) => factory[key] = value );
1503
+ const { QueryCommand } = __webpack_require__( 1671 );
1504
+ const { camelize } = __webpack_require__( 5762 );
1505
+ const parseItems = __webpack_require__( 7261 );
1772
1506
 
1773
- // Then add the special method "getClient", so it is possible use the native client
1774
- factory.getClient = client => client;
1507
+ const query = async ( client, queryString, { prevItems = [], recursive, paginationToken, maxRows, rawResponse } ) => {
1508
+ const response = await client.send( new QueryCommand( { QueryString: queryString, NextToken: paginationToken, MaxRows: maxRows } ) );
1509
+ if ( !recursive && rawResponse ) {
1510
+ return response;
1511
+ }
1775
1512
 
1776
- // Finally makes the proxy which will allow each singleton method to use the client provider of the AWS service+
1777
- return new Proxy( factory, {
1778
- get( target, key ) {
1779
- const t = target[key];
1780
- return ( typeof t === 'function' ) ? t.bind( null, providerFn() ) : t;
1781
- }
1782
- } );
1513
+ const nextToken = response.NextToken;
1514
+ if ( nextToken && recursive ) {
1515
+ return query( client, queryString, { prevItems: parseItems( response ), recursive, paginationToken: nextToken, maxRows } );
1516
+ }
1517
+
1518
+ const items = prevItems.concat( parseItems( response ) );
1519
+ return { nextToken, count: items.length, items, queryStatus: camelize( response.QueryStatus ) };
1783
1520
  };
1784
1521
 
1522
+ module.exports = async ( client, queryString, { recursive = false, paginationToken = undefined, maxRows = undefined, rawResponse = false } = {} ) =>
1523
+ query( client, queryString, { recursive, paginationToken, maxRows, rawResponse } );
1785
1524
 
1786
- /***/ }),
1787
1525
 
1788
- /***/ 5624:
1789
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1526
+ /***/ },
1790
1527
 
1791
- const deleteSuppressedDestination = __webpack_require__( 809 );
1792
- const sendEmail = __webpack_require__( 1783 );
1793
- const { SESv2Client } = __webpack_require__( 9556 );
1528
+ /***/ 2538
1529
+ (module, __unused_webpack_exports, __webpack_require__) {
1530
+
1531
+ const writeRecords = __webpack_require__( 8936 );
1532
+ const { TimestreamWriteClient } = __webpack_require__( 8248 );
1533
+ const { Agent } = __webpack_require__( 5692 );
1794
1534
  const clientProvider = __webpack_require__( 9039 );
1795
1535
  const createInstance = __webpack_require__( 5438 );
1796
1536
 
1797
- const methods = {
1798
- deleteSuppressedDestination,
1799
- sendEmail
1537
+ const methods = { writeRecords };
1538
+ const defaultArgs = {
1539
+ maxRetries: 10,
1540
+ httpOptions: { timeout: 60000, agent: new Agent( { maxSockets: 5000 } ) }
1800
1541
  };
1801
1542
 
1802
- module.exports = createInstance( clientProvider.bind( null, SESv2Client ), methods );
1543
+ module.exports = createInstance( args => clientProvider( TimestreamWriteClient, [ Object.assign( {}, defaultArgs, args ) ] ), methods );
1803
1544
 
1804
1545
 
1805
- /***/ }),
1546
+ /***/ },
1806
1547
 
1807
- /***/ 5637:
1808
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1548
+ /***/ 8936
1549
+ (module, __unused_webpack_exports, __webpack_require__) {
1809
1550
 
1810
- const { DeleteMessageCommand } = __webpack_require__( 1976 );
1551
+ const { WriteRecordsCommand } = __webpack_require__( 8248 );
1811
1552
 
1812
- module.exports = async ( client, queue, receiptHandle ) =>
1813
- client.send( new DeleteMessageCommand( {
1814
- QueueUrl: queue,
1815
- ReceiptHandle: receiptHandle
1816
- } ) );
1553
+ module.exports = async ( client, { database, table, records, ignoreRejections = false } ) => {
1554
+ try {
1555
+ const response = await client.send( new WriteRecordsCommand( {
1556
+ DatabaseName: database,
1557
+ TableName: table,
1558
+ Records: records
1559
+ } ) );
1560
+ return { recordsIngested: response.RecordsIngested };
1561
+ } catch ( error ) {
1562
+ if ( ignoreRejections && error.name === 'RejectedRecordsException' ) {
1563
+ return { rejectedRecords: error.RejectedRecords };
1564
+ }
1565
+ throw error;
1566
+ }
1567
+ };
1817
1568
 
1818
1569
 
1819
- /***/ }),
1570
+ /***/ },
1820
1571
 
1821
- /***/ 5692:
1822
- /***/ ((module) => {
1572
+ /***/ 5263
1573
+ (module) {
1823
1574
 
1824
- "use strict";
1825
- module.exports = require("https");
1575
+ module.exports = t => t * 24 * 60 * 60 * 1000;
1826
1576
 
1827
- /***/ }),
1828
1577
 
1829
- /***/ 5723:
1830
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1578
+ /***/ },
1831
1579
 
1832
- const { randomBytes } = __webpack_require__( 6982 );
1833
- const { StartQueryExecutionCommand } = __webpack_require__( 3744 );
1580
+ /***/ 6961
1581
+ (module) {
1834
1582
 
1835
- /**
1836
- * args : https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/athena/command/StartQueryExecutionCommand/
1837
- * A ClientRequestToken is created automatically
1838
- */
1839
- module.exports = async ( { client, ...args } ) => {
1840
- const cmd = new StartQueryExecutionCommand( {
1841
- ClientRequestToken: randomBytes( 16 ).toString( 'hex' ),
1842
- ...args
1843
- } );
1844
- const { QueryExecutionId: queryId } = await client.send( cmd );
1845
- return queryId;
1846
- };
1583
+ module.exports = t => t * 60 * 60 * 1000;
1847
1584
 
1848
1585
 
1849
- /***/ }),
1586
+ /***/ },
1850
1587
 
1851
- /***/ 5725:
1852
- /***/ ((module) => {
1588
+ /***/ 3830
1589
+ (module, __unused_webpack_exports, __webpack_require__) {
1853
1590
 
1854
- "use strict";
1855
- module.exports = require("@aws-sdk/client-s3");
1591
+ const days = __webpack_require__( 5263 );
1592
+ const hours = __webpack_require__( 6961 );
1593
+ const minutes = __webpack_require__( 6635 );
1594
+ const months = __webpack_require__( 8119 );
1595
+ const msToS = __webpack_require__( 7416 );
1596
+ const round = __webpack_require__( 3990 );
1597
+ const seconds = __webpack_require__( 7051 );
1856
1598
 
1857
- /***/ }),
1599
+ module.exports = {
1600
+ days,
1601
+ hours,
1602
+ minutes,
1603
+ months,
1604
+ msToS,
1605
+ round,
1606
+ seconds
1607
+ };
1858
1608
 
1859
- /***/ 5744:
1860
- /***/ ((module) => {
1861
1609
 
1862
- module.exports = {
1863
- encode: k => {
1864
- if ( k === null || k === undefined ) { return k; }
1610
+ /***/ },
1865
1611
 
1866
- return Buffer.from( JSON.stringify( k ) ).toString( 'base64' );
1867
- },
1868
- decode: k => {
1869
- if ( k === null || k === undefined ) { return k; }
1612
+ /***/ 6635
1613
+ (module) {
1870
1614
 
1871
- const result = Buffer.from( k, 'base64' ).toString( 'utf8' );
1872
- try {
1873
- return JSON.parse( result );
1874
- } catch {
1875
- return result;
1876
- }
1877
- }
1878
- };
1615
+ module.exports = t => t * 60 * 1000;
1879
1616
 
1880
1617
 
1881
- /***/ }),
1618
+ /***/ },
1882
1619
 
1883
- /***/ 5762:
1884
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1620
+ /***/ 8119
1621
+ (module) {
1885
1622
 
1886
- const camelize = __webpack_require__( 8256 );
1887
- const filterProps = __webpack_require__( 6451 );
1888
- const removeEmptyArrays = __webpack_require__( 2047 );
1889
- const snakelize = __webpack_require__( 7572 );
1623
+ module.exports = t => t * 30 * 24 * 60 * 60 * 1000;
1890
1624
 
1891
- module.exports = {
1892
- camelize,
1893
- filterProps,
1894
- removeEmptyArrays,
1895
- snakelize
1896
- };
1897
1625
 
1626
+ /***/ },
1898
1627
 
1899
- /***/ }),
1628
+ /***/ 7416
1629
+ (module) {
1900
1630
 
1901
- /***/ 5847:
1902
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1631
+ module.exports = v => Math.ceil( v / 1000 );
1903
1632
 
1904
- const batchWrite = __webpack_require__( 8593 );
1905
1633
 
1906
- module.exports = async ( client, ...args ) => batchWrite( client, 'put', ...args );
1634
+ /***/ },
1907
1635
 
1636
+ /***/ 3990
1637
+ (module) {
1908
1638
 
1909
- /***/ }),
1639
+ module.exports = ( time, interval ) => time - ( time % interval );
1910
1640
 
1911
- /***/ 5888:
1912
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1913
1641
 
1914
- const get = __webpack_require__( 8660 );
1915
- const { SSMClient } = __webpack_require__( 4348 );
1916
- const clientProvider = __webpack_require__( 9039 );
1917
- const createInstance = __webpack_require__( 5438 );
1642
+ /***/ },
1918
1643
 
1919
- const methods = { get };
1644
+ /***/ 7051
1645
+ (module) {
1920
1646
 
1921
- module.exports = createInstance( clientProvider.bind( null, SSMClient ), methods );
1647
+ module.exports = t => t * 1000;
1922
1648
 
1923
1649
 
1924
- /***/ }),
1650
+ /***/ },
1925
1651
 
1926
- /***/ 5892:
1927
- /***/ ((module) => {
1652
+ /***/ 44
1653
+ (module, __unused_webpack_exports, __webpack_require__) {
1928
1654
 
1929
- "use strict";
1930
- module.exports = require("@aws-sdk/client-lambda");
1655
+ const { LambdaApi } = __webpack_require__( 2705 );
1656
+ const array = __webpack_require__( 8278 );
1657
+ const aws = __webpack_require__( 4870 );
1658
+ const epoch = __webpack_require__( 3830 );
1659
+ const math = __webpack_require__( 943 );
1660
+ const object = __webpack_require__( 5762 );
1661
+ const redis = __webpack_require__( 4528 );
1662
+ const string = __webpack_require__( 268 );
1663
+ const utils = __webpack_require__( 6878 );
1931
1664
 
1932
- /***/ }),
1665
+ module.exports = {
1666
+ array,
1667
+ aws,
1668
+ epoch,
1669
+ LambdaApi,
1670
+ math,
1671
+ object,
1672
+ redis,
1673
+ string,
1674
+ utils
1675
+ };
1933
1676
 
1934
- /***/ 5894:
1935
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1936
1677
 
1937
- const { InvokeCommand } = __webpack_require__( 5892 );
1938
- const AWSLambdaError = __webpack_require__( 468 );
1678
+ /***/ },
1939
1679
 
1940
- module.exports = async ( client, name, payload = {}, type = 'RequestResponse' ) => {
1941
- const response = await client.send( new InvokeCommand( {
1942
- FunctionName: name,
1943
- InvocationType: type,
1944
- Payload: Buffer.from( JSON.stringify( payload ) )
1945
- } ) );
1680
+ /***/ 3119
1681
+ (module, __unused_webpack_exports, __webpack_require__) {
1946
1682
 
1947
- if ( response.FunctionError ) {
1948
- throw new AWSLambdaError( response );
1683
+ const { snakelize, camelize } = __webpack_require__( 5762 );
1684
+ const charset = 'utf-8';
1685
+
1686
+ const transformFns = {
1687
+ camelcase: camelize,
1688
+ snakecase: snakelize
1689
+ };
1690
+
1691
+ module.exports = class ApiResponse {
1692
+ #headers = null;
1693
+ #statusCode = null;
1694
+ #transformFn = false;
1695
+ #isBase64Encoded = false;
1696
+ #body = '';
1697
+
1698
+ constructor( { headers = {}, transform } = {} ) {
1699
+ this.#transformFn = transformFns[transform] ?? ( v => v );
1700
+ this.#headers = Object.assign( {
1701
+ 'Cache-Control': 'no-store',
1702
+ 'Access-Control-Allow-Origin': '*'
1703
+ }, headers );
1949
1704
  }
1950
1705
 
1951
- if ( type !== 'RequestResponse' ) { return true; }
1706
+ setContent( statusCode, body, headers = {}, isBase64Encoded = false ) {
1707
+ this.#statusCode = statusCode;
1708
+ this.#isBase64Encoded = isBase64Encoded;
1709
+ if ( body?.length === 0 || [ null, undefined ].includes( body ) ) {
1710
+ this.#body = '';
1711
+ } else if ( typeof body === 'object' ) {
1712
+ this.#body = JSON.stringify( this.#transformFn( body ) );
1713
+ this.#headers['Content-Type'] = `application/json; charset=${charset}`;
1714
+ } else {
1715
+ this.#body = String( body );
1716
+ this.#headers['Content-Type'] = `text/plain; charset=${charset}`;
1717
+ }
1718
+ this.#headers['Content-Length'] = this.#body.length;
1719
+ Object.assign( this.#headers, headers ?? {} );
1720
+ return this;
1721
+ }
1952
1722
 
1953
- try {
1954
- return JSON.parse( Buffer.from( response.Payload ).toString() );
1955
- } catch {
1956
- return response.Payload;
1723
+ toJSON() {
1724
+ return {
1725
+ isBase64Encoded: this.#isBase64Encoded,
1726
+ statusCode: this.#statusCode,
1727
+ body: this.#body,
1728
+ headers: this.#headers
1729
+ };
1957
1730
  }
1958
1731
  };
1959
1732
 
1960
1733
 
1961
- /***/ }),
1734
+ /***/ },
1962
1735
 
1963
- /***/ 6030:
1964
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1736
+ /***/ 329
1737
+ (module, __unused_webpack_exports, __webpack_require__) {
1965
1738
 
1966
- const { QueryCommand } = __webpack_require__( 1671 );
1967
- const { camelize } = __webpack_require__( 5762 );
1968
- const parseItems = __webpack_require__( 7261 );
1739
+ const { camelize, snakelize } = __webpack_require__( 5762 );
1969
1740
 
1970
- const query = async ( client, queryString, { prevItems = [], recursive, paginationToken, maxRows, rawResponse } ) => {
1971
- const response = await client.send( new QueryCommand( { QueryString: queryString, NextToken: paginationToken, MaxRows: maxRows } ) );
1972
- if ( !recursive && rawResponse ) {
1973
- return response;
1974
- }
1741
+ const transformFns = {
1742
+ camelcase: camelize,
1743
+ snakecase: snakelize
1744
+ };
1975
1745
 
1976
- const nextToken = response.NextToken;
1977
- if ( nextToken && recursive ) {
1978
- return query( client, queryString, { prevItems: parseItems( response ), recursive, paginationToken: nextToken, maxRows } );
1746
+ const parseJson = content => {
1747
+ try {
1748
+ return JSON.parse( content );
1749
+ } catch {
1750
+ return content;
1979
1751
  }
1980
-
1981
- const items = prevItems.concat( parseItems( response ) );
1982
- return { nextToken, count: items.length, items, queryStatus: camelize( response.QueryStatus ) };
1983
1752
  };
1984
1753
 
1985
- module.exports = async ( client, queryString, { recursive = false, paginationToken = undefined, maxRows = undefined, rawResponse = false } = {} ) =>
1986
- query( client, queryString, { recursive, paginationToken, maxRows, rawResponse } );
1754
+ module.exports = class Event {
1755
+ #transformFn;
1756
+ authorizer;
1757
+ body;
1758
+ rawBody;
1759
+ headers;
1760
+ method;
1761
+ params;
1762
+ path;
1763
+ queryString;
1764
+ route;
1987
1765
 
1766
+ context = {};
1988
1767
 
1989
- /***/ }),
1768
+ constructor( { transform = false } = {} ) {
1769
+ this.#transformFn = transformFns[transform] ?? ( v => v );
1770
+ }
1990
1771
 
1991
- /***/ 6089:
1992
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1772
+ parseFromAwsEvent( awsEvent ) {
1773
+ this[`parseFromAwsEventV${awsEvent.version === '2.0' ? 2 : 1}`]( awsEvent );
1774
+ }
1993
1775
 
1994
- const calcMean = __webpack_require__( 4124 );
1776
+ parseFromAwsEventV1( awsEvent ) {
1777
+ const {
1778
+ body,
1779
+ path,
1780
+ resource,
1781
+ httpMethod,
1782
+ requestContext,
1783
+ pathParameters,
1784
+ headers,
1785
+ multiValueHeaders,
1786
+ queryStringParameters,
1787
+ multiValueQueryStringParameters: multiValueQueryString,
1788
+ isBase64Encoded
1789
+ } = awsEvent;
1995
1790
 
1996
- module.exports = values => {
1997
- if ( values.length < 2 ) { return NaN; }
1791
+ const unifiedHeaders = {
1792
+ ...headers,
1793
+ ...Object.fromEntries( Object.entries( multiValueHeaders ?? {} ).map( ( [ k, v ] ) => [ k, Array.isArray( v ) ? v.join( ',' ) : k ] ) )
1794
+ };
1998
1795
 
1999
- const mean = calcMean( values );
2000
- const squareDiffs = values.map( value => Math.pow( value - mean, 2 ) );
2001
- const avgSquareDiff = squareDiffs.reduce( ( sum, v ) => sum + v, 0 ) / ( values.length - 1 );
2002
- return Math.sqrt( avgSquareDiff );
2003
- };
1796
+ const unifiedQueryString = {
1797
+ ...queryStringParameters,
1798
+ ...Object.fromEntries( Object.entries( multiValueQueryString ?? {} ).map( ( [ k, v ] ) => [ k, Array.isArray( v ) ? v.join( ',' ) : k ] ) )
1799
+ };
2004
1800
 
1801
+ this.authorizer = requestContext?.authorizer;
1802
+ this.rawBody = body ?? null;
1803
+ this.body = body ? this.#transformFn( parseJson( body ) ) : null;
1804
+ this.headers = unifiedHeaders ?? {};
1805
+ this.method = httpMethod;
1806
+ this.params = this.#transformFn( pathParameters ) ?? {};
1807
+ this.path = path;
1808
+ this.queryString = this.#transformFn( unifiedQueryString ) ?? {};
1809
+ this.route = resource;
1810
+ this.isBase64Encoded = isBase64Encoded ?? false;
1811
+ }
2005
1812
 
2006
- /***/ }),
1813
+ parseFromAwsEventV2( awsEvent ) {
1814
+ const {
1815
+ body,
1816
+ routeKey,
1817
+ requestContext,
1818
+ pathParameters,
1819
+ headers,
1820
+ queryStringParameters,
1821
+ isBase64Encoded
1822
+ } = awsEvent;
2007
1823
 
2008
- /***/ 6451:
2009
- /***/ ((module) => {
1824
+ const { http: { method, path } } = requestContext;
2010
1825
 
2011
- module.exports = ( obj, props ) => Object.fromEntries( Object.entries( obj ).filter( ( [ k ] ) => props.includes( k ) ) );
1826
+ this.authorizer = requestContext?.authorizer;
1827
+ this.rawBody = body ?? null;
1828
+ this.body = body ? this.#transformFn( parseJson( body ) ) : null;
1829
+ this.headers = headers ?? {};
1830
+ this.method = method;
1831
+ this.params = this.#transformFn( pathParameters ) ?? {};
1832
+ this.path = path;
1833
+ this.queryString = this.#transformFn( queryStringParameters ) ?? {};
1834
+ this.route = routeKey?.split( ' ' )[1].replace( /\/$/, '' );
1835
+ this.isBase64Encoded = isBase64Encoded ?? false;
1836
+ }
1837
+ };
2012
1838
 
2013
1839
 
2014
- /***/ }),
1840
+ /***/ },
2015
1841
 
2016
- /***/ 6635:
2017
- /***/ ((module) => {
1842
+ /***/ 3109
1843
+ (module, __unused_webpack_exports, __webpack_require__) {
2018
1844
 
2019
- module.exports = t => t * 60 * 1000;
1845
+ const validators = __webpack_require__( 8994 );
2020
1846
 
1847
+ module.exports = class Handler {
1848
+ #method;
1849
+ #fn;
1850
+ #route;
1851
+ #routeIncludes;
1852
+ #routeNotIncludes;
1853
+ #routeMatches;
1854
+ #path;
1855
+ #pathIncludes;
1856
+ #pathNotIncludes;
1857
+ #pathMatches;
2021
1858
 
2022
- /***/ }),
1859
+ constructor( { method, fn, ...matchers } ) {
1860
+ validators.httpMethod( method );
1861
+ validators.function( fn );
1862
+ validators.matcherRoute( matchers.route );
1863
+ validators.matcherRouteIncludes( matchers.routeIncludes );
1864
+ validators.matcherRouteNotIncludes( matchers.routeNotIncludes );
1865
+ validators.matcherRouteMatch( matchers.routeMatch );
1866
+ validators.matcherPath( matchers.path );
1867
+ validators.matcherPathIncludes( matchers.pathIncludes );
1868
+ validators.matcherPathNotIncludes( matchers.pathNotIncludes );
1869
+ validators.matcherPathMatch( matchers.pathMatch );
2023
1870
 
2024
- /***/ 6720:
2025
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1871
+ this.#method = method;
1872
+ this.#fn = fn;
1873
+ this.#route = matchers.route;
1874
+ this.#routeIncludes = matchers.routeIncludes;
1875
+ this.#routeNotIncludes = matchers.routeNotIncludes;
1876
+ this.#routeMatches = matchers.routeMatches;
1877
+ this.#path = matchers.path;
1878
+ this.#pathIncludes = matchers.pathIncludes;
1879
+ this.#pathNotIncludes = matchers.pathNotIncludes;
1880
+ this.#pathMatches = matchers.pathMatches;
1881
+ }
2026
1882
 
2027
- const { SendMessageCommand } = __webpack_require__( 1976 );
2028
- const sanitizeSqs = __webpack_require__( 8175 );
1883
+ match( event ) {
1884
+ if ( this.#method !== event.method ) {
1885
+ return false;
1886
+ }
1887
+ if ( this.#route ) {
1888
+ return this.#route === event.route;
1889
+ }
1890
+ if ( this.#path ) {
1891
+ return this.#path === event.path;
1892
+ }
1893
+ if ( this.#routeIncludes && !event.route.includes( this.#routeIncludes ) ) {
1894
+ return false;
1895
+ }
1896
+ if ( this.#routeNotIncludes && event.route.includes( this.#routeNotIncludes ) ) {
1897
+ return false;
1898
+ }
1899
+ if ( this.#routeMatches && !this.#routeMatches.test( event.route ) ) {
1900
+ return false;
1901
+ }
1902
+ if ( this.#pathIncludes && !event.path.includes( this.#pathIncludes ) ) {
1903
+ return false;
1904
+ }
1905
+ if ( this.#pathNotIncludes && event.path.includes( this.#pathNotIncludes ) ) {
1906
+ return false;
1907
+ }
1908
+ if ( this.#pathMatches && !this.#pathMatches.test( event.path ) ) {
1909
+ return false;
1910
+ }
1911
+ return true;
1912
+ }
2029
1913
 
2030
- module.exports = async ( client, queue, body, args ) => {
2031
- const response = await client.send( new SendMessageCommand( {
2032
- ...args,
2033
- MessageBody: sanitizeSqs( typeof body === 'string' ? body : JSON.stringify( body ) ),
2034
- QueueUrl: queue
2035
- } ) );
2036
- return response.MessageId;
1914
+ get fn() { return this.#fn; }
2037
1915
  };
2038
1916
 
2039
1917
 
2040
- /***/ }),
2041
-
2042
- /***/ 6777:
2043
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2044
-
2045
- const { DeleteCommand } = __webpack_require__( 3489 );
2046
-
2047
- module.exports = async ( client, tableName, key ) => {
2048
- const { Attributes: item } = await client.send( new DeleteCommand( {
2049
- ReturnValues: 'ALL_OLD',
2050
- TableName: tableName,
2051
- Key: key
2052
- } ) );
2053
- return item;
2054
- };
1918
+ /***/ },
2055
1919
 
1920
+ /***/ 798
1921
+ (module, __unused_webpack_exports, __webpack_require__) {
2056
1922
 
2057
- /***/ }),
1923
+ const validators = __webpack_require__( 8994 );
2058
1924
 
2059
- /***/ 6878:
2060
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1925
+ module.exports = class Hook {
1926
+ #fn;
2061
1927
 
2062
- const retryOnError = __webpack_require__( 4243 );
2063
- const sleep = __webpack_require__( 2445 );
2064
- const Timer = __webpack_require__( 9651 );
2065
- const untarJsonGz = __webpack_require__( 8233 );
1928
+ constructor( { fn } ) {
1929
+ validators.function( fn );
1930
+ this.#fn = fn;
1931
+ }
2066
1932
 
2067
- module.exports = {
2068
- retryOnError,
2069
- sleep,
2070
- Timer,
2071
- untarJsonGz
1933
+ get fn() { return this.#fn; }
2072
1934
  };
2073
1935
 
2074
1936
 
2075
- /***/ }),
1937
+ /***/ },
2076
1938
 
2077
- /***/ 6961:
2078
- /***/ ((module) => {
2079
-
2080
- module.exports = t => t * 60 * 60 * 1000;
2081
-
2082
-
2083
- /***/ }),
2084
-
2085
- /***/ 6982:
2086
- /***/ ((module) => {
2087
-
2088
- "use strict";
2089
- module.exports = require("crypto");
1939
+ /***/ 2705
1940
+ (module, __unused_webpack_exports, __webpack_require__) {
2090
1941
 
2091
- /***/ }),
1942
+ const LambdaApi = __webpack_require__( 321 );
2092
1943
 
2093
- /***/ 7051:
2094
- /***/ ((module) => {
1944
+ module.exports = { LambdaApi };
2095
1945
 
2096
- module.exports = t => t * 1000;
2097
1946
 
1947
+ /***/ },
2098
1948
 
2099
- /***/ }),
1949
+ /***/ 321
1950
+ (module, __unused_webpack_exports, __webpack_require__) {
2100
1951
 
2101
- /***/ 7261:
2102
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1952
+ const validators = __webpack_require__( 8994 );
1953
+ const ApiResponse = __webpack_require__( 3119 );
1954
+ const Event = __webpack_require__( 329 );
1955
+ const Handler = __webpack_require__( 3109 );
1956
+ const Hook = __webpack_require__( 798 );
1957
+ const UserResponse = __webpack_require__( 8282 );
1958
+ const Text = __webpack_require__( 9760 );
2103
1959
 
2104
- // https://docs.aws.amazon.com/timestream/latest/developerguide/API_query_Type.html
2105
- // https://docs.aws.amazon.com/timestream/latest/developerguide/supported-data-types.html
1960
+ module.exports = class LambdaApi {
1961
+ #apiResponse = null;
1962
+ #handlers = [];
1963
+ #errorResponses = [];
1964
+ #beforeHooks = [];
1965
+ #afterHooks = [];
1966
+ #transformRequest = [];
2106
1967
 
2107
- const { ScalarType } = __webpack_require__( 1671 );
1968
+ /**
1969
+ * Creates a new Lambda Api
1970
+ *
1971
+ * @param {Object} headers Any headers you want to be included in all responses
1972
+ */
1973
+ constructor( { headers = {}, transformRequest = false, transformResponse = false } = {} ) {
1974
+ validators.transformRequest( transformRequest );
1975
+ validators.transformResponse( transformResponse );
2108
1976
 
2109
- const parseBigInt = value => {
2110
- const asInt = parseInt( value, 10 );
2111
- return asInt <= Number.MAX_SAFE_INTEGER && asInt >= Number.MIN_SAFE_INTEGER ? asInt : value;
2112
- };
1977
+ this.#transformRequest = transformRequest;
1978
+ this.#apiResponse = new ApiResponse( { headers, transform: transformResponse } );
1979
+ }
2113
1980
 
2114
- const parseScalarValue = ( type, value ) => {
2115
- switch ( type ) {
2116
- case ScalarType.BOOLEAN:
2117
- return value === 'true';
2118
- case ScalarType.DOUBLE:
2119
- return parseFloat( value );
2120
- case ScalarType.TIMESTAMP:
2121
- return new Date( `${value.replace( ' ', 'T' )}Z` );
2122
- case ScalarType.INTEGER:
2123
- return parseInt( value, 10 );
2124
- case ScalarType.UNKNOWN: // is NULL
2125
- return null;
2126
- case ScalarType.BIGINT:
2127
- return parseBigInt( value );
2128
- case ScalarType.VARCHAR:
2129
- case ScalarType.DATE:
2130
- case ScalarType.TIME:
2131
- case ScalarType.INTERVAL_DAY_TO_SECOND:
2132
- case ScalarType.INTERVAL_YEAR_TO_MONTH:
2133
- default:
2134
- return value;
1981
+ /**
1982
+ * Register a function that will run before the matching route (only if matches)
1983
+ *
1984
+ * @param {Object} args
1985
+ * @param {function} args.fn A function
1986
+ */
1987
+ addBeforeHook( { fn } = {} ) {
1988
+ this.#beforeHooks.push( new Hook( { fn } ) );
2135
1989
  }
2136
- };
2137
1990
 
2138
- const parseValue = ( typeInfo, datum ) => {
2139
- // value might be null
2140
- if ( datum['NullValue'] === true ) {
2141
- return null;
1991
+ /**
1992
+ * Register a function that will run after the matching route (only if matches)
1993
+ *
1994
+ * @param {Object} args
1995
+ * @param {function} args.fn A function
1996
+ */
1997
+ addAfterHook( { fn } = {} ) {
1998
+ this.#afterHooks.push( new Hook( { fn } ) );
2142
1999
  }
2143
2000
 
2144
- // or a time series
2145
- if ( Object.hasOwn( typeInfo, 'TimeSeriesMeasureValueColumnInfo' ) ) {
2146
- return datum.TimeSeriesValue.map( v => ( {
2147
- time: new Date( v.Time ),
2148
- value: parseValue( typeInfo.TimeSeriesMeasureValueColumnInfo.Type, v.Value )
2149
- } ) );
2001
+ /**
2002
+ * Register a handler for a given request method and optionally a path
2003
+ *
2004
+ * @param {Object} args
2005
+ * @param {string} args.method The method to match this handler
2006
+ * @param {function} args.fn The handler function
2007
+ * @param {string} [args.route] A route to match this handler
2008
+ * @param {string} [args.routeIncludes] A part of the route to match this handler
2009
+ * @param {string} [args.routeNotIncludes] A part of the route to not match this handler
2010
+ * @param {RegExp} [args.routeMatches] A RegExp to match the route
2011
+ * @param {string} [args.path] A path to match this handler
2012
+ * @param {string} [args.pathIncludes] A part of the path to match this handler
2013
+ * @param {string} [args.pathNotIncludes] A part of the path to not match this handler
2014
+ * @param {RegExp} [args.pathMatches] A RegExp to match the path
2015
+ */
2016
+ addHandler( { method, fn, ...matchers } = {} ) {
2017
+ this.#handlers.push( new Handler( { method, fn, ...matchers } ) );
2150
2018
  }
2151
2019
 
2152
- // maybe an array
2153
- if ( Object.hasOwn( typeInfo, 'ArrayColumnInfo' ) ) {
2154
- return datum.ArrayValue.map( v => parseValue( typeInfo.ArrayColumnInfo.Type, v ) );
2020
+ /**
2021
+ * Register an automatic error code response for given error class (constructor name)
2022
+ *
2023
+ * @param {Object} args
2024
+ * @param {string} args.code The HTTP status code to return
2025
+ * @param {class} args.errorType The error class
2026
+ * @param {string} [args.message=null] Optional message to return for the status code, if not present will default to Error.message
2027
+ * @param {message} [args.errorType] And optional message to display
2028
+ */
2029
+ addErrorHandler( { errorType, code, message = null } = {} ) {
2030
+ validators.statusCode( code );
2031
+ validators.errorType( errorType );
2032
+ this.#errorResponses.push( { errorType, code, message } );
2155
2033
  }
2156
2034
 
2157
- // or even a row
2158
- if ( Object.hasOwn( typeInfo, 'RowColumnInfo' ) ) {
2159
- const rowColumnInfo = typeInfo.RowColumnInfo;
2160
- return datum.RowValue.Data.reduce( ( object, value, index ) => {
2161
- const { Name: name, Type: typeInfo } = rowColumnInfo[index];
2162
- return Object.assign( object, { [name]: parseValue( typeInfo, value ) } );
2163
- }, {} );
2164
- }
2035
+ /**
2036
+ * Init the flow using a given AWS Lambda APIGateway event (v2 syntax)
2037
+ *
2038
+ * @param {Object} ApiGatewayPayload The raw API Gateway event
2039
+ * @returns {Object} The http response with status, body and headers
2040
+ */
2041
+ async process( awsEvent ) {
2042
+ const event = new Event( { transform: this.#transformRequest } );
2043
+ event.parseFromAwsEvent( awsEvent );
2165
2044
 
2166
- // if none, it is scalar
2167
- return parseScalarValue( typeInfo.ScalarType, datum['ScalarValue'] );
2168
- };
2045
+ if ( event.method === 'HEAD' ) {
2046
+ return this.#apiResponse.setContent( 204 ).toJSON();
2047
+ }
2169
2048
 
2170
- module.exports = response => {
2171
- const { ColumnInfo: colInfo, Rows: rows } = response;
2172
- return rows.map( row =>
2173
- row.Data.reduce( ( entry, value, index ) => {
2174
- const { Name: name, Type: typeInfo } = colInfo[index];
2175
- return Object.assign( entry, { [name]: parseValue( typeInfo, value ) } );
2176
- }, { } )
2177
- );
2178
- };
2049
+ const handler = this.#handlers.find( h => h.match( event ) );
2050
+ if ( !handler ) {
2051
+ return this.#apiResponse.setContent( 405, Text.ERROR_405 ).toJSON();
2052
+ }
2179
2053
 
2054
+ const chain = [
2055
+ ...this.#beforeHooks.map( b => b.fn ),
2056
+ async ev => {
2057
+ const result = await handler.fn( ev );
2058
+ const response = new UserResponse( result );
2059
+ this.#apiResponse.setContent( ...response.values ).toJSON();
2060
+ },
2061
+ ...this.#afterHooks.map( a => a.fn )
2062
+ ];
2180
2063
 
2181
- /***/ }),
2064
+ try {
2065
+ for ( const fn of chain ) {
2066
+ await fn( event );
2067
+ }
2068
+ return this.#apiResponse.toJSON();
2182
2069
 
2183
- /***/ 7337:
2184
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2070
+ } catch ( error ) {
2071
+ console.error( 'Lambda API Error', { error, event } );
2185
2072
 
2186
- const { GetQueryExecutionCommand, GetQueryResultsCommand } = __webpack_require__( 3744 );
2187
- const parseResults = __webpack_require__( 834 );
2188
- const pollingDelay = __webpack_require__( 4127 );
2073
+ const response = this.#errorResponses.find( e => error instanceof e.errorType );
2074
+ if ( response ) {
2075
+ return this.#apiResponse.setContent( response.code, response.message ?? error.message ).toJSON();
2076
+ }
2077
+ return this.#apiResponse.setContent( 500, Text.ERROR_500 ).toJSON();
2078
+ }
2079
+ }
2080
+ };
2189
2081
 
2190
- const sleep = t => new Promise( r => setTimeout( () => r(), t ) );
2191
2082
 
2192
- const getQueryResults = async ( { client, queryExecutionId, maxResults, token } ) => {
2193
- const { NextToken: nextToken, ResultSet } = await client.send( new GetQueryResultsCommand( {
2194
- ...{ QueryExecutionId: queryExecutionId },
2195
- ...( maxResults ? { MaxResults: maxResults } : {} ),
2196
- ...( token ? { NextToken: token } : {} )
2197
- } ) );
2083
+ /***/ },
2198
2084
 
2199
- return { nextToken, items: parseResults( ResultSet ) };
2200
- };
2201
- const getQueryResultsRecursive = async ( { client, queryExecutionId, token } ) => {
2202
- const { nextToken, items } = await getQueryResults( { client, queryExecutionId, token } );
2085
+ /***/ 3446
2086
+ (module) {
2203
2087
 
2204
- if ( nextToken ) {
2205
- return { items: items.concat( ( await getQueryResultsRecursive( { client, queryExecutionId, token: nextToken } ) ).items ) };
2206
- }
2207
- return { items };
2208
- };
2088
+ module.exports = class LambdaApiValidationError extends Error {};
2209
2089
 
2210
- /**
2211
- * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/athena/command/GetQueryResultsCommand/
2212
- * { client, recursive, queryExecutionId, maxResults, paginationToken }
2213
- */
2214
- const getResults = async ( { client, recursive, queryExecutionId, token, maxResults } ) => {
2215
- const { QueryExecution: { Status: status } } = await client.send( new GetQueryExecutionCommand( { QueryExecutionId: queryExecutionId } ) );
2216
2090
 
2217
- if ( status.State === 'FAILED' ) {
2218
- throw new Error( status.AthenaError?.ErrorMessage ?? status.StateChangeReason );
2219
- }
2091
+ /***/ },
2220
2092
 
2221
- if ( status.State === 'SUCCEEDED' ) {
2222
- const fn = recursive ? getQueryResultsRecursive : getQueryResults;
2223
- return fn( { client, recursive, queryExecutionId, token, maxResults } );
2224
- }
2093
+ /***/ 9760
2094
+ (module) {
2225
2095
 
2226
- // sleep an try again
2227
- await sleep( pollingDelay );
2228
- return getResults( { client, recursive, queryExecutionId, token, maxResults } );
2096
+ module.exports = {
2097
+ ERROR_500: 'Internal Server Error',
2098
+ ERROR_405: 'Method Not Allowed',
2099
+ INVALID_ERROR_TYPE: 'Argument "errorType" must be a constructor Function',
2100
+ INVALID_FN: 'Argument "fn" must be of type function',
2101
+ INVALID_METHOD: 'Argument "method" must be one of the default HTTP methods',
2102
+ INVALID_STATUS_CODE: 'Argument "statusCode" must be valid HTTP Status Code',
2103
+ INVALID_TRANSFORM_REQUEST: 'Argument "transformRequest" must be either "camelize", "snakelize", false or null',
2104
+ INVALID_TRANSFORM_RESPONSE: 'Argument "transformResponse" must be either "camelize", "snakelize", false or null',
2105
+ INVALID_MATCHER_ROUTE: 'Argument "route" must be either undefined or an string with length greater than 0',
2106
+ INVALID_MATCHER_ROUTE_INCLUDES: 'Argument "routeIncludes" must be either undefined or an string with length greater than 0',
2107
+ INVALID_MATCHER_ROUTE_NOT_INCLUDES: 'Argument "routeNotIncludes" must be either undefined or an string with length greater than 0',
2108
+ INVALID_MATCHER_ROUTE_MATCH: 'Argument "routeMatch" must be either undefined or type RegExp',
2109
+ INVALID_MATCHER_PATH: 'Argument "path" must be either undefined or an string with length greater than 0',
2110
+ INVALID_MATCHER_PATH_INCLUDES: 'Argument "pathIncludes" must be either undefined or an string with length greater than 0',
2111
+ INVALID_MATCHER_PATH_NOT_INCLUDES: 'Argument "pathNotIncludes" must be either undefined or an string with length greater than 0',
2112
+ INVALID_MATCHER_PATH_MATCH: 'Argument "pathMatch" must be either undefined or type RegExp',
2113
+ INVALID_USER_RESPONSE: 'Function return must be a number, a string, an array (where p=0 is a number) or an object (where .statusCode is a number)'
2229
2114
  };
2230
2115
 
2231
- module.exports = getResults;
2232
2116
 
2117
+ /***/ },
2233
2118
 
2234
- /***/ }),
2119
+ /***/ 8282
2120
+ (module, __unused_webpack_exports, __webpack_require__) {
2235
2121
 
2236
- /***/ 7416:
2237
- /***/ ((module) => {
2122
+ const validators = __webpack_require__( 8994 );
2123
+ const LambdaApiValidationError = __webpack_require__( 3446 );
2124
+ const Text = __webpack_require__( 9760 );
2238
2125
 
2239
- module.exports = v => Math.ceil( v / 1000 );
2126
+ module.exports = class UserResponse {
2127
+ constructor( args ) {
2128
+ if ( args === undefined ) {
2129
+ this.values = [ 204 ];
2130
+ } else if ( typeof args === 'string' && args.length === 0 ) {
2131
+ this.values = [ 204 ];
2240
2132
 
2133
+ } else if ( typeof args === 'string' && args.length > 0 ) {
2134
+ this.values = [ 200, args ];
2241
2135
 
2242
- /***/ }),
2136
+ } else if ( typeof args === 'number' ) {
2137
+ validators.statusCode( args );
2138
+ this.values = [ args ];
2243
2139
 
2244
- /***/ 7493:
2245
- /***/ ((module) => {
2140
+ } else if ( Array.isArray( args ) ) {
2141
+ validators.statusCode( args[0] );
2142
+ this.values = args;
2246
2143
 
2247
- "use strict";
2248
- module.exports = require("@aws-sdk/client-cloudwatch-logs");
2144
+ } else if ( args.statusCode ) {
2145
+ validators.statusCode( args.statusCode );
2146
+ this.values = [ args.statusCode, args.body, args.headers, args.isBase64Encoded ];
2249
2147
 
2250
- /***/ }),
2148
+ } else if ( [ undefined, null ].includes( args ) ) {
2149
+ this.values = [ 200 ];
2150
+ } else {
2151
+ throw new LambdaApiValidationError( Text.INVALID_USER_RESPONSE );
2152
+ }
2153
+ }
2154
+ };
2251
2155
 
2252
- /***/ 7572:
2253
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2254
2156
 
2255
- const isSerializable = __webpack_require__( 8864 );
2256
- const snakelize = __webpack_require__( 3402 );
2157
+ /***/ },
2257
2158
 
2258
- const change = ( obj, keepAllCaps ) =>
2259
- !isSerializable( obj ) ? obj : Object.entries( obj ).reduce( ( transformed, [ key, value ] ) => {
2260
- delete transformed[key];
2261
- transformed[snakelize( key, { keepAllCaps } )] = typeof value === 'object' ? change( value, keepAllCaps ) : value;
2262
- return transformed;
2263
- }, Array.isArray( obj ) ? [] : {} );
2159
+ /***/ 8994
2160
+ (module, __unused_webpack_exports, __webpack_require__) {
2264
2161
 
2265
- module.exports = ( obj, { keepAllCaps = false } = {} ) => change( obj, keepAllCaps );
2162
+ const Text = __webpack_require__( 9760 );
2163
+ const LambdaApiValidationError = __webpack_require__( 3446 );
2266
2164
 
2165
+ const evaluate = ( condition, errorMessage ) => {
2166
+ if ( !condition ) { throw new LambdaApiValidationError( errorMessage ); }
2167
+ };
2267
2168
 
2268
- /***/ }),
2169
+ const isConstructor = v => {
2170
+ try {
2171
+ return !!Reflect.construct( new Proxy( v, {} ), [] );
2172
+ } catch {
2173
+ return false;
2174
+ }
2175
+ };
2269
2176
 
2270
- /***/ 7651:
2271
- /***/ ((module) => {
2177
+ module.exports = {
2178
+ errorType: v => evaluate( isConstructor( v ), Text.INVALID_ERROR_TYPE ),
2179
+ function: v => evaluate( typeof v === 'function', Text.INVALID_FN ),
2180
+ httpMethod: v => evaluate( [ 'DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT' ].includes( v ), Text.INVALID_METHOD ),
2181
+ matcherPath: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_PATH ),
2182
+ matcherPathIncludes: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_PATH_INCLUDES ),
2183
+ matcherPathMatch: v => evaluate( v === undefined || v?.constructor?.name === RegExp.name, Text.INVALID_MATCHER_PATH_MATCH ),
2184
+ matcherPathNotIncludes: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_PATH_NOT_INCLUDES ),
2185
+ matcherRoute: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_ROUTE ),
2186
+ matcherRouteIncludes: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_ROUTE_INCLUDES ),
2187
+ matcherRouteMatch: v => evaluate( v === undefined || v?.constructor?.name === RegExp.name, Text.INVALID_MATCHER_ROUTE_MATCH ),
2188
+ matcherRouteNotIncludes: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_ROUTE_NOT_INCLUDES ),
2189
+ statusCode: v => evaluate( typeof v === 'number' && /^[1-5]\d\d$/.test( String( v ) ), Text.INVALID_STATUS_CODE ),
2190
+ transformRequest: v => evaluate( [ 'camelcase', 'snakecase', null, false ].includes( v ), Text.INVALID_TRANSFORM_REQUEST ),
2191
+ transformResponse: v => evaluate( [ 'camelcase', 'snakecase', null, false ].includes( v ), Text.INVALID_TRANSFORM_RESPONSE )
2192
+ };
2272
2193
 
2273
- "use strict";
2274
- module.exports = require("@aws-sdk/client-sns");
2275
2194
 
2276
- /***/ }),
2195
+ /***/ },
2277
2196
 
2278
- /***/ 8080:
2279
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2197
+ /***/ 4124
2198
+ (module) {
2280
2199
 
2281
- const { PublishCommand } = __webpack_require__( 7651 );
2200
+ module.exports = values => values.reduce( ( sum, value ) => sum + value, 0 ) / values.length;
2282
2201
 
2283
- module.exports = async ( client, topic, message, args = {} ) => {
2284
- const response = await client.send( new PublishCommand( {
2285
- ...args,
2286
- TopicArn: topic,
2287
- Message: typeof message === 'string' ? message : JSON.stringify( message )
2288
- } ) );
2289
- return response.MessageId;
2290
- };
2291
2202
 
2203
+ /***/ },
2292
2204
 
2293
- /***/ }),
2205
+ /***/ 3187
2206
+ (module) {
2294
2207
 
2295
- /***/ 8119:
2296
- /***/ ((module) => {
2208
+ module.exports = values => {
2209
+ //Sort bug: https://www.tutorialrepublic.com/faq/how-to-sort-an-array-of-integers-correctly-in-javascript.php
2210
+ const sorted = values.slice().sort( ( a, b ) => a - b );
2211
+ const evenArray = values.length % 2 === 0;
2212
+ const midIndex = Math.floor( values.length / 2 );
2213
+ return evenArray ? ( sorted[midIndex - 1] + sorted[midIndex] ) / 2 : sorted[midIndex];
2214
+ };
2297
2215
 
2298
- module.exports = t => t * 30 * 24 * 60 * 60 * 1000;
2299
2216
 
2217
+ /***/ },
2300
2218
 
2301
- /***/ }),
2219
+ /***/ 4692
2220
+ (module, __unused_webpack_exports, __webpack_require__) {
2302
2221
 
2303
- /***/ 8175:
2304
- /***/ ((module) => {
2222
+ const calcMedian = __webpack_require__( 3187 );
2305
2223
 
2306
- /*
2307
- References:
2308
- - https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_SendMessage.html
2309
- - https://stackoverflow.com/questions/58809098/remove-invalid-characters-from-message-sent-to-aws-amazon-sqs
2310
- */
2311
- module.exports = v => v?.replace( /[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/ug, '' ) // eslint-disable-line
2224
+ module.exports = pop => {
2225
+ const center = calcMedian( pop );
2226
+ return calcMedian( pop.map( v => Math.abs( v - center ) ) );
2227
+ };
2312
2228
 
2313
2229
 
2314
- /***/ }),
2230
+ /***/ },
2315
2231
 
2316
- /***/ 8233:
2317
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2232
+ /***/ 2736
2233
+ (module, __unused_webpack_exports, __webpack_require__) {
2318
2234
 
2319
- const { unzipSync } = __webpack_require__( 3106 );
2235
+ const calcMean = __webpack_require__( 4124 );
2320
2236
 
2321
- const firstIndexOf = ( c, ...vars ) => Math.min( ...vars.map( v => c.indexOf( v ) ).filter( n => n > -1 ) );
2322
- const lastIndexOf = ( c, ...vars ) => Math.max( ...vars.map( v => c.lastIndexOf( v ) ) );
2237
+ module.exports = values => {
2238
+ const mean = calcMean( values );
2239
+ const squareDiffs = values.map( value => Math.pow( value - mean, 2 ) );
2240
+ const avgSquareDiff = calcMean( squareDiffs );
2241
+ return Math.sqrt( avgSquareDiff );
2242
+ };
2323
2243
 
2324
- /**
2325
- * Decompress JSON
2326
- *
2327
- * Reads a gzipped tarball (.tar.gz)
2328
- * 1. Unzip it
2329
- * 2. Convert all to utf-8
2330
- * 3. Split files using the \0star separator
2331
- * 4. Trim files until JSON markup start/end ({})
2332
- * 5. JSON parse
2333
- *
2334
- * Enjoy this 100% native tarball decompression!
2335
- */
2336
- module.exports = raw =>
2337
- unzipSync( raw )
2338
- .toString( 'utf-8' )
2339
- .split( '\0ustar' )
2340
- .slice( 1 )
2341
- .map( c =>
2342
- JSON.parse( c.substring( firstIndexOf( c, '{', '[' ), lastIndexOf( c, '}', ']' ) + 1 ) )
2343
- );
2344
2244
 
2245
+ /***/ },
2345
2246
 
2346
- /***/ }),
2247
+ /***/ 6089
2248
+ (module, __unused_webpack_exports, __webpack_require__) {
2347
2249
 
2348
- /***/ 8248:
2349
- /***/ ((module) => {
2250
+ const calcMean = __webpack_require__( 4124 );
2350
2251
 
2351
- "use strict";
2352
- module.exports = require("@aws-sdk/client-timestream-write");
2252
+ module.exports = values => {
2253
+ if ( values.length < 2 ) { return NaN; }
2353
2254
 
2354
- /***/ }),
2255
+ const mean = calcMean( values );
2256
+ const squareDiffs = values.map( value => Math.pow( value - mean, 2 ) );
2257
+ const avgSquareDiff = squareDiffs.reduce( ( sum, v ) => sum + v, 0 ) / ( values.length - 1 );
2258
+ return Math.sqrt( avgSquareDiff );
2259
+ };
2355
2260
 
2356
- /***/ 8256:
2357
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2358
2261
 
2359
- const isSerializable = __webpack_require__( 8864 );
2360
- const camelize = __webpack_require__( 3914 );
2262
+ /***/ },
2361
2263
 
2362
- const change = ( obj, keepAllCaps ) =>
2363
- !isSerializable( obj ) ? obj : Object.entries( obj ).reduce( ( transformed, [ key, value ] ) => {
2364
- delete transformed[key];
2365
- transformed[camelize( key, { keepAllCaps } )] = typeof value === 'object' ? change( value, keepAllCaps ) : value;
2366
- return transformed;
2367
- }, Array.isArray( obj ) ? [] : {} );
2264
+ /***/ 4110
2265
+ (module) {
2368
2266
 
2369
- module.exports = ( obj, { keepAllCaps = false } = {} ) => change( obj, keepAllCaps );
2267
+ module.exports = ( sample, mean, stdDev ) => stdDev === 0 ? NaN : ( sample - mean ) / stdDev;
2370
2268
 
2371
2269
 
2372
- /***/ }),
2270
+ /***/ },
2373
2271
 
2374
- /***/ 8278:
2375
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2272
+ /***/ 943
2273
+ (module, __unused_webpack_exports, __webpack_require__) {
2376
2274
 
2377
- const joinUnique = __webpack_require__( 2836 );
2378
- const joinUniqueCustom = __webpack_require__( 536 );
2379
- const splitBatches = __webpack_require__( 4821 );
2275
+ const calcMean = __webpack_require__( 4124 );
2276
+ const calcMedian = __webpack_require__( 3187 );
2277
+ const calcMedianAbsDev = __webpack_require__( 4692 );
2278
+ const calcStdDevPopulation = __webpack_require__( 2736 );
2279
+ const calcStdDevSample = __webpack_require__( 6089 );
2280
+ const calcZScore = __webpack_require__( 4110 );
2281
+ const roundGaussian = __webpack_require__( 637 );
2282
+ const roundStandard = __webpack_require__( 115 );
2380
2283
 
2381
2284
  module.exports = {
2382
- joinUnique,
2383
- joinUniqueCustom,
2384
- splitBatches
2285
+ calcMean,
2286
+ calcMedian,
2287
+ calcMedianAbsDev,
2288
+ calcStdDevPopulation,
2289
+ calcStdDevSample,
2290
+ calcZScore,
2291
+ roundGaussian,
2292
+ roundStandard
2385
2293
  };
2386
2294
 
2387
2295
 
2388
- /***/ }),
2296
+ /***/ },
2389
2297
 
2390
- /***/ 8282:
2391
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2298
+ /***/ 637
2299
+ (module) {
2392
2300
 
2393
- const validators = __webpack_require__( 8994 );
2394
- const LambdaApiValidationError = __webpack_require__( 3446 );
2395
- const Text = __webpack_require__( 9760 );
2396
-
2397
- module.exports = class UserResponse {
2398
- constructor( args ) {
2399
- if ( args === undefined ) {
2400
- this.values = [ 204 ];
2401
- } else if ( typeof args === 'string' && args.length === 0 ) {
2402
- this.values = [ 204 ];
2403
-
2404
- } else if ( typeof args === 'string' && args.length > 0 ) {
2405
- this.values = [ 200, args ];
2301
+ module.exports = ( n, d = 2 ) => {
2302
+ if ( !isFinite( n ) || typeof n !== 'number' ) { return NaN; }
2406
2303
 
2407
- } else if ( typeof args === 'number' ) {
2408
- validators.statusCode( args );
2409
- this.values = [ args ];
2304
+ const m = Math.pow( 10, d );
2305
+ const num = +( n * m ).toFixed( 8 ); // Avoid rounding errors
2306
+ const i = Math.floor( num );
2307
+ const f = num - i;
2308
+ const e = 1e-8; // Allow for rounding errors in f
2309
+ const r = ( f > 0.5 - e && f < 0.5 + e ) ? // eslint-disable-line no-nested-ternary
2310
+ ( ( i % 2 === 0 ) ? i : i + 1 ) : Math.round( num );
2311
+ return r / m;
2312
+ };
2410
2313
 
2411
- } else if ( Array.isArray( args ) ) {
2412
- validators.statusCode( args[0] );
2413
- this.values = args;
2414
2314
 
2415
- } else if ( args.statusCode ) {
2416
- validators.statusCode( args.statusCode );
2417
- this.values = [ args.statusCode, args.body, args.headers, args.isBase64Encoded ];
2315
+ /***/ },
2418
2316
 
2419
- } else if ( [ undefined, null ].includes( args ) ) {
2420
- this.values = [ 200 ];
2421
- } else {
2422
- throw new LambdaApiValidationError( Text.INVALID_USER_RESPONSE );
2423
- }
2424
- }
2425
- };
2317
+ /***/ 115
2318
+ (module) {
2426
2319
 
2320
+ module.exports = ( n, d = 2 ) => Math.round( n * ( 10 ** d ) ) / ( 10 ** d );
2427
2321
 
2428
- /***/ }),
2429
2322
 
2430
- /***/ 8593:
2431
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2323
+ /***/ },
2432
2324
 
2433
- const { BatchWriteCommand } = __webpack_require__( 3489 );
2434
- const splitBatches = __webpack_require__( 4821 );
2325
+ /***/ 8256
2326
+ (module, __unused_webpack_exports, __webpack_require__) {
2435
2327
 
2436
- const batchSize = 25;
2328
+ const isSerializable = __webpack_require__( 8864 );
2329
+ const camelize = __webpack_require__( 3914 );
2437
2330
 
2438
- const getMapper = method => method === 'put' ? v => ( { PutRequest: { Item: v } } ) : v => ( { DeleteRequest: { Key: v } } );
2331
+ const change = ( obj, keepAllCaps ) =>
2332
+ !isSerializable( obj ) ? obj : Object.entries( obj ).reduce( ( transformed, [ key, value ] ) => {
2333
+ delete transformed[key];
2334
+ transformed[camelize( key, { keepAllCaps } )] = typeof value === 'object' ? change( value, keepAllCaps ) : value;
2335
+ return transformed;
2336
+ }, Array.isArray( obj ) ? [] : {} );
2439
2337
 
2440
- const process = async ( { client, method, table, batches } ) => {
2441
- if ( batches.length === 0 ) { return true; }
2338
+ module.exports = ( obj, { keepAllCaps = false } = {} ) => change( obj, keepAllCaps );
2442
2339
 
2443
- const response = await client.send( new BatchWriteCommand( { RequestItems: { [table]: batches[0] } } ) );
2444
2340
 
2445
- const unprocessed = response.UnprocessedItems?.[table];
2446
- return process( {
2447
- client, method, table,
2448
- batches: unprocessed ? splitBatches( batches.slice( 1 ).flat().concat( unprocessed ), batchSize ) : batches.slice( 1 )
2449
- } );
2450
- };
2341
+ /***/ },
2451
2342
 
2452
- module.exports = async ( client, method, table, items ) =>
2453
- process( { client, method, table, batches: splitBatches( items.map( getMapper( method ) ), batchSize ) } );
2343
+ /***/ 6451
2344
+ (module) {
2454
2345
 
2346
+ module.exports = ( obj, props ) => Object.fromEntries( Object.entries( obj ).filter( ( [ k ] ) => props.includes( k ) ) );
2455
2347
 
2456
- /***/ }),
2457
2348
 
2458
- /***/ 8660:
2459
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2349
+ /***/ },
2460
2350
 
2461
- const cacheStorage = __webpack_require__( 4164 );
2462
- const { GetParameterCommand } = __webpack_require__( 4348 );
2351
+ /***/ 5762
2352
+ (module, __unused_webpack_exports, __webpack_require__) {
2463
2353
 
2464
- module.exports = async ( client, name ) => {
2465
- const key = `SSM_${name}`;
2466
- const cacheValue = cacheStorage.get( key );
2467
- if ( cacheValue ) { return cacheValue; }
2354
+ const camelize = __webpack_require__( 8256 );
2355
+ const filterProps = __webpack_require__( 6451 );
2356
+ const removeEmptyArrays = __webpack_require__( 2047 );
2357
+ const snakelize = __webpack_require__( 7572 );
2468
2358
 
2469
- try {
2470
- const response = await client.send( new GetParameterCommand( { Name: name, WithDecryption: true } ) );
2471
- const value = response?.Parameter?.Value;
2472
- cacheStorage.set( key, value );
2473
- return value;
2474
- } catch ( error ) {
2475
- if ( error.constructor.name === 'ParameterNotFound' ) {
2476
- return null;
2477
- }
2478
- throw error;
2479
- }
2359
+ module.exports = {
2360
+ camelize,
2361
+ filterProps,
2362
+ removeEmptyArrays,
2363
+ snakelize
2480
2364
  };
2481
2365
 
2482
2366
 
2483
- /***/ }),
2367
+ /***/ },
2484
2368
 
2485
- /***/ 8864:
2486
- /***/ ((module) => {
2369
+ /***/ 8864
2370
+ (module) {
2487
2371
 
2488
2372
  module.exports = obj =>
2489
2373
  typeof obj === 'object' &&
@@ -2494,203 +2378,235 @@ module.exports = obj =>
2494
2378
  !( obj instanceof Date );
2495
2379
 
2496
2380
 
2497
- /***/ }),
2381
+ /***/ },
2498
2382
 
2499
- /***/ 8936:
2500
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2383
+ /***/ 2047
2384
+ (module) {
2501
2385
 
2502
- const { WriteRecordsCommand } = __webpack_require__( 8248 );
2386
+ module.exports = o => Object.fromEntries( Object.entries( o ).filter( ( [ , v ] ) => !Array.isArray( v ) || v.length > 0 ) );
2503
2387
 
2504
- module.exports = async ( client, { database, table, records, ignoreRejections = false } ) => {
2505
- try {
2506
- const response = await client.send( new WriteRecordsCommand( {
2507
- DatabaseName: database,
2508
- TableName: table,
2509
- Records: records
2510
- } ) );
2511
- return { recordsIngested: response.RecordsIngested };
2512
- } catch ( error ) {
2513
- if ( ignoreRejections && error.name === 'RejectedRecordsException' ) {
2514
- return { rejectedRecords: error.RejectedRecords };
2515
- }
2516
- throw error;
2517
- }
2518
- };
2519
2388
 
2389
+ /***/ },
2520
2390
 
2521
- /***/ }),
2391
+ /***/ 7572
2392
+ (module, __unused_webpack_exports, __webpack_require__) {
2522
2393
 
2523
- /***/ 8994:
2524
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2394
+ const isSerializable = __webpack_require__( 8864 );
2395
+ const snakelize = __webpack_require__( 3402 );
2525
2396
 
2526
- const Text = __webpack_require__( 9760 );
2527
- const LambdaApiValidationError = __webpack_require__( 3446 );
2397
+ const change = ( obj, keepAllCaps ) =>
2398
+ !isSerializable( obj ) ? obj : Object.entries( obj ).reduce( ( transformed, [ key, value ] ) => {
2399
+ delete transformed[key];
2400
+ transformed[snakelize( key, { keepAllCaps } )] = typeof value === 'object' ? change( value, keepAllCaps ) : value;
2401
+ return transformed;
2402
+ }, Array.isArray( obj ) ? [] : {} );
2528
2403
 
2529
- const evaluate = ( condition, errorMessage ) => {
2530
- if ( !condition ) { throw new LambdaApiValidationError( errorMessage ); }
2531
- };
2404
+ module.exports = ( obj, { keepAllCaps = false } = {} ) => change( obj, keepAllCaps );
2532
2405
 
2533
- const isConstructor = v => {
2534
- try {
2535
- return !!Reflect.construct( new Proxy( v, {} ), [] );
2536
- } catch {
2537
- return false;
2406
+
2407
+ /***/ },
2408
+
2409
+ /***/ 5422
2410
+ (module) {
2411
+
2412
+ global.__redisInstances = {};
2413
+
2414
+ /**
2415
+ * Create a redis client instance
2416
+ * @param {Object} redis Redis npm dependency
2417
+ * @param {String} address Redis DB address (either RW or RO)
2418
+ * @returns redisClient A new redis client instance connected to the database
2419
+ */
2420
+ module.exports = async ( { redis, address, protocol = 'rediss', port = 6379 } ) => {
2421
+ if ( global.__redisInstances[address] ) {
2422
+ try {
2423
+ const r = await global.__redisInstances[address].ping();
2424
+ if ( r === 'PONG' ) {
2425
+ return global.__redisInstances[address];
2426
+ } else {
2427
+ delete global.__redisInstances[address];
2428
+ }
2429
+ } catch {
2430
+ delete global.__redisInstances[address];
2431
+ }
2538
2432
  }
2539
- };
2540
2433
 
2541
- module.exports = {
2542
- errorType: v => evaluate( isConstructor( v ), Text.INVALID_ERROR_TYPE ),
2543
- function: v => evaluate( typeof v === 'function', Text.INVALID_FN ),
2544
- httpMethod: v => evaluate( [ 'DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT' ].includes( v ), Text.INVALID_METHOD ),
2545
- matcherPath: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_PATH ),
2546
- matcherPathIncludes: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_PATH_INCLUDES ),
2547
- matcherPathMatch: v => evaluate( v === undefined || v?.constructor?.name === RegExp.name, Text.INVALID_MATCHER_PATH_MATCH ),
2548
- matcherPathNotIncludes: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_PATH_NOT_INCLUDES ),
2549
- matcherRoute: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_ROUTE ),
2550
- matcherRouteIncludes: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_ROUTE_INCLUDES ),
2551
- matcherRouteMatch: v => evaluate( v === undefined || v?.constructor?.name === RegExp.name, Text.INVALID_MATCHER_ROUTE_MATCH ),
2552
- matcherRouteNotIncludes: v => evaluate( v === undefined || ( typeof v === 'string' && v.length > 0 ), Text.INVALID_MATCHER_ROUTE_NOT_INCLUDES ),
2553
- statusCode: v => evaluate( typeof v === 'number' && /^[1-5]\d\d$/.test( String( v ) ), Text.INVALID_STATUS_CODE ),
2554
- transformRequest: v => evaluate( [ 'camelcase', 'snakecase', null, false ].includes( v ), Text.INVALID_TRANSFORM_REQUEST ),
2555
- transformResponse: v => evaluate( [ 'camelcase', 'snakecase', null, false ].includes( v ), Text.INVALID_TRANSFORM_RESPONSE )
2434
+ const client = redis.createClient( { url: `${protocol}://${address}:${port}`, socket: { keepAlive: 15000 } } );
2435
+
2436
+ await client.connect();
2437
+
2438
+ global.__redisInstances[address] = client;
2439
+ return client;
2556
2440
  };
2557
2441
 
2558
2442
 
2559
- /***/ }),
2443
+ /***/ },
2560
2444
 
2561
- /***/ 9039:
2562
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2445
+ /***/ 4528
2446
+ (module, __unused_webpack_exports, __webpack_require__) {
2563
2447
 
2564
- const cache = __webpack_require__( 4164 );
2448
+ const createClient = __webpack_require__( 5422 );
2565
2449
 
2566
- module.exports = ( constructor, args = [] ) => {
2567
- const cacheKey = `${constructor.name}(${args.map( arg => JSON.stringify( arg ) ).join( ',' )})`;
2568
- return cache.get( cacheKey ) ?? ( () => {
2569
- const client = Reflect.construct( constructor, args );
2570
- cache.set( cacheKey, client );
2571
- return client;
2572
- } )();
2450
+ module.exports = {
2451
+ createClient
2573
2452
  };
2574
2453
 
2575
2454
 
2576
- /***/ }),
2455
+ /***/ },
2577
2456
 
2578
- /***/ 9129:
2579
- /***/ ((module) => {
2457
+ /***/ 3914
2458
+ (module) {
2580
2459
 
2581
- /* eslint consistent-return: 0 */
2582
- const removeNullValues = ( o, isArray = Array.isArray( o ) ) =>
2583
- Object.entries( o ).reduce( ( newObj, [ k, v ] ) => {
2584
- if ( v === null && !isArray ) { return newObj; }
2585
- return Object.assign( newObj, { [k]: v?.constructor === Object ? removeNullValues( v ) : v } );
2586
- }, isArray ? [] : {} );
2587
-
2588
- module.exports = ( v, type ) => {
2589
- if ( [ null, undefined ].includes( v ) ) {
2590
- return undefined;
2591
- }
2592
- if ( v === '' && type !== 'varchar' ) {
2593
- return undefined;
2594
- }
2595
- if ( type === 'boolean' ) {
2596
- return v === 'true';
2597
- }
2598
- if ( [ 'float', 'decimal', 'double' ].includes( type ) ) {
2599
- return parseFloat( v );
2600
- }
2601
- if ( [ 'tinyint', 'smallint', 'int', 'bigint' ].includes( type ) ) {
2602
- return parseInt( v );
2603
- }
2604
- if ( 'timestamp' === type ) {
2605
- return new Date( v ).getTime();
2606
- }
2607
- if ( [ 'row', 'array' ].includes( type ) ) {
2608
- const obj = v.replace( /(?<=(?:{|,\s)[\w-_]+)=/g, '@@DELIMITER@@' ) // replaces delimiter = with @@DELIMITER@@
2609
- .replace( /(?<={|,\s)([\w_-]+)(?=@@DELIMITER@@)/g, '"$1"' ) // wrap object keys
2610
- .replace( /(?<=@@DELIMITER@@)((?:(?!,\s|}|\[|{).)+)/g, '"$1"' ) // wrap object values
2611
- .replace( /(?<=\[|,\s)((?:(?!,\s|{|\]|").)+)/g, '"$1"' ) // wrap array values
2612
- .replace( /"null"/g, 'null' ) // convert "null" to null
2613
- .replace( /@@DELIMITER@@/g, ':' ); // replaces @@DELIMITER@@ for :
2460
+ // Convert a string to camelCase
2461
+ module.exports = ( input, { keepAllCaps = false } = {} ) =>
2462
+ // Break the string into sequences to rebuild later
2463
+ !input ? input : input.split( /\s/ )
2464
+ // ALL_CAPS terms are ignored
2465
+ .map( term => [ term, keepAllCaps && /^[A-Z_]+$/g.test( term ) ? term : term
2466
+ // Matches the penultimate letter in a sequence of upper case followed by lower case and convert it to lower case
2467
+ // Effectively creating a word break eg: BDay => bDay
2468
+ .replace( /[A-Z](?=[A-Z][a-z])/g, c => `${c[0].toLowerCase()}` )
2469
+ .replace( /([A-Z])([A-Z]+)/g, c => `${c[0]}${c.slice( 1 ).toLowerCase()}` ) // Sequences of upper case
2470
+ .replace( /([-_]\w)/g, c => c[1].toUpperCase() ) // first letter after hyphen and underline
2471
+ .replace( /^([A-Z])/g, c => c[0].toLowerCase() ) // first letter
2472
+ ] )
2473
+ // Rebuild the string replacing the converter terms keeping the original delimiters
2474
+ .reduce( ( result, [ term, repl ] ) => result.replace( term, repl ), input );
2614
2475
 
2615
- return removeNullValues( JSON.parse( obj ) );
2616
- }
2617
- if ( 'json' === type ) {
2618
- return JSON.parse( v );
2619
- }
2620
- return v;
2476
+
2477
+ /***/ },
2478
+
2479
+ /***/ 3258
2480
+ (module) {
2481
+
2482
+ module.exports = input =>
2483
+ // Break the string into sequences to rebuild later
2484
+ !input ? input : input.split( /\s/ )
2485
+ // ALL_CAPS terms are ignored
2486
+ .map( term => [ term, term.charAt( 0 ).toUpperCase() + term.slice( 1 ).toLowerCase() ] )
2487
+ // Rebuild the string replacing the converter terms keeping the original delimiters
2488
+ .reduce( ( result, [ term, repl ] ) => result.replace( term, repl ), input );
2489
+
2490
+
2491
+ /***/ },
2492
+
2493
+ /***/ 268
2494
+ (module, __unused_webpack_exports, __webpack_require__) {
2495
+
2496
+ const camelize = __webpack_require__( 3914 );
2497
+ const capitalizeWords = __webpack_require__( 3258 );
2498
+ const snakelize = __webpack_require__( 3402 );
2499
+
2500
+ module.exports = {
2501
+ camelize,
2502
+ capitalizeWords,
2503
+ snakelize
2621
2504
  };
2622
2505
 
2623
2506
 
2624
- /***/ }),
2507
+ /***/ },
2625
2508
 
2626
- /***/ 9179:
2627
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2509
+ /***/ 3402
2510
+ (module) {
2628
2511
 
2629
- const parseValue = __webpack_require__( 2847 );
2512
+ // convert a string to snake_case
2513
+ module.exports = ( input, { keepAllCaps = false } = {} ) =>
2514
+ // Break the string into sequences to rebuild later
2515
+ !input ? input : input.split( /\s/ )
2516
+ // ALL_CAPS terms are ignored
2517
+ .map( term => [ term, keepAllCaps && /^[A-Z_]+$/g.test( term ) ? term : term
2518
+ .replace( /-/g, '_' ) // replaces hyphen
2519
+ .replace( /([a-z\d])([A-Z])/g, '$1_$2' ) // add _ between lower and upper case letters
2520
+ .replace( /([A-Z])([A-Z])(?=[a-z\d])/g, '$1_$2' ).toLowerCase() // add _ between uppercase char and next uppercase char follow by lowercase
2521
+ ] )
2522
+ // Rebuild the string replacing the converter terms keeping the original delimiters
2523
+ .reduce( ( result, [ term, repl ] ) => result.replace( term, repl ), input );
2630
2524
 
2631
- module.exports = item =>
2632
- item.reduce( ( row, { field, value } ) =>
2633
- Object.assign( row, {
2634
- [field]: parseValue( value )
2635
- } ), {} );
2636
2525
 
2526
+ /***/ },
2637
2527
 
2638
- /***/ }),
2528
+ /***/ 6878
2529
+ (module, __unused_webpack_exports, __webpack_require__) {
2639
2530
 
2640
- /***/ 9552:
2641
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2531
+ const retryOnError = __webpack_require__( 4243 );
2532
+ const sleep = __webpack_require__( 2445 );
2533
+ const Timer = __webpack_require__( 9651 );
2534
+ const untarJsonGz = __webpack_require__( 8233 );
2642
2535
 
2643
- const parseItem = __webpack_require__( 9179 );
2536
+ module.exports = {
2537
+ retryOnError,
2538
+ sleep,
2539
+ Timer,
2540
+ untarJsonGz
2541
+ };
2644
2542
 
2645
- module.exports = results => results.map( item => parseItem( item ) );
2646
2543
 
2544
+ /***/ },
2647
2545
 
2648
- /***/ }),
2546
+ /***/ 4243
2547
+ (module, __unused_webpack_exports, __webpack_require__) {
2649
2548
 
2650
- /***/ 9556:
2651
- /***/ ((module) => {
2549
+ const sleep = __webpack_require__( 2445 );
2652
2550
 
2653
- "use strict";
2654
- module.exports = require("@aws-sdk/client-sesv2");
2551
+ const execWithRetry = async ( closure, { limit, delay, retryHook, execCount = 0 } ) => {
2552
+ if ( !( closure instanceof Function ) ) {
2553
+ throw new Error( 'Closure is not a function' );
2554
+ }
2655
2555
 
2656
- /***/ }),
2556
+ try {
2557
+ return await closure();
2558
+ } catch ( error ) {
2559
+ // exhausted
2560
+ if ( execCount === limit ) { throw error; }
2657
2561
 
2658
- /***/ 9628:
2659
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2562
+ // async retry hook to check if it should retry or give up and throw
2563
+ if ( retryHook instanceof Function ) {
2564
+ try {
2565
+ const retry = await retryHook( error, execCount );
2566
+ if ( retry === false ) { return false; }
2660
2567
 
2661
- const { PutCommand } = __webpack_require__( 3489 );
2568
+ // Hook errors break the flow
2569
+ } catch ( hookError ) {
2570
+ console.debug( hookError );
2571
+ throw hookError;
2572
+ }
2573
+ }
2662
2574
 
2663
- const parseArgs = args => {
2664
- // native args mode
2665
- if ( args[0] instanceof Object ) {
2666
- return args[0];
2575
+ // if there is no hook back-off and retry
2576
+ if ( delay > 0 ) {
2577
+ await sleep( delay ** ( 1 + execCount ) );
2578
+ }
2579
+ return execWithRetry( closure, { limit, delay, retryHook, execCount: execCount + 1 } );
2667
2580
  }
2668
- // sugar mode
2669
- return {
2670
- TableName: args[0],
2671
- Item: args[1],
2672
- ReturnValues: 'NONE',
2673
- ReturnConsumedCapacity: 'NONE'
2674
- };
2675
2581
  };
2676
2582
 
2677
2583
  /**
2678
2584
  *
2679
- * @param {*} client
2680
- * @param {...any} args The args. either one object with the native args or two string args, tableName and item.
2681
- * @returns
2585
+ * @param {Function} closure A self contained function that will be invoked
2586
+ * @param {Object} config
2587
+ * @param {Number} limit The max number of retries
2588
+ * @param {Number} delay The delay between each retry (it will be multiplied by the number of retries, so, it is linear back-off)
2589
+ * @param {Function} retryHook A function to be called every-time a retry is needed.
2590
+ * If this functions returns false, the retry error is raised
2591
+ * If this functions throws error, the thrown error is raised
2592
+ * @returns {Any} The closure result
2682
2593
  */
2683
- module.exports = async ( client, ...args ) => {
2684
- const nativeArgs = parseArgs( args );
2685
- const response = await client.send( new PutCommand( nativeArgs ) );
2686
- return response.Attributes ?? nativeArgs.Item;
2687
- };
2594
+ module.exports = async ( closure, { limit = 0, delay = 0, retryHook = null } = {} ) =>
2595
+ execWithRetry( closure, { limit, delay, retryHook } );
2596
+
2597
+
2598
+ /***/ },
2599
+
2600
+ /***/ 2445
2601
+ (module) {
2602
+
2603
+ module.exports = t => new Promise( r => setTimeout( r, t ) );
2688
2604
 
2689
2605
 
2690
- /***/ }),
2606
+ /***/ },
2691
2607
 
2692
- /***/ 9651:
2693
- /***/ ((module) => {
2608
+ /***/ 9651
2609
+ (module) {
2694
2610
 
2695
2611
  module.exports = class Timer {
2696
2612
  #startedAt;
@@ -2735,49 +2651,167 @@ module.exports = class Timer {
2735
2651
  };
2736
2652
 
2737
2653
 
2738
- /***/ }),
2654
+ /***/ },
2739
2655
 
2740
- /***/ 9704:
2741
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2656
+ /***/ 8233
2657
+ (module, __unused_webpack_exports, __webpack_require__) {
2742
2658
 
2743
- const { PutObjectCommand } = __webpack_require__( 5725 );
2659
+ const { unzipSync } = __webpack_require__( 3106 );
2744
2660
 
2745
- module.exports = ( client, bucket, key, body, nativeArgs ) =>
2746
- client.send( new PutObjectCommand( {
2747
- ...nativeArgs,
2748
- Bucket: bucket,
2749
- Key: key,
2750
- Body: typeof body === 'string' || Buffer.isBuffer( body ) ? body : JSON.stringify( body )
2751
- } ) );
2661
+ const firstIndexOf = ( c, ...vars ) => Math.min( ...vars.map( v => c.indexOf( v ) ).filter( n => n > -1 ) );
2662
+ const lastIndexOf = ( c, ...vars ) => Math.max( ...vars.map( v => c.lastIndexOf( v ) ) );
2663
+
2664
+ /**
2665
+ * Decompress JSON
2666
+ *
2667
+ * Reads a gzipped tarball (.tar.gz)
2668
+ * 1. Unzip it
2669
+ * 2. Convert all to utf-8
2670
+ * 3. Split files using the \0star separator
2671
+ * 4. Trim files until JSON markup start/end ({})
2672
+ * 5. JSON parse
2673
+ *
2674
+ * Enjoy this 100% native tarball decompression!
2675
+ */
2676
+ module.exports = raw =>
2677
+ unzipSync( raw )
2678
+ .toString( 'utf-8' )
2679
+ .split( '\0ustar' )
2680
+ .slice( 1 )
2681
+ .map( c =>
2682
+ JSON.parse( c.substring( firstIndexOf( c, '{', '[' ), lastIndexOf( c, '}', ']' ) + 1 ) )
2683
+ );
2752
2684
 
2753
2685
 
2754
- /***/ }),
2686
+ /***/ },
2755
2687
 
2756
- /***/ 9760:
2757
- /***/ ((module) => {
2688
+ /***/ 3744
2689
+ (module) {
2758
2690
 
2759
- module.exports = {
2760
- ERROR_500: 'Internal Server Error',
2761
- ERROR_405: 'Method Not Allowed',
2762
- INVALID_ERROR_TYPE: 'Argument "errorType" must be a constructor Function',
2763
- INVALID_FN: 'Argument "fn" must be of type function',
2764
- INVALID_METHOD: 'Argument "method" must be one of the default HTTP methods',
2765
- INVALID_STATUS_CODE: 'Argument "statusCode" must be valid HTTP Status Code',
2766
- INVALID_TRANSFORM_REQUEST: 'Argument "transformRequest" must be either "camelize", "snakelize", false or null',
2767
- INVALID_TRANSFORM_RESPONSE: 'Argument "transformResponse" must be either "camelize", "snakelize", false or null',
2768
- INVALID_MATCHER_ROUTE: 'Argument "route" must be either undefined or an string with length greater than 0',
2769
- INVALID_MATCHER_ROUTE_INCLUDES: 'Argument "routeIncludes" must be either undefined or an string with length greater than 0',
2770
- INVALID_MATCHER_ROUTE_NOT_INCLUDES: 'Argument "routeNotIncludes" must be either undefined or an string with length greater than 0',
2771
- INVALID_MATCHER_ROUTE_MATCH: 'Argument "routeMatch" must be either undefined or type RegExp',
2772
- INVALID_MATCHER_PATH: 'Argument "path" must be either undefined or an string with length greater than 0',
2773
- INVALID_MATCHER_PATH_INCLUDES: 'Argument "pathIncludes" must be either undefined or an string with length greater than 0',
2774
- INVALID_MATCHER_PATH_NOT_INCLUDES: 'Argument "pathNotIncludes" must be either undefined or an string with length greater than 0',
2775
- INVALID_MATCHER_PATH_MATCH: 'Argument "pathMatch" must be either undefined or type RegExp',
2776
- INVALID_USER_RESPONSE: 'Function return must be a number, a string, an array (where p=0 is a number) or an object (where .statusCode is a number)'
2777
- };
2691
+ "use strict";
2692
+ module.exports = require("@aws-sdk/client-athena");
2693
+
2694
+ /***/ },
2695
+
2696
+ /***/ 7493
2697
+ (module) {
2698
+
2699
+ "use strict";
2700
+ module.exports = require("@aws-sdk/client-cloudwatch-logs");
2701
+
2702
+ /***/ },
2703
+
2704
+ /***/ 4671
2705
+ (module) {
2706
+
2707
+ "use strict";
2708
+ module.exports = require("@aws-sdk/client-dynamodb");
2778
2709
 
2710
+ /***/ },
2711
+
2712
+ /***/ 5892
2713
+ (module) {
2714
+
2715
+ "use strict";
2716
+ module.exports = require("@aws-sdk/client-lambda");
2717
+
2718
+ /***/ },
2719
+
2720
+ /***/ 5725
2721
+ (module) {
2722
+
2723
+ "use strict";
2724
+ module.exports = require("@aws-sdk/client-s3");
2725
+
2726
+ /***/ },
2727
+
2728
+ /***/ 9556
2729
+ (module) {
2730
+
2731
+ "use strict";
2732
+ module.exports = require("@aws-sdk/client-sesv2");
2733
+
2734
+ /***/ },
2735
+
2736
+ /***/ 7651
2737
+ (module) {
2738
+
2739
+ "use strict";
2740
+ module.exports = require("@aws-sdk/client-sns");
2741
+
2742
+ /***/ },
2743
+
2744
+ /***/ 1976
2745
+ (module) {
2746
+
2747
+ "use strict";
2748
+ module.exports = require("@aws-sdk/client-sqs");
2749
+
2750
+ /***/ },
2751
+
2752
+ /***/ 4348
2753
+ (module) {
2754
+
2755
+ "use strict";
2756
+ module.exports = require("@aws-sdk/client-ssm");
2757
+
2758
+ /***/ },
2759
+
2760
+ /***/ 1671
2761
+ (module) {
2762
+
2763
+ "use strict";
2764
+ module.exports = require("@aws-sdk/client-timestream-query");
2765
+
2766
+ /***/ },
2767
+
2768
+ /***/ 8248
2769
+ (module) {
2770
+
2771
+ "use strict";
2772
+ module.exports = require("@aws-sdk/client-timestream-write");
2773
+
2774
+ /***/ },
2775
+
2776
+ /***/ 3489
2777
+ (module) {
2778
+
2779
+ "use strict";
2780
+ module.exports = require("@aws-sdk/lib-dynamodb");
2781
+
2782
+ /***/ },
2783
+
2784
+ /***/ 4991
2785
+ (module) {
2786
+
2787
+ "use strict";
2788
+ module.exports = require("@aws-sdk/s3-request-presigner");
2789
+
2790
+ /***/ },
2791
+
2792
+ /***/ 6982
2793
+ (module) {
2794
+
2795
+ "use strict";
2796
+ module.exports = require("crypto");
2797
+
2798
+ /***/ },
2799
+
2800
+ /***/ 5692
2801
+ (module) {
2802
+
2803
+ "use strict";
2804
+ module.exports = require("https");
2805
+
2806
+ /***/ },
2807
+
2808
+ /***/ 3106
2809
+ (module) {
2810
+
2811
+ "use strict";
2812
+ module.exports = require("zlib");
2779
2813
 
2780
- /***/ })
2814
+ /***/ }
2781
2815
 
2782
2816
  /******/ });
2783
2817
  /************************************************************************/