Skip to content

Commit da874f6

Browse files
committed
MailingLists type; error for missing API key
1 parent 9e5135e commit da874f6

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/index.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ type Contact = {
5050
/**
5151
* The source the contact was created from.
5252
*/
53-
source: string | null;
53+
source: string;
5454
/**
5555
* Whether the contact will receive campaign and loops emails.
5656
*/
5757
subscribed: boolean;
5858
/**
5959
* The contact's user group (used to segemnt users when sending emails).
6060
*/
61-
userGroup: string | null;
61+
userGroup: string;
6262
/**
6363
* A unique user ID (for example, from an external application).
6464
*/
@@ -102,6 +102,8 @@ type ContactProperties = Record<string, string | number | boolean | null>;
102102

103103
type EventProperties = Record<string, string | number | boolean>;
104104

105+
type MailingLists = Record<string, boolean>;
106+
105107
type TransactionalVariables = Record<string, string | number>;
106108

107109
interface TransactionalAttachment {
@@ -266,6 +268,9 @@ class LoopsClient {
266268
apiRoot = "https://app.loops.so/api/";
267269

268270
constructor(apiKey: string) {
271+
if (!apiKey) {
272+
throw new Error("API key is required");
273+
}
269274
this.apiKey = apiKey;
270275
}
271276

@@ -354,7 +359,7 @@ class LoopsClient {
354359
async createContact(
355360
email: string,
356361
properties?: ContactProperties,
357-
mailingLists?: Record<string, boolean>
362+
mailingLists?: MailingLists
358363
): Promise<ContactSuccessResponse> {
359364
const payload = { email, ...properties, mailingLists };
360365
return this._makeQuery({
@@ -378,7 +383,7 @@ class LoopsClient {
378383
async updateContact(
379384
email: string,
380385
properties: ContactProperties,
381-
mailingLists?: Record<string, boolean>
386+
mailingLists?: MailingLists
382387
): Promise<ContactSuccessResponse> {
383388
const payload = { email, ...properties, mailingLists };
384389
return this._makeQuery({
@@ -538,7 +543,7 @@ class LoopsClient {
538543
eventName: string;
539544
contactProperties?: ContactProperties;
540545
eventProperties?: EventProperties;
541-
mailingLists?: Record<string, boolean>;
546+
mailingLists?: MailingLists;
542547
}): Promise<EventSuccessResponse> {
543548
if (!userId && !email)
544549
throw "You must provide an `email` or `userId` value.";
@@ -658,4 +663,5 @@ export {
658663
PaginationData,
659664
TransactionalEmail,
660665
ListTransactionalsResponse,
666+
MailingLists,
661667
};

0 commit comments

Comments
 (0)