@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.
@@ -0,0 +1,144 @@
1
+ /**
2
+ * zod helper
3
+ * @module zod
4
+ */
5
+ import { ObjectId } from 'bson';
6
+ import { z } from 'zod';
7
+ /**
8
+ * Check if string is a valid ObjectId
9
+ */
10
+ export declare const zStrId: z.ZodEffects<z.ZodString, string, string>;
11
+ /**
12
+ * Check if value is a valid ObjectId
13
+ */
14
+ export declare const zObjectId: z.ZodType<ObjectId, z.ZodTypeDef, ObjectId>;
15
+ /**
16
+ * Check if string is ISO Date
17
+ */
18
+ export declare const zDateAt: z.ZodString;
19
+ /**
20
+ * Check if value is a valid Date
21
+ */
22
+ export declare const zDate: z.ZodDate;
23
+ /**
24
+ * Check if string is a valid CPF
25
+ */
26
+ export declare const zCPF: z.ZodEffects<z.ZodString, string, string>;
27
+ /**
28
+ * Check if string is a valid birthdate, a.k.a: date < now
29
+ */
30
+ export declare const zBirthdate: z.ZodEffects<z.ZodString, string, string>;
31
+ /**
32
+ * Check if object is a valid address object
33
+ */
34
+ export declare const zAddress: z.ZodObject<{
35
+ street: z.ZodString;
36
+ number: z.ZodString;
37
+ complement: z.ZodOptional<z.ZodString>;
38
+ neighborhood: z.ZodString;
39
+ city: z.ZodString;
40
+ state: z.ZodString;
41
+ zipCode: z.ZodString;
42
+ country: z.ZodString;
43
+ }, "strict", z.ZodTypeAny, {
44
+ number?: string;
45
+ state?: string;
46
+ country?: string;
47
+ street?: string;
48
+ complement?: string;
49
+ neighborhood?: string;
50
+ city?: string;
51
+ zipCode?: string;
52
+ }, {
53
+ number?: string;
54
+ state?: string;
55
+ country?: string;
56
+ street?: string;
57
+ complement?: string;
58
+ neighborhood?: string;
59
+ city?: string;
60
+ zipCode?: string;
61
+ }>;
62
+ /**
63
+ * Check if string is a valid integer
64
+ */
65
+ export declare const zStrInt: z.ZodString;
66
+ export declare const zLogsFromResponse: z.ZodObject<{
67
+ request: z.ZodObject<{
68
+ url: z.ZodString;
69
+ path: z.ZodString;
70
+ method: z.ZodString;
71
+ headers: z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>;
72
+ body: z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>;
73
+ }, "strip", z.ZodTypeAny, {
74
+ url?: string;
75
+ body?: {} & {
76
+ [k: string]: unknown;
77
+ };
78
+ path?: string;
79
+ method?: string;
80
+ headers?: {} & {
81
+ [k: string]: unknown;
82
+ };
83
+ }, {
84
+ url?: string;
85
+ body?: {} & {
86
+ [k: string]: unknown;
87
+ };
88
+ path?: string;
89
+ method?: string;
90
+ headers?: {} & {
91
+ [k: string]: unknown;
92
+ };
93
+ }>;
94
+ response: z.ZodObject<{
95
+ status: z.ZodNumber;
96
+ body: z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>;
97
+ }, "strip", z.ZodTypeAny, {
98
+ body?: {} & {
99
+ [k: string]: unknown;
100
+ };
101
+ status?: number;
102
+ }, {
103
+ body?: {} & {
104
+ [k: string]: unknown;
105
+ };
106
+ status?: number;
107
+ }>;
108
+ }, "strip", z.ZodTypeAny, {
109
+ request?: {
110
+ url?: string;
111
+ body?: {} & {
112
+ [k: string]: unknown;
113
+ };
114
+ path?: string;
115
+ method?: string;
116
+ headers?: {} & {
117
+ [k: string]: unknown;
118
+ };
119
+ };
120
+ response?: {
121
+ body?: {} & {
122
+ [k: string]: unknown;
123
+ };
124
+ status?: number;
125
+ };
126
+ }, {
127
+ request?: {
128
+ url?: string;
129
+ body?: {} & {
130
+ [k: string]: unknown;
131
+ };
132
+ path?: string;
133
+ method?: string;
134
+ headers?: {} & {
135
+ [k: string]: unknown;
136
+ };
137
+ };
138
+ response?: {
139
+ body?: {} & {
140
+ [k: string]: unknown;
141
+ };
142
+ status?: number;
143
+ };
144
+ }>;
@@ -0,0 +1,7 @@
1
+ import z from 'zod';
2
+ import { ActionSchema, DeductionActionSchema, DependentActionSchema, GrantRevokeActionSchema, RechargeActionSchema } from '../schemas/action.schema';
3
+ export type ActionBaseGrantRevoke = z.infer<typeof GrantRevokeActionSchema>;
4
+ export type ActionBaseRecharge = z.infer<typeof RechargeActionSchema>;
5
+ export type ActionBaseDeduction = z.infer<typeof DeductionActionSchema>;
6
+ export type ActionBaseDependent = z.infer<typeof DependentActionSchema>;
7
+ export type ActionBase = z.infer<typeof ActionSchema>;
@@ -0,0 +1,3 @@
1
+ import z from 'zod';
2
+ import { BenefitDefinitionSchema } from '../schemas/benefit-definition.schema';
3
+ export type BenefitDefinition = z.infer<typeof BenefitDefinitionSchema>;
@@ -0,0 +1,62 @@
1
+ import { Message } from '@aws-sdk/client-sqs';
2
+ import { AxiosInstance } from 'axios';
3
+ import pino from 'pino';
4
+ import z from 'zod';
5
+ import { HandlerResponse } from '../lib/consumer';
6
+ import ActionConsumerMessageSchema from '../schemas/action-consumer/message.schema';
7
+ import { BenefitDefinition } from './benefit-definition.types';
8
+ export type MessageBody = z.infer<typeof ActionConsumerMessageSchema>;
9
+ export interface StateHandlerResponse<TLogs, TCtx> {
10
+ handlerResponse: HandlerResponse;
11
+ action?: {
12
+ state: string;
13
+ logs: TLogs;
14
+ ctx?: TCtx;
15
+ };
16
+ }
17
+ export interface StateHandlerCtx {
18
+ /**
19
+ * The raw message object received from sqs
20
+ */
21
+ rawMessage: Message;
22
+ /**
23
+ * Instace of pino.Logger with the execution context
24
+ */
25
+ logger: pino.Logger;
26
+ /**
27
+ * Correlation IDs captured in message attributes
28
+ */
29
+ correlationIDs: Record<string, string>;
30
+ /**
31
+ * benefitsAPI Axios instance
32
+ */
33
+ benefitsAPI: AxiosInstance;
34
+ /**
35
+ * lgProxy Axios instance
36
+ */
37
+ lgProxyAPI: AxiosInstance;
38
+ /**
39
+ * apiBenup Axios instance
40
+ */
41
+ benupAPI: AxiosInstance;
42
+ /**
43
+ * universAPI Axios instance
44
+ */
45
+ universAPI: AxiosInstance;
46
+ /**
47
+ * benefitDefinition
48
+ */
49
+ benefitDefinition: BenefitDefinition;
50
+ }
51
+ /**
52
+ * State Handler
53
+ * @param TAction - Action type
54
+ * @param TLogs - Logs type
55
+ * @param TCtx - Context type
56
+ */
57
+ export type StateHandler<TAction, TLogs, TCtx> = (message: MessageBody, action: TAction, ctx: StateHandlerCtx) => Promise<StateHandlerResponse<TLogs, TCtx>>;
58
+ export type StateHandlerConfig = {
59
+ maxRetries: number;
60
+ delayBetweenRetries: number;
61
+ delayMode: 'fixed' | 'exponential';
62
+ };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@benup/bensdk",
3
- "version": "1.2.4",
3
+ "version": "1.3.1",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1",
8
8
  "start": "tsx src/cli/app.ts",
9
- "build": "tsc && cp -r src/cli/templates bin/src/cli/"
9
+ "build": "tsc && cp -r src/cli/templates bin/src/cli/ && cp -r src/lib/ bin/lib/"
10
10
  },
11
11
  "repository": {
12
12
  "url": "https://developers.benup.io"