Skip to content

Commit

Permalink
Merge pull request #20 from onready/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Juan Cernadas authored Jul 3, 2020
2 parents b98d7a5 + b8f1780 commit 5724994
Show file tree
Hide file tree
Showing 16 changed files with 850 additions and 510 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Master Data (V2) | :white_check_mark: (*) <em>Attachments API pending</em> |
Catalog | :white_check_mark: |
Search | :white_check_mark: |
Payments Gateway | :white_check_mark: |
Suggestions | Comming soon... |
Suggestions | :white_check_mark: |
Antifraud Provider | :x: |
Checkout | :x: |
CMS | :x: |
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onreadydesa/vtex-node-sdk",
"version": "1.6.0-beta",
"version": "1.7.0-beta",
"description": "VTEX Node SDK, built 100% with Typescript and 0 dependencies!",
"author": "Onready",
"private": false,
Expand Down Expand Up @@ -38,9 +38,9 @@
"prepublishOnly": "yarn lint && yarn test && yarn build"
},
"devDependencies": {
"@babel/core": "7.10.3",
"@babel/preset-env": "7.10.3",
"@babel/preset-typescript": "7.10.1",
"@babel/core": "7.10.4",
"@babel/preset-env": "7.10.4",
"@babel/preset-typescript": "7.10.4",
"@types/jest": "26.0.3",
"@types/node": "14.0.14",
"@typescript-eslint/eslint-plugin": "3.5.0",
Expand All @@ -53,11 +53,11 @@
"eslint-plugin-jest": "23.17.1",
"eslint-plugin-prettier": "3.1.4",
"jest": "26.1.0",
"nock": "13.0.0",
"nock": "13.0.2",
"prettier": "2.0.5",
"rimraf": "3.0.2",
"ts-jest": "26.1.1",
"typescript": "3.9.5"
"typescript": "3.9.6"
},
"engines": {
"node": ">=8.0.0"
Expand Down
7 changes: 7 additions & 0 deletions src/VTEX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
PaymentsGateway,
VtexPaymentsHttpClient,
} from "./modules/payments-gateway";
import { Suggestions } from "./modules/suggestions";

export class VTEX {
private static buildErrorMessage(paramName: string): string {
Expand Down Expand Up @@ -69,6 +70,11 @@ export class VTEX {
*/
readonly paymentsGateway: PaymentsGateway;

/**
* Suggestions Module
*/
readonly suggestions: Suggestions;

/**
* @param {string} store
* @param {string} appKey
Expand Down Expand Up @@ -100,5 +106,6 @@ export class VTEX {
this.paymentsGateway = new PaymentsGateway(
new VtexPaymentsHttpClient(vtexCredentials)
);
this.suggestions = new Suggestions(vtexHttpClient);
}
}
27 changes: 27 additions & 0 deletions src/modules/suggestions/Suggestions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { VtexHttpClient } from "../../utils/VtexHttpClient";
import { Feed } from "./apis/feed";
import { Send } from "./apis/send";
import { Manage } from "./apis/manage";

export class Suggestions {
/**
* Feed API
*/
readonly feed: Feed;

/**
* Feed API
*/
readonly send: Send;

/**
* Manage API
*/
readonly manage: Manage;

constructor(vtexHttpClient: VtexHttpClient) {
this.feed = new Feed(vtexHttpClient);
this.send = new Send(vtexHttpClient);
this.manage = new Manage(vtexHttpClient);
}
}
15 changes: 15 additions & 0 deletions src/modules/suggestions/apis/feed/Feed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { AbstractApi } from "../../../AbstractApi";
import { VtexHttpResponse } from "../../../../utils/VtexHttpResponse";

export class Feed extends AbstractApi {
/**
*
* @param {string} params Example: q=search&seller=1
*/
getSuggestions(params?: string): Promise<VtexHttpResponse> {
const path = `/${this.vtexHttpClient.vtexCredentials.store}/suggestions?${
params || ""
}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.GET);
}
}
1 change: 1 addition & 0 deletions src/modules/suggestions/apis/feed/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Feed";
97 changes: 97 additions & 0 deletions src/modules/suggestions/apis/manage/Manage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { AbstractApi } from "../../../AbstractApi";
import { VtexHttpClient } from "../../../../utils/VtexHttpClient";
import { VtexHttpResponse } from "../../../../utils/VtexHttpResponse";
import { MatchRequest } from "./requests/MatchRequest";

export class Manage extends AbstractApi {
private readonly basePath: string;

constructor(vtexHttpClient: VtexHttpClient) {
super(vtexHttpClient);
this.basePath = `/${vtexHttpClient.vtexCredentials.store}/suggestions`;
}

/**
*
* @param {string} sellerId
* @param {string} sellerSkuId
*/
getSuggestion(
sellerId: string,
sellerSkuId: string
): Promise<VtexHttpResponse> {
const path = `${this.basePath}/${sellerId}/${sellerSkuId}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.GET);
}

/**
*
* @param {string} sellerId
* @param {string} sellerSkuId
*/
deleteSuggestion(
sellerId: string,
sellerSkuId: string
): Promise<VtexHttpResponse> {
const path = `${this.basePath}/${sellerId}/${sellerSkuId}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.DELETE);
}

/**
* Get all versions for a specific suggestion
* @param {string} sellerId
* @param {string} sellerSkuId
*/
getVersions(
sellerId: string,
sellerSkuId: string
): Promise<VtexHttpResponse> {
const path = `${this.basePath}/${sellerId}/${sellerSkuId}/versions`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.GET);
}

/**
* Get a specific version for a suggestion. To list the versions available,
* use 'GET Versions' request. Replace {{version}} parameter with the chosen version.
* @param {string} sellerId
* @param {string} sellerSkuId
* @param {string} version
*/
getSuggestionByVersion(
sellerId: string,
sellerSkuId: string,
version: string
): Promise<VtexHttpResponse> {
const path = `${this.basePath}/${sellerId}/${sellerSkuId}/versions/${version}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.GET);
}

/**
* Apply a match for a version of a suggestion. All information inside curly brackets should be replaced,
* some of them are highlighted below.{{score}}: Should be a decimal value that represents the confidence
* level.Default rules for score: score < 30: suggestion will be denied; score > 30 and < 80 - suggestion
* status continue as 'Pending'; score >= 80 - suggestion will be accepted and processed in accordance with
* body specification. The executions rules are defined by existence of information in request body, below
* is the precedence order and information about each match type. skuRef: should be specifed when type is
* a sku match; productRef: should be specified when type is a product match.
* @param {string} sellerId
* @param {string} sellerSkuId
* @param {string} version
* @param {string} matchId
* @param {MatchRequest} data
*/
match(
sellerId: string,
sellerSkuId: string,
version: string,
matchId: string,
data: MatchRequest
): Promise<VtexHttpResponse> {
const path = `${this.basePath}/${sellerId}/${sellerSkuId}/versions/${version}/matches/${matchId}`;
return this.vtexHttpClient.performRequest(
path,
this.HTTP_METHODS.PUT,
data
);
}
}
1 change: 1 addition & 0 deletions src/modules/suggestions/apis/manage/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Manage";
30 changes: 30 additions & 0 deletions src/modules/suggestions/apis/manage/requests/MatchRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
interface Product {
name?: string;
description?: string;
categoryId?: number;
brandId?: number;
specifications?: string;
}

