|
95 | 95 | async function retrieve(){
|
96 | 96 | const recipient = "WA Health Summary Viewer";
|
97 | 97 |
|
| 98 | + let retrieveResult; |
98 | 99 | let passcode;
|
99 |
| - const needPasscode = shlClient.flag({ shl: shl ?? "" })?.includes('P'); |
100 |
| - if (needPasscode) { |
101 |
| - passcode = prompt("WA Health Summary Viewer\n----------------------------------------\nEnter a passcode to access this SMART Health Link\nIf no passcode was set, just click \"OK\""); |
| 100 | + try { |
| 101 | + retrieveResult = await fetch(shlClient.url({ shl: shl ?? "" }), { |
| 102 | + method: 'POST', |
| 103 | + headers: { |
| 104 | + 'content-type': 'application/json', |
| 105 | + }, |
| 106 | + body: JSON.stringify({ |
| 107 | + passcode: "", |
| 108 | + recipient: recipient, |
| 109 | + }), |
| 110 | + }); |
| 111 | + let message = await retrieveResult.text(); |
| 112 | + message = JSON.parse(message)?.message; |
| 113 | + if (!retrieveResult.ok && retrieveResult.status === 400 && message === "Passcode required") { |
| 114 | + // Failed the password requirement |
| 115 | + const needPasscode = shlClient.flag({ shl: shl ?? "" })?.includes('P'); |
| 116 | + if (needPasscode) { |
| 117 | + passcode = prompt("WA Health Summary Viewer\n----------------------------------------\nEnter a passcode to access this SMART Health Link\nIf no passcode was set, just click \"OK\""); |
| 118 | + } |
| 119 | + } |
| 120 | + } catch (e) { |
| 121 | + console.log(e); |
102 | 122 | }
|
103 |
| - let retrieveResult; |
| 123 | + |
104 | 124 | try {
|
105 | 125 | retrieveResult = await shlClient.retrieve({
|
106 | 126 | shl: shl ?? "",
|
|
123 | 143 | } else if (retrieveResult.status === 401) {
|
124 | 144 | // Failed the password requirement
|
125 | 145 | while (retrieveResult.status === 401) {
|
126 |
| - passcode = prompt(`WA Health Summary Viewer\n----------------------------------------\nEnter a passcode to access this SMART Health Link\nIf no passcode was set, just click \"OK\"${retrieveResult.error.remainingAttempts !== undefined ? "\nAttempts remaining: "+retrieveResult.error.remainingAttempts : ""}`); |
| 146 | + passcode = prompt(`WA Health Summary Viewer\n----------------------------------------\nEnter a passcode to access this SMART Health Link`); |
127 | 147 | try {
|
128 | 148 | retrieveResult = await shlClient.retrieve({
|
129 | 149 | shl: shl ?? "",
|
|
138 | 158 | }
|
139 | 159 | if (retrieveResult.error) {
|
140 | 160 | const managerLink = `<a href="${new URL(import.meta.url).origin}/view/${shlClient.id({ shl: shl ?? "" })}">Manage or reactivate it here</a>`;
|
141 |
| - errorMsg = `<p>The requested SMART Health Link has been deactivated due to too many failed password attempts.</p><p>Are you the owner of this link? ${managerLink}</p>`; |
| 161 | + errorMsg = `<p>You have been locked from accessing this SMART Health Link due to too many failed password attempts.</p><p>Are you the owner of this link? ${managerLink}</p>`; |
142 | 162 | }
|
143 | 163 | } else {
|
144 | 164 | errorMsg = retrieveResult.error;
|
|
0 commit comments