tesla-inventory 3.1.49 → 3.2.0-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/LICENSE.md CHANGED
File without changes
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.1.49",
5
+ "version": "3.2.0-0",
6
6
  "main": "src/index.js",
7
7
  "author": {
8
8
  "email": "josefrancisco.verdu@gmail.com",
@@ -40,6 +40,7 @@
40
40
  "devDependencies": {
41
41
  "@commitlint/cli": "latest",
42
42
  "@commitlint/config-conventional": "latest",
43
+ "@ksmithut/prettier-standard": "latest",
43
44
  "ava": "latest",
44
45
  "c8": "latest",
45
46
  "ci-publish": "latest",
@@ -54,7 +55,6 @@
54
55
  "markdown-tables-to-json": "latest",
55
56
  "nano-staged": "latest",
56
57
  "npm-check-updates": "latest",
57
- "prettier-standard": "latest",
58
58
  "simple-git-hooks": "latest",
59
59
  "standard": "latest",
60
60
  "standard-markdown": "latest",
@@ -66,21 +66,6 @@
66
66
  "files": [
67
67
  "src"
68
68
  ],
69
- "scripts": {
70
- "clean": "rm -rf node_modules",
71
- "contributors": "(npx git-authors-cli && npx finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
72
- "lint": "standard-markdown README.md && standard",
73
- "postrelease": "npm run release:tags && npm run release:github && (ci-publish || npm publish --access=public)",
74
- "prerelease": "npm run update:check && npm run contributors",
75
- "pretest": "npm run lint",
76
- "release": "standard-version -a",
77
- "release:github": "conventional-github-releaser -p angular",
78
- "release:tags": "git push --follow-tags origin HEAD:master",
79
- "test": "c8 ava",
80
- "update": "ncu -u",
81
- "update:check": "ncu -- --error-level 2",
82
- "update:dependencies": "ncu -u"
83
- },
84
69
  "license": "MIT",
85
70
  "ava": {
86
71
  "timeout": "2m"
@@ -118,7 +103,8 @@
118
103
  },
119
104
  "nano-staged": {
120
105
  "*.js": [
121
- "prettier-standard"
106
+ "prettier-standard",
107
+ "standard --fix"
122
108
  ],
123
109
  "*.md": [
124
110
  "standard-markdown"
@@ -130,5 +116,20 @@
130
116
  "simple-git-hooks": {
131
117
  "commit-msg": "npx commitlint --edit",
132
118
  "pre-commit": "npx nano-staged"
119
+ },
120
+ "scripts": {
121
+ "clean": "rm -rf node_modules",
122
+ "contributors": "(npx git-authors-cli && npx finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
123
+ "lint": "standard-markdown README.md && standard",
124
+ "postrelease": "npm run release:tags && npm run release:github && (ci-publish || npm publish --access=public)",
125
+ "prerelease": "npm run update:check && npm run contributors",
126
+ "pretest": "npm run lint",
127
+ "release": "standard-version -a",
128
+ "release:github": "conventional-github-releaser -p angular",
129
+ "release:tags": "git push --follow-tags origin HEAD:master",
130
+ "test": "c8 ava",
131
+ "update": "ncu -u",
132
+ "update:check": "ncu -- --error-level 2",
133
+ "update:dependencies": "ncu -u"
133
134
  }
134
- }
135
+ }
package/src/index.js CHANGED
@@ -3,63 +3,73 @@
3
3
  const debug = require('debug-logfmt')('tesla-inventory')
4
4
  const inventories = require('./inventories')
5
5
 
6
- const timestamp = (start = process.hrtime.bigint()) => () =>
7
- Math.round(Number(process.hrtime.bigint() - start) / 1e6) + 'ms'
6
+ const ITEMS_PER_PAGE = 50
7
+
8
+ const uniqBy = (arr, prop) =>
9
+ arr.filter((x, i, self) => i === self.findIndex(y => x[prop] === y[prop]))
10
+
11
+ const timestamp =
12
+ (start = process.hrtime.bigint()) =>
13
+ () =>
14
+ Math.round(Number(process.hrtime.bigint() - start) / 1e6) + 'ms'
8
15
 
9
- const got = require('got').extend({
16
+ const defaults = {
10
17
  url: 'https://www.tesla.com/inventory/api/v1/inventory-results',
11
18
  responseType: 'json',
12
19
  resolveBodyOnly: true,
13
20
  headers: { 'user-agent': undefined }
14
- })
21
+ }
15
22
 
16
- const uniqBy = (arr, prop) =>
17
- arr.filter((x, i, self) => i === self.findIndex(y => x[prop] === y[prop]))
23
+ const create = opts => {
24
+ const got = require('got').extend({ ...defaults, ...opts })
18
25
 
19
- const ITEMS_PER_PAGE = 50
26
+ return async (inventory, opts, gotOpts) => {
27
+ if (!inventories[inventory]) {
28
+ throw new TypeError(`Tesla inventory \`${inventory}\` not found!`)
29
+ }
20
30
 
21
- module.exports = async (inventory, opts, gotOpts) => {
22
- if (!inventories[inventory]) {
23
- throw new TypeError(`Tesla inventory \`${inventory}\` not found!`)
24
- }
31
+ if (opts.model && !opts.model.startsWith('m')) {
32
+ opts.model = `m${opts.model}`
33
+ }
25
34
 
26
- if (opts.model && !opts.model.startsWith('m')) {
27
- opts.model = `m${opts.model}`
28
- }
35
+ const { country, ...query } = { ...inventories[inventory], ...opts }
36
+
37
+ const duration = timestamp()
38
+
39
+ const paginate = async (offset = 0) =>
40
+ got(
41
+ got.mergeOptions(
42
+ got.defaults.options,
43
+ {
44
+ searchParams: {
45
+ query: JSON.stringify({
46
+ query,
47
+ count: ITEMS_PER_PAGE,
48
+ offset,
49
+ outsideOffset: 0,
50
+ outsideSearch: false
51
+ })
52
+ }
53
+ },
54
+ gotOpts
55
+ )
56
+ ).then(({ results }) => ({ items: results }))
57
+
58
+ let offset = 0
59
+ let items = []
60
+ let page
29
61
 
30
- const { country, ...query } = { ...inventories[inventory], ...opts }
31
-
32
- const duration = timestamp()
33
-
34
- const paginate = async (offset = 0) =>
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 }))
52
-
53
- let offset = 0
54
- let items = []
55
- let page
56
-
57
- do {
58
- page = await paginate(offset)
59
- items = uniqBy(items.concat(page.items), 'VIN')
60
- offset = items.length
61
- debug({ items: items.length, duration: duration() })
62
- } while (page.items.length >= ITEMS_PER_PAGE)
63
-
64
- return items.filter(item => item.Model === opts.model)
62
+ do {
63
+ page = await paginate(offset)
64
+ items = uniqBy(items.concat(page.items), 'VIN')
65
+ offset = items.length
66
+ debug({ items: items.length, duration: duration() })
67
+ } while (page.items.length >= ITEMS_PER_PAGE)
68
+
69
+ return items.filter(item => item.Model === opts.model)
70
+ }
65
71
  }
