-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.js
More file actions
35 lines (29 loc) · 1.06 KB
/
utils.js
File metadata and controls
35 lines (29 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { getTraceId } from '@defra/hapi-tracing'
import Joi from 'joi'
import { config } from '~/src/config/index.js'
/**
* Returns a set of headers to use in an HTTP request, merging them with any existing headers in options.
* @param {Record<string, string> | undefined} [existingHeaders] - Optional existing headers to merge with the tracing headers.
* @param {string} [header] - The tracing header name to use.
* @returns {Record<string, string> | undefined} The merged headers, or undefined if no tracing header is available.
*/
export function applyTraceHeaders(
existingHeaders,
header = config.get('tracing').header
) {
if (!header) {
return existingHeaders
}
const traceId = getTraceId()
const headers = traceId ? { [header]: traceId } : undefined
return existingHeaders ? Object.assign(existingHeaders, headers) : headers
}
/**
* Validates if a string conforms to the uuid structure
* @param {string} str
* @returns
*/
export function isValidUUID(str) {
const { error } = Joi.string().uuid().validate(str)
return error === undefined
}