@medusajs/customer 0.0.1

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 (46) hide show
  1. package/README.md +8 -0
  2. package/dist/index.d.ts +4 -0
  3. package/dist/index.js +22 -0
  4. package/dist/initialize/index.d.ts +4 -0
  5. package/dist/initialize/index.js +16 -0
  6. package/dist/joiner-config.d.ts +7 -0
  7. package/dist/joiner-config.js +28 -0
  8. package/dist/loaders/connection.d.ts +4 -0
  9. package/dist/loaders/connection.js +41 -0
  10. package/dist/loaders/container.d.ts +2 -0
  11. package/dist/loaders/container.js +33 -0
  12. package/dist/loaders/index.d.ts +2 -0
  13. package/dist/loaders/index.js +18 -0
  14. package/dist/models/address.d.ts +26 -0
  15. package/dist/models/address.js +130 -0
  16. package/dist/models/customer-group-customer.d.ts +20 -0
  17. package/dist/models/customer-group-customer.js +101 -0
  18. package/dist/models/customer-group.d.ts +17 -0
  19. package/dist/models/customer-group.js +88 -0
  20. package/dist/models/customer.d.ts +28 -0
  21. package/dist/models/customer.js +148 -0
  22. package/dist/models/index.d.ts +4 -0
  23. package/dist/models/index.js +14 -0
  24. package/dist/module-definition.d.ts +4 -0
  25. package/dist/module-definition.js +50 -0
  26. package/dist/scripts/bin/run-seed.d.ts +3 -0
  27. package/dist/scripts/bin/run-seed.js +38 -0
  28. package/dist/scripts/seed.d.ts +4 -0
  29. package/dist/scripts/seed.js +54 -0
  30. package/dist/services/address.d.ts +18 -0
  31. package/dist/services/address.js +11 -0
  32. package/dist/services/customer-group-customer.d.ts +21 -0
  33. package/dist/services/customer-group-customer.js +11 -0
  34. package/dist/services/customer-group.d.ts +18 -0
  35. package/dist/services/customer-group.js +11 -0
  36. package/dist/services/customer-module.d.ts +46 -0
  37. package/dist/services/customer-module.js +253 -0
  38. package/dist/services/customer.d.ts +17 -0
  39. package/dist/services/customer.js +11 -0
  40. package/dist/services/index.d.ts +5 -0
  41. package/dist/services/index.js +16 -0
  42. package/dist/types/address.d.ts +27 -0
  43. package/dist/types/address.js +2 -0
  44. package/dist/types/index.d.ts +5 -0
  45. package/dist/types/index.js +17 -0
  46. package/package.json +61 -0
