@cyc-seattle/gsuite-sdk

中文文档
1.0.0发布于 2026/11/03Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 2141

Domain-agnostic wrappers around Google Workspace APIs

原始使用文档
文档目录7 节
  1. Directory and Group Settings
  2. Client options
  3. Retries
  4. Workspace fake
  5. Container image
  6. Development
  7. Release

@cyc-seattle/gsuite-sdk

Typed wrappers around Google Workspace APIs: the Admin SDK Directory and Group Settings.

pnpm add @cyc-seattle/gsuite-sdk

Every client takes a GoogleAuth instance from googleapis. It uses Application Default Credentials (ADC) unless you pass a key. Set scopes for the APIs you call.

Directory and Group Settings

import { DirectoryClient, GroupSettingsClient } from "@cyc-seattle/gsuite-sdk";
import { google } from "googleapis";

const auth = new google.auth.GoogleAuth({
  scopes: [
    "https://www.googleapis.com/auth/admin.directory.group",
    "https://www.googleapis.com/auth/apps.groups.settings",
  ],
});
const members = await new DirectoryClient(auth).listMembers("[email protected]");
const settings = await new GroupSettingsClient(auth).getSettings("[email protected]");

Client options

DirectoryClient and GroupSettingsClient take an optional second argument:

  • rootUrl sends requests somewhere other than Google, such as the Workspace fake. googleapis uses only its origin.
  • pacing sets safeCall's waits: requestDelayMs before every request (default 500) and retryDelayMs before the retry of a transient error (default 60000).
const directory = new DirectoryClient(auth, { rootUrl, pacing: { requestDelayMs: 0, retryDelayMs: 0 } });

Retries

safeCall wraps a request. It waits between requests and retries transient errors, such as rate limits and 5xx responses.

import { safeCall } from "@cyc-seattle/gsuite-sdk";

await safeCall(() => row.save());

safeCall(request, pacing) takes the same pacing as the clients.

Workspace fake

@cyc-seattle/gsuite-sdk/fake stands in for the Directory and Groups Settings APIs. It serves the calls that DirectoryClient and GroupSettingsClient make, from memory.

import { ManualClock, WorkspaceModel, startFakeServer } from "@cyc-seattle/gsuite-sdk/fake";

const clock = new ManualClock();
const fake = await startFakeServer({ model: new WorkspaceModel({ clock }) });
const directory = new DirectoryClient(auth, { rootUrl: fake.rootUrl, pacing: { requestDelayMs: 0, retryDelayMs: 0 } });
// ...
await fake.close();

startFakeServer listens on a free loopback port unless given host and port. The clients still need an auth object, but the fake ignores its token. A GoogleAuth whose authClient is a UserRefreshClient holding any access token needs no ADC. test/features/world.ts builds one.

WorkspaceModel holds the groups, members, and settings. Use it directly in unit tests, or seed it before a test: pass { settled: true } to insertGroup or insertMember to skip the new-group delay. Its options:

OptionDefaultWhat it does
clockthe systemWhere the model reads the time. ManualClock moves on advance(ms).
newGroupDelayMs60000How long a new group refuses member inserts
pageSize200The largest page a list returns

It answers as Google does:

CaseStatusReasonMessage
An unknown group404notFoundResource Not Found: groupKey
An unknown member404notFoundResource Not Found: memberKey
A member insert into a group still too new404notFoundResource Not Found: groupKey
A member who's already in the group409duplicateMember already exists.
A group that already exists409duplicateEntity already exists.
A membership that would make a cycle412conditionNotMetCyclic memberships not allowed
Settings of an unknown group404notFoundNot Found

Google doesn't document the cycle's status or the settings 404's message. The fake follows the JSON API's conventions for them.

Derived membership isn't modeled, because the SDK reads only direct members.

Groups Settings answers in Atom XML unless the request asks for alt=json, like Google.

Container image

Every release publishes ghcr.io/cyc-seattle/workspace-fake:<version> and :latest, built from the Dockerfile. The fake ignores auth tokens, so any bearer token works.

  • It listens on port 8080. PORT changes that.
  • NEW_GROUP_DELAY_MS sets how long a new group refuses member inserts (default 60000). Set it to 0 to seed a group and its members at once.
  • GET /healthz returns 200.
  • It runs as uid 1000 and writes no files, so it works with a read-only root filesystem and all capabilities dropped.
  • Seed it through the Directory API: POST /admin/directory/v1/groups, then POST .../groups/<group>/members.
docker run -p 8080:8080 -e NEW_GROUP_DELAY_MS=0 ghcr.io/cyc-seattle/workspace-fake

Development

mise run test runs the unit tests in test/. mise run integration runs the Gherkin features in features/ against the fake, which starts in the test process. mise run ci runs both, after check. See AGENTS.md.

Release

Every merge to main releases from the PR title, once CI passes. The title must be a conventional commit. fix: makes a patch release, feat: a minor release, and a ! after the type a major release. Types such as docs:, build:, and test: release nothing. semantic-release publishes to npm and creates the GitHub release.

版本与发布记录

@cyc-seattle/gsuite-sdk 共发布 6 个版本,首次发布于 2026/10/13;过去 12 个月发布了 6 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.0.0latest2026/11/0310 天前
0.3.02026/10/1628 天前
0.2.02026/10/131 个月前
0.1.12026/10/131 个月前
0.1.02026/10/131 个月前
0.0.0-stage2026/10/131 个月前

关于 @cyc-seattle/gsuite-sdk 的常见问题

@cyc-seattle/gsuite-sdk 是什么?

Domain-agnostic wrappers around Google Workspace APIs

如何安装 @cyc-seattle/gsuite-sdk?

在项目目录运行 npm install @cyc-seattle/gsuite-sdk,或使用 pnpm add / yarn add / bun add。

@cyc-seattle/gsuite-sdk 支持 TypeScript 吗?

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

@cyc-seattle/gsuite-sdk 支持 ESM 还是 CommonJS?

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

@cyc-seattle/gsuite-sdk 需要什么版本的 Node.js?

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

@cyc-seattle/gsuite-sdk 可以商用吗?

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

@cyc-seattle/gsuite-sdk 的下载量有多少?

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

@cyc-seattle/gsuite-sdk 还在维护吗?

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