|
| 1 | +import common from "../common/base.mjs"; |
| 2 | +import constants from "../../common/constants.mjs"; |
| 3 | + |
| 4 | +export default { |
| 5 | + ...common, |
| 6 | + key: "google_contacts-list-directory-contacts", |
| 7 | + name: "List Directory Contacts", |
| 8 | + description: "Lists contacts from the Google Workspace directory (domain contacts). Use this to search directory profiles and domain shared contacts, as opposed to the user's personal contacts. Requires directory.readonly OAuth scope. Returns names, email addresses, phone numbers, and other fields specified in the read mask. [See the documentation](https://developers.google.com/people/api/rest/v1/people/listDirectoryPeople)", |
| 9 | + version: "0.0.1", |
| 10 | + annotations: { |
| 11 | + destructiveHint: false, |
| 12 | + openWorldHint: true, |
| 13 | + readOnlyHint: true, |
| 14 | + }, |
| 15 | + type: "action", |
| 16 | + props: { |
| 17 | + ...common.props, |
| 18 | + fields: { |
| 19 | + propDefinition: [ |
| 20 | + common.props.googleContacts, |
| 21 | + "fields", |
| 22 | + ], |
| 23 | + }, |
| 24 | + source: { |
| 25 | + type: "string", |
| 26 | + label: "Source", |
| 27 | + description: "Directory source to return", |
| 28 | + options: constants.SOURCE_OPTIONS, |
| 29 | + }, |
| 30 | + mergeSources: { |
| 31 | + type: "string[]", |
| 32 | + label: "Merge Sources", |
| 33 | + description: "Optional. Additional data to merge into the directory sources if they are connected through verified join keys such as email addresses or phone numbers.", |
| 34 | + options: constants.MERGE_SOURCE_OPTIONS, |
| 35 | + optional: true, |
| 36 | + }, |
| 37 | + pageSize: { |
| 38 | + type: "integer", |
| 39 | + label: "Page Size", |
| 40 | + description: "Optional. The number of people to include in the response. Valid values are between 1 and 1000, inclusive. Defaults to 100 if not set", |
| 41 | + optional: true, |
| 42 | + default: 100, |
| 43 | + min: 1, |
| 44 | + max: 1000, |
| 45 | + }, |
| 46 | + pageToken: { |
| 47 | + type: "string", |
| 48 | + label: "Page Token", |
| 49 | + description: "Optional. A page token, received from a previous response nextPageToken. Provide this to retrieve the subsequent page.", |
| 50 | + optional: true, |
| 51 | + }, |
| 52 | + requestSyncToken: { |
| 53 | + type: "boolean", |
| 54 | + label: "Request Sync Token", |
| 55 | + description: "Optional. Whether the response should return nextSyncToken. It can be used to get incremental changes since the last request by setting it on the request syncToken.", |
| 56 | + optional: true, |
| 57 | + }, |
| 58 | + syncToken: { |
| 59 | + type: "string", |
| 60 | + label: "Sync Token", |
| 61 | + description: "Optional. A sync token, received from a previous response nextSyncToken Provide this to retrieve only the resources changed since the last request.", |
| 62 | + optional: true, |
| 63 | + }, |
| 64 | + }, |
| 65 | + methods: { |
| 66 | + async processResults(client) { |
| 67 | + const params = { |
| 68 | + readMask: this.fields.join(), |
| 69 | + sources: this.source, |
| 70 | + mergeSources: this.mergeSources?.join(), |
| 71 | + pageSize: this.pageSize, |
| 72 | + pageToken: this.pageToken, |
| 73 | + requestSyncToken: this.requestSyncToken, |
| 74 | + syncToken: this.syncToken, |
| 75 | + }; |
| 76 | + |
| 77 | + const response = await this.googleContacts.listDirectoryContacts(client, params); |
| 78 | + return response; |
| 79 | + }, |
| 80 | + emitSummary($, response) { |
| 81 | + const count = Array.isArray(response) |
| 82 | + ? response.length |
| 83 | + : (response?.people?.length ?? 0); |
| 84 | + $.export("$summary", `Successfully retrieved ${count} directory contacts`); |
| 85 | + }, |
| 86 | + }, |
| 87 | +}; |
0 commit comments