@sgftech/medusa-plugin-marketplace-v2 0.1.26

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 (222) hide show
  1. package/.babelrc.js +12 -0
  2. package/.eslintrc.js +68 -0
  3. package/.vscode/settings.json +2 -0
  4. package/.yarnrc.yml +1 -0
  5. package/README.md +70 -0
  6. package/SECURITY.md +21 -0
  7. package/data/seed-onboarding.json +141 -0
  8. package/data/seed.json +1006 -0
  9. package/dist/api/middlewares/authenticate-user.d.ts +15 -0
  10. package/dist/api/middlewares/authenticate-user.js +212 -0
  11. package/dist/api/middlewares/authenticate-user.js.map +1 -0
  12. package/dist/api/middlewares/logged-in-user-v2.d.ts +3 -0
  13. package/dist/api/middlewares/logged-in-user-v2.js +69 -0
  14. package/dist/api/middlewares/logged-in-user-v2.js.map +1 -0
  15. package/dist/api/middlewares/logged-in-user.d.ts +1 -0
  16. package/dist/api/middlewares/logged-in-user.js +18 -0
  17. package/dist/api/middlewares/logged-in-user.js.map +1 -0
  18. package/dist/api/routes/admin/create-product.d.ts +1 -0
  19. package/dist/api/routes/admin/create-product.js +19 -0
  20. package/dist/api/routes/admin/create-product.js.map +1 -0
  21. package/dist/api/routes/admin/create-store.d.ts +1 -0
  22. package/dist/api/routes/admin/create-store.js +19 -0
  23. package/dist/api/routes/admin/create-store.js.map +1 -0
  24. package/dist/api/routes/admin/create-user.d.ts +1 -0
  25. package/dist/api/routes/admin/create-user.js +19 -0
  26. package/dist/api/routes/admin/create-user.js.map +1 -0
  27. package/dist/index.d.ts +0 -0
  28. package/dist/index.js +1 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/migrations/1629000000000-create-workflow-table.d.ts +5 -0
  31. package/dist/migrations/1629000000000-create-workflow-table.js +29 -0
  32. package/dist/migrations/1629000000000-create-workflow-table.js.map +1 -0
  33. package/dist/migrations/1629000000001-workflow-table-stage.d.ts +5 -0
  34. package/dist/migrations/1629000000001-workflow-table-stage.js +48 -0
  35. package/dist/migrations/1629000000001-workflow-table-stage.js.map +1 -0
  36. package/dist/migrations/1632467997443-workflow-requests.d.ts +5 -0
  37. package/dist/migrations/1632467997443-workflow-requests.js +48 -0
  38. package/dist/migrations/1632467997443-workflow-requests.js.map +1 -0
  39. package/dist/migrations/1632468000000-update-workflow-keys-table.d.ts +5 -0
  40. package/dist/migrations/1632468000000-update-workflow-keys-table.js +31 -0
  41. package/dist/migrations/1632468000000-update-workflow-keys-table.js.map +1 -0
  42. package/dist/migrations/1632470000000-add-approvers-to-workflow-stage.d.ts +5 -0
  43. package/dist/migrations/1632470000000-add-approvers-to-workflow-stage.js +52 -0
  44. package/dist/migrations/1632470000000-add-approvers-to-workflow-stage.js.map +1 -0
  45. package/dist/migrations/1632471000000-update-user-table-for-approvers.d.ts +5 -0
  46. package/dist/migrations/1632471000000-update-user-table-for-approvers.js +43 -0
  47. package/dist/migrations/1632471000000-update-user-table-for-approvers.js.map +1 -0
  48. package/dist/migrations/1632472000000-update-workflow-request-table-for-approvals.d.ts +5 -0
  49. package/dist/migrations/1632472000000-update-workflow-request-table-for-approvals.js +43 -0
  50. package/dist/migrations/1632472000000-update-workflow-request-table-for-approvals.js.map +1 -0
  51. package/dist/migrations/1632473000000-create-approval-table.d.ts +5 -0
  52. package/dist/migrations/1632473000000-create-approval-table.js +54 -0
  53. package/dist/migrations/1632473000000-create-approval-table.js.map +1 -0
  54. package/dist/migrations/1652101349791-order.migration.d.ts +6 -0
  55. package/dist/migrations/1652101349791-order.migration.js +26 -0
  56. package/dist/migrations/1652101349791-order.migration.js.map +1 -0
  57. package/dist/migrations/1655123458263-invite.migration.d.ts +6 -0
  58. package/dist/migrations/1655123458263-invite.migration.js +23 -0
  59. package/dist/migrations/1655123458263-invite.migration.js.map +1 -0
  60. package/dist/migrations/1655131148363-role.migration.d.ts +6 -0
  61. package/dist/migrations/1655131148363-role.migration.js +32 -0
  62. package/dist/migrations/1655131148363-role.migration.js.map +1 -0
  63. package/dist/migrations/1655131601491-permission.migration.d.ts +6 -0
  64. package/dist/migrations/1655131601491-permission.migration.js +47 -0
  65. package/dist/migrations/1655131601491-permission.migration.js.map +1 -0
  66. package/dist/migrations/1655132360987-user.migration.d.ts +6 -0
  67. package/dist/migrations/1655132360987-user.migration.js +29 -0
  68. package/dist/migrations/1655132360987-user.migration.js.map +1 -0
  69. package/dist/migrations/1666588571522-user.migration.d.ts +6 -0
  70. package/dist/migrations/1666588571522-user.migration.js +27 -0
  71. package/dist/migrations/1666588571522-user.migration.js.map +1 -0
  72. package/dist/migrations/1666588577183-store.migration.d.ts +6 -0
  73. package/dist/migrations/1666588577183-store.migration.js +26 -0
  74. package/dist/migrations/1666588577183-store.migration.js.map +1 -0
  75. package/dist/migrations/1667045765051-customer.migration.d.ts +6 -0
  76. package/dist/migrations/1667045765051-customer.migration.js +33 -0
  77. package/dist/migrations/1667045765051-customer.migration.js.map +1 -0
  78. package/dist/migrations/1683175918497-add-user-stores.migration.d.ts +6 -0
  79. package/dist/migrations/1683175918497-add-user-stores.migration.js +60 -0
  80. package/dist/migrations/1683175918497-add-user-stores.migration.js.map +1 -0
  81. package/dist/migrations/1683177500538-add-product-store-id.migration.d.ts +6 -0
  82. package/dist/migrations/1683177500538-add-product-store-id.migration.js +53 -0
  83. package/dist/migrations/1683177500538-add-product-store-id.migration.js.map +1 -0
  84. package/dist/migrations/address.migration.d.ts +6 -0
  85. package/dist/migrations/address.migration.js +25 -0
  86. package/dist/migrations/address.migration.js.map +1 -0
  87. package/dist/migrations/product.migration.d.ts +6 -0
  88. package/dist/migrations/product.migration.js +21 -0
  89. package/dist/migrations/product.migration.js.map +1 -0
  90. package/dist/migrations/stage-status.d.ts +5 -0
  91. package/dist/migrations/stage-status.js +22 -0
  92. package/dist/migrations/stage-status.js.map +1 -0
  93. package/dist/migrations/user.migration.d.ts +6 -0
  94. package/dist/migrations/user.migration.js +21 -0
  95. package/dist/migrations/user.migration.js.map +1 -0
  96. package/dist/models/address.d.ts +3 -0
  97. package/dist/models/address.js +18 -0
  98. package/dist/models/address.js.map +1 -0
  99. package/dist/models/customer.d.ts +9 -0
  100. package/dist/models/customer.js +49 -0
  101. package/dist/models/customer.js.map +1 -0
  102. package/dist/models/invite.d.ts +6 -0
  103. package/dist/models/invite.js +32 -0
  104. package/dist/models/invite.js.map +1 -0
  105. package/dist/models/order.d.ts +9 -0
  106. package/dist/models/order.js +48 -0
  107. package/dist/models/order.js.map +1 -0
  108. package/dist/models/permission.d.ts +8 -0
  109. package/dist/models/permission.js +56 -0
  110. package/dist/models/permission.js.map +1 -0
  111. package/dist/models/product.d.ts +5 -0
  112. package/dist/models/product.js +43 -0
  113. package/dist/models/product.js.map +1 -0
  114. package/dist/models/role.d.ts +12 -0
  115. package/dist/models/role.js +68 -0
  116. package/dist/models/role.js.map +1 -0
  117. package/dist/models/setting.d.ts +69 -0
  118. package/dist/models/setting.js +46 -0
  119. package/dist/models/setting.js.map +1 -0
  120. package/dist/models/store.d.ts +15 -0
  121. package/dist/models/store.js +85 -0
  122. package/dist/models/store.js.map +1 -0
  123. package/dist/models/user.d.ts +15 -0
  124. package/dist/models/user.js +76 -0
  125. package/dist/models/user.js.map +1 -0
  126. package/dist/models/workflow-approval.d.ts +8 -0
  127. package/dist/models/workflow-approval.js +37 -0
  128. package/dist/models/workflow-approval.js.map +1 -0
  129. package/dist/models/workflow-requests.d.ts +9 -0
  130. package/dist/models/workflow-requests.js +42 -0
  131. package/dist/models/workflow-requests.js.map +1 -0
  132. package/dist/models/workflow-stage.d.ts +8 -0
  133. package/dist/models/workflow-stage.js +38 -0
  134. package/dist/models/workflow-stage.js.map +1 -0
  135. package/dist/models/workflow.d.ts +8 -0
  136. package/dist/models/workflow.js +37 -0
  137. package/dist/models/workflow.js.map +1 -0
  138. package/dist/repositories/address.d.ts +7 -0
  139. package/dist/repositories/address.js +11 -0
  140. package/dist/repositories/address.js.map +1 -0
  141. package/dist/repositories/currency.d.ts +7 -0
  142. package/dist/repositories/currency.js +11 -0
  143. package/dist/repositories/currency.js.map +1 -0
  144. package/dist/repositories/customer.d.ts +12 -0
  145. package/dist/repositories/customer.js +11 -0
  146. package/dist/repositories/customer.js.map +1 -0
  147. package/dist/repositories/invite.d.ts +7 -0
  148. package/dist/repositories/invite.js +11 -0
  149. package/dist/repositories/invite.js.map +1 -0
  150. package/dist/repositories/order.d.ts +9 -0
  151. package/dist/repositories/order.js +11 -0
  152. package/dist/repositories/order.js.map +1 -0
  153. package/dist/repositories/permission.d.ts +3 -0
  154. package/dist/repositories/permission.js +8 -0
  155. package/dist/repositories/permission.js.map +1 -0
  156. package/dist/repositories/product.d.ts +43 -0
  157. package/dist/repositories/product.js +11 -0
  158. package/dist/repositories/product.js.map +1 -0
  159. package/dist/repositories/role.d.ts +3 -0
  160. package/dist/repositories/role.js +8 -0
  161. package/dist/repositories/role.js.map +1 -0
  162. package/dist/repositories/store.d.ts +7 -0
  163. package/dist/repositories/store.js +11 -0
  164. package/dist/repositories/store.js.map +1 -0
  165. package/dist/repositories/user.d.ts +7 -0
  166. package/dist/repositories/user.js +11 -0
  167. package/dist/repositories/user.js.map +1 -0
  168. package/dist/services/currency.d.ts +24 -0
  169. package/dist/services/currency.js +49 -0
  170. package/dist/services/currency.js.map +1 -0
  171. package/dist/services/customer.d.ts +34 -0
  172. package/dist/services/customer.js +137 -0
  173. package/dist/services/customer.js.map +1 -0
  174. package/dist/services/process-constant.d.ts +17 -0
  175. package/dist/services/process-constant.js +27 -0
  176. package/dist/services/process-constant.js.map +1 -0
  177. package/dist/services/product.d.ts +121 -0
  178. package/dist/services/product.js +382 -0
  179. package/dist/services/product.js.map +1 -0
  180. package/dist/services/region.d.ts +42 -0
  181. package/dist/services/region.js +190 -0
  182. package/dist/services/region.js.map +1 -0
  183. package/dist/services/store.d.ts +98 -0
  184. package/dist/services/store.js +607 -0
  185. package/dist/services/store.js.map +1 -0
  186. package/dist/services/user.d.ts +74 -0
  187. package/dist/services/user.js +356 -0
  188. package/dist/services/user.js.map +1 -0
  189. package/dist/services/workflow-request.d.ts +14 -0
  190. package/dist/services/workflow-request.js +100 -0
  191. package/dist/services/workflow-request.js.map +1 -0
  192. package/dist/services/workflow-stage.d.ts +19 -0
  193. package/dist/services/workflow-stage.js +46 -0
  194. package/dist/services/workflow-stage.js.map +1 -0
  195. package/dist/services/workflow.d.ts +22 -0
  196. package/dist/services/workflow.js +108 -0
  197. package/dist/services/workflow.js.map +1 -0
  198. package/dist/subscribers/customer.d.ts +5 -0
  199. package/dist/subscribers/customer.js +20 -0
  200. package/dist/subscribers/customer.js.map +1 -0
  201. package/dist/subscribers/product.d.ts +11 -0
  202. package/dist/subscribers/product.js +30 -0
  203. package/dist/subscribers/product.js.map +1 -0
  204. package/dist/subscribers/store.d.ts +25 -0
  205. package/dist/subscribers/store.js +54 -0
  206. package/dist/subscribers/store.js.map +1 -0
  207. package/dist/subscribers/user.d.ts +16 -0
  208. package/dist/subscribers/user.js +62 -0
  209. package/dist/subscribers/user.js.map +1 -0
  210. package/dist/types/global.d.ts +1 -0
  211. package/dist/types/global.js +3 -0
  212. package/dist/types/global.js.map +1 -0
  213. package/dist/types/oidc-types.d.ts +13 -0
  214. package/dist/types/oidc-types.js +3 -0
  215. package/dist/types/oidc-types.js.map +1 -0
  216. package/index.js +50 -0
  217. package/package.json +105 -0
  218. package/tsconfig.admin.json +8 -0
  219. package/tsconfig.json +33 -0
  220. package/tsconfig.server.json +8 -0
  221. package/tsconfig.spec.json +5 -0
  222. package/yarn-error.log +12869 -0
