Skip to content

Commit 1df9c62

Browse files
authored
Merge branch 'master' into patch-1
2 parents 1be0fb5 + fafcaf8 commit 1df9c62

File tree

9 files changed

+96
-18
lines changed

9 files changed

+96
-18
lines changed

.circleci/config.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
version: 2
2+
jobs:
3+
build:
4+
docker:
5+
- image: circleci/node:8-browsers
6+
7+
working_directory: ~/intercom-node
8+
9+
environment:
10+
- YARN_VERSION: 1.7.0
11+
12+
steps:
13+
- checkout
14+
- run: export PATH="${PATH}:/home/circleci/.yarn/bin"
15+
- run:
16+
name: Install Yarn
17+
command: |
18+
if [[ ! -e ~/.yarn/bin/yarn || $(yarn --version) != "${YARN_VERSION}" ]]; then
19+
echo "Download and install Yarn."
20+
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version $YARN_VERSION
21+
else
22+
echo "The correct version of Yarn is already installed."
23+
fi
24+
- run: yarn
25+
- run: yarn test
26+
27+
notify:
28+
webhooks:
29+
- url: https://muster.intercom.io/circle_webhooks

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#### Why?
2+
Why are you making this change?
3+
4+
#### How?
5+
Technical details on your change

.travis.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# intercom-node
22
> Official Node bindings to the Intercom API
33
4-
[![Build Status](https://travis-ci.org/intercom/intercom-node.svg?branch=master)](https://travis-ci.org/intercom/intercom-node)
4+
[![Circle CI](https://circleci.com/gh/intercom/intercom-node.png?style=badge)](https://circleci.com/gh/intercom/intercom-node)
55

66
[![npm version](https://badge.fury.io/js/intercom-client.svg)](http://badge.fury.io/js/intercom-client)
77

@@ -143,8 +143,14 @@ client.users.find({ email: '[email protected]' }, callback);
143143
```
144144

145145
```node
146-
// Delete user by id
147-
client.users.delete({ id: '1234' }, callback);
146+
// Archive user by id (https://developers.intercom.com/v2.0/reference#archive-a-user)
147+
client.users.archive({ id: '1234' }, callback);
148+
```
149+
150+
```node
151+
// Permanently delete a user user by id (https://developers.intercom.com/v2.0/reference#delete-users)
152+
const intercomUserId = '123'
153+
client.users.requestPermanentDeletion(intercomUserId, callback);
148154
```
149155

150156
## Leads

lib/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export default class Client {
145145
if (f.length >= 2) {
146146
if (res && res.body && res.body.type === 'error.list') {
147147
let message = null;
148-
if (Array.isArray(res.body.errors) && res.body.errors[0] && 'message' in res.body.errors) {
148+
if (Array.isArray(res.body.errors) && res.body.errors[0] && 'message' in res.body.errors[0]) {
149149
// Try to use the first errors message
150150
message = res.body.errors[0].message;
151151
}

lib/user.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import Bulk from './bulk';
22
import Scroll from './scroll';
3+
import { deprecate } from 'util';
34

45
export default class User {
56
constructor(client) {
67
this.client = client;
78
this.scroll = new Scroll(this.client, 'user');
9+
10+
// Keep this API around but mark it deprecated
11+
this.delete = deprecate(this.archive.bind(this), 'intercom-client - user.delete: Use user.archive instead');
812
}
913
create(data, f) {
1014
return this.client.post('/users', data, f);
@@ -27,7 +31,7 @@ export default class User {
2731
return this.client.get(`/users`, { email: params.email }, f);
2832
}
2933
}
30-
delete(params, f) {
34+
archive(params, f) {
3135
if (params.id) {
3236
return this.client.delete(`/users/${params.id}`, {}, f);
3337
} else if (params.user_id) {
@@ -39,4 +43,7 @@ export default class User {
3943
bulk(params, f) {
4044
return (new Bulk(this.client, 'user').bulk(params, f));
4145
}
46+
requestPermanentDeletion(intercom_user_id, f) {
47+
return this.client.post('/user_delete_requests', { intercom_user_id }, f);
48+
}
4249
}

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "intercom-client",
3-
"version": "2.9.3",
3+
"version": "2.10.2",
44
"description": "Official Node bindings to the Intercom API",
55
"homepage": "https://github.com/intercom/intercom-node",
66
"bugs:": "https://github.com/intercom/intercom-node/issues",
@@ -20,8 +20,7 @@
2020
"dependencies": {
2121
"bluebird": "^3.3.4",
2222
"htmlencode": "^0.0.4",
23-
"request": "^2.83.0",
24-
"sinon": "^4.1.3"
23+
"request": "^2.83.0"
2524
},
2625
"devDependencies": {
2726
"babel-core": "^6.7.4",
@@ -36,7 +35,8 @@
3635
"gulp-mocha": "^2.0.0",
3736
"gulp-nsp": "^2.4.2",
3837
"gulp-plumber": "^1.1.0",
39-
"nock": "7.5.0"
38+
"nock": "7.5.0",
39+
"sinon": "^6.1.4"
4040
},
4141
"scripts": {
4242
"prepublish": "gulp prepublish",

test/errors.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ describe('errors', () => {
4545
assert.strictEqual(err.statusCode, 401);
4646
assert.strictEqual(err.body.request_id, 'b2i3ri5909msvfqskol0');
4747
assert.deepStrictEqual(err.body.errors, [{ code: 'token_unauthorized', message: 'Not authorized to access resource' }]);
48+
assert.deepStrictEqual(err.message, 'Not authorized to access resource');
4849
assert.strictEqual(err.headers['x-request-id'], 'b2i3ri5909msvfqskol0');
4950
});
5051
});
@@ -76,6 +77,7 @@ describe('errors', () => {
7677
assert.strictEqual(err.statusCode, 429);
7778
assert.strictEqual(err.body.request_id, 'b2i3mhcboc6pcbe33q80');
7879
assert.deepStrictEqual(err.body.errors, [{ code: 'rate_limit_exceeded', message: 'Exceeded rate limit of 83 in 10_seconds' }]);
80+
assert.deepStrictEqual(err.message, 'Exceeded rate limit of 83 in 10_seconds');
7981
assert.strictEqual(err.headers['x-request-id'], 'b2i3mhcboc6pcbe33q80');
8082
assert.strictEqual(err.headers['x-ratelimit-reset'], '1522849880');
8183
});
@@ -204,6 +206,7 @@ describe('errors', () => {
204206
assert.strictEqual(err.statusCode, 401);
205207
assert.strictEqual(err.body.request_id, 'b2i3ri5909msvfqskol0');
206208
assert.deepStrictEqual(err.body.errors, [{ code: 'token_unauthorized', message: 'Not authorized to access resource' }]);
209+
assert.deepStrictEqual(err.message, 'Not authorized to access resource');
207210
assert.strictEqual(err.headers['x-request-id'], 'b2i3ri5909msvfqskol0');
208211

209212
done();
@@ -237,6 +240,7 @@ describe('errors', () => {
237240
assert.strictEqual(err.statusCode, 429);
238241
assert.strictEqual(err.body.request_id, 'b2i3mhcboc6pcbe33q80');
239242
assert.deepStrictEqual(err.body.errors, [{ code: 'rate_limit_exceeded', message: 'Exceeded rate limit of 83 in 10_seconds' }]);
243+
assert.deepStrictEqual(err.message, 'Exceeded rate limit of 83 in 10_seconds');
240244
assert.strictEqual(err.headers['x-request-id'], 'b2i3mhcboc6pcbe33q80');
241245
assert.strictEqual(err.headers['x-ratelimit-reset'], '1522849880');
242246

test/user.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,61 @@ describe('users', () => {
5959
done();
6060
});
6161
});
62-
it('should delete users by id', done => {
62+
it('should archive users by id', done => {
63+
nock('https://api.intercom.io').delete('/users/baz').reply(200, {});
64+
const client = new Client('foo', 'bar').usePromises();
65+
client.users.archive({ id: 'baz' }).then(r => {
66+
assert.equal(200, r.statusCode);
67+
done();
68+
});
69+
});
70+
it('should archive users by user_id', done => {
71+
nock('https://api.intercom.io').delete('/users').query({ user_id: 'foo' }).reply(200, {});
72+
const client = new Client('foo', 'bar').usePromises();
73+
client.users.archive({ user_id: 'foo' }).then(r => {
74+
assert.equal(200, r.statusCode);
75+
done();
76+
});
77+
});
78+
it('should archive users by email', done => {
79+
nock('https://api.intercom.io').delete('/users').query({ email: 'foo' }).reply(200, {});
80+
const client = new Client('foo', 'bar').usePromises();
81+
client.users.archive({ email: 'foo' }).then(r => {
82+
assert.equal(200, r.statusCode);
83+
done();
84+
});
85+
});
86+
it('should archive (using old delete function) users by id', done => {
6387
nock('https://api.intercom.io').delete('/users/baz').reply(200, {});
6488
const client = new Client('foo', 'bar').usePromises();
6589
client.users.delete({ id: 'baz' }).then(r => {
6690
assert.equal(200, r.statusCode);
6791
done();
6892
});
6993
});
70-
it('should delete users by user_id', done => {
94+
it('should archive (using old delete function) users by user_id', done => {
7195
nock('https://api.intercom.io').delete('/users').query({ user_id: 'foo' }).reply(200, {});
7296
const client = new Client('foo', 'bar').usePromises();
7397
client.users.delete({ user_id: 'foo' }).then(r => {
7498
assert.equal(200, r.statusCode);
7599
done();
76100
});
77101
});
78-
it('should delete users by email', done => {
102+
it('should archive (using old delete function) users by email', done => {
79103
nock('https://api.intercom.io').delete('/users').query({ email: 'foo' }).reply(200, {});
80104
const client = new Client('foo', 'bar').usePromises();
81105
client.users.delete({ email: 'foo' }).then(r => {
82106
assert.equal(200, r.statusCode);
83107
done();
84108
});
85109
});
110+
it('should permanently delete users by intercom user ID', done => {
111+
nock('https://api.intercom.io').post('/user_delete_requests', { intercom_user_id: 'foo' }).reply(200, { id: 10 });
112+
const client = new Client('foo', 'bar').usePromises();
113+
client.users.requestPermanentDeletion('foo').then(r => {
114+
assert.equal(200, r.statusCode);
115+
assert.deepStrictEqual({ id: 10 }, r.body);
116+
done();
117+
});
118+
});
86119
});

0 commit comments

Comments
 (0)