@stigg/typescript 0.1.0-alpha.1 → 0.1.0-alpha.11

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 (317) hide show
  1. package/CHANGELOG.md +158 -0
  2. package/README.md +40 -0
  3. package/client.d.mts +6 -8
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts +6 -8
  6. package/client.d.ts.map +1 -1
  7. package/client.js +23 -21
  8. package/client.js.map +1 -1
  9. package/client.mjs +24 -22
  10. package/client.mjs.map +1 -1
  11. package/core/pagination.d.mts +11 -5
  12. package/core/pagination.d.mts.map +1 -1
  13. package/core/pagination.d.ts +11 -5
  14. package/core/pagination.d.ts.map +1 -1
  15. package/core/pagination.js +9 -9
  16. package/core/pagination.js.map +1 -1
  17. package/core/pagination.mjs +9 -9
  18. package/core/pagination.mjs.map +1 -1
  19. package/internal/parse.d.mts.map +1 -1
  20. package/internal/parse.d.ts.map +1 -1
  21. package/internal/parse.js +5 -0
  22. package/internal/parse.js.map +1 -1
  23. package/internal/parse.mjs +5 -0
  24. package/internal/parse.mjs.map +1 -1
  25. package/internal/qs/formats.d.mts +7 -0
  26. package/internal/qs/formats.d.mts.map +1 -0
  27. package/internal/qs/formats.d.ts +7 -0
  28. package/internal/qs/formats.d.ts.map +1 -0
  29. package/internal/qs/formats.js +13 -0
  30. package/internal/qs/formats.js.map +1 -0
  31. package/internal/qs/formats.mjs +9 -0
  32. package/internal/qs/formats.mjs.map +1 -0
  33. package/internal/qs/index.d.mts +10 -0
  34. package/internal/qs/index.d.mts.map +1 -0
  35. package/internal/qs/index.d.ts +10 -0
  36. package/internal/qs/index.d.ts.map +1 -0
  37. package/internal/qs/index.js +14 -0
  38. package/internal/qs/index.js.map +1 -0
  39. package/internal/qs/index.mjs +10 -0
  40. package/internal/qs/index.mjs.map +1 -0
  41. package/internal/qs/stringify.d.mts +3 -0
  42. package/internal/qs/stringify.d.mts.map +1 -0
  43. package/internal/qs/stringify.d.ts +3 -0
  44. package/internal/qs/stringify.d.ts.map +1 -0
  45. package/internal/qs/stringify.js +277 -0
  46. package/internal/qs/stringify.js.map +1 -0
  47. package/internal/qs/stringify.mjs +274 -0
  48. package/internal/qs/stringify.mjs.map +1 -0
  49. package/internal/qs/types.d.mts +57 -0
  50. package/internal/qs/types.d.mts.map +1 -0
  51. package/internal/qs/types.d.ts +57 -0
  52. package/internal/qs/types.d.ts.map +1 -0
  53. package/internal/qs/types.js +3 -0
  54. package/internal/qs/types.js.map +1 -0
  55. package/internal/qs/types.mjs +2 -0
  56. package/internal/qs/types.mjs.map +1 -0
  57. package/internal/qs/utils.d.mts +15 -0
  58. package/internal/qs/utils.d.mts.map +1 -0
  59. package/internal/qs/utils.d.ts +15 -0
  60. package/internal/qs/utils.d.ts.map +1 -0
  61. package/internal/qs/utils.js +230 -0
  62. package/internal/qs/utils.js.map +1 -0
  63. package/internal/qs/utils.mjs +217 -0
  64. package/internal/qs/utils.mjs.map +1 -0
  65. package/package.json +1 -1
  66. package/resources/index.d.mts +1 -1
  67. package/resources/index.d.mts.map +1 -1
  68. package/resources/index.d.ts +1 -1
  69. package/resources/index.d.ts.map +1 -1
  70. package/resources/index.js.map +1 -1
  71. package/resources/index.mjs +1 -1
  72. package/resources/index.mjs.map +1 -1
  73. package/resources/v1/addons/addons.d.mts +1298 -0
  74. package/resources/v1/addons/addons.d.mts.map +1 -0
  75. package/resources/v1/addons/addons.d.ts +1298 -0
  76. package/resources/v1/addons/addons.d.ts.map +1 -0
  77. package/resources/v1/addons/addons.js +78 -0
  78. package/resources/v1/addons/addons.js.map +1 -0
  79. package/resources/v1/addons/addons.mjs +73 -0
  80. package/resources/v1/addons/addons.mjs.map +1 -0
  81. package/resources/v1/addons/entitlements.d.mts +747 -0
  82. package/resources/v1/addons/entitlements.d.mts.map +1 -0
  83. package/resources/v1/addons/entitlements.d.ts +747 -0
  84. package/resources/v1/addons/entitlements.d.ts.map +1 -0
  85. package/resources/v1/addons/entitlements.js +36 -0
  86. package/resources/v1/addons/entitlements.js.map +1 -0
  87. package/resources/v1/addons/entitlements.mjs +32 -0
  88. package/resources/v1/addons/entitlements.mjs.map +1 -0
  89. package/resources/v1/addons/index.d.mts +3 -0
  90. package/resources/v1/addons/index.d.mts.map +1 -0
  91. package/resources/v1/addons/index.d.ts +3 -0
  92. package/resources/v1/addons/index.d.ts.map +1 -0
  93. package/resources/v1/addons/index.js +9 -0
  94. package/resources/v1/addons/index.js.map +1 -0
  95. package/resources/v1/addons/index.mjs +4 -0
  96. package/resources/v1/addons/index.mjs.map +1 -0
  97. package/resources/v1/addons.d.mts +2 -0
  98. package/resources/v1/addons.d.mts.map +1 -0
  99. package/resources/v1/addons.d.ts +2 -0
  100. package/resources/v1/addons.d.ts.map +1 -0
  101. package/resources/v1/addons.js +6 -0
  102. package/resources/v1/addons.js.map +1 -0
  103. package/resources/v1/addons.mjs +3 -0
  104. package/resources/v1/addons.mjs.map +1 -0
  105. package/resources/v1/coupons.d.mts +154 -157
  106. package/resources/v1/coupons.d.mts.map +1 -1
  107. package/resources/v1/coupons.d.ts +154 -157
  108. package/resources/v1/coupons.d.ts.map +1 -1
  109. package/resources/v1/coupons.js +21 -4
  110. package/resources/v1/coupons.js.map +1 -1
  111. package/resources/v1/coupons.mjs +21 -4
  112. package/resources/v1/coupons.mjs.map +1 -1
  113. package/resources/v1/customers/customers.d.mts +247 -118
  114. package/resources/v1/customers/customers.d.mts.map +1 -1
  115. package/resources/v1/customers/customers.d.ts +247 -118
  116. package/resources/v1/customers/customers.d.ts.map +1 -1
  117. package/resources/v1/customers/customers.js +37 -16
  118. package/resources/v1/customers/customers.js.map +1 -1
  119. package/resources/v1/customers/customers.mjs +37 -16
  120. package/resources/v1/customers/customers.mjs.map +1 -1
  121. package/resources/v1/customers/index.d.mts +2 -2
  122. package/resources/v1/customers/index.d.mts.map +1 -1
  123. package/resources/v1/customers/index.d.ts +2 -2
  124. package/resources/v1/customers/index.d.ts.map +1 -1
  125. package/resources/v1/customers/index.js +3 -3
  126. package/resources/v1/customers/index.js.map +1 -1
  127. package/resources/v1/customers/index.mjs +1 -1
  128. package/resources/v1/customers/index.mjs.map +1 -1
  129. package/resources/v1/customers/payment-method.d.mts +7 -2
  130. package/resources/v1/customers/payment-method.d.mts.map +1 -1
  131. package/resources/v1/customers/payment-method.d.ts +7 -2
  132. package/resources/v1/customers/payment-method.d.ts.map +1 -1
  133. package/resources/v1/customers/payment-method.js +4 -2
  134. package/resources/v1/customers/payment-method.js.map +1 -1
  135. package/resources/v1/customers/payment-method.mjs +4 -2
  136. package/resources/v1/customers/payment-method.mjs.map +1 -1
  137. package/resources/v1/customers/promotional-entitlements.d.mts +498 -0
  138. package/resources/v1/customers/promotional-entitlements.d.mts.map +1 -0
  139. package/resources/v1/customers/promotional-entitlements.d.ts +498 -0
  140. package/resources/v1/customers/promotional-entitlements.d.ts.map +1 -0
  141. package/resources/v1/customers/promotional-entitlements.js +32 -0
  142. package/resources/v1/customers/promotional-entitlements.js.map +1 -0
  143. package/resources/v1/customers/promotional-entitlements.mjs +28 -0
  144. package/resources/v1/customers/promotional-entitlements.mjs.map +1 -0
  145. package/resources/v1/events.d.mts +63 -0
  146. package/resources/v1/events.d.mts.map +1 -0
  147. package/resources/v1/events.d.ts +63 -0
  148. package/resources/v1/events.d.ts.map +1 -0
  149. package/resources/v1/events.js +16 -0
  150. package/resources/v1/events.js.map +1 -0
  151. package/resources/v1/events.mjs +12 -0
  152. package/resources/v1/events.mjs.map +1 -0
  153. package/resources/v1/features.d.mts +444 -0
  154. package/resources/v1/features.d.mts.map +1 -0
  155. package/resources/v1/features.d.ts +444 -0
  156. package/resources/v1/features.d.ts.map +1 -0
  157. package/resources/v1/features.js +51 -0
  158. package/resources/v1/features.js.map +1 -0
  159. package/resources/v1/features.mjs +47 -0
  160. package/resources/v1/features.mjs.map +1 -0
  161. package/resources/v1/index.d.mts +10 -4
  162. package/resources/v1/index.d.mts.map +1 -1
  163. package/resources/v1/index.d.ts +10 -4
  164. package/resources/v1/index.d.ts.map +1 -1
  165. package/resources/v1/index.js +17 -5
  166. package/resources/v1/index.js.map +1 -1
  167. package/resources/v1/index.mjs +7 -1
  168. package/resources/v1/index.mjs.map +1 -1
  169. package/resources/v1/plans/entitlements.d.mts +747 -0
  170. package/resources/v1/plans/entitlements.d.mts.map +1 -0
  171. package/resources/v1/plans/entitlements.d.ts +747 -0
  172. package/resources/v1/plans/entitlements.d.ts.map +1 -0
  173. package/resources/v1/plans/entitlements.js +36 -0
  174. package/resources/v1/plans/entitlements.js.map +1 -0
  175. package/resources/v1/plans/entitlements.mjs +32 -0
  176. package/resources/v1/plans/entitlements.mjs.map +1 -0
  177. package/resources/v1/plans/index.d.mts +3 -0
  178. package/resources/v1/plans/index.d.mts.map +1 -0
  179. package/resources/v1/plans/index.d.ts +3 -0
  180. package/resources/v1/plans/index.d.ts.map +1 -0
  181. package/resources/v1/plans/index.js +9 -0
  182. package/resources/v1/plans/index.js.map +1 -0
  183. package/resources/v1/plans/index.mjs +4 -0
  184. package/resources/v1/plans/index.mjs.map +1 -0
  185. package/resources/v1/plans/plans.d.mts +973 -0
  186. package/resources/v1/plans/plans.d.mts.map +1 -0
  187. package/resources/v1/plans/plans.d.ts +973 -0
  188. package/resources/v1/plans/plans.d.ts.map +1 -0
  189. package/resources/v1/plans/plans.js +76 -0
  190. package/resources/v1/plans/plans.js.map +1 -0
  191. package/resources/v1/plans/plans.mjs +71 -0
  192. package/resources/v1/plans/plans.mjs.map +1 -0
  193. package/resources/v1/plans.d.mts +2 -0
  194. package/resources/v1/plans.d.mts.map +1 -0
  195. package/resources/v1/plans.d.ts +2 -0
  196. package/resources/v1/plans.d.ts.map +1 -0
  197. package/resources/v1/plans.js +6 -0
  198. package/resources/v1/plans.js.map +1 -0
  199. package/resources/v1/plans.mjs +3 -0
  200. package/resources/v1/plans.mjs.map +1 -0
  201. package/resources/v1/products.d.mts +332 -0
  202. package/resources/v1/products.d.mts.map +1 -0
  203. package/resources/v1/products.d.ts +332 -0
  204. package/resources/v1/products.d.ts.map +1 -0
  205. package/resources/v1/products.js +52 -0
  206. package/resources/v1/products.js.map +1 -0
  207. package/resources/v1/products.mjs +48 -0
  208. package/resources/v1/products.mjs.map +1 -0
  209. package/resources/v1/subscriptions/future-update.d.mts +12 -19
  210. package/resources/v1/subscriptions/future-update.d.mts.map +1 -1
  211. package/resources/v1/subscriptions/future-update.d.ts +12 -19
  212. package/resources/v1/subscriptions/future-update.d.ts.map +1 -1
  213. package/resources/v1/subscriptions/future-update.js +3 -2
  214. package/resources/v1/subscriptions/future-update.js.map +1 -1
  215. package/resources/v1/subscriptions/future-update.mjs +3 -2
  216. package/resources/v1/subscriptions/future-update.mjs.map +1 -1
  217. package/resources/v1/subscriptions/index.d.mts +4 -2
  218. package/resources/v1/subscriptions/index.d.mts.map +1 -1
  219. package/resources/v1/subscriptions/index.d.ts +4 -2
  220. package/resources/v1/subscriptions/index.d.ts.map +1 -1
  221. package/resources/v1/subscriptions/index.js +5 -1
  222. package/resources/v1/subscriptions/index.js.map +1 -1
  223. package/resources/v1/subscriptions/index.mjs +3 -1
  224. package/resources/v1/subscriptions/index.mjs.map +1 -1
  225. package/resources/v1/subscriptions/invoice.d.mts +34 -0
  226. package/resources/v1/subscriptions/invoice.d.mts.map +1 -0
  227. package/resources/v1/subscriptions/invoice.d.ts +34 -0
  228. package/resources/v1/subscriptions/invoice.d.ts.map +1 -0
  229. package/resources/v1/subscriptions/invoice.js +17 -0
  230. package/resources/v1/subscriptions/invoice.js.map +1 -0
  231. package/resources/v1/subscriptions/invoice.mjs +13 -0
  232. package/resources/v1/subscriptions/invoice.mjs.map +1 -0
  233. package/resources/v1/subscriptions/subscriptions.d.mts +1565 -518
  234. package/resources/v1/subscriptions/subscriptions.d.mts.map +1 -1
  235. package/resources/v1/subscriptions/subscriptions.d.ts +1565 -518
  236. package/resources/v1/subscriptions/subscriptions.d.ts.map +1 -1
  237. package/resources/v1/subscriptions/subscriptions.js +52 -12
  238. package/resources/v1/subscriptions/subscriptions.js.map +1 -1
  239. package/resources/v1/subscriptions/subscriptions.mjs +53 -13
  240. package/resources/v1/subscriptions/subscriptions.mjs.map +1 -1
  241. package/resources/v1/subscriptions/usage.d.mts +98 -0
  242. package/resources/v1/subscriptions/usage.d.mts.map +1 -0
  243. package/resources/v1/subscriptions/usage.d.ts +98 -0
  244. package/resources/v1/subscriptions/usage.d.ts.map +1 -0
  245. package/resources/v1/subscriptions/usage.js +24 -0
  246. package/resources/v1/subscriptions/usage.js.map +1 -0
  247. package/resources/v1/subscriptions/usage.mjs +20 -0
  248. package/resources/v1/subscriptions/usage.mjs.map +1 -0
  249. package/resources/v1/usage.d.mts +230 -0
  250. package/resources/v1/usage.d.mts.map +1 -0
  251. package/resources/v1/usage.d.ts +230 -0
  252. package/resources/v1/usage.d.ts.map +1 -0
  253. package/resources/v1/usage.js +24 -0
  254. package/resources/v1/usage.js.map +1 -0
  255. package/resources/v1/usage.mjs +20 -0
  256. package/resources/v1/usage.mjs.map +1 -0
  257. package/resources/v1/v1.d.mts +30 -149
  258. package/resources/v1/v1.d.mts.map +1 -1
  259. package/resources/v1/v1.d.ts +30 -149
  260. package/resources/v1/v1.d.ts.map +1 -1
  261. package/resources/v1/v1.js +24 -12
  262. package/resources/v1/v1.js.map +1 -1
  263. package/resources/v1/v1.mjs +24 -12
  264. package/resources/v1/v1.mjs.map +1 -1
  265. package/src/client.ts +33 -40
  266. package/src/core/pagination.ts +24 -18
  267. package/src/internal/parse.ts +6 -0
  268. package/src/internal/qs/LICENSE.md +13 -0
  269. package/src/internal/qs/README.md +3 -0
  270. package/src/internal/qs/formats.ts +10 -0
  271. package/src/internal/qs/index.ts +13 -0
  272. package/src/internal/qs/stringify.ts +385 -0
  273. package/src/internal/qs/types.ts +71 -0
  274. package/src/internal/qs/utils.ts +265 -0
  275. package/src/resources/index.ts +1 -7
  276. package/src/resources/v1/addons/addons.ts +3245 -0
  277. package/src/resources/v1/addons/entitlements.ts +976 -0
  278. package/src/resources/v1/addons/index.ts +26 -0
  279. package/src/resources/v1/addons.ts +3 -0
  280. package/src/resources/v1/coupons.ts +311 -436
  281. package/src/resources/v1/customers/customers.ts +334 -153
  282. package/src/resources/v1/customers/index.ts +17 -2
  283. package/src/resources/v1/customers/payment-method.ts +7 -2
  284. package/src/resources/v1/customers/promotional-entitlements.ts +669 -0
  285. package/src/resources/v1/events.ts +74 -0
  286. package/src/resources/v1/features.ts +571 -0
  287. package/src/resources/v1/index.ts +73 -15
  288. package/src/resources/v1/plans/entitlements.ts +968 -0
  289. package/src/resources/v1/plans/index.ts +24 -0
  290. package/src/resources/v1/plans/plans.ts +2032 -0
  291. package/src/resources/v1/plans.ts +3 -0
  292. package/src/resources/v1/products.ts +423 -0
  293. package/src/resources/v1/subscriptions/future-update.ts +12 -27
  294. package/src/resources/v1/subscriptions/index.ts +16 -11
  295. package/src/resources/v1/subscriptions/invoice.ts +42 -0
  296. package/src/resources/v1/subscriptions/subscriptions.ts +3341 -832
  297. package/src/resources/v1/subscriptions/usage.ts +126 -0
  298. package/src/resources/v1/usage.ts +284 -0
  299. package/src/resources/v1/v1.ts +174 -197
  300. package/src/version.ts +1 -1
  301. package/version.d.mts +1 -1
  302. package/version.d.mts.map +1 -1
  303. package/version.d.ts +1 -1
  304. package/version.d.ts.map +1 -1
  305. package/version.js +1 -1
  306. package/version.js.map +1 -1
  307. package/version.mjs +1 -1
  308. package/version.mjs.map +1 -1
  309. package/resources/v1/customers/usage.d.mts +0 -98
  310. package/resources/v1/customers/usage.d.mts.map +0 -1
  311. package/resources/v1/customers/usage.d.ts +0 -98
  312. package/resources/v1/customers/usage.d.ts.map +0 -1
  313. package/resources/v1/customers/usage.js +0 -20
  314. package/resources/v1/customers/usage.js.map +0 -1
  315. package/resources/v1/customers/usage.mjs +0 -16
  316. package/resources/v1/customers/usage.mjs.map +0 -1
  317. package/src/resources/v1/customers/usage.ts +0 -132
