@vroskus/library-social 1.0.0

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.
Files changed (2) hide show
  1. package/dist/index.js +76 -0
  2. package/package.json +69 -0
package/dist/index.js ADDED
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ var _Social_instances, _Social_setupMock;
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ const axios_1 = __importDefault(require("axios"));
22
+ const axios_mock_adapter_1 = __importDefault(require("axios-mock-adapter"));
23
+ const mocks_1 = require("./mocks");
24
+ class Social {
25
+ constructor({ mock, timeout, }) {
26
+ _Social_instances.add(this);
27
+ if (mock === true) {
28
+ __classPrivateFieldGet(this, _Social_instances, "m", _Social_setupMock).call(this);
29
+ }
30
+ this.connection = axios_1.default.create({
31
+ headers: {
32
+ Accept: 'application/json',
33
+ 'Content-Type': 'application/json',
34
+ },
35
+ timeout,
36
+ });
37
+ }
38
+ authenticateFacebook(params) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ const url = 'https://graph.facebook.com/v9.0/me';
41
+ const request = {
42
+ params: {
43
+ access_token: params.token,
44
+ fields: 'name,email,picture',
45
+ },
46
+ };
47
+ const response = yield this.connection.get(url, request);
48
+ return response.data;
49
+ });
50
+ }
51
+ authenticateGoogle(params) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ const url = 'https://www.googleapis.com/oauth2/v2/userinfo';
54
+ const request = {
55
+ params: {
56
+ access_token: params.token,
57
+ },
58
+ };
59
+ const response = yield this.connection.get(url, request);
60
+ return response.data;
61
+ });
62
+ }
63
+ }
64
+ _Social_instances = new WeakSet(), _Social_setupMock = function _Social_setupMock() {
65
+ const mock = new axios_mock_adapter_1.default(axios_1.default);
66
+ mock.onGet('https://graph.facebook.com/v9.0/me').reply(() => {
67
+ const responseBody = mocks_1.facebookMock;
68
+ return [200, responseBody];
69
+ });
70
+ mock.onGet(/https:\/\/www.googleapis.com\/oauth2\/v2\/userinfo/).reply(() => {
71
+ const responseBody = mocks_1.googleMock;
72
+ return [200, responseBody];
73
+ });
74
+ };
75
+ exports.default = Social;
76
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@vroskus/library-social",
3
+ "version": "1.0.0",
4
+ "description": "Social",
5
+ "author": "Vilius Roškus <vilius@regattas.eu>",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/vroskus/library-social.git"
10
+ },
11
+ "main": "dist/index.js",
12
+ "files": [
13
+ "dist/index.js"
14
+ ],
15
+ "scripts": {
16
+ "postinstall": "npm run build",
17
+ "build": "tsc",
18
+ "test": "npm run test:eslint && npm run test:e2e",
19
+ "test:eslint": "eslint src test --fix",
20
+ "test:e2e": "npm run test:e2e:run && npm run test:e2e:post",
21
+ "test:e2e:run": "jest --ci --colors",
22
+ "test:e2e:post": "jest-coverage-thresholds-bumper"
23
+ },
24
+ "dependencies": {
25
+ "axios": "1.3.4",
26
+ "axios-mock-adapter": "1.21.2"
27
+ },
28
+ "devDependencies": {
29
+ "@types/jest": "29.5.0",
30
+ "@types/node": "18.15.11",
31
+ "@typescript-eslint/eslint-plugin": "5.53.0",
32
+ "@typescript-eslint/parser": "5.53.0",
33
+ "body-parser": "1.20.2",
34
+ "eslint": "8.34.0",
35
+ "eslint-config-airbnb-base": "15.0.0",
36
+ "eslint-config-airbnb-typescript": "17.0.0",
37
+ "eslint-plugin-import": "2.27.5",
38
+ "eslint-plugin-import-newlines": "1.3.1",
39
+ "eslint-plugin-react": "7.32.2",
40
+ "eslint-plugin-sort": "2.4.0",
41
+ "express": "4.18.2",
42
+ "jest": "29.4.3",
43
+ "jest-coverage-thresholds-bumper": "1.1.0",
44
+ "npm-check": "6.0.1",
45
+ "supertest": "6.3.3",
46
+ "ts-jest": "29.0.5",
47
+ "typescript": "4.9.5"
48
+ },
49
+ "jest": {
50
+ "preset": "ts-jest",
51
+ "testEnvironment": "node",
52
+ "coverageReporters": [
53
+ "json-summary",
54
+ "text"
55
+ ],
56
+ "collectCoverage": true,
57
+ "collectCoverageFrom": [
58
+ "src/**/*.ts"
59
+ ],
60
+ "coverageThreshold": {
61
+ "global": {
62
+ "branches": 100,
63
+ "functions": 100,
64
+ "lines": 100,
65
+ "statements": 100
66
+ }
67
+ }
68
+ }
69
+ }