diff --git a/.eslintignore b/.eslintignore index 4ebc8aea..c4d48a6b 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ coverage +doc diff --git a/doc/AuthClient.html b/doc/AuthClient.html new file mode 100644 index 00000000..095de62b --- /dev/null +++ b/doc/AuthClient.html @@ -0,0 +1,1387 @@ + + + + + JSDoc: Class: AuthClient + + + + + + + + + + +
+ +

Class: AuthClient

+ + + + + + +
+ +
+ +

AuthClient(options)

+ + +
+ +
+
+ + + + + + +

new AuthClient(options)

+ + + + + + +
+

Create a Smartcar OAuth client for your application.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
options + + +Object + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
clientId + + +String + + + + + + + + + + + +

Application client id obtained from +Smartcar Developer Portal. If you do not +have access to the dashboard, please +request access.

clientSecret + + +String + + + + + + + + + + + +

The application's client secret.

redirectUri + + +String + + + + + + + + + + + +

Redirect URI registered in the +application settings. The given URL +must exactly match one of the registered URLs.

testMode + + +Boolean + + + + + + <optional>
+ + + + + +
+ + false + +

Deprecated, please use mode instead. +Launch Smartcar Connect in test mode.

mode + + +String + + + + + + <optional>
+ + + + + +
+ + 'live' + +

Determine what mode Smartcar Connect should be +launched in. Should be one of test, live or simulated.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + +

Methods

+ + + + + + + +

exchangeCode(code) → {Access}

+ + + + + + +
+

Exchange an authorization code for an access object.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
code + + +String + + + + + + + + + +

Authorization code to exchange for a Smartcar +access token and refresh token.

options.flags + + +Object + + + + + + <optional>
+ + + + + +

Object of flags where key is the name of the flag +value is string or boolean value.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + +
+

New set of Access and Refresh tokens.

+
+ + + +
+
+ Type +
+
+ +Access + + +
+
+ + + + + + + + + + + + + +

exchangeRefreshToken(token) → {Access}

+ + + + + + +
+

Exchange a refresh token for a new access object.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
token + + +String + + + + + + + + + +

Refresh token to exchange for a new set of Access and +Refresh tokens.

options.flags + + +Object + + + + + + <optional>
+ + + + + +

Object of flags where key is the name of the flag +value is string or boolean value.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + +
+

New set of Access and Refresh tokens.

+
+ + + +
+
+ Type +
+
+ +Access + + +
+
+ + + + + + + + + + + + + +

getAuthUrl(scopeopt, optionsopt) → {String}

+ + + + + + +
+

Generate the Smartcar Connect URL.

+

By default users are not shown the permission dialog if they have already +approved the set of scopes for this application. The application can elect +to always display the permissions dialog to the user by setting +approval_prompt to force.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
scope + + +Array.<String> + + + + + + <optional>
+ + + + + +

List of permissions your application +requires. The valid permission names are found in the API Reference

options + + +Object + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
forcePrompt + + +Boolean + + + + + + <optional>
+ + + + + +

Setting forcePrompt to +true will show the permissions approval screen on every authentication +attempt, even if the user has previously consented to the exact scope of +permissions.

singleSelect + + +Boolean +| + +Object + + + + + + <optional>
+ + + + + +

An optional value that sets the +behavior of the grant dialog displayed to the user. Object can contain two keys :

+
    +
  • enabled - Boolean value, if set to true, single_select limits the user to +selecting only one vehicle.
  • +
  • vin - String vin, if set, Smartcar will only authorize the vehicle with the specified VIN. +See the Single Select guide for more information.
  • +
state + + +String + + + + + + <optional>
+ + + + + +

OAuth state parameter passed to the +redirect uri. This parameter may be used for identifying the user who +initiated the request.

makeBypass + + +Object + + + + + + <optional>
+ + + + + +

An optional parameter that allows +users to bypass the car brand selection screen. +For a complete list of supported makes, please see our +API Reference documentation.

flags + + +Object + + + + + + <optional>
+ + + + + +

Object of flags where key is the name of the flag +value is string or boolean value.

user + + +String + + + + + + <optional>
+ + + + + +

An optional unique identifier for a vehicle owner. +This identifier is used to aggregate analytics across Connect sessions for each vehicle owner.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + +
+

Smartcar Connect URL to direct user to.

+
+ + + +
+
+ Type +
+
+ +String + + +
+
+ + + + + + +
Example
+ +
https://connect.smartcar.com/oauth/authorize?
+response_type=code
+&client_id=8229df9f-91a0-4ff0-a1ae-a1f38ee24d07
+&scope=read_odometer read_vehicle_info
+&redirect_uri=https://example.com/home
+&state=0facda3319
+&make=TESLA
+&single_select=true
+&single_select_vin=5YJSA1E14FF101307
+&flags=country:DE color:00819D
+&user=61a3e3d2-5198-47ba-aabd-4623ce4a4042
+ + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/SmartcarError.html b/doc/SmartcarError.html new file mode 100644 index 00000000..bac6b3e8 --- /dev/null +++ b/doc/SmartcarError.html @@ -0,0 +1,1139 @@ + + + + + JSDoc: Class: SmartcarError + + + + + + + + + + +
+ +

Class: SmartcarError

+ + + + + + +
+ +
+ +

SmartcarError(status, body, headers)

+ +

Class to handle all errors from Smartcar API +Please see our error guides to see a list +of all the possible error types and codes of both v2.0 and v1.0 requests.

+ + +
+ +
+
+ + + + +

Constructor

+ + + +

new SmartcarError(status, body, headers)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
status + + +number + + + +

response status

body + + +object + + + +

response body

headers + + +object + + + +

response headers

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Members

+ + + +

(static) code :string

+ + + + +
+

Error code

+
+ + + +
Type:
+
    +
  • + +string + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

(static) description :string

+ + + + +
+

Description of meaning of the error.

+
+ + + +
Type:
+
    +
  • + +string + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

(static) details :Array.<object>

+ + + + +
+

Further detail about the error in form of array of objects

+
+ + + +
Type:
+
    +
  • + +Array.<object> + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

(static) docURL :string

+ + + + +
+

Reference to Smartcar documentation

+
+ + + +
Type:
+
    +
  • + +string + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

(static) error :string

+ + + + +
+

Legacy field from V1 error depicting a category/type/description +of the error.

+
+ + + +
Type:
+
    +
  • + +string + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

(static) message :string

+ + + + +
+

Error message field inherited from StandardError

+
+ + + +
Type:
+
    +
  • + +string + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

(static) requestId :string

+ + + + +
+

Unique identifier for request

+
+ + + +
Type:
+
    +
  • + +string + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

(static) resolution :SmartcarError.Resolution

+ + + + +
+

Possible resolution for fixing the error

+
+ + + +
Type:
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

(static) statusCode :number

+ + + + +
+

HTTP status code

+
+ + + +
Type:
+
    +
  • + +number + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

(static) type :string

+ + + + +
+

Type of error

+
+ + + +
Type:
+
    +
  • + +string + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + +

Type Definitions

+ + + +

Resolution

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + +

Possible hint to fixing the issue

url + + +String + + + +

A URL to help resolve the issue or resume the operation

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/SmartcarService.html b/doc/SmartcarService.html new file mode 100644 index 00000000..5dd375e4 --- /dev/null +++ b/doc/SmartcarService.html @@ -0,0 +1,358 @@ + + + + + JSDoc: Class: SmartcarService + + + + + + + + + + +
+ +

Class: SmartcarService

+ + + + + + +
+ +
+ +

SmartcarService(optionsopt)

+ + +
+ +
+
+ + + + + + +

new SmartcarService(optionsopt)

+ + + + + + +
+

Initializes a new Service object to make requests to the Smartcar API.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
options + + +Object + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
baseUrl + + +String + + + + + + <optional>
+ + + + + +

Host/Base URL for the requests

auth + + +Object + + + + + + <optional>
+ + + + + +

authorization options

headers + + +Object + + + + + + <optional>
+ + + + + +

headers to add

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/Vehicle.html b/doc/Vehicle.html new file mode 100644 index 00000000..0361ff0a --- /dev/null +++ b/doc/Vehicle.html @@ -0,0 +1,4745 @@ + + + + + JSDoc: Class: Vehicle + + + + + + + + + + +
+ +

Class: Vehicle

+ + + + + + +
+ +
+ +

Vehicle(id, token, optionsopt)

+ + +
+ +
+
+ + + + + + +

new Vehicle(id, token, optionsopt)

+ + + + + + +
+

Initializes a new Vehicle to use for making requests to the Smartcar API.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
id + + +String + + + + + + + + + +

The vehicle's unique identifier. Retrieve a user's +vehicle id using module:smartcar.getVehicles.

token + + +String + + + + + + + + + +

A valid access token

options + + +Object + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
unitSystem + + +String + + + + + + <optional>
+ + + + + +
+ + metric + +

The unit system to use for vehicle data +must be either metric or imperial.

version + + +Object + + + + + + <optional>
+ + + + + +
+ +

API version to use

flags + + +Object + + + + + + <optional>
+ + + + + +
+ +

Object of flags where key is the name of the flag +and value is string or boolean value.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + +

Methods

+ + + + + + + +

attributes() → {Attributes}

+ + + + + + +
+

Returns make model year and id of the vehicle

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Attributes + + +
+
+ + + + + + + + + + + + + +

batch(paths) → {Batch}

+ + + + + + +
+

Make batch requests for supported items

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
paths + + +Array.<String> + + + +

A list of paths of endpoints to send requests to.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • on unsuccessful request. An instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Batch + + +
+
+ + + + + + + + + + + + + +

battery() → {Battery}

+ + + + + + +
+

Returns the state of charge (SOC) and remaining range of an electric or +plug-in hybrid vehicle's battery.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Battery + + +
+
+ + + + + + + + + + + + + +

batteryCapacity() → {BatteryCapacity}

+ + + + + + +
+

Returns the capacity of an electric or plug-in hybrid vehicle's battery.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +BatteryCapacity + + +
+
+ + + + + + + + + + + + + +

charge() → {Charge}

+ + + + + + +
+

Returns the current charge status of the vehicle.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Charge + + +
+
+ + + + + + + + + + + + + +

disconnect() → {ActionResponse}

+ + + + + + +
+

Disconnect this vehicle from the connected application. +Note: Calling this method will invalidate your token's access to the vehicle. +You will have to reauthorize the user to your application again if you wish +to make requests to it again.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +ActionResponse + + +
+
+ + + + + + + + + + + + + +

engineOil() → {EngineOil}

+ + + + + + +
+

Returns the remaining life span of a vehicle's engine oil

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +EngineOil + + +
+
+ + + + + + + + + + + + + +

fuel() → {Fuel}

+ + + + + + +
+

Returns the status of the fuel remaining in the vehicle's gas tank.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Fuel + + +
+
+ + + + + + + + + + + + + +

getChargeLimit() → {ChargeLimit}

+ + + + + + +
+

Fetch the charge limit for an electric vehicle

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +ChargeLimit + + +
+
+ + + + + + +
Example
+ +
{
+  limit: .7,
+  meta: {
+   requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+  }
+}
+ + + + + + + + + +

location() → {Location}

+ + + + + + +
+

Returns the last known location of the vehicle in geographic coordinates.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Location + + +
+
+ + + + + + + + + + + + + +

lock() → {ActionResponse}

+ + + + + + +
+

Attempts to lock the vehicle.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +ActionResponse + + +
+
+ + + + + + + + + + + + + +

lockStatus() → {LockStatus}

+ + + + + + +
+

Returns the lock status of the vehicle.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +LockStatus + + +
+
+ + + + + + + + + + + + + +

odometer() → {Odometer}

+ + + + + + +
+

Returns the vehicle's last known odometer reading.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Odometer + + +
+
+ + + + + + + + + + + + + +

permissions(pagingopt) → {Permissions}

+ + + + + + +
+

Fetch the list of permissions that this application has been granted

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
paging + + +Object + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
limit + + +String + + + + + + <optional>
+ + + + + +

number of permissions to return

+ +
options.offset + + +Object + + + + + + <optional>
+ + + + + +

The current start index of the returned list of elements.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Permissions + + +
+
+ + + + + + + + + + + + + +

request(method, path, body, headers) → {Response}

+ + + + + + +
+

General purpose method to make a request to a Smartcar endpoint.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
method + + +String + + + +

The HTTP request method to use.

path + + +String + + + +

The path to make the request to.

body + + +Object + + + +

The request body.

headers + + +Object + + + +

The headers to include in the request.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Response + + +
+
+ + + + + + + + + + + + + +

sendDestination(latitude, longitude) → {ActionResponse}

+ + + + + + +
+

Send a destination to the vehicle's navigation system.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
latitude + + +number + + + +

Latitude of the destination. Must be a valid latitude +value between -90 and 90 (inclusive).

longitude + + +number + + + +

Longitude of the destination. Must be a valid longitude +value between -180 and 180 (inclusive).

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • An instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + +
+
    +
  • A Response object containing the status and metadata.
  • +
+
+ + + +
+
+ Type +
+
+ +ActionResponse + + +
+
+ + + + + + +
Example
+ +
{
+  status: string,
+  meta: {
+    requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+  }
+}
+ + + + + + + + + +

serviceHistory(startDateopt, endDateopt) → {Array.<ServiceHistory>}

+ + + + + + +
+

Returns a list of all the service records performed on the vehicle, +filtered by the optional date range. If no dates are specified, records from the +last year are returned.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
startDate + + +String + + + + + + <optional>
+ + + + + +

The start date for the record filter, either in 'YYYY-MM-DD' or +'YYYY-MM-DDTHH:MM:SS.SSSZ' format.

endDate + + +String + + + + + + <optional>
+ + + + + +

The end date for the record filter, similar format to startDate.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. See the errors section for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array.<ServiceHistory> + + +
+
+ + + + + + + + + + + + + +

setChargeLimit(limit) → {ChargeLimit}

+ + + + + + +
+

Set the charge limit for an electric vehicle.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
limit + + +number + + + +

a number between 0 and 1

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +ChargeLimit + + +
+
+ + + + + + +
Example
+ +
{
+  status: string,
+  meta: {
+   requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+  }
+}
+ + + + + + + + + +

startCharge() → {ActionResponse}

+ + + + + + +
+

Attempts to start charging the vehicle.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +ActionResponse + + +
+
+ + + + + + + + + + + + + +

stopCharge() → {ActionResponse}

+ + + + + + +
+

Attempts to stop charging the vehicle.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +ActionResponse + + +
+
+ + + + + + + + + + + + + +

subscribe(webhookId) → {Object}

+ + + + + + +
+

Subscribe the vehicle to given webhook Id

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
webhookId + + +String + + + +

Webhook Id to subscribe to.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + +
+
+ + + + + + + + + + + + + +

tirePressure() → {TirePressure}

+ + + + + + +
+

Returns the air pressure of each of the vehicle's tires.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +TirePressure + + +
+
+ + + + + + + + + + + + + +

unlock() → {ActionResponse}

+ + + + + + +
+

Attempts to lock the vehicle.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +ActionResponse + + +
+
+ + + + + + + + + + + + + +

unsubscribe(amt, webhookId) → {Meta}

+ + + + + + +
+

Unsubscribe the vehicle from given webhook Id

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amt + + +String + + + +

Application management token to be used as authorization

webhookId + + +String + + + +

Webhook Id to unsubscribe from.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Meta + + +
+
+ + + + + + + + + + + + + +

