@upstash/qstash 2.6.2 → 2.6.4-workflow-alpha.0

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/dist/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Upstash, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/README.md ADDED
@@ -0,0 +1,160 @@
1
+ # Upstash QStash SDK
2
+
3
+ ![npm (scoped)](https://img.shields.io/npm/v/@upstash/qstash)
4
+
5
+ > [!NOTE] > **This project is in GA Stage.**
6
+ > The Upstash Professional Support fully covers this project. It receives regular updates, and bug fixes.
7
+ > The Upstash team is committed to maintaining and improving its functionality.
8
+
9
+ **QStash** is an HTTP based messaging and scheduling solution for serverless and
10
+ edge runtimes.
11
+
12
+ It is 100% built on stateless HTTP requests and designed for:
13
+
14
+ - Serverless functions (AWS Lambda ...)
15
+ - Cloudflare Workers (see
16
+ [the example](https://github.com/upstash/sdk-qstash-ts/tree/main/examples/cloudflare-workers))
17
+ - Fastly Compute@Edge
18
+ - Next.js, including [edge](https://nextjs.org/docs/api-reference/edge-runtime)
19
+ - Deno
20
+ - Client side web/mobile applications
21
+ - WebAssembly
22
+ - and other environments where HTTP is preferred over TCP.
23
+
24
+ ## How does QStash work?
25
+
26
+ QStash is the message broker between your serverless apps. You send an HTTP
27
+ request to QStash, that includes a destination, a payload and optional settings.
28
+ We durably store your message and will deliver it to the destination API via
29
+ HTTP. In case the destination is not ready to receive the message, we will retry
30
+ the message later, to guarentee at-least-once delivery.
31
+
32
+ ## Quick Start
33
+
34
+ ### Install
35
+
36
+ #### npm
37
+
38
+ ```bash
39
+ npm install @upstash/qstash
40
+ ```
41
+
42
+ ### Get your authorization token
43
+
44
+ Go to [Upstash Console](https://console.upstash.com/qstash) and copy the QSTASH_TOKEN.
45
+
46
+ ## Basic Usage:
47
+
48
+ ### Publishing a message
49
+
50
+ ```ts
51
+ import { Client } from "@upstash/qstash";
52
+ /**
53
+ * Import a fetch polyfill only if you are using node prior to v18.
54
+ * This is not necessary for nextjs, deno or cloudflare workers.
55
+ */
56
+ import "isomorphic-fetch";
57
+
58
+ const c = new Client({
59
+ token: "<QSTASH_TOKEN>",
60
+ });
61
+
62
+ const res = await c.publishJSON({
63
+ url: "https://my-api...",
64
+ // or urlGroup: "the name or id of a url group"
65
+ body: {
66
+ hello: "world",
67
+ },
68
+ });
69
+ console.log(res);
70
+ // { messageId: "msg_xxxxxxxxxxxxxxxx" }
71
+ ```
72
+
73
+ ### Receiving a message
74
+
75
+ How to receive a message depends on your http server. The `Receiver.verify`
76
+ method should be called by you as the first step in your handler function.
77
+
78
+ ```ts
79
+ import { Receiver } from "@upstash/qstash";
80
+
81
+ const r = new Receiver({
82
+ currentSigningKey: "..",
83
+ nextSigningKey: "..",
84
+ });
85
+
86
+ const isValid = await r.verify({
87
+ /**
88
+ * The signature from the `Upstash-Signature` header.
89
+ *
90
+ * Please note that on some platforms (e.g. Vercel or Netlify) you might
91
+ * receive the header in lower case: `upstash-signature`
92
+ *
93
+ */
94
+ signature: "string";
95
+
96
+ /**
97
+ * The raw request body.
98
+ */
99
+ body: "string";
100
+ })
101
+ ```
102
+
103
+ ### Publishing a message to Open AI or any Open AI Compatible LLM
104
+
105
+ No need for complicated setup your LLM request. We'll call LLM and schedule it for your serverless needs.
106
+
107
+ ```ts
108
+ import { Client, openai } from "@upstash/qstash";
109
+
110
+ const c = new Client({
111
+ token: "<QSTASH_TOKEN>",
112
+ });
113
+
114
+ const result = await client.publishJSON({
115
+ api: { name: "llm", provider: openai({ token: process.env.OPENAI_API_KEY! }) },
116
+ body: {
117
+ model: "gpt-3.5-turbo",
118
+ messages: [
119
+ {
120
+ role: "user",
121
+ content: "Where is the capital of Turkey?",
122
+ },
123
+ ],
124
+ },
125
+ callback: "https://oz.requestcatcher.com/",
126
+ });
127
+ ```
128
+
129
+ ### Chatting with your favorite LLM
130
+
131
+ You can easily start streaming Upstash or OpenAI responses from your favorite framework(Next.js) or library
132
+
133
+ ```ts
134
+ import { upstash } from "@upstash/qstash";
135
+
136
+ const response = await client.chat().create({
137
+ provider: upstash(), // Optionally, provider: "custom({token: "XXX", baseUrl: "https://api.openai.com"})". This will allow you to call every OpenAI compatible API out there.
138
+ model: "meta-llama/Meta-Llama-3-8B-Instruct", // Optionally, model: "gpt-3.5-turbo",
139
+ messages: [
140
+ {
141
+ role: "system",
142
+ content: "from now on, foo is whale",
143
+ },
144
+ {
145
+ role: "user",
146
+ content: "what exactly is foo?",
147
+ },
148
+ ],
149
+ stream: true,
150
+ temperature: 0.5,
151
+ });
152
+ ```
153
+
154
+ ## Docs
155
+
156
+ See [the documentation](https://docs.upstash.com/qstash) for details.
157
+
158
+ ## Contributing
159
+
160
+ ### [Install Deno](https://deno.land/#installation)