Skip to content

Commit

Permalink
feature: User invite workflow and magic links (#118)
Browse files Browse the repository at this point in the history
This commit implements user invitation workflow and magic links.
  • Loading branch information
geclos authored Aug 30, 2024
1 parent 2b2efbb commit 363af52
Show file tree
Hide file tree
Showing 205 changed files with 11,130 additions and 658 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/buildtest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test Builds

on:
pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x] # Specify node versions you want to test against

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 2 # Checkout HEAD^

- name: Build packages
run: docker compose --profile building build
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
run: pnpm install

- name: Use Turbo to build affected packages
run: pnpm turbo build --cache-dir=.turbo --filter="./packages/*"
run: pnpm turbo build --cache-dir=.turbo --filter="./packages/**"

- name: Prettier
run: pnpm prettier:check
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ node_modules
# Local env files
.env
.env.local
.env.development
.env.development.local
.env.test.local
.env.production.local
Expand Down
1 change: 1 addition & 0 deletions apps/gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@latitude-data/core": "workspace:^",
"@latitude-data/env": "workspace:^",
"@latitude-data/jobs": "workspace:^",
"@latitude-data/mailers": "workspace:^",
"@t3-oss/env-core": "^0.10.1",
"drizzle-orm": "^0.33.0",
"hono": "^4.5.3",
Expand Down
2 changes: 1 addition & 1 deletion apps/gateway/src/common/pipeToStream.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { streamToGenerator } from '@latitude-data/core'
import { streamToGenerator } from '@latitude-data/core/lib/streamToGenerator'
import { SSEStreamingApi } from 'hono/streaming'

export async function pipeToStream(
Expand Down
4 changes: 2 additions & 2 deletions apps/gateway/src/middlewares/auth.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { ApiKey, Workspace } from '@latitude-data/core/browser'
import {
unsafelyFindWorkspace,
unsafelyGetApiKeyByToken,
} from '@latitude-data/core'
import type { ApiKey, Workspace } from '@latitude-data/core/browser'
} from '@latitude-data/core/data-access'
import { bearerAuth } from 'hono/bearer-auth'

declare module 'hono' {
Expand Down
5 changes: 4 additions & 1 deletion apps/gateway/src/middlewares/errorHandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { LatitudeError, UnprocessableEntityError } from '@latitude-data/core'
import {
LatitudeError,
UnprocessableEntityError,
} from '@latitude-data/core/lib/errors'
import { createMiddleware } from 'hono/factory'

import HttpStatusCodes from '../common/httpStatusCodes'
Expand Down
22 changes: 13 additions & 9 deletions apps/gateway/src/routes/api/v1/chats/handlers/addMessage.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { apiKeys, database, Result } from '@latitude-data/core'
import {
ApiKey,
ChainEventTypes,
LogSources,
StreamEventTypes,
Workspace,
} from '@latitude-data/core/browser'
import { database } from '@latitude-data/core/client'
import { createProject } from '@latitude-data/core/factories'
import { Result } from '@latitude-data/core/lib/Result'
import { apiKeys } from '@latitude-data/core/schema'
import app from '$/routes/app'
import { eq } from 'drizzle-orm'
import { testConsumeStream } from 'test/helpers'
Expand Down Expand Up @@ -48,14 +50,17 @@ const mocks = vi.hoisted(() => ({
},
}))

vi.mock('@latitude-data/core', async (importOriginal) => {
const original = (await importOriginal()) as typeof importOriginal
vi.mock(
'@latitude-data/core/services/documentLogs/index',
async (importOriginal) => {
const original = (await importOriginal()) as typeof importOriginal

return {
...original,
addMessages: mocks.addMessages,
}
})
return {
...original,
addMessages: mocks.addMessages,
}
},
)

