メインコンテンツまでスキップ
バージョン: 0.5.0 (最新)

💬 チャットサービス

Testing Status

チャットサービスは、チャンネル、サブスクリプション、メッセージング機能を含むリアルタイム通信のための包括的なソリューションを提供します。チャンネル管理とサブスクリプション管理を単一の一貫したAPIに統合しています。


🚀 クイックスタート

import express from 'express';
import { middlewares, services, drivers } from '@nodeblocks/backend-sdk';

const { nodeBlocksErrorMiddleware } = middlewares;
const { chatService } = services;
const { getMongoClient } = drivers;

const client = getMongoClient('mongodb://localhost:27017', 'dev');

express()
.use(
chatService(
{
identities: client.collection('identities'),
chatChannels: client.collection('chatChannels'),
chatMessages: client.collection('chatMessages'),
subscriptions: client.collection('subscriptions'),
},
{
authSecrets: {
authEncSecret: 'your-encryption-secret',
authSignSecret: 'your-signing-secret',
},
identity: {
typeIds: {
admin: '100',
guest: '000',
regular: '001',
},
},
}
)
)
.use(nodeBlocksErrorMiddleware())
.listen(8089, () => console.log('Server running'));

📋 エンドポイント概要

チャンネル操作

メソッドパス説明
POST/channels新しいチャンネルを作成
GET/channelsすべてのチャンネルを一覧取得
GET/channels/:channelId特定のチャンネルを取得
PATCH/channels/:channelIdチャンネルを更新
DELETE/channels/:channelIdチャンネルを削除

サブスクリプション操作

メソッドパス説明
POST/subscriptions新しいサブスクリプションを作成
GET/subscriptionsすべてのサブスクリプションを一覧取得
GET/subscriptions/:subscriptionId特定のサブスクリプションを取得
DELETE/subscriptions/:subscriptionIdサブスクリプションを削除

メッセージ操作

メソッドパス説明
POST/messages新しいメッセージを作成
GET/messages?channelId=:channelIdチャンネル内のメッセージを一覧取得
GET/messages/:messageId特定のメッセージを取得
PATCH/messages/:messageIdメッセージを更新
DELETE/messages/:messageIdメッセージを削除

🗄️ エンティティスキーマ

チャンネルエンティティ

{
"name": "string",
"ownerId": "string",
"createdAt": "string (datetime)",
"id": "string",
"updatedAt": "string (datetime)"
}

フィールド詳細:

フィールド自動生成必須説明
namestringチャンネル名/タイトル
ownerIdstringこのチャンネルの所有者となるアイデンティティのID
createdAtdatetime作成日時
idstring一意識別子(UUID)
updatedAtdatetime最終更新日時

サブスクリプションエンティティ

{
"approved": "boolean",
"channelId": "string",
"permissions": ["string"],
"subscribedAt": "string (datetime)",
"subscribedId": "string",
"createdAt": "string (datetime)",
"id": "string",
"updatedAt": "string (datetime)"
}

フィールド詳細:

フィールド自動生成必須説明
approvedbooleanサブスクリプションが承認済みかどうか
channelIdstring対象チャンネルのID
permissionsarray権限文字列の配列(例: ["read", "write"])
subscribedAtdatetimeサブスクリプション作成日時
subscribedIdstring購読するアイデンティティのID
createdAtdatetime作成日時
idstring一意識別子(UUID)
updatedAtdatetime最終更新日時

メッセージエンティティ

{
"channelId": "string",
"content": "string",
"senderId": "string",
"title": "string",
"createdAt": "string (datetime)",
"id": "string",
"updatedAt": "string (datetime)"
}

フィールド詳細:

フィールド自動生成必須説明
channelIdstringメッセージが送信されるチャンネルのID
contentstringメッセージ本文
senderIdstringメッセージ送信者のアイデンティティID
titlestring任意のメッセージタイトル
createdAtdatetime作成日時
idstring一意識別子(UUID)
updatedAtdatetime最終更新日時

