From 2baec9711fbf9ef0aca427d327f2201254fa0283 Mon Sep 17 00:00:00 2001 From: Vitor Gomes Date: Thu, 3 Oct 2024 10:19:01 -0300 Subject: [PATCH 1/3] Extend VBase clients with conflict handler endpoints --- CHANGELOG.md | 2 ++ src/api/clients/IOClients/infra/VBase.ts | 27 +++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf5f7cb37..77133906d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/api/clients/IOClients/infra/VBase.ts b/src/api/clients/IOClients/infra/VBase.ts index f4ac28944..952a92eee 100644 --- a/src/api/clients/IOClients/infra/VBase.ts +++ b/src/api/clients/IOClients/infra/VBase.ts @@ -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 { @@ -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 From 4b5bebac46e420a737758f27bc66287099e766bd Mon Sep 17 00:00:00 2001 From: Vitor Gomes Date: Thu, 10 Oct 2024 11:14:00 -0300 Subject: [PATCH 2/3] Extend checkForConflicts to verify any conflict inside the pages-graphql bucket --- src/api/clients/IOClients/infra/VBase.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/api/clients/IOClients/infra/VBase.ts b/src/api/clients/IOClients/infra/VBase.ts index 952a92eee..f190736c4 100644 --- a/src/api/clients/IOClients/infra/VBase.ts +++ b/src/api/clients/IOClients/infra/VBase.ts @@ -22,6 +22,7 @@ export class VBase extends InfraClient { }) } + // Resolve a specific pages-graphql conflict public resolveConflict = (bucketKey: string, path: string, content: any) => { const data = [ { @@ -36,22 +37,17 @@ export class VBase extends InfraClient { }) } + // 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/userData', '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 } } From 7fb5b4290262217d5434e579b26c265c38a4f55f Mon Sep 17 00:00:00 2001 From: Vitor Gomes Date: Mon, 14 Oct 2024 16:12:29 -0300 Subject: [PATCH 3/3] Fix checkForConflicts condition --- src/api/clients/IOClients/infra/VBase.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/clients/IOClients/infra/VBase.ts b/src/api/clients/IOClients/infra/VBase.ts index f190736c4..0d61a07ef 100644 --- a/src/api/clients/IOClients/infra/VBase.ts +++ b/src/api/clients/IOClients/infra/VBase.ts @@ -48,6 +48,6 @@ export class VBase extends InfraClient { public checkForConflicts = async () => { const response = await this.getConflicts().then(res => res.data) - return response?.data?.length > 0 + return response?.length > 0 } }