@upstash/qstash
Advanced tools
Comparing version 0.0.0-ci.94b4fb120e0d0a0a6ed93b3239c7b33792b43172-20241031112117 to 0.0.0-ci.a6c7ec6ece691c7954f2687836e3992e90f0d4c6-20241204154143
@@ -1,2 +0,2 @@ | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-RORrka04.js'; | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-D4Vf0aPU.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-RORrka04.js'; | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-D4Vf0aPU.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-RORrka04.js'; | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-D4Vf0aPU.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,3 +0,3 @@ | ||
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-RORrka04.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-RORrka04.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-D4Vf0aPU.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-D4Vf0aPU.js'; | ||
import 'neverthrow'; | ||
@@ -9,3 +9,4 @@ | ||
declare class QstashError extends Error { | ||
constructor(message: string); | ||
readonly status?: number; | ||
constructor(message: string, status?: number); | ||
} | ||
@@ -12,0 +13,0 @@ declare class QstashRatelimitError extends QstashError { |
525
index.js
@@ -175,6 +175,9 @@ "use strict"; | ||
// 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; | ||
} | ||
@@ -187,3 +190,3 @@ }; | ||
constructor(args) { | ||
super(`Exceeded burst rate limit. ${JSON.stringify(args)} `); | ||
super(`Exceeded burst rate limit. ${JSON.stringify(args)}`, RATELIMIT_STATUS); | ||
this.name = "QstashRatelimitError"; | ||
@@ -203,3 +206,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"]; | ||
@@ -218,7 +222,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"; | ||
} | ||
@@ -254,2 +258,245 @@ }; | ||
// 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 | ||
var isIgnoredHeader = (header) => { | ||
const lowerCaseHeader = header.toLowerCase(); | ||
return lowerCaseHeader.startsWith("content-type") || lowerCaseHeader.startsWith("upstash-"); | ||
}; | ||
function prefixHeaders(headers) { | ||
const keysToBePrefixed = [...headers.keys()].filter((key) => !isIgnoredHeader(key)); | ||
for (const key of keysToBePrefixed) { | ||
const value = headers.get(key); | ||
if (value !== null) { | ||
headers.set(`Upstash-Forward-${key}`, value); | ||
} | ||
headers.delete(key); | ||
} | ||
return headers; | ||
} | ||
function processHeaders(request) { | ||
const headers = prefixHeaders(new Headers(request.headers)); | ||
headers.set("Upstash-Method", request.method ?? "POST"); | ||
if (request.delay !== void 0) { | ||
if (typeof request.delay === "string") { | ||
headers.set("Upstash-Delay", request.delay); | ||
} else { | ||
headers.set("Upstash-Delay", `${request.delay.toFixed(0)}s`); | ||
} | ||
} | ||
if (request.notBefore !== void 0) { | ||
headers.set("Upstash-Not-Before", request.notBefore.toFixed(0)); | ||
} | ||
if (request.deduplicationId !== void 0) { | ||
headers.set("Upstash-Deduplication-Id", request.deduplicationId); | ||
} | ||
if (request.contentBasedDeduplication) { | ||
headers.set("Upstash-Content-Based-Deduplication", "true"); | ||
} | ||
if (request.retries !== void 0) { | ||
headers.set("Upstash-Retries", request.retries.toFixed(0)); | ||
} | ||
if (request.callback !== void 0) { | ||
headers.set("Upstash-Callback", request.callback); | ||
} | ||
if (request.failureCallback !== void 0) { | ||
headers.set("Upstash-Failure-Callback", request.failureCallback); | ||
} | ||
if (request.timeout !== void 0) { | ||
if (typeof request.timeout === "string") { | ||
headers.set("Upstash-Timeout", request.timeout); | ||
} else { | ||
headers.set("Upstash-Timeout", `${request.timeout}s`); | ||
} | ||
} | ||
return headers; | ||
} | ||
function getRequestPath(request) { | ||
const nonApiPath = request.url ?? request.urlGroup ?? request.topic; | ||
if (nonApiPath) | ||
return nonApiPath; | ||
if (request.api?.name === "llm") | ||
return `api/llm`; | ||
if (request.api?.name === "email") { | ||
const providerInfo = getProviderInfo(request.api, "not-needed"); | ||
return providerInfo.baseUrl; | ||
} | ||
throw new QstashError(`Failed to infer request path for ${JSON.stringify(request)}`); | ||
} | ||
function decodeBase64(base64) { | ||
try { | ||
const binString = atob(base64); | ||
const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0)); | ||
return new TextDecoder().decode(intArray); | ||
} catch (error) { | ||
try { | ||
const result = atob(base64); | ||
console.warn( | ||
`Upstash QStash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}` | ||
); | ||
return result; | ||
} catch (error2) { | ||
console.warn( | ||
`Upstash QStash: Failed to decode base64 "${base64}" with atob. Returning it as it is. ${error2}` | ||
); | ||
return base64; | ||
} | ||
} | ||
} | ||
// src/client/http.ts | ||
@@ -260,2 +507,3 @@ var HttpClient = class { | ||
options; | ||
globalHeaders; | ||
retry; | ||
@@ -270,5 +518,6 @@ constructor(config) { | ||
} : { | ||
attempts: config.retry?.retries ? config.retry.retries + 1 : 5, | ||
attempts: config.retry?.retries ?? 5, | ||
backoff: config.retry?.backoff ?? ((retryCount) => Math.exp(retryCount) * 50) | ||
}; | ||
this.globalHeaders = prefixHeaders(new Headers(config.headers)); | ||
} | ||
@@ -316,3 +565,3 @@ async request(request) { | ||
let error = void 0; | ||
for (let index = 0; index < this.retry.attempts; index++) { | ||
for (let index = 0; index <= this.retry.attempts; index++) { | ||
try { | ||
@@ -323,3 +572,5 @@ response = await fetch(url.toString(), requestOptions); | ||
error = error_; | ||
await new Promise((r) => setTimeout(r, this.retry.backoff(index))); | ||
if (index < this.retry.attempts) { | ||
await new Promise((r) => setTimeout(r, this.retry.backoff(index))); | ||
} | ||
} | ||
@@ -337,3 +588,7 @@ } | ||
processRequest = (request) => { | ||
const headers = new Headers(request.headers); | ||
const newHeaders = new Headers(request.headers); | ||
const headers = new Headers(this.globalHeaders); | ||
newHeaders.forEach((value, key) => { | ||
headers.set(key, value); | ||
}); | ||
if (!headers.has("Authorization")) { | ||
@@ -384,3 +639,6 @@ headers.set("Authorization", this.authorization); | ||
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 | ||
); | ||
} | ||
@@ -606,242 +864,2 @@ } | ||
// 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 {}; | ||
} | ||
const header = this.owner === "anthropic" ? "x-api-key" : "authorization"; | ||
const headerValue = this.owner === "anthropic" ? this.token : `Bearer ${this.token}`; | ||
const headers = { [header]: headerValue }; | ||
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 | ||
var isIgnoredHeader = (header) => { | ||
const lowerCaseHeader = header.toLowerCase(); | ||
return lowerCaseHeader.startsWith("content-type") || lowerCaseHeader.startsWith("upstash-"); | ||
}; | ||
function prefixHeaders(headers) { | ||
const keysToBePrefixed = [...headers.keys()].filter((key) => !isIgnoredHeader(key)); | ||
for (const key of keysToBePrefixed) { | ||
const value = headers.get(key); | ||
if (value !== null) { | ||
headers.set(`Upstash-Forward-${key}`, value); | ||
} | ||
headers.delete(key); | ||
} | ||
return headers; | ||
} | ||
function processHeaders(request) { | ||
const headers = prefixHeaders(new Headers(request.headers)); | ||
headers.set("Upstash-Method", request.method ?? "POST"); | ||
if (request.delay !== void 0) { | ||
if (typeof request.delay === "string") { | ||
headers.set("Upstash-Delay", request.delay); | ||
} else { | ||
headers.set("Upstash-Delay", `${request.delay.toFixed(0)}s`); | ||
} | ||
} | ||
if (request.notBefore !== void 0) { | ||
headers.set("Upstash-Not-Before", request.notBefore.toFixed(0)); | ||
} | ||
if (request.deduplicationId !== void 0) { | ||
headers.set("Upstash-Deduplication-Id", request.deduplicationId); | ||
} | ||
if (request.contentBasedDeduplication !== void 0) { | ||
headers.set("Upstash-Content-Based-Deduplication", "true"); | ||
} | ||
if (request.retries !== void 0) { | ||
headers.set("Upstash-Retries", request.retries.toFixed(0)); | ||
} | ||
if (request.callback !== void 0) { | ||
headers.set("Upstash-Callback", request.callback); | ||
} | ||
if (request.failureCallback !== void 0) { | ||
headers.set("Upstash-Failure-Callback", request.failureCallback); | ||
} | ||
if (request.timeout !== void 0) { | ||
if (typeof request.timeout === "string") { | ||
headers.set("Upstash-Timeout", request.timeout); | ||
} else { | ||
headers.set("Upstash-Timeout", `${request.timeout}s`); | ||
} | ||
} | ||
return headers; | ||
} | ||
function getRequestPath(request) { | ||
const nonApiPath = request.url ?? request.urlGroup ?? request.topic; | ||
if (nonApiPath) | ||
return nonApiPath; | ||
if (request.api?.name === "llm") | ||
return `api/llm`; | ||
if (request.api?.name === "email") { | ||
const providerInfo = getProviderInfo(request.api, "not-needed"); | ||
return providerInfo.baseUrl; | ||
} | ||
throw new QstashError(`Failed to infer request path for ${JSON.stringify(request)}`); | ||
} | ||
function decodeBase64(base64) { | ||
try { | ||
const binString = atob(base64); | ||
const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0)); | ||
return new TextDecoder().decode(intArray); | ||
} catch (error) { | ||
try { | ||
const result = atob(base64); | ||
console.warn( | ||
`Upstash QStash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}` | ||
); | ||
return result; | ||
} catch (error2) { | ||
console.warn( | ||
`Upstash QStash: Failed to decode base64 "${base64}" with atob. Returning it as it is. ${error2}` | ||
); | ||
return base64; | ||
} | ||
} | ||
} | ||
// src/client/queue.ts | ||
@@ -1181,3 +1199,4 @@ var Queue = class { | ||
baseUrl: config.baseUrl ? config.baseUrl.replace(/\/$/, "") : "https://qstash.upstash.io", | ||
authorization: `Bearer ${config.token}` | ||
authorization: `Bearer ${config.token}`, | ||
headers: config.headers | ||
}); | ||
@@ -1232,2 +1251,6 @@ this.token = config.token; | ||
* 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 | ||
*/ | ||
@@ -1234,0 +1257,0 @@ get workflow() { |
import { NextApiHandler } from 'next'; | ||
import { NextRequest, NextFetchEvent } from 'next/server'; | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-RORrka04.js'; | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-D4Vf0aPU.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.94b4fb120e0d0a0a6ed93b3239c7b33792b43172-20241031112117", "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.a6c7ec6ece691c7954f2687836e3992e90f0d4c6-20241204154143", "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-RORrka04.js'; | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-D4Vf0aPU.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-RORrka04.js'; | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-D4Vf0aPU.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-RORrka04.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-D4Vf0aPU.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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
917317
27067
10