sec-edgar-api 0.0.1
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/README.md +27 -0
- package/build/index.d.ts +21 -0
- package/build/index.js +26 -0
- package/build/services/FactFileReader/FactFileReader.d.ts +30 -0
- package/build/services/FactFileReader/FactFileReader.js +36 -0
- package/build/services/FactFileReader/index.d.ts +2 -0
- package/build/services/FactFileReader/index.js +4 -0
- package/build/services/ReportParser/FactIterator.d.ts +18 -0
- package/build/services/ReportParser/FactIterator.js +35 -0
- package/build/services/ReportParser/PropertyResolver.d.ts +25 -0
- package/build/services/ReportParser/PropertyResolver.js +44 -0
- package/build/services/ReportParser/ReportParser.d.ts +53 -0
- package/build/services/ReportParser/ReportParser.js +97 -0
- package/build/services/ReportParser/ReportRawParser.d.ts +34 -0
- package/build/services/ReportParser/ReportRawParser.js +154 -0
- package/build/services/ReportParser/ReportTranslatedProxy.d.ts +9 -0
- package/build/services/ReportParser/ReportTranslatedProxy.js +40 -0
- package/build/services/ReportParser/ReportWrapper.d.ts +27 -0
- package/build/services/ReportParser/ReportWrapper.js +89 -0
- package/build/services/ReportParser/index.d.ts +2 -0
- package/build/services/ReportParser/index.js +4 -0
- package/build/services/ReportParser/resolvers/helpers.d.ts +21 -0
- package/build/services/ReportParser/resolvers/helpers.js +49 -0
- package/build/services/ReportParser/resolvers/index.d.ts +31 -0
- package/build/services/ReportParser/resolvers/index.js +33 -0
- package/build/services/ReportParser/resolvers/resolve-asset-current.d.ts +2 -0
- package/build/services/ReportParser/resolvers/resolve-asset-current.js +20 -0
- package/build/services/ReportParser/resolvers/resolve-asset-non-current-ppe-gross.d.ts +2 -0
- package/build/services/ReportParser/resolvers/resolve-asset-non-current-ppe-gross.js +20 -0
- package/build/services/ReportParser/resolvers/resolve-cash-flow-capex.d.ts +5 -0
- package/build/services/ReportParser/resolvers/resolve-cash-flow-capex.js +37 -0
- package/build/services/ReportParser/resolvers/resolve-cash-flow-free.d.ts +2 -0
- package/build/services/ReportParser/resolvers/resolve-cash-flow-free.js +23 -0
- package/build/services/ReportParser/resolvers/resolve-cash-flow-operating.d.ts +2 -0
- package/build/services/ReportParser/resolvers/resolve-cash-flow-operating.js +39 -0
- package/build/services/ReportParser/resolvers/resolve-cash-flow-working-capital-non-cash.d.ts +2 -0
- package/build/services/ReportParser/resolvers/resolve-cash-flow-working-capital-non-cash.js +22 -0
- package/build/services/ReportParser/resolvers/resolve-ebit.d.ts +2 -0
- package/build/services/ReportParser/resolvers/resolve-ebit.js +25 -0
- package/build/services/ReportParser/resolvers/resolve-expense-depreciation.d.ts +2 -0
- package/build/services/ReportParser/resolvers/resolve-expense-depreciation.js +96 -0
- package/build/services/ReportParser/resolvers/resolve-expense-operating.d.ts +2 -0
- package/build/services/ReportParser/resolvers/resolve-expense-operating.js +22 -0
- package/build/services/ReportParser/resolvers/resolve-expense-total.d.ts +2 -0
- package/build/services/ReportParser/resolvers/resolve-expense-total.js +20 -0
- package/build/services/ReportParser/resolvers/resolve-fiscal-year-cumulative-properties.d.ts +5 -0
- package/build/services/ReportParser/resolvers/resolve-fiscal-year-cumulative-properties.js +70 -0
- package/build/services/ReportParser/resolvers/resolve-liability-current.d.ts +2 -0
- package/build/services/ReportParser/resolvers/resolve-liability-current.js +20 -0
- package/build/services/ReportParser/resolvers/resolve-q4-fiscal-year-matching-properties.d.ts +5 -0
- package/build/services/ReportParser/resolvers/resolve-q4-fiscal-year-matching-properties.js +24 -0
- package/build/services/ReportParser/resolvers/resolve-revenue-total.d.ts +2 -0
- package/build/services/ReportParser/resolvers/resolve-revenue-total.js +20 -0
- package/build/services/SecEdgarApi/Client.d.ts +44 -0
- package/build/services/SecEdgarApi/Client.js +104 -0
- package/build/services/SecEdgarApi/Downloader.d.ts +26 -0
- package/build/services/SecEdgarApi/Downloader.js +102 -0
- package/build/services/SecEdgarApi/FactsDownloader.d.ts +30 -0
- package/build/services/SecEdgarApi/FactsDownloader.js +125 -0
- package/build/services/SecEdgarApi/SecConnector.d.ts +47 -0
- package/build/services/SecEdgarApi/SecConnector.js +143 -0
- package/build/services/SecEdgarApi/SecEdgarApi.d.ts +92 -0
- package/build/services/SecEdgarApi/SecEdgarApi.js +184 -0
- package/build/services/SecEdgarApi/Throttler.d.ts +34 -0
- package/build/services/SecEdgarApi/Throttler.js +111 -0
- package/build/services/SecEdgarApi/Unzipper.d.ts +40 -0
- package/build/services/SecEdgarApi/Unzipper.js +40 -0
- package/build/services/SecEdgarApi/index.d.ts +3 -0
- package/build/services/SecEdgarApi/index.js +19 -0
- package/build/types/company-facts.type.d.ts +53 -0
- package/build/types/company-facts.type.js +2 -0
- package/build/types/index.d.ts +4 -0
- package/build/types/index.js +20 -0
- package/build/types/report-raw.type.d.ts +23 -0
- package/build/types/report-raw.type.js +2 -0
- package/build/types/report-translated.type.d.ts +58 -0
- package/build/types/report-translated.type.js +2 -0
- package/build/types/submission.type.d.ts +70 -0
- package/build/types/submission.type.js +2 -0
- package/build/util/cik-by-symbol.d.ts +5 -0
- package/build/util/cik-by-symbol.js +9632 -0
- package/build/util/key-translations.d.ts +7 -0
- package/build/util/key-translations.js +174 -0
- package/package.json +41 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveExpenseOperating = void 0;
|
|
4
|
+
var helpers_1 = require("./helpers");
|
|
5
|
+
function resolveExpenseOperating(report) {
|
|
6
|
+
var _a = report, expenseOperating = _a.expenseOperating, revenueTotal = _a.revenueTotal, revenueCost = _a.revenueCost, incomeOperating = _a.incomeOperating;
|
|
7
|
+
var nullKey = (0, helpers_1.getSingleNullKey)({ expenseOperating: expenseOperating, revenueTotal: revenueTotal, revenueCost: revenueCost, incomeOperating: incomeOperating });
|
|
8
|
+
switch (nullKey) {
|
|
9
|
+
case 'expenseOperating':
|
|
10
|
+
report.expenseOperating = revenueTotal - incomeOperating - revenueCost;
|
|
11
|
+
break;
|
|
12
|
+
case 'incomeOperating':
|
|
13
|
+
report.incomeOperating = revenueTotal - revenueCost - expenseOperating;
|
|
14
|
+
break;
|
|
15
|
+
case 'revenueCost':
|
|
16
|
+
report.revenueCost = revenueTotal - incomeOperating - expenseOperating;
|
|
17
|
+
break;
|
|
18
|
+
case 'revenueTotal':
|
|
19
|
+
report.revenueTotal = incomeOperating + expenseOperating + revenueCost;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.resolveExpenseOperating = resolveExpenseOperating;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveExpenseTotal = void 0;
|
|
4
|
+
var helpers_1 = require("./helpers");
|
|
5
|
+
function resolveExpenseTotal(report) {
|
|
6
|
+
var _a = report, revenueTotal = _a.revenueTotal, incomeNet = _a.incomeNet, expenseTotal = _a.expenseTotal;
|
|
7
|
+
var nullKey = (0, helpers_1.getSingleNullKey)({ revenueTotal: revenueTotal, incomeNet: incomeNet, expenseTotal: expenseTotal });
|
|
8
|
+
switch (nullKey) {
|
|
9
|
+
case 'revenueTotal':
|
|
10
|
+
report.revenueTotal = incomeNet + expenseTotal;
|
|
11
|
+
break;
|
|
12
|
+
case 'incomeNet':
|
|
13
|
+
report.incomeNet = revenueTotal - expenseTotal;
|
|
14
|
+
break;
|
|
15
|
+
case 'expenseTotal':
|
|
16
|
+
report.expenseTotal = revenueTotal - incomeNet;
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.resolveExpenseTotal = resolveExpenseTotal;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveFiscalYearCumulativeProperties = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Properties where the quarters add up to FY resolved if 1 of the 5 reports is missing.
|
|
6
|
+
*/
|
|
7
|
+
function resolveFiscalYearCumulativeProperties(report) {
|
|
8
|
+
var _a = report.getReportsFiscalYearByPeriod(), FY = _a.FY, Q1 = _a.Q1, Q2 = _a.Q2, Q3 = _a.Q3, Q4 = _a.Q4;
|
|
9
|
+
if (!FY || !Q1 || !Q2 || !Q3 || !Q4)
|
|
10
|
+
return;
|
|
11
|
+
// these properties should be the same for Q4 and FY
|
|
12
|
+
matchProperty('assetNonCurrentPPEGross', Q4, FY);
|
|
13
|
+
matchProperty('assetNonCurrentPPENet', Q4, FY);
|
|
14
|
+
matchProperty('expenseDepreciationAccumulated', Q4, FY);
|
|
15
|
+
// keys that should not add up to the FY value
|
|
16
|
+
var keysToSkip = new Set([
|
|
17
|
+
'expenseDepreciationAccumulated',
|
|
18
|
+
'assetNonCurrentPPEGross',
|
|
19
|
+
'assetNonCurrentPPENet',
|
|
20
|
+
'dateFiled',
|
|
21
|
+
'dateReport',
|
|
22
|
+
'fiscalPeriod',
|
|
23
|
+
'fiscalYear',
|
|
24
|
+
'isTTM',
|
|
25
|
+
'form',
|
|
26
|
+
'sharesOutstanding',
|
|
27
|
+
'sharesOutstandingDiluted',
|
|
28
|
+
]);
|
|
29
|
+
var reportKeys = Object.keys(Q1);
|
|
30
|
+
var keysToResolve = reportKeys.filter(function (key) {
|
|
31
|
+
var reportsWithVal = [FY, Q1, Q2, Q3, Q4].filter(function (report) {
|
|
32
|
+
return typeof report[key] === 'number' && !keysToSkip.has(key);
|
|
33
|
+
});
|
|
34
|
+
// we want to get the keys that are in 4 of the 5 reports
|
|
35
|
+
return reportsWithVal.length === 4;
|
|
36
|
+
});
|
|
37
|
+
var _loop_1 = function (key) {
|
|
38
|
+
var valueFY = FY[key];
|
|
39
|
+
// this will be the sum of the 3 quarters if a quarter is missing, and sum of 4 quarters if FY is missing
|
|
40
|
+
var sumQuarters = [Q1, Q2, Q3, Q4].reduce(function (acc, rep) { var _a; return acc + ((_a = rep === null || rep === void 0 ? void 0 : rep[key]) !== null && _a !== void 0 ? _a : 0); }, 0);
|
|
41
|
+
// if FY is missing use the sum of the 4 quarters, otherwise use FY - sum of 3 other quarters
|
|
42
|
+
if (typeof FY[key] !== 'number') {
|
|
43
|
+
;
|
|
44
|
+
FY[key] = sumQuarters;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
for (var _b = 0, _c = [Q1, Q2, Q3, Q4]; _b < _c.length; _b++) {
|
|
48
|
+
var rep = _c[_b];
|
|
49
|
+
if (rep && typeof rep[key] !== 'number') {
|
|
50
|
+
;
|
|
51
|
+
rep[key] = valueFY - sumQuarters;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
for (var _i = 0, keysToResolve_1 = keysToResolve; _i < keysToResolve_1.length; _i++) {
|
|
58
|
+
var key = keysToResolve_1[_i];
|
|
59
|
+
_loop_1(key);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.resolveFiscalYearCumulativeProperties = resolveFiscalYearCumulativeProperties;
|
|
63
|
+
function matchProperty(propertyName, reportA, reportB) {
|
|
64
|
+
var isReportANull = reportA[propertyName] === null;
|
|
65
|
+
var value = isReportANull ? reportB[propertyName] : reportA[propertyName];
|
|
66
|
+
if (typeof value !== 'number')
|
|
67
|
+
return;
|
|
68
|
+
reportA[propertyName] = value;
|
|
69
|
+
reportB[propertyName] = value;
|
|
70
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveLiabilityCurrent = void 0;
|
|
4
|
+
var helpers_1 = require("./helpers");
|
|
5
|
+
function resolveLiabilityCurrent(report) {
|
|
6
|
+
var _a = report, liabilityCurrent = _a.liabilityCurrent, liabilityNonCurrent = _a.liabilityNonCurrent, liabilityTotal = _a.liabilityTotal;
|
|
7
|
+
var nullKey = (0, helpers_1.getSingleNullKey)({ liabilityCurrent: liabilityCurrent, liabilityNonCurrent: liabilityNonCurrent, liabilityTotal: liabilityTotal });
|
|
8
|
+
switch (nullKey) {
|
|
9
|
+
case 'liabilityCurrent':
|
|
10
|
+
report.liabilityCurrent = liabilityTotal - liabilityNonCurrent;
|
|
11
|
+
break;
|
|
12
|
+
case 'liabilityNonCurrent':
|
|
13
|
+
report.liabilityNonCurrent = liabilityTotal - liabilityCurrent;
|
|
14
|
+
break;
|
|
15
|
+
case 'liabilityTotal':
|
|
16
|
+
report.liabilityTotal = liabilityCurrent + liabilityNonCurrent;
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.resolveLiabilityCurrent = resolveLiabilityCurrent;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveQ4FiscalYearMatchingProperties = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Properties that should be the same for Q4 and FY
|
|
6
|
+
*/
|
|
7
|
+
function resolveQ4FiscalYearMatchingProperties(reportWrapper) {
|
|
8
|
+
var _a = reportWrapper.getReportsFiscalYearByPeriod(), FY = _a.FY, Q1 = _a.Q1, Q2 = _a.Q2, Q3 = _a.Q3, Q4 = _a.Q4;
|
|
9
|
+
if (!FY || !Q1 || !Q2 || !Q3 || !Q4)
|
|
10
|
+
return;
|
|
11
|
+
// these properties should be the same for Q4 and FY
|
|
12
|
+
matchProperty('assetNonCurrentPPEGross', Q4, FY);
|
|
13
|
+
matchProperty('assetNonCurrentPPENet', Q4, FY);
|
|
14
|
+
matchProperty('expenseDepreciationAccumulated', Q4, FY);
|
|
15
|
+
}
|
|
16
|
+
exports.resolveQ4FiscalYearMatchingProperties = resolveQ4FiscalYearMatchingProperties;
|
|
17
|
+
function matchProperty(propertyName, reportA, reportB) {
|
|
18
|
+
var isReportANull = reportA[propertyName] === null;
|
|
19
|
+
var value = isReportANull ? reportB[propertyName] : reportA[propertyName];
|
|
20
|
+
if (typeof value !== 'number')
|
|
21
|
+
return;
|
|
22
|
+
reportA[propertyName] = value;
|
|
23
|
+
reportB[propertyName] = value;
|
|
24
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveRevenueTotal = void 0;
|
|
4
|
+
var helpers_1 = require("./helpers");
|
|
5
|
+
function resolveRevenueTotal(report) {
|
|
6
|
+
var _a = report, revenueTotal = _a.revenueTotal, revenueCost = _a.revenueCost, profitGross = _a.profitGross;
|
|
7
|
+
var nullKey = (0, helpers_1.getSingleNullKey)({ revenueTotal: revenueTotal, revenueCost: revenueCost, profitGross: profitGross });
|
|
8
|
+
switch (nullKey) {
|
|
9
|
+
case 'revenueTotal':
|
|
10
|
+
report.revenueTotal = revenueCost + profitGross;
|
|
11
|
+
break;
|
|
12
|
+
case 'revenueCost':
|
|
13
|
+
report.revenueCost = revenueTotal - profitGross;
|
|
14
|
+
break;
|
|
15
|
+
case 'profitGross':
|
|
16
|
+
report.profitGross = revenueTotal - revenueCost;
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.resolveRevenueTotal = resolveRevenueTotal;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { ClientRequest, IncomingMessage, RequestOptions } from 'http';
|
|
4
|
+
type Primitive = string | number | boolean | null | undefined;
|
|
5
|
+
interface HttpClient {
|
|
6
|
+
request: (options: string | URL | RequestOptions, callback?: (res: IncomingMessage) => void) => ClientRequest;
|
|
7
|
+
}
|
|
8
|
+
export interface OnChunkData {
|
|
9
|
+
percentComplete: number;
|
|
10
|
+
chunk: Buffer;
|
|
11
|
+
}
|
|
12
|
+
export interface ClientResponse {
|
|
13
|
+
statusCode: number;
|
|
14
|
+
message: string;
|
|
15
|
+
data: Buffer | null;
|
|
16
|
+
}
|
|
17
|
+
export interface RequestParams {
|
|
18
|
+
url: string;
|
|
19
|
+
headers?: Record<string, string>;
|
|
20
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
21
|
+
data?: string | Record<string, Primitive | object>;
|
|
22
|
+
timeout?: number;
|
|
23
|
+
onError?: (err: Error) => void;
|
|
24
|
+
onChunk?: (data: OnChunkData) => void;
|
|
25
|
+
onResponse?: (response: IncomingMessage) => void;
|
|
26
|
+
onSuccess?: (response: ClientResponse) => void;
|
|
27
|
+
resolveData?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface ClientArgs {
|
|
30
|
+
httpClient: HttpClient;
|
|
31
|
+
defaultHeaders?: Record<string, string>;
|
|
32
|
+
}
|
|
33
|
+
export interface IClient {
|
|
34
|
+
request(params: RequestParams): Promise<ClientResponse>;
|
|
35
|
+
setDefaultHeaders?(headers: Record<string, string>): void;
|
|
36
|
+
}
|
|
37
|
+
export default class Client implements IClient {
|
|
38
|
+
private readonly httpClient;
|
|
39
|
+
private defaultHeaders;
|
|
40
|
+
constructor(args?: ClientArgs);
|
|
41
|
+
setDefaultHeaders(headers: Record<string, string>): void;
|
|
42
|
+
request(params: RequestParams): Promise<ClientResponse>;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
var https = require("https");
|
|
15
|
+
var Client = /** @class */ (function () {
|
|
16
|
+
function Client(args) {
|
|
17
|
+
if (args === void 0) { args = {
|
|
18
|
+
httpClient: https,
|
|
19
|
+
defaultHeaders: {
|
|
20
|
+
// this can be any user agent, just not empty
|
|
21
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 RuxitSynthetic/1.0 v1060014908909962014 t8797611264074608560 ath259cea6f altpriv cvcv=2 smf=0',
|
|
22
|
+
},
|
|
23
|
+
}; }
|
|
24
|
+
var httpClient = args.httpClient, defaultHeaders = args.defaultHeaders;
|
|
25
|
+
this.httpClient = httpClient;
|
|
26
|
+
this.defaultHeaders = defaultHeaders !== null && defaultHeaders !== void 0 ? defaultHeaders : {};
|
|
27
|
+
}
|
|
28
|
+
Client.prototype.setDefaultHeaders = function (headers) {
|
|
29
|
+
this.defaultHeaders = headers;
|
|
30
|
+
};
|
|
31
|
+
Client.prototype.request = function (params) {
|
|
32
|
+
var _this = this;
|
|
33
|
+
var url = params.url, data = params.data, headers = params.headers, onChunk = params.onChunk, onResponse = params.onResponse, onError = params.onError, onSuccess = params.onSuccess, _a = params.resolveData, resolveData = _a === void 0 ? true : _a, _b = params.method, method = _b === void 0 ? 'GET' : _b, _c = params.timeout, timeout = _c === void 0 ? 86400000 : _c;
|
|
34
|
+
var allHeaders = __assign(__assign({}, this.defaultHeaders), headers);
|
|
35
|
+
return new Promise(function (resolve, reject) {
|
|
36
|
+
var responseData = '';
|
|
37
|
+
var request = _this.httpClient.request(url, function (res) {
|
|
38
|
+
var _a, _b, _c;
|
|
39
|
+
var lengthTotal = parseInt((_a = res.headers['content-length']) !== null && _a !== void 0 ? _a : '0');
|
|
40
|
+
var lengthCurrent = 0;
|
|
41
|
+
onResponse === null || onResponse === void 0 ? void 0 : onResponse(res);
|
|
42
|
+
if (res.statusCode !== 200) {
|
|
43
|
+
reject({
|
|
44
|
+
statusCode: (_b = res.statusCode) !== null && _b !== void 0 ? _b : 400,
|
|
45
|
+
message: (_c = res.statusMessage) !== null && _c !== void 0 ? _c : 'Bad Request',
|
|
46
|
+
data: null,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
res.on('data', function (chunk) {
|
|
50
|
+
lengthCurrent += chunk.length;
|
|
51
|
+
if (resolveData) {
|
|
52
|
+
responseData += chunk;
|
|
53
|
+
}
|
|
54
|
+
onChunk === null || onChunk === void 0 ? void 0 : onChunk({
|
|
55
|
+
percentComplete: lengthCurrent / lengthTotal,
|
|
56
|
+
chunk: Buffer.from(chunk),
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
res.on('error', function (err) {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
onError === null || onError === void 0 ? void 0 : onError(err);
|
|
62
|
+
reject({
|
|
63
|
+
statusCode: (_a = res.statusCode) !== null && _a !== void 0 ? _a : 400,
|
|
64
|
+
message: (_b = res.statusMessage) !== null && _b !== void 0 ? _b : 'Bad Request',
|
|
65
|
+
data: null,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
res.on('end', function () {
|
|
69
|
+
var _a, _b;
|
|
70
|
+
var buffer = Buffer.from(responseData);
|
|
71
|
+
var clientResponse = {
|
|
72
|
+
statusCode: (_a = res.statusCode) !== null && _a !== void 0 ? _a : 200,
|
|
73
|
+
message: (_b = res.statusMessage) !== null && _b !== void 0 ? _b : 'OK',
|
|
74
|
+
data: buffer,
|
|
75
|
+
};
|
|
76
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(clientResponse);
|
|
77
|
+
resolve(clientResponse);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
request.on('timeout', function () {
|
|
81
|
+
request.destroy();
|
|
82
|
+
reject({
|
|
83
|
+
statusCode: null,
|
|
84
|
+
message: 'Connection Timeout',
|
|
85
|
+
data: null,
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
request.setTimeout(timeout, function () { return reject("timeout after ".concat(timeout, "ms")); });
|
|
89
|
+
for (var key in allHeaders) {
|
|
90
|
+
request.setHeader(key, allHeaders[key]);
|
|
91
|
+
}
|
|
92
|
+
if (data) {
|
|
93
|
+
if (typeof data === 'string')
|
|
94
|
+
request.write(data);
|
|
95
|
+
else
|
|
96
|
+
request.write(JSON.stringify(data));
|
|
97
|
+
}
|
|
98
|
+
request.method = method;
|
|
99
|
+
request.end();
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
return Client;
|
|
103
|
+
}());
|
|
104
|
+
exports.default = Client;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { WriteStream } from 'fs';
|
|
3
|
+
import { IClient, RequestParams } from './Client';
|
|
4
|
+
export interface DownloadParams extends RequestParams {
|
|
5
|
+
filename: string;
|
|
6
|
+
createDirIfNotExists?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface IDownloader {
|
|
9
|
+
download(params: DownloadParams): Promise<boolean>;
|
|
10
|
+
}
|
|
11
|
+
interface FileManager {
|
|
12
|
+
createWriteStream(path: string): WriteStream;
|
|
13
|
+
existsSync(path: string): boolean;
|
|
14
|
+
mkdirSync(path: string): void;
|
|
15
|
+
}
|
|
16
|
+
interface DownloaderArgs {
|
|
17
|
+
client: IClient;
|
|
18
|
+
fileManager: FileManager;
|
|
19
|
+
}
|
|
20
|
+
export default class Downlaoder implements IDownloader {
|
|
21
|
+
private readonly client;
|
|
22
|
+
private readonly fileManager;
|
|
23
|
+
constructor(args?: DownloaderArgs);
|
|
24
|
+
download(params: DownloadParams): Promise<boolean>;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
50
|
+
var t = {};
|
|
51
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
52
|
+
t[p] = s[p];
|
|
53
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
54
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
55
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
56
|
+
t[p[i]] = s[p[i]];
|
|
57
|
+
}
|
|
58
|
+
return t;
|
|
59
|
+
};
|
|
60
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
|
+
var fs = require("fs");
|
|
62
|
+
var Client_1 = require("./Client");
|
|
63
|
+
var Downlaoder = /** @class */ (function () {
|
|
64
|
+
function Downlaoder(args) {
|
|
65
|
+
if (args === void 0) { args = { client: new Client_1.default(), fileManager: fs }; }
|
|
66
|
+
var client = args.client, fileManager = args.fileManager;
|
|
67
|
+
this.client = client;
|
|
68
|
+
this.fileManager = fileManager;
|
|
69
|
+
}
|
|
70
|
+
Downlaoder.prototype.download = function (params) {
|
|
71
|
+
var _this = this;
|
|
72
|
+
var filename = params.filename, onSuccess = params.onSuccess, onError = params.onError, _a = params.createDirIfNotExists, createDirIfNotExists = _a === void 0 ? false : _a, rest = __rest(params, ["filename", "onSuccess", "onError", "createDirIfNotExists"]);
|
|
73
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
74
|
+
var dir, file;
|
|
75
|
+
return __generator(this, function (_a) {
|
|
76
|
+
dir = filename.substring(0, filename.lastIndexOf('/'));
|
|
77
|
+
if (dir.length > 0 && createDirIfNotExists && !this.fileManager.existsSync(dir)) {
|
|
78
|
+
this.fileManager.mkdirSync(dir);
|
|
79
|
+
}
|
|
80
|
+
file = this.fileManager.createWriteStream(filename);
|
|
81
|
+
file.on('close', function () { return resolve(true); });
|
|
82
|
+
file.on('finish', function () { return file.close(); });
|
|
83
|
+
file.on('error', function (err) {
|
|
84
|
+
file.destroy();
|
|
85
|
+
onError === null || onError === void 0 ? void 0 : onError(err);
|
|
86
|
+
reject(false);
|
|
87
|
+
});
|
|
88
|
+
this.client
|
|
89
|
+
.request(__assign(__assign({ onError: onError }, rest), { onResponse: function (res) {
|
|
90
|
+
var _a;
|
|
91
|
+
res.pipe(file);
|
|
92
|
+
(_a = rest.onResponse) === null || _a === void 0 ? void 0 : _a.call(rest, res);
|
|
93
|
+
} }))
|
|
94
|
+
.then(function (res) { return onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(res); })
|
|
95
|
+
.catch(function () { return reject(false); });
|
|
96
|
+
return [2 /*return*/];
|
|
97
|
+
});
|
|
98
|
+
}); });
|
|
99
|
+
};
|
|
100
|
+
return Downlaoder;
|
|
101
|
+
}());
|
|
102
|
+
exports.default = Downlaoder;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IDownloader } from './Downloader';
|
|
3
|
+
import Unzipper from './Unzipper';
|
|
4
|
+
interface FactsDownloaderArgs {
|
|
5
|
+
downloader: IDownloader;
|
|
6
|
+
unzipper: Unzipper;
|
|
7
|
+
}
|
|
8
|
+
interface OnChunkData {
|
|
9
|
+
percentComplete: number;
|
|
10
|
+
chunk: Buffer;
|
|
11
|
+
stage: 'download' | 'unzip';
|
|
12
|
+
}
|
|
13
|
+
export interface DownloadCompanyFactsDirectoryParams {
|
|
14
|
+
outputDirname: string;
|
|
15
|
+
unzip?: boolean;
|
|
16
|
+
onChunk?: (data: OnChunkData) => void;
|
|
17
|
+
onDownloadComplete?: () => void;
|
|
18
|
+
onComplete?: () => void;
|
|
19
|
+
onError?: (err: Error) => void;
|
|
20
|
+
}
|
|
21
|
+
export interface IFactsDownloader {
|
|
22
|
+
downloadCompanyFactsDirectory(params: DownloadCompanyFactsDirectoryParams): Promise<boolean>;
|
|
23
|
+
}
|
|
24
|
+
export default class FactsDownloader implements IFactsDownloader {
|
|
25
|
+
private readonly unzipper;
|
|
26
|
+
private readonly downloader;
|
|
27
|
+
constructor(args?: FactsDownloaderArgs);
|
|
28
|
+
downloadCompanyFactsDirectory(params: DownloadCompanyFactsDirectoryParams): Promise<boolean>;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
var Downloader_1 = require("./Downloader");
|
|
51
|
+
var Unzipper_1 = require("./Unzipper");
|
|
52
|
+
var FactsDownloader = /** @class */ (function () {
|
|
53
|
+
function FactsDownloader(args) {
|
|
54
|
+
if (args === void 0) { args = {
|
|
55
|
+
downloader: new Downloader_1.default(),
|
|
56
|
+
unzipper: new Unzipper_1.default(),
|
|
57
|
+
}; }
|
|
58
|
+
var unzipper = args.unzipper, downloader = args.downloader;
|
|
59
|
+
this.unzipper = unzipper;
|
|
60
|
+
this.downloader = downloader;
|
|
61
|
+
}
|
|
62
|
+
FactsDownloader.prototype.downloadCompanyFactsDirectory = function (params) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
64
|
+
var outputDirname, onChunk, onDownloadComplete, onError, onComplete, _a, unzip;
|
|
65
|
+
var _this = this;
|
|
66
|
+
return __generator(this, function (_b) {
|
|
67
|
+
outputDirname = params.outputDirname, onChunk = params.onChunk, onDownloadComplete = params.onDownloadComplete, onError = params.onError, onComplete = params.onComplete, _a = params.unzip, unzip = _a === void 0 ? true : _a;
|
|
68
|
+
// writes download and unzip progress with percentage in terminal if useWriteProgressBar is true
|
|
69
|
+
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
70
|
+
var filename, e_1;
|
|
71
|
+
return __generator(this, function (_a) {
|
|
72
|
+
switch (_a.label) {
|
|
73
|
+
case 0:
|
|
74
|
+
filename = "".concat(outputDirname, ".zip");
|
|
75
|
+
_a.label = 1;
|
|
76
|
+
case 1:
|
|
77
|
+
_a.trys.push([1, 5, , 6]);
|
|
78
|
+
// download from sec
|
|
79
|
+
return [4 /*yield*/, this.downloader.download({
|
|
80
|
+
url: 'https://www.sec.gov/Archives/edgar/daily-index/xbrl/companyfacts.zip',
|
|
81
|
+
filename: filename,
|
|
82
|
+
createDirIfNotExists: true,
|
|
83
|
+
resolveData: false,
|
|
84
|
+
headers: {
|
|
85
|
+
'Accept-Encoding': 'gzip, deflate',
|
|
86
|
+
},
|
|
87
|
+
onError: function (err) { return reject(err); },
|
|
88
|
+
onChunk: onChunk ? function (data) { return onChunk === null || onChunk === void 0 ? void 0 : onChunk(__assign(__assign({}, data), { stage: 'download' })); } : undefined,
|
|
89
|
+
})];
|
|
90
|
+
case 2:
|
|
91
|
+
// download from sec
|
|
92
|
+
_a.sent();
|
|
93
|
+
onDownloadComplete === null || onDownloadComplete === void 0 ? void 0 : onDownloadComplete();
|
|
94
|
+
if (!unzip) return [3 /*break*/, 4];
|
|
95
|
+
// unzip companyfacts.zip
|
|
96
|
+
return [4 /*yield*/, this.unzipper.unzip({
|
|
97
|
+
inputFilename: filename,
|
|
98
|
+
outputDirname: outputDirname,
|
|
99
|
+
deleteOriginal: true,
|
|
100
|
+
onError: function (err) { return reject(err); },
|
|
101
|
+
onChunk: onChunk ? function (data) { return onChunk === null || onChunk === void 0 ? void 0 : onChunk(__assign(__assign({}, data), { stage: 'unzip' })); } : undefined,
|
|
102
|
+
})];
|
|
103
|
+
case 3:
|
|
104
|
+
// unzip companyfacts.zip
|
|
105
|
+
_a.sent();
|
|
106
|
+
_a.label = 4;
|
|
107
|
+
case 4:
|
|
108
|
+
onComplete === null || onComplete === void 0 ? void 0 : onComplete();
|
|
109
|
+
resolve(true);
|
|
110
|
+
return [3 /*break*/, 6];
|
|
111
|
+
case 5:
|
|
112
|
+
e_1 = _a.sent();
|
|
113
|
+
onError === null || onError === void 0 ? void 0 : onError(e_1);
|
|
114
|
+
reject(e_1);
|
|
115
|
+
return [3 /*break*/, 6];
|
|
116
|
+
case 6: return [2 /*return*/];
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}); })];
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
return FactsDownloader;
|
|
124
|
+
}());
|
|
125
|
+
exports.default = FactsDownloader;
|