-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathQonversionConfigBuilder.ts
102 lines (92 loc) · 3.63 KB
/
QonversionConfigBuilder.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import {EntitlementsCacheLifetime, Environment, LaunchMode} from './dto/enums';
import {EntitlementsUpdateListener} from './dto/EntitlementsUpdateListener';
import QonversionConfig from './QonversionConfig';
class QonversionConfigBuilder {
private readonly projectKey: string;
private readonly launchMode: LaunchMode;
constructor(projectKey: string, launchMode: LaunchMode) {
this.projectKey = projectKey;
this.launchMode = launchMode;
}
private environment: Environment = Environment.PRODUCTION;
private entitlementsCacheLifetime: EntitlementsCacheLifetime = EntitlementsCacheLifetime.MONTH;
private entitlementsUpdateListener: EntitlementsUpdateListener | undefined = undefined;
private proxyUrl: string | undefined = undefined;
private kidsMode: boolean = false;
/**
* Set current application {@link Environment}. Used to distinguish sandbox and production users.
*
* @param environment current environment.
* @return builder instance for chain calls.
*/
setEnvironment(environment: Environment): QonversionConfigBuilder {
this.environment = environment;
return this;
}
/**
* Entitlements cache is used when there are problems with the Qonversion API
* or internet connection. If so, Qonversion will return the last successfully loaded
* entitlements. The current method allows you to configure how long that cache may be used.
* The default value is {@link EntitlementsCacheLifetime.MONTH}.
*
* @param lifetime desired entitlements cache lifetime duration
* @return builder instance for chain calls.
*/
setEntitlementsCacheLifetime(lifetime: EntitlementsCacheLifetime): QonversionConfigBuilder {
this.entitlementsCacheLifetime = lifetime;
return this;
}
/**
* Provide a listener to be notified about asynchronous user entitlements updates.
*
* Make sure you provide this listener for being up-to-date with the user entitlements.
* Else you can lose some important updates. Also, please, consider that this listener
* should live for the whole lifetime of the application.
*
* @param entitlementsUpdateListener listener to be called when entitlements update.
* @return builder instance for chain calls.
*/
setEntitlementsUpdateListener(entitlementsUpdateListener: EntitlementsUpdateListener): QonversionConfigBuilder {
this.entitlementsUpdateListener = entitlementsUpdateListener;
return this;
}
/**
* Provide a URL to your proxy server which will redirect all the requests from the app
* to our API. Please, contact us before using this feature.
*
* @param url your proxy server url
* @return builder instance for chain calls.
* @see [The documentation](https://documentation.qonversion.io/docs/custom-proxy-server-for-sdks)
*/
setProxyURL(url: string): QonversionConfigBuilder {
this.proxyUrl = url;
return this;
}
/**
* Android only.
* Use this function to enable Qonversion SDK Kids mode.
* With this mode activated, our SDK does not collect any information that violates Google Children’s Privacy Policy.
* @return builder instance for chain calls.
*/
enableKidsMode(): QonversionConfigBuilder {
this.kidsMode = true;
return this;
}
/**
* Generate {@link QonversionConfig} instance with all the provided configurations.
*
* @return the complete {@link QonversionConfig} instance.
*/
build(): QonversionConfig {
return new QonversionConfig(
this.projectKey,
this.launchMode,
this.environment,
this.entitlementsCacheLifetime,
this.entitlementsUpdateListener,
this.proxyUrl,
this.kidsMode
)
}
}
export default QonversionConfigBuilder;