Skip to content

Commit 64f2cc9

Browse files
authored
Merge pull request #203 from bookcreator/f/permanently-delete-a-user
Support for permanently delete a user
2 parents 496e137 + 2404ca6 commit 64f2cc9

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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/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
}

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)