idosell 0.1.5 → 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 CHANGED
@@ -1569,6 +1569,7 @@
1569
1569
  * @property {(resultsPage: Integer) => GetProductsAuctionsRequest} resultsPage Page with results number. Numeration starts from 0
1570
1570
  * @property {(resultsLimit: Integer) => GetProductsAuctionsRequest} resultsLimit Number of results on page. Value from 1 to 100
1571
1571
  * @property {(ids: Array<Integer>) => GetProductsAuctionsRequest} ids Define products by passing array of values
1572
+ * @property {() => GetProductsAuctionsRequest} fromAllegro Get auction data on products
1572
1573
  * @property {(page: Integer, limit: Integer) => GetProductsAuctionsRequest} page Define page number and maximum results per page
1573
1574
  * @property {() => Integer} count Returns total numer of results
1574
1575
  * @property {function} exec Excecute request
@@ -1808,7 +1809,7 @@
1808
1809
  * @property {(groups: Array<Object>) => PutProductsGroupsOrderRequest} groups
1809
1810
  * @property {(productsInOrder: Array<Object>) => PutProductsGroupsOrderRequest} productsInOrder
1810
1811
  * @property {function} append Append current data to array and start modifying next row
1811
- * @property {() => PutProductsGroupsOrderRequest} productIdsInOrder Defines order of products within group by automatically setting proprities in order of appearance
1812
+ * @property {(Array<Integer>) => PutProductsGroupsOrderRequest} productIdsInOrder Defines order of products within group by automatically setting proprities in order of appearance
1812
1813
  * @property {function} exec Excecute request
1813
1814
  */
1814
1815
 
@@ -2224,6 +2225,9 @@
2224
2225
  * @property {(minQuantityPerOrder: Object) => PostProductsRequest} minQuantityPerOrder Minimal number of products in an order
2225
2226
  * @property {(productDimensions: Object) => PostProductsRequest} productDimensions Dimensions and overall weight
2226
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
2227
2231
  * @property {function} exec Excecute request
2228
2232
  */
2229
2233
 
@@ -2363,6 +2367,12 @@
2363
2367
  * @property {(productDimensions: Object) => PutProductsRequest} productDimensions Dimensions and overall weight
2364
2368
  * @property {function} append Append current data to array and start modifying next row
2365
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
2370
+ * @property {() => PutProductsRequest} editMode Set edit mode - disables adding new product
2371
+ * @property {() => PutProductsRequest} addMode Set add mode - Api is allowed to create new products
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
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
2366
2376
  * @property {function} exec Excecute request
2367
2377
  */
2368
2378
 
package/dist/helpers.js CHANGED
@@ -119,11 +119,15 @@ export const nest = (valueName, nodeName, obj = {}, forceArray = false) => (valu
119
119
  return params;
120
120
  }
121
121
 
122
+ export const getCurrentAppendableArray = (object, nodeName) => {
123
+ const arr = object.params[object.appendable.arrayNode];
124
+ return arr[object.appendable.index][nodeName] ?? [];
125
+ }
126
+
122
127
  export const nestArray = (object, valueName, nodeName, obj = {}) => (value) => {
123
128
  const node = { ...obj }, params = {};
124
129
  if (object.appendable) {
125
- const arr = object.params[object.appendable.arrayNode];
126
- params[nodeName] = arr[arr.length - 1][nodeName] ?? [];
130
+ params[nodeName] = getCurrentAppendableArray(object, nodeName)
127
131
  } else {
128
132
  params[nodeName] = object.params[nodeName] ?? [];
129
133
  }
@@ -138,6 +142,28 @@ export const orderSource = (sourceName) => (accountName = null) => {
138
142
  return params;
139
143
  }
140
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
+
141
167
  const TEXT_NODES = {
142
168
  name: {
143
169
  main: 'productNames',
@@ -5,6 +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.auctionSites ?? []; auctionSites.push("allegro"); return { auctionSites }},
8
9
  page
9
10
  };
10
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,13 +1,19 @@
1
1
  import { paramsProxy } from "../params.js";
2
- import { setProductText } 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' };
6
6
  object.custom = {
7
- setText: setProductText(object)
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
+ 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)}
8
14
  };
9
15
  object.appendable = {
10
- except: ["settings","picturesSettings"],
16
+ except: ["settings","picturesSettings","editMode","addMode"],
11
17
  arrayNode: "products",
12
18
  index: 0
13
19
  }
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "idosell",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Idosell 3 REST connector",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -11,8 +11,8 @@ test("getClientsClientHasTradeCredit", () => {
11
11
  expect(params).toEqual({"clientHasTradeCredit":"nonzero"});
