sec-edgar-api 0.0.5 → 0.0.7

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.
Files changed (70) hide show
  1. package/README.md +9 -45
  2. package/build/index.d.ts +2 -7
  3. package/build/index.js +16 -8
  4. package/build/services/DocumentParser/DocumentParser.d.ts +16 -0
  5. package/build/services/DocumentParser/DocumentParser.js +22 -0
  6. package/build/services/DocumentParser/XMLNode/ColNode.d.ts +18 -0
  7. package/build/services/DocumentParser/XMLNode/ColNode.js +74 -0
  8. package/build/services/DocumentParser/XMLNode/DocumentNode.d.ts +3 -0
  9. package/build/services/DocumentParser/XMLNode/DocumentNode.js +27 -0
  10. package/build/services/DocumentParser/XMLNode/HRNode.d.ts +3 -0
  11. package/build/services/DocumentParser/XMLNode/HRNode.js +27 -0
  12. package/build/services/DocumentParser/XMLNode/NonTableNode.d.ts +3 -0
  13. package/build/services/DocumentParser/XMLNode/NonTableNode.js +27 -0
  14. package/build/services/DocumentParser/XMLNode/RowNode.d.ts +30 -0
  15. package/build/services/DocumentParser/XMLNode/RowNode.js +177 -0
  16. package/build/services/DocumentParser/XMLNode/TableNode.d.ts +20 -0
  17. package/build/services/DocumentParser/XMLNode/TableNode.js +132 -0
  18. package/build/services/DocumentParser/XMLNode/XMLNode.d.ts +37 -0
  19. package/build/services/DocumentParser/XMLNode/XMLNode.js +154 -0
  20. package/build/services/DocumentParser/XMLParser.d.ts +40 -0
  21. package/build/services/DocumentParser/XMLParser.js +306 -0
  22. package/build/services/DocumentParser/index.d.ts +2 -0
  23. package/build/services/DocumentParser/index.js +4 -0
  24. package/build/services/DocumentParser/parsers/index.d.ts +9 -0
  25. package/build/services/DocumentParser/parsers/index.js +11 -0
  26. package/build/services/DocumentParser/parsers/parse-form-10k.d.ts +3 -0
  27. package/build/services/DocumentParser/parsers/parse-form-10k.js +78 -0
  28. package/build/services/DocumentParser/parsers/parse-form-13g.d.ts +8 -0
  29. package/build/services/DocumentParser/parsers/parse-form-13g.js +88 -0
  30. package/build/services/DocumentParser/parsers/parse-form-4.d.ts +8 -0
  31. package/build/services/DocumentParser/parsers/parse-form-4.js +220 -0
  32. package/build/services/ReportParser/ReportParser.d.ts +2 -2
  33. package/build/services/ReportParser/ReportParser.js +8 -4
  34. package/build/services/SecEdgarApi/RequestWrapper.d.ts +37 -0
  35. package/build/services/SecEdgarApi/RequestWrapper.js +147 -0
  36. package/build/services/SecEdgarApi/SecEdgarApi.d.ts +156 -22
  37. package/build/services/SecEdgarApi/SecEdgarApi.js +314 -32
  38. package/build/types/common.type.d.ts +12 -0
  39. package/build/types/common.type.js +2 -0
  40. package/build/types/index.d.ts +2 -0
  41. package/build/types/index.js +2 -0
  42. package/build/types/parsed-filings.type.d.ts +66 -0
  43. package/build/types/parsed-filings.type.js +2 -0
  44. package/build/types/submission.type.d.ts +19 -1
  45. package/package.json +1 -5
  46. package/build/.DS_Store +0 -0
  47. package/build/downloader.d.ts +0 -6
  48. package/build/downloader.js +0 -9
  49. package/build/services/FactFileReader/FactFileReader.d.ts +0 -30
  50. package/build/services/FactFileReader/FactFileReader.js +0 -36
  51. package/build/services/FactFileReader/index.d.ts +0 -2
  52. package/build/services/FactFileReader/index.js +0 -4
  53. package/build/services/FactsDownloader/Downloader.d.ts +0 -26
  54. package/build/services/FactsDownloader/Downloader.js +0 -102
  55. package/build/services/FactsDownloader/FactsDownloader.d.ts +0 -37
  56. package/build/services/FactsDownloader/FactsDownloader.js +0 -131
  57. package/build/services/FactsDownloader/Unzipper.d.ts +0 -40
  58. package/build/services/FactsDownloader/Unzipper.js +0 -40
  59. package/build/services/FactsDownloader/index.d.ts +0 -2
  60. package/build/services/FactsDownloader/index.js +0 -4
  61. package/build/services/SecEdgarApi/Client.d.ts +0 -44
  62. package/build/services/SecEdgarApi/Client.js +0 -104
  63. package/build/services/SecEdgarApi/Downloader.d.ts +0 -26
  64. package/build/services/SecEdgarApi/Downloader.js +0 -102
  65. package/build/services/SecEdgarApi/FactsDownloader.d.ts +0 -30
  66. package/build/services/SecEdgarApi/FactsDownloader.js +0 -124
  67. package/build/services/SecEdgarApi/SecConnector.d.ts +0 -47
  68. package/build/services/SecEdgarApi/SecConnector.js +0 -143
  69. package/build/services/SecEdgarApi/Unzipper.d.ts +0 -40
  70. package/build/services/SecEdgarApi/Unzipper.js +0 -40
