erpnext-queue-client 2.4.4 → 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 +7 -1
- package/dist/erpnext/methodRequest.js +0 -2
- package/dist/erpnext/model/Waitlist.d.ts +22 -6
- package/dist/erpnext/model/Waitlist.js +6 -9
- package/dist/erpnext/resourceRequest.js +1 -9
- package/dist/utils/zodUtils.d.ts +1 -1
- package/dist/utils/zodUtils.js +21 -18
- package/package.json +1 -1
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
|
-
|
|
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,
|
|
@@ -1,20 +1,35 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const Waitlist: z.ZodObject<{
|
|
3
3
|
sku: z.ZodString;
|
|
4
4
|
e_mail: z.ZodString;
|
|
5
|
+
is_notified: z.ZodNumber & {
|
|
6
|
+
__optionalForInput: true;
|
|
7
|
+
};
|
|
8
|
+
requested_at: z.ZodString & {
|
|
9
|
+
__optionalForInput: true;
|
|
10
|
+
};
|
|
5
11
|
}, "strip", z.ZodTypeAny, {
|
|
6
12
|
sku: string;
|
|
7
13
|
e_mail: string;
|
|
14
|
+
is_notified: number;
|
|
15
|
+
requested_at: string;
|
|
8
16
|
}, {
|
|
9
17
|
sku: string;
|
|
10
18
|
e_mail: string;
|
|
19
|
+
is_notified: number;
|
|
20
|
+
requested_at: string;
|
|
11
21
|
}>;
|
|
12
|
-
export type
|
|
13
|
-
|
|
22
|
+
export type WaitlistType = z.infer<typeof Waitlist>;
|
|
23
|
+
/** @deprecated Use `Waitlist` instead. */
|
|
24
|
+
export declare const WaitlistInput: z.ZodObject<{
|
|
14
25
|
sku: z.ZodString;
|
|
15
26
|
e_mail: z.ZodString;
|
|
16
|
-
is_notified: z.ZodNumber
|
|
17
|
-
|
|
27
|
+
is_notified: z.ZodNumber & {
|
|
28
|
+
__optionalForInput: true;
|
|
29
|
+
};
|
|
30
|
+
requested_at: z.ZodString & {
|
|
31
|
+
__optionalForInput: true;
|
|
32
|
+
};
|
|
18
33
|
}, "strip", z.ZodTypeAny, {
|
|
19
34
|
sku: string;
|
|
20
35
|
e_mail: string;
|
|
@@ -26,4 +41,5 @@ export declare const Waitlist: z.ZodObject<{
|
|
|
26
41
|
is_notified: number;
|
|
27
42
|
requested_at: string;
|
|
28
43
|
}>;
|
|
29
|
-
|
|
44
|
+
/** @deprecated Use `WaitlistType` instead. */
|
|
45
|
+
export type WaitlistInputType = WaitlistType;
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.WaitlistInput = exports.Waitlist = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
-
|
|
6
|
-
.object({
|
|
7
|
-
sku: zod_1.z.string(),
|
|
8
|
-
e_mail: zod_1.z.string(),
|
|
9
|
-
})
|
|
10
|
-
.describe("WaitlistInput");
|
|
5
|
+
const zodContextOptionals_1 = require("../../utils/zodContextOptionals");
|
|
11
6
|
exports.Waitlist = zod_1.z
|
|
12
7
|
.object({
|
|
13
8
|
sku: zod_1.z.string(),
|
|
14
9
|
e_mail: zod_1.z.string(),
|
|
15
|
-
is_notified: zod_1.z.number(),
|
|
16
|
-
requested_at: zod_1.z.string(),
|
|
10
|
+
is_notified: (0, zodContextOptionals_1.optionalForInput)(zod_1.z.number()),
|
|
11
|
+
requested_at: (0, zodContextOptionals_1.optionalForInput)(zod_1.z.string()),
|
|
17
12
|
})
|
|
18
13
|
.describe("Waitlist");
|
|
14
|
+
/** @deprecated Use `Waitlist` instead. */
|
|
15
|
+
exports.WaitlistInput = exports.Waitlist;
|
|
@@ -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(`${
|
|
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,
|
package/dist/utils/zodUtils.d.ts
CHANGED
|
@@ -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;
|
package/dist/utils/zodUtils.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
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
|
}
|