mindee 5.7.0 → 5.7.1

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 (30) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/package.json +1 -1
  3. package/src/parsing/{localResponseBase.d.ts → baseLocalResponse.d.ts} +6 -2
  4. package/src/parsing/{localResponseBase.js → baseLocalResponse.js} +32 -7
  5. package/src/pdf/pdfCompressor.js +0 -17
  6. package/src/v1/parsing/localResponse.d.ts +2 -2
  7. package/src/v1/parsing/localResponse.js +2 -2
  8. package/src/v2/client.d.ts +3 -3
  9. package/src/v2/client.js +3 -3
  10. package/src/v2/http/mindeeApiV2.d.ts +2 -2
  11. package/src/v2/http/mindeeApiV2.js +2 -2
  12. package/src/v2/parsing/inference/field/ragMetadata.d.ts +1 -1
  13. package/src/v2/parsing/inference/field/ragMetadata.js +1 -1
  14. package/src/v2/parsing/localResponse.d.ts +2 -2
  15. package/src/v2/parsing/localResponse.js +2 -2
  16. package/src/v2/parsing/search/baseSearchResponse.d.ts +2 -1
  17. package/src/v2/parsing/search/modelWebhook.d.ts +1 -1
  18. package/src/v2/parsing/search/modelWebhook.js +1 -1
  19. package/src/v2/parsing/search/paginationMetadata.d.ts +1 -1
  20. package/src/v2/parsing/search/paginationMetadata.js +1 -1
  21. package/src/v2/parsing/search/searchModel.d.ts +2 -2
  22. package/src/v2/parsing/search/searchModel.js +1 -1
  23. package/src/v2/parsing/search/searchModels.d.ts +3 -0
  24. package/src/v2/parsing/search/searchModels.js +3 -0
  25. package/src/v2/search/models/modelSearch.d.ts +6 -1
  26. package/src/v2/search/models/modelSearch.js +6 -1
  27. package/src/v2/search/models/modelSearchParameters.d.ts +2 -2
  28. package/src/v2/search/models/modelSearchResponse.d.ts +1 -1
  29. package/src/v2/search/ragDocuments/ragDocumentSearchResponse.d.ts +1 -1
  30. package/src/v2/search/ragDocuments/ragDocumentSearchResponse.js +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Mindee Node.js API Library Changelog
2
2
 
3
+ ## v5.7.1 - 2026-09-10
4
+ ### Fixes
5
+ * :bug: constant-time HMAC security fix
6
+
7
+
3
8
  ## v5.7.0 - 2026-08-20
4
9
  ### Changes
5
10
  * :sparkles: add support for RAG search API
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mindee",
3
- "version": "5.7.0",
3
+ "version": "5.7.1",
4
4
  "description": "Mindee Client Library for Node.js",