@@ -1,52 +1,108 @@
1
- import { CompanyFactFrame, CompanyFactListData, MultiCompanyFactFrame, ReportRaw, SubmissionList } from '../../types';
1
+ import { CompanyFactFrame, CompanyFactListData, CompanyTickerItem, FieldDataResponse, Holder, InsiderTransaction, MultiCompanyFactFrame, ReportRaw, ReportTranslated, TableData } from '../../types';
2
+ import { FilingListDetails, FilingListItemTranslated, SubmissionList } from '../../types/submission.type';
3
+ import { IClient } from '../Client';
4
+ import DocumentParser from '../DocumentParser';
2
5
  import ReportParser from '../ReportParser';
3
6
  import { ParseReportsOptions } from '../ReportParser/ReportRawParser';
4
7
  import ReportWrapper from '../ReportParser/ReportWrapper';
5
- import { GetFactFrameParams, GetFactParams, GetSymbolParams, ISecConnector } from './SecConnector';
6
- interface SecEdgarApiArgs {
7
- secConnector: ISecConnector;
8
+ import SubmissionRequestWrapper from './RequestWrapper';
9
+ import { IThrottler } from './Throttler';
10
+ interface SecApiArgs {
11
+ throttler: IThrottler;
12
+ client: IClient;
13
+ cikBySymbol: Record<string, number>;
8
14
  reportParser: ReportParser;
15
+ documentParser: DocumentParser;
16
+ }
17
+ export interface CreateRequestWrapperParams {
18
+ /** symbol or cik */
19
+ symbol: string | number;
20
+ filings: FilingListDetails | FilingListItemTranslated[];
21
+ /** earliest allowed filing date that is allowed to be fetched */
22
+ cutoffDate?: Date;
23
+ maxRequests?: number;
24
+ }
25
+ export interface GetSymbolParams {
26
+ /** symbol or cik */
27
+ symbol: string | number;
28
+ }
29
+ export interface GetReportsParams {
30
+ /** symbol or cik */
31
+ symbol: string | number;
32
+ withWrapper?: boolean;
33
+ usePropertyResolver?: boolean;
34
+ }
35
+ export interface GetFactParams {
36
+ /** symbol or cik */
37
+ symbol: string | number;
38
+ fact: string;
39
+ taxonomy?: 'us-gaap' | 'dei' | 'invest' | string;
40
+ }
41
+ export interface GetFactFrameParams {
42
+ fact: string;
43
+ frame: string;
44
+ unit?: 'pure' | 'USD' | 'shares' | string;
45
+ taxonomy?: 'us-gaap' | 'dei' | 'invest' | string;
46
+ }
47
+ export interface GetDocumentXMLParams {
48
+ /** symbol or cik */
49
+ symbol: string | number;
50
+ accessionNumber: string;
51
+ primaryDocument: string;
52
+ }
53
+ export interface GetSubmissionsParams {
54
+ /** symbol or cik */
55
+ symbol: string;
56
+ includeTranslated?: boolean;
9
57
  }
10
58
  /**
11
- * Gets company reports and filings from the SEC EDGAR API
12
- *
13
- * Requests are throttled with 120ms delay between requests to avoid rate limiting
59
+ * Gets reports from companies filed with the SEC
14
60
  *
15
61
  * @see https://www.sec.gov/edgar/sec-api-documentation
16
62
  */
17
63
  export default class SecEdgarApi {
18
- private readonly reportParser;
19
- private readonly secConnector;
20
- constructor(args?: SecEdgarApiArgs);
64
+ private readonly baseUrlEdgar;
65
+ private readonly baseUrlSec;
66
+ private readonly throttler;
67
+ private readonly client;
68
+ readonly cikBySymbol: Record<string, number>;
69
+ readonly reportParser: ReportParser;
70
+ readonly documentParser: DocumentParser;
71
+ constructor(args?: SecApiArgs);
72
+ private request;
73
+ private mapFilingListDetails;
74
+ private getCreateRequestSubmissions;
75
+ /**
76
+ * If symbol is not in cikBySymbol, assume it is a cik. does not make a request
77
+ */
78
+ getCikString(symbol: string | number): string;
21
79
  /**
22
- * endpoint: /submissions/CIK${cik}.json
23
- *
24
80
  * This JSON data structure contains metadata such as current name, former name,
25
81
  * and stock exchanges and ticker symbols of publicly-traded companies. The object’s
26
82
  * property path contains at least one year’s of filing or to 1,000 (whichever is more)
27
83
  * of the most recent filings in a compact columnar data array. If the entity has
28
84
  * additional filings, files will contain an array of additional JSON files and the
29
85
  * date range for the filings each one contains.
30
- */
31
- getSubmissions(params: GetSymbolParams): Promise<SubmissionList>;
32
- /**
33
- * endpoint /api/xbrl/companyconcept/CIK${cik}/${taxonomy}/${fact}.json
34
86
  *
35
- * This API returns all the company concepts data for a company into a single API call:
87
+ * endpoint: `/submissions/CIK${cik}.json`
36
88
  */
37
- getFacts(params: GetSymbolParams): Promise<CompanyFactListData>;
89
+ getSubmissions(params: GetSubmissionsParams): Promise<SubmissionList>;
38
90
  /**
39
- * endpoint /api/xbrl/companyconcept/CIK${cik}/${taxonomy}/${fact}.json
40
- *
41
91
  * The company-concept API returns all the XBRL disclosures from a single company (CIK)
42
92
  * and concept (a taxonomy and tag) into a single JSON file, with a separate array
43
93
  * of facts for each units on measure that the company has chosen to disclose
44
94
  * (e.g. net profits reported in U.S. dollars and in Canadian dollars).
95
+ *
96
+ * endpoint `/api/xbrl/companyconcept/CIK${cik}/${taxonomy}/${fact}.json`
45
97
  */
46
98
  getFact(params: GetFactParams): Promise<CompanyFactFrame>;
47
99
  /**
48
- * endpoint /api/xbrl/frames/${taxonomy}/${fact}/${unit}/${frame}.json
100
+ * Returns all the company concepts data for a company into a single API call:
49
101
  *
102
+ * endpoint `/api/xbrl/companyconcept/CIK${cik}/${taxonomy}/${fact}.json`
103
+ */
104
+ getFacts(params: GetSymbolParams): Promise<CompanyFactListData>;
105
+ /**
50
106
  * The xbrl/frames API aggregates one fact for each reporting entity that is last filed
51
107
  * that most closely fits the calendrical period requested. This API supports for annual,
52
108
  * quarterly and instantaneous data:
@@ -64,6 +120,8 @@ export default class SecEdgarApi {
64
120
  * data is assembled by the dates that best align with a calendar quarter or year. Data
65
121
  * users should be mindful different reporting start and end dates for facts contained
66
122
  * in a frame.
123
+ *
124
+ * endpoint `/api/xbrl/frames/${taxonomy}/${fact}/${unit}/${frame}.json`
67
125
  */
68
126
  getFactFrame(params: GetFactFrameParams): Promise<MultiCompanyFactFrame>;
69
127
  /**
@@ -76,11 +134,87 @@ export default class SecEdgarApi {
76
134
  * for all reports. This includes only 10-K and 10-Q annual and quarterly reports. To include
77
135
  * all reports, use getReportsRaw.
78
136
  */
79
- getReports(params: GetSymbolParams): Promise<ReportWrapper[]>;
137
+ getReports<T extends GetReportsParams>(params: T): Promise<T['withWrapper'] extends true ? ReportWrapper[] : ReportTranslated[]>;
80
138
  /**
81
139
  * Parses reports from company facts. Calculates missing properties and uses a single interface
82
140
  * for all reports.
83
141
  */
84
142
  getReportsRaw(params: GetSymbolParams & ParseReportsOptions): Promise<ReportRaw[]>;
143
+ /**
144
+ * Gets a list of all tickers and CIKs from `https://www.sec.gov/files/company_tickers.json`
145
+ *
146
+ * Note that they key cik_str is actually a number. To get cik string, you can do `${cik_str}`.padStart(10, '0')
147
+ */
148
+ getCompanyTickerList(): Promise<CompanyTickerItem[]>;
149
+ /**
150
+ * Gets a list of all tickers and CIKs with exchange and company name from `https://www.sec.gov/files/company_tickers_exchange.json`
151
+ *
152
+ * response: { fields: ['cik', 'name', 'ticker', 'exchange'], data: [ [320193,'Apple Inc.','AAPL','Nasdaq'], ... ] }
153
+ */
154
+ getCompanyTickerExchangeList(): Promise<FieldDataResponse<'cik' | 'name' | 'ticker' | 'exchange'>>;
155
+ /**
156
+ * Gets a list of all mutual funds from `https://www.sec.gov/files/company_tickers_mf.json`
157
+ *
158
+ * response: { fields: ['cik','seriesId','classId','symbol'], data: [ [2110,'S000009184','C000024954','LACAX'], ... ] }
159
+ */
160
+ getMutualFundList(): Promise<FieldDataResponse<'cik' | 'seriesId' | 'classId' | 'symbol'>>;
161
+ /**
162
+ * Gets a raw xml document string. the parameters are found in the submission list response. (response.filings.recent or response.filings.recentTranslated)
163
+ *
164
+ * Some form types can be parsed using the DocumentParser such as form 4 (insider transactions) and form 13g (institutional holders)
165
+ *
166
+ * endpoint: `https://www.sec.gov/Archives/edgar/data/${cik}/${accessionNumber}/${primaryDocument}`
167
+ *
168
+ * @see https://www.sec.gov/forms for a list of form types
169
+ */
170
+ getDocumentXML(params: GetDocumentXMLParams): Promise<string>;
171
+ /**
172
+ * Gets a raw xml document string. the url is found in the submission list response. (response.filings.recentTranslated.url)
173
+ *
174
+ * Some form types can be parsed using the DocumentParser such as form 4 (insider transactions) and form 13g (institutional holders)
175
+ *
176
+ * endpoint: `https://www.sec.gov/Archives/edgar/data/${cik}/${accessionNumber}/${primaryDocument}`
177
+ *
178
+ * @see https://www.sec.gov/forms for a list of form types
179
+ */
180
+ getDocumentXMLByUrl(params: {
181
+ url: string;
182
+ }): Promise<string>;
183
+ /**
184
+ * Used for getting insider transactions. extracts insider transaction urls from submission list response, and parses the xml doc.
185
+ *
186
+ * ```ts
187
+ * const submissions = await secEdgarApi.getSubmissions({ symbol: 'AAPL' })
188
+ * const requestWrapper = secEdgarApi.createRequestInsiderTransactions({ symbol: 'AAPL', filings: submissions.filings.recent })
189
+ *
190
+ * const transactions1 = (await requestWrapper.requestNext()).result // array of transactions from most recent doc
191
+ * const transactions2 = (await requestWrapper.requestNext()).result // array of transactions from second most recent doc
192
+ * ```
193
+ */
194
+ createRequestInsiderTransactions(params: CreateRequestWrapperParams): SubmissionRequestWrapper<InsiderTransaction[]>;
195
+ /**
196
+ * Used for getting institutional holders. extracts holders urls from submission list response, and parses the xml doc.
197
+ *
198
+ * ```ts
199
+ * const submissions = await secEdgarApi.getSubmissions({ symbol: 'AAPL' })
200
+ * const requestWrapper = secEdgarApi.createRequestHolders({ symbol: 'AAPL', filings: submissions.filings.recent })
201
+ *
202
+ * const holders1 = (await requestWrapper.requestNext()).result // array of holders from most recent doc
203
+ * const holders2 = (await requestWrapper.requestNext()).result // array of holders from second most recent doc
204
+ * ```
205
+ */
206
+ createRequestHolders(params: CreateRequestWrapperParams): SubmissionRequestWrapper<Holder[]>;
207
+ /**
208
+ * Used for getting earnings report tables from submission files.
209
+ *
210
+ * ```ts
211
+ * const submissions = await secEdgarApi.getSubmissions({ symbol: 'AAPL' })
212
+ * const requestWrapper = secEdgarApi.createRequesEarningsReports({ symbol: 'AAPL', filings: submissions.filings.recent })
213
+ *
214
+ * const tables1 = (await requestWrapper.requestNext()).result // array of tables from most recent doc
215
+ * const tables2 = (await requestWrapper.requestNext()).result // array of tables from second most recent doc
216
+ * ```
217
+ */
218
+ createRequestEarningsReports(params: CreateRequestWrapperParams): SubmissionRequestWrapper<TableData[]>;
85
219
  }
86
220
  export {};
@@ -36,72 +36,180 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
+ var cik_by_symbol_1 = require("../../util/cik-by-symbol");
40
+ var Client_1 = require("../Client");
41
+ var DocumentParser_1 = require("../DocumentParser");
39
42
  var ReportParser_1 = require("../ReportParser");
40
- var SecConnector_1 = require("./SecConnector");
43
+ var RequestWrapper_1 = require("./RequestWrapper");
44
+ var Throttler_1 = require("./Throttler");
41
45
  /**
42
- * Gets company reports and filings from the SEC EDGAR API
43
- *
44
- * Requests are throttled with 120ms delay between requests to avoid rate limiting
46
+ * Gets reports from companies filed with the SEC
45
47
  *
46
48
  * @see https://www.sec.gov/edgar/sec-api-documentation
47
49
  */
48
50
  var SecEdgarApi = /** @class */ (function () {
49
51
  function SecEdgarApi(args) {
50
52
  if (args === void 0) { args = {
51
- secConnector: new SecConnector_1.default(),
53
+ client: new Client_1.default(),
54
+ throttler: new Throttler_1.default(),
55
+ cikBySymbol: cik_by_symbol_1.default,
52
56
  reportParser: new ReportParser_1.default(),
57
+ documentParser: new DocumentParser_1.default(),
53
58
  }; }
54
- var secConnector = args.secConnector, reportParser = args.reportParser;
55
- this.secConnector = secConnector;
59
+ var client = args.client, throttler = args.throttler, cikBySymbol = args.cikBySymbol, reportParser = args.reportParser, documentParser = args.documentParser;
60
+ this.client = client;
61
+ this.throttler = throttler;
62
+ this.cikBySymbol = cikBySymbol;
56
63
  this.reportParser = reportParser;
64
+ this.documentParser = documentParser;
65
+ this.baseUrlEdgar = 'https://data.sec.gov';
66
+ this.baseUrlSec = 'https://www.sec.gov';
57
67
  }
68
+ SecEdgarApi.prototype.request = function (url, isText) {
69
+ if (isText === void 0) { isText = false; }
70
+ return __awaiter(this, void 0, void 0, function () {
71
+ var _this = this;
72
+ return __generator(this, function (_a) {
73
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
74
+ var _this = this;
75
+ return __generator(this, function (_a) {
76
+ this.throttler.add(function () { return __awaiter(_this, void 0, void 0, function () {
77
+ var response, responseData, e_1;
78
+ var _a, _b;
79
+ return __generator(this, function (_c) {
80
+ switch (_c.label) {
81
+ case 0:
82
+ _c.trys.push([0, 2, , 3]);
83
+ return [4 /*yield*/, this.client.request({
84
+ url: url,
85
+ onError: function (err) { return reject(err); },
86
+ })];
87
+ case 1:
88
+ response = _c.sent();
89
+ responseData = (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.toString('utf-8')) !== null && _b !== void 0 ? _b : null;
90
+ if (response.statusCode >= 400 || typeof responseData !== 'string') {
91
+ reject("Request failed with status ".concat(response.statusCode, " ").concat(response.message));
92
+ }
93
+ resolve((isText ? responseData : JSON.parse(responseData)));
94
+ return [3 /*break*/, 3];
95
+ case 2:
96
+ e_1 = _c.sent();
97
+ reject(e_1);
98
+ return [3 /*break*/, 3];
99
+ case 3: return [2 /*return*/];
100
+ }
101
+ });
102
+ }); });
103
+ return [2 /*return*/];
104
+ });
105
+ }); })];
106
+ });
107
+ });
108
+ };
109
+ SecEdgarApi.prototype.mapFilingListDetails = function (cik, filingListDetails) {
110
+ var _a;
111
+ var filings = [];
112
+ for (var key in filingListDetails) {
113
+ var k = key;
114
+ var dataArr = filingListDetails[k];
115
+ for (var i = 0; i < dataArr.length; i++) {
116
+ filings[i] = (_a = filings[i]) !== null && _a !== void 0 ? _a : {};
117
+ var filing = filings[i];
118
+ filing[k] = dataArr[i];
119
+ }
120
+ }
121
+ for (var _i = 0, filings_1 = filings; _i < filings_1.length; _i++) {
122
+ var filing = filings_1[_i];
123
+ var accessionStr = filing.accessionNumber.replace(/-/g, '');
124
+ var primaryDocument = filing.primaryDocument;
125
+ filing.url = "https://www.sec.gov/Archives/edgar/data/".concat(Number(cik), "/").concat(accessionStr, "/").concat(primaryDocument);
126
+ }
127
+ return filings;
128
+ };
129
+ SecEdgarApi.prototype.getCreateRequestSubmissions = function (params, forms) {
130
+ var symbol = params.symbol, filings = params.filings, _a = params.cutoffDate, cutoffDate = _a === void 0 ? new Date('1970-01-01') : _a;
131
+ var cik = this.getCikString(symbol);
132
+ var filingsArr = Array.isArray(filings) ? filings : this.mapFilingListDetails(cik, filings);
133
+ return filingsArr.filter(function (_a) {
134
+ var form = _a.form, filingDate = _a.filingDate;
135
+ return forms.includes(form) && new Date(filingDate).getTime() > cutoffDate.getTime();
136
+ });
137
+ };
138
+ /**
139
+ * If symbol is not in cikBySymbol, assume it is a cik. does not make a request
140
+ */
141
+ SecEdgarApi.prototype.getCikString = function (symbol) {
142
+ var cik = this.cikBySymbol[symbol];
143
+ if (cik)
144
+ return cik.toString().padStart(10, '0');
145
+ if (!isNaN(Number(symbol)))
146
+ return Number(symbol).toString().padStart(10, '0');
147
+ throw new Error("".concat(symbol, " is not a known symbol or valid cik"));
148
+ };
58
149
  /**
59
- * endpoint: /submissions/CIK${cik}.json
60
- *
61
150
  * This JSON data structure contains metadata such as current name, former name,
62
151
  * and stock exchanges and ticker symbols of publicly-traded companies. The object’s
63
152
  * property path contains at least one year’s of filing or to 1,000 (whichever is more)
64
153
  * of the most recent filings in a compact columnar data array. If the entity has
65
154
  * additional filings, files will contain an array of additional JSON files and the
66
155
  * date range for the filings each one contains.
156
+ *
157
+ * endpoint: `/submissions/CIK${cik}.json`
67
158
  */
