{"id":45743,"library":"payload-hooks-queue","title":"Payload Hooks Queue","description":"A lightweight utility for deferring Payload CMS collection hooks into background jobs or workflows. Version 0.0.1 is the initial release, designed for Payload 2.x+. It captures hook payloads (beforeChange, afterChange, etc.) and pushes them to a queue for async processing, reducing request latency and preventing hook failures from blocking API responses. Unlike custom job runners, it integrates directly with Payload's hook system and can work with any queue backend (Bull, Redis, etc.) via a simple adapter pattern. Ships TypeScript types.","status":"active","version":"0.0.1","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","typescript"],"install":[{"cmd":"npm install payload-hooks-queue","lang":"bash","label":"npm"},{"cmd":"yarn add payload-hooks-queue","lang":"bash","label":"yarn"},{"cmd":"pnpm add payload-hooks-queue","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: integrates with Payload CMS collection hooks","package":"payload","optional":false}],"imports":[{"note":"Package is ESM-only; CommonJS require will not work.","wrong":"const createHookQueue = require('payload-hooks-queue')","symbol":"createHookQueue","correct":"import { createHookQueue } from 'payload-hooks-queue'"},{"note":"QueuePayload is a type (interface) and should be imported with import type in TypeScript to avoid runtime errors.","wrong":"import { QueuePayload } from 'payload-hooks-queue'","symbol":"QueuePayload","correct":"import type { QueuePayload } from 'payload-hooks-queue'"},{"note":"HookEventType is a runtime enum; named import is correct.","wrong":"","symbol":"HookEventType","correct":"import { HookEventType } from 'payload-hooks-queue'"}],"quickstart":{"code":"import { createHookQueue } from 'payload-hooks-queue';\nimport { CollectionConfig } from 'payload/types';\n\nconst myQueue = createHookQueue({\n  type: 'bull',\n  options: {\n    redis: { host: 'localhost', port: 6379 },\n  },\n});\n\nexport const MyCollection: CollectionConfig = {\n  slug: 'items',\n  hooks: {\n    afterChange: [\n      myQueue.enqueue({\n        handler: async (args) => {\n          // background processing\n          console.log('Processing doc', args.doc.id);\n        },\n      }),\n    ],\n  },\n  fields: [],\n};","lang":"typescript","description":"Creates a Bull queue adapter and attaches it to a Payload collection's afterChange hook for async processing."},"warnings":[{"fix":"Install the queue adapter: npm install bull (or redis, etc.)","message":"The queue adapter (Bull in this example) must be installed separately; payload-hooks-queue does not bundle it.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Pin to a specific version and test upgrades thoroughly.","message":"Initial release (0.0.1); all APIs are experimental and may change without major version bump.","severity":"breaking","affected_versions":"0.0.1"},{"fix":"Wrap enqueue in try/catch or use a fallback synchronous handler.","message":"Hooks run asynchronously; if the queue fails to enqueue, the hook will reject, potentially causing request failure. Ensure queue connection is resilient.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'0.0.1':19 '2':27 'adapt':81 'afterchang':34 'api':54 'async':43 'backend':74 'background':14 'beforechang':33 'block':53 'bull':75 'captur':30 'cms':10 'collect':11 'custom':57 'defer':8 'design':24 'direct':62 'etc':35,77 'failur':51 'hook':2,12,31,50,66 'initi':22 'integr':61 'javascript':86 'job':15,58 'latenc':47 'lightweight':5 'pattern':82 'payload':1,9,26,32,64 'prevent':49 'process':44 'push':37 'queue':3,41,73 'redi':76 'reduc':45 'releas':23 'request':46 'respons':55 'runner':59 'ship':83 'simpl':80 'system':67 'type':85 'typescript':84,87 'unlik':56 'util':6 'version':18 'via':78 'work':70 'workflow':17 'x':28","created_at":"2026-06-07T12:56:30.883367+00:00","updated_at":"2026-06-07T12:56:30.883367+00:00","problems":[{"fix":"npm install payload-hooks-queue","cause":"Package not installed or missing from package.json","error":"Error: Cannot find module 'payload-hooks-queue'"},{"fix":"Use import { createHookQueue } from 'payload-hooks-queue' and ensure \"type\": \"module\" in package.json or use .mjs extension.","cause":"CommonJS require used instead of ESM import; this package is ESM-only.","error":"TypeError: createHookQueue is not a function"},{"fix":"Ensure the hook array item is the result of myQueue.enqueue({...}) which returns a function wrapping the queued handler.","cause":"enqueue() returns an object, but Payload expects a function. The returned object is not compatible directly.","error":"TypeError: AfterChange hook must be an array of functions"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":null,"npm":"payload-hooks-queue","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops","storage"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}