sec-edgar-api 0.5.0 → 0.5.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.
@@ -2,6 +2,7 @@ import { XMLParams } from '../../types';
2
2
  import { GetDocumentXbrlParams } from '../SecEdgarApi';
3
3
  import XMLParser from './XMLParserLegacy';
4
4
  import parsers from './parsers';
5
+ import { DocumentXbrlResult } from './parsers/parse-xbrl';
5
6
  interface DocumentParserArgs {
6
7
  parser?: XMLParser;
7
8
  parsersByName?: typeof parsers;
@@ -36,10 +37,6 @@ export default class DocumentParser {
36
37
  };
37
38
  parseCurrentFilings(params: XMLParams): import("../../types").CurrentFilingsList;
38
39
  parseCurrentFilingsXbrl(params: XMLParams): import("../../types").CurrentFilingsXBRL;
39
- parseXbrl(params: XMLParams & GetDocumentXbrlParams): import("./XBRLParser/XBRLParser").XbrlParseResult & {
40
- report: import("../../types").ReportRaw | null;
41
- facts: import("../../types").FactItemExtended[];
42
- xml: string;
43
- };
40
+ parseXbrl(params: XMLParams & GetDocumentXbrlParams): DocumentXbrlResult;
44
41
  }
45
42
  export {};
