@dolard.eu/versiq-widget 0.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,47 @@
1
+ /**
2
+ * postMessage Protocol
3
+ *
4
+ * Handles secure bidirectional communication between the parent page
5
+ * and the widget iframe using the postMessage API.
6
+ */
7
+ import type { WidgetCommand, WidgetEvent } from "./types";
8
+ /**
9
+ * Validate that a message origin is trusted.
10
+ */
11
+ export declare function isValidOrigin(origin: string, allowedOrigins: string[]): boolean;
12
+ /**
13
+ * Check if an event contains a valid Versiq message.
14
+ */
15
+ export declare function isVersiqMessage(event: MessageEvent): event is MessageEvent<WidgetCommand | WidgetEvent>;
16
+ /**
17
+ * Send a command to the widget iframe.
18
+ */
19
+ export declare function sendCommand(iframe: HTMLIFrameElement, command: WidgetCommand, targetOrigin: string): void;
20
+ /**
21
+ * Send an event to the parent window.
22
+ * Used by the embedded widget to notify the parent of state changes.
23
+ */
24
+ export declare function sendEvent(event: WidgetEvent, targetOrigin: string): void;
25
+ export interface MessageListenerOptions {
26
+ /** Allowed origins for incoming messages */
27
+ allowedOrigins?: string[];
28
+ /** Callback for received messages */
29
+ onMessage: (message: WidgetCommand | WidgetEvent, origin: string) => void;
30
+ /** Enable debug logging */
31
+ debug?: boolean;
32
+ /** Only accept messages from this window (for multi-instance isolation) */
33
+ sourceWindow?: Window | null;
34
+ }
35
+ /**
36
+ * Create a message listener with origin validation.
37
+ * Returns a cleanup function to remove the listener.
38
+ */
39
+ export declare function createMessageListener(options: MessageListenerOptions): () => void;
40
+ /**
41
+ * Encode theme config for URL parameter.
42
+ */
43
+ export declare function encodeTheme(theme: object): string;
44
+ /**
45
+ * Decode theme config from URL parameter.
46
+ */
47
+ export declare function decodeTheme<T>(encoded: string): T | null;
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Widget SDK Types
3
+ *
4
+ * Cross-workspace contracts (viewport, theme, widget config, application
5
+ * config, postMessage protocol) now live in `@dolard.eu/versiq-core-types` — this file
6
+ * re-exports them so existing consumers (`apps/marketing`,
7
+ * `apps/app/src/components/portal/sandbox`) keep working unchanged. The only
8
+ * types still defined locally are widget-specific SDK surfaces (B2B profile
9
+ * schemas, `VersiqAPI`, `window` augmentation).
10
+ */
11
+ import { z } from "zod";
12
+ import type { ColorScheme, ThemeConfig, WidgetEventHandler, WidgetEventType } from "@dolard.eu/versiq-core-types";
13
+ export { applicationConfigResponseSchema, breakpointsConfigSchema, MESSAGE_TYPES, messageRoleSchema, resolveTheme, responsiveConfigSchema, themeConfigSchema, viewportModeSchema, widgetConfigSchema, widgetMessageSchema, widgetPositionSchema, } from "@dolard.eu/versiq-core-types";
14
+ export type { ApplicationConfigResponse, BreakpointsConfig, ColorScheme, MessageRole, MessageType, ResolvedTheme, ResponsiveConfig, ThemeConfig, ThemeDefaults, ViewportMode, WidgetCommand, WidgetConfig, WidgetEvent, WidgetEventHandler, WidgetEventType, WidgetMessage, WidgetPosition, WidgetProfile, } from "@dolard.eu/versiq-core-types";
15
+ /**
16
+ * User type enum.
17
+ */
18
+ export declare const b2bUserTypeSchema: z.ZodEnum<{
19
+ prospect: "prospect";
20
+ partner: "partner";
21
+ unknown: "unknown";
22
+ }>;
23
+ /**
24
+ * Business sector enum.
25
+ */
26
+ export declare const b2bSectorSchema: z.ZodEnum<{
27
+ ecommerce: "ecommerce";
28
+ "real-estate": "real-estate";
29
+ automotive: "automotive";
30
+ travel: "travel";
31
+ recruitment: "recruitment";
32
+ other: "other";
33
+ }>;
34
+ /**
35
+ * Company size enum.
36
+ */
37
+ export declare const b2bCompanySizeSchema: z.ZodEnum<{
38
+ startup: "startup";
39
+ pme: "pme";
40
+ eti: "eti";
41
+ "grand-groupe": "grand-groupe";
42
+ }>;
43
+ /**
44
+ * Monthly traffic enum.
45
+ */
46
+ export declare const b2bMonthlyTrafficSchema: z.ZodEnum<{
47
+ "< 10k": "< 10k";
48
+ "10k-50k": "10k-50k";
49
+ "50k-200k": "50k-200k";
50
+ "> 200k": "> 200k";
51
+ }>;
52
+ /**
53
+ * Business objectives enum.
54
+ */
55
+ export declare const b2bObjectiveSchema: z.ZodEnum<{
56
+ other: "other";
57
+ "lead-qualification": "lead-qualification";
58
+ personalization: "personalization";
59
+ "cart-abandonment": "cart-abandonment";
60
+ conversion: "conversion";
61
+ }>;
62
+ /**
63
+ * E-commerce platform enum.
64
+ */
65
+ export declare const b2bPlatformSchema: z.ZodEnum<{
66
+ shopify: "shopify";
67
+ woocommerce: "woocommerce";
68
+ prestashop: "prestashop";
69
+ custom: "custom";
70
+ none: "none";
71
+ }>;
72
+ /**
73
+ * Implementation timeline enum.
74
+ */
75
+ export declare const b2bTimelineSchema: z.ZodEnum<{
76
+ immediate: "immediate";
77
+ "1-month": "1-month";
78
+ "3-months": "3-months";
79
+ exploring: "exploring";
80
+ }>;
81
+ /**
82
+ * Budget range enum.
83
+ */
84
+ export declare const b2bBudgetRangeSchema: z.ZodEnum<{
85
+ "< 500": "< 500";
86
+ "500-2000": "500-2000";
87
+ "2000-5000": "2000-5000";
88
+ "> 5000": "> 5000";
89
+ }>;
90
+ /**
91
+ * B2B qualification profile schema.
92
+ */
93
+ export declare const b2bProfileSchema: z.ZodObject<{
94
+ userType: z.ZodOptional<z.ZodEnum<{
95
+ prospect: "prospect";
96
+ partner: "partner";
97
+ unknown: "unknown";
98
+ }>>;
99
+ sector: z.ZodOptional<z.ZodEnum<{
100
+ ecommerce: "ecommerce";
101
+ "real-estate": "real-estate";
102
+ automotive: "automotive";
103
+ travel: "travel";
104
+ recruitment: "recruitment";
105
+ other: "other";
106
+ }>>;
107
+ companySize: z.ZodOptional<z.ZodEnum<{
108
+ startup: "startup";
109
+ pme: "pme";
110
+ eti: "eti";
111
+ "grand-groupe": "grand-groupe";
112
+ }>>;
113
+ monthlyTraffic: z.ZodOptional<z.ZodEnum<{
114
+ "< 10k": "< 10k";
115
+ "10k-50k": "10k-50k";
116
+ "50k-200k": "50k-200k";
117
+ "> 200k": "> 200k";
118
+ }>>;
119
+ objectives: z.ZodOptional<z.ZodArray<z.ZodEnum<{
120
+ other: "other";
121
+ "lead-qualification": "lead-qualification";
122
+ personalization: "personalization";
123
+ "cart-abandonment": "cart-abandonment";
124
+ conversion: "conversion";
125
+ }>>>;
126
+ platform: z.ZodOptional<z.ZodEnum<{
127
+ shopify: "shopify";
128
+ woocommerce: "woocommerce";
129
+ prestashop: "prestashop";
130
+ custom: "custom";
131
+ none: "none";
132
+ }>>;
133
+ timeline: z.ZodOptional<z.ZodEnum<{
134
+ immediate: "immediate";
135
+ "1-month": "1-month";
136
+ "3-months": "3-months";
137
+ exploring: "exploring";
138
+ }>>;
139
+ budgetRange: z.ZodOptional<z.ZodEnum<{
140
+ "< 500": "< 500";
141
+ "500-2000": "500-2000";
142
+ "2000-5000": "2000-5000";
143
+ "> 5000": "> 5000";
144
+ }>>;
145
+ }, z.core.$strip>;
146
+ export type B2BProfile = z.infer<typeof b2bProfileSchema>;
147
+ /**
148
+ * Public API exposed on window.Versiq.
149
+ */
150
+ export interface VersiqAPI {
151
+ /** Application ID (available after config resolution) */
152
+ readonly applicationId: string;
153
+ /** Open the widget */
154
+ open(): void;
155
+ /** Close the widget */
156
+ close(): void;
157
+ /** Reset the conversation */
158
+ reset(): void;
159
+ /** Update theme dynamically */
160
+ setTheme(theme: ThemeConfig): void;
161
+ /**
162
+ * Update only the color scheme. Sugar over setTheme({ colorScheme }) so
163
+ * integrators can wire their own dark-mode toggle without rebuilding the
164
+ * full theme object: `window.Versiq.setColorScheme("dark")`.
165
+ */
166
+ setColorScheme(scheme: ColorScheme): void;
167
+ /** Identify the current user with host-attested HMAC verification */
168
+ identify(params: {
169
+ email: string;
170
+ userId?: string;
171
+ userHash: string;
172
+ }): void;
173
+ /** Subscribe to events */
174
+ on<T = unknown>(event: WidgetEventType, handler: WidgetEventHandler<T>): void;
175
+ /** Unsubscribe from events */
176
+ off<T = unknown>(event: WidgetEventType, handler: WidgetEventHandler<T>): void;
177
+ /** Widget version */
178
+ version: string;
179
+ }
180
+ declare global {
181
+ interface Window {
182
+ Versiq?: VersiqAPI;
183
+ VersiqApps?: Map<string, VersiqAPI>;
184
+ }
185
+ }