@flatfile/listener-driver-pubsub

中文文档
3.0.0发布于 2026/11/12ISCTypeScriptESM + CJS构建来源已验证近 30 天下载 11.3万

A driver for streaming events from Flatfile via a pubsub pattern

原始使用文档
文档目录5 节
  1. Introduction
  2. Usage
  3. Logging
  4. Axios Interceptor
  5. Errors

@flatfile/listener-driver-pubsub

This document provides instructions on how to use the PubSubDriver class, a utility for the @flatfile/listener package.

Introduction

PubSubDriver is an EventDriver that uses a real-time messaging system to listen for events. It uses the Flatfile API to authenticate, and automatically handles re-authentication if necessary.

The driver requires a scope, which can either be an environment or space ID. It also sets up an interceptor for Axios, which helps in debugging HTTP requests.

Usage

Import the necessary dependencies:

import { EventDriver } from '@flatfile/listener'
import { PubSubDriver } from './PubSubDriver'

Create a new PubSubDriver instance, passing the scope as a string (either an environment ID or a space ID):

const pubSubDriver = new PubSubDriver('your-environment-or-space-id')

Start the driver:

pubSubDriver.mount(instanceOfListenerClient)
pubSubDriver.start()

Please note that the start method is asynchronous and returns a Promise.

The PubSubDriver instance will automatically subscribe to the event channel corresponding to the provided scope, and will start processing events as they come in.

It also handles connection status events, logging successful connections and errors, and automatically reauthenticating if necessary.

Logging

The PubSubDriver uses the Debugger from the @flatfile/utils-debugger package to log events. Log entries include successful connections, errors, and event processing info.

For example, when the driver successfully connects to the event stream, it logs a success message with the scope:

  ✅ Connected to event stream for scope your-environment-or-space-id

Please refer to the @flatfile/utils-debugger package documentation for more information on how logging works.

Axios Interceptor

The axiosInterceptor from @flatfile/utils-debugger is automatically set up when the PubSubDriver is started, which can help with debugging HTTP requests made using Axios.

Please refer to the @flatfile/utils-debugger package documentation for more information on how the Axios interceptor works.

Errors

If the scope is not provided during the initialization of PubSubDriver, an error is thrown:

Error: scope is required (must be an environment or space id)

Please ensure that a valid scope is provided when creating a new PubSubDriver instance.

版本与发布记录

@flatfile/listener-driver-pubsub 共发布 29 个版本,首次发布于 2023/06/07;过去 12 个月发布了 1 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.0.0latest2026/11/124 天前
2.1.02024/05/232 年前
2.0.82024/05/232 年前
2.0.72024/05/022 年前
2.0.52024/04/112 年前
2.0.42024/02/082 年前

其他发布通道:next → 1.0.12-rc4。

关于 @flatfile/listener-driver-pubsub 的常见问题

@flatfile/listener-driver-pubsub 是什么?

A driver for streaming events from Flatfile via a pubsub pattern

如何安装 @flatfile/listener-driver-pubsub?

在项目目录运行 npm install @flatfile/listener-driver-pubsub,或使用 pnpm add / yarn add / bun add。

@flatfile/listener-driver-pubsub 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@flatfile/listener-driver-pubsub 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@flatfile/listener-driver-pubsub 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@flatfile/listener-driver-pubsub 可以商用吗?

@flatfile/listener-driver-pubsub 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@flatfile/listener-driver-pubsub 的下载量有多少?

根据 npm 官方下载统计,@flatfile/listener-driver-pubsub 在 2026/10/15 – 2026/11/13 这 30 天内被下载 113,383 次,日均约 3,779 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@flatfile/listener-driver-pubsub 还在维护吗?

最新版本 3.0.0 发布于 2026/11/12(4 天前);至今共发布 29 个版本,其中过去 12 个月发布了 1 个;首次发布于 2023/06/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。