@empathyco/x-adapter 8.0.0-alpha.4 → 8.0.0-alpha.5
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/dist/cjs/http-clients/index.js +0 -1
- package/dist/cjs/http-clients/index.js.map +1 -1
- package/dist/esm/http-clients/index.js +0 -1
- package/dist/esm/http-clients/index.js.map +1 -1
- package/dist/types/http-clients/index.d.ts +0 -1
- package/package.json +2 -2
- package/dist/cjs/http-clients/beacon.http-client.js +0 -61
- package/dist/cjs/http-clients/beacon.http-client.js.map +0 -1
- package/dist/esm/http-clients/beacon.http-client.js +0 -57
- package/dist/esm/http-clients/beacon.http-client.js.map +0 -1
- package/dist/types/http-clients/beacon.http-client.d.ts +0 -14
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./fetch.http-client"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./beacon.http-client"), exports);
|
|
6
5
|
tslib_1.__exportStar(require("./types"), exports);
|
|
7
6
|
tslib_1.__exportStar(require("./utils"), exports);
|
|
8
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/http-clients/index.ts"],"names":[],"mappings":";;;AAAA,8DAAoC;AACpC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/http-clients/index.ts"],"names":[],"mappings":";;;AAAA,8DAAoC;AACpC,kDAAwB;AACxB,kDAAwB","sourcesContent":["export * from './fetch.http-client';\nexport * from './types';\nexport * from './utils';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/http-clients/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/http-clients/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC","sourcesContent":["export * from './fetch.http-client';\nexport * from './types';\nexport * from './utils';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empathyco/x-adapter",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.5",
|
|
4
4
|
"description": "A utils library to create a client for any API",
|
|
5
5
|
"author": "Empathy Systems Corporation S.L.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "0687f98044c987babc41bb8109b6550f0a9985a1"
|
|
52
52
|
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.beaconHttpClient = void 0;
|
|
4
|
-
const x_utils_1 = require("@empathyco/x-utils");
|
|
5
|
-
const utils_1 = require("./utils");
|
|
6
|
-
/**
|
|
7
|
-
* Flag determining if the user has an ad-blocker installed.
|
|
8
|
-
*/
|
|
9
|
-
let hasAdBlocker = undefined;
|
|
10
|
-
/**
|
|
11
|
-
* The `beaconHttpClient()` function is a http client implementation using the WebAPI
|
|
12
|
-
* `navigator.sendBeacon`.
|
|
13
|
-
*
|
|
14
|
-
* @remarks As a `navigation.sendBeacon` request might be cancelled by an ad-blocker, the function
|
|
15
|
-
* firstly checks if an ad-blocker is installed. In case it is, the `fetch` API is used as fallback.
|
|
16
|
-
*
|
|
17
|
-
* @param endpoint - The endpoint to make the request to.
|
|
18
|
-
* @param options - The request options.
|
|
19
|
-
*
|
|
20
|
-
* @public
|
|
21
|
-
*/
|
|
22
|
-
const beaconHttpClient = async (endpoint, { parameters = {}, properties } = {}) => {
|
|
23
|
-
const url = (0, utils_1.buildUrl)(endpoint, (0, x_utils_1.flatObject)(parameters));
|
|
24
|
-
if (hasAdBlocker === undefined) {
|
|
25
|
-
try {
|
|
26
|
-
const response = await detectAdBlocker();
|
|
27
|
-
// The Promise returned from fetch() won't reject on HTTP error status even if the response is
|
|
28
|
-
// an HTTP 404 or 500. Instead, it will resolve normally (with ok status set to false), and it
|
|
29
|
-
// will only reject on network failure or if anything prevented the request from completing.
|
|
30
|
-
// eslint-disable-next-line require-atomic-updates
|
|
31
|
-
hasAdBlocker = !response.ok;
|
|
32
|
-
}
|
|
33
|
-
catch (_error) {
|
|
34
|
-
// eslint-disable-next-line require-atomic-updates
|
|
35
|
-
hasAdBlocker = true;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (hasAdBlocker) {
|
|
39
|
-
return fetch(url, properties);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
navigator.sendBeacon(url);
|
|
43
|
-
return Promise.resolve({});
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
exports.beaconHttpClient = beaconHttpClient;
|
|
47
|
-
/**
|
|
48
|
-
* The `detectAdBlocker()` function checks if the user has an ad-blocker installed.
|
|
49
|
-
*
|
|
50
|
-
* @returns A Promise object. If the `response` is `ok`, no ad-blocker is installed. Otherwise, an
|
|
51
|
-
* ad-blocker is active.
|
|
52
|
-
*
|
|
53
|
-
* @internal
|
|
54
|
-
*/
|
|
55
|
-
function detectAdBlocker() {
|
|
56
|
-
return fetch('https://google.com/pagead/js/adsbygoogle.js', {
|
|
57
|
-
method: 'HEAD',
|
|
58
|
-
mode: 'no-cors'
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
//# sourceMappingURL=beacon.http-client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"beacon.http-client.js","sourceRoot":"","sources":["../../../src/http-clients/beacon.http-client.ts"],"names":[],"mappings":";;;AAAA,gDAAgD;AAEhD,mCAAmC;AAEnC;;GAEG;AACH,IAAI,YAAY,GAAwB,SAAS,CAAC;AAElD;;;;;;;;;;;GAWG;AACI,MAAM,gBAAgB,GAAe,KAAK,EAC/C,QAAQ,EACR,EAAE,UAAU,GAAG,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,EACpC,EAAE;IACF,MAAM,GAAG,GAAG,IAAA,gBAAQ,EAAC,QAAQ,EAAE,IAAA,oBAAU,EAAC,UAAU,CAAC,CAAC,CAAC;IAEvD,IAAI,YAAY,KAAK,SAAS,EAAE;QAC9B,IAAI;YACF,MAAM,QAAQ,GAAG,MAAM,eAAe,EAAE,CAAC;YACzC,8FAA8F;YAC9F,8FAA8F;YAC9F,4FAA4F;YAC5F,kDAAkD;YAClD,YAAY,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;SAC7B;QAAC,OAAO,MAAM,EAAE;YACf,kDAAkD;YAClD,YAAY,GAAG,IAAI,CAAC;SACrB;KACF;IAED,IAAI,YAAY,EAAE;QAChB,OAAO,KAAK,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;KAC/B;SAAM;QACL,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAE1B,OAAO,OAAO,CAAC,OAAO,CAAM,EAAE,CAAC,CAAC;KACjC;AACH,CAAC,CAAC;AA3BW,QAAA,gBAAgB,oBA2B3B;AAEF;;;;;;;GAOG;AACH,SAAS,eAAe;IACtB,OAAO,KAAK,CAAC,6CAA6C,EAAE;QAC1D,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,SAAS;KAChB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { flatObject } from '@empathyco/x-utils';\nimport { HttpClient } from './types';\nimport { buildUrl } from './utils';\n\n/**\n * Flag determining if the user has an ad-blocker installed.\n */\nlet hasAdBlocker: boolean | undefined = undefined;\n\n/**\n * The `beaconHttpClient()` function is a http client implementation using the WebAPI\n * `navigator.sendBeacon`.\n *\n * @remarks As a `navigation.sendBeacon` request might be cancelled by an ad-blocker, the function\n * firstly checks if an ad-blocker is installed. In case it is, the `fetch` API is used as fallback.\n *\n * @param endpoint - The endpoint to make the request to.\n * @param options - The request options.\n *\n * @public\n */\nexport const beaconHttpClient: HttpClient = async (\n endpoint,\n { parameters = {}, properties } = {}\n) => {\n const url = buildUrl(endpoint, flatObject(parameters));\n\n if (hasAdBlocker === undefined) {\n try {\n const response = await detectAdBlocker();\n // The Promise returned from fetch() won't reject on HTTP error status even if the response is\n // an HTTP 404 or 500. Instead, it will resolve normally (with ok status set to false), and it\n // will only reject on network failure or if anything prevented the request from completing.\n // eslint-disable-next-line require-atomic-updates\n hasAdBlocker = !response.ok;\n } catch (_error) {\n // eslint-disable-next-line require-atomic-updates\n hasAdBlocker = true;\n }\n }\n\n if (hasAdBlocker) {\n return fetch(url, properties);\n } else {\n navigator.sendBeacon(url);\n\n return Promise.resolve<any>({});\n }\n};\n\n/**\n * The `detectAdBlocker()` function checks if the user has an ad-blocker installed.\n *\n * @returns A Promise object. If the `response` is `ok`, no ad-blocker is installed. Otherwise, an\n * ad-blocker is active.\n *\n * @internal\n */\nfunction detectAdBlocker(): Promise<Response> {\n return fetch('https://google.com/pagead/js/adsbygoogle.js', {\n method: 'HEAD',\n mode: 'no-cors'\n });\n}\n"]}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { flatObject } from '@empathyco/x-utils';
|
|
2
|
-
import { buildUrl } from './utils';
|
|
3
|
-
/**
|
|
4
|
-
* Flag determining if the user has an ad-blocker installed.
|
|
5
|
-
*/
|
|
6
|
-
let hasAdBlocker = undefined;
|
|
7
|
-
/**
|
|
8
|
-
* The `beaconHttpClient()` function is a http client implementation using the WebAPI
|
|
9
|
-
* `navigator.sendBeacon`.
|
|
10
|
-
*
|
|
11
|
-
* @remarks As a `navigation.sendBeacon` request might be cancelled by an ad-blocker, the function
|
|
12
|
-
* firstly checks if an ad-blocker is installed. In case it is, the `fetch` API is used as fallback.
|
|
13
|
-
*
|
|
14
|
-
* @param endpoint - The endpoint to make the request to.
|
|
15
|
-
* @param options - The request options.
|
|
16
|
-
*
|
|
17
|
-
* @public
|
|
18
|
-
*/
|
|
19
|
-
export const beaconHttpClient = async (endpoint, { parameters = {}, properties } = {}) => {
|
|
20
|
-
const url = buildUrl(endpoint, flatObject(parameters));
|
|
21
|
-
if (hasAdBlocker === undefined) {
|
|
22
|
-
try {
|
|
23
|
-
const response = await detectAdBlocker();
|
|
24
|
-
// The Promise returned from fetch() won't reject on HTTP error status even if the response is
|
|
25
|
-
// an HTTP 404 or 500. Instead, it will resolve normally (with ok status set to false), and it
|
|
26
|
-
// will only reject on network failure or if anything prevented the request from completing.
|
|
27
|
-
// eslint-disable-next-line require-atomic-updates
|
|
28
|
-
hasAdBlocker = !response.ok;
|
|
29
|
-
}
|
|
30
|
-
catch (_error) {
|
|
31
|
-
// eslint-disable-next-line require-atomic-updates
|
|
32
|
-
hasAdBlocker = true;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
if (hasAdBlocker) {
|
|
36
|
-
return fetch(url, properties);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
navigator.sendBeacon(url);
|
|
40
|
-
return Promise.resolve({});
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* The `detectAdBlocker()` function checks if the user has an ad-blocker installed.
|
|
45
|
-
*
|
|
46
|
-
* @returns A Promise object. If the `response` is `ok`, no ad-blocker is installed. Otherwise, an
|
|
47
|
-
* ad-blocker is active.
|
|
48
|
-
*
|
|
49
|
-
* @internal
|
|
50
|
-
*/
|
|
51
|
-
function detectAdBlocker() {
|
|
52
|
-
return fetch('https://google.com/pagead/js/adsbygoogle.js', {
|
|
53
|
-
method: 'HEAD',
|
|
54
|
-
mode: 'no-cors'
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=beacon.http-client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"beacon.http-client.js","sourceRoot":"","sources":["../../../src/http-clients/beacon.http-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC;;GAEG;AACH,IAAI,YAAY,GAAwB,SAAS,CAAC;AAElD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAe,KAAK,EAC/C,QAAQ,EACR,EAAE,UAAU,GAAG,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,EACpC,EAAE;IACF,MAAM,GAAG,GAAG,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;IAEvD,IAAI,YAAY,KAAK,SAAS,EAAE;QAC9B,IAAI;YACF,MAAM,QAAQ,GAAG,MAAM,eAAe,EAAE,CAAC;YACzC,8FAA8F;YAC9F,8FAA8F;YAC9F,4FAA4F;YAC5F,kDAAkD;YAClD,YAAY,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;SAC7B;QAAC,OAAO,MAAM,EAAE;YACf,kDAAkD;YAClD,YAAY,GAAG,IAAI,CAAC;SACrB;KACF;IAED,IAAI,YAAY,EAAE;QAChB,OAAO,KAAK,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;KAC/B;SAAM;QACL,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAE1B,OAAO,OAAO,CAAC,OAAO,CAAM,EAAE,CAAC,CAAC;KACjC;AACH,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,SAAS,eAAe;IACtB,OAAO,KAAK,CAAC,6CAA6C,EAAE;QAC1D,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,SAAS;KAChB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { flatObject } from '@empathyco/x-utils';\nimport { HttpClient } from './types';\nimport { buildUrl } from './utils';\n\n/**\n * Flag determining if the user has an ad-blocker installed.\n */\nlet hasAdBlocker: boolean | undefined = undefined;\n\n/**\n * The `beaconHttpClient()` function is a http client implementation using the WebAPI\n * `navigator.sendBeacon`.\n *\n * @remarks As a `navigation.sendBeacon` request might be cancelled by an ad-blocker, the function\n * firstly checks if an ad-blocker is installed. In case it is, the `fetch` API is used as fallback.\n *\n * @param endpoint - The endpoint to make the request to.\n * @param options - The request options.\n *\n * @public\n */\nexport const beaconHttpClient: HttpClient = async (\n endpoint,\n { parameters = {}, properties } = {}\n) => {\n const url = buildUrl(endpoint, flatObject(parameters));\n\n if (hasAdBlocker === undefined) {\n try {\n const response = await detectAdBlocker();\n // The Promise returned from fetch() won't reject on HTTP error status even if the response is\n // an HTTP 404 or 500. Instead, it will resolve normally (with ok status set to false), and it\n // will only reject on network failure or if anything prevented the request from completing.\n // eslint-disable-next-line require-atomic-updates\n hasAdBlocker = !response.ok;\n } catch (_error) {\n // eslint-disable-next-line require-atomic-updates\n hasAdBlocker = true;\n }\n }\n\n if (hasAdBlocker) {\n return fetch(url, properties);\n } else {\n navigator.sendBeacon(url);\n\n return Promise.resolve<any>({});\n }\n};\n\n/**\n * The `detectAdBlocker()` function checks if the user has an ad-blocker installed.\n *\n * @returns A Promise object. If the `response` is `ok`, no ad-blocker is installed. Otherwise, an\n * ad-blocker is active.\n *\n * @internal\n */\nfunction detectAdBlocker(): Promise<Response> {\n return fetch('https://google.com/pagead/js/adsbygoogle.js', {\n method: 'HEAD',\n mode: 'no-cors'\n });\n}\n"]}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { HttpClient } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* The `beaconHttpClient()` function is a http client implementation using the WebAPI
|
|
4
|
-
* `navigator.sendBeacon`.
|
|
5
|
-
*
|
|
6
|
-
* @remarks As a `navigation.sendBeacon` request might be cancelled by an ad-blocker, the function
|
|
7
|
-
* firstly checks if an ad-blocker is installed. In case it is, the `fetch` API is used as fallback.
|
|
8
|
-
*
|
|
9
|
-
* @param endpoint - The endpoint to make the request to.
|
|
10
|
-
* @param options - The request options.
|
|
11
|
-
*
|
|
12
|
-
* @public
|
|
13
|
-
*/
|
|
14
|
-
export declare const beaconHttpClient: HttpClient;
|