From c200a86af9bde98297e359374f398ca57f5e4eac Mon Sep 17 00:00:00 2001 From: Kishan Nath Date: Fri, 6 Oct 2023 14:40:53 +0530 Subject: [PATCH 1/5] added Cart endpoints --- .../endpoints/V3/Cart/CartLineItems.ts | 62 +++++++++++++++++++ .../endpoints/V3/Cart/CartRedirect.ts | 21 +++++++ .../endpoints/V3/Cart/CartSettingsChannel.ts | 25 ++++++++ .../endpoints/V3/Cart/CartSettingsGlobal.ts | 25 ++++++++ src/RestClient/endpoints/V3/Cart/Carts.ts | 62 +++++++++++++++++++ src/RestClient/endpoints/V3/Cart/index.ts | 25 ++++++++ src/RestClient/endpoints/V3/Cart/types.ts | 61 ++++++++++++++++++ src/RestClient/endpoints/V3/index.ts | 3 + 8 files changed, 284 insertions(+) create mode 100644 src/RestClient/endpoints/V3/Cart/CartLineItems.ts create mode 100644 src/RestClient/endpoints/V3/Cart/CartRedirect.ts create mode 100644 src/RestClient/endpoints/V3/Cart/CartSettingsChannel.ts create mode 100644 src/RestClient/endpoints/V3/Cart/CartSettingsGlobal.ts create mode 100644 src/RestClient/endpoints/V3/Cart/Carts.ts create mode 100644 src/RestClient/endpoints/V3/Cart/index.ts create mode 100644 src/RestClient/endpoints/V3/Cart/types.ts diff --git a/src/RestClient/endpoints/V3/Cart/CartLineItems.ts b/src/RestClient/endpoints/V3/Cart/CartLineItems.ts new file mode 100644 index 0000000..2e602f4 --- /dev/null +++ b/src/RestClient/endpoints/V3/Cart/CartLineItems.ts @@ -0,0 +1,62 @@ +import { AxiosInstance } from 'axios'; + +import { AxiosPromise } from '../../../../types'; + +import { getCartsPath } from './Carts'; +import type { CartLineItem } from './types'; + +const cartLineItemsPath = '/items'; + +/** + * Builds a base CartLineItems API path given an optional cartLineItem ID + * + * @param cartId The cart ID + * @param id Optional filter parameters + * @returns Returns either '/v3/cart/:cartId/items' or '/v3/cart/:cartId/items/:itemId + */ +export const getCartLineItemsPath = (cartId: string, id?: string): string => + `${getCartsPath(cartId)}/${cartLineItemsPath}/${id ?? ''}`; + +class CartLineItems { + private client: AxiosInstance; + + constructor(client: AxiosInstance) { + this.client = client; + } + + /** + * Creates a new cartLineItem + * + * @param data Data used to create the cartLineItem + * @returns Promise resolving to a newly created cartLineItem + */ + create(cartId: string, data: CartLineItem['CreateRequest']): CartLineItem['CreateResponse'] { + return this.client.post(getCartLineItemsPath(cartId), data); + } + + /** + * Updates an existing cartLineItem + * + * @param id The cartLineItem ID + * @param data Data used to update the cartLineItem + * @returns Promise resolving to an updated cartLineItem + */ + update(cartId: string, id: string, data: CartLineItem['UpdateRequest']): CartLineItem['UpdateResponse'] { + return this.client.put(getCartLineItemsPath(cartId, id), data); + } + + /** + * Deletes a single cartLineItem by ID + * + * @param id The cartLineItem ID + * @param params Query params used to delete cartLineItem + * @returns Promise resolving to a 204 No Content response + */ + delete(cartId: string, id: string, params: CartLineItem['DeleteRequest']): AxiosPromise { + return this.client.delete(getCartLineItemsPath(cartId, id), { + params, + }); + } +} + +export default CartLineItems; diff --git a/src/RestClient/endpoints/V3/Cart/CartRedirect.ts b/src/RestClient/endpoints/V3/Cart/CartRedirect.ts new file mode 100644 index 0000000..b5c7ef9 --- /dev/null +++ b/src/RestClient/endpoints/V3/Cart/CartRedirect.ts @@ -0,0 +1,21 @@ +import { AxiosInstance } from 'axios'; + +import { AxiosPromise } from '../../../../types'; + +import type { CartRedirect } from './types'; + +const cartRedirectPath = '/v3/carts'; + +export const getCartRedirectPath = (cartId: string): string => `${cartRedirectPath}/${cartId}/redirect_urls`; + +export default class CartSettingsGlobalEndpoint { + private client: AxiosInstance; + + constructor(client: AxiosInstance) { + this.client = client; + } + + public get(cartId: string): AxiosPromise { + return this.client.get(getCartRedirectPath(cartId)); + } +} diff --git a/src/RestClient/endpoints/V3/Cart/CartSettingsChannel.ts b/src/RestClient/endpoints/V3/Cart/CartSettingsChannel.ts new file mode 100644 index 0000000..a5d98ed --- /dev/null +++ b/src/RestClient/endpoints/V3/Cart/CartSettingsChannel.ts @@ -0,0 +1,25 @@ +import { AxiosInstance } from 'axios'; + +import { AxiosPromise } from '../../../../types'; + +import type { CartSettingsChannel } from './types'; + +const channelSettingsPath = '/v3/carts/settings/channel'; + +export const getCartSettingsChannelPath = (channelId: string): string => `${channelSettingsPath}/${channelId}`; + +export default class CartSettingsChannelEndpoint { + private client: AxiosInstance; + + constructor(client: AxiosInstance) { + this.client = client; + } + + public get(channelId: string): AxiosPromise { + return this.client.get(getCartSettingsChannelPath(channelId)); + } + + public update(channelId: string, data: CartSettingsChannel['UpdateRequest']): CartSettingsChannel['UpdateResponse'] { + return this.client.put(getCartSettingsChannelPath(channelId), data); + } +} diff --git a/src/RestClient/endpoints/V3/Cart/CartSettingsGlobal.ts b/src/RestClient/endpoints/V3/Cart/CartSettingsGlobal.ts new file mode 100644 index 0000000..3b3eecf --- /dev/null +++ b/src/RestClient/endpoints/V3/Cart/CartSettingsGlobal.ts @@ -0,0 +1,25 @@ +import { AxiosInstance } from 'axios'; + +import { AxiosPromise } from '../../../../types'; + +import type { CartSettingsGlobal } from './types'; + +const cartSettingsGlobalPath = '/v3/carts/settings'; + +export const getCartSettingsGlobalPath = (): string => `${cartSettingsGlobalPath}`; + +export default class CartSettingsGlobalEndpoint { + private client: AxiosInstance; + + constructor(client: AxiosInstance) { + this.client = client; + } + + public get(): AxiosPromise { + return this.client.get(getCartSettingsGlobalPath()); + } + + public update(data: CartSettingsGlobal['UpdateRequest']): CartSettingsGlobal['UpdateResponse'] { + return this.client.put(getCartSettingsGlobalPath(), data); + } +} diff --git a/src/RestClient/endpoints/V3/Cart/Carts.ts b/src/RestClient/endpoints/V3/Cart/Carts.ts new file mode 100644 index 0000000..c3d463f --- /dev/null +++ b/src/RestClient/endpoints/V3/Cart/Carts.ts @@ -0,0 +1,62 @@ +import { AxiosInstance } from 'axios'; + +import { AxiosPromise } from '../../../../types'; + +import type { Cart } from './types'; + +const cartsPath = '/v3/carts'; + +/** + * Builds a base Carts API path given an optional cart ID + * + * @param id Optional filter parameters + * @returns Returns either '/v3/carts' or '/v3/carts/:cartId + */ + +export const getCartsPath = (id?: string): string => `${cartsPath}/${id ?? ''}`; + +class Carts { + private client: AxiosInstance; + + constructor(client: AxiosInstance) { + this.client = client; + } + + /** + * Creates a new cart + * + * @param data Data used to create the cart + * @returns Promise resolving to a newly created cart + */ + create(data: Cart['CreateRequest']): Cart['CreateResponse'] { + return this.client.post(getCartsPath(), data); + } + + /** + * Gets a single cart by ID + * + * @param id The cart ID + * @param params Query params used to get cart + * @returns Promise resolving to a cart + */ + get(id: string, params: Cart['GetRequest']): Cart['GetResponse'] { + return this.client.get(getCartsPath(id), { + params, + }); + } + + /** + * Deletes a single cart by ID + * + * @param id The cart ID + * @param params Query params used to delete cart + * @returns Promise resolving to a 204 No Content response + */ + delete(id: string, params: Cart['DeleteRequest']): AxiosPromise { + return this.client.delete(getCartsPath(id), { + params, + }); + } +} + +export default Carts; diff --git a/src/RestClient/endpoints/V3/Cart/index.ts b/src/RestClient/endpoints/V3/Cart/index.ts new file mode 100644 index 0000000..151512c --- /dev/null +++ b/src/RestClient/endpoints/V3/Cart/index.ts @@ -0,0 +1,25 @@ +import { AxiosInstance } from 'axios'; + +import CartLineItems from './CartLineItems'; +import CartRedirect from './CartRedirect'; +import Carts from './Carts'; +import CartSettingsChannel from './CartSettingsChannel'; +import CartSettingsGlobal from './CartSettingsGlobal'; + +class CartsV3 { + public carts: Carts; + public cartLineItems: CartLineItems; + public cartRedirect: CartRedirect; + public cartSettingsGlobal: CartSettingsGlobal; + public cartSettingsChannel: CartSettingsChannel; + + constructor(client: AxiosInstance) { + this.carts = new Carts(client); + this.cartLineItems = new CartLineItems(client); + this.cartRedirect = new CartRedirect(client); + this.cartSettingsGlobal = new CartSettingsGlobal(client); + this.cartSettingsChannel = new CartSettingsChannel(client); + } +} + +export default CartsV3; diff --git a/src/RestClient/endpoints/V3/Cart/types.ts b/src/RestClient/endpoints/V3/Cart/types.ts new file mode 100644 index 0000000..df2310c --- /dev/null +++ b/src/RestClient/endpoints/V3/Cart/types.ts @@ -0,0 +1,61 @@ +import { operations } from '../../../../generate/generated/carts.v3'; +import { AxiosPromise } from '../../../../types'; + +export interface Cart { + CreateRequest: operations['createACart']['requestBody']['content']['application/json']; + CreateResponse: AxiosPromise; + GetRequest: operations['getACart']['parameters']['path']; + GetResponse: AxiosPromise; + DeleteRequest: operations['deleteACart']['parameters']['path']; + DeleteResponse: AxiosPromise; +} + +export interface CartLineItem { + CreateRequest: operations['addCartLineItem']['requestBody']['content']['application/json']; + CreateResponse: AxiosPromise; + UpdateRequest: operations['updateCartLineItem']['parameters']['path']; + UpdateResponse: AxiosPromise; + DeleteRequest: operations['deleteCartLineItem']['parameters']['path']; + DeleteResponse: AxiosPromise; +} + +export interface CartMetaField { + ListRequest: operations['getAllCartMetafields']['parameters']['path']; + ListResponse: AxiosPromise; + GetRequest: operations['getACartMetafield']['parameters']['path']; + GetResponse: AxiosPromise; + CreateRequest: operations['CreateCartMetafieldsByCartId']['requestBody']['content']['application/json']; + CreateResponse: AxiosPromise< + operations['CreateCartMetafieldsByCartId']['responses']['200']['content']['application/json'] + >; + UpdateRequest: operations['UpdateCartMetafieldsByCartId']['parameters']['path']; + UpdateResponse: AxiosPromise< + operations['UpdateCartMetafieldsByCartId']['responses']['200']['content']['application/json'] + >; + DeleteRequest: operations['deleteCartMetafieldById']['parameters']['path']; + DeleteResponse: AxiosPromise< + operations['deleteCartMetafieldById']['responses']['204']['content']['application/json'] + >; +} + +export interface CartRedirect { + CreateRequest: operations['createCartRedirectURL']['parameters']['path']; + CreateResponse: AxiosPromise; +} + +export interface CartSettingsGlobal { + GetResponse: AxiosPromise; + UpdateRequest: operations['updateGlobalCartSettings']['requestBody']['content']['application/json']; + UpdateResponse: AxiosPromise< + operations['updateGlobalCartSettings']['responses']['200']['content']['application/json'] + >; +} + +export interface CartSettingsChannel { + GetRequest: operations['getChannelCartSettings']['parameters']['path']; + GetResponse: AxiosPromise; + UpdateRequest: operations['updateChannelCartSettings']['parameters']['path']; + UpdateResponse: AxiosPromise< + operations['updateChannelCartSettings']['responses']['200']['content']['application/json'] + >; +} diff --git a/src/RestClient/endpoints/V3/index.ts b/src/RestClient/endpoints/V3/index.ts index aa934f8..adffc38 100644 --- a/src/RestClient/endpoints/V3/index.ts +++ b/src/RestClient/endpoints/V3/index.ts @@ -1,5 +1,6 @@ import { AxiosInstance } from 'axios'; +import CartsV3 from './Cart/Carts'; import CatalogV3 from './Catalog'; import CustomersV3 from './Customers'; import ThemesV3 from './Themes'; @@ -8,12 +9,14 @@ class V3 { private client: AxiosInstance; public catalog: CatalogV3; + public carts: CartsV3; public customers: CustomersV3; public themes: ThemesV3; constructor(client: AxiosInstance) { this.client = client; this.catalog = new CatalogV3(this.client); + this.carts = new CartsV3(this.client); this.customers = new CustomersV3(this.client); this.themes = new ThemesV3(this.client); } From 75002d83ad54227822e2a6962b0742a9dc272db6 Mon Sep 17 00:00:00 2001 From: Kishan Nath Date: Sat, 7 Oct 2023 18:31:11 +0530 Subject: [PATCH 2/5] fixed cart endpoit imports - fixed cart get params --- src/RestClient/endpoints/V3/Cart/CartLineItems.ts | 5 ++++- src/RestClient/endpoints/V3/Cart/Carts.ts | 4 ++-- src/RestClient/endpoints/V3/index.ts | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/RestClient/endpoints/V3/Cart/CartLineItems.ts b/src/RestClient/endpoints/V3/Cart/CartLineItems.ts index 2e602f4..47f330a 100644 --- a/src/RestClient/endpoints/V3/Cart/CartLineItems.ts +++ b/src/RestClient/endpoints/V3/Cart/CartLineItems.ts @@ -27,6 +27,7 @@ class CartLineItems { /** * Creates a new cartLineItem * + * @param cartId The cart ID * @param data Data used to create the cartLineItem * @returns Promise resolving to a newly created cartLineItem */ @@ -37,6 +38,7 @@ class CartLineItems { /** * Updates an existing cartLineItem * + * @param cartId The cart ID * @param id The cartLineItem ID * @param data Data used to update the cartLineItem * @returns Promise resolving to an updated cartLineItem @@ -48,11 +50,12 @@ class CartLineItems { /** * Deletes a single cartLineItem by ID * + * @param cartId The cart ID * @param id The cartLineItem ID * @param params Query params used to delete cartLineItem * @returns Promise resolving to a 204 No Content response */ - delete(cartId: string, id: string, params: CartLineItem['DeleteRequest']): AxiosPromise { + delete(cartId: string, id: string, params?: CartLineItem['DeleteRequest']): AxiosPromise { return this.client.delete(getCartLineItemsPath(cartId, id), { params, }); diff --git a/src/RestClient/endpoints/V3/Cart/Carts.ts b/src/RestClient/endpoints/V3/Cart/Carts.ts index c3d463f..aa91c55 100644 --- a/src/RestClient/endpoints/V3/Cart/Carts.ts +++ b/src/RestClient/endpoints/V3/Cart/Carts.ts @@ -39,7 +39,7 @@ class Carts { * @param params Query params used to get cart * @returns Promise resolving to a cart */ - get(id: string, params: Cart['GetRequest']): Cart['GetResponse'] { + get(id: string, params?: Cart['GetRequest']): Cart['GetResponse'] { return this.client.get(getCartsPath(id), { params, }); @@ -52,7 +52,7 @@ class Carts { * @param params Query params used to delete cart * @returns Promise resolving to a 204 No Content response */ - delete(id: string, params: Cart['DeleteRequest']): AxiosPromise { + delete(id: string, params?: Cart['DeleteRequest']): AxiosPromise { return this.client.delete(getCartsPath(id), { params, }); diff --git a/src/RestClient/endpoints/V3/index.ts b/src/RestClient/endpoints/V3/index.ts index adffc38..2de1aed 100644 --- a/src/RestClient/endpoints/V3/index.ts +++ b/src/RestClient/endpoints/V3/index.ts @@ -1,6 +1,6 @@ import { AxiosInstance } from 'axios'; -import CartsV3 from './Cart/Carts'; +import CartsV3 from './Cart'; import CatalogV3 from './Catalog'; import CustomersV3 from './Customers'; import ThemesV3 from './Themes'; From 7bed1c276202a80cef926b1402b430b245d311ab Mon Sep 17 00:00:00 2001 From: Kishan Nath Date: Mon, 9 Oct 2023 20:20:25 +0530 Subject: [PATCH 3/5] fixed update CartLineItem --- src/RestClient/endpoints/V3/Cart/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RestClient/endpoints/V3/Cart/types.ts b/src/RestClient/endpoints/V3/Cart/types.ts index df2310c..0857abd 100644 --- a/src/RestClient/endpoints/V3/Cart/types.ts +++ b/src/RestClient/endpoints/V3/Cart/types.ts @@ -13,7 +13,7 @@ export interface Cart { export interface CartLineItem { CreateRequest: operations['addCartLineItem']['requestBody']['content']['application/json']; CreateResponse: AxiosPromise; - UpdateRequest: operations['updateCartLineItem']['parameters']['path']; + UpdateRequest: operations['updateCartLineItem']['requestBody']['content']['application/json']; UpdateResponse: AxiosPromise; DeleteRequest: operations['deleteCartLineItem']['parameters']['path']; DeleteResponse: AxiosPromise; From 816e96400258657e10320e56730bb5e02a92d1d7 Mon Sep 17 00:00:00 2001 From: Kishan Nath Date: Tue, 10 Oct 2023 13:33:44 +0530 Subject: [PATCH 4/5] fixed cart paths --- src/RestClient/endpoints/V3/Cart/CartLineItems.ts | 3 ++- src/RestClient/endpoints/V3/Cart/Carts.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/RestClient/endpoints/V3/Cart/CartLineItems.ts b/src/RestClient/endpoints/V3/Cart/CartLineItems.ts index 47f330a..9856fe0 100644 --- a/src/RestClient/endpoints/V3/Cart/CartLineItems.ts +++ b/src/RestClient/endpoints/V3/Cart/CartLineItems.ts @@ -7,6 +7,7 @@ import type { CartLineItem } from './types'; const cartLineItemsPath = '/items'; +const getItemPath = (itemId?: string): string => (itemId ? `${cartLineItemsPath}/${itemId}` : cartLineItemsPath); /** * Builds a base CartLineItems API path given an optional cartLineItem ID * @@ -15,7 +16,7 @@ const cartLineItemsPath = '/items'; * @returns Returns either '/v3/cart/:cartId/items' or '/v3/cart/:cartId/items/:itemId */ export const getCartLineItemsPath = (cartId: string, id?: string): string => - `${getCartsPath(cartId)}/${cartLineItemsPath}/${id ?? ''}`; + `${getCartsPath(cartId)}/${getItemPath(id)}}`; class CartLineItems { private client: AxiosInstance; diff --git a/src/RestClient/endpoints/V3/Cart/Carts.ts b/src/RestClient/endpoints/V3/Cart/Carts.ts index aa91c55..8ef1064 100644 --- a/src/RestClient/endpoints/V3/Cart/Carts.ts +++ b/src/RestClient/endpoints/V3/Cart/Carts.ts @@ -13,7 +13,7 @@ const cartsPath = '/v3/carts'; * @returns Returns either '/v3/carts' or '/v3/carts/:cartId */ -export const getCartsPath = (id?: string): string => `${cartsPath}/${id ?? ''}`; +export const getCartsPath = (id?: string): string => (id ? `${cartsPath}/${id}` : cartsPath); class Carts { private client: AxiosInstance; From 714a42e4bf373e59de39adcd77baaf213e4eb424 Mon Sep 17 00:00:00 2001 From: Kishan Nath Date: Wed, 11 Oct 2023 12:16:43 +0530 Subject: [PATCH 5/5] fixed cart line items path --- src/RestClient/endpoints/V3/Cart/CartLineItems.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/RestClient/endpoints/V3/Cart/CartLineItems.ts b/src/RestClient/endpoints/V3/Cart/CartLineItems.ts index 9856fe0..a42ea15 100644 --- a/src/RestClient/endpoints/V3/Cart/CartLineItems.ts +++ b/src/RestClient/endpoints/V3/Cart/CartLineItems.ts @@ -5,7 +5,7 @@ import { AxiosPromise } from '../../../../types'; import { getCartsPath } from './Carts'; import type { CartLineItem } from './types'; -const cartLineItemsPath = '/items'; +const cartLineItemsPath = 'items'; const getItemPath = (itemId?: string): string => (itemId ? `${cartLineItemsPath}/${itemId}` : cartLineItemsPath); /** @@ -16,7 +16,7 @@ const getItemPath = (itemId?: string): string => (itemId ? `${cartLineItemsPath} * @returns Returns either '/v3/cart/:cartId/items' or '/v3/cart/:cartId/items/:itemId */ export const getCartLineItemsPath = (cartId: string, id?: string): string => - `${getCartsPath(cartId)}/${getItemPath(id)}}`; + `${getCartsPath(cartId)}/${getItemPath(id)}`; class CartLineItems { private client: AxiosInstance;