@withnicer/sdk 0.0.0 → 1.0.0-beta.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.
Files changed (80) hide show
  1. package/README.md +89 -4
  2. package/dist/_/codec.d.ts +93 -0
  3. package/dist/_/codec.js +298 -0
  4. package/dist/_/error.d.ts +27 -0
  5. package/dist/_/error.js +68 -0
  6. package/dist/_/hooks/envelope.d.ts +11 -0
  7. package/dist/_/hooks/envelope.js +15 -0
  8. package/dist/_/index.d.ts +3 -0
  9. package/dist/_/index.js +5 -0
  10. package/dist/_/transport.d.ts +146 -0
  11. package/dist/_/transport.js +220 -0
  12. package/dist/activity/client.d.ts +42 -0
  13. package/dist/activity/client.js +18 -0
  14. package/dist/activity/index.d.ts +5 -0
  15. package/dist/activity/index.js +4 -0
  16. package/dist/activity/models.d.ts +65 -0
  17. package/dist/activity/models.js +3 -0
  18. package/dist/client.d.ts +1680 -0
  19. package/dist/client.js +748 -0
  20. package/dist/crmSettings/client.d.ts +50 -0
  21. package/dist/crmSettings/client.js +25 -0
  22. package/dist/crmSettings/index.d.ts +5 -0
  23. package/dist/crmSettings/index.js +4 -0
  24. package/dist/crmSettings/models.d.ts +313 -0
  25. package/dist/crmSettings/models.js +3 -0
  26. package/dist/crmTrips/client.d.ts +100 -0
  27. package/dist/crmTrips/client.js +38 -0
  28. package/dist/crmTrips/index.d.ts +5 -0
  29. package/dist/crmTrips/index.js +4 -0
  30. package/dist/crmTrips/models.d.ts +193 -0
  31. package/dist/crmTrips/models.js +3 -0
  32. package/dist/crmTrips/travelers/client.d.ts +33 -0
  33. package/dist/crmTrips/travelers/client.js +18 -0
  34. package/dist/crmTrips/travelers/index.d.ts +5 -0
  35. package/dist/crmTrips/travelers/index.js +4 -0
  36. package/dist/crmTrips/travelers/models.d.ts +14 -0
  37. package/dist/crmTrips/travelers/models.js +3 -0
  38. package/dist/index.d.ts +5 -0
  39. package/dist/index.js +4 -0
  40. package/dist/me/client.d.ts +56 -0
  41. package/dist/me/client.js +25 -0
  42. package/dist/me/index.d.ts +5 -0
  43. package/dist/me/index.js +4 -0
  44. package/dist/me/models.d.ts +95 -0
  45. package/dist/me/models.js +3 -0
  46. package/dist/models.d.ts +9269 -0
  47. package/dist/models.js +4 -0
  48. package/dist/notes/client.d.ts +82 -0
  49. package/dist/notes/client.js +41 -0
  50. package/dist/notes/index.d.ts +5 -0
  51. package/dist/notes/index.js +4 -0
  52. package/dist/notes/models.d.ts +116 -0
  53. package/dist/notes/models.js +3 -0
  54. package/dist/options/index.d.ts +52 -0
  55. package/dist/options/index.js +53 -0
  56. package/dist/profileForms/client.d.ts +38 -0
  57. package/dist/profileForms/client.js +25 -0
  58. package/dist/profileForms/index.d.ts +5 -0
  59. package/dist/profileForms/index.js +4 -0
  60. package/dist/profileForms/models.d.ts +24 -0
  61. package/dist/profileForms/models.js +3 -0
  62. package/dist/taskTemplates/client.d.ts +36 -0
  63. package/dist/taskTemplates/client.js +18 -0
  64. package/dist/taskTemplates/index.d.ts +5 -0
  65. package/dist/taskTemplates/index.js +4 -0
  66. package/dist/taskTemplates/models.d.ts +15 -0
  67. package/dist/taskTemplates/models.js +3 -0
  68. package/dist/tasks/client.d.ts +105 -0
  69. package/dist/tasks/client.js +41 -0
  70. package/dist/tasks/index.d.ts +5 -0
  71. package/dist/tasks/index.js +4 -0
  72. package/dist/tasks/models.d.ts +59 -0
  73. package/dist/tasks/models.js +3 -0
  74. package/dist/travelers/client.d.ts +214 -0
  75. package/dist/travelers/client.js +76 -0
  76. package/dist/travelers/index.d.ts +5 -0
  77. package/dist/travelers/index.js +4 -0
  78. package/dist/travelers/models.d.ts +576 -0
  79. package/dist/travelers/models.js +3 -0
  80. package/package.json +35 -2
