@medusajs/customer 0.0.2 → 0.0.3-next-20240429170320
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.
- package/dist/joiner-config.d.ts +1 -0
- package/dist/joiner-config.js +22 -5
- package/dist/loaders/container.js +3 -2
- package/dist/models/address.js +9 -0
- package/dist/models/customer-group.js +1 -0
- package/dist/models/customer.d.ts +1 -1
- package/dist/models/customer.js +6 -1
- package/dist/repositories/index.d.ts +1 -0
- package/dist/repositories/index.js +5 -0
- package/dist/scripts/bin/run-seed.js +0 -0
- package/dist/services/customer-module.d.ts +0 -1
- package/dist/services/customer-module.js +9 -21
- package/package.json +5 -5
package/dist/joiner-config.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { MapToConfig } from "@medusajs/utils";
|
|
|
3
3
|
export declare const LinkableKeys: {
|
|
4
4
|
customer_id: string;
|
|
5
5
|
customer_group_id: string;
|
|
6
|
+
customer_address_id: string;
|
|
6
7
|
};
|
|
7
8
|
export declare const entityNameToLinkableKeysMap: MapToConfig;
|
|
8
9
|
export declare const joinerConfig: ModuleJoinerConfig;
|
package/dist/joiner-config.js
CHANGED
|
@@ -6,6 +6,7 @@ const _models_1 = require("./models");
|
|
|
6
6
|
exports.LinkableKeys = {
|
|
7
7
|
customer_id: _models_1.Customer.name,
|
|
8
8
|
customer_group_id: _models_1.CustomerGroup.name,
|
|
9
|
+
customer_address_id: _models_1.Address.name,
|
|
9
10
|
};
|
|
10
11
|
const entityLinkableKeysMap = {};
|
|
11
12
|
Object.entries(exports.LinkableKeys).forEach(([key, value]) => {
|
|
@@ -20,10 +21,26 @@ exports.joinerConfig = {
|
|
|
20
21
|
serviceName: modules_sdk_1.Modules.CUSTOMER,
|
|
21
22
|
primaryKeys: ["id"],
|
|
22
23
|
linkableKeys: exports.LinkableKeys,
|
|
23
|
-
alias:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
alias: [
|
|
25
|
+
{
|
|
26
|
+
name: ["customer", "customers"],
|
|
27
|
+
args: {
|
|
28
|
+
entity: _models_1.Customer.name,
|
|
29
|
+
},
|
|
27
30
|
},
|
|
28
|
-
|
|
31
|
+
{
|
|
32
|
+
name: ["customer_group", "customer_groups"],
|
|
33
|
+
args: {
|
|
34
|
+
entity: _models_1.CustomerGroup.name,
|
|
35
|
+
methodSuffix: "CustomerGroups",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: ["customer_address", "customer_addresses"],
|
|
40
|
+
args: {
|
|
41
|
+
entity: _models_1.Address.name,
|
|
42
|
+
methodSuffix: "Addresses",
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
],
|
|
29
46
|
};
|
|
@@ -23,11 +23,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const utils_1 = require("@medusajs/utils");
|
|
27
26
|
const ModuleModels = __importStar(require("../models"));
|
|
27
|
+
const CustomerRepositories = __importStar(require("../repositories"));
|
|
28
28
|
const ModuleServices = __importStar(require("../services"));
|
|
29
|
+
const utils_1 = require("@medusajs/utils");
|
|
29
30
|
exports.default = utils_1.ModulesSdkUtils.moduleContainerLoaderFactory({
|
|
30
31
|
moduleModels: ModuleModels,
|
|
31
32
|
moduleServices: ModuleServices,
|
|
32
|
-
moduleRepositories:
|
|
33
|
+
moduleRepositories: CustomerRepositories,
|
|
33
34
|
});
|
package/dist/models/address.js
CHANGED
|
@@ -47,6 +47,7 @@ __decorate([
|
|
|
47
47
|
__metadata("design:type", String)
|
|
48
48
|
], Address.prototype, "id", void 0);
|
|
49
49
|
__decorate([
|
|
50
|
+
(0, utils_1.Searchable)(),
|
|
50
51
|
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
51
52
|
__metadata("design:type", Object)
|
|
52
53
|
], Address.prototype, "address_name", void 0);
|
|
@@ -71,26 +72,32 @@ __decorate([
|
|
|
71
72
|
__metadata("design:type", customer_1.default)
|
|
72
73
|
], Address.prototype, "customer", void 0);
|
|
73
74
|
__decorate([
|
|
75
|
+
(0, utils_1.Searchable)(),
|
|
74
76
|
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
75
77
|
__metadata("design:type", Object)
|
|
76
78
|
], Address.prototype, "company", void 0);
|
|
77
79
|
__decorate([
|
|
80
|
+
(0, utils_1.Searchable)(),
|
|
78
81
|
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
79
82
|
__metadata("design:type", Object)
|
|
80
83
|
], Address.prototype, "first_name", void 0);
|
|
81
84
|
__decorate([
|
|
85
|
+
(0, utils_1.Searchable)(),
|
|
82
86
|
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
83
87
|
__metadata("design:type", Object)
|
|
84
88
|
], Address.prototype, "last_name", void 0);
|
|
85
89
|
__decorate([
|
|
90
|
+
(0, utils_1.Searchable)(),
|
|
86
91
|
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
87
92
|
__metadata("design:type", Object)
|
|
88
93
|
], Address.prototype, "address_1", void 0);
|
|
89
94
|
__decorate([
|
|
95
|
+
(0, utils_1.Searchable)(),
|
|
90
96
|
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
91
97
|
__metadata("design:type", Object)
|
|
92
98
|
], Address.prototype, "address_2", void 0);
|
|
93
99
|
__decorate([
|
|
100
|
+
(0, utils_1.Searchable)(),
|
|
94
101
|
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
95
102
|
__metadata("design:type", Object)
|
|
96
103
|
], Address.prototype, "city", void 0);
|
|
@@ -99,10 +106,12 @@ __decorate([
|
|
|
99
106
|
__metadata("design:type", Object)
|
|
100
107
|
], Address.prototype, "country_code", void 0);
|
|
101
108
|
__decorate([
|
|
109
|
+
(0, utils_1.Searchable)(),
|
|
102
110
|
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
103
111
|
__metadata("design:type", Object)
|
|
104
112
|
], Address.prototype, "province", void 0);
|
|
105
113
|
__decorate([
|
|
114
|
+
(0, utils_1.Searchable)(),
|
|
106
115
|
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
107
116
|
__metadata("design:type", Object)
|
|
108
117
|
], Address.prototype, "postal_code", void 0);
|
|
@@ -36,6 +36,7 @@ __decorate([
|
|
|
36
36
|
__metadata("design:type", String)
|
|
37
37
|
], CustomerGroup.prototype, "id", void 0);
|
|
38
38
|
__decorate([
|
|
39
|
+
(0, utils_1.Searchable)(),
|
|
39
40
|
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
40
41
|
__metadata("design:type", Object)
|
|
41
42
|
], CustomerGroup.prototype, "name", void 0);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DAL } from "@medusajs/types";
|
|
2
2
|
import { Collection, OptionalProps } from "@mikro-orm/core";
|
|
3
|
-
import CustomerGroup from "./customer-group";
|
|
4
3
|
import Address from "./address";
|
|
4
|
+
import CustomerGroup from "./customer-group";
|
|
5
5
|
type OptionalCustomerProps = "groups" | "addresses" | DAL.SoftDeletableEntityDateColumns;
|
|
6
6
|
export default class Customer {
|
|
7
7
|
[OptionalProps]?: OptionalCustomerProps;
|
package/dist/models/customer.js
CHANGED
|
@@ -14,9 +14,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const utils_1 = require("@medusajs/utils");
|
|
16
16
|
const core_1 = require("@mikro-orm/core");
|
|
17
|
+
const address_1 = __importDefault(require("./address"));
|
|
17
18
|
const customer_group_1 = __importDefault(require("./customer-group"));
|
|
18
19
|
const customer_group_customer_1 = __importDefault(require("./customer-group-customer"));
|
|
19
|
-
const address_1 = __importDefault(require("./address"));
|
|
20
20
|
let Customer = class Customer {
|
|
21
21
|
constructor() {
|
|
22
22
|
this.company_name = null;
|
|
@@ -43,22 +43,27 @@ __decorate([
|
|
|
43
43
|
__metadata("design:type", String)
|
|
44
44
|
], Customer.prototype, "id", void 0);
|
|
45
45
|
__decorate([
|
|
46
|
+
(0, utils_1.Searchable)(),
|
|
46
47
|
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
47
48
|
__metadata("design:type", Object)
|
|
48
49
|
], Customer.prototype, "company_name", void 0);
|
|
49
50
|
__decorate([
|
|
51
|
+
(0, utils_1.Searchable)(),
|
|
50
52
|
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
51
53
|
__metadata("design:type", Object)
|
|
52
54
|
], Customer.prototype, "first_name", void 0);
|
|
53
55
|
__decorate([
|
|
56
|
+
(0, utils_1.Searchable)(),
|
|
54
57
|
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
55
58
|
__metadata("design:type", Object)
|
|
56
59
|
], Customer.prototype, "last_name", void 0);
|
|
57
60
|
__decorate([
|
|
61
|
+
(0, utils_1.Searchable)(),
|
|
58
62
|
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
59
63
|
__metadata("design:type", Object)
|
|
60
64
|
], Customer.prototype, "email", void 0);
|
|
61
65
|
__decorate([
|
|
66
|
+
(0, utils_1.Searchable)(),
|
|
62
67
|
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
63
68
|
__metadata("design:type", Object)
|
|
64
69
|
], Customer.prototype, "phone", void 0);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MikroOrmBaseRepository as BaseRepository } from "@medusajs/utils";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseRepository = void 0;
|
|
4
|
+
var utils_1 = require("@medusajs/utils");
|
|
5
|
+
Object.defineProperty(exports, "BaseRepository", { enumerable: true, get: function () { return utils_1.MikroOrmBaseRepository; } });
|
|
File without changes
|
|
@@ -54,6 +54,5 @@ export default class CustomerModuleService<TAddress extends Address = Address, T
|
|
|
54
54
|
removeCustomerFromGroup(groupCustomerPair: CustomerTypes.GroupCustomerPair, sharedContext?: Context): Promise<void>;
|
|
55
55
|
removeCustomerFromGroup(groupCustomerPairs: CustomerTypes.GroupCustomerPair[], sharedContext?: Context): Promise<void>;
|
|
56
56
|
private flush;
|
|
57
|
-
private handleDbErrors;
|
|
58
57
|
}
|
|
59
58
|
export {};
|
|
@@ -16,11 +16,12 @@ const types_1 = require("@medusajs/types");
|
|
|
16
16
|
const utils_1 = require("@medusajs/utils");
|
|
17
17
|
const joiner_config_1 = require("../joiner-config");
|
|
18
18
|
const _models_1 = require("../models");
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
const generateMethodForModels = [
|
|
20
|
+
{ model: _models_1.Address, singular: "Address", plural: "Addresses" },
|
|
21
|
+
_models_1.CustomerGroup,
|
|
22
|
+
_models_1.CustomerGroupCustomer,
|
|
23
|
+
];
|
|
24
|
+
class CustomerModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFactory(_models_1.Customer, generateMethodForModels, joiner_config_1.entityNameToLinkableKeysMap) {
|
|
24
25
|
constructor({ baseRepository, customerService, addressService, customerGroupService, customerGroupCustomerService, }, moduleDeclaration) {
|
|
25
26
|
// @ts-ignore
|
|
26
27
|
super(...arguments);
|
|
@@ -35,7 +36,7 @@ class CustomerModuleService
|
|
|
35
36
|
return joiner_config_1.joinerConfig;
|
|
36
37
|
}
|
|
37
38
|
async create(dataOrArray, sharedContext = {}) {
|
|
38
|
-
const customers = await this.create_(dataOrArray, sharedContext)
|
|
39
|
+
const customers = await this.create_(dataOrArray, sharedContext);
|
|
39
40
|
const serialized = await this.baseRepository_.serialize(customers, {
|
|
40
41
|
populate: true,
|
|
41
42
|
});
|
|
@@ -121,7 +122,7 @@ class CustomerModuleService
|
|
|
121
122
|
return { id: groupCustomers.id };
|
|
122
123
|
}
|
|
123
124
|
async addAddresses(data, sharedContext = {}) {
|
|
124
|
-
const addresses = await this.addAddresses_(data, sharedContext)
|
|
125
|
+
const addresses = await this.addAddresses_(data, sharedContext);
|
|
125
126
|
const serialized = await this.baseRepository_.serialize(addresses, { populate: true });
|
|
126
127
|
if (Array.isArray(data)) {
|
|
127
128
|
return serialized;
|
|
@@ -154,7 +155,7 @@ class CustomerModuleService
|
|
|
154
155
|
};
|
|
155
156
|
}
|
|
156
157
|
const addresses = await this.addressService_.update(updateData, sharedContext);
|
|
157
|
-
await this.flush(sharedContext)
|
|
158
|
+
await this.flush(sharedContext);
|
|
158
159
|
const serialized = await this.baseRepository_.serialize(addresses, { populate: true });
|
|
159
160
|
if ((0, utils_1.isString)(addressIdOrSelector)) {
|
|
160
161
|
return serialized[0];
|
|
@@ -172,19 +173,6 @@ class CustomerModuleService
|
|
|
172
173
|
const em = (context.manager ?? context.transactionManager);
|
|
173
174
|
await em.flush();
|
|
174
175
|
}
|
|
175
|
-
async handleDbErrors(err) {
|
|
176
|
-
if ((0, utils_1.isDuplicateError)(err)) {
|
|
177
|
-
switch (err.constraint) {
|
|
178
|
-
case address_1.UNIQUE_CUSTOMER_SHIPPING_ADDRESS:
|
|
179
|
-
throw new utils_1.MedusaError(utils_1.MedusaError.Types.DUPLICATE_ERROR, "A default shipping address already exists");
|
|
180
|
-
case address_1.UNIQUE_CUSTOMER_BILLING_ADDRESS:
|
|
181
|
-
throw new utils_1.MedusaError(utils_1.MedusaError.Types.DUPLICATE_ERROR, "A default billing address already exists");
|
|
182
|
-
default:
|
|
183
|
-
break;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
throw err;
|
|
187
|
-
}
|
|
188
176
|
}
|
|
189
177
|
exports.default = CustomerModuleService;
|
|
190
178
|
__decorate([
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medusajs/customer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3-next-20240429170320",
|
|
4
4
|
"description": "Medusa Customer module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"watch:test": "tsc --build tsconfig.spec.json --watch",
|
|
29
29
|
"prepublishOnly": "cross-env NODE_ENV=production tsc --build && tsc-alias -p tsconfig.json",
|
|
30
30
|
"build": "rimraf dist && tsc --build && tsc-alias -p tsconfig.json",
|
|
31
|
-
"test": "jest --runInBand --bail --forceExit -- src
|
|
31
|
+
"test": "jest --runInBand --bail --passWithNoTests --forceExit -- src",
|
|
32
32
|
"test:integration": "jest --forceExit -- integration-tests/**/__tests__/**/*.ts",
|
|
33
33
|
"migration:generate": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:generate",
|
|
34
34
|
"migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:create --initial",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@mikro-orm/cli": "5.9.7",
|
|
42
42
|
"cross-env": "^5.2.1",
|
|
43
43
|
"jest": "^29.6.3",
|
|
44
|
-
"medusa-test-utils": "
|
|
44
|
+
"medusa-test-utils": "1.1.44-next-20240429170320",
|
|
45
45
|
"rimraf": "^3.0.2",
|
|
46
46
|
"ts-jest": "^29.1.1",
|
|
47
47
|
"ts-node": "^10.9.1",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"typescript": "^5.1.6"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@medusajs/modules-sdk": "
|
|
53
|
-
"@medusajs/utils": "
|
|
52
|
+
"@medusajs/modules-sdk": "1.12.11-next-20240429170320",
|
|
53
|
+
"@medusajs/utils": "1.12.0-next-20240429170320",
|
|
54
54
|
"@mikro-orm/core": "5.9.7",
|
|
55
55
|
"@mikro-orm/migrations": "5.9.7",
|
|
56
56
|
"@mikro-orm/postgresql": "5.9.7",
|