@upstash/qstash
Advanced tools
Comparing version 0.0.0-ci.ac75675ba93d6580cd08b5db28076ef5d99cb6ef-20241209092530 to 0.0.0-ci.adfe6a688e03195a770ebd5e1b2fe0b36ea97ce8-20250207113405
@@ -1,2 +0,2 @@ | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-B2FDnusw.js'; | ||
import { a4 as RouteFunction, a5 as WorkflowServeOptions } from './client-vTeVVeh7.js'; | ||
import 'neverthrow'; | ||
@@ -3,0 +3,0 @@ |
import * as h3 from 'h3'; | ||
import { H3Event } from 'h3'; | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-B2FDnusw.js'; | ||
import { a4 as RouteFunction, a5 as WorkflowServeOptions } from './client-vTeVVeh7.js'; | ||
import 'neverthrow'; | ||
@@ -5,0 +5,0 @@ |
import { Context } from 'hono'; | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-B2FDnusw.js'; | ||
import { a4 as RouteFunction, a5 as WorkflowServeOptions } from './client-vTeVVeh7.js'; | ||
import 'neverthrow'; | ||
@@ -4,0 +4,0 @@ |
@@ -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-B2FDnusw.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-B2FDnusw.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-vTeVVeh7.js'; | ||
export { A as AddEndpointsRequest, y as BodyInit, J as Chat, N as ChatCompletion, O as ChatCompletionChunk, K as ChatCompletionMessage, $ as ChatRequest, h as Client, p as CreateScheduleRequest, r as Endpoint, v as Event, w as EventPayload, g as EventsRequest, I as FlowControl, x as GetEventsPayload, G as GetEventsResponse, H as HTTPMethods, z as HeadersInit, M as Message, m as MessagePayload, n as Messages, Z as OpenAIChatModel, _ 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, X as StreamDisabled, T as StreamEnabled, Y as StreamParameter, U as UrlGroup, t as UrlGroups, V as VerifyRequest, W as WithCursor, a2 as anthropic, a3 as custom, a1 as openai, a0 as upstash } from './client-vTeVVeh7.js'; | ||
import 'neverthrow'; | ||
@@ -81,2 +81,3 @@ | ||
readonly batch: boolean; | ||
readonly method = "POST"; | ||
constructor(baseUrl: string, token: string, owner: EmailOwner, batch: boolean); | ||
@@ -83,0 +84,0 @@ getRoute(): string[]; |
147
index.js
@@ -144,3 +144,4 @@ "use strict"; | ||
...message, | ||
urlGroup: message.topicName | ||
urlGroup: message.topicName, | ||
ratePerSecond: "rate" in message ? message.rate : void 0 | ||
}; | ||
@@ -261,2 +262,3 @@ }), | ||
retry; | ||
headers; | ||
constructor(config) { | ||
@@ -273,2 +275,3 @@ this.baseUrl = config.baseUrl.replace(/\/$/, ""); | ||
}; | ||
this.headers = config.headers; | ||
} | ||
@@ -575,3 +578,4 @@ async request(request) { | ||
...messagePayload, | ||
urlGroup: messagePayload.topicName | ||
urlGroup: messagePayload.topicName, | ||
ratePerSecond: "rate" in messagePayload ? messagePayload.rate : void 0 | ||
}; | ||
@@ -627,2 +631,3 @@ return message; | ||
organization; | ||
method = "POST"; | ||
constructor(baseUrl, token, owner, organization) { | ||
@@ -648,2 +653,5 @@ super(baseUrl, token, owner); | ||
} | ||
if (this.owner === "anthropic") { | ||
headers["anthropic-version"] = "2023-06-01"; | ||
} | ||
return headers; | ||
@@ -705,11 +713,20 @@ } | ||
appendHeaders: finalProvider.getHeaders(parameters), | ||
owner: finalProvider.owner | ||
owner: finalProvider.owner, | ||
method: finalProvider.method | ||
}; | ||
return finalProvider.onFinish(providerInfo, parameters); | ||
}; | ||
var processApi = (request, upstashToken) => { | ||
var safeJoinHeaders = (headers, record) => { | ||
const joinedHeaders = new Headers(record); | ||
for (const [header, value] of headers.entries()) { | ||
joinedHeaders.set(header, value); | ||
} | ||
return joinedHeaders; | ||
}; | ||
var processApi = (request, headers, upstashToken) => { | ||
if (!request.api) { | ||
request.headers = headers; | ||
return request; | ||
} | ||
const { url, appendHeaders, owner } = getProviderInfo(request.api, upstashToken); | ||
const { url, appendHeaders, owner, method } = getProviderInfo(request.api, upstashToken); | ||
if (request.api.name === "llm") { | ||
@@ -722,7 +739,4 @@ const callback = request.callback; | ||
...request, | ||
// @ts-expect-error undici header conflict | ||
headers: new Headers({ | ||
...request.headers, | ||
...appendHeaders | ||
}), | ||
method: request.method ?? method, | ||
headers: safeJoinHeaders(headers, appendHeaders), | ||
...owner === "upstash" && !request.api.analytics ? { api: { name: "llm" }, url: void 0, callback } : { url, api: void 0 } | ||
@@ -733,7 +747,4 @@ }; | ||
...request, | ||
// @ts-expect-error undici header conflict | ||
headers: new Headers({ | ||
...request.headers, | ||
...appendHeaders | ||
}), | ||
method: request.method ?? method, | ||
headers: safeJoinHeaders(headers, appendHeaders), | ||
url, | ||
@@ -786,2 +797,12 @@ api: void 0 | ||
} | ||
function wrapWithGlobalHeaders(headers, globalHeaders) { | ||
if (!globalHeaders) { | ||
return headers; | ||
} | ||
const finalHeaders = new Headers(globalHeaders); | ||
headers.forEach((value, key) => { | ||
finalHeaders.set(key, value); | ||
}); | ||
return finalHeaders; | ||
} | ||
function processHeaders(request) { | ||
@@ -822,2 +843,15 @@ const headers = prefixHeaders(new Headers(request.headers)); | ||
} | ||
if (request.flowControl?.key) { | ||
const parallelism = request.flowControl.parallelism?.toString(); | ||
const rate = request.flowControl.ratePerSecond?.toString(); | ||
const controlValue = [ | ||
parallelism ? `parallelism=${parallelism}` : void 0, | ||
rate ? `rate=${rate}` : void 0 | ||
].filter(Boolean); | ||
if (controlValue.length === 0) { | ||
throw new QstashError("Provide at least one of parallelism or ratePerSecond for flowControl"); | ||
} | ||
headers.set("Upstash-Flow-Control-Key", request.flowControl.key); | ||
headers.set("Upstash-Flow-Control-Value", controlValue.join(", ")); | ||
} | ||
return headers; | ||
@@ -929,3 +963,6 @@ } | ||
} | ||
const headers = processHeaders(request); | ||
const headers = wrapWithGlobalHeaders( | ||
processHeaders(request), | ||
this.http.headers | ||
); | ||
const destination = getRequestPath(request); | ||
@@ -946,9 +983,7 @@ const response = await this.http.request({ | ||
headers.set("Content-Type", "application/json"); | ||
request.headers = headers; | ||
const upstashToken = String(this.http.authorization).split("Bearer ")[1]; | ||
const nonApiRequest = processApi(request, upstashToken); | ||
const nonApiRequest = processApi(request, headers, upstashToken); | ||
const response = await this.enqueue({ | ||
...nonApiRequest, | ||
body: JSON.stringify(nonApiRequest.body), | ||
headers | ||
body: JSON.stringify(nonApiRequest.body) | ||
}); | ||
@@ -1035,5 +1070,20 @@ return response; | ||
} | ||
if (request.flowControl?.key) { | ||
const parallelism = request.flowControl.parallelism?.toString(); | ||
const rate = request.flowControl.ratePerSecond?.toString(); | ||
const controlValue = [ | ||
parallelism ? `parallelism=${parallelism}` : void 0, | ||
rate ? `rate=${rate}` : void 0 | ||
].filter(Boolean); | ||
if (controlValue.length === 0) { | ||
throw new QstashError( | ||
"Provide at least one of parallelism or ratePerSecond for flowControl" | ||
); | ||
} | ||
headers.set("Upstash-Flow-Control-Key", request.flowControl.key); | ||
headers.set("Upstash-Flow-Control-Value", controlValue.join(", ")); | ||
} | ||
return await this.http.request({ | ||
method: "POST", | ||
headers, | ||
headers: wrapWithGlobalHeaders(headers, this.http.headers), | ||
path: ["v2", "schedules", request.destination], | ||
@@ -1047,6 +1097,9 @@ body: request.body | ||
async get(scheduleId) { | ||
return await this.http.request({ | ||
const schedule = await this.http.request({ | ||
method: "GET", | ||
path: ["v2", "schedules", scheduleId] | ||
}); | ||
if ("rate" in schedule) | ||
schedule.ratePerSecond = schedule.rate; | ||
return schedule; | ||
} | ||
@@ -1057,6 +1110,11 @@ /** | ||
async list() { | ||
return await this.http.request({ | ||
const schedules = await this.http.request({ | ||
method: "GET", | ||
path: ["v2", "schedules"] | ||
}); | ||
for (const schedule of schedules) { | ||
if ("rate" in schedule) | ||
schedule.ratePerSecond = schedule.rate; | ||
} | ||
return schedules; | ||
} | ||
@@ -1193,19 +1251,20 @@ /** | ||
token; | ||
headers; | ||
constructor(config) { | ||
const environment = typeof process === "undefined" ? {} : process.env; | ||
const baseUrl = config?.baseUrl ? config.baseUrl.replace(/\/$/, "") : environment.QSTASH_URL ?? "https://qstash.upstash.io"; | ||
const token = config?.token ?? environment.QSTASH_TOKEN; | ||
this.http = new HttpClient({ | ||
retry: config.retry, | ||
baseUrl: config.baseUrl ? config.baseUrl.replace(/\/$/, "") : "https://qstash.upstash.io", | ||
authorization: `Bearer ${config.token}` | ||
retry: config?.retry, | ||
baseUrl, | ||
authorization: `Bearer ${token}`, | ||
//@ts-expect-error caused by undici and bunjs type overlap | ||
headers: prefixHeaders(new Headers(config?.headers ?? {})) | ||
}); | ||
this.token = config.token; | ||
this.headers = prefixHeaders(new Headers(config.headers)); | ||
if (!token) { | ||
console.warn( | ||
"[Upstash QStash] client token is not set. Either pass a token or set QSTASH_TOKEN env variable." | ||
); | ||
} | ||
this.token = token; | ||
} | ||
wrapWithGlobalHeaders(headers) { | ||
const finalHeaders = new Headers(this.headers); | ||
headers.forEach((value, key) => { | ||
finalHeaders.set(key, value); | ||
}); | ||
return finalHeaders; | ||
} | ||
/** | ||
@@ -1282,3 +1341,6 @@ * Access the urlGroup API. | ||
async publish(request) { | ||
const headers = this.wrapWithGlobalHeaders(processHeaders(request)); | ||
const headers = wrapWithGlobalHeaders( | ||
processHeaders(request), | ||
this.http.headers | ||
); | ||
const response = await this.http.request({ | ||
@@ -1299,5 +1361,4 @@ path: ["v2", "publish", getRequestPath(request)], | ||
headers.set("Content-Type", "application/json"); | ||
request.headers = headers; | ||
const upstashToken = String(this.http.authorization).split("Bearer ")[1]; | ||
const nonApiRequest = processApi(request, upstashToken); | ||
const nonApiRequest = processApi(request, headers, upstashToken); | ||
const response = await this.publish({ | ||
@@ -1315,3 +1376,3 @@ ...nonApiRequest, | ||
for (const message of request) { | ||
const headers = this.wrapWithGlobalHeaders(processHeaders(message)); | ||
const headers = wrapWithGlobalHeaders(processHeaders(message), this.http.headers); | ||
const headerEntries = Object.fromEntries(headers.entries()); | ||
@@ -1344,5 +1405,4 @@ messages.push({ | ||
} | ||
message.headers = new Headers(message.headers); | ||
const upstashToken = String(this.http.authorization).split("Bearer ")[1]; | ||
const nonApiMessage = processApi(message, upstashToken); | ||
const nonApiMessage = processApi(message, new Headers(message.headers), upstashToken); | ||
nonApiMessage.headers.set("Content-Type", "application/json"); | ||
@@ -1411,2 +1471,3 @@ return nonApiMessage; | ||
batch; | ||
method = "POST"; | ||
constructor(baseUrl, token, owner, batch) { | ||
@@ -1421,3 +1482,3 @@ super(baseUrl, token, owner); | ||
return { | ||
"upstash-forward-authorization": `Bearer ${this.token}` | ||
authorization: `Bearer ${this.token}` | ||
}; | ||
@@ -1424,0 +1485,0 @@ } |
import { NextApiHandler } from 'next'; | ||
import { NextRequest, NextFetchEvent } from 'next/server'; | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-B2FDnusw.js'; | ||
import { a4 as RouteFunction, a5 as WorkflowServeOptions } from './client-vTeVVeh7.js'; | ||
import 'neverthrow'; | ||
@@ -5,0 +5,0 @@ |
@@ -1,1 +0,1 @@ | ||
{ "version": "v0.0.0-ci.ac75675ba93d6580cd08b5db28076ef5d99cb6ef-20241209092530", "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.adfe6a688e03195a770ebd5e1b2fe0b36ea97ce8-20250207113405", "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-B2FDnusw.js'; | ||
import { a4 as RouteFunction, a5 as WorkflowServeOptions } from './client-vTeVVeh7.js'; | ||
import 'neverthrow'; | ||
@@ -4,0 +4,0 @@ |
import { RequestHandler } from '@sveltejs/kit'; | ||
import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-B2FDnusw.js'; | ||
import { a4 as RouteFunction, a5 as WorkflowServeOptions } from './client-vTeVVeh7.js'; | ||
import 'neverthrow'; | ||
@@ -4,0 +4,0 @@ |
@@ -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-B2FDnusw.js'; | ||
export { ah as AsyncStepFunction, aa as DisabledWorkflowContext, F as FailureFunctionPayload, ak as FinishCondition, am as LogLevel, aj as ParallelCallState, af as RawStep, al as RequiredExceptFields, a4 as RouteFunction, S as Step, ai as StepFunction, ae as StepType, ad as StepTypes, ag as SyncStepFunction, a6 as Workflow, ab as WorkflowClient, a9 as WorkflowContext, ao as WorkflowLogger, an as WorkflowLoggerOptions, ac as WorkflowReceiver, a5 as WorkflowServeOptions, a7 as processOptions, a8 as serve } from './client-vTeVVeh7.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 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
944605
27691
39