@upstash/qstash 0.0.3 → 0.0.7

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.
Files changed (44) hide show
  1. package/README.md +119 -1
  2. package/esm/_dnt.shims.js +65 -0
  3. package/esm/consumer.js +82 -0
  4. package/esm/deps/deno.land/std@0.144.0/encoding/base64.js +115 -0
  5. package/esm/deps/deno.land/std@0.144.0/encoding/base64url.js +42 -0
  6. package/esm/entrypoints/nextjs.js +49 -0
  7. package/package.json +15 -21
  8. package/script/_dnt.shims.js +70 -0
  9. package/script/consumer.js +110 -0
  10. package/script/deps/deno.land/std@0.144.0/encoding/base64.js +120 -0
  11. package/script/deps/deno.land/std@0.144.0/encoding/base64url.js +71 -0
  12. package/script/entrypoints/nextjs.js +53 -0
  13. package/types/_dnt.shims.d.ts +7 -0
  14. package/types/consumer.d.ts +43 -0
  15. package/types/deps/deno.land/std@0.144.0/encoding/base64.d.ts +11 -0
  16. package/types/deps/deno.land/std@0.144.0/encoding/base64url.d.ts +11 -0
  17. package/types/entrypoints/nextjs.d.ts +6 -0
  18. package/esm/client.js +0 -133
  19. package/esm/endpoints.js +0 -63
  20. package/esm/error.js +0 -9
  21. package/esm/http.js +0 -81
  22. package/esm/messages.js +0 -64
  23. package/esm/platforms/nodejs.js +0 -1
  24. package/esm/schedules.js +0 -41
  25. package/esm/topics.js +0 -71
  26. package/esm/types.js +0 -1
  27. package/script/client.js +0 -137
  28. package/script/endpoints.js +0 -67
  29. package/script/error.js +0 -13
  30. package/script/http.js +0 -85
  31. package/script/messages.js +0 -68
  32. package/script/platforms/nodejs.js +0 -5
  33. package/script/schedules.js +0 -45
  34. package/script/topics.js +0 -75
  35. package/script/types.js +0 -2
  36. package/types/client.d.ts +0 -198
  37. package/types/endpoints.d.ts +0 -59
  38. package/types/error.d.ts +0 -6
  39. package/types/http.d.ts +0 -65
  40. package/types/messages.d.ts +0 -66
  41. package/types/platforms/nodejs.d.ts +0 -1
  42. package/types/schedules.d.ts +0 -63
  43. package/types/topics.d.ts +0 -64
  44. package/types/types.d.ts +0 -20