vin() → {Vin}

+ + + + + + +
+

Returns the vehicle's manufacturer identifier (VIN).

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Vin + + +
+
+ + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/fonts/OpenSans-Bold-webfont.eot b/doc/fonts/OpenSans-Bold-webfont.eot new file mode 100644 index 00000000..5d20d916 Binary files /dev/null and b/doc/fonts/OpenSans-Bold-webfont.eot differ diff --git a/doc/fonts/OpenSans-Bold-webfont.svg b/doc/fonts/OpenSans-Bold-webfont.svg new file mode 100644 index 00000000..3ed7be4b --- /dev/null +++ b/doc/fonts/OpenSans-Bold-webfont.svg @@ -0,0 +1,1830 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/doc/fonts/OpenSans-Bold-webfont.woff b/doc/fonts/OpenSans-Bold-webfont.woff new file mode 100644 index 00000000..1205787b Binary files /dev/null and b/doc/fonts/OpenSans-Bold-webfont.woff differ diff --git a/doc/fonts/OpenSans-BoldItalic-webfont.eot b/doc/fonts/OpenSans-BoldItalic-webfont.eot new file mode 100644 index 00000000..1f639a15 Binary files /dev/null and b/doc/fonts/OpenSans-BoldItalic-webfont.eot differ diff --git a/doc/fonts/OpenSans-BoldItalic-webfont.svg b/doc/fonts/OpenSans-BoldItalic-webfont.svg new file mode 100644 index 00000000..6a2607b9 --- /dev/null +++ b/doc/fonts/OpenSans-BoldItalic-webfont.svg @@ -0,0 +1,1830 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/doc/fonts/OpenSans-BoldItalic-webfont.woff b/doc/fonts/OpenSans-BoldItalic-webfont.woff new file mode 100644 index 00000000..ed760c06 Binary files /dev/null and b/doc/fonts/OpenSans-BoldItalic-webfont.woff differ diff --git a/doc/fonts/OpenSans-Italic-webfont.eot b/doc/fonts/OpenSans-Italic-webfont.eot new file mode 100644 index 00000000..0c8a0ae0 Binary files /dev/null and b/doc/fonts/OpenSans-Italic-webfont.eot differ diff --git a/doc/fonts/OpenSans-Italic-webfont.svg b/doc/fonts/OpenSans-Italic-webfont.svg new file mode 100644 index 00000000..e1075dcc --- /dev/null +++ b/doc/fonts/OpenSans-Italic-webfont.svg @@ -0,0 +1,1830 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/doc/fonts/OpenSans-Italic-webfont.woff b/doc/fonts/OpenSans-Italic-webfont.woff new file mode 100644 index 00000000..ff652e64 Binary files /dev/null and b/doc/fonts/OpenSans-Italic-webfont.woff differ diff --git a/doc/fonts/OpenSans-Light-webfont.eot b/doc/fonts/OpenSans-Light-webfont.eot new file mode 100644 index 00000000..14868406 Binary files /dev/null and b/doc/fonts/OpenSans-Light-webfont.eot differ diff --git a/doc/fonts/OpenSans-Light-webfont.svg b/doc/fonts/OpenSans-Light-webfont.svg new file mode 100644 index 00000000..11a472ca --- /dev/null +++ b/doc/fonts/OpenSans-Light-webfont.svg @@ -0,0 +1,1831 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/doc/fonts/OpenSans-Light-webfont.woff b/doc/fonts/OpenSans-Light-webfont.woff new file mode 100644 index 00000000..e7860748 Binary files /dev/null and b/doc/fonts/OpenSans-Light-webfont.woff differ diff --git a/doc/fonts/OpenSans-LightItalic-webfont.eot b/doc/fonts/OpenSans-LightItalic-webfont.eot new file mode 100644 index 00000000..8f445929 Binary files /dev/null and b/doc/fonts/OpenSans-LightItalic-webfont.eot differ diff --git a/doc/fonts/OpenSans-LightItalic-webfont.svg b/doc/fonts/OpenSans-LightItalic-webfont.svg new file mode 100644 index 00000000..431d7e35 --- /dev/null +++ b/doc/fonts/OpenSans-LightItalic-webfont.svg @@ -0,0 +1,1835 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/doc/fonts/OpenSans-LightItalic-webfont.woff b/doc/fonts/OpenSans-LightItalic-webfont.woff new file mode 100644 index 00000000..43e8b9e6 Binary files /dev/null and b/doc/fonts/OpenSans-LightItalic-webfont.woff differ diff --git a/doc/fonts/OpenSans-Regular-webfont.eot b/doc/fonts/OpenSans-Regular-webfont.eot new file mode 100644 index 00000000..6bbc3cf5 Binary files /dev/null and b/doc/fonts/OpenSans-Regular-webfont.eot differ diff --git a/doc/fonts/OpenSans-Regular-webfont.svg b/doc/fonts/OpenSans-Regular-webfont.svg new file mode 100644 index 00000000..25a39523 --- /dev/null +++ b/doc/fonts/OpenSans-Regular-webfont.svg @@ -0,0 +1,1831 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/doc/fonts/OpenSans-Regular-webfont.woff b/doc/fonts/OpenSans-Regular-webfont.woff new file mode 100644 index 00000000..e231183d Binary files /dev/null and b/doc/fonts/OpenSans-Regular-webfont.woff differ diff --git a/doc/global.html b/doc/global.html new file mode 100644 index 00000000..e9baa2c3 --- /dev/null +++ b/doc/global.html @@ -0,0 +1,4046 @@ + + + + + JSDoc: Global + + + + + + + + + + +
+ +

Global

+ + + + + + +
+ +
+ +

+ + +
+ +
+
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + + + + + + + + + +

Members

+ + + +

(constant) METHODS_MAP :object.<String, Object>

+ + + + +
+

Every key here is the function name on vehicle +This map is used to generate the methods dynamically. Every value is an object of +the following fields :

+
    +
  • requestType: http request type, defaults to 'get' if not mentioned.
  • +
  • path: url path to hit, defaults to the method name
  • +
  • body: body for post requests.
  • +
+
+ + + +
Type:
+
    +
  • + +object.<String, Object> + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + +

Type Definitions

+ + + +

Access

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
expiration + + +Date + + + +

Date object which represents when the access +token expires.

accessToken + + +String + + + +

A token to be used for requests to the +Smartcar API

refreshToken + + +String + + + +

A token which is used to renew access when +the current access token expires, expires in 60 days

refreshExpiration + + +Date + + + +

Date object which represents when the +refresh token expires.

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + +
Example
+ +
{
+  expiration: new Date('2017-05-26T01:21:27.070Z'),
+  accessToken: '88704225-9f6c-4919-93e7-e0cec71317ce',
+  refreshToken: '60a9e801-6d26-4d88-926e-5c7f9fc13486',
+  refreshExpiration: new Date('2017-05-26T01:21:27.070Z'),
+}
+ + + + + +

ActionResponse

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
status + + +String + + + +

set to success on successful request

meta + + +Meta + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + +
Example
+ +
{
+  status: 'success',
+  meta: {
+   requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+  }
+}
+ + + + + +

Attributes

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + +

The vehicle's unique Smartcar identifier.

make + + +String + + + +

The brand of the vehicle.

model + + +String + + + +

The specific model of the vehicle.

year + + +Number + + + +

The model year of the vehicle.

meta + + +Meta + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + +
Example
+ +
{
+  id: '19c0cc8c-80e0-4182-9372-6ef903c7599c',
+  make: 'TESLA',
+  model: 'S',
+  year: 2017,
+  meta: {
+   requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+  }
+}
+ + + + + +

Batch

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
ENDPOINT + + +function + + + +

The response object for a given ENDPOINT where +ENDPOINT is a Smartcar endpoint (i.e. /odometer, /fuel) or throws SmartcarError +if the endpoint resulted in an error.

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + +
Example
+ +
{
+   "odometer" : function() => returns odometer object or throws SmartcarError,
+   "location" : function() => returns odometer location or throws SmartcarError,
+}
+ + + + + +

Battery

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
range + + +Number + + + +

The estimated remaining distance the car can +travel (in kms or miles). Unit is passed as a parameter in vehicle constructor.

percentRemaining + + +Number + + + +

The remaining level of charge in +the battery (in percent).

meta + + +Meta + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + +
Example
+ +
{
+  range: 40.5,
+  percentRemaining: 0.3,
+  meta: {
+   dataAge: new Date('2018-05-04T07:20:50.844Z'),
+   unitSystem: 'imperial',
+   requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+  }
+}
+ + + + + +

BatteryCapacity

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
capacity + + +Number + + + +

The total capacity of the vehicle's battery +(in kilowatt-hours)

meta + + +Meta + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + +
Example
+ +
{
+  capacity: 24,
+  meta: {
+   dataAge: new Date('2018-05-04T07:20:50.844Z'),
+   unitSystem: 'imperial',
+   requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+  }
+}
+ + + + + +

Charge

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
isPluggedIn + + +Boolean + + + +

Indicates whether charging cable is +plugged in.

state + + +String + + + +

Indicates the current state of the charge +system. Can be FULLY_CHARGED, CHARGING, or NOT_CHARGING.

meta + + +Meta + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + +
Example
+ +
{
+  isPluggedIn: false,
+  state: "FULLY_CHARGED",
+  meta: {
+    dataAge: new Date('2018-05-04T07:20:50.844Z'),
+  }
+}
+ + + + + +

ChargeLimit

+ + + + + + + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
limit + + +number + + + +

the charge limit expressed as a decimal value between 0 and 1.

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

EngineOil

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
lifeRemaining + + +Number + + + +

The engine oil's remaining life span +(as a percentage). Oil life is based on the current quality of the oil.

meta + + +Meta + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + +
Example
+ +
{
+  lifeRemaining: 0.86,
+  meta: {
+   dataAge: new Date('2018-05-04T07:20:50.844Z'),
+   unitSystem: 'imperial',
+   requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+  }
+}
+ + + + + +

Fuel

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
range + + +Number + + + +

The estimated remaining distance the car can +travel (in kms or miles). Unit is passed as a parameter in vehicle constructor.

percentRemaining + + +Number + + + +

The remaining level of fuel in +the tank (in percent).

amountRemaining + + +Number + + + +

The amount of fuel in the tank (in +liters or gallons (US)). Unit is passed as a parameter in vehicle constructor.

meta + + +Meta + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + +
Example
+ +
{
+  range: 40.5,
+  percentRemaining: 0.3,
+  amountRemaining: 40.5,
+  meta: {
+   dataAge: new Date('2018-05-04T07:20:50.844Z'),
+   unitSystem: 'imperial',
+   requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+  }
+}
+ + + + + +

Location

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
latitude + + +Number + + + +

The vehicle latitude (in degrees).

longitude + + +Number + + + +

The vehicle longitude (in degrees).

meta + + +Meta + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + +
Example
+ +
{
+  latitude: 37.400880,
+  longitude: -122.057804,
+  meta: {
+   dataAge: new Date('2018-05-04T07:20:50.844Z'),
+   unitSystem: 'imperial',
+   requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+  }
+}
+ + + + + +

Meta

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dataAge + + +Date + + + +

The timestamp of when the data was recorded; returned if applicable.

requestId + + +String + + + +

The smartcar request ID for debugging

unitSystem + + +String + + + +

Unit system used, metric or imperial; returned if applicable.

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + +
Example
+ +
{
+  requestId: 'b9593682-8515-4f36-8190-bb56cde4c38a',
+  dataAge: new Date('2018-05-04T07:20:50.844Z'),
+  unitSystem: 'imperial',
+}
+ + + + + +

Odometer

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
distance + + +Number + + + +

The reading of the vehicle's odometer (in +kms or miles). Unit is passed as a parameter in vehicle constructor.

meta + + +Meta + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + +
Example
+ +
{
+  distance: 1234.12,
+  meta: {
+   dataAge: new Date('2018-05-04T07:20:50.844Z'),
+   unitSystem: 'imperial',
+   requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+  }
+}
+ + + + + +

Permissions

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
permissions + + +Array.<String> + + + + + + + +

An array of permissions names.

paging + + +Object + + + + + + <optional>
+ + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
count + + +Number + + + + + + <optional>
+ + + +

The total number of elements for the entire query +(not just the given page).

+ +
options.offset + + +Number + + + + + + <optional>
+ + + +

The current start index of the returned list of elements.

meta + + +Meta + + + + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + +
Example
+ +
{
+  permissions: ['read_vehicle_info'],
+  paging: {
+     count: 25,
+     offset: 10
+  },
+  meta: {
+   requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+  }
+}
+ + + + + +

Response

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
body + + +String + + + +

The response body

meta + + +Meta + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + +
Example
+ +
{
+ body: { distance: 59801.6373441601 },
+ meta: {
+   dataAge: 2022-01-20T02:55:25.041Z,
+   unitSystem: 'imperial',
+   requestId: 'f787849d-d228-482d-345f-459a5154sg73'
+ }
+}
+ + + + + +

SecurityResponse

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
isLocked + + +Boolean + + + +

Whether the vehicle is locked or not.

doors + + +Array + + + +

The status of each of the vehicle's doors.

windows + + +Array + + + +

The status of each of the vehicle's windows.

sunroof + + +Array + + + +

The status of each of the vehicle's sunroof.

storage + + +Array + + + +

The status of each of the vehicle's storage.

chargingPort + + +Array + + + +

The status of each of the vehicle's chargingPort.

meta + + +Meta + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + +
Example
+ +
{
+   isLocked: true,
+   doors: [
+      {
+          type: 'frontLeft',
+          status: 'LOCKED',
+      },
+      {
+          type: 'frontRight',
+          status: 'LOCKED',
+      },
+      {
+          type: 'backLeft',
+          status: 'LOCKED',
+      },
+      {
+          type: 'backRight',
+          status: 'LOCKED',
+      },
+   ],
+   windows: [
+      {
+          type: 'frontLeft',
+          status: 'CLOSED',
+      },
+      {
+          type: 'frontRight',
+          status: 'CLOSED',
+      },
+      {
+          type: 'backLeft',
+          status: 'CLOSED',
+      },
+      {
+          type: 'backRight',
+          status: 'CLOSED',
+      },
+   ],
+   sunroof: [
+      {
+          type: 'sunroof',
+          status: 'CLOSED',
+      },
+   ],
+   storage: [
+      {
+          type: 'rear',
+          status: 'CLOSED',
+      },
+      {
+          type: 'front',
+          status: 'CLOSED',
+      },
+   ],
+   chargingPort: [
+      {
+          type: 'chargingPort',
+          status: 'CLOSED',
+      },
+   ],
+   meta: {
+       dataAge: new Date('2018-05-04T07:20:50.844Z'),
+       requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+   },
+}
+ + + + + +

ServiceHistory

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
serviceID + + +Number +| + +null + + + +

The unique identifier for the service record, +or null if not available.

serviceDate + + +String + + + +

The date and time the service was performed.

odometerDistance + + +Number + + + +

The odometer reading at the time of service, +in miles or kilometers based on the unit system.

serviceTasks + + +Array.<ServiceTask> + + + +

A list of tasks performed during the service.

serviceDetails + + +ServiceDetails + + + +

Details about the service +provider and the type of service.

serviceCost + + +ServiceCost + + + +

The cost of the service with currency.

meta + + +Meta + + + +

