@smartcar/auth 2.8.0 → 2.10.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 +2 -2
- package/dist/npm/sdk.js +218 -200
- package/doc/README.md +27 -6
- package/package.json +21 -27
- package/postinstall.js +0 -29
package/README.md
CHANGED
|
@@ -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.10.0/sdk.js"></script>
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
## SDK reference
|
|
@@ -178,4 +178,4 @@ https://application-backend.com/page?error=access_denied&error_description=User+
|
|
|
178
178
|
[tag-image]: https://img.shields.io/github/tag/smartcar/javascript-sdk.svg
|
|
179
179
|
|
|
180
180
|
<!-- Please do not modify or remove this, it is used by the build process -->
|
|
181
|
-
[version]: 2.
|
|
181
|
+
[version]: 2.10.0
|
package/dist/npm/sdk.js
CHANGED
|
@@ -1,32 +1,69 @@
|
|
|
1
|
-
|
|
1
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
6
6
|
|
|
7
|
-
function
|
|
7
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
8
8
|
|
|
9
|
-
function
|
|
9
|
+
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
|
10
10
|
|
|
11
|
-
function
|
|
11
|
+
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
12
|
+
|
|
13
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
14
|
+
|
|
15
|
+
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
|
|
16
|
+
|
|
17
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
18
|
+
|
|
19
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
20
|
+
|
|
21
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
22
|
+
|
|
23
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
24
|
+
|
|
25
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
26
|
+
|
|
27
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
28
|
+
|
|
29
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
30
|
+
|
|
31
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
32
|
+
|
|
33
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
34
|
+
|
|
35
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
36
|
+
|
|
37
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
38
|
+
|
|
39
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
40
|
+
|
|
41
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
12
42
|
|
|
13
43
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
14
44
|
|
|
15
|
-
;(
|
|
45
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
46
|
+
|
|
47
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
48
|
+
|
|
49
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
50
|
+
|
|
51
|
+
;
|
|
52
|
+
|
|
53
|
+
(function (root, factory) {
|
|
16
54
|
/* istanbul ignore next */
|
|
17
55
|
if (typeof define === 'function' && define.amd) {
|
|
18
56
|
define([], factory);
|
|
19
|
-
} else if ((typeof exports ===
|
|
57
|
+
} else if ((typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object') {
|
|
20
58
|
module.exports = factory();
|
|
21
59
|
} else {
|
|
22
60
|
root.Smartcar = factory();
|
|
23
61
|
}
|
|
24
62
|
})(this, function () {
|
|
25
63
|
'use strict';
|
|
26
|
-
|
|
27
64
|
/* eslint-env node */
|
|
28
65
|
|
|
29
|
-
var Smartcar = function () {
|
|
66
|
+
var Smartcar = /*#__PURE__*/function () {
|
|
30
67
|
/**
|
|
31
68
|
* @callback OnComplete
|
|
32
69
|
* @param {?Error} error - something went wrong in Connect; this
|
|
@@ -36,6 +73,10 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
36
73
|
* backend sever for an access token
|
|
37
74
|
* @param {Object} [state] - contains state if it was set on the initial
|
|
38
75
|
* authorization request
|
|
76
|
+
* @param {String} [virtualKeyUrl] - virtual key URL used by Tesla to register
|
|
77
|
+
* Smartcar's virtual key on a vehicle. This registration will be required in order to use
|
|
78
|
+
* any commands on a Tesla vehicle. It is an optional argument as it is only included in
|
|
79
|
+
* specific cases.
|
|
39
80
|
*/
|
|
40
81
|
|
|
41
82
|
/**
|
|
@@ -48,8 +89,11 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
48
89
|
* application
|
|
49
90
|
* @param {String[]} [options.scope] - requested permission scopes
|
|
50
91
|
* @param {OnComplete} [options.onComplete] - called on completion of Smartcar Connect
|
|
51
|
-
* @param {Boolean} [options.testMode=false] -
|
|
52
|
-
|
|
92
|
+
* @param {Boolean} [options.testMode=false] - Deprecated, please use `mode` instead.
|
|
93
|
+
* Launch Smartcar Connect in [test mode](https://smartcar.com/docs/guides/testing/).
|
|
94
|
+
* @param {String} [options.mode='live'] - Determine what mode Smartcar Connect should be
|
|
95
|
+
* launched in. Should be one of test, live or simulated.
|
|
96
|
+
*/
|
|
53
97
|
function Smartcar(options) {
|
|
54
98
|
var _this = this;
|
|
55
99
|
|
|
@@ -63,37 +107,50 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
63
107
|
position = position || 0;
|
|
64
108
|
return this.substr(position, searchString.length) === searchString;
|
|
65
109
|
};
|
|
66
|
-
}
|
|
110
|
+
} // ensure options are well formed
|
|
111
|
+
|
|
67
112
|
|
|
68
|
-
// ensure options are well formed
|
|
69
113
|
Smartcar._validateConstructorOptions(options);
|
|
70
114
|
|
|
71
115
|
this.clientId = options.clientId;
|
|
72
116
|
this.redirectUri = options.redirectUri;
|
|
73
117
|
this.scope = options.scope;
|
|
74
118
|
this.onComplete = options.onComplete;
|
|
75
|
-
this.mode =
|
|
76
|
-
|
|
77
|
-
|
|
119
|
+
this.mode = 'live';
|
|
120
|
+
|
|
121
|
+
if (options.hasOwnProperty('testMode')) {
|
|
122
|
+
// eslint-disable-next-line no-console
|
|
123
|
+
console.warn('The "testMode" parameter is deprecated, please use the "mode" parameter instead.');
|
|
124
|
+
this.mode = options.testMode === true ? 'test' : 'live';
|
|
125
|
+
} else if (options.hasOwnProperty('mode')) {
|
|
126
|
+
this.mode = options.mode;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (!['test', 'live', 'simulated'].includes(this.mode)) {
|
|
130
|
+
throw new Error('The "mode" parameter MUST be one of the following: \'test\', \'live\', \'simulated\'');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
this.responseType = 'code'; // identifier for matching message event and multiple Smartcar instances
|
|
78
134
|
// it is a string composed of a timestamp and a 8-digit random number
|
|
79
|
-
this.instanceId = new Date().getTime() + String(Math.random()).slice(2, 10);
|
|
80
135
|
|
|
81
|
-
// handler
|
|
136
|
+
this.instanceId = new Date().getTime() + String(Math.random()).slice(2, 10); // handler
|
|
137
|
+
|
|
82
138
|
this.messageHandler = function (event) {
|
|
83
139
|
// bail if message from unexpected source
|
|
84
140
|
if (!_this.redirectUri.startsWith(event.origin)) {
|
|
85
141
|
return;
|
|
86
142
|
}
|
|
87
143
|
|
|
88
|
-
var message = event.data || {};
|
|
89
|
-
// bail if `message.name` is not `SmartcarAuthMessage`
|
|
144
|
+
var message = event.data || {}; // bail if `message.name` is not `SmartcarAuthMessage`
|
|
90
145
|
// this prevents attempting to handle messages intended for others
|
|
146
|
+
|
|
91
147
|
if (message.name !== 'SmartcarAuthMessage') {
|
|
92
148
|
return;
|
|
93
|
-
}
|
|
149
|
+
} // bail if `state` is invalid
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
var stateObject;
|
|
94
153
|
|
|
95
|
-
// bail if `state` is invalid
|
|
96
|
-
var stateObject = void 0;
|
|
97
154
|
try {
|
|
98
155
|
stateObject = JSON.parse(window.atob(message.state));
|
|
99
156
|
} catch (e) {
|
|
@@ -102,16 +159,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
102
159
|
|
|
103
160
|
var _stateObject = stateObject,
|
|
104
161
|
originalState = _stateObject.originalState,
|
|
105
|
-
instanceId = _stateObject.instanceId;
|
|
106
|
-
// bail if `instanceId` doesn't match
|
|
162
|
+
instanceId = _stateObject.instanceId; // bail if `instanceId` doesn't match
|
|
107
163
|
|
|
108
164
|
if (instanceId !== _this.instanceId) {
|
|
109
165
|
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// if onComplete not specified do nothing, assume developer is conveying
|
|
166
|
+
} // if onComplete not specified do nothing, assume developer is conveying
|
|
113
167
|
// completion information from backend server receiving redirect to front
|
|
114
168
|
// end (not using onComplete)
|
|
169
|
+
|
|
170
|
+
|
|
115
171
|
if (_this.onComplete) {
|
|
116
172
|
// if auth errored generate appropriate error else null
|
|
117
173
|
var generateError = function generateError(error, description) {
|
|
@@ -122,36 +178,37 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
122
178
|
switch (error) {
|
|
123
179
|
case 'access_denied':
|
|
124
180
|
return new Smartcar.AccessDenied(description);
|
|
181
|
+
|
|
125
182
|
case 'invalid_subscription':
|
|
126
183
|
return new Smartcar.InvalidSubscription(description);
|
|
184
|
+
|
|
127
185
|
case 'vehicle_incompatible':
|
|
128
|
-
var params = event.data;
|
|
186
|
+
var params = event.data; // This field will always exist if vehicleInfo is returned
|
|
129
187
|
|
|
130
|
-
// This field will always exist if vehicleInfo is returned
|
|
131
188
|
if (!params.vin) {
|
|
132
189
|
return new Smartcar.VehicleIncompatible(description, null);
|
|
133
|
-
}
|
|
190
|
+
} // These fields are required when vehicleInfo is returned
|
|
191
|
+
|
|
134
192
|
|
|
135
|
-
// These fields are required when vehicleInfo is returned
|
|
136
193
|
var vehicleInfo = {
|
|
137
194
|
vin: params.vin,
|
|
138
195
|
make: params.make,
|
|
139
196
|
year: Number(params.year)
|
|
140
|
-
};
|
|
197
|
+
}; // This field is optional
|
|
141
198
|
|
|
142
|
-
// This field is optional
|
|
143
199
|
if (params.model) {
|
|
144
200
|
vehicleInfo.model = params.model;
|
|
145
201
|
}
|
|
146
202
|
|
|
147
203
|
return new Smartcar.VehicleIncompatible(description, vehicleInfo);
|
|
204
|
+
|
|
148
205
|
default:
|
|
149
|
-
return new Error(
|
|
206
|
+
return new Error("Unexpected error: ".concat(error, " - ").concat(description));
|
|
150
207
|
}
|
|
151
208
|
};
|
|
152
209
|
|
|
153
210
|
var err = generateError(message.error, message.errorDescription);
|
|
154
|
-
|
|
211
|
+
var virtualKeyUrl = message.virtualKeyUrl;
|
|
155
212
|
/**
|
|
156
213
|
* Call `onComplete` with parameters even if developer is not using
|
|
157
214
|
* a Smartcar-hosted redirect. Regardless of if they are using a
|
|
@@ -164,14 +221,14 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
164
221
|
* parameters they must also handle populating the corresponding query
|
|
165
222
|
* parameters in their redirect uri.
|
|
166
223
|
*/
|
|
167
|
-
|
|
224
|
+
|
|
225
|
+
_this.onComplete(err, message.code, originalState, virtualKeyUrl);
|
|
168
226
|
}
|
|
169
|
-
};
|
|
227
|
+
}; // add handler for postMessage event on completion of Smartcar Connect
|
|
228
|
+
|
|
170
229
|
|
|
171
|
-
// add handler for postMessage event on completion of Smartcar Connect
|
|
172
230
|
window.addEventListener('message', this.messageHandler);
|
|
173
231
|
}
|
|
174
|
-
|
|
175
232
|
/**
|
|
176
233
|
* Validate options passed to Smartcar constructor.
|
|
177
234
|
*
|
|
@@ -183,9 +240,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
183
240
|
|
|
184
241
|
|
|
185
242
|
_createClass(Smartcar, [{
|
|
186
|
-
key:
|
|
187
|
-
|
|
188
|
-
|
|
243
|
+
key: "getAuthUrl",
|
|
244
|
+
value:
|
|
189
245
|
/**
|
|
190
246
|
* Generates Smartcar OAuth URL.
|
|
191
247
|
*
|
|
@@ -223,56 +279,36 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
223
279
|
* &single_select_vin=5YJSA1E14FF101307
|
|
224
280
|
* &flags=country:DE color:00819D
|
|
225
281
|
*/
|
|
226
|
-
|
|
282
|
+
function getAuthUrl(options) {
|
|
227
283
|
options = options || {};
|
|
228
|
-
|
|
229
284
|
var link = '';
|
|
230
285
|
link += 'https://connect.smartcar.com/oauth/authorize';
|
|
231
|
-
link +=
|
|
232
|
-
link +=
|
|
233
|
-
link +=
|
|
286
|
+
link += "?response_type=".concat(this.responseType);
|
|
287
|
+
link += "&client_id=".concat(this.clientId);
|
|
288
|
+
link += "&redirect_uri=".concat(encodeURIComponent(this.redirectUri)); // map forcePrompt to approvalPrompt, two options: 'force' and 'auto'
|
|
234
289
|
|
|
235
|
-
// map forcePrompt to approvalPrompt, two options: 'force' and 'auto'
|
|
236
290
|
var forcePrompt = options.forcePrompt === true;
|
|
237
|
-
link +=
|
|
238
|
-
|
|
239
|
-
// If scope is not specified, Smartcar will default to requesting all scopes
|
|
291
|
+
link += "&approval_prompt=".concat(forcePrompt ? 'force' : 'auto'); // If scope is not specified, Smartcar will default to requesting all scopes
|
|
240
292
|
// from the user
|
|
293
|
+
|
|
241
294
|
if (this.scope) {
|
|
242
|
-
link +=
|
|
295
|
+
link += "&scope=".concat(encodeURIComponent(this.scope.join(' ')));
|
|
243
296
|
}
|
|
244
297
|
|
|
245
|
-
link +=
|
|
298
|
+
link += "&mode=".concat(this.mode);
|
|
246
299
|
|
|
247
300
|
if (options.singleSelect !== undefined && options.singleSelect !== null) {
|
|
248
301
|
var singleSelectParamAdded = false;
|
|
302
|
+
|
|
249
303
|
if (_typeof(options.singleSelect) === 'object') {
|
|
250
304
|
var availableParams = ['vin'];
|
|
251
|
-
var _iteratorNormalCompletion = true;
|
|
252
|
-
var _didIteratorError = false;
|
|
253
|
-
var _iteratorError = undefined;
|
|
254
305
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
var param = _step.value;
|
|
306
|
+
for (var _i = 0, _availableParams = availableParams; _i < _availableParams.length; _i++) {
|
|
307
|
+
var param = _availableParams[_i];
|
|
258
308
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
} catch (err) {
|
|
265
|
-
_didIteratorError = true;
|
|
266
|
-
_iteratorError = err;
|
|
267
|
-
} finally {
|
|
268
|
-
try {
|
|
269
|
-
if (!_iteratorNormalCompletion && _iterator.return) {
|
|
270
|
-
_iterator.return();
|
|
271
|
-
}
|
|
272
|
-
} finally {
|
|
273
|
-
if (_didIteratorError) {
|
|
274
|
-
throw _iteratorError;
|
|
275
|
-
}
|
|
309
|
+
if (param in options.singleSelect) {
|
|
310
|
+
link += "&single_select_".concat(param, "=").concat(options.singleSelect[param]);
|
|
311
|
+
singleSelectParamAdded = true;
|
|
276
312
|
}
|
|
277
313
|
}
|
|
278
314
|
|
|
@@ -282,57 +318,40 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
282
318
|
link += '&single_select=true';
|
|
283
319
|
}
|
|
284
320
|
} else {
|
|
285
|
-
link +=
|
|
321
|
+
link += "&single_select=".concat(options.singleSelect === true);
|
|
286
322
|
}
|
|
287
|
-
}
|
|
323
|
+
} // augment state to track the corresponding instance
|
|
324
|
+
|
|
288
325
|
|
|
289
|
-
// augment state to track the corresponding instance
|
|
290
326
|
var state = {
|
|
291
327
|
instanceId: this.instanceId
|
|
292
328
|
};
|
|
329
|
+
|
|
293
330
|
if (options.state) {
|
|
294
331
|
state.originalState = options.state;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
|
|
332
|
+
} // convert the augmented state to a base64 string
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
link += "&state=".concat(window.btoa(JSON.stringify(state)));
|
|
298
336
|
|
|
299
337
|
if (options.vehicleInfo) {
|
|
300
|
-
var
|
|
301
|
-
var _iteratorNormalCompletion2 = true;
|
|
302
|
-
var _didIteratorError2 = false;
|
|
303
|
-
var _iteratorError2 = undefined;
|
|
338
|
+
var _availableParams2 = ['make'];
|
|
304
339
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
var _param = _step2.value;
|
|
340
|
+
for (var _i2 = 0, _availableParams3 = _availableParams2; _i2 < _availableParams3.length; _i2++) {
|
|
341
|
+
var _param = _availableParams3[_i2];
|
|
308
342
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
} catch (err) {
|
|
314
|
-
_didIteratorError2 = true;
|
|
315
|
-
_iteratorError2 = err;
|
|
316
|
-
} finally {
|
|
317
|
-
try {
|
|
318
|
-
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
|
319
|
-
_iterator2.return();
|
|
320
|
-
}
|
|
321
|
-
} finally {
|
|
322
|
-
if (_didIteratorError2) {
|
|
323
|
-
throw _iteratorError2;
|
|
324
|
-
}
|
|
343
|
+
if (_param in options.vehicleInfo) {
|
|
344
|
+
link += "&".concat(_param, "=").concat(encodeURIComponent(options.vehicleInfo[_param]));
|
|
325
345
|
}
|
|
326
346
|
}
|
|
327
347
|
}
|
|
328
348
|
|
|
329
349
|
if (options.flags) {
|
|
330
|
-
link +=
|
|
350
|
+
link += "&flags=".concat(encodeURIComponent(options.flags.join(' ')));
|
|
331
351
|
}
|
|
332
352
|
|
|
333
353
|
return link;
|
|
334
354
|
}
|
|
335
|
-
|
|
336
355
|
/**
|
|
337
356
|
* Launches Smartcar Connect in a new window.
|
|
338
357
|
*
|
|
@@ -353,26 +372,20 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
353
372
|
* the vehicle with the specified VIN. See the
|
|
354
373
|
* [API reference](https://smartcar.com/docs/api/#connect-match)
|
|
355
374
|
* for more information.
|
|
356
|
-
* @param {
|
|
357
|
-
*
|
|
358
|
-
* @param {
|
|
359
|
-
*
|
|
360
|
-
* @param {String} [options.windowOptions.left] - the left property of
|
|
361
|
-
* [window features](https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Window_features)
|
|
362
|
-
* @param {String} [options.windowOptions.width] - the width property of
|
|
363
|
-
* [window features](https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Window_features)
|
|
364
|
-
* @param {String} [options.windowOptions.height] - the height property of
|
|
365
|
-
* [window features](https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Window_features)
|
|
375
|
+
* @param {String[]} [options.flags] - An optional space-separated list of feature
|
|
376
|
+
* flags that your application has early access to.
|
|
377
|
+
* @param {WindowOptions} [options.windowOptions] - position and size settings for
|
|
378
|
+
* the popup window
|
|
366
379
|
*/
|
|
367
380
|
|
|
368
381
|
}, {
|
|
369
|
-
key:
|
|
382
|
+
key: "openDialog",
|
|
370
383
|
value: function openDialog(options) {
|
|
371
384
|
var windowOptions = Smartcar._getWindowOptions(options.windowOptions || {});
|
|
385
|
+
|
|
372
386
|
var href = this.getAuthUrl(options);
|
|
373
387
|
window.open(href, 'Connect your car', windowOptions);
|
|
374
388
|
}
|
|
375
|
-
|
|
376
389
|
/**
|
|
377
390
|
* Adds an on-click event listener to the element with the provided id.
|
|
378
391
|
*
|
|
@@ -397,58 +410,66 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
397
410
|
* the vehicle with the specified VIN. See the
|
|
398
411
|
* [API reference](https://smartcar.com/docs/api/#connect-match)
|
|
399
412
|
* for more information.
|
|
413
|
+
* @param {String[]} [options.flags] - An optional space-separated list of feature
|
|
414
|
+
* flags that your application has early access to.
|
|
415
|
+
* @param {WindowOptions} [options.windowOptions] - position and size settings for
|
|
416
|
+
* the popup window
|
|
400
417
|
*/
|
|
401
418
|
|
|
402
419
|
}, {
|
|
403
|
-
key:
|
|
420
|
+
key: "addClickHandler",
|
|
404
421
|
value: function addClickHandler(options) {
|
|
405
422
|
var _this2 = this;
|
|
406
423
|
|
|
407
424
|
var id = options.id,
|
|
408
|
-
selector = options.selector;
|
|
409
|
-
|
|
410
|
-
// check if id or selector option exists
|
|
425
|
+
selector = options.selector; // check if id or selector option exists
|
|
411
426
|
|
|
412
427
|
if (!id && !selector) {
|
|
413
428
|
throw new Error('Could not add click handler: id or selector must be provided.');
|
|
414
|
-
}
|
|
429
|
+
} // find all the DOM elements that match the id and selector
|
|
430
|
+
|
|
415
431
|
|
|
416
|
-
// find all the DOM elements that match the id and selector
|
|
417
432
|
var elements = [];
|
|
433
|
+
|
|
418
434
|
if (id) {
|
|
419
435
|
var element = document.getElementById(id);
|
|
436
|
+
|
|
420
437
|
if (element) {
|
|
421
438
|
elements.push(element);
|
|
422
439
|
}
|
|
423
440
|
}
|
|
441
|
+
|
|
424
442
|
if (selector) {
|
|
425
443
|
elements.push.apply(elements, _toConsumableArray(document.querySelectorAll(selector)));
|
|
426
444
|
}
|
|
427
|
-
if (!elements.length) {
|
|
428
|
-
throw new Error('\n Could not add click handler: element with \'' + (id || selector) + '\' was not found.\n ');
|
|
429
|
-
}
|
|
430
445
|
|
|
431
|
-
|
|
446
|
+
if (!elements.length) {
|
|
447
|
+
throw new Error("\n Could not add click handler: element with '".concat(id || selector, "' was not found.\n "));
|
|
448
|
+
} // _elementToClickHandler stores all the element - clickHandler pairs under the same instance
|
|
432
449
|
// because it is possible to call addClickHandler multiple times with different options
|
|
450
|
+
|
|
451
|
+
|
|
433
452
|
if (!this._elementToClickHandler) {
|
|
434
453
|
this._elementToClickHandler = new Map();
|
|
435
454
|
}
|
|
455
|
+
|
|
436
456
|
var clickHandler = function clickHandler() {
|
|
437
|
-
_this2.openDialog(options);
|
|
438
|
-
// this is equivalent to calling:
|
|
457
|
+
_this2.openDialog(options); // this is equivalent to calling:
|
|
439
458
|
// event.preventDefault();
|
|
440
459
|
// event.stopPropogation();
|
|
460
|
+
|
|
461
|
+
|
|
441
462
|
return false;
|
|
442
463
|
};
|
|
443
464
|
|
|
444
465
|
elements.forEach(function (element) {
|
|
445
466
|
// register element - clickHandler pair
|
|
446
|
-
_this2._elementToClickHandler.set(element, clickHandler);
|
|
447
|
-
|
|
467
|
+
_this2._elementToClickHandler.set(element, clickHandler); // register eventListener
|
|
468
|
+
|
|
469
|
+
|
|
448
470
|
element.addEventListener('click', clickHandler);
|
|
449
471
|
});
|
|
450
472
|
}
|
|
451
|
-
|
|
452
473
|
/**
|
|
453
474
|
* Remove Smartcar's event listeners.
|
|
454
475
|
*
|
|
@@ -464,43 +485,31 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
464
485
|
*/
|
|
465
486
|
|
|
466
487
|
}, {
|
|
467
|
-
key:
|
|
488
|
+
key: "unmount",
|
|
468
489
|
value: function unmount() {
|
|
469
490
|
window.removeEventListener('message', this.messageHandler);
|
|
491
|
+
|
|
470
492
|
if (this._elementToClickHandler) {
|
|
471
|
-
var
|
|
472
|
-
|
|
473
|
-
var _iteratorError3 = undefined;
|
|
493
|
+
var _iterator = _createForOfIteratorHelper(this._elementToClickHandler.entries()),
|
|
494
|
+
_step;
|
|
474
495
|
|
|
475
496
|
try {
|
|
476
|
-
for (
|
|
477
|
-
var
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
var element = _ref2[0];
|
|
482
|
-
var clickHandler = _ref2[1];
|
|
497
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
498
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
499
|
+
element = _step$value[0],
|
|
500
|
+
clickHandler = _step$value[1];
|
|
483
501
|
|
|
484
502
|
element.removeEventListener('click', clickHandler);
|
|
485
503
|
}
|
|
486
504
|
} catch (err) {
|
|
487
|
-
|
|
488
|
-
_iteratorError3 = err;
|
|
505
|
+
_iterator.e(err);
|
|
489
506
|
} finally {
|
|
490
|
-
|
|
491
|
-
if (!_iteratorNormalCompletion3 && _iterator3.return) {
|
|
492
|
-
_iterator3.return();
|
|
493
|
-
}
|
|
494
|
-
} finally {
|
|
495
|
-
if (_didIteratorError3) {
|
|
496
|
-
throw _iteratorError3;
|
|
497
|
-
}
|
|
498
|
-
}
|
|
507
|
+
_iterator.f();
|
|
499
508
|
}
|
|
500
509
|
}
|
|
501
510
|
}
|
|
502
511
|
}], [{
|
|
503
|
-
key:
|
|
512
|
+
key: "_validateConstructorOptions",
|
|
504
513
|
value: function _validateConstructorOptions(options) {
|
|
505
514
|
if (!options.clientId) {
|
|
506
515
|
throw new TypeError('A client ID option must be provided');
|
|
@@ -521,34 +530,37 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
521
530
|
|
|
522
531
|
if (usesOldUriScheme) {
|
|
523
532
|
// eslint-disable-next-line no-console
|
|
524
|
-
console.warn("\nThe Smartcar redirect URI you're using is outdated! To update it, please see:\nhttps://
|
|
533
|
+
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");
|
|
525
534
|
}
|
|
526
535
|
}
|
|
527
536
|
}
|
|
537
|
+
/**
|
|
538
|
+
* Position and size settings for the popup window.
|
|
539
|
+
*
|
|
540
|
+
* @see Please reference the {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Window_features|Window.open()#Window Features}
|
|
541
|
+
* MDN article for more details
|
|
542
|
+
*
|
|
543
|
+
* @typedef {Object} WindowOptions
|
|
544
|
+
* @property {String} [top]
|
|
545
|
+
* @property {String} [left]
|
|
546
|
+
* @property {String} [width]
|
|
547
|
+
* @property {String} [height]
|
|
548
|
+
*/
|
|
528
549
|
|
|
529
550
|
/**
|
|
530
551
|
* Calculate popup window size and position based on current window settings.
|
|
531
552
|
*
|
|
532
|
-
* @param {Object} options - the postion and dimention setting of the popup window
|
|
533
|
-
* @param {String|Number} [options.top] - the top property of
|
|
534
|
-
* [window features](https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Window_features)
|
|
535
|
-
* @param {String|Number} [options.left] - the left property of
|
|
536
|
-
* [window features](https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Window_features)
|
|
537
|
-
* @param {String|Number} [options.width] - the width property of
|
|
538
|
-
* [window features](https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Window_features)
|
|
539
|
-
* the minimum required value is 100.
|
|
540
|
-
* @param {String|Number} [options.height] - the height property of
|
|
541
|
-
* [window features](https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Window_features)
|
|
542
|
-
* the minimum required value is 100.
|
|
543
553
|
* @private
|
|
554
|
+
* @param {WindowOptions} options
|
|
544
555
|
* @return {String} a string of window settings
|
|
545
556
|
*/
|
|
546
557
|
|
|
547
558
|
}, {
|
|
548
|
-
key:
|
|
559
|
+
key: "_getWindowOptions",
|
|
549
560
|
value: function _getWindowOptions(windowOptions) {
|
|
550
561
|
Object.keys(windowOptions).forEach(function (option) {
|
|
551
562
|
var numValue = parseFloat(windowOptions[option]);
|
|
563
|
+
|
|
552
564
|
if (isNaN(numValue)) {
|
|
553
565
|
windowOptions[option] = '';
|
|
554
566
|
} else if (numValue < 100 && (option === 'width' || option === 'height')) {
|
|
@@ -556,31 +568,26 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
556
568
|
} else {
|
|
557
569
|
windowOptions[option] = String(numValue);
|
|
558
570
|
}
|
|
559
|
-
});
|
|
560
|
-
|
|
561
|
-
// Sets default popup window size as percentage of screen size
|
|
571
|
+
}); // Sets default popup window size as percentage of screen size
|
|
562
572
|
// Note that this only applies to desktop browsers
|
|
573
|
+
|
|
563
574
|
var windowSettings = {
|
|
564
575
|
width: window.screen.width * 0.3,
|
|
565
576
|
height: window.screen.height * 0.75
|
|
566
577
|
};
|
|
567
|
-
|
|
568
578
|
var widthOffset = (window.outerWidth - windowSettings.width) / 2;
|
|
569
579
|
var heightOffset = (window.outerHeight - windowSettings.height) / 8;
|
|
570
|
-
|
|
571
580
|
var options = '';
|
|
572
|
-
options +=
|
|
573
|
-
options +=
|
|
574
|
-
options +=
|
|
575
|
-
options +=
|
|
576
|
-
|
|
581
|
+
options += "top=".concat(windowOptions.top || window.screenY + heightOffset, ",");
|
|
582
|
+
options += "left=".concat(windowOptions.left || window.screenX + widthOffset, ",");
|
|
583
|
+
options += "width=".concat(windowOptions.width || windowSettings.width, ",");
|
|
584
|
+
options += "height=".concat(windowOptions.height || windowSettings.height, ",");
|
|
577
585
|
return options;
|
|
578
586
|
}
|
|
579
587
|
}]);
|
|
580
588
|
|
|
581
589
|
return Smartcar;
|
|
582
590
|
}();
|
|
583
|
-
|
|
584
591
|
/**
|
|
585
592
|
* Access denied error returned by Connect.
|
|
586
593
|
*
|
|
@@ -588,24 +595,26 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
588
595
|
*/
|
|
589
596
|
|
|
590
597
|
|
|
591
|
-
Smartcar.AccessDenied = function (_Error) {
|
|
598
|
+
Smartcar.AccessDenied = /*#__PURE__*/function (_Error) {
|
|
592
599
|
_inherits(_class, _Error);
|
|
593
600
|
|
|
601
|
+
var _super = _createSuper(_class);
|
|
602
|
+
|
|
594
603
|
/**
|
|
595
604
|
* @param {String} message - detailed error description
|
|
596
605
|
*/
|
|
597
606
|
function _class(message) {
|
|
598
|
-
|
|
607
|
+
var _this3;
|
|
599
608
|
|
|
600
|
-
|
|
609
|
+
_classCallCheck(this, _class);
|
|
601
610
|
|
|
611
|
+
_this3 = _super.call(this, message);
|
|
602
612
|
_this3.name = 'AccessDenied';
|
|
603
613
|
return _this3;
|
|
604
614
|
}
|
|
605
615
|
|
|
606
|
-
return _class;
|
|
607
|
-
}(Error);
|
|
608
|
-
|
|
616
|
+
return _createClass(_class);
|
|
617
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
609
618
|
/**
|
|
610
619
|
* Vehicle incompatible error returned by Connect. Will optionally
|
|
611
620
|
* have a vehicleInfo object if the user chooses to give permissions to provide
|
|
@@ -614,9 +623,13 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
614
623
|
*
|
|
615
624
|
* @extends Error
|
|
616
625
|
*/
|
|
617
|
-
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
Smartcar.VehicleIncompatible = /*#__PURE__*/function (_Error2) {
|
|
618
629
|
_inherits(_class2, _Error2);
|
|
619
630
|
|
|
631
|
+
var _super2 = _createSuper(_class2);
|
|
632
|
+
|
|
620
633
|
/**
|
|
621
634
|
* @param {String} message - detailed error description
|
|
622
635
|
* @param {?Object} vehicleInfo - If a vehicle is incompatible, the user has
|
|
@@ -627,40 +640,45 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
627
640
|
* @param {String} [vehicleInfo.model] - optionally returned if user gives permission.
|
|
628
641
|
*/
|
|
629
642
|
function _class2(message, vehicleInfo) {
|
|
630
|
-
|
|
643
|
+
var _this4;
|
|
631
644
|
|
|
632
|
-
|
|
645
|
+
_classCallCheck(this, _class2);
|
|
633
646
|
|
|
647
|
+
_this4 = _super2.call(this, message);
|
|
634
648
|
_this4.name = 'VehicleIncompatible';
|
|
635
649
|
_this4.vehicleInfo = vehicleInfo;
|
|
636
650
|
return _this4;
|
|
637
651
|
}
|
|
638
652
|
|
|
639
|
-
return _class2;
|
|
640
|
-
}(Error);
|
|
641
|
-
|
|
653
|
+
return _createClass(_class2);
|
|
654
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
642
655
|
/**
|
|
643
656
|
* Invalid subscription error returned by Connect.
|
|
644
657
|
*
|
|
645
658
|
* @extends Error
|
|
646
659
|
*/
|
|
647
|
-
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
Smartcar.InvalidSubscription = /*#__PURE__*/function (_Error3) {
|
|
648
663
|
_inherits(_class3, _Error3);
|
|
649
664
|
|
|
665
|
+
var _super3 = _createSuper(_class3);
|
|
666
|
+
|
|
650
667
|
/**
|
|
651
668
|
* @param {String} message - detailed error description
|
|
652
669
|
*/
|
|
653
670
|
function _class3(message) {
|
|
654
|
-
|
|
671
|
+
var _this5;
|
|
655
672
|
|
|
656
|
-
|
|
673
|
+
_classCallCheck(this, _class3);
|
|
657
674
|
|
|
675
|
+
_this5 = _super3.call(this, message);
|
|
658
676
|
_this5.name = 'InvalidSubscription';
|
|
659
677
|
return _this5;
|
|
660
678
|
}
|
|
661
679
|
|
|
662
|
-
return _class3;
|
|
663
|
-
}(Error);
|
|
680
|
+
return _createClass(_class3);
|
|
681
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
664
682
|
|
|
665
683
|
return Smartcar;
|
|
666
684
|
});
|
package/doc/README.md
CHANGED
|
@@ -15,6 +15,9 @@ Smartcar JavaScript SDK documentation.
|
|
|
15
15
|
<dl>
|
|
16
16
|
<dt><a href="#OnComplete">OnComplete</a> : <code>function</code></dt>
|
|
17
17
|
<dd></dd>
|
|
18
|
+
<dt><a href="#WindowOptions">WindowOptions</a> : <code>Object</code></dt>
|
|
19
|
+
<dd><p>Position and size settings for the popup window.</p>
|
|
20
|
+
</dd>
|
|
18
21
|
</dl>
|
|
19
22
|
|
|
20
23
|
<a name="Smartcar"></a>
|
|
@@ -50,7 +53,8 @@ Initializes Smartcar class.
|
|
|
50
53
|
| options.redirectUri | <code>String</code> | | the registered redirect uri of the application |
|
|
51
54
|
| [options.scope] | <code>Array.<String></code> | | requested permission scopes |
|
|
52
55
|
| [options.onComplete] | [<code>OnComplete</code>](#OnComplete) | | called on completion of Smartcar Connect |
|
|
53
|
-
| [options.testMode] | <code>Boolean</code> | <code>false</code> |
|
|
56
|
+
| [options.testMode] | <code>Boolean</code> | <code>false</code> | Deprecated, please use `mode` instead. Launch Smartcar Connect in [test mode](https://smartcar.com/docs/guides/testing/). |
|
|
57
|
+
| [options.mode] | <code>String</code> | <code>'live'</code> | Determine what mode Smartcar Connect should be launched in. Should be one of test, live or simulated. |
|
|
54
58
|
|
|
55
59
|
<a name="Smartcar+getAuthUrl"></a>
|
|
56
60
|
|
|
@@ -96,11 +100,8 @@ Launches Smartcar Connect in a new window.
|
|
|
96
100
|
| [options.forcePrompt] | <code>Boolean</code> | <code>false</code> | force permission approval screen to show on every authentication, even if the user has previously consented to the exact scope of permission |
|
|
97
101
|
| [options.vehicleInfo.make] | <code>String</code> | | `vehicleInfo` is an object with an optional property `make`, which 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. |
|
|
98
102
|
| [options.singleSelect] | <code>Boolean</code> \| <code>Object</code> | | An optional value that sets the behavior of the grant dialog displayed to the user. If set to `true`, `single_select` limits the user to selecting only one vehicle. If `single_select` is passed in as an object with the property `vin`, Smartcar will only authorize the vehicle with the specified VIN. See the [API reference](https://smartcar.com/docs/api/#connect-match) for more information. |
|
|
99
|
-
| [options.
|
|
100
|
-
| [options.windowOptions
|
|
101
|
-
| [options.windowOptions.left] | <code>String</code> | | the left property of [window features](https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Window_features) |
|
|
102
|
-
| [options.windowOptions.width] | <code>String</code> | | the width property of [window features](https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Window_features) |
|
|
103
|
-
| [options.windowOptions.height] | <code>String</code> | | the height property of [window features](https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Window_features) |
|
|
103
|
+
| [options.flags] | <code>Array.<String></code> | | An optional space-separated list of feature flags that your application has early access to. |
|
|
104
|
+
| [options.windowOptions] | [<code>WindowOptions</code>](#WindowOptions) | | position and size settings for the popup window |
|
|
104
105
|
|
|
105
106
|
<a name="Smartcar+addClickHandler"></a>
|
|
106
107
|
|
|
@@ -120,6 +121,8 @@ On-click event calls openDialog when the specified element is clicked.
|
|
|
120
121
|
| [options.forcePrompt] | <code>Boolean</code> | <code>false</code> | force permission approval screen to show on every authentication, even if the user has previously consented to the exact scope of permission |
|
|
121
122
|
| [options.vehicleInfo.make] | <code>String</code> | | `vehicleInfo` is an object with an optional property `make`, which 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. |
|
|
122
123
|
| [options.singleSelect] | <code>Boolean</code> \| <code>Object</code> | | An optional value that sets the behavior of the grant dialog displayed to the user. If set to `true`, `single_select` limits the user to selecting only one vehicle. If `single_select` is passed in as an object with the property `vin`, Smartcar will only authorize the vehicle with the specified VIN. See the [API reference](https://smartcar.com/docs/api/#connect-match) for more information. |
|
|
124
|
+
| [options.flags] | <code>Array.<String></code> | | An optional space-separated list of feature flags that your application has early access to. |
|
|
125
|
+
| [options.windowOptions] | [<code>WindowOptions</code>](#WindowOptions) | | position and size settings for the popup window |
|
|
123
126
|
|
|
124
127
|
<a name="Smartcar+unmount"></a>
|
|
125
128
|
|
|
@@ -200,4 +203,22 @@ Invalid subscription error returned by Connect.
|
|
|
200
203
|
| error | <code>Error</code> | something went wrong in Connect; this normally indicates that the user denied access to your application or does not have a connected vehicle |
|
|
201
204
|
| code | <code>String</code> | the authorization code to be exchanged from a backend sever for an access token |
|
|
202
205
|
| [state] | <code>Object</code> | contains state if it was set on the initial authorization request |
|
|
206
|
+
| [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. |
|
|
207
|
+
|
|
208
|
+
<a name="WindowOptions"></a>
|
|
209
|
+
|
|
210
|
+
## WindowOptions : <code>Object</code>
|
|
211
|
+
Position and size settings for the popup window.
|
|
212
|
+
|
|
213
|
+
**Kind**: global typedef
|
|
214
|
+
**See**: Please reference the [Window.open()#Window Features](https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Window_features)
|
|
215
|
+
MDN article for more details
|
|
216
|
+
**Properties**
|
|
217
|
+
|
|
218
|
+
| Name | Type |
|
|
219
|
+
| --- | --- |
|
|
220
|
+
| [top] | <code>String</code> |
|
|
221
|
+
| [left] | <code>String</code> |
|
|
222
|
+
| [width] | <code>String</code> |
|
|
223
|
+
| [height] | <code>String</code> |
|
|
203
224
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartcar/auth",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.0",
|
|
4
4
|
"description": "javascript auth sdk for the smartcar",
|
|
5
5
|
"main": "dist/npm/sdk.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,48 +15,42 @@
|
|
|
15
15
|
"homepage": "https://github.com/smartcar/javascript-sdk#readme",
|
|
16
16
|
"files": [
|
|
17
17
|
"dist/npm/**",
|
|
18
|
-
"doc/**"
|
|
19
|
-
"postinstall.js"
|
|
18
|
+
"doc/**"
|
|
20
19
|
],
|
|
21
20
|
"scripts": {
|
|
22
21
|
"pretest": "gulp build",
|
|
23
|
-
"postinstall": "node postinstall",
|
|
24
22
|
"test": "jest",
|
|
25
23
|
"posttest": "npm run lint -s",
|
|
26
24
|
"lint": "eslint . --cache",
|
|
27
25
|
"cover": "npm test -- --coverage",
|
|
28
26
|
"readme": "gulp template:readme",
|
|
29
27
|
"jsdoc": "jsdoc2md --example-lang js --template doc/.template.hbs --files src/sdk.js | sed 's/[ \t]*$//' > doc/README.md",
|
|
30
|
-
"prepare-release": "semantic-release --
|
|
28
|
+
"prepare-release": "semantic-release --branches \"$(git rev-parse --abbrev-ref HEAD)\" --extends ./build/sr-configs/local.js"
|
|
31
29
|
},
|
|
32
30
|
"devDependencies": {
|
|
33
|
-
"@
|
|
34
|
-
"babel-
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"eslint": "^
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"gulp": "^
|
|
41
|
-
"gulp-awspublish": "^
|
|
42
|
-
"gulp-babel": "^
|
|
43
|
-
"gulp-rename": "^
|
|
31
|
+
"@babel/core": "^7.18.2",
|
|
32
|
+
"@babel/preset-env": "^7.18.2",
|
|
33
|
+
"@semantic-release/exec": "^6.0.3",
|
|
34
|
+
"eslint": "^8.16.0",
|
|
35
|
+
"eslint-config-smartcar": "^3.0.0",
|
|
36
|
+
"express": "^4.18.1",
|
|
37
|
+
"geckodriver": "^3.0.1",
|
|
38
|
+
"gulp": "^4.0.2",
|
|
39
|
+
"gulp-awspublish": "^6.0.2",
|
|
40
|
+
"gulp-babel": "^8.0.0",
|
|
41
|
+
"gulp-rename": "^2.0.0",
|
|
44
42
|
"gulp-template": "^5.0.0",
|
|
45
43
|
"gulp-uglify": "^3.0.0",
|
|
46
44
|
"gulp-umd": "^2.0.0",
|
|
47
|
-
"
|
|
48
|
-
"jest
|
|
49
|
-
"jest-environment-jsdom
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
45
|
+
"is-ci": "^3.0.1",
|
|
46
|
+
"jest": "^28.1.0",
|
|
47
|
+
"jest-environment-jsdom": "^28.1.0",
|
|
48
|
+
"jest-environment-jsdom-global": "^3.1.2",
|
|
49
|
+
"jsdoc-to-markdown": "^7.1.1",
|
|
50
|
+
"selenium-webdriver": "^4.0.0-alpha.7",
|
|
51
|
+
"semantic-release": "^19.0.2"
|
|
53
52
|
},
|
|
54
53
|
"publishConfig": {
|
|
55
54
|
"access": "public"
|
|
56
|
-
},
|
|
57
|
-
"dependencies": {
|
|
58
|
-
"chalk": "^2.4.2",
|
|
59
|
-
"request": "^2.88.0",
|
|
60
|
-
"semver": "^6.1.1"
|
|
61
55
|
}
|
|
62
56
|
}
|
package/postinstall.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/* eslint-env node */
|
|
2
|
-
/* eslint-disable no-console */
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
const chalk = require('chalk');
|
|
6
|
-
const request = require('request');
|
|
7
|
-
const semver = require('semver');
|
|
8
|
-
|
|
9
|
-
const {version} = require('./package');
|
|
10
|
-
|
|
11
|
-
const primaryColor = (text) => chalk.yellow(text);
|
|
12
|
-
const highlight = (text) => chalk.cyan.bold(text);
|
|
13
|
-
|
|
14
|
-
request.get('https://registry.npmjs.org/@smartcar/auth', function(err, res, body) {
|
|
15
|
-
if (err) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
body = JSON.parse(body);
|
|
20
|
-
|
|
21
|
-
const {latest} = body['dist-tags'];
|
|
22
|
-
|
|
23
|
-
if (semver.gt(latest, version)) {
|
|
24
|
-
console.warn(
|
|
25
|
-
primaryColor('\nYour Smartcar JavaScript SDK is outdated! Please update by running:\n'),
|
|
26
|
-
highlight('> npm i @smartcar/auth@latest\n'),
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
});
|