@polar-sh/sdk 1.0.2 → 1.0.3-alpha.3

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 (569) hide show
  1. package/dist/2026-04/index.cjs +4 -4
  2. package/dist/2026-04/index.d.cts +2 -2
  3. package/dist/2026-04/index.d.mts +2 -2
  4. package/dist/2026-04/index.mjs +3 -3
  5. package/dist/2026-04/services/benefit_grants.cjs +1 -1
  6. package/dist/2026-04/services/benefit_grants.d.cts +1 -1
  7. package/dist/2026-04/services/benefit_grants.d.mts +1 -1
  8. package/dist/2026-04/services/benefit_grants.mjs +1 -1
  9. package/dist/2026-04/services/benefits.cjs +1 -1
  10. package/dist/2026-04/services/benefits.d.cts +1 -1
  11. package/dist/2026-04/services/benefits.d.mts +1 -1
  12. package/dist/2026-04/services/benefits.mjs +1 -1
  13. package/dist/2026-04/services/checkout_links.cjs +1 -1
  14. package/dist/2026-04/services/checkout_links.d.cts +1 -1
  15. package/dist/2026-04/services/checkout_links.d.mts +1 -1
  16. package/dist/2026-04/services/checkout_links.mjs +1 -1
  17. package/dist/2026-04/services/checkouts.cjs +1 -1
  18. package/dist/2026-04/services/checkouts.d.cts +1 -1
  19. package/dist/2026-04/services/checkouts.d.mts +1 -1
  20. package/dist/2026-04/services/checkouts.mjs +1 -1
  21. package/dist/2026-04/services/custom_fields.cjs +1 -1
  22. package/dist/2026-04/services/custom_fields.d.cts +1 -1
  23. package/dist/2026-04/services/custom_fields.d.mts +1 -1
  24. package/dist/2026-04/services/custom_fields.mjs +1 -1
  25. package/dist/2026-04/services/customer_meters.cjs +1 -1
  26. package/dist/2026-04/services/customer_meters.d.cts +1 -1
  27. package/dist/2026-04/services/customer_meters.d.mts +1 -1
  28. package/dist/2026-04/services/customer_meters.mjs +1 -1
  29. package/dist/2026-04/services/customer_portal/benefit_grants.cjs +1 -1
  30. package/dist/2026-04/services/customer_portal/benefit_grants.d.cts +1 -1
  31. package/dist/2026-04/services/customer_portal/benefit_grants.d.mts +1 -1
  32. package/dist/2026-04/services/customer_portal/benefit_grants.mjs +1 -1
  33. package/dist/2026-04/services/customer_portal/customer_meters.cjs +1 -1
  34. package/dist/2026-04/services/customer_portal/customer_meters.d.cts +1 -1
  35. package/dist/2026-04/services/customer_portal/customer_meters.d.mts +1 -1
  36. package/dist/2026-04/services/customer_portal/customer_meters.mjs +1 -1
  37. package/dist/2026-04/services/customer_portal/customer_session.d.cts +1 -1
  38. package/dist/2026-04/services/customer_portal/customer_session.d.mts +1 -1
  39. package/dist/2026-04/services/customer_portal/customers.cjs +1 -1
  40. package/dist/2026-04/services/customer_portal/customers.d.cts +1 -1
  41. package/dist/2026-04/services/customer_portal/customers.d.mts +1 -1
  42. package/dist/2026-04/services/customer_portal/customers.mjs +1 -1
  43. package/dist/2026-04/services/customer_portal/downloadables.cjs +1 -1
  44. package/dist/2026-04/services/customer_portal/downloadables.d.cts +1 -1
  45. package/dist/2026-04/services/customer_portal/downloadables.d.mts +1 -1
  46. package/dist/2026-04/services/customer_portal/downloadables.mjs +1 -1
  47. package/dist/2026-04/services/customer_portal/index.d.cts +1 -1
  48. package/dist/2026-04/services/customer_portal/index.d.mts +1 -1
  49. package/dist/2026-04/services/customer_portal/license_keys.cjs +1 -1
  50. package/dist/2026-04/services/customer_portal/license_keys.d.cts +1 -1
  51. package/dist/2026-04/services/customer_portal/license_keys.d.mts +1 -1
  52. package/dist/2026-04/services/customer_portal/license_keys.mjs +1 -1
  53. package/dist/2026-04/services/customer_portal/members.cjs +1 -1
  54. package/dist/2026-04/services/customer_portal/members.d.cts +1 -1
  55. package/dist/2026-04/services/customer_portal/members.d.mts +1 -1
  56. package/dist/2026-04/services/customer_portal/members.mjs +1 -1
  57. package/dist/2026-04/services/customer_portal/orders.cjs +1 -1
  58. package/dist/2026-04/services/customer_portal/orders.d.cts +1 -1
  59. package/dist/2026-04/services/customer_portal/orders.d.mts +1 -1
  60. package/dist/2026-04/services/customer_portal/orders.mjs +1 -1
  61. package/dist/2026-04/services/customer_portal/organizations.cjs +1 -1
  62. package/dist/2026-04/services/customer_portal/organizations.d.cts +1 -1
  63. package/dist/2026-04/services/customer_portal/organizations.d.mts +1 -1
  64. package/dist/2026-04/services/customer_portal/organizations.mjs +1 -1
  65. package/dist/2026-04/services/customer_portal/seats.cjs +1 -1
  66. package/dist/2026-04/services/customer_portal/seats.d.cts +1 -1
  67. package/dist/2026-04/services/customer_portal/seats.d.mts +1 -1
  68. package/dist/2026-04/services/customer_portal/seats.mjs +1 -1
  69. package/dist/2026-04/services/customer_portal/subscriptions.cjs +1 -1
  70. package/dist/2026-04/services/customer_portal/subscriptions.d.cts +1 -1
  71. package/dist/2026-04/services/customer_portal/subscriptions.d.mts +1 -1
  72. package/dist/2026-04/services/customer_portal/subscriptions.mjs +1 -1
  73. package/dist/2026-04/services/customer_portal/wallets.cjs +1 -1
  74. package/dist/2026-04/services/customer_portal/wallets.d.cts +1 -1
  75. package/dist/2026-04/services/customer_portal/wallets.d.mts +1 -1
  76. package/dist/2026-04/services/customer_portal/wallets.mjs +1 -1
  77. package/dist/2026-04/services/customer_seats.cjs +1 -1
  78. package/dist/2026-04/services/customer_seats.d.cts +1 -1
  79. package/dist/2026-04/services/customer_seats.d.mts +1 -1
  80. package/dist/2026-04/services/customer_seats.mjs +1 -1
  81. package/dist/2026-04/services/customer_sessions.cjs +1 -1
  82. package/dist/2026-04/services/customer_sessions.d.cts +1 -1
  83. package/dist/2026-04/services/customer_sessions.d.mts +1 -1
  84. package/dist/2026-04/services/customer_sessions.mjs +1 -1
  85. package/dist/2026-04/services/customers/index.cjs +1 -1
  86. package/dist/2026-04/services/customers/index.d.cts +1 -1
  87. package/dist/2026-04/services/customers/index.d.mts +1 -1
  88. package/dist/2026-04/services/customers/index.mjs +1 -1
  89. package/dist/2026-04/services/customers/members.cjs +1 -1
  90. package/dist/2026-04/services/customers/members.d.cts +1 -1
  91. package/dist/2026-04/services/customers/members.d.mts +1 -1
  92. package/dist/2026-04/services/customers/members.mjs +1 -1
  93. package/dist/2026-04/services/discounts.cjs +1 -1
  94. package/dist/2026-04/services/discounts.d.cts +1 -1
  95. package/dist/2026-04/services/discounts.d.mts +1 -1
  96. package/dist/2026-04/services/discounts.mjs +1 -1
  97. package/dist/2026-04/services/disputes.cjs +1 -1
  98. package/dist/2026-04/services/disputes.d.cts +1 -1
  99. package/dist/2026-04/services/disputes.d.mts +1 -1
  100. package/dist/2026-04/services/disputes.mjs +1 -1
  101. package/dist/2026-04/services/event_types.cjs +1 -1
  102. package/dist/2026-04/services/event_types.d.cts +1 -1
  103. package/dist/2026-04/services/event_types.d.mts +1 -1
  104. package/dist/2026-04/services/event_types.mjs +1 -1
  105. package/dist/2026-04/services/events.cjs +1 -1
  106. package/dist/2026-04/services/events.d.cts +1 -1
  107. package/dist/2026-04/services/events.d.mts +1 -1
  108. package/dist/2026-04/services/events.mjs +1 -1
  109. package/dist/2026-04/services/files.cjs +1 -1
  110. package/dist/2026-04/services/files.d.cts +1 -1
  111. package/dist/2026-04/services/files.d.mts +1 -1
  112. package/dist/2026-04/services/files.mjs +1 -1
  113. package/dist/2026-04/services/license_keys.cjs +1 -1
  114. package/dist/2026-04/services/license_keys.d.cts +1 -1
  115. package/dist/2026-04/services/license_keys.d.mts +1 -1
  116. package/dist/2026-04/services/license_keys.mjs +1 -1
  117. package/dist/2026-04/services/meters.cjs +1 -1
  118. package/dist/2026-04/services/meters.d.cts +1 -1
  119. package/dist/2026-04/services/meters.d.mts +1 -1
  120. package/dist/2026-04/services/meters.mjs +1 -1
  121. package/dist/2026-04/services/metrics.cjs +1 -1
  122. package/dist/2026-04/services/metrics.d.cts +1 -1
  123. package/dist/2026-04/services/metrics.d.mts +1 -1
  124. package/dist/2026-04/services/metrics.mjs +1 -1
  125. package/dist/2026-04/services/oauth2/clients/index.d.cts +1 -1
  126. package/dist/2026-04/services/oauth2/clients/index.d.mts +1 -1
  127. package/dist/2026-04/services/oauth2/clients/oauth2.cjs +1 -1
  128. package/dist/2026-04/services/oauth2/clients/oauth2.d.cts +1 -1
  129. package/dist/2026-04/services/oauth2/clients/oauth2.d.mts +1 -1
  130. package/dist/2026-04/services/oauth2/clients/oauth2.mjs +1 -1
  131. package/dist/2026-04/services/oauth2/index.d.cts +1 -1
  132. package/dist/2026-04/services/oauth2/index.d.mts +1 -1
  133. package/dist/2026-04/services/orders.cjs +1 -1
  134. package/dist/2026-04/services/orders.d.cts +1 -1
  135. package/dist/2026-04/services/orders.d.mts +1 -1
  136. package/dist/2026-04/services/orders.mjs +1 -1
  137. package/dist/2026-04/services/organizations.cjs +1 -1
  138. package/dist/2026-04/services/organizations.d.cts +1 -1
  139. package/dist/2026-04/services/organizations.d.mts +1 -1
  140. package/dist/2026-04/services/organizations.mjs +1 -1
  141. package/dist/2026-04/services/payments.cjs +1 -1
  142. package/dist/2026-04/services/payments.d.cts +1 -1
  143. package/dist/2026-04/services/payments.d.mts +1 -1
  144. package/dist/2026-04/services/payments.mjs +1 -1
  145. package/dist/2026-04/services/products.cjs +1 -1
  146. package/dist/2026-04/services/products.d.cts +1 -1
  147. package/dist/2026-04/services/products.d.mts +1 -1
  148. package/dist/2026-04/services/products.mjs +1 -1
  149. package/dist/2026-04/services/refunds.cjs +1 -1
  150. package/dist/2026-04/services/refunds.d.cts +1 -1
  151. package/dist/2026-04/services/refunds.d.mts +1 -1
  152. package/dist/2026-04/services/refunds.mjs +1 -1
  153. package/dist/2026-04/services/subscriptions.cjs +1 -1
  154. package/dist/2026-04/services/subscriptions.d.cts +1 -1
  155. package/dist/2026-04/services/subscriptions.d.mts +1 -1
  156. package/dist/2026-04/services/subscriptions.mjs +1 -1
  157. package/dist/2026-04/services/webhooks.cjs +1 -1
  158. package/dist/2026-04/services/webhooks.d.cts +1 -1
  159. package/dist/2026-04/services/webhooks.d.mts +1 -1
  160. package/dist/2026-04/services/webhooks.mjs +1 -1
  161. package/dist/2026-10/index.cjs +4 -4
  162. package/dist/2026-10/index.cjs.map +1 -1
  163. package/dist/2026-10/index.d.cts +2 -2
  164. package/dist/2026-10/index.d.mts +2 -2
  165. package/dist/2026-10/index.mjs +3 -3
  166. package/dist/2026-10/index.mjs.map +1 -1
  167. package/dist/2026-10/services/benefit_grants.cjs +1 -1
  168. package/dist/2026-10/services/benefit_grants.d.cts +1 -1
  169. package/dist/2026-10/services/benefit_grants.d.mts +1 -1
  170. package/dist/2026-10/services/benefit_grants.mjs +1 -1
  171. package/dist/2026-10/services/benefits.cjs +1 -1
  172. package/dist/2026-10/services/benefits.d.cts +1 -1
  173. package/dist/2026-10/services/benefits.d.mts +1 -1
  174. package/dist/2026-10/services/benefits.mjs +1 -1
  175. package/dist/2026-10/services/checkout_links.cjs +1 -1
  176. package/dist/2026-10/services/checkout_links.d.cts +1 -1
  177. package/dist/2026-10/services/checkout_links.d.mts +1 -1
  178. package/dist/2026-10/services/checkout_links.mjs +1 -1
  179. package/dist/2026-10/services/checkouts.cjs +1 -1
  180. package/dist/2026-10/services/checkouts.d.cts +1 -1
  181. package/dist/2026-10/services/checkouts.d.mts +1 -1
  182. package/dist/2026-10/services/checkouts.mjs +1 -1
  183. package/dist/2026-10/services/custom_fields.cjs +1 -1
  184. package/dist/2026-10/services/custom_fields.d.cts +1 -1
  185. package/dist/2026-10/services/custom_fields.d.mts +1 -1
  186. package/dist/2026-10/services/custom_fields.mjs +1 -1
  187. package/dist/2026-10/services/customer_meters.cjs +1 -1
  188. package/dist/2026-10/services/customer_meters.d.cts +1 -1
  189. package/dist/2026-10/services/customer_meters.d.mts +1 -1
  190. package/dist/2026-10/services/customer_meters.mjs +1 -1
  191. package/dist/2026-10/services/customer_portal/benefit_grants.cjs +1 -1
  192. package/dist/2026-10/services/customer_portal/benefit_grants.d.cts +1 -1
  193. package/dist/2026-10/services/customer_portal/benefit_grants.d.mts +1 -1
  194. package/dist/2026-10/services/customer_portal/benefit_grants.mjs +1 -1
  195. package/dist/2026-10/services/customer_portal/customer_meters.cjs +1 -1
  196. package/dist/2026-10/services/customer_portal/customer_meters.d.cts +1 -1
  197. package/dist/2026-10/services/customer_portal/customer_meters.d.mts +1 -1
  198. package/dist/2026-10/services/customer_portal/customer_meters.mjs +1 -1
  199. package/dist/2026-10/services/customer_portal/customer_session.d.cts +1 -1
  200. package/dist/2026-10/services/customer_portal/customer_session.d.mts +1 -1
  201. package/dist/2026-10/services/customer_portal/customers.cjs +1 -1
  202. package/dist/2026-10/services/customer_portal/customers.d.cts +1 -1
  203. package/dist/2026-10/services/customer_portal/customers.d.mts +1 -1
  204. package/dist/2026-10/services/customer_portal/customers.mjs +1 -1
  205. package/dist/2026-10/services/customer_portal/downloadables.cjs +1 -1
  206. package/dist/2026-10/services/customer_portal/downloadables.d.cts +1 -1
  207. package/dist/2026-10/services/customer_portal/downloadables.d.mts +1 -1
  208. package/dist/2026-10/services/customer_portal/downloadables.mjs +1 -1
  209. package/dist/2026-10/services/customer_portal/index.d.cts +1 -1
  210. package/dist/2026-10/services/customer_portal/index.d.mts +1 -1
  211. package/dist/2026-10/services/customer_portal/license_keys.cjs +1 -1
  212. package/dist/2026-10/services/customer_portal/license_keys.d.cts +1 -1
  213. package/dist/2026-10/services/customer_portal/license_keys.d.mts +1 -1
  214. package/dist/2026-10/services/customer_portal/license_keys.mjs +1 -1
  215. package/dist/2026-10/services/customer_portal/members.cjs +1 -1
  216. package/dist/2026-10/services/customer_portal/members.d.cts +1 -1
  217. package/dist/2026-10/services/customer_portal/members.d.mts +1 -1
  218. package/dist/2026-10/services/customer_portal/members.mjs +1 -1
  219. package/dist/2026-10/services/customer_portal/orders.cjs +1 -1
  220. package/dist/2026-10/services/customer_portal/orders.d.cts +1 -1
  221. package/dist/2026-10/services/customer_portal/orders.d.mts +1 -1
  222. package/dist/2026-10/services/customer_portal/orders.mjs +1 -1
  223. package/dist/2026-10/services/customer_portal/organizations.cjs +1 -1
  224. package/dist/2026-10/services/customer_portal/organizations.d.cts +1 -1
  225. package/dist/2026-10/services/customer_portal/organizations.d.mts +1 -1
  226. package/dist/2026-10/services/customer_portal/organizations.mjs +1 -1
  227. package/dist/2026-10/services/customer_portal/seats.cjs +1 -1
  228. package/dist/2026-10/services/customer_portal/seats.d.cts +1 -1
  229. package/dist/2026-10/services/customer_portal/seats.d.mts +1 -1
  230. package/dist/2026-10/services/customer_portal/seats.mjs +1 -1
  231. package/dist/2026-10/services/customer_portal/subscriptions.cjs +1 -1
  232. package/dist/2026-10/services/customer_portal/subscriptions.d.cts +1 -1
  233. package/dist/2026-10/services/customer_portal/subscriptions.d.mts +1 -1
  234. package/dist/2026-10/services/customer_portal/subscriptions.mjs +1 -1
  235. package/dist/2026-10/services/customer_portal/wallets.cjs +1 -1
  236. package/dist/2026-10/services/customer_portal/wallets.d.cts +1 -1
  237. package/dist/2026-10/services/customer_portal/wallets.d.mts +1 -1
  238. package/dist/2026-10/services/customer_portal/wallets.mjs +1 -1
  239. package/dist/2026-10/services/customer_seats.cjs +1 -1
  240. package/dist/2026-10/services/customer_seats.d.cts +1 -1
  241. package/dist/2026-10/services/customer_seats.d.mts +1 -1
  242. package/dist/2026-10/services/customer_seats.mjs +1 -1
  243. package/dist/2026-10/services/customer_sessions.cjs +1 -1
  244. package/dist/2026-10/services/customer_sessions.d.cts +1 -1
  245. package/dist/2026-10/services/customer_sessions.d.mts +1 -1
  246. package/dist/2026-10/services/customer_sessions.mjs +1 -1
  247. package/dist/2026-10/services/customers/index.cjs +1 -1
  248. package/dist/2026-10/services/customers/index.d.cts +1 -1
  249. package/dist/2026-10/services/customers/index.d.mts +1 -1
  250. package/dist/2026-10/services/customers/index.mjs +1 -1
  251. package/dist/2026-10/services/customers/members.cjs +1 -1
  252. package/dist/2026-10/services/customers/members.d.cts +1 -1
  253. package/dist/2026-10/services/customers/members.d.mts +1 -1
  254. package/dist/2026-10/services/customers/members.mjs +1 -1
  255. package/dist/2026-10/services/discounts.cjs +1 -1
  256. package/dist/2026-10/services/discounts.d.cts +1 -1
  257. package/dist/2026-10/services/discounts.d.mts +1 -1
  258. package/dist/2026-10/services/discounts.mjs +1 -1
  259. package/dist/2026-10/services/disputes.cjs +1 -1
  260. package/dist/2026-10/services/disputes.d.cts +1 -1
  261. package/dist/2026-10/services/disputes.d.mts +1 -1
  262. package/dist/2026-10/services/disputes.mjs +1 -1
  263. package/dist/2026-10/services/event_types.cjs +1 -1
  264. package/dist/2026-10/services/event_types.d.cts +1 -1
  265. package/dist/2026-10/services/event_types.d.mts +1 -1
  266. package/dist/2026-10/services/event_types.mjs +1 -1
  267. package/dist/2026-10/services/events.cjs +1 -1
  268. package/dist/2026-10/services/events.d.cts +1 -1
  269. package/dist/2026-10/services/events.d.mts +1 -1
  270. package/dist/2026-10/services/events.mjs +1 -1
  271. package/dist/2026-10/services/files.cjs +1 -1
  272. package/dist/2026-10/services/files.d.cts +1 -1
  273. package/dist/2026-10/services/files.d.mts +1 -1
  274. package/dist/2026-10/services/files.mjs +1 -1
  275. package/dist/2026-10/services/license_keys.cjs +1 -1
  276. package/dist/2026-10/services/license_keys.d.cts +1 -1
  277. package/dist/2026-10/services/license_keys.d.mts +1 -1
  278. package/dist/2026-10/services/license_keys.mjs +1 -1
  279. package/dist/2026-10/services/meters.cjs +1 -1
  280. package/dist/2026-10/services/meters.d.cts +1 -1
  281. package/dist/2026-10/services/meters.d.mts +1 -1
  282. package/dist/2026-10/services/meters.mjs +1 -1
  283. package/dist/2026-10/services/metrics.cjs +1 -1
  284. package/dist/2026-10/services/metrics.d.cts +1 -1
  285. package/dist/2026-10/services/metrics.d.mts +1 -1
  286. package/dist/2026-10/services/metrics.mjs +1 -1
  287. package/dist/2026-10/services/oauth2/clients/index.d.cts +1 -1
  288. package/dist/2026-10/services/oauth2/clients/index.d.mts +1 -1
  289. package/dist/2026-10/services/oauth2/clients/oauth2.cjs +1 -1
  290. package/dist/2026-10/services/oauth2/clients/oauth2.d.cts +1 -1
  291. package/dist/2026-10/services/oauth2/clients/oauth2.d.mts +1 -1
  292. package/dist/2026-10/services/oauth2/clients/oauth2.mjs +1 -1
  293. package/dist/2026-10/services/oauth2/index.d.cts +1 -1
  294. package/dist/2026-10/services/oauth2/index.d.mts +1 -1
  295. package/dist/2026-10/services/orders.cjs +1 -1
  296. package/dist/2026-10/services/orders.d.cts +1 -1
  297. package/dist/2026-10/services/orders.d.mts +1 -1
  298. package/dist/2026-10/services/orders.mjs +1 -1
  299. package/dist/2026-10/services/organizations.cjs +1 -1
  300. package/dist/2026-10/services/organizations.d.cts +1 -1
  301. package/dist/2026-10/services/organizations.d.mts +1 -1
  302. package/dist/2026-10/services/organizations.mjs +1 -1
  303. package/dist/2026-10/services/payments.cjs +1 -1
  304. package/dist/2026-10/services/payments.d.cts +1 -1
  305. package/dist/2026-10/services/payments.d.mts +1 -1
  306. package/dist/2026-10/services/payments.mjs +1 -1
  307. package/dist/2026-10/services/products.cjs +1 -1
  308. package/dist/2026-10/services/products.d.cts +1 -1
  309. package/dist/2026-10/services/products.d.mts +1 -1
  310. package/dist/2026-10/services/products.mjs +1 -1
  311. package/dist/2026-10/services/refunds.cjs +1 -1
  312. package/dist/2026-10/services/refunds.d.cts +1 -1
  313. package/dist/2026-10/services/refunds.d.mts +1 -1
  314. package/dist/2026-10/services/refunds.mjs +1 -1
  315. package/dist/2026-10/services/subscriptions.cjs +1 -1
  316. package/dist/2026-10/services/subscriptions.d.cts +1 -1
  317. package/dist/2026-10/services/subscriptions.d.mts +1 -1
  318. package/dist/2026-10/services/subscriptions.mjs +1 -1
  319. package/dist/2026-10/services/webhooks.cjs +1 -1
  320. package/dist/2026-10/services/webhooks.d.cts +1 -1
  321. package/dist/2026-10/services/webhooks.d.mts +1 -1
  322. package/dist/2026-10/services/webhooks.mjs +1 -1
  323. package/dist/2027-01/index.cjs +4 -4
  324. package/dist/2027-01/index.cjs.map +1 -1
  325. package/dist/2027-01/index.d.cts +2 -2
  326. package/dist/2027-01/index.d.mts +2 -2
  327. package/dist/2027-01/index.mjs +3 -3
  328. package/dist/2027-01/index.mjs.map +1 -1
  329. package/dist/2027-01/services/benefit_grants.cjs +1 -1
  330. package/dist/2027-01/services/benefit_grants.d.cts +1 -1
  331. package/dist/2027-01/services/benefit_grants.d.mts +1 -1
  332. package/dist/2027-01/services/benefit_grants.mjs +1 -1
  333. package/dist/2027-01/services/benefits.cjs +2 -2
  334. package/dist/2027-01/services/benefits.cjs.map +1 -1
  335. package/dist/2027-01/services/benefits.d.cts +1 -1
  336. package/dist/2027-01/services/benefits.d.mts +1 -1
  337. package/dist/2027-01/services/benefits.mjs +2 -2
  338. package/dist/2027-01/services/benefits.mjs.map +1 -1
  339. package/dist/2027-01/services/checkout_links.cjs +1 -1
  340. package/dist/2027-01/services/checkout_links.d.cts +1 -1
  341. package/dist/2027-01/services/checkout_links.d.mts +1 -1
  342. package/dist/2027-01/services/checkout_links.mjs +1 -1
  343. package/dist/2027-01/services/checkouts.cjs +1 -1
  344. package/dist/2027-01/services/checkouts.d.cts +1 -1
  345. package/dist/2027-01/services/checkouts.d.mts +1 -1
  346. package/dist/2027-01/services/checkouts.mjs +1 -1
  347. package/dist/2027-01/services/custom_fields.cjs +1 -1
  348. package/dist/2027-01/services/custom_fields.d.cts +1 -1
  349. package/dist/2027-01/services/custom_fields.d.mts +1 -1
  350. package/dist/2027-01/services/custom_fields.mjs +1 -1
  351. package/dist/2027-01/services/customer_meters.cjs +32 -1
  352. package/dist/2027-01/services/customer_meters.cjs.map +1 -1
  353. package/dist/2027-01/services/customer_meters.d.cts +4 -2
  354. package/dist/2027-01/services/customer_meters.d.cts.map +1 -1
  355. package/dist/2027-01/services/customer_meters.d.mts +4 -2
  356. package/dist/2027-01/services/customer_meters.d.mts.map +1 -1
  357. package/dist/2027-01/services/customer_meters.mjs +32 -2
  358. package/dist/2027-01/services/customer_meters.mjs.map +1 -1
  359. package/dist/2027-01/services/customer_portal/benefit_grants.cjs +1 -1
  360. package/dist/2027-01/services/customer_portal/benefit_grants.d.cts +1 -1
  361. package/dist/2027-01/services/customer_portal/benefit_grants.d.mts +1 -1
  362. package/dist/2027-01/services/customer_portal/benefit_grants.mjs +1 -1
  363. package/dist/2027-01/services/customer_portal/customer_meters.cjs +1 -1
  364. package/dist/2027-01/services/customer_portal/customer_meters.d.cts +1 -1
  365. package/dist/2027-01/services/customer_portal/customer_meters.d.mts +1 -1
  366. package/dist/2027-01/services/customer_portal/customer_meters.mjs +1 -1
  367. package/dist/2027-01/services/customer_portal/customer_session.d.cts +1 -1
  368. package/dist/2027-01/services/customer_portal/customer_session.d.mts +1 -1
  369. package/dist/2027-01/services/customer_portal/customers.cjs +1 -1
  370. package/dist/2027-01/services/customer_portal/customers.d.cts +1 -1
  371. package/dist/2027-01/services/customer_portal/customers.d.mts +1 -1
  372. package/dist/2027-01/services/customer_portal/customers.mjs +1 -1
  373. package/dist/2027-01/services/customer_portal/downloadables.cjs +1 -1
  374. package/dist/2027-01/services/customer_portal/downloadables.d.cts +1 -1
  375. package/dist/2027-01/services/customer_portal/downloadables.d.mts +1 -1
  376. package/dist/2027-01/services/customer_portal/downloadables.mjs +1 -1
  377. package/dist/2027-01/services/customer_portal/index.d.cts +1 -1
  378. package/dist/2027-01/services/customer_portal/index.d.mts +1 -1
  379. package/dist/2027-01/services/customer_portal/license_keys.cjs +1 -1
  380. package/dist/2027-01/services/customer_portal/license_keys.d.cts +1 -1
  381. package/dist/2027-01/services/customer_portal/license_keys.d.mts +1 -1
  382. package/dist/2027-01/services/customer_portal/license_keys.mjs +1 -1
  383. package/dist/2027-01/services/customer_portal/members.cjs +1 -1
  384. package/dist/2027-01/services/customer_portal/members.d.cts +1 -1
  385. package/dist/2027-01/services/customer_portal/members.d.mts +1 -1
  386. package/dist/2027-01/services/customer_portal/members.mjs +1 -1
  387. package/dist/2027-01/services/customer_portal/orders.cjs +1 -1
  388. package/dist/2027-01/services/customer_portal/orders.d.cts +1 -1
  389. package/dist/2027-01/services/customer_portal/orders.d.mts +1 -1
  390. package/dist/2027-01/services/customer_portal/orders.mjs +1 -1
  391. package/dist/2027-01/services/customer_portal/organizations.cjs +1 -1
  392. package/dist/2027-01/services/customer_portal/organizations.d.cts +1 -1
  393. package/dist/2027-01/services/customer_portal/organizations.d.mts +1 -1
  394. package/dist/2027-01/services/customer_portal/organizations.mjs +1 -1
  395. package/dist/2027-01/services/customer_portal/seats.cjs +1 -1
  396. package/dist/2027-01/services/customer_portal/seats.d.cts +1 -1
  397. package/dist/2027-01/services/customer_portal/seats.d.mts +1 -1
  398. package/dist/2027-01/services/customer_portal/seats.mjs +1 -1
  399. package/dist/2027-01/services/customer_portal/subscriptions.cjs +1 -1
  400. package/dist/2027-01/services/customer_portal/subscriptions.d.cts +1 -1
  401. package/dist/2027-01/services/customer_portal/subscriptions.d.mts +1 -1
  402. package/dist/2027-01/services/customer_portal/subscriptions.mjs +1 -1
  403. package/dist/2027-01/services/customer_portal/wallets.cjs +1 -1
  404. package/dist/2027-01/services/customer_portal/wallets.d.cts +1 -1
  405. package/dist/2027-01/services/customer_portal/wallets.d.mts +1 -1
  406. package/dist/2027-01/services/customer_portal/wallets.mjs +1 -1
  407. package/dist/2027-01/services/customer_seats.cjs +11 -1
  408. package/dist/2027-01/services/customer_seats.cjs.map +1 -1
  409. package/dist/2027-01/services/customer_seats.d.cts +1 -1
  410. package/dist/2027-01/services/customer_seats.d.cts.map +1 -1
  411. package/dist/2027-01/services/customer_seats.d.mts +1 -1
  412. package/dist/2027-01/services/customer_seats.d.mts.map +1 -1
  413. package/dist/2027-01/services/customer_seats.mjs +11 -1
  414. package/dist/2027-01/services/customer_seats.mjs.map +1 -1
  415. package/dist/2027-01/services/customer_sessions.cjs +1 -1
  416. package/dist/2027-01/services/customer_sessions.d.cts +1 -1
  417. package/dist/2027-01/services/customer_sessions.d.mts +1 -1
  418. package/dist/2027-01/services/customer_sessions.mjs +1 -1
  419. package/dist/2027-01/services/customers/index.cjs +3 -1
  420. package/dist/2027-01/services/customers/index.cjs.map +1 -1
  421. package/dist/2027-01/services/customers/index.d.cts +1 -1
  422. package/dist/2027-01/services/customers/index.d.cts.map +1 -1
  423. package/dist/2027-01/services/customers/index.d.mts +1 -1
  424. package/dist/2027-01/services/customers/index.d.mts.map +1 -1
  425. package/dist/2027-01/services/customers/index.mjs +3 -1
  426. package/dist/2027-01/services/customers/index.mjs.map +1 -1
  427. package/dist/2027-01/services/customers/members.cjs +1 -1
  428. package/dist/2027-01/services/customers/members.d.cts +1 -1
  429. package/dist/2027-01/services/customers/members.d.mts +1 -1
  430. package/dist/2027-01/services/customers/members.mjs +1 -1
  431. package/dist/2027-01/services/discounts.cjs +2 -1
  432. package/dist/2027-01/services/discounts.cjs.map +1 -1
  433. package/dist/2027-01/services/discounts.d.cts +5 -1
  434. package/dist/2027-01/services/discounts.d.cts.map +1 -1
  435. package/dist/2027-01/services/discounts.d.mts +5 -1
  436. package/dist/2027-01/services/discounts.d.mts.map +1 -1
  437. package/dist/2027-01/services/discounts.mjs +2 -1
  438. package/dist/2027-01/services/discounts.mjs.map +1 -1
  439. package/dist/2027-01/services/disputes.cjs +1 -1
  440. package/dist/2027-01/services/disputes.d.cts +1 -1
  441. package/dist/2027-01/services/disputes.d.mts +1 -1
  442. package/dist/2027-01/services/disputes.mjs +1 -1
  443. package/dist/2027-01/services/event_types.cjs +1 -1
  444. package/dist/2027-01/services/event_types.d.cts +1 -1
  445. package/dist/2027-01/services/event_types.d.mts +1 -1
  446. package/dist/2027-01/services/event_types.mjs +1 -1
  447. package/dist/2027-01/services/events.cjs +1 -1
  448. package/dist/2027-01/services/events.d.cts +1 -1
  449. package/dist/2027-01/services/events.d.mts +1 -1
  450. package/dist/2027-01/services/events.mjs +1 -1
  451. package/dist/2027-01/services/files.cjs +1 -1
  452. package/dist/2027-01/services/files.d.cts +1 -1
  453. package/dist/2027-01/services/files.d.mts +1 -1
  454. package/dist/2027-01/services/files.mjs +1 -1
  455. package/dist/2027-01/services/license_keys.cjs +1 -1
  456. package/dist/2027-01/services/license_keys.d.cts +1 -1
  457. package/dist/2027-01/services/license_keys.d.mts +1 -1
  458. package/dist/2027-01/services/license_keys.mjs +1 -1
  459. package/dist/2027-01/services/meters.cjs +1 -1
  460. package/dist/2027-01/services/meters.d.cts +1 -1
  461. package/dist/2027-01/services/meters.d.mts +1 -1
  462. package/dist/2027-01/services/meters.mjs +1 -1
  463. package/dist/2027-01/services/metrics.cjs +1 -1
  464. package/dist/2027-01/services/metrics.d.cts +1 -1
  465. package/dist/2027-01/services/metrics.d.mts +1 -1
  466. package/dist/2027-01/services/metrics.mjs +1 -1
  467. package/dist/2027-01/services/oauth2/clients/index.d.cts +1 -1
  468. package/dist/2027-01/services/oauth2/clients/index.d.mts +1 -1
  469. package/dist/2027-01/services/oauth2/clients/oauth2.cjs +1 -1
  470. package/dist/2027-01/services/oauth2/clients/oauth2.d.cts +1 -1
  471. package/dist/2027-01/services/oauth2/clients/oauth2.d.mts +1 -1
  472. package/dist/2027-01/services/oauth2/clients/oauth2.mjs +1 -1
  473. package/dist/2027-01/services/oauth2/index.d.cts +1 -1
  474. package/dist/2027-01/services/oauth2/index.d.mts +1 -1
  475. package/dist/2027-01/services/orders.cjs +1 -1
  476. package/dist/2027-01/services/orders.d.cts +1 -1
  477. package/dist/2027-01/services/orders.d.mts +1 -1
  478. package/dist/2027-01/services/orders.mjs +1 -1
  479. package/dist/2027-01/services/organizations.cjs +1 -1
  480. package/dist/2027-01/services/organizations.d.cts +1 -1
  481. package/dist/2027-01/services/organizations.d.mts +1 -1
  482. package/dist/2027-01/services/organizations.mjs +1 -1
  483. package/dist/2027-01/services/payments.cjs +1 -1
  484. package/dist/2027-01/services/payments.d.cts +1 -1
  485. package/dist/2027-01/services/payments.d.mts +1 -1
  486. package/dist/2027-01/services/payments.mjs +1 -1
  487. package/dist/2027-01/services/products.cjs +1 -1
  488. package/dist/2027-01/services/products.d.cts +1 -1
  489. package/dist/2027-01/services/products.d.mts +1 -1
  490. package/dist/2027-01/services/products.mjs +1 -1
  491. package/dist/2027-01/services/refunds.cjs +1 -1
  492. package/dist/2027-01/services/refunds.d.cts +1 -1
  493. package/dist/2027-01/services/refunds.d.mts +1 -1
  494. package/dist/2027-01/services/refunds.mjs +1 -1
  495. package/dist/2027-01/services/subscriptions.cjs +1 -1
  496. package/dist/2027-01/services/subscriptions.d.cts +1 -1
  497. package/dist/2027-01/services/subscriptions.d.mts +1 -1
  498. package/dist/2027-01/services/subscriptions.mjs +1 -1
  499. package/dist/2027-01/services/webhooks.cjs +1 -1
  500. package/dist/2027-01/services/webhooks.d.cts +1 -1
  501. package/dist/2027-01/services/webhooks.d.mts +1 -1
  502. package/dist/2027-01/services/webhooks.mjs +1 -1
  503. package/dist/{base-elZHdyac.cjs → base-DHy1aJ70.cjs} +5 -2
  504. package/dist/{base-Cir88A-B.mjs.map → base-DHy1aJ70.cjs.map} +1 -1
  505. package/dist/{base-Cir88A-B.mjs → base-jGd8URjq.mjs} +5 -2
  506. package/dist/{base-elZHdyac.cjs.map → base-jGd8URjq.mjs.map} +1 -1
  507. package/dist/{errors-BNX4S5mh.cjs → errors-B-sbvXah.cjs} +23 -3
  508. package/dist/errors-B-sbvXah.cjs.map +1 -0
  509. package/dist/{errors-CU3SpW0J.mjs → errors-B3PVjuYS.mjs} +2 -2
  510. package/dist/{errors-CU3SpW0J.mjs.map → errors-B3PVjuYS.mjs.map} +1 -1
  511. package/dist/{errors-CpcxXUUY.cjs → errors-BHJtI-Az.cjs} +3 -3
  512. package/dist/{errors-CpcxXUUY.cjs.map → errors-BHJtI-Az.cjs.map} +1 -1
  513. package/dist/{errors-D48S0nru.cjs → errors-CzBzBuG7.cjs} +3 -3
  514. package/dist/{errors-D48S0nru.cjs.map → errors-CzBzBuG7.cjs.map} +1 -1
  515. package/dist/{errors-DeSE0QDX.mjs → errors-TTexeU-I.mjs} +17 -3
  516. package/dist/errors-TTexeU-I.mjs.map +1 -0
  517. package/dist/{errors-CmQk48Hf.mjs → errors-v8-ROkLl.mjs} +2 -2
  518. package/dist/{errors-CmQk48Hf.mjs.map → errors-v8-ROkLl.mjs.map} +1 -1
  519. package/dist/{index-DW6QhN4v.d.mts → index-4QvmyIfk.d.mts} +14 -3
  520. package/dist/index-4QvmyIfk.d.mts.map +1 -0
  521. package/dist/{index-fmn-6v-G.d.cts → index-BsjbzbzQ.d.cts} +2 -2
  522. package/dist/index-BsjbzbzQ.d.cts.map +1 -0
  523. package/dist/{index-NMXOM5dy.d.cts → index-CdOi2TtF.d.cts} +2 -2
  524. package/dist/{index-NMXOM5dy.d.cts.map → index-CdOi2TtF.d.cts.map} +1 -1
  525. package/dist/{index-BAjXT-W8.d.cts → index-ClJvTviw.d.cts} +14 -3
  526. package/dist/index-ClJvTviw.d.cts.map +1 -0
  527. package/dist/{index-CZh-OhWh.d.mts → index-Dsoc8aUZ.d.mts} +2 -2
  528. package/dist/index-Dsoc8aUZ.d.mts.map +1 -0
  529. package/dist/{index-CgqeU9bV.d.mts → index-aTh5rKU2.d.mts} +2 -2
  530. package/dist/{index-CgqeU9bV.d.mts.map → index-aTh5rKU2.d.mts.map} +1 -1
  531. package/dist/index.cjs +1 -1
  532. package/dist/index.mjs +1 -2
  533. package/dist/{models-MQGPXSzo.d.cts → models-DEZDKjvs.d.cts} +2 -2
  534. package/dist/{models-MQGPXSzo.d.cts.map → models-DEZDKjvs.d.cts.map} +1 -1
  535. package/dist/{models-MQGPXSzo.d.mts → models-DEZDKjvs.d.mts} +2 -2
  536. package/dist/{models-MQGPXSzo.d.mts.map → models-DEZDKjvs.d.mts.map} +1 -1
  537. package/dist/models-DqFvgD36.d.cts +22224 -0
  538. package/dist/models-DqFvgD36.d.cts.map +1 -0
  539. package/dist/models-DqFvgD36.d.mts +22224 -0
  540. package/dist/models-DqFvgD36.d.mts.map +1 -0
  541. package/dist/{models-P8aaHkKR.d.cts → models-ZHvf-GL5.d.cts} +12 -12
  542. package/dist/{models-P8aaHkKR.d.cts.map → models-ZHvf-GL5.d.cts.map} +1 -1
  543. package/dist/{models-P8aaHkKR.d.mts → models-ZHvf-GL5.d.mts} +12 -12
  544. package/dist/{models-P8aaHkKR.d.mts.map → models-ZHvf-GL5.d.mts.map} +1 -1
  545. package/dist/outpost/index.cjs +587 -0
  546. package/dist/outpost/index.cjs.map +1 -0
  547. package/dist/outpost/index.d.cts +114 -0
  548. package/dist/outpost/index.d.cts.map +1 -0
  549. package/dist/outpost/index.d.mts +114 -0
  550. package/dist/outpost/index.d.mts.map +1 -0
  551. package/dist/outpost/index.mjs +581 -0
  552. package/dist/outpost/index.mjs.map +1 -0
  553. package/dist/rolldown-runtime-C0BPl7ul.cjs +43 -0
  554. package/dist/{webhooks-DHKM6i1k.mjs → webhooks-DZ_9hr_d.mjs} +2 -2
  555. package/dist/{webhooks-DHKM6i1k.mjs.map → webhooks-DZ_9hr_d.mjs.map} +1 -1
  556. package/dist/{webhooks-Da8LWSE5.cjs → webhooks-iwHkVmKt.cjs} +2 -2
  557. package/dist/{webhooks-Da8LWSE5.cjs.map → webhooks-iwHkVmKt.cjs.map} +1 -1
  558. package/package.json +31 -5
  559. package/dist/errors-BNX4S5mh.cjs.map +0 -1
  560. package/dist/errors-DeSE0QDX.mjs.map +0 -1
  561. package/dist/index-BAjXT-W8.d.cts.map +0 -1
  562. package/dist/index-CZh-OhWh.d.mts.map +0 -1
  563. package/dist/index-DW6QhN4v.d.mts.map +0 -1
  564. package/dist/index-fmn-6v-G.d.cts.map +0 -1
  565. package/dist/models-D1RXR1_Z.d.cts +0 -22148
  566. package/dist/models-D1RXR1_Z.d.cts.map +0 -1
  567. package/dist/models-D1RXR1_Z.d.mts +0 -22148
  568. package/dist/models-D1RXR1_Z.d.mts.map +0 -1
  569. package/dist/rolldown-runtime-ak5kbic3.cjs +0 -18
