Skip to content

Commit ca64e9b

Browse files
committed
0.1.14
1 parent 917039f commit ca64e9b

19 files changed

+347
-162
lines changed

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/lib
2+
/esm
3+
/coverage
4+
/flow-typed/npm

.eslintrc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"parser": "babel-eslint",
3+
"extends": [
4+
"airbnb-base"
5+
],
6+
"plugins": [
7+
"flowtype"
8+
],
9+
"rules": {
10+
"max-len": 0,
11+
"eqeqeq": [
12+
"error",
13+
"smart"
14+
],
15+
"no-dupe-keys": "error",
16+
"no-return-assign": "off",
17+
"consistent-return": "off",
18+
"no-redeclare": "off",
19+
"object-curly-newline": "off",
20+
"import/prefer-default-export": "off",
21+
"import/no-extraneous-dependencies": "off",
22+
"flowtype/define-flow-type": "error",
23+
"flowtype/no-dupe-keys": "error",
24+
"flowtype/no-mutable-array": "error",
25+
"flowtype/no-primitive-constructor-types": "error",
26+
"flowtype/no-types-missing-file-annotation": "error",
27+
"flowtype/require-valid-file-annotation": [
28+
"error",
29+
"never",
30+
{
31+
"annotationStyle": "block"
32+
}
33+
],
34+
"flowtype/type-id-match": [
35+
"error",
36+
"^[A-Z][a-z0-9]*"
37+
],
38+
"flowtype/use-flow-type": "error"
39+
},
40+
"env": {
41+
"node": true,
42+
"browser": true
43+
}
44+
}

__tests__/adapter.spec.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,33 @@ import {
44
generalName,
55
unCnownName,
66
} from '../__mock__/channelName';
7-
import { getParamsFromChannelName, getThreadFromChannelFactory } from '../src/adapters';
7+
import { getParamsFromChannelName } from '../src/adapters';
88

