@devwithbobby/loops 0.1.6 → 0.1.8
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/dist/component/lib.d.ts +1 -0
- package/dist/component/lib.d.ts.map +1 -1
- package/dist/component/lib.js +17 -15
- package/package.json +1 -1
- package/src/component/lib.ts +22 -16
package/dist/component/lib.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/component/lib.ts"],"names":[],"mappings":"AA0BA;;GAEG;AACH,eAAO,MAAM,YAAY,KA6CvB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,aAAa,KAexB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,iBAAiB,KAgC5B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,aAAa,KAwCxB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/component/lib.ts"],"names":[],"mappings":"AA0BA;;GAEG;AACH,eAAO,MAAM,YAAY,KA6CvB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,aAAa,KAexB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,iBAAiB,KAgC5B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,aAAa,KAwCxB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,UAAU,KAiHrB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,aAAa,KAoDxB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,iBAAiB,KAqD5B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,SAAS,KAgCpB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,aAAa,KA8BxB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,YAAY,KAkFvB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,WAAW,KA+CtB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,WAAW,KA2DtB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,mBAAmB,KA4C9B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,kBAAkB,KA+B7B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,kBAAkB,KA+B7B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,mBAAmB,KAwC9B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,eAAe,KAwC1B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,aAAa,KAgDxB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,uBAAuB,KAsGlC,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,uBAAuB,KA6ClC,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,mBAAmB,KA6C9B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,oBAAoB,KA8B/B,CAAC"}
|
package/dist/component/lib.js
CHANGED
|
@@ -190,7 +190,6 @@ export const addContact = za({
|
|
|
190
190
|
id: z.string().optional(),
|
|
191
191
|
}),
|
|
192
192
|
handler: async (ctx, args) => {
|
|
193
|
-
// First, try to create the contact
|
|
194
193
|
const response = await fetch(`${LOOPS_API_BASE_URL}/contacts/create`, {
|
|
195
194
|
method: "POST",
|
|
196
195
|
headers: {
|
|
@@ -201,10 +200,8 @@ export const addContact = za({
|
|
|
201
200
|
});
|
|
202
201
|
if (!response.ok) {
|
|
203
202
|
const errorText = await response.text();
|
|
204
|
-
// If contact already exists (409), fall back to update
|
|
205
203
|
if (response.status === 409) {
|
|
206
204
|
console.log(`Contact ${args.contact.email} already exists, updating instead`);
|
|
207
|
-
// Try to find the existing contact to get their ID
|
|
208
205
|
const findResponse = await fetch(`${LOOPS_API_BASE_URL}/contacts/find?email=${encodeURIComponent(args.contact.email)}`, {
|
|
209
206
|
method: "GET",
|
|
210
207
|
headers: {
|
|
@@ -215,9 +212,7 @@ export const addContact = za({
|
|
|
215
212
|
if (!findResponse.ok) {
|
|
216
213
|
const findErrorText = await findResponse.text();
|
|
217
214
|
console.error(`Failed to find existing contact [${findResponse.status}]:`, findErrorText);
|
|
218
|
-
// Continue with update anyway - it should work
|
|
219
215
|
}
|
|
220
|
-
// Update the contact instead
|
|
221
216
|
const updateResponse = await fetch(`${LOOPS_API_BASE_URL}/contacts/update`, {
|
|
222
217
|
method: "PUT",
|
|
223
218
|
headers: {
|
|
@@ -583,6 +578,7 @@ export const triggerLoop = za({
|
|
|
583
578
|
/**
|
|
584
579
|
* Find a contact by email
|
|
585
580
|
* Retrieves contact information from Loops
|
|
581
|
+
* Note: Loops API may return either an object or an array
|
|
586
582
|
*/
|
|
587
583
|
export const findContact = za({
|
|
588
584
|
args: z.object({
|
|
@@ -593,15 +589,15 @@ export const findContact = za({
|
|
|
593
589
|
success: z.boolean(),
|
|
594
590
|
contact: z
|
|
595
591
|
.object({
|
|
596
|
-
id: z.string().optional(),
|
|
597
|
-
email: z.string().optional(),
|
|
598
|
-
firstName: z.string().optional(),
|
|
599
|
-
lastName: z.string().optional(),
|
|
600
|
-
source: z.string().optional(),
|
|
601
|
-
subscribed: z.boolean().optional(),
|
|
602
|
-
userGroup: z.string().optional(),
|
|
603
|
-
userId: z.string().optional(),
|
|
604
|
-
createdAt: z.string().optional(),
|
|
592
|
+
id: z.string().nullable().optional(),
|
|
593
|
+
email: z.string().nullable().optional(),
|
|
594
|
+
firstName: z.string().nullable().optional(),
|
|
595
|
+
lastName: z.string().nullable().optional(),
|
|
596
|
+
source: z.string().nullable().optional(),
|
|
597
|
+
subscribed: z.boolean().nullable().optional(),
|
|
598
|
+
userGroup: z.string().nullable().optional(),
|
|
599
|
+
userId: z.string().nullable().optional(),
|
|
600
|
+
createdAt: z.string().nullable().optional(),
|
|
605
601
|
})
|
|
606
602
|
.optional(),
|
|
607
603
|
}),
|
|
@@ -622,9 +618,15 @@ export const findContact = za({
|
|
|
622
618
|
throw sanitizeError(response.status, errorText);
|
|
623
619
|
}
|
|
624
620
|
const data = (await response.json());
|
|
621
|
+
// Handle case where Loops returns an array instead of a single object
|
|
622
|
+
let contact = Array.isArray(data) ? data[0] : data;
|
|
623
|
+
// Convert null values to undefined for optional fields (Zod handles undefined but not null in optional())
|
|
624
|
+
if (contact) {
|
|
625
|
+
contact = Object.fromEntries(Object.entries(contact).map(([key, value]) => [key, value === null ? undefined : value]));
|
|
626
|
+
}
|
|
625
627
|
return {
|
|
626
628
|
success: true,
|
|
627
|
-
contact:
|
|
629
|
+
contact: contact,
|
|
628
630
|
};
|
|
629
631
|
},
|
|
630
632
|
});
|
package/package.json
CHANGED
package/src/component/lib.ts
CHANGED
|
@@ -192,7 +192,6 @@ export const addContact = za({
|
|
|
192
192
|
id: z.string().optional(),
|
|
193
193
|
}),
|
|
194
194
|
handler: async (ctx, args) => {
|
|
195
|
-
// First, try to create the contact
|
|
196
195
|
const response = await fetch(`${LOOPS_API_BASE_URL}/contacts/create`, {
|
|
197
196
|
method: "POST",
|
|
198
197
|
headers: {
|
|
@@ -205,11 +204,9 @@ export const addContact = za({
|
|
|
205
204
|
if (!response.ok) {
|
|
206
205
|
const errorText = await response.text();
|
|
207
206
|
|
|
208
|
-
// If contact already exists (409), fall back to update
|
|
209
207
|
if (response.status === 409) {
|
|
210
208
|
console.log(`Contact ${args.contact.email} already exists, updating instead`);
|
|
211
209
|
|
|
212
|
-
// Try to find the existing contact to get their ID
|
|
213
210
|
const findResponse = await fetch(
|
|
214
211
|
`${LOOPS_API_BASE_URL}/contacts/find?email=${encodeURIComponent(args.contact.email)}`,
|
|
215
212
|
{
|
|
@@ -224,10 +221,8 @@ export const addContact = za({
|
|
|
224
221
|
if (!findResponse.ok) {
|
|
225
222
|
const findErrorText = await findResponse.text();
|
|
226
223
|
console.error(`Failed to find existing contact [${findResponse.status}]:`, findErrorText);
|
|
227
|
-
// Continue with update anyway - it should work
|
|
228
224
|
}
|
|
229
225
|
|
|
230
|
-
// Update the contact instead
|
|
231
226
|
const updateResponse = await fetch(`${LOOPS_API_BASE_URL}/contacts/update`, {
|
|
232
227
|
method: "PUT",
|
|
233
228
|
headers: {
|
|
@@ -634,6 +629,7 @@ export const triggerLoop = za({
|
|
|
634
629
|
/**
|
|
635
630
|
* Find a contact by email
|
|
636
631
|
* Retrieves contact information from Loops
|
|
632
|
+
* Note: Loops API may return either an object or an array
|
|
637
633
|
*/
|
|
638
634
|
export const findContact = za({
|
|
639
635
|
args: z.object({
|
|
@@ -644,15 +640,15 @@ export const findContact = za({
|
|
|
644
640
|
success: z.boolean(),
|
|
645
641
|
contact: z
|
|
646
642
|
.object({
|
|
647
|
-
id: z.string().optional(),
|
|
648
|
-
email: z.string().optional(),
|
|
649
|
-
firstName: z.string().optional(),
|
|
650
|
-
lastName: z.string().optional(),
|
|
651
|
-
source: z.string().optional(),
|
|
652
|
-
subscribed: z.boolean().optional(),
|
|
653
|
-
userGroup: z.string().optional(),
|
|
654
|
-
userId: z.string().optional(),
|
|
655
|
-
createdAt: z.string().optional(),
|
|
643
|
+
id: z.string().nullable().optional(),
|
|
644
|
+
email: z.string().nullable().optional(),
|
|
645
|
+
firstName: z.string().nullable().optional(),
|
|
646
|
+
lastName: z.string().nullable().optional(),
|
|
647
|
+
source: z.string().nullable().optional(),
|
|
648
|
+
subscribed: z.boolean().nullable().optional(),
|
|
649
|
+
userGroup: z.string().nullable().optional(),
|
|
650
|
+
userId: z.string().nullable().optional(),
|
|
651
|
+
createdAt: z.string().nullable().optional(),
|
|
656
652
|
})
|
|
657
653
|
.optional(),
|
|
658
654
|
}),
|
|
@@ -677,11 +673,21 @@ export const findContact = za({
|
|
|
677
673
|
throw sanitizeError(response.status, errorText);
|
|
678
674
|
}
|
|
679
675
|
|
|
680
|
-
const data = (await response.json()) as Record<string, any
|
|
676
|
+
const data = (await response.json()) as Record<string, any> | Array<Record<string, any>>;
|
|
677
|
+
|
|
678
|
+
// Handle case where Loops returns an array instead of a single object
|
|
679
|
+
let contact = Array.isArray(data) ? data[0] : data;
|
|
680
|
+
|
|
681
|
+
// Convert null values to undefined for optional fields (Zod handles undefined but not null in optional())
|
|
682
|
+
if (contact) {
|
|
683
|
+
contact = Object.fromEntries(
|
|
684
|
+
Object.entries(contact).map(([key, value]) => [key, value === null ? undefined : value])
|
|
685
|
+
) as Record<string, any>;
|
|
686
|
+
}
|
|
681
687
|
|
|
682
688
|
return {
|
|
683
689
|
success: true,
|
|
684
|
-
contact:
|
|
690
|
+
contact: contact as Record<string, any> | undefined,
|
|
685
691
|
};
|
|
686
692
|
},
|
|
687
693
|
});
|