npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

cb10-sdk

v0.4.0

Published

Cybozu Office 10 SDK for Node.js

Readme

cb10-sdk

npm version testings codecov

cb10-sdk とは、 Node.js にてパッケージ版の サイボウス Office 10 へのメッセージ投稿や宛先更新、個人フォルダへの仕分け作業ができるツールです。
cb10-sdk を使うことで、普段のサイボウズ上での作業を自動化することに役立てることができます。

ご利用の前に

以前は サイボウズ Office 10 向けに SOAP API が提供されていましたが、2018年9⽉28⽇をもって新規での利用ができないようにされているため、cb10-sdk では HTML のスクレイピングにてデータ取得などを実現しています。

「サイボウズ Office」連携APIドキュメント配布終了のお知らせ (2018/09/19)

ちなみに API での連携に興味がある場合は、 Garoonkintone を検討してみてもいいと思います。

特徴

一般的な Web スクレイピング手法と比べた cb10-sdk の主な利点は以下の通りです。

  1. 充実した機能
  1. 軽量な実装
  • 静的ファイルのダウンロードを最小限に抑制
  • ブラウザ起動不要で高速な実行と低リソース消費
  • 最適化された通信制御による低負荷な動作
  1. モダンな開発環境
  • マルチプラットフォーム対応(Windows, macOS, Linux, AWS Lambda等)
  • TypeScriptによる優れた開発体験
  • npmによる簡単な導入とバージョン管理

導入方法について

1. 事前準備

cb10-sdk を使うには Node.js 20 以上が必要です。 Node.js をはじめて使う場合はインストールする必要があります。

2. cb10-sdk をインストールする

package.json があるディレクトリで、以下のコマンドを実行します。

npm install cb10-sdk

3. cb10-sdk をアップデートする

アップデートする場合は以下のコマンドを実行します。

npm install cb10-sdk@latest

使用方法について

実装例はこちらです。

import CybozuOffice from 'cb10-sdk';

const client = new CybozuOffice({
  baseUrl: 'https://onlinedemo.cybozu.info/scripts/office10/ag.cgi',
  id: '17',
  password: '',
});

// グループ ID が 13(総務部)のユーザ一覧を取得
const groupMembers = await client.user.getMembers({ groupId: 13 });
groupMembers.forEach(it => JSON.stringify(it));
// { uID: 17, userName: '高橋 健太' }
// { uID: 27, userName: '加藤 美咲' }
// { uID: 208, userName: '大山 春香' }

具体的な使い方については samples 配下のコードをご参考ください。

ログイン方法について

サイボウズへのログインする際に、ユーザをプルダウンではなくフォーム入力となっている場合、以下のような実装になります。

const client = new CybozuOffice({
  baseUrl: 'https://your-cybozu-office-site/xxxx/xxxx/ag.cgi',
  accountId: 'hoge',
  password: 'hogehoge',
});

HTTP 通信時の振る舞いを変更をしたい

cb10-sdk では HTTP 通信をする際に axios を使用しており、 CybozuOffice のコンストラクタにて、 Request Config のオブジェクトを渡すことで、HTTP 通信時における細かい振る舞いを変更することができます。
以下、使用例です。

import https from 'https';
import { AxiosRequestConfig } from 'axios';
import CybozuOffice from 'cb10-sdk';

const axiosRequestConfig: AxiosRequestConfig = {
  // 通信時のタイムアウトの時間を 1 秒(1,000 ミリ秒)に変更する
  timeout: 3000,

  // SSL 認証を無効化したい
  httpsAgent: new https.Agent({
    rejectUnauthorized: false,
  }),

  // BASIS 認証を使用する
  auth: {
    username: 'janedoe',
    password: 's00pers3cret',
  },

  // PROXY を使用する
  proxy: {
    protocol: 'https',
    host: '127.0.0.1',
    port: 9000,
    auth: {
      username: 'mikeymike',
      password: 'rapunz3l',
    },
  },
}

const client = new CybozuOffice({
  baseUrl: 'https://192.168.0.1/xxxx/xxxx/ag.cgi',
  accountId: 'hoge',
  password: 'hogehoge',
  axiosRequestConfig
});

設定可能な項目については axios - リクエスト設定 をご参照ください。
また、すべての項目を適用する実装にしていますが、項目によっては cb10-sdk が意図しない挙動になる可能性があるため、ご注意ください。

前回ログインした際のセッション情報を使い回ししたい

サイボウズ Office 10 のセッションはデフォルト設定の場合、前回のアクセスから 24 時間以内であれば有効になります。
そのため、5 分おきなどにサイボウズから情報を取得するスクリプトを各場合、毎回ログインするのは無駄になるので、以下の方法でセッションを使い回しすることができます。

// 使用していたセッション情報を取得する
const session = previousClient.transport.sessionCredentials;

// 前回使用していたセッション情報を再利用する
const currentClient = new CybozuOffice({
  baseUrl: 'https://your-cybozu-office-site/xxxx/xxxx/ag.cgi',
  accountId: 'hoge',
  password: 'hogehoge',
  sessionCredentials: session,
});

// 前回のセッションが有効期限内であれば、ログインに関する HTTP リクエストは発生しません
currentClient.user.getMembers({ groupId: 13 });

また、もしセッションが有効期限切れしていた場合、 SDK 内部で再ログインしてリトライするため、特にユーザ側でセッションが有効期限内かどうかを判定する処理を省略いただいても問題ございません。

未対応のページの情報を取得したり、フォームの送信を行いたい

CybozuOfficetransport にて実装できます。
transport を使うことで、サイボウズ Office 10 への Cookie の取得や、csrf_ticket を Body に入れるといった共通処理をユーザ側で実装する手間がなくなり、HTML のパースやフォームの送信の実装に集中いただけます。

transport.get で未対応のページの情報を取得する

ページの情報取得の場合、 URL のリクエストパラメータ部分の情報を query にオブジェクトとして渡すことでページの HTML が取得できます。

その後、 Cheerio でパースしてもらえれば、該当の文字列を取得することができます。

import * as cheerio from 'cheerio';

const html = await client.transport.get({
  query: {
    page: 'MyFolderMemoView',
    mEID: 42,
  },
});

const $ = cheerio.load(html);

// メモのタイトルを取得
const title = $('.vr_viewTitleAreaSubject').text();
// メモの本文を取得
const content = $('.vr_mainColumn').text();

transport.post でフォームの送信を行う

ブラウザの開発者ツールにて、「Network」→「Fetch/XHR or Doc」→「Payload」にてフォームの送信内容が確認できるので、そちらを参考に body に指定するオブジェクトを実装することでフォームの送信ができます。

import * as cheerio from 'cheerio';

// 例外がおきなければ送信成功です。
await client.transport.post({
  body: {
    Page: 'MyFolderMemoModify',
    FID: 23,
    EID: 42,
    Subject: '変更後のメモのタイトル',
    EditMode: 0,
    Data: `変更後のメモの本文を送信。
複数行でも可能です。`,
    Submit: '変更する',
    AjaxRequest: 'AjaxRequest',
  },
});