Skip to content

Commit

Permalink
Merge pull request #34 from onready/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Juan Cernadas authored Jul 13, 2020
2 parents 04423fd + 3cf3b9f commit 69b1e90
Show file tree
Hide file tree
Showing 47 changed files with 1,392 additions and 63 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ CMS | :white_check_mark: |
Session Manager | :white_check_mark: |
License Manager | :white_check_mark: |
Customer Credit | :white_check_mark: |
Subscriptions (V2) | :white_check_mark: |
Rates and Benefits | :white_check_mark: |
Checkout | :white_check_mark: |
Antifraud Provider | :x: |
Checkout | :x: |
Giftcard | :x: |
Giftcard Hub | :x: |
Giftcard Provider Protocol | :x: |
Payment Provider Protocol | :x: |
Rates and Benefits | :x: |
Subscriptions (V2) | :x: |
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.12.0-beta",
"version": "1.15.0-beta",
"description": "VTEX Node SDK, built 100% with Typescript and 0 dependencies!",
"author": "Onready",
"private": false,
Expand Down Expand Up @@ -41,10 +41,10 @@
"@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.6.0",
"@typescript-eslint/parser": "3.6.0",
"@types/jest": "26.0.4",
"@types/node": "14.0.23",
"@typescript-eslint/eslint-plugin": "3.6.1",
"@typescript-eslint/parser": "3.6.1",
"babel-jest": "26.1.0",
"eslint": "7.4.0",
"eslint-config-airbnb-base": "14.2.0",
Expand All @@ -56,7 +56,7 @@
"nock": "13.0.2",
"prettier": "2.0.5",
"rimraf": "3.0.2",
"ts-jest": "26.1.1",
"ts-jest": "26.1.2",
"typescript": "3.9.6"
},
"engines": {
Expand Down
21 changes: 21 additions & 0 deletions src/VTEX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import { CMS } from "./modules/CMS";
import { SessionManager } from "./modules/session-manager";
import { LicenseManager } from "./modules/license-manager";
import { CustomerCredit } from "./modules/customer-credit";
import { Subscriptions } from "./modules/subscriptions/v2";
import { RatesAndBenefits } from "./modules/rates-and-benefits";
import { Checkout } from "./modules/checkout";

export class VTEX {
private static buildErrorMessage(paramName: string): string {
Expand Down Expand Up @@ -105,6 +108,21 @@ export class VTEX {
*/
readonly customerCredit: CustomerCredit;

/**
* Subscriptions (V2) Module
*/
readonly subscriptions: Subscriptions;

/**
* Rates and Benefits Module
*/
readonly ratesAndBenefits: RatesAndBenefits;

/**
* Checkout Module
*/
readonly checkout: Checkout;

/**
* @param {string} store
* @param {string} appKey
Expand Down Expand Up @@ -142,5 +160,8 @@ export class VTEX {
this.sessionManager = new SessionManager(vtexHttpClient);
this.licenseManager = new LicenseManager(vtexHttpClient);
this.customerCredit = new CustomerCredit(vtexHttpClient);
this.subscriptions = new Subscriptions(vtexHttpClient);
this.ratesAndBenefits = new RatesAndBenefits(vtexHttpClient);
this.checkout = new Checkout(vtexHttpClient);
}
}
34 changes: 34 additions & 0 deletions src/modules/checkout/Checkout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { VtexHttpClient } from "../../utils/VtexHttpClient";
import { OrderForm } from "./apis/order-form";
import { CartUpdate } from "./apis/cart-update";
import { CustomData } from "./apis/custom-data";
import { Configuration } from "./apis/configuration";

export class Checkout {
/**
* Order Form API
*/
readonly orderForm: OrderForm;

/**
* Cart Update API
*/
readonly cartUpdate: CartUpdate;

/**
* Custom Data API
*/
readonly customData: CustomData;

/**
* Configuration API
*/
readonly configuration: Configuration;

constructor(vtexHttpClient: VtexHttpClient) {
this.orderForm = new OrderForm(vtexHttpClient);
this.cartUpdate = new CartUpdate(vtexHttpClient);
this.customData = new CustomData(vtexHttpClient);
this.configuration = new Configuration(vtexHttpClient);
}
}
52 changes: 52 additions & 0 deletions src/modules/checkout/apis/cart-update/CartUpdate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { AbstractApi } from "../../../AbstractApi";
import { VtexHttpResponse } from "../../../../utils/VtexHttpResponse";
import { UpdateCartItemsRequest } from "./requests/UpdateCartItemsRequest";
import { ChangePriceRequest } from "./requests/ChangePriceRequest";

export class CartUpdate extends AbstractApi {
private static readonly BASE_PATH: string = "/api/checkout/pub/orderForm";

/**
* With the Items Update request you can:
* 1) Add items to the cart
* 2) Change the quantity of one or more items in a specific cart
* 3) Remove items from the cart (by changing their quantity to 0).
* @param {string} orderFormId
* @param {UpdateCartItemsRequest} data
*/
updateCartItems(
orderFormId: string,
data: UpdateCartItemsRequest
): Promise<VtexHttpResponse> {
const path = `${CartUpdate.BASE_PATH}/${orderFormId}/items`;
return this.vtexHttpClient.performRequest(
path,
this.HTTP_METHODS.PATCH,
data
);
}

/**
* This request changes the price of a specific item in a cart. You need to inform which cart you are
* referring to, by sending its orderFormID; and what is the item whose price you want to change, by
* sending its itemIndex. You also need to pass the new price value in the body. Remember that, to
* use this endpoint, the feature of manual price must be active. To check if it's active, use the
* Get orderForm configuration endpoint. To make it active, use the Update orderForm configuration
* endpoint, making the allowManualPrice field true.
* @param {string} orderFormId
* @param {number} itemIndex
* @param {ChangePriceRequest} data
*/
changePrice(
orderFormId: string,
itemIndex: number,
data: ChangePriceRequest
): Promise<VtexHttpResponse> {
const path = `${CartUpdate.BASE_PATH}/${orderFormId}/items/${itemIndex}/price`;
return this.vtexHttpClient.performRequest(
path,
this.HTTP_METHODS.PUT,
data
);
}
}
1 change: 1 addition & 0 deletions src/modules/checkout/apis/cart-update/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./CartUpdate";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface ChangePriceRequest {
price?: number;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
interface OrderItem {
quantity?: number;
index?: number;
seller?: string;
id?: string;
}

export interface UpdateCartItemsRequest {
orderItems?: Array<OrderItem>;
}
39 changes: 39 additions & 0 deletions src/modules/checkout/apis/configuration/Configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { AbstractApi } from "../../../AbstractApi";
import { VtexHttpResponse } from "../../../../utils/VtexHttpResponse";
import { UpdateOrderFormConfigurationRequest } from "./requests/UpdateOrderFormConfigurationRequest";

export class Configuration extends AbstractApi {
private static readonly BASE_PATH: string =
"/api/checkout/pvt/configuration/orderForm";

/**
* Retrieves the settings that are currently applied to every orderForm in the account.
* These settings are defined by the request Update orderForm configuration.
* Always use this request to retrieve the current configuration before performing an update.
* By doing so you ensure that you are modifying only the properties you want.
*/
getOrderFormConfiguration(): Promise<VtexHttpResponse> {
return this.vtexHttpClient.performRequest(
Configuration.BASE_PATH,
this.HTTP_METHODS.GET
);
}

/**
* Determines settings that will apply to every orderForm in the account. For example, if you create an app
* using this request, every orderForm of this account will have the custom fields created though it.
* Important: always retrieve the current configuration before performing an update to ensure that you are
* modifying only the properties you want. Otherwise, old values can be overwritten. To retrieve the current
* configuration, use the request Get orderForm configuration.
* @param {UpdateOrderFormConfigurationRequest} data
*/
updateOrderFormConfiguration(
data: UpdateOrderFormConfigurationRequest
): Promise<VtexHttpResponse> {
return this.vtexHttpClient.performRequest(
Configuration.BASE_PATH,
this.HTTP_METHODS.POST,
data
);
}
}
1 change: 1 addition & 0 deletions src/modules/checkout/apis/configuration/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Configuration";
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
interface PaymentConfiguration {
requiresAuthenticationForPreAuthorizedPaymentOption?: boolean;
allowInstallmentsMerge?: boolean;
}

interface TaxConfiguration {
url?: string;
authorizationHeader?: string;
allowExecutionAfterErrors?: boolean;
integratedAuthentication?: boolean;
appId?: string;
}

interface Apps {
id?: string;
fields?: Array<string>;
major?: number;
}

export interface UpdateOrderFormConfigurationRequest {
paymentConfiguration?: PaymentConfiguration;
taxConfiguration?: TaxConfiguration;
minimumQuantityAccumulatedForItems?: number;
decimalDigitsPrecision?: number;
minimumValueAccumulated?: number;
apps?: Apps;
allowMultipleDeliveries?: boolean;
allowManualPrice?: boolean;
maxNumberOfWhiteLabelSellers?: number;
maskFirstPurchaseData?: boolean;
}
73 changes: 73 additions & 0 deletions src/modules/checkout/apis/custom-data/CustomData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { AbstractApi } from "../../../AbstractApi";
import { VtexHttpResponse } from "../../../../utils/VtexHttpResponse";
import { SetSingleCustomFieldValueRequest } from "./requests/SetSingleCustomFieldValueRequest";

export class CustomData extends AbstractApi {
private static readonly BASE_PATH: string = "/api/checkout/pub/orderForm";

/**
* Your account may create apps, which contain custom fields, through the Update orderForm configuration request.
* The values of these custom fields can then be updated by this request.To do that, you need to inform the ID
* of the app you created with the configuration API (appId). In the body of the request, for each field created
* in this app (appFieldName) you will inform a value (appFieldValue).
* @param {string} orderFormId
* @param {string} appId
* @param {object} data
*/
setMultipleCustomFieldValues(
orderFormId: string,
appId: string,
data: object
): Promise<VtexHttpResponse> {
const path = `${CustomData.BASE_PATH}/${orderFormId}/customData/${appId}`;
return this.vtexHttpClient.performRequest(
path,
this.HTTP_METHODS.PUT,
data
);
}

/**
* Your account may create apps, which contain custom fields, through the Update orderForm configuration request.
* The value of a specific custom field can then be updated by this request. To do that, you need to inform in the
* URL the ID of the app you created with the configuration API (appId).
* In the body of the request, you will inform the new value (appFieldValue, passed through the body) of the
* specific field created in this app (identified by the appFieldName parameter, passed through the URL).
* @param {string} orderFormId
* @param {string} appId
* @param {string} appFieldName
* @param {SetSingleCustomFieldValueRequest} data
*/
setSingleCustomFieldValue(
orderFormId: string,
appId: string,
appFieldName: string,
data: SetSingleCustomFieldValueRequest
): Promise<VtexHttpResponse> {
const path = `${CustomData.BASE_PATH}/${orderFormId}/customData/${appId}/${appFieldName}`;
return this.vtexHttpClient.performRequest(
path,
this.HTTP_METHODS.PUT,
data
);
}

/**
* Your account may create apps, which contain custom fields, through the Update orderForm configuration request.
* The value of a specific custom field can then be updated by this request. To do that, you need to inform in the
* URL the ID of the app you created with the configuration API (appId).
* You also need to iform the specific field created in this app (identified by the appFieldName parameter, also
* passed through the URL) whose value you want to remove.
* @param {string} orderFormId
* @param {string} appId
* @param {string} appFieldName
*/
deleteSingleCustomFieldValue(
orderFormId: string,
appId: string,
appFieldName: string
): Promise<VtexHttpResponse> {
const path = `${CustomData.BASE_PATH}/${orderFormId}/customData/${appId}/${appFieldName}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.DELETE);
}
}
1 change: 1 addition & 0 deletions src/modules/checkout/apis/custom-data/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./CustomData";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface SetSingleCustomFieldValueRequest {
value?: any;
}
49 changes: 49 additions & 0 deletions src/modules/checkout/apis/order-form/OrderForm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { AbstractApi } from "../../../AbstractApi";
import { VtexHttpResponse } from "../../../../utils/VtexHttpResponse";
import { DoOrderFormSimulationRequest } from "./requests/DoOrderFormSimulationRequest";

export class OrderForm extends AbstractApi {
private static readonly BASE_PATH: string = "/api/checkout";

/**
* The orderForm simulation endpoint is used to simulate a cart in VTEX Checkout. It receives an SKU ID,
* the quantity of items in the cart, the ID of the Seller and the country in ISO ALPHA-3 Code (eg. BRA, USA, ARG).
* It sends back all information about the cart, such as the selling price of each item, rates and benefits data,
* payment and logistics info. This is useful whenever you need to know the avaiability of fulfilling an order
* for a specific cart setting, since the API response will let you know the updated price, inventory and
* shipping data.
* @param {DoOrderFormSimulationRequest} data
*/
doOrderFormSimulation(
data: DoOrderFormSimulationRequest
): Promise<VtexHttpResponse> {
const path = `${OrderForm.BASE_PATH}/pub/orderforms/simulation`;
return this.vtexHttpClient.performRequest(
path,
this.HTTP_METHODS.POST,
data
);
}

/**
* This call removes all items from a given cart, leaving it empty. The ID of the specific cart whose
* items you want to remove is passed as an URL paramater, replacing the variable orderFormId in this example.
* The orderFormId is the identification number of a given cart. That is, it's the ID of a specific orderForm.
* @param {string} orderFormId
*/
removeAllItems(orderFormId: string): Promise<VtexHttpResponse> {
const path = `${OrderForm.BASE_PATH}/pub/orderform/${orderFormId}/items/removeAll`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.POST, {});
}

/**
* This call removes all user information, leaving the orderForm anonymous. That is, it keeps the items of
* the cart in the orderForm. This call works by creating a new orderForm, setting a new cookie and returning
* a redirect 302 to the cart URL (/checkout/#/orderform).
* @param {string} orderFormId
*/
removeAllPersonalData(orderFormId: string): Promise<VtexHttpResponse> {
const path = `${OrderForm.BASE_PATH}/changeToAnonymousUser/${orderFormId}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.GET);
}
}
1 change: 1 addition & 0 deletions src/modules/checkout/apis/order-form/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./OrderForm";
Loading

0 comments on commit 69b1e90

Please sign in to comment.