@medusajs/sales-channel 0.1.2-snapshot-20240607093839 → 0.1.2-snapshot-20240703074611

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { moduleDefinition } from "./module-definition";
1
+ import { ModuleExports } from "@medusajs/types";
2
+ declare const moduleDefinition: ModuleExports;
2
3
  export default moduleDefinition;
3
- export * from "./types";
4
- export * from "./models";
5
- export * from "./services";
package/dist/index.js CHANGED
@@ -1,21 +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
- const module_definition_1 = require("./module-definition");
18
- exports.default = module_definition_1.moduleDefinition;
19
- __exportStar(require("./types"), exports);
20
- __exportStar(require("./models"), exports);
21
- __exportStar(require("./services"), exports);
3
+ const _services_1 = require("./services");
4
+ const moduleDefinition = {
5
+ service: _services_1.SalesChannelModuleService,
6
+ };
7
+ exports.default = moduleDefinition;
@@ -1,7 +1,3 @@
1
- import { ModuleJoinerConfig } from "@medusajs/types";
2
1
  import { MapToConfig } from "@medusajs/utils";
3
- export declare const LinkableKeys: {
4
- sales_channel_id: string;
5
- };
2
+ export declare const joinerConfig: Omit<import("@medusajs/types").ModuleJoinerConfig, "serviceName" | "primaryKeys" | "alias" | "linkableKeys"> & Required<Pick<import("@medusajs/types").ModuleJoinerConfig, "serviceName" | "primaryKeys" | "alias" | "linkableKeys">>;
6
3
  export declare const entityNameToLinkableKeysMap: MapToConfig;
7
- export declare const joinerConfig: ModuleJoinerConfig;
@@ -1,28 +1,6 @@
1
1
  "use strict";
2
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
- const _models_1 = require("./models");
6
- exports.LinkableKeys = {
7
- sales_channel_id: _models_1.SalesChannel.name,
8
- };
9
- const entityLinkableKeysMap = {};
10
- Object.entries(exports.LinkableKeys).forEach(([key, value]) => {
11
- entityLinkableKeysMap[value] ??= [];
12
- entityLinkableKeysMap[value].push({
13
- mapTo: key,
14
- valueFrom: key.split("_").pop(),
15
- });
16
- });
17
- exports.entityNameToLinkableKeysMap = entityLinkableKeysMap;
18
- exports.joinerConfig = {
19
- serviceName: modules_sdk_1.Modules.SALES_CHANNEL,
20
- primaryKeys: ["id"],
21
- linkableKeys: exports.LinkableKeys,
22
- alias: [
23
- {
24
- name: ["sales_channel", "sales_channels"],
25
- args: { entity: "SalesChannel" },
26
- },
27
- ],
28
- };
3
+ exports.entityNameToLinkableKeysMap = exports.joinerConfig = void 0;
4
+ const utils_1 = require("@medusajs/utils");
5
+ exports.joinerConfig = (0, utils_1.defineJoinerConfig)(utils_1.Modules.SALES_CHANNEL);
6
+ exports.entityNameToLinkableKeysMap = (0, utils_1.buildEntitiesNameToLinkableKeysMap)(exports.joinerConfig.linkableKeys);
@@ -41,7 +41,7 @@ __decorate([
41
41
  ], SalesChannel.prototype, "description", void 0);
42
42
  __decorate([
43
43
  (0, core_1.Property)({ columnType: "boolean", default: false }),
44
- __metadata("design:type", Object)
44
+ __metadata("design:type", Boolean)
45
45
  ], SalesChannel.prototype, "is_disabled", void 0);
