Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release version v1.0.0-133 #2177

Merged
merged 12 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## v1.0.0-133


### 🩹 Fixes

- Fix oauth ([224922e](https://github.com/undb-io/undb/commit/224922e))

### ❤️ Contributors

- Nichenqin ([@nichenqin](http://github.com/nichenqin))

## v1.0.0-132


Expand Down
199 changes: 199 additions & 0 deletions apps/backend/migrations/deployment.json

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions apps/backend/src/modules/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "@undb/authz"
import { AcceptInvitationCommand } from "@undb/commands"
import type { ContextMember } from "@undb/context"
import { type IContext, injectContext } from "@undb/context"
import { executionContext, setContextValue } from "@undb/context/server"
import { CommandBus } from "@undb/cqrs"
import { container, inject, singleton } from "@undb/di"
Expand Down Expand Up @@ -53,6 +54,8 @@ export class Auth {
private readonly lucia: Lucia,
@injectTxCTX()
private readonly txContext: ITxContext,
@injectContext()
private readonly context: IContext,
) {}

async #generateEmailVerificationCode(userId: string, email: string): Promise<string> {
Expand Down Expand Up @@ -150,10 +153,10 @@ export class Auth {

const userId = user?.id!
const spaceId = session?.spaceId
const space = await this.spaceService.setSpaceContext(setContextValue, { spaceId })
const space = await this.spaceService.setSpaceContext(this.context, { spaceId })

const member = space
? (await this.spaceMemberService.setSpaceMemberContext(setContextValue, space.id.value, userId))
? (await this.spaceMemberService.setSpaceMemberContext(this.context, space.id.value, userId))
.into(null)
?.toJSON()
: undefined
Expand Down
3 changes: 2 additions & 1 deletion apps/backend/src/modules/auth/oauth/github.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export const GITHUB_PROVIDER = Symbol.for("GITHUB_PROVIDER")

container.register(GITHUB_PROVIDER, {
useFactory: instanceCachingFactory(() => {
return new GitHub(env.GITHUB_CLIENT_ID!, env.GITHUB_CLIENT_SECRET!)
const redirectURL = new URL("/login/github/callback", env.UNDB_BASE_URL)
return new GitHub(env.GITHUB_CLIENT_ID!, env.GITHUB_CLIENT_SECRET!, redirectURL.toString())
}),
})

Expand Down
7 changes: 5 additions & 2 deletions apps/backend/src/modules/auth/oauth/github.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type ISpaceMemberService, injectSpaceMemberService } from "@undb/authz"
import { type IContext, injectContext } from "@undb/context"
import { setContextValue } from "@undb/context/server"
import { singleton } from "@undb/di"
import { createLogger } from "@undb/logger"
Expand Down Expand Up @@ -27,6 +28,8 @@ export class GithubOAuth {
private readonly lucia: Lucia,
@injectTxCTX()
private readonly txContext: ITxContext,
@injectContext()
private readonly context: IContext,
) {}

private logger = createLogger(GithubOAuth.name)
Expand Down Expand Up @@ -67,7 +70,7 @@ export class GithubOAuth {
const tokens = await this.github.validateAuthorizationCode(code)
const githubUserResponse = await fetch("https://api.github.com/user", {
headers: {
Authorization: `Bearer ${tokens.accessToken}`,
Authorization: `Bearer ${tokens.accessToken()}`,
},
})
const githubUserResult: GitHubUserResult = await githubUserResponse.json()
Expand Down Expand Up @@ -122,7 +125,7 @@ export class GithubOAuth {
.executeTakeFirst()

if (existingGithubUser) {
const space = await this.spaceService.setSpaceContext(setContextValue, { userId: existingGithubUser.id })
const space = await this.spaceService.setSpaceContext(this.context, { userId: existingGithubUser.id })

await this.queryBuilder
.insertInto("undb_oauth_account")
Expand Down
7 changes: 5 additions & 2 deletions apps/backend/src/modules/auth/oauth/google.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type ISpaceMemberService, injectSpaceMemberService } from "@undb/authz"
import { type IContext, injectContext } from "@undb/context"
import { setContextValue } from "@undb/context/server"
import { singleton } from "@undb/di"
import { createLogger } from "@undb/logger"
Expand Down Expand Up @@ -27,6 +28,8 @@ export class GoogleOAuth {
private readonly lucia: Lucia,
@injectTxCTX()
private readonly txContext: ITxContext,
@injectContext()
private readonly context: IContext,
) {}

private logger = createLogger(GoogleOAuth.name)
Expand Down Expand Up @@ -75,7 +78,7 @@ export class GoogleOAuth {
const tokens = await this.google.validateAuthorizationCode(code, storedCodeVerifier)
const googleUserResponse = await fetch("https://www.googleapis.com/oauth2/v1/userinfo", {
headers: {
Authorization: `Bearer ${tokens.accessToken}`,
Authorization: `Bearer ${tokens.accessToken()}`,
},
})
const googleUserResult: GoogleUserResult = await googleUserResponse.json()
Expand Down Expand Up @@ -110,7 +113,7 @@ export class GoogleOAuth {
.executeTakeFirst()

if (existingGoogleUser) {
const space = await this.spaceService.setSpaceContext(setContextValue, { userId: existingGoogleUser.id })
const space = await this.spaceService.setSpaceContext(this.context, { userId: existingGoogleUser.id })

await this.queryBuilder
.insertInto("undb_oauth_account")
Expand Down
6 changes: 3 additions & 3 deletions apps/backend/src/modules/openapi/openapi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { injectSpaceMemberService, type ISpaceMemberService } from "@undb/authz"
import { type IBaseRepository, injectBaseRepository } from "@undb/base"
import { type IContext, injectContext } from "@undb/context"
import { executionContext, setContextValue } from "@undb/context/server"
import { executionContext } from "@undb/context/server"
import { container, singleton } from "@undb/di"
import { Some } from "@undb/domain"
import { createLogger } from "@undb/logger"
Expand Down Expand Up @@ -146,8 +146,8 @@ export class OpenAPI {
const userId = await this.apiTokenService.verify(apiToken)
if (userId.isSome()) {
const user = (await this.userService.findOneById(userId.unwrap())).unwrap()
const space = await this.spaceService.setSpaceContext(setContextValue, { apiToken })
await this.spaceMemberService.setSpaceMemberContext(setContextValue, space.id.value, user.id)
const space = await this.spaceService.setSpaceContext(this.context, { apiToken })
await this.spaceMemberService.setSpaceMemberContext(this.context, space.id.value, user.id)

return
}
Expand Down
3 changes: 3 additions & 0 deletions apps/frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ module.exports = {
sourceType: "module",
ecmaVersion: 2020,
extraFileExtensions: [".svelte"],
ecmaFeatures: {
experimentalDecorators: true,
},
},
env: {
browser: true,
Expand Down
6 changes: 6 additions & 0 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@
"@typescript-eslint/eslint-plugin": "^8.16.0",
"@typescript-eslint/parser": "^8.16.0",
"@undb/commands": "workspace:*",
"@undb/command-handlers": "workspace:*",
"@undb/query-handlers": "workspace:*",
"@undb/domain": "workspace:*",
"@undb/formula": "workspace:*",
"@undb/i18n": "workspace:*",
"@undb/di": "workspace:*",
"@undb/data-service": "workspace:*",
"@undb/openapi": "workspace:*",
"@undb/queries": "workspace:*",
"@undb/share": "workspace:*",
"@undb/table": "workspace:*",
"@undb/template": "workspace:*",
"@undb/persistence": "workspace:*",
"@undb/trpc": "workspace:*",
"@undb/utils": "workspace:*",
"array-move": "^4.0.0",
Expand Down Expand Up @@ -105,6 +110,7 @@
"lucide-svelte": "^0.462.0",
"mode-watcher": "^0.5.0",
"paneforge": "^0.0.6",
"reflect-metadata": "^0.2.2",
"svelte-grid": "^5.1.2",
"svelte-qrcode": "^1.0.1",
"svelte-radix": "^2.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</script>

{#if $hasPermission("record:update")}
<Sheet.Root bind:open>
<Sheet.Root bind:open portal="body">
<Sheet.Trigger asChild let:builder>
<Button size="sm" variant="outline" builders={[builder]}>
<PencilIcon class="mr-2 h-3 w-3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import { CREATE_RECORD_MODAL, openModal } from "$lib/store/modal.store"
import { tick } from "svelte"
import { hasPermission } from "$lib/store/space-member.store"
import { getIsLocal, getDataService } from "$lib/store/data-service.store"

export let viewId: Readable<string | undefined>
export let view: CalendarView
Expand Down Expand Up @@ -103,13 +104,16 @@
const t = getTable()
const q = queryParam("q")

const isLocal = getIsLocal()

const getRecords = createQuery(
derived([t, viewId, q, date], ([$table, $viewId, $q, $date]) => {
const view = $table.views.getViewById($viewId)
return {
queryKey: ["records", $table?.id.value, $viewId, $q, $date.toISOString()],
enabled: view?.type === "calendar" && !disableRecordQuery,
queryFn: () => {
queryFn: async () => {
const dataService = await getDataService(isLocal)
const value = format($date, "yyyy-MM-dd")
if (shareId) {
return trpc.shareData.records.query({
Expand All @@ -123,7 +127,7 @@
},
})
}
return trpc.record.list.query({
return dataService.records.getRecords({
tableId: $table?.id.value,
viewId: $viewId,
filters: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<script lang="ts">
import {
getConditionGroupCount,
mergeConditionGroups,
type DateField,
type DateRangeField,
} from "@undb/table"
import { getConditionGroupCount, mergeConditionGroups, type DateField, type DateRangeField } from "@undb/table"
import { createInfiniteQuery, type CreateInfiniteQueryOptions } from "@tanstack/svelte-query"
import CalendarViewMonthRecordsFilterPicker from "./calendar-view-month-records-filter-picker.svelte"
import { derived, type Writable } from "svelte/store"
Expand All @@ -23,8 +18,9 @@
import { inview } from "svelte-inview"
import { LoaderCircleIcon } from "lucide-svelte"
import { CalendarView } from "@undb/table"
import { type MaybeConditionGroup, type IViewFilterOptionSchema } from "@undb/table"
import { type MaybeConditionGroup, type IViewFilterOptionSchema } from "@undb/table"
import { LL } from "@undb/i18n/client"
import { getIsLocal, getDataService } from "$lib/store/data-service.store"

export let viewId: Readable<string | undefined>
export let view: CalendarView
Expand All @@ -34,6 +30,7 @@
export let readonly = false

const t = getTable()
const isLocal = getIsLocal()

let defaultField = $t.schema.getDefaultDisplayField().into(undefined)

Expand Down Expand Up @@ -102,7 +99,8 @@
.otherwise(() => undefined)
return {
queryKey: ["records", $table?.id.value, $viewId, $scope, dateString, $search],
queryFn: ({ pageParam = 1 }) => {
queryFn: async ({ pageParam = 1 }) => {
const dataService = await getDataService(isLocal)
if (shareId) {
return trpc.shareData.records.query({
shareId,
Expand All @@ -117,7 +115,7 @@
},
})
}
return trpc.record.list.query({
return dataService.records.getRecords({
tableId: $table?.id.value,
viewId: $viewId,
filters: merged,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import CalendarViewMiniMonth from "./calendar-view-mini-month.svelte"
import CalendarViewMonthRecords from "./calendar-view-month-records.svelte"
import CalendarViewMonthDate from "./calendar-view-month-date.svelte"
import { getIsLocal, getDataService } from "$lib/store/data-service.store"

export let viewId: Readable<string | undefined>
export let view: CalendarView
Expand All @@ -26,6 +27,7 @@

const t = getTable()
const q = queryParam("q")
const isLocal = getIsLocal()

const getRecords = createQuery(
derived([t, viewId, q, startTimestamp, endTimestamp], ([$table, $viewId, $q, $startTimestamp, $endTimestamp]) => {
Expand All @@ -40,7 +42,8 @@
$endTimestamp?.toISOString(),
],
enabled: view?.type === "calendar" && !!$startTimestamp && !!$endTimestamp && !disableRecordQuery,
queryFn: () => {
queryFn: async () => {
const dataService = await getDataService(isLocal)
if (shareId) {
return trpc.shareData.records.query({
shareId,
Expand All @@ -56,7 +59,7 @@
},
})
}
return trpc.record.list.query({
return dataService.records.getRecords({
tableId: $table?.id.value,
viewId: $viewId,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import type { ICreateRecordCommandOutput } from "@undb/commands"
import { onMount } from "svelte"
import { LL } from "@undb/i18n/client"
import { getIsLocal } from "$lib/store/data-service.store"

// beforeNavigate(({ cancel }) => {
// if ($tainted) {
Expand All @@ -40,6 +41,7 @@
const client = useQueryClient()

const mediaQuery = useMediaQuery("(max-width: 768px)")
const isLocal = getIsLocal()

const createRecordMutation = createMutation(
derived([table], ([$table]) => ({
Expand All @@ -51,7 +53,7 @@
})
toast.success($LL.table.record.createdRecord())
onSuccess?.(data)
recordsStore?.invalidateRecord($table, data)
recordsStore?.invalidateRecord(isLocal, $table, data)
},
onError: (error: Error) => {
toast.error(error.message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { getTable } from "$lib/store/table.store"
import { gridViewStore } from "../grid-view/grid-view.store"
import { getRecordsStore } from "$lib/store/records.store"
import { getIsLocal } from "$lib/store/data-service.store"

export let tableId: string
export let field: ButtonField
Expand All @@ -19,12 +20,14 @@
const client = useQueryClient()
const recordsStore = getRecordsStore()

const isLocal = getIsLocal()

const updateCell = createMutation({
mutationKey: ["record", tableId, field.id.value, recordId],
mutationFn: trpc.record.update.mutate,
async onSuccess(data, variables, context) {
gridViewStore.exitEditing()
await recordsStore?.invalidateRecord($table, recordId)
await recordsStore?.invalidateRecord(isLocal, $table, recordId)
await client.invalidateQueries({ queryKey: [recordId, "get"] })
},
onError(error: Error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</Button>
{/if}
</ForeignRecordsPickerDropdown>
{#if hasValueReactive}
{#if hasValueReactive && !readonly}
<ForeignRecordsPickerDropdown
{onValueChange}
{r}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import { cn } from "$lib/utils"
import GalleryViewLoading from "./gallery-view-loading.svelte"
import GalleryViewOptionButton from "./gallery-option-button.svelte"
import { getIsLocal, getDataService } from "$lib/store/data-service.store"

const table = getTable()
export let viewId: Readable<string | undefined>
Expand All @@ -29,8 +30,9 @@
const perPage = writable(50)
const currentPage = writable(1)
const q = queryParam("q")
const isLocal = getIsLocal()

const getRecords = () => {
const getRecords = async () => {
if (shareId) {
return trpc.shareData.records.query({
shareId,
Expand All @@ -40,7 +42,8 @@
pagination: { limit: $perPage, page: $currentPage },
})
}
return trpc.record.list.query({
const dataService = await getDataService(isLocal)
return dataService.records.getRecords({
tableId: $table?.id.value,
viewId: $viewId,
q: $q ?? undefined,
Expand Down
Loading
Loading