idosell 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gates.def.js +6 -2
- package/dist/helpers.js +22 -0
- package/dist/methods/getProductsAuctions.js +1 -1
- package/dist/methods/postProducts.js +6 -0
- package/dist/methods/putProducts.js +5 -4
- package/dist/request.js +1 -1
- package/package.json +1 -1
- package/tests/getClients.test.js +2 -2
- package/tests/postProducts.test.js +10 -0
- package/tests/putProducts.test.js +6 -1
- package/tests/url.test.js +2 -2
- package/dist/methods/putProducts copy.js +0 -20
package/dist/gates.def.js
CHANGED
|
@@ -2225,6 +2225,9 @@
|
|
|
2225
2225
|
* @property {(minQuantityPerOrder: Object) => PostProductsRequest} minQuantityPerOrder Minimal number of products in an order
|
|
2226
2226
|
* @property {(productDimensions: Object) => PostProductsRequest} productDimensions Dimensions and overall weight
|
|
2227
2227
|
* @property {function} append Append current data to array and start modifying next row
|
|
2228
|
+
* @property {(text: String, type: "name"|"short"|"long"|"metatitle"|"metadescription"|"metakeywords"|"acutionname"|"auctiondescription", language: String, shopId: Integer) => PostProductsRequest} setText Set various types of names or descriptions to the product
|
|
2229
|
+
* @property {(value: Float, type: 'retail'|'wholesale'|'pos'|'minimal'|'strikethroughRetail'|'strikethroughWholesale'|'suggested'|'automaticCalculation') => PostProductsRequest} addPrice Increases product price by amount
|
|
2230
|
+
* @property {(value: Float, type: 'retail'|'wholesale'|'pos'|'minimal'|'strikethroughRetail'|'strikethroughWholesale'|'suggested'|'automaticCalculation') => PostProductsRequest} setPrice Sets product price by amount
|
|
2228
2231
|
* @property {function} exec Excecute request
|
|
2229
2232
|
*/
|
|
2230
2233
|
|
|
@@ -2366,9 +2369,10 @@
|
|
|
2366
2369
|
* @property {(text: String, type: "name"|"short"|"long"|"metatitle"|"metadescription"|"metakeywords"|"acutionname"|"auctiondescription", language: String, shopId: Integer) => PutProductsRequest} setText Set various types of names or descriptions to the product
|
|
2367
2370
|
* @property {() => PutProductsRequest} editMode Set edit mode - disables adding new product
|
|
2368
2371
|
* @property {() => PutProductsRequest} addMode Set add mode - Api is allowed to create new products
|
|
2369
|
-
* @property {(value: Float, type: 'retail'|'wholesale'|'pos'|'minimal'|'
|
|
2370
|
-
* @property {(value: Float, type: 'retail'|'wholesale'|'pos'|'minimal'|'
|
|
2372
|
+
* @property {(value: Float, type: 'retail'|'wholesale'|'pos'|'minimal'|'strikethroughRetail'|'strikethroughWholesale'|'suggested'|'automaticCalculation') => PutProductsRequest} addPrice Increases product price by amount
|
|
2373
|
+
* @property {(value: Float, type: 'retail'|'wholesale'|'pos'|'minimal'|'strikethroughRetail'|'strikethroughWholesale'|'suggested'|'automaticCalculation') => PutProductsRequest} setPrice Sets product price by amount
|
|
2371
2374
|
* @property {(shopId: Integer, menuIds: Integer) => PutProductsRequest} setMenu Sets product selected IDs
|
|
2375
|
+
* @property {(picturesArray: Array<String>) => PutProductsRequest} pictures Sets list of pictures attached to product
|
|
2372
2376
|
* @property {function} exec Excecute request
|
|
2373
2377
|
*/
|
|
2374
2378
|
|
package/dist/helpers.js
CHANGED
|
@@ -142,6 +142,28 @@ export const orderSource = (sourceName) => (accountName = null) => {
|
|
|
142
142
|
return params;
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
+
const PRICE_TYPES = {
|
|
146
|
+
'advance': 'Advance',
|
|
147
|
+
'retail': 'Retail',
|
|
148
|
+
'wholesale': 'Wholesale',
|
|
149
|
+
'minimal': 'Minimal',
|
|
150
|
+
'automaticalculation': 'AutomaticCalculation',
|
|
151
|
+
'pos': "Pos",
|
|
152
|
+
'suggested': 'Suggested',
|
|
153
|
+
'strikethroughretail': 'StrikethroughRetail',
|
|
154
|
+
'strikethroughwholesale': 'StrikethroughWholesale'
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export const modifyPrice = (value, type, net, priceChangeMode = 'amount_set') => {
|
|
158
|
+
const typeName = PRICE_TYPES[type.toLowerCase()];
|
|
159
|
+
if (!typeName) throw new Error(`Invalid price type: ${type}. Availible types: ${Object.values(PRICE_TYPES)}`);
|
|
160
|
+
const node = ["product", typeName, "Price"];
|
|
161
|
+
if (net) node.push("Net");
|
|
162
|
+
const params = { priceChangeMode }
|
|
163
|
+
params[node.join('')] = value;
|
|
164
|
+
return params;
|
|
165
|
+
}
|
|
166
|
+
|
|
145
167
|
const TEXT_NODES = {
|
|
146
168
|
name: {
|
|
147
169
|
main: 'productNames',
|
|
@@ -5,7 +5,7 @@ export default (object) => {
|
|
|
5
5
|
object.gate = { method: 'get', node: '/products/auctions' };
|
|
6
6
|
object.custom = {
|
|
7
7
|
ids: arrayOfObjects("products", "identValue", {"identType":"id"}),
|
|
8
|
-
fromAllegro: () => { const auctionSites = object.params[
|
|
8
|
+
fromAllegro: () => { const auctionSites = object.params.auctionSites ?? []; auctionSites.push("allegro"); return { auctionSites }},
|
|
9
9
|
page
|
|
10
10
|
};
|
|
11
11
|
return new Proxy(object, paramsProxy);
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { paramsProxy } from "../params.js";
|
|
2
|
+
import { setProductText, modifyPrice } from "../helpers.js";
|
|
2
3
|
|
|
3
4
|
export default (object) => {
|
|
4
5
|
object.gate = { method: 'post', node: '/products/products' };
|
|
6
|
+
object.custom = {
|
|
7
|
+
setText: setProductText(object),
|
|
8
|
+
addPrice: (value, type = "retail", net = false) => modifyPrice(value, type, net, "amount_diff"),
|
|
9
|
+
setPrice: (value, type = "retail", net = false) => modifyPrice(value, type, net, "amount_set")
|
|
10
|
+
};
|
|
5
11
|
object.appendable = {
|
|
6
12
|
except: ["settings","picturesSettings"],
|
|
7
13
|
arrayNode: "products",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { paramsProxy } from "../params.js";
|
|
2
|
-
import { setProductText, getCurrentAppendableArray } from "../helpers.js";
|
|
2
|
+
import { setProductText, getCurrentAppendableArray, modifyPrice, arrayOfObjects } from "../helpers.js";
|
|
3
3
|
|
|
4
4
|
export default (object) => {
|
|
5
5
|
object.gate = { method: 'put', node: '/products/products' };
|
|
@@ -7,9 +7,10 @@ export default (object) => {
|
|
|
7
7
|
setText: setProductText(object),
|
|
8
8
|
editMode: () => { const settings = object.params.settings ?? {}; settings.settingModificationType = "edit"; return { settings } },
|
|
9
9
|
addMode: () => { const settings = object.params.settings ?? {}; settings.settingModificationType = "edit"; return { settings } },
|
|
10
|
-
addPrice: (value, type = "retail", net = false) =>
|
|
11
|
-
setPrice: (value, type = "retail", net = false) =>
|
|
12
|
-
setMenu: (shopId, menuIds) => { if (!Array.isArray(menuIds)) menuIds = [menuIds]; const productMenuItems = getCurrentAppendableArray(object, "productMenuItems"); for (const menuItemId of menuIds) { productMenuItems.push({ productMenuOperation: "add_product", shopId, menuItemId }) } return { productMenuItems}; }
|
|
10
|
+
addPrice: (value, type = "retail", net = false) => modifyPrice(value, type, net, "amount_diff"),
|
|
11
|
+
setPrice: (value, type = "retail", net = false) => modifyPrice(value, type, net, "amount_set"),
|
|
12
|
+
setMenu: (shopId, menuIds) => { if (!Array.isArray(menuIds)) menuIds = [menuIds]; const productMenuItems = getCurrentAppendableArray(object, "productMenuItems"); for (const menuItemId of menuIds) { productMenuItems.push({ productMenuOperation: "add_product", shopId, menuItemId }) } return { productMenuItems}; },
|
|
13
|
+
pictures: (picturesArray) => { if (picturesArray.length) { if (!object.params.picturesSettings) object.params.picturesSettings = {}; object.params.picturesSettings.picturesSettingInputType = picturesArray[0].indexOf("http") === 0 ? "url" : "base64" }; return arrayOfObjects("productPictures", "productPictureSource")(picturesArray)}
|
|
13
14
|
};
|
|
14
15
|
object.appendable = {
|
|
15
16
|
except: ["settings","picturesSettings","editMode","addMode"],
|
package/dist/request.js
CHANGED
|
@@ -57,9 +57,9 @@ export const sendRequest = async (request, options = {}) => {
|
|
|
57
57
|
let url = `${request.auth.url}/api/admin/v${request.auth.version}${node}`;
|
|
58
58
|
if (options.log || options.dump) {
|
|
59
59
|
console.log(util.inspect({ params: request.params, method, url }, {showHidden: false, depth: null, colors: true}))
|
|
60
|
+
if (options.dump) return;
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
if (options.dump) return;
|
|
63
63
|
|
|
64
64
|
if (method === 'get') {
|
|
65
65
|
url += '?' + queryfy(request.params);
|
package/package.json
CHANGED
package/tests/getClients.test.js
CHANGED
|
@@ -11,8 +11,8 @@ test("getClientsClientHasTradeCredit", () => {
|
|
|
11
11
|
expect(params).toEqual({"clientHasTradeCredit":"nonzero"});
|
|
12
12
|
})
|
|
13
13
|
|
|
14
|
-
test("
|
|
15
|
-
const params = idosell().getClients.
|
|
14
|
+
test("getClientsLastPurchased", () => {
|
|
15
|
+
const params = idosell().getClients.lastPurchased("2023-01-01", 1672704000000).getParams();
|
|
16
16
|
expect(params).toEqual({"clientLastPurchaseDate":{"clientLastPurchaseDateBegin":"2023-01-01","clientLastPurchaseDateEnd":"2023-01-03"}});
|
|
17
17
|
})
|
|
18
18
|
|
|
@@ -9,4 +9,14 @@ test("postProductsProductSizes", () => {
|
|
|
9
9
|
test("postProductsShopsMask", () => {
|
|
10
10
|
const params = idosell().postProducts.shopsMask(1).getParams();
|
|
11
11
|
expect(params).toEqual({"products":[{"shopsMask":1}]});
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
test("postProductsSetPrice", () => {
|
|
15
|
+
const params = idosell().postProducts.shopsMask(1).setPrice(199).getParams();
|
|
16
|
+
expect(params).toEqual({"products":[{"shopsMask":1,"priceChangeMode":"amount_set","productRetailPrice":199}]});
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test("postProductsSetText", () => {
|
|
20
|
+
const params = idosell().postProducts.shopsMask(1).setText("Awesome199","name").getParams();
|
|
21
|
+
expect(params).toEqual({"products":[{"shopsMask":1,"productNames":{"productNamesLangData":[{"langId":"pol","productName":"Awesome199"}]}}]});
|
|
12
22
|
})
|
|
@@ -21,7 +21,7 @@ test("putProductsSetRetailPrice", () => {
|
|
|
21
21
|
expect(params).toEqual({"products":[{"productId":33,"priceChangeMode":"amount_set","productRetailPrice":219}]});
|
|
22
22
|
})
|
|
23
23
|
|
|
24
|
-
test("
|
|
24
|
+
test("putProductsSetWholesaleNetPrice", () => {
|
|
25
25
|
const params = idosell().putProducts.productId(33).setPrice(169, "wholesale", true).getParams();
|
|
26
26
|
expect(params).toEqual({"products":[{"productId":33,"priceChangeMode":"amount_set","productWholesalePriceNet":169}]});
|
|
27
27
|
})
|
|
@@ -29,4 +29,9 @@ test("putProductsSetWholesalePrice", () => {
|
|
|
29
29
|
test("putProductsSetMenu", () => {
|
|
30
30
|
const params = idosell().putProducts.productId(33).setMenu(1,252).getParams();
|
|
31
31
|
expect(params).toEqual({"products":[{"productId":33,"productMenuItems":[{"productMenuOperation":"add_product","shopId":1,"menuItemId":252}]}]});
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test("putProductsPictures", () => {
|
|
35
|
+
const params = idosell().putProducts.productId(77).pictures(["https://www.wikipedia.org/portal/wikipedia.org/assets/img/Wikipedia-logo-v2.png"]).getParams();
|
|
36
|
+
expect(params).toEqual({"products":[{"productId":77,"productPictures":[{"productPictureSource":"https://www.wikipedia.org/portal/wikipedia.org/assets/img/Wikipedia-logo-v2.png"}]}],"picturesSettings":{"picturesSettingInputType":"url"}});
|
|
32
37
|
})
|
package/tests/url.test.js
CHANGED
|
@@ -4,8 +4,8 @@ import { queryfy } from "../dist/request";
|
|
|
4
4
|
import idosell from "./dist/index.js"
|
|
5
5
|
import { expect, test } from "vitest"
|
|
6
6
|
|
|
7
|
-
test("
|
|
8
|
-
const params = idosell().getClients.clientsIds([123,456,789]).
|
|
7
|
+
test("getClientsLastPurchased", () => {
|
|
8
|
+
const params = idosell().getClients.clientsIds([123,456,789]).lastPurchased("2023-01-01", 1672704000000).getParams();
|
|
9
9
|
const search = queryfy(params);
|
|
10
10
|
expect(search).toEqual("clientsIds=123%2C456%2C789&clientLastPurchaseDate%5BclientLastPurchaseDateBegin%5D=2023-01-01&clientLastPurchaseDate%5BclientLastPurchaseDateEnd%5D=2023-01-03")
|
|
11
11
|
})
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { paramsProxy } from "../params.js";
|
|
2
|
-
import { setProductText, nestArray, getCurrentAppendableArray } from "../helpers.js";
|
|
3
|
-
|
|
4
|
-
export default (object) => {
|
|
5
|
-
object.gate = { method: 'put', node: '/products/products' };
|
|
6
|
-
object.custom = {
|
|
7
|
-
setText: setProductText(object),
|
|
8
|
-
editMode: () => { const settings = object.params.settings ?? {}; settings.settingModificationType = 'edit'; return { settings } },
|
|
9
|
-
addMode: () => { const settings = object.params.settings ?? {}; settings.settingModificationType = 'edit'; return { settings } },
|
|
10
|
-
setPrice: (value, type = 'retail', net = false) => { const node = ['product', type[0].toUpperCase() + type.substring(1).toLowerCase(), 'Price']; if (net) node.push('Net'); const params = { priceChangeMode: 'amount_set' }; params[node.join('')] = value; return params; },
|
|
11
|
-
setMenu: (shopId, menuIds) => { if (!Array.isArray(menuIds)) menuIds = [menuIds]; const productMenuItems = getCurrentAppendableArray(object, "productMenuItems"); for (const menuItemId of menuIds) { productMenuItems.push({ productMenuOperation: "add_product", shopId, menuItemId }) } return { productMenuItems}; },
|
|
12
|
-
// dimensions: (width, height, length) => ({ productDimensions: { productWidth: width, productHeight: height, productLength: length } })
|
|
13
|
-
};
|
|
14
|
-
object.appendable = {
|
|
15
|
-
except: ["settings","picturesSettings","editMode","addMode"],
|
|
16
|
-
arrayNode: "products",
|
|
17
|
-
index: 0
|
|
18
|
-
}
|
|
19
|
-
return new Proxy(object, paramsProxy);
|
|
20
|
-
}
|