Skip to content

Commit f1fd96c

Browse files
committed
feat: Added page.htmlTemplate support
1 parent fa51d47 commit f1fd96c

File tree

10 files changed

+34
-41
lines changed

10 files changed

+34
-41
lines changed

src/__tests__/pdf.spec.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,27 @@ describe('PDF', () => {
1111

1212
axiosMock.onAny().reply(200, Buffer.from(''))
1313

14-
test('it should encode the pdf.headerTemplate and pdf.footerTemplate options', async () => {
14+
test('it should encode the page.html, page.htmlTemplate, pdf.headerHtml and pdf.footerHtml options', async () => {
1515
await client.pdf.direct({
1616
page: {
17-
html: '<div>Your first Doczilla PDF</div>'
17+
html: '<div>Your first Doczilla PDF</div>',
18+
htmlTemplate: '<div>Your first Doczilla {{ type }}</div>',
1819
},
1920
pdf: {
20-
headerTemplate: '<div>Header template</div>',
21-
footerTemplate: '<div>Footer template</div>'
21+
headerHtml: '<div>Header template</div>',
22+
footerHtml: '<div>Footer template</div>'
2223
}
2324
})
2425

2526
expect(axiosMock.history.post.length).toBe(1)
2627
expect(axiosMock.history.post[0].data).toEqual(JSON.stringify({
2728
page: {
28-
html: 'PGRpdj5Zb3VyIGZpcnN0IERvY3ppbGxhIFBERjwvZGl2Pg=='
29+
html: 'PGRpdj5Zb3VyIGZpcnN0IERvY3ppbGxhIFBERjwvZGl2Pg==',
30+
htmlTemplate: 'PGRpdj5Zb3VyIGZpcnN0IERvY3ppbGxhIHt7IHR5cGUgfX08L2Rpdj4='
2931
},
3032
pdf: {
31-
headerTemplate: 'PGRpdj5IZWFkZXIgdGVtcGxhdGU8L2Rpdj4=',
32-
footerTemplate: 'PGRpdj5Gb290ZXIgdGVtcGxhdGU8L2Rpdj4='
33+
headerHtml: 'PGRpdj5IZWFkZXIgdGVtcGxhdGU8L2Rpdj4=',
34+
footerHtml: 'PGRpdj5Gb290ZXIgdGVtcGxhdGU8L2Rpdj4='
3335
}
3436
}))
3537
})

src/generated/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,27 @@
66
export { AsyncJob } from './models/AsyncJob';
77
export type { AsyncPdf } from './models/AsyncPdf';
88
export type { AsyncScreenshot } from './models/AsyncScreenshot';
9+
export type { BadRequestResponse } from './models/BadRequestResponse';
910
export type { CreatePdf } from './models/CreatePdf';
1011
export type { CreateScreenshot } from './models/CreateScreenshot';
12+
export type { ForbiddenResponse } from './models/ForbiddenResponse';
13+
export type { InternalServerErrorResponse } from './models/InternalServerErrorResponse';
1114
export type { PageAuthentication } from './models/PageAuthentication';
1215
export { PageCookie } from './models/PageCookie';
1316
export { PageOptions } from './models/PageOptions';
17+
export type { PayloadTooLargeResponse } from './models/PayloadTooLargeResponse';
1418
export type { PDFMargin } from './models/PDFMargin';
1519
export { PdfOptions } from './models/PdfOptions';
1620
export type { ScreenshotClip } from './models/ScreenshotClip';
1721
export { ScreenshotOptions } from './models/ScreenshotOptions';
1822
export { ScreenshotOverlay } from './models/ScreenshotOverlay';
1923
export type { ScreenshotViewport } from './models/ScreenshotViewport';
2024
export type { StorageOptions } from './models/StorageOptions';
25+
export type { SubscriptionLimitReachedResponse } from './models/SubscriptionLimitReachedResponse';
2126
export { SyncJob } from './models/SyncJob';
2227
export type { SyncPdf } from './models/SyncPdf';
2328
export type { SyncScreenshot } from './models/SyncScreenshot';
29+
export type { TooManyRequestsResponse } from './models/TooManyRequestsResponse';
30+
export type { UnauthorizedResponse } from './models/UnauthorizedResponse';
2431
export { WebhookEvent } from './models/WebhookEvent';
2532
export { WebhookOptions } from './models/WebhookOptions';

src/generated/models/AsyncPdf.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@ import type { WebhookOptions } from './WebhookOptions';
1010

1111
export type AsyncPdf = {
1212
/**
13-
* Page options, either provide the `url` or `html` option.
13+
* Page options, either provide the `url`, `html` or `htmlTemplate` option.
1414
*/
1515
page: PageOptions;
16-
/**
17-
* Template data, only used in combination with `page.htmlTemplate`.
18-
*/
19-
templateData?: Record<string, any> | null;
2016
pdf?: PdfOptions | null;
2117
storage?: StorageOptions | null;
2218
/**

src/generated/models/AsyncScreenshot.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@ import type { WebhookOptions } from './WebhookOptions';
1010

1111
export type AsyncScreenshot = {
1212
/**
13-
* Page options, either provide the `url` or `html` option.
13+
* Page options, either provide the `url`, `html` or `htmlTemplate` option.
1414
*/
1515
page: PageOptions;
16-
/**
17-
* Template data, only used in combination with `page.htmlTemplate`.
18-
*/
19-
templateData?: Record<string, any> | null;
2016
screenshot?: ScreenshotOptions | null;
2117
storage?: StorageOptions | null;
2218
/**

src/generated/models/CreatePdf.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@ import type { PdfOptions } from './PdfOptions';
88

99
export type CreatePdf = {
1010
/**
11-
* Page options, either provide the `url` or `html` option.
11+
* Page options, either provide the `url`, `html` or `htmlTemplate` option.
1212
*/
1313
page: PageOptions;
14-
/**
15-
* Template data, only used in combination with `page.htmlTemplate`.
16-
*/
17-
templateData?: Record<string, any> | null;
1814
pdf?: PdfOptions | null;
1915
};
2016

src/generated/models/CreateScreenshot.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@ import type { ScreenshotOptions } from './ScreenshotOptions';
88

99
export type CreateScreenshot = {
1010
/**
11-
* Page options, either provide the `url` or `html` option.
11+
* Page options, either provide the `url`, `html` or `htmlTemplate` option.
1212
*/
1313
page: PageOptions;
14-
/**
15-
* Template data, only used in combination with `page.htmlTemplate`.
16-
*/
17-
templateData?: Record<string, any> | null;
1814
screenshot?: ScreenshotOptions | null;
1915
};
2016

src/generated/models/PageOptions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export type PageOptions = {
1919
* HTML template to render. Needs to be base64 encoded!
2020
*/
2121
htmlTemplate?: string | null;
22+
/**
23+
* Template data, only used in combination with `page.htmlTemplate`.
24+
*/
25+
templateData?: Record<string, any> | null;
2226
/**
2327
* When to consider waiting succeeds.
2428
* - `auto` our smart waiting option that can handle 90% of the cases.

src/generated/models/SyncPdf.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@ import type { StorageOptions } from './StorageOptions';
99

1010
export type SyncPdf = {
1111
/**
12-
* Page options, either provide the `url` or `html` option.
12+
* Page options, either provide the `url`, `html` or `htmlTemplate` option.
1313
*/
1414
page: PageOptions;
15-
/**
16-
* Template data, only used in combination with `page.htmlTemplate`.
17-
*/
18-
templateData?: Record<string, any> | null;
1915
pdf?: PdfOptions | null;
2016
storage?: StorageOptions | null;
2117
};

src/generated/models/SyncScreenshot.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@ import type { StorageOptions } from './StorageOptions';
99

1010
export type SyncScreenshot = {
1111
/**
12-
* Page options, either provide the `url` or `html` option.
12+
* Page options, either provide the `url`, `html` or `htmlTemplate` option.
1313
*/
1414
page: PageOptions;
15-
/**
16-
* Template data, only used in combination with `page.htmlTemplate`.
17-
*/
18-
templateData?: Record<string, any> | null;
1915
screenshot?: ScreenshotOptions | null;
2016
storage?: StorageOptions | null;
2117
};

src/services/BaseService.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,16 @@ export class BaseService {
4848
requestBody.page.html = this.baseEncodeContent(requestBody.page.html)
4949
}
5050

51-
if (requestBody.pdf?.headerTemplate) {
52-
requestBody.pdf.headerTemplate = this.baseEncodeContent(requestBody.pdf.headerTemplate)
51+
if (requestBody.page.htmlTemplate) {
52+
requestBody.page.htmlTemplate = this.baseEncodeContent(requestBody.page.htmlTemplate)
5353
}
5454

55-
if (requestBody.pdf?.footerTemplate) {
56-
requestBody.pdf.footerTemplate = this.baseEncodeContent(requestBody.pdf.footerTemplate)
55+
if (requestBody.pdf?.headerHtml) {
56+
requestBody.pdf.headerHtml = this.baseEncodeContent(requestBody.pdf.headerHtml)
57+
}
58+
59+
if (requestBody.pdf?.footerHtml) {
60+
requestBody.pdf.footerHtml = this.baseEncodeContent(requestBody.pdf.footerHtml)
5761
}
5862

5963
return requestBody

0 commit comments

Comments
 (0)