@attrove/sdk 0.1.3 → 0.1.4

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/cjs/README.md +247 -0
  2. package/cjs/package.json +56 -0
  3. package/cjs/src/__mocks__/version.js +17 -0
  4. package/cjs/src/__mocks__/version.js.map +1 -0
  5. package/cjs/src/admin-client.js +221 -0
  6. package/cjs/src/admin-client.js.map +1 -0
  7. package/cjs/src/client.js +312 -0
  8. package/cjs/src/client.js.map +1 -0
  9. package/cjs/src/constants.js +69 -0
  10. package/cjs/src/constants.js.map +1 -0
  11. package/cjs/src/errors/index.js +307 -0
  12. package/cjs/src/errors/index.js.map +1 -0
  13. package/cjs/src/index.js +98 -0
  14. package/cjs/src/index.js.map +1 -0
  15. package/cjs/src/resources/conversations.js +95 -0
  16. package/cjs/src/resources/conversations.js.map +1 -0
  17. package/cjs/src/resources/index.js +17 -0
  18. package/cjs/src/resources/index.js.map +1 -0
  19. package/cjs/src/resources/integrations.js +69 -0
  20. package/cjs/src/resources/integrations.js.map +1 -0
  21. package/cjs/src/resources/messages.js +98 -0
  22. package/cjs/src/resources/messages.js.map +1 -0
  23. package/cjs/src/resources/query.js +143 -0
  24. package/cjs/src/resources/query.js.map +1 -0
  25. package/cjs/src/resources/users.js +91 -0
  26. package/cjs/src/resources/users.js.map +1 -0
  27. package/cjs/src/types/index.js +292 -0
  28. package/cjs/src/types/index.js.map +1 -0
  29. package/cjs/src/utils/fetch.js +417 -0
  30. package/cjs/src/utils/fetch.js.map +1 -0
  31. package/cjs/src/utils/index.js +12 -0
  32. package/cjs/src/utils/index.js.map +1 -0
  33. package/cjs/src/utils/streaming.js +368 -0
  34. package/cjs/src/utils/streaming.js.map +1 -0
  35. package/cjs/src/version.js +31 -0
  36. package/cjs/src/version.js.map +1 -0
  37. package/esm/README.md +247 -0
  38. package/esm/package.json +56 -0
  39. package/esm/src/__mocks__/version.js +12 -0
  40. package/esm/src/__mocks__/version.js.map +1 -0
  41. package/esm/src/admin-client.js +216 -0
  42. package/esm/src/admin-client.js.map +1 -0
  43. package/esm/src/client.js +308 -0
  44. package/esm/src/client.js.map +1 -0
  45. package/esm/src/constants.js +65 -0
  46. package/esm/src/constants.js.map +1 -0
  47. package/esm/src/errors/index.js +285 -0
  48. package/esm/src/errors/index.js.map +1 -0
  49. package/esm/src/index.js +68 -0
  50. package/esm/src/index.js.map +1 -0
  51. package/esm/src/resources/conversations.js +91 -0
  52. package/esm/src/resources/conversations.js.map +1 -0
  53. package/esm/src/resources/index.js +9 -0
  54. package/esm/src/resources/index.js.map +1 -0
  55. package/esm/src/resources/integrations.js +65 -0
  56. package/esm/src/resources/integrations.js.map +1 -0
  57. package/esm/src/resources/messages.js +94 -0
  58. package/esm/src/resources/messages.js.map +1 -0
  59. package/esm/src/resources/query.js +139 -0
  60. package/esm/src/resources/query.js.map +1 -0
  61. package/esm/src/resources/users.js +87 -0
  62. package/esm/src/resources/users.js.map +1 -0
  63. package/esm/src/types/index.js +277 -0
  64. package/esm/src/types/index.js.map +1 -0
  65. package/esm/src/utils/fetch.js +413 -0
  66. package/esm/src/utils/fetch.js.map +1 -0
  67. package/esm/src/utils/index.js +6 -0
  68. package/esm/src/utils/index.js.map +1 -0
  69. package/esm/src/utils/streaming.js +363 -0
  70. package/esm/src/utils/streaming.js.map +1 -0
  71. package/esm/src/version.js +26 -0
  72. package/esm/src/version.js.map +1 -0
  73. package/package.json +16 -9
  74. package/types/src/__mocks__/version.d.ts +8 -0
  75. package/types/src/__mocks__/version.d.ts.map +1 -0
  76. package/types/src/admin-client.d.ts +144 -0
  77. package/types/src/admin-client.d.ts.map +1 -0
  78. package/types/src/client.d.ts +233 -0
  79. package/types/src/client.d.ts.map +1 -0
  80. package/types/src/constants.d.ts +47 -0
  81. package/types/src/constants.d.ts.map +1 -0
  82. package/types/src/errors/index.d.ts +206 -0
  83. package/types/src/errors/index.d.ts.map +1 -0
  84. package/types/src/index.d.ts +65 -0
  85. package/types/src/index.d.ts.map +1 -0
  86. package/types/src/resources/conversations.d.ts +81 -0
  87. package/types/src/resources/conversations.d.ts.map +1 -0
  88. package/types/src/resources/index.d.ts +12 -0
  89. package/types/src/resources/index.d.ts.map +1 -0
  90. package/types/src/resources/integrations.d.ts +63 -0
  91. package/types/src/resources/integrations.d.ts.map +1 -0
  92. package/types/src/resources/messages.d.ts +69 -0
  93. package/types/src/resources/messages.d.ts.map +1 -0
  94. package/types/src/resources/query.d.ts +86 -0
  95. package/types/src/resources/query.d.ts.map +1 -0
  96. package/types/src/resources/users.d.ts +88 -0
  97. package/types/src/resources/users.d.ts.map +1 -0
  98. package/types/src/types/index.d.ts +807 -0
  99. package/types/src/types/index.d.ts.map +1 -0
  100. package/types/src/utils/fetch.d.ts +161 -0
  101. package/types/src/utils/fetch.d.ts.map +1 -0
  102. package/types/src/utils/index.d.ts +8 -0
  103. package/types/src/utils/index.d.ts.map +1 -0
  104. package/types/src/utils/streaming.d.ts +210 -0
  105. package/types/src/utils/streaming.d.ts.map +1 -0
  106. package/types/src/version.d.ts +21 -0
  107. package/types/src/version.d.ts.map +1 -0
