sec-edgar-api 0.2.1 → 0.2.2

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 (73) hide show
  1. package/README.md +3 -5
  2. package/build/services/DocumentParser/HtmlTableExtractor.d.ts +41 -0
  3. package/build/services/DocumentParser/HtmlTableExtractor.js +408 -0
  4. package/build/services/DocumentParser/XMLParser.d.ts +20 -5
  5. package/build/services/DocumentParser/XMLParser.js +122 -118
  6. package/build/services/DocumentParser/parsers/index.d.ts +5 -3
  7. package/build/services/DocumentParser/parsers/index.js +5 -3
  8. package/build/services/DocumentParser/parsers/parse-current-filings.d.ts +3 -0
  9. package/build/services/DocumentParser/parsers/parse-current-filings.js +98 -0
  10. package/build/services/DocumentParser/parsers/parse-form-13f.d.ts +6 -0
  11. package/build/services/DocumentParser/parsers/parse-form-13f.js +91 -0
  12. package/build/services/DocumentParser/parsers/parse-form-13g.js +2 -2
  13. package/build/services/DocumentParser/parsers/parse-form-4.d.ts +6 -1
  14. package/build/services/DocumentParser/parsers/parse-form-4.js +134 -204
  15. package/build/services/DocumentParser/parsers/parse-form-def14a.d.ts +1 -2
  16. package/build/services/DocumentParser/parsers/parse-form-def14a.js +157 -106
  17. package/build/services/ReportBuilder/FactFiscalCalculator.d.ts +47 -0
  18. package/build/services/ReportBuilder/FactFiscalCalculator.js +228 -0
  19. package/build/services/ReportBuilder/FactPeriodResolver.d.ts +44 -0
  20. package/build/services/ReportBuilder/FactPeriodResolver.js +185 -0
  21. package/build/services/ReportBuilder/FactRecordBuilder.d.ts +7 -0
  22. package/build/services/ReportBuilder/FactRecordBuilder.js +49 -0
  23. package/build/services/ReportBuilder/FactSplitAdjuster.d.ts +39 -0
  24. package/build/services/ReportBuilder/FactSplitAdjuster.js +192 -0
  25. package/build/services/ReportBuilder/ReportBuilder.d.ts +37 -0
  26. package/build/services/ReportBuilder/ReportBuilder.js +180 -0
  27. package/build/services/ReportBuilder/ReportRawResolvable.d.ts +17 -0
  28. package/build/services/ReportBuilder/ReportRawResolvable.js +114 -0
  29. package/build/services/ReportBuilder/index.d.ts +2 -0
  30. package/build/services/ReportBuilder/index.js +4 -0
  31. package/build/services/ReportParser/FactItem.d.ts +66 -0
  32. package/build/services/ReportParser/FactItem.js +50 -0
  33. package/build/services/ReportParser/FactItemFactory.d.ts +22 -0
  34. package/build/services/ReportParser/FactItemFactory.js +150 -0
  35. package/build/services/ReportParser/FactSplitMap.d.ts +16 -0
  36. package/build/services/ReportParser/FactSplitMap.js +101 -0
  37. package/build/services/ReportParser/PropertyResolver.d.ts +1 -0
  38. package/build/services/ReportParser/PropertyResolver.js +1 -0
  39. package/build/services/ReportParser/ReportParser.d.ts +3 -10
  40. package/build/services/ReportParser/ReportParser.js +8 -23
  41. package/build/services/ReportParser/ReportRawParser.d.ts +5 -28
  42. package/build/services/ReportParser/ReportRawParser.js +29 -141
  43. package/build/services/ReportParser/ReportWrapper.js +2 -5
  44. package/build/services/ReportParser/resolvers/index.d.ts +2 -0
  45. package/build/services/ReportParser/resolvers/index.js +2 -0
  46. package/build/services/ReportParser/resolvers/resolve-cash-flow-capex.js +4 -3
  47. package/build/services/ReportParser/resolvers/resolve-cash-flow-operating.js +1 -1
  48. package/build/services/ReportParser/resolvers/resolve-cash-flow-working-capital-non-cash.js +1 -1
  49. package/build/services/ReportParser/resolvers/resolve-expense-depreciation.js +1 -1
  50. package/build/services/ReportParser/resolvers/resolve-fiscal-year-cumulative-properties.js +28 -14
  51. package/build/services/ReportParser/resolvers/resolve-q4-fiscal-year-matching-properties.js +32 -4
  52. package/build/services/ReportParser/resolvers/resolve-split-ratio.d.ts +2 -0
  53. package/build/services/ReportParser/resolvers/resolve-split-ratio.js +37 -0
  54. package/build/services/SecEdgarApi/SecEdgarApi.d.ts +85 -47
  55. package/build/services/SecEdgarApi/SecEdgarApi.js +246 -108
  56. package/build/types/current-filings-xml.type.d.ts +74 -0
  57. package/build/types/current-filings-xml.type.js +6 -0
  58. package/build/types/current-filings.type.d.ts +44 -0
  59. package/build/types/current-filings.type.js +2 -0
  60. package/build/types/form-13f-xml.type.d.ts +105 -0
  61. package/build/types/form-13f-xml.type.js +2 -0
  62. package/build/types/form-4-xml.type.d.ts +132 -0
  63. package/build/types/form-4-xml.type.js +2 -0
  64. package/build/types/index.d.ts +2 -2
  65. package/build/types/index.js +2 -2
  66. package/build/types/parsed-filings.type.d.ts +144 -5
  67. package/build/types/report-raw.type.d.ts +4 -7
  68. package/build/types/report-translated.type.d.ts +1 -2
  69. package/build/types/submission.type.d.ts +3 -2
  70. package/build/util/calculation-map-by-ns.d.ts +6 -0
  71. package/build/util/calculation-map-by-ns.js +9 -0
  72. package/build/util/key-translations.js +1 -2
  73. package/package.json +5 -2
