@roarkanalytics/sdk 0.1.0-alpha.1 → 0.1.0-alpha.2

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 (347) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE +1 -1
  3. package/README.md +48 -85
  4. package/_shims/MultipartBody.d.ts +9 -0
  5. package/_shims/MultipartBody.d.ts.map +1 -0
  6. package/_shims/MultipartBody.js +16 -0
  7. package/_shims/MultipartBody.js.map +1 -0
  8. package/_shims/MultipartBody.mjs +12 -0
  9. package/_shims/MultipartBody.mjs.map +1 -0
  10. package/_shims/README.md +46 -0
  11. package/_shims/auto/runtime-bun.d.ts +5 -0
  12. package/_shims/auto/runtime-bun.d.ts.map +1 -0
  13. package/{internal/utils.js → _shims/auto/runtime-bun.js} +5 -8
  14. package/_shims/auto/runtime-bun.js.map +1 -0
  15. package/_shims/auto/runtime-bun.mjs +2 -0
  16. package/_shims/auto/runtime-bun.mjs.map +1 -0
  17. package/_shims/auto/runtime-node.d.ts +5 -0
  18. package/_shims/auto/runtime-node.d.ts.map +1 -0
  19. package/_shims/auto/runtime-node.js +21 -0
  20. package/_shims/auto/runtime-node.js.map +1 -0
  21. package/_shims/auto/runtime-node.mjs +2 -0
  22. package/_shims/auto/runtime-node.mjs.map +1 -0
  23. package/_shims/auto/runtime.d.ts +5 -0
  24. package/_shims/auto/runtime.d.ts.map +1 -0
  25. package/_shims/auto/runtime.js +21 -0
  26. package/_shims/auto/runtime.js.map +1 -0
  27. package/_shims/auto/runtime.mjs +2 -0
  28. package/_shims/auto/runtime.mjs.map +1 -0
  29. package/_shims/auto/types-node.d.ts +5 -0
  30. package/_shims/auto/types-node.d.ts.map +1 -0
  31. package/_shims/auto/types-node.js +21 -0
  32. package/_shims/auto/types-node.js.map +1 -0
  33. package/_shims/auto/types-node.mjs +2 -0
  34. package/_shims/auto/types-node.mjs.map +1 -0
  35. package/_shims/auto/types.d.ts +101 -0
  36. package/_shims/auto/types.js +3 -0
  37. package/_shims/auto/types.mjs +3 -0
  38. package/_shims/bun-runtime.d.ts +6 -0
  39. package/_shims/bun-runtime.d.ts.map +1 -0
  40. package/_shims/bun-runtime.js +14 -0
  41. package/_shims/bun-runtime.js.map +1 -0
  42. package/_shims/bun-runtime.mjs +10 -0
  43. package/_shims/bun-runtime.mjs.map +1 -0
  44. package/_shims/index.d.ts +81 -0
  45. package/_shims/index.js +13 -0
  46. package/_shims/index.mjs +7 -0
  47. package/_shims/manual-types.d.ts +12 -0
  48. package/_shims/manual-types.js +3 -0
  49. package/_shims/manual-types.mjs +3 -0
  50. package/_shims/node-runtime.d.ts +3 -0
  51. package/_shims/node-runtime.d.ts.map +1 -0
  52. package/_shims/node-runtime.js +89 -0
  53. package/_shims/node-runtime.js.map +1 -0
  54. package/_shims/node-runtime.mjs +56 -0
  55. package/_shims/node-runtime.mjs.map +1 -0
  56. package/_shims/node-types.d.ts +42 -0
  57. package/_shims/node-types.js +3 -0
  58. package/_shims/node-types.mjs +3 -0
  59. package/_shims/registry.d.ts +37 -0
  60. package/_shims/registry.d.ts.map +1 -0
  61. package/_shims/registry.js +41 -0
  62. package/_shims/registry.js.map +1 -0
  63. package/_shims/registry.mjs +37 -0
  64. package/_shims/registry.mjs.map +1 -0
  65. package/_shims/web-runtime.d.ts +5 -0
  66. package/_shims/web-runtime.d.ts.map +1 -0
  67. package/_shims/web-runtime.js +78 -0
  68. package/_shims/web-runtime.js.map +1 -0
  69. package/_shims/web-runtime.mjs +71 -0
  70. package/_shims/web-runtime.mjs.map +1 -0
  71. package/_shims/web-types.d.ts +83 -0
  72. package/_shims/web-types.js +3 -0
  73. package/_shims/web-types.mjs +3 -0
  74. package/core.d.ts +241 -0
  75. package/core.d.ts.map +1 -0
  76. package/core.js +908 -0
  77. package/core.js.map +1 -0
  78. package/core.mjs +876 -0
  79. package/core.mjs.map +1 -0
  80. package/error.d.ts +3 -3
  81. package/error.d.ts.map +1 -1
  82. package/error.js +6 -6
  83. package/error.js.map +1 -1
  84. package/error.mjs +3 -3
  85. package/error.mjs.map +1 -1
  86. package/index.d.mts +109 -5
  87. package/index.d.ts +109 -5
  88. package/index.d.ts.map +1 -1
  89. package/index.js +103 -11
  90. package/index.js.map +1 -1
  91. package/index.mjs +77 -5
  92. package/index.mjs.map +1 -1
  93. package/package.json +66 -82
  94. package/resource.d.ts +3 -3
  95. package/resource.d.ts.map +1 -1
  96. package/resource.js.map +1 -1
  97. package/resource.mjs.map +1 -1
  98. package/resources/calls.d.ts +2 -3
  99. package/resources/calls.d.ts.map +1 -1
  100. package/resources/calls.js.map +1 -1
  101. package/resources/calls.mjs.map +1 -1
  102. package/resources/index.d.ts.map +1 -1
  103. package/shims/node.d.ts +30 -0
  104. package/shims/node.d.ts.map +1 -0
  105. package/shims/node.js +31 -0
  106. package/shims/node.js.map +1 -0
  107. package/shims/node.mjs +5 -0
  108. package/shims/node.mjs.map +1 -0
  109. package/shims/web.d.ts +26 -0
  110. package/shims/web.d.ts.map +1 -0
  111. package/shims/web.js +31 -0
  112. package/shims/web.js.map +1 -0
  113. package/shims/web.mjs +5 -0
  114. package/shims/web.mjs.map +1 -0
  115. package/src/_shims/MultipartBody.ts +9 -0
  116. package/src/_shims/README.md +46 -0
  117. package/src/_shims/auto/runtime-bun.ts +4 -0
  118. package/src/_shims/auto/runtime-node.ts +4 -0
  119. package/src/_shims/auto/runtime.ts +4 -0
  120. package/src/_shims/auto/types-node.ts +4 -0
  121. package/src/_shims/auto/types.d.ts +101 -0
  122. package/src/_shims/auto/types.js +3 -0
  123. package/src/_shims/auto/types.mjs +3 -0
  124. package/src/_shims/bun-runtime.ts +14 -0
  125. package/src/_shims/index.d.ts +81 -0
  126. package/src/_shims/index.js +13 -0
  127. package/src/_shims/index.mjs +7 -0
  128. package/src/_shims/manual-types.d.ts +12 -0
  129. package/src/_shims/manual-types.js +3 -0
  130. package/src/_shims/manual-types.mjs +3 -0
  131. package/src/_shims/node-runtime.ts +81 -0
  132. package/src/_shims/node-types.d.ts +42 -0
  133. package/src/_shims/node-types.js +3 -0
  134. package/src/_shims/node-types.mjs +3 -0
  135. package/src/_shims/registry.ts +67 -0
  136. package/src/_shims/web-runtime.ts +103 -0
  137. package/src/_shims/web-types.d.ts +83 -0
  138. package/src/_shims/web-types.js +3 -0
  139. package/src/_shims/web-types.mjs +3 -0
  140. package/src/core.ts +1200 -0
  141. package/src/error.ts +3 -3
  142. package/src/index.ts +172 -5
  143. package/src/resource.ts +3 -3
  144. package/src/resources/calls.ts +2 -3
  145. package/src/shims/node.ts +50 -0
  146. package/src/shims/web.ts +50 -0
  147. package/src/tsconfig.json +2 -2
  148. package/src/uploads.ts +255 -1
  149. package/src/version.ts +1 -1
  150. package/uploads.d.ts +74 -1
  151. package/uploads.d.ts.map +1 -1
  152. package/uploads.js +168 -3
  153. package/uploads.js.map +1 -1
  154. package/uploads.mjs +157 -1
  155. package/uploads.mjs.map +1 -1
  156. package/version.d.ts +1 -1
  157. package/version.js +1 -1
  158. package/version.mjs +1 -1
  159. package/api-promise.d.mts +0 -47
  160. package/api-promise.d.mts.map +0 -1
  161. package/api-promise.d.ts +0 -47
  162. package/api-promise.d.ts.map +0 -1
  163. package/api-promise.js +0 -84
  164. package/api-promise.js.map +0 -1
  165. package/api-promise.mjs +0 -80
  166. package/api-promise.mjs.map +0 -1
  167. package/client.d.mts +0 -186
  168. package/client.d.mts.map +0 -1
  169. package/client.d.ts +0 -186
  170. package/client.d.ts.map +0 -1
  171. package/client.js +0 -449
  172. package/client.js.map +0 -1
  173. package/client.mjs +0 -422
  174. package/client.mjs.map +0 -1
  175. package/error.d.mts +0 -47
  176. package/error.d.mts.map +0 -1
  177. package/index.d.mts.map +0 -1
  178. package/internal/builtin-types.d.mts +0 -65
  179. package/internal/builtin-types.d.mts.map +0 -1
  180. package/internal/builtin-types.d.ts +0 -65
  181. package/internal/builtin-types.d.ts.map +0 -1
  182. package/internal/builtin-types.js +0 -4
  183. package/internal/builtin-types.js.map +0 -1
  184. package/internal/builtin-types.mjs +0 -3
  185. package/internal/builtin-types.mjs.map +0 -1
  186. package/internal/detect-platform.d.mts +0 -15
  187. package/internal/detect-platform.d.mts.map +0 -1
  188. package/internal/detect-platform.d.ts +0 -15
  189. package/internal/detect-platform.d.ts.map +0 -1
  190. package/internal/detect-platform.js +0 -162
  191. package/internal/detect-platform.js.map +0 -1
  192. package/internal/detect-platform.mjs +0 -157
  193. package/internal/detect-platform.mjs.map +0 -1
  194. package/internal/errors.d.mts +0 -3
  195. package/internal/errors.d.mts.map +0 -1
  196. package/internal/errors.d.ts +0 -3
  197. package/internal/errors.d.ts.map +0 -1
  198. package/internal/errors.js +0 -26
  199. package/internal/errors.js.map +0 -1
  200. package/internal/errors.mjs +0 -21
  201. package/internal/errors.mjs.map +0 -1
  202. package/internal/headers.d.mts +0 -21
  203. package/internal/headers.d.mts.map +0 -1
  204. package/internal/headers.d.ts +0 -21
  205. package/internal/headers.d.ts.map +0 -1
  206. package/internal/headers.js +0 -77
  207. package/internal/headers.js.map +0 -1
  208. package/internal/headers.mjs +0 -72
  209. package/internal/headers.mjs.map +0 -1
  210. package/internal/parse.d.mts +0 -10
  211. package/internal/parse.d.mts.map +0 -1
  212. package/internal/parse.d.ts +0 -10
  213. package/internal/parse.d.ts.map +0 -1
  214. package/internal/parse.js +0 -28
  215. package/internal/parse.js.map +0 -1
  216. package/internal/parse.mjs +0 -24
  217. package/internal/parse.mjs.map +0 -1
  218. package/internal/polyfill/crypto.node.d.ts +0 -10
  219. package/internal/polyfill/crypto.node.js +0 -11
  220. package/internal/polyfill/crypto.node.mjs +0 -2
  221. package/internal/polyfill/file.node.d.ts +0 -9
  222. package/internal/polyfill/file.node.js +0 -17
  223. package/internal/polyfill/file.node.mjs +0 -9
  224. package/internal/request-options.d.mts +0 -34
  225. package/internal/request-options.d.mts.map +0 -1
  226. package/internal/request-options.d.ts +0 -34
  227. package/internal/request-options.d.ts.map +0 -1
  228. package/internal/request-options.js +0 -39
  229. package/internal/request-options.js.map +0 -1
  230. package/internal/request-options.mjs +0 -34
  231. package/internal/request-options.mjs.map +0 -1
  232. package/internal/shim-types.d.mts +0 -28
  233. package/internal/shim-types.d.ts +0 -28
  234. package/internal/shims.d.mts +0 -61
  235. package/internal/shims.d.mts.map +0 -1
  236. package/internal/shims.d.ts +0 -61
  237. package/internal/shims.d.ts.map +0 -1
  238. package/internal/shims.js +0 -101
  239. package/internal/shims.js.map +0 -1
  240. package/internal/shims.mjs +0 -92
  241. package/internal/shims.mjs.map +0 -1
  242. package/internal/types.d.mts +0 -68
  243. package/internal/types.d.mts.map +0 -1
  244. package/internal/types.d.ts +0 -68
  245. package/internal/types.d.ts.map +0 -1
  246. package/internal/types.js +0 -4
  247. package/internal/types.js.map +0 -1
  248. package/internal/types.mjs +0 -3
  249. package/internal/types.mjs.map +0 -1
  250. package/internal/uploads.d.mts +0 -73
  251. package/internal/uploads.d.mts.map +0 -1
  252. package/internal/uploads.d.ts +0 -73
  253. package/internal/uploads.d.ts.map +0 -1
  254. package/internal/uploads.js +0 -208
  255. package/internal/uploads.js.map +0 -1
  256. package/internal/uploads.mjs +0 -200
  257. package/internal/uploads.mjs.map +0 -1
  258. package/internal/utils/base64.d.mts +0 -3
  259. package/internal/utils/base64.d.mts.map +0 -1
  260. package/internal/utils/base64.d.ts +0 -3
  261. package/internal/utils/base64.d.ts.map +0 -1
  262. package/internal/utils/base64.js +0 -33
  263. package/internal/utils/base64.js.map +0 -1
  264. package/internal/utils/base64.mjs +0 -28
  265. package/internal/utils/base64.mjs.map +0 -1
  266. package/internal/utils/env.d.mts +0 -9
  267. package/internal/utils/env.d.mts.map +0 -1
  268. package/internal/utils/env.d.ts +0 -9
  269. package/internal/utils/env.d.ts.map +0 -1
  270. package/internal/utils/env.js +0 -22
  271. package/internal/utils/env.js.map +0 -1
  272. package/internal/utils/env.mjs +0 -18
  273. package/internal/utils/env.mjs.map +0 -1
  274. package/internal/utils/log.d.mts +0 -4
  275. package/internal/utils/log.d.mts.map +0 -1
  276. package/internal/utils/log.d.ts +0 -4
  277. package/internal/utils/log.d.ts.map +0 -1
  278. package/internal/utils/log.js +0 -47
  279. package/internal/utils/log.js.map +0 -1
  280. package/internal/utils/log.mjs +0 -43
  281. package/internal/utils/log.mjs.map +0 -1
  282. package/internal/utils/sleep.d.mts +0 -2
  283. package/internal/utils/sleep.d.mts.map +0 -1
  284. package/internal/utils/sleep.d.ts +0 -2
  285. package/internal/utils/sleep.d.ts.map +0 -1
  286. package/internal/utils/sleep.js +0 -7
  287. package/internal/utils/sleep.js.map +0 -1
  288. package/internal/utils/sleep.mjs +0 -3
  289. package/internal/utils/sleep.mjs.map +0 -1
  290. package/internal/utils/uuid.d.mts +0 -5
  291. package/internal/utils/uuid.d.mts.map +0 -1
  292. package/internal/utils/uuid.d.ts +0 -5
  293. package/internal/utils/uuid.d.ts.map +0 -1
  294. package/internal/utils/uuid.js +0 -15
  295. package/internal/utils/uuid.js.map +0 -1
  296. package/internal/utils/uuid.mjs +0 -11
  297. package/internal/utils/uuid.mjs.map +0 -1
  298. package/internal/utils/values.d.mts +0 -15
  299. package/internal/utils/values.d.mts.map +0 -1
  300. package/internal/utils/values.d.ts +0 -15
  301. package/internal/utils/values.d.ts.map +0 -1
  302. package/internal/utils/values.js +0 -100
  303. package/internal/utils/values.js.map +0 -1
  304. package/internal/utils/values.mjs +0 -84
  305. package/internal/utils/values.mjs.map +0 -1
  306. package/internal/utils.d.mts +0 -7
  307. package/internal/utils.d.mts.map +0 -1
  308. package/internal/utils.d.ts +0 -7
  309. package/internal/utils.d.ts.map +0 -1
  310. package/internal/utils.js.map +0 -1
  311. package/internal/utils.mjs +0 -8
  312. package/internal/utils.mjs.map +0 -1
  313. package/resource.d.mts +0 -6
  314. package/resource.d.mts.map +0 -1
  315. package/resources/calls.d.mts +0 -85
  316. package/resources/calls.d.mts.map +0 -1
  317. package/resources/index.d.mts +0 -2
  318. package/resources/index.d.mts.map +0 -1
  319. package/src/api-promise.ts +0 -92
  320. package/src/client.ts +0 -646
  321. package/src/internal/builtin-types.ts +0 -79
  322. package/src/internal/detect-platform.ts +0 -196
  323. package/src/internal/errors.ts +0 -22
  324. package/src/internal/headers.ts +0 -96
  325. package/src/internal/parse.ts +0 -41
  326. package/src/internal/polyfill/crypto.node.d.ts +0 -10
  327. package/src/internal/polyfill/crypto.node.js +0 -11
  328. package/src/internal/polyfill/crypto.node.mjs +0 -2
  329. package/src/internal/polyfill/file.node.d.ts +0 -9
  330. package/src/internal/polyfill/file.node.js +0 -17
  331. package/src/internal/polyfill/file.node.mjs +0 -9
  332. package/src/internal/request-options.ts +0 -67
  333. package/src/internal/shim-types.d.ts +0 -28
  334. package/src/internal/shims.ts +0 -145
  335. package/src/internal/types.ts +0 -98
  336. package/src/internal/uploads.ts +0 -307
  337. package/src/internal/utils/base64.ts +0 -37
  338. package/src/internal/utils/env.ts +0 -18
  339. package/src/internal/utils/log.ts +0 -49
  340. package/src/internal/utils/sleep.ts +0 -3
  341. package/src/internal/utils/uuid.ts +0 -13
  342. package/src/internal/utils/values.ts +0 -94
  343. package/src/internal/utils.ts +0 -8
  344. package/uploads.d.mts +0 -2
  345. package/uploads.d.mts.map +0 -1
  346. package/version.d.mts +0 -2
  347. package/version.d.mts.map +0 -1
