From 5585171c0d9592dbd8ffbd7f56caa6da55c670e8 Mon Sep 17 00:00:00 2001 From: YIFAN WU Date: Thu, 30 Nov 2023 11:23:33 -0500 Subject: [PATCH] Contact group endpoint --- src/resources/contacts.ts | 24 ++++++ src/test.mjs | 142 +++++++++++++++++++++++++++++++ tests/resources/contacts.spec.ts | 19 +++++ 3 files changed, 185 insertions(+) create mode 100644 src/test.mjs diff --git a/src/resources/contacts.ts b/src/resources/contacts.ts index 36fefdde..67a52ecc 100644 --- a/src/resources/contacts.ts +++ b/src/resources/contacts.ts @@ -5,6 +5,7 @@ import { ListContactQueryParams, FindContactQueryParams, UpdateContactRequest, + ContactGroup, } from '../models/contacts.js'; import { NylasResponse, @@ -62,6 +63,13 @@ interface DestroyContactParams { contactId: string; } +/** + * @property identifier The identifier of the grant to act upon + */ +interface ListContactGroupParams { + identifier: string; +} + /** * Nylas Contacts API * @@ -150,4 +158,20 @@ export class Contacts extends Resource { overrides, }); } + + /** + * Return a Contact Group + * @return The list of Contact Groups + */ + public groups({ + identifier, + overrides, + }: ListContactGroupParams & Overrides): Promise< + NylasListResponse + > { + return super._list({ + path: `/v3/grants/${identifier}/contacts/groups`, + overrides, + }); + } } diff --git a/src/test.mjs b/src/test.mjs new file mode 100644 index 00000000..6a167516 --- /dev/null +++ b/src/test.mjs @@ -0,0 +1,142 @@ +import Nylas from 'nylas'; +import { writeFile } from 'fs/promises'; +import fs from 'fs'; + +// CLIENT_ID="72c799a6-d779-47dd-b6d0-6c385978461c" +// CLIENT_SECRET="FU8JtPGBH6QKfmH39oh7ty4c0C6EAFUVQ" +// ACCESS_TOKEN="SLrmS7C_voMCb-SFH6KD9JYRMmvbx9YRwuQdAsDXINaz2siYYWWa4dqHB55d5QMmerXxy1KyhCeNuUvo4BHEW4YlRnsKUH_2VOJSD5_4hsDmCygBan_kHM633aoMh-x_OAusD3zxffyvXCN5CmCmXFSEfVfoMVY-q482Y1U2bFc" +// API_KEY = "7cded214-541e-4707-bb39-83ba3a970fef" +// API_KEY_SECRET = "nyk_v0_K6fNLrJqriAAfJfcn8ioGKIs5PI5VXB5NOgzwV0t8xycQQPDe1PHXXP2cxM1vk3B" + +const identifier = '5b351f15-e7ea-49d4-a2bd-d76b26cadbaf'; +const attachmentId = + 'v0:c21hbGxfdGV4dF9maWxlLnR4dA==:dGV4dC9wbGFpbjsgY2hhcnNldD0iVVMtQVNDSUkiOyBuYW1lPSJzbWFsbF90ZXh0X2ZpbGUudHh0Ig==:13'; +const messageId = '18bfe0e44c87b034'; + +const nylas = new Nylas({ + apiKey: + 'nyk_v0_K6fNLrJqriAAfJfcn8ioGKIs5PI5VXB5NOgzwV0t8xycQQPDe1PHXXP2cxM1vk3B', + apiUri: 'https://api-staging.us.nylas.com', +}); + +// nylas.drafts +// .list({ +// identifier: '5b351f15-e7ea-49d4-a2bd-d76b26cadbaf', +// queryParams: { subject: 'Test message with attachment' }, +// }) +// .then(drafts => { +// console.log(drafts); +// if (!!drafts?.data.length && !!drafts.data[0].attachments.length) { +// const attachment = drafts.data[0].attachments[0]; +// console.log({ attachment }); +// } +// }); + +// nylas.messages +// .list({ +// identifier: '5b351f15-e7ea-49d4-a2bd-d76b26cadbaf', +// queryParams: { subject: 'Test message with attachment' }, +// }) +// .then(messages => { +// console.log(messages); +// if (!!messages?.data.length && !!messages.data[0].attachments.length) { +// const attachment = messages.data[0].attachments[0]; +// console.log({ attachment }); +// } +// }); + +// nylas.messages +// .find({ +// identifier: '5b351f15-e7ea-49d4-a2bd-d76b26cadbaf', +// messageId: '18bfe0e44c87b034', +// }) +// .then(message => { +// console.log({ message }); +// if (message?.data?.attachments?.length) { +// const attachment = message.data.attachments[0]; +// console.log({ attachment }); +// } +// }); + +const SampleContact = { + birthday: '1960-12-31', + company_name: 'Nylas', + emails: [ + { + email: 'clothoff@gmail.com', + type: 'home', + }, + ], + given_name: 'Yifan', + im_addresses: [ + { + type: 'gtalk', + im_address: 'myaimaddressOrUsername', + }, + ], + job_title: 'Software Engineer', + manager_name: 'Bill the manager', + nickname: 'YF', + notes: 'Loves ramen', + office_location: '123 Main Street', + phone_numbers: [ + { + number: '1 800 123 4567', + type: 'business', + }, + ], + physical_addresses: [ + { + format: 'string', + type: 'work', + street_address: 'string', + city: 'string', + postal_code: 'string', + state: 'string', + country: 'string', + }, + ], + suffix: 'string', + surname: 'string', + web_pages: [ + { + type: 'profile', + url: 'string', + }, + ], + group: 'string', +}; + +// nylas.contacts +// .list({ +// identifier, +// }) +// .then(contact => { +// console.log(contact); +// }); + +// nylas.contacts +// .find({ +// identifier, +// contactId: 'c3227423799387848682', +// }) +// .then(contact => { +// console.log(contact); +// }); + +// nylas.contacts +// .destroy({ +// identifier, +// contactId: 'c3227423799387848682', +// }) +// .then(contact => { +// console.log(contact); +// }); + +nylas.contacts + .contactGroups({ + identifier, + }) + .then(contact => { + console.log(contact); + }); \ No newline at end of file diff --git a/tests/resources/contacts.spec.ts b/tests/resources/contacts.spec.ts index 65a525e0..b634fee0 100644 --- a/tests/resources/contacts.spec.ts +++ b/tests/resources/contacts.spec.ts @@ -236,4 +236,23 @@ describe('Contacts', () => { }); }); }); + + describe('contact group', () => { + it('should call apiClient.request with the correct params', async () => { + await contacts.groups({ + identifier: 'id123', + overrides: { + apiUri: 'https://test.api.nylas.com', + }, + }); + + expect(apiClient.request).toHaveBeenCalledWith({ + method: 'GET', + path: '/v3/grants/id123/contacts/groups', + overrides: { + apiUri: 'https://test.api.nylas.com', + }, + }); + }); + }); });