@qite/tide-client 2.0.24 → 2.0.25

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.
@@ -0,0 +1,19 @@
1
+ import { WebTemplate, WebTemplateField } from "../types/web/web-template";
2
+ export interface GenerateTemplateTypesOptions {
3
+ /** Module the generated file augments and imports from. Default "@qite/tide-client". */
4
+ moduleName?: string;
5
+ /** First line of the file, e.g. where the templates came from. */
6
+ header?: string;
7
+ }
8
+ /**
9
+ * Newtonsoft's CamelCasePropertyNamesContractResolver rule, which Tide's API applies
10
+ * to every content key: "General" -> "general", "SEOTitle" -> "seoTitle", "ProductCarddata" -> "productCarddata".
11
+ */
12
+ export declare const toTideCamelCase: (name: string) => string;
13
+ /** The published value type of a field: mirrors Tide's PublishedContentItemFactory per data type. */
14
+ export declare const fieldValueType: (field: WebTemplateField) => string;
15
+ /** Builds a .d.ts that types every template's content and registers it in TideTemplateMap. */
16
+ export declare const generateTemplateTypes: (
17
+ templates: WebTemplate[],
18
+ options?: GenerateTemplateTypesOptions
19
+ ) => string;
@@ -2,3 +2,5 @@ export * from "./geo-json-point";
2
2
  export * from "./mail";
3
3
  export * from "./published-content-item";
4
4
  export * from "./published-content";
5
+ export * from "./published-field-values";
6
+ export * from "./template-content";
@@ -0,0 +1,20 @@
1
+ /** An Image field, or one entry of an ImageList field, as Tide publishes it. */
2
+ export interface PublishedImage {
3
+ url?: string | null;
4
+ title?: string | null;
5
+ altText?: string | null;
6
+ order?: number | null;
7
+ type?: number | null;
8
+ copyright?: string | null;
9
+ }
10
+ /** An Entity field (or one entry of a MultipleEntities field). */
11
+ export interface PublishedEntity {
12
+ key: number;
13
+ value: string | null;
14
+ localizedValue?: string | null;
15
+ /** The template field's custom editor, e.g. "Product", "Country", "Airport". */
16
+ entityType: string | null;
17
+ code?: string | null;
18
+ /** Airline and Airport entities carry their IATA code instead of `code`. */
19
+ iata?: string | null;
20
+ }
@@ -0,0 +1,47 @@
1
+ import { PublishedContentItem } from "./published-content-item";
2
+ /**
3
+ * Template name -> content type. Empty here: a project fills it by running
4
+ * `tide-client generate-types`, whose output augments this interface
5
+ * (`declare module "@qite/tide-client" { interface TideTemplateMap { … } }`).
6
+ */
7
+ export interface TideTemplateMap {}
8
+ declare type HasTemplates = [keyof TideTemplateMap] extends [never]
9
+ ? false
10
+ : true;
11
+ /** The project's template names, or `string` when no types were generated. */
12
+ export declare type TideTemplateName = HasTemplates extends true
13
+ ? Extract<keyof TideTemplateMap, string>
14
+ : string;
15
+ declare type UntypedContent = {
16
+ [group: string]:
17
+ | {
18
+ [field: string]: unknown;
19
+ }
20
+ | undefined;
21
+ };
22
+ /** The `content` of an item of this template. */
23
+ export declare type TideTemplateContent<T extends string> =
24
+ T extends keyof TideTemplateMap ? TideTemplateMap[T] : UntypedContent;
25
+ /** A published item known to be of template `T`. */
26
+ export declare type TideTemplateItem<T extends string> =
27
+ PublishedContentItem & {
28
+ templateName: T;
29
+ content: TideTemplateContent<T>;
30
+ };
31
+ /** The groups of template `T`. */
32
+ export declare type TideTemplateGroup<T extends string> = Extract<
33
+ keyof TideTemplateContent<T>,
34
+ string
35
+ >;
36
+ /** The fields of group `G` of template `T`. */
37
+ export declare type TideTemplateFieldName<
38
+ T extends string,
39
+ G extends TideTemplateGroup<T>
40
+ > = Extract<keyof NonNullable<TideTemplateContent<T>[G]>, string>;
41
+ /** The published value of field `F` in group `G` of template `T`. */
42
+ export declare type TideTemplateFieldValue<
43
+ T extends string,
44
+ G extends TideTemplateGroup<T>,
45
+ F extends TideTemplateFieldName<T, G>
46
+ > = NonNullable<TideTemplateContent<T>[G]>[F];
47
+ export {};
@@ -24,3 +24,4 @@ export * from "./web-contact";
24
24
  export * from "./web-form";