interface Sku {
name?: string;
eans?: Array<string>;
refId?: string;
height?: number;
width?: number;
length?: number;
weight?: number;
images?: any;
unitMultiplier?: number;
measurementUnit?: string;
specifications: any;
}

export interface MatchRequest {
matcherId?: string;
score?: string;
skuRef?: string;
productRef?: string;
product?: Product;
sku?: Sku;
}
24 changes: 24 additions & 0 deletions src/modules/suggestions/apis/send/Send.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { AbstractApi } from "../../../AbstractApi";
import { SaveSuggestionRequest } from "./requests/SaveSuggestionRequest";
import { VtexHttpResponse } from "../../../../utils/VtexHttpResponse";

export class Send extends AbstractApi {
/**
* Insert or update a suggestion
* @param {string} sellerId
* @param {string} sellerSkuId
* @param {SaveSuggestionRequest} data
*/
saveSuggestion(
sellerId: string,
sellerSkuId: string,
data: SaveSuggestionRequest
): Promise<VtexHttpResponse> {
const path = `/${this.vtexHttpClient.vtexCredentials.store}/suggestions/${sellerId}/${sellerSkuId}`;
return this.vtexHttpClient.performRequest(
path,
this.HTTP_METHODS.PUT,
data
);
}
}
1 change: 1 addition & 0 deletions src/modules/suggestions/apis/send/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Send";
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
interface Specification {
fieldName?: string;
fieldValue?: string;
}

interface Image {
imageName?: string;
imageUrl?: string;
}

interface Pricing {
Currency?: string;
SalePrice?: number;
CurrencySymbol?: string;
}

export interface SaveSuggestionRequest {
ProductId?: number;
ProductName?: string;
NameComplete?: string;
ProductDescription?: string;
BrandName?: string;
SkuName?: string;
SellerId?: number;
Height?: number;
Width?: number;
Length?: number;
WeightKg?: number;
Updated?: boolean;
RefId?: string;
SellerStockKeepingUnitId?: number;
CategoryFullPath?: string;
SkuSpecifications?: Array<Specification>;
ProductSpecifications?: Array<Specification>;
Images?: Array<Image>;
EAN?: string;
MeasurementUnit?: string;
UnitMultiplier?: number;
AvailableQuantity?: number;
Pricing?: Pricing;
}
1 change: 1 addition & 0 deletions src/modules/suggestions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Suggestions";
3 changes: 3 additions & 0 deletions src/utils/VtexHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import { VtexHttpResponse } from "./VtexHttpResponse";
export class VtexHttpClient {
protected readonly defaultRequestOptions: https.RequestOptions;

readonly vtexCredentials: VtexCredentials;

/**
* @param {VtexCredentials} vtexCredentials
*/
constructor(vtexCredentials: VtexCredentials) {
this.vtexCredentials = vtexCredentials;
this.defaultRequestOptions = {
hostname: `${vtexCredentials.store}.vtexcommerce${vtexCredentials.environment}.com.br`,
port: 443,
Expand Down
5 changes: 5 additions & 0 deletions test/VTEX.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ describe("VTEX tests", () => {
expect(instance.paymentsGateway.configuration).not.toBe(null);
expect(instance.paymentsGateway.transactionProcess).not.toBe(null);
expect(instance.paymentsGateway.transactionFlow).not.toBe(null);

expect(instance.suggestions).not.toBe(null);
expect(instance.suggestions.feed).not.toBe(null);
expect(instance.suggestions.send).not.toBe(null);
expect(instance.suggestions.manage).not.toBe(null);
done();
}));

Expand Down
Loading

0 comments on commit 5724994

Please sign in to comment.