-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Loops client to capture contact when a signup is created
- Loading branch information
1 parent
3bf4389
commit 86f01cb
Showing
18 changed files
with
3,056 additions
and
2,002 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { Providers, RewardType } from '@latitude-data/core/browser' | ||
import { database } from '@latitude-data/core/client' | ||
import { publisher } from '@latitude-data/core/events/publisher' | ||
import { createProject, helpers } from '@latitude-data/core/factories' | ||
import { Result } from '@latitude-data/core/lib/Result' | ||
import { | ||
|
@@ -21,6 +22,7 @@ import setupService from './setupService' | |
const mocks = vi.hoisted(() => ({ | ||
claimReward: vi.fn(), | ||
})) | ||
const publisherSpy = vi.spyOn(publisher, 'publishLater') | ||
|
||
vi.mock('@latitude-data/core/services/claimedRewards/claim', () => ({ | ||
claimReward: mocks.claimReward, | ||
|
@@ -83,6 +85,24 @@ describe('setupService', () => { | |
expect(createdProviderApiKey?.authorId).toBe(user.id) | ||
}) | ||
|
||
it('publishes userCreated event', async () => { | ||
const result = await setupService({ | ||
email: '[email protected]', | ||
name: 'Test User', | ||
companyName: 'Test Company', | ||
}) | ||
|
||
const user = result.value?.user! | ||
expect(publisherSpy).toHaveBeenCalledWith({ | ||
type: 'userCreated', | ||
data: { | ||
...user, | ||
userEmail: user.email, | ||
workspaceId: result.value?.workspace.id, | ||
}, | ||
}) | ||
}) | ||
|
||
it('should import the default project when calling setup service', async () => { | ||
const prompt = helpers.createPrompt({ | ||
provider: 'Latitude', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Result } from '@latitude-data/core/lib/Result' | ||
import { env } from '@latitude-data/env' | ||
import { LoopsClient } from 'loops' | ||
|
||
import { type UserCreatedEvent } from '../events' | ||
|
||
function getApiKey() { | ||
const apiKey = env.LOOPS_API_KEY | ||
|
||
if (apiKey === undefined) { | ||
throw new Error('LOOPS_API_KEY is not set') | ||
} | ||
|
||
return apiKey | ||
} | ||
|
||
export async function createLoopsContact({ | ||
data: event, | ||
}: { | ||
data: UserCreatedEvent | ||
}) { | ||
// In dev is an empty string | ||
const apiKey = getApiKey() | ||
if (apiKey === '') return Result.nil() | ||
|
||
const client = new LoopsClient(apiKey) | ||
const data = event.data | ||
const response = await client.createContact(data.userEmail, { | ||
userId: data.id, | ||
firstName: data.name, | ||
workspaceId: data.workspaceId, | ||
source: 'latitudeLlmAppSignup', | ||
userGroup: 'LLMs', | ||
subscribed: true, | ||
}) | ||
|
||
if (!response.success) { | ||
// This will be capture by Workers Sentry | ||
throw new Error(response.message) | ||
} | ||
|
||
return Result.ok(response.id) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.