@juspay/neurolink 10.10.12 → 10.11.0

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 (49) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/adapters/imageFormatSupport.d.ts +75 -0
  3. package/dist/adapters/imageFormatSupport.js +283 -0
  4. package/dist/adapters/video/ffmpegAdapter.d.ts +6 -0
  5. package/dist/adapters/video/ffmpegAdapter.js +1 -1
  6. package/dist/browser/neurolink.min.js +399 -398
  7. package/dist/lib/adapters/imageFormatSupport.d.ts +75 -0
  8. package/dist/lib/adapters/imageFormatSupport.js +284 -0
  9. package/dist/lib/adapters/video/ffmpegAdapter.d.ts +6 -0
  10. package/dist/lib/adapters/video/ffmpegAdapter.js +1 -1
  11. package/dist/lib/processors/config/fileExtensions.d.ts +32 -15
  12. package/dist/lib/processors/config/fileExtensions.js +27 -66
  13. package/dist/lib/processors/config/fileTypeRegistry.d.ts +106 -0
  14. package/dist/lib/processors/config/fileTypeRegistry.js +702 -0
  15. package/dist/lib/processors/config/index.d.ts +2 -1
  16. package/dist/lib/processors/config/index.js +5 -1
  17. package/dist/lib/processors/config/mimeConstants.d.ts +22 -7
  18. package/dist/lib/processors/config/mimeConstants.js +45 -66
  19. package/dist/lib/processors/media/AudioProcessor.js +16 -38
  20. package/dist/lib/processors/media/VideoProcessor.js +11 -32
  21. package/dist/lib/providers/googleAiStudio/client.js +12 -1
  22. package/dist/lib/providers/googleVertex/client.js +123 -66
  23. package/dist/lib/types/file.d.ts +41 -0
  24. package/dist/lib/utils/fileDetector.js +367 -251
  25. package/dist/lib/utils/imageProcessor.js +14 -17
  26. package/dist/lib/utils/markupSniff.d.ts +37 -0
  27. package/dist/lib/utils/markupSniff.js +125 -0
  28. package/dist/lib/utils/messageBuilder.d.ts +14 -0
  29. package/dist/lib/utils/messageBuilder.js +172 -92
  30. package/dist/processors/config/fileExtensions.d.ts +32 -15
  31. package/dist/processors/config/fileExtensions.js +27 -66
  32. package/dist/processors/config/fileTypeRegistry.d.ts +106 -0
  33. package/dist/processors/config/fileTypeRegistry.js +701 -0
  34. package/dist/processors/config/index.d.ts +2 -1
  35. package/dist/processors/config/index.js +5 -1
  36. package/dist/processors/config/mimeConstants.d.ts +22 -7
  37. package/dist/processors/config/mimeConstants.js +45 -66
  38. package/dist/processors/media/AudioProcessor.js +16 -38
  39. package/dist/processors/media/VideoProcessor.js +11 -32
  40. package/dist/providers/googleAiStudio/client.js +12 -1
  41. package/dist/providers/googleVertex/client.js +123 -66
  42. package/dist/types/file.d.ts +41 -0
  43. package/dist/utils/fileDetector.js +367 -251
  44. package/dist/utils/imageProcessor.js +14 -17
  45. package/dist/utils/markupSniff.d.ts +37 -0
  46. package/dist/utils/markupSniff.js +124 -0
  47. package/dist/utils/messageBuilder.d.ts +14 -0
  48. package/dist/utils/messageBuilder.js +172 -92
  49. package/package.json +3 -2
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Canonical file-format registry — the single source of truth for
3
+ * extension ↔ MIME ↔ FileType ↔ modality.
4
+ *
5
+ * ## Why this exists
6
+ *
7
+ * The same knowledge used to live in five hand-maintained tables that had no
8
+ * way of agreeing with each other:
9
+ *
10
+ * 1. `EXTENSION_MIME_MAP` (config/mimeConstants.ts)
11
+ * 2. the `*_EXTENSIONS` category arrays (config/fileExtensions.ts)
12
+ * 3. `ExtensionStrategy.typeMap` + `.mimeMap` (utils/fileDetector.ts)
13
+ * 4. `EXTENSION_TYPE_MAP` (utils/messageBuilder.ts)
14
+ * 5. each processor's `supportedExtensions` / `supportedMimeTypes`
15
+ *
16
+ * They drifted, and the drift was not cosmetic — a format that a processor
17
+ * declared it supported was routinely invisible to the detector standing in
18
+ * front of it, so the file never reached the processor at all. Measured on real
19
+ * ffmpeg-generated media before this registry existed:
20
+ *
21
+ * .aiff .m2ts .mts .vob .3g2 .3gp → "unknown" (downgraded to metadata text)
22
+ * .mpg .mpeg → "csv" (binary parsed as a spreadsheet)
23
+ * .ts → "text" (MPEG-TS inlined as source code)
24
+ *
25
+ * Deriving all five consumers from one table makes that class of drift
26
+ * structurally impossible rather than merely fixed once.
27
+ *
28
+ * ## Invariants
29
+ *
30
+ * - `extensions[0]` is canonical for the format; the rest are accepted aliases.
31
+ * - `mimeTypes[0]` is canonical; the rest are aliases seen in the wild
32
+ * (`audio/x-wav`, `image/x-icon`, vendor prefixes, …).
33
+ * - Every extension and every MIME type appears in exactly one entry. The
34
+ * `assertRegistryIsUnambiguous()` check below is executed at module load, so
35
+ * a duplicate is a startup failure rather than a silent last-write-wins.
36
+ * - `fileType` is the *routing* type the detector emits (what processor to
37
+ * use); `modality` is the *category* a human means. They deliberately differ:
38
+ * an .odt is `fileType: "docx"` (the Word processor handles it) but
39
+ * `modality: "document"`, and .svg is `fileType: "svg"` (sanitised as markup,
40
+ * never sent to a vision API) but `modality: "image"`.
41
+ *
42
+ * @module processors/config/fileTypeRegistry
43
+ */
44
+ import type { FileFormatEntry, FileModality, FileType } from "../../types/index.js";
45
+ /**
46
+ * Every file format NeuroLink can identify, grouped by modality.
47
+ *
48
+ * Adding a format here is all that is required — the extension map, the MIME
49
+ * map, the detector's lookup tables, the category arrays and the media
50
+ * processors' supported-format lists are all derived from this array.
51
+ */
52
+ export declare const FILE_TYPE_REGISTRY: readonly FileFormatEntry[];
53
+ /**
54
+ * Extensions that must NOT be treated as belonging to their registry entry's
55
+ * modality when only a filename is available.
56
+ *
57
+ * Derived from {@link EXTENSION_OVERRIDES}: `extensionsForModality("video")`
58
+ * feeds both `VIDEO_EXTENSIONS` and `VideoProcessor`'s supported list, and
59
+ * `BaseFileProcessor.isFileSupported` accepts a file when the *extension*
60
+ * matches even if the supplied mimetype says otherwise. Leaving `.ts` in that
61
+ * list made `isVideoFile("text/plain", "app.ts")` return true.
62
+ */
63
+ /**
64
+ * Extension → MIME for the overridden extensions only.
65
+ *
66
+ * Exported so `EXTENSION_MIME_MAP` can apply the override as its FINAL layer.
67
+ * That map is built by spreading the registry over the text map, so without
68
+ * this the registry's `.ts → video/mp2t` won again and `getMimeTypeForExtension`
69
+ * disagreed with `mimeTypeForExtension` about the very same file.
70
+ */
71
+ export declare const EXTENSION_MIME_OVERRIDES: Readonly<Record<string, string>>;
72
+ /**
73
+ * Normalize an extension to the registry's key form: lowercased, with a leading
74
+ * dot. Accepts `"png"`, `".PNG"`, `"image.png"` and `"/tmp/a.png"` alike.
75
+ *
76
+ * Compound extensions (`.tar.gz`) are matched before the single-segment form so
77
+ * a `.tar.gz` resolves to the gzip entry rather than to `.gz` by accident —
78
+ * they happen to agree today, but the lookup should not depend on that.
79
+ */
80
+ export declare function normalizeExtension(raw: string): string;
81
+ /** Look up the registry entry for a file extension, or undefined. */
82
+ export declare function lookupByExtension(ext: string): FileFormatEntry | undefined;
83
+ /**
84
+ * Look up the registry entry for a MIME type, or undefined. Any `;charset=…`
85
+ * parameter is stripped, matching how Content-Type headers arrive.
86
+ */
87
+ export declare function lookupByMimeType(mime: string): FileFormatEntry | undefined;
88
+ /**
89
+ * Routing {@link FileType} for an extension, honouring {@link EXTENSION_OVERRIDES}.
90
+ * Returns undefined when the extension is not in the registry.
91
+ */
92
+ export declare function fileTypeForExtension(ext: string): FileType | undefined;
93
+ /** Canonical MIME type for an extension, or undefined when unknown. */
94
+ export declare function mimeTypeForExtension(ext: string): string | undefined;
95
+ /** Canonical extension (with leading dot) for a MIME type, or undefined. */
96
+ export declare function extensionForMimeType(mime: string): string | undefined;
97
+ /** Every extension registered for a modality, in registry order. */
98
+ export declare function extensionsForModality(modality: FileModality): readonly string[];
99
+ /** Every MIME type registered for a modality, in registry order. */
100
+ export declare function mimeTypesForModality(modality: FileModality): readonly string[];
101
+ /**
102
+ * True when the extension belongs to the given modality. Uses the entry's
103
+ * modality, not its routing `fileType`, so `.svg` counts as an image and `.odt`
104
+ * counts as a document.
105
+ */
106
+ export declare function isModalityExtension(ext: string, modality: FileModality): boolean;