@paroicms/public-server-lib 0.28.0 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paroicms/public-server-lib",
3
- "version": "0.28.0",
3
+ "version": "0.29.0",
4
4
  "description": "Common utilitaries for paroicms plugins (backend side).",
5
5
  "author": "Paroi Team",
6
6
  "repository": {
@@ -8,7 +8,50 @@ import type {
8
8
  SiteIds,
9
9
  ThemeConf,
10
10
  } from "@paroicms/public-anywhere-lib";
11
- import type { Request, Response } from "express";
11
+ import type Stream from "node:stream";
12
+
13
+ export interface PaHttpContext {
14
+ req: PaHttpRequest;
15
+ res: PaHttpResponse;
16
+ }
17
+
18
+ export interface PaHttpRequest {
19
+ hostname: string;
20
+ headers: { [headerName: string]: string | undefined };
21
+ method: string;
22
+ /** Contains the path and the query string. */
23
+ relativeUrl: string;
24
+ path: string;
25
+ query: { [parameterName: string]: string | undefined };
26
+ body: object | undefined;
27
+ file: MulterFile | undefined;
28
+ }
29
+
30
+ export interface MulterFile {
31
+ /** Name of the form field associated with this file. */
32
+ fieldname: string;
33
+ /** Name of the file on the uploader's computer. */
34
+ originalname: string;
35
+ /** Value of the `Content-Type` header for this file. */
36
+ mimetype: string;
37
+ /** Size of the file in bytes. */
38
+ size: number;
39
+ /** `DiskStorage` only: Directory to which this file has been uploaded. */
40
+ destination: string;
41
+ /** `DiskStorage` only: Name of this file within `destination`. */
42
+ filename: string;
43
+ /** `DiskStorage` only: Full path to the uploaded file. */
44
+ path: string;
45
+ /** `MemoryStorage` only: A Buffer containing the entire file. */
46
+ buffer: Buffer;
47
+ }
48
+
49
+ export interface PaHttpResponse {
50
+ readonly headersSent: boolean;
51
+ status(code: number): this;
52
+ append(field: string, value?: string[] | string): this;
53
+ send(body?: Buffer | object | string | Stream): this;
54
+ }
12
55
 
13
56
  export interface ParoiCmsPlugin {
14
57
  version: string;
@@ -55,8 +98,7 @@ export type PluginLiquidFilterHandler = (
55
98
 
56
99
  export type PublicApiHandler = (
57
100
  service: BackendPluginRenderService,
58
- req: Request,
59
- res: Response,
101
+ httpContext: PaHttpContext,
60
102
  relativePath: string,
61
103
  ) => Promise<void> | void;
62
104
 
@@ -94,22 +136,24 @@ export interface BackendPluginRenderService extends BackendPluginService {
94
136
  fieldName: string;
95
137
  language?: string;
96
138
  }) => Promise<FieldValue | undefined>;
97
- renderChildPartials(options: {
98
- req: Request;
99
- res: Response;
100
- params: PartialsParamsInput;
101
- parentDocumentId: ParsedNodelId;
102
- labeledByTermId?: string;
103
- }): Promise<void>;
104
- renderSearchPartials(options: {
105
- req: Request;
106
- res: Response;
107
- language: string;
108
- words: string[];
109
- limit: number;
110
- start: number;
111
- templateName: string;
112
- }): Promise<void>;
139
+ renderChildPartials(
140
+ ctx: PaHttpContext,
141
+ options: {
142
+ params: PartialsParamsInput;
143
+ parentDocumentId: ParsedNodelId;
144
+ labeledByTermId?: string;
145
+ },
146
+ ): Promise<void>;
147
+ renderSearchPartials(
148
+ ctx: PaHttpContext,
149
+ options: {
150
+ language: string;
151
+ words: string[];
152
+ limit: number;
153
+ start: number;
154
+ templateName: string;
155
+ },
156
+ ): Promise<void>;
113
157
  useImage: (options: { imageUid: string; size: ImageSize }) => Promise<UsedImage>;
114
158
  getDocument: (documentId: string) => Promise<PublicDocument | undefined>;
115
159
  }