diff --git a/demo-api/collections/mycol.yml b/demo-api/collections/mycol.yml new file mode 100644 index 0000000..4d2a1c8 --- /dev/null +++ b/demo-api/collections/mycol.yml @@ -0,0 +1,31 @@ +name: mycol +uploadPath: ../media/mycol + +meta: + label: { de: mycol, en: mycol } + rowIdentTpl: { twig: "{{ title }}" } + views: + - type: table + columns: + - title + +permissions: + public: + methods: + get: true + post: false + put: false + delete: false + user: + methods: + get: true + post: true + put: false + delete: false + +hooks: + get: + return: + type: javascript + file: hooks/mycol/get_return.js + diff --git a/demo-api/config.yml b/demo-api/config.yml new file mode 100644 index 0000000..8f564ff --- /dev/null +++ b/demo-api/config.yml @@ -0,0 +1,10 @@ +namespace: myapi + +# Metaangaben zum Projekt welche in der UI verwendet werden können +meta: + # wird in der Admin-UI zum Projekt aufgegeben + imageUrl: https://source.unsplash.com/random/?internet + +# Liste aller möglichen Kollektionen (Listen, Seiten...) zum Projekt +collections: + - !include collections/mycol.yml \ No newline at end of file diff --git a/demo-api/hooks/mycol/get_return.js b/demo-api/hooks/mycol/get_return.js new file mode 100644 index 0000000..c993ca0 --- /dev/null +++ b/demo-api/hooks/mycol/get_return.js @@ -0,0 +1,30 @@ +;(function () { + const r = context.request() + + /** @type {import("../../..").HookException} */ + const hEx = {} + + if (r.query("pdf")) { + // pdf test + hEx.status = 200 + hEx.bytes = context.pdf.fromHTML( + context.fs.readFile("testfiles/test.html"), + { + orientation: "Portrait", + pageSize: "A4", + title: "TestPDF", + marginTop: 30, + marginBottom: 30, + marginLeft: 30, + marginRight: 30, + headerLeft: "TestPDF", + headerCenter: "[date]", + headerRight: "[page] - [frompage] / [topage]", + headerSpacing: 10, + } + ) + context.response.header("Content-Type", "application/pdf") + context.response.header("Content-Disposition", "inline; filename=\"mypdf.pdf\"") + throw hEx + } +})() \ No newline at end of file diff --git a/demo-api/testfiles/test.html b/demo-api/testfiles/test.html new file mode 100644 index 0000000..0832a12 --- /dev/null +++ b/demo-api/testfiles/test.html @@ -0,0 +1,88 @@ + + + + + +

Title

+

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. + +Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. + +Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. + +Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. + +Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis. + +At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, At accusam aliquyam diam diam dolore dolores duo eirmod eos erat, et nonumy sed tempor et et invidunt justo labore Stet clita ea et gubergren, kasd magna no rebum. sanctus sea sed takimata ut vero voluptua. est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat. + +Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus. + +Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. + +Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. + +Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. + +Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo

+ + + + + + + + + +
Col 1Col 2
Cell 1-1Cell 1-2
+
+
+ +

+ Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. + +Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. + +Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. + +Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. + +Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis. + +At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, At accusam aliquyam diam diam dolore dolores duo eirmod eos erat, et nonumy sed tempor et et invidunt justo labore Stet clita ea et gubergren, kasd magna no rebum. sanctus sea sed takimata ut vero voluptua. est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat. + +Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus. + +Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. + +Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. + +Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. + +Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo +

