Skip to content

Commit 3087bfb

Browse files
authored
Merge branch 'master' into patch-1
2 parents e2cc9ff + 586adbb commit 3087bfb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1268
-79
lines changed

.circleci/config.yml

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,65 @@ jobs:
33
build:
44
docker:
55
- image: circleci/node:14-browsers
6-
76
working_directory: ~/intercom-node
8-
97
steps:
108
- checkout
119
- run: export PATH="${PATH}:/home/circleci/.yarn/bin"
1210
- run: npm install --prefix=$HOME/.local --global corepack
11+
- restore_cache:
12+
key: dependency-cache-{{ checksum "yarn.lock" }}
1313
- run: yarn
14+
- save_cache:
15+
key: dependency-cache-{{ checksum "yarn.lock" }}
16+
paths:
17+
- node_modules
18+
- .yarn/cache
19+
- restore_cache:
20+
key: dist-cache-{{ .Environment.CIRCLE_SHA1 }}
1421
- run: yarn prepublish
15-
- run: yarn test
22+
- save_cache:
23+
key: dist-cache-{{ .Environment.CIRCLE_SHA1 }}
24+
paths:
25+
- dist
26+
unit_test:
27+
docker:
28+
- image: circleci/node:14-browsers
29+
working_directory: ~/intercom-node
30+
steps:
31+
- checkout
32+
- restore_cache:
33+
key: dependency-cache-{{ checksum "yarn.lock" }}
34+
- run: yarn test:unit
35+
integration_test:
36+
docker:
37+
- image: circleci/node:14-browsers
38+
environment:
39+
API_TOKEN: $API_TOKEN
40+
working_directory: ~/intercom-node
41+
42+
steps:
43+
- checkout
44+
- restore_cache:
45+
key: dependency-cache-{{ checksum "yarn.lock" }}
46+
- restore_cache:
47+
key: dist-cache-{{ .Environment.CIRCLE_SHA1 }}
48+
- run: yarn test:integration
49+
50+
workflows:
51+
version: 2
52+
build_and_test:
53+
jobs:
54+
- build
55+
- unit_test:
56+
requires:
57+
- build
58+
- integration_test_approval:
59+
requires:
60+
- unit_test
61+
type: approval
62+
- integration_test:
63+
requires:
64+
- integration_test_approval
1665

1766
notify:
1867
webhooks:

