Skip to content

Commit 5724994

Browse files
author
Juan Cernadas
authored
Merge pull request #20 from onready/develop
Develop
2 parents b98d7a5 + b8f1780 commit 5724994

16 files changed

+850
-510
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Master Data (V2) | :white_check_mark: (*) <em>Attachments API pending</em> |
100100
Catalog | :white_check_mark: |
101101
Search | :white_check_mark: |
102102
Payments Gateway | :white_check_mark: |
103-
Suggestions | Comming soon... |
103+
Suggestions | :white_check_mark: |
104104
Antifraud Provider | :x: |
105105
Checkout | :x: |
106106
CMS | :x: |

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@onreadydesa/vtex-node-sdk",
3-
"version": "1.6.0-beta",
3+
"version": "1.7.0-beta",
44
"description": "VTEX Node SDK, built 100% with Typescript and 0 dependencies!",
55
"author": "Onready",
66
"private": false,
@@ -38,9 +38,9 @@
3838
"prepublishOnly": "yarn lint && yarn test && yarn build"
3939
},
4040
"devDependencies": {
41-
"@babel/core": "7.10.3",
42-
"@babel/preset-env": "7.10.3",
43-
"@babel/preset-typescript": "7.10.1",
41+
"@babel/core": "7.10.4",
42+
"@babel/preset-env": "7.10.4",
43+
"@babel/preset-typescript": "7.10.4",
4444
"@types/jest": "26.0.3",
4545
"@types/node": "14.0.14",
4646
"@typescript-eslint/eslint-plugin": "3.5.0",
@@ -53,11 +53,11 @@
5353
"eslint-plugin-jest": "23.17.1",
5454
"eslint-plugin-prettier": "3.1.4",
5555
"jest": "26.1.0",
56-
"nock": "13.0.0",
56+
"nock": "13.0.2",
5757
"prettier": "2.0.5",
5858
"rimraf": "3.0.2",
5959
"ts-jest": "26.1.1",
60-
"typescript": "3.9.5"
60+
"typescript": "3.9.6"
6161
},
6262
"engines": {
6363
"node": ">=8.0.0"

src/VTEX.ts

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
PaymentsGateway,
1111
VtexPaymentsHttpClient,
1212
} from "./modules/payments-gateway";
13+
import { Suggestions } from "./modules/suggestions";
1314

