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