feat: add idempotency-key

This commit is contained in:
2026-11-01 14:11:53 +03:00
parent b4d1497d1c
commit cdcff89d25
10 changed files with 269 additions and 12 deletions
+17 -1
View File
@@ -88,7 +88,7 @@ export const GUIDE = `
3. **Authorize → bearerAuth**: вставьте token (без слова Bearer). Basic отправляется только на вход, остальные запросы идут с Bearer.
4. \`GET /api/v1/users/me\` — свой id; id второго участника — из ответа его регистрации.
5. \`POST /api/v1/chats\` с \`member_ids\` = [свой id, id собеседника] → \`chat_id\`.
6. \`POST /api/v1/chats/{chat_id}/messages\`, затем \`GET …/messages?limit=1\` и следующая страница с \`cursor\` = \`next_cursor\`.
6. \`POST /api/v1/chats/{chat_id}/messages\` с заголовком \`Idempotency-Key\` (любая строка из \`A-Za-z0-9._:-\`, до 128 символов). Повтор с тем же ключом и телом вернёт то же сообщение, с другим телом — 409. Затем \`GET …/messages?limit=1\` и следующая страница с \`cursor\` = \`next_cursor\`.
7. Чтобы действовать от другого пользователя: Logout в Authorize, вход им и новый token.
8. \`DELETE /api/v1/auth/sessions/current\` — logout; тот же token дальше даёт 401.
@@ -287,9 +287,25 @@ export const OPERATION_EXAMPLES: Record<string, OperationExamples> = {
error('invalid_request', 'property sender_id should not exist'),
),
chatId: INVALID_CHAT_ID,
key: example(
'Нет Idempotency-Key или неверный формат',
error(
'invalid_request',
'Idempotency-Key header must match [A-Za-z0-9._:-]{1,128}',
),
),
},
'401': UNAUTHORIZED,
'404': CHAT_NOT_FOUND,
'409': {
keyReused: example(
'Тот же Idempotency-Key с другим телом',
error(
'conflict',
'Idempotency-Key was already used with a different request',
),
),
},
'503': UNAVAILABLE,
},
},