Skip to content

Commit 0828516

Browse files
authored
Merge pull request #11 from OnedocLabs/ffo-80-update-legacy-node-sdk-with-new-api
Fixes compiler options for mime-type
2 parents 6683e52 + 8573c70 commit 0828516

File tree

4 files changed

+37
-26
lines changed

4 files changed

+37
-26
lines changed

packages/client-js/src/client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ export interface PathBuffer {
1010
content: Buffer;
1111
}
1212

13+
type AssetOrPathBuffer = Asset | PathBuffer;
14+
1315
export interface ExternalLink {
1416
href: string;
1517
}
1618
export interface DocumentInput {
1719
html: string;
1820
title?: string;
1921
test?: boolean;
20-
assets?: Asset[] | PathBuffer[];
22+
assets?: AssetOrPathBuffer[];
2123
save?: boolean;
2224
/**
2325
* Number of seconds to cache the file in the CDN for.
@@ -56,7 +58,7 @@ export class Onedoc {
5658
}
5759

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

6264
const test: boolean = document.test ?? true;

packages/client-js/test/client.test.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,34 @@ import fs from "fs";
33
import path from "path";
44
import process from "process";
55

6-
const ONEDOC_API_KEY = process.env.ONEDOC;
6+
const ONEDOC_API_KEY = process.env.ONEDOC_API_KEY;
77
(async () => {
88

9-
const onedoc = new Onedoc(ONEDOC_API_KEY);
10-
11-
let doc = {
12-
html: "<h1>Hello World</h1>",
13-
title: "Hello",
14-
test: true, // if true, produce a PDF in test mode with a Onedoc's watermark
15-
save: false, // if true, host the document and provide a download link in the console and your Onedoc's dashboard
16-
expiresIn: 30, // the number of day you want to host your document
17-
assets: [
18-
{
19-
path: "./stylesheet.css",
20-
content: fs.readFileSync(path.join(process.cwd(), "/test/stylesheet.css")).toString(),
21-
},
22-
],
23-
};
24-
25-
const { file, link, error, info } = await onedoc.render(doc);
26-
27-
if (error) {
28-
throw error;
9+
try{
10+
const onedoc = new Onedoc(ONEDOC_API_KEY);
11+
12+
let doc = {
13+
html: "<h1>Hello World</h1>",
14+
title: "Hello",
15+
test: true, // if true, produce a PDF in test mode with a Onedoc's watermark
16+
save: false, // if true, host the document and provide a download link in the console and your Onedoc's dashboard
17+
expiresIn: 30, // the number of day you want to host your document
18+
assets: [
19+
{
20+
path: "./stylesheet.css",
21+
content: fs.readFileSync(path.join(process.cwd(), "/test/stylesheet.css")).toString(),
22+
},
23+
],
24+
};
25+
26+
const { file, link, error, info } = await onedoc.render(doc);
27+
28+
if (error) {
29+
throw error;
30+
}
31+
32+
fs.writeFileSync("./Test.pdf", Buffer.from(file));
33+
}catch(e){
34+
console.error(e);
2935
}
30-
31-
fs.writeFileSync("./Test.pdf", Buffer.from(file));
3236
})();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
body{
2-
background-color: red;
2+
background-color: rgb(0, 255, 187);
33
}

packages/client-js/tsconfig.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"moduleResolution": "node",
4+
}
5+
}

0 commit comments

Comments
 (0)