HIME-X LabDeveloper Portal

📦 @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 を促す
    }
  }
}

オプション

オプションデフォルト説明
apiKeystringConnect Key
timeoutnumber10000ms
retriesnumber25xx のリトライ回数
baseUrlstring各既定URLカスタム環境向け
headersRecord<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 が型付きで取れる