Metadata related to the service record.

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + +
Example
+ +
[
+  {
+    serviceId: 12345,
+    serviceDate: "2022-07-10T16:20:00.000Z",
+    odometerDistance: 50000,
+    serviceTasks: [
+      {
+        taskId: 01,
+        taskDescription: "oil change"
+      }
+    ],
+    serviceDetails: {
+      type: "dealership"  // "manual_entry" could be another possible value
+    },
+    serviceCost: {
+      totalCost: 100,
+      currency: 'USD'
+    },
+    meta: {
+      dataAge: new Date('2023-04-30T07:20:50.844Z'),
+      unitSystem: 'imperial',
+      requestId: 'b3c14915-0c26-43c5-8e42-9edfc2a66b2f'
+    }
+  }
+  // ... additional service records
+]
+ + + + + +

TirePressure

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
frontLeft + + +Number + + + +

The current air pressure of the front left tire

frontRight + + +Number + + + +

The current air pressure of the back right tire

backLeft + + +Number + + + +

The current air pressure of the back left tire

backRight + + +Number + + + +

The current air pressure of the back right tire

meta + + +Meta + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + +
Example
+ +
{
+  frontLeft: 33,
+  frontRight: 34,
+  backLeft: 34,
+  backRight: 33
+  meta: {
+   dataAge: new Date('2018-05-04T07:20:50.844Z'),
+   unitSystem: 'imperial',
+   requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+  }
+}
+ + + + + +

Vin

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
vin + + +String + + + +

VIN of the vehicle

meta + + +Meta + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + +
Example
+ +
{
+  vin: '12345678901234567',
+  meta: {
+    requestId: 'b9593682-8515-4f36-8190-bb56cde4c38a',
+  }
+}
+ + + + + +

WebhookSubscription

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
webhookId + + +String + + + +

Webhook Id that the vehicle was subscribed to

vehicleId + + +String + + + +

Current vehicle id that was subscribed to the webhook

meta + + +Meta + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + +
Example
+ +
{
+  webhookId: 'dd214915-0c26-13c5-8e42-7edfc2ab320a',
+  vehicleId: '19c0cc8c-80e0-4182-9372-6ef903c7599c',
+  meta: {
+   requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+  }
+}
+ + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/index.html b/doc/index.html new file mode 100644 index 00000000..e5547cb9 --- /dev/null +++ b/doc/index.html @@ -0,0 +1,211 @@ + + + + + JSDoc: Home + + + + + + + + + + +
+ +

Home

+ + + + + + + + +

+ + + + + + + + + + + + + + + +
+

Smartcar Node SDK Build Status npm version

+

The official Smartcar Node SDK.

+

Overview

+

The Smartcar API lets you read vehicle data +(location, odometer) and send commands to vehicles (lock, unlock) using HTTP requests.

+

To make requests to a vehicle from a web or mobile application, the end user +must connect their vehicle using +Smartcar Connect. +This flow follows the OAuth spec and will return a code which can be used to +obtain an access token from Smartcar.

+

The Smartcar Node SDK provides methods to:

+
    +
  1. Generate the link to redirect to Connect.
  2. +
  3. Make a request to Smartcar with the code obtained from Connect to obtain an +access and refresh token
  4. +
  5. Make requests to the Smartcar API to read vehicle data and send commands to +vehicles using the access token obtained in step 2.
  6. +
+

Before integrating with Smartcar's SDK, you'll need to register an application +in the Smartcar Developer portal. If you do +not have access to the dashboard, please +request access.

+

Flow

+
    +
  • Create a new AuthClient object with your clientId, clientSecret, +redirectUri.
  • +
  • Redirect the user to Smartcar Connect using getAuthUrl with required scope or with one +of our frontend SDKs.
  • +
  • The user will login, and then accept or deny your scope's permissions.
  • +
  • Handle the get request to redirectUri. +
      +
    • If the user accepted your permissions, req.query.code will contain an +authorization code. +
        +
      • Use exchangeCode with this code to obtain an access object +containing an access token (lasting 2 hours) and a refresh token +(lasting 60 days). +
          +
        • Save this access object.
        • +
        +
      • +
      • If the user denied your permissions, req.query.error will be set +to "access_denied".
      • +
      • If you passed a state parameter to getAuthUrl, req.query.state will +contain the state value.
      • +
      +
    • +
    +
  • +
  • Get the user's vehicles with getVehicles.
  • +
  • Create a new Vehicle object using a vehicleId from the previous response, +and the access_token.
  • +
  • Make requests to the Smartcar API.
  • +
  • Use exchangeRefreshToken on your saved refreshToken to retrieve a new token +when your accessToken expires.
  • +
+

Installation

+
npm install smartcar --save
+
+

Example

+
'use strict';
+
+const smartcar = require('smartcar');
+const express = require('express');
+
+const app = express();
+
+const port = 4000;
+
+const client = new smartcar.AuthClient({
+  clientId: '<Smartcar Client Id>', // fallback to SMARTCAR_CLIENT_ID ENV variable
+  clientSecret: '<Smartcar Client Secret>', // fallback to SMARTCAR_CLIENT_SECRET ENV variable
+  redirectUri: '<Your callback URI>', // fallback to SMARTCAR_REDIRECT_URI ENV variable
+  mode: 'test', // launch Smartcar Connect in test mode
+});
+
+// Redirect to Smartcar Connect
+app.get('/login', function(req, res) {
+  const link = client.getAuthUrl(['read_vehicle_info']);
+
+  // redirect to the link
+  res.redirect(link);
+});
+
+// Handle Smartcar callback with auth code
+app.get('/callback', async function(req, res, next) {
+  let access;
+
+  if (req.query.error) {
+    // the user denied your requested permissions
+    return next(new Error(req.query.error));
+  }
+
+  // exchange auth code for access token
+  const tokens = await client.exchangeCode(req.query.code);
+  // get the user's vehicles
+  const vehicles = await smartcar.getVehicles(tokens.accessToken);
+  // instantiate first vehicle in vehicle list
+  const vehicle = new smartcar.Vehicle(
+    vehicles.vehicles[0],
+    tokens.accessToken
+  );
+  // get identifying information about a vehicle
+  const attributes = await vehicle.attributes();
+  console.log(attributes);
+  // {
+  //   "id": "36ab27d0-fd9d-4455-823a-ce30af709ffc",
+  //   "make": "TESLA",
+  //   "model": "Model S",
+  //   "year": 2014
+  //   "meta": {
+  //     "requestId": "ada7207c-3c0a-4027-a47f-6215ce6f7b93"
+  //   }
+  // }
+});
+
+app.listen(port, () => console.log(`Listening on port ${port}`));
+
+

SDK Reference

+

For detailed documentation on parameters and available methods, please refer to +the SDK Reference.

+

Contributing

+

To contribute, please:

+
    +
  1. Open an issue for the feature (or bug) you would like to resolve.
  2. +
  3. Resolve the issue and add tests in your feature branch.
  4. +
  5. Open a PR from your feature branch into develop that tags the issue.
  6. +
+

To test:

+
npm run test
+
+

Note: In order to run tests locally the following environment variables would have to be set :

+
    +
  • E2E_SMARTCAR_CLIENT_ID - Client ID to be used.
  • +
  • E2E_SMARTCAR_CLIENT_SECRET - Client secret to be used.
  • +
  • E2E_SMARTCAR_AMT - AMT from dashboard for webhooks tests.
  • +
  • E2E_SMARTCAR_WEBHOOK_ID - Webhook ID use in the webhook tests success case.
  • +
  • BROWSER - Web browser for tests (chrome or firefox, default: firefox).
  • +
+

Your application needs to have https://example.com/auth set as a valid redirect URI

+

Supported Node.js Versions

+

Smartcar aims to support the SDK on all Node.js versions that have a status of "Maintenance" or "Active LTS" as defined in the Node.js Release schedule.

+

In accordance with the Semantic Versioning specification, the addition of support for new Node.js versions would result in a MINOR version bump and the removal of support for Node.js versions would result in a MAJOR version bump.

+
+ + + + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/index.js.html b/doc/index.js.html new file mode 100644 index 00000000..d4a572fd --- /dev/null +++ b/doc/index.js.html @@ -0,0 +1,418 @@ + + + + + JSDoc: Source: index.js + + + + + + + + + + +
+ +

Source: index.js

+ + + + + + +
+
+
/* eslint-disable max-len */
+/* eslint-disable camelcase */
+'use strict';
+
+const _ = require('lodash');
+const crypto = require('crypto');
+
+const {emitWarning} = require('process');
+const SmartcarService = require('./lib/smartcar-service');
+const util = require('./lib/util');
+const config = require('./lib/config.json');
+
+/* eslint-disable global-require */
+/** @exports smartcar */
+const smartcar = {
+  /** @see {@link module:errors} */
+  SmartcarError: require('./lib/smartcar-error'),
+  /** @see {@link Vehicle} */
+  Vehicle: require('./lib/vehicle'),
+  /** @see {@link AuthClient}*/
+  AuthClient: require('./lib/auth-client'),
+};
+/* eslint-enable global-require */
+
+const buildQueryParams = function(vin, scope, country, options) {
+  const parameters = {
+    vin,
+    scope: scope.join(' '),
+    country,
+  };
+  if (options.flags) {
+    parameters.flags = util.getFlagsString(options.flags);
+  }
+  if (options.hasOwnProperty('testMode')) {
+    emitWarning(
+      // eslint-disable-next-line max-len
+      'The "testMode" parameter is deprecated, please use the "mode" parameter instead.',
+    );
+    parameters.mode = options.testMode === true ? 'test' : 'live';
+  } else if (options.hasOwnProperty('mode')) {
+    parameters.mode = options.mode;
+    if (!['test', 'live', 'simulated'].includes(parameters.mode)) {
+      throw new Error( // eslint-disable-next-line max-len
+        "The \"mode\" parameter MUST be one of the following: 'test', 'live', 'simulated'",
+      );
+    }
+  }
+  if (options.testModeCompatibilityLevel) {
+    // eslint-disable-next-line camelcase
+    parameters.test_mode_compatibility_level =
+      options.testModeCompatibilityLevel;
+    parameters.mode = 'test';
+  }
+
+  return parameters;
+};
+
+/**
+ * Sets the version of Smartcar API you are using
+ * @method
+ * @param {String} version
+ */
+smartcar.setApiVersion = function(version) {
+  config.version = version;
+};
+
+/**
+ * Gets the version of Smartcar API that is set
+ * @method
+ * @return {String} version
+ */
+smartcar.getApiVersion = () => config.version;
+
+/**
+ * @type {Object}
+ * @typedef User
+ * @property {String} id - User Id
+ * @property {module:smartcar.Vehicle.Meta} meta
+ *
+ * @example
+ * {
+ *   id: "e0514ef4-5226-11e8-8c13-8f6e8f02e27e",
+ *   meta: {
+ *     requestId: 'b9593682-8515-4f36-8190-bb56cde4c38a',
+ *   }
+ * }
+ */
+
+/**
+ * Return the user's id.
+ *
+ * @method
+ * @param {String} accessToken - access token
+ * @return {module:smartcar~User}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+smartcar.getUser = async function(accessToken) {
+  const response = await new SmartcarService({
+    baseUrl: util.getConfig('SMARTCAR_API_ORIGIN') || config.api,
+    auth: {bearer: accessToken},
+  }).request('get', `/v${config.version}/user`);
+  return response;
+};
+
+/**
+ * @type {Object}
+ * @typedef VehicleIds
+ * @property {String[]} vehicles - A list of the user's authorized vehicle ids.
+ * @property {Object} paging
+ * @property {Number} paging.count- The total number of vehicles.
+ * @property {Number} paging.offset - The current start index of returned
+ * vehicle ids.
+ * @property {module:smartcar.Vehicle.Meta} meta
+ *
+ * @example
+ * {
+ *   vehicles: [
+ *     '36ab27d0-fd9d-4455-823a-ce30af709ffc',
+ *     '770bdda4-2429-4b20-87fd-6af475c4365e',
+ *   ],
+ *   paging: {
+ *     count: 2,
+ *     offset: 0,
+ *   },
+ *   meta: {
+ *     requestId: 'b9593682-8515-4f36-8190-bb56cde4c38a',
+ *   }
+ * }
+ */
+
+/**
+ * Return list of the user's vehicles ids.
+ *
+ * @method
+ * @param {String} accessToken - access token
+ * @param {Object} [paging]
+ * @param {Number} [paging.limit] - number of vehicles to return
+ * @param {Number} [paging.offset] - index to start vehicle list
+ * @return {module:smartcar~VehicleIds}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+smartcar.getVehicles = async function(accessToken, paging = {}) {
+  const response = await new SmartcarService({
+    baseUrl: util.getUrl(),
+    auth: {bearer: accessToken},
+    qs: paging,
+  }).request('get', '');
+  return response;
+};
+
+/**
+ * @type {Object}
+ * @typedef Compatibility
+ * @property {Boolean} compatible
+ * @property {(VEHICLE_NOT_COMPATIBLE|MAKE_NOT_COMPATIBLE|null)} reason
+ * @property {Array.<String>} capabilities
+ * @property {String} capabilities[].permission
+ * @property {String} capabilities[].endpoint
+ * @property {Boolean} capabilities[].capable
+ * @property {(VEHICLE_NOT_COMPATIBLE|MAKE_NOT_COMPATIBLE|null)} capabilities[].reason
+ * @property {module:smartcar.Vehicle.Meta} meta
+ *
+ * @example
+ * {
+ *  compatible: true,
+ *  reason: null,
+ *  capabilities: [
+ *    {
+ *      capable: false,
+ *      endpoint: '/engine/oil',
+ *      permission: 'read_engine_oil',
+ *      reason: 'SMARTCAR_NOT_CAPABLE',
+ *    },
+ *    {
+ *      capable: true,
+ *      endpoint: '/vin',
+ *      permission: 'read_vin',
+ *      reason: null,
+ *    },
+ *  ],
+ *  meta: {
+ *    'requestId':'6d4226e7-a7dd-44e0-b29c-9eed26be249d'
+ *  }
+ * }
+ */
+
+/**
+ * Determine whether a vehicle is compatible with Smartcar.
+ *
+ * A compatible vehicle is a vehicle that:
+ * 1. has the hardware required for internet connectivity,
+ * 2. belongs to the makes and models Smartcar supports, and
+ * 3. supports the permissions.
+ *
+ * _To use this function, please contact us!_
+ *
+ * @param {String} vin - the VIN of the vehicle
+ * @param {String[]} scope - list of permissions to check compatibility for
+ * @param {String} [country='US'] - an optional country code according to [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).
+ * @param {Object} [options]
+ * @param {Boolean} [options.testMode] - Deprecated, please use `mode` instead.
+ * Launch Smartcar Connect in [test mode](https://smartcar.com/docs/guides/testing/).
+ * @param {String} [options.mode] - Determine what mode Smartcar Connect should be
+ * launched in. Should be one of test, live or simulated.
+ * @param {String} [options.testModeCompatibilityLevel] - This string determines which permissions
+ * the simulated vehicle is capable of. Possible Values can be found at this link:
+ * (https://smartcar.com/docs/integration-guide/test-your-integration/test-requests/#test-successful-api-requests-with-specific-vins)
+ * @return {module:smartcar~Compatibility}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+smartcar.getCompatibility = async function(vin, scope, country, options = {}) {
+  country = country || 'US';
+  const clientId =
+    options.clientId || util.getOrThrowConfig('SMARTCAR_CLIENT_ID');
+  const clientSecret =
+    options.clientSecret || util.getOrThrowConfig('SMARTCAR_CLIENT_SECRET');
+
+  const response = await new SmartcarService({
+    baseUrl: util.getConfig('SMARTCAR_API_ORIGIN') || config.api,
+    auth: {
+      user: clientId,
+      pass: clientSecret,
+    },
+    qs: buildQueryParams(vin, scope, country, options),
+  }).request('get', `v${options.version || config.version}/compatibility`);
+  return response;
+};
+
+/**
+ * Generate hash challenege for webhooks. It does HMAC_SHA256(amt, challenge)
+ *
+ * @method
+ * @param {String} amt - Application Management Token
+ * @param {String} challenge - Challenge string
+ * @return {String}  String representing the hex digest
+ */
+smartcar.hashChallenge = function(amt, challenge) {
+  const hmac = crypto.createHmac('sha256', amt);
+  return hmac.update(challenge).digest('hex');
+};
+
+/**
+ * Verify webhook payload with AMT and signature.
+ *
+ * @method
+ * @param {String} amt - Application Management Token
+ * @param {String} signature - sc-signature header value
+ * @param {object} body - webhook response body
+ * @return {Boolean} true if signature matches the hex digest of amt and body
+ */
+smartcar.verifyPayload = (amt, signature, body) =>
+  smartcar.hashChallenge(amt, JSON.stringify(body)) === signature;
+
+/**
+ * Returns a paged list of all the vehicles that are connected to the application associated
+ * with the management API token used sorted in descending order by connection date.
+ *
+ * @type {Object}
+ * @typedef Connection
+ * @property {String} vehicleId
+ * @property {String} userId
+ * @property {String} connectedAt
+ *
+ * @type {Object}
+ * @typedef GetConnections
+ * @property {Connection[]} connections
+ * @property {Object} [paging]
+ * @property {string} [paging.cursor]
+ *
+ * @param {String} amt - Application Management Token
+ * @param {object} filter
+ * @param {String} filter.userId
+ * @param {String} filter.vehicleId
+ * @param {object} paging
+ * @param {number} paging.limit
+ * @param {String} paging.cursor
+ * @returns {GetConnections}
+ */
+smartcar.getConnections = async function(amt, filter = {}, paging = {}) {
+  const {userId, vehicleId} = _.pick(filter, ['userId', 'vehicleId']);
+  const {limit, cursor} = _.pick(paging, ['limit', 'cursor']);
+
+  const qs = {};
+  if (userId) {
+    qs.user_id = userId;
+  }
+  if (vehicleId) {
+    qs.vehicle_id = vehicleId;
+  }
+  if (limit) {
+    qs.limit = limit;
+  }
+  // istanbul ignore next
+  if (cursor) {
+    qs.cursor = cursor;
+  }
+
+  const response = await new SmartcarService({
+    // eslint-disable-next-line max-len
+    baseUrl:
+      `${util.getConfig('SMARTCAR_MANAGEMENT_API_ORIGIN') || config.management}/v${config.version}`,
+    auth: {
+      user: 'default',
+      pass: amt,
+    },
+    qs,
+  }).request('get', '/management/connections');
+
+  return response;
+};
+
+/**
+ * Deletes all the connections by vehicle or user ID and returns a
+ * list of all connections that were deleted.
+ *
+ * @type {Object}
+ * @typedef Connection
+ * @property {String} vehicleId
+ * @property {String} userId
+ *
+ * @type {Object}
+ * @typedef DeleteConnections
+ * @property {Connection[]} connections
+ *
+ * @param {String} amt - Application Management Token
+ * @param {object} filter
+ * @param {String} filter.userId
+ * @param {String} filter.vehicleId
+ * @returns {DeleteConnections}
+ */
+smartcar.deleteConnections = async function(amt, filter) {
+  const {userId, vehicleId} = _.pick(filter, ['userId', 'vehicleId']);
+  if (userId && vehicleId) {
+    // eslint-disable-next-line max-len
+    throw new Error(
+      'Filter can contain EITHER user_id OR vehicle_id, not both',
+    );
+  }
+
+  const qs = {};
+  if (userId) {
+    qs.user_id = userId;
+  }
+  if (vehicleId) {
+    qs.vehicle_id = vehicleId;
+  }
+
+  const response = await new SmartcarService({
+    baseUrl:
+      `${util.getConfig('SMARTCAR_MANAGEMENT_API_ORIGIN') || config.management}/v${config.version}`,
+    auth: {
+      user: 'default',
+      pass: amt,
+    },
+    qs,
+  }).request('delete', '/management/connections');
+
+  return response;
+};
+
+module.exports = smartcar;
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/lib_auth-client.js.html b/doc/lib_auth-client.js.html new file mode 100644 index 00000000..109e447c --- /dev/null +++ b/doc/lib_auth-client.js.html @@ -0,0 +1,299 @@ + + + + + JSDoc: Source: lib/auth-client.js + + + + + + + + + + +
+ +

