-
Notifications
You must be signed in to change notification settings - Fork 393
/
Copy pathheaders.ts
45 lines (41 loc) · 1.65 KB
/
headers.ts
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
36
37
38
39
40
41
42
43
44
45
import { Buffer } from 'buffer'
export const headers = {
BlobsInfo: 'x-nf-blobs-info',
DeployID: 'x-nf-deploy-id',
DeployContext: 'x-nf-deploy-context',
FeatureFlags: 'x-nf-feature-flags',
ForwardedHost: 'x-forwarded-host',
ForwardedProtocol: 'x-forwarded-proto',
Functions: 'x-nf-edge-functions',
InvocationMetadata: 'x-nf-edge-functions-metadata',
Geo: 'x-nf-geo',
Passthrough: 'x-nf-passthrough',
PassthroughHost: 'x-nf-passthrough-host',
PassthroughProtocol: 'x-nf-passthrough-proto',
IP: 'x-nf-client-connection-ip',
Site: 'X-NF-Site-Info',
DebugLogging: 'x-nf-debug-logging',
Account: 'x-nf-account-info',
}
/**
* Takes an array of feature flags and produces a Base64-encoded JSON object
* that the bootstrap layer can understand.
*
* @param {Array<string>} featureFlags
* @returns {string}
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'featureFlags' implicitly has an 'any' t... Remove this comment to see the full error message
export const getFeatureFlagsHeader = (featureFlags) => {
// @ts-expect-error TS(7006) FIXME: Parameter 'acc' implicitly has an 'any' type.
const featureFlagsObject = featureFlags.reduce((acc, flagName) => ({ ...acc, [flagName]: true }), {})
return Buffer.from(JSON.stringify(featureFlagsObject)).toString('base64')
}
/**
* Takes the invocation metadata object and produces a Base64-encoded JSON
* object that the bootstrap layer can understand.
*
* @param {object} metadata
* @returns {string}
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'metadata' implicitly has an 'any' type.
export const getInvocationMetadataHeader = (metadata) => Buffer.from(JSON.stringify(metadata)).toString('base64')