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.
- 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/StockEntry.d.ts +63 -21
- package/dist/erpnext/model/StockEntry.js +22 -21
- package/dist/erpnext/model/Waitlist.d.ts +22 -6
- package/dist/erpnext/model/Waitlist.js +6 -9
- 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 +5 -3
- package/dist/utils/zodUtils.js +2 -2
- package/package.json +1 -1
|
@@ -217,6 +217,10 @@ function createHmac(signingKey, time, iv, cipherText) {
|
|
|
217
217
|
* Instance of a Secret to be used for the token encryption
|
|
218
218
|
*/
|
|
219
219
|
class Secret {
|
|
220
|
+
signingKeyHex;
|
|
221
|
+
signingKey;
|
|
222
|
+
encryptionKeyHex;
|
|
223
|
+
encryptionKey;
|
|
220
224
|
/**
|
|
221
225
|
* Creates a Secret to be used for the token encryption
|
|
222
226
|
* @param {String} secret64 - base64 encoded secret string
|
|
@@ -248,21 +252,37 @@ exports.Secret = Secret;
|
|
|
248
252
|
* Token object to perform encryption/decryption
|
|
249
253
|
*/
|
|
250
254
|
class Token {
|
|
255
|
+
secret;
|
|
256
|
+
ttl;
|
|
257
|
+
message;
|
|
258
|
+
/** cipher text to decrypt */
|
|
259
|
+
cipherText;
|
|
260
|
+
cipherTextHex;
|
|
261
|
+
/** token string */
|
|
262
|
+
token;
|
|
263
|
+
/** version of token */
|
|
264
|
+
version;
|
|
265
|
+
/** the IV array */
|
|
266
|
+
optsIV;
|
|
267
|
+
maxClockSkew = 60;
|
|
268
|
+
time;
|
|
269
|
+
encoded;
|
|
270
|
+
iv;
|
|
271
|
+
ivHex;
|
|
272
|
+
hmacHex;
|
|
251
273
|
/**
|
|
252
274
|
* Token object to perform encryption/decryption
|
|
253
275
|
* @param {TokenOptions} opts - options for token initialization
|
|
254
276
|
*/
|
|
255
277
|
constructor(opts) {
|
|
256
|
-
var _a, _b;
|
|
257
|
-
this.maxClockSkew = 60;
|
|
258
278
|
opts = opts || {};
|
|
259
279
|
this.secret = opts.secret || defaults.secret;
|
|
260
280
|
this.ttl = opts.ttl || defaults.ttl;
|
|
261
281
|
if (opts.ttl === 0)
|
|
262
282
|
this.ttl = 0;
|
|
263
|
-
this.message =
|
|
283
|
+
this.message = opts.message ?? "";
|
|
264
284
|
this.cipherText = opts.cipherText;
|
|
265
|
-
this.token =
|
|
285
|
+
this.token = opts.token ?? "";
|
|
266
286
|
this.version = opts.version || parseHex(defaults.versionHex);
|
|
267
287
|
this.optsIV = opts.iv;
|
|
268
288
|
// @ts-ignore
|
package/dist/utils/request.js
CHANGED
|
@@ -1,30 +1,15 @@
|
|
|
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.RequestError = void 0;
|
|
24
4
|
exports.request = request;
|
|
25
5
|
const zodUtils_1 = require("./zodUtils");
|
|
26
6
|
const logger_1 = require("./logger");
|
|
27
7
|
class RequestError extends Error {
|
|
8
|
+
status;
|
|
9
|
+
requestUrl;
|
|
10
|
+
statusText;
|
|
11
|
+
responseHeaders;
|
|
12
|
+
response;
|
|
28
13
|
constructor({ status, requestUrl, statusText, responseHeaders, response, }) {
|
|
29
14
|
super(`Request failed with status ${status}: ${statusText} for URL ${requestUrl}`); // Call the parent `Error` constructor with the message
|
|
30
15
|
// Manually set the prototype to ensure `instanceof` works
|
|
@@ -52,56 +37,58 @@ class RequestError extends Error {
|
|
|
52
37
|
}
|
|
53
38
|
}
|
|
54
39
|
exports.RequestError = RequestError;
|
|
55
|
-
function request(options) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
40
|
+
async function request(options) {
|
|
41
|
+
const { body, url, inputValidationModel, responseValidationModel, credentials, headers, ...requestOptions } = options || {};
|
|
42
|
+
// Validate the request body
|
|
43
|
+
const validatedBody = inputValidationModel
|
|
44
|
+
? (0, zodUtils_1.validateData)(body, inputValidationModel)
|
|
45
|
+
: body;
|
|
46
|
+
const contentType = options.headers &&
|
|
47
|
+
"Content-Type" in options.headers &&
|
|
48
|
+
options.headers?.["Content-Type"]
|
|
49
|
+
? options.headers?.["Content-Type"]
|
|
50
|
+
: undefined;
|
|
51
|
+
const stringifiedBody = options.method !== "GET" &&
|
|
52
|
+
contentType !== "text/xml" &&
|
|
53
|
+
contentType !== "application/xml" &&
|
|
54
|
+
contentType !== "application/x-www-form-urlencoded"
|
|
55
|
+
? JSON.stringify(validatedBody)
|
|
56
|
+
: undefined;
|
|
57
|
+
const convertedOptions = {
|
|
58
|
+
...requestOptions,
|
|
59
|
+
...(headers ? { headers } : {}),
|
|
60
|
+
...(credentials ? { credentials } : {}),
|
|
61
|
+
...(options.method !== "GET"
|
|
62
|
+
? { body: stringifiedBody ?? validatedBody }
|
|
63
|
+
: {}),
|
|
64
|
+
};
|
|
65
|
+
// Log requests
|
|
66
|
+
logger_1.lg.info(`${options.method}: ${url}`);
|
|
67
|
+
// Wrap fetch
|
|
68
|
+
const response = await fetch(url, convertedOptions);
|
|
69
|
+
const { status, url: requestUrl, statusText, ok } = response;
|
|
70
|
+
const textResult = await response.text();
|
|
71
|
+
let finalResult;
|
|
72
|
+
try {
|
|
73
|
+
finalResult = JSON.parse(textResult);
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
finalResult = textResult;
|
|
77
|
+
}
|
|
78
|
+
// Reject promise when status is expected or unexpected error. Allows use of try/catch to catch http errors
|
|
79
|
+
if (!ok) {
|
|
80
|
+
logger_1.lg.error(`Error in request to ${requestUrl} with status text ${statusText}`, JSON.stringify(finalResult, null, 2));
|
|
81
|
+
throw new RequestError({
|
|
82
|
+
status,
|
|
83
|
+
requestUrl,
|
|
84
|
+
statusText,
|
|
85
|
+
responseHeaders: response?.headers,
|
|
86
|
+
response: finalResult,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
// Validate the response body
|
|
90
|
+
const validatedResult = responseValidationModel
|
|
91
|
+
? (0, zodUtils_1.validateData)(finalResult, responseValidationModel)
|
|
92
|
+
: finalResult;
|
|
93
|
+
return validatedResult;
|
|
107
94
|
}
|
|
@@ -15,8 +15,10 @@ function isMarkedOptionalForInput(schema) {
|
|
|
15
15
|
}
|
|
16
16
|
// schema transformation
|
|
17
17
|
function ResourceInput(schema) {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const shape = {
|
|
19
|
+
...schema.shape,
|
|
20
|
+
docstatus: zod_1.z.number().optional().default(0),
|
|
21
|
+
};
|
|
20
22
|
function makeMarkedKeysOptional(shape) {
|
|
21
23
|
const newShape = zod_1.z.object({}).shape;
|
|
22
24
|
for (const [key, value] of Object.entries(shape)) {
|
|
@@ -52,5 +54,5 @@ function ResourceInput(schema) {
|
|
|
52
54
|
}
|
|
53
55
|
return zod_1.z
|
|
54
56
|
.object(makeMarkedKeysOptional(shape))
|
|
55
|
-
.describe((
|
|
57
|
+
.describe((schema.description ?? "Unnamed Model") + " Input");
|
|
56
58
|
}
|
package/dist/utils/zodUtils.js
CHANGED
|
@@ -30,12 +30,12 @@ function validateData(data, ValidationModel) {
|
|
|
30
30
|
typeof data.message === "string") {
|
|
31
31
|
throw new Error(data.message);
|
|
32
32
|
}
|
|
33
|
-
throw errorObject;
|
|
33
|
+
throw new Error(errorObject.message, { cause: errorObject.error });
|
|
34
34
|
}
|
|
35
35
|
return validationResult.data;
|
|
36
36
|
}
|
|
37
37
|
function pickFromSchema(schema, keys) {
|
|
38
|
-
const pickedShape = keys
|
|
38
|
+
const pickedShape = keys?.reduce((acc, key) => {
|
|
39
39
|
if (typeof key === "string" && key.includes("as")) {
|
|
40
40
|
const [field, alias] = key.split(" as ");
|
|
41
41
|
if (key in schema.shape) {
|