payload-plugin-newsletter 0.6.0 → 0.6.1
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/CHANGELOG.md +4 -1
- package/dist/index.cjs +32 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +32 -28
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -800,20 +800,22 @@ var BroadcastProvider = class {
|
|
|
800
800
|
}
|
|
801
801
|
async addContact(contact) {
|
|
802
802
|
try {
|
|
803
|
-
const
|
|
803
|
+
const [firstName, ...lastNameParts] = (contact.name || "").split(" ");
|
|
804
|
+
const lastName = lastNameParts.join(" ");
|
|
805
|
+
const response = await fetch(`${this.apiUrl}/api/v1/subscribers.json`, {
|
|
804
806
|
method: "POST",
|
|
805
807
|
headers: {
|
|
806
808
|
"Authorization": `Bearer ${this.token}`,
|
|
807
809
|
"Content-Type": "application/json"
|
|
808
810
|
},
|
|
809
811
|
body: JSON.stringify({
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
812
|
+
subscriber: {
|
|
813
|
+
email: contact.email,
|
|
814
|
+
first_name: firstName || void 0,
|
|
815
|
+
last_name: lastName || void 0,
|
|
816
|
+
tags: [`lang:${contact.locale || "en"}`],
|
|
817
|
+
is_active: contact.subscriptionStatus === "active",
|
|
818
|
+
source: contact.source
|
|
817
819
|
}
|
|
818
820
|
})
|
|
819
821
|
});
|
|
@@ -832,7 +834,7 @@ var BroadcastProvider = class {
|
|
|
832
834
|
async updateContact(contact) {
|
|
833
835
|
try {
|
|
834
836
|
const searchResponse = await fetch(
|
|
835
|
-
`${this.apiUrl}/api/v1/
|
|
837
|
+
`${this.apiUrl}/api/v1/subscribers/find.json?email=${encodeURIComponent(contact.email)}`,
|
|
836
838
|
{
|
|
837
839
|
headers: {
|
|
838
840
|
"Authorization": `Bearer ${this.token}`
|
|
@@ -843,26 +845,27 @@ var BroadcastProvider = class {
|
|
|
843
845
|
await this.addContact(contact);
|
|
844
846
|
return;
|
|
845
847
|
}
|
|
846
|
-
const
|
|
847
|
-
|
|
848
|
-
if (!existingContact) {
|
|
848
|
+
const existingContact = await searchResponse.json();
|
|
849
|
+
if (!existingContact || !existingContact.id) {
|
|
849
850
|
await this.addContact(contact);
|
|
850
851
|
return;
|
|
851
852
|
}
|
|
852
|
-
const
|
|
853
|
-
|
|
853
|
+
const [firstName, ...lastNameParts] = (contact.name || "").split(" ");
|
|
854
|
+
const lastName = lastNameParts.join(" ");
|
|
855
|
+
const response = await fetch(`${this.apiUrl}/api/v1/subscribers.json`, {
|
|
856
|
+
method: "PATCH",
|
|
854
857
|
headers: {
|
|
855
858
|
"Authorization": `Bearer ${this.token}`,
|
|
856
859
|
"Content-Type": "application/json"
|
|
857
860
|
},
|
|
858
861
|
body: JSON.stringify({
|
|
859
862
|
email: contact.email,
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
863
|
+
subscriber: {
|
|
864
|
+
first_name: firstName || void 0,
|
|
865
|
+
last_name: lastName || void 0,
|
|
866
|
+
tags: [`lang:${contact.locale || "en"}`],
|
|
867
|
+
is_active: contact.subscriptionStatus === "active",
|
|
868
|
+
source: contact.source
|
|
866
869
|
}
|
|
867
870
|
})
|
|
868
871
|
});
|
|
@@ -881,7 +884,7 @@ var BroadcastProvider = class {
|
|
|
881
884
|
async removeContact(email) {
|
|
882
885
|
try {
|
|
883
886
|
const searchResponse = await fetch(
|
|
884
|
-
`${this.apiUrl}/api/v1/
|
|
887
|
+
`${this.apiUrl}/api/v1/subscribers/find.json?email=${encodeURIComponent(email)}`,
|
|
885
888
|
{
|
|
886
889
|
headers: {
|
|
887
890
|
"Authorization": `Bearer ${this.token}`
|
|
@@ -891,16 +894,17 @@ var BroadcastProvider = class {
|
|
|
891
894
|
if (!searchResponse.ok) {
|
|
892
895
|
return;
|
|
893
896
|
}
|
|
894
|
-
const
|
|
895
|
-
|
|
896
|
-
if (!contact) {
|
|
897
|
+
const contact = await searchResponse.json();
|
|
898
|
+
if (!contact || !contact.id) {
|
|
897
899
|
return;
|
|
898
900
|
}
|
|
899
|
-
const response = await fetch(`${this.apiUrl}/api/v1/
|
|
900
|
-
method: "
|
|
901
|
+
const response = await fetch(`${this.apiUrl}/api/v1/subscribers/deactivate.json`, {
|
|
902
|
+
method: "POST",
|
|
901
903
|
headers: {
|
|
902
|
-
"Authorization": `Bearer ${this.token}
|
|
903
|
-
|
|
904
|
+
"Authorization": `Bearer ${this.token}`,
|
|
905
|
+
"Content-Type": "application/json"
|
|
906
|
+
},
|
|
907
|
+
body: JSON.stringify({ email })
|
|
904
908
|
});
|
|
905
909
|
if (!response.ok) {
|
|
906
910
|
const error = await response.text();
|