@valtown/sdk 0.23.0 → 0.25.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.
Files changed (188) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/LICENSE +1 -1
  3. package/README.md +29 -1
  4. package/_shims/node-types.d.ts +1 -1
  5. package/core.d.ts +10 -8
  6. package/core.d.ts.map +1 -1
  7. package/core.js +41 -20
  8. package/core.js.map +1 -1
  9. package/core.mjs +38 -18
  10. package/core.mjs.map +1 -1
  11. package/error.d.ts +18 -24
  12. package/error.d.ts.map +1 -1
  13. package/error.js +1 -31
  14. package/error.js.map +1 -1
  15. package/error.mjs +1 -31
  16. package/error.mjs.map +1 -1
  17. package/index.d.mts +28 -33
  18. package/index.d.ts +28 -33
  19. package/index.d.ts.map +1 -1
  20. package/index.js +36 -17
  21. package/index.js.map +1 -1
  22. package/index.mjs +20 -16
  23. package/index.mjs.map +1 -1
  24. package/package.json +2 -2
  25. package/resources/alias/alias.d.ts +2 -1
  26. package/resources/alias/alias.d.ts.map +1 -1
  27. package/resources/alias/alias.js +2 -3
  28. package/resources/alias/alias.js.map +1 -1
  29. package/resources/alias/alias.mjs +2 -3
  30. package/resources/alias/alias.mjs.map +1 -1
  31. package/resources/alias/username/index.d.ts +1 -1
  32. package/resources/alias/username/index.d.ts.map +1 -1
  33. package/resources/alias/username/index.js.map +1 -1
  34. package/resources/alias/username/index.mjs.map +1 -1
  35. package/resources/alias/username/username.d.ts +2 -2
  36. package/resources/alias/username/username.d.ts.map +1 -1
  37. package/resources/alias/username/username.js +2 -3
  38. package/resources/alias/username/username.js.map +1 -1
  39. package/resources/alias/username/username.mjs +2 -3
  40. package/resources/alias/username/username.mjs.map +1 -1
  41. package/resources/alias/username/val-name.d.ts +2 -2
  42. package/resources/alias/username/val-name.d.ts.map +1 -1
  43. package/resources/alias/username/val-name.js +0 -2
  44. package/resources/alias/username/val-name.js.map +1 -1
  45. package/resources/alias/username/val-name.mjs +0 -2
  46. package/resources/alias/username/val-name.mjs.map +1 -1
  47. package/resources/blobs.d.ts +1 -4
  48. package/resources/blobs.d.ts.map +1 -1
  49. package/resources/blobs.js +0 -2
  50. package/resources/blobs.js.map +1 -1
  51. package/resources/blobs.mjs +0 -2
  52. package/resources/blobs.mjs.map +1 -1
  53. package/resources/emails.d.ts +1 -3
  54. package/resources/emails.d.ts.map +1 -1
  55. package/resources/emails.js +0 -2
  56. package/resources/emails.js.map +1 -1
  57. package/resources/emails.mjs +0 -2
  58. package/resources/emails.mjs.map +1 -1
  59. package/resources/index.d.ts +4 -4
  60. package/resources/index.d.ts.map +1 -1
  61. package/resources/index.js.map +1 -1
  62. package/resources/index.mjs.map +1 -1
  63. package/resources/me/comments.d.ts +1 -4
  64. package/resources/me/comments.d.ts.map +1 -1
  65. package/resources/me/comments.js +1 -27
  66. package/resources/me/comments.js.map +1 -1
  67. package/resources/me/comments.mjs +1 -4
  68. package/resources/me/comments.mjs.map +1 -1
  69. package/resources/me/index.d.ts +4 -4
  70. package/resources/me/index.d.ts.map +1 -1
  71. package/resources/me/index.js.map +1 -1
  72. package/resources/me/index.mjs.map +1 -1
  73. package/resources/me/likes.d.ts +1 -2
  74. package/resources/me/likes.d.ts.map +1 -1
  75. package/resources/me/likes.js +0 -2
  76. package/resources/me/likes.js.map +1 -1
  77. package/resources/me/likes.mjs +0 -2
  78. package/resources/me/likes.mjs.map +1 -1
  79. package/resources/me/me.d.ts +8 -12
  80. package/resources/me/me.d.ts.map +1 -1
  81. package/resources/me/me.js +10 -8
  82. package/resources/me/me.js.map +1 -1
  83. package/resources/me/me.mjs +10 -8
  84. package/resources/me/me.mjs.map +1 -1
  85. package/resources/me/profile.d.ts +1 -2
  86. package/resources/me/profile.d.ts.map +1 -1
  87. package/resources/me/profile.js +0 -2
  88. package/resources/me/profile.js.map +1 -1
  89. package/resources/me/profile.mjs +0 -2
  90. package/resources/me/profile.mjs.map +1 -1
  91. package/resources/me/references.d.ts +1 -4
  92. package/resources/me/references.d.ts.map +1 -1
  93. package/resources/me/references.js +1 -27
  94. package/resources/me/references.js.map +1 -1
  95. package/resources/me/references.mjs +1 -4
  96. package/resources/me/references.mjs.map +1 -1
  97. package/resources/search/index.d.ts +1 -1
  98. package/resources/search/index.d.ts.map +1 -1
  99. package/resources/search/index.js.map +1 -1
  100. package/resources/search/index.mjs.map +1 -1
  101. package/resources/search/search.d.ts +2 -2
  102. package/resources/search/search.d.ts.map +1 -1
  103. package/resources/search/search.js +2 -3
  104. package/resources/search/search.js.map +1 -1
  105. package/resources/search/search.mjs +2 -3
  106. package/resources/search/search.mjs.map +1 -1
  107. package/resources/search/vals.d.ts +1 -2
  108. package/resources/search/vals.d.ts.map +1 -1
  109. package/resources/search/vals.js +0 -2
  110. package/resources/search/vals.js.map +1 -1
  111. package/resources/search/vals.mjs +0 -2
  112. package/resources/search/vals.mjs.map +1 -1
  113. package/resources/shared.d.ts +1 -0
  114. package/resources/shared.d.ts.map +1 -1
  115. package/resources/shared.js.map +1 -1
  116. package/resources/shared.mjs.map +1 -1
  117. package/resources/sqlite.d.ts +1 -4
  118. package/resources/sqlite.d.ts.map +1 -1
  119. package/resources/sqlite.js +0 -2
  120. package/resources/sqlite.js.map +1 -1
  121. package/resources/sqlite.mjs +0 -2
  122. package/resources/sqlite.mjs.map +1 -1
  123. package/resources/users/index.d.ts +1 -1
  124. package/resources/users/index.d.ts.map +1 -1
  125. package/resources/users/index.js.map +1 -1
  126. package/resources/users/index.mjs.map +1 -1
  127. package/resources/users/users.d.ts +2 -2
  128. package/resources/users/users.d.ts.map +1 -1
  129. package/resources/users/users.js +2 -3
  130. package/resources/users/users.js.map +1 -1
  131. package/resources/users/users.mjs +2 -3
  132. package/resources/users/users.mjs.map +1 -1
  133. package/resources/users/vals.d.ts +1 -2
  134. package/resources/users/vals.d.ts.map +1 -1
  135. package/resources/users/vals.js +0 -2
  136. package/resources/users/vals.js.map +1 -1
  137. package/resources/users/vals.mjs +0 -2
  138. package/resources/users/vals.mjs.map +1 -1
  139. package/resources/vals/index.d.ts +2 -2
  140. package/resources/vals/index.d.ts.map +1 -1
  141. package/resources/vals/index.js.map +1 -1
  142. package/resources/vals/index.mjs.map +1 -1
  143. package/resources/vals/vals.d.ts +5 -13
  144. package/resources/vals/vals.d.ts.map +1 -1
  145. package/resources/vals/vals.js +3 -4
  146. package/resources/vals/vals.js.map +1 -1
  147. package/resources/vals/vals.mjs +3 -4
  148. package/resources/vals/vals.mjs.map +1 -1
  149. package/resources/vals/versions.d.ts +2 -7
  150. package/resources/vals/versions.d.ts.map +1 -1
  151. package/resources/vals/versions.js +1 -27
  152. package/resources/vals/versions.js.map +1 -1
  153. package/resources/vals/versions.mjs +1 -4
  154. package/resources/vals/versions.mjs.map +1 -1
  155. package/shims/node.d.ts +1 -0
  156. package/shims/node.d.ts.map +1 -1
  157. package/src/_shims/node-types.d.ts +1 -1
  158. package/src/core.ts +57 -27
  159. package/src/error.ts +25 -41
  160. package/src/index.ts +80 -49
  161. package/src/resources/alias/alias.ts +5 -2
  162. package/src/resources/alias/username/index.ts +1 -1
  163. package/src/resources/alias/username/username.ts +5 -3
  164. package/src/resources/alias/username/val-name.ts +4 -3
  165. package/src/resources/blobs.ts +6 -5
  166. package/src/resources/emails.ts +2 -4
  167. package/src/resources/index.ts +7 -7
  168. package/src/resources/me/comments.ts +8 -5
  169. package/src/resources/me/index.ts +6 -6
  170. package/src/resources/me/likes.ts +2 -3
  171. package/src/resources/me/me.ts +39 -13
  172. package/src/resources/me/profile.ts +2 -3
  173. package/src/resources/me/references.ts +8 -5
  174. package/src/resources/search/index.ts +1 -1
  175. package/src/resources/search/search.ts +5 -3
  176. package/src/resources/search/vals.ts +2 -3
  177. package/src/resources/shared.ts +2 -0
  178. package/src/resources/sqlite.ts +6 -5
  179. package/src/resources/users/index.ts +1 -1
  180. package/src/resources/users/users.ts +5 -3
  181. package/src/resources/users/vals.ts +2 -3
  182. package/src/resources/vals/index.ts +8 -8
  183. package/src/resources/vals/vals.ts +29 -14
  184. package/src/resources/vals/versions.ts +11 -8
  185. package/src/version.ts +1 -1
  186. package/version.d.ts +1 -1
  187. package/version.js +1 -1
  188. package/version.mjs +1 -1
