tally-xml-tdl 1.4.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.
Files changed (84) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +95 -0
  3. package/index.d.ts +84 -0
  4. package/index.js +1 -0
  5. package/package.json +57 -0
  6. package/src/index.js +5 -0
  7. package/src/v1/client.js +59 -0
  8. package/src/v1/envelope.js +87 -0
  9. package/src/v1/index.d.ts +65 -0
  10. package/src/v1/index.js +12 -0
  11. package/src/v1/jsonToXml.js +20 -0
  12. package/src/v1/xmlToJson.js +19 -0
  13. package/src/v2/client.js +59 -0
  14. package/src/v2/envelope.js +87 -0
  15. package/src/v2/index.d.ts +65 -0
  16. package/src/v2/index.js +12 -0
  17. package/src/v2/jsonToXml.js +20 -0
  18. package/src/v2/xmlToJson.js +19 -0
  19. package/src/v3/client.js +105 -0
  20. package/src/v3/envelope.js +87 -0
  21. package/src/v3/index.d.ts +78 -0
  22. package/src/v3/index.js +14 -0
  23. package/src/v3/jsonToXml.js +20 -0
  24. package/src/v3/xmlToJson.js +19 -0
  25. package/src/v4/company/body.json +7 -0
  26. package/src/v4/company/index.js +12 -0
  27. package/src/v4/core/execute/executeBody.js +48 -0
  28. package/src/v4/core/execute/executeXml.js +13 -0
  29. package/src/v4/core/execute/fetchCollection.js +35 -0
  30. package/src/v4/core/execute/index.js +4 -0
  31. package/src/v4/core/index.js +31 -0
  32. package/src/v4/core/request/envelope.js +86 -0
  33. package/src/v4/core/request/index.js +6 -0
  34. package/src/v4/core/request/jsonToXml.js +19 -0
  35. package/src/v4/core/response/extract.js +17 -0
  36. package/src/v4/core/response/index.js +4 -0
  37. package/src/v4/core/response/validate.js +20 -0
  38. package/src/v4/core/response/xmlToJson.js +18 -0
  39. package/src/v4/core/transport/http.js +40 -0
  40. package/src/v4/core/transport/index.js +1 -0
  41. package/src/v4/import/index.js +7 -0
  42. package/src/v4/import/transaction/index.js +10 -0
  43. package/src/v4/import/transaction/last/body.xml +34 -0
  44. package/src/v4/import/transaction/last/index.js +12 -0
  45. package/src/v4/import/transaction/sales/body.xml +50 -0
  46. package/src/v4/import/transaction/sales/index.js +12 -0
  47. package/src/v4/index.d.ts +132 -0
  48. package/src/v4/index.js +15 -0
  49. package/src/v4/masters/accounting/currency/body.json +10 -0
  50. package/src/v4/masters/accounting/currency/index.js +12 -0
  51. package/src/v4/masters/accounting/group/body.json +8 -0
  52. package/src/v4/masters/accounting/group/index.js +12 -0
  53. package/src/v4/masters/accounting/index.js +16 -0
  54. package/src/v4/masters/accounting/ledger/body.json +8 -0
  55. package/src/v4/masters/accounting/ledger/index.js +12 -0
  56. package/src/v4/masters/accounting/voucherTypes/body.json +11 -0
  57. package/src/v4/masters/accounting/voucherTypes/index.js +12 -0
  58. package/src/v4/masters/index.js +10 -0
  59. package/src/v4/masters/inventory/batch/body.json +26 -0
  60. package/src/v4/masters/inventory/batch/index.js +12 -0
  61. package/src/v4/masters/inventory/godown/body.json +8 -0
  62. package/src/v4/masters/inventory/godown/index.js +12 -0
  63. package/src/v4/masters/inventory/index.js +19 -0
  64. package/src/v4/masters/inventory/stockCategory/body.json +8 -0
  65. package/src/v4/masters/inventory/stockCategory/index.js +12 -0
  66. package/src/v4/masters/inventory/stockItems/body copy.json +8 -0
  67. package/src/v4/masters/inventory/stockItems/body.json +26 -0
  68. package/src/v4/masters/inventory/stockItems/index.js +12 -0
  69. package/src/v4/masters/inventory/uom/body.json +13 -0
  70. package/src/v4/masters/inventory/uom/index.js +12 -0
  71. package/src/v4/reports/index.js +7 -0
  72. package/src/v4/reports/inventory/index.js +7 -0
  73. package/src/v4/reports/inventory/stockItems/body copy 2.json +34 -0
  74. package/src/v4/reports/inventory/stockItems/body copy.json +26 -0
  75. package/src/v4/reports/inventory/stockItems/body.json +34 -0
  76. package/src/v4/reports/inventory/stockItems/index.js +12 -0
  77. package/src/v4/transactions/index.js +15 -0
  78. package/src/v4/transactions/purchase/body.json +36 -0
  79. package/src/v4/transactions/purchase/index.js +12 -0
  80. package/src/v4/transactions/sale/body copy.json +36 -0
  81. package/src/v4/transactions/sale/body.json +40 -0
  82. package/src/v4/transactions/sale/index.js +12 -0
  83. package/src/v4/transactions/stockJournal/body.json +40 -0
  84. package/src/v4/transactions/stockJournal/index.js +12 -0
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Converts an XML string into a JavaScript object.
3
+ * Attributes are prefixed with '@_'.
4
+ */
5
+ export function xmlToJson<T = any>(xml: string, options?: Record<string, any>): T;
6
+
7
+ /**
8
+ * Converts a JavaScript object into a formatted XML string.
9
+ */
10
+ export function jsonToXml(jsonObj: Record<string, any>, options?: Record<string, any>): string;
11
+
12
+ export interface CreateEnvelopeOptions {
13
+ id?: string;
14
+ type?: string;
15
+ staticVariables?: Record<string, any>;
16
+ tdlMessage?: Record<string, any>;
17
+ }
18
+
19
+ /**
20
+ * Creates a base Tally XML Envelope JavaScript Object.
21
+ */
22
+ export function createEnvelope(options?: CreateEnvelopeOptions): Record<string, any>;
23
+
24
+ export interface CreateCollectionEnvelopeOptions {
25
+ name: string;
26
+ type: string;
27
+ fields?: string | string[];
28
+ filters?: Record<string, any>;
29
+ staticVariables?: Record<string, any>;
30
+ }
31
+
32
+ /**
33
+ * Creates a Tally Collection Request Envelope object.
34
+ */
35
+ export function createCollectionEnvelope(options: CreateCollectionEnvelopeOptions): Record<string, any>;
36
+
37
+ /**
38
+ * Directly builds a Tally XML string for a collection request.
39
+ */
40
+ export function buildCollectionXml(options: CreateCollectionEnvelopeOptions): string;
41
+
42
+ export interface SendToTallyOptions {
43
+ xml: string;
44
+ url?: string;
45
+ }
46
+
47
+ /**
48
+ * Sends an XML payload to Tally via HTTP POST and returns parsed JSON response.
49
+ */
50
+ export function sendToTally<T = any>(options: SendToTallyOptions): Promise<T>;
51
+
52
+ export interface FetchCollectionOptions {
53
+ name: string;
54
+ type: string;
55
+ fields?: string | string[];
56
+ filters?: Record<string, any>;
57
+ staticVariables?: Record<string, any>;
58
+ url?: string;
59
+ }
60
+
61
+ /**
62
+ * High-level helper to fetch any Tally collection directly.
63
+ */
64
+ export function fetchCollection<T = any>(options: FetchCollectionOptions): Promise<T>;
65
+
@@ -0,0 +1,12 @@
1
+ export { xmlToJson } from "./xmlToJson.js";
2
+ export { jsonToXml } from "./jsonToXml.js";
3
+ export {
4
+ createEnvelope,
5
+ createCollectionEnvelope,
6
+ buildCollectionXml
7
+ } from "./envelope.js";
8
+ export {
9
+ sendToTally,
10
+ fetchCollection
11
+ } from "./client.js";
12
+
@@ -0,0 +1,20 @@
1
+ import { XMLBuilder } from "fast-xml-parser";
2
+
3
+ /**
4
+ * Converts a JavaScript Object into formatted XML string.
5
+ * Preserves XML attributes prefixed with `@_`.
6
+ *
7
+ * @param {object} jsonObj - The JavaScript object to serialize.
8
+ * @param {object} [options] - Optional XMLBuilder configurations.
9
+ * @returns {string} Formatted XML string.
10
+ */
11
+ export const jsonToXml = (jsonObj, options = {}) => {
12
+ const builder = new XMLBuilder({
13
+ ignoreAttributes: false,
14
+ format: true,
15
+ ...options
16
+ });
17
+
18
+ return builder.build(jsonObj);
19
+ };
20
+
@@ -0,0 +1,19 @@
1
+ import { XMLParser } from "fast-xml-parser";
2
+
3
+ /**
4
+ * Converts XML string into a JavaScript Object.
5
+ * Preserves XML attributes using the `@_` prefix.
6
+ *
7
+ * @param {string} xml - The XML string to parse.
8
+ * @param {object} [options] - Optional XMLParser configurations.
9
+ * @returns {object} The parsed JavaScript object.
10
+ */
11
+ export const xmlToJson = (xml, options = {}) => {
12
+ const parser = new XMLParser({
13
+ ignoreAttributes: false,
14
+ ...options
15
+ });
16
+
17
+ return parser.parse(xml);
18
+ };
19
+
@@ -0,0 +1,105 @@
1
+ import { xmlToJson } from "./xmlToJson.js";
2
+ import { jsonToXml } from "./jsonToXml.js";
3
+ import { createCollectionEnvelope } from "./envelope.js";
4
+
5
+ /**
6
+ * Sends an XML payload to Tally via HTTP POST.
7
+ *
8
+ * @param {object} params
9
+ * @param {string} params.xml - The XML string to send.
10
+ * @param {string} [params.url="http://localhost:9000"] - Tally HTTP endpoint URL.
11
+ * @returns {Promise<object>} Parsed JSON response from Tally.
12
+ */
13
+ export const sendToTally = async ({
14
+ xml,
15
+ url = "http://localhost:9000"
16
+ } = {}) => {
17
+ const res = await fetch(url, {
18
+ method: "POST",
19
+ headers: {
20
+ "Content-Type": "text/xml"
21
+ },
22
+ body: xml
23
+ });
24
+
25
+ const text = await res.text();
26
+ return xmlToJson(text);
27
+ };
28
+
29
+ /**
30
+ * High-level helper to fetch any Tally collection directly.
31
+ *
32
+ * @param {object} params
33
+ * @param {string} params.name - Collection name (e.g. 'KeshavGroups')
34
+ * @param {string} params.type - Tally Object Type (e.g. 'Group', 'Ledger', 'Company')
35
+ * @param {string|string[]} [params.fields] - Fields to fetch (e.g. ['Name', 'Parent'])
36
+ * @param {object} [params.filters] - Filters/additional collection properties
37
+ * @param {object} [params.staticVariables] - Optional static variables
38
+ * @param {string} [params.url="http://localhost:9000"] - Tally URL
39
+ * @returns {Promise<object>} Parsed JSON response from Tally
40
+ */
41
+ export const fetchCollection = async ({
42
+ name,
43
+ type,
44
+ fields,
45
+ filters,
46
+ staticVariables,
47
+ url = "http://localhost:9000"
48
+ } = {}) => {
49
+ const envelope = createCollectionEnvelope({
50
+ name,
51
+ type,
52
+ fields,
53
+ filters,
54
+ staticVariables
55
+ });
56
+ const xml = jsonToXml(envelope);
57
+ return await sendToTally({ xml, url });
58
+ };
59
+
60
+ /**
61
+ * Executes a Tally request from a JSON body (either envelope or collection definition).
62
+ *
63
+ * @param {object} body - JSON body (either { ENVELOPE: ... } or { name, type, fields, ... })
64
+ * @param {object} [options]
65
+ * @param {boolean} [options.full=false] - If true, returns full ENVELOPE JSON. If false, returns only children of DATA.COLLECTION on success.
66
+ * @param {string} [options.url="http://localhost:9000"] - Tally URL endpoint
67
+ * @returns {Promise<object>} Tally response data
68
+ */
69
+ export const executeBody = async (body, {
70
+ full = false,
71
+ url = "http://localhost:9000"
72
+ } = {}) => {
73
+ let rawRes;
74
+ if (body.ENVELOPE) {
75
+ const xml = jsonToXml(body);
76
+ rawRes = await sendToTally({ xml, url });
77
+ } else if (body.name && body.type) {
78
+ rawRes = await fetchCollection({ ...body, url });
79
+ } else {
80
+ throw new Error("Unrecognized body format: must contain ENVELOPE or name & type properties");
81
+ }
82
+
83
+ if (full) {
84
+ return rawRes;
85
+ }
86
+
87
+ const headerStatus = rawRes?.ENVELOPE?.HEADER?.STATUS;
88
+ if (headerStatus === 0 || headerStatus === "0" || Number(headerStatus) === 0) {
89
+ throw new Error(`Tally returned error status: ${JSON.stringify(rawRes?.ENVELOPE?.BODY || rawRes)}`);
90
+ }
91
+
92
+ if (rawRes?.ENVELOPE?.BODY?.DATA?.LINEERROR) {
93
+ throw new Error(`Tally line error: ${JSON.stringify(rawRes?.ENVELOPE?.BODY?.DATA?.LINEERROR)}`);
94
+ }
95
+
96
+
97
+ const collectionData = rawRes?.ENVELOPE?.BODY?.DATA?.COLLECTION;
98
+ if (!collectionData) {
99
+ throw new Error("No DATA.COLLECTION found in Tally response");
100
+ }
101
+
102
+ return collectionData;
103
+ };
104
+
105
+
@@ -0,0 +1,87 @@
1
+ import { jsonToXml } from "./jsonToXml.js";
2
+
3
+ /**
4
+ * Creates a base Tally XML Envelope JavaScript Object.
5
+ *
6
+ * @param {object} [params]
7
+ * @param {string} [params.id=""] - Collection or Request ID
8
+ * @param {string} [params.type="COLLECTION"] - Request Type (default "COLLECTION")
9
+ * @param {object} [params.staticVariables] - Static variables for DESC
10
+ * @param {object} [params.tdlMessage] - Object to place inside TDLMESSAGE
11
+ * @returns {object} Tally Envelope JS Object
12
+ */
13
+ export const createEnvelope = ({
14
+ id = "",
15
+ type = "COLLECTION",
16
+ staticVariables = { SVEXPORTFORMAT: "$$SysName:XML" },
17
+ tdlMessage = {}
18
+ } = {}) => {
19
+ return {
20
+ ENVELOPE: {
21
+ HEADER: {
22
+ VERSION: 1,
23
+ TALLYREQUEST: "EXPORT",
24
+ TYPE: type,
25
+ ID: id
26
+ },
27
+ BODY: {
28
+ DESC: {
29
+ STATICVARIABLES: staticVariables,
30
+ TDL: {
31
+ TDLMESSAGE: tdlMessage
32
+ }
33
+ }
34
+ }
35
+ }
36
+ };
37
+ };
38
+
39
+ /**
40
+ * Creates a Tally Collection Request Envelope object.
41
+ *
42
+ * @param {object} params
43
+ * @param {string} params.name - Collection name (used for ID and COLLECTION NAME)
44
+ * @param {string} params.type - Tally Object Type (e.g. 'Group', 'Ledger', 'Company')
45
+ * @param {string|string[]} [params.fields] - Field names to FETCH
46
+ * @param {object} [params.filters] - Additional collection child nodes or filters
47
+ * @param {object} [params.staticVariables] - Static variables for DESC
48
+ * @returns {object} Tally Envelope JS Object
49
+ */
50
+ export const createCollectionEnvelope = ({
51
+ name,
52
+ type,
53
+ fields = [],
54
+ filters = {},
55
+ staticVariables = { SVEXPORTFORMAT: "$$SysName:XML" }
56
+ } = {}) => {
57
+ const fetchValue = Array.isArray(fields)
58
+ ? fields.join(",\n ")
59
+ : (fields || "");
60
+
61
+ const collectionDef = {
62
+ "@_NAME": name,
63
+ TYPE: type,
64
+ ...(fetchValue ? { FETCH: fetchValue } : {}),
65
+ ...filters
66
+ };
67
+
68
+ return createEnvelope({
69
+ id: name,
70
+ type: "COLLECTION",
71
+ staticVariables,
72
+ tdlMessage: {
73
+ COLLECTION: collectionDef
74
+ }
75
+ });
76
+ };
77
+
78
+ /**
79
+ * Helper to build an XML string directly for a collection query.
80
+ *
81
+ * @param {object} options - Options passed to createCollectionEnvelope
82
+ * @returns {string} XML string ready to send to Tally
83
+ */
84
+ export const buildCollectionXml = (options) => {
85
+ return jsonToXml(createCollectionEnvelope(options));
86
+ };
87
+
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Converts an XML string into a JavaScript object.
3
+ * Attributes are prefixed with '@_'.
4
+ */
5
+ export function xmlToJson<T = any>(xml: string, options?: Record<string, any>): T;
6
+
7
+ /**
8
+ * Converts a JavaScript object into a formatted XML string.
9
+ */
10
+ export function jsonToXml(jsonObj: Record<string, any>, options?: Record<string, any>): string;
11
+
12
+ export interface CreateEnvelopeOptions {
13
+ id?: string;
14
+ type?: string;
15
+ staticVariables?: Record<string, any>;
16
+ tdlMessage?: Record<string, any>;
17
+ }
18
+
19
+ /**
20
+ * Creates a base Tally XML Envelope JavaScript Object.
21
+ */
22
+ export function createEnvelope(options?: CreateEnvelopeOptions): Record<string, any>;
23
+
24
+ export interface CreateCollectionEnvelopeOptions {
25
+ name: string;
26
+ type: string;
27
+ fields?: string | string[];
28
+ filters?: Record<string, any>;
29
+ staticVariables?: Record<string, any>;
30
+ }
31
+
32
+ /**
33
+ * Creates a Tally Collection Request Envelope object.
34
+ */
35
+ export function createCollectionEnvelope(options: CreateCollectionEnvelopeOptions): Record<string, any>;
36
+
37
+ /**
38
+ * Directly builds a Tally XML string for a collection request.
39
+ */
40
+ export function buildCollectionXml(options: CreateCollectionEnvelopeOptions): string;
41
+
42
+ export interface SendToTallyOptions {
43
+ xml: string;
44
+ url?: string;
45
+ }
46
+
47
+ /**
48
+ * Sends an XML payload to Tally via HTTP POST and returns parsed JSON response.
49
+ */
50
+ export function sendToTally<T = any>(options: SendToTallyOptions): Promise<T>;
51
+
52
+ export interface FetchCollectionOptions {
53
+ name: string;
54
+ type: string;
55
+ fields?: string | string[];
56
+ filters?: Record<string, any>;
57
+ staticVariables?: Record<string, any>;
58
+ url?: string;
59
+ }
60
+
61
+ /**
62
+ * High-level helper to fetch any Tally collection directly.
63
+ */
64
+ export function fetchCollection<T = any>(options: FetchCollectionOptions): Promise<T>;
65
+
66
+ export interface ExecuteBodyOptions {
67
+ full?: boolean;
68
+ url?: string;
69
+ }
70
+
71
+ /**
72
+ * Executes a Tally request from a JSON body (either envelope or collection definition).
73
+ * If options.full is false (default), returns only the children of DATA.COLLECTION on success.
74
+ * If options.full is true, returns the raw full ENVELOPE JSON response.
75
+ */
76
+ export function executeBody<T = any>(body: Record<string, any>, options?: ExecuteBodyOptions): Promise<T>;
77
+
78
+
@@ -0,0 +1,14 @@
1
+ export { xmlToJson } from "./xmlToJson.js";
2
+ export { jsonToXml } from "./jsonToXml.js";
3
+ export {
4
+ createEnvelope,
5
+ createCollectionEnvelope,
6
+ buildCollectionXml
7
+ } from "./envelope.js";
8
+ export {
9
+ sendToTally,
10
+ fetchCollection,
11
+ executeBody
12
+ } from "./client.js";
13
+
14
+
@@ -0,0 +1,20 @@
1
+ import { XMLBuilder } from "fast-xml-parser";
2
+
3
+ /**
4
+ * Converts a JavaScript Object into formatted XML string.
5
+ * Preserves XML attributes prefixed with `@_`.
6
+ *
7
+ * @param {object} jsonObj - The JavaScript object to serialize.
8
+ * @param {object} [options] - Optional XMLBuilder configurations.
9
+ * @returns {string} Formatted XML string.
10
+ */
11
+ export const jsonToXml = (jsonObj, options = {}) => {
12
+ const builder = new XMLBuilder({
13
+ ignoreAttributes: false,
14
+ format: true,
15
+ ...options
16
+ });
17
+
18
+ return builder.build(jsonObj);
19
+ };
20
+
@@ -0,0 +1,19 @@
1
+ import { XMLParser } from "fast-xml-parser";
2
+
3
+ /**
4
+ * Converts XML string into a JavaScript Object.
5
+ * Preserves XML attributes using the `@_` prefix.
6
+ *
7
+ * @param {string} xml - The XML string to parse.
8
+ * @param {object} [options] - Optional XMLParser configurations.
9
+ * @returns {object} The parsed JavaScript object.
10
+ */
11
+ export const xmlToJson = (xml, options = {}) => {
12
+ const parser = new XMLParser({
13
+ ignoreAttributes: false,
14
+ ...options
15
+ });
16
+
17
+ return parser.parse(xml);
18
+ };
19
+
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "KeshavOpenCompanies",
3
+ "type": "Company",
4
+ "fields": [
5
+ "Name"
6
+ ]
7
+ }
@@ -0,0 +1,12 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { fileURLToPath } from "url";
4
+ import { executeBody } from "../core/index.js";
5
+
6
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
+ export const body = JSON.parse(fs.readFileSync(path.join(__dirname, "body.json"), "utf8"));
8
+
9
+ export const get = (options) => executeBody(body, options);
10
+ get.body = body;
11
+
12
+ export default get;
@@ -0,0 +1,48 @@
1
+ import { jsonToXml } from "../request/jsonToXml.js";
2
+ import { createCollectionEnvelope } from "../request/envelope.js";
3
+ import { sendXml } from "../transport/http.js";
4
+ import { xmlToJson } from "../response/xmlToJson.js";
5
+ import { validateResponse } from "../response/validate.js";
6
+ import { extractCollection } from "../response/extract.js";
7
+
8
+ /**
9
+ * The Story of a Query:
10
+ * Act 1 - Request: Build XML payload from body
11
+ * Act 2 - Transport: Send XML over HTTP to Tally
12
+ * Act 3 - Response: Parse XML, validate status, and extract collection entities
13
+ *
14
+ * @param {object} body - Query specification (either { ENVELOPE: ... } or { name, type, fields, ... })
15
+ * @param {object} [options]
16
+ * @param {boolean} [options.full=false] - If true, returns the raw full ENVELOPE JSON. If false, validates and returns only children of DATA.COLLECTION.
17
+ * @param {string} [options.url="http://localhost:9000"] - Tally HTTP endpoint URL.
18
+ * @returns {Promise<object>} Tally data response.
19
+ */
20
+ export const executeBody = async (body, {
21
+ full = false,
22
+ url = "http://localhost:9000"
23
+ } = {}) => {
24
+ // Act 1: Request (Formulating what to send)
25
+ let xml;
26
+ if (body.ENVELOPE) {
27
+ xml = jsonToXml(body);
28
+ } else if (body.name && body.type) {
29
+ const envelope = createCollectionEnvelope(body);
30
+ xml = jsonToXml(envelope);
31
+ } else {
32
+ throw new Error("Unrecognized body format: must contain ENVELOPE or name & type properties");
33
+ }
34
+
35
+ // Act 2: Transport (Sending over the wire)
36
+ const rawXml = await sendXml({ xml, url });
37
+
38
+ // Act 3: Response (Interpreting the answer)
39
+ const res = xmlToJson(rawXml);
40
+
41
+ if (full) {
42
+ return res;
43
+ }
44
+
45
+ validateResponse(res);
46
+ return extractCollection(res);
47
+ };
48
+
@@ -0,0 +1,13 @@
1
+ // src/v4/core/execute/executeXml.js
2
+
3
+ import { sendXml } from "../transport/http.js";
4
+ import { xmlToJson } from "../response/xmlToJson.js";
5
+
6
+ export const executeXml = async (
7
+ xml,
8
+ { url = "http://localhost:9000" } = {}
9
+ ) => {
10
+ const rawXml = await sendXml({ xml, url });
11
+
12
+ return xmlToJson(rawXml);
13
+ };
@@ -0,0 +1,35 @@
1
+ import { createCollectionEnvelope } from "../request/envelope.js";
2
+ import { jsonToXml } from "../request/jsonToXml.js";
3
+ import { sendToTally } from "../transport/http.js";
4
+
5
+ /**
6
+ * High-level helper to fetch any Tally collection directly.
7
+ *
8
+ * @param {object} params
9
+ * @param {string} params.name - Collection name (e.g. 'KeshavGroups')
10
+ * @param {string} params.type - Tally Object Type (e.g. 'Group', 'Ledger', 'Company')
11
+ * @param {string|string[]} [params.fields] - Fields to fetch (e.g. ['Name', 'Parent'])
12
+ * @param {object} [params.filters] - Filters/additional collection properties
13
+ * @param {object} [params.staticVariables] - Optional static variables
14
+ * @param {string} [params.url="http://localhost:9000"] - Tally URL
15
+ * @returns {Promise<object>} Parsed JSON response from Tally
16
+ */
17
+ export const fetchCollection = async ({
18
+ name,
19
+ type,
20
+ fields,
21
+ filters,
22
+ staticVariables,
23
+ url = "http://localhost:9000"
24
+ } = {}) => {
25
+ const envelope = createCollectionEnvelope({
26
+ name,
27
+ type,
28
+ fields,
29
+ filters,
30
+ staticVariables
31
+ });
32
+ const xml = jsonToXml(envelope);
33
+ return await sendToTally({ xml, url });
34
+ };
35
+
@@ -0,0 +1,4 @@
1
+ export { executeBody } from "./executeBody.js";
2
+ export { fetchCollection } from "./fetchCollection.js";
3
+ export { executeXml } from "./executeXml.js";
4
+
@@ -0,0 +1,31 @@
1
+ // Sub-modules (The Narrative Story)
2
+ export * as request from "./request/index.js";
3
+ export * as transport from "./transport/index.js";
4
+ export * as response from "./response/index.js";
5
+ export * as execute from "./execute/index.js";
6
+
7
+ // Direct Core Exports
8
+ export {
9
+ jsonToXml,
10
+ createEnvelope,
11
+ createCollectionEnvelope,
12
+ buildCollectionXml
13
+ } from "./request/index.js";
14
+
15
+ export {
16
+ sendXml,
17
+ sendToTally
18
+ } from "./transport/index.js";
19
+
20
+ export {
21
+ xmlToJson,
22
+ validateResponse,
23
+ extractCollection
24
+ } from "./response/index.js";
25
+
26
+ export {
27
+ executeBody,
28
+ fetchCollection,
29
+ executeXml
30
+ } from "./execute/index.js";
31
+