@unchainedshop/cockpit-api 1.0.33 → 2.1.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/README.md +330 -65
- package/dist/client.d.ts +72 -0
- package/dist/client.js +101 -0
- package/dist/cockpit-logger.d.ts +8 -10
- package/dist/cockpit-logger.js +7 -21
- package/dist/core/cache.d.ts +19 -0
- package/dist/core/cache.js +32 -0
- package/dist/core/config.d.ts +45 -0
- package/dist/core/config.js +32 -0
- package/dist/core/http.d.ts +34 -0
- package/dist/core/http.js +98 -0
- package/dist/core/index.d.ts +14 -0
- package/dist/core/index.js +10 -0
- package/dist/core/locale.d.ts +11 -0
- package/dist/core/locale.js +17 -0
- package/dist/core/query-string.d.ts +18 -0
- package/dist/core/query-string.js +20 -0
- package/dist/core/url-builder.d.ts +22 -0
- package/dist/core/url-builder.js +35 -0
- package/dist/core/validation.d.ts +13 -0
- package/dist/core/validation.js +22 -0
- package/dist/fetch/client.d.ts +85 -0
- package/dist/fetch/client.js +143 -0
- package/dist/fetch/index.d.ts +19 -0
- package/dist/fetch/index.js +18 -0
- package/dist/index.d.ts +28 -2
- package/dist/index.js +13 -3
- package/dist/methods/assets.d.ts +65 -0
- package/dist/methods/assets.js +37 -0
- package/dist/methods/content.d.ts +77 -0
- package/dist/methods/content.js +79 -0
- package/dist/methods/graphql.d.ts +9 -0
- package/dist/methods/graphql.js +13 -0
- package/dist/methods/index.d.ts +22 -0
- package/dist/methods/index.js +12 -0
- package/dist/methods/localize.d.ts +12 -0
- package/dist/methods/localize.js +17 -0
- package/dist/methods/menus.d.ts +42 -0
- package/dist/methods/menus.js +25 -0
- package/dist/methods/pages.d.ts +49 -0
- package/dist/methods/pages.js +34 -0
- package/dist/methods/routes.d.ts +46 -0
- package/dist/methods/routes.js +24 -0
- package/dist/methods/search.d.ts +27 -0
- package/dist/methods/search.js +16 -0
- package/dist/methods/system.d.ts +15 -0
- package/dist/methods/system.js +14 -0
- package/dist/schema/executor.d.ts +67 -0
- package/dist/schema/executor.js +81 -0
- package/dist/schema/index.d.ts +26 -0
- package/dist/schema/index.js +26 -0
- package/dist/schema/schema-builder.d.ts +42 -0
- package/dist/schema/schema-builder.js +77 -0
- package/dist/transformers/asset-path.d.ts +20 -0
- package/dist/transformers/asset-path.js +40 -0
- package/dist/transformers/compose.d.ts +9 -0
- package/dist/transformers/compose.js +14 -0
- package/dist/transformers/image-path.d.ts +28 -0
- package/dist/transformers/image-path.js +60 -0
- package/dist/transformers/index.d.ts +8 -0
- package/dist/transformers/index.js +9 -0
- package/dist/transformers/page-link.d.ts +18 -0
- package/dist/transformers/page-link.js +45 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/route-map.d.ts +12 -0
- package/dist/utils/route-map.js +86 -0
- package/dist/utils/tenant.d.ts +71 -0
- package/dist/utils/tenant.js +88 -0
- package/package.json +50 -8
- package/.github/workflows/npm-publish.yml +0 -33
- package/.nvmrc +0 -1
- package/dist/api.d.ts +0 -70
- package/dist/api.js +0 -303
- package/dist/api.js.map +0 -1
- package/dist/cockpit-logger.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/src/api.ts +0 -350
- package/src/cockpit-logger.ts +0 -24
- package/src/index.ts +0 -3
- package/tsconfig.json +0 -23
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight fetch client for Cockpit CMS
|
|
3
|
+
*
|
|
4
|
+
* Designed for edge/RSC environments where the full CockpitAPI is too heavy.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { createFetchClient } from "@unchainedshop/cockpit-api/fetch";
|
|
9
|
+
*
|
|
10
|
+
* const cockpit = createFetchClient({
|
|
11
|
+
* endpoint: process.env.NEXT_PUBLIC_COCKPIT_ENDPOINT,
|
|
12
|
+
* tenant: "mytenant",
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* const page = await cockpit.pageByRoute("/about", { locale: "en" });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export { createFetchClient } from "./client.ts";
|
|
19
|
+
export type { FetchClient, FetchClientOptions, FetchCacheMode, PageFetchParams, } from "./client.ts";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight fetch client for Cockpit CMS
|
|
3
|
+
*
|
|
4
|
+
* Designed for edge/RSC environments where the full CockpitAPI is too heavy.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { createFetchClient } from "@unchainedshop/cockpit-api/fetch";
|
|
9
|
+
*
|
|
10
|
+
* const cockpit = createFetchClient({
|
|
11
|
+
* endpoint: process.env.NEXT_PUBLIC_COCKPIT_ENDPOINT,
|
|
12
|
+
* tenant: "mytenant",
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* const page = await cockpit.pageByRoute("/about", { locale: "en" });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export { createFetchClient } from "./client.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Cockpit API - TypeScript client for Cockpit CMS
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
export { CockpitAPI } from "./client.ts";
|
|
7
|
+
export type { CockpitAPIClient } from "./client.ts";
|
|
8
|
+
export type { CockpitAPIOptions } from "./core/config.ts";
|
|
9
|
+
export type { CacheManager, CacheOptions } from "./core/cache.ts";
|
|
10
|
+
export { getTenantIds, resolveTenantFromUrl, resolveTenantFromSubdomain, } from "./utils/tenant.ts";
|
|
11
|
+
export type { TenantUrlResult, ResolveTenantFromUrlOptions, ResolveTenantFromSubdomainOptions, } from "./utils/tenant.ts";
|
|
12
|
+
export { generateCmsRouteReplacements, generateCollectionAndSingletonSlugRouteMap, } from "./utils/route-map.ts";
|
|
13
|
+
export type { ResponseTransformer } from "./transformers/image-path.ts";
|
|
14
|
+
export { createImagePathTransformer, identityTransformer, FixImagePaths, } from "./transformers/image-path.ts";
|
|
15
|
+
export { createAssetPathTransformer, createPageLinkTransformer, composeTransformers, } from "./transformers/index.ts";
|
|
16
|
+
export type { MethodContext, ListQueryOptions, ContentItemQueryOptions, ContentListQueryOptions, TreeQueryOptions, AggregateQueryOptions, } from "./methods/content.ts";
|
|
17
|
+
export type { PageByIdOptions, PageByRouteOptions } from "./methods/pages.ts";
|
|
18
|
+
export type { MenuQueryOptions } from "./methods/menus.ts";
|
|
19
|
+
export type { SearchQueryOptions } from "./methods/search.ts";
|
|
20
|
+
export type { LocalizeOptions } from "./methods/localize.ts";
|
|
21
|
+
export type { CockpitContentItem, CockpitNewsItem, CockpitTreeNode, } from "./methods/content.ts";
|
|
22
|
+
export { ImageSizeMode, MimeType } from "./methods/assets.ts";
|
|
23
|
+
export type { CockpitAsset, ImageAssetQueryParams } from "./methods/assets.ts";
|
|
24
|
+
export type { CockpitPageType, CockpitPageMeta, CockpitPageSeo, CockpitLayoutBlock, CockpitPage, } from "./methods/pages.ts";
|
|
25
|
+
export type { CockpitMenuUrl, CockpitMenuLink, CockpitMenu, } from "./methods/menus.ts";
|
|
26
|
+
export type { CockpitRoute, CockpitRoutesResponse, CockpitSitemapEntry, CockpitPreviewConfig, CockpitSettings, } from "./methods/routes.ts";
|
|
27
|
+
export type { CockpitSearchHit, CockpitSearchResult, } from "./methods/search.ts";
|
|
28
|
+
export type { CockpitHealthCheck } from "./methods/system.ts";
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Cockpit API - TypeScript client for Cockpit CMS
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
export { CockpitAPI } from "./client.js";
|
|
7
|
+
export { getTenantIds, resolveTenantFromUrl, resolveTenantFromSubdomain, } from "./utils/tenant.js";
|
|
8
|
+
export { generateCmsRouteReplacements, generateCollectionAndSingletonSlugRouteMap, } from "./utils/route-map.js";
|
|
9
|
+
export { createImagePathTransformer, identityTransformer,
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
11
|
+
FixImagePaths, } from "./transformers/image-path.js";
|
|
12
|
+
export { createAssetPathTransformer, createPageLinkTransformer, composeTransformers, } from "./transformers/index.js";
|
|
13
|
+
export { ImageSizeMode, MimeType } from "./methods/assets.js";
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asset API methods
|
|
3
|
+
*/
|
|
4
|
+
import type { MethodContext } from "./content.ts";
|
|
5
|
+
export interface CockpitAsset {
|
|
6
|
+
_id: string;
|
|
7
|
+
path: string;
|
|
8
|
+
title: string;
|
|
9
|
+
mime: string;
|
|
10
|
+
type: "image" | "video" | "audio" | "document" | "archive" | "code" | "other";
|
|
11
|
+
description?: string;
|
|
12
|
+
tags?: string[];
|
|
13
|
+
size: number;
|
|
14
|
+
colors?: string[] | null;
|
|
15
|
+
width?: number | null;
|
|
16
|
+
height?: number | null;
|
|
17
|
+
_hash: string;
|
|
18
|
+
_created: number;
|
|
19
|
+
_modified: number;
|
|
20
|
+
_cby?: string;
|
|
21
|
+
_mby?: string;
|
|
22
|
+
altText?: string;
|
|
23
|
+
thumbhash?: string;
|
|
24
|
+
folder?: string;
|
|
25
|
+
}
|
|
26
|
+
export declare enum ImageSizeMode {
|
|
27
|
+
Thumbnail = "thumbnail",
|
|
28
|
+
BestFit = "bestFit",
|
|
29
|
+
Resize = "resize",
|
|
30
|
+
FitToWidth = "fitToWidth",
|
|
31
|
+
FitToHeight = "fitToHeight"
|
|
32
|
+
}
|
|
33
|
+
export declare enum MimeType {
|
|
34
|
+
AUTO = "auto",
|
|
35
|
+
GIF = "gif",
|
|
36
|
+
JPEG = "jpeg",
|
|
37
|
+
PNG = "png",
|
|
38
|
+
WEBP = "webp",
|
|
39
|
+
BMP = "bmp"
|
|
40
|
+
}
|
|
41
|
+
export interface ImageAssetQueryParams {
|
|
42
|
+
m?: ImageSizeMode;
|
|
43
|
+
w?: number;
|
|
44
|
+
h?: number;
|
|
45
|
+
q?: number;
|
|
46
|
+
mime?: MimeType;
|
|
47
|
+
re?: number;
|
|
48
|
+
t?: string;
|
|
49
|
+
o?: number;
|
|
50
|
+
}
|
|
51
|
+
export interface AssetMethods {
|
|
52
|
+
assetById<T = CockpitAsset>(assetId: string): Promise<T | null>;
|
|
53
|
+
/**
|
|
54
|
+
* Get a transformed image asset URL.
|
|
55
|
+
*
|
|
56
|
+
* **Important:** The `w` (width) or `h` (height) parameter is required by the API.
|
|
57
|
+
* Without it, the API returns a 400 error.
|
|
58
|
+
*
|
|
59
|
+
* @param assetId - The asset ID
|
|
60
|
+
* @param queryParams - Image transformation parameters (w or h required)
|
|
61
|
+
* @returns URL string to the generated image, or null if not found
|
|
62
|
+
*/
|
|
63
|
+
imageAssetById(assetId: string, queryParams?: ImageAssetQueryParams): Promise<string | null>;
|
|
64
|
+
}
|
|
65
|
+
export declare function createAssetMethods(ctx: MethodContext): AssetMethods;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asset API methods
|
|
3
|
+
*/
|
|
4
|
+
import { requireParam } from "../core/validation.js";
|
|
5
|
+
export var ImageSizeMode;
|
|
6
|
+
(function (ImageSizeMode) {
|
|
7
|
+
ImageSizeMode["Thumbnail"] = "thumbnail";
|
|
8
|
+
ImageSizeMode["BestFit"] = "bestFit";
|
|
9
|
+
ImageSizeMode["Resize"] = "resize";
|
|
10
|
+
ImageSizeMode["FitToWidth"] = "fitToWidth";
|
|
11
|
+
ImageSizeMode["FitToHeight"] = "fitToHeight";
|
|
12
|
+
})(ImageSizeMode || (ImageSizeMode = {}));
|
|
13
|
+
export var MimeType;
|
|
14
|
+
(function (MimeType) {
|
|
15
|
+
MimeType["AUTO"] = "auto";
|
|
16
|
+
MimeType["GIF"] = "gif";
|
|
17
|
+
MimeType["JPEG"] = "jpeg";
|
|
18
|
+
MimeType["PNG"] = "png";
|
|
19
|
+
MimeType["WEBP"] = "webp";
|
|
20
|
+
MimeType["BMP"] = "bmp";
|
|
21
|
+
})(MimeType || (MimeType = {}));
|
|
22
|
+
export function createAssetMethods(ctx) {
|
|
23
|
+
return {
|
|
24
|
+
async assetById(assetId) {
|
|
25
|
+
requireParam(assetId, "assetId");
|
|
26
|
+
const url = ctx.url.build(`/assets/${assetId}`);
|
|
27
|
+
return ctx.http.fetch(url);
|
|
28
|
+
},
|
|
29
|
+
async imageAssetById(assetId, queryParams) {
|
|
30
|
+
requireParam(assetId, "assetId");
|
|
31
|
+
const url = ctx.url.build(`/assets/image/${assetId}`, {
|
|
32
|
+
queryParams: queryParams,
|
|
33
|
+
});
|
|
34
|
+
return ctx.http.fetchText(url);
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content API methods
|
|
3
|
+
*/
|
|
4
|
+
import type { HttpClient } from "../core/http.ts";
|
|
5
|
+
import type { UrlBuilder } from "../core/url-builder.ts";
|
|
6
|
+
import type { CacheManager } from "../core/cache.ts";
|
|
7
|
+
export interface MethodContext {
|
|
8
|
+
readonly http: HttpClient;
|
|
9
|
+
readonly url: UrlBuilder;
|
|
10
|
+
readonly cache: CacheManager;
|
|
11
|
+
readonly endpoint: string;
|
|
12
|
+
readonly tenant?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ListQueryOptions {
|
|
15
|
+
limit?: number;
|
|
16
|
+
skip?: number;
|
|
17
|
+
sort?: Record<string, 1 | -1>;
|
|
18
|
+
filter?: Record<string, unknown>;
|
|
19
|
+
fields?: Record<string, 0 | 1>;
|
|
20
|
+
locale?: string;
|
|
21
|
+
populate?: number;
|
|
22
|
+
/** Override the client-level useAdminAccess setting for this request */
|
|
23
|
+
useAdminAccess?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface ContentItemQueryOptions extends ListQueryOptions {
|
|
26
|
+
model: string;
|
|
27
|
+
id?: string;
|
|
28
|
+
queryParams?: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
export interface ContentListQueryOptions extends ListQueryOptions {
|
|
31
|
+
queryParams?: Record<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
export interface TreeQueryOptions extends ListQueryOptions {
|
|
34
|
+
parent?: string;
|
|
35
|
+
queryParams?: Record<string, unknown>;
|
|
36
|
+
}
|
|
37
|
+
export interface AggregateQueryOptions {
|
|
38
|
+
model: string;
|
|
39
|
+
pipeline: Record<string, unknown>[];
|
|
40
|
+
locale?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface CockpitContentItem {
|
|
43
|
+
_id: string;
|
|
44
|
+
_created?: number;
|
|
45
|
+
_modified?: number;
|
|
46
|
+
_cby?: string;
|
|
47
|
+
_mby?: string;
|
|
48
|
+
_state?: number;
|
|
49
|
+
[key: string]: unknown;
|
|
50
|
+
}
|
|
51
|
+
export interface CockpitNewsItem extends CockpitContentItem {
|
|
52
|
+
title: string;
|
|
53
|
+
cover?: {
|
|
54
|
+
_id: string;
|
|
55
|
+
path: string;
|
|
56
|
+
title: string;
|
|
57
|
+
};
|
|
58
|
+
author?: string;
|
|
59
|
+
publicationDate?: string;
|
|
60
|
+
content?: string;
|
|
61
|
+
}
|
|
62
|
+
export interface CockpitTreeNode<T = CockpitContentItem> {
|
|
63
|
+
_id: string;
|
|
64
|
+
_pid?: string;
|
|
65
|
+
_o?: number;
|
|
66
|
+
children?: CockpitTreeNode<T>[];
|
|
67
|
+
data?: T;
|
|
68
|
+
}
|
|
69
|
+
export interface ContentMethods {
|
|
70
|
+
getContentItem<T = unknown>(options: ContentItemQueryOptions): Promise<T | null>;
|
|
71
|
+
getContentItems<T = CockpitContentItem>(model: string, options?: ContentListQueryOptions): Promise<T[] | null>;
|
|
72
|
+
getContentTree<T = CockpitContentItem>(model: string, options?: TreeQueryOptions): Promise<CockpitTreeNode<T>[] | null>;
|
|
73
|
+
getAggregateModel<T = unknown>(options: AggregateQueryOptions): Promise<T[] | null>;
|
|
74
|
+
postContentItem<T = unknown>(model: string, item: Record<string, unknown>): Promise<T | null>;
|
|
75
|
+
deleteContentItem<T = unknown>(model: string, id: string): Promise<T | null>;
|
|
76
|
+
}
|
|
77
|
+
export declare function createContentMethods(ctx: MethodContext): ContentMethods;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content API methods
|
|
3
|
+
*/
|
|
4
|
+
import { requireParam, validatePathSegment } from "../core/validation.js";
|
|
5
|
+
export function createContentMethods(ctx) {
|
|
6
|
+
const buildFetchOptions = (useAdminAccess) => useAdminAccess !== undefined ? { useAdminAccess } : {};
|
|
7
|
+
return {
|
|
8
|
+
async getContentItem(options) {
|
|
9
|
+
const { model, id, locale = "default", useAdminAccess, queryParams = {}, } = options;
|
|
10
|
+
requireParam(model, "a model");
|
|
11
|
+
validatePathSegment(model, "model");
|
|
12
|
+
if (id !== undefined)
|
|
13
|
+
validatePathSegment(id, "id");
|
|
14
|
+
const url = ctx.url.build(`/content/item/${model}${id !== undefined ? `/${id}` : ""}`, {
|
|
15
|
+
locale,
|
|
16
|
+
queryParams,
|
|
17
|
+
});
|
|
18
|
+
return ctx.http.fetch(url, buildFetchOptions(useAdminAccess));
|
|
19
|
+
},
|
|
20
|
+
async getContentItems(model, options = {}) {
|
|
21
|
+
requireParam(model, "a model");
|
|
22
|
+
validatePathSegment(model, "model");
|
|
23
|
+
const { locale = "default", limit, skip, sort, filter, fields, populate, useAdminAccess, queryParams = {}, } = options;
|
|
24
|
+
const url = ctx.url.build(`/content/items/${model}`, {
|
|
25
|
+
locale,
|
|
26
|
+
queryParams: {
|
|
27
|
+
...queryParams,
|
|
28
|
+
limit,
|
|
29
|
+
skip,
|
|
30
|
+
sort,
|
|
31
|
+
filter,
|
|
32
|
+
fields,
|
|
33
|
+
populate,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
return ctx.http.fetch(url, buildFetchOptions(useAdminAccess));
|
|
37
|
+
},
|
|
38
|
+
async getContentTree(model, options = {}) {
|
|
39
|
+
requireParam(model, "a model");
|
|
40
|
+
validatePathSegment(model, "model");
|
|
41
|
+
const { locale = "default", parent, filter, fields, populate, useAdminAccess, queryParams = {}, } = options;
|
|
42
|
+
const url = ctx.url.build(`/content/tree/${model}`, {
|
|
43
|
+
locale,
|
|
44
|
+
queryParams: {
|
|
45
|
+
...queryParams,
|
|
46
|
+
parent,
|
|
47
|
+
filter: filter ?? {},
|
|
48
|
+
fields,
|
|
49
|
+
populate,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
return ctx.http.fetch(url, buildFetchOptions(useAdminAccess));
|
|
53
|
+
},
|
|
54
|
+
async getAggregateModel(options) {
|
|
55
|
+
const { model, pipeline, locale = "default" } = options;
|
|
56
|
+
requireParam(model, "a model");
|
|
57
|
+
validatePathSegment(model, "model");
|
|
58
|
+
const url = ctx.url.build(`/content/aggregate/${model}`, {
|
|
59
|
+
locale,
|
|
60
|
+
queryParams: { pipeline },
|
|
61
|
+
});
|
|
62
|
+
return ctx.http.fetch(url);
|
|
63
|
+
},
|
|
64
|
+
async postContentItem(model, item) {
|
|
65
|
+
requireParam(model, "a model");
|
|
66
|
+
validatePathSegment(model, "model");
|
|
67
|
+
const url = ctx.url.build(`/content/item/${model}`);
|
|
68
|
+
return ctx.http.post(url, { data: item });
|
|
69
|
+
},
|
|
70
|
+
async deleteContentItem(model, id) {
|
|
71
|
+
requireParam(model, "a model");
|
|
72
|
+
requireParam(id, "an id");
|
|
73
|
+
validatePathSegment(model, "model");
|
|
74
|
+
validatePathSegment(id, "id");
|
|
75
|
+
const url = ctx.url.build(`/content/item/${model}/${id}`);
|
|
76
|
+
return ctx.http.delete(url);
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GraphQL API method
|
|
3
|
+
*/
|
|
4
|
+
import { type DocumentNode } from "graphql";
|
|
5
|
+
import type { MethodContext } from "./content.ts";
|
|
6
|
+
export interface GraphQLMethods {
|
|
7
|
+
graphQL<T = unknown>(document: DocumentNode, variables?: Record<string, unknown>): Promise<T | null>;
|
|
8
|
+
}
|
|
9
|
+
export declare function createGraphQLMethods(ctx: MethodContext): GraphQLMethods;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GraphQL API method
|
|
3
|
+
*/
|
|
4
|
+
import { print } from "graphql";
|
|
5
|
+
export function createGraphQLMethods(ctx) {
|
|
6
|
+
return {
|
|
7
|
+
async graphQL(document, variables) {
|
|
8
|
+
const query = print(document);
|
|
9
|
+
const endpoint = ctx.url.graphqlEndpoint();
|
|
10
|
+
return ctx.http.post(endpoint, { query, variables });
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Method exports
|
|
3
|
+
*/
|
|
4
|
+
export type { MethodContext } from "./content.ts";
|
|
5
|
+
export type { ContentMethods } from "./content.ts";
|
|
6
|
+
export { createContentMethods } from "./content.ts";
|
|
7
|
+
export type { PagesMethods, PageByRouteOptions } from "./pages.ts";
|
|
8
|
+
export { createPagesMethods } from "./pages.ts";
|
|
9
|
+
export type { MenuMethods } from "./menus.ts";
|
|
10
|
+
export { createMenuMethods } from "./menus.ts";
|
|
11
|
+
export type { RouteMethods } from "./routes.ts";
|
|
12
|
+
export { createRouteMethods } from "./routes.ts";
|
|
13
|
+
export type { AssetMethods } from "./assets.ts";
|
|
14
|
+
export { createAssetMethods } from "./assets.ts";
|
|
15
|
+
export type { GraphQLMethods } from "./graphql.ts";
|
|
16
|
+
export { createGraphQLMethods } from "./graphql.ts";
|
|
17
|
+
export type { SearchMethods } from "./search.ts";
|
|
18
|
+
export { createSearchMethods } from "./search.ts";
|
|
19
|
+
export type { LocalizeMethods } from "./localize.ts";
|
|
20
|
+
export { createLocalizeMethods } from "./localize.ts";
|
|
21
|
+
export type { SystemMethods } from "./system.ts";
|
|
22
|
+
export { createSystemMethods } from "./system.ts";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Method exports
|
|
3
|
+
*/
|
|
4
|
+
export { createContentMethods } from "./content.js";
|
|
5
|
+
export { createPagesMethods } from "./pages.js";
|
|
6
|
+
export { createMenuMethods } from "./menus.js";
|
|
7
|
+
export { createRouteMethods } from "./routes.js";
|
|
8
|
+
export { createAssetMethods } from "./assets.js";
|
|
9
|
+
export { createGraphQLMethods } from "./graphql.js";
|
|
10
|
+
export { createSearchMethods } from "./search.js";
|
|
11
|
+
export { createLocalizeMethods } from "./localize.js";
|
|
12
|
+
export { createSystemMethods } from "./system.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Localization API methods (Lokalize addon)
|
|
3
|
+
*/
|
|
4
|
+
import type { MethodContext } from "./content.ts";
|
|
5
|
+
export interface LocalizeOptions {
|
|
6
|
+
locale?: string;
|
|
7
|
+
nested?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface LocalizeMethods {
|
|
10
|
+
localize<T = unknown>(projectName: string, options?: LocalizeOptions): Promise<T | null>;
|
|
11
|
+
}
|
|
12
|
+
export declare function createLocalizeMethods(ctx: MethodContext): LocalizeMethods;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Localization API methods (Lokalize addon)
|
|
3
|
+
*/
|
|
4
|
+
import { requireParam } from "../core/validation.js";
|
|
5
|
+
export function createLocalizeMethods(ctx) {
|
|
6
|
+
return {
|
|
7
|
+
async localize(projectName, options = {}) {
|
|
8
|
+
requireParam(projectName, "projectName");
|
|
9
|
+
const { locale = "default", nested = false } = options;
|
|
10
|
+
const url = ctx.url.build(`/lokalize/project/${projectName}`, {
|
|
11
|
+
locale,
|
|
12
|
+
queryParams: { nested },
|
|
13
|
+
});
|
|
14
|
+
return ctx.http.fetch(url);
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Menu API methods
|
|
3
|
+
*/
|
|
4
|
+
import type { MethodContext } from "./content.ts";
|
|
5
|
+
import type { CockpitAsset } from "./assets.ts";
|
|
6
|
+
export interface MenuQueryOptions {
|
|
7
|
+
inactive?: boolean;
|
|
8
|
+
locale?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface CockpitMenuUrl {
|
|
11
|
+
route: string;
|
|
12
|
+
locale: string;
|
|
13
|
+
}
|
|
14
|
+
export interface CockpitMenuLink {
|
|
15
|
+
active: boolean;
|
|
16
|
+
title: string;
|
|
17
|
+
url: string | CockpitMenuUrl;
|
|
18
|
+
target?: string;
|
|
19
|
+
data?: {
|
|
20
|
+
image?: CockpitAsset | null;
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
};
|
|
23
|
+
children?: CockpitMenuLink[];
|
|
24
|
+
meta?: {
|
|
25
|
+
key: string;
|
|
26
|
+
value: string;
|
|
27
|
+
}[];
|
|
28
|
+
}
|
|
29
|
+
export interface CockpitMenu {
|
|
30
|
+
_id: string;
|
|
31
|
+
name: string;
|
|
32
|
+
label: string;
|
|
33
|
+
info?: string;
|
|
34
|
+
group?: string;
|
|
35
|
+
color?: string;
|
|
36
|
+
links: CockpitMenuLink[];
|
|
37
|
+
}
|
|
38
|
+
export interface MenuMethods {
|
|
39
|
+
pagesMenus<T = CockpitMenu>(options?: MenuQueryOptions | string): Promise<T[] | null>;
|
|
40
|
+
pagesMenu<T = CockpitMenu>(name: string, options?: MenuQueryOptions | string): Promise<T | null>;
|
|
41
|
+
}
|
|
42
|
+
export declare function createMenuMethods(ctx: MethodContext): MenuMethods;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Menu API methods
|
|
3
|
+
*/
|
|
4
|
+
export function createMenuMethods(ctx) {
|
|
5
|
+
return {
|
|
6
|
+
async pagesMenus(options = "default") {
|
|
7
|
+
const opts = typeof options === "string" ? { locale: options } : options;
|
|
8
|
+
const { locale = "default", inactive } = opts;
|
|
9
|
+
const url = ctx.url.build("/pages/menus", {
|
|
10
|
+
locale,
|
|
11
|
+
queryParams: { inactive },
|
|
12
|
+
});
|
|
13
|
+
return ctx.http.fetch(url);
|
|
14
|
+
},
|
|
15
|
+
async pagesMenu(name, options = "default") {
|
|
16
|
+
const opts = typeof options === "string" ? { locale: options } : options;
|
|
17
|
+
const { locale = "default", inactive } = opts;
|
|
18
|
+
const url = ctx.url.build(`/pages/menu/${name}`, {
|
|
19
|
+
locale,
|
|
20
|
+
queryParams: { inactive },
|
|
21
|
+
});
|
|
22
|
+
return ctx.http.fetch(url);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pages API methods
|
|
3
|
+
*/
|
|
4
|
+
import type { MethodContext, ContentListQueryOptions } from "./content.ts";
|
|
5
|
+
import type { CockpitAsset } from "./assets.ts";
|
|
6
|
+
export interface PageByIdOptions {
|
|
7
|
+
locale?: string;
|
|
8
|
+
populate?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface PageByRouteOptions {
|
|
11
|
+
locale?: string;
|
|
12
|
+
populate?: number;
|
|
13
|
+
}
|
|
14
|
+
export type CockpitPageType = "layout" | "collection" | "singleton" | "link";
|
|
15
|
+
export interface CockpitPageMeta {
|
|
16
|
+
_id: string;
|
|
17
|
+
title: string;
|
|
18
|
+
type: CockpitPageType;
|
|
19
|
+
slug?: string;
|
|
20
|
+
_r?: string;
|
|
21
|
+
_created?: number;
|
|
22
|
+
_modified?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface CockpitPageSeo {
|
|
25
|
+
title?: string;
|
|
26
|
+
description?: string;
|
|
27
|
+
keywords?: string;
|
|
28
|
+
image?: CockpitAsset;
|
|
29
|
+
noindex?: boolean;
|
|
30
|
+
nofollow?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface CockpitLayoutBlock {
|
|
33
|
+
component: string;
|
|
34
|
+
label?: string;
|
|
35
|
+
settings?: Record<string, unknown>;
|
|
36
|
+
children?: CockpitLayoutBlock[];
|
|
37
|
+
}
|
|
38
|
+
export interface CockpitPage extends CockpitPageMeta {
|
|
39
|
+
data?: Record<string, unknown>;
|
|
40
|
+
seo?: CockpitPageSeo;
|
|
41
|
+
layout?: CockpitLayoutBlock[];
|
|
42
|
+
_p?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface PagesMethods {
|
|
45
|
+
pages<T = CockpitPage>(options?: ContentListQueryOptions): Promise<T[] | null>;
|
|
46
|
+
pageById<T = CockpitPage>(id: string, options?: PageByIdOptions): Promise<T | null>;
|
|
47
|
+
pageByRoute<T = CockpitPage>(route: string, options?: PageByRouteOptions | string): Promise<T | null>;
|
|
48
|
+
}
|
|
49
|
+
export declare function createPagesMethods(ctx: MethodContext): PagesMethods;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pages API methods
|
|
3
|
+
*/
|
|
4
|
+
import { requireParam } from "../core/validation.js";
|
|
5
|
+
export function createPagesMethods(ctx) {
|
|
6
|
+
return {
|
|
7
|
+
async pages(options = {}) {
|
|
8
|
+
const { locale = "default", limit, skip, sort, filter, fields, queryParams = {}, } = options;
|
|
9
|
+
const url = ctx.url.build("/pages/pages", {
|
|
10
|
+
locale,
|
|
11
|
+
queryParams: { ...queryParams, limit, skip, sort, filter, fields },
|
|
12
|
+
});
|
|
13
|
+
return ctx.http.fetch(url);
|
|
14
|
+
},
|
|
15
|
+
async pageById(id, options = {}) {
|
|
16
|
+
requireParam(id, "a page id");
|
|
17
|
+
const { locale = "default", populate } = options;
|
|
18
|
+
const url = ctx.url.build(`/pages/page/${id}`, {
|
|
19
|
+
locale,
|
|
20
|
+
queryParams: { populate },
|
|
21
|
+
});
|
|
22
|
+
return ctx.http.fetch(url);
|
|
23
|
+
},
|
|
24
|
+
async pageByRoute(route, options = "default") {
|
|
25
|
+
const opts = typeof options === "string" ? { locale: options } : options;
|
|
26
|
+
const { locale = "default", populate } = opts;
|
|
27
|
+
const url = ctx.url.build("/pages/page", {
|
|
28
|
+
locale,
|
|
29
|
+
queryParams: { route, populate },
|
|
30
|
+
});
|
|
31
|
+
return ctx.http.fetch(url);
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Routes, sitemap, and settings API methods
|
|
3
|
+
*/
|
|
4
|
+
import type { MethodContext } from "./content.ts";
|
|
5
|
+
import type { CockpitAsset } from "./assets.ts";
|
|
6
|
+
import type { CockpitPageType, CockpitPageSeo } from "./pages.ts";
|
|
7
|
+
export interface CockpitRoute {
|
|
8
|
+
route: string;
|
|
9
|
+
slug: string;
|
|
10
|
+
type: CockpitPageType;
|
|
11
|
+
lastmod: string;
|
|
12
|
+
}
|
|
13
|
+
export type CockpitRoutesResponse = Record<string, CockpitRoute[]>;
|
|
14
|
+
export interface CockpitSitemapEntry {
|
|
15
|
+
routes: Record<string, string>;
|
|
16
|
+
type: CockpitPageType;
|
|
17
|
+
lastmod: string;
|
|
18
|
+
}
|
|
19
|
+
export interface CockpitPreviewConfig {
|
|
20
|
+
name: string;
|
|
21
|
+
uri: string;
|
|
22
|
+
}
|
|
23
|
+
export interface CockpitSettings {
|
|
24
|
+
revisions?: boolean;
|
|
25
|
+
meta?: Record<string, unknown>;
|
|
26
|
+
preview?: CockpitPreviewConfig[];
|
|
27
|
+
images?: {
|
|
28
|
+
logo?: CockpitAsset | null;
|
|
29
|
+
small?: CockpitAsset | null;
|
|
30
|
+
favicon?: CockpitAsset | null;
|
|
31
|
+
[key: string]: CockpitAsset | null | undefined;
|
|
32
|
+
};
|
|
33
|
+
scripts?: {
|
|
34
|
+
header?: string | null;
|
|
35
|
+
footer?: string | null;
|
|
36
|
+
};
|
|
37
|
+
seo?: CockpitPageSeo;
|
|
38
|
+
locales?: string[];
|
|
39
|
+
}
|
|
40
|
+
export interface RouteMethods {
|
|
41
|
+
pagesRoutes<T = CockpitRoutesResponse>(locale?: string): Promise<T | null>;
|
|
42
|
+
pagesSitemap<T = CockpitSitemapEntry>(): Promise<T[] | null>;
|
|
43
|
+
pagesSetting<T = CockpitSettings>(locale?: string): Promise<T | null>;
|
|
44
|
+
getFullRouteForSlug(slug: string): Promise<string | undefined>;
|
|
45
|
+
}
|
|
46
|
+
export declare function createRouteMethods(ctx: MethodContext): RouteMethods;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Routes, sitemap, and settings API methods
|
|
3
|
+
*/
|
|
4
|
+
import { generateCollectionAndSingletonSlugRouteMap } from "../utils/route-map.js";
|
|
5
|
+
export function createRouteMethods(ctx) {
|
|
6
|
+
return {
|
|
7
|
+
async pagesRoutes(locale = "default") {
|
|
8
|
+
const url = ctx.url.build("/pages/routes", { locale });
|
|
9
|
+
return ctx.http.fetch(url);
|
|
10
|
+
},
|
|
11
|
+
async pagesSitemap() {
|
|
12
|
+
const url = ctx.url.build("/pages/sitemap");
|
|
13
|
+
return ctx.http.fetch(url);
|
|
14
|
+
},
|
|
15
|
+
async pagesSetting(locale = "default") {
|
|
16
|
+
const url = ctx.url.build("/pages/settings", { locale });
|
|
17
|
+
return ctx.http.fetch(url);
|
|
18
|
+
},
|
|
19
|
+
async getFullRouteForSlug(slug) {
|
|
20
|
+
const routeSlugMap = await generateCollectionAndSingletonSlugRouteMap(ctx.endpoint, ctx.tenant, ctx.cache);
|
|
21
|
+
return routeSlugMap[slug];
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|