Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions client/client.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,57 @@ const getTreatmentsWithConfig = async (req, res) => {
}
};

/**
* getTreatmentsByFlagSets evaluates an array of flag sets and returns configs also
* @param {*} req
* @param {*} res
*/
const getTreatmentsByFlagSets = async (req, res) => {
const client = environmentManager.getClient(req.headers.authorization);
const key = parseKey(req.splitio.matchingKey, req.splitio.bucketingKey);
const flagSets = req.splitio.flagSetNames;
const attributes = req.splitio.attributes;

try {
const evaluationResults = await client.getTreatmentsByFlagSets(key, flagSets, attributes);
environmentManager.updateLastEvaluation(req.headers.authorization);

const result = {};
Object.keys(evaluationResults).forEach(featureFlag => {
result[featureFlag] = {
treatment: evaluationResults[featureFlag],
};
});

res.send(result);
} catch (error) {
res.status(500).send({error});
}
};

/**
* getTreatmentsWithConfigByFlagSets evaluates an array of flag sets
* @param {*} req
* @param {*} res
*/
const getTreatmentsWithConfigByFlagSets = async (req, res) => {
const client = environmentManager.getClient(req.headers.authorization);
const key = parseKey(req.splitio.matchingKey, req.splitio.bucketingKey);
const flagSets = req.splitio.flagSetNames;
const attributes = req.splitio.attributes;

try {
const evaluationResults = await client.getTreatmentsWithConfigByFlagSets(key, flagSets, attributes);
environmentManager.updateLastEvaluation(req.headers.authorization);

const result = evaluationResults;

res.send(result);
} catch (error) {
res.status(500).send({error});
}
};

/**
* track events tracking
* @param {*} req
Expand Down Expand Up @@ -205,6 +256,8 @@ module.exports = {
getTreatments,
getTreatmentWithConfig,
getTreatmentsWithConfig,
getTreatmentsByFlagSets,
getTreatmentsWithConfigByFlagSets,
getAllTreatments,
getAllTreatmentsWithConfig,
track,
Expand Down
37 changes: 37 additions & 0 deletions client/client.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const express = require('express');
const router = express.Router();
const keyValidator = require('../utils/inputValidation/key');
const splitValidator = require('../utils/inputValidation/split');
const flagSetValidator = require('../utils/inputValidation/flagSet');
const splitsValidator = require('../utils/inputValidation/splits');
const attributesValidator = require('../utils/inputValidation/attributes');
const trafficTypeValidator = require('../utils/inputValidation/trafficType');
Expand Down Expand Up @@ -76,6 +77,38 @@ const treatmentsValidation = (req, res, next) => {
next();
};

/**
* flagSetsValidation performs input validation for flag sets call.
* @param {object} req
* @param {object} res
* @param {function} next
*/
const flagSetsValidation = (req, res, next) => {
const matchingKeyValidation = keyValidator(req.query.key, 'key');
const bucketingKeyValidation = req.query['bucketing-key'] !== undefined ? keyValidator(req.query['bucketing-key'], 'bucketing-key') : null;
const flagSetNameValidation = flagSetValidator(req.query['set-names']);
const attributesValidation = attributesValidator(req.query.attributes);

const error = parseValidators([matchingKeyValidation, bucketingKeyValidation, flagSetNameValidation, attributesValidation]);
if (error.length) {
return res
.status(400)
.send({
error,
});
} else {
req.splitio = {
matchingKey: matchingKeyValidation.value,
flagSetNames: flagSetNameValidation.value,
attributes: attributesValidation.value,
};

if (bucketingKeyValidation && bucketingKeyValidation.valid) req.splitio.bucketingKey = bucketingKeyValidation.value;
}

next();
};