package/src/client.ts CHANGED
@@ -11,6 +11,7 @@ import type { APIResponseProps } from './internal/parse';
11
11
  import { getPlatformHeaders } from './internal/detect-platform';
12
12
  import * as Shims from './internal/shims';
13
13
  import * as Opts from './internal/request-options';
14
+ import * as qs from './internal/qs';
14
15
  import { VERSION } from './version';
15
16
  import * as Errors from './core/error';
16
17
  import * as Pagination from './core/pagination';
@@ -18,13 +19,7 @@ import { AbstractPage, type MyCursorIDPageParams, MyCursorIDPageResponse } from
18
19
  import * as Uploads from './core/uploads';
19
20
  import * as API from './resources/index';
20
21
  import { APIPromise } from './core/api-promise';
21
- import {
22
- V1,
23
- V1CreateEventParams,
24
- V1CreateEventResponse,
25
- V1CreateUsageParams,
26
- V1CreateUsageResponse,
27
- } from './resources/v1/v1';
22
+ import { V1 } from './resources/v1/v1';
28
23
  import { type Fetch } from './internal/builtin-types';
29
24
  import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
30
25
  import { FinalRequestOptions, RequestOptions } from './internal/request-options';
@@ -135,7 +130,7 @@ export class Stigg {
135
130
  * API Client for interfacing with the Stigg API.
136
131
  *
137
132
  * @param {string | undefined} [opts.apiKey=process.env['STIGG_API_KEY'] ?? undefined]
138
- * @param {string} [opts.baseURL=process.env['STIGG_BASE_URL'] ?? https://api.example.com] - Override the default base URL for the API.
133
+ * @param {string} [opts.baseURL=process.env['STIGG_BASE_URL'] ?? https://api.stigg.io] - Override the default base URL for the API.
139
134
  * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
140
135
  * @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
141
136
  * @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
@@ -157,7 +152,7 @@ export class Stigg {
157
152
  const options: ClientOptions = {
158
153
  apiKey,
159
154
  ...opts,
160
- baseURL: baseURL || `https://api.example.com`,
155
+ baseURL: baseURL || `https://api.stigg.io`,
161
156
  };
162
157
 
163
158
  this.baseURL = options.baseURL!;
@@ -203,7 +198,7 @@ export class Stigg {
203
198
  * Check whether the base URL is set to its default.
204
199
  */
205
200
  #baseURLOverridden(): boolean {
206
- return this.baseURL !== 'https://api.example.com';
201
+ return this.baseURL !== 'https://api.stigg.io';
207
202
  }
208
203
 
209
204
  protected defaultQuery(): Record<string, string | undefined> | undefined {
@@ -218,24 +213,8 @@ export class Stigg {
218
213
  return buildHeaders([{ 'X-API-KEY': this.apiKey }]);
219
214
  }
220
215
 
221
- /**
222
- * Basic re-implementation of `qs.stringify` for primitive types.
223
- */
224
216
  protected stringifyQuery(query: Record<string, unknown>): string {
225
- return Object.entries(query)
226
- .filter(([_, value]) => typeof value !== 'undefined')
227
- .map(([key, value]) => {
228
- if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
229
- return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
230
- }
231
- if (value === null) {
232
- return `${encodeURIComponent(key)}=`;
233
- }
234
- throw new Errors.StiggError(
235
- `Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
236
- );
237
- })
238
- .join('&');
217
+ return qs.stringify(query, { arrayFormat: 'comma' });
239
218
  }
240
219
 
241
220
  private getUserAgent(): string {
@@ -456,7 +435,7 @@ export class Stigg {
456
435
  loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
457
436
 
458
437
  const errText = await response.text().catch((err: any) => castToError(err).message);
459
- const errJSON = safeJSON(errText);
438
+ const errJSON = safeJSON(errText) as any;
460
439
  const errMessage = errJSON ? undefined : errText;
461
440
 
462
441
  loggerFor(this).debug(
@@ -493,9 +472,14 @@ export class Stigg {
493
472
  getAPIList<Item, PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>>(
494
473
  path: string,
495
474
  Page: new (...args: any[]) => PageClass,
496
- opts?: RequestOptions,
475
+ opts?: PromiseOrValue<RequestOptions>,
497
476
  ): Pagination.PagePromise<PageClass, Item> {
498
- return this.requestAPIList(Page, { method: 'get', path, ...opts });
477
+ return this.requestAPIList(
478
+ Page,
479
+ opts && 'then' in opts ?
480
+ opts.then((opts) => ({ method: 'get', path, ...opts }))
481
+ : { method: 'get', path, ...opts },
482
+ );
499
483
  }
500
484
 
501
485
  requestAPIList<
@@ -503,7 +487,7 @@ export class Stigg {
503
487
  PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>,
504
488
  >(
505
489
  Page: new (...args: ConstructorParameters<typeof Pagination.AbstractPage>) => PageClass,
506
- options: FinalRequestOptions,
490
+ options: PromiseOrValue<FinalRequestOptions>,
507
491
  ): Pagination.PagePromise<PageClass, Item> {
508
492
  const request = this.makeRequest(options, null, undefined);
509
493
  return new Pagination.PagePromise<PageClass, Item>(this as any as Stigg, request, Page);
@@ -516,9 +500,10 @@ export class Stigg {
516
500
  controller: AbortController,
517
501
  ): Promise<Response> {
518
502
  const { signal, method, ...options } = init || {};
519
- if (signal) signal.addEventListener('abort', () => controller.abort());
503
+ const abort = this._makeAbort(controller);
504
+ if (signal) signal.addEventListener('abort', abort, { once: true });
520
505
 
521
- const timeout = setTimeout(() => controller.abort(), ms);
506
+ const timeout = setTimeout(abort, ms);
522
507
 
523
508
  const isReadableBody =
524
509
  ((globalThis as any).ReadableStream && options.body instanceof (globalThis as any).ReadableStream) ||
@@ -685,6 +670,12 @@ export class Stigg {
685
670
  return headers.values;
686
671
  }
687
672
 
673
+ private _makeAbort(controller: AbortController) {
674
+ // note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
675
+ // would capture all request options, and cause a memory leak.
676
+ return () => controller.abort();
677
+ }
678
+
688
679
  private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {
689
680
  bodyHeaders: HeadersLike;
690
681
  body: BodyInit | undefined;
@@ -717,6 +708,14 @@ export class Stigg {
717
708
  (Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))
718
709
  ) {
719
710
  return { bodyHeaders: undefined, body: Shims.ReadableStreamFrom(body as AsyncIterable<Uint8Array>) };
711
+ } else if (
712
+ typeof body === 'object' &&
713
+ headers.values.get('content-type') === 'application/x-www-form-urlencoded'
714
+ ) {
715
+ return {
716
+ bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
717
+ body: this.stringifyQuery(body as Record<string, unknown>),
718
+ };
720
719
  } else {
721
720
  return this.#encoder({ body, headers });
722
721
  }
@@ -755,11 +754,5 @@ export declare namespace Stigg {
755
754
  type MyCursorIDPageResponse as MyCursorIDPageResponse,
756
755
  };
757
756
 
758
- export {
759
- V1 as V1,
760
- type V1CreateEventResponse as V1CreateEventResponse,
761
- type V1CreateUsageResponse as V1CreateUsageResponse,
762
- type V1CreateEventParams as V1CreateEventParams,
763
- type V1CreateUsageParams as V1CreateUsageParams,
764
- };
757
+ export { V1 as V1 };
765
758
  }
@@ -109,22 +109,31 @@ export class PagePromise<
109
109
 
110
110
  export interface MyCursorIDPageResponse<Item> {
111
111
  data: Array<Item>;
112
+
113
+ pagination: MyCursorIDPageResponse.Pagination;
114
+ }
115
+
116
+ export namespace MyCursorIDPageResponse {
117
+ export interface Pagination {
118
+ next?: string;
119
+
120
+ prev?: string;
121
+ }
112
122
  }
113
123
 
114
124
  export interface MyCursorIDPageParams {
115
- starting_after?: string;
125
+ after?: string;
116
126
 
117
- ending_before?: string;
127
+ before?: string;
118
128
 
119
129
  limit?: number;
120
130
  }
121
131
 
122
- export class MyCursorIDPage<Item extends { cursor_id: string }>
123
- extends AbstractPage<Item>
124
- implements MyCursorIDPageResponse<Item>
125
- {
132
+ export class MyCursorIDPage<Item> extends AbstractPage<Item> implements MyCursorIDPageResponse<Item> {
126
133
  data: Array<Item>;
127
134
 
135
+ pagination: MyCursorIDPageResponse.Pagination;
136
+
128
137
  constructor(
129
138
  client: Stigg,
130
139
  response: Response,
@@ -134,6 +143,7 @@ export class MyCursorIDPage<Item extends { cursor_id: string }>
134
143
  super(client, response, body, options);
135
144
 
136
145
  this.data = body.data || [];
146
+ this.pagination = body.pagination || {};
137
147
  }
138
148
 
139
149
  getPaginatedItems(): Item[] {
@@ -141,14 +151,10 @@ export class MyCursorIDPage<Item extends { cursor_id: string }>
141
151
  }
142
152
 
143
153
  nextPageRequestOptions(): PageRequestOptions | null {
144
- const data = this.getPaginatedItems();
145
-
146
- const isForwards = !(
147
- typeof this.options.query === 'object' && 'ending_before' in (this.options.query || {})
148
- );
149
- if (isForwards) {
150
- const cursorID = data[data.length - 1]?.cursor_id;
151
- if (!cursorID) {
154
+ if ((this.options.query as Record<string, unknown>)?.['before']) {
155
+ // in reverse
156
+ const prev = this.pagination?.prev;
157
+ if (!prev) {
152
158
  return null;
153
159
  }
154
160
 
@@ -156,13 +162,13 @@ export class MyCursorIDPage<Item extends { cursor_id: string }>
156
162
  ...this.options,
157
163
  query: {
158
164
  ...maybeObj(this.options.query),
159
- starting_after: cursorID,
165
+ before: prev,
160
166
  },
161
167
  };
162
168
  }
163
169
 
164
- const cursorID = data[0]?.cursor_id;
165
- if (!cursorID) {
170
+ const cursor = this.pagination?.next;
171
+ if (!cursor) {
166
172
  return null;
167
173
  }
168
174
 
@@ -170,7 +176,7 @@ export class MyCursorIDPage<Item extends { cursor_id: string }>
170
176
  ...this.options,
171
177
  query: {
172
178
  ...maybeObj(this.options.query),
173
- ending_before: cursorID,
179
+ after: cursor,
174
180
  },
175
181
  };
176
182
  }
@@ -29,6 +29,12 @@ export async function defaultParseResponse<T>(client: Stigg, props: APIResponseP
29
29
  const mediaType = contentType?.split(';')[0]?.trim();
30
30
  const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
31
31
  if (isJSON) {
32
+ const contentLength = response.headers.get('content-length');
33
+ if (contentLength === '0') {
34
+ // if there is no content we can't do anything
35
+ return undefined as T;
36
+ }
37
+
32
38
  const json = await response.json();
33
39
  return json as T;
34
40
  }
@@ -0,0 +1,13 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2014, Nathan LaFreniere and other [contributors](https://github.com/puruvj/neoqs/graphs/contributors) All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
+
9
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
10
+
11
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,3 @@
1
+ # qs
2
+
3
+ This is a vendored version of [neoqs](https://github.com/PuruVJ/neoqs) which is a TypeScript rewrite of [qs](https://github.com/ljharb/qs), a query string library.
@@ -0,0 +1,10 @@
1
+ import type { Format } from './types';
2
+
3
+ export const default_format: Format = 'RFC3986';
4
+ export const default_formatter = (v: PropertyKey) => String(v);
5
+ export const formatters: Record<Format, (str: PropertyKey) => string> = {
6
+ RFC1738: (v: PropertyKey) => String(v).replace(/%20/g, '+'),
7
+ RFC3986: default_formatter,
8
+ };
9
+ export const RFC1738 = 'RFC1738';
10
+ export const RFC3986 = 'RFC3986';
@@ -0,0 +1,13 @@
1
+ import { default_format, formatters, RFC1738, RFC3986 } from './formats';
2
+
3
+ const formats = {
4
+ formatters,
5
+ RFC1738,
6
+ RFC3986,
7
+ default: default_format,
8
+ };
9
+
10
+ export { stringify } from './stringify';
11
+ export { formats };
12
+
13
+ export type { DefaultDecoder, DefaultEncoder, Format, ParseOptions, StringifyOptions } from './types';