@8ms/helpers 1.33.2 → 1.35.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/ApiResponse.d.ts +2 -2
- package/api/ApiResponse.js +11 -11
- package/api/index.d.ts +8 -0
- package/api/index.js +12 -0
- package/api/isError.d.ts +2 -2
- package/api/isError.js +3 -6
- package/api/isSuccess.d.ts +1 -1
- package/api/isSuccess.js +3 -6
- package/api/response.d.ts +1 -1
- package/api/response.js +2 -5
- package/aws/s3/listFilesIteratively.d.ts +9 -0
- package/aws/s3/listFilesIteratively.js +44 -0
- package/aws/s3/readBuffer.d.ts +1 -1
- package/aws/s3/readBuffer.js +6 -19
- package/aws/s3/readFile.d.ts +3 -2
- package/aws/s3/readFile.js +13 -10
- package/aws/s3cache/getCache.d.ts +2 -2
- package/aws/s3cache/getCache.js +2 -2
- package/aws/s3cache/index.d.ts +6 -0
- package/aws/s3cache/updateCache.d.ts +1 -1
- package/brightData/webScraperIde/getRealtime.js +5 -5
- package/crud/index.d.ts +6 -0
- package/crud/index.js +10 -0
- package/date/getDate.d.ts +1 -1
- package/date/getDatesBetween.d.ts +1 -1
- package/date/getFinancialYear.d.ts +1 -1
- package/date/getFinancialYear.js +3 -6
- package/date/getFinancialYearToDate.d.ts +1 -1
- package/date/getFinancialYearToYesterday.d.ts +1 -1
- package/date/getFinancialYearWeeks.d.ts +1 -1
- package/date/getFinancialYearWeeks.js +1 -2
- package/date/getLastWeek.d.ts +1 -1
- package/date/getMax.d.ts +1 -1
- package/date/getMin.d.ts +1 -1
- package/date/getMonday.d.ts +3 -3
- package/date/getMonday.js +3 -5
- package/date/getPredefinedTimeframe.d.ts +2 -3
- package/date/getPredefinedTimeframe.js +4 -4
- package/date/getSunday.d.ts +1 -1
- package/date/getThisWeek.d.ts +1 -1
- package/date/getTwoWeeksAgo.d.ts +1 -1
- package/date/getWeeksAgo.d.ts +1 -1
- package/date/index.d.ts +55 -0
- package/date/index.js +36 -0
- package/date/isLastWeek.d.ts +1 -1
- package/date/isThisWeek.d.ts +2 -2
- package/date/isThisWeek.js +1 -1
- package/environment/getEnvironment.d.ts +1 -1
- package/environment/getEnvironment.js +8 -8
- package/environment/index.d.ts +9 -0
- package/environment/index.js +14 -0
- package/environment/isAws.js +2 -5
- package/environment/isDevelopment.js +2 -2
- package/environment/isProduction.js +2 -2
- package/environment/isStaging.js +2 -2
- package/googleAds/keywordPlanner/index.d.ts +238 -0
- package/googleAds/keywordPlanner/index.js +245 -0
- package/{google → googleAds}/keywordPlanner/request.d.ts +1 -3
- package/{google → googleAds}/keywordPlanner/request.js +2 -5
- package/{google → googleAds}/keywordPlanner/response.d.ts +1 -1
- package/littleWarden/index.d.ts +5 -0
- package/littleWarden/index.js +9 -0
- package/littleWarden/isAllGood.js +3 -6
- package/littleWarden/isDanger.js +2 -5
- package/littleWarden/isWarning.js +2 -5
- package/package.json +27 -26
- package/util/promiseChunks.d.ts +10 -0
- package/util/promiseChunks.js +18 -0
- package/webWorker/index.d.ts +5 -0
- package/webWorker/index.js +9 -0
- package/api/states.d.ts +0 -9
- package/api/states.js +0 -10
- package/api/unexpectedError.d.ts +0 -2
- package/api/unexpectedError.js +0 -4
- package/aws/s3cache/cache.d.ts +0 -7
- package/crud/actions.d.ts +0 -8
- package/crud/actions.js +0 -10
- package/date/date.d.ts +0 -4
- package/date/date.js +0 -2
- package/date/duration.d.ts +0 -5
- package/date/duration.js +0 -2
- package/date/durationComparisons.d.ts +0 -5
- package/date/durationComparisons.js +0 -7
- package/date/durations.d.ts +0 -8
- package/date/durations.js +0 -10
- package/date/financialYear.d.ts +0 -4
- package/date/financialYear.js +0 -2
- package/date/financialYearWeek.d.ts +0 -6
- package/date/financialYearWeek.js +0 -2
- package/date/predefinedTimeframes.d.ts +0 -7
- package/date/predefinedTimeframes.js +0 -9
- package/date/timeframe.d.ts +0 -8
- package/date/timeframe.js +0 -2
- package/date/timeframes.d.ts +0 -4
- package/date/timeframes.js +0 -7
- package/environment/environments.d.ts +0 -7
- package/environment/environments.js +0 -8
- package/environment/platforms.d.ts +0 -6
- package/environment/platforms.js +0 -7
- package/google/keywordPlanner/countries.d.ts +0 -222
- package/google/keywordPlanner/countries.js +0 -223
- package/google/keywordPlanner/months.d.ts +0 -16
- package/google/keywordPlanner/months.js +0 -17
- package/google/keywordPlanner/networks.d.ts +0 -6
- package/google/keywordPlanner/networks.js +0 -7
- package/littleWarden/states.d.ts +0 -7
- package/littleWarden/states.js +0 -8
- package/webWorker/states.d.ts +0 -7
- package/webWorker/states.js +0 -8
- /package/aws/s3cache/{cache.js → index.js} +0 -0
- /package/{google → googleAds}/keywordPlanner/response.js +0 -0
package/api/ApiResponse.d.ts
CHANGED
package/api/ApiResponse.js
CHANGED
|
@@ -4,18 +4,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const defaultTo_1 = __importDefault(require("../util/defaultTo"));
|
|
7
|
-
const
|
|
7
|
+
const _1 = require("./");
|
|
8
8
|
/**
|
|
9
9
|
* Class version of the API to enable quicker instances.
|
|
10
10
|
*/
|
|
11
11
|
class ApiResponse {
|
|
12
12
|
constructor({ body, error, state } = {}) {
|
|
13
|
-
this.state =
|
|
13
|
+
this.state = _1.State.IDLE;
|
|
14
14
|
this.body = null;
|
|
15
15
|
this.error = null;
|
|
16
16
|
this.body = body || null;
|
|
17
17
|
this.error = error || null;
|
|
18
|
-
this.state = state ||
|
|
18
|
+
this.state = state || _1.State.IDLE;
|
|
19
19
|
return this;
|
|
20
20
|
}
|
|
21
21
|
fromJson({ input }) {
|
|
@@ -48,34 +48,34 @@ class ApiResponse {
|
|
|
48
48
|
return this.state;
|
|
49
49
|
}
|
|
50
50
|
isError() {
|
|
51
|
-
return this.state ===
|
|
51
|
+
return this.state === _1.State.ERROR;
|
|
52
52
|
}
|
|
53
53
|
isIdle() {
|
|
54
|
-
return this.state ===
|
|
54
|
+
return this.state === _1.State.IDLE;
|
|
55
55
|
}
|
|
56
56
|
isPending() {
|
|
57
|
-
return this.state ===
|
|
57
|
+
return this.state === _1.State.PENDING;
|
|
58
58
|
}
|
|
59
59
|
isSuccess() {
|
|
60
|
-
return this.state ===
|
|
60
|
+
return this.state === _1.State.SUCCESS;
|
|
61
61
|
}
|
|
62
62
|
setToIdle() {
|
|
63
|
-
this.state =
|
|
63
|
+
this.state = _1.State.IDLE;
|
|
64
64
|
return this;
|
|
65
65
|
}
|
|
66
66
|
setToPending() {
|
|
67
|
-
this.state =
|
|
67
|
+
this.state = _1.State.PENDING;
|
|
68
68
|
return this;
|
|
69
69
|
}
|
|
70
70
|
setToError({ body, error }) {
|
|
71
71
|
this.body = body || null;
|
|
72
72
|
this.error = error;
|
|
73
|
-
this.state =
|
|
73
|
+
this.state = _1.State.ERROR;
|
|
74
74
|
return this;
|
|
75
75
|
}
|
|
76
76
|
setToSuccess({ body }) {
|
|
77
77
|
this.body = body;
|
|
78
|
-
this.state =
|
|
78
|
+
this.state = _1.State.SUCCESS;
|
|
79
79
|
return this;
|
|
80
80
|
}
|
|
81
81
|
setBody({ body }) {
|
package/api/index.d.ts
ADDED
package/api/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unexpectedError = exports.State = void 0;
|
|
4
|
+
var State;
|
|
5
|
+
(function (State) {
|
|
6
|
+
State["ERROR"] = "ERROR";
|
|
7
|
+
State["IDLE"] = "IDLE";
|
|
8
|
+
State["PENDING"] = "PENDING";
|
|
9
|
+
State["SUCCESS"] = "SUCCESS";
|
|
10
|
+
State["VALIDATION_ERROR"] = "VALIDATION_ERROR";
|
|
11
|
+
})(State || (exports.State = State = {}));
|
|
12
|
+
exports.unexpectedError = "An unexpected error occurred, please try again.";
|
package/api/isError.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Response } from
|
|
1
|
+
import { Response } from "./response";
|
|
2
2
|
type IsError = {
|
|
3
3
|
response: Response;
|
|
4
4
|
};
|
|
5
|
-
declare const isError: (
|
|
5
|
+
declare const isError: (props: IsError) => boolean;
|
|
6
6
|
export default isError;
|
package/api/isError.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
const isError = (
|
|
8
|
-
return
|
|
3
|
+
const _1 = require("./");
|
|
4
|
+
const isError = (props) => {
|
|
5
|
+
return _1.State.ERROR === props.response.state;
|
|
9
6
|
};
|
|
10
7
|
exports.default = isError;
|
package/api/isSuccess.d.ts
CHANGED
package/api/isSuccess.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
const isSuccess = (
|
|
8
|
-
return
|
|
3
|
+
const _1 = require("./");
|
|
4
|
+
const isSuccess = (props) => {
|
|
5
|
+
return _1.State.SUCCESS === props.response.state;
|
|
9
6
|
};
|
|
10
7
|
exports.default = isSuccess;
|
package/api/response.d.ts
CHANGED
package/api/response.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
3
|
+
const _1 = require("./");
|
|
7
4
|
const response = {
|
|
8
5
|
body: null,
|
|
9
6
|
error: null,
|
|
10
|
-
state:
|
|
7
|
+
state: _1.State.IDLE,
|
|
11
8
|
};
|
|
12
9
|
exports.default = response;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type ListFilesIteratively = {
|
|
2
|
+
bucket: string;
|
|
3
|
+
folder: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Fetch all the files within a given directory recursively
|
|
7
|
+
*/
|
|
8
|
+
declare const listFilesIteratively: (props: ListFilesIteratively) => Promise<string[]>;
|
|
9
|
+
export default listFilesIteratively;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const listFolders_1 = __importDefault(require("./listFolders"));
|
|
7
|
+
const listFiles_1 = __importDefault(require("./listFiles"));
|
|
8
|
+
/**
|
|
9
|
+
* Sub function
|
|
10
|
+
*/
|
|
11
|
+
const iterateFolders = async (props) => {
|
|
12
|
+
let response = [];
|
|
13
|
+
const folders = await (0, listFolders_1.default)({
|
|
14
|
+
bucket: props.bucket,
|
|
15
|
+
folder: props.folder,
|
|
16
|
+
});
|
|
17
|
+
for (let i = 0; i < folders.length; i++) {
|
|
18
|
+
const subFolderFiles = await iterateFolders({
|
|
19
|
+
bucket: props.bucket,
|
|
20
|
+
folder: `${props.folder}/${folders[i]}`,
|
|
21
|
+
});
|
|
22
|
+
const files = await (0, listFiles_1.default)({
|
|
23
|
+
bucket: props.bucket,
|
|
24
|
+
folder: `${props.folder}/${folders[i]}`,
|
|
25
|
+
});
|
|
26
|
+
response = [
|
|
27
|
+
...response,
|
|
28
|
+
...files,
|
|
29
|
+
...subFolderFiles,
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
return response;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Fetch all the files within a given directory recursively
|
|
36
|
+
*/
|
|
37
|
+
const listFilesIteratively = async (props) => {
|
|
38
|
+
const response = await iterateFolders({
|
|
39
|
+
bucket: props.bucket,
|
|
40
|
+
folder: props.folder,
|
|
41
|
+
});
|
|
42
|
+
return response;
|
|
43
|
+
};
|
|
44
|
+
exports.default = listFilesIteratively;
|
package/aws/s3/readBuffer.d.ts
CHANGED
package/aws/s3/readBuffer.js
CHANGED
|
@@ -3,30 +3,17 @@ 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 date_fns_1 = require("date-fns");
|
|
7
6
|
const isResponse200_1 = __importDefault(require("../isResponse200"));
|
|
7
|
+
const readFile_1 = require("./readFile");
|
|
8
8
|
/**
|
|
9
9
|
* Similar function to reading the S3 file, but instead of a text file return a buffer.
|
|
10
10
|
*/
|
|
11
11
|
const readBuffer = async ({ bucket, key }) => {
|
|
12
12
|
let response = {
|
|
13
|
+
...readFile_1.readFileDefault,
|
|
13
14
|
buffer: undefined,
|
|
14
|
-
now: (0, date_fns_1.getUnixTime)(new Date()),
|
|
15
|
-
modified: {
|
|
16
|
-
unix: null,
|
|
17
|
-
vsNow: {
|
|
18
|
-
months: 0,
|
|
19
|
-
days: 0,
|
|
20
|
-
hours: 0,
|
|
21
|
-
minutes: 0,
|
|
22
|
-
},
|
|
23
|
-
vsMidnight: {
|
|
24
|
-
hours: 0,
|
|
25
|
-
minutes: 0,
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
15
|
};
|
|
29
|
-
const { GetObjectCommand } = require(
|
|
16
|
+
const { GetObjectCommand } = require("@aws-sdk/client-s3");
|
|
30
17
|
const apiResponse = await global.awsS3Client.send(new GetObjectCommand({
|
|
31
18
|
Bucket: bucket,
|
|
32
19
|
Key: key,
|
|
@@ -37,11 +24,11 @@ const readBuffer = async ({ bucket, key }) => {
|
|
|
37
24
|
// Store the response
|
|
38
25
|
response.buffer = await new Promise((resolve, reject) => {
|
|
39
26
|
// @ts-ignore
|
|
40
|
-
apiResponse.Body.on(
|
|
27
|
+
apiResponse.Body.on("data", (chunk) => chunks.push(chunk));
|
|
41
28
|
// @ts-ignore
|
|
42
|
-
apiResponse.Body.on(
|
|
29
|
+
apiResponse.Body.on("error", (err) => reject(err));
|
|
43
30
|
// @ts-ignore
|
|
44
|
-
apiResponse.Body.on(
|
|
31
|
+
apiResponse.Body.on("end", () => resolve(Buffer.concat(chunks)));
|
|
45
32
|
});
|
|
46
33
|
}
|
|
47
34
|
else {
|
package/aws/s3/readFile.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { DurationComparison } from "../../date";
|
|
1
2
|
export type Modified = {
|
|
2
3
|
now: number;
|
|
3
4
|
modified: {
|
|
4
5
|
unix: null | number;
|
|
5
|
-
|
|
6
|
+
[DurationComparison.VS_NOW]: {
|
|
6
7
|
months: number;
|
|
7
8
|
days: number;
|
|
8
9
|
hours: number;
|
|
9
10
|
minutes: number;
|
|
10
11
|
};
|
|
11
|
-
|
|
12
|
+
[DurationComparison.VS_MIDNIGHT]: {
|
|
12
13
|
hours: number;
|
|
13
14
|
minutes: number;
|
|
14
15
|
};
|
package/aws/s3/readFile.js
CHANGED
|
@@ -17,18 +17,19 @@ const getStringFromStream_1 = __importDefault(require("../../string/getStringFro
|
|
|
17
17
|
const isResponse200_1 = __importDefault(require("../isResponse200"));
|
|
18
18
|
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
19
19
|
const isFileExists_1 = __importDefault(require("./isFileExists"));
|
|
20
|
+
const date_1 = require("../../date");
|
|
20
21
|
exports.readFileDefault = {
|
|
21
22
|
body: undefined,
|
|
22
23
|
now: undefined,
|
|
23
24
|
modified: {
|
|
24
25
|
unix: null,
|
|
25
|
-
|
|
26
|
+
[date_1.DurationComparison.VS_NOW]: {
|
|
26
27
|
months: 0,
|
|
27
28
|
days: 0,
|
|
28
29
|
hours: 0,
|
|
29
30
|
minutes: 0,
|
|
30
31
|
},
|
|
31
|
-
|
|
32
|
+
[date_1.DurationComparison.VS_MIDNIGHT]: {
|
|
32
33
|
hours: 0,
|
|
33
34
|
minutes: 0,
|
|
34
35
|
},
|
|
@@ -49,7 +50,7 @@ const readFile = async ({ bucket, key, isJson }) => {
|
|
|
49
50
|
});
|
|
50
51
|
// Only fetch the file if it exists
|
|
51
52
|
if (doesFileExist) {
|
|
52
|
-
const { GetObjectCommand } = require(
|
|
53
|
+
const { GetObjectCommand } = require("@aws-sdk/client-s3");
|
|
53
54
|
const apiResponse = await global.awsS3Client.send(new GetObjectCommand({
|
|
54
55
|
Bucket: bucket,
|
|
55
56
|
Key: key,
|
|
@@ -60,15 +61,17 @@ const readFile = async ({ bucket, key, isJson }) => {
|
|
|
60
61
|
// Convert the date to unix
|
|
61
62
|
response.modified.unix = (0, date_fns_7.getUnixTime)(modified);
|
|
62
63
|
// Compare now to unix
|
|
63
|
-
response.modified.
|
|
64
|
-
response.modified.
|
|
65
|
-
response.modified.
|
|
66
|
-
response.modified.
|
|
64
|
+
response.modified[date_1.DurationComparison.VS_NOW].months = (0, date_fns_4.differenceInMonths)(now, modified);
|
|
65
|
+
response.modified[date_1.DurationComparison.VS_NOW].days = (0, date_fns_1.differenceInDays)(now, modified);
|
|
66
|
+
response.modified[date_1.DurationComparison.VS_NOW].hours = (0, date_fns_2.differenceInHours)(now, modified);
|
|
67
|
+
response.modified[date_1.DurationComparison.VS_NOW].minutes = (0, date_fns_3.differenceInMinutes)(now, modified);
|
|
67
68
|
// Compare now to midnight
|
|
68
|
-
response.modified.
|
|
69
|
-
response.modified.
|
|
69
|
+
response.modified[date_1.DurationComparison.VS_MIDNIGHT].hours = (0, date_fns_5.getHours)(now);
|
|
70
|
+
response.modified[date_1.DurationComparison.VS_MIDNIGHT].minutes = (0, date_fns_6.getMinutes)(now);
|
|
70
71
|
// Convert stream into a string
|
|
71
|
-
response.body = await (0, getStringFromStream_1.default)({
|
|
72
|
+
response.body = await (0, getStringFromStream_1.default)({
|
|
73
|
+
stream: apiResponse.Body
|
|
74
|
+
});
|
|
72
75
|
// If we need to return JSON, parse it. On error return undefined
|
|
73
76
|
if (false !== isJson) {
|
|
74
77
|
response.body = JSON.parse(response.body) || undefined;
|
package/aws/s3cache/getCache.js
CHANGED
|
@@ -3,7 +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
|
|
6
|
+
const date_1 = require("../../date");
|
|
7
7
|
const getKey_1 = __importDefault(require("./getKey"));
|
|
8
8
|
const readGzip_1 = __importDefault(require("../s3/readGzip"));
|
|
9
9
|
/**
|
|
@@ -23,7 +23,7 @@ const getCache = async ({ bucket, cache, fileName, folder }) => {
|
|
|
23
23
|
isJson: true,
|
|
24
24
|
});
|
|
25
25
|
// Cache exists and is still within our caching timeframe
|
|
26
|
-
if (undefined !== cached.body && (
|
|
26
|
+
if (undefined !== cached.body && (date_1.Interval.FOREVER === cache.timeframe || cached.modified[cache.from][cache.timeframe] < cache.duration)) {
|
|
27
27
|
response = cached.body;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
@@ -4,7 +4,7 @@ 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
|
|
7
|
+
const api_1 = require("../../api");
|
|
8
8
|
const get_1 = __importDefault(require("../../axios/get"));
|
|
9
9
|
const sleep_1 = __importDefault(require("../../util/sleep"));
|
|
10
10
|
/**
|
|
@@ -30,8 +30,8 @@ const getRealtime = async (props) => {
|
|
|
30
30
|
keys: ["response_id"],
|
|
31
31
|
});
|
|
32
32
|
if ("" !== responseId) {
|
|
33
|
-
let state =
|
|
34
|
-
while (
|
|
33
|
+
let state = api_1.State.PENDING;
|
|
34
|
+
while (api_1.State.PENDING === state) {
|
|
35
35
|
const resultUrl = `https://api.brightdata.com/dca/get_result?response_id=${responseId}`;
|
|
36
36
|
// Use fetch with the agent option to make an HTTP request through the proxy
|
|
37
37
|
// Replace <target_url> with the URL you want to request
|
|
@@ -46,10 +46,10 @@ const getRealtime = async (props) => {
|
|
|
46
46
|
if (resultResponse.isSuccess()) {
|
|
47
47
|
if (undefined !== resultResponse.body.pending &&
|
|
48
48
|
true === resultResponse.body.pending) {
|
|
49
|
-
state =
|
|
49
|
+
state = api_1.State.PENDING;
|
|
50
50
|
}
|
|
51
51
|
else {
|
|
52
|
-
state =
|
|
52
|
+
state = api_1.State.SUCCESS;
|
|
53
53
|
response = resultResponse.getBody();
|
|
54
54
|
}
|
|
55
55
|
}
|
package/crud/index.d.ts
ADDED
package/crud/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Action = void 0;
|
|
4
|
+
var Action;
|
|
5
|
+
(function (Action) {
|
|
6
|
+
Action["CREATE"] = "CREATE";
|
|
7
|
+
Action["READ"] = "READ";
|
|
8
|
+
Action["UPDATE"] = "UPDATE";
|
|
9
|
+
Action["DELETE"] = "DELETE";
|
|
10
|
+
})(Action || (exports.Action = Action = {}));
|
package/date/getDate.d.ts
CHANGED
package/date/getFinancialYear.js
CHANGED
|
@@ -4,9 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const date_fns_1 = require("date-fns");
|
|
7
|
-
const date_fns_2 = require("date-fns");
|
|
8
|
-
const date_fns_3 = require("date-fns");
|
|
9
|
-
const date_fns_4 = require("date-fns");
|
|
10
7
|
const getDate_1 = __importDefault(require("./getDate"));
|
|
11
8
|
const getToday_1 = __importDefault(require("./getToday"));
|
|
12
9
|
/**
|
|
@@ -41,11 +38,11 @@ const getFinancialYear = (props = {}) => {
|
|
|
41
38
|
});
|
|
42
39
|
// Get the previous Monday if the 1st of April isn't a Monday
|
|
43
40
|
if (!(0, date_fns_1.isMonday)(yearStart)) {
|
|
44
|
-
yearStart = (0,
|
|
41
|
+
yearStart = (0, date_fns_1.previousMonday)(yearStart);
|
|
45
42
|
}
|
|
46
43
|
// Get the next Sunday if the 31st of March isn't a Sunday
|
|
47
|
-
if (!(0,
|
|
48
|
-
yearEnd = (0,
|
|
44
|
+
if (!(0, date_fns_1.isSunday)(yearEnd)) {
|
|
45
|
+
yearEnd = (0, date_fns_1.nextSunday)(yearEnd);
|
|
49
46
|
}
|
|
50
47
|
return {
|
|
51
48
|
end: yearEnd,
|
|
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const date_fns_1 = require("date-fns");
|
|
7
|
-
const date_fns_2 = require("date-fns");
|
|
8
7
|
const getFinancialYear_1 = __importDefault(require("./getFinancialYear"));
|
|
9
8
|
const getTimeZoned_1 = __importDefault(require("./getTimeZoned"));
|
|
10
9
|
/**
|
|
@@ -14,7 +13,7 @@ const getFinancialYearWeeks = (props = {}) => {
|
|
|
14
13
|
const financialYear = (0, getFinancialYear_1.default)({
|
|
15
14
|
year: props.year
|
|
16
15
|
});
|
|
17
|
-
const weeks = (0,
|
|
16
|
+
const weeks = (0, date_fns_1.eachWeekOfInterval)(financialYear, {
|
|
18
17
|
weekStartsOn: 1
|
|
19
18
|
});
|
|
20
19
|
let response = weeks.map((week, index) => {
|
package/date/getLastWeek.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GetMidnight } from "./getMidnight";
|
|
2
2
|
import { GetTimeZoned } from "./getTimeZoned";
|
|
3
|
-
import { Timeframe } from "./
|
|
3
|
+
import { Timeframe } from "./";
|
|
4
4
|
type GetLastWeek = GetTimeZoned & GetMidnight;
|
|
5
5
|
/**
|
|
6
6
|
* Return an object of start/end predefined date of Last Week.
|
package/date/getMax.d.ts
CHANGED
package/date/getMin.d.ts
CHANGED
package/date/getMonday.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DateType } from
|
|
2
|
-
import { GetMidnight } from
|
|
3
|
-
import { GetTimeZoned } from
|
|
1
|
+
import { DateType } from "./";
|
|
2
|
+
import { GetMidnight } from "./getMidnight";
|
|
3
|
+
import { GetTimeZoned } from "./getTimeZoned";
|
|
4
4
|
type GetMonday = GetTimeZoned & GetMidnight & {
|
|
5
5
|
input?: DateType;
|
|
6
6
|
isUtc?: boolean;
|
package/date/getMonday.js
CHANGED
|
@@ -4,8 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const date_fns_1 = require("date-fns");
|
|
7
|
-
const date_fns_2 = require("date-fns");
|
|
8
|
-
const date_fns_3 = require("date-fns");
|
|
9
7
|
const getDate_1 = __importDefault(require("./getDate"));
|
|
10
8
|
const getMidnight_1 = __importDefault(require("./getMidnight"));
|
|
11
9
|
const getToday_1 = __importDefault(require("./getToday"));
|
|
@@ -30,14 +28,14 @@ const getMonday = (props) => {
|
|
|
30
28
|
});
|
|
31
29
|
// console.log('dateInstance', dateInstance);
|
|
32
30
|
}
|
|
33
|
-
if (!(0,
|
|
31
|
+
if (!(0, date_fns_1.isMonday)(dateInstance)) {
|
|
34
32
|
// Get the ISO Day of week (Monday - 1 to Sunday - 7)
|
|
35
33
|
const isoDay = (0, date_fns_1.getISODay)(dateInstance);
|
|
36
34
|
// Move back to Monday
|
|
37
|
-
dateInstance = (0,
|
|
35
|
+
dateInstance = (0, date_fns_1.subDays)(dateInstance, isoDay - 1);
|
|
38
36
|
}
|
|
39
37
|
// Move it back a given number of weeks
|
|
40
|
-
dateInstance = (0,
|
|
38
|
+
dateInstance = (0, date_fns_1.subDays)(dateInstance, 7 * props.weeksAgo);
|
|
41
39
|
// console.log('dateInstance', dateInstance);
|
|
42
40
|
dateInstance = (0, getMidnight_1.default)({
|
|
43
41
|
input: dateInstance,
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Timeframe } from './timeframe';
|
|
1
|
+
import { PredefinedTimeframe, Timeframe } from "./";
|
|
3
2
|
/**
|
|
4
3
|
* Check to see the date matches a predefined time frame
|
|
5
4
|
*/
|
|
6
5
|
declare const getPredefinedTimeframe: ({ timeframe }: {
|
|
7
6
|
timeframe: Timeframe;
|
|
8
|
-
}) =>
|
|
7
|
+
}) => PredefinedTimeframe;
|
|
9
8
|
export default getPredefinedTimeframe;
|
|
@@ -5,19 +5,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const isLastWeek_1 = __importDefault(require("./isLastWeek"));
|
|
7
7
|
const isThisWeek_1 = __importDefault(require("./isThisWeek"));
|
|
8
|
-
const
|
|
8
|
+
const _1 = require("./");
|
|
9
9
|
/**
|
|
10
10
|
* Check to see the date matches a predefined time frame
|
|
11
11
|
*/
|
|
12
12
|
const getPredefinedTimeframe = ({ timeframe }) => {
|
|
13
|
-
let response =
|
|
13
|
+
let response = _1.PredefinedTimeframe.CUSTOM;
|
|
14
14
|
// If the selected date matches last week
|
|
15
15
|
if ((0, isLastWeek_1.default)(timeframe)) {
|
|
16
|
-
response =
|
|
16
|
+
response = _1.PredefinedTimeframe.LAST_WEEK;
|
|
17
17
|
}
|
|
18
18
|
// If the selected date matches this week
|
|
19
19
|
else if ((0, isThisWeek_1.default)(timeframe)) {
|
|
20
|
-
response =
|
|
20
|
+
response = _1.PredefinedTimeframe.THIS_WEEK;
|
|
21
21
|
}
|
|
22
22
|
return response;
|
|
23
23
|
};
|