@@ -0,0 +1,121 @@
1
+ import { EntityManager, FindOperator, InsertEvent } from "typeorm";
2
+ import { CartService, EventBusService, ProductCollectionService, ProductService as MedusaProductService, ProductVariantService } from "@medusajs/medusa/dist/services";
3
+ import { Product } from "../models/product";
4
+ import { User } from "../models/user";
5
+ import UserService from "./user";
6
+ import { AbstractPriceSelectionStrategy, PriceList, PriceListLoadConfig, SalesChannel } from "@medusajs/medusa/dist";
7
+ import { CreateProductInput, FilterableProductProps as MedusaFilterableProductProps } from "@medusajs/medusa/dist/types/product";
8
+ import { FindConfig, Selector } from "@medusajs/medusa/dist/types/common";
9
+ import { ProductRepository } from "../repositories/product";
10
+ import { ProductOptionRepository } from "@medusajs/medusa/dist/repositories/product-option";
11
+ import { ProductTypeRepository } from "@medusajs/medusa/dist/repositories/product-type";
12
+ import { ProductTagRepository } from "@medusajs/medusa/dist/repositories/product-tag";
13
+ import { ImageRepository } from "@medusajs/medusa/dist/repositories/image";
14
+ import DefaultSearchService from "@medusajs/medusa/dist/services/search";
15
+ import { ConfigModule, Logger } from "@medusajs/types";
16
+ import StoreService from "./store";
17
+ export type ProductSelector = MedusaFilterableProductProps | (Selector<Product> & {
18
+ q?: string;
19
+ discount_condition_id?: string;
20
+ price_list_id?: string[] | FindOperator<PriceList>;
21
+ sales_channel_id?: string[] | FindOperator<SalesChannel>;
22
+ });
23
+ type FindProductConfig = FindConfig<Product> & PriceListLoadConfig;
24
+ type ConstructorParams = {
25
+ manager: EntityManager;
26
+ loggedInUser?: User;
27
+ defaultAdmin?: User;
28
+ productRepository: typeof ProductRepository;
29
+ productVariantRepository: any;
30
+ productOptionRepository: any;
31
+ eventBusService: EventBusService;
32
+ productVariantService: ProductVariantService;
33
+ productCollectionService: ProductCollectionService;
34
+ productCategoryRepository: any;
35
+ productTypeRepository: any;
36
+ productTagRepository: any;
37
+ imageRepository: any;
38
+ searchService: DefaultSearchService;
39
+ userService: UserService;
40
+ storeService: StoreService;
41
+ cartRepository: CartService;
42
+ priceSelectionStrategy: AbstractPriceSelectionStrategy;
43
+ featureFlagRouter: any;
44
+ logger: Logger;
45
+ configModule: ConfigModule;
46
+ };
47
+ export declare class ProductService extends MedusaProductService {
48
+ #private;
49
+ readonly container: ConstructorParams;
50
+ static LIFE_TIME: import("awilix").LifetimeType;
51
+ protected eventBus_: EventBusService;
52
+ protected transactionManager_: EntityManager;
53
+ protected productRepository_: typeof ProductRepository;
54
+ protected productCollectionService: ProductCollectionService;
55
+ protected userService: UserService;
56
+ protected cartService: CartService;
57
+ protected priceSelectionStrategy: AbstractPriceSelectionStrategy;
58
+ protected loggedInUser: User;
59
+ protected productRepository: typeof ProductRepository;
60
+ protected eventBusService: EventBusService;
61
+ protected productTypeRepository: typeof ProductTypeRepository;
62
+ protected productOptionRepository_: typeof ProductOptionRepository;
63
+ protected productTagRepository: typeof ProductTagRepository;
64
+ protected imageRepository: typeof ImageRepository;
65
+ protected searchService: DefaultSearchService;
66
+ protected cartRepository: CartService;
67
+ protected productVariantService_: ProductVariantService;
68
+ logger: Logger;
69
+ storeService: StoreService;
70
+ configModule: ConfigModule;
71
+ constructor(container: ConstructorParams);
72
+ withTransaction(transactionManager: EntityManager): this;
73
+ attachProductToUserStores(event: InsertEvent<Product>): Promise<InsertEvent<Product>>;
74
+ /**
75
+ * Gets a product by id.
76
+ * Throws in case of DB Error and if product was not found.
77
+ * @param productId - id of the product to get.
78
+ * @param config - object that defines what should be included in the
79
+ * query response
80
+ * @return the result of the find one operation.
81
+ */
82
+ retrieve(productId: string, config?: FindProductConfig): Promise<Product>;
83
+ retrieve_(selector: Selector<Product>, config: FindConfig<Product>): Promise<Product>;
84
+ prepareListQuery_(selector: Selector<Product>, config: FindProductConfig): {
85
+ q: string;
86
+ relations: any;
87
+ query: any;
88
+ };
89
+ retrieveByHandle(productHandle: string, config?: FindProductConfig): Promise<Product>;
90
+ /**
91
+ * Gets a product by external id.
92
+ * Throws in case of DB Error and if product was not found.
93
+ * @param externalId - handle of the product to get.
94
+ * @param config - details about what to get from the product
95
+ * @param store_id - the store id to reference
96
+ * @return the result of the find one operation.
97
+ */
98
+ retrieveByExternalId(externalId: string, config?: FindProductConfig): Promise<Product>;
99
+ /**
100
+ * Lists products based on the provided parameters and includes the count of
101
+ * products that match the query.
102
+ * @param selector - an object that defines rules to filter products
103
+ * by
104
+ * @param config - object that defines the scope for what should be
105
+ * returned
106
+ * @return an array containing the products as
107
+ * the first element and the total count of products that matches the query
108
+ * as the second element.
109
+ */
110
+ listAndCount(selector: ProductSelector, config?: FindProductConfig): Promise<[Product[], number]>;
111
+ getStoreActiveUsers(): {
112
+ user?: User;
113
+ adminUser?: User;
114
+ };
115
+ create(productObject: CreateProductInput & {
116
+ store_id?: string;
117
+ }): Promise<Product>;
118
+ associateProductWithStore(product: Product, storeId: string): Promise<Product>;
119
+ dissociateProductFromStore(product: Product, storeId: string): Promise<Product>;
120
+ }
121
+ export default ProductService;
@@ -0,0 +1,382 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
+ };
17
+ var _ProductService_manager;
18
+ var ProductService_1;
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.ProductService = void 0;
21
+ /* eslint-disable new-cap */
22
+ /* eslint-disable require-jsdoc */
23
+ const typeorm_1 = require("typeorm");
24
+ const awilix_1 = require("awilix");
25
+ const services_1 = require("@medusajs/medusa/dist/services");
26
+ const product_1 = require("../models/product");
27
+ const utils_1 = require("@medusajs/medusa/dist/utils");
28
+ const medusa_core_utils_1 = require("medusa-core-utils");
29
+ let ProductService = ProductService_1 = class ProductService extends services_1.ProductService {
30
+ constructor(container) {
31
+ super(container);
32
+ this.container = container;
33
+ _ProductService_manager.set(this, void 0);
34
+ __classPrivateFieldSet(this, _ProductService_manager, container.manager, "f");
35
+ this.loggedInUser = Object.keys(container).includes("loggedInUser")
36
+ ? container.loggedInUser
37
+ : undefined;
38
+ this.logger = container.logger;
39
+ this.productRepository = container.productRepository;
40
+ this.productVariantService_ = container.productVariantService;
41
+ this.productOptionRepository_ = container.productOptionRepository;
42
+ this.eventBusService = container.eventBusService;
43
+ this.productCollectionService = container.productCollectionService;
44
+ this.productTypeRepository = container.productTypeRepository;
45
+ this.productTagRepository = container.productTagRepository;
46
+ this.imageRepository = container.imageRepository;
47
+ this.searchService = container.searchService;
48
+ this.userService = container.userService;
49
+ this.cartRepository = container.cartRepository;
50
+ this.priceSelectionStrategy = container.priceSelectionStrategy;
51
+ this.storeService = container.storeService;
52
+ this.eventBus_ = container.eventBusService;
53
+ this.productRepository_ = container.productRepository;
54
+ this.configModule = container.configModule;
55
+ __classPrivateFieldSet(this, _ProductService_manager, container.manager, "f");
56
+ }
57
+ withTransaction(transactionManager) {
58
+ if (!transactionManager) {
59
+ return this;
60
+ }
61
+ const cloned = new ProductService_1({
62
+ manager: transactionManager,
63
+ productRepository: this.productRepository_,
64
+ productVariantRepository: this.productVariantRepository_,
65
+ productOptionRepository: this.productOptionRepository_,
66
+ productCategoryRepository: this.productCategoryRepository_,
67
+ eventBusService: this.eventBus_,
68
+ productVariantService: this.productVariantService_,
69
+ productCollectionService: this.productCollectionService,
70
+ productTypeRepository: this.productTypeRepository_,
71
+ productTagRepository: this.productTagRepository_,
72
+ imageRepository: this.imageRepository_,
73
+ searchService: this.searchService_,
74
+ userService: this.userService,
75
+ cartRepository: this.cartService,
76
+ priceSelectionStrategy: this.priceSelectionStrategy,
77
+ featureFlagRouter: this.featureFlagRouter_,
78
+ logger: this.logger,
79
+ storeService: this.storeService,
80
+ configModule: this.configModule
81
+ });
82
+ cloned.transactionManager_ = transactionManager;
83
+ return cloned;
84
+ }
85
+ async attachProductToUserStores(event) {
86
+ const { user, adminUser } = this.getStoreActiveUsers();
87
+ const activeUser = user !== null && user !== void 0 ? user : adminUser;
88
+ Object.assign(event.entity.stores, activeUser.stores);
89
+ return event;
90
+ }
91
+ /**
92
+ * Gets a product by id.
93
+ * Throws in case of DB Error and if product was not found.
94
+ * @param productId - id of the product to get.
95
+ * @param config - object that defines what should be included in the
96
+ * query response
97
+ * @return the result of the find one operation.
98
+ */
99
+ async retrieve(productId, config = {
100
+ include_discount_prices: false
101
+ }) {
102
+ return await this.retrieve_({ id: productId }, config);
103
+ }
104
+ async retrieve_(selector, config) {
105
+ var _a;
106
+ // const manager = this.transactionManager_ ?? this.#manager;
107
+ const productRepo = this.activeManager_.withRepository(this.productRepository);
108
+ if (!((_a = config.relations) === null || _a === void 0 ? void 0 : _a.includes("stores"))) {
109
+ if (config.relations) {
110
+ config.relations.push("stores");
111
+ }
112
+ else {
113
+ config.relations = ["stores"];
114
+ }
115
+ }
116
+ const { relations, ...query } = (0, utils_1.buildQuery)(selector, config);
117
+ this.logger.debug(`querying where:${JSON.stringify(query.where)}`);
118
+ try {
119
+ const product = await productRepo.findOne({ relations, ...query });
120
+ if (!product) {
121
+ throw new Error("Product not found " + JSON.stringify(query));
122
+ }
123
+ return product;
124
+ }
125
+ catch (e) {
126
+ const selectorConstraints = Object.entries(selector)
127
+ .map(([key, value]) => `${key}: ${value}`)
128
+ .join(", ");
129
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, `Product with ${selectorConstraints} was not found`);
130
+ }
131
+ }
132
+ /* prepareListQuery_(selector: object, config: object): {
133
+ q: string;
134
+ relations: (keyof Product)[];
135
+ query: FindWithoutRelationsOptions;
136
+ }
137
+ {
138
+ const loggedInUser = Object.keys(this.container).
139
+ includes('loggedInUser') ? this.container.loggedInUser : null
140
+ if (loggedInUser) {
141
+ selector['store_id'] = loggedInUser.store_id
142
+ }
143
+
144
+ return super.prepareListQuery_(selector, config);
145
+ }*/
146
+ prepareListQuery_(selector, config) {
147
+ var _a;
148
+ if (!((_a = config.relations) === null || _a === void 0 ? void 0 : _a.includes("stores"))) {
149
+ if (config.relations) {
150
+ config.relations.push("stores");
151
+ }
152
+ else {
153
+ config.relations = ["stores"];
154
+ }
155
+ }
156
+ return super.prepareListQuery_(selector, config);
157
+ /* let q;
158
+ if ("q" in selector) {
159
+ q = selector.q;
160
+ delete selector.q;
161
+ }
162
+
163
+ const query = buildQuery(selector, config);
164
+
165
+ if (config.relations && config.relations.length > 0) {
166
+ query.relations = config.relations as any;
167
+ }
168
+
169
+ if (config.select && config.select.length > 0) {
170
+ query.select = config.select as any;
171
+ }
172
+
173
+ const relations = query.relations;
174
+ delete query.relations;
175
+
176
+ return {
177
+ query: query,
178
+ relations: relations,
179
+ q
180
+ };*/
181
+ }
182
+ async retrieveByHandle(productHandle, config = {}) {
183
+ var _a;
184
+ const storeBasedConfig = ((_a = config.relations) === null || _a === void 0 ? void 0 : _a.includes("stores"))
185
+ ? config
186
+ : {
187
+ ...config,
188
+ relations: config.relations
189
+ ? config.relations.concat("stores")
190
+ : ["stores"]
191
+ };
192
+ return await this.retrieve_({ handle: productHandle }, storeBasedConfig);
193
+ }
194
+ /**
195
+ * Gets a product by external id.
196
+ * Throws in case of DB Error and if product was not found.
197
+ * @param externalId - handle of the product to get.
198
+ * @param config - details about what to get from the product
199
+ * @param store_id - the store id to reference
200
+ * @return the result of the find one operation.
201
+ */
202
+ async retrieveByExternalId(externalId, config = {}) {
203
+ var _a;
204
+ const storeBasedConfig = ((_a = config.relations) === null || _a === void 0 ? void 0 : _a.includes("stores"))
205
+ ? config
206
+ : {
207
+ ...config,
208
+ relations: config.relations
209
+ ? config.relations.concat("stores")
210
+ : ["stores"]
211
+ };
212
+ return await this.retrieve_({ external_id: externalId }, storeBasedConfig);
213
+ }
214
+ /**
215
+ * Lists products based on the provided parameters and includes the count of
216
+ * products that match the query.
217
+ * @param selector - an object that defines rules to filter products
218
+ * by
219
+ * @param config - object that defines the scope for what should be
220
+ * returned
221
+ * @return an array containing the products as
222
+ * the first element and the total count of products that matches the query
223
+ * as the second element.
224
+ */
225
+ /* async listAndCount(
226
+ selector: ProductSelector,
227
+ config: FindProductConfig = {
228
+ relations: [],
229
+ skip: 0,
230
+ take: 20,
231
+ include_discount_prices: false
232
+ }
233
+ ): Promise<[Product[], number]> {
234
+ const productRepo = this.activeManager_.withRepository(
235
+ this.productRepository_
236
+ );
237
+ this.logger.debug(`listAndCount:selector:${JSON.stringify(selector)}`);
238
+ this.logger.debug(`listAndCount:config:${JSON.stringify(config)}`);
239
+
240
+ const { q, query, relations } = this.prepareListQuery_(
241
+ selector,
242
+ config
243
+ );
244
+
245
+ const { where, ...queryWithoutWhere } = query;
246
+
247
+ let result;
248
+ if (q) {
249
+ result = await productRepo.findAndCount({
250
+ where: { id: q },
251
+ ...queryWithoutWhere,
252
+ relations
253
+ });
254
+ } else {
255
+ result = await productRepo.findAndCount({
256
+ relations,
257
+ ...query
258
+ });
259
+ }
260
+ return result;
261
+ }*/
262
+ async listAndCount(selector, config = {
263
+ relations: [],
264
+ skip: 0,
265
+ take: 20,
266
+ include_discount_prices: false
267
+ }) {
268
+ return await this.atomicPhase_(async (manager) => {
269
+ var _a, _b;
270
+ const productRepo = manager.getRepository(product_1.Product);
271
+ if (!((_a = config.relations) === null || _a === void 0 ? void 0 : _a.includes("stores"))) {
272
+ (_b = config.relations) === null || _b === void 0 ? void 0 : _b.push("stores");
273
+ }
274
+ else if (!config.relations) {
275
+ config.relations = ["stores"];
276
+ }
277
+ this.logger.debug(`listAndCount:selector:${JSON.stringify(selector)}`);
278
+ this.logger.debug(`listAndCount:config:${JSON.stringify(config)}`);
279
+ const result = (await super.listAndCount(selector, config));
280
+ /* const result = (await super.listAndCount(
281
+ selector,
282
+ config as any
283
+ )) as [Product[], number];
284
+ /* const { q, ...productSelector } = selector;
285
+ const query = buildQuery(
286
+ productSelector,
287
+ config
288
+ ) as ExtendedFindConfig<Product & ProductFilterOptions>;
289
+ */
290
+ // const result = (await productRepo.findAndCount(query))
291
+ return result;
292
+ });
293
+ }
294
+ getStoreActiveUsers() {
295
+ let user = Object.keys(this.container).includes("loggedInUser")
296
+ ? this.container.loggedInUser
297
+ : undefined;
298
+ const defaultAdmin = Object.keys(this.container).includes("defaultAdmin")
299
+ ? this.container.defaultAdmin
300
+ : undefined;
301
+ if (defaultAdmin) {
302
+ const defaultAdminUser = Array.isArray(defaultAdmin)
303
+ ? this.container.defaultAdmin[0]
304
+ : this.container.defaultAdmin;
305
+ user = user !== null && user !== void 0 ? user : defaultAdminUser;
306
+ }
307
+ return { user, adminUser: defaultAdmin };
308
+ }
309
+ async create(productObject) {
310
+ const storeId = productObject.store_id;
311
+ delete productObject.store_id;
312
+ return this.atomicPhase_(async (manager) => {
313
+ let product = (await super.create(productObject));
314
+ product = await this.withTransaction(manager).associateProductWithStore(product, storeId);
315
+ return product;
316
+ });
317
+ }
318
+ async associateProductWithStore(product, storeId) {
319
+ const defaultStoreName = process.env.DEFAULT_STORE_NAME;
320
+ try {
321
+ return this.atomicPhase_(async (manager) => {
322
+ if (storeId) {
323
+ const productRepo = manager.getRepository(product_1.Product);
324
+ const store = await this.storeService
325
+ .withTransaction(manager)
326
+ .retrieveByStoreIdOrName(storeId);
327
+ const defaultStore = await this.storeService
328
+ .withTransaction(manager)
329
+ .retrieveByStoreIdOrName(defaultStoreName);
330
+ const stores = store.id != defaultStore.id
331
+ ? [store, defaultStore]
332
+ : [store];
333
+ product.stores = product.stores
334
+ ? product.stores.concat(stores)
335
+ : stores;
336
+ return (product = await productRepo.save(product));
337
+ }
338
+ });
339
+ }
340
+ catch (e) {
341
+ this.logger.error(`unable to associate ${product.title} with ${storeId},` +
342
+ `because ${e.message}`);
343
+ return product;
344
+ }
345
+ }
346
+ async dissociateProductFromStore(product, storeId) {
347
+ const defaultStoreName = process.env.DEFAULT_STORE_NAME;
348
+ try {
349
+ return this.atomicPhase_(async (manager) => {
350
+ if (storeId) {
351
+ const productRepo = manager.getRepository(product_1.Product);
352
+ const defaultStore = await this.storeService
353
+ .withTransaction(manager)
354
+ .retrieveByStoreIdOrName(defaultStoreName);
355
+ const store = product.stores.findIndex((store) => store.id == storeId && store.id != defaultStore.id);
356
+ if (storeId == defaultStore.id) {
357
+ this.logger.error("attempting to disassociate from default store");
358
+ return product;
359
+ }
360
+ if (store != -1) {
361
+ product.stores.splice(store, 1);
362
+ }
363
+ return (product = await productRepo.save(product));
364
+ }
365
+ });
366
+ }
367
+ catch (e) {
368
+ this.logger.error(`unable to associate ${product.title} with ${storeId},` +
369
+ `because ${e.message}`);
370
+ return product;
371
+ }
372
+ }
373
+ };
374
+ _ProductService_manager = new WeakMap();
375
+ ProductService.LIFE_TIME = awilix_1.Lifetime.TRANSIENT;
376
+ ProductService = ProductService_1 = __decorate([
377
+ (0, typeorm_1.EventSubscriber)(),
378
+ __metadata("design:paramtypes", [Object])
379
+ ], ProductService);
380
+ exports.ProductService = ProductService;
381
+ exports.default = ProductService;
382
+ //# sourceMappingURL=product.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product.js","sourceRoot":"","sources":["../../src/services/product.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,4BAA4B;AAC5B,kCAAkC;AAClC,qCAOiB;AACjB,mCAAkC;AAClC,6DAMwC;AACxC,+CAA4C;AAgB5C,uDAAyD;AACzD,yDAAgD;AAyDzC,IAAM,cAAc,sBAApB,MAAM,cAAe,SAAQ,yBAAoB;IA0BpD,YAAqB,SAA4B;QAC7C,KAAK,CAAC,SAAS,CAAC,CAAC;QADA,cAAS,GAAT,SAAS,CAAmB;QAvBjD,0CAAiC;QAyB7B,uBAAA,IAAI,2BAAY,SAAS,CAAC,OAAO,MAAA,CA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OAAO,CAAC,KAAK,SAAS,OAAO,GAAG;gBACnD,WAAW,CAAC,CAAC,OAAO,EAAE,CAC7B,CAAC;YACF,OAAO,OAAO,CAAC;SAClB;IACL,CAAC;;;AA/bM,wBAAS,GAAG,iBAAQ,CAAC,SAAS,CAAC;AAD7B,cAAc;IAD1B,IAAA,yBAAe,GAAE;;GACL,cAAc,CAic1B;AAjcY,wCAAc;AAmc3B,kBAAe,cAAc,CAAC"}
@@ -0,0 +1,42 @@
1
+ import { CurrencyRepository } from "../repositories/currency";
2
+ import { EntityManager, InsertEvent, UpdateEvent } from "typeorm";
3
+ import EventBusService from "@medusajs/medusa/dist/services/event-bus";
4
+ import { FulfillmentProviderService, RegionService as MedusaRegionService, PaymentProviderService } from "@medusajs/medusa/dist/services";
5
+ import { CountryRepository } from "@medusajs/medusa/dist/repositories/country";
6
+ import { RegionRepository } from "@medusajs/medusa/dist/repositories/region";
7
+ import { Region } from "@medusajs/medusa";
8
+ import { TaxProviderRepository } from "@medusajs/medusa/dist/repositories/tax-provider";
9
+ import { PaymentProviderRepository } from "@medusajs/medusa/dist/repositories/payment-provider";
10
+ import { FulfillmentProviderRepository } from "@medusajs/medusa/dist/repositories/fulfillment-provider";
11
+ import { Logger } from "@medusajs/medusa/dist/types/global";
12
+ import StoreService from "./store";
13
+ import { Store } from "../models/store";
14
+ interface ConstructorParams {
15
+ manager: EntityManager;
16
+ regionRepository: typeof RegionRepository;
17
+ countryRepository: typeof CountryRepository;
18
+ currencyRepository: typeof CurrencyRepository;
19
+ eventBusService: EventBusService;
20
+ storeService: StoreService;
21
+ paymentProviderService: PaymentProviderService;
22
+ fulfillmentProviderService: FulfillmentProviderService;
23
+ featureFlagRouter: any;
24
+ taxProviderRepository: typeof TaxProviderRepository;
25
+ paymentProviderRepository: typeof PaymentProviderRepository;
26
+ fulfillmentProviderRepository: typeof FulfillmentProviderRepository;
27
+ logger: Logger;
28
+ }
29
+ export default class RegionService extends MedusaRegionService {
30
+ readonly container: ConstructorParams;
31
+ private readonly manager;
32
+ private readonly regionRepository;
33
+ protected storeService_: StoreService;
34
+ logger: Logger;
35
+ constructor(container: ConstructorParams);
36
+ withTransaction(transactionManager: EntityManager): this;
37
+ createDefaultRegion(event: UpdateEvent<Store>): Promise<UpdateEvent<Store>>;
38
+ createNewRegion(name?: string): Promise<Region>;
39
+ updateDefaultRegion(defaultRegion: Region): Promise<Region>;
40
+ verifyOrCreateDefaultRegion(event: UpdateEvent<Store> | InsertEvent<Store>): Promise<UpdateEvent<Store> | InsertEvent<Store>>;
41
+ }
42
+ export {};