@credal/actions 0.2.134 → 0.2.136

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.
@@ -102,6 +102,20 @@ const getDriveFileContentById = (_a) => __awaiter(void 0, [_a], void 0, function
102
102
  });
103
103
  content = downloadRes.data;
104
104
  }
105
+ else if (mimeType === "text/plain" ||
106
+ mimeType === "text/csv" ||
107
+ mimeType === "text/tab-separated-values" ||
108
+ mimeType === "application/rtf" ||
109
+ mimeType === "application/json") {
110
+ const downloadUrl = `${BASE_URL}${encodeURIComponent(params.fileId)}?alt=media${sharedDriveParam}`;
111
+ const downloadRes = yield axiosClient.get(downloadUrl, {
112
+ headers,
113
+ responseType: "arraybuffer",
114
+ });
115
+ const bufferResults = downloadRes.data;
116
+ const rawContentBuffer = Buffer.from(bufferResults); // Convert rawContent ArrayBuffer to Buffer
117
+ content = rawContentBuffer.toString("utf-8");
118
+ }
105
119
  else {
106
120
  return { success: false, error: `Unsupported file type: ${mimeType}` };
107
121
  }
@@ -31,9 +31,21 @@ const updateRecord = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params
31
31
  }
32
32
  catch (error) {
33
33
  console.error("Error updating Salesforce record:", error);
34
+ // Extract more detailed error information from Salesforce API response
35
+ let errorMessage = "An unknown error occurred";
36
+ if (error && typeof error === "object" && "data" in error && Array.isArray(error.data)) {
37
+ // Salesforce API returns detailed error information in the data array
38
+ const salesforceErrors = error.data
39
+ .map((err) => `${err.message || "Unknown error"} (${err.errorCode || "UNKNOWN_ERROR"})`)
40
+ .join("; ");
41
+ errorMessage = salesforceErrors;
42
+ }
43
+ else if (error instanceof Error) {
44
+ errorMessage = error.message;
45
+ }
34
46
  return {
35
47
  success: false,
36
- error: error instanceof Error ? error.message : "An unknown error occurred",
48
+ error: errorMessage,
37
49
  };
38
50
  }
39
51
  });
@@ -1 +1 @@
1
- export declare function extractTextFromPdf(buffer: ArrayBuffer): Promise<string>;
1
+ export declare function extractTextFromPdf(input: ArrayBuffer | Uint8Array): Promise<string>;
package/dist/utils/pdf.js CHANGED
@@ -7,34 +7,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import PDFParser from "pdf2json";
11
- export function extractTextFromPdf(buffer) {
10
+ import DOMMatrix from "@thednp/dommatrix";
11
+ // Set global DOMMatrix
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ global.DOMMatrix = DOMMatrix;
14
+ import { getDocument } from "pdfjs-dist/legacy/build/pdf.mjs";
15
+ export function extractTextFromPdf(input) {
12
16
  return __awaiter(this, void 0, void 0, function* () {
13
- try {
14
- const extractedText = yield new Promise((resolve, reject) => {
15
- const pdfParser = new PDFParser();
16
- pdfParser.on("pdfParser_dataError", (errData) => {
17
- reject(errData.parserError || new Error("PDF parsing failed"));
18
- });
19
- pdfParser.on("pdfParser_dataReady", (pdfData) => {
20
- try {
21
- const text = pdfData.Pages.map((page) => page.Texts.map((textItem) => {
22
- // Handle cases where R array might be empty or have multiple runs
23
- return textItem.R.map((run) => decodeURIComponent(run.T)).join("");
24
- }).join("")).join("\n");
25
- resolve(text);
26
- }
27
- catch (error) {
28
- reject(error);
29
- }
30
- });
31
- pdfParser.parseBuffer(Buffer.from(buffer));
32
- });
33
- return extractedText;
34
- }
35
- catch (error) {
36
- console.error("Error extracting PDF text:", error);
37
- throw error;
17
+ // Convert Buffer or ArrayBuffer -> plain Uint8Array
18
+ const data = input instanceof Uint8Array && !(typeof Buffer !== "undefined" && Buffer.isBuffer(input))
19
+ ? input
20
+ : typeof Buffer !== "undefined" && Buffer.isBuffer(input)
21
+ ? new Uint8Array(input) // copies bytes out of the Buffer
22
+ : new Uint8Array(input); // ArrayBuffer case
23
+ // Load PDF
24
+ const loadingTask = getDocument({ data });
25
+ const pdf = yield loadingTask.promise;
26
+ const pages = [];
27
+ for (let i = 1; i <= pdf.numPages; i++) {
28
+ const page = yield pdf.getPage(i);
29
+ const content = yield page.getTextContent();
30
+ // content.items is typed as TextItem | TextMarkedContent
31
+ const strings = content.items.map(item => ("str" in item ? item.str : "")).join(" ");
32
+ pages.push(strings.trim());
38
33
  }
34
+ yield pdf.destroy();
35
+ return pages.join("\n\n");
39
36
  });
40
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@credal/actions",
3
- "version": "0.2.134",
3
+ "version": "0.2.136",
4
4
  "type": "module",
5
5
  "description": "AI Actions by Credal AI",
6
6
  "sideEffects": false,
@@ -53,6 +53,7 @@
53
53
  "@octokit/core": "^6.1.6",
54
54
  "@octokit/plugin-rest-endpoint-methods": "^16.0.0",
55
55
  "@slack/web-api": "^7.8.0",
56
+ "@thednp/dommatrix": "^2.0.12",
56
57
  "@types/snowflake-sdk": "^1.6.24",
57
58
  "ajv": "^8.17.1",
58
59
  "axios-retry": "^4.5.0",
@@ -68,6 +69,7 @@
68
69
  "node-forge": "^1.3.1",
69
70
  "p-limit": "^7.1.1",
70
71
  "pdf2json": "^3.1.6",
72
+ "pdfjs-dist": "^5.4.149",
71
73
  "resend": "^4.7.0",
72
74
  "snowflake-sdk": "^2.0.2",
73
75
  "ts-node": "^10.9.2",