@managesome/eposmatic-toolkit 0.4.90 → 0.4.93

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 (33) 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/storage/index.js +1 -0
  5. package/esm/helpers/storage/upload-paths.js +384 -0
  6. package/esm/schemas/models/index.js +1 -0
  7. package/esm/schemas/models/pending_uploads.js +102 -0
  8. package/esm/schemas/types/index.js +1 -0
  9. package/esm/schemas/types/pending_uploads.js +1 -0
  10. package/lib/constants/ENUMS.d.ts +1 -0
  11. package/lib/constants/ENUMS.js +1 -0
  12. package/lib/constants/enums/storage.d.ts +21 -0
  13. package/lib/constants/enums/storage.js +26 -0
  14. package/lib/helpers/index.d.ts +1 -0
  15. package/lib/helpers/index.js +1 -0
  16. package/lib/helpers/storage/index.d.ts +1 -0
  17. package/lib/helpers/storage/index.js +17 -0
  18. package/lib/helpers/storage/upload-paths.d.ts +117 -0
  19. package/lib/helpers/storage/upload-paths.js +394 -0
  20. package/lib/schemas/models/index.d.ts +1 -0
  21. package/lib/schemas/models/index.js +1 -0
  22. package/lib/schemas/models/pending_uploads.d.ts +118 -0
  23. package/lib/schemas/models/pending_uploads.js +105 -0
  24. package/lib/schemas/models/tenant_hr_employees.d.ts +3 -3
  25. package/lib/schemas/types/index.d.ts +1 -0
  26. package/lib/schemas/types/index.js +1 -0
  27. package/lib/schemas/types/pending_uploads.d.ts +30 -0
  28. package/lib/schemas/types/pending_uploads.js +2 -0
  29. package/lib/tests/pending-uploads-schema.test.d.ts +1 -0
  30. package/lib/tests/pending-uploads-schema.test.js +79 -0
  31. package/lib/tests/storage-upload-paths.test.d.ts +1 -0
  32. package/lib/tests/storage-upload-paths.test.js +198 -0
  33. 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[];
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.4.90",
3
+ "version": "0.4.93",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",