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.
- package/LICENSE +21 -0
- package/README.md +95 -0
- package/index.d.ts +84 -0
- package/index.js +1 -0
- package/package.json +57 -0
- package/src/index.js +5 -0
- package/src/v1/client.js +59 -0
- package/src/v1/envelope.js +87 -0
- package/src/v1/index.d.ts +65 -0
- package/src/v1/index.js +12 -0
- package/src/v1/jsonToXml.js +20 -0
- package/src/v1/xmlToJson.js +19 -0
- package/src/v2/client.js +59 -0
- package/src/v2/envelope.js +87 -0
- package/src/v2/index.d.ts +65 -0
- package/src/v2/index.js +12 -0
- package/src/v2/jsonToXml.js +20 -0
- package/src/v2/xmlToJson.js +19 -0
- package/src/v3/client.js +105 -0
- package/src/v3/envelope.js +87 -0
- package/src/v3/index.d.ts +78 -0
- package/src/v3/index.js +14 -0
- package/src/v3/jsonToXml.js +20 -0
- package/src/v3/xmlToJson.js +19 -0
- package/src/v4/company/body.json +7 -0
- package/src/v4/company/index.js +12 -0
- package/src/v4/core/execute/executeBody.js +48 -0
- package/src/v4/core/execute/executeXml.js +13 -0
- package/src/v4/core/execute/fetchCollection.js +35 -0
- package/src/v4/core/execute/index.js +4 -0
- package/src/v4/core/index.js +31 -0
- package/src/v4/core/request/envelope.js +86 -0
- package/src/v4/core/request/index.js +6 -0
- package/src/v4/core/request/jsonToXml.js +19 -0
- package/src/v4/core/response/extract.js +17 -0
- package/src/v4/core/response/index.js +4 -0
- package/src/v4/core/response/validate.js +20 -0
- package/src/v4/core/response/xmlToJson.js +18 -0
- package/src/v4/core/transport/http.js +40 -0
- package/src/v4/core/transport/index.js +1 -0
- package/src/v4/import/index.js +7 -0
- package/src/v4/import/transaction/index.js +10 -0
- package/src/v4/import/transaction/last/body.xml +34 -0
- package/src/v4/import/transaction/last/index.js +12 -0
- package/src/v4/import/transaction/sales/body.xml +50 -0
- package/src/v4/import/transaction/sales/index.js +12 -0
- package/src/v4/index.d.ts +132 -0
- package/src/v4/index.js +15 -0
- package/src/v4/masters/accounting/currency/body.json +10 -0
- package/src/v4/masters/accounting/currency/index.js +12 -0
- package/src/v4/masters/accounting/group/body.json +8 -0
- package/src/v4/masters/accounting/group/index.js +12 -0
- package/src/v4/masters/accounting/index.js +16 -0
- package/src/v4/masters/accounting/ledger/body.json +8 -0
- package/src/v4/masters/accounting/ledger/index.js +12 -0
- package/src/v4/masters/accounting/voucherTypes/body.json +11 -0
- package/src/v4/masters/accounting/voucherTypes/index.js +12 -0
- package/src/v4/masters/index.js +10 -0
- package/src/v4/masters/inventory/batch/body.json +26 -0
- package/src/v4/masters/inventory/batch/index.js +12 -0
- package/src/v4/masters/inventory/godown/body.json +8 -0
- package/src/v4/masters/inventory/godown/index.js +12 -0
- package/src/v4/masters/inventory/index.js +19 -0
- package/src/v4/masters/inventory/stockCategory/body.json +8 -0
- package/src/v4/masters/inventory/stockCategory/index.js +12 -0
- package/src/v4/masters/inventory/stockItems/body copy.json +8 -0
- package/src/v4/masters/inventory/stockItems/body.json +26 -0
- package/src/v4/masters/inventory/stockItems/index.js +12 -0
- package/src/v4/masters/inventory/uom/body.json +13 -0
- package/src/v4/masters/inventory/uom/index.js +12 -0
- package/src/v4/reports/index.js +7 -0
- package/src/v4/reports/inventory/index.js +7 -0
- package/src/v4/reports/inventory/stockItems/body copy 2.json +34 -0
- package/src/v4/reports/inventory/stockItems/body copy.json +26 -0
- package/src/v4/reports/inventory/stockItems/body.json +34 -0
- package/src/v4/reports/inventory/stockItems/index.js +12 -0
- package/src/v4/transactions/index.js +15 -0
- package/src/v4/transactions/purchase/body.json +36 -0
- package/src/v4/transactions/purchase/index.js +12 -0
- package/src/v4/transactions/sale/body copy.json +36 -0
- package/src/v4/transactions/sale/body.json +40 -0
- package/src/v4/transactions/sale/index.js +12 -0
- package/src/v4/transactions/stockJournal/body.json +40 -0
- package/src/v4/transactions/stockJournal/index.js +12 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 KeshavSoft
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to do so, subject to the
|
|
10
|
+
following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# KeshavSoft
|
|
2
|
+
|
|
3
|
+
Simple tools. Clean architecture. Fast development.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## @keshavsoft/kschema
|
|
8
|
+
|
|
9
|
+
A lightweight schema-driven JSON database for Node.js.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
npm i @keshavsoft/kschema
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
import { kschema } from "@keshavsoft/kschema";
|
|
22
|
+
|
|
23
|
+
kschema.loadConfig({ dataPath: "./data" });
|
|
24
|
+
|
|
25
|
+
const users = kschema.table("users");
|
|
26
|
+
|
|
27
|
+
users.insert({ name: "keshav" });
|
|
28
|
+
|
|
29
|
+
const data = users.get();
|
|
30
|
+
|
|
31
|
+
console.log(data);
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## API
|
|
36
|
+
|
|
37
|
+
Create
|
|
38
|
+
|
|
39
|
+
users.insert(record);
|
|
40
|
+
users.insertStrict(record);
|
|
41
|
+
|
|
42
|
+
Read
|
|
43
|
+
|
|
44
|
+
users.get();
|
|
45
|
+
users.findByPk(id);
|
|
46
|
+
|
|
47
|
+
Filter
|
|
48
|
+
|
|
49
|
+
users.filterByPk(id);
|
|
50
|
+
users.filterByColumns({ name: "keshav" });
|
|
51
|
+
|
|
52
|
+
Update
|
|
53
|
+
|
|
54
|
+
users.update(record);
|
|
55
|
+
|
|
56
|
+
Delete
|
|
57
|
+
|
|
58
|
+
users.delete(id);
|
|
59
|
+
users.deleteByColumns({ name: "keshav" });
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Features
|
|
64
|
+
|
|
65
|
+
* File-based JSON storage
|
|
66
|
+
* Schema-driven design
|
|
67
|
+
* Auto primary key
|
|
68
|
+
* Simple CRUD API
|
|
69
|
+
* Zero dependencies
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Links
|
|
74
|
+
|
|
75
|
+
GitHub: https://github.com/keshavsoft/kschema
|
|
76
|
+
NPM: https://www.npmjs.com/package/@keshavsoft/kschema
|
|
77
|
+
Website: https://keshavsoft.com
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## Contact
|
|
82
|
+
|
|
83
|
+
Email: founder@keshavsoft.com
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## About
|
|
88
|
+
|
|
89
|
+
KeshavSoft builds simple and practical developer tools focused on clarity, speed, and real-world usage.
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## License
|
|
94
|
+
|
|
95
|
+
MIT License — see LICENSE file
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
export * as v1 from "./src/v1/index.js";
|
|
79
|
+
export * as v2 from "./src/v2/index.js";
|
|
80
|
+
export * as v3 from "./src/v3/index.js";
|
|
81
|
+
export * as v4 from "./src/v4/index.js";
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index.js";
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tally-xml-tdl",
|
|
3
|
+
"version": "1.4.1",
|
|
4
|
+
"description": "Simple, clean TDL and XML extraction and manipulation tools for Tally",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./index.d.ts",
|
|
12
|
+
"import": "./index.js",
|
|
13
|
+
"default": "./index.js"
|
|
14
|
+
},
|
|
15
|
+
"./v1": {
|
|
16
|
+
"types": "./src/v1/index.d.ts",
|
|
17
|
+
"import": "./src/v1/index.js",
|
|
18
|
+
"default": "./src/v1/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./v2": {
|
|
21
|
+
"types": "./src/v2/index.d.ts",
|
|
22
|
+
"import": "./src/v2/index.js",
|
|
23
|
+
"default": "./src/v2/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./v3": {
|
|
26
|
+
"types": "./src/v3/index.d.ts",
|
|
27
|
+
"import": "./src/v3/index.js",
|
|
28
|
+
"default": "./src/v3/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./v4": {
|
|
31
|
+
"types": "./src/v4/index.d.ts",
|
|
32
|
+
"import": "./src/v4/index.js",
|
|
33
|
+
"default": "./src/v4/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./*": "./src/*.js"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"src",
|
|
39
|
+
"index.js",
|
|
40
|
+
"index.d.ts",
|
|
41
|
+
"README.md",
|
|
42
|
+
"LICENSE"
|
|
43
|
+
],
|
|
44
|
+
"homepage": "https://keshavsoft.com",
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "https://github.com/keshavsoft/tally-xml-tdl"
|
|
48
|
+
},
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/keshavsoft/tally-xml-tdl/issues"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"fast-xml-parser": "^5.11.1",
|
|
54
|
+
"stream-chain": "^4.2.5",
|
|
55
|
+
"stream-json": "^3.6.0"
|
|
56
|
+
}
|
|
57
|
+
}
|
package/src/index.js
ADDED
package/src/v1/client.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
|
|
@@ -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,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
|
+
|
package/src/v1/index.js
ADDED
|
@@ -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
|
+
|
package/src/v2/client.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
|
|
@@ -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
|
+
|