@cntrl-site/sdk 1.25.10 → 1.25.11-components.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/lib/Client/Client.d.ts +4 -0
- package/lib/Client/Client.js +30 -0
- package/lib/index.d.ts +1 -0
- package/lib/schemas/article/Item.schema.js +2 -1
- package/lib/types/article/Item.d.ts +1 -0
- package/lib/types/customComponent/CustomComponentMeta.d.ts +5 -0
- package/lib/types/customComponent/CustomComponentMeta.js +2 -0
- package/package.json +2 -1
package/lib/Client/Client.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Project } from '../types/project/Project';
|
|
|
3
3
|
import { Layout } from '../types/project/Layout';
|
|
4
4
|
import { Article } from '../types/article/Article';
|
|
5
5
|
import { KeyframeAny } from '../types/keyframe/Keyframe';
|
|
6
|
+
import { CustomComponentMeta } from '../types/customComponent/CustomComponentMeta';
|
|
6
7
|
export declare class Client {
|
|
7
8
|
private fetchImpl;
|
|
8
9
|
private url;
|
|
@@ -11,6 +12,8 @@ export declare class Client {
|
|
|
11
12
|
getPageData(pageSlug: string, buildMode?: 'default' | 'self-hosted'): Promise<CntrlPageData>;
|
|
12
13
|
getProjectPagesPaths(): Promise<string[]>;
|
|
13
14
|
getLayouts(): Promise<Layout[]>;
|
|
15
|
+
fetchCustomComponents(buildMode?: 'default' | 'self-hosted'): Promise<CustomComponentMeta[]>;
|
|
16
|
+
fetchCustomComponentBundle(componentId: string, buildMode?: 'default' | 'self-hosted'): Promise<string>;
|
|
14
17
|
private fetchProject;
|
|
15
18
|
private fetchArticle;
|
|
16
19
|
private findArticleIdByPageSlug;
|
|
@@ -18,6 +21,7 @@ export declare class Client {
|
|
|
18
21
|
interface FetchImplResponse {
|
|
19
22
|
ok: boolean;
|
|
20
23
|
json(): Promise<any>;
|
|
24
|
+
text(): Promise<string>;
|
|
21
25
|
statusText: string;
|
|
22
26
|
}
|
|
23
27
|
type FetchImpl = (url: string, init?: RequestInit) => Promise<FetchImplResponse>;
|
package/lib/Client/Client.js
CHANGED
|
@@ -81,6 +81,36 @@ class Client {
|
|
|
81
81
|
}
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
|
+
fetchCustomComponents() {
|
|
85
|
+
return __awaiter(this, arguments, void 0, function* (buildMode = 'default') {
|
|
86
|
+
const { username: projectId, password: apiKey, origin } = this.url;
|
|
87
|
+
const url = new url_1.URL(`/projects/${projectId}/custom-components?buildMode=${buildMode}`, origin);
|
|
88
|
+
const response = yield this.fetchImpl(url.href, {
|
|
89
|
+
headers: {
|
|
90
|
+
Authorization: `Bearer ${apiKey}`
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
if (!response.ok) {
|
|
94
|
+
throw new Error(`Failed to fetch custom components for project #${projectId}: ${response.statusText}`);
|
|
95
|
+
}
|
|
96
|
+
return response.json();
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
fetchCustomComponentBundle(componentId_1) {
|
|
100
|
+
return __awaiter(this, arguments, void 0, function* (componentId, buildMode = 'default') {
|
|
101
|
+
const { username: projectId, password: apiKey, origin } = this.url;
|
|
102
|
+
const url = new url_1.URL(`/projects/${projectId}/custom-components/${componentId}/bundle.js?buildMode=${buildMode}`, origin);
|
|
103
|
+
const response = yield this.fetchImpl(url.href, {
|
|
104
|
+
headers: {
|
|
105
|
+
Authorization: `Bearer ${apiKey}`
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
if (!response.ok) {
|
|
109
|
+
throw new Error(`Failed to fetch bundle for custom component #${componentId}: ${response.statusText}`);
|
|
110
|
+
}
|
|
111
|
+
return response.text();
|
|
112
|
+
});
|
|
113
|
+
}
|
|
84
114
|
fetchProject() {
|
|
85
115
|
return __awaiter(this, arguments, void 0, function* (buildMode = 'default') {
|
|
86
116
|
const { username: projectId, password: apiKey, origin } = this.url;
|
package/lib/index.d.ts
CHANGED
|
@@ -21,3 +21,4 @@ export type { Meta } from './types/project/Meta';
|
|
|
21
21
|
export type { KeyframeValueMap, KeyframeAny } from './types/keyframe/Keyframe';
|
|
22
22
|
export type { CompoundSettings } from './types/article/CompoundSettings';
|
|
23
23
|
export type { Dimensions, Left, Position, RectCoordinates, RectObject, ScaleOrigin, Sides, Top } from './types/article/Rect';
|
|
24
|
+
export type { CustomComponentMeta } from './types/customComponent/CustomComponentMeta';
|
|
@@ -191,7 +191,8 @@ const ComponentItemSchema = ItemBase_schema_1.ItemBaseSchema.extend({
|
|
|
191
191
|
type: zod_1.z.literal(ArticleItemType_1.ArticleItemType.Component),
|
|
192
192
|
commonParams: zod_1.z.object({
|
|
193
193
|
componentId: zod_1.z.string(),
|
|
194
|
-
content: zod_1.z.any().optional()
|
|
194
|
+
content: zod_1.z.any().optional(),
|
|
195
|
+
parameters: zod_1.z.record(zod_1.z.any()).optional()
|
|
195
196
|
}),
|
|
196
197
|
sticky: zod_1.z.record(zod_1.z.object({
|
|
197
198
|
from: zod_1.z.number(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntrl-site/sdk",
|
|
3
|
-
"version": "1.25.
|
|
3
|
+
"version": "1.25.11-components.0",
|
|
4
4
|
"description": "Generic SDK for use in public websites.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"test": "jest",
|
|
9
9
|
"prebuild": "rimraf ./lib",
|
|
10
10
|
"build": "tsc --project tsconfig.build.json",
|
|
11
|
+
"build:watch": "tsc --watch --project tsconfig.build.json",
|
|
11
12
|
"prepublishOnly": "cross-env NODE_ENV=production npm run build"
|
|
12
13
|
},
|
|
13
14
|
"bin": {
|