-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbatchStub.ts
203 lines (184 loc) · 5.5 KB
/
batchStub.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import { BatchSDK } from "../types";
import { InboxNotificationSource } from "./modules/inbox";
import { AndroidNotificationTypes, iOSNotificationTypes } from "./modules/push";
import { BatchUserAttributeType } from "./modules/user";
/* tslint:disable:no-console */
class MessagingStub implements BatchSDK.MessagingModule {
public setDoNotDisturbEnabled(_enabled: boolean) {}
public showPendingMessage() {}
}
class PushStub implements BatchSDK.PushModule {
public AndroidNotificationTypes: typeof AndroidNotificationTypes;
public iOSNotificationTypes: typeof iOSNotificationTypes;
constructor() {
this.AndroidNotificationTypes = AndroidNotificationTypes;
this.iOSNotificationTypes = iOSNotificationTypes;
}
public refreshToken() {}
public requestNotificationAuthorization() {}
public requestProvisionalNotificationAuthorization() {}
public setiOSShowForegroundNotifications(_showForeground: boolean) {}
public setAndroidNotificationTypes(_notifTypes: unknown) {}
public setiOSNotificationTypes(_notifTypes: unknown) {}
public clearBadge() {}
public dismissNotifications() {}
public getLastKnownPushToken(): Promise<undefined | string> {
return Promise.resolve(undefined);
}
}
class ProfileStub implements BatchSDK.ProfileModule {
public eventAttributes: typeof BatchSDK.BatchEventAttributes;
constructor() {
this.eventAttributes = BatchEventDataStub;
}
public getEditor(): BatchSDK.BatchProfileAttributeEditor {
return new BatchUserDataEditorStub();
}
public trackEvent(
_name: string,
_data?: BatchEventDataStub
): Promise<string | undefined> {
return Promise.resolve("");
}
public trackLocation(_location: BatchSDK.Location): void {}
public identify(_identifier: string | null): void {}
}
class UserStub implements BatchSDK.UserModule {
public BatchUserAttributeType: typeof BatchSDK.BatchUserAttributeType;
constructor() {
this.BatchUserAttributeType = BatchUserAttributeType;
}
public getLanguage(): Promise<undefined | string> {
return Promise.resolve(undefined);
}
public getRegion(): Promise<undefined | string> {
return Promise.resolve(undefined);
}
public getIdentifier(): Promise<undefined | string> {
return Promise.resolve(undefined);
}
public getInstallationID(): Promise<undefined | string> {
return Promise.resolve(undefined);
}
public getAttributes(): Promise<{
[key: string]: BatchSDK.BatchUserAttribute;
}> {
return Promise.resolve({});
}
public getTagCollections(): Promise<{ [key: string]: string[] }> {
return Promise.resolve({});
}
public clearInstallationData(): void {}
}
class InboxStub implements BatchSDK.InboxModule {
public NotificationSource: typeof InboxNotificationSource;
constructor() {
this.NotificationSource = InboxNotificationSource;
}
getFetcherForInstallation(
_maxPageSize?: number,
_limit?: number
): Promise<BatchSDK.InboxFetcher> {
return new Promise(() => {});
}
getFetcherForUser(
_userIdentifier: string,
_authenticationKey: string,
_maxPageSize?: number,
_limit?: number
): Promise<BatchSDK.InboxFetcher> {
return new Promise(() => {});
}
}
class BatchEventDataStub implements BatchSDK.BatchEventAttributes {
public put(
_key: unknown,
_value:
| string
| number
| boolean
| Date
| URL
| Array<string>
| BatchSDK.BatchEventAttributes
| Array<BatchSDK.BatchEventAttributes>
) {
return this;
}
}
class BatchUserDataEditorStub implements BatchSDK.BatchProfileAttributeEditor {
public setLanguage(_language: string | null) {
return this;
}
public setRegion(_region: string | null) {
return this;
}
public setEmailAddress(_email: string | null) {
return this;
}
public setEmailMarketingSubscription(_state: "subscribed" | "unsubscribed") {
return this;
}
public setPhoneNumber(_phoneNumber: string | null) {
return this;
}
public setSMSMarketingSubscription(_state: "subscribed" | "unsubscribed") {
return this;
}
public setAttribute(
_key: string,
_value: string | number | boolean | Date | URL
) {
return this;
}
public removeAttribute(_key: string) {
return this;
}
public addToArray(_key: string, _value: string) {
return this;
}
public removeFromArray(_key: string, _value: string) {
return this;
}
public save() {
return this;
}
}
export class BatchStub implements BatchSDK.Batch {
public push: BatchSDK.PushModule;
public profile: BatchSDK.ProfileModule;
public user: BatchSDK.UserModule;
public messaging: BatchSDK.MessagingModule;
public inbox: BatchSDK.InboxModule;
constructor() {
this.push = new PushStub();
this.profile = new ProfileStub();
this.user = new UserStub();
this.messaging = new MessagingStub();
this.inbox = new InboxStub();
}
public on(
_event: string,
_listener: (
eventName: string,
parameters: { [key: string]: unknown }
) => void
): void {}
public off(_event?: string): void {}
public setConfig(_config: BatchSDK.Config): void {}
public start(): void {
if (console && console.log) {
console.log("Batch is not supported in this environment");
}
}
public optIn(): void {}
public optOut(): void {}
public optOutAndWipeData(): void {}
public isOptedOut(): Promise<boolean> {
return Promise.resolve(false);
}
public setFindMyInstallationEnabled(_enabled: boolean): void {}
public updateAutomaticDataCollection(
_dataCollection: BatchSDK.DataCollectionConfig
): void {}
}