@@ -0,0 +1,807 @@
1
+ /**
2
+ * Attrove SDK Types
3
+ *
4
+ * Standalone type definitions for the SDK. These are bundled with the package
5
+ * and do not depend on internal monorepo packages.
6
+ */
7
+ /**
8
+ * Branded type for UUID strings.
9
+ * Prevents accidental mixing of different ID types at compile time.
10
+ */
11
+ export type UUID = string & {
12
+ readonly __brand: 'UUID';
13
+ };
14
+ /**
15
+ * Branded type for user IDs.
16
+ */
17
+ export type UserId = string & {
18
+ readonly __brand: 'UserId';
19
+ };
20
+ /**
21
+ * Branded type for integration IDs.
22
+ */
23
+ export type IntegrationId = string & {
24
+ readonly __brand: 'IntegrationId';
25
+ };
26
+ /**
27
+ * Branded type for message IDs.
28
+ */
29
+ export type MessageId = string & {
30
+ readonly __brand: 'MessageId';
31
+ };
32
+ /**
33
+ * Branded type for conversation IDs.
34
+ */
35
+ export type ConversationId = string & {
36
+ readonly __brand: 'ConversationId';
37
+ };
38
+ /**
39
+ * Template literal type for API key format validation.
40
+ * Provides compile-time validation that API keys start with 'sk_'.
41
+ */
42
+ export type ApiKeyFormat = `sk_${string}`;
43
+ /**
44
+ * Branded type for API key tokens (sk_ prefix).
45
+ * Use ApiKeyFormat for compile-time validation of the prefix format.
46
+ */
47
+ export type ApiKeyToken = ApiKeyFormat & {
48
+ readonly __brand: 'ApiKeyToken';
49
+ };
50
+ /**
51
+ * Branded type for ISO 8601 date strings.
52
+ */
53
+ export type ISODateString = string & {
54
+ readonly __brand: 'ISODateString';
55
+ };
56
+ /**
57
+ * Helper to cast a string to a branded type.
58
+ *
59
+ * Use with caution - this bypasses type safety. Prefer using the
60
+ * validation factory functions (createUserId, createApiKey, etc.)
61
+ * which validate the input before branding.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * // Only use after validating the format
66
+ * const userId = asBrandedString<UserId>(validatedUuid);
67
+ * ```
68
+ */
69
+ export declare function asBrandedString<T extends string>(value: string): T;
70
+ /**
71
+ * Check if a string is a valid UUID format.
72
+ * Validates the 8-4-4-4-12 hexadecimal format but does not enforce a specific UUID version.
73
+ *
74
+ * @param value - String to validate
75
+ * @returns True if the string is a valid UUID format
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * if (isValidUUID(userId)) {
80
+ * // proceed with the valid UUID
81
+ * }
82
+ * ```
83
+ */
84
+ export declare function isValidUUID(value: string): boolean;
85
+ /**
86
+ * Result of a validation attempt.
87
+ */
88
+ export type ValidationResult<T> = {
89
+ success: true;
90
+ value: T;
91
+ } | {
92
+ success: false;
93
+ error: string;
94
+ };
95
+ /**
96
+ * Validate and create a UserId from a string.
97
+ *
98
+ * @param value - String to validate
99
+ * @returns Validation result with branded UserId or error message
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * const result = createUserId('550e8400-e29b-41d4-a716-446655440000');
104
+ * if (result.success) {
105
+ * const userId: UserId = result.value;
106
+ * } else {
107
+ * console.error(result.error);
108
+ * }
109
+ * ```
110
+ */
111
+ export declare function createUserId(value: string): ValidationResult<UserId>;
112
+ /**
113
+ * Validate and create an IntegrationId from a string.
114
+ */
115
+ export declare function createIntegrationId(value: string): ValidationResult<IntegrationId>;
116
+ /**
117
+ * Validate and create a MessageId from a string.
118
+ */
119
+ export declare function createMessageId(value: string): ValidationResult<MessageId>;
120
+ /**
121
+ * Validate and create a ConversationId from a string.
122
+ */
123
+ export declare function createConversationId(value: string): ValidationResult<ConversationId>;
124
+ /**
125
+ * Validate and create an ApiKeyToken from a string.
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * const result = createApiKey('sk_live_abc123');
130
+ * if (result.success) {
131
+ * const apiKey: ApiKeyToken = result.value;
132
+ * }
133
+ * ```
134
+ */
135
+ export declare function createApiKey(value: string): ValidationResult<ApiKeyToken>;
136
+ /**
137
+ * Validate and create an ISODateString from a string.
138
+ *
139
+ * @example
140
+ * ```ts
141
+ * const result = createISODate('2024-01-15T10:30:00Z');
142
+ * if (result.success) {
143
+ * const date: ISODateString = result.value;
144
+ * }
145
+ * ```
146
+ */
147
+ export declare function createISODate(value: string): ValidationResult<ISODateString>;
148
+ /**
149
+ * Validate and create a UUID from a string.
150
+ */
151
+ export declare function createUUID(value: string): ValidationResult<UUID>;
152
+ /**
153
+ * Check if a string is a valid API key format.
154
+ */
155
+ export declare function isValidApiKey(value: string): boolean;
156
+ /**
157
+ * Check if a string is a valid ISO 8601 date format.
158
+ */
159
+ export declare function isValidISODate(value: string): boolean;
160
+ /**
161
+ * Configuration options for the Attrove client.
162
+ */
163
+ export interface AttroveConfig {
164
+ /**
165
+ * API key for authentication. Must start with `sk_` prefix.
166
+ * Template literal type provides compile-time validation of the prefix.
167
+ */
168
+ apiKey: ApiKeyFormat;
169
+ /**
170
+ * User ID (UUID) to scope API calls to a specific user.
171
+ */
172
+ userId: string;
173
+ /**
174
+ * Optional base URL for the API. Defaults to https://api.attrove.com.
175
+ */
176
+ baseUrl?: string;
177
+ /**
178
+ * Request timeout in milliseconds. Defaults to 30000 (30 seconds).
179
+ */
180
+ timeout?: number;
181
+ /**
182
+ * Number of retry attempts for failed requests. Defaults to 3.
183
+ */
184
+ maxRetries?: number;
185
+ /**
186
+ * Optional callback invoked before each retry attempt.
187
+ * Useful for logging or monitoring retry behavior.
188
+ */
189
+ onRetry?: (info: RetryInfo) => void;
190
+ }
191
+ /**
192
+ * Information about a retry attempt.
193
+ */
194
+ export interface RetryInfo {
195
+ /** Current retry attempt (1-indexed) */
196
+ attempt: number;
197
+ /** Maximum number of retries configured */
198
+ maxRetries: number;
199
+ /** The error that triggered the retry */
200
+ error: Error;
201
+ /** Delay in milliseconds before the retry */
202
+ delayMs: number;
203
+ /** The URL being requested */
204
+ url: string;
205
+ /** The HTTP method */
206
+ method: string;
207
+ }
208
+ /**
209
+ * Configuration options for the Attrove admin client (server-to-server).
210
+ */
211
+ export interface AttroveAdminConfig {
212
+ /**
213
+ * Partner client ID.
214
+ */
215
+ clientId: string;
216
+ /**
217
+ * Partner client secret.
218
+ */
219
+ clientSecret: string;
220
+ /**
221
+ * Optional base URL for the API. Defaults to https://api.attrove.com.
222
+ */
223
+ baseUrl?: string;
224
+ /**
225
+ * Request timeout in milliseconds. Defaults to 30000 (30 seconds).
226
+ */
227
+ timeout?: number;
228
+ /**
229
+ * Number of retry attempts for failed requests. Defaults to 3.
230
+ */
231
+ maxRetries?: number;
232
+ /**
233
+ * Optional callback invoked before each retry attempt.
234
+ */
235
+ onRetry?: (info: RetryInfo) => void;
236
+ }
237
+ /**
238
+ * Standardized error codes from the Attrove API.
239
+ */
240
+ export declare const ErrorCodes: {
241
+ readonly AUTH_MISSING_TOKEN: "AUTH_MISSING_TOKEN";
242
+ readonly AUTH_INVALID_TOKEN: "AUTH_INVALID_TOKEN";
243
+ readonly AUTH_EXPIRED_TOKEN: "AUTH_EXPIRED_TOKEN";
244
+ readonly AUTH_USER_MISMATCH: "AUTH_USER_MISMATCH";
245
+ readonly AUTH_INSUFFICIENT_PERMISSIONS: "AUTH_INSUFFICIENT_PERMISSIONS";
246
+ readonly RESOURCE_NOT_FOUND: "RESOURCE_NOT_FOUND";
247
+ readonly RESOURCE_ACCESS_DENIED: "RESOURCE_ACCESS_DENIED";
248
+ readonly RESOURCE_ALREADY_EXISTS: "RESOURCE_ALREADY_EXISTS";
249
+ readonly RESOURCE_DELETED: "RESOURCE_DELETED";
250
+ readonly VALIDATION_INVALID_ID: "VALIDATION_INVALID_ID";
251
+ readonly VALIDATION_REQUIRED_FIELD: "VALIDATION_REQUIRED_FIELD";
252
+ readonly VALIDATION_INVALID_FORMAT: "VALIDATION_INVALID_FORMAT";
253
+ readonly VALIDATION_OUT_OF_RANGE: "VALIDATION_OUT_OF_RANGE";
254
+ readonly INTEGRATION_OAUTH_FAILED: "INTEGRATION_OAUTH_FAILED";
255
+ readonly INTEGRATION_EMAIL_EXISTS: "INTEGRATION_EMAIL_EXISTS";
256
+ readonly INTEGRATION_TOKEN_EXPIRED: "INTEGRATION_TOKEN_EXPIRED";
257
+ readonly INTEGRATION_SYNC_FAILED: "INTEGRATION_SYNC_FAILED";
258
+ readonly INTEGRATION_NOT_CONNECTED: "INTEGRATION_NOT_CONNECTED";
259
+ readonly RATE_LIMIT_EXCEEDED: "RATE_LIMIT_EXCEEDED";
260
+ readonly INTERNAL_ERROR: "INTERNAL_ERROR";
261
+ readonly SERVICE_UNAVAILABLE: "SERVICE_UNAVAILABLE";
262
+ };
263
+ export type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
264
+ /**
265
+ * Authentication-related error codes.
266
+ */
267
+ export type AuthErrorCode = typeof ErrorCodes.AUTH_MISSING_TOKEN | typeof ErrorCodes.AUTH_INVALID_TOKEN | typeof ErrorCodes.AUTH_EXPIRED_TOKEN | typeof ErrorCodes.AUTH_USER_MISMATCH | typeof ErrorCodes.AUTH_INSUFFICIENT_PERMISSIONS;
268
+ /**
269
+ * Validation-related error codes.
270
+ */
271
+ export type ValidationErrorCode = typeof ErrorCodes.VALIDATION_INVALID_ID | typeof ErrorCodes.VALIDATION_REQUIRED_FIELD | typeof ErrorCodes.VALIDATION_INVALID_FORMAT | typeof ErrorCodes.VALIDATION_OUT_OF_RANGE;
272
+ /**
273
+ * Base error details shared by all error types.
274
+ */
275
+ interface BaseErrorDetails {
276
+ /** Additional context-specific properties */
277
+ [key: string]: unknown;
278
+ }
279
+ /**
280
+ * Error details for validation errors.
281
+ */
282
+ export interface ValidationErrorDetails extends BaseErrorDetails {
283
+ category: 'validation';
284
+ /** Field name that failed validation */
285
+ field?: string;
286
+ /** Fields that were provided (for partial credential errors) */
287
+ providedFields?: string[];
288
+ /** Expected value or format */
289
+ expected?: string;
290
+ /** Received value or format */
291
+ received?: string;
292
+ /** Actual value that caused the error */
293
+ value?: unknown;
294
+ }
295
+ /**
296
+ * Error details for rate limiting errors.
297
+ */
298
+ export interface RateLimitErrorDetails extends BaseErrorDetails {
299
+ category: 'rateLimit';
300
+ /** Time in seconds until rate limit resets */
301
+ retryAfter?: number;
302
+ /** Rate limit ceiling */
303
+ limit?: number;
304
+ }
305
+ /**
306
+ * Error details for resource errors (not found, access denied, etc.).
307
+ */
308
+ export interface ResourceErrorDetails extends BaseErrorDetails {
309
+ category: 'resource';
310
+ /** Type of resource involved */
311
+ resourceType?: string;
312
+ /** ID of resource involved */
313
+ resourceId?: string;
314
+ }
315
+ /**
316
+ * Error details for network/wrapped errors.
317
+ */
318
+ export interface NetworkErrorDetails extends BaseErrorDetails {
319
+ category: 'network';
320
+ /** Original error name for wrapped errors */
321
+ originalErrorName?: string;
322
+ /** Original error message for wrapped errors */
323
+ originalErrorMessage?: string;
324
+ /** Truncated stack trace for debugging */
325
+ originalStack?: string;
326
+ }
327
+ /**
328
+ * Error details for parse/serialization errors.
329
+ */
330
+ export interface ParseErrorDetails extends BaseErrorDetails {
331
+ category: 'parse';
332
+ /** Truncated response preview for debugging */
333
+ responsePreview?: string;
334
+ /** Truncated raw data preview for debugging */
335
+ rawDataPreview?: string;
336
+ }
337
+ /**
338
+ * Generic error details for errors that don't fit other categories.
339
+ * Note: category is optional for backward compatibility with existing code
340
+ * that passes arbitrary details without specifying a category.
341
+ */
342
+ export interface GenericErrorDetails extends BaseErrorDetails {
343
+ category?: 'generic';
344
+ }
345
+ /**
346
+ * Discriminated union of error details for type-safe error handling.
347
+ * The `category` field discriminates which type of error details are present.
348
+ *
349
+ * @example
350
+ * ```ts
351
+ * if (error.details?.category === 'validation') {
352
+ * console.log('Invalid field:', error.details.field);
353
+ * } else if (error.details?.category === 'rateLimit') {
354
+ * console.log('Retry after:', error.details.retryAfter);
355
+ * }
356
+ * ```
357
+ */
358
+ export type ErrorDetails = ValidationErrorDetails | RateLimitErrorDetails | ResourceErrorDetails | NetworkErrorDetails | ParseErrorDetails | GenericErrorDetails;
359
+ /**
360
+ * API error response structure.
361
+ */
362
+ export interface ApiError {
363
+ code: ErrorCode;
364
+ message: string;
365
+ details?: ErrorDetails;
366
+ }
367
+ /**
368
+ * Pagination metadata for list responses.
369
+ */
370
+ export interface Pagination {
371
+ limit: number;
372
+ offset: number;
373
+ has_more: boolean;
374
+ total_count?: number;
375
+ }
376
+ /**
377
+ * Success response wrapper.
378
+ */
379
+ export interface SuccessResponse<T> {
380
+ success: true;
381
+ data: T;
382
+ }
383
+ /**
384
+ * Paginated success response wrapper.
385
+ */
386
+ export interface PaginatedResponse<T> {
387
+ success: true;
388
+ data: T[];
389
+ pagination: Pagination;
390
+ }
391
+ /**
392
+ * Error response wrapper.
393
+ * Note: The error is always normalized to ApiError format in the SDK.
394
+ */
395
+ export interface ErrorResponse {
396
+ success: false;
397
+ error: ApiError;
398
+ }
399
+ /**
400
+ * Generic API response type.
401
+ */
402
+ export type ApiResponse<T> = SuccessResponse<T> | ErrorResponse;
403
+ /**
404
+ * Supported integration providers.
405
+ * Note: 'unknown' is included for forward compatibility with new providers.
406
+ */
407
+ export type IntegrationProvider = 'slack' | 'gmail' | 'outlook' | 'google_calendar' | 'unknown';
408
+ /**
409
+ * Authentication status for an integration.
410
+ * Note: 'unknown' is included for forward compatibility with new statuses.
411
+ */
412
+ export type AuthStatus = 'connected' | 'disconnected' | 'expired' | 'error' | 'pending' | 'unknown';
413
+ /**
414
+ * Sync status for an integration.
415
+ * Note: 'unknown' is included for forward compatibility with new statuses.
416
+ */
417
+ export type SyncStatus = 'syncing' | 'complete' | 'partial' | 'error' | 'pending' | 'paused' | 'unknown';
418
+ /**
419
+ * User profile information.
420
+ */
421
+ export interface User {
422
+ id: string;
423
+ email: string;
424
+ first_name: string | null;
425
+ last_name: string | null;
426
+ full_name: string | null;
427
+ role: string | null;
428
+ timezone: string | null;
429
+ onboarded: boolean;
430
+ }
431
+ /**
432
+ * Integration (connected service) information.
433
+ */
434
+ export interface Integration {
435
+ id: string;
436
+ provider: IntegrationProvider;
437
+ name: string;
438
+ is_active: boolean;
439
+ auth_status: AuthStatus;
440
+ }
441
+ /**
442
+ * Message from a connected service.
443
+ */
444
+ export interface Message {
445
+ id: string;
446
+ integration_id: string;
447
+ body_text?: string;
448
+ subject: string | null;
449
+ received_at: string;
450
+ parent_message_id: string | null;
451
+ thread_position: number | null;
452
+ is_bot: boolean;
453
+ conversation_id: string | null;
454
+ }
455
+ /**
456
+ * Conversation type.
457
+ * Note: 'unknown' is included for forward compatibility with new types.
458
+ */
459
+ export type ConversationType = 'channel' | 'direct_message' | 'group' | 'email_thread' | 'other' | 'unknown';
460
+ /**
461
+ * Conversation (channel, thread, etc.) from a connected service.
462
+ */
463
+ export interface Conversation {
464
+ id: string;
465
+ integration_id: string;
466
+ title: string;
467
+ type: ConversationType;
468
+ provider: IntegrationProvider;
469
+ import_messages: boolean;
470
+ }
471
+ /**
472
+ * Calendar event.
473
+ */
474
+ export interface CalendarEvent {
475
+ id: string;
476
+ calendar_id: string;
477
+ title: string;
478
+ start_time: string;
479
+ end_time: string;
480
+ all_day: boolean;
481
+ description?: string;
482
+ location?: string;
483
+ attendees?: Array<{
484
+ email: string;
485
+ name?: string;
486
+ status?: string;
487
+ }>;
488
+ html_link?: string;
489
+ }
490
+ /**
491
+ * Meeting with AI-generated summary.
492
+ */
493
+ export interface Meeting {
494
+ id: string;
495
+ event_id: string;
496
+ title: string;
497
+ start_time: string;
498
+ end_time: string;
499
+ summary?: string;
500
+ short_summary?: string;
501
+ action_items?: string[];
502
+ attendees?: Array<{
503
+ email: string;
504
+ name?: string;
505
+ }>;
506
+ meeting_link?: string;
507
+ }
508
+ /**
509
+ * Entity type.
510
+ */
511
+ export type EntityType = 'person' | 'company' | 'other';
512
+ /**
513
+ * Entity (person, company, etc.) identified from messages.
514
+ */
515
+ export interface Entity {
516
+ id: string;
517
+ name: string;
518
+ type: EntityType;
519
+ email?: string;
520
+ domain?: string;
521
+ message_count: number;
522
+ last_interaction?: string;
523
+ }
524
+ /**
525
+ * Overall sync status.
526
+ */
527
+ export type OverallSyncStatus = 'syncing' | 'complete' | 'partial' | 'error' | 'pending';
528
+ /**
529
+ * Integration sync statistics.
530
+ */
531
+ export interface IntegrationSyncStats {
532
+ id: string;
533
+ provider: IntegrationProvider;
534
+ name: string;
535
+ status: SyncStatus;
536
+ message_count: number;
537
+ meeting_count: number;
538
+ event_count: number;
539
+ last_synced_at: string | null;
540
+ }
541
+ /**
542
+ * Sync statistics for a user's integrations.
543
+ */
544
+ export interface SyncStats {
545
+ user_id: string;
546
+ overall_status: OverallSyncStatus;
547
+ last_sync_at: string | null;
548
+ totals: {
549
+ messages: {
550
+ count: number;
551
+ earliest?: string;
552
+ latest?: string;
553
+ };
554
+ meetings: {
555
+ count: number;
556
+ earliest?: string;
557
+ latest?: string;
558
+ };
559
+ events: {
560
+ count: number;
561
+ earliest?: string;
562
+ latest?: string;
563
+ };
564
+ };
565
+ integrations: IntegrationSyncStats[];
566
+ }
567
+ /**
568
+ * Conversation history message for RAG queries.
569
+ */
570
+ export interface ConversationMessage {
571
+ role: 'user' | 'assistant' | 'system';
572
+ content: string;
573
+ }
574
+ /**
575
+ * Options for the query() method.
576
+ */
577
+ export interface QueryOptions {
578
+ /**
579
+ * Conversation history for multi-turn conversations.
580
+ */
581
+ history?: ConversationMessage[];
582
+ /**
583
+ * User's timezone (IANA format). Helps with date-aware queries.
584
+ */
585
+ timezone?: string;
586
+ /**
587
+ * Filter to specific integration IDs.
588
+ */
589
+ integrationIds?: string[];
590
+ /**
591
+ * Filter to specific conversation IDs.
592
+ */
593
+ conversationIds?: string[];
594
+ /**
595
+ * Include bot messages in search results. Defaults to false.
596
+ */
597
+ allowBotMessages?: boolean;
598
+ /**
599
+ * Include source snippets in response. Defaults to false.
600
+ */
601
+ includeSources?: boolean;
602
+ }
603
+ /**
604
+ * Source reference from a RAG query response.
605
+ */
606
+ export interface QuerySource {
607
+ title: string;
608
+ snippet: string;
609
+ }
610
+ /**
611
+ * Response from the query() method.
612
+ */
613
+ export interface QueryResponse {
614
+ answer: string;
615
+ history: ConversationMessage[];
616
+ used_message_ids: string[];
617
+ sources?: QuerySource[];
618
+ }
619
+ /**
620
+ * Options for the search() method.
621
+ */
622
+ export interface SearchOptions {
623
+ /**
624
+ * Filter to specific integration IDs.
625
+ */
626
+ integrationIds?: string[];
627
+ /**
628
+ * Filter to specific conversation IDs.
629
+ */
630
+ conversationIds?: string[];
631
+ /**
632
+ * Filter messages after this date (ISO 8601).
633
+ */
634
+ afterDate?: string;
635
+ /**
636
+ * Filter messages before this date (ISO 8601).
637
+ */
638
+ beforeDate?: string;
639
+ /**
640
+ * Include bot messages in search results. Defaults to false.
641
+ */
642
+ allowBotMessages?: boolean;
643
+ /**
644
+ * Filter by sender email domains (e.g., ['acme.com']).
645
+ */
646
+ senderDomains?: string[];
647
+ /**
648
+ * Filter by entity IDs.
649
+ */
650
+ entityIds?: string[];
651
+ /**
652
+ * Include message body text. Defaults to false.
653
+ */
654
+ includeBodyText?: boolean;
655
+ }
656
+ /**
657
+ * Key message reference from search results.
658
+ * Note: IDs are strings for consistency (converted from API numbers).
659
+ */
660
+ export interface SearchKeyMessage {
661
+ message_id: string;
662
+ thread_id: string | null;
663
+ conversation_id: string | null;
664
+ }
665
+ /**
666
+ * Thread message in search results.
667
+ * Note: IDs are strings for consistency (converted from API numbers).
668
+ */
669
+ export interface SearchThreadMessage {
670
+ message_id: string;
671
+ received_at: string;
672
+ integration_type: IntegrationProvider;
673
+ integration_type_generic: string;
674
+ sender_name: string;
675
+ recipient_names: string[];
676
+ body_text?: string;
677
+ thread_id: string | null;
678
+ thread_message_count: number | null;
679
+ thread_position: number | null;
680
+ parent_message_id: string | null;
681
+ conversation_type: ConversationType | null;
682
+ conversation_id: string | null;
683
+ conversation_participants: Array<{
684
+ name: string;
685
+ }>;
686
+ }
687
+ /**
688
+ * Conversation data in search results.
689
+ */
690
+ export interface SearchConversation {
691
+ conversation_name: string | null;
692
+ threads: Record<string, SearchThreadMessage[]>;
693
+ }
694
+ /**
695
+ * Response from the search() method.
696
+ */
697
+ export interface SearchResponse {
698
+ key_messages: SearchKeyMessage[];
699
+ conversations: Record<string, SearchConversation>;
700
+ }
701
+ /**
702
+ * Options for creating a user.
703
+ */
704
+ export interface CreateUserOptions {
705
+ email: string;
706
+ firstName?: string;
707
+ lastName?: string;
708
+ role?: string;
709
+ }
710
+ /**
711
+ * Response from creating a user.
712
+ * Note: `apiKey` is an sk_ prefixed API key for authenticating as this user.
713
+ */
714
+ export interface CreateUserResponse {
715
+ /** The user's ID (UUID format) */
716
+ id: string;
717
+ /** API key (sk_ prefix) for authenticating requests as this user */
718
+ apiKey: string;
719
+ }
720
+ /**
721
+ * Response from creating an integration token.
722
+ */
723
+ export interface CreateTokenResponse {
724
+ token: string;
725
+ expires_at: string;
726
+ }
727
+ /**
728
+ * Stream state during query processing.
729
+ */
730
+ export type StreamState = 'selecting_messages' | 'streaming' | 'completed' | 'cancelled' | 'error';
731
+ /**
732
+ * Stream end reasons.
733
+ */
734
+ export type StreamEndReason = 'completed' | 'cancelled' | 'error';
735
+ /**
736
+ * Frame types for WebSocket streaming.
737
+ * Note: used_message_ids are strings for consistency.
738
+ */
739
+ export type StreamFrame = {
740
+ type: 'chunk';
741
+ message_id: string;
742
+ content: string;
743
+ } | {
744
+ type: 'end';
745
+ message_id: string;
746
+ reason: StreamEndReason;
747
+ used_message_ids?: string[];
748
+ } | {
749
+ type: 'error';
750
+ message_id: string;
751
+ error: string;
752
+ } | {
753
+ type: 'state';
754
+ message_id: string;
755
+ state: StreamState;
756
+ } | {
757
+ type: 'message_ids';
758
+ message_id: string;
759
+ used_message_ids: string[];
760
+ } | {
761
+ type: 'stream_start';
762
+ message_id: string;
763
+ };
764
+ /**
765
+ * Runtime validator for StreamFrame objects.
766
+ * Validates that parsed JSON has the required structure for a StreamFrame.
767
+ *
768
+ * @param data - Unknown data to validate (typically from JSON.parse)
769
+ * @returns True if the data is a valid StreamFrame, false otherwise
770
+ *
771
+ * @example
772
+ * ```ts
773
+ * const parsed = JSON.parse(event.data);
774
+ * if (isValidStreamFrame(parsed)) {
775
+ * // TypeScript knows parsed is StreamFrame
776
+ * handleFrame(parsed);
777
+ * }
778
+ * ```
779
+ */
780
+ export declare function isValidStreamFrame(data: unknown): data is StreamFrame;
781
+ /**
782
+ * Pagination options for list methods.
783
+ */
784
+ export interface PaginationOptions {
785
+ limit?: number;
786
+ offset?: number;
787
+ }
788
+ /**
789
+ * Options for listing messages.
790
+ */
791
+ export interface ListMessagesOptions extends PaginationOptions {
792
+ ids?: string[];
793
+ integrationId?: string;
794
+ conversationId?: string;
795
+ startDate?: string;
796
+ endDate?: string;
797
+ expand?: string[];
798
+ }
799
+ /**
800
+ * Options for listing conversations.
801
+ */
802
+ export interface ListConversationsOptions extends PaginationOptions {
803
+ integrationIds?: string[];
804
+ syncedOnly?: boolean;
805
+ }
806
+ export {};
807
+ //# sourceMappingURL=index.d.ts.map