@8ms/helpers 1.1.109 → 1.1.111
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.
|
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const post_1 = __importDefault(require("../../axios/post"));
|
|
7
7
|
global.deepcrawlApi = {
|
|
8
|
-
lastUpdated: null,
|
|
9
8
|
token: null,
|
|
9
|
+
updatedAt: null,
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
12
|
* http://api-docs.deepcrawl.com/
|
|
@@ -26,7 +26,10 @@ const initClient = async ({ auth }) => {
|
|
|
26
26
|
url: `https://api.deepcrawl.com/sessions`,
|
|
27
27
|
});
|
|
28
28
|
// Ensure the value exists
|
|
29
|
-
const token = apiResponse.getBodyDefaultTo({
|
|
29
|
+
const token = apiResponse.getBodyDefaultTo({
|
|
30
|
+
defaultValue: null,
|
|
31
|
+
keys: ['token'],
|
|
32
|
+
});
|
|
30
33
|
if (token) {
|
|
31
34
|
global.deepcrawlApi.token = token;
|
|
32
35
|
}
|
|
@@ -4,10 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const post_1 = __importDefault(require("../../axios/post"));
|
|
7
|
-
const defaultTo_1 = __importDefault(require("../../util/defaultTo"));
|
|
8
7
|
global.deepcrawlGraphql = {
|
|
9
|
-
lastUpdated: null,
|
|
10
8
|
token: null,
|
|
9
|
+
updatedAt: null,
|
|
11
10
|
};
|
|
12
11
|
/**
|
|
13
12
|
* https://graph-docs.deepcrawl.com/graphql/explorer/
|
|
@@ -26,10 +25,9 @@ const initClient = async ({ auth }) => {
|
|
|
26
25
|
},
|
|
27
26
|
url: `https://graph.deepcrawl.com/`,
|
|
28
27
|
});
|
|
29
|
-
const token =
|
|
28
|
+
const token = apiResponse.getBodyDefaultTo({
|
|
30
29
|
defaultValue: null,
|
|
31
|
-
|
|
32
|
-
keys: ['data', 'data', 'createSessionUsingUserKey', 'token'],
|
|
30
|
+
keys: ['data', 'createSessionUsingUserKey', 'token'],
|
|
33
31
|
});
|
|
34
32
|
// Ensure the value exists
|
|
35
33
|
if (token) {
|
package/package.json
CHANGED
package/util/defaultTo.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const isObject_1 = __importDefault(require("lodash/isObject"));
|
|
6
7
|
const getArray_1 = __importDefault(require("../array/getArray"));
|
|
7
8
|
/**
|
|
8
9
|
* Function to default to a value, whilst filtering through an instance
|
|
@@ -11,8 +12,8 @@ const defaultTo = ({ defaultValue, instance, keys }) => {
|
|
|
11
12
|
const keysArray = (0, getArray_1.default)({ input: keys });
|
|
12
13
|
let found = true;
|
|
13
14
|
let pointer = instance;
|
|
14
|
-
// Instance is undefined
|
|
15
|
-
if (undefined === instance) {
|
|
15
|
+
// Instance is undefined or is null
|
|
16
|
+
if (undefined === instance || null === pointer) {
|
|
16
17
|
found = false;
|
|
17
18
|
}
|
|
18
19
|
// Instance exists
|
|
@@ -20,12 +21,17 @@ const defaultTo = ({ defaultValue, instance, keys }) => {
|
|
|
20
21
|
keysArray.forEach(key => {
|
|
21
22
|
if (found) {
|
|
22
23
|
// Sub key doesn't exist
|
|
23
|
-
if (
|
|
24
|
-
|
|
24
|
+
if ((0, isObject_1.default)(pointer)) {
|
|
25
|
+
if (undefined === pointer[key] || null === pointer[key]) {
|
|
26
|
+
found = false;
|
|
27
|
+
}
|
|
28
|
+
// Sub key exists, update pointer
|
|
29
|
+
else {
|
|
30
|
+
pointer = pointer[key];
|
|
31
|
+
}
|
|
25
32
|
}
|
|
26
|
-
// Sub key exists, update pointer
|
|
27
33
|
else {
|
|
28
|
-
|
|
34
|
+
found = false;
|
|
29
35
|
}
|
|
30
36
|
}
|
|
31
37
|
});
|