|
| 1 | +import { AbstractApi } from "../../../AbstractApi"; |
| 2 | +import { VtexHttpClient } from "../../../../utils/VtexHttpClient"; |
| 3 | +import { VtexHttpResponse } from "../../../../utils/VtexHttpResponse"; |
| 4 | +import { MatchRequest } from "./requests/MatchRequest"; |
| 5 | + |
| 6 | +export class Manage extends AbstractApi { |
| 7 | + private readonly basePath: string; |
| 8 | + |
| 9 | + constructor(vtexHttpClient: VtexHttpClient) { |
| 10 | + super(vtexHttpClient); |
| 11 | + this.basePath = `/${vtexHttpClient.vtexCredentials.store}/suggestions`; |
| 12 | + } |
| 13 | + |
| 14 | + /** |
| 15 | + * |
| 16 | + * @param {string} sellerId |
| 17 | + * @param {string} sellerSkuId |
| 18 | + */ |
| 19 | + getSuggestion( |
| 20 | + sellerId: string, |
| 21 | + sellerSkuId: string |
| 22 | + ): Promise<VtexHttpResponse> { |
| 23 | + const path = `${this.basePath}/${sellerId}/${sellerSkuId}`; |
| 24 | + return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.GET); |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * |
| 29 | + * @param {string} sellerId |
| 30 | + * @param {string} sellerSkuId |
| 31 | + */ |
| 32 | + deleteSuggestion( |
| 33 | + sellerId: string, |
| 34 | + sellerSkuId: string |
| 35 | + ): Promise<VtexHttpResponse> { |
| 36 | + const path = `${this.basePath}/${sellerId}/${sellerSkuId}`; |
| 37 | + return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.DELETE); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Get all versions for a specific suggestion |
| 42 | + * @param {string} sellerId |
| 43 | + * @param {string} sellerSkuId |
| 44 | + */ |
| 45 | + getVersions( |
| 46 | + sellerId: string, |
| 47 | + sellerSkuId: string |
| 48 | + ): Promise<VtexHttpResponse> { |
| 49 | + const path = `${this.basePath}/${sellerId}/${sellerSkuId}/versions`; |
| 50 | + return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.GET); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Get a specific version for a suggestion. To list the versions available, |
| 55 | + * use 'GET Versions' request. Replace {{version}} parameter with the chosen version. |
| 56 | + * @param {string} sellerId |
| 57 | + * @param {string} sellerSkuId |
| 58 | + * @param {string} version |
| 59 | + */ |
| 60 | + getSuggestionByVersion( |
| 61 | + sellerId: string, |
| 62 | + sellerSkuId: string, |
| 63 | + version: string |
| 64 | + ): Promise<VtexHttpResponse> { |
| 65 | + const path = `${this.basePath}/${sellerId}/${sellerSkuId}/versions/${version}`; |
| 66 | + return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.GET); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Apply a match for a version of a suggestion. All information inside curly brackets should be replaced, |
| 71 | + * some of them are highlighted below.{{score}}: Should be a decimal value that represents the confidence |
| 72 | + * level.Default rules for score: score < 30: suggestion will be denied; score > 30 and < 80 - suggestion |
| 73 | + * status continue as 'Pending'; score >= 80 - suggestion will be accepted and processed in accordance with |
| 74 | + * body specification. The executions rules are defined by existence of information in request body, below |
| 75 | + * is the precedence order and information about each match type. skuRef: should be specifed when type is |
| 76 | + * a sku match; productRef: should be specified when type is a product match. |
| 77 | + * @param {string} sellerId |
| 78 | + * @param {string} sellerSkuId |
| 79 | + * @param {string} version |
| 80 | + * @param {string} matchId |
| 81 | + * @param {MatchRequest} data |
| 82 | + */ |
| 83 | + match( |
| 84 | + sellerId: string, |
| 85 | + sellerSkuId: string, |
| 86 | + version: string, |
| 87 | + matchId: string, |
| 88 | + data: MatchRequest |
| 89 | + ): Promise<VtexHttpResponse> { |
| 90 | + const path = `${this.basePath}/${sellerId}/${sellerSkuId}/versions/${version}/matches/${matchId}`; |
| 91 | + return this.vtexHttpClient.performRequest( |
| 92 | + path, |
| 93 | + this.HTTP_METHODS.PUT, |
| 94 | + data |
| 95 | + ); |
| 96 | + } |
| 97 | +} |
0 commit comments