New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

@upstash/qstash

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@upstash/qstash - npm Package Compare versions

Comparing version 2.0.0-canary.19 to 2.0.0-canary.20

@@ -1,104 +0,9 @@

"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __knownSymbol = (name, symbol) => {
if (symbol = Symbol[name])
return symbol;
throw Error("Symbol." + name + " is not defined");
};
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
// src/receiver.ts
var _jose = require('jose'); var jose = _interopRequireWildcard(_jose);
var _cryptojs = require('crypto-js'); var crypto = _interopRequireWildcard(_cryptojs);
var SignatureError = class extends Error {
constructor(message) {
super(message);
this.name = "SignatureError";
}
};
var Receiver = class {
constructor(config) {
this.currentSigningKey = config.currentSigningKey;
this.nextSigningKey = config.nextSigningKey;
}
/**
* Verify the signature of a request.
*
* Tries to verify the signature with the current signing key.
* If that fails, maybe because you have rotated the keys recently, it will
* try to verify the signature with the next signing key.
*
* If that fails, the signature is invalid and a `SignatureError` is thrown.
*/
verify(req) {
return __async(this, null, function* () {
const isValid = yield this.verifyWithKey(this.currentSigningKey, req);
if (isValid) {
return true;
}
return this.verifyWithKey(this.nextSigningKey, req);
});
}
/**
* Verify signature with a specific signing key
*/
verifyWithKey(key, req) {
return __async(this, null, function* () {
const jwt = yield jose.jwtVerify(req.signature, new TextEncoder().encode(key), {
issuer: "Upstash",
clockTolerance: req.clockTolerance
}).catch((e) => {
throw new SignatureError(e.message);
});
const p = jwt.payload;
if (typeof req.url !== "undefined" && p.sub !== req.url) {
throw new SignatureError(`invalid subject: ${p.sub}, want: ${req.url}`);
}
const bodyHash = crypto.SHA256(req.body).toString(crypto.enc.Base64url);
const padding = new RegExp(/=+$/);
if (p.body.replace(padding, "") !== bodyHash.replace(padding, "")) {
throw new SignatureError(`body hash does not match, want: ${p.body}, got: ${bodyHash}`);
}
return true;
});
}
};
var _chunkEQTYEU4Ujs = require('./chunk-EQTYEU4U.js');
// src/client/error.ts

