@windrun-huaiin/backend-core 14.6.0 → 15.1.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 (281) hide show
  1. package/dist/app/api/stripe/checkout/route.js +2 -2
  2. package/dist/app/api/stripe/checkout/route.mjs +1 -1
  3. package/dist/app/api/stripe/customer-portal/route.js +2 -2
  4. package/dist/app/api/stripe/customer-portal/route.mjs +1 -1
  5. package/dist/app/api/user/anonymous/init/route.js +6 -6
  6. package/dist/app/api/user/anonymous/init/route.mjs +1 -1
  7. package/dist/app/api/webhook/clerk/user/route.js +4 -4
  8. package/dist/app/api/webhook/clerk/user/route.mjs +1 -1
  9. package/dist/app/api/webhook/stripe/route.js +2 -2
  10. package/dist/app/api/webhook/stripe/route.mjs +1 -1
  11. package/dist/auth/auth-middleware.js +3 -3
  12. package/dist/auth/auth-middleware.mjs +1 -1
  13. package/dist/auth/auth-utils.js +10 -10
  14. package/dist/auth/auth-utils.mjs +1 -1
  15. package/dist/lib/money-price-helper.js +3 -3
  16. package/dist/lib/money-price-helper.mjs +1 -1
  17. package/dist/lib/stripe-config.js +8 -8
  18. package/dist/lib/stripe-config.mjs +1 -1
  19. package/dist/lib/upstash/qstash.js +12 -12
  20. package/dist/lib/upstash/qstash.mjs +2 -2
  21. package/dist/lib/upstash/redis-counter.js +7 -7
  22. package/dist/lib/upstash/redis-counter.mjs +1 -1
  23. package/dist/lib/upstash/redis-favorite.js +9 -9
  24. package/dist/lib/upstash/redis-favorite.mjs +1 -1
  25. package/dist/lib/upstash/redis-like.js +9 -9
  26. package/dist/lib/upstash/redis-like.mjs +1 -1
  27. package/dist/lib/upstash/redis-lock.js +6 -6
  28. package/dist/lib/upstash/redis-lock.mjs +1 -1
  29. package/dist/lib/upstash/redis-structures.js +25 -25
  30. package/dist/lib/upstash/redis-structures.mjs +1 -1
  31. package/dist/lib/upstash-config.js +14 -14
  32. package/dist/lib/upstash-config.mjs +4 -4
  33. package/dist/prisma/prisma-transaction-util.js +2 -2
  34. package/dist/prisma/prisma-transaction-util.mjs +1 -1
  35. package/dist/services/aggregate/anonymous.aggregate.service.js +6 -6
  36. package/dist/services/aggregate/anonymous.aggregate.service.mjs +1 -1
  37. package/dist/services/aggregate/billing.aggregate.service.js +21 -21
  38. package/dist/services/aggregate/billing.aggregate.service.mjs +1 -1
  39. package/dist/services/aggregate/user.aggregate.service.js +10 -10
  40. package/dist/services/aggregate/user.aggregate.service.mjs +1 -1
  41. package/dist/services/context/user-context-service.js +3 -3
  42. package/dist/services/context/user-context-service.mjs +1 -1
  43. package/dist/services/database/apilog.service.js +14 -14
  44. package/dist/services/database/apilog.service.mjs +1 -1
  45. package/dist/services/database/credit.service.js +20 -20
  46. package/dist/services/database/credit.service.mjs +1 -1
  47. package/dist/services/database/creditAuditLog.service.js +13 -13
  48. package/dist/services/database/creditAuditLog.service.mjs +1 -1
  49. package/dist/services/database/subscription.service.js +16 -16
  50. package/dist/services/database/subscription.service.mjs +1 -1
  51. package/dist/services/database/transaction.service.js +18 -18
  52. package/dist/services/database/transaction.service.mjs +1 -1
  53. package/dist/services/database/user.service.js +14 -14
  54. package/dist/services/database/user.service.mjs +1 -1
  55. package/dist/services/database/userBackup.service.js +15 -15
  56. package/dist/services/database/userBackup.service.mjs +1 -1
  57. package/dist/services/stripe/webhook-handler.js +13 -13
  58. package/dist/services/stripe/webhook-handler.mjs +3 -3
  59. package/package.json +6 -3
  60. package/dist/_virtual/_commonjs-dynamic-modules.js +0 -7
  61. package/dist/_virtual/_commonjs-dynamic-modules.mjs +0 -5
  62. package/dist/_virtual/_commonjsHelpers.js +0 -10
  63. package/dist/_virtual/_commonjsHelpers.mjs +0 -7
  64. package/dist/_virtual/aes.js +0 -5
  65. package/dist/_virtual/aes.mjs +0 -3
  66. package/dist/_virtual/blowfish.js +0 -5
  67. package/dist/_virtual/blowfish.mjs +0 -3
  68. package/dist/_virtual/cipher-core.js +0 -5
  69. package/dist/_virtual/cipher-core.mjs +0 -3
  70. package/dist/_virtual/core.js +0 -5
  71. package/dist/_virtual/core.mjs +0 -3
  72. package/dist/_virtual/enc-base64.js +0 -5
  73. package/dist/_virtual/enc-base64.mjs +0 -3
  74. package/dist/_virtual/enc-base64url.js +0 -5
  75. package/dist/_virtual/enc-base64url.mjs +0 -3
  76. package/dist/_virtual/enc-utf16.js +0 -5
  77. package/dist/_virtual/enc-utf16.mjs +0 -3
  78. package/dist/_virtual/evpkdf.js +0 -5
  79. package/dist/_virtual/evpkdf.mjs +0 -3
  80. package/dist/_virtual/format-hex.js +0 -5
  81. package/dist/_virtual/format-hex.mjs +0 -3
  82. package/dist/_virtual/hmac.js +0 -5
  83. package/dist/_virtual/hmac.mjs +0 -3
  84. package/dist/_virtual/index.js +0 -11
  85. package/dist/_virtual/index.mjs +0 -7
  86. package/dist/_virtual/index2.js +0 -5
  87. package/dist/_virtual/index2.mjs +0 -3
  88. package/dist/_virtual/lib-typedarrays.js +0 -5
  89. package/dist/_virtual/lib-typedarrays.mjs +0 -3
  90. package/dist/_virtual/md5.js +0 -5
  91. package/dist/_virtual/md5.mjs +0 -3
  92. package/dist/_virtual/mode-cfb.js +0 -5
  93. package/dist/_virtual/mode-cfb.mjs +0 -3
  94. package/dist/_virtual/mode-ctr-gladman.js +0 -5
  95. package/dist/_virtual/mode-ctr-gladman.mjs +0 -3
  96. package/dist/_virtual/mode-ctr.js +0 -5
  97. package/dist/_virtual/mode-ctr.mjs +0 -3
  98. package/dist/_virtual/mode-ecb.js +0 -5
  99. package/dist/_virtual/mode-ecb.mjs +0 -3
  100. package/dist/_virtual/mode-ofb.js +0 -5
  101. package/dist/_virtual/mode-ofb.mjs +0 -3
  102. package/dist/_virtual/pad-ansix923.js +0 -5
  103. package/dist/_virtual/pad-ansix923.mjs +0 -3
  104. package/dist/_virtual/pad-iso10126.js +0 -5
  105. package/dist/_virtual/pad-iso10126.mjs +0 -3
  106. package/dist/_virtual/pad-iso97971.js +0 -5
  107. package/dist/_virtual/pad-iso97971.mjs +0 -3
  108. package/dist/_virtual/pad-nopadding.js +0 -5
  109. package/dist/_virtual/pad-nopadding.mjs +0 -3
  110. package/dist/_virtual/pad-zeropadding.js +0 -5
  111. package/dist/_virtual/pad-zeropadding.mjs +0 -3
  112. package/dist/_virtual/pbkdf2.js +0 -5
  113. package/dist/_virtual/pbkdf2.mjs +0 -3
  114. package/dist/_virtual/rabbit-legacy.js +0 -5
  115. package/dist/_virtual/rabbit-legacy.mjs +0 -3
  116. package/dist/_virtual/rabbit.js +0 -5
  117. package/dist/_virtual/rabbit.mjs +0 -3
  118. package/dist/_virtual/rc4.js +0 -5
  119. package/dist/_virtual/rc4.mjs +0 -3
  120. package/dist/_virtual/ripemd160.js +0 -5
  121. package/dist/_virtual/ripemd160.mjs +0 -3
  122. package/dist/_virtual/sha1.js +0 -5
  123. package/dist/_virtual/sha1.mjs +0 -3
  124. package/dist/_virtual/sha224.js +0 -5
  125. package/dist/_virtual/sha224.mjs +0 -3
  126. package/dist/_virtual/sha256.js +0 -5
  127. package/dist/_virtual/sha256.mjs +0 -3
  128. package/dist/_virtual/sha3.js +0 -5
  129. package/dist/_virtual/sha3.mjs +0 -3
  130. package/dist/_virtual/sha384.js +0 -5
  131. package/dist/_virtual/sha384.mjs +0 -3
  132. package/dist/_virtual/sha512.js +0 -5
  133. package/dist/_virtual/sha512.mjs +0 -3
  134. package/dist/_virtual/tripledes.js +0 -5
  135. package/dist/_virtual/tripledes.mjs +0 -3
  136. package/dist/_virtual/x64-core.js +0 -5
  137. package/dist/_virtual/x64-core.mjs +0 -3
  138. package/dist/node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.js +0 -48
  139. package/dist/node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.mjs +0 -45
  140. package/dist/node_modules/.pnpm/@upstash_qstash@2.10.1/node_modules/@upstash/qstash/chunk-35B33QW3.js +0 -1848
  141. package/dist/node_modules/.pnpm/@upstash_qstash@2.10.1/node_modules/@upstash/qstash/chunk-35B33QW3.mjs +0 -1830
  142. package/dist/node_modules/.pnpm/@upstash_redis@1.37.0/node_modules/@upstash/redis/chunk-IH7W44G6.js +0 -5308
  143. package/dist/node_modules/.pnpm/@upstash_redis@1.37.0/node_modules/@upstash/redis/chunk-IH7W44G6.mjs +0 -5302
  144. package/dist/node_modules/.pnpm/@upstash_redis@1.37.0/node_modules/@upstash/redis/nodejs.js +0 -116
  145. package/dist/node_modules/.pnpm/@upstash_redis@1.37.0/node_modules/@upstash/redis/nodejs.mjs +0 -113
  146. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/aes.js +0 -248
  147. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/aes.mjs +0 -246
  148. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/blowfish.js +0 -485
  149. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/blowfish.mjs +0 -483
  150. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/cipher-core.js +0 -906
  151. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/cipher-core.mjs +0 -904
  152. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/core.js +0 -818
  153. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/core.mjs +0 -816
  154. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/enc-base64.js +0 -146
  155. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/enc-base64.mjs +0 -144
  156. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/enc-base64url.js +0 -158
  157. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/enc-base64url.mjs +0 -156
  158. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/enc-utf16.js +0 -159
  159. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/enc-utf16.mjs +0 -157
  160. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/evpkdf.js +0 -146
  161. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/evpkdf.mjs +0 -144
  162. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/format-hex.js +0 -77
  163. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/format-hex.mjs +0 -75
  164. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/hmac.js +0 -153
  165. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/hmac.mjs +0 -151
  166. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/index.js +0 -62
  167. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/index.mjs +0 -60
  168. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/lib-typedarrays.js +0 -86
  169. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/lib-typedarrays.mjs +0 -84
  170. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/md5.js +0 -278
  171. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/md5.mjs +0 -276
  172. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-cfb.js +0 -91
  173. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-cfb.mjs +0 -89
  174. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ctr-gladman.js +0 -127
  175. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ctr-gladman.mjs +0 -125
  176. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ctr.js +0 -69
  177. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ctr.mjs +0 -67
  178. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ecb.js +0 -51
  179. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ecb.mjs +0 -49
  180. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ofb.js +0 -65
  181. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ofb.mjs +0 -63
  182. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-ansix923.js +0 -60
  183. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-ansix923.mjs +0 -58
  184. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-iso10126.js +0 -55
  185. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-iso10126.mjs +0 -53
  186. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-iso97971.js +0 -51
  187. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-iso97971.mjs +0 -49
  188. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-nopadding.js +0 -41
  189. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-nopadding.mjs +0 -39
  190. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-zeropadding.js +0 -58
  191. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-zeropadding.mjs +0 -56
  192. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pbkdf2.js +0 -157
  193. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pbkdf2.mjs +0 -155
  194. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/rabbit-legacy.js +0 -204
  195. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/rabbit-legacy.mjs +0 -202
  196. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/rabbit.js +0 -206
  197. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/rabbit.mjs +0 -204
  198. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/rc4.js +0 -153
  199. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/rc4.mjs +0 -151
  200. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/ripemd160.js +0 -277
  201. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/ripemd160.mjs +0 -275
  202. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha1.js +0 -160
  203. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha1.mjs +0 -158
  204. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha224.js +0 -91
  205. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha224.mjs +0 -89
  206. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha256.js +0 -209
  207. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha256.mjs +0 -207
  208. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha3.js +0 -337
  209. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha3.mjs +0 -335
  210. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha384.js +0 -95
  211. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha384.mjs +0 -93
  212. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha512.js +0 -337
  213. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha512.mjs +0 -335
  214. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/tripledes.js +0 -793
  215. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/tripledes.mjs +0 -791
  216. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/x64-core.js +0 -314
  217. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/x64-core.mjs +0 -312
  218. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jws/compact/verify.js +0 -26
  219. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jws/compact/verify.mjs +0 -24
  220. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jws/flattened/verify.js +0 -127
  221. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jws/flattened/verify.mjs +0 -125
  222. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwt/verify.js +0 -20
  223. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwt/verify.mjs +0 -18
  224. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/key/import.js +0 -31
  225. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/key/import.mjs +0 -29
  226. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/buffer_utils.js +0 -18
  227. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/buffer_utils.mjs +0 -14
  228. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/check_key_type.js +0 -82
  229. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/check_key_type.mjs +0 -80
  230. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/crypto_key.js +0 -103
  231. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/crypto_key.mjs +0 -101
  232. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/epoch.js +0 -7
  233. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/epoch.mjs +0 -3
  234. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/invalid_key_input.js +0 -38
  235. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/invalid_key_input.mjs +0 -33
  236. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_disjoint.js +0 -27
  237. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_disjoint.mjs +0 -23
  238. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_jwk.js +0 -21
  239. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_jwk.mjs +0 -16
  240. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_object.js +0 -22
  241. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_object.mjs +0 -18
  242. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/jwt_claims_set.js +0 -111
  243. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/jwt_claims_set.mjs +0 -107
  244. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/secs.js +0 -61
  245. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/secs.mjs +0 -57
  246. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/validate_algorithms.js +0 -16
  247. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/validate_algorithms.mjs +0 -12
  248. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/validate_crit.js +0 -40
  249. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/validate_crit.mjs +0 -36
  250. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/base64url.js +0 -15
  251. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/base64url.mjs +0 -13
  252. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/check_key_length.js +0 -23
  253. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/check_key_length.mjs +0 -19
  254. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/dsa_digest.js +0 -30
  255. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/dsa_digest.mjs +0 -26
  256. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/get_named_curve.js +0 -60
  257. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/get_named_curve.mjs +0 -56
  258. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/get_sign_verify_key.js +0 -35
  259. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/get_sign_verify_key.mjs +0 -31
  260. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/hmac_digest.js +0 -20
  261. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/hmac_digest.mjs +0 -16
  262. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/is_key_like.js +0 -15
  263. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/is_key_like.mjs +0 -10
  264. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/is_key_object.js +0 -28
  265. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/is_key_object.mjs +0 -5
  266. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/jwk_to_key.js +0 -14
  267. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/jwk_to_key.mjs +0 -10
  268. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/node_key.js +0 -115
  269. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/node_key.mjs +0 -111
  270. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/sign.js +0 -42
  271. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/sign.mjs +0 -19
  272. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/verify.js +0 -54
  273. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/verify.mjs +0 -31
  274. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/webcrypto.js +0 -32
  275. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/webcrypto.mjs +0 -7
  276. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/util/errors.js +0 -69
  277. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/util/errors.mjs +0 -60
  278. package/dist/node_modules/.pnpm/neverthrow@7.2.0/node_modules/neverthrow/dist/index.es.js +0 -422
  279. package/dist/node_modules/.pnpm/neverthrow@7.2.0/node_modules/neverthrow/dist/index.es.mjs +0 -415
  280. package/dist/node_modules/.pnpm/uncrypto@0.1.3/node_modules/uncrypto/dist/crypto.web.js +0 -6
  281. package/dist/node_modules/.pnpm/uncrypto@0.1.3/node_modules/uncrypto/dist/crypto.web.mjs +0 -4