@@ -1,4 +1,15 @@
1
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
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -38,9 +49,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
49
  Object.defineProperty(exports, "__esModule", { value: true });
39
50
  var cik_by_symbol_1 = require("../../util/cik-by-symbol");
40
51
  var Client_1 = require("../Client");
41
- var DocumentParser_1 = require("../DocumentParser");
52
+ var parsers_1 = require("../DocumentParser/parsers");
42
53
  var ReportParser_1 = require("../ReportParser");
43
- var RequestWrapper_1 = require("./RequestWrapper");
44
54
  var Throttler_1 = require("./Throttler");
45
55
  /**
46
56
  * Gets reports from companies filed with the SEC
@@ -54,14 +64,14 @@ var SecEdgarApi = /** @class */ (function () {
54
64
  throttler: new Throttler_1.default(),
55
65
  cikBySymbol: cik_by_symbol_1.default,
56
66
  reportParser: new ReportParser_1.default(),
57
- documentParser: new DocumentParser_1.default(),
67
+ parsers: parsers_1.default,
58
68
  }; }
59
- var client = args.client, throttler = args.throttler, cikBySymbol = args.cikBySymbol, reportParser = args.reportParser, documentParser = args.documentParser;
69
+ var client = args.client, throttler = args.throttler, cikBySymbol = args.cikBySymbol, reportParser = args.reportParser, parsers = args.parsers;
60
70
  this.client = client;
61
71
  this.throttler = throttler;
62
72
  this.cikBySymbol = cikBySymbol;
63
73
  this.reportParser = reportParser;
64
- this.documentParser = documentParser;
74
+ this.parsers = parsers;
65
75
  this.baseUrlEdgar = 'https://data.sec.gov';
66
76
  this.baseUrlSec = 'https://www.sec.gov';
67
77
  }
