@foxford/sdk 6.2.1 → 7.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.
- package/api.cjs +599 -0
- package/api.d.cts +68 -0
- package/api.d.ts +68 -0
- package/api.js +560 -0
- package/api.js.flow +108 -0
- package/index.cjs +73 -73
- package/index.js +73 -73
- package/package.json +14 -3
package/api.cjs
ADDED
|
@@ -0,0 +1,599 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __export = (target, all) => {
|
|
26
|
+
for (var name in all)
|
|
27
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
28
|
+
};
|
|
29
|
+
var __copyProps = (to, from, except, desc) => {
|
|
30
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
31
|
+
for (let key of __getOwnPropNames(from))
|
|
32
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
33
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
34
|
+
}
|
|
35
|
+
return to;
|
|
36
|
+
};
|
|
37
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
38
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
39
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
40
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
41
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
42
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
43
|
+
mod
|
|
44
|
+
));
|
|
45
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
46
|
+
var __async = (__this, __arguments, generator) => {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
var fulfilled = (value) => {
|
|
49
|
+
try {
|
|
50
|
+
step(generator.next(value));
|
|
51
|
+
} catch (e) {
|
|
52
|
+
reject(e);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var rejected = (value) => {
|
|
56
|
+
try {
|
|
57
|
+
step(generator.throw(value));
|
|
58
|
+
} catch (e) {
|
|
59
|
+
reject(e);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
63
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// src/api/index.ts
|
|
68
|
+
var api_exports = {};
|
|
69
|
+
__export(api_exports, {
|
|
70
|
+
CamelizeRequestPlugin: () => CamelizeRequestPlugin,
|
|
71
|
+
CaptchaPlugin: () => CaptchaPlugin,
|
|
72
|
+
ReferrerRequestPlugin: () => ReferrerRequestPlugin,
|
|
73
|
+
apiBaseConfig: () => apiBaseConfig,
|
|
74
|
+
apiConfig: () => apiConfig,
|
|
75
|
+
defaultPlugins: () => defaultPlugins
|
|
76
|
+
});
|
|
77
|
+
module.exports = __toCommonJS(api_exports);
|
|
78
|
+
|
|
79
|
+
// src/constants.ts
|
|
80
|
+
var CSRF_COOKIE_NAME = "_csrf_token";
|
|
81
|
+
|
|
82
|
+
// src/api/config.ts
|
|
83
|
+
var apiBaseConfig = {
|
|
84
|
+
headers: { "X-Requested-With": "XMLHttpRequest" },
|
|
85
|
+
withXSRFToken: true,
|
|
86
|
+
xsrfCookieName: CSRF_COOKIE_NAME,
|
|
87
|
+
xsrfHeaderName: "X-CSRF-Token"
|
|
88
|
+
};
|
|
89
|
+
var apiConfig = __spreadProps(__spreadValues({}, apiBaseConfig), {
|
|
90
|
+
withCredentials: true
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// src/utils/camelize.ts
|
|
94
|
+
var import_camelcase_keys_deep = __toESM(require("camelcase-keys-deep"), 1);
|
|
95
|
+
var import_decamelize_keys_deep = __toESM(require("decamelize-keys-deep"), 1);
|
|
96
|
+
var camelize = (obj) => (0, import_camelcase_keys_deep.default)(obj);
|
|
97
|
+
|
|
98
|
+
// src/api/plugins/CamelizeRequestPlugin.ts
|
|
99
|
+
var CamelizeRequestPlugin = class {
|
|
100
|
+
constructor() {
|
|
101
|
+
this.pluginType = "request";
|
|
102
|
+
this.pluginName = "camelizeRequestPlugin";
|
|
103
|
+
}
|
|
104
|
+
// требуется публичный метод, а для внутренней реализации может понадобиться this
|
|
105
|
+
// eslint-disable-next-line @typescript-eslint/class-methods-use-this
|
|
106
|
+
execute(config, instance) {
|
|
107
|
+
return new Promise((resolve) => {
|
|
108
|
+
const convert = typeof config.camelize === "boolean" ? config.camelize : true;
|
|
109
|
+
if (convert) {
|
|
110
|
+
const defaultTransform = instance.defaults.transformResponse;
|
|
111
|
+
const camelizeResponse = (data) => {
|
|
112
|
+
return camelize(data);
|
|
113
|
+
};
|
|
114
|
+
if (defaultTransform) {
|
|
115
|
+
config.transformResponse = Array.isArray(defaultTransform) ? [...defaultTransform, camelizeResponse] : [defaultTransform, camelizeResponse];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
resolve(config);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
// требуется публичный метод, а для внутренней реализации может понадобиться this
|
|
122
|
+
// eslint-disable-next-line @typescript-eslint/class-methods-use-this
|
|
123
|
+
isApplicable(config) {
|
|
124
|
+
return typeof config.camelize === "boolean" ? config.camelize : true;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// src/api/plugins/CaptchaPlugin.ts
|
|
129
|
+
var import_services = require("@foxford/services");
|
|
130
|
+
var CaptchaPlugin = class {
|
|
131
|
+
constructor(captchaConfig) {
|
|
132
|
+
this.pluginType = "responseFail";
|
|
133
|
+
this.pluginName = "captchaPlugin";
|
|
134
|
+
this.captchaConfig = captchaConfig;
|
|
135
|
+
}
|
|
136
|
+
// требуется публичный метод, а для внутренней реализации может понадобиться this
|
|
137
|
+
// eslint-disable-next-line complexity
|
|
138
|
+
execute(error) {
|
|
139
|
+
return __async(this, null, function* () {
|
|
140
|
+
var _a, _b;
|
|
141
|
+
try {
|
|
142
|
+
const captchaConfig = typeof this.captchaConfig === "function" ? this.captchaConfig() : this.captchaConfig;
|
|
143
|
+
if (!captchaConfig) return error;
|
|
144
|
+
const { settings = {} } = (_b = (_a = error.response) == null ? void 0 : _a.data) != null ? _b : {};
|
|
145
|
+
const { provider } = settings;
|
|
146
|
+
const siteKey = settings.siteKey || settings.site_key || void 0;
|
|
147
|
+
if (!settings || !provider || !siteKey) return error;
|
|
148
|
+
this.captcha = new import_services.CaptchaService(__spreadProps(__spreadValues({}, captchaConfig), {
|
|
149
|
+
provider,
|
|
150
|
+
sitekey: siteKey
|
|
151
|
+
}));
|
|
152
|
+
const { config } = error;
|
|
153
|
+
const captchaAnswer = yield this.captcha.execute({
|
|
154
|
+
location: config.url,
|
|
155
|
+
method: config.method
|
|
156
|
+
});
|
|
157
|
+
if (captchaAnswer === null || captchaAnswer === void 0 || typeof (captchaAnswer == null ? void 0 : captchaAnswer.captcha_token) !== "string") {
|
|
158
|
+
return config;
|
|
159
|
+
}
|
|
160
|
+
const captchaPayload = {
|
|
161
|
+
verification: {
|
|
162
|
+
settings: {
|
|
163
|
+
token: captchaAnswer.captcha_token
|
|
164
|
+
},
|
|
165
|
+
type: "captcha"
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
if (config.method === "get") {
|
|
169
|
+
config.params = __spreadValues(__spreadValues({}, config.params), captchaPayload);
|
|
170
|
+
}
|
|
171
|
+
if (typeof config.data === "string") {
|
|
172
|
+
try {
|
|
173
|
+
let data = JSON.parse(config.data);
|
|
174
|
+
data = __spreadValues(__spreadValues({}, data), captchaPayload);
|
|
175
|
+
config.data = JSON.stringify(data);
|
|
176
|
+
} catch (err) {
|
|
177
|
+
console.error(err);
|
|
178
|
+
}
|
|
179
|
+
} else if (config.data instanceof FormData) {
|
|
180
|
+
const formData = config.data;
|
|
181
|
+
formData.append("verification[settings][token]", captchaPayload.verification.settings.token);
|
|
182
|
+
formData.append("verification[type]", captchaPayload.verification.type);
|
|
183
|
+
config.data = formData;
|
|
184
|
+
} else if (typeof config.data === "object") {
|
|
185
|
+
config.data = __spreadValues(__spreadValues({}, config.data), captchaPayload);
|
|
186
|
+
}
|
|
187
|
+
return config;
|
|
188
|
+
} catch (error2) {
|
|
189
|
+
return error2;
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
// требуется публичный метод, а для внутренней реализации может понадобиться this
|
|
194
|
+
// eslint-disable-next-line @typescript-eslint/class-methods-use-this
|
|
195
|
+
isApplicable(error) {
|
|
196
|
+
var _a;
|
|
197
|
+
return ((_a = error.response) == null ? void 0 : _a.status) === 449;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
// src/api/plugins/DataLayerEventDispatcherPlugin.ts
|
|
202
|
+
var DataLayerEventDispatcherPlugin = class {
|
|
203
|
+
constructor() {
|
|
204
|
+
this.pluginType = "responseSuccess";
|
|
205
|
+
this.pluginName = "dataLayerEventDispatcherPlugin";
|
|
206
|
+
}
|
|
207
|
+
// требуется публичный метод, а для внутренней реализации может понадобиться this
|
|
208
|
+
// eslint-disable-next-line @typescript-eslint/class-methods-use-this
|
|
209
|
+
execute(response) {
|
|
210
|
+
return new Promise((resolve) => {
|
|
211
|
+
try {
|
|
212
|
+
const rawResponse = JSON.parse(response.request.response);
|
|
213
|
+
if (Array.isArray(rawResponse["data_layer_events"])) {
|
|
214
|
+
if (!Array.isArray(window.dataLayer)) {
|
|
215
|
+
window.dataLayer = [];
|
|
216
|
+
}
|
|
217
|
+
window.dataLayer.push(...rawResponse["data_layer_events"]);
|
|
218
|
+
}
|
|
219
|
+
} catch (e) {
|
|
220
|
+
}
|
|
221
|
+
resolve(response);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
// требуется публичный метод, а для внутренней реализации может понадобиться this
|
|
225
|
+
// eslint-disable-next-line @typescript-eslint/class-methods-use-this
|
|
226
|
+
isApplicable() {
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
// src/utils/pathToRegexp.ts
|
|
232
|
+
function lexer(str) {
|
|
233
|
+
const tokens = [];
|
|
234
|
+
let i = 0;
|
|
235
|
+
while (i < str.length) {
|
|
236
|
+
const char = str[i];
|
|
237
|
+
if (char === "*" || char === "+" || char === "?") {
|
|
238
|
+
tokens.push({ index: i, type: "MODIFIER", value: str[i++] });
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
if (char === "\\") {
|
|
242
|
+
tokens.push({ index: i++, type: "ESCAPED_CHAR", value: str[i++] });
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
if (char === "{") {
|
|
246
|
+
tokens.push({ index: i, type: "OPEN", value: str[i++] });
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
if (char === "}") {
|
|
250
|
+
tokens.push({ index: i, type: "CLOSE", value: str[i++] });
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
if (char === ":") {
|
|
254
|
+
let name = "";
|
|
255
|
+
let j = i + 1;
|
|
256
|
+
while (j < str.length) {
|
|
257
|
+
const code = str.charCodeAt(j);
|
|
258
|
+
if (
|
|
259
|
+
// `0-9`
|
|
260
|
+
code >= 48 && code <= 57 || // `A-Z`
|
|
261
|
+
code >= 65 && code <= 90 || // `a-z`
|
|
262
|
+
code >= 97 && code <= 122 || // `_`
|
|
263
|
+
code === 95
|
|
264
|
+
) {
|
|
265
|
+
name += str[j++];
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
if (!name) throw new TypeError(`Missing parameter name at ${i}`);
|
|
271
|
+
tokens.push({ index: i, type: "NAME", value: name });
|
|
272
|
+
i = j;
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
if (char === "(") {
|
|
276
|
+
let count = 1;
|
|
277
|
+
let pattern = "";
|
|
278
|
+
let j = i + 1;
|
|
279
|
+
if (str[j] === "?") {
|
|
280
|
+
throw new TypeError(`Pattern cannot start with "?" at ${j}`);
|
|
281
|
+
}
|
|
282
|
+
while (j < str.length) {
|
|
283
|
+
if (str[j] === "\\") {
|
|
284
|
+
pattern += str[j++] + str[j++];
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
if (str[j] === ")") {
|
|
288
|
+
count--;
|
|
289
|
+
if (count === 0) {
|
|
290
|
+
j++;
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
} else if (str[j] === "(") {
|
|
294
|
+
count++;
|
|
295
|
+
if (str[j + 1] !== "?") {
|
|
296
|
+
throw new TypeError(`Capturing groups are not allowed at ${j}`);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
pattern += str[j++];
|
|
300
|
+
}
|
|
301
|
+
if (count) throw new TypeError(`Unbalanced pattern at ${i}`);
|
|
302
|
+
if (!pattern) throw new TypeError(`Missing pattern at ${i}`);
|
|
303
|
+
tokens.push({ index: i, type: "PATTERN", value: pattern });
|
|
304
|
+
i = j;
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
tokens.push({ index: i, type: "CHAR", value: str[i++] });
|
|
308
|
+
}
|
|
309
|
+
tokens.push({ index: i, type: "END", value: "" });
|
|
310
|
+
return tokens;
|
|
311
|
+
}
|
|
312
|
+
function parse(str, options = {}) {
|
|
313
|
+
const tokens = lexer(str);
|
|
314
|
+
const { prefixes = "./" } = options;
|
|
315
|
+
const defaultPattern = `[^${escapeString(options.delimiter || "/#?")}]+?`;
|
|
316
|
+
const result = [];
|
|
317
|
+
let key = 0;
|
|
318
|
+
let i = 0;
|
|
319
|
+
let path = "";
|
|
320
|
+
const tryConsume = (type) => {
|
|
321
|
+
var _a, _b;
|
|
322
|
+
if (i < tokens.length && ((_a = tokens[i]) == null ? void 0 : _a.type) === type) return (_b = tokens[i++]) == null ? void 0 : _b.value;
|
|
323
|
+
return void 0;
|
|
324
|
+
};
|
|
325
|
+
const mustConsume = (type) => {
|
|
326
|
+
var _a, _b;
|
|
327
|
+
const value = tryConsume(type);
|
|
328
|
+
if (value !== void 0) return value;
|
|
329
|
+
throw new TypeError(`Unexpected ${(_a = tokens[i]) == null ? void 0 : _a.type} at ${(_b = tokens[i]) == null ? void 0 : _b.index}, expected ${type}`);
|
|
330
|
+
};
|
|
331
|
+
const consumeText = () => {
|
|
332
|
+
let result2 = "";
|
|
333
|
+
let value;
|
|
334
|
+
while (value = tryConsume("CHAR") || tryConsume("ESCAPED_CHAR")) {
|
|
335
|
+
result2 += value;
|
|
336
|
+
}
|
|
337
|
+
return result2;
|
|
338
|
+
};
|
|
339
|
+
while (i < tokens.length) {
|
|
340
|
+
const char = tryConsume("CHAR");
|
|
341
|
+
const name = tryConsume("NAME");
|
|
342
|
+
const pattern = tryConsume("PATTERN");
|
|
343
|
+
if (name || pattern) {
|
|
344
|
+
let prefix = char || "";
|
|
345
|
+
if (prefixes.indexOf(prefix) === -1) {
|
|
346
|
+
path += prefix;
|
|
347
|
+
prefix = "";
|
|
348
|
+
}
|
|
349
|
+
if (path) {
|
|
350
|
+
result.push(path);
|
|
351
|
+
path = "";
|
|
352
|
+
}
|
|
353
|
+
result.push({
|
|
354
|
+
modifier: tryConsume("MODIFIER") || "",
|
|
355
|
+
name: name || key++,
|
|
356
|
+
pattern: pattern || defaultPattern,
|
|
357
|
+
prefix,
|
|
358
|
+
suffix: ""
|
|
359
|
+
});
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
const value = char || tryConsume("ESCAPED_CHAR");
|
|
363
|
+
if (value) {
|
|
364
|
+
path += value;
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
if (path) {
|
|
368
|
+
result.push(path);
|
|
369
|
+
path = "";
|
|
370
|
+
}
|
|
371
|
+
const open = tryConsume("OPEN");
|
|
372
|
+
if (open) {
|
|
373
|
+
const prefix = consumeText();
|
|
374
|
+
const name2 = tryConsume("NAME") || "";
|
|
375
|
+
const pattern2 = tryConsume("PATTERN") || "";
|
|
376
|
+
const suffix = consumeText();
|
|
377
|
+
mustConsume("CLOSE");
|
|
378
|
+
result.push({
|
|
379
|
+
modifier: tryConsume("MODIFIER") || "",
|
|
380
|
+
name: name2 || (pattern2 ? key++ : ""),
|
|
381
|
+
pattern: name2 && !pattern2 ? defaultPattern : pattern2,
|
|
382
|
+
prefix,
|
|
383
|
+
suffix
|
|
384
|
+
});
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
mustConsume("END");
|
|
388
|
+
}
|
|
389
|
+
return result;
|
|
390
|
+
}
|
|
391
|
+
function escapeString(str) {
|
|
392
|
+
return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
|
|
393
|
+
}
|
|
394
|
+
function flags(options) {
|
|
395
|
+
return options && options.sensitive ? "" : "i";
|
|
396
|
+
}
|
|
397
|
+
function regexpToRegexp(path, keys) {
|
|
398
|
+
if (!keys) return path;
|
|
399
|
+
const groupsRegex = /\((?:\?<(.*?)>)?(?!\?)/g;
|
|
400
|
+
let index = 0;
|
|
401
|
+
let execResult = groupsRegex.exec(path.source);
|
|
402
|
+
while (execResult) {
|
|
403
|
+
keys.push({
|
|
404
|
+
modifier: "",
|
|
405
|
+
// Use parenthesized substring match if available, index otherwise
|
|
406
|
+
name: execResult[1] || index++,
|
|
407
|
+
pattern: "",
|
|
408
|
+
prefix: "",
|
|
409
|
+
suffix: ""
|
|
410
|
+
});
|
|
411
|
+
execResult = groupsRegex.exec(path.source);
|
|
412
|
+
}
|
|
413
|
+
return path;
|
|
414
|
+
}
|
|
415
|
+
function arrayToRegexp(paths, keys, options) {
|
|
416
|
+
const parts = paths.map((path) => pathToRegexp(path, keys, options).source);
|
|
417
|
+
return new RegExp(`(?:${parts.join("|")})`, flags(options));
|
|
418
|
+
}
|
|
419
|
+
function stringToRegexp(path, keys, options) {
|
|
420
|
+
return tokensToRegexp(parse(path, options), keys, options);
|
|
421
|
+
}
|
|
422
|
+
function tokensToRegexp(tokens, keys, options = {}) {
|
|
423
|
+
const {
|
|
424
|
+
strict = false,
|
|
425
|
+
start = true,
|
|
426
|
+
end = true,
|
|
427
|
+
encode = (x) => x,
|
|
428
|
+
delimiter = "/#?",
|
|
429
|
+
endsWith = ""
|
|
430
|
+
} = options;
|
|
431
|
+
const endsWithRe = `[${escapeString(endsWith)}]|$`;
|
|
432
|
+
const delimiterRe = `[${escapeString(delimiter)}]`;
|
|
433
|
+
let route = start ? "^" : "";
|
|
434
|
+
for (const token of tokens) {
|
|
435
|
+
if (typeof token === "string") {
|
|
436
|
+
route += escapeString(encode(token));
|
|
437
|
+
} else {
|
|
438
|
+
const prefix = escapeString(encode(token.prefix));
|
|
439
|
+
const suffix = escapeString(encode(token.suffix));
|
|
440
|
+
if (token.pattern) {
|
|
441
|
+
if (keys) keys.push(token);
|
|
442
|
+
if (prefix || suffix) {
|
|
443
|
+
if (token.modifier === "+" || token.modifier === "*") {
|
|
444
|
+
const mod = token.modifier === "*" ? "?" : "";
|
|
445
|
+
route += `(?:${prefix}((?:${token.pattern})(?:${suffix}${prefix}(?:${token.pattern}))*)${suffix})${mod}`;
|
|
446
|
+
} else {
|
|
447
|
+
route += `(?:${prefix}(${token.pattern})${suffix})${token.modifier}`;
|
|
448
|
+
}
|
|
449
|
+
} else {
|
|
450
|
+
if (token.modifier === "+" || token.modifier === "*") {
|
|
451
|
+
route += `((?:${token.pattern})${token.modifier})`;
|
|
452
|
+
} else {
|
|
453
|
+
route += `(${token.pattern})${token.modifier}`;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
} else {
|
|
457
|
+
route += `(?:${prefix}${suffix})${token.modifier}`;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
if (end) {
|
|
462
|
+
if (!strict) route += `${delimiterRe}?`;
|
|
463
|
+
route += !options.endsWith ? "$" : `(?=${endsWithRe})`;
|
|
464
|
+
} else {
|
|
465
|
+
const endToken = tokens[tokens.length - 1];
|
|
466
|
+
const isEndDelimited = typeof endToken === "string" ? delimiterRe.indexOf(endToken[endToken.length - 1]) > -1 : endToken === void 0;
|
|
467
|
+
if (!strict) {
|
|
468
|
+
route += `(?:${delimiterRe}(?=${endsWithRe}))?`;
|
|
469
|
+
}
|
|
470
|
+
if (!isEndDelimited) {
|
|
471
|
+
route += `(?=${delimiterRe}|${endsWithRe})`;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
return new RegExp(route, flags(options));
|
|
475
|
+
}
|
|
476
|
+
function pathToRegexp(path, keys, options) {
|
|
477
|
+
if (path instanceof RegExp) return regexpToRegexp(path, keys);
|
|
478
|
+
if (Array.isArray(path)) return arrayToRegexp(path, keys, options);
|
|
479
|
+
return stringToRegexp(path, keys, options);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// src/utils/matchPath.ts
|
|
483
|
+
var cache = {};
|
|
484
|
+
var cacheLimit = 1e4;
|
|
485
|
+
var cacheCount = 0;
|
|
486
|
+
function compilePath(path, options) {
|
|
487
|
+
const { end = false, strict = false, sensitive = false } = options;
|
|
488
|
+
const cacheKey = `${path}/${end.toString()}/${strict.toString()}/${sensitive.toString()}`;
|
|
489
|
+
const pathCache = cache[cacheKey] || (cache[cacheKey] = {});
|
|
490
|
+
if (pathCache[path]) return pathCache[path];
|
|
491
|
+
const keys = [];
|
|
492
|
+
const regexp = pathToRegexp(path, keys, options);
|
|
493
|
+
const result = { keys, regexp };
|
|
494
|
+
if (cacheCount < cacheLimit) {
|
|
495
|
+
pathCache[path] = result;
|
|
496
|
+
cacheCount += 1;
|
|
497
|
+
}
|
|
498
|
+
return result;
|
|
499
|
+
}
|
|
500
|
+
var matchPath = (pathname, options) => {
|
|
501
|
+
if (options === void 0) {
|
|
502
|
+
options = {};
|
|
503
|
+
}
|
|
504
|
+
if (typeof options === "string" || Array.isArray(options)) {
|
|
505
|
+
options = {
|
|
506
|
+
path: options
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
const _options = options, path = _options.path, _options$exact = _options.exact, exact = _options$exact === void 0 ? false : _options$exact, _options$strict = _options.strict, strict = _options$strict === void 0 ? false : _options$strict, _options$sensitive = _options.sensitive, sensitive = _options$sensitive === void 0 ? false : _options$sensitive;
|
|
510
|
+
const paths = [].concat(path);
|
|
511
|
+
return paths.reduce(function(matched, path2) {
|
|
512
|
+
if (!path2 && path2 !== "") return null;
|
|
513
|
+
if (matched) return matched;
|
|
514
|
+
const _compilePath = compilePath(path2, {
|
|
515
|
+
end: exact,
|
|
516
|
+
sensitive,
|
|
517
|
+
strict
|
|
518
|
+
}), regexp = _compilePath.regexp, keys = _compilePath.keys;
|
|
519
|
+
const match = regexp.exec(pathname);
|
|
520
|
+
if (!match) return null;
|
|
521
|
+
const url = match[0], values = match.slice(1);
|
|
522
|
+
const isExact = pathname === url;
|
|
523
|
+
if (exact && !isExact) return null;
|
|
524
|
+
return {
|
|
525
|
+
// the matched portion of the URL
|
|
526
|
+
isExact,
|
|
527
|
+
// whether or not we matched exactly
|
|
528
|
+
params: keys.reduce(function(memo, key, index) {
|
|
529
|
+
memo[key.name] = values[index];
|
|
530
|
+
return memo;
|
|
531
|
+
}, {}),
|
|
532
|
+
path: path2,
|
|
533
|
+
// the path used to match
|
|
534
|
+
url: path2 === "/" && url === "" ? "/" : url
|
|
535
|
+
};
|
|
536
|
+
}, null);
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
// src/api/plugins/ReferrerRequestPlugin.ts
|
|
540
|
+
var REFERRER_PAYLOAD_NAME = "referrer";
|
|
541
|
+
var REFERRER_ENDPOINTS = {
|
|
542
|
+
delete: [],
|
|
543
|
+
get: [],
|
|
544
|
+
patch: [],
|
|
545
|
+
post: ["/api/email_registration", "/api/phone_registration", "/api/auth/registration"],
|
|
546
|
+
put: []
|
|
547
|
+
};
|
|
548
|
+
var ReferrerRequestPlugin = class {
|
|
549
|
+
constructor() {
|
|
550
|
+
this.pluginType = "request";
|
|
551
|
+
this.pluginName = "referrerRequestPlugin";
|
|
552
|
+
}
|
|
553
|
+
// требуется публичный метод, а для внутренней реализации может понадобиться this
|
|
554
|
+
// eslint-disable-next-line @typescript-eslint/class-methods-use-this
|
|
555
|
+
execute(config) {
|
|
556
|
+
return new Promise((resolve) => {
|
|
557
|
+
const referrer = String(window.__fox_referrer__);
|
|
558
|
+
if (!referrer) {
|
|
559
|
+
resolve(config);
|
|
560
|
+
}
|
|
561
|
+
config.params = __spreadProps(__spreadValues({}, config.params), {
|
|
562
|
+
[REFERRER_PAYLOAD_NAME]: referrer
|
|
563
|
+
});
|
|
564
|
+
resolve(config);
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
// требуется публичный метод, а для внутренней реализации может понадобиться this
|
|
568
|
+
// eslint-disable-next-line @typescript-eslint/class-methods-use-this
|
|
569
|
+
getEndpoints() {
|
|
570
|
+
return REFERRER_ENDPOINTS;
|
|
571
|
+
}
|
|
572
|
+
isApplicable(config) {
|
|
573
|
+
var _a;
|
|
574
|
+
const { method, url: pathUrl = "" } = config;
|
|
575
|
+
const endpointMethod = method ? method : "post";
|
|
576
|
+
const endpoints = this.getEndpoints();
|
|
577
|
+
const referrerURLs = (_a = endpoints[endpointMethod]) != null ? _a : [];
|
|
578
|
+
return referrerURLs.some((url) => url === pathUrl || pathUrl && matchPath(pathUrl, { exact: true, path: url })) || config.withReferrer === true;
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
// src/api/index.ts
|
|
583
|
+
var referrerRequestPlugin = new ReferrerRequestPlugin();
|
|
584
|
+
var camelizeRequestPlugin = new CamelizeRequestPlugin();
|
|
585
|
+
var dataLayerEventDispatcherPlugin = new DataLayerEventDispatcherPlugin();
|
|
586
|
+
var defaultPlugins = [
|
|
587
|
+
camelizeRequestPlugin,
|
|
588
|
+
referrerRequestPlugin,
|
|
589
|
+
dataLayerEventDispatcherPlugin
|
|
590
|
+
];
|
|
591
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
592
|
+
0 && (module.exports = {
|
|
593
|
+
CamelizeRequestPlugin,
|
|
594
|
+
CaptchaPlugin,
|
|
595
|
+
ReferrerRequestPlugin,
|
|
596
|
+
apiBaseConfig,
|
|
597
|
+
apiConfig,
|
|
598
|
+
defaultPlugins
|
|
599
|
+
});
|
package/api.d.cts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { RequestPlugin, ApiRequestConfigExtended, ApiInstance, ApiConfig, CaptchaConfig, ResponseFailPlugin, CaptchaService, ApiErrorExtended, RequestPluginInterface, ResponseSuccessPluginInterface } from '@foxford/services';
|
|
2
|
+
import { FoxfordAntibotConfig } from './antibot.cjs';
|
|
3
|
+
|
|
4
|
+
declare const apiBaseConfig: {
|
|
5
|
+
headers: {
|
|
6
|
+
'X-Requested-With': string;
|
|
7
|
+
};
|
|
8
|
+
withXSRFToken: boolean;
|
|
9
|
+
xsrfCookieName: string;
|
|
10
|
+
xsrfHeaderName: string;
|
|
11
|
+
};
|
|
12
|
+
declare const apiConfig: {
|
|
13
|
+
withCredentials: boolean;
|
|
14
|
+
headers: {
|
|
15
|
+
'X-Requested-With': string;
|
|
16
|
+
};
|
|
17
|
+
withXSRFToken: boolean;
|
|
18
|
+
xsrfCookieName: string;
|
|
19
|
+
xsrfHeaderName: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
declare class CamelizeRequestPlugin implements RequestPlugin {
|
|
23
|
+
pluginType: "request";
|
|
24
|
+
pluginName: string;
|
|
25
|
+
execute(config: ApiRequestConfigExtended, instance: ApiInstance): Promise<ApiRequestConfigExtended>;
|
|
26
|
+
isApplicable(config: ApiRequestConfigExtended): boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type WidgetsInitConfig = {
|
|
30
|
+
version?: 'latest' | string;
|
|
31
|
+
locale?: 'ru';
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type FoxfordConfig = {
|
|
35
|
+
host?: string;
|
|
36
|
+
/** @deprecated */
|
|
37
|
+
widgetsVersion?: 'latest' | string;
|
|
38
|
+
antibot?: boolean;
|
|
39
|
+
antibotConfig?: FoxfordAntibotConfig;
|
|
40
|
+
api?: ApiConfig;
|
|
41
|
+
captchaConfig?: () => CaptchaConfig;
|
|
42
|
+
/** @deprecated Не используйте инициализацию виджетов через SDK */
|
|
43
|
+
widgetsConfig?: WidgetsInitConfig;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
declare class CaptchaPlugin implements ResponseFailPlugin {
|
|
47
|
+
pluginType: "responseFail";
|
|
48
|
+
pluginName: string;
|
|
49
|
+
captchaConfig: FoxfordConfig['captchaConfig'];
|
|
50
|
+
captcha?: CaptchaService;
|
|
51
|
+
constructor(captchaConfig: FoxfordConfig['captchaConfig']);
|
|
52
|
+
execute(error: ApiErrorExtended): Promise<ApiErrorExtended | ApiRequestConfigExtended>;
|
|
53
|
+
isApplicable(error: ApiErrorExtended): boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type ReferrerEndpointMethod = 'delete' | 'get' | 'patch' | 'post' | 'put';
|
|
57
|
+
type ReferrerEndpointsType = Record<ReferrerEndpointMethod, string[]>;
|
|
58
|
+
declare class ReferrerRequestPlugin implements RequestPlugin {
|
|
59
|
+
pluginType: "request";
|
|
60
|
+
pluginName: string;
|
|
61
|
+
execute(config: ApiRequestConfigExtended): Promise<ApiRequestConfigExtended>;
|
|
62
|
+
getEndpoints(): ReferrerEndpointsType;
|
|
63
|
+
isApplicable(config: ApiRequestConfigExtended): boolean;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
declare const defaultPlugins: Array<RequestPluginInterface | ResponseSuccessPluginInterface>;
|
|
67
|
+
|
|
68
|
+
export { CamelizeRequestPlugin, CaptchaPlugin, ReferrerRequestPlugin, apiBaseConfig, apiConfig, defaultPlugins };
|