Skip to content

Commit

Permalink
Updates SDK for AllowViewing option
Browse files Browse the repository at this point in the history
  • Loading branch information
Titou325 committed Sep 6, 2024
2 parents fd4ceca + d450975 commit e7b6e93
Show file tree
Hide file tree
Showing 16 changed files with 159 additions and 26 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Test key to connect to the customer API
FILEFORGE_API_KEY=1466ffcd-95d0-4c84-9ebd-cb0997d4c31c
FILEFORGE_API_KEY=
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules
.env
dist
.DS_Store
.pdf
.zip
19 changes: 18 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"update": "rm fern/openapi/openapi.yml && curl https://api.fileforge.com/documentation/yaml > fern/openapi/openapi.yml && ts-node scripts/openapi-process.ts",
"generate": "fern generate && cp -r packages/typescript/src/client/_patches/* packages/typescript/src/client/codegen && ts-node scripts/ts-process.ts",
"regenerate": "npm run update && npm run generate",
"test": "npx vitest",
"test": "npm run build --workspace=@fileforge/client && npx vitest",
"test:browser": "npx vitest --config browser.vitest.config.ts"
},
"workspaces": [
Expand All @@ -20,6 +20,7 @@
"@types/eslint": "^8.56.6",
"@types/eslint__js": "^8.42.3",
"@types/eslint-config-prettier": "^6.11.3",
"@types/glob": "^8.1.0",
"@types/mime": "^3.0.4",
"@types/randomstring": "^1.1.12",
"@vitest/browser": "^1.6.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fileforge/client",
"version": "0.1.15",
"version": "0.1.17",
"scripts": {
"build": "tsc --module es2022 --outDir dist/esm && tsc --module Node16 --moduleResolution Node16 --outDir dist/cjs"
},
Expand Down
156 changes: 134 additions & 22 deletions packages/typescript/src/test/snippets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as fs from "node:fs";
import internal, { Readable } from "node:stream";
import { fileFromPath } from "formdata-node/file-from-path";
import { BadRequestError, UnauthorizedError } from "@/client/codegen/api";
import { pipeline } from "node:stream/promises";

const NODE_VERSION = parseInt(process.versions.node.split(".")[0]);

Expand Down Expand Up @@ -111,30 +112,33 @@ describe("node", () => {
}
});

it.skipIf(NODE_VERSION < 20)("detect form fields in PDFs should work", async () => {
const ff = new FileforgeClient({
apiKey: process.env.FILEFORGE_API_KEY,
});
it.skipIf(NODE_VERSION < 20)(
"detect form fields in PDFs should work",
async () => {
const ff = new FileforgeClient({
apiKey: process.env.FILEFORGE_API_KEY,
});

try {
const resultObject = await ff.pdf.form.detect(
new File(
[fs.readFileSync(__dirname + "/samples/form.pdf")],
"form.pdf",
{
type: "application/pdf",
},
),
{ options: {} },
);
try {
const resultObject = await ff.pdf.form.detect(
new File(
[fs.readFileSync(__dirname + "/samples/form.pdf")],
"form.pdf",
{
type: "application/pdf",
},
),
{ options: {} },
);

console.log(resultObject);
expect(resultObject).toBeInstanceOf(Array<FormDetectResponseItem>);
} catch (error) {
console.error("Error during PDF form detect:", error);
throw error;
}
});
console.log(resultObject);
expect(resultObject).toBeInstanceOf(Array<FormDetectResponseItem>);
} catch (error) {
console.error("Error during PDF form detect:", error);
throw error;
}
},
);

it.skipIf(NODE_VERSION < 20)("mark fields in PDFs should work", async () => {
const ff = new FileforgeClient({
Expand Down Expand Up @@ -201,4 +205,112 @@ describe("node", () => {
console.error("Error during PDF form filling:", error);
}
});

it.skipIf(NODE_VERSION < 20)("Split", async () => {
const ff = new FileforgeClient({
apiKey: process.env.FILEFORGE_API_KEY,
});

try {
const splitRequest = {
options: {
splitPage: 1,
},
};
const requestOptions = {
timeoutInSeconds: 60,
maxRetries: 3,
};
const splitArchiveStream = await ff.pdf.split(
new File(
[fs.readFileSync(__dirname + "/samples/form.pdf")],
"form.pdf",
{
type: "application/pdf",
},
),
splitRequest,
requestOptions,
);

await pipeline(
splitArchiveStream,
fs.createWriteStream("./result_split.zip"),
);
expect(splitArchiveStream).toBeInstanceOf(Readable);
console.log("Split successful. Zip Stream ready.");
} catch (error) {
console.error("Error during PDF splitting:", error);
}
});

it.skipIf(NODE_VERSION < 20)("Extract", async () => {
const ff = new FileforgeClient({
apiKey: process.env.FILEFORGE_API_KEY,
});

try {
const extractRequest = {
options: {
start: 1,
end: 1,
},
};
const requestOptions = {
timeoutInSeconds: 60,
maxRetries: 3,
};
const extractStream = await ff.pdf.extract(
new File(
[fs.readFileSync(__dirname + "/samples/form.pdf")],
"form.pdf",
{
type: "application/pdf",
},
),
extractRequest,
requestOptions,
);

await pipeline(
extractStream,
fs.createWriteStream("./result_extract.pdf"),
);
expect(extractStream).toBeInstanceOf(Readable);
console.log("Extraction successful.Stream ready.");
} catch (error) {
console.error("Error during PDF extraction:", error);
}
});

it.skipIf(NODE_VERSION < 20)("Insert PDFs should work", async () => {
const ff = new FileforgeClient({
apiKey: process.env.FILEFORGE_API_KEY,
});

try {
const pdfFiles = [
fs.createReadStream(__dirname + "/pdf1.pdf"),
fs.createReadStream(__dirname + "/pdf2.pdf"),
];
const insertPDFStream = await ff.pdf.insert(
pdfFiles,
{
options: {
// Specify insert options if any
insertPage: 1,
},
},
{
timeoutInSeconds: 60,
},
);
insertPDFStream.pipe(fs.createWriteStream("./result_insert.pdf"));
console.log("PDF inserted successfully. Stream ready.");
expect(insertPDFStream).toBeInstanceOf(Readable);
} catch (error) {
console.error("Error during PDF insertion:", error);
throw error;
}
});
});
Binary file modified result_docx.pdf
Binary file not shown.
Binary file added result_extract.pdf
Binary file not shown.
Binary file modified result_filled.pdf
Binary file not shown.
Binary file added result_insert.pdf
Binary file not shown.
Binary file modified result_mark.pdf
Binary file not shown.
Binary file modified result_merge.pdf
Binary file not shown.
Binary file added result_split.zip
Binary file not shown.
Binary file added result_split/form_1_1.pdf
Binary file not shown.
Binary file added result_split/form_2_2.pdf
Binary file not shown.

0 comments on commit e7b6e93

Please sign in to comment.