@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.
- 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 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../packages/sdk/src/constants.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC;AAEnC;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AAE1D;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,CAAC;AAErC;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAErC;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAExC;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAU,CAAC;AAE1E;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAwB,IAAI,GAAG,CAAC,kBAAkB,CAAC,CAAC;AAErF;;GAEG;AACH,MAAM,CAAC,MAAM,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,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,OAAO,cAAc,CAAC,IAAI,CAAC,IAAI,sBAAsB,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attrove SDK Error Classes
|
|
3
|
+
*
|
|
4
|
+
* Provides a structured error hierarchy for handling API errors.
|
|
5
|
+
* Each error type maps to specific HTTP status codes and error codes.
|
|
6
|
+
*/
|
|
7
|
+
import { ErrorCodes } from '../types';
|
|
8
|
+
/**
|
|
9
|
+
* Base error class for all Attrove SDK errors.
|
|
10
|
+
*
|
|
11
|
+
* All SDK errors extend this class, enabling consistent error handling
|
|
12
|
+
* across the SDK. Use the type guards (isAttroveError, isAuthenticationError, etc.)
|
|
13
|
+
* for type-safe error handling.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* try {
|
|
18
|
+
* await attrove.query('...');
|
|
19
|
+
* } catch (error) {
|
|
20
|
+
* if (isAttroveError(error)) {
|
|
21
|
+
* console.log(`Error ${error.code}: ${error.message}`);
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export class AttroveError extends Error {
|
|
27
|
+
constructor(message, code, status, details) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.name = 'AttroveError';
|
|
30
|
+
this.code = code;
|
|
31
|
+
this.status = status;
|
|
32
|
+
this.details = details;
|
|
33
|
+
// Maintains proper stack trace for where our error was thrown (only available on V8)
|
|
34
|
+
const ErrorWithCapture = Error;
|
|
35
|
+
if (ErrorWithCapture.captureStackTrace) {
|
|
36
|
+
ErrorWithCapture.captureStackTrace(this, AttroveError);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates an AttroveError from an API error response.
|
|
41
|
+
*
|
|
42
|
+
* @param error - The error from the API (ApiError object or string)
|
|
43
|
+
* @param status - Optional HTTP status code
|
|
44
|
+
* @returns An AttroveError instance
|
|
45
|
+
*/
|
|
46
|
+
static fromApiError(error, status) {
|
|
47
|
+
if (typeof error === 'string') {
|
|
48
|
+
return new AttroveError(error, ErrorCodes.INTERNAL_ERROR, status);
|
|
49
|
+
}
|
|
50
|
+
return new AttroveError(error.message, error.code, status, error.details);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Returns a formatted string representation of the error.
|
|
54
|
+
*/
|
|
55
|
+
toString() {
|
|
56
|
+
const parts = [`${this.name}: ${this.message}`];
|
|
57
|
+
if (this.code)
|
|
58
|
+
parts.push(`Code: ${this.code}`);
|
|
59
|
+
if (this.status)
|
|
60
|
+
parts.push(`Status: ${this.status}`);
|
|
61
|
+
return parts.join(' | ');
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Returns a JSON-serializable representation of the error.
|
|
65
|
+
*/
|
|
66
|
+
toJSON() {
|
|
67
|
+
return {
|
|
68
|
+
name: this.name,
|
|
69
|
+
message: this.message,
|
|
70
|
+
code: this.code,
|
|
71
|
+
status: this.status,
|
|
72
|
+
details: this.details,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Error thrown when authentication fails (401).
|
|
78
|
+
*
|
|
79
|
+
* Common causes:
|
|
80
|
+
* - Invalid API key
|
|
81
|
+
* - Expired token
|
|
82
|
+
* - Missing authentication header
|
|
83
|
+
*
|
|
84
|
+
* @throws {AuthenticationError}
|
|
85
|
+
*/
|
|
86
|
+
export class AuthenticationError extends AttroveError {
|
|
87
|
+
constructor(message, code = ErrorCodes.AUTH_INVALID_TOKEN, details) {
|
|
88
|
+
super(message, code, 401, details);
|
|
89
|
+
this.name = 'AuthenticationError';
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Error thrown when the user lacks permission for an action (403).
|
|
94
|
+
*
|
|
95
|
+
* Common causes:
|
|
96
|
+
* - Accessing another user's data
|
|
97
|
+
* - Insufficient permissions for the operation
|
|
98
|
+
* - Resource access denied
|
|
99
|
+
*/
|
|
100
|
+
export class AuthorizationError extends AttroveError {
|
|
101
|
+
constructor(message, code = ErrorCodes.AUTH_INSUFFICIENT_PERMISSIONS, details) {
|
|
102
|
+
super(message, code, 403, details);
|
|
103
|
+
this.name = 'AuthorizationError';
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Error thrown when a resource is not found (404).
|
|
108
|
+
*
|
|
109
|
+
* Common causes:
|
|
110
|
+
* - Invalid resource ID
|
|
111
|
+
* - Resource was deleted
|
|
112
|
+
* - User doesn't have access to the resource
|
|
113
|
+
*/
|
|
114
|
+
export class NotFoundError extends AttroveError {
|
|
115
|
+
constructor(message, details) {
|
|
116
|
+
super(message, ErrorCodes.RESOURCE_NOT_FOUND, 404, details);
|
|
117
|
+
this.name = 'NotFoundError';
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Error thrown when request validation fails (400).
|
|
122
|
+
*
|
|
123
|
+
* Common causes:
|
|
124
|
+
* - Invalid request parameters
|
|
125
|
+
* - Missing required fields
|
|
126
|
+
* - Invalid data format
|
|
127
|
+
*/
|
|
128
|
+
export class ValidationError extends AttroveError {
|
|
129
|
+
constructor(message, code = ErrorCodes.VALIDATION_INVALID_FORMAT, details) {
|
|
130
|
+
super(message, code, 400, details);
|
|
131
|
+
this.name = 'ValidationError';
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Error thrown when rate limits are exceeded (429).
|
|
136
|
+
*
|
|
137
|
+
* When this error is thrown, you should wait before retrying.
|
|
138
|
+
* Check the `retryAfter` property for the recommended wait time.
|
|
139
|
+
*/
|
|
140
|
+
export class RateLimitError extends AttroveError {
|
|
141
|
+
constructor(message, retryAfter, details) {
|
|
142
|
+
super(message, ErrorCodes.RATE_LIMIT_EXCEEDED, 429, details);
|
|
143
|
+
this.name = 'RateLimitError';
|
|
144
|
+
this.retryAfter = retryAfter;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Error thrown when there's a network or connectivity issue.
|
|
149
|
+
*
|
|
150
|
+
* Common causes:
|
|
151
|
+
* - No internet connection
|
|
152
|
+
* - DNS resolution failure
|
|
153
|
+
* - Connection refused
|
|
154
|
+
* - SSL/TLS errors
|
|
155
|
+
*/
|
|
156
|
+
export class NetworkError extends AttroveError {
|
|
157
|
+
constructor(message, details) {
|
|
158
|
+
super(message, ErrorCodes.SERVICE_UNAVAILABLE, undefined, details);
|
|
159
|
+
this.name = 'NetworkError';
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Error thrown when a request times out (408).
|
|
164
|
+
*
|
|
165
|
+
* The request took longer than the configured timeout.
|
|
166
|
+
* Consider increasing the timeout or retrying the request.
|
|
167
|
+
*/
|
|
168
|
+
export class TimeoutError extends AttroveError {
|
|
169
|
+
constructor(message = 'Request timed out', details) {
|
|
170
|
+
super(message, ErrorCodes.SERVICE_UNAVAILABLE, 408, details);
|
|
171
|
+
this.name = 'TimeoutError';
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Error thrown when there's a server-side issue (5xx).
|
|
176
|
+
*
|
|
177
|
+
* These errors are typically transient and may be resolved by retrying.
|
|
178
|
+
* The SDK automatically retries on 408, 429, 500, 502, 503, and 504 errors.
|
|
179
|
+
* See RETRY_STATUS_CODES in constants.ts for the authoritative list.
|
|
180
|
+
*/
|
|
181
|
+
export class ServerError extends AttroveError {
|
|
182
|
+
constructor(message, status = 500, details) {
|
|
183
|
+
super(message, ErrorCodes.INTERNAL_ERROR, status, details);
|
|
184
|
+
this.name = 'ServerError';
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Maps HTTP status codes to appropriate error classes.
|
|
189
|
+
*
|
|
190
|
+
* @param message - Error message
|
|
191
|
+
* @param status - HTTP status code
|
|
192
|
+
* @param code - Optional error code from the API
|
|
193
|
+
* @param details - Optional error details
|
|
194
|
+
* @returns An appropriate error instance for the status code
|
|
195
|
+
*/
|
|
196
|
+
export function createErrorFromStatus(message, status, code, details) {
|
|
197
|
+
switch (status) {
|
|
198
|
+
case 400:
|
|
199
|
+
return new ValidationError(message, code || ErrorCodes.VALIDATION_INVALID_FORMAT, details);
|
|
200
|
+
case 401:
|
|
201
|
+
return new AuthenticationError(message, code || ErrorCodes.AUTH_INVALID_TOKEN, details);
|
|
202
|
+
case 403:
|
|
203
|
+
return new AuthorizationError(message, code || ErrorCodes.AUTH_INSUFFICIENT_PERMISSIONS, details);
|
|
204
|
+
case 404:
|
|
205
|
+
return new NotFoundError(message, details);
|
|
206
|
+
case 408:
|
|
207
|
+
return new TimeoutError(message, details);
|
|
208
|
+
case 429:
|
|
209
|
+
return new RateLimitError(message, undefined, details);
|
|
210
|
+
default:
|
|
211
|
+
if (status >= 500) {
|
|
212
|
+
return new ServerError(message, status, details);
|
|
213
|
+
}
|
|
214
|
+
return new AttroveError(message, code || ErrorCodes.INTERNAL_ERROR, status, details);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
// =============================================================================
|
|
218
|
+
// Type Guards
|
|
219
|
+
// =============================================================================
|
|
220
|
+
/**
|
|
221
|
+
* Type guard to check if an error is an AttroveError.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```ts
|
|
225
|
+
* try {
|
|
226
|
+
* await attrove.query('...');
|
|
227
|
+
* } catch (error) {
|
|
228
|
+
* if (isAttroveError(error)) {
|
|
229
|
+
* console.log(`Error code: ${error.code}`);
|
|
230
|
+
* }
|
|
231
|
+
* }
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
export function isAttroveError(error) {
|
|
235
|
+
return error instanceof AttroveError;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Type guard to check if an error is an AuthenticationError.
|
|
239
|
+
*/
|
|
240
|
+
export function isAuthenticationError(error) {
|
|
241
|
+
return error instanceof AuthenticationError;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Type guard to check if an error is an AuthorizationError.
|
|
245
|
+
*/
|
|
246
|
+
export function isAuthorizationError(error) {
|
|
247
|
+
return error instanceof AuthorizationError;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Type guard to check if an error is a NotFoundError.
|
|
251
|
+
*/
|
|
252
|
+
export function isNotFoundError(error) {
|
|
253
|
+
return error instanceof NotFoundError;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Type guard to check if an error is a ValidationError.
|
|
257
|
+
*/
|
|
258
|
+
export function isValidationError(error) {
|
|
259
|
+
return error instanceof ValidationError;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Type guard to check if an error is a RateLimitError.
|
|
263
|
+
*/
|
|
264
|
+
export function isRateLimitError(error) {
|
|
265
|
+
return error instanceof RateLimitError;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Type guard to check if an error is a NetworkError.
|
|
269
|
+
*/
|
|
270
|
+
export function isNetworkError(error) {
|
|
271
|
+
return error instanceof NetworkError;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Type guard to check if an error is a TimeoutError.
|
|
275
|
+
*/
|
|
276
|
+
export function isTimeoutError(error) {
|
|
277
|
+
return error instanceof TimeoutError;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Type guard to check if an error is a ServerError.
|
|
281
|
+
*/
|
|
282
|
+
export function isServerError(error) {
|
|
283
|
+
return error instanceof ServerError;
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/sdk/src/errors/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAa,UAAU,EAA8D,MAAM,UAAU,CAAC;AAE7G;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IAiBrC,YAAY,OAAe,EAAE,IAAe,EAAE,MAAe,EAAE,OAAsB;QACnF,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,qFAAqF;QACrF,MAAM,gBAAgB,GAAG,KAExB,CAAC;QACF,IAAI,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;YACvC,gBAAgB,CAAC,iBAAiB,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,YAAY,CAAC,KAAwB,EAAE,MAAe;QAC3D,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,IAAI,YAAY,CAAC,KAAK,EAAE,UAAU,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;QACpE,CAAC;QACD,OAAO,IAAI,YAAY,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC5E,CAAC;IAED;;OA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M,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,KAAK,YAAY,YAAY,CAAC;AACvC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAc;IAClD,OAAO,KAAK,YAAY,mBAAmB,CAAC;AAC9C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,OAAO,KAAK,YAAY,kBAAkB,CAAC;AAC7C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,OAAO,KAAK,YAAY,aAAa,CAAC;AACxC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC9C,OAAO,KAAK,YAAY,eAAe,CAAC;AAC1C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,OAAO,KAAK,YAAY,cAAc,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,KAAK,YAAY,YAAY,CAAC;AACvC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,KAAK,YAAY,YAAY,CAAC;AACvC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,KAAK,YAAY,WAAW,CAAC;AACtC,CAAC"}
|
package/esm/src/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @attrove/sdk
|
|
3
|
+
*
|
|
4
|
+
* Official TypeScript SDK for the Attrove API.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { Attrove } from '@attrove/sdk';
|
|
9
|
+
*
|
|
10
|
+
* // Create a client for end-user operations
|
|
11
|
+
* const attrove = new Attrove({
|
|
12
|
+
* apiKey: 'sk_...',
|
|
13
|
+
* userId: 'user-uuid'
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* // Query user's context
|
|
17
|
+
* const response = await attrove.query('What meetings do I have tomorrow?');
|
|
18
|
+
* console.log(response.answer);
|
|
19
|
+
*
|
|
20
|
+
* // Create an admin client for server-to-server operations
|
|
21
|
+
* const admin = Attrove.admin({
|
|
22
|
+
* clientId: 'your-client-id',
|
|
23
|
+
* clientSecret: 'your-client-secret'
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // Create a user
|
|
27
|
+
* const { id, apiKey } = await admin.users.create({
|
|
28
|
+
* email: 'user@example.com'
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @packageDocumentation
|
|
33
|
+
*/
|
|
34
|
+
import { Attrove as AttroveClient } from './client';
|
|
35
|
+
import { AttroveAdmin } from './admin-client';
|
|
36
|
+
// Re-export the client class with the static admin method
|
|
37
|
+
export class Attrove extends AttroveClient {
|
|
38
|
+
/**
|
|
39
|
+
* Create an admin client for server-to-server operations.
|
|
40
|
+
*
|
|
41
|
+
* @param config - Admin client configuration
|
|
42
|
+
* @returns Admin client instance
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* const admin = Attrove.admin({
|
|
47
|
+
* clientId: 'your-client-id',
|
|
48
|
+
* clientSecret: 'your-client-secret'
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
static admin(config) {
|
|
53
|
+
return new AttroveAdmin(config);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Export the admin client class
|
|
57
|
+
export { AttroveAdmin } from './admin-client';
|
|
58
|
+
// Export all types
|
|
59
|
+
export * from './types';
|
|
60
|
+
// Export errors
|
|
61
|
+
export { AttroveError, AuthenticationError, AuthorizationError, NotFoundError, ValidationError, RateLimitError, NetworkError, TimeoutError, ServerError, isAttroveError, isAuthenticationError, isAuthorizationError, isNotFoundError, isValidationError, isRateLimitError, isNetworkError, isTimeoutError, isServerError, } from './errors';
|
|
62
|
+
// Export streaming utilities
|
|
63
|
+
export { generateMessageId } from './utils/streaming';
|
|
64
|
+
// Export constants for advanced usage
|
|
65
|
+
export { SDK_VERSION, DEFAULT_BASE_URL, DEFAULT_TIMEOUT, DEFAULT_MAX_RETRIES, } from './constants';
|
|
66
|
+
// Export version utility for programmatic access
|
|
67
|
+
export { getVersion } from './version';
|
|
68
|
+
//# 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,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,YAAY,EAAsB,MAAM,gBAAgB,CAAC;AAGlE,0DAA0D;AAC1D,MAAM,OAAO,OAAQ,SAAQ,aAAa;IACxC;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,KAAK,CAAC,MAA0B;QACrC,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;CACF;AAED,gCAAgC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,mBAAmB;AACnB,cAAc,SAAS,CAAC;AAExB,gBAAgB;AAChB,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,aAAa,GACd,MAAM,UAAU,CAAC;AAalB,6BAA6B;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAGtD,sCAAsC;AACtC,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,mBAAmB,GACpB,MAAM,aAAa,CAAC;AAErB,iDAAiD;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conversations Resource
|
|
3
|
+
*
|
|
4
|
+
* Provides methods for accessing and managing conversations (channels, threads, etc.).
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Conversations resource for accessing conversation data.
|
|
8
|
+
*
|
|
9
|
+
* Provides methods for listing conversations and managing sync settings.
|
|
10
|
+
*/
|
|
11
|
+
export class ConversationsResource {
|
|
12
|
+
constructor(http, userId) {
|
|
13
|
+
this.http = http;
|
|
14
|
+
this.userId = userId;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* List conversations with optional filtering.
|
|
18
|
+
*
|
|
19
|
+
* @param options - Filtering and pagination options
|
|
20
|
+
* @returns Paginated list of conversations
|
|
21
|
+
*
|
|
22
|
+
* @throws {AuthenticationError} If the API key is invalid or expired
|
|
23
|
+
* @throws {ValidationError} If the filter parameters are invalid
|
|
24
|
+
* @throws {NetworkError} If unable to reach the API
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* // List all conversations
|
|
29
|
+
* const { data, pagination } = await attrove.conversations.list();
|
|
30
|
+
*
|
|
31
|
+
* // List only synced conversations
|
|
32
|
+
* const { data } = await attrove.conversations.list({ syncedOnly: true });
|
|
33
|
+
*
|
|
34
|
+
* // Filter by integration
|
|
35
|
+
* const { data } = await attrove.conversations.list({
|
|
36
|
+
* integrationIds: ['550e8400-e29b-41d4-a716-446655440000']
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
async list(options = {}) {
|
|
41
|
+
const params = {};
|
|
42
|
+
if (options.integrationIds?.length) {
|
|
43
|
+
params.integration_ids = options.integrationIds;
|
|
44
|
+
}
|
|
45
|
+
if (options.syncedOnly !== undefined) {
|
|
46
|
+
params.synced_only = String(options.syncedOnly);
|
|
47
|
+
}
|
|
48
|
+
if (options.limit !== undefined) {
|
|
49
|
+
params.limit = String(options.limit);
|
|
50
|
+
}
|
|
51
|
+
if (options.offset !== undefined) {
|
|
52
|
+
params.offset = String(options.offset);
|
|
53
|
+
}
|
|
54
|
+
const response = await this.http.request(`/v1/users/${this.userId}/conversations`, { method: 'GET' }, params);
|
|
55
|
+
return {
|
|
56
|
+
data: response.data,
|
|
57
|
+
pagination: response.pagination,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Update sync settings for multiple conversations.
|
|
62
|
+
*
|
|
63
|
+
* @param updates - Array of conversation sync updates
|
|
64
|
+
* @returns Count of updated conversations
|
|
65
|
+
*
|
|
66
|
+
* @throws {AuthenticationError} If the API key is invalid or expired
|
|
67
|
+
* @throws {ValidationError} If the updates are invalid
|
|
68
|
+
* @throws {NotFoundError} If any conversation does not exist
|
|
69
|
+
* @throws {NetworkError} If unable to reach the API
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* // Enable syncing for specific conversations
|
|
74
|
+
* const { updated } = await attrove.conversations.updateSync([
|
|
75
|
+
* { id: '550e8400-e29b-41d4-a716-446655440000', importMessages: true },
|
|
76
|
+
* { id: '550e8400-e29b-41d4-a716-446655440001', importMessages: false }
|
|
77
|
+
* ]);
|
|
78
|
+
* console.log(`Updated ${updated} conversations`);
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
async updateSync(updates) {
|
|
82
|
+
const body = {
|
|
83
|
+
conversations: updates.map((u) => ({
|
|
84
|
+
id: u.id,
|
|
85
|
+
import_messages: u.importMessages,
|
|
86
|
+
})),
|
|
87
|
+
};
|
|
88
|
+
return this.http.patch(`/v1/users/${this.userId}/conversations`, body);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//# 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,MAAM,OAAO,qBAAqB;IAChC,YACmB,IAAgB,EAChB,MAAc;QADd,SAAI,GAAJ,IAAI,CAAY;QAChB,WAAM,GAAN,MAAM,CAAQ;IAC9B,CAAC;IAEJ;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,KAAK,CAAC,IAAI,CAAC,UAAoC,EAAE;QAC/C,MAAM,MAAM,GAAkD,EAAE,CAAC;QAEjE,IAAI,OAAO,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC;YACnC,MAAM,CAAC,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;QAClD,CAAC;QACD,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;YACrC,MAAM,CAAC,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAClD,CAAC;QACD,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAChC,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACvC,CAAC;QACD,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YACjC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACzC,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CACtC,aAAa,IAAI,CAAC,MAAM,gBAAgB,EACxC,EAAE,MAAM,EAAE,KAAK,EAAE,EACjB,MAAM,CACP,CAAC;QAEF,OAAO;YACL,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,UAAU,EAAE,QAAQ,CAAC,UAAU;SAChC,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,KAAK,CAAC,UAAU,CAAC,OAAiC;QAChD,MAAM,IAAI,GAAG;YACX,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBACjC,EAAE,EAAE,CAAC,CAAC,EAAE;gBACR,eAAe,EAAE,CAAC,CAAC,cAAc;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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resource exports
|
|
3
|
+
*/
|
|
4
|
+
export { UsersResource } from './users';
|
|
5
|
+
export { MessagesResource } from './messages';
|
|
6
|
+
export { ConversationsResource } from './conversations';
|
|
7
|
+
export { IntegrationsResource } from './integrations';
|
|
8
|
+
export { QueryResource } from './query';
|
|
9
|
+
//# 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,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAGxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integrations Resource
|
|
3
|
+
*
|
|
4
|
+
* Provides methods for managing connected integrations (Gmail, Slack, etc.).
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Integrations resource for managing connected services.
|
|
8
|
+
*
|
|
9
|
+
* Provides methods for listing and disconnecting integrations
|
|
10
|
+
* (Gmail, Slack, Google Calendar, etc.).
|
|
11
|
+
*/
|
|
12
|
+
export class IntegrationsResource {
|
|
13
|
+
constructor(http, userId) {
|
|
14
|
+
this.http = http;
|
|
15
|
+
this.userId = userId;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* List all integrations for the user.
|
|
19
|
+
*
|
|
20
|
+
* Note: This returns the same data as `users.get().integrations`.
|
|
21
|
+
* Use this method when you only need integration data.
|
|
22
|
+
*
|
|
23
|
+
* @returns Array of connected integrations
|
|
24
|
+
*
|
|
25
|
+
* @throws {AuthenticationError} If the API key is invalid or expired
|
|
26
|
+
* @throws {NetworkError} If unable to reach the API
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const integrations = await attrove.integrations.list();
|
|
31
|
+
* console.log(integrations.map(i => `${i.provider}: ${i.auth_status}`));
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
async list() {
|
|
35
|
+
const response = await this.http.get(`/v1/users/${this.userId}`);
|
|
36
|
+
return response.integrations;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Disconnect an integration.
|
|
40
|
+
*
|
|
41
|
+
* This will:
|
|
42
|
+
* - Revoke OAuth tokens where possible
|
|
43
|
+
* - Stop syncing data from this integration
|
|
44
|
+
* - Remove the integration record
|
|
45
|
+
*
|
|
46
|
+
* Note: Historical data that was already synced is retained.
|
|
47
|
+
*
|
|
48
|
+
* @param id - Integration ID (UUID format)
|
|
49
|
+
* @returns Confirmation of deletion
|
|
50
|
+
*
|
|
51
|
+
* @throws {AuthenticationError} If the API key is invalid or expired
|
|
52
|
+
* @throws {NotFoundError} If the integration does not exist
|
|
53
|
+
* @throws {NetworkError} If unable to reach the API
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const { deleted } = await attrove.integrations.disconnect('integration-uuid');
|
|
58
|
+
* console.log(deleted ? 'Disconnected' : 'Already removed');
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
async disconnect(id) {
|
|
62
|
+
return this.http.delete(`/v1/users/${this.userId}/integrations/${id}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# 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,MAAM,OAAO,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"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Messages Resource
|
|
3
|
+
*
|
|
4
|
+
* Provides methods for accessing messages from connected integrations.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Messages resource for accessing message data.
|
|
8
|
+
*
|
|
9
|
+
* Provides methods for listing and retrieving messages from
|
|
10
|
+
* connected integrations (Gmail, Slack, etc.).
|
|
11
|
+
*/
|
|
12
|
+
export class MessagesResource {
|
|
13
|
+
constructor(http, userId) {
|
|
14
|
+
this.http = http;
|
|
15
|
+
this.userId = userId;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* List messages with optional filtering.
|
|
19
|
+
*
|
|
20
|
+
* @param options - Filtering, pagination, and expansion options
|
|
21
|
+
* @returns Paginated list of messages
|
|
22
|
+
*
|
|
23
|
+
* @throws {AuthenticationError} If the API key is invalid or expired
|
|
24
|
+
* @throws {ValidationError} If the filter parameters are invalid
|
|
25
|
+
* @throws {NetworkError} If unable to reach the API
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* // List recent messages
|
|
30
|
+
* const { data, pagination } = await attrove.messages.list();
|
|
31
|
+
*
|
|
32
|
+
* // List messages with body text
|
|
33
|
+
* const { data } = await attrove.messages.list({ expand: ['body_text'] });
|
|
34
|
+
*
|
|
35
|
+
* // Fetch specific messages by ID (UUIDs)
|
|
36
|
+
* const { data } = await attrove.messages.list({
|
|
37
|
+
* ids: ['message-uuid-1', 'message-uuid-2'],
|
|
38
|
+
* expand: ['body_text']
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
async list(options = {}) {
|
|
43
|
+
const params = {};
|
|
44
|
+
if (options.ids?.length) {
|
|
45
|
+
params.ids = options.ids.join(',');
|
|
46
|
+
}
|
|
47
|
+
if (options.integrationId) {
|
|
48
|
+
params.integration_id = options.integrationId;
|
|
49
|
+
}
|
|
50
|
+
if (options.conversationId) {
|
|
51
|
+
params.conversation_id = options.conversationId;
|
|
52
|
+
}
|
|
53
|
+
if (options.startDate) {
|
|
54
|
+
params.start_date = options.startDate;
|
|
55
|
+
}
|
|
56
|
+
if (options.endDate) {
|
|
57
|
+
params.end_date = options.endDate;
|
|
58
|
+
}
|
|
59
|
+
if (options.limit !== undefined) {
|
|
60
|
+
params.limit = String(options.limit);
|
|
61
|
+
}
|
|
62
|
+
if (options.offset !== undefined) {
|
|
63
|
+
params.offset = String(options.offset);
|
|
64
|
+
}
|
|
65
|
+
if (options.expand?.length) {
|
|
66
|
+
params.expand = options.expand.join(',');
|
|
67
|
+
}
|
|
68
|
+
const response = await this.http.request(`/v1/users/${this.userId}/messages`, { method: 'GET' }, params);
|
|
69
|
+
return {
|
|
70
|
+
data: response.data,
|
|
71
|
+
pagination: response.pagination,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get a single message by ID.
|
|
76
|
+
*
|
|
77
|
+
* @param id - Message ID (UUID format)
|
|
78
|
+
* @returns The requested message
|
|
79
|
+
*
|
|
80
|
+
* @throws {AuthenticationError} If the API key is invalid or expired
|
|
81
|
+
* @throws {NotFoundError} If the message does not exist
|
|
82
|
+
* @throws {NetworkError} If unable to reach the API
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* const message = await attrove.messages.get('message-uuid');
|
|
87
|
+
* console.log(message.subject);
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
async get(id) {
|
|
91
|
+
return this.http.get(`/v1/users/${this.userId}/messages/${id}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../../../../../packages/sdk/src/resources/messages.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAaH;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IAC3B,YACmB,IAAgB,EAChB,MAAc;QADd,SAAI,GAAJ,IAAI,CAAY;QAChB,WAAM,GAAN,MAAM,CAAQ;IAC9B,CAAC;IAEJ;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,KAAK,CAAC,IAAI,CAAC,UAA+B,EAAE;QAC1C,MAAM,MAAM,GAAuC,EAAE,CAAC;QAEtD,IAAI,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC;YACxB,MAAM,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CA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