From ddfa94d65bec8d6885e987f5f3998b2caeebc500 Mon Sep 17 00:00:00 2001 From: Colm Doyle Date: Tue, 12 Dec 2023 15:55:22 +0000 Subject: [PATCH 1/4] Update the company.update method (#375) * Update the company.update method Makes it clearer that this endpoint uses the Intercom ID for a company, and not the companyID that is optionally provided during creation closes #356 * Add a createOrUpdate company method This method actually creates or updates, so add a more appropriately named method and mark the old one as deprecated/ --- lib/company.ts | 53 ++++++++++++++++++++++++++++-- test/integration/companies.test.ts | 19 ++++++++++- test/unit/company.test.ts | 6 ++-- 3 files changed, 71 insertions(+), 7 deletions(-) diff --git a/lib/company.ts b/lib/company.ts index e1d3b98f..3704a457 100644 --- a/lib/company.ts +++ b/lib/company.ts @@ -21,6 +21,9 @@ export default class Company { this.client = client; this.scroll = new Scroll(this.client, this.baseUrl); } + /** + * @deprecated Use `client.companies.createOrUpdate()` instead. + */ create({ createdAt, companyId, @@ -31,6 +34,34 @@ export default class Company { website, industry, customAttributes, + }: CreateCompanyData) { + return this.createOrUpdate({ + createdAt, + companyId, + name, + monthlySpend, + plan, + size, + website, + industry, + customAttributes, + }); + } + /** + * Create or update a company by its `companyId`. + * + * Companies are looked up via the `companyId` field. If a company with the given `companyId` does not exist, it will be created. If a company with the given `companyId` does exist, it will be updated. + **/ + createOrUpdate({ + createdAt, + companyId, + name, + monthlySpend, + plan, + size, + website, + industry, + customAttributes, }: CreateCompanyData) { const data = { remote_created_at: createdAt, @@ -49,9 +80,23 @@ export default class Company { data, }); } + + /** + * Update a single company by its `id`. + * @param id - The `id` field is required for updating a company. This is distinct from the `companyId` field on the Company object , which is an identifier for the company in your database. + * @param createdAt - The time the company was created by you. + * @param name - The name of the company. + * @param monthlySpend - The amount the company spends on your product each month. How much revenue the company generates for your business. + * Note that this will truncate floats. i.e. it only allow for whole integers, 155.98 will be truncated to 155. Note that this has an upper limit of 2**31-1 or 2147483647.. + * @param plan - The name of the plan you have associated with the company. + * @param size - The number of employees the company has. + * @param website -The URL for this company's website. Please note that the value specified here is not validated. Accepts any string. + * @param industry - The industry the company operates in. + * @param customAttributes - A hash of key/value pairs containing any other data about the company you want Intercom to store. + */ update({ + id, createdAt, - companyId, name, monthlySpend, plan, @@ -72,7 +117,7 @@ export default class Company { }; return this.client.put({ - url: `/${this.baseUrl}/${companyId}`, + url: `/${this.baseUrl}/${id}`, data, }); } @@ -160,7 +205,9 @@ interface CreateCompanyData { customAttributes?: JavascriptObject; } // -type UpdateCompanyData = CreateCompanyData; +interface UpdateCompanyData extends Omit { + id: string; +} // interface FindCompanyData { companyId?: string; diff --git a/test/integration/companies.test.ts b/test/integration/companies.test.ts index 0be07f80..be79c26a 100644 --- a/test/integration/companies.test.ts +++ b/test/integration/companies.test.ts @@ -34,10 +34,27 @@ describe('Companies', () => { assert.notEqual(response, undefined); }); + it('createOrUpdate', async () => { + const response = await client.companies.createOrUpdate({ + createdAt: dateToUnixTimestamp(new Date()), + companyId: '46029', + name: 'BestCompanyInc.', + monthlySpend: 9001, + plan: '1. Get pizzaid', + size: 62049, + website: 'http://the-best.one', + industry: 'The Best One', + customAttributes: {}, + }); + + createdCompany = response; + + assert.notEqual(response, undefined); + }); it('update', async () => { const response = await client.companies.update({ createdAt: dateToUnixTimestamp(new Date()), - companyId: createdCompany.id, + id: createdCompany.id, name: 'BestCompanyInc', monthlySpend: 9001, plan: '1. Get pizzaid', diff --git a/test/unit/company.test.ts b/test/unit/company.test.ts index 48e3e4b2..19665cb6 100644 --- a/test/unit/company.test.ts +++ b/test/unit/company.test.ts @@ -64,7 +64,7 @@ describe('companies', () => { assert.deepStrictEqual({}, response); }); it('should be updated', async () => { - const company_id = '46029'; + const id = '625e90fc55ab113b6d92175f'; const requestBody = { remote_created_at: dateToUnixTimestamp(new Date()), name: 'BestCompanyInc.', @@ -77,12 +77,12 @@ describe('companies', () => { }; nock('https://api.intercom.io') - .put(`/companies/${company_id}`, requestBody) + .put(`/companies/${id}`, requestBody) .reply(200, {}); const response = await client.companies.update({ createdAt: requestBody.remote_created_at, - companyId: company_id, + id: id, name: requestBody.name, monthlySpend: requestBody.monthly_spend, plan: requestBody.plan, From 48276f393d95e579f9d5b60cd6ddfbf0a945715f Mon Sep 17 00:00:00 2001 From: Colm Doyle Date: Tue, 12 Dec 2023 16:01:50 +0000 Subject: [PATCH 2/4] Revert "Update the company.update method (#375)" (#393) This reverts commit ddfa94d65bec8d6885e987f5f3998b2caeebc500. --- lib/company.ts | 53 ++---------------------------- test/integration/companies.test.ts | 19 +---------- test/unit/company.test.ts | 6 ++-- 3 files changed, 7 insertions(+), 71 deletions(-) diff --git a/lib/company.ts b/lib/company.ts index 3704a457..e1d3b98f 100644 --- a/lib/company.ts +++ b/lib/company.ts @@ -21,9 +21,6 @@ export default class Company { this.client = client; this.scroll = new Scroll(this.client, this.baseUrl); } - /** - * @deprecated Use `client.companies.createOrUpdate()` instead. - */ create({ createdAt, companyId, @@ -34,34 +31,6 @@ export default class Company { website, industry, customAttributes, - }: CreateCompanyData) { - return this.createOrUpdate({ - createdAt, - companyId, - name, - monthlySpend, - plan, - size, - website, - industry, - customAttributes, - }); - } - /** - * Create or update a company by its `companyId`. - * - * Companies are looked up via the `companyId` field. If a company with the given `companyId` does not exist, it will be created. If a company with the given `companyId` does exist, it will be updated. - **/ - createOrUpdate({ - createdAt, - companyId, - name, - monthlySpend, - plan, - size, - website, - industry, - customAttributes, }: CreateCompanyData) { const data = { remote_created_at: createdAt, @@ -80,23 +49,9 @@ export default class Company { data, }); } - - /** - * Update a single company by its `id`. - * @param id - The `id` field is required for updating a company. This is distinct from the `companyId` field on the Company object , which is an identifier for the company in your database. - * @param createdAt - The time the company was created by you. - * @param name - The name of the company. - * @param monthlySpend - The amount the company spends on your product each month. How much revenue the company generates for your business. - * Note that this will truncate floats. i.e. it only allow for whole integers, 155.98 will be truncated to 155. Note that this has an upper limit of 2**31-1 or 2147483647.. - * @param plan - The name of the plan you have associated with the company. - * @param size - The number of employees the company has. - * @param website -The URL for this company's website. Please note that the value specified here is not validated. Accepts any string. - * @param industry - The industry the company operates in. - * @param customAttributes - A hash of key/value pairs containing any other data about the company you want Intercom to store. - */ update({ - id, createdAt, + companyId, name, monthlySpend, plan, @@ -117,7 +72,7 @@ export default class Company { }; return this.client.put({ - url: `/${this.baseUrl}/${id}`, + url: `/${this.baseUrl}/${companyId}`, data, }); } @@ -205,9 +160,7 @@ interface CreateCompanyData { customAttributes?: JavascriptObject; } // -interface UpdateCompanyData extends Omit { - id: string; -} +type UpdateCompanyData = CreateCompanyData; // interface FindCompanyData { companyId?: string; diff --git a/test/integration/companies.test.ts b/test/integration/companies.test.ts index be79c26a..0be07f80 100644 --- a/test/integration/companies.test.ts +++ b/test/integration/companies.test.ts @@ -34,27 +34,10 @@ describe('Companies', () => { assert.notEqual(response, undefined); }); - it('createOrUpdate', async () => { - const response = await client.companies.createOrUpdate({ - createdAt: dateToUnixTimestamp(new Date()), - companyId: '46029', - name: 'BestCompanyInc.', - monthlySpend: 9001, - plan: '1. Get pizzaid', - size: 62049, - website: 'http://the-best.one', - industry: 'The Best One', - customAttributes: {}, - }); - - createdCompany = response; - - assert.notEqual(response, undefined); - }); it('update', async () => { const response = await client.companies.update({ createdAt: dateToUnixTimestamp(new Date()), - id: createdCompany.id, + companyId: createdCompany.id, name: 'BestCompanyInc', monthlySpend: 9001, plan: '1. Get pizzaid', diff --git a/test/unit/company.test.ts b/test/unit/company.test.ts index 19665cb6..48e3e4b2 100644 --- a/test/unit/company.test.ts +++ b/test/unit/company.test.ts @@ -64,7 +64,7 @@ describe('companies', () => { assert.deepStrictEqual({}, response); }); it('should be updated', async () => { - const id = '625e90fc55ab113b6d92175f'; + const company_id = '46029'; const requestBody = { remote_created_at: dateToUnixTimestamp(new Date()), name: 'BestCompanyInc.', @@ -77,12 +77,12 @@ describe('companies', () => { }; nock('https://api.intercom.io') - .put(`/companies/${id}`, requestBody) + .put(`/companies/${company_id}`, requestBody) .reply(200, {}); const response = await client.companies.update({ createdAt: requestBody.remote_created_at, - id: id, + companyId: company_id, name: requestBody.name, monthlySpend: requestBody.monthly_spend, plan: requestBody.plan, From f7426ea45fa0b7422bd03cbecfc5e09f5fd0cb14 Mon Sep 17 00:00:00 2001 From: Colm Doyle Date: Tue, 12 Dec 2023 16:07:29 +0000 Subject: [PATCH 3/4] Update package.json (#394) --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e25a5f40..028941d4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "intercom-client", - "version": "4.0.1", + "version": "5.0.0", "description": "Official Node bindings to the Intercom API", "homepage": "https://github.com/intercom/intercom-node", "bugs:": "https://github.com/intercom/intercom-node/issues", @@ -58,4 +58,4 @@ }, "license": "Apache-2.0", "packageManager": "yarn@3.1.1" -} \ No newline at end of file +} From 7d52a55cfc32e48831a016cb6fee128653e80ec5 Mon Sep 17 00:00:00 2001 From: Colm Doyle Date: Tue, 12 Dec 2023 16:19:02 +0000 Subject: [PATCH 4/4] Update README.md with maintenance mode information (#395) --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 3d004d20..b8118cd0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # intercom-node +## Maintenance mode + +The Intercom Node SDK is currently in maintenance mode whilst we consider the best way to support it. We are not currently accepting new feature requests or actively working on the SDK. + [![Circle CI](https://circleci.com/gh/intercom/intercom-node.png?style=shield)](https://circleci.com/gh/intercom/intercom-node) [![npm](https://img.shields.io/npm/v/intercom-client)](https://www.npmjs.com/package/intercom-client) ![Intercom API Version](https://img.shields.io/badge/Intercom%20API%20Version-2.6-blue)