@medusajs/inventory 1.0.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.
Files changed (41) hide show
  1. package/dist/config.d.ts +1 -0
  2. package/dist/config.js +5 -0
  3. package/dist/config.js.map +1 -0
  4. package/dist/index.d.ts +7 -0
  5. package/dist/index.js +36 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/loaders/connection.d.ts +5 -0
  8. package/dist/loaders/connection.js +64 -0
  9. package/dist/loaders/connection.js.map +1 -0
  10. package/dist/migrations/schema-migrations/1665748086258-inventory_setup.d.ts +13 -0
  11. package/dist/migrations/schema-migrations/1665748086258-inventory_setup.js +131 -0
  12. package/dist/migrations/schema-migrations/1665748086258-inventory_setup.js.map +1 -0
  13. package/dist/models/index.d.ts +3 -0
  14. package/dist/models/index.js +20 -0
  15. package/dist/models/index.js.map +1 -0
  16. package/dist/models/inventory-item.d.ts +15 -0
  17. package/dist/models/inventory-item.js +95 -0
  18. package/dist/models/inventory-item.js.map +1 -0
  19. package/dist/models/inventory-level.d.ts +10 -0
  20. package/dist/models/inventory-level.js +77 -0
  21. package/dist/models/inventory-level.js.map +1 -0
  22. package/dist/models/reservation-item.d.ts +9 -0
  23. package/dist/models/reservation-item.js +73 -0
  24. package/dist/models/reservation-item.js.map +1 -0
  25. package/dist/services/index.d.ts +4 -0
  26. package/dist/services/index.js +15 -0
  27. package/dist/services/index.js.map +1 -0
  28. package/dist/services/inventory-item.d.ts +53 -0
  29. package/dist/services/inventory-item.js +289 -0
  30. package/dist/services/inventory-item.js.map +1 -0
  31. package/dist/services/inventory-level.d.ts +89 -0
  32. package/dist/services/inventory-level.js +411 -0
  33. package/dist/services/inventory-level.js.map +1 -0
  34. package/dist/services/inventory.d.ts +150 -0
  35. package/dist/services/inventory.js +496 -0
  36. package/dist/services/inventory.js.map +1 -0
  37. package/dist/services/reservation-item.d.ts +68 -0
  38. package/dist/services/reservation-item.js +385 -0
  39. package/dist/services/reservation-item.js.map +1 -0
  40. package/jest.config.js +13 -0
  41. package/package.json +37 -0
