@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.
- package/esm/constants/ENUMS.js +1 -0
- package/esm/constants/enums/storage.js +23 -0
- package/esm/helpers/index.js +1 -0
- package/esm/helpers/order/generate-warehouse-internal-movement.js +3 -0
- package/esm/helpers/storage/index.js +1 -0
- package/esm/helpers/storage/upload-paths.js +384 -0
- package/esm/helpers/store/common-warehouse-internal-movement-actions.js +124 -4
- package/esm/helpers/utils/discount-amounts.js +64 -0
- package/esm/helpers/utils/index.js +2 -0
- package/esm/helpers/utils/internal-movement-items.js +30 -0
- package/esm/helpers/utils/tenant-purchase-order-engine.js +10 -18
- package/esm/helpers/utils/warehouse-purchase-order-engine.js +10 -18
- package/esm/schemas/models/index.js +1 -0
- package/esm/schemas/models/pending_uploads.js +102 -0
- package/esm/schemas/models/warehouse_internal_movements.js +54 -0
- package/esm/schemas/types/index.js +1 -0
- package/esm/schemas/types/pending_uploads.js +1 -0
- package/lib/constants/ENUMS.d.ts +1 -0
- package/lib/constants/ENUMS.js +1 -0
- package/lib/constants/enums/storage.d.ts +21 -0
- package/lib/constants/enums/storage.js +26 -0
- package/lib/helpers/index.d.ts +1 -0
- package/lib/helpers/index.js +1 -0
- package/lib/helpers/order/generate-warehouse-internal-movement.js +3 -0
- package/lib/helpers/storage/index.d.ts +1 -0
- package/lib/helpers/storage/index.js +17 -0
- package/lib/helpers/storage/upload-paths.d.ts +117 -0
- package/lib/helpers/storage/upload-paths.js +394 -0
- package/lib/helpers/store/common-warehouse-internal-movement-actions.d.ts +33 -1
- package/lib/helpers/store/common-warehouse-internal-movement-actions.js +126 -3
- package/lib/helpers/utils/discount-amounts.d.ts +50 -0
- package/lib/helpers/utils/discount-amounts.js +69 -0
- package/lib/helpers/utils/index.d.ts +2 -0
- package/lib/helpers/utils/index.js +2 -0
- package/lib/helpers/utils/internal-movement-items.d.ts +35 -0
- package/lib/helpers/utils/internal-movement-items.js +36 -0
- package/lib/helpers/utils/tenant-purchase-order-engine.js +9 -17
- package/lib/helpers/utils/warehouse-purchase-order-engine.js +9 -17
- package/lib/schemas/models/index.d.ts +1 -0
- package/lib/schemas/models/index.js +1 -0
- package/lib/schemas/models/inventories.d.ts +3 -3
- package/lib/schemas/models/inventory_transactions.d.ts +3 -3
- package/lib/schemas/models/item_transactions.d.ts +3 -3
- package/lib/schemas/models/materialized_tenant_discount_entries.d.ts +3 -3
- package/lib/schemas/models/materialized_tenant_prep_time_entries.d.ts +3 -3
- package/lib/schemas/models/orders.d.ts +120 -120
- package/lib/schemas/models/pending_uploads.d.ts +118 -0
- package/lib/schemas/models/pending_uploads.js +105 -0
- package/lib/schemas/models/tenant_hr_employees.d.ts +3 -3
- package/lib/schemas/models/tenant_inventory_department_transactions.d.ts +3 -3
- package/lib/schemas/models/tenant_inventory_department_utilities.d.ts +3 -3
- package/lib/schemas/models/warehouse_internal_movements.d.ts +570 -0
- package/lib/schemas/models/warehouse_internal_movements.js +54 -0
- package/lib/schemas/models/warehouse_inventory_transactions.d.ts +3 -3
- package/lib/schemas/models/warehouse_item_transactions.d.ts +3 -3
- package/lib/schemas/models/warehouse_items.d.ts +3 -3
- package/lib/schemas/types/index.d.ts +1 -0
- package/lib/schemas/types/index.js +1 -0
- package/lib/schemas/types/pending_uploads.d.ts +30 -0
- package/lib/schemas/types/pending_uploads.js +2 -0
- package/lib/schemas/types/warehouse_internal_movements.d.ts +17 -1
- package/lib/tests/pending-uploads-schema.test.d.ts +1 -0
- package/lib/tests/pending-uploads-schema.test.js +79 -0
- package/lib/tests/storage-upload-paths.test.d.ts +1 -0
- package/lib/tests/storage-upload-paths.test.js +198 -0
- package/package.json +1 -1
|
@@ -19,6 +19,30 @@ const WarehouseInternalMovementActorSchema = new mongoose_1.Schema({
|
|
|
19
19
|
_id: false,
|
|
20
20
|
minimize: false,
|
|
21
21
|
});
|
|
22
|
+
const WarehouseInternalMovementDiscountDetailsSchema = new mongoose_1.Schema({
|
|
23
|
+
special_discount: {
|
|
24
|
+
type: Number,
|
|
25
|
+
},
|
|
26
|
+
special_discount_id: {
|
|
27
|
+
type: String,
|
|
28
|
+
},
|
|
29
|
+
special_discount_name: {
|
|
30
|
+
type: String,
|
|
31
|
+
},
|
|
32
|
+
is_special_discount_percentage: {
|
|
33
|
+
type: Boolean,
|
|
34
|
+
},
|
|
35
|
+
special_discount_reason: {
|
|
36
|
+
type: String,
|
|
37
|
+
},
|
|
38
|
+
special_reference_number: {
|
|
39
|
+
type: String,
|
|
40
|
+
},
|
|
41
|
+
total_discount: {
|
|
42
|
+
type: Number,
|
|
43
|
+
required: true,
|
|
44
|
+
},
|
|
45
|
+
}, { _id: false, minimize: false });
|
|
22
46
|
const WarehouseInternalMovementItemSchema = new mongoose_1.Schema({
|
|
23
47
|
_id: {
|
|
24
48
|
type: mongoose_1.Schema.Types.ObjectId,
|
|
@@ -60,6 +84,10 @@ const WarehouseInternalMovementItemSchema = new mongoose_1.Schema({
|
|
|
60
84
|
min: 0,
|
|
61
85
|
required: false,
|
|
62
86
|
},
|
|
87
|
+
item_discount_details: {
|
|
88
|
+
type: WarehouseInternalMovementDiscountDetailsSchema,
|
|
89
|
+
default: null,
|
|
90
|
+
},
|
|
63
91
|
notes: {
|
|
64
92
|
type: String,
|
|
65
93
|
required: false,
|
|
@@ -123,6 +151,19 @@ exports.WarehouseInternalMovementIterationSchema = new mongoose_1.Schema({
|
|
|
123
151
|
min: 0,
|
|
124
152
|
required: false,
|
|
125
153
|
},
|
|
154
|
+
order_discount_details: {
|
|
155
|
+
type: WarehouseInternalMovementDiscountDetailsSchema,
|
|
156
|
+
required: false,
|
|
157
|
+
},
|
|
158
|
+
total_discount_applied: {
|
|
159
|
+
type: Number,
|
|
160
|
+
min: 0,
|
|
161
|
+
required: false,
|
|
162
|
+
},
|
|
163
|
+
exclude_discount_from_gst: {
|
|
164
|
+
type: Boolean,
|
|
165
|
+
required: false,
|
|
166
|
+
},
|
|
126
167
|
labor_charges: { type: Number, min: 0, required: false },
|
|
127
168
|
labor_charges_amount: { type: Number, min: 0, required: false },
|
|
128
169
|
is_labor_charges_percentage: { type: Boolean, required: false },
|
|
@@ -269,6 +310,19 @@ exports.WarehouseInternalMovementsSchema = new mongoose_1.Schema({
|
|
|
269
310
|
min: 0,
|
|
270
311
|
required: false,
|
|
271
312
|
},
|
|
313
|
+
order_discount_details: {
|
|
314
|
+
type: WarehouseInternalMovementDiscountDetailsSchema,
|
|
315
|
+
required: false,
|
|
316
|
+
},
|
|
317
|
+
total_discount_applied: {
|
|
318
|
+
type: Number,
|
|
319
|
+
min: 0,
|
|
320
|
+
required: false,
|
|
321
|
+
},
|
|
322
|
+
exclude_discount_from_gst: {
|
|
323
|
+
type: Boolean,
|
|
324
|
+
required: false,
|
|
325
|
+
},
|
|
272
326
|
labor_charges: { type: Number, min: 0, required: false },
|
|
273
327
|
labor_charges_amount: { type: Number, min: 0, required: false },
|
|
274
328
|
is_labor_charges_percentage: { type: Boolean, required: false },
|
|
@@ -13,8 +13,8 @@ export declare const WarehouseInventoryTransactionsSchema: Schema<any, import("m
|
|
|
13
13
|
inventory_code: string;
|
|
14
14
|
createdAt_mins: number;
|
|
15
15
|
warehouse_id: string;
|
|
16
|
-
quantity_left: number;
|
|
17
16
|
unit_price: number;
|
|
17
|
+
quantity_left: number;
|
|
18
18
|
remaining_stock_price: number;
|
|
19
19
|
previous_quantity_left: number;
|
|
20
20
|
previous_unit_price: number;
|
|
@@ -38,8 +38,8 @@ export declare const WarehouseInventoryTransactionsSchema: Schema<any, import("m
|
|
|
38
38
|
inventory_code: string;
|
|
39
39
|
createdAt_mins: number;
|
|
40
40
|
warehouse_id: string;
|
|
41
|
-
quantity_left: number;
|
|
42
41
|
unit_price: number;
|
|
42
|
+
quantity_left: number;
|
|
43
43
|
remaining_stock_price: number;
|
|
44
44
|
previous_quantity_left: number;
|
|
45
45
|
previous_unit_price: number;
|
|
@@ -63,8 +63,8 @@ export declare const WarehouseInventoryTransactionsSchema: Schema<any, import("m
|
|
|
63
63
|
inventory_code: string;
|
|
64
64
|
createdAt_mins: number;
|
|
65
65
|
warehouse_id: string;
|
|
66
|
-
quantity_left: number;
|
|
67
66
|
unit_price: number;
|
|
67
|
+
quantity_left: number;
|
|
68
68
|
remaining_stock_price: number;
|
|
69
69
|
previous_quantity_left: number;
|
|
70
70
|
previous_unit_price: number;
|
|
@@ -17,9 +17,9 @@ export declare const WarehouseItemTransactionsSchema: Schema<any, import("mongoo
|
|
|
17
17
|
warehouse_id: string;
|
|
18
18
|
item_id: import("mongoose").Types.ObjectId;
|
|
19
19
|
quantity: number;
|
|
20
|
+
item_name: string;
|
|
20
21
|
transaction_type: import("../../constants").ITEM_TRANSACTION_TYPE_ENUM;
|
|
21
22
|
selling_price: number;
|
|
22
|
-
item_name: string;
|
|
23
23
|
category_name: string;
|
|
24
24
|
cost_price: number;
|
|
25
25
|
description?: string | null | undefined;
|
|
@@ -38,9 +38,9 @@ export declare const WarehouseItemTransactionsSchema: Schema<any, import("mongoo
|
|
|
38
38
|
warehouse_id: string;
|
|
39
39
|
item_id: import("mongoose").Types.ObjectId;
|
|
40
40
|
quantity: number;
|
|
41
|
+
item_name: string;
|
|
41
42
|
transaction_type: import("../../constants").ITEM_TRANSACTION_TYPE_ENUM;
|
|
42
43
|
selling_price: number;
|
|
43
|
-
item_name: string;
|
|
44
44
|
category_name: string;
|
|
45
45
|
cost_price: number;
|
|
46
46
|
description?: string | null | undefined;
|
|
@@ -59,9 +59,9 @@ export declare const WarehouseItemTransactionsSchema: Schema<any, import("mongoo
|
|
|
59
59
|
warehouse_id: string;
|
|
60
60
|
item_id: import("mongoose").Types.ObjectId;
|
|
61
61
|
quantity: number;
|
|
62
|
+
item_name: string;
|
|
62
63
|
transaction_type: import("../../constants").ITEM_TRANSACTION_TYPE_ENUM;
|
|
63
64
|
selling_price: number;
|
|
64
|
-
item_name: string;
|
|
65
65
|
category_name: string;
|
|
66
66
|
cost_price: number;
|
|
67
67
|
description?: string | null | undefined;
|
|
@@ -35,10 +35,10 @@ export declare const WarehouseItemSchema: Schema<any, import("mongoose").Model<a
|
|
|
35
35
|
hide_name: boolean;
|
|
36
36
|
keywords: string[];
|
|
37
37
|
warehouse_id: string;
|
|
38
|
+
unit_price: number;
|
|
38
39
|
unit: import("../../constants").INVENTORY_ITEM_UNIT_ENUM;
|
|
39
40
|
threshold_quantity: number;
|
|
40
41
|
quantity_left: number;
|
|
41
|
-
unit_price: number;
|
|
42
42
|
remaining_stock_price: number;
|
|
43
43
|
purchase_price: {
|
|
44
44
|
BASE_PRICE: number;
|
|
@@ -84,10 +84,10 @@ export declare const WarehouseItemSchema: Schema<any, import("mongoose").Model<a
|
|
|
84
84
|
hide_name: boolean;
|
|
85
85
|
keywords: string[];
|
|
86
86
|
warehouse_id: string;
|
|
87
|
+
unit_price: number;
|
|
87
88
|
unit: import("../../constants").INVENTORY_ITEM_UNIT_ENUM;
|
|
88
89
|
threshold_quantity: number;
|
|
89
90
|
quantity_left: number;
|
|
90
|
-
unit_price: number;
|
|
91
91
|
remaining_stock_price: number;
|
|
92
92
|
purchase_price: {
|
|
93
93
|
BASE_PRICE: number;
|
|
@@ -133,10 +133,10 @@ export declare const WarehouseItemSchema: Schema<any, import("mongoose").Model<a
|
|
|
133
133
|
hide_name: boolean;
|
|
134
134
|
keywords: string[];
|
|
135
135
|
warehouse_id: string;
|
|
136
|
+
unit_price: number;
|
|
136
137
|
unit: import("../../constants").INVENTORY_ITEM_UNIT_ENUM;
|
|
137
138
|
threshold_quantity: number;
|
|
138
139
|
quantity_left: number;
|
|
139
|
-
unit_price: number;
|
|
140
140
|
remaining_stock_price: number;
|
|
141
141
|
purchase_price: {
|
|
142
142
|
BASE_PRICE: number;
|
|
@@ -66,6 +66,7 @@ export * from './offers';
|
|
|
66
66
|
export * from './offers_fingerprints';
|
|
67
67
|
export * from './operational_roles';
|
|
68
68
|
export * from './orders';
|
|
69
|
+
export * from './pending_uploads';
|
|
69
70
|
export * from './printer_settings';
|
|
70
71
|
export * from './public_holidays';
|
|
71
72
|
export * from './reservations';
|
|
@@ -82,6 +82,7 @@ __exportStar(require("./offers"), exports);
|
|
|
82
82
|
__exportStar(require("./offers_fingerprints"), exports);
|
|
83
83
|
__exportStar(require("./operational_roles"), exports);
|
|
84
84
|
__exportStar(require("./orders"), exports);
|
|
85
|
+
__exportStar(require("./pending_uploads"), exports);
|
|
85
86
|
__exportStar(require("./printer_settings"), exports);
|
|
86
87
|
__exportStar(require("./public_holidays"), exports);
|
|
87
88
|
__exportStar(require("./reservations"), exports);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { PENDING_UPLOAD_REF_TYPE_ENUM, PENDING_UPLOAD_STAGE_ENUM } from '../../constants/enums/storage';
|
|
2
|
+
import type { TStorageUploadKind } from '../../helpers/storage/upload-paths';
|
|
3
|
+
/**
|
|
4
|
+
* One row per server-signed upload attempt.
|
|
5
|
+
*
|
|
6
|
+
* `path` is unique because it is server-built and deterministic. A repeated
|
|
7
|
+
* `/sign` for the same path supersedes the previous row (the route resets the
|
|
8
|
+
* timestamps), which matches the last-writer-wins behaviour of a deterministic
|
|
9
|
+
* object path.
|
|
10
|
+
*/
|
|
11
|
+
export interface IPendingUpload {
|
|
12
|
+
_id: string;
|
|
13
|
+
path: string;
|
|
14
|
+
uid: string;
|
|
15
|
+
kind: TStorageUploadKind;
|
|
16
|
+
ref_type: PENDING_UPLOAD_REF_TYPE_ENUM;
|
|
17
|
+
ref_id: string;
|
|
18
|
+
stage?: PENDING_UPLOAD_STAGE_ENUM | null;
|
|
19
|
+
mime: string;
|
|
20
|
+
max_bytes: number;
|
|
21
|
+
uploaded_at?: Date | null;
|
|
22
|
+
committed_at?: Date | null;
|
|
23
|
+
discarded_at?: Date | null;
|
|
24
|
+
expires_at: Date;
|
|
25
|
+
size?: number | null;
|
|
26
|
+
content_type?: string | null;
|
|
27
|
+
generation?: string | null;
|
|
28
|
+
createdAt: Date;
|
|
29
|
+
updatedAt: Date;
|
|
30
|
+
}
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import { WAREHOUSE_INTERNAL_MOVEMENT_EDIT_REQUEST_STATUS_ENUM, WAREHOUSE_INTERNAL_MOVEMENT_FLOW_ENUM, WAREHOUSE_INTERNAL_MOVEMENT_LOCATION_TYPE_ENUM, WAREHOUSE_INTERNAL_MOVEMENT_RECORD_TYPE_ENUM, WAREHOUSE_INTERNAL_MOVEMENT_STATUS_ENUM, WAREHOUSE_REF_TYPE_ENUM } from '../../constants';
|
|
2
|
-
import { IOrderPayment } from './orders';
|
|
2
|
+
import { IDiscountDetails, IOrderPayment } from './orders';
|
|
3
3
|
export interface IWarehouseInternalMovementActorRef {
|
|
4
4
|
uid: string;
|
|
5
5
|
name: string;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Order-level discount on an internal movement.
|
|
9
|
+
*/
|
|
10
|
+
export interface IWarehouseInternalMovementDiscountDetails {
|
|
11
|
+
special_discount?: number;
|
|
12
|
+
special_discount_id?: string;
|
|
13
|
+
special_discount_name?: string;
|
|
14
|
+
is_special_discount_percentage?: boolean;
|
|
15
|
+
special_discount_reason?: string;
|
|
16
|
+
special_reference_number?: string;
|
|
17
|
+
total_discount: number;
|
|
18
|
+
}
|
|
7
19
|
export interface IWarehouseInternalMovementItem {
|
|
8
20
|
_id: string;
|
|
9
21
|
item_id: string;
|
|
@@ -13,6 +25,7 @@ export interface IWarehouseInternalMovementItem {
|
|
|
13
25
|
dispatched_qty?: number | null;
|
|
14
26
|
received_qty: number;
|
|
15
27
|
unit_price?: number;
|
|
28
|
+
item_discount_details?: IDiscountDetails | null;
|
|
16
29
|
notes?: string | null;
|
|
17
30
|
}
|
|
18
31
|
export interface IWarehouseInternalMovementStatusMeta {
|
|
@@ -59,6 +72,9 @@ export interface IWarehouseInternalMovementIteration {
|
|
|
59
72
|
is_gst_inclusive?: boolean;
|
|
60
73
|
gst?: number | null;
|
|
61
74
|
gst_amount?: number | null;
|
|
75
|
+
order_discount_details?: IWarehouseInternalMovementDiscountDetails | null;
|
|
76
|
+
total_discount_applied?: number;
|
|
77
|
+
exclude_discount_from_gst?: boolean;
|
|
62
78
|
labor_charges?: number;
|
|
63
79
|
labor_charges_amount?: number;
|
|
64
80
|
is_labor_charges_percentage?: boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
7
|
+
const pending_uploads_1 = require("../schemas/models/pending_uploads");
|
|
8
|
+
const constants_1 = require("../constants");
|
|
9
|
+
const upload_paths_1 = require("../helpers/storage/upload-paths");
|
|
10
|
+
const PendingUploadModel = mongoose_1.default.model('PendingUploadSchemaTest', pending_uploads_1.PendingUploadSchema);
|
|
11
|
+
const valid = {
|
|
12
|
+
path: 'images/tenants/tenant-a/image_url.jpeg',
|
|
13
|
+
uid: 'uid-a',
|
|
14
|
+
kind: upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_IMAGE,
|
|
15
|
+
ref_type: constants_1.PENDING_UPLOAD_REF_TYPE_ENUM.TENANT,
|
|
16
|
+
ref_id: 'tenant-a',
|
|
17
|
+
mime: 'image/jpeg',
|
|
18
|
+
max_bytes: 5 * 1024 * 1024,
|
|
19
|
+
expires_at: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000),
|
|
20
|
+
};
|
|
21
|
+
describe('PendingUploadSchema', () => {
|
|
22
|
+
it('uses the pending_uploads collection', () => {
|
|
23
|
+
expect(pending_uploads_1.PENDING_UPLOADS_COLLECTION_NAME).toBe('pending_uploads');
|
|
24
|
+
expect(pending_uploads_1.PendingUploadSchema.get('collection')).toBe('pending_uploads');
|
|
25
|
+
});
|
|
26
|
+
it('declares explicit standard createdAt/updatedAt timestamps', () => {
|
|
27
|
+
expect(pending_uploads_1.PendingUploadSchema.get('timestamps')).toBe(true);
|
|
28
|
+
const createdAt = pending_uploads_1.PendingUploadSchema.path('createdAt');
|
|
29
|
+
const updatedAt = pending_uploads_1.PendingUploadSchema.path('updatedAt');
|
|
30
|
+
expect(createdAt.options.required).toBe(true);
|
|
31
|
+
expect(createdAt.options.immutable).toBe(true);
|
|
32
|
+
expect(updatedAt.options.required).toBe(true);
|
|
33
|
+
expect(pending_uploads_1.PendingUploadSchema.path('created_at')).toBeUndefined();
|
|
34
|
+
});
|
|
35
|
+
it('accepts a minimal valid row', () => {
|
|
36
|
+
const doc = new PendingUploadModel(valid);
|
|
37
|
+
expect(doc.validateSync()).toBeUndefined();
|
|
38
|
+
});
|
|
39
|
+
it('rejects an unknown kind', () => {
|
|
40
|
+
const doc = new PendingUploadModel({ ...valid, kind: 'other.kind' });
|
|
41
|
+
expect(doc.validateSync()).toBeDefined();
|
|
42
|
+
});
|
|
43
|
+
it('rejects an unknown stage', () => {
|
|
44
|
+
const doc = new PendingUploadModel({ ...valid, stage: 'other' });
|
|
45
|
+
expect(doc.validateSync()).toBeDefined();
|
|
46
|
+
});
|
|
47
|
+
it('uses the stage enum values', () => {
|
|
48
|
+
expect(pending_uploads_1.PendingUploadSchema.path('stage').options.enum).toEqual(constants_1.ALL_PENDING_UPLOAD_STAGES);
|
|
49
|
+
});
|
|
50
|
+
it('rejects an unknown ref_type', () => {
|
|
51
|
+
const doc = new PendingUploadModel({ ...valid, ref_type: 'OTHER' });
|
|
52
|
+
expect(doc.validateSync()).toBeDefined();
|
|
53
|
+
});
|
|
54
|
+
it('requires a ref_id', () => {
|
|
55
|
+
const doc = new PendingUploadModel({ ...valid, ref_id: undefined });
|
|
56
|
+
expect(doc.validateSync()).toBeDefined();
|
|
57
|
+
});
|
|
58
|
+
it('exports hintable key patterns for the indexes', () => {
|
|
59
|
+
expect(pending_uploads_1.PENDING_UPLOADS_COLLECTION_INDEXES.path).toEqual({ path: 1 });
|
|
60
|
+
expect(pending_uploads_1.PENDING_UPLOADS_COLLECTION_INDEXES.uid__createdAt).toEqual({
|
|
61
|
+
uid: 1,
|
|
62
|
+
createdAt: -1,
|
|
63
|
+
});
|
|
64
|
+
expect(pending_uploads_1.PENDING_UPLOADS_COLLECTION_INDEXES.expires_at).toEqual({ expires_at: 1 });
|
|
65
|
+
});
|
|
66
|
+
it('exports the unique path and TTL creation options', () => {
|
|
67
|
+
const byName = new Map(pending_uploads_1.PENDING_UPLOADS_INDEX_OPTIONS.map((option) => [option.name, option]));
|
|
68
|
+
expect(byName.get('path')?.key).toEqual({ path: 1 });
|
|
69
|
+
expect(byName.get('path')?.unique).toBe(true);
|
|
70
|
+
expect(byName.get('uid__createdAt')?.key).toEqual({ uid: 1, createdAt: -1 });
|
|
71
|
+
expect(byName.get('expires_at_ttl')?.key).toEqual({ expires_at: 1 });
|
|
72
|
+
expect(byName.get('expires_at_ttl')?.expireAfterSeconds).toBe(0);
|
|
73
|
+
});
|
|
74
|
+
it('does not attach ad-hoc schema.index() definitions', () => {
|
|
75
|
+
// Toolkit convention: indexes are exported as key patterns/options and
|
|
76
|
+
// created by the owning service's migration, never attached to the schema.
|
|
77
|
+
expect(pending_uploads_1.PendingUploadSchema.indexes()).toEqual([]);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const upload_paths_1 = require("../helpers/storage/upload-paths");
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const UUID = '123e4567-e89b-42d3-a456-426614174000';
|
|
6
|
+
const DELIVERY_ID = '64b7f9c2a1b2c3d4e5f60718';
|
|
7
|
+
const RECORD_ID = '64b7f9c2a1b2c3d4e5f60719';
|
|
8
|
+
const ids = {
|
|
9
|
+
brand_id: 'brand-a',
|
|
10
|
+
tenant_id: 'tenant-a',
|
|
11
|
+
warehouse_id: 'warehouse-a',
|
|
12
|
+
employee_id: 'employee-a',
|
|
13
|
+
delivery_id: DELIVERY_ID,
|
|
14
|
+
record_id: RECORD_ID,
|
|
15
|
+
resource_id: 'resource-a',
|
|
16
|
+
stage: constants_1.PENDING_UPLOAD_STAGE_ENUM.PICKUP,
|
|
17
|
+
};
|
|
18
|
+
function build(kind, overrides = {}) {
|
|
19
|
+
return (0, upload_paths_1.buildStorageUploadPath)({
|
|
20
|
+
kind,
|
|
21
|
+
ids: { ...ids, ...(overrides.ids ?? {}) },
|
|
22
|
+
mime: overrides.mime ?? 'image/jpeg',
|
|
23
|
+
filename: overrides.filename,
|
|
24
|
+
uuid: Object.prototype.hasOwnProperty.call(overrides, 'uuid') ? overrides.uuid : UUID,
|
|
25
|
+
uid: Object.prototype.hasOwnProperty.call(overrides, 'uid') ? overrides.uid : 'rider-uid',
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
describe('buildStorageUploadPath', () => {
|
|
29
|
+
const expected = [
|
|
30
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.BRAND_IMAGE, 'images/brands/brand-a/image_url.jpeg'],
|
|
31
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.BRAND_CATEGORY_IMAGE, `images/brands/brand-a/categories/${RECORD_ID}.jpeg`],
|
|
32
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.BRAND_CATEGORY_BANNER, `images/brands/brand-a/categories-banner/${RECORD_ID}.jpeg`],
|
|
33
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.BRAND_ITEM_IMAGE, `images/brands/brand-a/items/${RECORD_ID}.jpeg`],
|
|
34
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.BRAND_OFFER_IMAGE, `images/brands/brand-a/offers/${RECORD_ID}.jpeg`],
|
|
35
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.BRAND_SPECIAL_IMAGE, `images/brands/brand-a/specials/${RECORD_ID}.jpeg`],
|
|
36
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.BRAND_HALF_HALF_IMAGE, `images/brands/brand-a/halfhalf/${RECORD_ID}.jpeg`],
|
|
37
|
+
[
|
|
38
|
+
upload_paths_1.STORAGE_UPLOAD_KIND.BRAND_WAREHOUSE_CATEGORY_IMAGE,
|
|
39
|
+
`images/brands/brand-a/warehouse-categories/${RECORD_ID}.jpeg`,
|
|
40
|
+
],
|
|
41
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.BRAND_WAREHOUSE_ITEM_IMAGE, `images/brands/brand-a/warehouse-items/${RECORD_ID}.jpeg`],
|
|
42
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_IMAGE, 'images/tenants/tenant-a/image_url.jpeg'],
|
|
43
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_WEB_COVER, 'images/tenants/tenant-a/web_cover.jpeg'],
|
|
44
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_WEB_FAVICON, 'images/tenants/tenant-a/web_favicon.jpeg'],
|
|
45
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_DIGITAL_MENU, `images/tenants/tenant-a/digital-menu/${UUID}.jpeg`],
|
|
46
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_SLIDER, `images/tenants/tenant-a/sliders/${UUID}.jpeg`],
|
|
47
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_STAFF_IMAGE, `images/tenants/tenant-a/staff/${RECORD_ID}.jpeg`],
|
|
48
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_MARKETING_IMAGE, `images/tenants/tenant-a/marketing/${RECORD_ID}.jpeg`],
|
|
49
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_EXPENSE_IMAGE, `images/tenants/tenant-a/expense-details/${RECORD_ID}.jpeg`],
|
|
50
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_INVENTORY_IMAGE, `images/tenants/tenant-a/inventory/${RECORD_ID}.jpeg`],
|
|
51
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_DEPARTMENT_IMAGE, `images/tenants/tenant-a/departments/${RECORD_ID}.jpeg`],
|
|
52
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.WAREHOUSE_IMAGE, 'images/warehouses/warehouse-a/image_url.jpeg'],
|
|
53
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.WAREHOUSE_STAFF_IMAGE, `images/warehouses/warehouse-a/staff/${RECORD_ID}.jpeg`],
|
|
54
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.WAREHOUSE_INVENTORY_IMAGE, `images/warehouses/warehouse-a/inventory/${RECORD_ID}.jpeg`],
|
|
55
|
+
[
|
|
56
|
+
upload_paths_1.STORAGE_UPLOAD_KIND.WAREHOUSE_EXPENSE_IMAGE,
|
|
57
|
+
`images/warehouses/warehouse-a/warehouse-expense-details/${RECORD_ID}.jpeg`,
|
|
58
|
+
],
|
|
59
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.DOCUMENT_HR, `documents/tenants/tenant-a/hr-documents/employee-a/${UUID}.pdf`],
|
|
60
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.DOCUMENT_POLICY, `documents/tenants/tenant-a/hr-policies/${UUID}.pdf`],
|
|
61
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.INTERNAL_RESTAURANT_IMAGE, 'images/restaurants/resource-a/image_url.jpeg'],
|
|
62
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.INTERNAL_EXPENSE_IMAGE, 'images/expenses/resource-a/image_url.jpeg'],
|
|
63
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.RIDER_IMAGE, 'images/riders/rider-uid/image_url.jpeg'],
|
|
64
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.DELIVERY_PROOF, `images/deliveries/${DELIVERY_ID}/pickup_food_image_url.jpeg`],
|
|
65
|
+
];
|
|
66
|
+
it.each(expected)('builds the canonical path for %s', (kind, path) => {
|
|
67
|
+
const result = build(kind, {
|
|
68
|
+
mime: kind.startsWith('document.') ? 'application/pdf' : 'image/jpeg',
|
|
69
|
+
filename: kind.startsWith('document.') ? 'Policy.PDF' : undefined,
|
|
70
|
+
});
|
|
71
|
+
expect(result.path).toBe(path);
|
|
72
|
+
expect(result.path).not.toContain('?');
|
|
73
|
+
expect(result.path).not.toContain('#');
|
|
74
|
+
expect(result.path).not.toContain('..');
|
|
75
|
+
expect(result.extension.startsWith('.')).toBe(true);
|
|
76
|
+
});
|
|
77
|
+
it('registers every defined kind', () => {
|
|
78
|
+
for (const kind of Object.values(upload_paths_1.STORAGE_UPLOAD_KIND)) {
|
|
79
|
+
expect((0, upload_paths_1.getStorageUploadDefinition)(kind).kind).toBe(kind);
|
|
80
|
+
expect(build(kind, {
|
|
81
|
+
mime: kind.startsWith('document.') ? 'application/pdf' : 'image/jpeg',
|
|
82
|
+
filename: kind.startsWith('document.') ? 'file.pdf' : undefined,
|
|
83
|
+
}).path.length).toBeGreaterThan(0);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
it('uses the image max by default and the document max for HR files', () => {
|
|
87
|
+
expect(build(upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_IMAGE).maxBytes).toBe(upload_paths_1.IMAGE_MAX_BYTES);
|
|
88
|
+
expect(build(upload_paths_1.STORAGE_UPLOAD_KIND.DOCUMENT_HR, {
|
|
89
|
+
mime: 'application/pdf',
|
|
90
|
+
filename: 'terms.pdf',
|
|
91
|
+
}).maxBytes).toBe(upload_paths_1.DOCUMENT_MAX_BYTES);
|
|
92
|
+
});
|
|
93
|
+
it('derives the extension from the MIME subtype for images', () => {
|
|
94
|
+
expect(build(upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_IMAGE, { mime: 'image/png' }).path).toMatch(/\.png$/);
|
|
95
|
+
expect(build(upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_IMAGE, { mime: 'image/webp' }).path).toMatch(/\.webp$/);
|
|
96
|
+
expect(build(upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_IMAGE, { mime: 'image/jpg' }).path).toMatch(/\.jpeg$/);
|
|
97
|
+
expect(build(upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_IMAGE, { mime: 'image/jpeg; charset=binary' }).path).toMatch(/\.jpeg$/);
|
|
98
|
+
});
|
|
99
|
+
it('keeps a safe document extension from the filename and rejects mismatches', () => {
|
|
100
|
+
expect(build(upload_paths_1.STORAGE_UPLOAD_KIND.DOCUMENT_POLICY, {
|
|
101
|
+
mime: 'application/pdf',
|
|
102
|
+
filename: 'Policy.PDF',
|
|
103
|
+
}).path).toMatch(/\.pdf$/);
|
|
104
|
+
expect(() => build(upload_paths_1.STORAGE_UPLOAD_KIND.DOCUMENT_POLICY, {
|
|
105
|
+
mime: 'application/pdf',
|
|
106
|
+
filename: 'policy.html',
|
|
107
|
+
})).toThrow(upload_paths_1.StorageUploadValidationError);
|
|
108
|
+
});
|
|
109
|
+
it('rejects unknown kinds', () => {
|
|
110
|
+
expect((0, upload_paths_1.isStorageUploadKind)('nope')).toBe(false);
|
|
111
|
+
expect(() => build('nope')).toThrow(upload_paths_1.StorageUploadValidationError);
|
|
112
|
+
});
|
|
113
|
+
it('rejects path traversal in every supplied id', () => {
|
|
114
|
+
const badIds = ['../other', 'a/b', 'a\\b', '%2e%2e', 'a b', 'a?b', '.hidden', '..', '', 'a'.repeat(129)];
|
|
115
|
+
for (const bad of badIds) {
|
|
116
|
+
expect(() => build(upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_IMAGE, { ids: { tenant_id: bad } })).toThrow(upload_paths_1.StorageUploadValidationError);
|
|
117
|
+
expect(() => build(upload_paths_1.STORAGE_UPLOAD_KIND.BRAND_CATEGORY_IMAGE, { ids: { record_id: bad } })).toThrow(upload_paths_1.StorageUploadValidationError);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
it('rejects a missing required id', () => {
|
|
121
|
+
expect(() => build(upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_IMAGE, { ids: { tenant_id: undefined } })).toThrow(upload_paths_1.StorageUploadValidationError);
|
|
122
|
+
expect(() => build(upload_paths_1.STORAGE_UPLOAD_KIND.BRAND_CATEGORY_IMAGE, { ids: { record_id: undefined } })).toThrow(upload_paths_1.StorageUploadValidationError);
|
|
123
|
+
});
|
|
124
|
+
it('rejects unsupported image MIME types, including SVG', () => {
|
|
125
|
+
expect(() => build(upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_IMAGE, { mime: 'image/svg+xml' })).toThrow(upload_paths_1.StorageUploadValidationError);
|
|
126
|
+
expect(() => build(upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_IMAGE, { mime: 'application/pdf' })).toThrow(upload_paths_1.StorageUploadValidationError);
|
|
127
|
+
});
|
|
128
|
+
it('requires a server UUID for UUID leaf kinds and rejects malformed ones', () => {
|
|
129
|
+
expect(() => build(upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_DIGITAL_MENU, { uuid: undefined })).toThrow(upload_paths_1.StorageUploadValidationError);
|
|
130
|
+
expect(() => build(upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_DIGITAL_MENU, { uuid: '../escape' })).toThrow(upload_paths_1.StorageUploadValidationError);
|
|
131
|
+
});
|
|
132
|
+
it('requires the rider uid for rider images', () => {
|
|
133
|
+
expect(() => build(upload_paths_1.STORAGE_UPLOAD_KIND.RIDER_IMAGE, { uid: undefined })).toThrow(upload_paths_1.StorageUploadValidationError);
|
|
134
|
+
});
|
|
135
|
+
it('requires and validates the delivery stage', () => {
|
|
136
|
+
expect(() => build(upload_paths_1.STORAGE_UPLOAD_KIND.DELIVERY_PROOF, { ids: { stage: undefined } })).toThrow(upload_paths_1.StorageUploadValidationError);
|
|
137
|
+
expect(() => build(upload_paths_1.STORAGE_UPLOAD_KIND.DELIVERY_PROOF, { ids: { stage: 'other' } })).toThrow(upload_paths_1.StorageUploadValidationError);
|
|
138
|
+
expect(build(upload_paths_1.STORAGE_UPLOAD_KIND.DELIVERY_PROOF, { ids: { stage: constants_1.PENDING_UPLOAD_STAGE_ENUM.DROPOFF } }).path).toContain('/dropoff_food_image_url.jpeg');
|
|
139
|
+
expect(() => build(upload_paths_1.STORAGE_UPLOAD_KIND.DELIVERY_PROOF, {
|
|
140
|
+
ids: { stage: 'pickup' },
|
|
141
|
+
})).toThrow(upload_paths_1.StorageUploadValidationError);
|
|
142
|
+
});
|
|
143
|
+
it('returns the ledger ref_type/ref_id for each owner family', () => {
|
|
144
|
+
const cases = [
|
|
145
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_IMAGE, {}, constants_1.PENDING_UPLOAD_REF_TYPE_ENUM.TENANT, 'tenant-a'],
|
|
146
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.BRAND_CATEGORY_IMAGE, {}, constants_1.PENDING_UPLOAD_REF_TYPE_ENUM.BRAND, 'brand-a'],
|
|
147
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.WAREHOUSE_IMAGE, {}, constants_1.PENDING_UPLOAD_REF_TYPE_ENUM.WAREHOUSE, 'warehouse-a'],
|
|
148
|
+
[
|
|
149
|
+
upload_paths_1.STORAGE_UPLOAD_KIND.DOCUMENT_HR,
|
|
150
|
+
{ mime: 'application/pdf', filename: 'contract.pdf' },
|
|
151
|
+
constants_1.PENDING_UPLOAD_REF_TYPE_ENUM.EMPLOYEE,
|
|
152
|
+
'employee-a',
|
|
153
|
+
],
|
|
154
|
+
[
|
|
155
|
+
upload_paths_1.STORAGE_UPLOAD_KIND.DOCUMENT_POLICY,
|
|
156
|
+
{ mime: 'application/pdf', filename: 'policy.pdf' },
|
|
157
|
+
constants_1.PENDING_UPLOAD_REF_TYPE_ENUM.TENANT,
|
|
158
|
+
'tenant-a',
|
|
159
|
+
],
|
|
160
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.INTERNAL_RESTAURANT_IMAGE, {}, constants_1.PENDING_UPLOAD_REF_TYPE_ENUM.RESTAURANT, 'resource-a'],
|
|
161
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.RIDER_IMAGE, {}, constants_1.PENDING_UPLOAD_REF_TYPE_ENUM.RIDER, 'rider-uid'],
|
|
162
|
+
[upload_paths_1.STORAGE_UPLOAD_KIND.DELIVERY_PROOF, {}, constants_1.PENDING_UPLOAD_REF_TYPE_ENUM.DELIVERY, DELIVERY_ID],
|
|
163
|
+
];
|
|
164
|
+
for (const [kind, overrides, refType, refId] of cases) {
|
|
165
|
+
const result = build(kind, overrides);
|
|
166
|
+
expect(result.refType).toBe(refType);
|
|
167
|
+
expect(result.refId).toBe(refId);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
it('supports favicon MIME types', () => {
|
|
171
|
+
expect(build(upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_WEB_FAVICON, { mime: 'image/x-icon' }).path).toMatch(/\.ico$/);
|
|
172
|
+
expect(build(upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_WEB_FAVICON, { mime: 'image/vnd.microsoft.icon' }).path).toMatch(/\.ico$/);
|
|
173
|
+
});
|
|
174
|
+
it('rejects non-string runtime inputs instead of throwing a TypeError', () => {
|
|
175
|
+
expect(() => build(upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_IMAGE, { mime: 123 })).toThrow(upload_paths_1.StorageUploadValidationError);
|
|
176
|
+
expect(() => build(upload_paths_1.STORAGE_UPLOAD_KIND.DOCUMENT_POLICY, {
|
|
177
|
+
mime: 'application/pdf',
|
|
178
|
+
filename: 123,
|
|
179
|
+
})).toThrow(upload_paths_1.StorageUploadValidationError);
|
|
180
|
+
expect(() => build(upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_DIGITAL_MENU, { uuid: 123 })).toThrow(upload_paths_1.StorageUploadValidationError);
|
|
181
|
+
expect(() => build(upload_paths_1.STORAGE_UPLOAD_KIND.RIDER_IMAGE, { uid: 123 })).toThrow(upload_paths_1.StorageUploadValidationError);
|
|
182
|
+
expect(() => build(upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_IMAGE, { ids: { tenant_id: 123 } })).toThrow(upload_paths_1.StorageUploadValidationError);
|
|
183
|
+
});
|
|
184
|
+
it('normalizes MIME parameters', () => {
|
|
185
|
+
expect((0, upload_paths_1.normalizeStorageMime)(' Image/JPEG; charset=binary ')).toBe('image/jpeg');
|
|
186
|
+
});
|
|
187
|
+
it('exposes route-scoped kinds', () => {
|
|
188
|
+
const operations = (0, upload_paths_1.getStorageUploadKindsForRoute)('operations');
|
|
189
|
+
expect(operations).toContain(upload_paths_1.STORAGE_UPLOAD_KIND.WAREHOUSE_IMAGE);
|
|
190
|
+
expect(operations).toContain(upload_paths_1.STORAGE_UPLOAD_KIND.BRAND_WAREHOUSE_ITEM_IMAGE);
|
|
191
|
+
expect(operations).not.toContain(upload_paths_1.STORAGE_UPLOAD_KIND.TENANT_IMAGE);
|
|
192
|
+
const riders = (0, upload_paths_1.getStorageUploadKindsForRoute)('riders');
|
|
193
|
+
expect(riders).toHaveLength(2);
|
|
194
|
+
expect(riders).toContain(upload_paths_1.STORAGE_UPLOAD_KIND.RIDER_IMAGE);
|
|
195
|
+
expect(riders).toContain(upload_paths_1.STORAGE_UPLOAD_KIND.DELIVERY_PROOF);
|
|
196
|
+
expect((0, upload_paths_1.getStorageUploadKindsForRoute)('items')).toContain(upload_paths_1.STORAGE_UPLOAD_KIND.DOCUMENT_HR);
|
|
197
|
+
});
|
|
198
|
+
});
|