@windrun-huaiin/backend-core 12.0.0 → 13.0.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 (270) hide show
  1. package/dist/_virtual/_commonjs-dynamic-modules.js +7 -0
  2. package/dist/_virtual/_commonjs-dynamic-modules.mjs +5 -0
  3. package/dist/_virtual/_commonjsHelpers.js +10 -0
  4. package/dist/_virtual/_commonjsHelpers.mjs +7 -0
  5. package/dist/_virtual/aes.js +5 -0
  6. package/dist/_virtual/aes.mjs +3 -0
  7. package/dist/_virtual/blowfish.js +5 -0
  8. package/dist/_virtual/blowfish.mjs +3 -0
  9. package/dist/_virtual/cipher-core.js +5 -0
  10. package/dist/_virtual/cipher-core.mjs +3 -0
  11. package/dist/_virtual/core.js +5 -0
  12. package/dist/_virtual/core.mjs +3 -0
  13. package/dist/_virtual/enc-base64.js +5 -0
  14. package/dist/_virtual/enc-base64.mjs +3 -0
  15. package/dist/_virtual/enc-base64url.js +5 -0
  16. package/dist/_virtual/enc-base64url.mjs +3 -0
  17. package/dist/_virtual/enc-utf16.js +5 -0
  18. package/dist/_virtual/enc-utf16.mjs +3 -0
  19. package/dist/_virtual/evpkdf.js +5 -0
  20. package/dist/_virtual/evpkdf.mjs +3 -0
  21. package/dist/_virtual/format-hex.js +5 -0
  22. package/dist/_virtual/format-hex.mjs +3 -0
  23. package/dist/_virtual/hmac.js +5 -0
  24. package/dist/_virtual/hmac.mjs +3 -0
  25. package/dist/_virtual/index.js +7 -0
  26. package/dist/_virtual/index.mjs +5 -0
  27. package/dist/_virtual/index2.js +9 -0
  28. package/dist/_virtual/index2.mjs +7 -0
  29. package/dist/_virtual/index3.js +5 -0
  30. package/dist/_virtual/index3.mjs +3 -0
  31. package/dist/_virtual/lib-typedarrays.js +5 -0
  32. package/dist/_virtual/lib-typedarrays.mjs +3 -0
  33. package/dist/_virtual/md5.js +5 -0
  34. package/dist/_virtual/md5.mjs +3 -0
  35. package/dist/_virtual/mode-cfb.js +5 -0
  36. package/dist/_virtual/mode-cfb.mjs +3 -0
  37. package/dist/_virtual/mode-ctr-gladman.js +5 -0
  38. package/dist/_virtual/mode-ctr-gladman.mjs +3 -0
  39. package/dist/_virtual/mode-ctr.js +5 -0
  40. package/dist/_virtual/mode-ctr.mjs +3 -0
  41. package/dist/_virtual/mode-ecb.js +5 -0
  42. package/dist/_virtual/mode-ecb.mjs +3 -0
  43. package/dist/_virtual/mode-ofb.js +5 -0
  44. package/dist/_virtual/mode-ofb.mjs +3 -0
  45. package/dist/_virtual/pad-ansix923.js +5 -0
  46. package/dist/_virtual/pad-ansix923.mjs +3 -0
  47. package/dist/_virtual/pad-iso10126.js +5 -0
  48. package/dist/_virtual/pad-iso10126.mjs +3 -0
  49. package/dist/_virtual/pad-iso97971.js +5 -0
  50. package/dist/_virtual/pad-iso97971.mjs +3 -0
  51. package/dist/_virtual/pad-nopadding.js +5 -0
  52. package/dist/_virtual/pad-nopadding.mjs +3 -0
  53. package/dist/_virtual/pad-zeropadding.js +5 -0
  54. package/dist/_virtual/pad-zeropadding.mjs +3 -0
  55. package/dist/_virtual/pbkdf2.js +5 -0
  56. package/dist/_virtual/pbkdf2.mjs +3 -0
  57. package/dist/_virtual/rabbit-legacy.js +5 -0
  58. package/dist/_virtual/rabbit-legacy.mjs +3 -0
  59. package/dist/_virtual/rabbit.js +5 -0
  60. package/dist/_virtual/rabbit.mjs +3 -0
  61. package/dist/_virtual/rc4.js +5 -0
  62. package/dist/_virtual/rc4.mjs +3 -0
  63. package/dist/_virtual/ripemd160.js +5 -0
  64. package/dist/_virtual/ripemd160.mjs +3 -0
  65. package/dist/_virtual/sha1.js +5 -0
  66. package/dist/_virtual/sha1.mjs +3 -0
  67. package/dist/_virtual/sha224.js +5 -0
  68. package/dist/_virtual/sha224.mjs +3 -0
  69. package/dist/_virtual/sha256.js +5 -0
  70. package/dist/_virtual/sha256.mjs +3 -0
  71. package/dist/_virtual/sha3.js +5 -0
  72. package/dist/_virtual/sha3.mjs +3 -0
  73. package/dist/_virtual/sha384.js +5 -0
  74. package/dist/_virtual/sha384.mjs +3 -0
  75. package/dist/_virtual/sha512.js +5 -0
  76. package/dist/_virtual/sha512.mjs +3 -0
  77. package/dist/_virtual/tripledes.js +5 -0
  78. package/dist/_virtual/tripledes.mjs +3 -0
  79. package/dist/_virtual/x64-core.js +5 -0
  80. package/dist/_virtual/x64-core.mjs +3 -0
  81. package/dist/index.js +46 -0
  82. package/dist/index.mjs +7 -0
  83. package/dist/lib/index.d.ts +2 -0
  84. package/dist/lib/index.d.ts.map +1 -1
  85. package/dist/lib/index.js +46 -0
  86. package/dist/lib/index.mjs +7 -0
  87. package/dist/lib/upstash/index.d.ts +7 -0
  88. package/dist/lib/upstash/index.d.ts.map +1 -0
  89. package/dist/lib/upstash/qstash.d.ts +36 -0
  90. package/dist/lib/upstash/qstash.d.ts.map +1 -0
  91. package/dist/lib/upstash/qstash.js +130 -0
  92. package/dist/lib/upstash/qstash.mjs +124 -0
  93. package/dist/lib/upstash/redis-counter.d.ts +17 -0
  94. package/dist/lib/upstash/redis-counter.d.ts.map +1 -0
  95. package/dist/lib/upstash/redis-counter.js +55 -0
  96. package/dist/lib/upstash/redis-counter.mjs +50 -0
  97. package/dist/lib/upstash/redis-favorite.d.ts +21 -0
  98. package/dist/lib/upstash/redis-favorite.d.ts.map +1 -0
  99. package/dist/lib/upstash/redis-favorite.js +74 -0
  100. package/dist/lib/upstash/redis-favorite.mjs +68 -0
  101. package/dist/lib/upstash/redis-like.d.ts +21 -0
  102. package/dist/lib/upstash/redis-like.d.ts.map +1 -0
  103. package/dist/lib/upstash/redis-like.js +74 -0
  104. package/dist/lib/upstash/redis-like.mjs +68 -0
  105. package/dist/lib/upstash/redis-lock.d.ts +13 -0
  106. package/dist/lib/upstash/redis-lock.d.ts.map +1 -0
  107. package/dist/lib/upstash/redis-lock.js +75 -0
  108. package/dist/lib/upstash/redis-lock.mjs +71 -0
  109. package/dist/lib/upstash/redis-structures.d.ts +63 -0
  110. package/dist/lib/upstash/redis-structures.d.ts.map +1 -0
  111. package/dist/lib/upstash/redis-structures.js +211 -0
  112. package/dist/lib/upstash/redis-structures.mjs +195 -0
  113. package/dist/lib/upstash-config.d.ts +11 -0
  114. package/dist/lib/upstash-config.d.ts.map +1 -0
  115. package/dist/lib/upstash-config.js +53 -0
  116. package/dist/lib/upstash-config.mjs +50 -0
  117. package/dist/node_modules/.pnpm/@upstash_lock@0.2.1_typescript@5.9.3/node_modules/@upstash/lock/dist/index.js +191 -0
  118. package/dist/node_modules/.pnpm/@upstash_lock@0.2.1_typescript@5.9.3/node_modules/@upstash/lock/dist/index.mjs +189 -0
  119. package/dist/node_modules/.pnpm/@upstash_qstash@2.8.4/node_modules/@upstash/qstash/chunk-RQPZUJXG.js +1419 -0
  120. package/dist/node_modules/.pnpm/@upstash_qstash@2.8.4/node_modules/@upstash/qstash/chunk-RQPZUJXG.mjs +1403 -0
  121. package/dist/node_modules/.pnpm/@upstash_redis@1.36.1/node_modules/@upstash/redis/chunk-LLI2WIYN.js +4691 -0
  122. package/dist/node_modules/.pnpm/@upstash_redis@1.36.1/node_modules/@upstash/redis/chunk-LLI2WIYN.mjs +4686 -0
  123. package/dist/node_modules/.pnpm/@upstash_redis@1.36.1/node_modules/@upstash/redis/nodejs.js +115 -0
  124. package/dist/node_modules/.pnpm/@upstash_redis@1.36.1/node_modules/@upstash/redis/nodejs.mjs +113 -0
  125. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/aes.js +248 -0
  126. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/aes.mjs +246 -0
  127. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/blowfish.js +485 -0
  128. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/blowfish.mjs +483 -0
  129. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/cipher-core.js +906 -0
  130. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/cipher-core.mjs +904 -0
  131. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/core.js +818 -0
  132. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/core.mjs +816 -0
  133. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/enc-base64.js +146 -0
  134. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/enc-base64.mjs +144 -0
  135. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/enc-base64url.js +158 -0
  136. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/enc-base64url.mjs +156 -0
  137. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/enc-utf16.js +159 -0
  138. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/enc-utf16.mjs +157 -0
  139. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/evpkdf.js +146 -0
  140. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/evpkdf.mjs +144 -0
  141. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/format-hex.js +77 -0
  142. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/format-hex.mjs +75 -0
  143. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/hmac.js +153 -0
  144. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/hmac.mjs +151 -0
  145. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/index.js +62 -0
  146. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/index.mjs +60 -0
  147. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/lib-typedarrays.js +86 -0
  148. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/lib-typedarrays.mjs +84 -0
  149. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/md5.js +278 -0
  150. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/md5.mjs +276 -0
  151. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-cfb.js +91 -0
  152. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-cfb.mjs +89 -0
  153. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ctr-gladman.js +127 -0
  154. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ctr-gladman.mjs +125 -0
  155. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ctr.js +69 -0
  156. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ctr.mjs +67 -0
  157. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ecb.js +51 -0
  158. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ecb.mjs +49 -0
  159. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ofb.js +65 -0
  160. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ofb.mjs +63 -0
  161. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-ansix923.js +60 -0
  162. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-ansix923.mjs +58 -0
  163. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-iso10126.js +55 -0
  164. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-iso10126.mjs +53 -0
  165. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-iso97971.js +51 -0
  166. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-iso97971.mjs +49 -0
  167. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-nopadding.js +41 -0
  168. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-nopadding.mjs +39 -0
  169. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-zeropadding.js +58 -0
  170. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-zeropadding.mjs +56 -0
  171. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pbkdf2.js +157 -0
  172. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pbkdf2.mjs +155 -0
  173. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/rabbit-legacy.js +204 -0
  174. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/rabbit-legacy.mjs +202 -0
  175. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/rabbit.js +206 -0
  176. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/rabbit.mjs +204 -0
  177. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/rc4.js +153 -0
  178. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/rc4.mjs +151 -0
  179. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/ripemd160.js +277 -0
  180. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/ripemd160.mjs +275 -0
  181. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha1.js +160 -0
  182. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha1.mjs +158 -0
  183. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha224.js +91 -0
  184. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha224.mjs +89 -0
  185. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha256.js +209 -0
  186. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha256.mjs +207 -0
  187. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha3.js +337 -0
  188. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha3.mjs +335 -0
  189. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha384.js +95 -0
  190. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha384.mjs +93 -0
  191. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha512.js +337 -0
  192. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha512.mjs +335 -0
  193. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/tripledes.js +793 -0
  194. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/tripledes.mjs +791 -0
  195. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/x64-core.js +314 -0
  196. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/x64-core.mjs +312 -0
  197. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jws/compact/verify.js +26 -0
  198. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jws/compact/verify.mjs +24 -0
  199. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jws/flattened/verify.js +127 -0
  200. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jws/flattened/verify.mjs +125 -0
  201. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwt/verify.js +20 -0
  202. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwt/verify.mjs +18 -0
  203. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/key/import.js +31 -0
  204. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/key/import.mjs +29 -0
  205. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/buffer_utils.js +18 -0
  206. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/buffer_utils.mjs +14 -0
  207. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/check_key_type.js +82 -0
  208. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/check_key_type.mjs +80 -0
  209. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/crypto_key.js +103 -0
  210. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/crypto_key.mjs +101 -0
  211. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/epoch.js +5 -0
  212. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/epoch.mjs +3 -0
  213. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/invalid_key_input.js +38 -0
  214. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/invalid_key_input.mjs +33 -0
  215. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_disjoint.js +25 -0
  216. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_disjoint.mjs +23 -0
  217. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_jwk.js +21 -0
  218. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_jwk.mjs +16 -0
  219. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_object.js +20 -0
  220. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_object.mjs +18 -0
  221. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/jwt_claims_set.js +109 -0
  222. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/jwt_claims_set.mjs +107 -0
  223. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/secs.js +59 -0
  224. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/secs.mjs +57 -0
  225. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/validate_algorithms.js +14 -0
  226. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/validate_algorithms.mjs +12 -0
  227. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/validate_crit.js +38 -0
  228. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/validate_crit.mjs +36 -0
  229. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/base64url.js +15 -0
  230. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/base64url.mjs +13 -0
  231. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/check_key_length.js +21 -0
  232. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/check_key_length.mjs +19 -0
  233. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/dsa_digest.js +28 -0
  234. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/dsa_digest.mjs +26 -0
  235. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/get_named_curve.js +58 -0
  236. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/get_named_curve.mjs +56 -0
  237. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/get_sign_verify_key.js +33 -0
  238. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/get_sign_verify_key.mjs +31 -0
  239. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/hmac_digest.js +18 -0
  240. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/hmac_digest.mjs +16 -0
  241. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/is_key_like.js +15 -0
  242. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/is_key_like.mjs +10 -0
  243. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/is_key_object.js +26 -0
  244. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/is_key_object.mjs +5 -0
  245. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/jwk_to_key.js +12 -0
  246. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/jwk_to_key.mjs +10 -0
  247. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/node_key.js +113 -0
  248. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/node_key.mjs +111 -0
  249. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/sign.js +40 -0
  250. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/sign.mjs +19 -0
  251. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/verify.js +52 -0
  252. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/verify.mjs +31 -0
  253. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/webcrypto.js +32 -0
  254. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/webcrypto.mjs +7 -0
  255. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/util/errors.js +69 -0
  256. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/util/errors.mjs +60 -0
  257. package/dist/node_modules/.pnpm/neverthrow@7.2.0/node_modules/neverthrow/dist/index.es.js +422 -0
  258. package/dist/node_modules/.pnpm/neverthrow@7.2.0/node_modules/neverthrow/dist/index.es.mjs +415 -0
  259. package/dist/node_modules/.pnpm/uncrypto@0.1.3/node_modules/uncrypto/dist/crypto.web.js +6 -0
  260. package/dist/node_modules/.pnpm/uncrypto@0.1.3/node_modules/uncrypto/dist/crypto.web.mjs +4 -0
  261. package/package.json +14 -11
  262. package/src/lib/index.ts +2 -0
  263. package/src/lib/upstash/index.ts +6 -0
  264. package/src/lib/upstash/qstash.ts +157 -0
  265. package/src/lib/upstash/redis-counter.ts +51 -0
  266. package/src/lib/upstash/redis-favorite.ts +75 -0
  267. package/src/lib/upstash/redis-like.ts +75 -0
  268. package/src/lib/upstash/redis-lock.ts +85 -0
  269. package/src/lib/upstash/redis-structures.ts +249 -0
  270. package/src/lib/upstash-config.ts +54 -0
