@merkaly/api 0.2.4-7 → 0.2.4-8

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 (252) hide show
  1. package/.output/abstract/abstract.entity.d.ts +1 -1
  2. package/package.json +2 -3
  3. package/.DS_Store +0 -0
  4. package/.bin/deploy.sh +0 -9
  5. package/.bin/package.sh +0 -7
  6. package/.docker/Dockerfile +0 -21
  7. package/.dockerignore +0 -12
  8. package/.env +0 -21
  9. package/.eslintignore +0 -8
  10. package/.eslintrc.js +0 -35
  11. package/.github/dependabot.yml +0 -17
  12. package/.github/semantic.yml +0 -5
  13. package/.github/workflows/pull_request.yml +0 -35
  14. package/.gitignore +0 -42
  15. package/.husky/.gitignore +0 -1
  16. package/.husky/commit-msg +0 -5
  17. package/.husky/common.sh +0 -8
  18. package/.husky/pre-commit +0 -5
  19. package/.husky/pre-push +0 -4
  20. package/.idea/.gitignore +0 -5
  21. package/.idea/api.iml +0 -13
  22. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  23. package/.idea/inspectionProfiles/Project_Default.xml +0 -11
  24. package/.idea/modules.xml +0 -8
  25. package/.idea/vcs.xml +0 -12
  26. package/.idea/workspace.xml +0 -2320
  27. package/.output/abstract/abstract.entity.js +0 -53
  28. package/.output/modules/assets/asset.entity.js +0 -69
  29. package/.output/modules/content/banners/banner.entity.js +0 -54
  30. package/.output/modules/content/pages/page.entity.js +0 -69
  31. package/.output/modules/inventory/brands/brand.entity.js +0 -50
  32. package/.output/modules/inventory/categories/category.entity.js +0 -61
  33. package/.output/modules/inventory/products/entities/code.entity.js +0 -53
  34. package/.output/modules/inventory/products/entities/dimension.entity.js +0 -57
  35. package/.output/modules/inventory/products/entities/price.entity.js +0 -49
  36. package/.output/modules/inventory/products/entities/seo.entity.js +0 -53
  37. package/.output/modules/inventory/products/product.entity.js +0 -101
  38. package/.output/modules/inventory/properties/property.entity.js +0 -55
  39. package/.output/modules/sales/clients/client.entity.js +0 -64
  40. package/.output/modules/sales/orders/billing/billing.entity.js +0 -64
  41. package/.output/modules/sales/orders/billing/entities/address.entity.js +0 -68
  42. package/.output/modules/sales/orders/billing/entities/customer.entity.js +0 -52
  43. package/.output/modules/sales/orders/billing/entities/status.entity.js +0 -37
  44. package/.output/modules/sales/orders/customer/customer.entity.js +0 -52
  45. package/.output/modules/sales/orders/item/item.entity.js +0 -58
  46. package/.output/modules/sales/orders/order.entity.js +0 -89
  47. package/.output/modules/sales/orders/shipping/entities/address.entity.js +0 -68
  48. package/.output/modules/sales/orders/shipping/entities/customer.entity.js +0 -52
  49. package/.output/modules/sales/orders/shipping/entities/status.entity.js +0 -37
  50. package/.output/modules/sales/orders/shipping/shipping.entity.js +0 -68
  51. package/.output/modules/sales/orders/status/status.entity.js +0 -37
  52. package/.output/modules/setting/layout/layout.entity.js +0 -46
  53. package/.output/modules/setting/organization/organization.entity.js +0 -28
  54. package/.output/modules/setting/theme/theme.entity.js +0 -46
  55. package/authCertificate.pem +0 -19
  56. package/cloudbuild.yaml +0 -20
  57. package/commitlint.config.js +0 -3
  58. package/jest.config.js +0 -14
  59. package/merkaly-api-0.2.4-6.tgz +0 -0
  60. package/nest-cli.json +0 -9
  61. package/serviceAccount.json +0 -7
  62. package/src/abstract/absctract.listener.ts +0 -2
  63. package/src/abstract/abstract.controller.ts +0 -27
  64. package/src/abstract/abstract.entity.ts +0 -19
  65. package/src/abstract/abstract.exception.ts +0 -56
  66. package/src/abstract/abstract.fixture.ts +0 -7
  67. package/src/abstract/abstract.migration.ts +0 -13
  68. package/src/abstract/abstract.repository.ts +0 -79
  69. package/src/abstract/abstract.router.ts +0 -7
  70. package/src/abstract/abstract.validator.ts +0 -62
  71. package/src/app.config.ts +0 -57
  72. package/src/app.console.ts +0 -30
  73. package/src/app.controller.ts +0 -48
  74. package/src/app.migration.ts +0 -7
  75. package/src/app.module.ts +0 -92
  76. package/src/app.strategy.ts +0 -25
  77. package/src/commands/assets.command.ts +0 -38
  78. package/src/commands/deploy.command.ts +0 -6
  79. package/src/commands/fixture.command.ts +0 -11
  80. package/src/commands/generate.command.ts +0 -286
  81. package/src/decorators/public.decorator.ts +0 -5
  82. package/src/decorators/user.decorator.ts +0 -21
  83. package/src/exceptions/missing-identity.exception.ts +0 -11
  84. package/src/exceptions/store-not-implemented.exception.ts +0 -13
  85. package/src/exceptions/store-not-recognized.exception.ts +0 -11
  86. package/src/guards/auth.guard.ts +0 -43
  87. package/src/guards/organization.guard.ts +0 -39
  88. package/src/interceptors/mongo.interceptor.ts +0 -16
  89. package/src/main.ts +0 -37
  90. package/src/middlewares/logger.middleware.ts +0 -15
  91. package/src/middlewares/organization.middleware.ts +0 -76
  92. package/src/migrations/1667226478717-product_price_enhance.ts +0 -29
  93. package/src/migrations/1667329249561-product_add_seo_code_dimension.ts +0 -37
  94. package/src/migrations/1667601099139-product_activve_and_hashtag.ts +0 -35
  95. package/src/migrations/1668136428972-content_banners-use-as-image.ts +0 -56
  96. package/src/migrations/1680483744321-order-billing-shipping-status.ts +0 -32
  97. package/src/modules/assets/asset.controller.ts +0 -33
  98. package/src/modules/assets/asset.entity.ts +0 -26
  99. package/src/modules/assets/asset.module.ts +0 -21
  100. package/src/modules/assets/asset.repository.ts +0 -51
  101. package/src/modules/assets/asset.schema.ts +0 -4
  102. package/src/modules/assets/asset.service.ts +0 -41
  103. package/src/modules/auth/auth.controller.ts +0 -42
  104. package/src/modules/auth/auth.module.ts +0 -18
  105. package/src/modules/auth/logout.ts +0 -0
  106. package/src/modules/command.module.ts +0 -19
  107. package/src/modules/content/banners/banner.controller.ts +0 -56
  108. package/src/modules/content/banners/banner.entity.ts +0 -17
  109. package/src/modules/content/banners/banner.fixture.ts +0 -19
  110. package/src/modules/content/banners/banner.listener.ts +0 -6
  111. package/src/modules/content/banners/banner.module.ts +0 -21
  112. package/src/modules/content/banners/banner.repository.ts +0 -38
  113. package/src/modules/content/banners/banner.schema.ts +0 -4
  114. package/src/modules/content/banners/banner.types.ts +0 -7
  115. package/src/modules/content/banners/banner.validator.ts +0 -19
  116. package/src/modules/content/content.module.ts +0 -20
  117. package/src/modules/content/pages/page.controller.ts +0 -53
  118. package/src/modules/content/pages/page.entity.ts +0 -27
  119. package/src/modules/content/pages/page.fixture.ts +0 -19
  120. package/src/modules/content/pages/page.listener.ts +0 -6
  121. package/src/modules/content/pages/page.module.ts +0 -21
  122. package/src/modules/content/pages/page.repository.ts +0 -44
  123. package/src/modules/content/pages/page.schema.ts +0 -4
  124. package/src/modules/content/pages/page.types.ts +0 -9
  125. package/src/modules/content/pages/page.validator.ts +0 -29
  126. package/src/modules/global.module.ts +0 -70
  127. package/src/modules/insight/controllers/address.controller.ts +0 -29
  128. package/src/modules/insight/controllers/order.controller.ts +0 -70
  129. package/src/modules/insight/controllers/products.controller.ts +0 -18
  130. package/src/modules/insight/insight.module.ts +0 -24
  131. package/src/modules/insight/validators/order.validator.ts +0 -10
  132. package/src/modules/inventory/brands/brand.controller.ts +0 -59
  133. package/src/modules/inventory/brands/brand.entity.ts +0 -14
  134. package/src/modules/inventory/brands/brand.exception.ts +0 -9
  135. package/src/modules/inventory/brands/brand.listener.ts +0 -18
  136. package/src/modules/inventory/brands/brand.module.ts +0 -19
  137. package/src/modules/inventory/brands/brand.repository.ts +0 -39
  138. package/src/modules/inventory/brands/brand.schema.ts +0 -4
  139. package/src/modules/inventory/brands/brand.validator.ts +0 -23
  140. package/src/modules/inventory/categories/category.controller.ts +0 -59
  141. package/src/modules/inventory/categories/category.entity.ts +0 -21
  142. package/src/modules/inventory/categories/category.exception.ts +0 -9
  143. package/src/modules/inventory/categories/category.fixture.ts +0 -18
  144. package/src/modules/inventory/categories/category.listener.ts +0 -17
  145. package/src/modules/inventory/categories/category.module.ts +0 -19
  146. package/src/modules/inventory/categories/category.repository.ts +0 -40
  147. package/src/modules/inventory/categories/category.schema.ts +0 -4
  148. package/src/modules/inventory/categories/category.validator.ts +0 -30
  149. package/src/modules/inventory/inventory.module.ts +0 -22
  150. package/src/modules/inventory/products/entities/code.entity.ts +0 -15
  151. package/src/modules/inventory/products/entities/dimension.entity.ts +0 -18
  152. package/src/modules/inventory/products/entities/price.entity.ts +0 -12
  153. package/src/modules/inventory/products/entities/seo.entity.ts +0 -15
  154. package/src/modules/inventory/products/product.controller.ts +0 -59
  155. package/src/modules/inventory/products/product.entity.ts +0 -53
  156. package/src/modules/inventory/products/product.exception.ts +0 -9
  157. package/src/modules/inventory/products/product.fixture.ts +0 -19
  158. package/src/modules/inventory/products/product.listener.ts +0 -27
  159. package/src/modules/inventory/products/product.module.ts +0 -20
  160. package/src/modules/inventory/products/product.repository.ts +0 -108
  161. package/src/modules/inventory/products/product.schema.ts +0 -15
  162. package/src/modules/inventory/products/product.validator.ts +0 -71
  163. package/src/modules/inventory/products/validators/code.validator.ts +0 -15
  164. package/src/modules/inventory/products/validators/dimension.validator.ts +0 -19
  165. package/src/modules/inventory/products/validators/price.validator.ts +0 -10
  166. package/src/modules/inventory/products/validators/seo.validator.ts +0 -15
  167. package/src/modules/inventory/properties/property.controller.ts +0 -56
  168. package/src/modules/inventory/properties/property.entity.ts +0 -18
  169. package/src/modules/inventory/properties/property.exception.ts +0 -9
  170. package/src/modules/inventory/properties/property.listener.ts +0 -20
  171. package/src/modules/inventory/properties/property.module.ts +0 -21
  172. package/src/modules/inventory/properties/property.repository.ts +0 -23
  173. package/src/modules/inventory/properties/property.schema.ts +0 -4
  174. package/src/modules/inventory/properties/property.validator.ts +0 -27
  175. package/src/modules/sales/clients/client.controller.ts +0 -60
  176. package/src/modules/sales/clients/client.entity.ts +0 -25
  177. package/src/modules/sales/clients/client.exception.ts +0 -9
  178. package/src/modules/sales/clients/client.listener.ts +0 -20
  179. package/src/modules/sales/clients/client.module.ts +0 -19
  180. package/src/modules/sales/clients/client.repository.ts +0 -37
  181. package/src/modules/sales/clients/client.schema.ts +0 -4
  182. package/src/modules/sales/clients/client.validator.ts +0 -43
  183. package/src/modules/sales/orders/billing/billing.entity.ts +0 -22
  184. package/src/modules/sales/orders/billing/billing.types.ts +0 -10
  185. package/src/modules/sales/orders/billing/billing.validator.ts +0 -21
  186. package/src/modules/sales/orders/billing/entities/address.entity.ts +0 -27
  187. package/src/modules/sales/orders/billing/entities/customer.entity.ts +0 -14
  188. package/src/modules/sales/orders/billing/entities/status.entity.ts +0 -16
  189. package/src/modules/sales/orders/billing/validators/address.validator.ts +0 -28
  190. package/src/modules/sales/orders/billing/validators/customer.validator.ts +0 -14
  191. package/src/modules/sales/orders/customer/customer.entity.ts +0 -14
  192. package/src/modules/sales/orders/customer/customer.validator.ts +0 -14
  193. package/src/modules/sales/orders/item/item.entity.ts +0 -21
  194. package/src/modules/sales/orders/item/item.schema.ts +0 -8
  195. package/src/modules/sales/orders/item/item.validator.ts +0 -10
  196. package/src/modules/sales/orders/order.controller.ts +0 -93
  197. package/src/modules/sales/orders/order.entity.ts +0 -47
  198. package/src/modules/sales/orders/order.listener.ts +0 -20
  199. package/src/modules/sales/orders/order.module.ts +0 -19
  200. package/src/modules/sales/orders/order.repository.ts +0 -189
  201. package/src/modules/sales/orders/order.schema.ts +0 -35
  202. package/src/modules/sales/orders/order.validator.ts +0 -72
  203. package/src/modules/sales/orders/shipping/entities/address.entity.ts +0 -27
  204. package/src/modules/sales/orders/shipping/entities/customer.entity.ts +0 -14
  205. package/src/modules/sales/orders/shipping/entities/status.entity.ts +0 -16
  206. package/src/modules/sales/orders/shipping/shipping.entity.ts +0 -25
  207. package/src/modules/sales/orders/shipping/shipping.types.ts +0 -12
  208. package/src/modules/sales/orders/shipping/shipping.validator.ts +0 -25
  209. package/src/modules/sales/orders/shipping/validators/address.validator.ts +0 -28
  210. package/src/modules/sales/orders/shipping/validators/customer.validator.ts +0 -14
  211. package/src/modules/sales/orders/status/status.entity.ts +0 -16
  212. package/src/modules/sales/orders/status/status.validator.ts +0 -8
  213. package/src/modules/sales/sales.module.ts +0 -20
  214. package/src/modules/setting/connections/connection.controller.ts +0 -27
  215. package/src/modules/setting/connections/connection.module.ts +0 -17
  216. package/src/modules/setting/connections/connection.validator.ts +0 -15
  217. package/src/modules/setting/layout/layout.controller.ts +0 -34
  218. package/src/modules/setting/layout/layout.entity.ts +0 -13
  219. package/src/modules/setting/layout/layout.listener.ts +0 -7
  220. package/src/modules/setting/layout/layout.module.ts +0 -21
  221. package/src/modules/setting/layout/layout.repository.ts +0 -29
  222. package/src/modules/setting/layout/layout.schema.ts +0 -4
  223. package/src/modules/setting/members/member.controller.ts +0 -22
  224. package/src/modules/setting/members/member.module.ts +0 -17
  225. package/src/modules/setting/members/member.validator.ts +0 -3
  226. package/src/modules/setting/organization/organization.controller.ts +0 -33
  227. package/src/modules/setting/organization/organization.entity.ts +0 -27
  228. package/src/modules/setting/organization/organization.listener.ts +0 -46
  229. package/src/modules/setting/organization/organization.module.ts +0 -21
  230. package/src/modules/setting/organization/organization.repository.ts +0 -55
  231. package/src/modules/setting/organization/organization.types.ts +0 -65
  232. package/src/modules/setting/organization/organization.validator.ts +0 -56
  233. package/src/modules/setting/setting.module.ts +0 -23
  234. package/src/modules/setting/theme/theme.controller.ts +0 -34
  235. package/src/modules/setting/theme/theme.entity.ts +0 -13
  236. package/src/modules/setting/theme/theme.listener.ts +0 -6
  237. package/src/modules/setting/theme/theme.module.ts +0 -21
  238. package/src/modules/setting/theme/theme.repository.ts +0 -23
  239. package/src/modules/setting/theme/theme.schema.ts +0 -4
  240. package/src/modules/users/user.controller.ts +0 -75
  241. package/src/modules/users/user.module.ts +0 -20
  242. package/src/modules/users/user.validator.ts +0 -28
  243. package/src/providers/auth0.provider.ts +0 -36
  244. package/src/providers/storage.provider.ts +0 -22
  245. package/src/services/auth0.service.ts +0 -7
  246. package/src/services/logger.service.ts +0 -33
  247. package/src/services/mongo.service.ts +0 -44
  248. package/src/services/storage.service.ts +0 -39
  249. package/src/types.ts +0 -19
  250. package/tsconfig.json +0 -40
  251. package/tsconfig.package.json +0 -20
  252. package/yarn.lock +0 -8782
