📦 @hime/sdk
HIME 公式 SDK — 型安全な API クライアント
導入
npm install @hime/sdk # or yarn add @hime/sdk # or pnpm add @hime/sdk基本の使い方
import { HimeClient } from "@hime/sdk";
const hime = new HimeClient({ apiKey: "ck:your_key" });
// セッション検証
const session = await hime.account.verifySession();
if (!session.authenticated) throw new Error("Login required");
// CC 決済 (冪等性キー自動生成)
const tx = await hime.account.ccPay({
amount: 1000,
recipient: "user_xyz",
reference: "order_abc",
});
console.log("TX:", tx.transaction_id);
// メール送信
await hime.mail.send({
to: ["customer@example.com"],
subject: "ご注文確認",
text: "ありがとうございました",
origin_service: "my-app",
});
// 周辺店舗
const { stores } = await hime.navigate.nearbyStores({
lat: 41.7688, lng: 140.7290, radius_m: 1000,
});エラー処理
import { HimeClient, HimeApiError } from "@hime/sdk";
try {
await hime.account.ccPay({ /* ... */ });
} catch (err) {
if (err instanceof HimeApiError) {
console.error(`${err.status}:`, err.body);
if (err.status === 402) {
// 残高不足 — ユーザーに charge を促す
}
}
}オプション
| オプション | 型 | デフォルト | 説明 |
|---|---|---|---|
apiKey | string | — | Connect Key |
timeout | number | 10000 | ms |
retries | number | 2 | 5xx のリトライ回数 |
baseUrl | string | 各既定URL | カスタム環境向け |
headers | Record<string,string> | — | 追加ヘッダー |
サポートクライアント
hime.account— セッション / 残高 / CC決済 / CCチャージ / 名前解決hime.mail— 送信 / 一覧hime.market— チェックアウト / 商品・ストア一覧hime.broadcasting— 投げ銭 / ランキング / 配信一覧hime.navigate— 周辺店舗 / 経路探索
特長
- ✅ 外部依存ゼロ — fetch のみで動作 (Node / Workers / Browser 共通)
- ✅ 自動リトライ — 5xx / タイムアウトに指数バックオフ
- ✅ 冪等性キー自動生成 — POST/PUT/DELETE は自動で Idempotency-Key 付与
- ✅ 型安全 — 全エンドポイントの入出力が TypeScript 型で定義
- ✅ HimeApiError — status + body が型付きで取れる