Skip to content

Commit

Permalink
Merge pull request #7 from Doczilla-APP/improvements
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
TriPSs authored Jan 4, 2024
2 parents 02f4f05 + f1fd96c commit f4fc2be
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 20 deletions.
16 changes: 9 additions & 7 deletions src/__tests__/pdf.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,27 @@ describe('PDF', () => {

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

test('it should encode the pdf.headerTemplate and pdf.footerTemplate options', async () => {
test('it should encode the page.html, page.htmlTemplate, pdf.headerHtml and pdf.footerHtml options', async () => {
await client.pdf.direct({
page: {
html: '<div>Your first Doczilla PDF</div>'
html: '<div>Your first Doczilla PDF</div>',
htmlTemplate: '<div>Your first Doczilla {{ type }}</div>',
},
pdf: {
headerTemplate: '<div>Header template</div>',
footerTemplate: '<div>Footer template</div>'
headerHtml: '<div>Header template</div>',
footerHtml: '<div>Footer template</div>'
}
})

expect(axiosMock.history.post.length).toBe(1)
expect(axiosMock.history.post[0].data).toEqual(JSON.stringify({
page: {
html: 'PGRpdj5Zb3VyIGZpcnN0IERvY3ppbGxhIFBERjwvZGl2Pg=='
html: 'PGRpdj5Zb3VyIGZpcnN0IERvY3ppbGxhIFBERjwvZGl2Pg==',
htmlTemplate: 'PGRpdj5Zb3VyIGZpcnN0IERvY3ppbGxhIHt7IHR5cGUgfX08L2Rpdj4='
},
pdf: {
headerTemplate: 'PGRpdj5IZWFkZXIgdGVtcGxhdGU8L2Rpdj4=',
footerTemplate: 'PGRpdj5Gb290ZXIgdGVtcGxhdGU8L2Rpdj4='
headerHtml: 'PGRpdj5IZWFkZXIgdGVtcGxhdGU8L2Rpdj4=',
footerHtml: 'PGRpdj5Gb290ZXIgdGVtcGxhdGU8L2Rpdj4='
}
}))
})
Expand Down
7 changes: 7 additions & 0 deletions src/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,27 @@
export { AsyncJob } from './models/AsyncJob';
export type { AsyncPdf } from './models/AsyncPdf';
export type { AsyncScreenshot } from './models/AsyncScreenshot';
export type { BadRequestResponse } from './models/BadRequestResponse';
export type { CreatePdf } from './models/CreatePdf';
export type { CreateScreenshot } from './models/CreateScreenshot';
export type { ForbiddenResponse } from './models/ForbiddenResponse';
export type { InternalServerErrorResponse } from './models/InternalServerErrorResponse';
export type { PageAuthentication } from './models/PageAuthentication';
export { PageCookie } from './models/PageCookie';
export { PageOptions } from './models/PageOptions';
export type { PayloadTooLargeResponse } from './models/PayloadTooLargeResponse';
export type { PDFMargin } from './models/PDFMargin';
export { PdfOptions } from './models/PdfOptions';
export type { ScreenshotClip } from './models/ScreenshotClip';
export { ScreenshotOptions } from './models/ScreenshotOptions';
export { ScreenshotOverlay } from './models/ScreenshotOverlay';
export type { ScreenshotViewport } from './models/ScreenshotViewport';
export type { StorageOptions } from './models/StorageOptions';
export type { SubscriptionLimitReachedResponse } from './models/SubscriptionLimitReachedResponse';
export { SyncJob } from './models/SyncJob';
export type { SyncPdf } from './models/SyncPdf';
export type { SyncScreenshot } from './models/SyncScreenshot';
export type { TooManyRequestsResponse } from './models/TooManyRequestsResponse';
export type { UnauthorizedResponse } from './models/UnauthorizedResponse';
export { WebhookEvent } from './models/WebhookEvent';
export { WebhookOptions } from './models/WebhookOptions';
2 changes: 1 addition & 1 deletion src/generated/models/AsyncPdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { WebhookOptions } from './WebhookOptions';

export type AsyncPdf = {
/**
* Page options, either provide the `url` or `html` option.
* Page options, either provide the `url`, `html` or `htmlTemplate` option.
*/
page: PageOptions;
pdf?: PdfOptions | null;
Expand Down
2 changes: 1 addition & 1 deletion src/generated/models/AsyncScreenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { WebhookOptions } from './WebhookOptions';

export type AsyncScreenshot = {
/**
* Page options, either provide the `url` or `html` option.
* Page options, either provide the `url`, `html` or `htmlTemplate` option.
*/
page: PageOptions;
screenshot?: ScreenshotOptions | null;
Expand Down
11 changes: 11 additions & 0 deletions src/generated/models/BadRequestResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type BadRequestResponse = {
message: string;
code: string;
fields: Record<string, string>;
};

2 changes: 1 addition & 1 deletion src/generated/models/CreatePdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { PdfOptions } from './PdfOptions';

export type CreatePdf = {
/**
* Page options, either provide the `url` or `html` option.
* Page options, either provide the `url`, `html` or `htmlTemplate` option.
*/
page: PageOptions;
pdf?: PdfOptions | null;
Expand Down
2 changes: 1 addition & 1 deletion src/generated/models/CreateScreenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { ScreenshotOptions } from './ScreenshotOptions';

export type CreateScreenshot = {
/**
* Page options, either provide the `url` or `html` option.
* Page options, either provide the `url`, `html` or `htmlTemplate` option.
*/
page: PageOptions;
screenshot?: ScreenshotOptions | null;
Expand Down
9 changes: 9 additions & 0 deletions src/generated/models/ForbiddenResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type ForbiddenResponse = {
message: string;
};

9 changes: 9 additions & 0 deletions src/generated/models/InternalServerErrorResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type InternalServerErrorResponse = {
message: string;
};

8 changes: 8 additions & 0 deletions src/generated/models/PageOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ export type PageOptions = {
* HTML to render. Needs to be base64 encoded!
*/
html?: string | null;
/**
* HTML template to render. Needs to be base64 encoded!
*/
htmlTemplate?: string | null;
/**
* Template data, only used in combination with `page.htmlTemplate`.
*/
templateData?: Record<string, any> | null;
/**
* When to consider waiting succeeds.
* - `auto` our smart waiting option that can handle 90% of the cases.
Expand Down
9 changes: 9 additions & 0 deletions src/generated/models/PayloadTooLargeResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type PayloadTooLargeResponse = {
message: string;
};

6 changes: 3 additions & 3 deletions src/generated/models/PdfOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export type PdfOptions = {
* - `pageNumber` current page number
* - `totalPages` total pages in the document
*/
headerTemplate?: string | null;
headerHtml?: string | null;
/**
* HTML template for the print footer. Has the same constraints and support for special classes as `headerTemplate`.
* HTML template for the print footer. Has the same constraints and support for special classes as `headerHtml`.
*/
footerTemplate?: string | null;
footerHtml?: string | null;
/**
* Set to `true` to print background graphics.
*/
Expand Down
9 changes: 9 additions & 0 deletions src/generated/models/SubscriptionLimitReachedResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type SubscriptionLimitReachedResponse = {
message: string;
};

2 changes: 1 addition & 1 deletion src/generated/models/SyncPdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { StorageOptions } from './StorageOptions';

export type SyncPdf = {
/**
* Page options, either provide the `url` or `html` option.
* Page options, either provide the `url`, `html` or `htmlTemplate` option.
*/
page: PageOptions;
pdf?: PdfOptions | null;
Expand Down
2 changes: 1 addition & 1 deletion src/generated/models/SyncScreenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { StorageOptions } from './StorageOptions';

export type SyncScreenshot = {
/**
* Page options, either provide the `url` or `html` option.
* Page options, either provide the `url`, `html` or `htmlTemplate` option.
*/
page: PageOptions;
screenshot?: ScreenshotOptions | null;
Expand Down
9 changes: 9 additions & 0 deletions src/generated/models/TooManyRequestsResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type TooManyRequestsResponse = {
message: string;
};

9 changes: 9 additions & 0 deletions src/generated/models/UnauthorizedResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type UnauthorizedResponse = {
message: string;
};

12 changes: 8 additions & 4 deletions src/services/BaseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@ export class BaseService {
requestBody.page.html = this.baseEncodeContent(requestBody.page.html)
}

if (requestBody.pdf?.headerTemplate) {
requestBody.pdf.headerTemplate = this.baseEncodeContent(requestBody.pdf.headerTemplate)
if (requestBody.page.htmlTemplate) {
requestBody.page.htmlTemplate = this.baseEncodeContent(requestBody.page.htmlTemplate)
}

if (requestBody.pdf?.footerTemplate) {
requestBody.pdf.footerTemplate = this.baseEncodeContent(requestBody.pdf.footerTemplate)
if (requestBody.pdf?.headerHtml) {
requestBody.pdf.headerHtml = this.baseEncodeContent(requestBody.pdf.headerHtml)
}

if (requestBody.pdf?.footerHtml) {
requestBody.pdf.footerHtml = this.baseEncodeContent(requestBody.pdf.footerHtml)
}

return requestBody
Expand Down

0 comments on commit f4fc2be

Please sign in to comment.