Skip to content

Commit 95a3fbd

Browse files
authored
[Components] elevio - new components (#15517)
1 parent f5b70ff commit 95a3fbd

File tree

13 files changed

+897
-9
lines changed

13 files changed

+897
-9
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import app from "../../elevio.app.mjs";
2+
3+
export default {
4+
key: "elevio-create-article",
5+
name: "Create Article",
6+
description: "Creates a new article in the Elevio knowledge base. [See the documentation](https://api-docs.elevio.help/en/articles/71-rest-api-articles).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
categoryId: {
12+
propDefinition: [
13+
app,
14+
"categoryId",
15+
],
16+
},
17+
restriction: {
18+
propDefinition: [
19+
app,
20+
"restriction",
21+
],
22+
},
23+
discoverable: {
24+
propDefinition: [
25+
app,
26+
"discoverable",
27+
],
28+
},
29+
isInternal: {
30+
propDefinition: [
31+
app,
32+
"isInternal",
33+
],
34+
},
35+
notes: {
36+
propDefinition: [
37+
app,
38+
"notes",
39+
],
40+
},
41+
status: {
42+
propDefinition: [
43+
app,
44+
"status",
45+
],
46+
},
47+
title: {
48+
propDefinition: [
49+
app,
50+
"title",
51+
],
52+
},
53+
body: {
54+
propDefinition: [
55+
app,
56+
"body",
57+
],
58+
},
59+
keywords: {
60+
propDefinition: [
61+
app,
62+
"keywords",
63+
],
64+
},
65+
tags: {
66+
propDefinition: [
67+
app,
68+
"tags",
69+
],
70+
},
71+
externalId: {
72+
propDefinition: [
73+
app,
74+
"externalId",
75+
],
76+
},
77+
},
78+
methods: {
79+
createArticle(args = {}) {
80+
return this.app.post({
81+
path: "/articles",
82+
...args,
83+
});
84+
},
85+
},
86+
async run({ $ }) {
87+
const {
88+
createArticle,
89+
externalId,
90+
restriction,
91+
discoverable,
92+
isInternal,
93+
notes,
94+
status,
95+
title,
96+
body,
97+
keywords,
98+
tags,
99+
categoryId,
100+
} = this;
101+
const response = await createArticle({
102+
$,
103+
data: {
104+
article: {
105+
external_id: externalId,
106+
restriction,
107+
discoverable,
108+
is_internal: isInternal,
109+
notes,
110+
status,
111+
category_id: categoryId,
112+
keywords,
113+
tags,
114+
translations: [
115+
{
116+
language_id: "en",
117+
title,
118+
body,
119+
},
120+
],
121+
},
122+
},
123+
});
124+
125+
$.export("$summary", `Successfully created article with ID \`${response.article.id}\`.`);
126+
return response;
127+
},
128+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import app from "../../elevio.app.mjs";
2+
3+
export default {
4+
key: "elevio-delete-article",
5+
name: "Delete Article",
6+
description: "Deletes an existing article from the Elevio knowledge base. [See the documentation](https://api-docs.elevio.help/en/articles/71-rest-api-articles).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
articleId: {
12+
propDefinition: [
13+
app,
14+
"articleId",
15+
],
16+
},
17+
},
18+
methods: {
19+
deleteArticle({
20+
articleId, ...args
21+
}) {
22+
return this.app.delete({
23+
path: `/articles/${articleId}`,
24+
...args,
25+
});
26+
},
27+
},
28+
async run({ $ }) {
29+
const {
30+
deleteArticle,
31+
articleId,
32+
} = this;
33+
34+
const response = await deleteArticle({
35+
$,
36+
articleId,
37+
});
38+
$.export("$summary", "Successfully deleted article.");
39+
return response;
40+
},
41+
};
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import app from "../../elevio.app.mjs";
2+
3+
export default {
4+
key: "elevio-update-article",
5+
name: "Update Article",
6+
description: "Updates an existing article in the Elevio knowledge base. [See the documentation](https://api-docs.elevio.help/en/articles/71-rest-api-articles).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
articleId: {
12+
propDefinition: [
13+
app,
14+
"articleId",
15+
],
16+
},
17+
categoryId: {
18+
propDefinition: [
19+
app,
20+
"categoryId",
21+
],
22+
},
23+
restriction: {
24+
optional: true,
25+
propDefinition: [
26+
app,
27+
"restriction",
28+
],
29+
},
30+
discoverable: {
31+
optional: true,
32+
propDefinition: [
33+
app,
34+
"discoverable",
35+
],
36+
},
37+
isInternal: {
38+
optional: true,
39+
propDefinition: [
40+
app,
41+
"isInternal",
42+
],
43+
},
44+
notes: {
45+
optional: true,
46+
propDefinition: [
47+
app,
48+
"notes",
49+
],
50+
},
51+
status: {
52+
optional: true,
53+
propDefinition: [
54+
app,
55+
"status",
56+
],
57+
},
58+
title: {
59+
optional: true,
60+
propDefinition: [
61+
app,
62+
"title",
63+
],
64+
},
65+
body: {
66+
optional: true,
67+
propDefinition: [
68+
app,
69+
"body",
70+
],
71+
},
72+
keywords: {
73+
propDefinition: [
74+
app,
75+
"keywords",
76+
],
77+
},
78+
tags: {
79+
propDefinition: [
80+
app,
81+
"tags",
82+
],
83+
},
84+
externalId: {
85+
propDefinition: [
86+
app,
87+
"externalId",
88+
],
89+
},
90+
},
91+
methods: {
92+
updateArticle({
93+
articleId, ...args
94+
} = {}) {
95+
return this.app.put({
96+
path: `/articles/${articleId}`,
97+
...args,
98+
});
99+
},
100+
},
101+
async run({ $ }) {
102+
const {
103+
updateArticle,
104+
articleId,
105+
externalId,
106+
restriction,
107+
discoverable,
108+
isInternal,
109+
notes,
110+
status,
111+
title,
112+
body,
113+
keywords,
114+
tags,
115+
categoryId,
116+
} = this;
117+
const response = await updateArticle({
118+
$,
119+
articleId,
120+
data: {
121+
article: {
122+
external_id: externalId,
123+
restriction,
124+
discoverable,
125+
is_internal: isInternal,
126+
notes,
127+
status,
128+
keywords,
129+
tags,
130+
category_id: categoryId,
131+
...((title || body)
132+
? {
133+
translations: [
134+
{
135+
language_id: "en",
136+
title,
137+
body,
138+
},
139+
],
140+
}
141+
: {}),
142+
},
143+
},
144+
});
145+
146+
$.export("$summary", `Successfully updated article with ID \`${response.article.id}\`.`);
147+
return response;
148+
},
149+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const BASE_URL = "https://api.elev.io";
2+
const VERSION_PATH = "/v1";
3+
const IS_FIRST_RUN = "isFirstRun";
4+
const LAST_DATE_AT = "lastDateAt";
5+
const DEFAULT_LIMIT = 100;
6+
const DEFAULT_MAX = 600;
7+
8+
export default {
9+
BASE_URL,
10+
VERSION_PATH,
11+
IS_FIRST_RUN,
12+
LAST_DATE_AT,
13+
DEFAULT_LIMIT,
14+
DEFAULT_MAX,
15+
};

components/elevio/common/utils.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
async function iterate(iterations) {
2+
const items = [];
3+
for await (const item of iterations) {
4+
items.push(item);
5+
}
6+
return items;
7+
}
8+
9+
function getNestedProperty(obj, propertyString) {
10+
const properties = propertyString.split(".");
11+
return properties.reduce((prev, curr) => prev?.[curr], obj);
12+
}
13+
14+
export default {
15+
iterate,
16+
getNestedProperty,
17+
};

0 commit comments

Comments
 (0)