@flagship.io/react-sdk 2.2.0-beta.3 → 3.0.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.
@@ -0,0 +1,9 @@
1
+ import { IFlag, IFlagMetadata } from '@flagship.io/js-sdk';
2
+ export declare class Flag<T> implements IFlag<T> {
3
+ private _defaultValue;
4
+ constructor(defaultValue: T);
5
+ getValue(): T;
6
+ exists(): boolean;
7
+ userExposed(): Promise<void>;
8
+ get metadata(): IFlagMetadata;
9
+ }
@@ -1,6 +1,5 @@
1
1
  import React, { ReactNode, Dispatch, SetStateAction } from 'react';
2
- import { BucketingDTO, CampaignDTO, IFlagshipConfig, Modification, Visitor } from '@flagship.io/js-sdk';
3
- export declare type primitive = string | number | boolean;
2
+ import { BucketingDTO, CampaignDTO, FlagDTO, IFlagshipConfig, primitive, Visitor } from '@flagship.io/js-sdk';
4
3
  export interface FsStatus {
5
4
  /**
6
5
  * Boolean. When true, the SDK is still not ready to render your App otherwise it'll use default modifications.
@@ -16,8 +15,8 @@ export interface FsStatus {
16
15
  */
17
16
  isVisitorDefined?: boolean;
18
17
  /**
19
- * String or null. The last update date occurred on the flagship visitor instance.
20
- */
18
+ * String or null. The last update date occurred on the flagship visitor instance.
19
+ */
21
20
  lastRefresh?: string;
22
21
  /**
23
22
  * String or null. When null no initialization succeed yet. When string contains stringified date of last successful initialization.
@@ -27,30 +26,34 @@ export interface FsStatus {
27
26
  export interface FsState {
28
27
  visitor?: Visitor;
29
28
  config?: IFlagshipConfig;
30
- modifications?: Map<string, Modification>;
29
+ modifications?: Map<string, FlagDTO>;
31
30
  status: FsStatus;
32
31
  initialCampaigns?: CampaignDTO[];
33
- initialModifications?: Map<string, Modification> | Modification[];
32
+ initialModifications?: Map<string, FlagDTO> | FlagDTO[];
34
33
  }
35
34
  interface FsContext {
36
35
  state: FsState;
37
36
  setState?: Dispatch<SetStateAction<FsState>>;
38
37
  }
39
38
  interface FlagshipProviderProps extends IFlagshipConfig {
39
+ /**
40
+ * This is the data to identify the current visitor using your app
41
+ */
40
42
  visitorData: {
41
- id: string;
43
+ id?: string;
42
44
  context?: Record<string, primitive>;
43
45
  isAuthenticated?: boolean;
44
46
  hasConsented?: boolean;
45
47
  };
46
48
  envId: string;
47
49
  apiKey: string;
48
- loadingComponent?: ReactNode;
49
- children?: ReactNode;
50
50
  /**
51
- * If value is other than production , it will also display Debug logs.
51
+ * This component will be rendered when Flagship is loading at first initialization only.
52
+ * By default, the value is undefined. It means it will display your app and it might
53
+ * display default modifications value for a very short moment.
52
54
  */
53
- nodeEnv?: string;
55
+ loadingComponent?: ReactNode;
56
+ children?: ReactNode;
54
57
  /**
55
58
  * Callback function called when the SDK starts initialization.
56
59
  */
@@ -63,16 +66,29 @@ interface FlagshipProviderProps extends IFlagshipConfig {
63
66
  * Callback function called when the SDK is updated. For example, after a synchronize is triggered or visitor context has changed.
64
67
  */
65
68
  onUpdate?(params: {
66
- fsModifications: Map<string, Modification>;
69
+ fsModifications: Map<string, FlagDTO>;
67
70
  config: IFlagshipConfig;
68
71
  status: FsStatus;
69
72
  }): void;
73
+ /**
74
+ * This is an object of the data received when fetching bucketing endpoint.
75
+ * Providing this prop will make bucketing ready to use and the first polling will immediatly check for an update.
76
+ * If the shape of an element is not correct, an error log will give the reason why.
77
+ */
70
78
  initialBucketing?: BucketingDTO;
71
79
  initialCampaigns?: CampaignDTO[];
72
- initialModifications?: Map<string, Modification> | Modification[];
73
80
  /**
74
- * If true, it'll automatically call synchronizeModifications when the bucketing file has updated
75
- */
81
+ * This is a set of flag data provided to avoid the SDK to have an empty cache during the first initialization.
82
+ * @deprecated use initialFlagsData instead
83
+ */
84
+ initialModifications?: Map<string, FlagDTO> | FlagDTO[];
85
+ /**
86
+ * This is a set of flag data provided to avoid the SDK to have an empty cache during the first initialization.
87
+ */
88
+ initialFlagsData?: Map<string, FlagDTO> | FlagDTO[];
89
+ /**
90
+ * If true, it'll automatically call synchronizeModifications when the bucketing file has updated
91
+ */
76
92
  synchronizeOnBucketingUpdated?: boolean;
77
93
  }
78
94
  export declare const FlagshipContext: React.Context<FsContext>;
@@ -1,11 +1,13 @@
1
- import { HitAbstract, IHit, Modification, modificationsRequested, primitive } from '@flagship.io/js-sdk';
1
+ import { FlagDTO, HitAbstract, HitShape, IFlag, IHit, Modification, modificationsRequested, primitive } from '@flagship.io/js-sdk';
2
2
  import { FsStatus } from './FlagshipContext';
3
3
  /**
4
4
  * Retrieve a modification value by its key. If no modification match the given key or if the stored value type and default value type do not match, default value will be returned.
5
+ * @deprecated use useFsGetFlag instead
5
6
  */
6
7
  export declare const useFsModifications: <T extends unknown>(params: modificationsRequested<T>[], activateAll?: boolean | undefined) => Record<string, T>;
7
8
  /**
8
9
  * Retrieve a modification value by its key. If no modification match the given key or if the stored value type and default value type do not match, default value will be returned.
10
+ * @deprecated use useFsGetFlag instead
9
11
  */
10
12
  export declare const useFsModification: {
11
13
  <T>(params: modificationsRequested<T>): T;
@@ -13,17 +15,22 @@ export declare const useFsModification: {
13
15
  /**
14
16
  * Get the campaign modification information value matching the given key.
15
17
  * @param {string} key key which identify the modification.
18
+ * @deprecated use useFsGetFlag instead
16
19
  */
17
20
  export declare const useFsModificationInfo: {
18
21
  (key: string): Modification | null;
19
22
  };
20
23
  /**
21
- * This function calls the decision api and update all the campaigns modifications from the server according to the visitor context.
22
- */
23
- export declare const useFsSynchronizeModifications: () => Promise<void>;
24
+ * This hook returns a flag object by its key. If no flag match the given key an empty flag will be returned.
25
+ * @param key
26
+ * @param defaultValue
27
+ * @returns
28
+ */
29
+ export declare const useFsFlag: <T extends unknown>(key: string, defaultValue: T) => IFlag<T>;
24
30
  /**
25
31
  * Report this user has seen this modification. Report this user has seen these modifications.
26
32
  * @param params
33
+ * @deprecated use useFsGetFlag instead
27
34
  * @returns
28
35
  */
29
36
  export declare const useFsActivate: {
@@ -39,11 +46,38 @@ export declare type UseFlagshipParams<T> = {
39
46
  };
40
47
  };
41
48
  export declare type UseFlagshipOutput = {
49
+ visitorId?: string;
50
+ anonymousId?: string | null;
51
+ context?: Record<string, primitive>;
52
+ hasConsented?: boolean;
53
+ /**
54
+ * Set if visitor has consented for protected data usage.
55
+ * @param hasConsented True if the visitor has consented false otherwise.
56
+ */
57
+ setConsent: (hasConsented: boolean) => void;
42
58
  modifications: Modification[];
59
+ FlagsData: FlagDTO[];
43
60
  status: FsStatus;
61
+ /**
62
+ *
63
+ * @param params
64
+ * @param activateAll
65
+ * @deprecated use useFsGetFlag instead
66
+ */
44
67
  getModifications<T>(params: modificationsRequested<T>[], activateAll?: boolean): Record<string, T>;
68
+ /**
69
+ *
70
+ * @param key
71
+ * @deprecated use useFsGetFlag instead
72
+ */
45
73
  getModificationInfo(key: string): Modification | null;
74
+ /**
75
+ * @deprecated use useFsFetchFlags instead
76
+ */
46
77
  synchronizeModifications(): Promise<void>;
78
+ /**
79
+ * @deprecated use useFsGetFlag instead
80
+ */
47
81
  activateModification: {
48
82
  (keys: {
49
83
  key: string;
@@ -51,37 +85,46 @@ export declare type UseFlagshipOutput = {
51
85
  (keys: string[]): Promise<void>;
52
86
  };
53
87
  /**
54
- * Update the visitor context values, matching the given keys, used for targeting.
55
- * A new context value associated with this key will be created if there is no previous matching value.
56
- * Context keys must be String, and values types must be one of the following : Number, Boolean, String.
57
- * @param context collection of keys, values.
58
- */
88
+ * Update the visitor context values, matching the given keys, used for targeting.
89
+ * A new context value associated with this key will be created if there is no previous matching value.
90
+ * Context keys must be String, and values types must be one of the following : Number, Boolean, String.
91
+ * @param context collection of keys, values.
92
+ */
59
93
  updateContext(context: Record<string, primitive>): void;
60
94
  /**
61
- * clear the actual visitor context
62
- */
95
+ * clear the actual visitor context
96
+ */
63
97
  clearContext(): void;
64
98
  /**
65
- * Authenticate anonymous visitor
66
- * @param visitorId
67
- */
99
+ * Authenticate anonymous visitor
100
+ * @param visitorId
101
+ */
68
102
  authenticate(visitorId: string): void;
69
103
  /**
70
- * This hook change authenticated Visitor to anonymous visitor
71
- * @param visitorId
72
- */
104
+ * This function change authenticated Visitor to anonymous visitor
105
+ * @param visitorId
106
+ */
73
107
  unauthenticate(): void;
74
108
  hit: {
75
109
  send: {
76
110
  (hit: HitAbstract): Promise<void>;
77
- (hit: HitAbstract | IHit): Promise<void>;
111
+ (hit: IHit): Promise<void>;
112
+ (hit: HitShape): Promise<void>;
113
+ (hit: HitAbstract | IHit | HitShape): Promise<void>;
78
114
  };
79
115
  sendMultiple: {
80
116
  (hit: HitAbstract[]): Promise<void>;
81
117
  (hit: IHit[]): Promise<void>;
118
+ (hit: HitShape[]): Promise<void>;
119
+ (hit: HitAbstract[] | IHit[] | HitShape[]): Promise<void>;
82
120
  };
83
121
  };
122
+ /**
123
+ * Retrieve a Flag object by its key. If no flag match the given key an empty flag will be returned.
124
+ * @param key flag key
125
+ * @param defaultValue
126
+ */
127
+ getFlag<T>(key: string, defaultValue: T): IFlag<T>;
128
+ fetchFlags: () => Promise<void>;
84
129
  };
85
130
  export declare const useFlagship: () => UseFlagshipOutput;
86
- export declare const noVisitorMessage = "sdk not correctly initialized... Make sure fsVisitor is ready.";
87
- export declare const noVisitorDefault = "fsVisitor not initialized, returns default value";
@@ -0,0 +1,2 @@
1
+ export declare const noVisitorMessage = "sdk not correctly initialized... Make sure fsVisitor is ready.";
2
+ export declare const noVisitorDefault = "fsVisitor not initialized, returns default value";
@@ -1,3 +1,3 @@
1
1
  export * from './FlagshipContext';
2
- export { DecisionMode } from '@flagship.io/js-sdk';
2
+ export * from '@flagship.io/js-sdk';
3
3
  export * from './FlagshipHooks';
@@ -1,5 +1,7 @@
1
- import { CampaignDTO, IFlagshipConfig, Modification } from '@flagship.io/js-sdk';
1
+ import { CampaignDTO, IFlagshipConfig, LogLevel, Modification } from '@flagship.io/js-sdk';
2
2
  export declare function logError(config: IFlagshipConfig | undefined, message: string, tag: string): void;
3
3
  export declare function logInfo(config: IFlagshipConfig | undefined, message: string, tag: string): void;
4
4
  export declare function logWarn(config: IFlagshipConfig | undefined, message: string, tag: string): void;
5
+ export declare function log(level: LogLevel, message: string, tag: string): void;
5
6
  export declare const getModificationsFromCampaigns: (campaigns: Array<CampaignDTO>) => Map<string, Modification>;
7
+ export declare function uuidV4(): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flagship.io/react-sdk",
3
- "version": "2.2.0-beta.3",
3
+ "version": "3.0.0",
4
4
  "description": "Flagship REACT SDK",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -11,7 +11,7 @@
11
11
  "README.md"
12
12
  ],
13
13
  "dependencies": {
14
- "@flagship.io/js-sdk": "^2.3.1-beta.6",
14
+ "@flagship.io/js-sdk": "^3.0.0",
15
15
  "encoding": "^0.1.13"
16
16
  },
17
17
  "peerDependencies": {
@@ -97,4 +97,4 @@
97
97
  "last 1 safari version"
98
98
  ]
99
99
  }
100
- }
100
+ }