package/src/error.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
- import { castToError } from './internal/errors';
3
+ import { castToError, Headers } from './core';
4
4
 
5
- export class PetstoreError extends Error {}
5
+ export class RoarkError extends Error {}
6
6
 
7
7
  export class APIError<
8
8
  TStatus extends number | undefined = number | undefined,
9
9
  THeaders extends Headers | undefined = Headers | undefined,
10
10
  TError extends Object | undefined = Object | undefined,
11
- > extends PetstoreError {
11
+ > extends RoarkError {
12
12
  /** HTTP status for the response that caused the error */
13
13
  readonly status: TStatus;
14
14
  /** HTTP headers for the response that caused the error */
package/src/index.ts CHANGED
@@ -1,12 +1,177 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
- export { Petstore as default } from './client';
3
+ import { type Agent } from './_shims/index';
4
+ import * as Core from './core';
5
+ import * as Errors from './error';
6
+ import * as Uploads from './uploads';
7
+ import * as API from './resources/index';
8
+ import { CallCreateParams, CallCreateResponse, Calls } from './resources/calls';
4
9
 
5
- export { type Uploadable, toFile } from './uploads';
6
- export { APIPromise } from './api-promise';
7
- export { Petstore, type ClientOptions } from './client';
10
+ export interface ClientOptions {
11
+ /**
12
+ * JWT token for authentication
13
+ */
14
+ bearerToken?: string | undefined;
15
+
16
+ /**
17
+ * Override the default base URL for the API, e.g., "https://api.example.com/v2/"
18
+ *
19
+ * Defaults to process.env['ROARK_BASE_URL'].
20
+ */
21
+ baseURL?: string | null | undefined;
22
+
23
+ /**
24
+ * The maximum amount of time (in milliseconds) that the client should wait for a response
25
+ * from the server before timing out a single request.
26
+ *
27
+ * Note that request timeouts are retried by default, so in a worst-case scenario you may wait
28
+ * much longer than this timeout before the promise succeeds or fails.
29
+ */
30
+ timeout?: number | undefined;
31
+
32
+ /**
33
+ * An HTTP agent used to manage HTTP(S) connections.
34
+ *
35
+ * If not provided, an agent will be constructed by default in the Node.js environment,
36
+ * otherwise no agent is used.
37
+ */
38
+ httpAgent?: Agent | undefined;
39
+
40
+ /**
41
+ * Specify a custom `fetch` function implementation.
42
+ *
43
+ * If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is
44
+ * defined globally.
45
+ */
46
+ fetch?: Core.Fetch | undefined;
47
+
48
+ /**
49
+ * The maximum number of times that the client will retry a request in case of a
50
+ * temporary failure, like a network error or a 5XX error from the server.
51
+ *
52
+ * @default 2
53
+ */
54
+ maxRetries?: number | undefined;
55
+
56
+ /**
57
+ * Default headers to include with every request to the API.
58
+ *
59
+ * These can be removed in individual requests by explicitly setting the
60
+ * header to `undefined` or `null` in request options.
61
+ */
62
+ defaultHeaders?: Core.Headers | undefined;
63
+
64
+ /**
65
+ * Default query parameters to include with every request to the API.
66
+ *
67
+ * These can be removed in individual requests by explicitly setting the
68
+ * param to `undefined` in request options.
69
+ */
70
+ defaultQuery?: Core.DefaultQuery | undefined;
71
+ }
72
+
73
+ /**
74
+ * API Client for interfacing with the Roark API.
75
+ */
76
+ export class Roark extends Core.APIClient {
77
+ bearerToken: string;
78
+
79
+ private _options: ClientOptions;
80
+
81
+ /**
82
+ * API Client for interfacing with the Roark API.
83
+ *
84
+ * @param {string | undefined} [opts.bearerToken=process.env['ROARK_API_BEARER_TOKEN'] ?? undefined]
85
+ * @param {string} [opts.baseURL=process.env['ROARK_BASE_URL'] ?? https://customer.api.roark.ai] - Override the default base URL for the API.
86
+ * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
87
+ * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
88
+ * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
89
+ * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
90
+ * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
91
+ * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
92
+ */
93
+ constructor({
94
+ baseURL = Core.readEnv('ROARK_BASE_URL'),
95
+ bearerToken = Core.readEnv('ROARK_API_BEARER_TOKEN'),
96
+ ...opts
97
+ }: ClientOptions = {}) {
98
+ if (bearerToken === undefined) {
99
+ throw new Errors.RoarkError(
100
+ "The ROARK_API_BEARER_TOKEN environment variable is missing or empty; either provide it, or instantiate the Roark client with an bearerToken option, like new Roark({ bearerToken: 'My Bearer Token' }).",
101
+ );
102
+ }
103
+
104
+ const options: ClientOptions = {
105
+ bearerToken,
106
+ ...opts,
107
+ baseURL: baseURL || `https://customer.api.roark.ai`,
108
+ };
109
+
110
+ super({
111
+ baseURL: options.baseURL!,
112
+ timeout: options.timeout ?? 60000 /* 1 minute */,
113
+ httpAgent: options.httpAgent,
114
+ maxRetries: options.maxRetries,
115
+ fetch: options.fetch,
116
+ });
117
+
118
+ this._options = options;
119
+
120
+ this.bearerToken = bearerToken;
121
+ }
122
+
123
+ calls: API.Calls = new API.Calls(this);
124
+
125
+ protected override defaultQuery(): Core.DefaultQuery | undefined {
126
+ return this._options.defaultQuery;
127
+ }
128
+
129
+ protected override defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers {
130
+ return {
131
+ ...super.defaultHeaders(opts),
132
+ ...this._options.defaultHeaders,
133
+ };
134
+ }
135
+
136
+ protected override authHeaders(opts: Core.FinalRequestOptions): Core.Headers {
137
+ return { Authorization: `Bearer ${this.bearerToken}` };
138
+ }
139
+
140
+ static Roark = this;
141
+ static DEFAULT_TIMEOUT = 60000; // 1 minute
142
+
143
+ static RoarkError = Errors.RoarkError;
144
+ static APIError = Errors.APIError;
145
+ static APIConnectionError = Errors.APIConnectionError;
146
+ static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
147
+ static APIUserAbortError = Errors.APIUserAbortError;
148
+ static NotFoundError = Errors.NotFoundError;
149
+ static ConflictError = Errors.ConflictError;
150
+ static RateLimitError = Errors.RateLimitError;
151
+ static BadRequestError = Errors.BadRequestError;
152
+ static AuthenticationError = Errors.AuthenticationError;
153
+ static InternalServerError = Errors.InternalServerError;
154
+ static PermissionDeniedError = Errors.PermissionDeniedError;
155
+ static UnprocessableEntityError = Errors.UnprocessableEntityError;
156
+
157
+ static toFile = Uploads.toFile;
158
+ static fileFromPath = Uploads.fileFromPath;
159
+ }
160
+
161
+ Roark.Calls = Calls;
162
+ export declare namespace Roark {
163
+ export type RequestOptions = Core.RequestOptions;
164
+
165
+ export {
166
+ Calls as Calls,
167
+ type CallCreateResponse as CallCreateResponse,
168
+ type CallCreateParams as CallCreateParams,
169
+ };
170
+ }
171
+
172
+ export { toFile, fileFromPath } from './uploads';
8
173
  export {
9
- PetstoreError,
174
+ RoarkError,
10
175
  APIError,
11
176
  APIConnectionError,
12
177
  APIConnectionTimeoutError,
@@ -20,3 +185,5 @@ export {
20
185
  PermissionDeniedError,
21
186
  UnprocessableEntityError,
22
187
  } from './error';
188
+
189
+ export default Roark;
package/src/resource.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
- import type { Petstore } from './client';
3
+ import type { Roark } from './index';
4
4
 
5
5
  export class APIResource {
6
- protected _client: Petstore;
6
+ protected _client: Roark;
7
7
 
8
- constructor(client: Petstore) {
8
+ constructor(client: Roark) {
9
9
  this._client = client;
10
10
  }
11
11
  }
@@ -1,14 +1,13 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
3
  import { APIResource } from '../resource';
4
- import { APIPromise } from '../api-promise';
5
- import { RequestOptions } from '../internal/request-options';
4
+ import * as Core from '../core';
6
5
 
7
6
  export class Calls extends APIResource {
8
7
  /**
9
8
  * Upload a call recording.
10
9
  */
11
- create(body: CallCreateParams, options?: RequestOptions): APIPromise<CallCreateResponse> {
10
+ create(body: CallCreateParams, options?: Core.RequestOptions): Core.APIPromise<CallCreateResponse> {
12
11
  return this._client.post('/call', { body, ...options });
13
12
  }
14
13
  }
@@ -0,0 +1,50 @@
1
+ // @ts-ignore
2
+ import * as types from '../_shims/node-types';
3
+ import { setShims } from '../_shims/registry';
4
+ import { getRuntime } from '../_shims/node-runtime';
5
+ setShims(getRuntime());
6
+
7
+ declare module '../_shims/manual-types' {
8
+ export namespace manual {
9
+ // @ts-ignore
10
+ export type Agent = types.Agent;
11
+ // @ts-ignore
12
+ export import fetch = types.fetch;
13
+ // @ts-ignore
14
+ export type Request = types.Request;
15
+ // @ts-ignore
16
+ export type RequestInfo = types.RequestInfo;
17
+ // @ts-ignore
18
+ export type RequestInit = types.RequestInit;
19
+ // @ts-ignore
20
+ export type Response = types.Response;
21
+ // @ts-ignore
22
+ export type ResponseInit = types.ResponseInit;
23
+ // @ts-ignore
24
+ export type ResponseType = types.ResponseType;
25
+ // @ts-ignore
26
+ export type BodyInit = types.BodyInit;
27
+ // @ts-ignore
28
+ export type Headers = types.Headers;
29
+ // @ts-ignore
30
+ export type HeadersInit = types.HeadersInit;
31
+ // @ts-ignore
32
+ export type BlobPropertyBag = types.BlobPropertyBag;
33
+ // @ts-ignore
34
+ export type FilePropertyBag = types.FilePropertyBag;
35
+ // @ts-ignore
36
+ export type FileFromPathOptions = types.FileFromPathOptions;
37
+ // @ts-ignore
38
+ export import FormData = types.FormData;
39
+ // @ts-ignore
40
+ export import File = types.File;
41
+ // @ts-ignore
42
+ export import Blob = types.Blob;
43
+ // @ts-ignore
44
+ export type Readable = types.Readable;
45
+ // @ts-ignore
46
+ export type FsReadStream = types.FsReadStream;
47
+ // @ts-ignore
48
+ export import ReadableStream = types.ReadableStream;
49
+ }
50
+ }
@@ -0,0 +1,50 @@
1
+ // @ts-ignore
2
+ import * as types from '../_shims/web-types';
3
+ import { setShims } from '../_shims/registry';
4
+ import { getRuntime } from '../_shims/web-runtime';
5
+ setShims(getRuntime({ manuallyImported: true }));
6
+
7
+ declare module '../_shims/manual-types' {
8
+ export namespace manual {
9
+ // @ts-ignore
10
+ export type Agent = types.Agent;
11
+ // @ts-ignore
12
+ export import fetch = types.fetch;
13
+ // @ts-ignore
14
+ export type Request = types.Request;
15
+ // @ts-ignore
16
+ export type RequestInfo = types.RequestInfo;
17
+ // @ts-ignore
18
+ export type RequestInit = types.RequestInit;
19
+ // @ts-ignore
20
+ export type Response = types.Response;
21
+ // @ts-ignore
22
+ export type ResponseInit = types.ResponseInit;
23
+ // @ts-ignore
24
+ export type ResponseType = types.ResponseType;
25
+ // @ts-ignore
26
+ export type BodyInit = types.BodyInit;
27
+ // @ts-ignore
28
+ export type Headers = types.Headers;
29
+ // @ts-ignore
30
+ export type HeadersInit = types.HeadersInit;
31
+ // @ts-ignore
32
+ export type BlobPropertyBag = types.BlobPropertyBag;
33
+ // @ts-ignore
34
+ export type FilePropertyBag = types.FilePropertyBag;
35
+ // @ts-ignore
36
+ export type FileFromPathOptions = types.FileFromPathOptions;
37
+ // @ts-ignore
38
+ export import FormData = types.FormData;
39
+ // @ts-ignore
40
+ export import File = types.File;
41
+ // @ts-ignore
42
+ export import Blob = types.Blob;
43
+ // @ts-ignore
44
+ export type Readable = types.Readable;
45
+ // @ts-ignore
46
+ export type FsReadStream = types.FsReadStream;
47
+ // @ts-ignore
48
+ export import ReadableStream = types.ReadableStream;
49
+ }
50
+ }
package/src/tsconfig.json CHANGED
@@ -4,8 +4,8 @@
4
4
  // via declaration maps
5
5
  "include": ["index.ts"],
6
6
  "compilerOptions": {
7
- "target": "ES2015",
8
- "lib": ["DOM", "DOM.Iterable", "ES2018"],
7
+ "target": "es2015",
8
+ "lib": ["DOM"],
9
9
  "moduleResolution": "node"
10
10
  }
11
11
  }
package/src/uploads.ts CHANGED
@@ -1 +1,255 @@
1
- export { type Uploadable, toFile } from './internal/uploads';
1
+ import { type RequestOptions } from './core';
2
+ import {
3
+ FormData,
4
+ File,
5
+ type Blob,
6
+ type FilePropertyBag,
7
+ getMultipartRequestOptions,
8
+ type FsReadStream,
9
+ isFsReadStream,
10
+ } from './_shims/index';
11
+ import { MultipartBody } from './_shims/MultipartBody';
12
+ export { fileFromPath } from './_shims/index';
13
+
14
+ type BlobLikePart = string | ArrayBuffer | ArrayBufferView | BlobLike | Uint8Array | DataView;
15
+ export type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | Uint8Array | DataView;
16
+
17
+ /**
18
+ * Typically, this is a native "File" class.
19
+ *
20
+ * We provide the {@link toFile} utility to convert a variety of objects
21
+ * into the File class.
22
+ *
23
+ * For convenience, you can also pass a fetch Response, or in Node,
24
+ * the result of fs.createReadStream().
25
+ */
26
+ export type Uploadable = FileLike | ResponseLike | FsReadStream;
27
+
28
+ /**
29
+ * Intended to match web.Blob, node.Blob, node-fetch.Blob, etc.
30
+ */
31
+ export interface BlobLike {
32
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/size) */
33
+ readonly size: number;
34
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/type) */
35
+ readonly type: string;
36
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/text) */
37
+ text(): Promise<string>;
38
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */
39
+ slice(start?: number, end?: number): BlobLike;
40
+ // unfortunately @types/node-fetch@^2.6.4 doesn't type the arrayBuffer method
41
+ }
42
+
43
+ /**
44
+ * Intended to match web.File, node.File, node-fetch.File, etc.
45
+ */
46
+ export interface FileLike extends BlobLike {
47
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/lastModified) */
48
+ readonly lastModified: number;
49
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/name) */
50
+ readonly name: string;
51
+ }
52
+
53
+ /**
54
+ * Intended to match web.Response, node.Response, node-fetch.Response, etc.
55
+ */
56
+ export interface ResponseLike {
57
+ url: string;
58
+ blob(): Promise<BlobLike>;
59
+ }
60
+
61
+ export const isResponseLike = (value: any): value is ResponseLike =>
62
+ value != null &&
63
+ typeof value === 'object' &&
64
+ typeof value.url === 'string' &&
65
+ typeof value.blob === 'function';
66
+
67
+ export const isFileLike = (value: any): value is FileLike =>
68
+ value != null &&
69
+ typeof value === 'object' &&
70
+ typeof value.name === 'string' &&
71
+ typeof value.lastModified === 'number' &&
72
+ isBlobLike(value);
73
+
74
+ /**
75
+ * The BlobLike type omits arrayBuffer() because @types/node-fetch@^2.6.4 lacks it; but this check
76
+ * adds the arrayBuffer() method type because it is available and used at runtime
77
+ */
78
+ export const isBlobLike = (value: any): value is BlobLike & { arrayBuffer(): Promise<ArrayBuffer> } =>
79
+ value != null &&
80
+ typeof value === 'object' &&
81
+ typeof value.size === 'number' &&
82
+ typeof value.type === 'string' &&
83
+ typeof value.text === 'function' &&
84
+ typeof value.slice === 'function' &&
85
+ typeof value.arrayBuffer === 'function';
86
+
87
+ export const isUploadable = (value: any): value is Uploadable => {
88
+ return isFileLike(value) || isResponseLike(value) || isFsReadStream(value);
89
+ };
90
+
91
+ export type ToFileInput = Uploadable | Exclude<BlobLikePart, string> | AsyncIterable<BlobLikePart>;
92
+
93
+ /**
94
+ * Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
95
+ * @param value the raw content of the file. Can be an {@link Uploadable}, {@link BlobLikePart}, or {@link AsyncIterable} of {@link BlobLikePart}s
96
+ * @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
97
+ * @param {Object=} options additional properties
98
+ * @param {string=} options.type the MIME type of the content
99
+ * @param {number=} options.lastModified the last modified timestamp
100
+ * @returns a {@link File} with the given properties
101
+ */
102
+ export async function toFile(
103
+ value: ToFileInput | PromiseLike<ToFileInput>,
104
+ name?: string | null | undefined,
105
+ options?: FilePropertyBag | undefined,
106
+ ): Promise<FileLike> {
107
+ // If it's a promise, resolve it.
108
+ value = await value;
109
+
110
+ // If we've been given a `File` we don't need to do anything
111
+ if (isFileLike(value)) {
112
+ return value;
113
+ }
114
+
115
+ if (isResponseLike(value)) {
116
+ const blob = await value.blob();
117
+ name ||= new URL(value.url).pathname.split(/[\\/]/).pop() ?? 'unknown_file';
118
+
119
+ // we need to convert the `Blob` into an array buffer because the `Blob` class
120
+ // that `node-fetch` defines is incompatible with the web standard which results
121
+ // in `new File` interpreting it as a string instead of binary data.
122
+ const data = isBlobLike(blob) ? [(await blob.arrayBuffer()) as any] : [blob];
123
+
124
+ return new File(data, name, options);
125
+ }
126
+
127
+ const bits = await getBytes(value);
128
+
129
+ name ||= getName(value) ?? 'unknown_file';
130
+
131
+ if (!options?.type) {
132
+ const type = (bits[0] as any)?.type;
133
+ if (typeof type === 'string') {
134
+ options = { ...options, type };
135
+ }
136
+ }
137
+
138
+ return new File(bits, name, options);
139
+ }
140
+
141
+ async function getBytes(value: ToFileInput): Promise<Array<BlobPart>> {
142
+ let parts: Array<BlobPart> = [];
143
+ if (
144
+ typeof value === 'string' ||
145
+ ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.
146
+ value instanceof ArrayBuffer
147
+ ) {
148
+ parts.push(value);
149
+ } else if (isBlobLike(value)) {
150
+ parts.push(await value.arrayBuffer());
151
+ } else if (
152
+ isAsyncIterableIterator(value) // includes Readable, ReadableStream, etc.
153
+ ) {
154
+ for await (const chunk of value) {
155
+ parts.push(chunk as BlobPart); // TODO, consider validating?
156
+ }
157
+ } else {
158
+ throw new Error(
159
+ `Unexpected data type: ${typeof value}; constructor: ${value?.constructor
160
+ ?.name}; props: ${propsForError(value)}`,
161
+ );
162
+ }
163
+
164
+ return parts;
165
+ }
166
+
167
+ function propsForError(value: any): string {
168
+ const props = Object.getOwnPropertyNames(value);
169
+ return `[${props.map((p) => `"${p}"`).join(', ')}]`;
170
+ }
171
+
172
+ function getName(value: any): string | undefined {
173
+ return (
174
+ getStringFromMaybeBuffer(value.name) ||
175
+ getStringFromMaybeBuffer(value.filename) ||
176
+ // For fs.ReadStream
177
+ getStringFromMaybeBuffer(value.path)?.split(/[\\/]/).pop()
178
+ );
179
+ }
180
+
181
+ const getStringFromMaybeBuffer = (x: string | Buffer | unknown): string | undefined => {
182
+ if (typeof x === 'string') return x;
183
+ if (typeof Buffer !== 'undefined' && x instanceof Buffer) return String(x);
184
+ return undefined;
185
+ };
186
+
187
+ const isAsyncIterableIterator = (value: any): value is AsyncIterableIterator<unknown> =>
188
+ value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';
189
+
190
+ export const isMultipartBody = (body: any): body is MultipartBody =>
191
+ body && typeof body === 'object' && body.body && body[Symbol.toStringTag] === 'MultipartBody';
192
+
193
+ /**
194
+ * Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
195
+ * Otherwise returns the request as is.
196
+ */
197
+ export const maybeMultipartFormRequestOptions = async <T = Record<string, unknown>>(
198
+ opts: RequestOptions<T>,
199
+ ): Promise<RequestOptions<T | MultipartBody>> => {
200
+ if (!hasUploadableValue(opts.body)) return opts;
201
+
202
+ const form = await createForm(opts.body);
203
+ return getMultipartRequestOptions(form, opts);
204
+ };
205
+
206
+ export const multipartFormRequestOptions = async <T = Record<string, unknown>>(
207
+ opts: RequestOptions<T>,
208
+ ): Promise<RequestOptions<T | MultipartBody>> => {
209
+ const form = await createForm(opts.body);
210
+ return getMultipartRequestOptions(form, opts);
211
+ };
212
+
213
+ export const createForm = async <T = Record<string, unknown>>(body: T | undefined): Promise<FormData> => {
214
+ const form = new FormData();
215
+ await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));
216
+ return form;
217
+ };
218
+
219
+ const hasUploadableValue = (value: unknown): boolean => {
220
+ if (isUploadable(value)) return true;
221
+ if (Array.isArray(value)) return value.some(hasUploadableValue);
222
+ if (value && typeof value === 'object') {
223
+ for (const k in value) {
224
+ if (hasUploadableValue((value as any)[k])) return true;
225
+ }
226
+ }
227
+ return false;
228
+ };
229
+
230
+ const addFormValue = async (form: FormData, key: string, value: unknown): Promise<void> => {
231
+ if (value === undefined) return;
232
+ if (value == null) {
233
+ throw new TypeError(
234
+ `Received null for "${key}"; to pass null in FormData, you must use the string 'null'`,
235
+ );
236
+ }
237
+
238
+ // TODO: make nested formats configurable
239
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
240
+ form.append(key, String(value));
241
+ } else if (isUploadable(value)) {
242
+ const file = await toFile(value);
243
+ form.append(key, file as File);
244
+ } else if (Array.isArray(value)) {
245
+ await Promise.all(value.map((entry) => addFormValue(form, key + '[]', entry)));
246
+ } else if (typeof value === 'object') {
247
+ await Promise.all(
248
+ Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop)),
249
+ );
250
+ } else {
251
+ throw new TypeError(
252
+ `Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`,
253
+ );
254
+ }
255
+ };
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.1.0-alpha.1'; // x-release-please-version
1
+ export const VERSION = '0.1.0-alpha.2'; // x-release-please-version