@mudraforge/statutory 2.9.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/CONTRIBUTING.md +1 -0
  3. package/README.md +142 -158
  4. package/SECURITY.md +2 -2
  5. package/SKILL.md +7 -2
  6. package/bin/cli.js +213 -8
  7. package/docs/ARCHITECTURE.md +10 -10
  8. package/docs/ARCHITECTURE_DECISIONS.md +5 -4
  9. package/docs/CATALOG.md +489 -89
  10. package/docs/CORPUS_QUALITY.md +17 -9
  11. package/docs/DATA_LICENSING.md +1 -1
  12. package/docs/DOMAIN_BREADTH_AND_DEPTH_COMPARISON.md +35 -33
  13. package/docs/ENTERPRISE_GOVERNANCE.md +81 -22
  14. package/docs/OKF_MAINTENANCE_SOP.md +12 -12
  15. package/docs/PILOT_EVALUATION_GUIDE.md +155 -90
  16. package/docs/PROVENANCE.md +4 -4
  17. package/docs/VERIFICATION.md +8 -8
  18. package/okf/corporate_ma_restructuring/tax_clearance_sec281/circulars/cbdt_circular_04_2011_sec281_clearance.md +57 -0
  19. package/okf/corporate_ma_restructuring/tax_clearance_sec281/forms/form_281_tax_clearance_application.json +42 -0
  20. package/okf/corporate_ma_restructuring/tax_clearance_sec281/section.json +70 -0
  21. package/okf/direct_tax/statutory_disallowance_43b/circulars/supreme_court_checkmate_services_2022.md +64 -0
  22. package/okf/direct_tax/statutory_disallowance_43b/forms/tax_audit_form_3cd_clause_26_schedule.json +71 -0
  23. package/okf/direct_tax/statutory_disallowance_43b/section.json +77 -0
  24. package/okf/direct_tax/tds_ecommerce_194o/circulars/cbdt_circular_20_2020_guidelines_194o.md +36 -0
  25. package/okf/direct_tax/tds_ecommerce_194o/forms/form_26q_ecommerce_schedule.json +75 -0
  26. package/okf/direct_tax/tds_ecommerce_194o/section.json +65 -0
  27. package/okf/direct_tax/tds_individual_contract_194m/circulars/finance_act_2024_194m_rate_cut_memo.md +24 -0
  28. package/okf/direct_tax/tds_individual_contract_194m/forms/form_26qd_contractor_statement.json +64 -0
  29. package/okf/direct_tax/tds_individual_contract_194m/section.json +58 -0
  30. package/okf/direct_tax/tds_interest_194a/circulars/cbdt_circular_03_2010_interest_tds.md +28 -0
  31. package/okf/direct_tax/tds_interest_194a/forms/form_15g_15h_interest_declaration.json +55 -0
  32. package/okf/direct_tax/tds_interest_194a/forms/form_26q_interest_schedule.json +72 -0
  33. package/okf/direct_tax/tds_interest_194a/section.json +64 -0
  34. package/okf/direct_tax/tds_perquisites_194r/forms/form_26q_perquisites_schedule.json +83 -0
  35. package/okf/direct_tax/tds_perquisites_194r/section.json +1 -1
  36. package/okf/direct_tax/tds_property_194ia/circulars/cbdt_notification_67_2022_property_tds.md +57 -0
  37. package/okf/direct_tax/tds_property_194ia/forms/form_26qb_property_tds_challan.json +43 -0
  38. package/okf/direct_tax/tds_property_194ia/section.json +73 -0
  39. package/okf/direct_tax/tds_rent_individual_194ib/circulars/finance_act_2024_rent_rate_cut_memo.md +24 -0
  40. package/okf/direct_tax/tds_rent_individual_194ib/forms/form_26qc_challan_cum_statement.json +74 -0
  41. package/okf/direct_tax/tds_rent_individual_194ib/section.json +57 -0
  42. package/okf/indirect_tax_gst/itc_reversal_rule37_37a/circulars/cbic_notification_19_2022_rule37.md +31 -0
  43. package/okf/indirect_tax_gst/itc_reversal_rule37_37a/forms/gstr_3b_table_4b_reversal.json +81 -0
  44. package/okf/indirect_tax_gst/itc_reversal_rule37_37a/section.json +64 -0
  45. package/okf/manifest.json +48 -6
  46. package/package.json +18 -1
  47. package/src/calculators.js +5374 -49
  48. package/src/constants.js +10 -0
  49. package/src/index.js +289 -13
  50. package/src/outcomes.js +483 -0
  51. package/types/index.d.ts +95 -0
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @fileoverview Canonical Single-Source-of-Truth Constants for @mudraforge/statutory.
3
+ * Pure ESM module with zero Node.js/browser-specific dependencies.
4
+ * Safe to import across Node.js, Cloudflare Workers, browsers, and Edge runtimes.
5
+ *
6
+ * @license MIT
7
+ */
8
+
9
+ export const STATUTORY_CLIENT_VERSION = '2.11.0';
10
+ export const DEFAULT_BASE_URL = 'https://api.mudraforge.in';
package/src/index.js CHANGED
@@ -21,20 +21,77 @@ import {
21
21
  evaluatePlaceOfSupplyAndLut,
22
22
  calculateTransferPricingAlp,
23
23
  evaluateSection79LossContinuity,
24
- revalueForeignExchangeIndAs109
24
+ evaluateSection281TaxClearance,
25
+ revalueForeignExchangeIndAs109,
26
+ evaluateSection194Q,
27
+ evaluateSection194C,
28
+ evaluateSection194H,
29
+ evaluateSection194I,
30
+ evaluateSection194J,
31
+ evaluateSection194A,
32
+ evaluateSection194O,
33
+ evaluateSection194IA,
34
+ evaluateSection194IB,
35
+ evaluateSection194M,
36
+ evaluateSection194R,
37
+ evaluateSection43BStatutoryPayables,
38
+ calculateItcReversalRule37,
39
+ calculateRule37ASupplierNonFilingReversal,
40
+ evaluateSection206C1H,
41
+ evaluateSection43bH,
42
+ calculateMsmeCompoundInterest,
43
+ calculateAdvanceTaxAndInterest,
44
+ calculateGstItcApportionmentRule42_43,
45
+ evaluateCrossBorderRemittance,
46
+ generateMsme1AndScheduleThreeAging,
47
+ evaluateLowerDeductionCertificateValidity,
48
+ getRbiBankRateForDate,
49
+ DEFAULT_RBI_BANK_RATE,
50
+ MSMED_RATE_MULTIPLIER,
51
+ RBI_BANK_RATE_SCHEDULE,
52
+ AUTHORITATIVE_STATUTORY_RATES,
53
+ VALID_194J_CATEGORIES
25
54
  } from './calculators.js';
