@foxford/sdk 5.0.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.
@@ -0,0 +1,469 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+
22
+ // src/plugins/confirm-phone/index.ts
23
+ import merge from "lodash/merge";
24
+ var DEFAULT_OPTIONS = {
25
+ className: "foxford-phone-confirm",
26
+ confirmCodeInvalidText: "\u0414\u043E\u043B\u0436\u0435\u043D \u0441\u043E\u0441\u0442\u043E\u044F\u0442\u044C \u0438\u0437 4 \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432",
27
+ confirmCodePlaceholderText: "\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u043A\u043E\u0434",
28
+ confirmedInputClassName: "is-confirmed",
29
+ disabledClassName: "is-disabled",
30
+ errorClassName: "is-error",
31
+ hiddenClassName: "is-hidden",
32
+ inputParentsToHide: [],
33
+ requestButtonText: "\u041F\u043E\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u0442\u044C",
34
+ retryButtonText: "\u0412\u044B\u0441\u043B\u0430\u0442\u044C \u043A\u043E\u0434 \u043F\u043E\u0432\u0442\u043E\u0440\u043D\u043E",
35
+ sendCodeButtonText: "\u041E\u0442\u043F\u0440\u0430\u0432\u0438\u0442\u044C \u043A\u043E\u0434",
36
+ unconfirmedHintText: "\u041D\u0435 \u043F\u043E\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043D",
37
+ untilRetryText: "\u0412\u044B\u0441\u043B\u0430\u0442\u044C \u043A\u043E\u0434 \u043F\u043E\u0432\u0442\u043E\u0440\u043D\u043E \u0447\u0435\u0440\u0435\u0437",
38
+ userData: {
39
+ phone: "",
40
+ phoneConfirmed: false
41
+ }
42
+ };
43
+ var INITIAL_STATE = {
44
+ confirmedData: "",
45
+ dataToConfirm: "",
46
+ isConfirmRequested: false,
47
+ isConfirmed: false
48
+ };
49
+ var INITIALIZATION_FAILED_ERROR = "Initialization failed";
50
+ var FORM_NOT_FOUND_ERROR = "Form not found";
51
+ var FIELD_WITHOUT_PARENT_ERROR = "Input without parent";
52
+ var API_NOT_SPECIFIED_ERROR = "Api not specified";
53
+ var _ConfirmPhone = class _ConfirmPhone {
54
+ constructor(node, options) {
55
+ this.fieldType = "phone";
56
+ this.formCheckAttrName = "data-fields-to-confirm";
57
+ this.formPreventSubmitAttr = "data-prevent-submit";
58
+ this.state = INITIAL_STATE;
59
+ this.bindListeners = () => {
60
+ this.formControls.input.addEventListener("keyup", this.inputListener);
61
+ if (this.confirmControls.input) this.confirmControls.input.addEventListener("input", this.confirmInputListener);
62
+ if (this.confirmControls.sendCodeButton) {
63
+ this.confirmControls.sendCodeButton.addEventListener("click", this.sendCodeListener);
64
+ }
65
+ if (this.confirmControls.retryButton) this.confirmControls.retryButton.addEventListener("click", this.retryListener);
66
+ if (this.confirmControls.requestConfirmButton) {
67
+ this.confirmControls.requestConfirmButton.addEventListener("click", this.requestConfirmListener);
68
+ }
69
+ };
70
+ this.inputListener = () => {
71
+ this.state.dataToConfirm = _ConfirmPhone.cleanPhoneFormatting(this.formControls.input.value);
72
+ this.state.isConfirmed = this.state.dataToConfirm === this.state.confirmedData;
73
+ if (!this.options.confirmedInputClassName) return;
74
+ _ConfirmPhone.hideElement(this.confirmControls.requestConfirmError);
75
+ if (this.state.dataToConfirm && !this.state.isConfirmed) {
76
+ this.formControls.input.classList.remove(this.options.confirmedInputClassName);
77
+ this.showConfirmButtonAndHint();
78
+ this.addFieldForCheck();
79
+ this.disableSubmit();
80
+ } else {
81
+ this.formControls.input.classList.add(this.options.confirmedInputClassName);
82
+ this.removeFieldFromCheck();
83
+ this.attemptToEnableSubmit();
84
+ if (this.confirmControls.input) _ConfirmPhone.hideElement(this.confirmControls.input);
85
+ this.hideConfirmButtonAndHint();
86
+ }
87
+ };
88
+ this.updateRetryHintText = (diff) => {
89
+ if (this.confirmControls.countDown) {
90
+ this.confirmControls.countDown.innerText = `${this.options.untilRetryText} ${diff}`;
91
+ }
92
+ };
93
+ this.requestConfirmListener = () => {
94
+ if (this.state.dataToConfirm && !this.state.isConfirmed && !this.state.isConfirmRequested) {
95
+ const requestData = this.requestData;
96
+ if (!requestData) return;
97
+ this.state.isConfirmRequested = true;
98
+ if (this.options.disabledClassName && this.confirmControls.requestConfirmButton) {
99
+ this.confirmControls.requestConfirmButton.classList.add(this.options.disabledClassName);
100
+ }
101
+ this.requestCode(requestData).then(({ nextDeliveryAt }) => {
102
+ if (nextDeliveryAt && typeof nextDeliveryAt !== "function") {
103
+ const diff = _ConfirmPhone.getDiffSeconds(nextDeliveryAt);
104
+ if (diff > 0 && !this.state.isConfirmed) {
105
+ this.toggleInputParents(false);
106
+ _ConfirmPhone.hideElement(this.formControls.input);
107
+ _ConfirmPhone.showElement(this.confirmControls.container);
108
+ _ConfirmPhone.showElement(this.confirmControls.input);
109
+ _ConfirmPhone.showElement(this.confirmControls.countDown);
110
+ _ConfirmPhone.showElement(this.confirmControls.sendCodeButton);
111
+ _ConfirmPhone.hideElement(this.confirmControls.retryButton);
112
+ _ConfirmPhone.hideElement(this.confirmControls.requestConfirmError);
113
+ this.updateRetryHintText(diff);
114
+ }
115
+ this.hideConfirmButtonAndHint();
116
+ this.retryCounter(nextDeliveryAt);
117
+ }
118
+ }).catch((e) => {
119
+ if (e.errors && e.errors[this.fieldType] && this.confirmControls.requestConfirmError) {
120
+ this.confirmControls.requestConfirmError.innerText = String(e.errors[this.fieldType]);
121
+ _ConfirmPhone.showElement(this.confirmControls.requestConfirmError);
122
+ }
123
+ }).finally(() => {
124
+ this.state.isConfirmRequested = false;
125
+ if (this.options.disabledClassName && this.confirmControls.requestConfirmButton) {
126
+ this.confirmControls.requestConfirmButton.classList.remove(this.options.disabledClassName);
127
+ }
128
+ });
129
+ }
130
+ };
131
+ this.validateConfirmInput = () => {
132
+ if (this.confirmControls.input && !this.confirmControls.input.value || !this.confirmControls.input) {
133
+ return false;
134
+ }
135
+ return this.confirmControls.input.value.length === 4;
136
+ };
137
+ this.confirmInputListener = () => {
138
+ if (!this.confirmControls.sendCodeButton || !this.options.disabledClassName || !this.confirmControls.input) {
139
+ return;
140
+ }
141
+ const confirmInput = this.confirmControls.input;
142
+ const confirmValue = confirmInput.value;
143
+ this.confirmControls.input.value = confirmValue.replace(/[^0-9]/g, "");
144
+ const isConfirmValid = this.validateConfirmInput();
145
+ if (this.options.errorClassName) confirmInput.classList.remove(this.options.errorClassName);
146
+ if (isConfirmValid) {
147
+ this.confirmControls.sendCodeButton.classList.remove(this.options.disabledClassName);
148
+ } else {
149
+ this.confirmControls.sendCodeButton.classList.add(this.options.disabledClassName);
150
+ }
151
+ this.sendCodeListener();
152
+ };
153
+ this.sendCodeListener = () => {
154
+ const isConfirmValid = this.validateConfirmInput();
155
+ if (!isConfirmValid) return;
156
+ const confirmData = this.confirmData;
157
+ if (!confirmData) return;
158
+ const confirmInput = this.confirmControls.input;
159
+ if (!confirmInput) return;
160
+ confirmInput.setAttribute("disabled", "disabled");
161
+ this.confirmCode(confirmData).then(({ verificationToken }) => {
162
+ this.state.isConfirmed = true;
163
+ this.state.confirmedData = this.state.dataToConfirm;
164
+ this.toggleInputParents(true);
165
+ _ConfirmPhone.showElement(this.formControls.input);
166
+ _ConfirmPhone.hideElement(this.confirmControls.input);
167
+ _ConfirmPhone.hideElement(this.confirmControls.sendCodeButton);
168
+ _ConfirmPhone.hideElement(this.confirmControls.container);
169
+ _ConfirmPhone.hideElement(this.confirmControls.countDown);
170
+ _ConfirmPhone.hideElement(this.confirmControls.requestConfirmError);
171
+ _ConfirmPhone.hideElement(this.confirmControls.requestConfirmContainer);
172
+ if (verificationToken) {
173
+ this.formControls.tokenInput.value = verificationToken;
174
+ }
175
+ if (this.options.confirmedInputClassName) {
176
+ this.formControls.input.classList.add(this.options.confirmedInputClassName);
177
+ }
178
+ confirmInput.value = "";
179
+ if (this.options.errorClassName) confirmInput.classList.remove(this.options.errorClassName);
180
+ this.removeFieldFromCheck();
181
+ }).catch((error) => {
182
+ if (this.options.errorClassName) confirmInput.classList.add(this.options.errorClassName);
183
+ if (error.messages && this.confirmControls.requestConfirmError) {
184
+ this.confirmControls.requestConfirmError.innerText = String(error.messages);
185
+ _ConfirmPhone.showElement(this.confirmControls.requestConfirmError);
186
+ }
187
+ }).finally(() => {
188
+ this.attemptToEnableSubmit();
189
+ confirmInput.removeAttribute("disabled");
190
+ });
191
+ };
192
+ this.addFieldForCheck = () => {
193
+ if (!this.formControls.form) return;
194
+ const fieldsToConfirm = this.formCheckState;
195
+ if (fieldsToConfirm && !fieldsToConfirm.includes(this.fieldType)) {
196
+ this.formControls.form.setAttribute(this.formCheckAttrName, [...fieldsToConfirm, this.fieldType].join(","));
197
+ }
198
+ };
199
+ this.removeFieldFromCheck = () => {
200
+ const fieldsToConfirm = this.formCheckState;
201
+ if (fieldsToConfirm.includes(this.fieldType)) {
202
+ const updatedFieldsToConfirm = fieldsToConfirm.filter((field) => field !== this.fieldType);
203
+ if (!this.formControls.form) return;
204
+ if (updatedFieldsToConfirm.length) {
205
+ this.formControls.form.setAttribute(this.formCheckAttrName, updatedFieldsToConfirm.join(","));
206
+ } else {
207
+ this.formControls.form.removeAttribute(this.formCheckAttrName);
208
+ }
209
+ }
210
+ };
211
+ this.toggleInputParents = (shouldBeShowed) => {
212
+ const { inputParentsToHide } = this.options;
213
+ if (!inputParentsToHide) return;
214
+ for (let i = 0; i <= inputParentsToHide.length; i++) {
215
+ const el = inputParentsToHide[i];
216
+ const inputParent = el ? this.formControls.input.closest(el) : null;
217
+ if (inputParent && this.options.hiddenClassName) {
218
+ if (shouldBeShowed) {
219
+ inputParent.classList.remove(this.options.hiddenClassName);
220
+ } else {
221
+ inputParent.classList.add(this.options.hiddenClassName);
222
+ }
223
+ }
224
+ }
225
+ };
226
+ this.disableSubmit = () => {
227
+ if (this.formControls.form) this.formControls.form.setAttribute(this.formPreventSubmitAttr, String(true));
228
+ if (this.formControls.submitButton) {
229
+ this.formControls.submitButton.setAttribute("disabled", "disabled");
230
+ if (this.options.disabledClassName) this.formControls.submitButton.classList.add(this.options.disabledClassName);
231
+ }
232
+ };
233
+ this.attemptToEnableSubmit = () => {
234
+ const fieldsToConfirm = this.formCheckState;
235
+ if (fieldsToConfirm.length === 0) {
236
+ if (this.formControls.form) this.formControls.form.removeAttribute(this.formPreventSubmitAttr);
237
+ if (this.formControls.submitButton) {
238
+ this.formControls.submitButton.removeAttribute("disabled");
239
+ if (this.options.disabledClassName) {
240
+ this.formControls.submitButton.classList.remove(this.options.disabledClassName);
241
+ }
242
+ }
243
+ }
244
+ };
245
+ this.retryListener = () => {
246
+ const requestData = this.requestData;
247
+ if (!requestData) return;
248
+ this.requestCode(requestData).then(({ nextDeliveryAt }) => {
249
+ this.retryCounter(nextDeliveryAt);
250
+ });
251
+ };
252
+ this.retryCounter = (nextDeliveryAt) => {
253
+ if (this.state.isConfirmed) {
254
+ return;
255
+ }
256
+ const interval = setInterval(() => {
257
+ const diff = _ConfirmPhone.getDiffSeconds(nextDeliveryAt);
258
+ if (diff > 0 && !this.state.isConfirmed) {
259
+ _ConfirmPhone.hideElement(this.confirmControls.retryButton);
260
+ _ConfirmPhone.showElement(this.confirmControls.countDown);
261
+ this.updateRetryHintText(diff);
262
+ } else {
263
+ if (!this.state.isConfirmed) {
264
+ _ConfirmPhone.showElement(this.confirmControls.retryButton);
265
+ }
266
+ _ConfirmPhone.hideElement(this.confirmControls.countDown);
267
+ clearInterval(interval);
268
+ }
269
+ }, 1e3);
270
+ };
271
+ this.destroy = () => {
272
+ if (this.formControls.input) this.formControls.input.removeEventListener("keyup", this.inputListener);
273
+ if (this.confirmControls.input) this.confirmControls.input.removeEventListener("input", this.confirmInputListener);
274
+ if (this.confirmControls.sendCodeButton) {
275
+ this.confirmControls.sendCodeButton.removeEventListener("click", this.sendCodeListener);
276
+ }
277
+ if (this.confirmControls.retryButton) {
278
+ this.confirmControls.retryButton.removeEventListener("click", this.retryListener);
279
+ }
280
+ if (this.confirmControls.requestConfirmButton) {
281
+ this.confirmControls.requestConfirmButton.removeEventListener("click", this.requestConfirmListener);
282
+ }
283
+ this.confirmControls.container = null;
284
+ this.confirmControls.input = null;
285
+ this.confirmControls.countDown = null;
286
+ this.confirmControls.retryButton = null;
287
+ this.confirmControls.requestConfirmContainer = null;
288
+ this.confirmControls.requestConfirmButton = null;
289
+ this.confirmControls.requestConfirmHint = null;
290
+ this.confirmControls.requestConfirmError = null;
291
+ this.confirmControls.sendCodeButton = null;
292
+ };
293
+ this.options = merge(DEFAULT_OPTIONS, options);
294
+ const form = node.closest("form");
295
+ this.formControls = {
296
+ form: node.closest("form"),
297
+ input: node,
298
+ submitButton: form ? form.querySelector('[type="submit"]') : null,
299
+ tokenInput: document.createElement("input")
300
+ };
301
+ this.formControls.tokenInput.type = "hidden";
302
+ this.formControls.tokenInput.name = "verification_token";
303
+ this.state.isConfirmed = this.isConfirmed;
304
+ this.state.dataToConfirm = this.userPhoneWithoutFormatting || "";
305
+ this.state.confirmedData = this.confirmedData;
306
+ this.confirmControls = {
307
+ container: document.createElement("div"),
308
+ countDown: document.createElement("div"),
309
+ input: document.createElement("input"),
310
+ requestConfirmButton: document.createElement("div"),
311
+ requestConfirmContainer: document.createElement("div"),
312
+ requestConfirmError: document.createElement("div"),
313
+ requestConfirmHint: document.createElement("div"),
314
+ retryButton: document.createElement("div"),
315
+ sendCodeButton: document.createElement("div")
316
+ };
317
+ }
318
+ // eslint-disable-next-line complexity
319
+ apply(sdk) {
320
+ var _a, _b, _c, _d, _e;
321
+ if (this.formControls.input.ffcc !== void 0 && this.formControls.input.ffcc !== null) {
322
+ return;
323
+ }
324
+ this.api = sdk.foxApi;
325
+ this.formControls.input.ffcc = this;
326
+ const { isConfirmRequested, isConfirmed, dataToConfirm } = this.state;
327
+ const { input: phoneInput } = this.formControls;
328
+ const {
329
+ container,
330
+ input: confirmInput,
331
+ countDown,
332
+ retryButton,
333
+ requestConfirmContainer,
334
+ requestConfirmButton,
335
+ requestConfirmHint,
336
+ requestConfirmError,
337
+ sendCodeButton
338
+ } = this.confirmControls;
339
+ if (!this.formControls.form) {
340
+ throw new Error(FORM_NOT_FOUND_ERROR);
341
+ } else if (!phoneInput.parentNode) {
342
+ throw new Error(FIELD_WITHOUT_PARENT_ERROR);
343
+ } else if (!confirmInput || !container || !countDown || !retryButton || !requestConfirmContainer || !requestConfirmButton || !requestConfirmHint || !requestConfirmError || !sendCodeButton) {
344
+ throw new Error(INITIALIZATION_FAILED_ERROR);
345
+ }
346
+ const inputClassNames = [`${this.options.className}__input`, ...Array.from(this.formControls.input.classList)];
347
+ confirmInput.maxLength = 4;
348
+ confirmInput.pattern = "[0-9]{4}";
349
+ confirmInput.classList.add(...inputClassNames);
350
+ confirmInput.placeholder = (_a = this.options.confirmCodePlaceholderText) != null ? _a : "";
351
+ this.formControls.form.prepend(this.formControls.tokenInput);
352
+ if (isConfirmed && this.options.confirmedInputClassName) {
353
+ phoneInput.classList.add(this.options.confirmedInputClassName);
354
+ }
355
+ if (!isConfirmed) {
356
+ this.addFieldForCheck();
357
+ this.disableSubmit();
358
+ }
359
+ if (!isConfirmRequested) {
360
+ _ConfirmPhone.hideElement(confirmInput);
361
+ }
362
+ container.classList.add(`${this.options.className}`);
363
+ countDown.classList.add(`${this.options.className}__countdown`);
364
+ retryButton.classList.add(`${this.options.className}__button`);
365
+ retryButton.innerText = (_b = this.options.retryButtonText) != null ? _b : "";
366
+ sendCodeButton.classList.add(`${this.options.className}__send-code-button`);
367
+ if (this.options.disabledClassName) sendCodeButton.classList.add(this.options.disabledClassName);
368
+ sendCodeButton.innerText = (_c = this.options.sendCodeButtonText) != null ? _c : "";
369
+ requestConfirmError.classList.add(`${this.options.className}__error`);
370
+ container.appendChild(confirmInput);
371
+ container.appendChild(requestConfirmError);
372
+ container.appendChild(countDown);
373
+ container.appendChild(sendCodeButton);
374
+ container.appendChild(retryButton);
375
+ phoneInput.parentNode.insertBefore(container, phoneInput.nextSibling);
376
+ requestConfirmContainer.classList.add(`${this.options.className}__button-container`);
377
+ requestConfirmButton.classList.add(`${this.options.className}__button`);
378
+ requestConfirmButton.innerText = (_d = this.options.requestButtonText) != null ? _d : "";
379
+ requestConfirmHint.innerText = (_e = this.options.unconfirmedHintText) != null ? _e : "";
380
+ requestConfirmHint.classList.add(`${this.options.className}__hint`);
381
+ if (!dataToConfirm || dataToConfirm && isConfirmed) {
382
+ this.hideConfirmButtonAndHint();
383
+ }
384
+ _ConfirmPhone.hideElement(countDown);
385
+ _ConfirmPhone.hideElement(requestConfirmError);
386
+ _ConfirmPhone.hideElement(retryButton);
387
+ _ConfirmPhone.hideElement(sendCodeButton);
388
+ requestConfirmContainer.appendChild(requestConfirmHint);
389
+ requestConfirmContainer.appendChild(requestConfirmButton);
390
+ container.appendChild(requestConfirmContainer);
391
+ this.bindListeners();
392
+ }
393
+ requestCode(payloadData) {
394
+ return __async(this, null, function* () {
395
+ if (!this.api) {
396
+ throw new Error(API_NOT_SPECIFIED_ERROR);
397
+ }
398
+ const { data } = yield this.api.post(_ConfirmPhone.requestUrl(), payloadData);
399
+ return data;
400
+ });
401
+ }
402
+ confirmCode(payloadData) {
403
+ return __async(this, null, function* () {
404
+ if (!this.api) {
405
+ throw new Error(API_NOT_SPECIFIED_ERROR);
406
+ }
407
+ const { data } = yield this.api.post(_ConfirmPhone.confirmUrl(), payloadData);
408
+ return data;
409
+ });
410
+ }
411
+ get isConfirmed() {
412
+ return this.options.userData.phoneConfirmed;
413
+ }
414
+ get confirmedData() {
415
+ return this.isConfirmed ? this.userPhoneWithoutFormatting : "";
416
+ }
417
+ get userPhoneWithoutFormatting() {
418
+ return _ConfirmPhone.cleanPhoneFormatting(this.options.userData.phone);
419
+ }
420
+ static requestUrl() {
421
+ return "/api/phone_confirmation_codes";
422
+ }
423
+ static confirmUrl() {
424
+ return "/api/phone_confirmations";
425
+ }
426
+ get requestData() {
427
+ return {
428
+ phone: this.state.dataToConfirm,
429
+ type: "sms"
430
+ };
431
+ }
432
+ get confirmData() {
433
+ return {
434
+ code: this.confirmControls.input ? this.confirmControls.input.value : "",
435
+ phone: this.state.dataToConfirm
436
+ };
437
+ }
438
+ get formCheckState() {
439
+ if (!this.formControls.form) return [];
440
+ const formConfirmState = this.formControls.form.getAttribute(this.formCheckAttrName) || "";
441
+ return formConfirmState === "" ? [] : formConfirmState.split(",");
442
+ }
443
+ static cleanPhoneFormatting(rawPhone) {
444
+ return rawPhone.replace(/[-+ ()]/g, "");
445
+ }
446
+ showConfirmButtonAndHint() {
447
+ _ConfirmPhone.showElement(this.confirmControls.container);
448
+ _ConfirmPhone.showElement(this.confirmControls.requestConfirmContainer);
449
+ _ConfirmPhone.showElement(this.confirmControls.requestConfirmButton);
450
+ _ConfirmPhone.showElement(this.confirmControls.requestConfirmHint);
451
+ }
452
+ hideConfirmButtonAndHint() {
453
+ _ConfirmPhone.hideElement(this.confirmControls.requestConfirmButton);
454
+ _ConfirmPhone.hideElement(this.confirmControls.requestConfirmHint);
455
+ }
456
+ };
457
+ _ConfirmPhone.showElement = (el) => {
458
+ if (el) el.style.removeProperty("display");
459
+ };
460
+ _ConfirmPhone.hideElement = (el) => {
461
+ if (el) el.style.display = "none";
462
+ };
463
+ _ConfirmPhone.getDiffSeconds = (date) => {
464
+ return Math.round((Date.parse(date) - Date.now()) / 1e3);
465
+ };
466
+ var ConfirmPhone = _ConfirmPhone;
467
+ export {
468
+ ConfirmPhone
469
+ };
@@ -0,0 +1,69 @@
1
+ // @flow
2
+ import type { SdkPlugin } from "../index";
3
+
4
+ declare interface IUserData {
5
+ phone: string;
6
+ phoneConfirmed: boolean;
7
+ }
8
+ declare interface IConfirmPhoneOptions {
9
+ className?: string;
10
+ errorClassName?: string;
11
+ disabledClassName?: string;
12
+ hiddenClassName?: string;
13
+ confirmedInputClassName?: string;
14
+ confirmCodePlaceholderText?: string;
15
+ confirmCodeInvalidText?: string;
16
+ inputParentsToHide?: string[];
17
+ requestButtonText?: string;
18
+ retryButtonText?: string;
19
+ sendCodeButtonText?: string;
20
+ unconfirmedHintText?: string;
21
+ untilRetryText?: string;
22
+ userData: IUserData;
23
+ }
24
+ declare interface IRequestPhoneData {
25
+ phone: string;
26
+ type: string;
27
+ }
28
+ declare interface IRequestEmailData {
29
+ email: string;
30
+ type: string;
31
+ }
32
+ declare interface TRequestResponse {
33
+ nextDeliveryAt: string;
34
+ retryTime?: number;
35
+ }
36
+ declare type TRequestData = IRequestPhoneData | IRequestEmailData | void;
37
+ declare interface IConfirmPhoneData {
38
+ code: string;
39
+ phone: string;
40
+ }
41
+ declare interface IConfirmEmailData {
42
+ code: string;
43
+ email: string;
44
+ }
45
+ declare type TConfirmData = IConfirmPhoneData | IConfirmEmailData | void;
46
+ declare type TConfirmResponse = {
47
+ verificationToken?: string,
48
+ ...
49
+ };
50
+ declare class ConfirmPhone implements SdkPlugin {
51
+ constructor(node: HTMLInputElement, options?: IConfirmPhoneOptions): this;
52
+ apply(
53
+ sdk: $Call<<A, R>((A, ...any[]) => R) => A, $PropertyType<SdkPlugin, "apply">>
54
+ ): void;
55
+ requestCode(payloadData: TRequestData): Promise<TRequestResponse>;
56
+ confirmCode(payloadData: TConfirmData): Promise<TConfirmResponse>;
57
+ isConfirmed: boolean;
58
+ confirmedData: string;
59
+ userPhoneWithoutFormatting: string;
60
+ static requestUrl(): string;
61
+ static confirmUrl(): string;
62
+ requestData: TRequestData;
63
+ confirmData: TConfirmData;
64
+ formCheckState: string[];
65
+ static cleanPhoneFormatting(rawPhone: string): string;
66
+ addFieldForCheck: () => void;
67
+ destroy: () => void;
68
+ }
69
+ declare export { ConfirmPhone };