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.
Files changed (191) hide show
  1. package/package.json +12 -2
  2. package/src/auth/apple/apple.module.ts +10 -0
  3. package/src/auth/apple/apple.service.ts +28 -0
  4. package/src/auth/apple/dto/apple-login.dto.ts +16 -0
  5. package/src/auth/apple/dto/index.ts +1 -0
  6. package/src/auth/apple/index.ts +3 -0
  7. package/src/auth/config/apple.config.ts +18 -0
  8. package/src/auth/config/auth.config.ts +29 -0
  9. package/src/auth/config/facebook.config.ts +23 -0
  10. package/src/auth/config/file.config.ts +50 -0
  11. package/src/auth/config/google.config.ts +23 -0
  12. package/src/auth/config/index.ts +6 -0
  13. package/src/auth/config/twitter.config.ts +22 -0
  14. package/src/auth/facebook/dto/facebook-login.dto.ts +8 -0
  15. package/src/auth/facebook/dto/index.ts +1 -0
  16. package/src/auth/facebook/facebook.module.ts +11 -0
  17. package/src/auth/facebook/facebook.service.ts +51 -0
  18. package/src/auth/facebook/index.ts +4 -0
  19. package/src/auth/facebook/interface/facebook.interface.ts +6 -0
  20. package/src/auth/facebook/interface/index.ts +1 -0
  21. package/src/auth/google/dto/google-login.dto.ts +8 -0
  22. package/src/auth/google/dto/index.ts +1 -0
  23. package/src/auth/google/google.module.ts +10 -0
  24. package/src/auth/google/google.service.ts +51 -0
  25. package/src/auth/google/index.ts +3 -0
  26. package/src/auth/index.ts +5 -0
  27. package/src/auth/twitter/dto/index.ts +1 -0
  28. package/src/auth/twitter/dto/twitter-login.dto.ts +12 -0
  29. package/src/auth/twitter/index.ts +3 -0
  30. package/src/auth/twitter/twitter.module.ts +11 -0
  31. package/src/auth/twitter/twitter.service.ts +43 -0
  32. package/src/config/index.ts +1 -0
  33. package/src/config/type.config.ts +88 -0
  34. package/src/dto/pagination.dto.ts +14 -2
  35. package/src/exception/bad-request-error.exception.spec.ts +24 -0
  36. package/src/exception/bad-request-error.exception.ts +8 -0
  37. package/src/exception/base.exception.ts +36 -0
  38. package/src/exception/conflict-error.exception.spec.ts +23 -0
  39. package/src/exception/conflict-error.exception.ts +8 -0
  40. package/src/exception/forbidden-error.exception.spec.ts +23 -0
  41. package/src/exception/forbidden-error.exception.ts +8 -0
  42. package/src/exception/index.ts +7 -0
  43. package/src/exception/internal-server-error.exception.spec.ts +23 -0
  44. package/src/exception/internal-server-error.exception.ts +12 -0
  45. package/src/exception/not-found-error.exception.spec.ts +23 -0
  46. package/src/exception/not-found-error.exception.ts +8 -0
  47. package/src/exception/unauthorized-error.exception.spec.ts +23 -0
  48. package/src/exception/unauthorized-error.exception.ts +12 -0
  49. package/src/filter/http-exception.filter.ts +23 -0
  50. package/src/filter/index.ts +1 -0
  51. package/src/filter/rpc-exception.filter.ts +15 -0
  52. package/src/index.ts +3 -0
  53. package/src/interface/index.ts +1 -0
  54. package/src/interface/social.interface.ts +6 -0
  55. package/src/lib/index.ts +2 -0
  56. package/src/lib/mailer/config/index.ts +1 -0
  57. package/src/lib/mailer/config/mailer.config.ts +62 -0
  58. package/src/lib/mailer/index.ts +2 -0
  59. package/src/lib/mailer/mailer.module.ts +8 -0
  60. package/src/lib/mailer/mailer.service.ts +53 -0
  61. package/src/lib/redis/index.ts +0 -0
  62. package/src/lib/search-engine/document/base.document.ts +2 -2
  63. package/src/lib/search-engine/interface/search-document.interface.ts +10 -2
  64. package/src/lib/search-engine/schema/generic.schema.ts +1 -1
  65. package/src/lib/search-engine/schema/index.ts +1 -1
  66. package/src/lib/search-engine/typesense/collection/index.ts +1 -0
  67. package/src/lib/search-engine/typesense/document/index.ts +1 -0
  68. package/src/lib/search-engine/typesense/index.ts +1 -0
  69. package/src/lib/search-engine/typesense/service/client.service.ts +5 -3
  70. package/src/lib/storage/index.ts +0 -0
  71. package/src/lib/typesense/client/index.ts +1 -0
  72. package/src/lib/typesense/collection/index.ts +1 -0
  73. package/src/lib/typesense/decorator/field.decorator.spec.ts +89 -0
  74. package/src/lib/typesense/decorator/field.decorator.ts +44 -0
  75. package/src/lib/typesense/decorator/index.ts +2 -0
  76. package/src/lib/typesense/decorator/schema.decorator.ts +23 -0
  77. package/src/lib/typesense/document/base.document.ts +3 -0
  78. package/src/lib/typesense/index.ts +6 -0
  79. package/src/lib/typesense/metadata/index.ts +4 -0
  80. package/src/lib/typesense/metadata/schema.metadata.ts +21 -0
  81. package/src/lib/typesense/metadata/typesense.metadata-accessor.ts +37 -0
  82. package/src/lib/typesense/metadata/typesense.metadata-explorer.spec.ts +56 -0
  83. package/src/lib/typesense/metadata/typesense.metadata-explorer.ts +41 -0
  84. package/src/lib/typesense/metadata/typesense.metadata-registry.ts +28 -0
  85. package/src/lib/typesense/module/index.ts +4 -0
  86. package/src/lib/typesense/module/interface.module.ts +34 -0
  87. package/src/lib/typesense/module/typesense.constant.ts +1 -0
  88. package/src/lib/typesense/module/typesense.module.spec.ts +94 -0
  89. package/src/lib/typesense/module/typesense.module.ts +87 -0
  90. package/src/lib/typesense/module/typesense.provider.ts +54 -0
  91. package/src/response/base-entity.response.ts +8 -0
  92. package/src/response/index.ts +1 -0
  93. package/src/response/login.response.ts +0 -0
  94. package/src/response/pagination.response.ts +23 -8
  95. package/src/setup/index.ts +1 -0
  96. package/src/setup/microservice.setup.ts +29 -0
  97. package/src/setup/swagger.setup.ts +0 -0
  98. package/src/util/app.utils.ts +18 -0
  99. package/src/util/index.ts +2 -0
  100. package/src/util/validate-config.ts +20 -0
  101. package/dist/index.d.ts +0 -1
  102. package/dist/index.js +0 -18
  103. package/dist/index.js.map +0 -1
  104. package/dist/src/dto/base-filter.dto.d.ts +0 -4
  105. package/dist/src/dto/base-filter.dto.js +0 -11
  106. package/dist/src/dto/base-filter.dto.js.map +0 -1
  107. package/dist/src/dto/index.d.ts +0 -2
  108. package/dist/src/dto/index.js +0 -19
  109. package/dist/src/dto/index.js.map +0 -1
  110. package/dist/src/dto/pagination.dto.d.ts +0 -4
  111. package/dist/src/dto/pagination.dto.js +0 -11
  112. package/dist/src/dto/pagination.dto.js.map +0 -1
  113. package/dist/src/index.d.ts +0 -6
  114. package/dist/src/index.js +0 -23
  115. package/dist/src/index.js.map +0 -1
  116. package/dist/src/lib/index.d.ts +0 -1
  117. package/dist/src/lib/index.js +0 -18
  118. package/dist/src/lib/index.js.map +0 -1
  119. package/dist/src/lib/search-engine/document/base.document.d.ts +0 -3
  120. package/dist/src/lib/search-engine/document/base.document.js +0 -7
  121. package/dist/src/lib/search-engine/document/base.document.js.map +0 -1
  122. package/dist/src/lib/search-engine/document/index.js +0 -18
  123. package/dist/src/lib/search-engine/document/index.js.map +0 -1
  124. package/dist/src/lib/search-engine/index.d.ts +0 -1
  125. package/dist/src/lib/search-engine/index.js +0 -18
  126. package/dist/src/lib/search-engine/index.js.map +0 -1
  127. package/dist/src/lib/search-engine/interface/index.d.ts +0 -2
  128. package/dist/src/lib/search-engine/interface/index.js +0 -19
  129. package/dist/src/lib/search-engine/interface/index.js.map +0 -1
  130. package/dist/src/lib/search-engine/interface/search-document.interface.d.ts +0 -4
  131. package/dist/src/lib/search-engine/interface/search-document.interface.js +0 -3
  132. package/dist/src/lib/search-engine/interface/search-document.interface.js.map +0 -1
  133. package/dist/src/lib/search-engine/interface/transform-service.interface.d.ts +0 -6
  134. package/dist/src/lib/search-engine/interface/transform-service.interface.js +0 -3
  135. package/dist/src/lib/search-engine/interface/transform-service.interface.js.map +0 -1
  136. package/dist/src/lib/search-engine/schema/generic.schema.d.ts +0 -2
  137. package/dist/src/lib/search-engine/schema/generic.schema.js +0 -7
  138. package/dist/src/lib/search-engine/schema/generic.schema.js.map +0 -1
  139. package/dist/src/lib/search-engine/schema/index.d.ts +0 -1
  140. package/dist/src/lib/search-engine/schema/index.js +0 -18
  141. package/dist/src/lib/search-engine/schema/index.js.map +0 -1
  142. package/dist/src/lib/search-engine/typesense/index.d.ts +0 -3
  143. package/dist/src/lib/search-engine/typesense/index.js +0 -20
  144. package/dist/src/lib/search-engine/typesense/index.js.map +0 -1
  145. package/dist/src/lib/search-engine/typesense/metadata/index.d.ts +0 -2
  146. package/dist/src/lib/search-engine/typesense/metadata/index.js +0 -19
  147. package/dist/src/lib/search-engine/typesense/metadata/index.js.map +0 -1
  148. package/dist/src/lib/search-engine/typesense/metadata/schema.metadata.d.ts +0 -12
  149. package/dist/src/lib/search-engine/typesense/metadata/schema.metadata.js +0 -3
  150. package/dist/src/lib/search-engine/typesense/metadata/schema.metadata.js.map +0 -1
  151. package/dist/src/lib/search-engine/typesense/metadata/typesense.metadata-registry.d.ts +0 -10
  152. package/dist/src/lib/search-engine/typesense/metadata/typesense.metadata-registry.js +0 -33
  153. package/dist/src/lib/search-engine/typesense/metadata/typesense.metadata-registry.js.map +0 -1
  154. package/dist/src/lib/search-engine/typesense/service/client.service.d.ts +0 -33
  155. package/dist/src/lib/search-engine/typesense/service/client.service.js +0 -197
  156. package/dist/src/lib/search-engine/typesense/service/client.service.js.map +0 -1
  157. package/dist/src/lib/search-engine/typesense/service/index.d.ts +0 -1
  158. package/dist/src/lib/search-engine/typesense/service/index.js +0 -18
  159. package/dist/src/lib/search-engine/typesense/service/index.js.map +0 -1
  160. package/dist/src/lib/search-engine/typesense/typesense-module.interface.d.ts +0 -27
  161. package/dist/src/lib/search-engine/typesense/typesense-module.interface.js +0 -3
  162. package/dist/src/lib/search-engine/typesense/typesense-module.interface.js.map +0 -1
  163. package/dist/src/lib/search-engine/typesense/typesense.constants.d.ts +0 -1
  164. package/dist/src/lib/search-engine/typesense/typesense.constants.js +0 -5
  165. package/dist/src/lib/search-engine/typesense/typesense.constants.js.map +0 -1
  166. package/dist/src/lib/search-engine/typesense/typesense.module.d.ts +0 -8
  167. package/dist/src/lib/search-engine/typesense/typesense.module.js +0 -68
  168. package/dist/src/lib/search-engine/typesense/typesense.module.js.map +0 -1
  169. package/dist/src/lib/search-engine/typesense/typesense.module.test.d.ts +0 -1
  170. package/dist/src/lib/search-engine/typesense/typesense.module.test.js +0 -89
  171. package/dist/src/lib/search-engine/typesense/typesense.module.test.js.map +0 -1
  172. package/dist/src/lib/search-engine/typesense/typesense.providers.d.ts +0 -4
  173. package/dist/src/lib/search-engine/typesense/typesense.providers.js +0 -40
  174. package/dist/src/lib/search-engine/typesense/typesense.providers.js.map +0 -1
  175. package/dist/src/response/index.d.ts +0 -1
  176. package/dist/src/response/index.js +0 -18
  177. package/dist/src/response/index.js.map +0 -1
  178. package/dist/src/response/pagination.response.d.ts +0 -17
  179. package/dist/src/response/pagination.response.js +0 -29
  180. package/dist/src/response/pagination.response.js.map +0 -1
  181. package/dist/src/util/date.util.d.ts +0 -2
  182. package/dist/src/util/date.util.js +0 -14
  183. package/dist/src/util/date.util.js.map +0 -1
  184. package/dist/src/util/generator.util.d.ts +0 -4
  185. package/dist/src/util/generator.util.js +0 -29
  186. package/dist/src/util/generator.util.js.map +0 -1
  187. package/dist/src/util/index.d.ts +0 -2
  188. package/dist/src/util/index.js +0 -19
  189. package/dist/src/util/index.js.map +0 -1
  190. package/dist/tsconfig.build.tsbuildinfo +0 -1
  191. /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.4",
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,3 @@
1
+ export * from './dto';
2
+ export * from './apple.module';
3
+ export * from './apple.service';
@@ -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,6 @@
1
+ export * from './auth.config';
2
+ export * from './file.config';
3
+ export * from './apple.config';
4
+ export * from './google.config';
5
+ export * from './twitter.config';
6
+ export * from './facebook.config';
@@ -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,8 @@
1
+ import { ApiProperty } from '@nestjs/swagger';
2
+ import { IsNotEmpty } from 'class-validator';
3
+
4
+ export class FacebookLoginDto {
5
+ @ApiProperty({ example: 'abc' })
6
+ @IsNotEmpty()
7
+ accessToken: string;
8
+ }
@@ -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,4 @@
1
+ export * from './dto';
2
+ export * from './interface';
3
+ export * from './facebook.module';
4
+ export * from './facebook.service';
@@ -0,0 +1,6 @@
1
+ export interface FacebookInterface {
2
+ id: string;
3
+ first_name?: string;
4
+ last_name?: string;
5
+ email?: string;
6
+ }
@@ -0,0 +1 @@
1
+ export * from './facebook.interface';
@@ -0,0 +1,8 @@
1
+ import { ApiProperty } from '@nestjs/swagger';
2
+ import { IsNotEmpty } from 'class-validator';
3
+
4
+ export class GoogleLoginDto {
5
+ @ApiProperty({ example: 'abc' })
6
+ @IsNotEmpty()
7
+ idToken: string;
8
+ }
@@ -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,3 @@
1
+ export * from './dto';
2
+ export * from './google.module';
3
+ export * from './google.service';
@@ -0,0 +1,5 @@
1
+ export * from './apple';
2
+ export * from './config';
3
+ export * from './facebook';
4
+ export * from './google';
5
+ export * from './twitter';
@@ -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,3 @@
1
+ export * from './dto';
2
+ export * from './twitter.module';
3
+ export * from './twitter.service';
@@ -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
- limit = 25;
3
- offset = 0;
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
  }