📝 注意: 自動生成フィールドはサービス側で設定され、作成/更新リクエストに含めないでください。スキーマは additionalProperties: false を強制し、定義されたフィールドのみを許可します。


🔐 認証ヘッダー

保護されたエンドポイントでは、次のヘッダーを含めてください:

Authorization: Bearer <access_token>
x-nb-fingerprint: <device_fingerprint>

⚠️ 重要: 認可時にフィンガープリントを指定した場合、認証済みのすべてのリクエストで x-nb-fingerprint ヘッダーが必須です。欠如している場合は 401 Unauthorized が返ります。


🔧 APIエンドポイント

📺 チャンネル操作

1. チャンネル作成

指定された情報で新しいチャットチャンネルを作成します。

リクエスト:

  • Method: POST
  • Path: /channels
  • ヘッダー:
    • Content-Type: application/json
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラートークン必須

バリデーション:

  • スキーマ検証: 自動適用(name と ownerId が必須、追加プロパティなし)
  • ルートバリデーション:
    • 認証済みリクエスト(ベアラー)必須
    • 管理者ロールまたは本人(ownerId が認証ユーザーと一致)

リクエストボディ:

フィールド必須説明
namestringチャンネル名/タイトル
ownerIdstringこのチャンネルを所有するユーザーのID

レスポンスボディ:

フィールド説明
namestringチャンネル名/タイトル
ownerIdstringこのチャンネルを所有するユーザーのID
createdAtstring作成日時
idstringチャンネル一意ID
updatedAtstring最終更新日時

リクエスト例:

curl -X POST http://localhost:8089/channels \
-H "Content-Type: application/json" \
-d '{
"name": "Project Updates",
"ownerId": "user-456"
}'

成功レスポンス:

HTTP/1.1 201 Created
Content-Type: application/json

{
"name": "Project Updates",
"ownerId": "user-456",
"createdAt": "2025-06-24T08:33:40.146Z",
"id": "af62eac3-06aa-481a-8c44-a029e96de2ed",
"updatedAt": "2025-06-24T08:33:40.146Z"
}

バリデーションエラー例:

必須フィールド不足:

{
"error": {
"message": "must have ownerId when creating a new channel"
}
}

スキーマ検証エラー:

{
"error": {
"message": "Validation Error",
"data": [
"request body must have required property 'ownerId'"
]
}
}

追加プロパティエラー:

{
"error": {
"message": "Validation Error",
"data": [
"request body must NOT have additional properties"
]
}
}
{
"error": {
"message": "Validation Error",
"data": [
"request body must NOT have additional properties",
"request body must NOT have additional properties"
]
}
}

2. チャンネル一覧

フィルタやページングを指定して全チャンネルを取得します。

リクエスト:

  • Method: GET
  • Path: /channels
  • ヘッダー:
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラートークン必須

バリデーション:

  • スキーマ検証: name, ownerId とページング(page, limit)のクエリ検証
  • ルートバリデーション:
    • 認証済みリクエスト(ベアラー)必須
    • 管理者ロール、または本人(自分のチャンネルを取得する場合)

クエリパラメータ:

パラメータ必須説明
namestringチャンネル名でフィルタ
ownerIdstring所有者IDでフィルタ
pagenumberページ番号
limitnumber1ページあたりの件数

レスポンスボディ:

フィールド説明
namestringチャンネル名/タイトル
ownerIdstringこのチャンネルを所有するユーザーのID
createdAtstring作成日時
idstringチャンネル一意ID
updatedAtstring最終更新日時

リクエスト例:

curl http://localhost:8089/channels

成功レスポンス:

HTTP/1.1 200 OK
Content-Type: application/json

[
{
"name": "Project Updates",
"ownerId": "user-456",
"createdAt": "2025-06-24T08:33:40.146Z",
"id": "af62eac3-06aa-481a-8c44-a029e96de2ed",
"updatedAt": "2025-06-24T08:33:40.146Z"
}
]