@@ -120,19 +130,77 @@ var SecEdgarApi = /** @class */ (function () {
120
130
  }
121
131
  for (var _i = 0, filings_1 = filings; _i < filings_1.length; _i++) {
122
132
  var filing = filings_1[_i];
123
- var accessionStr = filing.accessionNumber.replace(/-/g, '');
133
+ var accessionStrTrimmed = filing.accessionNumber.replace(/-/g, '');
124
134
  var primaryDocument = filing.primaryDocument;
125
- filing.url = "https://www.sec.gov/Archives/edgar/data/".concat(Number(cik), "/").concat(accessionStr, "/").concat(primaryDocument);
135
+ var urlPrefix = "".concat(this.baseUrlSec, "/Archives/edgar/data/").concat(Number(cik), "/").concat(accessionStrTrimmed);
136
+ filing.url = "".concat(urlPrefix, "/").concat(primaryDocument);
137
+ filing.urlXml = "".concat(urlPrefix, "/").concat(filing.accessionNumber, ".txt");
126
138
  }
127
139
  return filings;
128
140
  };
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();
141
+ SecEdgarApi.prototype.filterSubmissionsInFiscalPeriodAsc = function (params) {
142
+ var fiscalYearEndMonth = params.fiscalYearEndMonth, fiscalPeriod = params.fiscalPeriod, year = params.fiscalYear, submissions = params.submissions;
143
+ var monthByFiscalPeriod = {
144
+ Q1: (fiscalYearEndMonth + 3) % 12,
145
+ Q2: (fiscalYearEndMonth + 6) % 12,
146
+ Q3: (fiscalYearEndMonth + 9) % 12,
147
+ Q4: fiscalYearEndMonth,
148
+ FY: fiscalYearEndMonth,
149
+ };
150
+ var monthNum = monthByFiscalPeriod[fiscalPeriod] === 0 ? 12 : monthByFiscalPeriod[fiscalPeriod];
151
+ var monthStr = monthNum.toString().padStart(2, '0');
152
+ var isNextYear = monthByFiscalPeriod[fiscalPeriod] > fiscalYearEndMonth + 2;
153
+ var fiscalYear = isNextYear ? year + 1 : year;
154
+ var dateSearch = new Date("".concat(fiscalYear, "-").concat(monthStr, "-28"));
155
+ var submissionsFiltered = submissions.filter(function (sub) {
156
+ var subDate = new Date(sub.reportDate);
157
+ var isWithin60DaysAfter = subDate.getTime() - dateSearch.getTime() < 1000 * 60 * 60 * 24 * 60;
158
+ var isWIthin30DaysBefore = dateSearch.getTime() - subDate.getTime() < 86400000 * 30;
159
+ return isWithin60DaysAfter && isWIthin30DaysBefore;
160
+ });
161
+ submissionsFiltered.sort(function (a, b) { return new Date(a.filingDate).getTime() - new Date(b.filingDate).getTime(); });
162
+ return submissionsFiltered;
163
+ };
164
+ SecEdgarApi.prototype.extractSubmissionsWithXml = function (data) {
165
+ var _a, _b;
166
+ return __awaiter(this, void 0, void 0, function () {
167
+ var symbol, subs, documentXml, getSubmissionUrl, xml, url, submissions, submissionList, _c, recent, recentTranslated, providedSubmissions, _d, _e;
168
+ return __generator(this, function (_f) {
169
+ switch (_f.label) {
170
+ case 0:
171
+ symbol = data.symbol, subs = data.submissions, documentXml = data.documentXml, getSubmissionUrl = data.getSubmissionUrl;
172
+ xml = documentXml !== null && documentXml !== void 0 ? documentXml : null;
173
+ url = null;
174
+ submissions = [];
175
+ submissionList = subs !== null && subs !== void 0 ? subs : null;
176
+ if (!!xml) return [3 /*break*/, 7];
177
+ _c = (_a = subs === null || subs === void 0 ? void 0 : subs.filings) !== null && _a !== void 0 ? _a : {}, recent = _c.recent, recentTranslated = _c.recentTranslated;
178
+ providedSubmissions = recentTranslated !== null && recentTranslated !== void 0 ? recentTranslated : (recent ? this.mapFilingListDetails(symbol, recent) : null);
179
+ if (!(subs !== null && subs !== void 0)) return [3 /*break*/, 1];
180
+ _d = subs;
181
+ return [3 /*break*/, 3];
182
+ case 1: return [4 /*yield*/, this.getSubmissions({ symbol: symbol })];
183
+ case 2:
184
+ _d = (_f.sent());
185
+ _f.label = 3;
186
+ case 3:
187
+ submissionList = _d;
188
+ submissions = (_b = providedSubmissions !== null && providedSubmissions !== void 0 ? providedSubmissions : submissionList.filings.recentTranslated) !== null && _b !== void 0 ? _b : [];
189
+ url = getSubmissionUrl(submissions, submissionList);
190
+ if (!url) return [3 /*break*/, 5];
191
+ return [4 /*yield*/, this.getDocumentXMLByUrl({ url: url })];
192
+ case 4:
193
+ _e = _f.sent();
194
+ return [3 /*break*/, 6];
195
+ case 5:
196
+ _e = null;
197
+ _f.label = 6;
198
+ case 6:
199
+ xml = _e;
200
+ _f.label = 7;
201
+ case 7: return [2 /*return*/, { xml: xml, url: url, submissions: submissions, submissionList: submissionList }];
202
+ }
203
+ });
136
204
  });
137
205
  };
