@foxford/sdk 6.2.0 → 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.js.flow ADDED
@@ -0,0 +1,108 @@
1
+ // @flow
2
+ import {
3
+ RequestPlugin,
4
+ ApiRequestConfigExtended,
5
+ ApiInstance,
6
+ type ApiConfig,
7
+ type CaptchaConfig,
8
+ ResponseFailPlugin,
9
+ CaptchaService,
10
+ ApiErrorExtended,
11
+ RequestPluginInterface,
12
+ ResponseSuccessPluginInterface,
13
+ } from "@foxford/services";
14
+ import { FoxfordAntibotConfig } from "./antibot.js";
15
+ declare var apiBaseConfig: {
16
+ headers: {
17
+ "X-Requested-With": string,
18
+ ...
19
+ },
20
+ withXSRFToken: boolean,
21
+ xsrfCookieName: string,
22
+ xsrfHeaderName: string,
23
+ ...
24
+ };
25
+ declare var apiConfig: {
26
+ withCredentials: boolean,
27
+ headers: {
28
+ "X-Requested-With": string,
29
+ ...
30
+ },
31
+ withXSRFToken: boolean,
32
+ xsrfCookieName: string,
33
+ xsrfHeaderName: string,
34
+ ...
35
+ };
36
+ declare class CamelizeRequestPlugin mixins RequestPlugin {
37
+ pluginType: "request";
38
+ pluginName: string;
39
+ execute(
40
+ config: ApiRequestConfigExtended,
41
+ instance: ApiInstance
42
+ ): Promise<ApiRequestConfigExtended>;
43
+ isApplicable(config: ApiRequestConfigExtended): boolean;
44
+ }
45
+ declare type WidgetsInitConfig = {
46
+ version?: "latest" | string,
47
+ locale?: "ru",
48
+ ...
49
+ };
50
+ declare type FoxfordConfig = {
51
+ host?: string,
52
+
53
+ /**
54
+ * @deprecated
55
+ */
56
+ widgetsVersion?: "latest" | string,
57
+ antibot?: boolean,
58
+ antibotConfig?: FoxfordAntibotConfig,
59
+ api?: ApiConfig,
60
+ captchaConfig?: () => CaptchaConfig,
61
+
62
+ /**
63
+ * @deprecated Не используйте инициализацию виджетов через SDK
64
+ */
65
+ widgetsConfig?: WidgetsInitConfig,
66
+ ...
67
+ };
68
+ declare class CaptchaPlugin mixins ResponseFailPlugin {
69
+ pluginType: "responseFail";
70
+ pluginName: string;
71
+ captchaConfig: $PropertyType<FoxfordConfig, "captchaConfig">;
72
+ captcha?: CaptchaService;
73
+ constructor(
74
+ captchaConfig: $PropertyType<FoxfordConfig, "captchaConfig">
75
+ ): this;
76
+ execute(
77
+ error: ApiErrorExtended
78
+ ): Promise<ApiErrorExtended | ApiRequestConfigExtended>;
79
+ isApplicable(error: ApiErrorExtended): boolean;
80
+ }
81
+ declare type ReferrerEndpointMethod =
82
+ | "delete"
83
+ | "get"
84
+ | "patch"
85
+ | "post"
86
+ | "put";
87
+ declare type ReferrerEndpointsType = {
88
+ [key: ReferrerEndpointMethod]: string[],
89
+ ...
90
+ };
91
+ declare class ReferrerRequestPlugin mixins RequestPlugin {
92
+ pluginType: "request";
93
+ pluginName: string;
94
+ execute(config: ApiRequestConfigExtended): Promise<ApiRequestConfigExtended>;
95
+ getEndpoints(): ReferrerEndpointsType;
96
+ isApplicable(config: ApiRequestConfigExtended): boolean;
97
+ }
98
+ declare var defaultPlugins: Array<
99
+ RequestPluginInterface | ResponseSuccessPluginInterface
100
+ >;
101
+ declare export {
102
+ CamelizeRequestPlugin,
103
+ CaptchaPlugin,
104
+ ReferrerRequestPlugin,
105
+ apiBaseConfig,
106
+ apiConfig,
107
+ defaultPlugins,
108
+ };
package/index.cjs CHANGED
@@ -211,6 +211,79 @@ var CamelizeRequestPlugin = class {
211
211
  }
