@benup/bensdk 1.2.4 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/lib/lib/consumer/datapoint/index.d.ts +18 -0
- package/bin/lib/lib/consumer/index.d.ts +97 -0
- package/bin/lib/schemas/action-consumer/message.schema.d.ts +25 -0
- package/bin/lib/schemas/action.schema.d.ts +12908 -0
- package/bin/lib/schemas/benefit-definition.schema.d.ts +617 -0
- package/bin/lib/schemas/common.schema.d.ts +144 -0
- package/bin/lib/types/action.types.d.ts +7 -0
- package/bin/lib/types/benefit-definition.types.d.ts +3 -0
- package/bin/lib/types/state-handler.types.d.ts +62 -0
- package/package.json +2 -2
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SendMessageCommandOutput } from '@aws-sdk/client-sqs';
|
|
2
|
+
export interface DataPointContext {
|
|
3
|
+
executionID: string;
|
|
4
|
+
accountID: string;
|
|
5
|
+
companyID: string;
|
|
6
|
+
correlationIDs: Record<string, string>;
|
|
7
|
+
ingestion: Record<string, unknown>;
|
|
8
|
+
SQSMessageID: string;
|
|
9
|
+
sendMessage: (ingestionRawData: unknown, origin: string, final: boolean) => Promise<SendMessageCommandOutput>;
|
|
10
|
+
}
|
|
11
|
+
export interface DataPoint {
|
|
12
|
+
executionID: string;
|
|
13
|
+
accountID: string;
|
|
14
|
+
companyID: string;
|
|
15
|
+
correlationIDs: Record<string, string>;
|
|
16
|
+
ingestion: Record<string, unknown>;
|
|
17
|
+
SQSMessageID: string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Message, MessageAttributeValue, SendMessageCommandOutput, SQSClient } from '@aws-sdk/client-sqs';
|
|
2
|
+
import pino from 'pino';
|
|
3
|
+
import { Consumer } from 'sqs-consumer';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { DataPoint, DataPointContext } from './datapoint/index.js';
|
|
6
|
+
export interface ConsumerHandlerCtx {
|
|
7
|
+
/**
|
|
8
|
+
* The raw message object received from sqs
|
|
9
|
+
*/
|
|
10
|
+
rawMessage: Message;
|
|
11
|
+
/**
|
|
12
|
+
* Instace of pino.Logger with the execution context
|
|
13
|
+
*/
|
|
14
|
+
logger: pino.Logger;
|
|
15
|
+
/**
|
|
16
|
+
* Correlation IDs captured in message attributes
|
|
17
|
+
*/
|
|
18
|
+
correlationIDs: Record<string, string>;
|
|
19
|
+
/**
|
|
20
|
+
* send message to a queue
|
|
21
|
+
*/
|
|
22
|
+
sendMessage: (queueUrl: string, message: object, executionID?: string) => Promise<SendMessageCommandOutput>;
|
|
23
|
+
/**
|
|
24
|
+
* Create a DataPointContext object with the provided mapping
|
|
25
|
+
*/
|
|
26
|
+
createDataPointContext: (dataPoint: DataPoint, meta?: Record<string, string>) => DataPointContext;
|
|
27
|
+
}
|
|
28
|
+
export type HandlerMessageResponse = 'ACK' | 'UNACK' | 'DLQ';
|
|
29
|
+
export interface HandlerResponse {
|
|
30
|
+
response: HandlerMessageResponse;
|
|
31
|
+
options?: {
|
|
32
|
+
maxRetries?: number;
|
|
33
|
+
delayBetweenRetries?: number;
|
|
34
|
+
delayMode?: 'fixed' | 'exponential';
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export type ConsumerHandler<T> = (message: T, ctx: ConsumerHandlerCtx) => Promise<HandlerResponse>;
|
|
38
|
+
/**
|
|
39
|
+
* Options for create a consumer
|
|
40
|
+
*/
|
|
41
|
+
export interface ConsumerOptions<T> {
|
|
42
|
+
/**
|
|
43
|
+
* Zod Schema of the message body. If message body isnt valid,
|
|
44
|
+
* the consumer will return an error, and the message will be sent to dlq.
|
|
45
|
+
*/
|
|
46
|
+
messageSchema: z.AnyZodObject;
|
|
47
|
+
/**
|
|
48
|
+
* The service name to be showed in log.
|
|
49
|
+
*/
|
|
50
|
+
serviceName: string;
|
|
51
|
+
/**
|
|
52
|
+
* SQS queues urls
|
|
53
|
+
* main - the url of the queue that consumer will be listen
|
|
54
|
+
* dlq - the url of the queue to be used as DLQ
|
|
55
|
+
*/
|
|
56
|
+
queuesUrl: {
|
|
57
|
+
main: string;
|
|
58
|
+
dlq: string;
|
|
59
|
+
dataPointMain?: string;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* set this attribute to use localstack
|
|
63
|
+
*/
|
|
64
|
+
sqsEndpoint?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Instace of pino.Logger to be used
|
|
67
|
+
*/
|
|
68
|
+
logger: pino.Logger;
|
|
69
|
+
/**
|
|
70
|
+
* Handler for the received messages
|
|
71
|
+
* @param message - the message as object
|
|
72
|
+
* @param ctx -
|
|
73
|
+
* @returns
|
|
74
|
+
*/
|
|
75
|
+
handler: ConsumerHandler<T>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* helper for send message to a sqs queue
|
|
79
|
+
*/
|
|
80
|
+
export declare function send(sqs: SQSClient, queueUrl: string, message: object | string, attributes: Record<string, MessageAttributeValue>): Promise<SendMessageCommandOutput>;
|
|
81
|
+
/**
|
|
82
|
+
* Create a new consumerHandler
|
|
83
|
+
*/
|
|
84
|
+
export declare const createConsumerHandler: <T>(options: ConsumerOptions<T>, sqs: SQSClient) => (rawMessage: Message) => Promise<Message | void>;
|
|
85
|
+
/**
|
|
86
|
+
* Create a new SQS Consumer
|
|
87
|
+
* @param {ConsumerOptions} options - consumer options
|
|
88
|
+
* @returns {Consumer} - sqs-consumer instance
|
|
89
|
+
*/
|
|
90
|
+
export declare const createConsumer: <T>(options: ConsumerOptions<T>) => Consumer;
|
|
91
|
+
/**
|
|
92
|
+
* Helper for mapping the ingestion data
|
|
93
|
+
* @param mapping - The mapping to be used
|
|
94
|
+
* @param ingestionRawData - The ingestion data to be mapped
|
|
95
|
+
* @returns The mapped data
|
|
96
|
+
*/
|
|
97
|
+
export declare const ingestionMapping: (mapping: Record<string, unknown>, ingestionRawData: Record<string, unknown>) => Record<string, unknown>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const ActionConsumerMessageSchema: z.ZodObject<{
|
|
3
|
+
version: z.ZodNumber;
|
|
4
|
+
data: z.ZodObject<{
|
|
5
|
+
actionID: z.ZodEffects<z.ZodString, string, string>;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
actionID?: string;
|
|
8
|
+
}, {
|
|
9
|
+
actionID?: string;
|
|
10
|
+
}>;
|
|
11
|
+
meta: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
|
|
12
|
+
}, "strict", z.ZodTypeAny, {
|
|
13
|
+
data?: {
|
|
14
|
+
actionID?: string;
|
|
15
|
+
};
|
|
16
|
+
meta?: {};
|
|
17
|
+
version?: number;
|
|
18
|
+
}, {
|
|
19
|
+
data?: {
|
|
20
|
+
actionID?: string;
|
|
21
|
+
};
|
|
22
|
+
meta?: {};
|
|
23
|
+
version?: number;
|
|
24
|
+
}>;
|
|
25
|
+
export default ActionConsumerMessageSchema;
|