Skip to content

Commit 6f98f3b

Browse files
authored
feat: [FFM-6507]: Add environment ID and account ID headers (#63)
1 parent ac6688f commit 6f98f3b

11 files changed

+52
-44
lines changed

Diff for: README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,21 @@ In case you want to import this library directly (without having to use npm or y
120120

121121
```html
122122
<script type="module">
123-
import { initialize, Event } from 'https://unpkg.com/@harnessio/ff-javascript-client-sdk@1.6.0/dist/sdk.client.js'
123+
import { initialize, Event } from 'https://unpkg.com/@harnessio/ff-javascript-client-sdk@1.7.0/dist/sdk.client.js'
124124
</script>
125125
```
126126

127127
If you need to support old browsers which don't support ES Module:
128128

129129
```html
130-
<script src="https://unpkg.com/@harnessio/ff-javascript-client-sdk@1.6.0/dist/sdk.client.js"></script>
130+
<script src="https://unpkg.com/@harnessio/ff-javascript-client-sdk@1.7.0/dist/sdk.client.js"></script>
131131
<script>
132132
var initialize = HarnessFFSDK.initialize
133133
var Event = HarnessFFSDK.Event
134134
</script>
135135
```
136136

137-
Remember to change the version `1.6.0` in the unpkg url accordingly.
137+
Remember to change the version `1.7.0` in the unpkg url accordingly.
138138

139139
## License
140140

Diff for: dist/sdk.cjs.js

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/sdk.client-iife.js

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/sdk.client.js

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/sdk.esm.js

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: examples/preact/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: examples/react-redux/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: examples/react/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@harnessio/ff-javascript-client-sdk",
3-
"version": "1.6.0",
3+
"version": "1.7.0",
44
"author": "Harness",
55
"license": "Apache-2.0",
66
"main": "dist/sdk.cjs.js",

Diff for: src/index.ts

+19-11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type {
1515
import { Event } from './types'
1616
import { defaultOptions, logError, MIN_EVENTS_SYNC_INTERVAL } from './utils'
1717

18-
const SDK_VERSION = '1.6.0'
18+
const SDK_VERSION = '1.7.0'
1919
const METRICS_VALID_COUNT_INTERVAL = 500
2020
const fetch = globalThis.fetch
2121
const EventSource = EventSourcePolyfill
@@ -54,6 +54,7 @@ const initialize = (apiKey: string, target: Target, options?: Options): Result =
5454
let jwtToken: string
5555
let metricsSchedulerId: number
5656
let metricsCollectorEnabled = true
57+
let standardHeaders: Record<string, string> = {}
5758

5859
const stopMetricsCollector = () => {
5960
metricsCollectorEnabled = false
@@ -158,7 +159,7 @@ const initialize = (apiKey: string, target: Target, options?: Options): Result =
158159

159160
fetch(`${configurations.eventUrl}/metrics/${environment}?cluster=${clusterIdentifier}`, {
160161
method: 'POST',
161-
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${jwtToken}` },
162+
headers: { 'Content-Type': 'application/json', ...standardHeaders },
162163
body: JSON.stringify(payload)
163164
})
164165
.then(() => {
@@ -278,7 +279,18 @@ const initialize = (apiKey: string, target: Target, options?: Options): Result =
278279
if (closed) return
279280

280281
jwtToken = token
281-
const decoded: { environment: string; clusterIdentifier: string } = jwt_decode(token)
282+
const decoded: {
283+
environment: string
284+
environmentIdentifier: string
285+
clusterIdentifier: string
286+
accountID: string
287+
} = jwt_decode(token)
288+
289+
standardHeaders = {
290+
Authorization: `Bearer ${jwtToken}`,
291+
'Harness-AccountID': decoded.accountID,
292+
'Harness-EnvironmentID': decoded.environmentIdentifier
293+
}
282294

283295
logDebug('Authenticated', decoded)
284296

@@ -337,9 +349,7 @@ const initialize = (apiKey: string, target: Target, options?: Options): Result =
337349
const res = await fetch(
338350
`${configurations.baseUrl}/client/env/${environment}/target/${target.identifier}/evaluations?cluster=${clusterIdentifier}`,
339351
{
340-
headers: {
341-
Authorization: `Bearer ${jwtToken}`
342-
}
352+
headers: standardHeaders
343353
}
344354
)
345355
const data = await res.json()
@@ -368,9 +378,7 @@ const initialize = (apiKey: string, target: Target, options?: Options): Result =
368378
const result = await fetch(
369379
`${configurations.baseUrl}/client/env/${environment}/target/${target.identifier}/evaluations/${identifier}?cluster=${clusterIdentifier}`,
370380
{
371-
headers: {
372-
Authorization: `Bearer ${jwtToken}`
373-
}
381+
headers: standardHeaders
374382
}
375383
)
376384

@@ -421,8 +429,8 @@ const initialize = (apiKey: string, target: Target, options?: Options): Result =
421429
}
422430
eventSource = new EventSource(`${configurations.baseUrl}/stream?cluster=${clusterIdentifier}`, {
423431
headers: {
424-
Authorization: `Bearer ${jwtToken}`,
425-
'API-Key': apiKey
432+
'API-Key': apiKey,
433+
...standardHeaders
426434
}
427435
})
428436

0 commit comments

Comments
 (0)