Skip to content

Commit 7a2e717

Browse files
committed
Extend VBase clients with conflict handler endpoints
1 parent 337698b commit 7a2e717

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
9+
### Updated
10+
- Extend VBase client, integrating the `getConflicts` and the `resolveConflict` endpoints.
911

1012
## [2.128.0] - 2021-05-25
1113

src/api/clients/IOClients/infra/VBase.ts

+24-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { InfraClient, InstanceOptions, IOContext } from '@vtex/api'
22
import { IOClientFactory } from '../IOClientFactory'
33

44
const routes = {
5-
Bucket: (bucket: string) => `/buckets/${bucket}`,
6-
File: (bucket: string, path: string) => `${routes.Bucket(bucket)}/userData/files/${path}`,
5+
Bucket: (bucket: string) => `${bucket}`,
6+
File: (bucket: string, path: string) => `buckets/${routes.Bucket(bucket)}/files/${path}`,
7+
Conflicts: (bucket: string) => `buckets/${routes.Bucket(bucket)}/conflicts`,
78
}
89

910
export class VBase extends InfraClient {
@@ -21,10 +22,30 @@ export class VBase extends InfraClient {
2122
})
2223
}
2324

25+
public resolveConflict = (bucketKey: string, path: string, content: any) => {
26+
const data = [
27+
{
28+
op: 'replace',
29+
path,
30+
value: content,
31+
},
32+
]
33+
34+
return this.http.patch(routes.Conflicts(`vtex.pages-graphql/${bucketKey}`), data, {
35+
metric: 'vbase-resolve-conflicts',
36+
})
37+
}
38+
39+
public getConflicts = async () => {
40+
return this.http.get(routes.Conflicts('vtex.pages-graphql/userData'), {
41+
metric: 'vbase-get-conflicts',
42+
})
43+
}
44+
2445
public checkForConflicts = async () => {
2546
let status: number
2647
try {
27-
const response = await this.http.get(routes.File('vtex.pages-graphql', 'store/content.json'), {
48+
const response = await this.http.get(routes.File('vtex.pages-graphql/userData', 'store/content.json'), {
2849
metric: 'vbase-conflict',
2950
})
3051
status = response.status

0 commit comments

Comments
 (0)