Skip to content

Commit 7118862

Browse files
SofianDRossb0b
authored andcommitted
chore: add types and doc
1 parent e0642a5 commit 7118862

8 files changed

+264
-13
lines changed

.editorconfig

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Editor configuration, see https://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
end_of_line = lf
11+
12+
[*.md]
13+
max_line_length = off
14+
trim_trailing_whitespace = false

.eslintrc

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"extends": "@myunisoft/eslint-config"
2+
"extends": "@nodesecure/eslint-config",
3+
"rules": {
4+
"@typescript-eslint/no-non-null-assertion": "off"
5+
}
36
}

.gitignore

+131
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,133 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
.pnpm-debug.log*
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
*.lcov
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
142
node_modules/
43+
jspm_packages/
44+
45+
# Snowpack dependency directory (https://snowpack.dev/)
46+
web_modules/
47+
48+
# TypeScript cache
49+
*.tsbuildinfo
50+
51+
# Optional npm cache directory
52+
.npm
53+
54+
# Optional eslint cache
55+
.eslintcache
56+
57+
# Optional stylelint cache
58+
.stylelintcache
59+
60+
# Microbundle cache
61+
.rpt2_cache/
62+
.rts2_cache_cjs/
63+
.rts2_cache_es/
64+
.rts2_cache_umd/
65+
66+
# Optional REPL history
67+
.node_repl_history
68+
69+
# Output of 'npm pack'
70+
*.tgz
71+
72+
# Yarn Integrity file
73+
.yarn-integrity
74+
75+
# dotenv environment variable files
76+
.env
77+
.env.development.local
78+
.env.test.local
79+
.env.production.local
80+
.env.local
81+
82+
# parcel-bundler cache (https://parceljs.org/)
83+
.cache
84+
.parcel-cache
85+
86+
# Next.js build output
87+
.next
88+
out
89+
90+
# Nuxt.js build / generate output
91+
.nuxt
92+
dist
93+
94+
# Gatsby files
95+
.cache/
96+
# Comment in the public line in if your project uses Gatsby and not Next.js
97+
# https://nextjs.org/blog/next-9-1#public-directory-support
98+
# public
99+
100+
# vuepress build output
101+
.vuepress/dist
102+
103+
# vuepress v2.x temp and cache directory
104+
.temp
105+
.cache
106+
107+
# Docusaurus cache and generated files
108+
.docusaurus
109+
110+
# Serverless directories
111+
.serverless/
112+
113+
# FuseBox cache
114+
.fusebox/
115+
116+
# DynamoDB Local files
117+
.dynamodb/
118+
119+
# TernJS port file
120+
.tern-port
121+
122+
# Stores VSCode versions used for testing VSCode extensions
123+
.vscode-test
124+
125+
# yarn v2
126+
.yarn/cache
127+
.yarn/unplugged
128+
.yarn/build-state.yml
129+
.yarn/install-state.gz
130+
.pnp.*
131+
132+
# lock file
2133
package-lock.json

README.md

