@webiny/feature-flags 0.0.0-unstable.615a930a68
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/LICENSE +21 -0
- package/README.md +97 -0
- package/index.d.ts +2 -0
- package/index.js +15 -0
- package/index.js.map +1 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# `@webiny/feature-flags`
|
|
2
|
+
[](https://www.npmjs.com/package/@webiny/feature-flags)
|
|
3
|
+
[](https://www.npmjs.com/package/@webiny/feature-flags)
|
|
4
|
+
[](https://github.com/prettier/prettier)
|
|
5
|
+
[](http://makeapullrequest.com)
|
|
6
|
+
|
|
7
|
+
A small library that provides a simple way to define and read feature flags in a Webiny project.
|
|
8
|
+
|
|
9
|
+
## Table of Contents
|
|
10
|
+
|
|
11
|
+
- [Installation](#installation)
|
|
12
|
+
- [Overview](#overview)
|
|
13
|
+
- [Examples](#examples)
|
|
14
|
+
- [Reference](#reference)
|
|
15
|
+
- [Objects](#objects)
|
|
16
|
+
- [`featureFlags`](#featureFlags)
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
npm install --save @webiny/feature-flags
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Or if you prefer yarn:
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
yarn add @webiny/feature-flags
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
## Overview
|
|
32
|
+
|
|
33
|
+
The `@webiny/feature-flags` exports a single `featureFlags` object which contains all of the feature flags initially set via the Webiny project's `webiny.project.ts` config file, via its `featureFlags` property.
|
|
34
|
+
|
|
35
|
+
For example, given the following `webiny.project.ts` config file;
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
// webiny.project.ts
|
|
39
|
+
export default {
|
|
40
|
+
name: "webiny-js",
|
|
41
|
+
cli: {
|
|
42
|
+
...
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
// Feature flags are defined via a simple JavaScript object.
|
|
46
|
+
featureFlags: {
|
|
47
|
+
myCustomFeatureFlag: false,
|
|
48
|
+
someFeature: { enabled: true, myCustomProperty: 123, thisIsJson: "yes"}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Within both backend and frontend application code, the `featureFlags` object can then be read like so:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { featureFlags } from "@webiny/feature-flags";
|
|
57
|
+
|
|
58
|
+
const useMyCustomFeature = featureFlags.myCustomFeatureFlag;
|
|
59
|
+
|
|
60
|
+
const someOtherFeatureMyCustomProperty = featureFlags.someFeature.myCustomProperty;
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
> **NOTE**
|
|
64
|
+
>
|
|
65
|
+
> Behind the scenes, it's the [Webiny CLI](https://www.webiny.com/docs/core-development-concepts/basics/webiny-cli) that enables the propagation of the `featureFlags` object into the actual applications. As mentioned, the `featureFlags` object can be accessed within both backend and frontend application code.
|
|
66
|
+
|
|
67
|
+
## Examples
|
|
68
|
+
|
|
69
|
+
No additional examples.
|
|
70
|
+
|
|
71
|
+
## Reference
|
|
72
|
+
|
|
73
|
+
### Objects
|
|
74
|
+
|
|
75
|
+
#### `featureFlags`
|
|
76
|
+
|
|
77
|
+
<details>
|
|
78
|
+
<summary>Type Declaration</summary>
|
|
79
|
+
<p>
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
declare let featureFlags: Record<string, any>;
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
</p>
|
|
86
|
+
</details>
|
|
87
|
+
|
|
88
|
+
The `featureFlags` object contains all of the feature flags initially set via the Webiny project's `webiny.project.ts` config file, via its `featureFlags` property.
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import { featureFlags } from "@webiny/feature-flags";
|
|
93
|
+
|
|
94
|
+
const useMyCustomFeature = featureFlags.myCustomFeatureFlag;
|
|
95
|
+
|
|
96
|
+
const someOtherFeatureMyCustomProperty = featureFlags.someFeature.myCustomProperty;
|
|
97
|
+
```
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.featureFlags = void 0;
|
|
7
|
+
let featureFlags = {}; // In API applications.
|
|
8
|
+
|
|
9
|
+
exports.featureFlags = featureFlags;
|
|
10
|
+
|
|
11
|
+
if (process.env.WEBINY_FEATURE_FLAGS) {
|
|
12
|
+
exports.featureFlags = featureFlags = JSON.parse(process.env.WEBINY_FEATURE_FLAGS); // In React applications.
|
|
13
|
+
} else if (process.env.REACT_APP_WEBINY_FEATURE_FLAGS) {
|
|
14
|
+
exports.featureFlags = featureFlags = JSON.parse(process.env.REACT_APP_WEBINY_FEATURE_FLAGS);
|
|
15
|
+
}
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["featureFlags","process","env","WEBINY_FEATURE_FLAGS","JSON","parse","REACT_APP_WEBINY_FEATURE_FLAGS"],"sources":["index.ts"],"sourcesContent":["let featureFlags: Record<string, any> = {};\n\n// In API applications.\nif (process.env.WEBINY_FEATURE_FLAGS) {\n featureFlags = JSON.parse(process.env.WEBINY_FEATURE_FLAGS);\n\n // In React applications.\n} else if (process.env.REACT_APP_WEBINY_FEATURE_FLAGS) {\n featureFlags = JSON.parse(process.env.REACT_APP_WEBINY_FEATURE_FLAGS);\n}\n\nexport { featureFlags };\n"],"mappings":";;;;;;AAAA,IAAIA,YAAiC,GAAG,EAAxC,C,CAEA;;;;AACA,IAAIC,OAAO,CAACC,GAAR,CAAYC,oBAAhB,EAAsC;EAClC,uBAAAH,YAAY,GAAGI,IAAI,CAACC,KAAL,CAAWJ,OAAO,CAACC,GAAR,CAAYC,oBAAvB,CAAf,CADkC,CAGlC;AACH,CAJD,MAIO,IAAIF,OAAO,CAACC,GAAR,CAAYI,8BAAhB,EAAgD;EACnD,uBAAAN,YAAY,GAAGI,IAAI,CAACC,KAAL,CAAWJ,OAAO,CAACC,GAAR,CAAYI,8BAAvB,CAAf;AACH"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/feature-flags",
|
|
3
|
+
"version": "0.0.0-unstable.615a930a68",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/webiny/webiny-js.git"
|
|
8
|
+
},
|
|
9
|
+
"description": "A small library that provides a simple way to define and read feature flags in a Webiny project.",
|
|
10
|
+
"contributors": [
|
|
11
|
+
"Adrian Smijulj <adrian@webiny.com>"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@babel/runtime": "7.19.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@babel/cli": "^7.19.3",
|
|
19
|
+
"@babel/core": "^7.19.3",
|
|
20
|
+
"@types/uniqid": "^5.3.2",
|
|
21
|
+
"@webiny/cli": "^0.0.0-unstable.615a930a68",
|
|
22
|
+
"@webiny/project-utils": "^0.0.0-unstable.615a930a68",
|
|
23
|
+
"rimraf": "^3.0.2",
|
|
24
|
+
"ttypescript": "^1.5.13",
|
|
25
|
+
"typescript": "4.7.4"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public",
|
|
29
|
+
"directory": "dist"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "yarn webiny run build",
|
|
33
|
+
"watch": "yarn webiny run watch"
|
|
34
|
+
},
|
|
35
|
+
"gitHead": "615a930a68d692c832e4f100405eeb3f5a8874af"
|
|
36
|
+
}
|