vi.mock('$/jobs', () => ({
queues: mocks.queues,
Expand Down Expand Up @@ -90,7 +95,6 @@ describe('POST /add-message', () => {
workspace = wsp
// TODO: move to core
const key = await database.query.apiKeys.findFirst({
// @ts-ignore
where: eq(apiKeys.workspaceId, workspace.id),
})
apiKey = key!
Expand Down
3 changes: 2 additions & 1 deletion apps/gateway/src/routes/api/v1/chats/handlers/addMessage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { zValidator } from '@hono/zod-validator'
import { addMessages, LogSources } from '@latitude-data/core'
import { LogSources } from '@latitude-data/core/browser'
import { addMessages } from '@latitude-data/core/services/documentLogs/index'
import { messageSchema } from '$/common/messageSchema'
import { pipeToStream } from '$/common/pipeToStream'
import { queues } from '$/jobs'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Workspace } from '@latitude-data/core/browser'
import {
CommitsRepository,
DocumentVersionsRepository,
ProjectsRepository,
} from '@latitude-data/core'
import type { Workspace } from '@latitude-data/core/browser'
} from '@latitude-data/core/repositories'

export const getData = async ({
workspace,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import {
apiKeys,
database,
DocumentVersionsRepository,
mergeCommit,
} from '@latitude-data/core'
import { database } from '@latitude-data/core/client'
import {
createDocumentVersion,
createDraft,
createProject,
} from '@latitude-data/core/factories'
import { DocumentVersionsRepository } from '@latitude-data/core/repositories'
import { apiKeys } from '@latitude-data/core/schema'
import { mergeCommit } from '@latitude-data/core/services/commits/merge'
import app from '$/routes/app'
import { eq } from 'drizzle-orm'
import { describe, expect, it, vi } from 'vitest'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { apiKeys, database, mergeCommit, Result } from '@latitude-data/core'
import {
ChainEventTypes,
Commit,
Expand All @@ -7,11 +6,15 @@ import {
StreamEventTypes,
Workspace,
} from '@latitude-data/core/browser'
import { database } from '@latitude-data/core/client'
import {
createDocumentVersion,
createDraft,
createProject,
} from '@latitude-data/core/factories'
import { Result } from '@latitude-data/core/lib/Result'
import { apiKeys } from '@latitude-data/core/schema'
import { mergeCommit } from '@latitude-data/core/services/commits/merge'
import app from '$/routes/app'
import { eq } from 'drizzle-orm'
import { testConsumeStream } from 'test/helpers'
Expand All @@ -29,14 +32,17 @@ const mocks = vi.hoisted(() => ({
},
}))

vi.mock('@latitude-data/core', async (importOriginal) => {
const original = (await importOriginal()) as typeof importOriginal
vi.mock(
'@latitude-data/core/services/commits/runDocumentAtCommit',
async (importOriginal) => {
const original = (await importOriginal()) as typeof importOriginal

return {
...original,
runDocumentAtCommit: mocks.runDocumentAtCommit,
}
})
return {
...original,
runDocumentAtCommit: mocks.runDocumentAtCommit,
}
},
)

vi.mock('$/jobs', () => ({
queues: mocks.queues,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { zValidator } from '@hono/zod-validator'
import { LogSources, runDocumentAtCommit } from '@latitude-data/core'
import { LogSources } from '@latitude-data/core/browser'
import { runDocumentAtCommit } from '@latitude-data/core/services/commits/runDocumentAtCommit'
import { pipeToStream } from '$/common/pipeToStream'
import { queues } from '$/jobs'
import { Factory } from 'hono/factory'
Expand Down Expand Up @@ -41,8 +42,7 @@ export const runHandler = factory.createHandlers(
commit,
parameters,
providerLogHandler: (log) => {
// TODO: review why this is possibly undefined now
queues.defaultQueue.jobs.enqueueCreateProviderLogJob!({
queues.defaultQueue.jobs.enqueueCreateProviderLogJob({
...log,
source,
apiKeyId: apiKey.id,
Expand All @@ -52,8 +52,7 @@ export const runHandler = factory.createHandlers(

await pipeToStream(stream, result.stream)

// TODO: review why this is possibly undefined now
queues.defaultQueue.jobs.enqueueCreateDocumentLogJob!({
queues.defaultQueue.jobs.enqueueCreateDocumentLogJob({
commit,
data: {
uuid: result.documentLogUuid,
Expand Down
9 changes: 7 additions & 2 deletions apps/gateway/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
"$/*": ["./src/*"],
"acorn": ["node_modules/@latitude-data/typescript-config/types/acorn"]
},
"types": ["node"]
"types": ["node"],
"jsx": "preserve"
},
"include": ["src/**/*.ts", "test/**/*.ts"],
"include": [
"src/**/*.ts",
"src/**/*.test.ts",
"test/**/*.ts"
],
"exclude": ["node_modules"]
}
1 change: 1 addition & 0 deletions apps/gateway/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ export default defineConfig({
'@latitude-data/env',
'@latitude-data/core',
'@latitude-data/jobs',
'@latitude-data/mailers',
],
})
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@latitude-data/core": "workspace:*",
"@latitude-data/env": "workspace:^",
"@latitude-data/jobs": "workspace:*",
"@latitude-data/mailers": "workspace:^",
"@latitude-data/sdk-js": "workspace:*",
"@latitude-data/web-ui": "workspace:*",
"@lucia-auth/adapter-drizzle": "^1.0.7",
Expand Down
Binary file added apps/web/public/logodark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion apps/web/src/actions/commits/create.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use server'

import { createCommit } from '@latitude-data/core'
import { createCommit } from '@latitude-data/core/services/commits/create'
import { z } from 'zod'

import { withProject } from '../procedures'
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/actions/commits/deleteDraftCommit.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { database } from '@latitude-data/core'
import type {
Commit,
Project,
SafeUser,
Workspace,
} from '@latitude-data/core/browser'
import { database } from '@latitude-data/core/client'
import * as factories from '@latitude-data/core/factories'
import { deleteDraftCommitAction } from '$/actions/commits/deleteDraftCommitAction'
import { beforeEach, describe, expect, it, vi } from 'vitest'
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/actions/commits/deleteDraftCommitAction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use server'

import { CommitsRepository, deleteCommitDraft } from '@latitude-data/core'
import { CommitsRepository } from '@latitude-data/core/repositories'
import { deleteCommitDraft } from '@latitude-data/core/services/commits/delete'
import { z } from 'zod'

import { withProject } from '../procedures'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CommitStatus } from '@latitude-data/core'
import type { Workspace } from '@latitude-data/core/browser'
import { CommitStatus, type Workspace } from '@latitude-data/core/browser'
import * as factories from '@latitude-data/core/factories'
import { beforeEach, describe, expect, it, vi } from 'vitest'

Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/actions/commits/fetchCommitsByProjectAction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use server'

import { CommitsRepository, CommitStatus } from '@latitude-data/core'
import { CommitStatus } from '@latitude-data/core/browser'
import { CommitsRepository } from '@latitude-data/core/repositories'
import { z } from 'zod'

import { withProject } from '../procedures'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use server'

import { CommitsRepository } from '@latitude-data/core'
import { CommitsRepository } from '@latitude-data/core/repositories'
import { z } from 'zod'

import { withProject } from '../procedures'
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/actions/commits/publishDraftCommit.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { updateDocument } from '@latitude-data/core'
import type {
Commit,
DocumentVersion,
Expand All @@ -7,6 +6,7 @@ import type {
Workspace,
} from '@latitude-data/core/browser'
import * as factories from '@latitude-data/core/factories'
import { updateDocument } from '@latitude-data/core/services/documents/update'
import { publishDraftCommitAction } from '$/actions/commits/publishDraftCommitAction'
import { beforeEach, describe, expect, it, vi } from 'vitest'

Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/actions/commits/publishDraftCommitAction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use server'

import { CommitsRepository, mergeCommit } from '@latitude-data/core'
import { CommitsRepository } from '@latitude-data/core/repositories'
import { mergeCommit } from '@latitude-data/core/services/commits/merge'
import { z } from 'zod'

import { withProject } from '../procedures'
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/actions/documents/create.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use server'

import { CommitsRepository, createNewDocument } from '@latitude-data/core'
import { CommitsRepository } from '@latitude-data/core/repositories'
import { createNewDocument } from '@latitude-data/core/services/documents/create'
import { z } from 'zod'

import { withProject } from '../procedures'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { database, documentVersions } from '@latitude-data/core'
import {
Commit,
DocumentVersion,
Project,
SafeUser,
} from '@latitude-data/core/browser'
import { database } from '@latitude-data/core/client'
import { createDraft, createProject } from '@latitude-data/core/factories'
import { documentVersions } from '@latitude-data/core/schema'
import { and, eq } from 'drizzle-orm'
import { beforeEach, describe, expect, it, vi } from 'vitest'

Expand Down Expand Up @@ -94,6 +95,7 @@ describe('destroyDocumentAction', async () => {
})
// TODO: move to core
const documents = await database.query.documentVersions.findMany({
// @ts-ignore
where: and(eq(documentVersions.documentUuid, document.documentUuid)),
})

Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/actions/documents/destroyDocumentAction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import {
CommitsRepository,
destroyDocument,
DocumentVersionsRepository,
} from '@latitude-data/core'
} from '@latitude-data/core/repositories'
import { destroyDocument } from '@latitude-data/core/services/documents/destroyDocument'
import { withProject } from '$/actions/procedures'
import { z } from 'zod'

Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/actions/documents/destroyFolderAction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use server'

import { CommitsRepository, destroyFolder } from '@latitude-data/core'
import { CommitsRepository } from '@latitude-data/core/repositories'
import { destroyFolder } from '@latitude-data/core/services/documents/destroyFolder'
import { z } from 'zod'

import { withProject } from '../procedures'
Expand Down
Loading

0 comments on commit 363af52

Please sign in to comment.