5
5
  "author": {
6
6
  "name": "Mindee",
@@ -4,8 +4,8 @@ import { Buffer } from "buffer";
4
4
  * Local response loaded from a file.
5
5
  * Note: Has to be initialized through init() before use.
6
6
  */
7
- export declare abstract class LocalResponseBase {
8
- private file;
7
+ export declare abstract class BaseLocalResponse {
8
+ private fileBytes;
9
9
  private readonly inputHandle;
10
10
  /** Whether the local response payload has been loaded. */
11
11
  protected initialized: boolean;
@@ -33,4 +33,8 @@ export declare abstract class LocalResponseBase {
33
33
  * @returns True if the HMAC signature is valid.
34
34
  */
35
35
  isValidHmacSignature(secretKey: string | Buffer | Uint8Array, signature: string): boolean;
36
+ /**
37
+ * Print the file as a UTF-8 string.
38
+ */
39
+ toString(): string;
36
40
  }
@@ -6,14 +6,20 @@ import { Buffer } from "buffer";
6
6
  * Local response loaded from a file.
7
7
  * Note: Has to be initialized through init() before use.
8
8
  */
9
- export class LocalResponseBase {
9
+ export class BaseLocalResponse {
10
10
  /**
11
11
  * Creates an instance of LocalResponse.
12
12
  */
13
13
  constructor(inputFile) {
14
14
  /** Whether the local response payload has been loaded. */
15
15
  this.initialized = false;
16
- this.file = Buffer.alloc(0);
16
+ if (inputFile === undefined || inputFile === null) {
17
+ throw new TypeError("input cannot be null or undefined");
18
+ }
19
+ if (typeof inputFile === "string" ? !inputFile.trim() : !inputFile.length) {
20
+ throw new TypeError("input cannot be empty");
21
+ }
22
+ this.fileBytes = Buffer.alloc(0);
17
23
  this.inputHandle = inputFile;
18
24
  }
19
25
  /** Loads the local payload from a string, buffer, or file path. */
@@ -25,7 +31,7 @@ export class LocalResponseBase {
25
31
  return;
26
32
  }
27
33
  if (Buffer.isBuffer(this.inputHandle)) {
28
- this.file = this.inputHandle;
34
+ this.fileBytes = this.inputHandle;
29
35
  }
30
36
  else if (typeof this.inputHandle === "string") {
31
37
  let fileContents;
@@ -36,7 +42,7 @@ export class LocalResponseBase {
36
42
  catch {
37
43
  fileContents = this.inputHandle;
38
44
  }
39
- this.file = Buffer.from(fileContents.replace(/\r/g, "").replace(/\n/g, ""), "utf-8");
45
+ this.fileBytes = Buffer.from(fileContents.replace(/\r/g, "").replace(/\n/g, ""), "utf-8");
40
46
  }
41
47
  else {
42
48
  throw new MindeeError("Incompatible type for input.");
@@ -52,7 +58,7 @@ export class LocalResponseBase {
52
58
  await this.init();
53
59
  }
54
60
  try {
55
- const content = this.file.toString("utf-8");
61
+ const content = this.fileBytes.toString("utf-8");
56
62
  return JSON.parse(content);
57
63
  }
58
64
  catch {
@@ -71,7 +77,7 @@ export class LocalResponseBase {
71
77
  const algorithm = "sha256";
72
78
  try {
73
79
  const hmac = crypto.createHmac(algorithm, secretKey);
74
- hmac.update(this.file);
80
+ hmac.update(this.fileBytes);
75
81
  return hmac.digest("hex");
76
82
  }
77
83
  catch {
@@ -88,6 +94,25 @@ export class LocalResponseBase {
88
94
  if (!this.initialized) {
89
95
  throw new Error("The `init()` method must be called before calling `isValidHmacSignature()`.");
90
96
  }
91
- return signature === this.getHmacSignature(secretKey);
97
+ if ((!signature || !signature?.trim())
98
+ || (!secretKey || (typeof secretKey === "string" ? !secretKey?.trim() : !secretKey?.length))) {
99
+ return false;
100
+ }
101
+ const expectedSignature = this.getHmacSignature(secretKey);
102
+ if (!expectedSignature?.trim()) {
103
+ return false;
104
+ }
105
+ const expectedBytes = Buffer.from(expectedSignature, "utf-8");
106
+ const actualBytes = Buffer.from(signature.toLowerCase(), "utf-8");
107
+ if (expectedBytes.length !== actualBytes.length) {
108
+ return false;
109
+ }
110
+ return crypto.timingSafeEqual(expectedBytes, actualBytes);
111
+ }
112
+ /**
113
+ * Print the file as a UTF-8 string.
114
+ */
115
+ toString() {
116
+ return this.fileBytes.toString("utf-8");
92
117
  }
93
118
  }
@@ -22,7 +22,6 @@ async function getPdfLib() {
22
22
  * @returns A Promise resolving to the compressed PDF as a Buffer.
23
23
  */
24
24
  export async function compressPdf(pdfData, imageQuality = 85, forceSourceTextCompression = false, disableSourceText = true) {
25
- handleCompressionWarnings(forceSourceTextCompression, disableSourceText);
26
25
  if (await hasSourceText(pdfData)) {
27
26
  if (forceSourceTextCompression) {
28
27
  if (!disableSourceText) {
@@ -48,22 +47,6 @@ export async function compressPdf(pdfData, imageQuality = 85, forceSourceTextCom
48
47
  }
49
48
  return createNewPdfFromCompressedPages(compressedPages);
50
49
  }
51
- /**
52
- * Handles compression warnings based on the provided parameters.
53
- * @param forceSourceTextCompression If true, attempts to re-write detected text.
54
- * @param disableSourceText If true, doesn't re-apply source text to the output PDF.
55
- */
56
- function handleCompressionWarnings(forceSourceTextCompression, disableSourceText) {
57
- if (forceSourceTextCompression) {
58
- if (!disableSourceText) {
59
- logger.warn("Re-writing PDF source-text is an EXPERIMENTAL feature.");
60
- }
61
- else {
62
- logger.warn("Source file contains text, but the disable_source_text is set to false. "
63
- + "Resulting file will not contain any embedded text.");
64
- }
65
- }
66
- }
67
50
  /**
68
51
  * Compresses PDF pages and returns an array of compressed page buffers.
69
52
  * @param pdfData The input PDF as a Buffer.
@@ -1,11 +1,11 @@
1
- import { LocalResponseBase } from "../../parsing/localResponseBase.js";
1
+ import { BaseLocalResponse } from "../../parsing/baseLocalResponse.js";
2
2
  import { AsyncPredictResponse, Inference, PredictResponse } from "../../v1/index.js";
3
3
  import { StringDict } from "../../parsing/index.js";
4
4
  /**
5
5
  * Local response loaded from a file.
6
6
  * Note: Has to be initialized through init() before use.
7
7
  */
8
- export declare class LocalResponse extends LocalResponseBase {
8
+ export declare class LocalResponse extends BaseLocalResponse {
9
9
  /** Loads a local JSON payload into a typed prediction response wrapper. */
10
10
  loadPrediction<T extends Inference>(productClass: new (httpResponse: StringDict) => T): Promise<AsyncPredictResponse<T> | PredictResponse<T>>;
11
11
  }
@@ -1,11 +1,11 @@
1
- import { LocalResponseBase } from "../../parsing/localResponseBase.js";
1
+ import { BaseLocalResponse } from "../../parsing/baseLocalResponse.js";
2
2
  import { AsyncPredictResponse, PredictResponse } from "../../v1/index.js";
3
3
  import { MindeeError } from "../../errors/index.js";
4
4
  /**
5
5
  * Local response loaded from a file.
6
6
  * Note: Has to be initialized through init() before use.
7
7
  */
8
- export class LocalResponse extends LocalResponseBase {
8
+ export class LocalResponse extends BaseLocalResponse {
9
9
  /** Loads a local JSON payload into a typed prediction response wrapper. */
10
10
  async loadPrediction(productClass) {
11
11
  /**
@@ -42,10 +42,10 @@ export declare class Client {
42
42
  */
43
43
  searchModels(name?: string, modelType?: string): Promise<SearchResponse>;
44
44
  /**
45
- * Searches for resources matching the given criteria.
46
- * @param search
45
+ * Search for resources matching the given criteria.
46
+ * @param search Search definition class to use.
47
47
  * @param searchParameters Search parameters.
48
- * @returns a `Promise` containing the search response.
48
+ * @returns a `Promise` containing the search response with the matching resources.
49
49
  */
50
50
  search<S extends typeof BaseSearch>(search: S, searchParameters: InstanceType<S["parametersClass"]> | ConstructorParameters<S["parametersClass"]>[0]): Promise<InstanceType<S["responseClass"]>>;
51
51
  /** Enqueues a product inference job without waiting for completion. */
package/src/v2/client.js CHANGED
@@ -37,10 +37,10 @@ export class Client {
37
37
  return await this.search(ModelSearch, { name: name, modelType: modelType });
38
38
  }
39
39
  /**
40
- * Searches for resources matching the given criteria.
41
- * @param search
40
+ * Search for resources matching the given criteria.
41
+ * @param search Search definition class to use.
42
42
  * @param searchParameters Search parameters.
43
- * @returns a `Promise` containing the search response.
43
+ * @returns a `Promise` containing the search response with the matching resources.
44
44
  */
45
45
  async search(search, searchParameters) {
46
46
  if (!searchParameters) {
@@ -51,8 +51,8 @@ export declare class MindeeApiV2 {
51
51
  */
52
52
  reqGetProductResultByUrl<P extends typeof BaseProduct>(product: P, url: string): Promise<InstanceType<P["responseClass"]>>;
53
53
  /**
54
- * Searches for resources matching the given criteria.
55
- * @param search
54
+ * Retrieves a list of resources with the given criteria.
55
+ * @param search Search definition class to use.
56
56
  * @param parameters Search parameters.
57
57
  * @returns a `Promise` containing the search response.
58
58
  */
@@ -106,8 +106,8 @@ export class MindeeApiV2 {
106
106
  return __classPrivateFieldGet(this, _MindeeApiV2_instances, "m", _MindeeApiV2_processResponse).call(this, response, product.responseClass);
107
107
  }
108
108
  /**
109
- * Searches for resources matching the given criteria.
110
- * @param search
109
+ * Retrieves a list of resources with the given criteria.
110
+ * @param search Search definition class to use.
111
111
  * @param parameters Search parameters.
112
112
  * @returns a `Promise` containing the search response.
113
113
  */
@@ -1,5 +1,5 @@
1
1
  import { StringDict } from "../../../../parsing/stringDict.js";
2
- /** Metadata produced by RAG-enabled extraction. */
2
+ /** Metadata about the RAG operation. */
3
3
  export declare class RagMetadata {
4
4
  /**
5
5
  * The UUID of the matched document used during the RAG operation.
@@ -1,4 +1,4 @@
1
- /** Metadata produced by RAG-enabled extraction. */
1
+ /** Metadata about the RAG operation. */
2
2
  export class RagMetadata {
3
3
  constructor(serverResponse) {
4
4
  this.retrievedDocumentId = serverResponse["retrieved_document_id"] ?? undefined;
@@ -1,11 +1,11 @@
1
1
  import { StringDict } from "../../parsing/stringDict.js";
2
- import { LocalResponseBase } from "../../parsing/localResponseBase.js";
2
+ import { BaseLocalResponse } from "../../parsing/baseLocalResponse.js";
3
3
  import { BaseResponse } from "./baseResponse.js";
4
4
  /**
5
5
  * Local response loaded from a file.
6
6
  * Note: Has to be initialized through init() before use.
7
7
  */
8
- export declare class LocalResponse extends LocalResponseBase {
8
+ export declare class LocalResponse extends BaseLocalResponse {
9
9
  /**
10
10
  * Deserialize the loaded local response into a product response class.
11
11
  *
@@ -1,10 +1,10 @@
1
1
  import { MindeeError } from "../../errors/index.js";
2
- import { LocalResponseBase } from "../../parsing/localResponseBase.js";
2
+ import { BaseLocalResponse } from "../../parsing/baseLocalResponse.js";
3
3
  /**
4
4
  * Local response loaded from a file.
5
5
  * Note: Has to be initialized through init() before use.
6
6
  */
7
- export class LocalResponse extends LocalResponseBase {
7
+ export class LocalResponse extends BaseLocalResponse {
8
8
  /**
9
9
  * Deserialize the loaded local response into a product response class.
10
10
  *
@@ -11,7 +11,8 @@ export declare abstract class BaseSearchResponse extends BaseResponse {
11
11
  pagination: PaginationMetadata;
12
12
  protected constructor(serverResponse: StringDict);
13
13
  /**
14
- * List of strings representing the search response.
14
+ * Lines composing the response-specific body (header + items).
15
+ * @returns An array of body lines.
15
16
  */
16
17
  protected abstract bodyLines(): string[];
17
18
  toString(): string;
@@ -1,6 +1,6 @@
1
1
  import { StringDict } from "../../../parsing/index.js";
2
2
  /**
3
- * Model webhook info.
3
+ * Information about a model's webhook.
4
4
  */
5
5
  export declare class ModelWebhook {
6
6
  /**
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Model webhook info.
2
+ * Information about a model's webhook.
3
3
  */
4
4
  export class ModelWebhook {
5
5
  constructor(serverResponse) {
@@ -1,6 +1,6 @@
1
1
  import { StringDict } from "../../../parsing/index.js";
2
2
  /**
3
- * PaginationMetadata data associated with model search.
3
+ * Pagination metadata associated with searches.
4
4
  */
5
5
  export declare class PaginationMetadata {
6
6
  /**
@@ -1,5 +1,5 @@
1
1
  /**
2
- * PaginationMetadata data associated with model search.
2
+ * Pagination metadata associated with searches.
3
3
  */
4
4
  export class PaginationMetadata {
5
5
  constructor(serverResponse) {
@@ -1,7 +1,7 @@
1
1
  import { StringDict } from "../../../parsing/index.js";
2
2
  import { ModelWebhook } from "./modelWebhook.js";
3
3
  /**
4
- * Models search response.
4
+ * Individual model information.
5
5
  */
6
6
  export declare class SearchModel {
7
7
  /**
@@ -17,7 +17,7 @@ export declare class SearchModel {
17
17
  */
18
18
  modelType: string;
19
19
  /**
20
- * Webhooks associated with the model.
20
+ * List of webhooks associated with the model.
21
21
  */
22
22
  webhooks: ModelWebhook[];
23
23
  constructor(serverResponse: StringDict);
@@ -1,6 +1,6 @@
1
1
  import { ModelWebhook } from "./modelWebhook.js";
2
2
  /**
3
- * Models search response.
3
+ * Individual model information.
4
4
  */
5
5
  export class SearchModel {
6
6
  constructor(serverResponse) {
@@ -1,5 +1,8 @@
1
1
  import { SearchModel } from "../../../v2/parsing/search/searchModel.js";
2
2
  import { StringDict } from "../../../parsing/index.js";
3
+ /**
4
+ * List of search models.
5
+ */
3
6
  export declare class SearchModels extends Array<SearchModel> {
4
7
  constructor(serverResponse?: StringDict[]);
5
8
  toString(): string;
@@ -1,4 +1,7 @@
1
1
  import { SearchModel } from "../../../v2/parsing/search/searchModel.js";
2
+ /**
3
+ * List of search models.
4
+ */
2
5
  export class SearchModels extends Array {
3
6
  constructor(serverResponse = []) {
4
7
  super();
@@ -2,7 +2,12 @@ import { ModelSearchParameters } from "../../../v2/search/index.js";
2
2
  import { BaseSearch } from "../../../v2/search/baseSearch.js";
3
3
  import { ModelSearchResponse } from "../../../v2/search/models/modelSearchResponse.js";
4
4
  /**
5
- * Search for models.
5
+ * Search for models within the organization linked to the API key.
6
+ *
7
+ * All search filters are optional.
8
+ * If no search filters are given, all models belonging to the organization are returned.
9
+ *
10
+ * Results are paginated.
6
11
  */
7
12
  export declare class ModelSearch extends BaseSearch {
8
13
  /** @inheritDoc */
@@ -2,7 +2,12 @@ import { ModelSearchParameters } from "../../../v2/search/index.js";
2
2
  import { BaseSearch } from "../../../v2/search/baseSearch.js";
3
3
  import { ModelSearchResponse } from "../../../v2/search/models/modelSearchResponse.js";
4
4
  /**
5
- * Search for models.
5
+ * Search for models within the organization linked to the API key.
6
+ *
7
+ * All search filters are optional.
8
+ * If no search filters are given, all models belonging to the organization are returned.
9
+ *
10
+ * Results are paginated.
6
11
  */
7
12
  export class ModelSearch extends BaseSearch {
8
13
  /** @inheritDoc */
@@ -11,11 +11,11 @@ export interface ModelSearchParametersConstructor extends BaseSearchParametersCo
11
11
  */
12
12
  export declare class ModelSearchParameters extends BaseSearchParameters {
13
13
  /**
14
- * Case-insensitive search term for the model name
14
+ * Filter models by partial name match, case-insensitive.
15
15
  */
16
16
  name?: string;
17
17
  /**
18
- * Case-insensitive search term for the model type
18
+ * Filter by an exact model type.
19
19
  */
20
20
  modelType?: string;
21
21
  constructor(params?: ModelSearchParametersConstructor);
@@ -6,7 +6,7 @@ import { SearchModels } from "../../../v2/parsing/search/searchModels.js";
6
6
  */
7
7
  export declare class ModelSearchResponse extends BaseSearchResponse {
8
8
  /**
9
- * List of models returned by the search.
9
+ * Paginated list of matching models.
10
10
  */
11
11
  models: SearchModels;
12
12
  constructor(serverResponse: StringDict);
@@ -2,7 +2,7 @@ import { StringDict } from "../../../parsing/index.js";
2
2
  import { BaseSearchResponse } from "../../../v2/parsing/search/index.js";
3
3
  import { SearchRagDocuments } from "../../../v2/parsing/search/searchRagDocuments.js";
4
4
  /**
5
- * RAG documents search response.
5
+ * RAG Documents search response.
6
6
  */
7
7
  export declare class RagDocumentSearchResponse extends BaseSearchResponse {
8
8
  /**
@@ -1,7 +1,7 @@
1
1
  import { BaseSearchResponse } from "../../../v2/parsing/search/index.js";
2
2
  import { SearchRagDocuments } from "../../../v2/parsing/search/searchRagDocuments.js";
3
3
  /**
4
- * RAG documents search response.
4
+ * RAG Documents search response.
5
5
  */
6
6
  export class RagDocumentSearchResponse extends BaseSearchResponse {
7
7
  constructor(serverResponse) {