mm-share-lib 0.0.4 → 0.0.6
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 +12 -2
- package/src/auth/apple/apple.module.ts +10 -0
- package/src/auth/apple/apple.service.ts +28 -0
- package/src/auth/apple/dto/apple-login.dto.ts +16 -0
- package/src/auth/apple/dto/index.ts +1 -0
- package/src/auth/apple/index.ts +3 -0
- package/src/auth/config/apple.config.ts +18 -0
- package/src/auth/config/auth.config.ts +29 -0
- package/src/auth/config/facebook.config.ts +23 -0
- package/src/auth/config/file.config.ts +50 -0
- package/src/auth/config/google.config.ts +23 -0
- package/src/auth/config/index.ts +6 -0
- package/src/auth/config/twitter.config.ts +22 -0
- package/src/auth/facebook/dto/facebook-login.dto.ts +8 -0
- package/src/auth/facebook/dto/index.ts +1 -0
- package/src/auth/facebook/facebook.module.ts +11 -0
- package/src/auth/facebook/facebook.service.ts +51 -0
- package/src/auth/facebook/index.ts +4 -0
- package/src/auth/facebook/interface/facebook.interface.ts +6 -0
- package/src/auth/facebook/interface/index.ts +1 -0
- package/src/auth/google/dto/google-login.dto.ts +8 -0
- package/src/auth/google/dto/index.ts +1 -0
- package/src/auth/google/google.module.ts +10 -0
- package/src/auth/google/google.service.ts +51 -0
- package/src/auth/google/index.ts +3 -0
- package/src/auth/index.ts +5 -0
- package/src/auth/twitter/dto/index.ts +1 -0
- package/src/auth/twitter/dto/twitter-login.dto.ts +12 -0
- package/src/auth/twitter/index.ts +3 -0
- package/src/auth/twitter/twitter.module.ts +11 -0
- package/src/auth/twitter/twitter.service.ts +43 -0
- package/src/config/index.ts +1 -0
- package/src/config/type.config.ts +88 -0
- package/src/dto/pagination.dto.ts +14 -2
- package/src/exception/bad-request-error.exception.spec.ts +24 -0
- package/src/exception/bad-request-error.exception.ts +8 -0
- package/src/exception/base.exception.ts +36 -0
- package/src/exception/conflict-error.exception.spec.ts +23 -0
- package/src/exception/conflict-error.exception.ts +8 -0
- package/src/exception/forbidden-error.exception.spec.ts +23 -0
- package/src/exception/forbidden-error.exception.ts +8 -0
- package/src/exception/index.ts +7 -0
- package/src/exception/internal-server-error.exception.spec.ts +23 -0
- package/src/exception/internal-server-error.exception.ts +12 -0
- package/src/exception/not-found-error.exception.spec.ts +23 -0
- package/src/exception/not-found-error.exception.ts +8 -0
- package/src/exception/unauthorized-error.exception.spec.ts +23 -0
- package/src/exception/unauthorized-error.exception.ts +12 -0
- package/src/filter/http-exception.filter.ts +23 -0
- package/src/filter/index.ts +1 -0
- package/src/filter/rpc-exception.filter.ts +15 -0
- package/src/index.ts +3 -0
- package/src/interface/index.ts +1 -0
- package/src/interface/social.interface.ts +6 -0
- package/src/lib/index.ts +2 -0
- package/src/lib/mailer/config/index.ts +1 -0
- package/src/lib/mailer/config/mailer.config.ts +62 -0
- package/src/lib/mailer/index.ts +2 -0
- package/src/lib/mailer/mailer.module.ts +8 -0
- package/src/lib/mailer/mailer.service.ts +53 -0
- package/src/lib/redis/index.ts +0 -0
- package/src/lib/search-engine/document/base.document.ts +2 -2
- package/src/lib/search-engine/interface/search-document.interface.ts +10 -2
- package/src/lib/search-engine/schema/generic.schema.ts +1 -1
- package/src/lib/search-engine/schema/index.ts +1 -1
- package/src/lib/search-engine/typesense/collection/index.ts +1 -0
- package/src/lib/search-engine/typesense/document/index.ts +1 -0
- package/src/lib/search-engine/typesense/index.ts +1 -0
- package/src/lib/search-engine/typesense/service/client.service.ts +5 -3
- package/src/lib/storage/index.ts +0 -0
- package/src/lib/typesense/client/index.ts +1 -0
- package/src/lib/typesense/collection/index.ts +1 -0
- package/src/lib/typesense/decorator/field.decorator.spec.ts +89 -0
- package/src/lib/typesense/decorator/field.decorator.ts +44 -0
- package/src/lib/typesense/decorator/index.ts +2 -0
- package/src/lib/typesense/decorator/schema.decorator.ts +23 -0
- package/src/lib/typesense/document/base.document.ts +3 -0
- package/src/lib/typesense/index.ts +6 -0
- package/src/lib/typesense/metadata/index.ts +4 -0
- package/src/lib/typesense/metadata/schema.metadata.ts +21 -0
- package/src/lib/typesense/metadata/typesense.metadata-accessor.ts +37 -0
- package/src/lib/typesense/metadata/typesense.metadata-explorer.spec.ts +56 -0
- package/src/lib/typesense/metadata/typesense.metadata-explorer.ts +41 -0
- package/src/lib/typesense/metadata/typesense.metadata-registry.ts +28 -0
- package/src/lib/typesense/module/index.ts +4 -0
- package/src/lib/typesense/module/interface.module.ts +34 -0
- package/src/lib/typesense/module/typesense.constant.ts +1 -0
- package/src/lib/typesense/module/typesense.module.spec.ts +94 -0
- package/src/lib/typesense/module/typesense.module.ts +87 -0
- package/src/lib/typesense/module/typesense.provider.ts +54 -0
- package/src/response/base-entity.response.ts +8 -0
- package/src/response/index.ts +1 -0
- package/src/response/login.response.ts +0 -0
- package/src/response/pagination.response.ts +23 -8
- package/src/setup/index.ts +1 -0
- package/src/setup/microservice.setup.ts +29 -0
- package/src/setup/swagger.setup.ts +0 -0
- package/src/util/app.utils.ts +18 -0
- package/src/util/index.ts +2 -0
- package/src/util/validate-config.ts +20 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -18
- package/dist/index.js.map +0 -1
- package/dist/src/dto/base-filter.dto.d.ts +0 -4
- package/dist/src/dto/base-filter.dto.js +0 -11
- package/dist/src/dto/base-filter.dto.js.map +0 -1
- package/dist/src/dto/index.d.ts +0 -2
- package/dist/src/dto/index.js +0 -19
- package/dist/src/dto/index.js.map +0 -1
- package/dist/src/dto/pagination.dto.d.ts +0 -4
- package/dist/src/dto/pagination.dto.js +0 -11
- package/dist/src/dto/pagination.dto.js.map +0 -1
- package/dist/src/index.d.ts +0 -6
- package/dist/src/index.js +0 -23
- package/dist/src/index.js.map +0 -1
- package/dist/src/lib/index.d.ts +0 -1
- package/dist/src/lib/index.js +0 -18
- package/dist/src/lib/index.js.map +0 -1
- package/dist/src/lib/search-engine/document/base.document.d.ts +0 -3
- package/dist/src/lib/search-engine/document/base.document.js +0 -7
- package/dist/src/lib/search-engine/document/base.document.js.map +0 -1
- package/dist/src/lib/search-engine/document/index.js +0 -18
- package/dist/src/lib/search-engine/document/index.js.map +0 -1
- package/dist/src/lib/search-engine/index.d.ts +0 -1
- package/dist/src/lib/search-engine/index.js +0 -18
- package/dist/src/lib/search-engine/index.js.map +0 -1
- package/dist/src/lib/search-engine/interface/index.d.ts +0 -2
- package/dist/src/lib/search-engine/interface/index.js +0 -19
- package/dist/src/lib/search-engine/interface/index.js.map +0 -1
- package/dist/src/lib/search-engine/interface/search-document.interface.d.ts +0 -4
- package/dist/src/lib/search-engine/interface/search-document.interface.js +0 -3
- package/dist/src/lib/search-engine/interface/search-document.interface.js.map +0 -1
- package/dist/src/lib/search-engine/interface/transform-service.interface.d.ts +0 -6
- package/dist/src/lib/search-engine/interface/transform-service.interface.js +0 -3
- package/dist/src/lib/search-engine/interface/transform-service.interface.js.map +0 -1
- package/dist/src/lib/search-engine/schema/generic.schema.d.ts +0 -2
- package/dist/src/lib/search-engine/schema/generic.schema.js +0 -7
- package/dist/src/lib/search-engine/schema/generic.schema.js.map +0 -1
- package/dist/src/lib/search-engine/schema/index.d.ts +0 -1
- package/dist/src/lib/search-engine/schema/index.js +0 -18
- package/dist/src/lib/search-engine/schema/index.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/index.d.ts +0 -3
- package/dist/src/lib/search-engine/typesense/index.js +0 -20
- package/dist/src/lib/search-engine/typesense/index.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/metadata/index.d.ts +0 -2
- package/dist/src/lib/search-engine/typesense/metadata/index.js +0 -19
- package/dist/src/lib/search-engine/typesense/metadata/index.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/metadata/schema.metadata.d.ts +0 -12
- package/dist/src/lib/search-engine/typesense/metadata/schema.metadata.js +0 -3
- package/dist/src/lib/search-engine/typesense/metadata/schema.metadata.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/metadata/typesense.metadata-registry.d.ts +0 -10
- package/dist/src/lib/search-engine/typesense/metadata/typesense.metadata-registry.js +0 -33
- package/dist/src/lib/search-engine/typesense/metadata/typesense.metadata-registry.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/service/client.service.d.ts +0 -33
- package/dist/src/lib/search-engine/typesense/service/client.service.js +0 -197
- package/dist/src/lib/search-engine/typesense/service/client.service.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/service/index.d.ts +0 -1
- package/dist/src/lib/search-engine/typesense/service/index.js +0 -18
- package/dist/src/lib/search-engine/typesense/service/index.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/typesense-module.interface.d.ts +0 -27
- package/dist/src/lib/search-engine/typesense/typesense-module.interface.js +0 -3
- package/dist/src/lib/search-engine/typesense/typesense-module.interface.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/typesense.constants.d.ts +0 -1
- package/dist/src/lib/search-engine/typesense/typesense.constants.js +0 -5
- package/dist/src/lib/search-engine/typesense/typesense.constants.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/typesense.module.d.ts +0 -8
- package/dist/src/lib/search-engine/typesense/typesense.module.js +0 -68
- package/dist/src/lib/search-engine/typesense/typesense.module.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/typesense.module.test.d.ts +0 -1
- package/dist/src/lib/search-engine/typesense/typesense.module.test.js +0 -89
- package/dist/src/lib/search-engine/typesense/typesense.module.test.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/typesense.providers.d.ts +0 -4
- package/dist/src/lib/search-engine/typesense/typesense.providers.js +0 -40
- package/dist/src/lib/search-engine/typesense/typesense.providers.js.map +0 -1
- package/dist/src/response/index.d.ts +0 -1
- package/dist/src/response/index.js +0 -18
- package/dist/src/response/index.js.map +0 -1
- package/dist/src/response/pagination.response.d.ts +0 -17
- package/dist/src/response/pagination.response.js +0 -29
- package/dist/src/response/pagination.response.js.map +0 -1
- package/dist/src/util/date.util.d.ts +0 -2
- package/dist/src/util/date.util.js +0 -14
- package/dist/src/util/date.util.js.map +0 -1
- package/dist/src/util/generator.util.d.ts +0 -4
- package/dist/src/util/generator.util.js +0 -29
- package/dist/src/util/generator.util.js.map +0 -1
- package/dist/src/util/index.d.ts +0 -2
- package/dist/src/util/index.js +0 -19
- package/dist/src/util/index.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- /package/{dist/src/lib/search-engine/document/index.d.ts → src/lib/typesense/document/index.ts} +0 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "mm-share-lib",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.6",
|
4
4
|
"description": "Share the generic service, entity, dto.",
|
5
5
|
"author": "Mesa SOT",
|
6
6
|
"license": "MIT",
|
@@ -24,16 +24,25 @@
|
|
24
24
|
"dependencies": {
|
25
25
|
"@babel/runtime": "^7.22.5",
|
26
26
|
"@nestjs/common": "^9.4.2",
|
27
|
+
"@nestjs/config": "^3.0.0",
|
27
28
|
"@nestjs/core": "^9.4.2",
|
29
|
+
"@nestjs/microservices": "^9.4.3",
|
28
30
|
"@nestjs/platform-express": "^9.4.2",
|
31
|
+
"@nestjs/swagger": "^7.1.1",
|
29
32
|
"@nestjs/typeorm": "^9.0.1",
|
33
|
+
"bcrypt": "^5.1.0",
|
30
34
|
"class-transformer": "^0.5.1",
|
31
35
|
"class-validator": "^0.14.0",
|
32
36
|
"dayjs": "^1.11.8",
|
37
|
+
"decamelize": "^6.0.0",
|
38
|
+
"fb": "^2.0.0",
|
39
|
+
"google-auth-library": "^9.0.0",
|
40
|
+
"handlebars": "^4.7.7",
|
41
|
+
"nodemailer": "^6.9.4",
|
33
42
|
"reflect-metadata": "^0.1.13",
|
34
43
|
"rxjs": "^7.8.1",
|
44
|
+
"twitter": "^1.7.1",
|
35
45
|
"typeorm": "^0.3.16",
|
36
|
-
"bcrypt": "^5.1.0",
|
37
46
|
"typesense": "^1.5.4"
|
38
47
|
},
|
39
48
|
"devDependencies": {
|
@@ -45,6 +54,7 @@
|
|
45
54
|
"@types/jest": "29.5.2",
|
46
55
|
"@types/node": "20.2.5",
|
47
56
|
"@types/supertest": "^2.0.12",
|
57
|
+
"@types/twitter": "^1.7.1",
|
48
58
|
"@typescript-eslint/eslint-plugin": "^5.59.9",
|
49
59
|
"@typescript-eslint/parser": "^5.59.9",
|
50
60
|
"eslint": "^8.42.0",
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { Module } from '@nestjs/common';
|
2
|
+
import { AppleService } from './apple.service';
|
3
|
+
import { ConfigModule } from '@nestjs/config';
|
4
|
+
|
5
|
+
@Module({
|
6
|
+
imports: [ConfigModule],
|
7
|
+
providers: [AppleService],
|
8
|
+
exports: [AppleService],
|
9
|
+
})
|
10
|
+
export class AppleModule {}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
2
|
+
import appleSigninAuth from 'apple-signin-auth';
|
3
|
+
import { ConfigService } from '@nestjs/config';
|
4
|
+
import { SocialInterface } from '../../interface';
|
5
|
+
import { AppleLoginDto } from './dto';
|
6
|
+
import { AllConfigType } from '../../config';
|
7
|
+
|
8
|
+
@Injectable()
|
9
|
+
export class AppleService {
|
10
|
+
constructor(private configService: ConfigService<AllConfigType>) {}
|
11
|
+
|
12
|
+
async getProfileByToken(loginDto: AppleLoginDto): Promise<SocialInterface> {
|
13
|
+
const { idToken, firstName, lastName } = loginDto;
|
14
|
+
|
15
|
+
const data = await appleSigninAuth.verifyIdToken(idToken, {
|
16
|
+
audience: this.configService.get('apple.appAudience', { infer: true }),
|
17
|
+
});
|
18
|
+
|
19
|
+
const { sub, email } = data;
|
20
|
+
|
21
|
+
return {
|
22
|
+
id: sub,
|
23
|
+
email: email,
|
24
|
+
firstName: firstName,
|
25
|
+
lastName: lastName,
|
26
|
+
};
|
27
|
+
}
|
28
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { ApiProperty } from '@nestjs/swagger';
|
2
|
+
import { Allow, IsNotEmpty } from 'class-validator';
|
3
|
+
|
4
|
+
export class AppleLoginDto {
|
5
|
+
@ApiProperty({ example: 'abc' })
|
6
|
+
@IsNotEmpty()
|
7
|
+
idToken: string;
|
8
|
+
|
9
|
+
@Allow()
|
10
|
+
@ApiProperty({ required: false })
|
11
|
+
firstName?: string;
|
12
|
+
|
13
|
+
@Allow()
|
14
|
+
@ApiProperty({ required: false })
|
15
|
+
lastName?: string;
|
16
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './apple-login.dto';
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { registerAs } from '@nestjs/config';
|
2
|
+
import { AppleConfig } from '../../config';
|
3
|
+
import { IsJSON, IsOptional } from 'class-validator';
|
4
|
+
import { validateConfig } from '../../util';
|
5
|
+
|
6
|
+
class EnvironmentVariablesValidator {
|
7
|
+
@IsJSON()
|
8
|
+
@IsOptional()
|
9
|
+
APPLE_APP_AUDIENCE: string;
|
10
|
+
}
|
11
|
+
|
12
|
+
export default registerAs<AppleConfig>('apple', () => {
|
13
|
+
validateConfig(process.env, EnvironmentVariablesValidator);
|
14
|
+
|
15
|
+
return {
|
16
|
+
appAudience: JSON.parse(process.env.APPLE_APP_AUDIENCE ?? '[]'),
|
17
|
+
};
|
18
|
+
});
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { IsString } from 'class-validator';
|
2
|
+
import { registerAs } from '@nestjs/config';
|
3
|
+
import { AuthConfig } from '../../config';
|
4
|
+
import { validateConfig } from '../../util';
|
5
|
+
|
6
|
+
class EnvironmentVariablesValidator {
|
7
|
+
@IsString()
|
8
|
+
AUTH_JWT_SECRET: string;
|
9
|
+
|
10
|
+
@IsString()
|
11
|
+
AUTH_JWT_TOKEN_EXPIRES_IN: string;
|
12
|
+
|
13
|
+
@IsString()
|
14
|
+
AUTH_REFRESH_SECRET: string;
|
15
|
+
|
16
|
+
@IsString()
|
17
|
+
AUTH_REFRESH_TOKEN_EXPIRES_IN: string;
|
18
|
+
}
|
19
|
+
|
20
|
+
export default registerAs<AuthConfig>('auth', () => {
|
21
|
+
validateConfig(process.env, EnvironmentVariablesValidator);
|
22
|
+
|
23
|
+
return {
|
24
|
+
secret: process.env.AUTH_JWT_SECRET,
|
25
|
+
expires: process.env.AUTH_JWT_TOKEN_EXPIRES_IN,
|
26
|
+
refreshSecret: process.env.AUTH_REFRESH_SECRET,
|
27
|
+
refreshExpires: process.env.AUTH_REFRESH_TOKEN_EXPIRES_IN,
|
28
|
+
};
|
29
|
+
});
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { IsOptional, IsString } from 'class-validator';
|
2
|
+
import { registerAs } from '@nestjs/config';
|
3
|
+
import { FacebookConfig } from '../../config';
|
4
|
+
import { validateConfig } from '../../util';
|
5
|
+
|
6
|
+
class EnvironmentVariablesValidator {
|
7
|
+
@IsString()
|
8
|
+
@IsOptional()
|
9
|
+
FACEBOOK_APP_ID: string;
|
10
|
+
|
11
|
+
@IsString()
|
12
|
+
@IsOptional()
|
13
|
+
FACEBOOK_APP_SECRET: string;
|
14
|
+
}
|
15
|
+
|
16
|
+
export default registerAs<FacebookConfig>('facebook', () => {
|
17
|
+
validateConfig(process.env, EnvironmentVariablesValidator);
|
18
|
+
|
19
|
+
return {
|
20
|
+
appId: process.env.FACEBOOK_APP_ID,
|
21
|
+
appSecret: process.env.FACEBOOK_APP_SECRET,
|
22
|
+
};
|
23
|
+
});
|
@@ -0,0 +1,50 @@
|
|
1
|
+
import { registerAs } from '@nestjs/config';
|
2
|
+
import { FileConfig } from '../../config';
|
3
|
+
import { IsEnum, IsOptional, IsString, ValidateIf } from 'class-validator';
|
4
|
+
import { validateConfig } from '../../util';
|
5
|
+
|
6
|
+
enum FileDriver {
|
7
|
+
LOCAL = 'local',
|
8
|
+
S3 = 's3',
|
9
|
+
GCS = 'gcs',
|
10
|
+
}
|
11
|
+
|
12
|
+
class EnvironmentVariablesValidator {
|
13
|
+
@IsEnum(FileDriver)
|
14
|
+
FILE_DRIVER: FileDriver;
|
15
|
+
|
16
|
+
@ValidateIf((envValues) => envValues.FILE_DRIVER === FileDriver.S3)
|
17
|
+
@IsString()
|
18
|
+
ACCESS_KEY_ID: string;
|
19
|
+
|
20
|
+
@ValidateIf((envValues) => envValues.FILE_DRIVER === FileDriver.S3)
|
21
|
+
@IsString()
|
22
|
+
SECRET_ACCESS_KEY: string;
|
23
|
+
|
24
|
+
@ValidateIf((envValues) => envValues.FILE_DRIVER === FileDriver.S3)
|
25
|
+
@IsString()
|
26
|
+
STORAGE_BUCKET: string;
|
27
|
+
|
28
|
+
@ValidateIf((envValues) => envValues.FILE_DRIVER === FileDriver.S3)
|
29
|
+
@IsString()
|
30
|
+
@IsOptional()
|
31
|
+
STORAGE_URL: string;
|
32
|
+
|
33
|
+
@ValidateIf((envValues) => envValues.FILE_DRIVER === FileDriver.S3)
|
34
|
+
@IsString()
|
35
|
+
STORAGE_REGION: string;
|
36
|
+
}
|
37
|
+
|
38
|
+
export default registerAs<FileConfig>('file', () => {
|
39
|
+
validateConfig(process.env, EnvironmentVariablesValidator);
|
40
|
+
|
41
|
+
return {
|
42
|
+
driver: process.env.FILE_DRIVER ?? 'local',
|
43
|
+
accessKeyId: process.env.ACCESS_KEY_ID,
|
44
|
+
secretAccessKey: process.env.SECRET_ACCESS_KEY,
|
45
|
+
awsDefaultS3Bucket: process.env.AWS_DEFAULT_S3_BUCKET,
|
46
|
+
awsDefaultS3Url: process.env.AWS_DEFAULT_S3_URL,
|
47
|
+
awsS3Region: process.env.AWS_S3_REGION,
|
48
|
+
maxFileSize: 5242880, // 5mb
|
49
|
+
};
|
50
|
+
});
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { IsOptional, IsString } from 'class-validator';
|
2
|
+
import { registerAs } from '@nestjs/config';
|
3
|
+
import { GoogleConfig } from '../../config';
|
4
|
+
import { validateConfig } from '../../util';
|
5
|
+
|
6
|
+
class EnvironmentVariablesValidator {
|
7
|
+
@IsString()
|
8
|
+
@IsOptional()
|
9
|
+
GOOGLE_CLIENT_ID: string;
|
10
|
+
|
11
|
+
@IsString()
|
12
|
+
@IsOptional()
|
13
|
+
GOOGLE_CLIENT_SECRET: string;
|
14
|
+
}
|
15
|
+
|
16
|
+
export default registerAs<GoogleConfig>('google', () => {
|
17
|
+
validateConfig(process.env, EnvironmentVariablesValidator);
|
18
|
+
|
19
|
+
return {
|
20
|
+
clientId: process.env.GOOGLE_CLIENT_ID,
|
21
|
+
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
|
22
|
+
};
|
23
|
+
});
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { registerAs } from '@nestjs/config';
|
2
|
+
import { IsString, IsOptional } from 'class-validator';
|
3
|
+
import { validateConfig } from '../../util';
|
4
|
+
|
5
|
+
class EnvironmentVariablesValidator {
|
6
|
+
@IsString()
|
7
|
+
@IsOptional()
|
8
|
+
TWITTER_CONSUMER_KEY: string;
|
9
|
+
|
10
|
+
@IsString()
|
11
|
+
@IsOptional()
|
12
|
+
TWITTER_CONSUMER_SECRET: string;
|
13
|
+
}
|
14
|
+
|
15
|
+
export default registerAs('twitter', () => {
|
16
|
+
validateConfig(process.env, EnvironmentVariablesValidator);
|
17
|
+
|
18
|
+
return {
|
19
|
+
consumerKey: process.env.TWITTER_CONSUMER_KEY,
|
20
|
+
consumerSecret: process.env.TWITTER_CONSUMER_SECRET,
|
21
|
+
};
|
22
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './facebook-login.dto';
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { Module } from '@nestjs/common';
|
2
|
+
import { ConfigModule } from '@nestjs/config';
|
3
|
+
import { FacebookService } from './facebook.service';
|
4
|
+
|
5
|
+
@Module({
|
6
|
+
imports: [ConfigModule],
|
7
|
+
providers: [FacebookService],
|
8
|
+
exports: [FacebookService],
|
9
|
+
controllers: [],
|
10
|
+
})
|
11
|
+
export class FacebookModule {}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import { Facebook } from 'fb';
|
2
|
+
import { Injectable } from '@nestjs/common';
|
3
|
+
import { ConfigService } from '@nestjs/config';
|
4
|
+
import { SocialInterface } from '../../interface';
|
5
|
+
import { FacebookInterface } from './interface';
|
6
|
+
import { FacebookLoginDto } from './dto/facebook-login.dto';
|
7
|
+
import { AllConfigType } from '../../config';
|
8
|
+
|
9
|
+
@Injectable()
|
10
|
+
export class FacebookService {
|
11
|
+
private fb: Facebook;
|
12
|
+
|
13
|
+
constructor(private readonly configService: ConfigService<AllConfigType>) {
|
14
|
+
this.fb = new Facebook({
|
15
|
+
appId: configService.get('facebook.appId', {
|
16
|
+
infer: true,
|
17
|
+
}),
|
18
|
+
appSecret: configService.get('facebook.appSecret', {
|
19
|
+
infer: true,
|
20
|
+
}),
|
21
|
+
version: 'v7.0',
|
22
|
+
});
|
23
|
+
}
|
24
|
+
|
25
|
+
async getProfileByToken(
|
26
|
+
loginDto: FacebookLoginDto,
|
27
|
+
): Promise<SocialInterface> {
|
28
|
+
const { accessToken } = loginDto;
|
29
|
+
this.fb.setAccessToken(accessToken);
|
30
|
+
|
31
|
+
const data: FacebookInterface = await new Promise((resolve) => {
|
32
|
+
this.fb.api(
|
33
|
+
'/me',
|
34
|
+
'get',
|
35
|
+
{ fields: 'id,last_name,email,first_name' },
|
36
|
+
(response: FacebookInterface) => {
|
37
|
+
resolve(response);
|
38
|
+
},
|
39
|
+
);
|
40
|
+
});
|
41
|
+
|
42
|
+
const { id, email, first_name, last_name } = data;
|
43
|
+
|
44
|
+
return {
|
45
|
+
id: id,
|
46
|
+
email: email,
|
47
|
+
firstName: first_name,
|
48
|
+
lastName: last_name,
|
49
|
+
};
|
50
|
+
}
|
51
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './facebook.interface';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './google-login.dto';
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { Module } from '@nestjs/common';
|
2
|
+
import { ConfigModule } from '@nestjs/config';
|
3
|
+
import { GoogleService } from './google.service';
|
4
|
+
|
5
|
+
@Module({
|
6
|
+
imports: [ConfigModule],
|
7
|
+
providers: [GoogleService],
|
8
|
+
exports: [GoogleService],
|
9
|
+
})
|
10
|
+
export class GoogleModule {}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
2
|
+
import { ConfigService } from '@nestjs/config';
|
3
|
+
import { OAuth2Client } from 'google-auth-library';
|
4
|
+
import { SocialInterface } from '../../interface';
|
5
|
+
import { GoogleLoginDto } from './dto/google-login.dto';
|
6
|
+
import { AllConfigType } from '../../config';
|
7
|
+
|
8
|
+
@Injectable()
|
9
|
+
export class GoogleService {
|
10
|
+
private google: OAuth2Client;
|
11
|
+
|
12
|
+
constructor(private configService: ConfigService<AllConfigType>) {
|
13
|
+
this.google = new OAuth2Client(
|
14
|
+
configService.get('google.clientId', { infer: true }),
|
15
|
+
configService.get('google.clientSecret', { infer: true }),
|
16
|
+
);
|
17
|
+
}
|
18
|
+
|
19
|
+
async getProfileByToken(loginDto: GoogleLoginDto): Promise<SocialInterface> {
|
20
|
+
const { idToken } = loginDto;
|
21
|
+
const ticket = await this.google.verifyIdToken({
|
22
|
+
idToken: idToken,
|
23
|
+
audience: [
|
24
|
+
this.configService.getOrThrow('google.clientId', { infer: true }),
|
25
|
+
],
|
26
|
+
});
|
27
|
+
|
28
|
+
const data = ticket.getPayload();
|
29
|
+
|
30
|
+
if (!data) {
|
31
|
+
throw new HttpException(
|
32
|
+
{
|
33
|
+
status: HttpStatus.UNPROCESSABLE_ENTITY,
|
34
|
+
errors: {
|
35
|
+
user: 'wrongToken',
|
36
|
+
},
|
37
|
+
},
|
38
|
+
HttpStatus.UNPROCESSABLE_ENTITY,
|
39
|
+
);
|
40
|
+
}
|
41
|
+
|
42
|
+
const { sub, email, given_name, family_name } = data;
|
43
|
+
|
44
|
+
return {
|
45
|
+
id: sub,
|
46
|
+
email: email,
|
47
|
+
firstName: given_name,
|
48
|
+
lastName: family_name,
|
49
|
+
};
|
50
|
+
}
|
51
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './twitter-login.dto';
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { ApiProperty } from '@nestjs/swagger';
|
2
|
+
import { IsNotEmpty } from 'class-validator';
|
3
|
+
|
4
|
+
export class TwitterLoginDto {
|
5
|
+
@ApiProperty({ example: 'abc' })
|
6
|
+
@IsNotEmpty()
|
7
|
+
accessTokenKey: string;
|
8
|
+
|
9
|
+
@ApiProperty({ example: 'abc' })
|
10
|
+
@IsNotEmpty()
|
11
|
+
accessTokenSecret: string;
|
12
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { Module } from '@nestjs/common';
|
2
|
+
import { ConfigModule } from '@nestjs/config';
|
3
|
+
import { TwitterService } from './twitter.service';
|
4
|
+
|
5
|
+
@Module({
|
6
|
+
imports: [ConfigModule],
|
7
|
+
providers: [TwitterService],
|
8
|
+
exports: [TwitterService],
|
9
|
+
controllers: [],
|
10
|
+
})
|
11
|
+
export class TwitterModule {}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import Twitter from 'twitter';
|
2
|
+
import { Injectable } from '@nestjs/common';
|
3
|
+
import { ConfigService } from '@nestjs/config';
|
4
|
+
import { AllConfigType } from '../../config';
|
5
|
+
import { SocialInterface } from '../../interface';
|
6
|
+
import { TwitterLoginDto } from './dto/twitter-login.dto';
|
7
|
+
|
8
|
+
@Injectable()
|
9
|
+
export class TwitterService {
|
10
|
+
constructor(private configService: ConfigService<AllConfigType>) {}
|
11
|
+
|
12
|
+
async getProfileByToken(loginDto: TwitterLoginDto): Promise<SocialInterface> {
|
13
|
+
const { accessTokenKey, accessTokenSecret } = loginDto;
|
14
|
+
const twitter = new Twitter({
|
15
|
+
consumer_key: this.configService.getOrThrow('twitter.consumerKey', {
|
16
|
+
infer: true,
|
17
|
+
}),
|
18
|
+
consumer_secret: this.configService.getOrThrow('twitter.consumerSecret', {
|
19
|
+
infer: true,
|
20
|
+
}),
|
21
|
+
access_token_key: accessTokenKey,
|
22
|
+
access_token_secret: accessTokenSecret,
|
23
|
+
});
|
24
|
+
|
25
|
+
const data: Twitter.ResponseData = await new Promise((resolve) => {
|
26
|
+
twitter.get(
|
27
|
+
'account/verify_credentials',
|
28
|
+
{ include_email: true },
|
29
|
+
(error, profile) => {
|
30
|
+
resolve(profile);
|
31
|
+
},
|
32
|
+
);
|
33
|
+
});
|
34
|
+
|
35
|
+
const { id, email, name } = data;
|
36
|
+
|
37
|
+
return {
|
38
|
+
id: id.toString(),
|
39
|
+
email: email,
|
40
|
+
firstName: name,
|
41
|
+
};
|
42
|
+
}
|
43
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './type.config';
|
@@ -0,0 +1,88 @@
|
|
1
|
+
export type AppConfig = {
|
2
|
+
nodeEnv: string;
|
3
|
+
name: string;
|
4
|
+
workingDirectory: string;
|
5
|
+
frontendDomain?: string;
|
6
|
+
backendDomain: string;
|
7
|
+
port: number;
|
8
|
+
apiPrefix: string;
|
9
|
+
fallbackLanguage: string;
|
10
|
+
headerLanguage: string;
|
11
|
+
};
|
12
|
+
|
13
|
+
export type AppleConfig = {
|
14
|
+
appAudience: string[];
|
15
|
+
};
|
16
|
+
|
17
|
+
export type AuthConfig = {
|
18
|
+
secret?: string;
|
19
|
+
expires?: string;
|
20
|
+
refreshSecret?: string;
|
21
|
+
refreshExpires?: string;
|
22
|
+
};
|
23
|
+
|
24
|
+
export type DatabaseConfig = {
|
25
|
+
url?: string;
|
26
|
+
type?: string;
|
27
|
+
host?: string;
|
28
|
+
port?: number;
|
29
|
+
password?: string;
|
30
|
+
name?: string;
|
31
|
+
username?: string;
|
32
|
+
synchronize?: boolean;
|
33
|
+
maxConnections: number;
|
34
|
+
sslEnabled?: boolean;
|
35
|
+
rejectUnauthorized?: boolean;
|
36
|
+
ca?: string;
|
37
|
+
key?: string;
|
38
|
+
cert?: string;
|
39
|
+
};
|
40
|
+
|
41
|
+
export type FacebookConfig = {
|
42
|
+
appId?: string;
|
43
|
+
appSecret?: string;
|
44
|
+
};
|
45
|
+
|
46
|
+
export type FileConfig = {
|
47
|
+
driver: string;
|
48
|
+
accessKeyId?: string;
|
49
|
+
secretAccessKey?: string;
|
50
|
+
awsDefaultS3Bucket?: string;
|
51
|
+
awsDefaultS3Url?: string;
|
52
|
+
awsS3Region?: string;
|
53
|
+
maxFileSize: number;
|
54
|
+
};
|
55
|
+
|
56
|
+
export type GoogleConfig = {
|
57
|
+
clientId?: string;
|
58
|
+
clientSecret?: string;
|
59
|
+
};
|
60
|
+
|
61
|
+
export type MailConfig = {
|
62
|
+
port: number;
|
63
|
+
host?: string;
|
64
|
+
user?: string;
|
65
|
+
password?: string;
|
66
|
+
defaultEmail?: string;
|
67
|
+
defaultName?: string;
|
68
|
+
ignoreTLS: boolean;
|
69
|
+
secure: boolean;
|
70
|
+
requireTLS: boolean;
|
71
|
+
};
|
72
|
+
|
73
|
+
export type TwitterConfig = {
|
74
|
+
consumerKey?: string;
|
75
|
+
consumerSecret?: string;
|
76
|
+
};
|
77
|
+
|
78
|
+
export type AllConfigType = {
|
79
|
+
app: AppConfig;
|
80
|
+
apple: AppleConfig;
|
81
|
+
auth: AuthConfig;
|
82
|
+
database: DatabaseConfig;
|
83
|
+
facebook: FacebookConfig;
|
84
|
+
file: FileConfig;
|
85
|
+
google: GoogleConfig;
|
86
|
+
mail: MailConfig;
|
87
|
+
twitter: TwitterConfig;
|
88
|
+
};
|
@@ -1,4 +1,16 @@
|
|
1
|
+
import { ApiPropertyOptional } from '@nestjs/swagger';
|
2
|
+
import { Type } from 'class-transformer';
|
3
|
+
|
1
4
|
export class PaginationDto {
|
2
|
-
|
3
|
-
|
5
|
+
@ApiPropertyOptional()
|
6
|
+
@Type(() => String)
|
7
|
+
query?: string;
|
8
|
+
|
9
|
+
@ApiPropertyOptional()
|
10
|
+
@Type(() => Number)
|
11
|
+
limit?: number = 25;
|
12
|
+
|
13
|
+
@ApiPropertyOptional()
|
14
|
+
@Type(() => Number)
|
15
|
+
offset?: number = 0;
|
4
16
|
}
|