@vroskus/library-social 1.0.8 → 1.0.9
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/dist/index.d.ts +3 -7
- package/dist/index.js +30 -6
- package/dist/mocks.d.ts +2 -1
- package/dist/mocks.js +24 -8
- package/dist/types.d.ts +7 -0
- package/package.json +6 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import type { Axios } from 'axios';
|
|
2
|
-
import type { $Config as Config, $
|
|
2
|
+
import type { $Config as Config, $SocialPayload } from './types';
|
|
3
3
|
export type $Config = Config;
|
|
4
4
|
declare class Social<C extends Config> {
|
|
5
5
|
#private;
|
|
6
6
|
connection: Axios;
|
|
7
7
|
constructor({ mock, timeout, }: C);
|
|
8
|
-
authenticateFacebook(
|
|
9
|
-
|
|
10
|
-
}): Promise<$FacebookPayload>;
|
|
11
|
-
authenticateGoogle(params: {
|
|
12
|
-
token: string;
|
|
13
|
-
}): Promise<$GooglePayload>;
|
|
8
|
+
authenticateFacebook(token: string): Promise<$SocialPayload>;
|
|
9
|
+
authenticateGoogle(token: string): Promise<$SocialPayload>;
|
|
14
10
|
}
|
|
15
11
|
export default Social;
|
package/dist/index.js
CHANGED
|
@@ -20,7 +20,15 @@ var _Social_instances, _Social_setupMock;
|
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
21
|
const axios_1 = __importDefault(require("axios"));
|
|
22
22
|
const axios_mock_adapter_1 = __importDefault(require("axios-mock-adapter"));
|
|
23
|
+
const library_validator_1 = require("@vroskus/library-validator");
|
|
23
24
|
const mocks_1 = require("./mocks");
|
|
25
|
+
const socialPayloadSchema = () => library_validator_1.Validator.object().keys({
|
|
26
|
+
Email: library_validator_1.Validator.string().required(),
|
|
27
|
+
EmailVerified: library_validator_1.Validator.boolean().required(),
|
|
28
|
+
Name: library_validator_1.Validator.string().required(),
|
|
29
|
+
PictureUrl: library_validator_1.Validator.string().allow(null),
|
|
30
|
+
Uid: library_validator_1.Validator.string().required(),
|
|
31
|
+
});
|
|
24
32
|
class Social {
|
|
25
33
|
constructor({ mock, timeout, }) {
|
|
26
34
|
_Social_instances.add(this);
|
|
@@ -35,29 +43,45 @@ class Social {
|
|
|
35
43
|
timeout,
|
|
36
44
|
});
|
|
37
45
|
}
|
|
38
|
-
authenticateFacebook(
|
|
46
|
+
authenticateFacebook(token) {
|
|
39
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
48
|
const url = 'https://graph.facebook.com/v9.0/me';
|
|
41
49
|
const request = {
|
|
42
50
|
params: {
|
|
43
|
-
access_token:
|
|
51
|
+
access_token: token,
|
|
44
52
|
fields: 'name,email,picture',
|
|
45
53
|
},
|
|
46
54
|
};
|
|
47
55
|
const response = yield this.connection.get(url, request);
|
|
48
|
-
|
|
56
|
+
const output = {
|
|
57
|
+
Email: response.data.email,
|
|
58
|
+
EmailVerified: true,
|
|
59
|
+
Name: response.data.name,
|
|
60
|
+
PictureUrl: response.data.picture ? response.data.picture.data.url : null,
|
|
61
|
+
Uid: String(response.data.id),
|
|
62
|
+
};
|
|
63
|
+
const validOutput = (0, library_validator_1.validateResponse)(output, socialPayloadSchema);
|
|
64
|
+
return validOutput;
|
|
49
65
|
});
|
|
50
66
|
}
|
|
51
|
-
authenticateGoogle(
|
|
67
|
+
authenticateGoogle(token) {
|
|
52
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
69
|
const url = 'https://www.googleapis.com/oauth2/v2/userinfo';
|
|
54
70
|
const request = {
|
|
55
71
|
params: {
|
|
56
|
-
access_token:
|
|
72
|
+
access_token: token,
|
|
57
73
|
},
|
|
58
74
|
};
|
|
59
75
|
const response = yield this.connection.get(url, request);
|
|
60
|
-
|
|
76
|
+
const output = {
|
|
77
|
+
Email: response.data.email,
|
|
78
|
+
EmailVerified: response.data.verified_email,
|
|
79
|
+
Name: response.data.name,
|
|
80
|
+
PictureUrl: response.data.picture,
|
|
81
|
+
Uid: String(response.data.id),
|
|
82
|
+
};
|
|
83
|
+
const validOutput = (0, library_validator_1.validateResponse)(output, socialPayloadSchema);
|
|
84
|
+
return validOutput;
|
|
61
85
|
});
|
|
62
86
|
}
|
|
63
87
|
}
|
package/dist/mocks.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type { $FacebookPayload, $GooglePayload } from './types';
|
|
1
|
+
import type { $FacebookPayload, $GooglePayload, $SocialPayload } from './types';
|
|
2
2
|
export declare const facebookMock: $FacebookPayload;
|
|
3
3
|
export declare const googleMock: $GooglePayload;
|
|
4
|
+
export declare const socialPayloadMock: $SocialPayload;
|
package/dist/mocks.js
CHANGED
|
@@ -1,19 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.googleMock = exports.facebookMock = void 0;
|
|
3
|
+
exports.socialPayloadMock = exports.googleMock = exports.facebookMock = void 0;
|
|
4
|
+
const id = '123';
|
|
5
|
+
const name = 'user';
|
|
6
|
+
const email = 'user@email.com';
|
|
7
|
+
const picture = 'http://picture.url';
|
|
4
8
|
exports.facebookMock = {
|
|
5
|
-
email
|
|
6
|
-
id
|
|
7
|
-
name
|
|
9
|
+
email,
|
|
10
|
+
id,
|
|
11
|
+
name,
|
|
12
|
+
picture: {
|
|
13
|
+
data: {
|
|
14
|
+
url: picture,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
8
17
|
};
|
|
9
18
|
exports.googleMock = {
|
|
10
|
-
email
|
|
19
|
+
email,
|
|
11
20
|
family_name: 'Lastname',
|
|
12
21
|
given_name: 'Firstname',
|
|
13
22
|
hd: 'hd',
|
|
14
|
-
id
|
|
23
|
+
id,
|
|
15
24
|
locale: 'en',
|
|
16
|
-
name
|
|
17
|
-
picture
|
|
25
|
+
name,
|
|
26
|
+
picture,
|
|
18
27
|
verified_email: true,
|
|
19
28
|
};
|
|
29
|
+
exports.socialPayloadMock = {
|
|
30
|
+
Email: email,
|
|
31
|
+
EmailVerified: true,
|
|
32
|
+
Name: name,
|
|
33
|
+
PictureUrl: picture,
|
|
34
|
+
Uid: id,
|
|
35
|
+
};
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vroskus/library-social",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "Social",
|
|
5
5
|
"author": "Vilius Roškus <vilius@regattas.eu>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"test:e2e:post": "jest-coverage-thresholds-bumper"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
+
"@vroskus/library-validator": "1.0.13",
|
|
25
26
|
"axios": "1.6.2",
|
|
26
27
|
"axios-mock-adapter": "1.22.0"
|
|
27
28
|
},
|
|
@@ -60,10 +61,10 @@
|
|
|
60
61
|
],
|
|
61
62
|
"coverageThreshold": {
|
|
62
63
|
"global": {
|
|
63
|
-
"branches":
|
|
64
|
-
"functions": 88.
|
|
65
|
-
"lines":
|
|
66
|
-
"statements":
|
|
64
|
+
"branches": 63.41,
|
|
65
|
+
"functions": 88.88,
|
|
66
|
+
"lines": 96.42,
|
|
67
|
+
"statements": 87.5
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
}
|