-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.ts
More file actions
94 lines (75 loc) · 2.53 KB
/
index.ts
File metadata and controls
94 lines (75 loc) · 2.53 KB
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
import { NativeModules, Platform, NativeEventEmitter } from 'react-native';
import type { Spec, SPCampaigns, SPUserData, LoadMessageParams } from './types';
const LINKING_ERROR =
`The package '@sourcepoint/react-native-cmp' doesn't seem to be linked. Make sure: \n\n` +
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
'- You rebuilt the app after installing the package\n' +
'- You are not using Expo Go\n';
// @ts-expect-error
const isTurboModuleEnabled = global.__turboModuleProxy != null;
const RNSourcepointCmpModule = isTurboModuleEnabled
? require('./NativeSourcepointCmp').default
: NativeModules.RNSourcepointCmp;
const RNSourcepointCmp = RNSourcepointCmpModule
? RNSourcepointCmpModule
: new Proxy(
{},
{
get() {
throw new Error(LINKING_ERROR);
},
}
);
export * from './types';
export type * from './types';
export class SPConsentManager implements Spec {
emitter = new NativeEventEmitter(RNSourcepointCmp);
build(
accountId: number,
propertyId: number,
propertyName: string,
campaigns: SPCampaigns
) {
RNSourcepointCmp.build(accountId, propertyId, propertyName, campaigns);
}
getUserData(): Promise<SPUserData> {
return RNSourcepointCmp.getUserData();
}
loadMessage(params?: LoadMessageParams) {
RNSourcepointCmp.loadMessage(params);
}
clearLocalData() {
RNSourcepointCmp.clearLocalData();
}
loadGDPRPrivacyManager(pmId: string) {
RNSourcepointCmp.loadGDPRPrivacyManager(pmId);
}
loadUSNatPrivacyManager(pmId: string) {
RNSourcepointCmp.loadUSNatPrivacyManager(pmId);
}
onAction(callback: (action: string) => void): void {
this.emitter.removeAllListeners('onAction');
this.emitter.addListener('onAction', callback);
}
onSPUIReady(callback: () => void): void {
this.emitter.removeAllListeners('onSPUIReady');
this.emitter.addListener('onSPUIReady', callback);
}
onSPUIFinished(callback: () => void): void {
this.emitter.removeAllListeners('onSPUIFinished');
this.emitter.addListener('onSPUIFinished', callback);
}
onFinished(callback: (userData: SPUserData) => void) {
this.emitter.removeAllListeners('onSPFinished');
this.emitter.addListener('onSPFinished', callback);
}
onError(callback: (description: string) => void): void {
this.emitter.removeAllListeners('onError');
this.emitter.addListener('onError', callback);
}
dispose(): void {
RNSourcepointCmp.supportedEvents()?.forEach(
this.emitter.removeAllListeners
);
}
}