99
describe('Adapters', () => {
10-
1110
it('Should return Document params', () => {
12-
expect(getParamsFromChannelName(documentName)).toEqual({
11+
expect(getParamsFromChannelName('local', documentName)).toEqual({
1312
env: 'local',
1413
companyId: 'a1ae760ff7',
1514
documentId: 'e9ff6bcb686c4ca7c2350bed5bc6346f.pdf',
1615
users: [
1716
1817
19-
]
18+
],
2019
});
2120
});
2221

2322
it('Should return General params', () => {
24-
expect(getParamsFromChannelName(generalName)).toEqual({
23+
expect(getParamsFromChannelName('staging', generalName)).toEqual({
2524
env: 'staging',
2625
companyId: 'ed70da07f4',
2726
users: [
2827
2928
30-
]
29+
],
3130
});
3231
});
3332

3433
it('Should return NULL in uncnown env', () => {
35-
expect(getParamsFromChannelName(unCnownName)).toBeNull();
34+
expect(getParamsFromChannelName('local', unCnownName)).toBeNull();
3635
});
37-
3836
});

__tests__/connect.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ describe('Connect to SendBird', () => {
1111
it('Should be connected', () => {
1212
sbCreatInstance(keys.apiKey);
1313
return sbConnect(keys.userId, keys.accessToken)
14-
.then(user => {
14+
.then((user) => {
1515
expect(user.userId).toEqual(keys.userId);
1616
sbDisconnect();
17-
})
17+
});
1818
});
1919
});

__tests__/groupChennel.spec.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
11
/* @flow */
2-
import sinon from 'sinon';
32
import keys from '../__mock__/keys';
43
import { sbCreatInstance, sbGetInstance } from '../src/instance';
54
import { sbConnect, sbDisconnect } from '../src/connect';
65
import { sbChannelList } from '../src/groupChannel';
7-
import { channelsToThreads } from '../src/imAdapters';
8-
9-
const fs = require('fs');
106

117
describe('Group Channel', () => {
12-
138
beforeAll((done) => {
149
sbCreatInstance(keys.apiKey);
15-
return sbConnect(keys.userId, keys.accessToken).then(() => { done(); })
10+
return sbConnect(keys.userId, keys.accessToken).then(() => { done(); });
1611
});
1712

18-
afterAll((done) => {
19-
return sbDisconnect().then(() => { done(); });
20-
})
13+
afterAll(done => sbDisconnect().then(() => { done(); }));
2114

2215
it('Should get channel list', () => {
23-
expect(sbGetInstance().getConnectionState()).toEqual('OPEN')
16+
expect(sbGetInstance().getConnectionState()).toEqual('OPEN');
2417
return sbChannelList()
25-
.then(channel => {
18+
.then((channel) => {
2619
expect(Array.isArray(channel)).toBeTruthy();
2720
});
2821
});
29-
30-
});
22+
});

__tests__/imadapters.spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
} from '../src/imAdapters';
1010

1111
describe('Immutamle Adapters', () => {
12-
1312
it('Should transform groupChannels to store data', () => {
1413
const threads = channelsToThreads('local', groupChannel);
1514
const documentThread = threads.get(documentName);
@@ -26,6 +25,5 @@ describe('Immutamle Adapters', () => {
2625
expect(res.messages.get(0).message).toEqual(userMessage.message);
2726
expect(res.messages.get(0).messageId).toEqual(userMessage.messageId);
2827
expect(res.messages.get(0).sender.userId).toEqual(userMessage.sender.userId);
29-
})
30-
28+
});
3129
});

__tests__/instance.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @flow */
22
import keys from '../__mock__/keys';
3-
import { sbGetInstance, sbCreatInstance } from '../src/instance';
3+
import { sbCreatInstance } from '../src/instance';
44

55
describe('SendBird instance', () => {
66
it('Should be created instance', () => {

__tests__/jsadapters.spec.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import userMessage from '../__mock__/userMessage.json';
44
import {
55
documentName,
66
generalName,
7-
unCnownName,
87
} from '../__mock__/channelName';
98
import {
109
channelsToThreads,
@@ -23,7 +22,7 @@ describe('JS Adapters', () => {
2322
});
2423

2524
it('Document adapter', () => {
26-
const threads = channelsToThreads('local', groupChannel);
25+
const threads = channelsToThreads('staging', groupChannel);
2726
expect(threads).toBeObject();
2827
const generalThread = threads[generalName];
2928
expect(generalThread.name).toEqual(generalName);
@@ -40,6 +39,5 @@ describe('JS Adapters', () => {
4039
expect(res.messages[0].message).toEqual(userMessage.message);
4140
expect(res.messages[0].messageId).toEqual(userMessage.messageId);
4241
expect(res.messages[0].sender.userId).toEqual(userMessage.sender.userId);
43-
})
44-
42+
});
4543
});

babel.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = function(api) {
1+
module.exports = function config(api) {
22
return {
33
plugins: [
44
'@babel/plugin-proposal-class-properties',
@@ -13,9 +13,9 @@ module.exports = function(api) {
1313
node: 6,
1414
browsers: ['last 4 version', '> 1%', 'not dead'],
1515
},
16-
forceAllTransforms: api.env("production"),
16+
forceAllTransforms: api.env('production'),
1717
},
18-
]
18+
],
1919
],
2020
env: {
2121
test: {
@@ -28,5 +28,5 @@ module.exports = function(api) {
2828
],
2929
},
3030
},
31-
}
31+
};
3232
};

package.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
{
22
"name": "sendbird-helpers",
3-
"version": "0.1.13",
3+
"version": "0.1.14",
44
"description": "SendBird helpers",
55
"main": "lib/index.js",
66
"repository": "https://github.com/agolovchuk/sendBird-helpers.git",
77
"author": "Alexandr Golovchuk <[email protected]>",
88
"license": "MIT",
99
"scripts": {
10-
"lint": "yarn lint:md && yarn lint:js",
10+
"lint": "yarn lint:js",
1111
"lint:js": "eslint .",
12-
"lint:md": "node scripts/mdlint",
1312
"flow": "flow",
1413
"test": "jest --env=node",
1514
"test:watch": "jest --env=node --watch",
1615
"test:coverage": "jest --env=node --coverage",
1716
"build": "rollup -c",
18-
"precommit": "yarn lint && yarn flow && yarn test",
17+
"precommit": "yarn lint && npx flow && yarn test",
1918
"preversion": "git checkout master && yarn precommit",
2019
"postversion": "git push --follow-tags"
2120
},
@@ -29,16 +28,21 @@
2928
"babel-jest": "^23.6.0",
3029
"babel-plugin-transform-es2015-classes": "^6.24.1",
3130
"eslint": "^5.12.0",
31+
"eslint-config-airbnb-base": "^13.1.0",
32+
"eslint-plugin-flowtype": "^3.2.0",
33+
"eslint-plugin-import": "^2.14.0",
34+
"eslint-plugin-jest": "^22.1.3",
3235
"flow-bin": "^0.91.0",
3336
"flow-typed": "^2.5.1",
3437
"jest": "^23.6.0",
3538
"jest-extended": "^0.11.0",
3639
"regenerator-runtime": "^0.13.1",
37-
"rollup": "^1.0.1",
38-
"rollup-plugin-babel": "^4.2.0",
40+
"rollup": "^1.1.2",
41+
"rollup-plugin-babel": "^4.3.2",
3942
"rollup-plugin-clear": "^2.0.7",
4043
"rollup-plugin-commonjs": "^9.2.0",
41-
"rollup-plugin-flow-entry": "^0.2.1",
44+
"rollup-plugin-flow": "^1.1.1",
45+
"rollup-plugin-flow-entry": "0.2.0",
4246
"sinon": "^7.2.3"
4347
},
4448
"dependencies": {

rollup.config.js

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ import commonjs from 'rollup-plugin-commonjs';
22
import babel from 'rollup-plugin-babel';
33
import flowEntry from 'rollup-plugin-flow-entry';
44
import clear from 'rollup-plugin-clear';
5+
import flow from 'rollup-plugin-flow';
56

67
import packageJson from './package.json';
78

9+
const configuredFlow = flow({ all: true, pretty: true });
10+
811
const { dependencies } = packageJson;
912

1013
const deps = dependencies && Object.keys(dependencies).join('|');
1114
const reg = deps && new RegExp(`^(${deps})($|/)`);
12-
const baseDistPath = 'lib/';
15+
const baseDistPath = './lib/';
1316

1417
const banner = `
1518
/**
@@ -20,7 +23,7 @@ const banner = `
2023

2124
export default [
2225
{
23-
input: 'src/index.js',
26+
input: './src/index.js',
2427
output: {
2528
file: `${baseDistPath}index.js`,
2629
format: 'cjs',
@@ -31,28 +34,12 @@ export default [
3134
targets: ['lib'],
3235
}),
3336
flowEntry(),
37+
configuredFlow,
3438
babel(),
3539
commonjs(),
3640
],
3741
external: id => !!reg && reg.test(id),
3842
},
39-
{
40-
input: 'src/index.js',
41-
output: {
42-
file: 'esm/index.mjs',
43-
format: 'esm',
44-
banner,
45-
},
46-
plugins: [
47-
clear({
48-
targets: ['esm'],
49-
}),
50-
flowEntry(),
51-
babel({ presets: [['@babel/env', { targets: { node: 10 } }]] }),
52-
commonjs(),
53-
],
54-
external: id => !!reg && reg.test(id),
55-
},
5643
{
5744
input: 'src/jsAdapters.js',
5845
output: {
@@ -65,6 +52,7 @@ export default [
6552
targets: ['lib'],
6653
}),
6754
flowEntry(),
55+
configuredFlow,
6856
babel(),
6957
commonjs(),
7058
],
@@ -82,6 +70,7 @@ export default [
8270
targets: ['lib'],
8371
}),
8472
flowEntry(),
73+
configuredFlow,
8574
babel(),
8675
commonjs(),
8776
],

