@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,307 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Attrove SDK Error Classes
|
|
4
|
+
*
|
|
5
|
+
* Provides a structured error hierarchy for handling API errors.
|
|
6
|
+
* Each error type maps to specific HTTP status codes and error codes.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.isServerError = exports.isTimeoutError = exports.isNetworkError = exports.isRateLimitError = exports.isValidationError = exports.isNotFoundError = exports.isAuthorizationError = exports.isAuthenticationError = exports.isAttroveError = exports.createErrorFromStatus = exports.ServerError = exports.TimeoutError = exports.NetworkError = exports.RateLimitError = exports.ValidationError = exports.NotFoundError = exports.AuthorizationError = exports.AuthenticationError = exports.AttroveError = void 0;
|
|
10
|
+
const types_1 = require("../types");
|
|
11
|
+
/**
|
|
12
|
+
* Base error class for all Attrove SDK errors.
|
|
13
|
+
*
|
|
14
|
+
* All SDK errors extend this class, enabling consistent error handling
|
|
15
|
+
* across the SDK. Use the type guards (isAttroveError, isAuthenticationError, etc.)
|
|
16
|
+
* for type-safe error handling.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* try {
|
|
21
|
+
* await attrove.query('...');
|
|
22
|
+
* } catch (error) {
|
|
23
|
+
* if (isAttroveError(error)) {
|
|
24
|
+
* console.log(`Error ${error.code}: ${error.message}`);
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
class AttroveError extends Error {
|
|
30
|
+
constructor(message, code, status, details) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.name = 'AttroveError';
|
|
33
|
+
this.code = code;
|
|
34
|
+
this.status = status;
|
|
35
|
+
this.details = details;
|
|
36
|
+
// Maintains proper stack trace for where our error was thrown (only available on V8)
|
|
37
|
+
const ErrorWithCapture = Error;
|
|
38
|
+
if (ErrorWithCapture.captureStackTrace) {
|
|
39
|
+
ErrorWithCapture.captureStackTrace(this, AttroveError);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Creates an AttroveError from an API error response.
|
|
44
|
+
*
|
|
45
|
+
* @param error - The error from the API (ApiError object or string)
|
|
46
|
+
* @param status - Optional HTTP status code
|
|
47
|
+
* @returns An AttroveError instance
|
|
48
|
+
*/
|
|
49
|
+
static fromApiError(error, status) {
|
|
50
|
+
if (typeof error === 'string') {
|
|
51
|
+
return new AttroveError(error, types_1.ErrorCodes.INTERNAL_ERROR, status);
|
|
52
|
+
}
|
|
53
|
+
return new AttroveError(error.message, error.code, status, error.details);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Returns a formatted string representation of the error.
|
|
57
|
+
*/
|
|
58
|
+
toString() {
|
|
59
|
+
const parts = [`${this.name}: ${this.message}`];
|
|
60
|
+
if (this.code)
|
|
61
|
+
parts.push(`Code: ${this.code}`);
|
|
62
|
+
if (this.status)
|
|
63
|
+
parts.push(`Status: ${this.status}`);
|
|
64
|
+
return parts.join(' | ');
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Returns a JSON-serializable representation of the error.
|
|
68
|
+
*/
|
|
69
|
+
toJSON() {
|
|
70
|
+
return {
|
|
71
|
+
name: this.name,
|
|
72
|
+
message: this.message,
|
|
73
|
+
code: this.code,
|
|
74
|
+
status: this.status,
|
|
75
|
+
details: this.details,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.AttroveError = AttroveError;
|
|
80
|
+
/**
|
|
81
|
+
* Error thrown when authentication fails (401).
|
|
82
|
+
*
|
|
83
|
+
* Common causes:
|
|
84
|
+
* - Invalid API key
|
|
85
|
+
* - Expired token
|
|
86
|
+
* - Missing authentication header
|
|
87
|
+
*
|
|
88
|
+
* @throws {AuthenticationError}
|
|
89
|
+
*/
|
|
90
|
+
class AuthenticationError extends AttroveError {
|
|
91
|
+
constructor(message, code = types_1.ErrorCodes.AUTH_INVALID_TOKEN, details) {
|
|
92
|
+
super(message, code, 401, details);
|
|
93
|
+
this.name = 'AuthenticationError';
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.AuthenticationError = AuthenticationError;
|
|
97
|
+
/**
|
|
98
|
+
* Error thrown when the user lacks permission for an action (403).
|
|
99
|
+
*
|
|
100
|
+
* Common causes:
|
|
101
|
+
* - Accessing another user's data
|
|
102
|
+
* - Insufficient permissions for the operation
|
|
103
|
+
* - Resource access denied
|
|
104
|
+
*/
|
|
105
|
+
class AuthorizationError extends AttroveError {
|
|
106
|
+
constructor(message, code = types_1.ErrorCodes.AUTH_INSUFFICIENT_PERMISSIONS, details) {
|
|
107
|
+
super(message, code, 403, details);
|
|
108
|
+
this.name = 'AuthorizationError';
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.AuthorizationError = AuthorizationError;
|
|
112
|
+
/**
|
|
113
|
+
* Error thrown when a resource is not found (404).
|
|
114
|
+
*
|
|
115
|
+
* Common causes:
|
|
116
|
+
* - Invalid resource ID
|
|
117
|
+
* - Resource was deleted
|
|
118
|
+
* - User doesn't have access to the resource
|
|
119
|
+
*/
|
|
120
|
+
class NotFoundError extends AttroveError {
|
|
121
|
+
constructor(message, details) {
|
|
122
|
+
super(message, types_1.ErrorCodes.RESOURCE_NOT_FOUND, 404, details);
|
|
123
|
+
this.name = 'NotFoundError';
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.NotFoundError = NotFoundError;
|
|
127
|
+
/**
|
|
128
|
+
* Error thrown when request validation fails (400).
|
|
129
|
+
*
|
|
130
|
+
* Common causes:
|
|
131
|
+
* - Invalid request parameters
|
|
132
|
+
* - Missing required fields
|
|
133
|
+
* - Invalid data format
|
|
134
|
+
*/
|
|
135
|
+
class ValidationError extends AttroveError {
|
|
136
|
+
constructor(message, code = types_1.ErrorCodes.VALIDATION_INVALID_FORMAT, details) {
|
|
137
|
+
super(message, code, 400, details);
|
|
138
|
+
this.name = 'ValidationError';
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.ValidationError = ValidationError;
|
|
142
|
+
/**
|
|
143
|
+
* Error thrown when rate limits are exceeded (429).
|
|
144
|
+
*
|
|
145
|
+
* When this error is thrown, you should wait before retrying.
|
|
146
|
+
* Check the `retryAfter` property for the recommended wait time.
|
|
147
|
+
*/
|
|
148
|
+
class RateLimitError extends AttroveError {
|
|
149
|
+
constructor(message, retryAfter, details) {
|
|
150
|
+
super(message, types_1.ErrorCodes.RATE_LIMIT_EXCEEDED, 429, details);
|
|
151
|
+
this.name = 'RateLimitError';
|
|
152
|
+
this.retryAfter = retryAfter;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.RateLimitError = RateLimitError;
|
|
156
|
+
/**
|
|
157
|
+
* Error thrown when there's a network or connectivity issue.
|
|
158
|
+
*
|
|
159
|
+
* Common causes:
|
|
160
|
+
* - No internet connection
|
|
161
|
+
* - DNS resolution failure
|
|
162
|
+
* - Connection refused
|
|
163
|
+
* - SSL/TLS errors
|
|
164
|
+
*/
|
|
165
|
+
class NetworkError extends AttroveError {
|
|
166
|
+
constructor(message, details) {
|
|
167
|
+
super(message, types_1.ErrorCodes.SERVICE_UNAVAILABLE, undefined, details);
|
|
168
|
+
this.name = 'NetworkError';
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.NetworkError = NetworkError;
|
|
172
|
+
/**
|
|
173
|
+
* Error thrown when a request times out (408).
|
|
174
|
+
*
|
|
175
|
+
* The request took longer than the configured timeout.
|
|
176
|
+
* Consider increasing the timeout or retrying the request.
|
|
177
|
+
*/
|
|
178
|
+
class TimeoutError extends AttroveError {
|
|
179
|
+
constructor(message = 'Request timed out', details) {
|
|
180
|
+
super(message, types_1.ErrorCodes.SERVICE_UNAVAILABLE, 408, details);
|
|
181
|
+
this.name = 'TimeoutError';
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.TimeoutError = TimeoutError;
|
|
185
|
+
/**
|
|
186
|
+
* Error thrown when there's a server-side issue (5xx).
|
|
187
|
+
*
|
|
188
|
+
* These errors are typically transient and may be resolved by retrying.
|
|
189
|
+
* The SDK automatically retries on 408, 429, 500, 502, 503, and 504 errors.
|
|
190
|
+
* See RETRY_STATUS_CODES in constants.ts for the authoritative list.
|
|
191
|
+
*/
|
|
192
|
+
class ServerError extends AttroveError {
|
|
193
|
+
constructor(message, status = 500, details) {
|
|
194
|
+
super(message, types_1.ErrorCodes.INTERNAL_ERROR, status, details);
|
|
195
|
+
this.name = 'ServerError';
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
exports.ServerError = ServerError;
|
|
199
|
+
/**
|
|
200
|
+
* Maps HTTP status codes to appropriate error classes.
|
|
201
|
+
*
|
|
202
|
+
* @param message - Error message
|
|
203
|
+
* @param status - HTTP status code
|
|
204
|
+
* @param code - Optional error code from the API
|
|
205
|
+
* @param details - Optional error details
|
|
206
|
+
* @returns An appropriate error instance for the status code
|
|
207
|
+
*/
|
|
208
|
+
function createErrorFromStatus(message, status, code, details) {
|
|
209
|
+
switch (status) {
|
|
210
|
+
case 400:
|
|
211
|
+
return new ValidationError(message, code || types_1.ErrorCodes.VALIDATION_INVALID_FORMAT, details);
|
|
212
|
+
case 401:
|
|
213
|
+
return new AuthenticationError(message, code || types_1.ErrorCodes.AUTH_INVALID_TOKEN, details);
|
|
214
|
+
case 403:
|
|
215
|
+
return new AuthorizationError(message, code || types_1.ErrorCodes.AUTH_INSUFFICIENT_PERMISSIONS, details);
|
|
216
|
+
case 404:
|
|
217
|
+
return new NotFoundError(message, details);
|
|
218
|
+
case 408:
|
|
219
|
+
return new TimeoutError(message, details);
|
|
220
|
+
case 429:
|
|
221
|
+
return new RateLimitError(message, undefined, details);
|
|
222
|
+
default:
|
|
223
|
+
if (status >= 500) {
|
|
224
|
+
return new ServerError(message, status, details);
|
|
225
|
+
}
|
|
226
|
+
return new AttroveError(message, code || types_1.ErrorCodes.INTERNAL_ERROR, status, details);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
exports.createErrorFromStatus = createErrorFromStatus;
|
|
230
|
+
// =============================================================================
|
|
231
|
+
// Type Guards
|
|
232
|
+
// =============================================================================
|
|
233
|
+
/**
|
|
234
|
+
* Type guard to check if an error is an AttroveError.
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* try {
|
|
239
|
+
* await attrove.query('...');
|
|
240
|
+
* } catch (error) {
|
|
241
|
+
* if (isAttroveError(error)) {
|
|
242
|
+
* console.log(`Error code: ${error.code}`);
|
|
243
|
+
* }
|
|
244
|
+
* }
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
function isAttroveError(error) {
|
|
248
|
+
return error instanceof AttroveError;
|
|
249
|
+
}
|
|
250
|
+
exports.isAttroveError = isAttroveError;
|
|
251
|
+
/**
|
|
252
|
+
* Type guard to check if an error is an AuthenticationError.
|
|
253
|
+
*/
|
|
254
|
+
function isAuthenticationError(error) {
|
|
255
|
+
return error instanceof AuthenticationError;
|
|
256
|
+
}
|
|
257
|
+
exports.isAuthenticationError = isAuthenticationError;
|
|
258
|
+
/**
|
|
259
|
+
* Type guard to check if an error is an AuthorizationError.
|
|
260
|
+
*/
|
|
261
|
+
function isAuthorizationError(error) {
|
|
262
|
+
return error instanceof AuthorizationError;
|
|
263
|
+
}
|
|
264
|
+
exports.isAuthorizationError = isAuthorizationError;
|
|
265
|
+
/**
|
|
266
|
+
* Type guard to check if an error is a NotFoundError.
|
|
267
|
+
*/
|
|
268
|
+
function isNotFoundError(error) {
|
|
269
|
+
return error instanceof NotFoundError;
|
|
270
|
+
}
|
|
271
|
+
exports.isNotFoundError = isNotFoundError;
|
|
272
|
+
/**
|
|
273
|
+
* Type guard to check if an error is a ValidationError.
|
|
274
|
+
*/
|
|
275
|
+
function isValidationError(error) {
|
|
276
|
+
return error instanceof ValidationError;
|
|
277
|
+
}
|
|
278
|
+
exports.isValidationError = isValidationError;
|
|
279
|
+
/**
|
|
280
|
+
* Type guard to check if an error is a RateLimitError.
|
|
281
|
+
*/
|
|
282
|
+
function isRateLimitError(error) {
|
|
283
|
+
return error instanceof RateLimitError;
|
|
284
|
+
}
|
|
285
|
+
exports.isRateLimitError = isRateLimitError;
|
|
286
|
+
/**
|
|
287
|
+
* Type guard to check if an error is a NetworkError.
|
|
288
|
+
*/
|
|
289
|
+
function isNetworkError(error) {
|
|
290
|
+
return error instanceof NetworkError;
|
|
291
|
+
}
|
|
292
|
+
exports.isNetworkError = isNetworkError;
|
|
293
|
+
/**
|
|
294
|
+
* Type guard to check if an error is a TimeoutError.
|
|
295
|
+
*/
|
|
296
|
+
function isTimeoutError(error) {
|
|
297
|
+
return error instanceof TimeoutError;
|
|
298
|
+
}
|
|
299
|
+
exports.isTimeoutError = isTimeoutError;
|
|
300
|
+
/**
|
|
301
|
+
* Type guard to check if an error is a ServerError.
|
|
302
|
+
*/
|
|
303
|
+
function isServerError(error) {
|
|
304
|
+
return error instanceof ServerError;
|
|
305
|
+
}
|
|
306
|
+
exports.isServerError = isServerError;
|
|
307
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../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SAAgB,oBAAoB,CAAC,KAAc;IACjD,OAAO,KAAK,YAAY,kBAAkB,CAAC;AAC7C,CAAC;AAFD,oDAEC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,KAAc;IAC5C,OAAO,KAAK,YAAY,aAAa,CAAC;AACxC,CAAC;AAFD,0CAEC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAAC,KAAc;IAC9C,OAAO,KAAK,YAAY,eAAe,CAAC;AAC1C,CAAC;AAFD,8CAEC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,KAAc;IAC7C,OAAO,KAAK,YAAY,cAAc,CAAC;AACzC,CAAC;AAFD,4CAEC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,KAAc;IAC3C,OAAO,KAAK,YAAY,YAAY,CAAC;AACvC,CAAC;AAFD,wCAEC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,KAAc;IAC3C,OAAO,KAAK,YAAY,YAAY,CAAC;AACvC,CAAC;AAFD,wCAEC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC1C,OAAO,KAAK,YAAY,WAAW,CAAC;AACtC,CAAC;AAFD,sCAEC"}
|
package/cjs/src/index.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @attrove/sdk
|
|
4
|
+
*
|
|
5
|
+
* Official TypeScript SDK for the Attrove API.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { Attrove } from '@attrove/sdk';
|
|
10
|
+
*
|
|
11
|
+
* // Create a client for end-user operations
|
|
12
|
+
* const attrove = new Attrove({
|
|
13
|
+
* apiKey: 'sk_...',
|
|
14
|
+
* userId: 'user-uuid'
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // Query user's context
|
|
18
|
+
* const response = await attrove.query('What meetings do I have tomorrow?');
|
|
19
|
+
* console.log(response.answer);
|
|
20
|
+
*
|
|
21
|
+
* // Create an admin client for server-to-server operations
|
|
22
|
+
* const admin = Attrove.admin({
|
|
23
|
+
* clientId: 'your-client-id',
|
|
24
|
+
* clientSecret: 'your-client-secret'
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // Create a user
|
|
28
|
+
* const { id, apiKey } = await admin.users.create({
|
|
29
|
+
* email: 'user@example.com'
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @packageDocumentation
|
|
34
|
+
*/
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getVersion = exports.DEFAULT_MAX_RETRIES = exports.DEFAULT_TIMEOUT = exports.DEFAULT_BASE_URL = exports.SDK_VERSION = exports.generateMessageId = exports.isServerError = exports.isTimeoutError = exports.isNetworkError = exports.isRateLimitError = exports.isValidationError = exports.isNotFoundError = exports.isAuthorizationError = exports.isAuthenticationError = exports.isAttroveError = exports.ServerError = exports.TimeoutError = exports.NetworkError = exports.RateLimitError = exports.ValidationError = exports.NotFoundError = exports.AuthorizationError = exports.AuthenticationError = exports.AttroveError = exports.AttroveAdmin = exports.Attrove = void 0;
|
|
37
|
+
const tslib_1 = require("tslib");
|
|
38
|
+
const client_1 = require("./client");
|
|
39
|
+
const admin_client_1 = require("./admin-client");
|
|
40
|
+
// Re-export the client class with the static admin method
|
|
41
|
+
class Attrove extends client_1.Attrove {
|
|
42
|
+
/**
|
|
43
|
+
* Create an admin client for server-to-server operations.
|
|
44
|
+
*
|
|
45
|
+
* @param config - Admin client configuration
|
|
46
|
+
* @returns Admin client instance
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* const admin = Attrove.admin({
|
|
51
|
+
* clientId: 'your-client-id',
|
|
52
|
+
* clientSecret: 'your-client-secret'
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
static admin(config) {
|
|
57
|
+
return new admin_client_1.AttroveAdmin(config);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.Attrove = Attrove;
|
|
61
|
+
// Export the admin client class
|
|
62
|
+
var admin_client_2 = require("./admin-client");
|
|
63
|
+
Object.defineProperty(exports, "AttroveAdmin", { enumerable: true, get: function () { return admin_client_2.AttroveAdmin; } });
|
|
64
|
+
// Export all types
|
|
65
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
66
|
+
// Export errors
|
|
67
|
+
var errors_1 = require("./errors");
|
|
68
|
+
Object.defineProperty(exports, "AttroveError", { enumerable: true, get: function () { return errors_1.AttroveError; } });
|
|
69
|
+
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_1.AuthenticationError; } });
|
|
70
|
+
Object.defineProperty(exports, "AuthorizationError", { enumerable: true, get: function () { return errors_1.AuthorizationError; } });
|
|
71
|
+
Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return errors_1.NotFoundError; } });
|
|
72
|
+
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return errors_1.ValidationError; } });
|
|
73
|
+
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return errors_1.RateLimitError; } });
|
|
74
|
+
Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function () { return errors_1.NetworkError; } });
|
|
75
|
+
Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return errors_1.TimeoutError; } });
|
|
76
|
+
Object.defineProperty(exports, "ServerError", { enumerable: true, get: function () { return errors_1.ServerError; } });
|
|
77
|
+
Object.defineProperty(exports, "isAttroveError", { enumerable: true, get: function () { return errors_1.isAttroveError; } });
|
|
78
|
+
Object.defineProperty(exports, "isAuthenticationError", { enumerable: true, get: function () { return errors_1.isAuthenticationError; } });
|
|
79
|
+
Object.defineProperty(exports, "isAuthorizationError", { enumerable: true, get: function () { return errors_1.isAuthorizationError; } });
|
|
80
|
+
Object.defineProperty(exports, "isNotFoundError", { enumerable: true, get: function () { return errors_1.isNotFoundError; } });
|
|
81
|
+
Object.defineProperty(exports, "isValidationError", { enumerable: true, get: function () { return errors_1.isValidationError; } });
|
|
82
|
+
Object.defineProperty(exports, "isRateLimitError", { enumerable: true, get: function () { return errors_1.isRateLimitError; } });
|
|
83
|
+
Object.defineProperty(exports, "isNetworkError", { enumerable: true, get: function () { return errors_1.isNetworkError; } });
|
|
84
|
+
Object.defineProperty(exports, "isTimeoutError", { enumerable: true, get: function () { return errors_1.isTimeoutError; } });
|
|
85
|
+
Object.defineProperty(exports, "isServerError", { enumerable: true, get: function () { return errors_1.isServerError; } });
|
|
86
|
+
// Export streaming utilities
|
|
87
|
+
var streaming_1 = require("./utils/streaming");
|
|
88
|
+
Object.defineProperty(exports, "generateMessageId", { enumerable: true, get: function () { return streaming_1.generateMessageId; } });
|
|
89
|
+
// Export constants for advanced usage
|
|
90
|
+
var constants_1 = require("./constants");
|
|
91
|
+
Object.defineProperty(exports, "SDK_VERSION", { enumerable: true, get: function () { return constants_1.SDK_VERSION; } });
|
|
92
|
+
Object.defineProperty(exports, "DEFAULT_BASE_URL", { enumerable: true, get: function () { return constants_1.DEFAULT_BASE_URL; } });
|
|
93
|
+
Object.defineProperty(exports, "DEFAULT_TIMEOUT", { enumerable: true, get: function () { return constants_1.DEFAULT_TIMEOUT; } });
|
|
94
|
+
Object.defineProperty(exports, "DEFAULT_MAX_RETRIES", { enumerable: true, get: function () { return constants_1.DEFAULT_MAX_RETRIES; } });
|
|
95
|
+
// Export version utility for programmatic access
|
|
96
|
+
var version_1 = require("./version");
|
|
97
|
+
Object.defineProperty(exports, "getVersion", { enumerable: true, get: function () { return version_1.getVersion; } });
|
|
98
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/sdk/src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;;;;AAEH,qCAAoD;AACpD,iDAAkE;AAGlE,0DAA0D;AAC1D,MAAa,OAAQ,SAAQ,gBAAa;IACxC;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,KAAK,CAAC,MAA0B;QACrC,OAAO,IAAI,2BAAY,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;CACF;AAlBD,0BAkBC;AAED,gCAAgC;AAChC,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AAGrB,mBAAmB;AACnB,kDAAwB;AAExB,gBAAgB;AAChB,mCAmBkB;AAlBhB,sGAAA,YAAY,OAAA;AACZ,6GAAA,mBAAmB,OAAA;AACnB,4GAAA,kBAAkB,OAAA;AAClB,uGAAA,aAAa,OAAA;AACb,yGAAA,eAAe,OAAA;AACf,wGAAA,cAAc,OAAA;AACd,sGAAA,YAAY,OAAA;AACZ,sGAAA,YAAY,OAAA;AACZ,qGAAA,WAAW,OAAA;AACX,wGAAA,cAAc,OAAA;AACd,+GAAA,qBAAqB,OAAA;AACrB,8GAAA,oBAAoB,OAAA;AACpB,yGAAA,eAAe,OAAA;AACf,2GAAA,iBAAiB,OAAA;AACjB,0GAAA,gBAAgB,OAAA;AAChB,wGAAA,cAAc,OAAA;AACd,wGAAA,cAAc,OAAA;AACd,uGAAA,aAAa,OAAA;AAcf,6BAA6B;AAC7B,+CAAsD;AAA7C,8GAAA,iBAAiB,OAAA;AAG1B,sCAAsC;AACtC,yCAKqB;AAJnB,wGAAA,WAAW,OAAA;AACX,6GAAA,gBAAgB,OAAA;AAChB,4GAAA,eAAe,OAAA;AACf,gHAAA,mBAAmB,OAAA;AAGrB,iDAAiD;AACjD,qCAAuC;AAA9B,qGAAA,UAAU,OAAA"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Conversations Resource
|
|
4
|
+
*
|
|
5
|
+
* Provides methods for accessing and managing conversations (channels, threads, etc.).
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.ConversationsResource = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* Conversations resource for accessing conversation data.
|
|
11
|
+
*
|
|
12
|
+
* Provides methods for listing conversations and managing sync settings.
|
|
13
|
+
*/
|
|
14
|
+
class ConversationsResource {
|
|
15
|
+
constructor(http, userId) {
|
|
16
|
+
this.http = http;
|
|
17
|
+
this.userId = userId;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* List conversations with optional filtering.
|
|
21
|
+
*
|
|
22
|
+
* @param options - Filtering and pagination options
|
|
23
|
+
* @returns Paginated list of conversations
|
|
24
|
+
*
|
|
25
|
+
* @throws {AuthenticationError} If the API key is invalid or expired
|
|
26
|
+
* @throws {ValidationError} If the filter parameters are invalid
|
|
27
|
+
* @throws {NetworkError} If unable to reach the API
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* // List all conversations
|
|
32
|
+
* const { data, pagination } = await attrove.conversations.list();
|
|
33
|
+
*
|
|
34
|
+
* // List only synced conversations
|
|
35
|
+
* const { data } = await attrove.conversations.list({ syncedOnly: true });
|
|
36
|
+
*
|
|
37
|
+
* // Filter by integration
|
|
38
|
+
* const { data } = await attrove.conversations.list({
|
|
39
|
+
* integrationIds: ['550e8400-e29b-41d4-a716-446655440000']
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
async list(options = {}) {
|
|
44
|
+
const params = {};
|
|
45
|
+
if (options.integrationIds?.length) {
|
|
46
|
+
params.integration_ids = options.integrationIds;
|
|
47
|
+
}
|
|
48
|
+
if (options.syncedOnly !== undefined) {
|
|
49
|
+
params.synced_only = String(options.syncedOnly);
|
|
50
|
+
}
|
|
51
|
+
if (options.limit !== undefined) {
|
|
52
|
+
params.limit = String(options.limit);
|
|
53
|
+
}
|
|
54
|
+
if (options.offset !== undefined) {
|
|
55
|
+
params.offset = String(options.offset);
|
|
56
|
+
}
|
|
57
|
+
const response = await this.http.request(`/v1/users/${this.userId}/conversations`, { method: 'GET' }, params);
|
|
58
|
+
return {
|
|
59
|
+
data: response.data,
|
|
60
|
+
pagination: response.pagination,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Update sync settings for multiple conversations.
|
|
65
|
+
*
|
|
66
|
+
* @param updates - Array of conversation sync updates
|
|
67
|
+
* @returns Count of updated conversations
|
|
68
|
+
*
|
|
69
|
+
* @throws {AuthenticationError} If the API key is invalid or expired
|
|
70
|
+
* @throws {ValidationError} If the updates are invalid
|
|
71
|
+
* @throws {NotFoundError} If any conversation does not exist
|
|
72
|
+
* @throws {NetworkError} If unable to reach the API
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* // Enable syncing for specific conversations
|
|
77
|
+
* const { updated } = await attrove.conversations.updateSync([
|
|
78
|
+
* { id: '550e8400-e29b-41d4-a716-446655440000', importMessages: true },
|
|
79
|
+
* { id: '550e8400-e29b-41d4-a716-446655440001', importMessages: false }
|
|
80
|
+
* ]);
|
|
81
|
+
* console.log(`Updated ${updated} conversations`);
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
async updateSync(updates) {
|
|
85
|
+
const body = {
|
|
86
|
+
conversations: updates.map((u) => ({
|
|
87
|
+
id: u.id,
|
|
88
|
+
import_messages: u.importMessages,
|
|
89
|
+
})),
|
|
90
|
+
};
|
|
91
|
+
return this.http.patch(`/v1/users/${this.userId}/conversations`, body);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.ConversationsResource = ConversationsResource;
|
|
95
|
+
//# sourceMappingURL=conversations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversations.js","sourceRoot":"","sources":["../../../../../../packages/sdk/src/resources/conversations.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAqBH;;;;GAIG;AACH,MAAa,qBAAqB;IAChC,YACmB,IAAgB,EAChB,MAAc;QADd,S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Ac;aAClC,CAAC,CAAC;SACJ,CAAC;QAEF,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CACpB,aAAa,IAAI,CAAC,MAAM,gBAAgB,EACxC,IAAI,CACL,CAAC;IACJ,CAAC;CACF;AA5FD,sDA4FC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Resource exports
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.QueryResource = exports.IntegrationsResource = exports.ConversationsResource = exports.MessagesResource = exports.UsersResource = void 0;
|
|
7
|
+
var users_1 = require("./users");
|
|
8
|
+
Object.defineProperty(exports, "UsersResource", { enumerable: true, get: function () { return users_1.UsersResource; } });
|
|
9
|
+
var messages_1 = require("./messages");
|
|
10
|
+
Object.defineProperty(exports, "MessagesResource", { enumerable: true, get: function () { return messages_1.MessagesResource; } });
|
|
11
|
+
var conversations_1 = require("./conversations");
|
|
12
|
+
Object.defineProperty(exports, "ConversationsResource", { enumerable: true, get: function () { return conversations_1.ConversationsResource; } });
|
|
13
|
+
var integrations_1 = require("./integrations");
|
|
14
|
+
Object.defineProperty(exports, "IntegrationsResource", { enumerable: true, get: function () { return integrations_1.IntegrationsResource; } });
|
|
15
|
+
var query_1 = require("./query");
|
|
16
|
+
Object.defineProperty(exports, "QueryResource", { enumerable: true, get: function () { return query_1.QueryResource; } });
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/sdk/src/resources/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iCAAwC;AAA/B,sGAAA,aAAa,OAAA;AAGtB,uCAA8C;AAArC,4GAAA,gBAAgB,OAAA;AAGzB,iDAAwD;AAA/C,sHAAA,qBAAqB,OAAA;AAG9B,+CAAsD;AAA7C,oHAAA,oBAAoB,OAAA;AAE7B,iCAAwC;AAA/B,sGAAA,aAAa,OAAA"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Integrations Resource
|
|
4
|
+
*
|
|
5
|
+
* Provides methods for managing connected integrations (Gmail, Slack, etc.).
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.IntegrationsResource = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* Integrations resource for managing connected services.
|
|
11
|
+
*
|
|
12
|
+
* Provides methods for listing and disconnecting integrations
|
|
13
|
+
* (Gmail, Slack, Google Calendar, etc.).
|
|
14
|
+
*/
|
|
15
|
+
class IntegrationsResource {
|
|
16
|
+
constructor(http, userId) {
|
|
17
|
+
this.http = http;
|
|
18
|
+
this.userId = userId;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* List all integrations for the user.
|
|
22
|
+
*
|
|
23
|
+
* Note: This returns the same data as `users.get().integrations`.
|
|
24
|
+
* Use this method when you only need integration data.
|
|
25
|
+
*
|
|
26
|
+
* @returns Array of connected integrations
|
|
27
|
+
*
|
|
28
|
+
* @throws {AuthenticationError} If the API key is invalid or expired
|
|
29
|
+
* @throws {NetworkError} If unable to reach the API
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const integrations = await attrove.integrations.list();
|
|
34
|
+
* console.log(integrations.map(i => `${i.provider}: ${i.auth_status}`));
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
async list() {
|
|
38
|
+
const response = await this.http.get(`/v1/users/${this.userId}`);
|
|
39
|
+
return response.integrations;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Disconnect an integration.
|
|
43
|
+
*
|
|
44
|
+
* This will:
|
|
45
|
+
* - Revoke OAuth tokens where possible
|
|
46
|
+
* - Stop syncing data from this integration
|
|
47
|
+
* - Remove the integration record
|
|
48
|
+
*
|
|
49
|
+
* Note: Historical data that was already synced is retained.
|
|
50
|
+
*
|
|
51
|
+
* @param id - Integration ID (UUID format)
|
|
52
|
+
* @returns Confirmation of deletion
|
|
53
|
+
*
|
|
54
|
+
* @throws {AuthenticationError} If the API key is invalid or expired
|
|
55
|
+
* @throws {NotFoundError} If the integration does not exist
|
|
56
|
+
* @throws {NetworkError} If unable to reach the API
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const { deleted } = await attrove.integrations.disconnect('integration-uuid');
|
|
61
|
+
* console.log(deleted ? 'Disconnected' : 'Already removed');
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
async disconnect(id) {
|
|
65
|
+
return this.http.delete(`/v1/users/${this.userId}/integrations/${id}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.IntegrationsResource = IntegrationsResource;
|
|
69
|
+
//# sourceMappingURL=integrations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integrations.js","sourceRoot":"","sources":["../../../../../../packages/sdk/src/resources/integrations.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAKH;;;;;GAKG;AACH,MAAa,oBAAoB;IAC/B,YACmB,IAAgB,EAChB,MAAc;QADd,SAAI,GAAJ,IAAI,CAAY;QAChB,WAAM,GAAN,MAAM,CAAQ;IAC9B,CAAC;IAEJ;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,CAAC,IAAI;QACR,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAClC,aAAa,IAAI,CAAC,MAAM,EAAE,CAC3B,CAAC;QACF,OAAO,QAAQ,CAAC,YAAY,CAAC;IAC/B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,KAAK,CAAC,UAAU,CAAC,EAAU;QACzB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CACrB,aAAa,IAAI,CAAC,MAAM,iBAAiB,EAAE,EAAE,CAC9C,CAAC;IACJ,CAAC;CACF;AA1DD,oDA0DC"}
|