@paroicms/public-server-lib 0.50.2 → 0.50.4

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/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export type * from "../typeonly/site-schema-json-types.d.ts";
4
4
  export type * from "../typeonly/theme-json-types.d.ts";
5
5
  export type * from "../types/backend-plugin-types.d.ts";
6
6
  export type * from "../types/load-descriptor-types.d.ts";
7
+ export type * from "../types/template-payload.types.d.ts";
7
8
  export * from "./api-error-handler.js";
8
9
  export * from "./html-helpers.js";
9
10
  export * from "./load-descriptors.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,uCAAuC,CAAC;AACtD,cAAc,kBAAkB,CAAC;AACjC,cAAc,iCAAiC,CAAC;AAChD,cAAc,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,uCAAuC,CAAC;AACtD,cAAc,kBAAkB,CAAC;AACjC,cAAc,iCAAiC,CAAC;AAChD,cAAc,yBAAyB,CAAC"}
@@ -1,13 +1,12 @@
1
1
  import type { DocumentsLoadDescriptor, ListBaseDescriptor, LoadDescriptor, OneDocumentLoadDescriptor } from "../types/load-descriptor-types.js";
2
- declare const loadDescriptorSymbol: unique symbol;
3
- export interface WithLoadDescriptor<T extends LoadDescriptor = LoadDescriptor> {
4
- [loadDescriptorSymbol]: T;
2
+ export interface WithLoadDescriptor {
3
+ __notARealProperty__: "__load_descriptor__";
5
4
  }
6
5
  export interface WithOneDocumentLoadDescriptor {
7
- [loadDescriptorSymbol]: OneDocumentLoadDescriptor;
6
+ __notARealProperty__: "__one_document_descriptor__";
8
7
  }
9
8
  export interface WithDocumentsLoadDescriptor {
10
- [loadDescriptorSymbol]: DocumentsLoadDescriptor;
9
+ __notARealProperty__: "__documents_descriptor__";
11
10
  }
12
11
  export declare function assignLoadDescriptor<T>(val: T, loadDescriptor: OneDocumentLoadDescriptor): T & WithOneDocumentLoadDescriptor;
13
12
  export declare function assignLoadDescriptor<T>(val: T, loadDescriptor: DocumentsLoadDescriptor): T & WithDocumentsLoadDescriptor;
@@ -16,4 +15,3 @@ export declare function extractLoadDescriptor(val: unknown): LoadDescriptor | un
16
15
  export declare function extractOneDocumentLoadDescriptor(val: unknown): OneDocumentLoadDescriptor | undefined;
17
16
  export declare function extractDocumentsLoadDescriptor(val: unknown): DocumentsLoadDescriptor | undefined;
18
17
  export declare function mergeListDescriptor<T extends ListBaseDescriptor>(base: T, newValues: ListBaseDescriptor): T;
19
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paroicms/public-server-lib",
3
- "version": "0.50.2",
3
+ "version": "0.50.4",
4
4
  "description": "Common utilitaries for paroicms plugins (backend side).",
5
5
  "author": "Paroi Team",
6
6
  "repository": {
@@ -22,9 +22,9 @@
22
22
  "dev": "tsc --watch --preserveWatchOutput"
23
23
  },
24
24
  "dependencies": {
25
- "@paroicms/internal-anywhere-lib": "1.37.1",
26
- "@paroicms/public-anywhere-lib": "0.41.1",
27
- "@paroicms/script-lib": "0.3.13",
25
+ "@paroicms/internal-anywhere-lib": "1.37.3",
26
+ "@paroicms/public-anywhere-lib": "0.41.3",
27
+ "@paroicms/script-lib": "0.3.15",
28
28
  "@typeonly/validator": "~1.1.2",
29
29
  "arktype": "~2.1.29"
30
30
  },
@@ -33,7 +33,7 @@
33
33
  "rimraf": "~6.1.2",
34
34
  "typeonly": "~1.1.3",
35
35
  "typescript": "~5.9.3",
36
- "vitest": "~4.0.16"
36
+ "vitest": "~4.0.17"
37
37
  },
