@indigov/flags-api
Advanced tools
Comparing version 0.0.13 to 0.0.15
@@ -1,10 +0,4 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const __1 = __importDefault(require("../")); | ||
// Tests require Flags lambda to be running locally | ||
import Flags from '../index'; | ||
describe('Flags Client', () => { | ||
const flags = new __1.default(process.env.AUTH_TOKEN, 'indigovdev', 'test', { env: 'local' }); | ||
const flags = new Flags(process.env.AUTH_TOKEN, 'indigovdev', 'test', { env: 'local' }); | ||
it('fetches all flags', async () => { | ||
@@ -11,0 +5,0 @@ const response = await flags.getAllFlags(); |
@@ -23,18 +23,5 @@ declare type Env = 'prod' | 'staging' | 'local'; | ||
constructor(token: string, office: string, source: Source, { env, traceId }?: ConstructorOps); | ||
/** | ||
* Retrieves a boolean value for {@param flag} if it follows our standard schema (see Flags repo) | ||
*/ | ||
getFlag: (flag: string) => Promise<GetFlagResponse>; | ||
/** | ||
* Retrieves boolean values for {@param flags} if they follow our standard schema (see Flags repo) | ||
* @param flags | ||
*/ | ||
getFlags: (flags: string[]) => Promise<GetFlagsResponse>; | ||
/** | ||
* Retrieves the raw value (as seen in Flagsmith) for {@param flag}. | ||
*/ | ||
getFlag: (flag: Flag) => Promise<GetFlagResponse>; | ||
getFlags: (flags: Flag[]) => Promise<GetFlagsResponse>; | ||
getFlagValue: (flag: string) => Promise<GetFlagValueResponse>; | ||
/** | ||
* Retrieves a mapping of all flags (in Flagsmith) to their raw value. | ||
*/ | ||
getAllFlags: () => Promise<GetAllFlagsResponse>; | ||
@@ -41,0 +28,0 @@ private request; |
@@ -1,7 +0,2 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const cross_fetch_1 = __importDefault(require("cross-fetch")); | ||
import fetch from 'cross-fetch'; | ||
const Endpoints = { | ||
@@ -12,3 +7,3 @@ prod: 'https://flags.indigov.us/v1', | ||
}; | ||
class Flags { | ||
export default class Flags { | ||
constructor(token, office, source, { env = 'prod', traceId } = {}) { | ||
@@ -18,20 +13,7 @@ this.token = token; | ||
this.source = source; | ||
/** | ||
* Retrieves a boolean value for {@param flag} if it follows our standard schema (see Flags repo) | ||
*/ | ||
this.getFlag = async (flag) => (await this.request(`flag/${flag}`)).value; | ||
/** | ||
* Retrieves boolean values for {@param flags} if they follow our standard schema (see Flags repo) | ||
* @param flags | ||
*/ | ||
this.getFlags = async (flags) => this.request(`flags?${flags.map((flag) => `&flags=${flag}`).join('')}`).then((_) => _.value); | ||
/** | ||
* Retrieves the raw value (as seen in Flagsmith) for {@param flag}. | ||
*/ | ||
this.getFlagValue = async (flag) => this.request(`flag/${flag}/raw`).then((_) => _.value); | ||
/** | ||
* Retrieves a mapping of all flags (in Flagsmith) to their raw value. | ||
*/ | ||
this.getAllFlags = async () => this.request('flags/all').then((_) => _.value); | ||
this.request = (path) => (0, cross_fetch_1.default)(`${this.endpoint}/${path}`, { | ||
this.request = (path) => fetch(`${this.endpoint}/${path}`, { | ||
method: 'GET', | ||
@@ -52,3 +34,2 @@ headers: { | ||
} | ||
exports.default = Flags; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@indigov/flags-api", | ||
"version": "0.0.13", | ||
"version": "0.0.15", | ||
"description": "Strongly typed React/Node client for the Flags service", | ||
@@ -9,3 +9,4 @@ "main": "dist/index.js", | ||
"test": "jest", | ||
"prepublishOnly": "rm -rf dist && tsc -p ." | ||
"lint": "eslint ", | ||
"prepublishOnly": "rm -rf dist && tsc" | ||
}, | ||
@@ -17,10 +18,5 @@ "author": "faizan@indigov.com", | ||
}, | ||
"devDependencies": { | ||
"@tsconfig/node16": "^1.0.2", | ||
"@types/node": "^17.0.23", | ||
"dotenv": "^16.0.0", | ||
"jest": "^27.5.1", | ||
"ts-jest": "^27.1.4", | ||
"typescript": "^4.6.3" | ||
"engines": { | ||
"node": ">=16.13.1" | ||
} | ||
} |
@@ -8,7 +8,2 @@ # F.L.A.G.S. API Client | ||
### Installation | ||
npm: | ||
```shell | ||
npm i @indigov/flags-api | ||
``` | ||
yarn: | ||
@@ -23,3 +18,3 @@ ```shell | ||
const flags = new Flags('API_TOKEN', 'OFFICE_NAME', 'SOURCE_OF_REQUEST') | ||
const flags = new Flags('API_TOKEN', 'OFFICE_OR_COHORT_NAME', 'SOURCE_OF_REQUEST') | ||
// e.g. | ||
@@ -36,3 +31,3 @@ flags = new Flags('435234sdfgswdasdf', 'indigovstaging', 'northstar') | ||
```ts | ||
// Uses office supplied in instanttiation | ||
// Uses office or cohort supplied in instanttiation | ||
flags.getFlag('bulkapi:flags:minifiedhtmlenabled').then(console.log) | ||
@@ -47,8 +42,5 @@ // Overrriding office | ||
## Local Development | ||
TODO | ||
TODO | ||
Maybe use `ts-node-script` | ||
## Testing | ||
Tests are pending. | ||
Tests are run using `jest` backed by `ts-jest` to avoid the need for transpilation. | ||
@@ -61,8 +53,10 @@ | ||
## Publishing | ||
Bump the version in `package.json` then run: | ||
Run: | ||
```shell | ||
npm publish | ||
yarn publish | ||
``` | ||
And pick a sensible SemVer. | ||
Note: You must be logged into `npm` through the CLI and part of the Indigov org. | ||
@@ -1,2 +0,2 @@ | ||
import Flags from '../' | ||
import Flags from '../index' | ||
@@ -3,0 +3,0 @@ // Tests require Flags lambda to be running locally |
@@ -45,16 +45,15 @@ import fetch from 'cross-fetch' | ||
/** | ||
* Retrieves a boolean value for {@param flag} if it follows our standard schema (see Flags repo) | ||
* Retrieves a boolean value for {@param flag} for an office or cohort if it follows our standard schema (see Flags repo) | ||
*/ | ||
public getFlag = async (flag: string): Promise<GetFlagResponse> => | ||
(await this.request<GetFlagResponse>(`flag/${flag}`)).value | ||
public getFlag = async (flag: Flag): Promise<GetFlagResponse> => (await this.request<GetFlagResponse>(`flag/${flag}`)).value | ||
/** | ||
* Retrieves boolean values for {@param flags} if they follow our standard schema (see Flags repo) | ||
* Retrieves boolean values for {@param flags} for an office or cohort if they follow our standard schema (see Flags repo) | ||
* @param flags | ||
*/ | ||
public getFlags = async (flags: string[]): Promise<GetFlagsResponse> => | ||
public getFlags = async (flags: Flag[]): Promise<GetFlagsResponse> => | ||
this.request<GetFlagsResponse>(`flags?${flags.map((flag) => `&flags=${flag}`).join('')}`).then((_) => _.value) | ||
/** | ||
* Retrieves the raw value (as seen in Flagsmith) for {@param flag}. | ||
* Retrieves the raw value (as seen in Flagsmith) for {@param flag} for an office or cohort. | ||
*/ | ||
@@ -61,0 +60,0 @@ public getFlagValue = async (flag: string): Promise<GetFlagValueResponse> => this.request<GetFlagValueResponse>(`flag/${flag}/raw`).then((_) => _.value) |
{ | ||
"extends": "@tsconfig/node16/tsconfig.json", | ||
"extends": "../tsconfig.packages.json", | ||
"include": ["src/**/*"], | ||
@@ -4,0 +4,0 @@ "compilerOptions": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
0
12612
14
191
58
1