3. チャンネル取得

ID で特定のチャンネルを取得します。

リクエスト:

  • Method: GET
  • Path: /channels/:channelId
  • ヘッダー:
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラートークン必須

バリデーション:

  • スキーマ検証: チャンネルIDのパスパラメータ検証
  • ルートバリデーション:
    • 認証済みリクエスト(ベアラー)必須
    • 管理者ロール、チャンネル所有者、または当該チャンネルの有効なサブスクリプション

リクエスト例:

curl http://localhost:8089/channels/af62eac3-06aa-481a-8c44-a029e96de2ed

4. チャンネル更新

既存のチャンネルのプロパティを更新します。

リクエスト:

  • Method: PATCH
  • Path: /channels/:channelId
  • ヘッダー:
    • Content-Type: application/json
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラートークン必須

バリデーション:

  • スキーマ検証: 部分更新スキーマ(全フィールド任意、追加プロパティなし)
  • ルートバリデーション:
    • 認証済みリクエスト(ベアラー)必須
    • 管理者ロールまたはチャンネル所有者

リクエストボディ:

フィールド必須説明
namestring新しいチャンネル名/タイトル
ownerIdstring新しい所有者ID

レスポンスボディ:

フィールド説明
namestring更新後のチャンネル名/タイトル
ownerIdstring更新後の所有者ID
createdAtstring作成日時
idstringチャンネル一意ID
updatedAtstring最終更新日時

リクエスト例:

curl -X PATCH http://localhost:8089/channels/af62eac3-06aa-481a-8c44-a029e96de2ed \
-H "Content-Type: application/json" \
-d '{
"name": "Updated Project Updates"
}'

5. チャンネル削除

チャンネルと関連データを削除します。

リクエスト:

  • Method: DELETE
  • Path: /channels/:channelId
  • ヘッダー:
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラートークン必須

バリデーション:

  • スキーマ検証: チャンネルIDのパスパラメータ検証
  • ルートバリデーション:
    • 認証済みリクエスト(ベアラー)必須
    • 管理者ロールまたはチャンネル所有者

レスポンスボディ:

フィールド説明
なし-成功時はレスポンスボディなし

リクエスト例:

curl -X DELETE http://localhost:8089/channels/af62eac3-06aa-481a-8c44-a029e96de2ed

成功レスポンス:

  • ステータス: 204 No Content
  • ボディ: (空)

Not Found エラー例:

{
"error": {
"message": "Channel not found"
}
}

📋 サブスクリプション操作

6. サブスクリプション作成

チャンネルへの新規サブスクリプションを作成します。

リクエスト:

  • Method: POST
  • Path: /subscriptions
  • ヘッダー:
    • Content-Type: application/json
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラートークン必須

バリデーション:

  • スキーマ検証: 自動適用(channelId と subscribedId が必須、追加プロパティなし)
  • ルートバリデーション:
    • 認証済みリクエスト(ベアラー)必須
    • 管理者ロールまたは本人(購読者が認証ユーザー)

リクエストボディ:

フィールド必須説明
channelIdstring購読対象のチャンネルID
approvedbooleanサブスクリプションが承認済みか
permissionsarray権限文字列の配列
subscribedAtstringサブスクリプション作成日時
subscribedIdstring購読ユーザーのID

レスポンスボディ:

フィールド説明
channelIdstring購読対象のチャンネルID
subscribedIdstring購読ユーザーのID
approvedbooleanサブスクリプションが承認済みか
permissionsarray権限文字列の配列
subscribedAtstringサブスクリプション作成日時
createdAtstring作成日時
idstringサブスクリプション一意ID
updatedAtstring最終更新日時

リクエスト例:

curl -X POST http://localhost:8089/subscriptions \
-H "Content-Type: application/json" \
-d '{
"channelId": "af62eac3-06aa-481a-8c44-a029e96de2ed",
"subscribedId": "user-456",
"approved": true,
"permissions": ["read", "write"]
}'

成功レスポンス:

