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
@@ -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 = (_a = opts.message) !== null && _a !== void 0 ? _a : "";
283
+ this.message = opts.message ?? "";
264
284
  this.cipherText = opts.cipherText;
265
- this.token = (_b = opts.token) !== null && _b !== void 0 ? _b : "";
285
+ this.token = opts.token ?? "";
266
286
  this.version = opts.version || parseHex(defaults.versionHex);
267
287
  this.optsIV = opts.iv;
268
288
  // @ts-ignore
@@ -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
- return __awaiter(this, void 0, void 0, function* () {
57
- var _a, _b;
58
- const _c = options || {}, { body, url, inputValidationModel, responseValidationModel, credentials, headers } = _c, requestOptions = __rest(_c, ["body", "url", "inputValidationModel", "responseValidationModel", "credentials", "headers"]);
59
- // Validate the request body
60
- const validatedBody = inputValidationModel
61
- ? (0, zodUtils_1.validateData)(body, inputValidationModel)
62
- : body;
63
- const contentType = options.headers &&
64
- "Content-Type" in options.headers &&
65
- ((_a = options.headers) === null || _a === void 0 ? void 0 : _a["Content-Type"])
66
- ? (_b = options.headers) === null || _b === void 0 ? void 0 : _b["Content-Type"]
67
- : undefined;
68
- const stringifiedBody = options.method !== "GET" &&
69
- contentType !== "text/xml" &&
70
- contentType !== "application/xml" &&
71
- contentType !== "application/x-www-form-urlencoded"
72
- ? JSON.stringify(validatedBody)
73
- : undefined;
74
- const convertedOptions = Object.assign(Object.assign(Object.assign(Object.assign({}, requestOptions), (headers ? { headers } : {})), (credentials ? { credentials } : {})), (options.method !== "GET"
75
- ? { body: stringifiedBody !== null && stringifiedBody !== void 0 ? stringifiedBody : validatedBody }
76
- : {}));
77
- // Log requests
78
- logger_1.lg.info(`${options.method}: ${url}`);
79
- // Wrap fetch
80
- const response = yield fetch(url, convertedOptions);
81
- const { status, url: requestUrl, statusText, ok } = response;
82
- const textResult = yield response.text();
83
- let finalResult;
84
- try {
85
- finalResult = JSON.parse(textResult);
86
- }
87
- catch (err) {
88
- finalResult = textResult;
89
- }
90
- // Reject promise when status is expected or unexpected error. Allows use of try/catch to catch http errors
91
- if (!ok) {
92
- logger_1.lg.error(`Error in request to ${requestUrl} with status text ${statusText}`, JSON.stringify(finalResult, null, 2));
93
- throw new RequestError({
94
- status,
95
- requestUrl,
96
- statusText,
97
- responseHeaders: response === null || response === void 0 ? void 0 : response.headers,
98
- response: finalResult,
99
- });
100
- }
101
- // Validate the response body
102
- const validatedResult = responseValidationModel
103
- ? (0, zodUtils_1.validateData)(finalResult, responseValidationModel)
104
- : finalResult;
105
- return validatedResult;
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
- var _a;
19
- const shape = Object.assign(Object.assign({}, schema.shape), { docstatus: zod_1.z.number().optional().default(0) });
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(((_a = schema.description) !== null && _a !== void 0 ? _a : "Unnamed Model") + " Input");
57
+ .describe((schema.description ?? "Unnamed Model") + " Input");
56
58
  }
@@ -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 === null || keys === void 0 ? void 0 : keys.reduce((acc, key) => {
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) {
package/package.json CHANGED
@@ -30,7 +30,7 @@
30
30
  "winston": "^3.15.0",
31
31
  "zod": "3.25.76"
32
32
  },
33
- "version": "2.4.3",
33
+ "version": "2.4.5",
34
34
  "devDependencies": {
35
35
  "@types/crypto-js": "^4.2.2",
36
36
  "@types/lodash": "^4.17.13",