@emulators/google

中文文档
0.13.1发布于 2026/11/09Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 24.3万

Google OAuth 2.0, OpenID Connect, and mutable Google Workspace-style surfaces for local Gmail, Calendar, and Drive flows.

原始使用文档
文档目录13 节
  1. Install
  2. Endpoints
  3. OAuth & OIDC
  4. Gmail
  5. Drafts
  6. Threads
  7. Labels
  8. History, Watch & Settings
  9. Calendar
  10. Drive
  11. Auth
  12. Seed Configuration
  13. Links

@emulators/google

Google OAuth 2.0, OpenID Connect, and mutable Google Workspace-style surfaces for local Gmail, Calendar, and Drive flows.

Part of emulate — local drop-in replacement services for CI and no-network sandboxes.

Install

npm install @emulators/google

Endpoints

OAuth & OIDC

  • GET /o/oauth2/v2/auth — authorization endpoint
  • POST /oauth2/token — token exchange
  • GET /oauth2/v2/userinfo — get user info
  • GET /.well-known/openid-configuration — OIDC discovery document
  • GET /oauth2/v3/certs — JSON Web Key Set (JWKS) with the RSA public key for ID token verification

Gmail

  • GET /gmail/v1/users/:userId/messages — list messages with q, labelIds, maxResults, and pageToken
  • GET /gmail/v1/users/:userId/messages/:id — fetch message in full, metadata, minimal, or raw formats
  • GET /gmail/v1/users/:userId/messages/:messageId/attachments/:id — fetch attachment bodies
  • POST /gmail/v1/users/:userId/messages/send — create sent mail from raw MIME or structured fields
  • POST /gmail/v1/users/:userId/messages/import — import inbox mail
  • POST /gmail/v1/users/:userId/messages — insert a message directly
  • POST /gmail/v1/users/:userId/messages/:id/modify — add/remove labels on one message
  • POST /gmail/v1/users/:userId/messages/batchModify — add/remove labels across many messages
  • POST /gmail/v1/users/:userId/messages/:id/trash — trash message
  • POST /gmail/v1/users/:userId/messages/:id/untrash — untrash message

Drafts

  • GET /gmail/v1/users/:userId/drafts — list drafts
  • POST /gmail/v1/users/:userId/drafts — create draft
  • GET /gmail/v1/users/:userId/drafts/:id — get draft
  • PUT /gmail/v1/users/:userId/drafts/:id — update draft
  • POST /gmail/v1/users/:userId/drafts/:id/send — send draft
  • DELETE /gmail/v1/users/:userId/drafts/:id — delete draft

Threads

  • GET /gmail/v1/users/:userId/threads — list threads
  • GET /gmail/v1/users/:userId/threads/:id — get thread
  • POST /gmail/v1/users/:userId/threads/:id/modify — add/remove labels across a thread

Labels

  • GET /gmail/v1/users/:userId/labels — list labels
  • POST /gmail/v1/users/:userId/labels — create label
  • PATCH /gmail/v1/users/:userId/labels/:id — update label
  • DELETE /gmail/v1/users/:userId/labels/:id — delete label

History, Watch & Settings

  • GET /gmail/v1/users/:userId/history — list history
  • POST /gmail/v1/users/:userId/watch — set up push notifications
  • POST /gmail/v1/users/:userId/stop — stop push notifications
  • GET /gmail/v1/users/:userId/settings/filters — list filters
  • POST /gmail/v1/users/:userId/settings/filters — create filter
  • DELETE /gmail/v1/users/:userId/settings/filters/:id — delete filter
  • GET /gmail/v1/users/:userId/settings/forwardingAddresses — list forwarding addresses
  • GET /gmail/v1/users/:userId/settings/sendAs — list send-as aliases

Calendar

  • GET /discovery/v1/apis/calendar/v3/rest — public Calendar v3 REST discovery document
  • GET /calendar/v3/users/:userId/calendarList — list calendars
  • GET /calendar/v3/calendars/:calendarId/events — list events
  • POST /calendar/v3/calendars/:calendarId/events — create event
  • DELETE /calendar/v3/calendars/:calendarId/events/:eventId — delete event
  • POST /calendar/v3/freeBusy — free/busy query

Drive

  • GET /drive/v3/files — list files
  • GET /drive/v3/files/:fileId — get file metadata
  • POST /drive/v3/files — create file
  • PATCH /drive/v3/files/:fileId — update file metadata
  • PUT /drive/v3/files/:fileId — update file content
  • POST /upload/drive/v3/files — upload file

Auth

Standard OAuth 2.0 authorization code flow with RS256-signed OIDC ID tokens. Configure clients in the seed config. The discovery document advertises RS256 and /oauth2/v3/certs returns the RSA public key used to verify issued ID tokens.

Seed Configuration

google:
  users:
    - email: [email protected]
      name: Test User
  oauth_clients:
    - client_id: my-client-id.apps.googleusercontent.com
      client_secret: GOCSPX-secret
      redirect_uris:
        - http://localhost:3000/api/auth/callback/google
  labels:
    - id: Label_ops
      user_email: [email protected]
      name: Ops/Review
  messages:
    - id: msg_welcome
      user_email: [email protected]
      from: [email protected]
      to: [email protected]
      subject: Welcome to the Gmail emulator
      body_text: You can now test Gmail, Calendar, and Drive flows locally.
      label_ids: [INBOX, UNREAD, CATEGORY_UPDATES]
  calendars:
    - id: primary
      user_email: [email protected]
      summary: [email protected]
      primary: true
      time_zone: UTC
  calendar_events:
    - id: evt_kickoff
      user_email: [email protected]
      calendar_id: primary
      summary: Project Kickoff
      start_date_time: 2025-01-10T09:00:00.000Z
      end_date_time: 2025-01-10T09:30:00.000Z
  drive_items:
    - id: drv_docs
      user_email: [email protected]
      name: Docs
      mime_type: application/vnd.google-apps.folder
      parent_ids: [root]

版本与发布记录

@emulators/google 共发布 19 个版本,首次发布于 2026/03/27;过去 12 个月发布了 19 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.13.1latest2026/11/094 天前
0.13.02026/10/2915 天前
0.12.32026/10/2321 天前
0.12.22026/10/1430 天前
0.12.12026/10/021 个月前
0.12.02026/09/241 个月前

关于 @emulators/google 的常见问题

@emulators/google 是什么?

Google OAuth 2.0, OpenID Connect, and mutable Google Workspace-style surfaces for local Gmail, Calendar, and Drive flows.

如何安装 @emulators/google?

在项目目录运行 npm install @emulators/google,或使用 pnpm add / yarn add / bun add。

@emulators/google 支持 TypeScript 吗?

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

@emulators/google 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@emulators/google 可以商用吗?

@emulators/google 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@emulators/google 的下载量有多少?

根据 npm 官方下载统计,@emulators/google 在 2026/10/14 – 2026/11/12 这 30 天内被下载 243,499 次,日均约 8,117 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@emulators/google 还在维护吗?

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