@upstash/qstash 0.0.10 → 0.0.13
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 +2 -2
- package/esm/_dnt.shims.js +0 -3
- package/esm/deps/deno.land/std@0.147.0/_wasm_crypto/lib/deno_std_wasm_crypto.generated.mjs +3159 -0
- package/esm/deps/deno.land/std@0.147.0/_wasm_crypto/mod.js +38 -0
- package/esm/deps/deno.land/std@0.147.0/crypto/_fnv/fnv32.js +24 -0
- package/esm/deps/deno.land/std@0.147.0/crypto/_fnv/fnv64.js +27 -0
- package/esm/deps/deno.land/std@0.147.0/crypto/_fnv/index.js +21 -0
- package/esm/deps/deno.land/std@0.147.0/crypto/_fnv/util.js +48 -0
- package/esm/deps/deno.land/std@0.147.0/crypto/mod.js +149 -0
- package/esm/deps/deno.land/{std@0.144.0 → std@0.147.0}/encoding/base64.js +0 -0
- package/esm/deps/deno.land/{std@0.144.0 → std@0.147.0}/encoding/base64url.js +1 -1
- package/esm/deps.js +1 -0
- package/esm/entrypoints/cloudflare.js +12 -0
- package/esm/entrypoints/nextjs.js +8 -3
- package/esm/entrypoints/nodejs.js +12 -0
- package/esm/pkg/client/client.js +130 -0
- package/esm/pkg/client/endpoints.js +63 -0
- package/esm/pkg/client/error.js +9 -0
- package/esm/pkg/client/http.js +81 -0
- package/esm/pkg/client/messages.js +64 -0
- package/esm/pkg/client/schedules.js +41 -0
- package/esm/pkg/client/topics.js +71 -0
- package/esm/pkg/client/types.js +1 -0
- package/esm/{consumer.js → pkg/consumer.js} +18 -8
- package/package.json +22 -14
- package/script/_dnt.shims.js +1 -5
- package/script/deps/deno.land/std@0.147.0/_wasm_crypto/lib/deno_std_wasm_crypto.generated.mjs +3167 -0
- package/script/deps/deno.land/std@0.147.0/_wasm_crypto/mod.js +43 -0
- package/script/deps/deno.land/std@0.147.0/crypto/_fnv/fnv32.js +29 -0
- package/script/deps/deno.land/std@0.147.0/crypto/_fnv/fnv64.js +32 -0
- package/script/deps/deno.land/std@0.147.0/crypto/_fnv/index.js +25 -0
- package/script/deps/deno.land/std@0.147.0/crypto/_fnv/util.js +54 -0
- package/script/deps/deno.land/std@0.147.0/crypto/mod.js +175 -0
- package/script/deps/deno.land/{std@0.144.0 → std@0.147.0}/encoding/base64.js +0 -0
- package/script/deps/deno.land/{std@0.144.0 → std@0.147.0}/encoding/base64url.js +1 -2
- package/script/deps.js +27 -0
- package/script/entrypoints/cloudflare.js +42 -0
- package/script/entrypoints/nextjs.js +31 -3
- package/script/entrypoints/nodejs.js +42 -0
- package/script/pkg/client/client.js +134 -0
- package/script/pkg/client/endpoints.js +67 -0
- package/script/pkg/client/error.js +13 -0
- package/script/pkg/client/http.js +85 -0
- package/script/pkg/client/messages.js +68 -0
- package/script/pkg/client/schedules.js +45 -0
- package/script/pkg/client/topics.js +75 -0
- package/script/pkg/client/types.js +2 -0
- package/script/{consumer.js → pkg/consumer.js} +18 -31
- package/types/_dnt.shims.d.ts +1 -4
- package/types/deps/deno.land/std@0.147.0/_wasm_crypto/lib/deno_std_wasm_crypto.generated.d.mts +125 -0
- package/types/deps/deno.land/std@0.147.0/_wasm_crypto/mod.d.ts +12 -0
- package/types/deps/deno.land/std@0.147.0/crypto/_fnv/fnv32.d.ts +2 -0
- package/types/deps/deno.land/std@0.147.0/crypto/_fnv/fnv64.d.ts +2 -0
- package/types/deps/deno.land/std@0.147.0/crypto/_fnv/index.d.ts +1 -0
- package/types/deps/deno.land/std@0.147.0/crypto/_fnv/util.d.ts +13 -0
- package/types/deps/deno.land/std@0.147.0/crypto/mod.d.ts +53 -0
- package/types/deps/deno.land/{std@0.144.0 → std@0.147.0}/encoding/base64.d.ts +0 -0
- package/types/deps/deno.land/{std@0.144.0 → std@0.147.0}/encoding/base64url.d.ts +0 -1
- package/types/deps.d.ts +1 -0
- package/types/entrypoints/cloudflare.d.ts +5 -0
- package/types/entrypoints/nextjs.d.ts +6 -0
- package/types/entrypoints/nodejs.d.ts +5 -0
- package/types/pkg/client/client.d.ts +193 -0
- package/types/pkg/client/endpoints.d.ts +59 -0
- package/types/pkg/client/error.d.ts +6 -0
- package/types/pkg/client/http.d.ts +66 -0
- package/types/pkg/client/messages.d.ts +66 -0
- package/types/pkg/client/schedules.d.ts +63 -0
- package/types/pkg/client/topics.d.ts +64 -0
- package/types/pkg/client/types.d.ts +20 -0
- package/types/{consumer.d.ts → pkg/consumer.d.ts} +14 -1
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export class Topics {
|
|
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
|
+
* Create a new topic with the given name.
|
|
13
|
+
*/
|
|
14
|
+
async create(req) {
|
|
15
|
+
return await this.http.request({
|
|
16
|
+
method: "POST",
|
|
17
|
+
path: ["v1", "topics"],
|
|
18
|
+
headers: { "Content-Type": "application/json" },
|
|
19
|
+
body: JSON.stringify({ name: req.name }),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get a list of all topics.
|
|
24
|
+
*/
|
|
25
|
+
async list() {
|
|
26
|
+
return await this.http.request({
|
|
27
|
+
method: "GET",
|
|
28
|
+
path: ["v1", "topics"],
|
|
29
|
+
headers: { "Content-Type": "application/json" },
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get a single topic by name or id.
|
|
34
|
+
*/
|
|
35
|
+
async get(req) {
|
|
36
|
+
const idOrName = req.id ?? req.name;
|
|
37
|
+
if (!idOrName) {
|
|
38
|
+
throw new Error("Either id or name must be provided");
|
|
39
|
+
}
|
|
40
|
+
return await this.http.request({
|
|
41
|
+
method: "GET",
|
|
42
|
+
path: ["v1", "topics", idOrName],
|
|
43
|
+
headers: { "Content-Type": "application/json" },
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Update a topic
|
|
48
|
+
*/
|
|
49
|
+
async update(req) {
|
|
50
|
+
return await this.http.request({
|
|
51
|
+
method: "PUT",
|
|
52
|
+
path: ["v1", "topics", req.id],
|
|
53
|
+
body: JSON.stringify({ name: req.name }),
|
|
54
|
+
headers: { "Content-Type": "application/json" },
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Delete a topic by name or id.
|
|
59
|
+
*/
|
|
60
|
+
async delete(req) {
|
|
61
|
+
const idOrName = req.id ?? req.name;
|
|
62
|
+
if (!idOrName) {
|
|
63
|
+
throw new Error("Either id or name must be provided");
|
|
64
|
+
}
|
|
65
|
+
return await this.http.request({
|
|
66
|
+
method: "DELETE",
|
|
67
|
+
path: ["v1", "topics", idOrName],
|
|
68
|
+
headers: { "Content-Type": "application/json" },
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as base64url from "./deps/deno.land/std@0.144.0/encoding/base64url.js";
|
|
1
|
+
import { base64Url } from "../deps.js";
|
|
3
2
|
export class SignatureError extends Error {
|
|
4
3
|
constructor(message) {
|
|
5
4
|
super(message);
|
|
@@ -23,8 +22,15 @@ export class Consumer {
|
|
|
23
22
|
writable: true,
|
|
24
23
|
value: void 0
|
|
25
24
|
});
|
|
25
|
+
Object.defineProperty(this, "subtleCrypto", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: void 0
|
|
30
|
+
});
|
|
26
31
|
this.currentSigningKey = config.currentSigningKey;
|
|
27
32
|
this.nextSigningKey = config.nextSigningKey;
|
|
33
|
+
this.subtleCrypto = config.subtleCrypto;
|
|
28
34
|
}
|
|
29
35
|
/**
|
|
30
36
|
* Verify the signature of a request.
|
|
@@ -51,12 +57,12 @@ export class Consumer {
|
|
|
51
57
|
throw new SignatureError("`Upstash-Signature` header is not a valid signature");
|
|
52
58
|
}
|
|
53
59
|
const [header, payload, signature] = parts;
|
|
54
|
-
const k = await
|
|
55
|
-
const isValid = await
|
|
60
|
+
const k = await this.subtleCrypto.importKey("raw", new TextEncoder().encode(key), { name: "HMAC", hash: "SHA-256" }, false, ["sign", "verify"]);
|
|
61
|
+
const isValid = await this.subtleCrypto.verify({ name: "HMAC" }, k, base64Url.decode(signature), new TextEncoder().encode(`${header}.${payload}`));
|
|
56
62
|
if (!isValid) {
|
|
57
63
|
throw new SignatureError("signature does not match");
|
|
58
64
|
}
|
|
59
|
-
const p = JSON.parse(new TextDecoder().decode(
|
|
65
|
+
const p = JSON.parse(new TextDecoder().decode(base64Url.decode(payload)));
|
|
60
66
|
console.log(JSON.stringify(p, null, 2));
|
|
61
67
|
if (p.iss !== "Upstash") {
|
|
62
68
|
throw new SignatureError(`invalid issuer: ${p.iss}`);
|
|
@@ -72,9 +78,13 @@ export class Consumer {
|
|
|
72
78
|
if (now < p.nbf) {
|
|
73
79
|
throw new SignatureError("token is not yet valid");
|
|
74
80
|
}
|
|
75
|
-
const bodyHash = await
|
|
76
|
-
|
|
77
|
-
|
|
81
|
+
const bodyHash = await this.subtleCrypto.digest("SHA-256", typeof req.body === "string"
|
|
82
|
+
? new TextEncoder().encode(req.body)
|
|
83
|
+
: req.body);
|
|
84
|
+
const padding = new RegExp(/=+$/);
|
|
85
|
+
if (p.body.replace(padding, "") !=
|
|
86
|
+
base64Url.encode(bodyHash).replace(padding, "")) {
|
|
87
|
+
throw new SignatureError(`body hash does not match, want: ${p.body}, got: ${base64Url.encode(bodyHash)}`);
|
|
78
88
|
}
|
|
79
89
|
return true;
|
|
80
90
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"module": "./esm/entrypoints/
|
|
3
|
-
"main": "./script/entrypoints/
|
|
4
|
-
"types": "./types/entrypoints/
|
|
2
|
+
"module": "./esm/entrypoints/nodejs.js",
|
|
3
|
+
"main": "./script/entrypoints/nodejs.js",
|
|
4
|
+
"types": "./types/entrypoints/nodejs.d.ts",
|
|
5
5
|
"name": "@upstash/qstash",
|
|
6
|
-
"version": "v0.0.
|
|
6
|
+
"version": "v0.0.13",
|
|
7
7
|
"description": "Official Deno/Typescript client for qStash",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
@@ -22,24 +22,32 @@
|
|
|
22
22
|
"url": "https://github.com/upstash/sdk-qstash-ts/issues"
|
|
23
23
|
},
|
|
24
24
|
"homepage": "https://github.com/upstash/sdk-qstash-ts#readme",
|
|
25
|
-
"
|
|
26
|
-
"micro": "latest"
|
|
27
|
-
"next": "latest"
|
|
28
|
-
},
|
|
29
|
-
"typesVersions": {
|
|
30
|
-
"*": {
|
|
31
|
-
"nextjs": "./types/entrypoints/nextjs.d.ts"
|
|
32
|
-
}
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"micro": "latest"
|
|
33
27
|
},
|
|
34
28
|
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"import": "./esm/entrypoints/nodejs.js",
|
|
31
|
+
"require": "./script/entrypoints/nodejs.js",
|
|
32
|
+
"types": "./types/entrypoints/nodejs.d.ts"
|
|
33
|
+
},
|
|
34
|
+
"./nodejs": {
|
|
35
|
+
"import": "./esm/entrypoints/nodejs.js",
|
|
36
|
+
"require": "./script/entrypoints/nodejs.js",
|
|
37
|
+
"types": "./types/entrypoints/nodejs.d.ts"
|
|
38
|
+
},
|
|
35
39
|
"./nextjs": {
|
|
36
40
|
"import": "./esm/entrypoints/nextjs.js",
|
|
37
41
|
"require": "./script/entrypoints/nextjs.js",
|
|
38
42
|
"types": "./types/entrypoints/nextjs.d.ts"
|
|
43
|
+
},
|
|
44
|
+
"./cloudflare": {
|
|
45
|
+
"import": "./esm/entrypoints/cloudflare.js",
|
|
46
|
+
"require": "./script/entrypoints/cloudflare.js",
|
|
47
|
+
"types": "./types/entrypoints/cloudflare.d.ts"
|
|
39
48
|
}
|
|
40
49
|
},
|
|
41
50
|
"dependencies": {
|
|
42
|
-
"@deno/shim-crypto": "~0.
|
|
43
|
-
"@deno/shim-deno": "~0.5.0"
|
|
51
|
+
"@deno/shim-crypto": "~0.3.1"
|
|
44
52
|
}
|
|
45
53
|
}
|
package/script/_dnt.shims.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dntGlobalThis = exports.crypto =
|
|
4
|
-
const shim_deno_1 = require("@deno/shim-deno");
|
|
5
|
-
var shim_deno_2 = require("@deno/shim-deno");
|
|
6
|
-
Object.defineProperty(exports, "Deno", { enumerable: true, get: function () { return shim_deno_2.Deno; } });
|
|
3
|
+
exports.dntGlobalThis = exports.crypto = void 0;
|
|
7
4
|
const shim_crypto_1 = require("@deno/shim-crypto");
|
|
8
5
|
var shim_crypto_2 = require("@deno/shim-crypto");
|
|
9
6
|
Object.defineProperty(exports, "crypto", { enumerable: true, get: function () { return shim_crypto_2.crypto; } });
|
|
10
7
|
const dntGlobals = {
|
|
11
|
-
Deno: shim_deno_1.Deno,
|
|
12
8
|
crypto: shim_crypto_1.crypto,
|
|
13
9
|
};
|
|
14
10
|
exports.dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|