@@ -1,1830 +0,0 @@
1
- import crypto2 from '../../../../../../_virtual/index.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
-
7
- // src/client/api/base.ts
8
- var BaseProvider = class {
9
- baseUrl;
10
- token;
11
- owner;
12
- constructor(baseUrl, token, owner) {
13
- this.baseUrl = baseUrl;
14
- this.token = token;
15
- this.owner = owner;
16
- }
17
- getUrl() {
18
- return `${this.baseUrl}/${this.getRoute().join("/")}`;
19
- }
20
- };
21
-
22
- // src/client/api/llm.ts
23
- var LLMProvider = class extends BaseProvider {
24
- apiKind = "llm";
25
- organization;
26
- method = "POST";
27
- constructor(baseUrl, token, owner, organization) {
28
- super(baseUrl, token, owner);
29
- this.organization = organization;
30
- }
31
- getRoute() {
32
- return this.owner === "anthropic" ? ["v1", "messages"] : ["v1", "chat", "completions"];
33
- }
34
- getHeaders(options) {
35
- if (this.owner === "upstash" && !options.analytics) {
36
- return { "content-type": "application/json" };
37
- }
38
- const header = this.owner === "anthropic" ? "x-api-key" : "authorization";
39
- const headerValue = this.owner === "anthropic" ? this.token : `Bearer ${this.token}`;
40
- const headers = {
41
- [header]: headerValue,
42
- "content-type": "application/json"
43
- };
44
- if (this.owner === "openai" && this.organization) {
45
- headers["OpenAI-Organization"] = this.organization;
46
- }
47
- if (this.owner === "anthropic") {
48
- headers["anthropic-version"] = "2023-06-01";
49
- }
50
- return headers;
51
- }
52
- /**
53
- * Checks if callback exists and adds analytics in place if it's set.
54
- *
55
- * @param request
56
- * @param options
57
- */
58
- onFinish(providerInfo, options) {
59
- if (options.analytics) {
60
- return updateWithAnalytics(providerInfo, options.analytics);
61
- }
62
- return providerInfo;
63
- }
64
- };
65
- var upstash = () => {
66
- return new LLMProvider("https://qstash.upstash.io/llm", "", "upstash");
67
- };
68
-
69
- // src/client/api/utils.ts
70
- var getProviderInfo = (api, upstashToken) => {
71
- const { name, provider, ...parameters } = api;
72
- const finalProvider = provider ?? upstash();
73
- if (finalProvider.owner === "upstash" && !finalProvider.token) {
74
- finalProvider.token = upstashToken;
75
- }
76
- if (!finalProvider.baseUrl)
77
- throw new TypeError("baseUrl cannot be empty or undefined!");
78
- if (!finalProvider.token)
79
- throw new TypeError("token cannot be empty or undefined!");
80
- if (finalProvider.apiKind !== name) {
81
- throw new TypeError(
82
- `Unexpected api name. Expected '${finalProvider.apiKind}', received ${name}`
83
- );
84
- }
85
- const providerInfo = {
86
- url: finalProvider.getUrl(),
87
- baseUrl: finalProvider.baseUrl,
88
- route: finalProvider.getRoute(),
89
- appendHeaders: finalProvider.getHeaders(parameters),
90
- owner: finalProvider.owner,
91
- method: finalProvider.method
92
- };
93
- return finalProvider.onFinish(providerInfo, parameters);
94
- };
95
- var safeJoinHeaders = (headers, record) => {
96
- const joinedHeaders = new Headers(record);
97
- for (const [header, value] of headers.entries()) {
98
- joinedHeaders.set(header, value);
99
- }
100
- return joinedHeaders;
101
- };
102
- var processApi = (request, headers, upstashToken) => {
103
- if (!request.api) {
104
- request.headers = headers;
105
- return request;
106
- }
107
- const { url, appendHeaders, owner, method } = getProviderInfo(request.api, upstashToken);
108
- if (request.api.name === "llm") {
109
- const callback = request.callback;
110
- if (!callback) {
111
- throw new TypeError("Callback cannot be undefined when using LLM api.");
112
- }
113
- return {
114
- ...request,
115
- method: request.method ?? method,
116
- headers: safeJoinHeaders(headers, appendHeaders),
117
- ...owner === "upstash" && !request.api.analytics ? { api: { name: "llm" }, url: void 0, callback } : { url, api: void 0 }
118
- };
119
- } else {
120
- return {
121
- ...request,
122
- method: request.method ?? method,
123
- headers: safeJoinHeaders(headers, appendHeaders),
124
- url,
125
- api: void 0
126
- };
127
- }
128
- };
129
- function updateWithAnalytics(providerInfo, analytics) {
130
- switch (analytics.name) {
131
- case "helicone": {
132
- providerInfo.appendHeaders["Helicone-Auth"] = `Bearer ${analytics.token}`;
133
- if (providerInfo.owner === "upstash") {
134
- updateProviderInfo(providerInfo, "https://qstash.helicone.ai", [
135
- "llm",
136
- ...providerInfo.route
137
- ]);
138
- } else {
139
- providerInfo.appendHeaders["Helicone-Target-Url"] = providerInfo.baseUrl;
140
- updateProviderInfo(providerInfo, "https://gateway.helicone.ai", providerInfo.route);
141
- }
142
- return providerInfo;
143
- }
144
- default: {
145
- throw new Error("Unknown analytics provider");
146
- }
147
- }
148
- }
149
- function updateProviderInfo(providerInfo, baseUrl, route) {
150
- providerInfo.baseUrl = baseUrl;
151
- providerInfo.route = route;
152
- providerInfo.url = `${baseUrl}/${route.join("/")}`;
153
- }
154
-
155
- // src/client/error.ts
156
- var RATELIMIT_STATUS = 429;
157
- var QstashError = class extends Error {
158
- status;
159
- constructor(message, status) {
160
- super(message);
161
- this.name = "QstashError";
162
- this.status = status;
163
- }
164
- };
165
- var QstashRatelimitError = class extends QstashError {
166
- limit;
167
- remaining;
168
- reset;
169
- constructor(args) {
170
- super(`Exceeded burst rate limit. ${JSON.stringify(args)}`, RATELIMIT_STATUS);
171
- this.name = "QstashRatelimitError";
172
- this.limit = args.limit;
173
- this.remaining = args.remaining;
174
- this.reset = args.reset;
175
- }
176
- };
177
- var QstashChatRatelimitError = class extends QstashError {
178
- limitRequests;
179
- limitTokens;
180
- remainingRequests;
181
- remainingTokens;
182
- resetRequests;
183
- resetTokens;
184
- constructor(args) {
185
- super(`Exceeded chat rate limit. ${JSON.stringify(args)}`, RATELIMIT_STATUS);
186
- this.name = "QstashChatRatelimitError";
187
- this.limitRequests = args["limit-requests"];
188
- this.limitTokens = args["limit-tokens"];
189
- this.remainingRequests = args["remaining-requests"];
190
- this.remainingTokens = args["remaining-tokens"];
191
- this.resetRequests = args["reset-requests"];
192
- this.resetTokens = args["reset-tokens"];
193
- }
194
- };
195
- var QstashDailyRatelimitError = class extends QstashError {
196
- limit;
197
- remaining;
198
- reset;
199
- constructor(args) {
200
- super(`Exceeded daily rate limit. ${JSON.stringify(args)}`, RATELIMIT_STATUS);
201
- this.name = "QstashDailyRatelimitError";
202
- this.limit = args.limit;
203
- this.remaining = args.remaining;
204
- this.reset = args.reset;
205
- }
206
- };
207
- var QstashEmptyArrayError = class extends QstashError {
208
- constructor(parameterName) {
209
- super(
210
- `Empty array provided for query parameter "${parameterName}". This would result in no filter being applied, which could affect all resources.`
211
- );
212
- this.name = "QstashEmptyArrayError";
213
- }
214
- };
215
-
216
- // src/client/utils.ts
217
- var DEFAULT_BULK_COUNT = 100;
218
- var isIgnoredHeader = (header) => {
219
- const lowerCaseHeader = header.toLowerCase();
220
- return lowerCaseHeader.startsWith("content-type") || lowerCaseHeader.startsWith("upstash-");
221
- };
222
- function prefixHeaders(headers) {
223
- const keysToBePrefixed = [...headers.keys()].filter((key) => !isIgnoredHeader(key));
224
- for (const key of keysToBePrefixed) {
225
- const value = headers.get(key);
226
- if (value !== null) {
227
- headers.set(`Upstash-Forward-${key}`, value);
228
- }
229
- headers.delete(key);
230
- }
231
- return headers;
232
- }
233
- function wrapWithGlobalHeaders(headers, globalHeaders, telemetryHeaders) {
234
- if (!globalHeaders) {
235
- return headers;
236
- }
237
- const finalHeaders = new Headers(globalHeaders);
238
- headers.forEach((value, key) => {
239
- finalHeaders.set(key, value);
240
- });
241
- telemetryHeaders?.forEach((value, key) => {
242
- if (!value)
243
- return;
244
- finalHeaders.append(key, value);
245
- });
246
- return finalHeaders;
247
- }
248
- function processHeaders(request) {
249
- const headers = prefixHeaders(new Headers(request.headers));
250
- headers.set("Upstash-Method", request.method ?? "POST");
251
- if (request.delay !== void 0) {
252
- if (typeof request.delay === "string") {
253
- headers.set("Upstash-Delay", request.delay);
254
- } else {
255
- headers.set("Upstash-Delay", `${request.delay.toFixed(0)}s`);
256
- }
257
- }
258
- if (request.notBefore !== void 0) {
259
- headers.set("Upstash-Not-Before", request.notBefore.toFixed(0));
260
- }
261
- if (request.deduplicationId !== void 0) {
262
- headers.set("Upstash-Deduplication-Id", request.deduplicationId);
263
- }
264
- if (request.contentBasedDeduplication) {
265
- headers.set("Upstash-Content-Based-Deduplication", "true");
266
- }
267
- if (request.retries !== void 0) {
268
- headers.set("Upstash-Retries", request.retries.toFixed(0));
269
- }
270
- if (request.retryDelay !== void 0) {
271
- headers.set("Upstash-Retry-Delay", request.retryDelay);
272
- }
273
- if (request.callback !== void 0) {
274
- headers.set("Upstash-Callback", request.callback);
275
- }
276
- if (request.failureCallback !== void 0) {
277
- headers.set("Upstash-Failure-Callback", request.failureCallback);
278
- }
279
- if (request.timeout !== void 0) {
280
- if (typeof request.timeout === "string") {
281
- headers.set("Upstash-Timeout", request.timeout);
282
- } else {
283
- headers.set("Upstash-Timeout", `${request.timeout}s`);
284
- }
285
- }
286
- if (request.flowControl?.key) {
287
- const parallelism = request.flowControl.parallelism?.toString();
288
- const rate = (request.flowControl.rate ?? request.flowControl.ratePerSecond)?.toString();
289
- const period = typeof request.flowControl.period === "number" ? `${request.flowControl.period}s` : request.flowControl.period;
290
- const controlValue = [
291
- parallelism ? `parallelism=${parallelism}` : void 0,
292
- rate ? `rate=${rate}` : void 0,
293
- period ? `period=${period}` : void 0
294
- ].filter(Boolean);
295
- if (controlValue.length === 0) {
296
- throw new QstashError("Provide at least one of parallelism or ratePerSecond for flowControl");
297
- }
298
- headers.set("Upstash-Flow-Control-Key", request.flowControl.key);
299
- headers.set("Upstash-Flow-Control-Value", controlValue.join(", "));
300
- }
301
- if (request.label !== void 0) {
302
- headers.set("Upstash-Label", request.label);
303
- }
304
- if (request.redact !== void 0) {
305
- const redactParts = [];
306
- if (request.redact.body) {
307
- redactParts.push("body");
308
- }
309
- if (request.redact.header !== void 0) {
310
- if (request.redact.header === true) {
311
- redactParts.push("header");
312
- } else if (Array.isArray(request.redact.header) && request.redact.header.length > 0) {
313
- for (const headerName of request.redact.header) {
314
- redactParts.push(`header[${headerName}]`);
315
- }
316
- }
317
- }
318
- if (redactParts.length > 0) {
319
- headers.set("Upstash-Redact-Fields", redactParts.join(","));
320
- }
321
- }
322
- return headers;
323
- }
324
- function getRequestPath(request) {
325
- const nonApiPath = request.url ?? request.urlGroup ?? request.topic;
326
- if (nonApiPath)
327
- return nonApiPath;
328
- if (request.api?.name === "llm")
329
- return `api/llm`;
330
- if (request.api?.name === "email") {
331
- const providerInfo = getProviderInfo(request.api, "not-needed");
332
- return providerInfo.baseUrl;
333
- }
334
- throw new QstashError(`Failed to infer request path for ${JSON.stringify(request)}`);
335
- }
336
- function buildBulkActionFilterPayload(request) {
337
- const cursor = "cursor" in request ? request.cursor : void 0;
338
- if ("all" in request) {
339
- const count2 = "count" in request ? request.count ?? DEFAULT_BULK_COUNT : DEFAULT_BULK_COUNT;
340
- return { count: count2, cursor };
341
- }
342
- if ("dlqIds" in request) {
343
- const ids = request.dlqIds;
344
- if (Array.isArray(ids) && ids.length === 0) {
345
- throw new QstashError(
346
- "Empty dlqIds array provided. If you intend to target all DLQ messages, use { all: true } explicitly."
347
- );
348
- }
349
- return { dlqIds: ids, cursor };
350
- }
351
- if ("messageIds" in request && request.messageIds) {
352
- if (request.messageIds.length === 0) {
353
- throw new QstashError(
354
- "Empty messageIds array provided. If you intend to target all messages, use { all: true } explicitly."
355
- );
356
- }
357
- return { messageIds: request.messageIds, cursor };
358
- }
359
- const count = "count" in request ? request.count ?? DEFAULT_BULK_COUNT : DEFAULT_BULK_COUNT;
360
- return {
361
- ...renameUrlGroup(request.filter),
362
- count,
363
- cursor
364
- };
365
- }
366
- function renameUrlGroup(filter) {
367
- const { urlGroup, api, ...rest } = filter;
368
- return { ...rest, ...urlGroup === void 0 ? {} : { topicName: urlGroup } };
369
- }
370
- function normalizeCursor(response) {
371
- const cursor = response.cursor;
372
- return { ...response, cursor: cursor || void 0 };
373
- }
374
- function getRuntime() {
375
- if (typeof process === "object" && typeof process.versions == "object" && process.versions.bun)
376
- return `bun@${process.versions.bun}`;
377
- if (typeof EdgeRuntime === "string")
378
- return "edge-light";
379
- else if (typeof process === "object" && typeof process.version === "string")
380
- return `node@${process.version}`;
381
- return "";
382
- }
383
- function getSafeEnvironment() {
384
- return typeof process === "undefined" ? {} : process.env;
385
- }
386
-
387
- // src/client/multi-region/utils.ts
388
- var VALID_REGIONS = ["EU_CENTRAL_1", "US_EAST_1"];
389
- var DEFAULT_QSTASH_URL = "https://qstash.upstash.io";
390
- var getRegionFromEnvironment = (environment) => {
391
- const region = environment.QSTASH_REGION;
392
- return normalizeRegionHeader(region);
393
- };
394
- function readEnvironmentVariables(environmentVariables, environment, region) {
395
- const result = {};
396
- for (const variable of environmentVariables) {
397
- const key = region ? `${region}_${variable}` : variable;
398
- result[variable] = environment[key];
399
- }
400
- return result;
401
- }
402
- function readClientEnvironmentVariables(environment, region) {
403
- return readEnvironmentVariables(["QSTASH_URL", "QSTASH_TOKEN"], environment, region);
404
- }
405
- function readReceiverEnvironmentVariables(environment, region) {
406
- return readEnvironmentVariables(
407
- ["QSTASH_CURRENT_SIGNING_KEY", "QSTASH_NEXT_SIGNING_KEY"],
408
- environment,
409
- region
410
- );
411
- }
412
- function normalizeRegionHeader(region) {
413
- if (!region) {
414
- return void 0;
415
- }
416
- region = region.replaceAll("-", "_").toUpperCase();
417
- if (VALID_REGIONS.includes(region)) {
418
- return region;
419
- }
420
- console.warn(
421
- `[Upstash QStash] Invalid UPSTASH_REGION header value: "${region}". Expected one of: ${VALID_REGIONS.join(
422
- ", "
423
- )}.`
424
- );
425
- return void 0;
426
- }
427
-
428
- // src/client/multi-region/incoming.ts
429
- var getReceiverSigningKeys = ({
430
- environment,
431
- regionFromHeader,
432
- config
433
- }) => {
434
- if (config?.currentSigningKey && config.nextSigningKey) {
435
- return {
436
- currentSigningKey: config.currentSigningKey,
437
- nextSigningKey: config.nextSigningKey
438
- };
439
- }
440
- const regionEnvironment = getRegionFromEnvironment(environment);
441
- if (regionEnvironment) {
442
- const regionHeader = normalizeRegionHeader(regionFromHeader);
443
- if (regionHeader) {
444
- const regionCreds = readReceiverEnvironmentVariables(environment, regionHeader);
445
- if (regionCreds.QSTASH_CURRENT_SIGNING_KEY && regionCreds.QSTASH_NEXT_SIGNING_KEY) {
446
- return {
447
- currentSigningKey: regionCreds.QSTASH_CURRENT_SIGNING_KEY,
448
- nextSigningKey: regionCreds.QSTASH_NEXT_SIGNING_KEY,
449
- region: regionHeader
450
- };
451
- } else {
452
- console.warn(
453
- `[Upstash QStash] Signing keys not found for region "${regionHeader}". Falling back to default signing keys.`
454
- );
455
- }
456
- } else {
457
- console.warn(
458
- `[Upstash QStash] Invalid UPSTASH_REGION header value: "${regionFromHeader}". Expected one of: EU-CENTRAL-1, US-EAST-1. Falling back to default signing keys.`
459
- );
460
- }
461
- }
462
- const defaultCreds = readReceiverEnvironmentVariables(environment);
463
- if (defaultCreds.QSTASH_CURRENT_SIGNING_KEY && defaultCreds.QSTASH_NEXT_SIGNING_KEY) {
464
- return {
465
- currentSigningKey: defaultCreds.QSTASH_CURRENT_SIGNING_KEY,
466
- nextSigningKey: defaultCreds.QSTASH_NEXT_SIGNING_KEY
467
- };
468
- }
469
- };
470
-
471
- // src/client/multi-region/outgoing.ts
472
- var getClientCredentials = (clientCredentialConfig) => {
473
- const credentials = resolveCredentials(clientCredentialConfig);
474
- return verifyCredentials(credentials);
475
- };
476
- var resolveCredentials = ({
477
- environment,
478
- config
479
- }) => {
480
- if (config?.baseUrl && config.token) {
481
- return {
482
- baseUrl: config.baseUrl,
483
- token: config.token
484
- };
485
- }
486
- const region = getRegionFromEnvironment(environment);
487
- if (region) {
488
- const regionCreds = readClientEnvironmentVariables(environment, region);
489
- if (regionCreds.QSTASH_URL && regionCreds.QSTASH_TOKEN) {
490
- return {
491
- baseUrl: regionCreds.QSTASH_URL,
492
- token: regionCreds.QSTASH_TOKEN,
493
- region
494
- };
495
- } else {
496
- console.warn(
497
- `[Upstash QStash] QSTASH_REGION is set to "${region}" but credentials are missing. Expected ${region}_QSTASH_URL and ${region}_QSTASH_TOKEN. Falling back to default credentials.`
498
- );
499
- }
500
- }
501
- const defaultCreds = readClientEnvironmentVariables(environment);
502
- return {
503
- baseUrl: config?.baseUrl ?? defaultCreds.QSTASH_URL ?? DEFAULT_QSTASH_URL,
504
- token: config?.token ?? defaultCreds.QSTASH_TOKEN ?? ""
505
- };
506
- };
507
- var verifyCredentials = (credentials) => {
508
- const token = credentials.token;
509
- let baseUrl = credentials.baseUrl;
510
- baseUrl = baseUrl.replace(/\/$/, "");
511
- if (baseUrl === "https://qstash.upstash.io/v2/publish") {
512
- baseUrl = DEFAULT_QSTASH_URL;
513
- }
514
- if (!token) {
515
- console.warn(
516
- "[Upstash QStash] client token is not set. Either pass a token or set QSTASH_TOKEN env variable."
517
- );
518
- }
519
- return { baseUrl, token };
520
- };
521
-
522
- // src/receiver.ts
523
- var SignatureError = class extends Error {
524
- constructor(message) {
525
- super(message);
526
- this.name = "SignatureError";
527
- }
528
- };
529
- var Receiver = class {
530
- currentSigningKey;
531
- nextSigningKey;
532
- constructor(config) {
533
- this.currentSigningKey = config?.currentSigningKey;
534
- this.nextSigningKey = config?.nextSigningKey;
535
- }
536
- /**
537
- * Verify the signature of a request.
538
- *
539
- * Tries to verify the signature with the current signing key.
540
- * If that fails, maybe because you have rotated the keys recently, it will
541
- * try to verify the signature with the next signing key.
542
- *
543
- * If that fails, the signature is invalid and a `SignatureError` is thrown.
544
- */
545
- async verify(request) {
546
- const environment = getSafeEnvironment();
547
- const signingKeys = getReceiverSigningKeys({
548
- environment,
549
- regionFromHeader: request.upstashRegion,
550
- config: {
551
- currentSigningKey: this.currentSigningKey,
552
- nextSigningKey: this.nextSigningKey
553
- }
554
- });
555
- if (!signingKeys) {
556
- throw new Error(
557
- "[Upstash QStash] No signing keys available for verification. See the warning above for more details."
558
- );
559
- }
560
- let payload;
561
- try {
562
- payload = await this.verifyWithKey(signingKeys.currentSigningKey, request);
563
- } catch {
564
- payload = await this.verifyWithKey(signingKeys.nextSigningKey, request);
565
- }
566
- this.verifyBodyAndUrl(payload, request);
567
- return true;
568
- }
569
- /**
570
- * Verify signature with a specific signing key
571
- */
572
- async verifyWithKey(key, request) {
573
- const jwt = await jwtVerify(request.signature, new TextEncoder().encode(key), {
574
- issuer: "Upstash",
575
- clockTolerance: request.clockTolerance
576
- }).catch((error) => {
577
- throw new SignatureError(error.message);
578
- });
579
- return jwt.payload;
580
- }
581
- verifyBodyAndUrl(payload, request) {
582
- const p = payload;
583
- if (request.url !== void 0 && p.sub !== request.url) {
584
- throw new SignatureError(`invalid subject: ${p.sub}, want: ${request.url}`);
585
- }
586
- const bodyHash = crypto2.SHA256(request.body).toString(crypto2.enc.Base64url);
587
- const padding = new RegExp(/=+$/);
588
- if (p.body.replace(padding, "") !== bodyHash.replace(padding, "")) {
589
- throw new SignatureError(`body hash does not match, want: ${p.body}, got: ${bodyHash}`);
590
- }
591
- }
592
- };
593
-
594
- // src/client/dlq.ts
595
- var DLQ = class {
596
- http;
597
- constructor(http) {
598
- this.http = http;
599
- }
600
- /**
601
- * List messages in the dlq
602
- *
603
- * Can be called with:
604
- * - Filters: `listMessages({ filter: { url: "https://example.com" } })`
605
- * - DLQ IDs: `listMessages({ dlqIds: ["id1", "id2"] })`
606
- * - No filter (list all): `listMessages()`
607
- */
608
- async listMessages(options = {}) {
609
- const query = {
610
- count: options.count,
611
- ..."dlqIds" in options ? { dlqIds: options.dlqIds } : { ...renameUrlGroup(options.filter ?? {}), cursor: options.cursor }
612
- };
613
- const messagesPayload = await this.http.request({
614
- method: "GET",
615
- path: ["v2", "dlq"],
616
- query
617
- });
618
- return {
619
- messages: messagesPayload.messages.map((message) => {
620
- return {
621
- ...message,
622
- urlGroup: message.topicName,
623
- ratePerSecond: "rate" in message ? message.rate : void 0
624
- };
625
- }),
626
- cursor: messagesPayload.cursor
627
- };
628
- }
629
- /**
630
- * Remove messages from the dlq.
631
- *
632
- * Can be called with:
633
- * - A single dlqId: `delete("id")`
634
- * - An array of dlqIds: `delete(["id1", "id2"])`
635
- * - An object with dlqIds: `delete({ dlqIds: ["id1", "id2"] })`
636
- * - A filter object: `delete({ filter: { url: "https://example.com", label: "label" } })`
637
- * - All messages: `delete({ all: true })`
638
- *
639
- * Pass `count` to limit the number of messages processed per call (defaults to 100).
640
- * Call in a loop until cursor is undefined:
641
- *
642
- * ```ts
643
- * let cursor: string | undefined;
644
- * do {
645
- * const result = await dlq.delete({ all: true, count: 100, cursor });
646
- * cursor = result.cursor;
647
- * } while (cursor);
648
- * ```
649
- */
650
- async delete(request) {
651
- if (typeof request === "string") {
652
- await this.http.request({
653
- method: "DELETE",
654
- path: ["v2", "dlq", request],
655
- parseResponseAsJson: false
656
- });
657
- return { deleted: 1 };
658
- }
659
- if (Array.isArray(request) && request.length === 0)
660
- return { deleted: 0 };
661
- const filters = Array.isArray(request) ? { dlqIds: request } : request;
662
- return await this.http.request({
663
- method: "DELETE",
664
- path: ["v2", "dlq"],
665
- query: buildBulkActionFilterPayload(filters)
666
- });
667
- }
668
- /**
669
- * Remove multiple messages from the dlq using their `dlqId`s
670
- *
671
- * @deprecated Use `delete` instead
672
- */
673
- async deleteMany(request) {
674
- return await this.delete(request);
675
- }
676
- /**
677
- * Retry messages from the dlq.
678
- *
679
- * Can be called with:
680
- * - A single dlqId: `retry("id")`
681
- * - An array of dlqIds: `retry(["id1", "id2"])`
682
- * - An object with dlqIds: `retry({ dlqIds: ["id1", "id2"] })`
683
- * - A filter object: `retry({ filter: { url: "https://example.com", label: "label" } })`
684
- * - All messages: `retry({ all: true })`
685
- *
686
- * Pass `count` to limit the number of messages processed per call (defaults to 100).
687
- * Call in a loop until cursor is undefined:
688
- *
689
- * ```ts
690
- * let cursor: string | undefined;
691
- * do {
692
- * const result = await dlq.retry({ all: true, count: 100, cursor });
693
- * cursor = result.cursor;
694
- * } while (cursor);
695
- * ```
696
- */
697
- async retry(request) {
698
- if (typeof request === "string")
699
- request = [request];
700
- if (Array.isArray(request) && request.length === 0)
701
- return { responses: [] };
702
- const filters = Array.isArray(request) ? { dlqIds: request } : request;
703
- return normalizeCursor(
704
- await this.http.request({
705
- method: "POST",
706
- path: ["v2", "dlq", "retry"],
707
- query: buildBulkActionFilterPayload(filters)
708
- })
709
- );
710
- }
711
- };
712
-
713
- // src/client/flow-control.ts
714
- var FlowControlApi = class {
715
- http;
716
- constructor(http) {
717
- this.http = http;
718
- }
719
- /**
720
- * Get a single flow control by key.
721
- */
722
- async get(flowControlKey) {
723
- return await this.http.request({
724
- method: "GET",
725
- path: ["v2", "flowControl", flowControlKey]
726
- });
727
- }
728
- /**
729
- * Get the global parallelism info.
730
- */
731
- async getGlobalParallelism() {
732
- const response = await this.http.request({
733
- method: "GET",
734
- path: ["v2", "globalParallelism"]
735
- });
736
- return {
737
- parallelismMax: response.parallelismMax ?? 0,
738
- parallelismCount: response.parallelismCount ?? 0
739
- };
740
- }
741
- /**
742
- * Pause message delivery for a flow-control key.
743
- *
744
- * Messages already in the waitlist will remain there.
745
- * New incoming messages will be added directly to the waitlist.
746
- */
747
- async pause(flowControlKey) {
748
- await this.http.request({
749
- method: "POST",
750
- path: ["v2", "flowControl", flowControlKey, "pause"],
751
- parseResponseAsJson: false
752
- });
753
- }
754
- /**
755
- * Resume message delivery for a flow-control key.
756
- */
757
- async resume(flowControlKey) {
758
- await this.http.request({
759
- method: "POST",
760
- path: ["v2", "flowControl", flowControlKey, "resume"],
761
- parseResponseAsJson: false
762
- });
763
- }
764
- /**
765
- * Pin a processing configuration for a flow-control key.
766
- *
767
- * While pinned, the system ignores configurations provided by incoming
768
- * messages and uses the pinned configuration instead.
769
- */
770
- async pin(flowControlKey, options) {
771
- await this.http.request({
772
- method: "POST",
773
- path: ["v2", "flowControl", flowControlKey, "pin"],
774
- query: {
775
- parallelism: options.parallelism,
776
- rate: options.rate,
777
- period: options.period
778
- },
779
- parseResponseAsJson: false
780
- });
781
- }
782
- /**
783
- * Remove the pinned configuration for a flow-control key.
784
- *
785
- * After unpinning, the system resumes updating the configuration
786
- * based on incoming messages.
787
- */
788
- async unpin(flowControlKey, options) {
789
- await this.http.request({
790
- method: "POST",
791
- path: ["v2", "flowControl", flowControlKey, "unpin"],
792
- query: {
793
- parallelism: options.parallelism,
794
- rate: options.rate
795
- },
796
- parseResponseAsJson: false
797
- });
798
- }
799
- /**
800
- * Reset the rate configuration state for a flow-control key.
801
- *
802
- * Clears the current rate count and immediately ends the current period.
803
- * The current timestamp becomes the start of the new rate period.
804
- */
805
- async resetRate(flowControlKey) {
806
- await this.http.request({
807
- method: "POST",
808
- path: ["v2", "flowControl", flowControlKey, "resetRate"],
809
- parseResponseAsJson: false
810
- });
811
- }
812
- };
813
-
814
- // src/client/http.ts
815
- var HttpClient = class {
816
- baseUrl;
817
- authorization;
818
- options;
819
- retry;
820
- headers;
821
- telemetryHeaders;
822
- constructor(config) {
823
- this.baseUrl = config.baseUrl.replace(/\/$/, "");
824
- this.authorization = config.authorization;
825
- this.retry = // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
826
- typeof config.retry === "boolean" && !config.retry ? {
827
- attempts: 1,
828
- backoff: () => 0
829
- } : {
830
- attempts: config.retry?.retries ?? 5,
831
- backoff: config.retry?.backoff ?? ((retryCount) => Math.exp(retryCount) * 50)
832
- };
833
- this.headers = config.headers;
834
- this.telemetryHeaders = config.telemetryHeaders;
835
- }
836
- async request(request) {
837
- const { response } = await this.requestWithBackoff(request);
838
- if (request.parseResponseAsJson === false) {
839
- return void 0;
840
- }
841
- return await response.json();
842
- }
843
- async *requestStream(request) {
844
- const { response } = await this.requestWithBackoff(request);
845
- if (!response.body) {
846
- throw new Error("No response body");
847
- }
848
- const body = response.body;
849
- const reader = body.getReader();
850
- const decoder = new TextDecoder();
851
- try {
852
- while (true) {
853
- const { done, value } = await reader.read();
854
- if (done) {
855
- break;
856
- }
857
- const chunkText = decoder.decode(value, { stream: true });
858
- const chunks = chunkText.split("\n").filter(Boolean);
859
- for (const chunk of chunks) {
860
- if (chunk.startsWith("data: ")) {
861
- const data = chunk.slice(6);
862
- if (data === "[DONE]") {
863
- break;
864
- }
865
- yield JSON.parse(data);
866
- }
867
- }
868
- }
869
- } finally {
870
- await reader.cancel();
871
- }
872
- }
873
- requestWithBackoff = async (request) => {
874
- const [url, requestOptions] = this.processRequest(request);
875
- let response = void 0;
876
- let error = void 0;
877
- for (let index = 0; index <= this.retry.attempts; index++) {
878
- try {
879
- response = await fetch(url.toString(), requestOptions);
880
- break;
881
- } catch (error_) {
882
- error = error_;
883
- if (index < this.retry.attempts) {
884
- await new Promise((r) => setTimeout(r, this.retry.backoff(index)));
885
- }
886
- }
887
- }
888
- if (!response) {
889
- throw error ?? new Error("Exhausted all retries");
890
- }
891
- await this.checkResponse(response);
892
- return {
893
- response,
894
- error
895
- };
896
- };
897
- processRequest = (request) => {
898
- const headers = new Headers(request.headers);
899
- if (!headers.has("Authorization")) {
900
- headers.set("Authorization", this.authorization);
901
- }
902
- const requestOptions = {
903
- method: request.method,
904
- headers,
905
- body: request.body,
906
- keepalive: request.keepalive
907
- };
908
- const url = new URL([request.baseUrl ?? this.baseUrl, ...request.path].join("/"));
909
- if (request.query) {
910
- for (const [key, value] of Object.entries(request.query)) {
911
- if (value === void 0)
912
- continue;
913
- if (Array.isArray(value)) {
914
- if (value.length === 0) {
915
- throw new QstashEmptyArrayError(key);
916
- }
917
- for (const item of value) {
918
- url.searchParams.append(key, item);
919
- }
920
- } else if (value instanceof Date) {
921
- url.searchParams.set(key, value.getTime().toString());
922
- } else {
923
- url.searchParams.set(key, value.toString());
924
- }
925
- }
926
- }
927
- return [url.toString(), requestOptions];
928
- };
929
- async checkResponse(response) {
930
- if (response.status === 429) {
931
- if (response.headers.get("x-ratelimit-limit-requests")) {
932
- throw new QstashChatRatelimitError({
933
- "limit-requests": response.headers.get("x-ratelimit-limit-requests"),
934
- "limit-tokens": response.headers.get("x-ratelimit-limit-tokens"),
935
- "remaining-requests": response.headers.get("x-ratelimit-remaining-requests"),
936
- "remaining-tokens": response.headers.get("x-ratelimit-remaining-tokens"),
937
- "reset-requests": response.headers.get("x-ratelimit-reset-requests"),
938
- "reset-tokens": response.headers.get("x-ratelimit-reset-tokens")
939
- });
940
- } else if (response.headers.get("RateLimit-Limit")) {
941
- throw new QstashDailyRatelimitError({
942
- limit: response.headers.get("RateLimit-Limit"),
943
- remaining: response.headers.get("RateLimit-Remaining"),
944
- reset: response.headers.get("RateLimit-Reset")
945
- });
946
- }
947
- throw new QstashRatelimitError({
948
- limit: response.headers.get("Burst-RateLimit-Limit"),
949
- remaining: response.headers.get("Burst-RateLimit-Remaining"),
950
- reset: response.headers.get("Burst-RateLimit-Reset")
951
- });
952
- }
953
- if (response.status < 200 || response.status >= 300) {
954
- const body = await response.text();
955
- throw new QstashError(
956
- body.length > 0 ? body : `Error: status=${response.status}`,
957
- response.status
958
- );
959
- }
960
- }
961
- };
962
-
963
- // src/client/llm/providers.ts
964
- var setupAnalytics = (analytics, providerApiKey, providerBaseUrl, provider) => {
965
- if (!analytics)
966
- return {};
967
- switch (analytics.name) {
968
- case "helicone": {
969
- switch (provider) {
970
- case "upstash": {
971
- return {
972
- baseURL: "https://qstash.helicone.ai/llm/v1/chat/completions",
973
- defaultHeaders: {
974
- "Helicone-Auth": `Bearer ${analytics.token}`,
975
- Authorization: `Bearer ${providerApiKey}`
976
- }
977
- };
978
- }
979
- default: {
980
- return {
981
- baseURL: "https://gateway.helicone.ai/v1/chat/completions",
982
- defaultHeaders: {
983
- "Helicone-Auth": `Bearer ${analytics.token}`,
984
- "Helicone-Target-Url": providerBaseUrl,
985
- Authorization: `Bearer ${providerApiKey}`
986
- }
987
- };
988
- }
989
- }
990
- }
991
- default: {
992
- throw new Error("Unknown analytics provider");
993
- }
994
- }
995
- };
996
-
997
- // src/client/llm/chat.ts
998
- var Chat = class _Chat {
999
- http;
1000
- token;
1001
- constructor(http, token) {
1002
- this.http = http;
1003
- this.token = token;
1004
- }
1005
- static toChatRequest(request) {
1006
- const messages = [];
1007
- messages.push(
1008
- { role: "system", content: request.system },
1009
- { role: "user", content: request.user }
1010
- );
1011
- const chatRequest = { ...request, messages };
1012
- return chatRequest;
1013
- }
1014
- /**
1015
- * Calls the Upstash completions api given a ChatRequest.
1016
- *
1017
- * Returns a ChatCompletion or a stream of ChatCompletionChunks
1018
- * if stream is enabled.
1019
- *
1020
- * @param request ChatRequest with messages
1021
- * @returns Chat completion or stream
1022
- */
1023
- create = async (request) => {
1024
- if (request.provider.owner != "upstash")
1025
- return this.createThirdParty(request);
1026
- const body = JSON.stringify(request);
1027
- let baseUrl = void 0;
1028
- let headers = {
1029
- "Content-Type": "application/json",
1030
- Authorization: `Bearer ${this.token}`,
1031
- ..."stream" in request && request.stream ? {
1032
- Connection: "keep-alive",
1033
- Accept: "text/event-stream",
1034
- "Cache-Control": "no-cache"
1035
- } : {}
1036
- };
1037
- if (request.analytics) {
1038
- const { baseURL, defaultHeaders } = setupAnalytics(
1039
- { name: "helicone", token: request.analytics.token },
1040
- this.getAuthorizationToken(),
1041
- request.provider.baseUrl,
1042
- "upstash"
1043
- );
1044
- headers = { ...headers, ...defaultHeaders };
1045
- baseUrl = baseURL;
1046
- }
1047
- const path = request.analytics ? [] : ["llm", "v1", "chat", "completions"];
1048
- return "stream" in request && request.stream ? this.http.requestStream({
1049
- path,
1050
- method: "POST",
1051
- headers,
1052
- baseUrl,
1053
- body
1054
- }) : this.http.request({
1055
- path,
1056
- method: "POST",
1057
- headers,
1058
- baseUrl,
1059
- body
1060
- });
1061
- };
1062
- /**
1063
- * Calls the Upstash completions api given a ChatRequest.
1064
- *
1065
- * Returns a ChatCompletion or a stream of ChatCompletionChunks
1066
- * if stream is enabled.
1067
- *
1068
- * @param request ChatRequest with messages
1069
- * @returns Chat completion or stream
1070
- */
1071
- createThirdParty = async (request) => {
1072
- const { baseUrl, token, owner, organization } = request.provider;
1073
- if (owner === "upstash")
1074
- throw new Error("Upstash is not 3rd party provider!");
1075
- delete request.provider;
1076
- delete request.system;
1077
- const analytics = request.analytics;
1078
- delete request.analytics;
1079
- const body = JSON.stringify(request);
1080
- const isAnalyticsEnabled = analytics?.name && analytics.token;
1081
- const analyticsConfig = analytics?.name && analytics.token ? setupAnalytics({ name: analytics.name, token: analytics.token }, token, baseUrl, owner) : { defaultHeaders: void 0, baseURL: baseUrl };
1082
- const isStream = "stream" in request && request.stream;
1083
- const headers = {
1084
- "Content-Type": "application/json",
1085
- Authorization: `Bearer ${token}`,
1086
- ...organization ? {
1087
- "OpenAI-Organization": organization
1088
- } : {},
1089
- ...isStream ? {
1090
- Connection: "keep-alive",
1091
- Accept: "text/event-stream",
1092
- "Cache-Control": "no-cache"
1093
- } : {},
1094
- ...analyticsConfig.defaultHeaders
1095
- };
1096
- const response = await this.http[isStream ? "requestStream" : "request"]({
1097
- path: isAnalyticsEnabled ? [] : ["v1", "chat", "completions"],
1098
- method: "POST",
1099
- headers,
1100
- body,
1101
- baseUrl: analyticsConfig.baseURL
1102
- });
1103
- return response;
1104
- };
1105
- // Helper method to get the authorization token
1106
- getAuthorizationToken() {
1107
- const authHeader = String(this.http.authorization);
1108
- const match = /Bearer (.+)/.exec(authHeader);
1109
- if (!match) {
1110
- throw new Error("Invalid authorization header format");
1111
- }
1112
- return match[1];
1113
- }
1114
- /**
1115
- * Calls the Upstash completions api given a PromptRequest.
1116
- *
1117
- * Returns a ChatCompletion or a stream of ChatCompletionChunks
1118
- * if stream is enabled.
1119
- *
1120
- * @param request PromptRequest with system and user messages.
1121
- * Note that system parameter shouldn't be passed in the case of
1122
- * mistralai/Mistral-7B-Instruct-v0.2 model.
1123
- * @returns Chat completion or stream
1124
- */
1125
- prompt = async (request) => {
1126
- const chatRequest = _Chat.toChatRequest(request);
1127
- return this.create(chatRequest);
1128
- };
1129
- };
1130
-
1131
- // src/client/messages.ts
1132
- var Messages = class {
1133
- http;
1134
- constructor(http) {
1135
- this.http = http;
1136
- }
1137
- /**
1138
- * Get a message
1139
- */
1140
- async get(messageId) {
1141
- const messagePayload = await this.http.request({
1142
- method: "GET",
1143
- path: ["v2", "messages", messageId]
1144
- });
1145
- const message = {
1146
- ...messagePayload,
1147
- urlGroup: messagePayload.topicName,
1148
- ratePerSecond: "rate" in messagePayload ? messagePayload.rate : void 0
1149
- };
1150
- return message;
1151
- }
1152
- /**
1153
- * Cancel messages.
1154
- *
1155
- * Can be called with:
1156
- * - A single messageId: `cancel("id")`
1157
- * - An array of messageIds: `cancel(["id1", "id2"])`
1158
- * - A filter object: `cancel({ filter: { flowControlKey: "key", label: "label" } })`
1159
- * - All messages: `cancel({ all: true })`
1160
- *
1161
- * Pass `count` to limit the number of messages processed per call (defaults to 100).
1162
- * Call in a loop until `cancelled` is 0:
1163
- *
1164
- * ```ts
1165
- * let cancelled: number;
1166
- * do {
1167
- * const result = await messages.cancel({ all: true, count: 100 });
1168
- * cancelled = result.cancelled;
1169
- * } while (cancelled > 0);
1170
- * ```
1171
- */
1172
- async cancel(request) {
1173
- if (typeof request === "string") {
1174
- return await this.http.request({
1175
- method: "DELETE",
1176
- path: ["v2", "messages", request]
1177
- });
1178
- }
1179
- if (Array.isArray(request) && request.length === 0)
1180
- return { cancelled: 0 };
1181
- const filters = Array.isArray(request) ? { messageIds: request } : request;
1182
- return await this.http.request({
1183
- method: "DELETE",
1184
- path: ["v2", "messages"],
1185
- query: buildBulkActionFilterPayload(filters)
1186
- });
1187
- }
1188
- /**
1189
- * Delete a message.
1190
- *
1191
- * @deprecated Use `cancel(messageId: string)` instead
1192
- */
1193
- async delete(messageId) {
1194
- await this.http.request({
1195
- method: "DELETE",
1196
- path: ["v2", "messages", messageId],
1197
- parseResponseAsJson: false
1198
- });
1199
- }
1200
- /**
1201
- * Cancel multiple messages by their messageIds.
1202
- *
1203
- * @deprecated Use `cancel(messageIds: string[])` instead
1204
- */
1205
- async deleteMany(messageIds) {
1206
- const result = await this.cancel(messageIds);
1207
- return result.cancelled;
1208
- }
1209
- /**
1210
- * Cancel all messages
1211
- * @deprecated Use `cancel({all: true})` to cancel all
1212
- */
1213
- async deleteAll() {
1214
- const result = await this.cancel({ all: true });
1215
- return result.cancelled;
1216
- }
1217
- };
1218
-
1219
- // src/client/queue.ts
1220
- var Queue = class {
1221
- http;
1222
- queueName;
1223
- constructor(http, queueName) {
1224
- this.http = http;
1225
- this.queueName = queueName;
1226
- }
1227
- /**
1228
- * Create or update the queue
1229
- */
1230
- async upsert(request) {
1231
- if (!this.queueName) {
1232
- throw new Error("Please provide a queue name to the Queue constructor");
1233
- }
1234
- const body = {
1235
- queueName: this.queueName,
1236
- parallelism: request.parallelism ?? 1,
1237
- paused: request.paused ?? false
1238
- };
1239
- await this.http.request({
1240
- method: "POST",
1241
- path: ["v2", "queues"],
1242
- headers: {
1243
- "Content-Type": "application/json"
1244
- },
1245
- body: JSON.stringify(body),
1246
- parseResponseAsJson: false
1247
- });
1248
- }
1249
- /**
1250
- * Get the queue details
1251
- */
1252
- async get() {
1253
- if (!this.queueName) {
1254
- throw new Error("Please provide a queue name to the Queue constructor");
1255
- }
1256
- return await this.http.request({
1257
- method: "GET",
1258
- path: ["v2", "queues", this.queueName]
1259
- });
1260
- }
1261
- /**
1262
- * List queues
1263
- */
1264
- async list() {
1265
- return await this.http.request({
1266
- method: "GET",
1267
- path: ["v2", "queues"]
1268
- });
1269
- }
1270
- /**
1271
- * Delete the queue
1272
- */
1273
- async delete() {
1274
- if (!this.queueName) {
1275
- throw new Error("Please provide a queue name to the Queue constructor");
1276
- }
1277
- await this.http.request({
1278
- method: "DELETE",
1279
- path: ["v2", "queues", this.queueName],
1280
- parseResponseAsJson: false
1281
- });
1282
- }
1283
- /**
1284
- * Enqueue a message to a queue.
1285
- */
1286
- async enqueue(request) {
1287
- if (!this.queueName) {
1288
- throw new Error("Please provide a queue name to the Queue constructor");
1289
- }
1290
- const headers = wrapWithGlobalHeaders(
1291
- processHeaders(request),
1292
- this.http.headers,
1293
- this.http.telemetryHeaders
1294
- );
1295
- const destination = getRequestPath(request);
1296
- const response = await this.http.request({
1297
- path: ["v2", "enqueue", this.queueName, destination],
1298
- body: request.body,
1299
- headers,
1300
- method: "POST"
1301
- });
1302
- return response;
1303
- }
1304
- /**
1305
- * Enqueue a message to a queue, serializing the body to JSON.
1306
- */
1307
- async enqueueJSON(request) {
1308
- const headers = prefixHeaders(new Headers(request.headers));
1309
- headers.set("Content-Type", "application/json");
1310
- const upstashToken = String(this.http.authorization).split("Bearer ")[1];
1311
- const nonApiRequest = processApi(request, headers, upstashToken);
1312
- const response = await this.enqueue({
1313
- ...nonApiRequest,
1314
- body: JSON.stringify(nonApiRequest.body)
1315
- });
1316
- return response;
1317
- }
1318
- /**
1319
- * Pauses the queue.
1320
- *
1321
- * A paused queue will not deliver messages until
1322
- * it is resumed.
1323
- */
1324
- async pause() {
1325
- if (!this.queueName) {
1326
- throw new Error("Please provide a queue name to the Queue constructor");
1327
- }
1328
- await this.http.request({
1329
- method: "POST",
1330
- path: ["v2", "queues", this.queueName, "pause"],
1331
- parseResponseAsJson: false
1332
- });
1333
- }
1334
- /**
1335
- * Resumes the queue.
1336
- */
1337
- async resume() {
1338
- if (!this.queueName) {
1339
- throw new Error("Please provide a queue name to the Queue constructor");
1340
- }
1341
- await this.http.request({
1342
- method: "POST",
1343
- path: ["v2", "queues", this.queueName, "resume"],
1344
- parseResponseAsJson: false
1345
- });
1346
- }
1347
- };
1348
-
1349
- // src/client/schedules.ts
1350
- var Schedules = class {
1351
- http;
1352
- constructor(http) {
1353
- this.http = http;
1354
- }
1355
- /**
1356
- * Create a schedule
1357
- */
1358
- async create(request) {
1359
- const headers = prefixHeaders(new Headers(request.headers));
1360
- if (!headers.has("Content-Type")) {
1361
- headers.set("Content-Type", "application/json");
1362
- }
1363
- headers.set("Upstash-Cron", request.cron);
1364
- if (request.method !== void 0) {
1365
- headers.set("Upstash-Method", request.method);
1366
- }
1367
- if (request.delay !== void 0) {
1368
- if (typeof request.delay === "string") {
1369
- headers.set("Upstash-Delay", request.delay);
1370
- } else {
1371
- headers.set("Upstash-Delay", `${request.delay.toFixed(0)}s`);
1372
- }
1373
- }
1374
- if (request.retries !== void 0) {
1375
- headers.set("Upstash-Retries", request.retries.toFixed(0));
1376
- }
1377
- if (request.retryDelay !== void 0) {
1378
- headers.set("Upstash-Retry-Delay", request.retryDelay);
1379
- }
1380
- if (request.callback !== void 0) {
1381
- headers.set("Upstash-Callback", request.callback);
1382
- }
1383
- if (request.failureCallback !== void 0) {
1384
- headers.set("Upstash-Failure-Callback", request.failureCallback);
1385
- }
1386
- if (request.timeout !== void 0) {
1387
- if (typeof request.timeout === "string") {
1388
- headers.set("Upstash-Timeout", request.timeout);
1389
- } else {
1390
- headers.set("Upstash-Timeout", `${request.timeout}s`);
1391
- }
1392
- }
1393
- if (request.scheduleId !== void 0) {
1394
- headers.set("Upstash-Schedule-Id", request.scheduleId);
1395
- }
1396
- if (request.queueName !== void 0) {
1397
- headers.set("Upstash-Queue-Name", request.queueName);
1398
- }
1399
- if (request.flowControl?.key) {
1400
- const parallelism = request.flowControl.parallelism?.toString();
1401
- const rate = (request.flowControl.rate ?? request.flowControl.ratePerSecond)?.toString();
1402
- const period = typeof request.flowControl.period === "number" ? `${request.flowControl.period}s` : request.flowControl.period;
1403
- const controlValue = [
1404
- parallelism ? `parallelism=${parallelism}` : void 0,
1405
- rate ? `rate=${rate}` : void 0,
1406
- period ? `period=${period}` : void 0
1407
- ].filter(Boolean);
1408
- if (controlValue.length === 0) {
1409
- throw new QstashError(
1410
- "Provide at least one of parallelism or ratePerSecond for flowControl"
1411
- );
1412
- }
1413
- headers.set("Upstash-Flow-Control-Key", request.flowControl.key);
1414
- headers.set("Upstash-Flow-Control-Value", controlValue.join(", "));
1415
- }
1416
- if (request.label !== void 0) {
1417
- headers.set("Upstash-Label", request.label);
1418
- }
1419
- if (request.redact !== void 0) {
1420
- const redactParts = [];
1421
- if (request.redact.body) {
1422
- redactParts.push("body");
1423
- }
1424
- if (request.redact.header !== void 0) {
1425
- if (request.redact.header === true) {
1426
- redactParts.push("header");
1427
- } else if (Array.isArray(request.redact.header) && request.redact.header.length > 0) {
1428
- for (const headerName of request.redact.header) {
1429
- redactParts.push(`header[${headerName}]`);
1430
- }
1431
- }
1432
- }
1433
- if (redactParts.length > 0) {
1434
- headers.set("Upstash-Redact-Fields", redactParts.join(","));
1435
- }
1436
- }
1437
- return await this.http.request({
1438
- method: "POST",
1439
- headers: wrapWithGlobalHeaders(headers, this.http.headers, this.http.telemetryHeaders),
1440
- path: ["v2", "schedules", request.destination],
1441
- body: request.body
1442
- });
1443
- }
1444
- /**
1445
- * Get a schedule
1446
- */
1447
- async get(scheduleId) {
1448
- const schedule = await this.http.request({
1449
- method: "GET",
1450
- path: ["v2", "schedules", scheduleId]
1451
- });
1452
- if ("rate" in schedule)
1453
- schedule.ratePerSecond = schedule.rate;
1454
- return schedule;
1455
- }
1456
- /**
1457
- * List your schedules
1458
- */
1459
- async list() {
1460
- const schedules = await this.http.request({
1461
- method: "GET",
1462
- path: ["v2", "schedules"]
1463
- });
1464
- for (const schedule of schedules) {
1465
- if ("rate" in schedule)
1466
- schedule.ratePerSecond = schedule.rate;
1467
- }
1468
- return schedules;
1469
- }
1470
- /**
1471
- * Delete a schedule
1472
- */
1473
- async delete(scheduleId) {
1474
- return await this.http.request({
1475
- method: "DELETE",
1476
- path: ["v2", "schedules", scheduleId],
1477
- parseResponseAsJson: false
1478
- });
1479
- }
1480
- /**
1481
- * Pauses the schedule.
1482
- *
1483
- * A paused schedule will not deliver messages until
1484
- * it is resumed.
1485
- */
1486
- async pause({ schedule }) {
1487
- await this.http.request({
1488
- method: "PATCH",
1489
- path: ["v2", "schedules", schedule, "pause"],
1490
- parseResponseAsJson: false
1491
- });
1492
- }
1493
- /**
1494
- * Resumes the schedule.
1495
- */
1496
- async resume({ schedule }) {
1497
- await this.http.request({
1498
- method: "PATCH",
1499
- path: ["v2", "schedules", schedule, "resume"],
1500
- parseResponseAsJson: false
1501
- });
1502
- }
1503
- };
1504
-
1505
- // src/client/url-groups.ts
1506
- var UrlGroups = class {
1507
- http;
1508
- constructor(http) {
1509
- this.http = http;
1510
- }
1511
- /**
1512
- * Create a new url group with the given name and endpoints
1513
- */
1514
- async addEndpoints(request) {
1515
- await this.http.request({
1516
- method: "POST",
1517
- path: ["v2", "topics", request.name, "endpoints"],
1518
- headers: { "Content-Type": "application/json" },
1519
- body: JSON.stringify({ endpoints: request.endpoints }),
1520
- parseResponseAsJson: false
1521
- });
1522
- }
1523
- /**
1524
- * Remove endpoints from a url group.
1525
- */
1526
- async removeEndpoints(request) {
1527
- await this.http.request({
1528
- method: "DELETE",
1529
- path: ["v2", "topics", request.name, "endpoints"],
1530
- headers: { "Content-Type": "application/json" },
1531
- body: JSON.stringify({ endpoints: request.endpoints }),
1532
- parseResponseAsJson: false
1533
- });
1534
- }
1535
- /**
1536
- * Get a list of all url groups.
1537
- */
1538
- async list() {
1539
- return await this.http.request({
1540
- method: "GET",
1541
- path: ["v2", "topics"]
1542
- });
1543
- }
1544
- /**
1545
- * Get a single url group
1546
- */
1547
- async get(name) {
1548
- return await this.http.request({
1549
- method: "GET",
1550
- path: ["v2", "topics", name]
1551
- });
1552
- }
1553
- /**
1554
- * Delete a url group
1555
- */
1556
- async delete(name) {
1557
- return await this.http.request({
1558
- method: "DELETE",
1559
- path: ["v2", "topics", name],
1560
- parseResponseAsJson: false
1561
- });
1562
- }
1563
- };
1564
-
1565
- // version.ts
1566
- var VERSION = "2.10.1";
1567
-
1568
- // src/client/client.ts
1569
- var Client = class {
1570
- http;
1571
- token;
1572
- constructor(config) {
1573
- const environment = getSafeEnvironment();
1574
- const { baseUrl, token } = getClientCredentials({ environment, config });
1575
- const enableTelemetry = environment.UPSTASH_DISABLE_TELEMETRY ? false : config?.enableTelemetry ?? true;
1576
- const isCloudflare = typeof caches !== "undefined" && "default" in caches;
1577
- const telemetryHeaders = new Headers(
1578
- enableTelemetry ? {
1579
- "Upstash-Telemetry-Sdk": `upstash-qstash-js@${VERSION}`,
1580
- "Upstash-Telemetry-Platform": isCloudflare ? "cloudflare" : environment.VERCEL ? "vercel" : environment.AWS_REGION ? "aws" : "",
1581
- "Upstash-Telemetry-Runtime": getRuntime()
1582
- } : {}
1583
- );
1584
- this.http = new HttpClient({
1585
- retry: config?.retry,
1586
- baseUrl,
1587
- authorization: `Bearer ${token}`,
1588
- //@ts-expect-error caused by undici and bunjs type overlap
1589
- headers: prefixHeaders(new Headers(config?.headers ?? {})),
1590
- //@ts-expect-error caused by undici and bunjs type overlap
1591
- telemetryHeaders
1592
- });
1593
- this.token = token;
1594
- }
1595
- /**
1596
- * Access the urlGroup API.
1597
- *
1598
- * Create, read, update or delete urlGroups.
1599
- */
1600
- get urlGroups() {
1601
- return new UrlGroups(this.http);
1602
- }
1603
- /**
1604
- * Deprecated. Use urlGroups instead.
1605
- *
1606
- * Access the topic API.
1607
- *
1608
- * Create, read, update or delete topics.
1609
- */
1610
- get topics() {
1611
- return this.urlGroups;
1612
- }
1613
- /**
1614
- * Access the dlq API.
1615
- *
1616
- * List or remove messages from the DLQ.
1617
- */
1618
- get dlq() {
1619
- return new DLQ(this.http);
1620
- }
1621
- /**
1622
- * Access the message API.
1623
- *
1624
- * Read or cancel messages.
1625
- */
1626
- get messages() {
1627
- return new Messages(this.http);
1628
- }
1629
- /**
1630
- * Access the schedule API.
1631
- *
1632
- * Create, read or delete schedules.
1633
- */
1634
- get schedules() {
1635
- return new Schedules(this.http);
1636
- }
1637
- /**
1638
- * Access the flow control API.
1639
- *
1640
- * List, get, or reset flow controls.
1641
- */
1642
- get flowControl() {
1643
- return new FlowControlApi(this.http);
1644
- }
1645
- /**
1646
- * Access the workflow API.
1647
- *
1648
- * cancel workflows.
1649
- *
1650
- * @deprecated as of version 2.7.17. Will be removed in qstash-js 3.0.0.
1651
- * Please use @upstash/workflow instead https://github.com/upstash/workflow-js
1652
- * Migration Guide: https://upstash.com/docs/workflow/migration
1653
- */
1654
- get workflow() {
1655
- return new Workflow(this.http);
1656
- }
1657
- /**
1658
- * Access the queue API.
1659
- *
1660
- * Create, read, update or delete queues.
1661
- */
1662
- queue(request) {
1663
- return new Queue(this.http, request?.queueName);
1664
- }
1665
- /**
1666
- * Access the Chat API.
1667
- *
1668
- * @deprecated This will be removed in qstash-js 3.0.0. Please use an alternative SDK for interacting with LLMs.
1669
- *
1670
- * Use the create or prompt methods.
1671
- */
1672
- chat() {
1673
- return new Chat(this.http, this.token);
1674
- }
1675
- async publish(request) {
1676
- const headers = wrapWithGlobalHeaders(
1677
- processHeaders(request),
1678
- this.http.headers,
1679
- this.http.telemetryHeaders
1680
- );
1681
- const response = await this.http.request({
1682
- path: ["v2", "publish", getRequestPath(request)],
1683
- body: request.body,
1684
- headers,
1685
- method: "POST"
1686
- });
1687
- return response;
1688
- }
1689
- /**
1690
- * publishJSON is a utility wrapper around `publish` that automatically serializes the body
1691
- * and sets the `Content-Type` header to `application/json`.
1692
- */
1693
- async publishJSON(request) {
1694
- const headers = prefixHeaders(new Headers(request.headers));
1695
- headers.set("Content-Type", "application/json");
1696
- const upstashToken = String(this.http.authorization).split("Bearer ")[1];
1697
- const nonApiRequest = processApi(request, headers, upstashToken);
1698
- const response = await this.publish({
1699
- ...nonApiRequest,
1700
- body: JSON.stringify(nonApiRequest.body)
1701
- });
1702
- return response;
1703
- }
1704
- /**
1705
- * Batch publish messages to QStash.
1706
- */
1707
- async batch(request) {
1708
- const messages = [];
1709
- for (const message of request) {
1710
- const headers = wrapWithGlobalHeaders(
1711
- processHeaders(message),
1712
- this.http.headers,
1713
- this.http.telemetryHeaders
1714
- );
1715
- const headerEntries = Object.fromEntries(headers.entries());
1716
- messages.push({
1717
- destination: getRequestPath(message),
1718
- headers: headerEntries,
1719
- body: message.body,
1720
- ...message.queueName && { queue: message.queueName }
1721
- });
1722
- }
1723
- const response = await this.http.request({
1724
- path: ["v2", "batch"],
1725
- body: JSON.stringify(messages),
1726
- headers: {
1727
- "Content-Type": "application/json"
1728
- },
1729
- method: "POST"
1730
- });
1731
- const arrayResposne = Array.isArray(response) ? response : [response];
1732
- return arrayResposne;
1733
- }
1734
- /**
1735
- * Batch publish messages to QStash, serializing each body to JSON.
1736
- */
1737
- async batchJSON(request) {
1738
- const batchPayload = request.map((message) => {
1739
- if ("body" in message) {
1740
- message.body = JSON.stringify(message.body);
1741
- }
1742
- const upstashToken = String(this.http.authorization).split("Bearer ")[1];
1743
- const nonApiMessage = processApi(message, new Headers(message.headers), upstashToken);
1744
- nonApiMessage.headers.set("Content-Type", "application/json");
1745
- return nonApiMessage;
1746
- });
1747
- const response = await this.batch(batchPayload);
1748
- return response;
1749
- }
1750
- /**
1751
- * Retrieve your logs.
1752
- *
1753
- * The logs endpoint is paginated and returns only 100 logs at a time.
1754
- * If you want to receive more logs, you can use the cursor to paginate.
1755
- *
1756
- * The cursor is a unix timestamp with millisecond precision
1757
- *
1758
- * @example
1759
- * ```ts
1760
- * let cursor = Date.now()
1761
- * const logs: Log[] = []
1762
- * while (cursor > 0) {
1763
- * const res = await qstash.logs({ cursor })
1764
- * logs.push(...res.logs)
1765
- * cursor = res.cursor ?? 0
1766
- * }
1767
- * ```
1768
- */
1769
- async logs(request = {}) {
1770
- const query = {
1771
- count: request.count,
1772
- ..."messageIds" in request ? { messageIds: request.messageIds } : { ...renameUrlGroup(request.filter ?? {}), cursor: request.cursor }
1773
- };
1774
- const responsePayload = await this.http.request({
1775
- path: ["v2", "events"],
1776
- method: "GET",
1777
- query
1778
- });
1779
- const logs = responsePayload.events.map((event) => ({ ...event, urlGroup: event.topicName }));
1780
- return { cursor: responsePayload.cursor, logs, events: logs };
1781
- }
1782
- /**
1783
- * @deprecated Will be removed in the next major release. Use the `logs` method instead.
1784
- *
1785
- * Retrieve your logs.
1786
- *
1787
- * The logs endpoint is paginated and returns only 100 logs at a time.
1788
- * If you want to receive more logs, you can use the cursor to paginate.
1789
- *
1790
- * The cursor is a unix timestamp with millisecond precision
1791
- *
1792
- * @example
1793
- * ```ts
1794
- * let cursor = Date.now()
1795
- * const logs: Log[] = []
1796
- * while (cursor > 0) {
1797
- * const res = await qstash.logs({ cursor })
1798
- * logs.push(...res.logs)
1799
- * cursor = res.cursor ?? 0
1800
- * }
1801
- * ```
1802
- */
1803
- async events(request) {
1804
- return await this.logs(request);
1805
- }
1806
- };
1807
-
1808
- // src/client/workflow/index.ts
1809
- var Workflow = class {
1810
- http;
1811
- constructor(http) {
1812
- this.http = http;
1813
- }
1814
- /**
1815
- * Cancel an ongoing workflow
1816
- *
1817
- * @param workflowRunId run id of the workflow to delete
1818
- * @returns true if workflow is succesfully deleted. Otherwise throws QStashError
1819
- */
1820
- async cancel(workflowRunId) {
1821
- const result = await this.http.request({
1822
- path: ["v2", "workflows", "runs", `${workflowRunId}?cancel=true`],
1823
- method: "DELETE",
1824
- parseResponseAsJson: false
1825
- });
1826
- return result ?? true;
1827
- }
1828
- };
1829
-
1830
- export { BaseProvider, Chat, Client, FlowControlApi, Messages, QstashChatRatelimitError, QstashDailyRatelimitError, QstashEmptyArrayError, QstashError, QstashRatelimitError, Receiver, Schedules, SignatureError, UrlGroups, Workflow, setupAnalytics, upstash };