@managesome/eposmatic-toolkit 0.4.89 → 0.4.92

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 (66) hide show
  1. package/esm/constants/ENUMS.js +1 -0
  2. package/esm/constants/enums/storage.js +23 -0
  3. package/esm/helpers/index.js +1 -0
  4. package/esm/helpers/order/generate-warehouse-internal-movement.js +3 -0
  5. package/esm/helpers/storage/index.js +1 -0
  6. package/esm/helpers/storage/upload-paths.js +384 -0
  7. package/esm/helpers/store/common-warehouse-internal-movement-actions.js +124 -4
  8. package/esm/helpers/utils/discount-amounts.js +64 -0
  9. package/esm/helpers/utils/index.js +2 -0
  10. package/esm/helpers/utils/internal-movement-items.js +30 -0
  11. package/esm/helpers/utils/tenant-purchase-order-engine.js +10 -18
  12. package/esm/helpers/utils/warehouse-purchase-order-engine.js +10 -18
  13. package/esm/schemas/models/index.js +1 -0
  14. package/esm/schemas/models/pending_uploads.js +102 -0
  15. package/esm/schemas/models/warehouse_internal_movements.js +54 -0
  16. package/esm/schemas/types/index.js +1 -0
  17. package/esm/schemas/types/pending_uploads.js +1 -0
  18. package/lib/constants/ENUMS.d.ts +1 -0
  19. package/lib/constants/ENUMS.js +1 -0
  20. package/lib/constants/enums/storage.d.ts +21 -0
  21. package/lib/constants/enums/storage.js +26 -0
  22. package/lib/helpers/index.d.ts +1 -0
  23. package/lib/helpers/index.js +1 -0
  24. package/lib/helpers/order/generate-warehouse-internal-movement.js +3 -0
  25. package/lib/helpers/storage/index.d.ts +1 -0
  26. package/lib/helpers/storage/index.js +17 -0
  27. package/lib/helpers/storage/upload-paths.d.ts +117 -0
  28. package/lib/helpers/storage/upload-paths.js +394 -0
  29. package/lib/helpers/store/common-warehouse-internal-movement-actions.d.ts +33 -1
  30. package/lib/helpers/store/common-warehouse-internal-movement-actions.js +126 -3
  31. package/lib/helpers/utils/discount-amounts.d.ts +50 -0
  32. package/lib/helpers/utils/discount-amounts.js +69 -0
  33. package/lib/helpers/utils/index.d.ts +2 -0
  34. package/lib/helpers/utils/index.js +2 -0
  35. package/lib/helpers/utils/internal-movement-items.d.ts +35 -0
  36. package/lib/helpers/utils/internal-movement-items.js +36 -0
  37. package/lib/helpers/utils/tenant-purchase-order-engine.js +9 -17
  38. package/lib/helpers/utils/warehouse-purchase-order-engine.js +9 -17
  39. package/lib/schemas/models/index.d.ts +1 -0
  40. package/lib/schemas/models/index.js +1 -0
  41. package/lib/schemas/models/inventories.d.ts +3 -3
  42. package/lib/schemas/models/inventory_transactions.d.ts +3 -3
  43. package/lib/schemas/models/item_transactions.d.ts +3 -3
  44. package/lib/schemas/models/materialized_tenant_discount_entries.d.ts +3 -3
  45. package/lib/schemas/models/materialized_tenant_prep_time_entries.d.ts +3 -3
  46. package/lib/schemas/models/orders.d.ts +120 -120
  47. package/lib/schemas/models/pending_uploads.d.ts +118 -0
  48. package/lib/schemas/models/pending_uploads.js +105 -0
  49. package/lib/schemas/models/tenant_hr_employees.d.ts +3 -3
  50. package/lib/schemas/models/tenant_inventory_department_transactions.d.ts +3 -3
  51. package/lib/schemas/models/tenant_inventory_department_utilities.d.ts +3 -3
  52. package/lib/schemas/models/warehouse_internal_movements.d.ts +570 -0
  53. package/lib/schemas/models/warehouse_internal_movements.js +54 -0
  54. package/lib/schemas/models/warehouse_inventory_transactions.d.ts +3 -3
  55. package/lib/schemas/models/warehouse_item_transactions.d.ts +3 -3
  56. package/lib/schemas/models/warehouse_items.d.ts +3 -3
  57. package/lib/schemas/types/index.d.ts +1 -0
  58. package/lib/schemas/types/index.js +1 -0
  59. package/lib/schemas/types/pending_uploads.d.ts +30 -0
  60. package/lib/schemas/types/pending_uploads.js +2 -0
  61. package/lib/schemas/types/warehouse_internal_movements.d.ts +17 -1
  62. package/lib/tests/pending-uploads-schema.test.d.ts +1 -0
  63. package/lib/tests/pending-uploads-schema.test.js +79 -0
  64. package/lib/tests/storage-upload-paths.test.d.ts +1 -0
  65. package/lib/tests/storage-upload-paths.test.js +198 -0
  66. package/package.json +1 -1