Source: lib/auth-client.js

+ + + + + + +
+
+
'use strict';
+
+const {emitWarning} = require('process');
+const qs = require('querystring');
+const SmartcarService = require('./smartcar-service');
+const util = require('./util');
+const config = require('./config.json');
+
+/** @exports AuthClient*/
+
+/**
+ * @type {Object}
+ * @typedef Access
+ * @property {Date} expiration - Date object which represents when the access
+ * token expires.
+ * @property {String} accessToken - A token to be used for requests to the
+ * Smartcar API
+ * @property {String} refreshToken - A token which is used to renew access when
+ * the current access token expires, expires in 60 days
+ * @property {Date} refreshExpiration - Date object which represents when the
+ * refresh token expires.
+ * @example
+ * {
+ *   expiration: new Date('2017-05-26T01:21:27.070Z'),
+ *   accessToken: '88704225-9f6c-4919-93e7-e0cec71317ce',
+ *   refreshToken: '60a9e801-6d26-4d88-926e-5c7f9fc13486',
+ *   refreshExpiration: new Date('2017-05-26T01:21:27.070Z'),
+ * }
+ */
+
+/**
+ * Create a Smartcar OAuth client for your application.
+ *
+ * @constructor
+ * @param {Object} options
+ * @param {String} options.clientId - Application client id obtained from
+ * [Smartcar Developer Portal](https://developer.smartcar.com). If you do not
+ * have access to the dashboard, please
+ * [request access](https://smartcar.com/subscribe).
+ * @param {String} options.clientSecret - The application's client secret.
+ * @param {String} options.redirectUri - Redirect URI registered in the
+ * [application settings](https://developer.smartcar.com/apps). The given URL
+ * must exactly match one of the registered URLs.
+ * @param {Boolean} [options.testMode=false] - Deprecated, please use `mode` instead.
+ * Launch Smartcar Connect in [test mode](https://smartcar.com/docs/guides/testing/).
+ * @param {String} [options.mode='live'] - Determine what mode Smartcar Connect should be
+ * launched in. Should be one of test, live or simulated.
+ */
+function AuthClient(options = {}) {
+  this.clientId =
+    options.clientId || util.getOrThrowConfig('SMARTCAR_CLIENT_ID');
+  this.clientSecret =
+    options.clientSecret || util.getOrThrowConfig('SMARTCAR_CLIENT_SECRET');
+  this.redirectUri =
+    options.redirectUri || util.getOrThrowConfig('SMARTCAR_REDIRECT_URI');
+
+  this.mode = 'live';
+  if (options.hasOwnProperty('testMode')) {
+    emitWarning(// eslint-disable-next-line max-len
+      'The "testMode" parameter is deprecated, please use the "mode" parameter instead.',
+    );
+    this.mode = options.testMode === true ? 'test' : 'live';
+  } else if (options.hasOwnProperty('mode')) {
+    this.mode = options.mode;
+  }
+  if (!['test', 'live', 'simulated'].includes(this.mode)) {
+    throw new Error(// eslint-disable-next-line max-len
+      'The "mode" parameter MUST be one of the following: \'test\', \'live\', \'simulated\'',
+    );
+  }
+  this.authUrl = util.getConfig('SMARTCAR_AUTH_ORIGIN') || config.auth;
+
+  this.service = new SmartcarService({
+    baseUrl: this.authUrl,
+    auth: {
+      user: this.clientId,
+      pass: this.clientSecret,
+    },
+  });
+}
+
+/**
+ * Generate the Smartcar Connect URL.
+ *
+ * By default users are not shown the permission dialog if they have already
+ * approved the set of scopes for this application. The application can elect
+ * to always display the permissions dialog to the user by setting
+ * approval_prompt to `force`.
+ * @param {String[]} [scope] - List of permissions your application
+ * requires. The valid permission names are found in the [API Reference](https://smartcar.com/docs/guides/scope/)
+ * @param {Object} [options]
+ * @param {Boolean} [options.forcePrompt] - Setting `forcePrompt` to
+ * `true` will show the permissions approval screen on every authentication
+ * attempt, even if the user has previously consented to the exact scope of
+ * permissions.
+ * @param {Boolean|Object} [options.singleSelect] - An optional value that sets the
+ * behavior of the grant dialog displayed to the user. Object can contain two keys :
+ *  - enabled - Boolean value, if set to `true`, `single_select` limits the user to
+ *    selecting only one vehicle.
+ *  - vin - String vin, if set, Smartcar will only authorize the vehicle with the specified VIN.
+ * See the [Single Select guide](https://smartcar.com/docs/guides/single-select/) for more information.
+ * @param {String} [options.state] - OAuth state parameter passed to the
+ * redirect uri. This parameter may be used for identifying the user who
+ * initiated the request.
+ * @param {Object} [options.makeBypass] - An optional parameter that allows
+ * users to bypass the car brand selection screen.
+ * For a complete list of supported makes, please see our
+ * [API Reference](https://smartcar.com/docs/api#authorization) documentation.
+ * @param {Object} [options.flags] - Object of flags where key is the name of the flag
+ * value is string or boolean value.
+ * @param {String} [options.user] - An optional unique identifier for a vehicle owner.
+ * This identifier is used to aggregate analytics across Connect sessions for each vehicle owner.
+ *
+ * @return {String} Smartcar Connect URL to direct user to.
+ * @example
+ * https://connect.smartcar.com/oauth/authorize?
+ * response_type=code
+ * &client_id=8229df9f-91a0-4ff0-a1ae-a1f38ee24d07
+ * &scope=read_odometer read_vehicle_info
+ * &redirect_uri=https://example.com/home
+ * &state=0facda3319
+ * &make=TESLA
+ * &single_select=true
+ * &single_select_vin=5YJSA1E14FF101307
+ * &flags=country:DE color:00819D
+ * &user=61a3e3d2-5198-47ba-aabd-4623ce4a4042
+ */
+AuthClient.prototype.getAuthUrl = function(scope, options = {}) {
+  /* eslint-disable camelcase */
+  const parameters = {
+    response_type: 'code',
+    client_id: this.clientId,
+    redirect_uri: this.redirectUri,
+    approval_prompt: options.forcePrompt === true ? 'force' : 'auto',
+  };
+  /* eslint-enable camelcase */
+
+  parameters.scope = scope.join(' ');
+
+  if (options.state) {
+    parameters.state = options.state;
+  }
+
+  if (options.singleSelect) {
+    /* eslint-disable camelcase */
+    if (options.singleSelect.vin) {
+      parameters.single_select = true;
+      parameters.single_select_vin = options.singleSelect.vin;
+    } else if ([true, false].includes(options.singleSelect.enabled)) {
+      parameters.single_select = options.singleSelect.enabled;
+    }
+    /* eslint-enable camelcase */
+  }
+
+  if (options.makeBypass) {
+    parameters.make = options.makeBypass;
+  }
+
+  if (options.flags) {
+    parameters.flags = util.getFlagsString(options.flags);
+  }
+
+  if (options.user) {
+    parameters.user = options.user;
+  }
+
+  parameters.mode = this.mode;
+
+  const query = qs.stringify(parameters);
+
+  return `${
+    util.getConfig('SMARTCAR_API_ORIGIN') || config.connect
+  }/oauth/authorize?${query}`;
+};
+
+/**
+ * Exchange an authorization code for an access object.
+ *
+ * @param {String} code - Authorization code to exchange for a Smartcar
+ * access token and refresh token.
+ * @param {Object} [options.flags] - Object of flags where key is the name of the flag
+ * value is string or boolean value.
+ * @return {Access} New set of Access and Refresh tokens.
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ * See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ * for all possible errors.
+ */
+AuthClient.prototype.exchangeCode = async function(code, options = {}) {
+  const qs = {};
+  if (options.flags) {
+    qs.flags = util.getFlagsString(options.flags);
+  }
+
+  /* eslint-disable camelcase */
+  const form = {
+    code,
+    grant_type: 'authorization_code',
+    redirect_uri: this.redirectUri,
+  };
+  /* eslint-enable camelcase */
+
+  const response = await this.service.request(
+    'post',
+    '/oauth/token',
+    {form},
+    {qs},
+  );
+  return util.formatAccess(response);
+};
+
+/**
+ * Exchange a refresh token for a new access object.
+ *
+ * @param {String} token - Refresh token to exchange for a new set of Access and
+ * Refresh tokens.
+ * @param {Object} [options.flags] - Object of flags where key is the name of the flag
+ * value is string or boolean value.
+ * @return {Access} New set of Access and Refresh tokens.
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ * See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ * for all possible errors.
+ */
+AuthClient.prototype.exchangeRefreshToken = async function(
+  token,
+  options = {},
+) {
+  const qs = {};
+  if (options.flags) {
+    qs.flags = util.getFlagsString(options.flags);
+  }
+
+  /* eslint-disable camelcase */
+  const form = {
+    grant_type: 'refresh_token',
+    refresh_token: token,
+  };
+  /* eslint-enable camelcase */
+
+  const response = await this.service.request(
+    'post',
+    '/oauth/token',
+    {form},
+    {qs},
+  );
+  return util.formatAccess(response);
+};
+
+module.exports = AuthClient;
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/lib_smartcar-error.js.html b/doc/lib_smartcar-error.js.html new file mode 100644 index 00000000..ed03f757 --- /dev/null +++ b/doc/lib_smartcar-error.js.html @@ -0,0 +1,179 @@ + + + + + JSDoc: Source: lib/smartcar-error.js + + + + + + + + + + +
+ +

Source: lib/smartcar-error.js

