-
Notifications
You must be signed in to change notification settings - Fork 8
/
DecodeVinValuesBatch.ts
241 lines (231 loc) · 6.71 KB
/
DecodeVinValuesBatch.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/**
* @module api/endpoints/DecodeVinValuesBatch
* @category API Endpoints
*/
import { useNHTSA } from '@/api'
import { catchInvalidArguments, rejectWithError } from '@/utils'
import type { IArgToValidate, NhtsaResponse } from '@/types'
/**
* ::: tip :bulb: More Information
* See: [DecodeVinValuesBatch Documentation](/api/endpoints/decode-vin-values-batch)
* :::
*
* `DecodeVinValuesBatch` decodes a batch of Vehicle Identification Numbers (VINs) and returns
* useful information about the vehicles in in a _flat format_. This means the endpoint will return
* an array with multiple objects of results. Each object represents a VIN from the `inputString`
* and the key:value pairs in the objects are variables and their values for each particular VIN.
*
* For this particular API you just have to provide a string of VINs, `inputString`, that are
* separated by a `;`. You can also indicate the model year after the vin, preceded by a `,`.
*
* The `inputString` parameter should be in the following format:
* - ex: `5UXWX7C5*BA, 2011; 5YJSA3DS*EF`
* - no modelYear: `vin; vin; vin`
* - with modelYear: `vin, modelYear; vin, modelYear; vin, modelYear`
* - mix of with/without modelYear: `vin; vin, modelYear`
* - _vin_ and _modelYear_ are placeholders for real values in these examples
* - all spaces between `;` and `,` are used in these examples for readability and are optional
* - _Max 50 VINs per batch_
*
* Providing the modelYear in the input string allows for the decoding to specifically be done in
* the current, or older (pre-1980), model year ranges. It is recommended to always provide
* the model year if it is known at the time of decoding, but it is not required.
*
* @param {string} inputString - A string of Vehicle Identification Numbers (full or partial)
* following the format listed in the description
* @param {boolean} [doFetch=true] - Whether to fetch the data or just return the URL
* (default: `true`)
* @returns {(Promise<NhtsaResponse<DecodeVinValuesBatchResults> | string>)} - Api Response `object`
* -or- url `string` if `doFetch = false`
*/
function DecodeVinValuesBatch(
inputString: string,
doFetch?: true
): Promise<NhtsaResponse<DecodeVinValuesBatchResults>>
function DecodeVinValuesBatch(
inputString: string,
doFetch: false
): Promise<string>
/* Implementation */
async function DecodeVinValuesBatch(
inputString: string,
doFetch = true
): Promise<NhtsaResponse<DecodeVinValuesBatchResults> | string> {
const endpointName = 'DecodeVinValuesBatch'
try {
const args: IArgToValidate[] = [
{
name: 'inputString',
value: inputString,
required: true,
types: ['string'],
},
]
catchInvalidArguments({ args })
const { post, createCachedUrl, getCachedUrl } = useNHTSA()
createCachedUrl({ endpointName, includeQueryString: false })
if (!doFetch) {
return getCachedUrl()
} else {
return post(getCachedUrl(), { body: inputString })
}
} catch (error) {
return rejectWithError(error)
}
}
export { DecodeVinValuesBatch }
/**
* Objects found in the `Results` array of `DecodeVinValuesBatch` endpoint response.
*/
export type DecodeVinValuesBatchResults = {
ABS: string
ActiveSafetySysNote: string
AdaptiveCruiseControl: string
AdaptiveDrivingBeam: string
AdaptiveHeadlights: string
AdditionalErrorText: string
AirBagLocCurtain: string
AirBagLocFront: string
AirBagLocKnee: string
AirBagLocSeatCushion: string
AirBagLocSide: string
AutoReverseSystem: string
AutomaticPedestrianAlertingSound: string
AxleConfiguration: string
Axles: string
BasePrice: string
BatteryA: string
BatteryA_to: string
BatteryCells: string
BatteryInfo: string
BatteryKWh: string
BatteryKWh_to: string
BatteryModules: string
BatteryPacks: string
BatteryType: string
BatteryV: string
BatteryV_to: string
BedLengthIN: string
BedType: string
BlindSpotIntervention: string
BlindSpotMon: string
BodyCabType: string
BodyClass: string
BrakeSystemDesc: string
BrakeSystemType: string
BusFloorConfigType: string
BusLength: string
BusType: string
CAN_AACN: string
CIB: string
CashForClunkers: string
ChargerLevel: string
ChargerPowerKW: string
CoolingType: string
CurbWeightLB: string
CustomMotorcycleType: string
DaytimeRunningLight: string
DestinationMarket: string
DisplacementCC: string
DisplacementCI: string
DisplacementL: string
Doors: string
DriveType: string
DriverAssist: string
DynamicBrakeSupport: string
EDR: string
ESC: string
EVDriveUnit: string
ElectrificationLevel: string
EngineConfiguration: string
EngineCycles: string
EngineCylinders: string
EngineHP: string
EngineHP_to: string
EngineKW: string
EngineManufacturer: string
EngineModel: string
EntertainmentSystem: string
ErrorCode: string
ErrorText: string
ForwardCollisionWarning: string
FuelInjectionType: string
FuelTypePrimary: string
FuelTypeSecondary: string
GCWR: string
GCWR_to: string
GVWR: string
GVWR_to: string
KeylessIgnition: string
LaneCenteringAssistance: string
LaneDepartureWarning: string
LaneKeepSystem: string
LowerBeamHeadlampLightSource: string
Make: string
MakeID: string
Manufacturer: string
ManufacturerId: string
Model: string
ModelID: string
ModelYear: string
MotorcycleChassisType: string
MotorcycleSuspensionType: string
NCSABodyType: string
NCSAMake: string
NCSAMapExcApprovedBy: string
NCSAMapExcApprovedOn: string
NCSAMappingException: string
NCSAModel: string
NCSANote: string
NonLandUse: string
Note: string
OtherBusInfo: string
OtherEngineInfo: string
OtherMotorcycleInfo: string
OtherRestraintSystemInfo: string
OtherTrailerInfo: string
ParkAssist: string
PedestrianAutomaticEmergencyBraking: string
PlantCity: string
PlantCompanyName: string
PlantCountry: string
PlantState: string
PossibleValues: string
Pretensioner: string
RearAutomaticEmergencyBraking: string
RearCrossTrafficAlert: string
RearVisibilitySystem: string
SAEAutomationLevel: string
SAEAutomationLevel_to: string
SeatBeltsAll: string
SeatRows: string
Seats: string
SemiautomaticHeadlampBeamSwitching: string
Series: string
Series2: string
SteeringLocation: string
SuggestedVIN: string
TPMS: string
TopSpeedMPH: string
TrackWidth: string
TractionControl: string
TrailerBodyType: string
TrailerLength: string
TrailerType: string
TransmissionSpeeds: string
TransmissionStyle: string
Trim: string
Trim2: string
Turbo: string
VIN: string
ValveTrainDesign: string
VehicleDescriptor: string
VehicleType: string
WheelBaseLong: string
WheelBaseShort: string
WheelBaseType: string
WheelSizeFront: string
WheelSizeRear: string
Wheels: string
Windows: string
}