Lifecycle hooks interfaces for Dismissible applications
npm install @dismissible/nestjs-hooksNever Show The Same Thing Twice!
Dismissible manages the state of your UI elements across sessions, so your users see what matters, once! No more onboarding messages reappearing on every tab, no more notifications haunting users across devices. Dismissible syncs dismissal state everywhere, so every message is intentional, never repetitive.
Lifecycle hooks interfaces for Dismissible applications.
> Part of the Dismissible API - This library is part of the Dismissible API ecosystem. Visit dismissible.io for more information and documentation.
This library provides the core interfaces for implementing lifecycle hooks in the Dismissible system:
- IDismissibleLifecycleHook - Interface for lifecycle hooks
- IHookResult - Result returned by pre-hooks
- IHookMutations - Mutations that can be applied by pre-hooks
- IRequestContext - Request context passed through dismissible operations
- DISMISSIBLE_HOOKS - Injection token for lifecycle hooks
``bash`
npm install @dismissible/nestjs-hooks
Implement the IDismissibleLifecycleHook interface to create custom lifecycle hooks:
`typescript
import { Injectable } from '@nestjs/common';
import { IDismissibleLifecycleHook, IHookResult, IRequestContext } from '@dismissible/nestjs-hooks';
@Injectable()
export class MyLifecycleHook implements IDismissibleLifecycleHook {
readonly priority = 0;
async onBeforeRequest(
itemId: string,
userId: string,
context?: IRequestContext,
): Promise
// Your logic here
return { proceed: true };
}
}
`
Interface for lifecycle hooks that can intercept dismissible operations.
#### Methods
- onBeforeRequest(itemId, userId, context?) - Called at the start of any operationonAfterRequest(itemId, item, userId, context?)
- - Called at the end of any operationonBeforeGet(itemId, item, userId, context?)
- - Called before returning an existing itemonAfterGet(itemId, item, userId, context?)
- - Called after returning an existing itemonBeforeCreate(itemId, userId, context?)
- - Called before creating a new itemonAfterCreate(itemId, item, userId, context?)
- - Called after creating a new itemonBeforeDismiss(itemId, userId, context?)
- - Called before dismissing an itemonAfterDismiss(itemId, item, userId, context?)
- - Called after dismissing an itemonBeforeRestore(itemId, userId, context?)
- - Called before restoring an itemonAfterRestore(itemId, item, userId, context?)
- - Called after restoring an item
Result returned by pre-hooks.
`typescript`
interface IHookResult {
proceed: boolean;
reason?: string;
mutations?: IHookMutations;
}
Mutations that can be applied by pre-hooks.
`typescript`
interface IHookMutations {
id?: string;
userId?: string;
context?: Partial
}
Request context passed through dismissible operations.
`typescript`
interface IRequestContext {
requestId: string;
authorizationHeader?: string;
}
This library is typically used alongside other Dismissible packages:
- @dismissible/nestjs-core - Main dismissible service and module@dismissible/nestjs-item
- - Core data models@dismissible/nestjs-jwt-auth-hook` - JWT authentication hook implementation
-
MIT