@careevolution/mydatahelps-js 3.18.0 → 3.18.1-FixMessagePassing.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/MyDataHelps.d.ts +3 -1
- package/MyDataHelps.js +184 -273
- package/MyDataHelps.min.js +1 -1
- package/MyDataHelps.min.js.map +1 -1
- package/package.json +1 -1
package/MyDataHelps.js
CHANGED
|
@@ -28,32 +28,51 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
28
28
|
class MyDataHelps {
|
|
29
29
|
// Surveys
|
|
30
30
|
startSurvey(surveyName) {
|
|
31
|
+
var _a, _b, _c;
|
|
31
32
|
if (this.isStandaloneMode()) {
|
|
32
33
|
this.startDelegatedSurvey(`${this.baseUrl}/survey?surveyName=${encodeURIComponent(surveyName)}`);
|
|
33
34
|
}
|
|
34
|
-
else
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
else {
|
|
36
|
+
if ((_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.StartParticipantSurvey) {
|
|
37
|
+
window.webkit.messageHandlers.StartParticipantSurvey.postMessage({
|
|
38
|
+
messageID: this.nextMessageID(),
|
|
39
|
+
surveyName: surveyName
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
(_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({
|
|
44
|
+
name: 'StartParticipantSurvey',
|
|
45
|
+
messageID: this.nextMessageID(),
|
|
46
|
+
surveyName: surveyName
|
|
47
|
+
}, this.applicationHost);
|
|
48
|
+
}
|
|
40
49
|
}
|
|
41
50
|
}
|
|
42
51
|
completeStep(answer) {
|
|
52
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
43
53
|
if (answer === undefined || answer === null)
|
|
44
54
|
answer = '';
|
|
45
55
|
if (typeof answer !== 'string') {
|
|
46
56
|
answer = JSON.stringify(answer);
|
|
47
57
|
}
|
|
48
|
-
if (window.webkit.messageHandlers.ResearchKit) {
|
|
58
|
+
if ((_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.ResearchKit) {
|
|
49
59
|
window.webkit.messageHandlers.ResearchKit.postMessage(answer);
|
|
50
60
|
}
|
|
51
|
-
else if (window.webkit.messageHandlers.CompleteStep) {
|
|
61
|
+
else if ((_d = (_c = window.webkit) === null || _c === void 0 ? void 0 : _c.messageHandlers) === null || _d === void 0 ? void 0 : _d.CompleteStep) {
|
|
52
62
|
let messageID = this.nextMessageID();
|
|
53
|
-
window.webkit.messageHandlers.CompleteStep
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
63
|
+
if ((_f = (_e = window.webkit) === null || _e === void 0 ? void 0 : _e.messageHandlers) === null || _f === void 0 ? void 0 : _f.CompleteStep) {
|
|
64
|
+
window.webkit.messageHandlers.CompleteStep.postMessage({
|
|
65
|
+
messageID: messageID,
|
|
66
|
+
answer: answer
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
(_g = window.parent) === null || _g === void 0 ? void 0 : _g.postMessage({
|
|
71
|
+
name: 'CompleteStep',
|
|
72
|
+
messageID: messageID,
|
|
73
|
+
answer: answer
|
|
74
|
+
}, mdh.applicationHost);
|
|
75
|
+
}
|
|
57
76
|
}
|
|
58
77
|
}
|
|
59
78
|
querySurveyAnswers(queryParameters) {
|
|
@@ -200,51 +219,94 @@ class MyDataHelps {
|
|
|
200
219
|
}
|
|
201
220
|
// Navigation
|
|
202
221
|
openExternalUrl(url) {
|
|
203
|
-
|
|
204
|
-
|
|
222
|
+
var _a, _b, _c, _d;
|
|
223
|
+
if ((_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.OpenExternalLink) {
|
|
224
|
+
(_c = window.webkit.messageHandlers.OpenExternalLink) === null || _c === void 0 ? void 0 : _c.postMessage(url);
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
(_d = window.parent) === null || _d === void 0 ? void 0 : _d.postMessage({
|
|
228
|
+
name: 'OpenExternalUrl',
|
|
229
|
+
url: url
|
|
230
|
+
}, mdh.applicationHost);
|
|
205
231
|
}
|
|
206
232
|
}
|
|
207
233
|
openEmbeddedUrl(url) {
|
|
208
|
-
|
|
209
|
-
|
|
234
|
+
var _a, _b, _c, _d;
|
|
235
|
+
if ((_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.OpenEmbeddedLink) {
|
|
236
|
+
(_c = window.webkit.messageHandlers.OpenEmbeddedLink) === null || _c === void 0 ? void 0 : _c.postMessage(url);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
(_d = window.parent) === null || _d === void 0 ? void 0 : _d.postMessage({
|
|
240
|
+
name: 'OpenEmbeddedUrl',
|
|
241
|
+
url: url
|
|
242
|
+
}, mdh.applicationHost);
|
|
210
243
|
}
|
|
211
244
|
}
|
|
212
245
|
showTab(tabKey) {
|
|
213
|
-
|
|
246
|
+
var _a, _b, _c;
|
|
247
|
+
if ((_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.ShowTab) {
|
|
214
248
|
window.webkit.messageHandlers.ShowTab.postMessage(tabKey);
|
|
215
249
|
}
|
|
250
|
+
else {
|
|
251
|
+
(_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({ name: 'ShowTab', tabKey: tabKey }, this.applicationHost);
|
|
252
|
+
}
|
|
216
253
|
}
|
|
217
254
|
openApplication(url, options) {
|
|
218
|
-
|
|
219
|
-
|
|
255
|
+
var _a, _b, _c;
|
|
256
|
+
if ((_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.OpenExternalApplication) {
|
|
220
257
|
window.webkit.messageHandlers.OpenExternalApplication.postMessage({
|
|
221
|
-
messageID:
|
|
258
|
+
messageID: this.nextMessageID(),
|
|
222
259
|
url: url,
|
|
223
260
|
modal: !!(options && options.modal)
|
|
224
261
|
});
|
|
225
262
|
}
|
|
263
|
+
else {
|
|
264
|
+
(_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({
|
|
265
|
+
name: 'OpenApplication',
|
|
266
|
+
messageID: this.nextMessageID(),
|
|
267
|
+
url: url,
|
|
268
|
+
modal: !!(options && options.modal)
|
|
269
|
+
}, this.applicationHost);
|
|
270
|
+
}
|
|
226
271
|
}
|
|
227
272
|
dismiss() {
|
|
228
|
-
|
|
273
|
+
var _a, _b, _c;
|
|
274
|
+
if ((_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.Dismiss) {
|
|
229
275
|
window.webkit.messageHandlers.Dismiss.postMessage({});
|
|
230
276
|
}
|
|
277
|
+
else {
|
|
278
|
+
(_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({ name: 'Dismiss' }, this.applicationHost);
|
|
279
|
+
}
|
|
231
280
|
}
|
|
232
281
|
back() {
|
|
233
|
-
|
|
282
|
+
var _a, _b, _c;
|
|
283
|
+
if ((_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.PopNavigation) {
|
|
234
284
|
window.webkit.messageHandlers.PopNavigation.postMessage({});
|
|
235
285
|
}
|
|
286
|
+
else {
|
|
287
|
+
(_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({ name: 'Back' }, this.applicationHost);
|
|
288
|
+
}
|
|
236
289
|
}
|
|
237
290
|
showDashboard(dashboardKey, options) {
|
|
238
|
-
|
|
291
|
+
var _a, _b, _c;
|
|
292
|
+
if ((_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.ShowParticipantDashboard) {
|
|
239
293
|
window.webkit.messageHandlers.ShowParticipantDashboard.postMessage({
|
|
240
294
|
dashboardKey: dashboardKey,
|
|
241
295
|
modal: !!(options && options.modal),
|
|
242
296
|
title: options && options.title ? options.title : undefined
|
|
243
297
|
});
|
|
244
298
|
}
|
|
299
|
+
else {
|
|
300
|
+
(_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({
|
|
301
|
+
name: 'ShowParticipantDashboard',
|
|
302
|
+
dashboardKey: dashboardKey,
|
|
303
|
+
modal: !!(options && options.modal)
|
|
304
|
+
}, this.applicationHost);
|
|
305
|
+
}
|
|
245
306
|
}
|
|
246
307
|
showWebVisualization(visualizationKey, parameters, options) {
|
|
247
|
-
|
|
308
|
+
var _a, _b, _c;
|
|
309
|
+
if ((_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.ShowParticipantWebVisualization) {
|
|
248
310
|
window.webkit.messageHandlers.ShowParticipantWebVisualization.postMessage({
|
|
249
311
|
visualizationKey: visualizationKey,
|
|
250
312
|
parameters: parameters,
|
|
@@ -252,9 +314,18 @@ class MyDataHelps {
|
|
|
252
314
|
title: options && options.title ? options.title : undefined
|
|
253
315
|
});
|
|
254
316
|
}
|
|
317
|
+
else {
|
|
318
|
+
(_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({
|
|
319
|
+
name: 'ShowParticipantWebVisualization',
|
|
320
|
+
visualizationKey: visualizationKey,
|
|
321
|
+
parameters: parameters,
|
|
322
|
+
modal: !!(options && options.modal),
|
|
323
|
+
}, this.applicationHost);
|
|
324
|
+
}
|
|
255
325
|
}
|
|
256
326
|
showWebVisualizationPdf(visualizationKey, parameters, options) {
|
|
257
|
-
|
|
327
|
+
var _a, _b, _c;
|
|
328
|
+
if ((_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.ShowParticipantWebVisualizationPDF) {
|
|
258
329
|
window.webkit.messageHandlers.ShowParticipantWebVisualizationPDF.postMessage({
|
|
259
330
|
visualizationKey: visualizationKey,
|
|
260
331
|
parameters: parameters,
|
|
@@ -262,16 +333,33 @@ class MyDataHelps {
|
|
|
262
333
|
htmlViewerZoom: options && options.htmlViewerZoom
|
|
263
334
|
});
|
|
264
335
|
}
|
|
336
|
+
else {
|
|
337
|
+
(_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({
|
|
338
|
+
name: 'ShowParticipantWebVisualizationPDF',
|
|
339
|
+
visualizationKey: visualizationKey,
|
|
340
|
+
parameters: parameters,
|
|
341
|
+
landscape: !!(options && options.landscape),
|
|
342
|
+
htmlViewerZoom: options && options.htmlViewerZoom
|
|
343
|
+
}, this.applicationHost);
|
|
344
|
+
}
|
|
265
345
|
}
|
|
266
346
|
showProject(projectCode) {
|
|
267
|
-
|
|
347
|
+
var _a, _b, _c;
|
|
348
|
+
if ((_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.ShowProject) {
|
|
268
349
|
window.webkit.messageHandlers.ShowProject.postMessage({ code: projectCode });
|
|
269
350
|
}
|
|
351
|
+
else {
|
|
352
|
+
(_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({ name: 'ShowProject', code: projectCode }, this.applicationHost);
|
|
353
|
+
}
|
|
270
354
|
}
|
|
271
355
|
joinProject(projectCode) {
|
|
272
|
-
|
|
356
|
+
var _a, _b, _c;
|
|
357
|
+
if ((_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.JoinProject) {
|
|
273
358
|
window.webkit.messageHandlers.JoinProject.postMessage({ code: projectCode });
|
|
274
359
|
}
|
|
360
|
+
else {
|
|
361
|
+
(_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({ name: 'JoinProject', code: projectCode }, this.applicationHost);
|
|
362
|
+
}
|
|
275
363
|
}
|
|
276
364
|
//Events
|
|
277
365
|
on(eventName, callback) {
|
|
@@ -566,6 +654,7 @@ class MyDataHelps {
|
|
|
566
654
|
}
|
|
567
655
|
connectExternalAccount(externalAccountProviderID, options) {
|
|
568
656
|
return new Promise((resolve, reject) => {
|
|
657
|
+
var _a, _b, _c;
|
|
569
658
|
const messageID = mdh.nextMessageID();
|
|
570
659
|
mdh.messageHandlers[messageID] = function (connectProviderAccountResponse) {
|
|
571
660
|
if (connectProviderAccountResponse && connectProviderAccountResponse.success) {
|
|
@@ -618,8 +707,13 @@ class MyDataHelps {
|
|
|
618
707
|
reject(error);
|
|
619
708
|
});
|
|
620
709
|
}
|
|
621
|
-
else
|
|
622
|
-
window.webkit.messageHandlers
|
|
710
|
+
else {
|
|
711
|
+
if ((_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.ConnectExternalAccount) {
|
|
712
|
+
window.webkit.messageHandlers.ConnectExternalAccount.postMessage(Object.assign({ externalAccountProviderID: externalAccountProviderID, messageID: messageID }, options));
|
|
713
|
+
}
|
|
714
|
+
else {
|
|
715
|
+
(_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage(Object.assign({ name: 'ConnectExternalAccount', externalAccountProviderID: externalAccountProviderID, messageID: messageID }, options), this.applicationHost);
|
|
716
|
+
}
|
|
623
717
|
}
|
|
624
718
|
});
|
|
625
719
|
}
|
|
@@ -667,23 +761,28 @@ class MyDataHelps {
|
|
|
667
761
|
});
|
|
668
762
|
}
|
|
669
763
|
return new Promise(function (resolve, reject) {
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
764
|
+
var _a, _b, _c;
|
|
765
|
+
const messageID = mdh.nextMessageID();
|
|
766
|
+
mdh.messageHandlers[messageID] = function (deleteProviderAccountResponse) {
|
|
767
|
+
if (!deleteProviderAccountResponse.success) {
|
|
768
|
+
reject(deleteProviderAccountResponse);
|
|
769
|
+
}
|
|
770
|
+
else {
|
|
771
|
+
resolve(deleteProviderAccountResponse);
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
if ((_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.DeleteProviderAccount) {
|
|
680
775
|
window.webkit.messageHandlers.DeleteProviderAccount.postMessage({
|
|
681
776
|
messageID: messageID,
|
|
682
777
|
accountID: accountID
|
|
683
778
|
});
|
|
684
779
|
}
|
|
685
780
|
else {
|
|
686
|
-
|
|
781
|
+
(_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({
|
|
782
|
+
name: 'DeleteProviderAccount',
|
|
783
|
+
messageID: messageID,
|
|
784
|
+
accountID: accountID
|
|
785
|
+
}, this.applicationHost);
|
|
687
786
|
}
|
|
688
787
|
});
|
|
689
788
|
}
|
|
@@ -896,8 +995,7 @@ class MyDataHelps {
|
|
|
896
995
|
let refreshDelegatedAccessToken = function () {
|
|
897
996
|
mdh.token = null;
|
|
898
997
|
mdh.refreshTokenPromise = new Promise(function (resolve, reject) {
|
|
899
|
-
|
|
900
|
-
mdh.messageHandlers[messageID] = function (tokenResponse) {
|
|
998
|
+
return mdh.sendBasicMessage("GetDelegatedAccessToken").then(function (tokenResponse) {
|
|
901
999
|
if (tokenResponse.success) {
|
|
902
1000
|
mdh.tokenExpires = Date.now() + (tokenResponse.data.expires_in * 1000);
|
|
903
1001
|
mdh.token = tokenResponse.data;
|
|
@@ -909,10 +1007,8 @@ class MyDataHelps {
|
|
|
909
1007
|
mdh.token = null;
|
|
910
1008
|
reject(tokenResponse.message);
|
|
911
1009
|
}
|
|
912
|
-
mdh.messageHandlers[messageID] = null;
|
|
913
1010
|
mdh.refreshTokenPromise = null;
|
|
914
|
-
};
|
|
915
|
-
window.webkit.messageHandlers.GetDelegatedAccessToken.postMessage({ messageID: messageID });
|
|
1011
|
+
});
|
|
916
1012
|
});
|
|
917
1013
|
};
|
|
918
1014
|
if (this.token && Date.now() < this.tokenExpires) {
|
|
@@ -952,7 +1048,8 @@ class MyDataHelps {
|
|
|
952
1048
|
}
|
|
953
1049
|
}
|
|
954
1050
|
setStatusBarStyle(style) {
|
|
955
|
-
|
|
1051
|
+
var _a, _b;
|
|
1052
|
+
if ((_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.SetStatusBarStyle) {
|
|
956
1053
|
window.webkit.messageHandlers.SetStatusBarStyle.postMessage({ style: style });
|
|
957
1054
|
}
|
|
958
1055
|
}
|
|
@@ -962,15 +1059,10 @@ class MyDataHelps {
|
|
|
962
1059
|
if (mdh.isStandaloneMode()) {
|
|
963
1060
|
resolve(null);
|
|
964
1061
|
}
|
|
965
|
-
else if (window.webkit.messageHandlers.GetDeviceInfo) {
|
|
966
|
-
let messageID = mdh.nextMessageID();
|
|
967
|
-
mdh.messageHandlers[messageID] = function (deviceInfoResponse) {
|
|
968
|
-
resolve(deviceInfoResponse.data);
|
|
969
|
-
};
|
|
970
|
-
window.webkit.messageHandlers.GetDeviceInfo.postMessage({ messageID: messageID });
|
|
971
|
-
}
|
|
972
1062
|
else {
|
|
973
|
-
|
|
1063
|
+
mdh.sendBasicMessage("GetDeviceInfo").then(function (deviceInfoResponse) {
|
|
1064
|
+
resolve(deviceInfoResponse.data);
|
|
1065
|
+
});
|
|
974
1066
|
}
|
|
975
1067
|
});
|
|
976
1068
|
}
|
|
@@ -986,15 +1078,10 @@ class MyDataHelps {
|
|
|
986
1078
|
if (mdh.isStandaloneMode()) {
|
|
987
1079
|
resolve(null);
|
|
988
1080
|
}
|
|
989
|
-
else if (window.webkit.messageHandlers.GetStepConfiguration) {
|
|
990
|
-
let messageID = mdh.nextMessageID();
|
|
991
|
-
mdh.messageHandlers[messageID] = function (stepConfigurationResponse) {
|
|
992
|
-
resolve(stepConfigurationResponse.data);
|
|
993
|
-
};
|
|
994
|
-
window.webkit.messageHandlers.GetStepConfiguration.postMessage({ messageID: messageID });
|
|
995
|
-
}
|
|
996
1081
|
else {
|
|
997
|
-
|
|
1082
|
+
mdh.sendBasicMessage("GetStepConfiguration").then(function (stepConfigurationResponse) {
|
|
1083
|
+
resolve(stepConfigurationResponse.data);
|
|
1084
|
+
});
|
|
998
1085
|
}
|
|
999
1086
|
});
|
|
1000
1087
|
}
|
|
@@ -1005,19 +1092,21 @@ class MyDataHelps {
|
|
|
1005
1092
|
resolve(null);
|
|
1006
1093
|
}
|
|
1007
1094
|
mdh.getDeviceInfo().then(function (deviceInfo) {
|
|
1095
|
+
var _a;
|
|
1008
1096
|
if (deviceInfo.platform !== "Web") {
|
|
1009
1097
|
resolve({ surveyMode: "Survey" });
|
|
1010
1098
|
}
|
|
1011
|
-
else
|
|
1099
|
+
else {
|
|
1012
1100
|
let messageID = mdh.nextMessageID();
|
|
1013
1101
|
mdh.messageHandlers[messageID] = function (surveyContextResponse) {
|
|
1014
1102
|
resolve(surveyContextResponse.data);
|
|
1015
1103
|
};
|
|
1104
|
+
(_a = window.parent) === null || _a === void 0 ? void 0 : _a.postMessage({
|
|
1105
|
+
name: 'GetSurveyContext',
|
|
1106
|
+
messageID: messageID
|
|
1107
|
+
}, mdh.applicationHost);
|
|
1016
1108
|
window.webkit.messageHandlers.GetSurveyContext.postMessage({ messageID: messageID });
|
|
1017
1109
|
}
|
|
1018
|
-
else {
|
|
1019
|
-
reject();
|
|
1020
|
-
}
|
|
1021
1110
|
}).catch(function (error) {
|
|
1022
1111
|
reject();
|
|
1023
1112
|
});
|
|
@@ -1029,15 +1118,10 @@ class MyDataHelps {
|
|
|
1029
1118
|
if (mdh.isStandaloneMode()) {
|
|
1030
1119
|
resolve(null);
|
|
1031
1120
|
}
|
|
1032
|
-
else if (window.webkit.messageHandlers.GetCurrentSurveyAnswers) {
|
|
1033
|
-
let messageID = mdh.nextMessageID();
|
|
1034
|
-
mdh.messageHandlers[messageID] = function (currentSurveyAnswersResponse) {
|
|
1035
|
-
resolve(currentSurveyAnswersResponse.data);
|
|
1036
|
-
};
|
|
1037
|
-
window.webkit.messageHandlers.GetCurrentSurveyAnswers.postMessage({ messageID: messageID });
|
|
1038
|
-
}
|
|
1039
1121
|
else {
|
|
1040
|
-
|
|
1122
|
+
mdh.sendBasicMessage("GetCurrentSurveyAnswers").then(function (currentSurveyAnswersResponse) {
|
|
1123
|
+
resolve(currentSurveyAnswersResponse.data);
|
|
1124
|
+
});
|
|
1041
1125
|
}
|
|
1042
1126
|
});
|
|
1043
1127
|
}
|
|
@@ -1070,12 +1154,14 @@ class MyDataHelps {
|
|
|
1070
1154
|
return this.language || navigator.language;
|
|
1071
1155
|
}
|
|
1072
1156
|
showGoogleFitSettings() {
|
|
1073
|
-
|
|
1157
|
+
var _a, _b;
|
|
1158
|
+
if ((_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.ShowGoogleFitSettings) {
|
|
1074
1159
|
window.webkit.messageHandlers.ShowGoogleFitSettings.postMessage({});
|
|
1075
1160
|
}
|
|
1076
1161
|
}
|
|
1077
1162
|
requestReview(cooldownDays) {
|
|
1078
|
-
|
|
1163
|
+
var _a, _b;
|
|
1164
|
+
if ((_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.RequestReview) {
|
|
1079
1165
|
window.webkit.messageHandlers.RequestReview.postMessage({ cooldownDays: cooldownDays });
|
|
1080
1166
|
}
|
|
1081
1167
|
}
|
|
@@ -1155,12 +1241,12 @@ class MyDataHelps {
|
|
|
1155
1241
|
this.registeredEventHandlers = {};
|
|
1156
1242
|
this.refreshTokenPromise = null;
|
|
1157
1243
|
this.standaloneMode = false;
|
|
1244
|
+
this.applicationHost = null;
|
|
1158
1245
|
if (this.handleConnectExternalAccountResponse()) {
|
|
1159
1246
|
return;
|
|
1160
1247
|
}
|
|
1161
1248
|
let mdh = this;
|
|
1162
|
-
|
|
1163
|
-
let supportedActions;
|
|
1249
|
+
mdh.applicationHost = getParentOrigin();
|
|
1164
1250
|
function getParentOrigin() {
|
|
1165
1251
|
let ancestorOrigins = document.location.ancestorOrigins;
|
|
1166
1252
|
if (ancestorOrigins && ancestorOrigins[0]) {
|
|
@@ -1183,23 +1269,10 @@ class MyDataHelps {
|
|
|
1183
1269
|
if (mdh.isStandaloneMode() && message.origin === window.location.origin) {
|
|
1184
1270
|
return true;
|
|
1185
1271
|
}
|
|
1186
|
-
if (applicationHost === "*") {
|
|
1272
|
+
if (mdh.applicationHost === "*") {
|
|
1187
1273
|
return acceptableOrigin(message.origin);
|
|
1188
1274
|
}
|
|
1189
|
-
return message.origin === applicationHost;
|
|
1190
|
-
}
|
|
1191
|
-
function addActions(actions) {
|
|
1192
|
-
for (let action in actions) {
|
|
1193
|
-
if (!window.webkit.messageHandlers[action]) {
|
|
1194
|
-
try {
|
|
1195
|
-
window.webkit.messageHandlers[action] = { postMessage: actions[action] };
|
|
1196
|
-
}
|
|
1197
|
-
catch (error) {
|
|
1198
|
-
console.log("Unable to add missing actions on this platform: " + error);
|
|
1199
|
-
return;
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1275
|
+
return message.origin === mdh.applicationHost;
|
|
1203
1276
|
}
|
|
1204
1277
|
function receiveWindowMessage(message) {
|
|
1205
1278
|
if (!validateWindowMessageOrigin(message)) {
|
|
@@ -1214,188 +1287,9 @@ class MyDataHelps {
|
|
|
1214
1287
|
mdh.triggerEvent(message.data);
|
|
1215
1288
|
}
|
|
1216
1289
|
}
|
|
1217
|
-
|
|
1218
|
-
for (let action in supportedActions) {
|
|
1219
|
-
if (window.webkit.messageHandlers[action]) {
|
|
1220
|
-
return true;
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
for (let action in mdh.unsupportedActions) {
|
|
1224
|
-
if (window.webkit.messageHandlers[mdh.unsupportedActions[action]]) {
|
|
1225
|
-
return true;
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
return false;
|
|
1229
|
-
}
|
|
1230
|
-
if (!acceptableOrigin(applicationHost)) {
|
|
1290
|
+
if (!acceptableOrigin(mdh.applicationHost)) {
|
|
1231
1291
|
console.log("Detected unsupported parent origin domain.");
|
|
1232
1292
|
}
|
|
1233
|
-
if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.ResearchKit) {
|
|
1234
|
-
// Presence of ResearchKit handler indicates the SDK is being used from within a WebViewStep. For pre-SDK backwards compatiblity,
|
|
1235
|
-
// WebViewStep setup registers the following handlers: GetDeviceInfo, DeleteProviderAccount, ConnectExternalAccount
|
|
1236
|
-
// ShowParticipantWebVisualizationPDF, ResearchKit
|
|
1237
|
-
supportedActions = {
|
|
1238
|
-
"GetDelegatedAccessToken": function (data) {
|
|
1239
|
-
window.parent.postMessage({
|
|
1240
|
-
name: 'GetDelegatedAccessToken',
|
|
1241
|
-
messageID: data.messageID
|
|
1242
|
-
}, applicationHost);
|
|
1243
|
-
},
|
|
1244
|
-
"OpenExternalLink": function (data) {
|
|
1245
|
-
window.parent.postMessage({
|
|
1246
|
-
name: 'OpenExternalUrl',
|
|
1247
|
-
url: data
|
|
1248
|
-
}, applicationHost);
|
|
1249
|
-
},
|
|
1250
|
-
"OpenEmbeddedLink": function (data) {
|
|
1251
|
-
window.parent.postMessage({
|
|
1252
|
-
name: 'OpenEmbeddedUrl',
|
|
1253
|
-
url: data
|
|
1254
|
-
}, applicationHost);
|
|
1255
|
-
},
|
|
1256
|
-
"GetCurrentSurveyAnswers": function (data) {
|
|
1257
|
-
window.parent.postMessage({
|
|
1258
|
-
name: 'GetCurrentSurveyAnswers',
|
|
1259
|
-
messageID: data.messageID
|
|
1260
|
-
}, applicationHost);
|
|
1261
|
-
},
|
|
1262
|
-
"GetStepConfiguration": function (data) {
|
|
1263
|
-
window.parent.postMessage({
|
|
1264
|
-
name: 'GetStepConfiguration',
|
|
1265
|
-
messageID: data.messageID
|
|
1266
|
-
}, applicationHost);
|
|
1267
|
-
},
|
|
1268
|
-
"GetSurveyContext": function (data) {
|
|
1269
|
-
window.parent.postMessage({
|
|
1270
|
-
name: 'GetSurveyContext',
|
|
1271
|
-
messageID: data.messageID
|
|
1272
|
-
}, applicationHost);
|
|
1273
|
-
},
|
|
1274
|
-
"CompleteStep": function (data) {
|
|
1275
|
-
window.parent.postMessage({
|
|
1276
|
-
name: 'CompleteStep',
|
|
1277
|
-
messageID: data.messageID,
|
|
1278
|
-
answer: data.answer
|
|
1279
|
-
}, applicationHost);
|
|
1280
|
-
}
|
|
1281
|
-
};
|
|
1282
|
-
}
|
|
1283
|
-
else {
|
|
1284
|
-
supportedActions = {
|
|
1285
|
-
"GetDelegatedAccessToken": function (data) {
|
|
1286
|
-
window.parent.postMessage({
|
|
1287
|
-
name: 'GetDelegatedAccessToken',
|
|
1288
|
-
messageID: data.messageID
|
|
1289
|
-
}, applicationHost);
|
|
1290
|
-
},
|
|
1291
|
-
"GetDeviceInfo": function (data) {
|
|
1292
|
-
window.parent.postMessage({ name: 'GetDeviceInfo', messageID: data.messageID }, applicationHost);
|
|
1293
|
-
},
|
|
1294
|
-
"StartParticipantSurvey": function (data) {
|
|
1295
|
-
window.parent.postMessage({
|
|
1296
|
-
name: 'StartParticipantSurvey',
|
|
1297
|
-
messageID: data.messageID,
|
|
1298
|
-
surveyName: data.surveyName
|
|
1299
|
-
}, applicationHost);
|
|
1300
|
-
},
|
|
1301
|
-
"OpenExternalLink": function (data) {
|
|
1302
|
-
window.parent.postMessage({ name: 'OpenExternalUrl', url: data }, applicationHost);
|
|
1303
|
-
},
|
|
1304
|
-
"OpenEmbeddedLink": function (data) {
|
|
1305
|
-
window.parent.postMessage({ name: 'OpenEmbeddedUrl', url: data }, applicationHost);
|
|
1306
|
-
},
|
|
1307
|
-
"OpenExternalApplication": function (data) {
|
|
1308
|
-
window.parent.postMessage({
|
|
1309
|
-
name: 'OpenApplication',
|
|
1310
|
-
messageID: data.messageID,
|
|
1311
|
-
url: data.url,
|
|
1312
|
-
modal: data.modal
|
|
1313
|
-
}, applicationHost);
|
|
1314
|
-
},
|
|
1315
|
-
"Dismiss": function () {
|
|
1316
|
-
window.parent.postMessage({ name: 'Dismiss' }, applicationHost);
|
|
1317
|
-
},
|
|
1318
|
-
"PopNavigation": function () {
|
|
1319
|
-
window.parent.postMessage({ name: 'Back' }, applicationHost);
|
|
1320
|
-
},
|
|
1321
|
-
"ShowTab": function (data) {
|
|
1322
|
-
window.parent.postMessage({ name: 'ShowTab', tabKey: data }, applicationHost);
|
|
1323
|
-
},
|
|
1324
|
-
"ShowParticipantDashboard": function (data) {
|
|
1325
|
-
window.parent.postMessage({
|
|
1326
|
-
name: 'ShowParticipantDashboard',
|
|
1327
|
-
dashboardKey: data.dashboardKey,
|
|
1328
|
-
modal: data.modal
|
|
1329
|
-
}, applicationHost);
|
|
1330
|
-
},
|
|
1331
|
-
"ShowParticipantWebVisualization": function (data) {
|
|
1332
|
-
window.parent.postMessage({
|
|
1333
|
-
name: 'ShowParticipantWebVisualization',
|
|
1334
|
-
visualizationKey: data.visualizationKey,
|
|
1335
|
-
parameters: data.parameters,
|
|
1336
|
-
modal: data.modal
|
|
1337
|
-
}, applicationHost);
|
|
1338
|
-
},
|
|
1339
|
-
"ShowParticipantWebVisualizationPDF": function (data) {
|
|
1340
|
-
window.parent.postMessage({
|
|
1341
|
-
name: 'ShowParticipantWebVisualizationPDF',
|
|
1342
|
-
visualizationKey: data.visualizationKey,
|
|
1343
|
-
parameters: data.parameters,
|
|
1344
|
-
modal: data.modal,
|
|
1345
|
-
landscape: data.landscape,
|
|
1346
|
-
htmlViewerZoom: data.htmlViewerZoom
|
|
1347
|
-
}, applicationHost);
|
|
1348
|
-
},
|
|
1349
|
-
"DeleteProviderAccount": function (data) {
|
|
1350
|
-
window.parent.postMessage({
|
|
1351
|
-
name: 'DeleteProviderAccount',
|
|
1352
|
-
messageID: data.messageID,
|
|
1353
|
-
accountID: data.accountID
|
|
1354
|
-
}, applicationHost);
|
|
1355
|
-
},
|
|
1356
|
-
"ConnectExternalAccount": function (data) {
|
|
1357
|
-
window.parent.postMessage({
|
|
1358
|
-
name: 'ConnectExternalAccount',
|
|
1359
|
-
externalAccountProviderID: data.externalAccountProviderID,
|
|
1360
|
-
messageID: data.messageID,
|
|
1361
|
-
openNewWindow: data.openNewWindow,
|
|
1362
|
-
width: data.width,
|
|
1363
|
-
height: data.height
|
|
1364
|
-
}, applicationHost);
|
|
1365
|
-
},
|
|
1366
|
-
"ShowProject": function (data) {
|
|
1367
|
-
window.parent.postMessage({ name: 'ShowProject', code: data.code }, applicationHost);
|
|
1368
|
-
},
|
|
1369
|
-
"JoinProject": function (data) {
|
|
1370
|
-
window.parent.postMessage({ name: 'JoinProject', code: data.code }, applicationHost);
|
|
1371
|
-
},
|
|
1372
|
-
"GetCurrentSurveyAnswers": function (data) {
|
|
1373
|
-
window.parent.postMessage({
|
|
1374
|
-
name: 'GetCurrentSurveyAnswers',
|
|
1375
|
-
messageID: data.messageID
|
|
1376
|
-
}, applicationHost);
|
|
1377
|
-
},
|
|
1378
|
-
"GetStepConfiguration": function (data) {
|
|
1379
|
-
window.parent.postMessage({
|
|
1380
|
-
name: 'GetStepConfiguration',
|
|
1381
|
-
messageID: data.messageID
|
|
1382
|
-
}, applicationHost);
|
|
1383
|
-
},
|
|
1384
|
-
"CompleteStep": function (data) {
|
|
1385
|
-
window.parent.postMessage({
|
|
1386
|
-
name: 'CompleteStep',
|
|
1387
|
-
messageID: data.messageID,
|
|
1388
|
-
answer: data.answer
|
|
1389
|
-
}, applicationHost);
|
|
1390
|
-
}
|
|
1391
|
-
};
|
|
1392
|
-
}
|
|
1393
|
-
if (!window.webkit || !window.webkit.messageHandlers || !windowHasAnyActions()) {
|
|
1394
|
-
window.webkit = {
|
|
1395
|
-
messageHandlers: {}
|
|
1396
|
-
};
|
|
1397
|
-
}
|
|
1398
|
-
addActions(supportedActions);
|
|
1399
1293
|
window.addEventListener("message", receiveWindowMessage, false);
|
|
1400
1294
|
}
|
|
1401
1295
|
nextMessageID() {
|
|
@@ -1556,6 +1450,23 @@ class MyDataHelps {
|
|
|
1556
1450
|
return true;
|
|
1557
1451
|
}
|
|
1558
1452
|
}
|
|
1453
|
+
sendBasicMessage(key) {
|
|
1454
|
+
const mdh = this;
|
|
1455
|
+
const messageID = this.nextMessageID();
|
|
1456
|
+
return new Promise(function (resolve) {
|
|
1457
|
+
var _a, _b, _c;
|
|
1458
|
+
mdh.messageHandlers[messageID] = function (response) {
|
|
1459
|
+
resolve(response);
|
|
1460
|
+
mdh.messageHandlers[messageID] = null;
|
|
1461
|
+
};
|
|
1462
|
+
if ((_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b[key]) {
|
|
1463
|
+
window.webkit.messageHandlers[key].postMessage({ messageID: messageID });
|
|
1464
|
+
}
|
|
1465
|
+
else {
|
|
1466
|
+
(_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({ name: key, messageID: messageID }, mdh.applicationHost);
|
|
1467
|
+
}
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1559
1470
|
}
|
|
1560
1471
|
//iOS/Android directly invoke window.MyDataHelps and window.RKStudioClient
|
|
1561
1472
|
//so it's necessary to explicitly ensure they are present on the window
|