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