@automate.ax/integration-contracts 0.144.1 → 0.144.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.
- package/dist/google-ads/events.js +39 -5
- package/package.json +2 -2
- package/src/google-ads/events.ts +43 -13
|
@@ -33,7 +33,7 @@ export const googleAdsTriggerContracts = {
|
|
|
33
33
|
* @param event - Normalized Google Ads change event.
|
|
34
34
|
*/
|
|
35
35
|
export function getGoogleAdsChangeEventTypes(event) {
|
|
36
|
-
const semanticType = getSemanticEventType(event.event
|
|
36
|
+
const semanticType = getSemanticEventType(event.event);
|
|
37
37
|
return semanticType
|
|
38
38
|
? ["googleAds.change", semanticType]
|
|
39
39
|
: ["googleAds.change"];
|
|
@@ -41,13 +41,19 @@ export function getGoogleAdsChangeEventTypes(event) {
|
|
|
41
41
|
/**
|
|
42
42
|
* Maps provider resource and operation enums to public event types.
|
|
43
43
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
44
|
+
* Google reports status-based removal of campaigns, ad groups, and ads as an
|
|
45
|
+
* update. Treat the terminal status as removal so the public event matches the
|
|
46
|
+
* user-visible mutation.
|
|
47
|
+
*
|
|
48
|
+
* @param event - Normalized provider change event.
|
|
46
49
|
*/
|
|
47
|
-
function getSemanticEventType(
|
|
50
|
+
function getSemanticEventType(event) {
|
|
51
|
+
const operation = isStatusRemoval(event)
|
|
52
|
+
? "REMOVE"
|
|
53
|
+
: event.resourceChangeOperation;
|
|
48
54
|
if (operation === "UNSPECIFIED" || operation === "UNKNOWN")
|
|
49
55
|
return undefined;
|
|
50
|
-
switch (
|
|
56
|
+
switch (event.changeResourceType) {
|
|
51
57
|
case "AD_GROUP":
|
|
52
58
|
return {
|
|
53
59
|
CREATE: "googleAds.adGroup.created",
|
|
@@ -94,3 +100,31 @@ function getSemanticEventType(resource, operation) {
|
|
|
94
100
|
return undefined;
|
|
95
101
|
}
|
|
96
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Returns whether Google encoded a status-based resource removal as update.
|
|
105
|
+
*
|
|
106
|
+
* @param event - Normalized provider change event.
|
|
107
|
+
*/
|
|
108
|
+
function isStatusRemoval(event) {
|
|
109
|
+
if (event.resourceChangeOperation !== "UPDATE")
|
|
110
|
+
return false;
|
|
111
|
+
let resourceKey;
|
|
112
|
+
switch (event.changeResourceType) {
|
|
113
|
+
case "AD_GROUP":
|
|
114
|
+
resourceKey = "adGroup";
|
|
115
|
+
break;
|
|
116
|
+
case "AD_GROUP_AD":
|
|
117
|
+
resourceKey = "adGroupAd";
|
|
118
|
+
break;
|
|
119
|
+
case "CAMPAIGN":
|
|
120
|
+
resourceKey = "campaign";
|
|
121
|
+
break;
|
|
122
|
+
default:
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
const resource = event.newResource?.[resourceKey];
|
|
126
|
+
return (typeof resource === "object" &&
|
|
127
|
+
resource !== null &&
|
|
128
|
+
!Array.isArray(resource) &&
|
|
129
|
+
resource.status === "REMOVED");
|
|
130
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automate.ax/integration-contracts",
|
|
3
|
-
"version": "0.144.
|
|
3
|
+
"version": "0.144.2",
|
|
4
4
|
"description": "Shared integration payload contracts and provider primitives for Automate.ax.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"@anthropic-ai/sdk": "0.123.0",
|
|
69
|
-
"@automate.ax/codec": "0.144.
|
|
69
|
+
"@automate.ax/codec": "0.144.2",
|
|
70
70
|
"@cfworker/json-schema": "^4.1.1",
|
|
71
71
|
"@googleapis/calendar": "^16.0.0",
|
|
72
72
|
"@googleapis/forms": "^6.0.1",
|
package/src/google-ads/events.ts
CHANGED
|
@@ -44,10 +44,7 @@ export type GoogleAdsEventType = keyof typeof googleAdsTriggerContracts
|
|
|
44
44
|
export function getGoogleAdsChangeEventTypes(
|
|
45
45
|
event: z.output<typeof GOOGLE_ADS_CHANGE_EVENT_PAYLOAD_SCHEMA>,
|
|
46
46
|
): GoogleAdsEventType[] {
|
|
47
|
-
const semanticType = getSemanticEventType(
|
|
48
|
-
event.event.changeResourceType,
|
|
49
|
-
event.event.resourceChangeOperation,
|
|
50
|
-
)
|
|
47
|
+
const semanticType = getSemanticEventType(event.event)
|
|
51
48
|
return semanticType
|
|
52
49
|
? ["googleAds.change", semanticType]
|
|
53
50
|
: ["googleAds.change"]
|
|
@@ -56,19 +53,20 @@ export function getGoogleAdsChangeEventTypes(
|
|
|
56
53
|
/**
|
|
57
54
|
* Maps provider resource and operation enums to public event types.
|
|
58
55
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
56
|
+
* Google reports status-based removal of campaigns, ad groups, and ads as an
|
|
57
|
+
* update. Treat the terminal status as removal so the public event matches the
|
|
58
|
+
* user-visible mutation.
|
|
59
|
+
*
|
|
60
|
+
* @param event - Normalized provider change event.
|
|
61
61
|
*/
|
|
62
62
|
function getSemanticEventType(
|
|
63
|
-
|
|
64
|
-
typeof GOOGLE_ADS_CHANGE_EVENT_PAYLOAD_SCHEMA
|
|
65
|
-
>["event"]["changeResourceType"],
|
|
66
|
-
operation: z.output<
|
|
67
|
-
typeof GOOGLE_ADS_CHANGE_EVENT_PAYLOAD_SCHEMA
|
|
68
|
-
>["event"]["resourceChangeOperation"],
|
|
63
|
+
event: z.output<typeof GOOGLE_ADS_CHANGE_EVENT_PAYLOAD_SCHEMA>["event"],
|
|
69
64
|
): GoogleAdsEventType | undefined {
|
|
65
|
+
const operation = isStatusRemoval(event)
|
|
66
|
+
? "REMOVE"
|
|
67
|
+
: event.resourceChangeOperation
|
|
70
68
|
if (operation === "UNSPECIFIED" || operation === "UNKNOWN") return undefined
|
|
71
|
-
switch (
|
|
69
|
+
switch (event.changeResourceType) {
|
|
72
70
|
case "AD_GROUP":
|
|
73
71
|
return (
|
|
74
72
|
{
|
|
@@ -129,3 +127,35 @@ function getSemanticEventType(
|
|
|
129
127
|
return undefined
|
|
130
128
|
}
|
|
131
129
|
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Returns whether Google encoded a status-based resource removal as update.
|
|
133
|
+
*
|
|
134
|
+
* @param event - Normalized provider change event.
|
|
135
|
+
*/
|
|
136
|
+
function isStatusRemoval(
|
|
137
|
+
event: z.output<typeof GOOGLE_ADS_CHANGE_EVENT_PAYLOAD_SCHEMA>["event"],
|
|
138
|
+
) {
|
|
139
|
+
if (event.resourceChangeOperation !== "UPDATE") return false
|
|
140
|
+
let resourceKey: "adGroup" | "adGroupAd" | "campaign"
|
|
141
|
+
switch (event.changeResourceType) {
|
|
142
|
+
case "AD_GROUP":
|
|
143
|
+
resourceKey = "adGroup"
|
|
144
|
+
break
|
|
145
|
+
case "AD_GROUP_AD":
|
|
146
|
+
resourceKey = "adGroupAd"
|
|
147
|
+
break
|
|
148
|
+
case "CAMPAIGN":
|
|
149
|
+
resourceKey = "campaign"
|
|
150
|
+
break
|
|
151
|
+
default:
|
|
152
|
+
return false
|
|
153
|
+
}
|
|
154
|
+
const resource = event.newResource?.[resourceKey]
|
|
155
|
+
return (
|
|
156
|
+
typeof resource === "object" &&
|
|
157
|
+
resource !== null &&
|
|
158
|
+
!Array.isArray(resource) &&
|
|
159
|
+
resource.status === "REMOVED"
|
|
160
|
+
)
|
|
161
|
+
}
|