@@ -1,79 +0,0 @@
1
- import { Inject } from '@nestjs/common';
2
- import { REQUEST } from '@nestjs/core';
3
- import { EventEmitter2 } from '@nestjs/event-emitter';
4
- import { Request } from 'express';
5
- import { FilterQuery, Model, PopulateOptions, UpdateQuery } from 'mongoose';
6
- import { DecodedUser } from '../decorators/user.decorator';
7
- import { AbstractEntity } from './abstract.entity';
8
- import { FindValidator, SearchResults } from './abstract.validator';
9
-
10
- export abstract class AbstractRepository<E extends AbstractEntity> {
11
- public readonly abstract $model: Model<E>;
12
-
13
- @Inject(REQUEST)
14
- protected readonly $request: Request;
15
-
16
- @Inject()
17
- protected $event: EventEmitter2;
18
-
19
- protected get $user(): Partial<DecodedUser> | undefined {
20
- return this.$request?.user || { sub: String(process.env.USER_ID) };
21
- }
22
-
23
- public async find(validator: FindValidator<E> = {}): Promise<SearchResults<E>> {
24
- return this.$find(validator);
25
- }
26
-
27
- public async read(id: string, ...params: any[]): Promise<E> {
28
- return this.$model.findById(id);
29
- }
30
-
31
- public abstract create(...params: any[]): Promise<E>
32
-
33
- public abstract update(id: string, ...params: unknown[]): Promise<E>
34
-
35
- public abstract delete(id: string): Promise<void>
36
-
37
- protected async $find(validator: FindValidator<E>): Promise<SearchResults<E>> {
38
- const filters: FilterQuery<E> = { ...validator.filters, deletedAt: null };
39
-
40
- const query = this.$model.find<E>(filters);
41
- const counter = this.$model.count(filters);
42
-
43
- const skip = (validator.page * validator.limit) - validator.limit;
44
-
45
- !validator.sort?.createdAt && (validator.sort = { ...validator.sort, createdAt: 'desc' })
46
-
47
- validator.page && query.skip(skip);
48
- validator.sort && query.sort(validator.sort);
49
- validator.join && query.populate(validator.join as (PopulateOptions | string)[]);
50
-
51
- validator.limit && query.limit(validator.limit);
52
-
53
- return Promise.all([counter.count(), query.exec()])
54
- .then(([total, items]) => ({ total, items, page: validator.page }));
55
- }
56
-
57
- protected async $create(model: Partial<E>): Promise<E> {
58
- return this.$model.create(model);
59
- }
60
-
61
- protected async $update(id: string, query: UpdateQuery<E>): Promise<E> {
62
- const entity: E = await this.$model.findById(id);
63
-
64
- await entity.updateOne(query)
65
-
66
- return entity;
67
- }
68
-
69
- protected async $delete(id: string): Promise<void> {
70
-
71
- const entity: E = await this.$model.findById(id);
72
-
73
- const query: UpdateQuery<E> = {
74
- $set: { deletedAt: new Date() },
75
- };
76
-
77
- return entity.updateOne(query);
78
- }
79
- }
@@ -1,7 +0,0 @@
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
- }
@@ -1,62 +0,0 @@
1
- import { Transform } from 'class-transformer';
2
- import { IsInt, isObject, IsOptional } from 'class-validator';
3
- import { FilterQuery, PopulateOptions, SortOrder } from 'mongoose';
4
- import { AbstractEntity } from './abstract.entity';
5
- import 'reflect-metadata'
6
-
7
- export interface SearchResults<I> {
8
- page: number;
9
- total: number;
10
- items: I[];
11
- }
12
-
13
- export abstract class AbstractValidator {
14
-
15
- }
16
-
17
- export type KeyOfType<T, V> = keyof {
18
- [P in keyof T as T[P] extends V ? P : string]: any
19
- }
20
-
21
- export class FindValidator<E extends AbstractEntity> extends AbstractValidator {
22
- @Transform(({ value }) => value ? Number(value) : 10)
23
- @IsInt()
24
- @IsOptional()
25
- public limit? = 10;
26
-
27
- @Transform(({ value }) => value ? Number(value) : 1)
28
- @IsInt()
29
- @IsOptional()
30
- public page? = 1;
31
-
32
- @Transform(({ value }) => {
33
- if (isObject(value)) {
34
- return value
35
- }
36
-
37
- return value && JSON.parse(value);
38
- })
39
- @IsOptional()
40
- public sort?: Partial<Record<keyof E, SortOrder>> = {};
41
-
42
- @Transform(({ value }) => {
43
- if (isObject(value)) {
44
- return value
45
- }
46
-
47
- return value && JSON.parse(value);
48
- })
49
-
50
- @IsOptional()
51
- public filters?: FilterQuery<E> = {};
52
-
53
- @Transform(({ value }) => value.map((path) => {
54
- try {
55
- return JSON.parse(path);
56
- } catch (e: any) {
57
- return path;
58
- }
59
- }))
60
- @IsOptional()
61
- public join?: (PopulateOptions | KeyOfType<E, AbstractEntity | AbstractEntity[]>)[] = [];
62
- }
package/src/app.config.ts DELETED
@@ -1,57 +0,0 @@
1
- import { config } from 'dotenv';
2
- import { readFileSync } from 'fs';
3
- import { W } from 'mongodb';
4
- import { join } from 'path';
5
-
6
- config();
7
-
8
- export abstract class AppConfig {
9
- public static get auth0() {
10
- const domain = 'merkaly.us.auth0.com';
11
- const audience = `https://${domain}/api/v2/`;
12
- const client = 'eApUjfHoWlMPcTUuU1lqvE517q0KzTh9';
13
- const secret = String(process.env.AUTH0_CLIENT_SECRET);
14
-
15
- return { domain, audience, client, secret };
16
- }
17
-
18
- public static get sentry() {
19
- return {
20
- dsn: process.env.SENTRY_DSN,
21
- debug: process.env.NODE_ENV !== 'production',
22
- environment: process.env.NODE_ENV,
23
- };
24
- }
25
-
26
- public static get server() {
27
- return {
28
- port: Number(process.env.PORT) || 8080,
29
- name: String(process.env.npm_package_name),
30
- description: String(process.env.npm_package_description),
31
- version: String(process.env.npm_package_version),
32
- };
33
- }
34
-
35
- public static get mongo() {
36
- const { MONGO_PASSWORD, MONGO_USER, MONGO_HOST } = process.env;
37
-
38
- return {
39
- host: MONGO_HOST,
40
- user: MONGO_USER,
41
- pass: MONGO_PASSWORD,
42
- retryWrites: true,
43
- w: 'majority' as W,
44
- };
45
- }
46
-
47
- public static get storage() {
48
- const serviceAccount = readFileSync(join(process.cwd(), '/serviceAccount.json'));
49
- const credentials = JSON.parse(serviceAccount.toString());
50
-
51
- return {
52
- projectId: 'api-merkaly-io',
53
- bucketName: process.env.GCP_BUCKET_NAME,
54
- serviceAccount: credentials,
55
- };
56
- }
57
- }
@@ -1,30 +0,0 @@
1
- import { Logger } from '@nestjs/common';
2
- import { BootstrapConsole } from 'nestjs-console';
3
- import { AppModule } from './app.module';
4
-
5
- const bootstrap = new BootstrapConsole({
6
- module: AppModule,
7
- useDecorators: true,
8
- contextOptions: {
9
- logger: [
10
- 'debug',
11
- 'error',
12
- 'log',
13
- 'verbose',
14
- 'warn',
15
- ],
16
- },
17
- });
18
-
19
- bootstrap.init().then(async (app) => {
20
- try {
21
- app.useLogger(Logger);
22
- await app.init();
23
- await bootstrap.boot();
24
- await app.close();
25
- } catch (e) {
26
- console.error(e);
27
- await app.close();
28
- process.exit(1);
29
- }
30
- });
@@ -1,48 +0,0 @@
1
- import { Controller, Get, Inject } from '@nestjs/common';
2
- import { REQUEST } from '@nestjs/core';
3
- import { EventEmitter2 } from '@nestjs/event-emitter';
4
- import { Organization } from 'auth0';
5
- import { Request } from 'express';
6
- import { Public } from './decorators/public.decorator';
7
- import { GetUser } from './decorators/user.decorator';
8
- import { OrganizationEvent } from './modules/setting/organization/organization.listener';
9
- import { Auth0Service } from './services/auth0.service';
10
-
11
- @Controller('/')
12
- export class AppController {
13
- @Inject()
14
- protected readonly $event: EventEmitter2;
15
- @Inject()
16
- protected readonly $auth0: Auth0Service;
17
- private readonly $organization: Organization;
18
-
19
- public constructor(@Inject(REQUEST) { session }: Request) {
20
- this.$organization = session.organization;
21
- }
22
-
23
- @Get('/health')
24
- @Public()
25
- public async health(): Promise<string> {
26
- return 'health';
27
- }
28
-
29
- @Get('/organization')
30
- @Public()
31
- public async organizations(): Promise<Organization> {
32
- return this.$organization;
33
- }
34
-
35
- @Get('/organizations')
36
- public async userOrganizations(@GetUser('sub') user: string): Promise<Organization[]> {
37
- return this.$auth0.users.getUserOrganizations({ id: user })
38
- .then((organizations) => {
39
-
40
- const newOrgs = organizations.map((organization) => {
41
- return this.$event.emitAsync(OrganizationEvent.POST_READ, organization)
42
- .then(({ 1: result }) => result);
43
- });
44
-
45
- return Promise.all<Organization>(newOrgs);
46
- });
47
- }
48
- }
@@ -1,7 +0,0 @@
1
- const { MONGO_HOST, MONGO_USER, MONGO_PASSWORD, ORG_ID } = process.env
2
-
3
- module.exports = {
4
- 'dbConnectionUri': `mongodb+srv://${MONGO_USER}:${MONGO_PASSWORD}@${MONGO_HOST}/${ORG_ID}?retryWrites=true&w=majority`,
5
- 'migrationsDir': './src/migrations',
6
- 'collection': 'app_migrations'
7
- }
package/src/app.module.ts DELETED
@@ -1,92 +0,0 @@
1
- import {
2
- CacheModule,
3
- Inject,
4
- Logger,
5
- MiddlewareConsumer,
6
- Module,
7
- ModuleMetadata,
8
- NestModule,
9
- RequestMethod,
10
- Scope,
11
- } from '@nestjs/common';
12
- import { ConfigModule } from '@nestjs/config';
13
- import { APP_INTERCEPTOR, RouterModule } from '@nestjs/core';
14
- import { Routes } from '@nestjs/core/router/interfaces';
15
- import { EventEmitter2, EventEmitterModule } from '@nestjs/event-emitter';
16
- import { AppController } from './app.controller';
17
- import { AppStrategy } from './app.strategy';
18
- import { MongoInterceptor } from './interceptors/mongo.interceptor';
19
- import { LoggerMiddleware } from './middlewares/logger.middleware';
20
- import { OrganizationMiddleware } from './middlewares/organization.middleware';
21
- import { AssetModule } from './modules/assets/asset.module';
22
- import { CommandsModule } from './modules/command.module';
23
- import { ContentModule } from './modules/content/content.module';
24
- import { GlobalModule } from './modules/global.module';
25
- import { InsightModule } from './modules/insight/insight.module';
26
- import { InventoryModule } from './modules/inventory/inventory.module';
27
- import { SettingModule } from './modules/setting/setting.module';
28
- import { SalesModule } from './modules/sales/sales.module';
29
- import { UserModule } from './modules/users/user.module';
30
- import { LoggerService } from './services/logger.service';
31
- import { AuthModule } from "./modules/auth/auth.module";
32
-
33
- export const router = [
34
- AssetModule,
35
- AuthModule,
36
- ContentModule,
37
- InventoryModule,
38
- InsightModule,
39
- SettingModule,
40
- SalesModule,
41
- UserModule,
42
- ];
43
-
44
- const modules = [
45
- ...router,
46
- GlobalModule.register(),
47
- CommandsModule.register(),
48
- RouterModule.register(router as Routes),
49
- CacheModule.register({ isGlobal: true }),
50
- ConfigModule.forRoot({ isGlobal: true }),
51
- EventEmitterModule.forRoot({ wildcard: true }),
52
- ];
53
-
54
- export const metadata: ModuleMetadata = {
55
- controllers: [AppController],
56
- imports: modules,
57
- providers: [
58
- AppStrategy,
59
- {
60
- provide: APP_INTERCEPTOR,
61
- scope: Scope.REQUEST,
62
- useClass: MongoInterceptor,
63
- },
64
- ],
65
- };
66
-
67
- @Module(metadata)
68
- export class AppModule implements NestModule {
69
- @Inject()
70
- protected readonly $event: EventEmitter2;
71
-
72
- @Inject()
73
- protected readonly $logger: LoggerService;
74
-
75
- public configure(consumer: MiddlewareConsumer): MiddlewareConsumer {
76
- this.$event.onAny((event) => Logger.verbose(`Event emitted: ${event}`));
77
-
78
- consumer
79
- .apply(OrganizationMiddleware)
80
- .exclude(
81
- { path: '/health', method: RequestMethod.GET },
82
- { path: '/organizations', method: RequestMethod.GET }
83
- )
84
- .forRoutes({ path: '/*', method: RequestMethod.ALL });
85
-
86
- consumer
87
- .apply(LoggerMiddleware)
88
- .forRoutes({ path: '/*', method: RequestMethod.ALL });
89
-
90
- return consumer;
91
- }
92
- }
@@ -1,25 +0,0 @@
1
- import { Injectable } from '@nestjs/common';
2
- import { PassportStrategy } from '@nestjs/passport';
3
- import { readFileSync } from 'fs';
4
- import { ExtractJwt, Strategy, StrategyOptions } from 'passport-jwt';
5
- import { join } from 'path';
6
- import { AppConfig } from './app.config';
7
- import { DecodedUser } from './decorators/user.decorator';
8
-
9
- @Injectable()
10
- export class AppStrategy extends PassportStrategy(Strategy) {
11
- public constructor() {
12
- const strategy: StrategyOptions = {
13
- jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
14
- audience: AppConfig.auth0.audience,
15
- ignoreExpiration: true,
16
- secretOrKey: process.env.AUTH_CERTIFICATE || readFileSync(join(process.cwd(), '/authCertificate.pem')),
17
- };
18
-
19
- super(strategy);
20
- }
21
-
22
- public validate(user: DecodedUser) {
23
- return user;
24
- }
25
- }
@@ -1,38 +0,0 @@
1
- import { Inject } from '@nestjs/common';
2
- import { Command, Console } from 'nestjs-console';
3
- import { AssetEntity } from '../modules/assets/asset.entity';
4
- import { AssetRepository } from '../modules/assets/asset.repository';
5
- import { ProductEntity } from '../modules/inventory/products/product.entity';
6
- import { ProductRepository } from '../modules/inventory/products/product.repository';
7
- import { StorageService } from '../services/storage.service';
8
-
9
- @Console({ command: 'assets', description: 'Prune, cleand and remove assets' })
10
- export class AssetsCommand {
11
- @Inject()
12
- protected readonly $storage: StorageService;
13
-
14
- @Inject()
15
- protected readonly $assetRepository: AssetRepository;
16
-
17
- @Inject()
18
- protected readonly $productRepository: ProductRepository;
19
-
20
- @Command({ command: 'prune', description: 'Remove assest that hasnt relation with another entity' })
21
- public async prune() {
22
-
23
- const products: ProductEntity[] = await this.$productRepository.$model
24
- .find({ files: { $exists: true, $not: { $size: 0 } } });
25
-
26
- const files = products.map(({ files }) => files).flat();
27
- const assets: AssetEntity[] = await this.$assetRepository.$model.find({ '_id': { $nin: files } });
28
-
29
- // Remove automatically assets that not are stored in google storage
30
- const externalAssets = assets.filter(asset => asset.url.startsWith('https://storage.googleapis.com') === false);
31
- const internalAssets = assets.filter(asset => asset.url.startsWith('https://storage.googleapis.com'));
32
-
33
- await this.$assetRepository.$model.find({ '_id': { $nin: files } });
34
- await this.$assetRepository.$model.deleteMany({ _id: { $in: externalAssets.map(asset => asset._id) } });
35
-
36
- return process.exit();
37
- }
38
- }
@@ -1,6 +0,0 @@
1
- import { Console } from 'nestjs-console';
2
-
3
- @Console({ command: 'deploy', description: 'Deploy App' })
4
- export class DeployCommand {
5
-
6
- }
@@ -1,11 +0,0 @@
1
- import { Command, Console } from 'nestjs-console';
2
-
3
- @Console({ command: 'fixture', description: 'Fill db with default required data' })
4
- export class FixtureCommand {
5
- @Command({ command: 'settings:payments', description: 'Add all default settings payments' })
6
- public async settingsPayments() {
7
- const types = [];
8
-
9
- return Promise.all(types);
10
- }
11
- }