tesla-inventory 3.0.310 → 3.1.0

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "tesla-inventory",
3
3
  "description": "Retrieve real-time data from Tesla Inventory.",
4
4
  "homepage": "https://github.com/Kikobeats/tesla-inventory",
5
- "version": "3.0.310",
5
+ "version": "3.1.0",
6
6
  "main": "src/index.js",
7
7
  "author": {
8
8
  "email": "josefrancisco.verdu@gmail.com",
@@ -96,6 +96,7 @@
96
96
  "./inventories": "./src/inventories/index.js",
97
97
  "./inventories/euro": "./src/inventories/euro.js",
98
98
  "./package.json": "./package.json",
99
+ "./prices/au": "./src/prices/au.json",
99
100
  "./prices/ca": "./src/prices/ca.json",
100
101
  "./prices/ch": "./src/prices/ch.json",
101
102
  "./prices/cz": "./src/prices/cz.json",
package/src/index.js CHANGED
@@ -9,22 +9,16 @@ const timestamp = (start = process.hrtime.bigint()) => () =>
9
9
  const got = require('got').extend({
10
10
  url: 'https://www.tesla.com/inventory/api/v1/inventory-results',
11
11
  responseType: 'json',
12
- resolveBodyOnly: true
12
+ resolveBodyOnly: true,
13
+ headers: { 'user-agent': undefined }
13
14
  })
14
15
 
15
- const toLowerCase = ({ results: items, total_matches_found: totalMatchesFound, ...rest }) => {
16
- return {
17
- items,
18
- total: Number(totalMatchesFound)
19
- }
20
- }
21
-
22
16
  const uniqBy = (arr, prop) =>
23
17
  arr.filter((x, i, self) => i === self.findIndex(y => x[prop] === y[prop]))
24
18
 
25
19
  const ITEMS_PER_PAGE = 50
26
20
 
27
- module.exports = async (inventory, opts, { headers, ...gotOpts } = {}) => {
21
+ module.exports = async (inventory, opts, gotOpts) => {
28
22
  if (!inventories[inventory]) {
29
23
  throw new TypeError(`Tesla inventory \`${inventory}\` not found!`)
30
24
  }
@@ -38,19 +32,23 @@ module.exports = async (inventory, opts, { headers, ...gotOpts } = {}) => {
38
32
  const duration = timestamp()
39
33
 
40
34
  const paginate = async (offset = 0) =>
41
- got({
42
- searchParams: {
43
- query: JSON.stringify({
44
- query,
45
- count: ITEMS_PER_PAGE,
46
- offset,
47
- outsideOffset: 0,
48
- outsideSearch: false
49
- })
50
- },
51
- ...gotOpts,
52
- headers: { 'user-agent': undefined, ...headers }
53
- }).then(toLowerCase)
35
+ got(
36
+ got.mergeOptions(
37
+ got.defaults.options,
38
+ {
39
+ searchParams: {
40
+ query: JSON.stringify({
41
+ query,
42
+ count: ITEMS_PER_PAGE,
43
+ offset,
44
+ outsideOffset: 0,
45
+ outsideSearch: false
46
+ })
47
+ }
48
+ },
49
+ gotOpts
50
+ )
51
+ ).then(({ results }) => ({ items: results }))
54
52
 
55
53
  let offset = 0
56
54
  let items = []
@@ -1,5 +1,6 @@
1
1
  module.exports = {
2
2
  at: { country: 'Austria', language: 'de', market: 'AT', super_region: 'europe' },
3
+ au: { country: 'Australia', language: 'en', market: 'AU', super_region: 'north america' },
3
4
  be: { country: 'Belgium', language: 'nl', market: 'BE', super_region: 'europe' },
4
5
  ca: { country: 'Canada', language: 'en', market: 'CA', super_region: 'north america' },
5
6
  ch: { country: 'Switzerland', language: 'de', market: 'CH', super_region: 'europe' },
@@ -0,0 +1,33 @@
1
+ {
2
+ "APF2": 10100,
3
+ "APPB": 5100,
4
+ "FM3U": 3000,
5
+ "IBW1": 1500,
6
+ "IN3PW": 1500,
7
+ "INPW0": 1500,
8
+ "IPW1": 1500,
9
+ "MT301": 11310,
10
+ "MT304": 30010,
11
+ "MT308": 11310,
12
+ "MT310": 24310,
13
+ "MT311": 30010,
14
+ "MT316": 24310,
15
+ "MT317": 30010,
16
+ "MT320": 11310,
17
+ "MT322": 11310,
18
+ "MT323": 24310,
19
+ "MT327": 11310,
20
+ "MT328": 24310,
21
+ "MT329": 30010,
22
+ "MT337": 11310,
23
+ "MT340": 30010,
24
+ "MTY10": 34400,
25
+ "MTY13": 8400,
26
+ "PBSB": 1500,
27
+ "PMNG": 1500,
28
+ "PPMR": 2400,
29
+ "PPSB": 1500,
30
+ "SPT31": 7300,
31
+ "W41B": 1800,
32
+ "WY20P": 2400
33
+ }