38
38
  "files": [
39
39
  "dist",
@@ -18,6 +18,7 @@ import type {
18
18
  } from "@paroicms/public-anywhere-lib";
19
19
  import type Stream from "node:stream";
20
20
  import type { DocumentsLoadDescriptor } from "./load-descriptor-types.d.ts";
21
+ import type { TpDocPayload } from "./template-payload.types.d.ts";
21
22
 
22
23
  export interface PaHttpContext {
23
24
  req: PaHttpRequest;
@@ -167,6 +168,8 @@ export type PluginSetLiquidTagHandler = (
167
168
  positionedParameters: unknown[];
168
169
  namedParameters: { [key: string]: unknown };
169
170
  variableName: string;
171
+ /** The document currently being rendered. May be undefined for detached documents. */
172
+ document: PluginRenderedDocument | undefined;
170
173
  },
171
174
  ) => Generator<unknown, unknown, unknown>;
172
175
 
@@ -175,9 +178,26 @@ export type PluginOutLiquidTagHandler = (
175
178
  options: {
176
179
  positionedParameters: unknown[];
177
180
  namedParameters: { [key: string]: unknown };
181
+ /** The document currently being rendered. May be undefined for detached documents. */
182
+ document: PluginRenderedDocument | undefined;
178
183
  },
179
184
  ) => string | Promise<string>;
180
185
 
186
+ export interface PublicDocumentBase {
187
+ id: string;
188
+ typeName: string;
189
+ nodeId: string;
190
+ language: string;
191
+ relativeId: string;
192
+ title?: string;
193
+ slug?: string;
194
+ publishDate: string;
195
+ }
196
+
197
+ export interface PluginRenderedDocument extends PublicDocumentBase {
198
+ url: string;
199
+ }
200
+
181
201
  export type PublicApiHandler = (
182
202
  service: BackendPluginService,
183
203
  httpContext: PaHttpContext,
@@ -244,13 +264,13 @@ export interface PluginRenderingService {
244
264
  homeUrl: string;
245
265
  setRenderState(key: string, value: any): void;
246
266
 
247
- loadDocuments(loadDescriptor: DocumentsLoadDescriptor): Promise<TpDocument[]>;
267
+ loadDocuments(loadDescriptor: DocumentsLoadDescriptor): Promise<LiquidPayload<TpDocPayload>[]>;
248
268
  loadDocuments(
249
269
  loadDescriptor: DocumentsLoadDescriptor,
250
270
  options: { withTotal: true },
251
- ): Promise<{ documents: TpDocument[]; total: number }>;
271
+ ): Promise<{ documents: LiquidPayload<TpDocPayload>[]; total: number }>;
252
272
 
253
- renderDocument(templateName: string, doc: TpDocument): Promise<string>;
273
+ renderDocument(templateName: string, doc: LiquidPayload<TpDocPayload>): Promise<string>;
254
274
 
255
275
  serve(
256
276
  httpContext: PaHttpContext,
@@ -275,22 +295,13 @@ export interface PluginRenderingService {
275
295
  close(): Promise<void>;
276
296
  }
277
297
 
278
- /** This type is a stub for `TpDocPayload`. It represents a full `doc` payload for LiquidJS templates. */
279
- export interface TpDocument {
280
- kind: "routingDocument" | "regularDocument";
281
- id: string;
282
- }
298
+ export type LiquidPayload<T> = {
299
+ /** This is not true at runtime, it's a way to keep the typing. */
300
+ __nestedPayloadType__: T;
301
+ };
283
302
 
284
- export interface PublicDocument {
285
- id: string;
303
+ export interface PublicDocument extends PublicDocumentBase {
286
304
  getUrl: (options?: { absoluteUrl?: boolean }) => Promise<string>;
287
- typeName: string;
288
- nodeId: string;
289
- language: string;
290
- relativeId: string;
291
- title?: string;
292
- slug?: string;
293
- publishDate: string;
294
305
  }
295
306
 
296
307
  export interface PluginStaticConfigurations {
@@ -0,0 +1,285 @@
1
+ export type TpTemplatePayload = TpDetachedTemplatePayload | TpRegularTemplatePayload;
2
+
3
+ export interface TpDetachedTemplatePayload {
4
+ site: TpSitePayload;
5
+ doc: TpDetachedDocPayload;
6
+ }
7
+
8
+ export interface TpRegularTemplatePayload {
9
+ site: TpSitePayload;
10
+ doc: TpDocPayload;
11
+ }
12
+
13
+ export interface TpHomePayload {
14
+ baseUrl: string;
15
+ url: string;
16
+ id: string;
17
+ routing: TpRoutingClusterNode;
18
+ language: string;
19
+ languageLabel: string;
20
+ }
21
+
22
+ export interface TpSitePayload {
23
+ kind: "site";
24
+ fqdn: string;
25
+ /** @deprecated Use `home.baseUrl` instead */
26
+ url: string;
27
+ assetsUrl: string;
28
+ field: { [fieldName: string]: unknown };
29
+ home: TpHomePayload;
30
+ /** @deprecated Use `home.language` instead */
31
+ language: string;
32
+ /** @deprecated Use `home.languageLabel` instead */
33
+ languageLabel: string;
34
+
35
+ /** @deprecated */
36
+ fields: { [fieldName: string]: unknown };
37
+ /** @deprecated */
38
+ configuration: unknown;
39
+ /** @deprecated */
40
+ recaptchaKey?: string;
41
+ }
42
+
43
+ export interface TpClusterPayload {
44
+ kind: "cluster";
45
+ routing: TpRoutingClusterNode;
46
+ /** Lazy loaded */
47
+ parentCluster: TpClusterPayload | undefined;
48
+ }
49
+
50
+ export interface TpRoutingClusterNode extends TpOneDocumentLoadDescriptor {
51
+ id: string;
52
+ children: TpDocumentsLoadDescriptor | undefined;
53
+ /**
54
+ * TS forces us to declare all the types here but values will be only of type
55
+ * `TpRoutingClusterNode`.
56
+ */
57
+ [typeName: string]: TpRoutingClusterNode | TpDocumentsLoadDescriptor | string | undefined;
58
+ }
59
+
60
+ export interface TpDetachedDocPayload {
61
+ kind: "detached";
62
+ typeName?: string;
63
+ language?: string;
64
+ languageLabel?: string;
65
+ translations: TpDocTranslation[];
66
+ id?: string;
67
+ title?: string;
68
+ urlQuery: TpUrlQuery | undefined;
69
+ /** Lazy loaded */
70
+ cluster: TpClusterPayload;
71
+ }
72
+
73
+ export interface TpDocValues {
74
+ type: string;
75
+ nodeId: string;
76
+ language: string;
77
+ relativeId: string;
78
+ title?: string;
79
+ slug?: string;
80
+ /**
81
+ * ISO 8601 formatted date string. For preview document, it fallbacks to the current date
82
+ */
83
+ publishDate: string;
84
+ metaDescription?: string;
85
+ metaKeywords?: string;
86
+ }
87
+
88
+ export interface TpDocPayload extends TpDocValues {
89
+ kind: "routingDocument" | "regularDocument" | "term";
90
+ /** @deprecated */
91
+ leafType: string;
92
+ /** @deprecated */
93
+ leafId: string;
94
+ id: string;
95
+ languageLabel: string;
96
+ url: string;
97
+ excerpt?: string;
98
+ list: {
99
+ [listName: string]: TpPart[];
100
+ };
101
+ listSize: {
102
+ [listName: string]: number;
103
+ };
104
+ /** @deprecated */
105
+ defaultImageId?: string;
106
+ defaultImage?: TpImage;
107
+ /** @deprecated */
108
+ featuredImageId?: string;
109
+ featuredImage?: TpImage;
110
+ field: TpFieldValues;
111
+ /** @deprecated */
112
+ fields: TpFieldValues;
113
+ translations: TpDocTranslation[];
114
+ /** deprecated */
115
+ labeling: undefined;
116
+ /** deprecated */
117
+ singleLabeling: undefined;
118
+ /** deprecated */
119
+ flaggedWith: undefined;
120
+ /** deprecated */
121
+ flaggedWithOne: undefined;
122
+ og: TpOgValues;
123
+ breadcrumb: TpBreadcrumbItem[];
124
+ siblings: TpSiblingDocuments;
125
+ typeLabel: string;
126
+ urlQuery: TpUrlQuery | undefined;
127
+ frontendAppPath: string | undefined;
128
+ /**
129
+ * Child routing document identifiers. Available on routing document only.
130
+ */
131
+ routing?: TpRoutingClusterNode;
132
+ /** @deprecated Use `routing` instead */
133
+ routingIds?: TpRoutingClusterNode;
134
+ /** Lazy loaded */
135
+ cluster: TpClusterPayload;
136
+ }
137
+
138
+ export interface TpDocTranslation extends TpOneDocumentLoadDescriptor {
139
+ language: string;
140
+ languageLabel: string;
141
+ active: boolean;
142
+ url: string;
143
+ }
144
+
145
+ export interface TpTerm extends TpOneDocumentLoadDescriptor {
146
+ inRightLanguage: boolean;
147
+ language: string;
148
+ languageLabel: string;
149
+ nodeId: string;
150
+ /**
151
+ * The term title is the term document title.
152
+ */
153
+ title?: string;
154
+ url?: string;
155
+ }
156
+
157
+ export interface TpPartValues {
158
+ type: string;
159
+ relativeId: string;
160
+ number: number;
161
+ numberOfType: number;
162
+ inRightLanguage: boolean;
163
+ language: string;
164
+ languageLabel: string;
165
+ nodeId: string;
166
+ publishDate: string;
167
+ }
168
+
169
+ export interface TpPart extends TpPartValues {
170
+ kind: "part";
171
+ /** @deprecated */
172
+ leafId: string;
173
+ /** @deprecated */
174
+ leafType: string;
175
+ id: string;
176
+ /** @deprecated */
177
+ num: number;
178
+ /** @deprecated */
179
+ defaultImageId?: string;
180
+ defaultImage?: TpImage;
181
+ /** @deprecated */
182
+ featuredImageId?: string;
183
+ featuredImage?: TpImage;
184
+ field: TpFieldValues;
185
+ /** @deprecated */
186
+ fields: TpFieldValues;
187
+ typeLabel: string;
188
+ parts?: TpPart[];
189
+ }
190
+
191
+ export interface TpOgValues {
192
+ url: string;
193
+ type?: string;
194
+ image?: TpImageVariant;
195
+ title?: string;
196
+ siteName?: string;
197
+ description?: string;
198
+ locale?: string;
199
+ }
200
+
201
+ export interface TpBreadcrumbItem extends TpOneDocumentLoadDescriptor {
202
+ id: string;
203
+ title?: string;
204
+ url?: string;
205
+ }
206
+
207
+ export interface TpSiblingDocuments {
208
+ previous?: TpOneDocumentLoadDescriptor;
209
+ next?: TpOneDocumentLoadDescriptor;
210
+ }
211
+
212
+ export interface TpFieldValues {
213
+ [fieldName: string]: string | number | boolean | object | undefined;
214
+ }
215
+
216
+ export type TpMedia = TpFile | TpImage;
217
+ export type TpSourceMedia = TpFile | TpSourceImage;
218
+ export type TpImage = TpSourceImage | TpImageVariant;
219
+
220
+ export interface TpMediaBase {
221
+ mediaId: string;
222
+ url: string;
223
+ mediaType: string;
224
+ }
225
+
226
+ export interface TpSourceBase {
227
+ isSource: true;
228
+ weightB: number;
229
+ originalName?: string;
230
+ attachedData?: TpAttachedData;
231
+ }
232
+
233
+ export interface TpAttachedData {
234
+ [propertyName: string]: string | number | boolean | object | undefined;
235
+ caption?: string;
236
+ }
237
+
238
+ export interface TpImageBase {
239
+ kind: "image";
240
+ rawWidth: number;
241
+ rawHeight: number;
242
+ /** Rendered width. Its value is equals to `round(rawWidth / pixelRatio)`. */
243
+ width: number;
244
+ /** Rendered height. Its value is equals to `round(rawHeight / pixelRatio)`. */
245
+ height: number;
246
+ pixelRatio: number;
247
+ }
248
+
249
+ export interface TpFile extends TpMediaBase, TpSourceBase {
250
+ kind: "file";
251
+ }
252
+
253
+ export interface TpSourceImage extends TpMediaBase, TpSourceBase, TpImageBase {}
254
+
255
+ export interface TpImageVariant extends TpMediaBase, TpImageBase {
256
+ isSource: false;
257
+ }
258
+
259
+ export interface TpUrlQuery {
260
+ [key: string]: undefined | string | TpUrlQuery | (string | TpUrlQuery)[];
261
+ }
262
+
263
+ /**
264
+ * This type represents a load descriptor for multiple documents. The Liquid template can't access
265
+ * any property of this type. But it can use it to request loading of multiple documents, using the
266
+ * `docs` function, for example:
267
+ * ```
268
+ * {% set children = docs(doc.routing.children) %}
269
+ * ```
270
+ */
271
+ export interface TpDocumentsLoadDescriptor {
272
+ __notARealProperty__: "__documents_descriptor__";
273
+ }
274
+
275
+ /**
276
+ * This type represents a load descriptor for a single document. The Liquid template can't access
277
+ * any property of this type. But it can use it to request loading of a single document, using the
278
+ * `doc` function, for example:
279
+ * ```
280
+ * {% set next = doc(doc.siblings.next) %}
281
+ * ```
282
+ */
283
+ export interface TpOneDocumentLoadDescriptor {
284
+ __notARealProperty__: "__one_document_descriptor__";
285
+ }