@benup/bensdk 1.13.4 → 1.13.9-0

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.
@@ -1,15 +1,20 @@
1
1
  import z from 'zod';
2
- import { EmploymentContracts } from '@benup-dev/benup-api';
2
+ import { PayrollConfiguration } from '@benup-dev/benup-api';
3
3
  import { AxiosInstance } from 'axios';
4
+ import pino from 'pino';
5
+ import { EmploymentContractSchema } from '../schemas/action.schema';
4
6
  import { BenefitDefinitionSchema } from '../schemas/benefit-definition.schema';
5
7
  import { LockHelper } from './lib/lock-helper.lib.type';
6
8
  import { TokenHelper } from './lib/token-helper.lib.type';
7
9
  import { StateHandlerCtx, WebhookRequest, WebhookResponse } from './state-handler.types';
8
10
  type Base = z.infer<typeof BenefitDefinitionSchema>;
11
+ type PayrollConfigurationType = z.infer<typeof PayrollConfiguration.default.collection.v3.PayrollConfigurationSchema>;
12
+ type BenefitGeneralOptions = NonNullable<NonNullable<PayrollConfigurationType['dataMapping']['eligibility']>[number]['options']>;
9
13
  export type AuthHandlerCtx = {
10
14
  tokenHelper: TokenHelper;
11
15
  lockHelper: LockHelper;
12
- employmentContract: z.infer<typeof EmploymentContracts.default.collection.default>;
16
+ employmentContract: z.infer<typeof EmploymentContractSchema>;
17
+ benefitGeneralOptions?: BenefitGeneralOptions;
13
18
  };
14
19
  export type AuthHandlerResult = {
15
20
  outcome: 'FAILED';
@@ -35,6 +40,46 @@ export type RateLimitConfig = {
35
40
  maxExecutionsPerWindow: number;
36
41
  windowSeconds: number;
37
42
  };
43
+ export type DeductionSftpHandlerInput = {
44
+ deductionID: string;
45
+ payrollConfigurationID: string;
46
+ accountID: string;
47
+ companyID: string;
48
+ rawLineNumber: number;
49
+ rawLine: string;
50
+ };
51
+ export type DeductionSftpHandlerCtx = {
52
+ logger: pino.Logger;
53
+ benupAPI: AxiosInstance;
54
+ };
55
+ export type DeductionEmploymentContractHandlerInput = {
56
+ deductionID: string;
57
+ payrollConfigurationID: string;
58
+ accountID: string;
59
+ companyID: string;
60
+ employmentContractID: string;
61
+ };
62
+ export type DeductionEmploymentContractHandlerCtx = {
63
+ logger: pino.Logger;
64
+ benupAPI: AxiosInstance;
65
+ benefitPartnerAPI?: AxiosInstance;
66
+ };
67
+ export type DeductionPlanResult = {
68
+ planResult: 'FAILED';
69
+ reason: string;
70
+ } | {
71
+ planResult: 'SUCCEEDED';
72
+ plannedPayrollDeduction: {
73
+ employmentContractID: string;
74
+ customerID: string;
75
+ externalEmploymentContractID: string;
76
+ value: number;
77
+ date: string;
78
+ isAccumulative: boolean;
79
+ externalPayrollID: string;
80
+ externalEventID: string;
81
+ };
82
+ };
38
83
  export type BenefitDefinition = Omit<Base, 'stateMachine'> & {
39
84
  rateLimit?: RateLimitConfig;
40
85
  /**
@@ -57,7 +102,7 @@ export type BenefitDefinition = Omit<Base, 'stateMachine'> & {
57
102
  } & any;
58
103
  DEDUCTION?: {
59
104
  REQUESTED_DEDUCTION: {
60
- next: 'REQUESTED_PAYROLL_DEDUCTION' | string;
105
+ next: 'DEDUCTION_REQUESTED' | string;
61
106
  };
62
107
  } & any;
63
108
  };
@@ -65,8 +110,16 @@ export type BenefitDefinition = Omit<Base, 'stateMachine'> & {
65
110
  handler: (request: WebhookRequest<any>, ctx: StateHandlerCtx) => Promise<WebhookResponse>;
66
111
  };
67
112
  auth?: {
68
- handler: (credentials: any, ctx: any) => Promise<AuthHandlerResult>;
113
+ handler: (credentials: any[], ctx: any) => Promise<AuthHandlerResult>;
69
114
  credentialsHealthCheckHandler?: (credentials: any) => Promise<CredentialsHealthCheckResult>;
70
115
  };
116
+ deduction?: {
117
+ sftp?: {
118
+ rawLineHandler: (input: DeductionSftpHandlerInput, ctx: DeductionSftpHandlerCtx) => Promise<DeductionPlanResult>;
119
+ };
120
+ employmentContract?: {
121
+ handler: (input: DeductionEmploymentContractHandlerInput, ctx: DeductionEmploymentContractHandlerCtx) => Promise<DeductionPlanResult>;
122
+ };
123
+ };
71
124
  };
72
125
  export {};
@@ -1,4 +1,6 @@
1
+ import { ActionAfterBeforeRecharge } from '../action.types';
1
2
  export interface ActionHelper {
3
+ findHooksByBatchID: (batchID: string) => Promise<ActionAfterBeforeRecharge[]>;
2
4
  findByContext: (ctx: any) => Promise<any[]>;
3
5
  findByExecutionID: (executionID: string) => Promise<any[]>;
4
6
  updateOne: (state: string, logs: any, body: any, action: any) => Promise<void>;
@@ -1,11 +1,13 @@
1
1
  type GetTokenParameters = {
2
2
  accountID: string;
3
3
  companyID: string;
4
+ cnpj?: string;
4
5
  benefitID: string;
5
6
  };
6
7
  type SetTokenParameters = {
7
8
  accountID: string;
8
9
  companyID: string;
10
+ cnpj?: string;
9
11
  benefitID: string;
10
12
  valueToBeStored: string;
11
13
  storeForSeconds: number;
@@ -78,6 +78,12 @@ export interface StateHandlerCtx {
78
78
  * Used to notify pc-recharge-api when a RECHARGE action reaches a terminal state.
79
79
  */
80
80
  pcRechargeAPI?: AxiosInstance;
81
+ /**
82
+ * pcDeductionAPI Axios instance
83
+ * Present only when PC_DEDUCTION_API_URL is configured.
84
+ * Used to notify pc-deduction-api when a DEDUCTION action reaches a terminal state.
85
+ */
86
+ pcDeductionAPI?: AxiosInstance;
81
87
  /**
82
88
  * deductionFileIngestionHelper
83
89
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@benup/bensdk",
3
- "version": "1.13.4",
3
+ "version": "1.13.9-0",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {