@orq-ai/node 3.1.6 → 3.2.0-rc.3

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 (165) hide show
  1. package/README.md +0 -38
  2. package/docs/sdks/deployments/README.md +0 -81
  3. package/jsr.json +1 -2
  4. package/lib/config.d.ts +2 -2
  5. package/lib/config.js +2 -2
  6. package/lib/config.js.map +1 -1
  7. package/lib/matchers.d.ts.map +1 -1
  8. package/lib/matchers.js +1 -4
  9. package/lib/matchers.js.map +1 -1
  10. package/models/operations/createcontact.js +2 -2
  11. package/models/operations/fileget.js +2 -2
  12. package/models/operations/filelist.js +2 -2
  13. package/models/operations/fileupload.js +2 -2
  14. package/models/operations/index.d.ts +0 -1
  15. package/models/operations/index.d.ts.map +1 -1
  16. package/models/operations/index.js +0 -1
  17. package/models/operations/index.js.map +1 -1
  18. package/package.json +3 -2
  19. package/sdk/deployments.d.ts +0 -8
  20. package/sdk/deployments.d.ts.map +1 -1
  21. package/sdk/deployments.js +0 -10
  22. package/sdk/deployments.js.map +1 -1
  23. package/src/lib/config.ts +2 -2
  24. package/src/lib/matchers.ts +1 -4
  25. package/src/models/operations/createcontact.ts +2 -2
  26. package/src/models/operations/fileget.ts +2 -2
  27. package/src/models/operations/filelist.ts +2 -2
  28. package/src/models/operations/fileupload.ts +2 -2
  29. package/src/models/operations/index.ts +0 -1
  30. package/src/sdk/deployments.ts +0 -19
  31. package/funcs/deploymentsStream.d.ts +0 -16
  32. package/funcs/deploymentsStream.d.ts.map +0 -1
  33. package/funcs/deploymentsStream.js +0 -126
  34. package/funcs/deploymentsStream.js.map +0 -1
  35. package/lib/event-streams.d.ts +0 -17
  36. package/lib/event-streams.d.ts.map +0 -1
  37. package/lib/event-streams.js +0 -220
  38. package/lib/event-streams.js.map +0 -1
  39. package/models/operations/deploymentstream.d.ts +0 -1622
  40. package/models/operations/deploymentstream.d.ts.map +0 -1
  41. package/models/operations/deploymentstream.js +0 -1571
  42. package/models/operations/deploymentstream.js.map +0 -1
  43. package/packages/orq-rc/FUNCTIONS.md +0 -106
  44. package/packages/orq-rc/README.md +0 -559
  45. package/packages/orq-rc/RUNTIMES.md +0 -48
  46. package/packages/orq-rc/docs/sdks/contacts/README.md +0 -84
  47. package/packages/orq-rc/docs/sdks/deployments/README.md +0 -316
  48. package/packages/orq-rc/docs/sdks/feedback/README.md +0 -92
  49. package/packages/orq-rc/docs/sdks/files/README.md +0 -305
  50. package/packages/orq-rc/docs/sdks/metrics/README.md +0 -86
  51. package/packages/orq-rc/docs/sdks/orq/README.md +0 -10
  52. package/packages/orq-rc/docs/sdks/prompts/README.md +0 -608
  53. package/packages/orq-rc/docs/sdks/promptsnippets/README.md +0 -534
  54. package/packages/orq-rc/docs/sdks/remoteconfig/README.md +0 -80
  55. package/packages/orq-rc/jsr.json +0 -28
  56. package/packages/orq-rc/package-lock.json +0 -1861
  57. package/packages/orq-rc/package.json +0 -31
  58. package/packages/orq-rc/src/core.ts +0 -13
  59. package/packages/orq-rc/src/funcs/contactsCreate.ts +0 -126
  60. package/packages/orq-rc/src/funcs/deploymentsGetConfig.ts +0 -134
  61. package/packages/orq-rc/src/funcs/deploymentsInvoke.ts +0 -142
  62. package/packages/orq-rc/src/funcs/deploymentsList.ts +0 -141
  63. package/packages/orq-rc/src/funcs/deploymentsMetricsCreate.ts +0 -134
  64. package/packages/orq-rc/src/funcs/deploymentsStream.ts +0 -150
  65. package/packages/orq-rc/src/funcs/feedbackCreate.ts +0 -126
  66. package/packages/orq-rc/src/funcs/filesDelete.ts +0 -130
  67. package/packages/orq-rc/src/funcs/filesGet.ts +0 -129
  68. package/packages/orq-rc/src/funcs/filesList.ts +0 -131
  69. package/packages/orq-rc/src/funcs/filesUpload.ts +0 -149
  70. package/packages/orq-rc/src/funcs/promptSnippetsCreate.ts +0 -128
  71. package/packages/orq-rc/src/funcs/promptSnippetsDelete.ts +0 -131
  72. package/packages/orq-rc/src/funcs/promptSnippetsGet.ts +0 -130
  73. package/packages/orq-rc/src/funcs/promptSnippetsGetByKey.ts +0 -132
  74. package/packages/orq-rc/src/funcs/promptSnippetsList.ts +0 -132
  75. package/packages/orq-rc/src/funcs/promptSnippetsUpdate.ts +0 -139
  76. package/packages/orq-rc/src/funcs/promptsCreate.ts +0 -126
  77. package/packages/orq-rc/src/funcs/promptsDelete.ts +0 -130
  78. package/packages/orq-rc/src/funcs/promptsGetVersion.ts +0 -146
  79. package/packages/orq-rc/src/funcs/promptsList.ts +0 -133
  80. package/packages/orq-rc/src/funcs/promptsListVersions.ts +0 -139
  81. package/packages/orq-rc/src/funcs/promptsRetrieve.ts +0 -132
  82. package/packages/orq-rc/src/funcs/promptsUpdate.ts +0 -138
  83. package/packages/orq-rc/src/funcs/remoteconfigGetConfig.ts +0 -127
  84. package/packages/orq-rc/src/hooks/global.ts +0 -44
  85. package/packages/orq-rc/src/hooks/hooks.ts +0 -132
  86. package/packages/orq-rc/src/hooks/index.ts +0 -6
  87. package/packages/orq-rc/src/hooks/registration.ts +0 -15
  88. package/packages/orq-rc/src/hooks/types.ts +0 -109
  89. package/packages/orq-rc/src/index.ts +0 -7
  90. package/packages/orq-rc/src/lib/base64.ts +0 -37
  91. package/packages/orq-rc/src/lib/config.ts +0 -70
  92. package/packages/orq-rc/src/lib/dlv.ts +0 -53
  93. package/packages/orq-rc/src/lib/encodings.ts +0 -483
  94. package/packages/orq-rc/src/lib/env.ts +0 -73
  95. package/packages/orq-rc/src/lib/event-streams.ts +0 -264
  96. package/packages/orq-rc/src/lib/files.ts +0 -40
  97. package/packages/orq-rc/src/lib/http.ts +0 -323
  98. package/packages/orq-rc/src/lib/is-plain-object.ts +0 -43
  99. package/packages/orq-rc/src/lib/logger.ts +0 -9
  100. package/packages/orq-rc/src/lib/matchers.ts +0 -325
  101. package/packages/orq-rc/src/lib/primitives.ts +0 -136
  102. package/packages/orq-rc/src/lib/retries.ts +0 -218
  103. package/packages/orq-rc/src/lib/schemas.ts +0 -91
  104. package/packages/orq-rc/src/lib/sdks.ts +0 -400
  105. package/packages/orq-rc/src/lib/security.ts +0 -254
  106. package/packages/orq-rc/src/lib/url.ts +0 -33
  107. package/packages/orq-rc/src/models/components/deployments.ts +0 -1666
  108. package/packages/orq-rc/src/models/components/index.ts +0 -6
  109. package/packages/orq-rc/src/models/components/security.ts +0 -71
  110. package/packages/orq-rc/src/models/errors/apierror.ts +0 -27
  111. package/packages/orq-rc/src/models/errors/getpromptversion.ts +0 -71
  112. package/packages/orq-rc/src/models/errors/honoapierror.ts +0 -82
  113. package/packages/orq-rc/src/models/errors/httpclienterrors.ts +0 -62
  114. package/packages/orq-rc/src/models/errors/index.ts +0 -11
  115. package/packages/orq-rc/src/models/errors/sdkvalidationerror.ts +0 -97
  116. package/packages/orq-rc/src/models/errors/updateprompt.ts +0 -71
  117. package/packages/orq-rc/src/models/errors/updatepromptsnippet.ts +0 -71
  118. package/packages/orq-rc/src/models/operations/createcontact.ts +0 -256
  119. package/packages/orq-rc/src/models/operations/createfeedback.ts +0 -286
  120. package/packages/orq-rc/src/models/operations/createprompt.ts +0 -3819
  121. package/packages/orq-rc/src/models/operations/createpromptsnippet.ts +0 -6239
  122. package/packages/orq-rc/src/models/operations/deleteprompt.ts +0 -69
  123. package/packages/orq-rc/src/models/operations/deletepromptsnippet.ts +0 -69
  124. package/packages/orq-rc/src/models/operations/deploymentcreatemetric.ts +0 -1790
  125. package/packages/orq-rc/src/models/operations/deploymentgetconfig.ts +0 -3527
  126. package/packages/orq-rc/src/models/operations/deploymentinvoke.ts +0 -1144
  127. package/packages/orq-rc/src/models/operations/deployments.ts +0 -2148
  128. package/packages/orq-rc/src/models/operations/deploymentstream.ts +0 -3062
  129. package/packages/orq-rc/src/models/operations/filedelete.ts +0 -78
  130. package/packages/orq-rc/src/models/operations/fileget.ts +0 -222
  131. package/packages/orq-rc/src/models/operations/filelist.ts +0 -321
  132. package/packages/orq-rc/src/models/operations/fileupload.ts +0 -322
  133. package/packages/orq-rc/src/models/operations/findonebykeypromptsnippet.ts +0 -4483
  134. package/packages/orq-rc/src/models/operations/findonepromptsnippet.ts +0 -4343
  135. package/packages/orq-rc/src/models/operations/getallprompts.ts +0 -2116
  136. package/packages/orq-rc/src/models/operations/getallpromptsnippets.ts +0 -4472
  137. package/packages/orq-rc/src/models/operations/getoneprompt.ts +0 -1982
  138. package/packages/orq-rc/src/models/operations/getpromptversion.ts +0 -2012
  139. package/packages/orq-rc/src/models/operations/index.ts +0 -29
  140. package/packages/orq-rc/src/models/operations/listpromptversions.ts +0 -2146
  141. package/packages/orq-rc/src/models/operations/remoteconfigsgetconfig.ts +0 -190
  142. package/packages/orq-rc/src/models/operations/updateprompt.ts +0 -3917
  143. package/packages/orq-rc/src/models/operations/updatepromptsnippet.ts +0 -6544
  144. package/packages/orq-rc/src/sdk/contacts.ts +0 -27
  145. package/packages/orq-rc/src/sdk/deployments.ts +0 -89
  146. package/packages/orq-rc/src/sdk/feedback.ts +0 -27
  147. package/packages/orq-rc/src/sdk/files.ts +0 -72
  148. package/packages/orq-rc/src/sdk/index.ts +0 -5
  149. package/packages/orq-rc/src/sdk/metrics.ts +0 -27
  150. package/packages/orq-rc/src/sdk/prompts.ts +0 -126
  151. package/packages/orq-rc/src/sdk/promptsnippets.ts +0 -99
  152. package/packages/orq-rc/src/sdk/remoteconfig.ts +0 -24
  153. package/packages/orq-rc/src/sdk/sdk.ts +0 -49
  154. package/packages/orq-rc/src/types/blobs.ts +0 -31
  155. package/packages/orq-rc/src/types/constdatetime.ts +0 -15
  156. package/packages/orq-rc/src/types/enums.ts +0 -16
  157. package/packages/orq-rc/src/types/fp.ts +0 -50
  158. package/packages/orq-rc/src/types/index.ts +0 -11
  159. package/packages/orq-rc/src/types/operations.ts +0 -105
  160. package/packages/orq-rc/src/types/rfcdate.ts +0 -54
  161. package/packages/orq-rc/src/types/streams.ts +0 -21
  162. package/packages/orq-rc/tsconfig.json +0 -41
  163. package/src/funcs/deploymentsStream.ts +0 -151
  164. package/src/lib/event-streams.ts +0 -264
  165. package/src/models/operations/deploymentstream.ts +0 -3062
@@ -1,264 +0,0 @@
1
- /*
2
- * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
- */
4
-
5
- export type ServerEvent<T> = {
6
- data?: T | undefined;
7
- event?: string | undefined;
8
- retry?: number | undefined;
9
- id?: string | undefined;
10
- };
11
- const LF = 0x0a;
12
- const CR = 0x0d;
13
- const NEWLINE_CHARS = new Set([LF, CR]);
14
- const MESSAGE_BOUNDARIES = [
15
- new Uint8Array([CR, LF, CR, LF]),
16
- new Uint8Array([CR, CR]),
17
- new Uint8Array([LF, LF]),
18
- ];
19
-
20
- export class EventStream<Event extends ServerEvent<unknown>> {
21
- private readonly stream: ReadableStream<Uint8Array>;
22
- private readonly decoder: (rawEvent: ServerEvent<string>) => Event;
23
-
24
- constructor(init: {
25
- stream: ReadableStream<Uint8Array>;
26
- decoder: (rawEvent: ServerEvent<string>) => Event;
27
- }) {
28
- this.stream = init.stream;
29
- this.decoder = init.decoder;
30
- }
31
-
32
- async *[Symbol.asyncIterator](): AsyncGenerator<Event, void, unknown> {
33
- const reader = this.stream.getReader();
34
- let buffer = new Uint8Array([]);
35
- let position = 0;
36
-
37
- try {
38
- while (true) {
39
- const { done, value } = await reader.read();
40
- if (done) {
41
- break;
42
- }
43
-
44
- const newBuffer = new Uint8Array(buffer.length + value.length);
45
- newBuffer.set(buffer);
46
- newBuffer.set(value, buffer.length);
47
- buffer = newBuffer;
48
-
49
- for (let i = position; i < buffer.length; i++) {
50
- const boundary = findBoundary(buffer, i);
51
- if (boundary == null) {
52
- continue;
53
- }
54
-
55
- const chunk = buffer.slice(position, i);
56
- position = i + boundary.length;
57
- const event = parseEvent(chunk, this.decoder);
58
- if (event != null) {
59
- yield event;
60
- }
61
- }
62
-
63
- if (position > 0) {
64
- buffer = buffer.slice(position);
65
- position = 0;
66
- }
67
- }
68
-
69
- if (buffer.length > 0) {
70
- const event = parseEvent(buffer, this.decoder);
71
- if (event != null) {
72
- yield event;
73
- }
74
- }
75
- } catch (e: unknown) {
76
- if (e instanceof Error && e.name === "AbortError") {
77
- return;
78
- }
79
-
80
- throw e;
81
- } finally {
82
- reader.releaseLock();
83
- }
84
- }
85
- }
86
-
87
- function findBoundary(buffer: Uint8Array, start: number): Uint8Array | null {
88
- const char1 = buffer[start];
89
- const char2 = buffer[start + 1];
90
-
91
- // Don't bother checking if the first two characters are not new line
92
- // characters.
93
- if (
94
- char1 == null
95
- || char2 == null
96
- || !NEWLINE_CHARS.has(char1)
97
- || !NEWLINE_CHARS.has(char2)
98
- ) {
99
- return null;
100
- }
101
-
102
- for (const s of MESSAGE_BOUNDARIES) {
103
- const seq = peekSequence(start, buffer, s);
104
- if (seq != null) {
105
- return seq;
106
- }
107
- }
108
-
109
- return null;
110
- }
111
-
112
- function peekSequence(
113
- position: number,
114
- buffer: Uint8Array,
115
- sequence: Uint8Array,
116
- ): Uint8Array | null {
117
- if (sequence.length > buffer.length - position) {
118
- return null;
119
- }
120
-
121
- for (let i = 0; i < sequence.length; i++) {
122
- if (buffer[position + i] !== sequence[i]) {
123
- return null;
124
- }
125
- }
126
-
127
- return sequence;
128
- }
129
-
130
- function parseEvent<Event extends ServerEvent<unknown>>(
131
- chunk: Uint8Array,
132
- decoder: (rawEvent: ServerEvent<string>) => Event,
133
- ) {
134
- if (!chunk.length) {
135
- return null;
136
- }
137
-
138
- const td = new TextDecoder();
139
- const raw = td.decode(chunk);
140
- const lines = raw.split(/\r?\n|\r/g);
141
- let publish = false;
142
- const rawEvent: ServerEvent<string> = {};
143
-
144
- for (const line of lines) {
145
- if (!line) {
146
- continue;
147
- }
148
-
149
- const delim = line.indexOf(":");
150
- // Lines starting with a colon are ignored.
151
- if (delim === 0) {
152
- continue;
153
- }
154
-
155
- const field = delim > 0 ? line.substring(0, delim) : "";
156
- let value = delim > 0 ? line.substring(delim + 1) : "";
157
- if (value.charAt(0) === " ") {
158
- value = value.substring(1);
159
- }
160
-
161
- switch (field) {
162
- case "event": {
163
- publish = true;
164
- rawEvent.event = value;
165
- break;
166
- }
167
- case "data": {
168
- publish = true;
169
- rawEvent.data ??= "";
170
- rawEvent.data += value + "\n";
171
- break;
172
- }
173
- case "id": {
174
- publish = true;
175
- rawEvent.id = value;
176
- break;
177
- }
178
- case "retry": {
179
- const r = parseInt(value, 10);
180
- if (!Number.isNaN(r)) {
181
- publish = true;
182
- rawEvent.retry = r;
183
- }
184
- break;
185
- }
186
- }
187
- }
188
-
189
- if (!publish) {
190
- return null;
191
- }
192
-
193
- if (rawEvent.data != null) {
194
- rawEvent.data = rawEvent.data.slice(0, -1);
195
- }
196
-
197
- return decoder(rawEvent);
198
- }
199
-
200
- export function discardSentinel(
201
- stream: ReadableStream<Uint8Array>,
202
- sentinel: string,
203
- ): ReadableStream<Uint8Array> {
204
- return new ReadableStream<Uint8Array>({
205
- async start(controller) {
206
- let buffer = new Uint8Array([]);
207
- let position = 0;
208
- let done = false;
209
- let discard = false;
210
- const rdr = stream.getReader();
211
- try {
212
- while (!done) {
213
- const result = await rdr.read();
214
- const value = result.value;
215
- done = done || result.done;
216
- // We keep consuming from the source to its completion so it can
217
- // flush all its contents and release resources.
218
- if (discard) {
219
- continue;
220
- }
221
- if (typeof value === "undefined") {
222
- continue;
223
- }
224
-
225
- const newBuffer = new Uint8Array(buffer.length + value.length);
226
- newBuffer.set(buffer);
227
- newBuffer.set(value, buffer.length);
228
- buffer = newBuffer;
229
-
230
- for (let i = position; i < buffer.length; i++) {
231
- const boundary = findBoundary(buffer, i);
232
- if (boundary == null) {
233
- continue;
234
- }
235
-
236
- const start = position;
237
- const chunk = buffer.slice(start, i);
238
- position = i + boundary.length;
239
- const event = parseEvent(chunk, id);
240
- if (event?.data === sentinel) {
241
- controller.enqueue(buffer.slice(0, start));
242
- discard = true;
243
- } else {
244
- controller.enqueue(buffer.slice(0, position));
245
- buffer = buffer.slice(position);
246
- position = 0;
247
- }
248
- }
249
- }
250
- } catch (e) {
251
- controller.error(e);
252
- } finally {
253
- // If the source stream terminates, flush its contents and terminate.
254
- // If the sentinel event was found, flush everything up to its start.
255
- controller.close();
256
- rdr.releaseLock();
257
- }
258
- },
259
- });
260
- }
261
-
262
- function id<T>(v: T): T {
263
- return v;
264
- }
@@ -1,40 +0,0 @@
1
- /*
2
- * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
- */
4
-
5
- /**
6
- * Consumes a stream and returns a concatenated array buffer. Useful in
7
- * situations where we need to read the whole file because it forms part of a
8
- * larger payload containing other fields, and we can't modify the underlying
9
- * request structure.
10
- */
11
- export async function readableStreamToArrayBuffer(
12
- readable: ReadableStream<Uint8Array>,
13
- ): Promise<ArrayBuffer> {
14
- const reader = readable.getReader();
15
- const chunks: Uint8Array[] = [];
16
-
17
- let totalLength = 0;
18
- let done = false;
19
-
20
- while (!done) {
21
- const { value, done: doneReading } = await reader.read();
22
-
23
- if (doneReading) {
24
- done = true;
25
- } else {
26
- chunks.push(value);
27
- totalLength += value.length;
28
- }
29
- }
30
-
31
- const concatenatedChunks = new Uint8Array(totalLength);
32
- let offset = 0;
33
-
34
- for (const chunk of chunks) {
35
- concatenatedChunks.set(chunk, offset);
36
- offset += chunk.length;
37
- }
38
-
39
- return concatenatedChunks.buffer;
40
- }
@@ -1,323 +0,0 @@
1
- /*
2
- * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
- */
4
-
5
- export type Fetcher = (
6
- input: RequestInfo | URL,
7
- init?: RequestInit,
8
- ) => Promise<Response>;
9
-
10
- export type Awaitable<T> = T | Promise<T>;
11
-
12
- const DEFAULT_FETCHER: Fetcher = (input, init) => {
13
- // If input is a Request and init is undefined, Bun will discard the method,
14
- // headers, body and other options that were set on the request object.
15
- // Node.js and browers would ignore an undefined init value. This check is
16
- // therefore needed for interop with Bun.
17
- if (init == null) {
18
- return fetch(input);
19
- } else {
20
- return fetch(input, init);
21
- }
22
- };
23
-
24
- export type RequestInput = {
25
- /**
26
- * The URL the request will use.
27
- */
28
- url: URL;
29
- /**
30
- * Options used to create a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request).
31
- */
32
- options?: RequestInit | undefined;
33
- };
34
-
35
- export interface HTTPClientOptions {
36
- fetcher?: Fetcher;
37
- }
38
-
39
- export type BeforeRequestHook = (req: Request) => Awaitable<Request | void>;
40
- export type RequestErrorHook = (err: unknown, req: Request) => Awaitable<void>;
41
- export type ResponseHook = (res: Response, req: Request) => Awaitable<void>;
42
-
43
- export class HTTPClient {
44
- private fetcher: Fetcher;
45
- private requestHooks: BeforeRequestHook[] = [];
46
- private requestErrorHooks: RequestErrorHook[] = [];
47
- private responseHooks: ResponseHook[] = [];
48
-
49
- constructor(private options: HTTPClientOptions = {}) {
50
- this.fetcher = options.fetcher || DEFAULT_FETCHER;
51
- }
52
-
53
- async request(request: Request): Promise<Response> {
54
- let req = request;
55
- for (const hook of this.requestHooks) {
56
- const nextRequest = await hook(req);
57
- if (nextRequest) {
58
- req = nextRequest;
59
- }
60
- }
61
-
62
- try {
63
- const res = await this.fetcher(req);
64
-
65
- for (const hook of this.responseHooks) {
66
- await hook(res, req);
67
- }
68
-
69
- return res;
70
- } catch (err) {
71
- for (const hook of this.requestErrorHooks) {
72
- await hook(err, req);
73
- }
74
-
75
- throw err;
76
- }
77
- }
78
-
79
- /**
80
- * Registers a hook that is called before a request is made. The hook function
81
- * can mutate the request or return a new request. This may be useful to add
82
- * additional information to request such as request IDs and tracing headers.
83
- */
84
- addHook(hook: "beforeRequest", fn: BeforeRequestHook): this;
85
- /**
86
- * Registers a hook that is called when a request cannot be made due to a
87
- * network error.
88
- */
89
- addHook(hook: "requestError", fn: RequestErrorHook): this;
90
- /**
91
- * Registers a hook that is called when a response has been received from the
92
- * server.
93
- */
94
- addHook(hook: "response", fn: ResponseHook): this;
95
- addHook(
96
- ...args:
97
- | [hook: "beforeRequest", fn: BeforeRequestHook]
98
- | [hook: "requestError", fn: RequestErrorHook]
99
- | [hook: "response", fn: ResponseHook]
100
- ) {
101
- if (args[0] === "beforeRequest") {
102
- this.requestHooks.push(args[1]);
103
- } else if (args[0] === "requestError") {
104
- this.requestErrorHooks.push(args[1]);
105
- } else if (args[0] === "response") {
106
- this.responseHooks.push(args[1]);
107
- } else {
108
- throw new Error(`Invalid hook type: ${args[0]}`);
109
- }
110
- return this;
111
- }
112
-
113
- /** Removes a hook that was previously registered with `addHook`. */
114
- removeHook(hook: "beforeRequest", fn: BeforeRequestHook): this;
115
- /** Removes a hook that was previously registered with `addHook`. */
116
- removeHook(hook: "requestError", fn: RequestErrorHook): this;
117
- /** Removes a hook that was previously registered with `addHook`. */
118
- removeHook(hook: "response", fn: ResponseHook): this;
119
- removeHook(
120
- ...args:
121
- | [hook: "beforeRequest", fn: BeforeRequestHook]
122
- | [hook: "requestError", fn: RequestErrorHook]
123
- | [hook: "response", fn: ResponseHook]
124
- ): this {
125
- let target: unknown[];
126
- if (args[0] === "beforeRequest") {
127
- target = this.requestHooks;
128
- } else if (args[0] === "requestError") {
129
- target = this.requestErrorHooks;
130
- } else if (args[0] === "response") {
131
- target = this.responseHooks;
132
- } else {
133
- throw new Error(`Invalid hook type: ${args[0]}`);
134
- }
135
-
136
- const index = target.findIndex((v) => v === args[1]);
137
- if (index >= 0) {
138
- target.splice(index, 1);
139
- }
140
-
141
- return this;
142
- }
143
-
144
- clone(): HTTPClient {
145
- const child = new HTTPClient(this.options);
146
- child.requestHooks = this.requestHooks.slice();
147
- child.requestErrorHooks = this.requestErrorHooks.slice();
148
- child.responseHooks = this.responseHooks.slice();
149
-
150
- return child;
151
- }
152
- }
153
-
154
- export type StatusCodePredicate = number | string | (number | string)[];
155
-
156
- // A semicolon surrounded by optional whitespace characters is used to separate
157
- // segments in a media type string.
158
- const mediaParamSeparator = /\s*;\s*/g;
159
-
160
- export function matchContentType(response: Response, pattern: string): boolean {
161
- // `*` is a special case which means anything is acceptable.
162
- if (pattern === "*") {
163
- return true;
164
- }
165
-
166
- let contentType =
167
- response.headers.get("content-type")?.trim() || "application/octet-stream";
168
- contentType = contentType.toLowerCase();
169
-
170
- const wantParts = pattern.toLowerCase().trim().split(mediaParamSeparator);
171
- const [wantType = "", ...wantParams] = wantParts;
172
-
173
- if (wantType.split("/").length !== 2) {
174
- return false;
175
- }
176
-
177
- const gotParts = contentType.split(mediaParamSeparator);
178
- const [gotType = "", ...gotParams] = gotParts;
179
-
180
- const [type = "", subtype = ""] = gotType.split("/");
181
- if (!type || !subtype) {
182
- return false;
183
- }
184
-
185
- if (
186
- wantType !== "*/*" &&
187
- gotType !== wantType &&
188
- `${type}/*` !== wantType &&
189
- `*/${subtype}` !== wantType
190
- ) {
191
- return false;
192
- }
193
-
194
- if (gotParams.length < wantParams.length) {
195
- return false;
196
- }
197
-
198
- const params = new Set(gotParams);
199
- for (const wantParam of wantParams) {
200
- if (!params.has(wantParam)) {
201
- return false;
202
- }
203
- }
204
-
205
- return true;
206
- }
207
-
208
- const codeRangeRE = new RegExp("^[0-9]xx$", "i");
209
-
210
- export function matchStatusCode(
211
- response: Response,
212
- codes: StatusCodePredicate,
213
- ): boolean {
214
- const actual = `${response.status}`;
215
- const expectedCodes = Array.isArray(codes) ? codes : [codes];
216
- if (!expectedCodes.length) {
217
- return false;
218
- }
219
-
220
- return expectedCodes.some((ec) => {
221
- const code = `${ec}`;
222
-
223
- if (code === "default") {
224
- return true;
225
- }
226
-
227
- if (!codeRangeRE.test(`${code}`)) {
228
- return code === actual;
229
- }
230
-
231
- const expectFamily = code.charAt(0);
232
- if (!expectFamily) {
233
- throw new Error("Invalid status code range");
234
- }
235
-
236
- const actualFamily = actual.charAt(0);
237
- if (!actualFamily) {
238
- throw new Error(`Invalid response status code: ${actual}`);
239
- }
240
-
241
- return actualFamily === expectFamily;
242
- });
243
- }
244
-
245
- export function matchResponse(
246
- response: Response,
247
- code: StatusCodePredicate,
248
- contentTypePattern: string,
249
- ): boolean {
250
- return (
251
- matchStatusCode(response, code) &&
252
- matchContentType(response, contentTypePattern)
253
- );
254
- }
255
-
256
- /**
257
- * Uses various heurisitics to determine if an error is a connection error.
258
- */
259
- export function isConnectionError(err: unknown): boolean {
260
- if (typeof err !== "object" || err == null) {
261
- return false;
262
- }
263
-
264
- // Covers fetch in Deno as well
265
- const isBrowserErr =
266
- err instanceof TypeError &&
267
- err.message.toLowerCase().startsWith("failed to fetch");
268
-
269
- const isNodeErr =
270
- err instanceof TypeError &&
271
- err.message.toLowerCase().startsWith("fetch failed");
272
-
273
- const isBunErr = "name" in err && err.name === "ConnectionError";
274
-
275
- const isGenericErr =
276
- "code" in err &&
277
- typeof err.code === "string" &&
278
- err.code.toLowerCase() === "econnreset";
279
-
280
- return isBrowserErr || isNodeErr || isGenericErr || isBunErr;
281
- }
282
-
283
- /**
284
- * Uses various heurisitics to determine if an error is a timeout error.
285
- */
286
- export function isTimeoutError(err: unknown): boolean {
287
- if (typeof err !== "object" || err == null) {
288
- return false;
289
- }
290
-
291
- // Fetch in browser, Node.js, Bun, Deno
292
- const isNative = "name" in err && err.name === "TimeoutError";
293
- const isLegacyNative = "code" in err && err.code === 23;
294
-
295
- // Node.js HTTP client and Axios
296
- const isGenericErr =
297
- "code" in err &&
298
- typeof err.code === "string" &&
299
- err.code.toLowerCase() === "econnaborted";
300
-
301
- return isNative || isLegacyNative || isGenericErr;
302
- }
303
-
304
- /**
305
- * Uses various heurisitics to determine if an error is a abort error.
306
- */
307
- export function isAbortError(err: unknown): boolean {
308
- if (typeof err !== "object" || err == null) {
309
- return false;
310
- }
311
-
312
- // Fetch in browser, Node.js, Bun, Deno
313
- const isNative = "name" in err && err.name === "AbortError";
314
- const isLegacyNative = "code" in err && err.code === 20;
315
-
316
- // Node.js HTTP client and Axios
317
- const isGenericErr =
318
- "code" in err &&
319
- typeof err.code === "string" &&
320
- err.code.toLowerCase() === "econnaborted";
321
-
322
- return isNative || isLegacyNative || isGenericErr;
323
- }
@@ -1,43 +0,0 @@
1
- /*
2
- * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
- */
4
-
5
- /*
6
- MIT License
7
-
8
- Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
9
-
10
- Permission is hereby granted, free of charge, to any person obtaining a copy of
11
- this software and associated documentation files (the "Software"), to deal in
12
- the Software without restriction, including without limitation the rights to
13
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
14
- the Software, and to permit persons to whom the Software is furnished to do so,
15
- subject to the following conditions:
16
-
17
- The above copyright notice and this permission notice shall be included in all
18
- copies or substantial portions of the Software.
19
-
20
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
22
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
23
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
- */
27
-
28
- // Taken from https://github.com/sindresorhus/is-plain-obj/blob/97f38e8836f86a642cce98fc6ab3058bc36df181/index.js
29
-
30
- export function isPlainObject(value: unknown): value is object {
31
- if (typeof value !== "object" || value === null) {
32
- return false;
33
- }
34
-
35
- const prototype = Object.getPrototypeOf(value);
36
- return (
37
- (prototype === null ||
38
- prototype === Object.prototype ||
39
- Object.getPrototypeOf(prototype) === null) &&
40
- !(Symbol.toStringTag in value) &&
41
- !(Symbol.iterator in value)
42
- );
43
- }
@@ -1,9 +0,0 @@
1
- /*
2
- * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
- */
4
-
5
- export interface Logger {
6
- group(label?: string): void;
7
- groupEnd(): void;
8
- log(message: any, ...args: any[]): void;
9
- }