@paroicms/public-server-lib 0.28.0 → 0.30.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/dist/api-error-handler.d.ts +7 -0
- package/dist/api-error-handler.js +30 -0
- package/dist/api-error-handler.js.map +1 -0
- package/dist/html-helpers/html-helpers.d.ts +1 -1
- package/dist/html-helpers/html-helpers.js +2 -0
- package/dist/html-helpers/html-helpers.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/types/backend-plugin-types.d.ts +69 -24
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type ApiErrorStatus = 400 | 401 | 403 | 404 | 409 | 500;
|
|
2
|
+
export declare class ApiError extends Error {
|
|
3
|
+
readonly status: ApiErrorStatus;
|
|
4
|
+
readonly statusLabel: string;
|
|
5
|
+
constructor(status: ApiErrorStatus);
|
|
6
|
+
constructor(message: string, status: ApiErrorStatus);
|
|
7
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export class ApiError extends Error {
|
|
2
|
+
status;
|
|
3
|
+
statusLabel;
|
|
4
|
+
constructor(arg1, arg2) {
|
|
5
|
+
const message = typeof arg1 === "string" ? arg1 : getErrorLabel(arg1);
|
|
6
|
+
const status = (typeof arg1 === "string" ? arg2 : arg1) ?? 500;
|
|
7
|
+
super(message);
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.statusLabel = getErrorLabel(status);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function getErrorLabel(status) {
|
|
13
|
+
switch (status) {
|
|
14
|
+
case 400:
|
|
15
|
+
return "Bad Request";
|
|
16
|
+
case 401:
|
|
17
|
+
return "Unauthorized";
|
|
18
|
+
case 403:
|
|
19
|
+
return "Forbidden";
|
|
20
|
+
case 404:
|
|
21
|
+
return "Not Found";
|
|
22
|
+
case 409:
|
|
23
|
+
return "Conflict";
|
|
24
|
+
case 500:
|
|
25
|
+
return "Internal Server Error";
|
|
26
|
+
default:
|
|
27
|
+
return "Unknown Error";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=api-error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-error-handler.js","sourceRoot":"","sources":["../src/api-error-handler.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,QAAS,SAAQ,KAAK;IACxB,MAAM,CAAiB;IACvB,WAAW,CAAS;IAI7B,YAAY,IAA6B,EAAE,IAAqB;QAC9D,MAAM,OAAO,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QACtE,MAAM,MAAM,GAAG,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC;QAC/D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;CACF;AAED,SAAS,aAAa,CAAC,MAAc;IACnC,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,GAAG;YACN,OAAO,aAAa,CAAC;QACvB,KAAK,GAAG;YACN,OAAO,cAAc,CAAC;QACxB,KAAK,GAAG;YACN,OAAO,WAAW,CAAC;QACrB,KAAK,GAAG;YACN,OAAO,WAAW,CAAC;QACrB,KAAK,GAAG;YACN,OAAO,UAAU,CAAC;QACpB,KAAK,GAAG;YACN,OAAO,uBAAuB,CAAC;QACjC;YACE,OAAO,eAAe,CAAC;IAC3B,CAAC;AACH,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @see https://stackoverflow.com/a/4835406/3786294
|
|
3
3
|
*/
|
|
4
|
-
export declare function escapeHtml(text: string, options?: {
|
|
4
|
+
export declare function escapeHtml(text: string | undefined, options?: {
|
|
5
5
|
newLinesToBr?: boolean;
|
|
6
6
|
}): string;
|
|
7
7
|
export declare function decodeHtmlEntities(str: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-helpers.js","sourceRoot":"","sources":["../../src/html-helpers/html-helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,YAAY,GAAG;IACnB,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,QAAQ;CACd,CAAC;AAEF,MAAM,UAAU,UAAU,
|
|
1
|
+
{"version":3,"file":"html-helpers.js","sourceRoot":"","sources":["../../src/html-helpers/html-helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,YAAY,GAAG;IACnB,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,QAAQ;CACd,CAAC;AAEF,MAAM,UAAU,UAAU,CACxB,IAAwB,EACxB,UAAsC,EAAE;IAExC,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IACrB,IAAI,GAAG,GAAG,IAAI,CAAC;IACf,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,CAA8B,CAAC,CAAC,CAAC;IACnF,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;QACzB,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC5C,MAAM,QAAQ,GAAiC;QAC7C,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,GAAG;QACZ,QAAQ,EAA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C,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;IACtC,CAAC,QAAQ,GAAG,KAAK,IAAI,EAAE;IACvB,IAAI,cAAc,IAAI,GAAG,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;QACnD,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,kBAAkB,CAAC,GAAG,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,IAAY,EAAE,GAAW;IAC7D,MAAM,KAAK,GACT,wLAAwL,CAAC;IAC3L,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,EAAE,CAAC,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO,IAAI,CAAC,OAAO,CAAC,8CAA8C,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;QACpF,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,wBAAwB,CAAC;AACvC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC;AACtC,cAAc,uCAAuC,CAAC;AACtD,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC;AACtC,cAAc,uCAAuC,CAAC;AACtD,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC"}
|
package/package.json
CHANGED
|
@@ -8,7 +8,50 @@ import type {
|
|
|
8
8
|
SiteIds,
|
|
9
9
|
ThemeConf,
|
|
10
10
|
} from "@paroicms/public-anywhere-lib";
|
|
11
|
-
import type
|
|
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;
|
|
@@ -35,7 +78,7 @@ export interface BackendPluginInitService {
|
|
|
35
78
|
registerHook(hookName: string, handler: BackendHookHandler, options?: { unique?: boolean }): void;
|
|
36
79
|
setPublicApiHandler(handler: PublicApiHandler): void;
|
|
37
80
|
addHeadTag(...htmlTags: string[]): void;
|
|
38
|
-
|
|
81
|
+
configuration: PluginConfiguration;
|
|
39
82
|
pluginAssetsUrl: string;
|
|
40
83
|
}
|
|
41
84
|
|
|
@@ -55,8 +98,7 @@ export type PluginLiquidFilterHandler = (
|
|
|
55
98
|
|
|
56
99
|
export type PublicApiHandler = (
|
|
57
100
|
service: BackendPluginRenderService,
|
|
58
|
-
|
|
59
|
-
res: Response,
|
|
101
|
+
httpContext: PaHttpContext,
|
|
60
102
|
relativePath: string,
|
|
61
103
|
) => Promise<void> | void;
|
|
62
104
|
|
|
@@ -75,7 +117,7 @@ export interface BackendPluginService {
|
|
|
75
117
|
validateRecaptchaResponse: (gRecaptchaResponse: string | undefined) => Promise<boolean>;
|
|
76
118
|
sendMail: ({ subject, html, replyTo, to }: MailData) => Promise<void>;
|
|
77
119
|
executeHook<T = unknown>(hookName: string, params?: any): T[];
|
|
78
|
-
|
|
120
|
+
configuration: PluginConfiguration;
|
|
79
121
|
pluginAssetsUrl: string;
|
|
80
122
|
registerNewSite: (options: NewSiteOptions) => Promise<Readonly<SiteConf>>;
|
|
81
123
|
/** This is the connector of the running instance of ParoiCMS. */
|
|
@@ -94,22 +136,24 @@ export interface BackendPluginRenderService extends BackendPluginService {
|
|
|
94
136
|
fieldName: string;
|
|
95
137
|
language?: string;
|
|
96
138
|
}) => Promise<FieldValue | undefined>;
|
|
97
|
-
renderChildPartials(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
}
|
|
@@ -138,13 +182,14 @@ export interface FieldPreprocessorOptions {
|
|
|
138
182
|
outputType?: "plainText";
|
|
139
183
|
}
|
|
140
184
|
|
|
141
|
-
export interface
|
|
142
|
-
[pluginName: string]:
|
|
185
|
+
export interface PluginConfigurations {
|
|
186
|
+
[pluginName: string]: PluginConfiguration;
|
|
143
187
|
}
|
|
144
188
|
|
|
145
|
-
export interface
|
|
189
|
+
export interface PluginConfiguration {
|
|
146
190
|
[key: string]: unknown;
|
|
147
191
|
backOffice?: Obj;
|
|
192
|
+
googleRecaptchaKey?: string;
|
|
148
193
|
}
|
|
149
194
|
|
|
150
195
|
export interface MailData {
|