Skip to content

Commit 6a5c234

Browse files
committed
[ACTION] Document360 - new components
1 parent 212cd8b commit 6a5c234

File tree

8 files changed

+383
-157
lines changed

8 files changed

+383
-157
lines changed

components/document360/actions/create-document/create-document.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "document360-create-document",
55
name: "Create Document",
66
description: "Creates a new document in Document360 from text. [See the documentation](https://apidocs.document360.com/apidocs/how-to-create-and-publish-an-article)",
7-
version: "0.0.1",
7+
version: "0.0.2",
88
type: "action",
99
props: {
1010
document360,
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import app from "../../document360.app.mjs";
2+
3+
export default {
4+
key: "document360-drive-search-files-and-folders",
5+
name: "Drive Search - Files and Folders",
6+
description: "Search for files and folders in Document360 Drive. [See the documentation](https://apidocs.document360.com/apidocs/drive-search-files-and-folders)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
searchKeyword: {
12+
type: "string",
13+
label: "Search Keyword",
14+
description: "Keyword to search file items from drive",
15+
},
16+
pageNo: {
17+
type: "integer",
18+
label: "Page Number",
19+
description: "Specify the page to retrieve. Page numbers are zero-based. Therefore, to retrieve the 10th page, you need to set `9`",
20+
optional: true,
21+
},
22+
take: {
23+
type: "integer",
24+
label: "Take",
25+
description: "The number of results per page",
26+
optional: true,
27+
},
28+
allowImagesOnly: {
29+
type: "boolean",
30+
label: "Allow Images Only",
31+
description: "Allow images only in response",
32+
optional: true,
33+
},
34+
userIds: {
35+
type: "string[]",
36+
label: "User IDs",
37+
description: "Find by userId",
38+
optional: true,
39+
propDefinition: [
40+
app,
41+
"userId",
42+
],
43+
},
44+
filterFromDate: {
45+
type: "string",
46+
label: "Filter From Date",
47+
description: "Filter using from-date (date-time format). Example: `2025-01-01T00:00:00Z`",
48+
optional: true,
49+
},
50+
filterToDate: {
51+
type: "string",
52+
label: "Filter To Date",
53+
description: "Filter using to-date (date-time format). Example: `2025-01-01T00:00:00Z`",
54+
optional: true,
55+
},
56+
filterTags: {
57+
type: "string[]",
58+
label: "Filter Tags",
59+
description: "Filter using tagIds",
60+
optional: true,
61+
},
62+
},
63+
async run({ $ }) {
64+
const {
65+
app,
66+
searchKeyword,
67+
pageNo,
68+
take,
69+
allowImagesOnly,
70+
userIds,
71+
filterFromDate,
72+
filterToDate,
73+
filterTags,
74+
} = this;
75+
76+
const response = await app.driveSearchFilesAndFolders({
77+
$,
78+
params: {
79+
searchKeyword,
80+
pageNo,
81+
take,
82+
allowImagesOnly,
83+
userIds,
84+
filterFromDate,
85+
filterToDate,
86+
filterTags,
87+
},
88+
});
89+
90+
$.export("$summary", `Successfully searched for files and folders with keyword \`${searchKeyword}\``);
91+
return response;
92+
},
93+
};
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import app from "../../document360.app.mjs";
2+
3+
export default {
4+
key: "document360-get-article",
5+
name: "Get Article",
6+
description: "Gets an article from Document360. [See the documentation](https://apidocs.document360.com/apidocs/get-article)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
projectVersionId: {
12+
propDefinition: [
13+
app,
14+
"projectVersionId",
15+
],
16+
},
17+
articleId: {
18+
propDefinition: [
19+
app,
20+
"articleId",
21+
({ projectVersionId }) => ({
22+
projectVersionId,
23+
}),
24+
],
25+
},
26+
langCode: {
27+
propDefinition: [
28+
app,
29+
"langCode",
30+
({ projectVersionId }) => ({
31+
projectVersionId,
32+
}),
33+
],
34+
default: "en",
35+
},
36+
isForDisplay: {
37+
type: "boolean",
38+
label: "Is For Display",
39+
description: "Set this to `true`, if you are displaying the article to the end-user. If `, the content of snippets or variables appears in the article. Note: If the value is true, ensure that the article content is not passed for update article endpoints.",
40+
optional: true,
41+
},
42+
isPublished: {
43+
type: "boolean",
44+
label: "Is Published",
45+
description: "`true` : You will get the latest published version of the article. (If there are no published versions, then it will return the latest version) `false` : To get the the latest version of the article",
46+
optional: true,
47+
},
48+
appendSASToken: {
49+
type: "boolean",
50+
label: "Append SAS Token",
51+
description: "Set this to `false` to exclude appending SAS token for images/files",
52+
optional: true,
53+
},
54+
},
55+
async run({ $ }) {
56+
const {
57+
app,
58+
articleId,
59+
langCode,
60+
isForDisplay,
61+
isPublished,
62+
appendSASToken,
63+
} = this;
64+
65+
const response = await app.getArticle({
66+
$,
67+
articleId,
68+
langCode,
69+
params: {
70+
isForDisplay,
71+
isPublished,
72+
appendSASToken,
73+
},
74+
});
75+
76+
$.export("$summary", `Successfully retrieved article ID \`${articleId}\` (${langCode})`);
77+
return response;
78+
},
79+
};
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import app from "../../document360.app.mjs";
2+
3+
export default {
4+
key: "document360-get-file-information",
5+
name: "Get File Information",
6+
description: "Gets file information from Document360 Drive. [See the documentation](https://apidocs.document360.com/apidocs/gets-file-information)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
folderId: {
12+
propDefinition: [
13+
app,
14+
"folderId",
15+
],
16+
},
17+
fileId: {
18+
propDefinition: [
19+
app,
20+
"fileId",
21+
({ folderId }) => ({
22+
folderId,
23+
}),
24+
],
25+
},
26+
appendSASToken: {
27+
type: "boolean",
28+
label: "Append SAS Token",
29+
description: "Set this to false to exclude appending SAS token for images/files",
30+
optional: true,
31+
},
32+
},
33+
async run({ $ }) {
34+
const {
35+
app,
36+
folderId,
37+
fileId,
38+
appendSASToken,
39+
} = this;
40+
41+
const response = await app.getFileInformation({
42+
$,
43+
folderId,
44+
fileId,
45+
params: {
46+
appendSASToken,
47+
},
48+
});
49+
50+
$.export("$summary", `Successfully retrieved file information for file ID \`${fileId}\``);
51+
return response;
52+
},
53+
};

