@automate.ax/integration-contracts 0.83.0 → 0.83.2

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.
@@ -8,7 +8,7 @@ export declare const CONVEX_SECRET_SCHEMA: z.ZodUnion<readonly [z.ZodObject<{
8
8
  }, z.core.$strip>, z.ZodObject<{
9
9
  deployKey: z.ZodString;
10
10
  deploymentUrl: z.ZodURL;
11
- webhookSecret: z.ZodString;
11
+ webhookSecret: z.ZodOptional<z.ZodString>;
12
12
  }, z.core.$strip>]>;
13
13
  export interface ConvexDeployment {
14
14
  deploymentUrl: string;
@@ -1,4 +1,4 @@
1
- import { convexToJson, jsonToConvex } from "convex/values";
1
+ import { ConvexError, convexToJson, jsonToConvex } from "convex/values";
2
2
  import * as z from "zod";
3
3
  import { CONVEX_VALUE_SCHEMA } from "./schemas.js";
4
4
  const CONVEX_OAUTH_SECRET_SCHEMA = z.object({
@@ -21,21 +21,31 @@ export const CONVEX_DEPLOYMENT_URL_SCHEMA = z.url().refine((value) => {
21
21
  const CONVEX_DEPLOY_KEY_SECRET_SCHEMA = z.object({
22
22
  deployKey: z.string(),
23
23
  deploymentUrl: CONVEX_DEPLOYMENT_URL_SCHEMA,
24
- webhookSecret: z.string(),
24
+ webhookSecret: z.string().min(32).optional(),
25
25
  });
26
26
  export const CONVEX_SECRET_SCHEMA = z.union([
27
27
  CONVEX_OAUTH_SECRET_SCHEMA,
28
28
  CONVEX_DEPLOY_KEY_SECRET_SCHEMA,
29
29
  ]);
30
- const CONVEX_DEPLOYMENT_SCHEMA = z.object({
31
- deploymentUrl: CONVEX_DEPLOYMENT_URL_SCHEMA,
32
- name: z.string(),
33
- reference: z.string(),
34
- });
30
+ const CONVEX_DEPLOYMENT_SCHEMA = z.discriminatedUnion("kind", [
31
+ z.object({
32
+ deploymentUrl: CONVEX_DEPLOYMENT_URL_SCHEMA,
33
+ kind: z.literal("cloud"),
34
+ name: z.string(),
35
+ reference: z.string(),
36
+ }),
37
+ z.object({ kind: z.literal("local"), name: z.string() }),
38
+ ]);
39
+ const CONVEX_PLATFORM_ID_SCHEMA = z
40
+ .number()
41
+ .int()
42
+ .nonnegative()
43
+ .max(Number.MAX_SAFE_INTEGER)
44
+ .transform(String);
35
45
  const CONVEX_DEPLOYMENT_INFO_SCHEMA = z.discriminatedUnion("kind", [
36
46
  z.object({
37
47
  kind: z.literal("cloud"),
38
- projectId: z.string(),
48
+ projectId: CONVEX_PLATFORM_ID_SCHEMA,
39
49
  projectName: z.string().nullable().optional(),
40
50
  reference: z.string().nullable().optional(),
41
51
  }),
@@ -43,7 +53,11 @@ const CONVEX_DEPLOYMENT_INFO_SCHEMA = z.discriminatedUnion("kind", [
43
53
  ]);
44
54
  const CONVEX_FUNCTION_RESPONSE_SCHEMA = z.discriminatedUnion("status", [
45
55
  z.object({ status: z.literal("success"), value: z.json() }),
46
- z.object({ errorMessage: z.string(), status: z.literal("error") }),
56
+ z.object({
57
+ errorData: z.json().optional(),
58
+ errorMessage: z.string(),
59
+ status: z.literal("error"),
60
+ }),
47
61
  ]);
48
62
  /**
49
63
  * Resolves the authenticated Convex deployment represented by an account.
@@ -72,6 +86,9 @@ export async function resolveConvexDeployment(secret, deployment = "prod") {
72
86
  throw new Error(`Convex could not resolve deployment ${deployment} (${response.status}).`);
73
87
  }
74
88
  const resolved = CONVEX_DEPLOYMENT_SCHEMA.parse(await response.json());
89
+ if (resolved.kind === "local") {
90
+ throw new Error(`Convex deployment ${deployment} is local and cannot be reached by Automate.ax.`);
91
+ }
75
92
  return {
76
93
  deploymentUrl: resolved.deploymentUrl,
77
94
  reference: resolved.reference,
@@ -156,8 +173,14 @@ async function requestConvexFunction(kind, deployment, functionName, arguments_
156
173
  throw new Error(`Convex function call failed (${response.status})${details ? `: ${details}` : "."}`);
157
174
  }
158
175
  const result = CONVEX_FUNCTION_RESPONSE_SCHEMA.parse(await response.json());
159
- if (result.status === "error")
176
+ if (result.status === "error") {
177
+ if (result.errorData !== undefined) {
178
+ const error = new ConvexError(decodeConvexValue(result.errorData));
179
+ error.message = result.errorMessage;
180
+ throw error;
181
+ }
160
182
  throw new Error(result.errorMessage);
183
+ }
161
184
  return decodeConvexValue(result.value);
162
185
  }
163
186
  /**
@@ -1,9 +1,10 @@
1
1
  import * as z from "zod";
2
+ const CONVEX_NUMBER_SCHEMA = z.custom((value) => typeof value === "number", "Expected a Convex number.");
2
3
  /** Recursive schema for values accepted and returned by Convex functions. */
3
4
  export const CONVEX_VALUE_SCHEMA = z.lazy(() => z.union([
4
5
  z.null(),
5
6
  z.boolean(),
6
- z.number(),
7
+ CONVEX_NUMBER_SCHEMA,
7
8
  z.bigint(),
8
9
  z.string(),
9
10
  z.instanceof(ArrayBuffer),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automate.ax/integration-contracts",
3
- "version": "0.83.0",
3
+ "version": "0.83.2",
4
4
  "description": "Shared integration payload contracts and provider primitives for Automate.ax.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -43,7 +43,7 @@
43
43
  }
44
44
  },
45
45
  "dependencies": {
46
- "@automate.ax/codec": "0.83.0",
46
+ "@automate.ax/codec": "0.83.2",
47
47
  "@googleapis/calendar": "^15.0.0",
48
48
  "@googleapis/forms": "^6.0.1",
49
49
  "@googleapis/gmail": "^12.0.0",
package/src/convex/api.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { convexToJson, jsonToConvex } from "convex/values"
1
+ import { ConvexError, convexToJson, jsonToConvex } from "convex/values"
2
2
  import type { JSONValue } from "convex/values"
3
3
  import * as z from "zod"
4
4
  import { CONVEX_VALUE_SCHEMA, type ConvexValue } from "./schemas"
@@ -24,22 +24,32 @@ export const CONVEX_DEPLOYMENT_URL_SCHEMA = z.url().refine((value) => {
24
24
  const CONVEX_DEPLOY_KEY_SECRET_SCHEMA = z.object({
25
25
  deployKey: z.string(),
26
26
  deploymentUrl: CONVEX_DEPLOYMENT_URL_SCHEMA,
27
- webhookSecret: z.string(),
27
+ webhookSecret: z.string().min(32).optional(),
28
28
  })
29
29
  export const CONVEX_SECRET_SCHEMA = z.union([
30
30
  CONVEX_OAUTH_SECRET_SCHEMA,
31
31
  CONVEX_DEPLOY_KEY_SECRET_SCHEMA,
32
32
  ])
33
33
 
34
- const CONVEX_DEPLOYMENT_SCHEMA = z.object({
35
- deploymentUrl: CONVEX_DEPLOYMENT_URL_SCHEMA,
36
- name: z.string(),
37
- reference: z.string(),
38
- })
34
+ const CONVEX_DEPLOYMENT_SCHEMA = z.discriminatedUnion("kind", [
35
+ z.object({
36
+ deploymentUrl: CONVEX_DEPLOYMENT_URL_SCHEMA,
37
+ kind: z.literal("cloud"),
38
+ name: z.string(),
39
+ reference: z.string(),
40
+ }),
41
+ z.object({ kind: z.literal("local"), name: z.string() }),
42
+ ])
43
+ const CONVEX_PLATFORM_ID_SCHEMA = z
44
+ .number()
45
+ .int()
46
+ .nonnegative()
47
+ .max(Number.MAX_SAFE_INTEGER)
48
+ .transform(String)
39
49
  const CONVEX_DEPLOYMENT_INFO_SCHEMA = z.discriminatedUnion("kind", [
40
50
  z.object({
41
51
  kind: z.literal("cloud"),
42
- projectId: z.string(),
52
+ projectId: CONVEX_PLATFORM_ID_SCHEMA,
43
53
  projectName: z.string().nullable().optional(),
44
54
  reference: z.string().nullable().optional(),
45
55
  }),
@@ -47,7 +57,11 @@ const CONVEX_DEPLOYMENT_INFO_SCHEMA = z.discriminatedUnion("kind", [
47
57
  ])
48
58
  const CONVEX_FUNCTION_RESPONSE_SCHEMA = z.discriminatedUnion("status", [
49
59
  z.object({ status: z.literal("success"), value: z.json() }),
50
- z.object({ errorMessage: z.string(), status: z.literal("error") }),
60
+ z.object({
61
+ errorData: z.json().optional(),
62
+ errorMessage: z.string(),
63
+ status: z.literal("error"),
64
+ }),
51
65
  ])
52
66
 
53
67
  export interface ConvexDeployment {
@@ -96,6 +110,11 @@ export async function resolveConvexDeployment(
96
110
  )
97
111
  }
98
112
  const resolved = CONVEX_DEPLOYMENT_SCHEMA.parse(await response.json())
113
+ if (resolved.kind === "local") {
114
+ throw new Error(
115
+ `Convex deployment ${deployment} is local and cannot be reached by Automate.ax.`,
116
+ )
117
+ }
99
118
  return {
100
119
  deploymentUrl: resolved.deploymentUrl,
101
120
  reference: resolved.reference,
@@ -218,7 +237,14 @@ async function requestConvexFunction(
218
237
  )
219
238
  }
220
239
  const result = CONVEX_FUNCTION_RESPONSE_SCHEMA.parse(await response.json())
221
- if (result.status === "error") throw new Error(result.errorMessage)
240
+ if (result.status === "error") {
241
+ if (result.errorData !== undefined) {
242
+ const error = new ConvexError(decodeConvexValue(result.errorData))
243
+ error.message = result.errorMessage
244
+ throw error
245
+ }
246
+ throw new Error(result.errorMessage)
247
+ }
222
248
  return decodeConvexValue(result.value)
223
249
  }
224
250
 
@@ -1,11 +1,16 @@
1
1
  import * as z from "zod"
2
2
 
3
+ const CONVEX_NUMBER_SCHEMA = z.custom<number>(
4
+ (value) => typeof value === "number",
5
+ "Expected a Convex number.",
6
+ )
7
+
3
8
  /** Recursive schema for values accepted and returned by Convex functions. */
4
9
  export const CONVEX_VALUE_SCHEMA: z.ZodType<ConvexValue> = z.lazy(() =>
5
10
  z.union([
6
11
  z.null(),
7
12
  z.boolean(),
8
- z.number(),
13
+ CONVEX_NUMBER_SCHEMA,
9
14
  z.bigint(),
10
15
  z.string(),
11
16
  z.instanceof(ArrayBuffer),