@benup/bensdk 1.0.8 → 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,170 +1,186 @@
1
1
  export type ActionBaseGrantRevoke = {
2
- _id: string;
3
- batchID?: string | undefined;
4
- parentActionID?: string | undefined;
5
- fingerprint?: string | undefined;
6
- benefitID: string;
7
- action: "GRANT" | "REVOKE";
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;
29
- };
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
- rechargeID: 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;
2
+ _id: string;
3
+ batchID?: string | undefined;
4
+ parentActionID?: string | undefined;
5
+ fingerprint?: string | undefined;
6
+ benefitID: string;
7
+ action: 'GRANT' | 'REVOKE';
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;
29
+ };
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;
162
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
+ | {
72
+ street: string;
73
+ number: string;
74
+ complement?: string | undefined;
75
+ neighborhood: string;
76
+ city: string;
77
+ state: string;
78
+ zipCode: string;
79
+ country: string;
80
+ }
81
+ | undefined;
82
+ createdAt: string;
83
+ updatedAt?: string | undefined;
84
+ };
85
+ payrollConfiguration: {
86
+ _id: string;
87
+ accountID: string;
88
+ companyID: string;
89
+ payrollSystem: 'LG_ONPREMISE_VLI' | 'LG_CLOUD' | 'LG_ONPREMISE_AMBEV';
90
+ eligibilitySource: 'BENEFIT_MODULE' | 'ADDITIONAL_ATTRIBUTE';
91
+ productToggle?: {
92
+ isOcherstratorActive?: boolean;
93
+ isIntegratorActive?: boolean;
94
+ };
95
+ cutoffDay: number;
96
+ modifiedContractsWindowInDays: number;
97
+ dataMapping: {
98
+ eligibility?:
99
+ | {
100
+ benefitID: string;
101
+ eligibilityType: 'BENEFIT' | 'ATTRIBUTE' | 'ELIGIBLE_TO_ALL';
102
+ eligibilityCode?: (number | string) | undefined;
103
+ eligibilityMap?:
104
+ | {
105
+ eligibilityValue: (boolean | number) | string;
106
+ isEligible: boolean;
107
+ options: {};
108
+ }[]
109
+ | undefined;
110
+ }[]
111
+ | undefined;
112
+ deduction?:
113
+ | {
114
+ benefitID: string;
115
+ deduction: {
116
+ externalPayrollID: number;
117
+ externalPayrollEventID: number;
118
+ };
119
+ refund?:
120
+ | {
121
+ externalPayrollID: number;
122
+ externalPayrollEventID: number;
123
+ }
124
+ | undefined;
125
+ meta?: {} | undefined;
126
+ }[]
127
+ | undefined;
128
+ recharge?:
129
+ | {
130
+ rechargeID: string;
131
+ label?: string | undefined;
132
+ eventID: number;
133
+ sheetID: number;
134
+ benefitID: string;
135
+ productID?: string | undefined;
136
+ executionCron: string;
137
+ rechargeDate?: number | undefined;
138
+ }[]
139
+ | undefined;
140
+ situation?:
141
+ | {
142
+ code: number;
143
+ value: 'ADMITTED' | 'DISMISSED' | 'SUSPENDED' | 'IGNORED';
144
+ }[]
145
+ | undefined;
146
+ };
147
+ version: 2;
148
+ isDeleted?: boolean;
149
+ createdAt: string;
150
+ updatedAt?: string | undefined;
151
+ deletedAt?: string | undefined;
152
+ };
153
+ establishment: {
154
+ _id: string;
155
+ accountID: string;
156
+ companyID: string;
157
+ cnpj: string;
158
+ /** razao social */
159
+ businessName: string;
160
+ /** nome fantasia */
161
+ tradeName: string;
162
+ /** código da empresa no sistema de folha */
163
+ externalEstablishmentID: string;
164
+ address?:
165
+ | {
166
+ street: string;
167
+ number: string;
168
+ complement?: string | undefined;
169
+ neighborhood: string;
170
+ city: string;
171
+ state: string;
172
+ zipCode: string;
173
+ country: string;
174
+ }
175
+ | undefined;
176
+ createdAt: string;
177
+ updatedAt?: string | undefined;
163
178
  };
164
- eligibilityOptions: {};
165
- ctx?: {} | undefined;
166
- log?: {} | undefined;
167
- origin: string;
168
- createdAt: string;
169
- updatedAt?: string | undefined;
170
- };
179
+ };
180
+ eligibilityOptions: {};
181
+ ctx?: {} | undefined;
182
+ log?: {} | undefined;
183
+ origin: string;
184
+ createdAt: string;
185
+ updatedAt?: string | undefined;
186
+ };
@@ -1,48 +1,44 @@
1
- import { serve } from '@hono/node-server'
2
- import { Hono } from 'hono'
3
- import { WebSocketServer } from 'ws'
4
- import benefitsDefinition from '../../src/benefit-definition'
5
- import { cors } from "hono/cors";
6
- import pino from "pino";
7
- import { PassThrough } from 'stream'
8
-
1
+ import { serve } from '@hono/node-server';
2
+ import { Hono } from 'hono';
3
+ import { cors } from 'hono/cors';
4
+ import pino from 'pino';
5
+ import { PassThrough } from 'stream';
6
+ import { WebSocketServer } from 'ws';
7
+ import benefitsDefinition from '../../src/benefit-definition';
9
8
 
