|
| 1 | +import app from "../../box.app.mjs"; |
| 2 | +import constants from "../../common/constants.mjs"; |
| 3 | + |
| 4 | +export default { |
| 5 | + key: "box-list-folder-items", |
| 6 | + name: "List Folder Items", |
| 7 | + description: "Lists files, folders, and web links in a Box folder. Use `0` for the root folder. Returns one page of results (default 100, max 1000). To find items by name or metadata across all folders, use **Search Content** instead. [See the documentation](https://developer.box.com/reference/get-folders-id-items/).", |
| 8 | + version: "0.0.1", |
| 9 | + type: "action", |
| 10 | + annotations: { |
| 11 | + destructiveHint: false, |
| 12 | + openWorldHint: true, |
| 13 | + readOnlyHint: true, |
| 14 | + }, |
| 15 | + props: { |
| 16 | + app, |
| 17 | + folderId: { |
| 18 | + propDefinition: [ |
| 19 | + app, |
| 20 | + "parentId", |
| 21 | + ], |
| 22 | + label: "Folder", |
| 23 | + description: "The folder to list items from. Use `0` for the root folder.", |
| 24 | + optional: false, |
| 25 | + }, |
| 26 | + fields: { |
| 27 | + propDefinition: [ |
| 28 | + app, |
| 29 | + "fields", |
| 30 | + ], |
| 31 | + description: "A comma-separated list of attributes to include in the response (e.g. `id,type,name,size,created_at`). [See available fields](https://developer.box.com/reference/get-folders-id-items/#param-fields).", |
| 32 | + }, |
| 33 | + sort: { |
| 34 | + type: "string", |
| 35 | + label: "Sort", |
| 36 | + description: "Defines the attribute by which items are sorted", |
| 37 | + optional: true, |
| 38 | + options: [ |
| 39 | + { |
| 40 | + label: "ID", |
| 41 | + value: "id", |
| 42 | + }, |
| 43 | + { |
| 44 | + label: "Name", |
| 45 | + value: "name", |
| 46 | + }, |
| 47 | + { |
| 48 | + label: "Date", |
| 49 | + value: "date", |
| 50 | + }, |
| 51 | + { |
| 52 | + label: "Size", |
| 53 | + value: "size", |
| 54 | + }, |
| 55 | + ], |
| 56 | + }, |
| 57 | + direction: { |
| 58 | + type: "string", |
| 59 | + label: "Direction", |
| 60 | + description: "The direction to sort results in", |
| 61 | + optional: true, |
| 62 | + options: [ |
| 63 | + { |
| 64 | + label: "Ascending", |
| 65 | + value: "ASC", |
| 66 | + }, |
| 67 | + { |
| 68 | + label: "Descending", |
| 69 | + value: "DESC", |
| 70 | + }, |
| 71 | + ], |
| 72 | + }, |
| 73 | + limit: { |
| 74 | + type: "integer", |
| 75 | + label: "Limit", |
| 76 | + description: "The maximum number of items to return per page (max 1000)", |
| 77 | + optional: true, |
| 78 | + default: 100, |
| 79 | + max: 1000, |
| 80 | + }, |
| 81 | + }, |
| 82 | + async run({ $ }) { |
| 83 | + const params = { |
| 84 | + limit: this.limit || constants.pageSize, |
| 85 | + usemarker: true, |
| 86 | + }; |
| 87 | + |
| 88 | + if (this.fields?.length) { |
| 89 | + params.fields = Array.isArray(this.fields) |
| 90 | + ? this.fields.join(",") |
| 91 | + : this.fields; |
| 92 | + } |
| 93 | + if (this.sort) { |
| 94 | + params.sort = this.sort; |
| 95 | + } |
| 96 | + if (this.direction) { |
| 97 | + params.direction = this.direction; |
| 98 | + } |
| 99 | + |
| 100 | + const response = await this.app.getItems({ |
| 101 | + $, |
| 102 | + folderId: this.folderId, |
| 103 | + params, |
| 104 | + }); |
| 105 | + |
| 106 | + const itemCount = response.entries?.length || 0; |
| 107 | + $.export("$summary", `Retrieved ${itemCount} item${itemCount === 1 |
| 108 | + ? "" |
| 109 | + : "s"} from folder`); |
| 110 | + |
| 111 | + return response; |
| 112 | + }, |
| 113 | +}; |
0 commit comments