@merkaly/api 0.2.5-4 → 0.2.5-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 (241) hide show
  1. package/.bin/deploy.sh +9 -0
  2. package/.bin/package.sh +12 -0
  3. package/.docker/Dockerfile +21 -0
  4. package/.dockerignore +12 -0
  5. package/.github/dependabot.yml +17 -0
  6. package/.github/semantic.yml +5 -0
  7. package/.github/workflows/pull_request.yml +35 -0
  8. package/.prettierrc +5 -0
  9. package/app.ts +11 -0
  10. package/authCertificate.pem +19 -0
  11. package/nest-cli.json +8 -0
  12. package/package.json +66 -78
  13. package/src/abstracts/abstarct.repository.ts +62 -0
  14. package/src/abstracts/abstract.controller.ts +18 -0
  15. package/src/abstracts/abstract.entity.ts +22 -0
  16. package/src/abstracts/abstract.router.ts +7 -0
  17. package/src/abstracts/abstract.validator.ts +61 -0
  18. package/src/app.config.ts +59 -0
  19. package/src/app.console.ts +24 -0
  20. package/src/app.guard.ts +39 -0
  21. package/src/app.module.ts +54 -0
  22. package/src/app.strategy.ts +21 -0
  23. package/src/commands/seed.command.ts +263 -0
  24. package/src/decorators/public.decorator.ts +5 -0
  25. package/src/decorators/user.decorator.ts +30 -0
  26. package/src/exceptions/missing-identity.exception.ts +11 -0
  27. package/src/interceptors/mongoose.interceptor.ts +63 -0
  28. package/src/main.ts +27 -0
  29. package/src/middlewares/router.middleware.ts +14 -0
  30. package/src/modules/asset/asset.module.ts +19 -0
  31. package/src/modules/asset/files/file.controller.ts +22 -0
  32. package/src/modules/asset/files/file.entity.ts +24 -0
  33. package/src/modules/asset/files/file.module.ts +21 -0
  34. package/src/modules/asset/files/file.repository.ts +44 -0
  35. package/src/modules/asset/files/file.schema.ts +8 -0
  36. package/src/modules/asset/files/file.service.ts +4 -0
  37. package/src/modules/auth/auth.controller.ts +57 -0
  38. package/src/modules/auth/auth.module.ts +20 -0
  39. package/src/modules/auth/organizations/organization.controller.ts +20 -0
  40. package/src/modules/auth/organizations/organization.entity.ts +22 -0
  41. package/src/modules/auth/organizations/organization.module.ts +21 -0
  42. package/src/modules/auth/organizations/organization.repository.ts +16 -0
  43. package/src/modules/auth/organizations/organization.schema.ts +8 -0
  44. package/src/modules/auth/users/user.controller.ts +23 -0
  45. package/src/modules/auth/users/user.entity.ts +25 -0
  46. package/src/modules/auth/users/user.module.ts +20 -0
  47. package/src/modules/auth/users/user.repository.ts +79 -0
  48. package/src/modules/auth/users/user.schema.ts +8 -0
  49. package/src/modules/auth/users/user.validator.ts +32 -0
  50. package/src/modules/command.module.ts +15 -0
  51. package/src/modules/global.module.ts +46 -0
  52. package/src/modules/inventory/brands/brand.controller.ts +44 -0
  53. package/src/modules/inventory/brands/brand.entity.ts +20 -0
  54. package/src/modules/inventory/brands/brand.module.ts +20 -0
  55. package/src/modules/inventory/brands/brand.repository.ts +40 -0
  56. package/src/modules/inventory/brands/brand.schema.ts +8 -0
  57. package/src/modules/inventory/brands/brand.validator.ts +31 -0
  58. package/src/modules/inventory/categories/category.controller.ts +42 -0
  59. package/src/modules/inventory/categories/category.entity.ts +15 -0
  60. package/src/modules/inventory/categories/category.module.ts +19 -0
  61. package/src/modules/inventory/categories/category.repository.ts +34 -0
  62. package/src/modules/inventory/categories/category.schema.ts +8 -0
  63. package/src/modules/inventory/categories/category.validator.ts +20 -0
  64. package/src/modules/inventory/complements/complement.controller.ts +41 -0
  65. package/src/modules/inventory/complements/complement.entity.ts +15 -0
  66. package/src/modules/inventory/complements/complement.module.ts +19 -0
  67. package/src/modules/inventory/complements/complement.repository.ts +37 -0
  68. package/src/modules/inventory/complements/complement.schema.ts +8 -0
  69. package/src/modules/inventory/complements/complement.validator.ts +28 -0
  70. package/src/modules/inventory/inventory.module.ts +23 -0
  71. package/src/modules/inventory/products/documents/attribute.document.ts +14 -0
  72. package/src/modules/inventory/products/documents/dimension.document.ts +16 -0
  73. package/src/modules/inventory/products/product.controller.ts +62 -0
  74. package/src/modules/inventory/products/product.entity.ts +46 -0
  75. package/src/modules/inventory/products/product.module.ts +19 -0
  76. package/src/modules/inventory/products/product.repository.ts +64 -0
  77. package/src/modules/inventory/products/product.schema.ts +19 -0
  78. package/src/modules/inventory/products/product.validator.ts +132 -0
  79. package/src/modules/inventory/products/validators/attributes.validator.ts +15 -0
  80. package/src/modules/inventory/products/validators/dimension.validator.ts +19 -0
  81. package/src/modules/sale/customers/customer.controller.ts +41 -0
  82. package/src/modules/sale/customers/customer.entity.ts +19 -0
  83. package/src/modules/sale/customers/customer.module.ts +18 -0
  84. package/src/modules/sale/customers/customer.repository.ts +30 -0
  85. package/src/modules/sale/customers/customer.schema.ts +8 -0
  86. package/src/modules/sale/customers/customer.validator.ts +43 -0
  87. package/src/modules/sale/orders/documents/address.document.ts +22 -0
  88. package/src/modules/sale/orders/documents/status.document.ts +17 -0
  89. package/src/modules/sale/orders/entities/item.entity.ts +24 -0
  90. package/src/modules/sale/orders/enums/order.status.ts +6 -0
  91. package/src/modules/sale/orders/order.controller.ts +65 -0
  92. package/src/modules/sale/orders/order.entity.ts +46 -0
  93. package/src/modules/sale/orders/order.module.ts +22 -0
  94. package/src/modules/sale/orders/order.repository.ts +122 -0
  95. package/src/modules/sale/orders/order.schema.ts +36 -0
  96. package/src/modules/sale/orders/order.validator.ts +44 -0
  97. package/src/modules/sale/orders/validators/address.validator.ts +50 -0
  98. package/src/modules/sale/orders/validators/billing.validator.ts +11 -0
  99. package/src/modules/sale/orders/validators/item.validator.ts +14 -0
  100. package/src/modules/sale/orders/validators/payment.validator.ts +44 -0
  101. package/src/modules/sale/orders/validators/shipping.validator.ts +14 -0
  102. package/src/modules/sale/payments/entities/status.entity.ts +17 -0
  103. package/src/modules/sale/payments/enums/billing.type.ts +6 -0
  104. package/src/modules/sale/payments/enums/payment.status.ts +7 -0
  105. package/src/modules/sale/payments/enums/shipping.type.ts +4 -0
  106. package/src/modules/sale/payments/payment.controller.ts +45 -0
  107. package/src/modules/sale/payments/payment.entity.ts +25 -0
  108. package/src/modules/sale/payments/payment.module.ts +20 -0
  109. package/src/modules/sale/payments/payment.repository.ts +57 -0
  110. package/src/modules/sale/payments/payment.schema.ts +14 -0
  111. package/src/modules/sale/payments/payment.validator.ts +32 -0
  112. package/src/modules/sale/sale.module.ts +20 -0
  113. package/src/services/auth0.service.ts +49 -0
  114. package/src/services/mongo.service.ts +52 -0
  115. package/test/auth/auth.spec.ts +20 -0
  116. package/test/main.ts +12 -0
  117. package/tsconfig.build.json +4 -0
  118. package/tsconfig.json +21 -0
  119. package/tsconfig.package.json +22 -0
  120. package/.output/abstract/abstract.entity.d.ts +0 -9
  121. package/.output/abstract/abstract.exception.d.ts +0 -11
  122. package/.output/abstract/abstract.exception.js +0 -53
  123. package/.output/abstract/abstract.fixture.d.ts +0 -4
  124. package/.output/abstract/abstract.fixture.js +0 -11
  125. package/.output/abstract/abstract.validator.d.ts +0 -20
  126. package/.output/abstract/abstract.validator.js +0 -105
  127. package/.output/exceptions/missing-identity.exception.d.ts +0 -5
  128. package/.output/exceptions/missing-identity.exception.js +0 -30
  129. package/.output/exceptions/store-not-implemented.exception.d.ts +0 -5
  130. package/.output/exceptions/store-not-implemented.exception.js +0 -31
  131. package/.output/exceptions/store-not-recognized.exception.d.ts +0 -5
  132. package/.output/exceptions/store-not-recognized.exception.js +0 -30
  133. package/.output/modules/asset/files/file.entity.d.ts +0 -10
  134. package/.output/modules/auth/auth.types.d.ts +0 -3
  135. package/.output/modules/auth/auth.types.js +0 -7
  136. package/.output/modules/auth/users/user.validator.d.ts +0 -10
  137. package/.output/modules/auth/users/user.validator.js +0 -50
  138. package/.output/modules/config/organization/organization.entity.d.ts +0 -21
  139. package/.output/modules/config/organization/organization.types.d.ts +0 -23
  140. package/.output/modules/config/organization/organization.types.js +0 -107
  141. package/.output/modules/config/organization/organization.validator.d.ts +0 -18
  142. package/.output/modules/config/organization/organization.validator.js +0 -88
  143. package/.output/modules/insight/validators/order.validator.d.ts +0 -4
  144. package/.output/modules/insight/validators/order.validator.js +0 -27
  145. package/.output/modules/inventory/brands/brand.entity.d.ts +0 -9
  146. package/.output/modules/inventory/brands/brand.exception.d.ts +0 -5
  147. package/.output/modules/inventory/brands/brand.exception.js +0 -40
  148. package/.output/modules/inventory/brands/brand.validator.d.ts +0 -11
  149. package/.output/modules/inventory/brands/brand.validator.js +0 -75
  150. package/.output/modules/inventory/categories/category.entity.d.ts +0 -12
  151. package/.output/modules/inventory/categories/category.exception.d.ts +0 -5
  152. package/.output/modules/inventory/categories/category.exception.js +0 -40
  153. package/.output/modules/inventory/categories/category.fixture.d.ts +0 -5
  154. package/.output/modules/inventory/categories/category.fixture.js +0 -38
  155. package/.output/modules/inventory/categories/category.validator.d.ts +0 -13
  156. package/.output/modules/inventory/categories/category.validator.js +0 -88
  157. package/.output/modules/inventory/products/entities/code.entity.d.ts +0 -5
  158. package/.output/modules/inventory/products/entities/dimension.entity.d.ts +0 -6
  159. package/.output/modules/inventory/products/entities/seo.entity.d.ts +0 -5
  160. package/.output/modules/inventory/products/entities/variant.entity.d.ts +0 -10
  161. package/.output/modules/inventory/products/product.entity.d.ts +0 -26
  162. package/.output/modules/inventory/products/product.exception.d.ts +0 -5
  163. package/.output/modules/inventory/products/product.exception.js +0 -40
  164. package/.output/modules/inventory/products/product.fixture.d.ts +0 -5
  165. package/.output/modules/inventory/products/product.fixture.js +0 -39
  166. package/.output/modules/inventory/products/product.validator.d.ts +0 -38
  167. package/.output/modules/inventory/products/product.validator.js +0 -235
  168. package/.output/modules/inventory/products/schemas/variant.schema.d.ts +0 -27
  169. package/.output/modules/inventory/products/schemas/variant.schema.js +0 -6
  170. package/.output/modules/inventory/products/validators/code.validator.d.ts +0 -5
  171. package/.output/modules/inventory/products/validators/code.validator.js +0 -37
  172. package/.output/modules/inventory/products/validators/dimension.validator.d.ts +0 -6
  173. package/.output/modules/inventory/products/validators/dimension.validator.js +0 -43
  174. package/.output/modules/inventory/products/validators/seo.validator.d.ts +0 -5
  175. package/.output/modules/inventory/products/validators/seo.validator.js +0 -34
  176. package/.output/modules/inventory/products/validators/variant.validator.d.ts +0 -9
  177. package/.output/modules/inventory/products/validators/variant.validator.js +0 -39
  178. package/.output/modules/inventory/properties/property.entity.d.ts +0 -8
  179. package/.output/modules/inventory/properties/property.exception.d.ts +0 -5
  180. package/.output/modules/inventory/properties/property.exception.js +0 -40
  181. package/.output/modules/inventory/properties/property.types.d.ts +0 -6
  182. package/.output/modules/inventory/properties/property.types.js +0 -10
  183. package/.output/modules/inventory/properties/property.validator.d.ts +0 -12
  184. package/.output/modules/inventory/properties/property.validator.js +0 -79
  185. package/.output/modules/layout/pages/page.entity.d.ts +0 -8
  186. package/.output/modules/layout/pages/page.fixture.d.ts +0 -5
  187. package/.output/modules/layout/pages/page.fixture.js +0 -36
  188. package/.output/modules/layout/pages/page.types.d.ts +0 -20
  189. package/.output/modules/layout/pages/page.types.js +0 -2
  190. package/.output/modules/layout/pages/page.validator.d.ts +0 -8
  191. package/.output/modules/layout/pages/page.validator.js +0 -61
  192. package/.output/modules/sale/customers/customer.entity.d.ts +0 -12
  193. package/.output/modules/sale/customers/customer.exception.d.ts +0 -5
  194. package/.output/modules/sale/customers/customer.exception.js +0 -40
  195. package/.output/modules/sale/customers/customer.validator.d.ts +0 -18
  196. package/.output/modules/sale/customers/customer.validator.js +0 -107
  197. package/.output/modules/sale/orders/billing/billing.entity.d.ts +0 -10
  198. package/.output/modules/sale/orders/billing/billing.types.d.ts +0 -9
  199. package/.output/modules/sale/orders/billing/billing.types.js +0 -14
  200. package/.output/modules/sale/orders/billing/billing.validator.d.ts +0 -9
  201. package/.output/modules/sale/orders/billing/billing.validator.js +0 -42
  202. package/.output/modules/sale/orders/billing/entities/address.entity.d.ts +0 -10
  203. package/.output/modules/sale/orders/billing/entities/customer.entity.d.ts +0 -5
  204. package/.output/modules/sale/orders/billing/entities/status.entity.d.ts +0 -6
  205. package/.output/modules/sale/orders/billing/validators/address.validator.d.ts +0 -10
  206. package/.output/modules/sale/orders/billing/validators/address.validator.js +0 -56
  207. package/.output/modules/sale/orders/billing/validators/customer.validator.d.ts +0 -5
  208. package/.output/modules/sale/orders/billing/validators/customer.validator.js +0 -36
  209. package/.output/modules/sale/orders/customer/customer.entity.d.ts +0 -5
  210. package/.output/modules/sale/orders/customer/customer.validator.d.ts +0 -5
  211. package/.output/modules/sale/orders/customer/customer.validator.js +0 -36
  212. package/.output/modules/sale/orders/item/item.entity.d.ts +0 -9
  213. package/.output/modules/sale/orders/item/item.schema.d.ts +0 -27
  214. package/.output/modules/sale/orders/item/item.schema.js +0 -9
  215. package/.output/modules/sale/orders/item/item.validator.d.ts +0 -4
  216. package/.output/modules/sale/orders/item/item.validator.js +0 -29
  217. package/.output/modules/sale/orders/order.entity.d.ts +0 -21
  218. package/.output/modules/sale/orders/order.exception.d.ts +0 -13
  219. package/.output/modules/sale/orders/order.exception.js +0 -46
  220. package/.output/modules/sale/orders/order.validator.d.ts +0 -28
  221. package/.output/modules/sale/orders/order.validator.js +0 -140
  222. package/.output/modules/sale/orders/shipping/entities/address.entity.d.ts +0 -10
  223. package/.output/modules/sale/orders/shipping/entities/customer.entity.d.ts +0 -5
  224. package/.output/modules/sale/orders/shipping/entities/status.entity.d.ts +0 -6
  225. package/.output/modules/sale/orders/shipping/shipping.entity.d.ts +0 -11
  226. package/.output/modules/sale/orders/shipping/shipping.types.d.ts +0 -11
  227. package/.output/modules/sale/orders/shipping/shipping.types.js +0 -16
  228. package/.output/modules/sale/orders/shipping/shipping.validator.d.ts +0 -10
  229. package/.output/modules/sale/orders/shipping/shipping.validator.js +0 -48
  230. package/.output/modules/sale/orders/shipping/validators/address.validator.d.ts +0 -10
  231. package/.output/modules/sale/orders/shipping/validators/address.validator.js +0 -56
  232. package/.output/modules/sale/orders/shipping/validators/customer.validator.d.ts +0 -5
  233. package/.output/modules/sale/orders/shipping/validators/customer.validator.js +0 -36
  234. package/.output/modules/sale/orders/status/status.entity.d.ts +0 -6
  235. package/.output/modules/sale/orders/status/status.validator.d.ts +0 -8
  236. package/.output/modules/sale/orders/status/status.validator.js +0 -12
  237. package/.output/services/logger.service.d.ts +0 -11
  238. package/.output/services/logger.service.js +0 -50
  239. package/.output/types.d.ts +0 -18
  240. package/.output/types.js +0 -2
  241. package/LICENSE +0 -674
