Skip to content

Fix no email in creating contact params #310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions lib/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class Contact {
}
createUser({
externalId,
email,
phone,
name,
avatar,
Expand All @@ -31,6 +32,7 @@ export default class Contact {
const requestData: CreateContactRequest = {
role: Role.USER,
external_id: externalId,
email,
phone,
name,
avatar,
Expand All @@ -55,7 +57,7 @@ export default class Contact {
signed_up_at: data?.signedUpAt,
last_seen_at: data?.lastSeenAt,
owner_id: data?.ownerId,
unsubscribed_from_emails: data?.isUnsubscribedFromMails,
unsubscribed_from_emails: data?.isUnsubscribedFromEmails,
custom_attributes: data?.customAttributes,
};
return this.client.post<ContactObject>({
Expand Down Expand Up @@ -185,8 +187,7 @@ type CreateContactRequest = Pick<ContactObject, 'role'> &
>
>;

interface CreateUserData {
externalId?: CreateContactRequest['external_id'];
interface CreateUserDataBase {
phone?: CreateContactRequest['phone'];
name?: CreateContactRequest['name'];
avatar?: CreateContactRequest['avatar'];
Expand All @@ -197,16 +198,12 @@ interface CreateUserData {
customAttributes?: CreateContactRequest['custom_attributes'];
}

interface CreateLeadData {
phone?: CreateContactRequest['phone'];
name?: CreateContactRequest['name'];
avatar?: CreateContactRequest['avatar'];
signedUpAt?: CreateContactRequest['signed_up_at'];
lastSeenAt?: CreateContactRequest['last_seen_at'];
ownerId?: CreateContactRequest['owner_id'];
isUnsubscribedFromMails?: CreateContactRequest['unsubscribed_from_emails'];
customAttributes?: CreateContactRequest['custom_attributes'];
interface CreateUserData extends CreateUserDataBase {
email?: string;
externalId?: string;
}

type CreateLeadData = CreateUserDataBase;
//
interface RetrieveContactData {
id: string;
Expand Down
2 changes: 1 addition & 1 deletion lib/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ interface SnoozeConversationData {
}
//
export enum CloseConversationMessageType {
CLOSED = 'closed',
CLOSED = 'close',
}
export enum CloseConversationType {
ADMIN = 'admin',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "intercom-client",
"version": "3.1.1",
"version": "3.1.2",
"description": "Official Node bindings to the Intercom API",
"homepage": "https://github.com/intercom/intercom-node",
"bugs:": "https://github.com/intercom/intercom-node/issues",
Expand Down
39 changes: 38 additions & 1 deletion test/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Operators, Role } from '../lib/common/common.types';
import { SearchContactOrderBy } from '../lib/contact';

describe('contacts', () => {
it('should create a contact with user role', async () => {
it('should create a contact with user role with external id', async () => {
const id = '536e564f316c83104c000020';

const contact = {
Expand Down Expand Up @@ -44,6 +44,43 @@ describe('contacts', () => {
assert.deepStrictEqual(expectedReply, response);
});

it('should create a contact with user role with email', async () => {
const contact = {
role: 'user',
email: 'niko_bellic@mail.com',
phone: '+48370044567',
name: 'Niko Bellic',
avatar: 'https://nico-from-gta-iv.com/lets_go_bowling.jpg',
signed_up_at: 1638203719,
last_seen_at: 1638203719,
owner_id: 1,
unsubscribed_from_emails: true,
};

const expectedReply = {};

nock('https://api.intercom.io')
.post('/contacts', contact)
.reply(200, expectedReply);

const client = new Client({
usernameAuth: { username: 'foo', password: 'bar' },
});

const response = await client.contacts.createUser({
email: contact.email,
phone: contact.phone,
name: contact.name,
avatar: contact.avatar,
signedUpAt: contact.signed_up_at,
lastSeenAt: contact.last_seen_at,
ownerId: contact.owner_id,
isUnsubscribedFromEmails: contact.unsubscribed_from_emails,
});

assert.deepStrictEqual(expectedReply, response);
});

it('should create a contact with lead role', async () => {
const contact = {
role: 'lead',
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"importHelpers": true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By removing this line, we revert the value of importHelpers to default one - false

So what's the difference?

Importing helpers results in using ts-lib for different functions, such as exportingStar. By disabling importHelpers we force TS to generate JS code, instead of requiring ts-lib:

importHelpers: true:

(0, tslib_1.__exportStar)(require("./admin/admin.types"), exports);
(0, tslib_1.__exportStar)(require("./article/article.types"), exports);
(0, tslib_1.__exportStar)(require("./common/common.types"), exports);
(0, tslib_1.__exportStar)(require("./company/company.types"), exports);

importHelpers: false:

var __exportStar = (this && this.__exportStar) || function(m, exports) {
    for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};

"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
Expand Down