@medusajs/store 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 +8 -0
- package/dist/index.js +29 -0
- package/dist/joiner-config.d.ts +5 -0
- package/dist/joiner-config.js +29 -0
- package/dist/migrations/InitialSetup20240227075933.d.ts +4 -0
- package/dist/migrations/InitialSetup20240227075933.js +34 -0
- package/dist/models/index.d.ts +1 -0
- package/dist/models/index.js +8 -0
- package/dist/models/store.d.ts +19 -0
- package/dist/models/store.js +101 -0
- package/dist/module-definition.d.ts +2 -0
- package/dist/module-definition.js +58 -0
- package/dist/repositories/index.d.ts +1 -0
- package/dist/repositories/index.js +5 -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/store-module-service.d.ts +30 -0
- package/dist/services/store-module-service.js +116 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.js +2 -0
- package/package.json +61 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Store Module
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { moduleDefinition } from "./module-definition";
|
|
2
|
+
export * from "./types";
|
|
3
|
+
export * from "./models";
|
|
4
|
+
export * from "./services";
|
|
5
|
+
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>;
|
|
6
|
+
export declare const runMigrations: ((options: import("@medusajs/modules-sdk").LoaderOptions<any>, moduleDeclaration?: import("@medusajs/modules-sdk").InternalModuleDeclaration | undefined) => Promise<void>) | undefined;
|
|
7
|
+
export declare const revertMigration: ((options: import("@medusajs/modules-sdk").LoaderOptions<any>, moduleDeclaration?: import("@medusajs/modules-sdk").InternalModuleDeclaration | undefined) => Promise<void>) | undefined;
|
|
8
|
+
export default moduleDefinition;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
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 module_definition_1 = require("./module-definition");
|
|
19
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
21
|
+
__exportStar(require("./models"), exports);
|
|
22
|
+
__exportStar(require("./services"), exports);
|
|
23
|
+
exports.initialize = (0, modules_sdk_1.initializeFactory)({
|
|
24
|
+
moduleName: modules_sdk_1.Modules.STORE,
|
|
25
|
+
moduleDefinition: module_definition_1.moduleDefinition,
|
|
26
|
+
});
|
|
27
|
+
exports.runMigrations = module_definition_1.moduleDefinition.runMigrations;
|
|
28
|
+
exports.revertMigration = module_definition_1.moduleDefinition.revertMigration;
|
|
29
|
+
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,29 @@
|
|
|
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.joinerConfig = exports.entityNameToLinkableKeysMap = exports.LinkableKeys = void 0;
|
|
7
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
8
|
+
const store_1 = __importDefault(require("./models/store"));
|
|
9
|
+
exports.LinkableKeys = {};
|
|
10
|
+
const entityLinkableKeysMap = {};
|
|
11
|
+
Object.entries(exports.LinkableKeys).forEach(([key, value]) => {
|
|
12
|
+
entityLinkableKeysMap[value] ?? (entityLinkableKeysMap[value] = []);
|
|
13
|
+
entityLinkableKeysMap[value].push({
|
|
14
|
+
mapTo: key,
|
|
15
|
+
valueFrom: key.split("_").pop(),
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
exports.entityNameToLinkableKeysMap = entityLinkableKeysMap;
|
|
19
|
+
exports.joinerConfig = {
|
|
20
|
+
serviceName: modules_sdk_1.Modules.STORE,
|
|
21
|
+
primaryKeys: ["id"],
|
|
22
|
+
linkableKeys: exports.LinkableKeys,
|
|
23
|
+
alias: [
|
|
24
|
+
{
|
|
25
|
+
name: ["store", "stores"],
|
|
26
|
+
args: { entity: store_1.default.name },
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InitialSetup20240226130829 = void 0;
|
|
4
|
+
const migrations_1 = require("@mikro-orm/migrations");
|
|
5
|
+
class InitialSetup20240226130829 extends migrations_1.Migration {
|
|
6
|
+
async up() {
|
|
7
|
+
// TODO: The migration needs to take care of moving data before dropping columns, among other things
|
|
8
|
+
const storeTables = await this.execute("select * from information_schema.tables where table_name = 'store' and table_schema = 'public'");
|
|
9
|
+
if (storeTables.length > 0) {
|
|
10
|
+
this.addSql(`alter table "store" alter column "id" TYPE text;`);
|
|
11
|
+
this.addSql(`alter table "store" alter column "name" TYPE text;`);
|
|
12
|
+
this.addSql(`alter table "store" alter column "name" SET DEFAULT 'Medusa Store';`);
|
|
13
|
+
this.addSql(`alter table "store" alter column "default_sales_channel_id" TYPE text;`);
|
|
14
|
+
this.addSql(`alter table "store" alter column "default_location_id" TYPE text;`);
|
|
15
|
+
this.addSql(`alter table "store" add column "default_region_id" text;`);
|
|
16
|
+
this.addSql(`alter table "store" add column "deleted_at" timestamptz null;`);
|
|
17
|
+
this.addSql(`alter table "store" add column "supported_currency_codes" text[] not null default \'{}\';`);
|
|
18
|
+
this.addSql('create index if not exists "IDX_store_deleted_at" on "store" (deleted_at) where deleted_at is not null;');
|
|
19
|
+
// this.addSql(`alter table "store" drop column "default_currency_code";`)
|
|
20
|
+
// this.addSql(`alter table "store" drop column "swap_link_template";`)
|
|
21
|
+
// this.addSql(`alter table "store" drop column "payment_link_template";`)
|
|
22
|
+
// this.addSql(`alter table "store" drop column "invite_link_template";`)
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.addSql(`create table if not exists "store"
|
|
26
|
+
("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,
|
|
28
|
+
"metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null,
|
|
29
|
+
constraint "store_pkey" primary key ("id"));`);
|
|
30
|
+
this.addSql('create index if not exists "IDX_store_deleted_at" on "store" (deleted_at) where deleted_at is not null;');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.InitialSetup20240226130829 = InitialSetup20240226130829;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Store } from "./store";
|
|
@@ -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.Store = void 0;
|
|
7
|
+
var store_1 = require("./store");
|
|
8
|
+
Object.defineProperty(exports, "Store", { enumerable: true, get: function () { return __importDefault(store_1).default; } });
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DAL } from "@medusajs/types";
|
|
2
|
+
import { OptionalProps } from "@mikro-orm/core";
|
|
3
|
+
type StoreOptionalProps = DAL.SoftDeletableEntityDateColumns;
|
|
4
|
+
export default class Store {
|
|
5
|
+
[OptionalProps]?: StoreOptionalProps;
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
supported_currency_codes: string[];
|
|
9
|
+
default_sales_channel_id: string | null;
|
|
10
|
+
default_region_id: string | null;
|
|
11
|
+
default_location_id: string | null;
|
|
12
|
+
metadata: Record<string, unknown> | null;
|
|
13
|
+
created_at: Date;
|
|
14
|
+
updated_at: Date;
|
|
15
|
+
deleted_at: Date | null;
|
|
16
|
+
onCreate(): void;
|
|
17
|
+
onInit(): void;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const utils_1 = require("@medusajs/utils");
|
|
13
|
+
const core_1 = require("@mikro-orm/core");
|
|
14
|
+
const StoreDeletedAtIndex = (0, utils_1.createPsqlIndexStatementHelper)({
|
|
15
|
+
tableName: "store",
|
|
16
|
+
columns: "deleted_at",
|
|
17
|
+
where: "deleted_at IS NOT NULL",
|
|
18
|
+
});
|
|
19
|
+
let Store = class Store {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.supported_currency_codes = [];
|
|
22
|
+
this.default_sales_channel_id = null;
|
|
23
|
+
this.default_region_id = null;
|
|
24
|
+
this.default_location_id = null;
|
|
25
|
+
this.metadata = null;
|
|
26
|
+
this.deleted_at = null;
|
|
27
|
+
}
|
|
28
|
+
onCreate() {
|
|
29
|
+
this.id = (0, utils_1.generateEntityId)(this.id, "store");
|
|
30
|
+
}
|
|
31
|
+
onInit() {
|
|
32
|
+
this.id = (0, utils_1.generateEntityId)(this.id, "store");
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
__decorate([
|
|
36
|
+
(0, core_1.PrimaryKey)({ columnType: "text" }),
|
|
37
|
+
__metadata("design:type", String)
|
|
38
|
+
], Store.prototype, "id", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, core_1.Property)({ columnType: "text", default: "Medusa Store" }),
|
|
41
|
+
__metadata("design:type", String)
|
|
42
|
+
], Store.prototype, "name", void 0);
|
|
43
|
+
__decorate([
|
|
44
|
+
(0, core_1.Property)({ type: "array", default: "{}" }),
|
|
45
|
+
__metadata("design:type", Array)
|
|
46
|
+
], Store.prototype, "supported_currency_codes", void 0);
|
|
47
|
+
__decorate([
|
|
48
|
+
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
49
|
+
__metadata("design:type", Object)
|
|
50
|
+
], Store.prototype, "default_sales_channel_id", void 0);
|
|
51
|
+
__decorate([
|
|
52
|
+
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
53
|
+
__metadata("design:type", Object)
|
|
54
|
+
], Store.prototype, "default_region_id", void 0);
|
|
55
|
+
__decorate([
|
|
56
|
+
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
57
|
+
__metadata("design:type", Object)
|
|
58
|
+
], Store.prototype, "default_location_id", void 0);
|
|
59
|
+
__decorate([
|
|
60
|
+
(0, core_1.Property)({ columnType: "jsonb", nullable: true }),
|
|
61
|
+
__metadata("design:type", Object)
|
|
62
|
+
], Store.prototype, "metadata", void 0);
|
|
63
|
+
__decorate([
|
|
64
|
+
(0, core_1.Property)({
|
|
65
|
+
onCreate: () => new Date(),
|
|
66
|
+
columnType: "timestamptz",
|
|
67
|
+
defaultRaw: "now()",
|
|
68
|
+
}),
|
|
69
|
+
__metadata("design:type", Date)
|
|
70
|
+
], Store.prototype, "created_at", void 0);
|
|
71
|
+
__decorate([
|
|
72
|
+
(0, core_1.Property)({
|
|
73
|
+
onCreate: () => new Date(),
|
|
74
|
+
onUpdate: () => new Date(),
|
|
75
|
+
columnType: "timestamptz",
|
|
76
|
+
defaultRaw: "now()",
|
|
77
|
+
}),
|
|
78
|
+
__metadata("design:type", Date)
|
|
79
|
+
], Store.prototype, "updated_at", void 0);
|
|
80
|
+
__decorate([
|
|
81
|
+
StoreDeletedAtIndex.MikroORMIndex(),
|
|
82
|
+
(0, core_1.Property)({ columnType: "timestamptz", nullable: true }),
|
|
83
|
+
__metadata("design:type", Object)
|
|
84
|
+
], Store.prototype, "deleted_at", void 0);
|
|
85
|
+
__decorate([
|
|
86
|
+
(0, core_1.BeforeCreate)(),
|
|
87
|
+
__metadata("design:type", Function),
|
|
88
|
+
__metadata("design:paramtypes", []),
|
|
89
|
+
__metadata("design:returntype", void 0)
|
|
90
|
+
], Store.prototype, "onCreate", null);
|
|
91
|
+
__decorate([
|
|
92
|
+
(0, core_1.OnInit)(),
|
|
93
|
+
__metadata("design:type", Function),
|
|
94
|
+
__metadata("design:paramtypes", []),
|
|
95
|
+
__metadata("design:returntype", void 0)
|
|
96
|
+
], Store.prototype, "onInit", null);
|
|
97
|
+
Store = __decorate([
|
|
98
|
+
(0, core_1.Entity)(),
|
|
99
|
+
(0, core_1.Filter)(utils_1.DALUtils.mikroOrmSoftDeletableFilterOptions)
|
|
100
|
+
], Store);
|
|
101
|
+
exports.default = Store;
|
|
@@ -0,0 +1,58 @@
|
|
|
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 ModuleServices = __importStar(require("./services"));
|
|
28
|
+
const _services_1 = require("./services");
|
|
29
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
30
|
+
const Models = __importStar(require("./models"));
|
|
31
|
+
const ModuleModels = __importStar(require("./models"));
|
|
32
|
+
const utils_1 = require("@medusajs/utils");
|
|
33
|
+
const ModuleRepositories = __importStar(require("./repositories"));
|
|
34
|
+
const migrationScriptOptions = {
|
|
35
|
+
moduleName: modules_sdk_1.Modules.STORE,
|
|
36
|
+
models: Models,
|
|
37
|
+
pathToMigrations: __dirname + "/migrations",
|
|
38
|
+
};
|
|
39
|
+
const runMigrations = utils_1.ModulesSdkUtils.buildMigrationScript(migrationScriptOptions);
|
|
40
|
+
const revertMigration = utils_1.ModulesSdkUtils.buildRevertMigrationScript(migrationScriptOptions);
|
|
41
|
+
const containerLoader = utils_1.ModulesSdkUtils.moduleContainerLoaderFactory({
|
|
42
|
+
moduleModels: ModuleModels,
|
|
43
|
+
moduleRepositories: ModuleRepositories,
|
|
44
|
+
moduleServices: ModuleServices,
|
|
45
|
+
});
|
|
46
|
+
const connectionLoader = utils_1.ModulesSdkUtils.mikroOrmConnectionLoaderFactory({
|
|
47
|
+
moduleName: modules_sdk_1.Modules.STORE,
|
|
48
|
+
moduleModels: Object.values(Models),
|
|
49
|
+
migrationsPath: __dirname + "/migrations",
|
|
50
|
+
});
|
|
51
|
+
const service = _services_1.StoreModuleService;
|
|
52
|
+
const loaders = [containerLoader, connectionLoader];
|
|
53
|
+
exports.moduleDefinition = {
|
|
54
|
+
service,
|
|
55
|
+
loaders,
|
|
56
|
+
revertMigration,
|
|
57
|
+
runMigrations,
|
|
58
|
+
};
|
|
@@ -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; } });
|
|
@@ -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 utils_1 = require("@medusajs/utils");
|
|
28
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
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-store-seed <filePath>`);
|
|
38
|
+
}
|
|
39
|
+
const run = utils_1.ModulesSdkUtils.buildSeedScript({
|
|
40
|
+
moduleName: modules_sdk_1.Modules.STORE,
|
|
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 StoreModuleService } from "./store-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.StoreModuleService = void 0;
|
|
7
|
+
var store_module_service_1 = require("./store-module-service");
|
|
8
|
+
Object.defineProperty(exports, "StoreModuleService", { enumerable: true, get: function () { return __importDefault(store_module_service_1).default; } });
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { DAL, InternalModuleDeclaration, ModuleJoinerConfig, ModulesSdkTypes, IStoreModuleService, StoreTypes, Context } from "@medusajs/types";
|
|
2
|
+
import { ModulesSdkUtils } from "@medusajs/utils";
|
|
3
|
+
import { Store } from "../models";
|
|
4
|
+
import { UpdateStoreInput } from "../types";
|
|
5
|
+
type InjectedDependencies = {
|
|
6
|
+
baseRepository: DAL.RepositoryService;
|
|
7
|
+
storeService: ModulesSdkTypes.InternalModuleService<any>;
|
|
8
|
+
};
|
|
9
|
+
declare const StoreModuleService_base: new (container: InjectedDependencies) => ModulesSdkUtils.AbstractModuleService<InjectedDependencies, StoreTypes.StoreDTO, {
|
|
10
|
+
Store: {
|
|
11
|
+
dto: StoreTypes.StoreDTO;
|
|
12
|
+
};
|
|
13
|
+
}>;
|
|
14
|
+
export default class StoreModuleService<TEntity extends Store = Store> extends StoreModuleService_base implements IStoreModuleService {
|
|
15
|
+
protected readonly moduleDeclaration: InternalModuleDeclaration;
|
|
16
|
+
protected baseRepository_: DAL.RepositoryService;
|
|
17
|
+
protected readonly storeService_: ModulesSdkTypes.InternalModuleService<TEntity>;
|
|
18
|
+
constructor({ baseRepository, storeService }: InjectedDependencies, moduleDeclaration: InternalModuleDeclaration);
|
|
19
|
+
__joinerConfig(): ModuleJoinerConfig;
|
|
20
|
+
create(data: StoreTypes.CreateStoreDTO[], sharedContext?: Context): Promise<StoreTypes.StoreDTO[]>;
|
|
21
|
+
create(data: StoreTypes.CreateStoreDTO, sharedContext?: Context): Promise<StoreTypes.StoreDTO>;
|
|
22
|
+
create_(data: StoreTypes.CreateStoreDTO[], sharedContext?: Context): Promise<Store[]>;
|
|
23
|
+
upsert(data: StoreTypes.UpsertStoreDTO[], sharedContext?: Context): Promise<StoreTypes.StoreDTO[]>;
|
|
24
|
+
upsert(data: StoreTypes.UpsertStoreDTO, sharedContext?: Context): Promise<StoreTypes.StoreDTO>;
|
|
25
|
+
update(id: string, data: StoreTypes.UpdateStoreDTO, sharedContext?: Context): Promise<StoreTypes.StoreDTO>;
|
|
26
|
+
update(selector: StoreTypes.FilterableStoreProps, data: StoreTypes.UpdateStoreDTO, sharedContext?: Context): Promise<StoreTypes.StoreDTO[]>;
|
|
27
|
+
protected update_(data: UpdateStoreInput[], sharedContext?: Context): Promise<Store[]>;
|
|
28
|
+
private static normalizeInput;
|
|
29
|
+
}
|
|
30
|
+
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 __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 _models_1 = require("../models");
|
|
18
|
+
const joiner_config_1 = require("../joiner-config");
|
|
19
|
+
const generateMethodForModels = [];
|
|
20
|
+
class StoreModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFactory(_models_1.Store, generateMethodForModels, joiner_config_1.entityNameToLinkableKeysMap) {
|
|
21
|
+
constructor({ baseRepository, storeService }, moduleDeclaration) {
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
super(...arguments);
|
|
24
|
+
this.moduleDeclaration = moduleDeclaration;
|
|
25
|
+
this.baseRepository_ = baseRepository;
|
|
26
|
+
this.storeService_ = storeService;
|
|
27
|
+
}
|
|
28
|
+
__joinerConfig() {
|
|
29
|
+
return joiner_config_1.joinerConfig;
|
|
30
|
+
}
|
|
31
|
+
async create(data, sharedContext = {}) {
|
|
32
|
+
const input = Array.isArray(data) ? data : [data];
|
|
33
|
+
const result = await this.create_(input, sharedContext);
|
|
34
|
+
return await this.baseRepository_.serialize(Array.isArray(data) ? result : result[0]);
|
|
35
|
+
}
|
|
36
|
+
async create_(data, sharedContext = {}) {
|
|
37
|
+
let normalizedInput = StoreModuleService.normalizeInput(data);
|
|
38
|
+
return await this.storeService_.create(normalizedInput, sharedContext);
|
|
39
|
+
}
|
|
40
|
+
async upsert(data, sharedContext = {}) {
|
|
41
|
+
const input = Array.isArray(data) ? data : [data];
|
|
42
|
+
const forUpdate = input.filter((store) => !!store.id);
|
|
43
|
+
const forCreate = input.filter((store) => !store.id);
|
|
44
|
+
const operations = [];
|
|
45
|
+
if (forCreate.length) {
|
|
46
|
+
operations.push(this.create_(forCreate, sharedContext));
|
|
47
|
+
}
|
|
48
|
+
if (forUpdate.length) {
|
|
49
|
+
operations.push(this.update_(forUpdate, sharedContext));
|
|
50
|
+
}
|
|
51
|
+
const result = (await (0, utils_1.promiseAll)(operations)).flat();
|
|
52
|
+
return await this.baseRepository_.serialize(Array.isArray(data) ? result : result[0]);
|
|
53
|
+
}
|
|
54
|
+
async update(idOrSelector, data, sharedContext = {}) {
|
|
55
|
+
let normalizedInput = [];
|
|
56
|
+
if ((0, utils_1.isString)(idOrSelector)) {
|
|
57
|
+
normalizedInput = [{ id: idOrSelector, ...data }];
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const stores = await this.storeService_.list(idOrSelector, {}, sharedContext);
|
|
61
|
+
normalizedInput = stores.map((store) => ({
|
|
62
|
+
id: store.id,
|
|
63
|
+
...data,
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
const updateResult = await this.update_(normalizedInput, sharedContext);
|
|
67
|
+
const stores = await this.baseRepository_.serialize(updateResult);
|
|
68
|
+
return (0, utils_1.isString)(idOrSelector) ? stores[0] : stores;
|
|
69
|
+
}
|
|
70
|
+
async update_(data, sharedContext = {}) {
|
|
71
|
+
const normalizedInput = StoreModuleService.normalizeInput(data);
|
|
72
|
+
return await this.storeService_.update(normalizedInput, sharedContext);
|
|
73
|
+
}
|
|
74
|
+
static normalizeInput(stores) {
|
|
75
|
+
return stores.map((store) => (0, utils_1.removeUndefined)({
|
|
76
|
+
...store,
|
|
77
|
+
name: store.name?.trim(),
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.default = StoreModuleService;
|
|
82
|
+
__decorate([
|
|
83
|
+
(0, utils_1.InjectManager)("baseRepository_"),
|
|
84
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
|
85
|
+
__metadata("design:type", Function),
|
|
86
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
87
|
+
__metadata("design:returntype", Promise)
|
|
88
|
+
], StoreModuleService.prototype, "create", null);
|
|
89
|
+
__decorate([
|
|
90
|
+
(0, utils_1.InjectTransactionManager)("baseRepository_"),
|
|
91
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
|
92
|
+
__metadata("design:type", Function),
|
|
93
|
+
__metadata("design:paramtypes", [Array, Object]),
|
|
94
|
+
__metadata("design:returntype", Promise)
|
|
95
|
+
], StoreModuleService.prototype, "create_", null);
|
|
96
|
+
__decorate([
|
|
97
|
+
(0, utils_1.InjectTransactionManager)("baseRepository_"),
|
|
98
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
|
99
|
+
__metadata("design:type", Function),
|
|
100
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
101
|
+
__metadata("design:returntype", Promise)
|
|
102
|
+
], StoreModuleService.prototype, "upsert", null);
|
|
103
|
+
__decorate([
|
|
104
|
+
(0, utils_1.InjectManager)("baseRepository_"),
|
|
105
|
+
__param(2, (0, utils_1.MedusaContext)()),
|
|
106
|
+
__metadata("design:type", Function),
|
|
107
|
+
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
108
|
+
__metadata("design:returntype", Promise)
|
|
109
|
+
], StoreModuleService.prototype, "update", null);
|
|
110
|
+
__decorate([
|
|
111
|
+
(0, utils_1.InjectTransactionManager)("baseRepository_"),
|
|
112
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
|
113
|
+
__metadata("design:type", Function),
|
|
114
|
+
__metadata("design:paramtypes", [Array, Object]),
|
|
115
|
+
__metadata("design:returntype", Promise)
|
|
116
|
+
], StoreModuleService.prototype, "update_", null);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { StoreTypes } from "@medusajs/types";
|
|
2
|
+
import { IEventBusModuleService, Logger } from "@medusajs/types";
|
|
3
|
+
export type InitializeModuleInjectableDependencies = {
|
|
4
|
+
logger?: Logger;
|
|
5
|
+
eventBusService?: IEventBusModuleService;
|
|
6
|
+
};
|
|
7
|
+
export type UpdateStoreInput = StoreTypes.UpdateStoreDTO & {
|
|
8
|
+
id: string;
|
|
9
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@medusajs/store",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Medusa Store 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-store-seed": "dist/scripts/bin/run-seed.js"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/medusajs/medusa",
|
|
19
|
+
"directory": "packages/store"
|
|
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 --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": "workspace:^",
|
|
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.9-next-20240305095805",
|
|
52
|
+
"@medusajs/types": "1.11.14-next-20240305095805",
|
|
53
|
+
"@medusajs/utils": "1.11.7-next-20240305095805",
|
|
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
|
+
}
|