flagsmith-nodejs 2.0.0-beta.4 → 2.0.0-beta.7
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/pull_request.yaml +37 -29
- package/.idea/flagsmith-nodejs-client.iml +12 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/README.md +7 -0
- package/build/flagsmith-engine/environments/integrations/models.d.ts +4 -0
- package/build/flagsmith-engine/environments/integrations/models.js +11 -0
- package/build/flagsmith-engine/environments/models.d.ts +25 -0
- package/build/flagsmith-engine/environments/models.js +29 -0
- package/build/flagsmith-engine/environments/util.d.ts +3 -0
- package/build/flagsmith-engine/environments/util.js +21 -0
- package/build/flagsmith-engine/features/constants.d.ts +4 -0
- package/build/flagsmith-engine/features/constants.js +7 -0
- package/build/flagsmith-engine/features/models.d.ts +31 -0
- package/build/flagsmith-engine/features/models.js +99 -0
- package/build/flagsmith-engine/features/util.d.ts +3 -0
- package/build/flagsmith-engine/features/util.js +20 -0
- package/build/flagsmith-engine/identities/models.d.ts +15 -0
- package/build/flagsmith-engine/identities/models.js +112 -0
- package/build/flagsmith-engine/identities/traits/models.d.ts +5 -0
- package/build/flagsmith-engine/identities/traits/models.js +11 -0
- package/build/flagsmith-engine/identities/util.d.ts +4 -0
- package/build/flagsmith-engine/identities/util.js +46 -0
- package/build/flagsmith-engine/index.d.ts +8 -0
- package/build/flagsmith-engine/index.js +113 -0
- package/build/flagsmith-engine/organisations/models.d.ts +9 -0
- package/build/flagsmith-engine/organisations/models.js +21 -0
- package/build/flagsmith-engine/organisations/util.d.ts +2 -0
- package/build/flagsmith-engine/organisations/util.js +8 -0
- package/build/flagsmith-engine/projects/models.d.ts +10 -0
- package/build/flagsmith-engine/projects/models.js +14 -0
- package/build/flagsmith-engine/projects/util.d.ts +2 -0
- package/build/flagsmith-engine/projects/util.js +15 -0
- package/build/flagsmith-engine/segments/constants.d.ts +26 -0
- package/build/flagsmith-engine/segments/constants.js +31 -0
- package/build/flagsmith-engine/segments/evaluators.d.ts +6 -0
- package/build/flagsmith-engine/segments/evaluators.js +37 -0
- package/build/flagsmith-engine/segments/models.d.ts +31 -0
- package/build/flagsmith-engine/segments/models.js +89 -0
- package/build/flagsmith-engine/segments/util.d.ts +4 -0
- package/build/flagsmith-engine/segments/util.js +25 -0
- package/build/flagsmith-engine/utils/collections.d.ts +3 -0
- package/build/flagsmith-engine/utils/collections.js +26 -0
- package/build/flagsmith-engine/utils/errors.d.ts +2 -0
- package/build/flagsmith-engine/utils/errors.js +26 -0
- package/build/flagsmith-engine/utils/hashing/index.d.ts +9 -0
- package/build/flagsmith-engine/utils/hashing/index.js +60 -0
- package/build/flagsmith-engine/utils/index.d.ts +1 -0
- package/build/flagsmith-engine/utils/index.js +14 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +11 -0
- package/build/sdk/analytics.d.ts +28 -0
- package/build/sdk/analytics.js +102 -0
- package/build/sdk/errors.d.ts +4 -0
- package/build/sdk/errors.js +34 -0
- package/build/sdk/index.d.ts +123 -0
- package/build/sdk/index.js +484 -0
- package/build/sdk/models.d.ts +55 -0
- package/build/sdk/models.js +149 -0
- package/build/sdk/polling_manager.d.ts +9 -0
- package/build/sdk/polling_manager.js +72 -0
- package/build/sdk/types.d.ts +7 -0
- package/build/sdk/types.js +2 -0
- package/build/sdk/utils.d.ts +12 -0
- package/build/sdk/utils.js +94 -0
- package/example/package-lock.json +1 -996
- package/flagsmith-engine/features/models.ts +0 -4
- package/flagsmith-engine/identities/models.ts +1 -1
- package/flagsmith-engine/index.ts +1 -1
- package/flagsmith-engine/organisations/models.ts +1 -1
- package/flagsmith-engine/segments/models.ts +0 -2
- package/flagsmith-engine/utils/collections.ts +1 -12
- package/flagsmith-engine/utils/hashing/index.ts +5 -2
- package/package.json +3 -2
- package/sdk/analytics.ts +0 -2
- package/sdk/index.ts +83 -26
- package/sdk/polling_manager.ts +0 -1
- package/sdk/types.ts +8 -0
- package/tests/engine/unit/{egine.test.ts → engine.test.ts} +20 -0
- package/tests/engine/unit/features/models.test.ts +7 -3
- package/tests/engine/unit/identities/identities_builders.test.ts +13 -0
- package/tests/engine/unit/identities/identities_models.test.ts +3 -14
- package/tests/engine/unit/organization/models.test.ts +1 -1
- package/tests/engine/unit/segments/segments_model.test.ts +2 -1
- package/tests/engine/unit/utils.ts +1 -1
- package/tests/sdk/analytics.test.ts +11 -0
- package/tests/sdk/flagsmith-cache.test.ts +150 -0
- package/tests/sdk/flagsmith-environment-flags.test.ts +197 -0
- package/tests/sdk/flagsmith-identity-flags.test.ts +140 -0
- package/tests/sdk/flagsmith.test.ts +100 -85
- package/tests/sdk/polling.test.ts +25 -0
- package/tests/sdk/utils.ts +21 -2
- package/tsconfig.json +2 -1
- package/.tool-versions +0 -1
- package/tests/engine/engine-tests/engine-test-data/data/environment_n9fbf9h3v4fFgH3U3ngWhb.json +0 -12393
- package/tests/engine/engine-tests/engine-test-data/readme.md +0 -30
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.EnvironmentDataPollingManager = void 0;
|
|
40
|
+
var EnvironmentDataPollingManager = /** @class */ (function () {
|
|
41
|
+
function EnvironmentDataPollingManager(main, refreshIntervalSeconds) {
|
|
42
|
+
this.main = main;
|
|
43
|
+
this.refreshIntervalSeconds = refreshIntervalSeconds;
|
|
44
|
+
}
|
|
45
|
+
EnvironmentDataPollingManager.prototype.start = function () {
|
|
46
|
+
var _this = this;
|
|
47
|
+
var updateEnvironment = function () {
|
|
48
|
+
if (_this.interval)
|
|
49
|
+
clearInterval(_this.interval);
|
|
50
|
+
_this.interval = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
51
|
+
return __generator(this, function (_a) {
|
|
52
|
+
switch (_a.label) {
|
|
53
|
+
case 0: return [4 /*yield*/, this.main.updateEnvironment()];
|
|
54
|
+
case 1:
|
|
55
|
+
_a.sent();
|
|
56
|
+
return [2 /*return*/];
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}); }, _this.refreshIntervalSeconds * 1000);
|
|
60
|
+
};
|
|
61
|
+
this.main.updateEnvironment();
|
|
62
|
+
updateEnvironment();
|
|
63
|
+
};
|
|
64
|
+
EnvironmentDataPollingManager.prototype.stop = function () {
|
|
65
|
+
if (!this.interval) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
clearInterval(this.interval);
|
|
69
|
+
};
|
|
70
|
+
return EnvironmentDataPollingManager;
|
|
71
|
+
}());
|
|
72
|
+
exports.EnvironmentDataPollingManager = EnvironmentDataPollingManager;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Response } from 'node-fetch';
|
|
2
|
+
export declare function generateIdentitiesData(identifier: string, traits?: {
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
}): {
|
|
5
|
+
identifier: string;
|
|
6
|
+
traits: {
|
|
7
|
+
trait_key: string;
|
|
8
|
+
trait_value: any;
|
|
9
|
+
}[];
|
|
10
|
+
};
|
|
11
|
+
export declare const delay: (ms: number) => Promise<unknown>;
|
|
12
|
+
export declare const retryFetch: (url: string, fetchOptions: {} | undefined, retries: number | undefined, retryDelay: number | undefined, timeout: number) => Promise<Response>;
|
|
@@ -0,0 +1,94 @@
|
|
|
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.retryFetch = exports.delay = exports.generateIdentitiesData = void 0;
|
|
43
|
+
var node_fetch_1 = __importDefault(require("node-fetch"));
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
if (typeof node_fetch_1.default.default !== 'undefined')
|
|
46
|
+
node_fetch_1.default = node_fetch_1.default.default;
|
|
47
|
+
function generateIdentitiesData(identifier, traits) {
|
|
48
|
+
var traitsGenerated = Object.entries(traits || {}).map(function (trait) { return ({
|
|
49
|
+
trait_key: trait[0],
|
|
50
|
+
trait_value: trait[1]
|
|
51
|
+
}); });
|
|
52
|
+
return {
|
|
53
|
+
identifier: identifier,
|
|
54
|
+
traits: traitsGenerated
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
exports.generateIdentitiesData = generateIdentitiesData;
|
|
58
|
+
var delay = function (ms) {
|
|
59
|
+
return new Promise(function (resolve) { return setTimeout(function () { return resolve(undefined); }, ms); });
|
|
60
|
+
};
|
|
61
|
+
exports.delay = delay;
|
|
62
|
+
var retryFetch = function (url, fetchOptions, retries, retryDelay, timeout) {
|
|
63
|
+
if (fetchOptions === void 0) { fetchOptions = {}; }
|
|
64
|
+
if (retries === void 0) { retries = 3; }
|
|
65
|
+
if (retryDelay === void 0) { retryDelay = 1000; }
|
|
66
|
+
return new Promise(function (resolve, reject) {
|
|
67
|
+
// check for timeout
|
|
68
|
+
if (timeout)
|
|
69
|
+
setTimeout(function () { return reject('error: timeout'); }, timeout);
|
|
70
|
+
var wrapper = function (n) {
|
|
71
|
+
(0, node_fetch_1.default)(url, fetchOptions)
|
|
72
|
+
.then(function (res) { return resolve(res); })
|
|
73
|
+
.catch(function (err) { return __awaiter(void 0, void 0, void 0, function () {
|
|
74
|
+
return __generator(this, function (_a) {
|
|
75
|
+
switch (_a.label) {
|
|
76
|
+
case 0:
|
|
77
|
+
if (!(n > 0)) return [3 /*break*/, 2];
|
|
78
|
+
return [4 /*yield*/, (0, exports.delay)(retryDelay)];
|
|
79
|
+
case 1:
|
|
80
|
+
_a.sent();
|
|
81
|
+
wrapper(--n);
|
|
82
|
+
return [3 /*break*/, 3];
|
|
83
|
+
case 2:
|
|
84
|
+
reject(err);
|
|
85
|
+
_a.label = 3;
|
|
86
|
+
case 3: return [2 /*return*/];
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}); });
|
|
90
|
+
};
|
|
91
|
+
wrapper(retries);
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
exports.retryFetch = retryFetch;
|