erpnext-queue-client 2.4.3 → 2.4.4

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 (39) hide show
  1. package/dist/client.js +87 -105
  2. package/dist/constants.js +1 -0
  3. package/dist/dataConverter.js +4 -13
  4. package/dist/erpnext/decryptFromErpNext.server.js +1 -1
  5. package/dist/erpnext/decryptFromErpNext.server.test.js +2 -11
  6. package/dist/erpnext/doctypeResourceRequest.js +44 -37
  7. package/dist/erpnext/doctypeSubmittableResourceRequest.js +19 -33
  8. package/dist/erpnext/doctypes/address.js +40 -41
  9. package/dist/erpnext/doctypes/consolidatedCustomsInvoice.js +18 -20
  10. package/dist/erpnext/doctypes/contact.js +30 -30
  11. package/dist/erpnext/doctypes/deliveryNote.js +13 -12
  12. package/dist/erpnext/doctypes/item.d.ts +10 -10
  13. package/dist/erpnext/doctypes/item.js +64 -63
  14. package/dist/erpnext/doctypes/paymentEntry.js +42 -43
  15. package/dist/erpnext/doctypes/productBundle.js +15 -17
  16. package/dist/erpnext/doctypes/purchaseInvoice.js +45 -49
  17. package/dist/erpnext/doctypes/purchaseReceipt.js +41 -43
  18. package/dist/erpnext/doctypes/salesInvoice.js +42 -43
  19. package/dist/erpnext/doctypes/servicecase.js +103 -114
  20. package/dist/erpnext/doctypes/shipment.js +30 -35
  21. package/dist/erpnext/doctypes/stock.js +94 -109
  22. package/dist/erpnext/doctypes/tags.js +58 -77
  23. package/dist/erpnext/erpnextRequestWrapper.js +83 -80
  24. package/dist/erpnext/fileRequests.js +28 -29
  25. package/dist/erpnext/methodRequest.js +37 -43
  26. package/dist/erpnext/model/DocTypeHelpers.js +2 -3
  27. package/dist/erpnext/model/Item.d.ts +6 -6
  28. package/dist/erpnext/model/Item.js +1 -1
  29. package/dist/erpnext/model/StockEntry.d.ts +63 -21
  30. package/dist/erpnext/model/StockEntry.js +22 -21
  31. package/dist/erpnext/reports.js +81 -89
  32. package/dist/erpnext/resourceRequest.js +142 -150
  33. package/dist/index.js +43 -3
  34. package/dist/index.test.js +69 -83
  35. package/dist/utils/fernet.server.js +24 -4
  36. package/dist/utils/request.js +59 -72
  37. package/dist/utils/zodContextOptionals.js +5 -3
  38. package/dist/utils/zodUtils.js +2 -2
  39. package/package.json +1 -1
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.ERPNextShipment = void 0;
13
4
  const doctypeSubmittableResourceRequest_1 = require("../doctypeSubmittableResourceRequest");
@@ -15,6 +6,16 @@ const methodRequest_1 = require("../methodRequest");
15
6
  const Shipment_1 = require("../model/Shipment");
16
7
  const zodContextOptionals_1 = require("../../utils/zodContextOptionals");
