@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
package/types/deps/deno.land/std@0.147.0/_wasm_crypto/lib/deno_std_wasm_crypto.generated.d.mts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the digest of the given `data` using the given hash `algorithm`.
|
|
3
|
+
*
|
|
4
|
+
* `length` will usually be left `undefined` to use the default length for
|
|
5
|
+
* the algorithm. For algorithms with variable-length output, it can be used
|
|
6
|
+
* to specify a non-negative integer number of bytes.
|
|
7
|
+
*
|
|
8
|
+
* An error will be thrown if `algorithm` is not a supported hash algorithm or
|
|
9
|
+
* `length` is not a supported length for the algorithm.
|
|
10
|
+
* @param {string} algorithm
|
|
11
|
+
* @param {Uint8Array} data
|
|
12
|
+
* @param {number | undefined} length
|
|
13
|
+
* @returns {Uint8Array}
|
|
14
|
+
*/
|
|
15
|
+
export function digest(algorithm: string, data: Uint8Array, length: number | undefined): Uint8Array;
|
|
16
|
+
/** Instantiates an instance of the Wasm module returning its functions.
|
|
17
|
+
* @remarks It is safe to call this multiple times and once successfully
|
|
18
|
+
* loaded it will always return a reference to the same object.
|
|
19
|
+
*/
|
|
20
|
+
export function instantiate(): {
|
|
21
|
+
digest: typeof digest;
|
|
22
|
+
DigestContext: typeof DigestContext;
|
|
23
|
+
};
|
|
24
|
+
/** Instantiates an instance of the Wasm module along with its exports.
|
|
25
|
+
* @remarks It is safe to call this multiple times and once successfully
|
|
26
|
+
* loaded it will always return a reference to the same object.
|
|
27
|
+
* @returns {{
|
|
28
|
+
* instance: WebAssembly.Instance;
|
|
29
|
+
* exports: { digest: typeof digest; DigestContext : typeof DigestContext }
|
|
30
|
+
* }}
|
|
31
|
+
*/
|
|
32
|
+
export function instantiateWithInstance(): {
|
|
33
|
+
instance: WebAssembly.Instance;
|
|
34
|
+
exports: {
|
|
35
|
+
digest: typeof digest;
|
|
36
|
+
DigestContext: typeof DigestContext;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
/** Gets if the Wasm module has been instantiated. */
|
|
40
|
+
export function isInstantiated(): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* A context for incrementally computing a digest using a given hash algorithm.
|
|
43
|
+
*/
|
|
44
|
+
export class DigestContext {
|
|
45
|
+
static __wrap(ptr: any): any;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a new context incrementally computing a digest using the given
|
|
48
|
+
* hash algorithm.
|
|
49
|
+
*
|
|
50
|
+
* An error will be thrown if `algorithm` is not a supported hash algorithm.
|
|
51
|
+
* @param {string} algorithm
|
|
52
|
+
*/
|
|
53
|
+
constructor(algorithm: string);
|
|
54
|
+
__destroy_into_raw(): number | undefined;
|
|
55
|
+
ptr: number | undefined;
|
|
56
|
+
free(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Update the digest's internal state with the additional input `data`.
|
|
59
|
+
*
|
|
60
|
+
* If the `data` array view is large, it will be split into subarrays (via
|
|
61
|
+
* JavaScript bindings) which will be processed sequentially in order to
|
|
62
|
+
* limit the amount of memory that needs to be allocated in the Wasm heap.
|
|
63
|
+
* @param {Uint8Array} data
|
|
64
|
+
*/
|
|
65
|
+
update(data: Uint8Array): void;
|
|
66
|
+
/**
|
|
67
|
+
* Returns the digest of the input data so far. This may be called repeatedly
|
|
68
|
+
* without side effects.
|
|
69
|
+
*
|
|
70
|
+
* `length` will usually be left `undefined` to use the default length for
|
|
71
|
+
* the algorithm. For algorithms with variable-length output, it can be used
|
|
72
|
+
* to specify a non-negative integer number of bytes.
|
|
73
|
+
*
|
|
74
|
+
* An error will be thrown if `algorithm` is not a supported hash algorithm or
|
|
75
|
+
* `length` is not a supported length for the algorithm.
|
|
76
|
+
* @param {number | undefined} length
|
|
77
|
+
* @returns {Uint8Array}
|
|
78
|
+
*/
|
|
79
|
+
digest(length: number | undefined): Uint8Array;
|
|
80
|
+
/**
|
|
81
|
+
* Returns the digest of the input data so far, and resets this context to
|
|
82
|
+
* its initial state, as though it has not yet been provided with any input
|
|
83
|
+
* data. (It will still use the same algorithm.)
|
|
84
|
+
*
|
|
85
|
+
* `length` will usually be left `undefined` to use the default length for
|
|
86
|
+
* the algorithm. For algorithms with variable-length output, it can be used
|
|
87
|
+
* to specify a non-negative integer number of bytes.
|
|
88
|
+
*
|
|
89
|
+
* An error will be thrown if `algorithm` is not a supported hash algorithm or
|
|
90
|
+
* `length` is not a supported length for the algorithm.
|
|
91
|
+
* @param {number | undefined} length
|
|
92
|
+
* @returns {Uint8Array}
|
|
93
|
+
*/
|
|
94
|
+
digestAndReset(length: number | undefined): Uint8Array;
|
|
95
|
+
/**
|
|
96
|
+
* Returns the digest of the input data so far, and then drops the context
|
|
97
|
+
* from memory on the Wasm side. This context must no longer be used, and any
|
|
98
|
+
* further method calls will result in null pointer errors being thrown.
|
|
99
|
+
* https://github.com/rustwasm/wasm-bindgen/blob/bf39cfd8/crates/backend/src/codegen.rs#L186
|
|
100
|
+
*
|
|
101
|
+
* `length` will usually be left `undefined` to use the default length for
|
|
102
|
+
* the algorithm. For algorithms with variable-length output, it can be used
|
|
103
|
+
* to specify a non-negative integer number of bytes.
|
|
104
|
+
*
|
|
105
|
+
* An error will be thrown if `algorithm` is not a supported hash algorithm or
|
|
106
|
+
* `length` is not a supported length for the algorithm.
|
|
107
|
+
* @param {number | undefined} length
|
|
108
|
+
* @returns {Uint8Array}
|
|
109
|
+
*/
|
|
110
|
+
digestAndDrop(length: number | undefined): Uint8Array;
|
|
111
|
+
/**
|
|
112
|
+
* Resets this context to its initial state, as though it has not yet been
|
|
113
|
+
* provided with any input data. (It will still use the same algorithm.)
|
|
114
|
+
*/
|
|
115
|
+
reset(): void;
|
|
116
|
+
/**
|
|
117
|
+
* Returns a new `DigestContext` that is a copy of this one, i.e., using the
|
|
118
|
+
* same algorithm and with a copy of the same internal state.
|
|
119
|
+
*
|
|
120
|
+
* This may be a more efficient option for computing multiple digests that
|
|
121
|
+
* start with a common prefix.
|
|
122
|
+
* @returns {DigestContext}
|
|
123
|
+
*/
|
|
124
|
+
clone(): DigestContext;
|
|
125
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { DigestContext, instantiate as instantiateWasm, } from "./lib/deno_std_wasm_crypto.generated.js";
|
|
2
|
+
/**
|
|
3
|
+
* All cryptographic hash/digest algorithms supported by std/_wasm_crypto.
|
|
4
|
+
*
|
|
5
|
+
* For algorithms that are supported by WebCrypto, the name here must match the
|
|
6
|
+
* one used by WebCrypto. Otherwise we should prefer the formatting used in the
|
|
7
|
+
* official specification. All names are uppercase to facilitate case-insensitive
|
|
8
|
+
* comparisons required by the WebCrypto spec.
|
|
9
|
+
*/
|
|
10
|
+
export declare const digestAlgorithms: readonly ["BLAKE2B-256", "BLAKE2B-384", "BLAKE2B", "BLAKE2S", "BLAKE3", "KECCAK-224", "KECCAK-256", "KECCAK-384", "KECCAK-512", "SHA-384", "SHA3-224", "SHA3-256", "SHA3-384", "SHA3-512", "SHAKE128", "SHAKE256", "TIGER", "RIPEMD-160", "SHA-224", "SHA-256", "SHA-512", "MD4", "MD5", "SHA-1"];
|
|
11
|
+
/** An algorithm name supported by std/_wasm_crypto. */
|
|
12
|
+
export declare type DigestAlgorithm = typeof digestAlgorithms[number];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const fnv: (name: string, buf: Uint8Array | undefined) => ArrayBuffer;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function swap32(val: number): number;
|
|
2
|
+
/**
|
|
3
|
+
* mul32 performs 32-bit multiplication, a * b
|
|
4
|
+
* @param a
|
|
5
|
+
* @param b
|
|
6
|
+
*/
|
|
7
|
+
export declare function mul32(a: number, b: number): number;
|
|
8
|
+
/**
|
|
9
|
+
* mul64 performs 64-bit multiplication with two 32-bit words
|
|
10
|
+
* @param [ah, al]
|
|
11
|
+
* @param [bh, bl]
|
|
12
|
+
*/
|
|
13
|
+
export declare function mul64([ah, al]: [number, number], [bh, bl]: [number, number]): [number, number];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as dntShim from "../../../../_dnt.shims.js";
|
|
2
|
+
import { DigestAlgorithm as WasmDigestAlgorithm } from "../_wasm_crypto/mod.js";
|
|
3
|
+
/**
|
|
4
|
+
* An wrapper for WebCrypto adding support for additional non-standard
|
|
5
|
+
* algorithms, but delegating to the runtime WebCrypto implementation whenever
|
|
6
|
+
* possible.
|
|
7
|
+
*/
|
|
8
|
+
declare const stdCrypto: {
|
|
9
|
+
subtle: {
|
|
10
|
+
/**
|
|
11
|
+
* Returns a new `Promise` object that will digest `data` using the specified
|
|
12
|
+
* `AlgorithmIdentifier`.
|
|
13
|
+
*/
|
|
14
|
+
digest(algorithm: DigestAlgorithm, data: dntShim.BufferSource | AsyncIterable<dntShim.BufferSource> | Iterable<dntShim.BufferSource>): Promise<ArrayBuffer>;
|
|
15
|
+
/**
|
|
16
|
+
* Returns a ArrayBuffer with the result of digesting `data` using the
|
|
17
|
+
* specified `AlgorithmIdentifier`.
|
|
18
|
+
*/
|
|
19
|
+
digestSync(algorithm: DigestAlgorithm, data: dntShim.BufferSource | Iterable<dntShim.BufferSource>): ArrayBuffer;
|
|
20
|
+
decrypt: (algorithm: dntShim.AlgorithmIdentifier | dntShim.RsaOaepParams | dntShim.AesCtrParams | dntShim.AesCbcParams | dntShim.AesGcmParams, key: dntShim.CryptoKey, data: dntShim.BufferSource) => Promise<any>;
|
|
21
|
+
deriveBits: (algorithm: dntShim.AlgorithmIdentifier | dntShim.EcdhKeyDeriveParams | dntShim.HkdfParams | dntShim.Pbkdf2Params, baseKey: dntShim.CryptoKey, length: number) => Promise<ArrayBuffer>;
|
|
22
|
+
deriveKey: (algorithm: dntShim.AlgorithmIdentifier | dntShim.EcdhKeyDeriveParams | dntShim.HkdfParams | dntShim.Pbkdf2Params, baseKey: dntShim.CryptoKey, derivedKeyType: dntShim.AlgorithmIdentifier | dntShim.HkdfParams | dntShim.Pbkdf2Params | dntShim.AesDerivedKeyParams | dntShim.HmacImportParams, extractable: boolean, keyUsages: dntShim.KeyUsage[]) => Promise<dntShim.CryptoKey>;
|
|
23
|
+
encrypt: (algorithm: dntShim.AlgorithmIdentifier | dntShim.RsaOaepParams | dntShim.AesCtrParams | dntShim.AesCbcParams | dntShim.AesGcmParams, key: dntShim.CryptoKey, data: dntShim.BufferSource) => Promise<any>;
|
|
24
|
+
exportKey: {
|
|
25
|
+
(format: "jwk", key: dntShim.CryptoKey): Promise<dntShim.JsonWebKey>;
|
|
26
|
+
(format: "pkcs8" | "raw" | "spki", key: dntShim.CryptoKey): Promise<ArrayBuffer>;
|
|
27
|
+
};
|
|
28
|
+
generateKey: {
|
|
29
|
+
(algorithm: dntShim.RsaHashedKeyGenParams | dntShim.EcKeyGenParams, extractable: boolean, keyUsages: readonly dntShim.KeyUsage[]): Promise<dntShim.CryptoKeyPair>;
|
|
30
|
+
(algorithm: dntShim.Pbkdf2Params | dntShim.AesKeyGenParams | dntShim.HmacKeyGenParams, extractable: boolean, keyUsages: readonly dntShim.KeyUsage[]): Promise<dntShim.CryptoKey>;
|
|
31
|
+
(algorithm: dntShim.AlgorithmIdentifier, extractable: boolean, keyUsages: dntShim.KeyUsage[]): Promise<dntShim.CryptoKey | dntShim.CryptoKeyPair>;
|
|
32
|
+
};
|
|
33
|
+
importKey: {
|
|
34
|
+
(format: "jwk", keyData: dntShim.JsonWebKey, algorithm: dntShim.AlgorithmIdentifier | dntShim.HmacImportParams | dntShim.RsaHashedImportParams | dntShim.EcKeyImportParams | dntShim.AesKeyAlgorithm, extractable: boolean, keyUsages: readonly dntShim.KeyUsage[]): Promise<dntShim.CryptoKey>;
|
|
35
|
+
(format: "pkcs8" | "raw" | "spki", keyData: dntShim.BufferSource, algorithm: dntShim.AlgorithmIdentifier | dntShim.HmacImportParams | dntShim.RsaHashedImportParams | dntShim.EcKeyImportParams | dntShim.AesKeyAlgorithm, extractable: boolean, keyUsages: dntShim.KeyUsage[]): Promise<dntShim.CryptoKey>;
|
|
36
|
+
};
|
|
37
|
+
sign: (algorithm: dntShim.AlgorithmIdentifier | dntShim.RsaPssParams | dntShim.EcdsaParams, key: dntShim.CryptoKey, data: dntShim.BufferSource) => Promise<ArrayBuffer>;
|
|
38
|
+
unwrapKey: (format: dntShim.KeyFormat, wrappedKey: dntShim.BufferSource, unwrappingKey: dntShim.CryptoKey, unwrapAlgorithm: dntShim.AlgorithmIdentifier | dntShim.RsaOaepParams | dntShim.AesCtrParams | dntShim.AesCbcParams | dntShim.AesGcmParams, unwrappedKeyAlgorithm: dntShim.AlgorithmIdentifier | dntShim.HmacImportParams | dntShim.RsaHashedImportParams | dntShim.EcKeyImportParams | dntShim.AesKeyAlgorithm, extractable: boolean, keyUsages: dntShim.KeyUsage[]) => Promise<dntShim.CryptoKey>;
|
|
39
|
+
verify: (algorithm: dntShim.AlgorithmIdentifier | dntShim.RsaPssParams | dntShim.EcdsaParams, key: dntShim.CryptoKey, signature: dntShim.BufferSource, data: dntShim.BufferSource) => Promise<boolean>;
|
|
40
|
+
wrapKey: (format: dntShim.KeyFormat, key: dntShim.CryptoKey, wrappingKey: dntShim.CryptoKey, wrapAlgorithm: dntShim.AlgorithmIdentifier | dntShim.RsaOaepParams | dntShim.AesCtrParams | dntShim.AesCbcParams | dntShim.AesGcmParams) => Promise<ArrayBuffer>;
|
|
41
|
+
};
|
|
42
|
+
getRandomValues: <T extends ArrayBufferView | null>(array: T) => T;
|
|
43
|
+
randomUUID: () => string;
|
|
44
|
+
};
|
|
45
|
+
declare const FNVAlgorithms: string[];
|
|
46
|
+
declare type FNVAlgorithms = "FNV32" | "FNV32A" | "FNV64" | "FNV64A";
|
|
47
|
+
declare type DigestAlgorithmName = WasmDigestAlgorithm | FNVAlgorithms;
|
|
48
|
+
declare type DigestAlgorithmObject = {
|
|
49
|
+
name: DigestAlgorithmName;
|
|
50
|
+
length?: number;
|
|
51
|
+
};
|
|
52
|
+
declare type DigestAlgorithm = DigestAlgorithmName | DigestAlgorithmObject;
|
|
53
|
+
export { stdCrypto as crypto };
|
|
File without changes
|
package/types/deps.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as base64Url from "./deps/deno.land/std@0.147.0/encoding/base64url.js";
|
|
@@ -2,5 +2,11 @@ import type { NextApiHandler } from "next";
|
|
|
2
2
|
export declare type VerifySignaturConfig = {
|
|
3
3
|
currentSigningKey?: string;
|
|
4
4
|
nextSigningKey?: string;
|
|
5
|
+
/**
|
|
6
|
+
* The url of this api route, including the protocol.
|
|
7
|
+
*
|
|
8
|
+
* If you omit this, the url will be automatically determined by checking the `VERCEL_URL` env variable and assuming `https`
|
|
9
|
+
*/
|
|
10
|
+
url?: string;
|
|
5
11
|
};
|
|
6
12
|
export declare function verifySignature(handler: NextApiHandler, config?: VerifySignaturConfig): NextApiHandler;
|
|
@@ -0,0 +1,193 @@
|
|
|
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
|
+
import type { BodyInit, HeadersInit } from "../../deps/raw.githubusercontent.com/microsoft/TypeScript/main/lib/lib.dom";
|
|
8
|
+
export declare type ClientConfig = {
|
|
9
|
+
/**
|
|
10
|
+
* Url of the qstash api server.
|
|
11
|
+
*
|
|
12
|
+
* This is only used for testing.
|
|
13
|
+
*
|
|
14
|
+
* @default "https://qstash.upstash.io"
|
|
15
|
+
*/
|
|
16
|
+
baseUrl?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The authorization token from the upstash console.
|
|
19
|
+
*/
|
|
20
|
+
token: string;
|
|
21
|
+
};
|
|
22
|
+
declare type Destination = {
|
|
23
|
+
/**
|
|
24
|
+
* The url of a publicly accessible server where you want to send this message to.
|
|
25
|
+
* The url must have a valid scheme (http or https).
|
|
26
|
+
*/
|
|
27
|
+
url: string;
|
|
28
|
+
topic?: never;
|
|
29
|
+
} | {
|
|
30
|
+
url?: never;
|
|
31
|
+
/**
|
|
32
|
+
* Either the name or id of a topic to send this message to.
|
|
33
|
+
*/
|
|
34
|
+
topic: string;
|
|
35
|
+
};
|
|
36
|
+
export declare type PublishRequest = Destination & {
|
|
37
|
+
/**
|
|
38
|
+
* The message to send.
|
|
39
|
+
*
|
|
40
|
+
* This can be anything, but please set the `Content-Type` header accordingly.
|
|
41
|
+
*
|
|
42
|
+
* You can leave this empty if you want to send a message with no body.
|
|
43
|
+
*/
|
|
44
|
+
body?: BodyInit;
|
|
45
|
+
/**
|
|
46
|
+
* Optionally send along headers with the message.
|
|
47
|
+
* These headers will be sent to your destination.
|
|
48
|
+
*
|
|
49
|
+
* We highly recommend sending a `Content-Type` header along, as this will help your destination
|
|
50
|
+
* server to understand the content of the message.
|
|
51
|
+
*/
|
|
52
|
+
headers?: HeadersInit;
|
|
53
|
+
/**
|
|
54
|
+
* Optionally delay the delivery of this message.
|
|
55
|
+
*
|
|
56
|
+
* In seconds.
|
|
57
|
+
*
|
|
58
|
+
* @default undefined
|
|
59
|
+
*/
|
|
60
|
+
delay?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Optionally set the absolute delay of this message.
|
|
63
|
+
* This will override the delay option.
|
|
64
|
+
* The message will not delivered until the specified time.
|
|
65
|
+
*
|
|
66
|
+
* Unix timestamp in seconds.
|
|
67
|
+
*
|
|
68
|
+
* @default undefined
|
|
69
|
+
*/
|
|
70
|
+
notBefore?: number;
|
|
71
|
+
/**
|
|
72
|
+
* Provide a unique id for deduplication. This id will be used to detect duplicate messages.
|
|
73
|
+
* If a duplicate message is detected, the request will be accepted but not enqueued.
|
|
74
|
+
*
|
|
75
|
+
* We store deduplication ids for 90 days. Afterwards it is possible that the message with the
|
|
76
|
+
* same deduplication id is delivered again.
|
|
77
|
+
*
|
|
78
|
+
* When scheduling a message, the deduplication happens before the schedule is created.
|
|
79
|
+
*
|
|
80
|
+
* @default undefined
|
|
81
|
+
*/
|
|
82
|
+
deduplicationId?: string;
|
|
83
|
+
/**
|
|
84
|
+
* If true, the message content will get hashed and used as deduplication id.
|
|
85
|
+
* If a duplicate message is detected, the request will be accepted but not enqueued.
|
|
86
|
+
*
|
|
87
|
+
* The content based hash includes the following values:
|
|
88
|
+
* - All headers, except Upstash-Authorization, this includes all headers you are sending.
|
|
89
|
+
* - The entire raw request body The destination from the url path
|
|
90
|
+
*
|
|
91
|
+
* We store deduplication ids for 90 days. Afterwards it is possible that the message with the
|
|
92
|
+
* same deduplication id is delivered again.
|
|
93
|
+
*
|
|
94
|
+
* When scheduling a message, the deduplication happens before the schedule is created.
|
|
95
|
+
*
|
|
96
|
+
* @default false
|
|
97
|
+
*/
|
|
98
|
+
contentBasedDeduplication?: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* In case your destination server is unavaialble or returns a status code outside of the 200-299
|
|
101
|
+
* range, we will retry the request after a certain amount of time.
|
|
102
|
+
*
|
|
103
|
+
* Configure how many times you would like the delivery to be retried
|
|
104
|
+
*
|
|
105
|
+
* @default The maximum retry quota associated with your account.
|
|
106
|
+
*/
|
|
107
|
+
retries?: number;
|
|
108
|
+
} & ({
|
|
109
|
+
/**
|
|
110
|
+
* Optionally specify a cron expression to repeatedly send this message to the destination.
|
|
111
|
+
*
|
|
112
|
+
* @default undefined
|
|
113
|
+
*/
|
|
114
|
+
cron: string;
|
|
115
|
+
} | {
|
|
116
|
+
cron?: never;
|
|
117
|
+
});
|
|
118
|
+
export declare type PublishJsonRequest = Omit<PublishRequest, "body"> & {
|
|
119
|
+
/**
|
|
120
|
+
* The message to send.
|
|
121
|
+
* This can be anything as long as it can be serialized to JSON.
|
|
122
|
+
*/
|
|
123
|
+
body: unknown;
|
|
124
|
+
};
|
|
125
|
+
export declare type LogsRequest = {
|
|
126
|
+
cursor?: number;
|
|
127
|
+
};
|
|
128
|
+
export declare type GetLogsRespone = {
|
|
129
|
+
cursor?: number;
|
|
130
|
+
logs: Log[];
|
|
131
|
+
};
|
|
132
|
+
export declare class Client {
|
|
133
|
+
http: Requester;
|
|
134
|
+
constructor(config: ClientConfig);
|
|
135
|
+
/**
|
|
136
|
+
* Access the topic API.
|
|
137
|
+
*
|
|
138
|
+
* Create, read, update or delete topics.
|
|
139
|
+
*/
|
|
140
|
+
get topics(): Topics;
|
|
141
|
+
/**
|
|
142
|
+
* Access the endpoint API.
|
|
143
|
+
*
|
|
144
|
+
* Create, read, update or delete endpoints.
|
|
145
|
+
*/
|
|
146
|
+
get endpoints(): Endpoints;
|
|
147
|
+
/**
|
|
148
|
+
* Access the message API.
|
|
149
|
+
*
|
|
150
|
+
* Read or cancel messages.
|
|
151
|
+
*/
|
|
152
|
+
get messages(): Messages;
|
|
153
|
+
/**
|
|
154
|
+
* Access the schedule API.
|
|
155
|
+
*
|
|
156
|
+
* Read or delete schedules.
|
|
157
|
+
*/
|
|
158
|
+
get schedules(): Schedules;
|
|
159
|
+
publish<R extends PublishRequest>(req: R): Promise<PublishResponse<R>>;
|
|
160
|
+
/**
|
|
161
|
+
* publishJSON is a utility wrapper around `publish` that automatically serializes the body
|
|
162
|
+
* and sets the `Content-Type` header to `application/json`.
|
|
163
|
+
*/
|
|
164
|
+
publishJSON<R extends PublishJsonRequest = PublishJsonRequest>(req: R): Promise<PublishResponse<R>>;
|
|
165
|
+
/**
|
|
166
|
+
* Retrieve your logs.
|
|
167
|
+
*
|
|
168
|
+
* The logs endpoint is paginated and returns only 100 logs at a time.
|
|
169
|
+
* If you want to receive more logs, you can use the cursor to paginate.
|
|
170
|
+
*
|
|
171
|
+
* The cursor is a unix timestamp with millisecond precision
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* let cursor = Date.now()
|
|
176
|
+
* const logs: Log[] = []
|
|
177
|
+
* while (cursor > 0) {
|
|
178
|
+
* const res = await qstash.logs({ cursor })
|
|
179
|
+
* logs.push(...res.logs)
|
|
180
|
+
* cursor = res.cursor ?? 0
|
|
181
|
+
* }
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
logs(req?: LogsRequest): Promise<GetLogsRespone>;
|
|
185
|
+
}
|
|
186
|
+
declare type PublishResponse<PublishRequest> = PublishRequest extends {
|
|
187
|
+
cron: string;
|
|
188
|
+
} ? {
|
|
189
|
+
scheduleId: string;
|
|
190
|
+
} : {
|
|
191
|
+
messageId: string;
|
|
192
|
+
};
|
|
193
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { BodyInit, HeadersInit } from "../../deps/raw.githubusercontent.com/microsoft/TypeScript/main/lib/lib.dom";
|
|
2
|
+
export declare type UpstashRequest = {
|
|
3
|
+
/**
|
|
4
|
+
* The path to the resource.
|
|
5
|
+
*/
|
|
6
|
+
path: string[];
|
|
7
|
+
/**
|
|
8
|
+
* A BodyInit object or null to set request's body.
|
|
9
|
+
*/
|
|
10
|
+
body?: BodyInit | null;
|
|
11
|
+
/**
|
|
12
|
+
* A Headers object, an object literal, or an array of two-item arrays to set
|
|
13
|
+
* request's headers.
|
|
14
|
+
*/
|
|
15
|
+
headers?: HeadersInit;
|
|
16
|
+
/**
|
|
17
|
+
* A boolean to set request's keepalive.
|
|
18
|
+
*/
|
|
19
|
+
keepalive?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* A string to set request's method.
|
|
22
|
+
*/
|
|
23
|
+
method?: "GET" | "POST" | "PUT" | "DELETE";
|
|
24
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
25
|
+
};
|
|
26
|
+
export declare type UpstashResponse<TResult> = TResult & {
|
|
27
|
+
error?: string;
|
|
28
|
+
};
|
|
29
|
+
export interface Requester {
|
|
30
|
+
request: <TResult = unknown>(req: UpstashRequest) => Promise<UpstashResponse<TResult>>;
|
|
31
|
+
}
|
|
32
|
+
export declare type RetryConfig = false | {
|
|
33
|
+
/**
|
|
34
|
+
* The number of retries to attempt before giving up.
|
|
35
|
+
*
|
|
36
|
+
* @default 5
|
|
37
|
+
*/
|
|
38
|
+
retries?: number;
|
|
39
|
+
/**
|
|
40
|
+
* A backoff function receives the current retry cound and returns a number in milliseconds to wait before retrying.
|
|
41
|
+
*
|
|
42
|
+
* @default
|
|
43
|
+
* ```ts
|
|
44
|
+
* Math.exp(retryCount) * 50
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
backoff?: (retryCount: number) => number;
|
|
48
|
+
};
|
|
49
|
+
export declare type HttpClientConfig = {
|
|
50
|
+
baseUrl: string;
|
|
51
|
+
authorization: string;
|
|
52
|
+
retry?: RetryConfig;
|
|
53
|
+
};
|
|
54
|
+
export declare class HttpClient implements Requester {
|
|
55
|
+
readonly baseUrl: string;
|
|
56
|
+
readonly authorization: string;
|
|
57
|
+
readonly options?: {
|
|
58
|
+
backend?: string;
|
|
59
|
+
};
|
|
60
|
+
readonly retry: {
|
|
61
|
+
attempts: number;
|
|
62
|
+
backoff: (retryCount: number) => number;
|
|
63
|
+
};
|
|
64
|
+
constructor(config: HttpClientConfig);
|
|
65
|
+
request<TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>>;
|
|
66
|
+
}
|
|
@@ -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
|
+
messaged: string;
|
|
11
|
+
header: Record<string, string[]>;
|
|
12
|
+
body: string;
|
|
13
|
+
} & ({
|
|
14
|
+
url: string;
|
|
15
|
+
topicd?: 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
|
+
}
|