@classytic/flow 0.1.4

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 (102) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/LICENSE +21 -0
  3. package/README.md +258 -0
  4. package/dist/allocation-policy-my_HfzdV.d.mts +23 -0
  5. package/dist/base-MWBqRFM2.mjs +16 -0
  6. package/dist/catalog-bridge-K8bdkncJ.d.mts +29 -0
  7. package/dist/cost-layer.port-iH9pvZqB.d.mts +30 -0
  8. package/dist/cost-layer.service-BQ1bs-XN.mjs +86 -0
  9. package/dist/cost-layer.service-DWmo9dQz.d.mts +53 -0
  10. package/dist/count.port-BRqwGbi3.d.mts +57 -0
  11. package/dist/counting/index.d.mts +2 -0
  12. package/dist/counting/index.mjs +2 -0
  13. package/dist/counting.service-BiQXqorv.mjs +232 -0
  14. package/dist/counting.service-CpAxU2G0.d.mts +74 -0
  15. package/dist/domain/contracts/index.d.mts +3 -0
  16. package/dist/domain/contracts/index.mjs +1 -0
  17. package/dist/domain/enums/index.d.mts +2 -0
  18. package/dist/domain/enums/index.mjs +4 -0
  19. package/dist/domain/index.d.mts +24 -0
  20. package/dist/domain/index.mjs +10 -0
  21. package/dist/domain/policies/index.d.mts +4 -0
  22. package/dist/domain/policies/index.mjs +1 -0
  23. package/dist/domain-D5cpMpR0.mjs +96 -0
  24. package/dist/domain-errors-D7S9ydNF.mjs +133 -0
  25. package/dist/enums-C3_z6aHC.mjs +82 -0
  26. package/dist/event-bus-BNmyoJb4.mjs +37 -0
  27. package/dist/event-bus-Um_xrcMY.d.mts +21 -0
  28. package/dist/event-emitter.port-BFh2pasY.d.mts +183 -0
  29. package/dist/event-types-BSqQOvXv.mjs +29 -0
  30. package/dist/events/index.d.mts +3 -0
  31. package/dist/events/index.mjs +3 -0
  32. package/dist/idempotency.port-CTC70JON.d.mts +55 -0
  33. package/dist/index-Bia4m8d2.d.mts +67 -0
  34. package/dist/index-BmNm3oNU2.d.mts +107 -0
  35. package/dist/index-C5PciI9P.d.mts +203 -0
  36. package/dist/index-CMTUKEK_.d.mts +308 -0
  37. package/dist/index-C_aEnozN.d.mts +220 -0
  38. package/dist/index-CulWO137.d.mts +107 -0
  39. package/dist/index-DFF0GJ4J.d.mts +36 -0
  40. package/dist/index-DsE7lZdO.d.mts +11 -0
  41. package/dist/index-DwO9IdNa.d.mts +1 -0
  42. package/dist/index-dtWUZr2a2.d.mts +350 -0
  43. package/dist/index.d.mts +128 -0
  44. package/dist/index.mjs +102 -0
  45. package/dist/insufficient-stock.error-Dyr4BYaV.mjs +15 -0
  46. package/dist/location.port-CValXIpb.d.mts +52 -0
  47. package/dist/lot.port-ChsmvZqs.d.mts +32 -0
  48. package/dist/models/index.d.mts +2 -0
  49. package/dist/models/index.mjs +2 -0
  50. package/dist/models-CHTMbp-G.mjs +1020 -0
  51. package/dist/move-group.port-DHGoQA3d.d.mts +56 -0
  52. package/dist/move-status-DkaFp2GD.mjs +38 -0
  53. package/dist/move.port-Qg1CYp7h.d.mts +89 -0
  54. package/dist/package.service-4tcAwBbr.mjs +95 -0
  55. package/dist/package.service-C605NaBQ.d.mts +42 -0
  56. package/dist/packaging/index.d.mts +2 -0
  57. package/dist/packaging/index.mjs +2 -0
  58. package/dist/procurement/index.d.mts +2 -0
  59. package/dist/procurement/index.mjs +2 -0
  60. package/dist/quant.port-BBa66PBT.d.mts +42 -0
  61. package/dist/removal-policy-BItBB8FD.d.mts +29 -0
  62. package/dist/replenishment-rule.port-DnEYtbyD.d.mts +78 -0
  63. package/dist/replenishment.service-BT9P-HKM.mjs +284 -0
  64. package/dist/replenishment.service-HO0sDhB_.d.mts +89 -0
  65. package/dist/reporting/index.d.mts +2 -0
  66. package/dist/reporting/index.mjs +2 -0
  67. package/dist/reporting-CL5ffrKM.mjs +243 -0
  68. package/dist/repositories/index.d.mts +2 -0
  69. package/dist/repositories/index.mjs +2 -0
  70. package/dist/repositories-nZXJKvLW.mjs +842 -0
  71. package/dist/reservation-status-ZfuTaWG0.mjs +22 -0
  72. package/dist/reservation.port-l9NFQ0si.d.mts +85 -0
  73. package/dist/reservations/index.d.mts +2 -0
  74. package/dist/reservations/index.mjs +2 -0
  75. package/dist/reservations-Cg4wN0QB.mjs +112 -0
  76. package/dist/routing/index.d.mts +362 -0
  77. package/dist/routing/index.mjs +582 -0
  78. package/dist/runtime-config-C0ggPkiK.mjs +40 -0
  79. package/dist/runtime-config-CQLtPPqY.d.mts +38 -0
  80. package/dist/scan-token-CNM9QVLY.d.mts +26 -0
  81. package/dist/scanning/index.d.mts +45 -0
  82. package/dist/scanning/index.mjs +228 -0
  83. package/dist/services/index.d.mts +8 -0
  84. package/dist/services/index.mjs +8 -0
  85. package/dist/services-_lLO4Xbl.mjs +1009 -0
  86. package/dist/stock-move-group-C0DqUfPY.mjs +88 -0
  87. package/dist/stock-package-BIarxbDS.d.mts +19 -0
  88. package/dist/stock-quant-CZhgvTu7.d.mts +41 -0
  89. package/dist/tenant-guard-6Ne-BILP.mjs +12 -0
  90. package/dist/tenant-isolation.error-D3OcKUdx.mjs +11 -0
  91. package/dist/trace.service-B9vAh-l-.d.mts +55 -0
  92. package/dist/trace.service-DE6Eh8_8.mjs +71 -0
  93. package/dist/traceability/index.d.mts +2 -0
  94. package/dist/traceability/index.mjs +2 -0
  95. package/dist/types/index.d.mts +2 -0
  96. package/dist/types/index.mjs +1 -0
  97. package/dist/unit-of-work.port-CWEkrDKu.d.mts +17 -0
  98. package/dist/valuation/index.d.mts +78 -0
  99. package/dist/valuation/index.mjs +103 -0
  100. package/dist/valuation-policy-Dco8c9Vw.d.mts +14 -0
  101. package/dist/virtual-locations-B9zXqPdi.d.mts +38 -0
  102. package/package.json +155 -0
