vtex
Version:
The platform for e-commerce apps
50 lines (49 loc) • 1.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.VBase = void 0;
const api_1 = require("@vtex/api");
const IOClientFactory_1 = require("../IOClientFactory");
const routes = {
Bucket: (bucket) => `${bucket}`,
File: (bucket, path) => `buckets/${routes.Bucket(bucket)}/files/${path}`,
Conflicts: (bucket) => `buckets/${routes.Bucket(bucket)}/conflicts`,
};
class VBase extends api_1.InfraClient {
constructor(ctx, opts) {
super('vbase@0.x', ctx, {
...opts,
headers: {
'X-Vtex-Detect-Conflicts': 'true',
Authorization: ctx.authToken,
},
});
// Resolve a specific pages-graphql conflict
this.resolveConflict = (bucketKey, path, content) => {
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
this.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
this.checkForConflicts = async () => {
const response = await this.getConflicts().then(res => res.data);
return (response === null || response === void 0 ? void 0 : response.length) > 0;
};
}
static createClient(customContext = {}, customOptions = {}) {
return IOClientFactory_1.IOClientFactory.createClient(VBase, customContext, customOptions);
}
}
exports.VBase = VBase;