@examplary/sdk 1.0.2 → 1.1.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/README.md +95 -9
- package/dist/generated/sdk.d.ts +1702 -0
- package/dist/generated/sdk.js +742 -0
- package/dist/generated/types.d.ts +5425 -0
- package/dist/generated/{client/client/types.gen.js → types.js} +1 -1
- package/dist/src/context.d.ts +7 -0
- package/dist/src/context.js +22 -0
- package/dist/src/error.d.ts +6 -0
- package/dist/src/error.js +24 -0
- package/dist/src/index.d.ts +5 -14
- package/dist/src/index.js +5 -45
- package/dist/src/options.d.ts +6 -0
- package/dist/{generated/client/core/types.gen.js → src/options.js} +0 -1
- package/dist/src/request.d.ts +3 -0
- package/dist/src/request.js +46 -0
- package/package.json +16 -8
- package/dist/generated/client/client/client.gen.d.ts +0 -2
- package/dist/generated/client/client/client.gen.js +0 -140
- package/dist/generated/client/client/index.d.ts +0 -8
- package/dist/generated/client/client/index.js +0 -16
- package/dist/generated/client/client/types.gen.d.ts +0 -87
- package/dist/generated/client/client/utils.gen.d.ts +0 -14
- package/dist/generated/client/client/utils.gen.js +0 -177
- package/dist/generated/client/client.gen.d.ts +0 -12
- package/dist/generated/client/client.gen.js +0 -6
- package/dist/generated/client/core/auth.gen.d.ts +0 -18
- package/dist/generated/client/core/auth.gen.js +0 -18
- package/dist/generated/client/core/bodySerializer.gen.d.ts +0 -25
- package/dist/generated/client/core/bodySerializer.gen.js +0 -60
- package/dist/generated/client/core/params.gen.d.ts +0 -43
- package/dist/generated/client/core/params.gen.js +0 -104
- package/dist/generated/client/core/pathSerializer.gen.d.ts +0 -33
- package/dist/generated/client/core/pathSerializer.gen.js +0 -115
- package/dist/generated/client/core/queryKeySerializer.gen.d.ts +0 -18
- package/dist/generated/client/core/queryKeySerializer.gen.js +0 -98
- package/dist/generated/client/core/serverSentEvents.gen.d.ts +0 -71
- package/dist/generated/client/core/serverSentEvents.gen.js +0 -135
- package/dist/generated/client/core/types.gen.d.ts +0 -78
- package/dist/generated/client/core/utils.gen.d.ts +0 -19
- package/dist/generated/client/core/utils.gen.js +0 -93
- package/dist/generated/client/index.d.ts +0 -2
- package/dist/generated/client/index.js +0 -36
- package/dist/generated/client/sdk.gen.d.ts +0 -863
- package/dist/generated/client/sdk.gen.js +0 -1826
- package/dist/generated/client/types.gen.d.ts +0 -2417
- package/dist/generated/client/types.gen.js +0 -3
package/README.md
CHANGED
|
@@ -1,25 +1,111 @@
|
|
|
1
1
|
# Examplary API SDK for TypeScript
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A type-safe TypeScript client for the [Examplary API](https://developers.examplary.ai/). One method per API operation, fully typed inputs and responses, axios-backed.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
You can install the SDK using npm or yarn:
|
|
8
|
-
|
|
9
7
|
```bash
|
|
10
8
|
yarn add @examplary/sdk
|
|
11
9
|
```
|
|
12
10
|
|
|
13
|
-
##
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { Examplary } from "@examplary/sdk";
|
|
15
|
+
|
|
16
|
+
const client = new Examplary({
|
|
17
|
+
apiKey: process.env.EXAMPLARY_API_KEY,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Create a minimal exam with a single open-ended question.
|
|
21
|
+
const exam = await client.exams.create({
|
|
22
|
+
name: "End-of-term assessment",
|
|
23
|
+
language: "en",
|
|
24
|
+
questions: [
|
|
25
|
+
{
|
|
26
|
+
type: "single-line-text",
|
|
27
|
+
title: "What is the capital of France?",
|
|
28
|
+
scoring: {
|
|
29
|
+
rubricType: "exact-values",
|
|
30
|
+
criteria: [{ id: "answer", title: "Paris", points: 1 }],
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
console.log(exam.id);
|
|
37
|
+
```
|
|
14
38
|
|
|
15
|
-
|
|
39
|
+
## Calling conventions
|
|
40
|
+
|
|
41
|
+
Every method takes a single object whose fields combine path, query, and body parameters:
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
// Path + body merged into one object.
|
|
45
|
+
await client.exams.update({
|
|
46
|
+
id: exam.id,
|
|
47
|
+
name: "Updated name",
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Just a string when the operation has a single path parameter.
|
|
51
|
+
const questionType = await client.questionTypes.get("single-line-text");
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Each method accepts an optional second argument that extends [axios's request config](https://axios-http.com/docs/req_config) — anything except `method`, `url`, `data`, `params`, `baseURL`:
|
|
16
55
|
|
|
17
56
|
```typescript
|
|
18
|
-
|
|
57
|
+
await client.exams.list({}, {
|
|
58
|
+
timeout: 10_000,
|
|
59
|
+
signal: controller.signal,
|
|
60
|
+
headers: { "X-Trace-Id": traceId },
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Nested resources (e.g. `client.exams.sessions.acceptSuggestion`) rename the parent `id` to `examId` (or `practiceSpaceId`, etc.) for readability:
|
|
19
65
|
|
|
20
|
-
|
|
21
|
-
|
|
66
|
+
```typescript
|
|
67
|
+
await client.exams.sessions.acceptSuggestion({
|
|
68
|
+
examId: exam.id,
|
|
69
|
+
sessionId,
|
|
70
|
+
questionId,
|
|
22
71
|
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Errors
|
|
23
75
|
|
|
24
|
-
|
|
76
|
+
Failed requests reject with an `ExamplaryError` (an `AxiosError` subclass). The error message is taken from the API response body when available:
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { Examplary, ExamplaryError } from "@examplary/sdk";
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
await client.exams.get("ex_does_not_exist");
|
|
83
|
+
} catch (err) {
|
|
84
|
+
if (err instanceof ExamplaryError) {
|
|
85
|
+
console.error(err.message, err.response?.status);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
25
88
|
```
|
|
89
|
+
|
|
90
|
+
## Configuration
|
|
91
|
+
|
|
92
|
+
`new Examplary(options)` accepts every [axios `CreateAxiosDefaults`](https://axios-http.com/docs/config_defaults) field plus:
|
|
93
|
+
|
|
94
|
+
| Option | Type | Description |
|
|
95
|
+
| --------- | -------- | ---------------------------------------------------------------------- |
|
|
96
|
+
| `apiKey` | `string` | Required. API key or OAuth access token. Sent as `Authorization` header. |
|
|
97
|
+
| `baseUrl` | `string` | Override the API host. Defaults to `https://api.examplary.ai`. |
|
|
98
|
+
|
|
99
|
+
## Types
|
|
100
|
+
|
|
101
|
+
Per-operation argument and response types are exported under predictable names:
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import type {
|
|
105
|
+
ExamsCreateArgs,
|
|
106
|
+
ExamsCreateResponse,
|
|
107
|
+
QuestionTypesGetArgs,
|
|
108
|
+
} from "@examplary/sdk";
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
The full OpenAPI surface is also available as `paths`, `operations`, and `components` exports for advanced use.
|