src/adapters.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/* @flow */
22
import type { GroupChannel } from 'sendbird';
3-
import { DOCUMENT_CHAT_TYPE } from './constants';
4-
import { ChatError } from './error';
53

64
export type EnvType = 'staging' | 'development' | 'production' | 'local';
75

@@ -10,21 +8,22 @@ export type ChannelAdapter<P, T = *> = (channel: $ReadOnly<GroupChannel>, params
108
export type GeneralChannelParamsType = {|
119
env: EnvType,
1210
companyId: string,
13-
users: string[],
11+
users: $ReadOnlyArray<string>,
1412
|}
1513

1614
export type DocumentChannelParamsType = {|
1715
env: EnvType,
1816
companyId: string,
19-
users: string[],
17+
users: $ReadOnlyArray<string>,
2018
documentId: string,
2119
|}
2220

2321
export type ParamsChannel = GeneralChannelParamsType | DocumentChannelParamsType;
2422

25-
export function getParamsFromChannelName(channelName: string): ParamsChannel | null {
23+
export function getParamsFromChannelName(buildEnv: EnvType, channelName: string): ParamsChannel | null {
2624
const params = channelName.split('#');
2725
const env = params[0];
26+
if (env !== buildEnv) return null;
2827
if (env !== 'staging' && env !== 'development' && env !== 'production' && env !== 'local') {
2928
return null;
3029
// throw new ChatError(`Unknown environment`, { env, channelName });
@@ -44,14 +43,14 @@ export function getParamsFromChannelName(channelName: string): ParamsChannel | n
4443
}: GeneralChannelParamsType);
4544
}
4645

47-
export function getThreadFromChannelFactory(env: EnvType) {
46+
export function getThreadFromChannelFactory(buildEnv: EnvType) {
4847
return function getThreadFromChannel(
4948
channel: GroupChannel,
5049
documentChannelAdapter: ChannelAdapter<$ReadOnly<DocumentChannelParamsType>, *>,
5150
generalChannelAdapter: ChannelAdapter<$ReadOnly<GeneralChannelParamsType>, *>,
5251
n: ChannelAdapter<null, *>,
5352
) {
54-
const params = getParamsFromChannelName(channel.name);
53+
const params = getParamsFromChannelName(buildEnv, channel.name);
5554

5655
if (params) {
5756
if (params.documentId) {
@@ -61,5 +60,5 @@ export function getThreadFromChannelFactory(env: EnvType) {
6160
return generalChannelAdapter(channel, params);
6261
}
6362
return n(channel, params);
64-
}
63+
};
6564
}

0 commit comments

Comments
 (0)