25
25
  export * from "./web-opportunity-request";
26
26
  export * from "./website-configuration";
27
+ export * from "./web-template";
@@ -0,0 +1,34 @@
1
+ /** Tide's `DataType` enum: decides the shape a template field has in the published content. */
2
+ export declare enum TideFieldDataType {
3
+ Text = 0,
4
+ Number = 1,
5
+ Date = 2,
6
+ Bool = 3,
7
+ Image = 4,
8
+ Entity = 5,
9
+ Url = 6,
10
+ Path = 7,
11
+ ExtraInformation = 8,
12
+ Geographical = 9,
13
+ ContentItem = 10,
14
+ ImageList = 11,
15
+ OptionList = 12,
16
+ Time = 13,
17
+ MultipleEntities = 14,
18
+ }
19
+ export interface WebTemplateField {
20
+ /** The field's system name (published as its camel-cased key). */
21
+ name: string | null;
22
+ dataType: TideFieldDataType;
23
+ customEditor: string | null;
24
+ }
25
+ export interface WebTemplateFieldGroup {
26
+ /** The group's system name (published as its camel-cased key). */
27
+ name: string | null;
28
+ fields: WebTemplateField[];
29
+ }
30
+ /** api/web/template: a CMS template with its field groups. */
31
+ export interface WebTemplate {
32
+ templateName: string;
33
+ fieldGroups: WebTemplateFieldGroup[];
34
+ }
@@ -0,0 +1,33 @@
1
+ import {
2
+ PublishedContentItem,
3
+ TideTemplateFieldName,
4
+ TideTemplateFieldValue,
5
+ TideTemplateGroup,
6
+ TideTemplateItem,
7
+ TideTemplateName,
8
+ } from "../types";
9
+ /** Narrows an item to template `templateName`, so its content is typed (after `tide-client generate-types`). */
10
+ export declare function isTemplate<T extends TideTemplateName>(
11
+ item: PublishedContentItem | null | undefined,
12
+ templateName: T
13
+ ): item is TideTemplateItem<T>;
14
+ /** The item as template `templateName`, or undefined when it is another template. */
15
+ export declare function asTemplate<T extends TideTemplateName>(
16
+ item: PublishedContentItem | null | undefined,
17
+ templateName: T
18
+ ): TideTemplateItem<T> | undefined;
19
+ /** The direct children of `item` that are of template `templateName`. */
20
+ export declare function childrenOfTemplate<T extends TideTemplateName>(
21
+ item: PublishedContentItem | null | undefined,
22
+ templateName: T
23
+ ): TideTemplateItem<T>[];
24
+ /** A typed field value: `getTemplateField(asTemplate(item, "Page"), "general", "title")`. */
25
+ export declare function getTemplateField<
26
+ T extends TideTemplateName,
27
+ G extends TideTemplateGroup<T>,
28
+ F extends TideTemplateFieldName<T, G>
29
+ >(
30
+ item: TideTemplateItem<T> | null | undefined,
31
+ group: G,
32
+ field: F
33
+ ): TideTemplateFieldValue<T, G, F> | undefined;
@@ -0,0 +1,12 @@
1
+ import { TideClientConfig, WebTemplate } from "../types";
2
+ /**
3
+ * api/web/template
4
+ * Gets every CMS template with its field groups and fields (system names, data types).
5
+ * @param config
6
+ * @param signal
7
+ * @returns OK if succeeded.
8
+ */
9
+ export declare const getTemplates: (
10
+ config: TideClientConfig,
11
+ signal?: AbortSignal | undefined
12
+ ) => Promise<WebTemplate[]>;
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "@qite/tide-client",
3
- "version": "2.0.24",
3
+ "version": "2.0.25",
4
4
  "description": "Frontend client for Tide",
5
5
  "main": "build/index.js",
6
+ "bin": {
7
+ "tide-client": "build/cli.js"
8
+ },
6
9
  "scripts": {
7
10
  "build": "rollup -c",
8
11
  "tsc": "tsc --noEmit",
@@ -33,6 +36,7 @@
33
36
  "@rollup/plugin-node-resolve": "^13.0.0",
34
37
  "@types/jest": "^26.0.23",
35
38
  "@types/moment": "^2.13.0",
39
+ "@types/node": "^15.3.0",
36
40
  "dotenv": "^9.0.2",
37
41
  "jest": "^26.6.3",
38
42
  "jest-fetch-mock": "^3.0.3",