influship 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (426) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/LICENSE +201 -0
  3. package/README.md +372 -0
  4. package/api-promise.d.mts +2 -0
  5. package/api-promise.d.mts.map +1 -0
  6. package/api-promise.d.ts +2 -0
  7. package/api-promise.d.ts.map +1 -0
  8. package/api-promise.js +6 -0
  9. package/api-promise.js.map +1 -0
  10. package/api-promise.mjs +2 -0
  11. package/api-promise.mjs.map +1 -0
  12. package/client.d.mts +198 -0
  13. package/client.d.mts.map +1 -0
  14. package/client.d.ts +198 -0
  15. package/client.d.ts.map +1 -0
  16. package/client.js +469 -0
  17. package/client.js.map +1 -0
  18. package/client.mjs +465 -0
  19. package/client.mjs.map +1 -0
  20. package/core/api-promise.d.mts +46 -0
  21. package/core/api-promise.d.mts.map +1 -0
  22. package/core/api-promise.d.ts +46 -0
  23. package/core/api-promise.d.ts.map +1 -0
  24. package/core/api-promise.js +74 -0
  25. package/core/api-promise.js.map +1 -0
  26. package/core/api-promise.mjs +70 -0
  27. package/core/api-promise.mjs.map +1 -0
  28. package/core/error.d.mts +46 -0
  29. package/core/error.d.mts.map +1 -0
  30. package/core/error.d.ts +46 -0
  31. package/core/error.d.ts.map +1 -0
  32. package/core/error.js +113 -0
  33. package/core/error.js.map +1 -0
  34. package/core/error.mjs +97 -0
  35. package/core/error.mjs.map +1 -0
  36. package/core/resource.d.mts +6 -0
  37. package/core/resource.d.mts.map +1 -0
  38. package/core/resource.d.ts +6 -0
  39. package/core/resource.d.ts.map +1 -0
  40. package/core/resource.js +11 -0
  41. package/core/resource.js.map +1 -0
  42. package/core/resource.mjs +7 -0
  43. package/core/resource.mjs.map +1 -0
  44. package/core/uploads.d.mts +3 -0
  45. package/core/uploads.d.mts.map +1 -0
  46. package/core/uploads.d.ts +3 -0
  47. package/core/uploads.d.ts.map +1 -0
  48. package/core/uploads.js +6 -0
  49. package/core/uploads.js.map +1 -0
  50. package/core/uploads.mjs +2 -0
  51. package/core/uploads.mjs.map +1 -0
  52. package/error.d.mts +2 -0
  53. package/error.d.mts.map +1 -0
  54. package/error.d.ts +2 -0
  55. package/error.d.ts.map +1 -0
  56. package/error.js +6 -0
  57. package/error.js.map +1 -0
  58. package/error.mjs +2 -0
  59. package/error.mjs.map +1 -0
  60. package/index.d.mts +6 -0
  61. package/index.d.mts.map +1 -0
  62. package/index.d.ts +6 -0
  63. package/index.d.ts.map +1 -0
  64. package/index.js +30 -0
  65. package/index.js.map +1 -0
  66. package/index.mjs +7 -0
  67. package/index.mjs.map +1 -0
  68. package/internal/builtin-types.d.mts +73 -0
  69. package/internal/builtin-types.d.mts.map +1 -0
  70. package/internal/builtin-types.d.ts +73 -0
  71. package/internal/builtin-types.d.ts.map +1 -0
  72. package/internal/builtin-types.js +4 -0
  73. package/internal/builtin-types.js.map +1 -0
  74. package/internal/builtin-types.mjs +3 -0
  75. package/internal/builtin-types.mjs.map +1 -0
  76. package/internal/detect-platform.d.mts +15 -0
  77. package/internal/detect-platform.d.mts.map +1 -0
  78. package/internal/detect-platform.d.ts +15 -0
  79. package/internal/detect-platform.d.ts.map +1 -0
  80. package/internal/detect-platform.js +162 -0
  81. package/internal/detect-platform.js.map +1 -0
  82. package/internal/detect-platform.mjs +157 -0
  83. package/internal/detect-platform.mjs.map +1 -0
  84. package/internal/errors.d.mts +3 -0
  85. package/internal/errors.d.mts.map +1 -0
  86. package/internal/errors.d.ts +3 -0
  87. package/internal/errors.d.ts.map +1 -0
  88. package/internal/errors.js +41 -0
  89. package/internal/errors.js.map +1 -0
  90. package/internal/errors.mjs +36 -0
  91. package/internal/errors.mjs.map +1 -0
  92. package/internal/headers.d.mts +20 -0
  93. package/internal/headers.d.mts.map +1 -0
  94. package/internal/headers.d.ts +20 -0
  95. package/internal/headers.d.ts.map +1 -0
  96. package/internal/headers.js +79 -0
  97. package/internal/headers.js.map +1 -0
  98. package/internal/headers.mjs +74 -0
  99. package/internal/headers.mjs.map +1 -0
  100. package/internal/parse.d.mts +12 -0
  101. package/internal/parse.d.mts.map +1 -0
  102. package/internal/parse.d.ts +12 -0
  103. package/internal/parse.d.ts.map +1 -0
  104. package/internal/parse.js +35 -0
  105. package/internal/parse.js.map +1 -0
  106. package/internal/parse.mjs +32 -0
  107. package/internal/parse.mjs.map +1 -0
  108. package/internal/qs/formats.d.mts +7 -0
  109. package/internal/qs/formats.d.mts.map +1 -0
  110. package/internal/qs/formats.d.ts +7 -0
  111. package/internal/qs/formats.d.ts.map +1 -0
  112. package/internal/qs/formats.js +13 -0
  113. package/internal/qs/formats.js.map +1 -0
  114. package/internal/qs/formats.mjs +9 -0
  115. package/internal/qs/formats.mjs.map +1 -0
  116. package/internal/qs/index.d.mts +10 -0
  117. package/internal/qs/index.d.mts.map +1 -0
  118. package/internal/qs/index.d.ts +10 -0
  119. package/internal/qs/index.d.ts.map +1 -0
  120. package/internal/qs/index.js +14 -0
  121. package/internal/qs/index.js.map +1 -0
  122. package/internal/qs/index.mjs +10 -0
  123. package/internal/qs/index.mjs.map +1 -0
  124. package/internal/qs/stringify.d.mts +3 -0
  125. package/internal/qs/stringify.d.mts.map +1 -0
  126. package/internal/qs/stringify.d.ts +3 -0
  127. package/internal/qs/stringify.d.ts.map +1 -0
  128. package/internal/qs/stringify.js +277 -0
  129. package/internal/qs/stringify.js.map +1 -0
  130. package/internal/qs/stringify.mjs +274 -0
  131. package/internal/qs/stringify.mjs.map +1 -0
  132. package/internal/qs/types.d.mts +57 -0
  133. package/internal/qs/types.d.mts.map +1 -0
  134. package/internal/qs/types.d.ts +57 -0
  135. package/internal/qs/types.d.ts.map +1 -0
  136. package/internal/qs/types.js +3 -0
  137. package/internal/qs/types.js.map +1 -0
  138. package/internal/qs/types.mjs +2 -0
  139. package/internal/qs/types.mjs.map +1 -0
  140. package/internal/qs/utils.d.mts +15 -0
  141. package/internal/qs/utils.d.mts.map +1 -0
  142. package/internal/qs/utils.d.ts +15 -0
  143. package/internal/qs/utils.d.ts.map +1 -0
  144. package/internal/qs/utils.js +230 -0
  145. package/internal/qs/utils.js.map +1 -0
  146. package/internal/qs/utils.mjs +217 -0
  147. package/internal/qs/utils.mjs.map +1 -0
  148. package/internal/request-options.d.mts +75 -0
  149. package/internal/request-options.d.mts.map +1 -0
  150. package/internal/request-options.d.ts +75 -0
  151. package/internal/request-options.d.ts.map +1 -0
  152. package/internal/request-options.js +14 -0
  153. package/internal/request-options.js.map +1 -0
  154. package/internal/request-options.mjs +10 -0
  155. package/internal/request-options.mjs.map +1 -0
  156. package/internal/shim-types.d.mts +17 -0
  157. package/internal/shim-types.d.mts.map +1 -0
  158. package/internal/shim-types.d.ts +17 -0
  159. package/internal/shim-types.d.ts.map +1 -0
  160. package/internal/shim-types.js +4 -0
  161. package/internal/shim-types.js.map +1 -0
  162. package/internal/shim-types.mjs +3 -0
  163. package/internal/shim-types.mjs.map +1 -0
  164. package/internal/shims.d.mts +20 -0
  165. package/internal/shims.d.mts.map +1 -0
  166. package/internal/shims.d.ts +20 -0
  167. package/internal/shims.d.ts.map +1 -0
  168. package/internal/shims.js +92 -0
  169. package/internal/shims.js.map +1 -0
  170. package/internal/shims.mjs +85 -0
  171. package/internal/shims.mjs.map +1 -0
  172. package/internal/to-file.d.mts +45 -0
  173. package/internal/to-file.d.mts.map +1 -0
  174. package/internal/to-file.d.ts +45 -0
  175. package/internal/to-file.d.ts.map +1 -0
  176. package/internal/to-file.js +91 -0
  177. package/internal/to-file.js.map +1 -0
  178. package/internal/to-file.mjs +88 -0
  179. package/internal/to-file.mjs.map +1 -0
  180. package/internal/tslib.js +81 -0
  181. package/internal/tslib.mjs +17 -0
  182. package/internal/types.d.mts +69 -0
  183. package/internal/types.d.mts.map +1 -0
  184. package/internal/types.d.ts +69 -0
  185. package/internal/types.d.ts.map +1 -0
  186. package/internal/types.js +4 -0
  187. package/internal/types.js.map +1 -0
  188. package/internal/types.mjs +3 -0
  189. package/internal/types.mjs.map +1 -0
  190. package/internal/uploads.d.mts +42 -0
  191. package/internal/uploads.d.mts.map +1 -0
  192. package/internal/uploads.d.ts +42 -0
  193. package/internal/uploads.d.ts.map +1 -0
  194. package/internal/uploads.js +141 -0
  195. package/internal/uploads.js.map +1 -0
  196. package/internal/uploads.mjs +131 -0
  197. package/internal/uploads.mjs.map +1 -0
  198. package/internal/utils/base64.d.mts +3 -0
  199. package/internal/utils/base64.d.mts.map +1 -0
  200. package/internal/utils/base64.d.ts +3 -0
  201. package/internal/utils/base64.d.ts.map +1 -0
  202. package/internal/utils/base64.js +38 -0
  203. package/internal/utils/base64.js.map +1 -0
  204. package/internal/utils/base64.mjs +33 -0
  205. package/internal/utils/base64.mjs.map +1 -0
  206. package/internal/utils/bytes.d.mts +4 -0
  207. package/internal/utils/bytes.d.mts.map +1 -0
  208. package/internal/utils/bytes.d.ts +4 -0
  209. package/internal/utils/bytes.d.ts.map +1 -0
  210. package/internal/utils/bytes.js +31 -0
  211. package/internal/utils/bytes.js.map +1 -0
  212. package/internal/utils/bytes.mjs +26 -0
  213. package/internal/utils/bytes.mjs.map +1 -0
  214. package/internal/utils/env.d.mts +9 -0
  215. package/internal/utils/env.d.mts.map +1 -0
  216. package/internal/utils/env.d.ts +9 -0
  217. package/internal/utils/env.d.ts.map +1 -0
  218. package/internal/utils/env.js +22 -0
  219. package/internal/utils/env.js.map +1 -0
  220. package/internal/utils/env.mjs +18 -0
  221. package/internal/utils/env.mjs.map +1 -0
  222. package/internal/utils/log.d.mts +37 -0
  223. package/internal/utils/log.d.mts.map +1 -0
  224. package/internal/utils/log.d.ts +37 -0
  225. package/internal/utils/log.d.ts.map +1 -0
  226. package/internal/utils/log.js +86 -0
  227. package/internal/utils/log.js.map +1 -0
  228. package/internal/utils/log.mjs +80 -0
  229. package/internal/utils/log.mjs.map +1 -0
  230. package/internal/utils/path.d.mts +15 -0
  231. package/internal/utils/path.d.mts.map +1 -0
  232. package/internal/utils/path.d.ts +15 -0
  233. package/internal/utils/path.d.ts.map +1 -0
  234. package/internal/utils/path.js +79 -0
  235. package/internal/utils/path.js.map +1 -0
  236. package/internal/utils/path.mjs +74 -0
  237. package/internal/utils/path.mjs.map +1 -0
  238. package/internal/utils/sleep.d.mts +2 -0
  239. package/internal/utils/sleep.d.mts.map +1 -0
  240. package/internal/utils/sleep.d.ts +2 -0
  241. package/internal/utils/sleep.d.ts.map +1 -0
  242. package/internal/utils/sleep.js +7 -0
  243. package/internal/utils/sleep.js.map +1 -0
  244. package/internal/utils/sleep.mjs +3 -0
  245. package/internal/utils/sleep.mjs.map +1 -0
  246. package/internal/utils/uuid.d.mts +5 -0
  247. package/internal/utils/uuid.d.mts.map +1 -0
  248. package/internal/utils/uuid.d.ts +5 -0
  249. package/internal/utils/uuid.d.ts.map +1 -0
  250. package/internal/utils/uuid.js +19 -0
  251. package/internal/utils/uuid.js.map +1 -0
  252. package/internal/utils/uuid.mjs +15 -0
  253. package/internal/utils/uuid.mjs.map +1 -0
  254. package/internal/utils/values.d.mts +18 -0
  255. package/internal/utils/values.d.mts.map +1 -0
  256. package/internal/utils/values.d.ts +18 -0
  257. package/internal/utils/values.d.ts.map +1 -0
  258. package/internal/utils/values.js +112 -0
  259. package/internal/utils/values.js.map +1 -0
  260. package/internal/utils/values.mjs +94 -0
  261. package/internal/utils/values.mjs.map +1 -0
  262. package/internal/utils.d.mts +7 -0
  263. package/internal/utils.d.mts.map +1 -0
  264. package/internal/utils.d.ts +7 -0
  265. package/internal/utils.d.ts.map +1 -0
  266. package/internal/utils.js +11 -0
  267. package/internal/utils.js.map +1 -0
  268. package/internal/utils.mjs +8 -0
  269. package/internal/utils.mjs.map +1 -0
  270. package/package.json +138 -0
  271. package/resource.d.mts +2 -0
  272. package/resource.d.mts.map +1 -0
  273. package/resource.d.ts +2 -0
  274. package/resource.d.ts.map +1 -0
  275. package/resource.js +6 -0
  276. package/resource.js.map +1 -0
  277. package/resource.mjs +2 -0
  278. package/resource.mjs.map +1 -0
  279. package/resources/brand-safety.d.mts +234 -0
  280. package/resources/brand-safety.d.mts.map +1 -0
  281. package/resources/brand-safety.d.ts +234 -0
  282. package/resources/brand-safety.d.ts.map +1 -0
  283. package/resources/brand-safety.js +75 -0
  284. package/resources/brand-safety.js.map +1 -0
  285. package/resources/brand-safety.mjs +71 -0
  286. package/resources/brand-safety.mjs.map +1 -0
  287. package/resources/creators.d.mts +364 -0
  288. package/resources/creators.d.mts.map +1 -0
  289. package/resources/creators.d.ts +364 -0
  290. package/resources/creators.d.ts.map +1 -0
  291. package/resources/creators.js +119 -0
  292. package/resources/creators.js.map +1 -0
  293. package/resources/creators.mjs +115 -0
  294. package/resources/creators.mjs.map +1 -0
  295. package/resources/health.d.mts +17 -0
  296. package/resources/health.d.mts.map +1 -0
  297. package/resources/health.d.ts +17 -0
  298. package/resources/health.d.ts.map +1 -0
  299. package/resources/health.js +15 -0
  300. package/resources/health.js.map +1 -0
  301. package/resources/health.mjs +11 -0
  302. package/resources/health.mjs.map +1 -0
  303. package/resources/index.d.mts +9 -0
  304. package/resources/index.d.mts.map +1 -0
  305. package/resources/index.d.ts +9 -0
  306. package/resources/index.d.ts.map +1 -0
  307. package/resources/index.js +21 -0
  308. package/resources/index.js.map +1 -0
  309. package/resources/index.mjs +10 -0
  310. package/resources/index.mjs.map +1 -0
  311. package/resources/lookalike.d.mts +142 -0
  312. package/resources/lookalike.d.mts.map +1 -0
  313. package/resources/lookalike.d.ts +142 -0
  314. package/resources/lookalike.d.ts.map +1 -0
  315. package/resources/lookalike.js +28 -0
  316. package/resources/lookalike.js.map +1 -0
  317. package/resources/lookalike.mjs +24 -0
  318. package/resources/lookalike.mjs.map +1 -0
  319. package/resources/match.d.mts +90 -0
  320. package/resources/match.d.mts.map +1 -0
  321. package/resources/match.d.ts +90 -0
  322. package/resources/match.d.ts.map +1 -0
  323. package/resources/match.js +22 -0
  324. package/resources/match.js.map +1 -0
  325. package/resources/match.mjs +18 -0
  326. package/resources/match.mjs.map +1 -0
  327. package/resources/posts.d.mts +284 -0
  328. package/resources/posts.d.mts.map +1 -0
  329. package/resources/posts.d.ts +284 -0
  330. package/resources/posts.d.ts.map +1 -0
  331. package/resources/posts.js +55 -0
  332. package/resources/posts.js.map +1 -0
  333. package/resources/posts.mjs +51 -0
  334. package/resources/posts.mjs.map +1 -0
  335. package/resources/profiles.d.mts +99 -0
  336. package/resources/profiles.d.mts.map +1 -0
  337. package/resources/profiles.d.ts +99 -0
  338. package/resources/profiles.d.ts.map +1 -0
  339. package/resources/profiles.js +69 -0
  340. package/resources/profiles.js.map +1 -0
  341. package/resources/profiles.mjs +65 -0
  342. package/resources/profiles.mjs.map +1 -0
  343. package/resources/search.d.mts +189 -0
  344. package/resources/search.d.mts.map +1 -0
  345. package/resources/search.d.ts +189 -0
  346. package/resources/search.d.ts.map +1 -0
  347. package/resources/search.js +33 -0
  348. package/resources/search.js.map +1 -0
  349. package/resources/search.mjs +29 -0
  350. package/resources/search.mjs.map +1 -0
  351. package/resources.d.mts +2 -0
  352. package/resources.d.mts.map +1 -0
  353. package/resources.d.ts +2 -0
  354. package/resources.d.ts.map +1 -0
  355. package/resources.js +5 -0
  356. package/resources.js.map +1 -0
  357. package/resources.mjs +2 -0
  358. package/resources.mjs.map +1 -0
  359. package/src/api-promise.ts +2 -0
  360. package/src/client.ts +845 -0
  361. package/src/core/README.md +3 -0
  362. package/src/core/api-promise.ts +92 -0
  363. package/src/core/error.ts +130 -0
  364. package/src/core/resource.ts +11 -0
  365. package/src/core/uploads.ts +2 -0
  366. package/src/error.ts +2 -0
  367. package/src/index.ts +22 -0
  368. package/src/internal/README.md +3 -0
  369. package/src/internal/builtin-types.ts +93 -0
  370. package/src/internal/detect-platform.ts +196 -0
  371. package/src/internal/errors.ts +33 -0
  372. package/src/internal/headers.ts +97 -0
  373. package/src/internal/parse.ts +50 -0
  374. package/src/internal/qs/LICENSE.md +13 -0
  375. package/src/internal/qs/README.md +3 -0
  376. package/src/internal/qs/formats.ts +10 -0
  377. package/src/internal/qs/index.ts +13 -0
  378. package/src/internal/qs/stringify.ts +385 -0
  379. package/src/internal/qs/types.ts +71 -0
  380. package/src/internal/qs/utils.ts +265 -0
  381. package/src/internal/request-options.ts +91 -0
  382. package/src/internal/shim-types.ts +26 -0
  383. package/src/internal/shims.ts +107 -0
  384. package/src/internal/to-file.ts +154 -0
  385. package/src/internal/types.ts +95 -0
  386. package/src/internal/uploads.ts +187 -0
  387. package/src/internal/utils/base64.ts +40 -0
  388. package/src/internal/utils/bytes.ts +32 -0
  389. package/src/internal/utils/env.ts +18 -0
  390. package/src/internal/utils/log.ts +127 -0
  391. package/src/internal/utils/path.ts +88 -0
  392. package/src/internal/utils/sleep.ts +3 -0
  393. package/src/internal/utils/uuid.ts +17 -0
  394. package/src/internal/utils/values.ts +105 -0
  395. package/src/internal/utils.ts +8 -0
  396. package/src/lib/.keep +4 -0
  397. package/src/resource.ts +2 -0
  398. package/src/resources/brand-safety.ts +304 -0
  399. package/src/resources/creators.ts +450 -0
  400. package/src/resources/health.ts +24 -0
  401. package/src/resources/index.ts +62 -0
  402. package/src/resources/lookalike.ts +186 -0
  403. package/src/resources/match.ts +115 -0
  404. package/src/resources/posts.ts +347 -0
  405. package/src/resources/profiles.ts +114 -0
  406. package/src/resources/search.ts +234 -0
  407. package/src/resources.ts +1 -0
  408. package/src/tsconfig.json +11 -0
  409. package/src/uploads.ts +2 -0
  410. package/src/version.ts +1 -0
  411. package/uploads.d.mts +2 -0
  412. package/uploads.d.mts.map +1 -0
  413. package/uploads.d.ts +2 -0
  414. package/uploads.d.ts.map +1 -0
  415. package/uploads.js +6 -0
  416. package/uploads.js.map +1 -0
  417. package/uploads.mjs +2 -0
  418. package/uploads.mjs.map +1 -0
  419. package/version.d.mts +2 -0
  420. package/version.d.mts.map +1 -0
  421. package/version.d.ts +2 -0
  422. package/version.d.ts.map +1 -0
  423. package/version.js +5 -0
  424. package/version.js.map +1 -0
  425. package/version.mjs +2 -0
  426. package/version.mjs.map +1 -0
