@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.
Files changed (68) hide show
  1. package/dist/socket/heartbeat.d.ts +10 -0
  2. package/dist/socket/heartbeat.d.ts.map +1 -1
  3. package/dist/socket/heartbeat.js +5 -0
  4. package/dist/socket/heartbeat.js.map +1 -1
  5. package/dist/socket/heartbeat.test.js +36 -0
  6. package/dist/socket/heartbeat.test.js.map +1 -1
  7. package/dist/socket/socket.d.ts +1 -0
  8. package/dist/socket/socket.d.ts.map +1 -1
  9. package/dist/socket/socket.js +8 -1
  10. package/dist/socket/socket.js.map +1 -1
  11. package/dist/socket/socket.test.js +33 -0
  12. package/dist/socket/socket.test.js.map +1 -1
  13. package/dist/types/audit/ocsf.d.ts.map +1 -1
  14. package/dist/types/audit/ocsf.js +0 -1
  15. package/dist/types/audit/ocsf.js.map +1 -1
  16. package/dist/types/policyGate/errors.d.ts +0 -3
  17. package/dist/types/policyGate/errors.d.ts.map +1 -1
  18. package/dist/types/policyGate/errors.js +0 -1
  19. package/dist/types/policyGate/errors.js.map +1 -1
  20. package/dist/types/policyGate/index.d.ts +0 -1
  21. package/dist/types/policyGate/index.d.ts.map +1 -1
  22. package/dist/types/policyGate/index.js +3 -5
  23. package/dist/types/policyGate/index.js.map +1 -1
  24. package/dist/utils/attachment-upload.d.ts +9 -0
  25. package/dist/utils/attachment-upload.d.ts.map +1 -1
  26. package/dist/utils/attachment-upload.js +26 -0
  27. package/dist/utils/attachment-upload.js.map +1 -1
  28. package/dist/utils/attachment-upload.test.js +19 -0
  29. package/dist/utils/attachment-upload.test.js.map +1 -1
  30. package/dist-esm/socket/heartbeat.d.ts +10 -0
  31. package/dist-esm/socket/heartbeat.d.ts.map +1 -1
  32. package/dist-esm/socket/heartbeat.js +5 -0
  33. package/dist-esm/socket/heartbeat.js.map +1 -1
  34. package/dist-esm/socket/heartbeat.test.js +36 -0
  35. package/dist-esm/socket/heartbeat.test.js.map +1 -1
  36. package/dist-esm/socket/socket.d.ts +1 -0
  37. package/dist-esm/socket/socket.d.ts.map +1 -1
  38. package/dist-esm/socket/socket.js +8 -1
  39. package/dist-esm/socket/socket.js.map +1 -1
  40. package/dist-esm/socket/socket.test.js +33 -0
  41. package/dist-esm/socket/socket.test.js.map +1 -1
  42. package/dist-esm/types/audit/ocsf.d.ts.map +1 -1
  43. package/dist-esm/types/audit/ocsf.js +0 -1
  44. package/dist-esm/types/audit/ocsf.js.map +1 -1
  45. package/dist-esm/types/policyGate/errors.d.ts +0 -3
  46. package/dist-esm/types/policyGate/errors.d.ts.map +1 -1
  47. package/dist-esm/types/policyGate/errors.js +0 -1
  48. package/dist-esm/types/policyGate/errors.js.map +1 -1
  49. package/dist-esm/types/policyGate/index.d.ts +0 -1
  50. package/dist-esm/types/policyGate/index.d.ts.map +1 -1
  51. package/dist-esm/types/policyGate/index.js +3 -4
  52. package/dist-esm/types/policyGate/index.js.map +1 -1
  53. package/dist-esm/utils/attachment-upload.d.ts +9 -0
  54. package/dist-esm/utils/attachment-upload.d.ts.map +1 -1
  55. package/dist-esm/utils/attachment-upload.js +25 -0
  56. package/dist-esm/utils/attachment-upload.js.map +1 -1
  57. package/dist-esm/utils/attachment-upload.test.js +20 -1
  58. package/dist-esm/utils/attachment-upload.test.js.map +1 -1
  59. package/package.json +1 -1
  60. package/src/socket/heartbeat.test.ts +44 -0
  61. package/src/socket/heartbeat.ts +15 -0
  62. package/src/socket/socket.test.ts +43 -0
  63. package/src/socket/socket.ts +10 -1
  64. package/src/types/audit/ocsf.ts +0 -1
  65. package/src/types/policyGate/errors.ts +0 -1
  66. package/src/types/policyGate/index.ts +5 -5
  67. package/src/utils/attachment-upload.test.ts +22 -0
  68. 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
  }