@expandai/sdk 0.17.0 → 0.17.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 (360) hide show
  1. package/LICENSE +2 -1
  2. package/README.md +83 -307
  3. package/build/dts/Client.d.ts +61 -0
  4. package/build/dts/Client.d.ts.map +1 -0
  5. package/build/dts/Error.d.ts +90 -0
  6. package/build/dts/Error.d.ts.map +1 -0
  7. package/build/dts/FetchJson.d.ts +364 -0
  8. package/build/dts/FetchJson.d.ts.map +1 -0
  9. package/build/dts/Generated.d.ts +1863 -0
  10. package/build/dts/Generated.d.ts.map +1 -0
  11. package/build/dts/HttpClientHelpers.d.ts +5 -0
  12. package/build/dts/HttpClientHelpers.d.ts.map +1 -0
  13. package/build/dts/Internal.d.ts +49 -0
  14. package/build/dts/Internal.d.ts.map +1 -0
  15. package/build/dts/Playground.d.ts +24 -0
  16. package/build/dts/Playground.d.ts.map +1 -0
  17. package/build/dts/Service.d.ts +277 -0
  18. package/build/dts/Service.d.ts.map +1 -0
  19. package/build/dts/index.d.ts +6 -0
  20. package/build/dts/index.d.ts.map +1 -0
  21. package/build/esm/Client.js +87 -0
  22. package/build/esm/Client.js.map +1 -0
  23. package/build/esm/Error.js +91 -0
  24. package/build/esm/Error.js.map +1 -0
  25. package/build/esm/FetchJson.js +70 -0
  26. package/build/esm/FetchJson.js.map +1 -0
  27. package/build/esm/Generated.js +646 -0
  28. package/build/esm/Generated.js.map +1 -0
  29. package/build/esm/HttpClientHelpers.js +14 -0
  30. package/build/esm/HttpClientHelpers.js.map +1 -0
  31. package/build/esm/Internal.js +95 -0
  32. package/build/esm/Internal.js.map +1 -0
  33. package/build/esm/Playground.js +55 -0
  34. package/build/esm/Playground.js.map +1 -0
  35. package/build/esm/Service.js +174 -0
  36. package/build/esm/Service.js.map +1 -0
  37. package/build/esm/index.js +4 -0
  38. package/build/esm/index.js.map +1 -0
  39. package/package.json +53 -136
  40. package/src/Client.ts +128 -0
  41. package/src/Error.ts +105 -0
  42. package/src/FetchJson.ts +109 -0
  43. package/src/Generated.ts +949 -0
  44. package/src/HttpClientHelpers.ts +24 -0
  45. package/src/Internal.ts +246 -0
  46. package/src/Playground.ts +76 -0
  47. package/src/Service.ts +264 -0
  48. package/src/index.ts +27 -21
  49. package/CHANGELOG.md +0 -238
  50. package/api-promise.d.mts +0 -2
  51. package/api-promise.d.mts.map +0 -1
  52. package/api-promise.d.ts +0 -2
  53. package/api-promise.d.ts.map +0 -1
  54. package/api-promise.js +0 -6
  55. package/api-promise.js.map +0 -1
  56. package/api-promise.mjs +0 -2
  57. package/api-promise.mjs.map +0 -1
  58. package/client.d.mts +0 -184
  59. package/client.d.mts.map +0 -1
  60. package/client.d.ts +0 -184
  61. package/client.d.ts.map +0 -1
  62. package/client.js +0 -476
  63. package/client.js.map +0 -1
  64. package/client.mjs +0 -472
  65. package/client.mjs.map +0 -1
  66. package/core/api-promise.d.mts +0 -46
  67. package/core/api-promise.d.mts.map +0 -1
  68. package/core/api-promise.d.ts +0 -46
  69. package/core/api-promise.d.ts.map +0 -1
  70. package/core/api-promise.js +0 -74
  71. package/core/api-promise.js.map +0 -1
  72. package/core/api-promise.mjs +0 -70
  73. package/core/api-promise.mjs.map +0 -1
  74. package/core/error.d.mts +0 -46
  75. package/core/error.d.mts.map +0 -1
  76. package/core/error.d.ts +0 -46
  77. package/core/error.d.ts.map +0 -1
  78. package/core/error.js +0 -113
  79. package/core/error.js.map +0 -1
  80. package/core/error.mjs +0 -97
  81. package/core/error.mjs.map +0 -1
  82. package/core/resource.d.mts +0 -6
  83. package/core/resource.d.mts.map +0 -1
  84. package/core/resource.d.ts +0 -6
  85. package/core/resource.d.ts.map +0 -1
  86. package/core/resource.js +0 -11
  87. package/core/resource.js.map +0 -1
  88. package/core/resource.mjs +0 -7
  89. package/core/resource.mjs.map +0 -1
  90. package/core/uploads.d.mts +0 -3
  91. package/core/uploads.d.mts.map +0 -1
  92. package/core/uploads.d.ts +0 -3
  93. package/core/uploads.d.ts.map +0 -1
  94. package/core/uploads.js +0 -6
  95. package/core/uploads.js.map +0 -1
  96. package/core/uploads.mjs +0 -2
  97. package/core/uploads.mjs.map +0 -1
  98. package/error.d.mts +0 -2
  99. package/error.d.mts.map +0 -1
  100. package/error.d.ts +0 -2
  101. package/error.d.ts.map +0 -1
  102. package/error.js +0 -6
  103. package/error.js.map +0 -1
  104. package/error.mjs +0 -2
  105. package/error.mjs.map +0 -1
  106. package/index.d.mts +0 -6
  107. package/index.d.mts.map +0 -1
  108. package/index.d.ts +0 -6
  109. package/index.d.ts.map +0 -1
  110. package/index.js +0 -30
  111. package/index.js.map +0 -1
  112. package/index.mjs +0 -7
  113. package/index.mjs.map +0 -1
  114. package/internal/builtin-types.d.mts +0 -73
  115. package/internal/builtin-types.d.mts.map +0 -1
  116. package/internal/builtin-types.d.ts +0 -73
  117. package/internal/builtin-types.d.ts.map +0 -1
  118. package/internal/builtin-types.js +0 -4
  119. package/internal/builtin-types.js.map +0 -1
  120. package/internal/builtin-types.mjs +0 -3
  121. package/internal/builtin-types.mjs.map +0 -1
  122. package/internal/detect-platform.d.mts +0 -15
  123. package/internal/detect-platform.d.mts.map +0 -1
  124. package/internal/detect-platform.d.ts +0 -15
  125. package/internal/detect-platform.d.ts.map +0 -1
  126. package/internal/detect-platform.js +0 -162
  127. package/internal/detect-platform.js.map +0 -1
  128. package/internal/detect-platform.mjs +0 -157
  129. package/internal/detect-platform.mjs.map +0 -1
  130. package/internal/errors.d.mts +0 -3
  131. package/internal/errors.d.mts.map +0 -1
  132. package/internal/errors.d.ts +0 -3
  133. package/internal/errors.d.ts.map +0 -1
  134. package/internal/errors.js +0 -41
  135. package/internal/errors.js.map +0 -1
  136. package/internal/errors.mjs +0 -36
  137. package/internal/errors.mjs.map +0 -1
  138. package/internal/headers.d.mts +0 -20
  139. package/internal/headers.d.mts.map +0 -1
  140. package/internal/headers.d.ts +0 -20
  141. package/internal/headers.d.ts.map +0 -1
  142. package/internal/headers.js +0 -79
  143. package/internal/headers.js.map +0 -1
  144. package/internal/headers.mjs +0 -74
  145. package/internal/headers.mjs.map +0 -1
  146. package/internal/parse.d.mts +0 -12
  147. package/internal/parse.d.mts.map +0 -1
  148. package/internal/parse.d.ts +0 -12
  149. package/internal/parse.d.ts.map +0 -1
  150. package/internal/parse.js +0 -40
  151. package/internal/parse.js.map +0 -1
  152. package/internal/parse.mjs +0 -37
  153. package/internal/parse.mjs.map +0 -1
  154. package/internal/request-options.d.mts +0 -75
  155. package/internal/request-options.d.mts.map +0 -1
  156. package/internal/request-options.d.ts +0 -75
  157. package/internal/request-options.d.ts.map +0 -1
  158. package/internal/request-options.js +0 -14
  159. package/internal/request-options.js.map +0 -1
  160. package/internal/request-options.mjs +0 -10
  161. package/internal/request-options.mjs.map +0 -1
  162. package/internal/shim-types.d.mts +0 -17
  163. package/internal/shim-types.d.mts.map +0 -1
  164. package/internal/shim-types.d.ts +0 -17
  165. package/internal/shim-types.d.ts.map +0 -1
  166. package/internal/shim-types.js +0 -4
  167. package/internal/shim-types.js.map +0 -1
  168. package/internal/shim-types.mjs +0 -3
  169. package/internal/shim-types.mjs.map +0 -1
  170. package/internal/shims.d.mts +0 -20
  171. package/internal/shims.d.mts.map +0 -1
  172. package/internal/shims.d.ts +0 -20
  173. package/internal/shims.d.ts.map +0 -1
  174. package/internal/shims.js +0 -92
  175. package/internal/shims.js.map +0 -1
  176. package/internal/shims.mjs +0 -85
  177. package/internal/shims.mjs.map +0 -1
  178. package/internal/to-file.d.mts +0 -45
  179. package/internal/to-file.d.mts.map +0 -1
  180. package/internal/to-file.d.ts +0 -45
  181. package/internal/to-file.d.ts.map +0 -1
  182. package/internal/to-file.js +0 -91
  183. package/internal/to-file.js.map +0 -1
  184. package/internal/to-file.mjs +0 -88
  185. package/internal/to-file.mjs.map +0 -1
  186. package/internal/tslib.js +0 -81
  187. package/internal/tslib.mjs +0 -17
  188. package/internal/types.d.mts +0 -69
  189. package/internal/types.d.mts.map +0 -1
  190. package/internal/types.d.ts +0 -69
  191. package/internal/types.d.ts.map +0 -1
  192. package/internal/types.js +0 -4
  193. package/internal/types.js.map +0 -1
  194. package/internal/types.mjs +0 -3
  195. package/internal/types.mjs.map +0 -1
  196. package/internal/uploads.d.mts +0 -42
  197. package/internal/uploads.d.mts.map +0 -1
  198. package/internal/uploads.d.ts +0 -42
  199. package/internal/uploads.d.ts.map +0 -1
  200. package/internal/uploads.js +0 -141
  201. package/internal/uploads.js.map +0 -1
  202. package/internal/uploads.mjs +0 -131
  203. package/internal/uploads.mjs.map +0 -1
  204. package/internal/utils/base64.d.mts +0 -3
  205. package/internal/utils/base64.d.mts.map +0 -1
  206. package/internal/utils/base64.d.ts +0 -3
  207. package/internal/utils/base64.d.ts.map +0 -1
  208. package/internal/utils/base64.js +0 -38
  209. package/internal/utils/base64.js.map +0 -1
  210. package/internal/utils/base64.mjs +0 -33
  211. package/internal/utils/base64.mjs.map +0 -1
  212. package/internal/utils/bytes.d.mts +0 -4
  213. package/internal/utils/bytes.d.mts.map +0 -1
  214. package/internal/utils/bytes.d.ts +0 -4
  215. package/internal/utils/bytes.d.ts.map +0 -1
  216. package/internal/utils/bytes.js +0 -31
  217. package/internal/utils/bytes.js.map +0 -1
  218. package/internal/utils/bytes.mjs +0 -26
  219. package/internal/utils/bytes.mjs.map +0 -1
  220. package/internal/utils/env.d.mts +0 -9
  221. package/internal/utils/env.d.mts.map +0 -1
  222. package/internal/utils/env.d.ts +0 -9
  223. package/internal/utils/env.d.ts.map +0 -1
  224. package/internal/utils/env.js +0 -22
  225. package/internal/utils/env.js.map +0 -1
  226. package/internal/utils/env.mjs +0 -18
  227. package/internal/utils/env.mjs.map +0 -1
  228. package/internal/utils/log.d.mts +0 -37
  229. package/internal/utils/log.d.mts.map +0 -1
  230. package/internal/utils/log.d.ts +0 -37
  231. package/internal/utils/log.d.ts.map +0 -1
  232. package/internal/utils/log.js +0 -86
  233. package/internal/utils/log.js.map +0 -1
  234. package/internal/utils/log.mjs +0 -80
  235. package/internal/utils/log.mjs.map +0 -1
  236. package/internal/utils/path.d.mts +0 -15
  237. package/internal/utils/path.d.mts.map +0 -1
  238. package/internal/utils/path.d.ts +0 -15
  239. package/internal/utils/path.d.ts.map +0 -1
  240. package/internal/utils/path.js +0 -79
  241. package/internal/utils/path.js.map +0 -1
  242. package/internal/utils/path.mjs +0 -74
  243. package/internal/utils/path.mjs.map +0 -1
  244. package/internal/utils/sleep.d.mts +0 -2
  245. package/internal/utils/sleep.d.mts.map +0 -1
  246. package/internal/utils/sleep.d.ts +0 -2
  247. package/internal/utils/sleep.d.ts.map +0 -1
  248. package/internal/utils/sleep.js +0 -7
  249. package/internal/utils/sleep.js.map +0 -1
  250. package/internal/utils/sleep.mjs +0 -3
  251. package/internal/utils/sleep.mjs.map +0 -1
  252. package/internal/utils/uuid.d.mts +0 -5
  253. package/internal/utils/uuid.d.mts.map +0 -1
  254. package/internal/utils/uuid.d.ts +0 -5
  255. package/internal/utils/uuid.d.ts.map +0 -1
  256. package/internal/utils/uuid.js +0 -19
  257. package/internal/utils/uuid.js.map +0 -1
  258. package/internal/utils/uuid.mjs +0 -15
  259. package/internal/utils/uuid.mjs.map +0 -1
  260. package/internal/utils/values.d.mts +0 -18
  261. package/internal/utils/values.d.mts.map +0 -1
  262. package/internal/utils/values.d.ts +0 -18
  263. package/internal/utils/values.d.ts.map +0 -1
  264. package/internal/utils/values.js +0 -112
  265. package/internal/utils/values.js.map +0 -1
  266. package/internal/utils/values.mjs +0 -94
  267. package/internal/utils/values.mjs.map +0 -1
  268. package/internal/utils.d.mts +0 -7
  269. package/internal/utils.d.mts.map +0 -1
  270. package/internal/utils.d.ts +0 -7
  271. package/internal/utils.d.ts.map +0 -1
  272. package/internal/utils.js +0 -11
  273. package/internal/utils.js.map +0 -1
  274. package/internal/utils.mjs +0 -8
  275. package/internal/utils.mjs.map +0 -1
  276. package/resource.d.mts +0 -2
  277. package/resource.d.mts.map +0 -1
  278. package/resource.d.ts +0 -2
  279. package/resource.d.ts.map +0 -1
  280. package/resource.js +0 -6
  281. package/resource.js.map +0 -1
  282. package/resource.mjs +0 -2
  283. package/resource.mjs.map +0 -1
  284. package/resources/index.d.mts +0 -2
  285. package/resources/index.d.mts.map +0 -1
  286. package/resources/index.d.ts +0 -2
  287. package/resources/index.d.ts.map +0 -1
  288. package/resources/index.js +0 -4
  289. package/resources/index.js.map +0 -1
  290. package/resources/index.mjs +0 -3
  291. package/resources/index.mjs.map +0 -1
  292. package/resources/top-level.d.mts +0 -469
  293. package/resources/top-level.d.mts.map +0 -1
  294. package/resources/top-level.d.ts +0 -469
  295. package/resources/top-level.d.ts.map +0 -1
  296. package/resources/top-level.js +0 -4
  297. package/resources/top-level.js.map +0 -1
  298. package/resources/top-level.mjs +0 -3
  299. package/resources/top-level.mjs.map +0 -1
  300. package/resources.d.mts +0 -2
  301. package/resources.d.mts.map +0 -1
  302. package/resources.d.ts +0 -2
  303. package/resources.d.ts.map +0 -1
  304. package/resources.js +0 -5
  305. package/resources.js.map +0 -1
  306. package/resources.mjs +0 -2
  307. package/resources.mjs.map +0 -1
  308. package/src/api-promise.ts +0 -2
  309. package/src/client.ts +0 -744
  310. package/src/core/README.md +0 -3
  311. package/src/core/api-promise.ts +0 -92
  312. package/src/core/error.ts +0 -130
  313. package/src/core/resource.ts +0 -11
  314. package/src/core/uploads.ts +0 -2
  315. package/src/error.ts +0 -2
  316. package/src/internal/README.md +0 -3
  317. package/src/internal/builtin-types.ts +0 -93
  318. package/src/internal/detect-platform.ts +0 -196
  319. package/src/internal/errors.ts +0 -33
  320. package/src/internal/headers.ts +0 -97
  321. package/src/internal/parse.ts +0 -56
  322. package/src/internal/request-options.ts +0 -91
  323. package/src/internal/shim-types.ts +0 -26
  324. package/src/internal/shims.ts +0 -107
  325. package/src/internal/to-file.ts +0 -154
  326. package/src/internal/types.ts +0 -95
  327. package/src/internal/uploads.ts +0 -187
  328. package/src/internal/utils/base64.ts +0 -40
  329. package/src/internal/utils/bytes.ts +0 -32
  330. package/src/internal/utils/env.ts +0 -18
  331. package/src/internal/utils/log.ts +0 -127
  332. package/src/internal/utils/path.ts +0 -88
  333. package/src/internal/utils/sleep.ts +0 -3
  334. package/src/internal/utils/uuid.ts +0 -17
  335. package/src/internal/utils/values.ts +0 -105
  336. package/src/internal/utils.ts +0 -8
  337. package/src/lib/.keep +0 -4
  338. package/src/resource.ts +0 -2
  339. package/src/resources/index.ts +0 -3
  340. package/src/resources/top-level.ts +0 -552
  341. package/src/resources.ts +0 -1
  342. package/src/tsconfig.json +0 -11
  343. package/src/uploads.ts +0 -2
  344. package/src/version.ts +0 -1
  345. package/uploads.d.mts +0 -2
  346. package/uploads.d.mts.map +0 -1
  347. package/uploads.d.ts +0 -2
  348. package/uploads.d.ts.map +0 -1
  349. package/uploads.js +0 -6
  350. package/uploads.js.map +0 -1
  351. package/uploads.mjs +0 -2
  352. package/uploads.mjs.map +0 -1
  353. package/version.d.mts +0 -2
  354. package/version.d.mts.map +0 -1
  355. package/version.d.ts +0 -2
  356. package/version.d.ts.map +0 -1
  357. package/version.js +0 -5
  358. package/version.js.map +0 -1
  359. package/version.mjs +0 -2
  360. package/version.mjs.map +0 -1