12
12
  })
13
13
 
14
- test("getClientsLastPurchase", () => {
15
- const params = idosell().getClients.lastPurchase("2023-01-01", 1672704000000).getParams();
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
 
@@ -4,4 +4,9 @@ import { expect, test } from "vitest"
4
4
  test("getProductsAuctionsPage", () => {
5
5
  const params = idosell().getProductsAuctions.page(2,10).getParams();
6
6
  expect(params).toEqual({"resultsPage":2,"resultsLimit":10});
7
+ })
8
+
9
+ test("getProductsAuctionsFromAllegro", () => {
10
+ const params = idosell().getProductsAuctions.ids(33).fromAllegro().getParams();
11
+ expect(params).toEqual({"products":[{"identType":"id","identValue":33}],"auctionSites":["allegro"]});
7
12
  })
@@ -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
  })
@@ -1,12 +1,37 @@
1
1
  import idosell from "./dist/index.js"
2
2
  import { expect, test } from "vitest"
3
3
 
4
+ test("putProductsCountryOfOrigin", () => {
5
+ const params = idosell().putProducts.productId(33).countryOfOrigin("PL").getParams();
6
+ expect(params).toEqual({"products":[{"productId":33,"countryOfOrigin":"PL"}]});
7
+ })
8
+
4
9
  test("putProductsSetText", () => {
5
10
  const params = idosell().putProducts.productId(33).setText("Krzesło Pavon", "name").getParams();
6
11
  expect(params).toEqual({"products":[{"productId":33,"productNames":{"productNamesLangData":[{"langId":"pol","productName":"Krzesło Pavon"}]}}]});
7
12
  })
8
13
 
9
- test("putProductsCountryOfOrigin", () => {
10
- const params = idosell().putProducts.productId(33).countryOfOrigin("PL").getParams();
11
- expect(params).toEqual({"products":[{"productId":33,"countryOfOrigin":"PL"}]});
14
+ test("putProductsEditMode", () => {
15
+ const params = idosell().putProducts.editMode().productId(33).productDisplayedCode("PD01").getParams();
16
+ expect(params).toEqual({"settings":{"settingModificationType":"edit"},"products":[{"productId":33,"productDisplayedCode":"PD01"}]});
17
+ })
18
+
19
+ test("putProductsSetRetailPrice", () => {
20
+ const params = idosell().putProducts.productId(33).setPrice(219).getParams();
21
+ expect(params).toEqual({"products":[{"productId":33,"priceChangeMode":"amount_set","productRetailPrice":219}]});
22
+ })
23
+
24
+ test("putProductsSetWholesaleNetPrice", () => {
25
+ const params = idosell().putProducts.productId(33).setPrice(169, "wholesale", true).getParams();
26
+ expect(params).toEqual({"products":[{"productId":33,"priceChangeMode":"amount_set","productWholesalePriceNet":169}]});
27
+ })
28
+
29
+ test("putProductsSetMenu", () => {
30
+ const params = idosell().putProducts.productId(33).setMenu(1,252).getParams();
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"}});
12
37
  })
@@ -8,7 +8,7 @@ test("putProductsImagesProductImages", () => {
8
8
 
9
9
  test("putProductsImagesAddSingleImage", () => {
10
10
  const params = idosell().putProductsImages.productId(31).addImage("https://www.idosell.com/panel/file-gate.php?id=279794&ext=.webp").getParams();
11
- expect(params).toEqual({"productsImagesSettings":{"productsImagesSourceType":"url","productsImagesApplyMacro":true},"productsImages":[{"productIdent":{"productIdentType":"id","identValue":31},"productImages":[{"productImageNumber":1,"productImageSource":"https://www.idosell.com/panel/file-gate.php?id=279794&ext=.webp"},{"productImageNumber":2,"productImageSource":"https://bit.ly/fcc-relaxing-cat"}]}]});
11
+ expect(params).toEqual({"productsImagesSettings":{"productsImagesSourceType":"url","productsImagesApplyMacro":true},"productsImages":[{"productIdent":{"productIdentType":"id","identValue":31},"productImages":[{"productImageNumber":1,"productImageSource":"https://www.idosell.com/panel/file-gate.php?id=279794&ext=.webp"}]}]});
12
12
  })
13
13
 
14
14
  test("putProductsImagesAddMultipleImage", () => {
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("putWmsSuppliersName", () => {
8
- const params = idosell().getClients.clientsIds([123,456,789]).lastPurchase("2023-01-01", 1672704000000).getParams();
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
  })
File without changes