@upstash/qstash 2.7.0-canary-1 → 2.7.0-workflow-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -29
- package/chunk-IJ5AEYLN.js +1 -0
- package/chunk-ITPUDOLS.js +2876 -0
- package/chunk-S7JMIMW4.mjs +0 -0
- package/chunk-SFGYSWJI.mjs +2876 -0
- package/client-BBvt1wQq.d.mts +1727 -0
- package/client-BBvt1wQq.d.ts +1727 -0
- package/index.d.mts +38 -1045
- package/index.d.ts +38 -1045
- package/index.js +41 -919
- package/index.mjs +24 -902
- package/nextjs.d.mts +4 -1
- package/nextjs.d.ts +4 -1
- package/nextjs.js +25 -6
- package/nextjs.mjs +22 -3
- package/nuxt.d.mts +17 -0
- package/nuxt.d.ts +17 -0
- package/nuxt.js +87 -0
- package/nuxt.mjs +87 -0
- package/package.json +1 -1
- package/solidjs.d.mts +13 -0
- package/solidjs.d.ts +13 -0
- package/solidjs.js +63 -0
- package/solidjs.mjs +63 -0
- package/svelte.d.mts +13 -0
- package/svelte.d.ts +13 -0
- package/svelte.js +62 -0
- package/svelte.mjs +62 -0
- package/workflow.d.mts +2 -0
- package/workflow.d.ts +2 -0
- package/workflow.js +18 -0
- package/workflow.mjs +18 -0
- package/chunk-CP4IU45K.mjs +0 -59
- package/chunk-UUR7N6E6.js +0 -59
package/nextjs.d.mts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { NextApiHandler } from 'next';
|
|
2
2
|
import { NextRequest, NextFetchEvent, NextResponse } from 'next/server';
|
|
3
|
+
import { a2 as RouteFunction, a3 as WorkflowServeOptions } from './client-BBvt1wQq.mjs';
|
|
4
|
+
import 'neverthrow';
|
|
3
5
|
|
|
4
6
|
type VerifySignatureConfig = {
|
|
5
7
|
currentSigningKey?: string;
|
|
@@ -21,5 +23,6 @@ declare function verifySignature(handler: NextApiHandler, config?: VerifySignatu
|
|
|
21
23
|
declare function verifySignatureEdge(handler: (request: NextRequest, nfe?: NextFetchEvent) => NextResponse | Promise<NextResponse>, config?: VerifySignatureConfig): (request: NextRequest, nfe: NextFetchEvent) => Promise<NextResponse<unknown>>;
|
|
22
24
|
type VerifySignatureAppRouterResponse = NextResponse | Promise<NextResponse> | Response | Promise<Response>;
|
|
23
25
|
declare function verifySignatureAppRouter(handler: ((request: Request) => VerifySignatureAppRouterResponse) | ((request: NextRequest) => VerifySignatureAppRouterResponse), config?: VerifySignatureConfig): (request: NextRequest | Request) => Promise<Response>;
|
|
26
|
+
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<NextResponse, TInitialPayload>, "onStepFinish">) => ((request: NextRequest) => Promise<NextResponse>);
|
|
24
27
|
|
|
25
|
-
export { type VerifySignatureConfig, verifySignature, verifySignatureAppRouter, verifySignatureEdge };
|
|
28
|
+
export { type VerifySignatureConfig, serve, verifySignature, verifySignatureAppRouter, verifySignatureEdge };
|
package/nextjs.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { NextApiHandler } from 'next';
|
|
2
2
|
import { NextRequest, NextFetchEvent, NextResponse } from 'next/server';
|
|
3
|
+
import { a2 as RouteFunction, a3 as WorkflowServeOptions } from './client-BBvt1wQq.js';
|
|
4
|
+
import 'neverthrow';
|
|
3
5
|
|
|
4
6
|
type VerifySignatureConfig = {
|
|
5
7
|
currentSigningKey?: string;
|
|
@@ -21,5 +23,6 @@ declare function verifySignature(handler: NextApiHandler, config?: VerifySignatu
|
|
|
21
23
|
declare function verifySignatureEdge(handler: (request: NextRequest, nfe?: NextFetchEvent) => NextResponse | Promise<NextResponse>, config?: VerifySignatureConfig): (request: NextRequest, nfe: NextFetchEvent) => Promise<NextResponse<unknown>>;
|
|
22
24
|
type VerifySignatureAppRouterResponse = NextResponse | Promise<NextResponse> | Response | Promise<Response>;
|
|
23
25
|
declare function verifySignatureAppRouter(handler: ((request: Request) => VerifySignatureAppRouterResponse) | ((request: NextRequest) => VerifySignatureAppRouterResponse), config?: VerifySignatureConfig): (request: NextRequest | Request) => Promise<Response>;
|
|
26
|
+
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<NextResponse, TInitialPayload>, "onStepFinish">) => ((request: NextRequest) => Promise<NextResponse>);
|
|
24
27
|
|
|
25
|
-
export { type VerifySignatureConfig, verifySignature, verifySignatureAppRouter, verifySignatureEdge };
|
|
28
|
+
export { type VerifySignatureConfig, serve, verifySignature, verifySignatureAppRouter, verifySignatureEdge };
|
package/nextjs.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var _chunkUUR7N6E6js = require('./chunk-UUR7N6E6.js');
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
var _chunkITPUDOLSjs = require('./chunk-ITPUDOLS.js');
|
|
6
|
+
|
|
7
|
+
// platforms/nextjs.ts
|
|
6
8
|
var _server = require('next/server');
|
|
7
9
|
var BAD_REQUEST = 400;
|
|
8
10
|
function verifySignature(handler, config) {
|
|
@@ -18,7 +20,7 @@ function verifySignature(handler, config) {
|
|
|
18
20
|
"nextSigningKey is required, either in the config or as env variable QSTASH_NEXT_SIGNING_KEY"
|
|
19
21
|
);
|
|
20
22
|
}
|
|
21
|
-
const receiver = new (0,
|
|
23
|
+
const receiver = new (0, _chunkITPUDOLSjs.Receiver)({
|
|
22
24
|
currentSigningKey,
|
|
23
25
|
nextSigningKey
|
|
24
26
|
});
|
|
@@ -70,7 +72,7 @@ function verifySignatureEdge(handler, config) {
|
|
|
70
72
|
"nextSigningKey is required, either in the config or as env variable QSTASH_NEXT_SIGNING_KEY"
|
|
71
73
|
);
|
|
72
74
|
}
|
|
73
|
-
const receiver = new (0,
|
|
75
|
+
const receiver = new (0, _chunkITPUDOLSjs.Receiver)({
|
|
74
76
|
currentSigningKey,
|
|
75
77
|
nextSigningKey
|
|
76
78
|
});
|
|
@@ -110,7 +112,7 @@ function verifySignatureAppRouter(handler, config) {
|
|
|
110
112
|
"nextSigningKey is required, either in the config or as env variable QSTASH_NEXT_SIGNING_KEY"
|
|
111
113
|
);
|
|
112
114
|
}
|
|
113
|
-
const receiver = new (0,
|
|
115
|
+
const receiver = new (0, _chunkITPUDOLSjs.Receiver)({
|
|
114
116
|
currentSigningKey,
|
|
115
117
|
nextSigningKey
|
|
116
118
|
});
|
|
@@ -137,8 +139,25 @@ function verifySignatureAppRouter(handler, config) {
|
|
|
137
139
|
return handler(request);
|
|
138
140
|
};
|
|
139
141
|
}
|
|
142
|
+
var serve2 = (routeFunction, options) => {
|
|
143
|
+
const handler = _chunkITPUDOLSjs.serve.call(void 0, routeFunction, {
|
|
144
|
+
onStepFinish: (workflowRunId) => new (0, _server.NextResponse)(JSON.stringify({ workflowRunId }), { status: 200 }),
|
|
145
|
+
...options
|
|
146
|
+
});
|
|
147
|
+
return async (request) => {
|
|
148
|
+
try {
|
|
149
|
+
return await handler(request);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
console.error(error);
|
|
152
|
+
return new (0, _server.NextResponse)(JSON.stringify(_chunkITPUDOLSjs.formatWorkflowError.call(void 0, error)), {
|
|
153
|
+
status: 500
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
|
|
140
159
|
|
|
141
160
|
|
|
142
161
|
|
|
143
162
|
|
|
144
|
-
exports.verifySignature = verifySignature; exports.verifySignatureAppRouter = verifySignatureAppRouter; exports.verifySignatureEdge = verifySignatureEdge;
|
|
163
|
+
exports.serve = serve2; exports.verifySignature = verifySignature; exports.verifySignatureAppRouter = verifySignatureAppRouter; exports.verifySignatureEdge = verifySignatureEdge;
|
package/nextjs.mjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Receiver
|
|
3
|
-
|
|
2
|
+
Receiver,
|
|
3
|
+
formatWorkflowError,
|
|
4
|
+
serve
|
|
5
|
+
} from "./chunk-SFGYSWJI.mjs";
|
|
4
6
|
|
|
5
|
-
//
|
|
7
|
+
// platforms/nextjs.ts
|
|
6
8
|
import { NextResponse } from "next/server";
|
|
7
9
|
var BAD_REQUEST = 400;
|
|
8
10
|
function verifySignature(handler, config) {
|
|
@@ -137,7 +139,24 @@ function verifySignatureAppRouter(handler, config) {
|
|
|
137
139
|
return handler(request);
|
|
138
140
|
};
|
|
139
141
|
}
|
|
142
|
+
var serve2 = (routeFunction, options) => {
|
|
143
|
+
const handler = serve(routeFunction, {
|
|
144
|
+
onStepFinish: (workflowRunId) => new NextResponse(JSON.stringify({ workflowRunId }), { status: 200 }),
|
|
145
|
+
...options
|
|
146
|
+
});
|
|
147
|
+
return async (request) => {
|
|
148
|
+
try {
|
|
149
|
+
return await handler(request);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
console.error(error);
|
|
152
|
+
return new NextResponse(JSON.stringify(formatWorkflowError(error)), {
|
|
153
|
+
status: 500
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
};
|
|
140
158
|
export {
|
|
159
|
+
serve2 as serve,
|
|
141
160
|
verifySignature,
|
|
142
161
|
verifySignatureAppRouter,
|
|
143
162
|
verifySignatureEdge
|
package/nuxt.d.mts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as h3 from 'h3';
|
|
2
|
+
import { H3Event } from 'h3';
|
|
3
|
+
import { a2 as RouteFunction, a3 as WorkflowServeOptions } from './client-BBvt1wQq.mjs';
|
|
4
|
+
import 'neverthrow';
|
|
5
|
+
|
|
6
|
+
type VerifySignatureConfig = {
|
|
7
|
+
currentSigningKey?: string;
|
|
8
|
+
nextSigningKey?: string;
|
|
9
|
+
clockTolerance?: number;
|
|
10
|
+
};
|
|
11
|
+
declare const verifySignatureNuxt: (handler: (event: H3Event) => Promise<unknown>, config?: VerifySignatureConfig) => h3.EventHandler<h3.EventHandlerRequest, Promise<unknown>>;
|
|
12
|
+
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) => h3.EventHandler<h3.EventHandlerRequest, Promise<Response | {
|
|
13
|
+
status: number;
|
|
14
|
+
body: string;
|
|
15
|
+
}>>;
|
|
16
|
+
|
|
17
|
+
export { serve, verifySignatureNuxt };
|
package/nuxt.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as h3 from 'h3';
|
|
2
|
+
import { H3Event } from 'h3';
|
|
3
|
+
import { a2 as RouteFunction, a3 as WorkflowServeOptions } from './client-BBvt1wQq.js';
|
|
4
|
+
import 'neverthrow';
|
|
5
|
+
|
|
6
|
+
type VerifySignatureConfig = {
|
|
7
|
+
currentSigningKey?: string;
|
|
8
|
+
nextSigningKey?: string;
|
|
9
|
+
clockTolerance?: number;
|
|
10
|
+
};
|
|
11
|
+
declare const verifySignatureNuxt: (handler: (event: H3Event) => Promise<unknown>, config?: VerifySignatureConfig) => h3.EventHandler<h3.EventHandlerRequest, Promise<unknown>>;
|
|
12
|
+
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) => h3.EventHandler<h3.EventHandlerRequest, Promise<Response | {
|
|
13
|
+
status: number;
|
|
14
|
+
body: string;
|
|
15
|
+
}>>;
|
|
16
|
+
|
|
17
|
+
export { serve, verifySignatureNuxt };
|
package/nuxt.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }require('./chunk-IJ5AEYLN.js');
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkITPUDOLSjs = require('./chunk-ITPUDOLS.js');
|
|
7
|
+
|
|
8
|
+
// platforms/nuxt.ts
|
|
9
|
+
var _h3 = require('h3');
|
|
10
|
+
var verifySignatureNuxt = (handler, config) => {
|
|
11
|
+
const currentSigningKey = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _ => _.currentSigningKey]), () => ( process.env.QSTASH_CURRENT_SIGNING_KEY));
|
|
12
|
+
if (!currentSigningKey) {
|
|
13
|
+
throw new Error(
|
|
14
|
+
"currentSigningKey is required, either in the config or as env variable QSTASH_CURRENT_SIGNING_KEY"
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
const nextSigningKey = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _2 => _2.nextSigningKey]), () => ( process.env.QSTASH_NEXT_SIGNING_KEY));
|
|
18
|
+
if (!nextSigningKey) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
"nextSigningKey is required, either in the config or as env variable QSTASH_NEXT_SIGNING_KEY"
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
const receiver = new (0, _chunkITPUDOLSjs.Receiver)({
|
|
24
|
+
currentSigningKey,
|
|
25
|
+
nextSigningKey
|
|
26
|
+
});
|
|
27
|
+
return _h3.defineEventHandler.call(void 0, async (event) => {
|
|
28
|
+
const signature = _h3.getHeader.call(void 0, event, "upstash-signature");
|
|
29
|
+
if (!signature) {
|
|
30
|
+
return { status: 403, body: "`Upstash-Signature` header is missing" };
|
|
31
|
+
}
|
|
32
|
+
if (typeof signature !== "string") {
|
|
33
|
+
throw new TypeError("`Upstash-Signature` header is not a string");
|
|
34
|
+
}
|
|
35
|
+
const body = await _h3.readRawBody.call(void 0, event);
|
|
36
|
+
const isValid = await receiver.verify({
|
|
37
|
+
signature,
|
|
38
|
+
body: JSON.stringify(body),
|
|
39
|
+
clockTolerance: _optionalChain([config, 'optionalAccess', _3 => _3.clockTolerance])
|
|
40
|
+
});
|
|
41
|
+
if (!isValid) {
|
|
42
|
+
return { status: 403, body: "invalid signature" };
|
|
43
|
+
}
|
|
44
|
+
event._requestBody = body;
|
|
45
|
+
return handler(event);
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
function transformHeaders(headers) {
|
|
49
|
+
const formattedHeaders = Object.entries(headers).map(([key, value]) => [
|
|
50
|
+
key,
|
|
51
|
+
Array.isArray(value) ? value.join(", ") : _nullishCoalesce(value, () => ( ""))
|
|
52
|
+
]);
|
|
53
|
+
return formattedHeaders;
|
|
54
|
+
}
|
|
55
|
+
var serve2 = (routeFunction, options) => {
|
|
56
|
+
const handler = _h3.defineEventHandler.call(void 0, async (event) => {
|
|
57
|
+
const method = event.node.req.method;
|
|
58
|
+
if (_optionalChain([method, 'optionalAccess', _4 => _4.toUpperCase, 'call', _5 => _5()]) !== "POST") {
|
|
59
|
+
return {
|
|
60
|
+
status: 405,
|
|
61
|
+
body: "Only POST requests are allowed in worklfows"
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const request_ = event.node.req;
|
|
65
|
+
const protocol = request_.headers["x-forwarded-proto"];
|
|
66
|
+
const host = request_.headers.host;
|
|
67
|
+
const url = `${protocol}://${host}${event.path}`;
|
|
68
|
+
const headers = transformHeaders(request_.headers);
|
|
69
|
+
const request = new Request(url, {
|
|
70
|
+
headers,
|
|
71
|
+
body: await _h3.readRawBody.call(void 0, event),
|
|
72
|
+
method: "POST"
|
|
73
|
+
});
|
|
74
|
+
const serveHandler = _chunkITPUDOLSjs.serve.call(void 0, routeFunction, options);
|
|
75
|
+
try {
|
|
76
|
+
return await serveHandler(request);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.error(error);
|
|
79
|
+
return new Response(JSON.stringify(_chunkITPUDOLSjs.formatWorkflowError.call(void 0, error)), { status: 500 });
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
return handler;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
exports.serve = serve2; exports.verifySignatureNuxt = verifySignatureNuxt;
|
package/nuxt.mjs
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import "./chunk-S7JMIMW4.mjs";
|
|
2
|
+
import {
|
|
3
|
+
Receiver,
|
|
4
|
+
formatWorkflowError,
|
|
5
|
+
serve
|
|
6
|
+
} from "./chunk-SFGYSWJI.mjs";
|
|
7
|
+
|
|
8
|
+
// platforms/nuxt.ts
|
|
9
|
+
import { defineEventHandler, getHeader, readRawBody } from "h3";
|
|
10
|
+
var verifySignatureNuxt = (handler, config) => {
|
|
11
|
+
const currentSigningKey = config?.currentSigningKey ?? process.env.QSTASH_CURRENT_SIGNING_KEY;
|
|
12
|
+
if (!currentSigningKey) {
|
|
13
|
+
throw new Error(
|
|
14
|
+
"currentSigningKey is required, either in the config or as env variable QSTASH_CURRENT_SIGNING_KEY"
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
const nextSigningKey = config?.nextSigningKey ?? process.env.QSTASH_NEXT_SIGNING_KEY;
|
|
18
|
+
if (!nextSigningKey) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
"nextSigningKey is required, either in the config or as env variable QSTASH_NEXT_SIGNING_KEY"
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
const receiver = new Receiver({
|
|
24
|
+
currentSigningKey,
|
|
25
|
+
nextSigningKey
|
|
26
|
+
});
|
|
27
|
+
return defineEventHandler(async (event) => {
|
|
28
|
+
const signature = getHeader(event, "upstash-signature");
|
|
29
|
+
if (!signature) {
|
|
30
|
+
return { status: 403, body: "`Upstash-Signature` header is missing" };
|
|
31
|
+
}
|
|
32
|
+
if (typeof signature !== "string") {
|
|
33
|
+
throw new TypeError("`Upstash-Signature` header is not a string");
|
|
34
|
+
}
|
|
35
|
+
const body = await readRawBody(event);
|
|
36
|
+
const isValid = await receiver.verify({
|
|
37
|
+
signature,
|
|
38
|
+
body: JSON.stringify(body),
|
|
39
|
+
clockTolerance: config?.clockTolerance
|
|
40
|
+
});
|
|
41
|
+
if (!isValid) {
|
|
42
|
+
return { status: 403, body: "invalid signature" };
|
|
43
|
+
}
|
|
44
|
+
event._requestBody = body;
|
|
45
|
+
return handler(event);
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
function transformHeaders(headers) {
|
|
49
|
+
const formattedHeaders = Object.entries(headers).map(([key, value]) => [
|
|
50
|
+
key,
|
|
51
|
+
Array.isArray(value) ? value.join(", ") : value ?? ""
|
|
52
|
+
]);
|
|
53
|
+
return formattedHeaders;
|
|
54
|
+
}
|
|
55
|
+
var serve2 = (routeFunction, options) => {
|
|
56
|
+
const handler = defineEventHandler(async (event) => {
|
|
57
|
+
const method = event.node.req.method;
|
|
58
|
+
if (method?.toUpperCase() !== "POST") {
|
|
59
|
+
return {
|
|
60
|
+
status: 405,
|
|
61
|
+
body: "Only POST requests are allowed in worklfows"
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const request_ = event.node.req;
|
|
65
|
+
const protocol = request_.headers["x-forwarded-proto"];
|
|
66
|
+
const host = request_.headers.host;
|
|
67
|
+
const url = `${protocol}://${host}${event.path}`;
|
|
68
|
+
const headers = transformHeaders(request_.headers);
|
|
69
|
+
const request = new Request(url, {
|
|
70
|
+
headers,
|
|
71
|
+
body: await readRawBody(event),
|
|
72
|
+
method: "POST"
|
|
73
|
+
});
|
|
74
|
+
const serveHandler = serve(routeFunction, options);
|
|
75
|
+
try {
|
|
76
|
+
return await serveHandler(request);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.error(error);
|
|
79
|
+
return new Response(JSON.stringify(formatWorkflowError(error)), { status: 500 });
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
return handler;
|
|
83
|
+
};
|
|
84
|
+
export {
|
|
85
|
+
serve2 as serve,
|
|
86
|
+
verifySignatureNuxt
|
|
87
|
+
};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"v2.7.0-
|
|
1
|
+
{"version":"v2.7.0-workflow-alpha.2","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"},"./nextjs":{"import":"./nextjs.js","require":"./nextjs.js"},"./dist/nextjs":{"import":"./nextjs.js","require":"./nextjs.js"},"./nuxt":{"types":"./nuxt.d.ts","import":"./nuxt.mjs","require":"./nuxt.js"},"./svelte":{"types":"./svelte.d.ts","import":"./svelte.mjs","require":"./svelte.js"},"./solidjs":{"types":"./solidjs.d.ts","import":"./solidjs.mjs","require":"./solidjs.js"},"./workflow":{"types":"./workflow.d.ts","import":"./workflow.mjs","require":"./workflow.js"}},"typesVersions":{"*":{"nextjs":["./nextjs.d.ts"]}},"keywords":["qstash","queue","events","serverless","upstash"],"scripts":{"build":"tsup && cp README.md ./dist/ && cp package.json ./dist/ && cp LICENSE ./dist/","test":"bun test","fmt":"prettier --write .","lint":"tsc && eslint \"src/**/*.{js,ts,tsx}\" --quiet --fix"},"devDependencies":{"@commitlint/cli":"^19.2.2","@commitlint/config-conventional":"^19.2.2","@types/bun":"^1.1.1","@types/crypto-js":"^4.2.0","@typescript-eslint/eslint-plugin":"^7.0.1","@typescript-eslint/parser":"^7.0.1","ai":"^3.1.28","bun-types":"^1.1.7","eslint":"^8","eslint-plugin-unicorn":"^51.0.1","husky":"^9.0.10","neverthrow":"^7.0.1","next":"^14.0.2","prettier":"^3.2.5","tsup":"latest","typescript":"^5.4.5","undici-types":"^6.16.0","vitest":"latest"},"dependencies":{"@solidjs/start":"^1.0.6","@sveltejs/kit":"^2.5.18","crypto-js":">=4.2.0","h3":"^1.12.0","jose":"^ 5.2.3"}}
|
package/solidjs.d.mts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { APIHandler, APIEvent } from '@solidjs/start/server';
|
|
2
|
+
import { a2 as RouteFunction, a3 as WorkflowServeOptions } from './client-BBvt1wQq.mjs';
|
|
3
|
+
import 'neverthrow';
|
|
4
|
+
|
|
5
|
+
type VerifySignatureConfig = {
|
|
6
|
+
currentSigningKey?: string;
|
|
7
|
+
nextSigningKey?: string;
|
|
8
|
+
clockTolerance?: number;
|
|
9
|
+
};
|
|
10
|
+
declare const verifySignatureSolidjs: (handler: APIHandler, config?: VerifySignatureConfig) => APIHandler;
|
|
11
|
+
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) => (event: APIEvent) => Promise<Response>;
|
|
12
|
+
|
|
13
|
+
export { serve, verifySignatureSolidjs };
|
package/solidjs.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { APIHandler, APIEvent } from '@solidjs/start/server';
|
|
2
|
+
import { a2 as RouteFunction, a3 as WorkflowServeOptions } from './client-BBvt1wQq.js';
|
|
3
|
+
import 'neverthrow';
|
|
4
|
+
|
|
5
|
+
type VerifySignatureConfig = {
|
|
6
|
+
currentSigningKey?: string;
|
|
7
|
+
nextSigningKey?: string;
|
|
8
|
+
clockTolerance?: number;
|
|
9
|
+
};
|
|
10
|
+
declare const verifySignatureSolidjs: (handler: APIHandler, config?: VerifySignatureConfig) => APIHandler;
|
|
11
|
+
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) => (event: APIEvent) => Promise<Response>;
|
|
12
|
+
|
|
13
|
+
export { serve, verifySignatureSolidjs };
|
package/solidjs.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }require('./chunk-IJ5AEYLN.js');
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkITPUDOLSjs = require('./chunk-ITPUDOLS.js');
|
|
7
|
+
|
|
8
|
+
// platforms/solidjs.ts
|
|
9
|
+
var verifySignatureSolidjs = (handler, config) => {
|
|
10
|
+
const currentSigningKey = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _ => _.currentSigningKey]), () => ( process.env.QSTASH_CURRENT_SIGNING_KEY));
|
|
11
|
+
if (!currentSigningKey) {
|
|
12
|
+
throw new Error("currentSigningKey is required, either in the config or from the env");
|
|
13
|
+
}
|
|
14
|
+
const nextSigningKey = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _2 => _2.nextSigningKey]), () => ( process.env.QSTASH_NEXT_SIGNING_KEY));
|
|
15
|
+
if (!nextSigningKey) {
|
|
16
|
+
throw new Error("nextSigningKey is required, either in the config or from the env");
|
|
17
|
+
}
|
|
18
|
+
const receiver = new (0, _chunkITPUDOLSjs.Receiver)({
|
|
19
|
+
currentSigningKey,
|
|
20
|
+
nextSigningKey
|
|
21
|
+
});
|
|
22
|
+
return async (event) => {
|
|
23
|
+
const signature = event.request.headers.get("upstash-signature");
|
|
24
|
+
if (!signature) {
|
|
25
|
+
return new Response("`Upstash-Signature` header is missing", { status: 403 });
|
|
26
|
+
}
|
|
27
|
+
if (typeof signature !== "string") {
|
|
28
|
+
throw new TypeError("`Upstash-Signature` header is not a string");
|
|
29
|
+
}
|
|
30
|
+
const cloneRequest = event.request.clone();
|
|
31
|
+
const body = await cloneRequest.text();
|
|
32
|
+
const isValid = await receiver.verify({
|
|
33
|
+
signature,
|
|
34
|
+
body,
|
|
35
|
+
clockTolerance: _optionalChain([config, 'optionalAccess', _3 => _3.clockTolerance])
|
|
36
|
+
});
|
|
37
|
+
if (!isValid) {
|
|
38
|
+
return new Response("invalid signature", { status: 403 });
|
|
39
|
+
}
|
|
40
|
+
return handler(event);
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
var serve2 = (routeFunction, options) => {
|
|
44
|
+
const handler = async (event) => {
|
|
45
|
+
const method = event.request.method;
|
|
46
|
+
if (method.toUpperCase() !== "POST") {
|
|
47
|
+
return new Response("Only POST requests are allowed in worklfows", { status: 405 });
|
|
48
|
+
}
|
|
49
|
+
const serveHandler = _chunkITPUDOLSjs.serve.call(void 0, routeFunction, options);
|
|
50
|
+
try {
|
|
51
|
+
const result = await serveHandler(event.request);
|
|
52
|
+
return result;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error(error);
|
|
55
|
+
return new Response(JSON.stringify(_chunkITPUDOLSjs.formatWorkflowError.call(void 0, error)), { status: 500 });
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return handler;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
exports.serve = serve2; exports.verifySignatureSolidjs = verifySignatureSolidjs;
|
package/solidjs.mjs
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import "./chunk-S7JMIMW4.mjs";
|
|
2
|
+
import {
|
|
3
|
+
Receiver,
|
|
4
|
+
formatWorkflowError,
|
|
5
|
+
serve
|
|
6
|
+
} from "./chunk-SFGYSWJI.mjs";
|
|
7
|
+
|
|
8
|
+
// platforms/solidjs.ts
|
|
9
|
+
var verifySignatureSolidjs = (handler, config) => {
|
|
10
|
+
const currentSigningKey = config?.currentSigningKey ?? process.env.QSTASH_CURRENT_SIGNING_KEY;
|
|
11
|
+
if (!currentSigningKey) {
|
|
12
|
+
throw new Error("currentSigningKey is required, either in the config or from the env");
|
|
13
|
+
}
|
|
14
|
+
const nextSigningKey = config?.nextSigningKey ?? process.env.QSTASH_NEXT_SIGNING_KEY;
|
|
15
|
+
if (!nextSigningKey) {
|
|
16
|
+
throw new Error("nextSigningKey is required, either in the config or from the env");
|
|
17
|
+
}
|
|
18
|
+
const receiver = new Receiver({
|
|
19
|
+
currentSigningKey,
|
|
20
|
+
nextSigningKey
|
|
21
|
+
});
|
|
22
|
+
return async (event) => {
|
|
23
|
+
const signature = event.request.headers.get("upstash-signature");
|
|
24
|
+
if (!signature) {
|
|
25
|
+
return new Response("`Upstash-Signature` header is missing", { status: 403 });
|
|
26
|
+
}
|
|
27
|
+
if (typeof signature !== "string") {
|
|
28
|
+
throw new TypeError("`Upstash-Signature` header is not a string");
|
|
29
|
+
}
|
|
30
|
+
const cloneRequest = event.request.clone();
|
|
31
|
+
const body = await cloneRequest.text();
|
|
32
|
+
const isValid = await receiver.verify({
|
|
33
|
+
signature,
|
|
34
|
+
body,
|
|
35
|
+
clockTolerance: config?.clockTolerance
|
|
36
|
+
});
|
|
37
|
+
if (!isValid) {
|
|
38
|
+
return new Response("invalid signature", { status: 403 });
|
|
39
|
+
}
|
|
40
|
+
return handler(event);
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
var serve2 = (routeFunction, options) => {
|
|
44
|
+
const handler = async (event) => {
|
|
45
|
+
const method = event.request.method;
|
|
46
|
+
if (method.toUpperCase() !== "POST") {
|
|
47
|
+
return new Response("Only POST requests are allowed in worklfows", { status: 405 });
|
|
48
|
+
}
|
|
49
|
+
const serveHandler = serve(routeFunction, options);
|
|
50
|
+
try {
|
|
51
|
+
const result = await serveHandler(event.request);
|
|
52
|
+
return result;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error(error);
|
|
55
|
+
return new Response(JSON.stringify(formatWorkflowError(error)), { status: 500 });
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return handler;
|
|
59
|
+
};
|
|
60
|
+
export {
|
|
61
|
+
serve2 as serve,
|
|
62
|
+
verifySignatureSolidjs
|
|
63
|
+
};
|
package/svelte.d.mts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RequestHandler } from '@sveltejs/kit';
|
|
2
|
+
import { a2 as RouteFunction, a3 as WorkflowServeOptions } from './client-BBvt1wQq.mjs';
|
|
3
|
+
import 'neverthrow';
|
|
4
|
+
|
|
5
|
+
type VerifySignatureConfig = {
|
|
6
|
+
currentSigningKey: string;
|
|
7
|
+
nextSigningKey: string;
|
|
8
|
+
clockTolerance?: number;
|
|
9
|
+
};
|
|
10
|
+
declare const verifySignatureSvelte: <Parameters extends Partial<Record<string, string>> = Partial<Record<string, string>>, RouteId extends string | null = string | null>(handler: RequestHandler<Parameters, RouteId>, config: VerifySignatureConfig) => RequestHandler<Parameters, RouteId>;
|
|
11
|
+
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, qstashClient: WorkflowServeOptions["qstashClient"], options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish" | "qstashClient">) => RequestHandler;
|
|
12
|
+
|
|
13
|
+
export { serve, verifySignatureSvelte };
|
package/svelte.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RequestHandler } from '@sveltejs/kit';
|
|
2
|
+
import { a2 as RouteFunction, a3 as WorkflowServeOptions } from './client-BBvt1wQq.js';
|
|
3
|
+
import 'neverthrow';
|
|
4
|
+
|
|
5
|
+
type VerifySignatureConfig = {
|
|
6
|
+
currentSigningKey: string;
|
|
7
|
+
nextSigningKey: string;
|
|
8
|
+
clockTolerance?: number;
|
|
9
|
+
};
|
|
10
|
+
declare const verifySignatureSvelte: <Parameters extends Partial<Record<string, string>> = Partial<Record<string, string>>, RouteId extends string | null = string | null>(handler: RequestHandler<Parameters, RouteId>, config: VerifySignatureConfig) => RequestHandler<Parameters, RouteId>;
|
|
11
|
+
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, qstashClient: WorkflowServeOptions["qstashClient"], options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish" | "qstashClient">) => RequestHandler;
|
|
12
|
+
|
|
13
|
+
export { serve, verifySignatureSvelte };
|
package/svelte.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('./chunk-IJ5AEYLN.js');
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkITPUDOLSjs = require('./chunk-ITPUDOLS.js');
|
|
7
|
+
|
|
8
|
+
// platforms/svelte.ts
|
|
9
|
+
var verifySignatureSvelte = (handler, config) => {
|
|
10
|
+
const currentSigningKey = config.currentSigningKey;
|
|
11
|
+
if (!currentSigningKey) {
|
|
12
|
+
throw new Error("currentSigningKey is required, either in the config or from the env");
|
|
13
|
+
}
|
|
14
|
+
const nextSigningKey = config.nextSigningKey;
|
|
15
|
+
if (!nextSigningKey) {
|
|
16
|
+
throw new Error("nextSigningKey is required, either in the config or from the env");
|
|
17
|
+
}
|
|
18
|
+
const receiver = new (0, _chunkITPUDOLSjs.Receiver)({
|
|
19
|
+
currentSigningKey,
|
|
20
|
+
nextSigningKey
|
|
21
|
+
});
|
|
22
|
+
const wrappedHandler = async (event) => {
|
|
23
|
+
const signature = event.request.headers.get("upstash-signature");
|
|
24
|
+
if (!signature) {
|
|
25
|
+
return new Response("`Upstash-Signature` header is missing", { status: 403 });
|
|
26
|
+
}
|
|
27
|
+
if (typeof signature !== "string") {
|
|
28
|
+
throw new TypeError("`Upstash-Signature` header is not a string");
|
|
29
|
+
}
|
|
30
|
+
const cloneRequest = event.request.clone();
|
|
31
|
+
const body = await cloneRequest.text();
|
|
32
|
+
const isValid = await receiver.verify({
|
|
33
|
+
signature,
|
|
34
|
+
body,
|
|
35
|
+
clockTolerance: config.clockTolerance
|
|
36
|
+
});
|
|
37
|
+
if (!isValid) {
|
|
38
|
+
return new Response("invalid signature", { status: 403 });
|
|
39
|
+
}
|
|
40
|
+
return handler(event);
|
|
41
|
+
};
|
|
42
|
+
return wrappedHandler;
|
|
43
|
+
};
|
|
44
|
+
var serve2 = (routeFunction, qstashClient, options) => {
|
|
45
|
+
const handler = async ({ request }) => {
|
|
46
|
+
const serveMethod = _chunkITPUDOLSjs.serve.call(void 0, routeFunction, {
|
|
47
|
+
qstashClient,
|
|
48
|
+
...options
|
|
49
|
+
});
|
|
50
|
+
try {
|
|
51
|
+
return await serveMethod(request);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error(error);
|
|
54
|
+
return new Response(JSON.stringify(_chunkITPUDOLSjs.formatWorkflowError.call(void 0, error)), { status: 500 });
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
return handler;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
exports.serve = serve2; exports.verifySignatureSvelte = verifySignatureSvelte;
|