Skip to content

Commit

Permalink
Merge pull request #2161 from undb-io/release/v1.0.0-127
Browse files Browse the repository at this point in the history
Release version v1.0.0-127
  • Loading branch information
nichenqin authored Nov 24, 2024
2 parents 6f0af02 + 51a7c95 commit 59ebe02
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 64 deletions.
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-127


### 🏡 Chore

- Add logging ([8decb41](https://github.com/undb-io/undb/commit/8decb41))

### ❤️ Contributors

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

## v1.0.0-126


Expand Down
8 changes: 6 additions & 2 deletions apps/backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ const openapi = container.resolve(OpenAPI)
const opentelemetry = container.resolve(OpenTelemetryModule)
const template = container.resolve(TemplateModule)

const logger = createLogger("app")

export const app = new Elysia()
.onStart(async () => {
.on("start", async () => {
logger.info("db migrate start")
await dbMigrate()
logger.info("db migrate done")
await auth.onStart()
})
.use(opentelemetry.plugin())
.use(loggerPlugin())
Expand All @@ -64,7 +69,6 @@ export const app = new Elysia()
set.headers["Server-Timing"] = `handle;dur=${(await end) - begin}`
})
.onStart(async () => {
const logger = createLogger("app onstart")
const pubsub = container.resolve(PubSubContext)
const webhookEventHandler = container.resolve(WebhookEventsHandler)
// const auditEventHandler = container.resolve(AuditEventHandler)
Expand Down
100 changes: 51 additions & 49 deletions apps/backend/src/modules/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,62 +173,64 @@ export class Auth {
}
}

route() {
const oauth = container.resolve(OAuth)
return new Elysia()
.use(oauth.route())
.onStart(async (ctx) => {
const adminEmail = env.UNDB_ADMIN_EMAIL
const adminPassword = env.UNDB_ADMIN_PASSWORD
if (env.UNDB_DISABLE_REGISTRATION) {
this.logger.info("Registration is disabled")
if (!adminEmail || !adminPassword) {
const message =
"Registration is disabled but admin user is not set, please set UNDB_ADMIN_EMAIL and UNDB_ADMIN_PASSWORD environment variables"
this.logger.fatal(message)
throw new Error(message)
}
async onStart() {
const adminEmail = env.UNDB_ADMIN_EMAIL
const adminPassword = env.UNDB_ADMIN_PASSWORD
if (env.UNDB_DISABLE_REGISTRATION) {
this.logger.info("Registration is disabled")
if (!adminEmail || !adminPassword) {
const message =
"Registration is disabled but admin user is not set, please set UNDB_ADMIN_EMAIL and UNDB_ADMIN_PASSWORD environment variables"
this.logger.fatal(message)
throw new Error(message)
}

const user = await this.queryBuilder
.selectFrom("undb_user")
.selectAll()
.where((eb) => eb.eb("email", "=", adminEmail))
.executeTakeFirst()
const user = await this.queryBuilder
.selectFrom("undb_user")
.selectAll()
.where((eb) => eb.eb("email", "=", adminEmail))
.executeTakeFirst()

if (!user) {
const userId = generateIdFromEntropySize(10) // 16 characters long
const passwordHash = await Bun.password.hash(adminPassword)
const username = getUsernameFromEmail(adminEmail)
if (!user) {
this.logger.info("Admin user not found, creating...")
const userId = generateIdFromEntropySize(10) // 16 characters long
const passwordHash = await Bun.password.hash(adminPassword)
const username = getUsernameFromEmail(adminEmail)

executionContext.enterWith({
requestId: v7(),
user: {
userId,
username,
email: adminEmail,
},
})

executionContext.enterWith({
requestId: v7(),
user: {
userId,
username,
email: adminEmail,
},
await withTransaction(this.queryBuilder)(async () => {
await getCurrentTransaction()
.insertInto("undb_user")
.values({
email: adminEmail,
username: username!,
id: userId,
password: passwordHash,
email_verified: true,
})
.execute()

await withTransaction(this.queryBuilder)(async () => {
await getCurrentTransaction()
.insertInto("undb_user")
.values({
email: adminEmail,
username: username!,
id: userId,
password: passwordHash,
email_verified: true,
})
.execute()
const space = await this.spaceService.createSpace({ name: username! })
await this.spaceMemberService.createMember(userId, space.id.value, "owner")

const space = await this.spaceService.createSpace({ name: username! })
await this.spaceMemberService.createMember(userId, space.id.value, "owner")
this.logger.info("Admin user created")
})
}
}
}

this.logger.info("Admin user created")
})
}
}
})
route() {
const oauth = container.resolve(OAuth)
return new Elysia()
.use(oauth.route())
.onAfterResponse((ctx) => {
const requestId = executionContext.getStore()?.requestId
this.logger.info(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { Button } from "$lib/components/ui/button"
import Separator from "$lib/components/ui/separator/separator.svelte"
import { writable } from "svelte/store"
import type { ZodUndefined } from "@undb/zod"
import { Switch } from "$lib/components/ui/switch"
import FiltersEditor from "../filters-editor/filters-editor.svelte"
import { onMount, tick } from "svelte"
Expand All @@ -40,15 +40,18 @@
confirm: true,
},
}
const value = writable<MaybeConditionGroup<ZodUndefined> | undefined>()
const value = writable<MaybeConditionGroup<any> | undefined>()
$: validValue = $table && $value ? parseValidViewFilter($table.schema, $value) : undefined
$: if (validValue) {
option.disabled = validValue
}
let disabledWhen = false
onMount(() => {
if (option.disabled) {
value.set(toMaybeConditionGroup(option.disabled))
disabledWhen = true
}
})
Expand All @@ -63,14 +66,19 @@
<Label for="label">Label</Label>
<Input class="w-full" placeholder="Button" id="label" bind:value={option.label} />

<div class="space-y-2 rounded-sm border pt-2">
<Label class="pl-4 text-xs font-semibold" for="disabled">Disabled When...</Label>
<FiltersEditor
bind:value={$value}
table={$table}
filter={(field) => visibleFields.some((f) => f.id.value === field.id) && getIsFilterableFieldType(field.type)}
></FiltersEditor>
</div>
<Label class="flex items-center gap-2 text-xs font-semibold" for="disabled">
<Switch id="disabled" bind:checked={disabledWhen} size="sm" />
Disabled When...
</Label>
{#if disabledWhen}
<div class="space-y-2 rounded-sm border pt-2">
<FiltersEditor
bind:value={$value}
table={$table}
filter={(field) => visibleFields.some((f) => f.id.value === field.id) && getIsFilterableFieldType(field.type)}
></FiltersEditor>
</div>
{/if}

<div class="space-y-2 rounded-md border px-4 py-3">
<p class="text-xs font-semibold">Update Value when Click Button</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
export let disabled = false
export let type: NoneSystemFieldType
const map: Record<NoneSystemFieldType, ComponentType> = {
string: StringFieldOption,
longText: LongTextFieldOption,
Expand Down Expand Up @@ -67,4 +66,5 @@
bind:option
{isNew}
{field}
{...$$restProps}
/>
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
bind:constraint={$formData.constraint}
bind:display={$formData.display}
bind:defaultValue={$formData.defaultValue}
{...attrs}
/>
</Form.Control>
<Form.Description />
Expand Down
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "undb",
"version": "1.0.0-126",
"version": "1.0.0-127",
"private": true,
"scripts": {
"build": "NODE_ENV=production bun --bun turbo build",
Expand Down
4 changes: 4 additions & 0 deletions packages/authz/src/space-member/space-member.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { inject, singleton } from "@undb/di"
import { and, None, Option } from "@undb/domain"
import { createLogger } from "@undb/logger"
import { injectSpaceService, type ISpaceId, type ISpaceService } from "@undb/space"
import type { SetContextValue } from "../../../context/src/context.type"
import { MemberIdVO } from "../member/member-id.vo"
Expand Down Expand Up @@ -32,6 +33,7 @@ export const injectSpaceMemberService = () => inject(SPACE_MEMBER_SERVICE)

@singleton()
export class SpaceMemberService implements ISpaceMemberService {
private logger = createLogger("SpaceMemberService")
constructor(
@injectSpaceService()
private readonly spaceService: ISpaceService,
Expand Down Expand Up @@ -110,6 +112,8 @@ export class SpaceMemberService implements ISpaceMemberService {
spaceId: ISpaceId,
userId: string,
): Promise<Option<SpaceMember>> {
this.logger.debug({ spaceId, userId }, "setSpaceMemberContext")

if (!spaceId || !userId) {
return None
}
Expand Down
1 change: 1 addition & 0 deletions packages/space/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"types": "src/index.d.ts",
"dependencies": {
"@undb/context": "workspace:*",
"@undb/logger": "workspace:*",
"ts-pattern": "^5.5.0"
},
"devDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions packages/space/src/space.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { SetContextValue } from "@undb/context"
import { inject, singleton } from "@undb/di"
import { createLogger } from "@undb/logger"
import { None, Option, Some } from "oxide.ts"
import { match, P } from "ts-pattern"
import type { ICreateSpaceDTO, ISpaceDTO } from "./dto"
Expand Down Expand Up @@ -37,6 +38,7 @@ export const injectSpaceService = () => inject(SPACE_SERVICE)

@singleton()
export class SpaceService implements ISpaceService {
private logger = createLogger("SpaceService")
constructor(
@injectSpaceRepository()
private readonly spaceRepository: ISpaceRepository,
Expand Down Expand Up @@ -86,6 +88,7 @@ export class SpaceService implements ISpaceService {
}

async setSpaceContext(setContext: SetContextValue, input: IGetSpaceInput): Promise<Space> {
this.logger.debug(input, "setSpaceContext")
const space = await this.getSpace(input)
setContext("spaceId", space.unwrap().id.value)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const buttonFieldUpdateAction = z.object({
confirm: z.boolean().optional(),
})

const buttonCondition = z.undefined()
const buttonCondition = z.any()

export const buttonDisabled = createConditionGroup(buttonCondition, buttonCondition)
export type IButtonDisabled = z.infer<typeof buttonDisabled>
Expand Down

0 comments on commit 59ebe02

Please sign in to comment.