@careevolution/mydatahelps-js 3.17.0 → 3.18.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 CHANGED
@@ -31,7 +31,7 @@ export declare class MyDataHelps {
31
31
  triggerEvent(event: Model.EventData): void;
32
32
  setActionResult(data: Model.EventData): void;
33
33
  getParticipantInfo(): Promise<Model.ParticipantInfo>;
34
- persistParticipantInfo(demographics: Model.ParticipantDemographics, customFields: StringMap): Promise<Model.ParticipantInfo>;
34
+ persistParticipantInfo(demographics: Partial<Model.ParticipantDemographics>, customFields: StringMap): Promise<Model.ParticipantInfo>;
35
35
  getProjectInfo(): Promise<Model.ProjectInfo>;
36
36
  getDeviceDataPoint(id: Model.Guid): Promise<Model.DeviceDataPoint>;
37
37
  deleteDeviceDataPoint(id: Model.Guid): Promise<void>;
@@ -39,7 +39,7 @@ export declare class MyDataHelps {
39
39
  persistDeviceData(deviceDataPoints: Model.PersistableDeviceDataPoint[]): Promise<void>;
40
40
  queryDeviceDataV2(queryParameters: Model.DeviceDataV2Query): Promise<Model.DeviceDataV2Page>;
41
41
  queryDeviceDataV2Aggregate(queryParameters: Model.DeviceDataV2AggregateQuery): Promise<Model.DeviceDataV2AggregatePage>;
42
- queryDeviceDataV2DailySleep(queryParameters: Model.DeviceDataV2AggregateQuery): Promise<Model.DeviceDataV2AggregatePage>;
42
+ queryDeviceDataV2DailySleep(queryParameters: Model.DeviceDataV2AggregateQuery): Promise<Model.DeviceDataV2DailySleepPage>;
43
43
  getExternalAccountProviders(search: string | null, category: string | null, pageSize: number, pageNumber: number): Promise<Model.ExternalAccountProvidersPage>;
44
44
  connectExternalAccount(externalAccountProviderID: number, options?: Model.ConnectExternalAccountOptions): Promise<void>;
45
45
  getExternalAccounts(): Promise<Model.ExternalAccount[]>;
@@ -55,7 +55,7 @@ export declare class MyDataHelps {
55
55
  getFileDownloadUrl(key: string): Promise<Model.DownloadedFile>;
56
56
  deleteFile(key: string): Promise<void>;
57
57
  connect(): Promise<void>;
58
- setParticipantAccessToken(token: Model.Token, baseUrl: string): void;
58
+ setParticipantAccessToken(token: Model.Token, baseUrl?: string): void;
59
59
  isStandaloneMode(): boolean;
60
60
  enableStandaloneMode(): void;
61
61
  setStatusBarStyle(style: Model.StatusBarStyle): void;
@@ -70,7 +70,7 @@ export declare class MyDataHelps {
70
70
  requestReview(cooldownDays?: number): void;
71
71
  trackCustomEvent(event: Model.CustomEventInfo): Promise<void>;
72
72
  getDataCollectionSettings(): Promise<Model.DataCollectionSettings>;
73
- invokeCustomApi(customApi: string, method: string, queryParameters: string, jsonResponse: boolean): Promise<any>;
73
+ invokeCustomApi(customApi: string, method: string, queryParameters: string | string[][] | Record<string, string> | URLSearchParams | null | undefined, jsonResponse: boolean): Promise<any>;
74
74
  constructor();
75
75
  private readonly acceptableParentDomains;
76
76
  private readonly accessTokenRenewalBufferSeconds;
@@ -83,7 +83,6 @@ export declare class MyDataHelps {
83
83
  private refreshTokenPromise;
84
84
  private standaloneMode;
85
85
  private nextMessageID;
86
- private getBaseUrl;
87
86
  private makeUrl;
88
87
  private makeRequest;
89
88
  private getSupportedLanguage;
package/MyDataHelps.js CHANGED
@@ -1,270 +1,31 @@
1
- var e=[],t=[];function n(n,r){if(n&&"undefined"!=typeof document){var a,s=!0===r.prepend?"prepend":"append",d=!0===r.singleTag,i="string"==typeof r.container?document.querySelector(r.container):document.getElementsByTagName("head")[0];if(d){var u=e.indexOf(i);-1===u&&(u=e.push(i)-1,t[u]={}),a=t[u]&&t[u][s]?t[u][s]:t[u][s]=c();}else a=c();65279===n.charCodeAt(0)&&(n=n.substring(1)),a.styleSheet?a.styleSheet.cssText+=n:a.appendChild(document.createTextNode(n));}function c(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),r.attributes)for(var t=Object.keys(r.attributes),n=0;n<t.length;n++)e.setAttribute(t[n],r.attributes[t[n]]);var a="prepend"===s?"afterbegin":"beforeend";return i.insertAdjacentElement(a,e),e}}
2
-
3
- var css = "body.no-scroll{height:100%;overflow:hidden!important;position:fixed!important;width:100%}#mydatahelps-survey-modal{background:rgba(0,0,0,.5);bottom:0;left:0;position:fixed;right:0;top:0}#mydatahelps-survey-modal .mydatahelps-survey{background:#fff;border-radius:5px;box-sizing:border-box;height:calc(100% - 32px);margin:16px auto;max-width:768px;overflow:hidden;position:relative;z-index:5002}#mydatahelps-survey-modal .mydatahelps-survey iframe{border:none;bottom:0;height:100%;left:0;opacity:0;position:absolute;right:0;top:0;width:100%}#mydatahelps-survey-modal.loaded .mydatahelps-survey iframe{opacity:1}@media (max-width:768px){#mydatahelps-survey-modal .mydatahelps-survey{border-radius:0;height:100%;margin-bottom:0;margin-top:0}}#mydatahelps-survey-modal .mydatahelps-survey .loader{-webkit-animation:load3 1.4s linear infinite;animation:load3 1.4s linear infinite;background:#fff;background:-moz-linear-gradient(left,#bbb 10%,hsla(0,0%,100%,0) 42%);background:-webkit-linear-gradient(left,#bbb 10%,hsla(0,0%,100%,0) 42%);background:-o-linear-gradient(left,#bbb 10%,hsla(0,0%,100%,0) 42%);background:-ms-linear-gradient(left,#bbb 10%,hsla(0,0%,100%,0) 42%);background:linear-gradient(90deg,#bbb 10%,hsla(0,0%,100%,0) 42%);border-radius:50%;font-size:5px;height:11em;left:calc(50% - 5.5em);position:absolute;text-indent:-9999em;top:calc(50% - 5.5em);-webkit-transform:translateZ(0);-ms-transform:translateZ(0);transform:translateZ(0);width:11em;z-index:1}#mydatahelps-survey-modal .mydatahelps-survey .loader:before{background:#bbb;border-radius:100% 0 0 0;content:\"\";height:50%;left:0;position:absolute;top:0;width:50%}#mydatahelps-survey-modal .mydatahelps-survey .loader:after{background:#fff;border-radius:50%;bottom:0;content:\"\";height:75%;left:0;margin:auto;position:absolute;right:0;top:0;width:75%}#mydatahelps-survey-modal.loaded .mydatahelps-survey .loader{display:none}@-webkit-keyframes load3{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}to{-webkit-transform:rotate(1turn);transform:rotate(1turn)}}@keyframes load3{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}to{-webkit-transform:rotate(1turn);transform:rotate(1turn)}}";
4
- n(css,{});
1
+ /******************************************************************************
2
+ Copyright (c) Microsoft Corporation.
3
+
4
+ Permission to use, copy, modify, and/or distribute this software for any
5
+ purpose with or without fee is hereby granted.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
+ PERFORMANCE OF THIS SOFTWARE.
14
+ ***************************************************************************** */
15
+ /* global Reflect, Promise */
16
+
17
+
18
+ function __awaiter(thisArg, _arguments, P, generator) {
19
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
20
+ return new (P || (P = Promise))(function (resolve, reject) {
21
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
22
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
23
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
24
+ step((generator = generator.apply(thisArg, [])).next());
25
+ });
26
+ }
5
27
 
6
- var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
7
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
- return new (P || (P = Promise))(function (resolve, reject) {
9
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
- step((generator = generator.apply(thisArg, _arguments || [])).next());
13
- });
14
- };
15
28
  class MyDataHelps {
16
- constructor() {
17
- this.acceptableParentDomains = [
18
- 'localhost',
19
- 'careevolution.com',
20
- 'internal',
21
- 'b3-deploys.com',
22
- 'mydatahelps.org',
23
- 'platform.joinallofus.org',
24
- 'careevolution.dev',
25
- 'ce.dev',
26
- 'mydatahelps.dev'
27
- ];
28
- this.accessTokenRenewalBufferSeconds = 120;
29
- this.unsupportedActions = ["SetHeight", "ResearchKit"];
30
- this.supportedEvents = ["surveyDidFinish", "applicationDidBecomeVisible", "externalAccountSyncComplete", "tokenWillExpire"];
31
- this.supportedLanguages = [];
32
- this.currentMessageID = 1;
33
- this.messageHandlers = [];
34
- this.registeredEventHandlers = {};
35
- this.refreshTokenPromise = null;
36
- this.standaloneMode = false;
37
- if (this.handleConnectExternalAccountResponse()) {
38
- return;
39
- }
40
- let mdh = this;
41
- let applicationHost = getParentOrigin();
42
- let supportedActions;
43
- function getParentOrigin() {
44
- let ancestorOrigins = document.location.ancestorOrigins;
45
- if (ancestorOrigins && ancestorOrigins[0]) {
46
- return ancestorOrigins[0];
47
- }
48
- return '*';
49
- }
50
- function acceptableOrigin(origin) {
51
- if (origin === '*')
52
- return true;
53
- let sourceURL = new URL(origin);
54
- for (let k = 0; k < mdh.acceptableParentDomains.length; k++) {
55
- if (sourceURL.hostname === mdh.acceptableParentDomains[k] || sourceURL.hostname.endsWith("." + mdh.acceptableParentDomains[k])) {
56
- return true;
57
- }
58
- }
59
- return false;
60
- }
61
- function validateWindowMessageOrigin(message) {
62
- if (mdh.isStandaloneMode() && message.origin === window.location.origin) {
63
- return true;
64
- }
65
- if (applicationHost === "*") {
66
- return acceptableOrigin(message.origin);
67
- }
68
- return message.origin === applicationHost;
69
- }
70
- function addActions(actions) {
71
- for (let action in actions) {
72
- if (!window.webkit.messageHandlers[action]) {
73
- try {
74
- window.webkit.messageHandlers[action] = { postMessage: actions[action] };
75
- }
76
- catch (error) {
77
- console.log("Unable to add missing actions on this platform: " + error);
78
- return;
79
- }
80
- }
81
- }
82
- }
83
- function receiveWindowMessage(message) {
84
- if (!validateWindowMessageOrigin(message)) {
85
- // todo: this can generate tons of console errors when hosting some apps within webappstep (youtube content, for example )
86
- console.error("message.origin '" + message.origin + "' is not allowed.");
87
- throw "message.origin '" + message.origin + "' is not allowed.";
88
- }
89
- if (message.data.messageID) {
90
- mdh.setActionResult(message.data);
91
- }
92
- else {
93
- mdh.triggerEvent(message.data);
94
- }
95
- }
96
- function windowHasAnyActions() {
97
- for (let action in supportedActions) {
98
- if (window.webkit.messageHandlers[action]) {
99
- return true;
100
- }
101
- }
102
- for (let action in mdh.unsupportedActions) {
103
- if (window.webkit.messageHandlers[mdh.unsupportedActions[action]]) {
104
- return true;
105
- }
106
- }
107
- return false;
108
- }
109
- if (!acceptableOrigin(applicationHost)) {
110
- console.log("Detected unsupported parent origin domain.");
111
- }
112
- if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.ResearchKit) {
113
- // Presence of ResearchKit handler indicates the SDK is being used from within a WebViewStep. For pre-SDK backwards compatiblity,
114
- // WebViewStep setup registers the following handlers: GetDeviceInfo, DeleteProviderAccount, ConnectExternalAccount
115
- // ShowParticipantWebVisualizationPDF, ResearchKit
116
- supportedActions = {
117
- "GetDelegatedAccessToken": function (data) {
118
- window.parent.postMessage({
119
- name: 'GetDelegatedAccessToken',
120
- messageID: data.messageID
121
- }, applicationHost);
122
- },
123
- "GetCurrentSurveyAnswers": function (data) {
124
- window.parent.postMessage({
125
- name: 'GetCurrentSurveyAnswers',
126
- messageID: data.messageID
127
- }, applicationHost);
128
- },
129
- "GetStepConfiguration": function (data) {
130
- window.parent.postMessage({
131
- name: 'GetStepConfiguration',
132
- messageID: data.messageID
133
- }, applicationHost);
134
- },
135
- "GetSurveyContext": function (data) {
136
- window.parent.postMessage({
137
- name: 'GetSurveyContext',
138
- messageID: data.messageID
139
- }, applicationHost);
140
- },
141
- "CompleteStep": function (data) {
142
- window.parent.postMessage({
143
- name: 'CompleteStep',
144
- messageID: data.messageID,
145
- answer: data.answer
146
- }, applicationHost);
147
- }
148
- };
149
- }
150
- else {
151
- supportedActions = {
152
- "GetDelegatedAccessToken": function (data) {
153
- window.parent.postMessage({
154
- name: 'GetDelegatedAccessToken',
155
- messageID: data.messageID
156
- }, applicationHost);
157
- },
158
- "GetDeviceInfo": function (data) {
159
- window.parent.postMessage({ name: 'GetDeviceInfo', messageID: data.messageID }, applicationHost);
160
- },
161
- "StartParticipantSurvey": function (data) {
162
- window.parent.postMessage({
163
- name: 'StartParticipantSurvey',
164
- messageID: data.messageID,
165
- surveyName: data.surveyName
166
- }, applicationHost);
167
- },
168
- "OpenExternalLink": function (data) {
169
- window.parent.postMessage({ name: 'OpenExternalUrl', url: data }, applicationHost);
170
- },
171
- "OpenEmbeddedLink": function (data) {
172
- window.parent.postMessage({ name: 'OpenEmbeddedUrl', url: data }, applicationHost);
173
- },
174
- "OpenExternalApplication": function (data) {
175
- window.parent.postMessage({
176
- name: 'OpenApplication',
177
- messageID: data.messageID,
178
- url: data.url,
179
- modal: data.modal
180
- }, applicationHost);
181
- },
182
- "Dismiss": function () {
183
- window.parent.postMessage({ name: 'Dismiss' }, applicationHost);
184
- },
185
- "PopNavigation": function () {
186
- window.parent.postMessage({ name: 'Back' }, applicationHost);
187
- },
188
- "ShowTab": function (data) {
189
- window.parent.postMessage({ name: 'ShowTab', tabKey: data }, applicationHost);
190
- },
191
- "ShowParticipantDashboard": function (data) {
192
- window.parent.postMessage({
193
- name: 'ShowParticipantDashboard',
194
- dashboardKey: data.dashboardKey,
195
- modal: data.modal
196
- }, applicationHost);
197
- },
198
- "ShowParticipantWebVisualization": function (data) {
199
- window.parent.postMessage({
200
- name: 'ShowParticipantWebVisualization',
201
- visualizationKey: data.visualizationKey,
202
- parameters: data.parameters,
203
- modal: data.modal
204
- }, applicationHost);
205
- },
206
- "ShowParticipantWebVisualizationPDF": function (data) {
207
- window.parent.postMessage({
208
- name: 'ShowParticipantWebVisualizationPDF',
209
- visualizationKey: data.visualizationKey,
210
- parameters: data.parameters,
211
- modal: data.modal,
212
- landscape: data.landscape,
213
- htmlViewerZoom: data.htmlViewerZoom
214
- }, applicationHost);
215
- },
216
- "DeleteProviderAccount": function (data) {
217
- window.parent.postMessage({
218
- name: 'DeleteProviderAccount',
219
- messageID: data.messageID,
220
- accountID: data.accountID
221
- }, applicationHost);
222
- },
223
- "ConnectExternalAccount": function (data) {
224
- window.parent.postMessage({
225
- name: 'ConnectExternalAccount',
226
- externalAccountProviderID: data.externalAccountProviderID,
227
- messageID: data.messageID,
228
- openNewWindow: data.openNewWindow,
229
- width: data.width,
230
- height: data.height
231
- }, applicationHost);
232
- },
233
- "ShowProject": function (data) {
234
- window.parent.postMessage({ name: 'ShowProject', code: data.code }, applicationHost);
235
- },
236
- "JoinProject": function (data) {
237
- window.parent.postMessage({ name: 'JoinProject', code: data.code }, applicationHost);
238
- },
239
- "GetCurrentSurveyAnswers": function (data) {
240
- window.parent.postMessage({
241
- name: 'GetCurrentSurveyAnswers',
242
- messageID: data.messageID
243
- }, applicationHost);
244
- },
245
- "GetStepConfiguration": function (data) {
246
- window.parent.postMessage({
247
- name: 'GetStepConfiguration',
248
- messageID: data.messageID
249
- }, applicationHost);
250
- },
251
- "CompleteStep": function (data) {
252
- window.parent.postMessage({
253
- name: 'CompleteStep',
254
- messageID: data.messageID,
255
- answer: data.answer
256
- }, applicationHost);
257
- }
258
- };
259
- }
260
- if (!window.webkit || !window.webkit.messageHandlers || !windowHasAnyActions()) {
261
- window.webkit = {
262
- messageHandlers: {}
263
- };
264
- }
265
- addActions(supportedActions);
266
- window.addEventListener("message", receiveWindowMessage, false);
267
- }
268
29
  // Surveys
269
30
  startSurvey(surveyName) {
270
31
  if (this.isStandaloneMode()) {
@@ -434,7 +195,7 @@ class MyDataHelps {
434
195
  if (!language) {
435
196
  language = this.getCurrentLanguage();
436
197
  }
437
- let surveyUrl = this.getBaseUrl() + "mydatahelps/" + linkIdentifier + '/surveylink/' + surveyName + "?lang=" + language;
198
+ let surveyUrl = this.baseUrl + "mydatahelps/" + linkIdentifier + '/surveylink/' + surveyName + "?lang=" + language;
438
199
  return this.startEmbeddedSurveyInternal(surveyUrl);
439
200
  }
440
201
  // Navigation
@@ -1281,12 +1042,17 @@ class MyDataHelps {
1281
1042
  });
1282
1043
  }
1283
1044
  setCurrentLanguage(language) {
1284
- let supportedLanguage = this.getSupportedLanguage(language);
1285
- if (supportedLanguage) {
1286
- this.language = supportedLanguage;
1287
- }
1045
+ if (language) {
1046
+ let supportedLanguage = this.getSupportedLanguage(language);
1047
+ if (supportedLanguage) {
1048
+ this.language = supportedLanguage;
1049
+ }
1050
+ else {
1051
+ console.warn(`language ${language} not supported`);
1052
+ }
1053
+ }
1288
1054
  else {
1289
- console.warn(`language ${language} not supported`);
1055
+ this.language = language;
1290
1056
  }
1291
1057
  }
1292
1058
  getCurrentLanguage() {
@@ -1367,12 +1133,274 @@ class MyDataHelps {
1367
1133
  return jsonResponse ? response.json() : undefined;
1368
1134
  });
1369
1135
  }
1136
+ constructor() {
1137
+ this.baseUrl = 'https://mydatahelps.org/';
1138
+ this.acceptableParentDomains = [
1139
+ 'localhost',
1140
+ 'careevolution.com',
1141
+ 'internal',
1142
+ 'b3-deploys.com',
1143
+ 'mydatahelps.org',
1144
+ 'platform.joinallofus.org',
1145
+ 'careevolution.dev',
1146
+ 'ce.dev',
1147
+ 'mydatahelps.dev'
1148
+ ];
1149
+ this.accessTokenRenewalBufferSeconds = 120;
1150
+ this.unsupportedActions = ["SetHeight", "ResearchKit"];
1151
+ this.supportedEvents = ["surveyDidFinish", "applicationDidBecomeVisible", "externalAccountSyncComplete", "tokenWillExpire"];
1152
+ this.supportedLanguages = [];
1153
+ this.currentMessageID = 1;
1154
+ this.messageHandlers = [];
1155
+ this.registeredEventHandlers = {};
1156
+ this.refreshTokenPromise = null;
1157
+ this.standaloneMode = false;
1158
+ if (this.handleConnectExternalAccountResponse()) {
1159
+ return;
1160
+ }
1161
+ let mdh = this;
1162
+ let applicationHost = getParentOrigin();
1163
+ let supportedActions;
1164
+ function getParentOrigin() {
1165
+ let ancestorOrigins = document.location.ancestorOrigins;
1166
+ if (ancestorOrigins && ancestorOrigins[0]) {
1167
+ return ancestorOrigins[0];
1168
+ }
1169
+ return '*';
1170
+ }
1171
+ function acceptableOrigin(origin) {
1172
+ if (origin === '*')
1173
+ return true;
1174
+ let sourceURL = new URL(origin);
1175
+ for (let k = 0; k < mdh.acceptableParentDomains.length; k++) {
1176
+ if (sourceURL.hostname === mdh.acceptableParentDomains[k] || sourceURL.hostname.endsWith("." + mdh.acceptableParentDomains[k])) {
1177
+ return true;
1178
+ }
1179
+ }
1180
+ return false;
1181
+ }
1182
+ function validateWindowMessageOrigin(message) {
1183
+ if (mdh.isStandaloneMode() && message.origin === window.location.origin) {
1184
+ return true;
1185
+ }
1186
+ if (applicationHost === "*") {
1187
+ return acceptableOrigin(message.origin);
1188
+ }
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
+ }
1203
+ }
1204
+ function receiveWindowMessage(message) {
1205
+ if (!validateWindowMessageOrigin(message)) {
1206
+ // todo: this can generate tons of console errors when hosting some apps within webappstep (youtube content, for example )
1207
+ console.error("message.origin '" + message.origin + "' is not allowed.");
1208
+ throw "message.origin '" + message.origin + "' is not allowed.";
1209
+ }
1210
+ if (message.data.messageID) {
1211
+ mdh.setActionResult(message.data);
1212
+ }
1213
+ else {
1214
+ mdh.triggerEvent(message.data);
1215
+ }
1216
+ }
1217
+ function windowHasAnyActions() {
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)) {
1231
+ console.log("Detected unsupported parent origin domain.");
1232
+ }
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
+ window.addEventListener("message", receiveWindowMessage, false);
1400
+ }
1370
1401
  nextMessageID() {
1371
1402
  return this.currentMessageID++;
1372
1403
  }
