Skip to content

Commit

Permalink
fix: remove package.json dependency from builderUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
shuowu committed Apr 17, 2020
1 parent 654f9e1 commit 7c7a179
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/okta-auth-js/lib/browser/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions packages/okta-auth-js/lib/builderUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -101,7 +100,7 @@ function buildOktaAuth(OktaAuthBuilder) {
};
}

function getUserAgent(args) {
function getUserAgent(args, sdkVersion) {
var userAgent = args.userAgent;

if (!userAgent) {
Expand All @@ -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 '';
Expand Down
2 changes: 1 addition & 1 deletion packages/okta-auth-js/lib/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
9 changes: 5 additions & 4 deletions packages/okta-auth-js/test/spec/builderUtil.js
Original file line number Diff line number Diff line change
@@ -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', () => {

Expand All @@ -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 = {};
Expand Down

0 comments on commit 7c7a179

Please sign in to comment.