@automate.ax/integration-contracts 0.139.2 → 0.142.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 (50) hide show
  1. package/dist/clickup/api.d.ts +76 -0
  2. package/dist/clickup/api.js +195 -0
  3. package/dist/clickup/index.d.ts +1921 -0
  4. package/dist/clickup/index.js +91 -0
  5. package/dist/clickup/schemas.d.ts +477 -0
  6. package/dist/clickup/schemas.js +286 -0
  7. package/dist/closebot/api.d.ts +39 -0
  8. package/dist/closebot/api.js +117 -0
  9. package/dist/closebot/index.d.ts +2 -0
  10. package/dist/closebot/index.js +2 -0
  11. package/dist/closebot/schemas.d.ts +775 -0
  12. package/dist/closebot/schemas.js +469 -0
  13. package/dist/google-ads/api.d.ts +40 -0
  14. package/dist/google-ads/api.js +109 -0
  15. package/dist/google-ads/events.d.ts +1155 -0
  16. package/dist/google-ads/events.js +96 -0
  17. package/dist/google-ads/index.d.ts +3 -0
  18. package/dist/google-ads/index.js +3 -0
  19. package/dist/google-ads/schemas.d.ts +756 -0
  20. package/dist/google-ads/schemas.js +249 -0
  21. package/dist/google-drive/index.d.ts +6 -6
  22. package/dist/linear/schemas.d.ts +3 -3
  23. package/dist/meta-ads/api.d.ts +90 -0
  24. package/dist/meta-ads/api.js +260 -0
  25. package/dist/meta-ads/events.d.ts +391 -0
  26. package/dist/meta-ads/events.js +193 -0
  27. package/dist/meta-ads/index.d.ts +3 -0
  28. package/dist/meta-ads/index.js +3 -0
  29. package/dist/meta-ads/schemas.d.ts +184 -0
  30. package/dist/meta-ads/schemas.js +181 -0
  31. package/dist/notion/schemas.d.ts +84 -84
  32. package/dist/teams/index.d.ts +20 -20
  33. package/dist/teams/schemas.d.ts +5 -5
  34. package/dist/triggers.d.ts +4 -1
  35. package/package.json +27 -3
  36. package/src/clickup/api.ts +270 -0
  37. package/src/clickup/index.ts +108 -0
  38. package/src/clickup/schemas.ts +324 -0
  39. package/src/closebot/api.ts +157 -0
  40. package/src/closebot/index.ts +2 -0
  41. package/src/closebot/schemas.ts +521 -0
  42. package/src/google-ads/api.ts +151 -0
  43. package/src/google-ads/events.ts +131 -0
  44. package/src/google-ads/index.ts +3 -0
  45. package/src/google-ads/schemas.ts +270 -0
  46. package/src/meta-ads/api.ts +327 -0
  47. package/src/meta-ads/events.ts +218 -0
  48. package/src/meta-ads/index.ts +3 -0
  49. package/src/meta-ads/schemas.ts +206 -0
  50. package/src/triggers.ts +6 -0
