@automate.ax/integration-contracts 0.125.0 → 0.127.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.
Files changed (49) hide show
  1. package/dist/axiom/api.d.ts +60 -0
  2. package/dist/axiom/api.js +192 -0
  3. package/dist/axiom/events.d.ts +104 -0
  4. package/dist/axiom/events.js +25 -0
  5. package/dist/axiom/index.d.ts +3 -0
  6. package/dist/axiom/index.js +3 -0
  7. package/dist/axiom/schemas.d.ts +1520 -0
  8. package/dist/axiom/schemas.js +580 -0
  9. package/dist/brevo/index.d.ts +2 -2
  10. package/dist/brevo/schemas.d.ts +3 -3
  11. package/dist/close/events.d.ts +9 -9
  12. package/dist/close/schemas.d.ts +3 -3
  13. package/dist/cloudflare/schemas.d.ts +4 -4
  14. package/dist/convex/index.d.ts +8 -8
  15. package/dist/convex/schemas.d.ts +4 -4
  16. package/dist/gmail/schemas.d.ts +3 -3
  17. package/dist/google-calendar/schemas.d.ts +2 -2
  18. package/dist/google-drive/index.d.ts +3 -3
  19. package/dist/google-forms/event-schemas.d.ts +2 -2
  20. package/dist/google-forms/google-forms.d.ts +4 -4
  21. package/dist/google-forms/index.d.ts +2 -2
  22. package/dist/google-forms/schemas.d.ts +7 -7
  23. package/dist/hubspot/events.d.ts +3 -3
  24. package/dist/linear/schemas.d.ts +12 -12
  25. package/dist/notion/schemas.d.ts +6 -6
  26. package/dist/outlook/index.d.ts +9 -9
  27. package/dist/outlook/schemas.d.ts +6 -6
  28. package/dist/reddit/api.d.ts +56 -0
  29. package/dist/reddit/api.js +135 -0
  30. package/dist/reddit/events.d.ts +439 -0
  31. package/dist/reddit/events.js +53 -0
  32. package/dist/reddit/index.d.ts +3 -0
  33. package/dist/reddit/index.js +3 -0
  34. package/dist/reddit/schemas.d.ts +816 -0
  35. package/dist/reddit/schemas.js +398 -0
  36. package/dist/trello/schemas.d.ts +2 -2
  37. package/dist/triggers.d.ts +3 -1
  38. package/dist/whatsapp/index.d.ts +4 -4
  39. package/dist/whatsapp/schemas.d.ts +8 -8
  40. package/package.json +14 -2
  41. package/src/axiom/api.ts +252 -0
  42. package/src/axiom/events.ts +31 -0
  43. package/src/axiom/index.ts +3 -0
  44. package/src/axiom/schemas.ts +614 -0
  45. package/src/reddit/api.ts +183 -0
  46. package/src/reddit/events.ts +68 -0
  47. package/src/reddit/index.ts +3 -0
  48. package/src/reddit/schemas.ts +442 -0
  49. package/src/triggers.ts +4 -0
