@upstash/qstash 2.7.13 → 2.7.14

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/solidjs.js CHANGED
@@ -61,11 +61,14 @@ var Receiver = class {
61
61
  * If that fails, the signature is invalid and a `SignatureError` is thrown.
62
62
  */
63
63
  async verify(request) {
64
- const isValid = await this.verifyWithKey(this.currentSigningKey, request);
65
- if (isValid) {
66
- return true;
64
+ let payload;
65
+ try {
66
+ payload = await this.verifyWithKey(this.currentSigningKey, request);
67
+ } catch {
68
+ payload = await this.verifyWithKey(this.nextSigningKey, request);
67
69
  }
68
- return this.verifyWithKey(this.nextSigningKey, request);
70
+ this.verifyBodyAndUrl(payload, request);
71
+ return true;
69
72
  }
70
73
  /**
71
74
  * Verify signature with a specific signing key
@@ -77,7 +80,10 @@ var Receiver = class {
77
80
  }).catch((error) => {
78
81
  throw new SignatureError(error.message);
79
82
  });
80
- const p = jwt.payload;
83
+ return jwt.payload;
84
+ }
85
+ verifyBodyAndUrl(payload, request) {
86
+ const p = payload;
81
87
  if (request.url !== void 0 && p.sub !== request.url) {
82
88
  throw new SignatureError(`invalid subject: ${p.sub}, want: ${request.url}`);
83
89
  }
@@ -86,7 +92,14 @@ var Receiver = class {
86
92
  if (p.body.replace(padding, "") !== bodyHash.replace(padding, "")) {
87
93
  throw new SignatureError(`body hash does not match, want: ${p.body}, got: ${bodyHash}`);
88
94
  }
89
- return true;
95
+ }
96
+ };
97
+
98
+ // src/client/api/utils.ts
99
+ var appendAPIOptions = (request, headers) => {
100
+ if (request.api?.name === "email") {
101
+ headers.set("Authorization", request.api.provider.token);
102
+ request.method = request.method ?? "POST";
90
103
  }
91
104
  };
92
105
 
@@ -523,7 +536,7 @@ var Chat = class _Chat {
523
536
 
524
537
  // src/client/llm/utils.ts
525
538
  function appendLLMOptionsIfNeeded(request, headers, http) {
526
- if (!request.api)
539
+ if (request.api?.name === "email" || !request.api)
527
540
  return;
528
541
  const provider = request.api.provider;
529
542
  const analytics = request.api.analytics;
@@ -680,7 +693,15 @@ function processHeaders(request) {
680
693
  return headers;
681
694
  }
682
695
  function getRequestPath(request) {
683
- return request.url ?? request.urlGroup ?? request.topic ?? `api/${request.api?.name}`;
696
+ const nonApiPath = request.url ?? request.urlGroup ?? request.topic;
697
+ if (nonApiPath)
698
+ return nonApiPath;
699
+ if (request.api?.name === "llm")
700
+ return `api/${request.api.name}`;
701
+ if (request.api?.name === "email") {
702
+ return request.api.provider.baseUrl;
703
+ }
704
+ throw new QstashError(`Failed to infer request path for ${JSON.stringify(request)}`);
684
705
  }
685
706
  var NANOID_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
686
707
  var NANOID_LENGTH = 21;
@@ -693,10 +714,18 @@ function decodeBase64(base64) {
693
714
  const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0));
694
715
  return new TextDecoder().decode(intArray);
695
716
  } catch (error) {
696
- console.warn(
697
- `Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
698
- );
699
- return atob(base64);
717
+ try {
718
+ const result = atob(base64);
719
+ console.warn(
720
+ `Upstash QStash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
721
+ );
722
+ return result;
723
+ } catch (error2) {
724
+ console.warn(
725
+ `Upstash QStash: Failed to decode base64 "${base64}" with atob. Returning it as it is. ${error2}`
726
+ );
727
+ return base64;
728
+ }
700
729
  }
701
730
  }
702
731
 
@@ -789,6 +818,7 @@ var Queue = class {
789
818
  headers.set("Content-Type", "application/json");
790
819
  ensureCallbackPresent(request);
791
820
  appendLLMOptionsIfNeeded(request, headers, this.http);
821
+ appendAPIOptions(request, headers);
792
822
  const response = await this.enqueue({
793
823
  ...request,
794
824
  body: JSON.stringify(request.body),
@@ -871,6 +901,9 @@ var Schedules = class {
871
901
  if (request.scheduleId !== void 0) {
872
902
  headers.set("Upstash-Schedule-Id", request.scheduleId);
873
903
  }
904
+ if (request.queueName !== void 0) {
905
+ headers.set("Upstash-Queue-Name", request.queueName);
906
+ }
874
907
  return await this.http.request({
875
908
  method: "POST",
876
909
  headers,
@@ -2474,6 +2507,7 @@ var Client = class {
2474
2507
  headers.set("Content-Type", "application/json");
2475
2508
  ensureCallbackPresent(request);
2476
2509
  appendLLMOptionsIfNeeded(request, headers, this.http);
2510
+ appendAPIOptions(request, headers);
2477
2511
  const response = await this.publish({
2478
2512
  ...request,
2479
2513
  headers,
@@ -2518,6 +2552,7 @@ var Client = class {
2518
2552
  message.headers = new Headers(message.headers);
2519
2553
  ensureCallbackPresent(message);
2520
2554
  appendLLMOptionsIfNeeded(message, message.headers, this.http);
2555
+ appendAPIOptions(message, message.headers);
2521
2556
  message.headers.set("Content-Type", "application/json");
2522
2557
  }
2523
2558
  const response = await this.batch(request);
package/solidjs.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import "./chunk-CIVGPRQN.mjs";
1
+ import "./chunk-AROUU44N.mjs";
2
2
  import {
3
3
  Receiver,
4
4
  serve
5
- } from "./chunk-Q6E5NF42.mjs";
5
+ } from "./chunk-Q2AGFQYM.mjs";
6
6
 
7
7
  // platforms/solidjs.ts
8
8
  var verifySignatureSolidjs = (handler, config) => {
package/svelte.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { RequestHandler } from '@sveltejs/kit';
2
- import { a2 as RouteFunction, a3 as WorkflowServeOptions } from './client-DEZq0-qk.mjs';
2
+ import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-kxUsvnWj.mjs';
3
3
  import 'neverthrow';
4
4
 
5
5
  type VerifySignatureConfig = {
package/svelte.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { RequestHandler } from '@sveltejs/kit';
2
- import { a2 as RouteFunction, a3 as WorkflowServeOptions } from './client-DEZq0-qk.js';
2
+ import { a3 as RouteFunction, a4 as WorkflowServeOptions } from './client-kxUsvnWj.js';
3
3
  import 'neverthrow';
4
4
 
5
5
  type VerifySignatureConfig = {
package/svelte.js CHANGED
@@ -61,11 +61,14 @@ var Receiver = class {
61
61
  * If that fails, the signature is invalid and a `SignatureError` is thrown.
62
62
  */
63
63
  async verify(request) {
64
- const isValid = await this.verifyWithKey(this.currentSigningKey, request);
65
- if (isValid) {
66
- return true;
64
+ let payload;
65
+ try {
66
+ payload = await this.verifyWithKey(this.currentSigningKey, request);
67
+ } catch {
68
+ payload = await this.verifyWithKey(this.nextSigningKey, request);
67
69
  }
68
- return this.verifyWithKey(this.nextSigningKey, request);
70
+ this.verifyBodyAndUrl(payload, request);
71
+ return true;
69
72
  }
70
73
  /**
71
74
  * Verify signature with a specific signing key
@@ -77,7 +80,10 @@ var Receiver = class {
77
80
  }).catch((error) => {
78
81
  throw new SignatureError(error.message);
79
82
  });
80
- const p = jwt.payload;
83
+ return jwt.payload;
84
+ }
85
+ verifyBodyAndUrl(payload, request) {
86
+ const p = payload;
81
87
  if (request.url !== void 0 && p.sub !== request.url) {
82
88
  throw new SignatureError(`invalid subject: ${p.sub}, want: ${request.url}`);
83
89
  }
@@ -86,7 +92,14 @@ var Receiver = class {
86
92
  if (p.body.replace(padding, "") !== bodyHash.replace(padding, "")) {
87
93
  throw new SignatureError(`body hash does not match, want: ${p.body}, got: ${bodyHash}`);
88
94
  }
89
- return true;
95
+ }
96
+ };
97
+
98
+ // src/client/api/utils.ts
99
+ var appendAPIOptions = (request, headers) => {
100
+ if (request.api?.name === "email") {
101
+ headers.set("Authorization", request.api.provider.token);
102
+ request.method = request.method ?? "POST";
90
103
  }
91
104
  };
92
105
 
@@ -523,7 +536,7 @@ var Chat = class _Chat {
523
536
 
524
537
  // src/client/llm/utils.ts
525
538
  function appendLLMOptionsIfNeeded(request, headers, http) {
526
- if (!request.api)
539
+ if (request.api?.name === "email" || !request.api)
527
540
  return;
528
541
  const provider = request.api.provider;
529
542
  const analytics = request.api.analytics;
@@ -680,7 +693,15 @@ function processHeaders(request) {
680
693
  return headers;
681
694
  }
682
695
  function getRequestPath(request) {
683
- return request.url ?? request.urlGroup ?? request.topic ?? `api/${request.api?.name}`;
696
+ const nonApiPath = request.url ?? request.urlGroup ?? request.topic;
697
+ if (nonApiPath)
698
+ return nonApiPath;
699
+ if (request.api?.name === "llm")
700
+ return `api/${request.api.name}`;
701
+ if (request.api?.name === "email") {
702
+ return request.api.provider.baseUrl;
703
+ }
704
+ throw new QstashError(`Failed to infer request path for ${JSON.stringify(request)}`);
684
705
  }
685
706
  var NANOID_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
686
707
  var NANOID_LENGTH = 21;
@@ -693,10 +714,18 @@ function decodeBase64(base64) {
693
714
  const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0));
694
715
  return new TextDecoder().decode(intArray);
695
716
  } catch (error) {
696
- console.warn(
697
- `Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
698
- );
699
- return atob(base64);
717
+ try {
718
+ const result = atob(base64);
719
+ console.warn(
720
+ `Upstash QStash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
721
+ );
722
+ return result;
723
+ } catch (error2) {
724
+ console.warn(
725
+ `Upstash QStash: Failed to decode base64 "${base64}" with atob. Returning it as it is. ${error2}`
726
+ );
727
+ return base64;
728
+ }
700
729
  }
701
730
  }
702
731
 
@@ -789,6 +818,7 @@ var Queue = class {
789
818
  headers.set("Content-Type", "application/json");
790
819
  ensureCallbackPresent(request);
791
820
  appendLLMOptionsIfNeeded(request, headers, this.http);
821
+ appendAPIOptions(request, headers);
792
822
  const response = await this.enqueue({
793
823
  ...request,
794
824
  body: JSON.stringify(request.body),
@@ -871,6 +901,9 @@ var Schedules = class {
871
901
  if (request.scheduleId !== void 0) {
872
902
  headers.set("Upstash-Schedule-Id", request.scheduleId);
873
903
  }
904
+ if (request.queueName !== void 0) {
905
+ headers.set("Upstash-Queue-Name", request.queueName);
906
+ }
874
907
  return await this.http.request({
875
908
  method: "POST",
876
909
  headers,
@@ -2474,6 +2507,7 @@ var Client = class {
2474
2507
  headers.set("Content-Type", "application/json");
2475
2508
  ensureCallbackPresent(request);
2476
2509
  appendLLMOptionsIfNeeded(request, headers, this.http);
2510
+ appendAPIOptions(request, headers);
2477
2511
  const response = await this.publish({
2478
2512
  ...request,
2479
2513
  headers,
@@ -2518,6 +2552,7 @@ var Client = class {
2518
2552
  message.headers = new Headers(message.headers);
2519
2553
  ensureCallbackPresent(message);
2520
2554
  appendLLMOptionsIfNeeded(message, message.headers, this.http);
2555
+ appendAPIOptions(message, message.headers);
2521
2556
  message.headers.set("Content-Type", "application/json");
2522
2557
  }
2523
2558
  const response = await this.batch(request);
package/svelte.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import "./chunk-CIVGPRQN.mjs";
1
+ import "./chunk-AROUU44N.mjs";
2
2
  import {
3
3
  Receiver,
4
4
  serve
5
- } from "./chunk-Q6E5NF42.mjs";
5
+ } from "./chunk-Q2AGFQYM.mjs";
6
6
 
7
7
  // platforms/svelte.ts
8
8
  var verifySignatureSvelte = (handler, config) => {
package/workflow.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- export { af as AsyncStepFunction, a8 as DisabledWorkflowContext, F as FailureFunctionPayload, ai as FinishCondition, ak as LogLevel, ah as ParallelCallState, ad as RawStep, aj as RequiredExceptFields, a2 as RouteFunction, S as Step, ag as StepFunction, ac as StepType, ab as StepTypes, ae as SyncStepFunction, a4 as Workflow, a9 as WorkflowClient, a7 as WorkflowContext, am as WorkflowLogger, al as WorkflowLoggerOptions, aa as WorkflowReceiver, a3 as WorkflowServeOptions, a5 as processOptions, a6 as serve } from './client-DEZq0-qk.mjs';
1
+ 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-kxUsvnWj.mjs';
2
2
  import 'neverthrow';
package/workflow.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { af as AsyncStepFunction, a8 as DisabledWorkflowContext, F as FailureFunctionPayload, ai as FinishCondition, ak as LogLevel, ah as ParallelCallState, ad as RawStep, aj as RequiredExceptFields, a2 as RouteFunction, S as Step, ag as StepFunction, ac as StepType, ab as StepTypes, ae as SyncStepFunction, a4 as Workflow, a9 as WorkflowClient, a7 as WorkflowContext, am as WorkflowLogger, al as WorkflowLoggerOptions, aa as WorkflowReceiver, a3 as WorkflowServeOptions, a5 as processOptions, a6 as serve } from './client-DEZq0-qk.js';
1
+ 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-kxUsvnWj.js';
2
2
  import 'neverthrow';
package/workflow.js CHANGED
@@ -66,11 +66,14 @@ var Receiver = class {
66
66
  * If that fails, the signature is invalid and a `SignatureError` is thrown.
67
67
  */
68
68
  async verify(request) {
69
- const isValid = await this.verifyWithKey(this.currentSigningKey, request);
70
- if (isValid) {
71
- return true;
69
+ let payload;
70
+ try {
71
+ payload = await this.verifyWithKey(this.currentSigningKey, request);
72
+ } catch {
73
+ payload = await this.verifyWithKey(this.nextSigningKey, request);
72
74
  }
73
- return this.verifyWithKey(this.nextSigningKey, request);
75
+ this.verifyBodyAndUrl(payload, request);
76
+ return true;
74
77
  }
75
78
  /**
76
79
  * Verify signature with a specific signing key
@@ -82,7 +85,10 @@ var Receiver = class {
82
85
  }).catch((error) => {
83
86
  throw new SignatureError(error.message);
84
87
  });
85
- const p = jwt.payload;
88
+ return jwt.payload;
89
+ }
90
+ verifyBodyAndUrl(payload, request) {
91
+ const p = payload;
86
92
  if (request.url !== void 0 && p.sub !== request.url) {
87
93
  throw new SignatureError(`invalid subject: ${p.sub}, want: ${request.url}`);
88
94
  }
@@ -91,7 +97,14 @@ var Receiver = class {
91
97
  if (p.body.replace(padding, "") !== bodyHash.replace(padding, "")) {
92
98
  throw new SignatureError(`body hash does not match, want: ${p.body}, got: ${bodyHash}`);
93
99
  }
94
- return true;
100
+ }
101
+ };
102
+
103
+ // src/client/api/utils.ts
104
+ var appendAPIOptions = (request, headers) => {
105
+ if (request.api?.name === "email") {
106
+ headers.set("Authorization", request.api.provider.token);
107
+ request.method = request.method ?? "POST";
95
108
  }
96
109
  };
97
110
 
@@ -528,7 +541,7 @@ var Chat = class _Chat {
528
541
 
529
542
  // src/client/llm/utils.ts
530
543
  function appendLLMOptionsIfNeeded(request, headers, http) {
531
- if (!request.api)
544
+ if (request.api?.name === "email" || !request.api)
532
545
  return;
533
546
  const provider = request.api.provider;
534
547
  const analytics = request.api.analytics;
@@ -685,7 +698,15 @@ function processHeaders(request) {
685
698
  return headers;
686
699
  }
687
700
  function getRequestPath(request) {
688
- return request.url ?? request.urlGroup ?? request.topic ?? `api/${request.api?.name}`;
701
+ const nonApiPath = request.url ?? request.urlGroup ?? request.topic;
702
+ if (nonApiPath)
703
+ return nonApiPath;
704
+ if (request.api?.name === "llm")
705
+ return `api/${request.api.name}`;
706
+ if (request.api?.name === "email") {
707
+ return request.api.provider.baseUrl;
708
+ }
709
+ throw new QstashError(`Failed to infer request path for ${JSON.stringify(request)}`);
689
710
  }
690
711
  var NANOID_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
691
712
  var NANOID_LENGTH = 21;
@@ -698,10 +719,18 @@ function decodeBase64(base64) {
698
719
  const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0));
699
720
  return new TextDecoder().decode(intArray);
700
721
  } catch (error) {
701
- console.warn(
702
- `Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
703
- );
704
- return atob(base64);
722
+ try {
723
+ const result = atob(base64);
724
+ console.warn(
725
+ `Upstash QStash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
726
+ );
727
+ return result;
728
+ } catch (error2) {
729
+ console.warn(
730
+ `Upstash QStash: Failed to decode base64 "${base64}" with atob. Returning it as it is. ${error2}`
731
+ );
732
+ return base64;
733
+ }
705
734
  }
706
735
  }
707
736
 
@@ -794,6 +823,7 @@ var Queue = class {
794
823
  headers.set("Content-Type", "application/json");
795
824
  ensureCallbackPresent(request);
796
825
  appendLLMOptionsIfNeeded(request, headers, this.http);
826
+ appendAPIOptions(request, headers);
797
827
  const response = await this.enqueue({
798
828
  ...request,
799
829
  body: JSON.stringify(request.body),
@@ -876,6 +906,9 @@ var Schedules = class {
876
906
  if (request.scheduleId !== void 0) {
877
907
  headers.set("Upstash-Schedule-Id", request.scheduleId);
878
908
  }
909
+ if (request.queueName !== void 0) {
910
+ headers.set("Upstash-Queue-Name", request.queueName);
911
+ }
879
912
  return await this.http.request({
880
913
  method: "POST",
881
914
  headers,
@@ -1093,6 +1126,7 @@ var Client = class {
1093
1126
  headers.set("Content-Type", "application/json");
1094
1127
  ensureCallbackPresent(request);
1095
1128
  appendLLMOptionsIfNeeded(request, headers, this.http);
1129
+ appendAPIOptions(request, headers);
1096
1130
  const response = await this.publish({
1097
1131
  ...request,
1098
1132
  headers,
@@ -1137,6 +1171,7 @@ var Client = class {
1137
1171
  message.headers = new Headers(message.headers);
1138
1172
  ensureCallbackPresent(message);
1139
1173
  appendLLMOptionsIfNeeded(message, message.headers, this.http);
1174
+ appendAPIOptions(message, message.headers);
1140
1175
  message.headers.set("Content-Type", "application/json");
1141
1176
  }
1142
1177
  const response = await this.batch(request);
package/workflow.mjs CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  WorkflowLogger,
7
7
  processOptions,
8
8
  serve
9
- } from "./chunk-Q6E5NF42.mjs";
9
+ } from "./chunk-Q2AGFQYM.mjs";
10
10
  export {
11
11
  DisabledWorkflowContext,
12
12
  StepTypes,
File without changes