@@ -0,0 +1,587 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_rolldown_runtime = require("../rolldown-runtime-C0BPl7ul.cjs");
3
+ const require_base = require("../base-DHy1aJ70.cjs");
4
+ let ioredis = require("ioredis");
5
+ let node_crypto = require("node:crypto");
6
+ let node_events = require("node:events");
7
+ let ws = require("ws");
8
+ ws = require_rolldown_runtime.__toESM(ws, 1);
9
+ //#region src/outpost/event.ts
10
+ const customerKey = (input) => {
11
+ if (input.customer_id === void 0 === (input.external_customer_id === void 0)) throw new TypeError("Provide exactly one customer_id or external_customer_id");
12
+ const identifier = input.customer_id ?? input.external_customer_id;
13
+ return `${input.customer_id !== void 0 ? "customer" : "external"}:${identifier}`;
14
+ };
15
+ const parseEvent = (input) => {
16
+ if (input.timestamp !== void 0 && !/(Z|[+-]\d{2}:?\d{2})$/i.test(input.timestamp)) throw new TypeError("Event timestamps must include a timezone");
17
+ const timestamp = input.timestamp === void 0 ? Date.now() : Date.parse(input.timestamp);
18
+ const fraction = input.timestamp?.match(/\.(\d+)/)?.[1] ?? "";
19
+ const microseconds = timestamp * 1e3 + Number(fraction.padEnd(6, "0").slice(3, 6));
20
+ if (!Number.isSafeInteger(microseconds)) throw new TypeError("Invalid event timestamp");
21
+ return {
22
+ name: input.name,
23
+ customer: customerKey(input),
24
+ timestamp: microseconds,
25
+ metadata: input.metadata ?? {}
26
+ };
27
+ };
28
+ const getProperty = (event, property) => {
29
+ if (property === "name") return event.name;
30
+ if (property === "source") return "user";
31
+ if (property === "timestamp") return Math.trunc(event.timestamp / 1e6);
32
+ let value = event.metadata;
33
+ for (const part of property.replace(/^metadata\./, "").split(".")) {
34
+ if (value === null || typeof value !== "object" || Array.isArray(value) || !Object.hasOwn(value, part)) return void 0;
35
+ value = value[part];
36
+ }
37
+ return value;
38
+ };
39
+ //#endregion
40
+ //#region src/outpost/reducer.ts
41
+ const emptyStatistics = () => ({
42
+ count: 0,
43
+ sum: 0,
44
+ min: null,
45
+ max: null
46
+ });
47
+ const addStatistics = (target, other) => {
48
+ const total = target.sum + other.sum;
49
+ if (!Number.isFinite(total)) throw new TypeError("Aggregation values must be finite");
50
+ target.count += other.count;
51
+ target.sum = total;
52
+ if (other.min !== null) target.min = target.min === null ? other.min : Math.min(target.min, other.min);
53
+ if (other.max !== null) target.max = target.max === null ? other.max : Math.max(target.max, other.max);
54
+ };
55
+ const quantity = (statistics, func) => {
56
+ switch (func) {
57
+ case "count": return statistics.count;
58
+ case "sum": return statistics.sum;
59
+ case "min": return statistics.min ?? 0;
60
+ case "max": return statistics.max ?? 0;
61
+ case "avg": return statistics.count ? statistics.sum / statistics.count : 0;
62
+ }
63
+ };
64
+ const BUCKET_SIZE = 3e8;
65
+ const getBucketStart = (timestamp) => {
66
+ if (!Number.isSafeInteger(timestamp)) throw new TypeError("Invalid bucket timestamp");
67
+ return Math.floor(timestamp / BUCKET_SIZE) * BUCKET_SIZE;
68
+ };
69
+ const getMatcher = (filter) => {
70
+ if (!("property" in filter)) {
71
+ const children = filter.clauses.map(getMatcher);
72
+ return filter.conjunction === "and" ? (event) => children.every((match) => match(event)) : (event) => children.some((match) => match(event));
73
+ }
74
+ return (event) => {
75
+ const actual = getProperty(event, filter.property);
76
+ if (actual === void 0 || actual === null) return false;
77
+ if (filter.operator === "eq" || filter.operator === "ne") {
78
+ const actualValue = typeof actual === "boolean" ? Number(actual) : actual;
79
+ const expectedValue = typeof filter.value === "boolean" ? Number(filter.value) : filter.value;
80
+ return filter.operator === "eq" ? actualValue === expectedValue : actualValue !== expectedValue;
81
+ }
82
+ if (typeof actual !== typeof filter.value) return false;
83
+ if (typeof actual !== "number" && typeof actual !== "string" || typeof filter.value !== "number" && typeof filter.value !== "string") return false;
84
+ switch (filter.operator) {
85
+ case "gt": return actual > filter.value;
86
+ case "gte": return actual >= filter.value;
87
+ case "lt": return actual < filter.value;
88
+ case "lte": return actual <= filter.value;
89
+ }
90
+ };
91
+ };
92
+ const reduce = (reducers, events, oldestBucketStart) => {
93
+ const updates = /* @__PURE__ */ new Map();
94
+ const matchers = reducers.map((reducer) => [reducer, getMatcher(reducer.filter)]);
95
+ for (const event of events) {
96
+ const bucketStart = getBucketStart(event.timestamp);
97
+ if (bucketStart < oldestBucketStart) continue;
98
+ for (const [reducer, match] of matchers) {
99
+ if (!match(event)) continue;
100
+ const { aggregation } = reducer;
101
+ const value = aggregation.func === "count" ? 1 : getProperty(event, aggregation.property);
102
+ if (typeof value !== "number") continue;
103
+ if (!Number.isFinite(value)) throw new TypeError("Aggregation values must be finite");
104
+ const key = JSON.stringify([
105
+ event.customer,
106
+ reducer.id,
107
+ bucketStart
108
+ ]);
109
+ let update = updates.get(key);
110
+ if (!update) {
111
+ update = {
112
+ customer: event.customer,
113
+ reducer: reducer.id,
114
+ bucketStart,
115
+ statistics: emptyStatistics()
116
+ };
117
+ updates.set(key, update);
118
+ }
119
+ addStatistics(update.statistics, aggregation.func === "count" ? {
120
+ count: 1,
121
+ sum: 0,
122
+ min: null,
123
+ max: null
124
+ } : {
125
+ count: 1,
126
+ sum: value,
127
+ min: value,
128
+ max: value
129
+ });
130
+ }
131
+ }
132
+ return [...updates.values()];
133
+ };
134
+ //#endregion
135
+ //#region src/outpost/scripts.ts
136
+ const READ_STATE_SCRIPT = `
137
+ if not redis.call('HGET', KEYS[1], 'epoch') then
138
+ redis.call('HSET', KEYS[1], 'epoch', ARGV[1], 'revision', '0')
139
+ end
140
+ return redis.call('HGETALL', KEYS[1])
141
+ `;
142
+ const WRITE_BUCKET_SCRIPT = `
143
+ local cutoff = redis.call('HGET', KEYS[1], 'cold_until')
144
+ if cutoff and tonumber(ARGV[4]) < tonumber(cutoff) then
145
+ return redis.call('HGETALL', KEYS[1])
146
+ end
147
+ local prefix = 'bucket:' .. ARGV[4] .. ':'
148
+ local total = tonumber(redis.call('HGET', KEYS[1], prefix .. 'sum') or '0') + tonumber(ARGV[6])
149
+ assert(total == total and math.abs(total) ~= math.huge, 'Aggregation values must be finite')
150
+ redis.call('HINCRBYFLOAT', KEYS[1], prefix .. 'sum', ARGV[6])
151
+ redis.call('HINCRBY', KEYS[1], prefix .. 'count', ARGV[5])
152
+ for i, func in ipairs({'min', 'max'}) do
153
+ local raw = ARGV[6 + i]
154
+ if raw ~= '' then
155
+ local value = tonumber(raw)
156
+ assert(value and value == value and math.abs(value) ~= math.huge, 'Invalid value')
157
+ local stored = redis.call('HGET', KEYS[1], prefix .. func)
158
+ local previous = stored and tonumber(stored)
159
+ if not previous or (func == 'min' and value < previous)
160
+ or (func == 'max' and value > previous) then
161
+ redis.call('HSET', KEYS[1], prefix .. func, raw)
162
+ end
163
+ end
164
+ end
165
+
166
+ if not redis.call('HGET', KEYS[1], 'epoch') then
167
+ redis.call('HSET', KEYS[1], 'epoch', ARGV[3], 'revision', '0')
168
+ end
169
+ redis.call('HINCRBY', KEYS[1], 'revision', 1)
170
+ local state = redis.call('HGETALL', KEYS[1])
171
+ redis.call('PUBLISH', ARGV[2], cjson.encode({customer = ARGV[1], state = state}))
172
+ return state
173
+ `;
174
+ const APPLY_SNAPSHOT_SCRIPT = `
175
+ local cutoff = tonumber(ARGV[4])
176
+ local current = redis.call('HGET', KEYS[1], 'cold_until')
177
+ if current and tonumber(current) > cutoff then
178
+ return redis.call('HGETALL', KEYS[1])
179
+ end
180
+ local version = tonumber(ARGV[5])
181
+ local previous = redis.call('HGET', KEYS[1], 'snapshot_version')
182
+ if not previous or version >= tonumber(previous) then
183
+ for _, field in ipairs(redis.call('HKEYS', KEYS[1])) do
184
+ if string.sub(field, 1, 5) == 'cold:'
185
+ or (string.sub(field, 1, 7) == 'bucket:'
186
+ and tonumber(string.match(field, '^bucket:(%-?%d+):')) < cutoff) then
187
+ redis.call('HDEL', KEYS[1], field)
188
+ end
189
+ end
190
+ redis.call('HSET', KEYS[1], 'cold_until', ARGV[4], 'snapshot_version', ARGV[5],
191
+ 'cold:count', ARGV[8], 'cold:sum', ARGV[9])
192
+ if ARGV[10] ~= '' then redis.call('HSET', KEYS[1], 'cold:min', ARGV[10]) end
193
+ if ARGV[11] ~= '' then redis.call('HSET', KEYS[1], 'cold:max', ARGV[11]) end
194
+ end
195
+ local credit_version = redis.call('HGET', KEYS[1], 'credited_version:' .. ARGV[6])
196
+ if not credit_version or version >= tonumber(credit_version) then
197
+ redis.call('HSET', KEYS[1], 'credited:' .. ARGV[6], ARGV[7],
198
+ 'credited_version:' .. ARGV[6], ARGV[5])
199
+ end
200
+
201
+ if not redis.call('HGET', KEYS[1], 'epoch') then
202
+ redis.call('HSET', KEYS[1], 'epoch', ARGV[3], 'revision', '0')
203
+ end
204
+ redis.call('HINCRBY', KEYS[1], 'revision', 1)
205
+ local state = redis.call('HGETALL', KEYS[1])
206
+ redis.call('PUBLISH', ARGV[2], cjson.encode({customer = ARGV[1], state = state}))
207
+ return state
208
+ `;
209
+ //#endregion
210
+ //#region src/outpost/client.ts
211
+ const CACHE_SIZE = 1024;
212
+ const SYNC_INTERVAL = 3e4;
213
+ const TIMEOUT = 5e3;
214
+ const generateEpoch = () => (0, node_crypto.randomUUID)().replaceAll("-", "");
215
+ const number = (value) => {
216
+ const parsed = JSON.parse(value);
217
+ if (!Number.isFinite(parsed)) throw new TypeError("Stored aggregation values must be finite numbers");
218
+ return parsed;
219
+ };
220
+ const signal = () => {
221
+ let resolve;
222
+ return {
223
+ promise: new Promise((done) => {
224
+ resolve = done;
225
+ }),
226
+ resolve
227
+ };
228
+ };
229
+ const withTimeout = async (promise) => {
230
+ let timer;
231
+ try {
232
+ return await Promise.race([promise, new Promise((_, reject) => {
233
+ timer = setTimeout(() => reject(new require_base.PolarError("Outpost operation timed out")), TIMEOUT);
234
+ })]);
235
+ } finally {
236
+ clearTimeout(timer);
237
+ }
238
+ };
239
+ const locked = (local, action) => {
240
+ const result = local.pending.then(action);
241
+ local.pending = result.catch(() => {});
242
+ return result;
243
+ };
244
+ const decodeState = (value) => {
245
+ const fields = {};
246
+ for (let i = 0; i < value.length; i += 2) fields[value[i]] = value[i + 1];
247
+ const state = {
248
+ epoch: fields.epoch,
249
+ revision: BigInt(fields.revision),
250
+ coldUntil: fields.cold_until === void 0 ? void 0 : number(fields.cold_until),
251
+ cold: emptyStatistics(),
252
+ buckets: /* @__PURE__ */ new Map(),
253
+ credited: {}
254
+ };
255
+ for (const [field, value] of Object.entries(fields)) if (field.startsWith("cold:")) {
256
+ const statistic = field.slice(5);
257
+ state.cold[statistic] = number(value);
258
+ } else if (field.startsWith("bucket:")) {
259
+ const [, timestamp, statistic] = field.split(":");
260
+ const start = Number(timestamp);
261
+ const bucket = state.buckets.get(start) ?? emptyStatistics();
262
+ bucket[statistic] = number(value);
263
+ state.buckets.set(start, bucket);
264
+ } else if (field.startsWith("credited:")) state.credited[field.slice(9)] = number(value);
265
+ return state;
266
+ };
267
+ const customerArguments = (customer) => {
268
+ const separator = customer.indexOf(":");
269
+ return { [customer.startsWith("customer:") ? "customer_id" : "external_customer_id"]: customer.slice(separator + 1) };
270
+ };
271
+ var Outpost = class {
272
+ redisUrl;
273
+ options;
274
+ redis;
275
+ subscriber;
276
+ websocket;
277
+ reducers = [];
278
+ cache = /* @__PURE__ */ new Map();
279
+ actors = /* @__PURE__ */ new Set();
280
+ configured = signal();
281
+ synced = signal();
282
+ isSynced = false;
283
+ generation = 0;
284
+ channel = "";
285
+ refreshTimer;
286
+ failure;
287
+ messages = Promise.resolve();
288
+ synchronizing;
289
+ constructor(redisUrl, options) {
290
+ this.redisUrl = redisUrl;
291
+ this.options = options;
292
+ }
293
+ async start() {
294
+ if (this.redis) throw new require_base.PolarError("Outpost is already connected");
295
+ this.failure = void 0;
296
+ this.configured = signal();
297
+ this.synced = signal();
298
+ this.messages = Promise.resolve();
299
+ try {
300
+ this.redis = new ioredis.Redis(this.redisUrl, {
301
+ lazyConnect: true,
302
+ enableOfflineQueue: false,
303
+ autoResendUnfulfilledCommands: false,
304
+ maxRetriesPerRequest: 0,
305
+ commandTimeout: TIMEOUT
306
+ });
307
+ this.redis.defineCommand("outpostReadState", {
308
+ numberOfKeys: 1,
309
+ lua: READ_STATE_SCRIPT
310
+ });
311
+ this.redis.defineCommand("outpostWriteBucket", {
312
+ numberOfKeys: 1,
313
+ lua: WRITE_BUCKET_SCRIPT
314
+ });
315
+ this.redis.defineCommand("outpostApplySnapshot", {
316
+ numberOfKeys: 1,
317
+ lua: APPLY_SNAPSHOT_SCRIPT
318
+ });
319
+ const redis = this.redis;
320
+ this.redis.on("error", () => {});
321
+ this.redis.on("close", () => {
322
+ if (this.redis === redis) this.invalidate();
323
+ });
324
+ this.redis.on("ready", () => {
325
+ if (this.subscriber?.status === "ready") this.synchronize();
326
+ });
327
+ await withTimeout(this.redis.connect());
328
+ await this.redis.ping();
329
+ this.channel = `outpost:${this.redis.options.db}:updates`;
330
+ this.subscriber = this.redis.duplicate({
331
+ lazyConnect: true,
332
+ autoResubscribe: false
333
+ });
334
+ const subscriber = this.subscriber;
335
+ this.subscriber.on("error", () => {});
336
+ this.subscriber.on("close", () => {
337
+ if (this.subscriber === subscriber) this.invalidate();
338
+ });
339
+ this.subscriber.on("ready", () => {
340
+ this.synchronize();
341
+ });
342
+ this.subscriber.on("message", (_channel, data) => {
343
+ this.receiveRedis(data).catch((error) => this.fail(error));
344
+ });
345
+ await withTimeout(this.subscriber.connect());
346
+ await withTimeout(this.synced.promise);
347
+ const [url, request] = this.options.client.buildRequest("GET", "/v1/outpost/");
348
+ const endpoint = new URL(url);
349
+ endpoint.protocol = endpoint.protocol === "https:" ? "wss:" : "ws:";
350
+ this.websocket = new ws.default(endpoint, {
351
+ headers: Object.fromEntries(new Headers(request.headers)),
352
+ handshakeTimeout: TIMEOUT
353
+ });
354
+ this.websocket.on("error", (error) => this.fail(error));
355
+ this.websocket.on("close", () => {
356
+ if (this.websocket) this.fail(new require_base.PolarError("Outpost WebSocket disconnected"));
357
+ });
358
+ this.websocket.on("message", (data) => {
359
+ this.messages = this.messages.then(() => this.receiveWebsocket(data.toString())).catch((error) => this.fail(error));
360
+ });
361
+ await withTimeout((0, node_events.once)(this.websocket, "open"));
362
+ await this.send({ type: "configuration" });
363
+ this.refreshTimer = setInterval(() => {
364
+ if (this.synchronizing) return;
365
+ this.synchronize();
366
+ }, SYNC_INTERVAL);
367
+ this.requireRedis();
368
+ return this;
369
+ } catch (error) {
370
+ await this.close();
371
+ throw error;
372
+ }
373
+ }
374
+ async close() {
375
+ clearInterval(this.refreshTimer);
376
+ const websocket = this.websocket;
377
+ const connections = [this.subscriber, this.redis].filter((redis) => redis !== void 0);
378
+ this.websocket = void 0;
379
+ this.subscriber = void 0;
380
+ this.redis = void 0;
381
+ const closed = connections.map((redis) => {
382
+ const ended = redis.status === "end" ? Promise.resolve() : (0, node_events.once)(redis, "end");
383
+ redis.disconnect();
384
+ return ended;
385
+ });
386
+ if (websocket && websocket.readyState !== ws.default.CLOSED) {
387
+ closed.push((0, node_events.once)(websocket, "close"));
388
+ websocket.terminate();
389
+ }
390
+ this.invalidate();
391
+ this.synced.resolve();
392
+ this.configured.resolve();
393
+ await Promise.allSettled([
394
+ ...closed,
395
+ this.messages,
396
+ this.synchronizing
397
+ ]);
398
+ this.cache.clear();
399
+ this.actors.clear();
400
+ this.reducers = [];
401
+ }
402
+ async [Symbol.asyncDispose]() {
403
+ await this.close();
404
+ }
405
+ async ingest({ events }) {
406
+ const redis = this.requireRedis();
407
+ if (!events.length) return {
408
+ inserted: 0,
409
+ duplicates: 0
410
+ };
411
+ const parsed = events.map(parseEvent);
412
+ await this.waitConfigured();
413
+ const updates = reduce(this.reducers, parsed, parsed.reduce((oldest, event) => Math.min(oldest, getBucketStart(event.timestamp)), Infinity));
414
+ for (const customer of new Set(parsed.map((event) => event.customer))) await this.actor(customerArguments(customer));
415
+ for (const update of updates) {
416
+ const identity = `${update.customer}:${update.reducer}`;
417
+ const statistics = update.statistics;
418
+ const state = await redis.outpostWriteBucket(`outpost:state:${identity}`, identity, this.channel, generateEpoch(), update.bucketStart, statistics.count, statistics.sum, statistics.min ?? "", statistics.max ?? "");
419
+ await this.receiveState(identity, decodeState(state));
420
+ }
421
+ return {
422
+ inserted: parsed.length,
423
+ duplicates: 0
424
+ };
425
+ }
426
+ async customerMeter(input) {
427
+ const customer = customerKey(input);
428
+ this.requireRedis();
429
+ await this.waitConfigured();
430
+ const reducer = this.reducers.find((item) => item.meter_ids?.includes(input.meter_id));
431
+ if (!reducer) return null;
432
+ const state = (await this.warmCustomer(customer, reducer)).state;
433
+ if (!state || state.coldUntil === void 0) throw new require_base.PolarError("Customer snapshot is not ready");
434
+ const combined = { ...state.cold };
435
+ for (const [start, statistics] of state.buckets) if (start >= state.coldUntil) addStatistics(combined, statistics);
436
+ const consumed = quantity(combined, reducer.aggregation.func);
437
+ const credited = state.credited[input.meter_id] ?? 0;
438
+ return {
439
+ ...input,
440
+ consumed_units: consumed,
441
+ credited_units: credited,
442
+ balance: credited - consumed
443
+ };
444
+ }
445
+ async actor(input) {
446
+ await this.waitConfigured();
447
+ for (const reducer of this.reducers) await this.warmCustomer(customerKey(input), reducer);
448
+ }
449
+ requireRedis() {
450
+ if (this.failure) throw this.failure;
451
+ if (!this.redis) throw new require_base.PolarError("Call Outpost.start() before using Outpost");
452
+ return this.redis;
453
+ }
454
+ async waitConfigured() {
455
+ await withTimeout(this.configured.promise);
456
+ this.requireRedis();
457
+ }
458
+ async send(message) {
459
+ this.requireRedis();
460
+ if (!this.websocket || this.websocket.readyState !== ws.default.OPEN) throw new require_base.PolarError("Outpost WebSocket is not connected");
461
+ await new Promise((resolve, reject) => this.websocket.send(JSON.stringify(message), (error) => error ? reject(error) : resolve()));
462
+ }
463
+ async warmCustomer(customer, reducer) {
464
+ const identity = `${customer}:${reducer.id}`;
465
+ this.requireRedis();
466
+ while (!this.isSynced) {
467
+ await withTimeout(this.synced.promise);
468
+ this.requireRedis();
469
+ }
470
+ let local = this.cache.get(identity);
471
+ if (!local) {
472
+ local = { pending: Promise.resolve() };
473
+ this.cache.set(identity, local);
474
+ if (this.cache.size > CACHE_SIZE) {
475
+ const evicted = this.cache.keys().next().value;
476
+ this.cache.delete(evicted);
477
+ this.actors.delete(evicted);
478
+ }
479
+ }
480
+ this.cache.delete(identity);
481
+ this.cache.set(identity, local);
482
+ if (local.state && this.actors.has(identity)) return local;
483
+ const entry = local;
484
+ await locked(entry, async () => {
485
+ if (!entry.state) entry.state = await this.loadState(identity);
486
+ if (!this.actors.has(identity)) {
487
+ for (const meter_id of reducer.meter_ids ?? []) await this.send({
488
+ type: "meter_usage",
489
+ payload: {
490
+ ...customerArguments(customer),
491
+ meter_id
492
+ }
493
+ });
494
+ this.actors.add(identity);
495
+ }
496
+ });
497
+ return entry;
498
+ }
499
+ async loadState(customer) {
500
+ const epoch = generateEpoch();
501
+ return decodeState(await this.requireRedis().outpostReadState(`outpost:state:${customer}`, epoch));
502
+ }
503
+ async receiveState(customer, state) {
504
+ const local = this.cache.get(customer);
505
+ if (!local) return;
506
+ await locked(local, async () => {
507
+ const current = local.state;
508
+ if (!current) return;
509
+ if (current.epoch !== state.epoch) state = await this.loadState(customer);
510
+ else if (current.revision >= state.revision) return;
511
+ local.state = state;
512
+ });
513
+ }
514
+ async receiveRedis(data) {
515
+ const update = JSON.parse(data);
516
+ await this.receiveState(update.customer, decodeState(update.state));
517
+ }
518
+ synchronize() {
519
+ if (this.synchronizing) return this.synchronizing;
520
+ const generation = this.generation;
521
+ this.synchronizing = (async () => {
522
+ if (this.failure || !this.subscriber || this.subscriber.status !== "ready" || this.redis?.status !== "ready") return;
523
+ if (!this.isSynced) await this.subscriber.subscribe(this.channel);
524
+ const entries = Array.from(this.cache);
525
+ for (const [customer, local] of entries) await locked(local, async () => {
526
+ const state = await this.loadState(customer);
527
+ if (generation === this.generation) local.state = state;
528
+ });
529
+ if (generation === this.generation) {
530
+ this.isSynced = true;
531
+ this.synced.resolve();
532
+ }
533
+ })().catch((error) => {
534
+ if (error instanceof TypeError) this.fail(error);
535
+ else this.invalidate();
536
+ }).finally(() => {
537
+ this.synchronizing = void 0;
538
+ if (!this.failure && generation !== this.generation && this.redis?.status === "ready" && this.subscriber?.status === "ready") this.synchronize();
539
+ });
540
+ return this.synchronizing;
541
+ }
542
+ invalidate() {
543
+ this.generation++;
544
+ this.isSynced = false;
545
+ this.synced.resolve();
546
+ this.synced = signal();
547
+ for (const local of this.cache.values()) local.state = void 0;
548
+ }
549
+ fail(error) {
550
+ this.failure = error instanceof Error ? error : new require_base.PolarError(String(error));
551
+ this.configured.resolve();
552
+ this.synced.resolve();
553
+ }
554
+ async receiveWebsocket(data) {
555
+ const message = JSON.parse(data);
556
+ if (message.type === "configuration") {
557
+ this.reducers = message.payload.reducers;
558
+ this.configured.resolve();
559
+ } else if (message.type === "meter_usage") {
560
+ const snapshot = message.payload;
561
+ const reducer = this.reducers.find((item) => item.meter_ids?.includes(snapshot.meter_id));
562
+ if (!reducer) return;
563
+ if (snapshot.customer_id !== null && snapshot.external_customer_id !== null) return;
564
+ const identity = `${customerKey({
565
+ customer_id: snapshot.customer_id ?? void 0,
566
+ external_customer_id: snapshot.external_customer_id ?? void 0
567
+ })}:${reducer.id}`;
568
+ if (!Number.isSafeInteger(snapshot.version) || !Number.isSafeInteger(snapshot.cold_until)) throw new TypeError("Snapshot timestamps must be safe integer microseconds");
569
+ for (const value of [
570
+ snapshot.count,
571
+ snapshot.sum,
572
+ snapshot.min,
573
+ snapshot.max,
574
+ snapshot.credited_units
575
+ ]) if (value !== null && !Number.isFinite(value)) throw new TypeError("Snapshot values must be finite");
576
+ const state = await this.requireRedis().outpostApplySnapshot(`outpost:state:${identity}`, identity, this.channel, generateEpoch(), snapshot.cold_until, snapshot.version, snapshot.meter_id, snapshot.credited_units, snapshot.count, snapshot.sum, snapshot.min ?? "", snapshot.max ?? "");
577
+ await this.receiveState(identity, decodeState(state));
578
+ }
579
+ }
580
+ };
581
+ //#endregion
582
+ exports.Outpost = Outpost;
583
+ exports.getBucketStart = getBucketStart;
584
+ exports.getMatcher = getMatcher;
585
+ exports.reduce = reduce;
586
+
587
+ //# sourceMappingURL=index.cjs.map