PluginProbe
Extendify / trunk
Extendify vtrunk
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
← All changes | src/Shared/components/ProductAccountActivation/createAccount.js +29 -76 3.1.6 → trunk View file →
@@ -6,85 +6,38 @@
6 6 // api-fetch collapses our AbortSignal.timeout into a generic fetch_error.
7 7 timedOut: signal.aborted,
8 8 });
9 9
10 -export async function createAccount(plugin, data) {
11 - if (!plugin?.idempotent) {
12 - const signal = AbortSignal.timeout(15000);
13 - const timings = {};
14 - const attemptStart = Date.now();
10 +export const createAccount = async (plugin, data) => {
11 + const signal = AbortSignal.timeout(55000);
12 + const timings = {};
13 + const attemptStart = Date.now();
15 14
16 - try {
17 - await plugin.createAccountCallback({ ...data, signal, timings });
15 + try {
16 + const body = await plugin.createAccountCallback({
17 + ...data,
18 + endpoint: plugin.endpoint,
19 + signal,
20 + timings,
21 + });
18 22
19 - return {
20 - requestTimeInMs: [Date.now() - attemptStart],
21 - captchaTimeInMs: timings.captchaTimeInMs,
22 - retries: 0,
23 - errors: [],
24 - };
25 - } catch (error) {
26 - const err = new Error('Single attempt failed');
23 + return {
24 + requestTimeInMs: [Date.now() - attemptStart],
25 + captchaTimeInMs: timings.captchaTimeInMs,
26 + captchaWasWarm: timings.captchaWasWarm,
27 + stepTimeInMs: body?.stepTimeInMs,
28 + retries: 0,
29 + errors: [],
30 + };
31 + } catch (error) {
32 + const err = new Error('Account creation failed');
27 33
28 - err.requestTimeInMs = [Date.now() - attemptStart];
29 - err.captchaTimeInMs = timings.captchaTimeInMs;
30 - err.retries = 0;
31 - err.errors = [describeError(error, signal)];
34 + err.requestTimeInMs = [Date.now() - attemptStart];
35 + err.captchaTimeInMs = timings.captchaTimeInMs;
36 + err.captchaWasWarm = timings.captchaWasWarm;
37 + err.stepTimeInMs = error?.stepTimeInMs;
38 + err.retries = 0;
39 + err.errors = [describeError(error, signal)];
32 40
33 - throw err;
34 - }
41 + throw err;
35 42 }
36 -
37 - return createAccountWithRetry(plugin, data);
38 -}
39 -
40 -async function createAccountWithRetry(
41 - plugin,
42 - { email, marketingConsent, termsAgreed, scriptData },
43 -) {
44 - const windowMs = 10000;
45 - const perAttemptMs = 5000;
46 - const backoffMs = 2500;
47 - const maxRetries = 5;
48 -
49 - const windowStart = Date.now();
50 - const requestTimeInMs = [];
51 - const errors = [];
52 - let retries = 0;
53 -
54 - while (Date.now() - windowStart < windowMs && retries < maxRetries) {
55 - const attemptStart = Date.now();
56 - const signal = AbortSignal.timeout(perAttemptMs);
57 -
58 - try {
59 - await plugin.createAccountCallback({
60 - email,
61 - marketingConsent,
62 - termsAgreed,
63 - scriptData,
64 - signal,
65 - });
66 - requestTimeInMs.push(Date.now() - attemptStart);
67 - return { requestTimeInMs, retries, errors };
68 - } catch (error) {
69 - requestTimeInMs.push(Date.now() - attemptStart);
70 -
71 - errors.push(describeError(error, signal));
72 -
73 - const remainingMs = windowMs - (Date.now() - windowStart);
74 -
75 - if (remainingMs <= 0) break;
76 -
77 - retries++;
78 -
79 - if (!signal.aborted && remainingMs >= backoffMs) {
80 - await new Promise((resolve) => setTimeout(resolve, backoffMs));
81 - }
82 - }
83 - }
84 -
85 - const err = new Error(`Retry window of ${windowMs}ms exceeded`);
86 - err.requestTimeInMs = requestTimeInMs;
87 - err.retries = retries;
88 - err.errors = errors;
89 - throw err;
90 -}
43 +};