@@ -0,0 +1,1020 @@
1
+ import { Schema } from "mongoose";
2
+ //#region src/models/cost-layer.model.ts
3
+ const schema$13 = new Schema({
4
+ organizationId: {
5
+ type: Schema.Types.ObjectId,
6
+ required: true,
7
+ index: true
8
+ },
9
+ skuRef: {
10
+ type: String,
11
+ required: true
12
+ },
13
+ locationId: {
14
+ type: String,
15
+ required: true
16
+ },
17
+ lotId: { type: Schema.Types.ObjectId },
18
+ remainingQty: {
19
+ type: Number,
20
+ required: true,
21
+ min: 0
22
+ },
23
+ unitCost: {
24
+ type: Number,
25
+ required: true,
26
+ min: 0
27
+ },
28
+ receivedAt: {
29
+ type: Date,
30
+ required: true
31
+ },
32
+ expiresAt: { type: Date },
33
+ procurementRef: { type: String },
34
+ moveRef: {
35
+ type: String,
36
+ required: true
37
+ }
38
+ }, { timestamps: true });
39
+ schema$13.index({
40
+ organizationId: 1,
41
+ skuRef: 1,
42
+ locationId: 1,
43
+ receivedAt: 1
44
+ });
45
+ schema$13.index({
46
+ organizationId: 1,
47
+ skuRef: 1,
48
+ locationId: 1,
49
+ expiresAt: 1
50
+ });
51
+ function createCostLayerModel(connection) {
52
+ return connection.model("CostLayer", schema$13);
53
+ }
54
+ //#endregion
55
+ //#region src/models/count-line.model.ts
56
+ const schema$12 = new Schema({
57
+ organizationId: {
58
+ type: Schema.Types.ObjectId,
59
+ required: true
60
+ },
61
+ countId: {
62
+ type: Schema.Types.ObjectId,
63
+ required: true,
64
+ ref: "InventoryCount"
65
+ },
66
+ skuRef: {
67
+ type: String,
68
+ required: true
69
+ },
70
+ locationId: {
71
+ type: String,
72
+ required: true
73
+ },
74
+ lotId: { type: Schema.Types.ObjectId },
75
+ serialCode: { type: String },
76
+ expectedQuantity: {
77
+ type: Number,
78
+ required: true,
79
+ min: 0
80
+ },
81
+ countedQuantity: {
82
+ type: Number,
83
+ required: true,
84
+ min: 0
85
+ },
86
+ variance: {
87
+ type: Number,
88
+ required: true
89
+ },
90
+ varianceReason: { type: String },
91
+ recountFlag: {
92
+ type: Boolean,
93
+ default: false
94
+ }
95
+ }, { timestamps: true });
96
+ schema$12.index({
97
+ organizationId: 1,
98
+ countId: 1
99
+ });
100
+ schema$12.index({
101
+ organizationId: 1,
102
+ skuRef: 1,
103
+ countId: 1
104
+ });
105
+ function createCountLineModel(connection) {
106
+ return connection.model("CountLine", schema$12);
107
+ }
108
+ //#endregion
109
+ //#region src/models/counters.model.ts
110
+ const schema$11 = new Schema({
111
+ organizationId: {
112
+ type: String,
113
+ required: true
114
+ },
115
+ prefix: {
116
+ type: String,
117
+ required: true
118
+ },
119
+ currentValue: {
120
+ type: Number,
121
+ default: 0
122
+ }
123
+ }, { timestamps: true });
124
+ schema$11.index({
125
+ organizationId: 1,
126
+ prefix: 1
127
+ }, { unique: true });
128
+ function createCounterModel(connection) {
129
+ return connection.model("Counter", schema$11);
130
+ }
131
+ /**
132
+ * Atomically increments the counter for the given organization + prefix
133
+ * and returns the next sequence value.
134
+ */
135
+ async function getNextSequence(counterModel, organizationId, prefix) {
136
+ return (await counterModel.findOneAndUpdate({
137
+ organizationId,
138
+ prefix
139
+ }, { $inc: { currentValue: 1 } }, {
140
+ returnDocument: "after",
141
+ upsert: true
142
+ }))?.currentValue;
143
+ }
144
+ //#endregion
145
+ //#region src/models/inventory-count.model.ts
146
+ const scopeSchema = new Schema({
147
+ nodeId: { type: Schema.Types.ObjectId },
148
+ locationId: { type: Schema.Types.ObjectId },
149
+ skuRefs: [{ type: String }]
150
+ }, { _id: false });
151
+ const schema$10 = new Schema({
152
+ organizationId: {
153
+ type: Schema.Types.ObjectId,
154
+ required: true,
155
+ index: true
156
+ },
157
+ countNumber: {
158
+ type: String,
159
+ required: true
160
+ },
161
+ countType: {
162
+ type: String,
163
+ required: true,
164
+ enum: [
165
+ "full",
166
+ "cycle",
167
+ "spot"
168
+ ]
169
+ },
170
+ scope: { type: scopeSchema },
171
+ status: {
172
+ type: String,
173
+ default: "draft",
174
+ enum: [
175
+ "draft",
176
+ "in_progress",
177
+ "submitted",
178
+ "reconciled",
179
+ "approved"
180
+ ]
181
+ },
182
+ freezePolicy: {
183
+ type: String,
184
+ default: "none",
185
+ enum: [
186
+ "hard_freeze",
187
+ "soft_freeze",
188
+ "none"
189
+ ]
190
+ },
191
+ startedAt: { type: Date },
192
+ submittedAt: { type: Date },
193
+ reconciledAt: { type: Date },
194
+ createdBy: { type: String },
195
+ modifiedBy: { type: String },
196
+ approvedBy: { type: String },
197
+ metadata: { type: Schema.Types.Mixed }
198
+ }, { timestamps: true });
199
+ schema$10.index({
200
+ organizationId: 1,
201
+ countNumber: 1
202
+ }, { unique: true });
203
+ schema$10.index({
204
+ organizationId: 1,
205
+ status: 1
206
+ });
207
+ function createInventoryCountModel(connection) {
208
+ return connection.model("InventoryCount", schema$10);
209
+ }
210
+ //#endregion
211
+ //#region src/models/inventory-node.model.ts
212
+ const addressSchema = new Schema({
213
+ street: { type: String },
214
+ city: { type: String },
215
+ state: { type: String },
216
+ postalCode: { type: String },
217
+ country: { type: String },
218
+ coordinates: { type: new Schema({
219
+ lat: { type: Number },
220
+ lng: { type: Number }
221
+ }, { _id: false }) }
222
+ }, { _id: false });
223
+ const schema$9 = new Schema({
224
+ organizationId: {
225
+ type: Schema.Types.ObjectId,
226
+ required: true,
227
+ index: true,
228
+ ref: "Organization"
229
+ },
230
+ code: {
231
+ type: String,
232
+ required: true
233
+ },
234
+ name: {
235
+ type: String,
236
+ required: true
237
+ },
238
+ type: {
239
+ type: String,
240
+ required: true
241
+ },
242
+ status: {
243
+ type: String,
244
+ enum: ["active", "inactive"],
245
+ default: "active"
246
+ },
247
+ timezone: { type: String },
248
+ currency: { type: String },
249
+ address: { type: addressSchema },
250
+ capabilities: [{ type: String }],
251
+ isDefault: {
252
+ type: Boolean,
253
+ default: false
254
+ },
255
+ metadata: { type: Schema.Types.Mixed }
256
+ }, { timestamps: true });
257
+ schema$9.index({
258
+ organizationId: 1,
259
+ code: 1
260
+ }, { unique: true });
261
+ schema$9.index({
262
+ organizationId: 1,
263
+ isDefault: 1
264
+ });
265
+ function createInventoryNodeModel(connection) {
266
+ return connection.model("InventoryNode", schema$9);
267
+ }
268
+ //#endregion
269
+ //#region src/models/location.model.ts
270
+ const schema$8 = new Schema({
271
+ organizationId: {
272
+ type: Schema.Types.ObjectId,
273
+ required: true,
274
+ index: true
275
+ },
276
+ nodeId: {
277
+ type: Schema.Types.ObjectId,
278
+ required: true,
279
+ ref: "InventoryNode"
280
+ },
281
+ parentLocationId: {
282
+ type: Schema.Types.ObjectId,
283
+ ref: "Location"
284
+ },
285
+ code: {
286
+ type: String,
287
+ required: true
288
+ },
289
+ name: {
290
+ type: String,
291
+ required: true
292
+ },
293
+ type: {
294
+ type: String,
295
+ required: true,
296
+ enum: [
297
+ "view",
298
+ "internal",
299
+ "receiving",
300
+ "storage",
301
+ "picking",
302
+ "packing",
303
+ "shipping",
304
+ "transit",
305
+ "vendor",
306
+ "customer",
307
+ "returns",
308
+ "quality_hold",
309
+ "damaged",
310
+ "scrap",
311
+ "inventory_loss",
312
+ "production"
313
+ ]
314
+ },
315
+ status: {
316
+ type: String,
317
+ enum: ["active", "inactive"],
318
+ default: "active"
319
+ },
320
+ barcode: { type: String },
321
+ capacity: { type: Number },
322
+ sortOrder: {
323
+ type: Number,
324
+ default: 999999
325
+ },
326
+ coordinates: {
327
+ type: {
328
+ zone: { type: String },
329
+ aisle: { type: Number },
330
+ bay: { type: Number },
331
+ level: { type: Number },
332
+ bin: { type: String }
333
+ },
334
+ _id: false
335
+ },
336
+ maxWeight: { type: Number },
337
+ maxVolume: { type: Number },
338
+ allowReservations: {
339
+ type: Boolean,
340
+ default: true
341
+ },
342
+ allowNegativeStock: {
343
+ type: Boolean,
344
+ default: false
345
+ },
346
+ metadata: { type: Schema.Types.Mixed }
347
+ }, { timestamps: true });
348
+ schema$8.index({
349
+ organizationId: 1,
350
+ nodeId: 1,
351
+ code: 1
352
+ }, { unique: true });
353
+ schema$8.index({
354
+ organizationId: 1,
355
+ barcode: 1
356
+ }, {
357
+ unique: true,
358
+ sparse: true
359
+ });
360
+ schema$8.index({
361
+ organizationId: 1,
362
+ nodeId: 1,
363
+ type: 1
364
+ });
365
+ schema$8.index({
366
+ organizationId: 1,
367
+ nodeId: 1,
368
+ sortOrder: 1,
369
+ _id: 1
370
+ });
371
+ function createLocationModel(connection) {
372
+ return connection.model("Location", schema$8);
373
+ }
374
+ //#endregion
375
+ //#region src/models/procurement-order.model.ts
376
+ const procurementItemSchema = new Schema({
377
+ skuRef: {
378
+ type: String,
379
+ required: true
380
+ },
381
+ quantity: {
382
+ type: Number,
383
+ required: true,
384
+ min: 0
385
+ },
386
+ quantityReceived: {
387
+ type: Number,
388
+ default: 0,
389
+ min: 0
390
+ },
391
+ unitCost: {
392
+ type: Number,
393
+ required: true,
394
+ min: 0
395
+ },
396
+ expectedAt: { type: Date }
397
+ }, { _id: false });
398
+ const schema$7 = new Schema({
399
+ organizationId: {
400
+ type: Schema.Types.ObjectId,
401
+ required: true,
402
+ index: true
403
+ },
404
+ orderNumber: {
405
+ type: String,
406
+ required: true
407
+ },
408
+ vendorRef: {
409
+ type: String,
410
+ required: true
411
+ },
412
+ destinationNodeId: {
413
+ type: Schema.Types.ObjectId,
414
+ required: true,
415
+ ref: "InventoryNode"
416
+ },
417
+ destinationLocationId: {
418
+ type: Schema.Types.ObjectId,
419
+ ref: "Location"
420
+ },
421
+ status: {
422
+ type: String,
423
+ required: true,
424
+ default: "draft",
425
+ enum: [
426
+ "draft",
427
+ "approved",
428
+ "ordered",
429
+ "partially_received",
430
+ "received",
431
+ "cancelled"
432
+ ]
433
+ },
434
+ items: [procurementItemSchema],
435
+ expectedAt: { type: Date },
436
+ receivedAt: { type: Date },
437
+ sourceDemandRefs: [{ type: String }],
438
+ createdBy: { type: String },
439
+ modifiedBy: { type: String },
440
+ metadata: { type: Schema.Types.Mixed }
441
+ }, { timestamps: true });
442
+ schema$7.index({
443
+ organizationId: 1,
444
+ orderNumber: 1
445
+ }, { unique: true });
446
+ schema$7.index({
447
+ organizationId: 1,
448
+ status: 1,
449
+ vendorRef: 1
450
+ });
451
+ function createProcurementOrderModel(connection) {
452
+ return connection.model("ProcurementOrder", schema$7);
453
+ }
454
+ //#endregion
455
+ //#region src/models/replenishment-rule.model.ts
456
+ const schema$6 = new Schema({
457
+ organizationId: {
458
+ type: Schema.Types.ObjectId,
459
+ required: true,
460
+ index: true
461
+ },
462
+ scopeType: {
463
+ type: String,
464
+ required: true
465
+ },
466
+ scopeRef: {
467
+ type: String,
468
+ required: true
469
+ },
470
+ skuRef: {
471
+ type: String,
472
+ required: true
473
+ },
474
+ locationId: { type: String },
475
+ triggerType: {
476
+ type: String,
477
+ required: true
478
+ },
479
+ reorderPoint: {
480
+ type: Number,
481
+ required: true,
482
+ min: 0
483
+ },
484
+ targetLevel: {
485
+ type: Number,
486
+ required: true,
487
+ min: 0
488
+ },
489
+ preferredSourceType: { type: String },
490
+ preferredSourceRef: { type: String },
491
+ procurementMode: { type: String },
492
+ leadTimeDays: {
493
+ type: Number,
494
+ min: 0
495
+ },
496
+ minOrderQty: {
497
+ type: Number,
498
+ min: 0
499
+ },
500
+ maxOrderQty: {
501
+ type: Number,
502
+ min: 0
503
+ },
504
+ multipleOf: {
505
+ type: Number,
506
+ min: 1
507
+ },
508
+ safetyStock: {
509
+ type: Number,
510
+ min: 0
511
+ },
512
+ enabled: {
513
+ type: Boolean,
514
+ default: true
515
+ },
516
+ metadata: { type: Schema.Types.Mixed }
517
+ }, { timestamps: true });
518
+ schema$6.index({
519
+ organizationId: 1,
520
+ skuRef: 1,
521
+ scopeRef: 1
522
+ }, { unique: true });
523
+ function createReplenishmentRuleModel(connection) {
524
+ return connection.model("ReplenishmentRule", schema$6);
525
+ }
526
+ //#endregion
527
+ //#region src/models/reservation.model.ts
528
+ const schema$5 = new Schema({
529
+ organizationId: {
530
+ type: Schema.Types.ObjectId,
531
+ required: true,
532
+ index: true
533
+ },
534
+ reservationType: {
535
+ type: String,
536
+ required: true,
537
+ enum: ["soft", "hard"]
538
+ },
539
+ ownerType: {
540
+ type: String,
541
+ required: true
542
+ },
543
+ ownerId: {
544
+ type: String,
545
+ required: true
546
+ },
547
+ skuRef: {
548
+ type: String,
549
+ required: true
550
+ },
551
+ locationId: {
552
+ type: String,
553
+ required: true
554
+ },
555
+ lotId: {
556
+ type: Schema.Types.ObjectId,
557
+ ref: "StockLot"
558
+ },
559
+ quantity: {
560
+ type: Number,
561
+ required: true,
562
+ min: 0
563
+ },
564
+ quantityConsumed: {
565
+ type: Number,
566
+ default: 0,
567
+ min: 0
568
+ },
569
+ status: {
570
+ type: String,
571
+ required: true,
572
+ default: "active",
573
+ enum: [
574
+ "active",
575
+ "partially_consumed",
576
+ "consumed",
577
+ "released",
578
+ "expired",
579
+ "cancelled"
580
+ ]
581
+ },
582
+ expiresAt: { type: Date },
583
+ allocationPolicy: { type: String },
584
+ createdBy: { type: String },
585
+ releasedAt: { type: Date }
586
+ }, { timestamps: true });
587
+ schema$5.index({
588
+ organizationId: 1,
589
+ ownerType: 1,
590
+ ownerId: 1
591
+ });
592
+ schema$5.index({
593
+ organizationId: 1,
594
+ skuRef: 1,
595
+ locationId: 1,
596
+ status: 1
597
+ });
598
+ schema$5.index({
599
+ organizationId: 1,
600
+ status: 1,
601
+ expiresAt: 1
602
+ });
603
+ function createReservationModel(connection) {
604
+ return connection.model("Reservation", schema$5);
605
+ }
606
+ //#endregion
607
+ //#region src/models/stock-lot.model.ts
608
+ const schema$4 = new Schema({
609
+ organizationId: {
610
+ type: Schema.Types.ObjectId,
611
+ required: true,
612
+ index: true
613
+ },
614
+ skuRef: {
615
+ type: String,
616
+ required: true
617
+ },
618
+ trackingType: {
619
+ type: String,
620
+ required: true,
621
+ enum: ["lot", "serial"]
622
+ },
623
+ lotCode: { type: String },
624
+ serialCode: { type: String },
625
+ manufacturedAt: { type: Date },
626
+ receivedAt: { type: Date },
627
+ expiresAt: { type: Date },
628
+ vendorBatchRef: { type: String },
629
+ status: {
630
+ type: String,
631
+ default: "active",
632
+ enum: [
633
+ "active",
634
+ "recalled",
635
+ "expired"
636
+ ]
637
+ },
638
+ metadata: { type: Schema.Types.Mixed }
639
+ }, { timestamps: true });
640
+ schema$4.index({
641
+ organizationId: 1,
642
+ skuRef: 1,
643
+ lotCode: 1
644
+ }, {
645
+ unique: true,
646
+ sparse: true
647
+ });
648
+ schema$4.index({
649
+ organizationId: 1,
650
+ skuRef: 1,
651
+ serialCode: 1
652
+ }, {
653
+ unique: true,
654
+ sparse: true
655
+ });
656
+ schema$4.index({
657
+ organizationId: 1,
658
+ expiresAt: 1
659
+ });
660
+ function createStockLotModel(connection) {
661
+ return connection.model("StockLot", schema$4);
662
+ }
663
+ //#endregion
664
+ //#region src/models/stock-move.model.ts
665
+ const trackingAssignmentSchema = new Schema({
666
+ trackingMode: { type: String },
667
+ lotId: { type: String },
668
+ lotCode: { type: String },
669
+ serialCode: { type: String },
670
+ quantity: { type: Number },
671
+ expiresAt: { type: Date }
672
+ }, { _id: false });
673
+ const schema$3 = new Schema({
674
+ organizationId: {
675
+ type: Schema.Types.ObjectId,
676
+ required: true,
677
+ index: true
678
+ },
679
+ moveGroupId: {
680
+ type: Schema.Types.ObjectId,
681
+ required: true,
682
+ ref: "StockMoveGroup"
683
+ },
684
+ referenceType: { type: String },
685
+ referenceId: { type: String },
686
+ operationType: {
687
+ type: String,
688
+ required: true,
689
+ enum: [
690
+ "receipt",
691
+ "transfer",
692
+ "shipment",
693
+ "return",
694
+ "adjustment",
695
+ "count"
696
+ ]
697
+ },
698
+ skuRef: {
699
+ type: String,
700
+ required: true
701
+ },
702
+ sourceLocationId: {
703
+ type: String,
704
+ required: true
705
+ },
706
+ destinationLocationId: {
707
+ type: String,
708
+ required: true
709
+ },
710
+ trackingAssignments: [trackingAssignmentSchema],
711
+ uom: {
712
+ type: String,
713
+ default: "unit"
714
+ },
715
+ quantityPlanned: {
716
+ type: Number,
717
+ required: true,
718
+ min: 0
719
+ },
720
+ quantityReserved: {
721
+ type: Number,
722
+ default: 0,
723
+ min: 0
724
+ },
725
+ quantityDone: {
726
+ type: Number,
727
+ default: 0,
728
+ min: 0
729
+ },
730
+ status: {
731
+ type: String,
732
+ required: true,
733
+ default: "draft",
734
+ enum: [
735
+ "draft",
736
+ "planned",
737
+ "waiting",
738
+ "ready",
739
+ "partially_done",
740
+ "done",
741
+ "cancelled"
742
+ ]
743
+ },
744
+ scheduledAt: { type: Date },
745
+ executedAt: { type: Date },
746
+ cancelledAt: { type: Date },
747
+ reservationIds: [{ type: Schema.Types.ObjectId }],
748
+ policySnapshot: { type: Schema.Types.Mixed },
749
+ createdBy: { type: String },
750
+ modifiedBy: { type: String },
751
+ metadata: { type: Schema.Types.Mixed }
752
+ }, { timestamps: true });
753
+ schema$3.index({
754
+ organizationId: 1,
755
+ moveGroupId: 1
756
+ });
757
+ schema$3.index({
758
+ organizationId: 1,
759
+ skuRef: 1,
760
+ status: 1
761
+ });
762
+ schema$3.index({
763
+ organizationId: 1,
764
+ sourceLocationId: 1,
765
+ status: 1
766
+ });
767
+ schema$3.index({
768
+ organizationId: 1,
769
+ destinationLocationId: 1,
770
+ status: 1
771
+ });
772
+ schema$3.index({
773
+ organizationId: 1,
774
+ status: 1,
775
+ executedAt: -1
776
+ });
777
+ schema$3.index({
778
+ organizationId: 1,
779
+ status: 1,
780
+ createdAt: -1
781
+ });
782
+ function createStockMoveModel(connection) {
783
+ return connection.model("StockMove", schema$3);
784
+ }
785
+ //#endregion
786
+ //#region src/models/stock-move-group.model.ts
787
+ const schema$2 = new Schema({
788
+ organizationId: {
789
+ type: Schema.Types.ObjectId,
790
+ required: true,
791
+ index: true
792
+ },
793
+ groupType: {
794
+ type: String,
795
+ required: true,
796
+ enum: [
797
+ "receipt",
798
+ "transfer",
799
+ "shipment",
800
+ "return",
801
+ "adjustment",
802
+ "pick_wave",
803
+ "count_reconciliation"
804
+ ]
805
+ },
806
+ documentNumber: {
807
+ type: String,
808
+ required: true
809
+ },
810
+ sourceNodeId: {
811
+ type: Schema.Types.ObjectId,
812
+ ref: "InventoryNode"
813
+ },
814
+ destinationNodeId: {
815
+ type: Schema.Types.ObjectId,
816
+ ref: "InventoryNode"
817
+ },
818
+ status: {
819
+ type: String,
820
+ required: true,
821
+ default: "draft",
822
+ enum: [
823
+ "draft",
824
+ "confirmed",
825
+ "allocated",
826
+ "in_progress",
827
+ "partially_done",
828
+ "done",
829
+ "cancelled"
830
+ ]
831
+ },
832
+ priority: {
833
+ type: Number,
834
+ default: 0
835
+ },
836
+ routePlanId: { type: Schema.Types.ObjectId },
837
+ counterparty: { type: new Schema({
838
+ type: { type: String },
839
+ id: { type: String }
840
+ }, { _id: false }) },
841
+ requestedAt: { type: Date },
842
+ confirmedAt: { type: Date },
843
+ completedAt: { type: Date },
844
+ createdBy: { type: String },
845
+ modifiedBy: { type: String },
846
+ notes: { type: String },
847
+ metadata: { type: Schema.Types.Mixed }
848
+ }, { timestamps: true });
849
+ schema$2.index({
850
+ organizationId: 1,
851
+ documentNumber: 1
852
+ }, { unique: true });
853
+ schema$2.index({
854
+ organizationId: 1,
855
+ groupType: 1,
856
+ status: 1
857
+ });
858
+ function createStockMoveGroupModel(connection) {
859
+ return connection.model("StockMoveGroup", schema$2);
860
+ }
861
+ //#endregion
862
+ //#region src/models/stock-package.model.ts
863
+ const schema$1 = new Schema({
864
+ organizationId: {
865
+ type: Schema.Types.ObjectId,
866
+ required: true,
867
+ index: true
868
+ },
869
+ name: {
870
+ type: String,
871
+ required: true
872
+ },
873
+ barcode: {
874
+ type: String,
875
+ required: true
876
+ },
877
+ packageTypeId: { type: Schema.Types.ObjectId },
878
+ parentPackageId: {
879
+ type: Schema.Types.ObjectId,
880
+ ref: "StockPackage"
881
+ },
882
+ locationId: { type: Schema.Types.ObjectId },
883
+ destinationLocationId: { type: Schema.Types.ObjectId },
884
+ baseWeight: {
885
+ type: Number,
886
+ min: 0
887
+ },
888
+ maxWeight: {
889
+ type: Number,
890
+ min: 0
891
+ },
892
+ packageUse: {
893
+ type: String,
894
+ default: "disposable"
895
+ },
896
+ metadata: { type: Schema.Types.Mixed }
897
+ }, { timestamps: true });
898
+ schema$1.index({
899
+ organizationId: 1,
900
+ barcode: 1
901
+ }, { unique: true });
902
+ schema$1.index({
903
+ organizationId: 1,
904
+ parentPackageId: 1
905
+ });
906
+ function createStockPackageModel(connection) {
907
+ return connection.model("StockPackage", schema$1);
908
+ }
909
+ //#endregion
910
+ //#region src/models/stock-quant.model.ts
911
+ const schema = new Schema({
912
+ organizationId: {
913
+ type: Schema.Types.ObjectId,
914
+ required: true
915
+ },
916
+ skuRef: {
917
+ type: String,
918
+ required: true
919
+ },
920
+ locationId: {
921
+ type: String,
922
+ required: true
923
+ },
924
+ lotId: {
925
+ type: Schema.Types.ObjectId,
926
+ ref: "StockLot"
927
+ },
928
+ ownerRef: { type: String },
929
+ stockStatus: {
930
+ type: String,
931
+ default: "sellable",
932
+ enum: [
933
+ "sellable",
934
+ "damaged",
935
+ "quarantine",
936
+ "hold",
937
+ "returns",
938
+ "expired",
939
+ "in_transit"
940
+ ]
941
+ },
942
+ quantityOnHand: {
943
+ type: Number,
944
+ required: true,
945
+ default: 0,
946
+ min: 0
947
+ },
948
+ quantityReserved: {
949
+ type: Number,
950
+ default: 0,
951
+ min: 0
952
+ },
953
+ quantityAvailable: {
954
+ type: Number,
955
+ default: 0,
956
+ min: 0
957
+ },
958
+ quantityIncoming: {
959
+ type: Number,
960
+ default: 0,
961
+ min: 0
962
+ },
963
+ quantityOutgoing: {
964
+ type: Number,
965
+ default: 0,
966
+ min: 0
967
+ },
968
+ inDate: {
969
+ type: Date,
970
+ required: true
971
+ },
972
+ lotExpiresAt: { type: Date },
973
+ unitCost: { type: Number },
974
+ lastMovementAt: { type: Date }
975
+ }, { timestamps: true });
976
+ schema.index({
977
+ organizationId: 1,
978
+ skuRef: 1,
979
+ locationId: 1,
980
+ lotId: 1,
981
+ ownerRef: 1
982
+ }, { unique: true });
983
+ schema.index({
984
+ organizationId: 1,
985
+ skuRef: 1,
986
+ stockStatus: 1
987
+ });
988
+ schema.index({
989
+ organizationId: 1,
990
+ locationId: 1
991
+ });
992
+ function createStockQuantModel(connection) {
993
+ return connection.model("StockQuant", schema);
994
+ }
995
+ //#endregion
996
+ //#region src/models/index.ts
997
+ /**
998
+ * Creates all Flow inventory models on the given Mongoose connection.
999
+ * Designed for multi-tenant usage where each tenant gets its own connection.
1000
+ */
1001
+ function createModels(connection) {
1002
+ return {
1003
+ InventoryNode: createInventoryNodeModel(connection),
1004
+ Location: createLocationModel(connection),
1005
+ StockMove: createStockMoveModel(connection),
1006
+ StockMoveGroup: createStockMoveGroupModel(connection),
1007
+ StockQuant: createStockQuantModel(connection),
1008
+ Reservation: createReservationModel(connection),
1009
+ StockLot: createStockLotModel(connection),
1010
+ CostLayer: createCostLayerModel(connection),
1011
+ ProcurementOrder: createProcurementOrderModel(connection),
1012
+ InventoryCount: createInventoryCountModel(connection),
1013
+ CountLine: createCountLineModel(connection),
1014
+ ReplenishmentRule: createReplenishmentRuleModel(connection),
1015
+ StockPackage: createStockPackageModel(connection),
1016
+ Counter: createCounterModel(connection)
1017
+ };
1018
+ }
1019
+ //#endregion
1020
+ export { createStockMoveModel as a, createReplenishmentRuleModel as c, createInventoryNodeModel as d, createInventoryCountModel as f, createCostLayerModel as g, createCountLineModel as h, createStockMoveGroupModel as i, createProcurementOrderModel as l, getNextSequence as m, createStockQuantModel as n, createStockLotModel as o, createCounterModel as p, createStockPackageModel as r, createReservationModel as s, createModels as t, createLocationModel as u };