@reqvet-sdk/sdk 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +179 -0
- package/SDK_REFERENCE.md +516 -0
- package/SECURITY.md +119 -0
- package/package.json +42 -0
- package/src/index.d.ts +261 -0
- package/src/index.js +444 -0
- package/src/webhooks.d.ts +14 -0
- package/src/webhooks.js +52 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 2.2.0
|
|
4
|
+
|
|
5
|
+
- **Feat** : ajout de `listJobs(options?)` — liste les jobs avec pagination (`limit`, `offset`) et filtres (`status`, `sort`, `order`). Aligne le SDK sur `GET /api/v1/jobs`.
|
|
6
|
+
- **Types** : ajout des interfaces `ListJobsOptions`, `JobSummary`, `ListJobsResult` dans `index.d.ts`.
|
|
7
|
+
- **Types** : `is_default?: boolean` ajouté dans `CreateTemplateParams` — exposé côté serveur mais absent des types SDK.
|
|
8
|
+
- **Types** : signature de `updateTemplate()` mise à jour pour inclure `is_default`.
|
|
9
|
+
|
|
10
|
+
## 2.1.1
|
|
11
|
+
|
|
12
|
+
- **Fix** : `_fetch` filtre désormais les clés `null`/`undefined` des payloads JSON (payloads plus propres, évite d'envoyer `callback_url: null`).
|
|
13
|
+
- **Fix doc** : README corrigé — `verifyWebhook` → `verifyWebhookSignature` (aligné sur l'export réel).
|
|
14
|
+
- **Fix doc** : SDK_REFERENCE timeout par défaut corrigé à 5 min (était indiqué 10 min).
|
|
15
|
+
- **Simplification** : les spread conditionnels (`...(x ? {k:v} : {})`) supprimés dans `createJob`, `amendJob`, `reformulateReport` — le filtrage `_fetch` gère.
|
|
16
|
+
|
|
17
|
+
## 2.1.0
|
|
18
|
+
|
|
19
|
+
- Simplification : suppression des exports `@reqvet/sdk/recorder` et `@reqvet/sdk/react`.
|
|
20
|
+
- Le SDK se concentre sur les appels **core** ReqVet (upload/jobs/templates/reformulations/amend).
|
|
21
|
+
- `uploadAudio()` retourne aussi un alias `path` (même valeur que `audio_file`) pour réduire les erreurs d’intégration.
|
|
22
|
+
- `callbackUrl` devient optionnel sur `createJob()` (fallback côté serveur sur le webhook par défaut de l’organisation).
|
|
23
|
+
- `generateReport()` supporte un mode polling (`waitForResult: true`).
|
package/README.md
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# @reqvet/sdk
|
|
2
|
+
|
|
3
|
+
Official JavaScript/TypeScript SDK for the [ReqVet](https://reqvet.com) API — AI-powered veterinary report generation from audio recordings.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@reqvet/sdk)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](https://nodejs.org)
|
|
8
|
+
|
|
9
|
+
## What it does
|
|
10
|
+
|
|
11
|
+
- **Upload** an audio recording (`uploadAudio`)
|
|
12
|
+
- **Generate** a veterinary report (`createJob`, `generateReport`)
|
|
13
|
+
- **Track** jobs — webhook-first or polling (`getJob`, `waitForJob`, `listJobs`)
|
|
14
|
+
- **Amend** a completed report with additional audio (`amendJob`)
|
|
15
|
+
- **Regenerate** with new instructions (`regenerateJob`)
|
|
16
|
+
- **Reformulate** for a specific audience — owner, referral, specialist (`reformulateReport`)
|
|
17
|
+
- **Manage templates** (`listTemplates`, `createTemplate`, `updateTemplate`, `deleteTemplate`)
|
|
18
|
+
- **Verify webhooks** with HMAC (`@reqvet/sdk/webhooks`)
|
|
19
|
+
|
|
20
|
+
> **Note**: this SDK does not include an audio recorder. Your application handles recording and passes a `File`, `Blob`, or `Buffer` to the SDK.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install @reqvet/sdk
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Requires Node.js ≥ 18. Works in modern browsers for client methods (Blob/FormData required for upload).
|
|
29
|
+
|
|
30
|
+
## Before your first call
|
|
31
|
+
|
|
32
|
+
Your ReqVet account manager will provide three environment variables:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
REQVET_API_KEY=rqv_live_...
|
|
36
|
+
REQVET_BASE_URL=https://api.reqvet.com
|
|
37
|
+
REQVET_WEBHOOK_SECRET=... # only needed if using webhooks
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Every job requires a `templateId`. **Call `listTemplates()` first** to discover what's available:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
const { system, custom } = await reqvet.listTemplates();
|
|
44
|
+
// system = ReqVet-provided templates, visible to all organizations (read-only)
|
|
45
|
+
// custom = templates created by your organization
|
|
46
|
+
|
|
47
|
+
const templateId = system[0].id;
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Quick start
|
|
51
|
+
|
|
52
|
+
### Webhook flow (recommended)
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import ReqVet from '@reqvet/sdk';
|
|
56
|
+
|
|
57
|
+
const reqvet = new ReqVet(process.env.REQVET_API_KEY!, {
|
|
58
|
+
baseUrl: process.env.REQVET_BASE_URL,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// 1. Upload the audio
|
|
62
|
+
const { path } = await reqvet.uploadAudio(audioBuffer, 'consultation.webm');
|
|
63
|
+
|
|
64
|
+
// 2. Create a job — ReqVet will POST the result to your webhook when ready
|
|
65
|
+
const job = await reqvet.createJob({
|
|
66
|
+
audioFile: path,
|
|
67
|
+
animalName: 'Rex',
|
|
68
|
+
templateId: 'your-template-uuid',
|
|
69
|
+
callbackUrl: 'https://your-app.com/api/reqvet/webhook',
|
|
70
|
+
metadata: { consultationId: 'abc123' }, // passed through to your webhook
|
|
71
|
+
});
|
|
72
|
+
// { job_id: '...', status: 'pending' }
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Your webhook receives a `job.completed` event:
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"event": "job.completed",
|
|
80
|
+
"job_id": "a1b2c3d4-...",
|
|
81
|
+
"animal_name": "Rex",
|
|
82
|
+
"html": "<section class=\"cr\">...</section>",
|
|
83
|
+
"transcription": "Le vétérinaire examine Rex...",
|
|
84
|
+
"fields": { "espece": "Chien", "poids": 28.5 },
|
|
85
|
+
"metadata": { "consultationId": "abc123" }
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Polling flow (simpler for development)
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
const report = await reqvet.generateReport({
|
|
93
|
+
audio: audioFile,
|
|
94
|
+
animalName: 'Rex',
|
|
95
|
+
templateId: 'your-template-uuid',
|
|
96
|
+
waitForResult: true,
|
|
97
|
+
onStatus: (s) => console.log(s),
|
|
98
|
+
});
|
|
99
|
+
// { jobId, html, fields, transcription, cost, metadata }
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Verify an incoming webhook
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
import { verifyWebhookSignature } from '@reqvet/sdk/webhooks';
|
|
106
|
+
|
|
107
|
+
export async function POST(req: NextRequest) {
|
|
108
|
+
const rawBody = await req.text();
|
|
109
|
+
|
|
110
|
+
const { ok, reason } = verifyWebhookSignature({
|
|
111
|
+
secret: process.env.REQVET_WEBHOOK_SECRET!,
|
|
112
|
+
rawBody,
|
|
113
|
+
signature: req.headers.get('x-reqvet-signature') ?? '',
|
|
114
|
+
timestamp: req.headers.get('x-reqvet-timestamp') ?? '',
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
if (!ok) return new Response('Unauthorized', { status: 401 });
|
|
118
|
+
|
|
119
|
+
const event = JSON.parse(rawBody);
|
|
120
|
+
// event.event, event.job_id, event.html, event.metadata ...
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## API
|
|
125
|
+
|
|
126
|
+
| Method | Description |
|
|
127
|
+
|--------|-------------|
|
|
128
|
+
| `uploadAudio(audio, fileName?)` | Upload an audio file |
|
|
129
|
+
| `generateReport(params)` | Upload + create job (convenience helper) |
|
|
130
|
+
| `createJob(params)` | Create a generation job |
|
|
131
|
+
| `listJobs(options?)` | List jobs with pagination and status filter |
|
|
132
|
+
| `getJob(jobId)` | Get job status and result |
|
|
133
|
+
| `waitForJob(jobId, onStatus?)` | Poll until job completes |
|
|
134
|
+
| `regenerateJob(jobId, options?)` | Regenerate a completed report |
|
|
135
|
+
| `amendJob(jobId, params)` | Add an audio complement to a completed job |
|
|
136
|
+
| `reformulateReport(jobId, params)` | Generate an audience-specific version |
|
|
137
|
+
| `listReformulations(jobId)` | List all reformulations for a job |
|
|
138
|
+
| `listTemplates()` | List available templates (`{ system, custom }`) |
|
|
139
|
+
| `getTemplate(templateId)` | Get a template by ID |
|
|
140
|
+
| `createTemplate(params)` | Create a custom template |
|
|
141
|
+
| `updateTemplate(templateId, updates)` | Update a template |
|
|
142
|
+
| `deleteTemplate(templateId)` | Delete a template |
|
|
143
|
+
| `health()` | API health check |
|
|
144
|
+
|
|
145
|
+
## Webhook events
|
|
146
|
+
|
|
147
|
+
ReqVet fires 5 event types: `job.completed`, `job.failed`, `job.amended`, `job.amend_failed`, `job.regenerated`.
|
|
148
|
+
|
|
149
|
+
Failed deliveries are retried 3 times (0s, 2s, 5s). Implement idempotency in your handler — deduplicate on `job_id + event`.
|
|
150
|
+
|
|
151
|
+
See [SDK_REFERENCE.md §6](./SDK_REFERENCE.md#6-webhook-events) for the full payload structure of each event.
|
|
152
|
+
|
|
153
|
+
## TypeScript
|
|
154
|
+
|
|
155
|
+
Full TypeScript definitions included:
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
import type {
|
|
159
|
+
ReqVetReport,
|
|
160
|
+
JobSummary,
|
|
161
|
+
ListJobsResult,
|
|
162
|
+
Template,
|
|
163
|
+
ReqVetReformulation,
|
|
164
|
+
ExtractedFields,
|
|
165
|
+
} from '@reqvet/sdk';
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Further reading
|
|
169
|
+
|
|
170
|
+
- [SDK_REFERENCE.md](./SDK_REFERENCE.md) — full parameter and response documentation, all webhook payloads, field schema, error codes
|
|
171
|
+
- [SECURITY.md](./SECURITY.md) — security guidelines, proxy pattern, complete webhook verification example
|
|
172
|
+
|
|
173
|
+
## Security
|
|
174
|
+
|
|
175
|
+
**Never** expose your API key in client-side code. Always use the SDK server-side and proxy requests from your frontend. See [SECURITY.md](./SECURITY.md).
|
|
176
|
+
|
|
177
|
+
## License
|
|
178
|
+
|
|
179
|
+
MIT
|