quidproquo-actionprocessor-awslambda 0.0.122 → 0.0.123

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.
@@ -0,0 +1,3 @@
1
+ type ClientConstructor<T> = new (args: any) => T;
2
+ export declare function createAwsClient<T>(ClientClass: ClientConstructor<T>, args: any): T;
3
+ export {};
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createAwsClient = void 0;
4
+ const cache = new WeakMap();
5
+ function createAwsClient(ClientClass, args) {
6
+ // Get or create the Map for the ClientClass
7
+ let argsCache = cache.get(ClientClass);
8
+ if (!argsCache) {
9
+ argsCache = new Map();
10
+ cache.set(ClientClass, argsCache);
11
+ }
12
+ // Generate a key for the arguments
13
+ const argsKey = JSON.stringify(args);
14
+ // Check if the instance already exists in the cache
15
+ if (!argsCache.has(argsKey)) {
16
+ // Create a new instance and store it in the cache
17
+ argsCache.set(argsKey, new ClientClass(args));
18
+ }
19
+ // Return the cached instance
20
+ return argsCache.get(argsKey);
21
+ }
22
+ exports.createAwsClient = createAwsClient;
@@ -21,7 +21,9 @@ const executeLambdaByName = (functionName, region, payload) => __awaiter(void 0,
21
21
  InvocationType: 'RequestResponse',
22
22
  }));
23
23
  if (response.FunctionError) {
24
- throw new Error(response.FunctionError);
24
+ // Get more details about the error if available
25
+ const errorDetails = response.Payload ? new TextDecoder().decode(response.Payload) : '';
26
+ throw new Error(`Lambda Error: ${response.FunctionError}. Details: ${errorDetails}`);
25
27
  }
26
28
  if (response.Payload) {
27
29
  const jsonString = new TextDecoder().decode(response.Payload);
@@ -11,8 +11,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.publishMessage = void 0;
13
13
  const client_sns_1 = require("@aws-sdk/client-sns");
14
+ const createAwsClient_1 = require("../createAwsClient");
14
15
  const publishMessage = (topicArn, region, messages) => __awaiter(void 0, void 0, void 0, function* () {
15
- const sqsClient = new client_sns_1.SNSClient({
16
+ const sqsClient = (0, createAwsClient_1.createAwsClient)(client_sns_1.SNSClient, {
16
17
  region,
17
18
  });
18
19
  // Convert them to entries
@@ -12,8 +12,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.sendMessages = void 0;
13
13
  const client_sqs_1 = require("@aws-sdk/client-sqs");
14
14
  const getQueueUrl_1 = require("./getQueueUrl");
15
+ const createAwsClient_1 = require("../createAwsClient");
15
16
  const sendMessages = (queueName, region, messages) => __awaiter(void 0, void 0, void 0, function* () {
16
- const sqsClient = new client_sqs_1.SQSClient({
17
+ const sqsClient = (0, createAwsClient_1.createAwsClient)(client_sqs_1.SQSClient, {
17
18
  region,
18
19
  });
19
20
  const url = yield (0, getQueueUrl_1.getQueueUrl)(queueName, sqsClient);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quidproquo-actionprocessor-awslambda",
3
- "version": "0.0.122",
3
+ "version": "0.0.123",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.js",