@upstash/qstash 0.0.0 → 0.0.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/esm/client.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { HttpClient } from "./http.js";
2
- import { Topics } from "./topic.js";
3
- import { Endpoints } from "./endpoint.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";
4
6
  export class Client {
5
7
  constructor(config) {
6
8
  Object.defineProperty(this, "http", {
@@ -22,6 +24,12 @@ export class Client {
22
24
  get endpoints() {
23
25
  return new Endpoints(this.http);
24
26
  }
27
+ get messages() {
28
+ return new Messages(this.http);
29
+ }
30
+ get schedules() {
31
+ return new Schedules(this.http);
32
+ }
25
33
  async publish(req) {
26
34
  const res = await this.http.request({
27
35
  path: ["v1", "publish", req.destination],
@@ -31,4 +39,16 @@ export class Client {
31
39
  });
32
40
  return res;
33
41
  }
42
+ async logs(req) {
43
+ const query = {};
44
+ if (req?.cursor && req.cursor > 0) {
45
+ query["cursor"] = req.cursor;
46
+ }
47
+ const res = await this.http.request({
48
+ path: ["v1", "logs"],
49
+ method: "GET",
50
+ query,
51
+ });
52
+ return res;
53
+ }
34
54
  }
File without changes
package/esm/http.js CHANGED
@@ -47,17 +47,24 @@ export class HttpClient {
47
47
  "Upstash-Authorization": `Bearer ${this.authorization}`,
48
48
  });
49
49
  const requestOptions = {
50
- method: "POST",
50
+ method: req.method,
51
51
  headers,
52
52
  body: req.body,
53
53
  keepalive: req.keepalive,
54
54
  };
55
- await fetch("https://qstash-debug.requestcatcher.com/test", requestOptions);
55
+ const url = new URL([this.baseUrl, ...(req.path ?? [])].join("/"));
56
+ if (req.query) {
57
+ for (const [key, value] of Object.entries(req.query)) {
58
+ if (typeof value !== "undefined") {
59
+ url.searchParams.set(key, value.toString());
60
+ }
61
+ }
62
+ }
56
63
  let res = null;
57
64
  let error = null;
58
65
  for (let i = 0; i <= this.retry.attempts; i++) {
59
66
  try {
60
- res = await fetch([this.baseUrl, ...(req.path ?? [])].join("/"), requestOptions);
67
+ res = await fetch(url.toString(), requestOptions);
61
68
  break;
62
69
  }
63
70
  catch (err) {
@@ -0,0 +1,64 @@
1
+ export class Messages {
2
+ constructor(http) {
3
+ Object.defineProperty(this, "http", {
4
+ enumerable: true,
5
+ configurable: true,
6
+ writable: true,
7
+ value: void 0
8
+ });
9
+ this.http = http;
10
+ }
11
+ /**
12
+ * Get a message
13
+ */
14
+ async get(req) {
15
+ return await this.http.request({
16
+ method: "GET",
17
+ path: ["v1", "messages", req.id],
18
+ headers: { "Content-Type": "application/json" },
19
+ });
20
+ }
21
+ /**
22
+ * List your messages
23
+ */
24
+ async list(req) {
25
+ return await this.http.request({
26
+ method: "GET",
27
+ path: ["v1", "messages"],
28
+ headers: { "Content-Type": "application/json" },
29
+ query: { cursor: req?.cursor },
30
+ });
31
+ }
32
+ /**
33
+ * List logs from a message
34
+ */
35
+ async logs(req) {
36
+ return await this.http.request({
37
+ method: "GET",
38
+ path: ["v1", "messages", req.id, "logs"],
39
+ headers: { "Content-Type": "application/json" },
40
+ query: { cursor: req.cursor },
41
+ });
42
+ }
43
+ /**
44
+ * List tasks for a message
45
+ */
46
+ async tasks(req) {
47
+ return await this.http.request({
48
+ method: "GET",
49
+ path: ["v1", "messages", req.id, "tasks"],
50
+ headers: { "Content-Type": "application/json" },
51
+ query: { cursor: req.cursor },
52
+ });
53
+ }
54
+ /**
55
+ * Cancel a topic by name or ID.
56
+ */
57
+ async delete(req) {
58
+ return await this.http.request({
59
+ method: "DELETE",
60
+ path: ["v1", "messages", req.id],
61
+ headers: { "Content-Type": "application/json" },
62
+ });
63
+ }
64
+ }
@@ -0,0 +1,41 @@
1
+ export class Schedules {
2
+ constructor(http) {
3
+ Object.defineProperty(this, "http", {
4
+ enumerable: true,
5
+ configurable: true,
6
+ writable: true,
7
+ value: void 0
8
+ });
9
+ this.http = http;
10
+ }
11
+ /**
12
+ * Get a schedule
13
+ */
14
+ async get(req) {
15
+ return await this.http.request({
16
+ method: "GET",
17
+ path: ["v1", "schedules", req.id],
18
+ headers: { "Content-Type": "application/json" },
19
+ });
20
+ }
21
+ /**
22
+ * List your schedules
23
+ */
24
+ async list() {
25
+ return await this.http.request({
26
+ method: "GET",
27
+ path: ["v1", "schedules"],
28
+ headers: { "Content-Type": "application/json" },
29
+ });
30
+ }
31
+ /**
32
+ * Delete a schedule
33
+ */
34
+ async delete(req) {
35
+ return await this.http.request({
36
+ method: "DELETE",
37
+ path: ["v1", "schedules", req.id],
38
+ headers: { "Content-Type": "application/json" },
39
+ });
40
+ }
41
+ }
File without changes
package/esm/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "main": "./script/platforms/nodejs.js",
4
4
  "types": "./types/platforms/nodejs.d.ts",
5
5
  "name": "@upstash/qstash",
6
- "version": "v0.0.0",
6
+ "version": "v0.0.2",
7
7
  "description": "Official Deno/Typescript client for qStash",
8
8
  "repository": {
9
9
  "type": "git",
package/script/client.js CHANGED
@@ -2,8 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Client = void 0;
4
4
  const http_js_1 = require("./http.js");
5
- const topic_js_1 = require("./topic.js");
6
- const endpoint_js_1 = require("./endpoint.js");
5
+ const topics_js_1 = require("./topics.js");
6
+ const messages_js_1 = require("./messages.js");
7
+ const schedules_js_1 = require("./schedules.js");
8
+ const endpoints_js_1 = require("./endpoints.js");
7
9
  class Client {
8
10
  constructor(config) {
9
11
  Object.defineProperty(this, "http", {
@@ -20,10 +22,16 @@ class Client {
20
22
  });
21
23
  }
22
24
  get topics() {
23
- return new topic_js_1.Topics(this.http);
25
+ return new topics_js_1.Topics(this.http);
24
26
  }
25
27
  get endpoints() {
26
- return new endpoint_js_1.Endpoints(this.http);
28
+ return new endpoints_js_1.Endpoints(this.http);
29
+ }
30
+ get messages() {
31
+ return new messages_js_1.Messages(this.http);
32
+ }
33
+ get schedules() {
34
+ return new schedules_js_1.Schedules(this.http);
27
35
  }
28
36
  async publish(req) {
29
37
  const res = await this.http.request({
@@ -34,5 +42,17 @@ class Client {
34
42
  });
35
43
  return res;
36
44
  }
45
+ async logs(req) {
46
+ const query = {};
47
+ if (req?.cursor && req.cursor > 0) {
48
+ query["cursor"] = req.cursor;
49
+ }
50
+ const res = await this.http.request({
51
+ path: ["v1", "logs"],
52
+ method: "GET",
53
+ query,
54
+ });
55
+ return res;
56
+ }
37
57
  }
38
58
  exports.Client = Client;
File without changes
package/script/http.js CHANGED
@@ -50,17 +50,24 @@ class HttpClient {
50
50
  "Upstash-Authorization": `Bearer ${this.authorization}`,
51
51
  });
52
52
  const requestOptions = {
53
- method: "POST",
53
+ method: req.method,
54
54
  headers,
55
55
  body: req.body,
56
56
  keepalive: req.keepalive,
57
57
  };
58
- await fetch("https://qstash-debug.requestcatcher.com/test", requestOptions);
58
+ const url = new URL([this.baseUrl, ...(req.path ?? [])].join("/"));
59
+ if (req.query) {
60
+ for (const [key, value] of Object.entries(req.query)) {
61
+ if (typeof value !== "undefined") {
62
+ url.searchParams.set(key, value.toString());
63
+ }
64
+ }
65
+ }
59
66
  let res = null;
60
67
  let error = null;
61
68
  for (let i = 0; i <= this.retry.attempts; i++) {
62
69
  try {
63
- res = await fetch([this.baseUrl, ...(req.path ?? [])].join("/"), requestOptions);
70
+ res = await fetch(url.toString(), requestOptions);
64
71
  break;
65
72
  }
66
73
  catch (err) {
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Messages = void 0;
4
+ class Messages {
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
+ * Get a message
16
+ */
17
+ async get(req) {
18
+ return await this.http.request({
19
+ method: "GET",
20
+ path: ["v1", "messages", req.id],
21
+ headers: { "Content-Type": "application/json" },
22
+ });
23
+ }
24
+ /**
25
+ * List your messages
26
+ */
27
+ async list(req) {
28
+ return await this.http.request({
29
+ method: "GET",
30
+ path: ["v1", "messages"],
31
+ headers: { "Content-Type": "application/json" },
32
+ query: { cursor: req?.cursor },
33
+ });
34
+ }
35
+ /**
36
+ * List logs from a message
37
+ */
38
+ async logs(req) {
39
+ return await this.http.request({
40
+ method: "GET",
41
+ path: ["v1", "messages", req.id, "logs"],
42
+ headers: { "Content-Type": "application/json" },
43
+ query: { cursor: req.cursor },
44
+ });
45
+ }
46
+ /**
47
+ * List tasks for a message
48
+ */
49
+ async tasks(req) {
50
+ return await this.http.request({
51
+ method: "GET",
52
+ path: ["v1", "messages", req.id, "tasks"],
53
+ headers: { "Content-Type": "application/json" },
54
+ query: { cursor: req.cursor },
55
+ });
56
+ }
57
+ /**
58
+ * Cancel a topic by name or ID.
59
+ */
60
+ async delete(req) {
61
+ return await this.http.request({
62
+ method: "DELETE",
63
+ path: ["v1", "messages", req.id],
64
+ headers: { "Content-Type": "application/json" },
65
+ });
66
+ }
67
+ }
68
+ exports.Messages = Messages;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Schedules = void 0;
4
+ class Schedules {
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
+ * Get a schedule
16
+ */
17
+ async get(req) {
18
+ return await this.http.request({
19
+ method: "GET",
20
+ path: ["v1", "schedules", req.id],
21
+ headers: { "Content-Type": "application/json" },
22
+ });
23
+ }
24
+ /**
25
+ * List your schedules
26
+ */
27
+ async list() {
28
+ return await this.http.request({
29
+ method: "GET",
30
+ path: ["v1", "schedules"],
31
+ headers: { "Content-Type": "application/json" },
32
+ });
33
+ }
34
+ /**
35
+ * Delete a schedule
36
+ */
37
+ async delete(req) {
38
+ return await this.http.request({
39
+ method: "DELETE",
40
+ path: ["v1", "schedules", req.id],
41
+ headers: { "Content-Type": "application/json" },
42
+ });
43
+ }
44
+ }
45
+ exports.Schedules = Schedules;
File without changes
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/types/client.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { Requester } from "./http.js";
2
- import { Topics } from "./topic.js";
3
- import { Endpoints } from "./endpoint.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";
4
7
  export declare type ClientConfig = {
5
8
  /**
6
9
  * Url of the qstash api server
@@ -107,12 +110,22 @@ declare type PublishRequest = {
107
110
  */
108
111
  retries?: number;
109
112
  };
113
+ export declare type LogsRequest = {
114
+ cursor?: number;
115
+ };
116
+ export declare type GetLogsRespone = {
117
+ cursor?: number;
118
+ logs: Log[];
119
+ };
110
120
  export declare class Client {
111
121
  http: Requester;
112
122
  constructor(config: ClientConfig);
113
123
  get topics(): Topics;
114
124
  get endpoints(): Endpoints;
125
+ get messages(): Messages;
126
+ get schedules(): Schedules;
115
127
  publish<R extends PublishRequest = PublishRequest>(req: R): Promise<PublishResponse<R>>;
128
+ logs(req?: LogsRequest): Promise<GetLogsRespone>;
116
129
  }
117
130
  declare type PublishResponse<PublishRequest> = PublishRequest extends {
118
131
  cron: string;
File without changes
package/types/http.d.ts CHANGED
@@ -20,6 +20,7 @@ export declare type UpstashRequest = {
20
20
  * A string to set request's method.
21
21
  */
22
22
  method?: "GET" | "POST" | "PUT" | "DELETE";
23
+ query?: Record<string, string | number | boolean | undefined>;
23
24
  };
24
25
  export declare type UpstashResponse<TResult> = TResult & {
25
26
  error?: string;
@@ -0,0 +1,66 @@
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
+ }
@@ -0,0 +1,63 @@
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
+ }
File without changes
@@ -0,0 +1,20 @@
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
+ };
package/.releaserc DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "branches": [
3
- {
4
- "name": "release"
5
- },
6
- {
7
- "name": "main",
8
- "channel": "next",
9
- "prerelease": "next"
10
- }
11
- ],
12
- "dryRun": false,
13
- "ci": true
14
- }