138
206
  /**
@@ -158,18 +226,16 @@ var SecEdgarApi = /** @class */ (function () {
158
226
  */
159
227
  SecEdgarApi.prototype.getSubmissions = function (params) {
160
228
  return __awaiter(this, void 0, void 0, function () {
161
- var symbol, includeTranslated, cik, submissions;
229
+ var symbol, cik, submissions;
162
230
  return __generator(this, function (_a) {
163
231
  switch (_a.label) {
164
232
  case 0:
165
- symbol = params.symbol, includeTranslated = params.includeTranslated;
233
+ symbol = params.symbol;
166
234
  cik = this.getCikString(symbol);
167
235
  return [4 /*yield*/, this.request("".concat(this.baseUrlEdgar, "/submissions/CIK").concat(cik, ".json"))];
168
236
  case 1:
169
237
  submissions = _a.sent();
170
238
  submissions.cik = Number(submissions.cik);
171
- if (!includeTranslated)
172
- return [2 /*return*/, submissions];
173
239
  submissions.filings.recentTranslated = this.mapFilingListDetails(cik, submissions.filings.recent);
174
240
  return [2 /*return*/, submissions];
175
241
  }
@@ -325,7 +391,8 @@ var SecEdgarApi = /** @class */ (function () {
325
391
  });
326
392
  };
327
393
  /**
328
- * Gets a raw xml document string. the parameters are found in the submission list response. (response.filings.recent or response.filings.recentTranslated)
394
+ * Gets a raw xml document string. the parameters are found in the submission list response.
395
+ * (response.filings.recent or response.filings.recentTranslated)
329
396
  *
330
397
  * Some form types can be parsed using the DocumentParser such as form 4 (insider transactions) and form 13g (institutional holders)
331
398
  *
@@ -335,11 +402,12 @@ var SecEdgarApi = /** @class */ (function () {
335
402
  */
336
403
  SecEdgarApi.prototype.getDocumentXML = function (params) {
337
404
  return __awaiter(this, void 0, void 0, function () {
338
- var accessionNumber, primaryDocument, symbol, cik;
405
+ var accessionNumber, primaryDocument, symbol, cik, document;
339
406
  return __generator(this, function (_a) {
340
407
  accessionNumber = params.accessionNumber, primaryDocument = params.primaryDocument, symbol = params.symbol;
341
408
  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)];
409
+ document = primaryDocument !== null && primaryDocument !== void 0 ? primaryDocument : "".concat(accessionNumber, ".txt");
410
+ return [2 /*return*/, this.request("".concat(this.baseUrlSec, "/Archives/edgar/data/").concat(cik, "/").concat(accessionNumber.replace(/-/g, ''), "/").concat(document), true)];
343
411
  });
344
412
  });
345
413
  };
@@ -360,123 +428,193 @@ var SecEdgarApi = /** @class */ (function () {
360
428
  });
361
429
  };
362
430
  /**
363
- * Used for getting insider transactions. extracts insider transaction urls from submission list response, and parses the xml doc.
431
+ * Used for getting security holdings.
432
+ *
433
+ * Forms: 13F, 13F/A, 13F-HR, 13F-HR/A
364
434
  *
365
- * ```ts
366
- * const submissions = await secEdgarApi.getSubmissions({ symbol: 'AAPL' })
367
- * const requestWrapper = secEdgarApi.createRequestInsiderTransactions({ symbol: 'AAPL', filings: submissions.filings.recent })
435
+ * Extracts holdings urls from submission list response, and parses the xml doc.
368
436
  *
369
- * const transactions1 = (await requestWrapper.requestNext()).result.transactions // array of transactions from most recent doc
370
- * const transactions2 = (await requestWrapper.requestNext()).result.transactions // array of transactions from second most recent doc
371
- * ```
437
+ * Sends 2 requests by default, 1 request if submissions is provided, and 0 requests if documentXml is provided.
438
+ *
439
+ * WARNING: XML and HTML docs can be formatted differently and is prone to innacuracies.
372
440
  */
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) {
441
+ SecEdgarApi.prototype.getHoldings = function (params) {
442
+ return __awaiter(this, void 0, void 0, function () {
443
+ var fiscalPeriod, fiscalYear, lookback, _a, submissions, url, xml, holdingsForm;
444
+ var _this = this;
445
+ return __generator(this, function (_b) {
446
+ switch (_b.label) {
382
447
  case 0:
383
- _b = (_a = this.documentParser).parseForm4;
384
- _c = {};
385
- return [4 /*yield*/, this.getDocumentXMLByUrl(params)];
386
- case 1: return [2 /*return*/, _b.apply(_a, [(_c.xml = _d.sent(), _c)])];
448
+ fiscalPeriod = params.fiscalPeriod, fiscalYear = params.fiscalYear, lookback = params.lookback;
449
+ if (!((fiscalPeriod && fiscalYear) || typeof lookback === 'number')) {
450
+ throw new Error('you must provide either both fiscalPeriod & fiscalYear, or just lookback');
451
+ }
452
+ return [4 /*yield*/, this.extractSubmissionsWithXml(__assign(__assign({}, params), { getSubmissionUrl: function (subs, submissionList) {
453
+ var _a;
454
+ var submissions = subs.filter(function (sub) { return sub === null || sub === void 0 ? void 0 : sub.form.startsWith('13F'); });
455
+ var submission = submissions[Number(lookback)];
456
+ if (fiscalPeriod && fiscalYear) {
457
+ var submissionsInPeriod = _this.filterSubmissionsInFiscalPeriodAsc({
458
+ fiscalYearEndMonth: Number(submissionList.fiscalYearEnd.substring(0, 2)),
459
+ fiscalPeriod: fiscalPeriod,
460
+ fiscalYear: fiscalYear,
461
+ submissions: submissions,
462
+ });
463
+ submission = submissionsInPeriod[0];
464
+ }
465
+ return (_a = submission === null || submission === void 0 ? void 0 : submission.urlXml) !== null && _a !== void 0 ? _a : null;
466
+ } }))];
467
+ case 1:
468
+ _a = _b.sent(), submissions = _a.submissions, url = _a.url, xml = _a.xml;
469
+ holdingsForm = xml ? this.parsers.parseForm13f({ xml: xml }) : null;
470
+ return [2 /*return*/, { url: url, holdingsForm: holdingsForm, submissions: submissions }];
387
471
  }
388
472
  });
389
- }); };
390
- return new RequestWrapper_1.default({ submissions: submissions, options: options, sendRequest: sendRequest });
473
+ });
391
474
  };
392
475
  /**
393
- * Used for getting institutional holders. extracts holders urls from submission list response, and parses the xml doc.
476
+ * Gets institutional holders that have a large stake in the company.
477
+ * If multiple submissions are found within the fiscal period, uses the first submission.
478
+ *
479
+ * Forms: SC 13G, SC 13G/A
394
480
  *
395
- * ```ts
396
- * const submissions = await secEdgarApi.getSubmissions({ symbol: 'AAPL' })
397
- * const requestWrapper = secEdgarApi.createRequestInstitutionalHolders({ symbol: 'AAPL', filings: submissions.filings.recent })
481
+ * Sends 2 requests by default, 1 request if submissions is provided, and 0 requests if documentXml is provided.
398
482
  *
399
- * const holders1 = (await requestWrapper.requestNext()).result.holders // array of holders from most recent doc
400
- * const holders2 = (await requestWrapper.requestNext()).result.holders // array of holders from second most recent doc
401
- * ```
483
+ * WARNING: XML and HTML docs can be formatted differently and is prone to innacuracies.
402
484
  */
403
- SecEdgarApi.prototype.createRequestInstitutionalHolders = 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) {
485
+ SecEdgarApi.prototype.getInstitutionalHolders = function (params) {
486
+ var _a;
487
+ return __awaiter(this, void 0, void 0, function () {
488
+ var fiscalPeriod, fiscalYear, lookback, _b, submissions, url, xml, response;
489
+ var _this = this;
490
+ return __generator(this, function (_c) {
491
+ switch (_c.label) {
412
492
  case 0:
413
- _b = (_a = this.documentParser).parseForm13g;
414
- _c = {};
415
- return [4 /*yield*/, this.getDocumentXMLByUrl(params)];
416
- case 1: return [2 /*return*/, _b.apply(_a, [(_c.xml = _d.sent(), _c)])];
493
+ fiscalPeriod = params.fiscalPeriod, fiscalYear = params.fiscalYear, lookback = params.lookback;
494
+ if (!((fiscalPeriod && fiscalYear) || typeof lookback === 'number')) {
495
+ throw new Error('you must provide either both fiscalPeriod & fiscalYear, or just lookback');
496
+ }
497
+ return [4 /*yield*/, this.extractSubmissionsWithXml(__assign(__assign({}, params), { getSubmissionUrl: function (subs, submissionList) {
498
+ var _a;
499
+ var submissions = subs.filter(function (sub) { var _a; return ['SC 13G', 'SC 13G/A'].includes(sub.form) && !((_a = sub.url) === null || _a === void 0 ? void 0 : _a.endsWith('.txt')); });
500
+ var submission = submissions[Number(lookback)];
501
+ if (fiscalPeriod && fiscalYear) {
502
+ var submissionsInPeriod = _this.filterSubmissionsInFiscalPeriodAsc({
503
+ fiscalYearEndMonth: Number(submissionList.fiscalYearEnd.substring(0, 2)),
504
+ fiscalPeriod: fiscalPeriod,
505
+ fiscalYear: fiscalYear,
506
+ submissions: submissions,
507
+ });
508
+ submission = submissionsInPeriod[0];
509
+ }
510
+ return (_a = submission === null || submission === void 0 ? void 0 : submission.url) !== null && _a !== void 0 ? _a : null;
511
+ } }))];
512
+ case 1:
513
+ _b = _c.sent(), submissions = _b.submissions, url = _b.url, xml = _b.xml;
514
+ response = xml ? this.parsers.parseForm13g({ xml: xml }) : null;
515
+ return [2 /*return*/, { url: url, institutionalHolders: (_a = response === null || response === void 0 ? void 0 : response.institutionalHolders) !== null && _a !== void 0 ? _a : [], submissions: submissions }];
417
516
  }
418
517
  });
419
- }); };
420
- return new RequestWrapper_1.default({ submissions: submissions, options: options, sendRequest: sendRequest });
518
+ });
421
519
  };
