@benup/bensdk 1.6.1 → 1.7.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.
- package/bin/lib/schemas/action.schema.d.ts +5 -5
- package/bin/lib/types/lib/deduction-file-ingestion.lib.type.d.ts +3 -0
- package/bin/lib/types/state-handler.types.d.ts +5 -0
- package/bin/src/cli/templates/bensdk-cli/generate.ts +41 -13
- package/bin/src/cli/templates/bensdk-cli/templates/action.test.template.ts +34 -0
- package/bin/src/cli/templates/bensdk-cli/templates/utils.template.ts +1 -0
- package/bin/src/cli/templates/bensdk-local-server/app.ts +3 -1
- package/bin/src/cli/templates/package.template.json +2 -2
- package/package.json +1 -1
|
@@ -8027,16 +8027,16 @@ export declare const DeductionFileIngestionActionSchema: z.ZodObject<{
|
|
|
8027
8027
|
name: z.ZodString;
|
|
8028
8028
|
size: z.ZodNumber;
|
|
8029
8029
|
type: z.ZodString;
|
|
8030
|
-
|
|
8030
|
+
key: z.ZodString;
|
|
8031
8031
|
}, "strip", z.ZodTypeAny, {
|
|
8032
8032
|
name?: string;
|
|
8033
8033
|
type?: string;
|
|
8034
|
-
|
|
8034
|
+
key?: string;
|
|
8035
8035
|
size?: number;
|
|
8036
8036
|
}, {
|
|
8037
8037
|
name?: string;
|
|
8038
8038
|
type?: string;
|
|
8039
|
-
|
|
8039
|
+
key?: string;
|
|
8040
8040
|
size?: number;
|
|
8041
8041
|
}>;
|
|
8042
8042
|
ctx: z.ZodOptional<z.ZodObject<{
|
|
@@ -8354,7 +8354,7 @@ export declare const DeductionFileIngestionActionSchema: z.ZodObject<{
|
|
|
8354
8354
|
deductionFileIngestionInput?: {
|
|
8355
8355
|
name?: string;
|
|
8356
8356
|
type?: string;
|
|
8357
|
-
|
|
8357
|
+
key?: string;
|
|
8358
8358
|
size?: number;
|
|
8359
8359
|
};
|
|
8360
8360
|
}, {
|
|
@@ -8620,7 +8620,7 @@ export declare const DeductionFileIngestionActionSchema: z.ZodObject<{
|
|
|
8620
8620
|
deductionFileIngestionInput?: {
|
|
8621
8621
|
name?: string;
|
|
8622
8622
|
type?: string;
|
|
8623
|
-
|
|
8623
|
+
key?: string;
|
|
8624
8624
|
size?: number;
|
|
8625
8625
|
};
|
|
8626
8626
|
}>;
|
|
@@ -5,6 +5,7 @@ import z from 'zod';
|
|
|
5
5
|
import { HandlerResponse } from '../lib/consumer';
|
|
6
6
|
import ActionConsumerMessageSchema from '../schemas/action-consumer/message.schema';
|
|
7
7
|
import { BenefitDefinition } from './benefit-definition.types';
|
|
8
|
+
import { DeductionFileIngestionHelper } from './lib/deduction-file-ingestion.lib.type.js';
|
|
8
9
|
export type MessageBody = z.infer<typeof ActionConsumerMessageSchema>;
|
|
9
10
|
export interface StateHandlerResponse<TLogs, TCtx> {
|
|
10
11
|
handlerResponse: HandlerResponse;
|
|
@@ -51,6 +52,10 @@ export interface StateHandlerCtx {
|
|
|
51
52
|
* executionAPI Axios instance
|
|
52
53
|
*/
|
|
53
54
|
executionAPI: AxiosInstance;
|
|
55
|
+
/**
|
|
56
|
+
* deductionFileIngestionHelper
|
|
57
|
+
*/
|
|
58
|
+
deductionFileIngestionHelper: DeductionFileIngestionHelper;
|
|
54
59
|
}
|
|
55
60
|
/**
|
|
56
61
|
* State Handler
|
|
@@ -34,22 +34,21 @@ async function main() {
|
|
|
34
34
|
|
|
35
35
|
const fileName = `${state.toLocaleLowerCase()}.handler.ts`;
|
|
36
36
|
let stateHandler = stateHandlerTemplate;
|
|
37
|
-
const actionSize = action
|
|
38
|
-
.split('_')
|
|
37
|
+
const actionSize = action.split('_');
|
|
39
38
|
let actionInCamelCase = '';
|
|
40
|
-
if(actionSize.length === 1){
|
|
41
|
-
actionInCamelCase = action
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
if (actionSize.length === 1) {
|
|
40
|
+
actionInCamelCase = action
|
|
41
|
+
.split('')
|
|
42
|
+
.map((word, index) => (index === 0 ? word.toUpperCase() : word.toLowerCase()))
|
|
43
|
+
.join('');
|
|
44
44
|
} else {
|
|
45
45
|
actionInCamelCase = action
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
.split('_')[1]
|
|
47
|
+
.split('')
|
|
48
|
+
.map((word, index) => (index === 0 ? word.toUpperCase() : word.toLowerCase()))
|
|
49
|
+
.join('');
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
53
52
|
stateHandler = stateHandler.replace(
|
|
54
53
|
'// StateMachine,',
|
|
55
54
|
`const stateMachine = benefitDefinition.stateMachine.${action}.${state}; `
|
|
@@ -60,13 +59,13 @@ async function main() {
|
|
|
60
59
|
`import benefitDefinition from '../benefit-definition';`
|
|
61
60
|
);
|
|
62
61
|
|
|
63
|
-
if(action === 'GRANT' || action === 'REVOKE'){
|
|
62
|
+
if (action === 'GRANT' || action === 'REVOKE') {
|
|
64
63
|
stateHandler = stateHandler.replace(
|
|
65
64
|
'// import {Action}',
|
|
66
65
|
`import { ActionBaseGrantRevoke as Action} from '@benup/bensdk/bin/lib/types/action.types'`
|
|
67
66
|
);
|
|
68
67
|
} else {
|
|
69
|
-
|
|
68
|
+
stateHandler = stateHandler.replace(
|
|
70
69
|
'// import {Action}',
|
|
71
70
|
`import { ActionBase${actionInCamelCase} as Action} from '@benup/bensdk/bin/lib/types/action.types'`
|
|
72
71
|
);
|
|
@@ -88,6 +87,35 @@ async function main() {
|
|
|
88
87
|
}
|
|
89
88
|
fs.writeFileSync(`${handlersDir}/${fileName}`, stateHandler, 'utf-8');
|
|
90
89
|
});
|
|
90
|
+
|
|
91
|
+
const testsDir = `${process.cwd()}/__tests__`;
|
|
92
|
+
|
|
93
|
+
if (!fs.existsSync(testsDir)) {
|
|
94
|
+
fs.mkdirSync(testsDir, { recursive: true });
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Read the action test template
|
|
98
|
+
let actionTestTemplate = fs.readFileSync(
|
|
99
|
+
process.cwd() + '/bin/cli/templates/action.test.template.ts',
|
|
100
|
+
'utf-8'
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
// Replaces the action placeholder with the current action name
|
|
104
|
+
actionTestTemplate = actionTestTemplate.replaceAll('CHANGE_ACTION_NAME_PLACEHOLDER', action);
|
|
105
|
+
|
|
106
|
+
fs.writeFileSync(`${testsDir}/${action.toLowerCase()}.test.ts`, actionTestTemplate, 'utf-8');
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Creates the utils.ts for the tests if it doesn't exists
|
|
110
|
+
*/
|
|
111
|
+
if (!fs.existsSync(`${testsDir}/utils.ts`)) {
|
|
112
|
+
const utilsTestTemplate = fs.readFileSync(
|
|
113
|
+
process.cwd() + '/bin/cli/templates/utils.template.ts',
|
|
114
|
+
'utf-8'
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
fs.writeFileSync(`${testsDir}/utils.ts`, utilsTestTemplate, 'utf-8');
|
|
118
|
+
}
|
|
91
119
|
});
|
|
92
120
|
}
|
|
93
121
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { app } from '../bin/server/app';
|
|
3
|
+
import { getUrl } from './utils';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Write your state-machine actions tests here!
|
|
7
|
+
* How to do that? This is the test-suite for CHANGE_ACTION_NAME_PLACEHOLDER, We recommend that
|
|
8
|
+
* for each state from the action you write the possible scenarios
|
|
9
|
+
*/
|
|
10
|
+
describe('SM Tests for CHANGE_ACTION_NAME_PLACEHOLDER', () => {
|
|
11
|
+
const action = 'CHANGE_ACTION_NAME_PLACEHOLDER';
|
|
12
|
+
|
|
13
|
+
it('[REQUEST_CHANGE_ACTION_NAME_PLACEHOLDER] should fail and return 500 for invalid payload', async () => {
|
|
14
|
+
const res = await app.request(`${getUrl()}`, {
|
|
15
|
+
method: 'POST',
|
|
16
|
+
headers: { 'Content-Type': 'application/json' },
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* We recommend you to create an utils or some method that create this payload
|
|
20
|
+
*/
|
|
21
|
+
body: JSON.stringify({
|
|
22
|
+
message: {},
|
|
23
|
+
requestPayload: {
|
|
24
|
+
action: 'CHANGE_ACTION_NAME_PLACEHOLDER'
|
|
25
|
+
},
|
|
26
|
+
currentContext: {}
|
|
27
|
+
})
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const data = await res.text();
|
|
31
|
+
|
|
32
|
+
expect(res.status).toBe(500);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const getUrl = () => 'http://localhost:3000/run-action';
|
|
@@ -69,7 +69,7 @@ wss.on('connection', (ws) => {
|
|
|
69
69
|
});
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
async function startServer() {
|
|
73
73
|
return new Promise((res: any, rej: any) => {
|
|
74
74
|
const server = serve({ fetch: app.fetch, port: 3000 });
|
|
75
75
|
server.on('upgrade', (request, socket, head) => {
|
|
@@ -85,3 +85,5 @@ export async function startServer() {
|
|
|
85
85
|
res();
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
|
+
|
|
89
|
+
export { app, startServer };
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "
|
|
7
|
+
"test": "vitest --run",
|
|
8
8
|
"format": "npx prettier --write .",
|
|
9
9
|
"lint": "npx tsc --noemit && npx prettier --check . && npx eslint .",
|
|
10
10
|
"start": "cd bin/viewer && tsx startup.ts",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"pino": "^9.6.0",
|
|
35
35
|
"hono": "^4.7.7",
|
|
36
36
|
"@hono/node-server": "^1.14.1",
|
|
37
|
-
"vitest": "^3.
|
|
37
|
+
"vitest": "^3.2.4",
|
|
38
38
|
"@sveltejs/adapter-auto": "^4.0.0",
|
|
39
39
|
"@sveltejs/kit": "^2.16.0",
|
|
40
40
|
"@sveltejs/vite-plugin-svelte": "^5.0.0",
|