From 7c7a1797554523d085a5ab9af7778a41b91fdfbd Mon Sep 17 00:00:00 2001 From: Shuo Wu Date: Fri, 17 Apr 2020 13:36:58 -0400 Subject: [PATCH] fix: remove package.json dependency from builderUtil --- packages/okta-auth-js/lib/browser/browser.js | 2 +- packages/okta-auth-js/lib/builderUtil.js | 5 ++--- packages/okta-auth-js/lib/server/server.js | 2 +- packages/okta-auth-js/test/spec/builderUtil.js | 9 +++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/okta-auth-js/lib/browser/browser.js b/packages/okta-auth-js/lib/browser/browser.js index 2c88b5bfd..7be967e50 100644 --- a/packages/okta-auth-js/lib/browser/browser.js +++ b/packages/okta-auth-js/lib/browser/browser.js @@ -82,7 +82,7 @@ function OktaAuthBuilder(args) { throw new AuthSdkError(errorMessage); } - this.userAgent = builderUtil.getUserAgent(args) || 'okta-auth-js-' + SDK_VERSION; + this.userAgent = builderUtil.getUserAgent(args, SDK_VERSION) || 'okta-auth-js-' + SDK_VERSION; // Digital clocks will drift over time, so the server // can misalign with the time reported by the browser. diff --git a/packages/okta-auth-js/lib/builderUtil.js b/packages/okta-auth-js/lib/builderUtil.js index 6b9ec6081..2022e1987 100644 --- a/packages/okta-auth-js/lib/builderUtil.js +++ b/packages/okta-auth-js/lib/builderUtil.js @@ -13,7 +13,6 @@ var AuthSdkError = require('./errors/AuthSdkError'); var tx = require('./tx'); var util = require('./util'); -var SDK_VERSION = require('../package.json').version; // TODO: use @okta/configuration-validation (move module to this monorepo?) // eslint-disable-next-line complexity @@ -101,7 +100,7 @@ function buildOktaAuth(OktaAuthBuilder) { }; } -function getUserAgent(args) { +function getUserAgent(args, sdkVersion) { var userAgent = args.userAgent; if (!userAgent) { @@ -113,7 +112,7 @@ function getUserAgent(args) { } if (userAgent.template) { - return userAgent.template.replace('$OKTA_AUTH_JS', `okta-auth-js/${SDK_VERSION}`); + return userAgent.template.replace('$OKTA_AUTH_JS', `okta-auth-js/${sdkVersion}`); } return ''; diff --git a/packages/okta-auth-js/lib/server/server.js b/packages/okta-auth-js/lib/server/server.js index 15e5a12f6..5ef13a50d 100644 --- a/packages/okta-auth-js/lib/server/server.js +++ b/packages/okta-auth-js/lib/server/server.js @@ -29,7 +29,7 @@ function OktaAuthBuilder(args) { headers: args.headers }; - this.userAgent = builderUtil.getUserAgent(args) || 'okta-auth-js-server' + SDK_VERSION; + this.userAgent = builderUtil.getUserAgent(args, SDK_VERSION) || 'okta-auth-js-server' + SDK_VERSION; sdk.tx = { status: util.bind(tx.transactionStatus, null, sdk), diff --git a/packages/okta-auth-js/test/spec/builderUtil.js b/packages/okta-auth-js/test/spec/builderUtil.js index 81fd29a3d..ec602b30d 100644 --- a/packages/okta-auth-js/test/spec/builderUtil.js +++ b/packages/okta-auth-js/test/spec/builderUtil.js @@ -1,5 +1,6 @@ -var builderUtil = require('../../lib/builderUtil'); -var SDK_VERSION = require('../../package.json').version; +const builderUtil = require('../../lib/builderUtil'); + +const SDK_VERSION = '0.0.0'; describe('builderUtil', () => { @@ -19,8 +20,8 @@ describe('builderUtil', () => { template: 'fake userAgent $OKTA_AUTH_JS' } }; - const userAgent = builderUtil.getUserAgent(args); - expect(userAgent).toEqual(`fake userAgent okta-auth-js/${SDK_VERSION}`); + const userAgent = builderUtil.getUserAgent(args, SDK_VERSION); + expect(userAgent).toEqual(`fake userAgent okta-auth-js/0.0.0`); }); it('should return undefined if neither with userAgent nor userAgentTemplate in args', () => { const args = {};