@attrove/sdk 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/README.md +247 -0
- package/cjs/package.json +56 -0
- package/cjs/src/__mocks__/version.js +17 -0
- package/cjs/src/__mocks__/version.js.map +1 -0
- package/cjs/src/admin-client.js +221 -0
- package/cjs/src/admin-client.js.map +1 -0
- package/cjs/src/client.js +312 -0
- package/cjs/src/client.js.map +1 -0
- package/cjs/src/constants.js +69 -0
- package/cjs/src/constants.js.map +1 -0
- package/cjs/src/errors/index.js +307 -0
- package/cjs/src/errors/index.js.map +1 -0
- package/cjs/src/index.js +98 -0
- package/cjs/src/index.js.map +1 -0
- package/cjs/src/resources/conversations.js +95 -0
- package/cjs/src/resources/conversations.js.map +1 -0
- package/cjs/src/resources/index.js +17 -0
- package/cjs/src/resources/index.js.map +1 -0
- package/cjs/src/resources/integrations.js +69 -0
- package/cjs/src/resources/integrations.js.map +1 -0
- package/cjs/src/resources/messages.js +98 -0
- package/cjs/src/resources/messages.js.map +1 -0
- package/cjs/src/resources/query.js +143 -0
- package/cjs/src/resources/query.js.map +1 -0
- package/cjs/src/resources/users.js +91 -0
- package/cjs/src/resources/users.js.map +1 -0
- package/cjs/src/types/index.js +292 -0
- package/cjs/src/types/index.js.map +1 -0
- package/cjs/src/utils/fetch.js +417 -0
- package/cjs/src/utils/fetch.js.map +1 -0
- package/cjs/src/utils/index.js +12 -0
- package/cjs/src/utils/index.js.map +1 -0
- package/cjs/src/utils/streaming.js +368 -0
- package/cjs/src/utils/streaming.js.map +1 -0
- package/cjs/src/version.js +31 -0
- package/cjs/src/version.js.map +1 -0
- package/esm/README.md +247 -0
- package/esm/package.json +56 -0
- package/esm/src/__mocks__/version.js +12 -0
- package/esm/src/__mocks__/version.js.map +1 -0
- package/esm/src/admin-client.js +216 -0
- package/esm/src/admin-client.js.map +1 -0
- package/esm/src/client.js +308 -0
- package/esm/src/client.js.map +1 -0
- package/esm/src/constants.js +65 -0
- package/esm/src/constants.js.map +1 -0
- package/esm/src/errors/index.js +285 -0
- package/esm/src/errors/index.js.map +1 -0
- package/esm/src/index.js +68 -0
- package/esm/src/index.js.map +1 -0
- package/esm/src/resources/conversations.js +91 -0
- package/esm/src/resources/conversations.js.map +1 -0
- package/esm/src/resources/index.js +9 -0
- package/esm/src/resources/index.js.map +1 -0
- package/esm/src/resources/integrations.js +65 -0
- package/esm/src/resources/integrations.js.map +1 -0
- package/esm/src/resources/messages.js +94 -0
- package/esm/src/resources/messages.js.map +1 -0
- package/esm/src/resources/query.js +139 -0
- package/esm/src/resources/query.js.map +1 -0
- package/esm/src/resources/users.js +87 -0
- package/esm/src/resources/users.js.map +1 -0
- package/esm/src/types/index.js +277 -0
- package/esm/src/types/index.js.map +1 -0
- package/esm/src/utils/fetch.js +413 -0
- package/esm/src/utils/fetch.js.map +1 -0
- package/esm/src/utils/index.js +6 -0
- package/esm/src/utils/index.js.map +1 -0
- package/esm/src/utils/streaming.js +363 -0
- package/esm/src/utils/streaming.js.map +1 -0
- package/esm/src/version.js +26 -0
- package/esm/src/version.js.map +1 -0
- package/package.json +16 -9
- package/types/src/__mocks__/version.d.ts +8 -0
- package/types/src/__mocks__/version.d.ts.map +1 -0
- package/types/src/admin-client.d.ts +144 -0
- package/types/src/admin-client.d.ts.map +1 -0
- package/types/src/client.d.ts +233 -0
- package/types/src/client.d.ts.map +1 -0
- package/types/src/constants.d.ts +47 -0
- package/types/src/constants.d.ts.map +1 -0
- package/types/src/errors/index.d.ts +206 -0
- package/types/src/errors/index.d.ts.map +1 -0
- package/types/src/index.d.ts +65 -0
- package/types/src/index.d.ts.map +1 -0
- package/types/src/resources/conversations.d.ts +81 -0
- package/types/src/resources/conversations.d.ts.map +1 -0
- package/types/src/resources/index.d.ts +12 -0
- package/types/src/resources/index.d.ts.map +1 -0
- package/types/src/resources/integrations.d.ts +63 -0
- package/types/src/resources/integrations.d.ts.map +1 -0
- package/types/src/resources/messages.d.ts +69 -0
- package/types/src/resources/messages.d.ts.map +1 -0
- package/types/src/resources/query.d.ts +86 -0
- package/types/src/resources/query.d.ts.map +1 -0
- package/types/src/resources/users.d.ts +88 -0
- package/types/src/resources/users.d.ts.map +1 -0
- package/types/src/types/index.d.ts +807 -0
- package/types/src/types/index.d.ts.map +1 -0
- package/types/src/utils/fetch.d.ts +161 -0
- package/types/src/utils/fetch.d.ts.map +1 -0
- package/types/src/utils/index.d.ts +8 -0
- package/types/src/utils/index.d.ts.map +1 -0
- package/types/src/utils/streaming.d.ts +210 -0
- package/types/src/utils/streaming.d.ts.map +1 -0
- package/types/src/version.d.ts +21 -0
- package/types/src/version.d.ts.map +1 -0
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Attrove Client
|
|
4
|
+
*
|
|
5
|
+
* Main entry point for the Attrove SDK. Provides a simple, intuitive API
|
|
6
|
+
* for accessing user context through connected integrations.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.Attrove = void 0;
|
|
10
|
+
const fetch_1 = require("./utils/fetch");
|
|
11
|
+
const streaming_1 = require("./utils/streaming");
|
|
12
|
+
const users_1 = require("./resources/users");
|
|
13
|
+
const messages_1 = require("./resources/messages");
|
|
14
|
+
const conversations_1 = require("./resources/conversations");
|
|
15
|
+
const integrations_1 = require("./resources/integrations");
|
|
16
|
+
const query_1 = require("./resources/query");
|
|
17
|
+
const errors_1 = require("./errors");
|
|
18
|
+
const types_1 = require("./types");
|
|
19
|
+
const types_2 = require("./types");
|
|
20
|
+
const constants_1 = require("./constants");
|
|
21
|
+
/**
|
|
22
|
+
* Validate the Attrove client configuration.
|
|
23
|
+
*
|
|
24
|
+
* @throws {ValidationError} If the configuration is invalid
|
|
25
|
+
*/
|
|
26
|
+
function validateConfig(config) {
|
|
27
|
+
// Validate apiKey
|
|
28
|
+
if (!config.apiKey || typeof config.apiKey !== 'string') {
|
|
29
|
+
throw new errors_1.ValidationError('apiKey is required and must be a non-empty string', types_1.ErrorCodes.VALIDATION_REQUIRED_FIELD, { field: 'apiKey' });
|
|
30
|
+
}
|
|
31
|
+
if (!config.apiKey.startsWith('sk_')) {
|
|
32
|
+
throw new errors_1.ValidationError('apiKey must start with "sk_" prefix. Make sure you are using a valid API key.', types_1.ErrorCodes.VALIDATION_INVALID_FORMAT, { field: 'apiKey', expected: 'sk_...' });
|
|
33
|
+
}
|
|
34
|
+
// Validate userId
|
|
35
|
+
if (!config.userId || typeof config.userId !== 'string') {
|
|
36
|
+
throw new errors_1.ValidationError('userId is required and must be a non-empty string', types_1.ErrorCodes.VALIDATION_REQUIRED_FIELD, { field: 'userId' });
|
|
37
|
+
}
|
|
38
|
+
if (!(0, types_2.isValidUUID)(config.userId)) {
|
|
39
|
+
throw new errors_1.ValidationError('userId must be a valid UUID format (e.g., "123e4567-e89b-12d3-a456-426614174000")', types_1.ErrorCodes.VALIDATION_INVALID_FORMAT, { field: 'userId', expected: 'UUID format' });
|
|
40
|
+
}
|
|
41
|
+
// Validate optional fields
|
|
42
|
+
if (config.timeout !== undefined && (typeof config.timeout !== 'number' || config.timeout <= 0)) {
|
|
43
|
+
throw new errors_1.ValidationError('timeout must be a positive number in milliseconds', types_1.ErrorCodes.VALIDATION_OUT_OF_RANGE, { field: 'timeout', value: config.timeout });
|
|
44
|
+
}
|
|
45
|
+
if (config.maxRetries !== undefined && (typeof config.maxRetries !== 'number' || config.maxRetries < 0)) {
|
|
46
|
+
throw new errors_1.ValidationError('maxRetries must be a non-negative number', types_1.ErrorCodes.VALIDATION_OUT_OF_RANGE, { field: 'maxRetries', value: config.maxRetries });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The Attrove client for accessing user context.
|
|
51
|
+
*
|
|
52
|
+
* This is the main entry point for the Attrove SDK. It provides methods for:
|
|
53
|
+
* - Querying user context with AI (query, search)
|
|
54
|
+
* - Streaming query responses in real-time
|
|
55
|
+
* - Accessing user data, messages, conversations, and integrations
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { Attrove } from '@attrove/sdk';
|
|
60
|
+
*
|
|
61
|
+
* const attrove = new Attrove({
|
|
62
|
+
* apiKey: 'sk_...',
|
|
63
|
+
* userId: 'user-uuid'
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* // Query user's context
|
|
67
|
+
* const response = await attrove.query('What meetings do I have tomorrow?');
|
|
68
|
+
* console.log(response.answer);
|
|
69
|
+
*
|
|
70
|
+
* // Search for specific information
|
|
71
|
+
* const results = await attrove.search('quarterly report');
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
class Attrove {
|
|
75
|
+
/**
|
|
76
|
+
* Create a new Attrove client.
|
|
77
|
+
*
|
|
78
|
+
* @param config - Client configuration
|
|
79
|
+
* @throws {ValidationError} If the configuration is invalid (missing apiKey, invalid userId format, etc.)
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* const attrove = new Attrove({
|
|
84
|
+
* apiKey: 'sk_...',
|
|
85
|
+
* userId: 'user-uuid',
|
|
86
|
+
* timeout: 60000, // 60 seconds
|
|
87
|
+
* onRetry: (info) => console.log(`Retrying (${info.attempt}/${info.maxRetries})...`)
|
|
88
|
+
* });
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
constructor(config) {
|
|
92
|
+
// Validate configuration before proceeding
|
|
93
|
+
validateConfig(config);
|
|
94
|
+
this.config = {
|
|
95
|
+
apiKey: config.apiKey,
|
|
96
|
+
userId: config.userId,
|
|
97
|
+
baseUrl: config.baseUrl ?? constants_1.DEFAULT_BASE_URL,
|
|
98
|
+
timeout: config.timeout ?? constants_1.DEFAULT_TIMEOUT,
|
|
99
|
+
maxRetries: config.maxRetries ?? constants_1.DEFAULT_MAX_RETRIES,
|
|
100
|
+
onRetry: config.onRetry,
|
|
101
|
+
};
|
|
102
|
+
this.http = new fetch_1.HttpClient({
|
|
103
|
+
baseUrl: this.config.baseUrl,
|
|
104
|
+
apiKey: this.config.apiKey,
|
|
105
|
+
userId: this.config.userId,
|
|
106
|
+
timeout: this.config.timeout,
|
|
107
|
+
maxRetries: this.config.maxRetries,
|
|
108
|
+
onRetry: this.config.onRetry,
|
|
109
|
+
});
|
|
110
|
+
// Initialize resources
|
|
111
|
+
this.users = new users_1.UsersResource(this.http, this.config.userId);
|
|
112
|
+
this.messages = new messages_1.MessagesResource(this.http, this.config.userId);
|
|
113
|
+
this.conversations = new conversations_1.ConversationsResource(this.http, this.config.userId);
|
|
114
|
+
this.integrations = new integrations_1.IntegrationsResource(this.http, this.config.userId);
|
|
115
|
+
this.queryResource = new query_1.QueryResource(this.http, this.config.userId);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Query the user's unified context with AI.
|
|
119
|
+
*
|
|
120
|
+
* This is the primary method for asking questions about the user's data.
|
|
121
|
+
* It performs semantic search across all connected integrations and returns
|
|
122
|
+
* an AI-generated answer based on the relevant context.
|
|
123
|
+
*
|
|
124
|
+
* @param prompt - The natural language question to answer
|
|
125
|
+
* @param options - Query options including history, filters, etc.
|
|
126
|
+
* @returns AI-generated answer with source references
|
|
127
|
+
*
|
|
128
|
+
* @throws {AuthenticationError} If the API key is invalid or expired
|
|
129
|
+
* @throws {ValidationError} If the request parameters are invalid
|
|
130
|
+
* @throws {RateLimitError} If rate limits are exceeded
|
|
131
|
+
* @throws {NetworkError} If unable to reach the API
|
|
132
|
+
* @throws {ServerError} If the server encounters an error
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* // Simple query
|
|
137
|
+
* const response = await attrove.query('What did Sarah say about the Q4 budget?');
|
|
138
|
+
* console.log(response.answer);
|
|
139
|
+
*
|
|
140
|
+
* // Multi-turn conversation
|
|
141
|
+
* let history: ConversationMessage[] = [];
|
|
142
|
+
*
|
|
143
|
+
* const first = await attrove.query('What meetings do I have tomorrow?');
|
|
144
|
+
* history = first.history;
|
|
145
|
+
*
|
|
146
|
+
* const followUp = await attrove.query('Who is attending?', { history });
|
|
147
|
+
* console.log(followUp.answer);
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
async query(prompt, options) {
|
|
151
|
+
return this.queryResource.query(prompt, options);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Semantic search across the user's context.
|
|
155
|
+
*
|
|
156
|
+
* Returns raw matching messages grouped by conversation, without AI summarization.
|
|
157
|
+
* Use this when you need full control over how results are displayed.
|
|
158
|
+
*
|
|
159
|
+
* @param query - The search query (semantic, not keyword-based)
|
|
160
|
+
* @param options - Search options including filters, date range, etc.
|
|
161
|
+
* @returns Matching messages grouped by conversation
|
|
162
|
+
*
|
|
163
|
+
* @throws {AuthenticationError} If the API key is invalid or expired
|
|
164
|
+
* @throws {ValidationError} If the request parameters are invalid
|
|
165
|
+
* @throws {RateLimitError} If rate limits are exceeded
|
|
166
|
+
* @throws {NetworkError} If unable to reach the API
|
|
167
|
+
* @throws {ServerError} If the server encounters an error
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* const results = await attrove.search('quarterly report', {
|
|
172
|
+
* afterDate: '2024-01-01T00:00:00Z',
|
|
173
|
+
* includeBodyText: true
|
|
174
|
+
* });
|
|
175
|
+
*
|
|
176
|
+
* for (const [convId, conv] of Object.entries(results.conversations)) {
|
|
177
|
+
* console.log(`Conversation: ${conv.conversation_name}`);
|
|
178
|
+
* for (const [threadId, messages] of Object.entries(conv.threads)) {
|
|
179
|
+
* console.log(` Thread ${threadId}: ${messages.length} messages`);
|
|
180
|
+
* }
|
|
181
|
+
* }
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
async search(query, options) {
|
|
185
|
+
return this.queryResource.search(query, options);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Stream a query response in real-time.
|
|
189
|
+
*
|
|
190
|
+
* Connects to the WebSocket endpoint and streams the AI-generated answer
|
|
191
|
+
* as it's being generated. Useful for displaying results progressively.
|
|
192
|
+
*
|
|
193
|
+
* @param prompt - The natural language question to answer
|
|
194
|
+
* @param options - Query and streaming options
|
|
195
|
+
* @returns Stream result with full answer and metadata
|
|
196
|
+
*
|
|
197
|
+
* @throws {AuthenticationError} If the API key is invalid or expired
|
|
198
|
+
* @throws {NetworkError} If WebSocket connection fails
|
|
199
|
+
* @throws {TimeoutError} If connection times out
|
|
200
|
+
* @throws {AttroveError} If the server returns an error
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```ts
|
|
204
|
+
* const result = await attrove.stream('What happened in the meeting?', {
|
|
205
|
+
* onChunk: (chunk) => process.stdout.write(chunk),
|
|
206
|
+
* onState: (state) => console.log('State:', state),
|
|
207
|
+
* });
|
|
208
|
+
*
|
|
209
|
+
* console.log('\\nFull answer:', result.answer);
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
async stream(prompt, options = {}) {
|
|
213
|
+
const { history = [], timezone, integrationIds, conversationIds, allowBotMessages, includeSources, ...streamOptions } = options;
|
|
214
|
+
// Add the user's prompt to history
|
|
215
|
+
const fullHistory = [
|
|
216
|
+
...history,
|
|
217
|
+
{ role: 'user', content: prompt },
|
|
218
|
+
];
|
|
219
|
+
// Extract query options (separate from stream options)
|
|
220
|
+
const queryOptions = {
|
|
221
|
+
timezone,
|
|
222
|
+
integrationIds,
|
|
223
|
+
conversationIds,
|
|
224
|
+
allowBotMessages,
|
|
225
|
+
includeSources,
|
|
226
|
+
};
|
|
227
|
+
const streaming = new streaming_1.StreamingClient(this.config.baseUrl, this.config.apiKey);
|
|
228
|
+
try {
|
|
229
|
+
const messageId = (0, streaming_1.generateMessageId)();
|
|
230
|
+
return await streaming.stream(prompt, messageId, fullHistory, queryOptions, streamOptions);
|
|
231
|
+
}
|
|
232
|
+
finally {
|
|
233
|
+
streaming.close();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Get meeting preparation brief.
|
|
238
|
+
*
|
|
239
|
+
* Retrieves context about attendees, recent conversations, and relevant
|
|
240
|
+
* information to help prepare for an upcoming meeting.
|
|
241
|
+
*
|
|
242
|
+
* @experimental This method is not yet implemented and will throw an error.
|
|
243
|
+
*
|
|
244
|
+
* @param meetingId - Meeting ID (UUID format)
|
|
245
|
+
* @returns Meeting brief with attendee info and relevant context
|
|
246
|
+
*
|
|
247
|
+
* @throws {Error} Always throws - not yet implemented
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```ts
|
|
251
|
+
* // Not yet available
|
|
252
|
+
* const brief = await attrove.brief('meeting-uuid-here');
|
|
253
|
+
* console.log(brief.summary);
|
|
254
|
+
* console.log('Attendees:', brief.attendees);
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
async brief(meetingId) {
|
|
258
|
+
// TODO: Implement meeting brief endpoint
|
|
259
|
+
throw new Error('Meeting brief not yet implemented. This feature is coming soon.');
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Get information about an entity (person, company, etc.).
|
|
263
|
+
*
|
|
264
|
+
* Retrieves profile information and interaction history for an entity
|
|
265
|
+
* identified from the user's communications.
|
|
266
|
+
*
|
|
267
|
+
* @experimental This method is not yet implemented and will throw an error.
|
|
268
|
+
*
|
|
269
|
+
* @param entityId - Entity ID (UUID format)
|
|
270
|
+
* @returns Entity profile with interaction history
|
|
271
|
+
*
|
|
272
|
+
* @throws {Error} Always throws - not yet implemented
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```ts
|
|
276
|
+
* // Not yet available
|
|
277
|
+
* const entity = await attrove.entity('entity-uuid');
|
|
278
|
+
* console.log(`${entity.name}: ${entity.message_count} messages`);
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
async entity(entityId) {
|
|
282
|
+
// TODO: Implement entity endpoint
|
|
283
|
+
throw new Error('Entity lookup not yet implemented. This feature is coming soon.');
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Get a conversation thread.
|
|
287
|
+
*
|
|
288
|
+
* Retrieves all messages in a specific conversation thread.
|
|
289
|
+
*
|
|
290
|
+
* @experimental This method is not yet implemented and will throw an error.
|
|
291
|
+
*
|
|
292
|
+
* @param conversationId - Conversation ID (UUID format)
|
|
293
|
+
* @returns Conversation thread with messages
|
|
294
|
+
*
|
|
295
|
+
* @throws {Error} Always throws - not yet implemented
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* ```ts
|
|
299
|
+
* // Not yet available
|
|
300
|
+
* const thread = await attrove.thread('conversation-uuid-here');
|
|
301
|
+
* for (const msg of thread.messages) {
|
|
302
|
+
* console.log(`${msg.sender_name}: ${msg.body_text}`);
|
|
303
|
+
* }
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
async thread(conversationId) {
|
|
307
|
+
// TODO: Implement thread endpoint
|
|
308
|
+
throw new Error('Thread retrieval not yet implemented. This feature is coming soon.');
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
exports.Attrove = Attrove;
|
|
312
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../../packages/sdk/src/client.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,yCAA2C;AAC3C,iDAAoG;AACpG,6CAAkD;AAClD,mDAAwD;AACxD,6DAAkE;AAClE,2DAAgE;AAChE,6CAAkD;AAClD,qCAA2C;AAC3C,mCAAqC;AACrC,mCAQiB;AACjB,2CAAqF;AAErF;;;;GAIG;AACH,SAAS,cAAc,CAAC,MAAqB;IAC3C,kBAAkB;IAClB,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QACxD,MAAM,IAA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;YACf,gBAAgB;YAChB,cAAc;SACf,CAAC;QAEF,MAAM,SAAS,GAAG,IAAI,2BAAe,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAE/E,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,IAAA,6BAAiB,GAAE,CAAC;YACtC,OAAO,MAAM,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC;QAC7F,CAAC;gBAAS,CAAC;YACT,SAAS,CAAC,KAAK,EAAE,CAAC;QACpB,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,KAAK,CAAC,KAAK,CAAC,SAAiB;QAC3B,yCAAyC;QACzC,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;IACrF,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,KAAK,CAAC,MAAM,CAAC,QAAgB;QAC3B,kCAAkC;QAClC,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;IACrF,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,KAAK,CAAC,MAAM,CAAC,cAAsB;QACjC,kCAAkC;QAClC,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;IACxF,CAAC;CACF;AA3RD,0BA2RC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SDK Constants
|
|
4
|
+
*
|
|
5
|
+
* Centralized constants used across the SDK. Consolidating these ensures
|
|
6
|
+
* consistency and makes maintenance easier.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.getWsCloseReason = exports.WS_CLOSE_CODES = exports.RETRYABLE_STATUS_SET = exports.RETRY_STATUS_CODES = exports.INITIAL_RETRY_DELAY = exports.DEFAULT_MAX_RETRIES = exports.DEFAULT_TIMEOUT = exports.DEFAULT_BASE_URL = exports.SDK_VERSION = void 0;
|
|
10
|
+
/**
|
|
11
|
+
* SDK version string.
|
|
12
|
+
*
|
|
13
|
+
* This version is updated by the release process. Keep it in sync with
|
|
14
|
+
* the version in package.json. For programmatic access, use `getVersion()`
|
|
15
|
+
* from './version'.
|
|
16
|
+
*/
|
|
17
|
+
exports.SDK_VERSION = '0.1.3';
|
|
18
|
+
/**
|
|
19
|
+
* Default API base URL for Attrove services.
|
|
20
|
+
*/
|
|
21
|
+
exports.DEFAULT_BASE_URL = 'https://api.attrove.com';
|
|
22
|
+
/**
|
|
23
|
+
* Default request timeout in milliseconds.
|
|
24
|
+
*/
|
|
25
|
+
exports.DEFAULT_TIMEOUT = 30000;
|
|
26
|
+
/**
|
|
27
|
+
* Default number of retry attempts for failed requests.
|
|
28
|
+
*/
|
|
29
|
+
exports.DEFAULT_MAX_RETRIES = 3;
|
|
30
|
+
/**
|
|
31
|
+
* Initial delay for retry backoff in milliseconds.
|
|
32
|
+
*/
|
|
33
|
+
exports.INITIAL_RETRY_DELAY = 1000;
|
|
34
|
+
/**
|
|
35
|
+
* HTTP status codes that trigger automatic retries.
|
|
36
|
+
*/
|
|
37
|
+
exports.RETRY_STATUS_CODES = [408, 429, 500, 502, 503, 504];
|
|
38
|
+
/**
|
|
39
|
+
* Set of retryable status codes for O(1) lookup.
|
|
40
|
+
*/
|
|
41
|
+
exports.RETRYABLE_STATUS_SET = new Set(exports.RETRY_STATUS_CODES);
|
|
42
|
+
/**
|
|
43
|
+
* WebSocket close code descriptions for better error messages.
|
|
44
|
+
*/
|
|
45
|
+
exports.WS_CLOSE_CODES = {
|
|
46
|
+
1000: 'Normal closure',
|
|
47
|
+
1001: 'Server going away',
|
|
48
|
+
1002: 'Protocol error',
|
|
49
|
+
1003: 'Unsupported data type',
|
|
50
|
+
1005: 'No status code received',
|
|
51
|
+
1006: 'Connection lost abnormally (no close frame)',
|
|
52
|
+
1007: 'Invalid frame payload data',
|
|
53
|
+
1008: 'Policy violation',
|
|
54
|
+
1009: 'Message too large',
|
|
55
|
+
1010: 'Missing expected extension',
|
|
56
|
+
1011: 'Internal server error',
|
|
57
|
+
1012: 'Service restart',
|
|
58
|
+
1013: 'Try again later',
|
|
59
|
+
1014: 'Bad gateway',
|
|
60
|
+
1015: 'TLS handshake failure',
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Get a human-readable description for a WebSocket close code.
|
|
64
|
+
*/
|
|
65
|
+
function getWsCloseReason(code) {
|
|
66
|
+
return exports.WS_CLOSE_CODES[code] || 'Unknown close reason';
|
|
67
|
+
}
|
|
68
|
+
exports.getWsCloseReason = getWsCloseReason;
|
|
69
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../packages/sdk/src/constants.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH;;;;;;GAMG;AACU,QAAA,WAAW,GAAG,OAAO,CAAC;AAEnC;;GAEG;AACU,QAAA,gBAAgB,GAAG,yBAAyB,CAAC;AAE1D;;GAEG;AACU,QAAA,eAAe,GAAG,KAAK,CAAC;AAErC;;GAEG;AACU,QAAA,mBAAmB,GAAG,CAAC,CAAC;AAErC;;GAEG;AACU,QAAA,mBAAmB,GAAG,IAAI,CAAC;AAExC;;GAEG;AACU,QAAA,kBAAkB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAU,CAAC;AAE1E;;GAEG;AACU,QAAA,oBAAoB,GAAwB,IAAI,GAAG,CAAC,0BAAkB,CAAC,CAAC;AAErF;;GAEG;AACU,QAAA,cAAc,GAA2B;IACpD,IAAI,EAAE,gBAAgB;IACtB,IAAI,EAAE,mBAAmB;IACzB,IAAI,EAAE,gBAAgB;IACtB,IAAI,EAAE,uBAAuB;IAC7B,IAAI,EAAE,yBAAyB;IAC/B,IAAI,EAAE,6CAA6C;IACnD,IAAI,EAAE,4BAA4B;IAClC,IAAI,EAAE,kBAAkB;IACxB,IAAI,EAAE,mBAAmB;IACzB,IAAI,EAAE,4BAA4B;IAClC,IAAI,EAAE,uBAAuB;IAC7B,IAAI,EAAE,iBAAiB;IACvB,IAAI,EAAE,iBAAiB;IACvB,IAAI,EAAE,aAAa;IACnB,IAAI,EAAE,uBAAuB;CAC9B,CAAC;AAEF;;GAEG;AACH,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,OAAO,sBAAc,CAAC,IAAI,CAAC,IAAI,sBAAsB,CAAC;AACxD,CAAC;AAFD,4CAEC"}
|