17
8
  class ERPNextShipment {
9
+ temporalClient;
10
+ baseRequest;
11
+ methodRequest;
12
+ getList;
13
+ getById;
14
+ updateById;
15
+ deleteById;
16
+ create;
17
+ cancel;
18
+ submit;
18
19
  constructor(temporalClient) {
19
20
  this.temporalClient = temporalClient;
20
21
  this.baseRequest = new doctypeSubmittableResourceRequest_1.ERPNextDoctypeSubmittableResourceRequest(temporalClient, "Shipment", Shipment_1.Shipment);
@@ -27,37 +28,31 @@ class ERPNextShipment {
27
28
  this.cancel = this.baseRequest.cancel;
28
29
  this.submit = this.baseRequest.submit;
29
30
  }
30
- createShipmentDraft(deliveryNoteName) {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- const draft = yield this.methodRequest.request({
33
- methodName: "erpnext.stock.doctype.delivery_note.delivery_note.make_shipment",
34
- requestMethod: "POST",
35
- responseValidationModel: (0, zodContextOptionals_1.ResourceInput)(Shipment_1.Shipment),
36
- params: { source_name: deliveryNoteName },
37
- });
38
- return draft;
31
+ async createShipmentDraft(deliveryNoteName) {
32
+ const draft = await this.methodRequest.request({
33
+ methodName: "erpnext.stock.doctype.delivery_note.delivery_note.make_shipment",
34
+ requestMethod: "POST",
35
+ responseValidationModel: (0, zodContextOptionals_1.ResourceInput)(Shipment_1.Shipment),
36
+ params: { source_name: deliveryNoteName },
39
37
  });
38
+ return draft;
40
39
  }
41
- getShipmentInfoByOrderNumber(orderNumber) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- const shipmentInfo = yield this.methodRequest.request({
44
- methodName: "shipment-by-order-number",
45
- requestMethod: "GET",
46
- params: { order_number: orderNumber },
47
- responseValidationModel: Shipment_1.ShipmentInfoByOrderNumberMethodResponseData,
48
- });
49
- return shipmentInfo;
40
+ async getShipmentInfoByOrderNumber(orderNumber) {
41
+ const shipmentInfo = await this.methodRequest.request({
42
+ methodName: "shipment-by-order-number",
43
+ requestMethod: "GET",
44
+ params: { order_number: orderNumber },
45
+ responseValidationModel: Shipment_1.ShipmentInfoByOrderNumberMethodResponseData,
50
46
  });
47
+ return shipmentInfo;
51
48
  }
52
- addShippingLabelAndSubmit(shipmentErpNextName, body) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- const shipment = yield this.baseRequest.updateById({
55
- resourceId: shipmentErpNextName,
56
- inputValidationModel: Shipment_1.ShipmentAddShippingLabelAndSubmitBody,
57
- body,
58
- });
59
- return shipment;
49
+ async addShippingLabelAndSubmit(shipmentErpNextName, body) {
50
+ const shipment = await this.baseRequest.updateById({
51
+ resourceId: shipmentErpNextName,
52
+ inputValidationModel: Shipment_1.ShipmentAddShippingLabelAndSubmitBody,
53
+ body,
60
54
  });
55
+ return shipment;
61
56
  }
62
57
  }
63
58
  exports.ERPNextShipment = ERPNextShipment;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.ERPNextStock = void 0;
13
4
  const zod_1 = require("zod");
@@ -15,120 +6,114 @@ const methodRequest_1 = require("../methodRequest");
15
6
  const Stock_1 = require("../model/Stock");
16
7
  const reports_1 = require("../reports");
17
8
  class ERPNextStock extends reports_1.ERPNextReports {
9
+ methodRequest;
18
10
  constructor(temporalClient) {
19
11
  super(temporalClient);
20
12
  this.methodRequest = new methodRequest_1.ERPNextMethodRequest(temporalClient);
21
13
  }
22
- getStockBalanceAtDate(date_1) {
23
- return __awaiter(this, arguments, void 0, function* (date, warehouse = "") {
24
- const dateString = date.toISOString().substring(0, 10);
25
- const result = yield this.getReport("Stock Balance", {
26
- filters: Object.assign({ from_date: dateString, to_date: dateString }, (warehouse ? { warehouse } : {})),
27
- }, Stock_1.StockBalanceReportItem);
28
- return result;
29
- });
14
+ async getStockBalanceAtDate(date, warehouse = "") {
15
+ const dateString = date.toISOString().substring(0, 10);
16
+ const result = await this.getReport("Stock Balance", {
17
+ filters: {
18
+ from_date: dateString,
19
+ to_date: dateString,
20
+ ...(warehouse ? { warehouse } : {}),
21
+ },
22
+ }, Stock_1.StockBalanceReportItem);
23
+ return result;
30
24
  }
31
- getStockProjectedQuantityReport(warehouse, sku) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- const result = yield this.getReport("Stock Projected Qty", {
34
- filters: Object.assign(Object.assign({}, (warehouse && { warehouse })), (sku && { item_code: sku })),
35
- }, Stock_1.StockProjectedQuantityReportItem);
36
- return result;
37
- });
25
+ async getStockProjectedQuantityReport(warehouse, sku) {
26
+ const result = await this.getReport("Stock Projected Qty", {
27
+ filters: {
28
+ ...(warehouse && { warehouse }),
29
+ ...(sku && { item_code: sku }),
30
+ },
31
+ }, Stock_1.StockProjectedQuantityReportItem);
32
+ return result;
38
33
  }
39
- getStockFromBin(topLevelWarehouse) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- return yield this.methodRequest.request({
42
- methodName: `get_stock_from_bin`,
43
- requestMethod: "GET",
44
- params: { warehouse: topLevelWarehouse },
45
- });
34
+ async getStockFromBin(topLevelWarehouse) {
35
+ return await this.methodRequest.request({
36
+ methodName: `get_stock_from_bin`,
37
+ requestMethod: "GET",
38
+ params: { warehouse: topLevelWarehouse },
46
39
  });
47
40
  }
48
- getBundleStockFromBin(topLevelWarehouse) {
49
- return __awaiter(this, void 0, void 0, function* () {
50
- return yield this.methodRequest.request({
51
- methodName: `get_bundle_stock_from_bin`,
52
- requestMethod: "GET",
53
- params: { warehouse: topLevelWarehouse },
54
- });
41
+ async getBundleStockFromBin(topLevelWarehouse) {
42
+ return await this.methodRequest.request({
43
+ methodName: `get_bundle_stock_from_bin`,
44
+ requestMethod: "GET",
45
+ params: { warehouse: topLevelWarehouse },
55
46
  });
56
47
  }
57
- getStock(topLevelWarehouse_1) {
58
- return __awaiter(this, arguments, void 0, function* (topLevelWarehouse, options = {
59
- includeBundleStock: false,
60
- respectOversellAmount: false,
61
- respectStockReserve: false,
62
- }) {
63
- const stock = yield this.methodRequest.request({
64
- methodName: `get_stock_from_bin`,
65
- requestMethod: "GET",
66
- params: {
67
- warehouse: topLevelWarehouse,
68
- respect_oversell_amount: options.respectOversellAmount
69
- ? "true"
70
- : "false",
71
- respect_stock_reserve: options.respectStockReserve ? "true" : "false",
72
- },
73
- });
74
- if (!options.includeBundleStock)
75
- return stock;
76
- const bundleStock = yield this.methodRequest.request({
77
- methodName: `get_bundle_stock_from_bin`,
78
- requestMethod: "GET",
79
- params: {
80
- warehouse: topLevelWarehouse,
81
- respect_oversell_amount: options.respectOversellAmount
82
- ? "true"
83
- : "false",
84
- respect_stock_reserve: options.respectStockReserve ? "true" : "false",
85
- },
86
- });
87
- return Object.assign(Object.assign({}, stock), bundleStock);
48
+ async getStock(topLevelWarehouse, options = {
49
+ includeBundleStock: false,
50
+ respectOversellAmount: false,
51
+ respectStockReserve: false,
52
+ }) {
53
+ const stock = await this.methodRequest.request({
54
+ methodName: `get_stock_from_bin`,
55
+ requestMethod: "GET",
56
+ params: {
57
+ warehouse: topLevelWarehouse,
58
+ respect_oversell_amount: options.respectOversellAmount
59
+ ? "true"
60
+ : "false",
61
+ respect_stock_reserve: options.respectStockReserve ? "true" : "false",
62
+ },
88
63
  });
89
- }
90
- getCompletedOrderItemAmounts(orderNumbers) {
91
- return __awaiter(this, void 0, void 0, function* () {
92
- const result = yield this.methodRequest.request({
93
- methodName: `get-completed-orderitem-amounts`,
94
- requestMethod: "POST",
95
- body: {
96
- orderNumbers,
97
- },
98
- responseValidationModel: zod_1.z
99
- .array(zod_1.z.object({
100
- item_code: zod_1.z.string(),
101
- qty: zod_1.z.number(),
102
- }))
103
- .describe("getCompletedOrderItemAmounts response"),
104
- });
105
- const res = result.reduce((acc, item) => {
106
- acc[item.item_code] = item.qty;
107
- return acc;
108
- }, {});
109
- return res;
64
+ if (!options.includeBundleStock)
65
+ return stock;
66
+ const bundleStock = await this.methodRequest.request({
67
+ methodName: `get_bundle_stock_from_bin`,
68
+ requestMethod: "GET",
69
+ params: {
70
+ warehouse: topLevelWarehouse,
71
+ respect_oversell_amount: options.respectOversellAmount
72
+ ? "true"
73
+ : "false",
74
+ respect_stock_reserve: options.respectStockReserve ? "true" : "false",
75
+ },
110
76
  });
77
+ return { ...stock, ...bundleStock };
111
78
  }
112
- getStockProjectedQuantityDict(warehouse, sku) {
113
- return __awaiter(this, void 0, void 0, function* () {
114
- const result = yield this.getStockProjectedQuantityReport(warehouse, sku);
115
- // Stock Projected Quantity report contains one line entry for every warehouse. We need to consolidate them
116
- // to be able to safely convert the report to a dict
117
- const consolidatedStockProjectedQuantity = result.reduce((acc, item) => {
118
- if (acc[item.item_code]) {
119
- acc[item.item_code].actual_qty += item.actual_qty;
120
- acc[item.item_code].ordered_qty += item.ordered_qty;
121
- }
122
- else {
123
- acc[item.item_code] = {
124
- actual_qty: item.actual_qty,
125
- ordered_qty: item.ordered_qty,
126
- };
127
- }
128
- return acc;
129
- }, {});
130
- return consolidatedStockProjectedQuantity;
79
+ async getCompletedOrderItemAmounts(orderNumbers) {
80
+ const result = await this.methodRequest.request({
81
+ methodName: `get-completed-orderitem-amounts`,
82
+ requestMethod: "POST",
83
+ body: {
84
+ orderNumbers,
85
+ },
86
+ responseValidationModel: zod_1.z
87
+ .array(zod_1.z.object({
88
+ item_code: zod_1.z.string(),
89
+ qty: zod_1.z.number(),
90
+ }))
91
+ .describe("getCompletedOrderItemAmounts response"),
131
92
  });
93
+ const res = result.reduce((acc, item) => {
94
+ acc[item.item_code] = item.qty;
95
+ return acc;
96
+ }, {});
97
+ return res;
98
+ }
99
+ async getStockProjectedQuantityDict(warehouse, sku) {
100
+ const result = await this.getStockProjectedQuantityReport(warehouse, sku);
101
+ // Stock Projected Quantity report contains one line entry for every warehouse. We need to consolidate them
102
+ // to be able to safely convert the report to a dict
103
+ const consolidatedStockProjectedQuantity = result.reduce((acc, item) => {
104
+ if (acc[item.item_code]) {
105
+ acc[item.item_code].actual_qty += item.actual_qty;
106
+ acc[item.item_code].ordered_qty += item.ordered_qty;
107
+ }
108
+ else {
109
+ acc[item.item_code] = {
110
+ actual_qty: item.actual_qty,
111
+ ordered_qty: item.ordered_qty,
112
+ };
113
+ }
114
+ return acc;
115
+ }, {});
116
+ return consolidatedStockProjectedQuantity;
132
117
  }
133
118
  }
134
119
  exports.ERPNextStock = ERPNextStock;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -19,84 +10,74 @@ class ERPNextTags extends methodRequest_1.ERPNextMethodRequest {
19
10
  constructor(temporalClient) {
20
11
  super(temporalClient);
21
12
  }
22
- addTag(tag, targetDocType, targetDocName) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- const result = yield this.request({
25
- methodName: "frappe.desk.doctype.tag.tag.add_tag",
26
- requestMethod: "POST",
27
- body: {
28
- dt: targetDocType,
29
- dn: targetDocName,
30
- tag,
31
- },
32
- responseValidationModel: zod_1.default.string().describe("Add Tag Response"),
33
- });
34
- return result;
13
+ async addTag(tag, targetDocType, targetDocName) {
14
+ const result = await this.request({
15
+ methodName: "frappe.desk.doctype.tag.tag.add_tag",
16
+ requestMethod: "POST",
17
+ body: {
18
+ dt: targetDocType,
19
+ dn: targetDocName,
20
+ tag,
21
+ },
22
+ responseValidationModel: zod_1.default.string().describe("Add Tag Response"),
35
23
  });
24
+ return result;
36
25
  }
37
- addTags(tags, targetDocType, targetDocNames) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- const result = yield this.request({
40
- methodName: "frappe.desk.doctype.tag.tag.add_tags",
41
- requestMethod: "POST",
42
- body: {
43
- dt: targetDocType,
44
- docs: targetDocNames,
45
- tags,
46
- },
47
- });
48
- return result;
26
+ async addTags(tags, targetDocType, targetDocNames) {
27
+ const result = await this.request({
28
+ methodName: "frappe.desk.doctype.tag.tag.add_tags",
29
+ requestMethod: "POST",
30
+ body: {
31
+ dt: targetDocType,
32
+ docs: targetDocNames,
33
+ tags,
34
+ },
49
35
  });
36
+ return result;
50
37
  }
51
- removeTag(tag, targetDocType, targetDocName) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- const result = yield this.request({
54
- methodName: "frappe.desk.doctype.tag.tag.remove_tag",
55
- requestMethod: "POST",
56
- params: {
57
- dt: targetDocType,
58
- dn: targetDocName,
59
- tag,
60
- },
61
- });
62
- return result;
38
+ async removeTag(tag, targetDocType, targetDocName) {
39
+ const result = await this.request({
40
+ methodName: "frappe.desk.doctype.tag.tag.remove_tag",
41
+ requestMethod: "POST",
42
+ params: {
43
+ dt: targetDocType,
44
+ dn: targetDocName,
45
+ tag,
46
+ },
63
47
  });
48
+ return result;
64
49
  }
65
- removeAllTags(targetDocType, targetDocName) {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- yield this.request({
68
- methodName: "remove-all-tags",
69
- requestMethod: "POST",
70
- body: {
71
- docname: targetDocName,
72
- doctype: targetDocType,
73
- },
74
- inputValidationModel: zod_1.default
75
- .object({
76
- doctype: zod_1.default.string(),
77
- docname: zod_1.default.string(),
78
- })
79
- .describe("Remove All Tags Input"),
80
- responseValidationModel: zod_1.default
81
- .object({
82
- success: zod_1.default.boolean(),
83
- message: zod_1.default.string(),
84
- removed_count: zod_1.default.number(),
85
- })
86
- .describe("Remove All Tags Response"),
87
- });
50
+ async removeAllTags(targetDocType, targetDocName) {
51
+ await this.request({
52
+ methodName: "remove-all-tags",
53
+ requestMethod: "POST",
54
+ body: {
55
+ docname: targetDocName,
56
+ doctype: targetDocType,
57
+ },
58
+ inputValidationModel: zod_1.default
59
+ .object({
60
+ doctype: zod_1.default.string(),
61
+ docname: zod_1.default.string(),
62
+ })
63
+ .describe("Remove All Tags Input"),
64
+ responseValidationModel: zod_1.default
65
+ .object({
66
+ success: zod_1.default.boolean(),
67
+ message: zod_1.default.string(),
68
+ removed_count: zod_1.default.number(),
69
+ })
70
+ .describe("Remove All Tags Response"),
88
71
  });
89
72
  }
90
73
  // List of all available Tags
91
- getAvailableTagsList() {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- const result = yield this.request({
94
- methodName: "frappe.desk.doctype.tag.tag.get_tags_list_for_awesomebar",
95
- requestMethod: "POST",
96
- responseValidationModel: zod_1.default.array(zod_1.default.string()).describe("Tags"),
97
- });
98
- return result;
74
+ async getAvailableTagsList() {
75
+ const result = await this.request({
76
+ methodName: "frappe.desk.doctype.tag.tag.get_tags_list_for_awesomebar",
77
+ requestMethod: "POST",
78
+ responseValidationModel: zod_1.default.array(zod_1.default.string()).describe("Tags"),
99
79
  });
80
+ return result;
100
81
  }
101
82
  }
102
83
  exports.ERPNextTags = ERPNextTags;