@upstash/qstash
Advanced tools
Comparing version 0.0.0-ci.c6d6062c8eb056e3898644acce464783c7251ff2-20241031073348 to 0.0.0-ci.ca28bc08443ea6af297ba7c95ff1628eee9acadb-20241202182308
@@ -1,2 +0,2 @@ | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-kxUsvnWj.js'; | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-Dq99U_Dk.js'; | ||
import 'neverthrow'; | ||
@@ -30,2 +30,6 @@ | ||
* @returns | ||
* | ||
* @deprecated as of version 2.7.17. Will be removed in qstash-js 3.0.0. | ||
* Please use https://github.com/upstash/workflow-js | ||
* Migration Guide: https://upstash.com/docs/workflow/migration | ||
*/ | ||
@@ -32,0 +36,0 @@ declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) => ((...args: PagesHandlerArgs | WorkersHandlerArgs) => Promise<Response>); |
import * as h3 from 'h3'; | ||
import { H3Event } from 'h3'; | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-kxUsvnWj.js'; | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-Dq99U_Dk.js'; | ||
import 'neverthrow'; | ||
@@ -12,2 +12,7 @@ | ||
declare const verifySignatureH3: (handler: (event: H3Event) => Promise<unknown>, config?: VerifySignatureConfig) => h3.EventHandler<h3.EventHandlerRequest, Promise<unknown>>; | ||
/** | ||
* @deprecated as of version 2.7.17. Will be removed in qstash-js 3.0.0. | ||
* Please use https://github.com/upstash/workflow-js | ||
* Migration Guide: https://upstash.com/docs/workflow/migration | ||
*/ | ||
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) => h3.EventHandler<h3.EventHandlerRequest, Promise<Response | { | ||
@@ -14,0 +19,0 @@ status: number; |
import { Context } from 'hono'; | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-kxUsvnWj.js'; | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-Dq99U_Dk.js'; | ||
import 'neverthrow'; | ||
@@ -20,2 +20,6 @@ | ||
* @returns | ||
* | ||
* @deprecated as of version 2.7.17. Will be removed in qstash-js 3.0.0. | ||
* Please use https://github.com/upstash/workflow-js | ||
* Migration Guide: https://upstash.com/docs/workflow/migration | ||
*/ | ||
@@ -22,0 +26,0 @@ declare const serve: <TInitialPayload = unknown, TBindings extends WorkflowBindings = WorkflowBindings>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) => ((context: Context<{ |
@@ -1,5 +0,6 @@ | ||
import { R as RateLimit, C as ChatRateLimit, S as Step, F as FailureFunctionPayload } from './client-kxUsvnWj.js'; | ||
export { A as AddEndpointsRequest, $ as AnalyticsConfig, a0 as AnalyticsSetup, B as BodyInit, y as Chat, D as ChatCompletion, I as ChatCompletionChunk, z as ChatCompletionMessage, T as ChatRequest, f as Client, n as CreateScheduleRequest, p as Endpoint, t as Event, u as EventPayload, E as EventsRequest, v as GetEventsPayload, G as GetEventsResponse, H as HTTPMethods, w as HeadersInit, M as Message, k as MessagePayload, l as Messages, O as OpenAIChatModel, N as PromptChatRequest, _ as ProviderReturnType, P as PublishBatchRequest, e as PublishJsonRequest, d as PublishRequest, j as PublishResponse, g as PublishToApiResponse, i as PublishToUrlGroupsResponse, h as PublishToUrlResponse, Q as QueueRequest, c as Receiver, a as ReceiverConfig, q as RemoveEndpointsRequest, x as RequestOptions, m as Schedule, o as Schedules, b as SignatureError, s as State, K as StreamDisabled, J as StreamEnabled, L as StreamParameter, U as UrlGroup, r as UrlGroups, V as VerifyRequest, W as WithCursor, X as custom, Y as openai, a2 as resend, a1 as setupAnalytics, Z as upstash } from './client-kxUsvnWj.js'; | ||
import { R as RateLimit, C as ChatRateLimit, S as Step, F as FailureFunctionPayload, L as LLMOwner, B as BaseProvider, E as EmailOwner, P as ProviderInfo } from './client-Dq99U_Dk.js'; | ||
export { A as AddEndpointsRequest, y as BodyInit, I as Chat, K as ChatCompletion, N as ChatCompletionChunk, J as ChatCompletionMessage, _ as ChatRequest, h as Client, p as CreateScheduleRequest, r as Endpoint, v as Event, w as EventPayload, g as EventsRequest, x as GetEventsPayload, G as GetEventsResponse, H as HTTPMethods, z as HeadersInit, M as Message, m as MessagePayload, n as Messages, Y as OpenAIChatModel, Z as PromptChatRequest, d as PublishBatchRequest, f as PublishJsonRequest, e as PublishRequest, l as PublishResponse, i as PublishToApiResponse, k as PublishToUrlGroupsResponse, j as PublishToUrlResponse, Q as QueueRequest, c as Receiver, a as ReceiverConfig, s as RemoveEndpointsRequest, D as RequestOptions, o as Schedule, q as Schedules, b as SignatureError, u as State, T as StreamDisabled, O as StreamEnabled, X as StreamParameter, U as UrlGroup, t as UrlGroups, V as VerifyRequest, W as WithCursor, a1 as anthropic, a2 as custom, a0 as openai, $ as upstash } from './client-Dq99U_Dk.js'; | ||
import 'neverthrow'; | ||
declare const RATELIMIT_STATUS = 429; | ||
/** | ||
@@ -9,3 +10,4 @@ * Result of 500 Internal Server Error | ||
declare class QstashError extends Error { | ||
constructor(message: string); | ||
readonly status?: number; | ||
constructor(message: string, status?: number); | ||
} | ||
@@ -68,2 +70,25 @@ declare class QstashRatelimitError extends QstashError { | ||
export { ChatRateLimit, QStashWorkflowAbort, QStashWorkflowError, QstashChatRatelimitError, QstashDailyRatelimitError, QstashError, QstashRatelimitError, RateLimit, decodeBase64, formatWorkflowError }; | ||
type AnalyticsConfig = { | ||
name: "helicone"; | ||
token: string; | ||
}; | ||
type AnalyticsSetup = { | ||
baseURL?: string; | ||
defaultHeaders?: Record<string, string | undefined>; | ||
}; | ||
declare const setupAnalytics: (analytics: AnalyticsConfig | undefined, providerApiKey: string, providerBaseUrl?: string, provider?: LLMOwner) => AnalyticsSetup; | ||
declare class EmailProvider extends BaseProvider<"email", EmailOwner> { | ||
readonly apiKind = "email"; | ||
readonly batch: boolean; | ||
constructor(baseUrl: string, token: string, owner: EmailOwner, batch: boolean); | ||
getRoute(): string[]; | ||
getHeaders(_options: unknown): Record<string, string>; | ||
onFinish(providerInfo: ProviderInfo, _options: unknown): ProviderInfo; | ||
} | ||
declare const resend: ({ token, batch, }: { | ||
token: string; | ||
batch?: boolean; | ||
}) => EmailProvider; | ||
export { ChatRateLimit, QStashWorkflowAbort, QStashWorkflowError, QstashChatRatelimitError, QstashDailyRatelimitError, QstashError, QstashRatelimitError, RATELIMIT_STATUS, RateLimit, decodeBase64, formatWorkflowError, resend, setupAnalytics }; |
373
index.js
@@ -42,2 +42,3 @@ "use strict"; | ||
QstashRatelimitError: () => QstashRatelimitError, | ||
RATELIMIT_STATUS: () => RATELIMIT_STATUS, | ||
Receiver: () => Receiver, | ||
@@ -47,2 +48,3 @@ Schedules: () => Schedules, | ||
UrlGroups: () => UrlGroups, | ||
anthropic: () => anthropic, | ||
custom: () => custom, | ||
@@ -118,10 +120,2 @@ decodeBase64: () => decodeBase64, | ||
// src/client/api/utils.ts | ||
var appendAPIOptions = (request, headers) => { | ||
if (request.api?.name === "email") { | ||
headers.set("Authorization", request.api.provider.token); | ||
request.method = request.method ?? "POST"; | ||
} | ||
}; | ||
// src/client/dlq.ts | ||
@@ -185,6 +179,9 @@ var DLQ = class { | ||
// src/client/error.ts | ||
var RATELIMIT_STATUS = 429; | ||
var QstashError = class extends Error { | ||
constructor(message) { | ||
status; | ||
constructor(message, status) { | ||
super(message); | ||
this.name = "QstashError"; | ||
this.status = status; | ||
} | ||
@@ -197,3 +194,3 @@ }; | ||
constructor(args) { | ||
super(`Exceeded burst rate limit. ${JSON.stringify(args)} `); | ||
super(`Exceeded burst rate limit. ${JSON.stringify(args)}`, RATELIMIT_STATUS); | ||
this.name = "QstashRatelimitError"; | ||
@@ -213,3 +210,4 @@ this.limit = args.limit; | ||
constructor(args) { | ||
super(`Exceeded chat rate limit. ${JSON.stringify(args)} `); | ||
super(`Exceeded chat rate limit. ${JSON.stringify(args)}`, RATELIMIT_STATUS); | ||
this.name = "QstashChatRatelimitError"; | ||
this.limitRequests = args["limit-requests"]; | ||
@@ -228,7 +226,7 @@ this.limitTokens = args["limit-tokens"]; | ||
constructor(args) { | ||
super(`Exceeded daily rate limit. ${JSON.stringify(args)} `); | ||
super(`Exceeded daily rate limit. ${JSON.stringify(args)}`, RATELIMIT_STATUS); | ||
this.name = "QstashDailyRatelimitError"; | ||
this.limit = args.limit; | ||
this.remaining = args.remaining; | ||
this.reset = args.reset; | ||
this.name = "QstashChatRatelimitError"; | ||
} | ||
@@ -276,6 +274,8 @@ }; | ||
attempts: 1, | ||
backoff: () => 0 | ||
backoff: () => 0, | ||
ratelimitBackoff: () => 0 | ||
} : { | ||
attempts: config.retry?.retries ? config.retry.retries + 1 : 5, | ||
backoff: config.retry?.backoff ?? ((retryCount) => Math.exp(retryCount) * 50) | ||
attempts: config.retry?.retries ?? 5, | ||
backoff: config.retry?.backoff ?? ((retryCount) => Math.exp(retryCount) * 50), | ||
ratelimitBackoff: config.retry?.ratelimitBackoff ?? ((lastBackoff) => Math.max(lastBackoff, Math.random() * 4e3) + 1e3) | ||
}; | ||
@@ -324,9 +324,21 @@ } | ||
let error = void 0; | ||
for (let index = 0; index < this.retry.attempts; index++) { | ||
let ratelimitBackoff = 0; | ||
for (let index = 0; index <= this.retry.attempts; index++) { | ||
try { | ||
response = await fetch(url.toString(), requestOptions); | ||
await this.checkResponse(response); | ||
break; | ||
} catch (error_) { | ||
error = error_; | ||
await new Promise((r) => setTimeout(r, this.retry.backoff(index))); | ||
if (index < this.retry.attempts) { | ||
if (error instanceof QstashError && error.status === RATELIMIT_STATUS) { | ||
ratelimitBackoff = this.retry.ratelimitBackoff(index); | ||
console.warn( | ||
`QStash Ratelimit Exceeded. Retrying after ${ratelimitBackoff} milliseconds. ${error.message}` | ||
); | ||
await new Promise((r) => setTimeout(r, ratelimitBackoff)); | ||
} else { | ||
await new Promise((r) => setTimeout(r, this.retry.backoff(index))); | ||
} | ||
} | ||
} | ||
@@ -337,3 +349,2 @@ } | ||
} | ||
await this.checkResponse(response); | ||
return { | ||
@@ -366,3 +377,3 @@ response, | ||
async checkResponse(response) { | ||
if (response.status === 429) { | ||
if (response.status === RATELIMIT_STATUS) { | ||
if (response.headers.get("x-ratelimit-limit-requests")) { | ||
@@ -392,3 +403,6 @@ throw new QstashChatRatelimitError({ | ||
const body = await response.text(); | ||
throw new QstashError(body.length > 0 ? body : `Error: status=${response.status}`); | ||
throw new QstashError( | ||
body.length > 0 ? body : `Error: status=${response.status}`, | ||
response.status | ||
); | ||
} | ||
@@ -431,33 +445,2 @@ } | ||
}; | ||
var upstash = () => { | ||
return { | ||
owner: "upstash", | ||
baseUrl: "https://qstash.upstash.io/llm", | ||
token: "", | ||
organization: void 0 | ||
}; | ||
}; | ||
var openai = ({ | ||
token, | ||
organization | ||
}) => { | ||
return { | ||
token, | ||
owner: "openai", | ||
baseUrl: "https://api.openai.com", | ||
organization | ||
}; | ||
}; | ||
var custom = ({ | ||
baseUrl, | ||
token | ||
}) => { | ||
const trimmedBaseUrl = baseUrl.replace(/\/(v1\/)?chat\/completions$/, ""); | ||
return { | ||
token, | ||
owner: "custom", | ||
baseUrl: trimmedBaseUrl, | ||
organization: void 0 | ||
}; | ||
}; | ||
@@ -538,3 +521,2 @@ // src/client/llm/chat.ts | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/require-await | ||
createThirdParty = async (request) => { | ||
@@ -600,59 +582,2 @@ const { baseUrl, token, owner, organization } = request.provider; | ||
// src/client/llm/utils.ts | ||
function appendLLMOptionsIfNeeded(request, headers, http) { | ||
if (request.api?.name === "email" || !request.api) | ||
return; | ||
const provider = request.api.provider; | ||
const analytics = request.api.analytics; | ||
if (provider?.owner === "upstash") { | ||
handleUpstashProvider(request, headers, http, analytics); | ||
return; | ||
} | ||
if (!("provider" in request.api)) | ||
return; | ||
const { baseUrl, token } = validateProviderConfig(provider); | ||
const analyticsConfig = analytics ? setupAnalytics({ name: analytics.name, token: analytics.token }, token, baseUrl, "custom") : void 0; | ||
if (analyticsConfig) { | ||
setAnalyticsHeaders(headers, analyticsConfig); | ||
request.url = analyticsConfig.baseURL; | ||
} else { | ||
request.url = `${baseUrl}/v1/chat/completions`; | ||
headers.set("Authorization", `Bearer ${token}`); | ||
} | ||
} | ||
function handleUpstashProvider(request, headers, http, analytics) { | ||
if (analytics) { | ||
const analyticsConfig = setupAnalytics( | ||
{ name: analytics.name, token: analytics.token }, | ||
//@ts-expect-error hacky way to get bearer token | ||
String(http.authorization).split("Bearer ")[1], | ||
request.api?.provider?.baseUrl, | ||
"upstash" | ||
); | ||
setAnalyticsHeaders(headers, analyticsConfig); | ||
request.url = analyticsConfig.baseURL; | ||
} else { | ||
request.api = { name: "llm" }; | ||
} | ||
} | ||
function validateProviderConfig(provider) { | ||
if (!provider?.baseUrl) | ||
throw new Error("baseUrl cannot be empty or undefined!"); | ||
if (!provider.token) | ||
throw new Error("token cannot be empty or undefined!"); | ||
return { baseUrl: provider.baseUrl, token: provider.token }; | ||
} | ||
function setAnalyticsHeaders(headers, analyticsConfig) { | ||
headers.set("Helicone-Auth", analyticsConfig.defaultHeaders?.["Helicone-Auth"] ?? ""); | ||
headers.set("Authorization", analyticsConfig.defaultHeaders?.Authorization ?? ""); | ||
if (analyticsConfig.defaultHeaders?.["Helicone-Target-Url"]) { | ||
headers.set("Helicone-Target-Url", analyticsConfig.defaultHeaders["Helicone-Target-Url"]); | ||
} | ||
} | ||
function ensureCallbackPresent(request) { | ||
if (request.api?.name === "llm" && !request.callback) { | ||
throw new TypeError("Callback cannot be undefined when using LLM"); | ||
} | ||
} | ||
// src/client/messages.ts | ||
@@ -706,2 +631,159 @@ var Messages = class { | ||
// src/client/api/base.ts | ||
var BaseProvider = class { | ||
baseUrl; | ||
token; | ||
owner; | ||
constructor(baseUrl, token, owner) { | ||
this.baseUrl = baseUrl; | ||
this.token = token; | ||
this.owner = owner; | ||
} | ||
getUrl() { | ||
return `${this.baseUrl}/${this.getRoute().join("/")}`; | ||
} | ||
}; | ||
// src/client/api/llm.ts | ||
var LLMProvider = class extends BaseProvider { | ||
apiKind = "llm"; | ||
organization; | ||
constructor(baseUrl, token, owner, organization) { | ||
super(baseUrl, token, owner); | ||
this.organization = organization; | ||
} | ||
getRoute() { | ||
return this.owner === "anthropic" ? ["v1", "messages"] : ["v1", "chat", "completions"]; | ||
} | ||
getHeaders(options) { | ||
if (this.owner === "upstash" && !options.analytics) { | ||
return { "content-type": "application/json" }; | ||
} | ||
const header = this.owner === "anthropic" ? "x-api-key" : "authorization"; | ||
const headerValue = this.owner === "anthropic" ? this.token : `Bearer ${this.token}`; | ||
const headers = { | ||
[header]: headerValue, | ||
"content-type": "application/json" | ||
}; | ||
if (this.owner === "openai" && this.organization) { | ||
headers["OpenAI-Organization"] = this.organization; | ||
} | ||
return headers; | ||
} | ||
/** | ||
* Checks if callback exists and adds analytics in place if it's set. | ||
* | ||
* @param request | ||
* @param options | ||
*/ | ||
onFinish(providerInfo, options) { | ||
if (options.analytics) { | ||
return updateWithAnalytics(providerInfo, options.analytics); | ||
} | ||
return providerInfo; | ||
} | ||
}; | ||
var upstash = () => { | ||
return new LLMProvider("https://qstash.upstash.io/llm", "", "upstash"); | ||
}; | ||
var openai = ({ | ||
token, | ||
organization | ||
}) => { | ||
return new LLMProvider("https://api.openai.com", token, "openai", organization); | ||
}; | ||
var anthropic = ({ token }) => { | ||
return new LLMProvider("https://api.anthropic.com", token, "anthropic"); | ||
}; | ||
var custom = ({ | ||
baseUrl, | ||
token | ||
}) => { | ||
const trimmedBaseUrl = baseUrl.replace(/\/(v1\/)?chat\/completions$/, ""); | ||
return new LLMProvider(trimmedBaseUrl, token, "custom"); | ||
}; | ||
// src/client/api/utils.ts | ||
var getProviderInfo = (api, upstashToken) => { | ||
const { name, provider, ...parameters } = api; | ||
const finalProvider = provider ?? upstash(); | ||
if (finalProvider.owner === "upstash" && !finalProvider.token) { | ||
finalProvider.token = upstashToken; | ||
} | ||
if (!finalProvider.baseUrl) | ||
throw new TypeError("baseUrl cannot be empty or undefined!"); | ||
if (!finalProvider.token) | ||
throw new TypeError("token cannot be empty or undefined!"); | ||
if (finalProvider.apiKind !== name) { | ||
throw new TypeError( | ||
`Unexpected api name. Expected '${finalProvider.apiKind}', received ${name}` | ||
); | ||
} | ||
const providerInfo = { | ||
url: finalProvider.getUrl(), | ||
baseUrl: finalProvider.baseUrl, | ||
route: finalProvider.getRoute(), | ||
appendHeaders: finalProvider.getHeaders(parameters), | ||
owner: finalProvider.owner | ||
}; | ||
return finalProvider.onFinish(providerInfo, parameters); | ||
}; | ||
var processApi = (request, upstashToken) => { | ||
if (!request.api) { | ||
return request; | ||
} | ||
const { url, appendHeaders, owner } = getProviderInfo(request.api, upstashToken); | ||
if (request.api.name === "llm") { | ||
const callback = request.callback; | ||
if (!callback) { | ||
throw new TypeError("Callback cannot be undefined when using LLM api."); | ||
} | ||
return { | ||
...request, | ||
// @ts-expect-error undici header conflict | ||
headers: new Headers({ | ||
...request.headers, | ||
...appendHeaders | ||
}), | ||
...owner === "upstash" && !request.api.analytics ? { api: { name: "llm" }, url: void 0, callback } : { url, api: void 0 } | ||
}; | ||
} else { | ||
return { | ||
...request, | ||
// @ts-expect-error undici header conflict | ||
headers: new Headers({ | ||
...request.headers, | ||
...appendHeaders | ||
}), | ||
url, | ||
api: void 0 | ||
}; | ||
} | ||
}; | ||
function updateWithAnalytics(providerInfo, analytics) { | ||
switch (analytics.name) { | ||
case "helicone": { | ||
providerInfo.appendHeaders["Helicone-Auth"] = `Bearer ${analytics.token}`; | ||
if (providerInfo.owner === "upstash") { | ||
updateProviderInfo(providerInfo, "https://qstash.helicone.ai", [ | ||
"llm", | ||
...providerInfo.route | ||
]); | ||
} else { | ||
providerInfo.appendHeaders["Helicone-Target-Url"] = providerInfo.baseUrl; | ||
updateProviderInfo(providerInfo, "https://gateway.helicone.ai", providerInfo.route); | ||
} | ||
return providerInfo; | ||
} | ||
default: { | ||
throw new Error("Unknown analytics provider"); | ||
} | ||
} | ||
} | ||
function updateProviderInfo(providerInfo, baseUrl, route) { | ||
providerInfo.baseUrl = baseUrl; | ||
providerInfo.route = route; | ||
providerInfo.url = `${baseUrl}/${route.join("/")}`; | ||
} | ||
// src/client/utils.ts | ||
@@ -765,5 +847,6 @@ var isIgnoredHeader = (header) => { | ||
if (request.api?.name === "llm") | ||
return `api/${request.api.name}`; | ||
return `api/llm`; | ||
if (request.api?.name === "email") { | ||
return request.api.provider.baseUrl; | ||
const providerInfo = getProviderInfo(request.api, "not-needed"); | ||
return providerInfo.baseUrl; | ||
} | ||
@@ -880,8 +963,8 @@ throw new QstashError(`Failed to infer request path for ${JSON.stringify(request)}`); | ||
headers.set("Content-Type", "application/json"); | ||
ensureCallbackPresent(request); | ||
appendLLMOptionsIfNeeded(request, headers, this.http); | ||
appendAPIOptions(request, headers); | ||
request.headers = headers; | ||
const upstashToken = String(this.http.authorization).split("Bearer ")[1]; | ||
const nonApiRequest = processApi(request, upstashToken); | ||
const response = await this.enqueue({ | ||
...request, | ||
body: JSON.stringify(request.body), | ||
...nonApiRequest, | ||
body: JSON.stringify(nonApiRequest.body), | ||
headers | ||
@@ -1178,2 +1261,6 @@ }); | ||
* cancel workflows. | ||
* | ||
* @deprecated as of version 2.7.17. Will be removed in qstash-js 3.0.0. | ||
* Please use @upstash/workflow instead https://github.com/upstash/workflow-js | ||
* Migration Guide: https://upstash.com/docs/workflow/migration | ||
*/ | ||
@@ -1216,9 +1303,8 @@ get workflow() { | ||
headers.set("Content-Type", "application/json"); | ||
ensureCallbackPresent(request); | ||
appendLLMOptionsIfNeeded(request, headers, this.http); | ||
appendAPIOptions(request, headers); | ||
request.headers = headers; | ||
const upstashToken = String(this.http.authorization).split("Bearer ")[1]; | ||
const nonApiRequest = processApi(request, upstashToken); | ||
const response = await this.publish({ | ||
...request, | ||
headers, | ||
body: JSON.stringify(request.body) | ||
...nonApiRequest, | ||
body: JSON.stringify(nonApiRequest.body) | ||
}); | ||
@@ -1257,3 +1343,3 @@ return response; | ||
async batchJSON(request) { | ||
for (const message of request) { | ||
const batchPayload = request.map((message) => { | ||
if ("body" in message) { | ||
@@ -1263,8 +1349,8 @@ message.body = JSON.stringify(message.body); | ||
message.headers = new Headers(message.headers); | ||
ensureCallbackPresent(message); | ||
appendLLMOptionsIfNeeded(message, message.headers, this.http); | ||
appendAPIOptions(message, message.headers); | ||
message.headers.set("Content-Type", "application/json"); | ||
} | ||
const response = await this.batch(request); | ||
const upstashToken = String(this.http.authorization).split("Bearer ")[1]; | ||
const nonApiMessage = processApi(message, upstashToken); | ||
nonApiMessage.headers.set("Content-Type", "application/json"); | ||
return nonApiMessage; | ||
}); | ||
const response = await this.batch(batchPayload); | ||
return response; | ||
@@ -1326,2 +1412,21 @@ } | ||
// src/client/api/email.ts | ||
var EmailProvider = class extends BaseProvider { | ||
apiKind = "email"; | ||
batch; | ||
constructor(baseUrl, token, owner, batch) { | ||
super(baseUrl, token, owner); | ||
this.batch = batch; | ||
} | ||
getRoute() { | ||
return this.batch ? ["emails", "batch"] : ["emails"]; | ||
} | ||
getHeaders(_options) { | ||
return { | ||
"upstash-forward-authorization": `Bearer ${this.token}` | ||
}; | ||
} | ||
onFinish(providerInfo, _options) { | ||
return providerInfo; | ||
} | ||
}; | ||
var resend = ({ | ||
@@ -1331,7 +1436,3 @@ token, | ||
}) => { | ||
return { | ||
owner: "resend", | ||
baseUrl: `https://api.resend.com/emails${batch ? "/batch" : ""}`, | ||
token | ||
}; | ||
return new EmailProvider("https://api.resend.com", token, "resend", batch); | ||
}; | ||
@@ -1349,2 +1450,3 @@ // Annotate the CommonJS export names for ESM import in node: | ||
QstashRatelimitError, | ||
RATELIMIT_STATUS, | ||
Receiver, | ||
@@ -1354,2 +1456,3 @@ Schedules, | ||
UrlGroups, | ||
anthropic, | ||
custom, | ||
@@ -1356,0 +1459,0 @@ decodeBase64, |
import { NextApiHandler } from 'next'; | ||
import { NextRequest, NextFetchEvent } from 'next/server'; | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-kxUsvnWj.js'; | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-Dq99U_Dk.js'; | ||
import 'neverthrow'; | ||
@@ -34,6 +34,15 @@ | ||
* @returns | ||
* | ||
* @deprecated as of version 2.7.17. Will be removed in qstash-js 3.0.0. | ||
* Please use https://github.com/upstash/workflow-js | ||
* Migration Guide: https://upstash.com/docs/workflow/migration | ||
*/ | ||
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) => ((request: Request) => Promise<Response>); | ||
/** | ||
* @deprecated as of version 2.7.17. Will be removed in qstash-js 3.0.0. | ||
* Please use https://github.com/upstash/workflow-js | ||
* Migration Guide: https://upstash.com/docs/workflow/migration | ||
*/ | ||
declare const servePagesRouter: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) => NextApiHandler; | ||
export { type VerifySignatureConfig, serve, servePagesRouter, verifySignature, verifySignatureAppRouter, verifySignatureEdge }; |
import * as h3 from 'h3'; | ||
/** | ||
* @deprecated Use import { verifySignatureH3 } from "@upstash/qstash/h3" instead | ||
* @deprecated as of version 2.7.17. Will be removed in qstash-js 3.0.0. | ||
* Please use https://github.com/upstash/workflow-js | ||
* Migration Guide: https://upstash.com/docs/workflow/migration | ||
*/ | ||
@@ -6,0 +8,0 @@ declare const verifySignatureNuxt: (handler: (event: h3.H3Event<h3.EventHandlerRequest>) => Promise<unknown>, config?: { |
@@ -1,1 +0,1 @@ | ||
{ "version": "v0.0.0-ci.c6d6062c8eb056e3898644acce464783c7251ff2-20241031073348", "name": "@upstash/qstash", "description": "Official Typescript client for QStash", "author": "Andreas Thomas <dev@chronark.com>", "license": "MIT", "homepage": "https://github.com/upstash/sdk-qstash-ts#readme", "repository": { "type": "git", "url": "git+https://github.com/upstash/sdk-qstash-ts.git" }, "bugs": { "url": "https://github.com/upstash/sdk-qstash-ts/issues" }, "main": "./index.js", "module": "./index.mjs", "types": "./index.d.ts", "files": [ "./*" ], "exports": { ".": { "import": "./index.mjs", "require": "./index.js" }, "./dist/nextjs": { "import": "./nextjs.mjs", "require": "./nextjs.js" }, "./nextjs": { "import": "./nextjs.mjs", "require": "./nextjs.js" }, "./h3": { "import": "./h3.mjs", "require": "./h3.js" }, "./nuxt": { "import": "./nuxt.mjs", "require": "./nuxt.js" }, "./svelte": { "import": "./svelte.mjs", "require": "./svelte.js" }, "./solidjs": { "import": "./solidjs.mjs", "require": "./solidjs.js" }, "./workflow": { "import": "./workflow.mjs", "require": "./workflow.js" }, "./hono": { "import": "./hono.mjs", "require": "./hono.js" }, "./cloudflare": { "import": "./cloudflare.mjs", "require": "./cloudflare.js" } }, "keywords": [ "qstash", "queue", "events", "serverless", "upstash" ], "scripts": { "build": "tsup && cp README.md ./dist/ && cp package.json ./dist/ && cp LICENSE ./dist/", "test": "bun test src", "fmt": "prettier --write .", "lint": "tsc && eslint \"{src,platforms}/**/*.{js,ts,tsx}\" --quiet --fix", "check-exports": "bun run build && cd dist && attw -P", "prepare": "husky" }, "devDependencies": { "@commitlint/cli": "^19.2.2", "@commitlint/config-conventional": "^19.2.2", "@eslint/eslintrc": "^3.1.0", "@eslint/js": "^9.10.0", "@solidjs/start": "^1.0.6", "@sveltejs/kit": "^2.5.18", "@types/bun": "^1.1.1", "@types/crypto-js": "^4.2.0", "@typescript-eslint/eslint-plugin": "^8.4.0", "@typescript-eslint/parser": "^8.4.0", "ai": "^3.1.28", "bun-types": "^1.1.7", "eslint": "^9.10.0", "eslint-plugin-unicorn": "^51.0.1", "h3": "^1.12.0", "hono": "^4.5.8", "husky": "^9.0.10", "next": "^14.0.2", "prettier": "^3.2.5", "tsup": "latest", "typescript": "^5.4.5", "undici-types": "^6.16.0", "vitest": "latest" }, "dependencies": { "neverthrow": "^7.0.1", "crypto-js": ">=4.2.0", "jose": "^5.2.3" } } | ||
{ "version": "v0.0.0-ci.ca28bc08443ea6af297ba7c95ff1628eee9acadb-20241202182308", "name": "@upstash/qstash", "description": "Official Typescript client for QStash", "author": "Andreas Thomas <dev@chronark.com>", "license": "MIT", "homepage": "https://github.com/upstash/sdk-qstash-ts#readme", "repository": { "type": "git", "url": "git+https://github.com/upstash/sdk-qstash-ts.git" }, "bugs": { "url": "https://github.com/upstash/sdk-qstash-ts/issues" }, "main": "./index.js", "module": "./index.mjs", "types": "./index.d.ts", "files": [ "./*" ], "exports": { ".": { "import": "./index.mjs", "require": "./index.js" }, "./dist/nextjs": { "import": "./nextjs.mjs", "require": "./nextjs.js" }, "./nextjs": { "import": "./nextjs.mjs", "require": "./nextjs.js" }, "./h3": { "import": "./h3.mjs", "require": "./h3.js" }, "./nuxt": { "import": "./nuxt.mjs", "require": "./nuxt.js" }, "./svelte": { "import": "./svelte.mjs", "require": "./svelte.js" }, "./solidjs": { "import": "./solidjs.mjs", "require": "./solidjs.js" }, "./workflow": { "import": "./workflow.mjs", "require": "./workflow.js" }, "./hono": { "import": "./hono.mjs", "require": "./hono.js" }, "./cloudflare": { "import": "./cloudflare.mjs", "require": "./cloudflare.js" } }, "keywords": [ "qstash", "queue", "events", "serverless", "upstash" ], "scripts": { "build": "tsup && cp README.md ./dist/ && cp package.json ./dist/ && cp LICENSE ./dist/", "test": "bun test src", "fmt": "prettier --write .", "lint": "tsc && eslint \"{src,platforms}/**/*.{js,ts,tsx}\" --quiet --fix", "check-exports": "bun run build && cd dist && attw -P", "prepare": "husky" }, "devDependencies": { "@commitlint/cli": "^19.2.2", "@commitlint/config-conventional": "^19.2.2", "@eslint/eslintrc": "^3.1.0", "@eslint/js": "^9.10.0", "@solidjs/start": "^1.0.6", "@sveltejs/kit": "^2.5.18", "@types/bun": "^1.1.1", "@types/crypto-js": "^4.2.0", "@typescript-eslint/eslint-plugin": "^8.4.0", "@typescript-eslint/parser": "^8.4.0", "ai": "^3.1.28", "bun-types": "^1.1.7", "eslint": "^9.10.0", "eslint-plugin-unicorn": "^51.0.1", "h3": "^1.12.0", "hono": "^4.5.8", "husky": "^9.0.10", "next": "^14.0.2", "prettier": "^3.2.5", "tsup": "latest", "typescript": "^5.4.5", "undici-types": "^6.16.0", "vitest": "latest" }, "dependencies": { "neverthrow": "^7.0.1", "crypto-js": ">=4.2.0", "jose": "^5.2.3" } } |
import { APIHandler, APIEvent } from '@solidjs/start/server'; | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-kxUsvnWj.js'; | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-Dq99U_Dk.js'; | ||
import 'neverthrow'; | ||
@@ -19,2 +19,6 @@ | ||
* @returns | ||
* | ||
* @deprecated as of version 2.7.17. Will be removed in qstash-js 3.0.0. | ||
* Please use https://github.com/upstash/workflow-js | ||
* Migration Guide: https://upstash.com/docs/workflow/migration | ||
*/ | ||
@@ -21,0 +25,0 @@ declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) => (event: APIEvent) => Promise<Response>; |
import { RequestHandler } from '@sveltejs/kit'; | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-kxUsvnWj.js'; | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-Dq99U_Dk.js'; | ||
import 'neverthrow'; | ||
@@ -19,2 +19,6 @@ | ||
* @returns | ||
* | ||
* @deprecated as of version 2.7.17. Will be removed in qstash-js 3.0.0. | ||
* Please use https://github.com/upstash/workflow-js | ||
* Migration Guide: https://upstash.com/docs/workflow/migration | ||
*/ | ||
@@ -21,0 +25,0 @@ declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish"> & { |
@@ -1,2 +0,2 @@ | ||
export { ag as AsyncStepFunction, a9 as DisabledWorkflowContext, F as FailureFunctionPayload, aj as FinishCondition, al as LogLevel, ai as ParallelCallState, ae as RawStep, ak as RequiredExceptFields, a3 as RouteFunction, S as Step, ah as StepFunction, ad as StepType, ac as StepTypes, af as SyncStepFunction, a5 as Workflow, aa as WorkflowClient, a8 as WorkflowContext, an as WorkflowLogger, am as WorkflowLoggerOptions, ab as WorkflowReceiver, a4 as WorkflowServeOptions, a6 as processOptions, a7 as serve } from './client-kxUsvnWj.js'; | ||
export { ag as AsyncStepFunction, a9 as DisabledWorkflowContext, F as FailureFunctionPayload, aj as FinishCondition, al as LogLevel, ai as ParallelCallState, ae as RawStep, ak as RequiredExceptFields, a3 as RouteFunction, S as Step, ah as StepFunction, ad as StepType, ac as StepTypes, af as SyncStepFunction, a5 as Workflow, aa as WorkflowClient, a8 as WorkflowContext, an as WorkflowLogger, am as WorkflowLoggerOptions, ab as WorkflowReceiver, a4 as WorkflowServeOptions, a6 as processOptions, a7 as serve } from './client-Dq99U_Dk.js'; | ||
import 'neverthrow'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
921359
27117