@atelierlogos/hotcross 0.0.1
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/FUNCTIONS.md +87 -0
- package/README.md +459 -0
- package/RUNTIMES.md +48 -0
- package/package.json +122 -0
package/FUNCTIONS.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Standalone Functions
|
|
2
|
+
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This section is useful if you are using a bundler and targetting browsers and
|
|
5
|
+
> runtimes where the size of an application affects performance and load times.
|
|
6
|
+
|
|
7
|
+
Every method in this SDK is also available as a standalone function. This
|
|
8
|
+
alternative API is suitable when targetting the browser or serverless runtimes
|
|
9
|
+
and using a bundler to build your application since all unused functionality
|
|
10
|
+
will be tree-shaken away. This includes code for unused methods, Zod schemas,
|
|
11
|
+
encoding helpers and response handlers. The result is dramatically smaller
|
|
12
|
+
impact on the application's final bundle size which grows very slowly as you use
|
|
13
|
+
more and more functionality from this SDK.
|
|
14
|
+
|
|
15
|
+
Calling methods through the main SDK class remains a valid and generally more
|
|
16
|
+
more ergonomic option. Standalone functions represent an optimisation for a
|
|
17
|
+
specific category of applications.
|
|
18
|
+
|
|
19
|
+
## Example
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { HotcrossCore } from "hotcross/core.js";
|
|
23
|
+
import { healthCheck } from "hotcross/funcs/healthCheck.js";
|
|
24
|
+
|
|
25
|
+
// Use `HotcrossCore` for best tree-shaking performance.
|
|
26
|
+
// You can create one instance of it to use across an application.
|
|
27
|
+
const hotcross = new HotcrossCore({
|
|
28
|
+
bearerAuth: process.env["HOTCROSS_BEARER_AUTH"] ?? "",
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
async function run() {
|
|
32
|
+
const res = await healthCheck(hotcross);
|
|
33
|
+
if (res.ok) {
|
|
34
|
+
const { value: result } = res;
|
|
35
|
+
console.log(result);
|
|
36
|
+
} else {
|
|
37
|
+
console.log("healthCheck failed:", res.error);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
run();
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Result types
|
|
45
|
+
|
|
46
|
+
Standalone functions differ from SDK methods in that they return a
|
|
47
|
+
`Result<Value, Error>` type to capture _known errors_ and document them using
|
|
48
|
+
the type system. By avoiding throwing errors, application code maintains clear
|
|
49
|
+
control flow and error-handling become part of the regular flow of application
|
|
50
|
+
code.
|
|
51
|
+
|
|
52
|
+
> We use the term "known errors" because standalone functions, and JavaScript
|
|
53
|
+
> code in general, can still throw unexpected errors such as `TypeError`s,
|
|
54
|
+
> `RangeError`s and `DOMException`s. Exhaustively catching all errors may be
|
|
55
|
+
> something this SDK addresses in the future. Nevertheless, there is still a lot
|
|
56
|
+
> of benefit from capturing most errors and turning them into values.
|
|
57
|
+
|
|
58
|
+
The second reason for this style of programming is because these functions will
|
|
59
|
+
typically be used in front-end applications where exception throwing is
|
|
60
|
+
sometimes discouraged or considered unidiomatic. React and similar ecosystems
|
|
61
|
+
and libraries tend to promote this style of programming so that components
|
|
62
|
+
render useful content under all states (loading, success, error and so on).
|
|
63
|
+
|
|
64
|
+
The general pattern when calling standalone functions looks like this:
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { Core } from "<sdk-package-name>";
|
|
68
|
+
import { fetchSomething } from "<sdk-package-name>/funcs/fetchSomething.js";
|
|
69
|
+
|
|
70
|
+
const client = new Core();
|
|
71
|
+
|
|
72
|
+
async function run() {
|
|
73
|
+
const result = await fetchSomething(client, { id: "123" });
|
|
74
|
+
if (!result.ok) {
|
|
75
|
+
// You can throw the error or handle it. It's your choice now.
|
|
76
|
+
throw result.error;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
console.log(result.value);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
run();
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Notably, `result.error` above will have an explicit type compared to a try-catch
|
|
86
|
+
variation where the error in the catch block can only be of type `unknown` (or
|
|
87
|
+
`any` depending on your TypeScript settings).
|
package/README.md
ADDED
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
# hotcross
|
|
2
|
+
|
|
3
|
+
Developer-friendly & type-safe Typescript SDK specifically catered to leverage *hotcross* API.
|
|
4
|
+
|
|
5
|
+
[](https://www.speakeasy.com/?utm_source=hotcross&utm_campaign=typescript)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<br /><br />
|
|
10
|
+
> [!IMPORTANT]
|
|
11
|
+
> This SDK is not yet ready for production use. To complete setup please follow the steps outlined in your [workspace](https://app.speakeasy.com/org/usenabla/dev). Delete this section before > publishing to a package manager.
|
|
12
|
+
|
|
13
|
+
<!-- Start Summary [summary] -->
|
|
14
|
+
## Summary
|
|
15
|
+
|
|
16
|
+
Voice UI Broker API: Hotcross Voice UI Broker for creating chat sessions, streaming UI updates, recording client actions, and handling Arcade connect webhook events.
|
|
17
|
+
<!-- End Summary [summary] -->
|
|
18
|
+
|
|
19
|
+
<!-- Start Table of Contents [toc] -->
|
|
20
|
+
## Table of Contents
|
|
21
|
+
<!-- $toc-max-depth=2 -->
|
|
22
|
+
* [hotcross](#hotcross)
|
|
23
|
+
* [SDK Installation](#sdk-installation)
|
|
24
|
+
* [Requirements](#requirements)
|
|
25
|
+
* [SDK Example Usage](#sdk-example-usage)
|
|
26
|
+
* [Authentication](#authentication)
|
|
27
|
+
* [Available Resources and Operations](#available-resources-and-operations)
|
|
28
|
+
* [Standalone functions](#standalone-functions)
|
|
29
|
+
* [Retries](#retries)
|
|
30
|
+
* [Error Handling](#error-handling)
|
|
31
|
+
* [Server Selection](#server-selection)
|
|
32
|
+
* [Custom HTTP Client](#custom-http-client)
|
|
33
|
+
* [Debugging](#debugging)
|
|
34
|
+
* [Development](#development)
|
|
35
|
+
* [Maturity](#maturity)
|
|
36
|
+
* [Contributions](#contributions)
|
|
37
|
+
|
|
38
|
+
<!-- End Table of Contents [toc] -->
|
|
39
|
+
|
|
40
|
+
<!-- Start SDK Installation [installation] -->
|
|
41
|
+
## SDK Installation
|
|
42
|
+
|
|
43
|
+
> [!TIP]
|
|
44
|
+
> To finish publishing your SDK to npm and others you must [run your first generation action](https://www.speakeasy.com/docs/github-setup#step-by-step-guide).
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
The SDK can be installed with either [npm](https://www.npmjs.com/), [pnpm](https://pnpm.io/), [bun](https://bun.sh/) or [yarn](https://classic.yarnpkg.com/en/) package managers.
|
|
48
|
+
|
|
49
|
+
### NPM
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npm add <UNSET>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### PNPM
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pnpm add <UNSET>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Bun
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
bun add <UNSET>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Yarn
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
yarn add <UNSET>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
> [!NOTE]
|
|
74
|
+
> This package is published with CommonJS and ES Modules (ESM) support.
|
|
75
|
+
<!-- End SDK Installation [installation] -->
|
|
76
|
+
|
|
77
|
+
<!-- Start Requirements [requirements] -->
|
|
78
|
+
## Requirements
|
|
79
|
+
|
|
80
|
+
For supported JavaScript runtimes, please consult [RUNTIMES.md](RUNTIMES.md).
|
|
81
|
+
<!-- End Requirements [requirements] -->
|
|
82
|
+
|
|
83
|
+
<!-- Start SDK Example Usage [usage] -->
|
|
84
|
+
## SDK Example Usage
|
|
85
|
+
|
|
86
|
+
### Example
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { Hotcross } from "hotcross";
|
|
90
|
+
|
|
91
|
+
const hotcross = new Hotcross({
|
|
92
|
+
bearerAuth: process.env["HOTCROSS_BEARER_AUTH"] ?? "",
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
async function run() {
|
|
96
|
+
const result = await hotcross.health.check();
|
|
97
|
+
|
|
98
|
+
console.log(result);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
run();
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
<!-- End SDK Example Usage [usage] -->
|
|
105
|
+
|
|
106
|
+
<!-- Start Authentication [security] -->
|
|
107
|
+
## Authentication
|
|
108
|
+
|
|
109
|
+
### Per-Client Security Schemes
|
|
110
|
+
|
|
111
|
+
This SDK supports the following security scheme globally:
|
|
112
|
+
|
|
113
|
+
| Name | Type | Scheme | Environment Variable |
|
|
114
|
+
| ------------ | ---- | ----------- | ---------------------- |
|
|
115
|
+
| `bearerAuth` | http | HTTP Bearer | `HOTCROSS_BEARER_AUTH` |
|
|
116
|
+
|
|
117
|
+
To authenticate with the API the `bearerAuth` parameter must be set when initializing the SDK client instance. For example:
|
|
118
|
+
```typescript
|
|
119
|
+
import { Hotcross } from "hotcross";
|
|
120
|
+
|
|
121
|
+
const hotcross = new Hotcross({
|
|
122
|
+
bearerAuth: process.env["HOTCROSS_BEARER_AUTH"] ?? "",
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
async function run() {
|
|
126
|
+
const result = await hotcross.health.check();
|
|
127
|
+
|
|
128
|
+
console.log(result);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
run();
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Per-Operation Security Schemes
|
|
136
|
+
|
|
137
|
+
Some operations in this SDK require the security scheme to be specified at the request level. For example:
|
|
138
|
+
```typescript
|
|
139
|
+
import { Hotcross } from "hotcross";
|
|
140
|
+
|
|
141
|
+
const hotcross = new Hotcross();
|
|
142
|
+
|
|
143
|
+
async function run() {
|
|
144
|
+
const result = await hotcross.sessions.get({}, {
|
|
145
|
+
sessionId: "<id>",
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
console.log(result);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
run();
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
<!-- End Authentication [security] -->
|
|
155
|
+
|
|
156
|
+
<!-- Start Available Resources and Operations [operations] -->
|
|
157
|
+
## Available Resources and Operations
|
|
158
|
+
|
|
159
|
+
<details open>
|
|
160
|
+
<summary>Available methods</summary>
|
|
161
|
+
|
|
162
|
+
### [Arcade.Webhook](docs/sdks/webhook/README.md)
|
|
163
|
+
|
|
164
|
+
* [receive](docs/sdks/webhook/README.md#receive) - Receive Arcade webhook events
|
|
165
|
+
|
|
166
|
+
### [Health](docs/sdks/health/README.md)
|
|
167
|
+
|
|
168
|
+
* [check](docs/sdks/health/README.md#check) - Health check
|
|
169
|
+
|
|
170
|
+
### [Sessions](docs/sdks/sessions/README.md)
|
|
171
|
+
|
|
172
|
+
* [create](docs/sdks/sessions/README.md#create) - Create a session
|
|
173
|
+
* [get](docs/sdks/sessions/README.md#get) - Get a session
|
|
174
|
+
* [streamEvents](docs/sdks/sessions/README.md#streamevents) - Stream session events (SSE)
|
|
175
|
+
|
|
176
|
+
#### [Sessions.Actions](docs/sdks/actions/README.md)
|
|
177
|
+
|
|
178
|
+
* [record](docs/sdks/actions/README.md#record) - Record a client action
|
|
179
|
+
|
|
180
|
+
#### [Sessions.Arcade](docs/sdks/sessionsarcade/README.md)
|
|
181
|
+
|
|
182
|
+
* [createConnectIntent](docs/sdks/sessionsarcade/README.md#createconnectintent) - Create an Arcade connect intent
|
|
183
|
+
|
|
184
|
+
</details>
|
|
185
|
+
<!-- End Available Resources and Operations [operations] -->
|
|
186
|
+
|
|
187
|
+
<!-- Start Standalone functions [standalone-funcs] -->
|
|
188
|
+
## Standalone functions
|
|
189
|
+
|
|
190
|
+
All the methods listed above are available as standalone functions. These
|
|
191
|
+
functions are ideal for use in applications running in the browser, serverless
|
|
192
|
+
runtimes or other environments where application bundle size is a primary
|
|
193
|
+
concern. When using a bundler to build your application, all unused
|
|
194
|
+
functionality will be either excluded from the final bundle or tree-shaken away.
|
|
195
|
+
|
|
196
|
+
To read more about standalone functions, check [FUNCTIONS.md](./FUNCTIONS.md).
|
|
197
|
+
|
|
198
|
+
<details>
|
|
199
|
+
|
|
200
|
+
<summary>Available standalone functions</summary>
|
|
201
|
+
|
|
202
|
+
- [`arcadeWebhookReceive`](docs/sdks/webhook/README.md#receive) - Receive Arcade webhook events
|
|
203
|
+
- [`healthCheck`](docs/sdks/health/README.md#check) - Health check
|
|
204
|
+
- [`sessionsActionsRecord`](docs/sdks/actions/README.md#record) - Record a client action
|
|
205
|
+
- [`sessionsArcadeCreateConnectIntent`](docs/sdks/sessionsarcade/README.md#createconnectintent) - Create an Arcade connect intent
|
|
206
|
+
- [`sessionsCreate`](docs/sdks/sessions/README.md#create) - Create a session
|
|
207
|
+
- [`sessionsGet`](docs/sdks/sessions/README.md#get) - Get a session
|
|
208
|
+
- [`sessionsStreamEvents`](docs/sdks/sessions/README.md#streamevents) - Stream session events (SSE)
|
|
209
|
+
|
|
210
|
+
</details>
|
|
211
|
+
<!-- End Standalone functions [standalone-funcs] -->
|
|
212
|
+
|
|
213
|
+
<!-- Start Retries [retries] -->
|
|
214
|
+
## Retries
|
|
215
|
+
|
|
216
|
+
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
|
|
217
|
+
|
|
218
|
+
To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:
|
|
219
|
+
```typescript
|
|
220
|
+
import { Hotcross } from "hotcross";
|
|
221
|
+
|
|
222
|
+
const hotcross = new Hotcross({
|
|
223
|
+
bearerAuth: process.env["HOTCROSS_BEARER_AUTH"] ?? "",
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
async function run() {
|
|
227
|
+
const result = await hotcross.health.check({
|
|
228
|
+
retries: {
|
|
229
|
+
strategy: "backoff",
|
|
230
|
+
backoff: {
|
|
231
|
+
initialInterval: 1,
|
|
232
|
+
maxInterval: 50,
|
|
233
|
+
exponent: 1.1,
|
|
234
|
+
maxElapsedTime: 100,
|
|
235
|
+
},
|
|
236
|
+
retryConnectionErrors: false,
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
console.log(result);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
run();
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:
|
|
248
|
+
```typescript
|
|
249
|
+
import { Hotcross } from "hotcross";
|
|
250
|
+
|
|
251
|
+
const hotcross = new Hotcross({
|
|
252
|
+
retryConfig: {
|
|
253
|
+
strategy: "backoff",
|
|
254
|
+
backoff: {
|
|
255
|
+
initialInterval: 1,
|
|
256
|
+
maxInterval: 50,
|
|
257
|
+
exponent: 1.1,
|
|
258
|
+
maxElapsedTime: 100,
|
|
259
|
+
},
|
|
260
|
+
retryConnectionErrors: false,
|
|
261
|
+
},
|
|
262
|
+
bearerAuth: process.env["HOTCROSS_BEARER_AUTH"] ?? "",
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
async function run() {
|
|
266
|
+
const result = await hotcross.health.check();
|
|
267
|
+
|
|
268
|
+
console.log(result);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
run();
|
|
272
|
+
|
|
273
|
+
```
|
|
274
|
+
<!-- End Retries [retries] -->
|
|
275
|
+
|
|
276
|
+
<!-- Start Error Handling [errors] -->
|
|
277
|
+
## Error Handling
|
|
278
|
+
|
|
279
|
+
[`HotcrossError`](./src/models/errors/hotcrosserror.ts) is the base class for all HTTP error responses. It has the following properties:
|
|
280
|
+
|
|
281
|
+
| Property | Type | Description |
|
|
282
|
+
| ------------------- | ---------- | --------------------------------------------------------------------------------------- |
|
|
283
|
+
| `error.message` | `string` | Error message |
|
|
284
|
+
| `error.statusCode` | `number` | HTTP response status code eg `404` |
|
|
285
|
+
| `error.headers` | `Headers` | HTTP response headers |
|
|
286
|
+
| `error.body` | `string` | HTTP body. Can be empty string if no body is returned. |
|
|
287
|
+
| `error.rawResponse` | `Response` | Raw HTTP response |
|
|
288
|
+
| `error.data$` | | Optional. Some errors may contain structured data. [See Error Classes](#error-classes). |
|
|
289
|
+
|
|
290
|
+
### Example
|
|
291
|
+
```typescript
|
|
292
|
+
import { Hotcross } from "hotcross";
|
|
293
|
+
import * as errors from "hotcross/models/errors";
|
|
294
|
+
|
|
295
|
+
const hotcross = new Hotcross({
|
|
296
|
+
bearerAuth: process.env["HOTCROSS_BEARER_AUTH"] ?? "",
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
async function run() {
|
|
300
|
+
try {
|
|
301
|
+
const result = await hotcross.sessions.create({
|
|
302
|
+
tenantId: "<id>",
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
console.log(result);
|
|
306
|
+
} catch (error) {
|
|
307
|
+
// The base class for HTTP error responses
|
|
308
|
+
if (error instanceof errors.HotcrossError) {
|
|
309
|
+
console.log(error.message);
|
|
310
|
+
console.log(error.statusCode);
|
|
311
|
+
console.log(error.body);
|
|
312
|
+
console.log(error.headers);
|
|
313
|
+
|
|
314
|
+
// Depending on the method different errors may be thrown
|
|
315
|
+
if (error instanceof errors.ErrorResponse) {
|
|
316
|
+
console.log(error.data$.error); // models.ErrorT
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
run();
|
|
323
|
+
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
### Error Classes
|
|
327
|
+
**Primary errors:**
|
|
328
|
+
* [`HotcrossError`](./src/models/errors/hotcrosserror.ts): The base class for HTTP error responses.
|
|
329
|
+
* [`ErrorResponse`](./src/models/errors/errorresponse.ts): Missing or invalid authentication. *
|
|
330
|
+
|
|
331
|
+
<details><summary>Less common errors (6)</summary>
|
|
332
|
+
|
|
333
|
+
<br />
|
|
334
|
+
|
|
335
|
+
**Network errors:**
|
|
336
|
+
* [`ConnectionError`](./src/models/errors/httpclienterrors.ts): HTTP client was unable to make a request to a server.
|
|
337
|
+
* [`RequestTimeoutError`](./src/models/errors/httpclienterrors.ts): HTTP request timed out due to an AbortSignal signal.
|
|
338
|
+
* [`RequestAbortedError`](./src/models/errors/httpclienterrors.ts): HTTP request was aborted by the client.
|
|
339
|
+
* [`InvalidRequestError`](./src/models/errors/httpclienterrors.ts): Any input used to create a request is invalid.
|
|
340
|
+
* [`UnexpectedClientError`](./src/models/errors/httpclienterrors.ts): Unrecognised or unexpected error.
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
**Inherit from [`HotcrossError`](./src/models/errors/hotcrosserror.ts)**:
|
|
344
|
+
* [`ResponseValidationError`](./src/models/errors/responsevalidationerror.ts): Type mismatch between the data returned from the server and the structure expected by the SDK. See `error.rawValue` for the raw value and `error.pretty()` for a nicely formatted multi-line string.
|
|
345
|
+
|
|
346
|
+
</details>
|
|
347
|
+
|
|
348
|
+
\* Check [the method documentation](#available-resources-and-operations) to see if the error is applicable.
|
|
349
|
+
<!-- End Error Handling [errors] -->
|
|
350
|
+
|
|
351
|
+
<!-- Start Server Selection [server] -->
|
|
352
|
+
## Server Selection
|
|
353
|
+
|
|
354
|
+
### Override Server URL Per-Client
|
|
355
|
+
|
|
356
|
+
The default server can be overridden globally by passing a URL to the `serverURL: string` optional parameter when initializing the SDK client instance. For example:
|
|
357
|
+
```typescript
|
|
358
|
+
import { Hotcross } from "hotcross";
|
|
359
|
+
|
|
360
|
+
const hotcross = new Hotcross({
|
|
361
|
+
serverURL: "http://localhost:3000",
|
|
362
|
+
bearerAuth: process.env["HOTCROSS_BEARER_AUTH"] ?? "",
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
async function run() {
|
|
366
|
+
const result = await hotcross.health.check();
|
|
367
|
+
|
|
368
|
+
console.log(result);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
run();
|
|
372
|
+
|
|
373
|
+
```
|
|
374
|
+
<!-- End Server Selection [server] -->
|
|
375
|
+
|
|
376
|
+
<!-- Start Custom HTTP Client [http-client] -->
|
|
377
|
+
## Custom HTTP Client
|
|
378
|
+
|
|
379
|
+
The TypeScript SDK makes API calls using an `HTTPClient` that wraps the native
|
|
380
|
+
[Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). This
|
|
381
|
+
client is a thin wrapper around `fetch` and provides the ability to attach hooks
|
|
382
|
+
around the request lifecycle that can be used to modify the request or handle
|
|
383
|
+
errors and response.
|
|
384
|
+
|
|
385
|
+
The `HTTPClient` constructor takes an optional `fetcher` argument that can be
|
|
386
|
+
used to integrate a third-party HTTP client or when writing tests to mock out
|
|
387
|
+
the HTTP client and feed in fixtures.
|
|
388
|
+
|
|
389
|
+
The following example shows how to use the `"beforeRequest"` hook to to add a
|
|
390
|
+
custom header and a timeout to requests and how to use the `"requestError"` hook
|
|
391
|
+
to log errors:
|
|
392
|
+
|
|
393
|
+
```typescript
|
|
394
|
+
import { Hotcross } from "hotcross";
|
|
395
|
+
import { HTTPClient } from "hotcross/lib/http";
|
|
396
|
+
|
|
397
|
+
const httpClient = new HTTPClient({
|
|
398
|
+
// fetcher takes a function that has the same signature as native `fetch`.
|
|
399
|
+
fetcher: (request) => {
|
|
400
|
+
return fetch(request);
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
httpClient.addHook("beforeRequest", (request) => {
|
|
405
|
+
const nextRequest = new Request(request, {
|
|
406
|
+
signal: request.signal || AbortSignal.timeout(5000)
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
nextRequest.headers.set("x-custom-header", "custom value");
|
|
410
|
+
|
|
411
|
+
return nextRequest;
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
httpClient.addHook("requestError", (error, request) => {
|
|
415
|
+
console.group("Request Error");
|
|
416
|
+
console.log("Reason:", `${error}`);
|
|
417
|
+
console.log("Endpoint:", `${request.method} ${request.url}`);
|
|
418
|
+
console.groupEnd();
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
const sdk = new Hotcross({ httpClient: httpClient });
|
|
422
|
+
```
|
|
423
|
+
<!-- End Custom HTTP Client [http-client] -->
|
|
424
|
+
|
|
425
|
+
<!-- Start Debugging [debug] -->
|
|
426
|
+
## Debugging
|
|
427
|
+
|
|
428
|
+
You can setup your SDK to emit debug logs for SDK requests and responses.
|
|
429
|
+
|
|
430
|
+
You can pass a logger that matches `console`'s interface as an SDK option.
|
|
431
|
+
|
|
432
|
+
> [!WARNING]
|
|
433
|
+
> Beware that debug logging will reveal secrets, like API tokens in headers, in log messages printed to a console or files. It's recommended to use this feature only during local development and not in production.
|
|
434
|
+
|
|
435
|
+
```typescript
|
|
436
|
+
import { Hotcross } from "hotcross";
|
|
437
|
+
|
|
438
|
+
const sdk = new Hotcross({ debugLogger: console });
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
You can also enable a default debug logger by setting an environment variable `HOTCROSS_DEBUG` to true.
|
|
442
|
+
<!-- End Debugging [debug] -->
|
|
443
|
+
|
|
444
|
+
<!-- Placeholder for Future Speakeasy SDK Sections -->
|
|
445
|
+
|
|
446
|
+
# Development
|
|
447
|
+
|
|
448
|
+
## Maturity
|
|
449
|
+
|
|
450
|
+
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage
|
|
451
|
+
to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally
|
|
452
|
+
looking for the latest version.
|
|
453
|
+
|
|
454
|
+
## Contributions
|
|
455
|
+
|
|
456
|
+
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation.
|
|
457
|
+
We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.
|
|
458
|
+
|
|
459
|
+
### SDK Created by [Speakeasy](https://www.speakeasy.com/?utm_source=hotcross&utm_campaign=typescript)
|
package/RUNTIMES.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Supported JavaScript runtimes
|
|
2
|
+
|
|
3
|
+
This SDK is intended to be used in JavaScript runtimes that support ECMAScript 2020 or newer. The SDK uses the following features:
|
|
4
|
+
|
|
5
|
+
- [Web Fetch API][web-fetch]
|
|
6
|
+
- [Web Streams API][web-streams] and in particular `ReadableStream`
|
|
7
|
+
- [Async iterables][async-iter] using `Symbol.asyncIterator`
|
|
8
|
+
|
|
9
|
+
[web-fetch]: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
|
|
10
|
+
[web-streams]: https://developer.mozilla.org/en-US/docs/Web/API/Streams_API
|
|
11
|
+
[async-iter]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols
|
|
12
|
+
|
|
13
|
+
Runtime environments that are explicitly supported are:
|
|
14
|
+
|
|
15
|
+
- Evergreen browsers which include: Chrome, Safari, Edge, Firefox
|
|
16
|
+
- Node.js active and maintenance LTS releases
|
|
17
|
+
- Currently, this is v18 and v20
|
|
18
|
+
- Bun v1 and above
|
|
19
|
+
- Deno v1.39
|
|
20
|
+
- Note that Deno does not currently have native support for streaming file uploads backed by the filesystem ([issue link][deno-file-streaming])
|
|
21
|
+
|
|
22
|
+
[deno-file-streaming]: https://github.com/denoland/deno/issues/11018
|
|
23
|
+
|
|
24
|
+
## Recommended TypeScript compiler options
|
|
25
|
+
|
|
26
|
+
The following `tsconfig.json` options are recommended for projects using this
|
|
27
|
+
SDK in order to get static type support for features like async iterables,
|
|
28
|
+
streams and `fetch`-related APIs ([`for await...of`][for-await-of],
|
|
29
|
+
[`AbortSignal`][abort-signal], [`Request`][request], [`Response`][response] and
|
|
30
|
+
so on):
|
|
31
|
+
|
|
32
|
+
[for-await-of]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of
|
|
33
|
+
[abort-signal]: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
|
34
|
+
[request]: https://developer.mozilla.org/en-US/docs/Web/API/Request
|
|
35
|
+
[response]: https://developer.mozilla.org/en-US/docs/Web/API/Response
|
|
36
|
+
|
|
37
|
+
```jsonc
|
|
38
|
+
{
|
|
39
|
+
"compilerOptions": {
|
|
40
|
+
"target": "es2020", // or higher
|
|
41
|
+
"lib": ["es2020", "dom", "dom.iterable"]
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
While `target` can be set to older ECMAScript versions, it may result in extra,
|
|
47
|
+
unnecessary compatibility code being generated if you are not targeting old
|
|
48
|
+
runtimes.
|
package/package.json
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atelierlogos/hotcross",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"author": "Speakeasy",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"tshy": {
|
|
7
|
+
"sourceDialects": [
|
|
8
|
+
"hotcross/source"
|
|
9
|
+
],
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./src/index.ts",
|
|
12
|
+
"./package.json": "./package.json",
|
|
13
|
+
"./types": "./src/types/index.ts",
|
|
14
|
+
"./models/errors": "./src/models/errors/index.ts",
|
|
15
|
+
"./models": "./src/models/index.ts",
|
|
16
|
+
"./models/operations": "./src/models/operations/index.ts",
|
|
17
|
+
"./*.js": "./src/*.ts",
|
|
18
|
+
"./*": "./src/*.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"scripts": {
|
|
23
|
+
"lint": "eslint --cache --max-warnings=0 src",
|
|
24
|
+
"build": "tshy",
|
|
25
|
+
"prepublishOnly": "npm run build"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@eslint/js": "^9.19.0",
|
|
30
|
+
"eslint": "^9.19.0",
|
|
31
|
+
"globals": "^15.14.0",
|
|
32
|
+
"tshy": "^2.0.0",
|
|
33
|
+
"typescript": "~5.8.3",
|
|
34
|
+
"typescript-eslint": "^8.26.0"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"zod": "^3.25.65 || ^4.0.0"
|
|
38
|
+
},
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"import": {
|
|
42
|
+
"hotcross/source": "./src/index.ts",
|
|
43
|
+
"types": "./dist/esm/index.d.ts",
|
|
44
|
+
"default": "./dist/esm/index.js"
|
|
45
|
+
},
|
|
46
|
+
"require": {
|
|
47
|
+
"types": "./dist/commonjs/index.d.ts",
|
|
48
|
+
"default": "./dist/commonjs/index.js"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"./package.json": "./package.json",
|
|
52
|
+
"./types": {
|
|
53
|
+
"import": {
|
|
54
|
+
"hotcross/source": "./src/types/index.ts",
|
|
55
|
+
"types": "./dist/esm/types/index.d.ts",
|
|
56
|
+
"default": "./dist/esm/types/index.js"
|
|
57
|
+
},
|
|
58
|
+
"require": {
|
|
59
|
+
"types": "./dist/commonjs/types/index.d.ts",
|
|
60
|
+
"default": "./dist/commonjs/types/index.js"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"./models/errors": {
|
|
64
|
+
"import": {
|
|
65
|
+
"hotcross/source": "./src/models/errors/index.ts",
|
|
66
|
+
"types": "./dist/esm/models/errors/index.d.ts",
|
|
67
|
+
"default": "./dist/esm/models/errors/index.js"
|
|
68
|
+
},
|
|
69
|
+
"require": {
|
|
70
|
+
"types": "./dist/commonjs/models/errors/index.d.ts",
|
|
71
|
+
"default": "./dist/commonjs/models/errors/index.js"
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"./models": {
|
|
75
|
+
"import": {
|
|
76
|
+
"hotcross/source": "./src/models/index.ts",
|
|
77
|
+
"types": "./dist/esm/models/index.d.ts",
|
|
78
|
+
"default": "./dist/esm/models/index.js"
|
|
79
|
+
},
|
|
80
|
+
"require": {
|
|
81
|
+
"types": "./dist/commonjs/models/index.d.ts",
|
|
82
|
+
"default": "./dist/commonjs/models/index.js"
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
"./models/operations": {
|
|
86
|
+
"import": {
|
|
87
|
+
"hotcross/source": "./src/models/operations/index.ts",
|
|
88
|
+
"types": "./dist/esm/models/operations/index.d.ts",
|
|
89
|
+
"default": "./dist/esm/models/operations/index.js"
|
|
90
|
+
},
|
|
91
|
+
"require": {
|
|
92
|
+
"types": "./dist/commonjs/models/operations/index.d.ts",
|
|
93
|
+
"default": "./dist/commonjs/models/operations/index.js"
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
"./*.js": {
|
|
97
|
+
"import": {
|
|
98
|
+
"hotcross/source": "./src/*.ts",
|
|
99
|
+
"types": "./dist/esm/*.d.ts",
|
|
100
|
+
"default": "./dist/esm/*.js"
|
|
101
|
+
},
|
|
102
|
+
"require": {
|
|
103
|
+
"types": "./dist/commonjs/*.d.ts",
|
|
104
|
+
"default": "./dist/commonjs/*.js"
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
"./*": {
|
|
108
|
+
"import": {
|
|
109
|
+
"hotcross/source": "./src/*.ts",
|
|
110
|
+
"types": "./dist/esm/*.d.ts",
|
|
111
|
+
"default": "./dist/esm/*.js"
|
|
112
|
+
},
|
|
113
|
+
"require": {
|
|
114
|
+
"types": "./dist/commonjs/*.d.ts",
|
|
115
|
+
"default": "./dist/commonjs/*.js"
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
"main": "./dist/commonjs/index.js",
|
|
120
|
+
"types": "./dist/commonjs/index.d.ts",
|
|
121
|
+
"module": "./dist/esm/index.js"
|
|
122
|
+
}
|