@@ -2,8 +2,9 @@ import { InfraClient, InstanceOptions, IOContext } from '@vtex/api'
22import { IOClientFactory } from '../IOClientFactory'
33
44const 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
910export class VBase extends InfraClient {
@@ -21,16 +22,32 @@ export class VBase extends InfraClient {
2122 } )
2223 }
2324
25+ // Resolve a specific pages-graphql conflict
26+ public resolveConflict = ( bucketKey : string , path : string , content : any ) => {
27+ const data = [
28+ {
29+ op : 'replace' ,
30+ path,
31+ value : content ,
32+ } ,
33+ ]
34+
35+ return this . http . patch ( routes . Conflicts ( `vtex.pages-graphql/${ bucketKey } ` ) , data , {
36+ metric : 'vbase-resolve-conflicts' ,
37+ } )
38+ }
39+
40+ // List all conflicts in the pages-graphql bucket
41+ public getConflicts = async ( ) => {
42+ return this . http . get ( routes . Conflicts ( 'vtex.pages-graphql/userData' ) , {
43+ metric : 'vbase-get-conflicts' ,
44+ } )
45+ }
46+
47+ // Verify if there is at least one conlfict in the pages-graphql bucket
2448 public checkForConflicts = async ( ) => {
25- let status : number
26- try {
27- const response = await this . http . get ( routes . File ( 'vtex.pages-graphql' , 'store/content.json' ) , {
28- metric : 'vbase-conflict' ,
29- } )
30- status = response . status
31- } catch ( error ) {
32- status = error . response && error . response . status
33- }
34- return status === 409
49+ const response = await this . getConflicts ( ) . then ( res => res . data )
50+
51+ return response ?. length > 0
3552 }
3653}
0 commit comments