@@ -0,0 +1,118 @@
1
+ import { Schema } from 'mongoose';
2
+ export declare const PENDING_UPLOADS_COLLECTION_NAME = "pending_uploads";
3
+ /**
4
+ * Ledger for server-signed uploads.
5
+ *
6
+ * Standard collection timestamps: `createdAt` / `updatedAt` (timestamps: true).
7
+ * The TTL index is the audit boundary: rows are retained for 30 days after
8
+ * creation, then removed. A discarded or committed row is kept until then so
9
+ * a late discard/confirm can still answer deterministically.
10
+ *
11
+ * A repeated `/sign` for the same deterministic path supersedes the row with
12
+ * `findOneAndReplace`, so the standard timestamps and lifecycle fields restart
13
+ * for the new attempt.
14
+ */
15
+ export declare const PendingUploadSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
16
+ collection: string;
17
+ timestamps: true;
18
+ versionKey: false;
19
+ minimize: false;
20
+ }, {
21
+ createdAt: NativeDate;
22
+ updatedAt: NativeDate;
23
+ } & {
24
+ createdAt: NativeDate;
25
+ updatedAt: NativeDate;
26
+ path: string;
27
+ ref_type: import("../../constants/enums/storage").PENDING_UPLOAD_REF_TYPE_ENUM;
28
+ ref_id: string;
29
+ uid: string;
30
+ size: number;
31
+ committed_at: NativeDate;
32
+ kind: "brand.category_banner" | "brand.category" | "brand.halfhalf" | "brand.image" | "brand.item" | "brand.offer" | "brand.special" | "brand.warehouse.category" | "brand.warehouse.item" | "delivery.proof" | "document.hr" | "document.policy" | "internal.expense" | "internal.restaurant" | "rider.image" | "tenant.department" | "tenant.digital_menu" | "tenant.expense" | "tenant.image" | "tenant.inventory" | "tenant.marketing" | "tenant.slider" | "tenant.staff" | "tenant.web_cover" | "tenant.web_favicon" | "warehouse.expense" | "warehouse.image" | "warehouse.inventory" | "warehouse.staff";
33
+ mime: string;
34
+ max_bytes: number;
35
+ uploaded_at: NativeDate;
36
+ discarded_at: NativeDate;
37
+ expires_at: NativeDate;
38
+ content_type: string;
39
+ generation: string;
40
+ stage?: import("../../constants/enums/storage").PENDING_UPLOAD_STAGE_ENUM | null | undefined;
41
+ }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
42
+ createdAt: NativeDate;
43
+ updatedAt: NativeDate;
44
+ } & {
45
+ createdAt: NativeDate;
46
+ updatedAt: NativeDate;
47
+ path: string;
48
+ ref_type: import("../../constants/enums/storage").PENDING_UPLOAD_REF_TYPE_ENUM;
49
+ ref_id: string;
50
+ uid: string;
51
+ size: number;
52
+ committed_at: NativeDate;
53
+ kind: "brand.category_banner" | "brand.category" | "brand.halfhalf" | "brand.image" | "brand.item" | "brand.offer" | "brand.special" | "brand.warehouse.category" | "brand.warehouse.item" | "delivery.proof" | "document.hr" | "document.policy" | "internal.expense" | "internal.restaurant" | "rider.image" | "tenant.department" | "tenant.digital_menu" | "tenant.expense" | "tenant.image" | "tenant.inventory" | "tenant.marketing" | "tenant.slider" | "tenant.staff" | "tenant.web_cover" | "tenant.web_favicon" | "warehouse.expense" | "warehouse.image" | "warehouse.inventory" | "warehouse.staff";
54
+ mime: string;
55
+ max_bytes: number;
56
+ uploaded_at: NativeDate;
57
+ discarded_at: NativeDate;
58
+ expires_at: NativeDate;
59
+ content_type: string;
60
+ generation: string;
61
+ stage?: import("../../constants/enums/storage").PENDING_UPLOAD_STAGE_ENUM | null | undefined;
62
+ }>> & import("mongoose").FlatRecord<{
63
+ createdAt: NativeDate;
64
+ updatedAt: NativeDate;
65
+ } & {
66
+ createdAt: NativeDate;
67
+ updatedAt: NativeDate;
68
+ path: string;
69
+ ref_type: import("../../constants/enums/storage").PENDING_UPLOAD_REF_TYPE_ENUM;
70
+ ref_id: string;
71
+ uid: string;
72
+ size: number;
73
+ committed_at: NativeDate;
74
+ kind: "brand.category_banner" | "brand.category" | "brand.halfhalf" | "brand.image" | "brand.item" | "brand.offer" | "brand.special" | "brand.warehouse.category" | "brand.warehouse.item" | "delivery.proof" | "document.hr" | "document.policy" | "internal.expense" | "internal.restaurant" | "rider.image" | "tenant.department" | "tenant.digital_menu" | "tenant.expense" | "tenant.image" | "tenant.inventory" | "tenant.marketing" | "tenant.slider" | "tenant.staff" | "tenant.web_cover" | "tenant.web_favicon" | "warehouse.expense" | "warehouse.image" | "warehouse.inventory" | "warehouse.staff";
75
+ mime: string;
76
+ max_bytes: number;
77
+ uploaded_at: NativeDate;
78
+ discarded_at: NativeDate;
79
+ expires_at: NativeDate;
80
+ content_type: string;
81
+ generation: string;
82
+ stage?: import("../../constants/enums/storage").PENDING_UPLOAD_STAGE_ENUM | null | undefined;
83
+ }> & {
84
+ _id: import("mongoose").Types.ObjectId;
85
+ } & {
86
+ __v: number;
87
+ }>;
88
+ /**
89
+ * Describes the indexes for `pending_uploads`. Values are Mongo key patterns
90
+ * that can be passed to `.hint()`; creation must use
91
+ * `PENDING_UPLOADS_INDEX_OPTIONS`.
92
+ */
93
+ export declare const PENDING_UPLOADS_COLLECTION_INDEXES: {
94
+ _id: {
95
+ _id: number;
96
+ };
97
+ path: {
98
+ path: number;
99
+ };
100
+ uid__createdAt: {
101
+ uid: number;
102
+ createdAt: number;
103
+ };
104
+ expires_at: {
105
+ expires_at: number;
106
+ };
107
+ };
108
+ /**
109
+ * Index OPTIONS the owner must CREATE. This is declared in the toolkit and
110
+ * applied by a separate migration/deploy step; it is never created by a read
111
+ * at runtime (services connect with `autoIndex: false`).
112
+ */
113
+ export declare const PENDING_UPLOADS_INDEX_OPTIONS: readonly {
114
+ key: Record<string, 1 | -1>;
115
+ name: string;
116
+ unique?: boolean;
117
+ expireAfterSeconds?: number;
118
+ }[];
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PENDING_UPLOADS_INDEX_OPTIONS = exports.PENDING_UPLOADS_COLLECTION_INDEXES = exports.PendingUploadSchema = exports.PENDING_UPLOADS_COLLECTION_NAME = void 0;
4
+ const mongoose_1 = require("mongoose");
5
+ const storage_1 = require("../../constants/enums/storage");
6
+ const upload_paths_1 = require("../../helpers/storage/upload-paths");
7
+ exports.PENDING_UPLOADS_COLLECTION_NAME = 'pending_uploads';
8
+ /**
9
+ * Ledger for server-signed uploads.
10
+ *
11
+ * Standard collection timestamps: `createdAt` / `updatedAt` (timestamps: true).
12
+ * The TTL index is the audit boundary: rows are retained for 30 days after
13
+ * creation, then removed. A discarded or committed row is kept until then so
14
+ * a late discard/confirm can still answer deterministically.
15
+ *
16
+ * A repeated `/sign` for the same deterministic path supersedes the row with
17
+ * `findOneAndReplace`, so the standard timestamps and lifecycle fields restart
18
+ * for the new attempt.
19
+ */
20
+ exports.PendingUploadSchema = new mongoose_1.Schema({
21
+ path: {
22
+ type: String,
23
+ required: true,
24
+ immutable: true,
25
+ },
26
+ uid: {
27
+ type: String,
28
+ required: true,
29
+ },
30
+ kind: {
31
+ type: String,
32
+ required: true,
33
+ enum: Object.values(upload_paths_1.STORAGE_UPLOAD_KIND),
34
+ },
35
+ ref_type: {
36
+ type: String,
37
+ required: true,
38
+ enum: storage_1.ALL_PENDING_UPLOAD_REF_TYPES,
39
+ },
40
+ ref_id: {
41
+ type: String,
42
+ required: true,
43
+ },
44
+ stage: {
45
+ type: String,
46
+ enum: storage_1.ALL_PENDING_UPLOAD_STAGES,
47
+ },
48
+ mime: { type: String, required: true },
49
+ max_bytes: { type: Number, required: true },
50
+ uploaded_at: { type: Date, default: null },
51
+ committed_at: { type: Date, default: null },
52
+ discarded_at: { type: Date, default: null },
53
+ expires_at: { type: Date, required: true },
54
+ size: { type: Number, default: null },
55
+ content_type: { type: String, default: null },
56
+ generation: { type: String, default: null },
57
+ createdAt: {
58
+ type: Date,
59
+ required: true,
60
+ immutable: true,
61
+ default: () => new Date(),
62
+ },
63
+ updatedAt: {
64
+ type: Date,
65
+ required: true,
66
+ default: () => new Date(),
67
+ },
68
+ }, {
69
+ collection: exports.PENDING_UPLOADS_COLLECTION_NAME,
70
+ timestamps: true,
71
+ versionKey: false,
72
+ minimize: false,
73
+ });
74
+ /**
75
+ * Describes the indexes for `pending_uploads`. Values are Mongo key patterns
76
+ * that can be passed to `.hint()`; creation must use
77
+ * `PENDING_UPLOADS_INDEX_OPTIONS`.
78
+ */
79
+ exports.PENDING_UPLOADS_COLLECTION_INDEXES = {
80
+ _id: { _id: 1 }, // Unique Index
81
+ path: { path: 1 }, // unique server-built upload path
82
+ uid__createdAt: { uid: 1, createdAt: -1 }, // per-user upload history
83
+ expires_at: { expires_at: 1 }, // TTL audit cleanup
84
+ };
85
+ /**
86
+ * Index OPTIONS the owner must CREATE. This is declared in the toolkit and
87
+ * applied by a separate migration/deploy step; it is never created by a read
88
+ * at runtime (services connect with `autoIndex: false`).
89
+ */
90
+ exports.PENDING_UPLOADS_INDEX_OPTIONS = [
91
+ {
92
+ key: { path: 1 },
93
+ name: 'path',
94
+ unique: true,
95
+ },
96
+ {
97
+ key: { uid: 1, createdAt: -1 },
98
+ name: 'uid__createdAt',
99
+ },
100
+ {
101
+ key: { expires_at: 1 },
102
+ name: 'expires_at_ttl',
103
+ expireAfterSeconds: 0,
104
+ },
105
+ ];
@@ -38,9 +38,9 @@ export declare const TenantHrEmployeeSchema: Schema<any, import("mongoose").Mode
38
38
  join_date: NativeDate;
