UNPKG

cb10-sdk

Version:

Cybozu Office 10 SDK for Node.js

86 lines (85 loc) 3.16 kB
import { AxiosRequestConfig } from 'axios'; export type CustomURLParams = Record<string, string | number | boolean | Array<string | number | boolean>>; /** * サイボウズOffice接続の設定オプションを定義するインターフェース * * @interface CybozuOfficeOptions * @property {string} baseUrl - 処理対象となるサイボウズのURL(http~/ag.cgiまで) * @property {string} accountId - ログインID * @property {string} password - パスワード * @property {string} [cookie] - 有効期限内のクッキー情報(未指定の場合は自動で取得) */ export interface CybozuOfficeOptions { baseUrl: string; accountId?: string; id?: string; password: string; sessionCredentials?: SessionCredentials; axiosRequestConfig?: AxiosRequestConfig; } /** * GETリクエストのオプションを定義するインターフェース * * @interface GetOptions * @property {string} [path] - リクエストパス * @property {CustomURLPrams} [query] - URLクエリパラメータ * @property {'text' | 'file'} [responseType] - レスポンスタイプ(デフォルト: 'text') * @property {BufferEncoding} [encoding] - ファイル取得時のエンコーディング(デフォルト: 'utf-8') */ export interface GetOptions { path?: string; query?: CustomURLParams; responseType?: 'text' | 'file'; encoding?: BufferEncoding; } /** * セッション認証情報を定義するインターフェース * * @interface SessionCredentials * @property {string} cookie - セッションクッキー * @property {string} csrfTicket - CSRFトークン */ export interface SessionCredentials { cookie: string; myOwnUID: number; csrfTicket?: string; } /** * Cybozu Office 10 APIへのアクセスを管理するクラス * * このクラスはCybozu Office 10のHTTP APIへのアクセスを簡素化します。 * セッション管理、認証、CSRFトークンの処理を自動的に行います。 * */ export default class Transport { #private; private readonly options; get sessionCredentials(): SessionCredentials | undefined; /** * Transportクラスのインスタンスを作成します * * @param baseUrl - サイボウズのベースURL(http~/ag.cgiまで) * @param accountId - ログインID * @param password - パスワード * @param cookie - 有効な既存のクッキー(オプション) * * @throws {CybozuOfficeSDKException} 認証に失敗した場合 */ constructor(options: CybozuOfficeOptions); /** * GETリクエストを実行します * * @param options - GETリクエストのオプション * @returns 取得したコンテンツ * * @throws {CybozuOfficeSDKException} リクエストが失敗した場合 */ get(options?: GetOptions): Promise<string>; /** * POSTリクエストを実行します * * @param body - POSTリクエストのボディ * @throws {CybozuOfficeSDKException} リクエストが失敗した場合 */ post(body: CustomURLParams): Promise<void>; }