package/script/topics.js DELETED
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Topics = void 0;
4
- class Topics {
5
- constructor(http) {
6
- Object.defineProperty(this, "http", {
7
- enumerable: true,
8
- configurable: true,
9
- writable: true,
10
- value: void 0
11
- });
12
- this.http = http;
13
- }
14
- /**
15
- * Create a new topic with the given name.
16
- */
17
- async create(req) {
18
- return await this.http.request({
19
- method: "POST",
20
- path: ["v1", "topics"],
21
- headers: { "Content-Type": "application/json" },
22
- body: JSON.stringify({ name: req.name }),
23
- });
24
- }
25
- /**
26
- * Get a list of all topics.
27
- */
28
- async list() {
29
- return await this.http.request({
30
- method: "GET",
31
- path: ["v1", "topics"],
32
- headers: { "Content-Type": "application/json" },
33
- });
34
- }
35
- /**
36
- * Get a single topic by name or ID.
37
- */
38
- async get(req) {
39
- const idOrName = req.id ?? req.name;
40
- if (!idOrName) {
41
- throw new Error("Either id or name must be provided");
42
- }
43
- return await this.http.request({
44
- method: "GET",
45
- path: ["v1", "topics", idOrName],
46
- headers: { "Content-Type": "application/json" },
47
- });
48
- }
49
- /**
50
- * Update a topic
51
- */
52
- async update(req) {
53
- return await this.http.request({
54
- method: "PUT",
55
- path: ["v1", "topics", req.id],
56
- body: JSON.stringify({ name: req.name }),
57
- headers: { "Content-Type": "application/json" },
58
- });
59
- }
60
- /**
61
- * Delete a topic by name or ID.
62
- */
63
- async delete(req) {
64
- const idOrName = req.id ?? req.name;
65
- if (!idOrName) {
66
- throw new Error("Either id or name must be provided");
67
- }
68
- return await this.http.request({
69
- method: "DELETE",
70
- path: ["v1", "topics", idOrName],
71
- headers: { "Content-Type": "application/json" },
72
- });
73
- }
74
- }
75
- exports.Topics = Topics;
package/script/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
package/types/client.d.ts DELETED
@@ -1,198 +0,0 @@
1
- import { Requester } from "./http.js";
2
- import { Topics } from "./topics.js";
3
- import { Messages } from "./messages.js";
4
- import { Schedules } from "./schedules.js";
5
- import { Endpoints } from "./endpoints.js";
6
- import type { Log } from "./types.js";
7
- export declare type ClientConfig = {
8
- /**
9
- * Url of the qstash api server
10
- *
11
- * @default "https://qstash.upstash.io"
12
- */
13
- baseUrl?: string;
14
- /**
15
- * The authorization token from the upstash console.
16
- */
17
- authorization: string;
18
- };
19
- declare type Destination = {
20
- /**
21
- * The url of a publicly accessible server where you want to send this message to.
22
- * The url must have a valid scheme (http or https).
23
- */
24
- url: string;
25
- topic?: never;
26
- } | {
27
- url?: never;
28
- /**
29
- * Either the name or id of a topic to send this message to.
30
- */
31
- topic: string;
32
- };
33
- export declare type PublishRequest = Destination & {
34
- /**
35
- * The message to send.
36
- *
37
- * This can be anything, but please set the `Content-Type` header accordingly.
38
- *
39
- * You can leave this empty if you want to send a message with no body.
40
- */
41
- body?: BodyInit;
42
- /**
43
- * Optionally send along headers with the message.
44
- * These headers will be sent to your destination.
45
- *
46
- * We highly recommend sending a `Content-Type` header along, as this will help your destination
47
- * server to understand the content of the message.
48
- */
49
- headers?: HeadersInit;
50
- /**
51
- * Optionally delay the delivery of this message.
52
- *
53
- * In seconds.
54
- *
55
- * @default undefined
56
- */
57
- delay?: number;
58
- /**
59
- * Optionally set the absolute delay of this message.
60
- * This will override the delay option.
61
- * The message will not delivered until the specified time.
62
- *
63
- * Unix timestamp in seconds.
64
- *
65
- * @default undefined
66
- */
67
- notBefore?: number;
68
- /**
69
- * We will no longer try to deliver the message after this time
70
- *
71
- * Unix timestamp with second precicion
72
- *
73
- * @default undefined
74
- */
75
- deadline?: number;
76
- /**
77
- * Provide a unique id for deduplication. This id will be used to detect duplicate messages.
78
- * If a duplicate message is detected, the request will be accepted but not enqueued.
79
- *
80
- * We store deduplication ids for 90 days. Afterwards it is possible that the message with the
81
- * same deduplication id is delivered again.
82
- *
83
- * When scheduling a message, the deduplication happens before the schedule is created.
84
- *
85
- * @default undefined
86
- */
87
- deduplicationID?: string;
88
- /**
89
- * If true, the message content will get hashed and used as deduplication id.
90
- * If a duplicate message is detected, the request will be accepted but not enqueued.
91
- *
92
- * The content based hash includes the following values:
93
- * - All headers, except Upstash-Authorization, this includes all headers you are sending.
94
- * - The entire raw request body The destination from the url path
95
- *
96
- * We store deduplication ids for 90 days. Afterwards it is possible that the message with the
97
- * same deduplication id is delivered again.
98
- *
99
- * When scheduling a message, the deduplication happens before the schedule is created.
100
- *
101
- * @default false
102
- */
103
- contentBasedDeduplication?: boolean;
104
- /**
105
- * In case your destination server is unavaialble or returns a status code outside of the 200-299
106
- * range, we will retry the request after a certain amount of time.
107
- *
108
- * Configure how many times you would like the delivery to be retried
109
- *
110
- * @default The maximum retry quota associated with your account.
111
- */
112
- retries?: number;
113
- } & ({
114
- /**
115
- * Optionally specify a cron expression to repeatedly send this message to the destination.
116
- *
117
- * @default undefined
118
- */
119
- cron: string;
120
- } | {
121
- cron?: never;
122
- });
123
- export declare type PublishJsonRequest = Omit<PublishRequest, "body"> & {
124
- /**
125
- * The message to send.
126
- * This can be anything as long as it can be serialized to JSON.
127
- */
128
- body: unknown;
129
- };
130
- export declare type LogsRequest = {
131
- cursor?: number;
132
- };
133
- export declare type GetLogsRespone = {
134
- cursor?: number;
135
- logs: Log[];
136
- };
137
- export declare class Client {
138
- http: Requester;
139
- constructor(config: ClientConfig);
140
- /**
141
- * Access the topic API.
142
- *
143
- * Create, read, update or delete topics.
144
- */
145
- get topics(): Topics;
146
- /**
147
- * Access the endpoint API.
148
- *
149
- * Create, read, update or delete endpoints.
150
- */
151
- get endpoints(): Endpoints;
152
- /**
153
- * Access the message API.
154
- *
155
- * Read or cancel messages.
156
- */
157
- get messages(): Messages;
158
- /**
159
- * Access the schedule API.
160
- *
161
- * Read or delete schedules.
162
- */
163
- get schedules(): Schedules;
164
- publish<R extends PublishRequest>(req: R): Promise<PublishResponse<R>>;
165
- /**
166
- * publishJSON is a utility wrapper around `publish` that automatically serializes the body
167
- * and sets the `Content-Type` header to `application/json`.
168
- */
169
- publishJSON<R extends PublishJsonRequest = PublishJsonRequest>(req: R): Promise<PublishResponse<R>>;
170
- /**
171
- * Retrieve your logs.
172
- *
173
- * The logs endpoint is paginated and returns only 100 logs at a time.
174
- * If you want to receive more logs, you can use the cursor to paginate.
175
- *
176
- * The cursor is a unix timestamp with millisecond precision
177
- *
178
- * @example
179
- * ```ts
180
- * let cursor = Date.now()
181
- * const logs: Log[] = []
182
- * while (cursor > 0) {
183
- * const res = await qstash.logs({ cursor })
184
- * logs.push(...res.logs)
185
- * cursor = res.cursor ?? 0
186
- * }
187
- * ```
188
- */
189
- logs(req?: LogsRequest): Promise<GetLogsRespone>;
190
- }
191
- declare type PublishResponse<PublishRequest> = PublishRequest extends {
192
- cron: string;
193
- } ? {
194
- scheduleID: string;
195
- } : {
196
- messageID: string;
197
- };
198
- export {};
@@ -1,59 +0,0 @@
1
- import { Requester } from "./http.js";
2
- export declare type CreateEndpointRequest = {
3
- /**
4
- * The url of the endpoint.
5
- */
6
- url: string;
7
- /**
8
- * The name of the topic to subscribe to.
9
- */
10
- topicName: string;
11
- };
12
- export declare type GetEndpointRequest = {
13
- id: string;
14
- };
15
- export declare type UpdateEndpointRequest = {
16
- id: string;
17
- url?: string;
18
- };
19
- export declare type DeleteEndpointRequest = {
20
- id: string;
21
- };
22
- export declare type Endpoint = {
23
- /**
24
- * ID for this endpoint
25
- */
26
- id: string;
27
- /**
28
- * The url of this endpoint.
29
- */
30
- url: string;
31
- /**
32
- * The topic id this endpoint is subscribed to.
33
- */
34
- topicID: string;
35
- };
36
- export declare class Endpoints {
37
- private readonly http;
38
- constructor(http: Requester);
39
- /**
40
- * Create a new endpoint with the given name.
41
- */
42
- create(req: CreateEndpointRequest): Promise<Endpoint>;
43
- /**
44
- * Get a list of all endpoints.
45
- */
46
- list(): Promise<Endpoint[]>;
47
- /**
48
- * Get a single endpoint.
49
- */
50
- get(req: GetEndpointRequest): Promise<Endpoint>;
51
- /**
52
- * Update a endpoint
53
- */
54
- update(req: UpdateEndpointRequest): Promise<Endpoint>;
55
- /**
56
- * Delete a endpoint.
57
- */
58
- delete(req: DeleteEndpointRequest): Promise<void>;
59
- }
package/types/error.d.ts DELETED
@@ -1,6 +0,0 @@
1
- /**
2
- * Result of 500 Internal Server Error
3
- */
4
- export declare class QstashError extends Error {
5
- constructor(message: string);
6
- }
package/types/http.d.ts DELETED
@@ -1,65 +0,0 @@
1
- export declare type UpstashRequest = {
2
- /**
3
- * The path to the resource.
4
- */
5
- path: string[];
6
- /**
7
- * A BodyInit object or null to set request's body.
8
- */
9
- body?: BodyInit | null;
10
- /**
11
- * A Headers object, an object literal, or an array of two-item arrays to set
12
- * request's headers.
13
- */
14
- headers?: HeadersInit;
15
- /**
16
- * A boolean to set request's keepalive.
17
- */
18
- keepalive?: boolean;
19
- /**
20
- * A string to set request's method.
21
- */
22
- method?: "GET" | "POST" | "PUT" | "DELETE";
23
- query?: Record<string, string | number | boolean | undefined>;
24
- };
25
- export declare type UpstashResponse<TResult> = TResult & {
26
- error?: string;
27
- };
28
- export interface Requester {
29
- request: <TResult = unknown>(req: UpstashRequest) => Promise<UpstashResponse<TResult>>;
30
- }
31
- export declare type RetryConfig = false | {
32
- /**
33
- * The number of retries to attempt before giving up.
34
- *
35
- * @default 5
36
- */
37
- retries?: number;
38
- /**
39
- * A backoff function receives the current retry cound and returns a number in milliseconds to wait before retrying.
40
- *
41
- * @default
42
- * ```ts
43
- * Math.exp(retryCount) * 50
44
- * ```
45
- */
46
- backoff?: (retryCount: number) => number;
47
- };
48
- export declare type HttpClientConfig = {
49
- baseUrl: string;
50
- authorization: string;
51
- retry?: RetryConfig;
52
- };
53
- export declare class HttpClient implements Requester {
54
- readonly baseUrl: string;
55
- readonly authorization: string;
56
- readonly options?: {
57
- backend?: string;
58
- };
59
- readonly retry: {
60
- attempts: number;
61
- backoff: (retryCount: number) => number;
62
- };
63
- constructor(config: HttpClientConfig);
64
- request<TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>>;
65
- }
@@ -1,66 +0,0 @@
1
- import { Requester } from "./http.js";
2
- import type { Log, Task } from "./types.js";
3
- export declare type GetMessageRequest = {
4
- id: string;
5
- };
6
- export declare type CancelMessageRequest = {
7
- id: string;
8
- };
9
- export declare type Message = {
10
- messageID: string;
11
- header: Record<string, string[]>;
12
- body: string;
13
- } & ({
14
- url: string;
15
- topicID?: never;
16
- } | {
17
- url?: never;
18
- topicID: string;
19
- });
20
- export declare type ListMessagesRequest = {
21
- cursor?: number;
22
- };
23
- export declare type ListMessagesResponse = {
24
- cursor?: number;
25
- messages: Message[];
26
- };
27
- export declare type ListLogsRequest = {
28
- id: string;
29
- cursor?: number;
30
- };
31
- export declare type ListLogsResponse = {
32
- cursor?: number;
33
- logs: Log[];
34
- };
35
- export declare type ListTasksRequest = {
36
- id: string;
37
- cursor?: number;
38
- };
39
- export declare type ListTasksResponse = {
40
- cursor?: number;
41
- logs: Task[];
42
- };
43
- export declare class Messages {
44
- private readonly http;
45
- constructor(http: Requester);
46
- /**
47
- * Get a message
48
- */
49
- get(req: GetMessageRequest): Promise<Message>;
50
- /**
51
- * List your messages
52
- */
53
- list(req?: ListMessagesRequest): Promise<ListMessagesResponse>;
54
- /**
55
- * List logs from a message
56
- */
57
- logs(req: ListLogsRequest): Promise<ListLogsResponse>;
58
- /**
59
- * List tasks for a message
60
- */
61
- tasks(req: ListTasksRequest): Promise<ListTasksResponse>;
62
- /**
63
- * Cancel a topic by name or ID.
64
- */
65
- delete(req: CancelMessageRequest): Promise<void>;
66
- }
@@ -1 +0,0 @@
1
- export { Client } from "../client.js";
@@ -1,63 +0,0 @@
1
- import { Requester } from "./http.js";
2
- import type { Log, Task } from "./types.js";
3
- export declare type GetScheduleRequest = {
4
- id: string;
5
- };
6
- export declare type DeleteScheduleRequest = {
7
- id: string;
8
- };
9
- export declare type Schedule = {
10
- scheduleID: string;
11
- cron: string;
12
- createdAt: number;
13
- content: {
14
- header: Record<string, string[]>;
15
- body: string;
16
- };
17
- destination: {
18
- type: "topicID";
19
- topicID: string;
20
- url?: never;
21
- } | {
22
- type: "url";
23
- topicID?: never;
24
- url: string;
25
- };
26
- settings: {
27
- deadline?: number;
28
- notBefore?: number;
29
- retries?: number;
30
- };
31
- };
32
- export declare type ListLogsRequest = {
33
- id: string;
34
- cursor?: number;
35
- };
36
- export declare type ListLogsResponse = {
37
- cursor?: number;
38
- logs: Log[];
39
- };
40
- export declare type ListTasksRequest = {
41
- id: string;
42
- cursor?: number;
43
- };
44
- export declare type ListTasksResponse = {
45
- cursor?: number;
46
- logs: Task[];
47
- };
48
- export declare class Schedules {
49
- private readonly http;
50
- constructor(http: Requester);
51
- /**
52
- * Get a schedule
53
- */
54
- get(req: GetScheduleRequest): Promise<Schedule>;
55
- /**
56
- * List your schedules
57
- */
58
- list(): Promise<Schedule[]>;
59
- /**
60
- * Delete a schedule
61
- */
62
- delete(req: DeleteScheduleRequest): Promise<void>;
63
- }
package/types/topics.d.ts DELETED
@@ -1,64 +0,0 @@
1
- import { Requester } from "./http.js";
2
- export declare type CreateTopicRequest = {
3
- /**
4
- * The name of the topic.
5
- * Must be unique and only contain alphanumeric, hyphen, underscore and periods.
6
- */
7
- name: string;
8
- };
9
- export declare type GetTopicRequest = {
10
- name: string;
11
- id?: never;
12
- } | {
13
- id: string;
14
- name?: never;
15
- };
16
- export declare type UpdateTopicRequest = {
17
- id: string;
18
- name?: string;
19
- };
20
- export declare type DeleteTopicRequest = {
21
- name: string;
22
- id?: never;
23
- } | {
24
- id: string;
25
- name?: never;
26
- };
27
- export declare type Topic = {
28
- /**
29
- * ID for this topic
30
- */
31
- id: string;
32
- /**
33
- * The name of this topic.
34
- */
35
- name: string;
36
- /**
37
- * A list of all subscribed endpoints
38
- */
39
- endpointIDs: string[];
40
- };
41
- export declare class Topics {
42
- private readonly http;
43
- constructor(http: Requester);
44
- /**
45
- * Create a new topic with the given name.
46
- */
47
- create(req: CreateTopicRequest): Promise<Topic>;
48
- /**
49
- * Get a list of all topics.
50
- */
51
- list(): Promise<Topic[]>;
52
- /**
53
- * Get a single topic by name or ID.
54
- */
55
- get(req: GetTopicRequest): Promise<Topic>;
56
- /**
57
- * Update a topic
58
- */
59
- update(req: UpdateTopicRequest): Promise<Topic>;
60
- /**
61
- * Delete a topic by name or ID.
62
- */
63
- delete(req: DeleteTopicRequest): Promise<void>;
64
- }
package/types/types.d.ts DELETED
@@ -1,20 +0,0 @@
1
- export declare type State = "created" | "scheduled" | "active" | "delivered" | "error" | "failed" | "canceled";
2
- export declare type Log = {
3
- time: number;
4
- state: State;
5
- messageID: string;
6
- taskID: string;
7
- nextScheduledAt?: number;
8
- error?: string;
9
- };
10
- export declare type WithCursor<T> = T & {
11
- cursor?: number;
12
- };
13
- export declare type Task = {
14
- taskID: string;
15
- state: State;
16
- maxRetry: number;
17
- retried: number;
18
- completedAt?: number;
19
- url: string;
20
- };