@devwithbobby/loops 0.1.6 → 0.1.7

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.
@@ -51,6 +51,7 @@ export declare const triggerLoop: any;
51
51
  /**
52
52
  * Find a contact by email
53
53
  * Retrieves contact information from Loops
54
+ * Note: Loops API may return either an object or an array
54
55
  */
55
56
  export declare const findContact: any;
56
57
  /**
@@ -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,KAsHrB,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;;;GAGG;AACH,eAAO,MAAM,WAAW,KAiDtB,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;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H;;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"}
@@ -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({
@@ -622,9 +618,11 @@ 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
+ const contact = Array.isArray(data) ? data[0] : data;
625
623
  return {
626
624
  success: true,
627
- contact: data,
625
+ contact: contact,
628
626
  };
629
627
  },
630
628
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devwithbobby/loops",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Convex component for integrating with Loops.so email marketing platform",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -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({
@@ -677,11 +673,14 @@ 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
+ const contact = Array.isArray(data) ? data[0] : data;
681
680
 
682
681
  return {
683
682
  success: true,
684
- contact: data,
683
+ contact: contact as Record<string, any> | undefined,
685
684
  };
686
685
  },
687
686
  });