@cntrl-site/sdk 1.25.12 → 1.26.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.
@@ -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>;
@@ -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';
@@ -200,7 +200,8 @@ const ComponentItemSchema = ItemBase_schema_1.ItemBaseSchema.extend({
200
200
  type: zod_1.z.literal(ArticleItemType_1.ArticleItemType.Component),
201
201
  commonParams: zod_1.z.object({
202
202
  componentId: zod_1.z.string(),
203
- content: zod_1.z.any().optional()
203
+ content: zod_1.z.any().optional(),
204
+ parameters: zod_1.z.record(zod_1.z.any()).optional()
204
205
  }),
205
206
  sticky: zod_1.z.record(zod_1.z.object({
206
207
  from: zod_1.z.number(),
@@ -90,6 +90,7 @@ interface YoutubeEmbedCommonParams extends CommonParamsBase {
90
90
  interface ComponentCommonParams extends CommonParamsBase {
91
91
  componentId: string;
92
92
  content?: any;
93
+ parameters?: Record<string, any>;
93
94
  }
94
95
  interface MediaLayoutParams {
95
96
  opacity: number;
@@ -0,0 +1,5 @@
1
+ export type CustomComponentMeta = {
2
+ id: string;
3
+ name: string;
4
+ schema: Record<string, unknown>;
5
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk",
3
- "version": "1.25.12",
3
+ "version": "1.26.1",
4
4
  "description": "Generic SDK for use in public websites.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",