@8ms/helpers 1.1.105 → 1.1.108
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/ApiResponse.d.ts +2 -1
- package/api/ApiResponse.js +2 -1
- package/aws/s3/writeUrlContents.js +4 -7
- package/axios/get.d.ts +4 -4
- package/axios/get.js +24 -35
- package/axios/post.d.ts +1 -4
- package/axios/post.js +21 -35
- package/deepcrawl/api/getData.d.ts +2 -2
- package/deepcrawl/api/getData.js +2 -13
- package/deepcrawl/api/initClient.js +3 -2
- package/deepcrawl/graphql/getData.js +2 -10
- package/eskimi/{request.d.ts → getData.d.ts} +2 -2
- package/eskimi/{request.js → getData.js} +3 -4
- package/littleWarden/getUrlStatus.js +1 -1
- package/myTarget/request.d.ts +2 -1
- package/myTarget/request.js +0 -1
- package/package.json +1 -1
- package/snapchat/getAccessToken.js +5 -7
package/api/ApiResponse.d.ts
CHANGED
package/api/ApiResponse.js
CHANGED
|
@@ -3,18 +3,15 @@ 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
|
|
6
|
+
const axios_1 = __importDefault(require("axios"));
|
|
7
7
|
const writeFile_1 = __importDefault(require("./writeFile"));
|
|
8
8
|
/**
|
|
9
9
|
* Download a file and write to S3.
|
|
10
10
|
*/
|
|
11
11
|
const writeUrlContents = async ({ bucket, key, url }) => {
|
|
12
|
-
return (0,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
responseEncoding: "binary",
|
|
16
|
-
},
|
|
17
|
-
url,
|
|
12
|
+
return (0, axios_1.default)(url, {
|
|
13
|
+
responseType: "arraybuffer",
|
|
14
|
+
responseEncoding: "binary",
|
|
18
15
|
})
|
|
19
16
|
.then(async (response) => {
|
|
20
17
|
await (0, writeFile_1.default)({
|
package/axios/get.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import ApiResponse from '../api/ApiResponse';
|
|
2
2
|
export declare type Get = {
|
|
3
3
|
config?: object;
|
|
4
|
-
onError?: Function;
|
|
5
|
-
onSuccess?: Function;
|
|
6
|
-
returnApiResponse?: boolean;
|
|
7
4
|
url: string;
|
|
8
5
|
};
|
|
9
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Make a GET request.
|
|
8
|
+
*/
|
|
9
|
+
declare const get: ({ config, url }: Get) => Promise<ApiResponse>;
|
|
10
10
|
export default get;
|
package/axios/get.js
CHANGED
|
@@ -5,45 +5,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const axios_1 = __importDefault(require("axios"));
|
|
7
7
|
const ApiResponse_1 = __importDefault(require("../api/ApiResponse"));
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Make a GET request.
|
|
10
|
+
*/
|
|
11
|
+
const get = async ({ config = {}, url }) => {
|
|
12
|
+
const response = await axios_1.default.get(url, config)
|
|
11
13
|
.then(async (response) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// Success return the body
|
|
16
|
-
if (states_1.default.SUCCESS === response.data.state) {
|
|
17
|
-
return onSuccess ? await onSuccess(response.data.body) : response.data.body;
|
|
18
|
-
}
|
|
19
|
-
// Error
|
|
20
|
-
else {
|
|
21
|
-
if (onError) {
|
|
22
|
-
return await onError(response.data.error);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
throw new Error(response.data.error);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
return onSuccess ? await onSuccess(response) : response;
|
|
31
|
-
}
|
|
14
|
+
// Is API response
|
|
15
|
+
if (undefined !== response.data.body && undefined !== response.data.error && undefined !== response.data.state) {
|
|
16
|
+
return new ApiResponse_1.default(response.data);
|
|
32
17
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
throw Error;
|
|
18
|
+
// General success
|
|
19
|
+
else if (200 === response.status) {
|
|
20
|
+
return (new ApiResponse_1.default()).setToSuccess({
|
|
21
|
+
body: response.data,
|
|
22
|
+
});
|
|
41
23
|
}
|
|
24
|
+
// Error
|
|
25
|
+
return (new ApiResponse_1.default()).setToError({
|
|
26
|
+
body: response.data,
|
|
27
|
+
error: response.statusText,
|
|
28
|
+
});
|
|
29
|
+
})
|
|
30
|
+
.catch(error => {
|
|
31
|
+
// Error
|
|
32
|
+
return (new ApiResponse_1.default()).setToError({
|
|
33
|
+
error: error.message,
|
|
34
|
+
});
|
|
42
35
|
});
|
|
43
|
-
// Convert the response into an ApiResponse instance
|
|
44
|
-
if (returnApiResponse) {
|
|
45
|
-
response = new ApiResponse_1.default(response);
|
|
46
|
-
}
|
|
47
36
|
return response;
|
|
48
37
|
};
|
|
49
38
|
exports.default = get;
|
package/axios/post.d.ts
CHANGED
|
@@ -2,13 +2,10 @@ import ApiResponse from '../api/ApiResponse';
|
|
|
2
2
|
export declare type Post = {
|
|
3
3
|
config?: object;
|
|
4
4
|
data?: object;
|
|
5
|
-
onError?: Function;
|
|
6
|
-
onSuccess?: Function;
|
|
7
|
-
returnApiResponse?: boolean;
|
|
8
5
|
url: string;
|
|
9
6
|
};
|
|
10
7
|
/**
|
|
11
8
|
* Make a POST request.
|
|
12
9
|
*/
|
|
13
|
-
declare const post: ({ config, data,
|
|
10
|
+
declare const post: ({ config, data, url }: Post) => Promise<ApiResponse>;
|
|
14
11
|
export default post;
|
package/axios/post.js
CHANGED
|
@@ -5,48 +5,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const axios_1 = __importDefault(require("axios"));
|
|
7
7
|
const ApiResponse_1 = __importDefault(require("../api/ApiResponse"));
|
|
8
|
-
const states_1 = __importDefault(require("../api/states"));
|
|
9
8
|
/**
|
|
10
9
|
* Make a POST request.
|
|
11
10
|
*/
|
|
12
|
-
const post = async ({ config = {}, data = {},
|
|
13
|
-
|
|
11
|
+
const post = async ({ config = {}, data = {}, url }) => {
|
|
12
|
+
const response = await axios_1.default.post(url, data, config)
|
|
14
13
|
.then(async (response) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// Success return the body
|
|
19
|
-
if (states_1.default.SUCCESS === response.data.state) {
|
|
20
|
-
return onSuccess ? await onSuccess(response.data.body) : response.data.body;
|
|
21
|
-
}
|
|
22
|
-
// Error
|
|
23
|
-
else {
|
|
24
|
-
if (onError) {
|
|
25
|
-
return await onError(response.data.error);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
throw new Error(response.data.error);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
return onSuccess ? await onSuccess(response) : response;
|
|
34
|
-
}
|
|
14
|
+
// Is API response
|
|
15
|
+
if (undefined !== response.data.body && undefined !== response.data.error && undefined !== response.data.state) {
|
|
16
|
+
return new ApiResponse_1.default(response.data);
|
|
35
17
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
throw Error;
|
|
18
|
+
// General success
|
|
19
|
+
else if (200 === response.status) {
|
|
20
|
+
return (new ApiResponse_1.default()).setToSuccess({
|
|
21
|
+
body: response.data,
|
|
22
|
+
});
|
|
44
23
|
}
|
|
24
|
+
// Error
|
|
25
|
+
return (new ApiResponse_1.default()).setToError({
|
|
26
|
+
body: response.data,
|
|
27
|
+
error: response.statusText,
|
|
28
|
+
});
|
|
29
|
+
})
|
|
30
|
+
.catch(error => {
|
|
31
|
+
// Error
|
|
32
|
+
return (new ApiResponse_1.default()).setToError({
|
|
33
|
+
error: error.message,
|
|
34
|
+
});
|
|
45
35
|
});
|
|
46
|
-
// Convert the response into an ApiResponse instance
|
|
47
|
-
if (returnApiResponse) {
|
|
48
|
-
response = new ApiResponse_1.default(response);
|
|
49
|
-
}
|
|
50
36
|
return response;
|
|
51
37
|
};
|
|
52
38
|
exports.default = post;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import ApiResponse from '../../api/ApiResponse';
|
|
2
2
|
declare type GetData = {
|
|
3
3
|
url: string;
|
|
4
4
|
};
|
|
5
|
-
declare const getData: ({ url }: GetData) => Promise<
|
|
5
|
+
declare const getData: ({ url }: GetData) => Promise<ApiResponse>;
|
|
6
6
|
export default getData;
|
package/deepcrawl/api/getData.js
CHANGED
|
@@ -3,27 +3,16 @@ 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 response_1 = __importDefault(require("../../api/response"));
|
|
7
|
-
const states_1 = __importDefault(require("../../api/states"));
|
|
8
6
|
const get_1 = __importDefault(require("../../axios/get"));
|
|
9
7
|
const getData = async ({ url }) => {
|
|
10
|
-
|
|
11
|
-
await (0, get_1.default)({
|
|
8
|
+
const apiResponse = await (0, get_1.default)({
|
|
12
9
|
config: {
|
|
13
10
|
headers: {
|
|
14
11
|
'X-AUTH-TOKEN': global.deepcrawlApi.token,
|
|
15
12
|
},
|
|
16
13
|
},
|
|
17
|
-
onError: error => {
|
|
18
|
-
response.state = states_1.default.ERROR;
|
|
19
|
-
response.error = error.message;
|
|
20
|
-
},
|
|
21
|
-
onSuccess: success => {
|
|
22
|
-
response.state = states_1.default.SUCCESS;
|
|
23
|
-
response.body = success.data;
|
|
24
|
-
},
|
|
25
14
|
url,
|
|
26
15
|
});
|
|
27
|
-
return
|
|
16
|
+
return apiResponse;
|
|
28
17
|
};
|
|
29
18
|
exports.default = getData;
|
|
@@ -26,8 +26,9 @@ const initClient = async ({ auth }) => {
|
|
|
26
26
|
url: `https://api.deepcrawl.com/sessions`,
|
|
27
27
|
});
|
|
28
28
|
// Ensure the value exists
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const token = apiResponse.getBodyDefaultTo({ defaultValue: null, keys: ['data', 'token'] });
|
|
30
|
+
if (token) {
|
|
31
|
+
global.deepcrawlApi.token = token;
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
};
|
|
@@ -3,15 +3,13 @@ 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 ApiResponse_1 = __importDefault(require("../../api/ApiResponse"));
|
|
7
6
|
const post_1 = __importDefault(require("../../axios/post"));
|
|
8
7
|
const getData = async ({ query, variables }) => {
|
|
9
|
-
const response = new ApiResponse_1.default();
|
|
10
8
|
let queryClean = query.trim();
|
|
11
9
|
queryClean = queryClean.replace(/\n/g, ' ');
|
|
12
10
|
queryClean = queryClean.replace(/\t/g, ' ');
|
|
13
11
|
queryClean = queryClean.replace(/ /g, ' ');
|
|
14
|
-
await (0, post_1.default)({
|
|
12
|
+
const apiResponse = await (0, post_1.default)({
|
|
15
13
|
config: {
|
|
16
14
|
headers: {
|
|
17
15
|
'x-auth-token': global.deepcrawlGraphql.token,
|
|
@@ -21,14 +19,8 @@ const getData = async ({ query, variables }) => {
|
|
|
21
19
|
query: queryClean,
|
|
22
20
|
variables,
|
|
23
21
|
},
|
|
24
|
-
onError: error => {
|
|
25
|
-
response.setToError({ error: error.message });
|
|
26
|
-
},
|
|
27
|
-
onSuccess: success => {
|
|
28
|
-
response.setToSuccess({ body: success.data });
|
|
29
|
-
},
|
|
30
22
|
url: 'https://graph.deepcrawl.com/',
|
|
31
23
|
});
|
|
32
|
-
return
|
|
24
|
+
return apiResponse;
|
|
33
25
|
};
|
|
34
26
|
exports.default = getData;
|
|
@@ -7,7 +7,7 @@ const post_1 = __importDefault(require("../axios/post"));
|
|
|
7
7
|
/**
|
|
8
8
|
* Make the request to Eskimi API using the access token.
|
|
9
9
|
*/
|
|
10
|
-
const
|
|
10
|
+
const getData = async ({ data, url }) => {
|
|
11
11
|
const response = await (0, post_1.default)({
|
|
12
12
|
config: {
|
|
13
13
|
headers: {
|
|
@@ -16,9 +16,8 @@ const request = async ({ data, url }) => {
|
|
|
16
16
|
},
|
|
17
17
|
},
|
|
18
18
|
data: data,
|
|
19
|
-
onSuccess: response => response.data,
|
|
20
19
|
url: url,
|
|
21
20
|
});
|
|
22
|
-
return response;
|
|
21
|
+
return response.getBodyDefaultTo({ defaultValue: null, keys: ['data'] });
|
|
23
22
|
};
|
|
24
|
-
exports.default =
|
|
23
|
+
exports.default = getData;
|
|
@@ -16,6 +16,6 @@ const getUrlStatus = async ({ apiKey, urlId }) => {
|
|
|
16
16
|
},
|
|
17
17
|
url: `https://littlewarden.com/api/sites/${urlId}`,
|
|
18
18
|
});
|
|
19
|
-
return response.
|
|
19
|
+
return response.getBodyDefaultTo({ defaultValue: {}, keys: ['data', 'site'] });
|
|
20
20
|
};
|
|
21
21
|
exports.default = getUrlStatus;
|
package/myTarget/request.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import ApiResponse from '../api/ApiResponse';
|
|
1
2
|
/**
|
|
2
3
|
* Make the request to MyTarget API using the access token.
|
|
3
4
|
*/
|
|
4
5
|
declare const request: ({ data, url }: {
|
|
5
6
|
data: object;
|
|
6
7
|
url: string;
|
|
7
|
-
}) => Promise<
|
|
8
|
+
}) => Promise<ApiResponse>;
|
|
8
9
|
export default request;
|
package/myTarget/request.js
CHANGED
package/package.json
CHANGED
|
@@ -23,14 +23,12 @@ const getAccessToken = async ({ force, parameterName }) => {
|
|
|
23
23
|
url += `&client_secret=${parameter.clientSecret}`;
|
|
24
24
|
url += `&grant_type=refresh_token`;
|
|
25
25
|
url += `&refresh_token=${parameter.refreshToken}`;
|
|
26
|
-
await (0, post_1.default)({
|
|
27
|
-
|
|
28
|
-
if (undefined !== apiResponse['data']['access_token']) {
|
|
29
|
-
global.snapchatAccessToken = apiResponse['data']['access_token'];
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
url: url,
|
|
26
|
+
const apiResponse = await (0, post_1.default)({
|
|
27
|
+
url,
|
|
33
28
|
});
|
|
29
|
+
if (apiResponse.isSuccess()) {
|
|
30
|
+
global.snapchatAccessToken = apiResponse.getBodyDefaultTo({ defaultValue: null, keys: ['data', 'access_token'] });
|
|
31
|
+
}
|
|
34
32
|
}
|
|
35
33
|
return global.snapchatAccessToken;
|
|
36
34
|
};
|