@automate.ax/integration-contracts 0.139.2 → 0.141.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/closebot/api.d.ts +39 -0
- package/dist/closebot/api.js +117 -0
- package/dist/closebot/index.d.ts +2 -0
- package/dist/closebot/index.js +2 -0
- package/dist/closebot/schemas.d.ts +775 -0
- package/dist/closebot/schemas.js +467 -0
- package/dist/meta-ads/api.d.ts +90 -0
- package/dist/meta-ads/api.js +260 -0
- package/dist/meta-ads/events.d.ts +391 -0
- package/dist/meta-ads/events.js +193 -0
- package/dist/meta-ads/index.d.ts +3 -0
- package/dist/meta-ads/index.js +3 -0
- package/dist/meta-ads/schemas.d.ts +184 -0
- package/dist/meta-ads/schemas.js +181 -0
- package/dist/triggers.d.ts +2 -1
- package/package.json +14 -2
- package/src/closebot/api.ts +157 -0
- package/src/closebot/index.ts +2 -0
- package/src/closebot/schemas.ts +517 -0
- package/src/meta-ads/api.ts +327 -0
- package/src/meta-ads/events.ts +218 -0
- package/src/meta-ads/index.ts +3 -0
- package/src/meta-ads/schemas.ts +206 -0
- package/src/triggers.ts +2 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type Encodable } from "@automate.ax/codec";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
export declare const CLOSEBOT_VALUE_SCHEMA: z.ZodCustom<Encodable, Encodable>;
|
|
4
|
+
export declare const CLOSEBOT_RESPONSE_SCHEMA: z.ZodUnion<readonly [z.ZodCustom<Encodable, Encodable>, z.ZodPipe<z.ZodUndefined, z.ZodTransform<null, undefined>>]>;
|
|
5
|
+
interface CloseBotRequestOptions<TSchema extends z.ZodType> {
|
|
6
|
+
body?: Encodable | FormData;
|
|
7
|
+
method?: "DELETE" | "GET" | "PATCH" | "POST" | "PUT";
|
|
8
|
+
query?: Record<string, boolean | Date | number | string | (boolean | Date | number | string)[] | null | undefined>;
|
|
9
|
+
responseSchema: TSchema;
|
|
10
|
+
}
|
|
11
|
+
/** Error returned by a rejected CloseBot API request. */
|
|
12
|
+
export declare class CloseBotApiError extends Error {
|
|
13
|
+
readonly details: Encodable;
|
|
14
|
+
readonly retryAfter?: string;
|
|
15
|
+
readonly status: number;
|
|
16
|
+
/**
|
|
17
|
+
* Creates an error from a rejected CloseBot response.
|
|
18
|
+
*
|
|
19
|
+
* @param status - HTTP response status.
|
|
20
|
+
* @param details - Codec-safe response details.
|
|
21
|
+
* @param retryAfter - Raw provider retry timing, when present.
|
|
22
|
+
*/
|
|
23
|
+
constructor(status: number, details: Encodable, retryAfter?: string);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Creates an authenticated CloseBot REST API client.
|
|
27
|
+
*
|
|
28
|
+
* @param secret - Stored CloseBot API key.
|
|
29
|
+
*/
|
|
30
|
+
export declare function getCloseBotApi(secret: unknown): {
|
|
31
|
+
/**
|
|
32
|
+
* Sends one JSON request to a CloseBot API path.
|
|
33
|
+
*
|
|
34
|
+
* @param path - Relative path below the CloseBot API origin.
|
|
35
|
+
* @param options - Request method, query, body, and response schema.
|
|
36
|
+
*/
|
|
37
|
+
request<TSchema extends z.ZodType>(path: string, options: CloseBotRequestOptions<TSchema>): Promise<z.output<TSchema>>;
|
|
38
|
+
};
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { isEncodable } from "@automate.ax/codec";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
const CLOSEBOT_API_ORIGIN = "https://api.closebot.com/";
|
|
4
|
+
const CLOSEBOT_SECRET_SCHEMA = z.object({
|
|
5
|
+
apiKey: z.string().trim().min(1),
|
|
6
|
+
});
|
|
7
|
+
export const CLOSEBOT_VALUE_SCHEMA = z.custom(isEncodable, {
|
|
8
|
+
message: "Expected a codec-safe CloseBot value.",
|
|
9
|
+
});
|
|
10
|
+
export const CLOSEBOT_RESPONSE_SCHEMA = z.union([
|
|
11
|
+
CLOSEBOT_VALUE_SCHEMA,
|
|
12
|
+
z.undefined().transform(() => null),
|
|
13
|
+
]);
|
|
14
|
+
/** Error returned by a rejected CloseBot API request. */
|
|
15
|
+
export class CloseBotApiError extends Error {
|
|
16
|
+
details;
|
|
17
|
+
retryAfter;
|
|
18
|
+
status;
|
|
19
|
+
/**
|
|
20
|
+
* Creates an error from a rejected CloseBot response.
|
|
21
|
+
*
|
|
22
|
+
* @param status - HTTP response status.
|
|
23
|
+
* @param details - Codec-safe response details.
|
|
24
|
+
* @param retryAfter - Raw provider retry timing, when present.
|
|
25
|
+
*/
|
|
26
|
+
constructor(status, details, retryAfter) {
|
|
27
|
+
super(`CloseBot API request failed (${status}).`);
|
|
28
|
+
this.name = "CloseBotApiError";
|
|
29
|
+
this.details = details;
|
|
30
|
+
this.retryAfter = retryAfter;
|
|
31
|
+
this.status = status;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Creates an authenticated CloseBot REST API client.
|
|
36
|
+
*
|
|
37
|
+
* @param secret - Stored CloseBot API key.
|
|
38
|
+
*/
|
|
39
|
+
export function getCloseBotApi(secret) {
|
|
40
|
+
const { apiKey } = CLOSEBOT_SECRET_SCHEMA.parse(secret);
|
|
41
|
+
const root = new URL(CLOSEBOT_API_ORIGIN);
|
|
42
|
+
return {
|
|
43
|
+
/**
|
|
44
|
+
* Sends one JSON request to a CloseBot API path.
|
|
45
|
+
*
|
|
46
|
+
* @param path - Relative path below the CloseBot API origin.
|
|
47
|
+
* @param options - Request method, query, body, and response schema.
|
|
48
|
+
*/
|
|
49
|
+
async request(path, options) {
|
|
50
|
+
const normalizedPath = path.replace(/^\/+/, "");
|
|
51
|
+
if (!normalizedPath ||
|
|
52
|
+
normalizedPath.includes("://") ||
|
|
53
|
+
normalizedPath.includes("\\")) {
|
|
54
|
+
throw new TypeError("CloseBot API paths must be relative.");
|
|
55
|
+
}
|
|
56
|
+
const url = new URL(normalizedPath, root);
|
|
57
|
+
if (url.origin !== root.origin) {
|
|
58
|
+
throw new TypeError("CloseBot API paths must remain on api.closebot.com.");
|
|
59
|
+
}
|
|
60
|
+
for (const [key, value] of Object.entries(options.query ?? {})) {
|
|
61
|
+
if (value == null)
|
|
62
|
+
continue;
|
|
63
|
+
if (Array.isArray(value)) {
|
|
64
|
+
for (const item of value)
|
|
65
|
+
url.searchParams.append(key, queryValue(item));
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
url.searchParams.set(key, queryValue(value));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const headers = new Headers({
|
|
72
|
+
Accept: "application/json",
|
|
73
|
+
"X-CB-KEY": apiKey,
|
|
74
|
+
});
|
|
75
|
+
if (options.body !== undefined && !(options.body instanceof FormData)) {
|
|
76
|
+
headers.set("Content-Type", "application/json");
|
|
77
|
+
}
|
|
78
|
+
const response = await fetch(url, {
|
|
79
|
+
body: options.body === undefined
|
|
80
|
+
? undefined
|
|
81
|
+
: options.body instanceof FormData
|
|
82
|
+
? options.body
|
|
83
|
+
: JSON.stringify(options.body),
|
|
84
|
+
headers,
|
|
85
|
+
method: options.method ?? "GET",
|
|
86
|
+
redirect: "error",
|
|
87
|
+
});
|
|
88
|
+
const text = await response.text();
|
|
89
|
+
const parsed = CLOSEBOT_RESPONSE_SCHEMA.safeParse(text ? parseJson(text) : null);
|
|
90
|
+
if (!response.ok || !parsed.success) {
|
|
91
|
+
throw new CloseBotApiError(response.status, parsed.success ? parsed.data : { response: text }, response.headers.get("Retry-After") ?? undefined);
|
|
92
|
+
}
|
|
93
|
+
return options.responseSchema.parse(parsed.data);
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Parses a response while retaining non-JSON provider diagnostics.
|
|
99
|
+
*
|
|
100
|
+
* @param value - Raw response body.
|
|
101
|
+
*/
|
|
102
|
+
function parseJson(value) {
|
|
103
|
+
try {
|
|
104
|
+
return JSON.parse(value);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Serializes one supported query value.
|
|
112
|
+
*
|
|
113
|
+
* @param value - Public query value.
|
|
114
|
+
*/
|
|
115
|
+
function queryValue(value) {
|
|
116
|
+
return value instanceof Date ? value.toISOString() : String(value);
|
|
117
|
+
}
|