Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend/vbase client v2 #1236

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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?.data?.length > 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am not wrong, axios throws an error for 4xx responses. If that is the case, I think we are changing the behavior here, since the line 49 will raise the error and will not get to the return statement. Have you checked that? Also, as in the other PR, I would avoid the await / .then combination.

}
}
Loading