Skip to content

Commit

Permalink
Extend VBase clients with conflict handler endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorflg committed Oct 3, 2024
1 parent 337698b commit 7a2e717
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Updated
- Extend VBase client, integrating the `getConflicts` and the `resolveConflict` endpoints.

## [2.128.0] - 2021-05-25

Expand Down
27 changes: 24 additions & 3 deletions src/api/clients/IOClients/infra/VBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { InfraClient, InstanceOptions, IOContext } from '@vtex/api'
import { IOClientFactory } from '../IOClientFactory'

const routes = {
Bucket: (bucket: string) => `/buckets/${bucket}`,
File: (bucket: string, path: string) => `${routes.Bucket(bucket)}/userData/files/${path}`,
Bucket: (bucket: string) => `${bucket}`,
File: (bucket: string, path: string) => `buckets/${routes.Bucket(bucket)}/files/${path}`,
Conflicts: (bucket: string) => `buckets/${routes.Bucket(bucket)}/conflicts`,
}

export class VBase extends InfraClient {
Expand All @@ -21,10 +22,30 @@ export class VBase extends InfraClient {
})
}

public resolveConflict = (bucketKey: string, path: string, content: any) => {
const data = [
{
op: 'replace',
path,
value: content,
},
]

return this.http.patch(routes.Conflicts(`vtex.pages-graphql/${bucketKey}`), data, {
metric: 'vbase-resolve-conflicts',
})
}

public getConflicts = async () => {
return this.http.get(routes.Conflicts('vtex.pages-graphql/userData'), {
metric: 'vbase-get-conflicts',
})
}

public checkForConflicts = async () => {
let status: number
try {
const response = await this.http.get(routes.File('vtex.pages-graphql', 'store/content.json'), {
const response = await this.http.get(routes.File('vtex.pages-graphql/userData', 'store/content.json'), {
metric: 'vbase-conflict',
})
status = response.status
Expand Down

0 comments on commit 7a2e717

Please sign in to comment.