erpnext-queue-client 2.4.3 → 2.4.5

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 (41) 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/model/Waitlist.d.ts +22 -6
  32. package/dist/erpnext/model/Waitlist.js +6 -9
  33. package/dist/erpnext/reports.js +81 -89
  34. package/dist/erpnext/resourceRequest.js +142 -150
  35. package/dist/index.js +43 -3
  36. package/dist/index.test.js +69 -83
  37. package/dist/utils/fernet.server.js +24 -4
  38. package/dist/utils/request.js +59 -72
  39. package/dist/utils/zodContextOptionals.js +5 -3
  40. package/dist/utils/zodUtils.js +2 -2
  41. package/package.json +1 -1
package/dist/client.js CHANGED
@@ -1,24 +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
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
2
  Object.defineProperty(exports, "__esModule", { value: true });
23
3
  exports.TemporalClient = void 0;
24
4
  const client_1 = require("@temporalio/client");
@@ -28,8 +8,10 @@ const nanoid_1 = require("nanoid");
28
8
  const dataConverter_1 = require("./dataConverter");
29
9
  const nanoid = (0, nanoid_1.customAlphabet)("1234567890", 4);
30
10
  class TemporalClient {
11
+ client;
12
+ options;
31
13
  constructor(options) {
32
- const { client } = options, clientOptions = __rest(options, ["client"]);
14
+ const { client, ...clientOptions } = options;
33
15
  if (client)
34
16
  this.client = client;
35
17
  else if (clientOptions.temporalHost)
@@ -37,10 +19,11 @@ class TemporalClient {
37
19
  else
38
20
  throw new Error("No client or connection details provided");
39
21
  }
40
- tryConnect(temporalHost, temporalCert, temporalKey) {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- try {
43
- return yield client_1.Connection.connect(Object.assign({ address: temporalHost }, (temporalCert && temporalKey
22
+ async tryConnect(temporalHost, temporalCert, temporalKey) {
23
+ try {
24
+ return await client_1.Connection.connect({
25
+ address: temporalHost,
26
+ ...(temporalCert && temporalKey
44
27
  ? {
45
28
  tls: {
46
29
  clientCertPair: {
@@ -49,95 +32,94 @@ class TemporalClient {
49
32
  },
50
33
  },
51
34
  }
52
- : {})));
53
- }
54
- catch (err) {
55
- return undefined;
56
- }
57
- });
35
+ : {}),
36
+ });
37
+ }
38
+ catch (err) {
39
+ return undefined;
40
+ }
58
41
  }
59
- createClient(options) {
60
- return __awaiter(this, void 0, void 0, function* () {
61
- const { temporalCert, temporalHost, temporalKey, temporalNamespace } = options;
62
- if (!temporalHost)
63
- throw new Error("No temporal credentials provided");
64
- const connection = yield this.tryConnect(temporalHost, temporalCert, temporalKey);
65
- console.log("Create new client", options.temporalHost);
66
- this.client = new client_1.Client(Object.assign(Object.assign({}, (connection ? { connection } : {})), { namespace: options.temporalNamespace || "default", dataConverter: dataConverter_1.dataConverter }));
67
- return this.client;
42
+ async createClient(options) {
43
+ const { temporalCert, temporalHost, temporalKey, temporalNamespace } = options;
44
+ if (!temporalHost)
45
+ throw new Error("No temporal credentials provided");
46
+ const connection = await this.tryConnect(temporalHost, temporalCert, temporalKey);
47
+ console.log("Create new client", options.temporalHost);
48
+ this.client = new client_1.Client({
49
+ ...(connection ? { connection } : {}),
50
+ namespace: options.temporalNamespace || "default",
51
+ dataConverter: dataConverter_1.dataConverter,
68
52
  });
53
+ return this.client;
69
54
  }
70
- getClient() {
71
- return __awaiter(this, void 0, void 0, function* () {
72
- if (this.client)
73
- return this.client;
74
- else if (this.options)
75
- return yield this.createClient(this.options);
76
- else
77
- throw new Error("No client or connection details provided");
78
- });
55
+ async getClient() {
56
+ if (this.client)
57
+ return this.client;
58
+ else if (this.options)
59
+ return await this.createClient(this.options);
60
+ else
61
+ throw new Error("No client or connection details provided");
79
62
  }
80
63
  /**
81
64
  * @description Execute a ERPNext request workflow, 0 is the highest priority, 5 is default
82
65
  */
83
- executeERPNextRequestWorkflow(requestName_1, options_1, queue_1) {
84
- return __awaiter(this, arguments, void 0, function* (requestName, options, queue, priority = 5) {
85
- if (process.env.NODE_ENV === "test" &&
86
- process.env.RUN_IN_TEST_ENV !== "true")
87
- return;
88
- const runId = `${requestName}-${nanoid(6)}-${new Date().toISOString()}`;
89
- const client = yield this.getClient();
90
- logger_1.lg.info(`Enqueue to ERPNext Queue: ${("url" in options && options.url) ||
91
- ("uri" in options && options.uri) ||
92
- ""}${("methodName" in options && options.methodName) ||
93
- ("resourceName" in options && options.resourceName) ||
94
- ""}${("resourceId" in options &&
95
- `/${encodeURIComponent(options.resourceId)}`) ||
96
- ""}${options.params || ""}`);
97
- let optionsWithoutValidationModels = Object.assign({}, options);
98
- let inputValidationModel;
99
- let responseValidationModel;
100
- if ("inputValidationModel" in optionsWithoutValidationModels) {
101
- const { inputValidationModel: a } = optionsWithoutValidationModels, rest = __rest(optionsWithoutValidationModels, ["inputValidationModel"]);
102
- inputValidationModel = a;
103
- optionsWithoutValidationModels = rest;
104
- }
105
- if ("responseValidationModel" in optionsWithoutValidationModels) {
106
- const { responseValidationModel: b } = optionsWithoutValidationModels, rest = __rest(optionsWithoutValidationModels, ["responseValidationModel"]);
107
- responseValidationModel = b;
108
- optionsWithoutValidationModels = rest;
109
- }
110
- if ("body" in options && options.body && inputValidationModel)
111
- (0, zodUtils_1.validateData)(options.body, inputValidationModel);
112
- const data = yield client.workflow
113
- .execute("erpnextRequestWorkflow", {
114
- args: [optionsWithoutValidationModels],
115
- taskQueue: priority < 5 ? `${queue}_priority` : queue, // add to priority queue if priority is 0-5
116
- workflowId: runId,
117
- searchAttributes: {
118
- requestName: [requestName],
119
- },
120
- })
121
- .catch((err) => {
122
- var _a, _b, _c;
123
- // Try parsing the temporal error format
124
- if ((_c = (_b = (_a = err === null || err === void 0 ? void 0 : err.cause) === null || _a === void 0 ? void 0 : _a.cause) === null || _b === void 0 ? void 0 : _b.failure) === null || _c === void 0 ? void 0 : _c.message) {
125
- const errorMessage = err.cause.cause.failure.message;
126
- let errorObject;
127
- try {
128
- errorObject = JSON.parse(errorMessage);
129
- }
130
- catch (e) {
131
- throw new Error(errorMessage);
132
- }
133
- if (errorObject)
134
- throw errorObject;
66
+ async executeERPNextRequestWorkflow(requestName, options, queue, priority = 5) {
67
+ if (process.env.NODE_ENV === "test" &&
68
+ process.env.RUN_IN_TEST_ENV !== "true")
69
+ return;
70
+ const runId = `${requestName}-${nanoid(6)}-${new Date().toISOString()}`;
71
+ const client = await this.getClient();
72
+ logger_1.lg.info(`Enqueue to ERPNext Queue: ${("url" in options && options.url) ||
73
+ ("uri" in options && options.uri) ||
74
+ ""}${("methodName" in options && options.methodName) ||
75
+ ("resourceName" in options && options.resourceName) ||
76
+ ""}${("resourceId" in options &&
77
+ `/${encodeURIComponent(options.resourceId)}`) ||
78
+ ""}${options.params || ""}`);
79
+ let optionsWithoutValidationModels = {
80
+ ...options,
81
+ };
82
+ let inputValidationModel;
83
+ let responseValidationModel;
84
+ if ("inputValidationModel" in optionsWithoutValidationModels) {
85
+ const { inputValidationModel: a, ...rest } = optionsWithoutValidationModels;
86
+ inputValidationModel = a;
87
+ optionsWithoutValidationModels = rest;
88
+ }
89
+ if ("responseValidationModel" in optionsWithoutValidationModels) {
90
+ const { responseValidationModel: b, ...rest } = optionsWithoutValidationModels;
91
+ responseValidationModel = b;
92
+ optionsWithoutValidationModels = rest;
93
+ }
94
+ if ("body" in options && options.body && inputValidationModel)
95
+ (0, zodUtils_1.validateData)(options.body, inputValidationModel);
96
+ const data = await client.workflow
97
+ .execute("erpnextRequestWorkflow", {
98
+ args: [optionsWithoutValidationModels],
99
+ taskQueue: priority < 5 ? `${queue}_priority` : queue, // add to priority queue if priority is 0-5
100
+ workflowId: runId,
101
+ searchAttributes: {
102
+ requestName: [requestName],
103
+ },
104
+ })
105
+ .catch((err) => {
106
+ // Try parsing the temporal error format
107
+ if (err?.cause?.cause?.failure?.message) {
108
+ const errorMessage = err.cause.cause.failure.message;
109
+ let errorObject;
110
+ try {
111
+ errorObject = JSON.parse(errorMessage);
135
112
  }
136
- throw err;
137
- });
138
- logger_1.lg.info(`Started workflow ${runId}`);
139
- return data;
113
+ catch (e) {
114
+ throw new Error(errorMessage);
115
+ }
116
+ if (errorObject)
117
+ throw errorObject;
118
+ }
119
+ throw err;
140
120
  });
121
+ logger_1.lg.info(`Started workflow ${runId}`);
122
+ return data;
141
123
  }
142
124
  }
143
125
  exports.TemporalClient = TemporalClient;
package/dist/constants.js CHANGED
@@ -11,6 +11,7 @@ const getEnvVar = (varName) => {
11
11
  };
12
12
  exports.getEnvVar = getEnvVar;
13
13
  class ConstantsManager {
14
+ constants;
14
15
  constructor(constantNames) {
15
16
  this.constants = {};
16
17
  constantNames.forEach((c) => {
@@ -32,15 +32,6 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
35
  Object.defineProperty(exports, "__esModule", { value: true });
45
36
  exports.dataConverter = void 0;
46
37
  const common_1 = require("@temporalio/common");
@@ -50,7 +41,7 @@ const ENCODING = "json/plain";
50
41
  exports.dataConverter = {
51
42
  payloadCodecs: [
52
43
  {
53
- encode: (payloads) => __awaiter(void 0, void 0, void 0, function* () {
44
+ encode: async (payloads) => {
54
45
  return Promise.all(payloads.map((payload) => {
55
46
  if (!payload.data)
56
47
  throw new common_1.ValueError("Payload data is missing in encode");
@@ -61,8 +52,8 @@ exports.dataConverter = {
61
52
  data: pako.gzip((0, encoding_1.decode)(payload.data)),
62
53
  };
63
54
  }));
64
- }),
65
- decode: (payloads) => __awaiter(void 0, void 0, void 0, function* () {
55
+ },
56
+ decode: async (payloads) => {
66
57
  return Promise.all(payloads.map((payload) => {
67
58
  if (!payload.metadata ||
68
59
  (0, encoding_1.decode)(payload.metadata[common_1.METADATA_ENCODING_KEY]) !== ENCODING) {
@@ -78,7 +69,7 @@ exports.dataConverter = {
78
69
  data: pako.ungzip(payload.data),
79
70
  };
80
71
  }));
81
- }),
72
+ },
82
73
  },
83
74
  ],
84
75
  };
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.decryptFromErpNext = decryptFromErpNext;
4
4
  const fernet_server_1 = require("../utils/fernet.server");
5
5
  function decryptFromErpNext(credentials, encryptedPassword) {
6
- if (!(credentials === null || credentials === void 0 ? void 0 : credentials.erpnextEncryptionKey))
6
+ if (!credentials?.erpnextEncryptionKey)
7
7
  throw new Error("ERPNext encryption key is not defined. Please specify it to use the decryptFromErpNext() function.");
8
8
  const encyptionKey = credentials.erpnextEncryptionKey;
9
9
  const encodedEncyptionKey = new fernet_server_1.Secret(encyptionKey);
@@ -1,17 +1,8 @@
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
  const __1 = require("..");
13
4
  describe("decryptFromErpNext", () => {
14
- test("should decrypt password", () => __awaiter(void 0, void 0, void 0, function* () {
5
+ test("should decrypt password", async () => {
15
6
  const { utils } = new __1.ERPNextQueueClient({
16
7
  temporalCredentials: {
17
8
  temporalHost: "temporalHost",
@@ -26,5 +17,5 @@ describe("decryptFromErpNext", () => {
26
17
  const encryptedPassword = "gAAAAABjW77Rn3UP_3CZISSag2bsrq0huYiN5kavTd_2fUJUkcQd3tsrbsIbLk82TkqFKbwC1BnEP9iXKMQ-DrlIlLyIvZiwag==";
27
18
  const decryptedPassword = utils.decryptFromErpNext(encryptedPassword);
28
19
  expect(decryptedPassword).toBe("12345");
29
- }));
20
+ });
30
21
  });
@@ -1,59 +1,66 @@
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.ERPNextDoctypeResourceRequest = void 0;
13
4
  const resourceRequest_1 = require("./resourceRequest");
14
5
  class ERPNextDoctypeResourceRequest {
6
+ temporalClient;
7
+ resourceName;
8
+ resourceModel;
9
+ baseRequest;
15
10
  constructor(temporalClient, resourceName, resourceModel) {
16
11
  this.temporalClient = temporalClient;
17
12
  this.resourceName = resourceName;
18
13
  this.resourceModel = resourceModel.describe(resourceName);
19
14
  this.baseRequest = new resourceRequest_1.ERPNextResourceRequest(this.temporalClient);
20
15
  }
21
- getList() {
22
- return __awaiter(this, arguments, void 0, function* ({ fields, filters, skip, limit, priority = 5, asDict, params, } = {}) {
23
- return yield this.baseRequest.getList(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ resourceName: this.resourceName, resourceModel: this.resourceModel, priority }, (fields !== undefined ? { fields } : {})), (filters !== undefined ? { filters } : {})), (limit !== undefined ? { limit } : {})), (skip !== undefined ? { skip } : {})), (params !== undefined ? { params } : {})), (asDict !== undefined ? { asDict } : {})));
16
+ async getList({ fields, filters, skip, limit, priority = 5, asDict, params, } = {}) {
17
+ return await this.baseRequest.getList({
18
+ resourceName: this.resourceName,
19
+ resourceModel: this.resourceModel,
20
+ priority,
21
+ ...(fields !== undefined ? { fields } : {}),
22
+ ...(filters !== undefined ? { filters } : {}),
23
+ ...(limit !== undefined ? { limit } : {}),
24
+ ...(skip !== undefined ? { skip } : {}),
25
+ ...(params !== undefined ? { params } : {}),
26
+ ...(asDict !== undefined ? { asDict } : {}),
24
27
  });
25
28
  }
26
- getById(_a) {
27
- return __awaiter(this, arguments, void 0, function* ({ resourceId, priority = 5, }) {
28
- const returnValue = yield this.baseRequest.getById({
29
- resourceName: this.resourceName,
30
- resourceId,
31
- resourceModel: this.resourceModel,
32
- priority,
33
- });
34
- return returnValue;
29
+ async getById({ resourceId, priority = 5, }) {
30
+ const returnValue = await this.baseRequest.getById({
31
+ resourceName: this.resourceName,
32
+ resourceId,
33
+ resourceModel: this.resourceModel,
34
+ priority,
35
35
  });
36
+ return returnValue;
36
37
  }
37
- updateById(_a) {
38
- return __awaiter(this, arguments, void 0, function* ({ resourceId, inputValidationModel, body, priority = 5, }) {
39
- return yield this.baseRequest.updateById(Object.assign(Object.assign({ resourceName: this.resourceName, resourceId }, (inputValidationModel ? { inputValidationModel } : {})), { resourceModel: this.resourceModel, body,
40
- priority }));
38
+ async updateById({ resourceId, inputValidationModel, body, priority = 5, }) {
39
+ return await this.baseRequest.updateById({
40
+ resourceName: this.resourceName,
41
+ resourceId,
42
+ ...(inputValidationModel ? { inputValidationModel } : {}),
43
+ resourceModel: this.resourceModel,
44
+ body,
45
+ priority,
41
46
  });
42
47
  }
43
- create(_a) {
44
- return __awaiter(this, arguments, void 0, function* ({ inputValidationModel, body, params, priority = 5, }) {
45
- return yield this.baseRequest.create(Object.assign(Object.assign(Object.assign({ resourceName: this.resourceName }, (inputValidationModel ? { inputValidationModel } : {})), { resourceModel: this.resourceModel, body,
46
- priority }), (params ? { params } : {})));
48
+ async create({ inputValidationModel, body, params, priority = 5, }) {
49
+ return await this.baseRequest.create({
50
+ resourceName: this.resourceName,
51
+ ...(inputValidationModel ? { inputValidationModel } : {}),
52
+ resourceModel: this.resourceModel,
53
+ body,
54
+ priority,
55
+ ...(params ? { params } : {}),
47
56
  });
48
57
  }
49
- deleteById(_a) {
50
- return __awaiter(this, arguments, void 0, function* ({ resourceId, priority = 5, }) {
51
- return yield this.baseRequest.deleteById({
52
- resourceName: this.resourceName,
53
- resourceId,
54
- resourceModel: this.resourceModel,
55
- priority,
56
- });
58
+ async deleteById({ resourceId, priority = 5, }) {
59
+ return await this.baseRequest.deleteById({
60
+ resourceName: this.resourceName,
61
+ resourceId,
62
+ resourceModel: this.resourceModel,
63
+ priority,
57
64
  });
58
65
  }
59
66
  }
@@ -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
  };
@@ -18,36 +9,31 @@ const doctypeResourceRequest_1 = require("./doctypeResourceRequest");
18
9
  const ERPNextDocTypeMeta_1 = require("./model/ERPNextDocTypeMeta");
19
10
  class ERPNextDoctypeSubmittableResourceRequest extends doctypeResourceRequest_1.ERPNextDoctypeResourceRequest {
20
11
  constructor(temporalClient, resourceName, resourceModel) {
21
- var _a;
22
12
  const mergedModel = resourceModel
23
13
  .merge(ERPNextDocTypeMeta_1.SubmittableMeta)
24
- .describe((_a = resourceModel.description) !== null && _a !== void 0 ? _a : "Unknown Model");
14
+ .describe(resourceModel.description ?? "Unknown Model");
25
15
  super(temporalClient, resourceName, mergedModel);
26
16
  }
27
- cancel(_a) {
28
- return __awaiter(this, arguments, void 0, function* ({ resourceId, }) {
29
- return this.updateById({
30
- resourceId,
31
- inputValidationModel: zod_1.default
32
- .object({ docstatus: ERPNextDocTypeMeta_1.Docstatus })
33
- .describe("Cancel Input"),
34
- body: {
35
- docstatus: 2,
36
- },
37
- });
17
+ async cancel({ resourceId, }) {
18
+ return this.updateById({
19
+ resourceId,
20
+ inputValidationModel: zod_1.default
21
+ .object({ docstatus: ERPNextDocTypeMeta_1.Docstatus })
22
+ .describe("Cancel Input"),
23
+ body: {
24
+ docstatus: 2,
25
+ },
38
26
  });
39
27
  }
40
- submit(_a) {
41
- return __awaiter(this, arguments, void 0, function* ({ resourceId, }) {
42
- return this.updateById({
43
- resourceId,
44
- inputValidationModel: zod_1.default
45
- .object({ docstatus: ERPNextDocTypeMeta_1.Docstatus })
46
- .describe("Submit Input"),
47
- body: {
48
- docstatus: 1,
49
- },
50
- });
28
+ async submit({ resourceId, }) {
29
+ return this.updateById({
30
+ resourceId,
31
+ inputValidationModel: zod_1.default
32
+ .object({ docstatus: ERPNextDocTypeMeta_1.Docstatus })
33
+ .describe("Submit Input"),
34
+ body: {
35
+ docstatus: 1,
36
+ },
51
37
  });
52
38
  }
53
39
  }
@@ -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.ERPNextAddress = void 0;
13
4
  const zod_1 = require("zod");
@@ -19,28 +10,14 @@ const DocInfo_1 = require("../model/DocInfo");
19
10
  const DocTypeHelpers_1 = require("../model/DocTypeHelpers");
20
11
  const Supplier_1 = require("../model/Supplier");
21
12
  class ERPNextAddress {
13
+ temporalClient;
14
+ baseRequest;
15
+ methodRequest;
16
+ getList;
17
+ getById;
18
+ updateById;
19
+ deleteById;
22
20
  constructor(temporalClient) {
23
- this.getAddressesByEmail = (email_1, ...args_1) => __awaiter(this, [email_1, ...args_1], void 0, function* (email, fields = ["name"]) {
24
- const result = yield this.getList({
25
- fields,
26
- filters: [["email_id", "=", email]],
27
- });
28
- return result;
29
- });
30
- this.getAddressesBySupplier = (supplierName) => __awaiter(this, void 0, void 0, function* () {
31
- const response = yield this.methodRequest.request({
32
- methodName: `frappe.desk.form.load.getdoc?doctype=Supplier&name=${supplierName}`,
33
- requestMethod: "GET",
34
- responseValidationModel: (0, DocInfo_1.GetDocResponse)((0, DocTypeHelpers_1.LoadDocumentWrapper)(Supplier_1.Supplier)),
35
- isAutoWrapResponseValidationWithMessage: false,
36
- });
37
- const validatedAddressList = (0, zodUtils_1.validateData)(response.docs[0].__onload.addr_list, zod_1.z
38
- .array(Address_1.Address.omit({
39
- links: true,
40
- }))
41
- .describe("Linked Address List"));
42
- return validatedAddressList;
43
- });
44
21
  this.temporalClient = temporalClient;
45
22
  this.baseRequest = new doctypeResourceRequest_1.ERPNextDoctypeResourceRequest(temporalClient, "Address", Address_1.Address);
46
23
  this.methodRequest = new methodRequest_1.ERPNextMethodRequest(temporalClient);
@@ -49,18 +26,40 @@ class ERPNextAddress {
49
26
  this.updateById = this.baseRequest.updateById;
50
27
  this.deleteById = this.baseRequest.deleteById;
51
28
  }
52
- create(address, customerName) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- const result = yield this.baseRequest.create({
55
- body: Object.assign(Object.assign({}, address), { links: [
56
- {
57
- link_doctype: "Customer",
58
- link_name: customerName,
59
- },
60
- ] }),
61
- });
62
- return result;
29
+ async create(address, customerName) {
30
+ const result = await this.baseRequest.create({
31
+ body: {
32
+ ...address,
33
+ links: [
34
+ {
35
+ link_doctype: "Customer",
36
+ link_name: customerName,
37
+ },
38
+ ],
39
+ },
63
40
  });
41
+ return result;
64
42
  }
43
+ getAddressesByEmail = async (email, fields = ["name"]) => {
44
+ const result = await this.getList({
45
+ fields,
46
+ filters: [["email_id", "=", email]],
47
+ });
48
+ return result;
49
+ };
50
+ getAddressesBySupplier = async (supplierName) => {
51
+ const response = await this.methodRequest.request({
52
+ methodName: `frappe.desk.form.load.getdoc?doctype=Supplier&name=${supplierName}`,
53
+ requestMethod: "GET",
54
+ responseValidationModel: (0, DocInfo_1.GetDocResponse)((0, DocTypeHelpers_1.LoadDocumentWrapper)(Supplier_1.Supplier)),
55
+ isAutoWrapResponseValidationWithMessage: false,
56
+ });
57
+ const validatedAddressList = (0, zodUtils_1.validateData)(response.docs[0].__onload.addr_list, zod_1.z
58
+ .array(Address_1.Address.omit({
59
+ links: true,
60
+ }))
61
+ .describe("Linked Address List"));
62
+ return validatedAddressList;
63
+ };
65
64
  }
66
65
  exports.ERPNextAddress = ERPNextAddress;