+ + + + + + +
+
+
'use strict';
+
+/** @exports SmartcarError */
+
+/**
+ * Class to handle all errors from Smartcar API
+ * Please see our [error guides]{@link https://smartcar.com/docs} to see a list
+ * of all the possible error types and codes of both v2.0 and v1.0 requests.
+ * */
+class SmartcarError extends Error {
+
+  /**
+   * @param {number} status - response status
+   * @param {object} body - response body
+   * @param {object} headers - response headers
+   */
+  constructor(status, body, headers) {
+    const fields = [
+      'type', 'code', 'description', 'docURL', 'detail', 'suggestedUserMessage',
+    ];
+    if (body.error) {
+      body.type = body.error;
+    }
+
+    if (!body.description) {
+      // `error_description` is for handling oauth.
+      if (body.error_description) {
+        body.description = body.error_description;
+      } else if (body.message) {
+        body.description = body.message;
+      } else if (typeof body !== 'string') {
+        body.description = 'Unknown error';
+      }
+    }
+
+    if (typeof body === 'string') {
+      super(body);
+    } else {
+      super(`${body.type}:${body.code} - ${body.description}`);
+    }
+
+    if (headers['retry-after']) {
+      this.retryAfter = headers['retry-after'];
+    }
+
+    this.statusCode = status;
+    this.requestId = body.requestId || headers['sc-request-id'];
+    if (typeof body.resolution === 'string') {
+      this.resolution = {
+        type: body.resolution,
+      };
+    } else if (body.resolution !== null
+        && typeof body.resolution === 'object') {
+      this.resolution = body.resolution;
+    }
+
+    // Now dynamically set the remaining ones if passed
+    fields.forEach((item) => {
+      if (body[item]) {
+        this[item] = body[item];
+      }
+    });
+
+    this.name = 'SmartcarError';
+  }
+}
+
+/**
+ * Legacy field from V1 error depicting a category/type/description
+ * of the error.
+ * @var {string} SmartcarError.error
+ */
+
+/**
+ * Error message field inherited from StandardError
+ * @var {string} SmartcarError.message
+ */
+
+/**
+ * Description of meaning of the error.
+ * @var {string} SmartcarError.description
+ */
+
+/**
+ * Type of error
+ * @var {string} SmartcarError.type
+ */
+
+/**
+ * Error code
+ * @var {string} SmartcarError.code
+ */
+
+/**
+ * HTTP status code
+ * @var {number} SmartcarError.statusCode
+ */
+
+/**
+ * Unique identifier for request
+ * @var {string} SmartcarError.requestId
+ */
+
+/**
+ * @type {Object}
+ * @typedef SmartcarError.Resolution
+ * @property {String} type - Possible hint to fixing the issue
+ * @property {String} url - A URL to help resolve the issue or resume the operation
+ */
+
+/**
+ * Possible resolution for fixing the error
+ * @var {SmartcarError.Resolution} SmartcarError.resolution
+ */
+
+/**
+ * Reference to Smartcar documentation
+ * @var {string} SmartcarError.docURL
+ */
+
+/**
+ * Further detail about the error in form of array of objects
+ * @memberof SmartcarError
+ *
+ * @var {object[]} SmartcarError.details
+ */
+
+module.exports = SmartcarError;
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/lib_smartcar-service.js.html b/doc/lib_smartcar-service.js.html new file mode 100644 index 00000000..8be3df78 --- /dev/null +++ b/doc/lib_smartcar-service.js.html @@ -0,0 +1,184 @@ + + + + + JSDoc: Source: lib/smartcar-service.js + + + + + + + + + + +
+ +

Source: lib/smartcar-service.js

+ + + + + + +
+
+

+'use strict';
+
+const _ = require('lodash');
+const requestPromise = require('request-promise');
+const config = require('./config.json');
+const util = require('./util');
+const HEADER_TO_META_KEYS = {
+  'sc-data-age': 'dataAge',
+  'sc-unit-system': 'unitSystem',
+  'sc-request-id': 'requestId',
+};
+
+
+const buildMeta = (headers) => {
+  const lowerCaseHeaders = _.mapKeys(
+    headers,
+    (_, key) => key.toLocaleLowerCase(),
+  );
+  const meta = {};
+  Object.entries(HEADER_TO_META_KEYS).forEach(([headerName, key]) => {
+    if (lowerCaseHeaders[headerName]) {
+      meta[key] = lowerCaseHeaders[headerName];
+    }
+  });
+  if (meta.dataAge) {
+    meta.dataAge = new Date(meta.dataAge);
+  }
+
+  return meta;
+};
+
+const getNameFromPath = (path) => {
+  // Using this constant for edge cases.
+  // '/' should have a method name of 'attributes'
+  // '/tires/pressure' should be tirePressure and NOT tiresPressure
+  const BATCH_PATH_TO_ATTRIBUTE = {
+    '/security': 'lockStatus',
+    '/tires/pressure': 'tirePressure',
+    '/': 'attributes',
+  };
+  if (BATCH_PATH_TO_ATTRIBUTE[path]) {
+    return BATCH_PATH_TO_ATTRIBUTE[path];
+  }
+
+  // For everything else camelCase method from lodash works
+  // Examples: '/battery/capacity', '/engine/oil', '/odometer', '/tesla/speedometer'
+  // converts to 'batteryCapacity', 'engineOil', 'odometer', 'teslaSpeedometer'
+  return _.camelCase(path);
+};
+const buildBatchResponse = (body, headers) => {
+  const batchResponse = {};
+  body.responses.forEach((response) => {
+    const attributeName = getNameFromPath(response.path);
+    if ([200, 204].includes(response.code)) {
+      batchResponse[attributeName] = () => {
+        return {
+          ...(response.body || {}),
+          meta: buildMeta({
+            ...headers,
+            ...response.headers,
+          }),
+        };
+      };
+    } else {
+      batchResponse[attributeName] = () => {
+        util.handleError({
+          statusCode: response.code,
+          response: {
+            body: response.body,
+            headers: {
+              ...headers,
+              ...response.headers,
+            },
+          },
+        });
+      };
+    }
+  });
+  return batchResponse;
+};
+/**
+ * Initializes a new Service object to make requests to the Smartcar API.
+ *
+ * @constructor
+ * @param {Object} [options]
+ * @param {String} [options.baseUrl] - Host/Base URL for the requests
+ * @param {Object} [options.auth] - authorization options
+ * @param {Object} [options.headers] - headers to add
+ */
+function SmartcarService(options = {}) {
+  const defaultOptions = {
+    json: true,
+    headers: {
+      'User-Agent': util.USER_AGENT,
+    },
+    timeout: config.timeout,
+  };
+  this.requestObject = requestPromise.defaults(
+    _.merge(defaultOptions, options),
+  );
+}
+
+SmartcarService.prototype.request = async function(
+  type,
+  path,
+  body = {},
+  options = {},
+) {
+  body.resolveWithFullResponse = true;
+  const response = await util.wrap(
+    this.requestObject.defaults(options)[type](path, body),
+  );
+
+  return {
+    ...(response.body || {}),
+    meta: buildMeta(response.headers),
+  };
+};
+
+SmartcarService.prototype.batchRequest = async function(paths) {
+  const requests = paths.map((path) => ({path}));
+  const response = await util.wrap(
+    this.requestObject.post('batch', {
+      body: {requests},
+      resolveWithFullResponse: true,
+    }),
+  );
+
+  return buildBatchResponse(response.body, response.headers);
+};
+
+module.exports = SmartcarService;
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/lib_util.js.html b/doc/lib_util.js.html new file mode 100644 index 00000000..619a1c4d --- /dev/null +++ b/doc/lib_util.js.html @@ -0,0 +1,180 @@ + + + + + JSDoc: Source: lib/util.js + + + + + + + + + + +
+ +

Source: lib/util.js

+ + + + + + +
+
+
'use strict';
+
+const _ = require('lodash');
+const {format} = require('util');
+const {StatusCodeError} = require('request-promise/errors');
+
+const config = require('./config.json');
+const SmartcarError = require('./smartcar-error');
+const {version} = require('../package.json');
+const {env} = require('process');
+
+const util = {};
+
+util.USER_AGENT = format(
+  'Smartcar/%s (%s; %s) Node.js %s',
+  version,
+  process.platform,
+  process.arch,
+  process.version,
+);
+
+/**
+ * Format Access object and set expiration properties.
+ *
+ * @param {Access} access access object
+ * @return {Access}
+ */
+util.formatAccess = function(access) {
+  const expiresIn = access.expires_in * 1000; // normalize to ms
+  const expiration = new Date(Date.now() + expiresIn);
+  const dayMs = 24 * 60 * 60 * 1000;
+  const refreshExpiration = new Date(Date.now() + (60 * dayMs));
+  return {
+    accessToken: access.access_token,
+    refreshToken: access.refresh_token,
+    expiration,
+    refreshExpiration,
+  };
+};
+
+/**
+ * Form an API request URI.
+ *
+ * @param {String} id vehicle identifier
+ * @param {String} endpoint API endpoint
+ * @return {String} API request URI
+ */
+util.getUrl = function(id, endpoint, version = config.version) {
+  const origin = util.getConfig('SMARTCAR_API_ORIGIN') || config.api;
+  let url = `${origin}/v${version}/vehicles`;
+
+  if (id) {
+    url += `/${id}`;
+  }
+
+  if (endpoint) {
+    url += `/${endpoint}`;
+  }
+
+  return url;
+};
+
+util.wrap = function(promise) {
+  return promise.catch(StatusCodeError, util.handleError);
+};
+
+util.getOrThrowConfig = function(configName) {
+  if (env[configName]) {
+    return env[configName];
+  }
+
+  throw new Error(
+    `${configName} not set or passed as arguments`,
+  );
+};
+
+util.getConfig = function(configName) {
+  return env[configName];
+};
+
+util.getFlagsString = function(flags) {
+  return Object.entries(flags)
+    .map(([key, value]) => `${key}:${value}`).join(' ');
+};
+
+util.handleError = function(caught) {
+  const body = _.get(caught, 'response.body', '');
+  const headers = _.get(caught, 'response.headers', {});
+
+  const contentType = String(headers['content-type']);
+  if (!contentType.toLowerCase().includes('application/json')) {
+    // body would be a string in this case
+    throw new SmartcarError(caught.statusCode, body, headers);
+  }
+
+  if (typeof body === 'string') {
+    throw new SmartcarError(
+      caught.statusCode,
+      {message: body, type: 'SDK_ERROR'},
+      headers,
+    );
+  }
+
+  if (body.error || body.type) {
+    throw new SmartcarError(caught.statusCode, body, headers);
+  } else {
+    throw new SmartcarError(
+      caught.statusCode,
+      {body, type: 'SDK_ERROR'},
+      headers,
+    );
+  }
+};
+
+/**
+ *
+ * Generate the token for vehicle management APIs using the amt.
+ *
+ * @method
+ * @param {String} amt - Application Management Token
+ * @param {String} username
+ * @return {String} managementToken
+ */
+util.getManagementToken = function(amt, username = 'default') {
+  const credentials = `${username}:${amt}`;
+  return Buffer.from(credentials).toString('base64');
+};
+
+module.exports = util;
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/lib_vehicle.js.html b/doc/lib_vehicle.js.html new file mode 100644 index 00000000..2e862ba3 --- /dev/null +++ b/doc/lib_vehicle.js.html @@ -0,0 +1,1014 @@ + + + + + JSDoc: Source: lib/vehicle.js + + + + + + + + + + +
+ +

Source: lib/vehicle.js

