@@ -50,15 +50,15 @@ type Contact = {
50
50
/**
51
51
* The source the contact was created from.
52
52
*/
53
- source : string | null ;
53
+ source : string ;
54
54
/**
55
55
* Whether the contact will receive campaign and loops emails.
56
56
*/
57
57
subscribed : boolean ;
58
58
/**
59
59
* The contact's user group (used to segemnt users when sending emails).
60
60
*/
61
- userGroup : string | null ;
61
+ userGroup : string ;
62
62
/**
63
63
* A unique user ID (for example, from an external application).
64
64
*/
@@ -102,6 +102,8 @@ type ContactProperties = Record<string, string | number | boolean | null>;
102
102
103
103
type EventProperties = Record < string , string | number | boolean > ;
104
104
105
+ type MailingLists = Record < string , boolean > ;
106
+
105
107
type TransactionalVariables = Record < string , string | number > ;
106
108
107
109
interface TransactionalAttachment {
@@ -266,6 +268,9 @@ class LoopsClient {
266
268
apiRoot = "https://app.loops.so/api/" ;
267
269
268
270
constructor ( apiKey : string ) {
271
+ if ( ! apiKey ) {
272
+ throw new Error ( "API key is required" ) ;
273
+ }
269
274
this . apiKey = apiKey ;
270
275
}
271
276
@@ -354,7 +359,7 @@ class LoopsClient {
354
359
async createContact (
355
360
email : string ,
356
361
properties ?: ContactProperties ,
357
- mailingLists ?: Record < string , boolean >
362
+ mailingLists ?: MailingLists
358
363
) : Promise < ContactSuccessResponse > {
359
364
const payload = { email, ...properties , mailingLists } ;
360
365
return this . _makeQuery ( {
@@ -378,7 +383,7 @@ class LoopsClient {
378
383
async updateContact (
379
384
email : string ,
380
385
properties : ContactProperties ,
381
- mailingLists ?: Record < string , boolean >
386
+ mailingLists ?: MailingLists
382
387
) : Promise < ContactSuccessResponse > {
383
388
const payload = { email, ...properties , mailingLists } ;
384
389
return this . _makeQuery ( {
@@ -538,7 +543,7 @@ class LoopsClient {
538
543
eventName : string ;
539
544
contactProperties ?: ContactProperties ;
540
545
eventProperties ?: EventProperties ;
541
- mailingLists ?: Record < string , boolean > ;
546
+ mailingLists ?: MailingLists ;
542
547
} ) : Promise < EventSuccessResponse > {
543
548
if ( ! userId && ! email )
544
549
throw "You must provide an `email` or `userId` value." ;
@@ -658,4 +663,5 @@ export {
658
663
PaginationData ,
659
664
TransactionalEmail ,
660
665
ListTransactionalsResponse ,
666
+ MailingLists ,
661
667
} ;
0 commit comments