@veltdev/sdk-dev 5.0.2-beta.68 → 5.0.2-beta.7

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 (43) hide show
  1. package/app/client/snippyly.model.d.ts +2 -21
  2. package/app/models/data/attachment-resolver.data.model.d.ts +2 -2
  3. package/app/models/data/attachment.model.d.ts +0 -1
  4. package/app/models/data/autocomplete.data.model.d.ts +3 -4
  5. package/app/models/data/base-metadata.data.model.d.ts +0 -3
  6. package/app/models/data/comment-actions.data.model.d.ts +0 -4
  7. package/app/models/data/comment-annotation.data.model.d.ts +2 -18
  8. package/app/models/data/comment-events.data.model.d.ts +10 -12
  9. package/app/models/data/comment-resolver.data.model.d.ts +3 -3
  10. package/app/models/data/config.data.model.d.ts +0 -26
  11. package/app/models/data/core-events.data.model.d.ts +1 -74
  12. package/app/models/data/crdt.data.model.d.ts +0 -51
  13. package/app/models/data/document.data.model.d.ts +0 -2
  14. package/app/models/data/live-state-events.data.model.d.ts +0 -6
  15. package/app/models/data/notification.model.d.ts +0 -4
  16. package/app/models/data/presence-user.data.model.d.ts +0 -5
  17. package/app/models/data/provider.data.model.d.ts +1 -8
  18. package/app/models/data/reaction-resolver.data.model.d.ts +3 -3
  19. package/app/models/data/recorder-annotation.data.model.d.ts +0 -11
  20. package/app/models/data/recorder-events.data.model.d.ts +0 -3
  21. package/app/models/data/resolver.data.model.d.ts +0 -1
  22. package/app/models/data/user-resolver.data.model.d.ts +1 -17
  23. package/app/models/data/user.data.model.d.ts +0 -2
  24. package/app/models/element/comment-element.model.d.ts +8 -48
  25. package/app/models/element/crdt-element.model.d.ts +1 -88
  26. package/app/models/element/presence-element.model.d.ts +0 -25
  27. package/app/models/element/rewriter-element.model.d.ts +0 -20
  28. package/app/utils/constants.d.ts +0 -224
  29. package/app/utils/enums.d.ts +3 -36
  30. package/models.d.ts +0 -7
  31. package/package.json +1 -1
  32. package/types.d.ts +0 -2
  33. package/velt.css +1 -1
  34. package/velt.js +140 -128
  35. package/app/models/data/activity-resolver.data.model.d.ts +0 -27
  36. package/app/models/data/activity.data.model.d.ts +0 -179
  37. package/app/models/data/notification-resolver.data.model.d.ts +0 -39
  38. package/app/models/data/recorder-resolver.data.model.d.ts +0 -58
  39. package/app/models/data/rewriter-events.data.model.d.ts +0 -44
  40. package/app/models/data/suggestion-events.data.model.d.ts +0 -57
  41. package/app/models/data/suggestion.data.model.d.ts +0 -262
  42. package/app/models/element/activity-element.model.d.ts +0 -33
  43. package/app/models/element/suggestion-element.model.d.ts +0 -180
