@valtown/sdk 0.1.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (347) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/LICENSE +7 -0
  3. package/README.md +288 -0
  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/_shims/auto/runtime-bun.js +21 -0
  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 +90 -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 +239 -0
  75. package/core.d.ts.map +1 -0
  76. package/core.js +881 -0
  77. package/core.js.map +1 -0
  78. package/core.mjs +850 -0
  79. package/core.mjs.map +1 -0
  80. package/error.d.ts +53 -0
  81. package/error.d.ts.map +1 -0
  82. package/error.js +143 -0
  83. package/error.js.map +1 -0
  84. package/error.mjs +127 -0
  85. package/error.mjs.map +1 -0
  86. package/index.d.mts +143 -0
  87. package/index.d.ts +143 -0
  88. package/index.d.ts.map +1 -0
  89. package/index.js +124 -0
  90. package/index.js.map +1 -0
  91. package/index.mjs +96 -0
  92. package/index.mjs.map +1 -0
  93. package/package.json +104 -0
  94. package/pagination.d.ts +24 -0
  95. package/pagination.d.ts.map +1 -0
  96. package/pagination.js +35 -0
  97. package/pagination.js.map +1 -0
  98. package/pagination.mjs +31 -0
  99. package/pagination.mjs.map +1 -0
  100. package/resource.d.ts +6 -0
  101. package/resource.d.ts.map +1 -0
  102. package/resource.js +11 -0
  103. package/resource.js.map +1 -0
  104. package/resource.mjs +7 -0
  105. package/resource.mjs.map +1 -0
  106. package/resources/alias/alias.d.ts +9 -0
  107. package/resources/alias/alias.d.ts.map +1 -0
  108. package/resources/alias/alias.js +40 -0
  109. package/resources/alias/alias.js.map +1 -0
  110. package/resources/alias/alias.mjs +13 -0
  111. package/resources/alias/alias.mjs.map +1 -0
  112. package/resources/alias/index.d.ts +3 -0
  113. package/resources/alias/index.d.ts.map +1 -0
  114. package/resources/alias/index.js +9 -0
  115. package/resources/alias/index.js.map +1 -0
  116. package/resources/alias/index.mjs +4 -0
  117. package/resources/alias/index.mjs.map +1 -0
  118. package/resources/alias/username/index.d.ts +3 -0
  119. package/resources/alias/username/index.d.ts.map +1 -0
  120. package/resources/alias/username/index.js +9 -0
  121. package/resources/alias/username/index.js.map +1 -0
  122. package/resources/alias/username/index.mjs +4 -0
  123. package/resources/alias/username/index.mjs.map +1 -0
  124. package/resources/alias/username/username.d.ts +16 -0
  125. package/resources/alias/username/username.d.ts.map +1 -0
  126. package/resources/alias/username/username.js +46 -0
  127. package/resources/alias/username/username.js.map +1 -0
  128. package/resources/alias/username/username.mjs +19 -0
  129. package/resources/alias/username/username.mjs.map +1 -0
  130. package/resources/alias/username/val-name.d.ts +42 -0
  131. package/resources/alias/username/val-name.d.ts.map +1 -0
  132. package/resources/alias/username/val-name.js +17 -0
  133. package/resources/alias/username/val-name.js.map +1 -0
  134. package/resources/alias/username/val-name.mjs +13 -0
  135. package/resources/alias/username/val-name.mjs.map +1 -0
  136. package/resources/blobs.d.ts +13 -0
  137. package/resources/blobs.d.ts.map +1 -0
  138. package/resources/blobs.js +27 -0
  139. package/resources/blobs.js.map +1 -0
  140. package/resources/blobs.mjs +23 -0
  141. package/resources/blobs.mjs.map +1 -0
  142. package/resources/emails.d.ts +77 -0
  143. package/resources/emails.d.ts.map +1 -0
  144. package/resources/emails.js +18 -0
  145. package/resources/emails.js.map +1 -0
  146. package/resources/emails.mjs +14 -0
  147. package/resources/emails.mjs.map +1 -0
  148. package/resources/evals.d.ts +19 -0
  149. package/resources/evals.d.ts.map +1 -0
  150. package/resources/evals.js +18 -0
  151. package/resources/evals.js.map +1 -0
  152. package/resources/evals.mjs +14 -0
  153. package/resources/evals.mjs.map +1 -0
  154. package/resources/index.d.ts +11 -0
  155. package/resources/index.d.ts.map +1 -0
  156. package/resources/index.js +38 -0
  157. package/resources/index.js.map +1 -0
  158. package/resources/index.mjs +12 -0
  159. package/resources/index.mjs.map +1 -0
  160. package/resources/me/comments.d.ts +55 -0
  161. package/resources/me/comments.d.ts.map +1 -0
  162. package/resources/me/comments.js +49 -0
  163. package/resources/me/comments.js.map +1 -0
  164. package/resources/me/comments.mjs +21 -0
  165. package/resources/me/comments.mjs.map +1 -0
  166. package/resources/me/index.d.ts +6 -0
  167. package/resources/me/index.d.ts.map +1 -0
  168. package/resources/me/index.js +18 -0
  169. package/resources/me/index.js.map +1 -0
  170. package/resources/me/index.mjs +7 -0
  171. package/resources/me/index.mjs.map +1 -0
  172. package/resources/me/likes.d.ts +46 -0
  173. package/resources/me/likes.d.ts.map +1 -0
  174. package/resources/me/likes.js +46 -0
  175. package/resources/me/likes.js.map +1 -0
  176. package/resources/me/likes.mjs +18 -0
  177. package/resources/me/likes.mjs.map +1 -0
  178. package/resources/me/me.d.ts +28 -0
  179. package/resources/me/me.d.ts.map +1 -0
  180. package/resources/me/me.js +52 -0
  181. package/resources/me/me.js.map +1 -0
  182. package/resources/me/me.mjs +25 -0
  183. package/resources/me/me.mjs.map +1 -0
  184. package/resources/me/profile.d.ts +32 -0
  185. package/resources/me/profile.d.ts.map +1 -0
  186. package/resources/me/profile.js +17 -0
  187. package/resources/me/profile.js.map +1 -0
  188. package/resources/me/profile.mjs +13 -0
  189. package/resources/me/profile.mjs.map +1 -0
  190. package/resources/me/references.d.ts +41 -0
  191. package/resources/me/references.d.ts.map +1 -0
  192. package/resources/me/references.js +49 -0
  193. package/resources/me/references.js.map +1 -0
  194. package/resources/me/references.mjs +21 -0
  195. package/resources/me/references.mjs.map +1 -0
  196. package/resources/search/index.d.ts +3 -0
  197. package/resources/search/index.d.ts.map +1 -0
  198. package/resources/search/index.js +10 -0
  199. package/resources/search/index.js.map +1 -0
  200. package/resources/search/index.mjs +4 -0
  201. package/resources/search/index.mjs.map +1 -0
  202. package/resources/search/search.d.ts +12 -0
  203. package/resources/search/search.d.ts.map +1 -0
  204. package/resources/search/search.js +41 -0
  205. package/resources/search/search.js.map +1 -0
  206. package/resources/search/search.mjs +14 -0
  207. package/resources/search/search.mjs.map +1 -0
  208. package/resources/search/vals.d.ts +51 -0
  209. package/resources/search/vals.d.ts.map +1 -0
  210. package/resources/search/vals.js +46 -0
  211. package/resources/search/vals.js.map +1 -0
  212. package/resources/search/vals.mjs +18 -0
  213. package/resources/search/vals.mjs.map +1 -0
  214. package/resources/shared.d.ts +19 -0
  215. package/resources/shared.d.ts.map +1 -0
  216. package/resources/shared.js +4 -0
  217. package/resources/shared.js.map +1 -0
  218. package/resources/shared.mjs +3 -0
  219. package/resources/shared.mjs.map +1 -0
  220. package/resources/sqlite.d.ts +54 -0
  221. package/resources/sqlite.d.ts.map +1 -0
  222. package/resources/sqlite.js +25 -0
  223. package/resources/sqlite.js.map +1 -0
  224. package/resources/sqlite.mjs +21 -0
  225. package/resources/sqlite.mjs.map +1 -0
  226. package/resources/users/index.d.ts +3 -0
  227. package/resources/users/index.d.ts.map +1 -0
  228. package/resources/users/index.js +10 -0
  229. package/resources/users/index.js.map +1 -0
  230. package/resources/users/index.mjs +4 -0
  231. package/resources/users/index.mjs.map +1 -0
  232. package/resources/users/users.d.ts +18 -0
  233. package/resources/users/users.d.ts.map +1 -0
  234. package/resources/users/users.js +47 -0
  235. package/resources/users/users.js.map +1 -0
  236. package/resources/users/users.mjs +20 -0
  237. package/resources/users/users.mjs.map +1 -0
  238. package/resources/users/vals.d.ts +46 -0
  239. package/resources/users/vals.d.ts.map +1 -0
  240. package/resources/users/vals.js +49 -0
  241. package/resources/users/vals.js.map +1 -0
  242. package/resources/users/vals.mjs +21 -0
  243. package/resources/users/vals.mjs.map +1 -0
  244. package/resources/vals/index.d.ts +3 -0
  245. package/resources/vals/index.d.ts.map +1 -0
  246. package/resources/vals/index.js +10 -0
  247. package/resources/vals/index.js.map +1 -0
  248. package/resources/vals/index.mjs +4 -0
  249. package/resources/vals/index.mjs.map +1 -0
  250. package/resources/vals/vals.d.ts +150 -0
  251. package/resources/vals/vals.d.ts.map +1 -0
  252. package/resources/vals/vals.js +109 -0
  253. package/resources/vals/vals.js.map +1 -0
  254. package/resources/vals/vals.mjs +82 -0
  255. package/resources/vals/vals.mjs.map +1 -0
  256. package/resources/vals/versions.d.ts +110 -0
  257. package/resources/vals/versions.d.ts.map +1 -0
  258. package/resources/vals/versions.js +70 -0
  259. package/resources/vals/versions.js.map +1 -0
  260. package/resources/vals/versions.mjs +42 -0
  261. package/resources/vals/versions.mjs.map +1 -0
  262. package/shims/node.d.ts +29 -0
  263. package/shims/node.d.ts.map +1 -0
  264. package/shims/node.js +31 -0
  265. package/shims/node.js.map +1 -0
  266. package/shims/node.mjs +5 -0
  267. package/shims/node.mjs.map +1 -0
  268. package/shims/web.d.ts +26 -0
  269. package/shims/web.d.ts.map +1 -0
  270. package/shims/web.js +31 -0
  271. package/shims/web.js.map +1 -0
  272. package/shims/web.mjs +5 -0
  273. package/shims/web.mjs.map +1 -0
  274. package/src/_shims/MultipartBody.ts +9 -0
  275. package/src/_shims/README.md +46 -0
  276. package/src/_shims/auto/runtime-bun.ts +4 -0
  277. package/src/_shims/auto/runtime-node.ts +4 -0
  278. package/src/_shims/auto/runtime.ts +4 -0
  279. package/src/_shims/auto/types-node.ts +4 -0
  280. package/src/_shims/auto/types.d.ts +101 -0
  281. package/src/_shims/auto/types.js +3 -0
  282. package/src/_shims/auto/types.mjs +3 -0
  283. package/src/_shims/bun-runtime.ts +14 -0
  284. package/src/_shims/index.d.ts +81 -0
  285. package/src/_shims/index.js +13 -0
  286. package/src/_shims/index.mjs +7 -0
  287. package/src/_shims/manual-types.d.ts +12 -0
  288. package/src/_shims/manual-types.js +3 -0
  289. package/src/_shims/manual-types.mjs +3 -0
  290. package/src/_shims/node-runtime.ts +83 -0
  291. package/src/_shims/node-types.d.ts +42 -0
  292. package/src/_shims/node-types.js +3 -0
  293. package/src/_shims/node-types.mjs +3 -0
  294. package/src/_shims/registry.ts +67 -0
  295. package/src/_shims/web-runtime.ts +103 -0
  296. package/src/_shims/web-types.d.ts +83 -0
  297. package/src/_shims/web-types.js +3 -0
  298. package/src/_shims/web-types.mjs +3 -0
  299. package/src/core.ts +1165 -0
  300. package/src/error.ts +146 -0
  301. package/src/index.ts +227 -0
  302. package/src/lib/.keep +4 -0
  303. package/src/pagination.ts +62 -0
  304. package/src/resource.ts +11 -0
  305. package/src/resources/alias/alias.ts +12 -0
  306. package/src/resources/alias/index.ts +4 -0
  307. package/src/resources/alias/username/index.ts +4 -0
  308. package/src/resources/alias/username/username.ts +22 -0
  309. package/src/resources/alias/username/val-name.ts +65 -0
  310. package/src/resources/blobs.ts +26 -0
  311. package/src/resources/emails.ts +123 -0
  312. package/src/resources/evals.ts +39 -0
  313. package/src/resources/index.ts +23 -0
  314. package/src/resources/me/comments.ts +83 -0
  315. package/src/resources/me/index.ts +17 -0
  316. package/src/resources/me/likes.ts +65 -0
  317. package/src/resources/me/me.ts +31 -0
  318. package/src/resources/me/profile.ts +42 -0
  319. package/src/resources/me/references.ts +65 -0
  320. package/src/resources/search/index.ts +4 -0
  321. package/src/resources/search/search.ts +15 -0
  322. package/src/resources/search/vals.ts +72 -0
  323. package/src/resources/shared.ts +23 -0
  324. package/src/resources/sqlite.ts +77 -0
  325. package/src/resources/users/index.ts +4 -0
  326. package/src/resources/users/users.ts +24 -0
  327. package/src/resources/users/vals.ts +69 -0
  328. package/src/resources/vals/index.ts +24 -0
  329. package/src/resources/vals/vals.ts +267 -0
  330. package/src/resources/vals/versions.ts +181 -0
  331. package/src/shims/node.ts +50 -0
  332. package/src/shims/web.ts +50 -0
  333. package/src/tsconfig.json +11 -0
  334. package/src/uploads.ts +248 -0
  335. package/src/version.ts +1 -0
  336. package/uploads.d.ts +75 -0
  337. package/uploads.d.ts.map +1 -0
  338. package/uploads.js +165 -0
  339. package/uploads.js.map +1 -0
  340. package/uploads.mjs +152 -0
  341. package/uploads.mjs.map +1 -0
  342. package/version.d.ts +2 -0
  343. package/version.d.ts.map +1 -0
  344. package/version.js +5 -0
  345. package/version.js.map +1 -0
  346. package/version.mjs +2 -0
  347. package/version.mjs.map +1 -0
