Skip to content

Commit

Permalink
Merge pull request #11 from OnedocLabs/ffo-80-update-legacy-node-sdk-…
Browse files Browse the repository at this point in the history
…with-new-api

Fixes compiler options for mime-type
  • Loading branch information
Titou325 authored May 21, 2024
2 parents 6683e52 + 8573c70 commit 0828516
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
6 changes: 4 additions & 2 deletions packages/client-js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ export interface PathBuffer {
content: Buffer;
}

type AssetOrPathBuffer = Asset | PathBuffer;

export interface ExternalLink {
href: string;
}
export interface DocumentInput {
html: string;
title?: string;
test?: boolean;
assets?: Asset[] | PathBuffer[];
assets?: AssetOrPathBuffer[];
save?: boolean;
/**
* Number of seconds to cache the file in the CDN for.
Expand Down Expand Up @@ -56,7 +58,7 @@ export class Onedoc {
}

async render(document: DocumentInput): Promise<any> {
const assets: Asset[] = document.assets ?? [];
const assets: AssetOrPathBuffer[] = document.assets ?? [];
assets.push({ path: "/index.html", content: document.html });

const test: boolean = document.test ?? true;
Expand Down
50 changes: 27 additions & 23 deletions packages/client-js/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,34 @@ import fs from "fs";
import path from "path";
import process from "process";

const ONEDOC_API_KEY = process.env.ONEDOC;
const ONEDOC_API_KEY = process.env.ONEDOC_API_KEY;
(async () => {

const onedoc = new Onedoc(ONEDOC_API_KEY);

let doc = {
html: "<h1>Hello World</h1>",
title: "Hello",
test: true, // if true, produce a PDF in test mode with a Onedoc's watermark
save: false, // if true, host the document and provide a download link in the console and your Onedoc's dashboard
expiresIn: 30, // the number of day you want to host your document
assets: [
{
path: "./stylesheet.css",
content: fs.readFileSync(path.join(process.cwd(), "/test/stylesheet.css")).toString(),
},
],
};

const { file, link, error, info } = await onedoc.render(doc);

if (error) {
throw error;
try{
const onedoc = new Onedoc(ONEDOC_API_KEY);

let doc = {
html: "<h1>Hello World</h1>",
title: "Hello",
test: true, // if true, produce a PDF in test mode with a Onedoc's watermark
save: false, // if true, host the document and provide a download link in the console and your Onedoc's dashboard
expiresIn: 30, // the number of day you want to host your document
assets: [
{
path: "./stylesheet.css",
content: fs.readFileSync(path.join(process.cwd(), "/test/stylesheet.css")).toString(),
},
],
};

const { file, link, error, info } = await onedoc.render(doc);

if (error) {
throw error;
}

fs.writeFileSync("./Test.pdf", Buffer.from(file));
}catch(e){
console.error(e);
}

fs.writeFileSync("./Test.pdf", Buffer.from(file));
})();
2 changes: 1 addition & 1 deletion packages/client-js/test/stylesheet.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
body{
background-color: red;
background-color: rgb(0, 255, 187);
}
5 changes: 5 additions & 0 deletions packages/client-js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"moduleResolution": "node",
}
}

0 comments on commit 0828516

Please sign in to comment.