Skip to content

Commit

Permalink
Extend/vbase client v2 (#1236)
Browse files Browse the repository at this point in the history
* Extend VBase clients with conflict handler endpoints

* Extend checkForConflicts to verify any conflict inside the pages-graphql bucket

* Fix checkForConflicts condition
  • Loading branch information
vitorflg authored Oct 24, 2024
1 parent 3212e13 commit 69d5537
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 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.

## [4.1.0] - 2024-08-01

Expand Down
41 changes: 29 additions & 12 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,16 +22,32 @@ export class VBase extends InfraClient {
})
}

// Resolve a specific pages-graphql conflict
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',
})
}

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

// Verify if there is at least one conlfict in the pages-graphql bucket
public checkForConflicts = async () => {
let status: number
try {
const response = await this.http.get(routes.File('vtex.pages-graphql', 'store/content.json'), {
metric: 'vbase-conflict',
})
status = response.status
} catch (error) {
status = error.response && error.response.status
}
return status === 409
const response = await this.getConflicts().then(res => res.data)

return response?.length > 0
}
}

0 comments on commit 69d5537

Please sign in to comment.