From 81ded356506a12b131cfe3a63709e7cbb21e583e Mon Sep 17 00:00:00 2001 From: Allison Chen <39199989+allisonc07@users.noreply.github.com> Date: Wed, 3 Apr 2024 10:31:36 -0700 Subject: [PATCH] feat: add user param for auth URL (#83) * feat: add user param for auth URL * chore: run prepare release + update doc --- README.md | 4 ++-- doc/README.md | 2 ++ package-lock.json | 2 +- package.json | 2 +- src/sdk.js | 7 +++++++ test/unit/sdk.test.js | 22 ++++++++++++++++++++++ 6 files changed, 35 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 40603165..c3a1ab7b 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ npm install @smartcar/auth ### Smartcar CDN ```html - + ``` ## SDK reference @@ -178,4 +178,4 @@ https://application-backend.com/page?error=access_denied&error_description=User+ [tag-image]: https://img.shields.io/github/tag/smartcar/javascript-sdk.svg -[version]: 2.10.0 +[version]: 2.11.0 diff --git a/doc/README.md b/doc/README.md index 210c02c8..552af140 100644 --- a/doc/README.md +++ b/doc/README.md @@ -72,6 +72,7 @@ Generates Smartcar OAuth URL. | [options.vehicleInfo.make] | String | | `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 brands, please see our [API Reference](https://smartcar.com/docs/api#authorization) documentation. | | [options.singleSelect] | Boolean \| Object | | 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. | | [options.flags] | Array.<String> | | An optional space-separated list of feature flags that your application has early access to. | +| [options.user] | String | | An optional unique identifier for a vehicle owner. This identifier is used to aggregate analytics across Connect sessions for each vehicle owner. | **Example** ```js @@ -85,6 +86,7 @@ response_type=code &single_select=true &single_select_vin=5YJSA1E14FF101307 &flags=country:DE color:00819D +&user=2dad4eaf-9094-4bff-bb0f-ffbbdde8b562 ``` diff --git a/package-lock.json b/package-lock.json index 37c3d9d2..601e4444 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@smartcar/auth", - "version": "2.10.0", + "version": "2.11.0", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index 2707f438..1dbbf65b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@smartcar/auth", - "version": "2.10.0", + "version": "2.11.0", "description": "javascript auth sdk for the smartcar", "main": "dist/npm/sdk.js", "license": "MIT", diff --git a/src/sdk.js b/src/sdk.js index d7d2b754..b2d4d3d5 100644 --- a/src/sdk.js +++ b/src/sdk.js @@ -276,6 +276,8 @@ class Smartcar { * for more information. * @param {String[]} [options.flags] - An optional space-separated list of feature * flags that your application has early access to. + * @param {String} [options.user] - An optional unique identifier for a vehicle owner. + * This identifier is used to aggregate analytics across Connect sessions for each vehicle owner. * * @return {String} Connect URL to redirect user to. * @@ -290,6 +292,7 @@ class Smartcar { * &single_select=true * &single_select_vin=5YJSA1E14FF101307 * &flags=country:DE color:00819D + * &user=2dad4eaf-9094-4bff-bb0f-ffbbdde8b562 */ getAuthUrl(options) { options = options || {}; @@ -355,6 +358,10 @@ class Smartcar { link += `&flags=${encodeURIComponent(options.flags.join(' '))}`; } + if (options.user) { + link += `&user=${encodeURIComponent(options.user)}`; + } + return link; } diff --git a/test/unit/sdk.test.js b/test/unit/sdk.test.js index 3492e21c..c2997963 100644 --- a/test/unit/sdk.test.js +++ b/test/unit/sdk.test.js @@ -1092,6 +1092,28 @@ describe('sdk', () => { expect(link).toBe(expectedLink); }); + test('Includes user when passed to getAuthUrl', () => { + const options = { + clientId: 'clientId', + redirectUri: 'https://smartcar.com', + scope: ['read_vehicle_info', 'read_odometer'], + onComplete: jest.fn(), + mode: 'live', + }; + + const smartcar = new Smartcar(options); + + const link = smartcar.getAuthUrl({ + state: originalState, + forcePrompt: true, + user: 'test-user-param', + }); + + const expectedLink = + `https://connect.smartcar.com/oauth/authorize?response_type=code&client_id=clientId&redirect_uri=https%3A%2F%2Fsmartcar.com&approval_prompt=force&scope=read_vehicle_info%20read_odometer&mode=live&state=${getEncodedState(smartcar.instanceId)}&user=test-user-param`; + expect(link).toBe(expectedLink); + }); + describe('openDialog and addClickHandler', () => { const options = { clientId: 'clientId',