@featurevisor/vue 0.33.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/CHANGELOG.md +11 -0
- package/LICENSE +21 -0
- package/README.md +76 -0
- package/coverage/clover.xml +12 -0
- package/coverage/coverage-final.json +2 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +116 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/setupApp.ts.html +109 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov.info +14 -0
- package/dist/index.js +2 -0
- package/dist/index.js.gz +0 -0
- package/dist/index.js.map +1 -0
- package/jest.config.js +7 -0
- package/jest.setup.js +4 -0
- package/lib/activateFeature.d.ts +2 -0
- package/lib/activateFeature.js +7 -0
- package/lib/activateFeature.js.map +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +7 -0
- package/lib/index.js.map +1 -0
- package/lib/index.spec.d.ts +1 -0
- package/lib/index.spec.js +112 -0
- package/lib/index.spec.js.map +1 -0
- package/lib/setupApp.d.ts +4 -0
- package/lib/setupApp.js +5 -0
- package/lib/setupApp.js.map +1 -0
- package/lib/useSdk.d.ts +2 -0
- package/lib/useSdk.js +7 -0
- package/lib/useSdk.js.map +1 -0
- package/lib/useStatus.d.ts +5 -0
- package/lib/useStatus.js +17 -0
- package/lib/useStatus.js.map +1 -0
- package/lib/useVariable.d.ts +2 -0
- package/lib/useVariable.js +7 -0
- package/lib/useVariable.js.map +1 -0
- package/lib/useVariation.d.ts +2 -0
- package/lib/useVariation.js +7 -0
- package/lib/useVariation.js.map +1 -0
- package/package.json +55 -0
- package/src/activateFeature.ts +12 -0
- package/src/index.spec.ts +75 -0
- package/src/index.ts +7 -0
- package/src/setupApp.ts +8 -0
- package/src/useSdk.ts +10 -0
- package/src/useStatus.ts +26 -0
- package/src/useVariable.ts +13 -0
- package/src/useVariation.ts +12 -0
- package/stub/types__react/index.d.ts +1 -0
- package/tsconfig.cjs.json +12 -0
- package/tsconfig.esm.json +14 -0
- package/tsconfig.json +13 -0
- package/webpack.config.js +21 -0
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@featurevisor/vue",
|
|
3
|
+
"version": "0.33.0",
|
|
4
|
+
"description": "Vue.js package for Featurevisor",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "lib/index.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"lint": "echo 'not linting in this package yet'",
|
|
10
|
+
"transpile": "rimraf lib && tsc --project tsconfig.esm.json",
|
|
11
|
+
"dist": "webpack --config ./webpack.config.js",
|
|
12
|
+
"build": "npm run transpile && npm run dist",
|
|
13
|
+
"test": "jest --config jest.config.js --verbose --coverage ./src/*.spec.ts"
|
|
14
|
+
},
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "Fahad Heylaal",
|
|
17
|
+
"url": "https://fahad19.com"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://featurevisor.com",
|
|
20
|
+
"keywords": [
|
|
21
|
+
"featurevisor",
|
|
22
|
+
"feature",
|
|
23
|
+
"features",
|
|
24
|
+
"flags",
|
|
25
|
+
"feature flags",
|
|
26
|
+
"feature toggles",
|
|
27
|
+
"feature management",
|
|
28
|
+
"experimentation",
|
|
29
|
+
"experiment",
|
|
30
|
+
"experiments",
|
|
31
|
+
"vue"
|
|
32
|
+
],
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://github.com/fahad19/featurevisor.git"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public",
|
|
39
|
+
"registry": "https://registry.npmjs.org/"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/fahad19/featurevisor/issues"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@featurevisor/sdk": "^0.33.0",
|
|
46
|
+
"@featurevisor/types": "^0.33.0",
|
|
47
|
+
"vue": "^3.3.4"
|
|
48
|
+
},
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@vue/cli-plugin-unit-jest": "^5.0.8",
|
|
52
|
+
"@vue/test-utils": "^2.4.0"
|
|
53
|
+
},
|
|
54
|
+
"gitHead": "a03246983110e5e83432b0a90849aece2fae1512"
|
|
55
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Attributes, FeatureKey, VariationValue } from "@featurevisor/types";
|
|
2
|
+
|
|
3
|
+
import { useSdk } from "./useSdk";
|
|
4
|
+
|
|
5
|
+
export function activateFeature(
|
|
6
|
+
featureKey: FeatureKey,
|
|
7
|
+
attributes: Attributes = {},
|
|
8
|
+
): VariationValue | undefined {
|
|
9
|
+
const sdk = useSdk();
|
|
10
|
+
|
|
11
|
+
return sdk.activate(featureKey, attributes);
|
|
12
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createApp } from "vue";
|
|
2
|
+
import { createInstance } from "@featurevisor/sdk";
|
|
3
|
+
import { mount } from "@vue/test-utils";
|
|
4
|
+
|
|
5
|
+
import { setupApp, PROVIDER_NAME } from "./setupApp";
|
|
6
|
+
import { useSdk } from "./useSdk";
|
|
7
|
+
|
|
8
|
+
describe("vue: index", function () {
|
|
9
|
+
it("can set up sdk in app and then inject the sdk instance", async function () {
|
|
10
|
+
const sdk = createInstance({
|
|
11
|
+
datafile: {
|
|
12
|
+
schemaVersion: "1",
|
|
13
|
+
revision: "1.0",
|
|
14
|
+
features: [
|
|
15
|
+
{
|
|
16
|
+
key: "test",
|
|
17
|
+
defaultVariation: false,
|
|
18
|
+
bucketBy: "userId",
|
|
19
|
+
variations: [{ value: true }, { value: false }],
|
|
20
|
+
traffic: [
|
|
21
|
+
{
|
|
22
|
+
key: "1",
|
|
23
|
+
segments: "*",
|
|
24
|
+
percentage: 100000,
|
|
25
|
+
allocation: [
|
|
26
|
+
{ variation: true, range: [0, 100000] },
|
|
27
|
+
{ variation: false, range: [0, 0] },
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
attributes: [],
|
|
34
|
+
segments: [],
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const TestComponent = {
|
|
39
|
+
inject: [PROVIDER_NAME],
|
|
40
|
+
data: function () {
|
|
41
|
+
const revision = this[PROVIDER_NAME].getRevision();
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
revision,
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
template: `<div>
|
|
48
|
+
<p data-test="p">TestComponent here</p>
|
|
49
|
+
<p data-test="revision">{{ revision }}</p>
|
|
50
|
+
</div>`,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const App = {
|
|
54
|
+
components: { TestComponent },
|
|
55
|
+
template: `<div><TestComponent /></div>`,
|
|
56
|
+
provide: {
|
|
57
|
+
[PROVIDER_NAME]: sdk,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const app = createApp(App);
|
|
62
|
+
setupApp(app, sdk);
|
|
63
|
+
|
|
64
|
+
const wrapper = mount(App);
|
|
65
|
+
expect(wrapper.exists()).toEqual(true);
|
|
66
|
+
|
|
67
|
+
const pText = await wrapper.get(`[data-test="p"]`).text();
|
|
68
|
+
expect(pText).toEqual("TestComponent here");
|
|
69
|
+
|
|
70
|
+
const revisionText = await wrapper.get(`[data-test="revision"]`).text();
|
|
71
|
+
expect(revisionText).toEqual("1.0");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// @TODO: add more tests that utilizes Composition API
|
|
75
|
+
});
|
package/src/index.ts
ADDED
package/src/setupApp.ts
ADDED
package/src/useSdk.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { inject } from "vue";
|
|
2
|
+
import { FeaturevisorInstance } from "@featurevisor/sdk";
|
|
3
|
+
|
|
4
|
+
import { PROVIDER_NAME } from "./setupApp";
|
|
5
|
+
|
|
6
|
+
export function useSdk(): FeaturevisorInstance {
|
|
7
|
+
const sdk = inject(PROVIDER_NAME) as FeaturevisorInstance;
|
|
8
|
+
|
|
9
|
+
return sdk;
|
|
10
|
+
}
|
package/src/useStatus.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Ref, readonly, ref } from "vue";
|
|
2
|
+
|
|
3
|
+
import { useSdk } from "./useSdk";
|
|
4
|
+
|
|
5
|
+
export interface Status {
|
|
6
|
+
isReady: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function useStatus(): Ref<Status> {
|
|
10
|
+
const sdk = useSdk();
|
|
11
|
+
const initialStatus = sdk.isReady();
|
|
12
|
+
|
|
13
|
+
const result = ref({
|
|
14
|
+
isReady: initialStatus,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
if (initialStatus) {
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
sdk.on("ready", () => {
|
|
22
|
+
result.value.isReady = true;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return readonly(result);
|
|
26
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Attributes, FeatureKey, VariableKey, VariableValue } from "@featurevisor/types";
|
|
2
|
+
|
|
3
|
+
import { useSdk } from "./useSdk";
|
|
4
|
+
|
|
5
|
+
export function useVariable(
|
|
6
|
+
featureKey: FeatureKey,
|
|
7
|
+
variableKey: VariableKey,
|
|
8
|
+
attributes: Attributes = {},
|
|
9
|
+
): VariableValue | undefined {
|
|
10
|
+
const sdk = useSdk();
|
|
11
|
+
|
|
12
|
+
return sdk.getVariable(featureKey, variableKey, attributes);
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Attributes, FeatureKey, VariationValue } from "@featurevisor/types";
|
|
2
|
+
|
|
3
|
+
import { useSdk } from "./useSdk";
|
|
4
|
+
|
|
5
|
+
export function useVariation(
|
|
6
|
+
featureKey: FeatureKey,
|
|
7
|
+
attributes: Attributes = {},
|
|
8
|
+
): VariationValue | undefined {
|
|
9
|
+
const sdk = useSdk();
|
|
10
|
+
|
|
11
|
+
return sdk.getVariation(featureKey, attributes);
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.esm.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "./lib",
|
|
5
|
+
"lib": ["es2015", "dom"],
|
|
6
|
+
"jsx": "preserve",
|
|
7
|
+
"types": ["jest"],
|
|
8
|
+
"paths": {
|
|
9
|
+
"react": ["./stub/types__react"]
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"include": ["./src/**/*.ts"],
|
|
13
|
+
"exclude": []
|
|
14
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const path = require("path");
|
|
2
|
+
|
|
3
|
+
const getWebpackConfig = require("../../tools/getWebpackConfig");
|
|
4
|
+
|
|
5
|
+
const wepbackConfig = getWebpackConfig({
|
|
6
|
+
entryFilePath: path.join(__dirname, "src", "index.ts"),
|
|
7
|
+
entryKey: "index",
|
|
8
|
+
outputDirectoryPath: path.join(__dirname, "dist"),
|
|
9
|
+
outputLibrary: "FeaturevisorVue",
|
|
10
|
+
tsConfigFilePath: path.join(__dirname, "tsconfig.cjs.json"),
|
|
11
|
+
externals: {
|
|
12
|
+
vue: {
|
|
13
|
+
commonjs: "vue",
|
|
14
|
+
commonjs2: "vue",
|
|
15
|
+
amd: "vue",
|
|
16
|
+
root: "Vue",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
module.exports = wepbackConfig;
|