+ + + \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index 95a7157..0394917 100644 --- a/index.d.ts +++ b/index.d.ts @@ -16,7 +16,7 @@ export interface DbReadOptions { offset?: number limit?: number sort?: string[] - pipelineMod?: (pipe: {[key: string]: any}[]) => {[key: string]: any}[] + pipelineMod?: (pipe: { [key: string]: any }[]) => { [key: string]: any }[] } interface GetHookGetOnlyData { @@ -58,7 +58,7 @@ interface GetHookData { /** * pipelineMod is a function to modify the mongodb query pipeline */ - pipelineMod?: (pipe: {[key: string]: any}[]) => {[key: string]: any}[] + pipelineMod?: (pipe: { [key: string]: any }[]) => { [key: string]: any }[] } interface PostHookData { @@ -75,10 +75,7 @@ interface DbPackage { * @param colName collection name * @param options options map */ - find( - colName: string, - options?: DbReadOptions - ): CollectionDocument[] + find(colName: string, options?: DbReadOptions): CollectionDocument[] /** * read count of documents for filter from a collection @@ -86,10 +83,7 @@ interface DbPackage { * @param colName collection name * @param options options map (only filter is valid) */ - count( - colName: string, - options?: DbReadOptions - ): number + count(colName: string, options?: DbReadOptions): number /** * create a document in a collection @@ -97,10 +91,7 @@ interface DbPackage { * @param colName collection name * @param data data map */ - create( - colName: string, - data: CollectionDocument - ): CollectionDocument + create(colName: string, data: CollectionDocument): CollectionDocument /** * update a document in a collection @@ -133,7 +124,6 @@ interface DbPackage { colName: string, options?: DbReadOptions ): { message: "ok"; removed: number } - } interface SmtpPackage { @@ -201,7 +191,6 @@ interface FsPackage { * @param path */ remove(path: string): void - } interface TplPackage { @@ -392,7 +381,7 @@ interface ImagePackage { interface XmlPackage { /** * create xml string - * + * * @param data object or array * @param options options */ @@ -400,38 +389,92 @@ interface XmlPackage { /** * parse xml string to json - * + * * @param xml xml string * @param options options */ - parse(xml:string, options?: {}): any + parse(xml: string, options?: {}): any } interface CookiePackage { /** * get cookie from http header - * + * * @param name cookie name */ get(name: string): string /** * set cookie via http header - * + * * @param name cookie name * @param value cookie value * @param options cookie options */ - set(name: string, value: string, options?:{ - maxAge?: number - path?:string - domain?:string - secure?:boolean - httpOnly?:boolean - }): void + set( + name: string, + value: string, + options?: { + maxAge?: number + path?: string + domain?: string + secure?: boolean + httpOnly?: boolean + } + ): void } -export interface HookContext extends GetHookData, GetHookGetOnlyData, PostHookData { +interface PdfPackage { + /** + * generate pdf from html + * + * @param html html string + * @param options options + */ + fromHTML( + html: string, + options?: { + copies?: number // Number of copies to print into the pdf file (default 1) + dpi?: number // Change the dpi explicitly (this has no effect on X11 based systems) + grayscale?: boolean // PDF will be generated in grayscale + imageDpi?: number // When embedding images scale them down to this dpi (default 600) + imageQuality?: number // When jpeg compressing images use this quality (default 94) + lowQuality?: boolean // Generates lower quality pdf/ps. Useful to shrink the result document space + marginBottom?: number // Set the page bottom margin + marginLeft?: number // Set the page left margin (default 10mm) + marginRight?: number // Set the page right margin (default 10mm) + marginTop?: number // Set the page top margin + noCollate?: boolean // Do not collate when printing multiple copies (default collate) + noPdfCompression?: boolean // Do not use lossless compression on pdf objects + orientation?: "Portrait" | "Landscape" // Set orientation to Landscape or Portrait (default Portrait) + pageHeight?: number // Page height + pageSize?: string // Set paper size to: A4, Letter, etc. (default A4) + pageWidth?: number // Page width + title?: string // The title of the generated pdf file (The title of the first document is used if not specified) + // page settings + printMediaType?: boolean // Use print media-type instead of screen + footerCenter?: string // Centered footer text + footerFontName?: string // Set footer font name (default Arial) + footerFontSize?: number // Set footer font size (default 12) + footerLeft?: string // Left aligned footer text + footerLine?: boolean // Display line above the footer + footerRight?: string // Right aligned footer text + footerSpacing?: number // Spacing between footer and content in mm (default 0) + headerCenter?: string // Centered header text + headerFontName?: string // Set header font name (default Arial) + headerFontSize?: number // Set header font size (default 12) + headerLeft?: string // Left aligned header text + headerLine?: boolean // Display line below the header + headerRight?: string // Right aligned header text + headerSpacing?: number // Spacing between header and content in mm (default 0) + } + ): any +} + +export interface HookContext + extends GetHookData, + GetHookGetOnlyData, + PostHookData { request(): { method: string remoteAddr: string @@ -462,11 +505,14 @@ export interface HookContext extends GetHookData, GetHookGetOnlyData, PostHookDa image: ImagePackage xml: XmlPackage cookie: CookiePackage + pdf: PdfPackage } export interface HookException { status?: number html?: string + string?: string + bytes?: any file?: string [key: string]: any } diff --git a/tsconfig.json b/tsconfig.json index 64ae38d..645493f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,15 +1,18 @@ { - "compilerOptions": { - "module": "commonjs", - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": true, - "strictFunctionTypes": true, - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts" - ] -} \ No newline at end of file + "include": ["demo-api/**/*"], + "compilerOptions": { + "typeRoots": ["."], + "module": "commonjs", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + + "allowJs": true, + "checkJs": true + }, + "files": ["index.d.ts"] +}