1373
- getBaseUrl() {
1374
- return this.baseUrl || 'https://mydatahelps.org/';
1375
- }
1376
1404
  makeUrl(endpoint, apiVersion) {
1377
1405
  if (!this.baseUrl) {
1378
1406
  console.error("Cannot use makeUrl without MyDataHelps.baseUrl.");
@@ -1454,7 +1482,7 @@ class MyDataHelps {
1454
1482
  return;
1455
1483
  }
1456
1484
  window.addEventListener("message", function listener(message) {
1457
- if (message.origin !== new URL(mdh.getBaseUrl()).origin) {
1485
+ if (message.origin !== new URL(mdh.baseUrl).origin) {
1458
1486
  return;
1459
1487
  }
1460
1488
  let frame = document.getElementById('mydatahelps-survey-frame').contentWindow;
@@ -1486,7 +1514,7 @@ class MyDataHelps {
1486
1514
  return;
1487
1515
  }
1488
1516
  window.addEventListener("message", function listener(message) {
1489
- if (message.origin !== new URL(mdh.getBaseUrl()).origin) {
1517
+ if (message.origin !== new URL(mdh.baseUrl).origin) {
1490
1518
  return;
1491
1519
  }
1492
1520
  let frame = document.getElementById('mydatahelps-survey-frame').contentWindow;