# hacocms-js-sdk

> hacoCMS SDK for JavaScript/TypeScript

Latest version **1.6.3** (published 2024-03-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install hacocms-js-sdk
pnpm add hacocms-js-sdk
yarn add hacocms-js-sdk
bun add hacocms-js-sdk
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.6.3 |
| Published | 2024-03-26 |
| First published | 2022-08-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 40.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | FAN Communications, Inc. |
| Maintainers | j-hayashi_seesaa |

## Links

- npm: https://www.npmjs.com/package/hacocms-js-sdk
- Repository: https://github.com/hacocms/hacocms-js-sdk
- Homepage: https://github.com/hacocms/hacocms-js-sdk#readme
- Issues: https://github.com/hacocms/hacocms-js-sdk/issues
- npm.io page: https://npm.io/package/hacocms-js-sdk

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^1.6.7

## Recent versions

- 1.6.3 (latest) — 2024-03-26
- 1.2.0-6 (beta) — 2022-10-31
- 1.6.2 — 2024-03-01
- 1.6.1 — 2024-01-30
- 1.6.0 — 2023-11-20
- 1.5.0 — 2023-10-06
- 1.4.0 — 2023-04-27
- 1.3.1 — 2022-11-30
- 1.3.0 — 2022-11-30
- 1.2.1 — 2022-11-29
- 1.2.0 — 2022-10-31
- 1.2.0-5 — 2022-10-28
- 1.2.0-4 — 2022-10-28
- 1.2.0-3 — 2022-10-28
- 1.2.0-2 — 2022-10-27
- … 7 more at https://npm.io/package/hacocms-js-sdk/versions

## README

# hacoCMS JavaScript/TypeScript SDK

[![build, test, lint](https://github.com/hacocms/hacocms-js-sdk/actions/workflows/test.yml/badge.svg)](https://github.com/hacocms/hacocms-js-sdk/actions/workflows/test.yml)
[![npm version](https://badge.fury.io/js/hacocms-js-sdk.svg)](https://badge.fury.io/js/hacocms-js-sdk)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

[hacoCMS](https://hacocms.com/) の JavaScript/TypeScript 用 API クライアントライブラリです。

## インストール

```sh
npm install hacocms-js-sdk

# or

yarn add hacocms-js-sdk
```

## 使い方

```js
import {
  HacoCmsClient, // API クライアント
  ApiContent, // API スキーマの基底クラス
  SortQuery, // ソートクエリビルダ
} from 'hacocms-js-sdk'

const client = new HacoCmsClient(
  'https://{プロジェクトのサブドメイン}.hacocms.com', // API のベース URL
  'ACCESS_TOKEN', // プロジェクトの Access-Token
  'PROJECT_DRAFT_TOKEN', // オプション：プロジェクトの Project-Draft-Token
)

// API スキーマの定義（例）
class ExampleContent extends ApiContent {
  // API レスポンスの JSON からコンテンツオブジェクトを生成するコンストラクタ
  constructor(json) {
    super(json) // API 共通のフィールド（id, createdAt など）が初期化されます。

    this.title = json.title
    this.body = json.body
  }
}

// コンテンツ一覧を取得
const res = await client.getList(ExampleContent, '/example', {
  s: SortQuery.build(['createdAt', 'desc']), // 作成日時の降順
})
for (const content of res.data) {
  console.log(content.title)
}

// 特定のコンテンツを取得
const contentId = 'CONTENT_ID' // コンテンツ ID
const content = await client.getContent(ExampleContent, '/example', contentId)
console.log(content.title)

// シングル形式の API コンテンツを取得
const single = await client.getSingle(ExampleContent, '/single')
console.log(single.title)

// 下書きを含めたコンテンツ一覧を取得
// ※ HacoCmsClient のコンストラクタに Project-Draft-Token を渡しておく必要があります。
const all = await client.getListIncludingDraft(ExampleContent, '/example', {
  s: SortQuery.build('-updatedAt'), // 更新日時の降順
})
for (const content of all.data) {
  console.log(content.title)
}

// 下書きのコンテンツを取得
const draftToken = 'DRAFT_TOKEN' // 取得するコンテンツの Draft-Token
const draft = await client.getContent(ExampleContent, '/example', contentId, draftToken)
console.log(draft.title)
```

## ライセンス

MIT License

---
_Source: https://npm.io/package/hacocms-js-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
