Skip to content

Commit

Permalink
fix: allow other key formats when the js-client-sdk is intialized fro…
Browse files Browse the repository at this point in the history
…m the nextjs sdk
  • Loading branch information
kaushalkapasi committed Aug 8, 2024
1 parent 51c3609 commit 524da32
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions sdk/js/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ jest.spyOn(Request, 'getConfigJson').mockImplementation(() => {
})

const test_key = 'client_test_sdk_key'
const test_server_key = 'dvc_server_key'
const missingKeyError = 'Missing SDK key! Call initialize with a valid SDK key'
const invalidKeyError =
'Invalid SDK key provided. Please call initialize with a valid client SDK key'
Expand Down Expand Up @@ -61,6 +62,13 @@ describe('initializeDevCycle tests', () => {
)
})

it('should not throw an error if invalid SDK key is passed in initialize when running with next option set', () => {
const user = { user_id: 'user1' }
expect(() =>
DVC.initializeDevCycle(test_server_key, user, { next: 'test' }),
).not.toThrow(invalidKeyError)
})

it('should flush when pagehide is triggered', () => {
const user = { user_id: 'bruh' }
const client = DVC.initializeDevCycle(test_key, user)
Expand Down
6 changes: 5 additions & 1 deletion sdk/js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ export function initializeDevCycle<
throw new Error('Missing SDK key! Call initialize with a valid SDK key')
}

if (!sdkKey.startsWith('client') && !sdkKey.startsWith('dvc_client')) {
if (
!sdkKey.startsWith('client') &&
!sdkKey.startsWith('dvc_client') &&
!optionsArg?.next
) {
throw new Error(
'Invalid SDK key provided. Please call initialize with a valid client SDK key',
)
Expand Down

0 comments on commit 524da32

Please sign in to comment.