lambda-toolkit 0.0.11-beta → 0.0.13-beta

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