@@ -0,0 +1,60 @@
1
+ import { type Encodable } from "@automate.ax/codec";
2
+ import * as z from "zod";
3
+ export interface AxiomResolvedAccount {
4
+ connectionMethodId: string;
5
+ secret: Record<string, unknown>;
6
+ serviceId: "axiom";
7
+ }
8
+ export interface AxiomRequestOptions<TSchema extends z.ZodType> {
9
+ body?: Encodable;
10
+ headers?: Record<string, string>;
11
+ method?: "DELETE" | "GET" | "PATCH" | "POST" | "PUT";
12
+ query?: Record<string, boolean | number | string | undefined>;
13
+ responseSchema: TSchema;
14
+ version?: "v1" | "v2";
15
+ }
16
+ /** Structured Axiom REST error. */
17
+ export declare class AxiomApiError extends Error {
18
+ readonly details: Encodable;
19
+ readonly ingestLimitReset?: number;
20
+ readonly queryLimitReset?: number;
21
+ readonly rateLimitReset?: number;
22
+ readonly retryAfter?: number;
23
+ readonly status: number;
24
+ /**
25
+ * Creates a structured provider error.
26
+ *
27
+ * @param options - Error response details and rate-limit metadata.
28
+ * @param options.details - Parsed provider response body.
29
+ * @param options.ingestLimitReset - Ingest-limit reset timestamp.
30
+ * @param options.queryLimitReset - Query-limit reset timestamp.
31
+ * @param options.rateLimitReset - Request-rate-limit reset timestamp.
32
+ * @param options.retryAfter - Suggested retry delay in seconds.
33
+ * @param options.status - HTTP response status.
34
+ */
35
+ constructor(options: {
36
+ details: Encodable;
37
+ ingestLimitReset?: number;
38
+ queryLimitReset?: number;
39
+ rateLimitReset?: number;
40
+ retryAfter?: number;
41
+ status: number;
42
+ });
43
+ }
44
+ /**
45
+ * Creates an authenticated, origin-confined Axiom API client.
46
+ *
47
+ * @param account - Resolved Axiom integration account.
48
+ * @param edgeUrl - Optional Axiom edge origin used by version-one endpoints.
49
+ * @throws When the account method, secret, or edge origin is invalid.
50
+ */
51
+ export declare function getAxiomApi(account: AxiomResolvedAccount, edgeUrl?: string): {
52
+ request: <TSchema extends z.ZodType>(path: string, options: AxiomRequestOptions<TSchema>) => Promise<z.output<TSchema>>;
53
+ };
54
+ /**
55
+ * Restricts edge traffic to Axiom-owned HTTPS origins on the standard port.
56
+ *
57
+ * @param value - Candidate edge URL.
58
+ * @throws {TypeError} When the URL is not a confined Axiom HTTPS origin.
59
+ */
60
+ export declare function validateAxiomOrigin(value: string): string;
@@ -0,0 +1,192 @@
1
+ import { encodableSchema } from "@automate.ax/codec";
2
+ import * as z from "zod";
3
+ const AXIOM_API_ORIGIN = "https://api.axiom.co";
4
+ const AXIOM_SECRET_SCHEMA = z.object({ apiKey: z.string().trim().min(1) });
5
+ /** Structured Axiom REST error. */
6
+ export class AxiomApiError extends Error {
7
+ details;
8
+ ingestLimitReset;
9
+ queryLimitReset;
10
+ rateLimitReset;
11
+ retryAfter;
12
+ status;
13
+ /**
14
+ * Creates a structured provider error.
15
+ *
16
+ * @param options - Error response details and rate-limit metadata.
17
+ * @param options.details - Parsed provider response body.
18
+ * @param options.ingestLimitReset - Ingest-limit reset timestamp.
19
+ * @param options.queryLimitReset - Query-limit reset timestamp.
20
+ * @param options.rateLimitReset - Request-rate-limit reset timestamp.
21
+ * @param options.retryAfter - Suggested retry delay in seconds.
22
+ * @param options.status - HTTP response status.
23
+ */
24
+ constructor(options) {
25
+ const message = isPlainObject(options.details) &&
26
+ typeof options.details.message === "string"
27
+ ? options.details.message
28
+ : undefined;
29
+ super(message
30
+ ? `Axiom API error (${options.status}): ${message}`
31
+ : `Axiom API request failed (${options.status}).`);
32
+ this.name = "AxiomApiError";
33
+ this.details = options.details;
34
+ this.ingestLimitReset = options.ingestLimitReset;
35
+ this.queryLimitReset = options.queryLimitReset;
36
+ this.rateLimitReset = options.rateLimitReset;
37
+ this.retryAfter = options.retryAfter;
38
+ this.status = options.status;
39
+ }
40
+ }
41
+ /**
42
+ * Creates an authenticated, origin-confined Axiom API client.
43
+ *
44
+ * @param account - Resolved Axiom integration account.
45
+ * @param edgeUrl - Optional Axiom edge origin used by version-one endpoints.
46
+ * @throws When the account method, secret, or edge origin is invalid.
47
+ */
48
+ export function getAxiomApi(account, edgeUrl = AXIOM_API_ORIGIN) {
49
+ if (account.connectionMethodId !== "api-token") {
50
+ throw new Error(`Unsupported Axiom connection method: ${account.connectionMethodId}`);
51
+ }
52
+ const { apiKey } = AXIOM_SECRET_SCHEMA.parse(account.secret);
53
+ const edgeOrigin = validateAxiomOrigin(edgeUrl);
54
+ /**
55
+ * Sends one authenticated request and validates its response.
56
+ *
57
+ * @param path - Relative Axiom API path.
58
+ * @param options - Request and response-validation options.
59
+ * @throws {AxiomApiError} When Axiom returns an unsuccessful response.
60
+ */
61
+ async function request(path, options) {
62
+ const version = options.version ?? "v2";
63
+ const url = confinedUrl(version === "v1" ? edgeOrigin : AXIOM_API_ORIGIN, version, path);
64
+ for (const [name, value] of Object.entries(options.query ?? {})) {
65
+ if (value !== undefined)
66
+ url.searchParams.set(name, String(value));
67
+ }
68
+ const response = await fetch(url, {
69
+ body: options.body === undefined
70
+ ? undefined
71
+ : JSON.stringify(encodableSchema.parse(options.body)),
72
+ headers: {
73
+ Accept: "application/json",
74
+ Authorization: `Bearer ${apiKey}`,
75
+ ...(options.body === undefined
76
+ ? {}
77
+ : { "Content-Type": "application/json" }),
78
+ ...options.headers,
79
+ },
80
+ method: options.method ?? "GET",
81
+ redirect: "manual",
82
+ });
83
+ const parsed = parseResponse(await response.text());
84
+ if (!response.ok || response.status >= 300) {
85
+ throw new AxiomApiError({
86
+ details: parsed,
87
+ ingestLimitReset: parseFiniteNumber(response.headers.get("X-IngestLimit-Reset")),
88
+ queryLimitReset: parseFiniteNumber(response.headers.get("X-QueryLimit-Reset")),
89
+ rateLimitReset: parseFiniteNumber(response.headers.get("X-RateLimit-Reset")),
90
+ retryAfter: parseRetryAfter(response.headers.get("Retry-After")),
91
+ status: response.status,
92
+ });
93
+ }
94
+ return options.responseSchema.parse(parsed);
95
+ }
96
+ return { request };
97
+ }
98
+ /**
99
+ * Restricts edge traffic to Axiom-owned HTTPS origins on the standard port.
100
+ *
101
+ * @param value - Candidate edge URL.
102
+ * @throws {TypeError} When the URL is not a confined Axiom HTTPS origin.
103
+ */
104
+ export function validateAxiomOrigin(value) {
105
+ const url = new URL(value);
106
+ const isAxiomHost = url.hostname === "api.axiom.co" || url.hostname.endsWith(".edge.axiom.co");
107
+ if (url.protocol !== "https:" ||
108
+ url.port !== "" ||
109
+ !isAxiomHost ||
110
+ url.username ||
111
+ url.password ||
112
+ url.search ||
113
+ url.hash) {
114
+ throw new TypeError("Axiom edge URLs must use api.axiom.co or an HTTPS *.edge.axiom.co host.");
115
+ }
116
+ return url.origin;
117
+ }
118
+ /**
119
+ * Resolves a relative path below one confined API-version root.
120
+ *
121
+ * @param origin - Validated Axiom origin.
122
+ * @param version - API version path segment.
123
+ * @param path - Relative request path.
124
+ * @throws {TypeError} When the path escapes its API-version root.
125
+ */
126
+ function confinedUrl(origin, version, path) {
127
+ const normalizedPath = path.replace(/^\/+/, "");
128
+ if (!normalizedPath ||
129
+ normalizedPath.includes("://") ||
130
+ normalizedPath.includes("\\")) {
131
+ throw new TypeError("Axiom API paths must be relative.");
132
+ }
133
+ const root = new URL(`/${version}/`, origin);
134
+ const url = new URL(normalizedPath, root);
135
+ if (url.origin !== root.origin || !url.pathname.startsWith(root.pathname)) {
136
+ throw new TypeError("Axiom API paths must remain below their API version.");
137
+ }
138
+ return url;
139
+ }
140
+ /**
141
+ * Parses an Axiom response into an encodable value.
142
+ *
143
+ * @param text - Raw response body.
144
+ */
145
+ function parseResponse(text) {
146
+ if (!text)
147
+ return null;
148
+ try {
149
+ return encodableSchema.parse(JSON.parse(text));
150
+ }
151
+ catch {
152
+ return { response: text };
153
+ }
154
+ }
155
+ /**
156
+ * Parses a finite numeric response header.
157
+ *
158
+ * @param value - Raw header value.
159
+ */
160
+ function parseFiniteNumber(value) {
161
+ if (value === null)
162
+ return undefined;
163
+ const number = Number(value);
164
+ return Number.isFinite(number) ? number : undefined;
165
+ }
166
+ /**
167
+ * Parses a Retry-After header into seconds.
168
+ *
169
+ * @param value - Raw header value.
170
+ */
171
+ function parseRetryAfter(value) {
172
+ if (value === null)
173
+ return undefined;
174
+ const seconds = Number(value);
175
+ if (Number.isFinite(seconds))
176
+ return seconds;
177
+ const timestamp = Date.parse(value);
178
+ return Number.isFinite(timestamp)
179
+ ? Math.max(0, Math.ceil((timestamp - Date.now()) / 1_000))
180
+ : undefined;
181
+ }
182
+ /**
183
+ * Checks whether an encodable value is a plain object.
184
+ *
185
+ * @param value - Value to inspect.
186
+ */
187
+ function isPlainObject(value) {
188
+ return (typeof value === "object" &&
189
+ value !== null &&
190
+ !Array.isArray(value) &&
191
+ Object.getPrototypeOf(value) === Object.prototype);
192
+ }
@@ -0,0 +1,104 @@
1
+ import * as z from "zod";
2
+ export declare const AXIOM_TRIGGER_CONFIG_SCHEMA: z.ZodObject<{
3
+ monitorId: z.ZodString;
4
+ }, z.core.$strip>;
5
+ export declare const AXIOM_MONITOR_OPENED_SCHEMA: z.ZodObject<{
6
+ event: z.ZodObject<{
7
+ body: z.ZodString;
8
+ description: z.ZodString;
9
+ groupKeys: z.ZodNullable<z.ZodArray<z.ZodString>>;
10
+ groupValues: z.ZodNullable<z.ZodArray<z.ZodJSONSchema>>;
11
+ matchedEvent: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
12
+ monitorId: z.ZodString;
13
+ queryEndTime: z.ZodString;
14
+ queryStartTime: z.ZodString;
15
+ timestamp: z.ZodString;
16
+ title: z.ZodString;
17
+ value: z.ZodNumber;
18
+ }, z.core.$strip>;
19
+ action: z.ZodLiteral<"Open">;
20
+ }, z.core.$strip>;
21
+ export declare const AXIOM_MONITOR_CLOSED_SCHEMA: z.ZodObject<{
22
+ event: z.ZodObject<{
23
+ body: z.ZodString;
24
+ description: z.ZodString;
25
+ groupKeys: z.ZodNullable<z.ZodArray<z.ZodString>>;
26
+ groupValues: z.ZodNullable<z.ZodArray<z.ZodJSONSchema>>;
27
+ matchedEvent: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
28
+ monitorId: z.ZodString;
29
+ queryEndTime: z.ZodString;
30
+ queryStartTime: z.ZodString;
31
+ timestamp: z.ZodString;
32
+ title: z.ZodString;
33
+ value: z.ZodNumber;
34
+ }, z.core.$strip>;
35
+ action: z.ZodLiteral<"Closed">;
36
+ }, z.core.$strip>;
37
+ export declare const axiomTriggerContracts: {
38
+ readonly "axiom.monitorNotification": {
39
+ readonly configSchema: z.ZodObject<{
40
+ monitorId: z.ZodString;
41
+ }, z.core.$strip>;
42
+ readonly eventSchema: z.ZodObject<{
43
+ action: z.ZodEnum<{
44
+ Closed: "Closed";
45
+ Open: "Open";
46
+ }>;
47
+ event: z.ZodObject<{
48
+ body: z.ZodString;
49
+ description: z.ZodString;
50
+ groupKeys: z.ZodNullable<z.ZodArray<z.ZodString>>;
51
+ groupValues: z.ZodNullable<z.ZodArray<z.ZodJSONSchema>>;
52
+ matchedEvent: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
53
+ monitorId: z.ZodString;
54
+ queryEndTime: z.ZodString;
55
+ queryStartTime: z.ZodString;
56
+ timestamp: z.ZodString;
57
+ title: z.ZodString;
58
+ value: z.ZodNumber;
59
+ }, z.core.$strip>;
60
+ }, z.core.$strip>;
61
+ };
62
+ readonly "axiom.monitorOpened": {
63
+ readonly configSchema: z.ZodObject<{
64
+ monitorId: z.ZodString;
65
+ }, z.core.$strip>;
66
+ readonly eventSchema: z.ZodObject<{
67
+ event: z.ZodObject<{
68
+ body: z.ZodString;
69
+ description: z.ZodString;
70
+ groupKeys: z.ZodNullable<z.ZodArray<z.ZodString>>;
71
+ groupValues: z.ZodNullable<z.ZodArray<z.ZodJSONSchema>>;
72
+ matchedEvent: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
73
+ monitorId: z.ZodString;
74
+ queryEndTime: z.ZodString;
75
+ queryStartTime: z.ZodString;
76
+ timestamp: z.ZodString;
77
+ title: z.ZodString;
78
+ value: z.ZodNumber;
79
+ }, z.core.$strip>;
80
+ action: z.ZodLiteral<"Open">;
81
+ }, z.core.$strip>;
82
+ };
83
+ readonly "axiom.monitorClosed": {
84
+ readonly configSchema: z.ZodObject<{
85
+ monitorId: z.ZodString;
86
+ }, z.core.$strip>;
87
+ readonly eventSchema: z.ZodObject<{
88
+ event: z.ZodObject<{
89
+ body: z.ZodString;
90
+ description: z.ZodString;
91
+ groupKeys: z.ZodNullable<z.ZodArray<z.ZodString>>;
92
+ groupValues: z.ZodNullable<z.ZodArray<z.ZodJSONSchema>>;
93
+ matchedEvent: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
94
+ monitorId: z.ZodString;
95
+ queryEndTime: z.ZodString;
96
+ queryStartTime: z.ZodString;
97
+ timestamp: z.ZodString;
98
+ title: z.ZodString;
99
+ value: z.ZodNumber;
100
+ }, z.core.$strip>;
101
+ action: z.ZodLiteral<"Closed">;
102
+ }, z.core.$strip>;
103
+ };
104
+ };
@@ -0,0 +1,25 @@
1
+ import * as z from "zod";
2
+ import { AXIOM_ID_SCHEMA, AXIOM_MONITOR_NOTIFICATION_SCHEMA } from "./schemas.js";
3
+ export const AXIOM_TRIGGER_CONFIG_SCHEMA = z.object({
4
+ monitorId: AXIOM_ID_SCHEMA,
5
+ });
6
+ export const AXIOM_MONITOR_OPENED_SCHEMA = AXIOM_MONITOR_NOTIFICATION_SCHEMA.extend({
7
+ action: z.literal("Open"),
8
+ });
9
+ export const AXIOM_MONITOR_CLOSED_SCHEMA = AXIOM_MONITOR_NOTIFICATION_SCHEMA.extend({
10
+ action: z.literal("Closed"),
11
+ });
12
+ export const axiomTriggerContracts = {
13
+ "axiom.monitorNotification": {
14
+ configSchema: AXIOM_TRIGGER_CONFIG_SCHEMA,
15
+ eventSchema: AXIOM_MONITOR_NOTIFICATION_SCHEMA,
16
+ },
17
+ "axiom.monitorOpened": {
18
+ configSchema: AXIOM_TRIGGER_CONFIG_SCHEMA,
19
+ eventSchema: AXIOM_MONITOR_OPENED_SCHEMA,
20
+ },
21
+ "axiom.monitorClosed": {
22
+ configSchema: AXIOM_TRIGGER_CONFIG_SCHEMA,
23
+ eventSchema: AXIOM_MONITOR_CLOSED_SCHEMA,
24
+ },
25
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./api.js";
2
+ export * from "./events.js";
3
+ export * from "./schemas.js";
@@ -0,0 +1,3 @@
1
+ export * from "./api.js";
2
+ export * from "./events.js";
3
+ export * from "./schemas.js";