/**
* trackValidation performs input validation for event tracking calls.
* @param {object} req
Expand Down Expand Up @@ -161,6 +194,8 @@ router.get('/get-treatment', treatmentValidation, clientController.getTreatment)
router.get('/get-treatment-with-config', treatmentValidation, clientController.getTreatmentWithConfig);
router.get('/get-treatments', treatmentsValidation, clientController.getTreatments);
router.get('/get-treatments-with-config', treatmentsValidation, clientController.getTreatmentsWithConfig);
router.get('/get-treatments-by-sets', flagSetsValidation, clientController.getTreatmentsByFlagSets);
router.get('/get-treatments-with-config-by-sets', flagSetsValidation, clientController.getTreatmentsWithConfigByFlagSets);
router.get('/get-all-treatments', allTreatmentValidation, clientController.getAllTreatments);
router.get('/get-all-treatments-with-config', allTreatmentValidation, clientController.getAllTreatmentsWithConfig);

Expand All @@ -170,6 +205,8 @@ router.post('/get-treatment',express.json(JSON_PARSE_OPTS), fwdAttributesFromPos
router.post('/get-treatment-with-config', express.json(JSON_PARSE_OPTS), fwdAttributesFromPost, handleBodyParserErr, treatmentValidation, clientController.getTreatmentWithConfig);
router.post('/get-treatments', express.json(JSON_PARSE_OPTS), fwdAttributesFromPost, handleBodyParserErr, treatmentsValidation, clientController.getTreatments);
router.post('/get-treatments-with-config', express.json(JSON_PARSE_OPTS), fwdAttributesFromPost, handleBodyParserErr, treatmentsValidation, clientController.getTreatmentsWithConfig);
router.post('/get-treatments-by-sets', express.json(JSON_PARSE_OPTS), fwdAttributesFromPost, handleBodyParserErr, flagSetsValidation, clientController.getTreatmentsByFlagSets);
router.post('/get-treatments-with-config-by-sets', express.json(JSON_PARSE_OPTS), fwdAttributesFromPost, handleBodyParserErr, flagSetsValidation, clientController.getTreatmentsWithConfigByFlagSets);
router.post('/get-all-treatments', express.json(JSON_PARSE_OPTS), fwdAttributesFromPost, handleBodyParserErr, allTreatmentValidation, clientController.getAllTreatments);
router.post('/get-all-treatments-with-config', express.json(JSON_PARSE_OPTS), fwdAttributesFromPost, handleBodyParserErr, allTreatmentValidation, clientController.getAllTreatmentsWithConfig);

Expand Down
168 changes: 168 additions & 0 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ components:
type: string
description: The name of the feature flags you want to include in the evaluation.
example: SPLIT_NAME1,SPLIT_NAME2,SPLIT_NAME3
set-names:
in: query
name: set-names
required: true
schema:
type: string
description: The name of the flag sets you want to include in the evaluation.
example: set_a,set_b,set_c
bucketing-key:
in: query
name: bucketing-key
Expand Down Expand Up @@ -114,6 +122,14 @@ components:
items:
type: string
example: ["you passed a null or undefined split-name, split-name must be a non-empty string."]
InputValidationSets:
type: object
properties:
error:
type: array
items:
type: string
example: ["you passed a null or undefined set-names, set-names must be a non-empty string."]
Unauthorized:
type: object
properties:
Expand Down Expand Up @@ -479,6 +495,158 @@ paths:
$ref: '#/components/schemas/Unauthorized'
'500':
description: Internal server error
/client/get-treatments-by-sets:
get:
tags:
- client
summary: performs multiple evaluation at once by sets
description: Calls getTreatmentsByFlagSets method from the SDK.
parameters:
- $ref: '#/components/parameters/key'
- $ref: '#/components/parameters/set-names'
- $ref: '#/components/parameters/bucketing-key'
- $ref: '#/components/parameters/attributes'
responses:
'200':
description: Evaluation result
content:
application/json:
schema:
type: object
example:
'split-name':
treatment: on
'split-name-2':
treatment: off
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/InputValidationSets'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/Unauthorized'
'500':
description: Internal server error
post:
tags:
- client
summary: performs multiple evaluation at once by sets, but receiving the attributes on the request body.
description: Calls getTreatmentsByFlagSets method from the SDK.
parameters:
- $ref: '#/components/parameters/key'
- $ref: '#/components/parameters/set-names'
- $ref: '#/components/parameters/bucketing-key'
requestBody:
$ref: '#/components/requestBodies/EvaluationRequestBody'
responses:
'200':
description: Evaluation result
content:
application/json:
schema:
type: object
example:
'split-name':
treatment: on
'split-name-2':
treatment: off
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/InputValidationSets'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/Unauthorized'
'500':
description: Internal server error
/client/get-treatments-with-config-by-sets:
get:
tags:
- client
summary: performs multiple evaluation by sets at once and attachs config
description: Calls getTreatmentsWithConfigBySets method from the SDK.
parameters:
- $ref: '#/components/parameters/key'
- $ref: '#/components/parameters/set-names'
- $ref: '#/components/parameters/bucketing-key'
- $ref: '#/components/parameters/attributes'
responses:
'200':
description: Evaluation result
content:
application/json:
schema:
type: object
example:
'split-name':
treatment: on
config: "{\"color\": \"on\" }"
'split-name-2':
treatment: off
config: "{\"color\": \"off\" }"
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/InputValidationSets'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/Unauthorized'
'500':
description: Internal server error
post:
tags:
- client
summary: performs multiple evaluation by sets at once and attachs config, but receiving the attributes on the request body.
description: Calls getTreatmentsWithConfigBySets method from the SDK.
parameters:
- $ref: '#/components/parameters/key'
- $ref: '#/components/parameters/set-names'
- $ref: '#/components/parameters/bucketing-key'
requestBody:
$ref: '#/components/requestBodies/EvaluationRequestBody'
responses:
'200':
description: Evaluation result
content:
application/json:
schema:
type: object
example:
'my-split':
treatment: on
config: null
'my-split2':
treatment: off
config: "{\"color\": \"blue\" }"
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/InputValidationSets'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/Unauthorized'
'500':
description: Internal server error
/client/get-all-treatments:
get:
tags:
Expand Down
Loading