@careevolution/mydatahelps-js 3.18.1-FixMessagePassing.0 → 3.19.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.js CHANGED
@@ -28,51 +28,32 @@ function __awaiter(thisArg, _arguments, P, generator) {
28
28
  class MyDataHelps {
29
29
  // Surveys
30
30
  startSurvey(surveyName) {
31
- var _a, _b, _c;
32
31
  if (this.isStandaloneMode()) {
33
32
  this.startDelegatedSurvey(`${this.baseUrl}/survey?surveyName=${encodeURIComponent(surveyName)}`);
34
33
  }
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
- }
34
+ else if (window.webkit.messageHandlers.StartParticipantSurvey) {
35
+ let messageID = this.nextMessageID();
36
+ window.webkit.messageHandlers.StartParticipantSurvey.postMessage({
37
+ messageID: messageID,
38
+ surveyName: surveyName
39
+ });
49
40
  }
50
41
  }
51
42
  completeStep(answer) {
52
- var _a, _b, _c, _d, _e, _f, _g;
53
43
  if (answer === undefined || answer === null)
54
44
  answer = '';
55
45
  if (typeof answer !== 'string') {
56
46
  answer = JSON.stringify(answer);
57
47
  }
58
- if ((_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.ResearchKit) {
48
+ if (window.webkit.messageHandlers.ResearchKit) {
59
49
  window.webkit.messageHandlers.ResearchKit.postMessage(answer);
60
50
  }
61
- else if ((_d = (_c = window.webkit) === null || _c === void 0 ? void 0 : _c.messageHandlers) === null || _d === void 0 ? void 0 : _d.CompleteStep) {
51
+ else if (window.webkit.messageHandlers.CompleteStep) {
62
52
  let messageID = this.nextMessageID();
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
- }
53
+ window.webkit.messageHandlers.CompleteStep.postMessage({
54
+ messageID: messageID,
55
+ answer: answer
56
+ });
76
57
  }
77
58
  }
78
59
  querySurveyAnswers(queryParameters) {
@@ -219,94 +200,51 @@ class MyDataHelps {
219
200
  }
220
201
  // Navigation
221
202
  openExternalUrl(url) {
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);
203
+ if (window.webkit.messageHandlers.OpenExternalLink) {
204
+ window.webkit.messageHandlers.OpenExternalLink.postMessage(url);
231
205
  }
232
206
  }
233
207
  openEmbeddedUrl(url) {
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);
208
+ if (window.webkit.messageHandlers.OpenEmbeddedLink) {
209
+ window.webkit.messageHandlers.OpenEmbeddedLink.postMessage(url);
243
210
  }
244
211
  }
245
212
  showTab(tabKey) {
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) {
213
+ if (window.webkit.messageHandlers.ShowTab) {
248
214
  window.webkit.messageHandlers.ShowTab.postMessage(tabKey);
249
215
  }
250
- else {
251
- (_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({ name: 'ShowTab', tabKey: tabKey }, this.applicationHost);
252
- }
253
216
  }
254
217
  openApplication(url, options) {
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) {
218
+ if (window.webkit.messageHandlers.OpenExternalApplication) {
219
+ let messageID = this.nextMessageID();
257
220
  window.webkit.messageHandlers.OpenExternalApplication.postMessage({
258
- messageID: this.nextMessageID(),
221
+ messageID: messageID,
259
222
  url: url,
260
223
  modal: !!(options && options.modal)
261
224
  });
262
225
  }
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
- }
271
226
  }
272
227
  dismiss() {
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) {
228
+ if (window.webkit.messageHandlers.Dismiss) {
275
229
  window.webkit.messageHandlers.Dismiss.postMessage({});
276
230
  }
277
- else {
278
- (_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({ name: 'Dismiss' }, this.applicationHost);
279
- }
280
231
  }
281
232
  back() {
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) {
233
+ if (window.webkit.messageHandlers.PopNavigation) {
284
234
  window.webkit.messageHandlers.PopNavigation.postMessage({});
285
235
  }
286
- else {
287
- (_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({ name: 'Back' }, this.applicationHost);
288
- }
289
236
  }
290
237
  showDashboard(dashboardKey, options) {
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) {
238
+ if (window.webkit.messageHandlers.ShowParticipantDashboard) {
293
239
  window.webkit.messageHandlers.ShowParticipantDashboard.postMessage({
294
240
  dashboardKey: dashboardKey,
295
241
  modal: !!(options && options.modal),
296
242
  title: options && options.title ? options.title : undefined
297
243
  });
298
244
  }
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
- }
306
245
  }
307
246
  showWebVisualization(visualizationKey, parameters, options) {
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) {
247
+ if (window.webkit.messageHandlers.ShowParticipantWebVisualization) {
310
248
  window.webkit.messageHandlers.ShowParticipantWebVisualization.postMessage({
311
249
  visualizationKey: visualizationKey,
312
250
  parameters: parameters,
@@ -314,18 +252,9 @@ class MyDataHelps {
314
252
  title: options && options.title ? options.title : undefined
315
253
  });
316
254
  }
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
- }
325
255
  }
326
256
  showWebVisualizationPdf(visualizationKey, parameters, options) {
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) {
257
+ if (window.webkit.messageHandlers.ShowParticipantWebVisualizationPDF) {
329
258
  window.webkit.messageHandlers.ShowParticipantWebVisualizationPDF.postMessage({
330
259
  visualizationKey: visualizationKey,
331
260
  parameters: parameters,
@@ -333,33 +262,16 @@ class MyDataHelps {
333
262
  htmlViewerZoom: options && options.htmlViewerZoom
334
263
  });
335
264
  }
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
- }
345
265
  }
346
266
  showProject(projectCode) {
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) {
267
+ if (window.webkit.messageHandlers.ShowProject) {
349
268
  window.webkit.messageHandlers.ShowProject.postMessage({ code: projectCode });
350
269
  }
351
- else {
352
- (_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({ name: 'ShowProject', code: projectCode }, this.applicationHost);
353
- }
354
270
  }
355
271
  joinProject(projectCode) {
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) {
272
+ if (window.webkit.messageHandlers.JoinProject) {
358
273
  window.webkit.messageHandlers.JoinProject.postMessage({ code: projectCode });
359
274
  }
360
- else {
361
- (_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({ name: 'JoinProject', code: projectCode }, this.applicationHost);
362
- }
363
275
  }
364
276
  //Events
365
277
  on(eventName, callback) {
@@ -538,6 +450,8 @@ class MyDataHelps {
538
450
  if (queryParameters.hasOwnProperty("modifiedAfter")) {
539
451
  queryParameters.modifiedAfter = MyDataHelps.convertDateToIsoString(queryParameters.modifiedAfter);
540
452
  }
453
+ MyDataHelps.flattenPropertyShallow(queryParameters, "dataSource");
454
+ MyDataHelps.flattenPropertyShallow(queryParameters, "properties");
541
455
  const queryString = new URLSearchParams(queryParameters).toString();
542
456
  const endpoint = 'devicedata?' + queryString;
543
457
  const mdh = this;
@@ -576,6 +490,8 @@ class MyDataHelps {
576
490
  if (queryParameters.hasOwnProperty("modifiedAfter")) {
577
491
  queryParameters.modifiedAfter = MyDataHelps.convertDateToIsoString(queryParameters.modifiedAfter);
578
492
  }
493
+ MyDataHelps.flattenPropertyShallow(queryParameters, "dataSource");
494
+ MyDataHelps.flattenPropertyShallow(queryParameters, "properties");
579
495
  const queryString = new URLSearchParams(queryParameters).toString();
580
496
  const endpoint = 'devicedata/aggregate?' + queryString;
581
497
  const mdh = this;
@@ -611,6 +527,8 @@ class MyDataHelps {
611
527
  if (queryParameters.hasOwnProperty("modifiedAfter")) {
612
528
  queryParameters.modifiedAfter = MyDataHelps.convertDateToIsoString(queryParameters.modifiedAfter);
613
529
  }
530
+ MyDataHelps.flattenPropertyShallow(queryParameters, "dataSource");
531
+ MyDataHelps.flattenPropertyShallow(queryParameters, "properties");
614
532
  const queryString = new URLSearchParams(queryParameters).toString();
615
533
  const endpoint = 'devicedata/aggregate/dailysleep?' + queryString;
616
534
  const mdh = this;
@@ -626,6 +544,21 @@ class MyDataHelps {
626
544
  return response.json();
627
545
  });
628
546
  }
547
+ getDeviceDataV2AllDataTypes() {
548
+ const endpoint = 'devicedata/allDataTypes';
549
+ const mdh = this;
550
+ return this
551
+ .connect()
552
+ .then(function () {
553
+ return mdh.makeRequest(endpoint, 'GET', null, 'v2');
554
+ })
555
+ .then(function (response) {
556
+ return MyDataHelps.validateResponse(response);
557
+ })
558
+ .then(function (response) {
559
+ return response.json();
560
+ });
561
+ }
629
562
  // External Accounts
630
563
  getExternalAccountProviders(search, category, pageSize, pageNumber) {
631
564
  let searchParameters = {};
@@ -654,7 +587,6 @@ class MyDataHelps {
654
587
  }
655
588
  connectExternalAccount(externalAccountProviderID, options) {
656
589
  return new Promise((resolve, reject) => {
657
- var _a, _b, _c;
658
590
  const messageID = mdh.nextMessageID();
659
591
  mdh.messageHandlers[messageID] = function (connectProviderAccountResponse) {
660
592
  if (connectProviderAccountResponse && connectProviderAccountResponse.success) {
@@ -707,13 +639,8 @@ class MyDataHelps {
707
639
  reject(error);
708
640
  });
709
641
  }
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
- }
642
+ else if (window.webkit.messageHandlers.ConnectExternalAccount) {
643
+ window.webkit.messageHandlers.ConnectExternalAccount.postMessage(Object.assign({ externalAccountProviderID: externalAccountProviderID, messageID: messageID }, options));
717
644
  }
718
645
  });
719
646
  }
@@ -761,28 +688,23 @@ class MyDataHelps {
761
688
  });
762
689
  }
763
690
  return new Promise(function (resolve, reject) {
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) {
691
+ if (window.webkit.messageHandlers.DeleteProviderAccount) {
692
+ const messageID = mdh.nextMessageID();
693
+ mdh.messageHandlers[messageID] = function (deleteProviderAccountResponse) {
694
+ if (!deleteProviderAccountResponse.success) {
695
+ reject(deleteProviderAccountResponse);
696
+ }
697
+ else {
698
+ resolve(deleteProviderAccountResponse);
699
+ }
700
+ };
775
701
  window.webkit.messageHandlers.DeleteProviderAccount.postMessage({
776
702
  messageID: messageID,
777
703
  accountID: accountID
778
704
  });
779
705
  }
780
706
  else {
781
- (_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({
782
- name: 'DeleteProviderAccount',
783
- messageID: messageID,
784
- accountID: accountID
785
- }, this.applicationHost);
707
+ reject();
786
708
  }
787
709
  });
788
710
  }
@@ -995,7 +917,8 @@ class MyDataHelps {
995
917
  let refreshDelegatedAccessToken = function () {
996
918
  mdh.token = null;
997
919
  mdh.refreshTokenPromise = new Promise(function (resolve, reject) {
998
- return mdh.sendBasicMessage("GetDelegatedAccessToken").then(function (tokenResponse) {
920
+ let messageID = mdh.nextMessageID();
921
+ mdh.messageHandlers[messageID] = function (tokenResponse) {
999
922
  if (tokenResponse.success) {
1000
923
  mdh.tokenExpires = Date.now() + (tokenResponse.data.expires_in * 1000);
1001
924
  mdh.token = tokenResponse.data;
@@ -1007,8 +930,10 @@ class MyDataHelps {
1007
930
  mdh.token = null;
1008
931
  reject(tokenResponse.message);
1009
932
  }
933
+ mdh.messageHandlers[messageID] = null;
1010
934
  mdh.refreshTokenPromise = null;
1011
- });
935
+ };
936
+ window.webkit.messageHandlers.GetDelegatedAccessToken.postMessage({ messageID: messageID });
1012
937
  });
1013
938
  };
1014
939
  if (this.token && Date.now() < this.tokenExpires) {
@@ -1048,8 +973,7 @@ class MyDataHelps {
1048
973
  }
1049
974
  }
1050
975
  setStatusBarStyle(style) {
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) {
976
+ if (window.webkit.messageHandlers.SetStatusBarStyle) {
1053
977
  window.webkit.messageHandlers.SetStatusBarStyle.postMessage({ style: style });
1054
978
  }
1055
979
  }
@@ -1059,10 +983,15 @@ class MyDataHelps {
1059
983
  if (mdh.isStandaloneMode()) {
1060
984
  resolve(null);
1061
985
  }
1062
- else {
1063
- mdh.sendBasicMessage("GetDeviceInfo").then(function (deviceInfoResponse) {
986
+ else if (window.webkit.messageHandlers.GetDeviceInfo) {
987
+ let messageID = mdh.nextMessageID();
988
+ mdh.messageHandlers[messageID] = function (deviceInfoResponse) {
1064
989
  resolve(deviceInfoResponse.data);
1065
- });
990
+ };
991
+ window.webkit.messageHandlers.GetDeviceInfo.postMessage({ messageID: messageID });
992
+ }
993
+ else {
994
+ reject();
1066
995
  }
1067
996
  });
1068
997
  }
@@ -1078,10 +1007,15 @@ class MyDataHelps {
1078
1007
  if (mdh.isStandaloneMode()) {
1079
1008
  resolve(null);
1080
1009
  }
1081
- else {
1082
- mdh.sendBasicMessage("GetStepConfiguration").then(function (stepConfigurationResponse) {
1010
+ else if (window.webkit.messageHandlers.GetStepConfiguration) {
1011
+ let messageID = mdh.nextMessageID();
1012
+ mdh.messageHandlers[messageID] = function (stepConfigurationResponse) {
1083
1013
  resolve(stepConfigurationResponse.data);
1084
- });
1014
+ };
1015
+ window.webkit.messageHandlers.GetStepConfiguration.postMessage({ messageID: messageID });
1016
+ }
1017
+ else {
1018
+ reject();
1085
1019
  }
1086
1020
  });
1087
1021
  }
@@ -1092,21 +1026,19 @@ class MyDataHelps {
1092
1026
  resolve(null);
1093
1027
  }
1094
1028
  mdh.getDeviceInfo().then(function (deviceInfo) {
1095
- var _a;
1096
1029
  if (deviceInfo.platform !== "Web") {
1097
1030
  resolve({ surveyMode: "Survey" });
1098
1031
  }
1099
- else {
1032
+ else if (window.webkit.messageHandlers.GetSurveyContext) {
1100
1033
  let messageID = mdh.nextMessageID();
1101
1034
  mdh.messageHandlers[messageID] = function (surveyContextResponse) {
1102
1035
  resolve(surveyContextResponse.data);
1103
1036
  };
1104
- (_a = window.parent) === null || _a === void 0 ? void 0 : _a.postMessage({
1105
- name: 'GetSurveyContext',
1106
- messageID: messageID
1107
- }, mdh.applicationHost);
1108
1037
  window.webkit.messageHandlers.GetSurveyContext.postMessage({ messageID: messageID });
1109
1038
  }
1039
+ else {
1040
+ reject();
1041
+ }
1110
1042
  }).catch(function (error) {
1111
1043
  reject();
1112
1044
  });
@@ -1118,10 +1050,15 @@ class MyDataHelps {
1118
1050
  if (mdh.isStandaloneMode()) {
1119
1051
  resolve(null);
1120
1052
  }
1121
- else {
1122
- mdh.sendBasicMessage("GetCurrentSurveyAnswers").then(function (currentSurveyAnswersResponse) {
1053
+ else if (window.webkit.messageHandlers.GetCurrentSurveyAnswers) {
1054
+ let messageID = mdh.nextMessageID();
1055
+ mdh.messageHandlers[messageID] = function (currentSurveyAnswersResponse) {
1123
1056
  resolve(currentSurveyAnswersResponse.data);
1124
- });
1057
+ };
1058
+ window.webkit.messageHandlers.GetCurrentSurveyAnswers.postMessage({ messageID: messageID });
1059
+ }
1060
+ else {
1061
+ reject();
1125
1062
  }
1126
1063
  });
1127
1064
  }
@@ -1154,14 +1091,12 @@ class MyDataHelps {
1154
1091
  return this.language || navigator.language;
1155
1092
  }
1156
1093
  showGoogleFitSettings() {
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) {
1094
+ if (window.webkit.messageHandlers.ShowGoogleFitSettings) {
1159
1095
  window.webkit.messageHandlers.ShowGoogleFitSettings.postMessage({});
1160
1096
  }
1161
1097
  }
1162
1098
  requestReview(cooldownDays) {
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) {
1099
+ if (window.webkit.messageHandlers.RequestReview) {
1165
1100
  window.webkit.messageHandlers.RequestReview.postMessage({ cooldownDays: cooldownDays });
1166
1101
  }
1167
1102
  }
@@ -1241,12 +1176,12 @@ class MyDataHelps {
1241
1176
  this.registeredEventHandlers = {};
1242
1177
  this.refreshTokenPromise = null;
1243
1178
  this.standaloneMode = false;
1244
- this.applicationHost = null;
1245
1179
  if (this.handleConnectExternalAccountResponse()) {
1246
1180
  return;
1247
1181
  }
1248
1182
  let mdh = this;
1249
- mdh.applicationHost = getParentOrigin();
1183
+ let applicationHost = getParentOrigin();
1184
+ let supportedActions;
1250
1185
  function getParentOrigin() {
1251
1186
  let ancestorOrigins = document.location.ancestorOrigins;
1252
1187
  if (ancestorOrigins && ancestorOrigins[0]) {
@@ -1269,10 +1204,23 @@ class MyDataHelps {
1269
1204
  if (mdh.isStandaloneMode() && message.origin === window.location.origin) {
1270
1205
  return true;
1271
1206
  }
1272
- if (mdh.applicationHost === "*") {
1207
+ if (applicationHost === "*") {
1273
1208
  return acceptableOrigin(message.origin);
1274
1209
  }
1275
- return message.origin === mdh.applicationHost;
1210
+ return message.origin === applicationHost;
1211
+ }
1212
+ function addActions(actions) {
1213
+ for (let action in actions) {
1214
+ if (!window.webkit.messageHandlers[action]) {
1215
+ try {
1216
+ window.webkit.messageHandlers[action] = { postMessage: actions[action] };
1217
+ }
1218
+ catch (error) {
1219
+ console.log("Unable to add missing actions on this platform: " + error);
1220
+ return;
1221
+ }
1222
+ }
1223
+ }
1276
1224
  }
1277
1225
  function receiveWindowMessage(message) {
1278
1226
  if (!validateWindowMessageOrigin(message)) {
@@ -1287,9 +1235,188 @@ class MyDataHelps {
1287
1235
  mdh.triggerEvent(message.data);
1288
1236
  }
1289
1237
  }
1290
- if (!acceptableOrigin(mdh.applicationHost)) {
1238
+ function windowHasAnyActions() {
1239
+ for (let action in supportedActions) {
1240
+ if (window.webkit.messageHandlers[action]) {
1241
+ return true;
1242
+ }
1243
+ }
1244
+ for (let action in mdh.unsupportedActions) {
1245
+ if (window.webkit.messageHandlers[mdh.unsupportedActions[action]]) {
1246
+ return true;
1247
+ }
1248
+ }
1249
+ return false;
1250
+ }
1251
+ if (!acceptableOrigin(applicationHost)) {
1291
1252
  console.log("Detected unsupported parent origin domain.");
1292
1253
  }
1254
+ if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.ResearchKit) {
1255
+ // Presence of ResearchKit handler indicates the SDK is being used from within a WebViewStep. For pre-SDK backwards compatiblity,
1256
+ // WebViewStep setup registers the following handlers: GetDeviceInfo, DeleteProviderAccount, ConnectExternalAccount
1257
+ // ShowParticipantWebVisualizationPDF, ResearchKit
1258
+ supportedActions = {
1259
+ "GetDelegatedAccessToken": function (data) {
1260
+ window.parent.postMessage({
1261
+ name: 'GetDelegatedAccessToken',
1262
+ messageID: data.messageID
1263
+ }, applicationHost);
1264
+ },
1265
+ "OpenExternalLink": function (data) {
1266
+ window.parent.postMessage({
1267
+ name: 'OpenExternalUrl',
1268
+ url: data
1269
+ }, applicationHost);
1270
+ },
1271
+ "OpenEmbeddedLink": function (data) {
1272
+ window.parent.postMessage({
1273
+ name: 'OpenEmbeddedUrl',
1274
+ url: data
1275
+ }, applicationHost);
1276
+ },
1277
+ "GetCurrentSurveyAnswers": function (data) {
1278
+ window.parent.postMessage({
1279
+ name: 'GetCurrentSurveyAnswers',
1280
+ messageID: data.messageID
1281
+ }, applicationHost);
1282
+ },
1283
+ "GetStepConfiguration": function (data) {
1284
+ window.parent.postMessage({
1285
+ name: 'GetStepConfiguration',
1286
+ messageID: data.messageID
1287
+ }, applicationHost);
1288
+ },
1289
+ "GetSurveyContext": function (data) {
1290
+ window.parent.postMessage({
1291
+ name: 'GetSurveyContext',
1292
+ messageID: data.messageID
1293
+ }, applicationHost);
1294
+ },
1295
+ "CompleteStep": function (data) {
1296
+ window.parent.postMessage({
1297
+ name: 'CompleteStep',
1298
+ messageID: data.messageID,
1299
+ answer: data.answer
1300
+ }, applicationHost);
1301
+ }
1302
+ };
1303
+ }
1304
+ else {
1305
+ supportedActions = {
1306
+ "GetDelegatedAccessToken": function (data) {
1307
+ window.parent.postMessage({
1308
+ name: 'GetDelegatedAccessToken',
1309
+ messageID: data.messageID
1310
+ }, applicationHost);
1311
+ },
1312
+ "GetDeviceInfo": function (data) {
1313
+ window.parent.postMessage({ name: 'GetDeviceInfo', messageID: data.messageID }, applicationHost);
1314
+ },
1315
+ "StartParticipantSurvey": function (data) {
1316
+ window.parent.postMessage({
1317
+ name: 'StartParticipantSurvey',
1318
+ messageID: data.messageID,
1319
+ surveyName: data.surveyName
1320
+ }, applicationHost);
1321
+ },
1322
+ "OpenExternalLink": function (data) {
1323
+ window.parent.postMessage({ name: 'OpenExternalUrl', url: data }, applicationHost);
1324
+ },
1325
+ "OpenEmbeddedLink": function (data) {
1326
+ window.parent.postMessage({ name: 'OpenEmbeddedUrl', url: data }, applicationHost);
1327
+ },
1328
+ "OpenExternalApplication": function (data) {
1329
+ window.parent.postMessage({
1330
+ name: 'OpenApplication',
1331
+ messageID: data.messageID,
1332
+ url: data.url,
1333
+ modal: data.modal
1334
+ }, applicationHost);
1335
+ },
1336
+ "Dismiss": function () {
1337
+ window.parent.postMessage({ name: 'Dismiss' }, applicationHost);
1338
+ },
1339
+ "PopNavigation": function () {
1340
+ window.parent.postMessage({ name: 'Back' }, applicationHost);
1341
+ },
1342
+ "ShowTab": function (data) {
1343
+ window.parent.postMessage({ name: 'ShowTab', tabKey: data }, applicationHost);
1344
+ },
1345
+ "ShowParticipantDashboard": function (data) {
1346
+ window.parent.postMessage({
1347
+ name: 'ShowParticipantDashboard',
1348
+ dashboardKey: data.dashboardKey,
1349
+ modal: data.modal
1350
+ }, applicationHost);
1351
+ },
1352
+ "ShowParticipantWebVisualization": function (data) {
1353
+ window.parent.postMessage({
1354
+ name: 'ShowParticipantWebVisualization',
1355
+ visualizationKey: data.visualizationKey,
1356
+ parameters: data.parameters,
1357
+ modal: data.modal
1358
+ }, applicationHost);
1359
+ },
1360
+ "ShowParticipantWebVisualizationPDF": function (data) {
1361
+ window.parent.postMessage({
1362
+ name: 'ShowParticipantWebVisualizationPDF',
1363
+ visualizationKey: data.visualizationKey,
1364
+ parameters: data.parameters,
1365
+ modal: data.modal,
1366
+ landscape: data.landscape,
1367
+ htmlViewerZoom: data.htmlViewerZoom
1368
+ }, applicationHost);
1369
+ },
1370
+ "DeleteProviderAccount": function (data) {
1371
+ window.parent.postMessage({
1372
+ name: 'DeleteProviderAccount',
1373
+ messageID: data.messageID,
1374
+ accountID: data.accountID
1375
+ }, applicationHost);
1376
+ },
1377
+ "ConnectExternalAccount": function (data) {
1378
+ window.parent.postMessage({
1379
+ name: 'ConnectExternalAccount',
1380
+ externalAccountProviderID: data.externalAccountProviderID,
1381
+ messageID: data.messageID,
1382
+ openNewWindow: data.openNewWindow,
1383
+ width: data.width,
1384
+ height: data.height
1385
+ }, applicationHost);
1386
+ },
1387
+ "ShowProject": function (data) {
1388
+ window.parent.postMessage({ name: 'ShowProject', code: data.code }, applicationHost);
1389
+ },
1390
+ "JoinProject": function (data) {
1391
+ window.parent.postMessage({ name: 'JoinProject', code: data.code }, applicationHost);
1392
+ },
1393
+ "GetCurrentSurveyAnswers": function (data) {
1394
+ window.parent.postMessage({
1395
+ name: 'GetCurrentSurveyAnswers',
1396
+ messageID: data.messageID
1397
+ }, applicationHost);
1398
+ },
1399
+ "GetStepConfiguration": function (data) {
1400
+ window.parent.postMessage({
1401
+ name: 'GetStepConfiguration',
1402
+ messageID: data.messageID
1403
+ }, applicationHost);
1404
+ },
1405
+ "CompleteStep": function (data) {
1406
+ window.parent.postMessage({
1407
+ name: 'CompleteStep',
1408
+ messageID: data.messageID,
1409
+ answer: data.answer
1410
+ }, applicationHost);
1411
+ }
1412
+ };
1413
+ }
1414
+ if (!window.webkit || !window.webkit.messageHandlers || !windowHasAnyActions()) {
1415
+ window.webkit = {
1416
+ messageHandlers: {}
1417
+ };
1418
+ }
1419
+ addActions(supportedActions);
1293
1420
  window.addEventListener("message", receiveWindowMessage, false);
1294
1421
  }
1295
1422
  nextMessageID() {
@@ -1367,6 +1494,16 @@ class MyDataHelps {
1367
1494
  }
1368
1495
  return paramAsDate.toISOString();
1369
1496
  }
1497
+ static flattenPropertyShallow(params, property) {
1498
+ if (params[property] === undefined || params[property] === null)
1499
+ return;
1500
+ for (var key in params[property]) {
1501
+ if (params[property].hasOwnProperty(key)) {
1502
+ params[`${property}.${key}`] = MyDataHelps.escapeParam(params[property][key]);
1503
+ }
1504
+ }
1505
+ delete params[property];
1506
+ }
1370
1507
  startEmbeddedSurveyInternal(surveyUrl) {
1371
1508
  let mdhSurveyModalId = 'mydatahelps-survey-modal';
1372
1509
  let mdh = this;
@@ -1450,23 +1587,6 @@ class MyDataHelps {
1450
1587
  return true;
1451
1588
  }
1452
1589
  }
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
- }
1470
1590
  }
1471
1591
  //iOS/Android directly invoke window.MyDataHelps and window.RKStudioClient
1472
1592
  //so it's necessary to explicitly ensure they are present on the window