@@ -18,6 +18,7 @@ type ApiKeyResponse = ApiKeySuccessResponse | ApiKeyErrorResponse;
18
18
19
19
interface ContactSuccessResponse {
20
20
success : true ;
21
+ /** The ID of the contact. */
21
22
id : string ;
22
23
}
23
24
@@ -78,8 +79,6 @@ interface EventSuccessResponse {
78
79
success : boolean ;
79
80
}
80
81
81
- type EventResponse = EventSuccessResponse | ErrorResponse ;
82
-
83
82
interface TransactionalSuccess {
84
83
success : true ;
85
84
}
@@ -101,11 +100,6 @@ interface TransactionalNestedError {
101
100
transactionalId ?: string ;
102
101
}
103
102
104
- type TransactionalResponse =
105
- | TransactionalSuccess
106
- | TransactionalError
107
- | TransactionalNestedError ;
108
-
109
103
type ContactProperties = Record < string , string | number | boolean | null > ;
110
104
111
105
type EventProperties = Record < string , string | number | boolean > ;
@@ -192,6 +186,15 @@ interface TransactionalEmail {
192
186
dataVariables : string [ ] ;
193
187
}
194
188
189
+ interface ContactProperty {
190
+ /**
191
+ */
192
+ label : string ;
193
+ /**
194
+ * The type of property.
195
+ */
196
+ type : "string" | "number" | "boolean" | "date" ;
197
+ }
195
198
interface ListTransactionalsResponse {
196
199
pagination : PaginationData ;
197
200
data : TransactionalEmail [ ] ;
@@ -210,9 +213,16 @@ class RateLimitExceededError extends Error {
210
213
211
214
class APIError extends Error {
212
215
statusCode : number ;
213
- json : Record < string , unknown > ;
214
- constructor ( statusCode : number , json : Record < string , unknown > ) {
215
- super ( `${ statusCode } ${ json . message ? ` - ${ json . message } ` : "" } ` ) ;
216
+ json : ErrorResponse | TransactionalError | TransactionalNestedError ;
217
+ json : ErrorResponse | TransactionalError | TransactionalNestedError
218
+ ) {
219
+ let message : string | undefined ;
220
+ if ( "error" in json && json . error ?. message ) {
221
+ message = json . error . message ;
222
+ } else if ( "message" in json ) {
223
+ message = json . message ;
224
+ }
225
+ super ( `${ statusCode } ${ message ? ` - ${ message } ` : "" } ` ) ;
216
226
this . name = "APIError" ;
217
227
this . statusCode = statusCode ;
218
228
this . json = json ;
@@ -318,7 +328,7 @@ class LoopsClient {
318
328
email : string ,
319
329
properties ?: ContactProperties ,
320
330
mailingLists ?: Record < string , boolean >
321
- ) : Promise < ContactSuccessResponse | ErrorResponse > {
331
+ ) : Promise < ContactSuccessResponse > {
322
332
const payload = { email, ...properties , mailingLists } ;
323
333
return this . _makeQuery ( {
324
334
path : "v1/contacts/create" ,
@@ -342,7 +352,7 @@ class LoopsClient {
342
352
email : string ,
343
353
properties : ContactProperties ,
344
354
mailingLists ?: Record < string , boolean >
345
- ) : Promise < ContactSuccessResponse | ErrorResponse > {
355
+ ) : Promise < ContactSuccessResponse > {
346
356
const payload = { email, ...properties , mailingLists } ;
347
357
return this . _makeQuery ( {
348
358
path : "v1/contacts/update" ,
@@ -397,7 +407,7 @@ class LoopsClient {
397
407
} : {
398
408
email ?: string ;
399
409
userId ?: string ;
400
- } ) : Promise < DeleteSuccessResponse | ErrorResponse > {
410
+ } ) : Promise < DeleteSuccessResponse > {
401
411
if ( email && userId ) throw "Only one parameter is permitted." ;
402
412
const payload : { email ?: string ; userId ?: string } = { } ;
403
413
if ( email ) payload [ "email" ] = email ;
@@ -423,7 +433,7 @@ class LoopsClient {
423
433
async createContactProperty (
424
434
name : string ,
425
435
type : "string" | "number" | "boolean" | "date"
426
- ) : Promise < ContactPropertySuccessResponse | ErrorResponse > {
436
+ ) : Promise < ContactPropertySuccessResponse > {
427
437
return this . _makeQuery ( {
428
438
path : "v1/contacts/properties" ,
429
439
method : "POST" ,
@@ -445,7 +455,7 @@ class LoopsClient {
445
455
*/
446
456
async getCustomProperties (
447
457
list ?: "all" | "custom"
448
- ) : Promise < Record < "key" | "label" | "type" , string > [ ] > {
458
+ ) : Promise < ContactProperty [ ] > {
449
459
return this . _makeQuery ( {
450
460
path : "v1/contacts/properties" ,
451
461
params : { list : list || "all" } ,
@@ -494,7 +504,7 @@ class LoopsClient {
494
504
contactProperties ?: ContactProperties ;
495
505
eventProperties ?: EventProperties ;
496
506
mailingLists ?: Record < string , boolean > ;
497
- } ) : Promise < EventResponse > {
507
+ } ) : Promise < EventSuccessResponse > {
498
508
if ( ! userId && ! email )
499
509
throw "You must provide an `email` or `userId` value." ;
500
510
const payload : {
@@ -544,7 +554,7 @@ class LoopsClient {
544
554
addToAudience ?: boolean ;
545
555
dataVariables ?: TransactionalVariables ;
546
556
attachments ?: Array < TransactionalAttachment > ;
547
- } ) : Promise < TransactionalResponse > {
557
+ } ) : Promise < TransactionalSuccess > {
548
558
const payload = {
549
559
transactionalId,
550
560
email,
0 commit comments