@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/svelte.mjs ADDED
@@ -0,0 +1,62 @@
1
+ import "./chunk-S7JMIMW4.mjs";
2
+ import {
3
+ Receiver,
4
+ formatWorkflowError,
5
+ serve
6
+ } from "./chunk-SFGYSWJI.mjs";
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 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 = serve(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(formatWorkflowError(error)), { status: 500 });
55
+ }
56
+ };
57
+ return handler;
58
+ };
59
+ export {
60
+ serve2 as serve,
61
+ verifySignatureSvelte
62
+ };
package/workflow.d.mts ADDED
@@ -0,0 +1,2 @@
1
+ export { ad as AsyncStepFunction, a8 as DisabledWorkflowContext, F as FailureFunctionPayload, ag as FinishCondition, ai as LogLevel, af as ParallelCallState, ab as RawStep, ah as RequiredExceptFields, a2 as RouteFunction, S as Step, ae as StepFunction, aa as StepType, a9 as StepTypes, ac as SyncStepFunction, a4 as Workflow, a7 as WorkflowContext, ak as WorkflowLogger, aj as WorkflowLoggerOptions, a3 as WorkflowServeOptions, a5 as processOptions, a6 as serve } from './client-BBvt1wQq.mjs';
2
+ import 'neverthrow';
package/workflow.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { ad as AsyncStepFunction, a8 as DisabledWorkflowContext, F as FailureFunctionPayload, ag as FinishCondition, ai as LogLevel, af as ParallelCallState, ab as RawStep, ah as RequiredExceptFields, a2 as RouteFunction, S as Step, ae as StepFunction, aa as StepType, a9 as StepTypes, ac as SyncStepFunction, a4 as Workflow, a7 as WorkflowContext, ak as WorkflowLogger, aj as WorkflowLoggerOptions, a3 as WorkflowServeOptions, a5 as processOptions, a6 as serve } from './client-BBvt1wQq.js';
2
+ import 'neverthrow';
package/workflow.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+ var _chunkITPUDOLSjs = require('./chunk-ITPUDOLS.js');
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+ exports.DisabledWorkflowContext = _chunkITPUDOLSjs.DisabledWorkflowContext; exports.StepTypes = _chunkITPUDOLSjs.StepTypes; exports.Workflow = _chunkITPUDOLSjs.Workflow; exports.WorkflowContext = _chunkITPUDOLSjs.WorkflowContext; exports.WorkflowLogger = _chunkITPUDOLSjs.WorkflowLogger; exports.processOptions = _chunkITPUDOLSjs.processOptions; exports.serve = _chunkITPUDOLSjs.serve;
package/workflow.mjs ADDED
@@ -0,0 +1,18 @@
1
+ import {
2
+ DisabledWorkflowContext,
3
+ StepTypes,
4
+ Workflow,
5
+ WorkflowContext,
6
+ WorkflowLogger,
7
+ processOptions,
8
+ serve
9
+ } from "./chunk-SFGYSWJI.mjs";
10
+ export {
11
+ DisabledWorkflowContext,
12
+ StepTypes,
13
+ Workflow,
14
+ WorkflowContext,
15
+ WorkflowLogger,
16
+ processOptions,
17
+ serve
18
+ };
@@ -1,59 +0,0 @@
1
- // src/receiver.ts
2
- import * as jose from "jose";
3
- import crypto from "crypto-js";
4
- var SignatureError = class extends Error {
5
- constructor(message) {
6
- super(message);
7
- this.name = "SignatureError";
8
- }
9
- };
10
- var Receiver = class {
11
- currentSigningKey;
12
- nextSigningKey;
13
- constructor(config) {
14
- this.currentSigningKey = config.currentSigningKey;
15
- this.nextSigningKey = config.nextSigningKey;
16
- }
17
- /**
18
- * Verify the signature of a request.
19
- *
20
- * Tries to verify the signature with the current signing key.
21
- * If that fails, maybe because you have rotated the keys recently, it will
22
- * try to verify the signature with the next signing key.
23
- *
24
- * If that fails, the signature is invalid and a `SignatureError` is thrown.
25
- */
26
- async verify(request) {
27
- const isValid = await this.verifyWithKey(this.currentSigningKey, request);
28
- if (isValid) {
29
- return true;
30
- }
31
- return this.verifyWithKey(this.nextSigningKey, request);
32
- }
33
- /**
34
- * Verify signature with a specific signing key
35
- */
36
- async verifyWithKey(key, request) {
37
- const jwt = await jose.jwtVerify(request.signature, new TextEncoder().encode(key), {
38
- issuer: "Upstash",
39
- clockTolerance: request.clockTolerance
40
- }).catch((error) => {
41
- throw new SignatureError(error.message);
42
- });
43
- const p = jwt.payload;
44
- if (request.url !== void 0 && p.sub !== request.url) {
45
- throw new SignatureError(`invalid subject: ${p.sub}, want: ${request.url}`);
46
- }
47
- const bodyHash = crypto.SHA256(request.body).toString(crypto.enc.Base64url);
48
- const padding = new RegExp(/=+$/);
49
- if (p.body.replace(padding, "") !== bodyHash.replace(padding, "")) {
50
- throw new SignatureError(`body hash does not match, want: ${p.body}, got: ${bodyHash}`);
51
- }
52
- return true;
53
- }
54
- };
55
-
56
- export {
57
- SignatureError,
58
- Receiver
59
- };
package/chunk-UUR7N6E6.js DELETED
@@ -1,59 +0,0 @@
1
- "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; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/receiver.ts
2
- var _jose = require('jose'); var jose = _interopRequireWildcard(_jose);
3
- var _cryptojs = require('crypto-js'); var _cryptojs2 = _interopRequireDefault(_cryptojs);
4
- var SignatureError = class extends Error {
5
- constructor(message) {
6
- super(message);
7
- this.name = "SignatureError";
8
- }
9
- };
10
- var Receiver = class {
11
-
12
-
13
- constructor(config) {
14
- this.currentSigningKey = config.currentSigningKey;
15
- this.nextSigningKey = config.nextSigningKey;
16
- }
17
- /**
18
- * Verify the signature of a request.
19
- *
20
- * Tries to verify the signature with the current signing key.
21
- * If that fails, maybe because you have rotated the keys recently, it will
22
- * try to verify the signature with the next signing key.
23
- *
24
- * If that fails, the signature is invalid and a `SignatureError` is thrown.
25
- */
26
- async verify(request) {
27
- const isValid = await this.verifyWithKey(this.currentSigningKey, request);
28
- if (isValid) {
29
- return true;
30
- }
31
- return this.verifyWithKey(this.nextSigningKey, request);
32
- }
33
- /**
34
- * Verify signature with a specific signing key
35
- */
36
- async verifyWithKey(key, request) {
37
- const jwt = await jose.jwtVerify(request.signature, new TextEncoder().encode(key), {
38
- issuer: "Upstash",
39
- clockTolerance: request.clockTolerance
40
- }).catch((error) => {
41
- throw new SignatureError(error.message);
42
- });
43
- const p = jwt.payload;
44
- if (request.url !== void 0 && p.sub !== request.url) {
45
- throw new SignatureError(`invalid subject: ${p.sub}, want: ${request.url}`);
46
- }
47
- const bodyHash = _cryptojs2.default.SHA256(request.body).toString(_cryptojs2.default.enc.Base64url);
48
- const padding = new RegExp(/=+$/);
49
- if (p.body.replace(padding, "") !== bodyHash.replace(padding, "")) {
50
- throw new SignatureError(`body hash does not match, want: ${p.body}, got: ${bodyHash}`);
51
- }
52
- return true;
53
- }
54
- };
55
-
56
-
57
-
58
-
59
- exports.SignatureError = SignatureError; exports.Receiver = Receiver;