@@ -1,6 +1,5 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
  import { APIResource } from "../../resource.mjs";
3
- import * as VersionsAPI from "./versions.mjs";
4
3
  import { PageCursorURL } from "../../pagination.mjs";
5
4
  export class Versions extends APIResource {
6
5
  /**
@@ -36,7 +35,5 @@ export class Versions extends APIResource {
36
35
  }
37
36
  export class VersionListResponsesPageCursorURL extends PageCursorURL {
38
37
  }
39
- (function (Versions) {
40
- Versions.VersionListResponsesPageCursorURL = VersionsAPI.VersionListResponsesPageCursorURL;
41
- })(Versions || (Versions = {}));
38
+ Versions.VersionListResponsesPageCursorURL = VersionListResponsesPageCursorURL;
42
39
  //# sourceMappingURL=versions.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"versions.mjs","sourceRoot":"","sources":["../../src/resources/vals/versions.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,WAAW,EAAE;OAEf,KAAK,WAAW;OAEhB,EAAE,aAAa,EAA4B;AAElD,MAAM,OAAO,QAAS,SAAQ,WAAW;IACvC;;OAEG;IACH,MAAM,CACJ,KAAa,EACb,IAAyB,EACzB,OAA6B;QAE7B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,KAAK,WAAW,EAAE,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAC/E,CAAC;IAED;;OAEG;IACH,QAAQ,CACN,KAAa,EACb,OAAe,EACf,KAA4B,EAC5B,OAA6B;QAE7B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,KAAK,aAAa,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAC1F,CAAC;IAED;;OAEG;IACH,IAAI,CACF,KAAa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a,EACb,KAAwB,EACxB,OAA6B;QAE7B,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,YAAY,KAAK,WAAW,EAAE,iCAAiC,EAAE;YAC9F,KAAK;YACL,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAa,EAAE,OAAe,EAAE,OAA6B;QAClE,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,KAAK,aAAa,OAAO,EAAE,EAAE;YAClE,GAAG,OAAO;YACV,OAAO,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE;SAChD,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,OAAO,iCAAkC,SAAQ,aAAkC;CAAG;AA2D5F,QAAQ,CAAC,iCAAiC,GAAG,iCAAiC,CAAC"}
package/shims/node.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
 
2
2
 
3
3
 
4
+
4
5
  import * as types from "../_shims/node-types.js";
5
6
  declare module '../_shims/manual-types' {
6
7
  namespace manual {
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/shims/node.ts"],"names":[],"mappings":";;;AACA,OAAO,KAAK,KAAK,MAAM,sBAAsB,CAAC;AAK9C,OAAO,QAAQ,wBAAwB,CAAC;IACtC,UAAiB,MAAM,CAAC;QAEtB,KAAY,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QAEhC,MAAM,QAAQ,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QAElC,KAAY,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAEpC,KAAY,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC;QAE5C,KAAY,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC;QAE5C,KAAY,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAEtC,KAAY,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC;QAE9C,KAAY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AAG,KAAK,CAAC,YAAY,CAAC;QAE9C,KAAY,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAEtC,KAAY,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAEpC,KAAY,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC;QAE5C,KAAY,eAAe,GAAG,KAAK,CAAC,eAAe,CAAC;QAEpD,KAAY,eAAe,GAAG,KAAK,CAAC,eAAe,CAAC;QAEpD,KAAY,mBAAmB,GAAG,KAAK,CAAC,mBAAmB,CAAC;QAE5D,MAAM,QAAQ,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAExC,MAAM,QAAQ,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QAEhC,MAAM,QAAQ,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QAEhC,KAAY,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAEtC,KAAY,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC;QAE9C,MAAM,QAAQ,cAAc,GAAG,KAAK,CAAC,cAAc,CAAC;KACrD;CACF"}
@@ -7,7 +7,7 @@ import * as fd from 'formdata-node';
7
7
  export { type Agent } from 'node:http';
8
8
  export { type Readable } from 'node:stream';
9
9
  export { type ReadStream as FsReadStream } from 'node:fs';
10
- export { ReadableStream } from 'web-streams-polyfill';
10
+ export { ReadableStream } from 'node:stream/web';
11
11
 
12
12
  export const fetch: typeof nf.default;
13
13
 
package/src/core.ts CHANGED
@@ -84,8 +84,10 @@ export class APIPromise<T> extends Promise<T> {
84
84
  });
85
85
  }
86
86
 
87
- _thenUnwrap<U>(transform: (data: T) => U): APIPromise<U> {
88
- return new APIPromise(this.responsePromise, async (props) => transform(await this.parseResponse(props)));
87
+ _thenUnwrap<U>(transform: (data: T, props: APIResponseProps) => U): APIPromise<U> {
88
+ return new APIPromise(this.responsePromise, async (props) =>
89
+ transform(await this.parseResponse(props), props),
90
+ );
89
91
  }
90
92
 
91
93
  /**
@@ -161,7 +163,7 @@ export abstract class APIClient {
161
163
  maxRetries = 2,
162
164
  timeout = 60000, // 1 minute
163
165
  httpAgent,
164
- fetch: overridenFetch,
166
+ fetch: overriddenFetch,
165
167
  }: {
166
168
  baseURL: string;
167
169
  maxRetries?: number | undefined;
@@ -174,7 +176,7 @@ export abstract class APIClient {
174
176
  this.timeout = validatePositiveInteger('timeout', timeout);
175
177
  this.httpAgent = httpAgent;
176
178
 
177
- this.fetch = overridenFetch ?? fetch;
179
+ this.fetch = overriddenFetch ?? fetch;
178
180
  }
179
181
 
180
182
  protected authHeaders(opts: FinalRequestOptions): Headers {
@@ -274,7 +276,10 @@ export abstract class APIClient {
274
276
  return null;
275
277
  }
276
278
 
277
- buildRequest<Req>(options: FinalRequestOptions<Req>): { req: RequestInit; url: string; timeout: number } {
279
+ buildRequest<Req>(
280
+ options: FinalRequestOptions<Req>,
281
+ { retryCount = 0 }: { retryCount?: number } = {},
282
+ ): { req: RequestInit; url: string; timeout: number } {
278
283
  const { method, path, query, headers: headers = {} } = options;
279
284
 
280
285
  const body =
@@ -306,7 +311,7 @@ export abstract class APIClient {
306
311
  headers[this.idempotencyHeader] = options.idempotencyKey;
307
312
  }
308
313
 
309
- const reqHeaders = this.buildHeaders({ options, headers, contentLength });
314
+ const reqHeaders = this.buildHeaders({ options, headers, contentLength, retryCount });
310
315
 
311
316
  const req: RequestInit = {
312
317
  method,
@@ -325,10 +330,12 @@ export abstract class APIClient {
325
330
  options,
326
331
  headers,
327
332
  contentLength,
333
+ retryCount,
328
334
  }: {
329
335
  options: FinalRequestOptions;
330
336
  headers: Record<string, string | null | undefined>;
331
337
  contentLength: string | null | undefined;
338
+ retryCount: number;
332
339
  }): Record<string, string> {
333
340
  const reqHeaders: Record<string, string> = {};
334
341
  if (contentLength) {
@@ -344,6 +351,16 @@ export abstract class APIClient {
344
351
  delete reqHeaders['content-type'];
345
352
  }
346
353
 
354
+ // Don't set the retry count header if it was already set or removed through default headers or by the
355
+ // caller. We check `defaultHeaders` and `headers`, which can contain nulls, instead of `reqHeaders` to
356
+ // account for the removal case.
357
+ if (
358
+ getHeader(defaultHeaders, 'x-stainless-retry-count') === undefined &&
359
+ getHeader(headers, 'x-stainless-retry-count') === undefined
360
+ ) {
361
+ reqHeaders['x-stainless-retry-count'] = String(retryCount);
362
+ }
363
+
347
364
  this.validateHeaders(reqHeaders, headers);
348
365
 
349
366
  return reqHeaders;
@@ -379,7 +396,7 @@ export abstract class APIClient {
379
396
  error: Object | undefined,
380
397
  message: string | undefined,
381
398
  headers: Headers | undefined,
382
- ) {
399
+ ): APIError {
383
400
  return APIError.generate(status, error, message, headers);
384
401
  }
385
402
 
@@ -395,13 +412,14 @@ export abstract class APIClient {
395
412
  retriesRemaining: number | null,
396
413
  ): Promise<APIResponseProps> {
397
414
  const options = await optionsInput;
415
+ const maxRetries = options.maxRetries ?? this.maxRetries;
398
416
  if (retriesRemaining == null) {
399
- retriesRemaining = options.maxRetries ?? this.maxRetries;
417
+ retriesRemaining = maxRetries;
400
418
  }
401
419
 
402
420
  await this.prepareOptions(options);
403
421
 
404
- const { req, url, timeout } = this.buildRequest(options);
422
+ const { req, url, timeout } = this.buildRequest(options, { retryCount: maxRetries - retriesRemaining });
405
423
 
406
424
  await this.prepareRequest(req, { url, options });
407
425
 
@@ -504,20 +522,24 @@ export abstract class APIClient {
504
522
 
505
523
  const timeout = setTimeout(() => controller.abort(), ms);
506
524
 
525
+ const fetchOptions = {
526
+ signal: controller.signal as any,
527
+ ...options,
528
+ };
529
+ if (fetchOptions.method) {
530
+ // Custom methods like 'patch' need to be uppercased
531
+ // See https://github.com/nodejs/undici/issues/2294
532
+ fetchOptions.method = fetchOptions.method.toUpperCase();
533
+ }
534
+
507
535
  return (
508
- this.getRequestClient()
509
- // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
510
- .fetch.call(undefined, url, { signal: controller.signal as any, ...options })
511
- .finally(() => {
512
- clearTimeout(timeout);
513
- })
536
+ // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
537
+ this.fetch.call(undefined, url, fetchOptions).finally(() => {
538
+ clearTimeout(timeout);
539
+ })
514
540
  );
515
541
  }
516
542
 
517
- protected getRequestClient(): RequestClient {
518
- return { fetch: this.fetch };
519
- }
520
-
521
543
  private shouldRetry(response: Response): boolean {
522
544
  // Note this is not a standard header.
523
545
  const shouldRetryHeader = response.headers.get('x-should-retry');
@@ -650,9 +672,9 @@ export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
650
672
  return await this.#client.requestAPIList(this.constructor as any, nextOptions);
651
673
  }
652
674
 
653
- async *iterPages() {
675
+ async *iterPages(): AsyncGenerator<this> {
654
676
  // eslint-disable-next-line @typescript-eslint/no-this-alias
655
- let page: AbstractPage<Item> = this;
677
+ let page: this = this;
656
678
  yield page;
657
679
  while (page.hasNextPage()) {
658
680
  page = await page.getNextPage();
@@ -660,7 +682,7 @@ export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
660
682
  }
661
683
  }
662
684
 
663
- async *[Symbol.asyncIterator]() {
685
+ async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
664
686
  for await (const page of this.iterPages()) {
665
687
  for (const item of page.getPaginatedItems()) {
666
688
  yield item;
@@ -703,7 +725,7 @@ export class PagePromise<
703
725
  * console.log(item)
704
726
  * }
705
727
  */
706
- async *[Symbol.asyncIterator]() {
728
+ async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
707
729
  const page = await this;
708
730
  for await (const item of page) {
709
731
  yield item;
@@ -958,8 +980,8 @@ export const safeJSON = (text: string) => {
958
980
  }
959
981
  };
960
982
 
961
- // https://stackoverflow.com/a/19709846
962
- const startsWithSchemeRegexp = new RegExp('^(?:[a-z]+:)?//', 'i');
983
+ // https://url.spec.whatwg.org/#url-scheme-string
984
+ const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
963
985
  const isAbsoluteURL = (url: string): boolean => {
964
986
  return startsWithSchemeRegexp.test(url);
965
987
  };
@@ -1120,7 +1142,15 @@ export const isHeadersProtocol = (headers: any): headers is HeadersProtocol => {
1120
1142
  return typeof headers?.get === 'function';
1121
1143
  };
1122
1144
 
1123
- export const getRequiredHeader = (headers: HeadersLike, header: string): string => {
1145
+ export const getRequiredHeader = (headers: HeadersLike | Headers, header: string): string => {
1146
+ const foundHeader = getHeader(headers, header);
1147
+ if (foundHeader === undefined) {
1148
+ throw new Error(`Could not find ${header} header`);
1149
+ }
1150
+ return foundHeader;
1151
+ };
1152
+
1153
+ export const getHeader = (headers: HeadersLike | Headers, header: string): string | undefined => {
1124
1154
  const lowerCasedHeader = header.toLowerCase();
1125
1155
  if (isHeadersProtocol(headers)) {
1126
1156
  // to deal with the case where the header looks like Stainless-Event-Id
@@ -1146,7 +1176,7 @@ export const getRequiredHeader = (headers: HeadersLike, header: string): string
1146
1176
  }
1147
1177
  }
1148
1178
 
1149
- throw new Error(`Could not find ${header} header`);
1179
+ return undefined;
1150
1180
  };
1151
1181
 
1152
1182
  /**
package/src/error.ts CHANGED
@@ -4,17 +4,19 @@ import { castToError, Headers } from './core';
4
4
 
5
5
  export class ValTownError extends Error {}
6
6
 
7
- export class APIError extends ValTownError {
8
- readonly status: number | undefined;
9
- readonly headers: Headers | undefined;
10
- readonly error: Object | undefined;
11
-
12
- constructor(
13
- status: number | undefined,
14
- error: Object | undefined,
15
- message: string | undefined,
16
- headers: Headers | undefined,
17
- ) {
7
+ export class APIError<
8
+ TStatus extends number | undefined = number | undefined,
9
+ THeaders extends Headers | undefined = Headers | undefined,
10
+ TError extends Object | undefined = Object | undefined,
11
+ > extends ValTownError {
12
+ /** HTTP status for the response that caused the error */
13
+ readonly status: TStatus;
14
+ /** HTTP headers for the response that caused the error */
15
+ readonly headers: THeaders;
16
+ /** JSON body of the response that caused the error */
17
+ readonly error: TError;
18
+
19
+ constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {
18
20
  super(`${APIError.makeMessage(status, error, message)}`);
19
21
  this.status = status;
20
22
  this.headers = headers;
@@ -47,8 +49,8 @@ export class APIError extends ValTownError {
47
49
  errorResponse: Object | undefined,
48
50
  message: string | undefined,
49
51
  headers: Headers | undefined,
50
- ) {
51
- if (!status) {
52
+ ): APIError {
53
+ if (!status || !headers) {
52
54
  return new APIConnectionError({ message, cause: castToError(errorResponse) });
53
55
  }
54
56
 
@@ -90,17 +92,13 @@ export class APIError extends ValTownError {
90
92
  }
91
93
  }
92
94
 
93
- export class APIUserAbortError extends APIError {
94
- override readonly status: undefined = undefined;
95
-
95
+ export class APIUserAbortError extends APIError<undefined, undefined, undefined> {
96
96
  constructor({ message }: { message?: string } = {}) {
97
97
  super(undefined, undefined, message || 'Request was aborted.', undefined);
98
98
  }
99
99
  }
100
100
 
101
- export class APIConnectionError extends APIError {
102
- override readonly status: undefined = undefined;
103
-
101
+ export class APIConnectionError extends APIError<undefined, undefined, undefined> {
104
102
  constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {
105
103
  super(undefined, undefined, message || 'Connection error.', undefined);
106
104
  // in some environments the 'cause' property is already declared
@@ -115,32 +113,18 @@ export class APIConnectionTimeoutError extends APIConnectionError {
115
113
  }
116
114
  }
117
115
 
118
- export class BadRequestError extends APIError {
119
- override readonly status: 400 = 400;
120
- }
116
+ export class BadRequestError extends APIError<400, Headers> {}
121
117
 
122
- export class AuthenticationError extends APIError {
123
- override readonly status: 401 = 401;
124
- }
118
+ export class AuthenticationError extends APIError<401, Headers> {}
125
119
 
126
- export class PermissionDeniedError extends APIError {
127
- override readonly status: 403 = 403;
128
- }
120
+ export class PermissionDeniedError extends APIError<403, Headers> {}
129
121
 
130
- export class NotFoundError extends APIError {
131
- override readonly status: 404 = 404;
132
- }
122
+ export class NotFoundError extends APIError<404, Headers> {}
133
123
 
134
- export class ConflictError extends APIError {
135
- override readonly status: 409 = 409;
136
- }
124
+ export class ConflictError extends APIError<409, Headers> {}
137
125
 
138
- export class UnprocessableEntityError extends APIError {
139
- override readonly status: 422 = 422;
140
- }
126
+ export class UnprocessableEntityError extends APIError<422, Headers> {}
141
127
 
142
- export class RateLimitError extends APIError {
143
- override readonly status: 429 = 429;
144
- }
128
+ export class RateLimitError extends APIError<429, Headers> {}
145
129
 
146
- export class InternalServerError extends APIError {}
130
+ export class InternalServerError extends APIError<number, Headers> {}
package/src/index.ts CHANGED
@@ -1,11 +1,26 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
- import * as Errors from './error';
4
- import * as Uploads from './uploads';
5
3
  import { type Agent } from './_shims/index';
6
4
  import * as Core from './core';
5
+ import * as Errors from './error';
7
6
  import * as Pagination from './pagination';
7
+ import { type PageCursorURLParams, PageCursorURLResponse } from './pagination';
8
+ import * as Uploads from './uploads';
8
9
  import * as API from './resources/index';
10
+ import { BlobListParams, BlobListResponse, BlobStoreParams, Blobs } from './resources/blobs';
11
+ import { EmailSendParams, EmailSendResponse, Emails } from './resources/emails';
12
+ import { Sqlite, SqliteBatchParams, SqliteBatchResponse, SqliteExecuteParams } from './resources/sqlite';
13
+ import { Alias } from './resources/alias/alias';
14
+ import { Me } from './resources/me/me';
15
+ import { Search } from './resources/search/search';
16
+ import { Users } from './resources/users/users';
17
+ import {
18
+ ValCancelEvaluationResponse,
19
+ ValCreateOrUpdateParams,
20
+ ValCreateParams,
21
+ ValUpdateParams,
22
+ Vals,
23
+ } from './resources/vals/vals';
9
24
 
10
25
  export interface ClientOptions {
11
26
  /**
@@ -189,7 +204,68 @@ export class ValTown extends Core.APIClient {
189
204
  static fileFromPath = Uploads.fileFromPath;
190
205
  }
191
206
 
192
- export const {
207
+ ValTown.Search = Search;
208
+ ValTown.Alias = Alias;
209
+ ValTown.Me = Me;
210
+ ValTown.Blobs = Blobs;
211
+ ValTown.Users = Users;
212
+ ValTown.Sqlite = Sqlite;
213
+ ValTown.Vals = Vals;
214
+ ValTown.Emails = Emails;
215
+ export declare namespace ValTown {
216
+ export type RequestOptions = Core.RequestOptions;
217
+
218
+ export import PageCursorURL = Pagination.PageCursorURL;
219
+ export {
220
+ type PageCursorURLParams as PageCursorURLParams,
221
+ type PageCursorURLResponse as PageCursorURLResponse,
222
+ };
223
+
224
+ export { Search as Search };
225
+
226
+ export { Alias as Alias };
227
+
228
+ export { Me as Me };
229
+
230
+ export {
231
+ Blobs as Blobs,
232
+ type BlobListResponse as BlobListResponse,
233
+ type BlobListParams as BlobListParams,
234
+ type BlobStoreParams as BlobStoreParams,
235
+ };
236
+
237
+ export { Users as Users };
238
+
239
+ export {
240
+ Sqlite as Sqlite,
241
+ type SqliteBatchResponse as SqliteBatchResponse,
242
+ type SqliteBatchParams as SqliteBatchParams,
243
+ type SqliteExecuteParams as SqliteExecuteParams,
244
+ };
245
+
246
+ export {
247
+ Vals as Vals,
248
+ type ValCancelEvaluationResponse as ValCancelEvaluationResponse,
249
+ type ValCreateParams as ValCreateParams,
250
+ type ValUpdateParams as ValUpdateParams,
251
+ type ValCreateOrUpdateParams as ValCreateOrUpdateParams,
252
+ };
253
+
254
+ export {
255
+ Emails as Emails,
256
+ type EmailSendResponse as EmailSendResponse,
257
+ type EmailSendParams as EmailSendParams,
258
+ };
259
+
260
+ export type BasicVal = API.BasicVal;
261
+ export type ExtendedVal = API.ExtendedVal;
262
+ export type PaginationLinks = API.PaginationLinks;
263
+ export type ResultSet = API.ResultSet;
264
+ export type User = API.User;
265
+ }
266
+
267
+ export { toFile, fileFromPath } from './uploads';
268
+ export {
193
269
  ValTownError,
194
270
  APIError,
195
271
  APIConnectionError,
@@ -203,51 +279,6 @@ export const {
203
279
  InternalServerError,
204
280
  PermissionDeniedError,
205
281
  UnprocessableEntityError,
206
- } = Errors;
207
-
208
- export import toFile = Uploads.toFile;
209
- export import fileFromPath = Uploads.fileFromPath;
210
-
211
- export namespace ValTown {
212
- export import RequestOptions = Core.RequestOptions;
213
-
214
- export import PageCursorURL = Pagination.PageCursorURL;
215
- export import PageCursorURLParams = Pagination.PageCursorURLParams;
216
- export import PageCursorURLResponse = Pagination.PageCursorURLResponse;
217
-
218
- export import Search = API.Search;
219
-
220
- export import Alias = API.Alias;
221
-
222
- export import Me = API.Me;
223
-
224
- export import Blobs = API.Blobs;
225
- export import BlobListResponse = API.BlobListResponse;
226
- export import BlobListParams = API.BlobListParams;
227
- export import BlobStoreParams = API.BlobStoreParams;
228
-
229
- export import Users = API.Users;
230
-
231
- export import Sqlite = API.Sqlite;
232
- export import SqliteBatchResponse = API.SqliteBatchResponse;
233
- export import SqliteBatchParams = API.SqliteBatchParams;
234
- export import SqliteExecuteParams = API.SqliteExecuteParams;
235
-
236
- export import Vals = API.Vals;
237
- export import ValCancelEvaluationResponse = API.ValCancelEvaluationResponse;
238
- export import ValCreateParams = API.ValCreateParams;
239
- export import ValUpdateParams = API.ValUpdateParams;
240
- export import ValCreateOrUpdateParams = API.ValCreateOrUpdateParams;
241
-
242
- export import Emails = API.Emails;
243
- export import EmailSendResponse = API.EmailSendResponse;
244
- export import EmailSendParams = API.EmailSendParams;
245
-
246
- export import BasicVal = API.BasicVal;
247
- export import ExtendedVal = API.ExtendedVal;
248
- export import PaginationLinks = API.PaginationLinks;
249
- export import ResultSet = API.ResultSet;
250
- export import User = API.User;
251
- }
282
+ } from './error';
252
283
 
253
284
  export default ValTown;
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { APIResource } from '../../resource';
4
4
  import * as UsernameAPI from './username/username';
5
+ import { Username } from './username/username';
5
6
 
6
7
  /**
7
8
  * Methods to translate between human-readable names and IDs
@@ -10,6 +11,8 @@ export class Alias extends APIResource {
10
11
  username: UsernameAPI.Username = new UsernameAPI.Username(this._client);
11
12
  }
12
13
 
13
- export namespace Alias {
14
- export import Username = UsernameAPI.Username;
14
+ Alias.Username = Username;
15
+
16
+ export declare namespace Alias {
17
+ export { Username as Username };
15
18
  }
@@ -1,4 +1,4 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
3
  export { Username } from './username';
4
- export { ValNameRetrieveResponse, ValName } from './val-name';
4
+ export { ValName, type ValNameRetrieveResponse } from './val-name';
@@ -4,6 +4,7 @@ import { APIResource } from '../../../resource';
4
4
  import * as Core from '../../../core';
5
5
  import * as Shared from '../../shared';
6
6
  import * as ValNameAPI from './val-name';
7
+ import { ValName, ValNameRetrieveResponse } from './val-name';
7
8
 
8
9
  export class Username extends APIResource {
9
10
  valName: ValNameAPI.ValName = new ValNameAPI.ValName(this._client);
@@ -16,7 +17,8 @@ export class Username extends APIResource {
16
17
  }
17
18
  }
18
19
 
19
- export namespace Username {
20
- export import ValName = ValNameAPI.ValName;
21
- export import ValNameRetrieveResponse = ValNameAPI.ValNameRetrieveResponse;
20
+ Username.ValName = ValName;
21
+
22
+ export declare namespace Username {
23
+ export { ValName as ValName, type ValNameRetrieveResponse as ValNameRetrieveResponse };
22
24
  }
@@ -2,7 +2,6 @@
2
2
 
3
3
  import { APIResource } from '../../../resource';
4
4
  import * as Core from '../../../core';
5
- import * as ValNameAPI from './val-name';
6
5
 
7
6
  export class ValName extends APIResource {
8
7
  /**
@@ -83,6 +82,8 @@ export interface ValNameRetrieveResponse {
83
82
  * The version of this val, starting at zero
84
83
  */
85
84
  version: number;
85
+
86
+ versionCreatedAt?: string;
86
87
  }
87
88
 
88
89
  export namespace ValNameRetrieveResponse {
@@ -118,6 +119,6 @@ export namespace ValNameRetrieveResponse {
118
119
  }
119
120
  }
120
121
 
121
- export namespace ValName {
122
- export import ValNameRetrieveResponse = ValNameAPI.ValNameRetrieveResponse;
122
+ export declare namespace ValName {
123
+ export { type ValNameRetrieveResponse as ValNameRetrieveResponse };
123
124
  }
@@ -3,7 +3,6 @@
3
3
  import { APIResource } from '../resource';
4
4
  import { isRequestOptions } from '../core';
5
5
  import * as Core from '../core';
6
- import * as BlobsAPI from './blobs';
7
6
  import { type Response } from '../_shims/index';
8
7
 
9
8
  /**
@@ -85,8 +84,10 @@ export interface BlobListParams {
85
84
 
86
85
  export type BlobStoreParams = Core.Uploadable;
87
86
 
88
- export namespace Blobs {
89
- export import BlobListResponse = BlobsAPI.BlobListResponse;
90
- export import BlobListParams = BlobsAPI.BlobListParams;
91
- export import BlobStoreParams = BlobsAPI.BlobStoreParams;
87
+ export declare namespace Blobs {
88
+ export {
89
+ type BlobListResponse as BlobListResponse,
90
+ type BlobListParams as BlobListParams,
91
+ type BlobStoreParams as BlobStoreParams,
92
+ };
92
93
  }
@@ -3,7 +3,6 @@
3
3
  import { APIResource } from '../resource';
4
4
  import { isRequestOptions } from '../core';
5
5
  import * as Core from '../core';
6
- import * as EmailsAPI from './emails';
7
6
 
8
7
  /**
9
8
  * Val Town supports sending emails from vals
@@ -179,7 +178,6 @@ export namespace EmailSendParams {
179
178
  }
180
179
  }
181
180
 
182
- export namespace Emails {
183
- export import EmailSendResponse = EmailsAPI.EmailSendResponse;
184
- export import EmailSendParams = EmailsAPI.EmailSendParams;
181
+ export declare namespace Emails {
182
+ export { type EmailSendResponse as EmailSendResponse, type EmailSendParams as EmailSendParams };
185
183
  }
@@ -2,16 +2,16 @@
2
2
 
3
3
  export * from './shared';
4
4
  export { Alias } from './alias/alias';
5
- export { BlobListResponse, BlobListParams, BlobStoreParams, Blobs } from './blobs';
6
- export { EmailSendResponse, EmailSendParams, Emails } from './emails';
5
+ export { Blobs, type BlobListResponse, type BlobListParams, type BlobStoreParams } from './blobs';
6
+ export { Emails, type EmailSendResponse, type EmailSendParams } from './emails';
7
7
  export { Me } from './me/me';
8
8
  export { Search } from './search/search';
9
- export { SqliteBatchResponse, SqliteBatchParams, SqliteExecuteParams, Sqlite } from './sqlite';
9
+ export { Sqlite, type SqliteBatchResponse, type SqliteBatchParams, type SqliteExecuteParams } from './sqlite';
10
10
  export { Users } from './users/users';
11
11
  export {
12
- ValCancelEvaluationResponse,
13
- ValCreateParams,
14
- ValUpdateParams,
15
- ValCreateOrUpdateParams,
16
12
  Vals,
13
+ type ValCancelEvaluationResponse,
14
+ type ValCreateParams,
15
+ type ValUpdateParams,
16
+ type ValCreateOrUpdateParams,
17
17
  } from './vals/vals';