| 1 |
import { reqDataBasics } from '@shared/lib/data'; |
| 2 |
import { ACCOUNT_STATUS } from './usePluginsActivation'; |
| 3 |
|
| 4 |
// PHP finishes the account after the browser stops waiting, so unanswered is not failed. |
| 5 |
const rejectionStatus = ([error]) => |
| 6 |
error?.code === 'fetch_error' && !error.httpStatus && !error.timedOut |
| 7 |
? ACCOUNT_STATUS.pending |
| 8 |
: ACCOUNT_STATUS.error; |
| 9 |
|
| 10 |
const outcome = (result) => { |
| 11 |
if (!result) { |
| 12 |
return { status: ACCOUNT_STATUS.pending }; |
| 13 |
} |
| 14 |
|
| 15 |
const { |
| 16 |
requestTimeInMs, |
| 17 |
captchaTimeInMs, |
| 18 |
captchaWasWarm, |
| 19 |
stepTimeInMs, |
| 20 |
retries, |
| 21 |
errors, |
| 22 |
} = result.status === 'fulfilled' ? result.value : result.reason; |
| 23 |
|
| 24 |
return { |
| 25 |
status: |
| 26 |
result.status === 'fulfilled' |
| 27 |
? ACCOUNT_STATUS.success |
| 28 |
: rejectionStatus(errors), |
| 29 |
requestTimeInMs, |
| 30 |
captchaTimeInMs, |
| 31 |
captchaWasWarm, |
| 32 |
stepTimeInMs, |
| 33 |
retries, |
| 34 |
...(errors.length > 0 && { errors }), |
| 35 |
}; |
| 36 |
}; |
| 37 |
|
| 38 |
export const accountContext = (selectedPlugins, results) => |
| 39 |
Object.fromEntries( |
| 40 |
selectedPlugins.map((plugin, index) => [ |
| 41 |
plugin.slug, |
| 42 |
{ |
| 43 |
endpoint: plugin.endpoint, |
| 44 |
// Reporting slices per entry, so the body's top-level version won't do. |
| 45 |
extendifyVersion: reqDataBasics.version, |
| 46 |
...outcome(results?.[index]), |
| 47 |
}, |
| 48 |
]), |
| 49 |
); |
| 50 |
|