+49-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,49 @@
1-
# Events
2-
MyUnisoft Events validation
1+
# Events-utils
2+
MyUnisoft Events data validation, and transparency on events & result of webhooks.
3+
4+
## Requirements
5+
- [Node.js](https://nodejs.org/en/) version 14 or higher
6+
7+
## Getting Started
8+
9+
This package is available in the Node Package Repository and can be easily installed with [npm](https://doc.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com)
10+
11+
```bash
12+
$ npm i @myunisoft/events
13+
# or
14+
$ yarn add @myunisoft/events
15+
```
16+
17+
## Usage
18+
19+
```ts
20+
import { ValidateEventDataOptions, validateEventData } from "@myunisoft/events";
21+
22+
const event: ValidateEventDataOptions = {
23+
name: "accountingFolder",
24+
operation: "CREATE",
25+
data: {
26+
accountingFolderId: 1
27+
}
28+
};
29+
30+
validateEventData(event);
31+
```
32+
33+
## Events Descriptions
34+
35+
### connector
36+
37+
| Operation | Agent | Payload |
38+
|---|---|---|
39+
| CREATE | Node.js | ```{ connectorId: number ;}``` |
40+
| UPDATE | Node.js | ```{ connectorId: number ;}``` |
41+
| DELETE | Node.js | ```{ connectorId: number ;}``` |
42+
43+
---
44+
45+
### accountingFolder
46+
47+
| Operation | Agent | Payload |
48+
|---|---|---|
49+
| CREATE | Windev | ```{ accountingFolderId: number ;}``` |

SECURITY.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
This project participates in the Responsible Disclosure Policy program for the Node.js Security Ecosystem.
2+
3+
# Responsible Disclosure Policy
4+
5+
A responsible disclosure policy helps protect the project and its users from security vulnerabilities discovered in the project’s scope by employing a process where vulnerabilities are publicly disclosed after a reasonable time period to allow patching the vulnerability.
6+
7+
All security bugs are taken seriously and are considered as top priority.
8+
Your efforts to responsibly disclose your findings are appreciated and will be taken into account to acknowledge your contributions.
9+
10+
11+
## Reporting a Security Issue
12+
13+
Any security related issue should be reported to the [Node.js Ecosystem](https://hackerone.com/nodejs-ecosystem
14+
) program hosted on HackerOne which follows the [3rd party responsible disclosure process](https://github.com/nodejs/security-wg/blob/master/processes/third_party_vuln_process.md) set by the Node.js Security WG. One may also directly contact the project’s maintainers, but through the HackerOne program the Security WG members will take care of triaging the vulnerability and invite project maintainers to participate in the report.
15+
16+
As an alternative method, vulnerabilities can also be reported by emailing security-ecosystem@nodejs.org.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"repository": {
1212
"type": "git",
13-
"url": "git+https://github.com/MyUnisoft/Events.git"
13+
"url": "git+https://github.com/MyUnisoft/events-utils.git"
1414
},
1515
"publishConfig": {
1616
"@myunisoft:registry": "https://registry.npmjs.org/"
@@ -21,7 +21,7 @@
2121
"author": "HALLAERT Nicolas <nicolas.hallaert.pro@gmail.com>",
2222
"license": "MIT",
2323
"bugs": {
24-
"url": "https://github.com/MyUnisoft/Events/issues"
24+
"url": "https://github.com/MyUnisoft/events-utils/issues"
2525
},
2626
"dependencies": {
2727
"ajv": "^8.11.0"

src/index.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// Import Internal Dependencies
22
import { events } from "./utils/index";
33

4-
export interface ValidateEventDataOptions {
5-
name: string;
6-
operation: "CREATE" | "UPDATE" | "DELETE" | "VOID";
7-
data: Record<string, any>;
8-
}
4+
// Import Types
5+
import { Events, EventsDefinition } from "types";
6+
7+
export type ValidateEventDataOptions<T extends keyof EventsDefinition = Events> = EventsDefinition[T];
98

10-
export function validateEventData(options: ValidateEventDataOptions) {
9+
export function validateEventData<T extends keyof EventsDefinition = Events>(options: ValidateEventDataOptions<T>) {
1110
const { name, operation, data } = options;
1211

1312
if(!events.has(name)) {
@@ -16,11 +15,11 @@ export function validateEventData(options: ValidateEventDataOptions) {
1615

1716
const event = events.get(name);
1817
if(!event.has(operation)) {
19-
throw "Unknown \"operation\" for for the specified \"event\"";
18+
throw `Unknown "operation" for for the specified "event"`;
2019
}
2120

2221
const operationValidationFunction = event.get(operation.toLocaleLowerCase());
2322
if (!operationValidationFunction(data)) {
24-
throw "Wrong data for the specified \"event\" & \"operation\"";
23+
throw `Wrong data for the specified "event" & "operation"`;
2524
}
2625
}

src/types/index.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
export type Events = "accountingFolder" | "connector";
2+
3+
// Events
4+
export interface Connector {
5+
name: "connector";
6+
operation: "CREATE" | "UPDATE" | "DELETE";
7+
data: {
8+
connectorId: number;
9+
};
10+
}
11+
12+
export interface AccountingFolder {
13+
name: "accountingFolder";
14+
operation: "CREATE";
15+
data: {
16+
accountingFolderId: number;
17+
};
18+
}
19+
20+
export interface EventsDefinition {
21+
accountingFolder: AccountingFolder;
22+
connector: Connector;
23+
}
24+
25+
26+
interface Scope {
27+
schemaId: number;
28+
accountingFolderId?: number;
29+
}
30+
31+
export type WebhookResponse<K extends keyof EventsDefinition = keyof EventsDefinition> = {
32+
scope: Scope;
33+
webhookId: string;
34+
createdAt: number;
35+
} & EventsDefinition[K];
36+
37+
38+
export type WebhooksResponse<T extends (keyof EventsDefinition)[]> = [
39+
...(WebhookResponse<T[number]>)[]
40+
];
41+

0 commit comments

Comments
 (0)