@@ -0,0 +1,15 @@
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.InventoryService = exports.ReservationItemService = exports.InventoryItemService = exports.InventoryLevelService = void 0;
7
+ var inventory_level_1 = require("./inventory-level");
8
+ Object.defineProperty(exports, "InventoryLevelService", { enumerable: true, get: function () { return __importDefault(inventory_level_1).default; } });
9
+ var inventory_item_1 = require("./inventory-item");
10
+ Object.defineProperty(exports, "InventoryItemService", { enumerable: true, get: function () { return __importDefault(inventory_item_1).default; } });
11
+ var reservation_item_1 = require("./reservation-item");
12
+ Object.defineProperty(exports, "ReservationItemService", { enumerable: true, get: function () { return __importDefault(reservation_item_1).default; } });
13
+ var inventory_1 = require("./inventory");
14
+ Object.defineProperty(exports, "InventoryService", { enumerable: true, get: function () { return __importDefault(inventory_1).default; } });
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;AAAA,qDAAoE;AAA3D,yIAAA,OAAO,OAAyB;AACzC,mDAAkE;AAAzD,uIAAA,OAAO,OAAwB;AACxC,uDAAsE;AAA7D,2IAAA,OAAO,OAA0B;AAC1C,yCAAyD;AAAhD,8HAAA,OAAO,OAAoB"}
@@ -0,0 +1,53 @@
1
+ import { DeepPartial } from "typeorm";
2
+ import { FindConfig, IEventBusService, FilterableInventoryItemProps, CreateInventoryItemInput } from "@medusajs/medusa";
3
+ import { InventoryItem } from "../models";
4
+ declare type InjectedDependencies = {
5
+ eventBusService: IEventBusService;
6
+ };
7
+ export default class InventoryItemService {
8
+ static Events: {
9
+ CREATED: string;
10
+ UPDATED: string;
11
+ DELETED: string;
12
+ };
13
+ protected readonly eventBusService_: IEventBusService;
14
+ constructor({ eventBusService }: InjectedDependencies);
15
+ private getManager;
16
+ /**
17
+ * @param selector - Filter options for inventory items.
18
+ * @param config - Configuration for query.
19
+ * @return Resolves to the list of inventory items that match the filter.
20
+ */
21
+ list(selector?: FilterableInventoryItemProps, config?: FindConfig<InventoryItem>): Promise<InventoryItem[]>;
22
+ private getListQuery;
23
+ /**
24
+ * @param selector - Filter options for inventory items.
25
+ * @param config - Configuration for query.
26
+ * @return - Resolves to the list of inventory items that match the filter and the count of all matching items.
27
+ */
28
+ listAndCount(selector?: FilterableInventoryItemProps, config?: FindConfig<InventoryItem>): Promise<[InventoryItem[], number]>;
29
+ /**
30
+ * Retrieves an inventory item by its id.
31
+ * @param inventoryItemId - the id of the inventory item to retrieve.
32
+ * @param config - the configuration options for the find operation.
33
+ * @return The retrieved inventory item.
34
+ * @throws If the inventory item id is not defined or if the inventory item is not found.
35
+ */
36
+ retrieve(inventoryItemId: string, config?: FindConfig<InventoryItem>): Promise<InventoryItem>;
37
+ /**
38
+ * @param input - Input for creating a new inventory item.
39
+ * @return The newly created inventory item.
40
+ */
41
+ create(data: CreateInventoryItemInput): Promise<InventoryItem>;
42
+ /**
43
+ * @param inventoryItemId - The id of the inventory item to update.
44
+ * @param update - The updates to apply to the inventory item.
45
+ * @return The updated inventory item.
46
+ */
47
+ update(inventoryItemId: string, data: Omit<DeepPartial<InventoryItem>, "id" | "created_at" | "metadata" | "deleted_at">): Promise<InventoryItem>;
48
+ /**
49
+ * @param inventoryItemId - The id of the inventory item to delete.
50
+ */
51
+ delete(inventoryItemId: string): Promise<void>;
52
+ }
53
+ export {};
@@ -0,0 +1,289 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __read = (this && this.__read) || function (o, n) {
39
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
40
+ if (!m) return o;
41
+ var i = m.call(o), r, ar = [], e;
42
+ try {
43
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
44
+ }
45
+ catch (error) { e = { error: error }; }
46
+ finally {
47
+ try {
48
+ if (r && !r.done && (m = i["return"])) m.call(i);
49
+ }
50
+ finally { if (e) throw e.error; }
51
+ }
52
+ return ar;
53
+ };
54
+ Object.defineProperty(exports, "__esModule", { value: true });
55
+ var typeorm_1 = require("typeorm");
56
+ var medusa_core_utils_1 = require("medusa-core-utils");
57
+ var medusa_1 = require("@medusajs/medusa");
58
+ var models_1 = require("../models");
59
+ var config_1 = require("../config");
60
+ var InventoryItemService = /** @class */ (function () {
61
+ function InventoryItemService(_a) {
62
+ var eventBusService = _a.eventBusService;
63
+ this.eventBusService_ = eventBusService;
64
+ }
65
+ InventoryItemService.prototype.getManager = function () {
66
+ var connection = (0, typeorm_1.getConnection)(config_1.CONNECTION_NAME);
67
+ return connection.manager;
68
+ };
69
+ /**
70
+ * @param selector - Filter options for inventory items.
71
+ * @param config - Configuration for query.
72
+ * @return Resolves to the list of inventory items that match the filter.
73
+ */
74
+ InventoryItemService.prototype.list = function (selector, config) {
75
+ if (selector === void 0) { selector = {}; }
76
+ if (config === void 0) { config = { relations: [], skip: 0, take: 10 }; }
77
+ return __awaiter(this, void 0, void 0, function () {
78
+ var queryBuilder;
79
+ return __generator(this, function (_a) {
80
+ switch (_a.label) {
81
+ case 0:
82
+ queryBuilder = this.getListQuery(selector, config);
83
+ return [4 /*yield*/, queryBuilder.getMany()];
84
+ case 1: return [2 /*return*/, _a.sent()];
85
+ }
86
+ });
87
+ });
88
+ };
89
+ InventoryItemService.prototype.getListQuery = function (selector, config) {
90
+ if (selector === void 0) { selector = {}; }
91
+ if (config === void 0) { config = { relations: [], skip: 0, take: 10 }; }
92
+ var manager = this.getManager();
93
+ var inventoryItemRepository = manager.getRepository(models_1.InventoryItem);
94
+ var query = (0, medusa_1.buildQuery)(selector, config);
95
+ var queryBuilder = inventoryItemRepository.createQueryBuilder("inv_item");
96
+ if (query.where.q) {
97
+ query.where.sku = (0, typeorm_1.ILike)("%".concat(query.where.q, "%"));
98
+ delete query.where.q;
99
+ }
100
+ if ("location_id" in query.where) {
101
+ var locationIds = Array.isArray(selector.location_id)
102
+ ? selector.location_id
103
+ : [selector.location_id];
104
+ queryBuilder.innerJoin("inventory_level", "level", "level.inventory_item_id = inv_item.id AND level.location_id IN (:...locationIds)", { locationIds: locationIds });
105
+ delete query.where.location_id;
106
+ }
107
+ if (query.take) {
108
+ queryBuilder.take(query.take);
109
+ }
110
+ if (query.skip) {
111
+ queryBuilder.skip(query.skip);
112
+ }
113
+ if (query.where) {
114
+ queryBuilder.where(query.where);
115
+ }
116
+ if (query.select) {
117
+ queryBuilder.select(query.select.map(function (s) { return "inv_item." + s; }));
118
+ }
119
+ if (query.order) {
120
+ var toSelect_1 = [];
121
+ var parsed = Object.entries(query.order).reduce(function (acc, _a) {
122
+ var _b = __read(_a, 2), k = _b[0], v = _b[1];
123
+ var key = "inv_item.".concat(k);
124
+ toSelect_1.push(key);
125
+ acc[key] = v;
126
+ return acc;
127
+ }, {});
128
+ queryBuilder.addSelect(toSelect_1);
129
+ queryBuilder.orderBy(parsed);
130
+ }
131
+ return queryBuilder;
132
+ };
133
+ /**
134
+ * @param selector - Filter options for inventory items.
135
+ * @param config - Configuration for query.
136
+ * @return - Resolves to the list of inventory items that match the filter and the count of all matching items.
137
+ */
138
+ InventoryItemService.prototype.listAndCount = function (selector, config) {
139
+ if (selector === void 0) { selector = {}; }
140
+ if (config === void 0) { config = { relations: [], skip: 0, take: 10 }; }
141
+ return __awaiter(this, void 0, void 0, function () {
142
+ var queryBuilder;
143
+ return __generator(this, function (_a) {
144
+ switch (_a.label) {
145
+ case 0:
146
+ queryBuilder = this.getListQuery(selector, config);
147
+ return [4 /*yield*/, queryBuilder.getManyAndCount()];
148
+ case 1: return [2 /*return*/, _a.sent()];
149
+ }
150
+ });
151
+ });
152
+ };
153
+ /**
154
+ * Retrieves an inventory item by its id.
155
+ * @param inventoryItemId - the id of the inventory item to retrieve.
156
+ * @param config - the configuration options for the find operation.
157
+ * @return The retrieved inventory item.
158
+ * @throws If the inventory item id is not defined or if the inventory item is not found.
159
+ */
160
+ InventoryItemService.prototype.retrieve = function (inventoryItemId, config) {
161
+ if (config === void 0) { config = {}; }
162
+ return __awaiter(this, void 0, void 0, function () {
163
+ var manager, itemRepository, query, _a, inventoryItem;
164
+ return __generator(this, function (_b) {
165
+ switch (_b.label) {
166
+ case 0:
167
+ if (!(0, medusa_core_utils_1.isDefined)(inventoryItemId)) {
168
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "\"inventoryItemId\" must be defined");
169
+ }
170
+ manager = this.getManager();
171
+ itemRepository = manager.getRepository(models_1.InventoryItem);
172
+ query = (0, medusa_1.buildQuery)({ id: inventoryItemId }, config);
173
+ return [4 /*yield*/, itemRepository.find(query)];
174
+ case 1:
175
+ _a = __read.apply(void 0, [_b.sent(), 1]), inventoryItem = _a[0];
176
+ if (!inventoryItem) {
177
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "InventoryItem with id ".concat(inventoryItemId, " was not found"));
178
+ }
179
+ return [2 /*return*/, inventoryItem];
180
+ }
181
+ });
182
+ });
183
+ };
184
+ /**
185
+ * @param input - Input for creating a new inventory item.
186
+ * @return The newly created inventory item.
187
+ */
188
+ InventoryItemService.prototype.create = function (data) {
189
+ return __awaiter(this, void 0, void 0, function () {
190
+ var manager, itemRepository, inventoryItem, result;
191
+ return __generator(this, function (_a) {
192
+ switch (_a.label) {
193
+ case 0:
194
+ manager = this.getManager();
195
+ itemRepository = manager.getRepository(models_1.InventoryItem);
196
+ inventoryItem = itemRepository.create({
197
+ sku: data.sku,
198
+ origin_country: data.origin_country,
199
+ metadata: data.metadata,
200
+ hs_code: data.hs_code,
201
+ mid_code: data.mid_code,
202
+ material: data.material,
203
+ weight: data.weight,
204
+ length: data.length,
205
+ height: data.height,
206
+ width: data.width,
207
+ requires_shipping: data.requires_shipping,
208
+ });
209
+ return [4 /*yield*/, itemRepository.save(inventoryItem)];
210
+ case 1:
211
+ result = _a.sent();
212
+ return [4 /*yield*/, this.eventBusService_.emit(InventoryItemService.Events.CREATED, {
213
+ id: result.id,
214
+ })];
215
+ case 2:
216
+ _a.sent();
217
+ return [2 /*return*/, result];
218
+ }
219
+ });
220
+ });
221
+ };
222
+ /**
223
+ * @param inventoryItemId - The id of the inventory item to update.
224
+ * @param update - The updates to apply to the inventory item.
225
+ * @return The updated inventory item.
226
+ */
227
+ InventoryItemService.prototype.update = function (inventoryItemId, data) {
228
+ return __awaiter(this, void 0, void 0, function () {
229
+ var manager, itemRepository, item, shouldUpdate;
230
+ return __generator(this, function (_a) {
231
+ switch (_a.label) {
232
+ case 0:
233
+ manager = this.getManager();
234
+ itemRepository = manager.getRepository(models_1.InventoryItem);
235
+ return [4 /*yield*/, this.retrieve(inventoryItemId)];
236
+ case 1:
237
+ item = _a.sent();
238
+ shouldUpdate = Object.keys(data).some(function (key) {
239
+ return item[key] !== data[key];
240
+ });
241
+ if (!shouldUpdate) return [3 /*break*/, 4];
242
+ itemRepository.merge(item, data);
243
+ return [4 /*yield*/, itemRepository.save(item)];
244
+ case 2:
245
+ _a.sent();
246
+ return [4 /*yield*/, this.eventBusService_.emit(InventoryItemService.Events.UPDATED, {
247
+ id: item.id,
248
+ })];
249
+ case 3:
250
+ _a.sent();
251
+ _a.label = 4;
252
+ case 4: return [2 /*return*/, item];
253
+ }
254
+ });
255
+ });
256
+ };
257
+ /**
258
+ * @param inventoryItemId - The id of the inventory item to delete.
259
+ */
260
+ InventoryItemService.prototype.delete = function (inventoryItemId) {
261
+ return __awaiter(this, void 0, void 0, function () {
262
+ var manager, itemRepository;
263
+ return __generator(this, function (_a) {
264
+ switch (_a.label) {
265
+ case 0:
266
+ manager = this.getManager();
267
+ itemRepository = manager.getRepository(models_1.InventoryItem);
268
+ return [4 /*yield*/, itemRepository.softRemove({ id: inventoryItemId })];
269
+ case 1:
270
+ _a.sent();
271
+ return [4 /*yield*/, this.eventBusService_.emit(InventoryItemService.Events.DELETED, {
272
+ id: inventoryItemId,
273
+ })];
274
+ case 2:
275
+ _a.sent();
276
+ return [2 /*return*/];
277
+ }
278
+ });
279
+ });
280
+ };
281
+ InventoryItemService.Events = {
282
+ CREATED: "inventory-item.created",
283
+ UPDATED: "inventory-item.updated",
284
+ DELETED: "inventory-item.deleted",
285
+ };
286
+ return InventoryItemService;
287
+ }());
288
+ exports.default = InventoryItemService;
289
+ //# sourceMappingURL=inventory-item.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inventory-item.js","sourceRoot":"","sources":["../../src/services/inventory-item.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAA8E;AAC9E,uDAA0D;AAC1D,2CAMyB;AAEzB,oCAAyC;AACzC,oCAA2C;AAM3C;IASE,8BAAY,EAAyC;YAAvC,eAAe,qBAAA;QAC3B,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAA;IACzC,CAAC;IAEO,yCAAU,GAAlB;QACE,IAAM,UAAU,GAAG,IAAA,uBAAa,EAAC,wBAAe,CAAC,CAAA;QACjD,OAAO,UAAU,CAAC,OAAO,CAAA;IAC3B,CAAC;IAED;;;;OAIG;IACG,mCAAI,GAAV,UACE,QAA2C,EAC3C,MAAwE;QADxE,yBAAA,EAAA,aAA2C;QAC3C,uBAAA,EAAA,WAAsC,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;;;;;;wBAElE,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;wBACjD,qBAAM,YAAY,CAAC,OAAO,EAAE,EAAA;4BAAnC,sBAAO,SAA4B,EAAA;;;;KACpC;I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F,SAEE,CAAA;;4BAGJ,sBAAO,IAAI,EAAA;;;;KACZ;IAED;;OAEG;IACG,qCAAM,GAAZ,UAAa,eAAuB;;;;;;wBAC5B,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAA;wBAC3B,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC,sBAAa,CAAC,CAAA;wBAE3D,qBAAM,cAAc,CAAC,UAAU,CAAC,EAAE,EAAE,EAAE,eAAe,EAAE,CAAC,EAAA;;wBAAxD,SAAwD,CAAA;wBAExD,qBAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,OAAO,EAAE;gCACpE,EAAE,EAAE,eAAe;6BACpB,CAAC,EAAA;;wBAFF,SAEE,CAAA;;;;;KACH;IAvNM,2BAAM,GAAG;QACd,OAAO,EAAE,wBAAwB;QACjC,OAAO,EAAE,wBAAwB;QACjC,OAAO,EAAE,wBAAwB;KAClC,CAAA;IAoNH,2BAAC;CAAA,AAzND,IAyNC;kBAzNoB,oBAAoB"}
@@ -0,0 +1,89 @@
1
+ import { DeepPartial, EntityManager } from "typeorm";
2
+ import { FindConfig, FilterableInventoryLevelProps, CreateInventoryLevelInput, IEventBusService, TransactionBaseService } from "@medusajs/medusa";
3
+ import { InventoryLevel } from "../models";
4
+ declare type InjectedDependencies = {
5
+ eventBusService: IEventBusService;
6
+ };
7
+ export default class InventoryLevelService extends TransactionBaseService {
8
+ static Events: {
9
+ CREATED: string;
10
+ UPDATED: string;
11
+ DELETED: string;
12
+ };
13
+ protected manager_: EntityManager;
14
+ protected transactionManager_: EntityManager | undefined;
15
+ protected readonly eventBusService_: IEventBusService;
16
+ constructor({ eventBusService }: InjectedDependencies);
17
+ private getManager;
18
+ /**
19
+ * Retrieves a list of inventory levels based on the provided selector and configuration.
20
+ * @param selector - An object containing filterable properties for inventory levels.
21
+ * @param config - An object containing configuration options for the query.
22
+ * @return Array of inventory levels.
23
+ */
24
+ list(selector?: FilterableInventoryLevelProps, config?: FindConfig<InventoryLevel>): Promise<InventoryLevel[]>;
25
+ /**
26
+ * Retrieves a list of inventory levels and a count based on the provided selector and configuration.
27
+ * @param selector - An object containing filterable properties for inventory levels.
28
+ * @param config - An object containing configuration options for the query.
29
+ * @return An array of inventory levels and a count.
30
+ */
31
+ listAndCount(selector?: FilterableInventoryLevelProps, config?: FindConfig<InventoryLevel>): Promise<[InventoryLevel[], number]>;
32
+ /**
33
+ * Retrieves a single inventory level by its ID.
34
+ * @param inventoryLevelId - The ID of the inventory level to retrieve.
35
+ * @param config - An object containing configuration options for the query.
36
+ * @return A inventory level.
37
+ * @throws If the inventory level ID is not defined or the given ID was not found.
38
+ */
39
+ retrieve(inventoryLevelId: string, config?: FindConfig<InventoryLevel>): Promise<InventoryLevel>;
40
+ /**
41
+ * Creates a new inventory level.
42
+ * @param data - An object containing the properties for the new inventory level.
43
+ * @return The created inventory level.
44
+ */
45
+ create(data: CreateInventoryLevelInput): Promise<InventoryLevel>;
46
+ /**
47
+ * Updates an existing inventory level.
48
+ * @param inventoryLevelId - The ID of the inventory level to update.
49
+ * @param data - An object containing the properties to update on the inventory level.
50
+ * @param autoSave - A flag indicating whether to save the changes automatically.
51
+ * @return The updated inventory level.
52
+ * @throws If the inventory level ID is not defined or the given ID was not found.
53
+ */
54
+ update(inventoryLevelId: string, data: Omit<DeepPartial<InventoryLevel>, "id" | "created_at" | "metadata" | "deleted_at">): Promise<InventoryLevel>;
55
+ /**
56
+ * Adjust the reserved quantity for an inventory item at a specific location.
57
+ * @param inventoryItemId - The ID of the inventory item.
58
+ * @param locationId - The ID of the location.
59
+ * @param quantity - The quantity to adjust from the reserved quantity.
60
+ */
61
+ adjustReservedQuantity(inventoryItemId: string, locationId: string, quantity: number): Promise<void>;
62
+ /**
63
+ * Deletes an inventory level by ID.
64
+ * @param inventoryLevelId - The ID of the inventory level to delete.
65
+ */
66
+ delete(inventoryLevelId: string): Promise<void>;
67
+ /**
68
+ * Gets the total stocked quantity for a specific inventory item at multiple locations.
69
+ * @param inventoryItemId - The ID of the inventory item.
70
+ * @param locationIds - The IDs of the locations.
71
+ * @return The total stocked quantity.
72
+ */
73
+ getStockedQuantity(inventoryItemId: string, locationIds: string[]): Promise<number>;
74
+ /**
75
+ * Gets the total available quantity for a specific inventory item at multiple locations.
76
+ * @param inventoryItemId - The ID of the inventory item.
77
+ * @param locationIds - The IDs of the locations.
78
+ * @return The total available quantity.
79
+ */
80
+ getAvailableQuantity(inventoryItemId: string, locationIds: string[]): Promise<number>;
81
+ /**
82
+ * Gets the total reserved quantity for a specific inventory item at multiple locations.
83
+ * @param inventoryItemId - The ID of the inventory item.
84
+ * @param locationIds - The IDs of the locations.
85
+ * @return The total reserved quantity.
86
+ */
87
+ getReservedQuantity(inventoryItemId: string, locationIds: string[]): Promise<number>;
88
+ }
89
+ export {};