Skip to content

Commit b7473d3

Browse files
committed
[Components] Create Blog Post - WIX
1 parent 233ece2 commit b7473d3

File tree

11 files changed

+313
-18
lines changed

11 files changed

+313
-18
lines changed

components/wix_api_key/actions/add-products-to-collection/add-products-to-collection.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "wix_api_key-add-products-to-collection",
55
name: "Add Products To Collection",
66
description: "Adds a product or products to a specified collection. [See the documentation](https://dev.wix.com/api/rest/wix-stores/catalog/collections/add-products-to-collection)",
7-
version: "0.0.1",
7+
version: "0.0.2",
88
type: "action",
99
props: {
1010
wix,

components/wix_api_key/actions/create-contact/create-contact.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "wix_api_key-create-contact",
55
name: "Create Contact",
66
description: "Creates a new contact. [See the documentation](https://dev.wix.com/api/rest/contacts/contacts/contacts-v4/create-contact)",
7-
version: "0.0.1",
7+
version: "0.0.2",
88
type: "action",
99
props: {
1010
wix,
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
import app from "../../wix_api_key.app.mjs";
2+
3+
export default {
4+
key: "wix_api_key-create-draft-post",
5+
name: "Create Draft Post",
6+
description: "Creates a new draft post. [See the documentation](https://dev.wix.com/docs/rest/business-solutions/blog/draft-posts/create-draft-post).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
title: {
12+
type: "string",
13+
label: "Title",
14+
description: "Draft post title",
15+
},
16+
featured: {
17+
type: "boolean",
18+
label: "Featured",
19+
description: "Whether the draft post is marked as featured",
20+
optional: true,
21+
},
22+
categoryIds: {
23+
type: "string[]",
24+
label: "Category IDs",
25+
description: "Category IDs of the draft post",
26+
propDefinition: [
27+
app,
28+
"categoryId",
29+
],
30+
},
31+
memberId: {
32+
description: "Draft post owner's member ID",
33+
propDefinition: [
34+
app,
35+
"memberId",
36+
],
37+
},
38+
hashtags: {
39+
type: "string[]",
40+
label: "Hashtags",
41+
description: "Hashtags of the draft post",
42+
optional: true,
43+
},
44+
commentingEnabled: {
45+
type: "boolean",
46+
label: "Commenting Enabled",
47+
description: "Whether commenting is enabled on the draft post",
48+
optional: true,
49+
},
50+
tagIds: {
51+
type: "string[]",
52+
label: "Tag IDs",
53+
description: "Tag IDs the draft post is tagged with",
54+
propDefinition: [
55+
app,
56+
"tagId",
57+
],
58+
},
59+
relatedPostIds: {
60+
type: "string[]",
61+
label: "Related Post IDs",
62+
description: "IDs of posts related to this draft post",
63+
propDefinition: [
64+
app,
65+
"postId",
66+
],
67+
},
68+
language: {
69+
type: "string",
70+
label: "Language",
71+
description: "Language the draft post is written in. 2-or-4-letter language code in [IETF BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) format. Eg. `en`",
72+
optional: true,
73+
},
74+
publish: {
75+
type: "boolean",
76+
label: "Publish",
77+
description: "Whether to publish the post after creation",
78+
optional: true,
79+
},
80+
fieldsets: {
81+
type: "string[]",
82+
label: "Fieldsets",
83+
description: "List of additional draft post fields to include in the response. For example, use the `URL` fieldset to retrieve the url field in the response in addition to the draft post's base fields. Base fields don't include any of the supported fieldset values. By default only the draft post's base fields are returned.",
84+
optional: true,
85+
options: [
86+
{
87+
label: "If the user has not set excerpt, returns the one autogenerated from content.",
88+
value: "GENERATED_EXCERPT",
89+
},
90+
{
91+
label: "Includes rich content field.",
92+
value: "RICH_CONTENT",
93+
},
94+
{
95+
label: "Includes content field.",
96+
value: "CONTENT",
97+
},
98+
{
99+
label: "Includes internal id field. Reserved for internal use.",
100+
value: "INTERNAL_ID",
101+
},
102+
{
103+
label: "Includes draft post preview URL.",
104+
value: "URL",
105+
},
106+
{
107+
label: "Unknown field.",
108+
value: "UNKNOWN",
109+
},
110+
],
111+
},
112+
},
113+
methods: {
114+
createDraftPost(args = {}) {
115+
return this.app._makeRequest({
116+
method: "POST",
117+
path: "/blog/v3/draft-posts",
118+
...args,
119+
});
120+
},
121+
},
122+
async run({ $ }) {
123+
const {
124+
createDraftPost,
125+
title,
126+
featured,
127+
categoryIds,
128+
memberId,
129+
hashtags,
130+
commentingEnabled,
131+
tagIds,
132+
relatedPostIds,
133+
language,
134+
publish,
135+
fieldsets,
136+
} = this;
137+
138+
const response = await createDraftPost({
139+
$,
140+
data: {
141+
draftPost: {
142+
title,
143+
featured,
144+
categoryIds,
145+
memberId,
146+
hashtags,
147+
commentingEnabled,
148+
tagIds,
149+
relatedPostIds,
150+
language,
151+
},
152+
publish,
153+
fieldsets,
154+
},
155+
});
156+
157+
$.export("$summary", `Successfully created draft post with ID \`${response.draftPost.id}\`.`);
158+
return response;
159+
},
160+
};

components/wix_api_key/actions/create-product/create-product.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "wix_api_key-create-product",
55
name: "Create Product",
66
description: "Creates a new product. [See the documentation](https://dev.wix.com/api/rest/wix-stores/catalog/products/create-product)",
7-
version: "0.0.1",
7+
version: "0.0.2",
88
type: "action",
99
props: {
1010
wix,

components/wix_api_key/actions/get-contact/get-contact.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "wix_api_key-get-contact",
55
name: "Get Contact",
66
description: "Retrieves information about a contact. [See the documentation](https://dev.wix.com/api/rest/contacts/contacts/contacts-v4/get-contact)",
7-
version: "0.0.1",
7+
version: "0.0.2",
88
type: "action",
99
props: {
1010
wix,

components/wix_api_key/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/wix_api_key",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Pipedream Wix Components",
55
"main": "wix_api_key.app.mjs",
66
"keywords": [
@@ -13,6 +13,6 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^1.5.1"
16+
"@pipedream/platform": "^3.0.3"
1717
}
1818
}

components/wix_api_key/sources/new-member-registered/new-member-registered.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "wix_api_key-new-member-registered",
77
name: "New Member Registered",
88
description: "Emit new event when a new member is registered. [See the documentation](https://dev.wix.com/api/rest/members/members/list-members)",
9-
version: "0.0.1",
9+
version: "0.0.2",
1010
type: "source",
1111
methods: {
1212
...common.methods,

components/wix_api_key/sources/new-order-created/new-order-created.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "wix_api_key-new-order-created",
77
name: "New Order Created",
88
description: "Emit new event when a new order is created. [See the documentation](https://dev.wix.com/api/rest/wix-stores/orders/query-orders)",
9-
version: "0.0.1",
9+
version: "0.0.2",
1010
type: "source",
1111
methods: {
1212
...common.methods,

components/wix_api_key/sources/new-product-created/new-product-created.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "wix_api_key-new-product-created",
77
name: "New Product Created",
88
description: "Emit new event when a new product is created. [See the documentation](https://dev.wix.com/api/rest/wix-stores/catalog/products/query-products)",
9-
version: "0.0.1",
9+
version: "0.0.2",
1010
type: "source",
1111
methods: {
1212
...common.methods,

components/wix_api_key/wix_api_key.app.mjs

Lines changed: 124 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,107 @@ export default {
133133
})) || [];
134134
},
135135
},
136+
categoryId: {
137+
type: "string",
138+
label: "Category ID",
139+
description: "Category ID of the draft post",
140+
optional: true,
141+
async options({ page }) {
142+
const limit = constants.DEFAULT_LIMIT;
143+
const { categories } = await this.listCategories({
144+
params: {
145+
"paging.limit": limit,
146+
"paging.offset": page * limit,
147+
},
148+
});
149+
return categories?.map(({
150+
id: value, label,
151+
}) => ({
152+
value,
153+
label,
154+
}));
155+
},
156+
},
157+
memberId: {
158+
type: "string",
159+
label: "Member ID",
160+
description: "The identifier of a member",
161+
optional: true,
162+
async options({ page }) {
163+
const limit = constants.DEFAULT_LIMIT;
164+
const { members } = await this.listMembers({
165+
params: {
166+
"paging.limit": limit,
167+
"paging.offset": page * limit,
168+
},
169+
});
170+
return members?.map(({
171+
id: value, loginEmail: label,
172+
}) => ({
173+
value,
174+
label,
175+
}));
176+
},
177+
},
178+
tagId: {
179+
type: "string",
180+
label: "Tag ID",
181+
description: "Tag ID of the draft post",
182+
optional: true,
183+
async options({ page }) {
184+
const limit = constants.DEFAULT_LIMIT;
185+
const { tags } = await this.queryTags({
186+
data: {
187+
query: {
188+
paging: {
189+
limit,
190+
offset: page * limit,
191+
},
192+
},
193+
},
194+
});
195+
return tags?.map(({
196+
id: value, label,
197+
}) => ({
198+
value,
199+
label,
200+
}));
201+
},
202+
},
203+
postId: {
204+
type: "string",
205+
label: "Post ID",
206+
description: "ID of a post",
207+
optional: true,
208+
useQuery: true,
209+
async options({
210+
page, query,
211+
filter = {
212+
title: {
213+
"$contains": query,
214+
},
215+
},
216+
}) {
217+
const limit = constants.DEFAULT_LIMIT;
218+
const { posts } = await this.queryPosts({
219+
data: {
220+
query: {
221+
filter,
222+
paging: {
223+
limit,
224+
offset: page * limit,
225+
},
226+
},
227+
},
228+
});
229+
return posts?.map(({
230+
id: value, title,
231+
}) => ({
232+
value,
233+
label: title,
234+
}));
235+
},
236+
},
136237
},
137238
methods: {
138239
_baseUrl() {
@@ -146,7 +247,9 @@ export default {
146247
},
147248
async getSiteHeaders(siteId) {
148249
if (!siteId) {
149-
return {};
250+
return {
251+
"wix-account-id": this.$auth.account_id,
252+
};
150253
}
151254
const accountId = await this.getSiteAccountId(siteId);
152255
return {
@@ -236,6 +339,26 @@ export default {
236339
...args,
237340
});
238341
},
342+
listCategories(args = {}) {
343+
return this._makeRequest({
344+
path: "/blog/v3/categories",
345+
...args,
346+
});
347+
},
348+
queryTags(args = {}) {
349+
return this._makeRequest({
350+
method: "POST",
351+
path: "/blog/v2/tags/query",
352+
...args,
353+
});
354+
},
355+
queryPosts(args = {}) {
356+
return this._makeRequest({
357+
method: "POST",
358+
path: "/blog/v3/posts/query",
359+
...args,
360+
});
361+
},
239362
createContact(args = {}) {
240363
return this._makeRequest({
241364
path: "/contacts/v4/contacts",

0 commit comments

Comments
 (0)