46
46
  __decorate([
47
47
  (0, core_1.Property)({
@@ -1,25 +1,28 @@
1
1
  import { Context, CreateSalesChannelDTO, DAL, FilterableSalesChannelProps, InternalModuleDeclaration, ISalesChannelModuleService, ModuleJoinerConfig, ModulesSdkTypes, SalesChannelDTO, UpdateSalesChannelDTO } from "@medusajs/types";
2
- import { ModulesSdkUtils } from "@medusajs/utils";
3
2
  import { SalesChannel } from "../models";
4
3
  import { UpsertSalesChannelDTO } from "@medusajs/types";
5
4
  type InjectedDependencies = {
6
5
  baseRepository: DAL.RepositoryService;
7
- salesChannelService: ModulesSdkTypes.InternalModuleService<any>;
6
+ salesChannelService: ModulesSdkTypes.IMedusaInternalService<any>;
8
7
  };
9
- declare const SalesChannelModuleService_base: new (container: InjectedDependencies) => ModulesSdkUtils.AbstractModuleService<InjectedDependencies, SalesChannelDTO, {}>;
10
- export default class SalesChannelModuleService<TEntity extends SalesChannel = SalesChannel> extends SalesChannelModuleService_base implements ISalesChannelModuleService {
8
+ declare const SalesChannelModuleService_base: new (...args: any[]) => import("@medusajs/utils").AbstractModuleService<{
9
+ SalesChannel: {
10
+ dto: SalesChannelDTO;
11
+ };
12
+ }>;
13
+ export default class SalesChannelModuleService extends SalesChannelModuleService_base implements ISalesChannelModuleService {
11
14
  protected readonly moduleDeclaration: InternalModuleDeclaration;
12
15
  protected baseRepository_: DAL.RepositoryService;
13
- protected readonly salesChannelService_: ModulesSdkTypes.InternalModuleService<TEntity>;
16
+ protected readonly salesChannelService_: ModulesSdkTypes.IMedusaInternalService<SalesChannel>;
14
17
  constructor({ baseRepository, salesChannelService }: InjectedDependencies, moduleDeclaration: InternalModuleDeclaration);
15
18
  __joinerConfig(): ModuleJoinerConfig;
16
- create(data: CreateSalesChannelDTO[], sharedContext?: Context): Promise<SalesChannelDTO[]>;
17
- create(data: CreateSalesChannelDTO, sharedContext?: Context): Promise<SalesChannelDTO>;
18
- create_(data: CreateSalesChannelDTO[], sharedContext: Context): Promise<SalesChannel[]>;
19
- update(id: string, data: UpdateSalesChannelDTO, sharedContext?: Context): Promise<SalesChannelDTO>;
20
- update(selector: FilterableSalesChannelProps, data: UpdateSalesChannelDTO, sharedContext?: Context): Promise<SalesChannelDTO[]>;
21
- update_(data: UpdateSalesChannelDTO[], sharedContext: Context): Promise<TEntity[]>;
22
- upsert(data: UpsertSalesChannelDTO[], sharedContext?: Context): Promise<SalesChannelDTO[]>;
23
- upsert(data: UpsertSalesChannelDTO, sharedContext?: Context): Promise<SalesChannelDTO>;
19
+ createSalesChannels(data: CreateSalesChannelDTO[], sharedContext?: Context): Promise<SalesChannelDTO[]>;
20
+ createSalesChannels(data: CreateSalesChannelDTO, sharedContext?: Context): Promise<SalesChannelDTO>;
21
+ createSalesChannels_(data: CreateSalesChannelDTO[], sharedContext: Context): Promise<SalesChannel[]>;
22
+ updateSalesChannels(id: string, data: UpdateSalesChannelDTO, sharedContext?: Context): Promise<SalesChannelDTO>;
23
+ updateSalesChannels(selector: FilterableSalesChannelProps, data: UpdateSalesChannelDTO, sharedContext?: Context): Promise<SalesChannelDTO[]>;
24
+ updateSalesChannels_(data: UpdateSalesChannelDTO[], sharedContext: Context): Promise<SalesChannel[]>;
25
+ upsertSalesChannels(data: UpsertSalesChannelDTO[], sharedContext?: Context): Promise<SalesChannelDTO[]>;
26
+ upsertSalesChannels(data: UpsertSalesChannelDTO, sharedContext?: Context): Promise<SalesChannelDTO>;
24
27
  }
25
28
  export {};
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const utils_1 = require("@medusajs/utils");
16
16
  const _models_1 = require("../models");
17
17
  const joiner_config_1 = require("../joiner-config");
18
- class SalesChannelModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFactory(_models_1.SalesChannel, [], joiner_config_1.entityNameToLinkableKeysMap) {
18
+ class SalesChannelModuleService extends (0, utils_1.MedusaService)({ SalesChannel: _models_1.SalesChannel }, joiner_config_1.entityNameToLinkableKeysMap) {
19
19
  constructor({ baseRepository, salesChannelService }, moduleDeclaration) {
20
20
  // @ts-ignore
21
21
  super(...arguments);
@@ -26,17 +26,17 @@ class SalesChannelModuleService extends utils_1.ModulesSdkUtils.abstractModuleSe
26
26
  __joinerConfig() {
27
27
  return joiner_config_1.joinerConfig;
28
28
  }
29
- async create(data, sharedContext = {}) {
29
+ async createSalesChannels(data, sharedContext = {}) {
30
30
  const input = Array.isArray(data) ? data : [data];
31
- const result = await this.create_(input, sharedContext);
31
+ const result = await this.createSalesChannels_(input, sharedContext);
32
32
  return await this.baseRepository_.serialize(Array.isArray(data) ? result : result[0], {
33
33
  populate: true,
34
34
  });
35
35
  }
36
- async create_(data, sharedContext) {
36
+ async createSalesChannels_(data, sharedContext) {
37
37
  return await this.salesChannelService_.create(data, sharedContext);
38
38
  }
39
- async update(idOrSelector, data, sharedContext = {}) {
39
+ async updateSalesChannels(idOrSelector, data, sharedContext = {}) {
40
40
  let normalizedInput = [];
41
41
  if ((0, utils_1.isString)(idOrSelector)) {
42
42
  normalizedInput = [{ id: idOrSelector, ...data }];
@@ -48,24 +48,24 @@ class SalesChannelModuleService extends utils_1.ModulesSdkUtils.abstractModuleSe
48
48
  ...data,
49
49
  }));
50
50
  }
51
- const result = await this.update_(normalizedInput, sharedContext);
51
+ const result = await this.updateSalesChannels_(normalizedInput, sharedContext);
52
52
  return await this.baseRepository_.serialize(Array.isArray(data) ? result : result[0], {
53
53
  populate: true,
54
54
  });
55
55
  }
56
- async update_(data, sharedContext) {
56
+ async updateSalesChannels_(data, sharedContext) {
57
57
  return await this.salesChannelService_.update(data, sharedContext);
58
58
  }
59
- async upsert(data, sharedContext = {}) {
59
+ async upsertSalesChannels(data, sharedContext = {}) {
60
60
  const input = Array.isArray(data) ? data : [data];
61
61
  const forUpdate = input.filter((channel) => !!channel.id);
62
62
  const forCreate = input.filter((channel) => !channel.id);
63
63
  const operations = [];
64
64
  if (forCreate.length) {
65
- operations.push(this.create_(forCreate, sharedContext));
65
+ operations.push(this.createSalesChannels_(forCreate, sharedContext));
66
66
  }
67
67
  if (forUpdate.length) {
68
- operations.push(this.update_(forUpdate, sharedContext));
68
+ operations.push(this.updateSalesChannels_(forUpdate, sharedContext));
69
69
  }
70
70
  const result = (await (0, utils_1.promiseAll)(operations)).flat();
71
71
  return await this.baseRepository_.serialize(Array.isArray(data) ? result : result[0]);
@@ -78,31 +78,31 @@ __decorate([
78
78
  __metadata("design:type", Function),
79
79
  __metadata("design:paramtypes", [Object, Object]),
80
80
  __metadata("design:returntype", Promise)
81
- ], SalesChannelModuleService.prototype, "create", null);
81
+ ], SalesChannelModuleService.prototype, "createSalesChannels", null);
82
82
  __decorate([
83
83
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
84
84
  __param(1, (0, utils_1.MedusaContext)()),
85
85
  __metadata("design:type", Function),
86
86
  __metadata("design:paramtypes", [Array, Object]),
87
87
  __metadata("design:returntype", Promise)
88
- ], SalesChannelModuleService.prototype, "create_", null);
88
+ ], SalesChannelModuleService.prototype, "createSalesChannels_", null);
89
89
  __decorate([
90
90
  (0, utils_1.InjectManager)("baseRepository_"),
91
91
  __param(2, (0, utils_1.MedusaContext)()),
92
92
  __metadata("design:type", Function),
93
93
  __metadata("design:paramtypes", [Object, Object, Object]),
94
94
  __metadata("design:returntype", Promise)
95
- ], SalesChannelModuleService.prototype, "update", null);
95
+ ], SalesChannelModuleService.prototype, "updateSalesChannels", null);
96
96
  __decorate([
97
97
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
98
98
  __metadata("design:type", Function),
99
99
  __metadata("design:paramtypes", [Array, Object]),
100
100
  __metadata("design:returntype", Promise)
101
- ], SalesChannelModuleService.prototype, "update_", null);
101
+ ], SalesChannelModuleService.prototype, "updateSalesChannels_", null);
102
102
  __decorate([
103
103
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
104
104
  __param(1, (0, utils_1.MedusaContext)()),
105
105
  __metadata("design:type", Function),
106
106
  __metadata("design:paramtypes", [Object, Object]),
107
107
  __metadata("design:returntype", Promise)
108
- ], SalesChannelModuleService.prototype, "upsert", null);
108
+ ], SalesChannelModuleService.prototype, "upsertSalesChannels", null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medusajs/sales-channel",
3
- "version": "0.1.2-snapshot-20240607093839",
3
+ "version": "0.1.2-snapshot-20240703074611",
4
4
  "description": "Medusa Sales Channel 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-sales-channel-seed": "dist/scripts/bin/run-seed.js"
11
+ "node": ">=20"
15
12
  },
16
13
  "repository": {
17
14
  "type": "git",
@@ -39,18 +36,17 @@
39
36
  "devDependencies": {
40
37
  "@mikro-orm/cli": "5.9.7",
41
38
  "cross-env": "^5.2.1",
42
- "jest": "^29.6.3",
43
- "medusa-test-utils": "1.1.45-snapshot-20240607093839",
39
+ "jest": "^29.7.0",
40
+ "medusa-test-utils": "1.1.45-snapshot-20240703074611",
44
41
  "rimraf": "^3.0.2",
45
- "ts-jest": "^29.1.1",
46
42
  "ts-node": "^10.9.1",
47
43
  "tsc-alias": "^1.8.6",
48
44
  "typescript": "^5.1.6"
49
45
  },
50
46
  "dependencies": {
51
- "@medusajs/modules-sdk": "1.13.0-snapshot-20240607093839",
52
- "@medusajs/types": "1.12.0-snapshot-20240607093839",
53
- "@medusajs/utils": "1.12.0-snapshot-20240607093839",
47
+ "@medusajs/modules-sdk": "1.13.0-snapshot-20240703074611",
48
+ "@medusajs/types": "1.12.0-snapshot-20240703074611",
49
+ "@medusajs/utils": "1.12.0-snapshot-20240703074611",
54
50
  "@mikro-orm/core": "5.9.7",
55
51
  "@mikro-orm/migrations": "5.9.7",
56
52
  "@mikro-orm/postgresql": "5.9.7",
@@ -1,2 +0,0 @@
1
- import { ModuleExports } from "@medusajs/types";
2
- export declare const moduleDefinition: ModuleExports;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.moduleDefinition = void 0;
4
- const _services_1 = require("./services");
5
- const service = _services_1.SalesChannelModuleService;
6
- exports.moduleDefinition = {
7
- service,
8
- };
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- declare const _default: Promise<void>;
3
- export default _default;
@@ -1,50 +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 ProductModels = __importStar(require("../../models"));
30
- const seed_utils_1 = require("../seed-utils");
31
- const os_1 = require("os");
32
- const args = process.argv;
33
- const path = args.pop();
34
- exports.default = (async () => {
35
- const { config } = await Promise.resolve().then(() => __importStar(require("dotenv")));
36
- config();
37
- if (!path) {
38
- throw new Error(`filePath is required.${os_1.EOL}Example: medusa-product-seed <filePath>`);
39
- }
40
- const run = utils_1.ModulesSdkUtils.buildSeedScript({
41
- moduleName: modules_sdk_1.Modules.PRODUCT,
42
- models: ProductModels,
43
- pathToMigrations: __dirname + "/../../migrations",
44
- seedHandler: async ({ manager, data }) => {
45
- const { salesChannelData } = data;
46
- await (0, seed_utils_1.createSalesChannels)(manager, salesChannelData);
47
- },
48
- });
49
- await run({ path });
50
- })();
@@ -1,4 +0,0 @@
1
- import { SalesChannel } from "../models";
2
- import { RequiredEntityData } from "@mikro-orm/core";
3
- import { SqlEntityManager } from "@mikro-orm/postgresql";
4
- export declare function createSalesChannels(manager: SqlEntityManager, data: RequiredEntityData<SalesChannel>[]): Promise<SalesChannel[]>;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createSalesChannels = void 0;
4
- const _models_1 = require("../models");
5
- async function createSalesChannels(manager, data) {
6
- const channels = data.map((channel) => {
7
- return manager.create(_models_1.SalesChannel, channel);
8
- });
9
- await manager.persistAndFlush(channels);
10
- return channels;
11
- }
12
- exports.createSalesChannels = createSalesChannels;