feat(api-key): Add CRUD functionalities to the api key module

This commit is contained in:
Stevche Radevski
2024-02-21 11:19:22 +01:00
parent e0750bae40
commit c99ca5cc22
14 changed files with 812 additions and 42 deletions
+18 -4
View File
@@ -1,8 +1,22 @@
import { BaseFilterable } from "../../dal"
// TODO:
export interface ApiKeyDTO {}
export type ApiKeyType = "secret" | "publishable"
export interface ApiKeyDTO {
id: string
token: string
redacted: string
title: string
type: ApiKeyType
last_used_at: Date | null
created_by: string
created_at: Date
revoked_by: string | null
revoked_at: Date | null
}
// TODO:
export interface FilterableApiKeyProps
extends BaseFilterable<FilterableApiKeyProps> {}
extends BaseFilterable<FilterableApiKeyProps> {
id?: string | string[]
title?: string | string[]
type?: ApiKeyType
}
@@ -1,5 +1,18 @@
// TODO:
export interface CreateApiKeyDTO {}
import { ApiKeyType } from "../common"
// TODO:
export interface UpdateApiKeyDTO {}
export interface CreateApiKeyDTO {
title: string
type: ApiKeyType
created_by: string
// We could add revoked_at as a parameter (or expires_at that gets mapped to revoked_at internally) in order to support expiring tokens
}
export interface UpdateApiKeyDTO {
id: string
title?: string
}
export interface RevokeApiKeyDTO {
id: string
revoked_by: string
}
+4 -3
View File
@@ -2,7 +2,7 @@ import { IModuleService } from "../modules-sdk"
import { ApiKeyDTO, FilterableApiKeyProps } from "./common"
import { FindConfig } from "../common"
import { Context } from "../shared-context"
import { CreateApiKeyDTO, UpdateApiKeyDTO } from "./mutations"
import { CreateApiKeyDTO, RevokeApiKeyDTO, UpdateApiKeyDTO } from "./mutations"
export interface IApiKeyModuleService extends IModuleService {
/**
@@ -67,10 +67,11 @@ export interface IApiKeyModuleService extends IModuleService {
/**
* Revokes an api key
* @param id
* @param data
* @param sharedContext
*/
revoke(id: string, sharedContext?: Context): Promise<void>
revoke(data: RevokeApiKeyDTO[], sharedContext?: Context): Promise<ApiKeyDTO[]>
revoke(data: RevokeApiKeyDTO, sharedContext?: Context): Promise<ApiKeyDTO>
/**
* Check the validity of an api key