@cmssy/core 9.10.0 → 10.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.
@@ -0,0 +1,189 @@
1
+ import { CmssyClientConfig, BlockRect, BlockSchema, BlockMeta } from '@cmssy/types';
2
+ import { G as GraphqlRequestOptions } from './locale-XintNd0n.js';
3
+
4
+ declare const DEFAULT_CMSSY_EDITOR_ORIGINS: string[];
5
+ declare function isDevelopment(): boolean;
6
+ declare function resolveEditorOrigin(editorOrigin: string | string[] | undefined): string | string[];
7
+ interface CmssyConfig {
8
+ /**
9
+ * Full GraphQL delivery endpoint. Defaults to the cmssy cloud endpoint
10
+ * (`https://api.cmssy.io/graphql`); set it only for self-hosted / staging.
11
+ */
12
+ apiUrl?: string;
13
+ /** Organization slug - part of the org-scoped delivery path. */
14
+ org: string;
15
+ workspaceSlug: string;
16
+ draftSecret: string;
17
+ /**
18
+ * A cmssy API token (`cs_…`) that opts this app into the editor-controlled dev
19
+ * preview. In development only, the SDK sends it on every page fetch so the
20
+ * backend can resolve the token's user and honour that user's dev-preview flag
21
+ * (toggled from the editor's dev-mode switch): flag on + a saved dev draft ⇒
22
+ * the draft overlay renders, otherwise published content. Server-only (never
23
+ * reaches the client); ignored outside development. See the Quickstart
24
+ * "Dev preview" section.
25
+ */
26
+ devToken?: string;
27
+ /**
28
+ * Origin allowed to frame your app in the editor. Defaults to
29
+ * {@link DEFAULT_CMSSY_EDITOR_ORIGINS}; set it only for self-hosted admins.
30
+ */
31
+ editorOrigin?: string | string[];
32
+ /**
33
+ * Canonical absolute site URL (e.g. https://cmssy.com), used by
34
+ * createCmssyRobots / createCmssySitemap. When omitted the helpers derive the
35
+ * origin from the request `host` header at render time (multi-domain safe).
36
+ */
37
+ siteUrl?: string;
38
+ /**
39
+ * Fallback locale resolver for a site whose URLs carry no language (e.g. a
40
+ * cookie or Accept-Language strategy). The workspace site config remains the
41
+ * source of truth for the default and enabled languages.
42
+ */
43
+ resolveLocale?: () => string | Promise<string>;
44
+ }
45
+ /**
46
+ * Env-shaped input for {@link defineCmssyConfig}: the required string fields are
47
+ * widened to `string | undefined` so a config can pass `process.env.*` straight
48
+ * through without a `?? ""` fallback (which would mask a missing value as an
49
+ * empty string) or a cast.
50
+ */
51
+ type CmssyEnvConfig = Omit<CmssyConfig, "org" | "workspaceSlug" | "draftSecret"> & {
52
+ org?: string;
53
+ workspaceSlug?: string;
54
+ draftSecret?: string;
55
+ };
56
+ /**
57
+ * Validates an env-sourced config and returns a strictly-typed
58
+ * {@link CmssyConfig}. Pass raw `process.env.*` values; this throws a clear,
59
+ * actionable error listing any missing required variables (rendered by the
60
+ * Next.js error overlay / boundary), so the app fails fast instead of running
61
+ * with silently-empty config.
62
+ */
63
+ declare function defineCmssyConfig(config: CmssyEnvConfig): CmssyConfig;
64
+
65
+ interface QueryScopedOptions extends GraphqlRequestOptions {
66
+ workspaceId?: string;
67
+ }
68
+ interface CmssyClient {
69
+ readonly config: CmssyClientConfig;
70
+ query<T = unknown>(document: string, variables?: Record<string, unknown>, options?: GraphqlRequestOptions): Promise<T>;
71
+ queryScoped<T = unknown>(document: string, variables?: Record<string, unknown>, options?: QueryScopedOptions): Promise<T>;
72
+ resolveWorkspaceId(options?: GraphqlRequestOptions): Promise<string>;
73
+ }
74
+ declare function createCmssyClient(input: CmssyClientConfig): CmssyClient;
75
+
76
+ declare const PROTOCOL_VERSION = 2;
77
+
78
+ interface ReadyMessage {
79
+ type: "cmssy:ready";
80
+ protocolVersion: number;
81
+ blocks: Array<{
82
+ id: string;
83
+ type: string;
84
+ bounds: BlockRect;
85
+ layoutPosition?: string;
86
+ }>;
87
+ schemas: Record<string, BlockSchema>;
88
+ blockMeta?: Record<string, BlockMeta>;
89
+ }
90
+ interface BoundsMessage {
91
+ type: "cmssy:bounds";
92
+ blockId: string;
93
+ rect: BlockRect;
94
+ }
95
+ interface ClickMessage {
96
+ type: "cmssy:click";
97
+ blockId: string;
98
+ rect: BlockRect;
99
+ layoutPosition?: string;
100
+ }
101
+ interface DeselectMessage {
102
+ type: "cmssy:deselect";
103
+ }
104
+ interface MoveMessage {
105
+ type: "cmssy:move";
106
+ protocolVersion: number;
107
+ blockId: string;
108
+ index: number;
109
+ }
110
+ interface DragIndexMessage {
111
+ type: "cmssy:drag-index";
112
+ protocolVersion: number;
113
+ index: number;
114
+ }
115
+ type AppToEditorMessage = ReadyMessage | BoundsMessage | ClickMessage | DeselectMessage | MoveMessage | DragIndexMessage;
116
+ interface SelectMessage {
117
+ type: "cmssy:select";
118
+ protocolVersion: number;
119
+ blockId: string;
120
+ }
121
+ interface PatchMessage {
122
+ type: "cmssy:patch";
123
+ protocolVersion: number;
124
+ blockId: string;
125
+ content: Record<string, unknown>;
126
+ style?: Record<string, unknown>;
127
+ advanced?: Record<string, unknown>;
128
+ layoutPosition?: string;
129
+ }
130
+ interface ParentReadyMessage {
131
+ type: "cmssy:parent-ready";
132
+ protocolVersion: number;
133
+ }
134
+ interface InsertMessage {
135
+ type: "cmssy:insert";
136
+ protocolVersion: number;
137
+ blockId: string;
138
+ blockType: string;
139
+ content: Record<string, unknown>;
140
+ style?: Record<string, unknown>;
141
+ advanced?: Record<string, unknown>;
142
+ index: number;
143
+ }
144
+ interface ReorderMessage {
145
+ type: "cmssy:reorder";
146
+ protocolVersion: number;
147
+ blockIds: string[];
148
+ }
149
+ interface RemoveMessage {
150
+ type: "cmssy:remove";
151
+ protocolVersion: number;
152
+ blockId: string;
153
+ }
154
+ interface DragOverMessage {
155
+ type: "cmssy:drag-over";
156
+ protocolVersion: number;
157
+ y: number;
158
+ }
159
+ interface DragEndMessage {
160
+ type: "cmssy:drag-end";
161
+ protocolVersion: number;
162
+ }
163
+ type EditorToAppMessage = SelectMessage | PatchMessage | ParentReadyMessage | InsertMessage | ReorderMessage | RemoveMessage | DragOverMessage | DragEndMessage;
164
+ declare function isProtocolCompatible(version: number): boolean;
165
+
166
+ interface PostTarget {
167
+ postMessage: (message: unknown, targetOrigin: string) => void;
168
+ }
169
+ declare function normalizeOrigin(origin: string): string;
170
+ declare function postToEditor(target: PostTarget, editorOrigin: string, message: AppToEditorMessage): void;
171
+ declare function resolveInitialTarget(editorOrigin: string | string[]): string;
172
+ declare function parseEditorMessage(data: unknown, origin: string, expectedOrigin: string | string[]): EditorToAppMessage | null;
173
+
174
+ interface CmssyCspOptions {
175
+ /** Defaults to the cmssy cloud admin origin when unset. */
176
+ editorOrigin?: string | string[];
177
+ }
178
+ interface MutableHeaders {
179
+ headers: {
180
+ get: (name: string) => string | null;
181
+ set: (name: string, value: string) => void;
182
+ delete: (name: string) => void;
183
+ };
184
+ }
185
+ declare function toCspOrigin(origin: string): string;
186
+ declare function cmssyCspHeaders(options: CmssyCspOptions): Record<string, string>;
187
+ declare function applyCmssyCsp<T extends MutableHeaders>(response: T, options: CmssyCspOptions): T;
188
+
189
+ export { type AppToEditorMessage as A, type BoundsMessage as B, type ClickMessage as C, DEFAULT_CMSSY_EDITOR_ORIGINS as D, type EditorToAppMessage as E, PROTOCOL_VERSION as P, type QueryScopedOptions as Q, type ReadyMessage as R, type SelectMessage as S, type CmssyClient as a, type CmssyConfig as b, type CmssyCspOptions as c, type CmssyEnvConfig as d, type ParentReadyMessage as e, type PatchMessage as f, type PostTarget as g, applyCmssyCsp as h, createCmssyClient as i, defineCmssyConfig as j, isProtocolCompatible as k, postToEditor as l, cmssyCspHeaders as m, normalizeOrigin as n, isDevelopment as o, parseEditorMessage as p, resolveInitialTarget as q, resolveEditorOrigin as r, toCspOrigin as t };
@@ -0,0 +1,189 @@
1
+ import { CmssyClientConfig, BlockRect, BlockSchema, BlockMeta } from '@cmssy/types';
2
+ import { G as GraphqlRequestOptions } from './locale-rhYcXU5z.cjs';
3
+
4
+ declare const DEFAULT_CMSSY_EDITOR_ORIGINS: string[];
5
+ declare function isDevelopment(): boolean;
6
+ declare function resolveEditorOrigin(editorOrigin: string | string[] | undefined): string | string[];
7
+ interface CmssyConfig {
8
+ /**
9
+ * Full GraphQL delivery endpoint. Defaults to the cmssy cloud endpoint
10
+ * (`https://api.cmssy.io/graphql`); set it only for self-hosted / staging.
11
+ */
12
+ apiUrl?: string;
13
+ /** Organization slug - part of the org-scoped delivery path. */
14
+ org: string;
15
+ workspaceSlug: string;
16
+ draftSecret: string;
17
+ /**
18
+ * A cmssy API token (`cs_…`) that opts this app into the editor-controlled dev
19
+ * preview. In development only, the SDK sends it on every page fetch so the
20
+ * backend can resolve the token's user and honour that user's dev-preview flag
21
+ * (toggled from the editor's dev-mode switch): flag on + a saved dev draft ⇒
22
+ * the draft overlay renders, otherwise published content. Server-only (never
23
+ * reaches the client); ignored outside development. See the Quickstart
24
+ * "Dev preview" section.
25
+ */
26
+ devToken?: string;
27
+ /**
28
+ * Origin allowed to frame your app in the editor. Defaults to
29
+ * {@link DEFAULT_CMSSY_EDITOR_ORIGINS}; set it only for self-hosted admins.
30
+ */
31
+ editorOrigin?: string | string[];
32
+ /**
33
+ * Canonical absolute site URL (e.g. https://cmssy.com), used by
34
+ * createCmssyRobots / createCmssySitemap. When omitted the helpers derive the
35
+ * origin from the request `host` header at render time (multi-domain safe).
36
+ */
37
+ siteUrl?: string;
38
+ /**
39
+ * Fallback locale resolver for a site whose URLs carry no language (e.g. a
40
+ * cookie or Accept-Language strategy). The workspace site config remains the
41
+ * source of truth for the default and enabled languages.
42
+ */
43
+ resolveLocale?: () => string | Promise<string>;
44
+ }
45
+ /**
46
+ * Env-shaped input for {@link defineCmssyConfig}: the required string fields are
47
+ * widened to `string | undefined` so a config can pass `process.env.*` straight
48
+ * through without a `?? ""` fallback (which would mask a missing value as an
49
+ * empty string) or a cast.
50
+ */
51
+ type CmssyEnvConfig = Omit<CmssyConfig, "org" | "workspaceSlug" | "draftSecret"> & {
52
+ org?: string;
53
+ workspaceSlug?: string;
54
+ draftSecret?: string;
55
+ };
56
+ /**
57
+ * Validates an env-sourced config and returns a strictly-typed
58
+ * {@link CmssyConfig}. Pass raw `process.env.*` values; this throws a clear,
59
+ * actionable error listing any missing required variables (rendered by the
60
+ * Next.js error overlay / boundary), so the app fails fast instead of running
61
+ * with silently-empty config.
62
+ */
63
+ declare function defineCmssyConfig(config: CmssyEnvConfig): CmssyConfig;
64
+
65
+ interface QueryScopedOptions extends GraphqlRequestOptions {
66
+ workspaceId?: string;
67
+ }
68
+ interface CmssyClient {
69
+ readonly config: CmssyClientConfig;
70
+ query<T = unknown>(document: string, variables?: Record<string, unknown>, options?: GraphqlRequestOptions): Promise<T>;
71
+ queryScoped<T = unknown>(document: string, variables?: Record<string, unknown>, options?: QueryScopedOptions): Promise<T>;
72
+ resolveWorkspaceId(options?: GraphqlRequestOptions): Promise<string>;
73
+ }
74
+ declare function createCmssyClient(input: CmssyClientConfig): CmssyClient;
75
+
76
+ declare const PROTOCOL_VERSION = 2;
77
+
78
+ interface ReadyMessage {
79
+ type: "cmssy:ready";
80
+ protocolVersion: number;
81
+ blocks: Array<{
82
+ id: string;
83
+ type: string;
84
+ bounds: BlockRect;
85
+ layoutPosition?: string;
86
+ }>;
87
+ schemas: Record<string, BlockSchema>;
88
+ blockMeta?: Record<string, BlockMeta>;
89
+ }
90
+ interface BoundsMessage {
91
+ type: "cmssy:bounds";
92
+ blockId: string;
93
+ rect: BlockRect;
94
+ }
95
+ interface ClickMessage {
96
+ type: "cmssy:click";
97
+ blockId: string;
98
+ rect: BlockRect;
99
+ layoutPosition?: string;
100
+ }
101
+ interface DeselectMessage {
102
+ type: "cmssy:deselect";
103
+ }
104
+ interface MoveMessage {
105
+ type: "cmssy:move";
106
+ protocolVersion: number;
107
+ blockId: string;
108
+ index: number;
109
+ }
110
+ interface DragIndexMessage {
111
+ type: "cmssy:drag-index";
112
+ protocolVersion: number;
113
+ index: number;
114
+ }
115
+ type AppToEditorMessage = ReadyMessage | BoundsMessage | ClickMessage | DeselectMessage | MoveMessage | DragIndexMessage;
116
+ interface SelectMessage {
117
+ type: "cmssy:select";
118
+ protocolVersion: number;
119
+ blockId: string;
120
+ }
121
+ interface PatchMessage {
122
+ type: "cmssy:patch";
123
+ protocolVersion: number;
124
+ blockId: string;
125
+ content: Record<string, unknown>;
126
+ style?: Record<string, unknown>;
127
+ advanced?: Record<string, unknown>;
128
+ layoutPosition?: string;
129
+ }
130
+ interface ParentReadyMessage {
131
+ type: "cmssy:parent-ready";
132
+ protocolVersion: number;
133
+ }
134
+ interface InsertMessage {
135
+ type: "cmssy:insert";
136
+ protocolVersion: number;
137
+ blockId: string;
138
+ blockType: string;
139
+ content: Record<string, unknown>;
140
+ style?: Record<string, unknown>;
141
+ advanced?: Record<string, unknown>;
142
+ index: number;
143
+ }
144
+ interface ReorderMessage {
145
+ type: "cmssy:reorder";
146
+ protocolVersion: number;
147
+ blockIds: string[];
148
+ }
149
+ interface RemoveMessage {
150
+ type: "cmssy:remove";
151
+ protocolVersion: number;
152
+ blockId: string;
153
+ }
154
+ interface DragOverMessage {
155
+ type: "cmssy:drag-over";
156
+ protocolVersion: number;
157
+ y: number;
158
+ }
159
+ interface DragEndMessage {
160
+ type: "cmssy:drag-end";
161
+ protocolVersion: number;
162
+ }
163
+ type EditorToAppMessage = SelectMessage | PatchMessage | ParentReadyMessage | InsertMessage | ReorderMessage | RemoveMessage | DragOverMessage | DragEndMessage;
164
+ declare function isProtocolCompatible(version: number): boolean;
165
+
166
+ interface PostTarget {
167
+ postMessage: (message: unknown, targetOrigin: string) => void;
168
+ }
169
+ declare function normalizeOrigin(origin: string): string;
170
+ declare function postToEditor(target: PostTarget, editorOrigin: string, message: AppToEditorMessage): void;
171
+ declare function resolveInitialTarget(editorOrigin: string | string[]): string;
172
+ declare function parseEditorMessage(data: unknown, origin: string, expectedOrigin: string | string[]): EditorToAppMessage | null;
173
+
174
+ interface CmssyCspOptions {
175
+ /** Defaults to the cmssy cloud admin origin when unset. */
176
+ editorOrigin?: string | string[];
177
+ }
178
+ interface MutableHeaders {
179
+ headers: {
180
+ get: (name: string) => string | null;
181
+ set: (name: string, value: string) => void;
182
+ delete: (name: string) => void;
183
+ };
184
+ }
185
+ declare function toCspOrigin(origin: string): string;
186
+ declare function cmssyCspHeaders(options: CmssyCspOptions): Record<string, string>;
187
+ declare function applyCmssyCsp<T extends MutableHeaders>(response: T, options: CmssyCspOptions): T;
188
+
189
+ export { type AppToEditorMessage as A, type BoundsMessage as B, type ClickMessage as C, DEFAULT_CMSSY_EDITOR_ORIGINS as D, type EditorToAppMessage as E, PROTOCOL_VERSION as P, type QueryScopedOptions as Q, type ReadyMessage as R, type SelectMessage as S, type CmssyClient as a, type CmssyConfig as b, type CmssyCspOptions as c, type CmssyEnvConfig as d, type ParentReadyMessage as e, type PatchMessage as f, type PostTarget as g, applyCmssyCsp as h, createCmssyClient as i, defineCmssyConfig as j, isProtocolCompatible as k, postToEditor as l, cmssyCspHeaders as m, normalizeOrigin as n, isDevelopment as o, parseEditorMessage as p, resolveInitialTarget as q, resolveEditorOrigin as r, toCspOrigin as t };