422
520
  /**
423
- * Used for getting earnings report tables from submission files.
521
+ * Gets executive compensation from the proxy statement.
522
+ *
523
+ * Forms: DEF 14A
424
524
  *
425
- * ```ts
426
- * const submissions = await secEdgarApi.getSubmissions({ symbol: 'AAPL' })
427
- * const requestWrapper = secEdgarApi.createRequesEarningsReports({ symbol: 'AAPL', filings: submissions.filings.recent })
525
+ * Sends 2 requests by default, 1 request if submissions is provided, and 0 requests if documentXml is provided.
428
526
  *
429
- * const tables1 = (await requestWrapper.requestNext()).result.tables // array of tables from most recent doc
430
- * const tables2 = (await requestWrapper.requestNext()).result.tables // array of tables from second most recent doc
431
- * ```
527
+ * WARNING: XML and HTML docs can be formatted differently and is prone to innacuracies.
432
528
  */
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) {
529
+ SecEdgarApi.prototype.getExecutivesCompensation = function (params) {
530
+ var _a;
531
+ return __awaiter(this, void 0, void 0, function () {
532
+ var fiscalYear, lookback, _b, submissions, url, xml, response;
533
+ var _this = this;
534
+ return __generator(this, function (_c) {
535
+ switch (_c.label) {
442
536
  case 0:
443
- _b = (_a = this.documentParser).parseForm10k;
444
- _c = {};
445
- return [4 /*yield*/, this.getDocumentXMLByUrl(params)];
446
- case 1: return [2 /*return*/, _b.apply(_a, [(_c.xml = _d.sent(), _c)])];
537
+ fiscalYear = params.fiscalYear, lookback = params.lookback;
538
+ if (!(fiscalYear || typeof lookback === 'number')) {
539
+ throw new Error('you must provide either both fiscalYear or lookback');
540
+ }
541
+ return [4 /*yield*/, this.extractSubmissionsWithXml(__assign(__assign({}, params), { getSubmissionUrl: function (subs, submissionList) {
542
+ var _a;
543
+ var submissions = subs.filter(function (sub) { var _a; return sub.form === 'DEF 14A' && !((_a = sub.url) === null || _a === void 0 ? void 0 : _a.endsWith('.txt')); });
544
+ // console.log('subs', submissions)
545
+ var submission = submissions[Number(lookback) || 0];
546
+ if (fiscalYear) {
547
+ var submissionsInPeriod = _this.filterSubmissionsInFiscalPeriodAsc({
548
+ fiscalYearEndMonth: Number(submissionList.fiscalYearEnd.substring(0, 2)),
549
+ fiscalPeriod: 'Q4',
550
+ fiscalYear: fiscalYear,
551
+ submissions: submissions,
552
+ });
553
+ submission = submissionsInPeriod[0];
554
+ }
555
+ return (_a = submission === null || submission === void 0 ? void 0 : submission.url) !== null && _a !== void 0 ? _a : null;
556
+ } }))];
557
+ case 1:
558
+ _b = _c.sent(), submissions = _b.submissions, url = _b.url, xml = _b.xml;
559
+ response = xml ? this.parsers.parseFormDef14a({ xml: xml }) : null;
560
+ return [2 /*return*/, { url: url, executiveCompensation: (_a = response === null || response === void 0 ? void 0 : response.executiveCompensation) !== null && _a !== void 0 ? _a : [], submissions: submissions }];
447
561
  }
448
562
  });
449
- }); };
450
- return new RequestWrapper_1.default({ submissions: submissions, options: options, sendRequest: sendRequest });
563
+ });
451
564
  };