39
39
  employment_status: HR_EMPLOYMENT_STATUS_ENUM;
40
40
  docs: Map<string, {
41
+ uploaded_at: NativeDate;
41
42
  doc_url: string;
42
43
  doc_name: string;
43
- uploaded_at: NativeDate;
44
44
  }>;
45
45
  operational_hours?: import("mongoose").Types.DocumentArray<{
46
46
  days_index: import("../../constants").DAY_INDEX_ENUM[];
@@ -362,9 +362,9 @@ export declare const TenantHrEmployeeSchema: Schema<any, import("mongoose").Mode
362
362
  join_date: NativeDate;
363
363
  employment_status: HR_EMPLOYMENT_STATUS_ENUM;
364
364
  docs: Map<string, {
365
+ uploaded_at: NativeDate;
365
366
  doc_url: string;
366
367
  doc_name: string;
367
- uploaded_at: NativeDate;
368
368
  }>;
369
369
  operational_hours?: import("mongoose").Types.DocumentArray<{
370
370
  days_index: import("../../constants").DAY_INDEX_ENUM[];
@@ -686,9 +686,9 @@ export declare const TenantHrEmployeeSchema: Schema<any, import("mongoose").Mode
686
686
  join_date: NativeDate;
687
687
  employment_status: HR_EMPLOYMENT_STATUS_ENUM;
688
688
  docs: Map<string, {
689
+ uploaded_at: NativeDate;
689
690
  doc_url: string;
690
691
  doc_name: string;
691
- uploaded_at: NativeDate;
692
692
  }>;
693
693
  operational_hours?: import("mongoose").Types.DocumentArray<{
694
694
  days_index: import("../../constants").DAY_INDEX_ENUM[];
@@ -14,8 +14,8 @@ export declare const TenantInventoryDepartmentTransactionsSchema: Schema<any, im
14
14
  department_code: string;
15
15
  tenant_id: string;
16
16
  createdAt_mins: number;
17
- quantity_left: number;
18
17
  unit_price: number;
18
+ quantity_left: number;
19
19
  remaining_stock_price: number;
20
20
  previous_quantity_left: number;
21
21
  previous_unit_price: number;
@@ -40,8 +40,8 @@ export declare const TenantInventoryDepartmentTransactionsSchema: Schema<any, im
40
40
  department_code: string;
41
41
  tenant_id: string;
42
42
  createdAt_mins: number;
43
- quantity_left: number;
44
43
  unit_price: number;
44
+ quantity_left: number;
45
45
  remaining_stock_price: number;
46
46
  previous_quantity_left: number;
47
47
  previous_unit_price: number;
@@ -66,8 +66,8 @@ export declare const TenantInventoryDepartmentTransactionsSchema: Schema<any, im
66
66
  department_code: string;
67
67
  tenant_id: string;
68
68
  createdAt_mins: number;
69
- quantity_left: number;
70
69
  unit_price: number;
70
+ quantity_left: number;
71
71
  remaining_stock_price: number;
72
72
  previous_quantity_left: number;
73
73
  previous_unit_price: number;
@@ -18,10 +18,10 @@ export declare const TenantInventoryDepartmentUtilitySchema: Schema<any, import(
18
18
  active: boolean;
19
19
  department_code: string;
20
20
  tenant_id: string;
21
+ unit_price: number;
21
22
  unit: import("../../constants").INVENTORY_ITEM_UNIT_ENUM;
22
23
  threshold_quantity: number;
23
24
  quantity_left: number;
24
- unit_price: number;
25
25
  remaining_stock_price: number;
26
26
  ingredients?: import("mongoose").Types.DocumentArray<{
27
27
  inventory_code: string;
@@ -50,10 +50,10 @@ export declare const TenantInventoryDepartmentUtilitySchema: Schema<any, import(
50
50
  active: boolean;
51
51
  department_code: string;
52
52
  tenant_id: string;
53
+ unit_price: number;
53
54
  unit: import("../../constants").INVENTORY_ITEM_UNIT_ENUM;
54
55
  threshold_quantity: number;
55
56
  quantity_left: number;
56
- unit_price: number;
57
57
  remaining_stock_price: number;
58
58
  ingredients?: import("mongoose").Types.DocumentArray<{
59
59
  inventory_code: string;
@@ -82,10 +82,10 @@ export declare const TenantInventoryDepartmentUtilitySchema: Schema<any, import(
82
82
  active: boolean;
83
83
  department_code: string;
84
84
  tenant_id: string;
85
+ unit_price: number;
85
86
  unit: import("../../constants").INVENTORY_ITEM_UNIT_ENUM;
86
87
  threshold_quantity: number;
87
88
  quantity_left: number;
88
- unit_price: number;
89
89
  remaining_stock_price: number;
90
90
  ingredients?: import("mongoose").Types.DocumentArray<{
91
91
  inventory_code: string;