@dolard.eu/versiq-core-types 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.
- package/LICENSE +48 -0
- package/dist/application-config.d.ts +64 -0
- package/dist/application-config.js +45 -0
- package/dist/geo.d.ts +24 -0
- package/dist/geo.js +25 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +18 -0
- package/dist/postmessage.d.ts +137 -0
- package/dist/postmessage.js +63 -0
- package/dist/theme-resolver.d.ts +54 -0
- package/dist/theme-resolver.js +40 -0
- package/dist/theme.d.ts +22 -0
- package/dist/theme.js +39 -0
- package/dist/viewport.d.ts +32 -0
- package/dist/viewport.js +36 -0
- package/dist/widget-config.d.ts +44 -0
- package/dist/widget-config.js +62 -0
- package/dist/widget-runtime-config.d.ts +48 -0
- package/dist/widget-runtime-config.js +63 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Versiq Core Types — Commercial Source-available License
|
|
2
|
+
========================================================
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2024-2026 Sébastien Dolard
|
|
5
|
+
|
|
6
|
+
This package ships TypeScript type contracts and Zod schemas consumed by the
|
|
7
|
+
Versiq Widget SDK. It is published under the same license as the widget
|
|
8
|
+
bundle so that TypeScript integrators get a working type tree when they
|
|
9
|
+
install `@dolard.eu/versiq-widget`.
|
|
10
|
+
|
|
11
|
+
1. Permitted use
|
|
12
|
+
You may, without separate written agreement:
|
|
13
|
+
(a) Install this package as a transitive dependency of
|
|
14
|
+
`@dolard.eu/versiq-widget` via standard package managers.
|
|
15
|
+
(b) Import the exported types and Zod schemas in client-side or
|
|
16
|
+
server-side code that interoperates with the Versiq backend API.
|
|
17
|
+
|
|
18
|
+
2. Prohibited without prior written agreement
|
|
19
|
+
You may not, in whole or in part:
|
|
20
|
+
(a) Modify, fork, or create derivative works for redistribution under
|
|
21
|
+
any name.
|
|
22
|
+
(b) Redistribute the package, or any derivative, under a different
|
|
23
|
+
package name, namespace, or scope.
|
|
24
|
+
(c) Use these contracts to design or implement a competing widget SDK,
|
|
25
|
+
qualification backend, or conversation orchestration product.
|
|
26
|
+
(d) Remove, alter, or obscure copyright notices, attribution, or this
|
|
27
|
+
license file from any copy.
|
|
28
|
+
|
|
29
|
+
3. Production use
|
|
30
|
+
Use of the corresponding Versiq backend in production is subject to the
|
|
31
|
+
Versiq Commercial Terms of Service. The license granted here is for the
|
|
32
|
+
type contracts only; it does not authorize backend access.
|
|
33
|
+
|
|
34
|
+
4. No warranty
|
|
35
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
36
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
37
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
|
38
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
39
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
40
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
41
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
42
|
+
|
|
43
|
+
5. Termination
|
|
44
|
+
Any breach of section 2 terminates your rights under section 1
|
|
45
|
+
immediately, without notice, and you must cease all use of the software
|
|
46
|
+
and destroy all copies in your possession or control.
|
|
47
|
+
|
|
48
|
+
For commercial licensing or written-agreement inquiries: admin@dolard.eu
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Application bootstrap config returned by `GET /api/application/config`.
|
|
3
|
+
*
|
|
4
|
+
* The app (`apps/app`) produces this response through a stricter server-side
|
|
5
|
+
* whitelist schema (`publicApplicationConfigSchema` in the route), and the
|
|
6
|
+
* widget (`@dolard.eu/versiq-widget`) consumes it here. Keeping the widget-side Zod
|
|
7
|
+
* schema as the canonical shape prevents drift — the server schema MUST remain
|
|
8
|
+
* a compatible subset (it may be stricter, never more permissive).
|
|
9
|
+
*/
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
export declare const applicationConfigResponseSchema: z.ZodObject<{
|
|
12
|
+
applicationId: z.ZodString;
|
|
13
|
+
applicationSlug: z.ZodString;
|
|
14
|
+
applicationName: z.ZodString;
|
|
15
|
+
vertical: z.ZodString;
|
|
16
|
+
theme: z.ZodNullable<z.ZodObject<{
|
|
17
|
+
primaryColor: z.ZodOptional<z.ZodString>;
|
|
18
|
+
backgroundColor: z.ZodOptional<z.ZodString>;
|
|
19
|
+
textColor: z.ZodOptional<z.ZodString>;
|
|
20
|
+
borderRadius: z.ZodOptional<z.ZodNumber>;
|
|
21
|
+
fontFamily: z.ZodOptional<z.ZodString>;
|
|
22
|
+
colorScheme: z.ZodOptional<z.ZodEnum<{
|
|
23
|
+
light: "light";
|
|
24
|
+
dark: "dark";
|
|
25
|
+
auto: "auto";
|
|
26
|
+
}>>;
|
|
27
|
+
}, z.core.$strip>>;
|
|
28
|
+
allowedOrigins: z.ZodArray<z.ZodString>;
|
|
29
|
+
monitoring: z.ZodBoolean;
|
|
30
|
+
primaryObjective: z.ZodNullable<z.ZodObject<{
|
|
31
|
+
id: z.ZodString;
|
|
32
|
+
type: z.ZodString;
|
|
33
|
+
label: z.ZodString;
|
|
34
|
+
ctaLabel: z.ZodNullable<z.ZodString>;
|
|
35
|
+
}, z.core.$strip>>;
|
|
36
|
+
identityVerificationRequired: z.ZodBoolean;
|
|
37
|
+
widget: z.ZodNullable<z.ZodObject<{
|
|
38
|
+
theme: z.ZodOptional<z.ZodObject<{
|
|
39
|
+
primaryColor: z.ZodOptional<z.ZodString>;
|
|
40
|
+
backgroundColor: z.ZodOptional<z.ZodString>;
|
|
41
|
+
textColor: z.ZodOptional<z.ZodString>;
|
|
42
|
+
borderRadius: z.ZodOptional<z.ZodNumber>;
|
|
43
|
+
fontFamily: z.ZodOptional<z.ZodString>;
|
|
44
|
+
colorScheme: z.ZodOptional<z.ZodEnum<{
|
|
45
|
+
light: "light";
|
|
46
|
+
dark: "dark";
|
|
47
|
+
auto: "auto";
|
|
48
|
+
}>>;
|
|
49
|
+
}, z.core.$strip>>;
|
|
50
|
+
position: z.ZodOptional<z.ZodEnum<{
|
|
51
|
+
"bottom-right": "bottom-right";
|
|
52
|
+
"bottom-left": "bottom-left";
|
|
53
|
+
inline: "inline";
|
|
54
|
+
}>>;
|
|
55
|
+
language: z.ZodOptional<z.ZodString>;
|
|
56
|
+
showProfile: z.ZodOptional<z.ZodBoolean>;
|
|
57
|
+
open: z.ZodOptional<z.ZodBoolean>;
|
|
58
|
+
brand: z.ZodOptional<z.ZodObject<{
|
|
59
|
+
title: z.ZodOptional<z.ZodString>;
|
|
60
|
+
avatarUrl: z.ZodOptional<z.ZodString>;
|
|
61
|
+
}, z.core.$strict>>;
|
|
62
|
+
}, z.core.$strict>>;
|
|
63
|
+
}, z.core.$strip>;
|
|
64
|
+
export type ApplicationConfigResponse = z.infer<typeof applicationConfigResponseSchema>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Application bootstrap config returned by `GET /api/application/config`.
|
|
3
|
+
*
|
|
4
|
+
* The app (`apps/app`) produces this response through a stricter server-side
|
|
5
|
+
* whitelist schema (`publicApplicationConfigSchema` in the route), and the
|
|
6
|
+
* widget (`@dolard.eu/versiq-widget`) consumes it here. Keeping the widget-side Zod
|
|
7
|
+
* schema as the canonical shape prevents drift — the server schema MUST remain
|
|
8
|
+
* a compatible subset (it may be stricter, never more permissive).
|
|
9
|
+
*/
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import { themeConfigSchema } from "./theme";
|
|
12
|
+
import { widgetRuntimeConfigSchema } from "./widget-runtime-config";
|
|
13
|
+
export const applicationConfigResponseSchema = z.object({
|
|
14
|
+
applicationId: z.string().uuid().describe("Application UUID"),
|
|
15
|
+
applicationSlug: z
|
|
16
|
+
.string()
|
|
17
|
+
.max(100)
|
|
18
|
+
.describe("Application slug (kebab-case)"),
|
|
19
|
+
applicationName: z.string().max(200).describe("Application display name"),
|
|
20
|
+
vertical: z
|
|
21
|
+
.string()
|
|
22
|
+
.max(50)
|
|
23
|
+
.describe("Vertical resolved from Application config"),
|
|
24
|
+
theme: themeConfigSchema.nullable().describe("Application theme"),
|
|
25
|
+
allowedOrigins: z
|
|
26
|
+
.array(z.string().max(200))
|
|
27
|
+
.max(50)
|
|
28
|
+
.describe("Allowed origins for this application"),
|
|
29
|
+
monitoring: z.boolean().describe("Monitoring enabled flag"),
|
|
30
|
+
primaryObjective: z
|
|
31
|
+
.object({
|
|
32
|
+
id: z.string().uuid(),
|
|
33
|
+
type: z.string(),
|
|
34
|
+
label: z.string(),
|
|
35
|
+
ctaLabel: z.string().nullable(),
|
|
36
|
+
})
|
|
37
|
+
.nullable()
|
|
38
|
+
.describe("Primary conversion objective"),
|
|
39
|
+
identityVerificationRequired: z
|
|
40
|
+
.boolean()
|
|
41
|
+
.describe("Whether HMAC identity verification is required"),
|
|
42
|
+
widget: widgetRuntimeConfigSchema
|
|
43
|
+
.nullable()
|
|
44
|
+
.describe("Admin-configured widget runtime config (theme, position, language, showProfile, open). Null when the application has not yet persisted a widget_config JSONB."),
|
|
45
|
+
});
|
package/dist/geo.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Geographic cross-boundary type contracts.
|
|
3
|
+
*
|
|
4
|
+
* Cross-boundary contract shared by the geo package (`@versiq/geo`) and the
|
|
5
|
+
* app host (`apps/app`). Previously co-located in `apps/app/src/lib/ai/schemas/`
|
|
6
|
+
* by historical happenstance — directions cardinales are not AI-specific, they
|
|
7
|
+
* are pure geographic primitives.
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
/**
|
|
11
|
+
* Cardinal directions for directional zone search (e.g., "nord de Lyon").
|
|
12
|
+
* Uses English keys for LLM consistency, mapped to French for display.
|
|
13
|
+
*/
|
|
14
|
+
export declare const cardinalDirectionEnum: z.ZodEnum<{
|
|
15
|
+
north: "north";
|
|
16
|
+
northeast: "northeast";
|
|
17
|
+
east: "east";
|
|
18
|
+
southeast: "southeast";
|
|
19
|
+
south: "south";
|
|
20
|
+
southwest: "southwest";
|
|
21
|
+
west: "west";
|
|
22
|
+
northwest: "northwest";
|
|
23
|
+
}>;
|
|
24
|
+
export type CardinalDirection = z.infer<typeof cardinalDirectionEnum>;
|
package/dist/geo.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Geographic cross-boundary type contracts.
|
|
3
|
+
*
|
|
4
|
+
* Cross-boundary contract shared by the geo package (`@versiq/geo`) and the
|
|
5
|
+
* app host (`apps/app`). Previously co-located in `apps/app/src/lib/ai/schemas/`
|
|
6
|
+
* by historical happenstance — directions cardinales are not AI-specific, they
|
|
7
|
+
* are pure geographic primitives.
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
/**
|
|
11
|
+
* Cardinal directions for directional zone search (e.g., "nord de Lyon").
|
|
12
|
+
* Uses English keys for LLM consistency, mapped to French for display.
|
|
13
|
+
*/
|
|
14
|
+
export const cardinalDirectionEnum = z
|
|
15
|
+
.enum([
|
|
16
|
+
"north",
|
|
17
|
+
"northeast",
|
|
18
|
+
"east",
|
|
19
|
+
"southeast",
|
|
20
|
+
"south",
|
|
21
|
+
"southwest",
|
|
22
|
+
"west",
|
|
23
|
+
"northwest",
|
|
24
|
+
])
|
|
25
|
+
.describe("Direction cardinale (north/south/east/west + combinaisons)");
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dolard.eu/versiq-core-types
|
|
3
|
+
*
|
|
4
|
+
* Cross-workspace type contracts shared by `apps/app`, `apps/marketing` and
|
|
5
|
+
* `packages/widget`. Scope is intentionally narrow (ADR-006): only types that
|
|
6
|
+
* cross a workspace boundary live here. Do NOT dump domain-specific schemas
|
|
7
|
+
* in this package — keep them in the consumer that owns the domain.
|
|
8
|
+
*
|
|
9
|
+
* See `docs/adr/ADR-006-monorepo-package-strategy.md`.
|
|
10
|
+
*/
|
|
11
|
+
export * from "./theme";
|
|
12
|
+
export * from "./theme-resolver";
|
|
13
|
+
export * from "./viewport";
|
|
14
|
+
export * from "./widget-config";
|
|
15
|
+
export * from "./widget-runtime-config";
|
|
16
|
+
export * from "./application-config";
|
|
17
|
+
export * from "./postmessage";
|
|
18
|
+
export * from "./geo";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dolard.eu/versiq-core-types
|
|
3
|
+
*
|
|
4
|
+
* Cross-workspace type contracts shared by `apps/app`, `apps/marketing` and
|
|
5
|
+
* `packages/widget`. Scope is intentionally narrow (ADR-006): only types that
|
|
6
|
+
* cross a workspace boundary live here. Do NOT dump domain-specific schemas
|
|
7
|
+
* in this package — keep them in the consumer that owns the domain.
|
|
8
|
+
*
|
|
9
|
+
* See `docs/adr/ADR-006-monorepo-package-strategy.md`.
|
|
10
|
+
*/
|
|
11
|
+
export * from "./theme";
|
|
12
|
+
export * from "./theme-resolver";
|
|
13
|
+
export * from "./viewport";
|
|
14
|
+
export * from "./widget-config";
|
|
15
|
+
export * from "./widget-runtime-config";
|
|
16
|
+
export * from "./application-config";
|
|
17
|
+
export * from "./postmessage";
|
|
18
|
+
export * from "./geo";
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* postMessage protocol between the widget iframe and its host page.
|
|
3
|
+
*
|
|
4
|
+
* Two directions share the `versiq:*` prefix:
|
|
5
|
+
* - `WidgetCommand` — parent page → iframe (commands)
|
|
6
|
+
* - `WidgetEvent` — iframe → parent page (events)
|
|
7
|
+
*
|
|
8
|
+
* The `MESSAGE_TYPES` const aggregates every message type string across both
|
|
9
|
+
* directions. Consumers that treat the protocol opaquely (e.g. origin
|
|
10
|
+
* validation helpers) can rely on it to check `type.startsWith("versiq:")`
|
|
11
|
+
* without enumerating every member.
|
|
12
|
+
*/
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
import { themeConfigSchema, type ThemeConfig } from "./theme";
|
|
15
|
+
import { viewportModeSchema, type ViewportMode } from "./viewport";
|
|
16
|
+
import { widgetConfigSchema, type WidgetConfig } from "./widget-config";
|
|
17
|
+
export declare const messageRoleSchema: z.ZodEnum<{
|
|
18
|
+
user: "user";
|
|
19
|
+
assistant: "assistant";
|
|
20
|
+
}>;
|
|
21
|
+
export type MessageRole = z.infer<typeof messageRoleSchema>;
|
|
22
|
+
export declare const widgetMessageSchema: z.ZodObject<{
|
|
23
|
+
role: z.ZodEnum<{
|
|
24
|
+
user: "user";
|
|
25
|
+
assistant: "assistant";
|
|
26
|
+
}>;
|
|
27
|
+
content: z.ZodString;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
export type WidgetMessage = z.infer<typeof widgetMessageSchema>;
|
|
30
|
+
/**
|
|
31
|
+
* Generic widget profile emitted across postMessage boundaries.
|
|
32
|
+
* The concrete shape depends on the vertical (`BuyerProfile` for real-estate,
|
|
33
|
+
* `B2BProfile` for b2b-qualification, etc.) — we intentionally keep the
|
|
34
|
+
* cross-boundary contract structural so verticals can evolve independently.
|
|
35
|
+
*/
|
|
36
|
+
export type WidgetProfile = Record<string, unknown>;
|
|
37
|
+
/**
|
|
38
|
+
* Exhaustive catalogue of every `versiq:*` message type used in either
|
|
39
|
+
* direction. Kept as a single const so a new event or command is declared in
|
|
40
|
+
* one place.
|
|
41
|
+
*/
|
|
42
|
+
export declare const MESSAGE_TYPES: {
|
|
43
|
+
readonly INIT: "versiq:init";
|
|
44
|
+
readonly OPEN: "versiq:open";
|
|
45
|
+
readonly CLOSE: "versiq:close";
|
|
46
|
+
readonly RESET: "versiq:reset";
|
|
47
|
+
readonly SET_THEME: "versiq:setTheme";
|
|
48
|
+
readonly VIEWPORT: "versiq:viewport";
|
|
49
|
+
readonly IDENTIFY: "versiq:identify";
|
|
50
|
+
readonly READY: "versiq:ready";
|
|
51
|
+
readonly PROFILE_UPDATE: "versiq:profile-update";
|
|
52
|
+
readonly MESSAGE: "versiq:message";
|
|
53
|
+
readonly QUALIFIED: "versiq:qualified";
|
|
54
|
+
readonly ERROR: "versiq:error";
|
|
55
|
+
readonly QUOTA_WARNING: "versiq:quota-warning";
|
|
56
|
+
readonly QUOTA_EXCEEDED: "versiq:quota-exceeded";
|
|
57
|
+
readonly FUNNEL_STAGE_CHANGE: "versiq:funnel-stage-change";
|
|
58
|
+
readonly CTA_SHOWN: "versiq:cta-shown";
|
|
59
|
+
readonly CTA_CLICKED: "versiq:cta-clicked";
|
|
60
|
+
readonly LEAD_CAPTURED: "versiq:lead-captured";
|
|
61
|
+
readonly IDENTITY_VERIFIED: "versiq:identity-verified";
|
|
62
|
+
};
|
|
63
|
+
export type MessageType = (typeof MESSAGE_TYPES)[keyof typeof MESSAGE_TYPES];
|
|
64
|
+
export type WidgetCommand = {
|
|
65
|
+
type: typeof MESSAGE_TYPES.INIT;
|
|
66
|
+
config: WidgetConfig;
|
|
67
|
+
} | {
|
|
68
|
+
type: typeof MESSAGE_TYPES.OPEN;
|
|
69
|
+
} | {
|
|
70
|
+
type: typeof MESSAGE_TYPES.CLOSE;
|
|
71
|
+
} | {
|
|
72
|
+
type: typeof MESSAGE_TYPES.RESET;
|
|
73
|
+
} | {
|
|
74
|
+
type: typeof MESSAGE_TYPES.SET_THEME;
|
|
75
|
+
theme: ThemeConfig;
|
|
76
|
+
} | {
|
|
77
|
+
type: typeof MESSAGE_TYPES.VIEWPORT;
|
|
78
|
+
mode: ViewportMode;
|
|
79
|
+
} | {
|
|
80
|
+
type: typeof MESSAGE_TYPES.IDENTIFY;
|
|
81
|
+
email: string;
|
|
82
|
+
userId?: string;
|
|
83
|
+
userHash: string;
|
|
84
|
+
};
|
|
85
|
+
export type WidgetEvent = {
|
|
86
|
+
type: typeof MESSAGE_TYPES.READY;
|
|
87
|
+
} | {
|
|
88
|
+
type: typeof MESSAGE_TYPES.PROFILE_UPDATE;
|
|
89
|
+
profile: WidgetProfile;
|
|
90
|
+
} | {
|
|
91
|
+
type: typeof MESSAGE_TYPES.MESSAGE;
|
|
92
|
+
message: WidgetMessage;
|
|
93
|
+
} | {
|
|
94
|
+
type: typeof MESSAGE_TYPES.QUALIFIED;
|
|
95
|
+
profile: WidgetProfile;
|
|
96
|
+
score: number;
|
|
97
|
+
} | {
|
|
98
|
+
type: typeof MESSAGE_TYPES.ERROR;
|
|
99
|
+
code: string;
|
|
100
|
+
message: string;
|
|
101
|
+
} | {
|
|
102
|
+
type: typeof MESSAGE_TYPES.OPEN;
|
|
103
|
+
} | {
|
|
104
|
+
type: typeof MESSAGE_TYPES.CLOSE;
|
|
105
|
+
} | {
|
|
106
|
+
type: typeof MESSAGE_TYPES.QUOTA_WARNING;
|
|
107
|
+
remaining: number;
|
|
108
|
+
limit: number;
|
|
109
|
+
} | {
|
|
110
|
+
type: typeof MESSAGE_TYPES.QUOTA_EXCEEDED;
|
|
111
|
+
} | {
|
|
112
|
+
type: typeof MESSAGE_TYPES.FUNNEL_STAGE_CHANGE;
|
|
113
|
+
stage: string;
|
|
114
|
+
previousStage: string | null;
|
|
115
|
+
} | {
|
|
116
|
+
type: typeof MESSAGE_TYPES.CTA_SHOWN;
|
|
117
|
+
ctaType: string;
|
|
118
|
+
objectiveId?: string;
|
|
119
|
+
} | {
|
|
120
|
+
type: typeof MESSAGE_TYPES.CTA_CLICKED;
|
|
121
|
+
ctaType: string;
|
|
122
|
+
objectiveId?: string;
|
|
123
|
+
} | {
|
|
124
|
+
type: typeof MESSAGE_TYPES.LEAD_CAPTURED;
|
|
125
|
+
hasEmail: boolean;
|
|
126
|
+
hasPhone: boolean;
|
|
127
|
+
} | {
|
|
128
|
+
type: typeof MESSAGE_TYPES.IDENTITY_VERIFIED;
|
|
129
|
+
email: string;
|
|
130
|
+
userId?: string;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Short keys (no `versiq:` prefix) used by the widget public API (on/off).
|
|
134
|
+
*/
|
|
135
|
+
export type WidgetEventType = "ready" | "profile-update" | "message" | "qualified" | "error" | "open" | "close" | "quota-warning" | "quota-exceeded" | "funnel-stage-change" | "cta-shown" | "cta-clicked" | "lead-captured" | "identity-verified";
|
|
136
|
+
export type WidgetEventHandler<T = unknown> = (data: T) => void;
|
|
137
|
+
export { themeConfigSchema, viewportModeSchema, widgetConfigSchema };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* postMessage protocol between the widget iframe and its host page.
|
|
3
|
+
*
|
|
4
|
+
* Two directions share the `versiq:*` prefix:
|
|
5
|
+
* - `WidgetCommand` — parent page → iframe (commands)
|
|
6
|
+
* - `WidgetEvent` — iframe → parent page (events)
|
|
7
|
+
*
|
|
8
|
+
* The `MESSAGE_TYPES` const aggregates every message type string across both
|
|
9
|
+
* directions. Consumers that treat the protocol opaquely (e.g. origin
|
|
10
|
+
* validation helpers) can rely on it to check `type.startsWith("versiq:")`
|
|
11
|
+
* without enumerating every member.
|
|
12
|
+
*/
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
import { themeConfigSchema } from "./theme";
|
|
15
|
+
import { viewportModeSchema } from "./viewport";
|
|
16
|
+
import { widgetConfigSchema } from "./widget-config";
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// Message primitives
|
|
19
|
+
// ============================================================================
|
|
20
|
+
export const messageRoleSchema = z
|
|
21
|
+
.enum(["user", "assistant"])
|
|
22
|
+
.describe("Message sender role");
|
|
23
|
+
export const widgetMessageSchema = z.object({
|
|
24
|
+
role: messageRoleSchema.describe("Message sender role"),
|
|
25
|
+
content: z
|
|
26
|
+
.string()
|
|
27
|
+
.max(10000)
|
|
28
|
+
.describe("Message content (max 10000 characters)"),
|
|
29
|
+
});
|
|
30
|
+
// ============================================================================
|
|
31
|
+
// Message type catalogue
|
|
32
|
+
// ============================================================================
|
|
33
|
+
/**
|
|
34
|
+
* Exhaustive catalogue of every `versiq:*` message type used in either
|
|
35
|
+
* direction. Kept as a single const so a new event or command is declared in
|
|
36
|
+
* one place.
|
|
37
|
+
*/
|
|
38
|
+
export const MESSAGE_TYPES = {
|
|
39
|
+
// Parent → iframe (commands)
|
|
40
|
+
INIT: "versiq:init",
|
|
41
|
+
OPEN: "versiq:open",
|
|
42
|
+
CLOSE: "versiq:close",
|
|
43
|
+
RESET: "versiq:reset",
|
|
44
|
+
SET_THEME: "versiq:setTheme",
|
|
45
|
+
VIEWPORT: "versiq:viewport",
|
|
46
|
+
IDENTIFY: "versiq:identify",
|
|
47
|
+
// iframe → parent (events)
|
|
48
|
+
READY: "versiq:ready",
|
|
49
|
+
PROFILE_UPDATE: "versiq:profile-update",
|
|
50
|
+
MESSAGE: "versiq:message",
|
|
51
|
+
QUALIFIED: "versiq:qualified",
|
|
52
|
+
ERROR: "versiq:error",
|
|
53
|
+
QUOTA_WARNING: "versiq:quota-warning",
|
|
54
|
+
QUOTA_EXCEEDED: "versiq:quota-exceeded",
|
|
55
|
+
FUNNEL_STAGE_CHANGE: "versiq:funnel-stage-change",
|
|
56
|
+
CTA_SHOWN: "versiq:cta-shown",
|
|
57
|
+
CTA_CLICKED: "versiq:cta-clicked",
|
|
58
|
+
LEAD_CAPTURED: "versiq:lead-captured",
|
|
59
|
+
IDENTITY_VERIFIED: "versiq:identity-verified",
|
|
60
|
+
};
|
|
61
|
+
// Re-export schemas that participate in the protocol for consumers that want
|
|
62
|
+
// runtime validation (e.g. widget bootstrap parsing a `WidgetConfig`).
|
|
63
|
+
export { themeConfigSchema, viewportModeSchema, widgetConfigSchema };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theme resolver — single source of truth for `ThemeConfig` → CSS-ready values.
|
|
3
|
+
*
|
|
4
|
+
* Pure function consumed by:
|
|
5
|
+
* - `apps/app/src/app/widget/embed/EmbedChat.tsx` (iframe runtime)
|
|
6
|
+
* - `apps/app/src/components/portal/sandbox/WidgetMockPreview.tsx` (admin preview)
|
|
7
|
+
*
|
|
8
|
+
* Before this module existed, the same resolution rules were duplicated across
|
|
9
|
+
* the two call sites (cf. audit `tmp/widget-customization-review.md` § 3.4 —
|
|
10
|
+
* fuite n° 3 of the verdict "abstraction qui ne tient pas sa promesse"). Any
|
|
11
|
+
* evolution had to be mirrored by hand, with no compiler check. The function
|
|
12
|
+
* here is the contract; both callers MUST consume it.
|
|
13
|
+
*
|
|
14
|
+
* Dark-mode policy:
|
|
15
|
+
* `backgroundColor` and `textColor` admin-side hex overrides apply in
|
|
16
|
+
* LIGHT MODE ONLY. The widget's `colorScheme: "dark"` token flips surface
|
|
17
|
+
* tokens via the `.dark` CSS class on the iframe root — forcing a saved
|
|
18
|
+
* "#FFFFFF" through dark mode would defeat the toggle and yield a
|
|
19
|
+
* white-on-white outcome on the visitor's site. When `isDark` is true,
|
|
20
|
+
* those two fields fall back to the resolver's `defaults` (typically CSS
|
|
21
|
+
* variables that respond to `.dark`).
|
|
22
|
+
*
|
|
23
|
+
* `primaryColor` is brand-side and applies in both schemes: the assistant
|
|
24
|
+
* bubble and the launcher button must stay the brand colour even on a
|
|
25
|
+
* dark surface.
|
|
26
|
+
*/
|
|
27
|
+
import type { ThemeConfig } from "./theme";
|
|
28
|
+
/**
|
|
29
|
+
* Caller-supplied fallback palette. Each consumer (runtime, preview) passes
|
|
30
|
+
* the same constant — that is what guarantees alignment by construction. The
|
|
31
|
+
* test contract (`theme-resolver.test.ts`) asserts identical output for
|
|
32
|
+
* identical input across callers.
|
|
33
|
+
*/
|
|
34
|
+
export interface ThemeDefaults {
|
|
35
|
+
/** Brand colour applied to launcher + user bubble. Used in BOTH schemes. */
|
|
36
|
+
primaryColor: string;
|
|
37
|
+
/** Background applied to the widget surface. Used only when `isDark === false`. */
|
|
38
|
+
backgroundColor: string;
|
|
39
|
+
/** Foreground text colour. Used only when `isDark === false`. */
|
|
40
|
+
textColor: string;
|
|
41
|
+
/** Default radius (in pixels) used when `theme.borderRadius == null`. */
|
|
42
|
+
borderRadiusPx: number;
|
|
43
|
+
/** Default font stack used when `theme.fontFamily == null`. */
|
|
44
|
+
fontFamily: string;
|
|
45
|
+
}
|
|
46
|
+
export interface ResolvedTheme {
|
|
47
|
+
primaryColor: string;
|
|
48
|
+
backgroundColor: string;
|
|
49
|
+
textColor: string;
|
|
50
|
+
/** CSS string ready to apply (e.g. `"16px"`). */
|
|
51
|
+
borderRadius: string;
|
|
52
|
+
fontFamily: string;
|
|
53
|
+
}
|
|
54
|
+
export declare function resolveTheme(theme: ThemeConfig | null | undefined, isDark: boolean, defaults: ThemeDefaults): ResolvedTheme;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theme resolver — single source of truth for `ThemeConfig` → CSS-ready values.
|
|
3
|
+
*
|
|
4
|
+
* Pure function consumed by:
|
|
5
|
+
* - `apps/app/src/app/widget/embed/EmbedChat.tsx` (iframe runtime)
|
|
6
|
+
* - `apps/app/src/components/portal/sandbox/WidgetMockPreview.tsx` (admin preview)
|
|
7
|
+
*
|
|
8
|
+
* Before this module existed, the same resolution rules were duplicated across
|
|
9
|
+
* the two call sites (cf. audit `tmp/widget-customization-review.md` § 3.4 —
|
|
10
|
+
* fuite n° 3 of the verdict "abstraction qui ne tient pas sa promesse"). Any
|
|
11
|
+
* evolution had to be mirrored by hand, with no compiler check. The function
|
|
12
|
+
* here is the contract; both callers MUST consume it.
|
|
13
|
+
*
|
|
14
|
+
* Dark-mode policy:
|
|
15
|
+
* `backgroundColor` and `textColor` admin-side hex overrides apply in
|
|
16
|
+
* LIGHT MODE ONLY. The widget's `colorScheme: "dark"` token flips surface
|
|
17
|
+
* tokens via the `.dark` CSS class on the iframe root — forcing a saved
|
|
18
|
+
* "#FFFFFF" through dark mode would defeat the toggle and yield a
|
|
19
|
+
* white-on-white outcome on the visitor's site. When `isDark` is true,
|
|
20
|
+
* those two fields fall back to the resolver's `defaults` (typically CSS
|
|
21
|
+
* variables that respond to `.dark`).
|
|
22
|
+
*
|
|
23
|
+
* `primaryColor` is brand-side and applies in both schemes: the assistant
|
|
24
|
+
* bubble and the launcher button must stay the brand colour even on a
|
|
25
|
+
* dark surface.
|
|
26
|
+
*/
|
|
27
|
+
export function resolveTheme(theme, isDark, defaults) {
|
|
28
|
+
const primaryColor = theme?.primaryColor ?? defaults.primaryColor;
|
|
29
|
+
const backgroundColor = isDark
|
|
30
|
+
? defaults.backgroundColor
|
|
31
|
+
: (theme?.backgroundColor ?? defaults.backgroundColor);
|
|
32
|
+
const textColor = isDark
|
|
33
|
+
? defaults.textColor
|
|
34
|
+
: (theme?.textColor ?? defaults.textColor);
|
|
35
|
+
const borderRadius = theme?.borderRadius != null
|
|
36
|
+
? `${theme.borderRadius}px`
|
|
37
|
+
: `${defaults.borderRadiusPx}px`;
|
|
38
|
+
const fontFamily = theme?.fontFamily ?? defaults.fontFamily;
|
|
39
|
+
return { primaryColor, backgroundColor, textColor, borderRadius, fontFamily };
|
|
40
|
+
}
|
package/dist/theme.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theme configuration schema for customizing widget appearance.
|
|
3
|
+
*
|
|
4
|
+
* Cross-boundary contract shared by the widget SDK (`@dolard.eu/versiq-widget`) and the
|
|
5
|
+
* app host (`apps/app`). Both workspaces historically redefined the same
|
|
6
|
+
* fields — this module is the single source of truth.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
export declare const themeConfigSchema: z.ZodObject<{
|
|
10
|
+
primaryColor: z.ZodOptional<z.ZodString>;
|
|
11
|
+
backgroundColor: z.ZodOptional<z.ZodString>;
|
|
12
|
+
textColor: z.ZodOptional<z.ZodString>;
|
|
13
|
+
borderRadius: z.ZodOptional<z.ZodNumber>;
|
|
14
|
+
fontFamily: z.ZodOptional<z.ZodString>;
|
|
15
|
+
colorScheme: z.ZodOptional<z.ZodEnum<{
|
|
16
|
+
light: "light";
|
|
17
|
+
dark: "dark";
|
|
18
|
+
auto: "auto";
|
|
19
|
+
}>>;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
export type ThemeConfig = z.infer<typeof themeConfigSchema>;
|
|
22
|
+
export type ColorScheme = NonNullable<ThemeConfig["colorScheme"]>;
|
package/dist/theme.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theme configuration schema for customizing widget appearance.
|
|
3
|
+
*
|
|
4
|
+
* Cross-boundary contract shared by the widget SDK (`@dolard.eu/versiq-widget`) and the
|
|
5
|
+
* app host (`apps/app`). Both workspaces historically redefined the same
|
|
6
|
+
* fields — this module is the single source of truth.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
// 6-digit hex color (e.g. "#3B82F6"). Lower or upper case accepted.
|
|
10
|
+
// `max(20)` is kept on top of the regex as a belt-and-braces guard against
|
|
11
|
+
// pre-validation length attacks even if the regex were ever loosened.
|
|
12
|
+
const HEX_COLOR_REGEX = /^#[0-9a-fA-F]{6}$/;
|
|
13
|
+
const HEX_COLOR_MESSAGE = "Color must be a 6-digit hex code (e.g. '#3B82F6'). Short hex, rgb(), and named colors are not supported.";
|
|
14
|
+
export const themeConfigSchema = z.object({
|
|
15
|
+
primaryColor: z
|
|
16
|
+
.string()
|
|
17
|
+
.max(20)
|
|
18
|
+
.regex(HEX_COLOR_REGEX, HEX_COLOR_MESSAGE)
|
|
19
|
+
.describe("Primary brand color (hex format, e.g., '#3B82F6')")
|
|
20
|
+
.optional(),
|
|
21
|
+
backgroundColor: z
|
|
22
|
+
.string()
|
|
23
|
+
.max(20)
|
|
24
|
+
.regex(HEX_COLOR_REGEX, HEX_COLOR_MESSAGE)
|
|
25
|
+
.describe("Background color for the widget container")
|
|
26
|
+
.optional(),
|
|
27
|
+
textColor: z
|
|
28
|
+
.string()
|
|
29
|
+
.max(20)
|
|
30
|
+
.regex(HEX_COLOR_REGEX, HEX_COLOR_MESSAGE)
|
|
31
|
+
.describe("Text color")
|
|
32
|
+
.optional(),
|
|
33
|
+
borderRadius: z.number().describe("Border radius in pixels").optional(),
|
|
34
|
+
fontFamily: z.string().max(100).describe("Font family").optional(),
|
|
35
|
+
colorScheme: z
|
|
36
|
+
.enum(["light", "dark", "auto"])
|
|
37
|
+
.describe("Widget color scheme: 'light' (default), 'dark', or 'auto' (follows the visitor's prefers-color-scheme).")
|
|
38
|
+
.optional(),
|
|
39
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Viewport, breakpoints, responsive and position contracts for the widget.
|
|
3
|
+
*
|
|
4
|
+
* Cross-boundary contract shared by `@dolard.eu/versiq-widget` (runtime enforcement) and
|
|
5
|
+
* `apps/app` (sandbox preview, embed layout).
|
|
6
|
+
*/
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
export declare const viewportModeSchema: z.ZodEnum<{
|
|
9
|
+
mobile: "mobile";
|
|
10
|
+
tablet: "tablet";
|
|
11
|
+
desktop: "desktop";
|
|
12
|
+
}>;
|
|
13
|
+
export type ViewportMode = z.infer<typeof viewportModeSchema>;
|
|
14
|
+
export declare const widgetPositionSchema: z.ZodEnum<{
|
|
15
|
+
"bottom-right": "bottom-right";
|
|
16
|
+
"bottom-left": "bottom-left";
|
|
17
|
+
inline: "inline";
|
|
18
|
+
}>;
|
|
19
|
+
export type WidgetPosition = z.infer<typeof widgetPositionSchema>;
|
|
20
|
+
export declare const breakpointsConfigSchema: z.ZodObject<{
|
|
21
|
+
mobile: z.ZodOptional<z.ZodNumber>;
|
|
22
|
+
tablet: z.ZodOptional<z.ZodNumber>;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
export type BreakpointsConfig = z.infer<typeof breakpointsConfigSchema>;
|
|
25
|
+
export declare const responsiveConfigSchema: z.ZodObject<{
|
|
26
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
27
|
+
breakpoints: z.ZodOptional<z.ZodObject<{
|
|
28
|
+
mobile: z.ZodOptional<z.ZodNumber>;
|
|
29
|
+
tablet: z.ZodOptional<z.ZodNumber>;
|
|
30
|
+
}, z.core.$strip>>;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
export type ResponsiveConfig = z.infer<typeof responsiveConfigSchema>;
|
package/dist/viewport.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Viewport, breakpoints, responsive and position contracts for the widget.
|
|
3
|
+
*
|
|
4
|
+
* Cross-boundary contract shared by `@dolard.eu/versiq-widget` (runtime enforcement) and
|
|
5
|
+
* `apps/app` (sandbox preview, embed layout).
|
|
6
|
+
*/
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
export const viewportModeSchema = z
|
|
9
|
+
.enum(["mobile", "tablet", "desktop"])
|
|
10
|
+
.describe("Viewport mode: mobile (<480px), tablet (480-768px), desktop (>768px)");
|
|
11
|
+
export const widgetPositionSchema = z
|
|
12
|
+
.enum(["bottom-right", "bottom-left", "inline"])
|
|
13
|
+
.describe("Widget position on the page");
|
|
14
|
+
export const breakpointsConfigSchema = z.object({
|
|
15
|
+
mobile: z
|
|
16
|
+
.number()
|
|
17
|
+
.min(0)
|
|
18
|
+
.max(1000)
|
|
19
|
+
.describe("Max width for mobile viewport (default: 480)")
|
|
20
|
+
.optional(),
|
|
21
|
+
tablet: z
|
|
22
|
+
.number()
|
|
23
|
+
.min(0)
|
|
24
|
+
.max(2000)
|
|
25
|
+
.describe("Max width for tablet viewport (default: 768)")
|
|
26
|
+
.optional(),
|
|
27
|
+
});
|
|
28
|
+
export const responsiveConfigSchema = z.object({
|
|
29
|
+
enabled: z
|
|
30
|
+
.boolean()
|
|
31
|
+
.describe("Enable responsive behavior (default: true)")
|
|
32
|
+
.optional(),
|
|
33
|
+
breakpoints: breakpointsConfigSchema
|
|
34
|
+
.describe("Custom breakpoint values")
|
|
35
|
+
.optional(),
|
|
36
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Full widget configuration contract.
|
|
3
|
+
*
|
|
4
|
+
* Consumed by `@dolard.eu/versiq-widget` (config parsing and iframe bootstrap) and by
|
|
5
|
+
* `apps/app` sandbox/preview components via `@dolard.eu/versiq-widget`'s re-export.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
export declare const widgetConfigSchema: z.ZodObject<{
|
|
9
|
+
theme: z.ZodOptional<z.ZodObject<{
|
|
10
|
+
primaryColor: z.ZodOptional<z.ZodString>;
|
|
11
|
+
backgroundColor: z.ZodOptional<z.ZodString>;
|
|
12
|
+
textColor: z.ZodOptional<z.ZodString>;
|
|
13
|
+
borderRadius: z.ZodOptional<z.ZodNumber>;
|
|
14
|
+
fontFamily: z.ZodOptional<z.ZodString>;
|
|
15
|
+
colorScheme: z.ZodOptional<z.ZodEnum<{
|
|
16
|
+
light: "light";
|
|
17
|
+
dark: "dark";
|
|
18
|
+
auto: "auto";
|
|
19
|
+
}>>;
|
|
20
|
+
}, z.core.$strip>>;
|
|
21
|
+
position: z.ZodOptional<z.ZodEnum<{
|
|
22
|
+
"bottom-right": "bottom-right";
|
|
23
|
+
"bottom-left": "bottom-left";
|
|
24
|
+
inline: "inline";
|
|
25
|
+
}>>;
|
|
26
|
+
open: z.ZodOptional<z.ZodBoolean>;
|
|
27
|
+
container: z.ZodOptional<z.ZodUnion<readonly [z.ZodCustom<HTMLElement, HTMLElement>, z.ZodString]>>;
|
|
28
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
29
|
+
debug: z.ZodOptional<z.ZodBoolean>;
|
|
30
|
+
responsive: z.ZodOptional<z.ZodObject<{
|
|
31
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
32
|
+
breakpoints: z.ZodOptional<z.ZodObject<{
|
|
33
|
+
mobile: z.ZodOptional<z.ZodNumber>;
|
|
34
|
+
tablet: z.ZodOptional<z.ZodNumber>;
|
|
35
|
+
}, z.core.$strip>>;
|
|
36
|
+
}, z.core.$strip>>;
|
|
37
|
+
showProfile: z.ZodOptional<z.ZodBoolean>;
|
|
38
|
+
language: z.ZodOptional<z.ZodString>;
|
|
39
|
+
apiKey: z.ZodString;
|
|
40
|
+
email: z.ZodOptional<z.ZodString>;
|
|
41
|
+
userId: z.ZodOptional<z.ZodString>;
|
|
42
|
+
userHash: z.ZodOptional<z.ZodString>;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
export type WidgetConfig = z.infer<typeof widgetConfigSchema>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Full widget configuration contract.
|
|
3
|
+
*
|
|
4
|
+
* Consumed by `@dolard.eu/versiq-widget` (config parsing and iframe bootstrap) and by
|
|
5
|
+
* `apps/app` sandbox/preview components via `@dolard.eu/versiq-widget`'s re-export.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import { themeConfigSchema } from "./theme";
|
|
9
|
+
import { responsiveConfigSchema, widgetPositionSchema } from "./viewport";
|
|
10
|
+
export const widgetConfigSchema = z.object({
|
|
11
|
+
theme: themeConfigSchema.describe("Custom theme configuration").optional(),
|
|
12
|
+
position: widgetPositionSchema
|
|
13
|
+
.describe("Widget position (default: 'bottom-right')")
|
|
14
|
+
.optional(),
|
|
15
|
+
open: z.boolean().describe("Initial open state (default: false)").optional(),
|
|
16
|
+
container: z
|
|
17
|
+
.union([
|
|
18
|
+
z.custom((val) => val instanceof HTMLElement),
|
|
19
|
+
z.string().max(200),
|
|
20
|
+
])
|
|
21
|
+
.describe("Container element for inline mode")
|
|
22
|
+
.optional(),
|
|
23
|
+
baseUrl: z
|
|
24
|
+
.string()
|
|
25
|
+
.url()
|
|
26
|
+
.max(200)
|
|
27
|
+
.describe("Base URL for the widget embed (default: production URL)")
|
|
28
|
+
.optional(),
|
|
29
|
+
debug: z.boolean().describe("Enable debug logging").optional(),
|
|
30
|
+
responsive: responsiveConfigSchema
|
|
31
|
+
.describe("Responsive behavior configuration")
|
|
32
|
+
.optional(),
|
|
33
|
+
showProfile: z
|
|
34
|
+
.boolean()
|
|
35
|
+
.describe("Show profile panel in widget header (default: false)")
|
|
36
|
+
.optional(),
|
|
37
|
+
language: z
|
|
38
|
+
.string()
|
|
39
|
+
.max(10)
|
|
40
|
+
.describe("Language for UI labels (e.g., 'fr', 'en'). Defaults to browser language.")
|
|
41
|
+
.optional(),
|
|
42
|
+
apiKey: z
|
|
43
|
+
.string()
|
|
44
|
+
.max(100)
|
|
45
|
+
.describe("Publishable API key (pk_*) for application authentication"),
|
|
46
|
+
email: z
|
|
47
|
+
.string()
|
|
48
|
+
.email()
|
|
49
|
+
.max(255)
|
|
50
|
+
.describe("Pre-identified user email (host-attested identity)")
|
|
51
|
+
.optional(),
|
|
52
|
+
userId: z
|
|
53
|
+
.string()
|
|
54
|
+
.max(255)
|
|
55
|
+
.describe("Host-side unique user identifier")
|
|
56
|
+
.optional(),
|
|
57
|
+
userHash: z
|
|
58
|
+
.string()
|
|
59
|
+
.max(128)
|
|
60
|
+
.describe("HMAC-SHA256 of email (or userId), signed with identity secret")
|
|
61
|
+
.optional(),
|
|
62
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Widget runtime config — server-authoritative, admin-editable.
|
|
3
|
+
*
|
|
4
|
+
* This schema defines what the admin portal can edit for a given Application
|
|
5
|
+
* and what the widget SDK receives at bootstrap via `GET /api/application/config`.
|
|
6
|
+
* It is deliberately disjoint from `widgetConfigSchema` (which contains the
|
|
7
|
+
* host-context attributes `apiKey`/`container`/`baseUrl`/`debug`/identity
|
|
8
|
+
* fields that can only live on the integrator's page).
|
|
9
|
+
*
|
|
10
|
+
* Single source of truth consumed by:
|
|
11
|
+
* - `apps/app` admin route handlers (Zod second-gate on response + PUT body)
|
|
12
|
+
* - `apps/app` portal widget editor (form schema)
|
|
13
|
+
* - `packages/widget` config resolver (server-wins merge policy)
|
|
14
|
+
*
|
|
15
|
+
* Storage: `applications.widget_config` JSONB column. Cache-invalidated on
|
|
16
|
+
* update via `invalidateKeyCacheForApplication`.
|
|
17
|
+
*
|
|
18
|
+
* Part of #726 — unifying widget config so the integration reduces to
|
|
19
|
+
* `<script data-api-key="pk_live_…"></script>`.
|
|
20
|
+
*/
|
|
21
|
+
import { z } from "zod";
|
|
22
|
+
export declare const widgetRuntimeConfigSchema: z.ZodObject<{
|
|
23
|
+
theme: z.ZodOptional<z.ZodObject<{
|
|
24
|
+
primaryColor: z.ZodOptional<z.ZodString>;
|
|
25
|
+
backgroundColor: z.ZodOptional<z.ZodString>;
|
|
26
|
+
textColor: z.ZodOptional<z.ZodString>;
|
|
27
|
+
borderRadius: z.ZodOptional<z.ZodNumber>;
|
|
28
|
+
fontFamily: z.ZodOptional<z.ZodString>;
|
|
29
|
+
colorScheme: z.ZodOptional<z.ZodEnum<{
|
|
30
|
+
light: "light";
|
|
31
|
+
dark: "dark";
|
|
32
|
+
auto: "auto";
|
|
33
|
+
}>>;
|
|
34
|
+
}, z.core.$strip>>;
|
|
35
|
+
position: z.ZodOptional<z.ZodEnum<{
|
|
36
|
+
"bottom-right": "bottom-right";
|
|
37
|
+
"bottom-left": "bottom-left";
|
|
38
|
+
inline: "inline";
|
|
39
|
+
}>>;
|
|
40
|
+
language: z.ZodOptional<z.ZodString>;
|
|
41
|
+
showProfile: z.ZodOptional<z.ZodBoolean>;
|
|
42
|
+
open: z.ZodOptional<z.ZodBoolean>;
|
|
43
|
+
brand: z.ZodOptional<z.ZodObject<{
|
|
44
|
+
title: z.ZodOptional<z.ZodString>;
|
|
45
|
+
avatarUrl: z.ZodOptional<z.ZodString>;
|
|
46
|
+
}, z.core.$strict>>;
|
|
47
|
+
}, z.core.$strict>;
|
|
48
|
+
export type WidgetRuntimeConfig = z.infer<typeof widgetRuntimeConfigSchema>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Widget runtime config — server-authoritative, admin-editable.
|
|
3
|
+
*
|
|
4
|
+
* This schema defines what the admin portal can edit for a given Application
|
|
5
|
+
* and what the widget SDK receives at bootstrap via `GET /api/application/config`.
|
|
6
|
+
* It is deliberately disjoint from `widgetConfigSchema` (which contains the
|
|
7
|
+
* host-context attributes `apiKey`/`container`/`baseUrl`/`debug`/identity
|
|
8
|
+
* fields that can only live on the integrator's page).
|
|
9
|
+
*
|
|
10
|
+
* Single source of truth consumed by:
|
|
11
|
+
* - `apps/app` admin route handlers (Zod second-gate on response + PUT body)
|
|
12
|
+
* - `apps/app` portal widget editor (form schema)
|
|
13
|
+
* - `packages/widget` config resolver (server-wins merge policy)
|
|
14
|
+
*
|
|
15
|
+
* Storage: `applications.widget_config` JSONB column. Cache-invalidated on
|
|
16
|
+
* update via `invalidateKeyCacheForApplication`.
|
|
17
|
+
*
|
|
18
|
+
* Part of #726 — unifying widget config so the integration reduces to
|
|
19
|
+
* `<script data-api-key="pk_live_…"></script>`.
|
|
20
|
+
*/
|
|
21
|
+
import { z } from "zod";
|
|
22
|
+
import { themeConfigSchema } from "./theme";
|
|
23
|
+
import { widgetPositionSchema } from "./viewport";
|
|
24
|
+
export const widgetRuntimeConfigSchema = z
|
|
25
|
+
.object({
|
|
26
|
+
theme: themeConfigSchema
|
|
27
|
+
.describe("Full visual theme palette applied by the widget. Admin-configured, no client-side override.")
|
|
28
|
+
.optional(),
|
|
29
|
+
position: widgetPositionSchema
|
|
30
|
+
.describe("Default launcher position. `inline` only applies when integrator supplies `data-container`.")
|
|
31
|
+
.optional(),
|
|
32
|
+
language: z
|
|
33
|
+
.string()
|
|
34
|
+
.max(10)
|
|
35
|
+
.describe("Locale forced for widget UI labels (ISO 639-1). Falls back to browser language when null.")
|
|
36
|
+
.optional(),
|
|
37
|
+
showProfile: z
|
|
38
|
+
.boolean()
|
|
39
|
+
.describe("Whether the widget header exposes the profile panel to end-users.")
|
|
40
|
+
.optional(),
|
|
41
|
+
open: z
|
|
42
|
+
.boolean()
|
|
43
|
+
.describe("Default open state on load. Host can still call `window.Versiq.open()` programmatically.")
|
|
44
|
+
.optional(),
|
|
45
|
+
brand: z
|
|
46
|
+
.object({
|
|
47
|
+
title: z
|
|
48
|
+
.string()
|
|
49
|
+
.max(60)
|
|
50
|
+
.describe("Custom widget header title. Falls back to a vertical-specific default (e.g. 'Versiq Chat' for B2B) when unset.")
|
|
51
|
+
.optional(),
|
|
52
|
+
avatarUrl: z
|
|
53
|
+
.string()
|
|
54
|
+
.url()
|
|
55
|
+
.max(2048)
|
|
56
|
+
.describe("Public URL of the custom widget avatar (PNG or JPEG). MUST originate from the branding-upload endpoint — arbitrary external URLs are rejected at the API boundary.")
|
|
57
|
+
.optional(),
|
|
58
|
+
})
|
|
59
|
+
.strict()
|
|
60
|
+
.describe("White-label branding overrides (issue #1083 Piste 5). Both fields are optional.")
|
|
61
|
+
.optional(),
|
|
62
|
+
})
|
|
63
|
+
.strict();
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dolard.eu/versiq-core-types",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Cross-workspace TypeScript contracts and Zod schemas consumed by @dolard.eu/versiq-widget. Intended as a peer of the widget SDK.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
26
|
+
"author": "Sébastien Dolard <admin@dolard.eu>",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/sdolard/Toize.git",
|
|
30
|
+
"directory": "packages/core-types"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/sdolard/Toize/tree/main/packages/core-types#readme",
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/sdolard/Toize/issues"
|
|
35
|
+
},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"versiq",
|
|
38
|
+
"widget",
|
|
39
|
+
"types",
|
|
40
|
+
"zod",
|
|
41
|
+
"schemas",
|
|
42
|
+
"sdk"
|
|
43
|
+
],
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=18.0.0"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"zod": "^4.2.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"typescript": "^6.0.2"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"clean": "rm -rf dist",
|
|
55
|
+
"build": "pnpm clean && tsc -p tsconfig.build.json",
|
|
56
|
+
"dev": "tsc -p tsconfig.build.json --watch",
|
|
57
|
+
"typecheck": "tsc --noEmit",
|
|
58
|
+
"typecheck:ci": "pnpm typecheck"
|
|
59
|
+
}
|
|
60
|
+
}
|