From 67c3b0cf7c46da94d5879dd649db6434c9bfa8ec Mon Sep 17 00:00:00 2001 From: Connor Lynch Date: Wed, 14 Sep 2022 14:31:40 -0400 Subject: [PATCH 1/3] MT-13452 Added support for audit logs --- src/endpoints/audit-logs.js | 34 ++++++++++++++++++++++++++++++++++ src/moltin.d.ts | 3 +++ src/moltin.js | 2 ++ src/types/audit-logs.d.ts | 30 ++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 src/endpoints/audit-logs.js create mode 100644 src/types/audit-logs.d.ts diff --git a/src/endpoints/audit-logs.js b/src/endpoints/audit-logs.js new file mode 100644 index 000000000..7ebcc06d2 --- /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..91112c93b 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..6ffa6069f --- /dev/null +++ b/src/types/audit-logs.d.ts @@ -0,0 +1,30 @@ + +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 +} From c6f9c3c19e5459c81eed63afe81ca7c5e2431766 Mon Sep 17 00:00:00 2001 From: Connor Lynch Date: Thu, 15 Sep 2022 16:21:22 -0400 Subject: [PATCH 2/3] MT-13452 minor formatting fix --- src/moltin.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/moltin.d.ts b/src/moltin.d.ts index 91112c93b..7916c3c2e 100644 --- a/src/moltin.d.ts +++ b/src/moltin.d.ts @@ -54,7 +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' +import { AuditLogsEndpoint } from './types/audit-logs' export * from './types/config' export * from './types/storage' From 708704c34934c940861320a1436c440d08e551f0 Mon Sep 17 00:00:00 2001 From: Sam Blacklock Date: Tue, 17 Jan 2023 10:26:40 +0000 Subject: [PATCH 3/3] fix: reindent at 2 spaces --- src/endpoints/audit-logs.js | 68 ++++++++++++++++++------------------- src/types/audit-logs.d.ts | 59 ++++++++++++++++---------------- 2 files changed, 63 insertions(+), 64 deletions(-) diff --git a/src/endpoints/audit-logs.js b/src/endpoints/audit-logs.js index 7ebcc06d2..d7bd31a8a 100644 --- a/src/endpoints/audit-logs.js +++ b/src/endpoints/audit-logs.js @@ -1,34 +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 +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/types/audit-logs.d.ts b/src/types/audit-logs.d.ts index 6ffa6069f..b43858b48 100644 --- a/src/types/audit-logs.d.ts +++ b/src/types/audit-logs.d.ts @@ -1,30 +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 -} +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 +}