55
+ import {
56
+ getStatutoryOutcomes,
57
+ explainStatutoryDisposition,
58
+ STATUTORY_OUTCOMES_DICTIONARY,
59
+ enrichWithOutcomeExplanation
60
+ } from './outcomes.js';
61
+
62
+ import { STATUTORY_CLIENT_VERSION, DEFAULT_BASE_URL } from './constants.js';
63
+
64
+ let defaultOkfDir = null;
65
+ try {
66
+ if (typeof import.meta?.url === 'string' && import.meta.url.startsWith('file:')) {
67
+ const __filename = fileURLToPath(import.meta.url);
68
+ const __dirname = path.dirname(__filename);
69
+ defaultOkfDir = path.resolve(__dirname, '..', 'okf');
70
+ }
71
+ } catch (_) {
72
+ defaultOkfDir = null;
73
+ }
74
+ export const DEFAULT_LOCAL_OKF_DIR = defaultOkfDir;
75
+ export { STATUTORY_CLIENT_VERSION, DEFAULT_BASE_URL };
26
76
 
27
- const __filename = fileURLToPath(import.meta.url);
28
- const __dirname = path.dirname(__filename);
29
- export const DEFAULT_LOCAL_OKF_DIR = path.resolve(__dirname, '..', 'okf');
30
- export const DEFAULT_BASE_URL = 'https://api.mudraforge.in';
31
- export const STATUTORY_CLIENT_VERSION = '2.9.0';
77
+ /**
78
+ * Current verified Merkle root digest for the active OKF v0.2 corpus.
79
+ */
80
+ export const CURRENT_RELEASE_MERKLE_ROOT = 'sha256-bf547512a57f26eae9a5ebcb9f0ec41c397421366b1b4223ab9e17d282721ca7';
81
+ export const MERKLE_ROOT_OKF_V2 = CURRENT_RELEASE_MERKLE_ROOT;
32
82
 
