tesla-inventory 3.2.33 → 3.2.35

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/README.md CHANGED
@@ -40,7 +40,7 @@ Type: `function`
40
40
 
41
41
  The fetcher function used for performing the networking calls. It should return text ([example](https://github.com/teslahunt/inventory/blob/master/test/index.js#L6)).
42
42
 
43
- ### .teslaInventory([query], [gotOpts])
43
+ ### .teslaInventory([inventory], [query], [fetcherOpts])
44
44
 
45
45
  #### inventory
46
46
 
@@ -62,6 +62,12 @@ These options can be:
62
62
  - **model**: ms|mx|m3
63
63
  - **order**: asc|desc
64
64
 
65
+ #### fetcherOpts
66
+
67
+ Type: `object`
68
+
69
+ The options to be passed against `fetcher`.
70
+
65
71
  ## License
66
72
 
67
73
  **tesla-inventory** © [Tesla Hunt](https://teslahunt.io), released under the [MIT](https://github.com/teslahunt/inventory/blob/master/LICENSE.md) License.<br>
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.2.33",
5
+ "version": "3.2.35",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -82,7 +82,7 @@
82
82
  "markdown-tables-to-json": "latest",
83
83
  "nano-staged": "latest",
84
84
  "npm-check-updates": "latest",
85
- "puppeteer": "latest",
85
+ "puppeteer": "21.2.1",
86
86
  "signal-exit": "latest",
87
87
  "simple-git-hooks": "latest",
88
88
  "standard": "latest",
package/src/codes.json CHANGED
@@ -344,6 +344,10 @@
344
344
  "MT324": "Model 3 Long Range All-Wheel Drive",
345
345
  "MT325": "Model 3 Long Range All-Wheel Drive Performance",
346
346
  "MT328": "Model 3 Long Range All-Wheel Drive",
347
+ "MT331": "Model 3 Standard Range Plus",
348
+ "MT332": "Model 3 Standard Range Plus",
349
+ "MT333": "Model 3 Standard Range Plus",
350
+ "MT334": "Model 3 Long Range Rear-Wheel Drive",
347
351
  "MT336": "Model 3 Standard Range Plus Rear-Wheel Drive",
348
352
  "MT337": "Model 3 Standard Range Plus Rear-Wheel Drive",
349
353
  "MT340": "Model 3 Long Range All-Wheel Drive Performance",
package/src/index.js CHANGED
@@ -15,58 +15,61 @@ const uniqBy = (arr, prop) =>
15
15
 
16
16
  const ITEMS_PER_PAGE = 50
17
17
 
18
- module.exports = fetcher => async (inventory, opts, fetcherOpts) => {
19
- if (!inventories[inventory]) {
20
- throw new TypeError(`Tesla inventory \`${inventory}\` not found!`)
21
- }
22
-
23
- if (opts.model && !opts.model.startsWith('m')) {
24
- opts.model = `m${opts.model}`
25
- }
26
-
27
- const { country, ...query } = { ...inventories[inventory], ...opts }
28
-
29
- const duration = timestamp()
30
-
31
- const paginate = async (offset = 0) => {
32
- const url = new URL(
33
- `https://www.tesla.com/inventory/api/v1/inventory-results?${new URLSearchParams({
34
- query: JSON.stringify({
35
- query,
36
- count: ITEMS_PER_PAGE,
37
- offset,
38
- outsideOffset: 0,
39
- outsideSearch: false
40
- })
41
- }).toString()}`
42
- ).toString()
43
-
44
- debug({ url, ...query })
45
-
46
- const result = await pRetry(
47
- () =>
48
- fetcher(url, fetcherOpts).then(async text => {
49
- const body = JSON.parse(text)
50
- return { items: body.results ?? [] }
51
- }),
52
- {
53
- onFailedAttempt: debug.error
18
+ module.exports =
19
+ fetcher =>
20
+ async (inventory, opts, { retries = 2, ...fetcherOpts } = {}) => {
21
+ if (!inventories[inventory]) {
22
+ throw new TypeError(`Tesla inventory \`${inventory}\` not found!`)
54
23
  }
55
- )
56
24
 
57
- return result
58
- }
25
+ if (opts.model && !opts.model.startsWith('m')) {
26
+ opts.model = `m${opts.model}`
27
+ }
28
+
29
+ const { country, ...query } = { ...inventories[inventory], ...opts }
30
+
31
+ const duration = timestamp()
32
+
33
+ const paginate = async (offset = 0) => {
34
+ const url = new URL(
35
+ `https://www.tesla.com/inventory/api/v1/inventory-results?${new URLSearchParams({
36
+ query: JSON.stringify({
37
+ query,
38
+ count: ITEMS_PER_PAGE,
39
+ offset,
40
+ outsideOffset: 0,
41
+ outsideSearch: false
42
+ })
43
+ }).toString()}`
44
+ ).toString()
45
+
46
+ debug({ url, ...query })
47
+
48
+ const result = await pRetry(
49
+ () =>
50
+ fetcher(url, fetcherOpts).then(async text => {
51
+ const body = JSON.parse(text)
52
+ return { items: body.results ?? [] }
53
+ }),
54
+ {
55
+ onFailedAttempt: debug.error,
56
+ retries
57
+ }
58
+ )
59
+
60
+ return result
61
+ }
59
62
 
60
- let offset = 0
61
- let items = []
62
- let page
63
+ let offset = 0
64
+ let items = []
65
+ let page
63
66
 
64
- do {
65
- page = await paginate(offset)
66
- items = uniqBy(items.concat(page.items), 'VIN')
67
- offset = items.length
68
- debug.info({ ...opts, items: items.length, duration: duration() })
69
- } while (page.items.length >= ITEMS_PER_PAGE)
67
+ do {
68
+ page = await paginate(offset)
69
+ items = uniqBy(items.concat(page.items), 'VIN')
70
+ offset = items.length
71
+ debug.info({ ...opts, items: items.length, duration: duration() })
72
+ } while (page.items.length >= ITEMS_PER_PAGE)
70
73
 
71
- return items.filter(item => item.Model === opts.model)
72
- }
74
+ return items.filter(item => item.Model === opts.model)
75
+ }
@@ -32,6 +32,7 @@
32
32
  "MT329": 26110,
33
33
  "MT337": 7410,
34
34
  "MT340": 30010,
35
+ "MTS05": 12000,
35
36
  "MTX04": 15000,
36
37
  "MTY09": 17500,
37
38
  "MTY10": 30500,
@@ -57,6 +57,7 @@
57
57
  "MTX08": 254000,
58
58
  "MTX13": 166000,
59
59
  "MTX14": 286000,
60
+ "MTX15": 166000,
60
61
  "MTY07": 135000,
61
62
  "MTY09": 135000,
62
63
  "MTY12": 185250,