+ + + + + + +
+
+
'use strict';
+
+const util = require('./util');
+const _ = require('lodash');
+
+const SmartcarService = require('./smartcar-service');
+const config = require('./config.json');
+
+/**
+ * @const {object<String, Object>} - Every key here is the function name on vehicle
+ * This map is used to generate the methods dynamically. Every value is an object of
+ * the following fields :
+ * - requestType: http request type, defaults to 'get' if not mentioned.
+ * - path: url path to hit, defaults to the method name
+ * - body: body for post requests.
+ */
+const METHODS_MAP = {
+  vin: {},
+  charge: {},
+  battery: {},
+  batteryCapacity: {path: 'battery/capacity'},
+  fuel: {},
+  tirePressure: {path: 'tires/pressure'},
+  engineOil: {path: 'engine/oil'},
+  odometer: {},
+  location: {},
+  attributes: {path: '/'},
+  permissions: {},
+  lock: {requestType: 'post', path: 'security', body: {action: 'LOCK'}},
+  unlock: {requestType: 'post', path: 'security', body: {action: 'UNLOCK'}},
+  startCharge: {requestType: 'post', path: 'charge', body: {action: 'START'}},
+  stopCharge: {requestType: 'post', path: 'charge', body: {action: 'STOP'}},
+  disconnect: {requestType: 'delete', path: 'application'},
+  lockStatus: {path: 'security'},
+  sendDestination: {path: 'navigation/destination'},
+  serviceHistory: {path: 'service/history'},
+};
+
+/** @exports Vehicle */
+/**
+ * Initializes a new Vehicle to use for making requests to the Smartcar API.
+ *
+ * @constructor
+ * @param {String} id - The vehicle's unique identifier. Retrieve a user's
+ * vehicle id using {@link module:smartcar.getVehicles}.
+ * @param {String} token - A valid access token
+ * @param {Object} [options]
+ * @param {String} [options.unitSystem=metric] - The unit system to use for vehicle data
+ * must be either `metric` or `imperial`.
+ * @param {Object} [options.version] - API version to use
+ * @param {Object} [options.flags] - Object of flags where key is the name of the flag
+ * and value is string or boolean value.
+ */
+function Vehicle(id, token, options = {}) {
+  this.id = id;
+  this.token = token;
+  this.unitSystem = options.unitSystem || 'metric';
+  this.version = options.version || config.version;
+  this.query = {};
+  if (options.flags) {
+    this.query.flags = util.getFlagsString(options.flags);
+  }
+
+
+  this.service = new SmartcarService({
+    baseUrl: util.getUrl(this.id, '', this.version),
+    auth: {
+      bearer: this.token,
+    },
+    headers: {
+      'sc-unit-system': this.unitSystem,
+    },
+    qs: this.query,
+  });
+}
+
+/* NOTES :
+  - We only generate the methods where there is no parameter for calling the method thats
+    the majority. For all the ones that require parameters, write them separately.
+    Ex. permissions, subscribe, unsubscribe
+  - The following snippet generates methods dynamically , but if we are adding a new item,
+    make sure we also add the JSDOC for it. These are at the end of the file in a section.
+*/
+
+_.forEach(METHODS_MAP, (attributes, methodName) => {
+  Vehicle.prototype[methodName] = async function() {
+    const bodyObject = {};
+    if (attributes.body) {
+      bodyObject.body = attributes.body;
+    }
+    const response = await this.service.request(
+      attributes.requestType || 'get',
+      attributes.path || methodName,
+      bodyObject,
+    );
+    return response;
+  };
+});
+
+/**
+ * @type {Object}
+ * @typedef Permissions
+ * @property {String[]} permissions - An array of permissions names.
+ * @property {Object} [paging]
+ * @property {Number} [paging.count] - The total number of elements for the entire query
+ * (not just the given page).
+ * @property {Number} [options.offset] - The current start index of the returned list of elements.
+ * @property {Meta} meta
+ *
+ * @example
+ * {
+ *   permissions: ['read_vehicle_info'],
+ *   paging: {
+ *      count: 25,
+ *      offset: 10
+ *   },
+ *   meta: {
+ *    requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+ *   }
+ * }
+ */
+
+/**
+ * Fetch the list of permissions that this application has been granted
+ *
+ * @method
+ * @param {Object} [paging]
+ * @param {String} [paging.limit] - number of permissions to return
+ * @param {Object} [options.offset] - The current start index of the returned list of elements.
+ * @returns {Permissions}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+Vehicle.prototype.permissions = async function(paging = {}) {
+  const response = await this.service.request(
+    'get',
+    'permissions',
+    {},
+    {qs: paging},
+  );
+  return response;
+};
+
+
+/**
+ * @type {Object}
+ * @typedef ServiceHistory
+ * @property {Number|null} serviceID - The unique identifier for the service record,
+ * or null if not available.
+ * @property {String} serviceDate - The date and time the service was performed.
+ * @property {Number} odometerDistance - The odometer reading at the time of service,
+ * in miles or kilometers based on the unit system.
+ * @property {Array.<ServiceTask>} serviceTasks - A list of tasks performed during the service.
+ * @property {ServiceDetails} serviceDetails - Details about the service
+ * provider and the type of service.
+ * @property {ServiceCost} serviceCost - The cost of the service with currency.
+ * @property {Meta} meta - Metadata related to the service record.
+ *
+ * @example
+ * [
+ *   {
+ *     serviceId: 12345,
+ *     serviceDate: "2022-07-10T16:20:00.000Z",
+ *     odometerDistance: 50000,
+ *     serviceTasks: [
+ *       {
+ *         taskId: 01,
+ *         taskDescription: "oil change"
+ *       }
+ *     ],
+ *     serviceDetails: {
+ *       type: "dealership"  // "manual_entry" could be another possible value
+ *     },
+ *     serviceCost: {
+ *       totalCost: 100,
+ *       currency: 'USD'
+ *     },
+ *     meta: {
+ *       dataAge: new Date('2023-04-30T07:20:50.844Z'),
+ *       unitSystem: 'imperial',
+ *       requestId: 'b3c14915-0c26-43c5-8e42-9edfc2a66b2f'
+ *     }
+ *   }
+ *   // ... additional service records
+ * ]
+ */
+
+/**
+ * @name Vehicle#serviceHistory
+ * @function
+ * @memberof Vehicle
+ * @description Returns a list of all the service records performed on the vehicle,
+ * filtered by the optional date range. If no dates are specified, records from the
+ * last year are returned.
+ * @param {String} [startDate] - The start date for the record filter, either in 'YYYY-MM-DD' or
+ * 'YYYY-MM-DDTHH:MM:SS.SSSZ' format.
+ * @param {String} [endDate] - The end date for the record filter, similar format to startDate.
+ * @see {@link https://smartcar.com/docs/api#get-vehicle-service-history|Smartcar API Doc - Vehicle Service History}
+ * @return {Array.<ServiceHistory>}
+ * @throws {SmartcarError} - an instance of SmartcarError. See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors) for all possible errors.
+ */
+Vehicle.prototype.serviceHistory = async function(startDate, endDate) {
+  const response = await this.service.request(
+    'get',
+    'service/request',
+    {},
+    {qs: {
+      startDate,
+      endDate,
+    }},
+  );
+  return response;
+};
+
+/**
+ * @typedef ChargeLimit
+ * @property {number} limit - the charge limit expressed as a decimal value between 0 and 1.
+ */
+
+/**
+ * Fetch the charge limit for an electric vehicle
+ *
+ * @method
+ * @returns {ChargeLimit}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ *
+ * @example
+ * {
+ *   limit: .7,
+ *   meta: {
+ *    requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+ *   }
+ * }
+ */
+
+Vehicle.prototype.getChargeLimit = async function() {
+  const response = await this.service.request(
+    'get',
+    'charge/limit',
+  );
+
+  return response;
+};
+
+/**
+ * Set the charge limit for an electric vehicle.
+ *
+ * @method
+ * @param {number} limit - a number between 0 and 1
+ * @returns {ChargeLimit}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ *
+ * @example
+ * {
+ *   status: string,
+ *   meta: {
+ *    requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+ *   }
+ * }
+ */
+Vehicle.prototype.setChargeLimit = async function(limit) {
+
+  const body = {
+    limit: String(limit),
+  };
+
+  const response = await this.service.request(
+    'post',
+    'charge/limit',
+    {body},
+  );
+
+  return response;
+};
+
+/**
+ * Send a destination to the vehicle's navigation system.
+ *
+ * @method
+ * @param {number} latitude - Latitude of the destination. Must be a valid latitude
+ *                            value between -90 and 90 (inclusive).
+ * @param {number} longitude - Longitude of the destination. Must be a valid longitude
+ *                             value between -180 and 180 (inclusive).
+ * @returns {ActionResponse} - A Response object containing the status and metadata.
+ * @throws {SmartcarError} - An instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ *
+ * @example
+ * {
+ *   status: string,
+ *   meta: {
+ *     requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+ *   }
+ * }
+ */
+Vehicle.prototype.sendDestination = async function(latitude, longitude) {
+  // Validate the latitude and longitude values
+  if (latitude < -90 || latitude > 90) {
+    throw new Error('Invalid latitude value. It must be between -90 and 90.');
+  }
+  if (longitude < -180 || longitude > 180) {
+    throw new Error(
+      'Invalid longitude value. It must be between -180 and 180.',
+    );
+  }
+
+  const body = {
+    latitude: Number(latitude),
+    longitude: Number(longitude),
+  };
+
+  const response = await this.service.request(
+    'post',
+    'navigation/destination',
+    {body},
+  );
+
+  return response;
+};
+
+
+/**
+ * @type {Object}
+ * @typedef WebhookSubscription
+ * @property {String} webhookId - Webhook Id that the vehicle was subscribed to
+ * @property {String} vehicleId - Current vehicle id that was subscribed to the webhook
+ * @property {Meta} meta
+ *
+ * @example
+ * {
+ *   webhookId: 'dd214915-0c26-13c5-8e42-7edfc2ab320a',
+ *   vehicleId: '19c0cc8c-80e0-4182-9372-6ef903c7599c',
+ *   meta: {
+ *    requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+ *   }
+ * }
+ */
+/**
+ * Subscribe the vehicle to given webhook Id
+ *
+ * @method
+ * @param {String} webhookId - Webhook Id to subscribe to.
+ * @return {Object}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+Vehicle.prototype.subscribe = async function(webhookId) {
+  const response = await this.service.request('post', `webhooks/${webhookId}`);
+  return response;
+};
+
+/**
+ * Unsubscribe  the vehicle from given webhook Id
+ *
+ * @method
+ * @param {String} amt - Application management token to be used as authorization
+ * @param {String} webhookId - Webhook Id to unsubscribe from.
+ * @return {Meta}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+Vehicle.prototype.unsubscribe = async function(amt, webhookId) {
+  const response = await this.service.request(
+    'delete',
+    `webhooks/${webhookId}`,
+    {},
+    {auth: {bearer: amt}},
+  );
+  return response;
+};
+
+
+/**
+ * @type {Object}
+ * @typedef Batch
+ * @property { function(): Object} ENDPOINT - The response object for a given ENDPOINT where
+ * ENDPOINT is a Smartcar endpoint (i.e. /odometer, /fuel) or throws SmartcarError
+ * if the endpoint resulted in an error.
+ *
+ * @example
+ * {
+ *    "odometer" : function() => returns odometer object or throws SmartcarError,
+ *    "location" : function() => returns odometer location or throws SmartcarError,
+ * }
+ */
+
+/**
+ * Make batch requests for supported items
+ * @see {@link https://smartcar.com/docs/api#post-batch-request|Smartcar API Doc - Batch Request}
+ * @param {String[]} paths - A list of paths of endpoints to send requests to.
+ * @return {Batch}
+ *
+ * @throws {SmartcarError} - on unsuccessful request. An instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+Vehicle.prototype.batch = async function(paths) {
+  const response = await this.service.batchRequest(paths);
+  return response;
+};
+
+/**
+ * @type {Object}
+ * @typedef Response
+ * @property {String} body - The response body
+ * @property {Meta} meta
+ *
+ * @example
+ * {
+ *  body: { distance: 59801.6373441601 },
+ *  meta: {
+ *    dataAge: 2022-01-20T02:55:25.041Z,
+ *    unitSystem: 'imperial',
+ *    requestId: 'f787849d-d228-482d-345f-459a5154sg73'
+ *  }
+ * }
+ */
+/**
+ * General purpose method to make a request to a Smartcar endpoint.
+ *
+ * @method
+ * @param {String} method - The HTTP request method to use.
+ * @param {String} path - The path to make the request to.
+ * @param {Object} body - The request body.
+ * @param {Object} headers - The headers to include in the request.
+ * @return {Response}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+Vehicle.prototype.request = async function(
+  method,
+  path,
+  body = {},
+  headers = {},
+) {
+  const options = {
+    baseUrl: util.getUrl(this.id, '', this.version),
+    headers: _.merge({'sc-unit-system': this.unitSystem}, headers),
+  };
+
+  if (!headers.Authorization) {
+    options.auth = {bearer: this.token};
+  }
+
+  const rawResponse = await new SmartcarService(options).request(
+    method.toLowerCase(),
+    path,
+    {body},
+  );
+
+  const response = {
+    body: _.omit(rawResponse, 'meta'),
+    meta: rawResponse.meta,
+  };
+
+  return response;
+};
+
+
+/* JSDOC for dynamically generated methods */
+/**
+ * @type {Object}
+ * @typedef Meta
+ * @property {Date} dataAge - The timestamp of when the data was recorded; returned if applicable.
+ * @property {String} requestId - The smartcar request ID for debugging
+ * @property {String} unitSystem - Unit system used, metric or imperial; returned if applicable.
+ *
+ * @example
+ * {
+ *   requestId: 'b9593682-8515-4f36-8190-bb56cde4c38a',
+ *   dataAge: new Date('2018-05-04T07:20:50.844Z'),
+ *   unitSystem: 'imperial',
+ * }
+ */
+
+/**
+ * @type {Object}
+ * @typedef Vin
+ * @property {String} vin - VIN of the vehicle
+ * @property {Meta} meta
+ *
+ * @example
+ * {
+ *   vin: '12345678901234567',
+ *   meta: {
+ *     requestId: 'b9593682-8515-4f36-8190-bb56cde4c38a',
+ *   }
+ * }
+ */
+/**
+ * @name Vehicle#vin
+ * @function
+ * @memberof Vehicle
+ * @description  Returns the vehicle's manufacturer identifier (VIN).
+ * @see {@link https://smartcar.com/docs/api#get-vin|Smartcar API Doc - VIN}
+ * @return {Vin}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+
+
+/**
+ * @type {Object}
+ * @typedef Charge
+ * @property {Boolean} isPluggedIn - Indicates whether charging cable is
+ *   plugged in.
+ * @property {String} state - Indicates the current state of the charge
+ *   system. Can be `FULLY_CHARGED`, `CHARGING`, or `NOT_CHARGING`.
+ * @property {Meta} meta
+ *
+ * @example
+ * {
+ *   isPluggedIn: false,
+ *   state: "FULLY_CHARGED",
+ *   meta: {
+ *     dataAge: new Date('2018-05-04T07:20:50.844Z'),
+ *   }
+ * }
+ */
+/**
+ * @name Vehicle#charge
+ * @function
+ * @memberof Vehicle
+ * @description  Returns the current charge status of the vehicle.
+ * @see {@link https://smartcar.com/docs/api#get-ev-charging-status|Smartcar API Doc - EV charging status}
+ * @return {Charge}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+
+/**
+ * @type {Object}
+ * @typedef Battery
+ * @property {Number} range - The estimated remaining distance the car can
+ *  travel (in kms or miles). Unit is passed as a parameter in vehicle constructor.
+ * @property {Number} percentRemaining - The remaining level of charge in
+ *   the battery (in percent).
+ * @property {Meta} meta
+ *
+ * @example
+ * {
+ *   range: 40.5,
+ *   percentRemaining: 0.3,
+ *   meta: {
+ *    dataAge: new Date('2018-05-04T07:20:50.844Z'),
+ *    unitSystem: 'imperial',
+ *    requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+ *   }
+ * }
+ */
+/**
+ * @name Vehicle#battery
+ * @function
+ * @memberof Vehicle
+ * @description  Returns the state of charge (SOC) and remaining range of an electric or
+ * plug-in hybrid vehicle's battery.
+ * @see {@link https://smartcar.com/docs/api#get-ev-battery|Smartcar API Doc - EV battery level}
+ * @return {Battery}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+
+/**
+ * @type {Object}
+ * @typedef BatteryCapacity
+ * @property {Number} capacity - The total capacity of the vehicle's battery
+ * (in kilowatt-hours)
+ * @property {Meta} meta
+ *
+ * @example
+ * {
+ *   capacity: 24,
+ *   meta: {
+ *    dataAge: new Date('2018-05-04T07:20:50.844Z'),
+ *    unitSystem: 'imperial',
+ *    requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+ *   }
+ * }
+ */
+/**
+ * @name Vehicle#batteryCapacity
+ * @function
+ * @memberof Vehicle
+ * @description  Returns the capacity of an electric or plug-in hybrid vehicle's battery.
+ * @see {@link https://smartcar.com/docs/api#get-ev-battery-capacity|Smartcar API Doc - EV battery capacity}
+ * @return {BatteryCapacity}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+
+/**
+ * @type {Object}
+ * @typedef Fuel
+ * @property {Number} range - The estimated remaining distance the car can
+ *  travel (in kms or miles). Unit is passed as a parameter in vehicle constructor.
+ * @property {Number} percentRemaining - The remaining level of fuel in
+ *   the tank (in percent).
+ * @property {Number} amountRemaining - The amount of fuel in the tank (in
+ *  liters or gallons (US)). Unit is passed as a parameter in vehicle constructor.
+ * @property {Meta} meta
+ *
+ * @example
+ * {
+ *   range: 40.5,
+ *   percentRemaining: 0.3,
+ *   amountRemaining: 40.5,
+ *   meta: {
+ *    dataAge: new Date('2018-05-04T07:20:50.844Z'),
+ *    unitSystem: 'imperial',
+ *    requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+ *   }
+ * }
+ */
+/**
+ * @name Vehicle#fuel
+ * @function
+ * @memberof Vehicle
+ * @description  Returns the status of the fuel remaining in the vehicle's gas tank.
+ * @see {@link https://smartcar.com/docs/api#get-fuel-tank|Smartcar API Doc - Fuel tank}
+ * @return {Fuel}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+
+/**
+ * @type {Object}
+ * @typedef TirePressure
+ * @property {Number} frontLeft - The current air pressure of the front left tire
+ * @property {Number} frontRight - The current air pressure of the back right tire
+ * @property {Number} backLeft - The current air pressure of the back left tire
+ * @property {Number} backRight - The current air pressure of the back right tire
+ * @property {Meta} meta
+ *
+ * @example
+ * {
+ *   frontLeft: 33,
+ *   frontRight: 34,
+ *   backLeft: 34,
+ *   backRight: 33
+ *   meta: {
+ *    dataAge: new Date('2018-05-04T07:20:50.844Z'),
+ *    unitSystem: 'imperial',
+ *    requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+ *   }
+ * }
+ */
+/**
+ * @name Vehicle#tirePressure
+ * @function
+ * @memberof Vehicle
+ * @description  Returns the air pressure of each of the vehicle's tires.
+ * @see {@link https://smartcar.com/docs/api#get-tire-pressure|Smartcar API Doc - Tire pressure}
+ * @return {TirePressure}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+
+/**
+ * @type {Object}
+ * @typedef EngineOil
+ * @property {Number} lifeRemaining - The engine oil's remaining life span
+ * (as a percentage). Oil life is based on the current quality of the oil.
+ * @property {Meta} meta
+ *
+ * @example
+ * {
+ *   lifeRemaining: 0.86,
+ *   meta: {
+ *    dataAge: new Date('2018-05-04T07:20:50.844Z'),
+ *    unitSystem: 'imperial',
+ *    requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+ *   }
+ * }
+ */
+/**
+ * @name Vehicle#engineOil
+ * @function
+ * @memberof Vehicle
+ * @description  Returns the remaining life span of a vehicle's engine oil
+ * @see {@link https://smartcar.com/docs/api#get-engine-oil-life|Smartcar API Doc - Engine oil life}
+ * @return {EngineOil}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+
+/**
+ * @type {Object}
+ * @typedef Odometer
+ * @property {Number} distance - The reading of the vehicle's odometer (in
+ *   kms or miles). Unit is passed as a parameter in vehicle constructor.
+ * @property {Meta} meta
+ *
+ * @example
+ * {
+ *   distance: 1234.12,
+ *   meta: {
+ *    dataAge: new Date('2018-05-04T07:20:50.844Z'),
+ *    unitSystem: 'imperial',
+ *    requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+ *   }
+ * }
+ */
+
+/**
+ * @type {Object}
+ * @typedef SecurityResponse
+ * @property {Boolean} isLocked - Whether the vehicle is locked or not.
+ * @property {Array} doors - The status of each of the vehicle's doors.
+ * @property {Array} windows - The status of each of the vehicle's windows.
+ * @property {Array} sunroof - The status of each of the vehicle's sunroof.
+ * @property {Array} storage - The status of each of the vehicle's storage.
+ * @property {Array} chargingPort - The status of each of the vehicle's chargingPort.
+ * @property {Meta} meta
+ *
+ * @example
+ * {
+ *    isLocked: true,
+ *    doors: [
+ *       {
+ *           type: 'frontLeft',
+ *           status: 'LOCKED',
+ *       },
+ *       {
+ *           type: 'frontRight',
+ *           status: 'LOCKED',
+ *       },
+ *       {
+ *           type: 'backLeft',
+ *           status: 'LOCKED',
+ *       },
+ *       {
+ *           type: 'backRight',
+ *           status: 'LOCKED',
+ *       },
+ *    ],
+ *    windows: [
+ *       {
+ *           type: 'frontLeft',
+ *           status: 'CLOSED',
+ *       },
+ *       {
+ *           type: 'frontRight',
+ *           status: 'CLOSED',
+ *       },
+ *       {
+ *           type: 'backLeft',
+ *           status: 'CLOSED',
+ *       },
+ *       {
+ *           type: 'backRight',
+ *           status: 'CLOSED',
+ *       },
+ *    ],
+ *    sunroof: [
+ *       {
+ *           type: 'sunroof',
+ *           status: 'CLOSED',
+ *       },
+ *    ],
+ *    storage: [
+ *       {
+ *           type: 'rear',
+ *           status: 'CLOSED',
+ *       },
+ *       {
+ *           type: 'front',
+ *           status: 'CLOSED',
+ *       },
+ *    ],
+ *    chargingPort: [
+ *       {
+ *           type: 'chargingPort',
+ *           status: 'CLOSED',
+ *       },
+ *    ],
+ *    meta: {
+ *        dataAge: new Date('2018-05-04T07:20:50.844Z'),
+ *        requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+ *    },
+ * }
+ */
+
+/**
+ * @name Vehicle#odometer
+ * @function
+ * @memberof Vehicle
+ * @description Returns the vehicle's last known odometer reading.
+ * @see {@link https://smartcar.com/docs/api#get-odometer|Smartcar API Doc - Odometer}
+ * @return {Odometer}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+
+/**
+ * @type {Object}
+ * @typedef Location
+ * @property {Number} latitude - The vehicle latitude (in degrees).
+ * @property {Number} longitude - The vehicle longitude (in degrees).
+ * @property {Meta} meta
+ *
+ * @example
+ * {
+ *   latitude: 37.400880,
+ *   longitude: -122.057804,
+ *   meta: {
+ *    dataAge: new Date('2018-05-04T07:20:50.844Z'),
+ *    unitSystem: 'imperial',
+ *    requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+ *   }
+ * }
+ */
+/**
+ * @name Vehicle#location
+ * @function
+ * @memberof Vehicle
+ * @description Returns the last known location of the vehicle in geographic coordinates.
+ * @see {@link https://smartcar.com/docs/api#get-location|Smartcar API Doc - Location}
+ * @return {Location}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+
+/**
+ * @type {Object}
+ * @typedef Attributes
+ * @property {String} id - The vehicle's unique Smartcar identifier.
+ * @property {String} make - The brand of the vehicle.
+ * @property {String} model - The specific model of the vehicle.
+ * @property {Number} year - The model year of the vehicle.
+ * @property {Meta} meta
+ *
+ * @example
+ * {
+ *   id: '19c0cc8c-80e0-4182-9372-6ef903c7599c',
+ *   make: 'TESLA',
+ *   model: 'S',
+ *   year: 2017,
+ *   meta: {
+ *    requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+ *   }
+ * }
+ */
+/**
+ * @name Vehicle#attributes
+ * @function
+ * @memberof Vehicle
+ * @description Returns make model year and id of the vehicle
+ * @see {@link https://smartcar.com/docs/api#get-vehicle-attributes|Smartcar API Doc - Vehicle attributes}
+ * @return {Attributes}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+
+/**
+ * @type {Object}
+ * @typedef ActionResponse
+ * @property {String} status - set to `success` on successful request
+ * @property {Meta} meta
+ *
+ * @example
+ * {
+ *   status: 'success',
+ *   meta: {
+ *    requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
+ *   }
+ * }
+ */
+
+/**
+ * @name Vehicle#lock
+ * @function
+ * @memberof Vehicle
+ * @description Attempts to lock the vehicle.
+ * @see {@link https://smartcar.com/docs/api#post-lockunlock|Smartcar API Doc - Lock}
+ * @return {ActionResponse}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+
+/**
+ * @name Vehicle#unlock
+ * @function
+ * @memberof Vehicle
+ * @description Attempts to lock the vehicle.
+ * @see {@link https://smartcar.com/docs/api#post-lockunlock|Smartcar API Doc - Unlock}
+ * @return {ActionResponse}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+
+/**
+ * @name Vehicle#startCharge
+ * @function
+ * @memberof Vehicle
+ * @description Attempts to start charging the vehicle.
+ * @see {@link https://smartcar.com/docs/api#post-ev-startstop-charge|Smartcar API Doc - EV start charge}
+ * @return {ActionResponse}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+
+/**
+ * @name Vehicle#stopCharge
+ * @function
+ * @memberof Vehicle
+ * @description Attempts to stop charging the vehicle.
+ * @see {@link https://smartcar.com/docs/api#post-ev-startstop-charge|Smartcar API Doc - EV stop charge}
+ * @return {ActionResponse}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+
+/**
+ * @name Vehicle#disconnect
+ * @function
+ * @memberof Vehicle
+ * @description Disconnect this vehicle from the connected application.
+ * Note: Calling this method will invalidate your token's access to the vehicle.
+ * You will have to reauthorize the user to your application again if you wish
+ * to make requests to it again.
+ * @see {@link https://smartcar.com/docs/api#delete-disconnect|Smartcar API Doc - Disconnect}
+ * @return {ActionResponse}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+
+/**
+ * @name Vehicle#lockStatus
+ * @function
+ * @memberof Vehicle
+ * @description Returns the lock status of the vehicle.
+ * @see {@link https://smartcar.com/docs/api#get-security|Smartcar API Doc - Lock Status}
+ * @return {LockStatus}
+ * @throws {SmartcarError} - an instance of SmartcarError.
+ *   See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
+ *   for all possible errors.
+ */
+
+module.exports = Vehicle;
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/module-smartcar.html b/doc/module-smartcar.html new file mode 100644 index 00000000..5a9ae25c --- /dev/null +++ b/doc/module-smartcar.html @@ -0,0 +1,3098 @@ + + + + + JSDoc: Module: smartcar + + + + + + + + + + +
+ +

