Skip to content

Commit ac940a4

Browse files
committed
Accept null contact property values
1 parent bd0b0c4 commit ac940a4

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

README.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ Create a new contact.
7272

7373
#### Parameters
7474

75-
| Name | Type | Required | Notes |
76-
| -------------- | ------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
77-
| `email` | string | Yes | If a contact already exists with this email address, an error response will be returned. |
78-
| `properties` | object | No | An object containing default and any custom properties for your contact.<br />Please [add custom properties](https://loops.so/docs/contacts/properties#custom-contact-properties) in your Loops account before using them with the SDK.<br />Values can be of type `string`, `number`, `boolean` or `date` ([see allowed date formats](https://loops.so/docs/contacts/properties#dates)). |
79-
| `mailingLists` | object | No | An object of mailing list IDs and boolean subscription statuses. |
75+
| Name | Type | Required | Notes |
76+
| -------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
77+
| `email` | string | Yes | If a contact already exists with this email address, an error response will be returned. |
78+
| `properties` | object | No | An object containing default and any custom properties for your contact.<br />Please [add custom properties](https://loops.so/docs/contacts/properties#custom-contact-properties) in your Loops account before using them with the SDK.<br />Values can be of type `string`, `number`, `null` (to reset a value) `boolean` or `date` ([see allowed date formats](https://loops.so/docs/contacts/properties#dates)). |
79+
| `mailingLists` | object | No | An object of mailing list IDs and boolean subscription statuses. |
8080

8181
#### Examples
8282

@@ -128,11 +128,11 @@ Note: To update a contact's email address, the contact requires a `userId` value
128128

129129
#### Parameters
130130

131-
| Name | Type | Required | Notes |
132-
| -------------- | ------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
133-
| `email` | string | Yes | The email address of the contact to update. If there is no contact with this email address, a new contact will be created using the email and properties in this request. |
134-
| `properties` | object | No | An object containing default and any custom properties for your contact.<br />Please [add custom properties](https://loops.so/docs/contacts/properties#custom-contact-properties) in your Loops account before using them with the SDK.<br />Values can be of type `string`, `number`, `boolean` or `date` ([see allowed date formats](https://loops.so/docs/contacts/properties#dates)). |
135-
| `mailingLists` | object | No | An object of mailing list IDs and boolean subscription statuses. |
131+
| Name | Type | Required | Notes |
132+
| -------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
133+
| `email` | string | Yes | The email address of the contact to update. If there is no contact with this email address, a new contact will be created using the email and properties in this request. |
134+
| `properties` | object | No | An object containing default and any custom properties for your contact.<br />Please [add custom properties](https://loops.so/docs/contacts/properties#custom-contact-properties) in your Loops account before using them with the SDK.<br />Values can be of type `string`, `number`, `null` (to reset a value) `boolean` or `date` ([see allowed date formats](https://loops.so/docs/contacts/properties#dates)). |
135+
| `mailingLists` | object | No | An object of mailing list IDs and boolean subscription statuses. |
136136

137137
#### Example
138138

@@ -304,14 +304,14 @@ Send an event to trigger an email in Loops. [Read more about events](https://loo
304304

305305
#### Parameters
306306

307-
| Name | Type | Required | Notes |
308-
| ------------------- | ------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
309-
| `email` | string | No | The contact's email address. Required if `userId` is not present. |
310-
| `userId` | string | No | The contact's unique user ID. If you use `userID` without `email`, this value must have already been added to your contact in Loops. Required if `email` is not present. |
311-
| `eventName` | string | Yes | |
312-
| `contactProperties` | object | No | An object containing contact properties, which will be updated or added to the contact when the event is received.<br />Please [add custom properties](https://loops.so/docs/contacts/properties#custom-contact-properties) in your Loops account before using them with the SDK.<br />Values can be of type `string`, `number`, `boolean` or `date` ([see allowed date formats](https://loops.so/docs/contacts/properties#dates)). |
313-
| `eventProperties` | object | No | An object containing event properties, which will be made availabe in emails that are triggered by this event.<br />Values can be of type `string`, `number`, `boolean` or `date` ([see allowed date formats](https://loops.so/docs/events/properties#important-information-about-event-properties)). |
314-
| `mailingLists` | object | No | An object of mailing list IDs and boolean subscription statuses. |
307+
| Name | Type | Required | Notes |
308+
| ------------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
309+
| `email` | string | No | The contact's email address. Required if `userId` is not present. |
310+
| `userId` | string | No | The contact's unique user ID. If you use `userID` without `email`, this value must have already been added to your contact in Loops. Required if `email` is not present. |
311+
| `eventName` | string | Yes | |
312+
| `contactProperties` | object | No | An object containing contact properties, which will be updated or added to the contact when the event is received.<br />Please [add custom properties](https://loops.so/docs/contacts/properties#custom-contact-properties) in your Loops account before using them with the SDK.<br />Values can be of type `string`, `number`, `null` (to reset a value) `boolean` or `date` ([see allowed date formats](https://loops.so/docs/contacts/properties#dates)). |
313+
| `eventProperties` | object | No | An object containing event properties, which will be made availabe in emails that are triggered by this event.<br />Values can be of type `string`, `number`, `boolean` or `date` ([see allowed date formats](https://loops.so/docs/events/properties#important-information-about-event-properties)). |
314+
| `mailingLists` | object | No | An object of mailing list IDs and boolean subscription statuses. |
315315

316316
#### Examples
317317

@@ -412,7 +412,7 @@ const resp = await loops.sendTransactionalEmail({
412412
contentType: "application/pdf",
413413
data: "JVBERi0xLjMKJcTl8uXrp/Og0MTGCjQgMCBvYmoKPD...",
414414
},
415-
]
415+
],
416416
});
417417
```
418418

@@ -490,6 +490,7 @@ If your account has no custom fields, an empty list will be returned.
490490

491491
## Version history
492492

493+
- `v3.1.0` (Aug 12, 2024) - The SDK now accepts `null` as a value for contact properties in `createContact()`, `updateContact()` and `sendEvent()`, which allows you to reset/empty properties.
493494
- `v3.0.0` (Jul 2, 2024) - [`sendTransactionalEmail()`](#sendtransactionalemail) now accepts an object instead of separate parameters (breaking change).
494495
- `v2.2.0` (Jul 2, 2024) - Deprecated. Added new `addToAudience` option to [`sendTransactionalEmail()`](#sendtransactionalemail).
495496
- `v2.1.1` (Jun 20, 2024) - Added support for mailing lists in [`createContact()`](#createcontact), [`updateContact()`](#updatecontact) and [`sendEvent()`](#sendevent).

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,20 @@ type Contact = {
4040
/**
4141
* The source the contact was created from.
4242
*/
43-
source: string;
43+
source: string | null;
4444
/**
4545
* Whether the contact will receive campaign and loops emails.
4646
*/
4747
subscribed: boolean;
4848
/**
4949
* The contact's user group (used to segemnt users when sending emails).
5050
*/
51-
userGroup: string;
51+
userGroup: string | null;
5252
/**
5353
* A unique user ID (for example, from an external application).
5454
*/
5555
userId: string | null;
56-
} & Record<string, any>;
56+
} & Record<string, string | number | boolean | null>;
5757

5858
interface EventSuccessResponse {
5959
success: boolean;
@@ -92,7 +92,7 @@ type TransactionalResponse =
9292
| TransactionalError
9393
| TransactionalNestedError;
9494

95-
type ContactProperties = Record<string, string | number | boolean>;
95+
type ContactProperties = Record<string, string | number | boolean | null>;
9696

9797
type EventProperties = Record<string, string | number | boolean>;
9898

0 commit comments

Comments
 (0)