@susilkumar006/widgets-test 1.0.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.
Files changed (107) hide show
  1. package/README.md +445 -0
  2. package/dist/api/FacePeApiClient.d.cts +74 -0
  3. package/dist/api/FacePeApiClient.d.ts +74 -0
  4. package/dist/api/FacePeApiContext.d.cts +8 -0
  5. package/dist/api/FacePeApiContext.d.ts +8 -0
  6. package/dist/api/decoders.d.cts +48 -0
  7. package/dist/api/decoders.d.ts +48 -0
  8. package/dist/api/index.d.cts +8 -0
  9. package/dist/api/index.d.ts +8 -0
  10. package/dist/api/json.d.cts +5 -0
  11. package/dist/api/json.d.ts +5 -0
  12. package/dist/api/useFacePeResource.d.cts +21 -0
  13. package/dist/api/useFacePeResource.d.ts +21 -0
  14. package/dist/components/Avatar/FacePeAvatar.d.cts +23 -0
  15. package/dist/components/Avatar/FacePeAvatar.d.ts +23 -0
  16. package/dist/components/Avatar/engines.d.cts +30 -0
  17. package/dist/components/Avatar/engines.d.ts +30 -0
  18. package/dist/components/Avatar/index.d.cts +1 -0
  19. package/dist/components/Avatar/index.d.ts +1 -0
  20. package/dist/components/Form/FacePeForm.d.cts +19 -0
  21. package/dist/components/Form/FacePeForm.d.ts +19 -0
  22. package/dist/components/Form/index.d.cts +1 -0
  23. package/dist/components/Form/index.d.ts +1 -0
  24. package/dist/components/Picker/FacePePicker.d.cts +22 -0
  25. package/dist/components/Picker/FacePePicker.d.ts +22 -0
  26. package/dist/components/Picker/index.d.cts +1 -0
  27. package/dist/components/Picker/index.d.ts +1 -0
  28. package/dist/components/Placement/FacePeOverlay.d.cts +13 -0
  29. package/dist/components/Placement/FacePeOverlay.d.ts +13 -0
  30. package/dist/components/Placement/FacePePage.d.cts +10 -0
  31. package/dist/components/Placement/FacePePage.d.ts +10 -0
  32. package/dist/components/Placement/index.d.cts +2 -0
  33. package/dist/components/Placement/index.d.ts +2 -0
  34. package/dist/components/Timeline/FacePeTimeline.d.cts +23 -0
  35. package/dist/components/Timeline/FacePeTimeline.d.ts +23 -0
  36. package/dist/components/Timeline/index.d.cts +1 -0
  37. package/dist/components/Timeline/index.d.ts +1 -0
  38. package/dist/components/shared/FacePeErrorBoundary.d.cts +28 -0
  39. package/dist/components/shared/FacePeErrorBoundary.d.ts +28 -0
  40. package/dist/components/shared/surface.d.cts +6 -0
  41. package/dist/components/shared/surface.d.ts +6 -0
  42. package/dist/context/FacePeContext.d.cts +22 -0
  43. package/dist/context/FacePeContext.d.ts +22 -0
  44. package/dist/context/avatar.d.cts +6 -0
  45. package/dist/context/avatar.d.ts +6 -0
  46. package/dist/context/index.d.cts +5 -0
  47. package/dist/context/index.d.ts +5 -0
  48. package/dist/context/navigation.d.cts +10 -0
  49. package/dist/context/navigation.d.ts +10 -0
  50. package/dist/events/FacePeEventEmitter.d.cts +59 -0
  51. package/dist/events/FacePeEventEmitter.d.ts +59 -0
  52. package/dist/events/createCorrelationId.d.cts +9 -0
  53. package/dist/events/createCorrelationId.d.ts +9 -0
  54. package/dist/events/index.d.cts +8 -0
  55. package/dist/events/index.d.ts +8 -0
  56. package/dist/events/telemetry.d.cts +11 -0
  57. package/dist/events/telemetry.d.ts +11 -0
  58. package/dist/events/useFacePeEmitter.d.cts +15 -0
  59. package/dist/events/useFacePeEmitter.d.ts +15 -0
  60. package/dist/index.cjs +1925 -0
  61. package/dist/index.cjs.map +1 -0
  62. package/dist/index.d.cts +26 -0
  63. package/dist/index.d.ts +26 -0
  64. package/dist/index.js +1903 -0
  65. package/dist/index.js.map +1 -0
  66. package/dist/schemas/FacePeCustomerPayload.schema.json +31 -0
  67. package/dist/schemas/FacePeError.schema.json +63 -0
  68. package/dist/schemas/FacePeEventMeta.schema.json +53 -0
  69. package/dist/schemas/FacePeFormValues.schema.json +27 -0
  70. package/dist/schemas/FacePeNavigationRequest.schema.json +33 -0
  71. package/dist/schemas/FacePePickerOption.schema.json +34 -0
  72. package/dist/schemas/FacePePickerOptionsPayload.schema.json +49 -0
  73. package/dist/schemas/FacePeTelemetryEvent.schema.json +66 -0
  74. package/dist/schemas/FacePeTimelineItem.schema.json +91 -0
  75. package/dist/schemas/FacePeTimelinePayload.schema.json +109 -0
  76. package/dist/styles.css +887 -0
  77. package/dist/types/api.d.cts +60 -0
  78. package/dist/types/api.d.ts +60 -0
  79. package/dist/types/avatar.d.cts +102 -0
  80. package/dist/types/avatar.d.ts +102 -0
  81. package/dist/types/common.d.cts +42 -0
  82. package/dist/types/common.d.ts +42 -0
  83. package/dist/types/components.d.cts +53 -0
  84. package/dist/types/components.d.ts +53 -0
  85. package/dist/types/config.d.cts +27 -0
  86. package/dist/types/config.d.ts +27 -0
  87. package/dist/types/events.d.cts +85 -0
  88. package/dist/types/events.d.ts +85 -0
  89. package/dist/types/form.d.cts +83 -0
  90. package/dist/types/form.d.ts +83 -0
  91. package/dist/types/index.d.cts +18 -0
  92. package/dist/types/index.d.ts +18 -0
  93. package/dist/types/picker.d.cts +82 -0
  94. package/dist/types/picker.d.ts +82 -0
  95. package/dist/types/placement.d.cts +69 -0
  96. package/dist/types/placement.d.ts +69 -0
  97. package/dist/types/provider.d.cts +75 -0
  98. package/dist/types/provider.d.ts +75 -0
  99. package/dist/types/results.d.cts +28 -0
  100. package/dist/types/results.d.ts +28 -0
  101. package/dist/types/telemetry.d.cts +38 -0
  102. package/dist/types/telemetry.d.ts +38 -0
  103. package/dist/types/timeline.d.cts +103 -0
  104. package/dist/types/timeline.d.ts +103 -0
  105. package/dist/version.d.cts +2 -0
  106. package/dist/version.d.ts +2 -0
  107. package/package.json +71 -0
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Contracts for how the SDK reaches the FacePe backend: what the host supplies
3
+ * to `<FacePeProvider>`, and the session event it receives back.
4
+ */
5
+ import type { FacePeNavigationRequest } from './events.cjs';
6
+ import type { FacePeFormValues } from './form.cjs';
7
+ import type { FacePePickerOption } from './picker.cjs';
8
+ import type { FacePeTimelineItem } from './timeline.cjs';
9
+ /** HTTP methods the SDK's API client sends. */
10
+ export type FacePeHttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
11
+ /** What the SDK tells the host when it asks for a token. */
12
+ export type FacePeTokenRequest = {
13
+ /**
14
+ * The audience the token must be exchanged for at the identity layer
15
+ * (architecture §7.4): always `'app-b'`, the FacePe service.
16
+ */
17
+ readonly audience: 'app-b';
18
+ /**
19
+ * `true` after the backend rejected the previous token (HTTP 401): return a
20
+ * fresh token rather than a cached one.
21
+ */
22
+ readonly forceRefresh: boolean;
23
+ };
24
+ /**
25
+ * Supplies the access token for API requests. Implemented by the host — the
26
+ * SDK never signs in, and never stores the token it is given.
27
+ */
28
+ export type FacePeTokenProvider = (request: FacePeTokenRequest) => string | Promise<string>;
29
+ /** Payload of the provider's `sessionExpired` event. Carries no credentials. */
30
+ export type FacePeSessionExpiredPayload = {
31
+ /** The request that was refused even with a fresh token. */
32
+ readonly method: FacePeHttpMethod;
33
+ readonly path: string;
34
+ };
35
+ /**
36
+ * Events `<FacePeProvider>` delivers: `sessionExpired` from its API client,
37
+ * and every component's `navigate` request (the context-bridge navigation
38
+ * callback, so the host can wire its router once).
39
+ */
40
+ export type FacePeProviderEvents = {
41
+ readonly sessionExpired: FacePeSessionExpiredPayload;
42
+ readonly navigate: FacePeNavigationRequest;
43
+ };
44
+ /**
45
+ * Gateway payloads (architecture §6.1, §7.5): the data the components fetch
46
+ * from the FacePe gateway when an entity is passed by `entityId`. Validated at
47
+ * runtime on arrival; unknown fields are ignored. A JSON Schema of each ships
48
+ * in the package (`@facepe/widgets/schemas/<TypeName>.schema.json`).
49
+ */
50
+ /** `GET /orders/:id/timeline` — an order's status history, oldest first. */
51
+ export type FacePeTimelinePayload = {
52
+ readonly items: readonly FacePeTimelineItem[];
53
+ readonly orderNumber?: string;
54
+ };
55
+ /** `GET /locations/:id/categories` — the menu categories offered at a location. */
56
+ export type FacePePickerOptionsPayload = {
57
+ readonly options: readonly FacePePickerOption[];
58
+ };
59
+ /** `GET` and `PUT /orders/:id/customer` — an order's customer details and notes. */
60
+ export type FacePeCustomerPayload = FacePeFormValues;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Contracts for how the SDK reaches the FacePe backend: what the host supplies
3
+ * to `<FacePeProvider>`, and the session event it receives back.
4
+ */
5
+ import type { FacePeNavigationRequest } from './events.js';
6
+ import type { FacePeFormValues } from './form.js';
7
+ import type { FacePePickerOption } from './picker.js';
8
+ import type { FacePeTimelineItem } from './timeline.js';
9
+ /** HTTP methods the SDK's API client sends. */
10
+ export type FacePeHttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
11
+ /** What the SDK tells the host when it asks for a token. */
12
+ export type FacePeTokenRequest = {
13
+ /**
14
+ * The audience the token must be exchanged for at the identity layer
15
+ * (architecture §7.4): always `'app-b'`, the FacePe service.
16
+ */
17
+ readonly audience: 'app-b';
18
+ /**
19
+ * `true` after the backend rejected the previous token (HTTP 401): return a
20
+ * fresh token rather than a cached one.
21
+ */
22
+ readonly forceRefresh: boolean;
23
+ };
24
+ /**
25
+ * Supplies the access token for API requests. Implemented by the host — the
26
+ * SDK never signs in, and never stores the token it is given.
27
+ */
28
+ export type FacePeTokenProvider = (request: FacePeTokenRequest) => string | Promise<string>;
29
+ /** Payload of the provider's `sessionExpired` event. Carries no credentials. */
30
+ export type FacePeSessionExpiredPayload = {
31
+ /** The request that was refused even with a fresh token. */
32
+ readonly method: FacePeHttpMethod;
33
+ readonly path: string;
34
+ };
35
+ /**
36
+ * Events `<FacePeProvider>` delivers: `sessionExpired` from its API client,
37
+ * and every component's `navigate` request (the context-bridge navigation
38
+ * callback, so the host can wire its router once).
39
+ */
40
+ export type FacePeProviderEvents = {
41
+ readonly sessionExpired: FacePeSessionExpiredPayload;
42
+ readonly navigate: FacePeNavigationRequest;
43
+ };
44
+ /**
45
+ * Gateway payloads (architecture §6.1, §7.5): the data the components fetch
46
+ * from the FacePe gateway when an entity is passed by `entityId`. Validated at
47
+ * runtime on arrival; unknown fields are ignored. A JSON Schema of each ships
48
+ * in the package (`@facepe/widgets/schemas/<TypeName>.schema.json`).
49
+ */
50
+ /** `GET /orders/:id/timeline` — an order's status history, oldest first. */
51
+ export type FacePeTimelinePayload = {
52
+ readonly items: readonly FacePeTimelineItem[];
53
+ readonly orderNumber?: string;
54
+ };
55
+ /** `GET /locations/:id/categories` — the menu categories offered at a location. */
56
+ export type FacePePickerOptionsPayload = {
57
+ readonly options: readonly FacePePickerOption[];
58
+ };
59
+ /** `GET` and `PUT /orders/:id/customer` — an order's customer details and notes. */
60
+ export type FacePeCustomerPayload = FacePeFormValues;
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Contracts of `<FacePeAvatar>`: the FacePe avatar conversation, embedded.
3
+ */
4
+ import type { FacePeComponentProps, FacePeHandleMethod } from './components.cjs';
5
+ import type { FacePeStandardEvents } from './events.cjs';
6
+ import type { FacePeFallbackContext } from './placement.cjs';
7
+ /** An avatar the signed-in user may use (from the gateway). */
8
+ export type FacePeAvatarInfo = {
9
+ /** The avatar_id. */
10
+ readonly id: string;
11
+ readonly name: string;
12
+ readonly gender: string;
13
+ readonly previewUrl?: string | null;
14
+ readonly description?: string | null;
15
+ /** Languages it speaks (ISO 639-1); empty means all supported ones. */
16
+ readonly languages: readonly string[];
17
+ };
18
+ /** Where the conversation stands. */
19
+ export type FacePeAvatarStatus = 'idle' | 'connecting' | 'live' | 'ended' | 'error';
20
+ /** One line of the conversation. */
21
+ export type FacePeTranscriptLine = {
22
+ readonly role: 'user' | 'assistant';
23
+ readonly text: string;
24
+ readonly id?: string;
25
+ };
26
+ /** Payload of `sessionStart`. */
27
+ export type FacePeAvatarSession = {
28
+ readonly avatarId: string;
29
+ /** The usage record of this conversation (minutes and points are counted on it). */
30
+ readonly usageId: string | null;
31
+ };
32
+ /** Payload of `sessionEnd`. */
33
+ export type FacePeAvatarSessionEnd = {
34
+ readonly avatarId: string;
35
+ readonly usageId: string | null;
36
+ /** `ended`: by the user or `end()`; `disconnected`: the stream dropped; `unmounted`: the component went away. */
37
+ readonly reason: 'ended' | 'disconnected' | 'unmounted';
38
+ };
39
+ /** Events `<FacePeAvatar>` emits. `ready` carries no data (`null`). */
40
+ export type FacePeAvatarEvents = {
41
+ readonly ready: null;
42
+ readonly sessionStart: FacePeAvatarSession;
43
+ readonly sessionEnd: FacePeAvatarSessionEnd;
44
+ readonly transcript: FacePeTranscriptLine;
45
+ /** The order the conversation has built so far (avatars trained to take orders). */
46
+ readonly orderUpdate: {
47
+ readonly items: readonly {
48
+ readonly name: string;
49
+ readonly qty: number;
50
+ }[];
51
+ };
52
+ readonly error: FacePeStandardEvents['error'];
53
+ };
54
+ /** What the `controls` slot's render function receives. */
55
+ export type FacePeAvatarControlsContext = {
56
+ readonly status: FacePeAvatarStatus;
57
+ readonly muted: boolean;
58
+ start(): void;
59
+ end(): void;
60
+ setMuted(muted: boolean): void;
61
+ };
62
+ /**
63
+ * Host-rendered regions: `header` above the avatar; `controls` replacing the
64
+ * built-in Start / Mute / End bar; `fallback` in place of the component if it
65
+ * fails to render. @default none
66
+ */
67
+ export type FacePeAvatarSlots = {
68
+ readonly header: void;
69
+ readonly controls: FacePeAvatarControlsContext;
70
+ readonly fallback: FacePeFallbackContext;
71
+ };
72
+ /** Props of `<FacePeAvatar>`. */
73
+ export type FacePeAvatarProps = FacePeComponentProps<FacePeAvatarEvents, FacePeAvatarSlots> & {
74
+ /**
75
+ * The avatar_id to talk to; it must be assigned to the user whose keys the
76
+ * host uses. Without one (here or on the provider), the component loads
77
+ * the user's assigned avatars itself and lets the user choose one.
78
+ * @default the provider's `avatarId`, else the user's avatars
79
+ */
80
+ readonly avatarId?: string;
81
+ /** The language the user will speak (ISO 639-1, e.g. `'en'`, `'hi'`). @default the avatar's default */
82
+ readonly language?: string;
83
+ /**
84
+ * Start the conversation on mount. Browsers allow sound and the microphone
85
+ * only after a user gesture, so by default the user presses Start.
86
+ * @default false
87
+ */
88
+ readonly autoStart?: boolean;
89
+ /** Show the latest lines of the conversation under the avatar. @default true */
90
+ readonly captions?: boolean;
91
+ };
92
+ /** Imperative handle of `<FacePeAvatar>`, reached through a React `ref`. */
93
+ export interface FacePeAvatarHandle {
94
+ /** Moves keyboard focus to the main control (Start, or End while live). */
95
+ readonly focus: FacePeHandleMethod;
96
+ /** Starts the conversation (as the Start button does). */
97
+ readonly start: FacePeHandleMethod;
98
+ /** Ends the conversation and frees the session. */
99
+ readonly end: FacePeHandleMethod;
100
+ /** Mutes or unmutes the user's microphone. */
101
+ readonly setMuted: FacePeHandleMethod<[muted: boolean]>;
102
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Contracts of `<FacePeAvatar>`: the FacePe avatar conversation, embedded.
3
+ */
4
+ import type { FacePeComponentProps, FacePeHandleMethod } from './components.js';
5
+ import type { FacePeStandardEvents } from './events.js';
6
+ import type { FacePeFallbackContext } from './placement.js';
7
+ /** An avatar the signed-in user may use (from the gateway). */
8
+ export type FacePeAvatarInfo = {
9
+ /** The avatar_id. */
10
+ readonly id: string;
11
+ readonly name: string;
12
+ readonly gender: string;
13
+ readonly previewUrl?: string | null;
14
+ readonly description?: string | null;
15
+ /** Languages it speaks (ISO 639-1); empty means all supported ones. */
16
+ readonly languages: readonly string[];
17
+ };
18
+ /** Where the conversation stands. */
19
+ export type FacePeAvatarStatus = 'idle' | 'connecting' | 'live' | 'ended' | 'error';
20
+ /** One line of the conversation. */
21
+ export type FacePeTranscriptLine = {
22
+ readonly role: 'user' | 'assistant';
23
+ readonly text: string;
24
+ readonly id?: string;
25
+ };
26
+ /** Payload of `sessionStart`. */
27
+ export type FacePeAvatarSession = {
28
+ readonly avatarId: string;
29
+ /** The usage record of this conversation (minutes and points are counted on it). */
30
+ readonly usageId: string | null;
31
+ };
32
+ /** Payload of `sessionEnd`. */
33
+ export type FacePeAvatarSessionEnd = {
34
+ readonly avatarId: string;
35
+ readonly usageId: string | null;
36
+ /** `ended`: by the user or `end()`; `disconnected`: the stream dropped; `unmounted`: the component went away. */
37
+ readonly reason: 'ended' | 'disconnected' | 'unmounted';
38
+ };
39
+ /** Events `<FacePeAvatar>` emits. `ready` carries no data (`null`). */
40
+ export type FacePeAvatarEvents = {
41
+ readonly ready: null;
42
+ readonly sessionStart: FacePeAvatarSession;
43
+ readonly sessionEnd: FacePeAvatarSessionEnd;
44
+ readonly transcript: FacePeTranscriptLine;
45
+ /** The order the conversation has built so far (avatars trained to take orders). */
46
+ readonly orderUpdate: {
47
+ readonly items: readonly {
48
+ readonly name: string;
49
+ readonly qty: number;
50
+ }[];
51
+ };
52
+ readonly error: FacePeStandardEvents['error'];
53
+ };
54
+ /** What the `controls` slot's render function receives. */
55
+ export type FacePeAvatarControlsContext = {
56
+ readonly status: FacePeAvatarStatus;
57
+ readonly muted: boolean;
58
+ start(): void;
59
+ end(): void;
60
+ setMuted(muted: boolean): void;
61
+ };
62
+ /**
63
+ * Host-rendered regions: `header` above the avatar; `controls` replacing the
64
+ * built-in Start / Mute / End bar; `fallback` in place of the component if it
65
+ * fails to render. @default none
66
+ */
67
+ export type FacePeAvatarSlots = {
68
+ readonly header: void;
69
+ readonly controls: FacePeAvatarControlsContext;
70
+ readonly fallback: FacePeFallbackContext;
71
+ };
72
+ /** Props of `<FacePeAvatar>`. */
73
+ export type FacePeAvatarProps = FacePeComponentProps<FacePeAvatarEvents, FacePeAvatarSlots> & {
74
+ /**
75
+ * The avatar_id to talk to; it must be assigned to the user whose keys the
76
+ * host uses. Without one (here or on the provider), the component loads
77
+ * the user's assigned avatars itself and lets the user choose one.
78
+ * @default the provider's `avatarId`, else the user's avatars
79
+ */
80
+ readonly avatarId?: string;
81
+ /** The language the user will speak (ISO 639-1, e.g. `'en'`, `'hi'`). @default the avatar's default */
82
+ readonly language?: string;
83
+ /**
84
+ * Start the conversation on mount. Browsers allow sound and the microphone
85
+ * only after a user gesture, so by default the user presses Start.
86
+ * @default false
87
+ */
88
+ readonly autoStart?: boolean;
89
+ /** Show the latest lines of the conversation under the avatar. @default true */
90
+ readonly captions?: boolean;
91
+ };
92
+ /** Imperative handle of `<FacePeAvatar>`, reached through a React `ref`. */
93
+ export interface FacePeAvatarHandle {
94
+ /** Moves keyboard focus to the main control (Start, or End while live). */
95
+ readonly focus: FacePeHandleMethod;
96
+ /** Starts the conversation (as the Start button does). */
97
+ readonly start: FacePeHandleMethod;
98
+ /** Ends the conversation and frees the session. */
99
+ readonly end: FacePeHandleMethod;
100
+ /** Mutes or unmutes the user's microphone. */
101
+ readonly setMuted: FacePeHandleMethod<[muted: boolean]>;
102
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Building blocks shared by every FacePe contract.
3
+ */
4
+ /** Identifier of an entity the component fetches itself (never the entity's data). */
5
+ export type EntityId = string;
6
+ /** Identifier that ties an event or result back to the request that caused it. */
7
+ export type CorrelationId = string;
8
+ /** BCP 47 language tag, e.g. "en", "en-IN", "ta-IN". */
9
+ export type FacePeLocale = string;
10
+ /** Whether a component only presents data or lets the user change it. */
11
+ export type FacePeMode = 'view' | 'edit';
12
+ /** Spacing density of a component, to fit dense or spacious host layouts. */
13
+ export type FacePeDensity = 'compact' | 'comfortable';
14
+ /** Named on/off switches. A flag the component does not know is ignored. */
15
+ export type FacePeFeatureFlags = Readonly<Record<string, boolean>>;
16
+ /** Any value that survives JSON serialisation unchanged. */
17
+ export type JsonPrimitive = string | number | boolean | null;
18
+ export type JsonValue = JsonPrimitive | JsonArray | JsonObject;
19
+ export type JsonArray = readonly JsonValue[];
20
+ export interface JsonObject {
21
+ readonly [key: string]: JsonValue;
22
+ }
23
+ /**
24
+ * Constraint for data objects passed in or out of the SDK.
25
+ *
26
+ * Payload interfaces must be JSON-serialisable so they can be described by a
27
+ * JSON Schema and recorded as contract-test fixtures. Unknown fields are
28
+ * ignored, which keeps additions backwards compatible.
29
+ */
30
+ export type FacePeDataObject = JsonObject;
31
+ /**
32
+ * The one error shape used across the SDK: in failed results and in the
33
+ * payload of `error` events.
34
+ */
35
+ export interface FacePeError {
36
+ /** Stable, machine-readable code, e.g. "NOT_FOUND". Safe to branch on. */
37
+ readonly code: string;
38
+ /** Human-readable description. For logs, not for display to end users. */
39
+ readonly message: string;
40
+ /** Optional structured detail. */
41
+ readonly details?: JsonValue;
42
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Building blocks shared by every FacePe contract.
3
+ */
4
+ /** Identifier of an entity the component fetches itself (never the entity's data). */
5
+ export type EntityId = string;
6
+ /** Identifier that ties an event or result back to the request that caused it. */
7
+ export type CorrelationId = string;
8
+ /** BCP 47 language tag, e.g. "en", "en-IN", "ta-IN". */
9
+ export type FacePeLocale = string;
10
+ /** Whether a component only presents data or lets the user change it. */
11
+ export type FacePeMode = 'view' | 'edit';
12
+ /** Spacing density of a component, to fit dense or spacious host layouts. */
13
+ export type FacePeDensity = 'compact' | 'comfortable';
14
+ /** Named on/off switches. A flag the component does not know is ignored. */
15
+ export type FacePeFeatureFlags = Readonly<Record<string, boolean>>;
16
+ /** Any value that survives JSON serialisation unchanged. */
17
+ export type JsonPrimitive = string | number | boolean | null;
18
+ export type JsonValue = JsonPrimitive | JsonArray | JsonObject;
19
+ export type JsonArray = readonly JsonValue[];
20
+ export interface JsonObject {
21
+ readonly [key: string]: JsonValue;
22
+ }
23
+ /**
24
+ * Constraint for data objects passed in or out of the SDK.
25
+ *
26
+ * Payload interfaces must be JSON-serialisable so they can be described by a
27
+ * JSON Schema and recorded as contract-test fixtures. Unknown fields are
28
+ * ignored, which keeps additions backwards compatible.
29
+ */
30
+ export type FacePeDataObject = JsonObject;
31
+ /**
32
+ * The one error shape used across the SDK: in failed results and in the
33
+ * payload of `error` events.
34
+ */
35
+ export interface FacePeError {
36
+ /** Stable, machine-readable code, e.g. "NOT_FOUND". Safe to branch on. */
37
+ readonly code: string;
38
+ /** Human-readable description. For logs, not for display to end users. */
39
+ readonly message: string;
40
+ /** Optional structured detail. */
41
+ readonly details?: JsonValue;
42
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Generic contracts that concrete FacePe components build on: props, slots
3
+ * and imperative handles. Components themselves are added in later tasks.
4
+ */
5
+ import type { ReactNode } from 'react';
6
+ import type { FacePeConfig } from './config.cjs';
7
+ import type { FacePeEventHandlers, FacePeEventMap, FacePeStandardEvents } from './events.cjs';
8
+ import type { AsyncResult } from './results.cjs';
9
+ /**
10
+ * A host-rendered region inside a component (header, footer, empty state,
11
+ * row renderer, …): either fixed content, or a render function that receives
12
+ * the component's context for that region.
13
+ */
14
+ export type FacePeSlot<TContext = void> = [TContext] extends [void] ? ReactNode : ReactNode | ((context: TContext) => ReactNode);
15
+ /** Map of slot name → the context that slot's render function receives. */
16
+ export type FacePeSlotMap = Readonly<Record<string, unknown>>;
17
+ /** The optional slot props derived from a slot map. */
18
+ export type FacePeSlots<TSlots extends FacePeSlotMap> = {
19
+ readonly [K in keyof TSlots]?: FacePeSlot<TSlots[K]>;
20
+ };
21
+ /** Visual prominence of a component (customization rung L2). */
22
+ export type FacePeEmphasis = 'subtle' | 'default' | 'strong';
23
+ /** Size of a component's type scale (customization rung L2). */
24
+ export type FacePeSize = 'small' | 'medium' | 'large';
25
+ /**
26
+ * The props every FacePe component accepts: shared configuration, typed
27
+ * event handlers, host-rendered slots, and the L2 presentation variants.
28
+ *
29
+ * @typeParam TEvents - the component's event map (defaults to the standard events).
30
+ * @typeParam TSlots - the component's slot map (defaults to none).
31
+ */
32
+ export type FacePeComponentProps<TEvents extends FacePeEventMap = FacePeStandardEvents, TSlots extends FacePeSlotMap = Record<never, never>> = FacePeConfig & FacePeEventHandlers<TEvents> & {
33
+ /** Host-rendered regions inside the component. */
34
+ readonly slots?: FacePeSlots<TSlots>;
35
+ /**
36
+ * `subtle`: no frame; `default`: a bordered frame; `strong`: a framed,
37
+ * elevated surface. @default 'default'
38
+ */
39
+ readonly emphasis?: FacePeEmphasis;
40
+ /** Type scale relative to the host's text size. @default 'medium' */
41
+ readonly size?: FacePeSize;
42
+ };
43
+ /**
44
+ * One method of an imperative handle. It is asynchronous and resolves to a
45
+ * `Result`, so it never throws across the component boundary.
46
+ */
47
+ export type FacePeHandleMethod<TArgs extends readonly unknown[] = [], TData = void> = (...args: TArgs) => AsyncResult<TData>;
48
+ /**
49
+ * Constraint for a component's imperative handle (reached through a React
50
+ * `ref`): an object whose members are all handle methods. Kept deliberately
51
+ * small; most interaction goes through props and events.
52
+ */
53
+ export type FacePeHandle = Readonly<Record<string, FacePeHandleMethod<never[], unknown>>>;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Generic contracts that concrete FacePe components build on: props, slots
3
+ * and imperative handles. Components themselves are added in later tasks.
4
+ */
5
+ import type { ReactNode } from 'react';
6
+ import type { FacePeConfig } from './config.js';
7
+ import type { FacePeEventHandlers, FacePeEventMap, FacePeStandardEvents } from './events.js';
8
+ import type { AsyncResult } from './results.js';
9
+ /**
10
+ * A host-rendered region inside a component (header, footer, empty state,
11
+ * row renderer, …): either fixed content, or a render function that receives
12
+ * the component's context for that region.
13
+ */
14
+ export type FacePeSlot<TContext = void> = [TContext] extends [void] ? ReactNode : ReactNode | ((context: TContext) => ReactNode);
15
+ /** Map of slot name → the context that slot's render function receives. */
16
+ export type FacePeSlotMap = Readonly<Record<string, unknown>>;
17
+ /** The optional slot props derived from a slot map. */
18
+ export type FacePeSlots<TSlots extends FacePeSlotMap> = {
19
+ readonly [K in keyof TSlots]?: FacePeSlot<TSlots[K]>;
20
+ };
21
+ /** Visual prominence of a component (customization rung L2). */
22
+ export type FacePeEmphasis = 'subtle' | 'default' | 'strong';
23
+ /** Size of a component's type scale (customization rung L2). */
24
+ export type FacePeSize = 'small' | 'medium' | 'large';
25
+ /**
26
+ * The props every FacePe component accepts: shared configuration, typed
27
+ * event handlers, host-rendered slots, and the L2 presentation variants.
28
+ *
29
+ * @typeParam TEvents - the component's event map (defaults to the standard events).
30
+ * @typeParam TSlots - the component's slot map (defaults to none).
31
+ */
32
+ export type FacePeComponentProps<TEvents extends FacePeEventMap = FacePeStandardEvents, TSlots extends FacePeSlotMap = Record<never, never>> = FacePeConfig & FacePeEventHandlers<TEvents> & {
33
+ /** Host-rendered regions inside the component. */
34
+ readonly slots?: FacePeSlots<TSlots>;
35
+ /**
36
+ * `subtle`: no frame; `default`: a bordered frame; `strong`: a framed,
37
+ * elevated surface. @default 'default'
38
+ */
39
+ readonly emphasis?: FacePeEmphasis;
40
+ /** Type scale relative to the host's text size. @default 'medium' */
41
+ readonly size?: FacePeSize;
42
+ };
43
+ /**
44
+ * One method of an imperative handle. It is asynchronous and resolves to a
45
+ * `Result`, so it never throws across the component boundary.
46
+ */
47
+ export type FacePeHandleMethod<TArgs extends readonly unknown[] = [], TData = void> = (...args: TArgs) => AsyncResult<TData>;
48
+ /**
49
+ * Constraint for a component's imperative handle (reached through a React
50
+ * `ref`): an object whose members are all handle methods. Kept deliberately
51
+ * small; most interaction goes through props and events.
52
+ */
53
+ export type FacePeHandle = Readonly<Record<string, FacePeHandleMethod<never[], unknown>>>;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Configuration: static, serialisable inputs every FacePe component accepts.
3
+ */
4
+ import type { EntityId, FacePeDensity, FacePeFeatureFlags, FacePeLocale, FacePeMode } from './common.cjs';
5
+ /**
6
+ * Configuration shared by all FacePe components.
7
+ *
8
+ * Every field is optional and has a documented default, so new fields can be
9
+ * added in a minor release without breaking existing hosts.
10
+ */
11
+ export interface FacePeConfig {
12
+ /**
13
+ * The entity the component works on. It is passed by id only: the
14
+ * component fetches the entity itself, so host and component never disagree
15
+ * about freshness or authorisation.
16
+ * @default undefined (the component starts without an entity)
17
+ */
18
+ readonly entityId?: EntityId;
19
+ /** @default 'view' */
20
+ readonly mode?: FacePeMode;
21
+ /** @default the browser's language (`navigator.language`) */
22
+ readonly locale?: FacePeLocale;
23
+ /** @default 'comfortable' */
24
+ readonly density?: FacePeDensity;
25
+ /** @default {} (every flag off) */
26
+ readonly featureFlags?: FacePeFeatureFlags;
27
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Configuration: static, serialisable inputs every FacePe component accepts.
3
+ */
4
+ import type { EntityId, FacePeDensity, FacePeFeatureFlags, FacePeLocale, FacePeMode } from './common.js';
5
+ /**
6
+ * Configuration shared by all FacePe components.
7
+ *
8
+ * Every field is optional and has a documented default, so new fields can be
9
+ * added in a minor release without breaking existing hosts.
10
+ */
11
+ export interface FacePeConfig {
12
+ /**
13
+ * The entity the component works on. It is passed by id only: the
14
+ * component fetches the entity itself, so host and component never disagree
15
+ * about freshness or authorisation.
16
+ * @default undefined (the component starts without an entity)
17
+ */
18
+ readonly entityId?: EntityId;
19
+ /** @default 'view' */
20
+ readonly mode?: FacePeMode;
21
+ /** @default the browser's language (`navigator.language`) */
22
+ readonly locale?: FacePeLocale;
23
+ /** @default 'comfortable' */
24
+ readonly density?: FacePeDensity;
25
+ /** @default {} (every flag off) */
26
+ readonly featureFlags?: FacePeFeatureFlags;
27
+ }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Events: how a component reports outcomes to the host.
3
+ *
4
+ * Every event is an envelope of `type`, `payload` and `meta`. Components declare
5
+ * their events as a map of event name → payload type; the typed `on…`
6
+ * handler props are derived from that map, so handler names and event types
7
+ * cannot drift apart.
8
+ */
9
+ import type { CorrelationId, EntityId, FacePeError } from './common.cjs';
10
+ /** Metadata stamped on every event. Never carries credentials. */
11
+ export interface FacePeEventMeta {
12
+ /**
13
+ * Version of the envelope's shape (`type`, `payload`, `meta`). Changes only
14
+ * if that shape changes incompatibly, independently of `sdkVersion`.
15
+ */
16
+ readonly schemaVersion: 1;
17
+ /** Ties the event to the request and gateway log entries that caused it. */
18
+ readonly correlationId: CorrelationId;
19
+ /** When the event was emitted, as an ISO 8601 timestamp. */
20
+ readonly timestamp: string;
21
+ /** Version of the SDK that emitted the event. */
22
+ readonly sdkVersion: string;
23
+ /** Name of the emitting component, e.g. "FacePeForm". */
24
+ readonly source: string;
25
+ /** The entity the emitting component works on, when it was given an `entityId`. */
26
+ readonly entityId?: EntityId;
27
+ }
28
+ /**
29
+ * A request to navigate, raised by a component and carried out by the host's
30
+ * router (the SDK never changes the URL itself).
31
+ */
32
+ export type FacePeNavigationRequest = {
33
+ /** Destination, as the host's routing understands it (a route name, path or deep link). */
34
+ readonly to: string;
35
+ /** Route parameters. @default none */
36
+ readonly params?: Readonly<Record<string, string>>;
37
+ /** Replace the current history entry instead of pushing one. @default false */
38
+ readonly replace?: boolean;
39
+ };
40
+ /**
41
+ * The envelope every FacePe event is delivered in.
42
+ *
43
+ * @typeParam TType - the event name, e.g. "submit".
44
+ * @typeParam TPayload - the event's data.
45
+ */
46
+ export interface FacePeEvent<TType extends string = string, TPayload = unknown> {
47
+ readonly type: TType;
48
+ readonly payload: TPayload;
49
+ readonly meta: FacePeEventMeta;
50
+ }
51
+ /** Map of event name → payload type that a component emits. */
52
+ export type FacePeEventMap = Readonly<Record<string, unknown>>;
53
+ /**
54
+ * The standard events defined by the architecture, by category:
55
+ * - lifecycle: `ready`, `error`
56
+ * - intent: `select`, `submit`, `cancel`
57
+ * - navigation: `navigate`
58
+ *
59
+ * `error` and `navigate` have fixed payloads; the others are `unknown` here,
60
+ * and a component narrows the ones it emits by intersecting this map with its
61
+ * own, e.g. `FacePeStandardEvents & { submit: MyFormValues }`.
62
+ */
63
+ export type FacePeStandardEvents = {
64
+ readonly ready: unknown;
65
+ readonly select: unknown;
66
+ readonly submit: unknown;
67
+ readonly cancel: unknown;
68
+ readonly navigate: FacePeNavigationRequest;
69
+ readonly error: FacePeError;
70
+ };
71
+ /** The name of a standard event. */
72
+ export type FacePeEventType = keyof FacePeStandardEvents;
73
+ /** A callback receiving one event envelope. */
74
+ export type FacePeEventHandler<TEvent extends FacePeEvent> = (event: TEvent) => void;
75
+ /**
76
+ * The optional `on…` handler props derived from an event map:
77
+ * `{ submit: X }` becomes `{ onSubmit?: (event: FacePeEvent<'submit', X>) => void }`.
78
+ */
79
+ export type FacePeEventHandlers<TEvents extends FacePeEventMap = FacePeStandardEvents> = {
80
+ readonly [K in keyof TEvents & string as `on${Capitalize<K>}`]?: FacePeEventHandler<FacePeEvent<K, TEvents[K]>>;
81
+ };
82
+ /** Union of every event envelope a component with this event map can emit. */
83
+ export type FacePeEventOf<TEvents extends FacePeEventMap = FacePeStandardEvents> = {
84
+ [K in keyof TEvents & string]: FacePeEvent<K, TEvents[K]>;
85
+ }[keyof TEvents & string];