.eslintrc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"root": true,
33
"parser": "@typescript-eslint/parser",
4-
"plugins": ["@typescript-eslint"],
4+
"plugins": ["@typescript-eslint", "no-only-tests"],
55
"rules": {
66
"keyword-spacing": 2,
77
"array-bracket-spacing": [2, "never"],
@@ -33,7 +33,9 @@
3333
"no-sparse-arrays": 2,
3434
"no-unreachable": 2,
3535
"use-isnan": 2,
36-
"valid-typeof": 2
36+
"valid-typeof": 2,
37+
"require-await": "error",
38+
"no-only-tests/no-only-tests": "error"
3739
},
3840
"extends": [
3941
"eslint:recommended",

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -738,12 +738,10 @@ const response = await client.conversations.search({
738738

739739
```typescript
740740
const response = await client.conversations.list({
741-
query: {
742-
order: Order.DESC,
743-
sort: SortBy.UpdatedAt,
744-
page: 1,
745-
perPage: 10,
746-
},
741+
order: Order.DESC,
742+
sort: SortBy.UpdatedAt,
743+
page: 1,
744+
perPage: 10,
747745
});
748746
```
749747

lib/client.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { deprecate } from 'util';
21
import axios, { Axios, AxiosDefaults, AxiosResponse } from 'axios';
32
import { merge, omit } from 'lodash';
43

@@ -69,7 +68,6 @@ export default class Client {
6968
requestOpts: Partial<AxiosDefaults>;
7069
tags: Tag;
7170
teams: Team;
72-
usebaseURL: (baseURL: string) => this;
7371
usernamePart?: string;
7472
visitors: Visitor;
7573

@@ -105,11 +103,6 @@ export default class Client {
105103
};
106104
this.propertiesToOmitInRequestOpts = ['headers.common.Accept'];
107105

108-
this.usebaseURL = deprecate(
109-
(baseURL) => this.useRequestOpts({ baseURL }),
110-
'intercom-client - client.usebaseURL(url): Use client.useRequestOpts({ baseURL: url }) instead'
111-
);
112-
113106
this.axiosInstance = this.initiateAxiosInstance();
114107
}
115108
initiateAxiosInstance(): Axios {

lib/conversation.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Client from './client';
22
import {
3-
Paginated,
43
StringifiedTimestamp,
54
GenericSearchFilters,
65
Order,
@@ -257,9 +256,7 @@ export default class Conversation {
257256
data,
258257
});
259258
}
260-
list({
261-
query: { order, sort, page, perPage: per_page },
262-
}: ListConversationData) {
259+
list({ order, sort, page, perPage: per_page }: ListConversationData) {
263260
const params = { order, sort, page, per_page };
264261

265262
return this.client.get<ListConversationResponse>({
@@ -521,15 +518,15 @@ export enum SortBy {
521518
}
522519

523520
interface ListConversationData {
524-
query: {
525-
order: Order;
526-
sort: SortBy;
527-
page?: number;
528-
perPage?: number;
529-
};
521+
order?: Order;
522+
sort?: SortBy;
523+
page?: number;
524+
perPage?: number;
530525
}
531526

532-
type ListConversationResponse = Paginated<ConversationObjectWithoutParts>;
527+
type ListConversationResponse = PaginatedBase & {
528+
conversations: ConversationObjectWithoutParts[];
529+
};
533530
//
534531
export enum RedactConversationPartType {
535532
CONVERSATION_PART = 'conversation_part',

lib/scroll.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default class Scroll<EntityType> {
1010
this.scrollParam = scrollParam;
1111
}
1212

13+
// eslint-disable-next-line require-await
1314
async each(params: EachData): Promise<EntityType[]> {
1415
this.scrollParam = params.scrollParam ?? undefined;
1516

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "intercom-client",
3-
"version": "3.1.2",
3+
"version": "3.1.4",
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",
@@ -32,6 +32,7 @@
3232
"@typescript-eslint/parser": "^5.7.0",
3333
"eslint": "^8.2.0",
3434
"eslint-config-prettier": "^8.3.0",
35+
"eslint-plugin-no-only-tests": "^2.6.0",
3536
"merge2": "^1.4.1",
3637
"mocha": "^9.2.0",
3738
"nock": "^13.0.11",
@@ -48,7 +49,8 @@
4849
"compile_ts": "tsc",
4950
"move_compiled_to_dist": "mv dist/lib/* dist && rmdir dist/lib",
5051
"prepublish": "yarn clean && yarn static && yarn compile_ts && yarn move_compiled_to_dist",
51-
"test": "mocha -r ts-node/register test/*.ts",
52+
"test:unit": "mocha -r ts-node/register test/unit/*.test.ts --reporter=nyan",
53+
"test:integration": "mocha -r ts-node/register test/integration/**/*.test.ts --timeout=30000",
5254
"coverage": "nyc yarn test"
5355
},
5456
"engines": {

test/integration/admins.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { token } from './utils/config';
2+
import { Client } from '../../dist';
3+
import assert from 'assert';
4+
5+
describe('Admins', () => {
6+
let adminId: string;
7+
const client = new Client({
8+
tokenAuth: { token },
9+
});
10+
11+
it('list', async () => {
12+
const response = await client.admins.list();
13+
14+
adminId = response.admins[0].id;
15+
16+
assert.notEqual(response, undefined);
17+
});
18+
it('find', async () => {
19+
const response = await client.admins.find({ id: adminId });
20+
21+
assert.notEqual(response, undefined);
22+
});
23+
it('listAllActivityLogs', async () => {
24+
const response = await client.admins.listAllActivityLogs({
25+
after: new Date('2021-12-12'),
26+
});
27+
28+
assert.notEqual(response, undefined);
29+
});
30+
it('away - ON', async () => {
31+
const response = await client.admins.away({
32+
adminId,
33+
enableAwayMode: true,
34+
enableReassignMode: true,
35+
});
36+
37+
assert.notEqual(response, undefined);
38+
});
39+
it('away - OFF', async () => {
40+
const response = await client.admins.away({
41+
adminId,
42+
enableAwayMode: false,
43+
enableReassignMode: false,
44+
});
45+
46+
assert.notEqual(response, undefined);
47+
});
48+
});

test/integration/articles.test.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { Client } from '../../dist';
2+
import assert from 'assert';
3+
import { token } from './utils/config';
4+
import { randomString } from './utils/random';
5+
6+
describe('Articles', () => {
7+
let newArticleId: string;
8+
let parentId: number;
9+
let adminId: number;
10+
11+
before(async () => {
12+
const randomCollections = await client.helpCenter.collections.list({
13+
perPage: 1,
14+
});
15+
const randomAdmins = await client.admins.list();
16+
17+
parentId = parseInt(randomCollections.data[0].id, 10);
18+
adminId = parseInt(randomAdmins.admins[0].id, 10);
19+
});
20+
21+
const client = new Client({ tokenAuth: { token } });
22+
23+
it('create', async () => {
24+
const response = await client.articles.create({
25+
title: randomString(),
26+
description: randomString(),
27+
body: '<b>Eins Zwei</b>',
28+
authorId: adminId,
29+
state: 'draft',
30+
parentId,
31+
parentType: 'collection',
32+
translatedContent: {
33+
fr: {
34+
title: 'Allez les verts',
35+
description: 'French description',
36+
body: '<p>French body in html</p>',
37+
author_id: adminId,
38+
state: 'draft',
39+
},
40+
},
41+
});
42+
43+
newArticleId = response.id;
44+
assert.notEqual(response, undefined);
45+
});
46+
it('find', async () => {
47+
const response = await client.articles.find({ id: newArticleId });
48+
49+
assert.notEqual(response, undefined);
50+
});
51+
it('update', async () => {
52+
const response = await client.articles.update({
53+
id: newArticleId,
54+
title: 'Biba & Boba',
55+
});
56+
57+
assert.notEqual(response, undefined);
58+
});
59+
it('delete', async () => {
60+
const response = await client.articles.delete({ id: newArticleId });
61+
62+
assert.notEqual(response, undefined);
63+
});
64+
it('list', async () => {
65+
const response = await client.articles.list({ page: 1, perPage: 12 });
66+
67+
assert.notEqual(response, undefined);
68+
});
69+
});

0 commit comments

Comments
 (0)