33
83
  /**
34
84
  * Pinned official release Merkle root digests.
35
85
  * Prevents unauthorized bundle substitution attacks even if an attacker controls the remote endpoint.
36
86
  */
37
87
  export const PINNED_RELEASE_ROOTS = new Set([
88
+ 'sha256-feb1555f10c9f5c70de18ef340e0ba6cf1f060fb19cae866aa36240345c46f3a', // feat/rent-194ib-contract-194m (37 Sections across 5 Domains)
89
+ 'sha256-02090e4063a863e3486401215469350c911dc0c9a24855e1d9db2903946aa644', // feat/perquisites-194r (35 Sections across 5 Domains)
90
+ 'sha256-bd351719a8235c44f2bac87cc347423baa8ac3ecb74c0ee63d1fffa9f33dbebe', // feat/property-194ia (35 Sections across 5 Domains)
91
+ 'sha256-fc208ff012bfc3044cfc6edc5fcbf1c0e445e387a8c7d806e271968b511919ce', // feat/mna-sec281 (34 Sections across 5 Domains)
92
+ 'sha256-7f2bd99d81a261743773230d2ab3e21717ac9ca02a55c867545f5777b1a7d69f', // feat/statutory-43b-payroll (33 Sections across 5 Domains)
93
+ 'sha256-bf547512a57f26eae9a5ebcb9f0ec41c397421366b1b4223ab9e17d282721ca7', // feat/ecommerce-194o (32 Sections across 5 Domains)
94
+ 'sha256-b12fab61f0ddcc8852a7db1b4831151163d1d0ff97112168d8dccf693cfe70a7', // v2.11.0 Complete Accounts Payable (31 Sections across 5 Domains)
38
95
  'sha256-4bbe36c3db841b833dd2bebbd6c1c5ed735498e7b20d1221c323ceb211529fe0', // v2.9.0 Corporate Finance 5 Domains Merkle Root (29 Sections across 5 Domains)
39
96
  'sha256-3fb34bdcd34eec794b1f8e6abb2c0e0e87664746ec2f50ad2599c34bf57565b3', // v2.8.1 Finance Act, 2025 Section 206AB Sunset Root (24 Sections across 5 Domains)
40
97
  'sha256-239641de2bef05917673f693f9ba4d14bd5e137d64554fba5db87e426bc13e14', // v2.8.0 Deep Semantic Citation Merkle Root (24 Sections across 5 Domains)
@@ -886,7 +943,11 @@ export async function checkUpdates(options = {}) {
886
943
  * @returns {Promise<{ updateAvailable: boolean, currentVersion: string, latestVersion: string } | null>}
887
944
  */
888
945
  export async function checkForPackageUpdate(options = {}) {
889
- if (!options.force && (process.env.NO_UPDATE_NOTIFIER === '1' || (process.env.CI === 'true' && !options.registryUrl))) {
946
+ if (!options.force && (
947
+ process.env.NO_UPDATE_NOTIFIER === '1' ||
948
+ process.env.MUDRA_NO_UPDATE_NOTIFIER === '1' ||
949
+ (process.env.CI === 'true' && !options.registryUrl)
950
+ )) {
890
951
  return null;
891
952
  }
892
953
 
@@ -922,7 +983,9 @@ export async function checkForPackageUpdate(options = {}) {
922
983
  latestVersion = json.version;
923
984
  if (cacheTtlMs > 0) {
924
985
  try {
986
+ const prev = fs.existsSync(cacheFile) ? JSON.parse(fs.readFileSync(cacheFile, 'utf8')) : {};
925
987
  fs.writeFileSync(cacheFile, JSON.stringify({
988
+ ...prev,
926
989
  lastChecked: Date.now(),
927
990
  latestVersion
928
991
  }), 'utf8');
@@ -939,13 +1002,44 @@ export async function checkForPackageUpdate(options = {}) {
939
1002
  if (!latestVersion) return null;
940
1003
 
941
1004
  const cmp = compareSemver(latestVersion, currentVersion);
1005
+ const isIgnored = Boolean(cached?.ignoredVersion && cached.ignoredVersion === latestVersion);
1006
+
942
1007
  return {
943
- updateAvailable: cmp > 0,
1008
+ updateAvailable: cmp > 0 && (!isIgnored || Boolean(options.force)),
1009
+ isIgnored,
944
1010
  currentVersion,
945
1011
  latestVersion
946
1012
  };
947
1013
  }
948
1014
 
1015
+ /**
1016
+ * Configure the CLI to ignore update notifications for a specific version.
1017
+ * @param {string} versionToIgnore Package version to suppress notifications for
1018
+ * @returns {{ status: 'SUCCESS' | 'ERROR', ignoredVersion: string, error?: string }}
1019
+ */
1020
+ export function ignorePackageUpdate(versionToIgnore) {
1021
+ if (!versionToIgnore || typeof versionToIgnore !== 'string') {
1022
+ throw new Error('[@mudraforge/statutory] A valid version string is required to ignore update notifications.');
1023
+ }
1024
+ const cacheFile = path.join(os.tmpdir(), '.mudraforge_statutory_npm_update.json');
1025
+ let current = {};
1026
+ try {
1027
+ if (fs.existsSync(cacheFile)) {
1028
+ current = JSON.parse(fs.readFileSync(cacheFile, 'utf8')) || {};
1029
+ }
1030
+ } catch (_) {}
1031
+
1032
+ current.ignoredVersion = versionToIgnore.trim();
1033
+ current.ignoredAt = Date.now();
1034
+
1035
+ try {
1036
+ fs.writeFileSync(cacheFile, JSON.stringify(current, null, 2), 'utf8');
1037
+ return { status: 'SUCCESS', ignoredVersion: versionToIgnore.trim() };
1038
+ } catch (err) {
1039
+ return { status: 'ERROR', ignoredVersion: versionToIgnore.trim(), error: err.message };
1040
+ }
1041
+ }
1042
+
949
1043
  /**
950
1044
  * Download and synchronize the latest OKF knowledge bundle to disk.
951
1045
  * Hardened with:
@@ -1574,9 +1668,10 @@ export class StatutoryClient {
1574
1668
  async calculate(payload = {}, options = {}) {
1575
1669
  if (!this.apiKey) {
1576
1670
  const err = new Error(
1577
- '[@mudraforge/statutory] Deterministic calculation engines (Section 194Q excess math, ' +
1578
- 'MSMED 3x RBI compounding interest, Section 194J FTS vs Professional) require an Enterprise API key.\n' +
1579
- 'Direct contact is required: email hello@mudraforge.in or support@mudraforge.in to request access.'
1671
+ '[@mudraforge/statutory] The hosted cloud calculation endpoint (\'/api/v1/statutory/calculate\') requires an Enterprise API key.\n' +
1672
+ 'To calculate deterministically offline without an API key or remote server, import pure calculation functions directly:\n' +
1673
+ ' import { calculateCorporateTaxMatVsConcessional, evaluatePlaceOfSupplyAndLut, calculateTransferPricingAlp, evaluateSection79LossContinuity, revalueForeignExchangeIndAs109 } from \'@mudraforge/statutory\';\n' +
1674
+ 'For hosted cloud edge calculation access or custom enterprise models, contact hello@mudraforge.in or support@mudraforge.in.'
1580
1675
  );
1581
1676
  err.code = 'API_KEY_REQUIRED';
1582
1677
  err.contact = 'hello@mudraforge.in';
@@ -1656,7 +1751,8 @@ export class StatutoryClient {
1656
1751
  throw err;
1657
1752
  }
1658
1753
 
1659
- return await safeJsonParse(res, 'StatutoryClient.calculate');
1754
+ const parsedResult = await safeJsonParse(res, 'StatutoryClient.calculate');
1755
+ return enrichWithOutcomeExplanation(parsedResult, { ...options, verbose: options.verbose || payload.verbose });
1660
1756
  }
1661
1757
 
1662
1758
  /**
@@ -1750,6 +1846,153 @@ export class StatutoryClient {
1750
1846
  revalueForeignExchangeIndAs109(payload) {
1751
1847
  return revalueForeignExchangeIndAs109(payload);
1752
1848
  }
1849
+
1850
+ /**
1851
+ * Section 194Q: Deduction of tax at source on purchase of goods exceeding ₹50 Lakh.
1852
+ */
1853
+ evaluateSection194Q(payload) {
1854
+ return evaluateSection194Q(payload);
1855
+ }
1856
+
1857
+ /**
1858
+ * Section 194C: Withholding on contractor and sub-contractor payments.
1859
+ */
1860
+ evaluateSection194C(payload) {
1861
+ return evaluateSection194C(payload);
1862
+ }
1863
+
1864
+ /**
1865
+ * Section 194H: Withholding on commission and brokerage payments.
1866
+ */
1867
+ evaluateSection194H(payload) {
1868
+ return evaluateSection194H(payload);
1869
+ }
1870
+
1871
+ /**
1872
+ * Section 194I: Withholding on rent (land/building vs plant/machinery).
1873
+ */
1874
+ evaluateSection194I(payload) {
1875
+ return evaluateSection194I(payload);
1876
+ }
1877
+
1878
+ /**
1879
+ * Section 194J: Withholding on professional and technical services (FTS).
1880
+ */
1881
+ evaluateSection194J(payload) {
1882
+ return evaluateSection194J(payload);
1883
+ }
1884
+
1885
+ /**
1886
+ * Section 194A: Withholding on interest other than interest on securities.
1887
+ */
1888
+ evaluateSection194A(payload) {
1889
+ return evaluateSection194A(payload);
1890
+ }
1891
+
1892
+ /**
1893
+ * Section 194O: E-commerce operator marketplace withholding & 194Q/206C(1H) override.
1894
+ */
1895
+ evaluateSection194O(payload) {
1896
+ return evaluateSection194O(payload);
1897
+ }
1898
+
1899
+ /**
1900
+ * Section 194-IA: Immovable property transfer TDS (higher of consideration or SDV) & Form 26QB.
1901
+ */
1902
+ evaluateSection194IA(payload) {
1903
+ return evaluateSection194IA(payload);
1904
+ }
1905
+
1906
+ /**
1907
+ * Section 194-IB: Individual/HUF rent TDS, 2% rate cut, Form 26QC, and Section 194-IB(4) last-month rent ceiling.
1908
+ */
1909
+ evaluateSection194IB(payload) {
1910
+ return evaluateSection194IB(payload);
1911
+ }
1912
+
1913
+ /**
1914
+ * Section 194M: Individual/HUF contract/commission/professional TDS, 2% rate cut, Form 26QD, and 50L threshold.
1915
+ */
1916
+ evaluateSection194M(payload) {
1917
+ return evaluateSection194M(payload);
1918
+ }
1919
+
1920
+ /**
1921
+ * Section 194R: Benefit or perquisite in business or profession TDS, in-kind advance tax, and de minimis threshold.
1922
+ */
1923
+ evaluateSection194R(payload) {
1924
+ return evaluateSection194R(payload);
1925
+ }
1926
+
1927
+ /**
1928
+ * Section 43B / Section 36(1)(va): Statutory payables disallowance & Supreme Court Checkmate Doctrine.
1929
+ */
1930
+ evaluateSection43B(payload) {
1931
+ return evaluateSection43BStatutoryPayables(payload);
1932
+ }
1933
+
1934
+ /**
1935
+ * Section 281: M&A asset transfer tax clearance & voidability evaluation under CBDT Circular 04/2011.
1936
+ */
1937
+ evaluateSection281(payload) {
1938
+ return evaluateSection281TaxClearance(payload);
1939
+ }
1940
+
1941
+ /**
1942
+ * Rule 37: 180-day vendor non-payment ITC reversal & Section 50(1) 18% interest.
1943
+ */
1944
+ calculateItcReversalRule37(payload) {
1945
+ return calculateItcReversalRule37(payload);
1946
+ }
1947
+
1948
+ /**
1949
+ * Rule 37A: Reversal of ITC where supplier failed to furnish Form GSTR-3B by November 30.
1950
+ */
1951
+ calculateRule37ASupplierNonFilingReversal(payload) {
1952
+ return calculateRule37ASupplierNonFilingReversal(payload);
1953
+ }
1954
+
1955
+ /**
1956
+ * MSMED Act Section 16: Compound interest with monthly rests at 3x RBI Bank Rate.
1957
+ */
1958
+ calculateMsmeCompoundInterest(payload) {
1959
+ return calculateMsmeCompoundInterest(payload);
1960
+ }
1961
+
1962
+ /**
1963
+ * Section 43B(h): Year-end tax disallowance on overdue MSME invoices.
1964
+ */
1965
+ evaluateSection43bH(payload) {
1966
+ return evaluateSection43bH(payload);
1967
+ }
1968
+
1969
+ /**
1970
+ * Section 195: Cross-border foreign remittance tax withholding.
1971
+ */
1972
+ evaluateCrossBorderRemittance(payload) {
1973
+ return evaluateCrossBorderRemittance(payload);
1974
+ }
1975
+
1976
+ /**
1977
+ * Retrieve statutory outcomes and disposition codes.
1978
+ * @param {string} [provision] Optional section code or provision alias
1979
+ * @param {Object} [options]
1980
+ */
1981
+ async getOutcomes(provision = null, options = {}) {
1982
+ return await getStatutoryOutcomes(provision, {
1983
+ ...options,
1984
+ baseUrl: this.baseUrl
1985
+ });
1986
+ }
1987
+
1988
+ /**
1989
+ * Retrieve in-depth explanation and remediation steps for a disposition code.
1990
+ * @param {string} codeOrQuery Disposition code (e.g. 'BUYER_TURNOVER_UNVERIFIED', 'INDETERMINATE')
1991
+ * @param {Object} [options]
1992
+ */
1993
+ explain(codeOrQuery, options = {}) {
1994
+ return explainStatutoryDisposition(codeOrQuery, options);
1995
+ }
1753
1996
  }
1754
1997
 
1755
1998
  /**
@@ -2752,7 +2995,40 @@ export {
2752
2995
  evaluatePlaceOfSupplyAndLut,
2753
2996
  calculateTransferPricingAlp,
2754
2997
  evaluateSection79LossContinuity,
2755
- revalueForeignExchangeIndAs109
2998
+ evaluateSection281TaxClearance,
2999
+ revalueForeignExchangeIndAs109,
3000
+ evaluateSection194Q,
3001
+ evaluateSection194C,
3002
+ evaluateSection194H,
3003
+ evaluateSection194I,
3004
+ evaluateSection194J,
3005
+ evaluateSection194A,
3006
+ evaluateSection194O,
3007
+ evaluateSection194IA,
3008
+ evaluateSection194IB,
3009
+ evaluateSection194M,
3010
+ evaluateSection194R,
3011
+ evaluateSection43BStatutoryPayables,
3012
+ calculateItcReversalRule37,
3013
+ calculateRule37ASupplierNonFilingReversal,
3014
+ evaluateSection206C1H,
3015
+ evaluateSection43bH,
3016
+ calculateMsmeCompoundInterest,
3017
+ calculateAdvanceTaxAndInterest,
3018
+ calculateGstItcApportionmentRule42_43,
3019
+ evaluateCrossBorderRemittance,
3020
+ generateMsme1AndScheduleThreeAging,
3021
+ evaluateLowerDeductionCertificateValidity,
3022
+ getRbiBankRateForDate,
3023
+ DEFAULT_RBI_BANK_RATE,
3024
+ MSMED_RATE_MULTIPLIER,
3025
+ RBI_BANK_RATE_SCHEDULE,
3026
+ AUTHORITATIVE_STATUTORY_RATES,
3027
+ VALID_194J_CATEGORIES,
3028
+ getStatutoryOutcomes,
3029
+ explainStatutoryDisposition,
3030
+ STATUTORY_OUTCOMES_DICTIONARY,
3031
+ enrichWithOutcomeExplanation
2756
3032
  };
2757
3033
 
2758
3034