@vroskus/library-social 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -1
- package/.eslintrc +0 -77
- package/src/index.ts +0 -99
- package/src/mocks.ts +0 -23
- package/src/types.ts +0 -27
- package/test/index.test.ts +0 -40
- package/tsconfig.eslint.json +0 -4
- package/tsconfig.json +0 -27
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vroskus/library-social",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Social",
|
|
5
5
|
"author": "Vilius Roškus <vilius@regattas.eu>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
"url": "git+https://github.com/vroskus/library-social.git"
|
|
10
10
|
},
|
|
11
11
|
"main": "dist/index.js",
|
|
12
|
+
"types": "dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist/"
|
|
15
|
+
],
|
|
12
16
|
"scripts": {
|
|
13
17
|
"postinstall": "npm run build",
|
|
14
18
|
"build": "tsc",
|
package/.eslintrc
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"root": true,
|
|
3
|
-
"parser": "@typescript-eslint/parser",
|
|
4
|
-
"parserOptions": {
|
|
5
|
-
"requireConfigFile": false,
|
|
6
|
-
"project": ["tsconfig.eslint.json"]
|
|
7
|
-
},
|
|
8
|
-
"extends": [
|
|
9
|
-
"airbnb-base",
|
|
10
|
-
"airbnb-typescript",
|
|
11
|
-
"plugin:import/recommended",
|
|
12
|
-
"plugin:@typescript-eslint/eslint-recommended",
|
|
13
|
-
"plugin:@typescript-eslint/recommended",
|
|
14
|
-
"plugin:sort/recommended"
|
|
15
|
-
],
|
|
16
|
-
"plugins": [
|
|
17
|
-
"@typescript-eslint",
|
|
18
|
-
"import",
|
|
19
|
-
"import-newlines",
|
|
20
|
-
"react",
|
|
21
|
-
"sort"
|
|
22
|
-
],
|
|
23
|
-
"rules": {
|
|
24
|
-
"complexity": ["error", 5],
|
|
25
|
-
"@typescript-eslint/ban-ts-comment": [1],
|
|
26
|
-
"@typescript-eslint/no-unused-vars": [2],
|
|
27
|
-
"curly": ["error", "all"],
|
|
28
|
-
"import/no-cycle": [0],
|
|
29
|
-
"no-await-in-loop": 0,
|
|
30
|
-
"no-console": "error",
|
|
31
|
-
"no-duplicate-imports": [0],
|
|
32
|
-
"no-loss-of-precision": [0],
|
|
33
|
-
"no-restricted-syntax": 0,
|
|
34
|
-
"no-unreachable-loop": [0],
|
|
35
|
-
"no-useless-backreference": [0],
|
|
36
|
-
"no-unused-private-class-members": [2],
|
|
37
|
-
"padding-line-between-statements": ["error", {
|
|
38
|
-
"blankLine": "always",
|
|
39
|
-
"prev": ["const", "let"],
|
|
40
|
-
"next": "*"
|
|
41
|
-
}, {
|
|
42
|
-
"blankLine": "any",
|
|
43
|
-
"prev": ["const", "let"],
|
|
44
|
-
"next": ["const", "let"]
|
|
45
|
-
}, {
|
|
46
|
-
"blankLine": "always",
|
|
47
|
-
"prev": ["if", "function", "for"],
|
|
48
|
-
"next": "*"
|
|
49
|
-
}, {
|
|
50
|
-
"blankLine": "always",
|
|
51
|
-
"prev": "*",
|
|
52
|
-
"next": "return"
|
|
53
|
-
}],
|
|
54
|
-
"object-curly-newline": ["error", {
|
|
55
|
-
"ObjectExpression": "always",
|
|
56
|
-
"ObjectPattern": "always",
|
|
57
|
-
"ImportDeclaration": "always",
|
|
58
|
-
"ExportDeclaration": "always"
|
|
59
|
-
}],
|
|
60
|
-
"function-call-argument-newline": ["error", "always"],
|
|
61
|
-
"object-property-newline": ["error", {
|
|
62
|
-
"allowMultiplePropertiesPerLine": false
|
|
63
|
-
}],
|
|
64
|
-
"import-newlines/enforce": ["error", {
|
|
65
|
-
"items": 1,
|
|
66
|
-
"forceSingleLine": false
|
|
67
|
-
}],
|
|
68
|
-
"sort/imports": [0],
|
|
69
|
-
"sort/exports": [0]
|
|
70
|
-
},
|
|
71
|
-
"env": {
|
|
72
|
-
"browser": true,
|
|
73
|
-
"node": true,
|
|
74
|
-
"jest": true,
|
|
75
|
-
"es6": true
|
|
76
|
-
}
|
|
77
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
// Global Types
|
|
2
|
-
import type {
|
|
3
|
-
Axios,
|
|
4
|
-
} from 'axios';
|
|
5
|
-
|
|
6
|
-
// Helpers
|
|
7
|
-
import axios from 'axios';
|
|
8
|
-
import AxiosMockAdapter from 'axios-mock-adapter';
|
|
9
|
-
|
|
10
|
-
// Mocks
|
|
11
|
-
import {
|
|
12
|
-
facebookMock,
|
|
13
|
-
googleMock,
|
|
14
|
-
} from './mocks';
|
|
15
|
-
|
|
16
|
-
// Types
|
|
17
|
-
import type {
|
|
18
|
-
$Config as Config,
|
|
19
|
-
$FacebookPayload,
|
|
20
|
-
$GooglePayload,
|
|
21
|
-
} from './types';
|
|
22
|
-
|
|
23
|
-
export type $Config = Config;
|
|
24
|
-
|
|
25
|
-
class Social<C extends Config> {
|
|
26
|
-
connection: Axios;
|
|
27
|
-
|
|
28
|
-
constructor({
|
|
29
|
-
mock,
|
|
30
|
-
timeout,
|
|
31
|
-
}: C) {
|
|
32
|
-
if (mock === true) {
|
|
33
|
-
this.#setupMock();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Connection setup
|
|
37
|
-
this.connection = axios.create({
|
|
38
|
-
headers: {
|
|
39
|
-
Accept: 'application/json',
|
|
40
|
-
'Content-Type': 'application/json',
|
|
41
|
-
},
|
|
42
|
-
timeout,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// eslint-disable-next-line
|
|
47
|
-
#setupMock(): void {
|
|
48
|
-
const mock = new AxiosMockAdapter(axios);
|
|
49
|
-
|
|
50
|
-
mock.onGet('https://graph.facebook.com/v9.0/me').reply(() => {
|
|
51
|
-
const responseBody: $FacebookPayload = facebookMock;
|
|
52
|
-
|
|
53
|
-
return [200, responseBody];
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
mock.onGet(/https:\/\/www.googleapis.com\/oauth2\/v2\/userinfo/).reply(() => {
|
|
57
|
-
const responseBody: $GooglePayload = googleMock;
|
|
58
|
-
|
|
59
|
-
return [200, responseBody];
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async authenticateFacebook(params: {
|
|
64
|
-
token: string;
|
|
65
|
-
}): Promise<$FacebookPayload> {
|
|
66
|
-
const url = 'https://graph.facebook.com/v9.0/me';
|
|
67
|
-
const request = {
|
|
68
|
-
params: {
|
|
69
|
-
access_token: params.token,
|
|
70
|
-
fields: 'name,email,picture',
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
const response = await this.connection.get(
|
|
74
|
-
url,
|
|
75
|
-
request,
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
return response.data;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async authenticateGoogle(params: {
|
|
82
|
-
token: string;
|
|
83
|
-
}): Promise<$GooglePayload> {
|
|
84
|
-
const url = 'https://www.googleapis.com/oauth2/v2/userinfo';
|
|
85
|
-
const request = {
|
|
86
|
-
params: {
|
|
87
|
-
access_token: params.token,
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
const response = await this.connection.get(
|
|
91
|
-
url,
|
|
92
|
-
request,
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
return response.data;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export default Social;
|
package/src/mocks.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// Types
|
|
2
|
-
import type {
|
|
3
|
-
$FacebookPayload,
|
|
4
|
-
$GooglePayload,
|
|
5
|
-
} from './types';
|
|
6
|
-
|
|
7
|
-
export const facebookMock: $FacebookPayload = {
|
|
8
|
-
email: 'user@facebook.com',
|
|
9
|
-
id: '123',
|
|
10
|
-
name: 'facebook-user',
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const googleMock: $GooglePayload = {
|
|
14
|
-
email: 'user@google.com',
|
|
15
|
-
family_name: 'Lastname',
|
|
16
|
-
given_name: 'Firstname',
|
|
17
|
-
hd: 'hd',
|
|
18
|
-
id: '123',
|
|
19
|
-
locale: 'en',
|
|
20
|
-
name: 'google-user',
|
|
21
|
-
picture: 'http://picture.url',
|
|
22
|
-
verified_email: true,
|
|
23
|
-
};
|
package/src/types.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export type $Config = {
|
|
2
|
-
mock?: boolean;
|
|
3
|
-
timeout: number;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
export type $FacebookPayload = {
|
|
7
|
-
email: string;
|
|
8
|
-
id: string;
|
|
9
|
-
name: string;
|
|
10
|
-
picture?: {
|
|
11
|
-
data: {
|
|
12
|
-
url: string;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export type $GooglePayload = {
|
|
18
|
-
email: string;
|
|
19
|
-
family_name: string;
|
|
20
|
-
given_name: string;
|
|
21
|
-
hd: string;
|
|
22
|
-
id: string;
|
|
23
|
-
locale: string;
|
|
24
|
-
name: string;
|
|
25
|
-
picture: string;
|
|
26
|
-
verified_email: boolean;
|
|
27
|
-
};
|
package/test/index.test.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import Social from '../src';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
facebookMock,
|
|
5
|
-
googleMock,
|
|
6
|
-
} from '../src/mocks';
|
|
7
|
-
|
|
8
|
-
describe(
|
|
9
|
-
'Social',
|
|
10
|
-
() => {
|
|
11
|
-
const service = new Social({
|
|
12
|
-
mock: true,
|
|
13
|
-
timeout: 0,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it(
|
|
17
|
-
'shoud get FACEBOOK auth data',
|
|
18
|
-
async () => {
|
|
19
|
-
const params = {
|
|
20
|
-
token: 'random-string',
|
|
21
|
-
};
|
|
22
|
-
const data = await service.authenticateFacebook(params);
|
|
23
|
-
|
|
24
|
-
expect(data).toMatchObject(facebookMock);
|
|
25
|
-
},
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
it(
|
|
29
|
-
'shoud get GOOGLE auth data',
|
|
30
|
-
async () => {
|
|
31
|
-
const params = {
|
|
32
|
-
token: 'random-string',
|
|
33
|
-
};
|
|
34
|
-
const data = await service.authenticateGoogle(params);
|
|
35
|
-
|
|
36
|
-
expect(data).toMatchObject(googleMock);
|
|
37
|
-
},
|
|
38
|
-
);
|
|
39
|
-
},
|
|
40
|
-
);
|
package/tsconfig.eslint.json
DELETED
package/tsconfig.json
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"outDir": "./dist/",
|
|
4
|
-
"types": ["node", "jest"],
|
|
5
|
-
"module": "commonjs",
|
|
6
|
-
"esModuleInterop": true,
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"noImplicitAny": false,
|
|
9
|
-
"removeComments": true,
|
|
10
|
-
"noLib": false,
|
|
11
|
-
"emitDecoratorMetadata": true,
|
|
12
|
-
"experimentalDecorators": true,
|
|
13
|
-
"target": "es6",
|
|
14
|
-
"sourceMap": true,
|
|
15
|
-
"lib": [
|
|
16
|
-
"dom",
|
|
17
|
-
"es6"
|
|
18
|
-
]
|
|
19
|
-
},
|
|
20
|
-
"exclude": [
|
|
21
|
-
"node_modules",
|
|
22
|
-
"./dist/**/*"
|
|
23
|
-
],
|
|
24
|
-
"include": [
|
|
25
|
-
"./src"
|
|
26
|
-
]
|
|
27
|
-
}
|