@alanszp/split 7.8.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/.gitignore +3 -0
- package/.npmignore +3 -0
- package/.vscode/settings.json +3 -0
- package/LICENSE +21 -0
- package/dist/client/index.d.ts +17 -0
- package/dist/client/index.js +70 -0
- package/dist/client/index.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -0
- package/src/client/index.ts +98 -0
- package/src/index.ts +2 -0
- package/tsconfig.json +15 -0
package/.gitignore
ADDED
package/.npmignore
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Alan Szpigiel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ILogger } from "@alanszp/logger";
|
|
2
|
+
export interface SplitClientConstructor {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
logger: ILogger;
|
|
5
|
+
timeout: number;
|
|
6
|
+
debug: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare class BaseSplitClient {
|
|
9
|
+
protected static client: SplitIO.IClient;
|
|
10
|
+
protected static logger: ILogger;
|
|
11
|
+
protected promiseConstruction: Promise<boolean>;
|
|
12
|
+
constructor({ apiKey, logger, timeout, debug, }: SplitClientConstructor);
|
|
13
|
+
hasLoaded(): Promise<boolean>;
|
|
14
|
+
getTreatment(key: string, splitName: string, attributes?: {}): string;
|
|
15
|
+
getBooleanTreatment(key: string, splitName: string, attributes?: {}): boolean;
|
|
16
|
+
destroy(): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.BaseSplitClient = void 0;
|
|
13
|
+
const splitio_1 = require("@splitsoftware/splitio");
|
|
14
|
+
const ON = "on";
|
|
15
|
+
const CONTROL = "control";
|
|
16
|
+
const TIMEOUT_ERROR = 6000;
|
|
17
|
+
class BaseSplitClient {
|
|
18
|
+
constructor({ apiKey, logger, timeout = TIMEOUT_ERROR, debug = false, }) {
|
|
19
|
+
BaseSplitClient.logger = logger;
|
|
20
|
+
const factory = (0, splitio_1.SplitFactory)({
|
|
21
|
+
core: {
|
|
22
|
+
authorizationKey: apiKey,
|
|
23
|
+
},
|
|
24
|
+
scheduler: {
|
|
25
|
+
impressionsRefreshRate: 1,
|
|
26
|
+
eventsPushRate: 2,
|
|
27
|
+
},
|
|
28
|
+
debug,
|
|
29
|
+
});
|
|
30
|
+
BaseSplitClient.client = factory.client();
|
|
31
|
+
this.promiseConstruction = Promise.race([
|
|
32
|
+
new Promise((resolve) => {
|
|
33
|
+
BaseSplitClient.client.on(BaseSplitClient.client.Event.SDK_READY, () => {
|
|
34
|
+
BaseSplitClient.logger.info("split_io_client.created.succeed");
|
|
35
|
+
resolve(true);
|
|
36
|
+
});
|
|
37
|
+
}),
|
|
38
|
+
new Promise((resolve) => {
|
|
39
|
+
setTimeout(() => {
|
|
40
|
+
resolve(false);
|
|
41
|
+
}, timeout);
|
|
42
|
+
}),
|
|
43
|
+
]);
|
|
44
|
+
}
|
|
45
|
+
hasLoaded() {
|
|
46
|
+
return this.promiseConstruction;
|
|
47
|
+
}
|
|
48
|
+
getTreatment(key, splitName, attributes = {}) {
|
|
49
|
+
const treatment = BaseSplitClient.client.getTreatment(key, splitName, attributes);
|
|
50
|
+
if (treatment === CONTROL) {
|
|
51
|
+
BaseSplitClient.logger.warn("split_io_client.created.sdk_return_control", {
|
|
52
|
+
key,
|
|
53
|
+
splitName,
|
|
54
|
+
attributes,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return treatment;
|
|
58
|
+
}
|
|
59
|
+
getBooleanTreatment(key, splitName, attributes = {}) {
|
|
60
|
+
const treatment = this.getTreatment(key, splitName, attributes);
|
|
61
|
+
return treatment === ON;
|
|
62
|
+
}
|
|
63
|
+
destroy() {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
yield BaseSplitClient.client.destroy();
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.BaseSplitClient = BaseSplitClient;
|
|
70
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oDAAsD;AAEtD,MAAM,EAAE,GAAG,IAAI,CAAC;AAChB,MAAM,OAAO,GAAG,SAAS,CAAC;AAC1B,MAAM,aAAa,GAAG,IAAI,CAAC;AAS3B,MAAa,eAAe;IAO1B,YAAY,EACV,MAAM,EACN,MAAM,EACN,OAAO,GAAG,aAAa,EACvB,KAAK,GAAG,KAAK,GACU;QACvB,eAAe,CAAC,MAAM,GAAG,MAAM,CAAC;QAEhC,MAAM,OAAO,GAAG,IAAA,sBAAY,EAAC;YAC3B,IAAI,EAAE;gBACJ,gBAAgB,EAAE,MAAM;aACzB;YACD,SAAS,EAAE;gBACT,sBAAsB,EAAE,CAAC;gBACzB,cAAc,EAAE,CAAC;aAClB;YACD,KAAK;SACN,CAAC,CAAC;QAEH,eAAe,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QAE1C,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;YACtC,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;gBAC5B,eAAe,CAAC,MAAM,CAAC,EAAE,CACvB,eAAe,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,EACtC,GAAG,EAAE;oBACH,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;oBAC/D,OAAO,CAAC,IAAI,CAAC,CAAC;gBAChB,CAAC,CACF,CAAC;YACJ,CAAC,CAAC;YACF,IAAI,OAAO,CAAQ,CAAC,OAAO,EAAE,EAAE;gBAC7B,UAAU,CAAC,GAAG,EAAE;oBACd,OAAO,CAAC,KAAK,CAAC,CAAC;gBACjB,CAAC,EAAE,OAAO,CAAC,CAAC;YACd,CAAC,CAAC;SACH,CAAC,CAAC;IACL,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;IAED,YAAY,CAAC,GAAW,EAAE,SAAiB,EAAE,UAAU,GAAG,EAAE;QAC1D,MAAM,SAAS,GAAG,eAAe,CAAC,MAAM,CAAC,YAAY,CACnD,GAAG,EACH,SAAS,EACT,UAAU,CACX,CAAC;QAEF,IAAI,SAAS,KAAK,OAAO,EAAE;YACzB,eAAe,CAAC,MAAM,CAAC,IAAI,CACzB,4CAA4C,EAC5C;gBACE,GAAG;gBACH,SAAS;gBACT,UAAU;aACX,CACF,CAAC;SACH;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,mBAAmB,CACjB,GAAW,EACX,SAAiB,EACjB,UAAU,GAAG,EAAE;QAEf,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;QAChE,OAAO,SAAS,KAAK,EAAE,CAAC;IAC1B,CAAC;IAEK,OAAO;;YACX,MAAM,eAAe,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACzC,CAAC;KAAA;CACF;AAnFD,0CAmFC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./client";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./client"), exports);
|
|
14
|
+
// comment to republish
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyB;AACzB,uBAAuB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alanszp/split",
|
|
3
|
+
"version": "7.8.0",
|
|
4
|
+
"description": "Alan's split client",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"typings": "dist/index.d.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"files": [
|
|
9
|
+
"**/*"
|
|
10
|
+
],
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"compile": "rm -rf ./dist && tsc --declaration",
|
|
16
|
+
"compile-watch": "tsc -w",
|
|
17
|
+
"build": "yarn run compile",
|
|
18
|
+
"prepack": "yarn run build",
|
|
19
|
+
"yalc-publish": "yarn run yalc publish"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@alanszp/logger": "^5.0.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@alanszp/logger": "^7.0.0",
|
|
26
|
+
"@types/lodash": "^4.14.170",
|
|
27
|
+
"@types/node": "^15.12.3",
|
|
28
|
+
"ts-node": "^10.0.0",
|
|
29
|
+
"tslint": "^6.1.3",
|
|
30
|
+
"typescript": "^4.3.4"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@alanszp/core": "^7.0.0",
|
|
34
|
+
"@alanszp/shared-context": "^7.0.0",
|
|
35
|
+
"@alanszp/typeorm": "^7.0.0",
|
|
36
|
+
"@splitsoftware/splitio": "^10.22.0",
|
|
37
|
+
"cuid": "^2.1.8",
|
|
38
|
+
"lodash": "^4.17.21"
|
|
39
|
+
},
|
|
40
|
+
"gitHead": "a3db8bf208ad80b94d63daee370b63ead267a410"
|
|
41
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { ILogger } from "@alanszp/logger";
|
|
2
|
+
import { SplitFactory } from "@splitsoftware/splitio";
|
|
3
|
+
|
|
4
|
+
const ON = "on";
|
|
5
|
+
const CONTROL = "control";
|
|
6
|
+
const TIMEOUT_ERROR = 6000;
|
|
7
|
+
|
|
8
|
+
export interface SplitClientConstructor {
|
|
9
|
+
apiKey: string;
|
|
10
|
+
logger: ILogger;
|
|
11
|
+
timeout: number;
|
|
12
|
+
debug: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class BaseSplitClient {
|
|
16
|
+
protected static client: SplitIO.IClient;
|
|
17
|
+
|
|
18
|
+
protected static logger: ILogger;
|
|
19
|
+
|
|
20
|
+
protected promiseConstruction: Promise<boolean>;
|
|
21
|
+
|
|
22
|
+
constructor({
|
|
23
|
+
apiKey,
|
|
24
|
+
logger,
|
|
25
|
+
timeout = TIMEOUT_ERROR,
|
|
26
|
+
debug = false,
|
|
27
|
+
}: SplitClientConstructor) {
|
|
28
|
+
BaseSplitClient.logger = logger;
|
|
29
|
+
|
|
30
|
+
const factory = SplitFactory({
|
|
31
|
+
core: {
|
|
32
|
+
authorizationKey: apiKey,
|
|
33
|
+
},
|
|
34
|
+
scheduler: {
|
|
35
|
+
impressionsRefreshRate: 1,
|
|
36
|
+
eventsPushRate: 2,
|
|
37
|
+
},
|
|
38
|
+
debug,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
BaseSplitClient.client = factory.client();
|
|
42
|
+
|
|
43
|
+
this.promiseConstruction = Promise.race([
|
|
44
|
+
new Promise<true>((resolve) => {
|
|
45
|
+
BaseSplitClient.client.on(
|
|
46
|
+
BaseSplitClient.client.Event.SDK_READY,
|
|
47
|
+
() => {
|
|
48
|
+
BaseSplitClient.logger.info("split_io_client.created.succeed");
|
|
49
|
+
resolve(true);
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
}),
|
|
53
|
+
new Promise<false>((resolve) => {
|
|
54
|
+
setTimeout(() => {
|
|
55
|
+
resolve(false);
|
|
56
|
+
}, timeout);
|
|
57
|
+
}),
|
|
58
|
+
]);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
hasLoaded(): Promise<boolean> {
|
|
62
|
+
return this.promiseConstruction;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
getTreatment(key: string, splitName: string, attributes = {}): string {
|
|
66
|
+
const treatment = BaseSplitClient.client.getTreatment(
|
|
67
|
+
key,
|
|
68
|
+
splitName,
|
|
69
|
+
attributes
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
if (treatment === CONTROL) {
|
|
73
|
+
BaseSplitClient.logger.warn(
|
|
74
|
+
"split_io_client.created.sdk_return_control",
|
|
75
|
+
{
|
|
76
|
+
key,
|
|
77
|
+
splitName,
|
|
78
|
+
attributes,
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return treatment;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
getBooleanTreatment(
|
|
87
|
+
key: string,
|
|
88
|
+
splitName: string,
|
|
89
|
+
attributes = {}
|
|
90
|
+
): boolean {
|
|
91
|
+
const treatment = this.getTreatment(key, splitName, attributes);
|
|
92
|
+
return treatment === ON;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async destroy(): Promise<void> {
|
|
96
|
+
await BaseSplitClient.client.destroy();
|
|
97
|
+
}
|
|
98
|
+
}
|
package/src/index.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"rootDir": "src",
|
|
4
|
+
"outDir": "dist",
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"target": "es6",
|
|
7
|
+
"types": ["node"],
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"sourceMap": true,
|
|
10
|
+
|
|
11
|
+
"alwaysStrict": true,
|
|
12
|
+
"strictNullChecks": true
|
|
13
|
+
},
|
|
14
|
+
"exclude": ["node_modules"]
|
|
15
|
+
}
|