@medusajs/store 0.1.2-snapshot-20240718083016 → 0.1.2-snapshot-20240719133408

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.ts CHANGED
@@ -1,8 +1,6 @@
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;
1
+ import { StoreModuleService } from "./services";
2
+ declare const _default: import("@medusajs/types").ModuleExports<typeof StoreModuleService> & {
3
+ linkable: Record<string, any>;
4
+ };
5
+ export default _default;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;;;;AAG9C,wBAEE"}
package/dist/index.js CHANGED
@@ -1,29 +1,7 @@
1
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
2
  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,
3
+ const _services_1 = require("./services");
4
+ const utils_1 = require("@medusajs/utils");
5
+ exports.default = (0, utils_1.Module)(utils_1.Modules.STORE, {
6
+ service: _services_1.StoreModuleService,
26
7
  });
27
- exports.runMigrations = module_definition_1.moduleDefinition.runMigrations;
28
- exports.revertMigration = module_definition_1.moduleDefinition.revertMigration;
29
- exports.default = module_definition_1.moduleDefinition;
@@ -2,3 +2,4 @@ import { Migration } from "@mikro-orm/migrations";
2
2
  export declare class InitialSetup20240226130829 extends Migration {
3
3
  up(): Promise<void>;
4
4
  }
5
+ //# sourceMappingURL=InitialSetup20240227075933.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InitialSetup20240227075933.d.ts","sourceRoot":"","sources":["../../src/migrations/InitialSetup20240227075933.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD,qBAAa,0BAA2B,SAAQ,SAAS;IACjD,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;CA8D1B"}
@@ -0,0 +1,5 @@
1
+ import { Migration } from "@mikro-orm/migrations";
2
+ export declare class Migration20240621145944 extends Migration {
3
+ up(): Promise<void>;
4
+ }
5
+ //# sourceMappingURL=Migration20240621145944.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration20240621145944.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20240621145944.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD,qBAAa,uBAAwB,SAAQ,SAAS;IAC9C,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;CAiB1B"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20240621145944 = void 0;
4
+ const migrations_1 = require("@mikro-orm/migrations");
5
+ class Migration20240621145944 extends migrations_1.Migration {
6
+ async up() {
7
+ this.addSql('create table if not exists "store_currency" ("id" text not null, "currency_code" text not null, "is_default" boolean not null default false, "store_id" text null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "store_currency_pkey" primary key ("id"));');
8
+ this.addSql('CREATE INDEX IF NOT EXISTS "IDX_store_currency_deleted_at" ON "store_currency" (deleted_at) WHERE deleted_at IS NOT NULL;');
9
+ this.addSql('alter table if exists "store_currency" add constraint "store_currency_store_id_foreign" foreign key ("store_id") references "store" ("id") on update cascade on delete cascade;');
10
+ this.addSql('alter table if exists "store" drop column if exists "supported_currency_codes";');
11
+ this.addSql('alter table if exists "store" drop column if exists "default_currency_code";');
12
+ }
13
+ }
14
+ exports.Migration20240621145944 = Migration20240621145944;
@@ -0,0 +1,14 @@
1
+ import Store from "./store";
2
+ export default class StoreCurrency {
3
+ id: string;
4
+ currency_code: string;
5
+ is_default?: boolean;
6
+ store_id: string | null;
7
+ store: Store | null;
8
+ created_at: Date;
9
+ updated_at: Date;
10
+ deleted_at: Date | null;
11
+ onCreate(): void;
12
+ onInit(): void;
13
+ }
14
+ //# sourceMappingURL=currency.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../../src/models/currency.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,MAAM,SAAS,CAAA;AAU3B,MAAM,CAAC,OAAO,OAAO,aAAa;IAEhC,EAAE,EAAE,MAAM,CAAA;IAIV,aAAa,EAAE,MAAM,CAAA;IAGrB,UAAU,CAAC,EAAE,OAAO,CAAA;IASpB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IAMvB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;IAOnB,UAAU,EAAE,IAAI,CAAA;IAQhB,UAAU,EAAE,IAAI,CAAA;IAIhB,UAAU,EAAE,IAAI,GAAG,IAAI,CAAO;IAG9B,QAAQ;IAKR,MAAM;CAGP"}
@@ -0,0 +1,102 @@
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 store_1 = __importDefault(require("./store"));
18
+ const StoreCurrencyDeletedAtIndex = (0, utils_1.createPsqlIndexStatementHelper)({
19
+ tableName: "store_currency",
20
+ columns: "deleted_at",
21
+ where: "deleted_at IS NOT NULL",
22
+ });
23
+ let StoreCurrency = class StoreCurrency {
24
+ constructor() {
25
+ this.deleted_at = null;
26
+ }
27
+ onCreate() {
28
+ this.id = (0, utils_1.generateEntityId)(this.id, "stocur");
29
+ }
30
+ onInit() {
31
+ this.id = (0, utils_1.generateEntityId)(this.id, "stocur");
32
+ }
33
+ };
34
+ __decorate([
35
+ (0, core_1.PrimaryKey)({ columnType: "text" }),
36
+ __metadata("design:type", String)
37
+ ], StoreCurrency.prototype, "id", void 0);
38
+ __decorate([
39
+ (0, utils_1.Searchable)(),
40
+ (0, core_1.Property)({ columnType: "text" }),
41
+ __metadata("design:type", String)
42
+ ], StoreCurrency.prototype, "currency_code", void 0);
43
+ __decorate([
44
+ (0, core_1.Property)({ columnType: "boolean", default: false }),
45
+ __metadata("design:type", Boolean)
46
+ ], StoreCurrency.prototype, "is_default", void 0);
47
+ __decorate([
48
+ (0, core_1.ManyToOne)(() => store_1.default, {
49
+ columnType: "text",
50
+ fieldName: "store_id",
51
+ mapToPk: true,
52
+ nullable: true,
53
+ onDelete: "cascade",
54
+ }),
55
+ __metadata("design:type", Object)
56
+ ], StoreCurrency.prototype, "store_id", void 0);
57
+ __decorate([
58
+ (0, core_1.ManyToOne)(() => store_1.default, {
59
+ persist: false,
60
+ nullable: true,
61
+ }),
62
+ __metadata("design:type", Object)
63
+ ], StoreCurrency.prototype, "store", void 0);
64
+ __decorate([
65
+ (0, core_1.Property)({
66
+ onCreate: () => new Date(),
67
+ columnType: "timestamptz",
68
+ defaultRaw: "now()",
69
+ }),
70
+ __metadata("design:type", Date)
71
+ ], StoreCurrency.prototype, "created_at", void 0);
72
+ __decorate([
73
+ (0, core_1.Property)({
74
+ onCreate: () => new Date(),
75
+ onUpdate: () => new Date(),
76
+ columnType: "timestamptz",
77
+ defaultRaw: "now()",
78
+ }),
79
+ __metadata("design:type", Date)
80
+ ], StoreCurrency.prototype, "updated_at", void 0);
81
+ __decorate([
82
+ StoreCurrencyDeletedAtIndex.MikroORMIndex(),
83
+ (0, core_1.Property)({ columnType: "timestamptz", nullable: true }),
84
+ __metadata("design:type", Object)
85
+ ], StoreCurrency.prototype, "deleted_at", void 0);
86
+ __decorate([
87
+ (0, core_1.BeforeCreate)(),
88
+ __metadata("design:type", Function),
89
+ __metadata("design:paramtypes", []),
90
+ __metadata("design:returntype", void 0)
91
+ ], StoreCurrency.prototype, "onCreate", null);
92
+ __decorate([
93
+ (0, core_1.OnInit)(),
94
+ __metadata("design:type", Function),
95
+ __metadata("design:paramtypes", []),
96
+ __metadata("design:returntype", void 0)
97
+ ], StoreCurrency.prototype, "onInit", null);
98
+ StoreCurrency = __decorate([
99
+ (0, core_1.Entity)(),
100
+ (0, core_1.Filter)(utils_1.DALUtils.mikroOrmSoftDeletableFilterOptions)
101
+ ], StoreCurrency);
102
+ exports.default = StoreCurrency;
@@ -1 +1,3 @@
1
1
  export { default as Store } from "./store";
