@medusajs/tax 0.1.0
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/README.md +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +28 -0
- package/dist/joiner-config.d.ts +5 -0
- package/dist/joiner-config.js +22 -0
- package/dist/models/index.d.ts +2 -0
- package/dist/models/index.js +10 -0
- package/dist/models/tax-rate.d.ts +22 -0
- package/dist/models/tax-rate.js +121 -0
- package/dist/models/tax-region.d.ts +20 -0
- package/dist/models/tax-region.js +116 -0
- package/dist/module-definition.d.ts +2 -0
- package/dist/module-definition.js +57 -0
- package/dist/scripts/bin/run-seed.d.ts +3 -0
- package/dist/scripts/bin/run-seed.js +48 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +8 -0
- package/dist/services/tax-module-service.d.ts +26 -0
- package/dist/services/tax-module-service.js +84 -0
- package/package.json +61 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Tax Module
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { moduleDefinition } from "./module-definition";
|
|
2
|
+
export * from "./models";
|
|
3
|
+
export * from "./services";
|
|
4
|
+
export declare const initialize: (options?: import("@medusajs/modules-sdk").InternalModuleDeclaration | import("@medusajs/modules-sdk").ModuleServiceInitializeOptions | import("@medusajs/modules-sdk").ModuleServiceInitializeCustomDataLayerOptions | import("@medusajs/modules-sdk").ExternalModuleDeclaration | undefined, injectedDependencies?: any) => Promise<unknown>;
|
|
5
|
+
export declare const runMigrations: ((options: import("@medusajs/modules-sdk").LoaderOptions<any>, moduleDeclaration?: import("@medusajs/modules-sdk").InternalModuleDeclaration | undefined) => Promise<void>) | undefined;
|
|
6
|
+
export declare const revertMigration: ((options: import("@medusajs/modules-sdk").LoaderOptions<any>, moduleDeclaration?: import("@medusajs/modules-sdk").InternalModuleDeclaration | undefined) => Promise<void>) | undefined;
|
|
7
|
+
export default moduleDefinition;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
exports.revertMigration = exports.runMigrations = exports.initialize = void 0;
|
|
18
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
19
|
+
const module_definition_1 = require("./module-definition");
|
|
20
|
+
__exportStar(require("./models"), exports);
|
|
21
|
+
__exportStar(require("./services"), exports);
|
|
22
|
+
exports.initialize = (0, modules_sdk_1.initializeFactory)({
|
|
23
|
+
moduleName: modules_sdk_1.Modules.TAX,
|
|
24
|
+
moduleDefinition: module_definition_1.moduleDefinition,
|
|
25
|
+
});
|
|
26
|
+
exports.runMigrations = module_definition_1.moduleDefinition.runMigrations;
|
|
27
|
+
exports.revertMigration = module_definition_1.moduleDefinition.revertMigration;
|
|
28
|
+
exports.default = module_definition_1.moduleDefinition;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ModuleJoinerConfig } from "@medusajs/types";
|
|
2
|
+
import { MapToConfig } from "@medusajs/utils";
|
|
3
|
+
export declare const LinkableKeys: Record<string, string>;
|
|
4
|
+
export declare const entityNameToLinkableKeysMap: MapToConfig;
|
|
5
|
+
export declare const joinerConfig: ModuleJoinerConfig;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.joinerConfig = exports.entityNameToLinkableKeysMap = exports.LinkableKeys = void 0;
|
|
4
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
5
|
+
exports.LinkableKeys = {
|
|
6
|
+
tax_rate_id: "TaxRate",
|
|
7
|
+
};
|
|
8
|
+
const entityLinkableKeysMap = {};
|
|
9
|
+
Object.entries(exports.LinkableKeys).forEach(([key, value]) => {
|
|
10
|
+
entityLinkableKeysMap[value] ?? (entityLinkableKeysMap[value] = []);
|
|
11
|
+
entityLinkableKeysMap[value].push({
|
|
12
|
+
mapTo: key,
|
|
13
|
+
valueFrom: key.split("_").pop(),
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
exports.entityNameToLinkableKeysMap = entityLinkableKeysMap;
|
|
17
|
+
exports.joinerConfig = {
|
|
18
|
+
serviceName: modules_sdk_1.Modules.TAX,
|
|
19
|
+
primaryKeys: ["id"],
|
|
20
|
+
linkableKeys: exports.LinkableKeys,
|
|
21
|
+
alias: [],
|
|
22
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
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.TaxRegion = exports.TaxRate = void 0;
|
|
7
|
+
var tax_rate_1 = require("./tax-rate");
|
|
8
|
+
Object.defineProperty(exports, "TaxRate", { enumerable: true, get: function () { return __importDefault(tax_rate_1).default; } });
|
|
9
|
+
var tax_region_1 = require("./tax-region");
|
|
10
|
+
Object.defineProperty(exports, "TaxRegion", { enumerable: true, get: function () { return __importDefault(tax_region_1).default; } });
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DAL } from "@medusajs/types";
|
|
2
|
+
import { OptionalProps } from "@mikro-orm/core";
|
|
3
|
+
import TaxRegion from "./tax-region";
|
|
4
|
+
type OptionalTaxRateProps = DAL.EntityDateColumns;
|
|
5
|
+
export default class TaxRate {
|
|
6
|
+
[OptionalProps]: OptionalTaxRateProps;
|
|
7
|
+
id: string;
|
|
8
|
+
rate: number | null;
|
|
9
|
+
code: string | null;
|
|
10
|
+
name: string;
|
|
11
|
+
is_default: boolean;
|
|
12
|
+
is_combinable: boolean;
|
|
13
|
+
tax_region_id: string;
|
|
14
|
+
tax_region: TaxRegion;
|
|
15
|
+
metadata: Record<string, unknown> | null;
|
|
16
|
+
created_at: Date;
|
|
17
|
+
updated_at: Date;
|
|
18
|
+
created_by: string | null;
|
|
19
|
+
onCreate(): void;
|
|
20
|
+
onInit(): void;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,121 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const utils_1 = require("@medusajs/utils");
|
|
16
|
+
const core_1 = require("@mikro-orm/core");
|
|
17
|
+
const tax_region_1 = __importDefault(require("./tax-region"));
|
|
18
|
+
const TABLE_NAME = "tax_rate";
|
|
19
|
+
const taxRegionIdIndexName = "IDX_tax_rate_tax_region_id";
|
|
20
|
+
const singleDefaultRegionIndexName = "IDX_single_default_region";
|
|
21
|
+
const singleDefaultRegionIndexStatement = (0, utils_1.createPsqlIndexStatementHelper)({
|
|
22
|
+
name: singleDefaultRegionIndexName,
|
|
23
|
+
tableName: TABLE_NAME,
|
|
24
|
+
columns: "tax_region_id",
|
|
25
|
+
unique: true,
|
|
26
|
+
where: "is_default = true",
|
|
27
|
+
});
|
|
28
|
+
let TaxRate = class TaxRate {
|
|
29
|
+
constructor() {
|
|
30
|
+
this.rate = null;
|
|
31
|
+
this.code = null;
|
|
32
|
+
this.is_default = false;
|
|
33
|
+
this.is_combinable = false;
|
|
34
|
+
this.metadata = null;
|
|
35
|
+
this.created_by = null;
|
|
36
|
+
}
|
|
37
|
+
onCreate() {
|
|
38
|
+
this.id = (0, utils_1.generateEntityId)(this.id, "txr");
|
|
39
|
+
}
|
|
40
|
+
onInit() {
|
|
41
|
+
this.id = (0, utils_1.generateEntityId)(this.id, "txr");
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
__decorate([
|
|
45
|
+
(0, core_1.PrimaryKey)({ columnType: "text" }),
|
|
46
|
+
__metadata("design:type", String)
|
|
47
|
+
], TaxRate.prototype, "id", void 0);
|
|
48
|
+
__decorate([
|
|
49
|
+
(0, core_1.Property)({ columnType: "real", nullable: true }),
|
|
50
|
+
__metadata("design:type", Object)
|
|
51
|
+
], TaxRate.prototype, "rate", void 0);
|
|
52
|
+
__decorate([
|
|
53
|
+
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
54
|
+
__metadata("design:type", Object)
|
|
55
|
+
], TaxRate.prototype, "code", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
(0, core_1.Property)({ columnType: "text" }),
|
|
58
|
+
__metadata("design:type", String)
|
|
59
|
+
], TaxRate.prototype, "name", void 0);
|
|
60
|
+
__decorate([
|
|
61
|
+
(0, core_1.Property)({ columnType: "bool", default: false }),
|
|
62
|
+
__metadata("design:type", Object)
|
|
63
|
+
], TaxRate.prototype, "is_default", void 0);
|
|
64
|
+
__decorate([
|
|
65
|
+
(0, core_1.Property)({ columnType: "bool", default: false }),
|
|
66
|
+
__metadata("design:type", Object)
|
|
67
|
+
], TaxRate.prototype, "is_combinable", void 0);
|
|
68
|
+
__decorate([
|
|
69
|
+
(0, core_1.Property)({ columnType: "text" }),
|
|
70
|
+
__metadata("design:type", String)
|
|
71
|
+
], TaxRate.prototype, "tax_region_id", void 0);
|
|
72
|
+
__decorate([
|
|
73
|
+
(0, core_1.ManyToOne)(() => tax_region_1.default, {
|
|
74
|
+
fieldName: "tax_region_id",
|
|
75
|
+
index: taxRegionIdIndexName,
|
|
76
|
+
cascade: [core_1.Cascade.REMOVE, core_1.Cascade.PERSIST],
|
|
77
|
+
}),
|
|
78
|
+
__metadata("design:type", tax_region_1.default)
|
|
79
|
+
], TaxRate.prototype, "tax_region", void 0);
|
|
80
|
+
__decorate([
|
|
81
|
+
(0, core_1.Property)({ columnType: "jsonb", nullable: true }),
|
|
82
|
+
__metadata("design:type", Object)
|
|
83
|
+
], TaxRate.prototype, "metadata", void 0);
|
|
84
|
+
__decorate([
|
|
85
|
+
(0, core_1.Property)({
|
|
86
|
+
onCreate: () => new Date(),
|
|
87
|
+
columnType: "timestamptz",
|
|
88
|
+
defaultRaw: "now()",
|
|
89
|
+
}),
|
|
90
|
+
__metadata("design:type", Date)
|
|
91
|
+
], TaxRate.prototype, "created_at", void 0);
|
|
92
|
+
__decorate([
|
|
93
|
+
(0, core_1.Property)({
|
|
94
|
+
onCreate: () => new Date(),
|
|
95
|
+
onUpdate: () => new Date(),
|
|
96
|
+
columnType: "timestamptz",
|
|
97
|
+
defaultRaw: "now()",
|
|
98
|
+
}),
|
|
99
|
+
__metadata("design:type", Date)
|
|
100
|
+
], TaxRate.prototype, "updated_at", void 0);
|
|
101
|
+
__decorate([
|
|
102
|
+
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
103
|
+
__metadata("design:type", Object)
|
|
104
|
+
], TaxRate.prototype, "created_by", void 0);
|
|
105
|
+
__decorate([
|
|
106
|
+
(0, core_1.BeforeCreate)(),
|
|
107
|
+
__metadata("design:type", Function),
|
|
108
|
+
__metadata("design:paramtypes", []),
|
|
109
|
+
__metadata("design:returntype", void 0)
|
|
110
|
+
], TaxRate.prototype, "onCreate", null);
|
|
111
|
+
__decorate([
|
|
112
|
+
(0, core_1.OnInit)(),
|
|
113
|
+
__metadata("design:type", Function),
|
|
114
|
+
__metadata("design:paramtypes", []),
|
|
115
|
+
__metadata("design:returntype", void 0)
|
|
116
|
+
], TaxRate.prototype, "onInit", null);
|
|
117
|
+
TaxRate = __decorate([
|
|
118
|
+
singleDefaultRegionIndexStatement.MikroORMIndex(),
|
|
119
|
+
(0, core_1.Entity)({ tableName: TABLE_NAME })
|
|
120
|
+
], TaxRate);
|
|
121
|
+
exports.default = TaxRate;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DAL } from "@medusajs/types";
|
|
2
|
+
import { Collection, OptionalProps } from "@mikro-orm/core";
|
|
3
|
+
import TaxRate from "./tax-rate";
|
|
4
|
+
type OptionalTaxRegionProps = DAL.EntityDateColumns;
|
|
5
|
+
export default class TaxRegion {
|
|
6
|
+
[OptionalProps]: OptionalTaxRegionProps;
|
|
7
|
+
id: string;
|
|
8
|
+
country_code: string;
|
|
9
|
+
province_code: string | null;
|
|
10
|
+
parent_id: string | null;
|
|
11
|
+
parent: TaxRegion;
|
|
12
|
+
tax_rates: Collection<TaxRate, object>;
|
|
13
|
+
metadata: Record<string, unknown> | null;
|
|
14
|
+
created_at: Date;
|
|
15
|
+
updated_at: Date;
|
|
16
|
+
created_by: string | null;
|
|
17
|
+
onCreate(): void;
|
|
18
|
+
onInit(): void;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,116 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const utils_1 = require("@medusajs/utils");
|
|
16
|
+
const core_1 = require("@mikro-orm/core");
|
|
17
|
+
const tax_rate_1 = __importDefault(require("./tax-rate"));
|
|
18
|
+
const TABLE_NAME = "tax_region";
|
|
19
|
+
const countryCodeProvinceIndexName = "IDX_tax_region_unique_country_province";
|
|
20
|
+
const countryCodeProvinceIndexStatement = (0, utils_1.createPsqlIndexStatementHelper)({
|
|
21
|
+
name: countryCodeProvinceIndexName,
|
|
22
|
+
tableName: TABLE_NAME,
|
|
23
|
+
columns: ["country_code", "province_code"],
|
|
24
|
+
unique: true,
|
|
25
|
+
});
|
|
26
|
+
const taxRegionCountryTopLevelCheckName = "CK_tax_region_country_top_level";
|
|
27
|
+
let TaxRegion = class TaxRegion {
|
|
28
|
+
constructor() {
|
|
29
|
+
this.province_code = null;
|
|
30
|
+
this.parent_id = null;
|
|
31
|
+
this.tax_rates = new core_1.Collection(this);
|
|
32
|
+
this.metadata = null;
|
|
33
|
+
this.created_by = null;
|
|
34
|
+
}
|
|
35
|
+
onCreate() {
|
|
36
|
+
this.id = (0, utils_1.generateEntityId)(this.id, "txreg");
|
|
37
|
+
}
|
|
38
|
+
onInit() {
|
|
39
|
+
this.id = (0, utils_1.generateEntityId)(this.id, "txreg");
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
__decorate([
|
|
43
|
+
(0, core_1.PrimaryKey)({ columnType: "text" }),
|
|
44
|
+
__metadata("design:type", String)
|
|
45
|
+
], TaxRegion.prototype, "id", void 0);
|
|
46
|
+
__decorate([
|
|
47
|
+
(0, core_1.Property)({ columnType: "text" }),
|
|
48
|
+
__metadata("design:type", String)
|
|
49
|
+
], TaxRegion.prototype, "country_code", void 0);
|
|
50
|
+
__decorate([
|
|
51
|
+
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
52
|
+
__metadata("design:type", Object)
|
|
53
|
+
], TaxRegion.prototype, "province_code", void 0);
|
|
54
|
+
__decorate([
|
|
55
|
+
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
56
|
+
__metadata("design:type", Object)
|
|
57
|
+
], TaxRegion.prototype, "parent_id", void 0);
|
|
58
|
+
__decorate([
|
|
59
|
+
(0, core_1.ManyToOne)(() => TaxRegion, {
|
|
60
|
+
index: "IDX_tax_region_parent_id",
|
|
61
|
+
cascade: [core_1.Cascade.PERSIST],
|
|
62
|
+
onDelete: "set null",
|
|
63
|
+
nullable: true,
|
|
64
|
+
}),
|
|
65
|
+
__metadata("design:type", TaxRegion)
|
|
66
|
+
], TaxRegion.prototype, "parent", void 0);
|
|
67
|
+
__decorate([
|
|
68
|
+
(0, core_1.OneToMany)(() => tax_rate_1.default, (label) => label.tax_region),
|
|
69
|
+
__metadata("design:type", Object)
|
|
70
|
+
], TaxRegion.prototype, "tax_rates", void 0);
|
|
71
|
+
__decorate([
|
|
72
|
+
(0, core_1.Property)({ columnType: "jsonb", nullable: true }),
|
|
73
|
+
__metadata("design:type", Object)
|
|
74
|
+
], TaxRegion.prototype, "metadata", void 0);
|
|
75
|
+
__decorate([
|
|
76
|
+
(0, core_1.Property)({
|
|
77
|
+
onCreate: () => new Date(),
|
|
78
|
+
columnType: "timestamptz",
|
|
79
|
+
defaultRaw: "now()",
|
|
80
|
+
}),
|
|
81
|
+
__metadata("design:type", Date)
|
|
82
|
+
], TaxRegion.prototype, "created_at", void 0);
|
|
83
|
+
__decorate([
|
|
84
|
+
(0, core_1.Property)({
|
|
85
|
+
onCreate: () => new Date(),
|
|
86
|
+
onUpdate: () => new Date(),
|
|
87
|
+
columnType: "timestamptz",
|
|
88
|
+
defaultRaw: "now()",
|
|
89
|
+
}),
|
|
90
|
+
__metadata("design:type", Date)
|
|
91
|
+
], TaxRegion.prototype, "updated_at", void 0);
|
|
92
|
+
__decorate([
|
|
93
|
+
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
94
|
+
__metadata("design:type", Object)
|
|
95
|
+
], TaxRegion.prototype, "created_by", void 0);
|
|
96
|
+
__decorate([
|
|
97
|
+
(0, core_1.BeforeCreate)(),
|
|
98
|
+
__metadata("design:type", Function),
|
|
99
|
+
__metadata("design:paramtypes", []),
|
|
100
|
+
__metadata("design:returntype", void 0)
|
|
101
|
+
], TaxRegion.prototype, "onCreate", null);
|
|
102
|
+
__decorate([
|
|
103
|
+
(0, core_1.OnInit)(),
|
|
104
|
+
__metadata("design:type", Function),
|
|
105
|
+
__metadata("design:paramtypes", []),
|
|
106
|
+
__metadata("design:returntype", void 0)
|
|
107
|
+
], TaxRegion.prototype, "onInit", null);
|
|
108
|
+
TaxRegion = __decorate([
|
|
109
|
+
(0, core_1.Check)({
|
|
110
|
+
name: taxRegionCountryTopLevelCheckName,
|
|
111
|
+
expression: `parent_id IS NULL OR province_code IS NOT NULL`,
|
|
112
|
+
}),
|
|
113
|
+
countryCodeProvinceIndexStatement.MikroORMIndex(),
|
|
114
|
+
(0, core_1.Entity)({ tableName: TABLE_NAME })
|
|
115
|
+
], TaxRegion);
|
|
116
|
+
exports.default = TaxRegion;
|
|
@@ -0,0 +1,57 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.moduleDefinition = void 0;
|
|
27
|
+
const utils_1 = require("@medusajs/utils");
|
|
28
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
29
|
+
const Models = __importStar(require("./models"));
|
|
30
|
+
const ModuleModels = __importStar(require("./models"));
|
|
31
|
+
const ModuleServices = __importStar(require("./services"));
|
|
32
|
+
const _services_1 = require("./services");
|
|
33
|
+
const migrationScriptOptions = {
|
|
34
|
+
moduleName: modules_sdk_1.Modules.TAX,
|
|
35
|
+
models: Models,
|
|
36
|
+
pathToMigrations: __dirname + "/migrations",
|
|
37
|
+
};
|
|
38
|
+
const runMigrations = utils_1.ModulesSdkUtils.buildMigrationScript(migrationScriptOptions);
|
|
39
|
+
const revertMigration = utils_1.ModulesSdkUtils.buildRevertMigrationScript(migrationScriptOptions);
|
|
40
|
+
const containerLoader = utils_1.ModulesSdkUtils.moduleContainerLoaderFactory({
|
|
41
|
+
moduleModels: ModuleModels,
|
|
42
|
+
moduleRepositories: { BaseRepository: utils_1.MikroOrmBaseRepository },
|
|
43
|
+
moduleServices: ModuleServices,
|
|
44
|
+
});
|
|
45
|
+
const connectionLoader = utils_1.ModulesSdkUtils.mikroOrmConnectionLoaderFactory({
|
|
46
|
+
moduleName: modules_sdk_1.Modules.TAX,
|
|
47
|
+
moduleModels: Object.values(Models),
|
|
48
|
+
migrationsPath: __dirname + "/migrations",
|
|
49
|
+
});
|
|
50
|
+
const service = _services_1.TaxModuleService;
|
|
51
|
+
const loaders = [containerLoader, connectionLoader];
|
|
52
|
+
exports.moduleDefinition = {
|
|
53
|
+
service,
|
|
54
|
+
loaders,
|
|
55
|
+
revertMigration,
|
|
56
|
+
runMigrations,
|
|
57
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
28
|
+
const utils_1 = require("@medusajs/utils");
|
|
29
|
+
const Models = __importStar(require("../../models"));
|
|
30
|
+
const os_1 = require("os");
|
|
31
|
+
const args = process.argv;
|
|
32
|
+
const path = args.pop();
|
|
33
|
+
exports.default = (async () => {
|
|
34
|
+
const { config } = await Promise.resolve().then(() => __importStar(require("dotenv")));
|
|
35
|
+
config();
|
|
36
|
+
if (!path) {
|
|
37
|
+
throw new Error(`filePath is required.${os_1.EOL}Example: medusa-tax-seed <filePath>`);
|
|
38
|
+
}
|
|
39
|
+
const run = utils_1.ModulesSdkUtils.buildSeedScript({
|
|
40
|
+
moduleName: modules_sdk_1.Modules.TAX,
|
|
41
|
+
models: Models,
|
|
42
|
+
pathToMigrations: __dirname + "/../../migrations",
|
|
43
|
+
seedHandler: async ({ manager, data }) => {
|
|
44
|
+
// TODO: Add seed logic
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
await run({ path });
|
|
48
|
+
})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as TaxModuleService } from "./tax-module-service";
|
|
@@ -0,0 +1,8 @@
|
|
|
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.TaxModuleService = void 0;
|
|
7
|
+
var tax_module_service_1 = require("./tax-module-service");
|
|
8
|
+
Object.defineProperty(exports, "TaxModuleService", { enumerable: true, get: function () { return __importDefault(tax_module_service_1).default; } });
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Context, DAL, ITaxModuleService, InternalModuleDeclaration, ModuleJoinerConfig, ModulesSdkTypes, TaxTypes } from "@medusajs/types";
|
|
2
|
+
import { ModulesSdkUtils } from "@medusajs/utils";
|
|
3
|
+
import { TaxRate, TaxRegion } from "../models";
|
|
4
|
+
type InjectedDependencies = {
|
|
5
|
+
baseRepository: DAL.RepositoryService;
|
|
6
|
+
taxRateService: ModulesSdkTypes.InternalModuleService<any>;
|
|
7
|
+
taxRegionService: ModulesSdkTypes.InternalModuleService<any>;
|
|
8
|
+
};
|
|
9
|
+
declare const TaxModuleService_base: new (container: InjectedDependencies) => ModulesSdkUtils.AbstractModuleService<InjectedDependencies, TaxTypes.TaxRateDTO, {
|
|
10
|
+
TaxRegion: {
|
|
11
|
+
dto: TaxTypes.TaxRegionDTO;
|
|
12
|
+
};
|
|
13
|
+
}>;
|
|
14
|
+
export default class TaxModuleService<TTaxRate extends TaxRate = TaxRate, TTaxRegion extends TaxRegion = TaxRegion> extends TaxModuleService_base implements ITaxModuleService {
|
|
15
|
+
protected readonly moduleDeclaration: InternalModuleDeclaration;
|
|
16
|
+
protected baseRepository_: DAL.RepositoryService;
|
|
17
|
+
protected taxRateService_: ModulesSdkTypes.InternalModuleService<TTaxRate>;
|
|
18
|
+
protected taxRegionService_: ModulesSdkTypes.InternalModuleService<TTaxRegion>;
|
|
19
|
+
constructor({ baseRepository, taxRateService, taxRegionService }: InjectedDependencies, moduleDeclaration: InternalModuleDeclaration);
|
|
20
|
+
__joinerConfig(): ModuleJoinerConfig;
|
|
21
|
+
create(data: TaxTypes.CreateTaxRateDTO[], sharedContext?: Context): Promise<TaxTypes.TaxRateDTO[]>;
|
|
22
|
+
create(data: TaxTypes.CreateTaxRateDTO, sharedContext?: Context): Promise<TaxTypes.TaxRateDTO>;
|
|
23
|
+
protected create_(data: TaxTypes.CreateTaxRateDTO[], sharedContext?: Context): Promise<TTaxRate[]>;
|
|
24
|
+
createTaxRegions(data: TaxTypes.CreateTaxRegionDTO[], sharedContext?: Context): Promise<TaxTypes.TaxRegionDTO[]>;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
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 utils_1 = require("@medusajs/utils");
|
|
16
|
+
const _models_1 = require("../models");
|
|
17
|
+
const joiner_config_1 = require("../joiner-config");
|
|
18
|
+
class TaxModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFactory(_models_1.TaxRate, [_models_1.TaxRegion], joiner_config_1.entityNameToLinkableKeysMap) {
|
|
19
|
+
constructor({ baseRepository, taxRateService, taxRegionService }, moduleDeclaration) {
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
super(...arguments);
|
|
22
|
+
this.moduleDeclaration = moduleDeclaration;
|
|
23
|
+
this.baseRepository_ = baseRepository;
|
|
24
|
+
this.taxRateService_ = taxRateService;
|
|
25
|
+
this.taxRegionService_ = taxRegionService;
|
|
26
|
+
}
|
|
27
|
+
__joinerConfig() {
|
|
28
|
+
return joiner_config_1.joinerConfig;
|
|
29
|
+
}
|
|
30
|
+
async create(data, sharedContext = {}) {
|
|
31
|
+
const input = Array.isArray(data) ? data : [data];
|
|
32
|
+
const rates = await this.create_(input, sharedContext);
|
|
33
|
+
const result = await this.baseRepository_.serialize(rates, { populate: true });
|
|
34
|
+
return Array.isArray(data) ? result : result[0];
|
|
35
|
+
}
|
|
36
|
+
async create_(data, sharedContext = {}) {
|
|
37
|
+
return await this.taxRateService_.create(data, sharedContext);
|
|
38
|
+
}
|
|
39
|
+
async createTaxRegions(data, sharedContext = {}) {
|
|
40
|
+
// TODO: check that country_code === parent.country_code
|
|
41
|
+
const [defaultRates, regionData] = data.reduce((acc, region) => {
|
|
42
|
+
const { default_tax_rate, ...rest } = region;
|
|
43
|
+
acc[0].push({
|
|
44
|
+
...default_tax_rate,
|
|
45
|
+
is_default: true,
|
|
46
|
+
created_by: region.created_by,
|
|
47
|
+
});
|
|
48
|
+
acc[1].push(rest);
|
|
49
|
+
return acc;
|
|
50
|
+
}, [[], []]);
|
|
51
|
+
const regions = await this.taxRegionService_.create(regionData, sharedContext);
|
|
52
|
+
const rates = regions.map((region, i) => {
|
|
53
|
+
return {
|
|
54
|
+
...defaultRates[i],
|
|
55
|
+
tax_region_id: region.id,
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
await this.create(rates, sharedContext);
|
|
59
|
+
return await this.baseRepository_.serialize(regions, {
|
|
60
|
+
populate: true,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.default = TaxModuleService;
|
|
65
|
+
__decorate([
|
|
66
|
+
(0, utils_1.InjectManager)("baseRepository_"),
|
|
67
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
|
68
|
+
__metadata("design:type", Function),
|
|
69
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
70
|
+
__metadata("design:returntype", Promise)
|
|
71
|
+
], TaxModuleService.prototype, "create", null);
|
|
72
|
+
__decorate([
|
|
73
|
+
(0, utils_1.InjectTransactionManager)("baseRepository_"),
|
|
74
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
|
75
|
+
__metadata("design:type", Function),
|
|
76
|
+
__metadata("design:paramtypes", [Array, Object]),
|
|
77
|
+
__metadata("design:returntype", Promise)
|
|
78
|
+
], TaxModuleService.prototype, "create_", null);
|
|
79
|
+
__decorate([
|
|
80
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
|
81
|
+
__metadata("design:type", Function),
|
|
82
|
+
__metadata("design:paramtypes", [Array, Object]),
|
|
83
|
+
__metadata("design:returntype", Promise)
|
|
84
|
+
], TaxModuleService.prototype, "createTaxRegions", null);
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@medusajs/tax",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Medusa Tax 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-tax-seed": "dist/scripts/bin/run-seed.js"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/medusajs/medusa",
|
|
19
|
+
"directory": "packages/tax"
|
|
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
|
+
"@mikro-orm/cli": "5.9.7",
|
|
41
|
+
"cross-env": "^5.2.1",
|
|
42
|
+
"jest": "^29.6.3",
|
|
43
|
+
"medusa-test-utils": "^1.1.40",
|
|
44
|
+
"rimraf": "^3.0.2",
|
|
45
|
+
"ts-jest": "^29.1.1",
|
|
46
|
+
"ts-node": "^10.9.1",
|
|
47
|
+
"tsc-alias": "^1.8.6",
|
|
48
|
+
"typescript": "^5.1.6"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@medusajs/modules-sdk": "^1.12.4",
|
|
52
|
+
"@medusajs/types": "^1.11.8",
|
|
53
|
+
"@medusajs/utils": "^1.11.1",
|
|
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
|
+
}
|