File size: 8,573 Bytes
9844ee9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
"use strict";
/*
 * This file is part of WPPConnect.
 *
 * WPPConnect is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * WPPConnect is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with WPPConnect.  If not, see <https://www.gnu.org/licenses/>.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.CatalogLayer = void 0;
const helpers_1 = require("../helpers");
const community_layer_1 = require("./community.layer");
class CatalogLayer extends community_layer_1.CommunityLayer {
    constructor(page, session, options) {
        super(page, session, options);
        this.page = page;
    }
    /**
     * Create a product on catalog
     * @param name Product name
     * @param image Product image
     * @param description Product description
     * @param price Product price
     * @param isHidden Product visibility
     * @param url Product url
     * @param retailerId Product own ID system
     * @param currency Product currency
     * @example
     * ```javascript
     * client.createtProduct(
     *    'Product name',
     *    'image in base64',
     *    'product description',
     *    '89.90',
     *    true,
     *    'https://wppconnect.io',
     *    'AKA001',
     *   );
     * ```
     */
    async createProduct(name, image, description, price, isHidden, url, retailerId, currency) {
        return (0, helpers_1.evaluateAndReturn)(this.page, ({ name, image, description, price, isHidden, url, retailerId, currency, }) => WPP.catalog.createProduct({
            name,
            image,
            description,
            price,
            isHidden,
            url,
            retailerId,
            currency,
        }), { name, image, description, price, isHidden, url, retailerId, currency });
    }
    /**
     * Querys all products
     * @param id Buisness profile id ('00000@c.us')
     * @param qnt limit to load products - Default: 10
     */
    async getProducts(id, qnt) {
        return (0, helpers_1.evaluateAndReturn)(this.page, ({ id, qnt }) => WPP.catalog.getProducts(id, qnt), { id, qnt });
    }
    /**
     * Create a new product on catalog
     * @param id Buisness profile id ('00000@c.us')
     * @param productId ID of Product
     */
    async getProductById(id, productId) {
        return (0, helpers_1.evaluateAndReturn)(this.page, ({ id, productId }) => WPP.catalog.getProductById(id, productId), { id, productId });
    }
    /**
     * Edit product on catalog
     * @param productId Product ID
     * @param options Object with options
     * @example
     * ```javascript
     * client.editProduct('56989897878' {
     *    name: 'Product name',
     *     description: 'product description',
     *     price: '89.90',
     *     isHidden: true,
     *     url: 'https://wppconnect.io',
     *     retailerId: 'AKA001',
     *   });
     * ```
     */
    async editProduct(productId, options) {
        return (0, helpers_1.evaluateAndReturn)(this.page, ({ productId, options }) => WPP.catalog.editProduct(productId, options), { productId, options });
    }
    /**
     * Delete product(s) on catalog
     * @param productsId Products ID
     * @example
     * ```javascript
     * //Delete one product
     * client.delProducts(['56989897878']);
     *
     * // Delete various products
     * client.delProducts(['56989897878','565657878']);
     * ```
     */
    async delProducts(productsId) {
        return (0, helpers_1.evaluateAndReturn)(this.page, ({ productsId }) => WPP.catalog.delProducts(productsId), { productsId });
    }
    /**
     * Add image on product This function change main image of product, for change additional images use client.addImage
     * @param productId Product ID
     * @param image Image in base64
     * @example
     * ```javascript
     * client.changeProductImage('56989897878', 'base64/string');
     * ```
     */
    async changeProductImage(productId, image) {
        return (0, helpers_1.evaluateAndReturn)(this.page, ({ productId, image }) => WPP.catalog.changeProductImage(productId, image), { productId, image });
    }
    /**
     * Add image on product This function include additional images on product for change main image use client.changeProductImage
     * @param productId Product ID
     * @param image Image in base64
     * @example
     * ```javascript
     * client.addProductImage('56989897878', 'base64/string');
     * ```
     */
    async addProductImage(productId, image) {
        return (0, helpers_1.evaluateAndReturn)(this.page, ({ productId, image }) => WPP.catalog.addProductImage(productId, image), { productId, image });
    }
    /**
     * Remove image on product This function remove additional images of product for change main image use client.changeProductImage
     * @param productId Product ID
     * @param index Index array of additional imagens
     * @example
     * ```javascript
     * client.removeProductImage('56989897878', '1');
     * ```
     */
    async removeProductImage(productId, index) {
        return (0, helpers_1.evaluateAndReturn)(this.page, ({ productId, index }) => WPP.catalog.removeProductImage(productId, index), { productId, index });
    }
    /**
     * Query all collections
     * @param id Product ID
     * @param qnt Max qnt collections - Default 10
     * @param maxProducts Max products in array products of collection - Default 10
     * @example
     * ```javascript
     * client.getCollections('5521988556558@c.us', '10','20');
     * ```
     */
    async getCollections(id, qnt, maxProducts) {
        return (0, helpers_1.evaluateAndReturn)(this.page, ({ id, qnt, maxProducts }) => WPP.catalog.getCollections(id, qnt, maxProducts), { id, qnt, maxProducts });
    }
    /**
     * Create new collection
     * @param collectionName Product ID
     * @param productsId Index array of additional imagens
     * @example
     * ```javascript
     * client.createCollection('Name of collection', ['655632565','5689859898']);
     * ```
     */
    async createCollection(collectionName, productsId) {
        return (0, helpers_1.evaluateAndReturn)(this.page, ({ collectionName, productsId }) => WPP.catalog.createCollection(collectionName, productsId), { collectionName, productsId });
    }
    /**
     * Edit a collection
     * @param collectionId Collection id
     * @param options Options arguments
     * @example
     * ```javascript
     * client.editCollection('656565898', {
     * collectionName: 'New Name for collection',
     * productsToAdd: ['5656523223'],
     * productsToRemove: ['5656523232']
     * });
     * ```
     */
    async editCollection(collectionId, options) {
        return (0, helpers_1.evaluateAndReturn)(this.page, ({ collectionId, options }) => WPP.catalog.editCollection(collectionId, options), { collectionId, options });
    }
    /**
     * Delete a collection
     * @param collectionId Collection id
     * @param options Options arguments
     * @example
     * ```javascript
     * client.deleteCollection('65666565898');
     * ```
     */
    async deleteCollection(collectionId) {
        return (0, helpers_1.evaluateAndReturn)(this.page, ({ collectionId }) => WPP.catalog.deleteCollection(collectionId), { collectionId });
    }
    /**
     * Set product visibility
     * @param productId Product id
     * @param value True for visibility, false for non visible
     * @example
     * ```javascript
     * client.setProductVisibility('65666565898', false);
     * ```
     */
    async setProductVisibility(productId, value) {
        return (0, helpers_1.evaluateAndReturn)(this.page, ({ productId, value }) => WPP.catalog.setProductVisibility(productId, value), { productId, value });
    }
    /**
     * Update options to customer cart your products
     * @param value True for enabled, false for non enabled
     * @example
     * ```javascript
     * client.updateCartEnabled(false);
     * ```
     */
    async updateCartEnabled(value) {
        return (0, helpers_1.evaluateAndReturn)(this.page, ({ value }) => WPP.catalog.updateCartEnabled(value), { value });
    }
}
exports.CatalogLayer = CatalogLayer;