Skip to content

Commit 69b1e90

Browse files
author
Juan Cernadas
authored
Merge pull request #34 from onready/develop
Develop
2 parents 04423fd + 3cf3b9f commit 69b1e90

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1392
-63
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ CMS | :white_check_mark: |
106106
Session Manager | :white_check_mark: |
107107
License Manager | :white_check_mark: |
108108
Customer Credit | :white_check_mark: |
109+
Subscriptions (V2) | :white_check_mark: |
110+
Rates and Benefits | :white_check_mark: |
111+
Checkout | :white_check_mark: |
109112
Antifraud Provider | :x: |
110-
Checkout | :x: |
111113
Giftcard | :x: |
112114
Giftcard Hub | :x: |
113115
Giftcard Provider Protocol | :x: |
114116
Payment Provider Protocol | :x: |
115-
Rates and Benefits | :x: |
116-
Subscriptions (V2) | :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.12.0-beta",
3+
"version": "1.15.0-beta",
44
"description": "VTEX Node SDK, built 100% with Typescript and 0 dependencies!",
55
"author": "Onready",
66
"private": false,
@@ -41,10 +41,10 @@
4141
"@babel/core": "7.10.4",
4242
"@babel/preset-env": "7.10.4",
4343
"@babel/preset-typescript": "7.10.4",
44-
"@types/jest": "26.0.3",
45-
"@types/node": "14.0.14",
46-
"@typescript-eslint/eslint-plugin": "3.6.0",
47-
"@typescript-eslint/parser": "3.6.0",
44+
"@types/jest": "26.0.4",
45+
"@types/node": "14.0.23",
46+
"@typescript-eslint/eslint-plugin": "3.6.1",
47+
"@typescript-eslint/parser": "3.6.1",
4848
"babel-jest": "26.1.0",
4949
"eslint": "7.4.0",
5050
"eslint-config-airbnb-base": "14.2.0",
@@ -56,7 +56,7 @@
5656
"nock": "13.0.2",
5757
"prettier": "2.0.5",
5858
"rimraf": "3.0.2",
59-
"ts-jest": "26.1.1",
59+
"ts-jest": "26.1.2",
6060
"typescript": "3.9.6"
6161
},
6262
"engines": {

src/VTEX.ts

+21
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import { CMS } from "./modules/CMS";
1616
import { SessionManager } from "./modules/session-manager";
1717
import { LicenseManager } from "./modules/license-manager";
1818
import { CustomerCredit } from "./modules/customer-credit";
19+
import { Subscriptions } from "./modules/subscriptions/v2";
20+
import { RatesAndBenefits } from "./modules/rates-and-benefits";
21+
import { Checkout } from "./modules/checkout";
1922

2023
export class VTEX {
2124
private static buildErrorMessage(paramName: string): string {
@@ -105,6 +108,21 @@ export class VTEX {
105108
*/
106109
readonly customerCredit: CustomerCredit;
107110

111+
/**
112+
* Subscriptions (V2) Module
113+
*/
114+
readonly subscriptions: Subscriptions;
115+
116+
/**
117+
* Rates and Benefits Module
118+
*/
119+
readonly ratesAndBenefits: RatesAndBenefits;
120+
121+
/**
122+
* Checkout Module
123+
*/
124+
readonly checkout: Checkout;
125+
108126
/**
109127
* @param {string} store
110128
* @param {string} appKey
@@ -142,5 +160,8 @@ export class VTEX {
142160
this.sessionManager = new SessionManager(vtexHttpClient);
143161
this.licenseManager = new LicenseManager(vtexHttpClient);
144162
this.customerCredit = new CustomerCredit(vtexHttpClient);
163+
this.subscriptions = new Subscriptions(vtexHttpClient);
164+
this.ratesAndBenefits = new RatesAndBenefits(vtexHttpClient);
165+
this.checkout = new Checkout(vtexHttpClient);
145166
}
146167
}

src/modules/checkout/Checkout.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { VtexHttpClient } from "../../utils/VtexHttpClient";
2+
import { OrderForm } from "./apis/order-form";
3+
import { CartUpdate } from "./apis/cart-update";
4+
import { CustomData } from "./apis/custom-data";
5+
import { Configuration } from "./apis/configuration";
6+
7+
export class Checkout {
8+
/**
9+
* Order Form API
10+
*/
11+
readonly orderForm: OrderForm;
12+
13+
/**
14+
* Cart Update API
15+
*/
16+
readonly cartUpdate: CartUpdate;
17+
18+
/**
19+
* Custom Data API
20+
*/
21+
readonly customData: CustomData;
22+
23+
/**
24+
* Configuration API
25+
*/
26+
readonly configuration: Configuration;
27+
28+
constructor(vtexHttpClient: VtexHttpClient) {
29+
this.orderForm = new OrderForm(vtexHttpClient);
30+
this.cartUpdate = new CartUpdate(vtexHttpClient);
31+
this.customData = new CustomData(vtexHttpClient);
32+
this.configuration = new Configuration(vtexHttpClient);
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { AbstractApi } from "../../../AbstractApi";
2+
import { VtexHttpResponse } from "../../../../utils/VtexHttpResponse";
3+
import { UpdateCartItemsRequest } from "./requests/UpdateCartItemsRequest";
4+
import { ChangePriceRequest } from "./requests/ChangePriceRequest";
5+
6+
export class CartUpdate extends AbstractApi {
7+
private static readonly BASE_PATH: string = "/api/checkout/pub/orderForm";
8+
9+
/**
10+
* With the Items Update request you can:
11+
* 1) Add items to the cart
12+
* 2) Change the quantity of one or more items in a specific cart
13+
* 3) Remove items from the cart (by changing their quantity to 0).
14+
* @param {string} orderFormId
15+
* @param {UpdateCartItemsRequest} data
16+
*/
17+
updateCartItems(
18+
orderFormId: string,
19+
data: UpdateCartItemsRequest
20+
): Promise<VtexHttpResponse> {
21+
const path = `${CartUpdate.BASE_PATH}/${orderFormId}/items`;
22+
return this.vtexHttpClient.performRequest(
23+
path,
24+
this.HTTP_METHODS.PATCH,
25+
data
26+
);
27+
}
28+
29+
/**
30+
* This request changes the price of a specific item in a cart. You need to inform which cart you are
31+
* referring to, by sending its orderFormID; and what is the item whose price you want to change, by
32+
* sending its itemIndex. You also need to pass the new price value in the body. Remember that, to
33+
* use this endpoint, the feature of manual price must be active. To check if it's active, use the
34+
* Get orderForm configuration endpoint. To make it active, use the Update orderForm configuration
35+
* endpoint, making the allowManualPrice field true.
36+
* @param {string} orderFormId
37+
* @param {number} itemIndex
38+
* @param {ChangePriceRequest} data
39+
*/
40+
changePrice(
41+
orderFormId: string,
42+
itemIndex: number,
43+
data: ChangePriceRequest
44+
): Promise<VtexHttpResponse> {
45+
const path = `${CartUpdate.BASE_PATH}/${orderFormId}/items/${itemIndex}/price`;
46+
return this.vtexHttpClient.performRequest(
47+
path,
48+
this.HTTP_METHODS.PUT,
49+
data
50+
);
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./CartUpdate";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface ChangePriceRequest {
2+
price?: number;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
interface OrderItem {
2+
quantity?: number;
3+
index?: number;
4+
seller?: string;
5+
id?: string;
6+
}
7+
8+
export interface UpdateCartItemsRequest {
9+
orderItems?: Array<OrderItem>;
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { AbstractApi } from "../../../AbstractApi";
2+
import { VtexHttpResponse } from "../../../../utils/VtexHttpResponse";
3+
import { UpdateOrderFormConfigurationRequest } from "./requests/UpdateOrderFormConfigurationRequest";
4+
5+
export class Configuration extends AbstractApi {
6+
private static readonly BASE_PATH: string =
7+
"/api/checkout/pvt/configuration/orderForm";
8+
9+
/**
10+
* Retrieves the settings that are currently applied to every orderForm in the account.
11+
* These settings are defined by the request Update orderForm configuration.
12+
* Always use this request to retrieve the current configuration before performing an update.
13+
* By doing so you ensure that you are modifying only the properties you want.
14+
*/
15+
getOrderFormConfiguration(): Promise<VtexHttpResponse> {
16+
return this.vtexHttpClient.performRequest(
17+
Configuration.BASE_PATH,
18+
this.HTTP_METHODS.GET
19+
);
20+
}
21+
22+
/**
23+
* Determines settings that will apply to every orderForm in the account. For example, if you create an app
24+
* using this request, every orderForm of this account will have the custom fields created though it.
25+
* Important: always retrieve the current configuration before performing an update to ensure that you are
26+
* modifying only the properties you want. Otherwise, old values can be overwritten. To retrieve the current
27+
* configuration, use the request Get orderForm configuration.
28+
* @param {UpdateOrderFormConfigurationRequest} data
29+
*/
30+
updateOrderFormConfiguration(
31+
data: UpdateOrderFormConfigurationRequest
32+
): Promise<VtexHttpResponse> {
33+
return this.vtexHttpClient.performRequest(
34+
Configuration.BASE_PATH,
35+
this.HTTP_METHODS.POST,
36+
data
37+
);
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./Configuration";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
interface PaymentConfiguration {
2+
requiresAuthenticationForPreAuthorizedPaymentOption?: boolean;
3+
allowInstallmentsMerge?: boolean;
4+
}
5+
6+
interface TaxConfiguration {
7+
url?: string;
8+
authorizationHeader?: string;
9+
allowExecutionAfterErrors?: boolean;
10+
integratedAuthentication?: boolean;
11+
appId?: string;
12+
}
13+
14+
interface Apps {
15+
id?: string;
16+
fields?: Array<string>;
17+
major?: number;
18+
}
19+
20+
export interface UpdateOrderFormConfigurationRequest {
21+
paymentConfiguration?: PaymentConfiguration;
22+
taxConfiguration?: TaxConfiguration;
23+
minimumQuantityAccumulatedForItems?: number;
24+
decimalDigitsPrecision?: number;
25+
minimumValueAccumulated?: number;
26+
apps?: Apps;
27+
allowMultipleDeliveries?: boolean;
28+
allowManualPrice?: boolean;
29+
maxNumberOfWhiteLabelSellers?: number;
30+
maskFirstPurchaseData?: boolean;
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { AbstractApi } from "../../../AbstractApi";
2+
import { VtexHttpResponse } from "../../../../utils/VtexHttpResponse";
3+
import { SetSingleCustomFieldValueRequest } from "./requests/SetSingleCustomFieldValueRequest";
4+
5+
export class CustomData extends AbstractApi {
6+
private static readonly BASE_PATH: string = "/api/checkout/pub/orderForm";
7+
8+
/**
9+
* Your account may create apps, which contain custom fields, through the Update orderForm configuration request.
10+
* The values of these custom fields can then be updated by this request.To do that, you need to inform the ID
11+
* of the app you created with the configuration API (appId). In the body of the request, for each field created
12+
* in this app (appFieldName) you will inform a value (appFieldValue).
13+
* @param {string} orderFormId
14+
* @param {string} appId
15+
* @param {object} data
16+
*/
17+
setMultipleCustomFieldValues(
18+
orderFormId: string,
19+
appId: string,
20+
data: object
21+
): Promise<VtexHttpResponse> {
22+
const path = `${CustomData.BASE_PATH}/${orderFormId}/customData/${appId}`;
23+
return this.vtexHttpClient.performRequest(
24+
path,
25+
this.HTTP_METHODS.PUT,
26+
data
27+
);
28+
}
29+
30+
/**
31+
* Your account may create apps, which contain custom fields, through the Update orderForm configuration request.
32+
* The value of a specific custom field can then be updated by this request. To do that, you need to inform in the
33+
* URL the ID of the app you created with the configuration API (appId).
34+
* In the body of the request, you will inform the new value (appFieldValue, passed through the body) of the
35+
* specific field created in this app (identified by the appFieldName parameter, passed through the URL).
36+
* @param {string} orderFormId
37+
* @param {string} appId
38+
* @param {string} appFieldName
39+
* @param {SetSingleCustomFieldValueRequest} data
40+
*/
41+
setSingleCustomFieldValue(
42+
orderFormId: string,
43+
appId: string,
44+
appFieldName: string,
45+
data: SetSingleCustomFieldValueRequest
46+
): Promise<VtexHttpResponse> {
47+
const path = `${CustomData.BASE_PATH}/${orderFormId}/customData/${appId}/${appFieldName}`;
48+
return this.vtexHttpClient.performRequest(
49+
path,
50+
this.HTTP_METHODS.PUT,
51+
data
52+
);
53+
}
54+
55+
/**
56+
* Your account may create apps, which contain custom fields, through the Update orderForm configuration request.
57+
* The value of a specific custom field can then be updated by this request. To do that, you need to inform in the
58+
* URL the ID of the app you created with the configuration API (appId).
59+
* You also need to iform the specific field created in this app (identified by the appFieldName parameter, also
60+
* passed through the URL) whose value you want to remove.
61+
* @param {string} orderFormId
62+
* @param {string} appId
63+
* @param {string} appFieldName
64+
*/
65+
deleteSingleCustomFieldValue(
66+
orderFormId: string,
67+
appId: string,
68+
appFieldName: string
69+
): Promise<VtexHttpResponse> {
70+
const path = `${CustomData.BASE_PATH}/${orderFormId}/customData/${appId}/${appFieldName}`;
71+
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.DELETE);
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./CustomData";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface SetSingleCustomFieldValueRequest {
2+
value?: any;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { AbstractApi } from "../../../AbstractApi";
2+
import { VtexHttpResponse } from "../../../../utils/VtexHttpResponse";
3+
import { DoOrderFormSimulationRequest } from "./requests/DoOrderFormSimulationRequest";
4+
5+
export class OrderForm extends AbstractApi {
6+
private static readonly BASE_PATH: string = "/api/checkout";
7+
8+
/**
9+
* The orderForm simulation endpoint is used to simulate a cart in VTEX Checkout. It receives an SKU ID,
10+
* the quantity of items in the cart, the ID of the Seller and the country in ISO ALPHA-3 Code (eg. BRA, USA, ARG).
11+
* It sends back all information about the cart, such as the selling price of each item, rates and benefits data,
12+
* payment and logistics info. This is useful whenever you need to know the avaiability of fulfilling an order
13+
* for a specific cart setting, since the API response will let you know the updated price, inventory and
14+
* shipping data.
15+
* @param {DoOrderFormSimulationRequest} data
16+
*/
17+
doOrderFormSimulation(
18+
data: DoOrderFormSimulationRequest
19+
): Promise<VtexHttpResponse> {
20+
const path = `${OrderForm.BASE_PATH}/pub/orderforms/simulation`;
21+
return this.vtexHttpClient.performRequest(
22+
path,
23+
this.HTTP_METHODS.POST,
24+
data
25+
);
26+
}
27+
28+
/**
29+
* This call removes all items from a given cart, leaving it empty. The ID of the specific cart whose
30+
* items you want to remove is passed as an URL paramater, replacing the variable orderFormId in this example.
31+
* The orderFormId is the identification number of a given cart. That is, it's the ID of a specific orderForm.
32+
* @param {string} orderFormId
33+
*/
34+
removeAllItems(orderFormId: string): Promise<VtexHttpResponse> {
35+
const path = `${OrderForm.BASE_PATH}/pub/orderform/${orderFormId}/items/removeAll`;
36+
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.POST, {});
37+
}
38+
39+
/**
40+
* This call removes all user information, leaving the orderForm anonymous. That is, it keeps the items of
41+
* the cart in the orderForm. This call works by creating a new orderForm, setting a new cookie and returning
42+
* a redirect 302 to the cart URL (/checkout/#/orderform).
43+
* @param {string} orderFormId
44+
*/
45+
removeAllPersonalData(orderFormId: string): Promise<VtexHttpResponse> {
46+
const path = `${OrderForm.BASE_PATH}/changeToAnonymousUser/${orderFormId}`;
47+
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.GET);
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./OrderForm";

0 commit comments

Comments
 (0)