package/.bin/deploy.sh ADDED
@@ -0,0 +1,9 @@
1
+ #!/bin/bash
2
+ rm -frd ./.output
3
+
4
+ yarn clean
5
+
6
+ #yarn console deploy mongo
7
+ #yarn console deploy auth0
8
+
9
+ yarn build
@@ -0,0 +1,12 @@
1
+ #!/bin/bash
2
+ rm -frd ./.output
3
+
4
+ yarn build -p tsconfig.package.json
5
+
6
+ sed "s/extends Document //" .output/abstracts/abstract.entity.d.ts > .output/abstracts/abstract.entity.ts.d
7
+ mv .output/abstracts/abstract.entity.ts.d .output/abstracts/abstract.entity.d.ts
8
+
9
+ sed "s/import { Document } from \'mongoose\';//" .output/abstracts/abstract.entity.d.ts > .output/abstracts/abstract.entity.ts.d
10
+ mv .output/abstracts/abstract.entity.ts.d .output/abstracts/abstract.entity.d.ts
11
+
12
+ find .output -name '*.entity.js' -delete
@@ -0,0 +1,21 @@
1
+ FROM node:16
2
+
3
+ WORKDIR /usr/src
4
+
5
+ ENV HOST 0.0.0.0
6
+ ENV PORT 6500
7
+
8
+ ARG SENTRY_DSN
9
+ ENV SENTRY_DSN $SENTRY_DSN
10
+
11
+ COPY package.json ./
12
+
13
+ RUN yarn
14
+
15
+ COPY . .
16
+
17
+ RUN yarn build
18
+
19
+ EXPOSE ${PORT}
20
+
21
+ CMD yarn start:prod
package/.dockerignore ADDED
@@ -0,0 +1,12 @@
1
+ /.git
2
+ /.github
3
+ /.husky
4
+ /node_modules
5
+
6
+ # environment vars
7
+ .env
8
+
9
+ # nestjs compiled files
10
+ /**/*.js
11
+ /**/*.map
12
+ /**/*.d.ts
@@ -0,0 +1,17 @@
1
+ version: 2
2
+ updates:
3
+ # Fetch and update latest `npm` packages
4
+ - package-ecosystem: npm
5
+ directory: '/'
6
+ schedule:
7
+ interval: daily
8
+ time: '00:00'
9
+ open-pull-requests-limit: 3
10
+ reviewers:
11
+ - kronhyx
12
+ assignees:
13
+ - kronhyx
14
+ commit-message:
15
+ prefix: chore
16
+ prefix-development: chore
17
+ include: scope
@@ -0,0 +1,5 @@
1
+ # Always validate the PR title AND all the commits
2
+ titleAndCommits: true
3
+ # Allows use of Merge commits (eg on github: "Merge branch 'master' into feature/ride-unicorns")
4
+ # this is only relevant when using commitsOnly: true (or titleAndCommits: true)
5
+ allowMergeCommits: true
@@ -0,0 +1,35 @@
1
+ name: PullRequest & Push master
2
+
3
+ env:
4
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
5
+
6
+ on:
7
+ push:
8
+ branches: [master]
9
+ pull_request:
10
+ branches: [master]
11
+
12
+ jobs:
13
+ build:
14
+ runs-on: ubuntu-latest
15
+
16
+ steps:
17
+ - name: Checkout 🛎
18
+ uses: actions/checkout@master
19
+
20
+ - name: Setup node env 🏗
21
+ uses: actions/setup-node@v2
22
+ with:
23
+ node-version: 18
24
+
25
+ - name: Install dependencies 🛠️
26
+ run: yarn
27
+
28
+ - name: Lint code 👀️
29
+ run: yarn lint
30
+
31
+ # - name: Run tests 🧪
32
+ # run: yarn test
33
+
34
+ - name: Build code 🛠️
35
+ run: yarn build
package/.prettierrc ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "printWidth": 120,
3
+ "singleQuote": true,
4
+ "trailingComma": "all"
5
+ }
package/app.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { INestApplication, ValidationPipe } from '@nestjs/common';
2
+ import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
3
+
4
+ export function createNestApp(app: INestApplication) {
5
+ const config = new DocumentBuilder().build();
6
+
7
+ const document = SwaggerModule.createDocument(app, config);
8
+ SwaggerModule.setup('/', app, document);
9
+
10
+ return app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));
11
+ }
@@ -0,0 +1,19 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDAzCCAeugAwIBAgIJHHJE5ykX1iXdMA0GCSqGSIb3DQEBCwUAMB8xHTAbBgNV
3
+ BAMTFG1lcmthbHkudXMuYXV0aDAuY29tMB4XDTIwMTEwNTIwMzY1MVoXDTM0MDcx
4
+ NTIwMzY1MVowHzEdMBsGA1UEAxMUbWVya2FseS51cy5hdXRoMC5jb20wggEiMA0G
5
+ CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCcZcJZ3OxWI+Gxp9a5GGY9035+FulG
6
+ 8+EWuIvRMCL1cUT5RMfib5/I66T3wipHw8t/yKO/Rjdx8uRUTZE94OuCbSI/qK7R
7
+ bQHdpvUw9B9W3lwwyJ+AjklDOYS91apJcn4g/poMQ5G9vdQsP6u1P176Bjkx0pxH
8
+ qx3XBbPf61IIb7Jv1yiyc6sQDHyR3ZUQPrDgjNgu30pTOxjQIOnnzSoCn/n0QjWA
9
+ O9JcMyO2kI6+dNJnWBfs7BhCz4fPJA6IfU57vaq50sSH99/DEbc7SDJh+Ty1z4iW
10
+ dX/4h+6GNtIUqBh35+fz606tN1x+RSET+/oDAHI78+KB8AkC4rTmdIBRAgMBAAGj
11
+ QjBAMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFJ8n4kEQjFyA504p+iJj2zr7
12
+ vpiPMA4GA1UdDwEB/wQEAwIChDANBgkqhkiG9w0BAQsFAAOCAQEAGHMjDFX1myDL
13
+ eHqlwxQTYJk1+sc68rfUxB70a/MU5OMZ8z53YTDbkeOhlsmrIuDMhIt3ZVHizWka
14
+ nITpKzU7cuRLJEyozps2bZyX/8QaoKwTkqV5IUV4W9FoL8K8A/zTOKp2H/T8WiSu
15
+ 5b29cltqXYrsWj2La3Fm0uaqupfweZgwLN/z/wRg+k7ZzAaHdAehZ9DW2mUkgqHg
16
+ 5z6f4SOvTvyTAcphG4tqeFk4YjV4OQcBSuDsnLxs1mQpQ12eA2gmoRQ3W70zRtdI
17
+ 1UzqunyLrz5Pt59fitaSeXfthfFNKW67zSfGfJhoqngIuxG/+UaAaDRx/LBJjO0O
18
+ 4/ztS0AZ/A==
19
+ -----END CERTIFICATE-----
package/nest-cli.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/nest-cli",
3
+ "collection": "@nestjs/schematics",
4
+ "sourceRoot": "src",
5
+ "compilerOptions": {
6
+ "deleteOutDir": true
7
+ }
8
+ }
package/package.json CHANGED
@@ -1,105 +1,93 @@
1
1
  {
2
2
  "name": "@merkaly/api",
3
- "version": "0.2.5-4",
4
- "description": "NestJS Backend ApiRest Service",
3
+ "version": "0.2.5-6",
5
4
  "repository": {
6
5
  "type": "git",
7
6
  "url": "https://github.com/merkaly-io/api.git"
8
7
  },
9
8
  "license": "UNLICENSED",
10
- "author": "Randy Tellez Galan <kronhyx@gmail.com>",
11
- "main": "./.output/main",
12
- "types": "./.output/types.d.ts",
13
- "files": [
14
- ".output"
15
- ],
16
9
  "scripts": {
17
- "prebuild": "yarn run clean",
18
10
  "build": "nest build",
19
11
  "clean": "tsc -b --clean",
20
12
  "console": "yarn clean && ts-node -r tsconfig-paths/register ./src/app.console.ts",
21
- "dev": "yarn start --watch",
22
- "lint": "eslint \"{src,test}/**/*.ts\" . ",
23
- "migrate": "tsc --target es5 --experimentalDecorators ./src/migrations/*.ts && migrate --config ./src/app.migration.ts",
24
- "prepack": ".bin/package.sh",
13
+ "dev": "nest start --watch",
14
+ "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
15
+ "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
25
16
  "postpack": "yarn run clean",
26
- "semantic-release": "yarn run build:package && semantic-release",
27
- "start": "nest start",
28
- "start:prod": "node ./src/main.js",
17
+ "prebuild": "yarn run clean",
18
+ "prepack": ".bin/package.sh",
19
+ "start": "node dist/src/main",
29
20
  "test": "jest",
30
- "test:cov": "yarn test -- --coverage",
21
+ "test:cov": "jest --coverage",
31
22
  "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
32
- "test:watch": "yarn test -- --watch"
33
- },
34
- "lint-staged": {
35
- "*.**": "yarn lint --cache --fix"
23
+ "test:e2e": "jest --config ./test/jest-e2e.json",
24
+ "test:watch": "jest --watch"
36
25
  },
37
26
  "dependencies": {
38
- "@nestjs/common": "^9.0.11",
39
- "@nestjs/swagger": "^6.1.0",
40
- "@types/auth0": "^3.3.1",
27
+ "auth0": "^4.2.0",
41
28
  "class-transformer": "^0.5.1",
42
29
  "class-validator": "^0.14.0",
43
- "mongoose": "^6",
44
- "reflect-metadata": "^0.1.13"
30
+ "mongoose": "^7.5.3",
31
+ "reflect-metadata": "^0.1.14"
45
32
  },
46
33
  "devDependencies": {
47
- "@commitlint/config-conventional": "^17.0.0",
48
- "@faker-js/faker": "^8.0.0",
49
- "@google-cloud/storage": "^6.4.1",
50
- "@nestjs/axios": "^2.0.0",
51
- "@nestjs/cli": "^9.1.1",
52
- "@nestjs/config": "^2.2.0",
53
- "@nestjs/core": "^9.0.11",
54
- "@nestjs/event-emitter": "^1.3.1",
55
- "@nestjs/jwt": "^10.0.2",
56
- "@nestjs/mongoose": "^9.2.0",
57
- "@nestjs/passport": "^9.0.0",
58
- "@nestjs/platform-express": "^9.0.11",
59
- "@nestjs/platform-socket.io": "^9.4.0",
60
- "@nestjs/schematics": "^9.0.1",
61
- "@nestjs/testing": "^9.0.11",
62
- "@nestjs/websockets": "^9.4.0",
63
- "@types/cache-manager": "^4.0.1",
64
- "@types/express": "^4.17.12",
65
- "@types/jest": "^27.0.0",
66
- "@types/multer": "^1.4.7",
67
- "@types/node": "^20.1.0",
68
- "@types/passport-jwt": "^3.0.5",
69
- "@types/supertest": "^2.0.11",
70
- "@types/uuid": "^9.0.1",
71
- "@typescript-eslint/eslint-plugin": "4.33.0",
72
- "@typescript-eslint/parser": "4.33.0",
73
- "auth0": "^3.2.0",
74
- "axios": "^1.3.4",
75
- "cache-manager": "^5.0.0",
76
- "commitlint": "^17.0.1",
77
- "eslint": "7.32.0",
78
- "eslint-plugin-import": "^2.23.4",
79
- "express": "^4.17.3",
80
- "husky": "^8.0.1",
81
- "jest": "27.5.1",
82
- "lint-staged": "^13.0.3",
83
- "migrate-mongoose": "^4.0.0",
84
- "nestjs-console": "^8.0.0",
34
+ "@faker-js/faker": "^8.3.1",
35
+ "@nestjs/cli": "^10.2.1",
36
+ "@nestjs/common": "^9.0.0",
37
+ "@nestjs/config": "^3.1.1",
38
+ "@nestjs/core": "^9.0.0",
39
+ "@nestjs/jwt": "^10.2.0",
40
+ "@nestjs/mongoose": "^10.0.1",
41
+ "@nestjs/passport": "^10.0.3",
42
+ "@nestjs/platform-express": "^9.0.0",
43
+ "@nestjs/schematics": "^10.0.3",
44
+ "@nestjs/swagger": "^7.1.16",
45
+ "@nestjs/testing": "^9.0.0",
46
+ "@types/express": "^4.17.21",
47
+ "@types/jest": "29.5.11",
48
+ "@types/multer": "^1.4.11",
49
+ "@types/node": "20.10.3",
50
+ "@types/passport-jwt": "^3.0.13",
51
+ "@types/supertest": "^2.0.16",
52
+ "@typescript-eslint/eslint-plugin": "^5.0.0",
53
+ "@typescript-eslint/parser": "^5.0.0",
54
+ "class-transformer": "^0.5.1",
55
+ "class-validator": "^0.14.0",
56
+ "dotenv": "^16.3.1",
57
+ "eslint": "^8.56.0",
58
+ "eslint-config-prettier": "^8.3.0",
59
+ "eslint-plugin-prettier": "^4.0.0",
60
+ "jest": "29.7.0",
61
+ "mongoose": "^7.5.3",
62
+ "nestjs-console": "^9.0.0",
85
63
  "passport": "^0.6.0",
86
- "passport-jwt": "^4.0.0",
87
- "rimraf": "^5.0.0",
64
+ "passport-jwt": "^4.0.1",
65
+ "prettier": "^2.3.2",
66
+ "reflect-metadata": "^0.1.14",
88
67
  "rxjs": "^7.2.0",
89
- "short-unique-id": "^4.4.4",
68
+ "source-map-support": "^0.5.20",
90
69
  "supertest": "^6.1.3",
91
- "swagger-ui-express": "^4.3.0",
92
- "ts-jest": "27.1.3",
93
- "ts-loader": "^9.2.3",
70
+ "ts-jest": "29.1.1",
71
+ "ts-loader": "^9.5.1",
94
72
  "ts-node": "^10.0.0",
95
- "tsconfig-paths": "^4.0.0",
96
- "typescript": "4.4.4",
97
- "webpack": "^5"
98
- },
99
- "publishConfig": {
100
- "access": "public"
73
+ "tsconfig-paths": "4.2.0",
74
+ "typescript": "<5.2.0"
101
75
  },
102
- "engines": {
103
- "node": ">=16"
76
+ "jest": {
77
+ "moduleFileExtensions": [
78
+ "js",
79
+ "json",
80
+ "ts"
81
+ ],
82
+ "rootDir": "src",
83
+ "testRegex": ".*\\.spec\\.ts$",
84
+ "transform": {
85
+ "^.+\\.(t|j)s$": "ts-jest"
86
+ },
87
+ "collectCoverageFrom": [
88
+ "**/*.(t|j)s"
89
+ ],
90
+ "coverageDirectory": "../coverage",
91
+ "testEnvironment": "node"
104
92
  }
105
93
  }
@@ -0,0 +1,62 @@
1
+ import { GoneException, Logger, NotFoundException } from '@nestjs/common';
2
+ import { FilterQuery, HydratedDocument, Model, PopulateOptions } from 'mongoose';
3
+ import { AbstractEntity } from './abstract.entity';
4
+ import { FindResult, FindValidator, ReadValidator } from './abstract.validator';
5
+
6
+ export abstract class AbstractRepository<E extends AbstractEntity = AbstractEntity> {
7
+ protected abstract $model: Model<AbstractEntity>;
8
+
9
+ public find(validator: FindValidator<E> = {}, ...params: unknown[]): Promise<FindResult<E>> {
10
+ const filters: FilterQuery<E> = { deletedAt: null, ...validator.filters };
11
+
12
+ const query = this.$model.find<E>(filters);
13
+ const counter = this.$model.count(filters);
14
+
15
+ const skip = validator.page * validator.limit - validator.limit;
16
+
17
+ !validator.sort?.createdAt && (validator.sort = { ...validator.sort, createdAt: 'desc' });
18
+
19
+ validator.page && query.skip(skip);
20
+ validator.sort && query.sort(validator.sort);
21
+
22
+ validator.join && query.populate(validator.join as (PopulateOptions | string)[]);
23
+
24
+ validator.limit && query.limit(validator.limit);
25
+
26
+ return Promise.all([counter.count(), query.exec()]).then(([total, items]) => ({
27
+ items,
28
+ page: validator.page,
29
+ total,
30
+ }));
31
+ }
32
+
33
+ public async read(id: string, validator?: ReadValidator) {
34
+ const entity = await this.$model.findById<HydratedDocument<E>>(id);
35
+
36
+ if (!entity) {
37
+ throw new NotFoundException();
38
+ }
39
+
40
+ if (entity.deletedAt) {
41
+ throw new GoneException();
42
+ }
43
+
44
+ if (validator?.join) {
45
+ await entity
46
+ .populate(validator.join as [])
47
+ .catch(() => Logger.warn(`Issue populating fields with id: ${entity._id}`));
48
+ }
49
+
50
+ return entity;
51
+ }
52
+
53
+ public abstract create(validator: unknown, ...params: unknown[]): any;
54
+
55
+ public abstract update(id: string, validator: unknown): any;
56
+
57
+ public async delete(id: string) {
58
+ await this.read(id);
59
+
60
+ return this.$model.deleteOne({ _id: id });
61
+ }
62
+ }
@@ -0,0 +1,18 @@
1
+ import { AbstractRepository } from './abstarct.repository';
2
+ import { IdMongoValidator, ReadValidator } from './abstract.validator';
3
+
4
+ export abstract class AbstractController {
5
+ protected abstract readonly $repository: AbstractRepository;
6
+
7
+ protected find?(...params: unknown[]) {
8
+ return this.$repository.find();
9
+ }
10
+
11
+ protected read?({ id }: IdMongoValidator, validator?: ReadValidator) {
12
+ return this.$repository.read(id, validator);
13
+ }
14
+
15
+ protected delete?({ id }: IdMongoValidator) {
16
+ return this.$repository.delete(id);
17
+ }
18
+ }
@@ -0,0 +1,22 @@
1
+ import { Prop } from '@nestjs/mongoose';
2
+ import { Schema as MongoSchema } from 'mongoose';
3
+
4
+ export const $collection = {
5
+ timestamps: true,
6
+ toJSON: { versionKey: false, virtuals: true },
7
+ };
8
+
9
+ export type MaybeEntity<T extends AbstractEntity> = T;
10
+
11
+ export abstract class AbstractEntity {
12
+ public readonly _id = String();
13
+
14
+ @Prop({ type: MongoSchema.Types.Date })
15
+ public readonly createdAt: Date;
16
+
17
+ @Prop({ type: MongoSchema.Types.Date })
18
+ public readonly updatedAt?: Date = null;
19
+
20
+ @Prop({ default: null, type: MongoSchema.Types.Date })
21
+ public readonly deletedAt?: Date = null;
22
+ }
@@ -0,0 +1,7 @@
1
+ export abstract class AbstractRouter {
2
+ public static readonly path: string;
3
+
4
+ public static readonly module: typeof AbstractRouter;
5
+
6
+ public static readonly children? = [];
7
+ }
@@ -0,0 +1,61 @@
1
+ import { Transform } from 'class-transformer';
2
+ import { IsInt, IsMongoId, isObject, IsOptional } from 'class-validator';
3
+ import { FilterQuery, PopulateOptions, SortOrder } from 'mongoose';
4
+ import { AbstractEntity } from './abstract.entity';
5
+
6
+ export abstract class AbstractValidator {}
7
+
8
+ export type FindResult<I> = { items: I[]; page: number; total: number };
9
+
10
+ export type KeyOfType<T, V> = keyof {
11
+ [P in keyof T as T[P] extends V ? P : string]: any;
12
+ };
13
+
14
+ export class IdMongoValidator {
15
+ @IsMongoId()
16
+ public id: string;
17
+ }
18
+
19
+ export class ReadValidator<E = AbstractEntity> extends AbstractValidator {
20
+ @Transform(({ value }) => {
21
+ try {
22
+ return JSON.parse(value);
23
+ } catch (e: unknown) {
24
+ return value;
25
+ }
26
+ })
27
+ @IsOptional()
28
+ public join?: (PopulateOptions | KeyOfType<E, AbstractEntity | AbstractEntity[]>)[] = [];
29
+ }
30
+
31
+ export class FindValidator<E = AbstractEntity> extends ReadValidator<E> {
32
+ @Transform(({ value }) => (value ? Number(value) : 10))
33
+ @IsInt()
34
+ @IsOptional()
35
+ public limit? = 10;
36
+
37
+ @Transform(({ value }) => (value ? Number(value) : 1))
38
+ @IsInt()
39
+ @IsOptional()
40
+ public page? = 1;
41
+
42
+ @Transform(({ value }) => {
43
+ if (isObject(value)) {
44
+ return value;
45
+ }
46
+
47
+ return value && JSON.parse(value);
48
+ })
49
+ @IsOptional()
50
+ public sort?: Partial<Record<keyof E, SortOrder>> = {};
51
+
52
+ @Transform(({ value }) => {
53
+ if (isObject(value)) {
54
+ return value;
55
+ }
56
+
57
+ return value && JSON.parse(value);
58
+ })
59
+ @IsOptional()
60
+ public filters?: FilterQuery<E> = {};
61
+ }
@@ -0,0 +1,59 @@
1
+ import { config } from 'dotenv';
2
+ import { readFileSync } from 'fs';
3
+ import { join } from 'path';
4
+ import * as process from 'process';
5
+
6
+ config();
7
+
8
+ export abstract class AppConfig {
9
+ public static get SENTRY() {
10
+ return {
11
+ dsn: process.env.SENTRY_DSN,
12
+ debug: process.env.NODE_ENV !== 'production',
13
+ environment: process.env.NODE_ENV,
14
+ };
15
+ }
16
+
17
+ public static get SERVER() {
18
+ return {
19
+ description: String(process.env.npm_package_description),
20
+ isDEV: process.env.NODE_ENV !== 'production',
21
+ name: String(process.env.npm_package_name),
22
+ port: Number(process.env.PORT || 6500),
23
+ version: String(process.env.npm_package_version),
24
+ };
25
+ }
26
+
27
+ public static get MONGO() {
28
+ const { MONGO_PASSWORD, MONGO_USER, MONGO_HOST } = process.env;
29
+
30
+ return {
31
+ host: MONGO_HOST,
32
+ user: MONGO_USER,
33
+ pass: MONGO_PASSWORD,
34
+ retryWrites: true,
35
+ w: 'majority',
36
+ };
37
+ }
38
+
39
+ public static get STORAGE() {
40
+ const serviceAccount = readFileSync(join(process.cwd(), '/serviceAccount.json'));
41
+ const credentials = JSON.parse(serviceAccount.toString());
42
+
43
+ return {
44
+ projectId: 'api-merkaly-io',
45
+ bucketName: process.env.GCP_BUCKET_NAME,
46
+ serviceAccount: credentials,
47
+ };
48
+ }
49
+
50
+ public static get AUTH0() {
51
+ const domain = 'merkaly.us.auth0.com';
52
+ const audience = `https://${domain}/api/v2/`;
53
+ const client = 'eApUjfHoWlMPcTUuU1lqvE517q0KzTh9';
54
+ const secret = String(process.env.AUTH0_CLIENT_SECRET);
55
+ const certificate = process.env.AUTH_CERTIFICATE || readFileSync(join(process.cwd(), '/authCertificate.pem'));
56
+
57
+ return { domain, audience, client, secret, certificate };
58
+ }
59
+ }
@@ -0,0 +1,24 @@
1
+ import { BootstrapConsole } from 'nestjs-console';
2
+ import process from 'process';
3
+ import { AppModule } from './app.module';
4
+
5
+ const bootstrap = new BootstrapConsole({
6
+ module: AppModule,
7
+ useDecorators: true,
8
+ });
9
+
10
+ bootstrap.init().then(async (app) => {
11
+ try {
12
+ await app.init();
13
+
14
+ await bootstrap.boot();
15
+
16
+ await app.close();
17
+ } catch (e) {
18
+ console.error(e);
19
+
20
+ await app.close();
21
+
22
+ process.exit(1);
23
+ }
24
+ });
@@ -0,0 +1,39 @@
1
+ import { ExecutionContext, Inject, Injectable, UnauthorizedException } from '@nestjs/common';
2
+ import { Reflector } from '@nestjs/core';
3
+ import { AuthGuard as JwtGuard } from '@nestjs/passport';
4
+ import { IS_PUBLIC_KEY } from './decorators/public.decorator';
5
+ import { DecodedUser } from './decorators/user.decorator';
6
+
7
+ declare module 'express' {
8
+ interface Request {
9
+ user?: DecodedUser;
10
+ }
11
+ }
12
+
13
+ @Injectable()
14
+ export class AuthGuard extends JwtGuard('jwt') {
15
+ public isPublic = false;
16
+ @Inject()
17
+ private reflector: Reflector;
18
+
19
+ public async canActivate(context: ExecutionContext): Promise<any> {
20
+ this.isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
21
+ context.getHandler(),
22
+ context.getClass(),
23
+ ]);
24
+
25
+ return super.canActivate(context);
26
+ }
27
+
28
+ public handleRequest(err: Record<string, unknown>, user: DecodedUser): any {
29
+ if (err) {
30
+ throw err;
31
+ }
32
+
33
+ if (!user && !this.isPublic) {
34
+ throw new UnauthorizedException();
35
+ }
36
+
37
+ return user || undefined;
38
+ }
39
+ }