@@ -1,27 +0,0 @@
1
- import { BaseMetadata } from './base-metadata.data.model';
2
- import { ActivityChanges } from './activity.data.model';
3
- import { ResolverConfig, ResolverResponse } from './resolver.data.model';
4
- export interface PartialActivityRecord {
5
- id: string;
6
- metadata?: BaseMetadata;
7
- changes?: ActivityChanges;
8
- entityData?: unknown;
9
- entityTargetData?: unknown;
10
- displayMessageTemplateData?: Record<string, unknown>;
11
- [key: string]: any;
12
- }
13
- export interface ActivityAnnotationDataProvider {
14
- get?: (request: GetActivityResolverRequest) => Promise<ResolverResponse<Record<string, PartialActivityRecord>>>;
15
- save?: (request: SaveActivityResolverRequest) => Promise<ResolverResponse<undefined>>;
16
- config?: ResolverConfig;
17
- }
18
- export interface GetActivityResolverRequest {
19
- activityIds?: string[];
20
- documentIds?: string[];
21
- organizationId?: string;
22
- }
23
- export interface SaveActivityResolverRequest {
24
- activity: Record<string, PartialActivityRecord>;
25
- event?: string;
26
- metadata?: BaseMetadata;
27
- }
@@ -1,179 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- import { BaseMetadata } from './base-metadata.data.model';
3
- import { User } from './user.data.model';
4
- /**
5
- * Feature types that can generate activities.
6
- */
7
- export type ActivityFeatureType = 'comment' | 'reaction' | 'recorder' | 'crdt' | 'custom';
8
- /**
9
- * Comment action type constants following the `entity_type.action` naming pattern.
10
- * Annotation-level actions use `comment_annotation.*`, comment-level use `comment.*`.
11
- */
12
- export declare const CommentActivityActionTypes: {
13
- readonly ANNOTATION_ADD: "comment_annotation.add";
14
- readonly ANNOTATION_DELETE: "comment_annotation.delete";
15
- readonly COMMENT_ADD: "comment.add";
16
- readonly COMMENT_UPDATE: "comment.update";
17
- readonly COMMENT_DELETE: "comment.delete";
18
- readonly STATUS_CHANGE: "comment_annotation.status_change";
19
- readonly PRIORITY_CHANGE: "comment_annotation.priority_change";
20
- readonly ASSIGN: "comment_annotation.assign";
21
- readonly ACCESS_MODE_CHANGE: "comment_annotation.access_mode_change";
22
- readonly CUSTOM_LIST_CHANGE: "comment_annotation.custom_list_change";
23
- readonly APPROVE: "comment_annotation.approve";
24
- readonly ACCEPT: "comment.accept";
25
- readonly REJECT: "comment.reject";
26
- readonly REACTION_ADD: "comment.reaction_add";
27
- readonly REACTION_DELETE: "comment.reaction_delete";
28
- readonly SUBSCRIBE: "comment_annotation.subscribe";
29
- readonly UNSUBSCRIBE: "comment_annotation.unsubscribe";
30
- };
31
- export type CommentActivityActionType = typeof CommentActivityActionTypes[keyof typeof CommentActivityActionTypes];
32
- /**
33
- * Recorder action type constants following the `recording.*` naming pattern.
34
- */
35
- export declare const RecorderActivityActionTypes: {
36
- readonly RECORDING_ADD: "recording.add";
37
- readonly RECORDING_DELETE: "recording.delete";
38
- };
39
- export type RecorderActivityActionType = typeof RecorderActivityActionTypes[keyof typeof RecorderActivityActionTypes];
40
- /**
41
- * Reaction action type constants following the `reaction.*` naming pattern.
42
- */
43
- export declare const ReactionActivityActionTypes: {
44
- readonly REACTION_ADD: "reaction.add";
45
- readonly REACTION_DELETE: "reaction.delete";
46
- };
47
- export type ReactionActivityActionType = typeof ReactionActivityActionTypes[keyof typeof ReactionActivityActionTypes];
48
- /**
49
- * CRDT action type constants following the `crdt.*` naming pattern.
50
- */
51
- export declare const CrdtActivityActionTypes: {
52
- readonly EDITOR_EDIT: "crdt.editor_edit";
53
- };
54
- export type CrdtActivityActionType = typeof CrdtActivityActionTypes[keyof typeof CrdtActivityActionTypes];
55
- /**
56
- * Represents a single from/to change pair.
57
- * `from` is always present (null for 'added' events) for uniform structure.
58
- */
59
- export interface ActivityChange<T = unknown> {
60
- from?: T | null;
61
- to?: T | null;
62
- }
63
- /**
64
- * Dynamic change tracking. Keys are domain-specific (e.g., 'status', 'commentText', 'assignedTo').
65
- * No fixed keys — activities span multiple features.
66
- */
67
- export interface ActivityChanges {
68
- [key: string]: ActivityChange | undefined;
69
- }
70
- /**
71
- * Metadata for activity records. Extends BaseMetadata with denormalized IDs
72
- * for efficient querying at the organization level.
73
- */
74
- export declare class ActivityMetadata extends BaseMetadata {
75
- [key: string]: any;
76
- }
77
- /**
78
- * Core activity record representing a single activity event.
79
- *
80
- * @typeParam TEntity - Type of the parent entity snapshot (e.g., CommentAnnotation)
81
- * @typeParam TTarget - Type of the sub-entity snapshot (e.g., Comment)
82
- */
83
- export declare class ActivityRecord<TEntity = unknown, TTarget = unknown> {
84
- /** Auto-generated unique ID */
85
- id: string;
86
- /** Feature that generated this activity */
87
- featureType: ActivityFeatureType;
88
- /** Action that occurred, following `entity_type.action` pattern */
89
- actionType: string;
90
- /** Event type that occurred */
91
- eventType?: string;
92
- /** User who performed the action */
93
- actionUser: User;
94
- /** Server timestamp (set by backend) */
95
- timestamp: number;
96
- /** Denormalized IDs for querying */
97
- metadata: ActivityMetadata;
98
- /** ID of the parent entity (annotationId, recordingId, etc.) */
99
- targetEntityId: string;
100
- /** ID of the sub-entity acted on (commentId within annotation, null for entity-level actions) */
101
- targetSubEntityId?: string | null;
102
- /** Linear-style from/to change pairs */
103
- changes?: ActivityChanges;
104
- /** Full parent entity snapshot at time of action */
105
- entityData?: TEntity;
106
- /** Sub-entity snapshot (or user-provided data for custom activities) */
107
- entityTargetData?: TTarget;
108
- /** Display message template — ONLY for custom activities */
109
- displayMessageTemplate?: string;
110
- /** Template variable values — ONLY for custom activities */
111
- displayMessageTemplateData?: Record<string, unknown>;
112
- /** Computed display message (generated client-side, never stored in Firestore) */
113
- displayMessage?: string;
114
- /** Icon URL or identifier for display */
115
- actionIcon?: string;
116
- /** If true, this activity cannot be updated or deleted via REST API */
117
- immutable?: boolean;
118
- /** If true, this activity was stripped by the activity resolver (for UI loading states) */
119
- isActivityResolverUsed?: boolean;
120
- }
121
- /**
122
- * Configuration for subscribing to activities.
123
- * Behavior is determined by the props passed:
124
- * - No config → org-wide
125
- * - documentIds → specific documents
126
- * - currentDocumentOnly → current document only
127
- */
128
- export interface ActivitySubscribeConfig {
129
- /** Subscribe to activities for a specific organization (defaults to current org) */
130
- organizationId?: string;
131
- /** Subscribe to activities for specific document IDs */
132
- documentIds?: string[];
133
- /** Subscribe to activities for the current document only (auto-switches on setDocument) */
134
- currentDocumentOnly?: boolean;
135
- /** Only fetch activities from the last N days (default: 30) */
136
- maxDays?: number;
137
- /** Allowlist: only include activities with these feature types */
138
- featureTypes?: ActivityFeatureType[];
139
- /** Disallowlist: exclude activities with these feature types (ignored if featureTypes is set) */
140
- excludeFeatureTypes?: ActivityFeatureType[];
141
- /** Allowlist: only include activities with these action types */
142
- actionTypes?: string[];
143
- /** Disallowlist: exclude activities with these action types (ignored if actionTypes is set) */
144
- excludeActionTypes?: string[];
145
- /** Allowlist: only include activities by these user IDs */
146
- userIds?: string[];
147
- /** Disallowlist: exclude activities by these user IDs (ignored if userIds is set) */
148
- excludeUserIds?: string[];
149
- }
150
- /**
151
- * Represents an active activity subscription.
152
- * Returned by `activityService.subscribe()`.
153
- */
154
- export interface ActivitySubscription {
155
- /** Observable stream of activities for this subscription's scope. null = not yet loaded. */
156
- getActivities$(): Observable<ActivityRecord[] | null>;
157
- /** Unsubscribe and clean up this subscription */
158
- unsubscribe(): void;
159
- }
160
- /**
161
- * Data required to create an activity.
162
- * Used for all activity types: comment, reaction, recorder, custom, etc.
163
- */
164
- export interface CreateActivityData<TEntity = unknown, TTarget = unknown> {
165
- featureType: ActivityFeatureType;
166
- actionType: string;
167
- eventType?: string;
168
- targetEntityId: string;
169
- targetSubEntityId?: string | null;
170
- changes?: ActivityChanges;
171
- entityData?: TEntity;
172
- entityTargetData?: TTarget;
173
- /** Icon URL or identifier — typically used for custom activities */
174
- actionIcon?: string;
175
- /** Display message template — only for custom activities */
176
- displayMessageTemplate?: string;
177
- /** Template variable values — only for custom activities */
178
- displayMessageTemplateData?: Record<string, unknown>;
179
- }
@@ -1,39 +0,0 @@
1
- import { ResolverEndpointConfig, ResolverResponse, RetryConfig } from "./resolver.data.model";
2
- import { User } from "./user.data.model";
3
- export interface NotificationDataProvider {
4
- get?: (request: GetNotificationResolverRequest) => Promise<ResolverResponse<Record<string, PartialNotification>>>;
5
- delete?: (request: DeleteNotificationResolverRequest) => Promise<ResolverResponse<undefined>>;
6
- config?: NotificationResolverConfig;
7
- }
8
- export interface NotificationResolverConfig {
9
- resolveTimeout?: number;
10
- getRetryConfig?: RetryConfig;
11
- deleteRetryConfig?: RetryConfig;
12
- getConfig?: ResolverEndpointConfig;
13
- deleteConfig?: ResolverEndpointConfig;
14
- }
15
- export interface GetNotificationResolverRequest {
16
- organizationId: string;
17
- notificationIds: string[];
18
- }
19
- export interface DeleteNotificationResolverRequest {
20
- notificationId: string;
21
- organizationId: string;
22
- }
23
- export interface PartialNotification {
24
- notificationId: string;
25
- displayHeadlineMessageTemplate?: string;
26
- displayHeadlineMessageTemplateData?: {
27
- actionUser?: User;
28
- recipientUser?: User;
29
- actionMessage?: string;
30
- [key: string]: any;
31
- };
32
- displayBodyMessage?: string;
33
- displayBodyMessageTemplate?: string;
34
- displayBodyMessageTemplateData?: {
35
- [key: string]: any;
36
- };
37
- notificationSourceData?: any;
38
- [key: string]: any;
39
- }
@@ -1,58 +0,0 @@
1
- import { ResolverActions } from "../../utils/enums";
2
- import { AttachmentDataProvider } from "./attachment-resolver.data.model";
3
- import { BaseMetadata } from "./base-metadata.data.model";
4
- import { RecorderAnnotation } from "./recorder-annotation.data.model";
5
- import { ResolverConfig, ResolverResponse } from "./resolver.data.model";
6
- import { Attachment } from "./attachment.model";
7
- import { Transcription } from "./transcription.data.model";
8
- import { User } from "./user.data.model";
9
- export interface RecorderAnnotationDataProvider {
10
- get?: (request: GetRecorderResolverRequest) => Promise<ResolverResponse<Record<string, PartialRecorderAnnotation>>>;
11
- save?: (request: SaveRecorderResolverRequest) => Promise<ResolverResponse<SaveRecorderResolverData | undefined>>;
12
- delete?: (request: DeleteRecorderResolverRequest) => Promise<ResolverResponse<undefined>>;
13
- config?: ResolverConfig;
14
- uploadChunks?: boolean;
15
- storage?: AttachmentDataProvider;
16
- }
17
- export interface GetRecorderResolverRequest {
18
- organizationId: string;
19
- recorderAnnotationIds?: string[];
20
- documentIds?: string[];
21
- }
22
- export interface SaveRecorderResolverRequest {
23
- recorderAnnotation: Record<string, PartialRecorderAnnotation>;
24
- event?: ResolverActions;
25
- metadata?: BaseMetadata;
26
- }
27
- export interface SaveRecorderResolverData {
28
- transcription?: Transcription;
29
- attachment?: Attachment | null;
30
- attachments?: Attachment[];
31
- }
32
- export interface DeleteRecorderResolverRequest {
33
- recorderAnnotationId: string;
34
- metadata?: BaseMetadata;
35
- event?: ResolverActions;
36
- }
37
- export interface PartialRecorderAnnotation {
38
- annotationId: string;
39
- metadata?: BaseMetadata;
40
- from?: User;
41
- transcription?: Transcription;
42
- attachment?: Attachment | null;
43
- attachments?: Attachment[];
44
- chunkUrls?: Record<number, string>;
45
- recordingEditVersions?: Record<number, PartialRecorderAnnotationEditVersion>;
46
- [key: string]: any;
47
- }
48
- export interface PartialRecorderAnnotationEditVersion {
49
- from?: User;
50
- attachment?: Attachment | null;
51
- attachments?: Attachment[];
52
- transcription?: Transcription;
53
- }
54
- export interface PartialRecorderAnnotationResult {
55
- strippedData: Record<string, PartialRecorderAnnotation> | null;
56
- originalData: RecorderAnnotation | null;
57
- eventType?: ResolverActions;
58
- }
@@ -1,44 +0,0 @@
1
- import { TargetTextRange } from './target-text-range.data.model';
2
- import { RewriterEventTypes } from '../../utils/enums';
3
- export type OpenAiModel = 'gpt-5.4' | 'gpt-5.4-pro' | 'gpt-5.4-mini' | 'gpt-5.4-nano' | 'gpt-5-mini' | 'gpt-5-nano' | 'gpt-5' | 'gpt-4.1' | 'gpt-4o' | 'gpt-4o-mini' | 'gpt-4-turbo' | 'o3-pro' | 'o3' | 'o3-mini' | 'o4-mini';
4
- export type AnthropicModel = 'claude-opus-4-6' | 'claude-sonnet-4-6' | 'claude-haiku-4-5' | 'claude-sonnet-4-5' | 'claude-opus-4-5' | 'claude-opus-4-1' | 'claude-sonnet-4-0' | 'claude-opus-4-0';
5
- export type GeminiModel = 'gemini-3.1-pro-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-2.5-flash' | 'gemini-2.5-flash-lite' | 'gemini-2.5-pro';
6
- export type AiModel = OpenAiModel | AnthropicModel | GeminiModel | (string & NonNullable<unknown>);
7
- export interface TextSelectedEvent {
8
- selectionId: string;
9
- text: string;
10
- targetTextRange: TargetTextRange;
11
- }
12
- export interface RewriterAskAiRequest {
13
- model: AiModel;
14
- prompt: string;
15
- selectedText: string;
16
- }
17
- export interface RewriterReplaceTextRequest {
18
- text: string;
19
- event: TextSelectedEvent;
20
- }
21
- export interface RewriterAddCommentRequest {
22
- text: string;
23
- event: TextSelectedEvent;
24
- }
25
- export interface RewriterAskAiResponse {
26
- text: string;
27
- success: boolean;
28
- error?: string;
29
- }
30
- export interface RewriterReplaceTextResponse {
31
- success: boolean;
32
- originalText: string;
33
- replacedText: string;
34
- error?: string;
35
- }
36
- export interface RewriterAddCommentResponse {
37
- success: boolean;
38
- annotationId?: string;
39
- commentText?: string;
40
- error?: string;
41
- }
42
- export type RewriterEventTypesMap = {
43
- [RewriterEventTypes.TEXT_SELECTED]: TextSelectedEvent;
44
- };
@@ -1,57 +0,0 @@
1
- import { SuggestionEventTypes } from '../../utils/enums';
2
- import { ApprovedSuggestion, PendingSuggestion, RejectedSuggestion, StaleSuggestion, TargetEditCommitBuilder, TargetEditDetails } from './suggestion.data.model';
3
- /**
4
- * Public payload types for the v1 Suggestions feature. Mirrors the layout of
5
- * `comment-events.data.model.ts` and `recorder-events.data.model.ts`:
6
- *
7
- * - One named interface per event payload.
8
- * - One `SuggestionEventTypesMap` keyed by `SuggestionEventTypes` enum values.
9
- *
10
- * Customers pass an event-name string (or the enum constant — they're
11
- * equivalent) to `velt.getSuggestionElement().on(...)` and receive an
12
- * `Observable<SuggestionEventTypesMap[T]>`.
13
- *
14
- * No separate `actor`/`user` field on the payloads: the user info is on
15
- * `suggestion.createdBy` (for created) and `suggestion.resolvedBy` (for
16
- * approved/rejected/stale). Matches the comment-event shape.
17
- */
18
- export interface SuggestionCreatedEvent {
19
- suggestion: PendingSuggestion;
20
- timestamp: number;
21
- }
22
- export interface SuggestionApprovedEvent {
23
- suggestion: ApprovedSuggestion;
24
- timestamp: number;
25
- }
26
- export interface SuggestionRejectedEvent {
27
- suggestion: RejectedSuggestion;
28
- timestamp: number;
29
- }
30
- export interface SuggestionStaleEvent {
31
- suggestion: StaleSuggestion;
32
- timestamp: number;
33
- }
34
- export interface TargetEditStartEvent {
35
- details: TargetEditDetails;
36
- timestamp: number;
37
- }
38
- export interface TargetEditCommitEvent {
39
- details: TargetEditDetails;
40
- /**
41
- * Pre-bound builder. Calling it commits the suggestion using the SDK's
42
- * default summary/metadata, optionally overridden by `result`. If the
43
- * customer's `onTargetEditCommit` handler already returned a non-null
44
- * result for this edit, this builder is a no-op so subscribers can't
45
- * double-commit.
46
- */
47
- commitSuggestion: TargetEditCommitBuilder;
48
- timestamp: number;
49
- }
50
- export type SuggestionEventTypesMap = {
51
- [SuggestionEventTypes.SUGGESTION_CREATED]: SuggestionCreatedEvent;
52
- [SuggestionEventTypes.SUGGESTION_APPROVED]: SuggestionApprovedEvent;
53
- [SuggestionEventTypes.SUGGESTION_REJECTED]: SuggestionRejectedEvent;
54
- [SuggestionEventTypes.SUGGESTION_STALE]: SuggestionStaleEvent;
55
- [SuggestionEventTypes.TARGET_EDIT_START]: TargetEditStartEvent;
56
- [SuggestionEventTypes.TARGET_EDIT_COMMIT]: TargetEditCommitEvent;
57
- };
@@ -1,262 +0,0 @@
1
- /**
2
- * Suggestions feature — public type surface for v1.
3
- *
4
- * Source contract: docs/suggestions-api-contract.md
5
- * Source flows: docs/suggestions-implementation-flows.md
6
- *
7
- * Types are exported from the SDK's public barrel. Customer code interacts
8
- * with these via Snippyly.getSuggestionElement(); the SDK constructs all
9
- * Suggestion objects internally and customers do not build them directly.
10
- */
11
- import { User } from './user.data.model';
12
- /**
13
- * Lifecycle state machine for a Suggestion.
14
- *
15
- * - pending: Just created, awaiting owner action.
16
- * - approved: Owner clicked Approve. Customer apply handler ran successfully.
17
- * - rejected: Owner clicked Reject (with optional reason).
18
- * - stale: Target was unresolvable at approve time. Owner can dismiss.
19
- * - apply_failed: Customer apply handler threw during a suggestionApproved event.
20
- * Status set by the SDK after the throw was caught.
21
- */
22
- export type SuggestionStatus = 'pending' | 'approved' | 'rejected' | 'stale' | 'apply_failed';
23
- /**
24
- * Global per-user-per-session suggestion mode. Not persisted; reload returns to 'editing'.
25
- */
26
- export type SuggestionMode = 'editing' | 'suggesting';
27
- /**
28
- * Discriminator for the substrate that produced a suggestion. v1: always 'custom'.
29
- * Wrapper libraries (e.g. tiptap-velt-comments) widen this union when they integrate.
30
- *
31
- * Customers should treat unknown values as opaque; the field exists so customer code
32
- * can differentiate substrate when domain-specific rendering matters.
33
- */
34
- export type SuggestionTargetType = 'custom';
35
- /**
36
- * Single-arg config passed to `SuggestionElement.registerTarget(config)`.
37
- * Carrying both `targetId` and `getter` in one object so the API can grow
38
- * (e.g., metadata, target-specific options) without breaking customers.
39
- */
40
- export interface RegisterTargetConfig<T = unknown> {
41
- targetId: string;
42
- getter: TargetGetter<T>;
43
- }
44
- /**
45
- * Function the customer registers via SuggestionElement.registerTarget(config).
46
- * Required for any non-primitive (wrapper) target.
47
- *
48
- * The SDK calls this getter twice in a typical edit cycle:
49
- * 1. On focus of the tagged element — to snapshot the pre-edit value.
50
- * 2. On commit (focusout / change) — to read the current value for the diff.
51
- *
52
- * IMPORTANT — edit-time state, not persisted state: the getter must reflect
53
- * what the user is currently editing, not what's persisted in the customer's
54
- * app store. If the customer's state is only updated on commit/approve (as
55
- * is typical when suggesting mode is on), reading from that state would
56
- * return the snapshot value at commit time, the diff check would short-
57
- * circuit, and no suggestion would ever fire.
58
- *
59
- * Recommended: read from the DOM (controlled or uncontrolled inputs) so the
60
- * getter always returns what's visible to the user.
61
- *
62
- * el.registerTarget('row.123', () => ({
63
- * qty: parseInt(qtyInput.value, 10),
64
- * price: parseInt(priceInput.value, 10),
65
- * }));
66
- *
67
- * For controlled inputs (state updates on every keystroke), reading from
68
- * the customer state is fine: `() => myState.row123`. The contract is
69
- * "edit-time state" — whichever source of truth has it.
70
- */
71
- export type TargetGetter<T = unknown> = () => T;
72
- /**
73
- * Returned from SuggestionElement.on(...). Calling it removes the handler.
74
- */
75
- export type Unsubscribe = () => void;
76
- /**
77
- * Details about a target edit, passed to the customer's resolver handler and
78
- * to subscribers of `targetEditStart` / `targetEditCommit` events.
79
- *
80
- * `element` is the DOM element that produced the edit. It's the tagged
81
- * descendant — or, for wrappers that nest interactive controls inside a
82
- * tagged container, the inner element that actually fired the event. In
83
- * either case the SDK walks up to the nearest ancestor carrying
84
- * `data-velt-suggestion-target` to resolve `targetId`.
85
- *
86
- * `element` is provided for read access only — customers should not retain
87
- * the reference past the synchronous handler call.
88
- */
89
- export interface TargetEditDetails<T = unknown> {
90
- targetId: string;
91
- oldValue: T;
92
- newValue: T;
93
- element: Element | null;
94
- }
95
- /**
96
- * Return type of `onTargetEditCommit`. Returning a value auto-commits the
97
- * suggestion using the (optional) overrides; returning null skips the
98
- * auto-commit so a subscriber to `targetEditCommit` can drive it explicitly.
99
- */
100
- export interface TargetEditCommitResult {
101
- /** Override the SDK's default `${targetId}: ${old} → ${new}` summary. */
102
- summary?: string;
103
- /** Customer metadata persisted on the resulting Suggestion. */
104
- metadata?: Record<string, unknown>;
105
- }
106
- /**
107
- * Return type of `onTargetEditStart`. Reserved for future fields; v1 has
108
- * no behavior-bearing return values, so customers may omit a return.
109
- *
110
- * Roadmap: future versions may accept `{ oldValue }` here so customers can
111
- * override the SDK's auto-snapshot with a domain-canonical value.
112
- */
113
- export interface TargetEditStartResult {
114
- }
115
- export type TargetEditStartHandler<T = unknown> = (details: TargetEditDetails<T>) => TargetEditStartResult | void | null;
116
- export type TargetEditCommitHandler<T = unknown> = (details: TargetEditDetails<T>) => TargetEditCommitResult | null;
117
- /**
118
- * Config passed to `SuggestionElement.enableSuggestionMode(config?)`.
119
- * Both callbacks are optional. If `onTargetEditCommit` is omitted, customers
120
- * can still drive auto-commit by subscribing to the `targetEditCommit` event
121
- * and calling the pre-bound `commitSuggestion` builder on the payload.
122
- */
123
- export interface EnableSuggestionModeConfig {
124
- /**
125
- * Invoked on focus of a tagged element, after the SDK captures the
126
- * snapshot. v1: informational — return value is reserved for future
127
- * use (e.g. `{ oldValue }` to override the SDK's auto-snapshot).
128
- */
129
- onTargetEditStart?: TargetEditStartHandler;
130
- /**
131
- * Invoked once per detected commit (on `change` for atomic inputs, on
132
- * `focusout` for text-like inputs). Returning a `TargetEditCommitResult`
133
- * auto-commits with the supplied summary/metadata; returning null defers
134
- * to event subscribers.
135
- */
136
- onTargetEditCommit?: TargetEditCommitHandler;
137
- }
138
- /**
139
- * SDK-managed suggestion data persisted on a CommentAnnotation.
140
- * Present iff annotation.type === 'suggestion'.
141
- *
142
- * Customer code must not write to this directly — use the SuggestionElement API.
143
- */
144
- export interface SuggestionData {
145
- /** Lifecycle state machine. */
146
- status: SuggestionStatus;
147
- /** Stable, customer-owned target identifier. */
148
- targetId: string;
149
- /** v1: always 'custom'. Wrappers widen later. */
150
- targetType: SuggestionTargetType;
151
- /** Snapshot taken at startSuggestion / focus time. Frozen via structuredClone. */
152
- oldValue: any;
153
- /** Value submitted via commitSuggestion. */
154
- newValue: any;
155
- /** Optional human-readable description for logs / notifications. */
156
- summary: string | null;
157
- /**
158
- * True if the live value at approve time differed from oldValue.
159
- * v1 records flag only; v1.1 will surface a confirmation prompt.
160
- */
161
- driftDetected: boolean;
162
- /** Populated only when status === 'rejected'. */
163
- rejectReason: string | null;
164
- /**
165
- * Full User snapshot of the resolver, populated when status moves to
166
- * approved | rejected | stale | apply_failed. Snapshot rather than userId
167
- * so customer code can render name/email/photoUrl without an extra lookup,
168
- * and so historical suggestions retain their resolver record even if the
169
- * user later updates their profile.
170
- */
171
- resolvedBy: User | null;
172
- resolvedAt: number | null;
173
- }
174
- /**
175
- * Fields shared across every Suggestion regardless of status.
176
- * Internal — used to build the per-status discriminated types below.
177
- */
178
- interface SuggestionBase<T = unknown> {
179
- /** Annotation document id (same as the underlying CommentAnnotation.annotationId). */
180
- annotationId: string;
181
- /** Stable, customer-owned target identifier. */
182
- targetId: string;
183
- /** v1: always 'custom'. */
184
- targetType: SuggestionTargetType;
185
- /** Snapshot taken at startSuggestion / focus time. */
186
- oldValue: T;
187
- /** Value submitted via commitSuggestion. */
188
- newValue: T;
189
- /** Optional human-readable description. */
190
- summary: string | null;
191
- /** Customer-defined metadata supplied via CommitSuggestionConfig.metadata. */
192
- metadata: Record<string, any>;
193
- /** True iff the live value at approve time differed from oldValue. */
194
- driftDetected: boolean;
195
- /**
196
- * User of the suggestion's creator (sourced from annotation.from).
197
- */
198
- createdBy?: User;
199
- createdAt: number;
200
- }
201
- /** A suggestion in the 'pending' state — newly created, no owner action yet. */
202
- export interface PendingSuggestion<T = unknown> extends SuggestionBase<T> {
203
- status: 'pending';
204
- rejectReason: null;
205
- resolvedBy: null;
206
- resolvedAt: null;
207
- }
208
- /** A suggestion that has been approved (apply handler success or pending invocation). */
209
- export interface ApprovedSuggestion<T = unknown> extends SuggestionBase<T> {
210
- status: 'approved' | 'apply_failed';
211
- rejectReason: null;
212
- resolvedBy: User;
213
- resolvedAt: number;
214
- }
215
- /** A suggestion that has been rejected. rejectReason is non-null. */
216
- export interface RejectedSuggestion<T = unknown> extends SuggestionBase<T> {
217
- status: 'rejected';
218
- rejectReason: string;
219
- resolvedBy: User;
220
- resolvedAt: number;
221
- }
222
- /** A suggestion whose target was unresolvable at approve time. */
223
- export interface StaleSuggestion<T = unknown> extends SuggestionBase<T> {
224
- status: 'stale';
225
- rejectReason: null;
226
- resolvedBy: User | null;
227
- resolvedAt: number | null;
228
- }
229
- /**
230
- * Public Suggestion — discriminated union keyed by `status`. TypeScript narrows
231
- * field types per status so handlers can rely on rejectReason: string when they've
232
- * checked status === 'rejected'.
233
- */
234
- export type Suggestion<T = unknown> = PendingSuggestion<T> | ApprovedSuggestion<T> | RejectedSuggestion<T> | StaleSuggestion<T>;
235
- export interface CommitSuggestionConfig<T = unknown> {
236
- /**
237
- * Must be registered (via data-velt-target attribute or registerTarget call)
238
- * before commit, otherwise the suggestion is rejected with a dev-mode warning.
239
- */
240
- targetId: string;
241
- /** Any JSON-serializable value. Customer's apply handler interprets it. */
242
- newValue: T;
243
- /** Optional human-readable string for logs and notifications. */
244
- summary?: string;
245
- /** Optional customer-defined metadata. Stored on Suggestion.metadata. */
246
- metadata?: Record<string, unknown>;
247
- }
248
- /**
249
- * Pre-bound builder attached to `targetEditCommit` payloads. Calling it
250
- * commits the suggestion with the SDK's default summary/metadata, optionally
251
- * overridden by `result`. If the customer's `onTargetEditCommit` handler
252
- * already returned a non-null result for this edit, this builder is a no-op
253
- * (resolves immediately) so subscribers can't double-commit.
254
- */
255
- export type TargetEditCommitBuilder = (result?: TargetEditCommitResult) => Promise<{
256
- id: string;
257
- } | null>;
258
- export interface SuggestionGetSuggestionsFilter {
259
- targetId?: string;
260
- status?: SuggestionStatus | SuggestionStatus[];
261
- }
262
- export {};