From bed4f7f524d740356a0dc67410890142b9b8e319 Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Thu, 8 Dec 2022 13:32:10 +0530 Subject: [PATCH] chore: add GetCatalogOptions type !BREAKING_CHANGE --- src/Socket/business.ts | 10 +++------- src/Types/Product.ts | 11 ++++++++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Socket/business.ts b/src/Socket/business.ts index 9f94f16..457701e 100644 --- a/src/Socket/business.ts +++ b/src/Socket/business.ts @@ -1,4 +1,4 @@ -import { CatalogCursor, ProductCreate, ProductUpdate, SocketConfig } from '../Types' +import { GetCatalogOptions, ProductCreate, ProductUpdate, SocketConfig } from '../Types' import { parseCatalogNode, parseCollectionsNode, parseOrderDetailsNode, parseProductNode, toProductNode, uploadingNecessaryImagesOfProduct } from '../Utils/business' import { BinaryNode, jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary' import { getBinaryNodeChild } from '../WABinary/generic-utils' @@ -12,11 +12,7 @@ export const makeBusinessSocket = (config: SocketConfig) => { waUploadToServer } = sock - const getCatalog = async( - jid?: string, - limit = 10, - cursor?: CatalogCursor - ) => { + const getCatalog = async({ jid, limit, cursor }: GetCatalogOptions) => { jid = jid || authState.creds.me?.id jid = jidNormalizedUser(jid!) @@ -24,7 +20,7 @@ export const makeBusinessSocket = (config: SocketConfig) => { { tag: 'limit', attrs: { }, - content: Buffer.from(limit.toString()) + content: Buffer.from((limit || 10).toString()) }, { tag: 'width', diff --git a/src/Types/Product.ts b/src/Types/Product.ts index e227497..4fcb0fc 100644 --- a/src/Types/Product.ts +++ b/src/Types/Product.ts @@ -72,4 +72,13 @@ export type OrderDetails = { products: OrderProduct[] } -export type CatalogCursor = string \ No newline at end of file +export type CatalogCursor = string + +export type GetCatalogOptions = { + /** cursor to start from */ + cursor?: CatalogCursor + /** number of products to fetch */ + limit?: number + + jid?: string +} \ No newline at end of file