package/src/client.ts ADDED
@@ -0,0 +1,845 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import type { RequestInit, RequestInfo, BodyInit } from './internal/builtin-types';
4
+ import type { HTTPMethod, PromiseOrValue, MergedRequestInit, FinalizedRequestInit } from './internal/types';
5
+ import { uuid4 } from './internal/utils/uuid';
6
+ import { validatePositiveInteger, isAbsoluteURL, safeJSON } from './internal/utils/values';
7
+ import { sleep } from './internal/utils/sleep';
8
+ export type { Logger, LogLevel } from './internal/utils/log';
9
+ import { castToError, isAbortError } from './internal/errors';
10
+ import type { APIResponseProps } from './internal/parse';
11
+ import { getPlatformHeaders } from './internal/detect-platform';
12
+ import * as Shims from './internal/shims';
13
+ import * as Opts from './internal/request-options';
14
+ import * as qs from './internal/qs';
15
+ import { VERSION } from './version';
16
+ import * as Errors from './core/error';
17
+ import * as Uploads from './core/uploads';
18
+ import * as API from './resources/index';
19
+ import { APIPromise } from './core/api-promise';
20
+ import {
21
+ BrandSafety,
22
+ BrandSafetyAnalysis,
23
+ BrandSafetyAnalyzeCreatorsParams,
24
+ BrandSafetyAnalyzeCreatorsResponse,
25
+ BrandSafetyAnalyzePostsParams,
26
+ BrandSafetyAnalyzePostsResponse,
27
+ BrandSafetyAnalyzeProfilesParams,
28
+ BrandSafetyAnalyzeProfilesResponse,
29
+ BrandSafetyFlag,
30
+ BrandSafetyResult,
31
+ } from './resources/brand-safety';
32
+ import {
33
+ Creator,
34
+ CreatorAutocomplete,
35
+ CreatorAutocompleteParams,
36
+ CreatorAutocompleteResponse,
37
+ CreatorListProfilesParams,
38
+ CreatorListProfilesResponse,
39
+ CreatorRetrieveParams,
40
+ CreatorRetrieveResponse,
41
+ Creators,
42
+ SocialAccountDetailed,
43
+ SocialAccountLite,
44
+ } from './resources/creators';
45
+ import { Health, HealthCheckResponse } from './resources/health';
46
+ import {
47
+ Lookalike,
48
+ LookalikeFindSimilarCreatorsParams,
49
+ LookalikeFindSimilarCreatorsResponse,
50
+ LookalikeSeedBase,
51
+ } from './resources/lookalike';
52
+ import {
53
+ CreatorReferenceByID,
54
+ Match,
55
+ MatchAnalyzeParams,
56
+ MatchAnalyzeResponse,
57
+ MatchResult,
58
+ } from './resources/match';
59
+ import {
60
+ AIAnalysis,
61
+ CursorPagination,
62
+ PostAnalysis,
63
+ PostAnalyzeParams,
64
+ PostListByCreatorParams,
65
+ PostListByCreatorResponse,
66
+ Posts,
67
+ } from './resources/posts';
68
+ import {
69
+ CreatorReferenceByHandle,
70
+ ProfileLookupParams,
71
+ ProfileLookupResponse,
72
+ Profiles,
73
+ } from './resources/profiles';
74
+ import { Search, SearchFindCreatorsParams, SearchFindCreatorsResponse, SearchItem } from './resources/search';
75
+ import { type Fetch } from './internal/builtin-types';
76
+ import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
77
+ import { FinalRequestOptions, RequestOptions } from './internal/request-options';
78
+ import { readEnv } from './internal/utils/env';
79
+ import {
80
+ type LogLevel,
81
+ type Logger,
82
+ formatRequestDetails,
83
+ loggerFor,
84
+ parseLogLevel,
85
+ } from './internal/utils/log';
86
+ import { isEmptyObj } from './internal/utils/values';
87
+
88
+ export interface ClientOptions {
89
+ /**
90
+ * API key for authentication
91
+ */
92
+ apiKey?: string | undefined;
93
+
94
+ /**
95
+ * Override the default base URL for the API, e.g., "https://api.example.com/v2/"
96
+ *
97
+ * Defaults to process.env['INFLUSHIP_API_BASE_URL'].
98
+ */
99
+ baseURL?: string | null | undefined;
100
+
101
+ /**
102
+ * The maximum amount of time (in milliseconds) that the client should wait for a response
103
+ * from the server before timing out a single request.
104
+ *
105
+ * Note that request timeouts are retried by default, so in a worst-case scenario you may wait
106
+ * much longer than this timeout before the promise succeeds or fails.
107
+ *
108
+ * @unit milliseconds
109
+ */
110
+ timeout?: number | undefined;
111
+ /**
112
+ * Additional `RequestInit` options to be passed to `fetch` calls.
113
+ * Properties will be overridden by per-request `fetchOptions`.
114
+ */
115
+ fetchOptions?: MergedRequestInit | undefined;
116
+
117
+ /**
118
+ * Specify a custom `fetch` function implementation.
119
+ *
120
+ * If not provided, we expect that `fetch` is defined globally.
121
+ */
122
+ fetch?: Fetch | undefined;
123
+
124
+ /**
125
+ * The maximum number of times that the client will retry a request in case of a
126
+ * temporary failure, like a network error or a 5XX error from the server.
127
+ *
128
+ * @default 2
129
+ */
130
+ maxRetries?: number | undefined;
131
+
132
+ /**
133
+ * Default headers to include with every request to the API.
134
+ *
135
+ * These can be removed in individual requests by explicitly setting the
136
+ * header to `null` in request options.
137
+ */
138
+ defaultHeaders?: HeadersLike | undefined;
139
+
140
+ /**
141
+ * Default query parameters to include with every request to the API.
142
+ *
143
+ * These can be removed in individual requests by explicitly setting the
144
+ * param to `undefined` in request options.
145
+ */
146
+ defaultQuery?: Record<string, string | undefined> | undefined;
147
+
148
+ /**
149
+ * Set the log level.
150
+ *
151
+ * Defaults to process.env['INFLUSHIP_API_LOG'] or 'warn' if it isn't set.
152
+ */
153
+ logLevel?: LogLevel | undefined;
154
+
155
+ /**
156
+ * Set the logger.
157
+ *
158
+ * Defaults to globalThis.console.
159
+ */
160
+ logger?: Logger | undefined;
161
+ }
162
+
163
+ /**
164
+ * API Client for interfacing with the Influship API API.
165
+ */
166
+ export class InflushipAPI {
167
+ apiKey: string;
168
+
169
+ baseURL: string;
170
+ maxRetries: number;
171
+ timeout: number;
172
+ logger: Logger;
173
+ logLevel: LogLevel | undefined;
174
+ fetchOptions: MergedRequestInit | undefined;
175
+
176
+ private fetch: Fetch;
177
+ #encoder: Opts.RequestEncoder;
178
+ protected idempotencyHeader?: string;
179
+ private _options: ClientOptions;
180
+
181
+ /**
182
+ * API Client for interfacing with the Influship API API.
183
+ *
184
+ * @param {string | undefined} [opts.apiKey=process.env['INFLUSHIP_API_KEY'] ?? undefined]
185
+ * @param {string} [opts.baseURL=process.env['INFLUSHIP_API_BASE_URL'] ?? https://api.influship.com] - Override the default base URL for the API.
186
+ * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
187
+ * @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
188
+ * @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
189
+ * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
190
+ * @param {HeadersLike} opts.defaultHeaders - Default headers to include with every request to the API.
191
+ * @param {Record<string, string | undefined>} opts.defaultQuery - Default query parameters to include with every request to the API.
192
+ */
193
+ constructor({
194
+ baseURL = readEnv('INFLUSHIP_API_BASE_URL'),
195
+ apiKey = readEnv('INFLUSHIP_API_KEY'),
196
+ ...opts
197
+ }: ClientOptions = {}) {
198
+ if (apiKey === undefined) {
199
+ throw new Errors.InflushipAPIError(
200
+ "The INFLUSHIP_API_KEY environment variable is missing or empty; either provide it, or instantiate the InflushipAPI client with an apiKey option, like new InflushipAPI({ apiKey: 'My API Key' }).",
201
+ );
202
+ }
203
+
204
+ const options: ClientOptions = {
205
+ apiKey,
206
+ ...opts,
207
+ baseURL: baseURL || `https://api.influship.com`,
208
+ };
209
+
210
+ this.baseURL = options.baseURL!;
211
+ this.timeout = options.timeout ?? InflushipAPI.DEFAULT_TIMEOUT /* 1 minute */;
212
+ this.logger = options.logger ?? console;
213
+ const defaultLogLevel = 'warn';
214
+ // Set default logLevel early so that we can log a warning in parseLogLevel.
215
+ this.logLevel = defaultLogLevel;
216
+ this.logLevel =
217
+ parseLogLevel(options.logLevel, 'ClientOptions.logLevel', this) ??
218
+ parseLogLevel(readEnv('INFLUSHIP_API_LOG'), "process.env['INFLUSHIP_API_LOG']", this) ??
219
+ defaultLogLevel;
220
+ this.fetchOptions = options.fetchOptions;
221
+ this.maxRetries = options.maxRetries ?? 2;
222
+ this.fetch = options.fetch ?? Shims.getDefaultFetch();
223
+ this.#encoder = Opts.FallbackEncoder;
224
+
225
+ this._options = options;
226
+
227
+ this.apiKey = apiKey;
228
+ }
229
+
230
+ /**
231
+ * Create a new client instance re-using the same options given to the current client with optional overriding.
232
+ */
233
+ withOptions(options: Partial<ClientOptions>): this {
234
+ const client = new (this.constructor as any as new (props: ClientOptions) => typeof this)({
235
+ ...this._options,
236
+ baseURL: this.baseURL,
237
+ maxRetries: this.maxRetries,
238
+ timeout: this.timeout,
239
+ logger: this.logger,
240
+ logLevel: this.logLevel,
241
+ fetch: this.fetch,
242
+ fetchOptions: this.fetchOptions,
243
+ apiKey: this.apiKey,
244
+ ...options,
245
+ });
246
+ return client;
247
+ }
248
+
249
+ /**
250
+ * Check whether the base URL is set to its default.
251
+ */
252
+ #baseURLOverridden(): boolean {
253
+ return this.baseURL !== 'https://api.influship.com';
254
+ }
255
+
256
+ protected defaultQuery(): Record<string, string | undefined> | undefined {
257
+ return this._options.defaultQuery;
258
+ }
259
+
260
+ protected validateHeaders({ values, nulls }: NullableHeaders) {
261
+ return;
262
+ }
263
+
264
+ protected async authHeaders(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {
265
+ return buildHeaders([{ 'X-API-Key': this.apiKey }]);
266
+ }
267
+
268
+ protected stringifyQuery(query: Record<string, unknown>): string {
269
+ return qs.stringify(query, { arrayFormat: 'comma' });
270
+ }
271
+
272
+ private getUserAgent(): string {
273
+ return `${this.constructor.name}/JS ${VERSION}`;
274
+ }
275
+
276
+ protected defaultIdempotencyKey(): string {
277
+ return `stainless-node-retry-${uuid4()}`;
278
+ }
279
+
280
+ protected makeStatusError(
281
+ status: number,
282
+ error: Object,
283
+ message: string | undefined,
284
+ headers: Headers,
285
+ ): Errors.APIError {
286
+ return Errors.APIError.generate(status, error, message, headers);
287
+ }
288
+
289
+ buildURL(
290
+ path: string,
291
+ query: Record<string, unknown> | null | undefined,
292
+ defaultBaseURL?: string | undefined,
293
+ ): string {
294
+ const baseURL = (!this.#baseURLOverridden() && defaultBaseURL) || this.baseURL;
295
+ const url =
296
+ isAbsoluteURL(path) ?
297
+ new URL(path)
298
+ : new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
299
+
300
+ const defaultQuery = this.defaultQuery();
301
+ if (!isEmptyObj(defaultQuery)) {
302
+ query = { ...defaultQuery, ...query };
303
+ }
304
+
305
+ if (typeof query === 'object' && query && !Array.isArray(query)) {
306
+ url.search = this.stringifyQuery(query as Record<string, unknown>);
307
+ }
308
+
309
+ return url.toString();
310
+ }
311
+
312
+ /**
313
+ * Used as a callback for mutating the given `FinalRequestOptions` object.
314
+ */
315
+ protected async prepareOptions(options: FinalRequestOptions): Promise<void> {}
316
+
317
+ /**
318
+ * Used as a callback for mutating the given `RequestInit` object.
319
+ *
320
+ * This is useful for cases where you want to add certain headers based off of
321
+ * the request properties, e.g. `method` or `url`.
322
+ */
323
+ protected async prepareRequest(
324
+ request: RequestInit,
325
+ { url, options }: { url: string; options: FinalRequestOptions },
326
+ ): Promise<void> {}
327
+
328
+ get<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
329
+ return this.methodRequest('get', path, opts);
330
+ }
331
+
332
+ post<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
333
+ return this.methodRequest('post', path, opts);
334
+ }
335
+
336
+ patch<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
337
+ return this.methodRequest('patch', path, opts);
338
+ }
339
+
340
+ put<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
341
+ return this.methodRequest('put', path, opts);
342
+ }
343
+
344
+ delete<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
345
+ return this.methodRequest('delete', path, opts);
346
+ }
347
+
348
+ private methodRequest<Rsp>(
349
+ method: HTTPMethod,
350
+ path: string,
351
+ opts?: PromiseOrValue<RequestOptions>,
352
+ ): APIPromise<Rsp> {
353
+ return this.request(
354
+ Promise.resolve(opts).then((opts) => {
355
+ return { method, path, ...opts };
356
+ }),
357
+ );
358
+ }
359
+
360
+ request<Rsp>(
361
+ options: PromiseOrValue<FinalRequestOptions>,
362
+ remainingRetries: number | null = null,
363
+ ): APIPromise<Rsp> {
364
+ return new APIPromise(this, this.makeRequest(options, remainingRetries, undefined));
365
+ }
366
+
367
+ private async makeRequest(
368
+ optionsInput: PromiseOrValue<FinalRequestOptions>,
369
+ retriesRemaining: number | null,
370
+ retryOfRequestLogID: string | undefined,
371
+ ): Promise<APIResponseProps> {
372
+ const options = await optionsInput;
373
+ const maxRetries = options.maxRetries ?? this.maxRetries;
374
+ if (retriesRemaining == null) {
375
+ retriesRemaining = maxRetries;
376
+ }
377
+
378
+ await this.prepareOptions(options);
379
+
380
+ const { req, url, timeout } = await this.buildRequest(options, {
381
+ retryCount: maxRetries - retriesRemaining,
382
+ });
383
+
384
+ await this.prepareRequest(req, { url, options });
385
+
386
+ /** Not an API request ID, just for correlating local log entries. */
387
+ const requestLogID = 'log_' + ((Math.random() * (1 << 24)) | 0).toString(16).padStart(6, '0');
388
+ const retryLogStr = retryOfRequestLogID === undefined ? '' : `, retryOf: ${retryOfRequestLogID}`;
389
+ const startTime = Date.now();
390
+
391
+ loggerFor(this).debug(
392
+ `[${requestLogID}] sending request`,
393
+ formatRequestDetails({
394
+ retryOfRequestLogID,
395
+ method: options.method,
396
+ url,
397
+ options,
398
+ headers: req.headers,
399
+ }),
400
+ );
401
+
402
+ if (options.signal?.aborted) {
403
+ throw new Errors.APIUserAbortError();
404
+ }
405
+
406
+ const controller = new AbortController();
407
+ const response = await this.fetchWithTimeout(url, req, timeout, controller).catch(castToError);
408
+ const headersTime = Date.now();
409
+
410
+ if (response instanceof globalThis.Error) {
411
+ const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
412
+ if (options.signal?.aborted) {
413
+ throw new Errors.APIUserAbortError();
414
+ }
415
+ // detect native connection timeout errors
416
+ // deno throws "TypeError: error sending request for url (https://example/): client error (Connect): tcp connect error: Operation timed out (os error 60): Operation timed out (os error 60)"
417
+ // undici throws "TypeError: fetch failed" with cause "ConnectTimeoutError: Connect Timeout Error (attempted address: example:443, timeout: 1ms)"
418
+ // others do not provide enough information to distinguish timeouts from other connection errors
419
+ const isTimeout =
420
+ isAbortError(response) ||
421
+ /timed? ?out/i.test(String(response) + ('cause' in response ? String(response.cause) : ''));
422
+ if (retriesRemaining) {
423
+ loggerFor(this).info(
424
+ `[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} - ${retryMessage}`,
425
+ );
426
+ loggerFor(this).debug(
427
+ `[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} (${retryMessage})`,
428
+ formatRequestDetails({
429
+ retryOfRequestLogID,
430
+ url,
431
+ durationMs: headersTime - startTime,
432
+ message: response.message,
433
+ }),
434
+ );
435
+ return this.retryRequest(options, retriesRemaining, retryOfRequestLogID ?? requestLogID);
436
+ }
437
+ loggerFor(this).info(
438
+ `[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} - error; no more retries left`,
439
+ );
440
+ loggerFor(this).debug(
441
+ `[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} (error; no more retries left)`,
442
+ formatRequestDetails({
443
+ retryOfRequestLogID,
444
+ url,
445
+ durationMs: headersTime - startTime,
446
+ message: response.message,
447
+ }),
448
+ );
449
+ if (isTimeout) {
450
+ throw new Errors.APIConnectionTimeoutError();
451
+ }
452
+ throw new Errors.APIConnectionError({ cause: response });
453
+ }
454
+
455
+ const responseInfo = `[${requestLogID}${retryLogStr}] ${req.method} ${url} ${
456
+ response.ok ? 'succeeded' : 'failed'
457
+ } with status ${response.status} in ${headersTime - startTime}ms`;
458
+
459
+ if (!response.ok) {
460
+ const shouldRetry = await this.shouldRetry(response);
461
+ if (retriesRemaining && shouldRetry) {
462
+ const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
463
+
464
+ // We don't need the body of this response.
465
+ await Shims.CancelReadableStream(response.body);
466
+ loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
467
+ loggerFor(this).debug(
468
+ `[${requestLogID}] response error (${retryMessage})`,
469
+ formatRequestDetails({
470
+ retryOfRequestLogID,
471
+ url: response.url,
472
+ status: response.status,
473
+ headers: response.headers,
474
+ durationMs: headersTime - startTime,
475
+ }),
476
+ );
477
+ return this.retryRequest(
478
+ options,
479
+ retriesRemaining,
480
+ retryOfRequestLogID ?? requestLogID,
481
+ response.headers,
482
+ );
483
+ }
484
+
485
+ const retryMessage = shouldRetry ? `error; no more retries left` : `error; not retryable`;
486
+
487
+ loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
488
+
489
+ const errText = await response.text().catch((err: any) => castToError(err).message);
490
+ const errJSON = safeJSON(errText);
491
+ const errMessage = errJSON ? undefined : errText;
492
+
493
+ loggerFor(this).debug(
494
+ `[${requestLogID}] response error (${retryMessage})`,
495
+ formatRequestDetails({
496
+ retryOfRequestLogID,
497
+ url: response.url,
498
+ status: response.status,
499
+ headers: response.headers,
500
+ message: errMessage,
501
+ durationMs: Date.now() - startTime,
502
+ }),
503
+ );
504
+
505
+ const err = this.makeStatusError(response.status, errJSON, errMessage, response.headers);
506
+ throw err;
507
+ }
508
+
509
+ loggerFor(this).info(responseInfo);
510
+ loggerFor(this).debug(
511
+ `[${requestLogID}] response start`,
512
+ formatRequestDetails({
513
+ retryOfRequestLogID,
514
+ url: response.url,
515
+ status: response.status,
516
+ headers: response.headers,
517
+ durationMs: headersTime - startTime,
518
+ }),
519
+ );
520
+
521
+ return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };
522
+ }
523
+
524
+ async fetchWithTimeout(
525
+ url: RequestInfo,
526
+ init: RequestInit | undefined,
527
+ ms: number,
528
+ controller: AbortController,
529
+ ): Promise<Response> {
530
+ const { signal, method, ...options } = init || {};
531
+ if (signal) signal.addEventListener('abort', () => controller.abort());
532
+
533
+ const timeout = setTimeout(() => controller.abort(), ms);
534
+
535
+ const isReadableBody =
536
+ ((globalThis as any).ReadableStream && options.body instanceof (globalThis as any).ReadableStream) ||
537
+ (typeof options.body === 'object' && options.body !== null && Symbol.asyncIterator in options.body);
538
+
539
+ const fetchOptions: RequestInit = {
540
+ signal: controller.signal as any,
541
+ ...(isReadableBody ? { duplex: 'half' } : {}),
542
+ method: 'GET',
543
+ ...options,
544
+ };
545
+ if (method) {
546
+ // Custom methods like 'patch' need to be uppercased
547
+ // See https://github.com/nodejs/undici/issues/2294
548
+ fetchOptions.method = method.toUpperCase();
549
+ }
550
+
551
+ try {
552
+ // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
553
+ return await this.fetch.call(undefined, url, fetchOptions);
554
+ } finally {
555
+ clearTimeout(timeout);
556
+ }
557
+ }
558
+
559
+ private async shouldRetry(response: Response): Promise<boolean> {
560
+ // Note this is not a standard header.
561
+ const shouldRetryHeader = response.headers.get('x-should-retry');
562
+
563
+ // If the server explicitly says whether or not to retry, obey.
564
+ if (shouldRetryHeader === 'true') return true;
565
+ if (shouldRetryHeader === 'false') return false;
566
+
567
+ // Retry on request timeouts.
568
+ if (response.status === 408) return true;
569
+
570
+ // Retry on lock timeouts.
571
+ if (response.status === 409) return true;
572
+
573
+ // Retry on rate limits.
574
+ if (response.status === 429) return true;
575
+
576
+ // Retry internal errors.
577
+ if (response.status >= 500) return true;
578
+
579
+ return false;
580
+ }
581
+
582
+ private async retryRequest(
583
+ options: FinalRequestOptions,
584
+ retriesRemaining: number,
585
+ requestLogID: string,
586
+ responseHeaders?: Headers | undefined,
587
+ ): Promise<APIResponseProps> {
588
+ let timeoutMillis: number | undefined;
589
+
590
+ // Note the `retry-after-ms` header may not be standard, but is a good idea and we'd like proactive support for it.
591
+ const retryAfterMillisHeader = responseHeaders?.get('retry-after-ms');
592
+ if (retryAfterMillisHeader) {
593
+ const timeoutMs = parseFloat(retryAfterMillisHeader);
594
+ if (!Number.isNaN(timeoutMs)) {
595
+ timeoutMillis = timeoutMs;
596
+ }
597
+ }
598
+
599
+ // About the Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
600
+ const retryAfterHeader = responseHeaders?.get('retry-after');
601
+ if (retryAfterHeader && !timeoutMillis) {
602
+ const timeoutSeconds = parseFloat(retryAfterHeader);
603
+ if (!Number.isNaN(timeoutSeconds)) {
604
+ timeoutMillis = timeoutSeconds * 1000;
605
+ } else {
606
+ timeoutMillis = Date.parse(retryAfterHeader) - Date.now();
607
+ }
608
+ }
609
+
610
+ // If the API asks us to wait a certain amount of time (and it's a reasonable amount),
611
+ // just do what it says, but otherwise calculate a default
612
+ if (!(timeoutMillis && 0 <= timeoutMillis && timeoutMillis < 60 * 1000)) {
613
+ const maxRetries = options.maxRetries ?? this.maxRetries;
614
+ timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
615
+ }
616
+ await sleep(timeoutMillis);
617
+
618
+ return this.makeRequest(options, retriesRemaining - 1, requestLogID);
619
+ }
620
+
621
+ private calculateDefaultRetryTimeoutMillis(retriesRemaining: number, maxRetries: number): number {
622
+ const initialRetryDelay = 0.5;
623
+ const maxRetryDelay = 8.0;
624
+
625
+ const numRetries = maxRetries - retriesRemaining;
626
+
627
+ // Apply exponential backoff, but not more than the max.
628
+ const sleepSeconds = Math.min(initialRetryDelay * Math.pow(2, numRetries), maxRetryDelay);
629
+
630
+ // Apply some jitter, take up to at most 25 percent of the retry time.
631
+ const jitter = 1 - Math.random() * 0.25;
632
+
633
+ return sleepSeconds * jitter * 1000;
634
+ }
635
+
636
+ async buildRequest(
637
+ inputOptions: FinalRequestOptions,
638
+ { retryCount = 0 }: { retryCount?: number } = {},
639
+ ): Promise<{ req: FinalizedRequestInit; url: string; timeout: number }> {
640
+ const options = { ...inputOptions };
641
+ const { method, path, query, defaultBaseURL } = options;
642
+
643
+ const url = this.buildURL(path!, query as Record<string, unknown>, defaultBaseURL);
644
+ if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
645
+ options.timeout = options.timeout ?? this.timeout;
646
+ const { bodyHeaders, body } = this.buildBody({ options });
647
+ const reqHeaders = await this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
648
+
649
+ const req: FinalizedRequestInit = {
650
+ method,
651
+ headers: reqHeaders,
652
+ ...(options.signal && { signal: options.signal }),
653
+ ...((globalThis as any).ReadableStream &&
654
+ body instanceof (globalThis as any).ReadableStream && { duplex: 'half' }),
655
+ ...(body && { body }),
656
+ ...((this.fetchOptions as any) ?? {}),
657
+ ...((options.fetchOptions as any) ?? {}),
658
+ };
659
+
660
+ return { req, url, timeout: options.timeout };
661
+ }
662
+
663
+ private async buildHeaders({
664
+ options,
665
+ method,
666
+ bodyHeaders,
667
+ retryCount,
668
+ }: {
669
+ options: FinalRequestOptions;
670
+ method: HTTPMethod;
671
+ bodyHeaders: HeadersLike;
672
+ retryCount: number;
673
+ }): Promise<Headers> {
674
+ let idempotencyHeaders: HeadersLike = {};
675
+ if (this.idempotencyHeader && method !== 'get') {
676
+ if (!options.idempotencyKey) options.idempotencyKey = this.defaultIdempotencyKey();
677
+ idempotencyHeaders[this.idempotencyHeader] = options.idempotencyKey;
678
+ }
679
+
680
+ const headers = buildHeaders([
681
+ idempotencyHeaders,
682
+ {
683
+ Accept: 'application/json',
684
+ 'User-Agent': this.getUserAgent(),
685
+ 'X-Stainless-Retry-Count': String(retryCount),
686
+ ...(options.timeout ? { 'X-Stainless-Timeout': String(Math.trunc(options.timeout / 1000)) } : {}),
687
+ ...getPlatformHeaders(),
688
+ },
689
+ await this.authHeaders(options),
690
+ this._options.defaultHeaders,
691
+ bodyHeaders,
692
+ options.headers,
693
+ ]);
694
+
695
+ this.validateHeaders(headers);
696
+
697
+ return headers.values;
698
+ }
699
+
700
+ private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {
701
+ bodyHeaders: HeadersLike;
702
+ body: BodyInit | undefined;
703
+ } {
704
+ if (!body) {
705
+ return { bodyHeaders: undefined, body: undefined };
706
+ }
707
+ const headers = buildHeaders([rawHeaders]);
708
+ if (
709
+ // Pass raw type verbatim
710
+ ArrayBuffer.isView(body) ||
711
+ body instanceof ArrayBuffer ||
712
+ body instanceof DataView ||
713
+ (typeof body === 'string' &&
714
+ // Preserve legacy string encoding behavior for now
715
+ headers.values.has('content-type')) ||
716
+ // `Blob` is superset of `File`
717
+ ((globalThis as any).Blob && body instanceof (globalThis as any).Blob) ||
718
+ // `FormData` -> `multipart/form-data`
719
+ body instanceof FormData ||
720
+ // `URLSearchParams` -> `application/x-www-form-urlencoded`
721
+ body instanceof URLSearchParams ||
722
+ // Send chunked stream (each chunk has own `length`)
723
+ ((globalThis as any).ReadableStream && body instanceof (globalThis as any).ReadableStream)
724
+ ) {
725
+ return { bodyHeaders: undefined, body: body as BodyInit };
726
+ } else if (
727
+ typeof body === 'object' &&
728
+ (Symbol.asyncIterator in body ||
729
+ (Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))
730
+ ) {
731
+ return { bodyHeaders: undefined, body: Shims.ReadableStreamFrom(body as AsyncIterable<Uint8Array>) };
732
+ } else {
733
+ return this.#encoder({ body, headers });
734
+ }
735
+ }
736
+
737
+ static InflushipAPI = this;
738
+ static DEFAULT_TIMEOUT = 60000; // 1 minute
739
+
740
+ static InflushipAPIError = Errors.InflushipAPIError;
741
+ static APIError = Errors.APIError;
742
+ static APIConnectionError = Errors.APIConnectionError;
743
+ static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
744
+ static APIUserAbortError = Errors.APIUserAbortError;
745
+ static NotFoundError = Errors.NotFoundError;
746
+ static ConflictError = Errors.ConflictError;
747
+ static RateLimitError = Errors.RateLimitError;
748
+ static BadRequestError = Errors.BadRequestError;
749
+ static AuthenticationError = Errors.AuthenticationError;
750
+ static InternalServerError = Errors.InternalServerError;
751
+ static PermissionDeniedError = Errors.PermissionDeniedError;
752
+ static UnprocessableEntityError = Errors.UnprocessableEntityError;
753
+
754
+ static toFile = Uploads.toFile;
755
+
756
+ health: API.Health = new API.Health(this);
757
+ search: API.Search = new API.Search(this);
758
+ creators: API.Creators = new API.Creators(this);
759
+ profiles: API.Profiles = new API.Profiles(this);
760
+ lookalike: API.Lookalike = new API.Lookalike(this);
761
+ posts: API.Posts = new API.Posts(this);
762
+ match: API.Match = new API.Match(this);
763
+ brandSafety: API.BrandSafety = new API.BrandSafety(this);
764
+ }
765
+
766
+ InflushipAPI.Health = Health;
767
+ InflushipAPI.Search = Search;
768
+ InflushipAPI.Creators = Creators;
769
+ InflushipAPI.Profiles = Profiles;
770
+ InflushipAPI.Lookalike = Lookalike;
771
+ InflushipAPI.Posts = Posts;
772
+ InflushipAPI.Match = Match;
773
+ InflushipAPI.BrandSafety = BrandSafety;
774
+
775
+ export declare namespace InflushipAPI {
776
+ export type RequestOptions = Opts.RequestOptions;
777
+
778
+ export { Health as Health, type HealthCheckResponse as HealthCheckResponse };
779
+
780
+ export {
781
+ Search as Search,
782
+ type SearchItem as SearchItem,
783
+ type SearchFindCreatorsResponse as SearchFindCreatorsResponse,
784
+ type SearchFindCreatorsParams as SearchFindCreatorsParams,
785
+ };
786
+
787
+ export {
788
+ Creators as Creators,
789
+ type Creator as Creator,
790
+ type CreatorAutocomplete as CreatorAutocomplete,
791
+ type SocialAccountDetailed as SocialAccountDetailed,
792
+ type SocialAccountLite as SocialAccountLite,
793
+ type CreatorRetrieveResponse as CreatorRetrieveResponse,
794
+ type CreatorAutocompleteResponse as CreatorAutocompleteResponse,
795
+ type CreatorListProfilesResponse as CreatorListProfilesResponse,
796
+ type CreatorRetrieveParams as CreatorRetrieveParams,
797
+ type CreatorAutocompleteParams as CreatorAutocompleteParams,
798
+ type CreatorListProfilesParams as CreatorListProfilesParams,
799
+ };
800
+
801
+ export {
802
+ Profiles as Profiles,
803
+ type CreatorReferenceByHandle as CreatorReferenceByHandle,
804
+ type ProfileLookupResponse as ProfileLookupResponse,
805
+ type ProfileLookupParams as ProfileLookupParams,
806
+ };
807
+
808
+ export {
809
+ Lookalike as Lookalike,
810
+ type LookalikeSeedBase as LookalikeSeedBase,
811
+ type LookalikeFindSimilarCreatorsResponse as LookalikeFindSimilarCreatorsResponse,
812
+ type LookalikeFindSimilarCreatorsParams as LookalikeFindSimilarCreatorsParams,
813
+ };
814
+
815
+ export {
816
+ Posts as Posts,
817
+ type AIAnalysis as AIAnalysis,
818
+ type CursorPagination as CursorPagination,
819
+ type PostAnalysis as PostAnalysis,
820
+ type PostListByCreatorResponse as PostListByCreatorResponse,
821
+ type PostAnalyzeParams as PostAnalyzeParams,
822
+ type PostListByCreatorParams as PostListByCreatorParams,
823
+ };
824
+
825
+ export {
826
+ Match as Match,
827
+ type CreatorReferenceByID as CreatorReferenceByID,
828
+ type MatchResult as MatchResult,
829
+ type MatchAnalyzeResponse as MatchAnalyzeResponse,
830
+ type MatchAnalyzeParams as MatchAnalyzeParams,
831
+ };
832
+
833
+ export {
834
+ BrandSafety as BrandSafety,
835
+ type BrandSafetyAnalysis as BrandSafetyAnalysis,
836
+ type BrandSafetyFlag as BrandSafetyFlag,
837
+ type BrandSafetyResult as BrandSafetyResult,
838
+ type BrandSafetyAnalyzeCreatorsResponse as BrandSafetyAnalyzeCreatorsResponse,
839
+ type BrandSafetyAnalyzePostsResponse as BrandSafetyAnalyzePostsResponse,
840
+ type BrandSafetyAnalyzeProfilesResponse as BrandSafetyAnalyzeProfilesResponse,
841
+ type BrandSafetyAnalyzeCreatorsParams as BrandSafetyAnalyzeCreatorsParams,
842
+ type BrandSafetyAnalyzePostsParams as BrandSafetyAnalyzePostsParams,
843
+ type BrandSafetyAnalyzeProfilesParams as BrandSafetyAnalyzeProfilesParams,
844
+ };
845
+ }