@smartsoft001/fb 2.75.0 → 2.80.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/index.js +35 -0
- package/package.json +1 -1
- package/src/lib/fb.service.d.ts +10 -0
- package/.eslintrc.json +0 -24
- package/jest.config.ts +0 -27
- package/project.json +0 -37
- package/src/lib/fb.service.spec.ts +0 -100
- package/src/lib/fb.service.ts +0 -25
- package/tsconfig.json +0 -13
- package/tsconfig.lib.json +0 -11
- package/tsconfig.spec.json +0 -20
- /package/src/{index.ts → index.d.ts} +0 -0
- /package/{test-setup.ts → test-setup.d.ts} +0 -0
package/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// packages/shared/fb/src/lib/fb.service.ts
|
|
14
|
+
import { Injectable } from "@nestjs/common";
|
|
15
|
+
var FbService = class {
|
|
16
|
+
constructor(http) {
|
|
17
|
+
this.http = http;
|
|
18
|
+
}
|
|
19
|
+
async getUserId(token) {
|
|
20
|
+
const { data } = await this.http.get("https://graph.facebook.com/me?access_token=" + token).toPromise();
|
|
21
|
+
return data.id;
|
|
22
|
+
}
|
|
23
|
+
async getData(token) {
|
|
24
|
+
const { data } = await this.http.get(
|
|
25
|
+
"https://graph.facebook.com/me?fields=email,id&access_token=" + token
|
|
26
|
+
).toPromise();
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
FbService = __decorateClass([
|
|
31
|
+
Injectable()
|
|
32
|
+
], FbService);
|
|
33
|
+
export {
|
|
34
|
+
FbService
|
|
35
|
+
};
|
package/package.json
CHANGED
package/.eslintrc.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": ["../../../.eslintrc.json"],
|
|
3
|
-
"ignorePatterns": ["!**/*"],
|
|
4
|
-
"rules": {},
|
|
5
|
-
"overrides": [
|
|
6
|
-
{
|
|
7
|
-
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
|
|
8
|
-
"rules": {}
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
"files": ["*.ts", "*.tsx"],
|
|
12
|
-
"rules": {}
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
"files": ["*.js", "*.jsx"],
|
|
16
|
-
"rules": {}
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
"files": "package.json",
|
|
20
|
-
"parser": "jsonc-eslint-parser",
|
|
21
|
-
"rules": {}
|
|
22
|
-
}
|
|
23
|
-
]
|
|
24
|
-
}
|
package/jest.config.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
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/project.json
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "shared-fb",
|
|
3
|
-
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
-
"sourceRoot": "packages/shared/fb/src",
|
|
5
|
-
"projectType": "library",
|
|
6
|
-
"tags": [],
|
|
7
|
-
"targets": {
|
|
8
|
-
"lint": {
|
|
9
|
-
"executor": "@nx/eslint:lint",
|
|
10
|
-
"outputs": ["{options.outputFile}"],
|
|
11
|
-
"options": {
|
|
12
|
-
"lintFilePatterns": [
|
|
13
|
-
"packages/shared/fb/**/*.{ts,tsx,js,jsx}",
|
|
14
|
-
"packages/shared/fb/package.json"
|
|
15
|
-
]
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
"test": {
|
|
19
|
-
"executor": "@nx/jest:jest",
|
|
20
|
-
"options": {
|
|
21
|
-
"jestConfig": "packages/shared/fb/jest.config.ts"
|
|
22
|
-
},
|
|
23
|
-
"outputs": ["{workspaceRoot}/coverage/packages/shared/fb"]
|
|
24
|
-
},
|
|
25
|
-
"build": {
|
|
26
|
-
"executor": "@nx/esbuild:esbuild",
|
|
27
|
-
"outputs": ["{options.outputPath}"],
|
|
28
|
-
"options": {
|
|
29
|
-
"outputPath": "dist/packages/shared/fb",
|
|
30
|
-
"tsConfig": "packages/shared/fb/tsconfig.lib.json",
|
|
31
|
-
"packageJson": "packages/shared/fb/package.json",
|
|
32
|
-
"main": "packages/shared/fb/src/index.ts",
|
|
33
|
-
"assets": ["packages/shared/fb/*.md"]
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { HttpService } from '@nestjs/axios';
|
|
2
|
-
import { Test, TestingModule } from '@nestjs/testing';
|
|
3
|
-
import { of } from 'rxjs';
|
|
4
|
-
|
|
5
|
-
import { FbService } from './fb.service';
|
|
6
|
-
|
|
7
|
-
describe('FbService', () => {
|
|
8
|
-
let service: FbService;
|
|
9
|
-
let httpService: HttpService;
|
|
10
|
-
|
|
11
|
-
const mockHttpService = {
|
|
12
|
-
get: jest.fn(),
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
beforeEach(async () => {
|
|
16
|
-
const module: TestingModule = await Test.createTestingModule({
|
|
17
|
-
providers: [
|
|
18
|
-
FbService,
|
|
19
|
-
{
|
|
20
|
-
provide: HttpService,
|
|
21
|
-
useValue: mockHttpService,
|
|
22
|
-
},
|
|
23
|
-
],
|
|
24
|
-
}).compile();
|
|
25
|
-
|
|
26
|
-
service = module.get<FbService>(FbService);
|
|
27
|
-
httpService = module.get<HttpService>(HttpService);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
afterEach(() => {
|
|
31
|
-
jest.clearAllMocks();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should be defined', () => {
|
|
35
|
-
expect(service).toBeDefined();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
describe('getUserId', () => {
|
|
39
|
-
it('should return user ID from Facebook API', async () => {
|
|
40
|
-
const mockToken = 'test-token';
|
|
41
|
-
const mockResponse = {
|
|
42
|
-
data: {
|
|
43
|
-
id: '123456789',
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
mockHttpService.get.mockReturnValue(of(mockResponse));
|
|
48
|
-
|
|
49
|
-
const result = await service.getUserId(mockToken);
|
|
50
|
-
|
|
51
|
-
expect(result).toBe('123456789');
|
|
52
|
-
expect(mockHttpService.get).toHaveBeenCalledWith(
|
|
53
|
-
'https://graph.facebook.com/me?access_token=' + mockToken,
|
|
54
|
-
);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('should throw error when API call fails', async () => {
|
|
58
|
-
const mockToken = 'invalid-token';
|
|
59
|
-
mockHttpService.get.mockImplementation(() => {
|
|
60
|
-
throw new Error('API Error');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
await expect(service.getUserId(mockToken)).rejects.toThrow('API Error');
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('getData', () => {
|
|
68
|
-
it('should return user data from Facebook API', async () => {
|
|
69
|
-
const mockToken = 'test-token';
|
|
70
|
-
const mockResponse = {
|
|
71
|
-
data: {
|
|
72
|
-
id: '123456789',
|
|
73
|
-
email: 'test@example.com',
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
mockHttpService.get.mockReturnValue(of(mockResponse));
|
|
78
|
-
|
|
79
|
-
const result = await service.getData(mockToken);
|
|
80
|
-
|
|
81
|
-
expect(result).toEqual({
|
|
82
|
-
id: '123456789',
|
|
83
|
-
email: 'test@example.com',
|
|
84
|
-
});
|
|
85
|
-
expect(mockHttpService.get).toHaveBeenCalledWith(
|
|
86
|
-
'https://graph.facebook.com/me?fields=email,id&access_token=' +
|
|
87
|
-
mockToken,
|
|
88
|
-
);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('should throw error when API call fails', async () => {
|
|
92
|
-
const mockToken = 'invalid-token';
|
|
93
|
-
mockHttpService.get.mockImplementation(() => {
|
|
94
|
-
throw new Error('API Error');
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
await expect(service.getData(mockToken)).rejects.toThrow('API Error');
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
});
|
package/src/lib/fb.service.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { HttpService } from '@nestjs/axios';
|
|
2
|
-
import { Injectable } from '@nestjs/common';
|
|
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
DELETED
package/tsconfig.lib.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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
|
-
}
|
package/tsconfig.spec.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
}
|
|
File without changes
|
|
File without changes
|