212
212
  };
213
213
 
214
+ // src/api/plugins/CaptchaPlugin.ts
215
+ var import_services = require("@foxford/services");
216
+ var CaptchaPlugin = class {
217
+ constructor(captchaConfig) {
218
+ this.pluginType = "responseFail";
219
+ this.pluginName = "captchaPlugin";
220
+ this.captchaConfig = captchaConfig;
221
+ }
222
+ // требуется публичный метод, а для внутренней реализации может понадобиться this
223
+ // eslint-disable-next-line complexity
224
+ execute(error) {
225
+ return __async(this, null, function* () {
226
+ var _a, _b;
227
+ try {
228
+ const captchaConfig = typeof this.captchaConfig === "function" ? this.captchaConfig() : this.captchaConfig;
229
+ if (!captchaConfig) return error;
230
+ const { settings = {} } = (_b = (_a = error.response) == null ? void 0 : _a.data) != null ? _b : {};
231
+ const { provider } = settings;
232
+ const siteKey = settings.siteKey || settings.site_key || void 0;
233
+ if (!settings || !provider || !siteKey) return error;
234
+ this.captcha = new import_services.CaptchaService(__spreadProps(__spreadValues({}, captchaConfig), {
235
+ provider,
236
+ sitekey: siteKey
237
+ }));
238
+ const { config } = error;
239
+ const captchaAnswer = yield this.captcha.execute({
240
+ location: config.url,
241
+ method: config.method
242
+ });
243
+ if (captchaAnswer === null || captchaAnswer === void 0 || typeof (captchaAnswer == null ? void 0 : captchaAnswer.captcha_token) !== "string") {
244
+ return config;
245
+ }
246
+ const captchaPayload = {
247
+ verification: {
248
+ settings: {
249
+ token: captchaAnswer.captcha_token
250
+ },
251
+ type: "captcha"
252
+ }
253
+ };
254
+ if (config.method === "get") {
255
+ config.params = __spreadValues(__spreadValues({}, config.params), captchaPayload);
256
+ }
257
+ if (typeof config.data === "string") {
258
+ try {
259
+ let data = JSON.parse(config.data);
260
+ data = __spreadValues(__spreadValues({}, data), captchaPayload);
261
+ config.data = JSON.stringify(data);
262
+ } catch (err) {
263
+ console.error(err);
264
+ }
265
+ } else if (config.data instanceof FormData) {
266
+ const formData = config.data;
267
+ formData.append("verification[settings][token]", captchaPayload.verification.settings.token);
268
+ formData.append("verification[type]", captchaPayload.verification.type);
269
+ config.data = formData;
270
+ } else if (typeof config.data === "object") {
271
+ config.data = __spreadValues(__spreadValues({}, config.data), captchaPayload);
272
+ }
273
+ return config;
274
+ } catch (error2) {
275
+ return error2;
276
+ }
277
+ });
278
+ }
279
+ // требуется публичный метод, а для внутренней реализации может понадобиться this
280
+ // eslint-disable-next-line @typescript-eslint/class-methods-use-this
281
+ isApplicable(error) {
282
+ var _a;
283
+ return ((_a = error.response) == null ? void 0 : _a.status) === 449;
284
+ }
285
+ };
286
+
214
287
  // src/api/plugins/DataLayerEventDispatcherPlugin.ts