package/package.json CHANGED
@@ -1,137 +1,54 @@
1
1
  {
2
- "name": "@expandai/sdk",
3
- "version": "0.17.0",
4
- "description": "The official TypeScript library for the Expand API",
5
- "author": "Expand <support@expand.ai>",
6
- "types": "./index.d.ts",
7
- "main": "./index.js",
8
- "type": "commonjs",
9
- "repository": "github:expandai/expandai-node",
10
- "license": "Apache-2.0",
11
- "files": [
12
- "**/*"
13
- ],
14
- "private": false,
15
- "publishConfig": {
16
- "access": "public"
17
- },
18
- "dependencies": {},
19
- "exports": {
20
- ".": {
21
- "require": {
22
- "types": "./index.d.ts",
23
- "default": "./index.js"
24
- },
25
- "types": "./index.d.mts",
26
- "default": "./index.mjs"
27
- },
28
- "./api-promise": {
29
- "import": "./api-promise.mjs",
30
- "require": "./api-promise.js"
31
- },
32
- "./api-promise.js": {
33
- "default": "./api-promise.js"
34
- },
35
- "./api-promise.mjs": {
36
- "default": "./api-promise.mjs"
37
- },
38
- "./client": {
39
- "import": "./client.mjs",
40
- "require": "./client.js"
41
- },
42
- "./client.js": {
43
- "default": "./client.js"
44
- },
45
- "./client.mjs": {
46
- "default": "./client.mjs"
47
- },
48
- "./core/*.mjs": {
49
- "default": "./core/*.mjs"
50
- },
51
- "./core/*.js": {
52
- "default": "./core/*.js"
53
- },
54
- "./core/*": {
55
- "import": "./core/*.mjs",
56
- "require": "./core/*.js"
57
- },
58
- "./error": {
59
- "import": "./error.mjs",
60
- "require": "./error.js"
61
- },
62
- "./error.js": {
63
- "default": "./error.js"
64
- },
65
- "./error.mjs": {
66
- "default": "./error.mjs"
67
- },
68
- "./index": {
69
- "import": "./index.mjs",
70
- "require": "./index.js"
71
- },
72
- "./index.js": {
73
- "default": "./index.js"
74
- },
75
- "./index.mjs": {
76
- "default": "./index.mjs"
77
- },
78
- "./resource": {
79
- "import": "./resource.mjs",
80
- "require": "./resource.js"
81
- },
82
- "./resource.js": {
83
- "default": "./resource.js"
84
- },
85
- "./resource.mjs": {
86
- "default": "./resource.mjs"
87
- },
88
- "./resources/*.mjs": {
89
- "default": "./resources/*.mjs"
90
- },
91
- "./resources/*.js": {
92
- "default": "./resources/*.js"
93
- },
94
- "./resources/*": {
95
- "import": "./resources/*.mjs",
96
- "require": "./resources/*.js"
97
- },
98
- "./resources": {
99
- "import": "./resources.mjs",
100
- "require": "./resources.js"
101
- },
102
- "./resources.js": {
103
- "default": "./resources.js"
104
- },
105
- "./resources.mjs": {
106
- "default": "./resources.mjs"
107
- },
108
- "./uploads": {
109
- "import": "./uploads.mjs",
110
- "require": "./uploads.js"
111
- },
112
- "./uploads.js": {
113
- "default": "./uploads.js"
114
- },
115
- "./uploads.mjs": {
116
- "default": "./uploads.mjs"
117
- },
118
- "./version": {
119
- "import": "./version.mjs",
120
- "require": "./version.js"
121
- },
122
- "./version.js": {
123
- "default": "./version.js"
124
- },
125
- "./version.mjs": {
126
- "default": "./version.mjs"
127
- }
128
- },
129
- "scripts": {
130
- "test": "./scripts/test",
131
- "build": "./scripts/build",
132
- "format": "./scripts/format",
133
- "tsn": "ts-node -r tsconfig-paths/register",
134
- "lint": "./scripts/lint",
135
- "fix": "./scripts/format"
136
- }
137
- }
2
+ "name": "@expandai/sdk",
3
+ "type": "module",
4
+ "version": "0.17.1",
5
+ "private": false,
6
+ "description": "TypeScript SDK for ExpandAI",
7
+ "author": "ExpandAI",
8
+ "license": "Apache-2.0",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/expandai/expandai-node.git"
12
+ },
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "files": [
17
+ "build/dts",
18
+ "build/esm",
19
+ "src",
20
+ "!**/*.tsbuildinfo"
21
+ ],
22
+ "exports": {
23
+ "./package.json": "./package.json",
24
+ ".": {
25
+ "types": "./build/dts/index.d.ts",
26
+ "import": "./build/esm/index.js"
27
+ },
28
+ "./*": "./src/*.ts"
29
+ },
30
+ "scripts": {
31
+ "generate": "tsx scripts/generate-client.ts",
32
+ "build": "tsc -b tsconfig.build.json",
33
+ "check": "tsc -b tsconfig.json",
34
+ "check:test": "tsc -b tsconfig.test.json",
35
+ "lint": "biome check --write --no-errors-on-unmatched",
36
+ "lint:check": "biome check",
37
+ "format": "biome format --write",
38
+ "format:check": "biome format",
39
+ "test": "vitest run --exclude 'test/**/*.integration.test.ts'",
40
+ "test:integration": "vitest run integration"
41
+ },
42
+ "dependencies": {
43
+ "@effect/platform": "0.96.1",
44
+ "@effect/platform-node": "0.106.0",
45
+ "effect": "3.21.2"
46
+ },
47
+ "devDependencies": {
48
+ "@biomejs/biome": "^2.4.14",
49
+ "@effect/vitest": "0.29.0",
50
+ "@tim-smart/openapi-gen": "0.3.12",
51
+ "@types/node": "^25.5.2",
52
+ "vitest": "4.1.4"
53
+ }
54
+ }
package/src/Client.ts ADDED
@@ -0,0 +1,128 @@
1
+ import { Effect, Either, Exit, Layer } from 'effect'
2
+ import { InternalClient } from './Internal.js'
3
+ import {
4
+ type BatchedParams,
5
+ type BatchedResponse,
6
+ buildServiceConfig,
7
+ type ExpandServiceOptions,
8
+ type FetchJsonParams,
9
+ type FetchJsonRequestOptions,
10
+ type FetchJsonResponse,
11
+ type FetchParams,
12
+ type FetchRequestOptions,
13
+ type FetchResponse,
14
+ type FetchSearchParams,
15
+ type FetchSearchResponse,
16
+ type GetBatchedParams,
17
+ type GetBatchedResponse,
18
+ type RequestOptions,
19
+ } from './Service.js'
20
+
21
+ export type {
22
+ BatchedParams,
23
+ BatchedResponse,
24
+ FetchJsonParams,
25
+ FetchJsonRequestOptions,
26
+ FetchJsonResponse,
27
+ FetchParams,
28
+ FetchRequestOptions,
29
+ FetchResponse,
30
+ FetchSearchParams,
31
+ FetchSearchResponse,
32
+ GetBatchedParams,
33
+ GetBatchedResponse,
34
+ } from './Service.js'
35
+
36
+ /** Options for constructing an {@link ExpandClient}. Same shape as `ExpandServiceOptions`. */
37
+ export type ExpandClientOptions = ExpandServiceOptions
38
+
39
+ /**
40
+ * Promise-based client for the Expand API. Holds an {@link InternalClient} layer and runs Effects
41
+ * against it, translating typed failures into the `ExpandClient*Error` hierarchy that async/await
42
+ * consumers expect.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * const client = new ExpandClient({ apiKey: 'sk_...' })
47
+ * const result = await client.fetch({ url: 'https://example.com' })
48
+ * ```
49
+ */
50
+ export class ExpandClient {
51
+ private readonly layer: Layer.Layer<InternalClient>
52
+
53
+ constructor(options: ExpandClientOptions = {}) {
54
+ // Eagerly validate so the Promise constructor matches the documented sync-throw contract.
55
+ // `buildServiceConfig` is a pure-sync Effect (env-var read + Schema.decode), so runSync is safe.
56
+ const result = Effect.runSync(buildServiceConfig(options).pipe(Effect.either))
57
+ if (Either.isLeft(result)) {
58
+ throw result.left.toPublicError()
59
+ }
60
+ // Validation passed; the layer's acquisition Effect re-runs the same logic, so it cannot fail.
61
+ // Layer.orDie narrows the error channel to `never` while keeping a die fallback as a defensive
62
+ // net (translateCause picks up dies via Cause.dieOption and converts via toPublicError).
63
+ this.layer = InternalClient.layer(options).pipe(Layer.orDie)
64
+ }
65
+
66
+ /**
67
+ * Fetch a URL through the Expand API.
68
+ *
69
+ * @throws {ExpandClientApiError} on 4xx/5xx responses
70
+ * @throws {ExpandClientTimeoutError} when the request exceeds `timeoutMs`
71
+ * @throws {ExpandClientConnectionError} on network failures
72
+ * @throws {ExpandClientError} for any other failure
73
+ */
74
+ async fetch(params: FetchParams, options: FetchRequestOptions = {}): Promise<FetchResponse> {
75
+ return this.run((client) => client.fetch(params, options))
76
+ }
77
+
78
+ /**
79
+ * Fetch a URL through the object-mode endpoint.
80
+ *
81
+ * Returns `{ meta, markdown, json }`; use {@link fetch} for the raw markdown document.
82
+ */
83
+ async fetchJson(params: FetchJsonParams, options: FetchJsonRequestOptions = {}): Promise<FetchJsonResponse> {
84
+ return this.run((client) => client.fetchJson(params, options))
85
+ }
86
+
87
+ /**
88
+ * Search a previous Fetch response by `snapshotId` without starting a new capture.
89
+ */
90
+ async fetchSearch(params: FetchSearchParams, options: RequestOptions = {}): Promise<FetchSearchResponse> {
91
+ return this.run((client) => client.fetchSearch(params, options))
92
+ }
93
+
94
+ /**
95
+ * Kick off an asynchronous batched fetch over one or more URLs. Returns a batched-run ID that can
96
+ * be polled via {@link getBatched}.
97
+ *
98
+ * Retries are disabled by default. Pass `{ maxRetries: N }` to opt in.
99
+ *
100
+ * @throws {ExpandClientApiError} on 4xx/5xx responses
101
+ * @throws {ExpandClientTimeoutError} when the request exceeds `timeoutMs`
102
+ * @throws {ExpandClientConnectionError} on network failures
103
+ * @throws {ExpandClientError} for any other failure
104
+ */
105
+ async batched(params: BatchedParams, options: RequestOptions = {}): Promise<BatchedResponse> {
106
+ return this.run((client) => client.batched(params, options))
107
+ }
108
+
109
+ /**
110
+ * Fetch the status and accumulated results for a batched run previously started by {@link batched}.
111
+ *
112
+ * @throws {ExpandClientApiError} on 4xx/5xx responses
113
+ * @throws {ExpandClientTimeoutError} when the request exceeds `timeoutMs`
114
+ * @throws {ExpandClientConnectionError} on network failures
115
+ * @throws {ExpandClientError} for any other failure
116
+ */
117
+ async getBatched(id: string, options: GetBatchedParams & RequestOptions = {}): Promise<GetBatchedResponse> {
118
+ return this.run((client) => client.getBatched(id, options))
119
+ }
120
+
121
+ private async run<A>(body: (ic: InternalClient) => Effect.Effect<A, Error>): Promise<A> {
122
+ const exit = await Effect.runPromiseExit(InternalClient.use(body).pipe(Effect.provide(this.layer)))
123
+ if (Exit.isSuccess(exit)) {
124
+ return exit.value
125
+ }
126
+ throw InternalClient.translateCause(exit.cause)
127
+ }
128
+ }
package/src/Error.ts ADDED
@@ -0,0 +1,105 @@
1
+ import { Schema } from 'effect'
2
+
3
+ /**
4
+ * Effect-side base error. Schema.TaggedError; Effect consumers receive these in the error channel.
5
+ */
6
+ export class ExpandSdkError extends Schema.TaggedError<ExpandSdkError>()('ExpandSdkError', {
7
+ message: Schema.String,
8
+ cause: Schema.optional(Schema.Defect),
9
+ }) {
10
+ toPublicError() {
11
+ return new ExpandClientError(this.message, { cause: this.cause })
12
+ }
13
+ }
14
+
15
+ /**
16
+ * Effect-side error for non-2xx API responses. Inspect `status` and `body` for details.
17
+ */
18
+ export class ExpandApiError extends Schema.TaggedError<ExpandApiError>()('ExpandApiError', {
19
+ message: Schema.String,
20
+ status: Schema.Number,
21
+ body: Schema.optional(Schema.Unknown),
22
+ cause: Schema.optional(Schema.Defect),
23
+ }) {
24
+ toPublicError() {
25
+ return new ExpandClientApiError(this.message, { status: this.status, body: this.body, cause: this.cause })
26
+ }
27
+ }
28
+
29
+ /**
30
+ * Effect-side error when the SDK cannot reach the API (DNS, connection refused, socket reset, etc.).
31
+ */
32
+ export class ExpandConnectionError extends Schema.TaggedError<ExpandConnectionError>()('ExpandConnectionError', {
33
+ message: Schema.String,
34
+ cause: Schema.optional(Schema.Defect),
35
+ }) {
36
+ toPublicError() {
37
+ return new ExpandClientConnectionError(this.message, { cause: this.cause })
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Effect-side error when a request exceeds its configured `timeoutMs`.
43
+ */
44
+ export class ExpandTimeoutError extends Schema.TaggedError<ExpandTimeoutError>()('ExpandTimeoutError', {
45
+ message: Schema.String,
46
+ timeoutMs: Schema.Number,
47
+ cause: Schema.optional(Schema.Defect),
48
+ }) {
49
+ toPublicError() {
50
+ return new ExpandClientTimeoutError(this.message, { timeoutMs: this.timeoutMs, cause: this.cause })
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Union of every error the Effect-side `ExpandService` can fail with.
56
+ */
57
+ export type ExpandError = ExpandSdkError | ExpandApiError | ExpandConnectionError | ExpandTimeoutError
58
+
59
+ /**
60
+ * Promise-side base class. Catch this to handle any failure thrown by `ExpandClient`.
61
+ */
62
+ export class ExpandClientError extends Error {
63
+ constructor(message: string, options: ErrorOptions = {}) {
64
+ super(message, options)
65
+ this.name = 'ExpandClientError'
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Promise-side error for non-2xx API responses. Inspect `status` and `body` for details.
71
+ */
72
+ export class ExpandClientApiError extends ExpandClientError {
73
+ readonly status: number
74
+ readonly body: unknown
75
+
76
+ constructor(message: string, options: ErrorOptions & { readonly status: number; readonly body?: unknown }) {
77
+ super(message, options)
78
+ this.name = 'ExpandClientApiError'
79
+ this.status = options.status
80
+ this.body = options.body
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Promise-side error when the SDK cannot reach the API (DNS, connection refused, socket reset, etc.).
86
+ */
87
+ export class ExpandClientConnectionError extends ExpandClientError {
88
+ constructor(message: string, options: ErrorOptions = {}) {
89
+ super(message, options)
90
+ this.name = 'ExpandClientConnectionError'
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Promise-side error when a request exceeds its configured `timeoutMs`.
96
+ */
97
+ export class ExpandClientTimeoutError extends ExpandClientConnectionError {
98
+ readonly timeoutMs: number
99
+
100
+ constructor(message: string, options: ErrorOptions & { readonly timeoutMs: number }) {
101
+ super(message, options)
102
+ this.name = 'ExpandClientTimeoutError'
103
+ this.timeoutMs = options.timeoutMs
104
+ }
105
+ }
@@ -0,0 +1,109 @@
1
+ // `json`-recovering decode for the fetch JSON-mode and snapshot-search endpoints.
2
+ //
3
+ // The OpenAPI spec declares `json` on each search snippet (the extracted State JSON value), but
4
+ // the code generator drops the bare `unknown`-typed field, so `Generated.FetchObjectModeResult`
5
+ // / `Generated.FetchSnapshotSearchResult` decode it away. These hand-written schemas re-add
6
+ // `json`, and the request functions mirror the generated client but decode the 200 body with
7
+ // them — so callers that need to surface the cited JSON get it. Kept out of `Generated.ts` so the
8
+ // OpenAPI conformance test (which checks the generated schemas) is unaffected.
9
+
10
+ import { HttpClient, HttpClientRequest, HttpClientResponse } from '@effect/platform'
11
+ import * as Generated from '@expandai/sdk/Generated'
12
+ import { decodeError, unexpectedStatus } from '@expandai/sdk/HttpClientHelpers'
13
+ import { Effect, Schema as S } from 'effect'
14
+
15
+ /** Search snippet with the extracted `json` value preserved (statejson snippets only). */
16
+ export const FetchSearchSnippetWithJson = S.Struct({
17
+ type: S.optionalWith(S.Literal('text'), { nullable: true, default: () => 'text' as const }),
18
+ source: S.Literal('markdown', 'appendix', 'statejson'),
19
+ text: S.String,
20
+ json: S.optionalWith(S.Unknown, { nullable: true }),
21
+ score: S.Number.pipe(S.greaterThanOrEqualTo(0), S.lessThanOrEqualTo(1)),
22
+ location: S.optionalWith(Generated.FetchSearchSnippetLocation, { nullable: true }),
23
+ })
24
+
25
+ export const FetchSearchResultWithJson = S.Struct({
26
+ query: S.String,
27
+ snippets: S.Array(FetchSearchSnippetWithJson),
28
+ meta: S.optionalWith(Generated.FetchSearchMeta, { nullable: true }),
29
+ })
30
+
31
+ export class FetchObjectModeResultWithJson extends S.Class<FetchObjectModeResultWithJson>(
32
+ 'FetchObjectModeResultWithJson',
33
+ )({
34
+ meta: Generated.FetchObjectModeMeta,
35
+ markdown: S.String,
36
+ json: S.Array(Generated.FetchObjectModeEvidence),
37
+ data: S.optionalWith(
38
+ S.Struct({
39
+ assets: S.optionalWith(S.Array(Generated.FetchAssetReference), { nullable: true }),
40
+ captureTelemetry: S.optionalWith(Generated.CaptureTelemetryInfo, { nullable: true }),
41
+ search: S.optionalWith(FetchSearchResultWithJson, { nullable: true }),
42
+ }),
43
+ { nullable: true },
44
+ ),
45
+ }) {}
46
+
47
+ export class FetchSnapshotSearchResultWithJson extends S.Class<FetchSnapshotSearchResultWithJson>(
48
+ 'FetchSnapshotSearchResultWithJson',
49
+ )({
50
+ snapshotId: S.String.pipe(S.minLength(1)),
51
+ response: Generated.ResponseInfo,
52
+ search: FetchSearchResultWithJson,
53
+ durationMs: S.Number.pipe(S.greaterThanOrEqualTo(0)),
54
+ }) {}
55
+
56
+ /** Mirrors `Generated.Client['fetchFetchJson']` but decodes the 200 body with `json` preserved. */
57
+ export const fetchObjectModeJson = (
58
+ httpClient: HttpClient.HttpClient,
59
+ options: {
60
+ readonly params: typeof Generated.FetchFetchJsonParams.Encoded
61
+ readonly payload: typeof Generated.FetchFetchJsonRequest.Encoded
62
+ },
63
+ ) =>
64
+ HttpClientRequest.make('POST')('/v1/fetch/json').pipe(
65
+ HttpClientRequest.setUrlParams(options.params.include !== undefined ? { include: options.params.include } : {}),
66
+ (request) => Effect.orDie(HttpClientRequest.bodyJson(request, options.payload)),
67
+ Effect.flatMap((request) =>
68
+ Effect.flatMap(
69
+ httpClient.execute(request),
70
+ HttpClientResponse.matchStatus({
71
+ '200': (response) => HttpClientResponse.schemaBodyJson(FetchObjectModeResultWithJson)(response),
72
+ '400': (response) => decodeError(response, Generated.FetchFetchJson400),
73
+ '401': (response) => decodeError(response, Generated.AuthFailed),
74
+ '403': (response) => decodeError(response, Generated.FetchFetchJson403),
75
+ '413': (response) => decodeError(response, Generated.PayloadTooLarge),
76
+ '429': (response) => decodeError(response, Generated.TooManyRequests),
77
+ '500': (response) => decodeError(response, Generated.InternalError),
78
+ '503': (response) => decodeError(response, Generated.ServiceUnavailable),
79
+ orElse: (response) => unexpectedStatus(request, response),
80
+ }),
81
+ ),
82
+ ),
83
+ )
84
+
85
+ /** Mirrors `Generated.Client['fetchFetchSearch']` but decodes the 200 body with `json` preserved. */
86
+ export const fetchSnapshotSearch = (
87
+ httpClient: HttpClient.HttpClient,
88
+ options: typeof Generated.FetchFetchSearchRequest.Encoded,
89
+ ) =>
90
+ HttpClientRequest.make('POST')('/v1/fetch/search').pipe(
91
+ (request) => Effect.orDie(HttpClientRequest.bodyJson(request, options)),
92
+ Effect.flatMap((request) =>
93
+ Effect.flatMap(
94
+ httpClient.execute(request),
95
+ HttpClientResponse.matchStatus({
96
+ '200': (response) => HttpClientResponse.schemaBodyJson(FetchSnapshotSearchResultWithJson)(response),
97
+ '400': (response) => decodeError(response, Generated.FetchFetchSearch400),
98
+ '401': (response) => decodeError(response, Generated.AuthFailed),
99
+ '403': (response) => decodeError(response, Generated.FetchFetchSearch403),
100
+ '404': (response) => decodeError(response, Generated.FetchSnapshotSearchNotFound),
101
+ '413': (response) => decodeError(response, Generated.PayloadTooLarge),
102
+ '429': (response) => decodeError(response, Generated.TooManyRequests),
103
+ '500': (response) => decodeError(response, Generated.InternalError),
104
+ '503': (response) => decodeError(response, Generated.ServiceUnavailable),
105
+ orElse: (response) => unexpectedStatus(request, response),
106
+ }),
107
+ ),
108
+ ),
109
+ )