tally-xml-tdl 1.6.2 → 1.13.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,21 +1,16 @@
1
1
  {
2
2
  "name": "tally-xml-tdl",
3
- "version": "1.6.2",
3
+ "version": "1.13.1",
4
4
  "description": "Simple, clean TDL and XML extraction and manipulation tools for Tally",
5
5
  "type": "module",
6
- "main": "index.js",
7
- "types": "index.d.ts",
6
+ "main": "src/v13/main.js",
7
+ "module": "./src/v13/main.js",
8
8
  "sideEffects": false,
9
9
  "exports": {
10
10
  ".": {
11
- "types": "./index.d.ts",
12
- "import": "./index.js",
13
- "default": "./index.js"
14
- },
15
- "./v6": {
16
- "types": "./src/v6/index.d.ts",
17
- "import": "./src/v6/index.js",
18
- "default": "./src/v6/index.js"
11
+ "types": "./src/v13/main.js",
12
+ "import": "./src/v13/main.js",
13
+ "default": "./src/v13/main.js"
19
14
  }
20
15
  },
21
16
  "files": [
package/src/index.js CHANGED
@@ -1,2 +1 @@
1
- export * from "./v6/index.js";
2
- export * as v6 from "./v6/index.js";
1
+ export * from "./v13/main.js";
@@ -0,0 +1,8 @@
1
+ export interface V6Options {
2
+ company: string;
3
+ jsonId: string;
4
+ url?: string;
5
+ }
6
+
7
+ export function get<T = any>(options?: V6Options): Promise<T>;
8
+ export function clean<T = any>(options?: V6Options): Promise<T>;
@@ -0,0 +1,92 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { fileURLToPath } from "url";
4
+
5
+ import { executeXml, executeXmlAndClean } from "./core/index.js";
6
+ import { buildXml } from "./core/buildXml.js";
7
+ import bodyJson from "./body.json" with {type: "json"};
8
+
9
+ import executeBody from "./core/execute/executeBody.js";
10
+ import executeXmlFunc from "./core/execute/executeXml.js";
11
+ import { cleanTallyResponse } from "./core/cleanTallyResponse.js";
12
+ import { xmlToJson } from "./core/response/xmlToJson.js";
13
+
14
+ import purchaseBody from "./purc/body.json" with {type: "json"};
15
+
16
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
17
+ const body = fs.readFileSync(path.join(__dirname, "body.xml"), "utf8");
18
+
19
+ const get = (options = {}) => {
20
+ const company = options.company;
21
+ const jsonId = options.jsonId;
22
+
23
+ const { tdlMessage } = bodyJson[jsonId];
24
+
25
+ const staticVariables = `<SVCURRENTCOMPANY>${company}</SVCURRENTCOMPANY>`;
26
+
27
+ const xml = buildXml(body, {
28
+ staticVariables,
29
+ tdlMessage
30
+ });
31
+
32
+ return executeXml(xml, options);
33
+ };
34
+
35
+ const clean = (options = {}) => {
36
+ const company = options.company;
37
+ const jsonId = options.jsonId;
38
+
39
+ const { tdlMessage } = bodyJson[jsonId];
40
+
41
+ const staticVariables = `<SVCURRENTCOMPANY>${company}</SVCURRENTCOMPANY>`;
42
+
43
+ const xml = buildXml(body, {
44
+ staticVariables,
45
+ tdlMessage
46
+ });
47
+
48
+ return executeXmlAndClean(xml, options);
49
+ };
50
+
51
+ const company = async (showLog = false) => {
52
+ const jsonId = "company";
53
+
54
+ const { tdlMessage } = bodyJson[jsonId];
55
+ if (showLog) console.log("tdlMessage : ", tdlMessage);
56
+
57
+ const xml = buildXml(body, {
58
+ tdlMessage
59
+ });
60
+
61
+ return executeXmlAndClean(xml);
62
+ };
63
+
64
+ const purchase = async () => {
65
+ const retXml = await executeBody(purchaseBody);
66
+ // console.log("retXml : ", retXml);
67
+ const fromTally = xmlToJson(retXml);
68
+
69
+ return cleanTallyResponse(fromTally);
70
+ };
71
+
72
+ const purchaseFromXml = async () => {
73
+
74
+ const xml = fs.readFileSync(path.join(__dirname, "purc/body.xml"), "utf8");
75
+
76
+ const retXml = await executeXmlFunc(xml);
77
+ // console.log("retXml : ", retXml);
78
+
79
+ return retXml;
80
+ };
81
+
82
+ const daybook = async () => {
83
+
84
+ const xml = fs.readFileSync(path.join(__dirname, "daybook/body.xml"), "utf8");
85
+ console.log("xml : ", xml);
86
+ const retXml = await executeXmlFunc(xml);
87
+ console.log("retXml : ", retXml);
88
+
89
+ return retXml;
90
+ };
91
+
92
+ export { get, clean, company, purchase, purchaseFromXml, daybook };
@@ -0,0 +1,3 @@
1
+ import company from "./company.js";
2
+
3
+ export { company };
package/src/v6/body.json CHANGED
@@ -1,4 +1,8 @@
1
1
  {
2
+ "company": {
3
+ "staticVariables": "<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>",
4
+ "tdlMessage": "<TYPE>Company</TYPE><FETCH>$$Alias:Name</FETCH>"
5
+ },
2
6
  "uom": {
3
7
  "staticVariables": "<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>",
4
8
  "tdlMessage": "<TYPE>Unit</TYPE><FETCH>$$Alias:Name</FETCH>"
@@ -1,5 +1,5 @@
1
1
  export const buildXml = (body, {
2
- staticVariables,
2
+ staticVariables = "",
3
3
  tdlMessage
4
4
  }) => {
5
5
 
package/src/v6/index.js CHANGED
@@ -41,4 +41,16 @@ const clean = (options = {}) => {
41
41
  return executeXmlAndClean(xml, options);
42
42
  };
43
43
 
44
- export { get, clean };
44
+ const company = async () => {
45
+ const jsonId = "company";
46
+
47
+ const { tdlMessage } = bodyJson[jsonId];
48
+
49
+ const xml = buildXml(body, {
50
+ tdlMessage
51
+ });
52
+
53
+ return executeXmlAndClean(xml);
54
+ };
55
+
56
+ export { get, clean, company };