@benup/bensdk 1.0.7 → 1.1.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.
Files changed (30) hide show
  1. package/README.md +3 -4
  2. package/bin/src/cli/app.js +7 -8
  3. package/bin/src/cli/app.js.map +1 -1
  4. package/bin/src/cli/init.js +49 -33
  5. package/bin/src/cli/init.js.map +1 -1
  6. package/bin/src/cli/templates/benefit-definition.template.ts +48 -2
  7. package/bin/src/cli/templates/benefit-definition.types.template.ts +29 -1
  8. package/bin/src/cli/templates/bensdk-cli/generate.ts +33 -29
  9. package/bin/src/cli/templates/bensdk-cli/lib/benefit-definition.schema.ts +20 -3
  10. package/bin/src/cli/templates/bensdk-cli/lib/state-machine.ts +65 -60
  11. package/bin/src/cli/templates/bensdk-cli/templates/state.handler.template.ts +6 -7
  12. package/bin/src/cli/templates/bensdk-cli/validate.ts +22 -20
  13. package/bin/src/cli/templates/bensdk-lib/types/action-base.type.ts +208 -170
  14. package/bin/src/cli/templates/bensdk-lib/types/action.types.ts +11 -9
  15. package/bin/src/cli/templates/bensdk-lib/types/base-deduction.type.ts +191 -175
  16. package/bin/src/cli/templates/bensdk-lib/types/base-dependent.type.ts +204 -0
  17. package/bin/src/cli/templates/bensdk-lib/types/base-recharge.type.ts +188 -172
  18. package/bin/src/cli/templates/bensdk-lib/types/benefits-definition.type.ts +49 -34
  19. package/bin/src/cli/templates/bensdk-lib/types/grant-revoke.type.ts +183 -167
  20. package/bin/src/cli/templates/bensdk-local-server/app.ts +43 -48
  21. package/bin/src/cli/templates/bensdk-viewer/.svelte-kit/tsconfig.json +37 -48
  22. package/bin/src/cli/templates/bensdk-viewer/src/app.d.ts +7 -7
  23. package/bin/src/cli/templates/bensdk-viewer/src/app.html +9 -9
  24. package/bin/src/cli/templates/bensdk-viewer/startup.ts +4 -5
  25. package/bin/src/cli/templates/bensdk-viewer/svelte.config.js +9 -9
  26. package/bin/src/cli/templates/bensdk-viewer/tsconfig.json +17 -17
  27. package/bin/src/cli/templates/bensdk-viewer/vite.config.ts +2 -4
  28. package/bin/src/cli/utils/zip.js +2 -2
  29. package/bin/src/cli/utils/zip.js.map +1 -1
  30. package/package.json +3 -1
@@ -1,14 +1,14 @@
1
1
  /* eslint-disable jsdoc/require-jsdoc */
2
+ // import benefitDefinition from '../benefit-definition';
2
3
  // import {Action} from "../benefit-definition.types.js";
3
- import benefitDefinition from '../benefit-definition';
4
4
  import { StateHandler } from '../lib/types/state.handler.type';
5
- import { getLogsFromResponse } from "../lib/utils/logs";
5
+ import { getLogsFromResponse } from '../lib/utils/logs';
6
6
 
7
7
  export interface BenefitResponse {
8
8
  values: string[];
9
9
  }
10
10
 
11
- // StateMachine,
11
+ // StateMachine,
12
12
 
13
13
  export const options = {
14
14
  maxRetries: 10
@@ -33,15 +33,14 @@ const handler: StateHandler<
33
33
  */
34
34
  return {
35
35
  handlerResponse: {
36
- response: "UNACK"
37
- },
36
+ response: 'UNACK'
37
+ }
38
38
  };
39
39
  }
40
40
 
