-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKASClient.js
12752 lines (12752 loc) · 648 KB
/
KASClient.js
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var KASClient;
(function (KASClient) {
var App;
(function (App) {
/**
* To simulate clients on older versions, versions starting from "0", "1", "2", ...
* @param {string} version
*/
function setCompatibilityMode(version) {
KASClient.Version.setClientSupportedVersion(version);
}
App.setCompatibilityMode = setCompatibilityMode;
/**
* Gets users' details (name, pic, phone number, etc.) against their ids
* @param {string[]} userIds array of user ids
* @param {Callback} callback with below parameters:
* * * * @param {Dictionary<UserId: string, UserInfo: KASUser>} userIdToInfoMap (users' details against their ids) can be null in case of error
* * * * @param {string} error message in case of error, null otherwise
*/
function getUsersDetailsAsync(userIds, callback) {
//////////// MOCK ////////////
if (KASClient.shouldMockData()) {
KASClient.getJsonFromFileAsync("mock/user.json", function (userJson, error) {
var userIdToInfoMap = {};
for (var i = 0; i < userIds.length; i++) {
var userId = userIds[i];
var userInfo = userJson;
userInfo["id"] = "USR_" + userId;
userInfo["uId"] = userId;
userIdToInfoMap[userId] = KASClient.KASUser.fromJSON(userInfo);
}
if (callback) {
callback(userIdToInfoMap, null);
}
});
return;
}
//////////// ACTUAL ////////////
KASClient.getUserDetails(userIds, function (userIdToInfoJson, error) {
var userIdToInfoMap = {};
for (var userId in userIdToInfoJson) {
var userInfo = userIdToInfoJson[userId];
if (typeof userInfo === "string") {
userInfo = KASClient.parseJsonObject(userInfo);
}
userIdToInfoMap[userId] = KASClient.KASUser.fromJSON(userInfo);
}
if (callback) {
callback(userIdToInfoMap, error);
}
});
}
App.getUsersDetailsAsync = getUsersDetailsAsync;
/**
* Gets users' details (name, pic, phone number, etc.) against their ids
* @param {Callback} callback with below parameters:
* * * * @param {string} token got from integeration service
* * * * @param {string} error message in case of error, null otherwise
*/
function getIntegerationServiceTokenAsync(callback) {
KASClient.getIntegerationServiceToken(function (token, error) {
if (callback) {
callback(token, error);
}
});
}
App.getIntegerationServiceTokenAsync = getIntegerationServiceTokenAsync;
/**
* Gets deviceId
* @param {Callback} callback with below parameters:
* * * * @param {string} deviceId got from integeration service
* * * * @param {string} error message in case of error, null otherwise
*/
function getDeviceIdAsync(callback) {
KASClient.getDeviceId(function (deviceId, error) {
if (callback) {
callback(deviceId, error);
}
});
}
App.getDeviceIdAsync = getDeviceIdAsync;
/**
* Shows a native contact picker, and returns an array of all the selected users' details
* @param {string} title of Contact Picker
* @param {string[]} selectedMutableUser array of selected userIds
* @param {string[]} selectedImmutableUser array of fixed selected userIds
* @param {boolean} isSingleSelection single selection in Contact Picker
* @param {Callback} callback with below parameters:
* * * * @param {KASUser[]} selectedUsers (array of user details) can be null in case of error
* * * * @param {string} error message in case of error, null otherwise
*/
function showContactPickerAsync(title, selectedMutableUser, selectedImmutableUser, isSingleSelection, callback) {
//////////// MOCK ////////////
if (KASClient.shouldMockData()) {
KASClient.getJsonFromFileAsync("mock/user.json", function (userJson, error) {
var userInfo = KASClient.KASUser.fromJSON(userJson);
if (callback) {
callback([userInfo, userInfo, userInfo], null);
}
});
return;
}
//////////// ACTUAL ////////////
KASClient.getSelectedUsers([title, selectedMutableUser, selectedImmutableUser, isSingleSelection], function (usersJson, error) {
var users = [];
for (var i in usersJson) {
users.push(KASClient.KASUser.fromJSON(usersJson[i]));
}
if (callback) {
callback(users, error);
}
});
}
App.showContactPickerAsync = showContactPickerAsync;
/**
* Gets whether talkback is enabled or not
* @param {Callback} callback with below parameters:
* * * * @param {boolean} talkBackEnabled true if talkback is enabled
*/
function isTalkBackEnabledAsync(callback) {
KASClient.isTalkBackEnabled(function (talkBackEnabled, error) {
if (callback && error == null) {
callback(talkBackEnabled);
}
});
}
App.isTalkBackEnabledAsync = isTalkBackEnabledAsync;
/**
* Reads the text if TalkBack/VoiceOver enabled
* @param {talkBackText} string to read by talkback
*/
function readTalkBackMessage(talkBackMessage) {
KASClient.readTalkBackMessageNative(talkBackMessage);
}
App.readTalkBackMessage = readTalkBackMessage;
/**
* Shows a native image picker, and returns the selected image path
* @param {Callback} callback with below parameters:
* * * * @param {string} selectedImagePath can be null in case of error
* * * * @param {string} error message in case of error, null otherwise
*/
function showImagePickerAsync(callback) {
//////////// MOCK ////////////
if (KASClient.shouldMockData()) {
if (callback) {
callback("file://DummyAttachmentPath", null);
}
return;
}
//////////// ACTUAL ////////////
KASClient.getAttachmentPath(callback);
}
App.showImagePickerAsync = showImagePickerAsync;
/**
* Displays an attachment picker in the native layer
* @param supportedTypes array of supported attachment types for the picker.
* @param props additional props to configure the picker
* @param callback callback with list of selected attachments
*/
function showAttachmentPickerAsync(supportedTypes, props, callback) {
KASClient.getAttachmentPaths([supportedTypes, JSON.stringify(props)], function (selectedAttachmentJson, error) {
var selectedAttachments = [];
for (var i in selectedAttachmentJson) {
selectedAttachments.push(KASClient.KASAttachmentFactory.fromJSON(JSON.parse(selectedAttachmentJson[i])));
}
if (callback) {
callback(selectedAttachments, error);
}
});
}
App.showAttachmentPickerAsync = showAttachmentPickerAsync;
/**
* Download the attachment specified
* @param attachment attachment with a valid server path to download
* @param callback callback on download completion
*/
function downloadAttachmentAsync(attachment, callback) {
KASClient.downloadAttachment(attachment.toJSON(), function (downloadedAttachmentJSON, error) {
var downloadedAttachment = KASClient.KASAttachmentFactory.fromJSON(downloadedAttachmentJSON);
if (callback) {
callback(downloadedAttachment, error);
}
});
}
App.downloadAttachmentAsync = downloadAttachmentAsync;
/**
* Download the attachment specified
* @param attachment attachment with a valid server path to download
* @param callback callback on download completion
*/
function isAttachmentDownloadingAsync(attachment, callback) {
KASClient.isAttachmentDownloading(attachment.toJSON(), function (isAttachmentDownloadingOrDownLoaded, error) {
if (callback) {
callback(isAttachmentDownloadingOrDownLoaded, error);
}
});
}
App.isAttachmentDownloadingAsync = isAttachmentDownloadingAsync;
/**
* Cancel a download operation queued for an attachment
* @param attachment
*/
function cancelAttachmentDownloadAsync(attachment, callback) {
KASClient.cancelAttachmentDownload(attachment.toJSON(), function (error) {
if (callback) {
callback(error);
}
});
}
App.cancelAttachmentDownloadAsync = cancelAttachmentDownloadAsync;
/**
* Shows a native place picker, and returns the selected place (lt, lg, n)
* @param {Callback} callback with below parameters:
* * * * @param {KASLocation} selectedLocation can be null in case of error
* * * * @param {string} error message in case of error, null otherwise
*/
function showPlacePickerAsync(callback) {
KASClient.showPlacePicker(function (locationJson, error) {
if (callback) {
callback(KASClient.KASLocation.fromJSON(locationJson), error);
}
});
}
App.showPlacePickerAsync = showPlacePickerAsync;
/**
* Shows a native duration picker with day/hour/minute
* @param {number} defaultDurationInMinutes the default duration to be shown on picker
* @param {Callback} callback with below parameters:
* * * * @param {number} durationInMinutes selected duration in minutes
* * * * @param {string} error message in case of error, null otherwise
*/
function showDurationPickerAsync(defaultDurationInMinutes, callback) {
KASClient.showDurationPicker(defaultDurationInMinutes, function (durationString, error) {
if (callback) {
callback(parseInt(durationString), error);
}
});
}
App.showDurationPickerAsync = showDurationPickerAsync;
/**
* Gets the previously stored device location
* @param {Callback} callback with below parameters:
* * * * @param {string} location can be null in case of error
* * * * @param {string} error message in case of error, null otherwise
*/
function getDeviceLocationAsync(callback) {
//////////// MOCK ////////////
if (KASClient.shouldMockData()) {
KASClient.getJsonFromFileAsync("mock/location.json", function (locationJson, error) {
if (callback) {
callback(JSON.stringify(locationJson), null);
}
});
return;
}
//////////// ACTUAL ////////////
KASClient.getLocation(callback);
}
App.getDeviceLocationAsync = getDeviceLocationAsync;
/**
* Gets the new UUID
* @param {Callback} callback with below parameters:
* * * * @param {string} uuid newly generated uuid
* * * * @param {string} error message in case of error, null otherwise
*/
function generateUUIDAsync(callback) {
//////////// MOCK ////////////
if (KASClient.shouldMockData()) {
callback(JSON.stringify(""), null);
return;
}
//////////// ACTUAL ////////////
KASClient.generateUUID(callback);
}
App.generateUUIDAsync = generateUUIDAsync;
/**
* Gets the current device location
* @param {Callback} callback with below parameters:
* * * * @param {string} location can be null in case of error
* * * * @param {string} error message in case of error, null otherwise
*/
function getCurrentDeviceLocationAsync(callback) {
//////////// MOCK ////////////
if (KASClient.shouldMockData()) {
KASClient.getJsonFromFileAsync("mock/location.json", function (locationJson, error) {
if (callback) {
callback(JSON.stringify(locationJson), null);
}
});
return;
}
//////////// ACTUAL ////////////
KASClient.getCurrentLocation(callback);
}
App.getCurrentDeviceLocationAsync = getCurrentDeviceLocationAsync;
/**
* Shows a native alert (for iOS) or a toast (for Android) with the message
* @param {string} message
*/
function showNativeErrorMessage(message) {
//////////// MOCK ////////////
if (KASClient.shouldMockData()) {
alert(message);
return;
}
//////////// ACTUAL ////////////
KASClient.showAlert(message);
}
App.showNativeErrorMessage = showNativeErrorMessage;
/**
* Gets the current app locale, the language in which the app is rendered, useful for localizing MiniApp's strings
* @param {Callback} callback with below parameters:
* * * * @param {string} locale can be null in case of error
* * * * @param {string} error message in case of error, null otherwise
*/
function getAppLocaleAsync(callback) {
//////////// MOCK ////////////
if (KASClient.shouldMockData()) {
if (callback) {
callback("en", null);
}
return;
}
//////////// ACTUAL ////////////
KASClient.getAppLocale(callback);
}
App.getAppLocaleAsync = getAppLocaleAsync;
/**
* Gets all the participant-ids of the current conversation
* @param {Callback} callback with below parameters:
* * * * @param {string} name can be null in case of error
* * * * @param {string} error message in case of error, null otherwise
*/
function getConversationParticipantsCountAsync(callback) {
KASClient.getConversationParticipantsCount(function (participantsCount, error) {
if (callback) {
callback(parseInt(participantsCount), error);
}
});
}
App.getConversationParticipantsCountAsync = getConversationParticipantsCountAsync;
/**
* Gets the current conversation name
* @param {Callback} callback with below parameters:
* * * * @param {string} name can be null in case of error
* * * * @param {string} error message in case of error, null otherwise
*/
function getConversationNameAsync(callback) {
//////////// MOCK ////////////
if (KASClient.shouldMockData()) {
if (callback) {
callback("The Conversation", null);
}
return;
}
//////////// ACTUAL ////////////
KASClient.getConversationName(callback);
}
App.getConversationNameAsync = getConversationNameAsync;
/**
* Gets the current conversation type
* @param {Callback} callback with below parameters:
* * * * @param {number} conversationType can be null in case of error
* * * * @param {string} error message in case of error, null otherwise
*/
function getConversationTypeAsync(callback) {
//////////// MOCK ////////////
if (KASClient.shouldMockData()) {
if (callback) {
callback(0, null);
}
return;
}
KASClient.getConversationType(function (conversationType, error) {
if (callback) {
callback(parseInt(conversationType), error);
}
});
}
App.getConversationTypeAsync = getConversationTypeAsync;
/**
* Dismiss the current screen (Creation, Response, or Summary)
*/
function dismissCurrentScreen() {
//////////// MOCK ////////////
if (KASClient.shouldMockData()) {
alert("dismissCurrentScreen");
return;
}
//////////// ACTUAL ////////////
KASClient.dismissScreen();
}
App.dismissCurrentScreen = dismissCurrentScreen;
/**
* Shows a native full sreen progress bar with the given text
* @param {string} text
*/
function showProgressBar(text) {
KASClient.showProgress(text);
}
App.showProgressBar = showProgressBar;
/**
* Hides the current progress bar, if any
*/
function hideProgressBar() {
KASClient.hideProgress();
}
App.hideProgressBar = hideProgressBar;
/**
* Gets the current user id who has opened the MiniApp
* @param {Callback} callback with below parameters:
* * * * @param {string} userId can be null in case of error
* * * * @param {string} error message in case of error, null otherwise
*/
function getCurrentUserIdAsync(callback) {
//////////// MOCK ////////////
if (KASClient.shouldMockData()) {
if (callback) {
callback("7dc6f31a-28ec-4c9b-91bb-ecf3ef5f4a0c", null);
}
return;
}
//////////// ACTUAL ////////////
KASClient.getCurrentUserId(callback);
}
App.getCurrentUserIdAsync = getCurrentUserIdAsync;
/**
* Sets few properties when using native toolbar
* @param {KASNativeToolbarProperties} properties
*/
function setNativeToolbarProperties(properties) {
KASClient.customizeNativeToolbar(properties.toJSON());
}
App.setNativeToolbarProperties = setNativeToolbarProperties;
/**
* Gets the package properties (user given)
* @param {Callback} callback with below parameters:
* * * * @param {JSON} properties can be null in case of error
* * * * @param {string} error message in case of error, null otherwise
*/
function getPackagePropertiesAsync(callback) {
KASClient.getPackageProperties(callback);
}
App.getPackagePropertiesAsync = getPackagePropertiesAsync;
/**
* Shows Image in Immersive view.
* @param {string[]} urls Array of images url:
*/
function showImageImmersiveView(urls, currentImageIndex) {
if (urls === void 0) { urls = []; }
if (currentImageIndex === void 0) { currentImageIndex = 0; }
KASClient.showImageInFullScreen(urls, currentImageIndex);
}
App.showImageImmersiveView = showImageImmersiveView;
/**
* Open attachment in Immersive view.
* @param {KASAttachment} attachmentObj
*/
function openAttachmentImmersiveView(attachmentObj) {
KASClient.openImmersiveViewForAttachment(attachmentObj.toJSON());
}
App.openAttachmentImmersiveView = openAttachmentImmersiveView;
/**
* checks whether app has read/write access to the storage
* @param {KASAttachmentType} attachmentType
*/
function hasStorageAccessForAttachmentType(type, callback) {
KASClient.hasStorageAccessForType(type, callback);
}
App.hasStorageAccessForAttachmentType = hasStorageAccessForAttachmentType;
/**
* Generates Base64 thumbnail for an image whose localPath is given
* @param {string} localPath localPath for the imageAttachment whose thumbnail needs to be generated:
*/
function generateBase64ThumbnailAsync(localPath, callback) {
KASClient.generateBase64ThumbnailForAttachment(localPath, callback);
}
App.generateBase64ThumbnailAsync = generateBase64ThumbnailAsync;
/**
* Gets the font size multiplier for large text.
* Current only required by iOS.
*/
function getFontSizeMultiplierAsync(callback) {
KASClient.getFontSizeMultiplier(callback);
}
App.getFontSizeMultiplierAsync = getFontSizeMultiplierAsync;
/**
* Gets the localized strings' dictionary based on current app locale.
* Strings must be provided inside the package with names like: strings_en.json, strings_hi.json, etc.
* @param {Callback} callback with below parameters:
* * * * @param {JSON} strings can be null in case of error
* * * * @param {string} error message in case of error, null otherwise
*/
function getLocalizedStringsAsync(callback) {
KASClient.getLocalizedMiniAppStrings(callback);
}
App.getLocalizedStringsAsync = getLocalizedStringsAsync;
/**
* Gets all the customization settings for a package (Used in case of Type-4 packages and their base).
* @param {Callback} callback with below parameters:
* * * * @param {JSON} settings can be null in case of error
* * * * @param {string} error message in case of error, null otherwise
*/
function getPackageCustomSettingsAsync(callback) {
KASClient.getPackageCustomSettings(callback);
}
App.getPackageCustomSettingsAsync = getPackageCustomSettingsAsync;
/**
* Logs an error for "Send report"
* @param {string} error string
*/
function logError(error) {
KASClient.logErrorNative(error);
}
App.logError = logError;
/**
* Logs data for "Send report"
* @param {string} data string
*/
function logToReport(data) {
KASClient.logToReportNative(data);
}
App.logToReport = logToReport;
/**
* Recording event for load and error telemetry
* @param {string} eventName string
* @param {string} eventType string
* @param {string} props JSON
*/
function recordEvent(eventName, eventType, props) {
if (props === void 0) { props = JSON.parse("{}"); }
KASClient.recordEventNative(eventName, eventType, props);
}
App.recordEvent = recordEvent;
/**
* Checks if the current user an O365 subscriber
* @param {Callback} callback with below parameters:
* * * * @param {boolean} subscribed true if subscribed, false otherwise
*/
function isCurrentUserO365SubscribedAsync(callback) {
KASClient.isCurrentUserO365Subscribed(function (subscribed, error) {
if (callback) {
callback(subscribed && error == null);
}
});
}
App.isCurrentUserO365SubscribedAsync = isCurrentUserO365SubscribedAsync;
/**
* Gets details of current logged-in O365 user
* @param {Callback} callback with below parameters:
* * * * @param {Json} returns the UserDetails in Json structure
*/
function getO365UserDetailsAsync(callback) {
KASClient.getO365UserDetails(function (userDetails, error) {
var userInfo = KASClient.KASO365User.fromJSON(userDetails);
if (callback) {
callback(userInfo, error);
}
});
}
App.getO365UserDetailsAsync = getO365UserDetailsAsync;
/**
* Gets the client details
* @param {Callback} callback with below parameters:
* * * * @param {JSON} properties can be null in case of error
* * * * @param {string} error message in case of error, null otherwise
*/
function getClientDetailsAsync(callback) {
KASClient.getClientDetails(callback);
}
App.getClientDetailsAsync = getClientDetailsAsync;
/**
* Registers a callback to be executed on hardware back button press (for Android)
* @param {Callback} callback to be executed
*/
var hardwareBackPressCallback = null;
function registerHardwareBackPressCallback(callback) {
if (callback === void 0) { callback = null; }
hardwareBackPressCallback = callback;
}
App.registerHardwareBackPressCallback = registerHardwareBackPressCallback;
// Will be called from Android Activity's onBackPressed()
function OnHardwareBackPress() {
if (hardwareBackPressCallback) {
hardwareBackPressCallback();
}
}
App.OnHardwareBackPress = OnHardwareBackPress;
/**
* Initializes the localization strings' map
* @param {Dictionary<StringId: Dictionary<Locale: StringValue>>} the strings' map
* @param {Callback} callback with below parameters:
* * * * @param {boolean} success denotes the success/failure of the initialization
*/
var locInited = false;
var locJson = null;
var currentLocale = "en"; // Default
function initLocalizationStringsAsync(strings, callback) {
locJson = strings;
getAppLocaleAsync(function (locale, error2) {
if (!error2) {
currentLocale = locale;
}
locInited = (!error2);
if (callback) {
callback(locInited);
}
});
}
App.initLocalizationStringsAsync = initLocalizationStringsAsync;
var userStrings = null;
function setUserStrings(strings) {
if (strings === void 0) { strings = null; }
userStrings = strings;
}
App.setUserStrings = setUserStrings;
/**
* Returns a string from the localized strings' file
* @param {string} stringId
*/
function getString(stringId) {
if (!userStrings && (!locInited || !locJson)) {
console.assert(false, "Valid localization file not initialized");
}
else {
// First preference should always be to user provided strings
if (userStrings && userStrings.hasOwnProperty(stringId) && userStrings[stringId]) {
return userStrings[stringId];
}
else if (locJson.hasOwnProperty(stringId)) {
if (locJson[stringId].hasOwnProperty(currentLocale)) {
return locJson[stringId][currentLocale];
}
else {
return locJson[stringId]["en"];
}
}
else {
return stringId;
}
}
}
App.getString = getString;
/**
* shows a particular location as mentioned in KASLocation
* @param {KASLocation} location
*/
function showLocationOnMap(location) {
KASClient.showLocationMap(JSON.stringify(location.toJSON()));
}
App.showLocationOnMap = showLocationOnMap;
/**
* Returns a string.
* @param {string} string denotes the formatted string. Specifier should be mentioned like {0},{1},{2}.....
* @param {string[]} args array of arguments.
*/
function printf(main) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
var formatted = main;
for (var i = 0; i < args.length; i++) {
var regexp = new RegExp('\\{' + i + '\\}', 'gi');
formatted = formatted.replace(regexp, args[i]);
}
return formatted;
}
App.printf = printf;
// For internal use.
function getCurrentLocale() {
return currentLocale;
}
App.getCurrentLocale = getCurrentLocale;
})(App = KASClient.App || (KASClient.App = {}));
})(KASClient || (KASClient = {}));
var KASClient;
(function (KASClient) {
var Constants = (function () {
function Constants() {
}
////////////// Telemetry event names ////////////////////////
// event name to track immersive page load time or error
Constants.TELEMETRY_EVENT_IMMERSIVE_PAGE_LOAD = "ACTION_IMMERSIVE_PAGE_LOAD";
// event name to track Insights page load time or error
Constants.TELEMETRY_EVENT_INSIGHTS_LOAD = "ACTION_INSIGHTS_LOAD";
// event name to track All Responses page load time or error
Constants.TELEMETRY_EVENT_ALL_RESPONSES_LOAD = "ACTION_ALL_RESPONSES_LOAD";
////////////// Telemetry event types ////////////////////////
// this type indicates start of the event, tracking for the event starts when this type is received
Constants.TELEMETRY_EVENT_TYPE_START = "START";
// this type indicates end of the event, tracking for the event stops when this type is received
// and the event is logged in telemetry, if corresponding start was recorded earlier.
// If no START was recorded earlier, this END type would be ignored
Constants.TELEMETRY_EVENT_TYPE_END = "END";
// this type indicates ERROR, tracking for the event stops if it was started earlier,
// and error telemetry for the event is logged
Constants.TELEMETRY_EVENT_TYPE_ERROR = "ERROR";
// For this type, there is no other marker associated and telemetry is logged without waiting for
// associated END or ERROR Event_Type
Constants.TELEMETRY_EVENT_TYPE_INDEPENDENT = "INDEPENDENT";
////////////// Telemetry properties keys ////////////////////////
// key to report error payload for an error event
Constants.TELEMETRY_PROPERTY_ERROR_KEY = "error";
return Constants;
}());
KASClient.Constants = Constants;
})(KASClient || (KASClient = {}));
var KASClient;
(function (KASClient) {
var Form;
(function (Form) {
//////////////////////////////
/////// Chat card APIs ///////
//////////////////////////////
function sendChatCardTemplate(template) {
KASClient.sendCardTemplate(template.toJSON());
}
Form.sendChatCardTemplate = sendChatCardTemplate;
//////////////////////////////////
/////// Creation flow APIs ///////
//////////////////////////////////
/**
* Initializes and returns an empty form object based on the default form file present in the package
* @param {Callback} callback with below parameters:
* * * * @param {KASForm} form can be null in case of error
* * * * @param {string} error message in case of error, null otherwise
*/
function initFormAsync(callback) {
//////////// MOCK ////////////
if (KASClient.shouldMockData()) {
KASClient.getJsonFromFileAsync("mock/form.json", function (formJson, error) {
if (callback) {
callback(KASClient.KASForm.fromJSON(formJson), null);
}
});
return;
}
//////////// ACTUAL ////////////
KASClient.getSurveyJson(function (formJson, error) {
if (callback) {
callback(KASClient.KASForm.fromJSON(formJson), error);
}
});
}
Form.initFormAsync = initFormAsync;
/**
* Submits the newly created form as a request. This results a new conversation card
* @param {KASForm} form
*/
function submitFormRequest(form, shouldInflate) {
//////////// MOCK ////////////
if (KASClient.shouldMockData()) {
alert("SubmitFormRequest");
return;
}
//////////// ACTUAL ////////////
KASClient.createRequest(form.toJSON(), null, shouldInflate);
}
Form.submitFormRequest = submitFormRequest;
/**
* Submits the newly created form as a request. This results a new conversation card
* @param {KASForm} form
*/
function submitFormRequestWithoutDismiss(form, shouldInflate) {
//////////// MOCK ////////////
if (KASClient.shouldMockData()) {
alert("submitFormRequestWithoutDismiss");
return;
}
//////////// ACTUAL ////////////
KASClient.createRequest(form.toJSON(), null, shouldInflate, false);
}
Form.submitFormRequestWithoutDismiss = submitFormRequestWithoutDismiss;
/**
* use for making changes in form fields like title, description and settings.
*/
function updateForm(fields, shouldInflate, callback) {
if (KASClient.shouldMockData()) {
alert("updateForm");
return;
}
KASClient.updateRequest(fields, null, shouldInflate, function (success, error) {
if (callback) {
callback(success && error == null);
}
});
}
Form.updateForm = updateForm;
//////////////////////////////////
/////// Response flow APIs ///////
//////////////////////////////////
/**
* Gets whether the current user can respond to the form
* @param {Callback} callback with below parameters:
* * * * @param {boolean} canRespond true if current user is allowed to respond
*/
function canRespondToFormAsync(callback) {
KASClient.canRespondToSurvey(function (canRespond, error) {
if (callback) {
callback(canRespond && error == null);
}
});
}
Form.canRespondToFormAsync = canRespondToFormAsync;
/**
* Gets the form object associated with the conversation card
* @param {Callback} callback with below parameters:
* * * * @param {KASForm} form can be null in case of error
* * * * @param {string} error message in case of error, null otherwise
*/
function getFormAsync(callback) {
//////////// MOCK ////////////
if (KASClient.shouldMockData()) {
KASClient.getJsonFromFileAsync("mock/form.json", function (formJson, error) {
if (callback) {
callback(KASClient.KASForm.fromJSON(formJson), null);
}
});
return;
}
//////////// ACTUAL ////////////
KASClient.getSurveyJson(function (formJson, error) {
if (callback) {
callback(KASClient.KASForm.fromJSON(formJson), error);
}
});
}
Form.getFormAsync = getFormAsync;
/**
* Gets the status of the form associated with the conversation card
* @param {Callback} callback with below parameters:
* * * * @param {boolean} isActive true if the form is not yet expired
* * * * @param {string} error message in case of error, null otherwise
*/
function getFormStatusAsync(callback) {
//////////// MOCK ////////////
if (KASClient.shouldMockData()) {
if (callback) {
callback(true, null);
}
return;
}
//////////// ACTUAL ////////////
KASClient.getPollStatus(function (isActive, error) {
if (callback) {
callback(isActive, error);
}
});
}
Form.getFormStatusAsync = getFormStatusAsync;
/**
* Gets all the responses of the current user against the form
* @param {Callback} callback with below parameters:
* * * * @param {KASFormResponse[]} responses can be null in case of error
* * * * @param {string} error message in case of error, null otherwise
*/
function getMyFormResponsesAsync(callback) {
//////////// MOCK ////////////
if (KASClient.shouldMockData()) {
KASClient.getJsonFromFileAsync("mock/form_response.json", function (responsesJson, error) {
var responses = [];
for (var i in responsesJson) {
responses.push(KASClient.KASFormResponse.fromJSON(responsesJson[i]));
}
if (callback) {
callback(responses, null);
}
});
return;
}
//////////// ACTUAL ////////////
KASClient.getResponsesJson(function (responsesJson, error) {
var responses = [];
for (var i in responsesJson) {
responses.push(KASClient.KASFormResponse.fromJSON(responsesJson[i]));
}
if (callback) {
callback(responses, error);
}
});
}
Form.getMyFormResponsesAsync = getMyFormResponsesAsync;
/**
* Submits a new response against the form associated with the conversation card
* This will dismiss the current screen
* @param {JSON} questionToAnswerMap question id to answer mapping
* @param {string} responseId to be filled if the current response is an edit/update to a previous one
* @param {boolean} isEdit denotes if the current response is an edit/update to a previous one
* @param {boolean} showInChatCanvas denotes if a separate chat card needs to be created for this response or not
* @param {boolean} isAnonymous denotes if the response should be registered as anonymous or not
*/
function sumbitFormResponse(questionToAnswerMap, responseId, isEdit, showInChatCanvas, isAnonymous) {
//////////// MOCK ////////////
if (KASClient.shouldMockData()) {
alert("SumbitFormResponse");
return;
}
//////////// ACTUAL ////////////
KASClient.sendResponse(questionToAnswerMap, responseId, isEdit, showInChatCanvas, isAnonymous);
}
Form.sumbitFormResponse = sumbitFormResponse;
/**
* Submits a new response against the form associated with the conversation card
* This won't dismiss the current screen
* @param {JSON} questionToAnswerMap question id to answer mapping
* @param {string} responseId to be filled if the current response is an edit/update to a previous one
* @param {boolean} isEdit denotes if the current response is an edit/update to a previous one
* @param {boolean} showInChatCanvas denotes if a separate chat card needs to be created for this response or not
* @param {boolean} isAnonymous denotes if the response should be registered as anonymous or not
*/
function sumbitFormResponseWithoutDismiss(questionToAnswerMap, responseId, isEdit, showInChatCanvas, isAnonymous) {
KASClient.sendResponse(questionToAnswerMap, responseId, isEdit, showInChatCanvas, isAnonymous, false);
}
Form.sumbitFormResponseWithoutDismiss = sumbitFormResponseWithoutDismiss;
/////////////////////////////////
/////// Summary flow APIs ///////
/////////////////////////////////
/**
* Gets whether the form summary is visible to the current user
* @param {Callback} callback with below parameters:
* * * * @param {boolean} shouldSeeSummary true if current user is allowed to see summary
*/
function shouldSeeFormSummaryAsync(callback) {
KASClient.shouldSeeSurveySummary(function (shouldSeeSummary, error) {
if (callback) {
callback(shouldSeeSummary && error == null);
}
});
}
Form.shouldSeeFormSummaryAsync = shouldSeeFormSummaryAsync;
/**
* Gets whether the current user is subscriber or not
* @param {Callback} callback with below parameters:
* * * * @param {boolean} isSubscribed true if current user subscriber
*/
function isSubscribed(callback) {
KASClient.isSubscriber(function (isSubscribed, error) {
if (callback) {
callback(isSubscribed && error == null);
}
});
}
Form.isSubscribed = isSubscribed;
/**
* Gets flat responses by all the users, and processed summary from all the responses associated
* with the form. It requires two callbacks:
* @param {Callback} mostUpdatedCallback to immediately get the most updated summary from local database. It has below parameters:
* * * * @param {KASFormFlatSummary} flatSummary can be null in case of error
* * * * @param {KASFormProcessedSummary} processedSummary can be null in case of error
* * * * @param {string} error message in case of error, null otherwise
* @param {Callback} notifyCallback to get notified with the latest summary fetched from server. It has below parameters:
* * * * @param {KASFormFlatSummary} flatSummary can be null in case of error
* * * * @param {KASFormProcessedSummary} processedSummary can be null in case of error
* * * * @param {string} error message in case of error, null otherwise
*
* This is useful when the network is flaky/disconnected, so that summary can
* immediately be shown with the present data we have, but with an option to refresh
* it later on arrival of latest data from server! None of the callbacks are mandatory,
* so if 1st is nil, this method can be used to always fetch summary from server, and
* if 2nd is nil, this can be used to always fetch summary from local database!
*/
function getFormSummaryAsync(mostUpdatedCallback, notifyCallback) {
//////////// MOCK ////////////
if (KASClient.shouldMockData()) {
KASClient.getJsonFromFileAsync("mock/form_summary.json", function (summaryJson, error) {
KASClient.getJsonFromFileAsync("mock/form_result.json", function (summaryResultJson, error) {
if (mostUpdatedCallback) {
mostUpdatedCallback(KASClient.KASFormFlatSummary.fromJSON(summaryJson, true), KASClient.KASFormProcessedSummary.fromJSON(summaryResultJson), null);
}
});
});
return;
}
//////////// ACTUAL ////////////
getFormAsync(function (form, error) {
if (error == null) {
var callback1 = null;
if (mostUpdatedCallback) {
callback1 = function (summaryJson, summaryResultJson, error) {
mostUpdatedCallback(KASClient.KASFormFlatSummary.fromJSON(summaryJson, form.isResponseAppended), KASClient.KASFormProcessedSummary.fromJSON(summaryResultJson), error);
};
}
var callback2 = null;
if (notifyCallback) {
callback2 = function (summaryJson, summaryResultJson, error) {
notifyCallback(KASClient.KASFormFlatSummary.fromJSON(summaryJson, form.isResponseAppended), KASClient.KASFormProcessedSummary.fromJSON(summaryResultJson), error);
};
}
KASClient.getSurveySummary(callback1, callback2);