@@ -0,0 +1,76 @@
1
+ import { type Encodable } from "@automate.ax/codec";
2
+ import * as z from "zod";
3
+ /** Resolved ClickUp account accepted by the shared API client. */
4
+ export interface ClickUpResolvedAccount {
5
+ connectionMethodId: string;
6
+ secret: Record<string, unknown>;
7
+ serviceId: "clickup";
8
+ }
9
+ /** Scalar value serialized into one ClickUp query parameter. */
10
+ export type ClickUpQueryValue = boolean | number | readonly (number | string)[] | string | undefined;
11
+ /** Options for one authenticated ClickUp REST request. */
12
+ export interface ClickUpRequestOptions<TSchema extends z.ZodType> {
13
+ /** Public camelCase JSON body. */
14
+ body?: Encodable;
15
+ /** HTTP verb. Defaults to `GET`. */
16
+ method?: "DELETE" | "GET" | "POST" | "PUT";
17
+ /** Public camelCase query parameters. */
18
+ query?: Record<string, ClickUpQueryValue>;
19
+ /** Schema for the normalized provider response. */
20
+ responseSchema: TSchema;
21
+ }
22
+ /** Authenticated ClickUp REST API helper for packaged actions. */
23
+ export interface ClickUpApi {
24
+ /**
25
+ * Calls a ClickUp API v2 endpoint and validates its normalized response.
26
+ *
27
+ * @param path - API path relative to `/api/v2/`.
28
+ * @param options - Request data and response schema.
29
+ */
30
+ request<TSchema extends z.ZodType>(path: string, options: ClickUpRequestOptions<TSchema>): Promise<z.output<TSchema>>;
31
+ }
32
+ /** Structured ClickUp REST error. */
33
+ export declare class ClickUpApiError extends Error {
34
+ /** Normalized provider error payload, when it was valid JSON. */
35
+ readonly body?: Encodable;
36
+ /** API path that failed. */
37
+ readonly path: string;
38
+ /** Unix timestamp in seconds when the current rate-limit window resets. */
39
+ readonly rateLimitReset?: number;
40
+ /** HTTP status returned by ClickUp. */
41
+ readonly status: number;
42
+ /**
43
+ * Creates a structured ClickUp API error.
44
+ *
45
+ * @param options - Provider and transport error details.
46
+ * @param options.body - Normalized provider error payload.
47
+ * @param options.path - API path that failed.
48
+ * @param options.rateLimitReset - Unix reset timestamp in seconds.
49
+ * @param options.status - HTTP response status.
50
+ */
51
+ constructor(options: {
52
+ body?: Encodable;
53
+ path: string;
54
+ rateLimitReset?: number;
55
+ status: number;
56
+ });
57
+ }
58
+ /**
59
+ * Creates an authenticated ClickUp API v2 client.
60
+ *
61
+ * @param account - Resolved ClickUp integration account.
62
+ * @throws When the account uses an unsupported connection method.
63
+ */
64
+ export declare function getClickUpApi(account: ClickUpResolvedAccount): ClickUpApi;
65
+ /**
66
+ * Converts public camelCase JSON to ClickUp wire keys.
67
+ *
68
+ * @param value - Public JSON value.
69
+ */
70
+ export declare function toClickUp(value: Encodable): Encodable;
71
+ /**
72
+ * Converts ClickUp response keys to public camelCase recursively.
73
+ *
74
+ * @param value - Provider response value.
75
+ */
76
+ export declare function fromClickUp(value: unknown): unknown;
@@ -0,0 +1,195 @@
1
+ import { encodableSchema } from "@automate.ax/codec";
2
+ import * as z from "zod";
3
+ const CLICKUP_API_BASE_URL = "https://api.clickup.com/api/v2/";
4
+ const CLICKUP_API_ORIGIN = new URL(CLICKUP_API_BASE_URL).origin;
5
+ const CLICKUP_OAUTH_SECRET_SCHEMA = z.object({ accessToken: z.string().min(1) });
6
+ const CLICKUP_TOKEN_SECRET_SCHEMA = z.object({ apiKey: z.string().min(1) });
7
+ /** Structured ClickUp REST error. */
8
+ export class ClickUpApiError extends Error {
9
+ /** Normalized provider error payload, when it was valid JSON. */
10
+ body;
11
+ /** API path that failed. */
12
+ path;
13
+ /** Unix timestamp in seconds when the current rate-limit window resets. */
14
+ rateLimitReset;
15
+ /** HTTP status returned by ClickUp. */
16
+ status;
17
+ /**
18
+ * Creates a structured ClickUp API error.
19
+ *
20
+ * @param options - Provider and transport error details.
21
+ * @param options.body - Normalized provider error payload.
22
+ * @param options.path - API path that failed.
23
+ * @param options.rateLimitReset - Unix reset timestamp in seconds.
24
+ * @param options.status - HTTP response status.
25
+ */
26
+ constructor(options) {
27
+ super(getErrorMessage(options.body) ??
28
+ `ClickUp API request failed with status ${options.status}.`);
29
+ this.name = "ClickUpApiError";
30
+ this.body = options.body;
31
+ this.path = options.path;
32
+ this.rateLimitReset = options.rateLimitReset;
33
+ this.status = options.status;
34
+ }
35
+ }
36
+ /**
37
+ * Creates an authenticated ClickUp API v2 client.
38
+ *
39
+ * @param account - Resolved ClickUp integration account.
40
+ * @throws When the account uses an unsupported connection method.
41
+ */
42
+ export function getClickUpApi(account) {
43
+ const accessToken = account.connectionMethodId === "oauth"
44
+ ? CLICKUP_OAUTH_SECRET_SCHEMA.parse(account.secret).accessToken
45
+ : account.connectionMethodId === "personal-token"
46
+ ? CLICKUP_TOKEN_SECRET_SCHEMA.parse(account.secret).apiKey
47
+ : "";
48
+ if (!accessToken) {
49
+ throw new Error(`Unsupported ClickUp connection method: ${account.connectionMethodId}`);
50
+ }
51
+ return {
52
+ request: async (path, options) => {
53
+ const normalizedPath = path.replace(/^\/+/, "");
54
+ const url = new URL(normalizedPath, CLICKUP_API_BASE_URL);
55
+ const expectedPathname = `/api/v2/${normalizedPath}`;
56
+ if (url.origin !== CLICKUP_API_ORIGIN ||
57
+ url.pathname !== expectedPathname) {
58
+ throw new Error("ClickUp API paths must remain under /api/v2.");
59
+ }
60
+ for (const [name, value] of Object.entries(options.query ?? {})) {
61
+ if (value === undefined)
62
+ continue;
63
+ const wireName = toSnakeCase(name);
64
+ if (Array.isArray(value)) {
65
+ for (const item of value)
66
+ url.searchParams.append(`${wireName}[]`, String(item));
67
+ }
68
+ else {
69
+ url.searchParams.set(wireName, String(value));
70
+ }
71
+ }
72
+ const response = await fetch(url, {
73
+ body: options.body === undefined
74
+ ? undefined
75
+ : JSON.stringify(toClickUp(options.body)),
76
+ headers: {
77
+ Accept: "application/json",
78
+ Authorization: account.connectionMethodId === "oauth"
79
+ ? `Bearer ${accessToken}`
80
+ : accessToken,
81
+ ...(options.body === undefined
82
+ ? {}
83
+ : { "Content-Type": "application/json" }),
84
+ },
85
+ method: options.method ?? "GET",
86
+ });
87
+ const responseText = await response.text();
88
+ const normalized = responseText === "" ? undefined : fromClickUp(parseJson(responseText));
89
+ if (!response.ok) {
90
+ const body = encodableSchema.safeParse(normalized);
91
+ throw new ClickUpApiError({
92
+ ...(body.success && { body: body.data }),
93
+ path: `/${normalizedPath}`,
94
+ rateLimitReset: parseFiniteNumber(response.headers.get("X-RateLimit-Reset")),
95
+ status: response.status,
96
+ });
97
+ }
98
+ return options.responseSchema.parse(normalized);
99
+ },
100
+ };
101
+ }
102
+ /**
103
+ * Converts public camelCase JSON to ClickUp wire keys.
104
+ *
105
+ * @param value - Public JSON value.
106
+ */
107
+ export function toClickUp(value) {
108
+ if (value instanceof Date)
109
+ return value.toISOString();
110
+ if (Array.isArray(value))
111
+ return value.map(toClickUp);
112
+ if (!isPlainObject(value))
113
+ return value;
114
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [
115
+ toSnakeCase(key),
116
+ toClickUp(item),
117
+ ]));
118
+ }
119
+ /**
120
+ * Converts ClickUp response keys to public camelCase recursively.
121
+ *
122
+ * @param value - Provider response value.
123
+ */
124
+ export function fromClickUp(value) {
125
+ if (Array.isArray(value))
126
+ return value.map(fromClickUp);
127
+ if (!isPlainObject(value))
128
+ return value;
129
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [
130
+ toCamelCase(key),
131
+ fromClickUp(item),
132
+ ]));
133
+ }
134
+ /**
135
+ * Returns whether a value is a non-array object.
136
+ *
137
+ * @param value - Candidate value.
138
+ */
139
+ function isPlainObject(value) {
140
+ return typeof value === "object" && value !== null && !Array.isArray(value);
141
+ }
142
+ /**
143
+ * Parses JSON without masking the provider's response status.
144
+ *
145
+ * @param value - Raw response text.
146
+ */
147
+ function parseJson(value) {
148
+ try {
149
+ return JSON.parse(value);
150
+ }
151
+ catch {
152
+ return undefined;
153
+ }
154
+ }
155
+ /**
156
+ * Parses a finite number from an optional response header.
157
+ *
158
+ * @param value - Raw response header.
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
+ * Reads ClickUp's human-readable error message from a response body.
168
+ *
169
+ * @param body - Normalized provider response body.
170
+ */
171
+ function getErrorMessage(body) {
172
+ if (!isPlainObject(body))
173
+ return undefined;
174
+ if (typeof body.err === "string")
175
+ return body.err;
176
+ if (typeof body.message === "string")
177
+ return body.message;
178
+ return undefined;
179
+ }
180
+ /**
181
+ * Converts one camelCase key to ClickUp's snake_case wire format.
182
+ *
183
+ * @param value - Public key.
184
+ */
185
+ function toSnakeCase(value) {
186
+ return value.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
187
+ }
188
+ /**
189
+ * Converts one ClickUp snake_case key to camelCase.
190
+ *
191
+ * @param value - Provider wire key.
192
+ */
193
+ function toCamelCase(value) {
194
+ return value.replace(/_([a-z0-9])/g, (_match, letter) => letter.toUpperCase());
195
+ }