@upstash/qstash 2.7.5 → 2.7.6-canary
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.
- package/README.md +10 -3
- package/chunk-B3NB4QLV.mjs +2920 -0
- package/chunk-IJ3475FO.mjs +403 -0
- package/chunk-IJ5AEYLN.js +1 -0
- package/chunk-NMSGEGBP.js +403 -0
- package/chunk-S7JMIMW4.mjs +0 -0
- package/chunk-WQZ4U6LJ.js +2920 -0
- package/{dist/workflow/index.d.mts → client-aUVEwn93.d.mts} +868 -800
- package/{dist/nextjs/index.d.mts → client-aUVEwn93.d.ts} +871 -743
- package/cloudflare.d.mts +33 -0
- package/cloudflare.d.ts +33 -0
- package/cloudflare.js +37 -0
- package/cloudflare.mjs +37 -0
- package/h3.d.mts +17 -0
- package/h3.d.ts +17 -0
- package/h3.js +10 -0
- package/h3.mjs +10 -0
- package/hono.d.mts +25 -0
- package/hono.d.ts +25 -0
- package/hono.js +22 -0
- package/hono.mjs +22 -0
- package/index.d.mts +54 -0
- package/index.d.ts +54 -0
- package/index.js +41 -0
- package/index.mjs +41 -0
- package/nextjs.d.mts +38 -0
- package/nextjs.d.ts +38 -0
- package/nextjs.js +178 -0
- package/nextjs.mjs +178 -0
- package/nuxt.d.mts +12 -0
- package/nuxt.d.ts +12 -0
- package/nuxt.js +11 -0
- package/nuxt.mjs +11 -0
- package/package.json +1 -1
- package/solidjs.d.mts +22 -0
- package/solidjs.d.ts +22 -0
- package/solidjs.js +56 -0
- package/solidjs.mjs +56 -0
- package/svelte.d.mts +24 -0
- package/svelte.d.ts +24 -0
- package/svelte.js +53 -0
- package/svelte.mjs +53 -0
- package/workflow.d.mts +2 -0
- package/workflow.d.ts +2 -0
- package/workflow.js +18 -0
- package/workflow.mjs +18 -0
- package/dist/base/index.d.mts +0 -1279
- package/dist/base/index.mjs +0 -2
- package/dist/cloudflare/index.d.mts +0 -1652
- package/dist/cloudflare/index.mjs +0 -11
- package/dist/h3/index.d.mts +0 -1637
- package/dist/h3/index.mjs +0 -11
- package/dist/hono/index.d.mts +0 -1645
- package/dist/hono/index.mjs +0 -11
- package/dist/nextjs/index.mjs +0 -11
- package/dist/solidjs/index.d.mts +0 -1642
- package/dist/solidjs/index.mjs +0 -11
- package/dist/svelte/index.d.mts +0 -1644
- package/dist/svelte/index.mjs +0 -11
- package/dist/workflow/index.mjs +0 -11
package/dist/base/index.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import*as j from"jose";import K from"crypto-js";var P=class extends Error{constructor(e){super(e),this.name="SignatureError"}},$=class{currentSigningKey;nextSigningKey;constructor(e){this.currentSigningKey=e.currentSigningKey,this.nextSigningKey=e.nextSigningKey}async verify(e){return await this.verifyWithKey(this.currentSigningKey,e)?!0:this.verifyWithKey(this.nextSigningKey,e)}async verifyWithKey(e,t){let n=(await j.jwtVerify(t.signature,new TextEncoder().encode(e),{issuer:"Upstash",clockTolerance:t.clockTolerance}).catch(a=>{throw new P(a.message)})).payload;if(t.url!==void 0&&n.sub!==t.url)throw new P(`invalid subject: ${n.sub}, want: ${t.url}`);let o=K.SHA256(t.body).toString(K.enc.Base64url),i=new RegExp(/=+$/);if(n.body.replace(i,"")!==o.replace(i,""))throw new P(`body hash does not match, want: ${n.body}, got: ${o}`);return!0}};var O=class{http;constructor(e){this.http=e}async listMessages(e){let t={...e?.filter,topicName:e?.filter?.urlGroup},s=await this.http.request({method:"GET",path:["v2","dlq"],query:{cursor:e?.cursor,count:e?.count,...t}});return{messages:s.messages.map(n=>({...n,urlGroup:n.topicName})),cursor:s.cursor}}async delete(e){return await this.http.request({method:"DELETE",path:["v2","dlq",e],parseResponseAsJson:!1})}async deleteMany(e){return await this.http.request({method:"DELETE",path:["v2","dlq"],headers:{"Content-Type":"application/json"},body:JSON.stringify({dlqIds:e.dlqIds})})}};var w=class extends Error{constructor(e){super(e),this.name="QstashError"}},N=class extends w{limit;remaining;reset;constructor(e){super(`Exceeded burst rate limit. ${JSON.stringify(e)} `),this.name="QstashRatelimitError",this.limit=e.limit,this.remaining=e.remaining,this.reset=e.reset}},L=class extends w{limitRequests;limitTokens;remainingRequests;remainingTokens;resetRequests;resetTokens;constructor(e){super(`Exceeded chat rate limit. ${JSON.stringify(e)} `),this.limitRequests=e["limit-requests"],this.limitTokens=e["limit-tokens"],this.remainingRequests=e["remaining-requests"],this.remainingTokens=e["remaining-tokens"],this.resetRequests=e["reset-requests"],this.resetTokens=e["reset-tokens"]}},q=class extends w{limit;remaining;reset;constructor(e){super(`Exceeded daily rate limit. ${JSON.stringify(e)} `),this.limit=e.limit,this.remaining=e.remaining,this.reset=e.reset,this.name="QstashChatRatelimitError"}},v=class extends w{constructor(e){super(e),this.name="QStashWorkflowError"}},E=class extends Error{stepInfo;stepName;constructor(e,t){super(`This is an QStash Workflow error thrown after a step executes. It is expected to be raised. Make sure that you await for each step. Also, if you are using try/catch blocks, you should not wrap context.run/sleep/sleepUntil/call methods with try/catch. Aborting workflow after executing step '${e}'.`),this.name="QStashWorkflowAbort",this.stepName=e,this.stepInfo=t}},te=r=>r instanceof Error?{error:r.name,message:r.message}:{error:"Error",message:"An error occured while executing workflow."};var W=class{baseUrl;authorization;options;retry;constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,""),this.authorization=e.authorization,this.retry=typeof e.retry=="boolean"&&!e.retry?{attempts:1,backoff:()=>0}:{attempts:e.retry?.retries?e.retry.retries+1:5,backoff:e.retry?.backoff??(t=>Math.exp(t)*50)}}async request(e){let{response:t}=await this.requestWithBackoff(e);if(e.parseResponseAsJson!==!1)return await t.json()}async*requestStream(e){let{response:t}=await this.requestWithBackoff(e);if(!t.body)throw new Error("No response body");let n=t.body.getReader(),o=new TextDecoder;try{for(;;){let{done:i,value:a}=await n.read();if(i)break;let c=o.decode(a,{stream:!0}).split(`
|
|
2
|
-
`).filter(Boolean);for(let u of c)if(u.startsWith("data: ")){let f=u.slice(6);if(f==="[DONE]")break;yield JSON.parse(f)}}}finally{await n.cancel()}}requestWithBackoff=async e=>{let[t,s]=this.processRequest(e),n,o;for(let i=0;i<this.retry.attempts;i++)try{n=await fetch(t.toString(),s);break}catch(a){o=a,await new Promise(p=>setTimeout(p,this.retry.backoff(i)))}if(!n)throw o??new Error("Exhausted all retries");return await this.checkResponse(n),{response:n,error:o}};processRequest=e=>{let t=new Headers(e.headers);t.has("Authorization")||t.set("Authorization",this.authorization);let s={method:e.method,headers:t,body:e.body,keepalive:e.keepalive},n=new URL([e.baseUrl??this.baseUrl,...e.path].join("/"));if(e.query)for(let[o,i]of Object.entries(e.query))i!==void 0&&n.searchParams.set(o,i.toString());return[n.toString(),s]};async checkResponse(e){if(e.status===429)throw e.headers.get("x-ratelimit-limit-requests")?new L({"limit-requests":e.headers.get("x-ratelimit-limit-requests"),"limit-tokens":e.headers.get("x-ratelimit-limit-tokens"),"remaining-requests":e.headers.get("x-ratelimit-remaining-requests"),"remaining-tokens":e.headers.get("x-ratelimit-remaining-tokens"),"reset-requests":e.headers.get("x-ratelimit-reset-requests"),"reset-tokens":e.headers.get("x-ratelimit-reset-tokens")}):e.headers.get("RateLimit-Limit")?new q({limit:e.headers.get("RateLimit-Limit"),remaining:e.headers.get("RateLimit-Remaining"),reset:e.headers.get("RateLimit-Reset")}):new N({limit:e.headers.get("Burst-RateLimit-Limit"),remaining:e.headers.get("Burst-RateLimit-Remaining"),reset:e.headers.get("Burst-RateLimit-Reset")});if(e.status<200||e.status>=300){let t=await e.text();throw new w(t.length>0?t:`Error: status=${e.status}`)}}};var S=(r,e,t,s)=>{if(!r)return{};switch(r.name){case"helicone":switch(s){case"upstash":return{baseURL:"https://qstash.helicone.ai/llm/v1/chat/completions",defaultHeaders:{"Helicone-Auth":`Bearer ${r.token}`,Authorization:`Bearer ${e}`}};default:return{baseURL:"https://gateway.helicone.ai/v1/chat/completions",defaultHeaders:{"Helicone-Auth":`Bearer ${r.token}`,"Helicone-Target-Url":t,Authorization:`Bearer ${e}`}}}default:throw new Error("Unknown analytics provider")}},Pe=()=>({owner:"upstash",baseUrl:"https://qstash.upstash.io/llm",token:""}),ve=({token:r})=>({token:r,owner:"openai",baseUrl:"https://api.openai.com"}),Ee=({baseUrl:r,token:e})=>{let t=r.replace(/\/(v1\/)?chat\/completions$/,"");return{token:e,owner:"custom",baseUrl:t}};var A=class r{http;token;constructor(e,t){this.http=e,this.token=t}static toChatRequest(e){let t=[];return t.push({role:"system",content:e.system},{role:"user",content:e.user}),{...e,messages:t}}create=async e=>{if(e.provider.owner!="upstash")return this.createThirdParty(e);let t=JSON.stringify(e),s,n={"Content-Type":"application/json",Authorization:`Bearer ${this.token}`,..."stream"in e&&e.stream?{Connection:"keep-alive",Accept:"text/event-stream","Cache-Control":"no-cache"}:{}};if(e.analytics){let{baseURL:i,defaultHeaders:a}=S({name:"helicone",token:e.analytics.token},this.getAuthorizationToken(),e.provider.baseUrl,"upstash");n={...n,...a},s=i}let o=e.analytics?[]:["llm","v1","chat","completions"];return"stream"in e&&e.stream?this.http.requestStream({path:o,method:"POST",headers:n,baseUrl:s,body:t}):this.http.request({path:o,method:"POST",headers:n,baseUrl:s,body:t})};createThirdParty=async e=>{let{baseUrl:t,token:s,owner:n}=e.provider;if(n==="upstash")throw new Error("Upstash is not 3rd party provider!");delete e.provider,delete e.system;let o=e.analytics;delete e.analytics;let i=JSON.stringify(e),a=o?.name&&o.token,p=o?.name&&o.token?S({name:o.name,token:o.token},s,t,n):{defaultHeaders:void 0,baseURL:t},c="stream"in e&&e.stream,u={"Content-Type":"application/json",Authorization:`Bearer ${s}`,...c?{Connection:"keep-alive",Accept:"text/event-stream","Cache-Control":"no-cache"}:{},...p.defaultHeaders};return await this.http[c?"requestStream":"request"]({path:a?[]:["v1","chat","completions"],method:"POST",headers:u,body:i,baseUrl:p.baseURL})};getAuthorizationToken(){let t=String(this.http.authorization).match(/Bearer (.+)/);if(!t)throw new Error("Invalid authorization header format");return t[1]}prompt=async e=>{let t=r.toChatRequest(e);return this.create(t)}};function C(r,e,t){if(!r.api)return;let s=r.api.provider,n=r.api.analytics;if(s?.owner==="upstash"){re(r,e,t,n);return}if(!("provider"in r.api))return;let{baseUrl:o,token:i}=se(s),a=n?S({name:n.name,token:n.token},i,o,"custom"):void 0;a?(z(e,a),r.url=a.baseURL):(r.url=`${o}/v1/chat/completions`,e.set("Authorization",`Bearer ${i}`))}function re(r,e,t,s){if(s){let n=S({name:s.name,token:s.token},String(t.authorization).split("Bearer ")[1],r.api?.provider?.baseUrl,"upstash");z(e,n),r.url=n.baseURL}else r.api={name:"llm"}}function se(r){if(!r?.baseUrl)throw new Error("baseUrl cannot be empty or undefined!");if(!r.token)throw new Error("token cannot be empty or undefined!");return{baseUrl:r.baseUrl,token:r.token}}function z(r,e){r.set("Helicone-Auth",e.defaultHeaders?.["Helicone-Auth"]??""),r.set("Authorization",e.defaultHeaders?.Authorization??""),e.defaultHeaders?.["Helicone-Target-Url"]&&r.set("Helicone-Target-Url",e.defaultHeaders["Helicone-Target-Url"])}function I(r){if(r.api?.name==="llm"&&!r.callback)throw new TypeError("Callback cannot be undefined when using LLM")}var _=class{http;constructor(e){this.http=e}async get(e){let t=await this.http.request({method:"GET",path:["v2","messages",e]});return{...t,urlGroup:t.topicName}}async delete(e){return await this.http.request({method:"DELETE",path:["v2","messages",e],parseResponseAsJson:!1})}async deleteMany(e){return(await this.http.request({method:"DELETE",path:["v2","messages"],headers:{"Content-Type":"application/json"},body:JSON.stringify({messageIds:e})})).cancelled}async deleteAll(){return(await this.http.request({method:"DELETE",path:["v2","messages"]})).cancelled}};var ne=r=>{let e=r.toLowerCase();return e.startsWith("content-type")||e.startsWith("upstash-")};function b(r){let e=[...r.keys()].filter(t=>!ne(t));for(let t of e){let s=r.get(t);s!==null&&r.set(`Upstash-Forward-${t}`,s),r.delete(t)}return r}function x(r){let e=b(new Headers(r.headers));return e.set("Upstash-Method",r.method??"POST"),r.delay!==void 0&&(typeof r.delay=="string"?e.set("Upstash-Delay",r.delay):e.set("Upstash-Delay",`${r.delay.toFixed(0)}s`)),r.notBefore!==void 0&&e.set("Upstash-Not-Before",r.notBefore.toFixed(0)),r.deduplicationId!==void 0&&e.set("Upstash-Deduplication-Id",r.deduplicationId),r.contentBasedDeduplication!==void 0&&e.set("Upstash-Content-Based-Deduplication","true"),r.retries!==void 0&&e.set("Upstash-Retries",r.retries.toFixed(0)),r.callback!==void 0&&e.set("Upstash-Callback",r.callback),r.failureCallback!==void 0&&e.set("Upstash-Failure-Callback",r.failureCallback),r.timeout!==void 0&&(typeof r.timeout=="string"?e.set("Upstash-Timeout",r.timeout):e.set("Upstash-Timeout",`${r.timeout}s`)),e}function U(r){return r.url??r.urlGroup??r.topic??`api/${r.api?.name}`}var F=class{http;queueName;constructor(e,t){this.http=e,this.queueName=t}async upsert(e){if(!this.queueName)throw new Error("Please provide a queue name to the Queue constructor");let t={queueName:this.queueName,parallelism:e.parallelism??1,paused:e.paused??!1};await this.http.request({method:"POST",path:["v2","queues"],headers:{"Content-Type":"application/json"},body:JSON.stringify(t),parseResponseAsJson:!1})}async get(){if(!this.queueName)throw new Error("Please provide a queue name to the Queue constructor");return await this.http.request({method:"GET",path:["v2","queues",this.queueName]})}async list(){return await this.http.request({method:"GET",path:["v2","queues"]})}async delete(){if(!this.queueName)throw new Error("Please provide a queue name to the Queue constructor");await this.http.request({method:"DELETE",path:["v2","queues",this.queueName],parseResponseAsJson:!1})}async enqueue(e){if(!this.queueName)throw new Error("Please provide a queue name to the Queue constructor");let t=x(e),s=U(e);return await this.http.request({path:["v2","enqueue",this.queueName,s],body:e.body,headers:t,method:"POST"})}async enqueueJSON(e){let t=b(new Headers(e.headers));return t.set("Content-Type","application/json"),I(e),C(e,t,this.http),await this.enqueue({...e,body:JSON.stringify(e.body),headers:t})}async pause(){if(!this.queueName)throw new Error("Please provide a queue name to the Queue constructor");await this.http.request({method:"POST",path:["v2","queues",this.queueName,"pause"],parseResponseAsJson:!1})}async resume(){if(!this.queueName)throw new Error("Please provide a queue name to the Queue constructor");await this.http.request({method:"POST",path:["v2","queues",this.queueName,"resume"],parseResponseAsJson:!1})}};var H=class{http;constructor(e){this.http=e}async create(e){let t=b(new Headers(e.headers));return t.has("Content-Type")||t.set("Content-Type","application/json"),t.set("Upstash-Cron",e.cron),e.method!==void 0&&t.set("Upstash-Method",e.method),e.delay!==void 0&&(typeof e.delay=="string"?t.set("Upstash-Delay",e.delay):t.set("Upstash-Delay",`${e.delay.toFixed(0)}s`)),e.retries!==void 0&&t.set("Upstash-Retries",e.retries.toFixed(0)),e.callback!==void 0&&t.set("Upstash-Callback",e.callback),e.failureCallback!==void 0&&t.set("Upstash-Failure-Callback",e.failureCallback),e.timeout!==void 0&&(typeof e.timeout=="string"?t.set("Upstash-Timeout",e.timeout):t.set("Upstash-Timeout",`${e.timeout}s`)),e.scheduleId!==void 0&&t.set("Upstash-Schedule-Id",e.scheduleId),await this.http.request({method:"POST",headers:t,path:["v2","schedules",e.destination],body:e.body})}async get(e){return await this.http.request({method:"GET",path:["v2","schedules",e]})}async list(){return await this.http.request({method:"GET",path:["v2","schedules"]})}async delete(e){return await this.http.request({method:"DELETE",path:["v2","schedules",e],parseResponseAsJson:!1})}async pause({schedule:e}){await this.http.request({method:"PATCH",path:["v2","schedules",e,"pause"],parseResponseAsJson:!1})}async resume({schedule:e}){await this.http.request({method:"PATCH",path:["v2","schedules",e,"resume"],parseResponseAsJson:!1})}};var B=class{http;constructor(e){this.http=e}async addEndpoints(e){await this.http.request({method:"POST",path:["v2","topics",e.name,"endpoints"],headers:{"Content-Type":"application/json"},body:JSON.stringify({endpoints:e.endpoints}),parseResponseAsJson:!1})}async removeEndpoints(e){await this.http.request({method:"DELETE",path:["v2","topics",e.name,"endpoints"],headers:{"Content-Type":"application/json"},body:JSON.stringify({endpoints:e.endpoints}),parseResponseAsJson:!1})}async list(){return await this.http.request({method:"GET",path:["v2","topics"]})}async get(e){return await this.http.request({method:"GET",path:["v2","topics",e]})}async delete(e){return await this.http.request({method:"DELETE",path:["v2","topics",e],parseResponseAsJson:!1})}};var oe={withStackTrace:!1},Y=(r,e,t=oe)=>{let s=e.isOk()?{type:"Ok",value:e.value}:{type:"Err",value:e.error},n=t.withStackTrace?new Error().stack:void 0;return{data:s,message:r,stack:n}};function k(r,e,t,s){function n(o){return o instanceof t?o:new t(function(i){i(o)})}return new(t||(t=Promise))(function(o,i){function a(u){try{c(s.next(u))}catch(f){i(f)}}function p(u){try{c(s.throw(u))}catch(f){i(f)}}function c(u){u.done?o(u.value):n(u.value).then(a,p)}c((s=s.apply(r,[])).next())})}function V(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],s=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&s>=r.length&&(r=void 0),{value:r&&r[s++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function R(r){return this instanceof R?(this.v=r,this):new R(r)}function ie(r,e,t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var s=t.apply(r,e||[]),n,o=[];return n={},i("next"),i("throw"),i("return"),n[Symbol.asyncIterator]=function(){return this},n;function i(l){s[l]&&(n[l]=function(T){return new Promise(function(G,ee){o.push([l,T,G,ee])>1||a(l,T)})})}function a(l,T){try{p(s[l](T))}catch(G){f(o[0][3],G)}}function p(l){l.value instanceof R?Promise.resolve(l.value.v).then(c,u):f(o[0][2],l)}function c(l){a("next",l)}function u(l){a("throw",l)}function f(l,T){l(T),o.shift(),o.length&&a(o[0][0],o[0][1])}}function ae(r){var e,t;return e={},s("next"),s("throw",function(n){throw n}),s("return"),e[Symbol.iterator]=function(){return this},e;function s(n,o){e[n]=r[n]?function(i){return(t=!t)?{value:R(r[n](i)),done:n==="return"}:o?o(i):i}:o}}function le(r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=r[Symbol.asyncIterator],t;return e?e.call(r):(r=typeof V=="function"?V(r):r[Symbol.iterator](),t={},s("next"),s("throw"),s("return"),t[Symbol.asyncIterator]=function(){return this},t);function s(o){t[o]=r[o]&&function(i){return new Promise(function(a,p){i=r[o](i),n(a,p,i.done,i.value)})}}function n(o,i,a,p){Promise.resolve(p).then(function(c){o({value:c,done:a})},i)}}var g=class r{constructor(e){this._promise=e}static fromSafePromise(e){let t=e.then(s=>new m(s));return new r(t)}static fromPromise(e,t){let s=e.then(n=>new m(n)).catch(n=>new d(t(n)));return new r(s)}static fromThrowable(e,t){return(...s)=>new r(k(this,void 0,void 0,function*(){try{return new m(yield e(...s))}catch(n){return new d(t?t(n):n)}}))}static combine(e){return ue(e)}static combineWithAllErrors(e){return pe(e)}map(e){return new r(this._promise.then(t=>k(this,void 0,void 0,function*(){return t.isErr()?new d(t.error):new m(yield e(t.value))})))}andThrough(e){return new r(this._promise.then(t=>k(this,void 0,void 0,function*(){if(t.isErr())return new d(t.error);let s=yield e(t.value);return s.isErr()?new d(s.error):new m(t.value)})))}andTee(e){return new r(this._promise.then(t=>k(this,void 0,void 0,function*(){if(t.isErr())return new d(t.error);try{yield e(t.value)}catch{}return new m(t.value)})))}mapErr(e){return new r(this._promise.then(t=>k(this,void 0,void 0,function*(){return t.isOk()?new m(t.value):new d(yield e(t.error))})))}andThen(e){return new r(this._promise.then(t=>{if(t.isErr())return new d(t.error);let s=e(t.value);return s instanceof r?s._promise:s}))}orElse(e){return new r(this._promise.then(t=>k(this,void 0,void 0,function*(){return t.isErr()?e(t.error):new m(t.value)})))}match(e,t){return this._promise.then(s=>s.match(e,t))}unwrapOr(e){return this._promise.then(t=>t.unwrapOr(e))}safeUnwrap(){return ie(this,arguments,function*(){return yield R(yield R(yield*ae(le(yield R(this._promise.then(t=>t.safeUnwrap()))))))})}then(e,t){return this._promise.then(e,t)}};var J=r=>new g(Promise.resolve(new d(r))),Be=g.fromPromise,De=g.fromSafePromise,Me=g.fromThrowable,X=r=>{let e=y([]);for(let t of r)if(t.isErr()){e=h(t.error);break}else e.map(s=>s.push(t.value));return e},ue=r=>g.fromSafePromise(Promise.all(r)).andThen(X),Z=r=>{let e=y([]);for(let t of r)t.isErr()&&e.isErr()?e.error.push(t.error):t.isErr()&&e.isOk()?e=h([t.error]):t.isOk()&&e.isOk()&&e.value.push(t.value);return e},pe=r=>g.fromSafePromise(Promise.all(r)).andThen(Z),Q;(function(r){function e(n,o){return(...i)=>{try{let a=n(...i);return y(a)}catch(a){return h(o?o(a):a)}}}r.fromThrowable=e;function t(n){return X(n)}r.combine=t;function s(n){return Z(n)}r.combineWithAllErrors=s})(Q||(Q={}));var y=r=>new m(r);function h(r){return new d(r)}var m=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return y(e(this.value))}mapErr(e){return y(this.value)}andThen(e){return e(this.value)}andThrough(e){return e(this.value).map(t=>this.value)}andTee(e){try{e(this.value)}catch{}return y(this.value)}orElse(e){return y(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return g.fromSafePromise(e(this.value))}unwrapOr(e){return this.value}match(e,t){return e(this.value)}safeUnwrap(){let e=this.value;return function*(){return e}()}_unsafeUnwrap(e){return this.value}_unsafeUnwrapErr(e){throw Y("Called `_unsafeUnwrapErr` on an Ok",this,e)}},d=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return h(this.error)}mapErr(e){return h(e(this.error))}andThrough(e){return h(this.error)}andTee(e){return h(this.error)}andThen(e){return h(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return J(this.error)}asyncAndThrough(e){return J(this.error)}asyncMap(e){return J(this.error)}unwrapOr(e){return e}match(e,t){return t(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield h(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw Y("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}},Ge=Q.fromThrowable;var M=class{http;constructor(e){this.http=e}async cancel(e){return await this.http.request({path:["v2","workflows","runs",`${e}?cancel=true`],method:"DELETE",parseResponseAsJson:!1})??!0}};var D=class{http;token;constructor(e){this.http=new W({retry:e.retry,baseUrl:e.baseUrl?e.baseUrl.replace(/\/$/,""):"https://qstash.upstash.io",authorization:`Bearer ${e.token}`}),this.token=e.token}get urlGroups(){return new B(this.http)}get topics(){return this.urlGroups}get dlq(){return new O(this.http)}get messages(){return new _(this.http)}get schedules(){return new H(this.http)}get workflow(){return new M(this.http)}queue(e){return new F(this.http,e?.queueName)}chat(){return new A(this.http,this.token)}async publish(e){let t=x(e);return await this.http.request({path:["v2","publish",U(e)],body:e.body,headers:t,method:"POST"})}async publishJSON(e){let t=b(new Headers(e.headers));return t.set("Content-Type","application/json"),I(e),C(e,t,this.http),await this.publish({...e,headers:t,body:JSON.stringify(e.body)})}async batch(e){let t=[];for(let o of e){let i=x(o),a=Object.fromEntries(i.entries());t.push({destination:U(o),headers:a,body:o.body,...o.queueName&&{queue:o.queueName}})}let s=await this.http.request({path:["v2","batch"],body:JSON.stringify(t),headers:{"Content-Type":"application/json"},method:"POST"});return Array.isArray(s)?s:[s]}async batchJSON(e){for(let s of e)"body"in s&&(s.body=JSON.stringify(s.body)),s.headers=new Headers(s.headers),I(s),C(s,s.headers,this.http),s.headers.set("Content-Type","application/json");return await this.batch(e)}async events(e){let t={};e?.cursor&&e.cursor>0&&(t.cursor=e.cursor.toString());for(let[n,o]of Object.entries(e?.filter??{}))typeof o=="number"&&o<0||(n==="urlGroup"?t.topicName=o.toString():typeof o<"u"&&(t[n]=o.toString()));let s=await this.http.request({path:["v2","events"],method:"GET",query:t});return{cursor:s.cursor,events:s.events.map(n=>({...n,urlGroup:n.topicName}))}}};export{A as Chat,D as Client,_ as Messages,E as QStashWorkflowAbort,v as QStashWorkflowError,L as QstashChatRatelimitError,q as QstashDailyRatelimitError,w as QstashError,N as QstashRatelimitError,$ as Receiver,H as Schedules,P as SignatureError,B as UrlGroups,Ee as custom,te as formatWorkflowError,ve as openai,S as setupAnalytics,Pe as upstash};
|