10
9
  const logStream = new PassThrough();
11
- const logger = pino(logStream)
12
- const app = new Hono()
13
- const connections = new Set<WebSocket>()
10
+ const logger = pino(logStream);
11
+ const app = new Hono();
12
+ const connections = new Set<WebSocket>();
14
13
  const onLog = (chunk: Buffer) => {
15
- connections.forEach(ws => {
14
+ connections.forEach((ws) => {
16
15
  if (ws.readyState === WebSocket.OPEN) {
17
- ws.send(chunk.toString())
16
+ ws.send(chunk.toString());
18
17
  }
19
- })
18
+ });
20
19
  };
21
20
 
22
21
  logStream.on('data', onLog);
23
22
 
24
-
25
-
26
- app.use(
27
- cors()
28
- );
23
+ app.use(cors());
29
24
 
30
25
  app.get('/state-machine', async (c) => {
31
26
  const response = benefitsDefinition.stateMachine;
32
27
 
33
- return c.json(response, 200)
34
- })
35
-
36
-
28
+ return c.json(response, 200);
29
+ });
37
30
 
38
31
  app.post('/run-action', async (c) => {
39
- const payload = await c.req.json()
32
+ const payload = await c.req.json();
40
33
  const { run, requestPayload, message, currentContext } = payload;
41
34
  const fileName = `${run.toLowerCase()}.handler.ts`;
42
35
  const fileDir = `../../src/handlers/${fileName}`;
43
- const handler = await import(fileDir)
36
+ const handler = await import(fileDir);
44
37
 
45
- const { ctxMock } = (await import('../../context.config')).createStateHandlerCtxMock(benefitsDefinition, logger)
38
+ const { ctxMock } = (await import('../../context.config')).createStateHandlerCtxMock(
39
+ benefitsDefinition,
40
+ logger
41
+ );
46
42
 
47
43
  logger.info(`Running: ${fileDir} to ${requestPayload.target.employee.name}`);
48
44
  logger.info(`Current context: ${JSON.stringify(currentContext)}`);
@@ -54,39 +50,38 @@ app.post('/run-action', async (c) => {
54
50
  ...requestPayload,
55
51
  ctx: currentContext
56
52
  },
57
- ctxMock)
58
- return c.json(response, 200)
59
- })
60
-
53
+ ctxMock
54
+ );
55
+ return c.json(response, 200);
56
+ });
61
57
 
62
-
63
- const wss = new WebSocketServer({ noServer: true })
58
+ const wss = new WebSocketServer({ noServer: true });
64
59
  wss.on('connection', (ws) => {
65
- connections.add(ws)
60
+ connections.add(ws);
66
61
 
67
62
  ws.on('message', (message) => {
68
- console.log('Message received:', message.toString())
69
- })
63
+ console.log('Message received:', message.toString());
64
+ });
70
65
 
71
66
  ws.on('close', () => {
72
- console.log('Close connection')
73
- connections.delete(ws)
74
- })
75
- })
67
+ console.log('Close connection');
68
+ connections.delete(ws);
69
+ });
70
+ });
76
71
 
