@superblocksteam/shared 0.9611.0 → 2.0.0-SNAPSHOT.12b3e4ccc970c4bd
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/dist/socket/heartbeat.d.ts +10 -0
- package/dist/socket/heartbeat.d.ts.map +1 -1
- package/dist/socket/heartbeat.js +5 -0
- package/dist/socket/heartbeat.js.map +1 -1
- package/dist/socket/heartbeat.test.js +36 -0
- package/dist/socket/heartbeat.test.js.map +1 -1
- package/dist/socket/socket.d.ts +1 -0
- package/dist/socket/socket.d.ts.map +1 -1
- package/dist/socket/socket.js +8 -1
- package/dist/socket/socket.js.map +1 -1
- package/dist/socket/socket.test.js +33 -0
- package/dist/socket/socket.test.js.map +1 -1
- package/dist/types/audit/ocsf.d.ts.map +1 -1
- package/dist/types/audit/ocsf.js +0 -1
- package/dist/types/audit/ocsf.js.map +1 -1
- package/dist/types/policyGate/errors.d.ts +0 -3
- package/dist/types/policyGate/errors.d.ts.map +1 -1
- package/dist/types/policyGate/errors.js +0 -1
- package/dist/types/policyGate/errors.js.map +1 -1
- package/dist/types/policyGate/index.d.ts +0 -1
- package/dist/types/policyGate/index.d.ts.map +1 -1
- package/dist/types/policyGate/index.js +3 -5
- package/dist/types/policyGate/index.js.map +1 -1
- package/dist/utils/attachment-upload.d.ts +9 -0
- package/dist/utils/attachment-upload.d.ts.map +1 -1
- package/dist/utils/attachment-upload.js +26 -0
- package/dist/utils/attachment-upload.js.map +1 -1
- package/dist/utils/attachment-upload.test.js +19 -0
- package/dist/utils/attachment-upload.test.js.map +1 -1
- package/dist-esm/socket/heartbeat.d.ts +10 -0
- package/dist-esm/socket/heartbeat.d.ts.map +1 -1
- package/dist-esm/socket/heartbeat.js +5 -0
- package/dist-esm/socket/heartbeat.js.map +1 -1
- package/dist-esm/socket/heartbeat.test.js +36 -0
- package/dist-esm/socket/heartbeat.test.js.map +1 -1
- package/dist-esm/socket/socket.d.ts +1 -0
- package/dist-esm/socket/socket.d.ts.map +1 -1
- package/dist-esm/socket/socket.js +8 -1
- package/dist-esm/socket/socket.js.map +1 -1
- package/dist-esm/socket/socket.test.js +33 -0
- package/dist-esm/socket/socket.test.js.map +1 -1
- package/dist-esm/types/audit/ocsf.d.ts.map +1 -1
- package/dist-esm/types/audit/ocsf.js +0 -1
- package/dist-esm/types/audit/ocsf.js.map +1 -1
- package/dist-esm/types/policyGate/errors.d.ts +0 -3
- package/dist-esm/types/policyGate/errors.d.ts.map +1 -1
- package/dist-esm/types/policyGate/errors.js +0 -1
- package/dist-esm/types/policyGate/errors.js.map +1 -1
- package/dist-esm/types/policyGate/index.d.ts +0 -1
- package/dist-esm/types/policyGate/index.d.ts.map +1 -1
- package/dist-esm/types/policyGate/index.js +3 -4
- package/dist-esm/types/policyGate/index.js.map +1 -1
- package/dist-esm/utils/attachment-upload.d.ts +9 -0
- package/dist-esm/utils/attachment-upload.d.ts.map +1 -1
- package/dist-esm/utils/attachment-upload.js +25 -0
- package/dist-esm/utils/attachment-upload.js.map +1 -1
- package/dist-esm/utils/attachment-upload.test.js +20 -1
- package/dist-esm/utils/attachment-upload.test.js.map +1 -1
- package/package.json +1 -1
- package/src/socket/heartbeat.test.ts +44 -0
- package/src/socket/heartbeat.ts +15 -0
- package/src/socket/socket.test.ts +43 -0
- package/src/socket/socket.ts +10 -1
- package/src/types/audit/ocsf.ts +0 -1
- package/src/types/policyGate/errors.ts +0 -1
- package/src/types/policyGate/index.ts +5 -5
- package/src/utils/attachment-upload.test.ts +22 -0
- package/src/utils/attachment-upload.ts +28 -0
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
buildAttachmentUploadMetadata,
|
|
6
6
|
buildAttachmentUploadFormData,
|
|
7
7
|
createUploadedAttachmentFromServer,
|
|
8
|
+
getAttachmentMimeTypeFromFileName,
|
|
8
9
|
getTextAttachmentType,
|
|
9
10
|
parseUserFacingUploadError,
|
|
10
11
|
isOfficeXml,
|
|
@@ -12,6 +13,27 @@ import {
|
|
|
12
13
|
toAttachmentUploadDescriptor
|
|
13
14
|
} from './attachment-upload.js';
|
|
14
15
|
|
|
16
|
+
describe('getAttachmentMimeTypeFromFileName', () => {
|
|
17
|
+
test.each([
|
|
18
|
+
['logo.png', 'image/png'],
|
|
19
|
+
['logo.PNG', 'image/png'],
|
|
20
|
+
['photo.jpg', 'image/jpeg'],
|
|
21
|
+
['photo.jpeg', 'image/jpeg'],
|
|
22
|
+
['animation.gif', 'image/gif'],
|
|
23
|
+
['shot.webp', 'image/webp'],
|
|
24
|
+
['report.pdf', 'application/pdf'],
|
|
25
|
+
['server.log', 'text/plain'],
|
|
26
|
+
['rows.csv', 'text/csv'],
|
|
27
|
+
['config.json', 'application/json']
|
|
28
|
+
])('reads %s as %s', (fileName, expected) => {
|
|
29
|
+
expect(getAttachmentMimeTypeFromFileName(fileName)).toBe(expected);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test.each(['app.exe', 'archive.dmg', 'noextension', ''])('has no type for %s', (fileName) => {
|
|
33
|
+
expect(getAttachmentMimeTypeFromFileName(fileName)).toBeUndefined();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
15
37
|
describe('toAttachmentUploadDescriptor', () => {
|
|
16
38
|
test('preserves explicit names for non-File uploads', () => {
|
|
17
39
|
const descriptor = toAttachmentUploadDescriptor({
|
|
@@ -291,6 +291,34 @@ function getTextLikeMimeTypeFromFileName(fileName: string | undefined): string |
|
|
|
291
291
|
return textAttachmentType ? TEXT_ATTACHMENT_MIME_TYPES[textAttachmentType] : undefined;
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
+
/**
|
|
295
|
+
* Names the media type for a file that arrives with nothing but a name, as it
|
|
296
|
+
* does when a caller points at a path instead of handing over the bytes.
|
|
297
|
+
*
|
|
298
|
+
* Derived from {@link MIME_TYPE_FILE_EXTENSIONS} rather than a general-purpose
|
|
299
|
+
* MIME database so the answer stays inside what attachments actually accept:
|
|
300
|
+
* a wider lookup would name a type for `.exe` that upload then refuses.
|
|
301
|
+
*/
|
|
302
|
+
export function getAttachmentMimeTypeFromFileName(fileName?: string): string | undefined {
|
|
303
|
+
const normalizedFileName = normalizeNonEmptyString(fileName)?.toLowerCase();
|
|
304
|
+
if (!normalizedFileName) {
|
|
305
|
+
return undefined;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
for (const [mimeType, extension] of Object.entries(MIME_TYPE_FILE_EXTENSIONS)) {
|
|
309
|
+
// '.jpeg' resolves through the text-like pass below only if listed there,
|
|
310
|
+
// so both spellings are matched here against the canonical extension.
|
|
311
|
+
if (normalizedFileName.endsWith(extension)) {
|
|
312
|
+
return mimeType === 'image/jpg' ? 'image/jpeg' : mimeType;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (normalizedFileName.endsWith('.jpeg')) {
|
|
316
|
+
return 'image/jpeg';
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return getTextLikeMimeTypeFromFileName(normalizedFileName);
|
|
320
|
+
}
|
|
321
|
+
|
|
294
322
|
function isProviderSafeTextMimeType(mimeType: string): boolean {
|
|
295
323
|
return mimeType.startsWith('text/') || mimeType === 'application/json';
|
|
296
324
|
}
|