@upstash/qstash 0.0.9 → 0.0.12

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 (68) hide show
  1. package/README.md +2 -2
  2. package/esm/_dnt.shims.js +0 -3
  3. package/esm/deps/deno.land/std@0.147.0/_wasm_crypto/lib/deno_std_wasm_crypto.generated.mjs +3159 -0
  4. package/esm/deps/deno.land/std@0.147.0/_wasm_crypto/mod.js +38 -0
  5. package/esm/deps/deno.land/std@0.147.0/crypto/_fnv/fnv32.js +24 -0
  6. package/esm/deps/deno.land/std@0.147.0/crypto/_fnv/fnv64.js +27 -0
  7. package/esm/deps/deno.land/std@0.147.0/crypto/_fnv/index.js +21 -0
  8. package/esm/deps/deno.land/std@0.147.0/crypto/_fnv/util.js +48 -0
  9. package/esm/deps/deno.land/std@0.147.0/crypto/mod.js +149 -0
  10. package/esm/deps/deno.land/{std@0.144.0 → std@0.147.0}/encoding/base64.js +0 -0
  11. package/esm/deps/deno.land/{std@0.144.0 → std@0.147.0}/encoding/base64url.js +1 -1
  12. package/esm/deps.js +1 -0
  13. package/esm/entrypoints/cloudflare.js +12 -0
  14. package/esm/entrypoints/nextjs.js +8 -3
  15. package/esm/pkg/client/client.js +130 -0
  16. package/esm/pkg/client/endpoints.js +63 -0
  17. package/esm/pkg/client/error.js +9 -0
  18. package/esm/pkg/client/http.js +81 -0
  19. package/esm/pkg/client/messages.js +64 -0
  20. package/esm/pkg/client/schedules.js +41 -0
  21. package/esm/pkg/client/topics.js +71 -0
  22. package/esm/pkg/client/types.js +1 -0
  23. package/esm/{consumer.js → pkg/consumer.js} +18 -8
  24. package/package.json +11 -7
  25. package/script/_dnt.shims.js +1 -5
  26. package/script/deps/deno.land/std@0.147.0/_wasm_crypto/lib/deno_std_wasm_crypto.generated.mjs +3167 -0
  27. package/script/deps/deno.land/std@0.147.0/_wasm_crypto/mod.js +43 -0
  28. package/script/deps/deno.land/std@0.147.0/crypto/_fnv/fnv32.js +29 -0
  29. package/script/deps/deno.land/std@0.147.0/crypto/_fnv/fnv64.js +32 -0
  30. package/script/deps/deno.land/std@0.147.0/crypto/_fnv/index.js +25 -0
  31. package/script/deps/deno.land/std@0.147.0/crypto/_fnv/util.js +54 -0
  32. package/script/deps/deno.land/std@0.147.0/crypto/mod.js +175 -0
  33. package/script/deps/deno.land/{std@0.144.0 → std@0.147.0}/encoding/base64.js +0 -0
  34. package/script/deps/deno.land/{std@0.144.0 → std@0.147.0}/encoding/base64url.js +1 -2
  35. package/script/deps.js +27 -0
  36. package/script/entrypoints/cloudflare.js +42 -0
  37. package/script/entrypoints/nextjs.js +31 -3
  38. package/script/pkg/client/client.js +134 -0
  39. package/script/pkg/client/endpoints.js +67 -0
  40. package/script/pkg/client/error.js +13 -0
  41. package/script/pkg/client/http.js +85 -0
  42. package/script/pkg/client/messages.js +68 -0
  43. package/script/pkg/client/schedules.js +45 -0
  44. package/script/pkg/client/topics.js +75 -0
  45. package/script/pkg/client/types.js +2 -0
  46. package/script/{consumer.js → pkg/consumer.js} +18 -31
  47. package/types/_dnt.shims.d.ts +1 -4
  48. package/types/deps/deno.land/std@0.147.0/_wasm_crypto/lib/deno_std_wasm_crypto.generated.d.mts +125 -0
  49. package/types/deps/deno.land/std@0.147.0/_wasm_crypto/mod.d.ts +12 -0
  50. package/types/deps/deno.land/std@0.147.0/crypto/_fnv/fnv32.d.ts +2 -0
  51. package/types/deps/deno.land/std@0.147.0/crypto/_fnv/fnv64.d.ts +2 -0
  52. package/types/deps/deno.land/std@0.147.0/crypto/_fnv/index.d.ts +1 -0
  53. package/types/deps/deno.land/std@0.147.0/crypto/_fnv/util.d.ts +13 -0
  54. package/types/deps/deno.land/std@0.147.0/crypto/mod.d.ts +53 -0
  55. package/types/deps/deno.land/{std@0.144.0 → std@0.147.0}/encoding/base64.d.ts +0 -0
  56. package/types/deps/deno.land/{std@0.144.0 → std@0.147.0}/encoding/base64url.d.ts +0 -1
  57. package/types/deps.d.ts +1 -0
  58. package/types/entrypoints/cloudflare.d.ts +5 -0
  59. package/types/entrypoints/nextjs.d.ts +6 -0
  60. package/types/pkg/client/client.d.ts +193 -0
  61. package/types/pkg/client/endpoints.d.ts +59 -0
  62. package/types/pkg/client/error.d.ts +6 -0
  63. package/types/pkg/client/http.d.ts +66 -0
  64. package/types/pkg/client/messages.d.ts +66 -0
  65. package/types/pkg/client/schedules.d.ts +63 -0
  66. package/types/pkg/client/topics.d.ts +64 -0
  67. package/types/pkg/client/types.d.ts +20 -0
  68. package/types/{consumer.d.ts → pkg/consumer.d.ts} +14 -1
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.digestAlgorithms = exports.instantiateWasm = exports.DigestContext = void 0;
4
+ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
5
+ var deno_std_wasm_crypto_generated_js_1 = require("./lib/deno_std_wasm_crypto.generated.js");
6
+ Object.defineProperty(exports, "DigestContext", { enumerable: true, get: function () { return deno_std_wasm_crypto_generated_js_1.DigestContext; } });
7
+ Object.defineProperty(exports, "instantiateWasm", { enumerable: true, get: function () { return deno_std_wasm_crypto_generated_js_1.instantiate; } });
8
+ /**
9
+ * All cryptographic hash/digest algorithms supported by std/_wasm_crypto.
10
+ *
11
+ * For algorithms that are supported by WebCrypto, the name here must match the
12
+ * one used by WebCrypto. Otherwise we should prefer the formatting used in the
13
+ * official specification. All names are uppercase to facilitate case-insensitive
14
+ * comparisons required by the WebCrypto spec.
15
+ */
16
+ exports.digestAlgorithms = [
17
+ "BLAKE2B-256",
18
+ "BLAKE2B-384",
19
+ "BLAKE2B",
20
+ "BLAKE2S",
21
+ "BLAKE3",
22
+ "KECCAK-224",
23
+ "KECCAK-256",
24
+ "KECCAK-384",
25
+ "KECCAK-512",
26
+ "SHA-384",
27
+ "SHA3-224",
28
+ "SHA3-256",
29
+ "SHA3-384",
30
+ "SHA3-512",
31
+ "SHAKE128",
32
+ "SHAKE256",
33
+ "TIGER",
34
+ // insecure (length-extendable):
35
+ "RIPEMD-160",
36
+ "SHA-224",
37
+ "SHA-256",
38
+ "SHA-512",
39
+ // insecure (collidable and length-extendable):
40
+ "MD4",
41
+ "MD5",
42
+ "SHA-1",
43
+ ];
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ // Ported from Go:
3
+ // https://github.com/golang/go/tree/go1.13.10/src/hash/fnv/fnv.go
4
+ // Copyright 2011 The Go Authors. All rights reserved. BSD license.
5
+ // https://github.com/golang/go/blob/master/LICENSE
6
+ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
7
+ // This module is browser compatible.
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.fnv32a = exports.fnv32 = void 0;
10
+ const util_js_1 = require("./util.js");
11
+ const prime32 = 16777619;
12
+ const fnv32 = (data) => {
13
+ let hash = 2166136261;
14
+ data.forEach((c) => {
15
+ hash = (0, util_js_1.mul32)(hash, prime32);
16
+ hash ^= c;
17
+ });
18
+ return Uint32Array.from([(0, util_js_1.swap32)(hash)]).buffer;
19
+ };
20
+ exports.fnv32 = fnv32;
21
+ const fnv32a = (data) => {
22
+ let hash = 2166136261;
23
+ data.forEach((c) => {
24
+ hash ^= c;
25
+ hash = (0, util_js_1.mul32)(hash, prime32);
26
+ });
27
+ return Uint32Array.from([(0, util_js_1.swap32)(hash)]).buffer;
28
+ };
29
+ exports.fnv32a = fnv32a;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ // Ported from Go:
3
+ // https://github.com/golang/go/tree/go1.13.10/src/hash/fnv/fnv.go
4
+ // Copyright 2011 The Go Authors. All rights reserved. BSD license.
5
+ // https://github.com/golang/go/blob/master/LICENSE
6
+ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
7
+ // This module is browser compatible.
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.fnv64a = exports.fnv64 = void 0;
10
+ const util_js_1 = require("./util.js");
11
+ const prime64Lo = 435;
12
+ const prime64Hi = 256;
13
+ const fnv64 = (data) => {
14
+ let hashLo = 2216829733;
15
+ let hashHi = 3421674724;
16
+ data.forEach((c) => {
17
+ [hashHi, hashLo] = (0, util_js_1.mul64)([hashHi, hashLo], [prime64Hi, prime64Lo]);
18
+ hashLo ^= c;
19
+ });
20
+ return new Uint32Array([(0, util_js_1.swap32)(hashHi >>> 0), (0, util_js_1.swap32)(hashLo >>> 0)]).buffer;
21
+ };
22
+ exports.fnv64 = fnv64;
23
+ const fnv64a = (data) => {
24
+ let hashLo = 2216829733;
25
+ let hashHi = 3421674724;
26
+ data.forEach((c) => {
27
+ hashLo ^= c;
28
+ [hashHi, hashLo] = (0, util_js_1.mul64)([hashHi, hashLo], [prime64Hi, prime64Lo]);
29
+ });
30
+ return new Uint32Array([(0, util_js_1.swap32)(hashHi >>> 0), (0, util_js_1.swap32)(hashLo >>> 0)]).buffer;
31
+ };
32
+ exports.fnv64a = fnv64a;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
3
+ // This module is browser compatible.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.fnv = void 0;
6
+ const fnv32_js_1 = require("./fnv32.js");
7
+ const fnv64_js_1 = require("./fnv64.js");
8
+ const fnv = (name, buf) => {
9
+ if (!buf) {
10
+ throw new TypeError("no data provided for hashing");
11
+ }
12
+ switch (name) {
13
+ case "FNV32":
14
+ return (0, fnv32_js_1.fnv32)(buf);
15
+ case "FNV64":
16
+ return (0, fnv64_js_1.fnv64)(buf);
17
+ case "FNV32A":
18
+ return (0, fnv32_js_1.fnv32a)(buf);
19
+ case "FNV64A":
20
+ return (0, fnv64_js_1.fnv64a)(buf);
21
+ default:
22
+ throw new TypeError(`unsupported fnv digest: ${name}`);
23
+ }
24
+ };
25
+ exports.fnv = fnv;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
3
+ // This module is browser compatible.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.mul64 = exports.mul32 = exports.swap32 = void 0;
6
+ function swap32(val) {
7
+ return (((val & 0xff) << 24) |
8
+ ((val & 0xff00) << 8) |
9
+ ((val >> 8) & 0xff00) |
10
+ ((val >> 24) & 0xff));
11
+ }
12
+ exports.swap32 = swap32;
13
+ function n16(n) {
14
+ return n & 0xffff;
15
+ }
16
+ function n32(n) {
17
+ return n >>> 0;
18
+ }
19
+ function add32WithCarry(a, b) {
20
+ const added = n32(a) + n32(b);
21
+ return [n32(added), added > 0xffffffff ? 1 : 0];
22
+ }
23
+ function mul32WithCarry(a, b) {
24
+ const al = n16(a);
25
+ const ah = n16(a >>> 16);
26
+ const bl = n16(b);
27
+ const bh = n16(b >>> 16);
28
+ const [t, tc] = add32WithCarry(al * bh, ah * bl);
29
+ const [n, nc] = add32WithCarry(al * bl, n32(t << 16));
30
+ const carry = nc + (tc << 16) + n16(t >>> 16) + ah * bh;
31
+ return [n, carry];
32
+ }
33
+ /**
34
+ * mul32 performs 32-bit multiplication, a * b
35
+ * @param a
36
+ * @param b
37
+ */
38
+ function mul32(a, b) {
39
+ // https://stackoverflow.com/a/28151933
40
+ const al = n16(a);
41
+ const ah = a - al;
42
+ return n32(n32(ah * b) + al * b);
43
+ }
44
+ exports.mul32 = mul32;
45
+ /**
46
+ * mul64 performs 64-bit multiplication with two 32-bit words
47
+ * @param [ah, al]
48
+ * @param [bh, bl]
49
+ */
50
+ function mul64([ah, al], [bh, bl]) {
51
+ const [n, c] = mul32WithCarry(al, bl);
52
+ return [n32(mul32(al, bh) + mul32(ah, bl) + c), n];
53
+ }
54
+ exports.mul64 = mul64;
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.crypto = void 0;
27
+ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
28
+ const dntShim = __importStar(require("../../../../_dnt.shims.js"));
29
+ const mod_js_1 = require("../_wasm_crypto/mod.js");
30
+ const index_js_1 = require("./_fnv/index.js");
31
+ /**
32
+ * A copy of the global WebCrypto interface, with methods bound so they're
33
+ * safe to re-export.
34
+ * @module
35
+ */
36
+ const webCrypto = ((crypto) => ({
37
+ getRandomValues: crypto.getRandomValues?.bind(crypto),
38
+ randomUUID: crypto.randomUUID?.bind(crypto),
39
+ subtle: {
40
+ decrypt: crypto.subtle?.decrypt?.bind(crypto.subtle),
41
+ deriveBits: crypto.subtle?.deriveBits?.bind(crypto.subtle),
42
+ deriveKey: crypto.subtle?.deriveKey?.bind(crypto.subtle),
43
+ digest: crypto.subtle?.digest?.bind(crypto.subtle),
44
+ encrypt: crypto.subtle?.encrypt?.bind(crypto.subtle),
45
+ exportKey: crypto.subtle?.exportKey?.bind(crypto.subtle),
46
+ generateKey: crypto.subtle?.generateKey?.bind(crypto.subtle),
47
+ importKey: crypto.subtle?.importKey?.bind(crypto.subtle),
48
+ sign: crypto.subtle?.sign?.bind(crypto.subtle),
49
+ unwrapKey: crypto.subtle?.unwrapKey?.bind(crypto.subtle),
50
+ verify: crypto.subtle?.verify?.bind(crypto.subtle),
51
+ wrapKey: crypto.subtle?.wrapKey?.bind(crypto.subtle),
52
+ },
53
+ }))(dntShim.dntGlobalThis.crypto);
54
+ const bufferSourceBytes = (data) => {
55
+ let bytes;
56
+ if (data instanceof Uint8Array) {
57
+ bytes = data;
58
+ }
59
+ else if (ArrayBuffer.isView(data)) {
60
+ bytes = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
61
+ }
62
+ else if (data instanceof ArrayBuffer) {
63
+ bytes = new Uint8Array(data);
64
+ }
65
+ return bytes;
66
+ };
67
+ /**
68
+ * An wrapper for WebCrypto adding support for additional non-standard
69
+ * algorithms, but delegating to the runtime WebCrypto implementation whenever
70
+ * possible.
71
+ */
72
+ const stdCrypto = ((x) => x)({
73
+ ...webCrypto,
74
+ subtle: {
75
+ ...webCrypto.subtle,
76
+ /**
77
+ * Returns a new `Promise` object that will digest `data` using the specified
78
+ * `AlgorithmIdentifier`.
79
+ */
80
+ async digest(algorithm, data) {
81
+ const { name, length } = normalizeAlgorithm(algorithm);
82
+ const bytes = bufferSourceBytes(data);
83
+ if (FNVAlgorithms.includes(name)) {
84
+ return (0, index_js_1.fnv)(name, bytes);
85
+ }
86
+ // We delegate to WebCrypto whenever possible,
87
+ if (
88
+ // if the algorithm is supported by the WebCrypto standard,
89
+ webCryptoDigestAlgorithms.includes(name) &&
90
+ // and the data is a single buffer,
91
+ bytes) {
92
+ return webCrypto.subtle.digest(algorithm, bytes);
93
+ }
94
+ else if (mod_js_1.digestAlgorithms.includes(name)) {
95
+ if (bytes) {
96
+ // Otherwise, we use our bundled Wasm implementation via digestSync
97
+ // if it supports the algorithm.
98
+ return stdCrypto.subtle.digestSync(algorithm, bytes);
99
+ }
100
+ else if (data[Symbol.iterator]) {
101
+ return stdCrypto.subtle.digestSync(algorithm, data);
102
+ }
103
+ else if (data[Symbol.asyncIterator]) {
104
+ const wasmCrypto = (0, mod_js_1.instantiateWasm)();
105
+ const context = new wasmCrypto.DigestContext(name);
106
+ for await (const chunk of data) {
107
+ const chunkBytes = bufferSourceBytes(chunk);
108
+ if (!chunkBytes) {
109
+ throw new TypeError("data contained chunk of the wrong type");
110
+ }
111
+ context.update(chunkBytes);
112
+ }
113
+ return context.digestAndDrop(length).buffer;
114
+ }
115
+ else {
116
+ throw new TypeError("data must be a BufferSource or [Async]Iterable<BufferSource>");
117
+ }
118
+ }
119
+ else if (webCrypto.subtle?.digest) {
120
+ // (TypeScript type definitions prohibit this case.) If they're trying
121
+ // to call an algorithm we don't recognize, pass it along to WebCrypto
122
+ // in case it's a non-standard algorithm supported by the the runtime
123
+ // they're using.
124
+ return webCrypto.subtle.digest(algorithm, data);
125
+ }
126
+ else {
127
+ throw new TypeError(`unsupported digest algorithm: ${algorithm}`);
128
+ }
129
+ },
130
+ /**
131
+ * Returns a ArrayBuffer with the result of digesting `data` using the
132
+ * specified `AlgorithmIdentifier`.
133
+ */
134
+ digestSync(algorithm, data) {
135
+ algorithm = normalizeAlgorithm(algorithm);
136
+ const bytes = bufferSourceBytes(data);
137
+ if (FNVAlgorithms.includes(algorithm.name)) {
138
+ return (0, index_js_1.fnv)(algorithm.name, bytes);
139
+ }
140
+ const wasmCrypto = (0, mod_js_1.instantiateWasm)();
141
+ if (bytes) {
142
+ return wasmCrypto.digest(algorithm.name, bytes, algorithm.length)
143
+ .buffer;
144
+ }
145
+ else if (data[Symbol.iterator]) {
146
+ const context = new wasmCrypto.DigestContext(algorithm.name);
147
+ for (const chunk of data) {
148
+ const chunkBytes = bufferSourceBytes(chunk);
149
+ if (!chunkBytes) {
150
+ throw new TypeError("data contained chunk of the wrong type");
151
+ }
152
+ context.update(chunkBytes);
153
+ }
154
+ return context.digestAndDrop(algorithm.length).buffer;
155
+ }
156
+ else {
157
+ throw new TypeError("data must be a BufferSource or Iterable<BufferSource>");
158
+ }
159
+ },
160
+ },
161
+ });
162
+ exports.crypto = stdCrypto;
163
+ const FNVAlgorithms = ["FNV32", "FNV32A", "FNV64", "FNV64A"];
164
+ /** Digest algorithms supported by WebCrypto. */
165
+ const webCryptoDigestAlgorithms = [
166
+ "SHA-384",
167
+ "SHA-256",
168
+ "SHA-512",
169
+ // insecure (length-extendable and collidable):
170
+ "SHA-1",
171
+ ];
172
+ const normalizeAlgorithm = (algorithm) => ((typeof algorithm === "string") ? { name: algorithm.toUpperCase() } : {
173
+ ...algorithm,
174
+ name: algorithm.name.toUpperCase(),
175
+ });
@@ -25,7 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  return result;
26
26
  };
