@davixlabs/h2i-sdk 0.0.0-stage → 1.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/LICENSE +10 -0
- package/README.md +54 -2
- package/index.d.ts +21589 -0
- package/index.js +20 -0
- package/package.json +38 -4
- package/src/client.js +447 -0
- package/src/errors.js +67 -0
- package/src/generated/api.js +395 -0
- package/src/generated/contract.json +1 -0
- package/src/generated/enums.js +2890 -0
- package/src/generated/error-codes.js +100 -0
- package/src/multipart.js +109 -0
- package/src/paths.js +47 -0
- package/src/schema.js +174 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Davix H2I SDK License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Davix Labs. All rights reserved.
|
|
4
|
+
|
|
5
|
+
You may install, copy and use this software, and include it unchanged or modified in your own applications, in order to
|
|
6
|
+
use the Davix H2I API with a Davix H2I account, under the Davix H2I terms of service (https://h2i.davixlabs.io/terms/).
|
|
7
|
+
You may not sell this software on its own, or use it to build or offer a service that competes with Davix H2I.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. TO THE EXTENT THE LAW ALLOWS,
|
|
10
|
+
DAVIX LABS IS NOT LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY ARISING FROM THE SOFTWARE OR ITS USE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,55 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @davixlabs/h2i-sdk (Node.js)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Official Davix H2I client. Methods, enums, typings and metadata are **generated from the canonical Davix H2I contract** (`contract/source`), so they cannot drift from the API. Requires Node 18+; no runtime dependencies.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Published on npm with every app release (app 1.4.0 gives SDK 1.4.0):
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @davixlabs/h2i-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Use
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
const { DavixH2I, enums } = require('@davixlabs/h2i-sdk');
|
|
17
|
+
const h2i = new DavixH2I({ apiKey: process.env.DAVIX_H2I_API_KEY, baseUrl: 'https://your-davix-h2i-host' });
|
|
18
|
+
|
|
19
|
+
const res = await h2i.images.resize({ images: './photo.jpg', width: 800, resizeMode: enums.ResizeFit.COVER });
|
|
20
|
+
console.log(res.data, res.requestId);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Authentication
|
|
24
|
+
The key is sent only in the `X-Api-Key` header. It is never put in a URL or body. The SDK never holds signing secrets: signed download URLs are produced by the server.
|
|
25
|
+
|
|
26
|
+
## Uploads
|
|
27
|
+
A file field accepts a path string, `Buffer`/`Uint8Array`, `Blob`/`File`, a readable stream, or `{ data, filename, contentType }`. Path strings are read from disk **only** for fields the contract declares as files.
|
|
28
|
+
|
|
29
|
+
## Metadata (bundled vs live)
|
|
30
|
+
```js
|
|
31
|
+
h2i.schema('images.resize').fields.quality; // type, minimum, maximum, default, enum, behavior (clamp/reject/fallback/unspecified)
|
|
32
|
+
h2i.capabilities.static(); // from the bundled contract, no request
|
|
33
|
+
await h2i.capabilities(); // RUNTIME: what this deployment has installed
|
|
34
|
+
await h2i.capabilities.account(); // ACCOUNT: plan, limits, usage of this key
|
|
35
|
+
await h2i.refreshContract(); // switch schema() to the live contract (GET /v1/contract)
|
|
36
|
+
```
|
|
37
|
+
`h2i.contract.bundled` is what this SDK was generated from; `h2i.contract.live` is what the server reported. They are never mixed silently.
|
|
38
|
+
|
|
39
|
+
## Errors
|
|
40
|
+
Every failure is a `DavixH2IError` subclass with `status`, `code`, `requestId`, `hint`, `details`, `renewalUrl` and `retryable`. Compare codes with `ErrorCodes`.
|
|
41
|
+
|
|
42
|
+
## Retries and idempotency
|
|
43
|
+
Only retryable errors are retried, and only for safe methods or calls that carry an idempotency key. Pass `idempotencyKey` yourself; the SDK never invents a key for a caller who did not ask for one (one per logical call is reused across its own retries).
|
|
44
|
+
|
|
45
|
+
## Escape hatch
|
|
46
|
+
`h2i.request('POST', '/v1/…', { json })` works for any `/v1/` path but refuses `/internal`, admin and anything outside the contract's request policy.
|
|
47
|
+
|
|
48
|
+
## Live slices
|
|
49
|
+
`h2i.contract.endpoint('images.optimize')`, `.field(id, name)`, `.enum(name)`, `.error(code)`, `.categories()` and `h2i.capabilities.section('pdfs')` / `.feature('pdfs', 'ocr')` fetch just the piece you need (one small cacheable GET, no API key required by the server).
|
|
50
|
+
|
|
51
|
+
## Development
|
|
52
|
+
`npm test` (conformance suite against a mock server) · `npm run typecheck`. Do not edit `src/generated` or `index.d.ts`; run `npm run contract:build` in the server repo.
|
|
53
|
+
|
|
54
|
+
## Naming your app in the History
|
|
55
|
+
Every processing call takes an optional `app`, shown under each result in your History: `await h2i.images.resize({ images: './photo.jpg', width: 800, app: 'My shop importer' })`.
|