veo-sdk 0.1.0 → 0.2.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.
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Tipos consumidos por el plugin de guides. Reflejan el shape que devuelve
3
+ * `GET /v1/guides/resolve` en el backend — debe mantenerse en sync con
4
+ * `veo-backend/src/modules/guides/types/guide-content.types.ts` y
5
+ * `guide.response.ts`.
6
+ */
7
+ type GuideType = 'modal' | 'banner' | 'tooltip' | 'walkthrough' | 'custom' | 'inline' | 'inline-custom' | 'form' | 'inline-form';
8
+ type FormFieldType = 'text' | 'textarea' | 'number' | 'select' | 'multiselect' | 'radio' | 'checkbox' | 'yesno' | 'nps' | 'rating';
9
+ /**
10
+ * Un campo de una guía `form`. `key` es el nombre de la PROPIEDAD que se
11
+ * escribe en los traits del usuario que responde (encuesta/NPS estilo Pendo).
12
+ */
13
+ interface FormField {
14
+ key: string;
15
+ label: string;
16
+ type: FormFieldType;
17
+ /** Para select/radio: opciones visibles (el valor guardado es el texto). */
18
+ options?: string[] | null;
19
+ required?: boolean | null;
20
+ placeholder?: string | null;
21
+ }
22
+ type CustomPlacementMode = 'floating' | 'anchored';
23
+ type CustomFloatingPosition = 'top-left' | 'top-center' | 'top-right' | 'center' | 'bottom-left' | 'bottom-center' | 'bottom-right';
24
+ type CustomAnchorSide = 'top' | 'bottom' | 'left' | 'right';
25
+ /** Dónde se monta una guía `custom`. Ver backend `guide-content.types.ts`. */
26
+ interface CustomPlacement {
27
+ mode: CustomPlacementMode;
28
+ position?: CustomFloatingPosition;
29
+ offsetX?: number;
30
+ offsetY?: number;
31
+ selector?: string;
32
+ side?: CustomAnchorSide;
33
+ width?: number | string;
34
+ height?: number | string;
35
+ }
36
+ type UrlMatchType = 'exact' | 'prefix' | 'regex';
37
+ type ActivationTrigger = 'immediate' | 'on_element' | 'on_event' | 'delayed';
38
+ type CtaAction = 'dismiss' | 'next' | 'url';
39
+ interface UrlMatcher {
40
+ type: UrlMatchType;
41
+ pattern: string;
42
+ }
43
+ interface ActivationRules {
44
+ url: UrlMatcher;
45
+ trigger: ActivationTrigger;
46
+ selector?: string;
47
+ eventName?: string;
48
+ delayMs?: number;
49
+ }
50
+ interface GuideStep {
51
+ title: string;
52
+ content: string;
53
+ ctaText?: string | null;
54
+ ctaAction?: CtaAction | null;
55
+ imageUrl?: string | null;
56
+ selector?: string | null;
57
+ /**
58
+ * Free-form JSONB. Convención: si `ctaAction === 'url'`, la URL destino
59
+ * se lee de `style.ctaUrl`. Otras keys que puede traer: `position`
60
+ * (`top` | `bottom` para banners), `theme`.
61
+ */
62
+ style?: Record<string, unknown> | null;
63
+ /** Solo guías `custom`: código a renderizar en un iframe sandbox + ubicación. */
64
+ html?: string | null;
65
+ css?: string | null;
66
+ js?: string | null;
67
+ placement?: CustomPlacement | null;
68
+ /** Solo guías `form`: los campos del formulario. */
69
+ fields?: FormField[] | null;
70
+ }
71
+
72
+ /** Entrada mínima para previsualizar una guía. */
73
+ interface PreviewGuideInput {
74
+ guideType: GuideType;
75
+ guideSteps: GuideStep[];
76
+ /**
77
+ * Opcional. Solo se usa `activationRules.selector` como fallback del
78
+ * ancla para tooltip/walkthrough cuando el step no trae su propio
79
+ * `selector`. El resto de reglas (url/trigger/delay) se ignoran.
80
+ */
81
+ activationRules?: Partial<ActivationRules>;
82
+ /** Nombre mostrado (p.ej. en el `title` del iframe de guías `custom`). */
83
+ guideName?: string;
84
+ /**
85
+ * Solo walkthrough: paso inicial a mostrar (default 0). Lo usa el editor del
86
+ * dashboard para que la preview salte al paso que se está editando.
87
+ */
88
+ startStepIndex?: number;
89
+ /**
90
+ * Solo guías form: envío REAL de respuestas. Sin esto, el submit en preview
91
+ * es un no-op (no escribe props). Lo usa el modo preview-por-link, que sí
92
+ * guarda en el usuario que responde.
93
+ */
94
+ formSubmit?: (answers: Record<string, unknown>) => Promise<boolean>;
95
+ /** Nota bajo el "¡Gracias!" cuando hay `formSubmit` propio. */
96
+ formSubmitNote?: string;
97
+ }
98
+ /** Resultado del primer render de una preview. */
99
+ interface PreviewResult {
100
+ /**
101
+ * `false` cuando la guía no pudo pintarse — típicamente un
102
+ * tooltip/walkthrough cuyo `selector` no existe en la página de preview.
103
+ */
104
+ rendered: boolean;
105
+ }
106
+ /** Handle de una preview activa. */
107
+ interface PreviewHandle {
108
+ /** Cierra y limpia la preview. Idempotente. */
109
+ close(): void;
110
+ /** Resuelve cuando el primer render terminó. */
111
+ ready: Promise<PreviewResult>;
112
+ }
113
+ /**
114
+ * Previsualiza una guía en la página actual usando los renderers reales
115
+ * del SDK. Devuelve un handle con `close()` y una promesa `ready`.
116
+ *
117
+ * Pensado para el builder no-code: no necesita `init()` ni apiKey. Abrir
118
+ * una nueva preview cierra automáticamente la anterior.
119
+ *
120
+ * @example
121
+ * ```ts
122
+ * import { previewGuide } from '@veo/sdk';
123
+ *
124
+ * const preview = previewGuide({
125
+ * guideType: 'modal',
126
+ * guideSteps: [{ title: 'Hola', content: 'Esto es una preview' }],
127
+ * });
128
+ * const { rendered } = await preview.ready;
129
+ * // ...más tarde:
130
+ * preview.close();
131
+ * ```
132
+ */
133
+ declare function previewGuide(input: PreviewGuideInput): PreviewHandle;
134
+ /** Cierra la preview activa, si la hay. Idempotente. */
135
+ declare function closeGuidePreview(): void;
136
+
137
+ export { type PreviewGuideInput as P, type PreviewHandle as a, type PreviewResult as b, closeGuidePreview as c, previewGuide as p };
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Tipos consumidos por el plugin de guides. Reflejan el shape que devuelve
3
+ * `GET /v1/guides/resolve` en el backend — debe mantenerse en sync con
4
+ * `veo-backend/src/modules/guides/types/guide-content.types.ts` y
5
+ * `guide.response.ts`.
6
+ */
7
+ type GuideType = 'modal' | 'banner' | 'tooltip' | 'walkthrough' | 'custom' | 'inline' | 'inline-custom' | 'form' | 'inline-form';
8
+ type FormFieldType = 'text' | 'textarea' | 'number' | 'select' | 'multiselect' | 'radio' | 'checkbox' | 'yesno' | 'nps' | 'rating';
9
+ /**
10
+ * Un campo de una guía `form`. `key` es el nombre de la PROPIEDAD que se
11
+ * escribe en los traits del usuario que responde (encuesta/NPS estilo Pendo).
12
+ */
13
+ interface FormField {
14
+ key: string;
15
+ label: string;
16
+ type: FormFieldType;
17
+ /** Para select/radio: opciones visibles (el valor guardado es el texto). */
18
+ options?: string[] | null;
19
+ required?: boolean | null;
20
+ placeholder?: string | null;
21
+ }
22
+ type CustomPlacementMode = 'floating' | 'anchored';
23
+ type CustomFloatingPosition = 'top-left' | 'top-center' | 'top-right' | 'center' | 'bottom-left' | 'bottom-center' | 'bottom-right';
24
+ type CustomAnchorSide = 'top' | 'bottom' | 'left' | 'right';
25
+ /** Dónde se monta una guía `custom`. Ver backend `guide-content.types.ts`. */
26
+ interface CustomPlacement {
27
+ mode: CustomPlacementMode;
28
+ position?: CustomFloatingPosition;
29
+ offsetX?: number;
30
+ offsetY?: number;
31
+ selector?: string;
32
+ side?: CustomAnchorSide;
33
+ width?: number | string;
34
+ height?: number | string;
35
+ }
36
+ type UrlMatchType = 'exact' | 'prefix' | 'regex';
37
+ type ActivationTrigger = 'immediate' | 'on_element' | 'on_event' | 'delayed';
38
+ type CtaAction = 'dismiss' | 'next' | 'url';
39
+ interface UrlMatcher {
40
+ type: UrlMatchType;
41
+ pattern: string;
42
+ }
43
+ interface ActivationRules {
44
+ url: UrlMatcher;
45
+ trigger: ActivationTrigger;
46
+ selector?: string;
47
+ eventName?: string;
48
+ delayMs?: number;
49
+ }
50
+ interface GuideStep {
51
+ title: string;
52
+ content: string;
53
+ ctaText?: string | null;
54
+ ctaAction?: CtaAction | null;
55
+ imageUrl?: string | null;
56
+ selector?: string | null;
57
+ /**
58
+ * Free-form JSONB. Convención: si `ctaAction === 'url'`, la URL destino
59
+ * se lee de `style.ctaUrl`. Otras keys que puede traer: `position`
60
+ * (`top` | `bottom` para banners), `theme`.
61
+ */
62
+ style?: Record<string, unknown> | null;
63
+ /** Solo guías `custom`: código a renderizar en un iframe sandbox + ubicación. */
64
+ html?: string | null;
65
+ css?: string | null;
66
+ js?: string | null;
67
+ placement?: CustomPlacement | null;
68
+ /** Solo guías `form`: los campos del formulario. */
69
+ fields?: FormField[] | null;
70
+ }
71
+
72
+ /** Entrada mínima para previsualizar una guía. */
73
+ interface PreviewGuideInput {
74
+ guideType: GuideType;
75
+ guideSteps: GuideStep[];
76
+ /**
77
+ * Opcional. Solo se usa `activationRules.selector` como fallback del
78
+ * ancla para tooltip/walkthrough cuando el step no trae su propio
79
+ * `selector`. El resto de reglas (url/trigger/delay) se ignoran.
80
+ */
81
+ activationRules?: Partial<ActivationRules>;
82
+ /** Nombre mostrado (p.ej. en el `title` del iframe de guías `custom`). */
83
+ guideName?: string;
84
+ /**
85
+ * Solo walkthrough: paso inicial a mostrar (default 0). Lo usa el editor del
86
+ * dashboard para que la preview salte al paso que se está editando.
87
+ */
88
+ startStepIndex?: number;
89
+ /**
90
+ * Solo guías form: envío REAL de respuestas. Sin esto, el submit en preview
91
+ * es un no-op (no escribe props). Lo usa el modo preview-por-link, que sí
92
+ * guarda en el usuario que responde.
93
+ */
94
+ formSubmit?: (answers: Record<string, unknown>) => Promise<boolean>;
95
+ /** Nota bajo el "¡Gracias!" cuando hay `formSubmit` propio. */
96
+ formSubmitNote?: string;
97
+ }
98
+ /** Resultado del primer render de una preview. */
99
+ interface PreviewResult {
100
+ /**
101
+ * `false` cuando la guía no pudo pintarse — típicamente un
102
+ * tooltip/walkthrough cuyo `selector` no existe en la página de preview.
103
+ */
104
+ rendered: boolean;
105
+ }
106
+ /** Handle de una preview activa. */
107
+ interface PreviewHandle {
108
+ /** Cierra y limpia la preview. Idempotente. */
109
+ close(): void;
110
+ /** Resuelve cuando el primer render terminó. */
111
+ ready: Promise<PreviewResult>;
112
+ }
113
+ /**
114
+ * Previsualiza una guía en la página actual usando los renderers reales
115
+ * del SDK. Devuelve un handle con `close()` y una promesa `ready`.
116
+ *
117
+ * Pensado para el builder no-code: no necesita `init()` ni apiKey. Abrir
118
+ * una nueva preview cierra automáticamente la anterior.
119
+ *
120
+ * @example
121
+ * ```ts
122
+ * import { previewGuide } from '@veo/sdk';
123
+ *
124
+ * const preview = previewGuide({
125
+ * guideType: 'modal',
126
+ * guideSteps: [{ title: 'Hola', content: 'Esto es una preview' }],
127
+ * });
128
+ * const { rendered } = await preview.ready;
129
+ * // ...más tarde:
130
+ * preview.close();
131
+ * ```
132
+ */
133
+ declare function previewGuide(input: PreviewGuideInput): PreviewHandle;
134
+ /** Cierra la preview activa, si la hay. Idempotente. */
135
+ declare function closeGuidePreview(): void;
136
+
137
+ export { type PreviewGuideInput as P, type PreviewHandle as a, type PreviewResult as b, closeGuidePreview as c, previewGuide as p };