@@ -131,3 +36,3 @@ var QstashError = class extends Error {

request(req) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
var _a, _b;

@@ -181,3 +86,3 @@ const headers = new Headers(req.headers);

addEndpoints(req) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
return yield this.http.request({

@@ -195,3 +100,3 @@ method: "POST",

removeEndpoints(req) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
return yield this.http.request({

@@ -209,3 +114,3 @@ method: "DELETE",

list() {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
return yield this.http.request({

@@ -221,3 +126,3 @@ method: "GET",

get(name) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
return yield this.http.request({

@@ -233,3 +138,3 @@ method: "GET",

delete(name) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
return yield this.http.request({

@@ -252,3 +157,3 @@ method: "DELETE",

get(messageId) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
return yield this.http.request({

@@ -264,3 +169,3 @@ method: "GET",

delete(messageId) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
return yield this.http.request({

@@ -283,3 +188,3 @@ method: "DELETE",

create(req) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
return yield this.http.request({

@@ -297,3 +202,3 @@ method: "POST",

get(scheduleId) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
return yield this.http.request({

@@ -309,3 +214,3 @@ method: "GET",

list() {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
return yield this.http.request({

@@ -321,3 +226,3 @@ method: "GET",

delete(scheduleId) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
return yield this.http.request({

@@ -365,3 +270,3 @@ method: "DELETE",

publish(req) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
var _a;

@@ -402,6 +307,6 @@ const headers = new Headers(req.headers);

publishJSON(req) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
const headers = new Headers(req.headers);
headers.set("Content-Type", "application/json");
const res = yield this.publish(__spreadProps(__spreadValues({}, req), {
const res = yield this.publish(_chunkEQTYEU4Ujs.__spreadProps.call(void 0, _chunkEQTYEU4Ujs.__spreadValues.call(void 0, {}, req), {
headers,

@@ -433,3 +338,3 @@ body: JSON.stringify(req.body)

events(req) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
const query = {};

@@ -449,124 +354,2 @@ if ((req == null ? void 0 : req.cursor) && req.cursor > 0) {

// src/nextjs.ts
var _server = require('next/server');
function verifySignature(handler, config) {
var _a, _b;
const currentSigningKey = (_a = config == null ? void 0 : config.currentSigningKey) != null ? _a : process.env.QSTASH_CURRENT_SIGNING_KEY;
if (!currentSigningKey) {
throw new Error(
"currentSigningKey is required, either in the config or as env variable QSTASH_CURRENT_SIGNING_KEY"
);
}
const nextSigningKey = (_b = config == null ? void 0 : config.nextSigningKey) != null ? _b : process.env.QSTASH_NEXT_SIGNING_KEY;
if (!nextSigningKey) {
throw new Error(
"nextSigningKey is required, either in the config or as env variable QSTASH_NEXT_SIGNING_KEY"
);
}
const receiver = new Receiver({
currentSigningKey,
nextSigningKey
});
return (req, res) => __async(this, null, function* () {
const signature = req.headers["upstash-signature"];
if (!signature) {
res.status(400);
res.send("`Upstash-Signature` header is missing");
res.end();
return;
}
if (typeof signature !== "string") {
throw new Error("`Upstash-Signature` header is not a string");
}
const chunks = [];
try {
for (var iter = __forAwait(req), more, temp, error; more = !(temp = yield iter.next()).done; more = false) {
const chunk = temp.value;
chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
}
} catch (temp) {
error = [temp];
} finally {
try {
more && (temp = iter.return) && (yield temp.call(iter));
} finally {
if (error)
throw error[0];
}
}
const body = Buffer.concat(chunks).toString("utf-8");
const isValid = yield receiver.verify({
signature,
body,
clockTolerance: config == null ? void 0 : config.clockTolerance
});
if (!isValid) {
res.status(400);
res.send("Invalid signature");
res.end();
return;
}
try {
if (req.headers["content-type"] === "application/json") {
req.body = JSON.parse(body);
} else {
req.body = body;
}
} catch (e) {
req.body = body;
}
return handler(req, res);
});
}
function verifySignatureEdge(handler, config) {
var _a, _b;
const currentSigningKey = (_a = config == null ? void 0 : config.currentSigningKey) != null ? _a : process.env.QSTASH_CURRENT_SIGNING_KEY;
if (!currentSigningKey) {
throw new Error(
"currentSigningKey is required, either in the config or as env variable QSTASH_CURRENT_SIGNING_KEY"
);
}
const nextSigningKey = (_b = config == null ? void 0 : config.nextSigningKey) != null ? _b : process.env.QSTASH_NEXT_SIGNING_KEY;
if (!nextSigningKey) {
throw new Error(
"nextSigningKey is required, either in the config or as env variable QSTASH_NEXT_SIGNING_KEY"
);
}
const receiver = new Receiver({
currentSigningKey,
nextSigningKey
});
return (req, nfe) => __async(this, null, function* () {
const reqClone = req.clone();
const signature = req.headers.get("upstash-signature");
if (!signature) {
return new (0, _server.NextResponse)(new TextEncoder().encode("`Upstash-Signature` header is missing"), {
status: 403
});
}
if (typeof signature !== "string") {
throw new Error("`Upstash-Signature` header is not a string");
}
const body = yield req.text();
const isValid = yield receiver.verify({
signature,
body,
clockTolerance: config == null ? void 0 : config.clockTolerance
});
if (!isValid) {
return new (0, _server.NextResponse)(new TextEncoder().encode("invalid signature"), { status: 403 });
}
let parsedBody = void 0;
try {
if (req.headers.get("content-type") === "application/json") {
parsedBody = JSON.parse(body);
} else {
parsedBody = body;
}
} catch (e) {
parsedBody = body;
}
return handler(reqClone, nfe);
});
}

@@ -579,6 +362,3 @@

exports.Client = Client; exports.Messages = Messages; exports.QstashError = QstashError; exports.Receiver = Receiver; exports.Schedules = Schedules; exports.SignatureError = SignatureError; exports.Topics = Topics; exports.verifySignature = verifySignature; exports.verifySignatureEdge = verifySignatureEdge;
exports.Client = Client; exports.Messages = Messages; exports.QstashError = QstashError; exports.Receiver = _chunkEQTYEU4Ujs.Receiver; exports.Schedules = Schedules; exports.SignatureError = _chunkEQTYEU4Ujs.SignatureError; exports.Topics = Topics;
//# sourceMappingURL=index.js.map

@@ -1,4 +0,1 @@

import { NextApiHandler } from 'next';
import { NextRequest, NextFetchEvent, NextResponse } from 'next/server';
/**

@@ -489,21 +486,2 @@ * Necessary to verify the signature of a request.

type VerifySignaturConfig = {
currentSigningKey?: string;
nextSigningKey?: string;
/**
* The url of this api route, including the protocol.
*
* If you omit this, the url will be automatically determined by checking the `VERCEL_URL` env variable and assuming `https`
*/
url?: string;
/**
* Number of seconds to tolerate when checking `nbf` and `exp` claims, to deal with small clock differences among different servers
*
* @default 0
*/
clockTolerance?: number;
};
declare function verifySignature(handler: NextApiHandler, config?: VerifySignaturConfig): NextApiHandler;
declare function verifySignatureEdge(handler: (req: NextRequest, nfe: NextFetchEvent) => NextResponse | Promise<NextResponse>, config?: VerifySignaturConfig): (req: NextRequest, nfe: NextFetchEvent) => Promise<NextResponse<unknown>>;
export { AddEndpointsRequest, Client, CreateScheduleRequest, Endpoint, Event, EventsRequest, GetEventsResponse, Messages, PublishJsonRequest, PublishRequest, QstashError, Receiver, ReceiverConfig, RemoveEndpointsRequest, Schedule, Schedules, SignatureError, State, Topic, Topics, VerifyRequest, VerifySignaturConfig, WithCursor, verifySignature, verifySignatureEdge };
export { AddEndpointsRequest, Client, CreateScheduleRequest, Endpoint, Event, EventsRequest, GetEventsResponse, Messages, PublishJsonRequest, PublishRequest, QstashError, Receiver, ReceiverConfig, RemoveEndpointsRequest, Schedule, Schedules, SignatureError, State, Topic, Topics, VerifyRequest, WithCursor };

@@ -1,104 +0,9 @@

"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __knownSymbol = (name, symbol) => {
if (symbol = Symbol[name])
return symbol;
throw Error("Symbol." + name + " is not defined");
};
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
// src/receiver.ts
var _jose = require('jose'); var jose = _interopRequireWildcard(_jose);
var _cryptojs = require('crypto-js'); var crypto = _interopRequireWildcard(_cryptojs);
var SignatureError = class extends Error {
constructor(message) {
super(message);
this.name = "SignatureError";
}
};
var Receiver = class {
constructor(config) {
this.currentSigningKey = config.currentSigningKey;
this.nextSigningKey = config.nextSigningKey;
}
/**
* Verify the signature of a request.
*
* Tries to verify the signature with the current signing key.
* If that fails, maybe because you have rotated the keys recently, it will
* try to verify the signature with the next signing key.
*
* If that fails, the signature is invalid and a `SignatureError` is thrown.
*/
verify(req) {
return __async(this, null, function* () {
const isValid = yield this.verifyWithKey(this.currentSigningKey, req);
if (isValid) {
return true;
}
return this.verifyWithKey(this.nextSigningKey, req);
});
}
/**
* Verify signature with a specific signing key
*/
verifyWithKey(key, req) {
return __async(this, null, function* () {
const jwt = yield jose.jwtVerify(req.signature, new TextEncoder().encode(key), {
issuer: "Upstash",
clockTolerance: req.clockTolerance
}).catch((e) => {
throw new SignatureError(e.message);
});
const p = jwt.payload;
if (typeof req.url !== "undefined" && p.sub !== req.url) {
throw new SignatureError(`invalid subject: ${p.sub}, want: ${req.url}`);
}
const bodyHash = crypto.SHA256(req.body).toString(crypto.enc.Base64url);
const padding = new RegExp(/=+$/);
if (p.body.replace(padding, "") !== bodyHash.replace(padding, "")) {
throw new SignatureError(`body hash does not match, want: ${p.body}, got: ${bodyHash}`);
}
return true;
});
}
};
var _chunkEQTYEU4Ujs = require('./chunk-EQTYEU4U.js');
// src/client/error.ts

@@ -131,3 +36,3 @@ var QstashError = class extends Error {

request(req) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
var _a, _b;

@@ -181,3 +86,3 @@ const headers = new Headers(req.headers);

addEndpoints(req) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
return yield this.http.request({

@@ -195,3 +100,3 @@ method: "POST",

removeEndpoints(req) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
return yield this.http.request({

@@ -209,3 +114,3 @@ method: "DELETE",

list() {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
return yield this.http.request({

@@ -221,3 +126,3 @@ method: "GET",

get(name) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
return yield this.http.request({

@@ -233,3 +138,3 @@ method: "GET",

delete(name) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
return yield this.http.request({

@@ -252,3 +157,3 @@ method: "DELETE",

get(messageId) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
return yield this.http.request({

@@ -264,3 +169,3 @@ method: "GET",

delete(messageId) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
return yield this.http.request({

@@ -283,3 +188,3 @@ method: "DELETE",

create(req) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
return yield this.http.request({

@@ -297,3 +202,3 @@ method: "POST",

get(scheduleId) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
return yield this.http.request({

@@ -309,3 +214,3 @@ method: "GET",

list() {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
return yield this.http.request({

@@ -321,3 +226,3 @@ method: "GET",

delete(scheduleId) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
return yield this.http.request({

@@ -365,3 +270,3 @@ method: "DELETE",

publish(req) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
var _a;

@@ -402,6 +307,6 @@ const headers = new Headers(req.headers);

publishJSON(req) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
const headers = new Headers(req.headers);
headers.set("Content-Type", "application/json");
const res = yield this.publish(__spreadProps(__spreadValues({}, req), {
const res = yield this.publish(_chunkEQTYEU4Ujs.__spreadProps.call(void 0, _chunkEQTYEU4Ujs.__spreadValues.call(void 0, {}, req), {
headers,

@@ -433,3 +338,3 @@ body: JSON.stringify(req.body)

events(req) {
return __async(this, null, function* () {
return _chunkEQTYEU4Ujs.__async.call(void 0, this, null, function* () {
const query = {};

@@ -449,124 +354,2 @@ if ((req == null ? void 0 : req.cursor) && req.cursor > 0) {

// src/nextjs.ts
var _server = require('next/server');
function verifySignature(handler, config) {
var _a, _b;
const currentSigningKey = (_a = config == null ? void 0 : config.currentSigningKey) != null ? _a : process.env.QSTASH_CURRENT_SIGNING_KEY;
if (!currentSigningKey) {
throw new Error(
"currentSigningKey is required, either in the config or as env variable QSTASH_CURRENT_SIGNING_KEY"
);
}
const nextSigningKey = (_b = config == null ? void 0 : config.nextSigningKey) != null ? _b : process.env.QSTASH_NEXT_SIGNING_KEY;
if (!nextSigningKey) {
throw new Error(
"nextSigningKey is required, either in the config or as env variable QSTASH_NEXT_SIGNING_KEY"
);
}
const receiver = new Receiver({
currentSigningKey,
nextSigningKey
});
return (req, res) => __async(this, null, function* () {
const signature = req.headers["upstash-signature"];
if (!signature) {
res.status(400);
res.send("`Upstash-Signature` header is missing");
res.end();
return;
}
if (typeof signature !== "string") {
throw new Error("`Upstash-Signature` header is not a string");
}
const chunks = [];
try {
for (var iter = __forAwait(req), more, temp, error; more = !(temp = yield iter.next()).done; more = false) {
const chunk = temp.value;
chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
}
} catch (temp) {
error = [temp];
} finally {
try {
more && (temp = iter.return) && (yield temp.call(iter));
} finally {
if (error)
throw error[0];
}
}
const body = Buffer.concat(chunks).toString("utf-8");
const isValid = yield receiver.verify({
signature,
body,
clockTolerance: config == null ? void 0 : config.clockTolerance
});
if (!isValid) {
res.status(400);
res.send("Invalid signature");
res.end();
return;
}
try {
if (req.headers["content-type"] === "application/json") {
req.body = JSON.parse(body);
} else {
req.body = body;
}
} catch (e) {
req.body = body;
}
return handler(req, res);
});
}
function verifySignatureEdge(handler, config) {
var _a, _b;
const currentSigningKey = (_a = config == null ? void 0 : config.currentSigningKey) != null ? _a : process.env.QSTASH_CURRENT_SIGNING_KEY;
if (!currentSigningKey) {
throw new Error(
"currentSigningKey is required, either in the config or as env variable QSTASH_CURRENT_SIGNING_KEY"
);
}
const nextSigningKey = (_b = config == null ? void 0 : config.nextSigningKey) != null ? _b : process.env.QSTASH_NEXT_SIGNING_KEY;
if (!nextSigningKey) {
throw new Error(
"nextSigningKey is required, either in the config or as env variable QSTASH_NEXT_SIGNING_KEY"
);
}
const receiver = new Receiver({
currentSigningKey,
nextSigningKey
});
return (req, nfe) => __async(this, null, function* () {
const reqClone = req.clone();
const signature = req.headers.get("upstash-signature");
if (!signature) {
return new (0, _server.NextResponse)(new TextEncoder().encode("`Upstash-Signature` header is missing"), {
status: 403
});
}
if (typeof signature !== "string") {
throw new Error("`Upstash-Signature` header is not a string");
}
const body = yield req.text();
const isValid = yield receiver.verify({
signature,
body,
clockTolerance: config == null ? void 0 : config.clockTolerance
});
if (!isValid) {
return new (0, _server.NextResponse)(new TextEncoder().encode("invalid signature"), { status: 403 });
}
let parsedBody = void 0;
try {
if (req.headers.get("content-type") === "application/json") {
parsedBody = JSON.parse(body);
} else {
parsedBody = body;
}
} catch (e) {
parsedBody = body;
}
return handler(reqClone, nfe);
});
}

@@ -579,6 +362,3 @@

exports.Client = Client; exports.Messages = Messages; exports.QstashError = QstashError; exports.Receiver = Receiver; exports.Schedules = Schedules; exports.SignatureError = SignatureError; exports.Topics = Topics; exports.verifySignature = verifySignature; exports.verifySignatureEdge = verifySignatureEdge;
exports.Client = Client; exports.Messages = Messages; exports.QstashError = QstashError; exports.Receiver = _chunkEQTYEU4Ujs.Receiver; exports.Schedules = Schedules; exports.SignatureError = _chunkEQTYEU4Ujs.SignatureError; exports.Topics = Topics;
//# sourceMappingURL=index.js.map
{
"name": "@upstash/qstash",
"version": "2.0.0-canary.19",
"version": "2.0.0-canary.20",
"description": "Official Typescript client for QStash",

@@ -40,2 +40,12 @@ "repository": {

},
"typesVersions": {
"*": {
".": [
"./dist/index.d.ts"
],
"cloudflare": [
"./dist/nextjs.d.ts"
]
}
},
"scripts": {

@@ -42,0 +52,0 @@ "build": "tsup",

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