41
-
42
41
  return {
43
42
  handlerResponse: {
44
- response: "ACK"
43
+ response: 'ACK'
45
44
  },
46
45
  action: {
47
46
  state: stateMachine.next,
@@ -1,19 +1,18 @@
1
1
  /// <reference types="node" />
2
- import { BenefitDefinitionSchema } from "./lib/benefit-definition.schema";
3
- import fs from "fs";
4
- import validateStateMachine, {
5
- finalStates,
6
- initialStates,
7
- } from "./lib/state-machine";
2
+ import { BenefitDefinitionSchema } from './lib/benefit-definition.schema';
3
+ import validateStateMachine, { finalStates, initialStates } from './lib/state-machine';
8
4
 
9
5
  function validateStateMachineStatesInLogs(benefitDefinition: any) {
10
6
  // Get all states from each action type's state machine
11
7
  const statesByAction = Object.entries(benefitDefinition.stateMachine)
12
8
  .filter(([action]) => benefitDefinition.availableActions.includes(action))
13
- .reduce((acc, [action, states]) => {
14
- acc[action] = Object.keys(states as object);
15
- return acc;
16
- }, {} as Record<string, string[]>);
9
+ .reduce(
10
+ (acc, [action, states]) => {
11
+ acc[action] = Object.keys(states as object);
12
+ return acc;
13
+ },
14
+ {} as Record<string, string[]>
15
+ );
17
16
 
18
17
  // Check if each state has a corresponding log schema
19
18
  Object.entries(statesByAction).forEach(([action, states]) => {
@@ -30,11 +29,7 @@ function validateStateMachineStatesInLogs(benefitDefinition: any) {
30
29
  );
31
30
 
32
31
  if (missingStates.length > 0) {
33
- throw new Error(
34
- `Missing log schemas for states in ${action}: ${missingStates.join(
35
- ", "
36
- )}`
37
- );
32
+ throw new Error(`Missing log schemas for states in ${action}: ${missingStates.join(', ')}`);
38
33
  }
39
34
  });
40
35
  }
@@ -46,22 +41,29 @@ export async function validateBenefitDefinition(benefitDefinition: any) {
46
41
  validateStateMachine(benefitDefinition.stateMachine.GRANT);
47
42
  validateStateMachine(benefitDefinition.stateMachine.REVOKE);
48
43
 
49
- if (benefitDefinition.availableActions.includes("RECHARGE")) {
44
+ if (benefitDefinition.availableActions.includes('RECHARGE')) {
50
45
  validateStateMachine(benefitDefinition.stateMachine.RECHARGE);
51
46
  }
52
47
 
48
+ if (benefitDefinition.availableActions.includes('GRANT_DEPENDENT')) {
49
+ validateStateMachine(benefitDefinition.stateMachine.GRANT_DEPENDENT);
50
+ }
51
+
52
+ if (benefitDefinition.availableActions.includes('REVOKE_DEPENDENT')) {
53
+ validateStateMachine(benefitDefinition.stateMachine.REVOKE_DEPENDENT);
54
+ }
55
+
53
56
  validateStateMachineStatesInLogs(benefitDefinition);
54
57
 
55
- console.log("Benefit definition is valid");
58
+ console.log('Benefit definition is valid');
56
59
  } catch (error) {
57
- console.error("Failed to validate benefit definition:", error);
60
+ console.error('Failed to validate benefit definition:', error);
58
61
  process.exit(1);
59
62
  }
60
63
  }
61
64
 
62
65
  async function main() {
63
- const benefitDefinition = (await import(`${process.cwd()}/src/benefit-definition.ts` ))
64
- .default;
66
+ const benefitDefinition = (await import(`${process.cwd()}/src/benefit-definition.ts`)).default;
65
67
 
66
68
  await validateBenefitDefinition(benefitDefinition);
67
69
  }
@@ -1,177 +1,214 @@
1
1
  export type ActionBase = {
2
- _id: string;
3
- batchID?: string | undefined;
4
- parentActionID?: string | undefined;
5
- fingerprint?: string | undefined;
6
- benefitID: string;
7
- action: "GRANT" | "REVOKE" | "DEDUCTION" | "RECHARGE";
8
- state: string;
9
- target: {
10
- employee: {
11
- _id: string;
12
- name: string;
13
- /** CPF in format 000.000.000-00 */
14
- cpf: string;
15
- birthdate: string;
16
- address: {
17
- street: string;
18
- number: string;
19
- complement?: string | undefined;
20
- neighborhood: string;
21
- city: string;
22
- state: string;
23
- zipCode: string;
24
- country: string;
25
- };
26
- email?: string | undefined;
27
- createdAt: string;
28
- updatedAt?: string | undefined;
2
+ _id: string;
3
+ batchID?: string | undefined;
4
+ parentActionID?: string | undefined;
5
+ fingerprint?: string | undefined;
6
+ benefitID: string;
7
+ action: 'GRANT' | 'REVOKE' | 'DEDUCTION' | 'RECHARGE' | 'GRANT_DEPENDENT' | 'REVOKE_DEPENDENT';
8
+ state: string;
9
+ target: {
10
+ dependent: {
11
+ externalDependentID: string;
12
+ externalDependentCode: string;
13
+ name: string;
14
+ /** CPF in format 000.000.000-00 */
15
+ cpf: string;
16
+ birthDate: string;
17
+ sex: 'M' | 'F';
18
+ relationshipType: string;
19
+ maritalStatus: string;
20
+ benefits: {
21
+ [x: string]: {
22
+ value: boolean;
23
+ options?: {} | undefined;
29
24
  };
30
- employmentContract: {
31
- _id: string;
32
- companyID: string;
33
- customerID: string;
34
- accountID: string;
35
- establishmentID: string;
36
- admissionDate: string;
37
- externalEmploymentContractID: string;
38
- position: {
39
- code: number;
40
- description: string;
41
- };
42
- establishment: {
43
- code: number;
44
- description: string;
45
- };
46
- startDateOfCurrentSituation: string;
47
- situation: {
48
- code: number;
49
- description: string;
50
- };
51
- benefits: {
52
- [x: string]: {
53
- value: boolean;
54
- options?: {} | undefined;
55
- };
56
- };
57
- status: "ADMITTED" | "DISMISSED" | "SUSPENDED" | "IGNORED";
58
- fingerprint: string;
59
- createdAt: string;
60
- isDeleted?: boolean;
61
- };
62
- company: {
63
- _id: string;
64
- accountID: string;
65
- cnpj: string;
66
- /** razao social */
67
- businessName: string;
68
- /** nome fantasia */
69
- tradeName: string;
70
- address?: {
71
- street: string;
72
- number: string;
73
- complement?: string | undefined;
74
- neighborhood: string;
75
- city: string;
76
- state: string;
77
- zipCode: string;
78
- country: string;
79
- } | undefined;
80
- createdAt: string;
81
- updatedAt?: string | undefined;
82
- };
83
- payrollConfiguration: {
84
- _id: string;
85
- accountID: string;
86
- companyID: string;
87
- payrollSystem: "LG_ONPREMISE_VLI" | "LG_CLOUD" | "LG_ONPREMISE_AMBEV";
88
- eligibilitySource: "BENEFIT_MODULE" | "ADDITIONAL_ATTRIBUTE";
89
- productToggle?: {
90
- isOcherstratorActive?: boolean;
91
- isIntegratorActive?: boolean;
92
- };
93
- cutoffDay: number;
94
- modifiedContractsWindowInDays: number;
95
- dataMapping: {
96
- eligibility?: {
97
- benefitID: string;
98
- eligibilityType: "BENEFIT" | "ATTRIBUTE" | "ELIGIBLE_TO_ALL";
99
- eligibilityCode?: (number | string) | undefined;
100
- eligibilityMap?: {
101
- eligibilityValue: (boolean | number) | string;
102
- isEligible: boolean;
103
- options: {};
104
- }[] | undefined;
105
- }[] | undefined;
106
- deduction?: {
107
- benefitID: string;
108
- deduction: {
109
- externalPayrollID: number;
110
- externalPayrollEventID: number;
111
- };
112
- refund?: {
113
- externalPayrollID: number;
114
- externalPayrollEventID: number;
115
- } | undefined;
116
- meta?: {} | undefined;
117
- }[] | undefined;
118
- recharge?: {
119
- cronID: string;
120
- label?: string | undefined;
121
- eventID: number;
122
- sheetID: number;
123
- benefitID: string;
124
- productID?: string | undefined;
125
- executionCron: string;
126
- rechargeDate?: number | undefined;
127
- }[] | undefined;
128
- situation?: {
129
- code: number;
130
- value: "ADMITTED" | "DISMISSED" | "SUSPENDED" | "IGNORED";
131
- }[] | undefined;
132
- };
133
- version: 2;
134
- isDeleted?: boolean;
135
- createdAt: string;
136
- updatedAt?: string | undefined;
137
- deletedAt?: string | undefined;
138
- };
139
- establishment: {
140
- _id: string;
141
- accountID: string;
142
- companyID: string;
143
- cnpj: string;
144
- /** razao social */
145
- businessName: string;
146
- /** nome fantasia */
147
- tradeName: string;
148
- /** código da empresa no sistema de folha */
149
- externalEstablishmentID: string;
150
- address?: {
151
- street: string;
152
- number: string;
153
- complement?: string | undefined;
154
- neighborhood: string;
155
- city: string;
156
- state: string;
157
- zipCode: string;
158
- country: string;
159
- } | undefined;
160
- createdAt: string;
161
- updatedAt?: string | undefined;
25
+ };
26
+ status: 'LINKED' | 'UNLINKED';
27
+ };
28
+ employee: {
29
+ _id: string;
30
+ name: string;
31
+ /** CPF in format 000.000.000-00 */
32
+ cpf: string;
33
+ birthdate: string;
34
+ address: {
35
+ street: string;
36
+ number: string;
37
+ complement?: string | undefined;
38
+ neighborhood: string;
39
+ city: string;
40
+ state: string;
41
+ zipCode: string;
42
+ country: string;
43
+ };
44
+ email?: string | undefined;
45
+ createdAt: string;
46
+ updatedAt?: string | undefined;
47
+ };
48
+ employmentContract: {
49
+ _id: string;
50
+ companyID: string;
51
+ customerID: string;
52
+ accountID: string;
53
+ establishmentID: string;
54
+ admissionDate: string;
55
+ externalEmploymentContractID: string;
56
+ position: {
57
+ code: number;
58
+ description: string;
59
+ };
60
+ establishment: {
61
+ code: number;
62
+ description: string;
63
+ };
64
+ startDateOfCurrentSituation: string;
65
+ situation: {
66
+ code: number;
67
+ description: string;
68
+ };
69
+ benefits: {
70
+ [x: string]: {
71
+ value: boolean;
72
+ options?: {} | undefined;
162
73
  };
74
+ };
75
+ status: 'ADMITTED' | 'DISMISSED' | 'SUSPENDED' | 'IGNORED';
76
+ fingerprint: string;
77
+ createdAt: string;
78
+ isDeleted?: boolean;
79
+ };
80
+ company: {
81
+ _id: string;
82
+ accountID: string;
83
+ cnpj: string;
84
+ /** razao social */
85
+ businessName: string;
86
+ /** nome fantasia */
87
+ tradeName: string;
88
+ address?:
89
+ | {
90
+ street: string;
91
+ number: string;
92
+ complement?: string | undefined;
93
+ neighborhood: string;
94
+ city: string;
95
+ state: string;
96
+ zipCode: string;
97
+ country: string;
98
+ }
99
+ | undefined;
100
+ createdAt: string;
101
+ updatedAt?: string | undefined;
102
+ };
103
+ payrollConfiguration: {
104
+ _id: string;
105
+ accountID: string;
106
+ companyID: string;
107
+ payrollSystem: 'LG_ONPREMISE_VLI' | 'LG_CLOUD' | 'LG_ONPREMISE_AMBEV';
108
+ eligibilitySource: 'BENEFIT_MODULE' | 'ADDITIONAL_ATTRIBUTE';
109
+ productToggle?: {
110
+ isOcherstratorActive?: boolean;
111
+ isIntegratorActive?: boolean;
112
+ };
113
+ cutoffDay: number;
114
+ modifiedContractsWindowInDays: number;
115
+ dataMapping: {
116
+ eligibility?:
117
+ | {
118
+ benefitID: string;
119
+ eligibilityType: 'BENEFIT' | 'ATTRIBUTE' | 'ELIGIBLE_TO_ALL';
120
+ eligibilityCode?: (number | string) | undefined;
121
+ eligibilityMap?:
122
+ | {
123
+ eligibilityValue: (boolean | number) | string;
124
+ isEligible: boolean;
125
+ options: {};
126
+ }[]
127
+ | undefined;
128
+ }[]
129
+ | undefined;
130
+ deduction?:
131
+ | {
132
+ benefitID: string;
133
+ deduction: {
134
+ externalPayrollID: number;
135
+ externalPayrollEventID: number;
136
+ };
137
+ refund?:
138
+ | {
139
+ externalPayrollID: number;
140
+ externalPayrollEventID: number;
141
+ }
142
+ | undefined;
143
+ meta?: {} | undefined;
144
+ }[]
145
+ | undefined;
146
+ recharge?:
147
+ | {
148
+ rechargeID: string;
149
+ label?: string | undefined;
150
+ eventID: number;
151
+ sheetID: number;
152
+ benefitID: string;
153
+ productID?: string | undefined;
154
+ executionCron: string;
155
+ rechargeDate?: number | undefined;
156
+ }[]
157
+ | undefined;
158
+ situation?:
159
+ | {
160
+ code: number;
161
+ value: 'ADMITTED' | 'DISMISSED' | 'SUSPENDED' | 'IGNORED';
162
+ }[]
163
+ | undefined;
164
+ };
165
+ version: 2;
166
+ isDeleted?: boolean;
167
+ createdAt: string;
168
+ updatedAt?: string | undefined;
169
+ deletedAt?: string | undefined;
170
+ };
171
+ establishment: {
172
+ _id: string;
173
+ accountID: string;
174
+ companyID: string;
175
+ cnpj: string;
176
+ /** razao social */
177
+ businessName: string;
178
+ /** nome fantasia */
179
+ tradeName: string;
180
+ /** código da empresa no sistema de folha */
181
+ externalEstablishmentID: string;
182
+ address?:
183
+ | {
184
+ street: string;
185
+ number: string;
186
+ complement?: string | undefined;
187
+ neighborhood: string;
188
+ city: string;
189
+ state: string;
190
+ zipCode: string;
191
+ country: string;
192
+ }
193
+ | undefined;
194
+ createdAt: string;
195
+ updatedAt?: string | undefined;
163
196
  };
164
- eligibilityOptions: {};
165
- ctx?: {} | undefined;
166
- log?: {} | undefined;
167
- origin: string;
168
- rechargeInput?: {
197
+ };
198
+ eligibilityOptions: {};
199
+ ctx?: {} | undefined;
200
+ log?: {} | undefined;
201
+ origin: string;
202
+ rechargeInput?:
203
+ | {
169
204
  externalSheetID: string;
170
205
  externalEventID: string;
171
206
  date: string;
172
207
  value: number;
173
- } | undefined;
174
- deductionInput?: {
208
+ }
209
+ | undefined;
210
+ deductionInput?:
211
+ | {
175
212
  payrollSystem: string;
176
213
  externalSheetID: string;
177
214
  externalEventID: string;
@@ -179,7 +216,8 @@ export type ActionBase = {
179
216
  isAccumulative: boolean;
180
217
  date: string;
181
218
  value: number;
182
- } | undefined;
183
- createdAt: string;
184
- updatedAt?: string | undefined;
185
- };
219
+ }
220
+ | undefined;
221
+ createdAt: string;
222
+ updatedAt?: string | undefined;
223
+ };
@@ -1,11 +1,13 @@
1
- import { ActionBase } from "./action-base.type"
2
- import { ActionBaseDeduction } from "./base-deduction.type"
3
- import { ActionBaseRecharge } from "./base-recharge.type"
4
- import { ActionBaseGrantRevoke } from "./grant-revoke.type"
1
+ import { ActionBase } from './action-base.type';
2
+ import { ActionBaseDeduction } from './base-deduction.type';
3
+ import { ActionBaseDependent } from './base-dependent.type';
4
+ import { ActionBaseRecharge } from './base-recharge.type';
5
+ import { ActionBaseGrantRevoke } from './grant-revoke.type';
5
6
 
6
7
  export {
7
- ActionBase,
8
- ActionBaseDeduction,
9
- ActionBaseRecharge,
10
- ActionBaseGrantRevoke
11
- }
8
+ ActionBase,
9
+ ActionBaseDeduction,
10
+ ActionBaseDependent,
11
+ ActionBaseGrantRevoke,
12
+ ActionBaseRecharge
13
+ };