@smartcar/auth 2.8.0 → 2.9.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 +211 -198
- package/doc/README.md +26 -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.9.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.9.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
|
|
@@ -48,8 +85,11 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
48
85
|
* application
|
|
49
86
|
* @param {String[]} [options.scope] - requested permission scopes
|
|
50
87
|
* @param {OnComplete} [options.onComplete] - called on completion of Smartcar Connect
|
|
51
|
-
* @param {Boolean} [options.testMode=false] -
|
|
52
|
-
|
|
88
|
+
* @param {Boolean} [options.testMode=false] - Deprecated, please use `mode` instead.
|
|
89
|
+
* Launch Smartcar Connect in [test mode](https://smartcar.com/docs/guides/testing/).
|
|
90
|
+
* @param {String} [options.mode='live'] - Determine what mode Smartcar Connect should be
|
|
91
|
+
* launched in. Should be one of test, live or simulated.
|
|
92
|
+
*/
|
|
53
93
|
function Smartcar(options) {
|
|
54
94
|
var _this = this;
|
|
55
95
|
|
|
@@ -63,37 +103,50 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
63
103
|
position = position || 0;
|
|
64
104
|
return this.substr(position, searchString.length) === searchString;
|
|
65
105
|
};
|
|
66
|
-
}
|
|
106
|
+
} // ensure options are well formed
|
|
107
|
+
|
|
67
108
|
|
|
68
|
-
// ensure options are well formed
|
|
69
109
|
Smartcar._validateConstructorOptions(options);
|
|
70
110
|
|
|
71
111
|
this.clientId = options.clientId;
|
|
72
112
|
this.redirectUri = options.redirectUri;
|
|
73
113
|
this.scope = options.scope;
|
|
74
114
|
this.onComplete = options.onComplete;
|
|
75
|
-
this.mode =
|
|
76
|
-
|
|
77
|
-
|
|
115
|
+
this.mode = 'live';
|
|
116
|
+
|
|
117
|
+
if (options.hasOwnProperty('testMode')) {
|
|
118
|
+
// eslint-disable-next-line no-console
|
|
119
|
+
console.warn('The "testMode" parameter is deprecated, please use the "mode" parameter instead.');
|
|
120
|
+
this.mode = options.testMode === true ? 'test' : 'live';
|
|
121
|
+
} else if (options.hasOwnProperty('mode')) {
|
|
122
|
+
this.mode = options.mode;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (!['test', 'live', 'simulated'].includes(this.mode)) {
|
|
126
|
+
throw new Error('The "mode" parameter MUST be one of the following: \'test\', \'live\', \'simulated\'');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
this.responseType = 'code'; // identifier for matching message event and multiple Smartcar instances
|
|
78
130
|
// 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
131
|
|
|
81
|
-
// handler
|
|
132
|
+
this.instanceId = new Date().getTime() + String(Math.random()).slice(2, 10); // handler
|
|
133
|
+
|
|
82
134
|
this.messageHandler = function (event) {
|
|
83
135
|
// bail if message from unexpected source
|
|
84
136
|
if (!_this.redirectUri.startsWith(event.origin)) {
|
|
85
137
|
return;
|
|
86
138
|
}
|
|
87
139
|
|
|
88
|
-
var message = event.data || {};
|
|
89
|
-
// bail if `message.name` is not `SmartcarAuthMessage`
|
|
140
|
+
var message = event.data || {}; // bail if `message.name` is not `SmartcarAuthMessage`
|
|
90
141
|
// this prevents attempting to handle messages intended for others
|
|
142
|
+
|
|
91
143
|
if (message.name !== 'SmartcarAuthMessage') {
|
|
92
144
|
return;
|
|
93
|
-
}
|
|
145
|
+
} // bail if `state` is invalid
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
var stateObject;
|
|
94
149
|
|
|
95
|
-
// bail if `state` is invalid
|
|
96
|
-
var stateObject = void 0;
|
|
97
150
|
try {
|
|
98
151
|
stateObject = JSON.parse(window.atob(message.state));
|
|
99
152
|
} catch (e) {
|
|
@@ -102,16 +155,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
102
155
|
|
|
103
156
|
var _stateObject = stateObject,
|
|
104
157
|
originalState = _stateObject.originalState,
|
|
105
|
-
instanceId = _stateObject.instanceId;
|
|
106
|
-
// bail if `instanceId` doesn't match
|
|
158
|
+
instanceId = _stateObject.instanceId; // bail if `instanceId` doesn't match
|
|
107
159
|
|
|
108
160
|
if (instanceId !== _this.instanceId) {
|
|
109
161
|
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// if onComplete not specified do nothing, assume developer is conveying
|
|
162
|
+
} // if onComplete not specified do nothing, assume developer is conveying
|
|
113
163
|
// completion information from backend server receiving redirect to front
|
|
114
164
|
// end (not using onComplete)
|
|
165
|
+
|
|
166
|
+
|
|
115
167
|
if (_this.onComplete) {
|
|
116
168
|
// if auth errored generate appropriate error else null
|
|
117
169
|
var generateError = function generateError(error, description) {
|
|
@@ -122,36 +174,36 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
122
174
|
switch (error) {
|
|
123
175
|
case 'access_denied':
|
|
124
176
|
return new Smartcar.AccessDenied(description);
|
|
177
|
+
|
|
125
178
|
case 'invalid_subscription':
|
|
126
179
|
return new Smartcar.InvalidSubscription(description);
|
|
180
|
+
|
|
127
181
|
case 'vehicle_incompatible':
|
|
128
|
-
var params = event.data;
|
|
182
|
+
var params = event.data; // This field will always exist if vehicleInfo is returned
|
|
129
183
|
|
|
130
|
-
// This field will always exist if vehicleInfo is returned
|
|
131
184
|
if (!params.vin) {
|
|
132
185
|
return new Smartcar.VehicleIncompatible(description, null);
|
|
133
|
-
}
|
|
186
|
+
} // These fields are required when vehicleInfo is returned
|
|
187
|
+
|
|
134
188
|
|
|
135
|
-
// These fields are required when vehicleInfo is returned
|
|
136
189
|
var vehicleInfo = {
|
|
137
190
|
vin: params.vin,
|
|
138
191
|
make: params.make,
|
|
139
192
|
year: Number(params.year)
|
|
140
|
-
};
|
|
193
|
+
}; // This field is optional
|
|
141
194
|
|
|
142
|
-
// This field is optional
|
|
143
195
|
if (params.model) {
|
|
144
196
|
vehicleInfo.model = params.model;
|
|
145
197
|
}
|
|
146
198
|
|
|
147
199
|
return new Smartcar.VehicleIncompatible(description, vehicleInfo);
|
|
200
|
+
|
|
148
201
|
default:
|
|
149
|
-
return new Error(
|
|
202
|
+
return new Error("Unexpected error: ".concat(error, " - ").concat(description));
|
|
150
203
|
}
|
|
151
204
|
};
|
|
152
205
|
|
|
153
206
|
var err = generateError(message.error, message.errorDescription);
|
|
154
|
-
|
|
155
207
|
/**
|
|
156
208
|
* Call `onComplete` with parameters even if developer is not using
|
|
157
209
|
* a Smartcar-hosted redirect. Regardless of if they are using a
|
|
@@ -164,14 +216,14 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
164
216
|
* parameters they must also handle populating the corresponding query
|
|
165
217
|
* parameters in their redirect uri.
|
|
166
218
|
*/
|
|
219
|
+
|
|
167
220
|
_this.onComplete(err, message.code, originalState);
|
|
168
221
|
}
|
|
169
|
-
};
|
|
222
|
+
}; // add handler for postMessage event on completion of Smartcar Connect
|
|
223
|
+
|
|
170
224
|
|
|
171
|
-
// add handler for postMessage event on completion of Smartcar Connect
|
|
172
225
|
window.addEventListener('message', this.messageHandler);
|
|
173
226
|
}
|
|
174
|
-
|
|
175
227
|
/**
|
|
176
228
|
* Validate options passed to Smartcar constructor.
|
|
177
229
|
*
|
|
@@ -183,9 +235,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
183
235
|
|
|
184
236
|
|
|
185
237
|
_createClass(Smartcar, [{
|
|
186
|
-
key:
|
|
187
|
-
|
|
188
|
-
|
|
238
|
+
key: "getAuthUrl",
|
|
239
|
+
value:
|
|
189
240
|
/**
|
|
190
241
|
* Generates Smartcar OAuth URL.
|
|
191
242
|
*
|
|
@@ -223,56 +274,36 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
223
274
|
* &single_select_vin=5YJSA1E14FF101307
|
|
224
275
|
* &flags=country:DE color:00819D
|
|
225
276
|
*/
|
|
226
|
-
|
|
277
|
+
function getAuthUrl(options) {
|
|
227
278
|
options = options || {};
|
|
228
|
-
|
|
229
279
|
var link = '';
|
|
230
280
|
link += 'https://connect.smartcar.com/oauth/authorize';
|
|
231
|
-
link +=
|
|
232
|
-
link +=
|
|
233
|
-
link +=
|
|
281
|
+
link += "?response_type=".concat(this.responseType);
|
|
282
|
+
link += "&client_id=".concat(this.clientId);
|
|
283
|
+
link += "&redirect_uri=".concat(encodeURIComponent(this.redirectUri)); // map forcePrompt to approvalPrompt, two options: 'force' and 'auto'
|
|
234
284
|
|
|
235
|
-
// map forcePrompt to approvalPrompt, two options: 'force' and 'auto'
|
|
236
285
|
var forcePrompt = options.forcePrompt === true;
|
|
237
|
-
link +=
|
|
238
|
-
|
|
239
|
-
// If scope is not specified, Smartcar will default to requesting all scopes
|
|
286
|
+
link += "&approval_prompt=".concat(forcePrompt ? 'force' : 'auto'); // If scope is not specified, Smartcar will default to requesting all scopes
|
|
240
287
|
// from the user
|
|
288
|
+
|
|
241
289
|
if (this.scope) {
|
|
242
|
-
link +=
|
|
290
|
+
link += "&scope=".concat(encodeURIComponent(this.scope.join(' ')));
|
|
243
291
|
}
|
|
244
292
|
|
|
245
|
-
link +=
|
|
293
|
+
link += "&mode=".concat(this.mode);
|
|
246
294
|
|
|
247
295
|
if (options.singleSelect !== undefined && options.singleSelect !== null) {
|
|
248
296
|
var singleSelectParamAdded = false;
|
|
297
|
+
|
|
249
298
|
if (_typeof(options.singleSelect) === 'object') {
|
|
250
299
|
var availableParams = ['vin'];
|
|
251
|
-
var _iteratorNormalCompletion = true;
|
|
252
|
-
var _didIteratorError = false;
|
|
253
|
-
var _iteratorError = undefined;
|
|
254
300
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
var param = _step.value;
|
|
301
|
+
for (var _i = 0, _availableParams = availableParams; _i < _availableParams.length; _i++) {
|
|
302
|
+
var param = _availableParams[_i];
|
|
258
303
|
|
|
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
|
-
}
|
|
304
|
+
if (param in options.singleSelect) {
|
|
305
|
+
link += "&single_select_".concat(param, "=").concat(options.singleSelect[param]);
|
|
306
|
+
singleSelectParamAdded = true;
|
|
276
307
|
}
|
|
277
308
|
}
|
|
278
309
|
|
|
@@ -282,57 +313,40 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
282
313
|
link += '&single_select=true';
|
|
283
314
|
}
|
|
284
315
|
} else {
|
|
285
|
-
link +=
|
|
316
|
+
link += "&single_select=".concat(options.singleSelect === true);
|
|
286
317
|
}
|
|
287
|
-
}
|
|
318
|
+
} // augment state to track the corresponding instance
|
|
319
|
+
|
|
288
320
|
|
|
289
|
-
// augment state to track the corresponding instance
|
|
290
321
|
var state = {
|
|
291
322
|
instanceId: this.instanceId
|
|
292
323
|
};
|
|
324
|
+
|
|
293
325
|
if (options.state) {
|
|
294
326
|
state.originalState = options.state;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
|
|
327
|
+
} // convert the augmented state to a base64 string
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
link += "&state=".concat(window.btoa(JSON.stringify(state)));
|
|
298
331
|
|
|
299
332
|
if (options.vehicleInfo) {
|
|
300
|
-
var
|
|
301
|
-
var _iteratorNormalCompletion2 = true;
|
|
302
|
-
var _didIteratorError2 = false;
|
|
303
|
-
var _iteratorError2 = undefined;
|
|
333
|
+
var _availableParams2 = ['make'];
|
|
304
334
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
var _param = _step2.value;
|
|
335
|
+
for (var _i2 = 0, _availableParams3 = _availableParams2; _i2 < _availableParams3.length; _i2++) {
|
|
336
|
+
var _param = _availableParams3[_i2];
|
|
308
337
|
|
|
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
|
-
}
|
|
338
|
+
if (_param in options.vehicleInfo) {
|
|
339
|
+
link += "&".concat(_param, "=").concat(encodeURIComponent(options.vehicleInfo[_param]));
|
|
325
340
|
}
|
|
326
341
|
}
|
|
327
342
|
}
|
|
328
343
|
|
|
329
344
|
if (options.flags) {
|
|
330
|
-
link +=
|
|
345
|
+
link += "&flags=".concat(encodeURIComponent(options.flags.join(' ')));
|
|
331
346
|
}
|
|
332
347
|
|
|
333
348
|
return link;
|
|
334
349
|
}
|
|
335
|
-
|
|
336
350
|
/**
|
|
337
351
|
* Launches Smartcar Connect in a new window.
|
|
338
352
|
*
|
|
@@ -353,26 +367,20 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
353
367
|
* the vehicle with the specified VIN. See the
|
|
354
368
|
* [API reference](https://smartcar.com/docs/api/#connect-match)
|
|
355
369
|
* 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)
|
|
370
|
+
* @param {String[]} [options.flags] - An optional space-separated list of feature
|
|
371
|
+
* flags that your application has early access to.
|
|
372
|
+
* @param {WindowOptions} [options.windowOptions] - position and size settings for
|
|
373
|
+
* the popup window
|
|
366
374
|
*/
|
|
367
375
|
|
|
368
376
|
}, {
|
|
369
|
-
key:
|
|
377
|
+
key: "openDialog",
|
|
370
378
|
value: function openDialog(options) {
|
|
371
379
|
var windowOptions = Smartcar._getWindowOptions(options.windowOptions || {});
|
|
380
|
+
|
|
372
381
|
var href = this.getAuthUrl(options);
|
|
373
382
|
window.open(href, 'Connect your car', windowOptions);
|
|
374
383
|
}
|
|
375
|
-
|
|
376
384
|
/**
|
|
377
385
|
* Adds an on-click event listener to the element with the provided id.
|
|
378
386
|
*
|
|
@@ -397,58 +405,66 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
397
405
|
* the vehicle with the specified VIN. See the
|
|
398
406
|
* [API reference](https://smartcar.com/docs/api/#connect-match)
|
|
399
407
|
* for more information.
|
|
408
|
+
* @param {String[]} [options.flags] - An optional space-separated list of feature
|
|
409
|
+
* flags that your application has early access to.
|
|
410
|
+
* @param {WindowOptions} [options.windowOptions] - position and size settings for
|
|
411
|
+
* the popup window
|
|
400
412
|
*/
|
|
401
413
|
|
|
402
414
|
}, {
|
|
403
|
-
key:
|
|
415
|
+
key: "addClickHandler",
|
|
404
416
|
value: function addClickHandler(options) {
|
|
405
417
|
var _this2 = this;
|
|
406
418
|
|
|
407
419
|
var id = options.id,
|
|
408
|
-
selector = options.selector;
|
|
409
|
-
|
|
410
|
-
// check if id or selector option exists
|
|
420
|
+
selector = options.selector; // check if id or selector option exists
|
|
411
421
|
|
|
412
422
|
if (!id && !selector) {
|
|
413
423
|
throw new Error('Could not add click handler: id or selector must be provided.');
|
|
414
|
-
}
|
|
424
|
+
} // find all the DOM elements that match the id and selector
|
|
425
|
+
|
|
415
426
|
|
|
416
|
-
// find all the DOM elements that match the id and selector
|
|
417
427
|
var elements = [];
|
|
428
|
+
|
|
418
429
|
if (id) {
|
|
419
430
|
var element = document.getElementById(id);
|
|
431
|
+
|
|
420
432
|
if (element) {
|
|
421
433
|
elements.push(element);
|
|
422
434
|
}
|
|
423
435
|
}
|
|
436
|
+
|
|
424
437
|
if (selector) {
|
|
425
438
|
elements.push.apply(elements, _toConsumableArray(document.querySelectorAll(selector)));
|
|
426
439
|
}
|
|
427
|
-
if (!elements.length) {
|
|
428
|
-
throw new Error('\n Could not add click handler: element with \'' + (id || selector) + '\' was not found.\n ');
|
|
429
|
-
}
|
|
430
440
|
|
|
431
|
-
|
|
441
|
+
if (!elements.length) {
|
|
442
|
+
throw new Error("\n Could not add click handler: element with '".concat(id || selector, "' was not found.\n "));
|
|
443
|
+
} // _elementToClickHandler stores all the element - clickHandler pairs under the same instance
|
|
432
444
|
// because it is possible to call addClickHandler multiple times with different options
|
|
445
|
+
|
|
446
|
+
|
|
433
447
|
if (!this._elementToClickHandler) {
|
|
434
448
|
this._elementToClickHandler = new Map();
|
|
435
449
|
}
|
|
450
|
+
|
|
436
451
|
var clickHandler = function clickHandler() {
|
|
437
|
-
_this2.openDialog(options);
|
|
438
|
-
// this is equivalent to calling:
|
|
452
|
+
_this2.openDialog(options); // this is equivalent to calling:
|
|
439
453
|
// event.preventDefault();
|
|
440
454
|
// event.stopPropogation();
|
|
455
|
+
|
|
456
|
+
|
|
441
457
|
return false;
|
|
442
458
|
};
|
|
443
459
|
|
|
444
460
|
elements.forEach(function (element) {
|
|
445
461
|
// register element - clickHandler pair
|
|
446
|
-
_this2._elementToClickHandler.set(element, clickHandler);
|
|
447
|
-
|
|
462
|
+
_this2._elementToClickHandler.set(element, clickHandler); // register eventListener
|
|
463
|
+
|
|
464
|
+
|
|
448
465
|
element.addEventListener('click', clickHandler);
|
|
449
466
|
});
|
|
450
467
|
}
|
|
451
|
-
|
|
452
468
|
/**
|
|
453
469
|
* Remove Smartcar's event listeners.
|
|
454
470
|
*
|
|
@@ -464,43 +480,31 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
464
480
|
*/
|
|
465
481
|
|
|
466
482
|
}, {
|
|
467
|
-
key:
|
|
483
|
+
key: "unmount",
|
|
468
484
|
value: function unmount() {
|
|
469
485
|
window.removeEventListener('message', this.messageHandler);
|
|
486
|
+
|
|
470
487
|
if (this._elementToClickHandler) {
|
|
471
|
-
var
|
|
472
|
-
|
|
473
|
-
var _iteratorError3 = undefined;
|
|
488
|
+
var _iterator = _createForOfIteratorHelper(this._elementToClickHandler.entries()),
|
|
489
|
+
_step;
|
|
474
490
|
|
|
475
491
|
try {
|
|
476
|
-
for (
|
|
477
|
-
var
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
var element = _ref2[0];
|
|
482
|
-
var clickHandler = _ref2[1];
|
|
492
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
493
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
494
|
+
element = _step$value[0],
|
|
495
|
+
clickHandler = _step$value[1];
|
|
483
496
|
|
|
484
497
|
element.removeEventListener('click', clickHandler);
|
|
485
498
|
}
|
|
486
499
|
} catch (err) {
|
|
487
|
-
|
|
488
|
-
_iteratorError3 = err;
|
|
500
|
+
_iterator.e(err);
|
|
489
501
|
} finally {
|
|
490
|
-
|
|
491
|
-
if (!_iteratorNormalCompletion3 && _iterator3.return) {
|
|
492
|
-
_iterator3.return();
|
|
493
|
-
}
|
|
494
|
-
} finally {
|
|
495
|
-
if (_didIteratorError3) {
|
|
496
|
-
throw _iteratorError3;
|
|
497
|
-
}
|
|
498
|
-
}
|
|
502
|
+
_iterator.f();
|
|
499
503
|
}
|
|
500
504
|
}
|
|
501
505
|
}
|
|
502
506
|
}], [{
|
|
503
|
-
key:
|
|
507
|
+
key: "_validateConstructorOptions",
|
|
504
508
|
value: function _validateConstructorOptions(options) {
|
|
505
509
|
if (!options.clientId) {
|
|
506
510
|
throw new TypeError('A client ID option must be provided');
|
|
@@ -525,30 +529,33 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
525
529
|
}
|
|
526
530
|
}
|
|
527
531
|
}
|
|
532
|
+
/**
|
|
533
|
+
* Position and size settings for the popup window.
|
|
534
|
+
*
|
|
535
|
+
* @see Please reference the {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Window_features|Window.open()#Window Features}
|
|
536
|
+
* MDN article for more details
|
|
537
|
+
*
|
|
538
|
+
* @typedef {Object} WindowOptions
|
|
539
|
+
* @property {String} [top]
|
|
540
|
+
* @property {String} [left]
|
|
541
|
+
* @property {String} [width]
|
|
542
|
+
* @property {String} [height]
|
|
543
|
+
*/
|
|
528
544
|
|
|
529
545
|
/**
|
|
530
546
|
* Calculate popup window size and position based on current window settings.
|
|
531
547
|
*
|
|
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
548
|
* @private
|
|
549
|
+
* @param {WindowOptions} options
|
|
544
550
|
* @return {String} a string of window settings
|
|
545
551
|
*/
|
|
546
552
|
|
|
547
553
|
}, {
|
|
548
|
-
key:
|
|
554
|
+
key: "_getWindowOptions",
|
|
549
555
|
value: function _getWindowOptions(windowOptions) {
|
|
550
556
|
Object.keys(windowOptions).forEach(function (option) {
|
|
551
557
|
var numValue = parseFloat(windowOptions[option]);
|
|
558
|
+
|
|
552
559
|
if (isNaN(numValue)) {
|
|
553
560
|
windowOptions[option] = '';
|
|
554
561
|
} else if (numValue < 100 && (option === 'width' || option === 'height')) {
|
|
@@ -556,31 +563,26 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
556
563
|
} else {
|
|
557
564
|
windowOptions[option] = String(numValue);
|
|
558
565
|
}
|
|
559
|
-
});
|
|
560
|
-
|
|
561
|
-
// Sets default popup window size as percentage of screen size
|
|
566
|
+
}); // Sets default popup window size as percentage of screen size
|
|
562
567
|
// Note that this only applies to desktop browsers
|
|
568
|
+
|
|
563
569
|
var windowSettings = {
|
|
564
570
|
width: window.screen.width * 0.3,
|
|
565
571
|
height: window.screen.height * 0.75
|
|
566
572
|
};
|
|
567
|
-
|
|
568
573
|
var widthOffset = (window.outerWidth - windowSettings.width) / 2;
|
|
569
574
|
var heightOffset = (window.outerHeight - windowSettings.height) / 8;
|
|
570
|
-
|
|
571
575
|
var options = '';
|
|
572
|
-
options +=
|
|
573
|
-
options +=
|
|
574
|
-
options +=
|
|
575
|
-
options +=
|
|
576
|
-
|
|
576
|
+
options += "top=".concat(windowOptions.top || window.screenY + heightOffset, ",");
|
|
577
|
+
options += "left=".concat(windowOptions.left || window.screenX + widthOffset, ",");
|
|
578
|
+
options += "width=".concat(windowOptions.width || windowSettings.width, ",");
|
|
579
|
+
options += "height=".concat(windowOptions.height || windowSettings.height, ",");
|
|
577
580
|
return options;
|
|
578
581
|
}
|
|
579
582
|
}]);
|
|
580
583
|
|
|
581
584
|
return Smartcar;
|
|
582
585
|
}();
|
|
583
|
-
|
|
584
586
|
/**
|
|
585
587
|
* Access denied error returned by Connect.
|
|
586
588
|
*
|
|
@@ -588,24 +590,26 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
588
590
|
*/
|
|
589
591
|
|
|
590
592
|
|
|
591
|
-
Smartcar.AccessDenied = function (_Error) {
|
|
593
|
+
Smartcar.AccessDenied = /*#__PURE__*/function (_Error) {
|
|
592
594
|
_inherits(_class, _Error);
|
|
593
595
|
|
|
596
|
+
var _super = _createSuper(_class);
|
|
597
|
+
|
|
594
598
|
/**
|
|
595
599
|
* @param {String} message - detailed error description
|
|
596
600
|
*/
|
|
597
601
|
function _class(message) {
|
|
598
|
-
|
|
602
|
+
var _this3;
|
|
599
603
|
|
|
600
|
-
|
|
604
|
+
_classCallCheck(this, _class);
|
|
601
605
|
|
|
606
|
+
_this3 = _super.call(this, message);
|
|
602
607
|
_this3.name = 'AccessDenied';
|
|
603
608
|
return _this3;
|
|
604
609
|
}
|
|
605
610
|
|
|
606
|
-
return _class;
|
|
607
|
-
}(Error);
|
|
608
|
-
|
|
611
|
+
return _createClass(_class);
|
|
612
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
609
613
|
/**
|
|
610
614
|
* Vehicle incompatible error returned by Connect. Will optionally
|
|
611
615
|
* have a vehicleInfo object if the user chooses to give permissions to provide
|
|
@@ -614,9 +618,13 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
614
618
|
*
|
|
615
619
|
* @extends Error
|
|
616
620
|
*/
|
|
617
|
-
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
Smartcar.VehicleIncompatible = /*#__PURE__*/function (_Error2) {
|
|
618
624
|
_inherits(_class2, _Error2);
|
|
619
625
|
|
|
626
|
+
var _super2 = _createSuper(_class2);
|
|
627
|
+
|
|
620
628
|
/**
|
|
621
629
|
* @param {String} message - detailed error description
|
|
622
630
|
* @param {?Object} vehicleInfo - If a vehicle is incompatible, the user has
|
|
@@ -627,40 +635,45 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
627
635
|
* @param {String} [vehicleInfo.model] - optionally returned if user gives permission.
|
|
628
636
|
*/
|
|
629
637
|
function _class2(message, vehicleInfo) {
|
|
630
|
-
|
|
638
|
+
var _this4;
|
|
631
639
|
|
|
632
|
-
|
|
640
|
+
_classCallCheck(this, _class2);
|
|
633
641
|
|
|
642
|
+
_this4 = _super2.call(this, message);
|
|
634
643
|
_this4.name = 'VehicleIncompatible';
|
|
635
644
|
_this4.vehicleInfo = vehicleInfo;
|
|
636
645
|
return _this4;
|
|
637
646
|
}
|
|
638
647
|
|
|
639
|
-
return _class2;
|
|
640
|
-
}(Error);
|
|
641
|
-
|
|
648
|
+
return _createClass(_class2);
|
|
649
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
642
650
|
/**
|
|
643
651
|
* Invalid subscription error returned by Connect.
|
|
644
652
|
*
|
|
645
653
|
* @extends Error
|
|
646
654
|
*/
|
|
647
|
-
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
Smartcar.InvalidSubscription = /*#__PURE__*/function (_Error3) {
|
|
648
658
|
_inherits(_class3, _Error3);
|
|
649
659
|
|
|
660
|
+
var _super3 = _createSuper(_class3);
|
|
661
|
+
|
|
650
662
|
/**
|
|
651
663
|
* @param {String} message - detailed error description
|
|
652
664
|
*/
|
|
653
665
|
function _class3(message) {
|
|
654
|
-
|
|
666
|
+
var _this5;
|
|
655
667
|
|
|
656
|
-
|
|
668
|
+
_classCallCheck(this, _class3);
|
|
657
669
|
|
|
670
|
+
_this5 = _super3.call(this, message);
|
|
658
671
|
_this5.name = 'InvalidSubscription';
|
|
659
672
|
return _this5;
|
|
660
673
|
}
|
|
661
674
|
|
|
662
|
-
return _class3;
|
|
663
|
-
}(Error);
|
|
675
|
+
return _createClass(_class3);
|
|
676
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
664
677
|
|
|
665
678
|
return Smartcar;
|
|
666
679
|
});
|
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
|
|
|
@@ -201,3 +204,20 @@ Invalid subscription error returned by Connect.
|
|
|
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 |
|
|
203
206
|
|
|
207
|
+
<a name="WindowOptions"></a>
|
|
208
|
+
|
|
209
|
+
## WindowOptions : <code>Object</code>
|
|
210
|
+
Position and size settings for the popup window.
|
|
211
|
+
|
|
212
|
+
**Kind**: global typedef
|
|
213
|
+
**See**: Please reference the [Window.open()#Window Features](https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Window_features)
|
|
214
|
+
MDN article for more details
|
|
215
|
+
**Properties**
|
|
216
|
+
|
|
217
|
+
| Name | Type |
|
|
218
|
+
| --- | --- |
|
|
219
|
+
| [top] | <code>String</code> |
|
|
220
|
+
| [left] | <code>String</code> |
|
|
221
|
+
| [width] | <code>String</code> |
|
|
222
|
+
| [height] | <code>String</code> |
|
|
223
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartcar/auth",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.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
|
-
});
|