@smartsoft001/fb 1.1.90 → 1.2.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.
- package/.eslintrc.json +26 -0
- package/README.md +21 -4
- package/jest.config.ts +27 -0
- package/package.json +3 -12
- package/project.json +37 -0
- package/src/index.ts +1 -0
- package/src/lib/fb.service.spec.ts +99 -0
- package/src/lib/fb.service.ts +25 -0
- package/tsconfig.json +13 -0
- package/tsconfig.lib.json +11 -0
- package/tsconfig.spec.json +20 -0
- package/src/index.d.ts +0 -1
- package/src/index.js +0 -5
- package/src/index.js.map +0 -1
- package/src/lib/fb.service.d.ts +0 -10
- package/src/lib/fb.service.js +0 -26
- package/src/lib/fb.service.js.map +0 -1
- package/test-setup.js +0 -1
- package/test-setup.js.map +0 -1
- /package/{test-setup.d.ts → test-setup.ts} +0 -0
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": ["../../../.eslintrc.json"],
|
|
3
|
+
"ignorePatterns": ["!**/*"],
|
|
4
|
+
"rules": {
|
|
5
|
+
"import/order": "off"
|
|
6
|
+
},
|
|
7
|
+
"overrides": [
|
|
8
|
+
{
|
|
9
|
+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
|
|
10
|
+
"rules": {}
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"files": ["*.ts", "*.tsx"],
|
|
14
|
+
"rules": {}
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"files": ["*.js", "*.jsx"],
|
|
18
|
+
"rules": {}
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"files": "package.json",
|
|
22
|
+
"parser": "jsonc-eslint-parser",
|
|
23
|
+
"rules": {}
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
package/README.md
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 📦 @smartsoft001/fb
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
 
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 🚀 Usage
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
`npm i @smartsoft001/fb`
|
|
8
|
+
|
|
9
|
+
## 🛠️ Services & Methods
|
|
10
|
+
|
|
11
|
+
### FbService
|
|
12
|
+
|
|
13
|
+
Methods:
|
|
14
|
+
|
|
15
|
+
<table>
|
|
16
|
+
<tr>
|
|
17
|
+
<td>getUserId</td>
|
|
18
|
+
<td>Makes a GET request to Facebook's Graph API to fetch the current user's profile</td>
|
|
19
|
+
</tr>
|
|
20
|
+
<tr>
|
|
21
|
+
<td>getData</td>
|
|
22
|
+
<td>Makes a GET request but specifically requests both email and ID fields</td>
|
|
23
|
+
</tr>
|
|
24
|
+
</table>
|
package/jest.config.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
export default {
|
|
3
|
+
globals: {},
|
|
4
|
+
transform: {
|
|
5
|
+
'^.+\\.[tj]sx?$': [
|
|
6
|
+
'ts-jest',
|
|
7
|
+
{
|
|
8
|
+
tsConfig: '<rootDir>/tsconfig.spec.json',
|
|
9
|
+
},
|
|
10
|
+
],
|
|
11
|
+
},
|
|
12
|
+
moduleFileExtensions: ['ts', 'js', 'jsx'],
|
|
13
|
+
coverageDirectory: '../../../coverage/packages/shared/fb',
|
|
14
|
+
displayName: 'shared-fb',
|
|
15
|
+
testEnvironment: 'node',
|
|
16
|
+
preset: '../../../jest.preset.js',
|
|
17
|
+
/* TODO: Update to latest Jest snapshotFormat
|
|
18
|
+
* By default Nx has kept the older style of Jest Snapshot formats
|
|
19
|
+
* to prevent breaking of any existing tests with snapshots.
|
|
20
|
+
* It's recommend you update to the latest format.
|
|
21
|
+
* You can do this by removing snapshotFormat property
|
|
22
|
+
* and running tests with --update-snapshot flag.
|
|
23
|
+
* Example: From within the project directory, run "nx test --update-snapshot"
|
|
24
|
+
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
|
25
|
+
*/
|
|
26
|
+
snapshotFormat: { escapeString: true, printBasicPrototype: true },
|
|
27
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartsoft001/fb",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Utils for fb authorisation",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/emiljuchnikowski/smartsoft.git"
|
|
@@ -11,14 +11,5 @@
|
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/emiljuchnikowski/smartsoft/issues"
|
|
13
13
|
},
|
|
14
|
-
"homepage": "https://github.com/emiljuchnikowski/smartsoft#readme"
|
|
15
|
-
"dependencies": {
|
|
16
|
-
"@nestjs/axios": "3.0.0",
|
|
17
|
-
"@nestjs/common": "^10.0.5"
|
|
18
|
-
},
|
|
19
|
-
"peerDependencies": {
|
|
20
|
-
"tslib": "2.5.3"
|
|
21
|
-
},
|
|
22
|
-
"main": "./src/index.js",
|
|
23
|
-
"types": "./src/index.d.ts"
|
|
14
|
+
"homepage": "https://github.com/emiljuchnikowski/smartsoft#readme"
|
|
24
15
|
}
|
package/project.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "shared-fb",
|
|
3
|
+
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "packages/shared/fb/src",
|
|
5
|
+
"projectType": "library",
|
|
6
|
+
"targets": {
|
|
7
|
+
"lint": {
|
|
8
|
+
"executor": "@nx/eslint:lint",
|
|
9
|
+
"outputs": ["{options.outputFile}"],
|
|
10
|
+
"options": {
|
|
11
|
+
"lintFilePatterns": [
|
|
12
|
+
"packages/shared/fb/**/*.{ts,tsx,js,jsx}",
|
|
13
|
+
"packages/shared/fb/package.json"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"test": {
|
|
18
|
+
"executor": "@nx/jest:jest",
|
|
19
|
+
"options": {
|
|
20
|
+
"jestConfig": "packages/shared/fb/jest.config.ts"
|
|
21
|
+
},
|
|
22
|
+
"outputs": ["{workspaceRoot}/coverage/packages/shared/fb"]
|
|
23
|
+
},
|
|
24
|
+
"build": {
|
|
25
|
+
"executor": "@nx/esbuild:esbuild",
|
|
26
|
+
"outputs": ["{options.outputPath}"],
|
|
27
|
+
"options": {
|
|
28
|
+
"outputPath": "dist/packages/shared/fb",
|
|
29
|
+
"tsConfig": "packages/shared/fb/tsconfig.lib.json",
|
|
30
|
+
"packageJson": "packages/shared/fb/package.json",
|
|
31
|
+
"main": "packages/shared/fb/src/index.ts",
|
|
32
|
+
"assets": ["packages/shared/fb/*.md"]
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"tags": []
|
|
37
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/fb.service';
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Test, TestingModule } from '@nestjs/testing';
|
|
2
|
+
import { HttpService } from '@nestjs/axios';
|
|
3
|
+
import { FbService } from './fb.service';
|
|
4
|
+
import { of } from 'rxjs';
|
|
5
|
+
|
|
6
|
+
describe('FbService', () => {
|
|
7
|
+
let service: FbService;
|
|
8
|
+
let httpService: HttpService;
|
|
9
|
+
|
|
10
|
+
const mockHttpService = {
|
|
11
|
+
get: jest.fn(),
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
beforeEach(async () => {
|
|
15
|
+
const module: TestingModule = await Test.createTestingModule({
|
|
16
|
+
providers: [
|
|
17
|
+
FbService,
|
|
18
|
+
{
|
|
19
|
+
provide: HttpService,
|
|
20
|
+
useValue: mockHttpService,
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
}).compile();
|
|
24
|
+
|
|
25
|
+
service = module.get<FbService>(FbService);
|
|
26
|
+
httpService = module.get<HttpService>(HttpService);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
jest.clearAllMocks();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should be defined', () => {
|
|
34
|
+
expect(service).toBeDefined();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('getUserId', () => {
|
|
38
|
+
it('should return user ID from Facebook API', async () => {
|
|
39
|
+
const mockToken = 'test-token';
|
|
40
|
+
const mockResponse = {
|
|
41
|
+
data: {
|
|
42
|
+
id: '123456789',
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
mockHttpService.get.mockReturnValue(of(mockResponse));
|
|
47
|
+
|
|
48
|
+
const result = await service.getUserId(mockToken);
|
|
49
|
+
|
|
50
|
+
expect(result).toBe('123456789');
|
|
51
|
+
expect(mockHttpService.get).toHaveBeenCalledWith(
|
|
52
|
+
'https://graph.facebook.com/me?access_token=' + mockToken,
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should throw error when API call fails', async () => {
|
|
57
|
+
const mockToken = 'invalid-token';
|
|
58
|
+
mockHttpService.get.mockImplementation(() => {
|
|
59
|
+
throw new Error('API Error');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
await expect(service.getUserId(mockToken)).rejects.toThrow('API Error');
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('getData', () => {
|
|
67
|
+
it('should return user data from Facebook API', async () => {
|
|
68
|
+
const mockToken = 'test-token';
|
|
69
|
+
const mockResponse = {
|
|
70
|
+
data: {
|
|
71
|
+
id: '123456789',
|
|
72
|
+
email: 'test@example.com',
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
mockHttpService.get.mockReturnValue(of(mockResponse));
|
|
77
|
+
|
|
78
|
+
const result = await service.getData(mockToken);
|
|
79
|
+
|
|
80
|
+
expect(result).toEqual({
|
|
81
|
+
id: '123456789',
|
|
82
|
+
email: 'test@example.com',
|
|
83
|
+
});
|
|
84
|
+
expect(mockHttpService.get).toHaveBeenCalledWith(
|
|
85
|
+
'https://graph.facebook.com/me?fields=email,id&access_token=' +
|
|
86
|
+
mockToken,
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('should throw error when API call fails', async () => {
|
|
91
|
+
const mockToken = 'invalid-token';
|
|
92
|
+
mockHttpService.get.mockImplementation(() => {
|
|
93
|
+
throw new Error('API Error');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
await expect(service.getData(mockToken)).rejects.toThrow('API Error');
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { HttpService } from '@nestjs/axios';
|
|
3
|
+
|
|
4
|
+
@Injectable()
|
|
5
|
+
export class FbService {
|
|
6
|
+
constructor(private http: HttpService) {}
|
|
7
|
+
|
|
8
|
+
async getUserId(token: string): Promise<string> {
|
|
9
|
+
const { data } = await this.http
|
|
10
|
+
.get('https://graph.facebook.com/me?access_token=' + token)
|
|
11
|
+
.toPromise();
|
|
12
|
+
|
|
13
|
+
return data.id;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async getData(token: string): Promise<{ id; email }> {
|
|
17
|
+
const { data } = await this.http
|
|
18
|
+
.get(
|
|
19
|
+
'https://graph.facebook.com/me?fields=email,id&access_token=' + token,
|
|
20
|
+
)
|
|
21
|
+
.toPromise();
|
|
22
|
+
|
|
23
|
+
return data;
|
|
24
|
+
}
|
|
25
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"outDir": "../../../dist/out-tsc",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"types": ["node"]
|
|
8
|
+
},
|
|
9
|
+
"exclude": ["**/*.spec.ts", "**/*.test.ts", "jest.config.ts"],
|
|
10
|
+
"include": ["**/*.ts"]
|
|
11
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../../dist/out-tsc",
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"types": ["jest", "node"]
|
|
7
|
+
},
|
|
8
|
+
"include": [
|
|
9
|
+
"**/*.spec.ts",
|
|
10
|
+
"**/*.test.ts",
|
|
11
|
+
"**/*.spec.tsx",
|
|
12
|
+
"**/*.test.tsx",
|
|
13
|
+
"**/*.spec.js",
|
|
14
|
+
"**/*.test.js",
|
|
15
|
+
"**/*.spec.jsx",
|
|
16
|
+
"**/*.test.jsx",
|
|
17
|
+
"**/*.d.ts",
|
|
18
|
+
"jest.config.ts"
|
|
19
|
+
]
|
|
20
|
+
}
|
package/src/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./lib/fb.service";
|
package/src/index.js
DELETED
package/src/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/shared/fb/src/index.ts"],"names":[],"mappings":";;;AAAA,2DAAiC"}
|
package/src/lib/fb.service.d.ts
DELETED
package/src/lib/fb.service.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FbService = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const common_1 = require("@nestjs/common");
|
|
6
|
-
const axios_1 = require("@nestjs/axios");
|
|
7
|
-
let FbService = exports.FbService = class FbService {
|
|
8
|
-
constructor(http) {
|
|
9
|
-
this.http = http;
|
|
10
|
-
}
|
|
11
|
-
async getUserId(token) {
|
|
12
|
-
const { data } = await this.http
|
|
13
|
-
.get('https://graph.facebook.com/me?access_token=' + token).toPromise();
|
|
14
|
-
return data.id;
|
|
15
|
-
}
|
|
16
|
-
async getData(token) {
|
|
17
|
-
const { data } = await this.http
|
|
18
|
-
.get('https://graph.facebook.com/me?fields=email,id&access_token=' + token).toPromise();
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
exports.FbService = FbService = tslib_1.__decorate([
|
|
23
|
-
(0, common_1.Injectable)(),
|
|
24
|
-
tslib_1.__metadata("design:paramtypes", [axios_1.HttpService])
|
|
25
|
-
], FbService);
|
|
26
|
-
//# sourceMappingURL=fb.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fb.service.js","sourceRoot":"","sources":["../../../../../../libs/shared/fb/src/lib/fb.service.ts"],"names":[],"mappings":";;;;AAAA,2CAA0C;AAC1C,yCAA0C;AAGnC,IAAM,SAAS,uBAAf,MAAM,SAAS;IAClB,YAAoB,IAAiB;QAAjB,SAAI,GAAJ,IAAI,CAAa;IAAI,CAAC;IAE1C,KAAK,CAAC,SAAS,CAAC,KAAa;QACzB,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI;aAC3B,GAAG,CAAC,6CAA6C,GAAG,KAAK,CAAC,CAAC,SAAS,EAAE,CAAC;QAE5E,OAAO,IAAI,CAAC,EAAE,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,KAAa;QACvB,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI;aAC3B,GAAG,CAAC,6DAA6D,GAAG,KAAK,CAAC,CAAC,SAAS,EAAE,CAAC;QAE5F,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ,CAAA;oBAhBY,SAAS;IADrB,IAAA,mBAAU,GAAE;6CAEiB,mBAAW;GAD5B,SAAS,CAgBrB"}
|
package/test-setup.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=test-setup.js.map
|
package/test-setup.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"test-setup.js","sourceRoot":"","sources":["../../../../libs/shared/fb/test-setup.ts"],"names":[],"mappings":""}
|
|
File without changes
|