({email, legacyGsuite})
| 143 | } |
| 144 | |
| 145 | export async function checkLicense({email, legacyGsuite}) { |
| 146 | const storedAuthData = await mvelo.storage.get(GOOGLE_OAUTH_STORE); |
| 147 | const storedData = storedAuthData[email]; |
| 148 | if (!storedData.gsuite) { |
| 149 | return; |
| 150 | } |
| 151 | if (legacyGsuite && storedData.legacyGsuite) { |
| 152 | return; |
| 153 | } |
| 154 | if (validateLicense(storedData)) { |
| 155 | return; |
| 156 | } |
| 157 | const {gsuite, gmail_account_id} = storedData; |
| 158 | let valid = false; |
| 159 | try { |
| 160 | await requestLicense(gsuite, gmail_account_id); |
| 161 | valid = true; |
| 162 | } catch (e) { |
| 163 | if (!legacyGsuite) { |
| 164 | throw new MvError(`Mailvelope Business license required to use this feature. ${e.message}`, 'GSUITE_LICENSING_ERROR'); |
| 165 | } |
| 166 | } finally { |
| 167 | await storeAuthData(email, {...buildLicenseData(valid), legacyGsuite}); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | async function requestLicense(domain, gmail_account_id) { |
| 172 | const ab = str2ab(gmail_account_id); |
nothing calls this directly
no test coverage detected