Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/run-test-harness.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ jobs:
sdks-to-test: nodejs,of-nodejs
sdk-github-sha: ${{github.event.pull_request.head.sha}}
github-token: ${{ secrets.AUTOMATION_USER_TOKEN }}
sdk-capabilities: '{ "NodeJS":["edgeDB", "cloud", "lastModifiedHeader", "bootstrapping", "sdkConfigEvent", "clientUUID", "v2Config", "clientCustomData", "variablesFeatureId", "cloudEvalReason", "evalReason"]}'
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,6 @@ verdaccio
e2e/js/js-cdn/src/assets/devcycle.min.js
e2e/js/js-cdn/playwright-report/
e2e/js/js-esm/playwright-report/

#opencode ai guidelines
AGENTS.md
20 changes: 19 additions & 1 deletion sdk/nodejs/__tests__/client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { DevCycleClient } from '../src/client'
import { DevCycleUser } from '@devcycle/js-cloud-server-sdk'
import { DVCCustomDataJSON } from '@devcycle/types'
import {
DEFAULT_REASON_DETAILS,
DVCCustomDataJSON,
EVAL_REASON_DETAILS,
EVAL_REASONS,
} from '@devcycle/types'
import { EvalHook } from '../src/hooks/EvalHook'

jest.mock('../src/bucketing')
Expand Down Expand Up @@ -34,10 +39,10 @@
describe('DevCycleClient', () => {
it('imports bucketing lib on initialize', async () => {
const client = new DevCycleClient('token')
expect((client as any).bucketingLib).toBeUndefined()

Check warning on line 42 in sdk/nodejs/__tests__/client.spec.ts

View workflow job for this annotation

GitHub Actions / build (22.12)

Unexpected any. Specify a different type
await client.onClientInitialized()
const platformData = (
(client as any).bucketingLib.setPlatformData as any

Check warning on line 45 in sdk/nodejs/__tests__/client.spec.ts

View workflow job for this annotation

GitHub Actions / build (22.12)

Unexpected any. Specify a different type

Check warning on line 45 in sdk/nodejs/__tests__/client.spec.ts

View workflow job for this annotation

GitHub Actions / build (22.12)

Unexpected any. Specify a different type
).mock.calls[0][0]

expect(JSON.parse(platformData)).toEqual({
Expand Down Expand Up @@ -80,6 +85,11 @@
const variable = client.variable(user, 'test-key', false)
expect(variable.value).toEqual(true)
expect(variable.type).toEqual('Boolean')
expect(variable.eval).toEqual({
reason: EVAL_REASONS.TARGETING_MATCH,
details: EVAL_REASON_DETAILS.ALL_USERS,
target_id: 'mockTargetId',
})

expect(client.variableValue(user, 'test-key', false)).toEqual(true)
})
Expand All @@ -98,6 +108,10 @@
const variable = client.variable(user, 'test-key2', false)
expect(variable.value).toEqual(false)
expect(variable.isDefaulted).toEqual(true)
expect(variable.eval).toEqual({
reason: EVAL_REASONS.DEFAULT,
details: DEFAULT_REASON_DETAILS.USER_NOT_TARGETED,
})

// @ts-ignore
client.bucketingLib.variableForUser_PB.mockReturnValueOnce(null)
Expand All @@ -110,6 +124,10 @@
const variable = client.variable(user, 'test-key', 'test')
expect(variable.value).toEqual('test')
expect(variable.isDefaulted).toEqual(true)
expect(variable.eval).toEqual({
reason: EVAL_REASONS.DEFAULT,
details: DEFAULT_REASON_DETAILS.TYPE_MISMATCH,
})

expect(client.variableValue(user, 'test-key', 'test')).toEqual('test')
})
Expand Down Expand Up @@ -168,7 +186,7 @@
client.setClientCustomData(customData)

expect(
(client as any).bucketingLib.setClientCustomData,

Check warning on line 189 in sdk/nodejs/__tests__/client.spec.ts

View workflow job for this annotation

GitHub Actions / build (22.12)

Unexpected any. Specify a different type
).toHaveBeenCalledWith('token', JSON.stringify(customData))
})

Expand Down
7 changes: 7 additions & 0 deletions sdk/nodejs/src/__mocks__/bucketing.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { Exports, ProtobufTypes } from '@devcycle/bucketing-assembly-script'
import { EVAL_REASON_DETAILS, EVAL_REASONS } from '@devcycle/types'

const testVariable = {
_id: 'test-id',
value: true,
type: 'Boolean',
key: 'test-key',
evalReason: null,
eval: {
reason: EVAL_REASONS.TARGETING_MATCH,
details: EVAL_REASON_DETAILS.ALL_USERS,
target_id: 'mockTargetId',
},
}
const buffer = ProtobufTypes.SDKVariable_PB.encode({
_id: testVariable._id,
Expand All @@ -14,6 +20,7 @@ const buffer = ProtobufTypes.SDKVariable_PB.encode({
boolValue: testVariable.value,
doubleValue: 0,
stringValue: '',
eval: testVariable.eval,
}).finish()

enum VariableType {
Expand Down
19 changes: 18 additions & 1 deletion sdk/nodejs/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
VariableDefinitions,
InferredVariableType,
DVCCustomDataJSON,
EVAL_REASONS,
DEFAULT_REASON_DETAILS,
} from '@devcycle/types'
import os from 'os'
import {
Expand Down Expand Up @@ -260,6 +262,10 @@ export class DevCycleClient<
defaultValue,
type,
key,
eval: {
reason: EVAL_REASONS.DEFAULT,
details: DEFAULT_REASON_DETAILS.MISSING_CONFIG,
},
})
}

Expand All @@ -279,12 +285,23 @@ export class DevCycleClient<
if (configVariable) {
if (type === configVariable.type) {
options.value = configVariable.value as VariableTypeAlias<T>
options.evalReason = configVariable.eval?.reason
if (configVariable.eval) {
options.eval = { ...configVariable.eval }
}
} else {
options.eval = {
reason: EVAL_REASONS.DEFAULT,
details: DEFAULT_REASON_DETAILS.TYPE_MISMATCH,
}
this.logger.error(
`Type mismatch for variable ${key}. Expected ${type}, got ${configVariable.type}`,
)
}
} else {
options.eval = {
reason: EVAL_REASONS.DEFAULT,
details: DEFAULT_REASON_DETAILS.USER_NOT_TARGETED,
}
}

return new DVCVariable(options)
Expand Down
1 change: 1 addition & 0 deletions sdk/nodejs/src/pb-types/pbTypeHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ export function pbSDKVariableTransform(
!variable._feature || variable._feature.isNull
? null
: variable._feature.value,
eval: variable.eval,
}
}
Loading