68
159
  SecEdgarApi.prototype.getSubmissions = function (params) {
69
160
  return __awaiter(this, void 0, void 0, function () {
161
+ var symbol, includeTranslated, cik, submissions;
70
162
  return __generator(this, function (_a) {
71
- return [2 /*return*/, this.secConnector.getSubmissions(params)];
163
+ switch (_a.label) {
164
+ case 0:
165
+ symbol = params.symbol, includeTranslated = params.includeTranslated;
166
+ cik = this.getCikString(symbol);
167
+ return [4 /*yield*/, this.request("".concat(this.baseUrlEdgar, "/submissions/CIK").concat(cik, ".json"))];
168
+ case 1:
169
+ submissions = _a.sent();
170
+ submissions.cik = Number(submissions.cik);
171
+ if (!includeTranslated)
172
+ return [2 /*return*/, submissions];
173
+ submissions.filings.recentTranslated = this.mapFilingListDetails(cik, submissions.filings.recent);
174
+ return [2 /*return*/, submissions];
175
+ }
72
176
  });
73
177
  });
74
178
  };
75
179
  /**
76
- * endpoint /api/xbrl/companyconcept/CIK${cik}/${taxonomy}/${fact}.json
180
+ * The company-concept API returns all the XBRL disclosures from a single company (CIK)
181
+ * and concept (a taxonomy and tag) into a single JSON file, with a separate array
182
+ * of facts for each units on measure that the company has chosen to disclose
183
+ * (e.g. net profits reported in U.S. dollars and in Canadian dollars).
77
184
  *
78
- * This API returns all the company concepts data for a company into a single API call:
185
+ * endpoint `/api/xbrl/companyconcept/CIK${cik}/${taxonomy}/${fact}.json`
79
186
  */