@@ -1,7 +1,14 @@
1
1
  export default class XMLParser {
2
2
  private readonly selfEnclosingTags;
3
+ private readonly textSelectStrategy;
4
+ private readonly tagsToIgnore;
5
+ private readonly textConcatDivider;
6
+ constructor(params?: {
7
+ textSelectStrategy?: 'useFirst' | 'useLast' | 'concatenate';
8
+ textConcatDivider?: string;
9
+ });
3
10
  mapAttributes(attributes: string[]): Map<string, string>;
4
- parse(xml: string): Record<string, unknown>;
11
+ parse(xml: string): any;
5
12
  iterateXML(params: {
6
13
  xml: string;
7
14
  onOpenTag?: (tagName: string, attributes: string[], isSelfEnclosing: boolean) => void;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var XMLParser = /** @class */ (function () {
4
- function XMLParser() {
4
+ function XMLParser(params) {
5
5
  this.selfEnclosingTags = new Set([
6
6
  '!doctype',
7
7
  '?xml',
@@ -14,6 +14,10 @@ var XMLParser = /** @class */ (function () {
14
14
  'filename',
15
15
  'description',
16
16
  ]);
17
+ this.tagsToIgnore = new Set(['script', '?xml']);
18
+ var _a = params !== null && params !== void 0 ? params : {}, _b = _a.textSelectStrategy, textSelectStrategy = _b === void 0 ? 'useFirst' : _b, _c = _a.textConcatDivider, textConcatDivider = _c === void 0 ? '<>' : _c;
19
+ this.textSelectStrategy = textSelectStrategy;
20
+ this.textConcatDivider = textConcatDivider;
17
21
  }
18
22
  XMLParser.prototype.mapAttributes = function (attributes) {
19
23
  var attributesMap = new Map();
@@ -25,6 +29,7 @@ var XMLParser = /** @class */ (function () {
25
29
  });
26
30
  return attributesMap;
27
31
  };
32
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
33
  XMLParser.prototype.parse = function (xml) {
29
34
  var _this = this;
30
35
  var currentObj = {};
@@ -35,7 +40,7 @@ var XMLParser = /** @class */ (function () {
35
40
  var newObj = {};
36
41
  var obj = currentObj;
37
42
  var isComment = tagName.startsWith('!--');
38
- if (isComment || tagName === '?xml')
43
+ if (isComment || _this.tagsToIgnore.has(tagName.toLowerCase()))
39
44
  return;
40
45
  if (obj[tagName] === undefined) {
41
46
  obj[tagName] = newObj;
@@ -60,10 +65,24 @@ var XMLParser = /** @class */ (function () {
60
65
  if (!textTrimmed)
61
66
  return;
62
67
  var obj = currentObj;
63
- obj['#text'] = textTrimmed;
68
+ switch (_this.textSelectStrategy) {
69
+ case 'useFirst':
70
+ if (obj['#text'])
71
+ return;
72
+ obj['#text'] = textTrimmed;
73
+ break;
74
+ case 'useLast':
75
+ obj['#text'] = textTrimmed;
76
+ break;
77
+ case 'concatenate':
78
+ obj['#text'] = obj['#text']
79
+ ? "".concat(obj['#text'], " ").concat(_this.textConcatDivider, " ").concat(textTrimmed)
80
+ : textTrimmed;
81
+ break;
82
+ }
64
83
  },
65
- onCloseTag: function () {
66
- if (objPath.length === 1)
84
+ onCloseTag: function (tagName) {
85
+ if (objPath.length === 1 || _this.tagsToIgnore.has(tagName.toLowerCase()))
67
86
  return;
68
87
  objPath.pop();
69
88
  currentObj = objPath[objPath.length - 1];
@@ -1,51 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseCompanies = void 0;
4
- var HtmlTableExtractor_1 = require("../../HtmlTableExtractor");
4
+ var XMLParser_1 = require("../XMLParser");
5
5
  function parseCompanies(params) {
6
- var _a, _b, _c, _d;
6
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
7
7
  var xml = params.xml;
8
- var parser = new HtmlTableExtractor_1.default();
9
- var tables = parser.extractTables(xml, {
10
- stripHtml: true,
11
- tagsToExclude: ['sup'],
12
- stripParenthesis: true,
13
- removeEmptyColumns: false,
14
- getHeaderRowIndex: function (data) {
15
- return data.rows.findIndex(function (row) {
16
- var isNotEmptyRow = row.some(function (cell) { return cell.html.replace(/<.*?>/g, '').replace(/&.*?;/g, '').replace(/\s/g, '').length > 0; });
17
- return isNotEmptyRow;
18
- });
19
- },
20
- });
21
- var header = ['cik', 'company_name', 'state_country'];
22
- var table = tables.find(function (t) { return t.rows.some(function (r) { return r.some(function (c) { return c.html.includes('CIK'); }); }); });
8
+ var parser = new XMLParser_1.default({ textSelectStrategy: 'concatenate', textConcatDivider: '<>' });
9
+ var result = parser.parse(xml);
10
+ var body = (_b = (_a = result.html) === null || _a === void 0 ? void 0 : _a.body) !== null && _b !== void 0 ? _b : {};
11
+ var bodyDivs = Array.isArray(body.div) ? body.div : [body.div].filter(Boolean);
12
+ var contentDiv = (_c = bodyDivs.find(function (d) { return d && typeof d === 'object' && d['@_id'] === 'contentDiv'; })) !== null && _c !== void 0 ? _c : {};
13
+ var tableDivs = Array.isArray(contentDiv.div) ? contentDiv.div : [contentDiv.div].filter(Boolean);
14
+ var tableDiv = (_d = tableDivs.find(function (d) { return d && typeof d === 'object' && d['@_id'] === 'seriesDiv'; })) !== null && _d !== void 0 ? _d : {};
15
+ var rows = (_j = (_f = (_e = tableDiv.table) === null || _e === void 0 ? void 0 : _e.tr) !== null && _f !== void 0 ? _f : (_h = (_g = tableDiv.table) === null || _g === void 0 ? void 0 : _g.tbody) === null || _h === void 0 ? void 0 : _h.tr) !== null && _j !== void 0 ? _j : [];
16
+ rows = (Array.isArray(rows) ? rows : [rows])
17
+ .filter(function (r) { return r === null || r === void 0 ? void 0 : r.td; })
18
+ .map(function (r) { return (Array.isArray(r.td) ? r.td : [r.td]).filter(Boolean); });
23
19
  var items = [];
24
- for (var _i = 0, _e = (_a = table === null || table === void 0 ? void 0 : table.rows) !== null && _a !== void 0 ? _a : []; _i < _e.length; _i++) {
25
- var row = _e[_i];
26
- if ((_b = row[0]) === null || _b === void 0 ? void 0 : _b.isHeaderRowCell)
20
+ for (var _i = 0, rows_1 = rows; _i < rows_1.length; _i++) {
21
+ var row = rows_1[_i];
22
+ var cik = Number((_l = (_k = row[0]) === null || _k === void 0 ? void 0 : _k.a) === null || _l === void 0 ? void 0 : _l['#text']) || 0;
23
+ if (!cik)
27
24
  continue;
28
- var item = {
29
- cik: 0,
30
- companyName: '',
31
- stateOrCountry: '',
32
- };
33
- for (var _f = 0, row_1 = row; _f < row_1.length; _f++) {
34
- var cell = row_1[_f];
35
- var colName = header[cell.colIndex];
36
- switch (colName) {
37
- case 'cik':
38
- item.cik = Number(cell.valueParsed) || 0;
39
- break;
40
- case 'company_name':
41
- item.companyName = String(((_d = (_c = cell.html.split('>')[1]) === null || _c === void 0 ? void 0 : _c.split('<')[0]) === null || _d === void 0 ? void 0 : _d.split('/')[0]) || cell.valueParsed).trim();
42
- break;
43
- case 'state_country':
44
- item.stateOrCountry = String(cell.valueParsed || '');
45
- break;
46
- }
47
- }
48
- items.push(item);
25
+ var row1Parts = (_o = (((_m = row[1]) === null || _m === void 0 ? void 0 : _m['#text']) || '').split('<>')) !== null && _o !== void 0 ? _o : [];
26
+ var sic = Number((_q = (_p = row[1]) === null || _p === void 0 ? void 0 : _p.a) === null || _q === void 0 ? void 0 : _q['#text']) || null;
27
+ var companyName = row1Parts[0].trim();
28
+ var sicDescription = sic ? ((_r = row1Parts.pop()) === null || _r === void 0 ? void 0 : _r.replace('-', '').trim()) || null : null;
29
+ var stateOrCountry = ((_t = (_s = row[2]) === null || _s === void 0 ? void 0 : _s.a) === null || _t === void 0 ? void 0 : _t['#text']) || null;
30
+ items.push({ cik: cik, sic: sic, sicDescription: sicDescription, companyName: companyName, stateOrCountry: stateOrCountry });
49
31
  }
50
32
  return { items: items };
51
33
  }
@@ -65,6 +65,7 @@ function parseCurrentFilingsXbrl(params) {
65
65
  case 'item': {
66
66
  result.items.push({
67
67
  title: '',
68
+ url: '',
68
69
  companyName: '',
69
70
  cikNumber: 0,
70
71
  link: '',
@@ -99,6 +100,13 @@ function parseCurrentFilingsXbrl(params) {
99
100
  }
100
101
  },
101
102
  });
103
+ // add url to each filing
104
+ result.items.forEach(function (item) {
105
+ var cikNumber = item.cikNumber, accessionNumber = item.accessionNumber;
106
+ var accessionNoHyphen = accessionNumber.replace(/-/g, '');
107
+ var filePath = "".concat(Number(cikNumber), "/").concat(accessionNoHyphen, "/").concat(accessionNumber, ".txt");
108
+ item.url = "https://www.sec.gov/Archives/edgar/data/".concat(filePath);
109
+ });
102
110
  return result;
103
111
  }
104
112
  exports.parseCurrentFilingsXbrl = parseCurrentFilingsXbrl;
@@ -1,8 +1,9 @@
1
1
  import type { FactItemExtended, ReportRaw, XMLParams } from '../../../types';
2
2
  import { GetDocumentXbrlParams } from '../../SecEdgarApi';
3
3
  import { XbrlParseResult } from '../XBRLParser/XBRLParser';
4
- export declare function parseXbrl(params: XMLParams & GetDocumentXbrlParams): XbrlParseResult & {
4
+ export interface DocumentXbrlResult extends XbrlParseResult {
5
5
  report: ReportRaw | null;
6
6
  facts: FactItemExtended[];
7
7
  xml: string;
8
- };
8
+ }
9
+ export declare function parseXbrl(params: XMLParams & GetDocumentXbrlParams): DocumentXbrlResult;
@@ -31,10 +31,10 @@ export default class ReportParser {
31
31
  /**
32
32
  * Same as parseReports but accepts ReportRaw[] instead of CompanyFactListData
33
33
  */
34
- parseReportsFromRaw<T = ReportTranslated>(params: {
35
- reportsRaw: ReportRaw[];
34
+ translateReport<T = ReportTranslated>(params: {
35
+ report: ReportRaw;
36
36
  calculationMap?: CalculationMap<T>;
37
- }): (ReportRaw & T)[];
37
+ }): ReportRaw & T;
38
38
  /**
39
39
  * Parse raw reports
40
40
  *
@@ -48,6 +48,8 @@ export default class ReportParser {
48
48
  */
49
49
  buildReports(params: BuildReportsParams): ReportRaw[];
50
50
  /**
51
+ * @deprecated use translateReport
52
+ *
51
53
  * Translate ReportRaw to ReportTranslated by default, but can be used to translate to any object using both the callback and keyTranslator
52
54
  *
53
55
  * @param reportsRaw this is the output of parseReportsRaw
@@ -53,31 +53,32 @@ var ReportParser = /** @class */ (function () {
53
53
  /**
54
54
  * Same as parseReports but accepts ReportRaw[] instead of CompanyFactListData
55
55
  */
56
- ReportParser.prototype.parseReportsFromRaw = function (params) {
57
- var reportsRaw = params.reportsRaw, calculationMap = params.calculationMap;
56
+ ReportParser.prototype.translateReport = function (params) {
57
+ var _a;
58
+ var report = params.report, calculationMap = params.calculationMap;
58
59
  var calcMap = calculationMap !== null && calculationMap !== void 0 ? calculationMap : this.defaultCalculationMap;
59
- return reportsRaw.map(function (report) {
60
- var _a;
61
- var reportNew = {
62
- cik: report.cik,
63
- dateFiled: report.dateFiled,
64
- dateReport: report.dateReport,
65
- fiscalPeriod: report.fiscalPeriod,
66
- url: report.url,
67
- fiscalYear: report.fiscalYear,
68
- splitDate: report.splitDate,
69
- splitRatio: report.splitRatio,
70
- };
71
- var reportResolvable = new ReportResolvable_1.default({
72
- report: report,
73
- calculationMap: calcMap,
74
- });
75
- for (var key in calcMap) {
76
- var value = (_a = reportResolvable.get(key)) !== null && _a !== void 0 ? _a : null;
60
+ var reportNew = {
61
+ cik: report.cik,
62
+ dateFiled: report.dateFiled,
63
+ dateReport: report.dateReport,
64
+ fiscalPeriod: report.fiscalPeriod,
65
+ url: report.url,
66
+ fiscalYear: report.fiscalYear,
67
+ splitDate: report.splitDate,
68
+ splitRatio: report.splitRatio,
69
+ };
70
+ var reportResolvable = new ReportResolvable_1.default({
71
+ report: report,
72
+ calculationMap: calcMap,
73
+ });
74
+ for (var key in calcMap) {
75
+ var value = (_a = reportResolvable.get(key)) !== null && _a !== void 0 ? _a : null;
76
+ // use first truthy value
77
+ if (!reportNew[key]) {
77
78
  reportNew[key] = value;
78
79
  }
79
- return reportNew;
80
- });
80
+ }
81
+ return reportNew;
81
82
  };
82
83
  /**
83
84
  * Parse raw reports
@@ -96,6 +97,8 @@ var ReportParser = /** @class */ (function () {
96
97
  return this.reportBuilder.buildReports(params);
97
98
  };
98
99
  /**
100
+ * @deprecated use translateReport
101
+ *
99
102
  * Translate ReportRaw to ReportTranslated by default, but can be used to translate to any object using both the callback and keyTranslator
100
103
  *
101
104
  * @param reportsRaw this is the output of parseReportsRaw
@@ -19,8 +19,6 @@ export default class ReportResolvable {
19
19
  constructor(args: {
20
20
  report: Record<string, string | number | null | boolean>;
21
21
  calculationMap?: CalculationMap;
22
- /** Used for member facts */
23
- pathSeparator?: string;
24
22
  });
25
23
  getMap(): CalculationMap;
26
24
  clearCache(): void;
@@ -22,9 +22,7 @@ export default class FactFiscalCalculator {
22
22
  facts?: Pick<FactItem, 'end' | 'filed'>[];
23
23
  filings?: Pick<FilingListItemTranslated, 'form' | 'reportDate' | 'filingDate' | 'accessionNumber'>[];
24
24
  });
25
- useFilingsForDates(params: {
26
- filings: Pick<FilingListItemTranslated, 'form' | 'reportDate' | 'filingDate' | 'accessionNumber'>[];
27
- }): void;
25
+ private useFilingsForDates;
28
26
  add(fact: {
29
27
  end: string;
30
28
  filed: string;
@@ -15,9 +15,7 @@ var FactFiscalCalculator = /** @class */ (function () {
15
15
  this.filedDateCountByEndDate = new Map();
16
16
  this.didResolve = false;
17
17
  var _a = params !== null && params !== void 0 ? params : {}, _b = _a.facts, facts = _b === void 0 ? [] : _b, _c = _a.filings, filings = _c === void 0 ? [] : _c;
18
- if (filings.length > 0) {
19
- this.useFilingsForDates({ filings: filings });
20
- }
18
+ this.useFilingsForDates({ filings: filings });
21
19
  facts.forEach(function (fact) { return _this.add(fact); });
22
20
  }
23
21
  FactFiscalCalculator.prototype.useFilingsForDates = function (params) {
@@ -197,20 +197,9 @@ var FactPeriodResolver = /** @class */ (function () {
197
197
  var _this = this;
198
198
  this.propertiesByYear.forEach(function (properties, year) {
199
199
  properties.forEach(function (propertyName) {
200
- var _a, _b;
200
+ var _a;
201
201
  for (var i = 0; i < 4; i++) {
202
202
  var bucketSum = (_a = _this.sumByQuarterByPropertyByYear.get(year)) === null || _a === void 0 ? void 0 : _a.get(propertyName);
203
- var bucketQuarter = _this.getOrSetBucketArr(_this.valueByQuarterByPropertyByYear, year, propertyName);
204
- if (bucketSum && !bucketSum.has(i)) {
205
- var prevSum = 0;
206
- var quarterSum = 0;
207
- for (var j = 0; j < i; j++) {
208
- prevSum = quarterSum;
209
- quarterSum = (_b = bucketSum.get(j)) !== null && _b !== void 0 ? _b : quarterSum;
210
- }
211
- bucketSum.set(i, quarterSum);
212
- bucketQuarter.set(i, quarterSum - prevSum);
213
- }
214
203
  var value = bucketSum === null || bucketSum === void 0 ? void 0 : bucketSum.get(i);
215
204
  if (value === undefined)
216
205
  continue;
@@ -1,18 +1,22 @@
1
- import type { CompanyFactListData, FactGroup, FactItem, ReportRaw, SplitData } from '../../types';
2
- import FactFiscalCalculator, { SetReportDatesParams } from './FactFiscalCalculator';
1
+ import type { CompanyFactListData, FactGroup, FactItem, FilingListItemTranslated, ReportRaw, SplitData } from '../../types';
2
+ import FactFiscalCalculator from './FactFiscalCalculator';
3
3
  export interface BuildReportsParams {
4
4
  facts: FactItem[];
5
5
  /**
6
6
  * for more accurate dates, add this. Otherwise, dates will be inferred
7
7
  * using the fact periods. The filing and report dates can be found in the SubmissionList (segEdgarApi.getSubmissions)
8
8
  */
9
- reportDates?: SetReportDatesParams[];
9
+ filings?: Pick<FilingListItemTranslated, 'form' | 'reportDate' | 'filingDate' | 'accessionNumber'>[];
10
10
  /**
11
11
  * Splits will be extracted from facts if not provided.
12
12
  */
13
13
  splits?: SplitData[];
14
14
  resolvePeriodValues?: boolean;
15
15
  adjustForSplits?: boolean;
16
+ /**
17
+ * For member facts (facts with segments), the separator between the fact name and the segments.
18
+ */
19
+ pathSeparatorForMemberFacts?: string;
16
20
  }
17
21
  /**
18
22
  * Builds ReportRaw objects from company facts. Adjusts for splits and resolves period values.
@@ -22,7 +26,7 @@ export default class ReportRawBuilder {
22
26
  createFacts(companyFacts: CompanyFactListData, includeNamePrefix?: boolean): {
23
27
  facts: FactItem[];
24
28
  };
25
- private createFiscalCalculator;
29
+ private getFactKey;
26
30
  buildReports(params: BuildReportsParams): ReportRaw[];
27
31
  private createReportKey;
28
32
  private createReport;
@@ -1,5 +1,17 @@
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
  Object.defineProperty(exports, "__esModule", { value: true });
14
+ var constants_1 = require("../../util/constants");
3
15
  var FactFiscalCalculator_1 = require("./FactFiscalCalculator");
4
16
  var FactGrouper_1 = require("./FactGrouper");
5
17
  var FactRecordBuilder_1 = require("./FactRecordBuilder");
@@ -15,43 +27,49 @@ var ReportRawBuilder = /** @class */ (function () {
15
27
  if (includeNamePrefix === void 0) { includeNamePrefix = false; }
16
28
  return this.factRecordBuilder.createFacts(companyFacts, includeNamePrefix);
17
29
  };
18
- ReportRawBuilder.prototype.createFiscalCalculator = function (params) {
19
- var facts = params.facts;
20
- var fiscalCalculator = new FactFiscalCalculator_1.default();
21
- for (var _i = 0, facts_1 = facts; _i < facts_1.length; _i++) {
22
- var fact = facts_1[_i];
23
- fiscalCalculator.add(fact);
24
- }
25
- return fiscalCalculator;
30
+ ReportRawBuilder.prototype.getFactKey = function (fact, pathSeparator) {
31
+ var _a;
32
+ var suffix = (_a = fact.segments) === null || _a === void 0 ? void 0 : _a.map(function (_a) {
33
+ var dimension = _a.dimension, value = _a.value;
34
+ return "".concat(dimension).concat(pathSeparator).concat(value);
35
+ }).join(pathSeparator);
36
+ return suffix ? "".concat(fact.name).concat(pathSeparator).concat(suffix) : fact.name;
26
37
  };
27
38
  ReportRawBuilder.prototype.buildReports = function (params) {
28
- var facts = params.facts, reportDates = params.reportDates, splitsProp = params.splits, _a = params.resolvePeriodValues, resolvePeriodValues = _a === void 0 ? true : _a, _b = params.adjustForSplits, adjustForSplits = _b === void 0 ? true : _b;
39
+ var _this = this;
40
+ var factsProp = params.facts, filings = params.filings, splitsProp = params.splits, _a = params.resolvePeriodValues, resolvePeriodValues = _a === void 0 ? true : _a, _b = params.adjustForSplits, adjustForSplits = _b === void 0 ? true : _b, _c = params.pathSeparatorForMemberFacts, pathSeparatorForMemberFacts = _c === void 0 ? '>' : _c;
41
+ // Rename member facts to prevent overwriting parent facts.
42
+ var facts = factsProp.map(function (fact) {
43
+ var factKey = _this.getFactKey(fact, pathSeparatorForMemberFacts);
44
+ return __assign(__assign({}, fact), { name: factKey });
45
+ });
29
46
  if (facts.length === 0) {
30
47
  return [];
31
48
  }
49
+ var reportsCik = Number(facts[0].cik);
50
+ var fiscalCalculator = new FactFiscalCalculator_1.default({
51
+ filings: filings === null || filings === void 0 ? void 0 : filings.filter(function (f) { return constants_1.FORMS_EARNINGS.includes(f.form); }),
52
+ facts: facts,
53
+ });
32
54
  var accessionByYearQuarter = new Map();
33
- reportDates === null || reportDates === void 0 ? void 0 : reportDates.forEach(function (params) {
34
- var year = params.year, quarter = params.quarter, accn = params.accn;
35
- if (accn)
36
- accessionByYearQuarter.set("".concat(year, "_").concat(quarter), accn);
55
+ filings === null || filings === void 0 ? void 0 : filings.forEach(function (f) {
56
+ var _a = fiscalCalculator.getFiscalYearQuarter({ dateStr: f.reportDate }), year = _a.year, quarter = _a.quarter;
57
+ accessionByYearQuarter.set(f.accessionNumber, "".concat(year, "_").concat(quarter));
37
58
  });
38
- var reportsCik = Number(facts[0].cik);
39
- var fiscalCalculator = reportDates ? new FactFiscalCalculator_1.default() : this.createFiscalCalculator({ facts: facts });
40
- reportDates === null || reportDates === void 0 ? void 0 : reportDates.forEach(function (params) { return fiscalCalculator.setReportDates(params); });
41
59
  var factGrouper = new FactGrouper_1.default();
42
60
  var factSplitAdjuster = new FactSplitAdjuster_1.default();
43
61
  // if splits not included in params and need to adjust, extract from facts
44
62
  var splits = adjustForSplits
45
63
  ? splitsProp !== null && splitsProp !== void 0 ? splitsProp : factSplitAdjuster.getSplits({ splitFacts: factSplitAdjuster.filterSplitFacts({ facts: facts }) })
46
64
  : splitsProp;
47
- var _c = factGrouper.buildFactGroupsByReportKey({
65
+ var _d = factGrouper.buildFactGroupsByReportKey({
48
66
  facts: facts,
49
67
  cik: reportsCik,
50
68
  fiscalCalculator: fiscalCalculator,
51
69
  resolvePeriodValues: resolvePeriodValues,
52
70
  generateMissingGroups: false,
53
71
  splits: splits,
54
- }), factGroupsByReportKey = _c.factGroupsByReportKey, maxYear = _c.maxYear, minYear = _c.minYear;
72
+ }), factGroupsByReportKey = _d.factGroupsByReportKey, maxYear = _d.maxYear, minYear = _d.minYear;
55
73
  return this.buildReportsFromGroups({
56
74
  factGroupsByReportKey: factGroupsByReportKey,
57
75
  fiscalCalculator: fiscalCalculator,
@@ -231,11 +231,7 @@ export default class SecEdgarApi {
231
231
  *
232
232
  * Use "include" params to specify what to parse. If not provided, all data is parsed.
233
233
  */
234
- getDocumentXbrl(params: GetDocumentXbrlParams): Promise<import("../DocumentParser/XBRLParser/XBRLParser").XbrlParseResult & {
235
- report: ReportRaw | null;
236
- facts: import("../../types").FactItemExtended[];
237
- xml: string;
238
- }>;
234
+ getDocumentXbrl(params: GetDocumentXbrlParams): Promise<import("../DocumentParser/parsers/parse-xbrl").DocumentXbrlResult>;
239
235
  /**
240
236
  * Builds a url for a document. If fileName is not provided, it defaults to `${accessionNumber}.txt`
241
237
  *
@@ -336,6 +332,8 @@ export default class SecEdgarApi {
336
332
  }>;
337
333
  /**
338
334
  * Search for companies from by name, sic code, or state.
335
+ *
336
+ * example at https://www.sec.gov/cgi-bin/browse-edgar?action=getcompany&owner=exclude&&start=0&count=100&hidefilings=0&company=Apple&match=contains
339
337
  */
340
338
  searchCompanies(params: SearchCompaniesParams): Promise<{
341
339
  items: import("../../types").CompanySearchResult[];
@@ -302,17 +302,17 @@ var SecEdgarApi = /** @class */ (function () {
302
302
  */
303
303
  SecEdgarApi.prototype.getReports = function (params) {
304
304
  return __awaiter(this, void 0, void 0, function () {
305
- var calculationMap, reportsRaw;
305
+ var calculationMap, reports;
306
+ var _this = this;
306
307
  return __generator(this, function (_a) {
307
308
  switch (_a.label) {
308
309
  case 0:
309
310
  calculationMap = params.calculationMap;
310
311
  return [4 /*yield*/, this.getReportsRaw(__assign(__assign({}, params), { includeNamePrefix: true }))];
311
312
  case 1:
312
- reportsRaw = _a.sent();
313
- return [2 /*return*/, this.reportParser.parseReportsFromRaw({
314
- reportsRaw: reportsRaw,
315
- calculationMap: calculationMap,
313
+ reports = _a.sent();
314
+ return [2 /*return*/, reports.map(function (report) {
315
+ return _this.reportParser.translateReport({ report: report, calculationMap: calculationMap });
316
316
  })];
317
317
  }
318
318
  });
@@ -701,6 +701,8 @@ var SecEdgarApi = /** @class */ (function () {
701
701
  };
702
702
  /**
703
703
  * Search for companies from by name, sic code, or state.
704
+ *
705
+ * example at https://www.sec.gov/cgi-bin/browse-edgar?action=getcompany&owner=exclude&&start=0&count=100&hidefilings=0&company=Apple&match=contains
704
706
  */
705
707
  SecEdgarApi.prototype.searchCompanies = function (params) {
706
708
  return __awaiter(this, void 0, void 0, function () {
@@ -1,5 +1,7 @@
1
1
  export interface CompanySearchResult {
2
2
  cik: number;
3
+ sic: number | null;
4
+ sicDescription: string | null;
3
5
  companyName: string;
4
- stateOrCountry: string;
6
+ stateOrCountry: string | null;
5
7
  }
@@ -11,6 +11,7 @@ export interface FilingItemXBRL {
11
11
  title: string;
12
12
  link: string;
13
13
  guid: string;
14
+ url: string;
14
15
  enclosureUrl: string;
15
16
  enclosureLength: number;
16
17
  enclosureType: string;
@@ -1,3 +1,4 @@
1
+ export type TransactionCode = 'S' | 'V' | 'A' | 'D' | 'F' | 'I' | 'M' | 'C' | 'E' | 'H' | 'O' | 'X' | 'G' | 'L' | 'W' | 'Z' | 'J' | 'K' | 'U';
1
2
  export interface Owner {
2
3
  ownerName: string;
3
4
  ownerCik: number;
@@ -22,7 +23,29 @@ export interface InsiderTransaction {
22
23
  isDirectOwnership: boolean;
23
24
  securityTitle: string;
24
25
  transactionDate: string;
25
- transactionCode: string;
26
+ /**
27
+ * ### Transaction Codes
28
+ * - S: Sale
29
+ * - V: Voluntary Reporting
30
+ * - A: Grant
31
+ * - D: Sale to Issuer
32
+ * - F: Payment of Exercise Price
33
+ * - I: Discretionary Transaction
34
+ * - M: Conversion of Derivative Exempt
35
+ * - C: Conversion of Derivative
36
+ * - E: Expiration of Short Derivative Position
37
+ * - H: Expiration of Long Derivative Position
38
+ * - O: Exercise of out-of-the-money Derivative
39
+ * - X: Exercise of in-the-money Derivative
40
+ * - G: Gift
41
+ * - L: Small Acquisition
42
+ * - W: Acquisition or Disposition By Will or Laws
43
+ * - Z: Voting Trust Deposit or Withdrawal
44
+ * - J: Other Acquisition or Disposition
45
+ * - K: Equity Swap
46
+ * - U: Disposition Change in Control
47
+ */
48
+ transactionCode: TransactionCode;
26
49
  transactionShares: number;
27
50
  sharesOwnedFollowingTransaction: number;
28
51
  lineNumber: number;
@@ -30,3 +53,26 @@ export interface InsiderTransaction {
30
53
  form: string;
31
54
  accessionNumber: string;
32
55
  }
56
+ export type TransactionType = 'Acquire' | 'Dispose';
57
+ export interface InsiderTransactionExtended {
58
+ filerName: string;
59
+ filerPosition: string;
60
+ filerPositionTypes: string[];
61
+ securityType: string;
62
+ securityTypeUnderlying: string | null;
63
+ category: 'Derivative' | 'Non-Derivative';
64
+ date: string;
65
+ dateExecuted: string | null;
66
+ dateExpiration: string | null;
67
+ dateExercisable: string | null;
68
+ transactionDescription: string | null;
69
+ transactionCode: TransactionCode | null;
70
+ transactionType: TransactionType | null;
71
+ sharesEnding: number | null;
72
+ shares: number | null;
73
+ sharesUnderlying: number | null;
74
+ price: number | null;
75
+ priceExcercised: number | null;
76
+ ownership: string;
77
+ explainationByKey: Partial<Record<keyof InsiderTransactionExtended, string>>;
78
+ }
@@ -1,49 +1,4 @@
1
- interface TransactionDescriptionByCode {
2
- S: 'Sale';
3
- V: 'Voluntary Reporting';
4
- A: 'Grant';
5
- D: 'Sale to Issuer';
6
- F: 'Payment of Exercise Price';
7
- I: 'Discretionary Transaction';
8
- M: 'Conversion of Derivative Exempt';
9
- C: 'Conversion of Derivative';
10
- E: 'Expiration of Short Derivative Position';
11
- H: 'Expiration of Long Derivative Position';
12
- O: 'Exercise of out-of-the-money Derivative';
13
- X: 'Exercise of in-the-money Derivative';
14
- G: 'Gift';
15
- L: 'Small Acquisition';
16
- W: 'Acquisition or Disposition By Will or Laws';
17
- Z: 'Voting Trust Deposit or Withdrawal';
18
- J: 'Other Acquisition or Disposition';
19
- K: 'Equity Swap';
20
- U: 'Disposition Change in Control';
21
- }
22
- export type TransactionType = 'Acquire' | 'Dispose';
23
- export type TransactionCode = keyof TransactionDescriptionByCode;
24
- export type TransactionDescription = TransactionDescriptionByCode[TransactionCode];
25
- export interface InsiderTransactionExtended {
26
- filerName: string;
27
- filerPosition: string;
28
- filerPositionTypes: string[];
29
- securityType: string;
30
- securityTypeUnderlying: string | null;
31
- category: 'Derivative' | 'Non-Derivative';
32
- date: string;
33
- dateExecuted: string | null;
34
- dateExpiration: string | null;
35
- dateExercisable: string | null;
36
- transactionDescription: string | null;
37
- transactionCode: TransactionCode | null;
38
- transactionType: TransactionType | null;
39
- sharesEnding: number | null;
40
- shares: number | null;
41
- sharesUnderlying: number | null;
42
- price: number | null;
43
- priceExcercised: number | null;
44
- ownership: string;
45
- explainationByKey: Partial<Record<keyof InsiderTransactionExtended, string>>;
46
- }
1
+ import type { InsiderTransactionExtended } from './insider-transaction.type';
47
2
  export interface InstitutionalHolder {
48
3
  name: string;
49
4
  origin: string;
@@ -94,4 +49,3 @@ export interface FormDef14aData {
94
49
  holders: Holder[];
95
50
  }
96
51
  export type DailyFilingFormType = '10-K' | '10-Q' | '8-K' | '14' | '485' | 'S-8' | 'ALL';
97
- export {};
@@ -1,2 +1,4 @@
1
1
  declare const KEY_SPLIT = "StockholdersEquityNoteStockSplitConversionRatio1";
2
- export { KEY_SPLIT };
2
+ declare const FORMS_EARNINGS: string[];
3
+ declare const FORMS_EARNINGS_ANNUAL: string[];
4
+ export { KEY_SPLIT, FORMS_EARNINGS, FORMS_EARNINGS_ANNUAL };
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KEY_SPLIT = void 0;
3
+ exports.FORMS_EARNINGS_ANNUAL = exports.FORMS_EARNINGS = exports.KEY_SPLIT = void 0;
4
4
  var KEY_SPLIT = 'StockholdersEquityNoteStockSplitConversionRatio1';
5
5
  exports.KEY_SPLIT = KEY_SPLIT;
6
+ var FORMS_EARNINGS = ['10-Q', '10-K', '20-F', '40-F'];
7
+ exports.FORMS_EARNINGS = FORMS_EARNINGS;
8
+ var FORMS_EARNINGS_ANNUAL = ['10-K', '20-F', '40-F'];
9
+ exports.FORMS_EARNINGS_ANNUAL = FORMS_EARNINGS_ANNUAL;
@@ -1,5 +1,7 @@
1
1
  import type { ReportTranslated } from '../types/report-translated.type';
2
2
  /**
3
+ * @deprecated use calculationMap for ReportResolvable
4
+ *
3
5
  * Checks if any of the array keys exist in the object to assign to the translated key
4
6
  * These were checked against Yahoo Finance values, adding the ones that most often matched the yahoo values
5
7
  */
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  /**
4
+ * @deprecated use calculationMap for ReportResolvable
5
+ *
4
6
  * Checks if any of the array keys exist in the object to assign to the translated key
5
7
  * These were checked against Yahoo Finance values, adding the ones that most often matched the yahoo values
6
8
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sec-edgar-api",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Fetch and parse SEC earnings reports and other filings. Useful for financial analysis.",
5
5
  "main": "build/index.js",
6
6
  "author": "Andrew Evers (https://github.com/andyevers)",