tally-http-json 1.3.2 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tally-http-json",
3
- "version": "1.3.2",
3
+ "version": "1.5.1",
4
4
  "description": "Tally HTTP JSON client for TallyPrime",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -34,6 +34,5 @@
34
34
  },
35
35
  "devDependencies": {},
36
36
  "dependencies": {
37
- "tally-spec": "^1.5.2"
38
37
  }
39
- }
38
+ }
package/src/index.js CHANGED
@@ -1 +1 @@
1
- export { default, noCompany, tdl } from "./v3/index.js";
1
+ export { default, noCompany, tdl, fromCollection, importLedger } from "./v5/index.js";
@@ -0,0 +1,18 @@
1
+ import noCompanyFromInternal from "./noCompany/index.js";
2
+ import tdlFromInternal from "./tdl/index.js";
3
+ import fromCollectionInternal from "./fromCollection/index.js";
4
+
5
+ const noCompany = async (headerId = "") => {
6
+ return await noCompanyFromInternal({ inHeaderId: headerId });
7
+ };
8
+
9
+ const fromCollection = async (headerId = "") => {
10
+ return await fromCollectionInternal({ inHeaderId: headerId });
11
+ };
12
+
13
+ const tdl = async (headerId = "", tdl) => {
14
+ return await tdlFromInternal({ inHeaderId: headerId, inTdl: tdl });
15
+ };
16
+
17
+ export default noCompany;
18
+ export { noCompany, tdl, fromCollection };
@@ -0,0 +1,9 @@
1
+ {
2
+ "static_variables": [
3
+ {
4
+ "name": "svExportFormat",
5
+ "value": "jsonex"
6
+ }
7
+ ],
8
+ "fetch_list": []
9
+ }
@@ -0,0 +1,18 @@
1
+ import transport from "../transport.js";
2
+ import body from "./body.json" with { type: "json" };
3
+
4
+ const startFunc = async ({
5
+ inHeaderId,
6
+ inUrl = "http://localhost:9000"
7
+ } = {}) => {
8
+ const localHeaderId = inHeaderId;
9
+ const localUrl = inUrl;
10
+
11
+ return transport({
12
+ inHeaderId: localHeaderId,
13
+ inUrl: localUrl,
14
+ inBodyAsJson: JSON.stringify(body)
15
+ });
16
+ };
17
+
18
+ export default startFunc;
@@ -0,0 +1,9 @@
1
+ {
2
+ "static_variables": [
3
+ {
4
+ "name": "svExportFormat",
5
+ "value": "jsonex"
6
+ }
7
+ ],
8
+ "fetch_list": []
9
+ }
@@ -0,0 +1,23 @@
1
+ import transport from "../transport.js";
2
+ import body from "./body.json" with { type: "json" };
3
+
4
+ const startFunc = async ({
5
+ inHeaderId,
6
+ inUrl = "http://localhost:9000",
7
+ inTdl
8
+ } = {}) => {
9
+ const localHeaderId = inHeaderId;
10
+ const localUrl = inUrl;
11
+
12
+ if (inTdl) {
13
+ body.tdlmessage = inTdl;
14
+ };
15
+
16
+ return transport({
17
+ inHeaderId: localHeaderId,
18
+ inUrl: localUrl,
19
+ inBodyAsJson: JSON.stringify(body)
20
+ });
21
+ };
22
+
23
+ export default startFunc;
@@ -0,0 +1,9 @@
1
+ {
2
+ "static_variables": [
3
+ {
4
+ "name": "svExportFormat",
5
+ "value": "jsonex"
6
+ }
7
+ ],
8
+ "fetch_list": []
9
+ }
@@ -0,0 +1,18 @@
1
+ import transport from "../transport.js";
2
+ import body from "./body.json" with { type: "json" };
3
+
4
+ const startFunc = async ({
5
+ inHeaderId,
6
+ inUrl = "http://localhost:9000"
7
+ } = {}) => {
8
+ const localHeaderId = inHeaderId;
9
+ const localUrl = inUrl;
10
+
11
+ return transport({
12
+ inHeaderId: localHeaderId,
13
+ inUrl: localUrl,
14
+ inBodyAsJson: JSON.stringify(body)
15
+ });
16
+ };
17
+
18
+ export default startFunc;
@@ -0,0 +1,23 @@
1
+ {
2
+ "static_variables": [
3
+ {
4
+ "name": "svMstImportFormat",
5
+ "value": "JSONEx"
6
+ },
7
+ {
8
+ "name": "svCurrentCompany",
9
+ "value": "mani9"
10
+ }
11
+ ],
12
+ "tallymessage": [
13
+ {
14
+ "metadata": {
15
+ "type": "Ledger",
16
+ "action": "create",
17
+ "name": "aaaaa"
18
+ },
19
+ "name": "aaaaaaa",
20
+ "parent": "Sundry Debtors"
21
+ }
22
+ ]
23
+ }
@@ -0,0 +1,16 @@
1
+ import transport from "../transport.js";
2
+ import body from "./body.json" with { type: "json" };
3
+
4
+ const startFunc = async (name) => {
5
+ body.tallymessage[0].metadata.name = name;
6
+ body.tallymessage[0].name = name;
7
+
8
+ return await transport({
9
+ inHeaderId: "All Masters",
10
+ inTallyrequest: "Import",
11
+ inType: "Data",
12
+ inBodyAsJson: JSON.stringify(body)
13
+ });
14
+ };
15
+
16
+ export default startFunc;
@@ -0,0 +1,23 @@
1
+ import noCompanyFromInternal from "./noCompany/index.js";
2
+ import tdlFromInternal from "./tdl/index.js";
3
+ import fromCollectionInternal from "./fromCollection/index.js";
4
+ import fromimport from "./import/index.js";
5
+
6
+ const noCompany = async (headerId = "") => {
7
+ return await noCompanyFromInternal({ inHeaderId: headerId });
8
+ };
9
+
10
+ const fromCollection = async (headerId = "") => {
11
+ return await fromCollectionInternal({ inHeaderId: headerId });
12
+ };
13
+
14
+ const tdl = async (headerId = "", tdl) => {
15
+ return await tdlFromInternal({ inHeaderId: headerId, inTdl: tdl });
16
+ };
17
+
18
+ const importLedger = async (name) => {
19
+ return await fromimport(name);
20
+ };
21
+
22
+ export default noCompany;
23
+ export { noCompany, tdl, fromCollection, importLedger };
@@ -0,0 +1,9 @@
1
+ {
2
+ "static_variables": [
3
+ {
4
+ "name": "svExportFormat",
5
+ "value": "jsonex"
6
+ }
7
+ ],
8
+ "fetch_list": []
9
+ }
@@ -0,0 +1,18 @@
1
+ import transport from "../transport.js";
2
+ import body from "./body.json" with { type: "json" };
3
+
4
+ const startFunc = async ({
5
+ inHeaderId,
6
+ inUrl = "http://localhost:9000"
7
+ } = {}) => {
8
+ const localHeaderId = inHeaderId;
9
+ const localUrl = inUrl;
10
+
11
+ return transport({
12
+ inHeaderId: localHeaderId,
13
+ inUrl: localUrl,
14
+ inBodyAsJson: JSON.stringify(body)
15
+ });
16
+ };
17
+
18
+ export default startFunc;
@@ -0,0 +1,9 @@
1
+ {
2
+ "static_variables": [
3
+ {
4
+ "name": "svExportFormat",
5
+ "value": "jsonex"
6
+ }
7
+ ],
8
+ "fetch_list": []
9
+ }
@@ -0,0 +1,23 @@
1
+ import transport from "../transport.js";
2
+ import body from "./body.json" with { type: "json" };
3
+
4
+ const startFunc = async ({
5
+ inHeaderId,
6
+ inUrl = "http://localhost:9000",
7
+ inTdl
8
+ } = {}) => {
9
+ const localHeaderId = inHeaderId;
10
+ const localUrl = inUrl;
11
+
12
+ if (inTdl) {
13
+ body.tdlmessage = inTdl;
14
+ };
15
+
16
+ return transport({
17
+ inHeaderId: localHeaderId,
18
+ inUrl: localUrl,
19
+ inBodyAsJson: JSON.stringify(body)
20
+ });
21
+ };
22
+
23
+ export default startFunc;
@@ -0,0 +1,26 @@
1
+ const startFunc = async ({ inBodyAsJson, inHeaderId,
2
+ inUrl = "http://localhost:9000",
3
+ inTallyrequest = "Export",
4
+ inType = "Collection"
5
+ }) => {
6
+
7
+ const localBodyAsJson = inBodyAsJson;
8
+ const localHeaderId = inHeaderId;
9
+ const localUrl = inUrl;
10
+
11
+ const response = await fetch(localUrl, {
12
+ method: "POST",
13
+ headers: {
14
+ "Content-Type": "application/json",
15
+ "version": "1",
16
+ "tallyrequest": inTallyrequest,
17
+ "type": inType,
18
+ "id": localHeaderId
19
+ },
20
+ body: localBodyAsJson
21
+ });
22
+
23
+ return await response.json();
24
+ };
25
+
26
+ export default startFunc;
@@ -1,16 +0,0 @@
1
- import transport from "../transport.js";
2
- import reportTemplate from "./template.js";
3
-
4
- const report = async ({
5
- reportId = "Stock Summary",
6
- company = "mani9",
7
- explode = true,
8
- url = "http://localhost:9000"
9
- } = {}) => {
10
- const inXml = reportTemplate({ reportId, company, explode });
11
- console.log("inXml : ", inXml);
12
-
13
- return transport({ inXml, url });
14
- };
15
-
16
- export default report;
@@ -1,23 +0,0 @@
1
- const stockSummaryTemplate = ({ company = "mani9", reportId = "Stock Summary", explode = true } = {}) => `
2
- <ENVELOPE>
3
- <HEADER>
4
- <VERSION>1</VERSION>
5
- <TALLYREQUEST>Export</TALLYREQUEST>
6
- <TYPE>Data</TYPE>
7
- <ID>${reportId}</ID>
8
- </HEADER>
9
- <BODY>
10
- <DESC>
11
- <STATICVARIABLES>
12
- <SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>
13
- <SVCURRENTCOMPANY>${company}</SVCURRENTCOMPANY>
14
- <ITEM>Viaadi Hooks</ITEM>
15
- ${explode ? "<EXPLODEFLAG>Yes</EXPLODEFLAG>" : ""}
16
- </STATICVARIABLES>
17
- </DESC>
18
- </BODY>
19
- </ENVELOPE>
20
- `;
21
-
22
- export default stockSummaryTemplate;
23
- export { stockSummaryTemplate };
package/src/v1/index.js DELETED
@@ -1,69 +0,0 @@
1
- import tallySpec from "tally-spec";
2
- import send from "./send/index.js";
3
- import sendPeriod from "./send/period.js";
4
- import byId from "./byId/index.js";
5
-
6
- /**
7
- * Story: Clean Tally XML Client (v12)
8
- *
9
- * Directly imports tally-spec for TDL definitions.
10
- * Exposes:
11
- * 1. companyFilter(inPath, inCompany): Fetches masters/company from Tally given a path and company name.
12
- * 2. companyAndPeriodFilter(inPath, inCompany, inFromDate, inToDate): Fetches period vouchers from Tally.
13
- * 3. reports(): Fetches reports (e.g. Stock Summary) from Tally.
14
- */
15
- const companyFilter = async (inPath, inCompany) => {
16
- const localPath = inPath;
17
- const localCompany = inCompany;
18
-
19
- const endpoint = localPath.split(".").reduce((acc, key) => acc?.[key], tallySpec.source);
20
-
21
- if (!endpoint?.tdl) {
22
- throw new Error(`Master endpoint not found in structure: ${localPath}`);
23
- }
24
-
25
- return await send({
26
- inTdlMessage: endpoint.tdl,
27
- inCompany: localCompany
28
- });
29
- };
30
-
31
- const companyAndPeriodFilter = async (inPath, inCompany, inFromDate, inToDate) => {
32
- const localPath = inPath;
33
- const localCompany = inCompany;
34
- const localFromDate = inFromDate;
35
- const localToDate = inToDate;
36
-
37
- const endpoint = localPath.split(".").reduce((acc, key) => acc?.[key], tallySpec.source);
38
-
39
- if (!endpoint?.tdl) {
40
- throw new Error(`Master endpoint not found in structure: ${localPath}`);
41
- }
42
-
43
- return await sendPeriod({
44
- inTdlMessage: endpoint.tdl,
45
- inCompany: localCompany,
46
- inFromDate: localFromDate,
47
- inToDate: localToDate
48
- });
49
- };
50
-
51
- const reports = async (inPath, inCompany) => {
52
- const localPath = inPath;
53
- const localCompany = inCompany;
54
-
55
- const endpoint = localPath.split(".").reduce((acc, key) => acc?.[key], tallySpec.source);
56
- // console.log("endpoint : ", endpoint);
57
-
58
- if (!endpoint?.reportId) {
59
- throw new Error(`Master endpoint not found in structure: ${localPath}`);
60
- };
61
-
62
- return await byId({
63
- reportId: endpoint.reportId,
64
- company: localCompany
65
- });
66
- };
67
-
68
- export default companyFilter;
69
- export { companyFilter, companyAndPeriodFilter, reports };
@@ -1,31 +0,0 @@
1
- import transport from "../transport.js";
2
- import { variableTemplate } from "./templates.js";
3
-
4
- /**
5
- * Story: Sending XML Payload to Tally
6
- *
7
- * 1. Wraps the TDL message into the Tally XML envelope.
8
- * 2. Injects SVCURRENTCOMPANY if a company name is supplied.
9
- * 3. Delegates HTTP dispatch to transport.
10
- * 4. Returns the raw XML response text.
11
- */
12
- const startFunc = async ({ inTdlMessage, inCompany }) => {
13
- const localTdlMessage = inTdlMessage;
14
- const localCompany = inCompany;
15
-
16
- let localXml = variableTemplate.replace("{{TDLMESSAGE}}", () => localTdlMessage);
17
-
18
- if (localCompany) {
19
- const companyTag = `<SVCURRENTCOMPANY>${localCompany}</SVCURRENTCOMPANY>`;
20
- localXml = localXml.replace("{{STATICVARIABLES}}", companyTag);
21
- } else {
22
- localXml = localXml.replace("{{STATICVARIABLES}}", "");
23
- }
24
- console.log("localXml : ", localXml);
25
-
26
- return await transport({
27
- inXml: localXml
28
- });
29
- };
30
-
31
- export default startFunc;
@@ -1,36 +0,0 @@
1
- import transport from "../transport.js";
2
- import { variableTemplate } from "./templates.js";
3
-
4
- /**
5
- * Story: Sending XML Payload to Tally with Period
6
- *
7
- * 1. Wraps the TDL message into the Tally XML envelope.
8
- * 2. Injects SVCURRENTCOMPANY and date range into static variables.
9
- * 3. Delegates HTTP dispatch to transport.
10
- * 4. Returns the raw XML response text.
11
- */
12
- const startFunc = async ({ inTdlMessage, inCompany, inFromDate, inToDate }) => {
13
- const localTdlMessage = inTdlMessage?.replaceAll("$$$$", "$$");
14
- const localCompany = inCompany;
15
- const localFromDate = inFromDate;
16
- const localToDate = inToDate;
17
-
18
- let localXml = variableTemplate.replace("{{TDLMESSAGE}}", () => localTdlMessage);
19
-
20
- if (localCompany) {
21
- const companyTag = `<SVCURRENTCOMPANY>${localCompany}</SVCURRENTCOMPANY>`;
22
- const fromDateTag = `<SVFROMDATE TYPE="Date">${localFromDate}</SVFROMDATE>`;
23
- const toDateTag = `<SVTODATE TYPE="Date">${localToDate}</SVTODATE>`;
24
- localXml = localXml.replace("{{STATICVARIABLES}}", companyTag + fromDateTag + toDateTag);
25
- } else {
26
- const fromDateTag = `<SVFROMDATE TYPE="Date">${localFromDate}</SVFROMDATE>`;
27
- const toDateTag = `<SVTODATE TYPE="Date">${localToDate}</SVTODATE>`;
28
- localXml = localXml.replace("{{STATICVARIABLES}}", fromDateTag + toDateTag);
29
- }
30
-
31
- return await transport({
32
- inXml: localXml
33
- });
34
- };
35
-
36
- export default startFunc;
@@ -1,90 +0,0 @@
1
- const companyTemplate = `<ENVELOPE>
2
- <HEADER>
3
- <VERSION>1</VERSION>
4
- <TALLYREQUEST>Export</TALLYREQUEST>
5
- <TYPE>Collection</TYPE>
6
- <ID>ks</ID>
7
- </HEADER>
8
- <BODY>
9
- <DESC>
10
- <STATICVARIABLES>
11
- <SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>
12
- </STATICVARIABLES>
13
- <TDL>
14
- <TDLMESSAGE>
15
- <COLLECTION NAME="ks">
16
- {{TDLMESSAGE}}
17
- </COLLECTION>
18
- </TDLMESSAGE>
19
- </TDL>
20
- </DESC>
21
- </BODY>
22
- </ENVELOPE>`;
23
-
24
- const variableTemplate = `<ENVELOPE>
25
- <HEADER>
26
- <VERSION>1</VERSION>
27
- <TALLYREQUEST>Export</TALLYREQUEST>
28
- <TYPE>Collection</TYPE>
29
- <ID>ks</ID>
30
- </HEADER>
31
- <BODY>
32
- <DESC>
33
- <STATICVARIABLES>
34
- <SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>
35
- {{STATICVARIABLES}}
36
- </STATICVARIABLES>
37
- <TDL>
38
- <TDLMESSAGE>
39
- <COLLECTION NAME="ks">
40
- {{TDLMESSAGE}}
41
- </COLLECTION>
42
- </TDLMESSAGE>
43
- </TDL>
44
- </DESC>
45
- </BODY>
46
- </ENVELOPE>`;
47
-
48
- const K2 = `<ENVELOPE>
49
- <HEADER>
50
- <VERSION>1</VERSION>
51
- <TALLYREQUEST>Export</TALLYREQUEST>
52
- <TYPE>Collection</TYPE>
53
- <ID>ks</ID>
54
- </HEADER>
55
-
56
- <BODY>
57
- <DESC>
58
- <STATICVARIABLES>
59
- <SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>
60
-
61
- <SVFROMDATE TYPE="Date">20260401</SVFROMDATE>
62
- <SVTODATE TYPE="Date">20260401</SVTODATE>
63
- </STATICVARIABLES>
64
-
65
- <TDL>
66
- <TDLMESSAGE>
67
-
68
- <COLLECTION NAME="ks">
69
- <TYPE>Vouchers:VoucherType</TYPE>
70
- <CHILDOF>$$VchTypeSales</CHILDOF>
71
- <BELONGSTO>Yes</BELONGSTO>
72
-
73
- <FETCH>
74
- Date,
75
- VoucherNumber,
76
- VoucherTypeName,
77
- PartyLedgerName,
78
- Amount,
79
- AllInventoryEntries,
80
- AllLedgerEntries
81
- </FETCH>
82
- </COLLECTION>
83
-
84
- </TDLMESSAGE>
85
- </TDL>
86
- </DESC>
87
- </BODY>
88
- </ENVELOPE>`;
89
-
90
- export { companyTemplate, variableTemplate, K2 };
@@ -1 +0,0 @@
1
- export { default, reportTemplate } from "../../send/templates/reports/stockSummary.js";
@@ -1,16 +0,0 @@
1
- const startFunc = async ({ inXml }) => {
2
- const localXml = inXml;
3
- const localUrl = "http://localhost:9000";
4
-
5
- const response = await fetch(localUrl, {
6
- method: "POST",
7
- headers: {
8
- "Content-Type": "text/xml"
9
- },
10
- body: localXml
11
- });
12
-
13
- return await response.text();
14
- };
15
-
16
- export default startFunc;
package/src/v2/index.js DELETED
@@ -1,8 +0,0 @@
1
- import noCompanyFromInternal from "./noCompany/index.js";
2
-
3
- const noCompany = async (headerId = "") => {
4
- return await noCompanyFromInternal({ inHeaderId: headerId });
5
- };
6
-
7
- export default noCompany;
8
- export { noCompany };
File without changes