cbcore-ts 1.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.
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/uicore.iml +9 -0
- package/.idea/vcs.xml +6 -0
- package/.jshintrc +4 -0
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/compiledScripts/CBCore.d.ts +54 -0
- package/compiledScripts/CBCore.js +182 -0
- package/compiledScripts/CBCore.js.map +7 -0
- package/compiledScripts/CBDataInterfaces.d.ts +156 -0
- package/compiledScripts/CBDataInterfaces.js +35 -0
- package/compiledScripts/CBDataInterfaces.js.map +7 -0
- package/compiledScripts/CBLanguageService.d.ts +43 -0
- package/compiledScripts/CBLanguageService.js +167 -0
- package/compiledScripts/CBLanguageService.js.map +7 -0
- package/compiledScripts/CBServerClient.d.ts +10 -0
- package/compiledScripts/CBServerClient.js +88 -0
- package/compiledScripts/CBServerClient.js.map +7 -0
- package/compiledScripts/CBSocketCallbackHolder.d.ts +65 -0
- package/compiledScripts/CBSocketCallbackHolder.js +343 -0
- package/compiledScripts/CBSocketCallbackHolder.js.map +7 -0
- package/compiledScripts/CBSocketClient.d.ts +70 -0
- package/compiledScripts/CBSocketClient.js +371 -0
- package/compiledScripts/CBSocketClient.js.map +7 -0
- package/compiledScripts/index.d.ts +6 -0
- package/compiledScripts/index.js +23 -0
- package/compiledScripts/index.js.map +7 -0
- package/etsc.config.mjs +23 -0
- package/package.json +51 -0
- package/rollup.config.js +49 -0
- package/scripts/CBCore.ts +381 -0
- package/scripts/CBDataInterfaces.ts +336 -0
- package/scripts/CBLanguageService.ts +371 -0
- package/scripts/CBServerClient.ts +147 -0
- package/scripts/CBSocketCallbackHolder.ts +872 -0
- package/scripts/CBSocketClient.ts +748 -0
- package/scripts/index.ts +18 -0
- package/tsconfig.json +69 -0
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FIRST,
|
|
3
|
+
FIRST_OR_NIL,
|
|
4
|
+
IS,
|
|
5
|
+
IS_NOT,
|
|
6
|
+
nil,
|
|
7
|
+
UICore,
|
|
8
|
+
UILink,
|
|
9
|
+
UIObject,
|
|
10
|
+
UIRoute,
|
|
11
|
+
UIViewBroadcastEvent,
|
|
12
|
+
YES
|
|
13
|
+
} from "../../uicore-ts"
|
|
14
|
+
import { CBLanguageService } from "./CBLanguageService"
|
|
15
|
+
import { CBLocalizedTextObject, CBUserProfile } from "./CBDataInterfaces"
|
|
16
|
+
import { CBServerClient } from "./CBServerClient"
|
|
17
|
+
import { CBSocketClient } from "./CBSocketClient"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
declare interface CBDialogViewShower {
|
|
21
|
+
|
|
22
|
+
alert(text: string, dismissCallback?: Function)
|
|
23
|
+
localizedAlert(textObject: CBLocalizedTextObject, dismissCallback?: Function)
|
|
24
|
+
|
|
25
|
+
showActionIndicatorDialog(message: string, dismissCallback?: Function)
|
|
26
|
+
hideActionIndicatorDialog()
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare const CBCoreInitializerObject: any
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
export class CBCore extends UIObject {
|
|
34
|
+
|
|
35
|
+
private static _sharedInstance: CBCore
|
|
36
|
+
|
|
37
|
+
viewCores: UICore[] = []
|
|
38
|
+
|
|
39
|
+
_isUserLoggedIn: boolean = nil
|
|
40
|
+
_cachedMinimizedChatInquiryIDs: string[] = nil
|
|
41
|
+
_socketClient: CBSocketClient = new CBSocketClient(this)
|
|
42
|
+
_serverClient: CBServerClient = new CBServerClient(this)
|
|
43
|
+
|
|
44
|
+
_functionsToCallForEachSocketClient: (() => void)[] = []
|
|
45
|
+
|
|
46
|
+
_models: any[] = []
|
|
47
|
+
|
|
48
|
+
dialogViewShowerClass: CBDialogViewShower = nil
|
|
49
|
+
|
|
50
|
+
constructor() {
|
|
51
|
+
|
|
52
|
+
super()
|
|
53
|
+
|
|
54
|
+
if (CBCoreInitializerObject) {
|
|
55
|
+
|
|
56
|
+
CBLanguageService.useStoredLanguageValues(CBCoreInitializerObject.languageValues)
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
window.addEventListener("storage", function (this: CBCore, event: StorageEvent) {
|
|
62
|
+
|
|
63
|
+
if (event.newValue == event.oldValue) {
|
|
64
|
+
|
|
65
|
+
return
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//console.log("" + event.key + " changed to " + event.newValue + " from " + event.oldValue);
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
if (event.key == "CBLanguageKey") {
|
|
74
|
+
|
|
75
|
+
this.didSetLanguageKey()
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
}.bind(this))
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
//this.checkIfUserIsAuthenticated();
|
|
83
|
+
|
|
84
|
+
this.didSetLanguageKey()
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
static initIfNeededWithViewCore(viewCore: UICore) {
|
|
91
|
+
|
|
92
|
+
CBCore.sharedInstance.viewCores.push(viewCore);
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
static get sharedInstance() {
|
|
99
|
+
if (!CBCore._sharedInstance) {
|
|
100
|
+
CBCore._sharedInstance = new CBCore()
|
|
101
|
+
}
|
|
102
|
+
return CBCore._sharedInstance
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
static broadcastEventName = {
|
|
110
|
+
|
|
111
|
+
"userDidLogIn": "UserDidLogIn",
|
|
112
|
+
"userDidLogOut": "UserDidLogOut"
|
|
113
|
+
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
broadcastMessageInRootViewTree(message: UIViewBroadcastEvent) {
|
|
117
|
+
|
|
118
|
+
this.viewCores.everyElement.rootViewController.view.broadcastEventInSubtree(message)
|
|
119
|
+
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
get socketClient() {
|
|
127
|
+
return this._socketClient
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
get serverClient() {
|
|
131
|
+
return this._serverClient
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
set isUserLoggedIn(isUserLoggedIn: boolean) {
|
|
139
|
+
|
|
140
|
+
const previousValue = this.isUserLoggedIn
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
localStorage.setItem("CBIsUserLoggedIn", "" + isUserLoggedIn)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
//this._isUserLoggedIn = isUserLoggedIn;
|
|
147
|
+
|
|
148
|
+
this.didSetIsUserLoggedIn(previousValue)
|
|
149
|
+
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
didSetIsUserLoggedIn(previousValue: boolean) {
|
|
153
|
+
|
|
154
|
+
const isUserLoggedIn = this.isUserLoggedIn
|
|
155
|
+
|
|
156
|
+
if (isUserLoggedIn && previousValue != isUserLoggedIn) {
|
|
157
|
+
|
|
158
|
+
// Send message to views
|
|
159
|
+
|
|
160
|
+
this.broadcastMessageInRootViewTree({
|
|
161
|
+
|
|
162
|
+
name: CBCore.broadcastEventName.userDidLogIn,
|
|
163
|
+
parameters: nil
|
|
164
|
+
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
this.updateLinkTargets()
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
}
|
|
171
|
+
else if (previousValue != isUserLoggedIn) {
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
this.performFunctionWithDelay(0.01, function (this: CBCore) {
|
|
175
|
+
|
|
176
|
+
UIRoute.currentRoute.routeByRemovingComponentsOtherThanOnesNamed([
|
|
177
|
+
|
|
178
|
+
"settings",
|
|
179
|
+
"inquiry"
|
|
180
|
+
|
|
181
|
+
]).apply()
|
|
182
|
+
|
|
183
|
+
this.broadcastMessageInRootViewTree({
|
|
184
|
+
|
|
185
|
+
name: CBCore.broadcastEventName.userDidLogOut,
|
|
186
|
+
parameters: nil
|
|
187
|
+
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
this.updateLinkTargets()
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
}.bind(this))
|
|
194
|
+
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
private updateLinkTargets() {
|
|
201
|
+
|
|
202
|
+
this.viewCores.everyElement.rootViewController.view.forEachViewInSubtree(function (view) {
|
|
203
|
+
if (view instanceof UILink) {
|
|
204
|
+
view.updateTarget()
|
|
205
|
+
}
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
get isUserLoggedIn() {
|
|
211
|
+
|
|
212
|
+
const result = (localStorage.getItem("CBIsUserLoggedIn") == "true")
|
|
213
|
+
|
|
214
|
+
return result
|
|
215
|
+
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
get userProfile() {
|
|
221
|
+
|
|
222
|
+
var result = nil
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
try {
|
|
226
|
+
result = JSON.parse(localStorage.getItem("CBUserProfile"))
|
|
227
|
+
} catch (error) {
|
|
228
|
+
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// if (IS_NOT(result)) {
|
|
232
|
+
|
|
233
|
+
// // Get userID from inquiryAccessKey if possible
|
|
234
|
+
// var inquiryKey = this.inquiryAccessKey;
|
|
235
|
+
|
|
236
|
+
// if (IS(inquiryKey)) {
|
|
237
|
+
|
|
238
|
+
// result = FIRST_OR_NIL(this.inquiriesModel.inquiriesByCurrentUser.firstElement).inquirer
|
|
239
|
+
|
|
240
|
+
// }
|
|
241
|
+
|
|
242
|
+
// }
|
|
243
|
+
|
|
244
|
+
return FIRST_OR_NIL(result)
|
|
245
|
+
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
set userProfile(userProfile: CBUserProfile) {
|
|
249
|
+
|
|
250
|
+
if (IS_NOT(userProfile)) {
|
|
251
|
+
|
|
252
|
+
localStorage.removeItem("CBUserProfile")
|
|
253
|
+
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
localStorage.setItem("CBUserProfile", JSON.stringify(userProfile))
|
|
257
|
+
|
|
258
|
+
this.didSetUserProfile()
|
|
259
|
+
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
didSetUserProfile() {
|
|
263
|
+
|
|
264
|
+
this.isUserLoggedIn = IS(this.userProfile)
|
|
265
|
+
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
set languageKey(languageKey: string) {
|
|
270
|
+
|
|
271
|
+
if (IS_NOT(languageKey)) {
|
|
272
|
+
|
|
273
|
+
localStorage.removeItem("CBLanguageKey")
|
|
274
|
+
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
localStorage.setItem("CBLanguageKey", JSON.stringify(languageKey))
|
|
278
|
+
|
|
279
|
+
this.didSetLanguageKey()
|
|
280
|
+
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
get languageKey() {
|
|
284
|
+
|
|
285
|
+
const result = FIRST(localStorage.getItem("CBLanguageKey"), CBLanguageService.defaultLanguageKey).replace(
|
|
286
|
+
"\"",
|
|
287
|
+
""
|
|
288
|
+
).replace("\"", "")
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
return result
|
|
292
|
+
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
didSetLanguageKey() {
|
|
296
|
+
|
|
297
|
+
UIRoute.currentRoute.routeWithComponent(
|
|
298
|
+
"settings",
|
|
299
|
+
{ "language": this.languageKey },
|
|
300
|
+
YES
|
|
301
|
+
).applyByReplacingCurrentRouteInHistory()
|
|
302
|
+
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
get externalServiceIdentifier(): { accessKey: string; serviceID: string; organizationID: string } {
|
|
307
|
+
|
|
308
|
+
const result = JSON.parse(localStorage.getItem("CBExternalServiceIdentifier"))
|
|
309
|
+
|
|
310
|
+
return result
|
|
311
|
+
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
set externalServiceIdentifier(externalServiceIdentifier: { accessKey: string; serviceID: string; organizationID: string }) {
|
|
315
|
+
|
|
316
|
+
localStorage.setItem("CBExternalServiceIdentifier", JSON.stringify(externalServiceIdentifier))
|
|
317
|
+
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
reloadSocketConnection() {
|
|
322
|
+
|
|
323
|
+
// @ts-ignore
|
|
324
|
+
this.socketClient.socket.disconnect()
|
|
325
|
+
|
|
326
|
+
const messagesToBeSent = this.socketClient._messagesToBeSent.filter(function (messageItem, index, array) {
|
|
327
|
+
|
|
328
|
+
return (!messageItem.isBoundToUserWithID || messageItem.isBoundToUserWithID ==
|
|
329
|
+
CBCore.sharedInstance.userProfile._id)
|
|
330
|
+
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
this._socketClient = new CBSocketClient(this)
|
|
334
|
+
this._socketClient._messagesToBeSent = messagesToBeSent
|
|
335
|
+
|
|
336
|
+
const socketClient = this._socketClient
|
|
337
|
+
|
|
338
|
+
this._models.forEach(function (model, index, array) {
|
|
339
|
+
|
|
340
|
+
model.setSocketClient(socketClient)
|
|
341
|
+
|
|
342
|
+
})
|
|
343
|
+
|
|
344
|
+
this._functionsToCallForEachSocketClient.forEach(function (functionToCall, index, array) {
|
|
345
|
+
|
|
346
|
+
functionToCall()
|
|
347
|
+
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
callFunctionForEachSocketClient(functionToCall: () => void) {
|
|
356
|
+
this._functionsToCallForEachSocketClient.push(functionToCall)
|
|
357
|
+
functionToCall()
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export type CBReferenceID = string;
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export interface CBLanguageItem {
|
|
10
|
+
|
|
11
|
+
value: string;
|
|
12
|
+
languageKey: string;
|
|
13
|
+
itemKey: string;
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export interface LanguagesData {
|
|
19
|
+
[key: string]: {
|
|
20
|
+
[key: string]: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
export interface CBFinancialAmount {
|
|
29
|
+
|
|
30
|
+
amount: number;
|
|
31
|
+
currency: string;
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
export interface CBLocalizedTextObject {
|
|
37
|
+
|
|
38
|
+
[key: string]: string
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
export interface CBDropdownData<T> {
|
|
44
|
+
|
|
45
|
+
_id: CBReferenceID;
|
|
46
|
+
name?: CBLocalizedTextObject;
|
|
47
|
+
dropdownCode: string;
|
|
48
|
+
data: CBDropdownDataItem<T>[];
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
export interface CBDropdownDataItem<T> {
|
|
54
|
+
|
|
55
|
+
_id: CBReferenceID;
|
|
56
|
+
title: CBLocalizedTextObject;
|
|
57
|
+
rowsData?: CBDropdownDataItem<T>[]
|
|
58
|
+
isADropdownDataSection: boolean;
|
|
59
|
+
isADropdownDataRow: boolean;
|
|
60
|
+
|
|
61
|
+
attachedObject: T
|
|
62
|
+
|
|
63
|
+
itemCode: string;
|
|
64
|
+
dropdownCode: string;
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
export interface CBFileAccessor {
|
|
75
|
+
|
|
76
|
+
fileData: CBFileData;
|
|
77
|
+
createdAt: number;
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
export interface CBFileData {
|
|
83
|
+
|
|
84
|
+
_id: string;
|
|
85
|
+
|
|
86
|
+
name: string;
|
|
87
|
+
dataURL: string;
|
|
88
|
+
type: string;
|
|
89
|
+
isLimitedAccess?: boolean;
|
|
90
|
+
accessibleToUsers?: CBUserProfilePublic[];
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export enum CBAuthenticationSource {
|
|
95
|
+
|
|
96
|
+
google = 10,
|
|
97
|
+
facebook = 11,
|
|
98
|
+
emailAccessLink = 200,
|
|
99
|
+
password = 220,
|
|
100
|
+
inquiryAccessLink = 500
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// AsdAsd
|
|
105
|
+
|
|
106
|
+
export interface CBCoreInitializer {
|
|
107
|
+
|
|
108
|
+
languageValues: LanguagesData;
|
|
109
|
+
defaultLanguageKey: string;
|
|
110
|
+
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface CBLoginKey {
|
|
114
|
+
|
|
115
|
+
key: string;
|
|
116
|
+
|
|
117
|
+
accessToken: string;
|
|
118
|
+
|
|
119
|
+
storeAccessTokenInClient: boolean;
|
|
120
|
+
|
|
121
|
+
authenticationSource: CBAuthenticationSource;
|
|
122
|
+
|
|
123
|
+
userID: CBReferenceID;
|
|
124
|
+
|
|
125
|
+
isValid: boolean;
|
|
126
|
+
|
|
127
|
+
loginDate?: Date;
|
|
128
|
+
logoutDate?: Date;
|
|
129
|
+
|
|
130
|
+
createdAt: Date;
|
|
131
|
+
updatedAt: Date;
|
|
132
|
+
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface CBUserPassword {
|
|
136
|
+
|
|
137
|
+
passwordHash: string;
|
|
138
|
+
|
|
139
|
+
userID: CBReferenceID;
|
|
140
|
+
|
|
141
|
+
isValid: boolean;
|
|
142
|
+
|
|
143
|
+
createdAt: Date;
|
|
144
|
+
updatedAt: Date;
|
|
145
|
+
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export interface CBAdministratorRightsDescriptor {
|
|
149
|
+
|
|
150
|
+
userProfile: CBUserProfile;
|
|
151
|
+
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export interface CBSubscription {
|
|
155
|
+
|
|
156
|
+
_id: CBReferenceID;
|
|
157
|
+
startDate: Date;
|
|
158
|
+
endDate?: Date;
|
|
159
|
+
|
|
160
|
+
isIndefinite: boolean;
|
|
161
|
+
|
|
162
|
+
subscriptionKind: number;// alternatiiv oleks string/objectId, mis viitaks tüübi objektile eraldi tabelis
|
|
163
|
+
createdAt: Date;
|
|
164
|
+
updatedAt: Date;
|
|
165
|
+
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
//Asdasd
|
|
169
|
+
|
|
170
|
+
export type CBUserProfilePublic = any;
|
|
171
|
+
export type CBUserProfile = any;
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
export interface SocketClientInterface {
|
|
175
|
+
|
|
176
|
+
[x: string]: SocketClientFunction<any, any>;
|
|
177
|
+
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
export interface SocketClientResult<ResultType> {
|
|
182
|
+
|
|
183
|
+
responseMessage: any;
|
|
184
|
+
result: ResultType;
|
|
185
|
+
errorResult: any;
|
|
186
|
+
respondWithMessage: CBSocketMessageSendResponseFunction;
|
|
187
|
+
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
export type SocketClientFunction<MessageType, ResultType> = (
|
|
192
|
+
messageData: MessageType,
|
|
193
|
+
completionPolicy?: string,
|
|
194
|
+
isUserBound?: boolean
|
|
195
|
+
) => Promise<SocketClientResult<ResultType>>;
|
|
196
|
+
|
|
197
|
+
export type SocketClientNoMessageFunction<ResultType> = (
|
|
198
|
+
messageData?: null,
|
|
199
|
+
completionPolicy?: string,
|
|
200
|
+
isUserBound?: boolean
|
|
201
|
+
) => Promise<SocketClientResult<ResultType>>;
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
export interface CBSocketMultipleMessageObject<MessageDataType = any> {
|
|
208
|
+
|
|
209
|
+
key: string;
|
|
210
|
+
message: CBSocketMessage<MessageDataType>;
|
|
211
|
+
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
// CBSocket communication messages
|
|
216
|
+
export interface CBSocketMessage<MessageDataType = any> {
|
|
217
|
+
|
|
218
|
+
identifier: string;
|
|
219
|
+
inResponseToIdentifier?: string;
|
|
220
|
+
keepWaitingForResponses?: boolean;
|
|
221
|
+
|
|
222
|
+
messageData: MessageDataType;
|
|
223
|
+
|
|
224
|
+
// This is sent from client to server with requests
|
|
225
|
+
storedResponseHash?: string;
|
|
226
|
+
|
|
227
|
+
// This is always present on messages sent from the server side
|
|
228
|
+
messageDataHash?: string;
|
|
229
|
+
|
|
230
|
+
// This tells the client to store this message for future use
|
|
231
|
+
canBeStoredAsResponse?: boolean;
|
|
232
|
+
|
|
233
|
+
// This tells the client to use the previously stored response
|
|
234
|
+
useStoredResponse?: boolean;
|
|
235
|
+
|
|
236
|
+
// This tells the client that the response is valid for at least this long in ms
|
|
237
|
+
responseValidityDuration?: number;
|
|
238
|
+
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
export interface CBSocketMultipleMessage extends CBSocketMessage<CBSocketMultipleMessageObject[]> {
|
|
243
|
+
|
|
244
|
+
shouldGroupResponses: boolean;
|
|
245
|
+
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
export type CBSocketMessageSendResponseFunctionBase<ResponseMessageType> = (
|
|
250
|
+
responseMessage: ResponseMessageType,
|
|
251
|
+
completion?: CBSocketMessageCompletionFunction
|
|
252
|
+
) => Promise<string>;
|
|
253
|
+
|
|
254
|
+
export type CBSocketMessageCompletionFunction = (
|
|
255
|
+
responseMessage: any,
|
|
256
|
+
respondWithMessage: CBSocketMessageSendResponseFunction
|
|
257
|
+
) => void;
|
|
258
|
+
export type CBSocketMessageHandlerFunction<ResponseMessageType = any> = (
|
|
259
|
+
message: any,
|
|
260
|
+
respondWithMessage: CBSocketMessageSendResponseFunction<ResponseMessageType>
|
|
261
|
+
) => void;
|
|
262
|
+
|
|
263
|
+
export type CBSocketMultipleMessagecompletionFunction = (
|
|
264
|
+
responseMessages: any[],
|
|
265
|
+
callcompletionFunctions: () => void
|
|
266
|
+
) => void;
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
export interface CBSocketMessageSendResponseFunction<ResponseMessageType = any> extends CBSocketMessageSendResponseFunctionBase<ResponseMessageType> {
|
|
270
|
+
respondingToMainResponse: boolean;
|
|
271
|
+
|
|
272
|
+
excludeMessageFromAutomaticConnectionEvents: () => void;
|
|
273
|
+
|
|
274
|
+
setResponseValidityDuration(duration: number);
|
|
275
|
+
|
|
276
|
+
useStoredResponseWithErrorResponse();
|
|
277
|
+
|
|
278
|
+
sendErrorResponse(message?: any, completion?: CBSocketMessageCompletionFunction);
|
|
279
|
+
|
|
280
|
+
sendIntermediateResponse(updateMessage: any, completion?: CBSocketMessageCompletionFunction);
|
|
281
|
+
|
|
282
|
+
// This tells the client to use the stored response if responseHash matches and also enables storing of responses
|
|
283
|
+
// in the client in the first place. Returns true if the hash matched.
|
|
284
|
+
confirmStoredResponseHash(responseHash: string, completion?: CBSocketMessageCompletionFunction): boolean;
|
|
285
|
+
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
// Socket handshake messages
|
|
291
|
+
export interface CBSocketHandshakeInitMessage {
|
|
292
|
+
|
|
293
|
+
accessToken?: string;
|
|
294
|
+
userID: CBReferenceID;
|
|
295
|
+
|
|
296
|
+
loginKey?: string;
|
|
297
|
+
inquiryAccessKey?: string;
|
|
298
|
+
|
|
299
|
+
instanceIdentifier: string;
|
|
300
|
+
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
export interface CBSocketHandshakeResponseMessage {
|
|
305
|
+
|
|
306
|
+
accepted: boolean;
|
|
307
|
+
|
|
308
|
+
userProfile?: CBUserProfile;
|
|
309
|
+
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
export type TypeWithoutKey<Type, Key> = Pick<Type, Exclude<keyof Type, Key>>;
|
|
317
|
+
|
|
318
|
+
export type TypeWithoutID<Type> = TypeWithoutKey<Type, "_id">;
|
|
319
|
+
|
|
320
|
+
export type Diff<T extends keyof any, U extends keyof any> =
|
|
321
|
+
({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T];
|
|
322
|
+
|
|
323
|
+
export type Overwrite<T, U> = Pick<T, Diff<keyof T, keyof U>> & U;
|
|
324
|
+
|
|
325
|
+
export type RecursivePartial<T> = {
|
|
326
|
+
[P in keyof T]?:
|
|
327
|
+
T[P] extends (infer U)[] ? RecursivePartial<U>[] :
|
|
328
|
+
T[P] extends object ? RecursivePartial<T[P]> :
|
|
329
|
+
T[P];
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
|