@careevolution/mydatahelps-js 2.1.0 → 2.3.1
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/LICENSE +201 -201
- package/MyDataHelps.css +147 -147
- package/MyDataHelps.js +700 -666
- package/MyDataHelps.min.js +2 -1
- package/MyDataHelps.min.js.map +1 -1
- package/README.md +10 -10
- package/package.json +26 -24
package/MyDataHelps.js
CHANGED
|
@@ -1,666 +1,700 @@
|
|
|
1
|
-
var MyDataHelps = {};
|
|
2
|
-
// For backwards compatibility
|
|
3
|
-
var RKStudioClient = {};
|
|
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
|
-
return
|
|
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
|
-
return
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
return
|
|
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
|
-
}
|
|
1
|
+
var MyDataHelps = {};
|
|
2
|
+
// For backwards compatibility
|
|
3
|
+
var RKStudioClient = {};
|
|
4
|
+
|
|
5
|
+
var accessTokenRenewalBufferSeconds = 120;
|
|
6
|
+
var currentMessageID = 1;
|
|
7
|
+
var messageHandlers = [];
|
|
8
|
+
var registeredEventHandlers = {};
|
|
9
|
+
var apiBasePath = 'api/v1/delegated/';
|
|
10
|
+
|
|
11
|
+
function getParentOrigin() {
|
|
12
|
+
var ancestorOrigins = document.location.ancestorOrigins;
|
|
13
|
+
if (ancestorOrigins && ancestorOrigins[0]) {
|
|
14
|
+
return ancestorOrigins[0];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return '*';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function acceptableOrigin(origin) {
|
|
21
|
+
if (origin === '*') return true;
|
|
22
|
+
|
|
23
|
+
var allowedApplicationHosts = [
|
|
24
|
+
'localhost',
|
|
25
|
+
'careevolution.com',
|
|
26
|
+
'internal',
|
|
27
|
+
'b3-deploys.com',
|
|
28
|
+
'mydatahelps.org',
|
|
29
|
+
'platform.joinallofus.org',
|
|
30
|
+
'careevolution.dev',
|
|
31
|
+
'ce.dev'
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
var sourceURL = new URL(origin);
|
|
35
|
+
for (var k = 0; k < allowedApplicationHosts.length; k++) {
|
|
36
|
+
if (sourceURL.hostname === allowedApplicationHosts[k] || sourceURL.hostname.endsWith("." + allowedApplicationHosts[k])) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
var applicationHost = getParentOrigin();
|
|
44
|
+
if (!acceptableOrigin(applicationHost)) {
|
|
45
|
+
console.error("Application is not hosted at an approved origin.");
|
|
46
|
+
throw "Application is not hosted at an approved origin.";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
var supportedActions;
|
|
50
|
+
if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.ResearchKit) {
|
|
51
|
+
supportedActions = {
|
|
52
|
+
"GetDelegatedAccessToken": function (data) { window.parent.postMessage({ name: 'GetDelegatedAccessToken', messageID: data.messageID }, applicationHost); },
|
|
53
|
+
"GetDeviceInfo": function (data) { window.parent.postMessage({ name: 'GetDeviceInfo', messageID: data.messageID }, applicationHost); }
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
supportedActions = {
|
|
58
|
+
"GetDelegatedAccessToken": function (data) { window.parent.postMessage({ name: 'GetDelegatedAccessToken', messageID: data.messageID }, applicationHost); },
|
|
59
|
+
"GetDeviceInfo": function (data) { window.parent.postMessage({ name: 'GetDeviceInfo', messageID: data.messageID }, applicationHost); },
|
|
60
|
+
"StartParticipantSurvey": function (data) { window.parent.postMessage({ name: 'StartParticipantSurvey', messageID: data.messageID, surveyName: data.surveyName }, applicationHost); },
|
|
61
|
+
"OpenExternalLink": function (data) { window.parent.postMessage({ name: 'OpenExternalUrl', url: data }, applicationHost); },
|
|
62
|
+
"OpenEmbeddedLink": function (data) { window.parent.postMessage({ name: 'OpenEmbeddedUrl', url: data }, applicationHost); },
|
|
63
|
+
"OpenExternalApplication": function (data) { window.parent.postMessage({ name: 'OpenApplication', messageID: data.messageID, url: data.url, modal: data.modal }, applicationHost); },
|
|
64
|
+
"Dismiss": function () { window.parent.postMessage({ name: 'Dismiss' }, applicationHost); },
|
|
65
|
+
"PopNavigation": function () { window.parent.postMessage({ name: 'Back' }, applicationHost); },
|
|
66
|
+
"ShowTab": function (data) { window.parent.postMessage({ name: 'ShowTab', tabKey: data }, applicationHost); },
|
|
67
|
+
"ShowParticipantDashboard": function (data) { window.parent.postMessage({ name: 'ShowParticipantDashboard', dashboardKey: data.dashboardKey, modal: data.modal }, applicationHost); },
|
|
68
|
+
"ShowParticipantWebVisualization": function (data) { window.parent.postMessage({ name: 'ShowParticipantWebVisualization', visualizationKey: data.visualizationKey, parameters: data.parameters, modal: data.modal }, applicationHost); },
|
|
69
|
+
"ShowParticipantWebVisualizationPDF": function (data) { window.parent.postMessage({ name: 'ShowParticipantWebVisualizationPDF', visualizationKey: data.visualizationKey, parameters: data.parameters, modal: data.modal, landscape: data.landscape, htmlViewerZoom: data.htmlViewerZoom }, applicationHost); },
|
|
70
|
+
"DeleteProviderAccount": function (data) { window.parent.postMessage({ name: 'DeleteProviderAccount', messageID: data.messageID, accountID: data.accountID }, applicationHost); },
|
|
71
|
+
"ConnectExternalAccount": function (data) { window.parent.postMessage({ name: 'ConnectExternalAccount', externalAccountProviderID: data.externalAccountProviderID }, applicationHost); },
|
|
72
|
+
"ShowProject": function (data) { window.parent.postMessage({ name: 'ShowProject', code: data.code }, applicationHost); },
|
|
73
|
+
"JoinProject": function (data) { window.parent.postMessage({ name: 'JoinProject', code: data.code }, applicationHost); }
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
var unsupportedActions = ["SetHeight", "ResearchKit"];
|
|
78
|
+
|
|
79
|
+
var supportedEvents = ["surveyDidFinish", "applicationDidBecomeVisible", "externalAccountSyncComplete", "tokenWillExpire"];
|
|
80
|
+
|
|
81
|
+
function windowHasAnyActions() {
|
|
82
|
+
for (var action in supportedActions) {
|
|
83
|
+
if (window.webkit.messageHandlers[action]) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
for (var action in unsupportedActions) {
|
|
88
|
+
if (window.webkit.messageHandlers[unsupportedActions[action]]) {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!window.webkit || !window.webkit.messageHandlers || !windowHasAnyActions()) {
|
|
96
|
+
window.webkit = {
|
|
97
|
+
messageHandlers: {}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
for (var action in supportedActions) {
|
|
102
|
+
window.webkit.messageHandlers[action] = window.webkit.messageHandlers[action] || { postMessage: supportedActions[action] };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
var nextMessageID = function () {
|
|
106
|
+
return currentMessageID++;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
function validateWindowMessageOrigin(message) {
|
|
110
|
+
if (applicationHost === "*") {
|
|
111
|
+
return acceptableOrigin(message.origin);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return message.origin === applicationHost;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
var receiveWindowMessage = function (message) {
|
|
118
|
+
if (!validateWindowMessageOrigin(message)) {
|
|
119
|
+
console.error("message.origin '" + message.origin + "' is not allowed.");
|
|
120
|
+
throw "message.origin '" + message.origin + "' is not allowed.";
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (message.data.messageID) {
|
|
124
|
+
MyDataHelps.setActionResult(message.data);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
MyDataHelps.triggerEvent(message.data);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
window.addEventListener("message", receiveWindowMessage, false);
|
|
132
|
+
|
|
133
|
+
MyDataHelps.setActionResult = function (data) {
|
|
134
|
+
messageHandlers[data.messageID](data);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
RKStudioClient.setActionResult = function (data) {
|
|
138
|
+
MyDataHelps.setActionResult(data);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
MyDataHelps.triggerEvent = function (event) {
|
|
142
|
+
var eventName = event.type;
|
|
143
|
+
if (supportedEvents.includes(eventName) && registeredEventHandlers[eventName]) {
|
|
144
|
+
registeredEventHandlers[eventName].forEach(function (handler) {
|
|
145
|
+
handler(event);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
//Authorization
|
|
151
|
+
|
|
152
|
+
var refreshTokenPromise = null;
|
|
153
|
+
MyDataHelps.connect = function () {
|
|
154
|
+
var refreshDelegatedAccessToken = function () {
|
|
155
|
+
MyDataHelps.token = null;
|
|
156
|
+
|
|
157
|
+
refreshTokenPromise = new Promise(function (resolve, reject) {
|
|
158
|
+
var messageID = nextMessageID();
|
|
159
|
+
messageHandlers[messageID] = function (tokenResponse) {
|
|
160
|
+
if (tokenResponse.success) {
|
|
161
|
+
MyDataHelps.tokenExpires = Date.now() + (tokenResponse.data.expires_in * 1000);
|
|
162
|
+
MyDataHelps.token = tokenResponse.data;
|
|
163
|
+
MyDataHelps.baseUrl = tokenResponse.baseUrl;
|
|
164
|
+
window.setTimeout(refreshDelegatedAccessToken, ((tokenResponse.data.expires_in - accessTokenRenewalBufferSeconds) * 1000));
|
|
165
|
+
resolve();
|
|
166
|
+
} else {
|
|
167
|
+
MyDataHelps.token = null;
|
|
168
|
+
reject(tokenResponse.message);
|
|
169
|
+
}
|
|
170
|
+
messageHandlers[messageID] = null;
|
|
171
|
+
refreshTokenPromise = null;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
window.webkit.messageHandlers.GetDelegatedAccessToken.postMessage({ messageID: messageID });
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
if (MyDataHelps.token && Date.now() < MyDataHelps.tokenExpires) {
|
|
179
|
+
return Promise.resolve();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (!refreshTokenPromise) {
|
|
183
|
+
refreshDelegatedAccessToken();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Re-use promise if refresh already in progress
|
|
187
|
+
return refreshTokenPromise;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
//Initializing access token manually
|
|
191
|
+
MyDataHelps.setParticipantAccessToken = function (token, baseUrl) {
|
|
192
|
+
MyDataHelps.token = token;
|
|
193
|
+
if (baseUrl) {
|
|
194
|
+
MyDataHelps.baseUrl = baseUrl;
|
|
195
|
+
}
|
|
196
|
+
MyDataHelps.tokenExpires = Date.now() + (token.expires_in * 1000);
|
|
197
|
+
window.setTimeout(function () {
|
|
198
|
+
MyDataHelps.triggerEvent({ type: "tokenWillExpire" });
|
|
199
|
+
}, ((token.expires_in - accessTokenRenewalBufferSeconds) * 1000));
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
//Actions
|
|
203
|
+
|
|
204
|
+
MyDataHelps.completeStep = function (answer) {
|
|
205
|
+
if (answer === undefined || answer === null) answer = '';
|
|
206
|
+
|
|
207
|
+
if (window.webkit.messageHandlers.ResearchKit) {
|
|
208
|
+
window.webkit.messageHandlers.ResearchKit.postMessage(answer);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
MyDataHelps.startSurvey = function (surveyName) {
|
|
213
|
+
var messageID = nextMessageID();
|
|
214
|
+
window.webkit.messageHandlers.StartParticipantSurvey.postMessage({ messageID: messageID, surveyName: surveyName });
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
MyDataHelps.openExternalUrl = function (url) {
|
|
218
|
+
window.webkit.messageHandlers.OpenExternalLink.postMessage(url);
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
MyDataHelps.openEmbeddedUrl = function (url) {
|
|
222
|
+
window.webkit.messageHandlers.OpenEmbeddedLink.postMessage(url);
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
MyDataHelps.openApplication = function (url, options) {
|
|
226
|
+
var messageID = nextMessageID();
|
|
227
|
+
window.webkit.messageHandlers.OpenExternalApplication.postMessage({ messageID: messageID, url: url, modal: options && options.modal ? true : false });
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
MyDataHelps.dismiss = function () {
|
|
231
|
+
window.webkit.messageHandlers.Dismiss.postMessage({});
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
MyDataHelps.back = function () {
|
|
235
|
+
window.webkit.messageHandlers.PopNavigation.postMessage({});
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
MyDataHelps.showTab = function (tabKey) {
|
|
239
|
+
window.webkit.messageHandlers.ShowTab.postMessage(tabKey);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
MyDataHelps.showDashboard = function (dashboardKey, options) {
|
|
243
|
+
window.webkit.messageHandlers.ShowParticipantDashboard.postMessage({
|
|
244
|
+
dashboardKey: dashboardKey,
|
|
245
|
+
modal: options && options.modal ? true : false,
|
|
246
|
+
title: options && options.title ? options.title : undefined
|
|
247
|
+
});
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
MyDataHelps.showWebVisualization = function (visualizationKey, parameters, options) {
|
|
251
|
+
window.webkit.messageHandlers.ShowParticipantWebVisualization.postMessage({
|
|
252
|
+
visualizationKey: visualizationKey,
|
|
253
|
+
parameters: parameters,
|
|
254
|
+
modal: options && options.modal ? true : false,
|
|
255
|
+
title: options && options.title ? options.title : undefined
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
MyDataHelps.showWebVisualizationPdf = function (visualizationKey, parameters, options) {
|
|
260
|
+
window.webkit.messageHandlers.ShowParticipantWebVisualizationPDF.postMessage({
|
|
261
|
+
visualizationKey: visualizationKey,
|
|
262
|
+
parameters: parameters,
|
|
263
|
+
landscape: options && options.landscape ? true : false,
|
|
264
|
+
htmlViewerZoom: options && options.htmlViewerZoom
|
|
265
|
+
});
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
MyDataHelps.setStatusBarStyle = function (style) {
|
|
269
|
+
if (window.webkit.messageHandlers.SetStatusBarStyle) {
|
|
270
|
+
window.webkit.messageHandlers.SetStatusBarStyle.postMessage({ style: style });
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
MyDataHelps.requestReview = function (cooldownDays) {
|
|
275
|
+
if (window.webkit.messageHandlers.RequestReview) {
|
|
276
|
+
window.webkit.messageHandlers.RequestReview.postMessage({ cooldownDays: cooldownDays });
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
MyDataHelps.getDeviceInfo = function () {
|
|
281
|
+
return new Promise(function (resolve, reject) {
|
|
282
|
+
var messageID = nextMessageID();
|
|
283
|
+
messageHandlers[messageID] = function (deviceInfoResponse) {
|
|
284
|
+
resolve(deviceInfoResponse.data);
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
if (window.webkit.messageHandlers.GetDeviceInfo) {
|
|
288
|
+
window.webkit.messageHandlers.GetDeviceInfo.postMessage({ messageID: messageID });
|
|
289
|
+
} else {
|
|
290
|
+
reject();
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
MyDataHelps.deleteExternalAccount = function (accountID) {
|
|
296
|
+
return new Promise(function (resolve, reject) {
|
|
297
|
+
var messageID = nextMessageID();
|
|
298
|
+
messageHandlers[messageID] = function (deleteProviderAccountResponse) {
|
|
299
|
+
if (!deleteProviderAccountResponse.success) {
|
|
300
|
+
reject(deleteProviderAccountResponse);
|
|
301
|
+
} else {
|
|
302
|
+
resolve(deleteProviderAccountResponse);
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
if (window.webkit.messageHandlers.DeleteProviderAccount) {
|
|
307
|
+
window.webkit.messageHandlers.DeleteProviderAccount.postMessage({ messageID: messageID, accountID: accountID });
|
|
308
|
+
} else {
|
|
309
|
+
reject();
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
MyDataHelps.connectExternalAccount = function (externalAccountProviderID) {
|
|
315
|
+
if (window.webkit.messageHandlers.ConnectExternalAccount) {
|
|
316
|
+
window.webkit.messageHandlers.ConnectExternalAccount.postMessage({ externalAccountProviderID: externalAccountProviderID });
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
MyDataHelps.showProject = function (projectCode) {
|
|
321
|
+
if (window.webkit.messageHandlers.ShowProject) {
|
|
322
|
+
window.webkit.messageHandlers.ShowProject.postMessage({ code: projectCode });
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
MyDataHelps.joinProject = function (projectCode) {
|
|
327
|
+
if (window.webkit.messageHandlers.JoinProject) {
|
|
328
|
+
window.webkit.messageHandlers.JoinProject.postMessage({ code: projectCode });
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
MyDataHelps.getCurrentLanguage = function () {
|
|
333
|
+
var searchParams = new URLSearchParams(window.location.search);
|
|
334
|
+
if (searchParams.has("lang")) {
|
|
335
|
+
return searchParams.get("lang");
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
return navigator.language;
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
MyDataHelps.showGoogleFitSettings = function () {
|
|
343
|
+
if (window.webkit.messageHandlers.ShowGoogleFitSettings) {
|
|
344
|
+
window.webkit.messageHandlers.ShowGoogleFitSettings.postMessage({});
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
//Events
|
|
349
|
+
|
|
350
|
+
MyDataHelps.on = function (eventName, eventHandler) {
|
|
351
|
+
|
|
352
|
+
if (!supportedEvents.includes(eventName)) {
|
|
353
|
+
throw new Error(eventName + " is not a supported event type.");
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (!registeredEventHandlers[eventName]) {
|
|
357
|
+
registeredEventHandlers[eventName] = [];
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
registeredEventHandlers[eventName].push(eventHandler);
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
MyDataHelps.off = function (eventName, eventHandler) {
|
|
364
|
+
|
|
365
|
+
if (!supportedEvents.includes(eventName)) {
|
|
366
|
+
throw new Error(eventName + " is not a supported event type.");
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (!registeredEventHandlers[eventName]) return;
|
|
370
|
+
|
|
371
|
+
var eventHandlerIndex = registeredEventHandlers[eventName].indexOf(eventHandler);
|
|
372
|
+
|
|
373
|
+
if (eventHandlerIndex !== -1) {
|
|
374
|
+
registeredEventHandlers[eventName].splice(eventHandlerIndex, 1);
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
//Data
|
|
379
|
+
|
|
380
|
+
var makeUrl = function (endpoint) {
|
|
381
|
+
if (!MyDataHelps.baseUrl) {
|
|
382
|
+
console.error("Cannot use makeUrl without MyDataHelps.baseUrl.");
|
|
383
|
+
throw "Cannot use makeUrl without MyDataHelps.baseUrl.";
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return MyDataHelps.baseUrl + apiBasePath + endpoint;
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
var makeRequest = function (endpoint, method, body) {
|
|
390
|
+
if (!MyDataHelps.token || !MyDataHelps.token.access_token) {
|
|
391
|
+
throw "No access_token available for request authorization.";
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
var url = makeUrl(endpoint);
|
|
395
|
+
|
|
396
|
+
var headers = new Headers();
|
|
397
|
+
headers.append('Authorization', 'Bearer ' + MyDataHelps.token.access_token);
|
|
398
|
+
headers.append('Accept', 'application/json, text/javascript, */*; q=0.01');
|
|
399
|
+
headers.append('Accept-Language', MyDataHelps.getCurrentLanguage());
|
|
400
|
+
if (!!body) {
|
|
401
|
+
headers.append('Content-Type', 'application/json');
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
var init = {
|
|
405
|
+
method: method,
|
|
406
|
+
headers: headers
|
|
407
|
+
};
|
|
408
|
+
if (!!body) {
|
|
409
|
+
init.body = JSON.stringify(body);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
return fetch(url, init);
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
var validateResponse = function (response) {
|
|
416
|
+
if (!response.ok) {
|
|
417
|
+
throw response.statusText;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
return response;
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
var escapeParam = function (param) {
|
|
424
|
+
return String(param)
|
|
425
|
+
.replace("\\", "\\\\")
|
|
426
|
+
.replace(",", "\\,");
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
var reduceArrayAndEscape = function (param) {
|
|
430
|
+
if (Array.isArray(param)) {
|
|
431
|
+
var escapedParams = param.map(function (elem) { return escapeParam(elem); });
|
|
432
|
+
return escapedParams.join(",");
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
return escapeParam(param);
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
var convertDateToIsoString = function (date) {
|
|
439
|
+
var paramAsDate = new Date(date);
|
|
440
|
+
if (isNaN(paramAsDate.getTime())) {
|
|
441
|
+
throw "Cannot interpret parameter as Date";
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
return paramAsDate.toISOString();
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
MyDataHelps.getParticipantInfo = function () {
|
|
448
|
+
var endpoint = 'participant';
|
|
449
|
+
|
|
450
|
+
return MyDataHelps
|
|
451
|
+
.connect()
|
|
452
|
+
.then(function () { return makeRequest(endpoint, 'GET', null); })
|
|
453
|
+
.then(function (response) { return validateResponse(response); })
|
|
454
|
+
.then(function (response) { return response.json(); });
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
MyDataHelps.getProjectInfo = function () {
|
|
458
|
+
var endpoint = 'project';
|
|
459
|
+
|
|
460
|
+
return MyDataHelps
|
|
461
|
+
.connect()
|
|
462
|
+
.then(function () { return makeRequest(endpoint, 'GET', null); })
|
|
463
|
+
.then(function (response) { return validateResponse(response); })
|
|
464
|
+
.then(function (response) { return response.json(); });
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
MyDataHelps.querySurveyAnswers = function (queryParameters) {
|
|
468
|
+
if (queryParameters.hasOwnProperty("surveyName")) {
|
|
469
|
+
queryParameters.surveyName = reduceArrayAndEscape(queryParameters.surveyName);
|
|
470
|
+
}
|
|
471
|
+
if (queryParameters.hasOwnProperty("stepIdentifier")) {
|
|
472
|
+
queryParameters.stepIdentifier = reduceArrayAndEscape(queryParameters.stepIdentifier);
|
|
473
|
+
}
|
|
474
|
+
if (queryParameters.hasOwnProperty("resultIdentifier")) {
|
|
475
|
+
queryParameters.resultIdentifier = reduceArrayAndEscape(queryParameters.resultIdentifier);
|
|
476
|
+
}
|
|
477
|
+
if (queryParameters.hasOwnProperty("answer")) {
|
|
478
|
+
queryParameters.answer = reduceArrayAndEscape(queryParameters.answer);
|
|
479
|
+
}
|
|
480
|
+
if (queryParameters.hasOwnProperty("before")) {
|
|
481
|
+
queryParameters.before = convertDateToIsoString(queryParameters.before);
|
|
482
|
+
}
|
|
483
|
+
if (queryParameters.hasOwnProperty("after")) {
|
|
484
|
+
queryParameters.after = convertDateToIsoString(queryParameters.after);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
var queryString = new URLSearchParams(queryParameters).toString();
|
|
488
|
+
var endpoint = 'surveyanswers?' + queryString;
|
|
489
|
+
|
|
490
|
+
return MyDataHelps
|
|
491
|
+
.connect()
|
|
492
|
+
.then(function () { return makeRequest(endpoint, 'GET', null); })
|
|
493
|
+
.then(function (response) { return validateResponse(response); })
|
|
494
|
+
.then(function (response) { return response.json(); });
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
MyDataHelps.deleteSurveyResult = function (resultID) {
|
|
498
|
+
var endpoint = 'surveyresults/' + encodeURIComponent(resultID);
|
|
499
|
+
|
|
500
|
+
return MyDataHelps
|
|
501
|
+
.connect()
|
|
502
|
+
.then(function () { return makeRequest(endpoint, 'DELETE', null); })
|
|
503
|
+
.then(function (response) { return validateResponse(response); })
|
|
504
|
+
.then(function (response) { return; });
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
MyDataHelps.queryDeviceData = function (queryParameters) {
|
|
508
|
+
if (queryParameters.hasOwnProperty("type")) {
|
|
509
|
+
queryParameters.type = reduceArrayAndEscape(queryParameters.type);
|
|
510
|
+
}
|
|
511
|
+
if (queryParameters.hasOwnProperty("observedBefore")) {
|
|
512
|
+
queryParameters.observedBefore = convertDateToIsoString(queryParameters.observedBefore);
|
|
513
|
+
}
|
|
514
|
+
if (queryParameters.hasOwnProperty("observedAfter")) {
|
|
515
|
+
queryParameters.observedAfter = convertDateToIsoString(queryParameters.observedAfter);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
var queryString = new URLSearchParams(queryParameters).toString();
|
|
519
|
+
var endpoint = 'devicedata?' + queryString;
|
|
520
|
+
|
|
521
|
+
return MyDataHelps
|
|
522
|
+
.connect()
|
|
523
|
+
.then(function () { return makeRequest(endpoint, 'GET', null); })
|
|
524
|
+
.then(function (response) { return validateResponse(response); })
|
|
525
|
+
.then(function (response) { return response.json(); });
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
MyDataHelps.persistDeviceData = function (deviceDataPoints) {
|
|
529
|
+
var endpoint = 'devicedata';
|
|
530
|
+
|
|
531
|
+
return MyDataHelps
|
|
532
|
+
.connect()
|
|
533
|
+
.then(function () { return makeRequest(endpoint, 'POST', deviceDataPoints); })
|
|
534
|
+
.then(function (response) { return validateResponse(response); })
|
|
535
|
+
.then(function (response) { return; });
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
MyDataHelps.trackCustomEvent = function (event) {
|
|
539
|
+
var endpoint = 'customevents';
|
|
540
|
+
|
|
541
|
+
return MyDataHelps
|
|
542
|
+
.connect()
|
|
543
|
+
.then(function () { return makeRequest(endpoint, 'POST', event); })
|
|
544
|
+
.then(function (response) { return validateResponse(response); })
|
|
545
|
+
.then(function (response) { return; });
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
MyDataHelps.querySurveyTasks = function (queryParameters) {
|
|
549
|
+
if (queryParameters.hasOwnProperty("status")) {
|
|
550
|
+
queryParameters.status = reduceArrayAndEscape(queryParameters.status);
|
|
551
|
+
}
|
|
552
|
+
if (queryParameters.hasOwnProperty("surveyName")) {
|
|
553
|
+
queryParameters.surveyName = reduceArrayAndEscape(queryParameters.surveyName);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
var queryString = new URLSearchParams(queryParameters).toString();
|
|
557
|
+
var endpoint = 'surveytasks?' + queryString;
|
|
558
|
+
|
|
559
|
+
return MyDataHelps
|
|
560
|
+
.connect()
|
|
561
|
+
.then(function () { return makeRequest(endpoint, 'GET', null); })
|
|
562
|
+
.then(function (response) { return validateResponse(response); })
|
|
563
|
+
.then(function (response) { return response.json(); });
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
MyDataHelps.queryNotifications = function (queryParameters) {
|
|
567
|
+
if (queryParameters.hasOwnProperty("sentBefore")) {
|
|
568
|
+
queryParameters.sentBefore = convertDateToIsoString(queryParameters.sentBefore);
|
|
569
|
+
}
|
|
570
|
+
if (queryParameters.hasOwnProperty("sentAfter")) {
|
|
571
|
+
queryParameters.sentAfter = convertDateToIsoString(queryParameters.sentAfter);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
var queryString = new URLSearchParams(queryParameters).toString();
|
|
575
|
+
var endpoint = 'notifications?' + queryString;
|
|
576
|
+
|
|
577
|
+
return MyDataHelps
|
|
578
|
+
.connect()
|
|
579
|
+
.then(function () { return makeRequest(endpoint, 'GET', null); })
|
|
580
|
+
.then(function (response) { return validateResponse(response); })
|
|
581
|
+
.then(function (response) { return response.json(); });
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
MyDataHelps.getExternalAccountProviders = function (search, category, pageSize, pageNumber) {
|
|
585
|
+
var searchParameters = {};
|
|
586
|
+
if (!!search) searchParameters.search = search;
|
|
587
|
+
if (!!category) searchParameters.category = category;
|
|
588
|
+
if (!!pageSize) searchParameters.pageSize = pageSize;
|
|
589
|
+
if (!!pageNumber) searchParameters.pageNumber = pageNumber;
|
|
590
|
+
|
|
591
|
+
var queryString = new URLSearchParams(searchParameters).toString();
|
|
592
|
+
var endpoint = 'externalaccountproviders?' + queryString;
|
|
593
|
+
|
|
594
|
+
return MyDataHelps
|
|
595
|
+
.connect()
|
|
596
|
+
.then(function () { return makeRequest(endpoint, 'GET', null); })
|
|
597
|
+
.then(function (response) { return validateResponse(response); })
|
|
598
|
+
.then(function (response) { return response.json(); });
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
MyDataHelps.getExternalAccounts = function () {
|
|
602
|
+
var endpoint = 'externalaccounts';
|
|
603
|
+
|
|
604
|
+
return MyDataHelps
|
|
605
|
+
.connect()
|
|
606
|
+
.then(function () { return makeRequest(endpoint, 'GET', null); })
|
|
607
|
+
.then(function (response) { return validateResponse(response); })
|
|
608
|
+
.then(function (response) { return response.json(); });
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
MyDataHelps.refreshExternalAccount = function (accountId) {
|
|
612
|
+
var endpoint = 'externalaccounts/refresh/' + accountId;
|
|
613
|
+
|
|
614
|
+
return MyDataHelps
|
|
615
|
+
.connect()
|
|
616
|
+
.then(function () { return makeRequest(endpoint, 'POST', null); })
|
|
617
|
+
.then(function (response) { return validateResponse(response); })
|
|
618
|
+
.then(function (response) { return; });
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
MyDataHelps.invokeCustomApi = function (customApi, method, queryParameters, jsonResponse) {
|
|
622
|
+
if (customApi.includes('?')) {
|
|
623
|
+
throw new Error("Cannot include query parameters directly in the \"customApi\" string. Provide as an argument for \"queryParameters\" instead.");
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
var endpoint = 'custom/' + customApi;
|
|
627
|
+
method = method.toUpperCase();
|
|
628
|
+
if (queryParameters !== null && queryParameters !== undefined && (method === 'GET' || method === 'DELETE')) {
|
|
629
|
+
var parameterString = new URLSearchParams(queryParameters).toString();
|
|
630
|
+
endpoint += "?" + parameterString;
|
|
631
|
+
queryParameters = null;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
return MyDataHelps
|
|
635
|
+
.connect()
|
|
636
|
+
.then(function () { return makeRequest(endpoint, method, queryParameters); })
|
|
637
|
+
.then(function (response) { return validateResponse(response); })
|
|
638
|
+
.then(function (response) { return jsonResponse ? response.json() : undefined; });
|
|
639
|
+
};
|
|
640
|
+
|
|
641
|
+
//Embedded surveys and tasks
|
|
642
|
+
|
|
643
|
+
function getBaseUrl() {
|
|
644
|
+
return MyDataHelps.baseUrl || 'https://mydatahelps.org/';
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
MyDataHelps.startEmbeddedSurvey = function (linkIdentifier, surveyName, language) {
|
|
648
|
+
if (!language) { language = this.getCurrentLanguage(); }
|
|
649
|
+
var surveyUrl = getBaseUrl() + "mydatahelps/" + linkIdentifier + '/surveylink/' + surveyName + "?lang=" + language;
|
|
650
|
+
return startEmbeddedSurvey(surveyUrl);
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
MyDataHelps.startEmbeddedTask = function (linkIdentifier, taskLinkIdentifier, language) {
|
|
654
|
+
if (!language) { language = this.getCurrentLanguage(); }
|
|
655
|
+
var surveyUrl = getBaseUrl() + "mydatahelps/" + linkIdentifier + '/tasklink/' + taskLinkIdentifier + "?lang=" + language;
|
|
656
|
+
return startEmbeddedSurvey(surveyUrl);
|
|
657
|
+
};
|
|
658
|
+
|
|
659
|
+
function startEmbeddedSurvey(surveyUrl) {
|
|
660
|
+
var mdhSurveyModalId = 'mydatahelps-survey-modal';
|
|
661
|
+
|
|
662
|
+
return new Promise(function (resolve, reject) {
|
|
663
|
+
if (document.getElementById(mdhSurveyModalId)) {
|
|
664
|
+
reject("Survey already in progress");
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
window.addEventListener("message", function listener(message) {
|
|
669
|
+
if (message.origin !== new URL(getBaseUrl()).origin) {
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
var frame = document.getElementById('mydatahelps-survey-frame').contentWindow;
|
|
673
|
+
if (message.source !== frame) {
|
|
674
|
+
return;
|
|
675
|
+
}
|
|
676
|
+
if (message.data.name == 'SurveyWindowInitialized') {
|
|
677
|
+
document.getElementById(mdhSurveyModalId).className += " loaded";
|
|
678
|
+
} else if (message.data.name == 'SurveyFinished') {
|
|
679
|
+
document.getElementById(mdhSurveyModalId).remove();
|
|
680
|
+
document.body.className = document.body.className.replace("no-scroll", "");
|
|
681
|
+
window.removeEventListener("message", listener, true);
|
|
682
|
+
resolve(message.data);
|
|
683
|
+
}
|
|
684
|
+
}, true);
|
|
685
|
+
|
|
686
|
+
var surveyModal = document.createElement('div');
|
|
687
|
+
surveyModal.className = 'mydatahelps-survey-modal';
|
|
688
|
+
surveyModal.id = mdhSurveyModalId;
|
|
689
|
+
surveyModal.innerHTML = "<div class='mydatahelps-survey'><div class='loader'>Loading...</div><iframe id='mydatahelps-survey-frame' allow='camera' sandbox='allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-presentation allow-same-origin allow-scripts' src='" + surveyUrl + "'></iframe></div>";
|
|
690
|
+
document.body.append(surveyModal);
|
|
691
|
+
document.body.className += ' no-scroll';
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
//iOS/Android directly invoke window.MyDataHelps and window.RKStudioClient
|
|
696
|
+
//so it's necessary to explicitly ensure they are present on the window
|
|
697
|
+
window.MyDataHelps = MyDataHelps;
|
|
698
|
+
window.RKStudioClient = RKStudioClient;
|
|
699
|
+
|
|
700
|
+
export { MyDataHelps as default };
|