@lokalise/fastify-extras 5.1.0 → 5.3.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/README.md +9 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/plugins/newrelicTransactionManagerPlugin.d.ts +1 -0
- package/dist/plugins/newrelicTransactionManagerPlugin.js +6 -0
- package/dist/plugins/newrelicTransactionManagerPlugin.js.map +1 -1
- package/dist/plugins/splitIOFeatureManagerPlugin.d.ts +24 -0
- package/dist/plugins/splitIOFeatureManagerPlugin.js +68 -0
- package/dist/plugins/splitIOFeatureManagerPlugin.js.map +1 -0
- package/dist/plugins/splitIOFeatureManagerPlugin.spec.d.ts +1 -0
- package/dist/plugins/splitIOFeatureManagerPlugin.spec.js +90 -0
- package/dist/plugins/splitIOFeatureManagerPlugin.spec.js.map +1 -0
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -8,3 +8,12 @@ The following needs to be taken into consideration when adding new runtime depen
|
|
|
8
8
|
|
|
9
9
|
* If dependency is an implementation detail, and end consumer is not expected to import and use the dependency directly, it should be a `dependency`;
|
|
10
10
|
* If dependency needs to be imported and used by consumer directly for it to function properly, it should be a `peerDependency`.
|
|
11
|
+
|
|
12
|
+
### Split IO plugin
|
|
13
|
+
|
|
14
|
+
Plugin has 3 modes:
|
|
15
|
+
- `enabled` - will connect to [](https://split.io) using provided `apiKey` and store data in memory with background sync
|
|
16
|
+
- `localhost` - will use `localhost` mode with features provided in a file via param `localhostFilePath`
|
|
17
|
+
- `disabled` - on any request to `SplitIOFeatureManager` it will return `control` treatment
|
|
18
|
+
|
|
19
|
+
More info about Split IO can be checked [here](https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK)
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export { requestContextProviderPlugin, getRequestIdFastifyAppConfig, REQUEST_ID_
|
|
|
4
4
|
export type { BaseRequestContext as RequestContext } from './plugins/requestContextProviderPlugin';
|
|
5
5
|
export { newrelicTransactionManagerPlugin, NewRelicTransactionManager, } from './plugins/newrelicTransactionManagerPlugin';
|
|
6
6
|
export type { NewRelicTransactionManagerOptions } from './plugins/newrelicTransactionManagerPlugin';
|
|
7
|
+
export { splitIOFeatureManagerPlugin, SplitIOFeatureManager, } from './plugins/splitIOFeatureManagerPlugin';
|
|
8
|
+
export type { SplitIOOptions } from './plugins/splitIOFeatureManagerPlugin';
|
|
7
9
|
export { metricsPlugin } from './plugins/metricsPlugin';
|
|
8
10
|
export type { ErrorObjectResolver, MetricsPluginOptions } from './plugins/metricsPlugin';
|
|
9
11
|
export { prismaOtelTracingPlugin } from './plugins/opentelemetry/prismaOtelTracingPlugin';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.publicHealthcheckPlugin = exports.prismaOtelTracingPlugin = exports.metricsPlugin = exports.NewRelicTransactionManager = exports.newrelicTransactionManagerPlugin = exports.REQUEST_ID_STORE_KEY = exports.getRequestIdFastifyAppConfig = exports.requestContextProviderPlugin = exports.reportErrorToBugsnag = exports.bugsnagPlugin = void 0;
|
|
3
|
+
exports.publicHealthcheckPlugin = exports.prismaOtelTracingPlugin = exports.metricsPlugin = exports.SplitIOFeatureManager = exports.splitIOFeatureManagerPlugin = exports.NewRelicTransactionManager = exports.newrelicTransactionManagerPlugin = exports.REQUEST_ID_STORE_KEY = exports.getRequestIdFastifyAppConfig = exports.requestContextProviderPlugin = exports.reportErrorToBugsnag = exports.bugsnagPlugin = void 0;
|
|
4
4
|
var bugsnagPlugin_1 = require("./plugins/bugsnagPlugin");
|
|
5
5
|
Object.defineProperty(exports, "bugsnagPlugin", { enumerable: true, get: function () { return bugsnagPlugin_1.bugsnagPlugin; } });
|
|
6
6
|
Object.defineProperty(exports, "reportErrorToBugsnag", { enumerable: true, get: function () { return bugsnagPlugin_1.reportErrorToBugsnag; } });
|
|
@@ -11,6 +11,9 @@ Object.defineProperty(exports, "REQUEST_ID_STORE_KEY", { enumerable: true, get:
|
|
|
11
11
|
var newrelicTransactionManagerPlugin_1 = require("./plugins/newrelicTransactionManagerPlugin");
|
|
12
12
|
Object.defineProperty(exports, "newrelicTransactionManagerPlugin", { enumerable: true, get: function () { return newrelicTransactionManagerPlugin_1.newrelicTransactionManagerPlugin; } });
|
|
13
13
|
Object.defineProperty(exports, "NewRelicTransactionManager", { enumerable: true, get: function () { return newrelicTransactionManagerPlugin_1.NewRelicTransactionManager; } });
|
|
14
|
+
var splitIOFeatureManagerPlugin_1 = require("./plugins/splitIOFeatureManagerPlugin");
|
|
15
|
+
Object.defineProperty(exports, "splitIOFeatureManagerPlugin", { enumerable: true, get: function () { return splitIOFeatureManagerPlugin_1.splitIOFeatureManagerPlugin; } });
|
|
16
|
+
Object.defineProperty(exports, "SplitIOFeatureManager", { enumerable: true, get: function () { return splitIOFeatureManagerPlugin_1.SplitIOFeatureManager; } });
|
|
14
17
|
var metricsPlugin_1 = require("./plugins/metricsPlugin");
|
|
15
18
|
Object.defineProperty(exports, "metricsPlugin", { enumerable: true, get: function () { return metricsPlugin_1.metricsPlugin; } });
|
|
16
19
|
var prismaOtelTracingPlugin_1 = require("./plugins/opentelemetry/prismaOtelTracingPlugin");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;AAAA,yDAA6E;AAApE,8GAAA,aAAa,OAAA;AAAE,qHAAA,oBAAoB,OAAA;AAG5C,uFAI+C;AAH7C,4IAAA,4BAA4B,OAAA;AAC5B,4IAAA,4BAA4B,OAAA;AAC5B,oIAAA,oBAAoB,OAAA;AAItB,+FAGmD;AAFjD,oJAAA,gCAAgC,OAAA;AAChC,8IAAA,0BAA0B,OAAA;AAI5B,yDAAuD;AAA9C,8GAAA,aAAa,OAAA;AAGtB,2FAAyF;AAAhF,kIAAA,uBAAuB,OAAA;AAGhC,6EAA2E;AAAlE,kIAAA,uBAAuB,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;AAAA,yDAA6E;AAApE,8GAAA,aAAa,OAAA;AAAE,qHAAA,oBAAoB,OAAA;AAG5C,uFAI+C;AAH7C,4IAAA,4BAA4B,OAAA;AAC5B,4IAAA,4BAA4B,OAAA;AAC5B,oIAAA,oBAAoB,OAAA;AAItB,+FAGmD;AAFjD,oJAAA,gCAAgC,OAAA;AAChC,8IAAA,0BAA0B,OAAA;AAI5B,qFAG8C;AAF5C,0IAAA,2BAA2B,OAAA;AAC3B,oIAAA,qBAAqB,OAAA;AAIvB,yDAAuD;AAA9C,8GAAA,aAAa,OAAA;AAGtB,2FAAyF;AAAhF,kIAAA,uBAAuB,OAAA;AAGhC,6EAA2E;AAAlE,kIAAA,uBAAuB,OAAA"}
|
|
@@ -10,6 +10,7 @@ export declare class NewRelicTransactionManager {
|
|
|
10
10
|
private readonly isEnabled;
|
|
11
11
|
private readonly transactionMap;
|
|
12
12
|
constructor(isNewRelicEnabled: boolean);
|
|
13
|
+
addCustomAttribte(attrName: string, attrValue: string | number | boolean): void;
|
|
13
14
|
start(jobName: string): void;
|
|
14
15
|
stop(jobId: string): void;
|
|
15
16
|
}
|
|
@@ -15,6 +15,12 @@ class NewRelicTransactionManager {
|
|
|
15
15
|
this.isEnabled = isNewRelicEnabled;
|
|
16
16
|
this.transactionMap = new Map();
|
|
17
17
|
}
|
|
18
|
+
addCustomAttribte(attrName, attrValue) {
|
|
19
|
+
if (!this.isEnabled) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
newrelic.addCustomAttribute(attrName, attrValue);
|
|
23
|
+
}
|
|
18
24
|
start(jobName) {
|
|
19
25
|
if (!this.isEnabled) {
|
|
20
26
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"newrelicTransactionManagerPlugin.js","sourceRoot":"","sources":["../../lib/plugins/newrelicTransactionManagerPlugin.ts"],"names":[],"mappings":";;;;AACA,4EAA+B;
|
|
1
|
+
{"version":3,"file":"newrelicTransactionManagerPlugin.js","sourceRoot":"","sources":["../../lib/plugins/newrelicTransactionManagerPlugin.ts"],"names":[],"mappings":";;;;AACA,4EAA+B;AAe/B,IAAI,QAAkB,CAAA;AAYtB,MAAa,0BAA0B;IACpB,SAAS,CAAS;IAClB,cAAc,CAAgC;IAE/D,YAAY,iBAA0B;QACpC,IAAI,iBAAiB,EAAE;YACrB,mEAAmE;YACnE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;SAC/B;QAED,IAAI,CAAC,SAAS,GAAG,iBAAiB,CAAA;QAClC,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAAE,CAAA;IACjC,CAAC;IAEM,iBAAiB,CAAC,QAAgB,EAAE,SAAoC;QAC7E,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACnB,OAAM;SACP;QAED,QAAQ,CAAC,kBAAkB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;IAClD,CAAC;IAEM,KAAK,CAAC,OAAe;QAC1B,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACnB,OAAM;SACP;QAED,QAAQ,CAAC,0BAA0B,CAAC,OAAO,EAAE,GAAG,EAAE;YAChD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,cAAc,EAAE,CAAC,CAAA;QAC7D,CAAC,CAAC,CAAA;IACJ,CAAC;IAEM,IAAI,CAAC,KAAa;QACvB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACnB,OAAM;SACP;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,CAAA;QAC1D,IAAI,IAAI,KAAK,WAAW,EAAE;YACxB,OAAM;SACP;QACD,WAAW,CAAC,GAAG,EAAE,CAAA;QACjB,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IACnC,CAAC;CACF;AA5CD,gEA4CC;AAED,SAAS,MAAM,CACb,OAAwB,EACxB,IAAuC,EACvC,IAAgB;IAEhB,MAAM,OAAO,GAAG,IAAI,0BAA0B,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IAE9D,OAAO,CAAC,QAAQ,CAAC,4BAA4B,EAAE,OAAO,CAAC,CAAA;IAEvD,IAAI,IAAI,CAAC,SAAS,EAAE;QAClB,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,IAAI,EAAE;YACpC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBACrC,QAAQ,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE;oBAC1B,IAAI,KAAK,EAAE;wBACT,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;qBACrB;oBACD,OAAO,EAAE,CAAA;gBACX,CAAC,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;KACH;IAED,IAAI,EAAE,CAAA;AACR,CAAC;AAEY,QAAA,gCAAgC,GAAG,IAAA,wBAAE,EAAC,MAAM,EAAE;IACzD,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,qCAAqC;CAC5C,CAAC,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type SplitIO from '@splitsoftware/splitio/types/splitio';
|
|
2
|
+
import type { Attributes, Properties, SplitKey, Treatment, TreatmentWithConfig } from '@splitsoftware/splitio/types/splitio';
|
|
3
|
+
declare module 'fastify' {
|
|
4
|
+
interface FastifyInstance {
|
|
5
|
+
splitIOFeatureManager: SplitIOFeatureManager;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export interface SplitIOOptions {
|
|
9
|
+
isEnabled: boolean;
|
|
10
|
+
apiKey: string;
|
|
11
|
+
debugMode: boolean;
|
|
12
|
+
localhostFilePath?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class SplitIOFeatureManager {
|
|
15
|
+
private readonly isEnabled;
|
|
16
|
+
private readonly splitIOClient?;
|
|
17
|
+
constructor(isSplitIOEnabled: boolean, apiKey: string, debugMode: boolean, localhostFilePath?: string);
|
|
18
|
+
init(): Promise<void>;
|
|
19
|
+
getTreatment(key: SplitKey, splitName: string, attributes?: Attributes): Treatment;
|
|
20
|
+
getTreatmentWithConfig(key: SplitKey, splitName: string, attributes?: Attributes): TreatmentWithConfig;
|
|
21
|
+
track(key: SplitIO.SplitKey, trafficType: string, eventType: string, value?: number, properties?: Properties): boolean;
|
|
22
|
+
shutdown(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export declare const splitIOFeatureManagerPlugin: import("fastify").FastifyPluginCallback<SplitIOOptions, import("fastify").RawServerDefault, import("fastify").FastifyTypeProviderDefault, import("fastify").FastifyBaseLogger>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.splitIOFeatureManagerPlugin = exports.SplitIOFeatureManager = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const path = tslib_1.__importStar(require("path"));
|
|
6
|
+
const process = tslib_1.__importStar(require("process"));
|
|
7
|
+
const splitio_1 = require("@splitsoftware/splitio");
|
|
8
|
+
const fastify_plugin_1 = tslib_1.__importDefault(require("fastify-plugin"));
|
|
9
|
+
const DISABLED_TREATMENT = 'control';
|
|
10
|
+
class SplitIOFeatureManager {
|
|
11
|
+
isEnabled;
|
|
12
|
+
splitIOClient;
|
|
13
|
+
constructor(isSplitIOEnabled, apiKey, debugMode, localhostFilePath) {
|
|
14
|
+
if (isSplitIOEnabled) {
|
|
15
|
+
const factory = (0, splitio_1.SplitFactory)({
|
|
16
|
+
core: {
|
|
17
|
+
authorizationKey: localhostFilePath ? 'localhost' : apiKey,
|
|
18
|
+
},
|
|
19
|
+
features: localhostFilePath ? path.join(process.cwd(), localhostFilePath) : undefined,
|
|
20
|
+
debug: debugMode,
|
|
21
|
+
});
|
|
22
|
+
this.splitIOClient = factory.client();
|
|
23
|
+
}
|
|
24
|
+
this.isEnabled = isSplitIOEnabled;
|
|
25
|
+
}
|
|
26
|
+
async init() {
|
|
27
|
+
await this.splitIOClient?.ready();
|
|
28
|
+
}
|
|
29
|
+
getTreatment(key, splitName, attributes) {
|
|
30
|
+
return this.splitIOClient?.getTreatment(key, splitName, attributes) ?? DISABLED_TREATMENT;
|
|
31
|
+
}
|
|
32
|
+
getTreatmentWithConfig(key, splitName, attributes) {
|
|
33
|
+
return (this.splitIOClient?.getTreatmentWithConfig(key, splitName, attributes) ?? {
|
|
34
|
+
treatment: DISABLED_TREATMENT,
|
|
35
|
+
config: null,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
track(key, trafficType, eventType, value, properties) {
|
|
39
|
+
return this.splitIOClient?.track(key, trafficType, eventType, value, properties) ?? false;
|
|
40
|
+
}
|
|
41
|
+
async shutdown() {
|
|
42
|
+
if (!this.isEnabled) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
await this.splitIOClient?.destroy();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.SplitIOFeatureManager = SplitIOFeatureManager;
|
|
49
|
+
function plugin(fastify, opts, done) {
|
|
50
|
+
const manager = new SplitIOFeatureManager(opts.isEnabled, opts.apiKey, opts.debugMode, opts.localhostFilePath);
|
|
51
|
+
fastify.decorate('splitIOFeatureManager', manager);
|
|
52
|
+
if (opts.isEnabled) {
|
|
53
|
+
fastify.addHook('onClose', async () => {
|
|
54
|
+
await manager.shutdown();
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
void manager
|
|
58
|
+
.init()
|
|
59
|
+
.then(() => done())
|
|
60
|
+
.catch(() => {
|
|
61
|
+
throw new Error('Split IO client is not ready');
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
exports.splitIOFeatureManagerPlugin = (0, fastify_plugin_1.default)(plugin, {
|
|
65
|
+
fastify: '4.x',
|
|
66
|
+
name: 'split-io-feature-manager-plugin',
|
|
67
|
+
});
|
|
68
|
+
//# sourceMappingURL=splitIOFeatureManagerPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"splitIOFeatureManagerPlugin.js","sourceRoot":"","sources":["../../lib/plugins/splitIOFeatureManagerPlugin.ts"],"names":[],"mappings":";;;;AAAA,mDAA4B;AAC5B,yDAAkC;AAElC,oDAAqD;AAUrD,4EAA+B;AAE/B,MAAM,kBAAkB,GAAc,SAAS,CAAA;AAe/C,MAAa,qBAAqB;IACf,SAAS,CAAS;IAElB,aAAa,CAAkB;IAEhD,YACE,gBAAyB,EACzB,MAAc,EACd,SAAkB,EAClB,iBAA0B;QAE1B,IAAI,gBAAgB,EAAE;YACpB,MAAM,OAAO,GAAiB,IAAA,sBAAY,EAAC;gBACzC,IAAI,EAAE;oBACJ,gBAAgB,EAAE,iBAAiB,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM;iBAC3D;gBACD,QAAQ,EAAE,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,SAAS;gBACrF,KAAK,EAAE,SAAS;aACjB,CAAC,CAAA;YACF,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,MAAM,EAAE,CAAA;SACtC;QAED,IAAI,CAAC,SAAS,GAAG,gBAAgB,CAAA;IACnC,CAAC;IAEM,KAAK,CAAC,IAAI;QACf,MAAM,IAAI,CAAC,aAAa,EAAE,KAAK,EAAE,CAAA;IACnC,CAAC;IAEM,YAAY,CAAC,GAAa,EAAE,SAAiB,EAAE,UAAuB;QAC3E,OAAO,IAAI,CAAC,aAAa,EAAE,YA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C,GAAG,EAAE;QACV,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;IACjD,CAAC,CAAC,CAAA;AACN,CAAC;AAEY,QAAA,2BAA2B,GAAG,IAAA,wBAAE,EAAC,MAAM,EAAE;IACpD,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,iCAAiC;CACxC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const fastify_1 = tslib_1.__importDefault(require("fastify"));
|
|
5
|
+
const splitIOFeatureManagerPlugin_1 = require("./splitIOFeatureManagerPlugin");
|
|
6
|
+
async function initApp(opts) {
|
|
7
|
+
const app = (0, fastify_1.default)();
|
|
8
|
+
await app.register(splitIOFeatureManagerPlugin_1.splitIOFeatureManagerPlugin, opts);
|
|
9
|
+
await app.ready();
|
|
10
|
+
return app;
|
|
11
|
+
}
|
|
12
|
+
describe('splitIOFeatureManagerPlugin', () => {
|
|
13
|
+
let app;
|
|
14
|
+
afterEach(async () => {
|
|
15
|
+
await app.close();
|
|
16
|
+
});
|
|
17
|
+
it('returns control treatment on disabled client', async () => {
|
|
18
|
+
expect.assertions(1);
|
|
19
|
+
const opts = {
|
|
20
|
+
isEnabled: false,
|
|
21
|
+
apiKey: '',
|
|
22
|
+
debugMode: false,
|
|
23
|
+
};
|
|
24
|
+
app = await initApp(opts);
|
|
25
|
+
const treatment = app.splitIOFeatureManager.getTreatment('', '');
|
|
26
|
+
expect(treatment).toBe('control');
|
|
27
|
+
});
|
|
28
|
+
it('returns treatments from local file', async () => {
|
|
29
|
+
expect.assertions(2);
|
|
30
|
+
const opts = {
|
|
31
|
+
isEnabled: true,
|
|
32
|
+
apiKey: 'localhost',
|
|
33
|
+
debugMode: false,
|
|
34
|
+
localhostFilePath: '/lib/plugins/tests/.split.yaml',
|
|
35
|
+
};
|
|
36
|
+
app = await initApp(opts);
|
|
37
|
+
const onTreatment = app.splitIOFeatureManager.getTreatment('mock_user_id', 'my_feature');
|
|
38
|
+
const offTreatment = app.splitIOFeatureManager.getTreatment('unknown_id', 'my_feature');
|
|
39
|
+
expect(onTreatment).toBe('on');
|
|
40
|
+
expect(offTreatment).toBe('off');
|
|
41
|
+
});
|
|
42
|
+
it('returns control treatment with config on disabled client', async () => {
|
|
43
|
+
expect.assertions(1);
|
|
44
|
+
const opts = {
|
|
45
|
+
isEnabled: false,
|
|
46
|
+
apiKey: '',
|
|
47
|
+
debugMode: false,
|
|
48
|
+
};
|
|
49
|
+
app = await initApp(opts);
|
|
50
|
+
const treatment = app.splitIOFeatureManager.getTreatmentWithConfig('', '');
|
|
51
|
+
expect(treatment).toStrictEqual({ config: null, treatment: 'control' });
|
|
52
|
+
});
|
|
53
|
+
it('returns false track on disabled client', async () => {
|
|
54
|
+
expect.assertions(1);
|
|
55
|
+
const opts = {
|
|
56
|
+
isEnabled: false,
|
|
57
|
+
apiKey: '',
|
|
58
|
+
debugMode: false,
|
|
59
|
+
};
|
|
60
|
+
app = await initApp(opts);
|
|
61
|
+
const trackResult = app.splitIOFeatureManager.track('', '', '');
|
|
62
|
+
expect(trackResult).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
it('shutdown running client', async () => {
|
|
65
|
+
expect.assertions(1);
|
|
66
|
+
const opts = {
|
|
67
|
+
isEnabled: true,
|
|
68
|
+
apiKey: 'localhost',
|
|
69
|
+
debugMode: false,
|
|
70
|
+
localhostFilePath: '/lib/plugins/tests/.split.yaml',
|
|
71
|
+
};
|
|
72
|
+
app = await initApp(opts);
|
|
73
|
+
await app.close();
|
|
74
|
+
const onTreatment = app.splitIOFeatureManager.getTreatment('mock_user_id', 'my_feature');
|
|
75
|
+
expect(onTreatment).toBe('control');
|
|
76
|
+
});
|
|
77
|
+
it('shutdown not active client', async () => {
|
|
78
|
+
expect.assertions(1);
|
|
79
|
+
const opts = {
|
|
80
|
+
isEnabled: false,
|
|
81
|
+
apiKey: '',
|
|
82
|
+
debugMode: false,
|
|
83
|
+
};
|
|
84
|
+
app = await initApp(opts);
|
|
85
|
+
await app.splitIOFeatureManager.shutdown();
|
|
86
|
+
const treatment = app.splitIOFeatureManager.getTreatment('', '');
|
|
87
|
+
expect(treatment).toBe('control');
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
//# sourceMappingURL=splitIOFeatureManagerPlugin.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"splitIOFeatureManagerPlugin.spec.js","sourceRoot":"","sources":["../../lib/plugins/splitIOFeatureManagerPlugin.spec.ts"],"names":[],"mappings":";;;AACA,8DAA6B;AAG7B,+EAA2E;AAE3E,KAAK,UAAU,OAAO,CAAC,IAAqB;IAC1C,MAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAA;IACrB,MAAM,GAAG,CAAC,QAAQ,CAAC,yDAA2B,EAAE,IAAI,CAAC,CAAA;IACrD,MAAM,GAAG,CAAC,KAAK,EAAE,CAAA;IACjB,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,IAAI,GAAoB,CAAA;IACxB,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,MAAM,GAAG,CAAC,KAAK,EAAE,CAAA;IACnB,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,8CAA8C,EAAE,KAAK,IAAI,EAAE;QAC5D,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;QACpB,MAAM,IAAI,GAAG;YACX,SAAS,EAAE,KAAK;YAChB,MAAM,EAAE,EAAE;YACV,SAAS,EAAE,KAAK;SACjB,CAAA;QAED,GAAG,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;QACzB,MAAM,SAAS,GAAG,GAAG,CAAC,qBAAqB,CAAC,YAAY,CAAC,EAAE,EAAE,EA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GAAG,CAAC,qBAAqB,CAAC,QAAQ,EAAE,CAAA;QAC1C,MAAM,SAAS,GAAG,GAAG,CAAC,qBAAqB,CAAC,YAAY,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA;QAEhE,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IACnC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lokalise/fastify-extras",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"description": "Opinionated set of fastify plugins, commonly used in Lokalise",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Lokalise",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"bugsnag",
|
|
18
18
|
"request-context",
|
|
19
19
|
"als",
|
|
20
|
-
"request-id"
|
|
20
|
+
"request-id",
|
|
21
|
+
"split-io"
|
|
21
22
|
],
|
|
22
23
|
"homepage": "https://github.com/lokalise/fastify-extras",
|
|
23
24
|
"files": [
|
|
@@ -58,6 +59,7 @@
|
|
|
58
59
|
"@fastify/request-context": "^4.2.0",
|
|
59
60
|
"fastify": "^4.10.2",
|
|
60
61
|
"newrelic": "^9.7.4",
|
|
62
|
+
"@splitsoftware/splitio": "^10.22.3",
|
|
61
63
|
"pino": "^8.8.0"
|
|
62
64
|
},
|
|
63
65
|
"devDependencies": {
|
|
@@ -74,6 +76,7 @@
|
|
|
74
76
|
"eslint-plugin-import": "^2.27.5",
|
|
75
77
|
"eslint-plugin-jest": "^27.2.1",
|
|
76
78
|
"eslint-plugin-prettier": "^4.2.1",
|
|
79
|
+
"esquery": "1.4.0",
|
|
77
80
|
"fastify": "^4.12.0",
|
|
78
81
|
"jest": "^29.4.1",
|
|
79
82
|
"newrelic": "^9.7.4",
|