452
565
  /**
453
- * Proxy statement includes list of holders, executiveCompensation, and other tables. returns FormDef14aData
566
+ * Gets insider transactions - when a company's executives buy or sell shares, options, or other securities in the company.
454
567
  *
455
- * ```ts
456
- * const submissions = await secEdgarApi.getSubmissions({ symbol: 'AAPL' })
457
- * const requestWrapper = secEdgarApi.createRequesProxyStatement({ symbol: 'AAPL', filings: submissions.filings.recent })
568
+ * Forms: 4, 4/A, 5, 5/A
458
569
  *
459
- * const { holders, executiveCompensation } = (await requestWrapper.requestNext()).result
460
- * ```
570
+ * Sends 2 requests by default, 1 request if submissions is provided, and 0 requests if documentXml is provided.
571
+ *
572
+ * WARNING: XML and HTML docs can be formatted differently and is prone to innacuracies.
461
573
  */
462
- SecEdgarApi.prototype.createRequestProxyStatement = function (params) {
463
- var _this = this;
464
- var submissions = this.getCreateRequestSubmissions(params, ['DEF 14A']);
465
- var options = { maxRequests: params.maxRequests };
466
- var sendRequest = function (params) { return __awaiter(_this, void 0, void 0, function () {
467
- var _a, _b;
468
- var _c;
469
- return __generator(this, function (_d) {
470
- switch (_d.label) {
574
+ SecEdgarApi.prototype.getInsiderTransaction = function (params) {
575
+ return __awaiter(this, void 0, void 0, function () {
576
+ var lookback, _a, submissions, url, xml, insiderTransaction;
577
+ return __generator(this, function (_b) {
578
+ switch (_b.label) {
471
579
  case 0:
472
- _b = (_a = this.documentParser).parseFormDef14a;
473
- _c = {};
474
- return [4 /*yield*/, this.getDocumentXMLByUrl(params)];
475
- case 1: return [2 /*return*/, _b.apply(_a, [(_c.xml = _d.sent(), _c)])];
580
+ lookback = params.lookback;
581
+ return [4 /*yield*/, this.extractSubmissionsWithXml(__assign(__assign({}, params), { getSubmissionUrl: function (subs) {
582
+ var _a, _b;
583
+ var submissions = subs.filter(function (sub) { return ['4', '4/A', '5', '5/A'].includes(sub.form); });
584
+ return (_b = (_a = submissions[lookback]) === null || _a === void 0 ? void 0 : _a.urlXml) !== null && _b !== void 0 ? _b : null;
585
+ } }))];
586
+ case 1:
587
+ _a = _b.sent(), submissions = _a.submissions, url = _a.url, xml = _a.xml;
588
+ insiderTransaction = xml ? this.parsers.parseForm4({ xml: xml }) : null;
589
+ return [2 /*return*/, { url: url, insiderTransaction: insiderTransaction, submissions: submissions }];
590
+ }
591
+ });
592
+ });
593
+ };
594
+ /**
595
+ * @see https://www.sec.gov/structureddata/rss-feeds-submitted-filings
596
+ */
597
+ SecEdgarApi.prototype.getCurrentFilings = function (params) {
598
+ return __awaiter(this, void 0, void 0, function () {
599
+ var _a, taxonomy, urlByTaxonomy, url, xml;
600
+ return __generator(this, function (_b) {
601
+ switch (_b.label) {
602
+ case 0:
603
+ _a = (params !== null && params !== void 0 ? params : {}).taxonomy, taxonomy = _a === void 0 ? 'allXbrl' : _a;
604
+ urlByTaxonomy = {
605
+ usGaap: 'https://www.sec.gov/Archives/edgar/usgaap.rss.xml',
606
+ mutualFund: 'https://www.sec.gov/Archives/edgar/xbrl-rr.rss.xml',
607
+ inlineXbrl: 'https://www.sec.gov/Archives/edgar/xbrl-inline.rss.xml',
608
+ allXbrl: 'https://www.sec.gov/Archives/edgar/xbrlrss.all.xml',
609
+ };
610
+ url = urlByTaxonomy[taxonomy] || urlByTaxonomy.allXbrl;
611
+ return [4 /*yield*/, this.request(url, true)];
612
+ case 1:
613
+ xml = _b.sent();
614
+ return [2 /*return*/, xml ? this.parsers.parseCurrentFilings({ xml: xml }) : null];
476
615
  }
477
616
  });
478
- }); };
479
- return new RequestWrapper_1.default({ submissions: submissions, options: options, sendRequest: sendRequest });
617
+ });
480
618
  };
481
619
  return SecEdgarApi;
482
620
  }());
@@ -0,0 +1,74 @@
1
+ export interface CurrentFilingsXML {
2
+ '?xml': XML;
3
+ rss: RSSXML;
4
+ }
5
+ interface XML {
6
+ '@_version': string;
7
+ '@_encoding': string;
8
+ }
9
+ interface RSSXML {
10
+ channel: ChannelXML;
11
+ '@_version': string;
12
+ }
13
+ interface ChannelXML {
14
+ title: string;
15
+ link: string;
16
+ 'atom:link': AtomLinkXML;
17
+ description: string;
18
+ language: string;
19
+ pubDate: string;
20
+ lastBuildDate: string;
21
+ item: ItemXML[];
22
+ }
23
+ interface AtomLinkXML {
24
+ '@_href': string;
25
+ '@_rel': string;
26
+ '@_type': string;
27
+ '@_xmlns:atom': string;
28
+ }
29
+ interface ItemXML {
30
+ title: string;
31
+ link: string;
32
+ guid: string;
33
+ enclosure: EnclosureXML;
34
+ description: string;
35
+ pubDate: string;
36
+ 'edgar:xbrlFiling': EdgarXbrlFilingXML;
37
+ }
38
+ interface EdgarXbrlFilingXML {
39
+ 'edgar:companyName': string;
40
+ 'edgar:formType': string;
41
+ 'edgar:filingDate': string;
42
+ 'edgar:cikNumber': number;
43
+ 'edgar:accessionNumber': string;
44
+ 'edgar:fileNumber': string;
45
+ 'edgar:acceptanceDatetime': number;
46
+ 'edgar:period'?: number;
47
+ 'edgar:assistantDirector'?: string;
48
+ 'edgar:assignedSic'?: number;
49
+ 'edgar:fiscalYearEnd'?: number;
50
+ 'edgar:xbrlFiles': EdgarXbrlFilesXML;
51
+ '@_xmlns:edgar': string;
52
+ 'edgar:otherCikNumbers'?: number | string;
53
+ }
54
+ interface EdgarXbrlFilesXML {
55
+ 'edgar:xbrlFile': EdgarXbrlFileXML[];
56
+ }
57
+ interface EdgarXbrlFileXML {
58
+ '@_edgar:sequence': string;
59
+ '@_edgar:file': string;
60
+ '@_edgar:type': string;
61
+ '@_edgar:size': string;
62
+ '@_edgar:description': string;
63
+ '@_edgar:inlineXBRL'?: string;
64
+ '@_edgar:url': string;
65
+ }
66
+ interface EnclosureXML {
67
+ '@_url': string;
68
+ '@_length': string;
69
+ '@_type': Type;
70
+ }
71
+ declare enum Type {
72
+ ApplicationZip = "application/zip"
73
+ }
74
+ export {};
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var Type;
4
+ (function (Type) {
5
+ Type["ApplicationZip"] = "application/zip";
6
+ })(Type || (Type = {}));
@@ -0,0 +1,44 @@
1
+ export interface CurrentFilingsList {
2
+ title: string;
3
+ link: string;
4
+ href: string;
5
+ description: string;
6
+ language: string;
7
+ pubDate: string;
8
+ lastBuildDate: string;
9
+ items: CurrentFiling[];
10
+ }
11
+ export interface CurrentFiling {
12
+ title: string;
13
+ link: string;
14
+ guid: string;
15
+ enclosureUrl: string;
16
+ enclosureLength: string;
17
+ enclosureType: string;
18
+ description: string;
19
+ pubDate: string;
20
+ filing: Filing;
21
+ }
22
+ export interface Filing {
23
+ companyName: string;
24
+ formType: string;
25
+ filingDate: string;
26
+ cikNumber: number;
27
+ accessionNumber: string;
28
+ fileNumber: string;
29
+ acceptanceDatetime: string;
30
+ period: string;
31
+ assistantDirector: string;
32
+ assignedSic: number;
33
+ fiscalYearEnd: string;
34
+ xbrlFiles: XbrlFile[];
35
+ }
36
+ export interface XbrlFile {
37
+ sequence: number;
38
+ file: string;
39
+ type: string;
40
+ size: number;
41
+ description: string;
42
+ inlineXBRL: boolean;
43
+ url: string;
44
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });