@dismissible/nestjs-dismissible-hooks 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/README.md +116 -0
- package/package.json +38 -0
- package/src/index.d.ts +1 -0
- 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/README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# @dismissible/nestjs-dismissible-hooks
|
|
2
|
+
|
|
3
|
+
Lifecycle hooks interfaces for Dismissible applications.
|
|
4
|
+
|
|
5
|
+
> **Part of the Dismissible API** - This library is part of the [Dismissible API](https://dismissible.io) ecosystem. Visit [dismissible.io](https://dismissible.io) for more information and documentation.
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
This library provides the core interfaces for implementing lifecycle hooks in the Dismissible system:
|
|
10
|
+
|
|
11
|
+
- `IDismissibleLifecycleHook` - Interface for lifecycle hooks
|
|
12
|
+
- `IHookResult` - Result returned by pre-hooks
|
|
13
|
+
- `IHookMutations` - Mutations that can be applied by pre-hooks
|
|
14
|
+
- `IRequestContext` - Request context passed through dismissible operations
|
|
15
|
+
- `DISMISSIBLE_HOOKS` - Injection token for lifecycle hooks
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @dismissible/nestjs-dismissible-hooks
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Getting Started
|
|
24
|
+
|
|
25
|
+
### Basic Usage
|
|
26
|
+
|
|
27
|
+
Implement the `IDismissibleLifecycleHook` interface to create custom lifecycle hooks:
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { Injectable } from '@nestjs/common';
|
|
31
|
+
import {
|
|
32
|
+
IDismissibleLifecycleHook,
|
|
33
|
+
IHookResult,
|
|
34
|
+
IRequestContext,
|
|
35
|
+
} from '@dismissible/nestjs-dismissible-hooks';
|
|
36
|
+
|
|
37
|
+
@Injectable()
|
|
38
|
+
export class MyLifecycleHook implements IDismissibleLifecycleHook {
|
|
39
|
+
readonly priority = 0;
|
|
40
|
+
|
|
41
|
+
async onBeforeRequest(
|
|
42
|
+
itemId: string,
|
|
43
|
+
userId: string,
|
|
44
|
+
context?: IRequestContext,
|
|
45
|
+
): Promise<IHookResult> {
|
|
46
|
+
// Your logic here
|
|
47
|
+
return { proceed: true };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## API Reference
|
|
53
|
+
|
|
54
|
+
### IDismissibleLifecycleHook
|
|
55
|
+
|
|
56
|
+
Interface for lifecycle hooks that can intercept dismissible operations.
|
|
57
|
+
|
|
58
|
+
#### Methods
|
|
59
|
+
|
|
60
|
+
- `onBeforeRequest(itemId, userId, context?)` - Called at the start of any operation
|
|
61
|
+
- `onAfterRequest(itemId, item, userId, context?)` - Called at the end of any operation
|
|
62
|
+
- `onBeforeGet(itemId, item, userId, context?)` - Called before returning an existing item
|
|
63
|
+
- `onAfterGet(itemId, item, userId, context?)` - Called after returning an existing item
|
|
64
|
+
- `onBeforeCreate(itemId, userId, context?)` - Called before creating a new item
|
|
65
|
+
- `onAfterCreate(itemId, item, userId, context?)` - Called after creating a new item
|
|
66
|
+
- `onBeforeDismiss(itemId, userId, context?)` - Called before dismissing an item
|
|
67
|
+
- `onAfterDismiss(itemId, item, userId, context?)` - Called after dismissing an item
|
|
68
|
+
- `onBeforeRestore(itemId, userId, context?)` - Called before restoring an item
|
|
69
|
+
- `onAfterRestore(itemId, item, userId, context?)` - Called after restoring an item
|
|
70
|
+
|
|
71
|
+
### IHookResult
|
|
72
|
+
|
|
73
|
+
Result returned by pre-hooks.
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
interface IHookResult {
|
|
77
|
+
proceed: boolean;
|
|
78
|
+
reason?: string;
|
|
79
|
+
mutations?: IHookMutations;
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### IHookMutations
|
|
84
|
+
|
|
85
|
+
Mutations that can be applied by pre-hooks.
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
interface IHookMutations {
|
|
89
|
+
id?: string;
|
|
90
|
+
userId?: string;
|
|
91
|
+
context?: Partial<IRequestContext>;
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### IRequestContext
|
|
96
|
+
|
|
97
|
+
Request context passed through dismissible operations.
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
interface IRequestContext {
|
|
101
|
+
requestId: string;
|
|
102
|
+
authorizationHeader?: string;
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Related Packages
|
|
107
|
+
|
|
108
|
+
This library is typically used alongside other Dismissible packages:
|
|
109
|
+
|
|
110
|
+
- `@dismissible/nestjs-dismissible` - Main dismissible service and module
|
|
111
|
+
- `@dismissible/nestjs-dismissible-item` - Core data models
|
|
112
|
+
- `@dismissible/nestjs-jwt-auth-hook` - JWT authentication hook implementation
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dismissible/nestjs-dismissible-hooks",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Lifecycle hooks interfaces for Dismissible applications",
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"types": "./src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./src/index.mjs",
|
|
10
|
+
"require": "./src/index.js",
|
|
11
|
+
"types": "./src/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"src",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@dismissible/nestjs-dismissible-item": "^0.0.1",
|
|
20
|
+
"@dismissible/nestjs-dismissible-request": "^0.0.1"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"nestjs",
|
|
24
|
+
"dismissible",
|
|
25
|
+
"hooks",
|
|
26
|
+
"lifecycle"
|
|
27
|
+
],
|
|
28
|
+
"author": "",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/DismissibleIo/dismissible-api"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"type": "commonjs"
|
|
38
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lifecycle-hook.interface';
|
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"}
|