Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

feat: [MT-13452] Added support for audit logs #729

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
34 changes: 34 additions & 0 deletions src/endpoints/audit-logs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { buildURL } from '../utils/helpers'
import BaseExtend from '../extends/base'

class AuditLogsEndpoint extends BaseExtend {
constructor(endpoint) {
super(endpoint)
this.endpoint = 'audit/logs'
}

All(token = null) {
const { limit, offset, filter } = this

const url = buildURL(this.endpoint, {
limit,
offset,
filter
})

return this.request.send(url, 'GET', undefined, token, this)
}

Filter(resourceType, resourceId) {
this.filter = {
eq: {
resource_type: resourceType,
resource_id: resourceId
}
}

return this
}
}

export default AuditLogsEndpoint
3 changes: 3 additions & 0 deletions src/moltin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { ErasureRequestsEndpoint } from './types/erasure-requests'
import { PriceBookPriceModifierEndpoint } from './types/price-book-price-modifiers'
import { AccountMembershipSettingsEndpoint } from './types/account-membership-settings'
import { ApplicationKeysEndpoint } from './types/application-keys'
import { AuditLogsEndpoint } from './types/audit-logs'

export * from './types/config'
export * from './types/storage'
Expand Down Expand Up @@ -118,6 +119,7 @@ export * from './types/user-authentication-password-profile'
export * from './types/locales'
export * from './types/extensions'
export * from './types/application-keys'
export * from './types/audit-logs'

// UMD
export as namespace moltin
Expand Down Expand Up @@ -174,6 +176,7 @@ export class Moltin {
ErasureRequests: ErasureRequestsEndpoint
PriceBookPriceModifier: PriceBookPriceModifierEndpoint
ApplicationKeys: ApplicationKeysEndpoint
AuditLogs: AuditLogsEndpoint

Cart(id?: string): CartEndpoint // This optional cart id is super worrying when using the SDK in a node server :/
constructor(config: Config)
Expand Down
2 changes: 2 additions & 0 deletions src/moltin.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import DataEntriesEndpoint from './endpoints/data-entry'
import AccountMembershipSettingsEndpoint from './endpoints/account-membership-settings'
import ErasureRequestsEndpoint from './endpoints/erasure-requests'
import ApplicationKeysEndpoint from './endpoints/application-keys'
import AuditLogsEndpoint from './endpoints/audit-logs'

import {cartIdentifier, tokenInvalid, getCredentials, resolveCredentialsStorageKey} from './utils/helpers'
import CatalogsEndpoint from './endpoints/catalogs'
Expand Down Expand Up @@ -112,6 +113,7 @@ export default class Moltin {
new UserAuthenticationPasswordProfileEndpoint(config)
this.Metrics = new MetricsEndpoint(config)
this.ApplicationKeys = new ApplicationKeysEndpoint(config)
this.AuditLogs = new AuditLogsEndpoint(config)
}

// Expose `Cart` class on Moltin class
Expand Down
29 changes: 29 additions & 0 deletions src/types/audit-logs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Identifiable, ResourcePage } from './core'

export interface AuditLogsRecord extends Identifiable {
store_id: string
type: string
initiator: {
'access-token-email': string
'access-token-id': string
'access-token-name': string
'access-token-store-id': string
'access-token-type': string
}
time: string
event_type: string
delta: Record<string, any>
resource_type: string
relationships: Record<string, any>
links: Record<string, string>
}

export interface AuditLogsEndpoint {
All(): Promise<ResourcePage<AuditLogsRecord>>

Filter(resourceType: string, resourceId: string): AuditLogsEndpoint

Limit(value: number): AuditLogsEndpoint

Offset(value: number): AuditLogsEndpoint
}