({
email,
userId,
firstName,
eventName,
eventProperties,
}: {
email: string;
userId: string;
firstName?: string;
eventName: string;
eventProperties?: Record<string, string | number | boolean>;
})
| 23 | } |
| 24 | |
| 25 | async #sendEvent({ |
| 26 | email, |
| 27 | userId, |
| 28 | firstName, |
| 29 | eventName, |
| 30 | eventProperties, |
| 31 | }: { |
| 32 | email: string; |
| 33 | userId: string; |
| 34 | firstName?: string; |
| 35 | eventName: string; |
| 36 | eventProperties?: Record<string, string | number | boolean>; |
| 37 | }) { |
| 38 | const options = { |
| 39 | method: "POST", |
| 40 | headers: { Authorization: `Bearer ${this.apiKey}`, "Content-Type": "application/json" }, |
| 41 | body: JSON.stringify({ |
| 42 | email, |
| 43 | userId, |
| 44 | firstName, |
| 45 | eventName, |
| 46 | eventProperties, |
| 47 | }), |
| 48 | }; |
| 49 | |
| 50 | try { |
| 51 | const response = await fetch("https://app.loops.so/api/v1/events/send", options); |
| 52 | |
| 53 | if (!response.ok) { |
| 54 | logger.error(`Loops sendEvent ${eventName} bad status`, { status: response.status }); |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | const responseBody = (await response.json()) as any; |
| 59 | |
| 60 | if (!responseBody.success) { |
| 61 | logger.error(`Loops sendEvent ${eventName} failed response`, { |
| 62 | message: responseBody.message, |
| 63 | }); |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | return true; |
| 68 | } catch (error) { |
| 69 | logger.error(`Loops sendEvent ${eventName} failed`, { error }); |
| 70 | return false; |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | export const loopsClient = env.LOOPS_API_KEY ? new LoopsClient(env.LOOPS_API_KEY) : null; |
no test coverage detected