Path: blob/master/node_modules/@adiwajshing/baileys/lib/LegacySocket/business.js
1129 views
"use strict";1var __importDefault = (this && this.__importDefault) || function (mod) {2return (mod && mod.__esModule) ? mod : { "default": mod };3};4Object.defineProperty(exports, "__esModule", { value: true });5const business_1 = require("../Utils/business");6const groups_1 = __importDefault(require("./groups"));7const makeBusinessSocket = (config) => {8const sock = (0, groups_1.default)(config);9const { query, generateMessageTag, waUploadToServer, state } = sock;10const getCatalog = async (jid, limit = 10) => {11var _a, _b;12jid = jid || ((_b = (_a = state.legacy) === null || _a === void 0 ? void 0 : _a.user) === null || _b === void 0 ? void 0 : _b.id);13const result = await query({14expect200: true,15json: [16'query',17'bizCatalog',18{19allowShopSource: false,20catalogWid: jid,21height: 100,22width: 100,23limit,24stanza_id: generateMessageTag(true),25type: 'get_product_catalog_reh',26}27]28});29const products = result.data.data.map(mapProduct);30return {31beforeCursor: result.data.paging.cursors.before,32products33};34};35const productCreate = async (product) => {36const result = await query({37expect200: true,38json: [39'action',40'addProduct_reh',41await mapProductCreate(product)42]43});44return mapProduct(result.data.product);45};46const productDelete = async (productIds) => {47const result = await query({48expect200: true,49json: [50'action',51'deleteProduct_reh',52{53product_ids: productIds,54stanza_id: generateMessageTag(true),55}56]57});58return {59deleted: result.data.deleted_count60};61};62const productUpdate = async (productId, update) => {63const productCreate = await mapProductCreate({ ...update, originCountryCode: undefined }, false);64const result = await query({65expect200: true,66json: [67'action',68'editProduct_reh',69{70product_id: productId,71...productCreate72}73]74});75return mapProduct(result.data.product);76};77const getOrderDetails = async (orderId, tokenBase64) => {78const result = await query({79expect200: true,80json: [81'query',82'order',83{84id: generateMessageTag(true),85orderId,86imageWidth: '80',87imageHeight: '80',88token: tokenBase6489}90]91});92const data = result.data;93const order = {94price: {95currency: data.price.currency,96total: data.price.total,97},98products: data.products.map(p => {99var _a;100return ({101id: p.id,102imageUrl: (_a = p.image) === null || _a === void 0 ? void 0 : _a.url,103name: p.name,104quantity: +p.quantity,105currency: p.currency,106price: +p.price107});108})109};110return order;111};112// maps product create to send to WA113const mapProductCreate = async (product, mapCompliance = true) => {114const imgs = (await (0, business_1.uploadingNecessaryImages)(product.images, waUploadToServer)).map(img => img.url);115const result = {116name: product.name,117description: product.description,118image_url: imgs[0],119url: product.url || '',120additional_image_urls: imgs.slice(1),121retailer_id: product.retailerId || '',122width: '100',123height: '100',124stanza_id: generateMessageTag(true),125price: product.price.toString(),126currency: product.currency127};128if (mapCompliance) {129Object.assign(result, {130compliance_category: product.originCountryCode131? undefined :132'COUNTRY_ORIGIN_EXEMPT',133compliance_info: product.originCountryCode134? { country_code_origin: product.originCountryCode }135: undefined136});137}138return result;139};140return {141...sock,142getOrderDetails,143getCatalog,144productCreate,145productDelete,146productUpdate147};148};149const mapProduct = (item) => ({150id: item.id,151name: item.name,152retailerId: item.retailer_id,153price: +item.price,154description: item.description,155currency: item.currency,156imageUrls: item.image_cdn_urls.reduce((dict, { key, value }) => {157dict[key] = value;158return dict;159}, {}),160reviewStatus: item.capability_to_review_status.reduce((dict, { key, value }) => {161dict[key] = value;162return dict;163}, {}),164isHidden: item.is_hidden,165availability: item.availability166});167exports.default = makeBusinessSocket;168169170