27
27
  Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.decode = exports.encode = exports.addPaddingToBase64url = void 0;
28
+ exports.decode = exports.encode = void 0;
29
29
  const base64 = __importStar(require("./base64.js"));
30
30
  /*
31
31
  * Some variants allow or require omitting the padding '=' signs:
@@ -42,7 +42,6 @@ function addPaddingToBase64url(base64url) {
42
42
  }
43
43
  return base64url;
44
44
  }
45
- exports.addPaddingToBase64url = addPaddingToBase64url;
46
45
  function convertBase64urlToBase64(b64url) {
47
46
  if (!/^[-_A-Z0-9]*?={0,2}$/i.test(b64url)) {
48
47
  // Contains characters not part of base64url spec.
package/script/deps.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.base64Url = void 0;
27
+ exports.base64Url = __importStar(require("./deps/deno.land/std@0.147.0/encoding/base64url.js"));
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ // dnt-shim-ignore
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
26
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
27
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.Consumer = void 0;
31
+ const c = __importStar(require("../pkg/consumer.js"));
32
+ __exportStar(require("../pkg/client/client.js"), exports);
33
+ class Consumer extends c.Consumer {
34
+ constructor(config) {
35
+ super({
36
+ ...config,
37
+ // dnt-shim-ignore
38
+ subtleCrypto: crypto.subtle
39
+ });
40
+ }
41
+ }
42
+ exports.Consumer = Consumer;
@@ -1,15 +1,42 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.verifySignature = void 0;
27
+ const dntShim = __importStar(require("../_dnt.shims.js"));
28
+ // @ts-ignore Deno can't compile
4
29
  const micro_1 = require("micro");
5
- const consumer_js_1 = require("../consumer.js");
30
+ const consumer_js_1 = require("../pkg/consumer.js");
6
31
  function verifySignature(handler, config) {
7
32
  const currentSigningKey = config?.currentSigningKey ??
33
+ // @ts-ignore Deno can't compile
8
34
  process.env.get["QSTASH_CURRENT_SIGNING_KEY"];
9
35
  if (!currentSigningKey) {
10
36
  throw new Error("currentSigningKey is required, either in the config or as env variable QSTASH_CURRENT_SIGNING_KEY");
11
37
  }
12
38
  const nextSigningKey = config?.nextSigningKey ??
39
+ // @ts-ignore Deno can't compile
13
40
  process.env.get["QSTASH_NEXT_SIGNING_KEY"];
14
41
  if (!nextSigningKey) {
15
42
  throw new Error("nextSigningKey is required, either in the config or as env variable QSTASH_NEXT_SIGNING_KEY");
@@ -17,6 +44,7 @@ function verifySignature(handler, config) {
17
44
  const consumer = new consumer_js_1.Consumer({
18
45
  currentSigningKey,
19
46
  nextSigningKey,
47
+ subtleCrypto: dntShim.crypto.subtle
20
48
  });
21
49
  return async (req, res) => {
22
50
  const signature = req.headers["upstash-signature"];
@@ -27,8 +55,8 @@ function verifySignature(handler, config) {
27
55
  throw new Error("`Upstash-Signature` header is not a string");
28
56
  }
29
57
  const body = (await (0, micro_1.buffer)(req)).toString();
30
- const url = new URL(req.url, `https://${req.headers.host}`).href;
31
- console.log({ reqUrl: req.url, url });
58
+ console.log(req.headers);
59
+ const url = config?.url ?? new URL(req.url, `https://${process.env.VERCEL_URL}`).href;
32
60
  const isValid = await consumer.verify({ signature, body, url });
33
61
  if (!isValid) {
34
62
  res.status(400);
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Client = void 0;
4
+ const http_js_1 = require("./http.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");
9
+ class Client {
10
+ constructor(config) {
11
+ Object.defineProperty(this, "http", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: void 0
16
+ });
17
+ this.http = new http_js_1.HttpClient({
18
+ baseUrl: config.baseUrl
19
+ ? config.baseUrl.replace(/\/$/, "")
20
+ : "https://qstash.upstash.io",
21
+ authorization: config.token,
22
+ });
23
+ }
24
+ /**
25
+ * Access the topic API.
26
+ *
27
+ * Create, read, update or delete topics.
28
+ */
29
+ get topics() {
30
+ return new topics_js_1.Topics(this.http);
31
+ }
32
+ /**
33
+ * Access the endpoint API.
34
+ *
35
+ * Create, read, update or delete endpoints.
36
+ */
37
+ get endpoints() {
38
+ return new endpoints_js_1.Endpoints(this.http);
39
+ }
40
+ /**
41
+ * Access the message API.
42
+ *
43
+ * Read or cancel messages.
44
+ */
45
+ get messages() {
46
+ return new messages_js_1.Messages(this.http);
47
+ }
48
+ /**
49
+ * Access the schedule API.
50
+ *
51
+ * Read or delete schedules.
52
+ */
53
+ get schedules() {
54
+ return new schedules_js_1.Schedules(this.http);
55
+ }
56
+ async publish(req) {
57
+ const destination = req.url ?? req.topic;
58
+ if (!destination) {
59
+ throw new Error("Either url or topic must be set");
60
+ }
61
+ const headers = new Headers(req.headers);
62
+ if (req.delay) {
63
+ headers.set("Upstash-Delay", req.delay.toFixed());
64
+ }
65
+ if (req.notBefore) {
66
+ headers.set("Upstash-Not-Before", req.notBefore.toFixed());
67
+ }
68
+ if (req.deduplicationId) {
69
+ headers.set("Upstash-Deduplication-Id", req.deduplicationId);
70
+ }
71
+ if (req.contentBasedDeduplication) {
72
+ headers.set("Upstash-Content-Based-Deduplication", "true");
73
+ }
74
+ if (req.retries) {
75
+ headers.set("Upstash-Retries", req.retries.toFixed());
76
+ }
77
+ if (req.cron) {
78
+ headers.set("Upstash-Cron", req.cron);
79
+ }
80
+ const res = await this.http.request({
81
+ path: ["v1", "publish", destination],
82
+ body: req.body,
83
+ headers,
84
+ method: "POST",
85
+ });
86
+ return res;
87
+ }
88
+ /**
89
+ * publishJSON is a utility wrapper around `publish` that automatically serializes the body
90
+ * and sets the `Content-Type` header to `application/json`.
91
+ */
92
+ async publishJSON(req) {
93
+ const headers = new Headers(req.headers);
94
+ headers.set("Content-Type", "application/json");
95
+ const res = await this.publish({
96
+ ...req,
97
+ headers,
98
+ body: JSON.stringify(req.body),
99
+ });
100
+ return res;
101
+ }
102
+ /**
103
+ * Retrieve your logs.
104
+ *
105
+ * The logs endpoint is paginated and returns only 100 logs at a time.
106
+ * If you want to receive more logs, you can use the cursor to paginate.
107
+ *
108
+ * The cursor is a unix timestamp with millisecond precision
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * let cursor = Date.now()
113
+ * const logs: Log[] = []
114
+ * while (cursor > 0) {
115
+ * const res = await qstash.logs({ cursor })
116
+ * logs.push(...res.logs)
117
+ * cursor = res.cursor ?? 0
118
+ * }
119
+ * ```
120
+ */
121
+ async logs(req) {
122
+ const query = {};
123
+ if (req?.cursor && req.cursor > 0) {
124
+ query["cursor"] = req.cursor;
125
+ }
126
+ const res = await this.http.request({
127
+ path: ["v1", "logs"],
128
+ method: "GET",
129
+ query,
130
+ });
131
+ return res;
132
+ }
133
+ }
134
+ exports.Client = Client;