package/README.md CHANGED
@@ -1,7 +1,92 @@
1
1
  # @withnicer/sdk
2
2
 
3
- The Nicer API for TypeScript and JavaScript.
3
+ The Nicer API for TypeScript and JavaScript: a method for every operation of Nicer's public OpenAPI document, generated by [Cloudflare Forge](https://github.com/cloudflare/forge).
4
4
 
5
- Version 0.0.0 only reserves the package name and contains no code. The first usable version
6
- is generated from Nicer's public OpenAPI document and published from
7
- [withnicer/sdk-js](https://github.com/withnicer/sdk-js).
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install @withnicer/sdk # stable, generated from production's document
9
+ npm install @withnicer/sdk@beta # beta, generated from DEV's document
10
+ ```
11
+
12
+ Pin an exact version, so a build is reproducible and a new client is a reviewed change.
13
+
14
+ ## Use
15
+
16
+ ```ts
17
+ import { ApiError, createClient } from "@withnicer/sdk";
18
+
19
+ const nicer = createClient({
20
+ baseUrl: "https://api.nicer.travel",
21
+ token,
22
+ headers: { "x-nicer-company": company },
23
+ });
24
+
25
+ const traveler = await nicer.travelers.get({
26
+ travelerId,
27
+ expand: "profile,trips",
28
+ });
29
+ const page = await nicer.notes.list({ travelerId, limit: 50 });
30
+ ```
31
+
32
+ A resource can be imported alone, so an app bundles only what it calls:
33
+
34
+ ```ts
35
+ import type { Note, NoteList } from "@withnicer/sdk/notes";
36
+ ```
37
+
38
+ `@withnicer/sdk/options` exports the values of each string enum the document names, as a readonly tuple in the document's order, for a select, a filter or a check: `SalesStage` gives `salesStageOptions`, whose elements are `SalesStage` values. These export names are a proposal and may change before 1.0.0.
39
+
40
+ ```ts
41
+ import { salesStageOptions } from "@withnicer/sdk/options";
42
+ ```
43
+
44
+ ## What it is and is not
45
+
46
+ - **One method per published operation**, under its resource. An operation without a public name is a method of the client itself, named after its `operationId`.
47
+ - **Types and wire conversion, not validation.** An answer whose shape differs from the contract is returned as it is.
48
+ - **No environment inside.** `baseUrl` is required; an app passes the API origin it already resolves. `token` is sent as `Authorization: Bearer <token>`.
49
+ - **A response outside 2XX throws `ApiError`**, with its `status`, the `response` and the decoded body in `details`. A call sends one request and is never retried.
50
+ - **Headers are not in the request types.** The company (`x-nicer-company`) and the idempotency key go in `headers`, on the client or on a call.
51
+ - **Dates are the ISO text the API sends** (`"2027-03-14"`, `"2027-03-14T15:00:00Z"`), typed `string`. Forge would turn them into `Temporal` values, which not every browser has, so the document it reads has no date formats (`scripts/prepare.ts`).
52
+ - **It needs `fetch`.** To type-check against it, TypeScript needs the `dom` library, for the `fetch` types.
53
+
54
+ ## How it is made
55
+
56
+ `src/` is Forge's output, with `src/options/` written from the same document by `scripts/prepare.ts`, and is never edited by hand: a change to the client is a change to the API's contract, deployed, then generated here.
57
+
58
+ The [Generate](.github/workflows/generate.yml) workflow:
59
+
60
+ 1. fetches an environment's live document (`bun run openapi`);
61
+ 2. compares its content hash, the SHA-256 of the document without `info.version`, with the one `package.json` records in `nicer.openapi`, and stops when they are equal;
62
+ 3. otherwise removes `src/`, prepares the document and its option lists and runs `forge generate --target ts` (`bun run generate`), records the document's release and hash, type-checks, builds and commits to the environment's branch;
63
+ 4. starts [Publish](.github/workflows/publish.yml) for that branch, once publishing is on.
64
+
65
+ The backend starts it when a deploy finishes. It also runs every 6 hours for DEV, in case a signal is lost, and can be run by hand.
66
+
67
+ `@cloudflare/forge` is pinned exactly. Before Forge 1.0 a minor version may change the generated code, so raising it is a pull request of its own, where the diff of `src/` is the review.
68
+
69
+ ## Releases
70
+
71
+ Each branch is generated from its own environment's document and publishes its own channel:
72
+
73
+ | Branch | Generated from | Version | npm tag |
74
+ | --- | --- | --- | --- |
75
+ | `main` | `https://api.nicer.travel/openapi.json` | `1.4.0` | `latest` |
76
+ | `dev` | `https://api.dev.nicer.travel/openapi.json` | `1.5.0-beta.3` | `beta` |
77
+
78
+ - **A stable version** is the highest stable one on npm with the minor raised; the first is `1.0.0`.
79
+ - **A beta** is the next minor of the highest stable version, numbered one more than the betas already published for it; the first is `1.0.0-beta.1`.
80
+ - **The workflows only ever raise the minor.** A major version, for a breaking change, is started by a person.
81
+
82
+ Versions are computed by `scripts/release.ts` from what npm already has, when a release is published, and are not committed. Publishing uses npm Trusted Publishing, with no token, and is off until the repository variable `NPM_PUBLISH` is `true`.
83
+
84
+ ## Working on it
85
+
86
+ ```sh
87
+ bun install
88
+ OPENAPI_URL=https://api.dev.nicer.travel/openapi.json bun run openapi
89
+ bun run generate
90
+ bun run check-types
91
+ bun run build
92
+ ```
@@ -0,0 +1,93 @@
1
+ /**
2
+ * A codec converts a value between its wire form, as JSON has it, and its
3
+ * TypeScript form. A value whose shape does not match the codec is kept as
4
+ * it is.
5
+ */
6
+ export interface Codec {
7
+ /**
8
+ * Converts a wire value. `source` is the source text of a number whose
9
+ * value JSON.parse could not hold exactly.
10
+ */
11
+ decode(value: unknown, source?: string): unknown;
12
+ /**
13
+ * Converts a TypeScript value to its wire form.
14
+ */
15
+ encode(value: unknown): unknown;
16
+ }
17
+ /**
18
+ * A codec, or a function that returns one, so codecs can form cycles.
19
+ */
20
+ export type CodecRef = Codec | (() => Codec);
21
+ /**
22
+ * An entry of an object codec: the wire name of a key, its field name when
23
+ * it is renamed, and the codec of its value when the value is converted.
24
+ */
25
+ export type Entry = readonly [wire: string, field: string] | readonly [wire: string, field: string | null, codec: CodecRef];
26
+ type Record = {
27
+ [key: string]: unknown;
28
+ };
29
+ /**
30
+ * Reports whether value is a plain object, as JSON.parse creates them.
31
+ */
32
+ export declare function isRecord(value: unknown): value is Record;
33
+ /**
34
+ * Sets a key of a new object, including one named `__proto__`.
35
+ */
36
+ export declare function set(target: Record, key: string, value: unknown): void;
37
+ /**
38
+ * Parses JSON, and keeps the source text of integers too large for a number,
39
+ * so that `int64` decodes them exactly.
40
+ */
41
+ export declare function parse(text: string): unknown;
42
+ /**
43
+ * Returns the codec of an object, with an entry for each key that is renamed
44
+ * or whose value is converted. Other keys are kept as they are.
45
+ */
46
+ export declare function object(entries: readonly Entry[]): Codec;
47
+ /**
48
+ * Returns the codec of an array, which converts its items.
49
+ */
50
+ export declare function array(items: CodecRef): Codec;
51
+ /**
52
+ * Returns the codec of a map, which converts its values and keeps its keys.
53
+ */
54
+ export declare function map(values: CodecRef): Codec;
55
+ /**
56
+ * Returns the codec of a union. Each member's codec converts the parts of
57
+ * the value it knows, and keeps the rest.
58
+ */
59
+ export declare function union(members: readonly CodecRef[]): Codec;
60
+ /**
61
+ * Returns the codec of an intersection, which converts the value with the
62
+ * codec of each member.
63
+ */
64
+ export declare function intersection(members: readonly CodecRef[]): Codec;
65
+ /**
66
+ * Returns the codec of a union that a property discriminates: the codec of
67
+ * the member that the property's value names. `wire` and `field` are the
68
+ * property's names, with `field` null when it is not renamed.
69
+ */
70
+ export declare function discriminated(wire: string, field: string | null, cases: {
71
+ readonly [value: string]: CodecRef;
72
+ }): Codec;
73
+ /**
74
+ * Converts a `date-time` string and a Temporal.Instant.
75
+ */
76
+ export declare const instant: Codec;
77
+ /**
78
+ * Converts a `date` string and a Temporal.PlainDate.
79
+ */
80
+ export declare const date: Codec;
81
+ /**
82
+ * Returns the base64 encoding of bytes.
83
+ */
84
+ export declare function toBase64(bytes: Uint8Array): string;
85
+ /**
86
+ * Converts a `byte` string, in base64, and a Uint8Array.
87
+ */
88
+ export declare const bytes: Codec;
89
+ /**
90
+ * Converts an `int64` number and a bigint, without losing digits.
91
+ */
92
+ export declare const int64: Codec;
93
+ export {};
@@ -0,0 +1,298 @@
1
+ // Code generated by forge. DO NOT EDIT.
2
+ /* eslint-disable */
3
+ function resolve(ref) {
4
+ return typeof ref === 'function' ? ref() : ref;
5
+ }
6
+ /**
7
+ * Reports whether value is a plain object, as JSON.parse creates them.
8
+ */
9
+ export function isRecord(value) {
10
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
11
+ return false;
12
+ }
13
+ const proto = Object.getPrototypeOf(value);
14
+ return proto === Object.prototype || proto === null;
15
+ }
16
+ /**
17
+ * Sets a key of a new object, including one named `__proto__`.
18
+ */
19
+ export function set(target, key, value) {
20
+ if (key === '__proto__') {
21
+ Object.defineProperty(target, key, {
22
+ value,
23
+ enumerable: true,
24
+ writable: true,
25
+ configurable: true,
26
+ });
27
+ }
28
+ else {
29
+ target[key] = value;
30
+ }
31
+ }
32
+ // The source text of the numbers that JSON.parse could not hold exactly, by
33
+ // the object or array they are in and their key.
34
+ const sources = new WeakMap();
35
+ function sourceOf(holder, key) {
36
+ return sources.get(holder)?.get(key);
37
+ }
38
+ const recordSource = function (key, value, context) {
39
+ const source = context?.source;
40
+ if (typeof value === 'number' && !Number.isSafeInteger(value) && source !== undefined && /^-?\d+$/.test(source)) {
41
+ const holder = this;
42
+ let keys = sources.get(holder);
43
+ if (keys === undefined) {
44
+ keys = new Map();
45
+ sources.set(holder, keys);
46
+ }
47
+ keys.set(key, source);
48
+ }
49
+ return value;
50
+ };
51
+ const parseWithReviver = JSON.parse;
52
+ /**
53
+ * Parses JSON, and keeps the source text of integers too large for a number,
54
+ * so that `int64` decodes them exactly.
55
+ */
56
+ export function parse(text) {
57
+ // An integer that a number cannot hold has at least 16 digits.
58
+ if (!/\d{16}/.test(text)) {
59
+ return JSON.parse(text);
60
+ }
61
+ return parseWithReviver(text, recordSource);
62
+ }
63
+ class ObjectCodec {
64
+ #entries;
65
+ #decodeTable;
66
+ #encodeTable;
67
+ constructor(entries) {
68
+ this.#entries = entries;
69
+ }
70
+ #table(decode) {
71
+ const table = new Map();
72
+ for (const [wire, field, codec] of this.#entries) {
73
+ const resolved = codec === undefined ? undefined : resolve(codec);
74
+ if (decode) {
75
+ table.set(wire, [field ?? wire, resolved]);
76
+ }
77
+ else {
78
+ table.set(field ?? wire, [wire, resolved]);
79
+ }
80
+ }
81
+ return table;
82
+ }
83
+ decode(value) {
84
+ if (!isRecord(value)) {
85
+ return value;
86
+ }
87
+ this.#decodeTable ??= this.#table(true);
88
+ return convert(value, this.#decodeTable, true);
89
+ }
90
+ encode(value) {
91
+ if (!isRecord(value)) {
92
+ return value;
93
+ }
94
+ this.#encodeTable ??= this.#table(false);
95
+ return convert(value, this.#encodeTable, false);
96
+ }
97
+ }
98
+ function convert(value, table, decode) {
99
+ const out = {};
100
+ for (const key of Object.keys(value)) {
101
+ const item = value[key];
102
+ const entry = table.get(key);
103
+ if (entry === undefined) {
104
+ set(out, key, item);
105
+ continue;
106
+ }
107
+ const [name, codec] = entry;
108
+ if (codec === undefined || item === undefined || item === null) {
109
+ set(out, name, item);
110
+ }
111
+ else if (decode) {
112
+ set(out, name, codec.decode(item, sourceOf(value, key)));
113
+ }
114
+ else {
115
+ set(out, name, codec.encode(item));
116
+ }
117
+ }
118
+ return out;
119
+ }
120
+ /**
121
+ * Returns the codec of an object, with an entry for each key that is renamed
122
+ * or whose value is converted. Other keys are kept as they are.
123
+ */
124
+ export function object(entries) {
125
+ return new ObjectCodec(entries);
126
+ }
127
+ /**
128
+ * Returns the codec of an array, which converts its items.
129
+ */
130
+ export function array(items) {
131
+ return {
132
+ decode(value) {
133
+ if (!Array.isArray(value)) {
134
+ return value;
135
+ }
136
+ const codec = resolve(items);
137
+ return value.map((item, i) => (item === null ? item : codec.decode(item, sourceOf(value, String(i)))));
138
+ },
139
+ encode(value) {
140
+ if (!Array.isArray(value)) {
141
+ return value;
142
+ }
143
+ const codec = resolve(items);
144
+ return value.map((item) => (item === null || item === undefined ? item : codec.encode(item)));
145
+ },
146
+ };
147
+ }
148
+ /**
149
+ * Returns the codec of a map, which converts its values and keeps its keys.
150
+ */
151
+ export function map(values) {
152
+ return {
153
+ decode(value) {
154
+ if (!isRecord(value)) {
155
+ return value;
156
+ }
157
+ const codec = resolve(values);
158
+ const out = {};
159
+ for (const key of Object.keys(value)) {
160
+ const item = value[key];
161
+ set(out, key, item === null ? item : codec.decode(item, sourceOf(value, key)));
162
+ }
163
+ return out;
164
+ },
165
+ encode(value) {
166
+ if (!isRecord(value)) {
167
+ return value;
168
+ }
169
+ const codec = resolve(values);
170
+ const out = {};
171
+ for (const key of Object.keys(value)) {
172
+ const item = value[key];
173
+ set(out, key, item === null || item === undefined ? item : codec.encode(item));
174
+ }
175
+ return out;
176
+ },
177
+ };
178
+ }
179
+ function every(members) {
180
+ return {
181
+ decode(value, source) {
182
+ for (const member of members) {
183
+ value = resolve(member).decode(value, source);
184
+ }
185
+ return value;
186
+ },
187
+ encode(value) {
188
+ for (const member of members) {
189
+ value = resolve(member).encode(value);
190
+ }
191
+ return value;
192
+ },
193
+ };
194
+ }
195
+ /**
196
+ * Returns the codec of a union. Each member's codec converts the parts of
197
+ * the value it knows, and keeps the rest.
198
+ */
199
+ export function union(members) {
200
+ return every(members);
201
+ }
202
+ /**
203
+ * Returns the codec of an intersection, which converts the value with the
204
+ * codec of each member.
205
+ */
206
+ export function intersection(members) {
207
+ return every(members);
208
+ }
209
+ /**
210
+ * Returns the codec of a union that a property discriminates: the codec of
211
+ * the member that the property's value names. `wire` and `field` are the
212
+ * property's names, with `field` null when it is not renamed.
213
+ */
214
+ export function discriminated(wire, field, cases) {
215
+ const pick = (value) => {
216
+ const key = String(value);
217
+ return Object.hasOwn(cases, key) ? resolve(cases[key]) : undefined;
218
+ };
219
+ return {
220
+ decode(value, source) {
221
+ if (!isRecord(value)) {
222
+ return value;
223
+ }
224
+ const codec = pick(value[wire]);
225
+ return codec === undefined ? value : codec.decode(value, source);
226
+ },
227
+ encode(value) {
228
+ if (!isRecord(value)) {
229
+ return value;
230
+ }
231
+ const codec = pick(value[field ?? wire]);
232
+ return codec === undefined ? value : codec.encode(value);
233
+ },
234
+ };
235
+ }
236
+ // attempt returns the result of fn, or fallback when the value is not in the
237
+ // form fn expects. A missing global, such as Temporal, is still thrown.
238
+ function attempt(fn, fallback) {
239
+ try {
240
+ return fn();
241
+ }
242
+ catch (e) {
243
+ if (e instanceof ReferenceError) {
244
+ throw e;
245
+ }
246
+ return fallback;
247
+ }
248
+ }
249
+ function toText(value) {
250
+ return typeof value === 'object' && value !== null ? String(value) : value;
251
+ }
252
+ /**
253
+ * Converts a `date-time` string and a Temporal.Instant.
254
+ */
255
+ export const instant = {
256
+ decode: (value) => (typeof value === 'string' ? attempt(() => Temporal.Instant.from(value), value) : value),
257
+ encode: toText,
258
+ };
259
+ /**
260
+ * Converts a `date` string and a Temporal.PlainDate.
261
+ */
262
+ export const date = {
263
+ decode: (value) => (typeof value === 'string' ? attempt(() => Temporal.PlainDate.from(value), value) : value),
264
+ encode: toText,
265
+ };
266
+ /**
267
+ * Returns the base64 encoding of bytes.
268
+ */
269
+ export function toBase64(bytes) {
270
+ let binary = '';
271
+ for (let i = 0; i < bytes.length; i += 0x8000) {
272
+ binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
273
+ }
274
+ return btoa(binary);
275
+ }
276
+ function fromBase64(text) {
277
+ const binary = atob(text);
278
+ const bytes = new Uint8Array(binary.length);
279
+ for (let i = 0; i < binary.length; i++) {
280
+ bytes[i] = binary.charCodeAt(i);
281
+ }
282
+ return bytes;
283
+ }
284
+ /**
285
+ * Converts a `byte` string, in base64, and a Uint8Array.
286
+ */
287
+ export const bytes = {
288
+ decode: (value) => (typeof value === 'string' ? attempt(() => fromBase64(value), value) : value),
289
+ encode: (value) => (value instanceof Uint8Array ? toBase64(value) : value),
290
+ };
291
+ const rawJSON = JSON.rawJSON;
292
+ /**
293
+ * Converts an `int64` number and a bigint, without losing digits.
294
+ */
295
+ export const int64 = {
296
+ decode: (value, source) => (typeof value === 'number' && Number.isInteger(value) ? BigInt(source ?? value) : value),
297
+ encode: (value) => (typeof value === 'bigint' ? rawJSON(value.toString()) : value),
298
+ };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * An error response from the API, or a success response whose body is not
3
+ * valid JSON.
4
+ */
5
+ export declare class ApiError extends Error {
6
+ /**
7
+ * The status of the response.
8
+ */
9
+ readonly status: number;
10
+ /**
11
+ * The response, whose body has been read.
12
+ */
13
+ readonly response: Response;
14
+ /**
15
+ * The body decoded as the error the API declares for the status, or the
16
+ * body as text when it declares none or the body does not parse, or
17
+ * undefined when the body is empty.
18
+ */
19
+ readonly details: unknown;
20
+ constructor(message: string, response: Response, details: unknown, options?: ErrorOptions);
21
+ }
22
+ /**
23
+ * Returns the message of a JSON error body: a string `message`, `error`,
24
+ * `detail` or `title`, then `error.message` or `error.detail`, then the
25
+ * messages of an `errors` array.
26
+ */
27
+ export declare function errorMessage(body: unknown): string | undefined;
@@ -0,0 +1,68 @@
1
+ // Code generated by forge. DO NOT EDIT.
2
+ /* eslint-disable */
3
+ import { isRecord } from './codec.js';
4
+ /**
5
+ * An error response from the API, or a success response whose body is not
6
+ * valid JSON.
7
+ */
8
+ export class ApiError extends Error {
9
+ /**
10
+ * The status of the response.
11
+ */
12
+ status;
13
+ /**
14
+ * The response, whose body has been read.
15
+ */
16
+ response;
17
+ /**
18
+ * The body decoded as the error the API declares for the status, or the
19
+ * body as text when it declares none or the body does not parse, or
20
+ * undefined when the body is empty.
21
+ */
22
+ details;
23
+ constructor(message, response, details, options) {
24
+ super(message, options);
25
+ this.name = 'ApiError';
26
+ this.status = response.status;
27
+ this.response = response;
28
+ this.details = details;
29
+ }
30
+ }
31
+ function text(value) {
32
+ return typeof value === 'string' && value !== '' ? value : undefined;
33
+ }
34
+ /**
35
+ * Returns the message of a JSON error body: a string `message`, `error`,
36
+ * `detail` or `title`, then `error.message` or `error.detail`, then the
37
+ * messages of an `errors` array.
38
+ */
39
+ export function errorMessage(body) {
40
+ if (!isRecord(body)) {
41
+ return undefined;
42
+ }
43
+ const message = text(body['message']) ?? text(body['error']) ?? text(body['detail']) ?? text(body['title']);
44
+ if (message !== undefined) {
45
+ return message;
46
+ }
47
+ const error = body['error'];
48
+ if (isRecord(error)) {
49
+ const nested = text(error['message']) ?? text(error['detail']);
50
+ if (nested !== undefined) {
51
+ return nested;
52
+ }
53
+ }
54
+ const errors = body['errors'];
55
+ if (Array.isArray(errors)) {
56
+ const messages = [];
57
+ for (const item of errors) {
58
+ const m = isRecord(item) ? text(item['message']) : text(item);
59
+ if (m !== undefined) {
60
+ messages.push(m);
61
+ }
62
+ }
63
+ if (messages.length > 0) {
64
+ return messages.join('; ');
65
+ }
66
+ }
67
+ return undefined;
68
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Returns the body a client decodes from a success response, given the
3
+ * response and its JSON body. It runs for every 2XX response with a JSON
4
+ * body, before the body is decoded or paginated.
5
+ *
6
+ * This implementation returns the body as it is. An SDK whose API wraps its
7
+ * payloads in an envelope can replace this file in the generated `_/hooks/`
8
+ * directory with one that returns the part of the envelope that the
9
+ * description declares.
10
+ */
11
+ export declare function unwrapEnvelope(_response: Response, body: unknown): unknown;
@@ -0,0 +1,15 @@
1
+ // Code generated by forge. DO NOT EDIT.
2
+ /* eslint-disable */
3
+ /**
4
+ * Returns the body a client decodes from a success response, given the
5
+ * response and its JSON body. It runs for every 2XX response with a JSON
6
+ * body, before the body is decoded or paginated.
7
+ *
8
+ * This implementation returns the body as it is. An SDK whose API wraps its
9
+ * payloads in an envelope can replace this file in the generated `_/hooks/`
10
+ * directory with one that returns the part of the envelope that the
11
+ * description declares.
12
+ */
13
+ export function unwrapEnvelope(_response, body) {
14
+ return body;
15
+ }
@@ -0,0 +1,3 @@
1
+ export { array, bytes, type Codec, type CodecRef, date, discriminated, type Entry, instant, int64, intersection, map, object, union, } from './codec.js';
2
+ export { ApiError } from './error.js';
3
+ export { type BaseClientOptions, type Operation, type Pagination, type RequestOptions, Transport, } from './transport.js';
@@ -0,0 +1,5 @@
1
+ // Code generated by forge. DO NOT EDIT.
2
+ /* eslint-disable */
3
+ export { array, bytes, date, discriminated, instant, int64, intersection, map, object, union, } from './codec.js';
4
+ export { ApiError } from './error.js';
5
+ export { Transport, } from './transport.js';