@paroicms/public-server-lib 0.8.0 → 0.9.1

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.8.0",
3
+ "version": "0.9.1",
4
4
  "description": "Common utilitaries for paroicms plugins (backend side).",
5
5
  "author": "Paroi Team",
6
6
  "repository": {
@@ -27,11 +27,12 @@
27
27
  "vitest": "~1.6.0"
28
28
  },
29
29
  "files": [
30
- "dist"
30
+ "dist",
31
+ "types"
31
32
  ],
32
33
  "dependencies": {
33
34
  "@paroi/data-formatters-lib": "~0.4.0",
34
- "@paroicms/internal-anywhere-lib": "1.18.0",
35
- "@paroicms/public-anywhere-lib": "0.3.0"
35
+ "@paroicms/internal-anywhere-lib": "1.18.1",
36
+ "@paroicms/public-anywhere-lib": "0.4.0"
36
37
  }
37
38
  }
@@ -0,0 +1,55 @@
1
+ import type { ImageSize } from "@paroicms/public-anywhere-lib";
2
+ import type { Request, Response } from "express";
3
+ import type { AppLog, PluginSiteContext } from "./plugin-site-context-types";
4
+
5
+ export interface ParoiCmsPlugin {
6
+ version: string;
7
+ siteInit?: (api: PluginInitApi) => void | Promise<void>;
8
+ }
9
+
10
+ export interface PluginInitApi {
11
+ siteLog: AppLog;
12
+ registerLiquidFilter(
13
+ filterName: string,
14
+ handler: (value: unknown) => string | Promise<string>,
15
+ options?: { raw?: boolean },
16
+ ): void;
17
+ registerFieldPreprocessor(dataType: string, handler: FieldPreprocessor): void;
18
+ setPublicAssetsDirectory(directory: string): void;
19
+ setBoAssetsDirectory(directory: string): void;
20
+ setPublicApiHandler(handler: PublicApiHandler): void;
21
+ addHeadTag(...htmlTags: string[]): void;
22
+ declareCommonSchemaLibrary(directory: string): void;
23
+ }
24
+
25
+ export type PublicApiHandler = (
26
+ pluginSiteContext: PluginSiteContext,
27
+ req: Request,
28
+ res: Response,
29
+ relativePath: string,
30
+ ) => Promise<void> | void;
31
+
32
+ export type FieldPreprocessor = (
33
+ ctx: FieldPreprocessorContext,
34
+ value: unknown,
35
+ options: FieldPreprocessorOptions,
36
+ ) => unknown | Promise<unknown>;
37
+
38
+ export interface FieldPreprocessorContext {
39
+ siteContext: PluginSiteContext;
40
+ useImage: UseImage;
41
+ }
42
+
43
+ export type UseImage = (options: { imageUid: string; size: ImageSize }) => Promise<UsedImage>;
44
+
45
+ export interface UsedImage {
46
+ url: string;
47
+ width: number;
48
+ height: number;
49
+ mediaType: string;
50
+ }
51
+
52
+ export interface FieldPreprocessorOptions {
53
+ absoluteUrls?: boolean;
54
+ outputType?: "plainText";
55
+ }
@@ -0,0 +1,41 @@
1
+ import type { ScSiteSchema, ThemeConf } from "@paroicms/public-anywhere-lib";
2
+
3
+ export interface PluginSiteContext {
4
+ fqdn: string;
5
+ siteUrl: string;
6
+ siteSchema: ScSiteSchema;
7
+ themeConf: ThemeConf;
8
+ siteLog: AppLog;
9
+ validateRecaptchaResponse: (gRecaptchaResponse: string | undefined) => Promise<boolean>;
10
+ getSiteFieldValue: (options: {
11
+ fieldName: string;
12
+ language?: string;
13
+ }) => Promise<unknown | undefined>;
14
+ sendMail: (
15
+ { subject, html, replyTo, to }: MailData,
16
+ {
17
+ appLog,
18
+ }: {
19
+ appLog: AppLog;
20
+ },
21
+ ) => Promise<void>;
22
+ }
23
+
24
+ export interface MailData {
25
+ subject: string;
26
+ html: string;
27
+ replyTo?: ReplyTo;
28
+ to: string;
29
+ }
30
+
31
+ export interface ReplyTo {
32
+ email: string;
33
+ name: string;
34
+ }
35
+
36
+ export interface AppLog {
37
+ error(...messages: any[]): void;
38
+ warn(...messages: any[]): void;
39
+ info(...messages: any[]): void;
40
+ debug(...messages: any[]): void;
41
+ }