@automate.ax/integration-contracts 0.143.0 → 0.143.4

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.
@@ -83,7 +83,7 @@ export declare const CLICKUP_LIST_SCHEMA: z.ZodObject<{
83
83
  status: z.ZodString;
84
84
  type: z.ZodOptional<z.ZodString>;
85
85
  }, z.core.$strip>>>;
86
- taskCount: z.ZodOptional<z.ZodNullable<z.ZodString>>;
86
+ taskCount: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>, z.ZodTransform<string | undefined, string | number | null | undefined>>;
87
87
  }, z.core.$strip>;
88
88
  export declare const CLICKUP_CUSTOM_FIELD_SCHEMA: z.ZodObject<{
89
89
  id: z.ZodString;
@@ -21,6 +21,11 @@ export const CLICKUP_STATUS_SCHEMA = z.object({
21
21
  status: z.string(),
22
22
  type: z.string().optional(),
23
23
  });
24
+ const CLICKUP_TASK_COUNT_SCHEMA = z
25
+ .union([z.string(), z.number()])
26
+ .nullable()
27
+ .optional()
28
+ .transform((value) => (value == null ? undefined : String(value)));
24
29
  export const CLICKUP_SPACE_SCHEMA = z.object({
25
30
  archived: z.boolean().prefault(false),
26
31
  color: z.string().nullable().optional(),
@@ -40,11 +45,7 @@ export const CLICKUP_FOLDER_SCHEMA = z.object({
40
45
  overrideStatuses: z.boolean().optional(),
41
46
  parentFolder: z.string().optional(),
42
47
  space: z.object({ id: z.string(), name: z.string().optional() }).optional(),
43
- taskCount: z
44
- .string()
45
- .nullable()
46
- .optional()
47
- .transform((value) => value ?? undefined),
48
+ taskCount: CLICKUP_TASK_COUNT_SCHEMA,
48
49
  });
49
50
  export const CLICKUP_LIST_SCHEMA = z.object({
50
51
  archived: z.boolean().optional(),
@@ -63,7 +64,7 @@ export const CLICKUP_LIST_SCHEMA = z.object({
63
64
  orderindex: z.number().optional(),
64
65
  space: z.object({ id: z.string(), name: z.string().optional() }).optional(),
65
66
  statuses: CLICKUP_STATUS_SCHEMA.array().prefault([]),
66
- taskCount: z.string().nullable().optional(),
67
+ taskCount: CLICKUP_TASK_COUNT_SCHEMA,
67
68
  });
68
69
  export const CLICKUP_CUSTOM_FIELD_SCHEMA = z.object({
69
70
  id: z.string(),
@@ -10,7 +10,7 @@ export declare const META_ADS_OAUTH_SECRET_SCHEMA: z.ZodObject<{
10
10
  declare const META_ERROR_SCHEMA: z.ZodObject<{
11
11
  code: z.ZodOptional<z.ZodNumber>;
12
12
  errorSubcode: z.ZodOptional<z.ZodNumber>;
13
- errorUserMessage: z.ZodOptional<z.ZodString>;
13
+ errorUserMsg: z.ZodOptional<z.ZodString>;
14
14
  fbtraceId: z.ZodOptional<z.ZodString>;
15
15
  isTransient: z.ZodOptional<z.ZodBoolean>;
16
16
  message: z.ZodString;
@@ -38,6 +38,7 @@ export declare class MetaAdsApiError extends Error {
38
38
  readonly appUsage?: string;
39
39
  readonly businessUseCaseUsage?: string;
40
40
  readonly code?: number;
41
+ readonly errorUserMessage?: string;
41
42
  readonly fbtraceId?: string;
42
43
  readonly isTransient: boolean;
43
44
  readonly adAccountUsage?: string;
@@ -11,7 +11,7 @@ export const META_ADS_OAUTH_SECRET_SCHEMA = z.object({
11
11
  const META_ERROR_SCHEMA = z.looseObject({
12
12
  code: z.number().optional(),
13
13
  errorSubcode: z.number().optional(),
14
- errorUserMessage: z.string().optional(),
14
+ errorUserMsg: z.string().optional(),
15
15
  fbtraceId: z.string().optional(),
16
16
  isTransient: z.boolean().optional(),
17
17
  message: z.string(),
@@ -38,6 +38,7 @@ export class MetaAdsApiError extends Error {
38
38
  appUsage;
39
39
  businessUseCaseUsage;
40
40
  code;
41
+ errorUserMessage;
41
42
  fbtraceId;
42
43
  isTransient;
43
44
  adAccountUsage;
@@ -57,8 +58,11 @@ export class MetaAdsApiError extends Error {
57
58
  */
58
59
  constructor(options) {
59
60
  const providerError = options.error;
60
- super(providerError?.message
61
- ? `Meta Ads API error (${providerError.code ?? options.status}): ${providerError.message}`
61
+ const providerMessage = providerError?.message
62
+ ? `${providerError.message}${providerError.errorUserMsg ? ` ${providerError.errorUserMsg}` : ""}`
63
+ : undefined;
64
+ super(providerMessage
65
+ ? `Meta Ads API error (${providerError?.code ?? options.status}): ${providerMessage}`
62
66
  : `Meta Ads API request failed with status ${options.status}.`);
63
67
  this.name = "MetaAdsApiError";
64
68
  this.adAccountUsage = options.adAccountUsage;
@@ -66,6 +70,7 @@ export class MetaAdsApiError extends Error {
66
70
  this.businessUseCaseUsage = options.businessUseCaseUsage;
67
71
  this.code = providerError?.code;
68
72
  this.errorSubcode = providerError?.errorSubcode;
73
+ this.errorUserMessage = providerError?.errorUserMsg;
69
74
  this.fbtraceId = providerError?.fbtraceId;
70
75
  this.isTransient = providerError?.isTransient ?? false;
71
76
  this.retryAfter = options.retryAfter;
@@ -131,10 +136,18 @@ export function getMetaAdsApi(account) {
131
136
  url.searchParams.set(toSnakeCase(name), Array.isArray(value) ? value.join(",") : String(value));
132
137
  }
133
138
  }
134
- const body = options.body === undefined ? undefined : toFormData(options.body);
139
+ const jsonBody = options.method === "PATCH" && options.body !== undefined;
140
+ const body = options.body === undefined
141
+ ? undefined
142
+ : jsonBody
143
+ ? JSON.stringify(toMeta(options.body))
144
+ : toFormData(options.body);
135
145
  const response = await fetch(url, {
136
146
  body,
137
- headers: { Authorization: `Bearer ${accessToken}` },
147
+ headers: {
148
+ Authorization: `Bearer ${accessToken}`,
149
+ ...(jsonBody && { "Content-Type": "application/json" }),
150
+ },
138
151
  method: options.method ?? (body ? "POST" : "GET"),
139
152
  });
140
153
  const payload = parseJson(await response.text());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automate.ax/integration-contracts",
3
- "version": "0.143.0",
3
+ "version": "0.143.4",
4
4
  "description": "Shared integration payload contracts and provider primitives for Automate.ax.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -65,7 +65,7 @@
65
65
  },
66
66
  "dependencies": {
67
67
  "@anthropic-ai/sdk": "0.123.0",
68
- "@automate.ax/codec": "0.143.0",
68
+ "@automate.ax/codec": "0.143.4",
69
69
  "@cfworker/json-schema": "^4.1.1",
70
70
  "@googleapis/calendar": "^16.0.0",
71
71
  "@googleapis/forms": "^6.0.1",
@@ -25,6 +25,12 @@ export const CLICKUP_STATUS_SCHEMA = z.object({
25
25
  type: z.string().optional(),
26
26
  })
27
27
 
28
+ const CLICKUP_TASK_COUNT_SCHEMA = z
29
+ .union([z.string(), z.number()])
30
+ .nullable()
31
+ .optional()
32
+ .transform((value) => (value == null ? undefined : String(value)))
33
+
28
34
  export const CLICKUP_SPACE_SCHEMA = z.object({
29
35
  archived: z.boolean().prefault(false),
30
36
  color: z.string().nullable().optional(),
@@ -56,11 +62,7 @@ export const CLICKUP_FOLDER_SCHEMA: z.ZodType<{
56
62
  overrideStatuses: z.boolean().optional(),
57
63
  parentFolder: z.string().optional(),
58
64
  space: z.object({ id: z.string(), name: z.string().optional() }).optional(),
59
- taskCount: z
60
- .string()
61
- .nullable()
62
- .optional()
63
- .transform((value) => value ?? undefined),
65
+ taskCount: CLICKUP_TASK_COUNT_SCHEMA,
64
66
  })
65
67
 
66
68
  export const CLICKUP_LIST_SCHEMA = z.object({
@@ -80,7 +82,7 @@ export const CLICKUP_LIST_SCHEMA = z.object({
80
82
  orderindex: z.number().optional(),
81
83
  space: z.object({ id: z.string(), name: z.string().optional() }).optional(),
82
84
  statuses: CLICKUP_STATUS_SCHEMA.array().prefault([]),
83
- taskCount: z.string().nullable().optional(),
85
+ taskCount: CLICKUP_TASK_COUNT_SCHEMA,
84
86
  })
85
87
 
86
88
  export const CLICKUP_CUSTOM_FIELD_SCHEMA = z.object({
@@ -13,7 +13,7 @@ export const META_ADS_OAUTH_SECRET_SCHEMA = z.object({
13
13
  const META_ERROR_SCHEMA = z.looseObject({
14
14
  code: z.number().optional(),
15
15
  errorSubcode: z.number().optional(),
16
- errorUserMessage: z.string().optional(),
16
+ errorUserMsg: z.string().optional(),
17
17
  fbtraceId: z.string().optional(),
18
18
  isTransient: z.boolean().optional(),
19
19
  message: z.string(),
@@ -62,6 +62,7 @@ export class MetaAdsApiError extends Error {
62
62
  readonly appUsage?: string
63
63
  readonly businessUseCaseUsage?: string
64
64
  readonly code?: number
65
+ readonly errorUserMessage?: string
65
66
  readonly fbtraceId?: string
66
67
  readonly isTransient: boolean
67
68
  readonly adAccountUsage?: string
@@ -89,9 +90,12 @@ export class MetaAdsApiError extends Error {
89
90
  status: number
90
91
  }) {
91
92
  const providerError = options.error
93
+ const providerMessage = providerError?.message
94
+ ? `${providerError.message}${providerError.errorUserMsg ? ` — ${providerError.errorUserMsg}` : ""}`
95
+ : undefined
92
96
  super(
93
- providerError?.message
94
- ? `Meta Ads API error (${providerError.code ?? options.status}): ${providerError.message}`
97
+ providerMessage
98
+ ? `Meta Ads API error (${providerError?.code ?? options.status}): ${providerMessage}`
95
99
  : `Meta Ads API request failed with status ${options.status}.`,
96
100
  )
97
101
  this.name = "MetaAdsApiError"
@@ -100,6 +104,7 @@ export class MetaAdsApiError extends Error {
100
104
  this.businessUseCaseUsage = options.businessUseCaseUsage
101
105
  this.code = providerError?.code
102
106
  this.errorSubcode = providerError?.errorSubcode
107
+ this.errorUserMessage = providerError?.errorUserMsg
103
108
  this.fbtraceId = providerError?.fbtraceId
104
109
  this.isTransient = providerError?.isTransient ?? false
105
110
  this.retryAfter = options.retryAfter
@@ -189,11 +194,19 @@ export function getMetaAdsApi(account: MetaAdsResolvedAccount) {
189
194
  )
190
195
  }
191
196
  }
197
+ const jsonBody = options.method === "PATCH" && options.body !== undefined
192
198
  const body =
193
- options.body === undefined ? undefined : toFormData(options.body)
199
+ options.body === undefined
200
+ ? undefined
201
+ : jsonBody
202
+ ? JSON.stringify(toMeta(options.body))
203
+ : toFormData(options.body)
194
204
  const response = await fetch(url, {
195
205
  body,
196
- headers: { Authorization: `Bearer ${accessToken}` },
206
+ headers: {
207
+ Authorization: `Bearer ${accessToken}`,
208
+ ...(jsonBody && { "Content-Type": "application/json" }),
209
+ },
197
210
  method: options.method ?? (body ? "POST" : "GET"),
198
211
  })
199
212
  const payload = parseJson(await response.text())