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

Commit 67c3b0c

Browse files
committed
MT-13452 Added support for audit logs
1 parent 6449f79 commit 67c3b0c

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

src/endpoints/audit-logs.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { buildURL } from '../utils/helpers'
2+
import BaseExtend from '../extends/base'
3+
4+
class AuditLogsEndpoint extends BaseExtend {
5+
constructor(endpoint) {
6+
super(endpoint)
7+
this.endpoint = 'audit/logs'
8+
}
9+
10+
All(token = null) {
11+
const { limit, offset, filter } = this
12+
13+
const url = buildURL(this.endpoint, {
14+
limit,
15+
offset,
16+
filter
17+
})
18+
19+
return this.request.send(url, 'GET', undefined, token, this)
20+
}
21+
22+
Filter(resourceType, resourceId) {
23+
this.filter = {
24+
eq: {
25+
resource_type: resourceType,
26+
resource_id: resourceId
27+
}
28+
}
29+
30+
return this
31+
}
32+
}
33+
34+
export default AuditLogsEndpoint

src/moltin.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { ErasureRequestsEndpoint } from './types/erasure-requests'
5454
import { PriceBookPriceModifierEndpoint } from './types/price-book-price-modifiers'
5555
import { AccountMembershipSettingsEndpoint } from './types/account-membership-settings'
5656
import { ApplicationKeysEndpoint } from './types/application-keys'
57+
import {AuditLogsEndpoint} from './types/audit-logs'
5758

5859
export * from './types/config'
5960
export * from './types/storage'
@@ -118,6 +119,7 @@ export * from './types/user-authentication-password-profile'
118119
export * from './types/locales'
119120
export * from './types/extensions'
120121
export * from './types/application-keys'
122+
export * from './types/audit-logs'
121123

122124
// UMD
123125
export as namespace moltin
@@ -174,6 +176,7 @@ export class Moltin {
174176
ErasureRequests: ErasureRequestsEndpoint
175177
PriceBookPriceModifier: PriceBookPriceModifierEndpoint
176178
ApplicationKeys: ApplicationKeysEndpoint
179+
AuditLogs: AuditLogsEndpoint
177180

178181
Cart(id?: string): CartEndpoint // This optional cart id is super worrying when using the SDK in a node server :/
179182
constructor(config: Config)

src/moltin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import DataEntriesEndpoint from './endpoints/data-entry'
4747
import AccountMembershipSettingsEndpoint from './endpoints/account-membership-settings'
4848
import ErasureRequestsEndpoint from './endpoints/erasure-requests'
4949
import ApplicationKeysEndpoint from './endpoints/application-keys'
50+
import AuditLogsEndpoint from './endpoints/audit-logs'
5051

5152
import {cartIdentifier, tokenInvalid, getCredentials, resolveCredentialsStorageKey} from './utils/helpers'
5253
import CatalogsEndpoint from './endpoints/catalogs'
@@ -112,6 +113,7 @@ export default class Moltin {
112113
new UserAuthenticationPasswordProfileEndpoint(config)
113114
this.Metrics = new MetricsEndpoint(config)
114115
this.ApplicationKeys = new ApplicationKeysEndpoint(config)
116+
this.AuditLogs = new AuditLogsEndpoint(config)
115117
}
116118

117119
// Expose `Cart` class on Moltin class

src/types/audit-logs.d.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
import { Identifiable, ResourcePage } from './core'
3+
4+
export interface AuditLogsRecord extends Identifiable {
5+
store_id: string;
6+
type: string;
7+
initiator: {
8+
"access-token-email": string;
9+
"access-token-id": string;
10+
"access-token-name": string;
11+
"access-token-store-id": string;
12+
"access-token-type": string;
13+
}
14+
time: string;
15+
event_type: string;
16+
delta: Record<string, any>;
17+
resource_type: string;
18+
relationships: Record<string, any>;
19+
links: Record<string, string>;
20+
}
21+
22+
export interface AuditLogsEndpoint {
23+
All(): Promise<ResourcePage<AuditLogsRecord>>
24+
25+
Filter(resourceType: string, resourceId: string): AuditLogsEndpoint
26+
27+
Limit(value: number): AuditLogsEndpoint
28+
29+
Offset(value: number): AuditLogsEndpoint
30+
}

0 commit comments

Comments
 (0)