2
+ export { default as StoreCurrency } from "./currency";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,YAAY,CAAA"}
@@ -3,6 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Store = void 0;
6
+ exports.StoreCurrency = exports.Store = void 0;
7
7
  var store_1 = require("./store");
8
8
  Object.defineProperty(exports, "Store", { enumerable: true, get: function () { return __importDefault(store_1).default; } });
9
+ var currency_1 = require("./currency");
10
+ Object.defineProperty(exports, "StoreCurrency", { enumerable: true, get: function () { return __importDefault(currency_1).default; } });
@@ -1,12 +1,12 @@
1
1
  import { DAL } from "@medusajs/types";
2
- import { OptionalProps } from "@mikro-orm/core";
3
- type StoreOptionalProps = DAL.SoftDeletableEntityDateColumns;
2
+ import { OptionalProps, Collection } from "@mikro-orm/core";
3
+ import StoreCurrency from "./currency";
4
+ type StoreOptionalProps = DAL.SoftDeletableModelDateColumns;
4
5
  export default class Store {
5
6
  [OptionalProps]?: StoreOptionalProps;
6
7
  id: string;
7
8
  name: string;
8
- supported_currency_codes: string[];
9
- default_currency_code: string | null;
9
+ supported_currencies: Collection<StoreCurrency, object>;
10
10
  default_sales_channel_id: string | null;
11
11
  default_region_id: string | null;
12
12
  default_location_id: string | null;
@@ -18,3 +18,4 @@ export default class Store {
18
18
  onInit(): void;
19
19
  }
20
20
  export {};
21
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/models/store.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AAErC,OAAO,EAOL,aAAa,EAEb,UAAU,EAEX,MAAM,iBAAiB,CAAA;AACxB,OAAO,aAAa,MAAM,YAAY,CAAA;AAEtC,KAAK,kBAAkB,GAAG,GAAG,CAAC,6BAA6B,CAAA;AAU3D,MAAM,CAAC,OAAO,OAAO,KAAK;IACxB,CAAC,aAAa,CAAC,CAAC,EAAE,kBAAkB,CAAA;IAGpC,EAAE,EAAE,MAAM,CAAA;IAIV,IAAI,EAAE,MAAM,CAAA;IAKZ,oBAAoB,oCAAsC;IAG1D,wBAAwB,EAAE,MAAM,GAAG,IAAI,CAAO;IAG9C,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAO;IAGvC,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAO;IAGzC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAO;IAO/C,UAAU,EAAE,IAAI,CAAA;IAQhB,UAAU,EAAE,IAAI,CAAA;IAIhB,UAAU,EAAE,IAAI,GAAG,IAAI,CAAO;IAG9B,QAAQ;IAKR,MAAM;CAGP"}
@@ -8,9 +8,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  const utils_1 = require("@medusajs/utils");
13
16
  const core_1 = require("@mikro-orm/core");
17
+ const currency_1 = __importDefault(require("./currency"));
14
18
  const StoreDeletedAtIndex = (0, utils_1.createPsqlIndexStatementHelper)({
15
19
  tableName: "store",
16
20
  columns: "deleted_at",
@@ -18,8 +22,7 @@ const StoreDeletedAtIndex = (0, utils_1.createPsqlIndexStatementHelper)({
18
22
  });
19
23
  let Store = class Store {
20
24
  constructor() {
21
- this.supported_currency_codes = [];
22
- this.default_currency_code = null;
25
+ this.supported_currencies = new core_1.Collection(this);
23
26
  this.default_sales_channel_id = null;
24
27
  this.default_region_id = null;
25
28
  this.default_location_id = null;
@@ -43,13 +46,11 @@ __decorate([
43
46
  __metadata("design:type", String)
44
47
  ], Store.prototype, "name", void 0);
45
48
  __decorate([
46
- (0, core_1.Property)({ type: "array", default: "{}" }),
47
- __metadata("design:type", Array)
48
- ], Store.prototype, "supported_currency_codes", void 0);
49
- __decorate([
50
- (0, core_1.Property)({ columnType: "text", nullable: true }),
49
+ (0, core_1.OneToMany)(() => currency_1.default, (o) => o.store, {
50
+ cascade: [core_1.Cascade.PERSIST, "soft-remove"],
51
+ }),
51
52
  __metadata("design:type", Object)
52
- ], Store.prototype, "default_currency_code", void 0);
53
+ ], Store.prototype, "supported_currencies", void 0);
53
54
  __decorate([
54
55
  (0, core_1.Property)({ columnType: "text", nullable: true }),
55
56
  __metadata("design:type", Object)
@@ -1 +1,2 @@
1
1
  export { default as StoreModuleService } from "./store-module-service";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,wBAAwB,CAAA"}
@@ -1,32 +1,34 @@
1
- import { DAL, InternalModuleDeclaration, ModuleJoinerConfig, ModulesSdkTypes, IStoreModuleService, StoreTypes, Context } from "@medusajs/types";
2
- import { ModulesSdkUtils } from "@medusajs/utils";
1
+ import { Context, DAL, InternalModuleDeclaration, IStoreModuleService, ModulesSdkTypes, StoreTypes } from "@medusajs/types";
3
2
  import { Store } from "../models";
4
3
  import { UpdateStoreInput } from "../types";
5
4
  type InjectedDependencies = {
6
5
  baseRepository: DAL.RepositoryService;
7
- storeService: ModulesSdkTypes.InternalModuleService<any>;
6
+ storeService: ModulesSdkTypes.IMedusaInternalService<any>;
8
7
  };
9
- declare const StoreModuleService_base: new (container: InjectedDependencies) => ModulesSdkUtils.AbstractModuleService<InjectedDependencies, StoreTypes.StoreDTO, {
8
+ declare const StoreModuleService_base: import("@medusajs/utils/dist/modules-sdk/types/medusa-service").MedusaServiceReturnType<{
10
9
  Store: {
11
10
  dto: StoreTypes.StoreDTO;
12
11
  };
12
+ StoreCurrency: {
13
+ dto: StoreTypes.StoreCurrencyDTO;
14
+ };
13
15
  }>;
14
- export default class StoreModuleService<TEntity extends Store = Store> extends StoreModuleService_base implements IStoreModuleService {
16
+ export default class StoreModuleService extends StoreModuleService_base implements IStoreModuleService {
15
17
  protected readonly moduleDeclaration: InternalModuleDeclaration;
16
18
  protected baseRepository_: DAL.RepositoryService;
17
- protected readonly storeService_: ModulesSdkTypes.InternalModuleService<TEntity>;
19
+ protected readonly storeService_: ModulesSdkTypes.IMedusaInternalService<Store>;
18
20
  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>;
21
+ createStores(data: StoreTypes.CreateStoreDTO[], sharedContext?: Context): Promise<StoreTypes.StoreDTO[]>;
22
+ createStores(data: StoreTypes.CreateStoreDTO, sharedContext?: Context): Promise<StoreTypes.StoreDTO>;
22
23
  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[]>;
24
+ upsertStores(data: StoreTypes.UpsertStoreDTO[], sharedContext?: Context): Promise<StoreTypes.StoreDTO[]>;
25
+ upsertStores(data: StoreTypes.UpsertStoreDTO, sharedContext?: Context): Promise<StoreTypes.StoreDTO>;
26
+ updateStores(id: string, data: StoreTypes.UpdateStoreDTO, sharedContext?: Context): Promise<StoreTypes.StoreDTO>;
27
+ updateStores(selector: StoreTypes.FilterableStoreProps, data: StoreTypes.UpdateStoreDTO, sharedContext?: Context): Promise<StoreTypes.StoreDTO[]>;
27
28
  protected update_(data: UpdateStoreInput[], sharedContext?: Context): Promise<Store[]>;
28
29
  private static normalizeInput;
29
30
  private static validateCreateRequest;
30
- private validateUpdateRequest;
31
+ private static validateUpdateRequest;
31
32
  }
32
33
  export {};
34
+ //# sourceMappingURL=store-module-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store-module-service.d.ts","sourceRoot":"","sources":["../../src/services/store-module-service.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,GAAG,EACH,yBAAyB,EACzB,mBAAmB,EACnB,eAAe,EACf,UAAU,EACX,MAAM,iBAAiB,CAAA;AAaxB,OAAO,EAAE,KAAK,EAAiB,MAAM,SAAS,CAAA;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAA;AAEzC,KAAK,oBAAoB,GAAG;IAC1B,cAAc,EAAE,GAAG,CAAC,iBAAiB,CAAA;IACrC,YAAY,EAAE,eAAe,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAA;CAC1D,CAAA;;WAIU;QAAE,GAAG,EAAE,WAAW,QAAQ,CAAA;KAAE;mBACpB;QAAE,GAAG,EAAE,WAAW,gBAAgB,CAAA;KAAE;;AAHvD,MAAM,CAAC,OAAO,OAAO,kBACnB,SAAQ,uBAIR,YAAW,mBAAmB;IAO5B,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,yBAAyB;IALjE,SAAS,CAAC,eAAe,EAAE,GAAG,CAAC,iBAAiB,CAAA;IAChD,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,eAAe,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAA;gBAG7E,EAAE,cAAc,EAAE,YAAY,EAAE,EAAE,oBAAoB,EACnC,iBAAiB,EAAE,yBAAyB;IAS3D,YAAY,CAChB,IAAI,EAAE,UAAU,CAAC,cAAc,EAAE,EACjC,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;IAC3B,YAAY,CAChB,IAAI,EAAE,UAAU,CAAC,cAAc,EAC/B,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC;IAgBzB,OAAO,CACX,IAAI,EAAE,UAAU,CAAC,cAAc,EAAE,EAChB,aAAa,GAAE,OAAY,GAC3C,OAAO,CAAC,KAAK,EAAE,CAAC;IAab,YAAY,CAChB,IAAI,EAAE,UAAU,CAAC,cAAc,EAAE,EACjC,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;IAC3B,YAAY,CAChB,IAAI,EAAE,UAAU,CAAC,cAAc,EAC/B,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC;IA8BzB,YAAY,CAChB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,UAAU,CAAC,cAAc,EAC/B,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC;IACzB,YAAY,CAChB,QAAQ,EAAE,UAAU,CAAC,oBAAoB,EACzC,IAAI,EAAE,UAAU,CAAC,cAAc,EAC/B,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;cAiCjB,OAAO,CACrB,IAAI,EAAE,gBAAgB,EAAE,EACP,aAAa,GAAE,OAAY,GAC3C,OAAO,CAAC,KAAK,EAAE,CAAC;IAanB,OAAO,CAAC,MAAM,CAAC,cAAc;IAe7B,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAuCpC,OAAO,CAAC,MAAM,CAAC,qBAAqB;CAGrC"}
@@ -15,9 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const types_1 = require("@medusajs/types");
16
16
  const utils_1 = require("@medusajs/utils");
17
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) {
18
+ class StoreModuleService extends (0, utils_1.MedusaService)({ Store: _models_1.Store, StoreCurrency: _models_1.StoreCurrency }) {
21
19
  constructor({ baseRepository, storeService }, moduleDeclaration) {
22
20
  // @ts-ignore
23
21
  super(...arguments);
@@ -25,10 +23,7 @@ class StoreModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
25
23
  this.baseRepository_ = baseRepository;
26
24
  this.storeService_ = storeService;
27
25
  }
28
- __joinerConfig() {
29
- return joiner_config_1.joinerConfig;
30
- }
31
- async create(data, sharedContext = {}) {
26
+ async createStores(data, sharedContext = {}) {
32
27
  const input = Array.isArray(data) ? data : [data];
33
28
  const result = await this.create_(input, sharedContext);
34
29
  return await this.baseRepository_.serialize(Array.isArray(data) ? result : result[0]);
@@ -36,9 +31,9 @@ class StoreModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
36
31
  async create_(data, sharedContext = {}) {
37
32
  let normalizedInput = StoreModuleService.normalizeInput(data);
38
33
  StoreModuleService.validateCreateRequest(normalizedInput);
39
- return await this.storeService_.create(normalizedInput, sharedContext);
34
+ return (await this.storeService_.upsertWithReplace(normalizedInput, { relations: ["supported_currencies"] }, sharedContext)).entities;
40
35
  }
41
- async upsert(data, sharedContext = {}) {
36
+ async upsertStores(data, sharedContext = {}) {
42
37
  const input = Array.isArray(data) ? data : [data];
43
38
  const forUpdate = input.filter((store) => !!store.id);
44
39
  const forCreate = input.filter((store) => !store.id);
@@ -52,7 +47,7 @@ class StoreModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
52
47
  const result = (await (0, utils_1.promiseAll)(operations)).flat();
53
48
  return await this.baseRepository_.serialize(Array.isArray(data) ? result : result[0]);
54
49
  }
55
- async update(idOrSelector, data, sharedContext = {}) {
50
+ async updateStores(idOrSelector, data, sharedContext = {}) {
56
51
  let normalizedInput = [];
57
52
  if ((0, utils_1.isString)(idOrSelector)) {
58
53
  normalizedInput = [{ id: idOrSelector, ...data }];
@@ -70,51 +65,44 @@ class StoreModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
70
65
  }
71
66
  async update_(data, sharedContext = {}) {
72
67
  const normalizedInput = StoreModuleService.normalizeInput(data);
73
- await this.validateUpdateRequest(normalizedInput);
74
- return await this.storeService_.update(normalizedInput, sharedContext);
68
+ StoreModuleService.validateUpdateRequest(normalizedInput);
69
+ return (await this.storeService_.upsertWithReplace(normalizedInput, { relations: ["supported_currencies"] }, sharedContext)).entities;
75
70
  }
76
71
  static normalizeInput(stores) {
77
72
  return stores.map((store) => (0, utils_1.removeUndefined)({
78
73
  ...store,
74
+ supported_currencies: store.supported_currencies?.map((c) => ({
75
+ ...c,
76
+ currency_code: c.currency_code.toLowerCase(),
77
+ })),
79
78
  name: store.name?.trim(),
80
79
  }));
81
80
  }
82
81
  static validateCreateRequest(stores) {
83
82
  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}`);
83
+ if (store.supported_currencies?.length) {
84
+ const duplicates = (0, utils_1.getDuplicates)(store.supported_currencies?.map((c) => c.currency_code));
85
+ if (duplicates.length) {
86
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Duplicate currency codes: ${duplicates.join(", ")}`);
101
87
  }
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");
88
+ let seenDefault = false;
89
+ store.supported_currencies?.forEach((c) => {
90
+ if (c.is_default) {
91
+ if (seenDefault) {
92
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Only one default currency is allowed`);
93
+ }
94
+ seenDefault = true;
95
+ }
96
+ });
97
+ if (!seenDefault) {
98
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `There should be a default currency set for the store`);
114
99
  }
115
100
  }
116
101
  }
117
102
  }
103
+ static validateUpdateRequest(stores) {
104
+ StoreModuleService.validateCreateRequest(stores);
105
+ }
118
106
  }
119
107
  exports.default = StoreModuleService;
120
108
  __decorate([
@@ -123,7 +111,7 @@ __decorate([
123
111
  __metadata("design:type", Function),
124
112
  __metadata("design:paramtypes", [Object, Object]),
125
113
  __metadata("design:returntype", Promise)
126
- ], StoreModuleService.prototype, "create", null);
114
+ ], StoreModuleService.prototype, "createStores", null);
127
115
  __decorate([
128
116
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
129
117
  __param(1, (0, utils_1.MedusaContext)()),
@@ -137,14 +125,14 @@ __decorate([
137
125
  __metadata("design:type", Function),
138
126
  __metadata("design:paramtypes", [Object, Object]),
139
127
  __metadata("design:returntype", Promise)
140
- ], StoreModuleService.prototype, "upsert", null);
128
+ ], StoreModuleService.prototype, "upsertStores", null);
141
129
  __decorate([
142
130
  (0, utils_1.InjectManager)("baseRepository_"),
143
131
  __param(2, (0, utils_1.MedusaContext)()),
144
132
  __metadata("design:type", Function),
145
133
  __metadata("design:paramtypes", [Object, Object, Object]),
146
134
  __metadata("design:returntype", Promise)
147
- ], StoreModuleService.prototype, "update", null);
135
+ ], StoreModuleService.prototype, "updateStores", null);
148
136
  __decorate([
149
137
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
150
138
  __param(1, (0, utils_1.MedusaContext)()),
@@ -2,8 +2,9 @@ import { StoreTypes } from "@medusajs/types";
2
2
  import { IEventBusModuleService, Logger } from "@medusajs/types";
3
3
  export type InitializeModuleInjectableDependencies = {
4
4
  logger?: Logger;
5
- eventBusService?: IEventBusModuleService;
5
+ eventBusModuleService?: IEventBusModuleService;
6
6
  };
7
7
  export type UpdateStoreInput = StoreTypes.UpdateStoreDTO & {
8
8
  id: string;
9
9
  };
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAEhE,MAAM,MAAM,sCAAsC,GAAG;IACnD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,qBAAqB,CAAC,EAAE,sBAAsB,CAAA;CAC/C,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,cAAc,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medusajs/store",
3
- "version": "0.1.2-snapshot-20240718083016",
3
+ "version": "0.1.2-snapshot-20240719133408",
4
4
  "description": "Medusa Store module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,10 +8,7 @@
8
8
  "dist"
9
9
  ],
10
10
  "engines": {
11
- "node": ">=16"
12
- },
13
- "bin": {
14
- "medusa-store-seed": "dist/scripts/bin/run-seed.js"
11
+ "node": ">=20"
15
12
  },
16
13
  "repository": {
17
14
  "type": "git",
@@ -37,25 +34,22 @@
37
34
  "orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear"
38
35
  },
39
36
  "devDependencies": {
37
+ "@medusajs/modules-sdk": "1.13.0-snapshot-20240719133408",
38
+ "@medusajs/types": "1.12.0-snapshot-20240719133408",
40
39
  "@mikro-orm/cli": "5.9.7",
41
40
  "cross-env": "^5.2.1",
42
- "jest": "^29.6.3",
41
+ "jest": "^29.7.0",
43
42
  "medusa-test-utils": "workspace:^",
44
43
  "rimraf": "^3.0.2",
45
- "ts-jest": "^29.1.1",
46
44
  "ts-node": "^10.9.1",
47
45
  "tsc-alias": "^1.8.6",
48
46
  "typescript": "^5.1.6"
49
47
  },
50
48
  "dependencies": {
51
- "@medusajs/modules-sdk": "1.12.12-snapshot-20240718083016",
52
- "@medusajs/types": "1.11.17-snapshot-20240718083016",
53
- "@medusajs/utils": "1.11.10-snapshot-20240718083016",
49
+ "@medusajs/utils": "1.12.0-snapshot-20240719133408",
54
50
  "@mikro-orm/core": "5.9.7",
55
51
  "@mikro-orm/migrations": "5.9.7",
56
52
  "@mikro-orm/postgresql": "5.9.7",
57
- "awilix": "^8.0.0",
58
- "dotenv": "^16.4.5",
59
- "knex": "2.4.2"
53
+ "awilix": "^8.0.0"
60
54
  }
61
55
  }
@@ -1,5 +0,0 @@
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;
@@ -1,29 +0,0 @@
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
- };
@@ -1,2 +0,0 @@
1
- import { ModuleExports } from "@medusajs/types";
2
- export declare const moduleDefinition: ModuleExports;
@@ -1,58 +0,0 @@
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
- };
@@ -1 +0,0 @@
1
- export { MikroOrmBaseRepository as BaseRepository } from "@medusajs/utils";
@@ -1,5 +0,0 @@
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; } });
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- declare const _default: Promise<void>;
3
- export default _default;
@@ -1,48 +0,0 @@
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
- })();