80
- SecEdgarApi.prototype.getFacts = function (params) {
187
+ SecEdgarApi.prototype.getFact = function (params) {
81
188
  return __awaiter(this, void 0, void 0, function () {
82
- return __generator(this, function (_a) {
83
- return [2 /*return*/, this.secConnector.getFacts(params)];
189
+ var symbol, fact, _a, taxonomy, cik;
190
+ return __generator(this, function (_b) {
191
+ symbol = params.symbol, fact = params.fact, _a = params.taxonomy, taxonomy = _a === void 0 ? 'us-gaap' : _a;
192
+ cik = this.getCikString(symbol);
193
+ return [2 /*return*/, this.request("".concat(this.baseUrlEdgar, "/api/xbrl/companyconcept/CIK").concat(cik, "/").concat(taxonomy, "/").concat(fact, ".json"))];
84
194
  });
85
195
  });
86
196
  };
87
197
  /**
88
- * endpoint /api/xbrl/companyconcept/CIK${cik}/${taxonomy}/${fact}.json
198
+ * Returns all the company concepts data for a company into a single API call:
89
199
  *
90
- * The company-concept API returns all the XBRL disclosures from a single company (CIK)
91
- * and concept (a taxonomy and tag) into a single JSON file, with a separate array
92
- * of facts for each units on measure that the company has chosen to disclose
93
- * (e.g. net profits reported in U.S. dollars and in Canadian dollars).
200
+ * endpoint `/api/xbrl/companyconcept/CIK${cik}/${taxonomy}/${fact}.json`
94
201
  */
95
- SecEdgarApi.prototype.getFact = function (params) {
202
+ SecEdgarApi.prototype.getFacts = function (params) {
96
203
  return __awaiter(this, void 0, void 0, function () {
204
+ var symbol, cik;
97
205
  return __generator(this, function (_a) {
98
- return [2 /*return*/, this.secConnector.getFact(params)];
206
+ symbol = params.symbol;
207
+ cik = this.getCikString(symbol);
208
+ return [2 /*return*/, this.request("".concat(this.baseUrlEdgar, "/api/xbrl/companyfacts/CIK").concat(cik, ".json"))];
99
209
  });
100
210
  });
101
211
  };
102
212
  /**
103
- * endpoint /api/xbrl/frames/${taxonomy}/${fact}/${unit}/${frame}.json
104
- *
105
213
  * The xbrl/frames API aggregates one fact for each reporting entity that is last filed
106
214
  * that most closely fits the calendrical period requested. This API supports for annual,
107
215
  * quarterly and instantaneous data:
@@ -119,11 +227,15 @@ var SecEdgarApi = /** @class */ (function () {
119
227
  * data is assembled by the dates that best align with a calendar quarter or year. Data
120
228
  * users should be mindful different reporting start and end dates for facts contained
121
229
  * in a frame.
230
+ *
231
+ * endpoint `/api/xbrl/frames/${taxonomy}/${fact}/${unit}/${frame}.json`
122
232
  */
123
233
  SecEdgarApi.prototype.getFactFrame = function (params) {
124
234
  return __awaiter(this, void 0, void 0, function () {
125
- return __generator(this, function (_a) {
126
- return [2 /*return*/, this.secConnector.getFactFrame(params)];
235
+ var fact, frame, _a, taxonomy, _b, unit;
236
+ return __generator(this, function (_c) {
237
+ fact = params.fact, frame = params.frame, _a = params.taxonomy, taxonomy = _a === void 0 ? 'us-gaap' : _a, _b = params.unit, unit = _b === void 0 ? 'pure' : _b;
238
+ return [2 /*return*/, this.request("".concat(this.baseUrlEdgar, "/api/xbrl/frames/").concat(taxonomy, "/").concat(fact, "/").concat(unit, "/").concat(frame, ".json"))];
127
239
  });
128
240
  });
129
241
  };
@@ -139,13 +251,16 @@ var SecEdgarApi = /** @class */ (function () {
139
251
  */
140
252
  SecEdgarApi.prototype.getReports = function (params) {
141
253
  return __awaiter(this, void 0, void 0, function () {
142
- var facts;
143
- return __generator(this, function (_a) {
144
- switch (_a.label) {
145
- case 0: return [4 /*yield*/, this.getFacts(params)];
254
+ var symbol, _a, withWrapper, _b, usePropertyResolver, facts, reports;
255
+ return __generator(this, function (_c) {
256
+ switch (_c.label) {
257
+ case 0:
258
+ symbol = params.symbol, _a = params.withWrapper, withWrapper = _a === void 0 ? false : _a, _b = params.usePropertyResolver, usePropertyResolver = _b === void 0 ? true : _b;
259
+ return [4 /*yield*/, this.getFacts({ symbol: symbol })];
146
260
  case 1:
147
- facts = _a.sent();
148
- return [2 /*return*/, this.reportParser.parseReports(facts)];
261
+ facts = _c.sent();
262
+ reports = this.reportParser.parseReports(facts, usePropertyResolver);
263
+ return [2 /*return*/, withWrapper ? reports : reports.map(function (report) { return report.getReport(); })];
149
264
  }
150
265
  });
151
266
  });
@@ -167,6 +282,173 @@ var SecEdgarApi = /** @class */ (function () {
167
282
  });
168
283
  });
169
284
  };
285
+ /**
286
+ * Gets a list of all tickers and CIKs from `https://www.sec.gov/files/company_tickers.json`
287
+ *
288
+ * Note that they key cik_str is actually a number. To get cik string, you can do `${cik_str}`.padStart(10, '0')
289
+ */
290
+ SecEdgarApi.prototype.getCompanyTickerList = function () {
291
+ return __awaiter(this, void 0, void 0, function () {
292
+ var response;
293
+ return __generator(this, function (_a) {
294
+ switch (_a.label) {
295
+ case 0: return [4 /*yield*/, this.request("".concat(this.baseUrlSec, "/files/company_tickers.json"))];
296
+ case 1:
297
+ response = _a.sent();
298
+ return [2 /*return*/, Object.values(response)];
299
+ }
300
+ });
301
+ });
302
+ };
303
+ /**
304
+ * Gets a list of all tickers and CIKs with exchange and company name from `https://www.sec.gov/files/company_tickers_exchange.json`
305
+ *
306
+ * response: { fields: ['cik', 'name', 'ticker', 'exchange'], data: [ [320193,'Apple Inc.','AAPL','Nasdaq'], ... ] }
307
+ */
308
+ SecEdgarApi.prototype.getCompanyTickerExchangeList = function () {
309
+ return __awaiter(this, void 0, void 0, function () {
310
+ return __generator(this, function (_a) {
311
+ return [2 /*return*/, this.request("".concat(this.baseUrlSec, "/files/company_tickers_exchange.json"))];
312
+ });
313
+ });
314
+ };
315
+ /**
316
+ * Gets a list of all mutual funds from `https://www.sec.gov/files/company_tickers_mf.json`
317
+ *
318
+ * response: { fields: ['cik','seriesId','classId','symbol'], data: [ [2110,'S000009184','C000024954','LACAX'], ... ] }
319
+ */
320
+ SecEdgarApi.prototype.getMutualFundList = function () {
321
+ return __awaiter(this, void 0, void 0, function () {
322
+ return __generator(this, function (_a) {
323
+ return [2 /*return*/, this.request("".concat(this.baseUrlSec, "/files/company_tickers_mf.json"))];
324
+ });
325
+ });
326
+ };
327
+ /**
328
+ * Gets a raw xml document string. the parameters are found in the submission list response. (response.filings.recent or response.filings.recentTranslated)
329
+ *
330
+ * Some form types can be parsed using the DocumentParser such as form 4 (insider transactions) and form 13g (institutional holders)
331
+ *
332
+ * endpoint: `https://www.sec.gov/Archives/edgar/data/${cik}/${accessionNumber}/${primaryDocument}`
333
+ *
334
+ * @see https://www.sec.gov/forms for a list of form types
335
+ */
336
+ SecEdgarApi.prototype.getDocumentXML = function (params) {
337
+ return __awaiter(this, void 0, void 0, function () {
338
+ var accessionNumber, primaryDocument, symbol, cik;
339
+ return __generator(this, function (_a) {
340
+ accessionNumber = params.accessionNumber, primaryDocument = params.primaryDocument, symbol = params.symbol;
341
+ cik = this.cikBySymbol[symbol];
342
+ return [2 /*return*/, this.request("".concat(this.baseUrlSec, "/Archives/edgar/data/").concat(cik, "/").concat(accessionNumber.replace(/-/g, ''), "/").concat(primaryDocument), true)];
343
+ });
344
+ });
345
+ };
346
+ /**
347
+ * Gets a raw xml document string. the url is found in the submission list response. (response.filings.recentTranslated.url)
348
+ *
349
+ * Some form types can be parsed using the DocumentParser such as form 4 (insider transactions) and form 13g (institutional holders)
350
+ *
351
+ * endpoint: `https://www.sec.gov/Archives/edgar/data/${cik}/${accessionNumber}/${primaryDocument}`
352
+ *
353
+ * @see https://www.sec.gov/forms for a list of form types
354
+ */
355
+ SecEdgarApi.prototype.getDocumentXMLByUrl = function (params) {
356
+ return __awaiter(this, void 0, void 0, function () {
357
+ return __generator(this, function (_a) {
358
+ return [2 /*return*/, this.request(params.url, true)];
359
+ });
360
+ });
361
+ };
362
+ /**
363
+ * Used for getting insider transactions. extracts insider transaction urls from submission list response, and parses the xml doc.
364
+ *
365
+ * ```ts
366
+ * const submissions = await secEdgarApi.getSubmissions({ symbol: 'AAPL' })
367
+ * const requestWrapper = secEdgarApi.createRequestInsiderTransactions({ symbol: 'AAPL', filings: submissions.filings.recent })
368
+ *
369
+ * const transactions1 = (await requestWrapper.requestNext()).result // array of transactions from most recent doc
370
+ * const transactions2 = (await requestWrapper.requestNext()).result // array of transactions from second most recent doc
371
+ * ```
372
+ */
373
+ SecEdgarApi.prototype.createRequestInsiderTransactions = function (params) {
374
+ var _this = this;
375
+ var submissions = this.getCreateRequestSubmissions(params, ['4', '4/A', '5', '5/A']);
376
+ var options = { maxRequests: params.maxRequests };
377
+ var sendRequest = function (params) { return __awaiter(_this, void 0, void 0, function () {
378
+ var _a, _b;
379
+ var _c;
380
+ return __generator(this, function (_d) {
381
+ switch (_d.label) {
382
+ case 0:
383
+ _b = (_a = this.documentParser).parseInsiderTransactions;
384
+ _c = {};
385
+ return [4 /*yield*/, this.getDocumentXMLByUrl(params)];
386
+ case 1: return [2 /*return*/, _b.apply(_a, [(_c.xml = _d.sent(), _c)])];
387
+ }
388
+ });
389
+ }); };
390
+ return new RequestWrapper_1.default({ submissions: submissions, options: options, sendRequest: sendRequest });
391
+ };
392
+ /**
393
+ * Used for getting institutional holders. extracts holders urls from submission list response, and parses the xml doc.
394
+ *
395
+ * ```ts
396
+ * const submissions = await secEdgarApi.getSubmissions({ symbol: 'AAPL' })
397
+ * const requestWrapper = secEdgarApi.createRequestHolders({ symbol: 'AAPL', filings: submissions.filings.recent })
398
+ *
399
+ * const holders1 = (await requestWrapper.requestNext()).result // array of holders from most recent doc
400
+ * const holders2 = (await requestWrapper.requestNext()).result // array of holders from second most recent doc
401
+ * ```
402
+ */
403
+ SecEdgarApi.prototype.createRequestHolders = function (params) {
404
+ var _this = this;
405
+ var submissions = this.getCreateRequestSubmissions(params, ['SC 13G', 'SC 13G/A']);
406
+ var options = { maxRequests: params.maxRequests };
407
+ var sendRequest = function (params) { return __awaiter(_this, void 0, void 0, function () {
408
+ var _a, _b;
409
+ var _c;
410
+ return __generator(this, function (_d) {
411
+ switch (_d.label) {
412
+ case 0:
413
+ _b = (_a = this.documentParser).parseHolders;
414
+ _c = {};
415
+ return [4 /*yield*/, this.getDocumentXMLByUrl(params)];
416
+ case 1: return [2 /*return*/, _b.apply(_a, [(_c.xml = _d.sent(), _c)])];
417
+ }
418
+ });
419
+ }); };
420
+ return new RequestWrapper_1.default({ submissions: submissions, options: options, sendRequest: sendRequest });
421
+ };
422
+ /**
423
+ * Used for getting earnings report tables from submission files.
424
+ *
425
+ * ```ts
426
+ * const submissions = await secEdgarApi.getSubmissions({ symbol: 'AAPL' })
427
+ * const requestWrapper = secEdgarApi.createRequesEarningsReports({ symbol: 'AAPL', filings: submissions.filings.recent })
428
+ *
429
+ * const tables1 = (await requestWrapper.requestNext()).result // array of tables from most recent doc
430
+ * const tables2 = (await requestWrapper.requestNext()).result // array of tables from second most recent doc
431
+ * ```
432
+ */
433
+ SecEdgarApi.prototype.createRequestEarningsReports = function (params) {
434
+ var _this = this;
435
+ var submissions = this.getCreateRequestSubmissions(params, ['10-Q', '10-Q/A', '10-K', '10-K/A']);
436
+ var options = { maxRequests: params.maxRequests };
437
+ var sendRequest = function (params) { return __awaiter(_this, void 0, void 0, function () {
438
+ var _a, _b;
439
+ var _c;
440
+ return __generator(this, function (_d) {
441
+ switch (_d.label) {
442
+ case 0:
443
+ _b = (_a = this.documentParser).parseEarningsTables;
444
+ _c = {};
445
+ return [4 /*yield*/, this.getDocumentXMLByUrl(params)];
446
+ case 1: return [2 /*return*/, _b.apply(_a, [(_c.xml = _d.sent(), _c)])];
447
+ }
448
+ });
449
+ }); };
450
+ return new RequestWrapper_1.default({ submissions: submissions, options: options, sendRequest: sendRequest });
451
+ };
170
452
  return SecEdgarApi;
171
453
  }());
172
454
  exports.default = SecEdgarApi;
@@ -0,0 +1,12 @@
1
+ export interface XMLParams {
2
+ xml: string;
3
+ }
4
+ export interface CompanyTickerItem {
5
+ cik_str: number;
6
+ ticker: string;
7
+ title: string;
8
+ }
9
+ export interface FieldDataResponse<Field extends string = string> {
10
+ fields: Field[];
11
+ data: (string | number)[][];
12
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });