logs-command.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { ClientLogCreate, HttpStatusCode, ServerLogLevel } from '@shared/models'
  2. import { AbstractCommand, OverrideCommandOptions } from '../shared'
  3. export class LogsCommand extends AbstractCommand {
  4. createLogClient (options: OverrideCommandOptions & { payload: ClientLogCreate }) {
  5. const path = '/api/v1/server/logs/client'
  6. return this.postBodyRequest({
  7. ...options,
  8. path,
  9. fields: options.payload,
  10. implicitToken: true,
  11. defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
  12. })
  13. }
  14. getLogs (options: OverrideCommandOptions & {
  15. startDate: Date
  16. endDate?: Date
  17. level?: ServerLogLevel
  18. tagsOneOf?: string[]
  19. }) {
  20. const { startDate, endDate, tagsOneOf, level } = options
  21. const path = '/api/v1/server/logs'
  22. return this.getRequestBody<any[]>({
  23. ...options,
  24. path,
  25. query: { startDate, endDate, level, tagsOneOf },
  26. implicitToken: true,
  27. defaultExpectedStatus: HttpStatusCode.OK_200
  28. })
  29. }
  30. getAuditLogs (options: OverrideCommandOptions & {
  31. startDate: Date
  32. endDate?: Date
  33. }) {
  34. const { startDate, endDate } = options
  35. const path = '/api/v1/server/audit-logs'
  36. return this.getRequestBody({
  37. ...options,
  38. path,
  39. query: { startDate, endDate },
  40. implicitToken: true,
  41. defaultExpectedStatus: HttpStatusCode.OK_200
  42. })
  43. }
  44. }