@credal/actions 0.2.119 → 0.2.121

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.
@@ -16,15 +16,28 @@ const getOktaUserByName = (_a) => __awaiter(void 0, [_a], void 0, function* ({ a
16
16
  error: "Missing Okta OAuth token (authToken) or base URL (baseUrl) in authParams.",
17
17
  };
18
18
  }
19
+ let searchExpression;
20
+ const tokens = params.name.trim().split(/\s+/);
21
+ if (tokens.length === 1) {
22
+ // Search first OR last name starts with token
23
+ const t = tokens[0].replace(/"/g, '\\"');
24
+ searchExpression = `profile.firstName sw "${t}" or profile.lastName sw "${t}"`;
25
+ }
26
+ else {
27
+ // Use first and last tokens; ignore middles
28
+ const first = tokens[0].replace(/"/g, '\\"');
29
+ const last = tokens[tokens.length - 1].replace(/"/g, '\\"');
30
+ // choose sw (startsWith) or eq (exact) as you prefer
31
+ searchExpression = `profile.firstName sw "${first}" and profile.lastName sw "${last}"`;
32
+ }
19
33
  try {
20
34
  const requestConfig = {
21
35
  headers: {
22
36
  Authorization: `Bearer ${authToken}`,
23
37
  Accept: "application/json",
24
- "Content-Type": "application/json",
25
38
  },
26
39
  params: {
27
- q: params.name,
40
+ search: searchExpression,
28
41
  },
29
42
  };
30
43
  const endpointUrl = new URL(`/api/v1/users`, baseUrl).toString();
@@ -1 +1 @@
1
- export declare function extractTextFromPdf(buffer: ArrayBuffer): Promise<string>;
1
+ export declare function extractTextFromPdf(buffer: ArrayBuffer | Uint8Array | Buffer): Promise<string>;
package/dist/utils/pdf.js CHANGED
@@ -7,34 +7,22 @@ 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";
10
+ import pdf from "pdf-parse";
11
+ function toNodeBuffer(input) {
12
+ if (Buffer.isBuffer(input))
13
+ return input;
14
+ if (input instanceof Uint8Array)
15
+ return Buffer.from(input);
16
+ return Buffer.from(new Uint8Array(input));
17
+ }
11
18
  export function extractTextFromPdf(buffer) {
12
19
  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;
38
- }
20
+ const nodeBuf = toNodeBuffer(buffer);
21
+ const { text } = yield pdf(nodeBuf);
22
+ // pdf-parse separates pages with form feed (\f)
23
+ return text
24
+ .split("\f")
25
+ .map(page => page.trim())
26
+ .join("\n\n");
39
27
  });
40
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@credal/actions",
3
- "version": "0.2.119",
3
+ "version": "0.2.121",
4
4
  "type": "module",
5
5
  "description": "AI Actions by Credal AI",
6
6
  "sideEffects": false,
@@ -33,6 +33,7 @@
33
33
  "@types/jsonwebtoken": "^9.0.9",
34
34
  "@types/node": "^22.10.1",
35
35
  "@types/node-forge": "^1.3.11",
36
+ "@types/pdf-parse": "^1.1.5",
36
37
  "@typescript-eslint/eslint-plugin": "^8.18.0",
37
38
  "@typescript-eslint/parser": "^8.18.0",
38
39
  "eslint": "^9.16.0",
@@ -67,6 +68,7 @@
67
68
  "mongodb": "^6.13.1",
68
69
  "node-forge": "^1.3.1",
69
70
  "p-limit": "^7.1.1",
71
+ "pdf-parse": "^1.1.1",
70
72
  "pdf2json": "^3.1.6",
71
73
  "resend": "^4.7.0",
72
74
  "snowflake-sdk": "^2.0.2",