@degenerate/endpoints 0.0.14 → 0.1.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.
- package/dist/cors/endpoints/helpers/validate-incoming-request-data.d.ts +1 -1
- package/dist/cors/endpoints/helpers/validate-incoming-request-data.d.ts.map +1 -1
- package/dist/cors/endpoints/helpers/validate-incoming-request-data.js +1 -1
- package/dist/cors/endpoints/helpers/validate-request-body.js +0 -1
- package/dist/routes/rules/v1/rule-set.routes.d.ts.map +1 -1
- package/dist/routes/rules/v1/rule-set.routes.js +23 -3
- package/dist/server-objects/ruleset-manager.d.ts +40 -0
- package/dist/server-objects/ruleset-manager.d.ts.map +1 -0
- package/dist/server-objects/ruleset-manager.js +75 -0
- package/package.json +4 -4
|
@@ -6,5 +6,5 @@ import { Request, Response, NextFunction } from 'express';
|
|
|
6
6
|
* @param schema the schema to validate against
|
|
7
7
|
* @returns a middleware function that will validate the incoming request data
|
|
8
8
|
*/
|
|
9
|
-
export declare function validateIncomingRequestData<T extends ZodSchema<
|
|
9
|
+
export declare function validateIncomingRequestData<T extends ZodSchema<unknown>>(schema: T): (req: Request, res: Response, next: NextFunction) => void;
|
|
10
10
|
//# sourceMappingURL=validate-incoming-request-data.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-incoming-request-data.d.ts","sourceRoot":"","sources":["../../../../src/cors/endpoints/helpers/validate-incoming-request-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,SAAS,EAAE,MAAM,KAAK,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG1D;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,SAAS,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"validate-incoming-request-data.d.ts","sourceRoot":"","sources":["../../../../src/cors/endpoints/helpers/validate-incoming-request-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,SAAS,EAAE,MAAM,KAAK,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG1D;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,SAAS,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,SAClE,OAAO,OAAO,QAAQ,QAAQ,YAAY,UAc1D"}
|
|
@@ -34,5 +34,5 @@ function validateIncomingRequestData(schema) {
|
|
|
34
34
|
* @returns an array of formatted error messages
|
|
35
35
|
*/
|
|
36
36
|
function formatZodErrors(error) {
|
|
37
|
-
return error.errors.map(issue => `${issue.path.join('.')} is ${issue.message}`);
|
|
37
|
+
return error.errors.map((issue) => `${issue.path.join('.')} is ${issue.message}`);
|
|
38
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rule-set.routes.d.ts","sourceRoot":"","sources":["../../../../src/routes/rules/v1/rule-set.routes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rule-set.routes.d.ts","sourceRoot":"","sources":["../../../../src/routes/rules/v1/rule-set.routes.ts"],"names":[],"mappings":"AAmIA,eAAO,MAAM,QAAQ,4CAAS,CAAC"}
|
|
@@ -35,6 +35,8 @@ const validate_request_body_1 = require("../../../cors/endpoints/helpers/validat
|
|
|
35
35
|
//#endregion Incoming Shape Validations
|
|
36
36
|
//#region Functions and Models
|
|
37
37
|
const generic_1 = require("@degenerate/generic");
|
|
38
|
+
const ruleset_manager_1 = require("../../../server-objects/ruleset-manager");
|
|
39
|
+
const ruleSetManager = new ruleset_manager_1.RuleSetManager();
|
|
38
40
|
//#endregion Functions and Models
|
|
39
41
|
//#region Route Imports
|
|
40
42
|
//#endregion Route Imports
|
|
@@ -47,6 +49,8 @@ router.post(// https://{hostname}/rules/v1/rule-sets
|
|
|
47
49
|
'/', validate_request_body_1.validateRequestBody, // make sure this is a valid request body
|
|
48
50
|
(0, validate_incoming_request_data_1.validateIncomingRequestData)(generic_1.ISAFETransactionRuleSetAddSchema), async (req, res, next) => {
|
|
49
51
|
try {
|
|
52
|
+
const ruleSet = req.body.transaction.data.ruleSet; // get the rule set;
|
|
53
|
+
ruleSetManager.addRuleSet(ruleSet); // add the rule set to the rule set manager
|
|
50
54
|
return res.status(200).send({ successful: true });
|
|
51
55
|
}
|
|
52
56
|
catch (err) {
|
|
@@ -59,7 +63,8 @@ router.post(// https://{hostname}/rules/v1/rule-sets
|
|
|
59
63
|
router.get('/', async (req, res, next) => {
|
|
60
64
|
try {
|
|
61
65
|
const lastId = (0, generic_1.getQueryLastId)(req); // get the last id from the query object
|
|
62
|
-
|
|
66
|
+
const ruleSets = ruleSetManager.getRuleSets(lastId); // add the rule set to the rule set manager
|
|
67
|
+
return res.status(200).send({ successful: true, ruleSets: ruleSets });
|
|
63
68
|
}
|
|
64
69
|
catch (err) {
|
|
65
70
|
next(err);
|
|
@@ -70,8 +75,13 @@ router.get('/', async (req, res, next) => {
|
|
|
70
75
|
*/
|
|
71
76
|
router.get('/:rulesetsid', async (req, res, next) => {
|
|
72
77
|
try {
|
|
73
|
-
const
|
|
74
|
-
|
|
78
|
+
const rulesSetsId = (0, generic_1.getParamRuleSetsId)(req); // get the rules id.
|
|
79
|
+
const ruleSets = ruleSetManager.getRuleSetById(rulesSetsId); // add the rule set to the rule set manager
|
|
80
|
+
const returnItem = { successful: true };
|
|
81
|
+
if (ruleSets) {
|
|
82
|
+
returnItem.ruleSet = ruleSets;
|
|
83
|
+
}
|
|
84
|
+
return res.status(200).send(returnItem);
|
|
75
85
|
}
|
|
76
86
|
catch (err) {
|
|
77
87
|
next(err);
|
|
@@ -84,6 +94,11 @@ router.patch('/:rulesetsid', validate_request_body_1.validateRequestBody, // mak
|
|
|
84
94
|
(0, validate_incoming_request_data_1.validateIncomingRequestData)(generic_1.ISAFETransactionRuleSetUpdateSchema), async (req, res, next) => {
|
|
85
95
|
try {
|
|
86
96
|
const rulesId = (0, generic_1.getParamRuleSetsId)(req); // get the rules id.
|
|
97
|
+
const ruleSet = req.body.transaction.data.ruleSet; // get the rule set;
|
|
98
|
+
if (ruleSet.id !== rulesId) {
|
|
99
|
+
throw new Error('Rule set id does not match');
|
|
100
|
+
}
|
|
101
|
+
ruleSetManager.updateRuleSet(ruleSet); // add the rule set to the rule set manager
|
|
87
102
|
return res.status(200).send({ successful: true, rulesId });
|
|
88
103
|
}
|
|
89
104
|
catch (err) {
|
|
@@ -97,6 +112,11 @@ router.delete('/:rulesetsid', validate_request_body_1.validateRequestBody, // ma
|
|
|
97
112
|
(0, validate_incoming_request_data_1.validateIncomingRequestData)(generic_1.ISAFETransactionRuleSetDeleteSchema), async (req, res, next) => {
|
|
98
113
|
try {
|
|
99
114
|
const rulesId = (0, generic_1.getParamRuleSetsId)(req); // get the rules id.
|
|
115
|
+
const ruleSet = req.body.transaction.data.ruleSet; // get the rule set;
|
|
116
|
+
if (ruleSet.id !== rulesId) {
|
|
117
|
+
throw new Error('Rule set id does not match');
|
|
118
|
+
}
|
|
119
|
+
ruleSetManager.removeRuleSetById(ruleSet.id); // add the rule set to the rule set manager
|
|
100
120
|
return res.status(200).send({ successful: true, rulesId });
|
|
101
121
|
}
|
|
102
122
|
catch (err) {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { IShareRuleSet } from '@degenerate/generic';
|
|
2
|
+
/**
|
|
3
|
+
* This class is used to host a rule set manager for the rule sets
|
|
4
|
+
*/
|
|
5
|
+
export declare class RuleSetManager {
|
|
6
|
+
_ruleSets: IShareRuleSet[];
|
|
7
|
+
constructor(ruleSets?: IShareRuleSet[]);
|
|
8
|
+
/**
|
|
9
|
+
* this adds a rule set to the rule set manager
|
|
10
|
+
*
|
|
11
|
+
* @param ruleSet the rule set to add
|
|
12
|
+
*/
|
|
13
|
+
addRuleSet(ruleSet: IShareRuleSet): void;
|
|
14
|
+
/**
|
|
15
|
+
* This gets a rule set by id
|
|
16
|
+
* @param id the id of the rule set
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
getRuleSetById(id: string): IShareRuleSet | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* This gets the rule sets by last id and ruleSetSize
|
|
22
|
+
*
|
|
23
|
+
* @param lastId the last id
|
|
24
|
+
* @param ruleSetSize the rule set size default is 25
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
getRuleSets(lastId: string, ruleSetSize?: number): IShareRuleSet[];
|
|
28
|
+
/**
|
|
29
|
+
* This updates the rule set
|
|
30
|
+
* @param ruleSet the rule set to update
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
updateRuleSet(ruleSet: IShareRuleSet): void;
|
|
34
|
+
/**
|
|
35
|
+
* This removes a rule set by id
|
|
36
|
+
* @param id the id of the rule set to remove
|
|
37
|
+
*/
|
|
38
|
+
removeRuleSetById(id: string): void;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=ruleset-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ruleset-manager.d.ts","sourceRoot":"","sources":["../../src/server-objects/ruleset-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;GAEG;AACH,qBAAa,cAAc;IACvB,SAAS,EAAE,aAAa,EAAE,CAAC;gBACf,QAAQ,GAAE,aAAa,EAAO;IAI1C;;;;OAIG;IACH,UAAU,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI;IASxC;;;;OAIG;IACH,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAIrD;;;;;;OAMG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,GAAE,MAAW;IASpD;;;;OAIG;IACH,aAAa,CAAC,OAAO,EAAE,aAAa;IAapC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,EAAE,MAAM;CAO/B"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RuleSetManager = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* This class is used to host a rule set manager for the rule sets
|
|
6
|
+
*/
|
|
7
|
+
class RuleSetManager {
|
|
8
|
+
constructor(ruleSets = []) {
|
|
9
|
+
this._ruleSets = ruleSets; // set the rule sets
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* this adds a rule set to the rule set manager
|
|
13
|
+
*
|
|
14
|
+
* @param ruleSet the rule set to add
|
|
15
|
+
*/
|
|
16
|
+
addRuleSet(ruleSet) {
|
|
17
|
+
// make sure the rule set does not already exist
|
|
18
|
+
const existingRuleSet = this.getRuleSetById(ruleSet.id);
|
|
19
|
+
if (existingRuleSet) {
|
|
20
|
+
throw new Error('Rule set already exists');
|
|
21
|
+
}
|
|
22
|
+
this._ruleSets.push(ruleSet);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* This gets a rule set by id
|
|
26
|
+
* @param id the id of the rule set
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
getRuleSetById(id) {
|
|
30
|
+
return this._ruleSets.find((ruleSet) => ruleSet.id === id);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* This gets the rule sets by last id and ruleSetSize
|
|
34
|
+
*
|
|
35
|
+
* @param lastId the last id
|
|
36
|
+
* @param ruleSetSize the rule set size default is 25
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
getRuleSets(lastId, ruleSetSize = 25) {
|
|
40
|
+
let nextIndex = 0;
|
|
41
|
+
if (lastId) {
|
|
42
|
+
const lastIndex = this._ruleSets.findIndex((ruleSet) => ruleSet.id === lastId);
|
|
43
|
+
nextIndex = lastIndex + 1;
|
|
44
|
+
}
|
|
45
|
+
return this._ruleSets.slice(nextIndex, nextIndex + ruleSetSize);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* This updates the rule set
|
|
49
|
+
* @param ruleSet the rule set to update
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
updateRuleSet(ruleSet) {
|
|
53
|
+
// find the rule set and update it
|
|
54
|
+
if (!this.getRuleSetById(ruleSet.id)) {
|
|
55
|
+
throw new Error('Rule set not found');
|
|
56
|
+
}
|
|
57
|
+
this._ruleSets = this._ruleSets.map((rs) => {
|
|
58
|
+
if (rs.id === ruleSet.id) {
|
|
59
|
+
return ruleSet;
|
|
60
|
+
}
|
|
61
|
+
return rs;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* This removes a rule set by id
|
|
66
|
+
* @param id the id of the rule set to remove
|
|
67
|
+
*/
|
|
68
|
+
removeRuleSetById(id) {
|
|
69
|
+
if (!this.getRuleSetById(id)) {
|
|
70
|
+
throw new Error('Rule set not found');
|
|
71
|
+
}
|
|
72
|
+
this._ruleSets = this._ruleSets.filter((ruleSet) => ruleSet.id !== id);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.RuleSetManager = RuleSetManager;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@degenerate/endpoints",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"devDependencies": {
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"author": "Degenerate Inc.",
|
|
40
40
|
"license": "ISC",
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@degenerate/generic": "^0.1
|
|
42
|
+
"@degenerate/generic": "^0.2.1",
|
|
43
43
|
"express": "^4.21.1",
|
|
44
|
-
"zod": "^3.
|
|
44
|
+
"zod": "^3.24.1"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "f7265dc7cc337feaca7326d30bf2bd5018aba01e"
|
|
47
47
|
}
|