HTTP/1.1 201 Created
Content-Type: application/json

{
"channelId": "af62eac3-06aa-481a-8c44-a029e96de2ed",
"subscribedId": "user-456",
"approved": true,
"permissions": ["read", "write"],
"createdAt": "2025-06-27T02:16:07.916Z",
"id": "b17501d6-2576-4a18-86f5-3545da75e678",
"updatedAt": "2025-06-27T02:16:07.916Z"
}

バリデーションエラー例:

{
"error": {
"message": "Validation Error",
"data": [
"request body must have required property 'channelId'",
"request body must have required property 'subscribedId'",
]
}
}
{
"error": {
"message": "Validation Error",
"data": [
"request body must NOT have additional properties",
]
}
}

7. サブスクリプション一覧

フィルタやページングを指定してサブスクリプションを取得します。

リクエスト:

  • Method: GET
  • Path: /subscriptions
  • ヘッダー:
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラートークン必須

バリデーション:

  • スキーマ検証: approved, channelId, subscribedAt, subscribedId とページング(page, limit)のクエリ検証
  • ルートバリデーション:
    • 認証済みリクエスト(ベアラー)必須
    • 管理者、当該チャンネルの有効なサブスクリプション、チャンネル所有者、または本人(購読者)

クエリパラメータ:

パラメータ必須説明
approvedboolean承認状態でフィルタ
channelIdstringチャンネルIDでフィルタ
subscribedIdstring購読者IDでフィルタ
subscribedAtstring購読日時でフィルタ
pagenumberページ番号
limitnumber1ページあたりの件数

レスポンスボディ:

フィールド説明
channelIdstring購読対象のチャンネルID
subscribedIdstring購読ユーザーのID
approvedbooleanサブスクリプションが承認済みか
permissionsarray権限文字列の配列
subscribedAtstringサブスクリプション作成日時
createdAtstring作成日時
idstringサブスクリプション一意ID
updatedAtstring最終更新日時

リクエスト例:

curl http://localhost:8089/subscriptions

8. サブスクリプション取得

ID で特定のサブスクリプションを取得します。

リクエスト:

  • Method: GET
  • Path: /subscriptions/:subscriptionId
  • ヘッダー:
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラートークン必須

バリデーション:

  • スキーマ検証: サブスクリプションIDのパスパラメータ検証
  • ルートバリデーション:
    • 認証済みリクエスト(ベアラー)必須
    • 管理者ロールまたはサブスクリプション所有者

リクエスト例:

curl http://localhost:8089/subscriptions/b17501d6-2576-4a18-86f5-3545da75e678

9. サブスクリプション削除

サブスクリプションを削除(チャンネルの購読解除)します。

リクエスト:

  • Method: DELETE
  • Path: /subscriptions/:subscriptionId
  • ヘッダー:
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラートークン必須

バリデーション:

  • スキーマ検証: サブスクリプションIDのパスパラメータ検証
  • ルートバリデーション:
    • 認証済みリクエスト(ベアラー)必須
    • 管理者ロールまたはサブスクリプション所有者

レスポンスボディ:

フィールド説明
なし-成功時はレスポンスボディなし

リクエスト例:

curl -X DELETE http://localhost:8089/subscriptions/b17501d6-2576-4a18-86f5-3545da75e678

成功レスポンス:

  • ステータス: 204 No Content
  • ボディ: (空)

Not Found エラー例:

{
"error": {
"message": "Subscription not found"
}
}

💬 メッセージ操作

10. メッセージ作成

チャンネルに新しいメッセージを送信します。

リクエスト:

  • Method: POST
  • Path: /messages
  • ヘッダー:
    • Content-Type: application/json
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラートークン必須

バリデーション:

  • スキーマ検証: 自動適用(content, senderId, channelId が必須、追加プロパティなし)
  • ルートバリデーション:
    • 認証済みリクエスト(ベアラー)必須
    • 送信者本人であること
    • 当該チャンネルの有効なサブスクリプションがあること

