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

feat(server): add metered billing module, remove subscription module, discard Prisma #1187

Merged
merged 57 commits into from
May 29, 2023
Merged
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
19acb20
design metering schema
maslow May 9, 2023
c85d99e
Merge remote-tracking branch 'upstream/main' into design-metering
maslow May 10, 2023
f65e737
Merge remote-tracking branch 'upstream/main' into design-metering
maslow May 12, 2023
e87187a
Merge remote-tracking branch 'upstream/main' into design-metering
maslow May 14, 2023
ef434e7
add region bundle schema
maslow May 14, 2023
bc36980
remove prisma in some modules
maslow May 16, 2023
e7f360d
remove prisma in gateway, website, storage
maslow May 16, 2023
d3b6888
remove prisma in dependency module
maslow May 16, 2023
45c0dd3
remove prisma in account module
maslow May 17, 2023
29ee47b
remove prisma in instance module
maslow May 17, 2023
7bc52d4
remove prisma in auth and user module
maslow May 17, 2023
54550c8
remove prisma in function and trigger module
maslow May 17, 2023
5076425
remove prisma totally
maslow May 17, 2023
9f5b31d
Merge remote-tracking branch 'upstream/main' into design-metering
maslow May 17, 2023
398c3a1
add resource option & template api
maslow May 19, 2023
a2dc9db
rename resource template to bundle
maslow May 19, 2023
fec7757
design metering schema
maslow May 9, 2023
1f51402
add region bundle schema
maslow May 14, 2023
393eda0
remove prisma in some modules
maslow May 16, 2023
52d926d
remove prisma in gateway, website, storage
maslow May 16, 2023
1f51c57
remove prisma in dependency module
maslow May 16, 2023
5938807
remove prisma in account module
maslow May 17, 2023
7e3fbf6
remove prisma in instance module
maslow May 17, 2023
e65b211
remove prisma in auth and user module
maslow May 17, 2023
cba015c
remove prisma in function and trigger module
maslow May 17, 2023
2d2a116
remove prisma totally
maslow May 17, 2023
2093afb
add resource option & template api
maslow May 19, 2023
b3a7d95
rename resource template to bundle
maslow May 19, 2023
10e8d6f
Merge remote-tracking branch 'upstream/metering' into design-metering
maslow May 22, 2023
935c7b2
add billing module & price calculation api
maslow May 23, 2023
1f23d43
add response api typings
maslow May 23, 2023
9130c52
Design metering (#1169)
maslow May 23, 2023
cdfeee4
update app bundle api
maslow May 24, 2023
1238998
impl billing task
maslow May 24, 2023
b6bf134
feat(server): add application billings http api
maslow May 24, 2023
e3f5886
impl billing payment task
maslow May 25, 2023
c415158
restart app while updating bundle
maslow May 25, 2023
5e045ff
update user profile api
maslow May 25, 2023
2f1cb16
fix account api response body
maslow May 26, 2023
1f7d298
feat(web): new metering design (#1171)
LeezQ May 26, 2023
cd72e16
add pagination response decoration
maslow May 26, 2023
34b1f35
feat(web): metering web (#1173)
LeezQ May 26, 2023
cd44872
chore: update entity typings
maslow May 26, 2023
172f9cc
fix(web): modal height (#1175)
LeezQ May 26, 2023
6a240c9
add application trial tier limit
maslow May 26, 2023
b51af3d
feat(server): add invite code feature and billings pagination (#1183)
HUAHUAI23 May 29, 2023
aab7d8e
feat(server): process free trial billing
maslow May 29, 2023
5c06979
fix(web): update app state api & rules add api (#1184)
LeezQ May 29, 2023
1033a18
fix(server): update response struct of rules, add response types
maslow May 29, 2023
ef1d85a
Merge remote-tracking branch 'upstream/design-metering' into design-m…
maslow May 29, 2023
7b558ea
refactor(web): api definitions (#1185)
LeezQ May 29, 2023
8440f77
fix(server): fix trial app logic
maslow May 29, 2023
4815947
Merge remote-tracking branch 'upstream/design-metering' into design-m…
maslow May 29, 2023
5234138
Feat definition (#1186)
LeezQ May 29, 2023
6ed2885
merge main into design-metering
maslow May 29, 2023
f89d90c
add metering yaml to laf helm charts
maslow May 29, 2023
4e4f460
Merge branch 'main' into design-metering
maslow May 29, 2023
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
Prev Previous commit
Next Next commit
add pagination response decoration
maslow committed May 26, 2023
commit cd72e1658f5f8a3592056245105efbaca0921743
3 changes: 2 additions & 1 deletion server/src/function/function.service.ts
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ import { SystemDatabase } from 'src/system-database'
import { ObjectId } from 'mongodb'
import { CloudFunction } from './entities/cloud-function'
import { ApplicationConfiguration } from 'src/application/entities/application-configuration'
import { FunctionLog } from 'src/log/entities/function-log'

@Injectable()
export class FunctionService {
@@ -210,7 +211,7 @@ export class FunctionService {
const { db, client } = await this.databaseService.findAndConnect(appid)

try {
const coll = db.collection(CN_FUNCTION_LOGS)
const coll = db.collection<FunctionLog>(CN_FUNCTION_LOGS)
const query: any = {}
if (requestId) {
query.request_id = requestId
21 changes: 21 additions & 0 deletions server/src/log/entities/function-log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ApiProperty } from '@nestjs/swagger'
import { ObjectId } from 'mongodb'

export class FunctionLog {
@ApiProperty({ type: String })
_id?: ObjectId

@ApiProperty()
request_id: string

// cloud function name
@ApiProperty()
func: string

// log content
@ApiProperty()
data: string

@ApiProperty()
created_at: Date
}
16 changes: 6 additions & 10 deletions server/src/log/log.controller.ts
Original file line number Diff line number Diff line change
@@ -6,17 +6,12 @@ import {
Query,
UseGuards,
} from '@nestjs/common'
import {
ApiBearerAuth,
ApiOperation,
ApiQuery,
ApiResponse,
ApiTags,
} from '@nestjs/swagger'
import { ApiBearerAuth, ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger'
import { ApplicationAuthGuard } from '../auth/application.auth.guard'
import { JwtAuthGuard } from '../auth/jwt.auth.guard'
import { FunctionService } from '../function/function.service'
import { ResponseUtil } from '../utils/response'
import { ApiResponsePagination, ResponseUtil } from '../utils/response'
import { FunctionLog } from './entities/function-log'

@ApiBearerAuth('Authorization')
@Controller('apps/:appid/logs')
@@ -32,8 +27,8 @@ export class LogController {
* @returns
*/
@ApiTags('Function')
@ApiResponse({ type: ResponseUtil })
@ApiOperation({ summary: 'Get function logs' })
@ApiResponsePagination(FunctionLog)
@UseGuards(JwtAuthGuard, ApplicationAuthGuard)
@ApiQuery({
name: 'functionName',
@@ -81,7 +76,8 @@ export class LogController {
list: res.data,
total: res.total,
page,
limit,
limit, // @deprecated use pageSize instead
pageSize: limit,
})
}
}
30 changes: 30 additions & 0 deletions server/src/utils/response.ts
Original file line number Diff line number Diff line change
@@ -104,3 +104,33 @@ export const ApiResponseArray = <DataDto extends Type<unknown>>(
},
}),
)

export const ApiResponsePagination = <DataDto extends Type<unknown>>(
dataDto: DataDto,
) =>
applyDecorators(
ApiExtraModels(ResponseUtil, dataDto),
ApiResponse({
schema: {
allOf: [
{ $ref: getSchemaPath(ResponseUtil) },
{
properties: {
data: {
type: 'object',
properties: {
list: {
type: 'array',
items: { $ref: getSchemaPath(dataDto) },
},
total: { type: 'number' },
page: { type: 'number' },
pageSize: { type: 'number' },
},
},
},
},
],
},
}),
)