Skip to content

Commit 983291f

Browse files
committed
validate property types
1 parent d3e3821 commit 983291f

File tree

4 files changed

+72
-31
lines changed

4 files changed

+72
-31
lines changed

components/notion/actions/common/base-page-builder.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export default {
8787
type: properties[property]?.type ?? property,
8888
label: properties[property]?.id || property,
8989
value: this[property] || this.properties?.[property],
90+
name: properties[property]?.name || property,
9091
}));
9192
},
9293
/**
@@ -107,7 +108,7 @@ export default {
107108
try {
108109
notionProperties[property.label] = notionProperty?.convertToNotion(property);
109110
} catch {
110-
throw new ConfigurationError(`Error converting property with label \`${property.label}\` to Notion format. Must be of type \`${NOTION_CONVERTER[property.type]?.type}\`.`);
111+
throw new ConfigurationError(`Error converting property \`${property.name}\` to Notion format. Must be of type \`${NOTION_CONVERTER[property.type]?.type}\`.`);
111112
}
112113
}
113114
}

components/notion/actions/create-page-from-database/create-page-from-database.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default {
88
key: "notion-create-page-from-database",
99
name: "Create Page from Data Source",
1010
description: "Create a page from a data source. [See the documentation](https://developers.notion.com/reference/post-page)",
11-
version: "1.0.1",
11+
version: "1.0.2",
1212
type: "action",
1313
props: {
1414
notion,

components/notion/common/notion-page-properties.mjs

Lines changed: 68 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,68 @@ const NOTION_PAGE_PROPERTIES = {
1313
type: "string",
1414
example: "New Beauty Title",
1515
options: () => undefined,
16-
convertToNotion: (property) => ({
17-
title: utils.buildTextProperty(property.value),
18-
}),
16+
convertToNotion: (property) => {
17+
if (typeof property.value !== "string") {
18+
throw new Error;
19+
}
20+
return {
21+
title: utils.buildTextProperty(property.value),
22+
};
23+
},
1924
},
2025
rich_text: {
2126
type: "string",
2227
example: "A beauty text value",
2328
options: () => undefined,
24-
convertToNotion: (property) => ({
25-
rich_text: utils.buildTextProperty(property.value),
26-
}),
29+
convertToNotion: (property) => {
30+
if (typeof property.value !== "string") {
31+
throw new Error;
32+
}
33+
return {
34+
rich_text: utils.buildTextProperty(property.value),
35+
};
36+
},
2737
},
2838
number: {
2939
type: "integer",
3040
example: "59",
3141
options: () => undefined,
32-
convertToNotion: (property) => ({
33-
number: property.value,
34-
}),
42+
convertToNotion: (property) => {
43+
if (isNaN(property.value)) {
44+
throw new Error;
45+
}
46+
return {
47+
number: property.value,
48+
};
49+
},
3550
},
3651
status: {
3752
type: "string",
3853
options: (property) => property.status?.options.map((option) => option.name),
39-
convertToNotion: (property) => ({
40-
status: {
41-
name: property.value,
42-
},
43-
}),
54+
convertToNotion: (property) => {
55+
if (typeof property.value !== "string") {
56+
throw new Error;
57+
}
58+
return {
59+
status: {
60+
name: property.value,
61+
},
62+
};
63+
},
4464
},
4565
select: {
4666
type: "string",
4767
options: (property) => property.select?.options.map((option) => option.name),
48-
convertToNotion: (property) => ({
49-
select: {
50-
name: property.value,
51-
},
52-
}),
68+
convertToNotion: (property) => {
69+
if (typeof property.value !== "string") {
70+
throw new Error;
71+
}
72+
return {
73+
select: {
74+
name: property.value,
75+
},
76+
};
77+
},
5378
},
5479
multi_select: {
5580
type: "string[]",
@@ -113,25 +138,40 @@ const NOTION_PAGE_PROPERTIES = {
113138
type: "string",
114139
example: "https://pipedream.com",
115140
options: () => undefined,
116-
convertToNotion: (property) => ({
117-
url: property.value,
118-
}),
141+
convertToNotion: (property) => {
142+
if (typeof property.value !== "string") {
143+
throw new Error;
144+
}
145+
return {
146+
url: property.value,
147+
};
148+
},
119149
},
120150
email: {
121151
type: "string",
122152
example: "[email protected]",
123153
options: () => undefined,
124-
convertToNotion: (property) => ({
125-
email: property.value,
126-
}),
154+
convertToNotion: (property) => {
155+
if (typeof property.value !== "string") {
156+
throw new Error;
157+
}
158+
return {
159+
email: property.value,
160+
};
161+
},
127162
},
128163
phone_number: {
129164
type: "string",
130165
example: "999-999-9999",
131166
options: () => undefined,
132-
convertToNotion: (property) => ({
133-
phone_number: property.value,
134-
}),
167+
convertToNotion: (property) => {
168+
if (typeof property.value !== "string") {
169+
throw new Error;
170+
}
171+
return {
172+
phone_number: property.value,
173+
};
174+
},
135175
},
136176
relation: {
137177
type: "string[]",

components/notion/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/notion",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "Pipedream Notion Components",
55
"main": "notion.app.mjs",
66
"keywords": [

0 commit comments

Comments
 (0)