Skip to content

Commit 5a4c18a

Browse files
committed
[Components] nextdoor - new action components
1 parent 4a30ccc commit 5a4c18a

File tree

10 files changed

+949
-10
lines changed

10 files changed

+949
-10
lines changed
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
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+
budgetType: {
63+
type: "string",
64+
label: "Budget Type",
65+
description: "The budget type for the ad group.",
66+
options: [
67+
"DAILY_CAP_MONEY",
68+
],
69+
},
70+
startTime: {
71+
propDefinition: [
72+
app,
73+
"startTime",
74+
],
75+
},
76+
endTime: {
77+
propDefinition: [
78+
app,
79+
"endTime",
80+
],
81+
},
82+
numberOfFrequencyCaps: {
83+
type: "integer",
84+
label: "Number Of Frequency Caps",
85+
description: "The number of frequency caps to be collected. Defaults to `1`.",
86+
default: 1,
87+
reloadProps: true,
88+
},
89+
},
90+
methods: {
91+
frequencyCapsPropsMapper(prefix) {
92+
const {
93+
[`${prefix}maxImpressions`]: maxImpressions,
94+
[`${prefix}numTimeunits`]: numTimeunits,
95+
[`${prefix}timeunit`]: timeunit,
96+
} = this;
97+
98+
return {
99+
max_impressions: maxImpressions,
100+
num_timeunits: numTimeunits,
101+
timeunit,
102+
};
103+
},
104+
getFrequencyCapsPropDefinitions({
105+
prefix,
106+
label,
107+
} = {}) {
108+
return {
109+
[`${prefix}maxImpressions`]: {
110+
type: "integer",
111+
label: `${label} - Max Impressions`,
112+
description: "The maximum number of impressions.",
113+
},
114+
[`${prefix}numTimeunits`]: {
115+
type: "integer",
116+
label: `${label} - Number of Time Units`,
117+
description: "The number of time units for frequency caps.",
118+
},
119+
[`${prefix}timeunit`]: {
120+
type: "string",
121+
label: `${label} - Time Unit`,
122+
description: "The time unit for frequency caps.",
123+
options: [
124+
"MINUTE",
125+
"MINUTES",
126+
"HOUR",
127+
"HOURS",
128+
"DAY",
129+
"DAYS",
130+
"WEEK",
131+
"WEEKS",
132+
"MONTH",
133+
"MONTHS",
134+
],
135+
},
136+
};
137+
},
138+
createAdGroup(args = {}) {
139+
return this.app.post({
140+
path: "/adgroup/create",
141+
...args,
142+
});
143+
},
144+
},
145+
async additionalProps() {
146+
const {
147+
numberOfFrequencyCaps,
148+
getFrequencyCapsPropDefinitions,
149+
} = this;
150+
151+
return utils.getAdditionalProps({
152+
numberOfFields: numberOfFrequencyCaps,
153+
fieldName: "frequency cap",
154+
getPropDefinitions: getFrequencyCapsPropDefinitions,
155+
});
156+
},
157+
async run({ $ }) {
158+
const {
159+
createAdGroup,
160+
advertiserId,
161+
campaignId,
162+
name,
163+
placements,
164+
bidAmount,
165+
bidPricingType,
166+
budgetAmount,
167+
budgetType,
168+
startTime,
169+
endTime,
170+
numberOfFrequencyCaps,
171+
frequencyCapsPropsMapper,
172+
} = this;
173+
174+
const response = await createAdGroup({
175+
$,
176+
data: {
177+
advertiser_id: advertiserId,
178+
campaign_id: campaignId,
179+
name,
180+
placements: utils.parseArray(placements),
181+
bid: {
182+
amount: bidAmount,
183+
pricing_type: bidPricingType,
184+
},
185+
budget: {
186+
amount: budgetAmount,
187+
budget_type: budgetType,
188+
},
189+
start_time: startTime,
190+
end_time: endTime,
191+
frequency_caps: utils.getFieldsProps({
192+
numberOfFields: numberOfFrequencyCaps,
193+
fieldName: "frequency cap",
194+
propsMapper: frequencyCapsPropsMapper,
195+
}),
196+
},
197+
});
198+
199+
$.export("$summary", `Successfully created ad group with ID \`${response.id}\`.`);
200+
return response;
201+
},
202+
};
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+
};

0 commit comments

Comments
 (0)