Skip to content

Commit

Permalink
chore: add types and doc
Browse files Browse the repository at this point in the history
  • Loading branch information
SofianD authored and Rossb0b committed Apr 6, 2022
1 parent e0642a5 commit 7118862
Show file tree
Hide file tree
Showing 8 changed files with 264 additions and 13 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "@myunisoft/eslint-config"
"extends": "@nodesecure/eslint-config",
"rules": {
"@typescript-eslint/no-non-null-assertion": "off"
}
}
131 changes: 131 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
51 changes: 49 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 ;}``` |
16 changes: 16 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -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 [email protected].
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand All @@ -21,7 +21,7 @@
"author": "HALLAERT Nicolas <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/MyUnisoft/Events/issues"
"url": "https://github.com/MyUnisoft/events-utils/issues"
},
"dependencies": {
"ajv": "^8.11.0"
Expand Down
15 changes: 7 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Import Internal Dependencies
import { events } from "./utils/index";

export interface ValidateEventDataOptions {
name: string;
operation: "CREATE" | "UPDATE" | "DELETE" | "VOID";
data: Record<string, any>;
}
// Import Types
import { Events, EventsDefinition } from "types";

export type ValidateEventDataOptions<T extends keyof EventsDefinition = Events> = EventsDefinition[T];

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

if(!events.has(name)) {
Expand All @@ -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"`;
}
}
41 changes: 41 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -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<K extends keyof EventsDefinition = keyof EventsDefinition> = {
scope: Scope;
webhookId: string;
createdAt: number;
} & EventsDefinition[K];


export type WebhooksResponse<T extends (keyof EventsDefinition)[]> = [
...(WebhookResponse<T[number]>)[]
];

0 comments on commit 7118862

Please sign in to comment.