Skip to content

Commit a909b52

Browse files
authored
[Components] nextdoor - new action components (#15306)
1 parent 98e0ee8 commit a909b52

File tree

10 files changed

+934
-8
lines changed

10 files changed

+934
-8
lines changed
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
import app from "../../nextdoor.app.mjs";
2+
import utils from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "nextdoor-create-ad-group",
6+
name: "Create Ad Group",
7+
description: "Creates an ad group based on the input payload for an existing campaign. [See the documentation](https://developer.nextdoor.com/reference/adgroup-create).",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
advertiserId: {
13+
propDefinition: [
14+
app,
15+
"advertiserId",
16+
],
17+
},
18+
campaignId: {
19+
propDefinition: [
20+
app,
21+
"campaignId",
22+
({ advertiserId }) => ({
23+
advertiserId,
24+
}),
25+
],
26+
},
27+
name: {
28+
description: "The name of the ad group.",
29+
propDefinition: [
30+
app,
31+
"name",
32+
],
33+
},
34+
placements: {
35+
type: "string[]",
36+
label: "Placements",
37+
description: "The placements for the ad group.",
38+
options: [
39+
"RHR",
40+
"FEED",
41+
"FSF",
42+
],
43+
},
44+
bidAmount: {
45+
type: "string",
46+
label: "Bid Amount",
47+
description: "The bid amount for the ad group. The value must be a string in the format `USD 10` as an example.",
48+
},
49+
bidPricingType: {
50+
type: "string",
51+
label: "Bid Pricing Type",
52+
description: "The bid pricing type for the ad group. The value must be one of `CPM`.",
53+
options: [
54+
"CPM",
55+
],
56+
},
57+
budgetAmount: {
58+
type: "string",
59+
label: "Budget Amount",
60+
description: "The budget amount for the ad group. The value must be a string in the format `USD 10` as an example.",
61+
},
62+
startTime: {
63+
propDefinition: [
64+
app,
65+
"startTime",
66+
],
67+
},
68+
endTime: {
69+
propDefinition: [
70+
app,
71+
"endTime",
72+
],
73+
},
74+
numberOfFrequencyCaps: {
75+
type: "integer",
76+
label: "Number Of Frequency Caps",
77+
description: "The number of frequency caps to be collected. Defaults to `1`.",
78+
default: 1,
79+
reloadProps: true,
80+
},
81+
},
82+
methods: {
83+
frequencyCapsPropsMapper(prefix) {
84+
const {
85+
[`${prefix}maxImpressions`]: maxImpressions,
86+
[`${prefix}numTimeunits`]: numTimeunits,
87+
[`${prefix}timeunit`]: timeunit,
88+
} = this;
89+
90+
return {
91+
max_impressions: maxImpressions,
92+
num_timeunits: numTimeunits,
93+
timeunit,
94+
};
95+
},
96+
getFrequencyCapsPropDefinitions({
97+
prefix,
98+
label,
99+
} = {}) {
100+
return {
101+
[`${prefix}maxImpressions`]: {
102+
type: "integer",
103+
label: `${label} - Max Impressions`,
104+
description: "The maximum number of impressions.",
105+
},
106+
[`${prefix}numTimeunits`]: {
107+
type: "integer",
108+
label: `${label} - Number of Time Units`,
109+
description: "The number of time units for frequency caps.",
110+
},
111+
[`${prefix}timeunit`]: {
112+
type: "string",
113+
label: `${label} - Time Unit`,
114+
description: "The time unit for frequency caps.",
115+
options: [
116+
"MINUTE",
117+
"HOUR",
118+
"DAY",
119+
"WEEK",
120+
"MONTH",
121+
],
122+
},
123+
};
124+
},
125+
createAdGroup(args = {}) {
126+
return this.app.post({
127+
path: "/adgroup/create",
128+
...args,
129+
});
130+
},
131+
},
132+
async additionalProps() {
133+
const {
134+
numberOfFrequencyCaps,
135+
getFrequencyCapsPropDefinitions,
136+
} = this;
137+
138+
return utils.getAdditionalProps({
139+
numberOfFields: numberOfFrequencyCaps,
140+
fieldName: "frequency cap",
141+
getPropDefinitions: getFrequencyCapsPropDefinitions,
142+
});
143+
},
144+
async run({ $ }) {
145+
const {
146+
createAdGroup,
147+
advertiserId,
148+
campaignId,
149+
name,
150+
placements,
151+
bidAmount,
152+
bidPricingType,
153+
budgetAmount,
154+
startTime,
155+
endTime,
156+
numberOfFrequencyCaps,
157+
frequencyCapsPropsMapper,
158+
} = this;
159+
160+
const response = await createAdGroup({
161+
$,
162+
data: {
163+
advertiser_id: advertiserId,
164+
campaign_id: campaignId,
165+
name,
166+
placements: utils.parseArray(placements),
167+
bid: {
168+
amount: bidAmount,
169+
pricing_type: bidPricingType,
170+
},
171+
budget: {
172+
amount: budgetAmount,
173+
budget_type: "DAILY_CAP_MONEY",
174+
},
175+
start_time: startTime,
176+
end_time: endTime,
177+
frequency_caps: utils.getFieldsProps({
178+
numberOfFields: numberOfFrequencyCaps,
179+
fieldName: "frequency cap",
180+
propsMapper: frequencyCapsPropsMapper,
181+
}),
182+
},
183+
});
184+
185+
$.export("$summary", `Successfully created ad group with ID \`${response.id}\`.`);
186+
return response;
187+
},
188+
};
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import app from "../../nextdoor.app.mjs";
2+
3+
export default {
4+
key: "nextdoor-create-ad",
5+
name: "Create Ad",
6+
description: "Creates an ad based on the input payload for an existing NAM ad group. [See the documentation](https://developer.nextdoor.com/reference/ad-create).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
advertiserId: {
12+
propDefinition: [
13+
app,
14+
"advertiserId",
15+
],
16+
},
17+
campaignId: {
18+
propDefinition: [
19+
app,
20+
"campaignId",
21+
({ advertiserId }) => ({
22+
advertiserId,
23+
}),
24+
],
25+
},
26+
adGroupId: {
27+
propDefinition: [
28+
app,
29+
"adGroupId",
30+
({
31+
advertiserId,
32+
campaignId,
33+
}) => ({
34+
advertiserId,
35+
campaignId,
36+
}),
37+
],
38+
},
39+
creativeId: {
40+
propDefinition: [
41+
app,
42+
"creativeId",
43+
({ advertiserId }) => ({
44+
advertiserId,
45+
}),
46+
],
47+
},
48+
name: {
49+
description: "The name of the ad.",
50+
propDefinition: [
51+
app,
52+
"name",
53+
],
54+
},
55+
},
56+
methods: {
57+
createAd(args = {}) {
58+
return this.app.post({
59+
path: "/ad/create",
60+
...args,
61+
});
62+
},
63+
},
64+
async run({ $ }) {
65+
const {
66+
createAd,
67+
advertiserId,
68+
adGroupId,
69+
creativeId,
70+
name,
71+
} = this;
72+
73+
const response = await createAd({
74+
$,
75+
data: {
76+
advertiser_id: advertiserId,
77+
adgroup_id: adGroupId,
78+
creative_id: creativeId,
79+
name,
80+
},
81+
});
82+
83+
$.export("$summary", `Successfully created ad with ID \`${response.id}\`.`);
84+
return response;
85+
},
86+
};
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import app from "../../nextdoor.app.mjs";
2+
3+
export default {
4+
key: "nextdoor-create-advertiser",
5+
name: "Create Advertiser",
6+
description: "Creates an advertiser that is tied to the NAM profile the API credentials are tied to. [See the documentation](https://developer.nextdoor.com/reference/advertiser-create).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
name: {
12+
description: "The name of the advertiser.",
13+
propDefinition: [
14+
app,
15+
"name",
16+
],
17+
},
18+
websiteUrl: {
19+
propDefinition: [
20+
app,
21+
"websiteUrl",
22+
],
23+
},
24+
categoryId: {
25+
propDefinition: [
26+
app,
27+
"categoryId",
28+
],
29+
},
30+
},
31+
methods: {
32+
createAdvertiser(args = {}) {
33+
return this.app.post({
34+
path: "/advertiser/create",
35+
...args,
36+
});
37+
},
38+
},
39+
async run({ $ }) {
40+
const {
41+
createAdvertiser,
42+
name,
43+
websiteUrl,
44+
categoryId,
45+
} = this;
46+
47+
const response = await createAdvertiser({
48+
$,
49+
data: {
50+
name,
51+
website_url: websiteUrl,
52+
category_id: categoryId,
53+
},
54+
});
55+
56+
$.export("$summary", `Successfully created advertiser with ID \`${response.id}\`.`);
57+
return response;
58+
},
59+
};
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import app from "../../nextdoor.app.mjs";
2+
3+
export default {
4+
key: "nextdoor-create-campaign",
5+
name: "Create Campaign",
6+
description: "Creates a campaign. [See the documentation](https://developer.nextdoor.com/reference/campaign-create).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
advertiserId: {
12+
propDefinition: [
13+
app,
14+
"advertiserId",
15+
],
16+
},
17+
name: {
18+
description: "The name of the campaign.",
19+
propDefinition: [
20+
app,
21+
"name",
22+
],
23+
},
24+
objective: {
25+
propDefinition: [
26+
app,
27+
"objective",
28+
],
29+
},
30+
},
31+
methods: {
32+
createCampaign(args = {}) {
33+
return this.app.post({
34+
path: "/campaign/create",
35+
...args,
36+
});
37+
},
38+
},
39+
async run({ $ }) {
40+
const {
41+
createCampaign,
42+
advertiserId,
43+
name,
44+
objective,
45+
} = this;
46+
47+
const response = await createCampaign({
48+
$,
49+
data: {
50+
advertiser_id: advertiserId,
51+
name,
52+
objective,
53+
},
54+
});
55+
56+
$.export("$summary", `Successfully created campaign with ID \`${response.id}\`.`);
57+
return response;
58+
},
59+
};

0 commit comments

Comments
 (0)