flagsmith-nodejs 2.5.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +25 -0
- package/examples/README.md +3 -0
- package/flagsmith-engine/identities/models.ts +3 -1
- package/flagsmith-engine/segments/evaluators.ts +4 -3
- package/package.json +1 -1
- package/tests/engine/unit/segments/segment_evaluators.test.ts +46 -6
- package/.vscode/launch.json +0 -18
- package/build/flagsmith-engine/environments/integrations/models.d.ts +0 -4
- package/build/flagsmith-engine/environments/integrations/models.js +0 -11
- package/build/flagsmith-engine/environments/models.d.ts +0 -25
- package/build/flagsmith-engine/environments/models.js +0 -29
- package/build/flagsmith-engine/environments/util.d.ts +0 -3
- package/build/flagsmith-engine/environments/util.js +0 -21
- package/build/flagsmith-engine/features/constants.d.ts +0 -4
- package/build/flagsmith-engine/features/constants.js +0 -7
- package/build/flagsmith-engine/features/models.d.ts +0 -37
- package/build/flagsmith-engine/features/models.js +0 -122
- package/build/flagsmith-engine/features/util.d.ts +0 -4
- package/build/flagsmith-engine/features/util.js +0 -27
- package/build/flagsmith-engine/identities/models.d.ts +0 -15
- package/build/flagsmith-engine/identities/models.js +0 -112
- package/build/flagsmith-engine/identities/traits/models.d.ts +0 -5
- package/build/flagsmith-engine/identities/traits/models.js +0 -11
- package/build/flagsmith-engine/identities/util.d.ts +0 -4
- package/build/flagsmith-engine/identities/util.js +0 -46
- package/build/flagsmith-engine/index.d.ts +0 -15
- package/build/flagsmith-engine/index.js +0 -129
- package/build/flagsmith-engine/organisations/models.d.ts +0 -9
- package/build/flagsmith-engine/organisations/models.js +0 -21
- package/build/flagsmith-engine/organisations/util.d.ts +0 -2
- package/build/flagsmith-engine/organisations/util.js +0 -8
- package/build/flagsmith-engine/projects/models.d.ts +0 -10
- package/build/flagsmith-engine/projects/models.js +0 -14
- package/build/flagsmith-engine/projects/util.d.ts +0 -2
- package/build/flagsmith-engine/projects/util.js +0 -15
- package/build/flagsmith-engine/segments/constants.d.ts +0 -34
- package/build/flagsmith-engine/segments/constants.js +0 -39
- package/build/flagsmith-engine/segments/evaluators.d.ts +0 -7
- package/build/flagsmith-engine/segments/evaluators.js +0 -44
- package/build/flagsmith-engine/segments/models.d.ts +0 -37
- package/build/flagsmith-engine/segments/models.js +0 -144
- package/build/flagsmith-engine/segments/util.d.ts +0 -6
- package/build/flagsmith-engine/segments/util.js +0 -33
- package/build/flagsmith-engine/utils/collections.d.ts +0 -3
- package/build/flagsmith-engine/utils/collections.js +0 -26
- package/build/flagsmith-engine/utils/errors.d.ts +0 -2
- package/build/flagsmith-engine/utils/errors.js +0 -26
- package/build/flagsmith-engine/utils/hashing/index.d.ts +0 -9
- package/build/flagsmith-engine/utils/hashing/index.js +0 -60
- package/build/flagsmith-engine/utils/index.d.ts +0 -1
- package/build/flagsmith-engine/utils/index.js +0 -17
- package/build/index.d.ts +0 -2
- package/build/index.js +0 -24
- package/build/sdk/analytics.d.ts +0 -31
- package/build/sdk/analytics.js +0 -116
- package/build/sdk/errors.d.ts +0 -4
- package/build/sdk/errors.js +0 -34
- package/build/sdk/index.d.ts +0 -120
- package/build/sdk/index.js +0 -527
- package/build/sdk/models.d.ts +0 -55
- package/build/sdk/models.js +0 -149
- package/build/sdk/polling_manager.d.ts +0 -9
- package/build/sdk/polling_manager.js +0 -72
- package/build/sdk/types.d.ts +0 -27
- package/build/sdk/types.js +0 -2
- package/build/sdk/utils.d.ts +0 -12
- package/build/sdk/utils.js +0 -99
- package/examples/api-proxy/.babelrc +0 -3
- package/examples/api-proxy/.eslintrc +0 -8
- package/examples/api-proxy/README.md +0 -12
- package/examples/api-proxy/package-lock.json +0 -10889
- package/examples/api-proxy/package.json +0 -57
- package/examples/api-proxy/src/api/index.js +0 -42
- package/examples/api-proxy/src/index.js +0 -29
- package/examples/basic/.babelrc +0 -3
- package/examples/basic/.eslintrc +0 -8
- package/examples/basic/README.md +0 -10
- package/examples/basic/package-lock.json +0 -10779
- package/examples/basic/package.json +0 -56
- package/examples/basic/src/api/index.js +0 -33
- package/examples/basic/src/index.js +0 -29
- package/examples/caching/.babelrc +0 -3
- package/examples/caching/.eslintrc +0 -8
- package/examples/caching/README.md +0 -9
- package/examples/caching/package-lock.json +0 -6750
- package/examples/caching/package.json +0 -56
- package/examples/caching/src/api/index.js +0 -38
- package/examples/caching/src/index.js +0 -29
- package/examples/custom-fetch-agent/.babelrc +0 -3
- package/examples/custom-fetch-agent/.eslintrc +0 -8
- package/examples/custom-fetch-agent/README.md +0 -12
- package/examples/custom-fetch-agent/package-lock.json +0 -6750
- package/examples/custom-fetch-agent/package.json +0 -56
- package/examples/custom-fetch-agent/src/api/index.js +0 -34
- package/examples/custom-fetch-agent/src/index.js +0 -29
- package/examples/local-evaluation/.babelrc +0 -3
- package/examples/local-evaluation/.eslintrc +0 -8
- package/examples/local-evaluation/README.md +0 -18
- package/examples/local-evaluation/package-lock.json +0 -6668
- package/examples/local-evaluation/package.json +0 -56
- package/examples/local-evaluation/src/api/index.js +0 -39
- package/examples/local-evaluation/src/index.js +0 -29
- package/tests/engine/engine-tests/engine-test-data/data/environment_n9fbf9h3v4fFgH3U3ngWhb.json +0 -12591
- package/tests/engine/engine-tests/engine-test-data/readme.md +0 -30
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.IdentityFeaturesList = void 0;
|
|
19
|
-
var IdentityFeaturesList = /** @class */ (function (_super) {
|
|
20
|
-
__extends(IdentityFeaturesList, _super);
|
|
21
|
-
function IdentityFeaturesList() {
|
|
22
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
23
|
-
}
|
|
24
|
-
return IdentityFeaturesList;
|
|
25
|
-
}(Array));
|
|
26
|
-
exports.IdentityFeaturesList = IdentityFeaturesList;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.FeatureStateNotFound = void 0;
|
|
19
|
-
var FeatureStateNotFound = /** @class */ (function (_super) {
|
|
20
|
-
__extends(FeatureStateNotFound, _super);
|
|
21
|
-
function FeatureStateNotFound() {
|
|
22
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
23
|
-
}
|
|
24
|
-
return FeatureStateNotFound;
|
|
25
|
-
}(Error));
|
|
26
|
-
exports.FeatureStateNotFound = FeatureStateNotFound;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Given a list of object ids, get a floating point number between 0 and 1 based on
|
|
3
|
-
* the hash of those ids. This should give the same value every time for any list of ids.
|
|
4
|
-
*
|
|
5
|
-
* @param {Array<any>} objectIds list of object ids to calculate the has for
|
|
6
|
-
* @param {} iterations=1 num times to include each id in the generated string to hash
|
|
7
|
-
* @returns number number between 0 (inclusive) and 100 (exclusive)
|
|
8
|
-
*/
|
|
9
|
-
export declare function getHashedPercentateForObjIds(objectIds: Array<any>, iterations?: number): number;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getHashedPercentateForObjIds = void 0;
|
|
7
|
-
var md5_1 = __importDefault(require("md5"));
|
|
8
|
-
var big_integer_1 = __importDefault(require("big-integer"));
|
|
9
|
-
var makeRepeated = function (arr, repeats) {
|
|
10
|
-
return Array.from({ length: repeats }, function () { return arr; }).flat();
|
|
11
|
-
};
|
|
12
|
-
// https://stackoverflow.com/questions/12532871/how-to-convert-a-very-large-hex-number-to-decimal-in-javascript
|
|
13
|
-
function h2d(s) {
|
|
14
|
-
function add(x, y) {
|
|
15
|
-
var c = 0, r = [];
|
|
16
|
-
var x = x.split('').map(Number);
|
|
17
|
-
var y = y.split('').map(Number);
|
|
18
|
-
while (x.length || y.length) {
|
|
19
|
-
var s = (x.pop() || 0) + (y.pop() || 0) + c;
|
|
20
|
-
r.unshift(s < 10 ? s : s - 10);
|
|
21
|
-
c = s < 10 ? 0 : 1;
|
|
22
|
-
}
|
|
23
|
-
if (c)
|
|
24
|
-
r.unshift(c);
|
|
25
|
-
return r.join('');
|
|
26
|
-
}
|
|
27
|
-
var dec = '0';
|
|
28
|
-
s.split('').forEach(function (chr) {
|
|
29
|
-
var n = parseInt(chr, 16);
|
|
30
|
-
for (var t = 8; t; t >>= 1) {
|
|
31
|
-
dec = add(dec, dec);
|
|
32
|
-
if (n & t)
|
|
33
|
-
dec = add(dec, '1');
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
return dec;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Given a list of object ids, get a floating point number between 0 and 1 based on
|
|
40
|
-
* the hash of those ids. This should give the same value every time for any list of ids.
|
|
41
|
-
*
|
|
42
|
-
* @param {Array<any>} objectIds list of object ids to calculate the has for
|
|
43
|
-
* @param {} iterations=1 num times to include each id in the generated string to hash
|
|
44
|
-
* @returns number number between 0 (inclusive) and 100 (exclusive)
|
|
45
|
-
*/
|
|
46
|
-
function getHashedPercentateForObjIds(objectIds, iterations) {
|
|
47
|
-
if (iterations === void 0) { iterations = 1; }
|
|
48
|
-
var toHash = makeRepeated(objectIds, iterations).join(',');
|
|
49
|
-
var hashedValue = (0, md5_1.default)(toHash);
|
|
50
|
-
var hashedInt = (0, big_integer_1.default)(h2d(hashedValue));
|
|
51
|
-
var value = (hashedInt.mod(9999).toJSNumber() / 9998) * 100;
|
|
52
|
-
// we ignore this for it's nearly impossible use case to catch
|
|
53
|
-
/* istanbul ignore next */
|
|
54
|
-
if (value === 100) {
|
|
55
|
-
/* istanbul ignore next */
|
|
56
|
-
return getHashedPercentateForObjIds(objectIds, iterations + 1);
|
|
57
|
-
}
|
|
58
|
-
return value;
|
|
59
|
-
}
|
|
60
|
-
exports.getHashedPercentateForObjIds = getHashedPercentateForObjIds;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getCastingFunction(traitType: 'boolean' | 'string' | 'number' | 'semver' | any): CallableFunction;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCastingFunction = void 0;
|
|
4
|
-
var util_1 = require("../segments/util");
|
|
5
|
-
function getCastingFunction(traitType) {
|
|
6
|
-
switch (traitType) {
|
|
7
|
-
case 'boolean':
|
|
8
|
-
return function (x) { return !['False', 'false'].includes(x); };
|
|
9
|
-
case 'number':
|
|
10
|
-
return function (x) { return parseFloat(x); };
|
|
11
|
-
case 'semver':
|
|
12
|
-
return function (x) { return (0, util_1.removeSemverSuffix)(x); };
|
|
13
|
-
default:
|
|
14
|
-
return function (x) { return String(x); };
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.getCastingFunction = getCastingFunction;
|
package/build/index.d.ts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export { AnalyticsProcessor, FlagsmithAPIError, FlagsmithClientError, EnvironmentDataPollingManager, FlagsmithCache, DefaultFlag, Flags, default } from './sdk';
|
|
2
|
-
export { EnvironmentModel, IntegrationModel, FeatureStateModel, IdentityModel, TraitModel, SegmentModel, OrganisationModel } from './flagsmith-engine';
|
package/build/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.OrganisationModel = exports.SegmentModel = exports.TraitModel = exports.IdentityModel = exports.FeatureStateModel = exports.IntegrationModel = exports.EnvironmentModel = exports.default = exports.Flags = exports.DefaultFlag = exports.EnvironmentDataPollingManager = exports.FlagsmithClientError = exports.FlagsmithAPIError = exports.AnalyticsProcessor = void 0;
|
|
7
|
-
var sdk_1 = __importDefault(require("./sdk"));
|
|
8
|
-
var sdk_2 = require("./sdk");
|
|
9
|
-
Object.defineProperty(exports, "AnalyticsProcessor", { enumerable: true, get: function () { return sdk_2.AnalyticsProcessor; } });
|
|
10
|
-
Object.defineProperty(exports, "FlagsmithAPIError", { enumerable: true, get: function () { return sdk_2.FlagsmithAPIError; } });
|
|
11
|
-
Object.defineProperty(exports, "FlagsmithClientError", { enumerable: true, get: function () { return sdk_2.FlagsmithClientError; } });
|
|
12
|
-
Object.defineProperty(exports, "EnvironmentDataPollingManager", { enumerable: true, get: function () { return sdk_2.EnvironmentDataPollingManager; } });
|
|
13
|
-
Object.defineProperty(exports, "DefaultFlag", { enumerable: true, get: function () { return sdk_2.DefaultFlag; } });
|
|
14
|
-
Object.defineProperty(exports, "Flags", { enumerable: true, get: function () { return sdk_2.Flags; } });
|
|
15
|
-
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(sdk_2).default; } });
|
|
16
|
-
var flagsmith_engine_1 = require("./flagsmith-engine");
|
|
17
|
-
Object.defineProperty(exports, "EnvironmentModel", { enumerable: true, get: function () { return flagsmith_engine_1.EnvironmentModel; } });
|
|
18
|
-
Object.defineProperty(exports, "IntegrationModel", { enumerable: true, get: function () { return flagsmith_engine_1.IntegrationModel; } });
|
|
19
|
-
Object.defineProperty(exports, "FeatureStateModel", { enumerable: true, get: function () { return flagsmith_engine_1.FeatureStateModel; } });
|
|
20
|
-
Object.defineProperty(exports, "IdentityModel", { enumerable: true, get: function () { return flagsmith_engine_1.IdentityModel; } });
|
|
21
|
-
Object.defineProperty(exports, "TraitModel", { enumerable: true, get: function () { return flagsmith_engine_1.TraitModel; } });
|
|
22
|
-
Object.defineProperty(exports, "SegmentModel", { enumerable: true, get: function () { return flagsmith_engine_1.SegmentModel; } });
|
|
23
|
-
Object.defineProperty(exports, "OrganisationModel", { enumerable: true, get: function () { return flagsmith_engine_1.OrganisationModel; } });
|
|
24
|
-
module.exports = sdk_1.default;
|
package/build/sdk/analytics.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Logger } from 'pino';
|
|
2
|
-
export declare class AnalyticsProcessor {
|
|
3
|
-
private analyticsEndpoint;
|
|
4
|
-
private environmentKey;
|
|
5
|
-
private lastFlushed;
|
|
6
|
-
analyticsData: {
|
|
7
|
-
[key: string]: any;
|
|
8
|
-
};
|
|
9
|
-
private requestTimeoutMs;
|
|
10
|
-
private logger;
|
|
11
|
-
/**
|
|
12
|
-
* AnalyticsProcessor is used to track how often individual Flags are evaluated within
|
|
13
|
-
* the Flagsmith SDK. Docs: https://docs.flagsmith.com/advanced-use/flag-analytics.
|
|
14
|
-
*
|
|
15
|
-
* @param data.environmentKey environment key obtained from the Flagsmith UI
|
|
16
|
-
* @param data.baseApiUrl base api url to override when using self hosted version
|
|
17
|
-
* @param data.requestTimeoutMs used to tell requests to stop waiting for a response after a
|
|
18
|
-
given number of milliseconds
|
|
19
|
-
*/
|
|
20
|
-
constructor(data: {
|
|
21
|
-
environmentKey: string;
|
|
22
|
-
baseApiUrl: string;
|
|
23
|
-
requestTimeoutMs?: number;
|
|
24
|
-
logger?: Logger;
|
|
25
|
-
});
|
|
26
|
-
/**
|
|
27
|
-
* Sends all the collected data to the api asynchronously and resets the timer
|
|
28
|
-
*/
|
|
29
|
-
flush(): Promise<void>;
|
|
30
|
-
trackFeature(featureName: string): void;
|
|
31
|
-
}
|
package/build/sdk/analytics.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.AnalyticsProcessor = void 0;
|
|
43
|
-
var node_fetch_1 = __importDefault(require("node-fetch"));
|
|
44
|
-
var pino_1 = __importDefault(require("pino"));
|
|
45
|
-
var ANALYTICS_ENDPOINT = 'analytics/flags/';
|
|
46
|
-
// Used to control how often we send data(in seconds)
|
|
47
|
-
var ANALYTICS_TIMER = 10;
|
|
48
|
-
var AnalyticsProcessor = /** @class */ (function () {
|
|
49
|
-
/**
|
|
50
|
-
* AnalyticsProcessor is used to track how often individual Flags are evaluated within
|
|
51
|
-
* the Flagsmith SDK. Docs: https://docs.flagsmith.com/advanced-use/flag-analytics.
|
|
52
|
-
*
|
|
53
|
-
* @param data.environmentKey environment key obtained from the Flagsmith UI
|
|
54
|
-
* @param data.baseApiUrl base api url to override when using self hosted version
|
|
55
|
-
* @param data.requestTimeoutMs used to tell requests to stop waiting for a response after a
|
|
56
|
-
given number of milliseconds
|
|
57
|
-
*/
|
|
58
|
-
function AnalyticsProcessor(data) {
|
|
59
|
-
this.requestTimeoutMs = 3000;
|
|
60
|
-
this.analyticsEndpoint = data.baseApiUrl + ANALYTICS_ENDPOINT;
|
|
61
|
-
this.environmentKey = data.environmentKey;
|
|
62
|
-
this.lastFlushed = Date.now();
|
|
63
|
-
this.analyticsData = {};
|
|
64
|
-
this.requestTimeoutMs = data.requestTimeoutMs || this.requestTimeoutMs;
|
|
65
|
-
this.logger = data.logger || (0, pino_1.default)();
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Sends all the collected data to the api asynchronously and resets the timer
|
|
69
|
-
*/
|
|
70
|
-
AnalyticsProcessor.prototype.flush = function () {
|
|
71
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
72
|
-
var error_1;
|
|
73
|
-
return __generator(this, function (_a) {
|
|
74
|
-
switch (_a.label) {
|
|
75
|
-
case 0:
|
|
76
|
-
if (!Object.keys(this.analyticsData).length) {
|
|
77
|
-
return [2 /*return*/];
|
|
78
|
-
}
|
|
79
|
-
_a.label = 1;
|
|
80
|
-
case 1:
|
|
81
|
-
_a.trys.push([1, 3, , 4]);
|
|
82
|
-
return [4 /*yield*/, (0, node_fetch_1.default)(this.analyticsEndpoint, {
|
|
83
|
-
method: 'POST',
|
|
84
|
-
body: JSON.stringify(this.analyticsData),
|
|
85
|
-
timeout: this.requestTimeoutMs,
|
|
86
|
-
headers: {
|
|
87
|
-
'Content-Type': 'application/json',
|
|
88
|
-
'X-Environment-Key': this.environmentKey
|
|
89
|
-
}
|
|
90
|
-
})];
|
|
91
|
-
case 2:
|
|
92
|
-
_a.sent();
|
|
93
|
-
return [3 /*break*/, 4];
|
|
94
|
-
case 3:
|
|
95
|
-
error_1 = _a.sent();
|
|
96
|
-
// We don't want failing to write analytics to cause any exceptions in the main
|
|
97
|
-
// thread so we just swallow them here.
|
|
98
|
-
this.logger.warn('Failed to post analytics to Flagsmith API. Not clearing data, will retry.');
|
|
99
|
-
return [2 /*return*/];
|
|
100
|
-
case 4:
|
|
101
|
-
this.analyticsData = {};
|
|
102
|
-
this.lastFlushed = Date.now();
|
|
103
|
-
return [2 /*return*/];
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
AnalyticsProcessor.prototype.trackFeature = function (featureName) {
|
|
109
|
-
this.analyticsData[featureName] = (this.analyticsData[featureName] || 0) + 1;
|
|
110
|
-
if (Date.now() - this.lastFlushed > ANALYTICS_TIMER * 1000) {
|
|
111
|
-
this.flush();
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
return AnalyticsProcessor;
|
|
115
|
-
}());
|
|
116
|
-
exports.AnalyticsProcessor = AnalyticsProcessor;
|
package/build/sdk/errors.d.ts
DELETED
package/build/sdk/errors.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.FlagsmithAPIError = exports.FlagsmithClientError = void 0;
|
|
19
|
-
var FlagsmithClientError = /** @class */ (function (_super) {
|
|
20
|
-
__extends(FlagsmithClientError, _super);
|
|
21
|
-
function FlagsmithClientError() {
|
|
22
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
23
|
-
}
|
|
24
|
-
return FlagsmithClientError;
|
|
25
|
-
}(Error));
|
|
26
|
-
exports.FlagsmithClientError = FlagsmithClientError;
|
|
27
|
-
var FlagsmithAPIError = /** @class */ (function (_super) {
|
|
28
|
-
__extends(FlagsmithAPIError, _super);
|
|
29
|
-
function FlagsmithAPIError() {
|
|
30
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
31
|
-
}
|
|
32
|
-
return FlagsmithAPIError;
|
|
33
|
-
}(Error));
|
|
34
|
-
exports.FlagsmithAPIError = FlagsmithAPIError;
|
package/build/sdk/index.d.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { RequestInit } from "node-fetch";
|
|
2
|
-
import { EnvironmentModel } from '../flagsmith-engine/environments/models';
|
|
3
|
-
import { DefaultFlag, Flags } from './models';
|
|
4
|
-
import { EnvironmentDataPollingManager } from './polling_manager';
|
|
5
|
-
import { SegmentModel } from '../flagsmith-engine/segments/models';
|
|
6
|
-
import { FlagsmithConfig } from './types';
|
|
7
|
-
export { AnalyticsProcessor } from './analytics';
|
|
8
|
-
export { FlagsmithAPIError, FlagsmithClientError } from './errors';
|
|
9
|
-
export { DefaultFlag, Flags } from './models';
|
|
10
|
-
export { EnvironmentDataPollingManager } from './polling_manager';
|
|
11
|
-
export { FlagsmithCache, FlagsmithConfig } from './types';
|
|
12
|
-
export declare class Flagsmith {
|
|
13
|
-
environmentKey?: string;
|
|
14
|
-
apiUrl: string;
|
|
15
|
-
customHeaders?: {
|
|
16
|
-
[key: string]: any;
|
|
17
|
-
};
|
|
18
|
-
requestTimeoutSeconds?: number;
|
|
19
|
-
agent: RequestInit['agent'];
|
|
20
|
-
requestTimeoutMs?: number;
|
|
21
|
-
enableLocalEvaluation?: boolean;
|
|
22
|
-
environmentRefreshIntervalSeconds: number;
|
|
23
|
-
retries?: number;
|
|
24
|
-
enableAnalytics: boolean;
|
|
25
|
-
defaultFlagHandler?: (featureName: string) => DefaultFlag;
|
|
26
|
-
environmentFlagsUrl: string;
|
|
27
|
-
identitiesUrl: string;
|
|
28
|
-
environmentUrl: string;
|
|
29
|
-
environmentDataPollingManager?: EnvironmentDataPollingManager;
|
|
30
|
-
environment: EnvironmentModel;
|
|
31
|
-
private cache?;
|
|
32
|
-
private onEnvironmentChange?;
|
|
33
|
-
private analyticsProcessor?;
|
|
34
|
-
private logger;
|
|
35
|
-
/**
|
|
36
|
-
* A Flagsmith client.
|
|
37
|
-
*
|
|
38
|
-
* Provides an interface for interacting with the Flagsmith http API.
|
|
39
|
-
* Basic Usage::
|
|
40
|
-
*
|
|
41
|
-
* import flagsmith from Flagsmith
|
|
42
|
-
* const flagsmith = new Flagsmith({environmentKey: '<your API key>'});
|
|
43
|
-
* const environmentFlags = flagsmith.getEnvironmentFlags();
|
|
44
|
-
* const featureEnabled = environmentFlags.isFeatureEnabled('foo');
|
|
45
|
-
* const identityFlags = flagsmith.getIdentityFlags('identifier', {'foo': 'bar'});
|
|
46
|
-
* const featureEnabledForIdentity = identityFlags.isFeatureEnabled("foo")
|
|
47
|
-
*
|
|
48
|
-
* @param {string} data.environmentKey: The environment key obtained from Flagsmith interface
|
|
49
|
-
@param {string} data.apiUrl: Override the URL of the Flagsmith API to communicate with
|
|
50
|
-
@param data.customHeaders: Additional headers to add to requests made to the
|
|
51
|
-
Flagsmith API
|
|
52
|
-
@param {number} data.requestTimeoutSeconds: Number of seconds to wait for a request to
|
|
53
|
-
complete before terminating the request
|
|
54
|
-
@param {boolean} data.enableLocalEvaluation: Enables local evaluation of flags
|
|
55
|
-
@param {number} data.environmentRefreshIntervalSeconds: If using local evaluation,
|
|
56
|
-
specify the interval period between refreshes of local environment data
|
|
57
|
-
@param {number} data.retries: a urllib3.Retry object to use on all http requests to the
|
|
58
|
-
Flagsmith API
|
|
59
|
-
@param {boolean} data.enableAnalytics: if enabled, sends additional requests to the Flagsmith
|
|
60
|
-
API to power flag analytics charts
|
|
61
|
-
@param data.defaultFlagHandler: callable which will be used in the case where
|
|
62
|
-
flags cannot be retrieved from the API or a non existent feature is
|
|
63
|
-
requested
|
|
64
|
-
@param data.logger: an instance of the pino Logger class to use for logging
|
|
65
|
-
*/
|
|
66
|
-
constructor(data: FlagsmithConfig);
|
|
67
|
-
/**
|
|
68
|
-
* Get all the default for flags for the current environment.
|
|
69
|
-
*
|
|
70
|
-
* @returns Flags object holding all the flags for the current environment.
|
|
71
|
-
*/
|
|
72
|
-
getEnvironmentFlags(): Promise<Flags>;
|
|
73
|
-
/**
|
|
74
|
-
* Get all the flags for the current environment for a given identity. Will also
|
|
75
|
-
upsert all traits to the Flagsmith API for future evaluations. Providing a
|
|
76
|
-
trait with a value of None will remove the trait from the identity if it exists.
|
|
77
|
-
*
|
|
78
|
-
* @param {string} identifier a unique identifier for the identity in the current
|
|
79
|
-
environment, e.g. email address, username, uuid
|
|
80
|
-
* @param {{[key:string]:any}} traits? a dictionary of traits to add / update on the identity in
|
|
81
|
-
Flagsmith, e.g. {"num_orders": 10}
|
|
82
|
-
* @returns Flags object holding all the flags for the given identity.
|
|
83
|
-
*/
|
|
84
|
-
getIdentityFlags(identifier: string, traits?: {
|
|
85
|
-
[key: string]: any;
|
|
86
|
-
}): Promise<Flags>;
|
|
87
|
-
/**
|
|
88
|
-
* Get the segments for the current environment for a given identity. Will also
|
|
89
|
-
upsert all traits to the Flagsmith API for future evaluations. Providing a
|
|
90
|
-
trait with a value of None will remove the trait from the identity if it exists.
|
|
91
|
-
*
|
|
92
|
-
* @param {string} identifier a unique identifier for the identity in the current
|
|
93
|
-
environment, e.g. email address, username, uuid
|
|
94
|
-
* @param {{[key:string]:any}} traits? a dictionary of traits to add / update on the identity in
|
|
95
|
-
Flagsmith, e.g. {"num_orders": 10}
|
|
96
|
-
* @returns Segments that the given identity belongs to.
|
|
97
|
-
*/
|
|
98
|
-
getIdentitySegments(identifier: string, traits?: {
|
|
99
|
-
[key: string]: any;
|
|
100
|
-
}): Promise<SegmentModel[]>;
|
|
101
|
-
/**
|
|
102
|
-
* Updates the environment state for local flag evaluation.
|
|
103
|
-
* Sets a local promise to prevent race conditions in getIdentityFlags / getIdentitySegments.
|
|
104
|
-
* You only need to call this if you wish to bypass environmentRefreshIntervalSeconds.
|
|
105
|
-
*/
|
|
106
|
-
updateEnvironment(): Promise<void>;
|
|
107
|
-
close(): Promise<void>;
|
|
108
|
-
private getJSONResponse;
|
|
109
|
-
/**
|
|
110
|
-
* This promise ensures that the environment is retrieved before attempting to locally evaluate.
|
|
111
|
-
*/
|
|
112
|
-
private environmentPromise;
|
|
113
|
-
private getEnvironmentFromApi;
|
|
114
|
-
private getEnvironmentFlagsFromDocument;
|
|
115
|
-
private getIdentityFlagsFromDocument;
|
|
116
|
-
private getEnvironmentFlagsFromApi;
|
|
117
|
-
private getIdentityFlagsFromApi;
|
|
118
|
-
private buildIdentityModel;
|
|
119
|
-
}
|
|
120
|
-
export default Flagsmith;
|