@easyhook/core 0.0.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/.swcrc +29 -0
- package/README.md +11 -0
- package/eslint.config.mjs +25 -0
- package/package.json +51 -0
- package/src/core/base.ts +45 -0
- package/src/index.ts +1 -0
- package/src/lib/core.spec.ts +7 -0
- package/src/lib/core.ts +6 -0
- package/src/types/events.d.ts +5 -0
- package/src/types/payload.d.ts +3 -0
- package/src/utils/intents.ts +7 -0
- package/src/utils/provider.ts +5 -0
- package/src/validator/easydonate.ts +11 -0
- package/src/validator/index.ts +1 -0
- package/tsconfig.json +13 -0
- package/tsconfig.lib.json +28 -0
- package/tsconfig.spec.json +34 -0
- package/vite.config.ts +24 -0
- package/vitest.config.mts +18 -0
package/.swcrc
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"jsc": {
|
|
3
|
+
"target": "es2017",
|
|
4
|
+
"parser": {
|
|
5
|
+
"syntax": "typescript",
|
|
6
|
+
"decorators": true,
|
|
7
|
+
"dynamicImport": true
|
|
8
|
+
},
|
|
9
|
+
"transform": {
|
|
10
|
+
"decoratorMetadata": true,
|
|
11
|
+
"legacyDecorator": true
|
|
12
|
+
},
|
|
13
|
+
"keepClassNames": true,
|
|
14
|
+
"externalHelpers": true,
|
|
15
|
+
"loose": true
|
|
16
|
+
},
|
|
17
|
+
"module": {
|
|
18
|
+
"type": "es6"
|
|
19
|
+
},
|
|
20
|
+
"sourceMaps": true,
|
|
21
|
+
"exclude": [
|
|
22
|
+
"jest.config.[ct]s",
|
|
23
|
+
".*\\.spec.tsx?$",
|
|
24
|
+
".*\\.test.tsx?$",
|
|
25
|
+
"./src/jest-setup.ts$",
|
|
26
|
+
"./**/jest-setup.ts$",
|
|
27
|
+
".*.js$"
|
|
28
|
+
]
|
|
29
|
+
}
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import baseConfig from '../../eslint.config.mjs';
|
|
2
|
+
|
|
3
|
+
export default [
|
|
4
|
+
...baseConfig,
|
|
5
|
+
{
|
|
6
|
+
files: ['**/*.json'],
|
|
7
|
+
rules: {
|
|
8
|
+
'@nx/dependency-checks': [
|
|
9
|
+
'error',
|
|
10
|
+
{
|
|
11
|
+
ignoredFiles: [
|
|
12
|
+
'{projectRoot}/eslint.config.{js,cjs,mjs,ts,cts,mts}',
|
|
13
|
+
'{projectRoot}/vite.config.{js,ts,mjs,mts}',
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
languageOptions: {
|
|
19
|
+
parser: await import('jsonc-eslint-parser'),
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
ignores: ['**/out-tsc'],
|
|
24
|
+
},
|
|
25
|
+
];
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@easyhook/core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
"./package.json": "./package.json",
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"nx": {
|
|
18
|
+
"tags": [
|
|
19
|
+
"type:core",
|
|
20
|
+
"scope:easyhook"
|
|
21
|
+
],
|
|
22
|
+
"sourceRoot": "packages/core/src",
|
|
23
|
+
"targets": {
|
|
24
|
+
"build": {
|
|
25
|
+
"executor": "@nx/js:swc",
|
|
26
|
+
"outputs": [
|
|
27
|
+
"{options.outputPath}"
|
|
28
|
+
],
|
|
29
|
+
"options": {
|
|
30
|
+
"outputPath": "packages/core/dist",
|
|
31
|
+
"main": "packages/core/src/index.ts",
|
|
32
|
+
"tsConfig": "packages/core/tsconfig.lib.json",
|
|
33
|
+
"skipTypeCheck": true,
|
|
34
|
+
"stripLeadingPaths": true
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"typecheck": {
|
|
38
|
+
"executor": "nx:run-commands",
|
|
39
|
+
"options": {
|
|
40
|
+
"command": "tsc -p packages/core/tsconfig.lib.json --noEmit"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@swc/helpers": "~0.5.11",
|
|
47
|
+
"tiny-typed-emitter": "^2.1.0",
|
|
48
|
+
"typed-emitter": "^2.1.0",
|
|
49
|
+
"vitest": "^4.0.17"
|
|
50
|
+
}
|
|
51
|
+
}
|
package/src/core/base.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
import { TypedEmitter } from 'tiny-typed-emitter';
|
|
3
|
+
import { BaseEvents } from '../types/events.js';
|
|
4
|
+
import { HookIntentValue } from '../utils/intents.js';
|
|
5
|
+
import { HookProvider } from '../utils/provider.js';
|
|
6
|
+
import { EasydonateSchema } from '../validator/index.js';
|
|
7
|
+
import { type } from 'arktype';
|
|
8
|
+
|
|
9
|
+
export interface EasyhookOptions {
|
|
10
|
+
intents: HookIntentValue[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class Easyhook extends (EventEmitter as {
|
|
14
|
+
new (): TypedEmitter<BaseEvents>;
|
|
15
|
+
}) {
|
|
16
|
+
private enabledIntents: Set<string>;
|
|
17
|
+
|
|
18
|
+
constructor(options: EasyhookOptions) {
|
|
19
|
+
super();
|
|
20
|
+
this.enabledIntents = new Set(options.intents);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public handleIncomingWebhook(provider: HookProvider, body: unknown) {
|
|
24
|
+
if (!this.enabledIntents.has(provider)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
switch (provider) {
|
|
29
|
+
case HookProvider.EasyDonate: {
|
|
30
|
+
const input = EasydonateSchema(body);
|
|
31
|
+
|
|
32
|
+
if (input instanceof type.errors) {
|
|
33
|
+
console.error(`Invalid Payload for ${provider}:`, input.summary);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
this.emit(HookProvider.EasyDonate, input);
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
default:
|
|
41
|
+
console.warn(`Provider not handled: ${provider}`);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './core/base.js';
|
package/src/lib/core.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './easydonate.js';
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": ".",
|
|
5
|
+
"rootDir": "src",
|
|
6
|
+
"outDir": "dist",
|
|
7
|
+
"tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
|
|
8
|
+
"emitDeclarationOnly": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"types": ["node"]
|
|
11
|
+
},
|
|
12
|
+
"include": ["src/**/*.ts"],
|
|
13
|
+
"references": [],
|
|
14
|
+
"exclude": [
|
|
15
|
+
"vite.config.ts",
|
|
16
|
+
"vite.config.mts",
|
|
17
|
+
"vitest.config.ts",
|
|
18
|
+
"vitest.config.mts",
|
|
19
|
+
"src/**/*.test.ts",
|
|
20
|
+
"src/**/*.spec.ts",
|
|
21
|
+
"src/**/*.test.tsx",
|
|
22
|
+
"src/**/*.spec.tsx",
|
|
23
|
+
"src/**/*.test.js",
|
|
24
|
+
"src/**/*.spec.js",
|
|
25
|
+
"src/**/*.test.jsx",
|
|
26
|
+
"src/**/*.spec.jsx"
|
|
27
|
+
]
|
|
28
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "./out-tsc/vitest",
|
|
5
|
+
"types": [
|
|
6
|
+
"vitest/globals",
|
|
7
|
+
"vitest/importMeta",
|
|
8
|
+
"vite/client",
|
|
9
|
+
"node",
|
|
10
|
+
"vitest"
|
|
11
|
+
],
|
|
12
|
+
"forceConsistentCasingInFileNames": true
|
|
13
|
+
},
|
|
14
|
+
"include": [
|
|
15
|
+
"vite.config.ts",
|
|
16
|
+
"vite.config.mts",
|
|
17
|
+
"vitest.config.ts",
|
|
18
|
+
"vitest.config.mts",
|
|
19
|
+
"src/**/*.test.ts",
|
|
20
|
+
"src/**/*.spec.ts",
|
|
21
|
+
"src/**/*.test.tsx",
|
|
22
|
+
"src/**/*.spec.tsx",
|
|
23
|
+
"src/**/*.test.js",
|
|
24
|
+
"src/**/*.spec.js",
|
|
25
|
+
"src/**/*.test.jsx",
|
|
26
|
+
"src/**/*.spec.jsx",
|
|
27
|
+
"src/**/*.d.ts"
|
|
28
|
+
],
|
|
29
|
+
"references": [
|
|
30
|
+
{
|
|
31
|
+
"path": "./tsconfig.lib.json"
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types='vitest' />
|
|
2
|
+
import { defineConfig } from 'vite';
|
|
3
|
+
|
|
4
|
+
export default defineConfig(() => ({
|
|
5
|
+
root: import.meta.dirname,
|
|
6
|
+
cacheDir: '../../node_modules/.vite/packages/core',
|
|
7
|
+
plugins: [],
|
|
8
|
+
// Uncomment this if you are using workers.
|
|
9
|
+
// worker: {
|
|
10
|
+
// plugins: [],
|
|
11
|
+
// },
|
|
12
|
+
test: {
|
|
13
|
+
name: '@easyhook/core',
|
|
14
|
+
watch: false,
|
|
15
|
+
globals: true,
|
|
16
|
+
environment: 'node',
|
|
17
|
+
include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
|
18
|
+
reporters: ['default'],
|
|
19
|
+
coverage: {
|
|
20
|
+
reportsDirectory: './test-output/vitest/coverage',
|
|
21
|
+
provider: 'v8' as const,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
}));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config';
|
|
2
|
+
|
|
3
|
+
export default defineConfig(() => ({
|
|
4
|
+
root: __dirname,
|
|
5
|
+
cacheDir: '../../node_modules/.vite/packages/core',
|
|
6
|
+
test: {
|
|
7
|
+
name: '@easyhook/core',
|
|
8
|
+
watch: false,
|
|
9
|
+
globals: true,
|
|
10
|
+
environment: 'node',
|
|
11
|
+
include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
|
12
|
+
reporters: ['default'],
|
|
13
|
+
coverage: {
|
|
14
|
+
reportsDirectory: './test-output/vitest/coverage',
|
|
15
|
+
provider: 'v8' as const,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
}));
|