diff --git a/src/endpoints/audit-logs.js b/src/endpoints/audit-logs.js new file mode 100644 index 000000000..d7bd31a8a --- /dev/null +++ b/src/endpoints/audit-logs.js @@ -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 diff --git a/src/moltin.d.ts b/src/moltin.d.ts index f86f27dea..7916c3c2e 100644 --- a/src/moltin.d.ts +++ b/src/moltin.d.ts @@ -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' @@ -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 @@ -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) diff --git a/src/moltin.js b/src/moltin.js index 4b9c97ff5..37eb3ea96 100644 --- a/src/moltin.js +++ b/src/moltin.js @@ -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' @@ -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 diff --git a/src/types/audit-logs.d.ts b/src/types/audit-logs.d.ts new file mode 100644 index 000000000..b43858b48 --- /dev/null +++ b/src/types/audit-logs.d.ts @@ -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 + resource_type: string + relationships: Record + links: Record +} + +export interface AuditLogsEndpoint { + All(): Promise> + + Filter(resourceType: string, resourceId: string): AuditLogsEndpoint + + Limit(value: number): AuditLogsEndpoint + + Offset(value: number): AuditLogsEndpoint +}