-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from Doczilla-APP/templating
Templating
- Loading branch information
Showing
21 changed files
with
1,747 additions
and
668 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,9 +28,9 @@ | |
"sideEffects": false, | ||
"exports": { | ||
".": { | ||
"types": "./dist/types/index.d.ts", | ||
"require": "./dist/index.js", | ||
"import": "./dist/index.mjs", | ||
"types": "./dist/types/index.d.ts" | ||
"import": "./dist/index.mjs" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
|
@@ -47,24 +47,23 @@ | |
"test": "jest" | ||
}, | ||
"dependencies": { | ||
"axios": "^1.7.5" | ||
"axios": "^1.7.7" | ||
}, | ||
"devDependencies": { | ||
"@jest/globals": "^29.7.0", | ||
"@swc/core": "^1.7.14", | ||
"@types/jest": "^29.5.12", | ||
"@types/node": "^20.14.10", | ||
"@typescript-eslint/eslint-plugin": "^7.17.0", | ||
"@typescript-eslint/parser": "^7.17.0", | ||
"axios-mock-adapter": "^1.22.0", | ||
"eslint": "9.8.0", | ||
"eslint-plugin-import": "2.29.1", | ||
"@types/jest": "^29.5.14", | ||
"@types/node": "^22.9.1", | ||
"@typescript-eslint/eslint-plugin": "^8.15.0", | ||
"@typescript-eslint/parser": "^8.15.0", | ||
"axios-mock-adapter": "^2.1.0", | ||
"eslint": "9.15.0", | ||
"eslint-plugin-import": "2.31.0", | ||
"eslint-plugin-simple-import-sort": "^12.1.1", | ||
"jest": "^29.7.0", | ||
"openapi-typescript-codegen": "^0.29.0", | ||
"ts-jest": "^29.2.5", | ||
"tsup": "^8.2.4", | ||
"typescript": "^5.5" | ||
"tsup": "^8.3.5", | ||
"typescript": "^5.6" | ||
}, | ||
"packageManager": "[email protected]", | ||
"engines": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { describe, expect, test } from '@jest/globals' | ||
import MockAdapter from 'axios-mock-adapter' | ||
|
||
import Doczilla from '../Doczilla' | ||
|
||
describe('Template', () => { | ||
|
||
const client = new Doczilla('fake-api-token') | ||
// @ts-expect-error private property | ||
const axiosMock = new MockAdapter(client.client) | ||
|
||
axiosMock.onAny().reply(200, Buffer.from('')) | ||
|
||
test('it should encode the page.html, page.htmlTemplate, pdf.headerHtml and pdf.footerHtml options', async () => { | ||
await client.template.direct('fake-template-id', { | ||
page: { | ||
html: '<div>Your first Doczilla PDF</div>', | ||
htmlTemplate: '<div>Your first Doczilla {{ type }}</div>' | ||
}, | ||
pdf: { | ||
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==', | ||
htmlTemplate: 'PGRpdj5Zb3VyIGZpcnN0IERvY3ppbGxhIHt7IHR5cGUgfX08L2Rpdj4=' | ||
}, | ||
pdf: { | ||
headerHtml: 'PGRpdj5IZWFkZXIgdGVtcGxhdGU8L2Rpdj4=', | ||
footerHtml: 'PGRpdj5Gb290ZXIgdGVtcGxhdGU8L2Rpdj4=' | ||
} | ||
})) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { describe, expect, test } from '@jest/globals' | ||
import MockAdapter from 'axios-mock-adapter' | ||
|
||
import Doczilla from '../Doczilla' | ||
import { CreateTemplate } from '../generated' | ||
|
||
describe('Templates', () => { | ||
|
||
const client = new Doczilla('fake-api-token') | ||
// @ts-expect-error private property | ||
const axiosMock = new MockAdapter(client.client) | ||
|
||
axiosMock.onAny().reply(200, Buffer.from('')) | ||
|
||
describe('create', () => { | ||
test('it should encode the page.html, page.htmlTemplate, pdf.headerHtml and pdf.footerHtml options', async () => { | ||
await client.template.create({ | ||
name: 'fake template', | ||
output: CreateTemplate.output.PDF, | ||
variables: { | ||
page: { | ||
html: '<div>Your first Doczilla PDF</div>', | ||
htmlTemplate: '<div>Your first Doczilla {{ type }}</div>' | ||
}, | ||
pdf: { | ||
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({ | ||
name: 'fake template', | ||
output: CreateTemplate.output.PDF, | ||
variables: { | ||
page: { | ||
html: 'PGRpdj5Zb3VyIGZpcnN0IERvY3ppbGxhIFBERjwvZGl2Pg==', | ||
htmlTemplate: 'PGRpdj5Zb3VyIGZpcnN0IERvY3ppbGxhIHt7IHR5cGUgfX08L2Rpdj4=' | ||
}, | ||
pdf: { | ||
headerHtml: 'PGRpdj5IZWFkZXIgdGVtcGxhdGU8L2Rpdj4=', | ||
footerHtml: 'PGRpdj5Gb290ZXIgdGVtcGxhdGU8L2Rpdj4=' | ||
} | ||
} | ||
})) | ||
}) | ||
}) | ||
|
||
describe('update', () => { | ||
test('it should encode the page.html, page.htmlTemplate, pdf.headerHtml and pdf.footerHtml options', async () => { | ||
await client.template.update('fake-template-id', { | ||
variables: { | ||
page: { | ||
html: '<div>Your first Doczilla PDF</div>', | ||
htmlTemplate: '<div>Your first Doczilla {{ type }}</div>' | ||
}, | ||
pdf: { | ||
headerHtml: '<div>Header template</div>', | ||
footerHtml: '<div>Footer template</div>' | ||
} | ||
} | ||
}) | ||
|
||
expect(axiosMock.history.post.length).toBe(2) | ||
expect(axiosMock.history.post[1].data).toEqual(JSON.stringify({ | ||
variables: { | ||
page: { | ||
html: 'PGRpdj5Zb3VyIGZpcnN0IERvY3ppbGxhIFBERjwvZGl2Pg==', | ||
htmlTemplate: 'PGRpdj5Zb3VyIGZpcnN0IERvY3ppbGxhIHt7IHR5cGUgfX08L2Rpdj4=' | ||
}, | ||
pdf: { | ||
headerHtml: 'PGRpdj5IZWFkZXIgdGVtcGxhdGU8L2Rpdj4=', | ||
footerHtml: 'PGRpdj5Gb290ZXIgdGVtcGxhdGU8L2Rpdj4=' | ||
} | ||
} | ||
})) | ||
}) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* generated using openapi-typescript-codegen -- do not edit */ | ||
/* istanbul ignore file */ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
import type { PageOptions } from './PageOptions'; | ||
import type { PdfOptions } from './PdfOptions'; | ||
import type { ScreenshotOptions } from './ScreenshotOptions'; | ||
import type { StorageOptions } from './StorageOptions'; | ||
import type { WebhookOptions } from './WebhookOptions'; | ||
export type AsyncFromTemplate = { | ||
/** | ||
* Page options. | ||
*/ | ||
page?: PageOptions | null; | ||
/** | ||
* Screenshot options, only used if Template's output is "SCREENSHOT". | ||
*/ | ||
screenshot?: ScreenshotOptions | null; | ||
/** | ||
* Pdf options, only used if Template's output is "PDF". | ||
*/ | ||
pdf?: PdfOptions | null; | ||
storage?: StorageOptions | null; | ||
/** | ||
* Webhook to call when screenshot is generated. | ||
*/ | ||
webhook: WebhookOptions; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* generated using openapi-typescript-codegen -- do not edit */ | ||
/* istanbul ignore file */ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
import type { PageOptions } from './PageOptions'; | ||
import type { PdfOptions } from './PdfOptions'; | ||
import type { ScreenshotOptions } from './ScreenshotOptions'; | ||
export type CreateFromTemplate = { | ||
/** | ||
* Page options. | ||
*/ | ||
page?: PageOptions | null; | ||
/** | ||
* Screenshot options, only used if Template's output is "SCREENSHOT". | ||
*/ | ||
screenshot?: ScreenshotOptions | null; | ||
/** | ||
* Pdf options, only used if Template's output is "PDF". | ||
*/ | ||
pdf?: PdfOptions | null; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* generated using openapi-typescript-codegen -- do not edit */ | ||
/* istanbul ignore file */ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
import type { TemplateVariables } from './TemplateVariables'; | ||
export type CreateTemplate = { | ||
/** | ||
* The name of the template. | ||
*/ | ||
name: string; | ||
/** | ||
* The output format of the template. | ||
*/ | ||
output: CreateTemplate.output; | ||
/** | ||
* The variables of the template. | ||
*/ | ||
variables: TemplateVariables; | ||
}; | ||
export namespace CreateTemplate { | ||
/** | ||
* The output format of the template. | ||
*/ | ||
export enum output { | ||
PDF = 'PDF', | ||
IMAGE = 'IMAGE', | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* generated using openapi-typescript-codegen -- do not edit */ | ||
/* istanbul ignore file */ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
export type ListTemplate = { | ||
/** | ||
* The unique identifier of the template. | ||
*/ | ||
id: string; | ||
/** | ||
* The name of the template. | ||
*/ | ||
name: string; | ||
/** | ||
* The output format of the template. | ||
*/ | ||
output: ListTemplate.output; | ||
/** | ||
* The date and time the template was created. | ||
*/ | ||
createdAt: string; | ||
/** | ||
* The date and time the template was last updated. | ||
*/ | ||
updatedAt: string; | ||
}; | ||
export namespace ListTemplate { | ||
/** | ||
* The output format of the template. | ||
*/ | ||
export enum output { | ||
PDF = 'PDF', | ||
IMAGE = 'IMAGE', | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* generated using openapi-typescript-codegen -- do not edit */ | ||
/* istanbul ignore file */ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
import type { ListTemplate } from './ListTemplate'; | ||
export type ListTemplateResponse = { | ||
/** | ||
* Is true if there is a next page. | ||
*/ | ||
hasNextPage: boolean; | ||
/** | ||
* Is true if there is a previous page. | ||
*/ | ||
hasPreviousPage: boolean; | ||
/** | ||
* The list of templates. | ||
*/ | ||
data: Array<ListTemplate>; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.