@yourgoods/ui-smart 0.20.0 → 0.21.0

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.
@@ -1,778 +0,0 @@
1
- import { defineComponent as Z, ref as M, reactive as J, watch as j, computed as V, toRefs as se, createElementBlock as k, openBlock as y, createElementVNode as S, createCommentVNode as P, toDisplayString as K, createVNode as b, unref as c, isRef as Q, withCtx as q, createTextVNode as te, Fragment as De, createBlock as R, resolveDynamicComponent as Ce, onMounted as Ue } from "vue";
2
- import { T as de, c as Ve, u as Ae, a as Fe, P as ye, b as Re } from "./useRateLimitToast-B7w14HCE.js";
3
- import { C as D, _ as ze, B as We, p as F, g as He } from "./index-Rt4lWoBK.js";
4
- import { PInput as G, IconMailMd as re, PButton as le, IconEyeMd as ge, IconEyeClosedMd as he, PDialog as qe, PTopBar as je, IconCrossMd as Ge } from "@profeat/ui-kit";
5
- const Ye = { class: "dialogDefaultContainerInsideContent" }, _e = { class: "dialogDefaultContainerTextHint" }, Je = {
6
- key: 0,
7
- class: "input-wrapper"
8
- }, Ke = {
9
- key: 1,
10
- class: "input-wrapper"
11
- }, Qe = {
12
- key: 2,
13
- class: "input-wrapper"
14
- }, Xe = { key: 3 }, Ze = /* @__PURE__ */ Z({
15
- __name: "AddNewEmailContent",
16
- props: {
17
- email: {},
18
- oldEmail: {},
19
- hintText: { default: "" },
20
- emailError: { default: "" },
21
- codeError: { default: "" },
22
- rateLimitText: { default: "" },
23
- showEmail: { type: Boolean, default: !0 },
24
- isFinalLimit: { type: Boolean },
25
- isNotMatchCode: { type: Boolean },
26
- loading: { type: Boolean }
27
- },
28
- emits: ["update:email", "update:code", "edit", "on-match-code", "on-match-code-error", "on-send-code", "on-send-code-again", "on-clear-code-error"],
29
- setup(z, { emit: U }) {
30
- const p = z, r = U, v = M(!1), e = M(""), n = J({
31
- emailModel: p.email || "",
32
- codeModel: "",
33
- touched: { email: !1, code: !1 }
34
- });
35
- j(
36
- () => n.emailModel,
37
- (i) => {
38
- r("update:email", i), e.value = "";
39
- }
40
- ), j(
41
- () => n.codeModel,
42
- (i) => r("update:code", i)
43
- );
44
- const g = (i) => {
45
- n.touched[i] = !0;
46
- }, s = V(() => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(n.emailModel.trim())), u = async () => {
47
- var d;
48
- if (g("email"), !s.value) {
49
- e.value = "Это не похоже на e-mail";
50
- return;
51
- }
52
- const {
53
- data: { data: i }
54
- } = await Ve(n.emailModel);
55
- if (!(((d = i == null ? void 0 : i[0]) == null ? void 0 : d.available) ?? !1)) {
56
- e.value = "Такой email уже используется";
57
- return;
58
- }
59
- e.value = "", r("on-send-code", {
60
- email: n.emailModel,
61
- prevEmail: p.oldEmail,
62
- offLoading: !0
63
- }), v.value = !0;
64
- };
65
- let $ = "";
66
- const N = (i) => {
67
- r("on-clear-code-error");
68
- const l = i.target;
69
- let d = l.value.replace(/\D/g, "");
70
- d.length > 4 && (d = d.slice(0, 4)), l.value = d, n.codeModel = d, d.length === 4 && d !== $ && ($ = d, r("on-match-code", { email: n.emailModel, code: d }));
71
- }, B = () => {
72
- r("on-send-code-again", { email: n.emailModel });
73
- }, O = V(() => {
74
- if (e.value) return e.value;
75
- if (n.touched.email) {
76
- if (!n.emailModel.trim()) return "Введите e-mail";
77
- if (!s.value) return "Это не похоже на e-mail";
78
- }
79
- return p.emailError || "";
80
- }), E = V(() => p.isNotMatchCode ? "Неверный код" : n.touched.code ? h.value.trim() ? p.codeError ?? null : "Введите код" : ""), { emailModel: m, codeModel: h } = se(n);
81
- return (i, l) => {
82
- const d = de;
83
- return y(), k("div", Ye, [
84
- S("div", _e, K(v.value ? "Введите код подтверждения" : i.hintText), 1),
85
- i.showEmail ? (y(), k("div", Je, [
86
- b(c(G), {
87
- modelValue: c(m),
88
- "onUpdate:modelValue": l[0] || (l[0] = (C) => Q(m) ? m.value = C : null),
89
- size: "large",
90
- "text-size": "medium",
91
- label: "Почта",
92
- type: "email",
93
- error: O.value,
94
- onBlur: l[1] || (l[1] = (C) => g("email")),
95
- onInput: l[2] || (l[2] = (C) => g("email"))
96
- }, null, 8, ["modelValue", "error"]),
97
- b(c(re), {
98
- class: "icon-locked",
99
- onClick: l[3] || (l[3] = (C) => i.$emit("edit", "email"))
100
- })
101
- ])) : P("", !0),
102
- v.value ? P("", !0) : (y(), k("div", Ke, [
103
- b(c(le), {
104
- style: { width: "100%" },
105
- disabled: !s.value,
106
- onClick: u
107
- }, {
108
- default: q(() => l[6] || (l[6] = [
109
- te(" Отправить код ")
110
- ])),
111
- _: 1,
112
- __: [6]
113
- }, 8, ["disabled"])
114
- ])),
115
- v.value ? (y(), k("div", Qe, [
116
- b(c(G), {
117
- modelValue: c(h),
118
- "onUpdate:modelValue": l[4] || (l[4] = (C) => Q(h) ? h.value = C : null),
119
- size: "large",
120
- "text-size": "medium",
121
- label: "Код",
122
- type: "text",
123
- error: E.value,
124
- onInput: N,
125
- onBlur: l[5] || (l[5] = (C) => g("code"))
126
- }, null, 8, ["modelValue", "error"])
127
- ])) : P("", !0),
128
- !i.loading && v.value ? (y(), k("div", Xe, [
129
- b(d, {
130
- loading: i.loading,
131
- "rate-limit-text": i.rateLimitText,
132
- "is-final-limit": i.isFinalLimit,
133
- "on-send-again": B
134
- }, null, 8, ["loading", "rate-limit-text", "is-final-limit"])
135
- ])) : P("", !0)
136
- ]);
137
- };
138
- }
139
- }), et = { class: "dialogDefaultContainer" }, tt = { class: "dialogDefaultContainerInsideContent" }, lt = { class: "input-wrapper" }, at = { class: "input-wrapper" }, ot = { style: { width: "100%", display: "flex" } }, it = {
140
- key: 0,
141
- class: "dialogDefaultContainer"
142
- }, nt = { class: "dialogDefaultContainerInsideContent" }, st = { style: { "margin-top": "12px" } }, Te = 8, dt = /* @__PURE__ */ Z({
143
- __name: "AddNewPasswordContent",
144
- props: {
145
- modelValue: { type: Boolean },
146
- title: { default: "Установка пароля" },
147
- hintText: { default: "" },
148
- emailSessionId: {}
149
- },
150
- emits: ["update:modelValue", "submit", "close", "update-user"],
151
- setup(z, { emit: U }) {
152
- const p = U, r = M(!1), v = M(""), e = M(""), n = J({
153
- newPassword: !1,
154
- newPasswordConfirm: !1
155
- }), g = M(D.NEW), s = M(!1), u = M(!1), $ = V(() => s.value ? "text" : "password"), N = V(() => u.value ? "text" : "password"), B = () => {
156
- s.value = !s.value;
157
- }, O = () => {
158
- u.value = !u.value;
159
- }, E = V(() => n.newPassword ? v.value.trim() ? v.value.trim().length < Te ? `Пароль слишком короткий. Введите хотя бы ${Te} символов` : "" : "Введите пароль" : ""), m = V(() => n.newPasswordConfirm ? e.value.trim() ? e.value !== v.value ? "Пароли не совпадают" : "" : "Повторите пароль" : ""), h = V(() => !!(E.value || m.value)), i = V(() => r.value || !v.value.trim() || !e.value.trim() ? !0 : h.value), l = () => {
160
- p("update:modelValue", !1), p("close");
161
- }, d = async () => {
162
- p("update-user", v.value);
163
- };
164
- return (C, f) => (y(), k(De, null, [
165
- S("div", et, [
166
- S("div", tt, [
167
- f[7] || (f[7] = S("div", { class: "dialogDefaultContainerTextHint" }, K("Установите новый пароль для защиты аккаунта. Пароль должен содержать не менее 8 символов."), -1)),
168
- S("div", lt, [
169
- b(c(G), {
170
- modelValue: v.value,
171
- "onUpdate:modelValue": f[0] || (f[0] = (Y) => v.value = Y),
172
- size: "large",
173
- "text-size": "medium",
174
- label: "Новый пароль",
175
- type: $.value,
176
- error: E.value,
177
- onBlur: f[1] || (f[1] = () => n.newPassword = !0),
178
- onInput: f[2] || (f[2] = () => n.newPassword = !0)
179
- }, null, 8, ["modelValue", "type", "error"]),
180
- (y(), R(Ce(s.value ? c(ge) : c(he)), {
181
- class: "icon-locked",
182
- onClick: B
183
- }))
184
- ]),
185
- S("div", at, [
186
- b(c(G), {
187
- modelValue: e.value,
188
- "onUpdate:modelValue": f[3] || (f[3] = (Y) => e.value = Y),
189
- size: "large",
190
- "text-size": "medium",
191
- label: "Повторите новый пароль",
192
- type: N.value,
193
- error: m.value,
194
- onBlur: f[4] || (f[4] = () => n.newPasswordConfirm = !0),
195
- onInput: f[5] || (f[5] = () => n.newPasswordConfirm = !0)
196
- }, null, 8, ["modelValue", "type", "error"]),
197
- (y(), R(Ce(u.value ? c(ge) : c(he)), {
198
- class: "icon-locked",
199
- onClick: O
200
- }))
201
- ]),
202
- S("div", ot, [
203
- b(c(le), {
204
- style: { width: "100%" },
205
- disabled: i.value,
206
- onClick: d
207
- }, {
208
- default: q(() => f[6] || (f[6] = [
209
- te(K("Сохранить"))
210
- ])),
211
- _: 1,
212
- __: [6]
213
- }, 8, ["disabled"])
214
- ])
215
- ])
216
- ]),
217
- g.value === c(D).COMPLETED ? (y(), k("div", it, [
218
- S("div", nt, [
219
- f[9] || (f[9] = S("p", null, "Пароль успешно установлен", -1)),
220
- S("div", st, [
221
- b(c(le), {
222
- style: { width: "100%" },
223
- onClick: l
224
- }, {
225
- default: q(() => f[8] || (f[8] = [
226
- te("Закрыть")
227
- ])),
228
- _: 1,
229
- __: [8]
230
- })
231
- ])
232
- ])
233
- ])) : P("", !0)
234
- ], 64));
235
- }
236
- }), rt = { class: "dialogDefaultContainerInsideContent" }, ut = { class: "dialogDefaultContainerTextHint" }, mt = {
237
- key: 0,
238
- class: "input-wrapper"
239
- }, ct = {
240
- key: 1,
241
- class: "input-wrapper"
242
- }, vt = /* @__PURE__ */ Z({
243
- __name: "OldEmailContent",
244
- props: {
245
- email: {},
246
- code: {},
247
- hintText: { default: "" },
248
- emailError: { default: "" },
249
- codeError: { default: "" },
250
- rateLimitText: { default: "" },
251
- showEmail: { type: Boolean, default: !0 },
252
- showCode: { type: Boolean, default: !0 },
253
- isFinalLimit: { type: Boolean },
254
- isNotMatchCode: { type: Boolean, default: !1 },
255
- loading: { type: Boolean }
256
- },
257
- emits: ["update:email", "update:code", "edit", "on-match-code", "on-match-code-error", "on-send-code-again", "on-clear-code-error"],
258
- setup(z, { emit: U }) {
259
- const p = z, r = U, v = J({
260
- touched: {
261
- email: !1,
262
- code: !1
263
- },
264
- emailModel: p.email,
265
- codeModel: p.code
266
- });
267
- j(
268
- () => v.emailModel,
269
- (E) => r("update:email", E)
270
- ), j(
271
- () => v.codeModel,
272
- (E) => r("update:code", E)
273
- );
274
- const e = (E) => {
275
- v.touched[E] = !0;
276
- }, n = M(""), g = (E) => {
277
- r("on-clear-code-error");
278
- const m = E.target;
279
- let h = ((m == null ? void 0 : m.value) ?? "").replace(/\D/g, "");
280
- h.length > 4 && (h = h.slice(0, 4)), $.value = h, m && m.value !== h && (m.value = h), h.length === 4 && h !== n.value && (n.value = h, r("on-match-code", { email: u.value, code: h }));
281
- }, s = () => {
282
- r("on-send-code-again", { email: u.value });
283
- }, { emailModel: u, codeModel: $, touched: N } = se(v), B = V(() => N.value.email && !u.value.trim() ? "Введите e-mail" : p.emailError), O = V(() => p.isNotMatchCode ? "Неверный код" : N.value.code ? $.value.trim() ? p.codeError ?? null : "Введите код" : "");
284
- return (E, m) => {
285
- const h = de;
286
- return y(), k("div", rt, [
287
- S("div", ut, K(E.hintText), 1),
288
- E.showEmail ? (y(), k("div", mt, [
289
- b(c(G), {
290
- modelValue: c(u),
291
- "onUpdate:modelValue": m[0] || (m[0] = (i) => Q(u) ? u.value = i : null),
292
- size: "large",
293
- "text-size": "medium",
294
- label: "Почта",
295
- type: "email",
296
- error: B.value,
297
- disabled: !0,
298
- onBlur: m[1] || (m[1] = (i) => e("email")),
299
- onInput: m[2] || (m[2] = (i) => e("email"))
300
- }, null, 8, ["modelValue", "error"]),
301
- b(c(re), {
302
- class: "icon-locked",
303
- onClick: m[3] || (m[3] = (i) => E.$emit("edit", "email"))
304
- })
305
- ])) : P("", !0),
306
- E.showCode ? (y(), k("div", ct, [
307
- b(c(G), {
308
- modelValue: c($),
309
- "onUpdate:modelValue": m[4] || (m[4] = (i) => Q($) ? $.value = i : null),
310
- size: "large",
311
- "text-size": "medium",
312
- label: "Код",
313
- type: "text",
314
- error: O.value,
315
- onInput: g,
316
- onBlur: m[5] || (m[5] = (i) => e("code"))
317
- }, null, 8, ["modelValue", "error"])
318
- ])) : P("", !0),
319
- b(h, {
320
- loading: E.loading,
321
- "rate-limit-text": E.rateLimitText,
322
- "is-final-limit": E.isFinalLimit,
323
- "on-send-again": s
324
- }, null, 8, ["loading", "rate-limit-text", "is-final-limit"])
325
- ]);
326
- };
327
- }
328
- }), pt = /* @__PURE__ */ ze(vt, [["__scopeId", "data-v-5e561fbe"]]), ft = { class: "dialogDefaultContainerInsideContent" }, Et = { class: "dialogDefaultContainerTextHint" }, wt = {
329
- key: 0,
330
- class: "input-wrapper"
331
- }, Ct = {
332
- key: 1,
333
- class: "input-wrapper"
334
- }, yt = {
335
- key: 2,
336
- class: "input-wrapper"
337
- }, gt = { key: 3 }, ht = /* @__PURE__ */ Z({
338
- __name: "NewEmailContent",
339
- props: {
340
- email: {},
341
- oldEmail: {},
342
- hintText: { default: "" },
343
- emailError: { default: "" },
344
- codeError: { default: "" },
345
- rateLimitText: { default: "" },
346
- showEmail: { type: Boolean, default: !0 },
347
- isFinalLimit: { type: Boolean, default: !1 },
348
- isNotMatchCode: { type: Boolean, default: !1 },
349
- loading: { type: Boolean }
350
- },
351
- emits: ["update:email", "update:code", "edit", "on-match-code", "on-match-code-error", "on-send-code", "on-send-code-again", "on-clear-code-error"],
352
- setup(z, { emit: U }) {
353
- const p = z, r = U, v = M(!1), e = M(""), n = J({
354
- touched: { email: !1, code: !1 },
355
- emailModel: "",
356
- codeModel: ""
357
- });
358
- j(
359
- () => n.emailModel,
360
- (l) => {
361
- r("update:email", l), e.value = "";
362
- }
363
- ), j(
364
- () => n.codeModel,
365
- (l) => r("update:code", l)
366
- );
367
- const g = (l) => n.touched[l] = !0, s = V(() => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(n.emailModel.trim())), u = async () => {
368
- var C;
369
- if (g("email"), !s.value) {
370
- e.value = "Это не похоже на e-mail";
371
- return;
372
- }
373
- const {
374
- data: { data: l }
375
- } = await Ve(n.emailModel);
376
- if (!(((C = l == null ? void 0 : l[0]) == null ? void 0 : C.available) ?? !1)) {
377
- e.value = "Такой email уже используется";
378
- return;
379
- }
380
- e.value = "", r("on-send-code", { email: n.emailModel, prevEmail: p.oldEmail, offLoading: !0 }), v.value = !0;
381
- };
382
- let $ = "";
383
- const N = (l) => {
384
- r("on-clear-code-error");
385
- const d = l.target;
386
- let C = d.value.replace(/\D/g, "");
387
- C.length > 4 && (C = C.slice(0, 4), d.value = C), n.codeModel = C, C.length === 4 && C !== $ && ($ = C, r("on-match-code", { email: n.emailModel, code: C }));
388
- }, B = () => {
389
- r("on-send-code-again", { email: n.emailModel });
390
- }, { emailModel: O, codeModel: E, touched: m } = se(n), h = V(() => {
391
- if (e.value) return e.value;
392
- if (n.touched.email) {
393
- if (!n.emailModel.trim()) return "Введите e-mail";
394
- if (!s.value) return "Это не похоже на e-mail";
395
- }
396
- return p.emailError || "";
397
- }), i = V(() => p.isNotMatchCode ? "Неверный код" : m.value.code ? E.value.trim() ? p.codeError ?? null : "Введите код" : "");
398
- return (l, d) => {
399
- const C = de;
400
- return y(), k("div", ft, [
401
- S("div", Et, K(v.value ? "Введите код подтверждения" : l.hintText), 1),
402
- l.showEmail ? (y(), k("div", wt, [
403
- b(c(G), {
404
- modelValue: c(O),
405
- "onUpdate:modelValue": d[0] || (d[0] = (f) => Q(O) ? O.value = f : null),
406
- size: "large",
407
- "text-size": "medium",
408
- label: "Почта",
409
- type: "email",
410
- error: h.value,
411
- onBlur: d[1] || (d[1] = (f) => g("email")),
412
- onInput: d[2] || (d[2] = (f) => g("email"))
413
- }, null, 8, ["modelValue", "error"]),
414
- b(c(re), {
415
- class: "icon-locked",
416
- onClick: d[3] || (d[3] = (f) => l.$emit("edit", "email"))
417
- })
418
- ])) : P("", !0),
419
- v.value ? P("", !0) : (y(), k("div", Ct, [
420
- b(c(le), {
421
- style: { width: "100%" },
422
- disabled: !s.value,
423
- onClick: u
424
- }, {
425
- default: q(() => d[6] || (d[6] = [
426
- te(" Отправить код ")
427
- ])),
428
- _: 1,
429
- __: [6]
430
- }, 8, ["disabled"])
431
- ])),
432
- v.value ? (y(), k("div", yt, [
433
- b(c(G), {
434
- modelValue: c(E),
435
- "onUpdate:modelValue": d[4] || (d[4] = (f) => Q(E) ? E.value = f : null),
436
- size: "large",
437
- "text-size": "medium",
438
- label: "Код",
439
- type: "text",
440
- error: i.value,
441
- onInput: N,
442
- onBlur: d[5] || (d[5] = (f) => g("code"))
443
- }, null, 8, ["modelValue", "error"])
444
- ])) : P("", !0),
445
- v.value ? (y(), k("div", gt, [
446
- b(C, {
447
- loading: l.loading,
448
- "rate-limit-text": l.rateLimitText,
449
- "is-final-limit": l.isFinalLimit,
450
- "on-send-again": B
451
- }, null, 8, ["loading", "rate-limit-text", "is-final-limit"])
452
- ])) : P("", !0)
453
- ]);
454
- };
455
- }
456
- }), Tt = { class: "text-center w-full" }, Mt = { class: "dialogTitle" }, Vt = {
457
- key: 0,
458
- class: "dialogDefaultContainer"
459
- }, bt = {
460
- key: 1,
461
- class: "dialogDefaultContainer"
462
- }, Me = 3, St = /* @__PURE__ */ Z({
463
- __name: "ProfileEmailDialog",
464
- props: {
465
- modelValue: { type: Boolean },
466
- title: { default: "Смена почты" },
467
- hintText: { default: "Чтобы продолжить, введите код подтверждения" },
468
- initialEmail: { default: "" },
469
- throttler: {},
470
- provider: {},
471
- mode: {}
472
- },
473
- emits: ["update:modelValue", "submit-email", "edit", "close", "notify", "clean-input-errors", "on-update-jwt", "update-email-field", "on-password-error", "on-toast"],
474
- setup(z, { emit: U }) {
475
- const p = z, r = U, v = M(p.modelValue), e = J({
476
- oldEmail: p.initialEmail,
477
- newEmail: "",
478
- code: "",
479
- addEmail: "",
480
- addCode: ""
481
- }), n = J({ email: !1, code: !1 }), g = M(D.OLD), s = M(null), u = M(!1), $ = M(!1), N = M(!1), B = M(We.VERIFY_EMAIL), O = V(() => B.value === "password-flow"), E = V(() => C.value ? p.title : O.value ? "Добавление пароля" : "Добавление почты"), { startTimer: m, remainingSeconds: h, isAvailableForSendAgain: i, totalRateAttempts: l, currentRateAttempt: d } = Fe(), { isEditFlow: C, getFlow: f } = Ae(M(p.mode ?? "edit")), { showRateLimitToast: Y } = Re(r), ue = V(() => n.email && !e.oldEmail.trim() ? "Введите e-mail" : ""), me = V(() => n.code && !e.code.trim() ? "Введите код" : ""), ae = V(() => i.value ? "Повторить" : `${h.value}`), W = M(Me), be = V(() => W.value === 0), $e = (a) => new Promise((t) => setTimeout(t, a));
482
- j(
483
- () => p.modelValue,
484
- (a) => v.value = a
485
- ), j(v, (a) => r("update:modelValue", a));
486
- const oe = () => {
487
- r("close"), v.value = !1;
488
- }, ce = (a) => r("edit", a);
489
- async function ve(a, t = !1) {
490
- var o;
491
- try {
492
- const T = (o = (await F("/users/profile/check-throttler", { method: "email", email: a, isInvite: t })).data) == null ? void 0 : o.data;
493
- return T ? (await $e(1e3), T.restTimeSec > 0 ? (m(T.restTimeSec), i.value = !1, l.value = T.attempts.total ?? l.value, d.value = (T.attempts.total ?? 0) - (T.attempts.available ?? 0), W.value = T.attempts.available ?? W.value) : i.value = !0, T) : null;
494
- } catch {
495
- return null;
496
- }
497
- }
498
- async function ie(a = "email") {
499
- var o;
500
- return ((o = (await He("/users/profile/session/get-edit-session", { params: { field: a } })).data) == null ? void 0 : o.data) ?? null;
501
- }
502
- async function xe(a = "email") {
503
- try {
504
- const t = await ie(a);
505
- s.value = (t == null ? void 0 : t.sessionId) ?? s.value, g.value = (t == null ? void 0 : t.step) ?? g.value, e.oldEmail = (t == null ? void 0 : t.oldValue) ?? e.oldEmail, t != null && t.sessionId || await pe(a);
506
- } catch {
507
- await pe(a);
508
- }
509
- }
510
- async function pe(a = "email") {
511
- var t;
512
- try {
513
- const o = await F("/users/profile/session/create-if-not-exists", { field: a, oldValue: p.initialEmail }), w = ((t = o.data) == null ? void 0 : t.data) ?? o.data;
514
- s.value = (w == null ? void 0 : w.sessionId) ?? s.value, g.value = (w == null ? void 0 : w.step) ?? g.value, e.oldEmail = (w == null ? void 0 : w.oldValue) ?? e.oldEmail, e.newEmail = (w == null ? void 0 : w.newValue) ?? e.newEmail;
515
- } catch {
516
- }
517
- }
518
- async function X({ value: a, offLoading: t = !0 }) {
519
- var o;
520
- try {
521
- u.value = !0;
522
- const w = a ?? e.addEmail, T = await F(
523
- "/users/profile/email/contact/send-code",
524
- {
525
- sessionId: s.value,
526
- email: w,
527
- value: w,
528
- oldValue: e.oldEmail,
529
- provider: p.provider
530
- }
531
- // { headers: { 'x-only-sms': 'true' } }
532
- );
533
- if (T.status === 403 && ((o = T.data) != null && o.tooManyRequests)) {
534
- const I = T.data.tooManyRequests;
535
- return I.restTimeSec > 0 ? (m(I.restTimeSec), l.value = I.attempts.total ?? l.value, d.value = (I.attempts.total ?? 0) - (I.attempts.available ?? 0), W.value = I.attempts.available ?? W.value) : i.value = !0, T;
536
- }
537
- return await ve(a ?? e.oldEmail), T;
538
- } catch (w) {
539
- throw console.error(w), w;
540
- } finally {
541
- t && (u.value = !1);
542
- }
543
- }
544
- const fe = async (a, t) => {
545
- var o, w, T, I, x, H;
546
- if (!e.oldEmail && t === D.OLD) throw new Error("oldEmail пустой — модель потерялась");
547
- try {
548
- u.value = !0;
549
- const L = await ie();
550
- if (s.value = (L == null ? void 0 : L.sessionId) ?? s.value, g.value = (L == null ? void 0 : L.step) ?? g.value, e.oldEmail = (L == null ? void 0 : L.oldValue) ?? e.oldEmail, e.newEmail = (L == null ? void 0 : L.newValue) ?? e.newEmail, !s.value) throw new Error("Нет sessionId для match");
551
- const A = await F("/users/profile/change/email/match-code", {
552
- email: t === D.NEW ? e.newEmail : e.oldEmail,
553
- sessionId: s.value,
554
- code: a,
555
- step: t
556
- }), ee = ((o = A.data) == null ? void 0 : o.nextStep) ?? ((T = (w = A.data) == null ? void 0 : w.data) == null ? void 0 : T.nextStep) ?? null, Ne = ((x = (I = A.data) == null ? void 0 : I.data) == null ? void 0 : x.rateLimit) ?? ((H = A.data) == null ? void 0 : H.rateLimit) ?? null, Oe = A.data.data.success ?? A.data.success;
557
- if (Y(Ne), !Oe) {
558
- $.value = !0;
559
- return;
560
- }
561
- if (ee) {
562
- if (g.value = ee, g.value === D.NEW) {
563
- const _ = await ie();
564
- e.oldEmail = (_ == null ? void 0 : _.oldValue) ?? e.oldEmail, e.newEmail = (_ == null ? void 0 : _.newValue) ?? e.newEmail, e.code = "";
565
- }
566
- g.value === D.COMPLETED && (e.code = "", r("submit-email", { email: e.addEmail, code: a }), r("on-toast", { color: "success", text: "E-mail изменён" }), r("on-update-jwt", "email", "edit", e.newEmail), s.value = null, r("close"));
567
- }
568
- return A;
569
- } finally {
570
- u.value = !1;
571
- }
572
- }, ke = async () => {
573
- try {
574
- const a = await F("/users/profile/bind/email/cancel", {
575
- sessionId: s.value
576
- });
577
- if ((a.data.data ?? a.data).success) {
578
- r("close");
579
- return;
580
- }
581
- } catch (a) {
582
- console.error(a);
583
- }
584
- };
585
- async function Ie({ code: a }) {
586
- await fe(a, D.OLD);
587
- }
588
- function Ee(a) {
589
- }
590
- async function Se({ code: a }) {
591
- await fe(a, D.NEW);
592
- }
593
- const we = async ({
594
- value: a,
595
- field: t = "email",
596
- offLoading: o = !0
597
- }) => {
598
- var w;
599
- try {
600
- if (u.value = !0, !s.value) throw new Error("Bind-сессия не найдена. Создайте её через createBindSession.");
601
- const T = a ?? e.addEmail, I = await F(`/users/profile/bind/contact/send-code/${t}`, {
602
- sessionId: s.value,
603
- email: T,
604
- provider: p.provider
605
- }), x = (w = I.data) == null ? void 0 : w.tooManyRequests;
606
- if (I.status === 403 && x) {
607
- x.restTimeSec > 0 ? (m(x.restTimeSec), l.value = x.attempts.total ?? l.value, d.value = (x.attempts.total ?? 0) - (x.attempts.available ?? 0), W.value = x.attempts.available ?? Me) : i.value = !0;
608
- return;
609
- }
610
- const H = await ve(T);
611
- return H && H.restTimeSec > 0 ? m(H.restTimeSec) : i.value = !0, I;
612
- } finally {
613
- o && (u.value = !1);
614
- }
615
- }, Be = async () => {
616
- var a, t, o, w, T, I;
617
- try {
618
- if (!s.value) {
619
- const ee = await ne();
620
- s.value = ee.sessionId ?? s.value;
621
- }
622
- const x = await F("/users/profile/bind/email/match-code", {
623
- email: e.addEmail,
624
- sessionId: s.value,
625
- code: e.addCode
626
- }), H = ((a = x.data) == null ? void 0 : a.nextStep) ?? ((o = (t = x.data) == null ? void 0 : t.data) == null ? void 0 : o.nextStep);
627
- B.value = H ?? B.value;
628
- const L = ((T = (w = x.data) == null ? void 0 : w.data) == null ? void 0 : T.rateLimit) ?? ((I = x.data) == null ? void 0 : I.rateLimit) ?? null, A = x.data.data.success ?? x.data.success;
629
- if (Y(L), !A) {
630
- N.value = !0;
631
- return;
632
- }
633
- } catch {
634
- }
635
- }, Le = async () => {
636
- }, Pe = async (a) => {
637
- if (!s.value) {
638
- const t = await ne();
639
- s.value = t.sessionId ?? s.value;
640
- }
641
- u.value = !0;
642
- try {
643
- await F("/users/profile/bind/email/password/set", { sessionId: s.value, newPassword: a }), B.value = D.COMPLETED, r("on-toast", { color: "success", text: "E-mail успешно привязан к аккаунту" }), r("update-email-field", e.addEmail), r("submit-email", { email: e.addEmail, code: e.addCode }), r("on-update-jwt", "email", "bind", e.addEmail), r("close");
644
- } finally {
645
- u.value = !1;
646
- }
647
- }, ne = async () => {
648
- u.value = !0;
649
- try {
650
- const a = await F("/users/profile/bind/email/init", { email: "" }), t = a.data.data ?? a.data;
651
- return B.value = t.step ?? B.value, s.value = t.sessionId ?? s.value, t;
652
- } finally {
653
- u.value = !1;
654
- }
655
- };
656
- return Ue(async () => {
657
- u.value = !0;
658
- const a = await f("email");
659
- if (p.mode === "bind" && a === "bind") {
660
- await ne(), u.value = !1;
661
- return;
662
- }
663
- await xe(), e.oldEmail && await X({ value: e.oldEmail }), u.value = !1;
664
- }), (a, t) => (y(), R(c(qe), {
665
- modelValue: v.value,
666
- "onUpdate:modelValue": [
667
- t[18] || (t[18] = (o) => v.value = o),
668
- oe
669
- ],
670
- width: "small",
671
- "auto-height": !0,
672
- "close-on-click-outside": !0,
673
- "onClick:outside": oe
674
- }, {
675
- header: q(() => [
676
- S("div", Tt, [
677
- b(c(je), {
678
- "slot-left": !1,
679
- size: "small",
680
- borded: !0,
681
- "no-padding": !1
682
- }, {
683
- title: q(() => [
684
- S("span", Mt, K(E.value), 1)
685
- ]),
686
- "right-button": q(() => [
687
- b(c(Ge), {
688
- class: "cross",
689
- onClick: oe
690
- })
691
- ]),
692
- _: 1
693
- })
694
- ])
695
- ]),
696
- default: q(() => [
697
- S("div", null, [
698
- c(C) ? (y(), k("div", Vt, [
699
- u.value ? (y(), R(ye, { key: 0 })) : P("", !0),
700
- g.value === c(D).OLD ? (y(), R(pt, {
701
- key: 1,
702
- email: e.oldEmail,
703
- "onUpdate:email": t[0] || (t[0] = (o) => e.oldEmail = o),
704
- code: e.code,
705
- "onUpdate:code": t[1] || (t[1] = (o) => e.code = o),
706
- "hint-text": a.hintText,
707
- "email-error": ue.value,
708
- "code-error": me.value,
709
- "rate-limit-text": ae.value,
710
- "is-final-limit": W.value === 0,
711
- "is-not-match-code": $.value,
712
- loading: u.value,
713
- onEdit: ce,
714
- onOnMatchCode: Ie,
715
- onOnMatchCodeError: Ee,
716
- onSendCode: t[2] || (t[2] = (o) => X({ value: e.oldEmail })),
717
- onOnSendCodeAgain: t[3] || (t[3] = (o) => X({ value: e.oldEmail })),
718
- onOnClearCodeError: t[4] || (t[4] = (o) => $.value = !1)
719
- }, null, 8, ["email", "code", "hint-text", "email-error", "code-error", "rate-limit-text", "is-final-limit", "is-not-match-code", "loading"])) : g.value === c(D).NEW ? (y(), R(ht, {
720
- key: 2,
721
- email: e.newEmail,
722
- "onUpdate:email": t[5] || (t[5] = (o) => e.newEmail = o),
723
- oldEmail: e.oldEmail,
724
- "onUpdate:oldEmail": t[6] || (t[6] = (o) => e.oldEmail = o),
725
- code: e.code,
726
- "onUpdate:code": t[7] || (t[7] = (o) => e.code = o),
727
- "hint-text": "Введите новый адрес вашей почты",
728
- "email-error": ue.value,
729
- "code-error": me.value,
730
- "rate-limit-text": ae.value,
731
- "is-final-limit": W.value === 0,
732
- "is-not-match-code": $.value,
733
- loading: u.value,
734
- onEdit: ce,
735
- onOnMatchCode: Se,
736
- onOnMatchCodeError: Ee,
737
- onOnSendCode: t[8] || (t[8] = (o) => X({ value: e.newEmail })),
738
- onOnSendCodeAgain: t[9] || (t[9] = (o) => X({ value: e.newEmail })),
739
- onOnClearCodeError: t[10] || (t[10] = (o) => $.value = !1)
740
- }, null, 8, ["email", "oldEmail", "code", "email-error", "code-error", "rate-limit-text", "is-final-limit", "is-not-match-code", "loading"])) : P("", !0)
741
- ])) : (y(), k("div", bt, [
742
- u.value ? (y(), R(ye, { key: 0 })) : P("", !0),
743
- O.value ? (y(), R(dt, {
744
- key: 2,
745
- "model-value": v.value,
746
- "email-session-id": s.value,
747
- "onUpdate:modelValue": t[17] || (t[17] = (o) => r("update:modelValue", o)),
748
- onUpdateUser: Pe,
749
- onClose: ke
750
- }, null, 8, ["model-value", "email-session-id"])) : (y(), R(Ze, {
751
- key: 1,
752
- email: e.addEmail,
753
- "onUpdate:email": t[11] || (t[11] = (o) => e.addEmail = o),
754
- oldEmail: e.addEmail,
755
- "onUpdate:oldEmail": t[12] || (t[12] = (o) => e.addEmail = o),
756
- code: e.addCode,
757
- "onUpdate:code": t[13] || (t[13] = (o) => e.addCode = o),
758
- "hint-text": c(C) ? a.hintText : "Чтобы продолжить, введите новый адрес вашей почты",
759
- "rate-limit-text": ae.value,
760
- "is-final-limit": be.value,
761
- "is-not-match-code": N.value,
762
- loading: u.value,
763
- onOnSendCode: t[14] || (t[14] = (o) => we({ value: e.addEmail, field: "email" })),
764
- onOnSendCodeAgain: t[15] || (t[15] = (o) => we({ value: e.addEmail, field: "email" })),
765
- onOnMatchCode: Be,
766
- onOnMatchCodeError: Le,
767
- onOnClearCodeError: t[16] || (t[16] = (o) => N.value = !1)
768
- }, null, 8, ["email", "oldEmail", "code", "hint-text", "rate-limit-text", "is-final-limit", "is-not-match-code", "loading"]))
769
- ]))
770
- ])
771
- ]),
772
- _: 1
773
- }, 8, ["modelValue"]));
774
- }
775
- });
776
- export {
777
- St as default
778
- };