@flagship.io/react-sdk 4.0.0-alpha.0 → 4.0.0-alpha.2

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/dist/src/Flag.js DELETED
@@ -1,69 +0,0 @@
1
- import Flagship, { FlagMetadata } from '@flagship.io/js-sdk';
2
- import { GET_FLAG_CAST_ERROR, GET_METADATA_CAST_ERROR, noVisitorMessage } from './constants';
3
- import { hasSameType, logInfo, logWarn, sprintf } from './utils';
4
- export class Flag {
5
- constructor(defaultValue, key, flagsData) {
6
- if (!flagsData) {
7
- logWarn(Flagship.getConfig(), noVisitorMessage, 'GetFlag');
8
- }
9
- this.defaultValue = defaultValue;
10
- this.key = key;
11
- this.flag = flagsData === null || flagsData === void 0 ? void 0 : flagsData.get(key);
12
- }
13
- NotSameType() {
14
- var _a;
15
- return this.defaultValue !== null && this.defaultValue !== undefined && !hasSameType((_a = this.flag) === null || _a === void 0 ? void 0 : _a.value, this.defaultValue);
16
- }
17
- getValue() {
18
- if (!this.flag) {
19
- logWarn(Flagship.getConfig(), noVisitorMessage, 'getValue');
20
- return this.defaultValue;
21
- }
22
- if (this.NotSameType()) {
23
- logInfo(Flagship.getConfig(), sprintf(GET_FLAG_CAST_ERROR, this.key), 'getValue');
24
- return this.defaultValue;
25
- }
26
- return this.flag.value;
27
- }
28
- exists() {
29
- if (!this.flag) {
30
- logWarn(Flagship.getConfig(), noVisitorMessage, 'exists');
31
- return false;
32
- }
33
- return !!(this.flag.campaignId && this.flag.variationId && this.flag.variationGroupId);
34
- }
35
- userExposed() {
36
- if (!this.flag) {
37
- logWarn(Flagship.getConfig(), noVisitorMessage, 'userExposed');
38
- }
39
- return Promise.resolve();
40
- }
41
- visitorExposed() {
42
- if (!this.flag) {
43
- logWarn(Flagship.getConfig(), noVisitorMessage, 'visitorExposed');
44
- }
45
- return Promise.resolve();
46
- }
47
- get metadata() {
48
- const functionName = 'metadata';
49
- if (!this.flag) {
50
- logWarn(Flagship.getConfig(), noVisitorMessage, functionName);
51
- return FlagMetadata.Empty();
52
- }
53
- if (this.NotSameType()) {
54
- logInfo(Flagship.getConfig(), sprintf(GET_METADATA_CAST_ERROR, this.key), functionName);
55
- return FlagMetadata.Empty();
56
- }
57
- return new FlagMetadata({
58
- campaignId: this.flag.campaignId,
59
- campaignName: this.flag.campaignName,
60
- variationGroupId: this.flag.variationGroupId,
61
- variationGroupName: this.flag.variationGroupName,
62
- variationId: this.flag.variationId,
63
- variationName: this.flag.variationName,
64
- isReference: !!this.flag.isReference,
65
- campaignType: this.flag.campaignType,
66
- slug: this.flag.slug
67
- });
68
- }
69
- }