erpnext-queue-client 2.4.5 → 2.5.0

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 CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.TemporalClient = void 0;
4
7
  const client_1 = require("@temporalio/client");
8
+ const zod_1 = __importDefault(require("zod"));
5
9
  const logger_1 = require("./utils/logger");
6
10
  const zodUtils_1 = require("./utils/zodUtils");
7
11
  const nanoid_1 = require("nanoid");
@@ -119,7 +123,9 @@ class TemporalClient {
119
123
  throw err;
120
124
  });
121
125
  logger_1.lg.info(`Started workflow ${runId}`);
122
- return data;
126
+ // console.log("TESTTEST", JSON.stringify(responseValidationModel, null, 2));
127
+ const validatedData = (0, zodUtils_1.validateData)(data, responseValidationModel ?? zod_1.default.any());
128
+ return validatedData;
123
129
  }
124
130
  }
125
131
  exports.TemporalClient = TemporalClient;
@@ -10,8 +10,6 @@ class ERPNextMethodRequest {
10
10
  this.temporalClient = temporalClient;
11
11
  }
12
12
  async request({ methodName, requestMethod, body, inputValidationModel, responseValidationModel, isAutoWrapResponseValidationWithMessage = true, params, priority = 5, }) {
13
- if (responseValidationModel && !responseValidationModel.description)
14
- throw new Error("Resource model must have a description");
15
13
  const result = await this.temporalClient.executeERPNextRequestWorkflow(`${requestMethod}-${methodName}`, {
16
14
  methodName,
17
15
  requestMethod,
@@ -34,8 +34,6 @@ class ERPNextResourceRequest {
34
34
  return allParams;
35
35
  };
36
36
  async getList({ resourceName, fields, filters, resourceModel, skip, limit, priority = 5, asDict, params, }) {
37
- if (resourceModel && !resourceModel.description)
38
- throw new Error("Resource model must have a description");
39
37
  const erpNextFields = fields?.length
40
38
  ? fields
41
39
  : ["name"]; // default field is name
@@ -57,7 +55,7 @@ class ERPNextResourceRequest {
57
55
  data: zod_1.z.array((0, zodUtils_1.pickFromSchema)((0, DocTypeHelpers_1.DocModelListEntry)(resourceModel), erpNextFields.filter((f) => f !== "*") // filter out * when other fields are present
58
56
  )),
59
57
  })
60
- .describe(`${resourceModel.description} List with fields ${JSON.stringify(erpNextFields.filter((f) => f !== "*"))}`)
58
+ .describe(`${resourceName} List with fields ${JSON.stringify(erpNextFields.filter((f) => f !== "*"))}`)
61
59
  : zod_1.z.any().describe("Any response");
62
60
  const defaultPaginationSize = 500;
63
61
  let loopLimit = defaultPaginationSize;
@@ -92,8 +90,6 @@ class ERPNextResourceRequest {
92
90
  return results;
93
91
  }
94
92
  async getById({ resourceName, resourceId, resourceModel, priority = 5, }) {
95
- if (resourceModel && !resourceModel.description)
96
- throw new Error("Resource model must have a description");
97
93
  if (!resourceId)
98
94
  throw new Error("Resource id is required");
99
95
  const result = await this.temporalClient
@@ -134,8 +130,6 @@ class ERPNextResourceRequest {
134
130
  return result.data;
135
131
  }
136
132
  async create({ resourceName, inputValidationModel, resourceModel, body, params, priority = 5, }) {
137
- if (resourceModel && !resourceModel.description)
138
- throw new Error("Resource model must have a description");
139
133
  const result = await this.temporalClient.executeERPNextRequestWorkflow(`POST-${resourceName}`, {
140
134
  requestMethod: "POST",
141
135
  resourceName,
@@ -154,8 +148,6 @@ class ERPNextResourceRequest {
154
148
  return result.data;
155
149
  }
156
150
  async deleteById({ resourceName, resourceId, resourceModel, priority = 5, }) {
157
- if (resourceModel && !resourceModel.description)
158
- throw new Error("Resource model must have a description");
159
151
  return await this.temporalClient.executeERPNextRequestWorkflow(`DELETE-${resourceName}`, {
160
152
  requestMethod: "DELETE",
161
153
  resourceName,
@@ -1,4 +1,4 @@
1
1
  import { z, ZodObject, ZodRawShape } from "zod";
2
- export declare function validateData<T extends z.ZodTypeAny>(data: unknown, ValidationModel: T): z.infer<T>;
2
+ export declare function validateData<T extends z.ZodTypeAny>(data: unknown, ValidationModel: T, isDebug?: boolean): z.infer<T>;
3
3
  export declare function pickFromSchema<T extends ZodRawShape, K extends keyof T>(schema: ZodObject<T>, keys: readonly K[]): ZodObject<Pick<T, K>>;
4
4
  export type KeysOf<T> = T extends ZodObject<any> ? keyof z.infer<T> : string;
@@ -4,33 +4,36 @@ exports.validateData = validateData;
4
4
  exports.pickFromSchema = pickFromSchema;
5
5
  const zod_1 = require("zod");
6
6
  const constants_1 = require("../constants");
7
- const logger_1 = require("./logger");
8
- function validateData(data, ValidationModel) {
7
+ function validateData(data, ValidationModel, isDebug) {
9
8
  if (!ValidationModel.description)
10
9
  throw new Error("ValidationModel.description is required");
11
10
  // writeFileSync("test.json", JSON.stringify(data, null, 2));
12
11
  if (!(ValidationModel instanceof zod_1.ZodObject) &&
13
12
  !(ValidationModel instanceof zod_1.ZodArray)) {
14
- console.log(ValidationModel);
15
13
  throw new Error("Invalid Zod Model");
16
14
  }
17
15
  const validationResult = ValidationModel.safeParse(data);
18
16
  if (!validationResult.success) {
19
- const errorObject = {
20
- message: `Validation error in model ${ValidationModel.description}`,
21
- error: validationResult.error,
22
- input: constants_1.constants.DEBUG_MODE === "true"
23
- ? data
24
- : "set DEBUG_MODE to true to see the input",
25
- };
26
- logger_1.lg.error(errorObject);
27
- if (data &&
28
- typeof data === "object" &&
29
- "message" in data &&
30
- typeof data.message === "string") {
31
- throw new Error(data.message);
32
- }
33
- throw new Error(errorObject.message, { cause: errorObject.error });
17
+ const isDebugSet = constants_1.constants.DEBUG_MODE === "true" || isDebug;
18
+ // ZodError.issues contains the most actionable information; render a readable list.
19
+ const issues = validationResult.error.issues;
20
+ const issueStrings = issues.map((issue) => {
21
+ const path = issue.path.length ? issue.path.join(".") : "(root)";
22
+ return `"${path}": ${issue.message}`;
23
+ });
24
+ const previewCount = 8;
25
+ const previewLines = "\n──────────────\n\n" +
26
+ issueStrings.slice(0, previewCount).join("\n") +
27
+ "\n\n──────────────\n";
28
+ const moreCount = Math.max(0, issueStrings.length - previewCount);
29
+ const moreSuffix = moreCount > 0 ? `\n- (+${moreCount} more)` : "";
30
+ const cleanMessage = `Validation failed for ${ValidationModel.description}\n${previewLines}${moreSuffix}`;
31
+ // Include the full error as a `cause` only when debugging; otherwise keep stack output clean.
32
+ if (isDebugSet)
33
+ console.dir(data, { depth: null });
34
+ const error = new Error(cleanMessage + "\n" + validationResult.error.toString());
35
+ delete error.stack;
36
+ throw error;
34
37
  }
35
38
  return validationResult.data;
36
39
  }
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.5",
33
+ "version": "2.5.0",
34
34
  "devDependencies": {
35
35
  "@types/crypto-js": "^4.2.2",
36
36
  "@types/lodash": "^4.17.13",