@unleash/proxy
Advanced tools
Comparing version 0.2.0 to 0.3.0
# Changelog | ||
### 0.3.0 | ||
- feat: Add support for namePrefix and tag filtering (#21) | ||
- fix: add maxAge to /proxy endpoint | ||
### 0.2.0 | ||
@@ -4,0 +9,0 @@ |
@@ -30,2 +30,4 @@ "use strict"; | ||
disableMetrics: true, | ||
namePrefix: config.namePrefix, | ||
tags: config.tags, | ||
customHeadersFunction, | ||
@@ -32,0 +34,0 @@ }); |
@@ -43,2 +43,8 @@ "use strict"; | ||
} | ||
function mapTagsToFilters(tags) { | ||
return resolveStringToArray(tags)?.map((tag) => { | ||
const [name, value] = tag.split(':'); | ||
return { name, value }; | ||
}); | ||
} | ||
function createProxyConfig(option) { | ||
@@ -62,2 +68,3 @@ const unleashUrl = option.unleashUrl || process.env.UNLEASH_URL; | ||
const trustProxy = option.trustProxy || loadTrustProxy(process.env.TRUST_PROXY); | ||
const tags = option.tags || mapTagsToFilters(process.env.UNLEASH_TAGS); | ||
const unleashInstanceId = option.unleashInstanceId || | ||
@@ -82,5 +89,7 @@ process.env.UNLEASH_INSTANCE_ID || | ||
projectName: option.projectName || process.env.UNLEASH_PROJECT_NAME, | ||
namePrefix: option.namePrefix || process.env.UNLEASH_NAME_PREFIX, | ||
disableMetrics: false, | ||
logger: option.logger || new logger_1.SimpleLogger(logLevel), | ||
trustProxy, | ||
tags, | ||
}; | ||
@@ -87,0 +96,0 @@ } |
@@ -146,2 +146,61 @@ "use strict"; | ||
}); | ||
test('should set namePrefix via options', () => { | ||
const config = config_1.createProxyConfig({ | ||
unleashUrl: 'some', | ||
unleashApiToken: 'some', | ||
namePrefix: 'somePrefix', | ||
proxySecrets: ['s1'], | ||
}); | ||
expect(config.namePrefix).toBe('somePrefix'); | ||
}); | ||
test('should set namePrefix via env', () => { | ||
process.env.UNLEASH_NAME_PREFIX = 'prefixViaEnv'; | ||
const config = config_1.createProxyConfig({ | ||
unleashUrl: 'some', | ||
unleashApiToken: 'some', | ||
proxySecrets: ['s1'], | ||
}); | ||
expect(config.namePrefix).toBe('prefixViaEnv'); | ||
delete process.env.UNLEASH_CUSTOM_STRATEGIES_FILE; | ||
}); | ||
test('should not set tags', () => { | ||
const config = config_1.createProxyConfig({ | ||
unleashUrl: 'some', | ||
unleashApiToken: 'some', | ||
proxySecrets: ['s1'], | ||
}); | ||
expect(config.tags).toBeUndefined(); | ||
}); | ||
test('should set tags via opts', () => { | ||
const config = config_1.createProxyConfig({ | ||
unleashUrl: 'some', | ||
unleashApiToken: 'some', | ||
proxySecrets: ['s1'], | ||
tags: [{ name: 'simple', value: 'proxy' }], | ||
}); | ||
expect(config.tags).toStrictEqual([{ name: 'simple', value: 'proxy' }]); | ||
}); | ||
test('should not set tags with empty env var', () => { | ||
process.env.UNLEASH_TAGS = ''; | ||
const config = config_1.createProxyConfig({ | ||
unleashUrl: 'some', | ||
unleashApiToken: 'some', | ||
proxySecrets: ['s1'], | ||
}); | ||
expect(config.tags).toBeUndefined(); | ||
delete process.env.UNLEASH_CUSTOM_STRATEGIES_FILE; | ||
}); | ||
test('should set tags with env var', () => { | ||
process.env.UNLEASH_TAGS = 'simple:proxy, demo:test'; | ||
const config = config_1.createProxyConfig({ | ||
unleashUrl: 'some', | ||
unleashApiToken: 'some', | ||
proxySecrets: ['s1'], | ||
}); | ||
expect(config.tags).toStrictEqual([ | ||
{ name: 'simple', value: 'proxy' }, | ||
{ name: 'demo', value: 'test' }, | ||
]); | ||
delete process.env.UNLEASH_CUSTOM_STRATEGIES_FILE; | ||
}); | ||
//# sourceMappingURL=config.test.js.map |
@@ -47,2 +47,3 @@ "use strict"; | ||
const toggles = this.client.getEnabledToggles(context); | ||
res.set('Cache-control', 'public, max-age=2'); | ||
res.send({ toggles }); | ||
@@ -49,0 +50,0 @@ } |
{ | ||
"name": "@unleash/proxy", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "The Unleash Proxy (Open-Source)", | ||
@@ -35,3 +35,3 @@ "main": "dist/index.js", | ||
"joi": "^17.4.0", | ||
"unleash-client": "^3.9.1" | ||
"unleash-client": "^3.10.1" | ||
}, | ||
@@ -38,0 +38,0 @@ "devDependencies": { |
@@ -114,5 +114,7 @@ # The Unleash Proxy | ||
| logger | n/a | SimpleLogger | no | Register a custom logger. | | ||
| logLevel | `LOG_LEVEL ` | "warn" | no | Used to set logLevel. Supported options: "debug", "info", "warn", "error" and "fatal | | ||
| logLevel | `LOG_LEVEL ` | "warn" | no | Used to set logLevel. Supported options: "debug", "info", "warn", "error" and "fatal" | | ||
| customStrategies| `UNLEASH_CUSTOM_STRATEGIES_FILE` | [] | no | Use this option to inject implementation of custom activation strategies. If you are using `UNLEASH_CUSTOM_STRATEGIES_FILE` you need to provide a valid path to a javascript files which exports an array of custom activation strategies and the SDK will automatically load these | | ||
| trustProxy | `TRUST_PROXY ` | `false` | no | By enabling the trustProxy option, Unleash Proxy will have knowledge that it's sitting behind a proxy and that the X-Forwarded-* header fields may be trusted, which otherwise may be easily spoofed. The proxy will automatically enrich the ip address in the Unleash Context. Can either be `true/false` (Trust all proxies), trust only given IP/CIDR (e.g. `'127.0.0.1'`) as a `string`. May be a list of comma separated values (e.g. `'127.0.0.1,192.168.1.1/24'` | | ||
| namePrefix | `UNLEASH_NAME_PREFIX` | undefined | no | Used to filter features by using prefix when requesting backend values. | | ||
| tags | `UNLEASH_TAGS` | undefined | no | Used to filter features by using tags set for features. Format should be `tagName:tagValue,tagName2:tagValue2` | | ||
@@ -119,0 +121,0 @@ ### Run with Node.js: |
@@ -74,2 +74,4 @@ import EventEmitter from 'events'; | ||
disableMetrics: true, | ||
namePrefix: config.namePrefix, | ||
tags: config.tags, | ||
customHeadersFunction, | ||
@@ -76,0 +78,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
import { Strategy } from 'unleash-client'; | ||
import { Strategy, TagFilter } from 'unleash-client'; | ||
import { Logger, LogLevel, SimpleLogger } from './logger'; | ||
@@ -21,2 +21,4 @@ import { generateInstanceId } from './util'; | ||
trustProxy?: boolean | string | number; | ||
namePrefix?: string; | ||
tags?: Array<TagFilter>; | ||
} | ||
@@ -39,2 +41,4 @@ | ||
trustProxy: boolean | string | number; | ||
namePrefix?: string; | ||
tags?: Array<TagFilter>; | ||
} | ||
@@ -81,2 +85,9 @@ | ||
function mapTagsToFilters(tags?: string): Array<TagFilter> | undefined { | ||
return resolveStringToArray(tags)?.map((tag) => { | ||
const [name, value] = tag.split(':'); | ||
return { name, value }; | ||
}); | ||
} | ||
export function createProxyConfig(option: IProxyOption): IProxyConfig { | ||
@@ -116,2 +127,4 @@ const unleashUrl = option.unleashUrl || process.env.UNLEASH_URL; | ||
const tags = option.tags || mapTagsToFilters(process.env.UNLEASH_TAGS); | ||
const unleashInstanceId = | ||
@@ -142,6 +155,8 @@ option.unleashInstanceId || | ||
projectName: option.projectName || process.env.UNLEASH_PROJECT_NAME, | ||
namePrefix: option.namePrefix || process.env.UNLEASH_NAME_PREFIX, | ||
disableMetrics: false, | ||
logger: option.logger || new SimpleLogger(logLevel), | ||
trustProxy, | ||
tags, | ||
}; | ||
} |
@@ -150,1 +150,73 @@ import * as path from 'path'; | ||
}); | ||
test('should set namePrefix via options', () => { | ||
const config = createProxyConfig({ | ||
unleashUrl: 'some', | ||
unleashApiToken: 'some', | ||
namePrefix: 'somePrefix', | ||
proxySecrets: ['s1'], | ||
}); | ||
expect(config.namePrefix).toBe('somePrefix'); | ||
}); | ||
test('should set namePrefix via env', () => { | ||
process.env.UNLEASH_NAME_PREFIX = 'prefixViaEnv'; | ||
const config = createProxyConfig({ | ||
unleashUrl: 'some', | ||
unleashApiToken: 'some', | ||
proxySecrets: ['s1'], | ||
}); | ||
expect(config.namePrefix).toBe('prefixViaEnv'); | ||
delete process.env.UNLEASH_CUSTOM_STRATEGIES_FILE; | ||
}); | ||
test('should not set tags', () => { | ||
const config = createProxyConfig({ | ||
unleashUrl: 'some', | ||
unleashApiToken: 'some', | ||
proxySecrets: ['s1'], | ||
}); | ||
expect(config.tags).toBeUndefined(); | ||
}); | ||
test('should set tags via opts', () => { | ||
const config = createProxyConfig({ | ||
unleashUrl: 'some', | ||
unleashApiToken: 'some', | ||
proxySecrets: ['s1'], | ||
tags: [{ name: 'simple', value: 'proxy' }], | ||
}); | ||
expect(config.tags).toStrictEqual([{ name: 'simple', value: 'proxy' }]); | ||
}); | ||
test('should not set tags with empty env var', () => { | ||
process.env.UNLEASH_TAGS = ''; | ||
const config = createProxyConfig({ | ||
unleashUrl: 'some', | ||
unleashApiToken: 'some', | ||
proxySecrets: ['s1'], | ||
}); | ||
expect(config.tags).toBeUndefined(); | ||
delete process.env.UNLEASH_CUSTOM_STRATEGIES_FILE; | ||
}); | ||
test('should set tags with env var', () => { | ||
process.env.UNLEASH_TAGS = 'simple:proxy, demo:test'; | ||
const config = createProxyConfig({ | ||
unleashUrl: 'some', | ||
unleashApiToken: 'some', | ||
proxySecrets: ['s1'], | ||
}); | ||
expect(config.tags).toStrictEqual([ | ||
{ name: 'simple', value: 'proxy' }, | ||
{ name: 'demo', value: 'test' }, | ||
]); | ||
delete process.env.UNLEASH_CUSTOM_STRATEGIES_FILE; | ||
}); |
@@ -68,2 +68,3 @@ import { Request, Response, Router } from 'express'; | ||
const toggles = this.client.getEnabledToggles(context); | ||
res.set('Cache-control', 'public, max-age=2'); | ||
res.send({ toggles }); | ||
@@ -70,0 +71,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
136867
2436
162
38
Updatedunleash-client@^3.10.1