Skip to content

Commit 80d3132

Browse files
committed
chore: Clean up
1 parent b82622e commit 80d3132

3 files changed

Lines changed: 56 additions & 26 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@chatwoot/utils",
3-
"version": "0.0.54",
3+
"version": "0.0.55",
44
"description": "Chatwoot utils",
55
"private": false,
66
"license": "MIT",

src/fileUploadRules.ts

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const INBOX_TYPES = {
5454
} as const;
5555

5656
// derive key type AFTER INBOX_TYPES is declared
57-
type ChannelKey = typeof INBOX_TYPES[keyof typeof INBOX_TYPES];
57+
type ChannelKey = (typeof INBOX_TYPES)[keyof typeof INBOX_TYPES];
5858

5959
// CHANNEL_CONFIGS shape: channels are optional; default node requires max
6060
type ChannelConfigs = Partial<Record<ChannelKey, ChannelConfig>> & {
@@ -88,33 +88,36 @@ type ChannelConfigs = Partial<Record<ChannelKey, ChannelConfig>> & {
8888
* 2. channel + "*" fallback
8989
* 3. global default
9090
*/
91+
92+
const STANDARD_TEXT_MIMES = ['csv', 'plain', 'rtf', 'xml'];
93+
const STANDARD_APPLICATION_MIMES = [
94+
'json',
95+
'pdf',
96+
'xml',
97+
'zip',
98+
'x-7z-compressed',
99+
'vnd.rar',
100+
'x-tar',
101+
'msword',
102+
'vnd.ms-excel',
103+
'vnd.ms-powerpoint',
104+
'vnd.oasis.opendocument.text',
105+
'vnd.openxmlformats-officedocument.presentationml.presentation',
106+
'vnd.openxmlformats-officedocument.spreadsheetml.sheet',
107+
'vnd.openxmlformats-officedocument.wordprocessingml.document',
108+
];
109+
const STANDARD_EXTENSIONS = ['.3gpp', '.xls', '.xlsx'];
110+
91111
const CHANNEL_CONFIGS: ChannelConfigs = {
92112
default: {
93113
mimeGroups: {
94114
image: ['*'],
95115
audio: ['*'],
96116
video: ['*'],
97-
text: ['csv', 'plain', 'rtf', 'xml'],
98-
application: [
99-
'json',
100-
'pdf',
101-
'xml',
102-
'zip',
103-
'x-7z-compressed',
104-
'vnd.rar',
105-
'x-tar',
106-
'msword',
107-
'vnd.ms-excel',
108-
'vnd.ms-powerpoint',
109-
'vnd.oasis.opendocument.text',
110-
'vnd.openxmlformats-officedocument.presentationml.presentation',
111-
'vnd.openxmlformats-officedocument.spreadsheetml.sheet',
112-
'vnd.openxmlformats-officedocument.wordprocessingml.document',
113-
'x-pkcs12',
114-
'pkcs12',
115-
],
117+
text: STANDARD_TEXT_MIMES,
118+
application: [...STANDARD_APPLICATION_MIMES, 'x-pkcs12', 'pkcs12'],
116119
},
117-
extensions: ['.3gpp', '.xls', '.xlsx', '.pfx'],
120+
extensions: [...STANDARD_EXTENSIONS, '.pfx'],
118121
max: 40,
119122
},
120123

@@ -193,7 +196,17 @@ const CHANNEL_CONFIGS: ChannelConfigs = {
193196
},
194197

195198
[INBOX_TYPES.TWILIO]: {
196-
sms: { max: 5 },
199+
sms: {
200+
mimeGroups: {
201+
image: ['jpeg', 'png'],
202+
audio: ['*'],
203+
video: ['*'],
204+
text: STANDARD_TEXT_MIMES,
205+
application: STANDARD_APPLICATION_MIMES,
206+
},
207+
extensions: STANDARD_EXTENSIONS,
208+
max: 5,
209+
},
197210
whatsapp: {
198211
mimeGroups: {
199212
image: ['png', 'jpeg'],

test/fileUploadRules.test.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
2-
INBOX_TYPES,
32
getAllowedFileTypesByChannel,
43
getMaxUploadSizeByChannel,
4+
INBOX_TYPES,
55
} from '../src/fileUploadRules';
66

77
describe('uploadRules helper', () => {
@@ -15,6 +15,9 @@ describe('uploadRules helper', () => {
1515
expect(accept).toContain('text/plain');
1616
expect(accept).toContain('application/json');
1717
expect(accept).toContain('.3gpp');
18+
expect(accept).toContain('application/x-pkcs12');
19+
expect(accept).toContain('application/pkcs12');
20+
expect(accept).toContain('.pfx');
1821
});
1922

2023
it('returns WhatsApp specific accept list', () => {
@@ -33,6 +36,8 @@ describe('uploadRules helper', () => {
3336
expect(accept).not.toContain('application/json');
3437
expect(accept).not.toContain('.3gpp');
3538
expect(accept).not.toContain('image/gif');
39+
expect(accept).not.toContain('application/x-pkcs12');
40+
expect(accept).not.toContain('.pfx');
3641
});
3742

3843
it('returns Instagram specific accept list', () => {
@@ -73,13 +78,25 @@ describe('uploadRules helper', () => {
7378
expect(accept).not.toContain('audio/mp3');
7479
});
7580

76-
it('falls back to default accept list for Twilio SMS (no mimeGroups)', () => {
81+
it('returns Twilio SMS accept list (default-aligned, excluding PFX)', () => {
7782
const accept = getAllowedFileTypesByChannel({
7883
channelType: INBOX_TYPES.TWILIO,
7984
medium: 'sms',
8085
});
81-
expect(accept).toContain('image/*');
86+
expect(accept).toContain('image/jpeg');
87+
expect(accept).toContain('image/png');
88+
expect(accept).not.toContain('image/*');
89+
expect(accept).not.toContain('image/gif');
90+
expect(accept).toContain('audio/*');
91+
expect(accept).toContain('video/*');
92+
expect(accept).toContain('text/plain');
93+
expect(accept).toContain('application/pdf');
94+
expect(accept).toContain('application/json');
8295
expect(accept).toContain('.3gpp');
96+
expect(accept).toContain('.xls');
97+
expect(accept).not.toContain('application/x-pkcs12');
98+
expect(accept).not.toContain('application/pkcs12');
99+
expect(accept).not.toContain('.pfx');
83100
});
84101

85102
it('handles empty object parameter', () => {

0 commit comments

Comments
 (0)