1415
export class VTEX {
1516
private static buildErrorMessage(paramName: string): string {
@@ -69,6 +70,11 @@ export class VTEX {
6970
*/
7071
readonly paymentsGateway: PaymentsGateway;
7172

73+
/**
74+
* Suggestions Module
75+
*/
76+
readonly suggestions: Suggestions;
77+
7278
/**
7379
* @param {string} store
7480
* @param {string} appKey
@@ -100,5 +106,6 @@ export class VTEX {
100106
this.paymentsGateway = new PaymentsGateway(
101107
new VtexPaymentsHttpClient(vtexCredentials)
102108
);
109+
this.suggestions = new Suggestions(vtexHttpClient);
103110
}
104111
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { VtexHttpClient } from "../../utils/VtexHttpClient";
2+
import { Feed } from "./apis/feed";
3+
import { Send } from "./apis/send";
4+
import { Manage } from "./apis/manage";
5+
6+
export class Suggestions {
7+
/**
8+
* Feed API
9+
*/
10+
readonly feed: Feed;
11+
12+
/**
13+
* Feed API
14+
*/
15+
readonly send: Send;
16+
17+
/**
18+
* Manage API
19+
*/
20+
readonly manage: Manage;
21+
22+
constructor(vtexHttpClient: VtexHttpClient) {
23+
this.feed = new Feed(vtexHttpClient);
24+
this.send = new Send(vtexHttpClient);
25+
this.manage = new Manage(vtexHttpClient);
26+
}
27+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { AbstractApi } from "../../../AbstractApi";
2+
import { VtexHttpResponse } from "../../../../utils/VtexHttpResponse";
3+
4+
export class Feed extends AbstractApi {
5+
/**
6+
*
7+
* @param {string} params Example: q=search&seller=1
8+
*/
9+
getSuggestions(params?: string): Promise<VtexHttpResponse> {
10+
const path = `/${this.vtexHttpClient.vtexCredentials.store}/suggestions?${
11+
params || ""
12+
}`;
13+
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.GET);
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./Feed";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./Manage";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
interface Product {
2+
name?: string;
3+
description?: string;
4+
categoryId?: number;
5+
brandId?: number;
6+
specifications?: string;
7+
}
8+
9+
interface Sku {
10+
name?: string;
11+
eans?: Array<string>;
12+
refId?: string;
13+
height?: number;
14+
width?: number;
15+
length?: number;
16+
weight?: number;
17+
images?: any;
18+
unitMultiplier?: number;
19+
measurementUnit?: string;
20+
specifications: any;
21+
}
22+
23+
export interface MatchRequest {
24+
matcherId?: string;
25+
score?: string;
26+
skuRef?: string;
27+
productRef?: string;
28+
product?: Product;
29+
sku?: Sku;
30+
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { AbstractApi } from "../../../AbstractApi";
2+
import { SaveSuggestionRequest } from "./requests/SaveSuggestionRequest";
3+
import { VtexHttpResponse } from "../../../../utils/VtexHttpResponse";
4+
5+
export class Send extends AbstractApi {
6+
/**
7+
* Insert or update a suggestion
8+
* @param {string} sellerId
9+
* @param {string} sellerSkuId
10+
* @param {SaveSuggestionRequest} data
11+
*/
12+
saveSuggestion(
13+
sellerId: string,
14+
sellerSkuId: string,
15+
data: SaveSuggestionRequest
16+
): Promise<VtexHttpResponse> {
17+
const path = `/${this.vtexHttpClient.vtexCredentials.store}/suggestions/${sellerId}/${sellerSkuId}`;
18+
return this.vtexHttpClient.performRequest(
19+
path,
20+
this.HTTP_METHODS.PUT,
21+
data
22+
);
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./Send";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
interface Specification {
2+
fieldName?: string;
3+
fieldValue?: string;
4+
}
5+
6+
interface Image {
7+
imageName?: string;
8+
imageUrl?: string;
9+
}
10+
11+
interface Pricing {
12+
Currency?: string;
13+
SalePrice?: number;
14+
CurrencySymbol?: string;
15+
}
16+
17+
export interface SaveSuggestionRequest {
18+
ProductId?: number;
19+
ProductName?: string;
20+
NameComplete?: string;
21+
ProductDescription?: string;
22+
BrandName?: string;
23+
SkuName?: string;
24+
SellerId?: number;
25+
Height?: number;
26+
Width?: number;
27+
Length?: number;
28+
WeightKg?: number;
29+
Updated?: boolean;
30+
RefId?: string;
31+
SellerStockKeepingUnitId?: number;
32+
CategoryFullPath?: string;
33+
SkuSpecifications?: Array<Specification>;
34+
ProductSpecifications?: Array<Specification>;
35+
Images?: Array<Image>;
36+
EAN?: string;
37+
MeasurementUnit?: string;
38+
UnitMultiplier?: number;
39+
AvailableQuantity?: number;
40+
Pricing?: Pricing;
41+
}

src/modules/suggestions/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./Suggestions";

src/utils/VtexHttpClient.ts

+3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ import { VtexHttpResponse } from "./VtexHttpResponse";
66
export class VtexHttpClient {
77
protected readonly defaultRequestOptions: https.RequestOptions;
88

9+
readonly vtexCredentials: VtexCredentials;
10+
911
/**
1012
* @param {VtexCredentials} vtexCredentials
1113
*/
1214
constructor(vtexCredentials: VtexCredentials) {
15+
this.vtexCredentials = vtexCredentials;
1316
this.defaultRequestOptions = {
1417
hostname: `${vtexCredentials.store}.vtexcommerce${vtexCredentials.environment}.com.br`,
1518
port: 443,

test/VTEX.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ describe("VTEX tests", () => {
7373
expect(instance.paymentsGateway.configuration).not.toBe(null);
7474
expect(instance.paymentsGateway.transactionProcess).not.toBe(null);
7575
expect(instance.paymentsGateway.transactionFlow).not.toBe(null);
76+
77+
expect(instance.suggestions).not.toBe(null);
78+
expect(instance.suggestions.feed).not.toBe(null);
79+
expect(instance.suggestions.send).not.toBe(null);
80+
expect(instance.suggestions.manage).not.toBe(null);
7681
done();
7782
}));
7883

0 commit comments

Comments
 (0)