@medusajs/store 0.1.0 → 0.1.1-next-20240319121007
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/migrations/InitialSetup20240227075933.js +6 -2
- package/dist/models/store.d.ts +1 -0
- package/dist/models/store.js +5 -0
- package/dist/scripts/bin/run-seed.js +0 -0
- package/dist/services/store-module-service.d.ts +2 -0
- package/dist/services/store-module-service.js +38 -0
- package/package.json +5 -5
|
@@ -10,12 +10,16 @@ class InitialSetup20240226130829 extends migrations_1.Migration {
|
|
|
10
10
|
this.addSql(`alter table "store" alter column "id" TYPE text;`);
|
|
11
11
|
this.addSql(`alter table "store" alter column "name" TYPE text;`);
|
|
12
12
|
this.addSql(`alter table "store" alter column "name" SET DEFAULT 'Medusa Store';`);
|
|
13
|
+
this.addSql(`alter table "store" alter column "default_currency_code" TYPE text;`);
|
|
14
|
+
this.addSql(`alter table "store" alter column "default_currency_code" drop not null;`);
|
|
13
15
|
this.addSql(`alter table "store" alter column "default_sales_channel_id" TYPE text;`);
|
|
14
16
|
this.addSql(`alter table "store" alter column "default_location_id" TYPE text;`);
|
|
15
|
-
this.addSql(`alter table "store" add column "default_region_id" text;`);
|
|
17
|
+
this.addSql(`alter table "store" add column "default_region_id" text null;`);
|
|
16
18
|
this.addSql(`alter table "store" add column "deleted_at" timestamptz null;`);
|
|
17
19
|
this.addSql(`alter table "store" add column "supported_currency_codes" text[] not null default \'{}\';`);
|
|
18
20
|
this.addSql('create index if not exists "IDX_store_deleted_at" on "store" (deleted_at) where deleted_at is not null;');
|
|
21
|
+
this.addSql(`alter table "store" drop constraint if exists "FK_61b0f48cccbb5f41c750bac7286";`);
|
|
22
|
+
this.addSql(`alter table "store" drop constraint if exists "FK_55beebaa09e947cccca554af222";`);
|
|
19
23
|
// this.addSql(`alter table "store" drop column "default_currency_code";`)
|
|
20
24
|
// this.addSql(`alter table "store" drop column "swap_link_template";`)
|
|
21
25
|
// this.addSql(`alter table "store" drop column "payment_link_template";`)
|
|
@@ -24,7 +28,7 @@ class InitialSetup20240226130829 extends migrations_1.Migration {
|
|
|
24
28
|
else {
|
|
25
29
|
this.addSql(`create table if not exists "store"
|
|
26
30
|
("id" text not null, "name" text not null default \'Medusa Store\', "supported_currency_codes" text[] not null default \'{}\',
|
|
27
|
-
"default_sales_channel_id" text null, "default_region_id" text null, "default_location_id" text null,
|
|
31
|
+
"default_currency_code" text null, "default_sales_channel_id" text null, "default_region_id" text null, "default_location_id" text null,
|
|
28
32
|
"metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null,
|
|
29
33
|
constraint "store_pkey" primary key ("id"));`);
|
|
30
34
|
this.addSql('create index if not exists "IDX_store_deleted_at" on "store" (deleted_at) where deleted_at is not null;');
|
package/dist/models/store.d.ts
CHANGED
package/dist/models/store.js
CHANGED
|
@@ -19,6 +19,7 @@ const StoreDeletedAtIndex = (0, utils_1.createPsqlIndexStatementHelper)({
|
|
|
19
19
|
let Store = class Store {
|
|
20
20
|
constructor() {
|
|
21
21
|
this.supported_currency_codes = [];
|
|
22
|
+
this.default_currency_code = null;
|
|
22
23
|
this.default_sales_channel_id = null;
|
|
23
24
|
this.default_region_id = null;
|
|
24
25
|
this.default_location_id = null;
|
|
@@ -44,6 +45,10 @@ __decorate([
|
|
|
44
45
|
(0, core_1.Property)({ type: "array", default: "{}" }),
|
|
45
46
|
__metadata("design:type", Array)
|
|
46
47
|
], Store.prototype, "supported_currency_codes", void 0);
|
|
48
|
+
__decorate([
|
|
49
|
+
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
50
|
+
__metadata("design:type", Object)
|
|
51
|
+
], Store.prototype, "default_currency_code", void 0);
|
|
47
52
|
__decorate([
|
|
48
53
|
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
49
54
|
__metadata("design:type", Object)
|
|
File without changes
|
|
@@ -26,5 +26,7 @@ export default class StoreModuleService<TEntity extends Store = Store> extends S
|
|
|
26
26
|
update(selector: StoreTypes.FilterableStoreProps, data: StoreTypes.UpdateStoreDTO, sharedContext?: Context): Promise<StoreTypes.StoreDTO[]>;
|
|
27
27
|
protected update_(data: UpdateStoreInput[], sharedContext?: Context): Promise<Store[]>;
|
|
28
28
|
private static normalizeInput;
|
|
29
|
+
private static validateCreateRequest;
|
|
30
|
+
private validateUpdateRequest;
|
|
29
31
|
}
|
|
30
32
|
export {};
|
|
@@ -35,6 +35,7 @@ class StoreModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
|
|
|
35
35
|
}
|
|
36
36
|
async create_(data, sharedContext = {}) {
|
|
37
37
|
let normalizedInput = StoreModuleService.normalizeInput(data);
|
|
38
|
+
StoreModuleService.validateCreateRequest(normalizedInput);
|
|
38
39
|
return await this.storeService_.create(normalizedInput, sharedContext);
|
|
39
40
|
}
|
|
40
41
|
async upsert(data, sharedContext = {}) {
|
|
@@ -69,6 +70,7 @@ class StoreModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
|
|
|
69
70
|
}
|
|
70
71
|
async update_(data, sharedContext = {}) {
|
|
71
72
|
const normalizedInput = StoreModuleService.normalizeInput(data);
|
|
73
|
+
await this.validateUpdateRequest(normalizedInput);
|
|
72
74
|
return await this.storeService_.update(normalizedInput, sharedContext);
|
|
73
75
|
}
|
|
74
76
|
static normalizeInput(stores) {
|
|
@@ -77,6 +79,42 @@ class StoreModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
|
|
|
77
79
|
name: store.name?.trim(),
|
|
78
80
|
}));
|
|
79
81
|
}
|
|
82
|
+
static validateCreateRequest(stores) {
|
|
83
|
+
for (const store of stores) {
|
|
84
|
+
// If we are setting the default currency code on creating, make sure it is supported
|
|
85
|
+
if (store.default_currency_code) {
|
|
86
|
+
if (!store.supported_currency_codes?.includes(store.default_currency_code ?? "")) {
|
|
87
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Store does not have currency: ${store.default_currency_code}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async validateUpdateRequest(stores) {
|
|
93
|
+
const dbStores = await this.storeService_.list({ id: stores.map((s) => s.id) }, { take: null });
|
|
94
|
+
const dbStoresMap = new Map(dbStores.map((dbStore) => [dbStore.id, dbStore]));
|
|
95
|
+
for (const store of stores) {
|
|
96
|
+
const dbStore = dbStoresMap.get(store.id);
|
|
97
|
+
// If it is updating both the supported currency codes and the default one, look in that list
|
|
98
|
+
if (store.supported_currency_codes && store.default_currency_code) {
|
|
99
|
+
if (!store.supported_currency_codes.includes(store.default_currency_code ?? "")) {
|
|
100
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Store does not have currency: ${store.default_currency_code}`);
|
|
101
|
+
}
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
// If it is updating only the default currency code, look in the db store
|
|
105
|
+
if (store.default_currency_code) {
|
|
106
|
+
if (!dbStore?.supported_currency_codes?.includes(store.default_currency_code)) {
|
|
107
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Store does not have currency: ${store.default_currency_code}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// If it is updating only the supported currency codes, make sure one of them is not set as a default one
|
|
111
|
+
if (store.supported_currency_codes) {
|
|
112
|
+
if (!store.supported_currency_codes.includes(dbStore?.default_currency_code ?? "")) {
|
|
113
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "You are not allowed to remove default currency from store currencies without replacing it as well");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
80
118
|
}
|
|
81
119
|
exports.default = StoreModuleService;
|
|
82
120
|
__decorate([
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medusajs/store",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-next-20240319121007",
|
|
4
4
|
"description": "Medusa Store module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -48,14 +48,14 @@
|
|
|
48
48
|
"typescript": "^5.1.6"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@medusajs/modules-sdk": "1.12.9-next-
|
|
52
|
-
"@medusajs/types": "1.11.14-next-
|
|
53
|
-
"@medusajs/utils": "1.11.7-next-
|
|
51
|
+
"@medusajs/modules-sdk": "1.12.9-next-20240319121007",
|
|
52
|
+
"@medusajs/types": "1.11.14-next-20240319121007",
|
|
53
|
+
"@medusajs/utils": "1.11.7-next-20240319121007",
|
|
54
54
|
"@mikro-orm/core": "5.9.7",
|
|
55
55
|
"@mikro-orm/migrations": "5.9.7",
|
|
56
56
|
"@mikro-orm/postgresql": "5.9.7",
|
|
57
57
|
"awilix": "^8.0.0",
|
|
58
|
-
"dotenv": "^16.
|
|
58
|
+
"dotenv": "^16.4.5",
|
|
59
59
|
"knex": "2.4.2"
|
|
60
60
|
}
|
|
61
61
|
}
|