erpnext-queue-client 2.4.2 → 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.
- package/dist/client.js +87 -105
- package/dist/constants.js +1 -0
- package/dist/dataConverter.js +4 -13
- package/dist/erpnext/decryptFromErpNext.server.js +1 -1
- package/dist/erpnext/decryptFromErpNext.server.test.js +2 -11
- package/dist/erpnext/doctypeResourceRequest.js +44 -37
- package/dist/erpnext/doctypeSubmittableResourceRequest.js +19 -33
- package/dist/erpnext/doctypes/address.js +40 -41
- package/dist/erpnext/doctypes/consolidatedCustomsInvoice.js +18 -20
- package/dist/erpnext/doctypes/contact.js +30 -30
- package/dist/erpnext/doctypes/deliveryNote.js +13 -12
- package/dist/erpnext/doctypes/item.d.ts +10 -10
- package/dist/erpnext/doctypes/item.js +64 -63
- package/dist/erpnext/doctypes/paymentEntry.js +42 -43
- package/dist/erpnext/doctypes/productBundle.js +15 -17
- package/dist/erpnext/doctypes/purchaseInvoice.js +45 -49
- package/dist/erpnext/doctypes/purchaseReceipt.js +41 -43
- package/dist/erpnext/doctypes/salesInvoice.js +42 -43
- package/dist/erpnext/doctypes/servicecase.js +103 -114
- package/dist/erpnext/doctypes/shipment.js +30 -35
- package/dist/erpnext/doctypes/stock.js +94 -109
- package/dist/erpnext/doctypes/tags.js +58 -77
- package/dist/erpnext/erpnextRequestWrapper.js +83 -80
- package/dist/erpnext/fileRequests.js +28 -29
- package/dist/erpnext/methodRequest.js +37 -43
- package/dist/erpnext/model/DocTypeHelpers.js +2 -3
- package/dist/erpnext/model/Item.d.ts +6 -6
- package/dist/erpnext/model/Item.js +1 -1
- package/dist/erpnext/model/PurchaseOrder.d.ts +34 -32
- package/dist/erpnext/model/PurchaseOrder.js +1 -1
- package/dist/erpnext/model/StockEntry.d.ts +63 -21
- package/dist/erpnext/model/StockEntry.js +22 -21
- package/dist/erpnext/reports.js +81 -89
- package/dist/erpnext/resourceRequest.js +142 -150
- package/dist/index.js +43 -3
- package/dist/index.test.js +69 -83
- package/dist/utils/fernet.server.js +24 -4
- package/dist/utils/request.js +59 -72
- package/dist/utils/zodContextOptionals.js +15 -6
- package/dist/utils/zodUtils.js +2 -2
- 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
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
35
|
+
: {}),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
58
41
|
}
|
|
59
|
-
createClient(options) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
package/dist/dataConverter.js
CHANGED
|
@@ -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) =>
|
|
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) =>
|
|
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 (!
|
|
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", () =>
|
|
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
|
|
23
|
-
|
|
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(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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(
|
|
38
|
-
return
|
|
39
|
-
|
|
40
|
-
|
|
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(
|
|
44
|
-
return
|
|
45
|
-
|
|
46
|
-
|
|
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(
|
|
50
|
-
return
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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(
|
|
14
|
+
.describe(resourceModel.description ?? "Unknown Model");
|
|
25
15
|
super(temporalClient, resourceName, mergedModel);
|
|
26
16
|
}
|
|
27
|
-
cancel(
|
|
28
|
-
return
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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(
|
|
41
|
-
return
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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;
|