@upstash/qstash 2.7.21 → 2.7.23
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 +19 -0
- package/{chunk-QHCEWG63.mjs → chunk-G7CVCBTL.mjs} +121 -18
- package/{chunk-FGKPOZOO.mjs → chunk-JZACTABH.mjs} +1 -1
- package/{chunk-3D34OUXY.mjs → chunk-ODRYYMMA.mjs} +1 -1
- package/{client-DuOcoFUv.d.ts → client-CYwLcEcQ.d.mts} +126 -11
- package/{client-DuOcoFUv.d.mts → client-CYwLcEcQ.d.ts} +126 -11
- package/cloudflare.d.mts +1 -1
- package/cloudflare.d.ts +1 -1
- package/cloudflare.js +121 -18
- package/cloudflare.mjs +1 -1
- package/h3.d.mts +1 -1
- package/h3.d.ts +1 -1
- package/h3.js +121 -18
- package/h3.mjs +3 -3
- package/hono.d.mts +1 -1
- package/hono.d.ts +1 -1
- package/hono.js +121 -18
- package/hono.mjs +1 -1
- package/index.d.mts +2 -2
- package/index.d.ts +2 -2
- package/index.js +121 -18
- package/index.mjs +2 -2
- package/nextjs.d.mts +1 -1
- package/nextjs.d.ts +1 -1
- package/nextjs.js +121 -18
- package/nextjs.mjs +1 -1
- package/nuxt.mjs +3 -3
- package/package.json +1 -1
- package/solidjs.d.mts +1 -1
- package/solidjs.d.ts +1 -1
- package/solidjs.js +121 -18
- package/solidjs.mjs +2 -2
- package/svelte.d.mts +1 -1
- package/svelte.d.ts +1 -1
- package/svelte.js +121 -18
- package/svelte.mjs +2 -2
- package/workflow.d.mts +1 -1
- package/workflow.d.ts +1 -1
- package/workflow.js +121 -18
- package/workflow.mjs +1 -1
|
@@ -64,7 +64,7 @@ declare class Receiver {
|
|
|
64
64
|
|
|
65
65
|
type State = "CREATED" | "ACTIVE" | "DELIVERED" | "ERROR" | "RETRY" | "FAILED";
|
|
66
66
|
type HTTPMethods = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
67
|
-
type
|
|
67
|
+
type Log = {
|
|
68
68
|
time: number;
|
|
69
69
|
state: State;
|
|
70
70
|
messageId: string;
|
|
@@ -77,13 +77,31 @@ type Event = {
|
|
|
77
77
|
header?: Record<string, string>;
|
|
78
78
|
body?: string;
|
|
79
79
|
};
|
|
80
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Deprecated. Use the `Log` type instead.
|
|
82
|
+
*
|
|
83
|
+
* @deprecated
|
|
84
|
+
*/
|
|
85
|
+
type Event = Log;
|
|
86
|
+
type LogPayload = Omit<Log, "urlGroup"> & {
|
|
81
87
|
topicName: string;
|
|
82
88
|
};
|
|
83
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Deprecated. Use the `EventPayload` type instead.
|
|
91
|
+
*
|
|
92
|
+
* @deprecated
|
|
93
|
+
*/
|
|
94
|
+
type EventPayload = LogPayload;
|
|
95
|
+
type GetLogsPayload = {
|
|
84
96
|
cursor?: string;
|
|
85
|
-
events:
|
|
97
|
+
events: LogPayload[];
|
|
86
98
|
};
|
|
99
|
+
/**
|
|
100
|
+
* Deprecated. use the `GetLogsPayload` type instead.
|
|
101
|
+
*
|
|
102
|
+
* @deprecated
|
|
103
|
+
*/
|
|
104
|
+
type GetEventsPayload = GetLogsPayload;
|
|
87
105
|
type WithCursor<T> = T & {
|
|
88
106
|
cursor?: number;
|
|
89
107
|
};
|
|
@@ -105,6 +123,30 @@ type RateLimit = {
|
|
|
105
123
|
remaining: string | null;
|
|
106
124
|
reset: string | null;
|
|
107
125
|
};
|
|
126
|
+
type FlowControl = {
|
|
127
|
+
/**
|
|
128
|
+
* flow control key
|
|
129
|
+
*/
|
|
130
|
+
key: string;
|
|
131
|
+
} & ({
|
|
132
|
+
/**
|
|
133
|
+
* number of requests which can be active with the same flow control key
|
|
134
|
+
*/
|
|
135
|
+
parallelism: number;
|
|
136
|
+
/**
|
|
137
|
+
* number of requests to activate per second with the same flow control key
|
|
138
|
+
*/
|
|
139
|
+
ratePerSecond?: number;
|
|
140
|
+
} | {
|
|
141
|
+
/**
|
|
142
|
+
* number of requests which can be active with the same flow control key
|
|
143
|
+
*/
|
|
144
|
+
parallelism?: number;
|
|
145
|
+
/**
|
|
146
|
+
* number of requests to activate per second with the same flow control key
|
|
147
|
+
*/
|
|
148
|
+
ratePerSecond: number;
|
|
149
|
+
});
|
|
108
150
|
|
|
109
151
|
type ProviderInfo = {
|
|
110
152
|
/**
|
|
@@ -363,6 +405,7 @@ type Requester = {
|
|
|
363
405
|
request: <TResult = unknown>(request: UpstashRequest) => Promise<UpstashResponse<TResult>>;
|
|
364
406
|
requestStream: (request: UpstashRequest) => AsyncIterable<ChatCompletionChunk>;
|
|
365
407
|
headers?: Headers;
|
|
408
|
+
telemetryHeaders?: Headers;
|
|
366
409
|
};
|
|
367
410
|
type RetryConfig = false | {
|
|
368
411
|
/**
|
|
@@ -457,6 +500,18 @@ type Message = {
|
|
|
457
500
|
* IP address of the publisher of this message
|
|
458
501
|
*/
|
|
459
502
|
callerIp?: string;
|
|
503
|
+
/**
|
|
504
|
+
* flow control key
|
|
505
|
+
*/
|
|
506
|
+
flowControlKey: string;
|
|
507
|
+
/**
|
|
508
|
+
* number of requests which can be active with the same flow control key
|
|
509
|
+
*/
|
|
510
|
+
parallelism?: number;
|
|
511
|
+
/**
|
|
512
|
+
* number of requests to activate per second with the same flow control key
|
|
513
|
+
*/
|
|
514
|
+
ratePerSecond?: number;
|
|
460
515
|
};
|
|
461
516
|
type MessagePayload = Omit<Message, "urlGroup"> & {
|
|
462
517
|
topicName: string;
|
|
@@ -693,6 +748,9 @@ type Schedule = {
|
|
|
693
748
|
callerIp?: string;
|
|
694
749
|
isPaused: boolean;
|
|
695
750
|
queueName?: string;
|
|
751
|
+
flowControlKey?: string;
|
|
752
|
+
parallelism?: number;
|
|
753
|
+
ratePerSecond?: number;
|
|
696
754
|
};
|
|
697
755
|
type CreateScheduleRequest = {
|
|
698
756
|
/**
|
|
@@ -781,6 +839,11 @@ type CreateScheduleRequest = {
|
|
|
781
839
|
* Queue name to schedule the message over.
|
|
782
840
|
*/
|
|
783
841
|
queueName?: string;
|
|
842
|
+
/**
|
|
843
|
+
* Settings for controlling the number of active requests
|
|
844
|
+
* and number of requests per second with the same key.
|
|
845
|
+
*/
|
|
846
|
+
flowControl?: FlowControl;
|
|
784
847
|
};
|
|
785
848
|
declare class Schedules {
|
|
786
849
|
private readonly http;
|
|
@@ -1587,6 +1650,13 @@ type ClientConfig = {
|
|
|
1587
1650
|
* These can be overridden by the headers in the request.
|
|
1588
1651
|
*/
|
|
1589
1652
|
headers?: HeadersInit;
|
|
1653
|
+
/**
|
|
1654
|
+
* Enable telemetry to help us improve the SDK.
|
|
1655
|
+
* The sdk will send the sdk version, platform and node version as telemetry headers.
|
|
1656
|
+
*
|
|
1657
|
+
* @default true
|
|
1658
|
+
*/
|
|
1659
|
+
enableTelemetry?: boolean;
|
|
1590
1660
|
};
|
|
1591
1661
|
type PublishBatchRequest<TBody = BodyInit> = PublishRequest<TBody> & {
|
|
1592
1662
|
queueName?: string;
|
|
@@ -1689,6 +1759,11 @@ type PublishRequest<TBody = BodyInit> = {
|
|
|
1689
1759
|
* @default undefined
|
|
1690
1760
|
*/
|
|
1691
1761
|
timeout?: Duration | number;
|
|
1762
|
+
/**
|
|
1763
|
+
* Settings for controlling the number of active requests
|
|
1764
|
+
* and number of requests per second with the same key.
|
|
1765
|
+
*/
|
|
1766
|
+
flowControl?: FlowControl;
|
|
1692
1767
|
} & ({
|
|
1693
1768
|
/**
|
|
1694
1769
|
* The url where the message should be sent to.
|
|
@@ -1772,11 +1847,17 @@ type PublishJsonRequest = Omit<PublishRequest, "body"> & {
|
|
|
1772
1847
|
*/
|
|
1773
1848
|
body: unknown;
|
|
1774
1849
|
};
|
|
1775
|
-
type
|
|
1850
|
+
type LogsRequest = {
|
|
1776
1851
|
cursor?: string | number;
|
|
1777
|
-
filter?:
|
|
1852
|
+
filter?: LogsRequestFilter;
|
|
1778
1853
|
};
|
|
1779
|
-
|
|
1854
|
+
/**
|
|
1855
|
+
* Deprecated. Use `LogsRequest` instead.
|
|
1856
|
+
*
|
|
1857
|
+
* @deprecated
|
|
1858
|
+
*/
|
|
1859
|
+
type EventsRequest = LogsRequest;
|
|
1860
|
+
type LogsRequestFilter = {
|
|
1780
1861
|
messageId?: string;
|
|
1781
1862
|
state?: State;
|
|
1782
1863
|
url?: string;
|
|
@@ -1789,10 +1870,22 @@ type EventsRequestFilter = {
|
|
|
1789
1870
|
toDate?: number;
|
|
1790
1871
|
count?: number;
|
|
1791
1872
|
};
|
|
1792
|
-
type
|
|
1873
|
+
type GetLogsResponse = {
|
|
1793
1874
|
cursor?: string;
|
|
1794
|
-
|
|
1875
|
+
logs: Log[];
|
|
1876
|
+
/**
|
|
1877
|
+
* Deprecated. Use the `logs` field instead.
|
|
1878
|
+
*
|
|
1879
|
+
* @deprecated
|
|
1880
|
+
*/
|
|
1881
|
+
events: Log[];
|
|
1795
1882
|
};
|
|
1883
|
+
/**
|
|
1884
|
+
* Deprecated. Use `GetLogsResponse` instead.
|
|
1885
|
+
*
|
|
1886
|
+
* @deprecated
|
|
1887
|
+
*/
|
|
1888
|
+
type GetEventsResponse = GetLogsResponse;
|
|
1796
1889
|
type QueueRequest = {
|
|
1797
1890
|
queueName?: string;
|
|
1798
1891
|
};
|
|
@@ -1887,7 +1980,29 @@ declare class Client {
|
|
|
1887
1980
|
* }
|
|
1888
1981
|
* ```
|
|
1889
1982
|
*/
|
|
1890
|
-
|
|
1983
|
+
logs(request?: LogsRequest): Promise<GetLogsResponse>;
|
|
1984
|
+
/**
|
|
1985
|
+
* @deprecated Will be removed in the next major release. Use the `logs` method instead.
|
|
1986
|
+
*
|
|
1987
|
+
* Retrieve your logs.
|
|
1988
|
+
*
|
|
1989
|
+
* The logs endpoint is paginated and returns only 100 logs at a time.
|
|
1990
|
+
* If you want to receive more logs, you can use the cursor to paginate.
|
|
1991
|
+
*
|
|
1992
|
+
* The cursor is a unix timestamp with millisecond precision
|
|
1993
|
+
*
|
|
1994
|
+
* @example
|
|
1995
|
+
* ```ts
|
|
1996
|
+
* let cursor = Date.now()
|
|
1997
|
+
* const logs: Log[] = []
|
|
1998
|
+
* while (cursor > 0) {
|
|
1999
|
+
* const res = await qstash.logs({ cursor })
|
|
2000
|
+
* logs.push(...res.logs)
|
|
2001
|
+
* cursor = res.cursor ?? 0
|
|
2002
|
+
* }
|
|
2003
|
+
* ```
|
|
2004
|
+
*/
|
|
2005
|
+
events(request?: LogsRequest): Promise<GetLogsResponse>;
|
|
1891
2006
|
}
|
|
1892
2007
|
type PublishToApiResponse = {
|
|
1893
2008
|
messageId: string;
|
|
@@ -1903,4 +2018,4 @@ type PublishResponse<TRequest> = TRequest extends {
|
|
|
1903
2018
|
urlGroup: string;
|
|
1904
2019
|
} ? PublishToUrlGroupsResponse : PublishToApiResponse;
|
|
1905
2020
|
|
|
1906
|
-
export {
|
|
2021
|
+
export { type StreamEnabled as $, type AddEndpointsRequest as A, BaseProvider as B, type ChatRateLimit as C, type EventPayload as D, type EmailOwner as E, type FailureFunctionPayload as F, type GetLogsResponse as G, type HTTPMethods as H, type GetLogsPayload as I, type GetEventsPayload as J, type BodyInit as K, type LLMOwner as L, type Message as M, type HeadersInit as N, type RequestOptions as O, type ProviderInfo as P, type QueueRequest as Q, type RateLimit as R, type Step as S, type FlowControl as T, type UrlGroup as U, type VerifyRequest as V, type WithCursor as W, Chat as X, type ChatCompletionMessage as Y, type ChatCompletion as Z, type ChatCompletionChunk as _, type ReceiverConfig as a, type StreamDisabled as a0, type StreamParameter as a1, type OpenAIChatModel as a2, type PromptChatRequest as a3, type ChatRequest as a4, upstash as a5, openai as a6, anthropic as a7, custom as a8, type RouteFunction as a9, type WorkflowServeOptions as aa, Workflow as ab, processOptions as ac, serve as ad, WorkflowContext as ae, DisabledWorkflowContext as af, type WorkflowClient as ag, type WorkflowReceiver as ah, StepTypes as ai, type StepType as aj, type RawStep as ak, type SyncStepFunction as al, type AsyncStepFunction as am, type StepFunction as an, type ParallelCallState as ao, type FinishCondition as ap, type RequiredExceptFields as aq, type LogLevel as ar, type WorkflowLoggerOptions as as, WorkflowLogger as at, SignatureError as b, Receiver as c, type PublishBatchRequest as d, type PublishRequest as e, type PublishJsonRequest as f, type LogsRequest as g, type EventsRequest as h, type GetEventsResponse as i, Client as j, type PublishToApiResponse as k, type PublishToUrlResponse as l, type PublishToUrlGroupsResponse as m, type PublishResponse as n, type MessagePayload as o, Messages as p, type Schedule as q, type CreateScheduleRequest as r, Schedules as s, type Endpoint as t, type RemoveEndpointsRequest as u, UrlGroups as v, type State as w, type Log as x, type Event as y, type LogPayload as z };
|
package/cloudflare.d.mts
CHANGED
package/cloudflare.d.ts
CHANGED
package/cloudflare.js
CHANGED
|
@@ -121,7 +121,8 @@ var DLQ = class {
|
|
|
121
121
|
messages: messagesPayload.messages.map((message) => {
|
|
122
122
|
return {
|
|
123
123
|
...message,
|
|
124
|
-
urlGroup: message.topicName
|
|
124
|
+
urlGroup: message.topicName,
|
|
125
|
+
ratePerSecond: "rate" in message ? message.rate : void 0
|
|
125
126
|
};
|
|
126
127
|
}),
|
|
127
128
|
cursor: messagesPayload.cursor
|
|
@@ -238,6 +239,7 @@ var HttpClient = class {
|
|
|
238
239
|
options;
|
|
239
240
|
retry;
|
|
240
241
|
headers;
|
|
242
|
+
telemetryHeaders;
|
|
241
243
|
constructor(config) {
|
|
242
244
|
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
243
245
|
this.authorization = config.authorization;
|
|
@@ -250,6 +252,7 @@ var HttpClient = class {
|
|
|
250
252
|
backoff: config.retry?.backoff ?? ((retryCount) => Math.exp(retryCount) * 50)
|
|
251
253
|
};
|
|
252
254
|
this.headers = config.headers;
|
|
255
|
+
this.telemetryHeaders = config.telemetryHeaders;
|
|
253
256
|
}
|
|
254
257
|
async request(request) {
|
|
255
258
|
const { response } = await this.requestWithBackoff(request);
|
|
@@ -551,7 +554,8 @@ var Messages = class {
|
|
|
551
554
|
});
|
|
552
555
|
const message = {
|
|
553
556
|
...messagePayload,
|
|
554
|
-
urlGroup: messagePayload.topicName
|
|
557
|
+
urlGroup: messagePayload.topicName,
|
|
558
|
+
ratePerSecond: "rate" in messagePayload ? messagePayload.rate : void 0
|
|
555
559
|
};
|
|
556
560
|
return message;
|
|
557
561
|
}
|
|
@@ -747,7 +751,7 @@ function prefixHeaders(headers) {
|
|
|
747
751
|
}
|
|
748
752
|
return headers;
|
|
749
753
|
}
|
|
750
|
-
function wrapWithGlobalHeaders(headers, globalHeaders) {
|
|
754
|
+
function wrapWithGlobalHeaders(headers, globalHeaders, telemetryHeaders) {
|
|
751
755
|
if (!globalHeaders) {
|
|
752
756
|
return headers;
|
|
753
757
|
}
|
|
@@ -755,6 +759,11 @@ function wrapWithGlobalHeaders(headers, globalHeaders) {
|
|
|
755
759
|
headers.forEach((value, key) => {
|
|
756
760
|
finalHeaders.set(key, value);
|
|
757
761
|
});
|
|
762
|
+
telemetryHeaders?.forEach((value, key) => {
|
|
763
|
+
if (!value)
|
|
764
|
+
return;
|
|
765
|
+
finalHeaders.append(key, value);
|
|
766
|
+
});
|
|
758
767
|
return finalHeaders;
|
|
759
768
|
}
|
|
760
769
|
function processHeaders(request) {
|
|
@@ -792,6 +801,19 @@ function processHeaders(request) {
|
|
|
792
801
|
headers.set("Upstash-Timeout", `${request.timeout}s`);
|
|
793
802
|
}
|
|
794
803
|
}
|
|
804
|
+
if (request.flowControl?.key) {
|
|
805
|
+
const parallelism = request.flowControl.parallelism?.toString();
|
|
806
|
+
const rate = request.flowControl.ratePerSecond?.toString();
|
|
807
|
+
const controlValue = [
|
|
808
|
+
parallelism ? `parallelism=${parallelism}` : void 0,
|
|
809
|
+
rate ? `rate=${rate}` : void 0
|
|
810
|
+
].filter(Boolean);
|
|
811
|
+
if (controlValue.length === 0) {
|
|
812
|
+
throw new QstashError("Provide at least one of parallelism or ratePerSecond for flowControl");
|
|
813
|
+
}
|
|
814
|
+
headers.set("Upstash-Flow-Control-Key", request.flowControl.key);
|
|
815
|
+
headers.set("Upstash-Flow-Control-Value", controlValue.join(", "));
|
|
816
|
+
}
|
|
795
817
|
return headers;
|
|
796
818
|
}
|
|
797
819
|
function getRequestPath(request) {
|
|
@@ -831,6 +853,15 @@ function decodeBase64(base64) {
|
|
|
831
853
|
}
|
|
832
854
|
}
|
|
833
855
|
}
|
|
856
|
+
function getRuntime() {
|
|
857
|
+
if (typeof process === "object" && typeof process.versions == "object" && process.versions.bun)
|
|
858
|
+
return `bun@${process.versions.bun}`;
|
|
859
|
+
if (typeof EdgeRuntime === "string")
|
|
860
|
+
return "edge-light";
|
|
861
|
+
else if (typeof process === "object" && typeof process.version === "string")
|
|
862
|
+
return `node@${process.version}`;
|
|
863
|
+
return "";
|
|
864
|
+
}
|
|
834
865
|
|
|
835
866
|
// src/client/queue.ts
|
|
836
867
|
var Queue = class {
|
|
@@ -905,7 +936,8 @@ var Queue = class {
|
|
|
905
936
|
}
|
|
906
937
|
const headers = wrapWithGlobalHeaders(
|
|
907
938
|
processHeaders(request),
|
|
908
|
-
this.http.headers
|
|
939
|
+
this.http.headers,
|
|
940
|
+
this.http.telemetryHeaders
|
|
909
941
|
);
|
|
910
942
|
const destination = getRequestPath(request);
|
|
911
943
|
const response = await this.http.request({
|
|
@@ -1008,9 +1040,24 @@ var Schedules = class {
|
|
|
1008
1040
|
if (request.queueName !== void 0) {
|
|
1009
1041
|
headers.set("Upstash-Queue-Name", request.queueName);
|
|
1010
1042
|
}
|
|
1043
|
+
if (request.flowControl?.key) {
|
|
1044
|
+
const parallelism = request.flowControl.parallelism?.toString();
|
|
1045
|
+
const rate = request.flowControl.ratePerSecond?.toString();
|
|
1046
|
+
const controlValue = [
|
|
1047
|
+
parallelism ? `parallelism=${parallelism}` : void 0,
|
|
1048
|
+
rate ? `rate=${rate}` : void 0
|
|
1049
|
+
].filter(Boolean);
|
|
1050
|
+
if (controlValue.length === 0) {
|
|
1051
|
+
throw new QstashError(
|
|
1052
|
+
"Provide at least one of parallelism or ratePerSecond for flowControl"
|
|
1053
|
+
);
|
|
1054
|
+
}
|
|
1055
|
+
headers.set("Upstash-Flow-Control-Key", request.flowControl.key);
|
|
1056
|
+
headers.set("Upstash-Flow-Control-Value", controlValue.join(", "));
|
|
1057
|
+
}
|
|
1011
1058
|
return await this.http.request({
|
|
1012
1059
|
method: "POST",
|
|
1013
|
-
headers: wrapWithGlobalHeaders(headers, this.http.headers),
|
|
1060
|
+
headers: wrapWithGlobalHeaders(headers, this.http.headers, this.http.telemetryHeaders),
|
|
1014
1061
|
path: ["v2", "schedules", request.destination],
|
|
1015
1062
|
body: request.body
|
|
1016
1063
|
});
|
|
@@ -1019,19 +1066,27 @@ var Schedules = class {
|
|
|
1019
1066
|
* Get a schedule
|
|
1020
1067
|
*/
|
|
1021
1068
|
async get(scheduleId) {
|
|
1022
|
-
|
|
1069
|
+
const schedule = await this.http.request({
|
|
1023
1070
|
method: "GET",
|
|
1024
1071
|
path: ["v2", "schedules", scheduleId]
|
|
1025
1072
|
});
|
|
1073
|
+
if ("rate" in schedule)
|
|
1074
|
+
schedule.ratePerSecond = schedule.rate;
|
|
1075
|
+
return schedule;
|
|
1026
1076
|
}
|
|
1027
1077
|
/**
|
|
1028
1078
|
* List your schedules
|
|
1029
1079
|
*/
|
|
1030
1080
|
async list() {
|
|
1031
|
-
|
|
1081
|
+
const schedules = await this.http.request({
|
|
1032
1082
|
method: "GET",
|
|
1033
1083
|
path: ["v2", "schedules"]
|
|
1034
1084
|
});
|
|
1085
|
+
for (const schedule of schedules) {
|
|
1086
|
+
if ("rate" in schedule)
|
|
1087
|
+
schedule.ratePerSecond = schedule.rate;
|
|
1088
|
+
}
|
|
1089
|
+
return schedules;
|
|
1035
1090
|
}
|
|
1036
1091
|
/**
|
|
1037
1092
|
* Delete a schedule
|
|
@@ -1128,20 +1183,37 @@ var UrlGroups = class {
|
|
|
1128
1183
|
}
|
|
1129
1184
|
};
|
|
1130
1185
|
|
|
1186
|
+
// version.ts
|
|
1187
|
+
var VERSION = "v2.7.23";
|
|
1188
|
+
|
|
1131
1189
|
// src/client/client.ts
|
|
1132
1190
|
var Client = class {
|
|
1133
1191
|
http;
|
|
1134
1192
|
token;
|
|
1135
1193
|
constructor(config) {
|
|
1136
1194
|
const environment = typeof process === "undefined" ? {} : process.env;
|
|
1137
|
-
|
|
1195
|
+
let baseUrl = (config?.baseUrl ?? environment.QSTASH_URL ?? "https://qstash.upstash.io").replace(/\/$/, "");
|
|
1196
|
+
if (baseUrl === "https://qstash.upstash.io/v2/publish") {
|
|
1197
|
+
baseUrl = "https://qstash.upstash.io";
|
|
1198
|
+
}
|
|
1138
1199
|
const token = config?.token ?? environment.QSTASH_TOKEN;
|
|
1200
|
+
const enableTelemetry = environment.UPSTASH_DISABLE_TELEMETRY ? false : config?.enableTelemetry ?? true;
|
|
1201
|
+
const isCloudflare = typeof caches !== "undefined" && "default" in caches;
|
|
1202
|
+
const telemetryHeaders = new Headers(
|
|
1203
|
+
enableTelemetry ? {
|
|
1204
|
+
"Upstash-Telemetry-Sdk": `upstash-qstash-js@${VERSION}`,
|
|
1205
|
+
"Upstash-Telemetry-Platform": isCloudflare ? "cloudflare" : environment.VERCEL ? "vercel" : environment.AWS_REGION ? "aws" : "",
|
|
1206
|
+
"Upstash-Telemetry-Runtime": getRuntime()
|
|
1207
|
+
} : {}
|
|
1208
|
+
);
|
|
1139
1209
|
this.http = new HttpClient({
|
|
1140
1210
|
retry: config?.retry,
|
|
1141
1211
|
baseUrl,
|
|
1142
1212
|
authorization: `Bearer ${token}`,
|
|
1143
1213
|
//@ts-expect-error caused by undici and bunjs type overlap
|
|
1144
|
-
headers: prefixHeaders(new Headers(config?.headers ?? {}))
|
|
1214
|
+
headers: prefixHeaders(new Headers(config?.headers ?? {})),
|
|
1215
|
+
//@ts-expect-error caused by undici and bunjs type overlap
|
|
1216
|
+
telemetryHeaders
|
|
1145
1217
|
});
|
|
1146
1218
|
if (!token) {
|
|
1147
1219
|
console.warn(
|
|
@@ -1223,7 +1295,8 @@ var Client = class {
|
|
|
1223
1295
|
async publish(request) {
|
|
1224
1296
|
const headers = wrapWithGlobalHeaders(
|
|
1225
1297
|
processHeaders(request),
|
|
1226
|
-
this.http.headers
|
|
1298
|
+
this.http.headers,
|
|
1299
|
+
this.http.telemetryHeaders
|
|
1227
1300
|
);
|
|
1228
1301
|
const response = await this.http.request({
|
|
1229
1302
|
path: ["v2", "publish", getRequestPath(request)],
|
|
@@ -1254,7 +1327,11 @@ var Client = class {
|
|
|
1254
1327
|
async batch(request) {
|
|
1255
1328
|
const messages = [];
|
|
1256
1329
|
for (const message of request) {
|
|
1257
|
-
const headers = wrapWithGlobalHeaders(
|
|
1330
|
+
const headers = wrapWithGlobalHeaders(
|
|
1331
|
+
processHeaders(message),
|
|
1332
|
+
this.http.headers,
|
|
1333
|
+
this.http.telemetryHeaders
|
|
1334
|
+
);
|
|
1258
1335
|
const headerEntries = Object.fromEntries(headers.entries());
|
|
1259
1336
|
messages.push({
|
|
1260
1337
|
destination: getRequestPath(message),
|
|
@@ -1309,7 +1386,7 @@ var Client = class {
|
|
|
1309
1386
|
* }
|
|
1310
1387
|
* ```
|
|
1311
1388
|
*/
|
|
1312
|
-
async
|
|
1389
|
+
async logs(request) {
|
|
1313
1390
|
const query = {};
|
|
1314
1391
|
if (typeof request?.cursor === "number" && request.cursor > 0) {
|
|
1315
1392
|
query.cursor = request.cursor.toString();
|
|
@@ -1331,16 +1408,42 @@ var Client = class {
|
|
|
1331
1408
|
method: "GET",
|
|
1332
1409
|
query
|
|
1333
1410
|
});
|
|
1411
|
+
const logs = responsePayload.events.map((event) => {
|
|
1412
|
+
return {
|
|
1413
|
+
...event,
|
|
1414
|
+
urlGroup: event.topicName
|
|
1415
|
+
};
|
|
1416
|
+
});
|
|
1334
1417
|
return {
|
|
1335
1418
|
cursor: responsePayload.cursor,
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
...event,
|
|
1339
|
-
urlGroup: event.topicName
|
|
1340
|
-
};
|
|
1341
|
-
})
|
|
1419
|
+
logs,
|
|
1420
|
+
events: logs
|
|
1342
1421
|
};
|
|
1343
1422
|
}
|
|
1423
|
+
/**
|
|
1424
|
+
* @deprecated Will be removed in the next major release. Use the `logs` method instead.
|
|
1425
|
+
*
|
|
1426
|
+
* Retrieve your logs.
|
|
1427
|
+
*
|
|
1428
|
+
* The logs endpoint is paginated and returns only 100 logs at a time.
|
|
1429
|
+
* If you want to receive more logs, you can use the cursor to paginate.
|
|
1430
|
+
*
|
|
1431
|
+
* The cursor is a unix timestamp with millisecond precision
|
|
1432
|
+
*
|
|
1433
|
+
* @example
|
|
1434
|
+
* ```ts
|
|
1435
|
+
* let cursor = Date.now()
|
|
1436
|
+
* const logs: Log[] = []
|
|
1437
|
+
* while (cursor > 0) {
|
|
1438
|
+
* const res = await qstash.logs({ cursor })
|
|
1439
|
+
* logs.push(...res.logs)
|
|
1440
|
+
* cursor = res.cursor ?? 0
|
|
1441
|
+
* }
|
|
1442
|
+
* ```
|
|
1443
|
+
*/
|
|
1444
|
+
async events(request) {
|
|
1445
|
+
return await this.logs(request);
|
|
1446
|
+
}
|
|
1344
1447
|
};
|
|
1345
1448
|
|
|
1346
1449
|
// src/client/workflow/constants.ts
|
package/cloudflare.mjs
CHANGED
package/h3.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as h3 from 'h3';
|
|
2
2
|
import { H3Event } from 'h3';
|
|
3
|
-
import {
|
|
3
|
+
import { a9 as RouteFunction, aa as WorkflowServeOptions } from './client-CYwLcEcQ.mjs';
|
|
4
4
|
import 'neverthrow';
|
|
5
5
|
|
|
6
6
|
type VerifySignatureConfig = {
|
package/h3.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as h3 from 'h3';
|
|
2
2
|
import { H3Event } from 'h3';
|
|
3
|
-
import {
|
|
3
|
+
import { a9 as RouteFunction, aa as WorkflowServeOptions } from './client-CYwLcEcQ.js';
|
|
4
4
|
import 'neverthrow';
|
|
5
5
|
|
|
6
6
|
type VerifySignatureConfig = {
|