diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..4cb15070 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +# Editor configuration, see https://editorconfig.org +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +insert_final_newline = true +trim_trailing_whitespace = true +end_of_line = lf + +[*.md] +max_line_length = off +trim_trailing_whitespace = false diff --git a/.eslintrc b/.eslintrc index 9a299605..c6021686 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,3 +1,6 @@ { - "extends": "@myunisoft/eslint-config" + "extends": "@nodesecure/eslint-config", + "rules": { + "@typescript-eslint/no-non-null-assertion": "off" + } } \ No newline at end of file diff --git a/.gitignore b/.gitignore index ccb2c800..c65a9b32 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,133 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp +.cache + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +# lock file package-lock.json \ No newline at end of file diff --git a/README.md b/README.md index 31230699..00267a27 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,49 @@ -# Events -MyUnisoft Events validation +# Events-utils +MyUnisoft Events data validation, and transparency on events & result of webhooks. + +## Requirements +- [Node.js](https://nodejs.org/en/) version 14 or higher + +## Getting Started + +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) + +```bash +$ npm i @myunisoft/events +# or +$ yarn add @myunisoft/events +``` + +## Usage + +```ts +import { ValidateEventDataOptions, validateEventData } from "@myunisoft/events"; + +const event: ValidateEventDataOptions = { + name: "accountingFolder", + operation: "CREATE", + data: { + accountingFolderId: 1 + } +}; + +validateEventData(event); +``` + +## Events Descriptions + +### connector + +| Operation | Agent | Payload | +|---|---|---| +| CREATE | Node.js | ```{ connectorId: number ;}``` | +| UPDATE | Node.js | ```{ connectorId: number ;}``` | +| DELETE | Node.js | ```{ connectorId: number ;}``` | + +--- + +### accountingFolder + +| Operation | Agent | Payload | +|---|---|---| +| CREATE | Windev | ```{ accountingFolderId: number ;}``` | \ No newline at end of file diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 00000000..78d52c28 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,16 @@ +This project participates in the Responsible Disclosure Policy program for the Node.js Security Ecosystem. + +# Responsible Disclosure Policy + +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. + +All security bugs are taken seriously and are considered as top priority. +Your efforts to responsibly disclose your findings are appreciated and will be taken into account to acknowledge your contributions. + + +## Reporting a Security Issue + +Any security related issue should be reported to the [Node.js Ecosystem](https://hackerone.com/nodejs-ecosystem +) 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. + +As an alternative method, vulnerabilities can also be reported by emailing security-ecosystem@nodejs.org. \ No newline at end of file diff --git a/package.json b/package.json index efd4ae6c..cb1700bc 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/MyUnisoft/Events.git" + "url": "git+https://github.com/MyUnisoft/events-utils.git" }, "publishConfig": { "@myunisoft:registry": "https://registry.npmjs.org/" @@ -21,7 +21,7 @@ "author": "HALLAERT Nicolas ", "license": "MIT", "bugs": { - "url": "https://github.com/MyUnisoft/Events/issues" + "url": "https://github.com/MyUnisoft/events-utils/issues" }, "dependencies": { "ajv": "^8.11.0" diff --git a/src/index.ts b/src/index.ts index 918034ae..496e1fc7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,13 +1,12 @@ // Import Internal Dependencies import { events } from "./utils/index"; -export interface ValidateEventDataOptions { - name: string; - operation: "CREATE" | "UPDATE" | "DELETE" | "VOID"; - data: Record; -} +// Import Types +import { Events, EventsDefinition } from "types"; + +export type ValidateEventDataOptions = EventsDefinition[T]; -export function validateEventData(options: ValidateEventDataOptions) { +export function validateEventData(options: ValidateEventDataOptions) { const { name, operation, data } = options; if(!events.has(name)) { @@ -16,11 +15,11 @@ export function validateEventData(options: ValidateEventDataOptions) { const event = events.get(name); if(!event.has(operation)) { - throw "Unknown \"operation\" for for the specified \"event\""; + throw `Unknown "operation" for for the specified "event"`; } const operationValidationFunction = event.get(operation.toLocaleLowerCase()); if (!operationValidationFunction(data)) { - throw "Wrong data for the specified \"event\" & \"operation\""; + throw `Wrong data for the specified "event" & "operation"`; } } diff --git a/src/types/index.ts b/src/types/index.ts new file mode 100644 index 00000000..1cd55c85 --- /dev/null +++ b/src/types/index.ts @@ -0,0 +1,41 @@ +export type Events = "accountingFolder" | "connector"; + +// Events +export interface Connector { + name: "connector"; + operation: "CREATE" | "UPDATE" | "DELETE"; + data: { + connectorId: number; + }; +} + +export interface AccountingFolder { + name: "accountingFolder"; + operation: "CREATE"; + data: { + accountingFolderId: number; + }; +} + +export interface EventsDefinition { + accountingFolder: AccountingFolder; + connector: Connector; +} + + +interface Scope { + schemaId: number; + accountingFolderId?: number; +} + +export type WebhookResponse = { + scope: Scope; + webhookId: string; + createdAt: number; +} & EventsDefinition[K]; + + +export type WebhooksResponse = [ + ...(WebhookResponse)[] +]; +