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-52 #1979

Merged
merged 3 commits into from
Sep 1, 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,6 +1,17 @@
# Changelog


## v1.0.0-52


### 🏡 Chore

- Use openapi prefix for openapi endpoint ([2e00df1](https://github.com/undb-io/undb/commit/2e00df1))

### ❤️ Contributors

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

## v1.0.0-51


Expand Down
100 changes: 52 additions & 48 deletions apps/backend/src/modules/openapi/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class OpenAPI {

public route() {
const recordOpenapi = container.resolve(RecordOpenApi)
return new Elysia({ prefix: "/api/bases/:baseName/tables/:tableName" })
return new Elysia()
.onAfterResponse((ctx) => {
const requestId = executionContext.getStore()?.requestId
this.logger.info(
Expand All @@ -91,7 +91,7 @@ export class OpenAPI {
)
})
.get(
"/",
"/api/bases/:baseName/tables/:tableName",
async (ctx) => {
const spec = await this.getSpec(ctx.params.baseName, ctx.params.tableName)

Expand Down Expand Up @@ -128,52 +128,56 @@ export class OpenAPI {
},
},
)
.guard({
beforeHandle: async (context) => {
const apiToken =
context.headers[API_TOKEN_HEADER_NAME] ?? context.headers[API_TOKEN_HEADER_NAME.toLowerCase()]

this.logger.debug({ apiToken }, "Checking Authorization token in openapi")

if (apiToken) {
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)

return
}
} else {
const userId = getCurrentUserId()

if (userId) {
return
} else {
this.logger.error("No api token found in openapi")
}
}

// throw 401 openapi error
context.set.status = 401
throw new Error("Unauthorized")
},
})
.get(
"/openapi.json",
async (ctx) => {
const spec = await this.getSpec(ctx.params.baseName, ctx.params.tableName)
return spec
},
{
params: t.Object({ baseName: t.String(), tableName: t.String() }),
detail: {
tags: ["Doc"],
summary: "Get OpenAPI documentation json spec for a table",
description: "Get OpenAPI documentation json spec for a table",
},
},
.group("/openapi/bases/:baseName/tables/:tableName", (app) =>
app

.guard({
beforeHandle: async (context) => {
const apiToken =
context.headers[API_TOKEN_HEADER_NAME] ?? context.headers[API_TOKEN_HEADER_NAME.toLowerCase()]

this.logger.debug({ apiToken }, "Checking Authorization token in openapi")

if (apiToken) {
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)

return
}
} else {
const userId = getCurrentUserId()

if (userId) {
return
} else {
this.logger.error("No api token found in openapi")
}
}

// throw 401 openapi error
context.set.status = 401
throw new Error("Unauthorized")
},
})
.get(
"/openapi.json",
async (ctx) => {
const spec = await this.getSpec(ctx.params.baseName, ctx.params.tableName)
return spec
},
{
params: t.Object({ baseName: t.String(), tableName: t.String() }),
detail: {
tags: ["Doc"],
summary: "Get OpenAPI documentation json spec for a table",
description: "Get OpenAPI documentation json spec for a table",
},
},
)
.use(recordOpenapi.route()),
)
.use(recordOpenapi.route())
}
}
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-51",
"version": "1.0.0-52",
"private": true,
"scripts": {
"build": "NODE_ENV=production bun --bun turbo build",
Expand Down
12 changes: 12 additions & 0 deletions packages/i18n/src/i18n/i18n-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,12 @@ type RootTranslation = {
*/
viewer: string
}
macros: {
/**
* C​u​r​r​e​n​t​ ​U​s​e​r
*/
'@me': string
}
}
}

Expand Down Expand Up @@ -719,6 +725,12 @@ export type TranslationFunctions = {
*/
viewer: () => LocalizedString
}
macros: {
/**
* Current User
*/
'@me': () => LocalizedString
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/openapi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const createOpenApiSpec = (
version: "1.0.0",
title: table.name.value,
},
servers: [{ url: "/api" }],
servers: [{ url: "/openapi" }],
})
}

Expand Down
Loading