77
72
  export async function startServer() {
78
73
  return new Promise((res: any, rej: any) => {
79
- const server = serve({ fetch: app.fetch, port: 3000 })
74
+ const server = serve({ fetch: app.fetch, port: 3000 });
80
75
  server.on('upgrade', (request, socket, head) => {
81
- const { url } = request
76
+ const { url } = request;
82
77
  if (url === '/ws') {
83
78
  wss.handleUpgrade(request, socket, head, (ws) => {
84
- wss.emit('connection', ws, request)
85
- })
79
+ wss.emit('connection', ws, request);
80
+ });
86
81
  } else {
87
- socket.destroy()
82
+ socket.destroy();
88
83
  }
89
- })
90
- res()
91
- })
92
- };
84
+ });
85
+ res();
86
+ });
87
+ }
@@ -1,49 +1,38 @@
1
1
  {
2
- "compilerOptions": {
3
- "paths": {
4
- "$lib": [
5
- "../src/lib"
6
- ],
7
- "$lib/*": [
8
- "../src/lib/*"
9
- ]
10
- },
11
- "rootDirs": [
12
- "..",
13
- "./types"
14
- ],
15
- "verbatimModuleSyntax": true,
16
- "isolatedModules": true,
17
- "lib": [
18
- "esnext",
19
- "DOM",
20
- "DOM.Iterable"
21
- ],
22
- "moduleResolution": "bundler",
23
- "module": "esnext",
24
- "noEmit": true,
25
- "target": "esnext"
26
- },
27
- "include": [
28
- "ambient.d.ts",
29
- "non-ambient.d.ts",
30
- "./types/**/$types.d.ts",
31
- "../vite.config.js",
32
- "../vite.config.ts",
33
- "../src/**/*.js",
34
- "../src/**/*.ts",
35
- "../src/**/*.svelte",
36
- "../tests/**/*.js",
37
- "../tests/**/*.ts",
38
- "../tests/**/*.svelte"
39
- ],
40
- "exclude": [
41
- "../node_modules/**",
42
- "../src/service-worker.js",
43
- "../src/service-worker/**/*.js",
44
- "../src/service-worker.ts",
45
- "../src/service-worker/**/*.ts",
46
- "../src/service-worker.d.ts",
47
- "../src/service-worker/**/*.d.ts"
48
- ]
49
- }
2
+ "compilerOptions": {
3
+ "paths": {
4
+ "$lib": ["../src/lib"],
5
+ "$lib/*": ["../src/lib/*"]
6
+ },
7
+ "rootDirs": ["..", "./types"],
8
+ "verbatimModuleSyntax": true,
9
+ "isolatedModules": true,
10
+ "lib": ["esnext", "DOM", "DOM.Iterable"],
11
+ "moduleResolution": "bundler",
12
+ "module": "esnext",
13
+ "noEmit": true,
14
+ "target": "esnext"
15
+ },
16
+ "include": [
17
+ "ambient.d.ts",
18
+ "non-ambient.d.ts",
19
+ "./types/**/$types.d.ts",
20
+ "../vite.config.js",
21
+ "../vite.config.ts",
22
+ "../src/**/*.js",
23
+ "../src/**/*.ts",
24
+ "../src/**/*.svelte",
25
+ "../tests/**/*.js",
26
+ "../tests/**/*.ts",
27
+ "../tests/**/*.svelte"
28
+ ],
29
+ "exclude": [
30
+ "../node_modules/**",
31
+ "../src/service-worker.js",
32
+ "../src/service-worker/**/*.js",
33
+ "../src/service-worker.ts",
34
+ "../src/service-worker/**/*.ts",
35
+ "../src/service-worker.d.ts",
36
+ "../src/service-worker/**/*.d.ts"
37
+ ]
38
+ }
@@ -1,13 +1,13 @@
1
1
  // See https://svelte.dev/docs/kit/types#app.d.ts
2
2
  // for information about these interfaces
3
3
  declare global {
4
- namespace App {
5
- // interface Error {}
6
- // interface Locals {}
7
- // interface PageData {}
8
- // interface PageState {}
9
- // interface Platform {}
10
- }
4
+ namespace App {
5
+ // interface Error {}
6
+ // interface Locals {}
7
+ // interface PageData {}
8
+ // interface PageState {}
9
+ // interface Platform {}
10
+ }
11
11
  }
12
12
 
13
13
  export {};
@@ -1,12 +1,12 @@
1
1
  <!doctype html>
2
2
  <html lang="en">
3
- <head>
4
- <meta charset="utf-8" />
5
- <link rel="icon" href="%sveltekit.assets%/favicon.png" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1" />
7
- %sveltekit.head%
8
- </head>
9
- <body data-sveltekit-preload-data="hover">
10
- <div style="display: contents">%sveltekit.body%</div>
11
- </body>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <link rel="icon" href="%sveltekit.assets%/favicon.png" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
7
+ %sveltekit.head%
8
+ </head>
9
+ <body data-sveltekit-preload-data="hover">
10
+ <div style="display: contents">%sveltekit.body%</div>
11
+ </body>
12
12
  </html>
@@ -1,7 +1,7 @@
1
1
  //@ts-nocheck
2
+ import open from 'open';
2
3
  import { preview } from 'vite';
3
- import open from 'open'
4
- import {startServer} from '../server/app';
4
+ import { startServer } from '../server/app';
5
5
 
6
6
  (async () => {
7
7
  await startServer();
@@ -9,6 +9,5 @@ import {startServer} from '../server/app';
9
9
  const view = await preview();
10
10
  const url = view.resolvedUrls!.local[0];
11
11
  console.log('\x1b[1m%s\x1b[0m %s', 'benSDK developer tools:', url);
12
- await open(url);
13
-
14
- })();
12
+ await open(url);
13
+ })();
@@ -3,16 +3,16 @@ import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
3
3
 
4
4
  /** @type {import('@sveltejs/kit').Config} */
5
5
  const config = {
6
- // Consult https://svelte.dev/docs/kit/integrations
7
- // for more information about preprocessors
8
- preprocess: vitePreprocess(),
6
+ // Consult https://svelte.dev/docs/kit/integrations
7
+ // for more information about preprocessors
8
+ preprocess: vitePreprocess(),
9
9
 
10
- kit: {
11
- // adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
12
- // If your environment is not supported, or you settled on a specific environment, switch out the adapter.
13
- // See https://svelte.dev/docs/kit/adapters for more information about adapters.
14
- adapter: adapter()
15
- }
10
+ kit: {
11
+ // adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
12
+ // If your environment is not supported, or you settled on a specific environment, switch out the adapter.
13
+ // See https://svelte.dev/docs/kit/adapters for more information about adapters.
14
+ adapter: adapter()
15
+ }
16
16
  };
17
17
 
18
18
  export default config;