@smartcar/auth 2.11.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -5
- package/README.mdt +5 -3
- package/dist/npm/sdk.js +40 -25
- package/doc/README.md +4 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ The [Smartcar API](https://smartcar.com/docs) lets you read vehicle data
|
|
|
9
9
|
|
|
10
10
|
To make requests to a vehicle from a web application, the end user must connect their vehicle using [Smartcar Connect](https://smartcar.com/docs/api#smartcar-connect). The Smartcar JavaScript SDK provides an easy way to launch and handle Connect to retrieve the resulting `code`.
|
|
11
11
|
|
|
12
|
-
Before integrating with the JavaScript SDK, you'll need to register an application in the [Smartcar dashboard](https://dashboard.smartcar.com). Once you have registered an application, you will have
|
|
12
|
+
Before integrating with the JavaScript SDK, you'll need to register an application in the [Smartcar dashboard](https://dashboard.smartcar.com). Once you have registered an application, you will have an Application ID, which will allow you to launch Connect and authorize users.
|
|
13
13
|
|
|
14
14
|
## Installation
|
|
15
15
|
|
|
@@ -24,7 +24,7 @@ npm install @smartcar/auth
|
|
|
24
24
|
### Smartcar CDN
|
|
25
25
|
|
|
26
26
|
```html
|
|
27
|
-
<script src="https://javascript-sdk.smartcar.com/2.
|
|
27
|
+
<script src="https://javascript-sdk.smartcar.com/2.13.0/sdk.js"></script>
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
## SDK reference
|
|
@@ -81,7 +81,7 @@ Once you have constructed your redirect URI, make sure to register it on the [Sm
|
|
|
81
81
|
|
|
82
82
|
```javascript
|
|
83
83
|
const smartcar = new Smartcar({
|
|
84
|
-
|
|
84
|
+
applicationId: '<your-application-id>',
|
|
85
85
|
redirectUri: '<your-redirect-uri>',
|
|
86
86
|
scope: ['read_vehicle_info', 'read_odometer'],
|
|
87
87
|
onComplete: function(err, code) {
|
|
@@ -94,6 +94,8 @@ const smartcar = new Smartcar({
|
|
|
94
94
|
});
|
|
95
95
|
```
|
|
96
96
|
|
|
97
|
+
`applicationId` is the preferred option name. For backward compatibility, `clientId` is also supported. You must provide one of `applicationId` or `clientId`.
|
|
98
|
+
|
|
97
99
|
**Reference:** [`new Smartcar(options)`](doc#new_Smartcar_new)
|
|
98
100
|
|
|
99
101
|
> NOTE: See the full set of available scopes for each endpoint in the [Smartcar API reference](https://smartcar.com/docs/api#permissions).
|
|
@@ -140,7 +142,7 @@ To use the JavaScript SDK for this flow, do the following:
|
|
|
140
142
|
|
|
141
143
|
```javascript
|
|
142
144
|
const smartcar = new Smartcar({
|
|
143
|
-
|
|
145
|
+
applicationId: '<your-application-id>',
|
|
144
146
|
redirectUri: '<your-backend-redirect-uri>',
|
|
145
147
|
scope: ['read_vehicle_info', 'read_odometer'],
|
|
146
148
|
onComplete: function() {},
|
|
@@ -178,4 +180,4 @@ https://application-backend.com/page?error=access_denied&error_description=User+
|
|
|
178
180
|
[tag-image]: https://img.shields.io/github/tag/smartcar/javascript-sdk.svg
|
|
179
181
|
|
|
180
182
|
<!-- Please do not modify or remove this, it is used by the build process -->
|
|
181
|
-
[version]: 2.
|
|
183
|
+
[version]: 2.13.0
|
package/README.mdt
CHANGED
|
@@ -9,7 +9,7 @@ The [Smartcar API](https://smartcar.com/docs) lets you read vehicle data
|
|
|
9
9
|
|
|
10
10
|
To make requests to a vehicle from a web application, the end user must connect their vehicle using [Smartcar Connect](https://smartcar.com/docs/api#smartcar-connect). The Smartcar JavaScript SDK provides an easy way to launch and handle Connect to retrieve the resulting `code`.
|
|
11
11
|
|
|
12
|
-
Before integrating with the JavaScript SDK, you'll need to register an application in the [Smartcar dashboard](https://dashboard.smartcar.com). Once you have registered an application, you will have
|
|
12
|
+
Before integrating with the JavaScript SDK, you'll need to register an application in the [Smartcar dashboard](https://dashboard.smartcar.com). Once you have registered an application, you will have an Application ID, which will allow you to launch Connect and authorize users.
|
|
13
13
|
|
|
14
14
|
## Installation
|
|
15
15
|
|
|
@@ -81,7 +81,7 @@ Once you have constructed your redirect URI, make sure to register it on the [Sm
|
|
|
81
81
|
|
|
82
82
|
```javascript
|
|
83
83
|
const smartcar = new Smartcar({
|
|
84
|
-
|
|
84
|
+
applicationId: '<your-application-id>',
|
|
85
85
|
redirectUri: '<your-redirect-uri>',
|
|
86
86
|
scope: ['read_vehicle_info', 'read_odometer'],
|
|
87
87
|
onComplete: function(err, code) {
|
|
@@ -94,6 +94,8 @@ const smartcar = new Smartcar({
|
|
|
94
94
|
});
|
|
95
95
|
```
|
|
96
96
|
|
|
97
|
+
`applicationId` is the preferred option name. For backward compatibility, `clientId` is also supported. You must provide one of `applicationId` or `clientId`.
|
|
98
|
+
|
|
97
99
|
**Reference:** [`new Smartcar(options)`](doc#new_Smartcar_new)
|
|
98
100
|
|
|
99
101
|
> NOTE: See the full set of available scopes for each endpoint in the [Smartcar API reference](https://smartcar.com/docs/api#permissions).
|
|
@@ -140,7 +142,7 @@ To use the JavaScript SDK for this flow, do the following:
|
|
|
140
142
|
|
|
141
143
|
```javascript
|
|
142
144
|
const smartcar = new Smartcar({
|
|
143
|
-
|
|
145
|
+
applicationId: '<your-application-id>',
|
|
144
146
|
redirectUri: '<your-backend-redirect-uri>',
|
|
145
147
|
scope: ['read_vehicle_info', 'read_odometer'],
|
|
146
148
|
onComplete: function() {},
|
package/dist/npm/sdk.js
CHANGED
|
@@ -63,6 +63,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
63
63
|
'use strict';
|
|
64
64
|
/* eslint-env node */
|
|
65
65
|
|
|
66
|
+
var hasWarnedClientIdDeprecation = false;
|
|
67
|
+
|
|
66
68
|
var Smartcar = /*#__PURE__*/function () {
|
|
67
69
|
/**
|
|
68
70
|
* @callback OnComplete
|
|
@@ -77,6 +79,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
77
79
|
* Smartcar's virtual key on a vehicle. This registration will be required in order to use
|
|
78
80
|
* any commands on a Tesla vehicle. It is an optional argument as it is only included in
|
|
79
81
|
* specific cases.
|
|
82
|
+
* @param {String} userId - A unique identifier for the vehicle owner that granted access.
|
|
80
83
|
*/
|
|
81
84
|
|
|
82
85
|
/**
|
|
@@ -84,7 +87,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
84
87
|
*
|
|
85
88
|
* @constructor
|
|
86
89
|
* @param {Object} options - the SDK configuration object
|
|
87
|
-
|
|
90
|
+
* @param {String} options.applicationId - the application's id
|
|
91
|
+
* @param {String} [options.clientId] - Deprecated alias for applicationId
|
|
88
92
|
* @param {String} options.redirectUri - the registered redirect uri of the
|
|
89
93
|
* application
|
|
90
94
|
* @param {String[]} [options.scope] - requested permission scopes
|
|
@@ -112,7 +116,15 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
112
116
|
|
|
113
117
|
Smartcar._validateConstructorOptions(options);
|
|
114
118
|
|
|
115
|
-
|
|
119
|
+
if (!options.applicationId && options.clientId && !hasWarnedClientIdDeprecation) {
|
|
120
|
+
// eslint-disable-next-line no-console
|
|
121
|
+
console.warn('The "clientId" parameter is deprecated, please use the "applicationId" parameter instead.');
|
|
122
|
+
hasWarnedClientIdDeprecation = true;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
var applicationId = options.applicationId || options.clientId;
|
|
126
|
+
this.applicationId = applicationId;
|
|
127
|
+
this.clientId = applicationId;
|
|
116
128
|
this.redirectUri = options.redirectUri;
|
|
117
129
|
this.scope = options.scope;
|
|
118
130
|
this.onComplete = options.onComplete;
|
|
@@ -137,7 +149,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
137
149
|
|
|
138
150
|
this.messageHandler = function (event) {
|
|
139
151
|
// bail if message from unexpected source
|
|
140
|
-
if (!_this.redirectUri.startsWith(event.origin)) {
|
|
152
|
+
if (_this.redirectUri && !_this.redirectUri.startsWith(event.origin)) {
|
|
141
153
|
return;
|
|
142
154
|
}
|
|
143
155
|
|
|
@@ -209,6 +221,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
209
221
|
|
|
210
222
|
var err = generateError(message.error, message.errorDescription);
|
|
211
223
|
var virtualKeyUrl = message.virtualKeyUrl;
|
|
224
|
+
var userId = message.userId;
|
|
212
225
|
/**
|
|
213
226
|
* Call `onComplete` with parameters even if developer is not using
|
|
214
227
|
* a Smartcar-hosted redirect. Regardless of if they are using a
|
|
@@ -222,7 +235,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
222
235
|
* parameters in their redirect uri.
|
|
223
236
|
*/
|
|
224
237
|
|
|
225
|
-
_this.onComplete(err, message.code, originalState, virtualKeyUrl);
|
|
238
|
+
_this.onComplete(err, message.code, originalState, virtualKeyUrl, userId);
|
|
226
239
|
}
|
|
227
240
|
}; // add handler for postMessage event on completion of Smartcar Connect
|
|
228
241
|
|
|
@@ -272,7 +285,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
272
285
|
* @example
|
|
273
286
|
* https://connect.smartcar.com/oauth/authorize?
|
|
274
287
|
* response_type=code
|
|
275
|
-
* &
|
|
288
|
+
* &application_id=8229df9f-91a0-4ff0-a1ae-a1f38ee24d07
|
|
276
289
|
* &scope=read_odometer read_vehicle_info
|
|
277
290
|
* &redirect_uri=https://example.com/home
|
|
278
291
|
* &state=0facda3319
|
|
@@ -287,12 +300,16 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
287
300
|
var link = '';
|
|
288
301
|
link += 'https://connect.smartcar.com/oauth/authorize';
|
|
289
302
|
link += "?response_type=".concat(this.responseType);
|
|
290
|
-
link += "&
|
|
291
|
-
|
|
303
|
+
link += "&application_id=".concat(this.applicationId);
|
|
304
|
+
|
|
305
|
+
if (this.redirectUri) {
|
|
306
|
+
link += "&redirect_uri=".concat(encodeURIComponent(this.redirectUri));
|
|
307
|
+
} // map forcePrompt to approvalPrompt, two options: 'force' and 'auto'
|
|
308
|
+
|
|
292
309
|
|
|
293
310
|
var forcePrompt = options.forcePrompt === true;
|
|
294
|
-
link += "&approval_prompt=".concat(forcePrompt ? 'force' : 'auto'); // If scope is not specified, Smartcar will default to requesting
|
|
295
|
-
//
|
|
311
|
+
link += "&approval_prompt=".concat(forcePrompt ? 'force' : 'auto'); // If scope is not specified, Smartcar will default to requesting the application's vehicle
|
|
312
|
+
// access configuration if available or the default set of permissions
|
|
296
313
|
|
|
297
314
|
if (this.scope) {
|
|
298
315
|
link += "&scope=".concat(encodeURIComponent(this.scope.join(' ')));
|
|
@@ -518,26 +535,24 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
518
535
|
}], [{
|
|
519
536
|
key: "_validateConstructorOptions",
|
|
520
537
|
value: function _validateConstructorOptions(options) {
|
|
521
|
-
if (!options.clientId) {
|
|
522
|
-
throw new TypeError('
|
|
538
|
+
if (!options.applicationId && !options.clientId) {
|
|
539
|
+
throw new TypeError('An applicationId option must be provided');
|
|
523
540
|
}
|
|
524
541
|
|
|
525
|
-
if (
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
if (!options.onComplete || options.onComplete.length < 2) {
|
|
533
|
-
throw new Error("When using Smartcar's CDN redirect an onComplete function with at" + ' least 2 parameters (error & code) is required to handle' + ' completion of Connect');
|
|
534
|
-
}
|
|
542
|
+
if (options.redirectUri) {
|
|
543
|
+
if (options.redirectUri.startsWith('https://javascript-sdk.smartcar.com')) {
|
|
544
|
+
// require onComplete method with at least two parameters (error & code)
|
|
545
|
+
// when hosting on Smartcar CDN
|
|
546
|
+
if (!options.onComplete || options.onComplete.length < 2) {
|
|
547
|
+
throw new Error("When using Smartcar's CDN redirect an onComplete function with at" + ' least 2 parameters (error & code) is required to handle' + ' completion of Connect');
|
|
548
|
+
}
|
|
535
549
|
|
|
536
|
-
|
|
550
|
+
var usesOldUriScheme = /redirect-[0-9]+\.[0-9]+\.[0-9]+\?/.test(options.redirectUri);
|
|
537
551
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
552
|
+
if (usesOldUriScheme) {
|
|
553
|
+
// eslint-disable-next-line no-console
|
|
554
|
+
console.warn("\nThe Smartcar redirect URI you're using is outdated! To update it, please see:\nhttps://github.com/smartcar/javascript-sdk#1-register-a-javascript-sdk-redirect-uri\n");
|
|
555
|
+
}
|
|
541
556
|
}
|
|
542
557
|
}
|
|
543
558
|
}
|
package/doc/README.md
CHANGED
|
@@ -49,7 +49,8 @@ Initializes Smartcar class.
|
|
|
49
49
|
| Param | Type | Default | Description |
|
|
50
50
|
| --- | --- | --- | --- |
|
|
51
51
|
| options | <code>Object</code> | | the SDK configuration object |
|
|
52
|
-
| options.
|
|
52
|
+
| options.applicationId | <code>String</code> | | the application's id |
|
|
53
|
+
| [options.clientId] | <code>String</code> | | Deprecated alias for applicationId |
|
|
53
54
|
| options.redirectUri | <code>String</code> | | the registered redirect uri of the application |
|
|
54
55
|
| [options.scope] | <code>Array.<String></code> | | requested permission scopes |
|
|
55
56
|
| [options.onComplete] | [<code>OnComplete</code>](#OnComplete) | | called on completion of Smartcar Connect |
|
|
@@ -78,7 +79,7 @@ Generates Smartcar OAuth URL.
|
|
|
78
79
|
```js
|
|
79
80
|
https://connect.smartcar.com/oauth/authorize?
|
|
80
81
|
response_type=code
|
|
81
|
-
&
|
|
82
|
+
&application_id=8229df9f-91a0-4ff0-a1ae-a1f38ee24d07
|
|
82
83
|
&scope=read_odometer read_vehicle_info
|
|
83
84
|
&redirect_uri=https://example.com/home
|
|
84
85
|
&state=0facda3319
|
|
@@ -206,6 +207,7 @@ Invalid subscription error returned by Connect.
|
|
|
206
207
|
| code | <code>String</code> | the authorization code to be exchanged from a backend sever for an access token |
|
|
207
208
|
| [state] | <code>Object</code> | contains state if it was set on the initial authorization request |
|
|
208
209
|
| [virtualKeyUrl] | <code>String</code> | virtual key URL used by Tesla to register Smartcar's virtual key on a vehicle. This registration will be required in order to use any commands on a Tesla vehicle. It is an optional argument as it is only included in specific cases. |
|
|
210
|
+
| userId | <code>String</code> | A unique identifier for the vehicle owner that granted access. |
|
|
209
211
|
|
|
210
212
|
<a name="WindowOptions"></a>
|
|
211
213
|
|