@zerodot/convex 1.0.0 → 1.0.1

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 CHANGED
@@ -1,23 +1,63 @@
1
1
  # @zerodot/convex
2
2
 
3
- Run queries, mutations, and actions in [Convex](https://www.convex.dev/).
3
+ <img src="https://raw.githubusercontent.com/zerodot-io/nodes/main/packages/convex/convex.svg" alt="Convex logo" width="48" height="48">
4
4
 
5
- ## Credential
5
+ Run queries, mutations, and actions in Convex. The node calls a Convex deployment by function path. It can pass JSON arguments and return the value that the function returns.
6
6
 
7
- Create a **Convex connection** credential:
7
+ ## Install
8
8
 
9
- - **Deployment URL**: Your Convex deployment URL, such as `https://happy-animal-123.convex.cloud`.
10
- - **Auth Type**: `None` for public functions, or `Bearer token` for functions that require a user token.
11
- - **Token**: A user token when using bearer authentication.
9
+ In zerodot, go to **System > Nodes** and install **Convex**.
12
10
 
13
- ## Node
11
+ Manual: install `@zerodot/convex` where the web app and the worker run, and add it to `ZERODOT_NODE_PACKAGES`.
14
12
 
15
- ### Convex
13
+ ## Nodes
16
14
 
17
- Run a Convex function by module path.
15
+ ### Convex (`convex.api`)
18
16
 
19
- - **Run Query**: Calls `/api/query`.
20
- - **Run Mutation**: Calls `/api/mutation`.
21
- - **Run Action**: Calls `/api/action`.
17
+ - **Function**: run query, run mutation, run action
22
18
 
23
- Provide the function path as `module:function`, for example `messages:list`, and optional JSON args.
19
+ **Function Path.** The path of the function, in the form `module:function`, for example `messages:list`. The field is required.
20
+
21
+ **Arguments.** A JSON object with the arguments of the function. It can be an object or a JSON string. An empty value means no arguments. A value that is not a JSON object fails the run.
22
+
23
+ **Run Query.** Calls `POST {deployment URL}/api/query`.
24
+
25
+ **Run Mutation.** Calls `POST {deployment URL}/api/mutation`.
26
+
27
+ **Run Action.** Calls `POST {deployment URL}/api/action`.
28
+
29
+ Each call sends the path, the arguments, and `format: "json"` in the body.
30
+
31
+ **Output.** The output is the value that the function returns. The node does not return binary data.
32
+
33
+ ## Behavior notes
34
+
35
+ - **Required fields.** Function Path is required. Bearer auth needs a token in the credential.
36
+ - **Errors.** When the function fails, the run fails. The error names the function, the HTTP status, and Convex's message. It adds a short hint for statuses 400, 401, 403, 404, 429, and 500. The error keeps the `errorData` of the function. The token never appears in an error.
37
+ - **Redirects.** The node does not follow redirects.
38
+ - **Retries.** The node does not retry.
39
+ - **Timeout.** Each run has a timeout of 30 seconds by default. The maximum is 300 seconds.
40
+ - **Binary data.** The node has no binary input or output.
41
+
42
+ ## Credentials
43
+
44
+ ### Convex connection (`convex.connection`)
45
+
46
+ - **Deployment URL** (`deploymentUrl`): The Convex deployment URL, such as `https://happy-animal-123.convex.cloud`. It must use `http` or `https`. A trailing slash, a trailing `/api`, a query, and a hash are removed. Any other path is kept, so a URL such as `https://convex.example.com/prefix` sends calls to `https://convex.example.com/prefix/api/...`. Not secret.
47
+ - **Auth Type** (`authType`): `None` (default) or `Bearer token`. Not secret.
48
+ - **Token** (`token`): A user token, sent as `Authorization: Bearer <token>`. Used only when Auth Type is `Bearer token`. Secret.
49
+
50
+ The credential has no scope setting. Use `None` for public functions. Use `Bearer token` for functions that need a user token.
51
+
52
+ The credential test calls a query named `__zerodot_connectivity_test__:ping`. The function does not exist. The test passes when the deployment answers with a function error, because that shows the deployment is reachable. Other errors fail the test.
53
+
54
+ Setup:
55
+
56
+ 1. Copy the deployment URL of your Convex deployment.
57
+ 2. If your functions need a user token, get a token for the user.
58
+ 3. In zerodot, create a **Convex connection** credential.
59
+ 4. Enter the deployment URL. Set Auth Type. For a bearer token, enter the token. Save the credential.
60
+
61
+ ## License
62
+
63
+ AGPL-3.0-only
package/dist/index.cjs CHANGED
@@ -38,7 +38,8 @@ function normalizeDeploymentUrl(raw) {
38
38
  throw new Error("The Convex credential \"deploymentUrl\" is not a valid URL");
39
39
  }
40
40
  if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error("The Convex credential \"deploymentUrl\" must use http or https");
41
- return parsed.toString().replace(/\/+$/, "");
41
+ const path = parsed.pathname.replace(/\/+$/, "").replace(/\/api$/, "");
42
+ return `${parsed.origin}${path}`;
42
43
  }
43
44
  /** The deployment URL and auth settings from a credential. */
44
45
  function convexAccess(credential) {
@@ -96,7 +97,7 @@ function convexErrorOf(label, status, answer, errorData) {
96
97
  async function callConvex(access, kind, path, args, options) {
97
98
  const fnPath = path.trim();
98
99
  if (!fnPath) throw new Error("Convex function path is required");
99
- const url = new URL(`/api/${kind}`, access.deploymentUrl);
100
+ const url = `${access.deploymentUrl}/api/${kind}`;
100
101
  const headers = {
101
102
  accept: "application/json",
102
103
  "content-type": "application/json",
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@zerodot/convex",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Run queries, mutations, and actions in Convex.",
5
5
  "license": "AGPL-3.0-only",
6
+ "homepage": "https://github.com/zerodot-io/nodes/tree/main/packages/convex",
6
7
  "repository": {
7
8
  "type": "git",
8
9
  "url": "git+https://github.com/zerodot-io/nodes.git",