リクエストボディ:

フィールド必須説明
channelIdstringメッセージが送信されるチャンネルのID
contentstringメッセージ本文
senderIdstringメッセージ送信者のユーザーID
titlestring任意のメッセージタイトル

レスポンスボディ:

フィールド説明
channelIdstringメッセージが送信されるチャンネルのID
contentstringメッセージ本文
senderIdstringメッセージ送信者のユーザーID
titlestring任意のメッセージタイトル
createdAtstring作成日時
idstringメッセージ一意ID
updatedAtstring最終更新日時

リクエスト例:

curl -X POST http://localhost:8089/messages \
-H "Content-Type: application/json" \
-d '{"channelId": "test-channel-123", "content": "Hello world!", "senderId": "user-456"}'

成功レスポンス:

{
"channelId": "test-channel-123",
"content": "Hello world!",
"senderId": "user-456",
"createdAt": "2025-07-01T03:22:06.178Z",
"id": "2b43d66c-9cab-434b-9cb7-18de8d3ec9c9",
"updatedAt": "2025-07-01T03:22:06.178Z"
}

バリデーションエラー例:

{
"error": {
"message": "Validation Error",
"data": [
"request body must have required property 'senderId'",
"request body must have required property 'channelId'"
]
}
}

11. メッセージ一覧

特定のチャンネルのメッセージを取得します。

リクエスト:

  • Method: GET
  • Path: /messages?channelId=:channelId
  • ヘッダー:
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラートークン必須

バリデーション:

  • スキーマ検証: channelId(必須)、任意の content, senderId, title、およびページング(page, limit)のクエリ検証
  • ルートバリデーション:
    • 認証済みリクエスト(ベアラー)必須
    • 管理者、当該チャンネルの有効なサブスクリプション、または送信者本人

クエリパラメータ:

パラメータ必須説明
channelIdstring取得対象のチャンネルID
contentstringメッセージ本文でフィルタ
senderIdstring送信者IDでフィルタ
titlestringメッセージタイトルでフィルタ
pagenumberページ番号
limitnumber1ページあたりの件数

レスポンスボディ:

フィールド説明
channelIdstringメッセージが送信されるチャンネルのID
contentstringメッセージ本文
senderIdstringメッセージ送信者のユーザーID
titlestring任意のメッセージタイトル
createdAtstring作成日時
idstringメッセージ一意ID
updatedAtstring最終更新日時

リクエスト例:

curl "http://localhost:8089/messages?channelId=test-channel-123"

成功レスポンス:

[
{
"channelId": "test-channel-123",
"content": "Updated message content",
"senderId": "user-456",
"createdAt": "2025-07-01T03:22:06.178Z",
"id": "2b43d66c-9cab-434b-9cb7-18de8d3ec9c9",
"updatedAt": "2025-07-01T03:22:34.413Z"
}
]

バリデーションエラー例:

{
"error": {
"message": "Validation Error",
"data": [
"query parameter 'channelId' is required"
]
}
}

12. メッセージ取得(ID指定)

ID で特定のメッセージを取得します。

リクエスト:

  • Method: GET
  • Path: /messages/:messageId
  • ヘッダー:
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラートークン必須

バリデーション:

  • スキーマ検証: メッセージIDのパスパラメータ検証
  • ルートバリデーション:
    • 認証済みリクエスト(ベアラー)必須
    • 管理者ロールまたはメッセージ所有者

リクエスト例:

curl http://localhost:8089/messages/2b43d66c-9cab-434b-9cb7-18de8d3ec9c9

成功レスポンス:

{
"channelId": "test-channel-123",
"content": "Updated message content",
"senderId": "user-456",
"createdAt": "2025-07-01T03:22:06.178Z",
"id": "2b43d66c-9cab-434b-9cb7-18de8d3ec9c9",
"updatedAt": "2025-07-01T03:22:34.413Z"
}

Not Found エラー例:

{
"error": {
"message": "Message not found"
}
}