@@ -0,0 +1,253 @@
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 __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const types_1 = require("@medusajs/types");
16
+ const utils_1 = require("@medusajs/utils");
17
+ const joiner_config_1 = require("../joiner-config");
18
+ class CustomerModuleService {
19
+ constructor({ baseRepository, customerService, addressService, customerGroupService, customerGroupCustomerService, }, moduleDeclaration) {
20
+ this.moduleDeclaration = moduleDeclaration;
21
+ this.baseRepository_ = baseRepository;
22
+ this.customerService_ = customerService;
23
+ this.addressService_ = addressService;
24
+ this.customerGroupService_ = customerGroupService;
25
+ this.customerGroupCustomerService_ = customerGroupCustomerService;
26
+ }
27
+ __joinerConfig() {
28
+ return joiner_config_1.joinerConfig;
29
+ }
30
+ async retrieve(id, config = {}, sharedContext = {}) {
31
+ const customer = await this.customerService_.retrieve(id, config, sharedContext);
32
+ return await this.baseRepository_.serialize(customer, {
33
+ populate: true,
34
+ });
35
+ }
36
+ async create(dataOrArray, sharedContext = {}) {
37
+ const data = Array.isArray(dataOrArray) ? dataOrArray : [dataOrArray];
38
+ const customer = await this.customerService_.create(data, sharedContext);
39
+ const serialized = await this.baseRepository_.serialize(customer, {
40
+ populate: true,
41
+ });
42
+ return Array.isArray(dataOrArray) ? serialized : serialized[0];
43
+ }
44
+ async update(idsOrSelector, data, sharedContext = {}) {
45
+ let updateData = [];
46
+ if ((0, utils_1.isString)(idsOrSelector)) {
47
+ updateData = [
48
+ {
49
+ id: idsOrSelector,
50
+ ...data,
51
+ },
52
+ ];
53
+ }
54
+ else if (Array.isArray(idsOrSelector)) {
55
+ updateData = idsOrSelector.map((id) => ({
56
+ id,
57
+ ...data,
58
+ }));
59
+ }
60
+ else {
61
+ const ids = await this.customerService_.list(idsOrSelector, { select: ["id"] }, sharedContext);
62
+ updateData = ids.map(({ id }) => ({
63
+ id,
64
+ ...data,
65
+ }));
66
+ }
67
+ const customers = await this.customerService_.update(updateData, sharedContext);
68
+ const serialized = await this.baseRepository_.serialize(customers, {
69
+ populate: true,
70
+ });
71
+ return (0, utils_1.isString)(idsOrSelector) ? serialized[0] : serialized;
72
+ }
73
+ async delete(idsOrSelector, sharedContext = {}) {
74
+ let toDelete = Array.isArray(idsOrSelector)
75
+ ? idsOrSelector
76
+ : [idsOrSelector];
77
+ if ((0, utils_1.isObject)(idsOrSelector)) {
78
+ const ids = await this.customerService_.list(idsOrSelector, {
79
+ select: ["id"],
80
+ }, sharedContext);
81
+ toDelete = ids.map(({ id }) => id);
82
+ }
83
+ return await this.customerService_.delete(toDelete, sharedContext);
84
+ }
85
+ async list(filters = {}, config = {}, sharedContext = {}) {
86
+ const customers = await this.customerService_.list(filters, config, sharedContext);
87
+ return await this.baseRepository_.serialize(customers, {
88
+ populate: true,
89
+ });
90
+ }
91
+ async listAndCount(filters = {}, config = {}, sharedContext = {}) {
92
+ const [customers, count] = await this.customerService_.listAndCount(filters, config, sharedContext);
93
+ return [
94
+ await this.baseRepository_.serialize(customers, {
95
+ populate: true,
96
+ }),
97
+ count,
98
+ ];
99
+ }
100
+ async createCustomerGroup(dataOrArrayOfData, sharedContext = {}) {
101
+ const data = Array.isArray(dataOrArrayOfData)
102
+ ? dataOrArrayOfData
103
+ : [dataOrArrayOfData];
104
+ const groups = await this.customerGroupService_.create(data, sharedContext);
105
+ const serialized = await this.baseRepository_.serialize(groups, {
106
+ populate: true,
107
+ });
108
+ return Array.isArray(dataOrArrayOfData) ? serialized : serialized[0];
109
+ }
110
+ async updateCustomerGroup(groupIdOrSelector, data, sharedContext = {}) {
111
+ let updateData = [];
112
+ if ((0, utils_1.isString)(groupIdOrSelector)) {
113
+ updateData = [
114
+ {
115
+ id: groupIdOrSelector,
116
+ ...data,
117
+ },
118
+ ];
119
+ }
120
+ else if (Array.isArray(groupIdOrSelector)) {
121
+ updateData = groupIdOrSelector.map((id) => ({
122
+ id,
123
+ ...data,
124
+ }));
125
+ }
126
+ else {
127
+ const ids = await this.customerGroupService_.list(groupIdOrSelector, { select: ["id"] }, sharedContext);
128
+ updateData = ids.map(({ id }) => ({
129
+ id,
130
+ ...data,
131
+ }));
132
+ }
133
+ const groups = await this.customerGroupService_.update(updateData, sharedContext);
134
+ if ((0, utils_1.isString)(groupIdOrSelector)) {
135
+ return await this.baseRepository_.serialize(groups[0], { populate: true });
136
+ }
137
+ return await this.baseRepository_.serialize(groups, { populate: true });
138
+ }
139
+ async addCustomerToGroup(data, sharedContext = {}) {
140
+ const groupCustomers = await this.customerGroupCustomerService_.create(Array.isArray(data) ? data : [data], sharedContext);
141
+ if (Array.isArray(data)) {
142
+ return groupCustomers.map((gc) => ({ id: gc.id }));
143
+ }
144
+ return { id: groupCustomers[0].id };
145
+ }
146
+ async removeCustomerFromGroup(data, sharedContext = {}) {
147
+ const pairs = Array.isArray(data) ? data : [data];
148
+ const groupCustomers = await this.customerGroupCustomerService_.list({
149
+ $or: pairs,
150
+ });
151
+ await this.customerGroupCustomerService_.delete(groupCustomers.map((gc) => gc.id), sharedContext);
152
+ }
153
+ async listCustomerGroups(filters = {}, config = {}, sharedContext = {}) {
154
+ const groups = await this.customerGroupService_.list(filters, config, sharedContext);
155
+ return await this.baseRepository_.serialize(groups, {
156
+ populate: true,
157
+ });
158
+ }
159
+ async listAndCountCustomerGroups(filters = {}, config = {}, sharedContext = {}) {
160
+ const [groups, count] = await this.customerGroupService_.listAndCount(filters, config, sharedContext);
161
+ return [
162
+ await this.baseRepository_.serialize(groups, {
163
+ populate: true,
164
+ }),
165
+ count,
166
+ ];
167
+ }
168
+ }
169
+ exports.default = CustomerModuleService;
170
+ __decorate([
171
+ (0, utils_1.InjectManager)("baseRepository_"),
172
+ __param(2, (0, utils_1.MedusaContext)()),
173
+ __metadata("design:type", Function),
174
+ __metadata("design:paramtypes", [String, Object, Object]),
175
+ __metadata("design:returntype", Promise)
176
+ ], CustomerModuleService.prototype, "retrieve", null);
177
+ __decorate([
178
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
179
+ __param(1, (0, utils_1.MedusaContext)()),
180
+ __metadata("design:type", Function),
181
+ __metadata("design:paramtypes", [Object, Object]),
182
+ __metadata("design:returntype", Promise)
183
+ ], CustomerModuleService.prototype, "create", null);
184
+ __decorate([
185
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
186
+ __param(2, (0, utils_1.MedusaContext)()),
187
+ __metadata("design:type", Function),
188
+ __metadata("design:paramtypes", [Object, Object, Object]),
189
+ __metadata("design:returntype", Promise)
190
+ ], CustomerModuleService.prototype, "update", null);
191
+ __decorate([
192
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
193
+ __param(1, (0, utils_1.MedusaContext)()),
194
+ __metadata("design:type", Function),
195
+ __metadata("design:paramtypes", [Object, Object]),
196
+ __metadata("design:returntype", Promise)
197
+ ], CustomerModuleService.prototype, "delete", null);
198
+ __decorate([
199
+ (0, utils_1.InjectManager)("baseRepository_"),
200
+ __param(2, (0, utils_1.MedusaContext)()),
201
+ __metadata("design:type", Function),
202
+ __metadata("design:paramtypes", [Object, Object, Object]),
203
+ __metadata("design:returntype", Promise)
204
+ ], CustomerModuleService.prototype, "list", null);
205
+ __decorate([
206
+ (0, utils_1.InjectManager)("baseRepository_"),
207
+ __param(2, (0, utils_1.MedusaContext)()),
208
+ __metadata("design:type", Function),
209
+ __metadata("design:paramtypes", [Object, Object, Object]),
210
+ __metadata("design:returntype", Promise)
211
+ ], CustomerModuleService.prototype, "listAndCount", null);
212
+ __decorate([
213
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
214
+ __param(1, (0, utils_1.MedusaContext)()),
215
+ __metadata("design:type", Function),
216
+ __metadata("design:paramtypes", [Object, Object]),
217
+ __metadata("design:returntype", Promise)
218
+ ], CustomerModuleService.prototype, "createCustomerGroup", null);
219
+ __decorate([
220
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
221
+ __param(2, (0, utils_1.MedusaContext)()),
222
+ __metadata("design:type", Function),
223
+ __metadata("design:paramtypes", [Object, Object, Object]),
224
+ __metadata("design:returntype", Promise)
225
+ ], CustomerModuleService.prototype, "updateCustomerGroup", null);
226
+ __decorate([
227
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
228
+ __param(1, (0, utils_1.MedusaContext)()),
229
+ __metadata("design:type", Function),
230
+ __metadata("design:paramtypes", [Object, Object]),
231
+ __metadata("design:returntype", Promise)
232
+ ], CustomerModuleService.prototype, "addCustomerToGroup", null);
233
+ __decorate([
234
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
235
+ __param(1, (0, utils_1.MedusaContext)()),
236
+ __metadata("design:type", Function),
237
+ __metadata("design:paramtypes", [Object, Object]),
238
+ __metadata("design:returntype", Promise)
239
+ ], CustomerModuleService.prototype, "removeCustomerFromGroup", null);
240
+ __decorate([
241
+ (0, utils_1.InjectManager)("baseRepository_"),
242
+ __param(2, (0, utils_1.MedusaContext)()),
243
+ __metadata("design:type", Function),
244
+ __metadata("design:paramtypes", [Object, Object, Object]),
245
+ __metadata("design:returntype", Promise)
246
+ ], CustomerModuleService.prototype, "listCustomerGroups", null);
247
+ __decorate([
248
+ (0, utils_1.InjectManager)("baseRepository_"),
249
+ __param(2, (0, utils_1.MedusaContext)()),
250
+ __metadata("design:type", Function),
251
+ __metadata("design:paramtypes", [Object, Object, Object]),
252
+ __metadata("design:returntype", Promise)
253
+ ], CustomerModuleService.prototype, "listAndCountCustomerGroups", null);
@@ -0,0 +1,17 @@
1
+ import { CustomerTypes, DAL } from "@medusajs/types";
2
+ import { ModulesSdkUtils } from "@medusajs/utils";
3
+ import { Customer } from "../models";
4
+ type InjectedDependencies = {
5
+ customerRepository: DAL.RepositoryService;
6
+ };
7
+ declare const CustomerService_base: new <TEntity_1 extends object = any>(container: InjectedDependencies) => ModulesSdkUtils.AbstractService<TEntity_1, InjectedDependencies, {
8
+ create: CustomerTypes.CreateCustomerDTO;
9
+ update: CustomerTypes.UpdateCustomerDTO;
10
+ }, {
11
+ list?: any;
12
+ listAndCount?: any;
13
+ }>;
14
+ export default class CustomerService<TEntity extends Customer = Customer> extends CustomerService_base<TEntity> {
15
+ constructor(container: InjectedDependencies);
16
+ }
17
+ export {};
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@medusajs/utils");
4
+ const _models_1 = require("../models");
5
+ class CustomerService extends utils_1.ModulesSdkUtils.abstractServiceFactory(_models_1.Customer) {
6
+ constructor(container) {
7
+ // @ts-ignore
8
+ super(...arguments);
9
+ }
10
+ }
11
+ exports.default = CustomerService;
@@ -0,0 +1,5 @@
1
+ export { default as AddressService } from "./address";
2
+ export { default as CustomerGroupService } from "./customer-group";
3
+ export { default as CustomerService } from "./customer";
4
+ export { default as CustomerModuleService } from "./customer-module";
5
+ export { default as CustomerGroupCustomerService } from "./customer-group-customer";
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CustomerGroupCustomerService = exports.CustomerModuleService = exports.CustomerService = exports.CustomerGroupService = exports.AddressService = void 0;
7
+ var address_1 = require("./address");
8
+ Object.defineProperty(exports, "AddressService", { enumerable: true, get: function () { return __importDefault(address_1).default; } });
9
+ var customer_group_1 = require("./customer-group");
10
+ Object.defineProperty(exports, "CustomerGroupService", { enumerable: true, get: function () { return __importDefault(customer_group_1).default; } });
11
+ var customer_1 = require("./customer");
12
+ Object.defineProperty(exports, "CustomerService", { enumerable: true, get: function () { return __importDefault(customer_1).default; } });
13
+ var customer_module_1 = require("./customer-module");
14
+ Object.defineProperty(exports, "CustomerModuleService", { enumerable: true, get: function () { return __importDefault(customer_module_1).default; } });
15
+ var customer_group_customer_1 = require("./customer-group-customer");
16
+ Object.defineProperty(exports, "CustomerGroupCustomerService", { enumerable: true, get: function () { return __importDefault(customer_group_customer_1).default; } });
@@ -0,0 +1,27 @@
1
+ export type CreateAddressDTO = {
2
+ customer_id: string;
3
+ company?: string | null;
4
+ first_name?: string | null;
5
+ last_name?: string | null;
6
+ address_1?: string | null;
7
+ address_2?: string | null;
8
+ city?: string | null;
9
+ country_code?: string | null;
10
+ province?: string | null;
11
+ postal_code?: string | null;
12
+ phone?: string | null;
13
+ metadata?: Record<string, unknown> | null;
14
+ };
15
+ export type UpdateAddressDTO = {
16
+ company?: string | null;
17
+ first_name?: string | null;
18
+ last_name?: string | null;
19
+ address_1?: string | null;
20
+ address_2?: string | null;
21
+ city?: string | null;
22
+ country_code?: string | null;
23
+ province?: string | null;
24
+ postal_code?: string | null;
25
+ phone?: string | null;
26
+ metadata?: Record<string, unknown> | null;
27
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import { Logger } from "@medusajs/types";
2
+ export * from "./address";
3
+ export type InitializeModuleInjectableDependencies = {
4
+ logger?: Logger;
5
+ };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./address"), exports);
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@medusajs/customer",
3
+ "version": "0.0.1",
4
+ "description": "Medusa Customer module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "engines": {
11
+ "node": ">=16"
12
+ },
13
+ "bin": {
14
+ "medusa-customer-seed": "dist/scripts/bin/run-seed.js"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/medusajs/medusa",
19
+ "directory": "packages/customer"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "author": "Medusa",
25
+ "license": "MIT",
26
+ "scripts": {
27
+ "watch": "tsc --build --watch",
28
+ "watch:test": "tsc --build tsconfig.spec.json --watch",
29
+ "prepublishOnly": "cross-env NODE_ENV=production tsc --build && tsc-alias -p tsconfig.json",
30
+ "build": "rimraf dist && tsc --build && tsc-alias -p tsconfig.json",
31
+ "test": "jest --runInBand --bail --forceExit -- src/**/__tests__/**/*.ts",
32
+ "test:integration": "jest --runInBand --forceExit -- integration-tests/**/__tests__/**/*.ts",
33
+ "migration:generate": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:generate",
34
+ "migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:create --initial",
35
+ "migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:create",
36
+ "migration:up": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:up",
37
+ "orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear"
38
+ },
39
+ "devDependencies": {
40
+ "@medusajs/types": "workspace:^",
41
+ "@mikro-orm/cli": "5.9.7",
42
+ "cross-env": "^5.2.1",
43
+ "jest": "^29.6.3",
44
+ "medusa-test-utils": "^1.1.40",
45
+ "rimraf": "^3.0.2",
46
+ "ts-jest": "^29.1.1",
47
+ "ts-node": "^10.9.1",
48
+ "tsc-alias": "^1.8.6",
49
+ "typescript": "^5.1.6"
50
+ },
51
+ "dependencies": {
52
+ "@medusajs/modules-sdk": "1.12.7-snapshot-20240123175817",
53
+ "@medusajs/utils": "1.11.4-snapshot-20240123175817",
54
+ "@mikro-orm/core": "5.9.7",
55
+ "@mikro-orm/migrations": "5.9.7",
56
+ "@mikro-orm/postgresql": "5.9.7",
57
+ "awilix": "^8.0.0",
58
+ "dotenv": "^16.1.4",
59
+ "knex": "2.4.2"
60
+ }
61
+ }