Skip to content

Commit

Permalink
Contact group endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
yifanplanet committed Nov 30, 2023
1 parent eeb2ed8 commit 5585171
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/resources/contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ListContactQueryParams,
FindContactQueryParams,
UpdateContactRequest,
ContactGroup,
} from '../models/contacts.js';
import {
NylasResponse,
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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<ContactGroup>
> {
return super._list({
path: `/v3/grants/${identifier}/contacts/groups`,
overrides,
});
}
}
142 changes: 142 additions & 0 deletions src/test.mjs
Original file line number Diff line number Diff line change
@@ -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: '[email protected]',
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);
});
19 changes: 19 additions & 0 deletions tests/resources/contacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
});
});
});
});

0 comments on commit 5585171

Please sign in to comment.