13. メッセージ更新

既存のメッセージ内容を更新します。

リクエスト:

  • Method: PATCH
  • Path: /messages/:messageId
  • ヘッダー:
    • Content-Type: application/json
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラートークン必須

バリデーション:

  • スキーマ検証: 部分更新スキーマ(全フィールド任意、メッセージIDのパス検証、追加プロパティなし)
  • ルートバリデーション:
    • 認証済みリクエスト(ベアラー)必須
    • 管理者ロールまたはメッセージ所有者

リクエストボディ:

フィールド必須説明
contentstring更新後のメッセージ本文
titlestring更新後のメッセージタイトル

レスポンスボディ:

フィールド説明
channelIdstringメッセージが送信されるチャンネルのID
contentstring更新後のメッセージ本文
senderIdstringメッセージ送信者のユーザーID
titlestring更新後のメッセージタイトル
createdAtstring作成日時
idstringメッセージ一意ID
updatedAtstring最終更新日時

リクエスト例:

curl -X PATCH http://localhost:8089/messages/2b43d66c-9cab-434b-9cb7-18de8d3ec9c9 \
-H "Content-Type: application/json" \
-d '{"content": "Updated message content"}'

成功レスポンス:

{
"channelId": "test-channel-123",
"content": "Updated message content",
"senderId": "user-456",
"createdAt": "2025-07-01T03:22:06.178Z",
"id": "2b43d66c-9cab-434b-9cb7-18de8d3ec9c9",
"updatedAt": "2025-07-01T03:22:34.413Z"
}

Not Found エラー例:

{
"error": {
"message": "Chat message not found"
}
}

14. メッセージ削除

チャンネルからメッセージを削除します。

リクエスト:

  • Method: DELETE
  • Path: /messages/:messageId
  • ヘッダー:
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラートークン必須

バリデーション:

  • スキーマ検証: メッセージIDのパスパラメータ検証
  • ルートバリデーション:
    • 認証済みリクエスト(ベアラー)必須
    • 管理者ロールまたはメッセージ所有者

レスポンスボディ:

フィールド説明
なし-成功時はレスポンスボディなし

リクエスト例:

curl -X DELETE http://localhost:8089/messages/81950444-5223-47c8-8a8c-0604c2955f15

成功レスポンス:

  • ステータス: 204 No Content
  • ボディ: (空)

Not Found Error Example:

{
"error": {
"message": "Chat message not found"
}
}

⚙️ 設定オプション

サービス設定

interface ChatServiceConfiguration {
authSecrets: {
authEncSecret: string; // JWT encryption secret
authSignSecret: string; // JWT signing secret
};
identity?: {
typeIds?: {
admin: string; // Admin user type identifier
guest: string; // Guest user type identifier
regular: string; // Regular user type identifier
};
};
}

設定詳細

チャットサービスの設定は、セキュリティとユーザー種別管理の論理グループに整理されています。

🔐 セキュリティ設定

authSecrets - JWT トークンのセキュリティシークレット

  • : { authEncSecret: string; authSignSecret: string }
  • 説明: JWT の暗号化および署名に使用する秘密鍵(トークン検証に使用)
  • 必須: 本番環境では必須
  • 子プロパティ:
    • authEncSecret: JWT ペイロード暗号化の秘密鍵
    • authSignSecret: JWT 署名検証の秘密鍵

👥 ユーザー種別設定

user.typeIds - ユーザー種別識別子の設定

  • : { admin?: string; guest?: string; user?: string }
  • 説明: ロールベースアクセス制御のためのカスタムユーザー種別識別子
  • デフォルト: undefined(デフォルトの種別検証を使用)
  • 子プロパティ:
    • admin: 管理者ユーザー種別の識別子
      • : string
      • 説明: 管理者ユーザーのカスタム識別子
      • 利用例: 管理操作のロールベースアクセス制御
      • : "admin", "administrator", "superuser"
    • guest: ゲストユーザー種別の識別子
      • : string
      • 説明: ゲストユーザーのカスタム識別子
      • 利用例: 未認証/一時ユーザーの限定的アクセス
      • : "guest", "visitor", "anonymous"
    • user: 一般ユーザー種別の識別子
      • : string
      • 説明: 一般ユーザーのカスタム識別子
      • 利用例: 標準的なユーザー権限
      • : "user", "member", "customer"