@@ -0,0 +1,1419 @@
1
+ 'use strict';
2
+
3
+ var index = require('../../../../../../_virtual/index2.js');
4
+ require('../../../../neverthrow@7.2.0/node_modules/neverthrow/dist/index.es.js');
5
+ var verify = require('../../../../jose@5.10.0/node_modules/jose/dist/node/esm/jwt/verify.js');
6
+
7
+ // src/receiver.ts
8
+ var SignatureError = class extends Error {
9
+ constructor(message) {
10
+ super(message);
11
+ this.name = "SignatureError";
12
+ }
13
+ };
14
+ var Receiver = class {
15
+ currentSigningKey;
16
+ nextSigningKey;
17
+ constructor(config) {
18
+ this.currentSigningKey = config.currentSigningKey;
19
+ this.nextSigningKey = config.nextSigningKey;
20
+ }
21
+ /**
22
+ * Verify the signature of a request.
23
+ *
24
+ * Tries to verify the signature with the current signing key.
25
+ * If that fails, maybe because you have rotated the keys recently, it will
26
+ * try to verify the signature with the next signing key.
27
+ *
28
+ * If that fails, the signature is invalid and a `SignatureError` is thrown.
29
+ */
30
+ async verify(request) {
31
+ let payload;
32
+ try {
33
+ payload = await this.verifyWithKey(this.currentSigningKey, request);
34
+ } catch {
35
+ payload = await this.verifyWithKey(this.nextSigningKey, request);
36
+ }
37
+ this.verifyBodyAndUrl(payload, request);
38
+ return true;
39
+ }
40
+ /**
41
+ * Verify signature with a specific signing key
42
+ */
43
+ async verifyWithKey(key, request) {
44
+ const jwt = await verify.jwtVerify(request.signature, new TextEncoder().encode(key), {
45
+ issuer: "Upstash",
46
+ clockTolerance: request.clockTolerance
47
+ }).catch((error) => {
48
+ throw new SignatureError(error.message);
49
+ });
50
+ return jwt.payload;
51
+ }
52
+ verifyBodyAndUrl(payload, request) {
53
+ const p = payload;
54
+ if (request.url !== void 0 && p.sub !== request.url) {
55
+ throw new SignatureError(`invalid subject: ${p.sub}, want: ${request.url}`);
56
+ }
57
+ const bodyHash = index.SHA256(request.body).toString(index.enc.Base64url);
58
+ const padding = new RegExp(/=+$/);
59
+ if (p.body.replace(padding, "") !== bodyHash.replace(padding, "")) {
60
+ throw new SignatureError(`body hash does not match, want: ${p.body}, got: ${bodyHash}`);
61
+ }
62
+ }
63
+ };
64
+
65
+ // src/client/dlq.ts
66
+ var DLQ = class {
67
+ http;
68
+ constructor(http) {
69
+ this.http = http;
70
+ }
71
+ /**
72
+ * List messages in the dlq
73
+ */
74
+ async listMessages(options) {
75
+ const filterPayload = {
76
+ ...options?.filter,
77
+ topicName: options?.filter?.urlGroup
78
+ };
79
+ const messagesPayload = await this.http.request({
80
+ method: "GET",
81
+ path: ["v2", "dlq"],
82
+ query: {
83
+ cursor: options?.cursor,
84
+ count: options?.count,
85
+ ...filterPayload
86
+ }
87
+ });
88
+ return {
89
+ messages: messagesPayload.messages.map((message) => {
90
+ return {
91
+ ...message,
92
+ urlGroup: message.topicName,
93
+ ratePerSecond: "rate" in message ? message.rate : void 0
94
+ };
95
+ }),
96
+ cursor: messagesPayload.cursor
97
+ };
98
+ }
99
+ /**
100
+ * Remove a message from the dlq using it's `dlqId`
101
+ */
102
+ async delete(dlqMessageId) {
103
+ return await this.http.request({
104
+ method: "DELETE",
105
+ path: ["v2", "dlq", dlqMessageId],
106
+ parseResponseAsJson: false
107
+ // there is no response
108
+ });
109
+ }
110
+ /**
111
+ * Remove multiple messages from the dlq using their `dlqId`s
112
+ */
113
+ async deleteMany(request) {
114
+ return await this.http.request({
115
+ method: "DELETE",
116
+ path: ["v2", "dlq"],
117
+ headers: { "Content-Type": "application/json" },
118
+ body: JSON.stringify({ dlqIds: request.dlqIds })
119
+ });
120
+ }
121
+ };
122
+
123
+ // src/client/error.ts
124
+ var RATELIMIT_STATUS = 429;
125
+ var QstashError = class extends Error {
126
+ status;
127
+ constructor(message, status) {
128
+ super(message);
129
+ this.name = "QstashError";
130
+ this.status = status;
131
+ }
132
+ };
133
+ var QstashRatelimitError = class extends QstashError {
134
+ limit;
135
+ remaining;
136
+ reset;
137
+ constructor(args) {
138
+ super(`Exceeded burst rate limit. ${JSON.stringify(args)}`, RATELIMIT_STATUS);
139
+ this.name = "QstashRatelimitError";
140
+ this.limit = args.limit;
141
+ this.remaining = args.remaining;
142
+ this.reset = args.reset;
143
+ }
144
+ };
145
+ var QstashChatRatelimitError = class extends QstashError {
146
+ limitRequests;
147
+ limitTokens;
148
+ remainingRequests;
149
+ remainingTokens;
150
+ resetRequests;
151
+ resetTokens;
152
+ constructor(args) {
153
+ super(`Exceeded chat rate limit. ${JSON.stringify(args)}`, RATELIMIT_STATUS);
154
+ this.name = "QstashChatRatelimitError";
155
+ this.limitRequests = args["limit-requests"];
156
+ this.limitTokens = args["limit-tokens"];
157
+ this.remainingRequests = args["remaining-requests"];
158
+ this.remainingTokens = args["remaining-tokens"];
159
+ this.resetRequests = args["reset-requests"];
160
+ this.resetTokens = args["reset-tokens"];
161
+ }
162
+ };
163
+ var QstashDailyRatelimitError = class extends QstashError {
164
+ limit;
165
+ remaining;
166
+ reset;
167
+ constructor(args) {
168
+ super(`Exceeded daily rate limit. ${JSON.stringify(args)}`, RATELIMIT_STATUS);
169
+ this.name = "QstashDailyRatelimitError";
170
+ this.limit = args.limit;
171
+ this.remaining = args.remaining;
172
+ this.reset = args.reset;
173
+ }
174
+ };
175
+
176
+ // src/client/http.ts
177
+ var HttpClient = class {
178
+ baseUrl;
179
+ authorization;
180
+ options;
181
+ retry;
182
+ headers;
183
+ telemetryHeaders;
184
+ constructor(config) {
185
+ this.baseUrl = config.baseUrl.replace(/\/$/, "");
186
+ this.authorization = config.authorization;
187
+ this.retry = // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
188
+ typeof config.retry === "boolean" && !config.retry ? {
189
+ attempts: 1,
190
+ backoff: () => 0
191
+ } : {
192
+ attempts: config.retry?.retries ?? 5,
193
+ backoff: config.retry?.backoff ?? ((retryCount) => Math.exp(retryCount) * 50)
194
+ };
195
+ this.headers = config.headers;
196
+ this.telemetryHeaders = config.telemetryHeaders;
197
+ }
198
+ async request(request) {
199
+ const { response } = await this.requestWithBackoff(request);
200
+ if (request.parseResponseAsJson === false) {
201
+ return void 0;
202
+ }
203
+ return await response.json();
204
+ }
205
+ async *requestStream(request) {
206
+ const { response } = await this.requestWithBackoff(request);
207
+ if (!response.body) {
208
+ throw new Error("No response body");
209
+ }
210
+ const body = response.body;
211
+ const reader = body.getReader();
212
+ const decoder = new TextDecoder();
213
+ try {
214
+ while (true) {
215
+ const { done, value } = await reader.read();
216
+ if (done) {
217
+ break;
218
+ }
219
+ const chunkText = decoder.decode(value, { stream: true });
220
+ const chunks = chunkText.split("\n").filter(Boolean);
221
+ for (const chunk of chunks) {
222
+ if (chunk.startsWith("data: ")) {
223
+ const data = chunk.slice(6);
224
+ if (data === "[DONE]") {
225
+ break;
226
+ }
227
+ yield JSON.parse(data);
228
+ }
229
+ }
230
+ }
231
+ } finally {
232
+ await reader.cancel();
233
+ }
234
+ }
235
+ requestWithBackoff = async (request) => {
236
+ const [url, requestOptions] = this.processRequest(request);
237
+ let response = void 0;
238
+ let error = void 0;
239
+ for (let index = 0; index <= this.retry.attempts; index++) {
240
+ try {
241
+ response = await fetch(url.toString(), requestOptions);
242
+ break;
243
+ } catch (error_) {
244
+ error = error_;
245
+ if (index < this.retry.attempts) {
246
+ await new Promise((r) => setTimeout(r, this.retry.backoff(index)));
247
+ }
248
+ }
249
+ }
250
+ if (!response) {
251
+ throw error ?? new Error("Exhausted all retries");
252
+ }
253
+ await this.checkResponse(response);
254
+ return {
255
+ response,
256
+ error
257
+ };
258
+ };
259
+ processRequest = (request) => {
260
+ const headers = new Headers(request.headers);
261
+ if (!headers.has("Authorization")) {
262
+ headers.set("Authorization", this.authorization);
263
+ }
264
+ const requestOptions = {
265
+ method: request.method,
266
+ headers,
267
+ body: request.body,
268
+ keepalive: request.keepalive
269
+ };
270
+ const url = new URL([request.baseUrl ?? this.baseUrl, ...request.path].join("/"));
271
+ if (request.query) {
272
+ for (const [key, value] of Object.entries(request.query)) {
273
+ if (value !== void 0) {
274
+ url.searchParams.set(key, value.toString());
275
+ }
276
+ }
277
+ }
278
+ return [url.toString(), requestOptions];
279
+ };
280
+ async checkResponse(response) {
281
+ if (response.status === 429) {
282
+ if (response.headers.get("x-ratelimit-limit-requests")) {
283
+ throw new QstashChatRatelimitError({
284
+ "limit-requests": response.headers.get("x-ratelimit-limit-requests"),
285
+ "limit-tokens": response.headers.get("x-ratelimit-limit-tokens"),
286
+ "remaining-requests": response.headers.get("x-ratelimit-remaining-requests"),
287
+ "remaining-tokens": response.headers.get("x-ratelimit-remaining-tokens"),
288
+ "reset-requests": response.headers.get("x-ratelimit-reset-requests"),
289
+ "reset-tokens": response.headers.get("x-ratelimit-reset-tokens")
290
+ });
291
+ } else if (response.headers.get("RateLimit-Limit")) {
292
+ throw new QstashDailyRatelimitError({
293
+ limit: response.headers.get("RateLimit-Limit"),
294
+ remaining: response.headers.get("RateLimit-Remaining"),
295
+ reset: response.headers.get("RateLimit-Reset")
296
+ });
297
+ }
298
+ throw new QstashRatelimitError({
299
+ limit: response.headers.get("Burst-RateLimit-Limit"),
300
+ remaining: response.headers.get("Burst-RateLimit-Remaining"),
301
+ reset: response.headers.get("Burst-RateLimit-Reset")
302
+ });
303
+ }
304
+ if (response.status < 200 || response.status >= 300) {
305
+ const body = await response.text();
306
+ throw new QstashError(
307
+ body.length > 0 ? body : `Error: status=${response.status}`,
308
+ response.status
309
+ );
310
+ }
311
+ }
312
+ };
313
+
314
+ // src/client/llm/providers.ts
315
+ var setupAnalytics = (analytics, providerApiKey, providerBaseUrl, provider) => {
316
+ if (!analytics)
317
+ return {};
318
+ switch (analytics.name) {
319
+ case "helicone": {
320
+ switch (provider) {
321
+ case "upstash": {
322
+ return {
323
+ baseURL: "https://qstash.helicone.ai/llm/v1/chat/completions",
324
+ defaultHeaders: {
325
+ "Helicone-Auth": `Bearer ${analytics.token}`,
326
+ Authorization: `Bearer ${providerApiKey}`
327
+ }
328
+ };
329
+ }
330
+ default: {
331
+ return {
332
+ baseURL: "https://gateway.helicone.ai/v1/chat/completions",
333
+ defaultHeaders: {
334
+ "Helicone-Auth": `Bearer ${analytics.token}`,
335
+ "Helicone-Target-Url": providerBaseUrl,
336
+ Authorization: `Bearer ${providerApiKey}`
337
+ }
338
+ };
339
+ }
340
+ }
341
+ }
342
+ default: {
343
+ throw new Error("Unknown analytics provider");
344
+ }
345
+ }
346
+ };
347
+
348
+ // src/client/llm/chat.ts
349
+ var Chat = class _Chat {
350
+ http;
351
+ token;
352
+ constructor(http, token) {
353
+ this.http = http;
354
+ this.token = token;
355
+ }
356
+ static toChatRequest(request) {
357
+ const messages = [];
358
+ messages.push(
359
+ { role: "system", content: request.system },
360
+ { role: "user", content: request.user }
361
+ );
362
+ const chatRequest = { ...request, messages };
363
+ return chatRequest;
364
+ }
365
+ /**
366
+ * Calls the Upstash completions api given a ChatRequest.
367
+ *
368
+ * Returns a ChatCompletion or a stream of ChatCompletionChunks
369
+ * if stream is enabled.
370
+ *
371
+ * @param request ChatRequest with messages
372
+ * @returns Chat completion or stream
373
+ */
374
+ create = async (request) => {
375
+ if (request.provider.owner != "upstash")
376
+ return this.createThirdParty(request);
377
+ const body = JSON.stringify(request);
378
+ let baseUrl = void 0;
379
+ let headers = {
380
+ "Content-Type": "application/json",
381
+ Authorization: `Bearer ${this.token}`,
382
+ ..."stream" in request && request.stream ? {
383
+ Connection: "keep-alive",
384
+ Accept: "text/event-stream",
385
+ "Cache-Control": "no-cache"
386
+ } : {}
387
+ };
388
+ if (request.analytics) {
389
+ const { baseURL, defaultHeaders } = setupAnalytics(
390
+ { name: "helicone", token: request.analytics.token },
391
+ this.getAuthorizationToken(),
392
+ request.provider.baseUrl,
393
+ "upstash"
394
+ );
395
+ headers = { ...headers, ...defaultHeaders };
396
+ baseUrl = baseURL;
397
+ }
398
+ const path = request.analytics ? [] : ["llm", "v1", "chat", "completions"];
399
+ return "stream" in request && request.stream ? this.http.requestStream({
400
+ path,
401
+ method: "POST",
402
+ headers,
403
+ baseUrl,
404
+ body
405
+ }) : this.http.request({
406
+ path,
407
+ method: "POST",
408
+ headers,
409
+ baseUrl,
410
+ body
411
+ });
412
+ };
413
+ /**
414
+ * Calls the Upstash completions api given a ChatRequest.
415
+ *
416
+ * Returns a ChatCompletion or a stream of ChatCompletionChunks
417
+ * if stream is enabled.
418
+ *
419
+ * @param request ChatRequest with messages
420
+ * @returns Chat completion or stream
421
+ */
422
+ createThirdParty = async (request) => {
423
+ const { baseUrl, token, owner, organization } = request.provider;
424
+ if (owner === "upstash")
425
+ throw new Error("Upstash is not 3rd party provider!");
426
+ delete request.provider;
427
+ delete request.system;
428
+ const analytics = request.analytics;
429
+ delete request.analytics;
430
+ const body = JSON.stringify(request);
431
+ const isAnalyticsEnabled = analytics?.name && analytics.token;
432
+ const analyticsConfig = analytics?.name && analytics.token ? setupAnalytics({ name: analytics.name, token: analytics.token }, token, baseUrl, owner) : { defaultHeaders: void 0, baseURL: baseUrl };
433
+ const isStream = "stream" in request && request.stream;
434
+ const headers = {
435
+ "Content-Type": "application/json",
436
+ Authorization: `Bearer ${token}`,
437
+ ...organization ? {
438
+ "OpenAI-Organization": organization
439
+ } : {},
440
+ ...isStream ? {
441
+ Connection: "keep-alive",
442
+ Accept: "text/event-stream",
443
+ "Cache-Control": "no-cache"
444
+ } : {},
445
+ ...analyticsConfig.defaultHeaders
446
+ };
447
+ const response = await this.http[isStream ? "requestStream" : "request"]({
448
+ path: isAnalyticsEnabled ? [] : ["v1", "chat", "completions"],
449
+ method: "POST",
450
+ headers,
451
+ body,
452
+ baseUrl: analyticsConfig.baseURL
453
+ });
454
+ return response;
455
+ };
456
+ // Helper method to get the authorization token
457
+ getAuthorizationToken() {
458
+ const authHeader = String(this.http.authorization);
459
+ const match = /Bearer (.+)/.exec(authHeader);
460
+ if (!match) {
461
+ throw new Error("Invalid authorization header format");
462
+ }
463
+ return match[1];
464
+ }
465
+ /**
466
+ * Calls the Upstash completions api given a PromptRequest.
467
+ *
468
+ * Returns a ChatCompletion or a stream of ChatCompletionChunks
469
+ * if stream is enabled.
470
+ *
471
+ * @param request PromptRequest with system and user messages.
472
+ * Note that system parameter shouldn't be passed in the case of
473
+ * mistralai/Mistral-7B-Instruct-v0.2 model.
474
+ * @returns Chat completion or stream
475
+ */
476
+ prompt = async (request) => {
477
+ const chatRequest = _Chat.toChatRequest(request);
478
+ return this.create(chatRequest);
479
+ };
480
+ };
481
+
482
+ // src/client/messages.ts
483
+ var Messages = class {
484
+ http;
485
+ constructor(http) {
486
+ this.http = http;
487
+ }
488
+ /**
489
+ * Get a message
490
+ */
491
+ async get(messageId) {
492
+ const messagePayload = await this.http.request({
493
+ method: "GET",
494
+ path: ["v2", "messages", messageId]
495
+ });
496
+ const message = {
497
+ ...messagePayload,
498
+ urlGroup: messagePayload.topicName,
499
+ ratePerSecond: "rate" in messagePayload ? messagePayload.rate : void 0
500
+ };
501
+ return message;
502
+ }
503
+ /**
504
+ * Cancel a message
505
+ */
506
+ async delete(messageId) {
507
+ return await this.http.request({
508
+ method: "DELETE",
509
+ path: ["v2", "messages", messageId],
510
+ parseResponseAsJson: false
511
+ });
512
+ }
513
+ async deleteMany(messageIds) {
514
+ const result = await this.http.request({
515
+ method: "DELETE",
516
+ path: ["v2", "messages"],
517
+ headers: { "Content-Type": "application/json" },
518
+ body: JSON.stringify({ messageIds })
519
+ });
520
+ return result.cancelled;
521
+ }
522
+ async deleteAll() {
523
+ const result = await this.http.request({
524
+ method: "DELETE",
525
+ path: ["v2", "messages"]
526
+ });
527
+ return result.cancelled;
528
+ }
529
+ };
530
+
531
+ // src/client/api/base.ts
532
+ var BaseProvider = class {
533
+ baseUrl;
534
+ token;
535
+ owner;
536
+ constructor(baseUrl, token, owner) {
537
+ this.baseUrl = baseUrl;
538
+ this.token = token;
539
+ this.owner = owner;
540
+ }
541
+ getUrl() {
542
+ return `${this.baseUrl}/${this.getRoute().join("/")}`;
543
+ }
544
+ };
545
+
546
+ // src/client/api/llm.ts
547
+ var LLMProvider = class extends BaseProvider {
548
+ apiKind = "llm";
549
+ organization;
550
+ method = "POST";
551
+ constructor(baseUrl, token, owner, organization) {
552
+ super(baseUrl, token, owner);
553
+ this.organization = organization;
554
+ }
555
+ getRoute() {
556
+ return this.owner === "anthropic" ? ["v1", "messages"] : ["v1", "chat", "completions"];
557
+ }
558
+ getHeaders(options) {
559
+ if (this.owner === "upstash" && !options.analytics) {
560
+ return { "content-type": "application/json" };
561
+ }
562
+ const header = this.owner === "anthropic" ? "x-api-key" : "authorization";
563
+ const headerValue = this.owner === "anthropic" ? this.token : `Bearer ${this.token}`;
564
+ const headers = {
565
+ [header]: headerValue,
566
+ "content-type": "application/json"
567
+ };
568
+ if (this.owner === "openai" && this.organization) {
569
+ headers["OpenAI-Organization"] = this.organization;
570
+ }
571
+ if (this.owner === "anthropic") {
572
+ headers["anthropic-version"] = "2023-06-01";
573
+ }
574
+ return headers;
575
+ }
576
+ /**
577
+ * Checks if callback exists and adds analytics in place if it's set.
578
+ *
579
+ * @param request
580
+ * @param options
581
+ */
582
+ onFinish(providerInfo, options) {
583
+ if (options.analytics) {
584
+ return updateWithAnalytics(providerInfo, options.analytics);
585
+ }
586
+ return providerInfo;
587
+ }
588
+ };
589
+ var upstash = () => {
590
+ return new LLMProvider("https://qstash.upstash.io/llm", "", "upstash");
591
+ };
592
+
593
+ // src/client/api/utils.ts
594
+ var getProviderInfo = (api, upstashToken) => {
595
+ const { name, provider, ...parameters } = api;
596
+ const finalProvider = provider ?? upstash();
597
+ if (finalProvider.owner === "upstash" && !finalProvider.token) {
598
+ finalProvider.token = upstashToken;
599
+ }
600
+ if (!finalProvider.baseUrl)
601
+ throw new TypeError("baseUrl cannot be empty or undefined!");
602
+ if (!finalProvider.token)
603
+ throw new TypeError("token cannot be empty or undefined!");
604
+ if (finalProvider.apiKind !== name) {
605
+ throw new TypeError(
606
+ `Unexpected api name. Expected '${finalProvider.apiKind}', received ${name}`
607
+ );
608
+ }
609
+ const providerInfo = {
610
+ url: finalProvider.getUrl(),
611
+ baseUrl: finalProvider.baseUrl,
612
+ route: finalProvider.getRoute(),
613
+ appendHeaders: finalProvider.getHeaders(parameters),
614
+ owner: finalProvider.owner,
615
+ method: finalProvider.method
616
+ };
617
+ return finalProvider.onFinish(providerInfo, parameters);
618
+ };
619
+ var safeJoinHeaders = (headers, record) => {
620
+ const joinedHeaders = new Headers(record);
621
+ for (const [header, value] of headers.entries()) {
622
+ joinedHeaders.set(header, value);
623
+ }
624
+ return joinedHeaders;
625
+ };
626
+ var processApi = (request, headers, upstashToken) => {
627
+ if (!request.api) {
628
+ request.headers = headers;
629
+ return request;
630
+ }
631
+ const { url, appendHeaders, owner, method } = getProviderInfo(request.api, upstashToken);
632
+ if (request.api.name === "llm") {
633
+ const callback = request.callback;
634
+ if (!callback) {
635
+ throw new TypeError("Callback cannot be undefined when using LLM api.");
636
+ }
637
+ return {
638
+ ...request,
639
+ method: request.method ?? method,
640
+ headers: safeJoinHeaders(headers, appendHeaders),
641
+ ...owner === "upstash" && !request.api.analytics ? { api: { name: "llm" }, url: void 0, callback } : { url, api: void 0 }
642
+ };
643
+ } else {
644
+ return {
645
+ ...request,
646
+ method: request.method ?? method,
647
+ headers: safeJoinHeaders(headers, appendHeaders),
648
+ url,
649
+ api: void 0
650
+ };
651
+ }
652
+ };
653
+ function updateWithAnalytics(providerInfo, analytics) {
654
+ switch (analytics.name) {
655
+ case "helicone": {
656
+ providerInfo.appendHeaders["Helicone-Auth"] = `Bearer ${analytics.token}`;
657
+ if (providerInfo.owner === "upstash") {
658
+ updateProviderInfo(providerInfo, "https://qstash.helicone.ai", [
659
+ "llm",
660
+ ...providerInfo.route
661
+ ]);
662
+ } else {
663
+ providerInfo.appendHeaders["Helicone-Target-Url"] = providerInfo.baseUrl;
664
+ updateProviderInfo(providerInfo, "https://gateway.helicone.ai", providerInfo.route);
665
+ }
666
+ return providerInfo;
667
+ }
668
+ default: {
669
+ throw new Error("Unknown analytics provider");
670
+ }
671
+ }
672
+ }
673
+ function updateProviderInfo(providerInfo, baseUrl, route) {
674
+ providerInfo.baseUrl = baseUrl;
675
+ providerInfo.route = route;
676
+ providerInfo.url = `${baseUrl}/${route.join("/")}`;
677
+ }
678
+
679
+ // src/client/utils.ts
680
+ var isIgnoredHeader = (header) => {
681
+ const lowerCaseHeader = header.toLowerCase();
682
+ return lowerCaseHeader.startsWith("content-type") || lowerCaseHeader.startsWith("upstash-");
683
+ };
684
+ function prefixHeaders(headers) {
685
+ const keysToBePrefixed = [...headers.keys()].filter((key) => !isIgnoredHeader(key));
686
+ for (const key of keysToBePrefixed) {
687
+ const value = headers.get(key);
688
+ if (value !== null) {
689
+ headers.set(`Upstash-Forward-${key}`, value);
690
+ }
691
+ headers.delete(key);
692
+ }
693
+ return headers;
694
+ }
695
+ function wrapWithGlobalHeaders(headers, globalHeaders, telemetryHeaders) {
696
+ if (!globalHeaders) {
697
+ return headers;
698
+ }
699
+ const finalHeaders = new Headers(globalHeaders);
700
+ headers.forEach((value, key) => {
701
+ finalHeaders.set(key, value);
702
+ });
703
+ telemetryHeaders?.forEach((value, key) => {
704
+ if (!value)
705
+ return;
706
+ finalHeaders.append(key, value);
707
+ });
708
+ return finalHeaders;
709
+ }
710
+ function processHeaders(request) {
711
+ const headers = prefixHeaders(new Headers(request.headers));
712
+ headers.set("Upstash-Method", request.method ?? "POST");
713
+ if (request.delay !== void 0) {
714
+ if (typeof request.delay === "string") {
715
+ headers.set("Upstash-Delay", request.delay);
716
+ } else {
717
+ headers.set("Upstash-Delay", `${request.delay.toFixed(0)}s`);
718
+ }
719
+ }
720
+ if (request.notBefore !== void 0) {
721
+ headers.set("Upstash-Not-Before", request.notBefore.toFixed(0));
722
+ }
723
+ if (request.deduplicationId !== void 0) {
724
+ headers.set("Upstash-Deduplication-Id", request.deduplicationId);
725
+ }
726
+ if (request.contentBasedDeduplication) {
727
+ headers.set("Upstash-Content-Based-Deduplication", "true");
728
+ }
729
+ if (request.retries !== void 0) {
730
+ headers.set("Upstash-Retries", request.retries.toFixed(0));
731
+ }
732
+ if (request.retryDelay !== void 0) {
733
+ headers.set("Upstash-Retry-Delay", request.retryDelay);
734
+ }
735
+ if (request.callback !== void 0) {
736
+ headers.set("Upstash-Callback", request.callback);
737
+ }
738
+ if (request.failureCallback !== void 0) {
739
+ headers.set("Upstash-Failure-Callback", request.failureCallback);
740
+ }
741
+ if (request.timeout !== void 0) {
742
+ if (typeof request.timeout === "string") {
743
+ headers.set("Upstash-Timeout", request.timeout);
744
+ } else {
745
+ headers.set("Upstash-Timeout", `${request.timeout}s`);
746
+ }
747
+ }
748
+ if (request.flowControl?.key) {
749
+ const parallelism = request.flowControl.parallelism?.toString();
750
+ const rate = (request.flowControl.rate ?? request.flowControl.ratePerSecond)?.toString();
751
+ const period = typeof request.flowControl.period === "number" ? `${request.flowControl.period}s` : request.flowControl.period;
752
+ const controlValue = [
753
+ parallelism ? `parallelism=${parallelism}` : void 0,
754
+ rate ? `rate=${rate}` : void 0,
755
+ period ? `period=${period}` : void 0
756
+ ].filter(Boolean);
757
+ if (controlValue.length === 0) {
758
+ throw new QstashError("Provide at least one of parallelism or ratePerSecond for flowControl");
759
+ }
760
+ headers.set("Upstash-Flow-Control-Key", request.flowControl.key);
761
+ headers.set("Upstash-Flow-Control-Value", controlValue.join(", "));
762
+ }
763
+ if (request.label !== void 0) {
764
+ headers.set("Upstash-Label", request.label);
765
+ }
766
+ return headers;
767
+ }
768
+ function getRequestPath(request) {
769
+ const nonApiPath = request.url ?? request.urlGroup ?? request.topic;
770
+ if (nonApiPath)
771
+ return nonApiPath;
772
+ if (request.api?.name === "llm")
773
+ return `api/llm`;
774
+ if (request.api?.name === "email") {
775
+ const providerInfo = getProviderInfo(request.api, "not-needed");
776
+ return providerInfo.baseUrl;
777
+ }
778
+ throw new QstashError(`Failed to infer request path for ${JSON.stringify(request)}`);
779
+ }
780
+ function getRuntime() {
781
+ if (typeof process === "object" && typeof process.versions == "object" && process.versions.bun)
782
+ return `bun@${process.versions.bun}`;
783
+ if (typeof EdgeRuntime === "string")
784
+ return "edge-light";
785
+ else if (typeof process === "object" && typeof process.version === "string")
786
+ return `node@${process.version}`;
787
+ return "";
788
+ }
789
+
790
+ // src/client/queue.ts
791
+ var Queue = class {
792
+ http;
793
+ queueName;
794
+ constructor(http, queueName) {
795
+ this.http = http;
796
+ this.queueName = queueName;
797
+ }
798
+ /**
799
+ * Create or update the queue
800
+ */
801
+ async upsert(request) {
802
+ if (!this.queueName) {
803
+ throw new Error("Please provide a queue name to the Queue constructor");
804
+ }
805
+ const body = {
806
+ queueName: this.queueName,
807
+ parallelism: request.parallelism ?? 1,
808
+ paused: request.paused ?? false
809
+ };
810
+ await this.http.request({
811
+ method: "POST",
812
+ path: ["v2", "queues"],
813
+ headers: {
814
+ "Content-Type": "application/json"
815
+ },
816
+ body: JSON.stringify(body),
817
+ parseResponseAsJson: false
818
+ });
819
+ }
820
+ /**
821
+ * Get the queue details
822
+ */
823
+ async get() {
824
+ if (!this.queueName) {
825
+ throw new Error("Please provide a queue name to the Queue constructor");
826
+ }
827
+ return await this.http.request({
828
+ method: "GET",
829
+ path: ["v2", "queues", this.queueName]
830
+ });
831
+ }
832
+ /**
833
+ * List queues
834
+ */
835
+ async list() {
836
+ return await this.http.request({
837
+ method: "GET",
838
+ path: ["v2", "queues"]
839
+ });
840
+ }
841
+ /**
842
+ * Delete the queue
843
+ */
844
+ async delete() {
845
+ if (!this.queueName) {
846
+ throw new Error("Please provide a queue name to the Queue constructor");
847
+ }
848
+ await this.http.request({
849
+ method: "DELETE",
850
+ path: ["v2", "queues", this.queueName],
851
+ parseResponseAsJson: false
852
+ });
853
+ }
854
+ /**
855
+ * Enqueue a message to a queue.
856
+ */
857
+ async enqueue(request) {
858
+ if (!this.queueName) {
859
+ throw new Error("Please provide a queue name to the Queue constructor");
860
+ }
861
+ const headers = wrapWithGlobalHeaders(
862
+ processHeaders(request),
863
+ this.http.headers,
864
+ this.http.telemetryHeaders
865
+ );
866
+ const destination = getRequestPath(request);
867
+ const response = await this.http.request({
868
+ path: ["v2", "enqueue", this.queueName, destination],
869
+ body: request.body,
870
+ headers,
871
+ method: "POST"
872
+ });
873
+ return response;
874
+ }
875
+ /**
876
+ * Enqueue a message to a queue, serializing the body to JSON.
877
+ */
878
+ async enqueueJSON(request) {
879
+ const headers = prefixHeaders(new Headers(request.headers));
880
+ headers.set("Content-Type", "application/json");
881
+ const upstashToken = String(this.http.authorization).split("Bearer ")[1];
882
+ const nonApiRequest = processApi(request, headers, upstashToken);
883
+ const response = await this.enqueue({
884
+ ...nonApiRequest,
885
+ body: JSON.stringify(nonApiRequest.body)
886
+ });
887
+ return response;
888
+ }
889
+ /**
890
+ * Pauses the queue.
891
+ *
892
+ * A paused queue will not deliver messages until
893
+ * it is resumed.
894
+ */
895
+ async pause() {
896
+ if (!this.queueName) {
897
+ throw new Error("Please provide a queue name to the Queue constructor");
898
+ }
899
+ await this.http.request({
900
+ method: "POST",
901
+ path: ["v2", "queues", this.queueName, "pause"],
902
+ parseResponseAsJson: false
903
+ });
904
+ }
905
+ /**
906
+ * Resumes the queue.
907
+ */
908
+ async resume() {
909
+ if (!this.queueName) {
910
+ throw new Error("Please provide a queue name to the Queue constructor");
911
+ }
912
+ await this.http.request({
913
+ method: "POST",
914
+ path: ["v2", "queues", this.queueName, "resume"],
915
+ parseResponseAsJson: false
916
+ });
917
+ }
918
+ };
919
+
920
+ // src/client/schedules.ts
921
+ var Schedules = class {
922
+ http;
923
+ constructor(http) {
924
+ this.http = http;
925
+ }
926
+ /**
927
+ * Create a schedule
928
+ */
929
+ async create(request) {
930
+ const headers = prefixHeaders(new Headers(request.headers));
931
+ if (!headers.has("Content-Type")) {
932
+ headers.set("Content-Type", "application/json");
933
+ }
934
+ headers.set("Upstash-Cron", request.cron);
935
+ if (request.method !== void 0) {
936
+ headers.set("Upstash-Method", request.method);
937
+ }
938
+ if (request.delay !== void 0) {
939
+ if (typeof request.delay === "string") {
940
+ headers.set("Upstash-Delay", request.delay);
941
+ } else {
942
+ headers.set("Upstash-Delay", `${request.delay.toFixed(0)}s`);
943
+ }
944
+ }
945
+ if (request.retries !== void 0) {
946
+ headers.set("Upstash-Retries", request.retries.toFixed(0));
947
+ }
948
+ if (request.retryDelay !== void 0) {
949
+ headers.set("Upstash-Retry-Delay", request.retryDelay);
950
+ }
951
+ if (request.callback !== void 0) {
952
+ headers.set("Upstash-Callback", request.callback);
953
+ }
954
+ if (request.failureCallback !== void 0) {
955
+ headers.set("Upstash-Failure-Callback", request.failureCallback);
956
+ }
957
+ if (request.timeout !== void 0) {
958
+ if (typeof request.timeout === "string") {
959
+ headers.set("Upstash-Timeout", request.timeout);
960
+ } else {
961
+ headers.set("Upstash-Timeout", `${request.timeout}s`);
962
+ }
963
+ }
964
+ if (request.scheduleId !== void 0) {
965
+ headers.set("Upstash-Schedule-Id", request.scheduleId);
966
+ }
967
+ if (request.queueName !== void 0) {
968
+ headers.set("Upstash-Queue-Name", request.queueName);
969
+ }
970
+ if (request.flowControl?.key) {
971
+ const parallelism = request.flowControl.parallelism?.toString();
972
+ const rate = (request.flowControl.rate ?? request.flowControl.ratePerSecond)?.toString();
973
+ const period = typeof request.flowControl.period === "number" ? `${request.flowControl.period}s` : request.flowControl.period;
974
+ const controlValue = [
975
+ parallelism ? `parallelism=${parallelism}` : void 0,
976
+ rate ? `rate=${rate}` : void 0,
977
+ period ? `period=${period}` : void 0
978
+ ].filter(Boolean);
979
+ if (controlValue.length === 0) {
980
+ throw new QstashError(
981
+ "Provide at least one of parallelism or ratePerSecond for flowControl"
982
+ );
983
+ }
984
+ headers.set("Upstash-Flow-Control-Key", request.flowControl.key);
985
+ headers.set("Upstash-Flow-Control-Value", controlValue.join(", "));
986
+ }
987
+ if (request.label !== void 0) {
988
+ headers.set("Upstash-Label", request.label);
989
+ }
990
+ return await this.http.request({
991
+ method: "POST",
992
+ headers: wrapWithGlobalHeaders(headers, this.http.headers, this.http.telemetryHeaders),
993
+ path: ["v2", "schedules", request.destination],
994
+ body: request.body
995
+ });
996
+ }
997
+ /**
998
+ * Get a schedule
999
+ */
1000
+ async get(scheduleId) {
1001
+ const schedule = await this.http.request({
1002
+ method: "GET",
1003
+ path: ["v2", "schedules", scheduleId]
1004
+ });
1005
+ if ("rate" in schedule)
1006
+ schedule.ratePerSecond = schedule.rate;
1007
+ return schedule;
1008
+ }
1009
+ /**
1010
+ * List your schedules
1011
+ */
1012
+ async list() {
1013
+ const schedules = await this.http.request({
1014
+ method: "GET",
1015
+ path: ["v2", "schedules"]
1016
+ });
1017
+ for (const schedule of schedules) {
1018
+ if ("rate" in schedule)
1019
+ schedule.ratePerSecond = schedule.rate;
1020
+ }
1021
+ return schedules;
1022
+ }
1023
+ /**
1024
+ * Delete a schedule
1025
+ */
1026
+ async delete(scheduleId) {
1027
+ return await this.http.request({
1028
+ method: "DELETE",
1029
+ path: ["v2", "schedules", scheduleId],
1030
+ parseResponseAsJson: false
1031
+ });
1032
+ }
1033
+ /**
1034
+ * Pauses the schedule.
1035
+ *
1036
+ * A paused schedule will not deliver messages until
1037
+ * it is resumed.
1038
+ */
1039
+ async pause({ schedule }) {
1040
+ await this.http.request({
1041
+ method: "PATCH",
1042
+ path: ["v2", "schedules", schedule, "pause"],
1043
+ parseResponseAsJson: false
1044
+ });
1045
+ }
1046
+ /**
1047
+ * Resumes the schedule.
1048
+ */
1049
+ async resume({ schedule }) {
1050
+ await this.http.request({
1051
+ method: "PATCH",
1052
+ path: ["v2", "schedules", schedule, "resume"],
1053
+ parseResponseAsJson: false
1054
+ });
1055
+ }
1056
+ };
1057
+
1058
+ // src/client/url-groups.ts
1059
+ var UrlGroups = class {
1060
+ http;
1061
+ constructor(http) {
1062
+ this.http = http;
1063
+ }
1064
+ /**
1065
+ * Create a new url group with the given name and endpoints
1066
+ */
1067
+ async addEndpoints(request) {
1068
+ await this.http.request({
1069
+ method: "POST",
1070
+ path: ["v2", "topics", request.name, "endpoints"],
1071
+ headers: { "Content-Type": "application/json" },
1072
+ body: JSON.stringify({ endpoints: request.endpoints }),
1073
+ parseResponseAsJson: false
1074
+ });
1075
+ }
1076
+ /**
1077
+ * Remove endpoints from a url group.
1078
+ */
1079
+ async removeEndpoints(request) {
1080
+ await this.http.request({
1081
+ method: "DELETE",
1082
+ path: ["v2", "topics", request.name, "endpoints"],
1083
+ headers: { "Content-Type": "application/json" },
1084
+ body: JSON.stringify({ endpoints: request.endpoints }),
1085
+ parseResponseAsJson: false
1086
+ });
1087
+ }
1088
+ /**
1089
+ * Get a list of all url groups.
1090
+ */
1091
+ async list() {
1092
+ return await this.http.request({
1093
+ method: "GET",
1094
+ path: ["v2", "topics"]
1095
+ });
1096
+ }
1097
+ /**
1098
+ * Get a single url group
1099
+ */
1100
+ async get(name) {
1101
+ return await this.http.request({
1102
+ method: "GET",
1103
+ path: ["v2", "topics", name]
1104
+ });
1105
+ }
1106
+ /**
1107
+ * Delete a url group
1108
+ */
1109
+ async delete(name) {
1110
+ return await this.http.request({
1111
+ method: "DELETE",
1112
+ path: ["v2", "topics", name],
1113
+ parseResponseAsJson: false
1114
+ });
1115
+ }
1116
+ };
1117
+
1118
+ // version.ts
1119
+ var VERSION = "v2.8.4";
1120
+
1121
+ // src/client/client.ts
1122
+ var Client = class {
1123
+ http;
1124
+ token;
1125
+ constructor(config) {
1126
+ const environment = typeof process === "undefined" ? {} : process.env;
1127
+ let baseUrl = (config?.baseUrl ?? environment.QSTASH_URL ?? "https://qstash.upstash.io").replace(/\/$/, "");
1128
+ if (baseUrl === "https://qstash.upstash.io/v2/publish") {
1129
+ baseUrl = "https://qstash.upstash.io";
1130
+ }
1131
+ const token = config?.token ?? environment.QSTASH_TOKEN;
1132
+ const enableTelemetry = environment.UPSTASH_DISABLE_TELEMETRY ? false : config?.enableTelemetry ?? true;
1133
+ const isCloudflare = typeof caches !== "undefined" && "default" in caches;
1134
+ const telemetryHeaders = new Headers(
1135
+ enableTelemetry ? {
1136
+ "Upstash-Telemetry-Sdk": `upstash-qstash-js@${VERSION}`,
1137
+ "Upstash-Telemetry-Platform": isCloudflare ? "cloudflare" : environment.VERCEL ? "vercel" : environment.AWS_REGION ? "aws" : "",
1138
+ "Upstash-Telemetry-Runtime": getRuntime()
1139
+ } : {}
1140
+ );
1141
+ this.http = new HttpClient({
1142
+ retry: config?.retry,
1143
+ baseUrl,
1144
+ authorization: `Bearer ${token}`,
1145
+ //@ts-expect-error caused by undici and bunjs type overlap
1146
+ headers: prefixHeaders(new Headers(config?.headers ?? {})),
1147
+ //@ts-expect-error caused by undici and bunjs type overlap
1148
+ telemetryHeaders
1149
+ });
1150
+ if (!token) {
1151
+ console.warn(
1152
+ "[Upstash QStash] client token is not set. Either pass a token or set QSTASH_TOKEN env variable."
1153
+ );
1154
+ }
1155
+ this.token = token;
1156
+ }
1157
+ /**
1158
+ * Access the urlGroup API.
1159
+ *
1160
+ * Create, read, update or delete urlGroups.
1161
+ */
1162
+ get urlGroups() {
1163
+ return new UrlGroups(this.http);
1164
+ }
1165
+ /**
1166
+ * Deprecated. Use urlGroups instead.
1167
+ *
1168
+ * Access the topic API.
1169
+ *
1170
+ * Create, read, update or delete topics.
1171
+ */
1172
+ get topics() {
1173
+ return this.urlGroups;
1174
+ }
1175
+ /**
1176
+ * Access the dlq API.
1177
+ *
1178
+ * List or remove messages from the DLQ.
1179
+ */
1180
+ get dlq() {
1181
+ return new DLQ(this.http);
1182
+ }
1183
+ /**
1184
+ * Access the message API.
1185
+ *
1186
+ * Read or cancel messages.
1187
+ */
1188
+ get messages() {
1189
+ return new Messages(this.http);
1190
+ }
1191
+ /**
1192
+ * Access the schedule API.
1193
+ *
1194
+ * Create, read or delete schedules.
1195
+ */
1196
+ get schedules() {
1197
+ return new Schedules(this.http);
1198
+ }
1199
+ /**
1200
+ * Access the workflow API.
1201
+ *
1202
+ * cancel workflows.
1203
+ *
1204
+ * @deprecated as of version 2.7.17. Will be removed in qstash-js 3.0.0.
1205
+ * Please use @upstash/workflow instead https://github.com/upstash/workflow-js
1206
+ * Migration Guide: https://upstash.com/docs/workflow/migration
1207
+ */
1208
+ get workflow() {
1209
+ return new Workflow(this.http);
1210
+ }
1211
+ /**
1212
+ * Access the queue API.
1213
+ *
1214
+ * Create, read, update or delete queues.
1215
+ */
1216
+ queue(request) {
1217
+ return new Queue(this.http, request?.queueName);
1218
+ }
1219
+ /**
1220
+ * Access the Chat API.
1221
+ *
1222
+ * @deprecated This will be removed in qstash-js 3.0.0. Please use an alternative SDK for interacting with LLMs.
1223
+ *
1224
+ * Use the create or prompt methods.
1225
+ */
1226
+ chat() {
1227
+ return new Chat(this.http, this.token);
1228
+ }
1229
+ async publish(request) {
1230
+ const headers = wrapWithGlobalHeaders(
1231
+ processHeaders(request),
1232
+ this.http.headers,
1233
+ this.http.telemetryHeaders
1234
+ );
1235
+ const response = await this.http.request({
1236
+ path: ["v2", "publish", getRequestPath(request)],
1237
+ body: request.body,
1238
+ headers,
1239
+ method: "POST"
1240
+ });
1241
+ return response;
1242
+ }
1243
+ /**
1244
+ * publishJSON is a utility wrapper around `publish` that automatically serializes the body
1245
+ * and sets the `Content-Type` header to `application/json`.
1246
+ */
1247
+ async publishJSON(request) {
1248
+ const headers = prefixHeaders(new Headers(request.headers));
1249
+ headers.set("Content-Type", "application/json");
1250
+ const upstashToken = String(this.http.authorization).split("Bearer ")[1];
1251
+ const nonApiRequest = processApi(request, headers, upstashToken);
1252
+ const response = await this.publish({
1253
+ ...nonApiRequest,
1254
+ body: JSON.stringify(nonApiRequest.body)
1255
+ });
1256
+ return response;
1257
+ }
1258
+ /**
1259
+ * Batch publish messages to QStash.
1260
+ */
1261
+ async batch(request) {
1262
+ const messages = [];
1263
+ for (const message of request) {
1264
+ const headers = wrapWithGlobalHeaders(
1265
+ processHeaders(message),
1266
+ this.http.headers,
1267
+ this.http.telemetryHeaders
1268
+ );
1269
+ const headerEntries = Object.fromEntries(headers.entries());
1270
+ messages.push({
1271
+ destination: getRequestPath(message),
1272
+ headers: headerEntries,
1273
+ body: message.body,
1274
+ ...message.queueName && { queue: message.queueName }
1275
+ });
1276
+ }
1277
+ const response = await this.http.request({
1278
+ path: ["v2", "batch"],
1279
+ body: JSON.stringify(messages),
1280
+ headers: {
1281
+ "Content-Type": "application/json"
1282
+ },
1283
+ method: "POST"
1284
+ });
1285
+ const arrayResposne = Array.isArray(response) ? response : [response];
1286
+ return arrayResposne;
1287
+ }
1288
+ /**
1289
+ * Batch publish messages to QStash, serializing each body to JSON.
1290
+ */
1291
+ async batchJSON(request) {
1292
+ const batchPayload = request.map((message) => {
1293
+ if ("body" in message) {
1294
+ message.body = JSON.stringify(message.body);
1295
+ }
1296
+ const upstashToken = String(this.http.authorization).split("Bearer ")[1];
1297
+ const nonApiMessage = processApi(message, new Headers(message.headers), upstashToken);
1298
+ nonApiMessage.headers.set("Content-Type", "application/json");
1299
+ return nonApiMessage;
1300
+ });
1301
+ const response = await this.batch(batchPayload);
1302
+ return response;
1303
+ }
1304
+ /**
1305
+ * Retrieve your logs.
1306
+ *
1307
+ * The logs endpoint is paginated and returns only 100 logs at a time.
1308
+ * If you want to receive more logs, you can use the cursor to paginate.
1309
+ *
1310
+ * The cursor is a unix timestamp with millisecond precision
1311
+ *
1312
+ * @example
1313
+ * ```ts
1314
+ * let cursor = Date.now()
1315
+ * const logs: Log[] = []
1316
+ * while (cursor > 0) {
1317
+ * const res = await qstash.logs({ cursor })
1318
+ * logs.push(...res.logs)
1319
+ * cursor = res.cursor ?? 0
1320
+ * }
1321
+ * ```
1322
+ */
1323
+ async logs(request) {
1324
+ const query = {};
1325
+ if (typeof request?.cursor === "number" && request.cursor > 0) {
1326
+ query.cursor = request.cursor.toString();
1327
+ } else if (typeof request?.cursor === "string" && request.cursor !== "") {
1328
+ query.cursor = request.cursor;
1329
+ }
1330
+ for (const [key, value] of Object.entries(request?.filter ?? {})) {
1331
+ if (typeof value === "number" && value < 0) {
1332
+ continue;
1333
+ }
1334
+ if (key === "urlGroup") {
1335
+ query.topicName = value.toString();
1336
+ } else if (typeof value !== "undefined") {
1337
+ query[key] = value.toString();
1338
+ }
1339
+ }
1340
+ const responsePayload = await this.http.request({
1341
+ path: ["v2", "events"],
1342
+ method: "GET",
1343
+ query
1344
+ });
1345
+ const logs = responsePayload.events.map((event) => {
1346
+ return {
1347
+ ...event,
1348
+ urlGroup: event.topicName
1349
+ };
1350
+ });
1351
+ return {
1352
+ cursor: responsePayload.cursor,
1353
+ logs,
1354
+ events: logs
1355
+ };
1356
+ }
1357
+ /**
1358
+ * @deprecated Will be removed in the next major release. Use the `logs` method instead.
1359
+ *
1360
+ * Retrieve your logs.
1361
+ *
1362
+ * The logs endpoint is paginated and returns only 100 logs at a time.
1363
+ * If you want to receive more logs, you can use the cursor to paginate.
1364
+ *
1365
+ * The cursor is a unix timestamp with millisecond precision
1366
+ *
1367
+ * @example
1368
+ * ```ts
1369
+ * let cursor = Date.now()
1370
+ * const logs: Log[] = []
1371
+ * while (cursor > 0) {
1372
+ * const res = await qstash.logs({ cursor })
1373
+ * logs.push(...res.logs)
1374
+ * cursor = res.cursor ?? 0
1375
+ * }
1376
+ * ```
1377
+ */
1378
+ async events(request) {
1379
+ return await this.logs(request);
1380
+ }
1381
+ };
1382
+
1383
+ // src/client/workflow/index.ts
1384
+ var Workflow = class {
1385
+ http;
1386
+ constructor(http) {
1387
+ this.http = http;
1388
+ }
1389
+ /**
1390
+ * Cancel an ongoing workflow
1391
+ *
1392
+ * @param workflowRunId run id of the workflow to delete
1393
+ * @returns true if workflow is succesfully deleted. Otherwise throws QStashError
1394
+ */
1395
+ async cancel(workflowRunId) {
1396
+ const result = await this.http.request({
1397
+ path: ["v2", "workflows", "runs", `${workflowRunId}?cancel=true`],
1398
+ method: "DELETE",
1399
+ parseResponseAsJson: false
1400
+ });
1401
+ return result ?? true;
1402
+ }
1403
+ };
1404
+
1405
+ exports.BaseProvider = BaseProvider;
1406
+ exports.Chat = Chat;
1407
+ exports.Client = Client;
1408
+ exports.Messages = Messages;
1409
+ exports.QstashChatRatelimitError = QstashChatRatelimitError;
1410
+ exports.QstashDailyRatelimitError = QstashDailyRatelimitError;
1411
+ exports.QstashError = QstashError;
1412
+ exports.QstashRatelimitError = QstashRatelimitError;
1413
+ exports.Receiver = Receiver;
1414
+ exports.Schedules = Schedules;
1415
+ exports.SignatureError = SignatureError;
1416
+ exports.UrlGroups = UrlGroups;
1417
+ exports.Workflow = Workflow;
1418
+ exports.setupAnalytics = setupAnalytics;
1419
+ exports.upstash = upstash;