@scryme/chat 2.91.2 → 2.91.3
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/dist/custom-message-schema.d.ts +631 -0
- package/dist/custom-message-schema.js +395 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/src/custom-message-schema.ts +517 -0
- package/src/index.ts +1 -1
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* GraphQL-inspired Custom Message Schema
|
|
4
|
+
*
|
|
5
|
+
* This schema defines a structured, node-based representation for custom messages.
|
|
6
|
+
* It separates the underlying "Data" from the "UI" components, allowing for
|
|
7
|
+
* flexible and type-safe rendering.
|
|
8
|
+
*/
|
|
9
|
+
/** Basic Value types for properties in custom message components */
|
|
10
|
+
export var PropertyValueSchema = z.union([
|
|
11
|
+
z.string(),
|
|
12
|
+
z.number(),
|
|
13
|
+
z.boolean(),
|
|
14
|
+
z.null(),
|
|
15
|
+
z.array(z.string()),
|
|
16
|
+
z.record(z.string(), z.any()),
|
|
17
|
+
]);
|
|
18
|
+
/**
|
|
19
|
+
* Validation Schema for Input components in custom messages.
|
|
20
|
+
*/
|
|
21
|
+
export var ValidationSchema = z.object({
|
|
22
|
+
/** Whether filling or selecting this field is strictly required before submitting an action */
|
|
23
|
+
required: z.boolean().optional(),
|
|
24
|
+
/** Regular expression string pattern for string validation */
|
|
25
|
+
pattern: z.string().optional(),
|
|
26
|
+
/** Minimum text length requirement */
|
|
27
|
+
minLength: z.number().optional(),
|
|
28
|
+
/** Maximum text length allowed */
|
|
29
|
+
maxLength: z.number().optional(),
|
|
30
|
+
/** Minimum numeric value allowed */
|
|
31
|
+
min: z.number().optional(),
|
|
32
|
+
/** Maximum numeric value allowed */
|
|
33
|
+
max: z.number().optional(),
|
|
34
|
+
/** Custom error message displayed when validation fails */
|
|
35
|
+
errorMessage: z.string().optional(),
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* Data Source Schema for dynamic content (e.g., Select options or dynamic dropdowns).
|
|
39
|
+
*/
|
|
40
|
+
export var DataSourceSchema = z.object({
|
|
41
|
+
/** Source type: 'STATIC' for inline items, 'API' for external fetching, 'VARIABLE' for message data interpolation */
|
|
42
|
+
type: z.enum(['STATIC', 'API', 'VARIABLE']),
|
|
43
|
+
/** For STATIC: explicit list of available options */
|
|
44
|
+
items: z.array(z.object({
|
|
45
|
+
label: z.string(),
|
|
46
|
+
value: z.union([z.string(), z.number(), z.boolean()]),
|
|
47
|
+
})).optional(),
|
|
48
|
+
/** For API: endpoint URL from which items will be fetched */
|
|
49
|
+
url: z.string().optional(),
|
|
50
|
+
/** For API: HTTP request method */
|
|
51
|
+
method: z.enum(['GET', 'POST']).default('GET').optional(),
|
|
52
|
+
/** For API: HTTP headers to send with the fetch request */
|
|
53
|
+
headers: z.record(z.string(), z.string()).optional(),
|
|
54
|
+
/** For VARIABLE: property key inside the custom message `data` object containing option items */
|
|
55
|
+
key: z.string().optional(),
|
|
56
|
+
/** Key mapping configuration when response objects do not natively use `label` and `value` */
|
|
57
|
+
map: z.object({
|
|
58
|
+
label: z.string(),
|
|
59
|
+
value: z.string(),
|
|
60
|
+
}).optional(),
|
|
61
|
+
});
|
|
62
|
+
/**
|
|
63
|
+
* Condition Schema for Visibility and Logical Evaluation.
|
|
64
|
+
*/
|
|
65
|
+
export var ConditionSchema = z.object({
|
|
66
|
+
/** The field ID or path inside data/formState to evaluate */
|
|
67
|
+
field: z.string(),
|
|
68
|
+
/** Comparison operator */
|
|
69
|
+
operator: z.enum(['EQUALS', 'NOT_EQUALS', 'CONTAINS', 'GREATER_THAN', 'LESS_THAN', 'EXISTS', 'NOT_EXISTS']),
|
|
70
|
+
/** Comparison target value */
|
|
71
|
+
value: z.any().optional(),
|
|
72
|
+
});
|
|
73
|
+
/**
|
|
74
|
+
* Theme configuration for Custom Messages enabling developer branding overrides.
|
|
75
|
+
*/
|
|
76
|
+
export var CustomMessageThemeSchema = z.object({
|
|
77
|
+
/** Custom background color (Hex/RGB/HSL/CSS var) */
|
|
78
|
+
backgroundColor: z.string().optional(),
|
|
79
|
+
/** Custom border color */
|
|
80
|
+
borderColor: z.string().optional(),
|
|
81
|
+
/** Primary text color override */
|
|
82
|
+
textColor: z.string().optional(),
|
|
83
|
+
/** Accent / Brand highlight color */
|
|
84
|
+
accentColor: z.string().optional(),
|
|
85
|
+
/** Custom CSS class names applied to the container */
|
|
86
|
+
className: z.string().optional(),
|
|
87
|
+
});
|
|
88
|
+
// Zod Schema for recursive MessageNode
|
|
89
|
+
export var MessageNodeSchema = z.lazy(function () {
|
|
90
|
+
return z.object({
|
|
91
|
+
type: z.string().min(1),
|
|
92
|
+
id: z.string().optional(),
|
|
93
|
+
properties: z.record(z.string(), z.any()).optional(),
|
|
94
|
+
children: z.array(MessageNodeSchema).optional(),
|
|
95
|
+
condition: ConditionSchema.optional(),
|
|
96
|
+
validation: ValidationSchema.optional(),
|
|
97
|
+
metadata: z.record(z.string(), z.any()).optional(),
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
/**
|
|
101
|
+
* Predefined Custom Message Types supported out of the box.
|
|
102
|
+
*/
|
|
103
|
+
export var PredefinedCustomMessageTypeSchema = z.enum([
|
|
104
|
+
'APPROVAL',
|
|
105
|
+
'REPORT',
|
|
106
|
+
'FORM',
|
|
107
|
+
'FEEDBACK',
|
|
108
|
+
'TASK_CARD',
|
|
109
|
+
'SURVEY',
|
|
110
|
+
'GENERIC',
|
|
111
|
+
]);
|
|
112
|
+
/**
|
|
113
|
+
* Action item schema for interactive buttons rendered on custom messages.
|
|
114
|
+
*/
|
|
115
|
+
export var MessageActionSchema = z.object({
|
|
116
|
+
/** Unique action identifier */
|
|
117
|
+
id: z.string(),
|
|
118
|
+
/** Button text label */
|
|
119
|
+
label: z.string(),
|
|
120
|
+
/** Visual variant of the button */
|
|
121
|
+
type: z.enum(['PRIMARY', 'SECONDARY', 'DESTRUCTIVE', 'GHOST']).default('SECONDARY'),
|
|
122
|
+
/** Name of the icon (from Lucide icons library) to render on the button */
|
|
123
|
+
icon: z.string().optional(),
|
|
124
|
+
/** Handler configuration specifying what happens when the action button is clicked */
|
|
125
|
+
handler: z.object({
|
|
126
|
+
/** Action handler type: CALLBACK (sends payload back), LINK (navigates), MODAL (opens modal) */
|
|
127
|
+
type: z.enum(['CALLBACK', 'LINK', 'MODAL']),
|
|
128
|
+
/** Target URL for LINK type actions */
|
|
129
|
+
url: z.string().optional(),
|
|
130
|
+
/** Callback ID for CALLBACK type actions */
|
|
131
|
+
callbackId: z.string().optional(),
|
|
132
|
+
/** Custom key-value payload sent back with the callback */
|
|
133
|
+
payload: z.record(z.string(), z.any()).optional(),
|
|
134
|
+
/** Whether to automatically gather and send all current form input state in the callback payload */
|
|
135
|
+
includeFormState: z.boolean().default(true).optional(),
|
|
136
|
+
}),
|
|
137
|
+
/** Optional visibility condition for displaying this action button */
|
|
138
|
+
condition: ConditionSchema.optional(),
|
|
139
|
+
});
|
|
140
|
+
/**
|
|
141
|
+
* Root Custom Message Schema defining full metadata structures for dynamic & customized UI rendering.
|
|
142
|
+
*/
|
|
143
|
+
export var CustomMessageSchema = z.object({
|
|
144
|
+
/** Schema version string (e.g. "v1") */
|
|
145
|
+
version: z.string().default('v1'),
|
|
146
|
+
/** Optional template identifier reference */
|
|
147
|
+
templateId: z.string().optional(),
|
|
148
|
+
/** The logical message category type (e.g. 'APPROVAL', 'REPORT', 'FORM', 'FEEDBACK', 'TASK_CARD', 'SURVEY', or custom string) */
|
|
149
|
+
type: z.string(),
|
|
150
|
+
/** Top-level configuration, branding, and header context */
|
|
151
|
+
context: z.object({
|
|
152
|
+
/** Main title displayed on the message header */
|
|
153
|
+
title: z.string().min(1),
|
|
154
|
+
/** Optional subtitle or description */
|
|
155
|
+
description: z.string().optional(),
|
|
156
|
+
/** Lucide icon name for the message header */
|
|
157
|
+
icon: z.string().optional(),
|
|
158
|
+
/** Accent color override for header or priority elements */
|
|
159
|
+
color: z.string().optional(),
|
|
160
|
+
/** Priority indicator badge level */
|
|
161
|
+
priority: z.enum(['low', 'normal', 'high', 'urgent']).default('normal'),
|
|
162
|
+
}),
|
|
163
|
+
/** Theme styling configuration for developer customization */
|
|
164
|
+
theme: CustomMessageThemeSchema.optional(),
|
|
165
|
+
/** Hierarchical node tree defining the layout and components */
|
|
166
|
+
root: MessageNodeSchema,
|
|
167
|
+
/** Interactive action buttons attached to the message */
|
|
168
|
+
actions: z.array(MessageActionSchema).optional(),
|
|
169
|
+
/** Data dictionary used for variable interpolation (e.g., `{{user.name}}`) and logic */
|
|
170
|
+
data: z.record(z.string(), z.any()).optional(),
|
|
171
|
+
/** Target restrictions and permissions constraints */
|
|
172
|
+
constraints: z
|
|
173
|
+
.object({
|
|
174
|
+
/** Restrict interactability to specific user IDs */
|
|
175
|
+
targetUsers: z.array(z.string()).optional(),
|
|
176
|
+
/** Required user roles/permissions to execute actions */
|
|
177
|
+
requiresPermissions: z.array(z.string()).optional(),
|
|
178
|
+
/** ISO expiration timestamp after which actions become disabled */
|
|
179
|
+
expiresAt: z.string().datetime().optional(),
|
|
180
|
+
})
|
|
181
|
+
.optional(),
|
|
182
|
+
});
|
|
183
|
+
/**
|
|
184
|
+
* Creates a standard Approval Custom Message schema structure.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* const approvalSchema = createApprovalMessage({
|
|
189
|
+
* title: 'Expense Reimbursement Request',
|
|
190
|
+
* description: 'Requested by Jane Doe for $450.00',
|
|
191
|
+
* fields: [
|
|
192
|
+
* { label: 'Category', value: 'Travel' },
|
|
193
|
+
* { label: 'Amount', value: '$450.00' }
|
|
194
|
+
* ],
|
|
195
|
+
* callbackId: 'expense-approval-101'
|
|
196
|
+
* });
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
export var createApprovalMessage = function (options) { return ({
|
|
200
|
+
version: 'v1',
|
|
201
|
+
type: 'APPROVAL',
|
|
202
|
+
context: {
|
|
203
|
+
title: options.title,
|
|
204
|
+
description: options.description,
|
|
205
|
+
icon: 'CheckSquare',
|
|
206
|
+
priority: options.priority || 'normal',
|
|
207
|
+
},
|
|
208
|
+
theme: options.theme,
|
|
209
|
+
root: {
|
|
210
|
+
type: 'Layout.Card',
|
|
211
|
+
children: [
|
|
212
|
+
{
|
|
213
|
+
type: 'Layout.Grid',
|
|
214
|
+
properties: { columns: 2 },
|
|
215
|
+
children: options.fields.map(function (f) { return ({
|
|
216
|
+
type: 'Display.Field',
|
|
217
|
+
properties: { label: f.label, value: f.value },
|
|
218
|
+
}); }),
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
},
|
|
222
|
+
actions: [
|
|
223
|
+
{
|
|
224
|
+
id: 'approve',
|
|
225
|
+
label: options.approveLabel || 'Approve',
|
|
226
|
+
type: 'PRIMARY',
|
|
227
|
+
icon: 'Check',
|
|
228
|
+
handler: {
|
|
229
|
+
type: 'CALLBACK',
|
|
230
|
+
callbackId: options.callbackId,
|
|
231
|
+
payload: { action: 'approve' },
|
|
232
|
+
includeFormState: true,
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
id: 'reject',
|
|
237
|
+
label: options.rejectLabel || 'Reject',
|
|
238
|
+
type: 'DESTRUCTIVE',
|
|
239
|
+
icon: 'X',
|
|
240
|
+
handler: {
|
|
241
|
+
type: 'CALLBACK',
|
|
242
|
+
callbackId: options.callbackId,
|
|
243
|
+
payload: { action: 'reject' },
|
|
244
|
+
includeFormState: true,
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
],
|
|
248
|
+
data: options.data,
|
|
249
|
+
}); };
|
|
250
|
+
/**
|
|
251
|
+
* Creates a standard Report Custom Message schema structure.
|
|
252
|
+
*/
|
|
253
|
+
export var createReportMessage = function (options) { return ({
|
|
254
|
+
version: 'v1',
|
|
255
|
+
type: 'REPORT',
|
|
256
|
+
context: {
|
|
257
|
+
title: options.title,
|
|
258
|
+
icon: 'BarChart',
|
|
259
|
+
priority: 'normal',
|
|
260
|
+
},
|
|
261
|
+
theme: options.theme,
|
|
262
|
+
root: {
|
|
263
|
+
type: 'Layout.Stack',
|
|
264
|
+
children: [
|
|
265
|
+
{
|
|
266
|
+
type: 'Text.Paragraph',
|
|
267
|
+
properties: { content: options.summary },
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
type: 'Data.StatsGrid',
|
|
271
|
+
children: options.metrics.map(function (m) { return ({
|
|
272
|
+
type: 'Data.Stat',
|
|
273
|
+
properties: { label: m.label, value: m.value },
|
|
274
|
+
}); }),
|
|
275
|
+
},
|
|
276
|
+
],
|
|
277
|
+
},
|
|
278
|
+
actions: [
|
|
279
|
+
{
|
|
280
|
+
id: 'view_details',
|
|
281
|
+
label: 'View Full Report',
|
|
282
|
+
type: 'SECONDARY',
|
|
283
|
+
icon: 'ExternalLink',
|
|
284
|
+
handler: {
|
|
285
|
+
type: 'LINK',
|
|
286
|
+
url: options.viewReportUrl || "/reports/".concat(options.reportId),
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
],
|
|
290
|
+
data: options.data,
|
|
291
|
+
}); };
|
|
292
|
+
/**
|
|
293
|
+
* Creates an interactive Form / Survey / Feedback Custom Message schema structure.
|
|
294
|
+
*/
|
|
295
|
+
export var createFormMessage = function (options) { return ({
|
|
296
|
+
version: 'v1',
|
|
297
|
+
type: options.type || 'FORM',
|
|
298
|
+
context: {
|
|
299
|
+
title: options.title,
|
|
300
|
+
description: options.description,
|
|
301
|
+
icon: options.type === 'FEEDBACK' ? 'HelpCircle' : 'FileText',
|
|
302
|
+
priority: 'normal',
|
|
303
|
+
},
|
|
304
|
+
theme: options.theme,
|
|
305
|
+
root: {
|
|
306
|
+
type: 'Layout.Stack',
|
|
307
|
+
children: options.fields.map(function (field) {
|
|
308
|
+
var nodeType = field.type === 'select'
|
|
309
|
+
? 'Input.Select'
|
|
310
|
+
: field.type === 'checkbox'
|
|
311
|
+
? 'Input.Checkbox'
|
|
312
|
+
: 'Input.Text';
|
|
313
|
+
var validation = field.required
|
|
314
|
+
? { required: true, errorMessage: "".concat(field.label, " is required") }
|
|
315
|
+
: undefined;
|
|
316
|
+
var properties = {
|
|
317
|
+
label: field.label,
|
|
318
|
+
placeholder: field.placeholder,
|
|
319
|
+
};
|
|
320
|
+
if (field.type === 'textarea') {
|
|
321
|
+
properties.multiline = true;
|
|
322
|
+
}
|
|
323
|
+
if (field.type === 'select' && field.options) {
|
|
324
|
+
properties.dataSource = {
|
|
325
|
+
type: 'STATIC',
|
|
326
|
+
items: field.options,
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
type: nodeType,
|
|
331
|
+
id: field.id,
|
|
332
|
+
properties: properties,
|
|
333
|
+
validation: validation,
|
|
334
|
+
};
|
|
335
|
+
}),
|
|
336
|
+
},
|
|
337
|
+
actions: [
|
|
338
|
+
{
|
|
339
|
+
id: 'submit',
|
|
340
|
+
label: options.submitLabel || 'Submit',
|
|
341
|
+
type: 'PRIMARY',
|
|
342
|
+
icon: 'Send',
|
|
343
|
+
handler: {
|
|
344
|
+
type: 'CALLBACK',
|
|
345
|
+
callbackId: options.submitCallbackId,
|
|
346
|
+
payload: { action: 'submit' },
|
|
347
|
+
includeFormState: true,
|
|
348
|
+
},
|
|
349
|
+
},
|
|
350
|
+
],
|
|
351
|
+
data: options.data,
|
|
352
|
+
}); };
|
|
353
|
+
/**
|
|
354
|
+
* Creates a Task Card Custom Message schema structure.
|
|
355
|
+
*/
|
|
356
|
+
export var createTaskCardMessage = function (options) { return ({
|
|
357
|
+
version: 'v1',
|
|
358
|
+
type: 'TASK_CARD',
|
|
359
|
+
context: {
|
|
360
|
+
title: options.title,
|
|
361
|
+
description: options.description,
|
|
362
|
+
icon: 'CheckSquare',
|
|
363
|
+
priority: 'normal',
|
|
364
|
+
},
|
|
365
|
+
theme: options.theme,
|
|
366
|
+
root: {
|
|
367
|
+
type: 'Layout.Stack',
|
|
368
|
+
children: [
|
|
369
|
+
{
|
|
370
|
+
type: 'Layout.Grid',
|
|
371
|
+
properties: { columns: 3 },
|
|
372
|
+
children: [
|
|
373
|
+
{ type: 'Display.Field', properties: { label: 'Status', value: options.status } },
|
|
374
|
+
{ type: 'Display.Field', properties: { label: 'Assignee', value: options.assignee || 'Unassigned' } },
|
|
375
|
+
{ type: 'Display.Field', properties: { label: 'Due Date', value: options.dueDate || 'None' } },
|
|
376
|
+
],
|
|
377
|
+
},
|
|
378
|
+
],
|
|
379
|
+
},
|
|
380
|
+
actions: [
|
|
381
|
+
{
|
|
382
|
+
id: 'complete_task',
|
|
383
|
+
label: 'Mark Completed',
|
|
384
|
+
type: 'PRIMARY',
|
|
385
|
+
icon: 'Check',
|
|
386
|
+
handler: {
|
|
387
|
+
type: 'CALLBACK',
|
|
388
|
+
callbackId: options.callbackId,
|
|
389
|
+
payload: { action: 'complete' },
|
|
390
|
+
includeFormState: false,
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
],
|
|
394
|
+
data: options.data,
|
|
395
|
+
}); };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from './custom-instance';
|
|
2
2
|
export * from './generated/v3-client';
|
|
3
3
|
export * from './sdk';
|
|
4
|
-
export { CustomMessageSchema, MessageNodeSchema, ConditionSchema, ValidationSchema, DataSourceSchema, CustomMessageThemeSchema, PredefinedCustomMessageTypeSchema, MessageActionSchema, createApprovalMessage, createReportMessage, createFormMessage, createTaskCardMessage, type CustomMessage, type MessageNode, type ConditionSchemaType, type ValidationSchemaType, type CustomMessageTheme, type PredefinedCustomMessageType, type MessageAction, type CreateApprovalMessageOptions, type CreateReportMessageOptions, type CreateFormMessageOptions, type CreateTaskCardMessageOptions, type FormFieldConfig, } from '
|
|
4
|
+
export { CustomMessageSchema, MessageNodeSchema, ConditionSchema, ValidationSchema, DataSourceSchema, CustomMessageThemeSchema, PredefinedCustomMessageTypeSchema, MessageActionSchema, createApprovalMessage, createReportMessage, createFormMessage, createTaskCardMessage, type CustomMessage, type MessageNode, type ConditionSchemaType, type ValidationSchemaType, type CustomMessageTheme, type PredefinedCustomMessageType, type MessageAction, type CreateApprovalMessageOptions, type CreateReportMessageOptions, type CreateFormMessageOptions, type CreateTaskCardMessageOptions, type FormFieldConfig, } from './custom-message-schema';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from './custom-instance';
|
|
2
2
|
export * from './generated/v3-client';
|
|
3
3
|
export * from './sdk';
|
|
4
|
-
export { CustomMessageSchema, MessageNodeSchema, ConditionSchema, ValidationSchema, DataSourceSchema, CustomMessageThemeSchema, PredefinedCustomMessageTypeSchema, MessageActionSchema, createApprovalMessage, createReportMessage, createFormMessage, createTaskCardMessage, } from '
|
|
4
|
+
export { CustomMessageSchema, MessageNodeSchema, ConditionSchema, ValidationSchema, DataSourceSchema, CustomMessageThemeSchema, PredefinedCustomMessageTypeSchema, MessageActionSchema, createApprovalMessage, createReportMessage, createFormMessage, createTaskCardMessage, } from './custom-message-schema';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scryme/chat",
|
|
3
|
-
"version": "2.91.
|
|
3
|
+
"version": "2.91.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@tanstack/react-query": "5.96.2",
|
|
31
31
|
"axios": "^1.7.9",
|
|
32
|
-
"
|
|
32
|
+
"zod": "^3.23.8"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"react": "^18.0.0 || ^19.0.0"
|