設定例

const chatConfig = {
authSecrets: {
authEncSecret: process.env.AUTH_ENC_SECRET || 'your-enc-secret',
authSignSecret: process.env.AUTH_SIGN_SECRET || 'your-sign-secret'
},
user: {
typeIds: {
admin: 'administrator',
guest: 'visitor',
user: 'member'
}
}
};

🚨 エラーハンドリング

チャットサービスのエラーは、適切なHTTPステータスコードとJSON形式で返されます。

代表的なエラーコード

ステータスエラーメッセージ説明
400Validation Errorリクエストボディの形式不正または必須項目不足
400must have ownerId when creating a new channelリクエストボディに ownerId が存在しない
400request body must have required property 'name'リクエストボディに name が存在しない
400request body must have required property 'ownerId'リクエストボディに ownerId が存在しない
400request body must have required property 'channelId'リクエストボディに channelId が存在しない
400request body must have required property 'subscribedId'リクエストボディに subscribedId が存在しない
400request body must have required property 'content'リクエストボディに content が存在しない
400request body must have required property 'senderId'リクエストボディに senderId が存在しない
400request body must NOT have additional propertiesサポートされないフィールドが含まれている
400query parameter 'channelId' is required必須のクエリパラメータが不足
400Failed to create channel追加IDが返らず作成に失敗
400Failed to update channel変更が検出されず更新に失敗
400Failed to delete channel削除処理に失敗
400Failed to create subscription追加IDが返らず作成に失敗
400Failed to delete subscription削除処理に失敗
400Failed to create message追加IDが返らず作成に失敗
400Failed to update message変更が検出されず更新に失敗
400Failed to delete message削除処理に失敗
401token could not be verified認可トークンがない/無効
401Authentication failed認証トークンがない/無効
401Token fails security checkトークンのセキュリティ検証に失敗
403User is not authorized to access this resource権限不足(管理者アクセスが必要)
404Channel not found対象のチャンネルが存在しない
404Subscription not found対象のサブスクリプションが存在しない
404Message not found対象のメッセージが存在しない
404Chat message not found対象のチャットメッセージが存在しない
500Failed to create channel作成中のDB接続問題/予期せぬ失敗
500Failed to get channel取得中のDB接続問題/予期せぬ失敗
500Failed to find channels一覧取得中のDB接続問題/フィルタ不正/予期せぬ失敗
500Failed to update channel更新中のDB接続問題/予期せぬ失敗
500Failed to delete channel削除中のDB接続問題/予期せぬ失敗
500Failed to create subscription作成中のDB接続問題/予期せぬ失敗
500Failed to get subscription取得中のDB接続問題/予期せぬ失敗
500Failed to find subscriptions一覧取得中のDB接続問題/フィルタ不正/予期せぬ失敗
500Failed to delete subscription削除中のDB接続問題/予期せぬ失敗
500Failed to create message作成中のDB接続問題/予期せぬ失敗
500Failed to get message取得中のDB接続問題/予期せぬ失敗
500Failed to find messages一覧取得中のDB接続問題/フィルタ不正/予期せぬ失敗
500Failed to update message更新中のDB接続問題/予期せぬ失敗
500Failed to delete message削除中のDB接続問題/予期せぬ失敗

エラーレスポンス形式

{
"error": {
"message": "Error message description",
"data": ["Additional error details"]
}
}

Validation Errors には追加情報が含まれます:

{
"error": {
"message": "Validation Error",
"data": [
"request body must have required property 'name'",
"request body must have required property 'ownerId'"
]
}
}

🔗 関連ドキュメント