@exayard/sdk 0.3.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/LICENSE +21 -0
- package/README.md +139 -0
- package/dist/_generated/operations.d.ts +8467 -0
- package/dist/_generated/operations.d.ts.map +1 -0
- package/dist/_generated/operations.js +2489 -0
- package/dist/client.d.ts +554 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +404 -0
- package/dist/error.d.ts +76 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +152 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +62 -0
- package/dist/listeners.d.ts +106 -0
- package/dist/listeners.d.ts.map +1 -0
- package/dist/listeners.js +214 -0
- package/dist/options.d.ts +41 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +11 -0
- package/dist/retry.d.ts +24 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +63 -0
- package/dist/webhooks.d.ts +59 -0
- package/dist/webhooks.d.ts.map +1 -0
- package/dist/webhooks.js +149 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Exayard
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# @exayard/sdk
|
|
2
|
+
|
|
3
|
+
Official TypeScript SDK for the [Exayard](https://exayard.com) API: AI takeoffs, estimates, bids, price lists and
|
|
4
|
+
webhooks. Every API operation is a typed method, generated from the API spec.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @exayard/sdk
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Node 20 or later (or any runtime with `fetch` and Web Crypto).
|
|
13
|
+
|
|
14
|
+
## Quickstart
|
|
15
|
+
|
|
16
|
+
Create an app and a key on the Developer page ([exayard.com/settings/developer](https://exayard.com/settings/developer)).
|
|
17
|
+
A sandbox company gives you an `exa_test_` key whose AI work returns sample results at no cost.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { readFile } from 'node:fs/promises'
|
|
21
|
+
import { Exayard } from '@exayard/sdk'
|
|
22
|
+
|
|
23
|
+
// A key made for a company acts in that company: no organizationId needed.
|
|
24
|
+
const exa = new Exayard({ apiKey: process.env.EXAYARD_API_KEY })
|
|
25
|
+
|
|
26
|
+
const project = await exa.projects.create({ name: 'Riverside clinic' })
|
|
27
|
+
const { fileId } = await exa.files.upload({
|
|
28
|
+
projectId: project.id,
|
|
29
|
+
filename: 'plans.pdf',
|
|
30
|
+
mimeType: 'application/pdf',
|
|
31
|
+
bytes: await readFile('plans.pdf')
|
|
32
|
+
})
|
|
33
|
+
const pages = await exa.pages.list(project.id)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Every operation is also on `exa.api` (camelCase) and `exa.call` (by its operation name):
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
await exa.api.listVendorQuotes({ id: project.id })
|
|
40
|
+
await exa.call('list_vendor_quotes', { id: project.id })
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Keys and companies
|
|
44
|
+
|
|
45
|
+
- `exa_live_...` and `exa_test_...` keys work, and so do the older `ak_...` keys and `xa_app_...` app secrets.
|
|
46
|
+
`apiKey` defaults to the `EXAYARD_API_KEY` environment variable. An OAuth access token goes in `bearerToken`.
|
|
47
|
+
- `organizationId` is optional everywhere. A key made for its own company implies that company. A personal key or
|
|
48
|
+
sign-in that belongs to several companies names one with the client's `organizationId` or on the call.
|
|
49
|
+
|
|
50
|
+
## End users
|
|
51
|
+
|
|
52
|
+
If you call Exayard for your own customers, name the customer so usage can be broken down by end user (on the
|
|
53
|
+
Usage screen and through the usage API):
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
const exa = new Exayard({ apiKey, endUser: 'customer-1842' })
|
|
57
|
+
await exa.projects.list({}) // sent with Exayard-End-User: customer-1842
|
|
58
|
+
await exa.call('get_project', { id }, { endUser: 'customer-77' }) // per call
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
An end user id is 1 to 128 printable characters. Use your own opaque id, never an email address.
|
|
62
|
+
|
|
63
|
+
## Retries and idempotency
|
|
64
|
+
|
|
65
|
+
429s, 5xx answers and dropped connections are retried twice by default, waiting as long as `Retry-After` asks (up to
|
|
66
|
+
a minute) or backing off from half a second. Every POST, PATCH, PUT and DELETE carries an `Idempotency-Key` that each
|
|
67
|
+
retry reuses, so a retried call runs once. Pass your own with `{ idempotencyKey }`, and set `maxRetries` on the client
|
|
68
|
+
or the call (`0` turns retries off).
|
|
69
|
+
|
|
70
|
+
## Errors
|
|
71
|
+
|
|
72
|
+
Every failed call throws an `ExayardError` subclass chosen by the problem's `code`:
|
|
73
|
+
|
|
74
|
+
| Class | Status | Codes |
|
|
75
|
+
|---|---|---|
|
|
76
|
+
| `BadRequestError` | 400 | `invalid_request`, `invalid_end_user`, `company_required`, `company_mismatch` |
|
|
77
|
+
| `AuthenticationError` | 401 | `unauthenticated`, `api_key_expired` |
|
|
78
|
+
| `PaymentRequiredError` | 402 | `insufficient_credits`, `usage_limit_reached`, `subscription_required`, ... |
|
|
79
|
+
| `PermissionDeniedError` | 403 | `forbidden`, `insufficient_scope`, `app_not_installed`, `app_suspended` |
|
|
80
|
+
| `NotFoundError` | 404 | `not_found` |
|
|
81
|
+
| `ConflictError` | 409 | `conflict`, `idempotency_key_reused` |
|
|
82
|
+
| `RateLimitError` | 429 | `rate_limited` (with `retryAfter`) |
|
|
83
|
+
| `InternalServerError` | 5xx | `internal_error` |
|
|
84
|
+
| `APIConnectionError` | none | `connection_error`, `timeout` |
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
try {
|
|
88
|
+
await exa.projects.get(id)
|
|
89
|
+
} catch (err) {
|
|
90
|
+
if (err instanceof NotFoundError) return null
|
|
91
|
+
throw err // err.code, err.detail, err.requestId, err.docUrl
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Webhooks
|
|
96
|
+
|
|
97
|
+
Verify a delivery with the raw request body, the `Exayard-Signature` header and the endpoint's `whsec_` secret.
|
|
98
|
+
`constructWebhookEvent` is async (it uses Web Crypto), so `await` it. It needs no API key; `exa.webhooks.constructEvent`
|
|
99
|
+
is the same function. With Express:
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import express from 'express'
|
|
103
|
+
import { constructWebhookEvent, WebhookSignatureError } from '@exayard/sdk'
|
|
104
|
+
|
|
105
|
+
const secret = process.env.EXAYARD_WEBHOOK_SECRET
|
|
106
|
+
if (!secret) throw new Error('Set EXAYARD_WEBHOOK_SECRET')
|
|
107
|
+
|
|
108
|
+
const app = express()
|
|
109
|
+
|
|
110
|
+
// Take the raw body (a Buffer), not express.json(): the signature covers the exact bytes sent.
|
|
111
|
+
app.post('/webhooks', express.raw({ type: 'application/json' }), async (req, res) => {
|
|
112
|
+
try {
|
|
113
|
+
const event = await constructWebhookEvent(req.body, req.get('Exayard-Signature'), secret)
|
|
114
|
+
if (event.type === 'assessment.completed') {
|
|
115
|
+
// ...
|
|
116
|
+
}
|
|
117
|
+
res.sendStatus(200)
|
|
118
|
+
} catch (err) {
|
|
119
|
+
if (err instanceof WebhookSignatureError) res.status(400).send(err.code)
|
|
120
|
+
else res.sendStatus(500)
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
app.listen(3000)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
It throws `WebhookSignatureError` (`invalid_signature`, `replay_window_exceeded`, `malformed_header`); answer it with
|
|
128
|
+
a 400. To receive events on your own machine without a public address, run `exayard listen --forward-to
|
|
129
|
+
http://localhost:3000/webhooks` from [`@exayard/cli`](https://www.npmjs.com/package/@exayard/cli), or use
|
|
130
|
+
`exa.webhooks.listeners` directly.
|
|
131
|
+
|
|
132
|
+
## Links
|
|
133
|
+
|
|
134
|
+
- API reference: https://developers.exayard.com/api-reference
|
|
135
|
+
- Errors: https://developers.exayard.com/concepts/errors
|
|
136
|
+
|
|
137
|
+
## License
|
|
138
|
+
|
|
139
|
+
MIT
|