@dismissible/nestjs-dismissible-hooks 0.0.2-canary.585db17.0 → 0.0.2-canary.a611bd3.0
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/package.json +9 -4
- package/src/index.js +5 -0
- package/src/index.js.map +1 -0
- package/src/lifecycle-hook.interface.d.ts +84 -0
- package/src/lifecycle-hook.interface.js +8 -0
- package/src/lifecycle-hook.interface.js.map +1 -0
- package/jest.config.ts +0 -26
- package/project.json +0 -42
- package/src/lifecycle-hook.interface.ts +0 -148
- package/tsconfig.json +0 -16
- package/tsconfig.lib.json +0 -14
- package/tsconfig.spec.json +0 -9
- /package/src/{index.ts → index.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dismissible/nestjs-dismissible-hooks",
|
|
3
|
-
"version": "0.0.2-canary.
|
|
3
|
+
"version": "0.0.2-canary.a611bd3.0",
|
|
4
4
|
"description": "Lifecycle hooks interfaces for Dismissible applications",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
@@ -11,9 +11,13 @@
|
|
|
11
11
|
"types": "./src/index.d.ts"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
+
"files": [
|
|
15
|
+
"src",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
14
18
|
"dependencies": {
|
|
15
|
-
"@dismissible/nestjs-dismissible-item": "
|
|
16
|
-
"@dismissible/nestjs-dismissible-request": "
|
|
19
|
+
"@dismissible/nestjs-dismissible-item": "0.0.2-canary.a611bd3.0",
|
|
20
|
+
"@dismissible/nestjs-dismissible-request": "0.0.2-canary.a611bd3.0"
|
|
17
21
|
},
|
|
18
22
|
"keywords": [
|
|
19
23
|
"nestjs",
|
|
@@ -29,5 +33,6 @@
|
|
|
29
33
|
},
|
|
30
34
|
"publishConfig": {
|
|
31
35
|
"access": "public"
|
|
32
|
-
}
|
|
36
|
+
},
|
|
37
|
+
"type": "commonjs"
|
|
33
38
|
}
|
package/src/index.js
ADDED
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/dismissible-hooks/src/index.ts"],"names":[],"mappings":";;;AAAA,qEAA2C"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { DismissibleItemDto } from '@dismissible/nestjs-dismissible-item';
|
|
2
|
+
import { IRequestContext } from '@dismissible/nestjs-dismissible-request';
|
|
3
|
+
/**
|
|
4
|
+
* Injection token for lifecycle hooks.
|
|
5
|
+
*/
|
|
6
|
+
export declare const DISMISSIBLE_HOOKS: unique symbol;
|
|
7
|
+
/**
|
|
8
|
+
* Mutations that can be applied by pre-hooks.
|
|
9
|
+
*/
|
|
10
|
+
export interface IHookMutations {
|
|
11
|
+
/** Mutated item ID */
|
|
12
|
+
id?: string;
|
|
13
|
+
/** Mutated user ID */
|
|
14
|
+
userId?: string;
|
|
15
|
+
/** Mutated request context */
|
|
16
|
+
context?: Partial<IRequestContext>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Result returned by pre-hooks.
|
|
20
|
+
*/
|
|
21
|
+
export interface IHookResult {
|
|
22
|
+
/** Whether the operation should proceed */
|
|
23
|
+
proceed: boolean;
|
|
24
|
+
/** Optional reason if the operation is blocked */
|
|
25
|
+
reason?: string;
|
|
26
|
+
/** Optional mutations to apply */
|
|
27
|
+
mutations?: IHookMutations;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Interface for lifecycle hooks that can intercept dismissible operations.
|
|
31
|
+
*/
|
|
32
|
+
export interface IDismissibleLifecycleHook {
|
|
33
|
+
/**
|
|
34
|
+
* Priority for hook execution (lower numbers run first).
|
|
35
|
+
* Default is 0.
|
|
36
|
+
*/
|
|
37
|
+
readonly priority?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Called at the start of any operation (getOrCreate, dismiss, restore).
|
|
40
|
+
* Use for global concerns like authentication, rate limiting, request validation.
|
|
41
|
+
*/
|
|
42
|
+
onBeforeRequest?(itemId: string, userId: string, context?: IRequestContext): Promise<IHookResult> | IHookResult;
|
|
43
|
+
/**
|
|
44
|
+
* Called at the end of any operation (getOrCreate, dismiss, restore).
|
|
45
|
+
* Use for global concerns like audit logging, metrics, cleanup.
|
|
46
|
+
*/
|
|
47
|
+
onAfterRequest?(itemId: string, item: DismissibleItemDto, userId: string, context?: IRequestContext): Promise<void> | void;
|
|
48
|
+
/**
|
|
49
|
+
* Called before returning an existing item.
|
|
50
|
+
* Only called when item exists in storage.
|
|
51
|
+
* Use for access control based on item state (e.g., block dismissed items).
|
|
52
|
+
*/
|
|
53
|
+
onBeforeGet?(itemId: string, item: DismissibleItemDto, userId: string, context?: IRequestContext): Promise<IHookResult> | IHookResult;
|
|
54
|
+
/**
|
|
55
|
+
* Called after returning an existing item.
|
|
56
|
+
* Only called when item exists in storage.
|
|
57
|
+
*/
|
|
58
|
+
onAfterGet?(itemId: string, item: DismissibleItemDto, userId: string, context?: IRequestContext): Promise<void> | void;
|
|
59
|
+
/**
|
|
60
|
+
* Called before creating a new item.
|
|
61
|
+
* Use for plan limits, quota checks, etc.
|
|
62
|
+
*/
|
|
63
|
+
onBeforeCreate?(itemId: string, userId: string, context?: IRequestContext): Promise<IHookResult> | IHookResult;
|
|
64
|
+
/**
|
|
65
|
+
* Called after creating a new item.
|
|
66
|
+
*/
|
|
67
|
+
onAfterCreate?(itemId: string, item: DismissibleItemDto, userId: string, context?: IRequestContext): Promise<void> | void;
|
|
68
|
+
/**
|
|
69
|
+
* Called before dismissing an item.
|
|
70
|
+
*/
|
|
71
|
+
onBeforeDismiss?(itemId: string, userId: string, context?: IRequestContext): Promise<IHookResult> | IHookResult;
|
|
72
|
+
/**
|
|
73
|
+
* Called after dismissing an item.
|
|
74
|
+
*/
|
|
75
|
+
onAfterDismiss?(itemId: string, item: DismissibleItemDto, userId: string, context?: IRequestContext): Promise<void> | void;
|
|
76
|
+
/**
|
|
77
|
+
* Called before restoring an item.
|
|
78
|
+
*/
|
|
79
|
+
onBeforeRestore?(itemId: string, userId: string, context?: IRequestContext): Promise<IHookResult> | IHookResult;
|
|
80
|
+
/**
|
|
81
|
+
* Called after restoring an item.
|
|
82
|
+
*/
|
|
83
|
+
onAfterRestore?(itemId: string, item: DismissibleItemDto, userId: string, context?: IRequestContext): Promise<void> | void;
|
|
84
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DISMISSIBLE_HOOKS = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Injection token for lifecycle hooks.
|
|
6
|
+
*/
|
|
7
|
+
exports.DISMISSIBLE_HOOKS = Symbol('DISMISSIBLE_HOOKS');
|
|
8
|
+
//# sourceMappingURL=lifecycle-hook.interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle-hook.interface.js","sourceRoot":"","sources":["../../../../libs/dismissible-hooks/src/lifecycle-hook.interface.ts"],"names":[],"mappings":";;;AAGA;;GAEG;AACU,QAAA,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC"}
|
package/jest.config.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
displayName: 'dismissible-hooks',
|
|
3
|
-
preset: '../../jest.preset.js',
|
|
4
|
-
testEnvironment: 'node',
|
|
5
|
-
transform: {
|
|
6
|
-
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.json' }],
|
|
7
|
-
},
|
|
8
|
-
moduleFileExtensions: ['ts', 'js', 'html'],
|
|
9
|
-
coverageDirectory: '../../coverage/libs/dismissible-hooks',
|
|
10
|
-
collectCoverageFrom: [
|
|
11
|
-
'src/**/*.ts',
|
|
12
|
-
'!src/**/*.spec.ts',
|
|
13
|
-
'!src/**/*.interface.ts',
|
|
14
|
-
'!src/**/*.dto.ts',
|
|
15
|
-
'!src/**/*.enum.ts',
|
|
16
|
-
'!src/**/index.ts',
|
|
17
|
-
],
|
|
18
|
-
coverageThreshold: {
|
|
19
|
-
global: {
|
|
20
|
-
branches: 80,
|
|
21
|
-
functions: 80,
|
|
22
|
-
lines: 80,
|
|
23
|
-
statements: 80,
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
};
|
package/project.json
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dismissible-hooks",
|
|
3
|
-
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
-
"sourceRoot": "libs/dismissible-hooks/src",
|
|
5
|
-
"projectType": "library",
|
|
6
|
-
"tags": [],
|
|
7
|
-
"targets": {
|
|
8
|
-
"build": {
|
|
9
|
-
"executor": "@nx/js:tsc",
|
|
10
|
-
"outputs": ["{options.outputPath}"],
|
|
11
|
-
"options": {
|
|
12
|
-
"outputPath": "dist/libs/dismissible-hooks",
|
|
13
|
-
"main": "libs/dismissible-hooks/src/index.ts",
|
|
14
|
-
"tsConfig": "libs/dismissible-hooks/tsconfig.lib.json",
|
|
15
|
-
"assets": ["libs/dismissible-hooks/package.json", "libs/dismissible-hooks/README.md"],
|
|
16
|
-
"generatePackageJson": true
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
"lint": {
|
|
20
|
-
"executor": "@nx/eslint:lint",
|
|
21
|
-
"outputs": ["{options.outputFile}"],
|
|
22
|
-
"options": {
|
|
23
|
-
"lintFilePatterns": ["libs/dismissible-hooks/**/*.ts"]
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
"test": {
|
|
27
|
-
"executor": "@nx/jest:jest",
|
|
28
|
-
"outputs": ["{workspaceRoot}/coverage/libs/dismissible-hooks"],
|
|
29
|
-
"options": {
|
|
30
|
-
"jestConfig": "libs/dismissible-hooks/jest.config.ts",
|
|
31
|
-
"passWithNoTests": true
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
"npm-publish": {
|
|
35
|
-
"executor": "nx:run-commands",
|
|
36
|
-
"options": {
|
|
37
|
-
"command": "npm publish --access public",
|
|
38
|
-
"cwd": "dist/libs/dismissible-hooks"
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { DismissibleItemDto } from '@dismissible/nestjs-dismissible-item';
|
|
2
|
-
import { IRequestContext } from '@dismissible/nestjs-dismissible-request';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Injection token for lifecycle hooks.
|
|
6
|
-
*/
|
|
7
|
-
export const DISMISSIBLE_HOOKS = Symbol('DISMISSIBLE_HOOKS');
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Mutations that can be applied by pre-hooks.
|
|
11
|
-
*/
|
|
12
|
-
export interface IHookMutations {
|
|
13
|
-
/** Mutated item ID */
|
|
14
|
-
id?: string;
|
|
15
|
-
|
|
16
|
-
/** Mutated user ID */
|
|
17
|
-
userId?: string;
|
|
18
|
-
|
|
19
|
-
/** Mutated request context */
|
|
20
|
-
context?: Partial<IRequestContext>;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Result returned by pre-hooks.
|
|
25
|
-
*/
|
|
26
|
-
export interface IHookResult {
|
|
27
|
-
/** Whether the operation should proceed */
|
|
28
|
-
proceed: boolean;
|
|
29
|
-
|
|
30
|
-
/** Optional reason if the operation is blocked */
|
|
31
|
-
reason?: string;
|
|
32
|
-
|
|
33
|
-
/** Optional mutations to apply */
|
|
34
|
-
mutations?: IHookMutations;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Interface for lifecycle hooks that can intercept dismissible operations.
|
|
39
|
-
*/
|
|
40
|
-
export interface IDismissibleLifecycleHook {
|
|
41
|
-
/**
|
|
42
|
-
* Priority for hook execution (lower numbers run first).
|
|
43
|
-
* Default is 0.
|
|
44
|
-
*/
|
|
45
|
-
readonly priority?: number;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Called at the start of any operation (getOrCreate, dismiss, restore).
|
|
49
|
-
* Use for global concerns like authentication, rate limiting, request validation.
|
|
50
|
-
*/
|
|
51
|
-
onBeforeRequest?(
|
|
52
|
-
itemId: string,
|
|
53
|
-
userId: string,
|
|
54
|
-
context?: IRequestContext,
|
|
55
|
-
): Promise<IHookResult> | IHookResult;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Called at the end of any operation (getOrCreate, dismiss, restore).
|
|
59
|
-
* Use for global concerns like audit logging, metrics, cleanup.
|
|
60
|
-
*/
|
|
61
|
-
onAfterRequest?(
|
|
62
|
-
itemId: string,
|
|
63
|
-
item: DismissibleItemDto,
|
|
64
|
-
userId: string,
|
|
65
|
-
context?: IRequestContext,
|
|
66
|
-
): Promise<void> | void;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Called before returning an existing item.
|
|
70
|
-
* Only called when item exists in storage.
|
|
71
|
-
* Use for access control based on item state (e.g., block dismissed items).
|
|
72
|
-
*/
|
|
73
|
-
onBeforeGet?(
|
|
74
|
-
itemId: string,
|
|
75
|
-
item: DismissibleItemDto,
|
|
76
|
-
userId: string,
|
|
77
|
-
context?: IRequestContext,
|
|
78
|
-
): Promise<IHookResult> | IHookResult;
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Called after returning an existing item.
|
|
82
|
-
* Only called when item exists in storage.
|
|
83
|
-
*/
|
|
84
|
-
onAfterGet?(
|
|
85
|
-
itemId: string,
|
|
86
|
-
item: DismissibleItemDto,
|
|
87
|
-
userId: string,
|
|
88
|
-
context?: IRequestContext,
|
|
89
|
-
): Promise<void> | void;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Called before creating a new item.
|
|
93
|
-
* Use for plan limits, quota checks, etc.
|
|
94
|
-
*/
|
|
95
|
-
onBeforeCreate?(
|
|
96
|
-
itemId: string,
|
|
97
|
-
userId: string,
|
|
98
|
-
context?: IRequestContext,
|
|
99
|
-
): Promise<IHookResult> | IHookResult;
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Called after creating a new item.
|
|
103
|
-
*/
|
|
104
|
-
onAfterCreate?(
|
|
105
|
-
itemId: string,
|
|
106
|
-
item: DismissibleItemDto,
|
|
107
|
-
userId: string,
|
|
108
|
-
context?: IRequestContext,
|
|
109
|
-
): Promise<void> | void;
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Called before dismissing an item.
|
|
113
|
-
*/
|
|
114
|
-
onBeforeDismiss?(
|
|
115
|
-
itemId: string,
|
|
116
|
-
userId: string,
|
|
117
|
-
context?: IRequestContext,
|
|
118
|
-
): Promise<IHookResult> | IHookResult;
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Called after dismissing an item.
|
|
122
|
-
*/
|
|
123
|
-
onAfterDismiss?(
|
|
124
|
-
itemId: string,
|
|
125
|
-
item: DismissibleItemDto,
|
|
126
|
-
userId: string,
|
|
127
|
-
context?: IRequestContext,
|
|
128
|
-
): Promise<void> | void;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Called before restoring an item.
|
|
132
|
-
*/
|
|
133
|
-
onBeforeRestore?(
|
|
134
|
-
itemId: string,
|
|
135
|
-
userId: string,
|
|
136
|
-
context?: IRequestContext,
|
|
137
|
-
): Promise<IHookResult> | IHookResult;
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Called after restoring an item.
|
|
141
|
-
*/
|
|
142
|
-
onAfterRestore?(
|
|
143
|
-
itemId: string,
|
|
144
|
-
item: DismissibleItemDto,
|
|
145
|
-
userId: string,
|
|
146
|
-
context?: IRequestContext,
|
|
147
|
-
): Promise<void> | void;
|
|
148
|
-
}
|
package/tsconfig.json
DELETED
package/tsconfig.lib.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "../../dist/out-tsc",
|
|
5
|
-
"declaration": true,
|
|
6
|
-
"module": "commonjs",
|
|
7
|
-
"types": ["node"],
|
|
8
|
-
"emitDecoratorMetadata": true,
|
|
9
|
-
"experimentalDecorators": true,
|
|
10
|
-
"target": "ES2021"
|
|
11
|
-
},
|
|
12
|
-
"exclude": ["node_modules", "**/*.spec.ts", "**/*.test.ts"],
|
|
13
|
-
"include": ["src/**/*.ts"]
|
|
14
|
-
}
|
package/tsconfig.spec.json
DELETED
|
File without changes
|