215
288
  var DataLayerEventDispatcherPlugin = class {
216
289
  constructor() {
@@ -602,79 +675,6 @@ var defaultPlugins = [
602
675
  dataLayerEventDispatcherPlugin
603
676
  ];
604
677
 
605
- // src/api/plugins/CaptchaPlugin.ts
606
- var import_services = require("@foxford/services");
607
- var CaptchaPlugin = class {
608
- constructor(captchaConfig) {
609
- this.pluginType = "responseFail";
610
- this.pluginName = "captchaPlugin";
611
- this.captchaConfig = captchaConfig;
612
- }
613
- // требуется публичный метод, а для внутренней реализации может понадобиться this
614
- // eslint-disable-next-line complexity
615
- execute(error) {
616
- return __async(this, null, function* () {
617
- var _a, _b;
618
- try {
619
- const captchaConfig = typeof this.captchaConfig === "function" ? this.captchaConfig() : this.captchaConfig;
620
- if (!captchaConfig) return error;
621
- const { settings = {} } = (_b = (_a = error.response) == null ? void 0 : _a.data) != null ? _b : {};
622
- const { provider } = settings;
623
- const siteKey = settings.siteKey || settings.site_key || void 0;
624
- if (!settings || !provider || !siteKey) return error;
625
- this.captcha = new import_services.CaptchaService(__spreadProps(__spreadValues({}, captchaConfig), {
626
- provider,
627
- sitekey: siteKey
628
- }));
629
- const { config } = error;
630
- const captchaAnswer = yield this.captcha.execute({
631
- location: config.url,
632
- method: config.method
633
- });
634
- if (captchaAnswer === null || captchaAnswer === void 0 || typeof (captchaAnswer == null ? void 0 : captchaAnswer.captcha_token) !== "string") {
635
- return config;
636
- }
637
- const captchaPayload = {
638
- verification: {
639
- settings: {
640
- token: captchaAnswer.captcha_token
641
- },
642
- type: "captcha"
643
- }
644
- };
645
- if (config.method === "get") {
646
- config.params = __spreadValues(__spreadValues({}, config.params), captchaPayload);
647
- }
648
- if (typeof config.data === "string") {
649
- try {
650
- let data = JSON.parse(config.data);
651
- data = __spreadValues(__spreadValues({}, data), captchaPayload);
652
- config.data = JSON.stringify(data);
653
- } catch (err) {
654
- console.error(err);
655
- }
656
- } else if (config.data instanceof FormData) {
657
- const formData = config.data;
658
- formData.append("verification[settings][token]", captchaPayload.verification.settings.token);
659
- formData.append("verification[type]", captchaPayload.verification.type);
660
- config.data = formData;
661
- } else if (typeof config.data === "object") {
662
- config.data = __spreadValues(__spreadValues({}, config.data), captchaPayload);
663
- }
664
- return config;
665
- } catch (error2) {
666
- return error2;
667
- }
668
- });
669
- }
670
- // требуется публичный метод, а для внутренней реализации может понадобиться this
671
- // eslint-disable-next-line @typescript-eslint/class-methods-use-this
672
- isApplicable(error) {
673
- var _a;
674
- return ((_a = error.response) == null ? void 0 : _a.status) === 449;
675
- }
676
- };
677
-
678
678
  // src/api-plugins.ts
679
679
  var getPlugins = (config, captchaConfig) => {
680
680
  const apiPlugins = config.plugins || [];
package/index.js CHANGED
@@ -159,6 +159,79 @@ var CamelizeRequestPlugin = class {
159
159
  }
160
160
  };
161
161
 
162
+ // src/api/plugins/CaptchaPlugin.ts
163
+ import { CaptchaService } from "@foxford/services";
164
+ var CaptchaPlugin = class {
165
+ constructor(captchaConfig) {
166
+ this.pluginType = "responseFail";
167
+ this.pluginName = "captchaPlugin";
168
+ this.captchaConfig = captchaConfig;
169
+ }
170
+ // требуется публичный метод, а для внутренней реализации может понадобиться this
171
+ // eslint-disable-next-line complexity
172
+ execute(error) {
173
+ return __async(this, null, function* () {
174
+ var _a, _b;
175
+ try {
176
+ const captchaConfig = typeof this.captchaConfig === "function" ? this.captchaConfig() : this.captchaConfig;
177
+ if (!captchaConfig) return error;
178
+ const { settings = {} } = (_b = (_a = error.response) == null ? void 0 : _a.data) != null ? _b : {};
179
+ const { provider } = settings;
180
+ const siteKey = settings.siteKey || settings.site_key || void 0;
181
+ if (!settings || !provider || !siteKey) return error;
182
+ this.captcha = new CaptchaService(__spreadProps(__spreadValues({}, captchaConfig), {
183
+ provider,
184
+ sitekey: siteKey
185
+ }));
186
+ const { config } = error;
187
+ const captchaAnswer = yield this.captcha.execute({
188
+ location: config.url,
189
+ method: config.method
190
+ });
191
+ if (captchaAnswer === null || captchaAnswer === void 0 || typeof (captchaAnswer == null ? void 0 : captchaAnswer.captcha_token) !== "string") {
192
+ return config;
193
+ }
194
+ const captchaPayload = {
195
+ verification: {
196
+ settings: {
197
+ token: captchaAnswer.captcha_token
198
+ },
199
+ type: "captcha"
200
+ }
201
+ };
202
+ if (config.method === "get") {
203
+ config.params = __spreadValues(__spreadValues({}, config.params), captchaPayload);
204
+ }
205
+ if (typeof config.data === "string") {
206
+ try {
207
+ let data = JSON.parse(config.data);
208
+ data = __spreadValues(__spreadValues({}, data), captchaPayload);
209
+ config.data = JSON.stringify(data);
210
+ } catch (err) {
211
+ console.error(err);
212
+ }
213
+ } else if (config.data instanceof FormData) {
214
+ const formData = config.data;
215
+ formData.append("verification[settings][token]", captchaPayload.verification.settings.token);
216
+ formData.append("verification[type]", captchaPayload.verification.type);
217
+ config.data = formData;
218
+ } else if (typeof config.data === "object") {
219
+ config.data = __spreadValues(__spreadValues({}, config.data), captchaPayload);
220
+ }
221
+ return config;
222
+ } catch (error2) {
223
+ return error2;
224
+ }
225
+ });
226
+ }
227
+ // требуется публичный метод, а для внутренней реализации может понадобиться this
228
+ // eslint-disable-next-line @typescript-eslint/class-methods-use-this
229
+ isApplicable(error) {
230
+ var _a;
231
+ return ((_a = error.response) == null ? void 0 : _a.status) === 449;
232
+ }
233
+ };
234
+
162
235
  // src/api/plugins/DataLayerEventDispatcherPlugin.ts
163
236
  var DataLayerEventDispatcherPlugin = class {
164
237
  constructor() {
@@ -550,79 +623,6 @@ var defaultPlugins = [
550
623
  dataLayerEventDispatcherPlugin
551
624
  ];
552
625
 
553
- // src/api/plugins/CaptchaPlugin.ts
554
- import { CaptchaService } from "@foxford/services";
555
- var CaptchaPlugin = class {
556
- constructor(captchaConfig) {
557
- this.pluginType = "responseFail";
558
- this.pluginName = "captchaPlugin";
559
- this.captchaConfig = captchaConfig;
560
- }
561
- // требуется публичный метод, а для внутренней реализации может понадобиться this
562
- // eslint-disable-next-line complexity
563
- execute(error) {
564
- return __async(this, null, function* () {
565
- var _a, _b;
566
- try {
567
- const captchaConfig = typeof this.captchaConfig === "function" ? this.captchaConfig() : this.captchaConfig;
568
- if (!captchaConfig) return error;
569
- const { settings = {} } = (_b = (_a = error.response) == null ? void 0 : _a.data) != null ? _b : {};
570
- const { provider } = settings;
571
- const siteKey = settings.siteKey || settings.site_key || void 0;
572
- if (!settings || !provider || !siteKey) return error;
573
- this.captcha = new CaptchaService(__spreadProps(__spreadValues({}, captchaConfig), {
574
- provider,
575
- sitekey: siteKey
576
- }));
577
- const { config } = error;
578
- const captchaAnswer = yield this.captcha.execute({
579
- location: config.url,
580
- method: config.method
581
- });
582
- if (captchaAnswer === null || captchaAnswer === void 0 || typeof (captchaAnswer == null ? void 0 : captchaAnswer.captcha_token) !== "string") {
583
- return config;
584
- }
585
- const captchaPayload = {
586
- verification: {
587
- settings: {
588
- token: captchaAnswer.captcha_token
589
- },
590
- type: "captcha"
591
- }
592
- };
593
- if (config.method === "get") {
594
- config.params = __spreadValues(__spreadValues({}, config.params), captchaPayload);
595
- }
596
- if (typeof config.data === "string") {
597
- try {
598
- let data = JSON.parse(config.data);
599
- data = __spreadValues(__spreadValues({}, data), captchaPayload);
600
- config.data = JSON.stringify(data);
601
- } catch (err) {
602
- console.error(err);
603
- }
604
- } else if (config.data instanceof FormData) {
605
- const formData = config.data;
606
- formData.append("verification[settings][token]", captchaPayload.verification.settings.token);
607
- formData.append("verification[type]", captchaPayload.verification.type);
608
- config.data = formData;
609
- } else if (typeof config.data === "object") {
610
- config.data = __spreadValues(__spreadValues({}, config.data), captchaPayload);
611
- }
612
- return config;
613
- } catch (error2) {
614
- return error2;
615
- }
616
- });
617
- }
618
- // требуется публичный метод, а для внутренней реализации может понадобиться this
619
- // eslint-disable-next-line @typescript-eslint/class-methods-use-this
620
- isApplicable(error) {
621
- var _a;
622
- return ((_a = error.response) == null ? void 0 : _a.status) === 449;
623
- }
624
- };
625
-
626
626
  // src/api-plugins.ts
627
627
  var getPlugins = (config, captchaConfig) => {
628
628
  const apiPlugins = config.plugins || [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foxford/sdk",
3
- "version": "6.2.0",
3
+ "version": "7.0.0",
4
4
  "description": "Foxford sdk for external projects",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -26,7 +26,7 @@
26
26
  "decamelize-keys-deep": "^0.1.1",
27
27
  "js-levenshtein": "^1.1.6",
28
28
  "lodash": "^4.18.1",
29
- "@foxford/services": "2.0.1",
29
+ "@foxford/services": "2.1.0",
30
30
  "@foxford/types": "1.2.1"
31
31
  },
32
32
  "main": "./index.cjs",
@@ -44,6 +44,12 @@
44
44
  "require": "./antibot.cjs",
45
45
  "types": "./antibot.d.ts"
46
46
  },
47
+ "./api": {
48
+ "flowTypes": "./api.js.flow",
49
+ "import": "./api.js",
50
+ "require": "./api.cjs",
51
+ "types": "./api.d.ts"
52
+ },
47
53
  "./entities": {
48
54
  "flowTypes": "./entities.js.flow",
49
55
  "import": "./entities.js",
@@ -70,6 +76,11 @@
70
76
  "antibot.d.ts",
71
77
  "antibot.js",
72
78
  "antibot.js.flow",
79
+ "api.cjs",
80
+ "api.d.cts",
81
+ "api.d.ts",
82
+ "api.js",
83
+ "api.js.flow",
73
84
  "entities.cjs",
74
85
  "entities.d.cts",
75
86
  "entities.d.ts",
@@ -83,6 +94,6 @@
83
94
  "package.json",
84
95
  "plugins"
85
96
  ],
86
- "sha": "234f85e",
97
+ "sha": "70cdd11",
87
98
  "scripts": {}
88
99
  }