Module: smartcar

+ + + + + + +
+ +
+ + + +
+ +
+
+ + + + + +
+ + + + + + + + + + + + + + +

Members

+ + + +

(static) AuthClient

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + +

(static) SmartcarError

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+
    +
  • module:errors
  • +
+
+ + + +
+ + + + + + + + +

(static) Vehicle

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + +

Methods

+ + + + + + + +

(static) getApiVersion() → {String}

+ + + + + + +
+

Gets the version of Smartcar API that is set

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + +
+

version

+
+ + + +
+
+ Type +
+
+ +String + + +
+
+ + + + + + + + + + + + + +

(static) getCompatibility(vin, scope, countryopt, optionsopt) → {module:smartcar~Compatibility}

+ + + + + + +
+

Determine whether a vehicle is compatible with Smartcar.

+

A compatible vehicle is a vehicle that:

+
    +
  1. has the hardware required for internet connectivity,
  2. +
  3. belongs to the makes and models Smartcar supports, and
  4. +
  5. supports the permissions.
  6. +
+

To use this function, please contact us!

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
vin + + +String + + + + + + + + + + + +

the VIN of the vehicle

scope + + +Array.<String> + + + + + + + + + + + +

list of permissions to check compatibility for

country + + +String + + + + + + <optional>
+ + + + + +
+ + 'US' + +

an optional country code according to ISO 3166-1 alpha-2.

options + + +Object + + + + + + <optional>
+ + + + + +
+ + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
testMode + + +Boolean + + + + + + <optional>
+ + + + + +

Deprecated, please use mode instead. +Launch Smartcar Connect in test mode.

mode + + +String + + + + + + <optional>
+ + + + + +

Determine what mode Smartcar Connect should be +launched in. Should be one of test, live or simulated.

testModeCompatibilityLevel + + +String + + + + + + <optional>
+ + + + + +