package/src/error.ts ADDED
@@ -0,0 +1,146 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { castToError, Headers } from './core';
4
+
5
+ export class ValTownError extends Error {}
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
+ ) {
18
+ super(`${APIError.makeMessage(status, error, message)}`);
19
+ this.status = status;
20
+ this.headers = headers;
21
+ this.error = error;
22
+ }
23
+
24
+ private static makeMessage(status: number | undefined, error: any, message: string | undefined) {
25
+ const msg =
26
+ error?.message ?
27
+ typeof error.message === 'string' ?
28
+ error.message
29
+ : JSON.stringify(error.message)
30
+ : error ? JSON.stringify(error)
31
+ : message;
32
+
33
+ if (status && msg) {
34
+ return `${status} ${msg}`;
35
+ }
36
+ if (status) {
37
+ return `${status} status code (no body)`;
38
+ }
39
+ if (msg) {
40
+ return msg;
41
+ }
42
+ return '(no status code or body)';
43
+ }
44
+
45
+ static generate(
46
+ status: number | undefined,
47
+ errorResponse: Object | undefined,
48
+ message: string | undefined,
49
+ headers: Headers | undefined,
50
+ ) {
51
+ if (!status) {
52
+ return new APIConnectionError({ cause: castToError(errorResponse) });
53
+ }
54
+
55
+ const error = errorResponse as Record<string, any>;
56
+
57
+ if (status === 400) {
58
+ return new BadRequestError(status, error, message, headers);
59
+ }
60
+
61
+ if (status === 401) {
62
+ return new AuthenticationError(status, error, message, headers);
63
+ }
64
+
65
+ if (status === 403) {
66
+ return new PermissionDeniedError(status, error, message, headers);
67
+ }
68
+
69
+ if (status === 404) {
70
+ return new NotFoundError(status, error, message, headers);
71
+ }
72
+
73
+ if (status === 409) {
74
+ return new ConflictError(status, error, message, headers);
75
+ }
76
+
77
+ if (status === 422) {
78
+ return new UnprocessableEntityError(status, error, message, headers);
79
+ }
80
+
81
+ if (status === 429) {
82
+ return new RateLimitError(status, error, message, headers);
83
+ }
84
+
85
+ if (status >= 500) {
86
+ return new InternalServerError(status, error, message, headers);
87
+ }
88
+
89
+ return new APIError(status, error, message, headers);
90
+ }
91
+ }
92
+
93
+ export class APIUserAbortError extends APIError {
94
+ override readonly status: undefined = undefined;
95
+
96
+ constructor({ message }: { message?: string } = {}) {
97
+ super(undefined, undefined, message || 'Request was aborted.', undefined);
98
+ }
99
+ }
100
+
101
+ export class APIConnectionError extends APIError {
102
+ override readonly status: undefined = undefined;
103
+
104
+ constructor({ message, cause }: { message?: string; cause?: Error | undefined }) {
105
+ super(undefined, undefined, message || 'Connection error.', undefined);
106
+ // in some environments the 'cause' property is already declared
107
+ // @ts-ignore
108
+ if (cause) this.cause = cause;
109
+ }
110
+ }
111
+
112
+ export class APIConnectionTimeoutError extends APIConnectionError {
113
+ constructor({ message }: { message?: string } = {}) {
114
+ super({ message: message ?? 'Request timed out.' });
115
+ }
116
+ }
117
+
118
+ export class BadRequestError extends APIError {
119
+ override readonly status: 400 = 400;
120
+ }
121
+
122
+ export class AuthenticationError extends APIError {
123
+ override readonly status: 401 = 401;
124
+ }
125
+
126
+ export class PermissionDeniedError extends APIError {
127
+ override readonly status: 403 = 403;
128
+ }
129
+
130
+ export class NotFoundError extends APIError {
131
+ override readonly status: 404 = 404;
132
+ }
133
+
134
+ export class ConflictError extends APIError {
135
+ override readonly status: 409 = 409;
136
+ }
137
+
138
+ export class UnprocessableEntityError extends APIError {
139
+ override readonly status: 422 = 422;
140
+ }
141
+
142
+ export class RateLimitError extends APIError {
143
+ override readonly status: 429 = 429;
144
+ }
145
+
146
+ export class InternalServerError extends APIError {}
package/src/index.ts ADDED
@@ -0,0 +1,227 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import * as Core from './core';
4
+ import * as Errors from './error';
5
+ import { type Agent } from './_shims/index';
6
+ import * as Uploads from './uploads';
7
+ import * as Pagination from "./pagination";
8
+ import * as API from "./resources/index";
9
+
10
+ export interface ClientOptions {
11
+ /**
12
+ * Defaults to process.env['VAL_TOWN_BEARER_TOKEN'].
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['VAL_TOWN_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;
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;
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;
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;
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;
71
+ }
72
+
73
+ /** API Client for interfacing with the Val Town API. */
74
+ export class ValTown extends Core.APIClient {
75
+ bearerToken: string;
76
+
77
+ private _options: ClientOptions;
78
+
79
+ /**
80
+ * API Client for interfacing with the Val Town API.
81
+ *
82
+ * @param {string | undefined} [opts.bearerToken=process.env['VAL_TOWN_BEARER_TOKEN'] ?? undefined]
83
+ * @param {string} [opts.baseURL=process.env['VAL_TOWN_BASE_URL'] ?? https://api.val.town] - Override the default base URL for the API.
84
+ * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
85
+ * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
86
+ * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
87
+ * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
88
+ * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
89
+ * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
90
+ */
91
+ constructor({
92
+ baseURL = Core.readEnv('VAL_TOWN_BASE_URL'),
93
+ bearerToken = Core.readEnv('VAL_TOWN_BEARER_TOKEN'),
94
+ ...opts
95
+ }: ClientOptions = {}) {
96
+ if (bearerToken === undefined) {
97
+ throw new Errors.ValTownError(
98
+ "The VAL_TOWN_BEARER_TOKEN environment variable is missing or empty; either provide it, or instantiate the ValTown client with an bearerToken option, like new ValTown({ bearerToken: 'My Bearer Token' }).",
99
+ );
100
+ }
101
+
102
+ const options: ClientOptions = {
103
+ bearerToken,
104
+ ...opts,
105
+ baseURL: baseURL || `https://api.val.town`,
106
+ };
107
+
108
+ super({
109
+ baseURL: options.baseURL!,
110
+ timeout: options.timeout ?? 60000 /* 1 minute */,
111
+ httpAgent: options.httpAgent,
112
+ maxRetries: options.maxRetries,
113
+ fetch: options.fetch,
114
+ });
115
+ this._options = options;
116
+
117
+ this.bearerToken = bearerToken;
118
+ }
119
+
120
+ search: API.Search = new API.Search(this);
121
+ alias: API.Alias = new API.Alias(this);
122
+ me: API.Me = new API.Me(this);
123
+ blobs: API.Blobs = new API.Blobs(this);
124
+ users: API.Users = new API.Users(this);
125
+ sqlite: API.Sqlite = new API.Sqlite(this);
126
+ evals: API.Evals = new API.Evals(this);
127
+ vals: API.Vals = new API.Vals(this);
128
+ emails: API.Emails = new API.Emails(this);
129
+
130
+ protected override defaultQuery(): Core.DefaultQuery | undefined {
131
+ return this._options.defaultQuery;
132
+ }
133
+
134
+ protected override defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers {
135
+ return {
136
+ ...super.defaultHeaders(opts),
137
+ ...this._options.defaultHeaders,
138
+ };
139
+ }
140
+
141
+ protected override authHeaders(opts: Core.FinalRequestOptions): Core.Headers {
142
+ return { Authorization: `Bearer ${this.bearerToken}` };
143
+ }
144
+
145
+ static ValTown = this;
146
+
147
+ static ValTownError = Errors.ValTownError;
148
+ static APIError = Errors.APIError;
149
+ static APIConnectionError = Errors.APIConnectionError;
150
+ static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
151
+ static APIUserAbortError = Errors.APIUserAbortError;
152
+ static NotFoundError = Errors.NotFoundError;
153
+ static ConflictError = Errors.ConflictError;
154
+ static RateLimitError = Errors.RateLimitError;
155
+ static BadRequestError = Errors.BadRequestError;
156
+ static AuthenticationError = Errors.AuthenticationError;
157
+ static InternalServerError = Errors.InternalServerError;
158
+ static PermissionDeniedError = Errors.PermissionDeniedError;
159
+ static UnprocessableEntityError = Errors.UnprocessableEntityError;
160
+
161
+ static toFile = Uploads.toFile;
162
+ static fileFromPath = Uploads.fileFromPath;
163
+ }
164
+
165
+ export const {
166
+ ValTownError,
167
+ APIError,
168
+ APIConnectionError,
169
+ APIConnectionTimeoutError,
170
+ APIUserAbortError,
171
+ NotFoundError,
172
+ ConflictError,
173
+ RateLimitError,
174
+ BadRequestError,
175
+ AuthenticationError,
176
+ InternalServerError,
177
+ PermissionDeniedError,
178
+ UnprocessableEntityError,
179
+ } = Errors;
180
+
181
+ export import toFile = Uploads.toFile;
182
+ export import fileFromPath = Uploads.fileFromPath;
183
+
184
+ export namespace ValTown {
185
+ export import RequestOptions = Core.RequestOptions;
186
+
187
+ export import PageCursorURL = Pagination.PageCursorURL;
188
+ export import PageCursorURLParams = Pagination.PageCursorURLParams;
189
+ export import PageCursorURLResponse = Pagination.PageCursorURLResponse;
190
+
191
+ export import Search = API.Search;
192
+
193
+ export import Alias = API.Alias;
194
+
195
+ export import Me = API.Me;
196
+
197
+ export import Blobs = API.Blobs;
198
+
199
+ export import Users = API.Users;
200
+
201
+ export import Sqlite = API.Sqlite;
202
+ export import SqliteBatchParams = API.SqliteBatchParams;
203
+ export import SqliteExecuteParams = API.SqliteExecuteParams;
204
+
205
+ export import Evals = API.Evals;
206
+ export import EvalRunCodeResponse = API.EvalRunCodeResponse;
207
+ export import EvalRunCodeParams = API.EvalRunCodeParams;
208
+
209
+ export import Vals = API.Vals;
210
+ export import ValCreateResponse = API.ValCreateResponse;
211
+ export import ValRetrieveResponse = API.ValRetrieveResponse;
212
+ export import ValRunAnonymousResponse = API.ValRunAnonymousResponse;
213
+ export import ValCreateParams = API.ValCreateParams;
214
+ export import ValUpdateParams = API.ValUpdateParams;
215
+ export import ValCreateOrUpdateParams = API.ValCreateOrUpdateParams;
216
+ export import ValRunParams = API.ValRunParams;
217
+ export import ValRunAnonymousParams = API.ValRunAnonymousParams;
218
+ export import ValRunGetParams = API.ValRunGetParams;
219
+
220
+ export import Emails = API.Emails;
221
+ export import EmailSendResponse = API.EmailSendResponse;
222
+ export import EmailSendParams = API.EmailSendParams;
223
+
224
+ export import User = API.User;
225
+ }
226
+
227
+ export default ValTown;
package/src/lib/.keep ADDED
@@ -0,0 +1,4 @@
1
+ File generated from our OpenAPI spec by Stainless.
2
+
3
+ This directory can be used to store custom files to expand the SDK.
4
+ It is ignored by Stainless code generation and its content (other than this keep file) won't be touched.
@@ -0,0 +1,62 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { AbstractPage, Response, APIClient, FinalRequestOptions, PageInfo } from './core';
4
+
5
+ export interface PageCursorURLResponse<Item> {
6
+ data: Array<Item>;
7
+
8
+ links: PageCursorURLResponse.Links;
9
+ }
10
+
11
+ export namespace PageCursorURLResponse {
12
+ export interface Links {
13
+ next?: string;
14
+
15
+ prev?: string;
16
+ }
17
+ }
18
+
19
+ export interface PageCursorURLParams {
20
+ limit?: number;
21
+
22
+ offset?: number;
23
+ }
24
+
25
+ export class PageCursorURL<Item> extends AbstractPage<Item> implements PageCursorURLResponse<Item> {
26
+ data: Array<Item>;
27
+
28
+ links: PageCursorURLResponse.Links;
29
+
30
+ constructor(
31
+ client: APIClient,
32
+ response: Response,
33
+ body: PageCursorURLResponse<Item>,
34
+ options: FinalRequestOptions,
35
+ ) {
36
+ super(client, response, body, options);
37
+
38
+ this.data = body.data || [];
39
+ this.links = body.links || {};
40
+ }
41
+
42
+ getPaginatedItems(): Item[] {
43
+ return this.data ?? [];
44
+ }
45
+
46
+ // @deprecated Please use `nextPageInfo()` instead
47
+ nextPageParams(): Partial<PageCursorURLParams> | null {
48
+ const info = this.nextPageInfo();
49
+ if (!info) return null;
50
+ if ('params' in info) return info.params;
51
+ const params = Object.fromEntries(info.url.searchParams);
52
+ if (!Object.keys(params).length) return null;
53
+ return params;
54
+ }
55
+
56
+ nextPageInfo(): PageInfo | null {
57
+ const url = this.links?.next;
58
+ if (!url) return null;
59
+
60
+ return { url: new URL(url) };
61
+ }
62
+ }
@@ -0,0 +1,11 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import type { ValTown } from './index';
4
+
5
+ export class APIResource {
6
+ protected _client: ValTown;
7
+
8
+ constructor(client: ValTown) {
9
+ this._client = client;
10
+ }
11
+ }
@@ -0,0 +1,12 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from "../../resource";
4
+ import * as UsernameAPI from "./username/username";
5
+
6
+ export class Alias extends APIResource {
7
+ username: UsernameAPI.Username = new UsernameAPI.Username(this._client);
8
+ }
9
+
10
+ export namespace Alias {
11
+ export import Username = UsernameAPI.Username;
12
+ }
@@ -0,0 +1,4 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ export { Alias } from './alias';
4
+ export { Username } from './username/index';
@@ -0,0 +1,4 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ export { Username } from './username';
4
+ export { ValNameRetrieveResponse, ValName } from './val-name';
@@ -0,0 +1,22 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import * as Core from "../../../core";
4
+ import { APIResource } from "../../../resource";
5
+ import * as Shared from "../../shared";
6
+ import * as ValNameAPI from "./val-name";
7
+
8
+ export class Username extends APIResource {
9
+ valName: ValNameAPI.ValName = new ValNameAPI.ValName(this._client);
10
+
11
+ /**
12
+ * Get basic details about a user, given their username
13
+ */
14
+ retrieve(username: string, options?: Core.RequestOptions): Core.APIPromise<Shared.User> {
15
+ return this._client.get(`/v1/alias/${username}`, options);
16
+ }
17
+ }
18
+
19
+ export namespace Username {
20
+ export import ValName = ValNameAPI.ValName;
21
+ export import ValNameRetrieveResponse = ValNameAPI.ValNameRetrieveResponse;
22
+ }
@@ -0,0 +1,65 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import * as Core from "../../../core";
4
+ import { APIResource } from "../../../resource";
5
+ import * as ValNameAPI from "./val-name";
6
+
7
+ export class ValName extends APIResource {
8
+ /**
9
+ * Get a val
10
+ */
11
+ retrieve(
12
+ username: string,
13
+ valName: string,
14
+ options?: Core.RequestOptions,
15
+ ): Core.APIPromise<ValNameRetrieveResponse> {
16
+ return this._client.get(`/v1/alias/${username}/${valName}`, options);
17
+ }
18
+ }
19
+
20
+ /**
21
+ * A Val
22
+ */
23
+ export interface ValNameRetrieveResponse {
24
+ id: string;
25
+
26
+ /**
27
+ * The user who created this val
28
+ */
29
+ author: ValNameRetrieveResponse.Author | null;
30
+
31
+ code: string | null;
32
+
33
+ createdAt: string;
34
+
35
+ likeCount: number;
36
+
37
+ name: string;
38
+
39
+ privacy: 'public' | 'unlisted' | 'private';
40
+
41
+ public: boolean;
42
+
43
+ readme: string | null;
44
+
45
+ referenceCount: number;
46
+
47
+ type: 'interval' | 'http' | 'express' | 'email' | 'script' | 'rpc';
48
+
49
+ version: number;
50
+ }
51
+
52
+ export namespace ValNameRetrieveResponse {
53
+ /**
54
+ * The user who created this val
55
+ */
56
+ export interface Author {
57
+ id: string;
58
+
59
+ username: string | null;
60
+ }
61
+ }
62
+
63
+ export namespace ValName {
64
+ export import ValNameRetrieveResponse = ValNameAPI.ValNameRetrieveResponse;
65
+ }
@@ -0,0 +1,26 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import * as Core from "../core";
4
+ import { APIResource } from "../resource";
5
+
6
+ export class Blobs extends APIResource {
7
+ /**
8
+ * Delete a blob
9
+ */
10
+ delete(key: string, options?: Core.RequestOptions): Core.APIPromise<void> {
11
+ return this._client.delete(`/v1/blob/${key}`, {
12
+ ...options,
13
+ headers: { Accept: '*/*', ...options?.headers },
14
+ });
15
+ }
16
+
17
+ /**
18
+ * Store data in blob storage
19
+ */
20
+ store(key: string, options?: Core.RequestOptions): Core.APIPromise<void> {
21
+ return this._client.post(`/v1/blob/${key}`, {
22
+ ...options,
23
+ headers: { Accept: '*/*', ...options?.headers },
24
+ });
25
+ }
26
+ }