72
+
73
+ module.exports = create()
74
+
75
+ module.exports.create = create
@@ -25,7 +25,7 @@
25
25
  "MT304": 87720,
26
26
  "MT308": 25720,
27
27
  "MT310": 85720,
28
- "MT311": 124434,
28
+ "MT311": 87720,
29
29
  "MT314": 25720,
30
30
  "MT315": 115720,
31
31
  "MT316": 136600,
@@ -35,7 +35,7 @@
35
35
  "MT325": 87720,
36
36
  "MT328": 85720,
37
37
  "MT336": 25720,
38
- "MT337": 84810,
38
+ "MT337": 25720,
39
39
  "MT340": 136600,
40
40
  "MT341": 53720,
41
41
  "MT90A": 85000,
@@ -11,6 +11,7 @@
11
11
  "INPW0": 150000,
12
12
  "IPW1": 150000,
13
13
  "IWC00": 345000,
14
+ "IWW00": 345000,
14
15
  "MT303": 2347255,
15
16
  "MT310": 2347255,
16
17
  "MT316": 2347255,
@@ -23,6 +23,7 @@
23
23
  "PMNG": 1000,
24
24
  "PPMR": 2000,
25
25
  "PPSB": 1000,
26
+ "PPSW": 1000,
26
27
  "PR01": 3000,
27
28
  "ST0Y": 250,
28
29
  "STY7S": 3000,
@@ -105,7 +105,7 @@
105
105
  "QTVW": 2500,
106
106
  "RFP2": 2000,
107
107
  "ST0Y": 250,
108
- "STY7S": 3000,
108
+ "STY7S": 2500,
109
109
  "TW01": 1000,
110
110
  "W39B": 1500,
111
111
  "W41B": 1500,