@dismissible/nestjs-hooks
v3.1.1
Published
Lifecycle hooks interfaces for Dismissible applications
Maintainers
Readme
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.
@dismissible/nestjs-hooks
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.
Overview
This library provides the core interfaces for implementing lifecycle hooks in the Dismissible system:
IDismissibleLifecycleHook- Interface for lifecycle hooksIHookResult- Result returned by pre-hooksIHookMutations- Mutations that can be applied by pre-hooksIRequestContext- Request context passed through dismissible operationsDISMISSIBLE_HOOKS- Injection token for lifecycle hooks
Installation
npm install @dismissible/nestjs-hooksGetting Started
Basic Usage
Implement the IDismissibleLifecycleHook interface to create custom lifecycle hooks:
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<IHookResult> {
// Your logic here
return { proceed: true };
}
}API Reference
IDismissibleLifecycleHook
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
IHookResult
Result returned by pre-hooks.
interface IHookResult {
proceed: boolean;
reason?: string;
mutations?: IHookMutations;
}IHookMutations
Mutations that can be applied by pre-hooks.
interface IHookMutations {
id?: string;
userId?: string;
context?: Partial<IRequestContext>;
}IRequestContext
Request context passed through dismissible operations.
interface IRequestContext {
requestId: string;
authorizationHeader?: string;
}Related Packages
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
License
MIT