components/document360/document360.app.mjs

Lines changed: 135 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,77 @@ export default {
3434
type: "string",
3535
label: "User ID",
3636
description: "Select a User or provide a custom User ID.",
37+
async options({ page }) {
38+
const users = await this.getUsers({
39+
params: {
40+
skip: page * 100,
41+
take: 100,
42+
},
43+
});
44+
return users?.result?.map?.(({
45+
first_name, last_name, user_id,
46+
}) => ({
47+
label: `${first_name || ""} ${last_name || ""}`.trim() || user_id,
48+
value: user_id,
49+
})) ?? [];
50+
},
51+
},
52+
folderId: {
53+
type: "string",
54+
label: "Folder ID",
55+
description: "Select a Folder or provide a custom Folder ID.",
3756
async options() {
38-
const users = await this.getUsers();
39-
return users?.result?.map?.((user) => ({
40-
label: `${user.first_name} ${user.last_name} (${user.email_id})`,
41-
value: user.user_id,
57+
const folders = await this.getFolders();
58+
return this._flattenFolders(folders?.data) ?? [];
59+
},
60+
},
61+
fileId: {
62+
type: "string",
63+
label: "File ID",
64+
description: "Select a File or provide a custom File ID.",
65+
async options({ folderId }) {
66+
if (!folderId) {
67+
return [];
68+
}
69+
const folderInfo = await this.getFolderInformation({
70+
folderId,
71+
debug: true,
72+
});
73+
return folderInfo?.data?.files?.map?.(({
74+
id: value, file_name: label,
75+
}) => ({
76+
label,
77+
value,
78+
})) ?? [];
79+
},
80+
},
81+
articleId: {
82+
type: "string",
83+
label: "Article ID",
84+
description: "Select an Article or provide a custom Article ID.",
85+
async options({ projectVersionId }) {
86+
if (!projectVersionId) {
87+
return [];
88+
}
89+
const articles = await this.getArticles(projectVersionId);
90+
return articles?.data?.map?.((article) => ({
91+
label: article.title || article.id,
92+
value: article.id,
93+
})) ?? [];
94+
},
95+
},
96+
langCode: {
97+
type: "string",
98+
label: "Language Code",
99+
description: "Select a Language Code or provide a custom Language Code.",
100+
async options({ projectVersionId }) {
101+
if (!projectVersionId) {
102+
return [];
103+
}
104+
const languages = await this.getProjectLanguages(projectVersionId);
105+
return languages?.data?.map?.((language) => ({
106+
label: `${language.language_name} (${language.language_code})`,
107+
value: language.language_code,
42108
})) ?? [];
43109
},
44110
},
@@ -82,12 +148,77 @@ export default {
82148
path: `/ProjectVersions/${projectVersionId}/articles`,
83149
});
84150
},
151+
getProjectLanguages(projectVersionId) {
152+
return this._makeRequest({
153+
path: `/Language/${projectVersionId}`,
154+
});
155+
},
85156
createDocument(args) {
86157
return this._makeRequest({
87158
method: "POST",
88159
path: "/Articles",
89160
...args,
90161
});
91162
},
163+
getFileInformation({
164+
folderId, fileId, ...args
165+
}) {
166+
return this._makeRequest({
167+
path: `/Drive/Folders/${folderId}/${fileId}`,
168+
...args,
169+
});
170+
},
171+
driveSearchFilesAndFolders(args) {
172+
return this._makeRequest({
173+
path: "/Drive/Search",
174+
...args,
175+
});
176+
},
177+
getArticle({
178+
articleId, langCode, ...args
179+
}) {
180+
return this._makeRequest({
181+
path: `/Articles/${articleId}/${langCode}`,
182+
...args,
183+
});
184+
},
185+
getFolders(args) {
186+
return this._makeRequest({
187+
path: "/Drive/Folders",
188+
...args,
189+
});
190+
},
191+
getFolderInformation({
192+
folderId, ...args
193+
}) {
194+
return this._makeRequest({
195+
path: `/Drive/Folders/${folderId}`,
196+
...args,
197+
});
198+
},
199+
_flattenFolders(folders, prefix = "") {
200+
const result = [];
201+
202+
folders?.forEach((folder) => {
203+
const folderLabel = folder.title || folder.id;
204+
const currentLabel = prefix
205+
? `${prefix} > ${folderLabel}`
206+
: folderLabel;
207+
208+
// Add the current folder
209+
result.push({
210+
label: currentLabel,
211+
value: folder.id,
212+
});
213+
214+
// Recursively add sub-folders
215+
if (folder.sub_folders && folder.sub_folders.length > 0) {
216+
const subFolders = this._flattenFolders(folder.sub_folders, currentLabel);
217+
result.push(...subFolders);
218+
}
219+
});
220+
221+
return result;
222+
},
92223
},
93224
};

0 commit comments

Comments
 (0)