This string determines which permissions +the simulated vehicle is capable of. Possible Values can be found at this link: +(https://smartcar.com/docs/integration-guide/test-your-integration/test-requests/#test-successful-api-requests-with-specific-vins)

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +module:smartcar~Compatibility + + +
+
+ + + + + + + + + + + + + +

(static) getUser(accessToken) → {module:smartcar~User}

+ + + + + + +
+

Return the user's id.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
accessToken + + +String + + + +

access token

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +module:smartcar~User + + +
+
+ + + + + + + + + + + + + +

(static) getVehicles(accessToken, pagingopt) → {module:smartcar~VehicleIds}

+ + + + + + +
+

Return list of the user's vehicles ids.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
accessToken + + +String + + + + + + + + + +

access token

paging + + +Object + + + + + + <optional>
+ + + + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
limit + + +Number + + + + + + <optional>
+ + + + + +

number of vehicles to return

offset + + +Number + + + + + + <optional>
+ + + + + +

index to start vehicle list

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+
    +
  • an instance of SmartcarError. +See the errors section +for all possible errors.
  • +
+
+
+
+
+
+
+ Type +
+
+ +SmartcarError + + +
+
+
+
+
+ + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +module:smartcar~VehicleIds + + +
+
+ + + + + + + + + + + + + +

(static) hashChallenge(amt, challenge) → {String}

+ + + + + + +
+

Generate hash challenege for webhooks. It does HMAC_SHA256(amt, challenge)

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amt + + +String + + + +

Application Management Token

challenge + + +String + + + +

Challenge string

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + +
+

String representing the hex digest

+
+ + + +
+
+ Type +
+
+ +String + + +
+
+ + + + + + + + + + + + + +

(static) setApiVersion(version)

+ + + + + + +
+

Sets the version of Smartcar API you are using

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
version + + +String + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

(static) verifyPayload(amt, signature, body) → {Boolean}

+ + + + + + +
+

Verify webhook payload with AMT and signature.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
amt + + +String + + + +

Application Management Token

signature + + +String + + + +

sc-signature header value

body + + +object + + + +

webhook response body

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + +
+

true if signature matches the hex digest of amt and body

+
+ + + +
+
+ Type +
+
+ +Boolean + + +
+
+ + + + + + + + + + + +

Type Definitions

+ + + +

Compatibility

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
compatible + + +Boolean + + + +
reason + + +VEHICLE_NOT_COMPATIBLE +| + +MAKE_NOT_COMPATIBLE +| + +null + + + +
capabilities + + +Array.<String> + + + +
capabilities[].permission + + +String + + + +
capabilities[].endpoint + + +String + + + +
capabilities[].capable + + +Boolean + + + +
capabilities[].reason + + +VEHICLE_NOT_COMPATIBLE +| + +MAKE_NOT_COMPATIBLE +| + +null + + + +
meta + + +module:smartcar.Vehicle.Meta + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + +
Example
+ +
{
+ compatible: true,
+ reason: null,
+ capabilities: [
+   {
+     capable: false,
+     endpoint: '/engine/oil',
+     permission: 'read_engine_oil',
+     reason: 'SMARTCAR_NOT_CAPABLE',
+   },
+   {
+     capable: true,
+     endpoint: '/vin',
+     permission: 'read_vin',
+     reason: null,
+   },
+ ],
+ meta: {
+   'requestId':'6d4226e7-a7dd-44e0-b29c-9eed26be249d'
+ }
+}
+ + + + + +

DeleteConnections

+ + + + +
+

Deletes all the connections by vehicle or user ID and returns a +list of all connections that were deleted.

+
+ + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
vehicleId + + +String + + + +
userId + + +String + + + +
connections + + +Array.<Connection> + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

GetConnections

+ + + + +
+

Returns a paged list of all the vehicles that are connected to the application associated +with the management API token used sorted in descending order by connection date.

+
+ + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
vehicleId + + +String + + + + + + + +
userId + + +String + + + + + + + +
connectedAt + + +String + + + + + + + +
connections + + +Array.<Connection> + + + + + + + +
paging + + +Object + + + + + + <optional>
+ + + +
+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
cursor + + +string + + + + + + <optional>
+ + + +
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

User

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + +

User Id

meta + + +module:smartcar.Vehicle.Meta + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + +
Example
+ +
{
+  id: "e0514ef4-5226-11e8-8c13-8f6e8f02e27e",
+  meta: {
+    requestId: 'b9593682-8515-4f36-8190-bb56cde4c38a',
+  }
+}
+ + + + + +

VehicleIds

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
vehicles + + +Array.<String> + + + +

A list of the user's authorized vehicle ids.

paging + + +Object + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
count- + + +Number + + + +

The total number of vehicles.

offset + + +Number + + + +

The current start index of returned +vehicle ids.

+ +
meta + + +module:smartcar.Vehicle.Meta + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + +
Example
+ +
{
+  vehicles: [
+    '36ab27d0-fd9d-4455-823a-ce30af709ffc',
+    '770bdda4-2429-4b20-87fd-6af475c4365e',
+  ],
+  paging: {
+    count: 2,
+    offset: 0,
+  },
+  meta: {
+    requestId: 'b9593682-8515-4f36-8190-bb56cde4c38a',
+  }
+}
+ + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/readme.md b/doc/readme.md index 08acbcac..9635c25c 100644 --- a/doc/readme.md +++ b/doc/readme.md @@ -48,6 +48,8 @@ the following fields :

Permissions : Object
+
ServiceHistory : Object
+
ChargeLimit
WebhookSubscription : Object
@@ -609,6 +611,7 @@ Initializes a new Service object to make requests to the Smartcar API. * [Vehicle](#Vehicle) * [new Vehicle(id, token, [options])](#new_Vehicle_new) * [.permissions([paging])](#Vehicle+permissions) ⇒ [Permissions](#Permissions) + * [.serviceHistory([startDate], [endDate])](#Vehicle+serviceHistory) ⇒ [Array.<ServiceHistory>](#ServiceHistory) * [.getChargeLimit()](#Vehicle+getChargeLimit) ⇒ [ChargeLimit](#ChargeLimit) * [.setChargeLimit(limit)](#Vehicle+setChargeLimit) ⇒ [ChargeLimit](#ChargeLimit) * [.sendDestination(latitude, longitude)](#Vehicle+sendDestination) ⇒ [ActionResponse](#ActionResponse) @@ -667,6 +670,25 @@ Fetch the list of permissions that this application has been granted | [paging.limit] | String | number of permissions to return | | [options.offset] | Object | The current start index of the returned list of elements. | + + +### vehicle.serviceHistory([startDate], [endDate]) ⇒ [Array.<ServiceHistory>](#ServiceHistory) +Returns a list of all the service records performed on the vehicle, +filtered by the optional date range. If no dates are specified, records from the +last year are returned. + +**Kind**: instance method of [Vehicle](#Vehicle) +**Throws**: + +- [SmartcarError](#SmartcarError) - an instance of SmartcarError. See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors) for all possible errors. + +**See**: [Smartcar API Doc - Vehicle Service History](https://smartcar.com/docs/api#get-vehicle-service-history) + +| Param | Type | Description | +| --- | --- | --- | +| [startDate] | String | The start date for the record filter, either in 'YYYY-MM-DD' or 'YYYY-MM-DDTHH:MM:SS.SSSZ' format. | +| [endDate] | String | The end date for the record filter, similar format to startDate. | + ### vehicle.getChargeLimit() ⇒ [ChargeLimit](#ChargeLimit) @@ -1087,6 +1109,51 @@ the following fields : } } ``` + + +## ServiceHistory : Object +**Kind**: global typedef +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| serviceID | Number \| null | The unique identifier for the service record, or null if not available. | +| serviceDate | String | The date and time the service was performed. | +| odometerDistance | Number | The odometer reading at the time of service, in miles or kilometers based on the unit system. | +| serviceTasks | Array.<ServiceTask> | A list of tasks performed during the service. | +| serviceDetails | ServiceDetails | Details about the service provider and the type of service. | +| serviceCost | ServiceCost | The cost of the service with currency. | +| meta | [Meta](#Meta) | Metadata related to the service record. | + +**Example** +```js +[ + { + serviceId: 12345, + serviceDate: "2022-07-10T16:20:00.000Z", + odometerDistance: 50000, + serviceTasks: [ + { + taskId: 01, + taskDescription: "oil change" + } + ], + serviceDetails: { + type: "dealership" // "manual_entry" could be another possible value + }, + serviceCost: { + totalCost: 100, + currency: 'USD' + }, + meta: { + dataAge: new Date('2023-04-30T07:20:50.844Z'), + unitSystem: 'imperial', + requestId: 'b3c14915-0c26-43c5-8e42-9edfc2a66b2f' + } + } + // ... additional service records +] +``` ## ChargeLimit diff --git a/doc/scripts/linenumber.js b/doc/scripts/linenumber.js new file mode 100644 index 00000000..4354785c --- /dev/null +++ b/doc/scripts/linenumber.js @@ -0,0 +1,25 @@ +/*global document */ +(() => { + const source = document.getElementsByClassName('prettyprint source linenums'); + let i = 0; + let lineNumber = 0; + let lineId; + let lines; + let totalLines; + let anchorHash; + + if (source && source[0]) { + anchorHash = document.location.hash.substring(1); + lines = source[0].getElementsByTagName('li'); + totalLines = lines.length; + + for (; i < totalLines; i++) { + lineNumber++; + lineId = `line${lineNumber}`; + lines[i].id = lineId; + if (lineId === anchorHash) { + lines[i].className += ' selected'; + } + } + } +})(); diff --git a/doc/scripts/prettify/Apache-License-2.0.txt b/doc/scripts/prettify/Apache-License-2.0.txt new file mode 100644 index 00000000..d6456956 --- /dev/null +++ b/doc/scripts/prettify/Apache-License-2.0.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/doc/scripts/prettify/lang-css.js b/doc/scripts/prettify/lang-css.js new file mode 100644 index 00000000..041e1f59 --- /dev/null +++ b/doc/scripts/prettify/lang-css.js @@ -0,0 +1,2 @@ +PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n "]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com", +/^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); diff --git a/doc/scripts/prettify/prettify.js b/doc/scripts/prettify/prettify.js new file mode 100644 index 00000000..eef5ad7e --- /dev/null +++ b/doc/scripts/prettify/prettify.js @@ -0,0 +1,28 @@ +var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; +(function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= +[],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), +l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, +q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, +q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, +"");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), +a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} +for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], +"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], +H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], +J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ +I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), +["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", +/^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), +["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", +hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= +!k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p th:last-child { border-right: 1px solid #ddd; } + +.ancestors, .attribs { color: #999; } +.ancestors a, .attribs a +{ + color: #999 !important; + text-decoration: none; +} + +.clear +{ + clear: both; +} + +.important +{ + font-weight: bold; + color: #950B02; +} + +.yes-def { + text-indent: -1000px; +} + +.type-signature { + color: #aaa; +} + +.name, .signature { + font-family: Consolas, Monaco, 'Andale Mono', monospace; +} + +.details { margin-top: 14px; border-left: 2px solid #DDD; } +.details dt { width: 120px; float: left; padding-left: 10px; padding-top: 6px; } +.details dd { margin-left: 70px; } +.details ul { margin: 0; } +.details ul { list-style-type: none; } +.details li { margin-left: 30px; padding-top: 6px; } +.details pre.prettyprint { margin: 0 } +.details .object-value { padding-top: 0; } + +.description { + margin-bottom: 1em; + margin-top: 1em; +} + +.code-caption +{ + font-style: italic; + font-size: 107%; + margin: 0; +} + +.source +{ + border: 1px solid #ddd; + width: 80%; + overflow: auto; +} + +.prettyprint.source { + width: inherit; +} + +.source code +{ + font-size: 100%; + line-height: 18px; + display: block; + padding: 4px 12px; + margin: 0; + background-color: #fff; + color: #4D4E53; +} + +.prettyprint code span.line +{ + display: inline-block; +} + +.prettyprint.linenums +{ + padding-left: 70px; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + +.prettyprint.linenums ol +{ + padding-left: 0; +} + +.prettyprint.linenums li +{ + border-left: 3px #ddd solid; +} + +.prettyprint.linenums li.selected, +.prettyprint.linenums li.selected * +{ + background-color: lightyellow; +} + +.prettyprint.linenums li * +{ + -webkit-user-select: text; + -moz-user-select: text; + -ms-user-select: text; + user-select: text; +} + +.params .name, .props .name, .name code { + color: #4D4E53; + font-family: Consolas, Monaco, 'Andale Mono', monospace; + font-size: 100%; +} + +.params td.description > p:first-child, +.props td.description > p:first-child +{ + margin-top: 0; + padding-top: 0; +} + +.params td.description > p:last-child, +.props td.description > p:last-child +{ + margin-bottom: 0; + padding-bottom: 0; +} + +.disabled { + color: #454545; +} diff --git a/doc/styles/prettify-jsdoc.css b/doc/styles/prettify-jsdoc.css new file mode 100644 index 00000000..5a2526e3 --- /dev/null +++ b/doc/styles/prettify-jsdoc.css @@ -0,0 +1,111 @@ +/* JSDoc prettify.js theme */ + +/* plain text */ +.pln { + color: #000000; + font-weight: normal; + font-style: normal; +} + +/* string content */ +.str { + color: #006400; + font-weight: normal; + font-style: normal; +} + +/* a keyword */ +.kwd { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* a comment */ +.com { + font-weight: normal; + font-style: italic; +} + +/* a type name */ +.typ { + color: #000000; + font-weight: normal; + font-style: normal; +} + +/* a literal value */ +.lit { + color: #006400; + font-weight: normal; + font-style: normal; +} + +/* punctuation */ +.pun { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* lisp open bracket */ +.opn { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* lisp close bracket */ +.clo { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* a markup tag name */ +.tag { + color: #006400; + font-weight: normal; + font-style: normal; +} + +/* a markup attribute name */ +.atn { + color: #006400; + font-weight: normal; + font-style: normal; +} + +/* a markup attribute value */ +.atv { + color: #006400; + font-weight: normal; + font-style: normal; +} + +/* a declaration */ +.dec { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* a variable name */ +.var { + color: #000000; + font-weight: normal; + font-style: normal; +} + +/* a function name */ +.fun { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* Specify class=linenums on a pre to get line numbering */ +ol.linenums { + margin-top: 0; + margin-bottom: 0; +} diff --git a/doc/styles/prettify-tomorrow.css b/doc/styles/prettify-tomorrow.css new file mode 100644 index 00000000..b6f92a78 --- /dev/null +++ b/doc/styles/prettify-tomorrow.css @@ -0,0 +1,132 @@ +/* Tomorrow Theme */ +/* Original theme - https://github.com/chriskempson/tomorrow-theme */ +/* Pretty printing styles. Used with prettify.js. */ +/* SPAN elements with the classes below are added by prettyprint. */ +/* plain text */ +.pln { + color: #4d4d4c; } + +@media screen { + /* string content */ + .str { + color: #718c00; } + + /* a keyword */ + .kwd { + color: #8959a8; } + + /* a comment */ + .com { + color: #8e908c; } + + /* a type name */ + .typ { + color: #4271ae; } + + /* a literal value */ + .lit { + color: #f5871f; } + + /* punctuation */ + .pun { + color: #4d4d4c; } + + /* lisp open bracket */ + .opn { + color: #4d4d4c; } + + /* lisp close bracket */ + .clo { + color: #4d4d4c; } + + /* a markup tag name */ + .tag { + color: #c82829; } + + /* a markup attribute name */ + .atn { + color: #f5871f; } + + /* a markup attribute value */ + .atv { + color: #3e999f; } + + /* a declaration */ + .dec { + color: #f5871f; } + + /* a variable name */ + .var { + color: #c82829; } + + /* a function name */ + .fun { + color: #4271ae; } } +/* Use higher contrast and text-weight for printable form. */ +@media print, projection { + .str { + color: #060; } + + .kwd { + color: #006; + font-weight: bold; } + + .com { + color: #600; + font-style: italic; } + + .typ { + color: #404; + font-weight: bold; } + + .lit { + color: #044; } + + .pun, .opn, .clo { + color: #440; } + + .tag { + color: #006; + font-weight: bold; } + + .atn { + color: #404; } + + .atv { + color: #060; } } +/* Style */ +/* +pre.prettyprint { + background: white; + font-family: Consolas, Monaco, 'Andale Mono', monospace; + font-size: 12px; + line-height: 1.5; + border: 1px solid #ccc; + padding: 10px; } +*/ + +/* Specify class=linenums on a pre to get line numbering */ +ol.linenums { + margin-top: 0; + margin-bottom: 0; } + +/* IE indents via margin-left */ +li.L0, +li.L1, +li.L2, +li.L3, +li.L4, +li.L5, +li.L6, +li.L7, +li.L8, +li.L9 { + /* */ } + +/* Alternate shading for lines */ +li.L1, +li.L3, +li.L5, +li.L7, +li.L9 { + /* */ } diff --git a/lib/smartcar-service.js b/lib/smartcar-service.js index 7e91b149..cb35988e 100644 --- a/lib/smartcar-service.js +++ b/lib/smartcar-service.js @@ -112,10 +112,17 @@ SmartcarService.prototype.request = async function( this.requestObject.defaults(options)[type](path, body), ); - return { - ...(response.body || {}), - meta: buildMeta(response.headers), - }; + if (Array.isArray(response.body)) { + return { + data: response.body, + meta: buildMeta(response.headers), + }; + } else { + return { + ...(response.body || {}), + meta: buildMeta(response.headers), + }; + } }; SmartcarService.prototype.batchRequest = async function(paths) { diff --git a/lib/vehicle.js b/lib/vehicle.js index 6e241b79..645f1102 100644 --- a/lib/vehicle.js +++ b/lib/vehicle.js @@ -33,6 +33,7 @@ const METHODS_MAP = { disconnect: {requestType: 'delete', path: 'application'}, lockStatus: {path: 'security'}, sendDestination: {path: 'navigation/destination'}, + serviceHistory: {}, }; /** @exports Vehicle */ @@ -141,6 +142,79 @@ Vehicle.prototype.permissions = async function(paging = {}) { return response; }; + +/** + * @type {Object} + * @typedef ServiceHistory + * @property {Number|null} serviceID - The unique identifier for the service record, + * or null if not available. + * @property {String} serviceDate - The date and time the service was performed. + * @property {Number} odometerDistance - The odometer reading at the time of service, + * in miles or kilometers based on the unit system. + * @property {Array.} serviceTasks - A list of tasks performed during the service. + * @property {ServiceDetails} serviceDetails - Details about the service + * provider and the type of service. + * @property {ServiceCost} serviceCost - The cost of the service with currency. + * @property {Meta} meta - Metadata related to the service record. + * + * @example + * [ + * { + * serviceId: 12345, + * serviceDate: "2022-07-10T16:20:00.000Z", + * odometerDistance: 50000, + * serviceTasks: [ + * { + * taskId: 01, + * taskDescription: "oil change" + * } + * ], + * serviceDetails: { + * type: "dealership" // "manual_entry" could be another possible value + * }, + * serviceCost: { + * totalCost: 100, + * currency: 'USD' + * }, + * meta: { + * dataAge: new Date('2023-04-30T07:20:50.844Z'), + * unitSystem: 'imperial', + * requestId: 'b3c14915-0c26-43c5-8e42-9edfc2a66b2f' + * } + * } + * // ... additional service records + * ] + */ + +/** + * @name Vehicle#serviceHistory + * @function + * @memberof Vehicle + * @description Returns a list of all the service records performed on the vehicle, + * filtered by the optional date range. If no dates are specified, records from the + * last year are returned. + * @param {String} [startDate] - The start date for the record filter, either in 'YYYY-MM-DD' or + * 'YYYY-MM-DDTHH:MM:SS.SSSZ' format. + * @param {String} [endDate] - The end date for the record filter, similar format to startDate. + * @see {@link https://smartcar.com/docs/api#get-vehicle-service-history|Smartcar API Doc - Vehicle Service History} + * @return {Array.} + * @throws {SmartcarError} - an instance of SmartcarError. See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors) for all possible errors. + */ +Vehicle.prototype.serviceHistory = async function(startDate, endDate) { + const response = await this.service.request( + 'get', + 'service/history', + {}, + {qs: { + // eslint-disable-next-line camelcase + start_date: startDate, + // eslint-disable-next-line camelcase + end_date: endDate, + }}, + ); + return response; +}; + /** * @typedef ChargeLimit * @property {number} limit - the charge limit expressed as a decimal value between 0 and 1. diff --git a/test/end-to-end/vehicle.js b/test/end-to-end/vehicle.js index 45060f81..c2255789 100644 --- a/test/end-to-end/vehicle.js +++ b/test/end-to-end/vehicle.js @@ -27,6 +27,7 @@ test.before(async(t) => { 'required:control_security', 'required:read_security', 'required:control_navigation', + 'required:read_service_history', ]), getVehicle('KIA', [ 'required:read_charge', @@ -511,6 +512,13 @@ test('vehicle request - set charge limit', async(t) => { t.is(response.status, 'success'); }); +test('vehicle request - service history', async(t) => { + const startDate = '2023-05-20'; + const endDate = '2024-02-10'; + const response = await t.context.ford.serviceHistory(startDate, endDate); + t.true(Array.isArray(response.data)); +}); + test('vehicle request - send destination', async(t) => { const latitude = 37.7749; const longitude = -122.4194;